lib/util: Remove obsolete sys_getpid() and sys_fork().
[samba.git] / source3 / smbd / files.c
index b8a25c1d5b6feec2f2dc2c0faabded97c7c4ac9b..e01a92e333de0c5ed566fec2adf322b2b901543e 100644 (file)
@@ -23,6 +23,7 @@
 #include "libcli/security/security.h"
 #include "util_tdb.h"
 #include <ccan/hash/hash.h>
+#include "lib/util/bitmap.h"
 
 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < real_max_open_files))
 
@@ -59,7 +60,7 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
           increases the chance that the errant client will get an error rather
           than causing corruption */
        if (sconn->first_file == 0) {
-               sconn->first_file = (sys_getpid() ^ (int)time(NULL));
+               sconn->first_file = (getpid() ^ (int)time(NULL));
                sconn->first_file %= sconn->real_max_open_files;
        }
 
@@ -104,7 +105,6 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
        sconn->first_file = (i+1) % (sconn->real_max_open_files);
 
        bitmap_set(sconn->file_bmap, i);
-       sconn->files_used += 1;
 
        fsp->fnum = i + FILE_HANDLE_OFFSET;
        SMB_ASSERT(fsp->fnum < 65536);
@@ -122,9 +122,10 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
        }
 
        DLIST_ADD(sconn->files, fsp);
+       sconn->num_files += 1;
 
-       DEBUG(5,("allocated file structure %d, fnum = %d (%d used)\n",
-                i, fsp->fnum, sconn->files_used));
+       DEBUG(5,("allocated file structure %d, fnum = %d (%u used)\n",
+                i, fsp->fnum, (unsigned int)sconn->num_files));
 
        if (req != NULL) {
                req->chain_fsp = fsp;
@@ -434,6 +435,8 @@ void file_free(struct smb_request *req, files_struct *fsp)
        struct smbd_server_connection *sconn = fsp->conn->sconn;
 
        DLIST_REMOVE(sconn->files, fsp);
+       SMB_ASSERT(sconn->num_files > 0);
+       sconn->num_files--;
 
        TALLOC_FREE(fsp->fake_file_handle);
 
@@ -444,11 +447,13 @@ void file_free(struct smb_request *req, files_struct *fsp)
        }
 
        if (fsp->notify) {
+               struct notify_context *notify_ctx =
+                       fsp->conn->sconn->notify_ctx;
                if (fsp->is_directory) {
-                       notify_remove_onelevel(fsp->conn->notify_ctx,
+                       notify_remove_onelevel(notify_ctx,
                                               &fsp->file_id, fsp);
                }
-               notify_remove(fsp->conn->notify_ctx, fsp);
+               notify_remove(notify_ctx, fsp);
                TALLOC_FREE(fsp->notify);
        }
 
@@ -459,10 +464,8 @@ void file_free(struct smb_request *req, files_struct *fsp)
        TALLOC_FREE(fsp->update_write_time_event);
 
        bitmap_clear(sconn->file_bmap, fsp->fnum - FILE_HANDLE_OFFSET);
-       sconn->files_used--;
-
-       DEBUG(5,("freed files structure %d (%d used)\n",
-                fsp->fnum, sconn->files_used));
+       DEBUG(5,("freed files structure %d (%u used)\n",
+                fsp->fnum, (unsigned int)sconn->num_files));
 
        fsp->conn->num_files_open--;
 
@@ -564,7 +567,6 @@ NTSTATUS dup_file_fsp(struct smb_request *req, files_struct *from,
 
        to->file_id = from->file_id;
        to->initial_allocation_size = from->initial_allocation_size;
-       to->mode = from->mode;
        to->file_pid = from->file_pid;
        to->vuid = from->vuid;
        to->open_time = from->open_time;