From 8c649d33eeb75236fcd05167179949212ce46fd8 Mon Sep 17 00:00:00 2001 From: trapexit Date: Wed, 17 Sep 2025 23:51:16 -0400 Subject: [PATCH] Start using std::filesystem::path for fusepath (#1522) --- libfuse/lib/fuse.cpp | 247 ++++++++++++++++++---------------- src/branches.cpp | 4 +- src/branches.hpp | 4 +- src/config.cpp | 11 +- src/config.hpp | 8 +- src/config_inodecalc.cpp | 2 +- src/dirinfo.hpp | 24 +++- src/fh.hpp | 13 +- src/fileinfo.hpp | 44 ++++-- src/from_string.cpp | 2 +- src/from_string.hpp | 5 +- src/fs_acl.cpp | 8 +- src/fs_acl.hpp | 4 +- src/fs_clonepath.cpp | 62 +++------ src/fs_clonepath.hpp | 26 ++-- src/fs_copyfile.cpp | 13 +- src/fs_copyfile.hpp | 15 +-- src/fs_cow.cpp | 6 +- src/fs_cow.hpp | 6 +- src/fs_eaccess.hpp | 9 ++ src/fs_exists.hpp | 44 +++--- src/fs_faccessat.hpp | 25 +++- src/fs_fchmodat.hpp | 27 +++- src/fs_fgetxattr.hpp | 1 + src/fs_findallfiles.cpp | 6 +- src/fs_findallfiles.hpp | 8 +- src/fs_findonfs.cpp | 6 +- src/fs_fstatat.hpp | 28 ++++ src/fs_inode.cpp | 58 ++++---- src/fs_inode.hpp | 17 ++- src/fs_is_rofs.hpp | 9 +- src/fs_mkdir.hpp | 11 +- src/fs_mktemp.cpp | 52 ++++--- src/fs_mktemp.hpp | 16 ++- src/fs_mounts.hpp | 2 +- src/fs_movefile_and_open.cpp | 28 ++-- src/fs_movefile_and_open.hpp | 11 +- src/fs_openat.hpp | 10 +- src/fs_path.cpp | 42 ------ src/fs_path.hpp | 66 +-------- src/fs_pathvector.hpp | 10 -- src/fs_wait_for_mount.cpp | 37 +++-- src/fs_wait_for_mount.hpp | 6 +- src/fuse_access.cpp | 62 ++++----- src/fuse_bmap.cpp | 23 ++-- src/fuse_chmod.cpp | 140 ++++++++++--------- src/fuse_chmod.hpp | 2 + src/fuse_chown.cpp | 156 +++++++++++---------- src/fuse_chown.hpp | 2 + src/fuse_copy_file_range.cpp | 70 +++++----- src/fuse_copy_file_range.hpp | 12 ++ src/fuse_create.cpp | 67 +++++---- src/fuse_destroy.cpp | 9 +- src/fuse_fallocate.cpp | 20 ++- src/fuse_fchmod.cpp | 4 +- src/fuse_fchown.cpp | 4 +- src/fuse_fgetattr.cpp | 4 +- src/fuse_flock.cpp | 19 ++- src/fuse_flush.cpp | 2 +- src/fuse_fsync.cpp | 2 +- src/fuse_fsyncdir.cpp | 2 +- src/fuse_ftruncate.cpp | 4 +- src/fuse_futimens.cpp | 4 +- src/fuse_getattr.cpp | 32 +++-- src/fuse_getattr.hpp | 8 ++ src/fuse_getxattr.cpp | 30 +++-- src/fuse_init.cpp | 4 +- src/fuse_ioctl.cpp | 10 +- src/fuse_link.cpp | 97 ++++++------- src/fuse_listxattr.cpp | 24 ++-- src/fuse_lock.cpp | 15 +-- src/fuse_mkdir.cpp | 33 ++--- src/fuse_mknod.cpp | 39 +++--- src/fuse_open.cpp | 59 ++++---- src/fuse_opendir.cpp | 6 +- src/fuse_poll.cpp | 23 ++-- src/fuse_read.cpp | 2 +- src/fuse_readdir.cpp | 2 +- src/fuse_readdir_cor.cpp | 247 +++++++++++++++++----------------- src/fuse_readdir_cosr.cpp | 246 +++++++++++++++++---------------- src/fuse_readdir_seq.cpp | 13 +- src/fuse_readlink.cpp | 39 +++--- src/fuse_release.cpp | 2 +- src/fuse_releasedir.cpp | 2 +- src/fuse_removexattr.cpp | 26 ++-- src/fuse_rename.cpp | 94 +++++++------ src/fuse_rmdir.cpp | 18 ++- src/fuse_setxattr.cpp | 41 +++--- src/fuse_statfs.cpp | 26 ++-- src/fuse_statx_supported.icpp | 43 ++++-- src/fuse_symlink.cpp | 48 ++++--- src/fuse_symlink.hpp | 11 ++ src/fuse_truncate.cpp | 23 ++-- src/fuse_unlink.cpp | 12 +- src/fuse_utimens.cpp | 19 ++- src/fuse_write.cpp | 2 +- src/mergerfs.cpp | 7 +- src/option_parser.cpp | 15 +-- src/policy.hpp | 45 ++----- src/policy_all.cpp | 6 +- src/policy_all.hpp | 6 +- src/policy_epall.cpp | 12 +- src/policy_epall.hpp | 6 +- src/policy_epff.cpp | 12 +- src/policy_epff.hpp | 6 +- src/policy_eplfs.cpp | 16 +-- src/policy_eplfs.hpp | 6 +- src/policy_eplus.cpp | 18 +-- src/policy_eplus.hpp | 6 +- src/policy_epmfs.cpp | 15 +-- src/policy_epmfs.hpp | 6 +- src/policy_eppfrd.cpp | 18 +-- src/policy_eppfrd.hpp | 6 +- src/policy_eprand.cpp | 7 +- src/policy_eprand.hpp | 6 +- src/policy_erofs.cpp | 6 +- src/policy_erofs.hpp | 6 +- src/policy_ff.cpp | 6 +- src/policy_ff.hpp | 6 +- src/policy_lfs.cpp | 6 +- src/policy_lfs.hpp | 6 +- src/policy_lus.cpp | 6 +- src/policy_lus.hpp | 6 +- src/policy_mfs.cpp | 6 +- src/policy_mfs.hpp | 6 +- src/policy_msplfs.cpp | 15 ++- src/policy_msplfs.hpp | 6 +- src/policy_msplus.cpp | 15 +-- src/policy_msplus.hpp | 6 +- src/policy_mspmfs.cpp | 17 +-- src/policy_mspmfs.hpp | 6 +- src/policy_msppfrd.cpp | 17 ++- src/policy_msppfrd.hpp | 6 +- src/policy_newest.cpp | 12 +- src/policy_newest.hpp | 6 +- src/policy_pfrd.cpp | 8 +- src/policy_pfrd.hpp | 6 +- src/policy_rand.cpp | 6 +- src/policy_rand.hpp | 6 +- 139 files changed, 1698 insertions(+), 1650 deletions(-) delete mode 100644 src/fs_pathvector.hpp diff --git a/libfuse/lib/fuse.cpp b/libfuse/lib/fuse.cpp index a0c702cc..f94e0845 100644 --- a/libfuse/lib/fuse.cpp +++ b/libfuse/lib/fuse.cpp @@ -833,13 +833,21 @@ unlock_path(struct fuse *f, } } +/* + Throughout this file all calls to the op.func() callbacks will be + '&fusepath[1]' because the current path generation always prefixes a + '/' for each path but we need a relative path for usage with + `openat()` functions and would rather do that here than in the + called function. + */ + static int try_get_path(struct fuse *f, uint64_t nodeid, const char *name, char **path, - node_t **wnodep, + node_t **wnodep, bool need_lock) { unsigned bufsize = 256; @@ -1395,7 +1403,7 @@ int lookup_path(struct fuse *f, uint64_t nodeid, const char *name, - const char *path, + const char *fusepath, struct fuse_entry_param *e, fuse_file_info_t *fi) { @@ -1404,7 +1412,7 @@ lookup_path(struct fuse *f, memset(e,0,sizeof(struct fuse_entry_param)); rv = ((fi == NULL) ? - f->fs->op.getattr(path,&e->attr,&e->timeout) : + f->fs->op.getattr(&fusepath[1],&e->attr,&e->timeout) : f->fs->op.fgetattr(fi->fh,&e->attr,&e->timeout)); if(rv) @@ -1556,7 +1564,7 @@ fuse_lib_lookup(fuse_req_t req, { int err; uint64_t nodeid; - char *path; + char *fusepath; const char *name; struct fuse *f; node_t *dot = NULL; @@ -1597,16 +1605,16 @@ fuse_lib_lookup(fuse_req_t req, } } - err = get_path_name(f,nodeid,name,&path); + err = get_path_name(f,nodeid,name,&fusepath); if(!err) { - err = lookup_path(f,nodeid,name,path,&e,NULL); + err = lookup_path(f,nodeid,name,fusepath,&e,NULL); if(err == -ENOENT) { e.ino = 0; err = 0; } - free_path(f,nodeid,path); + free_path(f,nodeid,fusepath); } if(dot) @@ -1673,7 +1681,7 @@ fuse_lib_getattr(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; uint64_t fh; struct fuse *f; struct stat buf; @@ -1691,21 +1699,21 @@ fuse_lib_getattr(fuse_req_t req, memset(&buf,0,sizeof(buf)); err = 0; - path = NULL; + fusepath = NULL; if(fh == 0) { - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(err == -ESTALE) // unlinked but open err = 0; } if(!err) { - err = ((path != NULL) ? - f->fs->op.getattr(path,&buf,&timeout) : + err = ((fusepath != NULL) ? + f->fs->op.getattr(&fusepath[1],&buf,&timeout) : f->fs->op.fgetattr(fh,&buf,&timeout)); - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } if(!err) @@ -1743,7 +1751,7 @@ fuse_lib_statx_path(fuse_req_t req_, return; } - err = f_->fs->op.statx(fusepath, + err = f_->fs->op.statx(&fusepath[1], inarg_->sx_flags, inarg_->sx_mask, &st, @@ -1804,7 +1812,7 @@ fuse_lib_setattr(fuse_req_t req, uint64_t fh; struct fuse *f = req_fuse_prepare(req); struct stat stbuf = {0}; - char *path; + char *fusepath; int err; fuse_timeouts_t timeout; struct fuse_setattr_in *arg; @@ -1816,10 +1824,10 @@ fuse_lib_setattr(fuse_req_t req, fh = arg->fh; err = 0; - path = NULL; + fusepath = NULL; if(fh == 0) { - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(err == -ESTALE) err = 0; } @@ -1828,8 +1836,8 @@ fuse_lib_setattr(fuse_req_t req, { err = 0; if(!err && (arg->valid & FATTR_MODE)) - err = ((path != NULL) ? - f->fs->op.chmod(path,arg->mode) : + err = ((fusepath != NULL) ? + f->fs->op.chmod(&fusepath[1],arg->mode) : f->fs->op.fchmod(fh,arg->mode)); if(!err && (arg->valid & (FATTR_UID | FATTR_GID))) @@ -1837,14 +1845,14 @@ fuse_lib_setattr(fuse_req_t req, uid_t uid = ((arg->valid & FATTR_UID) ? arg->uid : (uid_t)-1); gid_t gid = ((arg->valid & FATTR_GID) ? arg->gid : (gid_t)-1); - err = ((path != NULL) ? - f->fs->op.chown(path,uid,gid) : + err = ((fusepath != NULL) ? + f->fs->op.chown(&fusepath[1],uid,gid) : f->fs->op.fchown(fh,uid,gid)); } if(!err && (arg->valid & FATTR_SIZE)) - err = ((path != NULL) ? - f->fs->op.truncate(path,arg->size) : + err = ((fusepath != NULL) ? + f->fs->op.truncate(&fusepath[1],arg->size) : f->fs->op.ftruncate(fh,arg->size)); if(!err && (arg->valid & (FATTR_ATIME | FATTR_MTIME))) @@ -1866,8 +1874,8 @@ fuse_lib_setattr(fuse_req_t req, else if(arg->valid & FATTR_MTIME) tv[1] = (struct timespec){ static_cast(arg->mtime), arg->mtimensec }; - err = ((path != NULL) ? - f->fs->op.utimens(path,tv) : + err = ((fusepath != NULL) ? + f->fs->op.utimens(&fusepath[1],tv) : f->fs->op.futimens(fh,tv)); } else if(!err && ((arg->valid & (FATTR_ATIME|FATTR_MTIME)) == (FATTR_ATIME|FATTR_MTIME))) @@ -1877,17 +1885,17 @@ fuse_lib_setattr(fuse_req_t req, tv[0].tv_nsec = arg->atimensec; tv[1].tv_sec = arg->mtime; tv[1].tv_nsec = arg->mtimensec; - err = ((path != NULL) ? - f->fs->op.utimens(path,tv) : + err = ((fusepath != NULL) ? + f->fs->op.utimens(&fusepath[1],tv) : f->fs->op.futimens(fh,tv)); } if(!err) - err = ((path != NULL) ? - f->fs->op.getattr(path,&stbuf,&timeout) : + err = ((fusepath != NULL) ? + f->fs->op.getattr(&fusepath[1],&stbuf,&timeout) : f->fs->op.fgetattr(fh,&stbuf,&timeout)); - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } if(!err) @@ -1910,7 +1918,7 @@ fuse_lib_access(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; struct fuse_access_in *arg; @@ -1918,11 +1926,11 @@ fuse_lib_access(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.access(path,arg->mask); - free_path(f,hdr_->nodeid,path); + err = f->fs->op.access(&fusepath[1],arg->mask); + free_path(f,hdr_->nodeid,fusepath); } fuse_reply_err(req,err); @@ -1934,17 +1942,17 @@ fuse_lib_readlink(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; char linkname[PATH_MAX + 1]; f = req_fuse_prepare(req); - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.readlink(path,linkname,sizeof(linkname)); - free_path(f,hdr_->nodeid,path); + err = f->fs->op.readlink(&fusepath[1],linkname,sizeof(linkname)); + free_path(f,hdr_->nodeid,fusepath); } if(!err) @@ -1964,7 +1972,7 @@ fuse_lib_mknod(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; const char* name; struct fuse_entry_param e; @@ -1979,7 +1987,7 @@ fuse_lib_mknod(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path_name(f,hdr_->nodeid,name,&path); + err = get_path_name(f,hdr_->nodeid,name,&fusepath); if(!err) { err = -ENOSYS; @@ -1989,22 +1997,22 @@ fuse_lib_mknod(fuse_req_t req, memset(&fi,0,sizeof(fi)); fi.flags = O_CREAT | O_EXCL | O_WRONLY; - err = f->fs->op.create(path,arg->mode,&fi); + err = f->fs->op.create(&fusepath[1],arg->mode,&fi); if(!err) { - err = lookup_path(f,hdr_->nodeid,name,path,&e,&fi); + err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,&fi); f->fs->op.release(&fi); } } if(err == -ENOSYS) { - err = f->fs->op.mknod(path,arg->mode,arg->rdev); + err = f->fs->op.mknod(&fusepath[1],arg->mode,arg->rdev); if(!err) - err = lookup_path(f,hdr_->nodeid,name,path,&e,NULL); + err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,NULL); } - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } reply_entry(req,&e,err); @@ -2016,7 +2024,7 @@ fuse_lib_mkdir(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; const char *name; struct fuse_entry_param e; @@ -2029,13 +2037,13 @@ fuse_lib_mkdir(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path_name(f,hdr_->nodeid,name,&path); + err = get_path_name(f,hdr_->nodeid,name,&fusepath); if(!err) { - err = f->fs->op.mkdir(path,arg->mode); + err = f->fs->op.mkdir(&fusepath[1],arg->mode); if(!err) - err = lookup_path(f,hdr_->nodeid,name,path,&e,NULL); - free_path(f,hdr_->nodeid,path); + err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,NULL); + free_path(f,hdr_->nodeid,fusepath); } reply_entry(req,&e,err); @@ -2047,7 +2055,7 @@ fuse_lib_unlink(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; const char *name; node_t *wnode; @@ -2055,18 +2063,18 @@ fuse_lib_unlink(fuse_req_t req, name = (const char*)PARAM(hdr_); f = req_fuse_prepare(req); - err = get_path_wrlock(f,hdr_->nodeid,name,&path,&wnode); + err = get_path_wrlock(f,hdr_->nodeid,name,&fusepath,&wnode); if(!err) { if(node_open(wnode)) fuse_get_context()->nodeid = wnode->nodeid; - err = f->fs->op.unlink(path); + err = f->fs->op.unlink(&fusepath[1]); if(!err) remove_node(f,hdr_->nodeid,name); - free_path_wrlock(f,hdr_->nodeid,wnode,path); + free_path_wrlock(f,hdr_->nodeid,wnode,fusepath); } fuse_reply_err(req,err); @@ -2078,7 +2086,7 @@ fuse_lib_rmdir(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; const char *name; node_t *wnode; @@ -2087,13 +2095,13 @@ fuse_lib_rmdir(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path_wrlock(f,hdr_->nodeid,name,&path,&wnode); + err = get_path_wrlock(f,hdr_->nodeid,name,&fusepath,&wnode); if(!err) { - err = f->fs->op.rmdir(path); + err = f->fs->op.rmdir(&fusepath[1]); if(!err) remove_node(f,hdr_->nodeid,name); - free_path_wrlock(f,hdr_->nodeid,wnode,path); + free_path_wrlock(f,hdr_->nodeid,wnode,fusepath); } fuse_reply_err(req,err); @@ -2105,7 +2113,7 @@ fuse_lib_symlink(fuse_req_t req_, struct fuse_in_header *hdr_) { int rv; - char *path; + char *fusepath; struct fuse *f; const char *name; const char *linkname; @@ -2116,13 +2124,13 @@ fuse_lib_symlink(fuse_req_t req_, f = req_fuse_prepare(req_); - rv = get_path_name(f,hdr_->nodeid,name,&path); + rv = get_path_name(f,hdr_->nodeid,name,&fusepath); if(rv == 0) { - rv = f->fs->op.symlink(linkname,path,&e.attr,&e.timeout); + rv = f->fs->op.symlink(linkname,&fusepath[1],&e.attr,&e.timeout); if(rv == 0) rv = set_path_info(f,hdr_->nodeid,name,&e); - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } reply_entry(req_,&e,rv); @@ -2148,12 +2156,19 @@ fuse_lib_rename(fuse_req_t req, newname = (oldname + strlen(oldname) + 1); f = req_fuse_prepare(req); - err = get_path2(f,hdr_->nodeid,oldname,arg->newdir,newname, - &oldpath,&newpath,&wnode1,&wnode2); + err = get_path2(f, + hdr_->nodeid, + oldname, + arg->newdir, + newname, + &oldpath, + &newpath, + &wnode1, + &wnode2); if(!err) { - err = f->fs->op.rename(oldpath,newpath); + err = f->fs->op.rename(&oldpath[1],&newpath[1]); if(!err) err = rename_node(f,hdr_->nodeid,oldname,arg->newdir,newname); @@ -2200,12 +2215,17 @@ fuse_lib_link(fuse_req_t req, f = req_fuse_prepare(req); rv = get_path2(f, - arg->oldnodeid,NULL, - hdr_->nodeid,newname, - &oldpath,&newpath,NULL,NULL); + arg->oldnodeid, + NULL, + hdr_->nodeid, + newname, + &oldpath, + &newpath, + NULL, + NULL); if(!rv) { - rv = f->fs->op.link(oldpath,newpath,&e.attr,&e.timeout); + rv = f->fs->op.link(&oldpath[1],&newpath[1],&e.attr,&e.timeout); if(rv == 0) rv = set_path_info(f,hdr_->nodeid,newname,&e); free_path2(f,arg->oldnodeid,hdr_->nodeid,NULL,NULL,oldpath,newpath); @@ -2239,7 +2259,7 @@ fuse_lib_create(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; const char *name; uint64_t new_nodeid; @@ -2267,13 +2287,13 @@ fuse_lib_create(fuse_req_t req, fuse_get_context()->nodeid = new_nodeid; } - err = get_path_name(f,hdr_->nodeid,name,&path); + err = get_path_name(f,hdr_->nodeid,name,&fusepath); if(!err) { - err = f->fs->op.create(path,arg->mode,&ffi); + err = f->fs->op.create(&fusepath[1],arg->mode,&ffi); if(!err) { - err = lookup_path(f,hdr_->nodeid,name,path,&e,&ffi); + err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,&ffi); if(err) { f->fs->op.release(&ffi); @@ -2307,7 +2327,7 @@ fuse_lib_create(fuse_req_t req, fuse_reply_err(req,err); } - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } static @@ -2352,7 +2372,7 @@ fuse_lib_open(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; fuse_file_info_t ffi = {0}; struct fuse_open_in *arg; @@ -2363,14 +2383,14 @@ fuse_lib_open(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.open(path,&ffi); + err = f->fs->op.open(&fusepath[1],&ffi); if(!err) { if(ffi.auto_cache && (ffi.passthrough == false)) - open_auto_cache(f,hdr_->nodeid,path,&ffi); + open_auto_cache(f,hdr_->nodeid,fusepath,&ffi); } } @@ -2388,7 +2408,7 @@ fuse_lib_open(fuse_req_t req, fuse_reply_err(req,err); } - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } static @@ -2496,7 +2516,7 @@ fuse_lib_opendir(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse_dh *dh; fuse_file_info_t llffi = {0}; fuse_file_info_t ffi = {0}; @@ -2521,10 +2541,10 @@ fuse_lib_opendir(fuse_req_t req, llffi.fh = (uintptr_t)dh; ffi.flags = llffi.flags; - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.opendir(path,&ffi); + err = f->fs->op.opendir(&fusepath[1],&ffi); dh->fh = ffi.fh; llffi.keep_cache = ffi.keep_cache; llffi.cache_readdir = ffi.cache_readdir; @@ -2548,7 +2568,7 @@ fuse_lib_opendir(fuse_req_t req, free(dh); } - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } static @@ -2557,7 +2577,7 @@ readdir_buf_size(fuse_dirents_t *d_, size_t size_, off_t off_) { - if(off_ >= kv_size(d_->offs)) + if((size_t)off_ >= kv_size(d_->offs)) return 0; if((kv_A(d_->offs,off_) + size_) > kv_size(d_->data)) return (kv_size(d_->data) - kv_A(d_->offs,off_)); @@ -2723,19 +2743,20 @@ fuse_lib_statfs(fuse_req_t req, struct fuse_in_header *hdr_) { int err = 0; - char *path = NULL; + char *fusepath; struct fuse *f; struct statvfs buf = {0}; f = req_fuse_prepare(req); + fusepath = NULL; if(hdr_->nodeid) - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.statfs(path ? path : "/",&buf); - free_path(f,hdr_->nodeid,path); + err = f->fs->op.statfs(fusepath ? &fusepath[1] : "",&buf); + free_path(f,hdr_->nodeid,fusepath); } if(!err) @@ -2750,7 +2771,7 @@ fuse_lib_setxattr(fuse_req_t req, struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; const char *name; const char *value; struct fuse *f; @@ -2766,11 +2787,11 @@ fuse_lib_setxattr(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.setxattr(path,name,value,arg->size,arg->flags); - free_path(f,hdr_->nodeid,path); + err = f->fs->op.setxattr(&fusepath[1],name,value,arg->size,arg->flags); + free_path(f,hdr_->nodeid,fusepath); } fuse_reply_err(req,err); @@ -2786,14 +2807,14 @@ common_getxattr(struct fuse *f, size_t size) { int err; - char *path; + char *fusepath; - err = get_path(f,ino,&path); + err = get_path(f,ino,&fusepath); if(!err) { - err = f->fs->op.getxattr(path,name,value,size); + err = f->fs->op.getxattr(&fusepath[1],name,value,size); - free_path(f,ino,path); + free_path(f,ino,fusepath); } return err; @@ -2848,14 +2869,14 @@ common_listxattr(struct fuse *f, char *list, size_t size) { - char *path; int err; + char *fusepath; - err = get_path(f,ino,&path); + err = get_path(f,ino,&fusepath); if(!err) { - err = f->fs->op.listxattr(path,list,size); - free_path(f,ino,path); + err = f->fs->op.listxattr(&fusepath[1],list,size); + free_path(f,ino,fusepath); } return err; @@ -2906,7 +2927,7 @@ fuse_lib_removexattr(fuse_req_t req, const struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; const char *name; struct fuse *f; @@ -2914,11 +2935,11 @@ fuse_lib_removexattr(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.removexattr(path,name); - free_path(f,hdr_->nodeid,path); + err = f->fs->op.removexattr(&fusepath[1],name); + free_path(f,hdr_->nodeid,fusepath); } fuse_reply_err(req,err); @@ -2988,7 +3009,7 @@ fuse_lib_tmpfile(fuse_req_t req_, const struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; const char *name; fuse_file_info_t ffi = {0}; @@ -3007,13 +3028,13 @@ fuse_lib_tmpfile(fuse_req_t req_, f = req_fuse_prepare(req_); - err = get_path_name(f,hdr_->nodeid,name,&path); + err = get_path_name(f,hdr_->nodeid,name,&fusepath); if(!err) { - err = f->fs->op.tmpfile(path,arg->mode,&ffi); + err = f->fs->op.tmpfile(&fusepath[1],arg->mode,&ffi); if(!err) { - err = lookup_path(f,hdr_->nodeid,name,path,&e,&ffi); + err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,&ffi); if(err) { f->fs->op.release(&ffi); @@ -3046,7 +3067,7 @@ fuse_lib_tmpfile(fuse_req_t req_, fuse_reply_err(req_,err); } - free_path(f,hdr_->nodeid,path); + free_path(f,hdr_->nodeid,fusepath); } static @@ -3404,7 +3425,7 @@ fuse_lib_bmap(fuse_req_t req, const struct fuse_in_header *hdr_) { int err; - char *path; + char *fusepath; struct fuse *f; uint64_t block; const struct fuse_bmap_in *arg; @@ -3414,11 +3435,11 @@ fuse_lib_bmap(fuse_req_t req, f = req_fuse_prepare(req); - err = get_path(f,hdr_->nodeid,&path); + err = get_path(f,hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.bmap(path,arg->blocksize,&block); - free_path(f,hdr_->nodeid,path); + err = f->fs->op.bmap(&fusepath[1],arg->blocksize,&block); + free_path(f,hdr_->nodeid,fusepath); } if(!err) diff --git a/src/branches.cpp b/src/branches.cpp index d64941bb..c93aae71 100644 --- a/src/branches.cpp +++ b/src/branches.cpp @@ -391,10 +391,10 @@ Branches::Impl::to_paths(StrVec &paths_) const } } -fs::PathVector +std::vector Branches::Impl::to_paths() const { - fs::PathVector vp; + std::vector vp; for(const auto &branch : *this) vp.emplace_back(branch.path); diff --git a/src/branches.hpp b/src/branches.hpp index 157cc285..e8fc50ff 100644 --- a/src/branches.hpp +++ b/src/branches.hpp @@ -19,7 +19,7 @@ #pragma once #include "branch.hpp" -#include "fs_pathvector.hpp" +#include "fs_path.hpp" #include "strvec.hpp" #include "tofrom_string.hpp" @@ -52,7 +52,7 @@ public: public: const u64 &minfreespace(void) const; void to_paths(StrVec &strvec) const; - fs::PathVector to_paths() const; + std::vector to_paths() const; public: Impl& operator=(Impl &impl_); diff --git a/src/config.cpp b/src/config.cpp index d3644ee9..f248c395 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -18,12 +18,13 @@ #include "ef.hpp" #include "errno.hpp" #include "from_string.hpp" +#include "fs_path.hpp" +#include "nonstd/string.hpp" #include "num.hpp" #include "rwlock.hpp" #include "str.hpp" #include "to_string.hpp" #include "version.hpp" -#include "nonstd/string.hpp" #include #include @@ -428,15 +429,15 @@ Config::finish_initializing() } bool -Config::is_rootdir(const char *fusepath_) +Config::is_rootdir(const fs::path &fusepath_) { - return str::eq(fusepath_,"/"); + return fusepath_.empty(); } bool -Config::is_ctrl_file(const char *fusepath_) +Config::is_ctrl_file(const fs::path &fusepath_) { - return str::eq(fusepath_,"/.mergerfs"); + return (fusepath_ == ".mergerfs"); } bool diff --git a/src/config.hpp b/src/config.hpp index 17c657fb..bcd40f32 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -37,6 +37,7 @@ #include "config_xattr.hpp" #include "enum.hpp" #include "errno.hpp" +#include "fs_path.hpp" #include "funcs.hpp" #include "fuse_readdir.hpp" #include "policy.hpp" @@ -46,7 +47,6 @@ #include "fuse.h" #include -#include #include #include #include @@ -59,7 +59,7 @@ typedef ToFromWrapper ConfigUINT64; typedef ToFromWrapper ConfigS64; typedef ToFromWrapper ConfigINT; typedef ToFromWrapper ConfigSTR; -typedef ToFromWrapper ConfigPath; +typedef ToFromWrapper ConfigPath; typedef std::map Str2TFStrMap; extern const std::string CONTROLFILE; @@ -173,8 +173,8 @@ public: int from_file(const std::string &filepath, ErrVec *errs); public: - static bool is_rootdir(const char *fusepath); - static bool is_ctrl_file(const char *fusepath); + static bool is_rootdir(const fs::path &fusepath); + static bool is_ctrl_file(const fs::path &fusepath); static bool is_mergerfs_xattr(const char *attrname); static bool is_cmd_xattr(const std::string_view &attrname); static std::string prune_ctrl_xattr(const std::string &s); diff --git a/src/config_inodecalc.cpp b/src/config_inodecalc.cpp index e74b56d3..aa0303f9 100644 --- a/src/config_inodecalc.cpp +++ b/src/config_inodecalc.cpp @@ -34,5 +34,5 @@ InodeCalc::to_string(void) const int InodeCalc::from_string(const std::string_view s_) { - return fs::inode::set_algo(s_); + return fs::inode::set_algo(std::string{s_}); } diff --git a/src/dirinfo.hpp b/src/dirinfo.hpp index 7048fbf4..d9b67755 100644 --- a/src/dirinfo.hpp +++ b/src/dirinfo.hpp @@ -18,14 +18,32 @@ #include "fh.hpp" -#include - class DirInfo : public FH { public: - DirInfo(const char *fusepath_) + static DirInfo *from_fh(const uint64_t fh); + +public: + uint64_t to_fh() const; + +public: + DirInfo(const fs::path &fusepath_) : FH(fusepath_) { } }; + +inline +uint64_t +DirInfo::to_fh() const +{ + return reinterpret_cast(this); +} + +inline +DirInfo* +DirInfo::from_fh(const uint64_t fh_) +{ + return reinterpret_cast(fh_); +} diff --git a/src/fh.hpp b/src/fh.hpp index 816eee0f..ff2f8b2a 100644 --- a/src/fh.hpp +++ b/src/fh.hpp @@ -16,23 +16,18 @@ #pragma once -#include +#include "fs_path.hpp" class FH { public: - FH(const std::string fusepath_) - : fusepath(std::move(fusepath_)) - { - - } - - FH(const char *fusepath_) + FH(const fs::path &fusepath_) : fusepath(fusepath_) { + } public: - std::string fusepath; + fs::path fusepath; }; diff --git a/src/fileinfo.hpp b/src/fileinfo.hpp index 3a54ba85..c733835e 100644 --- a/src/fileinfo.hpp +++ b/src/fileinfo.hpp @@ -16,10 +16,10 @@ #pragma once -#include "fh.hpp" #include "branch.hpp" +#include "fh.hpp" +#include "fs_path.hpp" -#include #include #include "int_types.h" @@ -28,24 +28,27 @@ class FileInfo : public FH { public: - FileInfo(const int fd_, - const Branch &branch_, - const char *fusepath_, - const bool direct_io_) + static FileInfo *from_fh(const uint64_t fh); + +public: + FileInfo(const int fd_, + const Branch *branch_, + const fs::path &fusepath_, + const bool direct_io_) : FH(fusepath_), fd(fd_), - branch(branch_), + branch(*branch_), direct_io(direct_io_) { } - FileInfo(const int fd_, - const Branch *branch_, - const char *fusepath_, - const bool direct_io_) + FileInfo(const int fd_, + const Branch &branch_, + const fs::path &fusepath_, + const bool direct_io_) : FH(fusepath_), fd(fd_), - branch(*branch_), + branch(branch_), direct_io(direct_io_) { } @@ -58,9 +61,26 @@ public: { } +public: + uint64_t to_fh() const; + public: int fd; Branch branch; u32 direct_io:1; std::mutex mutex; }; + +inline +uint64_t +FileInfo::to_fh() const +{ + return reinterpret_cast(this); +} + +inline +FileInfo* +FileInfo::from_fh(const uintptr_t fh_) +{ + return reinterpret_cast(fh_); +} diff --git a/src/from_string.cpp b/src/from_string.cpp index 5d7f1ed4..2b311c1e 100644 --- a/src/from_string.cpp +++ b/src/from_string.cpp @@ -187,7 +187,7 @@ str::from(const std::string_view value_, int str::from(const std::string_view value_, - std::filesystem::path *path_) + fs::path *path_) { *path_ = value_; diff --git a/src/from_string.hpp b/src/from_string.hpp index 16bbd5aa..fae06634 100644 --- a/src/from_string.hpp +++ b/src/from_string.hpp @@ -18,8 +18,9 @@ #pragma once +#include "fs_path.hpp" + #include -#include #include #include @@ -32,5 +33,5 @@ namespace str int from(const std::string_view, int64_t *); int from(const std::string_view, std::string *); int from(const std::string_view, const std::string *); - int from(const std::string_view, std::filesystem::path *); + int from(const std::string_view, fs::path *); } diff --git a/src/fs_acl.cpp b/src/fs_acl.cpp index 818f193c..dbc30aff 100644 --- a/src/fs_acl.cpp +++ b/src/fs_acl.cpp @@ -21,18 +21,18 @@ #include "fs_lgetxattr.hpp" #include "fs_path.hpp" -#include +#include constexpr const char POSIX_ACL_DEFAULT_XATTR[] = "system.posix_acl_default"; bool -fs::acl::dir_has_defaults(const std::string &fullpath_) +fs::acl::dir_has_defaults(const fs::path &fullpath_) { int rv; - std::string dirpath; + fs::path dirpath; - dirpath = fs::path::dirname(fullpath_); + dirpath = fullpath_.parent_path(); rv = fs::lgetxattr(dirpath,POSIX_ACL_DEFAULT_XATTR,NULL,0); diff --git a/src/fs_acl.hpp b/src/fs_acl.hpp index 92fef84b..f9e81b20 100644 --- a/src/fs_acl.hpp +++ b/src/fs_acl.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include "fs_path.hpp" namespace fs @@ -26,6 +26,6 @@ namespace fs namespace acl { bool - dir_has_defaults(const std::string &fullpath); + dir_has_defaults(const fs::path &fullpath); } } diff --git a/src/fs_clonepath.cpp b/src/fs_clonepath.cpp index 5827597e..423b9d46 100644 --- a/src/fs_clonepath.cpp +++ b/src/fs_clonepath.cpp @@ -27,10 +27,6 @@ #include "fs_xattr.hpp" #include "ugid.hpp" -#include - -using std::string; - static bool @@ -56,36 +52,36 @@ _ignorable_error(const int err_) possible. Optionally ignore errors on metadata copies. */ int -fs::clonepath(const string &srcpath_, - const string &dstpath_, - const char *relpath_, - const bool return_metadata_errors_) +fs::clonepath(const fs::path &srcpath_, + const fs::path &dstpath_, + const fs::path &relpath_, + const bool return_metadata_errors_) { int rv; struct stat st; - string dstpath; - string srcpath; - string dirname; + fs::path dstpath; + fs::path srcpath; + fs::path dirname; - if((relpath_ == NULL) || (relpath_[0] == '\0')) + if(relpath_.empty()) return 0; - dirname = fs::path::dirname(relpath_); - if(dirname != "/") + dirname = relpath_.parent_path(); + if(!dirname.empty()) { rv = fs::clonepath(srcpath_,dstpath_,dirname,return_metadata_errors_); if(rv < 0) return rv; } - srcpath = fs::path::make(srcpath_,relpath_); + srcpath = srcpath_ / relpath_; rv = fs::lstat(srcpath,&st); if(rv < 0) return rv; else if(!S_ISDIR(st.st_mode)) return -ENOTDIR; - dstpath = fs::path::make(dstpath_,relpath_); + dstpath = dstpath_ / relpath_; rv = fs::mkdir(dstpath,st.st_mode); if(rv < 0) return ((rv == -EEXIST) ? 0 : rv); @@ -112,24 +108,12 @@ fs::clonepath(const string &srcpath_, } int -fs::clonepath(const string &srcpath_, - const string &dstpath_, - const string &relpath_, - const bool return_metadata_errors_) +fs::clonepath_as_root(const fs::path &srcpath_, + const fs::path &dstpath_, + const fs::path &relpath_, + const bool return_metadata_errors_) { - return fs::clonepath(srcpath_, - dstpath_, - relpath_.c_str(), - return_metadata_errors_); -} - -int -fs::clonepath_as_root(const string &srcpath_, - const string &dstpath_, - const char *relpath_, - const bool return_metadata_errors_) -{ - if((relpath_ == NULL) || (relpath_[0] == '\0')) + if(relpath_.empty()) return 0; if(srcpath_ == dstpath_) return 0; @@ -141,15 +125,3 @@ fs::clonepath_as_root(const string &srcpath_, relpath_, return_metadata_errors_); } - -int -fs::clonepath_as_root(const string &srcpath_, - const string &dstpath_, - const string &relpath_, - const bool return_metadata_errors_) -{ - return fs::clonepath_as_root(srcpath_, - dstpath_, - relpath_.c_str(), - return_metadata_errors_); -} diff --git a/src/fs_clonepath.hpp b/src/fs_clonepath.hpp index 00b717f3..3bd1a8c5 100644 --- a/src/fs_clonepath.hpp +++ b/src/fs_clonepath.hpp @@ -16,26 +16,18 @@ #pragma once -#include +#include "fs_path.hpp" namespace fs { - int clonepath(const std::string &srcpath, - const std::string &dstpath, - const char *relpath, - const bool return_metadata_errors = false); - int clonepath(const std::string &srcpath, - const std::string &dstpath, - const std::string &relpath, - const bool return_metadata_errors = false); + int clonepath(const fs::path &srcpath, + const fs::path &dstpath, + const fs::path &relpath, + const bool return_metadata_errors = false); - int clonepath_as_root(const std::string &srcpath, - const std::string &dstpath, - const char *relpath, - const bool return_metadata_errors = false); - int clonepath_as_root(const std::string &srcpath, - const std::string &dstpath, - const std::string &relpath, - const bool return_metadata_errors = false); + int clonepath_as_root(const fs::path &srcpath, + const fs::path &dstpath, + const fs::path &relpath, + const bool return_metadata_errors = false); } diff --git a/src/fs_copyfile.cpp b/src/fs_copyfile.cpp index fc36388c..e6949a99 100644 --- a/src/fs_copyfile.cpp +++ b/src/fs_copyfile.cpp @@ -29,6 +29,7 @@ #include "fs_futimens.hpp" #include "fs_mktemp.hpp" #include "fs_open.hpp" +#include "fs_path.hpp" #include "fs_rename.hpp" #include "fs_unlink.hpp" #include "fs_xattr.hpp" @@ -96,9 +97,9 @@ fs::copyfile(const int src_fd_, // * Does not handle non-regular files. s64 -fs::copyfile(const int src_fd_, - const std::filesystem::path &dst_filepath_, - const fs::CopyFileFlags &flags_) +fs::copyfile(const int src_fd_, + const fs::path &dst_filepath_, + const fs::CopyFileFlags &flags_) { s64 rv; int dst_fd; @@ -164,9 +165,9 @@ fs::copyfile(const int src_fd_, } s64 -fs::copyfile(const std::filesystem::path &src_filepath_, - const std::filesystem::path &dst_filepath_, - const fs::CopyFileFlags &flags_) +fs::copyfile(const fs::path &src_filepath_, + const fs::path &dst_filepath_, + const fs::CopyFileFlags &flags_) { int src_fd; diff --git a/src/fs_copyfile.hpp b/src/fs_copyfile.hpp index 75bdd168..a45d0469 100644 --- a/src/fs_copyfile.hpp +++ b/src/fs_copyfile.hpp @@ -1,8 +1,7 @@ #pragma once #include "int_types.h" - -#include +#include "fs_path.hpp" #include @@ -22,12 +21,12 @@ namespace fs const int dst_fd); s64 - copyfile(const int src_fd, - const std::filesystem::path &dst_filepath, - const CopyFileFlags &flags); + copyfile(const int src_fd, + const fs::path &dst_filepath, + const CopyFileFlags &flags); s64 - copyfile(const std::filesystem::path &src_filepath, - const std::filesystem::path &dst_filepath, - const CopyFileFlags &flags); + copyfile(const fs::path &src_filepath, + const fs::path &dst_filepath, + const CopyFileFlags &flags); } diff --git a/src/fs_cow.cpp b/src/fs_cow.cpp index 62f14cb8..5074f035 100644 --- a/src/fs_cow.cpp +++ b/src/fs_cow.cpp @@ -53,8 +53,8 @@ fs::cow::is_eligible(const int flags_, } bool -fs::cow::is_eligible(const char *fullpath_, - const int flags_) +fs::cow::is_eligible(const fs::path &fullpath_, + const int flags_) { int rv; struct stat st; @@ -70,7 +70,7 @@ fs::cow::is_eligible(const char *fullpath_, } int -fs::cow::break_link(const char *src_filepath_) +fs::cow::break_link(const fs::path &src_filepath_) { return fs::copyfile(src_filepath_, src_filepath_, diff --git a/src/fs_cow.hpp b/src/fs_cow.hpp index 7403e5d9..3f6fe6c0 100644 --- a/src/fs_cow.hpp +++ b/src/fs_cow.hpp @@ -18,6 +18,8 @@ #pragma once +#include "fs_path.hpp" + #include #include @@ -30,8 +32,8 @@ namespace fs bool is_eligible(const struct stat &st); bool is_eligible(const int flags, const struct stat &st); - bool is_eligible(const char *fullpath, const int flags); + bool is_eligible(const fs::path &fullpath, const int flags); - int break_link(const char *fullpath); + int break_link(const fs::path &fullpath); } } diff --git a/src/fs_eaccess.hpp b/src/fs_eaccess.hpp index 03f55287..07fdb9ae 100644 --- a/src/fs_eaccess.hpp +++ b/src/fs_eaccess.hpp @@ -40,4 +40,13 @@ namespace fs { return fs::eaccess(path_.c_str(),mode_); } + + static + inline + int + eaccess(const fs::path &path_, + const int mode_) + { + return fs::eaccess(path_.c_str(),mode_); + } } diff --git a/src/fs_exists.hpp b/src/fs_exists.hpp index 2abdd646..7b6151a4 100644 --- a/src/fs_exists.hpp +++ b/src/fs_exists.hpp @@ -21,16 +21,14 @@ #include "fs_lstat.hpp" #include "fs_path.hpp" -#include - namespace fs { static inline bool - exists(const std::string &path_, - struct stat *st_) + exists(const fs::path &path_, + struct stat *st_) { int rv; @@ -42,7 +40,7 @@ namespace fs static inline bool - exists(const std::string &path_) + exists(const fs::path &path_) { struct stat st; @@ -52,26 +50,27 @@ namespace fs static inline bool - exists(const std::string &basepath_, - const std::string &relpath_) + exists(const fs::path &basepath_, + const char *relpath_, + struct stat *st_) { - std::string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,relpath_); + fullpath = basepath_ / relpath_; - return fs::exists(fullpath); + return fs::exists(fullpath,st_); } static inline bool - exists(const std::string &basepath_, - const char *relpath_, - struct stat *st_) + exists(const fs::path &basepath_, + const fs::path &relpath_, + struct stat *st_) { - std::string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,relpath_); + fullpath = basepath_ / relpath_; return fs::exists(fullpath,st_); } @@ -79,8 +78,19 @@ namespace fs static inline bool - exists(const std::string &basepath_, - const char *relpath_) + exists(const fs::path &basepath_, + const char *relpath_) + { + struct stat st; + + return fs::exists(basepath_,relpath_,&st); + } + + static + inline + bool + exists(const fs::path &basepath_, + const fs::path &relpath_) { struct stat st; diff --git a/src/fs_faccessat.hpp b/src/fs_faccessat.hpp index d767b2a5..036bdec2 100644 --- a/src/fs_faccessat.hpp +++ b/src/fs_faccessat.hpp @@ -18,6 +18,7 @@ #pragma once +#include "fs_path.hpp" #include "to_neg_errno.hpp" #include @@ -38,7 +39,10 @@ namespace fs { int rv; - rv = ::faccessat(dirfd_,path_,mode_,flags_); + rv = ::faccessat(dirfd_, + path_, + mode_, + flags_); return ::to_neg_errno(rv); } @@ -51,6 +55,23 @@ namespace fs const int mode_, const int flags_) { - return fs::faccessat(dirfd_,path_.c_str(),mode_,flags_); + return fs::faccessat(dirfd_, + path_.c_str(), + mode_, + flags_); + } + + static + inline + int + faccessat(const int dirfd_, + const fs::path &path_, + const int mode_, + const int flags_) + { + return fs::faccessat(dirfd_, + path_.c_str(), + mode_, + flags_); } } diff --git a/src/fs_fchmodat.hpp b/src/fs_fchmodat.hpp index 4c092265..ad4e8549 100644 --- a/src/fs_fchmodat.hpp +++ b/src/fs_fchmodat.hpp @@ -20,8 +20,11 @@ #include "fs_fchmodat.hpp" +#include "fs_path.hpp" #include "to_neg_errno.hpp" +#include + #include #include @@ -38,7 +41,10 @@ namespace fs { int rv; - rv = ::fchmodat(dirfd_,pathname_,mode_,flags_); + rv = ::fchmodat(dirfd_, + pathname_, + mode_, + flags_); return ::to_neg_errno(rv); } @@ -51,6 +57,23 @@ namespace fs const mode_t mode_, const int flags_) { - return fs::fchmodat(dirfd_,pathname_.c_str(),mode_,flags_); + return fs::fchmodat(dirfd_, + pathname_.c_str(), + mode_, + flags_); + } + + static + inline + int + fchmodat(const int dirfd_, + const fs::path &pathname_, + const mode_t mode_, + const int flags_) + { + return fs::fchmodat(dirfd_, + pathname_.c_str(), + mode_, + flags_); } } diff --git a/src/fs_fgetxattr.hpp b/src/fs_fgetxattr.hpp index 48411b90..87c46c1d 100644 --- a/src/fs_fgetxattr.hpp +++ b/src/fs_fgetxattr.hpp @@ -21,6 +21,7 @@ #include "to_neg_errno.hpp" #include "xattr.hpp" +#include #include #include diff --git a/src/fs_findallfiles.cpp b/src/fs_findallfiles.cpp index 9cc9e50c..2c4ad0e0 100644 --- a/src/fs_findallfiles.cpp +++ b/src/fs_findallfiles.cpp @@ -27,14 +27,14 @@ void fs::findallfiles(const std::vector &basepaths_, - const char *fusepath_, + const fs::path &fusepath_, std::vector *paths_) { - std::string fullpath; + fs::path fullpath; for(const auto &basepath : basepaths_) { - fullpath = fs::path::make(basepath,fusepath_); + fullpath = basepath / fusepath_; if(!fs::exists(fullpath)) continue; diff --git a/src/fs_findallfiles.hpp b/src/fs_findallfiles.hpp index db3e5895..4a9e710a 100644 --- a/src/fs_findallfiles.hpp +++ b/src/fs_findallfiles.hpp @@ -18,7 +18,7 @@ #pragma once -#include "strvec.hpp" +#include "fs_path.hpp" #include #include @@ -27,7 +27,7 @@ namespace fs { void - findallfiles(const StrVec &basepaths, - const char *fusepath, - StrVec *paths); + findallfiles(const std::vector &basepaths, + const fs::path &fusepath, + std::vector *paths); } diff --git a/src/fs_findonfs.cpp b/src/fs_findonfs.cpp index e4d10880..c5e3fbd1 100644 --- a/src/fs_findonfs.cpp +++ b/src/fs_findonfs.cpp @@ -30,14 +30,14 @@ static int _findonfs(const Branches::Ptr &branches_, - const std::string &fusepath_, + const fs::path &fusepath_, const int fd_, std::string *basepath_) { int rv; dev_t dev; struct stat st; - std::string fullpath; + fs::path fullpath; rv = fs::fstat(fd_,&st); if(rv < 0) @@ -46,7 +46,7 @@ _findonfs(const Branches::Ptr &branches_, dev = st.st_dev; for(const auto &branch : *branches_) { - fullpath = fs::path::make(branch.path,fusepath_); + fullpath = branch.path / fusepath_; rv = fs::lstat(fullpath,&st); if(rv < 0) diff --git a/src/fs_fstatat.hpp b/src/fs_fstatat.hpp index b6ab8ca6..976c437e 100644 --- a/src/fs_fstatat.hpp +++ b/src/fs_fstatat.hpp @@ -18,6 +18,7 @@ #pragma once +#include "fs_path.hpp" #include "to_neg_errno.hpp" #include @@ -43,6 +44,20 @@ namespace fs return ::to_neg_errno(rv); } + static + inline + int + fstatat(const int dirfd_, + const fs::path &pathname_, + struct stat *statbuf_, + const int flags_) + { + return fs::fstatat(dirfd_, + pathname_.c_str(), + statbuf_, + flags_); + } + static inline int @@ -55,4 +70,17 @@ namespace fs statbuf_, AT_SYMLINK_NOFOLLOW); } + + static + inline + int + fstatat_nofollow(const int dirfd_, + const fs::path &pathname_, + struct stat *statbuf_) + { + return fs::fstatat(dirfd_, + pathname_, + statbuf_, + AT_SYMLINK_NOFOLLOW); + } } diff --git a/src/fs_inode.cpp b/src/fs_inode.cpp index 9a0fb133..1715e185 100644 --- a/src/fs_inode.cpp +++ b/src/fs_inode.cpp @@ -26,13 +26,13 @@ #include #include -typedef uint64_t (*inodefunc_t)(const std::string_view, - const std::string_view, +typedef uint64_t (*inodefunc_t)(const std::string &, + const std::string &, const mode_t, const ino_t); -static uint64_t _hybrid_hash(const std::string_view, - const std::string_view, +static uint64_t _hybrid_hash(const std::string &, + const std::string &, const mode_t, const ino_t); @@ -51,8 +51,8 @@ _h64_to_h32(uint64_t h_) static uint64_t -_passthrough(const std::string_view branch_path_, - const std::string_view fusepath_, +_passthrough(const std::string &branch_path_, + const std::string &fusepath_, const mode_t mode_, const ino_t ino_) { @@ -61,8 +61,8 @@ _passthrough(const std::string_view branch_path_, static uint64_t -_path_hash(const std::string_view branch_path_, - const std::string_view fusepath_, +_path_hash(const std::string &branch_path_, + const std::string &fusepath_, const mode_t mode_, const ino_t ino_) { @@ -75,8 +75,8 @@ _path_hash(const std::string_view branch_path_, static uint64_t -_path_hash32(const std::string_view branch_path_, - const std::string_view fusepath_, +_path_hash32(const std::string &branch_path_, + const std::string &fusepath_, const mode_t mode_, const ino_t ino_) { @@ -92,8 +92,8 @@ _path_hash32(const std::string_view branch_path_, static uint64_t -_devino_hash(const std::string_view branch_path_, - const std::string_view fusepath_, +_devino_hash(const std::string &branch_path_, + const std::string &fusepath_, const mode_t mode_, const ino_t ino_) { @@ -107,8 +107,8 @@ _devino_hash(const std::string_view branch_path_, static uint64_t -_devino_hash32(const std::string_view branch_path_, - const std::string_view fusepath_, +_devino_hash32(const std::string &branch_path_, + const std::string &fusepath_, const mode_t mode_, const ino_t ino_) { @@ -124,8 +124,8 @@ _devino_hash32(const std::string_view branch_path_, static uint64_t -_hybrid_hash(const std::string_view branch_path_, - const std::string_view fusepath_, +_hybrid_hash(const std::string &branch_path_, + const std::string &fusepath_, const mode_t mode_, const ino_t ino_) { @@ -136,8 +136,8 @@ _hybrid_hash(const std::string_view branch_path_, static uint64_t -_hybrid_hash32(const std::string_view branch_path_, - const std::string_view fusepath_, +_hybrid_hash32(const std::string &branch_path_, + const std::string &fusepath_, const mode_t mode_, const ino_t ino_) { @@ -147,7 +147,7 @@ _hybrid_hash32(const std::string_view branch_path_, } int -fs::inode::set_algo(const std::string_view algo_) +fs::inode::set_algo(const std::string &algo_) { if(algo_ == "passthrough") g_func = ::_passthrough; @@ -191,18 +191,18 @@ fs::inode::get_algo(void) } uint64_t -fs::inode::calc(const std::string_view branch_path_, - const std::string_view fusepath_, - const mode_t mode_, - const ino_t ino_) +fs::inode::calc(const std::string &branch_path_, + const std::string &fusepath_, + const mode_t mode_, + const ino_t ino_) { return g_func(branch_path_,fusepath_,mode_,ino_); } void -fs::inode::calc(const std::string_view branch_path_, - const std::string_view fusepath_, - struct stat *st_) +fs::inode::calc(const std::string &branch_path_, + const std::string &fusepath_, + struct stat *st_) { st_->st_ino = calc(branch_path_, fusepath_, @@ -211,9 +211,9 @@ fs::inode::calc(const std::string_view branch_path_, } void -fs::inode::calc(const std::string_view branch_path_, - const std::string_view fusepath_, - struct fuse_statx *st_) +fs::inode::calc(const std::string &branch_path_, + const std::string &fusepath_, + struct fuse_statx *st_) { st_->ino = calc(branch_path_, fusepath_, diff --git a/src/fs_inode.hpp b/src/fs_inode.hpp index 9756feb3..203dbe22 100644 --- a/src/fs_inode.hpp +++ b/src/fs_inode.hpp @@ -22,7 +22,6 @@ #include #include -#include #include @@ -31,19 +30,19 @@ namespace fs { namespace inode { - int set_algo(const std::string_view s); + int set_algo(const std::string &s); std::string get_algo(void); - uint64_t calc(const std::string_view basepath, - const std::string_view fusepath, + uint64_t calc(const std::string &basepath, + const std::string &fusepath, const mode_t mode, const ino_t ino); - void calc(const std::string_view basepath, - const std::string_view fusepath, + void calc(const std::string &basepath, + const std::string &fusepath, struct stat *st); - void calc(const std::string_view basepath, - const std::string_view fusepath, - struct fuse_statx *st); + void calc(const std::string &basepath, + const std::string &fusepath, + struct fuse_statx *st); } } diff --git a/src/fs_is_rofs.hpp b/src/fs_is_rofs.hpp index 6ea0ff40..22c556da 100644 --- a/src/fs_is_rofs.hpp +++ b/src/fs_is_rofs.hpp @@ -20,13 +20,12 @@ #include "fs_close.hpp" #include "fs_mktemp.hpp" +#include "fs_path.hpp" #include "fs_statvfs.hpp" #include "fs_unlink.hpp" #include "statvfs_util.hpp" #include "ugid.hpp" -#include - #include @@ -35,7 +34,7 @@ namespace fs static inline bool - is_mounted_rofs(const std::string path_) + is_mounted_rofs(const fs::path &path_) { int rv; struct statvfs st; @@ -48,7 +47,7 @@ namespace fs static inline bool - is_rofs(std::string path_) + is_rofs(const fs::path &path_) { ugid::SetRootGuard const ugid; @@ -68,7 +67,7 @@ namespace fs static inline bool - is_rofs_but_not_mounted_ro(const std::string path_) + is_rofs_but_not_mounted_ro(const fs::path &path_) { if(fs::is_mounted_rofs(path_)) return false; diff --git a/src/fs_mkdir.hpp b/src/fs_mkdir.hpp index a16aa185..7281b765 100644 --- a/src/fs_mkdir.hpp +++ b/src/fs_mkdir.hpp @@ -38,7 +38,8 @@ namespace fs { int rv; - rv = ::mkdir(path_,mode_); + rv = ::mkdir(path_, + mode_); return ::to_neg_errno(rv); } @@ -49,15 +50,17 @@ namespace fs mkdir(const std::string &path_, const mode_t mode_) { - return fs::mkdir(path_.c_str(),mode_); + return fs::mkdir(path_.c_str(), + mode_); } static inline int - mkdir(const fs::Path &path_, + mkdir(const fs::path &path_, const mode_t mode_) { - return fs::mkdir(path_.c_str(),mode_); + return fs::mkdir(path_.c_str(), + mode_); } } diff --git a/src/fs_mktemp.cpp b/src/fs_mktemp.cpp index 90f2ee10..8ca35e76 100644 --- a/src/fs_mktemp.cpp +++ b/src/fs_mktemp.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -37,45 +38,40 @@ static char const CHARS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static size_t const CHARS_SIZE = (sizeof(CHARS) - 1); - static -std::string -_generate_tmp_path(const std::string &dirpath_, - const std::string &filename_) +fs::path +_generate_tmp_path(const fs::path &dirpath_, + const std::string &src_filename_) { long name_max; size_t substr_len; - fs::Path path; - std::string filename; + std::string tmp_filename; name_max = ::pathconf(dirpath_.c_str(),_PC_NAME_MAX); if(name_max == -1) name_max = NAME_MAX; - substr_len = std::min(filename_.size(), + substr_len = std::min(src_filename_.size(), (size_t)(name_max - PAD_LEN - 2ULL)); - filename = '.'; - filename += filename_.substr(0,substr_len); - filename += '_'; + tmp_filename = '.'; + tmp_filename += src_filename_.substr(0,substr_len); + tmp_filename += '_'; for(size_t i = 0; i < PAD_LEN; i++) - filename += CHARS[RND::rand64(CHARS_SIZE)]; - - path = dirpath_; - path /= filename; + tmp_filename += CHARS[RND::rand64(CHARS_SIZE)]; - return path.string(); + return dirpath_ / tmp_filename; } -std::tuple -fs::mktemp_in_dir(const std::string &dirpath_, - const std::string &filename_, - const int flags_) +std::tuple +fs::mktemp_in_dir(const fs::path &dirpath_, + const fs::path &filename_, + const int flags_) { int fd; int count; int flags; - std::string tmp_filepath; + fs::path tmp_filepath; count = MAX_ATTEMPTS; flags = (flags_ | O_EXCL | O_CREAT); @@ -87,21 +83,19 @@ fs::mktemp_in_dir(const std::string &dirpath_, if(fd == -EEXIST) continue; if(fd < 0) - return std::make_tuple(fd,std::string()); + return std::make_tuple(fd,fs::path()); return std::make_tuple(fd,tmp_filepath); } - return std::make_tuple(-EEXIST,std::string()); + return std::make_tuple(-EEXIST,fs::path()); } -std::tuple -fs::mktemp(const std::string &filepath_, - const int flags_) +std::tuple +fs::mktemp(const fs::path &filepath_, + const int flags_) { - fs::Path filepath{filepath_}; - - return fs::mktemp_in_dir(filepath.parent_path(), - filepath.filename(), + return fs::mktemp_in_dir(filepath_.parent_path(), + filepath_.filename(), flags_); } diff --git a/src/fs_mktemp.hpp b/src/fs_mktemp.hpp index 38995740..302d18af 100644 --- a/src/fs_mktemp.hpp +++ b/src/fs_mktemp.hpp @@ -18,18 +18,20 @@ #pragma once +#include "fs_path.hpp" + #include #include namespace fs { - std::tuple - mktemp_in_dir(const std::string &dirpath, - const std::string &filename, - int const flags); + std::tuple + mktemp_in_dir(const fs::path &dirpath, + const fs::path &filename, + int const flags); - std::tuple - mktemp(const std::string &filepath, - const int flags); + std::tuple + mktemp(const fs::path &filepath, + const int flags); } diff --git a/src/fs_mounts.hpp b/src/fs_mounts.hpp index f68d5084..163005cc 100644 --- a/src/fs_mounts.hpp +++ b/src/fs_mounts.hpp @@ -9,7 +9,7 @@ namespace fs { struct Mount { - fs::Path dir; + fs::path dir; std::string fsname; std::string type; std::string opts; diff --git a/src/fs_movefile_and_open.cpp b/src/fs_movefile_and_open.cpp index bdc93046..9a9704e8 100644 --- a/src/fs_movefile_and_open.cpp +++ b/src/fs_movefile_and_open.cpp @@ -62,23 +62,23 @@ static int _movefile_and_open(const Policy::Create &createFunc_, const Branches::Ptr &branches_, - const std::string &branchpath_, - const std::string &fusepath_, + const fs::path &branchpath_, + const fs::path &fusepath_, int origfd_) { int rv; int dstfd_flags; int origfd_flags; s64 src_size; - std::string fusedir; - std::string src_branch; - std::string src_filepath; - std::string dst_filepath; + fs::path fusedir; + fs::path src_branch; + fs::path src_filepath; + fs::path dst_filepath; std::vector dst_branch; src_branch = branchpath_; - rv = createFunc_(branches_,fusepath_.c_str(),dst_branch); + rv = createFunc_(branches_,fusepath_,dst_branch); if(rv < 0) return rv; @@ -93,14 +93,14 @@ _movefile_and_open(const Policy::Create &createFunc_, if(fs::has_space(dst_branch[0]->path,src_size) == false) return -ENOSPC; - fusedir = fs::path::dirname(fusepath_); + fusedir = fusepath_.parent_path(); rv = fs::clonepath(src_branch,dst_branch[0]->path,fusedir); if(rv < 0) return -ENOSPC; - src_filepath = fs::path::make(src_branch,fusepath_); - dst_filepath = fs::path::make(dst_branch[0]->path,fusepath_); + src_filepath = src_branch / fusepath_; + dst_filepath = dst_branch[0]->path / fusepath_; rv = fs::copyfile(src_filepath,dst_filepath,{.cleanup_failure = true}); if(rv < 0) @@ -119,8 +119,8 @@ _movefile_and_open(const Policy::Create &createFunc_, int fs::movefile_and_open(const Policy::Create &policy_, const Branches::Ptr &branches_, - const std::string &branchpath_, - const std::string &fusepath_, + const fs::path &branchpath_, + const fs::path &fusepath_, const int origfd_) { return ::_movefile_and_open(policy_, @@ -133,8 +133,8 @@ fs::movefile_and_open(const Policy::Create &policy_, int fs::movefile_and_open_as_root(const Policy::Create &policy_, const Branches::Ptr &branches_, - const std::string &branchpath_, - const std::string &fusepath_, + const fs::path &branchpath_, + const fs::path &fusepath_, const int origfd_) { const ugid::Set ugid(0,0); diff --git a/src/fs_movefile_and_open.hpp b/src/fs_movefile_and_open.hpp index effc25bd..e5e4a0e1 100644 --- a/src/fs_movefile_and_open.hpp +++ b/src/fs_movefile_and_open.hpp @@ -17,6 +17,7 @@ #pragma once #include "branches.hpp" +#include "fs_path.hpp" #include "policy.hpp" #include @@ -27,14 +28,14 @@ namespace fs int movefile_and_open(const Policy::Create &policy, const Branches::Ptr &branches_, - const std::string &branchpath, - const std::string &fusepath, - const int origfd); + const fs::path &branchpath, + const fs::path &fusepath, + const int origfd); int movefile_and_open_as_root(const Policy::Create &policy, const Branches::Ptr &branches_, - const std::string &branchpath, - const std::string &fusepath, + const fs::path &branchpath, + const fs::path &fusepath, int origfd); } diff --git a/src/fs_openat.hpp b/src/fs_openat.hpp index 0da7b598..8e24d331 100644 --- a/src/fs_openat.hpp +++ b/src/fs_openat.hpp @@ -18,9 +18,9 @@ #pragma once +#include "fs_path.hpp" #include "to_neg_errno.hpp" -#include #include #include @@ -61,10 +61,10 @@ namespace fs static inline int - openat(const int dirfd_, - const std::filesystem::path &pathname_, - const int flags_, - const mode_t mode_ = 0) + openat(const int dirfd_, + const fs::path &pathname_, + const int flags_, + const mode_t mode_ = 0) { return fs::openat(dirfd_, pathname_.c_str(), diff --git a/src/fs_path.cpp b/src/fs_path.cpp index b72b6709..6ac3a71e 100644 --- a/src/fs_path.cpp +++ b/src/fs_path.cpp @@ -15,45 +15,3 @@ */ #include "fs_path.hpp" - -#include - -#include -#include -#include -#include - -using std::string; - - -string -fs::path::dirname(const char *path_) -{ - string path(path_); - - return fs::path::dirname(path); -} - -string -fs::path::dirname(const string &path_) -{ - std::size_t i; - - i = path_.size() - 1; - while((i > 0) && (path_[i] == '/')) - i--; - - while((i > 0) && (path_[i] != '/')) - i--; - - while((i > 0) && (path_[i] == '/')) - i--; - - return path_.substr(0,i+1); -} - -string -fs::path::basename(const string &path_) -{ - return path_.substr(path_.find_last_of('/')+1); -} diff --git a/src/fs_path.hpp b/src/fs_path.hpp index e285d3af..9140eb68 100644 --- a/src/fs_path.hpp +++ b/src/fs_path.hpp @@ -16,74 +16,10 @@ #pragma once - -#include -#include #include namespace fs { - typedef std::filesystem::path Path; - - namespace path - { - std::string dirname(const char *path); - std::string dirname(const std::string &path); - - std::string basename(const std::string &path); - - static - inline - void - append(std::string &base_, - const char *suffix_) - { - base_ += suffix_; - } - - static - inline - void - append(std::string &base_, - const std::string &suffix_) - { - base_ += suffix_; - } - - static - inline - std::string - make(const char *base_, - const char *suffix_) - { - char back; - std::string path(base_); - - back = *path.rbegin(); - if((back != '/') && (suffix_[0] != '/')) - path.push_back('/'); - path += suffix_; - - return path; - } - - static - inline - std::string - make(const std::string &base_, - const char *suffix_) - { - return (base_ + suffix_); - } - - static - inline - std::string - make(const std::string &base_, - const std::string &suffix_) - { - return (base_ + suffix_); - } - } + using path = std::filesystem::path; } diff --git a/src/fs_pathvector.hpp b/src/fs_pathvector.hpp deleted file mode 100644 index ff41ac40..00000000 --- a/src/fs_pathvector.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "fs_path.hpp" - -#include - -namespace fs -{ - typedef std::vector PathVector; -} diff --git a/src/fs_wait_for_mount.cpp b/src/fs_wait_for_mount.cpp index ff65d421..f5c933af 100644 --- a/src/fs_wait_for_mount.cpp +++ b/src/fs_wait_for_mount.cpp @@ -30,22 +30,17 @@ #include #include - -namespace fs -{ - typedef std::set PathSet; -} - constexpr std::chrono::milliseconds SLEEP_DURATION = std::chrono::milliseconds(333); + static bool -_branch_is_mounted(const struct stat &src_st_, - const fs::Path &branch_path_) +_branch_is_mounted(const struct stat &src_st_, + const fs::path &branch_path_) { int rv; struct stat st; - fs::Path filepath; + fs::path filepath; rv = fs::lgetxattr(branch_path_,"user.mergerfs.branch",NULL,0); if(rv >= 0) @@ -74,13 +69,13 @@ _branch_is_mounted(const struct stat &src_st_, static void -_check_mounted(const struct stat &src_st_, - const fs::PathSet &tgt_paths_, - fs::PathVector *successes_, - fs::PathVector *failures_) +_check_mounted(const struct stat &src_st_, + const std::set &tgt_paths_, + std::vector *successes_, + std::vector *failures_) { - fs::PathVector &successes = *successes_; - fs::PathVector &failures = *failures_; + std::vector &successes = *successes_; + std::vector &failures = *failures_; for(auto const &tgt_path : tgt_paths_) { @@ -97,13 +92,13 @@ _check_mounted(const struct stat &src_st_, static int _wait_for_mount(const struct stat &src_st_, - const fs::PathVector &tgt_paths_, + const std::vector &tgt_paths_, const std::chrono::milliseconds &timeout_) { bool first_loop; - fs::PathVector successes; - fs::PathVector failures; - fs::PathSet tgt_paths; + std::vector successes; + std::vector failures; + std::set tgt_paths; std::chrono::time_point now; std::chrono::time_point deadline; @@ -146,8 +141,8 @@ _wait_for_mount(const struct stat &src_st_, } int -fs::wait_for_mount(const fs::Path &src_path_, - const fs::PathVector &tgt_paths_, +fs::wait_for_mount(const fs::path &src_path_, + const std::vector &tgt_paths_, const std::chrono::milliseconds &timeout_) { int rv; diff --git a/src/fs_wait_for_mount.hpp b/src/fs_wait_for_mount.hpp index 87194d5a..a0e54139 100644 --- a/src/fs_wait_for_mount.hpp +++ b/src/fs_wait_for_mount.hpp @@ -17,7 +17,7 @@ #pragma once -#include "fs_pathvector.hpp" +#include "fs_path.hpp" #include #include @@ -26,7 +26,7 @@ namespace fs { int - wait_for_mount(const fs::Path &srcpath, - const fs::PathVector &tgtpaths, + wait_for_mount(const fs::path &srcpath, + const std::vector &tgtpaths, const std::chrono::milliseconds &timeout); } diff --git a/src/fuse_access.cpp b/src/fuse_access.cpp index a2983fdf..8a94ef9e 100644 --- a/src/fuse_access.cpp +++ b/src/fuse_access.cpp @@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "fuse_access.hpp" + #include "config.hpp" #include "errno.hpp" #include "fs_eaccess.hpp" @@ -23,48 +25,40 @@ #include #include -using std::string; -using std::vector; - -namespace l +static +int +_access(const Policy::Search &searchFunc_, + const Branches &branches_, + const fs::path &fusepath_, + const int mask_) { - static - int - access(const Policy::Search &searchFunc_, - const Branches &branches_, - const char *fusepath_, - const int mask_) - { - int rv; - string fullpath; - StrVec basepaths; - std::vector branches; + int rv; + StrVec basepaths; + fs::path fullpath; + std::vector branches; - rv = searchFunc_(branches_,fusepath_,branches); - if(rv < 0) - return rv; + rv = searchFunc_(branches_,fusepath_,branches); + if(rv < 0) + return rv; - fullpath = fs::path::make(branches[0]->path,fusepath_); + fullpath = branches[0]->path / fusepath_; - rv = fs::eaccess(fullpath,mask_); + rv = fs::eaccess(fullpath,mask_); - return rv; - } + return rv; } -namespace FUSE +int +FUSE::access(const char *fusepath_, + int mask_) { - int - access(const char *fusepath_, - int mask_) - { - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const fuse_context *fc = fuse_get_context(); + const ugid::Set ugid(fc->uid,fc->gid); - return l::access(cfg.func.access.policy, - cfg.branches, - fusepath_, - mask_); - } + return ::_access(cfg.func.access.policy, + cfg.branches, + fusepath, + mask_); } diff --git a/src/fuse_bmap.cpp b/src/fuse_bmap.cpp index 62359d42..5b950813 100644 --- a/src/fuse_bmap.cpp +++ b/src/fuse_bmap.cpp @@ -16,6 +16,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "fuse_bmap.hpp" + #include "errno.hpp" #include @@ -23,17 +25,14 @@ #include -namespace FUSE +int +FUSE::bmap(const char *fusepath_, + size_t blocksize_, + uint64_t *idx_) { - int - bmap(const char *fusepath_, - size_t blocksize_, - uint64_t *idx_) - { - (void)fusepath_; - (void)blocksize_; - (void)idx_; - - return -ENOSYS; - } + (void)fusepath_; + (void)blocksize_; + (void)idx_; + + return -ENOSYS; } diff --git a/src/fuse_chmod.cpp b/src/fuse_chmod.cpp index 1714d432..dd58e590 100644 --- a/src/fuse_chmod.cpp +++ b/src/fuse_chmod.cpp @@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "fuse_chmod.hpp" + #include "config.hpp" #include "errno.hpp" #include "fs_lchmod.hpp" @@ -23,96 +25,90 @@ #include "fuse.h" +#include #include -#include +static +void +_chmod_loop_core(const std::string &basepath_, + const fs::path &fusepath_, + const mode_t mode_, + PolicyRV *prv_) +{ + fs::path fullpath; + + fullpath = basepath_ / fusepath_; + + errno = 0; + fs::lchmod(fullpath,mode_); + + prv_->insert(errno,basepath_); +} + +static +void +_chmod_loop(const std::vector &branches_, + const fs::path &fusepath_, + const mode_t mode_, + PolicyRV *prv_) +{ + for(auto &branch : branches_) + { + ::_chmod_loop_core(branch->path,fusepath_,mode_,prv_); + } +} -namespace l +static +int +_chmod(const Policy::Action &actionFunc_, + const Policy::Search &searchFunc_, + const Branches &branches_, + const fs::path &fusepath_, + const mode_t mode_) { - static - void - chmod_loop_core(const std::string &basepath_, - const char *fusepath_, - const mode_t mode_, - PolicyRV *prv_) - { - std::string fullpath; - - fullpath = fs::path::make(basepath_,fusepath_); - - errno = 0; - fs::lchmod(fullpath,mode_); - - prv_->insert(errno,basepath_); - } - - static - void - chmod_loop(const std::vector &branches_, - const char *fusepath_, - const mode_t mode_, - PolicyRV *prv_) - { - for(auto &branch : branches_) - { - l::chmod_loop_core(branch->path,fusepath_,mode_,prv_); - } - } - - static - int - chmod(const Policy::Action &actionFunc_, - const Policy::Search &searchFunc_, - const Branches &branches_, - const char *fusepath_, - const mode_t mode_) - { - int rv; - PolicyRV prv; - std::vector branches; - - rv = actionFunc_(branches_,fusepath_,branches); - if(rv < 0) - return rv; - - l::chmod_loop(branches,fusepath_,mode_,&prv); - if(prv.errors.empty()) - return 0; - if(prv.successes.empty()) - return prv.errors[0].rv; - - branches.clear(); - rv = searchFunc_(branches_,fusepath_,branches); - if(rv < 0) - return rv; - - return prv.get_error(branches[0]->path); - } + int rv; + PolicyRV prv; + std::vector branches; + + rv = actionFunc_(branches_,fusepath_,branches); + if(rv < 0) + return rv; + + ::_chmod_loop(branches,fusepath_,mode_,&prv); + if(prv.errors.empty()) + return 0; + if(prv.successes.empty()) + return prv.errors[0].rv; + + branches.clear(); + rv = searchFunc_(branches_,fusepath_,branches); + if(rv < 0) + return rv; + + return prv.get_error(branches[0]->path); } static int -_chmod(const char *fusepath_, - const mode_t mode_) +_chmod(const fs::path &fusepath_, + const mode_t mode_) { const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); - return l::chmod(cfg.func.chmod.policy, + return ::_chmod(cfg.func.chmod.policy, cfg.func.getattr.policy, cfg.branches, fusepath_, mode_); } - -namespace FUSE +int +FUSE::chmod(const char *fusepath_, + mode_t mode_) { - int - chmod(const char *fusepath_, - mode_t mode_) - { - return ::_chmod(fusepath_,mode_); - } + const fs::path fusepath{fusepath_}; + + return ::_chmod(fusepath,mode_); } diff --git a/src/fuse_chmod.hpp b/src/fuse_chmod.hpp index ea335a34..5da49e17 100644 --- a/src/fuse_chmod.hpp +++ b/src/fuse_chmod.hpp @@ -16,6 +16,8 @@ #pragma once +#include + namespace FUSE { diff --git a/src/fuse_chown.cpp b/src/fuse_chown.cpp index cfbc1528..bda4464a 100644 --- a/src/fuse_chown.cpp +++ b/src/fuse_chown.cpp @@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "fuse_chown.hpp" + #include "config.hpp" #include "errno.hpp" #include "fs_lchown.hpp" @@ -27,87 +29,83 @@ #include -namespace l +static +void +_chown_loop_core(const fs::path &basepath_, + const fs::path &fusepath_, + const uid_t uid_, + const gid_t gid_, + PolicyRV *prv_) +{ + fs::path fullpath; + + fullpath = basepath_ / fusepath_; + + errno = 0; + fs::lchown(fullpath,uid_,gid_); + + prv_->insert(errno,basepath_); +} + +static +void +_chown_loop(const std::vector &branches_, + const fs::path &fusepath_, + const uid_t uid_, + const gid_t gid_, + PolicyRV *prv_) { - static - void - chown_loop_core(const std::string &basepath_, - const char *fusepath_, - const uid_t uid_, - const gid_t gid_, - PolicyRV *prv_) - { - std::string fullpath; - - fullpath = fs::path::make(basepath_,fusepath_); - - errno = 0; - fs::lchown(fullpath,uid_,gid_); - - prv_->insert(errno,basepath_); - } - - static - void - chown_loop(const std::vector &branches_, - const char *fusepath_, - const uid_t uid_, - const gid_t gid_, - PolicyRV *prv_) - { - for(auto &branch : branches_) - { - l::chown_loop_core(branch->path,fusepath_,uid_,gid_,prv_); - } - } - - static - int - chown(const Policy::Action &actionFunc_, - const Policy::Search &searchFunc_, - const Branches &branches_, - const char *fusepath_, - const uid_t uid_, - const gid_t gid_) - { - int rv; - PolicyRV prv; - std::vector branches; - - rv = actionFunc_(branches_,fusepath_,branches); - if(rv < 0) - return rv; - - l::chown_loop(branches,fusepath_,uid_,gid_,&prv); - if(prv.errors.empty()) - return 0; - if(prv.successes.empty()) - return prv.errors[0].rv; - - branches.clear(); - rv = searchFunc_(branches_,fusepath_,branches); - if(rv < 0) - return rv; - - return prv.get_error(branches[0]->path); - } + for(const auto &branch : branches_) + { + ::_chown_loop_core(branch->path,fusepath_,uid_,gid_,prv_); + } +} + +static +int +_chown(const Policy::Action &actionFunc_, + const Policy::Search &searchFunc_, + const Branches &branches_, + const fs::path &fusepath_, + const uid_t uid_, + const gid_t gid_) +{ + int rv; + PolicyRV prv; + std::vector branches; + + rv = actionFunc_(branches_,fusepath_,branches); + if(rv < 0) + return rv; + + ::_chown_loop(branches,fusepath_,uid_,gid_,&prv); + + if(prv.errors.empty()) + return 0; + if(prv.successes.empty()) + return prv.errors[0].rv; + + branches.clear(); + rv = searchFunc_(branches_,fusepath_,branches); + if(rv < 0) + return rv; + + return prv.get_error(branches[0]->path); } -namespace FUSE +int +FUSE::chown(const char *fusepath_, + uid_t uid_, + gid_t gid_) { - int - chown(const char *fusepath_, - uid_t uid_, - gid_t gid_) - { - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); - - return l::chown(cfg.func.chown.policy, - cfg.func.getattr.policy, - cfg.branches, - fusepath_, - uid_, - gid_); - } + const fs::path fusepath{fusepath_}; + const fuse_context *fc = fuse_get_context(); + const ugid::Set ugid(fc->uid,fc->gid); + + return ::_chown(cfg.func.chown.policy, + cfg.func.getattr.policy, + cfg.branches, + fusepath, + uid_, + gid_); } diff --git a/src/fuse_chown.hpp b/src/fuse_chown.hpp index 1a367acf..77233cb0 100644 --- a/src/fuse_chown.hpp +++ b/src/fuse_chown.hpp @@ -16,6 +16,8 @@ #pragma once +#include + namespace FUSE { diff --git a/src/fuse_copy_file_range.cpp b/src/fuse_copy_file_range.cpp index 4ecb0163..ac72324e 100644 --- a/src/fuse_copy_file_range.cpp +++ b/src/fuse_copy_file_range.cpp @@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "fuse_copy_file_range.hpp" + #include "errno.hpp" #include "fileinfo.hpp" #include "fs_copy_file_range.hpp" @@ -23,48 +25,42 @@ #include -namespace l +static +ssize_t +_copy_file_range(const int fd_in_, + off_t offset_in_, + const int fd_out_, + off_t offset_out_, + size_t size_, + int flags_) { - static - ssize_t - copy_file_range(const int fd_in_, - off_t offset_in_, - const int fd_out_, - off_t offset_out_, - size_t size_, - int flags_) - { - ssize_t rv; + ssize_t rv; - rv = fs::copy_file_range(fd_in_, - &offset_in_, - fd_out_, - &offset_out_, - size_, - flags_); + rv = fs::copy_file_range(fd_in_, + &offset_in_, + fd_out_, + &offset_out_, + size_, + flags_); - return rv; - } + return rv; } -namespace FUSE +ssize_t +FUSE::copy_file_range(const fuse_file_info_t *ffi_in_, + off_t offset_in_, + const fuse_file_info_t *ffi_out_, + off_t offset_out_, + size_t size_, + int flags_) { - ssize_t - copy_file_range(const fuse_file_info_t *ffi_in_, - off_t offset_in_, - const fuse_file_info_t *ffi_out_, - off_t offset_out_, - size_t size_, - int flags_) - { - FileInfo *fi_in = reinterpret_cast(ffi_in_->fh); - FileInfo *fi_out = reinterpret_cast(ffi_out_->fh); + FileInfo *fi_in = FileInfo::from_fh(ffi_in_->fh); + FileInfo *fi_out = FileInfo::from_fh(ffi_out_->fh); - return l::copy_file_range(fi_in->fd, - offset_in_, - fi_out->fd, - offset_out_, - size_, - flags_); - } + return ::_copy_file_range(fi_in->fd, + offset_in_, + fi_out->fd, + offset_out_, + size_, + flags_); } diff --git a/src/fuse_copy_file_range.hpp b/src/fuse_copy_file_range.hpp index ef18a3e6..60a28ba3 100644 --- a/src/fuse_copy_file_range.hpp +++ b/src/fuse_copy_file_range.hpp @@ -16,6 +16,18 @@ #pragma once +#include "fuse.h" + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 64 +#endif + +#include "fuse.h" + +#include namespace FUSE { diff --git a/src/fuse_create.cpp b/src/fuse_create.cpp index 2b6b4ee3..c8a6e328 100644 --- a/src/fuse_create.cpp +++ b/src/fuse_create.cpp @@ -14,9 +14,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "state.hpp" +#include "fuse_create.hpp" +#include "state.hpp" #include "config.hpp" + #include "errno.hpp" #include "fileinfo.hpp" #include "fs_acl.hpp" @@ -25,6 +27,7 @@ #include "fs_path.hpp" #include "fuse_passthrough.hpp" #include "procfs.hpp" +#include "syslog.hpp" #include "ugid.hpp" #include "fuse.h" @@ -32,7 +35,6 @@ #include #include - /* The kernel expects being able to issue read requests when running with writeback caching enabled so we must change O_WRONLY to @@ -135,10 +137,10 @@ _config_to_ffi_flags(Config &cfg_, static int -_create_core(const std::string &fullpath_, - mode_t mode_, - const mode_t umask_, - const int flags_) +_create_core(const fs::path &fullpath_, + mode_t mode_, + const mode_t umask_, + const int flags_) { if(!fs::acl::dir_has_defaults(fullpath_)) mode_ &= ~umask_; @@ -149,24 +151,24 @@ _create_core(const std::string &fullpath_, static int _create_core(const Branch *branch_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, const mode_t mode_, const mode_t umask_) { int rv; FileInfo *fi; - std::string fullpath; + fs::path fullpath; - fullpath = fs::path::make(branch_->path,fusepath_); + fullpath = branch_->path / fusepath_; rv = ::_create_core(fullpath,mode_,umask_,ffi_->flags); if(rv < 0) return rv; - fi = new FileInfo(rv,branch_,fusepath_,ffi_->direct_io); + fi = new FileInfo(rv,*branch_,fusepath_,ffi_->direct_io); - ffi_->fh = reinterpret_cast(fi); + ffi_->fh = fi->to_fh(); return 0; } @@ -176,18 +178,18 @@ int _create(const Policy::Search &searchFunc_, const Policy::Create &createFunc_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, const mode_t mode_, const mode_t umask_) { int rv; - std::string fullpath; - std::string fusedirpath; + fs::path fullpath; + fs::path fusedirpath; std::vector createpaths; std::vector existingpaths; - fusedirpath = fs::path::dirname(fusepath_); + fusedirpath = fusepath_.parent_path(); rv = searchFunc_(branches_,fusedirpath,existingpaths); if(rv < 0) @@ -222,7 +224,7 @@ _(const PassthroughEnum e_, static int _create_for_insert_lambda(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, const mode_t mode_, fuse_file_info_t *ffi_, State::OpenFile *of_) @@ -259,7 +261,7 @@ _create_for_insert_lambda(const fuse_context *fc_, if(rv < 0) return rv; - fi = reinterpret_cast(ffi_->fh); + fi = FileInfo::from_fh(ffi_->fh); of_->ref_count = 1; of_->fi = fi; @@ -289,10 +291,9 @@ _create_for_insert_lambda(const fuse_context *fc_, static inline -constexpr auto _create_insert_lambda(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, const mode_t mode_, fuse_file_info_t *ffi_, int *_rv_) @@ -311,14 +312,14 @@ _create_insert_lambda(const fuse_context *fc_, // This function should never be called? static inline -constexpr auto _create_update_lambda() { return - [=](auto &val_) + [](const auto &val_) { - fmt::println(stderr,"THIS SHOULD NOT HAPPEN"); + fmt::println(stderr,"CREATE_UPDATE_LAMBDA: THIS SHOULD NOT HAPPEN"); + SysLog::crit("CREATE_UPDATE_LAMBDA: THIS SHOULD NOT HAPPEN"); abort(); }; } @@ -326,7 +327,7 @@ _create_update_lambda() static int _create(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, mode_t mode_, fuse_file_info_t *ffi_) { @@ -343,7 +344,7 @@ _create(const fuse_context *fc_, // ref_count is default (0). if(rv < 0) of.erase_if(fc_->nodeid, - [](auto &val_) + [](const auto &val_) { return (val_.second.ref_count <= 0); }); @@ -351,15 +352,13 @@ _create(const fuse_context *fc_, return rv; } -namespace FUSE +int +FUSE::create(const char *fusepath_, + mode_t mode_, + fuse_file_info_t *ffi_) { - int - create(const char *fusepath_, - mode_t mode_, - fuse_file_info_t *ffi_) - { - const fuse_context *fc = fuse_get_context(); - - return ::_create(fc,fusepath_,mode_,ffi_); - } + const fs::path fusepath{fusepath_}; + const fuse_context *fc = fuse_get_context(); + + return ::_create(fc,fusepath,mode_,ffi_); } diff --git a/src/fuse_destroy.cpp b/src/fuse_destroy.cpp index d1c5632b..c14f866a 100644 --- a/src/fuse_destroy.cpp +++ b/src/fuse_destroy.cpp @@ -14,11 +14,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -namespace FUSE +#include "fuse_destroy.hpp" + +void +FUSE::destroy(void) { - void - destroy(void) - { - } } diff --git a/src/fuse_fallocate.cpp b/src/fuse_fallocate.cpp index 7b3bad9d..8a774759 100644 --- a/src/fuse_fallocate.cpp +++ b/src/fuse_fallocate.cpp @@ -16,6 +16,8 @@ #include "fuse_fallocate.hpp" +#include "state.hpp" + #include "errno.hpp" #include "fileinfo.hpp" #include "fs_fallocate.hpp" @@ -43,7 +45,23 @@ FUSE::fallocate(const uint64_t fh_, off_t offset_, off_t len_) { - FileInfo *fi = reinterpret_cast(fh_); + uint64_t fh; + const fuse_context *fc = fuse_get_context(); + + fh = fh_; + if(fh == 0) + { + state.open_files.cvisit(fc->nodeid, + [&](auto &val_) + { + fh = val_.second.fi->to_fh(); + }); + } + + if(fh == 0) + return -ENOENT; + + FileInfo *fi = FileInfo::from_fh(fh); return ::_fallocate(fi->fd, mode_, diff --git a/src/fuse_fchmod.cpp b/src/fuse_fchmod.cpp index 6ffbdfc3..52e3ff05 100644 --- a/src/fuse_fchmod.cpp +++ b/src/fuse_fchmod.cpp @@ -49,14 +49,14 @@ FUSE::fchmod(const uint64_t fh_, state.open_files.cvisit(fc->nodeid, [&](auto &val_) { - fh = reinterpret_cast(val_.second.fi); + fh = val_.second.fi->to_fh(); }); } if(fh == 0) return -ENOENT; - FileInfo *fi = reinterpret_cast(fh); + FileInfo *fi = FileInfo::from_fh(fh); return ::_fchmod(fi->fd,mode_); } diff --git a/src/fuse_fchown.cpp b/src/fuse_fchown.cpp index d1698422..f85eea0b 100644 --- a/src/fuse_fchown.cpp +++ b/src/fuse_fchown.cpp @@ -53,14 +53,14 @@ FUSE::fchown(const uint64_t fh_, state.open_files.cvisit(fc->nodeid, [&](auto &val_) { - fh = reinterpret_cast(val_.second.fi); + fh = val_.second.fi->to_fh(); }); } if(fh == 0) return -ENOENT; - FileInfo *fi = reinterpret_cast(fh); + FileInfo *fi = FileInfo::from_fh(fh); return ::_fchown(fi->fd,uid_,gid_); } diff --git a/src/fuse_fgetattr.cpp b/src/fuse_fgetattr.cpp index b38c437c..e4f36719 100644 --- a/src/fuse_fgetattr.cpp +++ b/src/fuse_fgetattr.cpp @@ -60,7 +60,7 @@ FUSE::fgetattr(const uint64_t fh_, state.open_files.cvisit(fc->nodeid, [&](const auto &val_) { - fh = reinterpret_cast(val_.second.fi); + fh = val_.second.fi->to_fh(); }); } @@ -70,7 +70,7 @@ FUSE::fgetattr(const uint64_t fh_, return -ENOENT; } - FileInfo *fi = reinterpret_cast(fh); + FileInfo *fi = FileInfo::from_fh(fh); rv = ::_fgetattr(fi,st_); diff --git a/src/fuse_flock.cpp b/src/fuse_flock.cpp index f8ea6e77..10aa96ac 100644 --- a/src/fuse_flock.cpp +++ b/src/fuse_flock.cpp @@ -19,6 +19,7 @@ #include "errno.hpp" #include "fileinfo.hpp" #include "fs_flock.hpp" +#include "state.hpp" #include "fuse.h" @@ -39,7 +40,23 @@ int FUSE::flock(const fuse_file_info_t *ffi_, int op_) { - FileInfo* fi = reinterpret_cast(ffi_->fh); + uint64_t fh; + const fuse_context *fc = fuse_get_context(); + + fh = ffi_->fh; + if(fh == 0) + { + state.open_files.cvisit(fc->nodeid, + [&](const auto &val_) + { + fh = val_.second.fi->to_fh(); + }); + } + + if(fh == 0) + return -ENOENT; + + FileInfo* fi = FileInfo::from_fh(fh); return ::_flock(fi->fd,op_); } diff --git a/src/fuse_flush.cpp b/src/fuse_flush.cpp index 99559190..7e92461a 100644 --- a/src/fuse_flush.cpp +++ b/src/fuse_flush.cpp @@ -40,7 +40,7 @@ _flush(const int fd_) int FUSE::flush(const fuse_file_info_t *ffi_) { - FileInfo *fi = reinterpret_cast(ffi_->fh); + FileInfo *fi = FileInfo::from_fh(ffi_->fh); return ::_flush(fi->fd); } diff --git a/src/fuse_fsync.cpp b/src/fuse_fsync.cpp index dba3a7f2..3a25fcb8 100644 --- a/src/fuse_fsync.cpp +++ b/src/fuse_fsync.cpp @@ -46,7 +46,7 @@ int FUSE::fsync(const uint64_t fh_, int isdatasync_) { - FileInfo *fi = reinterpret_cast(fh_); + FileInfo *fi = FileInfo::from_fh(fh_); return ::_fsync(fi->fd,isdatasync_); } diff --git a/src/fuse_fsyncdir.cpp b/src/fuse_fsyncdir.cpp index 69f0c7ed..1b56deca 100644 --- a/src/fuse_fsyncdir.cpp +++ b/src/fuse_fsyncdir.cpp @@ -38,7 +38,7 @@ int FUSE::fsyncdir(const fuse_file_info_t *ffi_, int isdatasync_) { - DirInfo *di = reinterpret_cast(ffi_->fh); + DirInfo *di = DirInfo::from_fh(ffi_->fh); return ::_fsyncdir(di,isdatasync_); } diff --git a/src/fuse_ftruncate.cpp b/src/fuse_ftruncate.cpp index 1719b575..61c24c40 100644 --- a/src/fuse_ftruncate.cpp +++ b/src/fuse_ftruncate.cpp @@ -49,11 +49,11 @@ FUSE::ftruncate(const uint64_t fh_, state.open_files.cvisit(fc->nodeid, [&](auto &val_) { - fh = reinterpret_cast(val_.second.fi); + fh = val_.second.fi->to_fh(); }); } - FileInfo *fi = reinterpret_cast(fh); + FileInfo *fi = FileInfo::from_fh(fh); return ::_ftruncate(fi->fd,size_); } diff --git a/src/fuse_futimens.cpp b/src/fuse_futimens.cpp index 85da68ba..605027c0 100644 --- a/src/fuse_futimens.cpp +++ b/src/fuse_futimens.cpp @@ -51,11 +51,11 @@ FUSE::futimens(const uint64_t fh_, state.open_files.cvisit(fc->nodeid, [&](const auto &val_) { - fh = reinterpret_cast(val_.second.fi); + fh = val_.second.fi->to_fh(); }); } - FileInfo *fi = reinterpret_cast(fh); + FileInfo *fi = FileInfo::from_fh(fh); return ::_futimens(fi->fd,ts_); } diff --git a/src/fuse_getattr.cpp b/src/fuse_getattr.cpp index e5ff20cf..ff937400 100644 --- a/src/fuse_getattr.cpp +++ b/src/fuse_getattr.cpp @@ -33,13 +33,11 @@ #include -using std::string; - static void -_set_stat_if_leads_to_dir(const std::string &path_, - struct stat *st_) +_set_stat_if_leads_to_dir(const fs::path &path_, + struct stat *st_) { int rv; struct stat st; @@ -56,8 +54,8 @@ _set_stat_if_leads_to_dir(const std::string &path_, static void -_set_stat_if_leads_to_reg(const std::string &path_, - struct stat *st_) +_set_stat_if_leads_to_reg(const fs::path &path_, + struct stat *st_) { int rv; struct stat st; @@ -122,21 +120,21 @@ static int _getattr(const Policy::Search &searchFunc_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, struct stat *st_, const bool symlinkify_, const time_t symlinkify_timeout_, FollowSymlinks followsymlinks_) { int rv; - string fullpath; + fs::path fullpath; std::vector branches; rv = searchFunc_(branches_,fusepath_,branches); if(rv < 0) return rv; - fullpath = fs::path::make(branches[0]->path,fusepath_); + fullpath = branches[0]->path / fusepath_; switch(followsymlinks_) { @@ -166,13 +164,15 @@ _getattr(const Policy::Search &searchFunc_, if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_)) symlinkify::convert(fullpath,st_); - fs::inode::calc(branches[0]->path,fusepath_,st_); + fs::inode::calc(branches[0]->path, + fusepath_, + st_); return 0; } int -_getattr(const char *fusepath_, +_getattr(const fs::path &fusepath_, struct stat *st_, fuse_timeouts_t *timeout_) { @@ -202,6 +202,16 @@ int FUSE::getattr(const char *fusepath_, struct stat *st_, fuse_timeouts_t *timeout_) +{ + const fs::path fusepath{fusepath_}; + + return FUSE::getattr(fusepath,st_,timeout_); +} + +int +FUSE::getattr(const fs::path &fusepath_, + struct stat *st_, + fuse_timeouts_t *timeout_) { if(Config::is_ctrl_file(fusepath_)) return ::_getattr_controlfile(st_); diff --git a/src/fuse_getattr.hpp b/src/fuse_getattr.hpp index 055af104..8cc0c7f8 100644 --- a/src/fuse_getattr.hpp +++ b/src/fuse_getattr.hpp @@ -18,6 +18,8 @@ #include "fuse.h" +#include "fs_path.hpp" + #include #include #include @@ -29,4 +31,10 @@ namespace FUSE getattr(const char *fusepath, struct stat *buf, fuse_timeouts_t *timeout); + + int + getattr(const fs::path &fusepath, + struct stat *buf, + fuse_timeouts_t *timeout); + } diff --git a/src/fuse_getxattr.cpp b/src/fuse_getxattr.cpp index a1ff14e6..0cc4e4f9 100644 --- a/src/fuse_getxattr.cpp +++ b/src/fuse_getxattr.cpp @@ -29,11 +29,11 @@ #include "fuse.h" #include +#include #include #include #include -#include static const char SECURITY_CAPABILITY[] = "security.capability"; @@ -97,7 +97,7 @@ _getxattr_from_string(char *destbuf_, static int _getxattr_user_mergerfs_allpaths(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, char *buf_, const size_t count_) { @@ -116,13 +116,13 @@ _getxattr_user_mergerfs_allpaths(const Branches::Ptr &branches_, static int -_getxattr_user_mergerfs(const std::string &basepath_, - const char *fusepath_, - const std::string &fullpath_, - const Branches &branches_, - const char *attrname_, - char *buf_, - const size_t count_) +_getxattr_user_mergerfs(const fs::path &basepath_, + const fs::path &fusepath_, + const fs::path &fullpath_, + const Branches &branches_, + const char *attrname_, + char *buf_, + const size_t count_) { std::string key; @@ -144,20 +144,20 @@ static int _getxattr(const Policy::Search &searchFunc_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const char *attrname_, char *buf_, const size_t count_) { int rv; - std::string fullpath; + fs::path fullpath; std::vector branches; rv = searchFunc_(branches_,fusepath_,branches); if(rv < 0) return rv; - fullpath = fs::path::make(branches[0]->path,fusepath_); + fullpath = branches[0]->path / fusepath_; if(Config::is_mergerfs_xattr(attrname_)) return ::_getxattr_user_mergerfs(branches[0]->path, @@ -177,7 +177,9 @@ FUSE::getxattr(const char *fusepath_, char *attrvalue_, size_t attrvalue_size_) { - if(Config::is_ctrl_file(fusepath_)) + const fs::path fusepath{fusepath_}; + + if(Config::is_ctrl_file(fusepath)) return ::_getxattr_ctrl_file(cfg, attrname_, attrvalue_, @@ -195,7 +197,7 @@ FUSE::getxattr(const char *fusepath_, return ::_getxattr(cfg.func.getxattr.policy, cfg.branches, - fusepath_, + fusepath, attrname_, attrvalue_, attrvalue_size_); diff --git a/src/fuse_init.cpp b/src/fuse_init.cpp index c174af64..84d1c49b 100644 --- a/src/fuse_init.cpp +++ b/src/fuse_init.cpp @@ -143,8 +143,8 @@ _want_if_capable_max_pages(fuse_conn_info *conn_, static void -_readahead(const fs::Path path_, - const int readahead_) +_readahead(const fs::path &path_, + const int readahead_) { int rv; diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index f372b76f..9c837613 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -112,7 +112,7 @@ _ioctl_file(const fuse_file_info_t *ffi_, void *data_, uint32_t *out_bufsz_) { - FileInfo *fi = reinterpret_cast(ffi_->fh); + FileInfo *fi = FileInfo::from_fh(ffi_->fh); const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); @@ -127,21 +127,21 @@ static int _ioctl_dir_base(const Policy::Search &searchFunc_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const uint32_t cmd_, void *data_, uint32_t *out_bufsz_) { int fd; int rv; - std::string fullpath; + fs::path fullpath; std::vector branches; rv = searchFunc_(branches_,fusepath_,branches); if(rv < 0) return rv; - fullpath = fs::path::make(branches[0]->path,fusepath_); + fullpath = branches[0]->path / fusepath_; fd = fs::open(fullpath,O_RDONLY|O_NOATIME|O_NONBLOCK); if(fd < 0) @@ -161,7 +161,7 @@ _ioctl_dir(const fuse_file_info_t *ffi_, void *data_, uint32_t *out_bufsz_) { - DirInfo *di = reinterpret_cast(ffi_->fh); + DirInfo *di = DirInfo::from_fh(ffi_->fh); const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); diff --git a/src/fuse_link.cpp b/src/fuse_link.cpp index 5d8b48a8..be39ed24 100644 --- a/src/fuse_link.cpp +++ b/src/fuse_link.cpp @@ -28,7 +28,6 @@ #include "fuse.h" -#include #include #include #include @@ -38,20 +37,20 @@ static int _link_create_path_loop(const std::vector &oldbranches_, const Branch *newbranch_, - const char *oldfusepath_, - const char *newfusepath_, - const std::string &newfusedirpath_) + const fs::path &oldfusepath_, + const fs::path &newfusepath_, + const fs::path &newfusedirpath_) { int rv; int err; - std::string oldfullpath; - std::string newfullpath; + fs::path oldfullpath; + fs::path newfullpath; err = -ENOENT; for(const auto &oldbranch : oldbranches_) { - oldfullpath = fs::path::make(oldbranch->path,oldfusepath_); - newfullpath = fs::path::make(oldbranch->path,newfusepath_); + oldfullpath = oldbranch->path / oldfusepath_; + newfullpath = oldbranch->path / newfusepath_; rv = fs::link(oldfullpath,newfullpath); if(rv == -ENOENT) @@ -73,11 +72,11 @@ int _link_create_path(const Policy::Search &searchFunc_, const Policy::Action &actionFunc_, const Branches &ibranches_, - const char *oldfusepath_, - const char *newfusepath_) + const fs::path &oldfusepath_, + const fs::path &newfusepath_) { int rv; - std::string newfusedirpath; + fs::path newfusedirpath; std::vector oldbranches; std::vector newbranches; @@ -85,7 +84,7 @@ _link_create_path(const Policy::Search &searchFunc_, if(rv < 0) return rv; - newfusedirpath = fs::path::dirname(newfusepath_); + newfusedirpath = newfusepath_.parent_path(); rv = searchFunc_(ibranches_,newfusedirpath,newbranches); if(rv < 0) @@ -98,17 +97,17 @@ _link_create_path(const Policy::Search &searchFunc_, static int -_link_preserve_path_core(const std::string &oldbasepath_, - const char *oldfusepath_, - const char *newfusepath_, - struct stat *st_) +_link_preserve_path_core(const fs::path &oldbasepath_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_, + struct stat *st_) { int rv; - std::string oldfullpath; - std::string newfullpath; + fs::path oldfullpath; + fs::path newfullpath; - oldfullpath = fs::path::make(oldbasepath_,oldfusepath_); - newfullpath = fs::path::make(oldbasepath_,newfusepath_); + oldfullpath = oldbasepath_ / oldfusepath_; + newfullpath = oldbasepath_ / newfusepath_; rv = fs::link(oldfullpath,newfullpath); if(rv == -ENOENT) @@ -122,8 +121,8 @@ _link_preserve_path_core(const std::string &oldbasepath_, static int _link_preserve_path_loop(const std::vector &oldbranches_, - const char *oldfusepath_, - const char *newfusepath_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_, struct stat *st_) { int rv; @@ -147,8 +146,8 @@ static int _link_preserve_path(const Policy::Action &actionFunc_, const Branches &branches_, - const char *oldfusepath_, - const char *newfusepath_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_, struct stat *st_) { int rv; @@ -166,10 +165,10 @@ _link_preserve_path(const Policy::Action &actionFunc_, static int -_link(Config &cfg_, - const char *oldpath_, - const char *newpath_, - struct stat *st_) +_link(Config &cfg_, + const fs::path &oldpath_, + const fs::path &newpath_, + struct stat *st_) { if(cfg_.func.create.policy.path_preserving() && !cfg_.ignorepponrename) return ::_link_preserve_path(cfg_.func.link.policy, @@ -188,8 +187,8 @@ _link(Config &cfg_, static int _link(Config &cfg_, - const char *oldpath_, - const char *newpath_, + const fs::path &oldpath_, + const fs::path &newpath_, struct stat *st_, fuse_timeouts_t *timeouts_) { @@ -204,18 +203,18 @@ _link(Config &cfg_, static int -_link_exdev_rel_symlink(const char *oldpath_, - const char *newpath_, +_link_exdev_rel_symlink(const fs::path &oldpath_, + const fs::path &newpath_, struct stat *st_, fuse_timeouts_t *timeouts_) { int rv; - fs::Path target(oldpath_); - fs::Path linkpath(newpath_); + fs::path target(oldpath_); + fs::path linkpath(newpath_); target = target.lexically_relative(linkpath.parent_path()); - rv = FUSE::symlink(target.c_str(),linkpath.c_str()); + rv = FUSE::symlink(target.c_str(),linkpath); if(rv == 0) rv = FUSE::getattr(oldpath_,st_,timeouts_); @@ -230,20 +229,20 @@ static int _link_exdev_abs_base_symlink(const Policy::Search &openPolicy_, const Branches::Ptr &ibranches_, - const char *oldpath_, - const char *newpath_, + const fs::path &oldpath_, + const fs::path &newpath_, struct stat *st_, fuse_timeouts_t *timeouts_) { int rv; - std::string target; + fs::path target; std::vector obranches; rv = openPolicy_(ibranches_,oldpath_,obranches); if(rv < 0) return rv; - target = fs::path::make(obranches[0]->path,oldpath_); + target = obranches[0]->path / oldpath_; rv = FUSE::symlink(target.c_str(),newpath_); if(rv == 0) @@ -258,17 +257,17 @@ _link_exdev_abs_base_symlink(const Policy::Search &openPolicy_, static int -_link_exdev_abs_pool_symlink(const fs::Path mount_, - const char *oldpath_, - const char *newpath_, +_link_exdev_abs_pool_symlink(const fs::path &mount_, + const fs::path &oldpath_, + const fs::path &newpath_, struct stat *st_, fuse_timeouts_t *timeouts_) { int rv; StrVec basepaths; - std::string target; + fs::path target; - target = fs::path::make(mount_,oldpath_); + target = mount_ / oldpath_; rv = FUSE::symlink(target.c_str(),newpath_); if(rv == 0) @@ -284,8 +283,8 @@ _link_exdev_abs_pool_symlink(const fs::Path mount_, static int _link_exdev(Config &cfg_, - const char *oldpath_, - const char *newpath_, + const fs::path &oldpath_, + const fs::path &newpath_, struct stat *st_, fuse_timeouts_t *timeouts_) { @@ -323,12 +322,14 @@ FUSE::link(const char *oldpath_, fuse_timeouts_t *timeouts_) { int rv; + const fs::path oldpath{oldpath_}; + const fs::path newpath{newpath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); - rv = ::_link(cfg,oldpath_,newpath_,st_,timeouts_); + rv = ::_link(cfg,oldpath,newpath,st_,timeouts_); if(rv == -EXDEV) - rv = ::_link_exdev(cfg,oldpath_,newpath_,st_,timeouts_); + rv = ::_link_exdev(cfg,oldpath,newpath,st_,timeouts_); return rv; } diff --git a/src/fuse_listxattr.cpp b/src/fuse_listxattr.cpp index a50387c0..8ea9c654 100644 --- a/src/fuse_listxattr.cpp +++ b/src/fuse_listxattr.cpp @@ -24,18 +24,19 @@ #include "fuse.h" +#include #include #include - #include + static ssize_t _listxattr_size(const std::vector &branches_, - const char *fusepath_) + const fs::path &fusepath_) { ssize_t size; - std::string fullpath; + fs::path fullpath; if(branches_.empty()) return -ENOENT; @@ -45,7 +46,7 @@ _listxattr_size(const std::vector &branches_, { ssize_t rv; - fullpath = fs::path::make(branch->path,fusepath_); + fullpath = branch->path / fusepath_; rv = fs::llistxattr(fullpath,NULL,0); if(rv < 0) @@ -60,13 +61,13 @@ _listxattr_size(const std::vector &branches_, static ssize_t _listxattr(const std::vector &branches_, - const char *fusepath_, + const fs::path &fusepath_, char *list_, size_t size_) { ssize_t rv; ssize_t size; - std::string fullpath; + fs::path fullpath; std::optional err; if(size_ == 0) @@ -76,7 +77,7 @@ _listxattr(const std::vector &branches_, err = -ENOENT; for(const auto branch : branches_) { - fullpath = fs::path::make(branch->path,fusepath_); + fullpath = branch->path / fusepath_; rv = fs::llistxattr(fullpath,list_,size_); if(rv == -ERANGE) @@ -104,12 +105,11 @@ static int _listxattr(const Policy::Search &searchFunc_, const Branches &ibranches_, - const char *fusepath_, + const fs::path &fusepath_, char *list_, const size_t size_) { int rv; - std::string fullpath; std::vector obranches; rv = searchFunc_(ibranches_,fusepath_,obranches); @@ -127,7 +127,9 @@ FUSE::listxattr(const char *fusepath_, char *list_, size_t size_) { - if(Config::is_ctrl_file(fusepath_)) + const fs::path fusepath{fusepath_}; + + if(Config::is_ctrl_file(fusepath)) return cfg.keys_listxattr(list_,size_); switch(cfg.xattr) @@ -145,7 +147,7 @@ FUSE::listxattr(const char *fusepath_, return ::_listxattr(cfg.func.listxattr.policy, cfg.branches, - fusepath_, + fusepath, list_, size_); } diff --git a/src/fuse_lock.cpp b/src/fuse_lock.cpp index 9d09a81f..813405f2 100644 --- a/src/fuse_lock.cpp +++ b/src/fuse_lock.cpp @@ -16,18 +16,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "fuse_lock.hpp" + #include "errno.hpp" #include "fuse.h" -namespace FUSE +int +FUSE::lock(const fuse_file_info_t *ffi, + int cmd, + struct flock *flock) { - int - lock(const fuse_file_info_t *ffi, - int cmd, - struct flock *flock) - { - return -ENOSYS; - } + return -ENOSYS; } diff --git a/src/fuse_mkdir.cpp b/src/fuse_mkdir.cpp index 80a4056d..3193062a 100644 --- a/src/fuse_mkdir.cpp +++ b/src/fuse_mkdir.cpp @@ -33,9 +33,9 @@ static int -_mkdir_core(const std::string &fullpath_, - mode_t mode_, - const mode_t umask_) +_mkdir_core(const fs::path &fullpath_, + mode_t mode_, + const mode_t umask_) { if(!fs::acl::dir_has_defaults(fullpath_)) mode_ &= ~umask_; @@ -45,15 +45,15 @@ _mkdir_core(const std::string &fullpath_, static int -_mkdir_loop_core(const std::string &createpath_, - const char *fusepath_, - const mode_t mode_, - const mode_t umask_) +_mkdir_loop_core(const fs::path &createpath_, + const fs::path &fusepath_, + const mode_t mode_, + const mode_t umask_) { int rv; - std::string fullpath; + fs::path fullpath; - fullpath = fs::path::make(createpath_,fusepath_); + fullpath = createpath_ / fusepath_; rv = ::_mkdir_core(fullpath,mode_,umask_); @@ -64,8 +64,8 @@ static int _mkdir_loop(const Branch *existingbranch_, const std::vector &createbranches_, - const char *fusepath_, - const std::string &fusedirpath_, + const fs::path &fusepath_, + const fs::path &fusedirpath_, const mode_t mode_, const mode_t umask_) { @@ -97,16 +97,16 @@ int _mkdir(const Policy::Search &getattrPolicy_, const Policy::Create &mkdirPolicy_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const mode_t mode_, const mode_t umask_) { int rv; - std::string fusedirpath; + fs::path fusedirpath; std::vector createbranches; std::vector existingbranches; - fusedirpath = fs::path::dirname(fusepath_); + fusedirpath = fusepath_.parent_path(); rv = getattrPolicy_(branches_,fusedirpath,existingbranches); if(rv < 0) @@ -129,13 +129,14 @@ FUSE::mkdir(const char *fusepath_, mode_t mode_) { int rv; + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); rv = ::_mkdir(cfg.func.getattr.policy, cfg.func.mkdir.policy, cfg.branches, - fusepath_, + fusepath, mode_, fc->umask); if(rv == -EROFS) @@ -144,7 +145,7 @@ FUSE::mkdir(const char *fusepath_, rv = ::_mkdir(cfg.func.getattr.policy, cfg.func.mkdir.policy, cfg.branches, - fusepath_, + fusepath, mode_, fc->umask); } diff --git a/src/fuse_mknod.cpp b/src/fuse_mknod.cpp index d7af33b2..2b45c776 100644 --- a/src/fuse_mknod.cpp +++ b/src/fuse_mknod.cpp @@ -34,10 +34,10 @@ static inline int -_mknod_core(const std::string &fullpath_, - mode_t mode_, - const mode_t umask_, - const dev_t dev_) +_mknod_core(const fs::path &fullpath_, + mode_t mode_, + const mode_t umask_, + const dev_t dev_) { if(!fs::acl::dir_has_defaults(fullpath_)) mode_ &= ~umask_; @@ -47,16 +47,16 @@ _mknod_core(const std::string &fullpath_, static int -_mknod_loop_core(const std::string &createbranch_, - const char *fusepath_, - const mode_t mode_, - const mode_t umask_, - const dev_t dev_) +_mknod_loop_core(const fs::path &createbranch_, + const fs::path &fusepath_, + const mode_t mode_, + const mode_t umask_, + const dev_t dev_) { int rv; - std::string fullpath; + fs::path fullpath; - fullpath = fs::path::make(createbranch_,fusepath_); + fullpath = createbranch_ / fusepath_; rv = ::_mknod_core(fullpath,mode_,umask_,dev_); @@ -65,10 +65,10 @@ _mknod_loop_core(const std::string &createbranch_, static int -_mknod_loop(const std::string &existingbranch_, +_mknod_loop(const fs::path &existingbranch_, const std::vector &createbranches_, - const char *fusepath_, - const std::string &fusedirpath_, + const fs::path &fusepath_, + const fs::path &fusedirpath_, const mode_t mode_, const mode_t umask_, const dev_t dev_) @@ -102,17 +102,17 @@ int _mknod(const Policy::Search &searchFunc_, const Policy::Create &createFunc_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const mode_t mode_, const mode_t umask_, const dev_t dev_) { int rv; - std::string fusedirpath; + fs::path fusedirpath; std::vector createbranches; std::vector existingbranches; - fusedirpath = fs::path::dirname(fusepath_); + fusedirpath = fusepath_.parent_path(); rv = searchFunc_(branches_,fusedirpath,existingbranches); if(rv < 0) @@ -137,13 +137,14 @@ FUSE::mknod(const char *fusepath_, dev_t rdev_) { int rv; + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); rv = ::_mknod(cfg.func.getattr.policy, cfg.func.mknod.policy, cfg.branches, - fusepath_, + fusepath, mode_, fc->umask, rdev_); @@ -153,7 +154,7 @@ FUSE::mknod(const char *fusepath_, rv = ::_mknod(cfg.func.getattr.policy, cfg.func.mknod.policy, cfg.branches, - fusepath_, + fusepath, mode_, fc->umask, rdev_); diff --git a/src/fuse_open.cpp b/src/fuse_open.cpp index 78a73ebd..dfec7e37 100644 --- a/src/fuse_open.cpp +++ b/src/fuse_open.cpp @@ -40,6 +40,7 @@ #include #include + static bool _rdonly(const int flags_) @@ -49,8 +50,8 @@ _rdonly(const int flags_) static int -_lchmod_and_open_if_not_writable_and_empty(const std::string &fullpath_, - const int flags_) +_lchmod_and_open_if_not_writable_and_empty(const fs::path &fullpath_, + const int flags_) { int rv; struct stat st; @@ -77,7 +78,7 @@ _lchmod_and_open_if_not_writable_and_empty(const std::string &fullpath_, static int -_nfsopenhack(const std::string &fullpath_, +_nfsopenhack(const fs::path &fullpath_, const int flags_, const NFSOpenHack nfsopenhack_) { @@ -89,7 +90,7 @@ _nfsopenhack(const std::string &fullpath_, case NFSOpenHack::ENUM::GIT: if(::_rdonly(flags_)) return -EACCES; - if(fullpath_.find("/.git/") == std::string::npos) + if(fullpath_.string().find("/.git/") == std::string::npos) return -EACCES; return ::_lchmod_and_open_if_not_writable_and_empty(fullpath_,flags_); case NFSOpenHack::ENUM::ALL: @@ -194,9 +195,9 @@ _config_to_ffi_flags(Config &cfg_, static int -_open_path(const std::string &filepath_, +_open_path(const fs::path &filepath_, const Branch *branch_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, const NFSOpenHack nfsopenhack_) { @@ -211,7 +212,7 @@ _open_path(const std::string &filepath_, fi = new FileInfo(fd,branch_,fusepath_,ffi_->direct_io); - ffi_->fh = reinterpret_cast(fi); + ffi_->fh = fi->to_fh(); return 0; } @@ -220,7 +221,7 @@ static int _open_fd(const int fd_, const Branch *branch_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_) { int fd; @@ -232,7 +233,7 @@ _open_fd(const int fd_, fi = new FileInfo(fd,branch_,fusepath_,ffi_->direct_io); - ffi_->fh = reinterpret_cast(fi); + ffi_->fh = fi->to_fh(); return 0; } @@ -241,23 +242,23 @@ static int _open(const Policy::Search &searchFunc_, const Branches &ibranches_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, const bool link_cow_, const NFSOpenHack nfsopenhack_) { int rv; - std::string filepath; + fs::path filepath; std::vector obranches; rv = searchFunc_(ibranches_,fusepath_,obranches); if(rv < 0) return rv; - filepath = fs::path::make(obranches[0]->path,fusepath_); + filepath = obranches[0]->path / fusepath_; - if(link_cow_ && fs::cow::is_eligible(filepath.c_str(),ffi_->flags)) - fs::cow::break_link(filepath.c_str()); + if(link_cow_ && fs::cow::is_eligible(filepath,ffi_->flags)) + fs::cow::break_link(filepath); rv = ::_open_path(filepath, obranches[0], @@ -280,7 +281,7 @@ _(const PassthroughEnum e_, static int _open_for_insert_lambda(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, State::OpenFile *of_) { @@ -306,7 +307,7 @@ _open_for_insert_lambda(const fuse_context *fc_, if(rv < 0) return rv; - fi = reinterpret_cast(ffi_->fh); + fi = FileInfo::from_fh(ffi_->fh); of_->ref_count = 1; of_->fi = fi; @@ -337,7 +338,7 @@ _open_for_insert_lambda(const fuse_context *fc_, static int _open_for_update_lambda(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, State::OpenFile *of_) { @@ -373,10 +374,9 @@ _open_for_update_lambda(const fuse_context *fc_, static inline -constexpr auto _open_insert_lambda(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, int *rv_) { @@ -392,10 +392,9 @@ _open_insert_lambda(const fuse_context *fc_, static inline -constexpr auto _open_update_lambda(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_, int *rv_) { @@ -424,7 +423,7 @@ _open_update_lambda(const fuse_context *fc_, static int _open(const fuse_context *fc_, - const char *fusepath_, + const fs::path &fusepath_, fuse_file_info_t *ffi_) { int rv; @@ -449,14 +448,12 @@ _open(const fuse_context *fc_, } -namespace FUSE +int +FUSE::open(const char *fusepath_, + fuse_file_info_t *ffi_) { - int - open(const char *fusepath_, - fuse_file_info_t *ffi_) - { - const fuse_context *fc = fuse_get_context(); - - return ::_open(fc,fusepath_,ffi_); - } + const fs::path fusepath{fusepath_}; + const fuse_context *fc = fuse_get_context(); + + return ::_open(fc,fusepath,ffi_); } diff --git a/src/fuse_opendir.cpp b/src/fuse_opendir.cpp index b0262e41..c2e09eac 100644 --- a/src/fuse_opendir.cpp +++ b/src/fuse_opendir.cpp @@ -26,7 +26,11 @@ int FUSE::opendir(const char *fusepath_, fuse_file_info_t *ffi_) { - ffi_->fh = reinterpret_cast(new DirInfo(fusepath_)); + DirInfo *di; + + di = new DirInfo(fusepath_); + + ffi_->fh = di->to_fh(); ffi_->noflush = true; diff --git a/src/fuse_poll.cpp b/src/fuse_poll.cpp index ad5b0a64..e6fe3f3e 100644 --- a/src/fuse_poll.cpp +++ b/src/fuse_poll.cpp @@ -16,22 +16,21 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "fuse_poll.hpp" + #include "errno.hpp" #include "fuse.h" -namespace FUSE +int +FUSE::poll(const fuse_file_info_t *ffi_, + fuse_pollhandle_t *ph_, + unsigned *reventsp_) { - int - poll(const fuse_file_info_t *ffi_, - fuse_pollhandle_t *ph_, - unsigned *reventsp_) - { - (void)ffi_; - (void)ph_; - (void)reventsp_; - - return -ENOSYS; - } + (void)ffi_; + (void)ph_; + (void)reventsp_; + + return -ENOSYS; } diff --git a/src/fuse_read.cpp b/src/fuse_read.cpp index 2def4e7e..dc378426 100644 --- a/src/fuse_read.cpp +++ b/src/fuse_read.cpp @@ -60,7 +60,7 @@ FUSE::read(const fuse_file_info_t *ffi_, size_t size_, off_t offset_) { - FileInfo *fi = reinterpret_cast(ffi_->fh); + FileInfo *fi = FileInfo::from_fh(ffi_->fh); if(fi->direct_io) return ::_read_direct_io(fi->fd,buf_,size_,offset_); diff --git a/src/fuse_readdir.cpp b/src/fuse_readdir.cpp index af12504e..16fc2045 100644 --- a/src/fuse_readdir.cpp +++ b/src/fuse_readdir.cpp @@ -80,7 +80,7 @@ _handle_ENOENT(const fuse_file_info_t *ffi_, fuse_dirents_t *buf_) { dirent de; - DirInfo *di = reinterpret_cast(ffi_->fh); + DirInfo *di = DirInfo::from_fh(ffi_->fh); if(di->fusepath != "/") return -ENOENT; diff --git a/src/fuse_readdir_cor.cpp b/src/fuse_readdir_cor.cpp index 82684e6e..b21a729e 100644 --- a/src/fuse_readdir_cor.cpp +++ b/src/fuse_readdir_cor.cpp @@ -35,6 +35,8 @@ #include "int_types.h" +#include + #define MAX_ENTRIES_PER_LOOP 64 @@ -63,153 +65,152 @@ _dirent_exact_namelen(const struct dirent *d_) #endif } -namespace l +struct Error { - struct Error +private: + int _err; + +public: + Error() + : _err(ENOENT) { - private: - int _err; + } - public: - Error() - : _err(ENOENT) - { - } + operator int() + { + return _err; + } - operator int() - { - return _err; - } + Error& + operator=(int v_) + { + if(_err != 0) + _err = v_; + + return *this; + } +}; - Error& - operator=(int v_) +static +inline +int +_readdir(const fs::path &branch_path_, + const fs::path &rel_dirpath_, + HashSet &names_, + fuse_dirents_t *buf_, + std::mutex &mutex_) +{ + int rv; + DIR *dir; + fs::path rel_filepath; + fs::path abs_dirpath; + + abs_dirpath = branch_path_ / rel_dirpath_; + + errno = 0; + dir = fs::opendir(abs_dirpath); + if(dir == NULL) + return errno; + + DEFER{ fs::closedir(dir); }; + + // The default buffer size in glibc is 32KB. 64 is based on a + // guess of an average size of 512B per entry. This is to limit + // contention on the lock when needing to request more data from + // the kernel. This could be handled better by using getdents but + // due to the differences between Linux and FreeBSD a more + // complicated abstraction needs to be created to handle them to + // make it easier to use across the codebase. + // * https://man7.org/linux/man-pages/man2/getdents.2.html + // * https://man.freebsd.org/cgi/man.cgi?query=getdents + rel_filepath = rel_dirpath_ / "dummy"; + while(true) { - if(_err != 0) - _err = v_; + std::lock_guard lk(mutex_); + for(int i = 0; i < MAX_ENTRIES_PER_LOOP; i++) + { + dirent *de; + u64 namelen; + + de = fs::readdir(dir); + if(de == NULL) + return 0; - return *this; + namelen = ::_dirent_exact_namelen(de); + + rv = names_.put(de->d_name,namelen); + if(rv == 0) + continue; + + rel_filepath.replace_filename(de->d_name); + + de->d_ino = fs::inode::calc(branch_path_, + rel_filepath, + DTTOIF(de->d_type), + de->d_ino); + + rv = fuse_dirents_add(buf_,de,namelen); + if(rv >= 0) + continue; + + return ENOMEM; + } } - }; - - static - inline - int - readdir(const std::string &branch_path_, - const std::string &rel_dirpath_, - HashSet &names_, - fuse_dirents_t *buf_, - std::mutex &mutex_) - { - int rv; - DIR *dir; - std::string rel_filepath; - std::string abs_dirpath; - - abs_dirpath = fs::path::make(branch_path_,rel_dirpath_); - - errno = 0; - dir = fs::opendir(abs_dirpath); - if(dir == NULL) - return errno; - - DEFER{ fs::closedir(dir); }; - - // The default buffer size in glibc is 32KB. 64 is based on a - // guess of an average size of 512B per entry. This is to limit - // contention on the lock when needing to request more data from - // the kernel. This could be handled better by using getdents but - // due to the differences between Linux and FreeBSD a more - // complicated abstraction needs to be created to handle them to - // make it easier to use across the codebase. - // * https://man7.org/linux/man-pages/man2/getdents.2.html - // * https://man.freebsd.org/cgi/man.cgi?query=getdents - while(true) - { - std::lock_guard lk(mutex_); - for(int i = 0; i < MAX_ENTRIES_PER_LOOP; i++) - { - dirent *de; - u64 namelen; - - de = fs::readdir(dir); - if(de == NULL) - return 0; - - namelen = ::_dirent_exact_namelen(de); - - rv = names_.put(de->d_name,namelen); - if(rv == 0) - continue; - - rel_filepath = fs::path::make(rel_dirpath_,de->d_name); - de->d_ino = fs::inode::calc(branch_path_, - rel_filepath, - DTTOIF(de->d_type), - de->d_ino); - - rv = fuse_dirents_add(buf_,de,namelen); - if(rv >= 0) - continue; - - return ENOMEM; - } - } - - return 0; - } - static - inline - int - concurrent_readdir(ThreadPool &tp_, - const Branches::Ptr &branches_, - const std::string &rel_dirpath_, - fuse_dirents_t *buf_, - const uid_t uid_, - const gid_t gid_) - { - HashSet names; - std::mutex mutex; - std::vector> futures; + return 0; +} + +static +inline +int +_concurrent_readdir(ThreadPool &tp_, + const Branches::Ptr &branches_, + const fs::path &rel_dirpath_, + fuse_dirents_t *buf_, + const uid_t uid_, + const gid_t gid_) +{ + HashSet names; + std::mutex mutex; + std::vector> futures; - fuse_dirents_reset(buf_); - futures.reserve(branches_->size()); + fuse_dirents_reset(buf_); + futures.reserve(branches_->size()); - for(const auto &branch : *branches_) - { - auto func = - [&,buf_,uid_,gid_]() - { - const ugid::Set ugid(uid_,gid_); + for(const auto &branch : *branches_) + { + auto func = + [&,buf_,uid_,gid_]() + { + const ugid::Set ugid(uid_,gid_); - return l::readdir(branch.path, - rel_dirpath_, - names, - buf_, - mutex); - }; + return ::_readdir(branch.path, + rel_dirpath_, + names, + buf_, + mutex); + }; - auto rv = tp_.enqueue_task(std::move(func)); + auto rv = tp_.enqueue_task(std::move(func)); - futures.emplace_back(std::move(rv)); - } + futures.emplace_back(std::move(rv)); + } - Error error; - for(auto &future : futures) - error = future.get(); + Error error; + for(auto &future : futures) + error = future.get(); - return -error; - } + return -error; } int FUSE::ReadDirCOR::operator()(const fuse_file_info_t *ffi_, fuse_dirents_t *buf_) { - DirInfo *di = reinterpret_cast(ffi_->fh); + DirInfo *di = DirInfo::from_fh(ffi_->fh); const fuse_context *fc = fuse_get_context(); - return l::concurrent_readdir(_tp, + return ::_concurrent_readdir(_tp, cfg.branches, di->fusepath, buf_, diff --git a/src/fuse_readdir_cosr.cpp b/src/fuse_readdir_cosr.cpp index 7246b242..d25ff244 100644 --- a/src/fuse_readdir_cosr.cpp +++ b/src/fuse_readdir_cosr.cpp @@ -45,175 +45,173 @@ FUSE::ReadDirCOSR::~ReadDirCOSR() } -namespace l +struct DirRV { - struct DirRV - { - const std::string *branch_path; - DIR *dir; - int err; - }; + const std::string *branch_path; + DIR *dir; + int err; +}; - struct Error - { - private: - int _err; +struct Error +{ +private: + int _err; - public: - Error() - : _err(ENOENT) - { +public: + Error() + : _err(ENOENT) + { - } + } - operator int() - { - return _err; - } + operator int() + { + return _err; + } - Error& - operator=(int const v_) - { - if(_err != 0) - _err = v_; + Error& + operator=(int const v_) + { + if(_err != 0) + _err = v_; - return *this; - } - }; + return *this; + } +}; - static - uint64_t - dirent_exact_namelen(const struct dirent *d_) - { +static +uint64_t +_dirent_exact_namelen(const struct dirent *d_) +{ #ifdef _D_EXACT_NAMLEN - return _D_EXACT_NAMLEN(d_); + return _D_EXACT_NAMLEN(d_); #elif defined _DIRENT_HAVE_D_NAMLEN - return d_->d_namlen; + return d_->d_namlen; #else - return strlen(d_->d_name); + return strlen(d_->d_name); #endif - } +} - static - inline - std::vector> - opendir(ThreadPool &tp_, - const Branches::Ptr &branches_, - const std::string &rel_dirpath_, - uid_t const uid_, - gid_t const gid_) - { - std::vector> futures; +static +inline +std::vector> +_opendir(ThreadPool &tp_, + const Branches::Ptr &branches_, + const fs::path &rel_dirpath_, + uid_t const uid_, + gid_t const gid_) +{ + std::vector> futures; - futures.reserve(branches_->size()); + futures.reserve(branches_->size()); - for(const auto &branch : *branches_) - { - auto func = - [&branch,&rel_dirpath_,uid_,gid_]() - { - DIR *dir; - std::string abs_dirpath; - const ugid::Set ugid(uid_,gid_); + for(const auto &branch : *branches_) + { + auto func = + [&branch,&rel_dirpath_,uid_,gid_]() + { + DIR *dir; + fs::path abs_dirpath; + const ugid::Set ugid(uid_,gid_); - abs_dirpath = fs::path::make(branch.path,rel_dirpath_); + abs_dirpath = branch.path / rel_dirpath_; - errno = 0; - dir = fs::opendir(abs_dirpath); + errno = 0; + dir = fs::opendir(abs_dirpath); - return DirRV{&branch.path,dir,errno}; - }; + return DirRV{&branch.path,dir,errno}; + }; - auto rv = tp_.enqueue_task(std::move(func)); + auto rv = tp_.enqueue_task(std::move(func)); - futures.emplace_back(std::move(rv)); - } + futures.emplace_back(std::move(rv)); + } - return futures; - } + return futures; +} - static - inline - int - readdir(std::vector> &dh_futures_, - const std::string &rel_dirpath_, - fuse_dirents_t *buf_) - { - Error error; - HashSet names; - std::string rel_filepath; +static +inline +int +_readdir(std::vector> &dh_futures_, + const fs::path &rel_dirpath_, + fuse_dirents_t *buf_) +{ + Error error; + HashSet names; + fs::path rel_filepath; - for(auto &dh_future : dh_futures_) - { - int rv; - DirRV dirrv; + rel_filepath = rel_dirpath_ / "dummy"; + for(auto &dh_future : dh_futures_) + { + int rv; + DirRV dirrv; - dirrv = dh_future.get(); + dirrv = dh_future.get(); - error = dirrv.err; - if(dirrv.dir == NULL) - continue; + error = dirrv.err; + if(dirrv.dir == NULL) + continue; - DEFER { fs::closedir(dirrv.dir); }; + DEFER { fs::closedir(dirrv.dir); }; - rv = 0; - for(dirent *de = fs::readdir(dirrv.dir); de && !rv; de = fs::readdir(dirrv.dir)) - { - std::uint64_t namelen; + rv = 0; + for(dirent *de = fs::readdir(dirrv.dir); de && !rv; de = fs::readdir(dirrv.dir)) + { + std::uint64_t namelen; - namelen = l::dirent_exact_namelen(de); + namelen = ::_dirent_exact_namelen(de); - rv = names.put(de->d_name,namelen); - if(rv == 0) - continue; + rv = names.put(de->d_name,namelen); + if(rv == 0) + continue; - rel_filepath = fs::path::make(rel_dirpath_,de->d_name); - de->d_ino = fs::inode::calc(*dirrv.branch_path, - rel_filepath, - DTTOIF(de->d_type), - de->d_ino); + rel_filepath.replace_filename(de->d_name); + de->d_ino = fs::inode::calc(*dirrv.branch_path, + rel_filepath, + DTTOIF(de->d_type), + de->d_ino); - rv = fuse_dirents_add(buf_,de,namelen); - if(rv == 0) - continue; + rv = fuse_dirents_add(buf_,de,namelen); + if(rv == 0) + continue; - error = ENOMEM; - } - } + error = ENOMEM; + } + } - return -error; - } + return -error; +} - static - inline - int - readdir(ThreadPool &tp_, - const Branches::Ptr &branches_, - const std::string &rel_dirpath_, - fuse_dirents_t *buf_, - uid_t const uid_, - gid_t const gid_) - { - int rv; - std::vector> futures; +static +inline +int +_readdir(ThreadPool &tp_, + const Branches::Ptr &branches_, + const fs::path &rel_dirpath_, + fuse_dirents_t *buf_, + uid_t const uid_, + gid_t const gid_) +{ + int rv; + std::vector> futures; - fuse_dirents_reset(buf_); + fuse_dirents_reset(buf_); - futures = l::opendir(tp_,branches_,rel_dirpath_,uid_,gid_); - rv = l::readdir(futures,rel_dirpath_,buf_); + futures = ::_opendir(tp_,branches_,rel_dirpath_,uid_,gid_); + rv = ::_readdir(futures,rel_dirpath_,buf_); - return rv; - } + return rv; } int FUSE::ReadDirCOSR::operator()(fuse_file_info_t const *ffi_, fuse_dirents_t *buf_) { - DirInfo *di = reinterpret_cast(ffi_->fh); + DirInfo *di = DirInfo::from_fh(ffi_->fh); const fuse_context *fc = fuse_get_context(); - return l::readdir(_tp, + return ::_readdir(_tp, cfg.branches, di->fusepath, buf_, diff --git a/src/fuse_readdir_seq.cpp b/src/fuse_readdir_seq.cpp index 9def08cd..7bb55c70 100644 --- a/src/fuse_readdir_seq.cpp +++ b/src/fuse_readdir_seq.cpp @@ -56,22 +56,23 @@ _dirent_exact_namelen(const struct dirent *d_) static int _readdir(const Branches::Ptr &branches_, - const std::string &rel_dirpath_, + const fs::path &rel_dirpath_, fuse_dirents_t *buf_) { Err err; HashSet names; - std::string rel_filepath; - std::string abs_dirpath; + fs::path rel_filepath; + fs::path abs_dirpath; fuse_dirents_reset(buf_); + rel_filepath = rel_dirpath_ / "dummy"; for(const auto &branch : *branches_) { int rv; DIR *dh; - abs_dirpath = fs::path::make(branch.path,rel_dirpath_); + abs_dirpath = branch.path / rel_dirpath_; errno = 0; dh = fs::opendir(abs_dirpath); @@ -92,7 +93,7 @@ _readdir(const Branches::Ptr &branches_, if(rv == 0) continue; - rel_filepath = fs::path::make(rel_dirpath_,de->d_name); + rel_filepath.replace_filename(de->d_name); de->d_ino = fs::inode::calc(branch.path, rel_filepath, DTTOIF(de->d_type), @@ -111,7 +112,7 @@ int FUSE::ReadDirSeq::operator()(fuse_file_info_t const *ffi_, fuse_dirents_t *buf_) { - DirInfo *di = reinterpret_cast(ffi_->fh); + DirInfo *di = DirInfo::from_fh(ffi_->fh); const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); diff --git a/src/fuse_readlink.cpp b/src/fuse_readlink.cpp index 42f9d71d..c202cd9a 100644 --- a/src/fuse_readlink.cpp +++ b/src/fuse_readlink.cpp @@ -26,16 +26,14 @@ #include "fuse.h" -#include - -using std::string; +#include static int -_readlink_core_standard(const string &fullpath_, - char *buf_, - const size_t size_) +_readlink_core_standard(const fs::path &fullpath_, + char *buf_, + const size_t size_) { int rv; @@ -51,10 +49,10 @@ _readlink_core_standard(const string &fullpath_, static int -_readlink_core_symlinkify(const string &fullpath_, - char *buf_, - const size_t size_, - const time_t symlinkify_timeout_) +_readlink_core_symlinkify(const fs::path &fullpath_, + char *buf_, + const size_t size_, + const time_t symlinkify_timeout_) { int rv; struct stat st; @@ -73,16 +71,16 @@ _readlink_core_symlinkify(const string &fullpath_, static int -_readlink_core(const string &basepath_, - const char *fusepath_, - char *buf_, - const size_t size_, - const bool symlinkify_, - const time_t symlinkify_timeout_) +_readlink_core(const fs::path &basepath_, + const fs::path &fusepath_, + char *buf_, + const size_t size_, + const bool symlinkify_, + const time_t symlinkify_timeout_) { - string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = basepath_ / fusepath_; if(symlinkify_) return ::_readlink_core_symlinkify(fullpath,buf_,size_,symlinkify_timeout_); @@ -94,7 +92,7 @@ static int _readlink(const Policy::Search &searchFunc_, const Branches &ibranches_, - const char *fusepath_, + const fs::path &fusepath_, char *buf_, const size_t size_, const bool symlinkify_, @@ -121,12 +119,13 @@ FUSE::readlink(const char *fusepath_, char *buf_, size_t size_) { + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); return ::_readlink(cfg.func.readlink.policy, cfg.branches, - fusepath_, + fusepath, buf_, size_, cfg.symlinkify, diff --git a/src/fuse_release.cpp b/src/fuse_release.cpp index c39deb2b..188032b9 100644 --- a/src/fuse_release.cpp +++ b/src/fuse_release.cpp @@ -93,7 +93,7 @@ int _release(const fuse_context *fc_, const fuse_file_info_t *ffi_) { - FileInfo *fi = reinterpret_cast(ffi_->fh); + FileInfo *fi = FileInfo::from_fh(ffi_->fh); return ::_release(fc_,fi,cfg.dropcacheonclose); } diff --git a/src/fuse_releasedir.cpp b/src/fuse_releasedir.cpp index bdc28f8a..47f36398 100644 --- a/src/fuse_releasedir.cpp +++ b/src/fuse_releasedir.cpp @@ -34,7 +34,7 @@ _releasedir(DirInfo *di_) int FUSE::releasedir(const fuse_file_info_t *ffi_) { - DirInfo *di = reinterpret_cast(ffi_->fh); + DirInfo *di = DirInfo::from_fh(ffi_->fh); return ::_releasedir(di); } diff --git a/src/fuse_removexattr.cpp b/src/fuse_removexattr.cpp index ad189492..b007af7b 100644 --- a/src/fuse_removexattr.cpp +++ b/src/fuse_removexattr.cpp @@ -25,23 +25,19 @@ #include "fuse.h" -#include #include -using std::string; -using std::vector; - static void -_removexattr_loop_core(const string &basepath_, - const char *fusepath_, - const char *attrname_, - PolicyRV *prv_) +_removexattr_loop_core(const fs::path &basepath_, + const fs::path &fusepath_, + const char *attrname_, + PolicyRV *prv_) { - string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = basepath_ / fusepath_; errno = 0; fs::lremovexattr(fullpath,attrname_); @@ -52,7 +48,7 @@ _removexattr_loop_core(const string &basepath_, static void _removexattr_loop(const std::vector &branches_, - const char *fusepath_, + const fs::path &fusepath_, const char *attrname_, PolicyRV *prv_) { @@ -67,7 +63,7 @@ int _removexattr(const Policy::Action &actionFunc_, const Policy::Search &searchFunc_, const Branches &ibranches_, - const char *fusepath_, + const fs::path &fusepath_, const char *attrname_) { int rv; @@ -96,7 +92,9 @@ int FUSE::removexattr(const char *fusepath_, const char *attrname_) { - if(Config::is_ctrl_file(fusepath_)) + const fs::path fusepath{fusepath_}; + + if(Config::is_ctrl_file(fusepath)) return -ENOATTR; if(cfg.xattr.to_int()) @@ -108,6 +106,6 @@ FUSE::removexattr(const char *fusepath_, return ::_removexattr(cfg.func.removexattr.policy, cfg.func.getxattr.policy, cfg.branches, - fusepath_, + fusepath, attrname_); } diff --git a/src/fuse_rename.cpp b/src/fuse_rename.cpp index 321958bf..7c9de7bc 100644 --- a/src/fuse_rename.cpp +++ b/src/fuse_rename.cpp @@ -31,12 +31,10 @@ #include "ugid.hpp" #include -#include #include #include #include -namespace stdfs = std::filesystem; static bool @@ -70,19 +68,19 @@ _remove(const StrVec &toremove_) static int -_rename_create_path(const Policy::Search &searchPolicy_, - const Policy::Action &actionPolicy_, - const Branches::Ptr &branches_, - const stdfs::path &oldfusepath_, - const stdfs::path &newfusepath_) +_rename_create_path(const Policy::Search &searchPolicy_, + const Policy::Action &actionPolicy_, + const Branches::Ptr &branches_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_) { int rv; Err err; StrVec toremove; std::vector newbranches; std::vector oldbranches; - stdfs::path oldfullpath; - stdfs::path newfullpath; + fs::path oldfullpath; + fs::path newfullpath; rv = actionPolicy_(branches_,oldfusepath_,oldbranches); if(rv < 0) @@ -129,17 +127,17 @@ _rename_create_path(const Policy::Search &searchPolicy_, static int -_rename_preserve_path(const Policy::Action &actionPolicy_, - const Branches::Ptr &branches_, - const stdfs::path &oldfusepath_, - const stdfs::path &newfusepath_) +_rename_preserve_path(const Policy::Action &actionPolicy_, + const Branches::Ptr &branches_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_) { int rv; bool success; StrVec toremove; std::vector oldbranches; - stdfs::path oldfullpath; - stdfs::path newfullpath; + fs::path oldfullpath; + fs::path newfullpath; rv = actionPolicy_(branches_,oldfusepath_,oldbranches); if(rv < 0) @@ -181,11 +179,11 @@ _rename_preserve_path(const Policy::Action &actionPolicy_, static void -_rename_exdev_rename_back(const std::vector &branches_, - const stdfs::path &oldfusepath_) +_rename_exdev_rename_back(const std::vector &branches_, + const fs::path &oldfusepath_) { - stdfs::path oldpath; - stdfs::path newpath; + fs::path oldpath; + fs::path newpath; for(auto &branch : branches_) { @@ -202,14 +200,14 @@ _rename_exdev_rename_back(const std::vector &branches_, static int -_rename_exdev_rename_target(const Policy::Action &actionPolicy_, - const Branches::Ptr &ibranches_, - const stdfs::path &oldfusepath_, - std::vector &obranches_) +_rename_exdev_rename_target(const Policy::Action &actionPolicy_, + const Branches::Ptr &ibranches_, + const fs::path &oldfusepath_, + std::vector &obranches_) { int rv; - stdfs::path clonesrc; - stdfs::path clonetgt; + fs::path clonesrc; + fs::path clonetgt; rv = actionPolicy_(ibranches_,oldfusepath_,obranches_); if(rv < 0) @@ -250,14 +248,14 @@ _rename_exdev_rename_target(const Policy::Action &actionPolicy_, static int -_rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, - const Branches::Ptr &branches_, - const stdfs::path &oldfusepath_, - const stdfs::path &newfusepath_) +_rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, + const Branches::Ptr &branches_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_) { int rv; - stdfs::path target; - stdfs::path linkpath; + fs::path target; + fs::path linkpath; std::vector branches; rv = ::_rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches); @@ -269,7 +267,7 @@ _rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, target += oldfusepath_; target = target.lexically_relative(linkpath.parent_path()); - rv = FUSE::symlink(target.c_str(),linkpath.c_str()); + rv = FUSE::symlink(target.c_str(),linkpath); if(rv < 0) ::_rename_exdev_rename_back(branches,oldfusepath_); @@ -278,15 +276,15 @@ _rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, static int -_rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, - const Branches::Ptr &branches_, - const stdfs::path &mount_, - const stdfs::path &oldfusepath_, - const stdfs::path &newfusepath_) +_rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, + const Branches::Ptr &branches_, + const fs::path &mount_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_) { int rv; - stdfs::path target; - stdfs::path linkpath; + fs::path target; + fs::path linkpath; std::vector branches; rv = ::_rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches); @@ -298,7 +296,7 @@ _rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, target /= ".mergerfs_rename_exdev"; target += oldfusepath_; - rv = FUSE::symlink(target.c_str(),linkpath.c_str()); + rv = FUSE::symlink(target.c_str(),linkpath); if(rv < 0) ::_rename_exdev_rename_back(branches,oldfusepath_); @@ -307,9 +305,9 @@ _rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, static int -_rename_exdev(Config &cfg_, - const stdfs::path &oldfusepath_, - const stdfs::path &newfusepath_) +_rename_exdev(Config &cfg_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_) { switch(cfg_.rename_exdev) { @@ -333,9 +331,9 @@ _rename_exdev(Config &cfg_, static int -_rename(Config &cfg_, - const stdfs::path &oldpath_, - const stdfs::path &newpath_) +_rename(Config &cfg_, + const fs::path &oldpath_, + const fs::path &newpath_) { if(cfg_.func.create.policy.path_preserving() && !cfg_.ignorepponrename) return ::_rename_preserve_path(cfg_.func.rename.policy, @@ -355,8 +353,8 @@ FUSE::rename(const char *oldfusepath_, const char *newfusepath_) { int rv; - stdfs::path oldfusepath(oldfusepath_); - stdfs::path newfusepath(newfusepath_); + const fs::path oldfusepath{oldfusepath_}; + const fs::path newfusepath{newfusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); diff --git a/src/fuse_rmdir.cpp b/src/fuse_rmdir.cpp index 560fb464..5c7c483e 100644 --- a/src/fuse_rmdir.cpp +++ b/src/fuse_rmdir.cpp @@ -30,9 +30,6 @@ #include -using std::string; -using std::vector; - static int @@ -45,14 +42,14 @@ _should_unlink(int rv_, static int -_rmdir_core(const string &basepath_, - const char *fusepath_, +_rmdir_core(const fs::path &basepath_, + const fs::path &fusepath_, const FollowSymlinks followsymlinks_) { int rv; - string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = basepath_ / fusepath_; rv = fs::rmdir(fullpath); if(::_should_unlink(rv,followsymlinks_)) @@ -64,7 +61,7 @@ _rmdir_core(const string &basepath_, static int _rmdir_loop(const std::vector &branches_, - const char *fusepath_, + const fs::path &fusepath_, const FollowSymlinks followsymlinks_) { Err err; @@ -82,7 +79,7 @@ int _rmdir(const Policy::Action &actionFunc_, const Branches &branches_, const FollowSymlinks followsymlinks_, - const char *fusepath_) + const fs::path &fusepath_) { int rv; std::vector branches; @@ -97,11 +94,12 @@ _rmdir(const Policy::Action &actionFunc_, int FUSE::rmdir(const char *fusepath_) { + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); return ::_rmdir(cfg.func.rmdir.policy, cfg.branches, cfg.follow_symlinks, - fusepath_); + fusepath); } diff --git a/src/fuse_setxattr.cpp b/src/fuse_setxattr.cpp index a9d7d350..542f7daf 100644 --- a/src/fuse_setxattr.cpp +++ b/src/fuse_setxattr.cpp @@ -31,11 +31,10 @@ #include "fuse.h" +#include #include #include -#include - static const char SECURITY_CAPABILITY[] = "security.capability"; @@ -107,17 +106,17 @@ _setxattr_ctrl_file(const char *attrname_, static void -_setxattr_loop_core(const std::string &basepath_, - const char *fusepath_, - const char *attrname_, - const char *attrval_, - const size_t attrvalsize_, - const int flags_, - PolicyRV *prv_) +_setxattr_loop_core(const fs::path &basepath_, + const fs::path &fusepath_, + const char *attrname_, + const char *attrval_, + const size_t attrvalsize_, + const int flags_, + PolicyRV *prv_) { - std::string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = basepath_ / fusepath_; errno = 0; fs::lsetxattr(fullpath,attrname_,attrval_,attrvalsize_,flags_); @@ -128,7 +127,7 @@ _setxattr_loop_core(const std::string &basepath_, static void _setxattr_loop(const std::vector &branches_, - const char *fusepath_, + const fs::path &fusepath_, const char *attrname_, const char *attrval_, const size_t attrvalsize_, @@ -151,7 +150,7 @@ int _setxattr(const Policy::Action &setxattrPolicy_, const Policy::Search &getxattrPolicy_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const char *attrname_, const char *attrval_, const size_t attrvalsize_, @@ -181,11 +180,11 @@ _setxattr(const Policy::Action &setxattrPolicy_, static int -_setxattr(const char *fusepath_, - const char *attrname_, - const char *attrval_, - size_t attrvalsize_, - int flags_) +_setxattr(const fs::path &fusepath_, + const char *attrname_, + const char *attrval_, + size_t attrvalsize_, + int flags_) { if((cfg.security_capability == false) && ::_is_attrname_security_capability(attrname_)) @@ -215,11 +214,13 @@ FUSE::setxattr(const char *fusepath_, size_t attrvalsize_, int flags_) { - if(Config::is_ctrl_file(fusepath_)) + const fs::path fusepath{fusepath_}; + + if(Config::is_ctrl_file(fusepath)) return ::_setxattr_ctrl_file(attrname_, attrval_, attrvalsize_, flags_); - return ::_setxattr(fusepath_,attrname_,attrval_,attrvalsize_,flags_); + return ::_setxattr(fusepath,attrname_,attrval_,attrvalsize_,flags_); } diff --git a/src/fuse_statfs.cpp b/src/fuse_statfs.cpp index 9339ac53..6d9184eb 100644 --- a/src/fuse_statfs.cpp +++ b/src/fuse_statfs.cpp @@ -26,16 +26,12 @@ #include "fuse.h" +#include #include #include #include -#include #include -using std::string; -using std::map; -using std::vector; - static void @@ -80,28 +76,29 @@ _should_ignore(const StatFSIgnore ignore_, static int _statfs(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, const StatFS mode_, const StatFSIgnore ignore_, struct statvfs *fsstat_) { int rv; - string fullpath; struct stat st; struct statvfs stvfs; unsigned long min_bsize; unsigned long min_frsize; unsigned long min_namemax; - map fsstats; + std::map fsstats; + fs::path fullpath; min_bsize = std::numeric_limits::max(); min_frsize = std::numeric_limits::max(); min_namemax = std::numeric_limits::max(); for(const auto &branch : *branches_) { - fullpath = ((mode_ == StatFS::ENUM::FULL) ? - fs::path::make(branch.path,fusepath_) : - branch.path); + if(mode_ == StatFS::ENUM::FULL) + fullpath = branch.path / fusepath_; + else + fullpath = branch.path; rv = fs::lstat(fullpath,&st); if(rv < 0) @@ -127,8 +124,8 @@ _statfs(const Branches::Ptr &branches_, fsstats.insert(std::make_pair(st.st_dev,stvfs)); } - map::iterator iter = fsstats.begin(); - map::iterator enditer = fsstats.end(); + std::map::iterator iter = fsstats.begin(); + std::map::iterator enditer = fsstats.end(); if(iter != enditer) { *fsstat_ = iter->second; @@ -148,11 +145,12 @@ int FUSE::statfs(const char *fusepath_, struct statvfs *st_) { + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); return ::_statfs(cfg.branches, - fusepath_, + fusepath, cfg.statfs, cfg.statfs_ignore, st_); diff --git a/src/fuse_statx_supported.icpp b/src/fuse_statx_supported.icpp index 69d2f6b9..4bf0f9a7 100644 --- a/src/fuse_statx_supported.icpp +++ b/src/fuse_statx_supported.icpp @@ -25,6 +25,7 @@ #include "fs_inode.hpp" #include "fs_path.hpp" #include "fs_statx.hpp" +#include "state.hpp" #include "str.hpp" #include "symlinkify.hpp" #include "ugid.hpp" @@ -38,7 +39,7 @@ static void -_set_stat_if_leads_to_dir(const std::string &path_, +_set_stat_if_leads_to_dir(const fs::path &path_, struct fuse_statx *st_) { int rv; @@ -56,7 +57,7 @@ _set_stat_if_leads_to_dir(const std::string &path_, static void -_set_stat_if_leads_to_reg(const std::string &path_, +_set_stat_if_leads_to_reg(const fs::path &path_, struct fuse_statx *st_) { int rv; @@ -116,7 +117,7 @@ static int _statx(const Policy::Search &searchFunc_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const uint32_t flags_, const uint32_t mask_, struct fuse_statx *st_, @@ -125,14 +126,14 @@ _statx(const Policy::Search &searchFunc_, FollowSymlinks followsymlinks_) { int rv; - std::string fullpath; + fs::path fullpath; std::vector branches; rv = searchFunc_(branches_,fusepath_,branches); if(rv < 0) return rv; - fullpath = fs::path::make(branches[0]->path,fusepath_); + fullpath = branches[0]->path / fusepath_; switch(followsymlinks_) { @@ -162,14 +163,16 @@ _statx(const Policy::Search &searchFunc_, if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_)) symlinkify::convert(fullpath,st_); - fs::inode::calc(branches[0]->path,fusepath_,st_); + fs::inode::calc(branches[0]->path, + fusepath_, + st_); return 0; } static int -_statx(const char *fusepath_, +_statx(const fs::path &fusepath_, const uint32_t flags_, const uint32_t mask_, struct fuse_statx *st_, @@ -206,10 +209,12 @@ FUSE::statx(const char *fusepath_, struct fuse_statx *st_, fuse_timeouts_t *timeout_) { - if(Config::is_ctrl_file(fusepath_)) + const fs::path fusepath{fusepath_}; + + if(Config::is_ctrl_file(fusepath)) return ::_statx_controlfile(st_); - return ::_statx(fusepath_, + return ::_statx(fusepath, flags_|AT_STATX_DONT_SYNC, mask_, st_, @@ -223,9 +228,25 @@ FUSE::statx_fh(const uint64_t fh_, struct fuse_statx *st_, fuse_timeouts_t *timeout_) { - FileInfo *fi = reinterpret_cast(fh_); + uint64_t fh; + const fuse_context *fc = fuse_get_context(); + + fh = fh_; + if(fh == 0) + { + state.open_files.cvisit(fc->nodeid, + [&](auto &val_) + { + fh = val_.second.fi->to_fh(); + }); + } + + if(fh == 0) + return -ENOENT; + + FileInfo *fi = FileInfo::from_fh(fh); - return ::_statx(fi->fusepath.c_str(), + return ::_statx(fi->fusepath, flags_|AT_STATX_DONT_SYNC, mask_, st_, diff --git a/src/fuse_symlink.cpp b/src/fuse_symlink.cpp index b3161966..ed43630e 100644 --- a/src/fuse_symlink.cpp +++ b/src/fuse_symlink.cpp @@ -29,32 +29,30 @@ #include "fuse.h" -#include - #include #include -using std::string; - static int -_symlink_loop_core(const std::string &newbranch_, - const char *target_, - const char *linkpath_, - struct stat *st_) +_symlink_loop_core(const fs::path &newbranch_, + const char *target_, + const fs::path &linkpath_, + struct stat *st_) { int rv; - string fullnewpath; + fs::path fullnewpath; - fullnewpath = fs::path::make(newbranch_,linkpath_); + fullnewpath = newbranch_ / linkpath_; rv = fs::symlink(target_,fullnewpath); if((rv >= 0) && (st_ != NULL) && (st_->st_ino == 0)) { fs::lstat(fullnewpath,st_); if(st_->st_ino != 0) - fs::inode::calc(newbranch_,linkpath_,st_); + fs::inode::calc(newbranch_, + linkpath_, + st_); } return rv; @@ -62,11 +60,11 @@ _symlink_loop_core(const std::string &newbranch_, static int -_symlink_loop(const std::string &existingbranch_, +_symlink_loop(const fs::path &existingbranch_, const std::vector &newbranches_, const char *target_, - const char *linkpath_, - const std::string &newdirpath_, + const fs::path &linkpath_, + const fs::path &newdirpath_, struct stat *st_) { int rv; @@ -95,15 +93,15 @@ _symlink(const Policy::Search &searchFunc_, const Policy::Create &createFunc_, const Branches &branches_, const char *target_, - const char *linkpath_, + const fs::path &linkpath_, struct stat *st_) { int rv; - string newdirpath; + fs::path newdirpath; std::vector newbranches; std::vector existingbranches; - newdirpath = fs::path::dirname(linkpath_); + newdirpath = linkpath_.parent_path(); rv = searchFunc_(branches_,newdirpath,existingbranches); if(rv < 0) @@ -126,9 +124,23 @@ FUSE::symlink(const char *target_, const char *linkpath_, struct stat *st_, fuse_timeouts_t *timeouts_) +{ + const fs::path linkpath{linkpath_}; + + return FUSE::symlink(target_, + linkpath, + st_, + timeouts_); +} + +int +FUSE::symlink(const char *target_, + const fs::path &linkpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { int rv; - const fuse_context *fc = fuse_get_context(); + const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); rv = ::_symlink(cfg.func.getattr.policy, diff --git a/src/fuse_symlink.hpp b/src/fuse_symlink.hpp index ba568633..dbfaeb9c 100644 --- a/src/fuse_symlink.hpp +++ b/src/fuse_symlink.hpp @@ -18,6 +18,10 @@ #include "fuse.h" +#include "fs_path.hpp" + +#include + #include namespace FUSE @@ -27,4 +31,11 @@ namespace FUSE const char *linkpath, struct stat *st = NULL, fuse_timeouts_t *timeouts = NULL); + + int + symlink(const char *target, + const fs::path &linkpath, + struct stat *st = NULL, + fuse_timeouts_t *timeouts = NULL); + } diff --git a/src/fuse_truncate.cpp b/src/fuse_truncate.cpp index 3b33485c..dfecae7e 100644 --- a/src/fuse_truncate.cpp +++ b/src/fuse_truncate.cpp @@ -25,25 +25,21 @@ #include "fuse.h" -#include - #include #include -using std::string; - static void -_truncate_loop_core(const string &basepath_, - const char *fusepath_, - const off_t size_, - PolicyRV *prv_) +_truncate_loop_core(const fs::path &basepath_, + const fs::path &fusepath_, + const off_t size_, + PolicyRV *prv_) { int rv; - string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = basepath_ / fusepath_; rv = fs::truncate(fullpath,size_); @@ -53,7 +49,7 @@ _truncate_loop_core(const string &basepath_, static void _truncate_loop(const std::vector &branches_, - const char *fusepath_, + const fs::path &fusepath_, const off_t size_, PolicyRV *prv_) { @@ -68,7 +64,7 @@ int _truncate(const Policy::Action &actionFunc_, const Policy::Search &searchFunc_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const off_t size_) { int rv; @@ -97,12 +93,13 @@ int FUSE::truncate(const char *fusepath_, off_t size_) { + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); return ::_truncate(cfg.func.truncate.policy, cfg.func.getattr.policy, cfg.branches, - fusepath_, + fusepath, size_); } diff --git a/src/fuse_unlink.cpp b/src/fuse_unlink.cpp index 1f549693..62fecfb8 100644 --- a/src/fuse_unlink.cpp +++ b/src/fuse_unlink.cpp @@ -25,7 +25,6 @@ #include "fuse.h" -#include #include #include @@ -34,14 +33,14 @@ static int _unlink_loop(const std::vector &branches_, - const char *fusepath_) + const fs::path &fusepath_) { Err err; - std::string fullpath; + fs::path fullpath; for(const auto &branch : branches_) { - fullpath = fs::path::make(branch->path,fusepath_); + fullpath = branch->path / fusepath_; err = fs::unlink(fullpath); } @@ -53,7 +52,7 @@ static int _unlink(const Policy::Action &unlinkPolicy_, const Branches &branches_, - const char *fusepath_) + const fs::path &fusepath_) { int rv; std::vector branches; @@ -68,10 +67,11 @@ _unlink(const Policy::Action &unlinkPolicy_, int FUSE::unlink(const char *fusepath_) { + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); return ::_unlink(cfg.func.unlink.policy, cfg.branches, - fusepath_); + fusepath); } diff --git a/src/fuse_utimens.cpp b/src/fuse_utimens.cpp index 2a24b3d9..2703cdb3 100644 --- a/src/fuse_utimens.cpp +++ b/src/fuse_utimens.cpp @@ -25,24 +25,20 @@ #include "fuse.h" -#include - #include -using std::string; - static void -_utimens_loop_core(const string &basepath_, - const char *fusepath_, +_utimens_loop_core(const fs::path &basepath_, + const fs::path &fusepath_, const timespec ts_[2], PolicyRV *prv_) { int rv; - string fullpath; + fs::path fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = basepath_ / fusepath_; rv = fs::lutimens(fullpath,ts_); @@ -52,7 +48,7 @@ _utimens_loop_core(const string &basepath_, static void _utimens_loop(const std::vector &branches_, - const char *fusepath_, + const fs::path &fusepath_, const timespec ts_[2], PolicyRV *prv_) { @@ -67,7 +63,7 @@ int _utimens(const Policy::Action &utimensPolicy_, const Policy::Search &getattrPolicy_, const Branches &branches_, - const char *fusepath_, + const fs::path &fusepath_, const timespec ts_[2]) { int rv; @@ -96,12 +92,13 @@ int FUSE::utimens(const char *fusepath_, const timespec ts_[2]) { + const fs::path fusepath{fusepath_}; const fuse_context *fc = fuse_get_context(); const ugid::Set ugid(fc->uid,fc->gid); return ::_utimens(cfg.func.utimens.policy, cfg.func.getattr.policy, cfg.branches, - fusepath_, + fusepath, ts_); } diff --git a/src/fuse_write.cpp b/src/fuse_write.cpp index 2d827f6d..53252fbc 100644 --- a/src/fuse_write.cpp +++ b/src/fuse_write.cpp @@ -162,7 +162,7 @@ _write(const fuse_file_info_t *ffi_, { FileInfo *fi; - fi = reinterpret_cast(ffi_->fh); + fi = FileInfo::from_fh(ffi_->fh); // Concurrent writes can only happen if: // 1) writeback-cache is enabled and using page caching diff --git a/src/mergerfs.cpp b/src/mergerfs.cpp index b4a02852..5cd44136 100644 --- a/src/mergerfs.cpp +++ b/src/mergerfs.cpp @@ -87,10 +87,9 @@ #include #include +#include #include -#include - namespace l { @@ -192,7 +191,7 @@ namespace l wait_for_mount(const Config &cfg_) { int failures; - fs::PathVector paths; + std::vector paths; std::chrono::milliseconds timeout; paths = cfg_.branches->to_paths(); @@ -232,7 +231,7 @@ namespace l static void - lazy_umount(const fs::Path target_) + lazy_umount(const fs::path &target_) { int rv; diff --git a/src/option_parser.cpp b/src/option_parser.cpp index ea3df578..58b06858 100644 --- a/src/option_parser.cpp +++ b/src/option_parser.cpp @@ -21,6 +21,7 @@ #include "errno.hpp" #include "fmt/core.h" #include "fs_glob.hpp" +#include "fs_path.hpp" #include "fs_statvfs_cache.hpp" #include "hw_cpu.hpp" #include "num.hpp" @@ -33,7 +34,6 @@ #include "fuse_config.hpp" #include -#include #include #include #include @@ -47,9 +47,6 @@ #include #include -using std::string; -using std::vector; - enum { MERGERFS_OPT_HELP, @@ -97,7 +94,7 @@ _set_fsname(Config &cfg_, { if(cfg_.fsname->empty()) { - vector paths; + std::vector paths; cfg_.branches->to_paths(paths); @@ -225,7 +222,7 @@ _process_branches(Config &cfg_, const char *arg_) { int rv; - string arg; + std::string arg; arg = arg_; rv = cfg_.set_raw("branches",arg); @@ -242,7 +239,7 @@ _process_mount(Config &cfg_, const char *arg_) { int rv; - string arg; + std::string arg; arg = arg_; rv = cfg_.set_raw("mount",arg); @@ -347,8 +344,8 @@ void _check_for_mount_loop(Config &cfg_, Config::ErrVec *errs_) { - fs::Path mount; - fs::PathVector branches; + fs::path mount; + std::vector branches; std::error_code ec; mount = *cfg_.mountpoint; diff --git a/src/policy.hpp b/src/policy.hpp index 07b1bd28..7c7341ce 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -18,6 +18,7 @@ #include "branches.hpp" #include "strvec.hpp" +#include "fs_path.hpp" #include #include @@ -37,7 +38,7 @@ namespace Policy public: std::string name; virtual int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const = 0; }; @@ -63,21 +64,13 @@ namespace Policy } int - operator()(const Branches::Ptr &branches_, - const char *fusepath_, - std::vector &output_) const + operator()(const Branches::Ptr &branches_, + const std::filesystem::path &fusepath_, + std::vector &output_) const { return (*impl)(branches_,fusepath_,output_); } - int - operator()(const Branches::Ptr &branches_, - const std::string &fusepath_, - std::vector &output_) const - { - return (*impl)(branches_,fusepath_.c_str(),output_); - } - operator bool() const { return (bool)impl; @@ -99,7 +92,7 @@ namespace Policy std::string name; virtual bool path_preserving(void) const = 0; virtual int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const = 0; }; @@ -131,21 +124,13 @@ namespace Policy } int - operator()(const Branches::Ptr &branches_, - const char *fusepath_, - std::vector &output_) const + operator()(const Branches::Ptr &branches_, + const std::filesystem::path &fusepath_, + std::vector &output_) const { return (*impl)(branches_,fusepath_,output_); } - int - operator()(const Branches::Ptr &branches_, - const std::string &fusepath_, - std::vector &output_) const - { - return (*impl)(branches_,fusepath_.c_str(),output_); - } - operator bool() const { return (bool)impl; @@ -166,7 +151,7 @@ namespace Policy public: std::string name; virtual int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const = 0; }; @@ -193,20 +178,12 @@ namespace Policy int operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const std::filesystem::path &fusepath_, std::vector &output_) const { return (*impl)(branches_,fusepath_,output_); } - int - operator()(const Branches::Ptr &branches_, - const std::string &fusepath_, - std::vector &output_) const - { - return (*impl)(branches_,fusepath_.c_str(),output_); - } - operator bool() const { return (bool)impl; diff --git a/src/policy_all.cpp b/src/policy_all.cpp index 054e466d..f5700116 100644 --- a/src/policy_all.cpp +++ b/src/policy_all.cpp @@ -62,7 +62,7 @@ _create(const Branches::Ptr &ibranches_, int Policy::All::Action::operator()(const Branches::Ptr &ibranches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &obranches_) const { return Policies::Action::epall(ibranches_,fusepath_,obranches_); @@ -70,7 +70,7 @@ Policy::All::Action::operator()(const Branches::Ptr &ibranches_, int Policy::All::Create::operator()(const Branches::Ptr &ibranches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &obranches_) const { return ::_create(ibranches_,obranches_); @@ -78,7 +78,7 @@ Policy::All::Create::operator()(const Branches::Ptr &ibranches_, int Policy::All::Search::operator()(const Branches::Ptr &ibranches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &obranches_) const { return Policies::Search::epall(ibranches_,fusepath_,obranches_); diff --git a/src/policy_all.hpp b/src/policy_all.hpp index 9ea29e1e..46e696f3 100644 --- a/src/policy_all.hpp +++ b/src/policy_all.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_epall.cpp b/src/policy_epall.cpp index 7944eb5e..8547bc8e 100644 --- a/src/policy_epall.cpp +++ b/src/policy_epall.cpp @@ -34,7 +34,7 @@ using std::string; static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -68,7 +68,7 @@ _create(const Branches::Ptr &branches_, static int _action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -100,7 +100,7 @@ _action(const Branches::Ptr &branches_, static int _search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { for(auto &branch : *branches_) @@ -119,7 +119,7 @@ _search(const Branches::Ptr &branches_, int Policy::EPAll::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_action(branches_,fusepath_,paths_); @@ -127,7 +127,7 @@ Policy::EPAll::Action::operator()(const Branches::Ptr &branches_, int Policy::EPAll::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -135,7 +135,7 @@ Policy::EPAll::Create::operator()(const Branches::Ptr &branches_, int Policy::EPAll::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_search(branches_,fusepath_,paths_); diff --git a/src/policy_epall.hpp b/src/policy_epall.hpp index f91d81b7..9e5eda10 100644 --- a/src/policy_epall.hpp +++ b/src/policy_epall.hpp @@ -34,7 +34,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -48,7 +48,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -63,7 +63,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_epff.cpp b/src/policy_epff.cpp index 1728364f..f49ee8b4 100644 --- a/src/policy_epff.cpp +++ b/src/policy_epff.cpp @@ -36,7 +36,7 @@ using std::vector; static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -69,7 +69,7 @@ _create(const Branches::Ptr &branches_, static int _action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -100,7 +100,7 @@ _action(const Branches::Ptr &branches_, static int _search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { for(auto &branch : *branches_) @@ -118,7 +118,7 @@ _search(const Branches::Ptr &branches_, int Policy::EPFF::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_action(branches_,fusepath_,paths_); @@ -126,7 +126,7 @@ Policy::EPFF::Action::operator()(const Branches::Ptr &branches_, int Policy::EPFF::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -134,7 +134,7 @@ Policy::EPFF::Create::operator()(const Branches::Ptr &branches_, int Policy::EPFF::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_search(branches_,fusepath_,paths_); diff --git a/src/policy_epff.hpp b/src/policy_epff.hpp index d438cbf5..c86652a2 100644 --- a/src/policy_epff.hpp +++ b/src/policy_epff.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_eplfs.cpp b/src/policy_eplfs.cpp index 377b5bf0..4447acd0 100644 --- a/src/policy_eplfs.cpp +++ b/src/policy_eplfs.cpp @@ -36,7 +36,7 @@ using std::vector; static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -79,7 +79,7 @@ _create(const Branches::Ptr &branches_, static int _action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -120,7 +120,7 @@ _action(const Branches::Ptr &branches_, static int _search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -154,23 +154,23 @@ _search(const Branches::Ptr &branches_, int Policy::EPLFS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_action(branches_,fusepath_,paths_); } int -Policy::EPLFS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, +Policy::EPLFS::Create::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); } int -Policy::EPLFS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, +Policy::EPLFS::Search::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_search(branches_,fusepath_,paths_); diff --git a/src/policy_eplfs.hpp b/src/policy_eplfs.hpp index 6a1ceeb5..0ead02bf 100644 --- a/src/policy_eplfs.hpp +++ b/src/policy_eplfs.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_eplus.cpp b/src/policy_eplus.cpp index 037093e1..35897bea 100644 --- a/src/policy_eplus.cpp +++ b/src/policy_eplus.cpp @@ -34,7 +34,7 @@ using std::string; static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -77,7 +77,7 @@ _create(const Branches::Ptr &branches_, static int _action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -118,7 +118,7 @@ _action(const Branches::Ptr &branches_, static int _search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -151,24 +151,24 @@ _search(const Branches::Ptr &branches_, } int -Policy::EPLUS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, +Policy::EPLUS::Action::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_action(branches_,fusepath_,paths_); } int -Policy::EPLUS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, +Policy::EPLUS::Create::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); } int -Policy::EPLUS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, +Policy::EPLUS::Search::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_search(branches_,fusepath_,paths_); diff --git a/src/policy_eplus.hpp b/src/policy_eplus.hpp index adf5879b..410f60d3 100644 --- a/src/policy_eplus.hpp +++ b/src/policy_eplus.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_epmfs.cpp b/src/policy_epmfs.cpp index 22c1bc6d..90d13f5d 100644 --- a/src/policy_epmfs.cpp +++ b/src/policy_epmfs.cpp @@ -29,13 +29,10 @@ #include -using std::string; - - static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -78,7 +75,7 @@ _create(const Branches::Ptr &branches_, static int _action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -119,7 +116,7 @@ _action(const Branches::Ptr &branches_, static int _search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -153,7 +150,7 @@ _search(const Branches::Ptr &branches_, int Policy::EPMFS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_action(branches_,fusepath_,paths_); @@ -161,7 +158,7 @@ Policy::EPMFS::Action::operator()(const Branches::Ptr &branches_, int Policy::EPMFS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -169,7 +166,7 @@ Policy::EPMFS::Create::operator()(const Branches::Ptr &branches_, int Policy::EPMFS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_search(branches_,fusepath_,paths_); diff --git a/src/policy_epmfs.hpp b/src/policy_epmfs.hpp index ad472c40..8dc26908 100644 --- a/src/policy_epmfs.hpp +++ b/src/policy_epmfs.hpp @@ -34,7 +34,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -48,7 +48,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -63,7 +63,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_eppfrd.cpp b/src/policy_eppfrd.cpp index 63fae1d2..7b2145c4 100644 --- a/src/policy_eppfrd.cpp +++ b/src/policy_eppfrd.cpp @@ -42,7 +42,7 @@ typedef std::vector BranchInfoVec; static int _get_branchinfo_create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, BranchInfoVec *branchinfo_, uint64_t *sum_) { @@ -77,7 +77,7 @@ _get_branchinfo_create(const Branches::Ptr &branches_, static int _get_branchinfo_action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, BranchInfoVec *branchinfo_, uint64_t *sum_) { @@ -110,7 +110,7 @@ _get_branchinfo_action(const Branches::Ptr &branches_, static int _get_branchinfo_search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, BranchInfoVec *branchinfo_, uint64_t *sum_) { @@ -163,7 +163,7 @@ _get_branch(const BranchInfoVec &branchinfo_, static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int err; @@ -184,7 +184,7 @@ _create(const Branches::Ptr &branches_, static int _action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int err; @@ -205,7 +205,7 @@ _action(const Branches::Ptr &branches_, static int _search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int err; @@ -225,7 +225,7 @@ _search(const Branches::Ptr &branches_, int Policy::EPPFRD::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_action(branches_,fusepath_,paths_); @@ -233,7 +233,7 @@ Policy::EPPFRD::Action::operator()(const Branches::Ptr &branches_, int Policy::EPPFRD::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -241,7 +241,7 @@ Policy::EPPFRD::Create::operator()(const Branches::Ptr &branches_, int Policy::EPPFRD::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_search(branches_,fusepath_,paths_); diff --git a/src/policy_eppfrd.hpp b/src/policy_eppfrd.hpp index 972701ea..0f431792 100644 --- a/src/policy_eppfrd.hpp +++ b/src/policy_eppfrd.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_eprand.cpp b/src/policy_eprand.cpp index 7ea2f142..6996adef 100644 --- a/src/policy_eprand.cpp +++ b/src/policy_eprand.cpp @@ -25,8 +25,9 @@ int Policy::EPRand::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const + { int rv; @@ -39,7 +40,7 @@ Policy::EPRand::Action::operator()(const Branches::Ptr &branches_, int Policy::EPRand::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { int rv; @@ -53,7 +54,7 @@ Policy::EPRand::Create::operator()(const Branches::Ptr &branches_, int Policy::EPRand::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { int rv; diff --git a/src/policy_eprand.hpp b/src/policy_eprand.hpp index eed5cdc5..aeb87a0d 100644 --- a/src/policy_eprand.hpp +++ b/src/policy_eprand.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_erofs.cpp b/src/policy_erofs.cpp index 733d2bd1..6de22759 100644 --- a/src/policy_erofs.cpp +++ b/src/policy_erofs.cpp @@ -26,7 +26,7 @@ using std::string; int Policy::ERoFS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return -EROFS; @@ -34,7 +34,7 @@ Policy::ERoFS::Action::operator()(const Branches::Ptr &branches_, int Policy::ERoFS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return -EROFS; @@ -42,7 +42,7 @@ Policy::ERoFS::Create::operator()(const Branches::Ptr &branches_, int Policy::ERoFS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return -EROFS; diff --git a/src/policy_erofs.hpp b/src/policy_erofs.hpp index b8a4af3d..d4e8d798 100644 --- a/src/policy_erofs.hpp +++ b/src/policy_erofs.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving(void) const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index 6195c38d..c80d1840 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -60,7 +60,7 @@ _create(const Branches::Ptr &ibranches_, int Policy::FF::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::epff(branches_,fusepath_,paths_); @@ -68,7 +68,7 @@ Policy::FF::Action::operator()(const Branches::Ptr &branches_, int Policy::FF::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,paths_); @@ -76,7 +76,7 @@ Policy::FF::Create::operator()(const Branches::Ptr &branches_, int Policy::FF::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &output_) const { for(auto &branch : *branches_) diff --git a/src/policy_ff.hpp b/src/policy_ff.hpp index 61a32ef4..5ddc622c 100644 --- a/src/policy_ff.hpp +++ b/src/policy_ff.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -47,7 +47,7 @@ namespace Policy public: bool path_preserving(void) const final { return false; } int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -61,7 +61,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_lfs.cpp b/src/policy_lfs.cpp index 69a51456..95fbe4b6 100644 --- a/src/policy_lfs.cpp +++ b/src/policy_lfs.cpp @@ -72,7 +72,7 @@ _create(const Branches::Ptr &branches_, int Policy::LFS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::eplfs(branches_,fusepath_,paths_); @@ -80,7 +80,7 @@ Policy::LFS::Action::operator()(const Branches::Ptr &branches_, int Policy::LFS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,paths_); @@ -88,7 +88,7 @@ Policy::LFS::Create::operator()(const Branches::Ptr &branches_, int Policy::LFS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::eplfs(branches_,fusepath_,paths_); diff --git a/src/policy_lfs.hpp b/src/policy_lfs.hpp index b9aac6d6..37d35856 100644 --- a/src/policy_lfs.hpp +++ b/src/policy_lfs.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_lus.cpp b/src/policy_lus.cpp index 52410193..ebda481f 100644 --- a/src/policy_lus.cpp +++ b/src/policy_lus.cpp @@ -75,7 +75,7 @@ _create(const Branches::Ptr &branches_, int Policy::LUS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::eplus(branches_,fusepath_,paths_); @@ -83,7 +83,7 @@ Policy::LUS::Action::operator()(const Branches::Ptr &branches_, int Policy::LUS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,paths_); @@ -91,7 +91,7 @@ Policy::LUS::Create::operator()(const Branches::Ptr &branches_, int Policy::LUS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::eplus(branches_,fusepath_,paths_); diff --git a/src/policy_lus.hpp b/src/policy_lus.hpp index 9c17e999..23755790 100644 --- a/src/policy_lus.hpp +++ b/src/policy_lus.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const std::filesystem::path&, std::vector&) const final; }; } diff --git a/src/policy_mfs.cpp b/src/policy_mfs.cpp index 049f68d5..546401db 100644 --- a/src/policy_mfs.cpp +++ b/src/policy_mfs.cpp @@ -71,7 +71,7 @@ _create(const Branches::Ptr &branches_, int Policy::MFS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::epmfs(branches_,fusepath_,paths_); @@ -79,7 +79,7 @@ Policy::MFS::Action::operator()(const Branches::Ptr &branches_, int Policy::MFS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,paths_); @@ -87,7 +87,7 @@ Policy::MFS::Create::operator()(const Branches::Ptr &branches_, int Policy::MFS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::epmfs(branches_,fusepath_,paths_); diff --git a/src/policy_mfs.hpp b/src/policy_mfs.hpp index f3e4d833..abfb7d65 100644 --- a/src/policy_mfs.hpp +++ b/src/policy_mfs.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; } diff --git a/src/policy_msplfs.cpp b/src/policy_msplfs.cpp index 2918595e..a5619aa6 100644 --- a/src/policy_msplfs.cpp +++ b/src/policy_msplfs.cpp @@ -27,6 +27,7 @@ #include "policy_msplfs.hpp" #include "strvec.hpp" +#include #include #include @@ -34,7 +35,7 @@ static Branch* _create_1(const Branches::Ptr &branches_, - const std::string &fusepath_, + const fs::path &fusepath_, int *err_) { int rv; @@ -70,12 +71,12 @@ _create_1(const Branches::Ptr &branches_, static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int error; Branch *branch; - std::string fusepath; + fs::path fusepath; error = ENOENT; fusepath = fusepath_; @@ -86,7 +87,7 @@ _create(const Branches::Ptr &branches_, break; if(fusepath == "/") break; - fusepath = fs::path::dirname(fusepath); + fusepath = fusepath.parent_path(); } if(!branch) @@ -99,7 +100,7 @@ _create(const Branches::Ptr &branches_, int Policy::MSPLFS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::eplfs(branches_,fusepath_,paths_); @@ -107,7 +108,7 @@ Policy::MSPLFS::Action::operator()(const Branches::Ptr &branches_, int Policy::MSPLFS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -115,7 +116,7 @@ Policy::MSPLFS::Create::operator()(const Branches::Ptr &branches_, int Policy::MSPLFS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::eplfs(branches_,fusepath_,paths_); diff --git a/src/policy_msplfs.hpp b/src/policy_msplfs.hpp index bbdbee99..dbd11db5 100644 --- a/src/policy_msplfs.hpp +++ b/src/policy_msplfs.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; } diff --git a/src/policy_msplus.cpp b/src/policy_msplus.cpp index b5340004..528c8635 100644 --- a/src/policy_msplus.cpp +++ b/src/policy_msplus.cpp @@ -27,13 +27,12 @@ #include "policy_msplus.hpp" #include -#include static Branch* _create_1(const Branches::Ptr &branches_, - const std::string &fusepath_, + const fs::path &fusepath_, int *err_) { int rv; @@ -69,12 +68,12 @@ _create_1(const Branches::Ptr &branches_, static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int err; Branch *branch; - std::string fusepath; + fs::path fusepath; err = -ENOENT; fusepath = fusepath_; @@ -85,7 +84,7 @@ _create(const Branches::Ptr &branches_, break; if(fusepath == "/") break; - fusepath = fs::path::dirname(fusepath); + fusepath = fusepath.parent_path(); } if(!branch) @@ -98,7 +97,7 @@ _create(const Branches::Ptr &branches_, int Policy::MSPLUS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::eplus(branches_,fusepath_,paths_); @@ -106,7 +105,7 @@ Policy::MSPLUS::Action::operator()(const Branches::Ptr &branches_, int Policy::MSPLUS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -114,7 +113,7 @@ Policy::MSPLUS::Create::operator()(const Branches::Ptr &branches_, int Policy::MSPLUS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::eplus(branches_,fusepath_,paths_); diff --git a/src/policy_msplus.hpp b/src/policy_msplus.hpp index 74c72da5..1ddc188c 100644 --- a/src/policy_msplus.hpp +++ b/src/policy_msplus.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; } diff --git a/src/policy_mspmfs.cpp b/src/policy_mspmfs.cpp index 2f93b681..771d33ef 100644 --- a/src/policy_mspmfs.cpp +++ b/src/policy_mspmfs.cpp @@ -34,7 +34,7 @@ static Branch* _create_1(const Branches::Ptr &branches_, - const std::string &fusepath_, + const fs::path &fusepath_, int *err_) { int rv; @@ -70,12 +70,12 @@ _create_1(const Branches::Ptr &branches_, static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int error; - std::string fusepath; Branch *branch; + fs::path fusepath; error = ENOENT; fusepath = fusepath_; @@ -86,7 +86,8 @@ _create(const Branches::Ptr &branches_, break; if(fusepath == "/") break; - fusepath = fs::path::dirname(fusepath); + + fusepath = fusepath.parent_path(); } if(!branch) @@ -98,8 +99,8 @@ _create(const Branches::Ptr &branches_, } int -Policy::MSPMFS::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, +Policy::MSPMFS::Action::operator()(const Branches::Ptr &branches_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::epmfs(branches_,fusepath_,paths_); @@ -107,7 +108,7 @@ Policy::MSPMFS::Action::operator()(const Branches::Ptr &branches_, int Policy::MSPMFS::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -115,7 +116,7 @@ Policy::MSPMFS::Create::operator()(const Branches::Ptr &branches_, int Policy::MSPMFS::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::epmfs(branches_,fusepath_,paths_); diff --git a/src/policy_mspmfs.hpp b/src/policy_mspmfs.hpp index fcb73fd1..ad376617 100644 --- a/src/policy_mspmfs.hpp +++ b/src/policy_mspmfs.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return true; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; } diff --git a/src/policy_msppfrd.cpp b/src/policy_msppfrd.cpp index 55d41195..5fbdbe84 100644 --- a/src/policy_msppfrd.cpp +++ b/src/policy_msppfrd.cpp @@ -29,7 +29,6 @@ #include "policy_error.hpp" #include "rnd.hpp" -#include #include @@ -44,7 +43,7 @@ typedef std::vector BranchInfoVec; static int _create_1(const Branches::Ptr &branches_, - const std::string &fusepath_, + const fs::path &fusepath_, BranchInfoVec *branchinfo_, uint64_t *sum_) { @@ -79,12 +78,12 @@ _create_1(const Branches::Ptr &branches_, static int _get_branchinfo(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, BranchInfoVec *branchinfo_, uint64_t *sum_) { int rv; - std::string fusepath; + fs::path fusepath; fusepath = fusepath_; for(;;) @@ -94,7 +93,7 @@ _get_branchinfo(const Branches::Ptr &branches_, break; if(fusepath == "/") break; - fusepath = fs::path::dirname(fusepath); + fusepath = fusepath.parent_path(); } return rv; @@ -129,7 +128,7 @@ _get_branch(const BranchInfoVec &branchinfo_, static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -149,7 +148,7 @@ _create(const Branches::Ptr &branches_, int Policy::MSPPFRD::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::eppfrd(branches_,fusepath_,paths_); @@ -157,7 +156,7 @@ Policy::MSPPFRD::Action::operator()(const Branches::Ptr &branches_, int Policy::MSPPFRD::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -165,7 +164,7 @@ Policy::MSPPFRD::Create::operator()(const Branches::Ptr &branches_, int Policy::MSPPFRD::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::eppfrd(branches_,fusepath_,paths_); diff --git a/src/policy_msppfrd.hpp b/src/policy_msppfrd.hpp index f9eb6b6e..101f1831 100644 --- a/src/policy_msppfrd.hpp +++ b/src/policy_msppfrd.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return true; }; }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; } diff --git a/src/policy_newest.cpp b/src/policy_newest.cpp index 8dc0b99f..d26c0b2c 100644 --- a/src/policy_newest.cpp +++ b/src/policy_newest.cpp @@ -36,7 +36,7 @@ using std::string; static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -80,7 +80,7 @@ _create(const Branches::Ptr &branches_, static int _action(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int rv; @@ -122,7 +122,7 @@ _action(const Branches::Ptr &branches_, static int _search(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { time_t newest; @@ -152,7 +152,7 @@ _search(const Branches::Ptr &branches_, int Policy::Newest::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_action(branches_,fusepath_,paths_); @@ -160,7 +160,7 @@ Policy::Newest::Action::operator()(const Branches::Ptr &branches_, int Policy::Newest::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -168,7 +168,7 @@ Policy::Newest::Create::operator()(const Branches::Ptr &branches_, int Policy::Newest::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_search(branches_,fusepath_,paths_); diff --git a/src/policy_newest.hpp b/src/policy_newest.hpp index 8a5fec33..16c2c1a8 100644 --- a/src/policy_newest.hpp +++ b/src/policy_newest.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; } diff --git a/src/policy_pfrd.cpp b/src/policy_pfrd.cpp index 49530056..dedd8c3e 100644 --- a/src/policy_pfrd.cpp +++ b/src/policy_pfrd.cpp @@ -99,7 +99,7 @@ _get_branch(const BranchInfoVec &branchinfo_, static int _create(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) { int err; @@ -119,7 +119,7 @@ _create(const Branches::Ptr &branches_, int Policy::PFRD::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Action::eppfrd(branches_,fusepath_,paths_); @@ -127,7 +127,7 @@ Policy::PFRD::Action::operator()(const Branches::Ptr &branches_, int Policy::PFRD::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return ::_create(branches_,fusepath_,paths_); @@ -135,7 +135,7 @@ Policy::PFRD::Create::operator()(const Branches::Ptr &branches_, int Policy::PFRD::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { return Policies::Search::eppfrd(branches_,fusepath_,paths_); diff --git a/src/policy_pfrd.hpp b/src/policy_pfrd.hpp index e100ca12..94ac11a0 100644 --- a/src/policy_pfrd.hpp +++ b/src/policy_pfrd.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; } diff --git a/src/policy_rand.cpp b/src/policy_rand.cpp index 94cc3d6a..52fca26a 100644 --- a/src/policy_rand.cpp +++ b/src/policy_rand.cpp @@ -24,7 +24,7 @@ int Policy::Rand::Action::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { int rv; @@ -38,7 +38,7 @@ Policy::Rand::Action::operator()(const Branches::Ptr &branches_, int Policy::Rand::Create::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { int rv; @@ -52,7 +52,7 @@ Policy::Rand::Create::operator()(const Branches::Ptr &branches_, int Policy::Rand::Search::operator()(const Branches::Ptr &branches_, - const char *fusepath_, + const fs::path &fusepath_, std::vector &paths_) const { int rv; diff --git a/src/policy_rand.hpp b/src/policy_rand.hpp index ae319298..608afd50 100644 --- a/src/policy_rand.hpp +++ b/src/policy_rand.hpp @@ -33,7 +33,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; @@ -46,7 +46,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -60,7 +60,7 @@ namespace Policy public: int operator()(const Branches::Ptr&, - const char*, + const fs::path&, std::vector&) const final; }; }