diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-10-04 04:48:17 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-10-04 04:48:17 +0000 |
commit | 60a683465647932f7241ba9f92443d5e5294e20b (patch) | |
tree | e2164f85c3dc5232d9d727607064875759dd95fd | |
parent | 04e92e692e49234df6fbbfd07a33b315ed62f0de (diff) | |
download | samba-60a683465647932f7241ba9f92443d5e5294e20b.tar.gz |
use dummy file descriptors opened on /dev/null to ensure that the smbw
file descriptor allocation order is identical to the kernels.
-rw-r--r-- | source/include/proto.h | 1 | ||||
-rw-r--r-- | source/lib/bitmap.c | 2 | ||||
-rw-r--r-- | source/smbwrapper/smbw.c | 16 | ||||
-rw-r--r-- | source/smbwrapper/smbw.h | 3 | ||||
-rw-r--r-- | source/smbwrapper/smbw_dir.c | 13 |
5 files changed, 23 insertions, 12 deletions
diff --git a/source/include/proto.h b/source/include/proto.h index 932621ce9a1..78863b59845 100644 --- a/source/include/proto.h +++ b/source/include/proto.h @@ -55,6 +55,7 @@ BOOL check_access(int sock, char *allow_list, char *deny_list); struct bitmap *bitmap_allocate(int n); BOOL bitmap_set(struct bitmap *bm, unsigned i); BOOL bitmap_clear(struct bitmap *bm, unsigned i); +BOOL bitmap_query(struct bitmap *bm, unsigned i); int bitmap_find(struct bitmap *bm, unsigned ofs); /*The following definitions come from lib/charcnv.c */ diff --git a/source/lib/bitmap.c b/source/lib/bitmap.c index 9ccdbb420b1..93c821c5285 100644 --- a/source/lib/bitmap.c +++ b/source/lib/bitmap.c @@ -81,7 +81,7 @@ BOOL bitmap_clear(struct bitmap *bm, unsigned i) /**************************************************************************** query a bit in a bitmap ****************************************************************************/ -static BOOL bitmap_query(struct bitmap *bm, unsigned i) +BOOL bitmap_query(struct bitmap *bm, unsigned i) { if (i >= bm->n) return False; if (bm->b[i/32] & (1<<(i%32))) { diff --git a/source/smbwrapper/smbw.c b/source/smbwrapper/smbw.c index d79131a8eaa..11192bedd78 100644 --- a/source/smbwrapper/smbw.c +++ b/source/smbwrapper/smbw.c @@ -95,7 +95,7 @@ determine if a file descriptor is a smb one int smbw_fd(int fd) { if (smbw_busy) return 0; - return (fd >= SMBW_FD_OFFSET); + return smbw_file_bmap && bitmap_query(smbw_file_bmap, fd); } /***************************************************** @@ -523,16 +523,19 @@ int smbw_open(const char *fname, int flags, mode_t mode) goto failed; } file->srv = srv; - file->fd = bitmap_find(smbw_file_bmap, 0); - + file->fd = open("/dev/null", O_WRONLY); if (file->fd == -1) { errno = EMFILE; goto failed; } - bitmap_set(smbw_file_bmap, file->fd); + if (bitmap_query(smbw_file_bmap, file->fd)) { + DEBUG(0,("ERROR: fd used in smbw_open\n")); + errno = EIO; + goto failed; + } - file->fd += SMBW_FD_OFFSET; + bitmap_set(smbw_file_bmap, file->fd); DLIST_ADD(smbw_files, file); @@ -648,7 +651,8 @@ int smbw_close(int fd) } - bitmap_clear(smbw_file_bmap, file->fd - SMBW_FD_OFFSET); + bitmap_clear(smbw_file_bmap, file->fd); + close(file->fd); DLIST_REMOVE(smbw_files, file); diff --git a/source/smbwrapper/smbw.h b/source/smbwrapper/smbw.h index 716205c1fc8..5fc864456e0 100644 --- a/source/smbwrapper/smbw.h +++ b/source/smbwrapper/smbw.h @@ -21,9 +21,8 @@ #define SMBW_PREFIX "/smb/" -#define SMBW_FD_OFFSET 700 #define SMBW_CLI_FD 512 -#define SMBW_MAX_OPEN 2048 +#define SMBW_MAX_OPEN 8192 #define SMBW_FILE_MODE (S_IFREG | 0644) #define SMBW_DIR_MODE (S_IFDIR | 0755) diff --git a/source/smbwrapper/smbw_dir.c b/source/smbwrapper/smbw_dir.c index 22da76eb17c..c437a53e1f5 100644 --- a/source/smbwrapper/smbw_dir.c +++ b/source/smbwrapper/smbw_dir.c @@ -175,17 +175,23 @@ int smbw_dir_open(const char *fname) cur_dir = NULL; - fd = bitmap_find(smbw_file_bmap, 0); + fd = open("/dev/null", O_WRONLY); if (fd == -1) { errno = EMFILE; goto failed; } + if (bitmap_query(smbw_file_bmap, fd)) { + DEBUG(0,("ERROR: fd used in smbw_dir_open\n")); + errno = EIO; + goto failed; + } + DLIST_ADD(smbw_dirs, dir); bitmap_set(smbw_file_bmap, fd); - dir->fd = fd + SMBW_FD_OFFSET; + dir->fd = fd; dir->srv = srv; dir->path = strdup(s); @@ -241,7 +247,8 @@ int smbw_dir_close(int fd) return -1; } - bitmap_clear(smbw_file_bmap, dir->fd - SMBW_FD_OFFSET); + bitmap_clear(smbw_file_bmap, dir->fd); + close(dir->fd); DLIST_REMOVE(smbw_dirs, dir); |