From: Franco B. <fr...@fu...> - 2007-09-19 02:01:03
|
OK that works. Is this now a fix and not a hack? Or are you thinking there's a better way around this problem? On Tue, 2007-09-18 at 16:05 +0200, Miklos Szeredi wrote: > > I just tested the hack and it appears to produce exactly the same result > > as before. > > OK, the hack was broken. Here's one that I actually tried. > > Miklos > --- > > struct xmp_dirp { > DIR *dp; > struct dirent *entry; > off_t offset; > }; > > static int xmp_opendir(const char *path, struct fuse_file_info *fi) > { > int res; > struct xmp_dirp *d = malloc(sizeof(struct xmp_dirp)); > if (d == NULL) > return -ENOMEM; > > d->dp = opendir(path); > if (d->dp == NULL) { > res = -errno; > free(d); > return res; > } > d->offset = 0; > d->entry = NULL; > > fi->fh = (unsigned long) d; > return 0; > } > > static inline struct xmp_dirp *get_dirp(struct fuse_file_info *fi) > { > return (struct xmp_dirp *) (uintptr_t) fi->fh; > } > > static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, > off_t offset, struct fuse_file_info *fi) > { > struct xmp_dirp *d = get_dirp(fi); > > (void) path; > if (offset != d->offset) { > seekdir(d->dp, offset); > d->entry = NULL; > d->offset = offset; > } > while (1) { > struct stat st; > off_t nextoff; > > if (!d->entry) { > d->entry = readdir(d->dp); > if (!d->entry) > break; > } > > memset(&st, 0, sizeof(st)); > st.st_ino = d->entry->d_ino; > st.st_mode = d->entry->d_type << 12; > nextoff = telldir(d->dp); > if (filler(buf, d->entry->d_name, &st, nextoff)) > break; > > d->entry = NULL; > d->offset = nextoff; > } > > return 0; > } > > static int xmp_releasedir(const char *path, struct fuse_file_info *fi) > { > struct xmp_dirp *d = get_dirp(fi); > (void) path; > closedir(d->dp); > free(d); > return 0; > } |