Now that fsp's are created on successful file open, the structure member
authorJeremy Allison <jra@samba.org>
Mon, 24 Apr 2000 19:23:51 +0000 (19:23 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 24 Apr 2000 19:23:51 +0000 (19:23 +0000)
fsp->open is no longer needed (if an fsp pointer is valid, then it's open :-).

NB for Luke, this patch also did not apply to TNG. TNG is not yet
identical w.r.t file serving with HEAD. This makes it impossible for
me to help maintain TNG. Please fix asap.

lib/substitute.c: Removed unused variable (pidstr).

Jeremy.

12 files changed:
source/include/proto.h
source/include/smb.h
source/include/smb_macros.h
source/lib/substitute.c
source/printing/printfsp.c
source/smbd/close.c
source/smbd/files.c
source/smbd/nttrans.c
source/smbd/open.c
source/smbd/oplock.c
source/smbd/reply.c
source/smbd/trans2.c

index dfa76b39952cb418c7e61d3495778930976b2130..4564ac832c8602a2a47eb2435921a7d383b795f3 100644 (file)
@@ -201,9 +201,9 @@ int smbrun(char *cmd,char *outfile,BOOL shared);
 
 /*The following definitions come from  lib/substitute.c  */
 
+void standard_sub_basic(char *str);
 void standard_sub_conn(connection_struct *conn, char *str);
 void standard_sub_snum(int snum, char *str);
-void standard_sub_basic(char *str);
 void standard_sub_vuser(char *str, user_struct *vuser);
 void standard_sub_vsnum(char *str, user_struct *vuser, int snum);
 
@@ -355,6 +355,7 @@ void *memdup(void *p, size_t size);
 char *myhostname(void);
 char *lock_path(char *name);
 char *parent_dirname(const char *path);
+int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6);
 
 /*The following definitions come from  lib/util_array.c  */
 
@@ -1173,7 +1174,7 @@ void wins_write_database(BOOL background);
 /*The following definitions come from  nmbd/nmbd_workgroupdb.c  */
 
 struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, 
-                                             fstring name);
+                                             const char *name);
 struct work_record *create_workgroup_on_subnet(struct subnet_record *subrec,
                                                fstring name, int ttl);
 void update_workgroup_ttl(struct work_record *work, int ttl);
@@ -1579,6 +1580,11 @@ int cups_printername_ok(char *name);
 void sysv_printer_fn(void (*fn)(char *, char *));
 int sysv_printername_ok(char *name);
 
+/*The following definitions come from  printing/printfsp.c  */
+
+files_struct *print_fsp_open(connection_struct *conn,char *jobname);
+void print_fsp_end(files_struct *fsp);
+
 /*The following definitions come from  printing/printing.c  */
 
 BOOL print_backend_init(void);
@@ -1601,8 +1607,6 @@ int print_queue_snum(char *qname);
 BOOL print_queue_pause(int snum);
 BOOL print_queue_resume(int snum);
 BOOL print_queue_purge(int snum);
-files_struct *print_fsp_open(connection_struct *conn,char *jobname);
-void print_fsp_end(files_struct *fsp);
 
 /*The following definitions come from  profile/profile.c  */
 
@@ -3019,6 +3023,7 @@ void file_close_conn(connection_struct *conn);
 void file_init(void);
 void file_close_user(int vuid);
 files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval);
+files_struct *file_find_fsp(files_struct *orig_fsp);
 files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode);
 files_struct *file_find_di_next(files_struct *start_fsp);
 files_struct *file_find_print(void);
index 854200e4cb3227eadb3c550dcd3eaefa40f1c206..7fef3f40b7123ae40abfbc785d40c704674fb47e 100644 (file)
@@ -490,7 +490,6 @@ typedef struct files_struct
        int oplock_type;
        int sent_oplock_break;
        unsigned int num_posix_locks;
-       BOOL open;
        BOOL can_lock;
        BOOL can_read;
        BOOL can_write;
index cc9f158af881b433f54970a134fec93fe7846c37..e7d05189cdcfa7f202819fa1ed7aab7d9afbadef 100644 (file)
@@ -73,7 +73,7 @@
 #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
 
 /* these are useful macros for checking validity of handles */
-#define OPEN_FSP(fsp)    ((fsp) && (fsp)->open && !(fsp)->is_directory)
+#define OPEN_FSP(fsp)    ((fsp) && !(fsp)->is_directory)
 #define OPEN_CONN(conn)    ((conn) && (conn)->open)
 #define IS_IPC(conn)       ((conn) && (conn)->ipc)
 #define IS_PRINT(conn)       ((conn) && (conn)->printer)
 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
                            w->wr_discard = True, -1)
 /* Macro to test if an error has been cached for this fnum */
-#define HAS_CACHED_ERROR(fsp) ((fsp)->open && (fsp)->wbmpx_ptr && \
+#define HAS_CACHED_ERROR(fsp) ((fsp)->wbmpx_ptr && \
                                (fsp)->wbmpx_ptr->wr_discard)
 /* Macro to turn the cached error into an error packet */
 #define CACHED_ERROR(fsp) cached_error_packet(inbuf,outbuf,fsp,__LINE__)
index 6f6d2a9c165fb52104adb8b492f6ac6f49afa0d3..c43c133d6ad3ff5bb44335d48ba39d5a799609ae 100644 (file)
@@ -200,7 +200,6 @@ void standard_sub_basic(char *str)
 static void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t gid, char *str)
 {
        char *p, *s, *home;
-       fstring pidstr;
        struct passwd *pass;
 
        for (s=str; (p=strchr(s, '%'));s=p) {
index 72cd006e20cb99a89b9e0465daab92d092479496..41635561a6fd384e1c16f8ab9d4f62b341221b90 100644 (file)
@@ -56,7 +56,6 @@ files_struct *print_fsp_open(connection_struct *conn,char *jobname)
        fsp->vuid = current_user.vuid;
        fsp->size = 0;
        fsp->pos = -1;
-       fsp->open = True;
        fsp->can_lock = True;
        fsp->can_read = False;
        fsp->can_write = True;
index ec28ff354038f3019be93e4a7fc20b5c2ec97f2f..03f6aaf81a5a6fbc1d80841bd8d6059b8d42397e 100644 (file)
@@ -72,8 +72,8 @@ void close_filestruct(files_struct *fsp)
     
     flush_write_cache(fsp, CLOSE_FLUSH);
 
-       fsp->open = False;
        fsp->is_directory = False; 
+       fsp->stat_open = False; 
     
        conn->num_files_open--;
        if(fsp->wbmpx_ptr) {  
index 6c0465097b9ca1999a3314ae3d8cdb6caff31e79..e644f52669fca1ff6805e03f5623a2d93a65616c 100644 (file)
@@ -120,7 +120,7 @@ void file_close_conn(connection_struct *conn)
        
        for (fsp=Files;fsp;fsp=next) {
                next = fsp->next;
-               if (fsp->conn == conn && fsp->open) {
+               if (fsp->conn == conn) {
                        close_file(fsp,False); 
                }
        }
@@ -173,7 +173,7 @@ void file_close_user(int vuid)
 
        for (fsp=Files;fsp;fsp=next) {
                next=fsp->next;
-               if ((fsp->vuid == vuid) && fsp->open) {
+               if (fsp->vuid == vuid) {
                        close_file(fsp,False);
                }
        }
@@ -191,8 +191,7 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval
        files_struct *fsp;
 
        for (fsp=Files;fsp;fsp=fsp->next,count++) {
-               if (fsp->open && 
-                       fsp->fd != -1 &&
+               if (fsp->fd != -1 &&
                    fsp->dev == dev && 
                    fsp->inode == inode &&
                    (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) &&
@@ -207,6 +206,22 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval
        return NULL;
 }
 
+/****************************************************************************
+ Check if an fsp still exists.
+****************************************************************************/
+
+files_struct *file_find_fsp(files_struct *orig_fsp)
+{
+       files_struct *fsp;
+
+    for (fsp=Files;fsp;fsp=fsp->next) {
+        if (fsp == orig_fsp)
+            return fsp;
+    }
+
+    return NULL;
+}
+
 /****************************************************************************
  Find the first fsp given a device and inode.
 ****************************************************************************/
@@ -216,8 +231,7 @@ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode)
     files_struct *fsp;
 
     for (fsp=Files;fsp;fsp=fsp->next) {
-        if (fsp->open &&
-           fsp->fd != -1 &&
+        if ( fsp->fd != -1 &&
             fsp->dev == dev &&
             fsp->inode == inode )
             return fsp;
@@ -235,8 +249,7 @@ files_struct *file_find_di_next(files_struct *start_fsp)
     files_struct *fsp;
 
     for (fsp = start_fsp->next;fsp;fsp=fsp->next) {
-        if (fsp->open &&
-           fsp->fd != -1 &&
+        if ( fsp->fd != -1 &&
             fsp->dev == start_fsp->dev &&
             fsp->inode == start_fsp->inode )
             return fsp;
@@ -253,7 +266,7 @@ files_struct *file_find_print(void)
        files_struct *fsp;
 
        for (fsp=Files;fsp;fsp=fsp->next) {
-               if (fsp->open && fsp->print_file) return fsp;
+               if (fsp->print_file) return fsp;
        } 
 
        return NULL;
@@ -269,7 +282,7 @@ void file_sync_all(connection_struct *conn)
 
        for (fsp=Files;fsp;fsp=next) {
                next=fsp->next;
-               if (fsp->open && (conn == fsp->conn) && (fsp->fd != -1)) {
+               if ((conn == fsp->conn) && (fsp->fd != -1)) {
                        conn->vfs_ops.fsync(fsp->fd);
                }
        }
index ca9522ecfcacbac7ce7cf8992db014518348feba..b4ae0f61a9a4aa23d7cdac2b4c8953e0dd166c94 100644 (file)
@@ -1708,7 +1708,7 @@ static int call_nt_transact_notify_change(connection_struct *conn,
   if(!fsp)
     return(ERROR(ERRDOS,ERRbadfid));
 
-  if((!fsp->open) || (!fsp->is_directory) || (conn != fsp->conn))
+  if((!fsp->is_directory) || (conn != fsp->conn))
     return(ERROR(ERRDOS,ERRbadfid));
 
   /*
index d2368aa44d3be5153307ec8265814b898319eee0..353e20df8a22fc53ceff40fc7d310cf71913f454 100644 (file)
@@ -90,8 +90,7 @@ static BOOL open_file(files_struct *fsp,connection_struct *conn,
        int accmode = (flags & O_ACCMODE);
        SMB_STRUCT_STAT sbuf;
 
-       fsp->open = False;
-       fsp->fd = 0;
+       fsp->fd = -1;
        fsp->oplock_type = NO_OPLOCK;
        errno = EPERM;
 
@@ -155,7 +154,6 @@ static BOOL open_file(files_struct *fsp,connection_struct *conn,
        fsp->vuid = current_user.vuid;
        fsp->size = 0;
        fsp->pos = -1;
-       fsp->open = True;
        fsp->can_lock = True;
        fsp->can_read = ((flags & O_WRONLY)==0);
        fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
@@ -508,6 +506,7 @@ files_struct *open_file_shared(connection_struct *conn,char *fname,int share_mod
        SMB_INO_T inode = 0;
        int num_share_modes = 0;
        BOOL all_current_opens_are_level_II = False;
+       BOOL fsp_open = False;
        files_struct *fsp = NULL;
        int open_mode=0;
        uint16 port = 0;
@@ -524,7 +523,6 @@ files_struct *open_file_shared(connection_struct *conn,char *fname,int share_mod
        if(!fsp)
                return NULL;
 
-       fsp->open = False;
        fsp->fd = -1;
 
        DEBUG(10,("open_file_shared: fname = %s, share_mode = %x, ofun = %x, mode = %o, oplock request = %d\n",
@@ -638,14 +636,14 @@ files_struct *open_file_shared(connection_struct *conn,char *fname,int share_mod
        DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o\n",
                        flags,flags2,(int)mode));
 
-       fsp->open = open_file(fsp,conn,fname,flags|(flags2&~(O_TRUNC)),mode);
+       fsp_open = open_file(fsp,conn,fname,flags|(flags2&~(O_TRUNC)),mode);
 
-       if (!fsp->open && (flags == O_RDWR) && (errno != ENOENT) && fcbopen) {
-               if((fsp->open = open_file(fsp,conn,fname,O_RDONLY,mode)) == True)
+       if (!fsp_open && (flags == O_RDWR) && (errno != ENOENT) && fcbopen) {
+               if((fsp_open = open_file(fsp,conn,fname,O_RDONLY,mode)) == True)
                        flags = O_RDONLY;
        }
 
-       if (!fsp->open) {
+       if (!fsp_open) {
                if(file_existed)
                        unlock_share_entry(conn, dev, inode);
                file_free(fsp);
@@ -790,7 +788,6 @@ files_struct *open_file_stat(connection_struct *conn,
        fsp->vuid = current_user.vuid;
        fsp->size = 0;
        fsp->pos = -1;
-       fsp->open = True;
        fsp->can_lock = False;
        fsp->can_read = False;
        fsp->can_write = False;
@@ -915,7 +912,6 @@ files_struct *open_directory(connection_struct *conn,
        fsp->vuid = current_user.vuid;
        fsp->size = 0;
        fsp->pos = -1;
-       fsp->open = True;
        fsp->can_lock = True;
        fsp->can_read = False;
        fsp->can_write = False;
index e794d2d92353b24a91e28e6bda5f96f39fd90c5b..28ab29d02747b0b9594ae74a69c58e45821307a7 100644 (file)
@@ -1304,10 +1304,10 @@ BOOL attempt_close_oplocked_file(files_struct *fsp)
 
   DEBUG(5,("attempt_close_oplocked_file: checking file %s.\n", fsp->fsp_name));
 
-  if (fsp->open && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !fsp->sent_oplock_break && (fsp->fd != -1)) {
+  if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !fsp->sent_oplock_break && (fsp->fd != -1)) {
          /* Try and break the oplock. */
          if (oplock_break(fsp->dev, fsp->inode, &fsp->open_time, True)) {
-                 if(!fsp->open) /* Did the oplock break close the file ? */
+                 if(file_find_fsp(fsp) == NULL) /* Did the oplock break close the file ? */
                          return True;
          }
   }
index baff8f2ac87b86cf4c00a86ddc84f50168656b96..a020f5eb3b12189e1f30a56b45886f5199ea0ed0 100644 (file)
@@ -2751,7 +2751,7 @@ int reply_close(connection_struct *conn, char *inbuf,char *outbuf, int size,
         * We can only use CHECK_FSP if we know it's not a directory.
         */
 
-       if(!fsp || !fsp->open || (fsp->conn != conn))
+       if(!fsp || (fsp->conn != conn))
                return(ERROR(ERRDOS,ERRbadfid));
 
        if(HAS_CACHED_ERROR(fsp)) {
index 7a5276aa42fb27d6dbfdc2acb058fb7a7d914899..a30038a431ee58466907975162a84ad857b16613 100644 (file)
@@ -1296,7 +1296,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
 
     DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
 
-    if(fsp && fsp->open && (fsp->is_directory || fsp->stat_open)) {
+    if(fsp && (fsp->is_directory || fsp->stat_open)) {
       /*
        * This is actually a QFILEINFO on a directory
        * handle (returned from an NT SMB). NT5.0 seems
@@ -1579,7 +1579,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
     fsp = file_fsp(params,0);
     info_level = SVAL(params,2);    
 
-    if(fsp && fsp->open && (fsp->is_directory || fsp->stat_open)) {
+    if(fsp && (fsp->is_directory || fsp->stat_open)) {
       /*
        * This is actually a SETFILEINFO on a directory
        * handle (returned from an NT SMB). NT5.0 seems