From 1dc7bff6e609475ff47a3caf37bf075fa4ecb302 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Wed, 19 Oct 2016 09:28:06 -0400 Subject: [PATCH] wrap most posix filesystem functions --- LICENSE | 2 +- src/access.cpp | 6 +-- src/chmod.cpp | 3 +- src/chown.cpp | 3 +- src/create.cpp | 7 +--- src/fallocate.cpp | 1 - src/fgetattr.cpp | 7 +--- src/fgetattr.hpp | 2 +- src/flush.cpp | 8 ++-- src/fs.cpp | 44 ++++++++-------------- src/fs.hpp | 3 -- src/fs_attr_linux.icpp | 23 ++++++------ src/fs_base_access.hpp | 46 +++++++++++++++++++++++ src/fs_base_chmod.hpp | 49 ++++++++++++++++++++++++ src/fs_base_chown.hpp | 74 +++++++++++++++++++++++++++++++++++++ src/fs_base_close.hpp | 30 +++++++++++++++ src/fs_base_closedir.hpp | 31 ++++++++++++++++ src/fs_base_dup.hpp | 30 +++++++++++++++ src/fs_base_fsync.hpp | 38 +++++++++++++++++++ src/fs_base_ftruncate.hpp | 32 ++++++++++++++++ src/fs_base_getxattr.hpp | 40 ++++++++++++++++++++ src/fs_base_ioctl.hpp | 32 ++++++++++++++++ src/fs_base_link.hpp | 33 +++++++++++++++++ src/fs_base_listxattr.hpp | 39 +++++++++++++++++++ src/fs_base_mkdir.hpp | 34 +++++++++++++++++ src/fs_base_mknod.hpp | 35 ++++++++++++++++++ src/fs_base_open.hpp | 45 ++++++++++++++++++++++ src/fs_base_opendir.hpp | 33 +++++++++++++++++ src/fs_base_read.hpp | 33 +++++++++++++++++ src/fs_base_readdir.hpp | 30 +++++++++++++++ src/fs_base_readlink.hpp | 34 +++++++++++++++++ src/fs_base_removexattr.hpp | 38 +++++++++++++++++++ src/fs_base_rename.hpp | 31 ++++++++++++++++ src/fs_base_rmdir.hpp | 32 ++++++++++++++++ src/fs_base_setxattr.hpp | 41 ++++++++++++++++++++ src/fs_base_stat.hpp | 62 +++++++++++++++++++++++++++++++ src/fs_base_statvfs.hpp | 42 +++++++++++++++++++++ src/fs_base_truncate.hpp | 34 +++++++++++++++++ src/fs_base_unlink.hpp | 32 ++++++++++++++++ src/fs_base_utimensat.hpp | 50 +++++++++++++++++++++++++ src/fs_base_write.hpp | 33 +++++++++++++++++ src/fs_clonefile.cpp | 21 +++++++---- src/fs_clonepath.cpp | 24 ++++++------ src/fs_movefile.cpp | 28 ++++++++------ src/fs_xattr.cpp | 6 ++- src/fsync.cpp | 7 ++-- src/ftruncate.cpp | 6 +-- src/getattr.cpp | 7 +--- src/getxattr.cpp | 10 +---- src/ioctl.cpp | 12 +++--- src/link.cpp | 9 ++--- src/listxattr.cpp | 10 +---- src/mkdir.cpp | 6 +-- src/mknod.cpp | 8 +--- src/open.cpp | 5 +-- src/read.cpp | 4 +- src/readdir.cpp | 11 +++--- src/readlink.cpp | 8 +--- src/release.cpp | 5 +-- src/removexattr.cpp | 12 +----- src/rename.cpp | 10 ++--- src/rmdir.cpp | 3 +- src/setxattr.cpp | 13 +------ src/statfs.cpp | 8 ++-- src/statvfs_util.hpp | 19 +--------- src/truncate.cpp | 3 +- src/unlink.cpp | 3 +- src/utimens.cpp | 4 +- src/write.cpp | 5 +-- 69 files changed, 1262 insertions(+), 227 deletions(-) create mode 100644 src/fs_base_access.hpp create mode 100644 src/fs_base_chmod.hpp create mode 100644 src/fs_base_chown.hpp create mode 100644 src/fs_base_close.hpp create mode 100644 src/fs_base_closedir.hpp create mode 100644 src/fs_base_dup.hpp create mode 100644 src/fs_base_fsync.hpp create mode 100644 src/fs_base_ftruncate.hpp create mode 100644 src/fs_base_getxattr.hpp create mode 100644 src/fs_base_ioctl.hpp create mode 100644 src/fs_base_link.hpp create mode 100644 src/fs_base_listxattr.hpp create mode 100644 src/fs_base_mkdir.hpp create mode 100644 src/fs_base_mknod.hpp create mode 100644 src/fs_base_open.hpp create mode 100644 src/fs_base_opendir.hpp create mode 100644 src/fs_base_read.hpp create mode 100644 src/fs_base_readdir.hpp create mode 100644 src/fs_base_readlink.hpp create mode 100644 src/fs_base_removexattr.hpp create mode 100644 src/fs_base_rename.hpp create mode 100644 src/fs_base_rmdir.hpp create mode 100644 src/fs_base_setxattr.hpp create mode 100644 src/fs_base_stat.hpp create mode 100644 src/fs_base_statvfs.hpp create mode 100644 src/fs_base_truncate.hpp create mode 100644 src/fs_base_unlink.hpp create mode 100644 src/fs_base_utimensat.hpp create mode 100644 src/fs_base_write.hpp diff --git a/LICENSE b/LICENSE index dbfb41c6..6ed51439 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ /* ISC License - + Copyright (c) 2016, Antonio SJ Musumeci Permission to use, copy, modify, and/or distribute this software for any diff --git a/src/access.cpp b/src/access.cpp index 64381b09..a613e34d 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -17,11 +17,9 @@ #include #include -#include -#include - #include "config.hpp" #include "errno.hpp" +#include "fs_base_access.hpp" #include "fs_path.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -49,7 +47,7 @@ _access(Policy::Func::Search searchFunc, fs::path::make(basepaths[0],fusepath,fullpath); - rv = ::faccessat(AT_FDCWD,fullpath.c_str(),mask,AT_EACCESS); + rv = fs::access(fullpath,mask,AT_EACCESS); return ((rv == -1) ? -errno : 0); } diff --git a/src/chmod.cpp b/src/chmod.cpp index 6b13c331..123f3b60 100644 --- a/src/chmod.cpp +++ b/src/chmod.cpp @@ -21,6 +21,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_chmod.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "rwlock.hpp" @@ -42,7 +43,7 @@ _chmod_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::chmod(fullpath.c_str(),mode); + rv = fs::chmod(fullpath,mode); return calc_error(rv,error,errno); } diff --git a/src/chown.cpp b/src/chown.cpp index 0262af0f..b0f210e3 100644 --- a/src/chown.cpp +++ b/src/chown.cpp @@ -21,6 +21,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_chown.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "rwlock.hpp" @@ -44,7 +45,7 @@ _chown_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::lchown(fullpath.c_str(),uid,gid); + rv = fs::lchown(fullpath,uid,gid); return calc_error(rv,error,errno); } diff --git a/src/create.cpp b/src/create.cpp index 1803c167..b96a087a 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -16,16 +16,13 @@ #include -#include -#include -#include - #include #include #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_open.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rwlock.hpp" @@ -57,7 +54,7 @@ _create_core(const string &existingpath, fs::path::make(&createpath,fusepath,fullpath); - fd = ::open(fullpath.c_str(),flags,mode); + fd = fs::open(fullpath,flags,mode); if(fd == -1) return -errno; diff --git a/src/fallocate.cpp b/src/fallocate.cpp index 5c1ea105..ed1012e0 100644 --- a/src/fallocate.cpp +++ b/src/fallocate.cpp @@ -49,7 +49,6 @@ namespace mergerfs { FileInfo *fi = reinterpret_cast(ffi->fh); - return _fallocate(fi->fd, mode, offset, diff --git a/src/fgetattr.cpp b/src/fgetattr.cpp index 1f370712..cc4da5c2 100644 --- a/src/fgetattr.cpp +++ b/src/fgetattr.cpp @@ -16,12 +16,9 @@ #include -#include -#include -#include - #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_stat.hpp" static int @@ -30,7 +27,7 @@ _fgetattr(const int fd, { int rv; - rv = ::fstat(fd,&st); + rv = fs::fstat(fd,st); return ((rv == -1) ? -errno : 0); } diff --git a/src/fgetattr.hpp b/src/fgetattr.hpp index 586182ce..b626dfcf 100644 --- a/src/fgetattr.hpp +++ b/src/fgetattr.hpp @@ -14,8 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include +#include #include namespace mergerfs diff --git a/src/flush.cpp b/src/flush.cpp index 2491e2e9..d04b7933 100644 --- a/src/flush.cpp +++ b/src/flush.cpp @@ -16,10 +16,10 @@ #include -#include - #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_close.hpp" +#include "fs_base_dup.hpp" static int @@ -27,11 +27,11 @@ _flush(const int fd) { int rv; - rv = ::dup(fd); + rv = fs::dup(fd); if(rv == -1) errno = EIO; else - rv = ::close(rv); + rv = fs::close(rv); return ((rv == -1) ? -errno : 0); } diff --git a/src/fs.cpp b/src/fs.cpp index 924e917e..1a6eb132 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -17,19 +17,16 @@ #include #include -#include #include #include #include #include #include -#include -#include -#include -#include #include "errno.hpp" #include "fs_attr.hpp" +#include "fs_base_stat.hpp" +#include "fs_base_statvfs.hpp" #include "fs_path.hpp" #include "fs_xattr.hpp" #include "statvfs_util.hpp" @@ -47,7 +44,7 @@ namespace fs { int rv; - rv = ::lstat(path.c_str(),&st); + rv = fs::lstat(path,st); return LSTAT_SUCCEEDED(rv); } @@ -60,74 +57,63 @@ namespace fs return exists(path,st); } - bool - statvfs(const string &path, - struct statvfs &st) - { - int rv; - - rv = ::statvfs(path.c_str(),&st); - - return STATVFS_SUCCEEDED(rv); - } - bool info(const string &path, bool &readonly, uint64_t &spaceavail, uint64_t &spaceused) { - bool rv; + int rv; struct statvfs st; rv = fs::statvfs(path,st); - if(rv) + if(STATVFS_SUCCEEDED(rv)) { readonly = StatVFS::readonly(st); spaceavail = StatVFS::spaceavail(st); spaceused = StatVFS::spaceused(st); } - return rv; + return STATVFS_SUCCEEDED(rv); } bool readonly(const string &path) { - bool rv; + int rv; struct statvfs st; rv = fs::statvfs(path,st); - return (rv && StatVFS::readonly(st)); + return (STATVFS_SUCCEEDED(rv) && StatVFS::readonly(st)); } bool spaceavail(const string &path, uint64_t &spaceavail) { - bool rv; + int rv; struct statvfs st; rv = fs::statvfs(path,st); - if(rv) + if(STATVFS_SUCCEEDED(rv)) spaceavail = StatVFS::spaceavail(st); - return rv; + return STATVFS_SUCCEEDED(rv); } bool spaceused(const string &path, uint64_t &spaceused) { - bool rv; + int rv; struct statvfs st; rv = fs::statvfs(path,st); - if(rv) + if(STATVFS_SUCCEEDED(rv)) spaceused = StatVFS::spaceused(st); - return rv; + return STATVFS_SUCCEEDED(rv); } void @@ -159,7 +145,7 @@ namespace fs string fullpath; struct stat st; - rv = ::fstat(fd,&st); + rv = fs::fstat(fd,st); if(FSTAT_FAILED(rv)) return -1; diff --git a/src/fs.hpp b/src/fs.hpp index f5981d47..cb65c6c0 100644 --- a/src/fs.hpp +++ b/src/fs.hpp @@ -31,9 +31,6 @@ namespace fs struct stat &st); bool exists(const string &path); - bool statvfs(const string &path, - struct statvfs &st); - bool info(const string &path, bool &readonly, uint64_t &spaceavail, diff --git a/src/fs_attr_linux.icpp b/src/fs_attr_linux.icpp index d23c4dcb..66722fb3 100644 --- a/src/fs_attr_linux.icpp +++ b/src/fs_attr_linux.icpp @@ -16,14 +16,13 @@ #include #include -#include -#include -#include -#include #include #include "errno.hpp" +#include "fs_base_close.hpp" +#include "fs_base_open.hpp" +#include "fs_base_ioctl.hpp" using std::string; @@ -36,7 +35,7 @@ namespace fs get_fs_ioc_flags(const int fd, int &flags) { - return ::ioctl(fd,FS_IOC_GETFLAGS,&flags); + return fs::ioctl(fd,FS_IOC_GETFLAGS,(void*)&flags); } static @@ -48,7 +47,7 @@ namespace fs int rv; const int openflags = O_RDONLY|O_NONBLOCK; - fd = ::open(file.c_str(),openflags); + fd = fs::open(file,openflags); if(fd == -1) return -1; @@ -56,12 +55,12 @@ namespace fs if(rv == -1) { int error = errno; - ::close(fd); + fs::close(fd); errno = error; return -1; } - return ::close(fd); + return fs::close(fd); } static @@ -69,7 +68,7 @@ namespace fs set_fs_ioc_flags(const int fd, const int flags) { - return ::ioctl(fd,FS_IOC_SETFLAGS,&flags); + return fs::ioctl(fd,FS_IOC_SETFLAGS,(void*)&flags); } static @@ -81,7 +80,7 @@ namespace fs int rv; const int openflags = O_RDONLY|O_NONBLOCK; - fd = ::open(file.c_str(),openflags); + fd = fs::open(file,openflags); if(fd == -1) return -1; @@ -89,12 +88,12 @@ namespace fs if(rv == -1) { int error = errno; - ::close(fd); + fs::close(fd); errno = error; return -1; } - return ::close(fd); + return fs::close(fd); } int diff --git a/src/fs_base_access.hpp b/src/fs_base_access.hpp new file mode 100644 index 00000000..517eafc5 --- /dev/null +++ b/src/fs_base_access.hpp @@ -0,0 +1,46 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include + +namespace fs +{ + static + inline + int + access(const int dirfd, + const std::string &pathname, + const int mode, + const int flags) + { + return ::faccessat(dirfd,pathname.c_str(),mode,flags); + } + + static + inline + int + access(const std::string &pathname, + const int mode, + const int flags) + { + return fs::access(AT_FDCWD,pathname,mode,flags); + } +} diff --git a/src/fs_base_chmod.hpp b/src/fs_base_chmod.hpp new file mode 100644 index 00000000..6ac47887 --- /dev/null +++ b/src/fs_base_chmod.hpp @@ -0,0 +1,49 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + int + chmod(const std::string &path, + const mode_t mode) + { + return ::chmod(path.c_str(),mode); + } + + static + inline + int + fchmod(const int fd, + const mode_t mode) + { + return ::fchmod(fd,mode); + } + + static + inline + int + fchmod(const int fd, + const struct stat &st) + { + return ::fchmod(fd,st.st_mode); + } +} diff --git a/src/fs_base_chown.hpp b/src/fs_base_chown.hpp new file mode 100644 index 00000000..783226a5 --- /dev/null +++ b/src/fs_base_chown.hpp @@ -0,0 +1,74 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include +#include + +namespace fs +{ + static + inline + int + chown(const std::string &path, + const uid_t uid, + const gid_t gid) + { + return ::chown(path.c_str(),uid,gid); + } + + static + inline + int + chown(const std::string &path, + const struct stat &st) + { + return fs::chown(path,st.st_uid,st.st_gid); + } + + static + inline + int + lchown(const std::string &path, + const uid_t uid, + const gid_t gid) + { + return ::lchown(path.c_str(),uid,gid); + } + + static + inline + int + fchown(const int fd, + const uid_t uid, + const gid_t gid) + { + return ::fchown(fd,uid,gid); + } + + static + inline + int + fchown(const int fd, + const struct stat &st) + { + return fs::fchown(fd,st.st_uid,st.st_gid); + } +} diff --git a/src/fs_base_close.hpp b/src/fs_base_close.hpp new file mode 100644 index 00000000..bb73080b --- /dev/null +++ b/src/fs_base_close.hpp @@ -0,0 +1,30 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + int + close(const int fd) + { + return ::close(fd); + } +} diff --git a/src/fs_base_closedir.hpp b/src/fs_base_closedir.hpp new file mode 100644 index 00000000..9845cc0e --- /dev/null +++ b/src/fs_base_closedir.hpp @@ -0,0 +1,31 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include + +namespace fs +{ + static + inline + int + closedir(DIR *dirp) + { + return ::closedir(dirp); + } +} diff --git a/src/fs_base_dup.hpp b/src/fs_base_dup.hpp new file mode 100644 index 00000000..f504a49e --- /dev/null +++ b/src/fs_base_dup.hpp @@ -0,0 +1,30 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + int + dup(const int fd) + { + return ::dup(fd); + } +} diff --git a/src/fs_base_fsync.hpp b/src/fs_base_fsync.hpp new file mode 100644 index 00000000..53dfcd40 --- /dev/null +++ b/src/fs_base_fsync.hpp @@ -0,0 +1,38 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + int + fsync(const int fd) + { + return ::fsync(fd); + } + + static + inline + int + fdatasync(const int fd) + { + return ::fdatasync(fd); + } +} diff --git a/src/fs_base_ftruncate.hpp b/src/fs_base_ftruncate.hpp new file mode 100644 index 00000000..a084ebe1 --- /dev/null +++ b/src/fs_base_ftruncate.hpp @@ -0,0 +1,32 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include + +namespace fs +{ + static + inline + int + ftruncate(const int fd, + const off_t size) + { + return ::ftruncate(fd,size); + } +} diff --git a/src/fs_base_getxattr.hpp b/src/fs_base_getxattr.hpp new file mode 100644 index 00000000..efcb0d5c --- /dev/null +++ b/src/fs_base_getxattr.hpp @@ -0,0 +1,40 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include "errno.hpp" +#include "xattr.hpp" + +namespace fs +{ + static + inline + int + lgetxattr(const std::string &path, + const char *attrname, + void *value, + const size_t size) + { +#ifndef WITHOUT_XATTR + return ::lgetxattr(path.c_str(),attrname,value,size); +#else + return (errno=ENOTSUP,-1); +#endif + } +} diff --git a/src/fs_base_ioctl.hpp b/src/fs_base_ioctl.hpp new file mode 100644 index 00000000..4de7ec38 --- /dev/null +++ b/src/fs_base_ioctl.hpp @@ -0,0 +1,32 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + int + ioctl(const int fd, + const int request, + void *data) + { + return ::ioctl(fd,request,data); + } +} diff --git a/src/fs_base_link.hpp b/src/fs_base_link.hpp new file mode 100644 index 00000000..5899cc58 --- /dev/null +++ b/src/fs_base_link.hpp @@ -0,0 +1,33 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +namespace fs +{ + static + inline + int + link(const std::string &oldpath, + const std::string &newpath) + { + return ::link(oldpath.c_str(),newpath.c_str()); + } +} diff --git a/src/fs_base_listxattr.hpp b/src/fs_base_listxattr.hpp new file mode 100644 index 00000000..88751892 --- /dev/null +++ b/src/fs_base_listxattr.hpp @@ -0,0 +1,39 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include "errno.hpp" +#include "xattr.hpp" + +namespace fs +{ + static + inline + int + llistxattr(const std::string &path, + char *list, + const size_t size) + { +#ifndef WITHOUT_XATTR + return ::llistxattr(path.c_str(),list,size); +#else + return (errno=ENOTSUP,-1); +#endif + } +} diff --git a/src/fs_base_mkdir.hpp b/src/fs_base_mkdir.hpp new file mode 100644 index 00000000..34ca9ae9 --- /dev/null +++ b/src/fs_base_mkdir.hpp @@ -0,0 +1,34 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include + +namespace fs +{ + static + inline + int + mkdir(const std::string &path, + const mode_t mode) + { + return ::mkdir(path.c_str(),mode); + } +} diff --git a/src/fs_base_mknod.hpp b/src/fs_base_mknod.hpp new file mode 100644 index 00000000..0a6fb5d0 --- /dev/null +++ b/src/fs_base_mknod.hpp @@ -0,0 +1,35 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include +#include +#include + +namespace fs +{ + static + inline + int + mknod(const std::string &path, + const mode_t mode, + const dev_t dev) + { + return ::mknod(path.c_str(),mode,dev); + } +} diff --git a/src/fs_base_open.hpp b/src/fs_base_open.hpp new file mode 100644 index 00000000..b32c5fdc --- /dev/null +++ b/src/fs_base_open.hpp @@ -0,0 +1,45 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include +#include + +namespace fs +{ + static + inline + int + open(const std::string &path, + const int flags) + { + return ::open(path.c_str(),flags); + } + + static + inline + int + open(const std::string &path, + const int flags, + const mode_t mode) + { + return ::open(path.c_str(),flags,mode); + } +} diff --git a/src/fs_base_opendir.hpp b/src/fs_base_opendir.hpp new file mode 100644 index 00000000..3124fe81 --- /dev/null +++ b/src/fs_base_opendir.hpp @@ -0,0 +1,33 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include + +namespace fs +{ + static + inline + DIR * + opendir(const std::string &name) + { + return ::opendir(name.c_str()); + } +} diff --git a/src/fs_base_read.hpp b/src/fs_base_read.hpp new file mode 100644 index 00000000..1955a267 --- /dev/null +++ b/src/fs_base_read.hpp @@ -0,0 +1,33 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + ssize_t + pread(const int fd, + void *buf, + const size_t count, + const off_t offset) + { + return ::pread(fd,buf,count,offset); + } +} diff --git a/src/fs_base_readdir.hpp b/src/fs_base_readdir.hpp new file mode 100644 index 00000000..c0163af4 --- /dev/null +++ b/src/fs_base_readdir.hpp @@ -0,0 +1,30 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + struct dirent * + readdir(DIR *dirp) + { + return ::readdir(dirp); + } +} diff --git a/src/fs_base_readlink.hpp b/src/fs_base_readlink.hpp new file mode 100644 index 00000000..f2291cca --- /dev/null +++ b/src/fs_base_readlink.hpp @@ -0,0 +1,34 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +namespace fs +{ + static + inline + int + readlink(const std::string &path, + char *buf, + const size_t bufsiz) + { + return ::readlink(path.c_str(),buf,bufsiz); + } +} diff --git a/src/fs_base_removexattr.hpp b/src/fs_base_removexattr.hpp new file mode 100644 index 00000000..b5105cf9 --- /dev/null +++ b/src/fs_base_removexattr.hpp @@ -0,0 +1,38 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include "errno.hpp" +#include "xattr.hpp" + +namespace fs +{ + static + inline + int + lremovexattr(const std::string &path, + const char *attrname) + { +#ifndef WITHOUT_XATTR + return ::lremovexattr(path.c_str(),attrname); +#else + return (errno=ENOTSUP,-1); +#endif + } +} diff --git a/src/fs_base_rename.hpp b/src/fs_base_rename.hpp new file mode 100644 index 00000000..5e968242 --- /dev/null +++ b/src/fs_base_rename.hpp @@ -0,0 +1,31 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + int + rename(const std::string &oldpath, + const std::string &newpath) + { + return ::rename(oldpath.c_str(),newpath.c_str()); + } +} diff --git a/src/fs_base_rmdir.hpp b/src/fs_base_rmdir.hpp new file mode 100644 index 00000000..918750ff --- /dev/null +++ b/src/fs_base_rmdir.hpp @@ -0,0 +1,32 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +namespace fs +{ + static + inline + int + rmdir(const std::string &path) + { + return ::rmdir(path.c_str()); + } +} diff --git a/src/fs_base_setxattr.hpp b/src/fs_base_setxattr.hpp new file mode 100644 index 00000000..52d872ba --- /dev/null +++ b/src/fs_base_setxattr.hpp @@ -0,0 +1,41 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include "errno.hpp" +#include "xattr.hpp" + +namespace fs +{ + static + inline + int + lsetxattr(const std::string &path, + const char *name, + const void *value, + const size_t size, + const int flags) + { +#ifndef WITHOUT_XATTR + return ::lsetxattr(path.c_str(),name,value,size,flags); +#else + return (errno=ENOTSUP,-1); +#endif + } +} diff --git a/src/fs_base_stat.hpp b/src/fs_base_stat.hpp new file mode 100644 index 00000000..d1e7a517 --- /dev/null +++ b/src/fs_base_stat.hpp @@ -0,0 +1,62 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include +#include + +namespace fs +{ + static + inline + int + stat(const char *path, + struct stat &st) + { + return ::stat(path,&st); + } + + static + inline + int + stat(const std::string &path, + struct stat &st) + { + return fs::stat(path.c_str(),st); + } + + static + inline + int + lstat(const std::string &path, + struct stat &st) + { + return ::lstat(path.c_str(),&st); + } + + static + inline + int + fstat(const int fd, + struct stat &st) + { + return ::fstat(fd,&st); + } +} diff --git a/src/fs_base_statvfs.hpp b/src/fs_base_statvfs.hpp new file mode 100644 index 00000000..2b3e6d4c --- /dev/null +++ b/src/fs_base_statvfs.hpp @@ -0,0 +1,42 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +namespace fs +{ + static + inline + int + statvfs(const char *path, + struct statvfs &st) + { + return ::statvfs(path,&st); + } + + static + inline + int + statvfs(const std::string &path, + struct statvfs &st) + { + return fs::statvfs(path.c_str(),st); + } +} diff --git a/src/fs_base_truncate.hpp b/src/fs_base_truncate.hpp new file mode 100644 index 00000000..350ce7fe --- /dev/null +++ b/src/fs_base_truncate.hpp @@ -0,0 +1,34 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include + +namespace fs +{ + static + inline + int + truncate(const std::string &path, + const off_t length) + { + return ::truncate(path.c_str(),length); + } +} diff --git a/src/fs_base_unlink.hpp b/src/fs_base_unlink.hpp new file mode 100644 index 00000000..6e6627e4 --- /dev/null +++ b/src/fs_base_unlink.hpp @@ -0,0 +1,32 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include + +namespace fs +{ + static + inline + int + unlink(const std::string &path) + { + return ::unlink(path.c_str()); + } +} diff --git a/src/fs_base_utimensat.hpp b/src/fs_base_utimensat.hpp new file mode 100644 index 00000000..fe49e3ee --- /dev/null +++ b/src/fs_base_utimensat.hpp @@ -0,0 +1,50 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include + +namespace fs +{ + static + inline + int + utimensat(const int dirfd, + const std::string &path, + const struct timespec times[2], + const int flags) + { + return ::utimensat(dirfd,path.c_str(),times,flags); + } + + static + inline + int + utimensat(const std::string &path, + const struct stat &st) + { + struct timespec times[2]; + + times[0] = st.st_atim; + times[1] = st.st_mtim; + + return fs::utimensat(AT_FDCWD,path,times,0); + } +} diff --git a/src/fs_base_write.hpp b/src/fs_base_write.hpp new file mode 100644 index 00000000..69ccc103 --- /dev/null +++ b/src/fs_base_write.hpp @@ -0,0 +1,33 @@ +/* + ISC License + + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +namespace fs +{ + static + inline + ssize_t + pwrite(const int fd, + const void *buf, + const size_t count, + const off_t offset) + { + return ::pwrite(fd,buf,count,offset); + } +} diff --git a/src/fs_clonefile.cpp b/src/fs_clonefile.cpp index 069e49cf..d1644657 100644 --- a/src/fs_clonefile.cpp +++ b/src/fs_clonefile.cpp @@ -25,6 +25,11 @@ #include "errno.hpp" #include "fs_attr.hpp" +#include "fs_base_chown.hpp" +#include "fs_base_chmod.hpp" +#include "fs_base_close.hpp" +#include "fs_base_mkdir.hpp" +#include "fs_base_open.hpp" #include "fs_fadvise.hpp" #include "fs_fallocate.hpp" #include "fs_sendfile.hpp" @@ -162,11 +167,11 @@ namespace fs if(rv == -1 && !ignorable_error(errno)) return -1; - rv = ::fchown(fdout,stin.st_uid,stin.st_gid); + rv = fs::fchown(fdout,stin); if(rv == -1) return -1; - rv = ::fchmod(fdout,stin.st_mode); + rv = fs::fchmod(fdout,stin); if(rv == -1) return -1; @@ -186,21 +191,21 @@ namespace fs int fdout; int error; - fdin = ::open(in.c_str(),O_RDONLY|O_NOFOLLOW); + fdin = fs::open(in,O_RDONLY|O_NOFOLLOW); if(fdin == -1) return -1; - const int flags = O_CREAT|O_LARGEFILE|O_NOATIME|O_NOFOLLOW|O_TRUNC|O_WRONLY; - const int mode = S_IWUSR; - fdout = ::open(out.c_str(),flags,mode); + const int flags = O_CREAT|O_LARGEFILE|O_NOATIME|O_NOFOLLOW|O_TRUNC|O_WRONLY; + const mode_t mode = S_IWUSR; + fdout = fs::open(out,flags,mode); if(fdout == -1) return -1; rv = fs::clonefile(fdin,fdout); error = errno; - ::close(fdin); - ::close(fdout); + fs::close(fdin); + fs::close(fdout); errno = error; return rv; diff --git a/src/fs_clonepath.cpp b/src/fs_clonepath.cpp index c9d27e5a..b6efcf33 100644 --- a/src/fs_clonepath.cpp +++ b/src/fs_clonepath.cpp @@ -14,14 +14,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include -#include - #include #include "errno.h" #include "fs_attr.hpp" +#include "fs_base_chmod.hpp" +#include "fs_base_chown.hpp" +#include "fs_base_mkdir.hpp" +#include "fs_base_stat.hpp" +#include "fs_base_utimensat.hpp" #include "fs_path.hpp" #include "fs_xattr.hpp" @@ -61,26 +62,26 @@ namespace fs fs::path::dirname(dirname); if(!dirname.empty()) { - rv = clonepath(fromsrc,tosrc,dirname.c_str()); + rv = fs::clonepath(fromsrc,tosrc,dirname.c_str()); if(rv == -1) return -1; } fs::path::make(&fromsrc,relative,frompath); - rv = ::stat(frompath.c_str(),&st); + rv = fs::stat(frompath,st); if(rv == -1) return -1; else if(!S_ISDIR(st.st_mode)) return (errno = ENOTDIR,-1); fs::path::make(&tosrc,relative,topath); - rv = ::mkdir(topath.c_str(),st.st_mode); + rv = fs::mkdir(topath,st.st_mode); if(rv == -1) { if(errno != EEXIST) return -1; - rv = ::chmod(topath.c_str(),st.st_mode); + rv = fs::chmod(topath,st.st_mode); if(rv == -1) return -1; } @@ -94,14 +95,11 @@ namespace fs if(rv == -1 && !ignorable_error(errno)) return -1; - rv = ::chown(topath.c_str(),st.st_uid,st.st_gid); + rv = fs::chown(topath,st); if(rv == -1) return -1; - struct timespec times[2]; - times[0] = st.st_atim; - times[1] = st.st_mtim; - rv = ::utimensat(-1,topath.c_str(),times,0); + rv = fs::utimensat(topath,st); if(rv == -1) return -1; diff --git a/src/fs_movefile.cpp b/src/fs_movefile.cpp index d2afd189..045295d7 100644 --- a/src/fs_movefile.cpp +++ b/src/fs_movefile.cpp @@ -23,6 +23,10 @@ #include #include "fs.hpp" +#include "fs_base_open.hpp" +#include "fs_base_close.hpp" +#include "fs_base_unlink.hpp" +#include "fs_base_stat.hpp" #include "fs_clonefile.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" @@ -49,7 +53,7 @@ namespace fs fdin = origfd; - rv = fstat(fdin,&fdin_st); + rv = fs::fstat(fdin,fdin_st); if(rv == -1) return -1; @@ -73,35 +77,35 @@ namespace fs return -1; fs::path::append(fdin_path,fusepath); - fdin = ::open(fdin_path.c_str(),O_RDONLY); + fdin = fs::open(fdin_path,O_RDONLY); if(fdin == -1) return -1; fs::path::append(fdout_path,fusepath); - fdout = ::open(fdout_path.c_str(),fdin_flags|O_CREAT,fdin_st.st_mode); + fdout = fs::open(fdout_path,fdin_flags|O_CREAT,fdin_st.st_mode); if(fdout == -1) return -1; rv = fs::clonefile(fdin,fdout); if(rv == -1) { - ::close(fdin); - ::close(fdout); - ::unlink(fdout_path.c_str()); + fs::close(fdin); + fs::close(fdout); + fs::unlink(fdout_path.c_str()); return -1; } - rv = ::unlink(fdin_path.c_str()); + rv = fs::unlink(fdin_path); if(rv == -1) { - ::close(fdin); - ::close(fdout); - ::unlink(fdout_path.c_str()); + fs::close(fdin); + fs::close(fdout); + fs::unlink(fdout_path); return -1; } - ::close(fdin); - ::close(origfd); + fs::close(fdin); + fs::close(origfd); origfd = fdout; diff --git a/src/fs_xattr.cpp b/src/fs_xattr.cpp index 72108438..acd8fb05 100644 --- a/src/fs_xattr.cpp +++ b/src/fs_xattr.cpp @@ -26,6 +26,8 @@ #include #include "errno.hpp" +#include "fs_base_open.hpp" +#include "fs_base_close.hpp" #include "str.hpp" #include "xattr.hpp" @@ -349,13 +351,13 @@ namespace fs { int fd; - fd = ::open(path.c_str(),O_RDONLY|O_NONBLOCK); + fd = fs::open(path,O_RDONLY|O_NONBLOCK); if(fd == -1) return -1; set(fd,attrs); - return ::close(fd); + return fs::close(fd); } int diff --git a/src/fsync.cpp b/src/fsync.cpp index 703e734a..6d10ab4b 100644 --- a/src/fsync.cpp +++ b/src/fsync.cpp @@ -23,10 +23,9 @@ #include #include -#include - #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_fsync.hpp" static int @@ -36,8 +35,8 @@ _fsync(const int fd, int rv; rv = (isdatasync ? - ::fdatasync(fd) : - ::fsync(fd)); + fs::fdatasync(fd) : + fs::fsync(fd)); return ((rv == -1) ? -errno : 0); } diff --git a/src/ftruncate.cpp b/src/ftruncate.cpp index 3bd6fd44..07c643df 100644 --- a/src/ftruncate.cpp +++ b/src/ftruncate.cpp @@ -16,11 +16,9 @@ #include -#include -#include - #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_ftruncate.hpp" static int @@ -29,7 +27,7 @@ _ftruncate(const int fd, { int rv; - rv = ::ftruncate(fd,size); + rv = fs::ftruncate(fd,size); return ((rv == -1) ? -errno : 0); } diff --git a/src/getattr.cpp b/src/getattr.cpp index 1c39eae4..eaba1efb 100644 --- a/src/getattr.cpp +++ b/src/getattr.cpp @@ -19,12 +19,9 @@ #include #include -#include -#include -#include - #include "config.hpp" #include "errno.hpp" +#include "fs_base_stat.hpp" #include "fs_path.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -76,7 +73,7 @@ _getattr(Policy::Func::Search searchFunc, fs::path::make(basepaths[0],fusepath,fullpath); - rv = ::lstat(fullpath.c_str(),&buf); + rv = fs::lstat(fullpath,buf); return ((rv == -1) ? -errno : 0); } diff --git a/src/getxattr.cpp b/src/getxattr.cpp index 7f54dad7..2a4143ea 100644 --- a/src/getxattr.cpp +++ b/src/getxattr.cpp @@ -23,17 +23,15 @@ #include #include -#include -#include #include "config.hpp" #include "errno.hpp" +#include "fs_base_getxattr.hpp" #include "fs_path.hpp" #include "rwlock.hpp" #include "str.hpp" #include "ugid.hpp" #include "version.hpp" -#include "xattr.hpp" using std::string; using std::vector; @@ -47,15 +45,11 @@ _lgetxattr(const string &path, void *value, const size_t size) { -#ifndef WITHOUT_XATTR int rv; - rv = ::lgetxattr(path.c_str(),attrname,value,size); + rv = fs::lgetxattr(path,attrname,value,size); return ((rv == -1) ? -errno : rv); -#else - return -ENOTSUP; -#endif } static diff --git a/src/ioctl.cpp b/src/ioctl.cpp index 410435c1..c081bfc9 100644 --- a/src/ioctl.cpp +++ b/src/ioctl.cpp @@ -20,13 +20,13 @@ #include #include -#include -#include -#include #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_close.hpp" +#include "fs_base_ioctl.hpp" +#include "fs_base_open.hpp" #include "fs_path.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -43,7 +43,7 @@ _ioctl(const int fd, { int rv; - rv = ::ioctl(fd,cmd,data); + rv = fs::ioctl(fd,cmd,data); return ((rv == -1) ? -errno : rv); } @@ -75,13 +75,13 @@ _ioctl_dir_base(Policy::Func::Search searchFunc, fs::path::make(basepaths[0],fusepath,fullpath); const int flags = O_RDONLY | O_NOATIME | O_NONBLOCK; - fd = ::open(fullpath.c_str(),flags); + fd = fs::open(fullpath,flags); if(fd == -1) return -errno; rv = _ioctl(fd,cmd,data); - ::close(fd); + fs::close(fd); return rv; } diff --git a/src/link.cpp b/src/link.cpp index dd0a7492..00e2bf2c 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -19,10 +19,9 @@ #include #include -#include - #include "config.hpp" #include "errno.hpp" +#include "fs_base_link.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rv.hpp" @@ -56,7 +55,7 @@ _link_create_path_core(const string &oldbasepath, fs::path::make(&oldbasepath,oldfusepath,oldfullpath); fs::path::make(&oldbasepath,newfusepath,newfullpath); - rv = ::link(oldfullpath.c_str(),newfullpath.c_str()); + rv = fs::link(oldfullpath,newfullpath); return calc_error(rv,error,errno); } @@ -171,7 +170,7 @@ _link_preserve_path_core(Policy::Func::Search searchFunc, fs::path::make(&oldbasepath,oldfusepath,oldfullpath); fs::path::make(&oldbasepath,newfusepath,newfullpath); - rv = ::link(oldfullpath.c_str(),newfullpath.c_str()); + rv = fs::link(oldfullpath,newfullpath); if((rv == -1) && (errno == ENOENT)) { rv = _clonepath_if_would_create(searchFunc,createFunc, @@ -179,7 +178,7 @@ _link_preserve_path_core(Policy::Func::Search searchFunc, oldbasepath, oldfusepath,newfusepath); if(rv != -1) - rv = ::link(oldfullpath.c_str(),newfullpath.c_str()); + rv = fs::link(oldfullpath,newfullpath); } return calc_error(rv,error,errno); diff --git a/src/listxattr.cpp b/src/listxattr.cpp index 33441bb4..b84be9ef 100644 --- a/src/listxattr.cpp +++ b/src/listxattr.cpp @@ -19,13 +19,13 @@ #include #include -#include #include #include "buildvector.hpp" #include "category.hpp" #include "config.hpp" #include "errno.hpp" +#include "fs_base_listxattr.hpp" #include "fs_path.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -69,7 +69,6 @@ _listxattr_controlfile(char *list, return xattrs.size(); } -#ifndef WITHOUT_XATTR static int _listxattr(Policy::Func::Search searchFunc, @@ -89,11 +88,10 @@ _listxattr(Policy::Func::Search searchFunc, fs::path::make(basepaths[0],fusepath,fullpath); - rv = ::llistxattr(fullpath.c_str(),list,size); + rv = fs::llistxattr(fullpath,list,size); return ((rv == -1) ? -errno : rv); } -#endif namespace mergerfs { @@ -110,7 +108,6 @@ namespace mergerfs if(fusepath == config.controlfile) return _listxattr_controlfile(list,size); -#ifndef WITHOUT_XATTR const ugid::Set ugid(fc->uid,fc->gid); const rwlock::ReadGuard readlock(&config.srcmountslock); @@ -120,9 +117,6 @@ namespace mergerfs fusepath, list, size); -#else - return -ENOTSUP; -#endif } } } diff --git a/src/mkdir.cpp b/src/mkdir.cpp index 51453645..6d7efecc 100644 --- a/src/mkdir.cpp +++ b/src/mkdir.cpp @@ -16,14 +16,12 @@ #include -#include -#include - #include #include #include "config.hpp" #include "errno.hpp" +#include "fs_base_mkdir.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rv.hpp" @@ -55,7 +53,7 @@ _mkdir_loop_core(const string &existingpath, fs::path::make(&createpath,fusepath,fullpath); - rv = ::mkdir(fullpath.c_str(),mode); + rv = fs::mkdir(fullpath,mode); return calc_error(rv,error,errno); } diff --git a/src/mknod.cpp b/src/mknod.cpp index 29b68c8b..164e9d61 100644 --- a/src/mknod.cpp +++ b/src/mknod.cpp @@ -19,13 +19,9 @@ #include #include -#include -#include -#include -#include - #include "config.hpp" #include "errno.hpp" +#include "fs_base_mknod.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rv.hpp" @@ -57,7 +53,7 @@ _mknod_loop_core(const string &existingpath, fs::path::make(&createpath,fusepath,fullpath); - rv = ::mknod(fullpath.c_str(),mode,dev); + rv = fs::mknod(fullpath,mode,dev); return calc_error(rv,error,errno); } diff --git a/src/open.cpp b/src/open.cpp index 569d6252..d51a99d1 100644 --- a/src/open.cpp +++ b/src/open.cpp @@ -17,8 +17,6 @@ #include #include -#include -#include #include #include @@ -26,6 +24,7 @@ #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_open.hpp" #include "fs_path.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -46,7 +45,7 @@ _open_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - fd = ::open(fullpath.c_str(),flags); + fd = fs::open(fullpath,flags); if(fd == -1) return -errno; diff --git a/src/read.cpp b/src/read.cpp index cf6d9a55..e741e777 100644 --- a/src/read.cpp +++ b/src/read.cpp @@ -17,12 +17,12 @@ #include #include -#include #include #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_read.hpp" static int @@ -33,7 +33,7 @@ _read(const int fd, { int rv; - rv = ::pread(fd,buf,count,offset); + rv = fs::pread(fd,buf,count,offset); return ((rv == -1) ? -errno : rv); } diff --git a/src/readdir.cpp b/src/readdir.cpp index ca4f8b5f..3ef78f53 100644 --- a/src/readdir.cpp +++ b/src/readdir.cpp @@ -22,10 +22,11 @@ #include #include -#include - #include "config.hpp" #include "errno.hpp" +#include "fs_base_closedir.hpp" +#include "fs_base_opendir.hpp" +#include "fs_base_readdir.hpp" #include "fs_path.hpp" #include "readdir.hpp" #include "rwlock.hpp" @@ -55,11 +56,11 @@ _readdir(const vector &srcmounts, fs::path::make(&srcmounts[i],dirname,basepath); - dh = ::opendir(basepath.c_str()); + dh = fs::opendir(basepath); if(!dh) continue; - for(struct dirent *de = ::readdir(dh); de != NULL; de = ::readdir(dh)) + for(struct dirent *de = fs::readdir(dh); de != NULL; de = fs::readdir(dh)) { if(found.insert(de->d_name).second == false) continue; @@ -69,7 +70,7 @@ _readdir(const vector &srcmounts, return -ENOMEM; } - ::closedir(dh); + fs::closedir(dh); } if(found.empty()) diff --git a/src/readlink.cpp b/src/readlink.cpp index 3a82c092..b484b052 100644 --- a/src/readlink.cpp +++ b/src/readlink.cpp @@ -16,13 +16,9 @@ #include -#include -#include -#include -#include - #include "config.hpp" #include "errno.hpp" +#include "fs_base_readlink.hpp" #include "fs_path.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -43,7 +39,7 @@ _readlink_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::readlink(fullpath.c_str(),buf,size); + rv = fs::readlink(fullpath,buf,size); if(rv == -1) return -errno; diff --git a/src/release.cpp b/src/release.cpp index a7dec87f..f38bfd6e 100644 --- a/src/release.cpp +++ b/src/release.cpp @@ -16,18 +16,17 @@ #include -#include - #include #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_close.hpp" static int _release(FileInfo *fi) { - ::close(fi->fd); + fs::close(fi->fd); delete fi; diff --git a/src/removexattr.cpp b/src/removexattr.cpp index 21795f31..f7398615 100644 --- a/src/removexattr.cpp +++ b/src/removexattr.cpp @@ -19,21 +19,18 @@ #include #include -#include - #include "config.hpp" #include "errno.hpp" +#include "fs_base_removexattr.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" -#include "xattr.hpp" using std::string; using std::vector; using mergerfs::Policy; -#ifndef WITHOUT_XATTR static int _removexattr_loop_core(const string *basepath, @@ -46,7 +43,7 @@ _removexattr_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::lremovexattr(fullpath.c_str(),attrname); + rv = fs::lremovexattr(fullpath,attrname); return calc_error(rv,error,errno); } @@ -86,7 +83,6 @@ _removexattr(Policy::Func::Action actionFunc, return _removexattr_loop(basepaths,fusepath,attrname); } -#endif namespace mergerfs { @@ -96,7 +92,6 @@ namespace mergerfs removexattr(const char *fusepath, const char *attrname) { -#ifndef WITHOUT_XATTR const fuse_context *fc = fuse_get_context(); const Config &config = Config::get(fc); @@ -111,9 +106,6 @@ namespace mergerfs config.minfreespace, fusepath, attrname); -#else - return -ENOTSUP; -#endif } } } diff --git a/src/rename.cpp b/src/rename.cpp index b75a3b98..bb3cfcd1 100644 --- a/src/rename.cpp +++ b/src/rename.cpp @@ -14,9 +14,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include - #include #include #include @@ -24,6 +21,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_rename.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rv.hpp" @@ -88,7 +86,7 @@ _rename_create_path_core(const vector &oldbasepaths, fs::path::make(&oldbasepath,oldfusepath,oldfullpath); - rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); + rv = fs::rename(oldfullpath,newfullpath); error = calc_error(rv,error,errno); if(RENAME_FAILED(rv)) tounlink.push_back(oldfullpath); @@ -217,14 +215,14 @@ _rename_preserve_path_core(Policy::Func::Search searchFunc, fs::path::make(&oldbasepath,oldfusepath,oldfullpath); - rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); + rv = fs::rename(oldfullpath,newfullpath); if(RENAME_FAILED_WITH(rv,ENOENT)) { rv = _clonepath_if_would_create(searchFunc,createFunc, srcmounts,minfreespace, oldbasepath,oldfusepath,newfusepath); if(POLICY_SUCCEEDED(rv)) - rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); + rv = fs::rename(oldfullpath,newfullpath); } error = calc_error(rv,error,errno); diff --git a/src/rmdir.cpp b/src/rmdir.cpp index 70e79ed3..4c804379 100644 --- a/src/rmdir.cpp +++ b/src/rmdir.cpp @@ -22,6 +22,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_rmdir.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "rwlock.hpp" @@ -42,7 +43,7 @@ _rmdir_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::rmdir(fullpath.c_str()); + rv = fs::rmdir(fullpath); return calc_error(rv,error,errno); } diff --git a/src/setxattr.cpp b/src/setxattr.cpp index ce61e360..92444750 100644 --- a/src/setxattr.cpp +++ b/src/setxattr.cpp @@ -21,17 +21,16 @@ #include #include -#include #include "config.hpp" #include "errno.hpp" +#include "fs_base_setxattr.hpp" #include "fs_path.hpp" #include "num.hpp" #include "rv.hpp" #include "rwlock.hpp" #include "str.hpp" #include "ugid.hpp" -#include "xattr.hpp" using std::string; using std::vector; @@ -287,8 +286,6 @@ _setxattr_controlfile(Config &config, return -EINVAL; } -#ifndef WITHOUT_XATTR - static int _setxattr_loop_core(const string *basepath, @@ -304,7 +301,7 @@ _setxattr_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::lsetxattr(fullpath.c_str(),attrname,attrval,attrvalsize,flags); + rv = fs::lsetxattr(fullpath,attrname,attrval,attrvalsize,flags); return calc_error(rv,error,errno); } @@ -352,8 +349,6 @@ _setxattr(Policy::Func::Action actionFunc, return _setxattr_loop(basepaths,fusepath,attrname,attrval,attrvalsize,flags); } -#endif - namespace mergerfs { namespace fuse @@ -374,7 +369,6 @@ namespace mergerfs string(attrval,attrvalsize), flags); -#ifndef WITHOUT_XATTR const ugid::Set ugid(fc->uid,fc->gid); const rwlock::ReadGuard readlock(&config.srcmountslock); @@ -386,9 +380,6 @@ namespace mergerfs attrval, attrvalsize, flags); -#else - return -ENOTSUP; -#endif } } } diff --git a/src/statfs.cpp b/src/statfs.cpp index f9d564ae..1461d9a1 100644 --- a/src/statfs.cpp +++ b/src/statfs.cpp @@ -16,8 +16,6 @@ #include -#include - #include #include #include @@ -26,6 +24,8 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_stat.hpp" +#include "fs_base_statvfs.hpp" #include "rwlock.hpp" #include "success_fail.hpp" #include "ugid.hpp" @@ -75,11 +75,11 @@ _statfs_core(const char *srcmount, struct stat st; struct statvfs fsstat; - rv = ::statvfs(srcmount,&fsstat); + rv = fs::statvfs(srcmount,fsstat); if(STATVFS_FAILED(rv)) return; - rv = ::stat(srcmount,&st); + rv = fs::stat(srcmount,st); if(STAT_FAILED(rv)) return; diff --git a/src/statvfs_util.hpp b/src/statvfs_util.hpp index d935329e..5f7e9d01 100644 --- a/src/statvfs_util.hpp +++ b/src/statvfs_util.hpp @@ -14,10 +14,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include - #include +#include + #include "success_fail.hpp" namespace StatVFS @@ -30,21 +30,6 @@ namespace StatVFS return (st.f_flag & ST_RDONLY); } - static - inline - bool - readonly(const std::string &path) - { - int rv; - struct statvfs st; - - rv = ::statvfs(path.c_str(),&st); - if(STATVFS_FAILED(rv)) - return false; - - return readonly(st); - } - static inline uint64_t diff --git a/src/truncate.cpp b/src/truncate.cpp index b67906a0..035beb53 100644 --- a/src/truncate.cpp +++ b/src/truncate.cpp @@ -24,6 +24,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_truncate.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "rwlock.hpp" @@ -45,7 +46,7 @@ _truncate_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::truncate(fullpath.c_str(),size); + rv = fs::truncate(fullpath,size); return calc_error(rv,error,errno); } diff --git a/src/unlink.cpp b/src/unlink.cpp index cc711f7a..4ace660d 100644 --- a/src/unlink.cpp +++ b/src/unlink.cpp @@ -23,6 +23,7 @@ #include "config.hpp" #include "errno.hpp" +#include "fs_base_unlink.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "rwlock.hpp" @@ -43,7 +44,7 @@ _unlink_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::unlink(fullpath.c_str()); + rv = fs::unlink(fullpath); return calc_error(rv,error,errno); } diff --git a/src/utimens.cpp b/src/utimens.cpp index 15a81f44..455b941c 100644 --- a/src/utimens.cpp +++ b/src/utimens.cpp @@ -17,13 +17,13 @@ #include #include -#include #include #include #include "config.hpp" #include "errno.hpp" +#include "fs_base_utimensat.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "rwlock.hpp" @@ -45,7 +45,7 @@ _utimens_loop_core(const string *basepath, fs::path::make(basepath,fusepath,fullpath); - rv = ::utimensat(0,fullpath.c_str(),ts,AT_SYMLINK_NOFOLLOW); + rv = fs::utimensat(AT_FDCWD,fullpath,ts,AT_SYMLINK_NOFOLLOW); return calc_error(rv,error,errno); } diff --git a/src/write.cpp b/src/write.cpp index 78fb9162..15f2efca 100644 --- a/src/write.cpp +++ b/src/write.cpp @@ -16,11 +16,10 @@ #include -#include - #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" +#include "fs_base_write.hpp" #include "fs_movefile.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -42,7 +41,7 @@ _write(const int fd, { int rv; - rv = ::pwrite(fd,buf,count,offset); + rv = fs::pwrite(fd,buf,count,offset); return ((rv == -1) ? -errno : rv); }