From 89efea81d9d67ebed159321e8ea496eee54c2deb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 10 Sep 2006 07:24:41 +0000 Subject: r18319: fixed the directory search resume code on IRIX The problem was twofold: 1) irix returns 64 bit numbers in telldir(). The protocol uses a 32 bit resume key. We now cope with this properly using the code in pvfs_list_seek_ofs(). 2) irix returns 0xFFFFFFFF from telldir() for the last entry in the directory. When added to DIR_OFFSET_BASE this became DIR_OFFSET_DOTDOT which meant an infinite loop! (This used to be commit 8cce9740ed0da9f08d6821beb4acaa9d28d149c2) --- source4/ntvfs/posix/pvfs_dirlist.c | 83 ++++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 8 deletions(-) (limited to 'source4/ntvfs/posix/pvfs_dirlist.c') diff --git a/source4/ntvfs/posix/pvfs_dirlist.c b/source4/ntvfs/posix/pvfs_dirlist.c index c351f6ba41..e8dd149836 100644 --- a/source4/ntvfs/posix/pvfs_dirlist.c +++ b/source4/ntvfs/posix/pvfs_dirlist.c @@ -45,10 +45,14 @@ struct pvfs_dir { uint32_t name_cache_index; }; +/* these three numbers are chosen to minimise the chances of a bad + interaction with the OS value for 'end of directory'. On IRIX + telldir() returns 0xFFFFFFFF at the end of a directory, and that + caused an infinite loop with the original values of 0,1,2 +*/ #define DIR_OFFSET_DOT 0 #define DIR_OFFSET_DOTDOT 1 -#define DIR_OFFSET_BASE 2 - +#define DIR_OFFSET_BASE 0x80000002 /* a special directory listing case where the pattern has no wildcard. We can just do a single stat() @@ -140,7 +144,7 @@ NTSTATUS pvfs_list_start(struct pvfs_state *pvfs, struct pvfs_filename *name, dir->pvfs = pvfs; dir->no_wildcard = False; dir->end_of_search = False; - dir->offset = 0; + dir->offset = DIR_OFFSET_DOT; dir->name_cache = talloc_zero_array(dir, struct name_cache_entry, NAME_CACHE_SIZE); @@ -173,7 +177,7 @@ static void dcache_add(struct pvfs_dir *dir, const char *name) /* return the next entry */ -const char *pvfs_list_next(struct pvfs_dir *dir, uint_t *ofs) +const char *pvfs_list_next(struct pvfs_dir *dir, off_t *ofs) { struct dirent *de; enum protocol_types protocol = dir->pvfs->ntvfs->ctx->protocol; @@ -190,7 +194,7 @@ const char *pvfs_list_next(struct pvfs_dir *dir, uint_t *ofs) not return them first in a directory, but windows client may assume that these entries always appear first */ if (*ofs == DIR_OFFSET_DOT) { - (*ofs)++; + (*ofs) = DIR_OFFSET_DOTDOT; dir->offset = *ofs; if (ms_fnmatch(dir->pattern, ".", protocol) == 0) { dcache_add(dir, "."); @@ -199,7 +203,7 @@ const char *pvfs_list_next(struct pvfs_dir *dir, uint_t *ofs) } if (*ofs == DIR_OFFSET_DOTDOT) { - (*ofs)++; + (*ofs) = DIR_OFFSET_BASE; dir->offset = *ofs; if (ms_fnmatch(dir->pattern, "..", protocol) == 0) { dcache_add(dir, ".."); @@ -254,7 +258,7 @@ const char *pvfs_list_unix_path(struct pvfs_dir *dir) /* return True if end of search has been reached */ -BOOL pvfs_list_eos(struct pvfs_dir *dir, uint_t ofs) +BOOL pvfs_list_eos(struct pvfs_dir *dir, off_t ofs) { return dir->end_of_search; } @@ -262,11 +266,13 @@ BOOL pvfs_list_eos(struct pvfs_dir *dir, uint_t ofs) /* seek to the given name */ -NTSTATUS pvfs_list_seek(struct pvfs_dir *dir, const char *name, uint_t *ofs) +NTSTATUS pvfs_list_seek(struct pvfs_dir *dir, const char *name, off_t *ofs) { struct dirent *de; int i; + dir->end_of_search = False; + if (ISDOT(name)) { dir->offset = DIR_OFFSET_DOTDOT; *ofs = dir->offset; @@ -309,6 +315,67 @@ NTSTATUS pvfs_list_seek(struct pvfs_dir *dir, const char *name, uint_t *ofs) return NT_STATUS_OBJECT_NAME_NOT_FOUND; } +/* + seek to the given offset +*/ +NTSTATUS pvfs_list_seek_ofs(struct pvfs_dir *dir, uint32_t resume_key, off_t *ofs) +{ + struct dirent *de; + int i; + + dir->end_of_search = False; + + if (resume_key == DIR_OFFSET_DOT) { + *ofs = DIR_OFFSET_DOTDOT; + return NT_STATUS_OK; + } + + if (resume_key == DIR_OFFSET_DOTDOT) { + *ofs = DIR_OFFSET_BASE; + return NT_STATUS_OK; + } + + if (resume_key == DIR_OFFSET_BASE) { + rewinddir(dir->dir); + if ((de=readdir(dir->dir)) == NULL) { + dir->end_of_search = True; + return NT_STATUS_OBJECT_NAME_NOT_FOUND; + } + *ofs = telldir(dir->dir) + DIR_OFFSET_BASE; + dir->offset = *ofs; + return NT_STATUS_OK; + } + + for (i=dir->name_cache_index;i>=0;i--) { + struct name_cache_entry *e = &dir->name_cache[i]; + if (resume_key == (uint32_t)e->offset) { + *ofs = e->offset; + return NT_STATUS_OK; + } + } + for (i=NAME_CACHE_SIZE-1;i>dir->name_cache_index;i--) { + struct name_cache_entry *e = &dir->name_cache[i]; + if (resume_key == (uint32_t)e->offset) { + *ofs = e->offset; + return NT_STATUS_OK; + } + } + + rewinddir(dir->dir); + + while ((de = readdir(dir->dir))) { + dir->offset = telldir(dir->dir) + DIR_OFFSET_BASE; + if (resume_key == (uint32_t)dir->offset) { + *ofs = dir->offset; + return NT_STATUS_OK; + } + } + + dir->end_of_search = True; + + return NT_STATUS_OBJECT_NAME_NOT_FOUND; +} + /* see if a directory is empty -- cgit