diff --git a/cache.c b/cache.c index 53d594b..4a7e3a9 100644 --- a/cache.c +++ b/cache.c @@ -385,6 +385,7 @@ static void cache_unity_fill(struct fuse_cache_operations *oper, cache_oper->listxattr = oper->oper.listxattr; cache_oper->removexattr = oper->oper.removexattr; cache_oper->create = oper->oper.create; + cache_oper->readdir = oper->oper.readdir; } struct fuse_operations *cache_init(struct fuse_cache_operations *oper) @@ -409,6 +410,7 @@ struct fuse_operations *cache_init(struct fuse_cache_operations *oper) cache_oper.utimens = oper->oper.utimens ? cache_utimens : NULL; cache_oper.write = oper->oper.write ? cache_write : NULL; cache_oper.create = oper->oper.create ? cache_create : NULL; + // TODO: cache `readdir` pthread_mutex_init(&cache.lock, NULL); cache.table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_node); diff --git a/cache.h b/cache.h index 6edcff1..da3879a 100644 --- a/cache.h +++ b/cache.h @@ -23,7 +23,6 @@ typedef int (*fuse_cache_dirfil_t) (fuse_cache_dirh_t h, const char *name, struct fuse_cache_operations { struct fuse_operations oper; - int (*cache_getdir) (const char *, fuse_cache_dirh_t, fuse_cache_dirfil_t); }; struct fuse_operations *cache_init(struct fuse_cache_operations *oper); diff --git a/ftpfs-ls.c b/ftpfs-ls.c index 15f83a2..63d6509 100644 --- a/ftpfs-ls.c +++ b/ftpfs-ls.c @@ -190,7 +190,7 @@ static int parse_dir_netware(const char *line, int parse_dir(const char* list, const char* dir, const char* name, struct stat* sbuf, char* linkbuf, int linklen, - fuse_cache_dirh_t h, fuse_cache_dirfil_t filler) { + void *dbuf, fuse_cache_dirfil_t filler) { char *file; char *link; const char *start = list; @@ -253,9 +253,9 @@ int parse_dir(const char* list, const char* dir, free(reallink); } - if (h && filler) { + if (dbuf && filler) { DEBUG(1, "filler: %s\n", file); - filler(h, file, &stat_buf); + filler(dbuf, file, &stat_buf); } else { DEBUG(1, "cache_add_attr: %s\n", full_path); cache_add_attr(full_path, &stat_buf); diff --git a/ftpfs-ls.h b/ftpfs-ls.h index 0ec087e..17a1456 100644 --- a/ftpfs-ls.h +++ b/ftpfs-ls.h @@ -14,6 +14,6 @@ int parse_dir(const char* list, const char* dir, const char* name, struct stat* sbuf, char* linkbuf, int linklen, - fuse_cache_dirh_t h, fuse_cache_dirfil_t filler); + void *dbuf, fuse_cache_dirfil_t filler); #endif /* __CURLFTPFS_FTPFS_LS_H__ */ diff --git a/ftpfs.c b/ftpfs.c index e9234ee..c982636 100644 --- a/ftpfs.c +++ b/ftpfs.c @@ -266,13 +266,17 @@ static size_t read_data(void *ptr, size_t size, size_t nmemb, void *data) { }\ }while(0) -static int ftpfs_getdir(const char* path, fuse_cache_dirh_t h, - fuse_cache_dirfil_t filler) { +static int ftpfs_readdir(const char* path, void *dbuf, fuse_fill_dir_t filler, + off_t offset, struct fuse_file_info *fi, + enum fuse_readdir_flags flags) { + // N.B.: fuse.h tells us that we can ignore `offset` and pass 0 to the filler where it would expect an offset. + // fuse_cache_dirfil_t handle = (struct dir_handle*) fi->fh; //< set by us in `open` + int err = 0; CURLcode curl_res; char* dir_path = get_fulldir_path(path); - DEBUG(1, "ftpfs_getdir: %s\n", dir_path); + DEBUG(1, "ftpfs_readdir: %s\n", dir_path); struct buffer buf; buf_init(&buf); @@ -289,12 +293,12 @@ static int ftpfs_getdir(const char* path, fuse_cache_dirh_t h, } else { buf_null_terminate(&buf); parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1, - NULL, NULL, NULL, 0, h, filler); + NULL, NULL, NULL, 0, dbuf, filler); } free(dir_path); buf_free(&buf); - return op_return(err, "ftpfs_getdir"); + return op_return(err, "ftpfs_readdir"); } static int ftpfs_getattr(const char* path, struct stat* sbuf, struct fuse_file_info* fi) { @@ -1361,6 +1365,15 @@ static int ftpfs_statfs(const char *path, struct statvfs *buf) return op_return(0, "ftpfs_statfs"); } +// static void *ftpfs_init(struct fuse_conn_info *conn, +// struct fuse_config *cfg) +// { +// // alternatively, mount with `-o readdirplus=no` +// conn->want &= ~FUSE_CAP_READDIRPLUS; +// // alternatively, mount with `-o sync_read` +// conn->want &= ~FUSE_CAP_ASYNC_READ; +// } + static struct fuse_cache_operations ftpfs_oper = { .oper = { // .init = ftpfs_init, @@ -1384,8 +1397,8 @@ static struct fuse_cache_operations ftpfs_oper = { .write = ftpfs_write, .statfs = ftpfs_statfs, .create = ftpfs_create, + .readdir = ftpfs_readdir, }, - .cache_getdir = ftpfs_getdir, }; static int curlftpfs_fuse_main(struct fuse_args *args)