From 8978aae69699ccab76fdf95037948b1cc7e7c286 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Aug 1998 03:52:05 +0000 Subject: much cleaner chain pointer handling for both files and pipes. the chain pointer is now stored as a static and is set whenever a handle is created or extracted. This also makes the code less error prone. (This used to be commit 068a862982bea726e8d7b1b4065d510b9840a272) --- source3/smbd/files.c | 55 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index bc3ea880bf..e66e53e6ed 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -35,6 +35,10 @@ static struct bitmap *fd_bmap; static files_struct *Files; +/* a fsp to use when chaining */ +static files_struct *chain_fsp = NULL; + + /* * Indirection for file fd's. Needed as POSIX locking * is based on file/process, not fd/process. @@ -106,6 +110,8 @@ files_struct *file_new(void ) DEBUG(5,("allocated file structure %d (%d used)\n", i, files_used)); + + chain_fsp = fsp; return fsp; } @@ -237,21 +243,6 @@ void file_init(void) } -/**************************************************************************** -find a fsp given a fnum -****************************************************************************/ -files_struct *file_fsp(int fnum) -{ - files_struct *fsp; - - for (fsp=Files;fsp;fsp=fsp->next) { - if (fsp->fnum == fnum) return fsp; - } - - return NULL; -} - - /**************************************************************************** close files open by a specified vuid ****************************************************************************/ @@ -375,5 +366,39 @@ void file_free(files_struct *fsp) information */ memset(fsp, 0, sizeof(*fsp)); + if (fsp == chain_fsp) chain_fsp = NULL; + free(fsp); } + + +/**************************************************************************** +get a fsp from a packet given the offset of a 16 bit fnum +****************************************************************************/ +files_struct *file_fsp(char *buf, int where) +{ + int fnum; + files_struct *fsp; + + if (chain_fsp) return chain_fsp; + + fnum = SVAL(buf, where); + + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp->fnum == fnum) { + chain_fsp = fsp; + return fsp; + } + } + + return NULL; +} + + +/**************************************************************************** +reset the chained fsp - done at the start of a packet reply +****************************************************************************/ +void file_chain_reset(void) +{ + chain_fsp = NULL; +} -- cgit