From: Volker Lendecke Date: Mon, 18 May 2009 07:46:05 +0000 (+0200) Subject: Add "file_walk_table" to do stuff with all open files X-Git-Tag: tdb-1.1.5~500 X-Git-Url: http://git.samba.org/samba.git/?p=ira%2Fwip.git;a=commitdiff_plain;h=22085c59cb31e90bd7fb555f54836f057bf4018b Add "file_walk_table" to do stuff with all open files --- diff --git a/source3/include/proto.h b/source3/include/proto.h index 81fc1c061f3..5b5f9098e02 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -6285,6 +6285,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); diff --git a/source3/smbd/files.c b/source3/smbd/files.c index d2ea520146c..0e6dd7e457e 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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. ****************************************************************************/