summaryrefslogtreecommitdiff
path: root/source3/smbd/files.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-08-17 03:06:20 +0000
committerAndrew Tridgell <tridge@samba.org>1998-08-17 03:06:20 +0000
commitf2d538a105a61ce6d2852700fc328e15ac158827 (patch)
tree47c819007b231a5a8ebfcc7faa0c1354561366df /source3/smbd/files.c
parentc5e2c883c0415ca3c7e366357c8c6ba573713aa6 (diff)
downloadsamba-f2d538a105a61ce6d2852700fc328e15ac158827.tar.gz
samba-f2d538a105a61ce6d2852700fc328e15ac158827.tar.bz2
samba-f2d538a105a61ce6d2852700fc328e15ac158827.zip
some cleanups from the conversion of Pipes[] to a linked list. I also
removed most cases where a pnum is used and substituted a pipes_struct*. in files.c I added a offset of 0x1000 to all file handles on the wire. This makes it much less likely that bad parsing will give us the wrong field. (This used to be commit 8bc2627ff28d340db65bfa017daca2dc291d5ef7)
Diffstat (limited to 'source3/smbd/files.c')
-rw-r--r--source3/smbd/files.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index 8f1cefbbb6..bc3ea880bf 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -28,6 +28,8 @@ extern int DEBUGLEVEL;
#define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < MAX_FNUMS))
+#define FILE_HANDLE_OFFSET 0x1000
+
static struct bitmap *file_bmap;
static struct bitmap *fd_bmap;
@@ -57,11 +59,6 @@ files_struct *file_new(void )
than causing corruption */
if (first_file == 0) {
first_file = (getpid() ^ (int)time(NULL)) % MAX_FNUMS;
- if (first_file == 0) first_file = 1;
- }
-
- if (first_file >= MAX_FNUMS) {
- first_file = 1;
}
i = bitmap_find(file_bmap, first_file);
@@ -89,12 +86,14 @@ files_struct *file_new(void )
if (!fsp) return NULL;
memset(fsp, 0, sizeof(*fsp));
- first_file = i+1;
- fsp->fnum = i;
- string_init(&fsp->fsp_name,"");
+
+ first_file = (i+1) % MAX_FNUMS;
bitmap_set(file_bmap, i);
files_used++;
+
+ fsp->fnum = i + FILE_HANDLE_OFFSET;
+ string_init(&fsp->fsp_name,"");
/* hook into the front of the list */
if (!Files) {
@@ -245,8 +244,6 @@ files_struct *file_fsp(int fnum)
{
files_struct *fsp;
- if (!VALID_FNUM(fnum)) return NULL;
-
for (fsp=Files;fsp;fsp=fsp->next) {
if (fsp->fnum == fnum) return fsp;
}
@@ -368,7 +365,7 @@ void file_free(files_struct *fsp)
fd_ptr_free(fsp->fd_ptr);
}
- bitmap_clear(file_bmap, fsp->fnum);
+ bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET);
files_used--;
DEBUG(5,("freed files structure %d (%d used)\n",