Add "file_walk_table" to do stuff with all open files
authorVolker Lendecke <vl@samba.org>
Mon, 18 May 2009 07:46:05 +0000 (09:46 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 18 May 2009 08:45:48 +0000 (10:45 +0200)
source3/include/proto.h
source3/smbd/files.c

index 718e0a9bc6ef20a4a0057f7a8420f0e539da7ec0..99cd1aa94f2af8b38887907766e9f90a743e3457 100644 (file)
@@ -6368,6 +6368,10 @@ void file_close_pid(uint16 smbpid, int vuid);
 void file_init(void);
 void file_close_user(int vuid);
 void file_dump_open_table(void);
+struct files_struct *file_walk_table(
+       struct files_struct *(*fn)(struct files_struct *fsp,
+                                  void *private_data),
+       void *private_data);
 files_struct *file_find_fd(int fd);
 files_struct *file_find_dif(struct file_id id, unsigned long gen_id);
 files_struct *file_find_fsp(files_struct *orig_fsp);
index 36e80a086ac26cb957c5f408442a2867f3f7c56a..a2200fc46f9f36b9e082c79dc905454a9f9c6c0d 100644 (file)
@@ -204,6 +204,28 @@ void file_close_user(int vuid)
        }
 }
 
+/*
+ * Walk the files table until "fn" returns non-NULL
+ */
+
+struct files_struct *file_walk_table(
+       struct files_struct *(*fn)(struct files_struct *fsp,
+                                  void *private_data),
+       void *private_data)
+{
+       struct files_struct *fsp, *next;
+
+       for (fsp = Files; fsp; fsp = next) {
+               struct files_struct *ret;
+               next = fsp->next;
+               ret = fn(fsp, private_data);
+               if (ret != NULL) {
+                       return ret;
+               }
+       }
+       return NULL;
+}
+
 /****************************************************************************
  Debug to enumerate all open files in the smbd.
 ****************************************************************************/