summaryrefslogtreecommitdiffstats
path: root/source/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
commit8bc2627ff28d340db65bfa017daca2dc291d5ef7 (patch)
tree2ab14b18760b8d94a3fed755e0096eda407d095e /source/smbd/files.c
parentf1c67a00b8603bf1a9e6bef680c0d563727ba108 (diff)
downloadsamba-8bc2627ff28d340db65bfa017daca2dc291d5ef7.tar.gz
samba-8bc2627ff28d340db65bfa017daca2dc291d5ef7.tar.xz
samba-8bc2627ff28d340db65bfa017daca2dc291d5ef7.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.
Diffstat (limited to 'source/smbd/files.c')
-rw-r--r--source/smbd/files.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/source/smbd/files.c b/source/smbd/files.c
index 8f1cefbbb6e..bc3ea880bfa 100644
--- a/source/smbd/files.c
+++ b/source/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",