From 413a76cef78de56087574a875a1c478603d5d090 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 18 May 2009 09:46:05 +0200 Subject: [PATCH] Add "file_walk_table" to do stuff with all open files --- source3/include/proto.h | 4 ++++ source3/smbd/files.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/source3/include/proto.h b/source3/include/proto.h index 718e0a9bc6e..99cd1aa94f2 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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); diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 36e80a086ac..a2200fc46f9 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. ****************************************************************************/ -- 2.11.4.GIT