1 Commits

Author SHA1 Message Date
c6c017b188 WIP: port to fuse3 2024-08-06 02:54:05 +00:00
5 changed files with 15 additions and 25 deletions

View File

@@ -385,7 +385,6 @@ 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)
@@ -410,7 +409,6 @@ 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);

View File

@@ -12,6 +12,10 @@
#include <fuse.h>
#include <fuse_opt.h>
#ifndef FUSE_VERSION
#define FUSE_VERSION (FUSE_MAJOR_VERSION * 10 + FUSE_MINOR_VERSION)
#endif
#define DEFAULT_CACHE_TIMEOUT 10
#define MAX_CACHE_SIZE 10000
#define MIN_CACHE_CLEAN_INTERVAL 5
@@ -23,6 +27,7 @@ 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);

View File

@@ -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,
void *dbuf, fuse_cache_dirfil_t filler) {
fuse_cache_dirh_t h, 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 (dbuf && filler) {
if (h && filler) {
DEBUG(1, "filler: %s\n", file);
filler(dbuf, file, &stat_buf);
filler(h, file, &stat_buf);
} else {
DEBUG(1, "cache_add_attr: %s\n", full_path);
cache_add_attr(full_path, &stat_buf);

View File

@@ -14,6 +14,6 @@
int parse_dir(const char* list, const char* dir,
const char* name, struct stat* sbuf,
char* linkbuf, int linklen,
void *dbuf, fuse_cache_dirfil_t filler);
fuse_cache_dirh_t h, fuse_cache_dirfil_t filler);
#endif /* __CURLFTPFS_FTPFS_LS_H__ */

25
ftpfs.c
View File

@@ -266,17 +266,13 @@ static size_t read_data(void *ptr, size_t size, size_t nmemb, void *data) {
}\
}while(0)
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`
static int ftpfs_getdir(const char* path, fuse_cache_dirh_t h,
fuse_cache_dirfil_t filler) {
int err = 0;
CURLcode curl_res;
char* dir_path = get_fulldir_path(path);
DEBUG(1, "ftpfs_readdir: %s\n", dir_path);
DEBUG(1, "ftpfs_getdir: %s\n", dir_path);
struct buffer buf;
buf_init(&buf);
@@ -293,12 +289,12 @@ static int ftpfs_readdir(const char* path, void *dbuf, fuse_fill_dir_t filler,
} else {
buf_null_terminate(&buf);
parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1,
NULL, NULL, NULL, 0, dbuf, filler);
NULL, NULL, NULL, 0, h, filler);
}
free(dir_path);
buf_free(&buf);
return op_return(err, "ftpfs_readdir");
return op_return(err, "ftpfs_getdir");
}
static int ftpfs_getattr(const char* path, struct stat* sbuf, struct fuse_file_info* fi) {
@@ -1365,15 +1361,6 @@ 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,
@@ -1397,8 +1384,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)