From 2fe20b888e3b77725f0518d69a697d1fb3775832 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Mon, 17 Aug 2020 16:29:22 -0400 Subject: [PATCH] clean up and separate out fs_* files --- src/fs_acl.cpp | 8 +- src/fs_attr_linux.icpp | 12 +- src/fs_attr_unsupported.icpp | 4 +- src/fs_base_utime.hpp | 67 ---- src/fs_base_utime_generic.hpp | 313 ------------------ src/fs_clonefile.cpp | 50 +-- src/fs_clonepath.cpp | 103 +++--- src/{fs_base_close.hpp => fs_close.hpp} | 0 src/{fs_base_closedir.hpp => fs_closedir.hpp} | 0 src/fs_copydata.cpp | 53 +++ src/fs_copydata.hpp | 29 ++ src/fs_copydata_copy_file_range.cpp | 2 +- src/fs_copydata_readwrite.cpp | 8 +- src/fs_cow.cpp | 53 +-- src/fs_devid.hpp | 6 +- src/{fs_base_dirfd.hpp => fs_dirfd.hpp} | 0 src/{fs_base_dup.hpp => fs_dup.hpp} | 0 src/fs_eaccess.hpp | 42 +++ src/fs_exists.hpp | 2 +- ...e_utime_utimensat.hpp => fs_faccessat.hpp} | 20 +- src/{fs_base_fadvise.cpp => fs_fadvise.cpp} | 28 +- src/{fs_base_fadvise.hpp => fs_fadvise.hpp} | 2 + ...dvise_posix.icpp => fs_fadvise_posix.icpp} | 12 +- ...orted.icpp => fs_fadvise_unsupported.icpp} | 8 +- ...fs_base_fallocate.cpp => fs_fallocate.cpp} | 8 +- ...fs_base_fallocate.hpp => fs_fallocate.hpp} | 0 ...ate_linux.icpp => fs_fallocate_linux.icpp} | 12 +- ...llocate_osx.icpp => fs_fallocate_osx.icpp} | 47 +-- ...ate_posix.icpp => fs_fallocate_posix.icpp} | 19 +- ...ted.icpp => fs_fallocate_unsupported.icpp} | 8 +- src/{fs_base_fchmod.hpp => fs_fchmod.hpp} | 2 +- src/fs_fchmodat.hpp | 49 +++ src/{fs_base_fchown.hpp => fs_fchown.hpp} | 3 +- src/{fs_base_fsync.hpp => fs_fdatasync.hpp} | 8 - src/fs_fgetxattr.hpp | 61 ++++ src/fs_ficlone_linux.icpp | 2 +- src/fs_file_size.cpp | 2 +- src/fs_findonfs.cpp | 3 +- src/fs_flistxattr.hpp | 41 +++ src/{fs_base_flock.hpp => fs_flock.hpp} | 0 src/fs_fsetxattr.hpp | 61 ++++ src/fs_fstat.hpp | 36 ++ src/{fs_base_fstatat.hpp => fs_fstatat.hpp} | 0 src/fs_fsync.hpp | 32 ++ ...fs_base_ftruncate.hpp => fs_ftruncate.hpp} | 0 src/fs_futimens.hpp | 48 +++ src/fs_futimens_freebsd_11.hpp | 33 ++ src/fs_futimens_generic.hpp | 283 ++++++++++++++++ src/fs_futimens_linux.hpp | 33 ++ ...fs_base_futimesat.cpp => fs_futimesat.cpp} | 4 +- ...fs_base_futimesat.hpp => fs_futimesat.hpp} | 0 ...generic.icpp => fs_futimesat_generic.icpp} | 8 +- ...timesat_osx.icpp => fs_futimesat_osx.icpp} | 67 ++-- ...fs_base_getdents.cpp => fs_getdents64.cpp} | 6 +- ...fs_base_getdents.hpp => fs_getdents64.hpp} | 6 +- src/fs_has_space.cpp | 2 +- src/fs_info.cpp | 4 +- src/{fs_base_ioctl.hpp => fs_ioctl.hpp} | 0 src/{fs_base_chmod.hpp => fs_lchmod.hpp} | 30 +- src/{fs_base_chown.hpp => fs_lchown.hpp} | 34 +- ...{fs_base_getxattr.hpp => fs_lgetxattr.hpp} | 38 +-- src/{fs_base_link.hpp => fs_link.hpp} | 0 ...s_base_listxattr.hpp => fs_llistxattr.hpp} | 14 - ...se_removexattr.hpp => fs_lremovexattr.hpp} | 0 src/{fs_base_lseek.hpp => fs_lseek.hpp} | 0 ...{fs_base_setxattr.hpp => fs_lsetxattr.hpp} | 24 +- src/fs_lstat.hpp | 46 +++ src/fs_lutimens.hpp | 48 +++ src/{fs_base_mkdir.hpp => fs_mkdir.hpp} | 0 src/{fs_base_mknod.hpp => fs_mknod.hpp} | 0 src/fs_mktemp.cpp | 2 +- src/fs_movefile.cpp | 10 +- src/{fs_base_open.hpp => fs_open.hpp} | 0 src/{fs_base_opendir.hpp => fs_opendir.hpp} | 0 src/{fs_base_read.hpp => fs_read.hpp} | 0 src/{fs_base_readdir.hpp => fs_readdir.hpp} | 0 src/{fs_base_readlink.hpp => fs_readlink.hpp} | 0 src/{fs_base_realpath.hpp => fs_realpath.hpp} | 0 src/fs_realpathize.cpp | 2 +- src/{fs_base_remove.hpp => fs_remove.hpp} | 0 src/{fs_base_rename.hpp => fs_rename.hpp} | 0 src/{fs_base_rmdir.hpp => fs_rmdir.hpp} | 0 src/fs_stat.hpp | 46 +++ src/{fs_base_stat.hpp => fs_stat_utils.hpp} | 47 +-- src/{fs_base_statvfs.hpp => fs_statvfs.hpp} | 4 +- src/fs_statvfs_cache.cpp | 2 +- src/{fs_base_symlink.hpp => fs_symlink.hpp} | 0 src/{fs_base_truncate.hpp => fs_truncate.hpp} | 0 src/{fs_base_unlink.hpp => fs_unlink.hpp} | 0 src/fs_utimensat.hpp | 27 ++ ...se_access.hpp => fs_utimensat_freebsd.hpp} | 32 +- src/fs_utimensat_generic.hpp | 295 +++++++++++++++++ src/fs_utimensat_linux.hpp | 49 +++ src/{fs_base_write.hpp => fs_write.hpp} | 0 src/fs_xattr.cpp | 21 +- src/fuse_access.cpp | 2 +- src/fuse_chmod.cpp | 4 +- src/fuse_chown.cpp | 2 +- src/fuse_create.cpp | 2 +- src/fuse_fallocate.cpp | 2 +- src/fuse_fchmod.cpp | 2 +- src/fuse_fchown.cpp | 2 +- src/fuse_fgetattr.cpp | 2 +- src/fuse_flock.cpp | 2 +- src/fuse_flush.cpp | 4 +- src/fuse_free_hide.cpp | 2 +- src/fuse_fsync.cpp | 3 +- src/fuse_fsyncdir.cpp | 2 +- src/fuse_ftruncate.cpp | 2 +- src/fuse_futimens.cpp | 2 +- src/fuse_getattr.cpp | 2 +- src/fuse_getxattr.cpp | 2 +- src/fuse_ioctl.cpp | 6 +- src/fuse_link.cpp | 2 +- src/fuse_listxattr.cpp | 2 +- src/fuse_mkdir.cpp | 2 +- src/fuse_mknod.cpp | 2 +- src/fuse_open.cpp | 18 +- src/fuse_read.cpp | 2 +- src/fuse_readdir_linux.cpp | 10 +- src/fuse_readdir_plus_linux.cpp | 12 +- src/fuse_readdir_plus_posix.cpp | 12 +- src/fuse_readdir_posix.cpp | 10 +- src/fuse_readlink.cpp | 4 +- src/fuse_release.cpp | 4 +- src/fuse_removexattr.cpp | 2 +- src/fuse_rename.cpp | 4 +- src/fuse_rmdir.cpp | 2 +- src/fuse_setxattr.cpp | 2 +- src/fuse_statfs.cpp | 4 +- src/fuse_symlink.cpp | 2 +- src/fuse_truncate.cpp | 2 +- src/fuse_unlink.cpp | 2 +- src/fuse_utimens.cpp | 4 +- src/fuse_write.cpp | 2 +- 135 files changed, 1722 insertions(+), 910 deletions(-) delete mode 100644 src/fs_base_utime.hpp delete mode 100644 src/fs_base_utime_generic.hpp rename src/{fs_base_close.hpp => fs_close.hpp} (100%) rename src/{fs_base_closedir.hpp => fs_closedir.hpp} (100%) create mode 100644 src/fs_copydata.cpp create mode 100644 src/fs_copydata.hpp rename src/{fs_base_dirfd.hpp => fs_dirfd.hpp} (100%) rename src/{fs_base_dup.hpp => fs_dup.hpp} (100%) create mode 100644 src/fs_eaccess.hpp rename src/{fs_base_utime_utimensat.hpp => fs_faccessat.hpp} (69%) rename src/{fs_base_fadvise.cpp => fs_fadvise.cpp} (68%) rename src/{fs_base_fadvise.hpp => fs_fadvise.hpp} (98%) rename src/{fs_base_fadvise_posix.icpp => fs_fadvise_posix.icpp} (82%) rename src/{fs_base_fadvise_unsupported.icpp => fs_fadvise_unsupported.icpp} (88%) rename src/{fs_base_fallocate.cpp => fs_fallocate.cpp} (84%) rename src/{fs_base_fallocate.hpp => fs_fallocate.hpp} (100%) rename src/{fs_base_fallocate_linux.icpp => fs_fallocate_linux.icpp} (81%) rename src/{fs_base_fallocate_osx.icpp => fs_fallocate_osx.icpp} (58%) rename src/{fs_base_fallocate_posix.icpp => fs_fallocate_posix.icpp} (79%) rename src/{fs_base_fallocate_unsupported.icpp => fs_fallocate_unsupported.icpp} (87%) rename src/{fs_base_fchmod.hpp => fs_fchmod.hpp} (98%) create mode 100644 src/fs_fchmodat.hpp rename src/{fs_base_fchown.hpp => fs_fchown.hpp} (97%) rename src/{fs_base_fsync.hpp => fs_fdatasync.hpp} (93%) create mode 100644 src/fs_fgetxattr.hpp create mode 100644 src/fs_flistxattr.hpp rename src/{fs_base_flock.hpp => fs_flock.hpp} (100%) create mode 100644 src/fs_fsetxattr.hpp create mode 100644 src/fs_fstat.hpp rename src/{fs_base_fstatat.hpp => fs_fstatat.hpp} (100%) create mode 100644 src/fs_fsync.hpp rename src/{fs_base_ftruncate.hpp => fs_ftruncate.hpp} (100%) create mode 100644 src/fs_futimens.hpp create mode 100644 src/fs_futimens_freebsd_11.hpp create mode 100644 src/fs_futimens_generic.hpp create mode 100644 src/fs_futimens_linux.hpp rename src/{fs_base_futimesat.cpp => fs_futimesat.cpp} (91%) rename src/{fs_base_futimesat.hpp => fs_futimesat.hpp} (100%) rename src/{fs_base_futimesat_generic.icpp => fs_futimesat_generic.icpp} (82%) rename src/{fs_base_futimesat_osx.icpp => fs_futimesat_osx.icpp} (54%) rename src/{fs_base_getdents.cpp => fs_getdents64.cpp} (91%) rename src/{fs_base_getdents.hpp => fs_getdents64.hpp} (89%) rename src/{fs_base_ioctl.hpp => fs_ioctl.hpp} (100%) rename src/{fs_base_chmod.hpp => fs_lchmod.hpp} (66%) rename src/{fs_base_chown.hpp => fs_lchown.hpp} (72%) rename src/{fs_base_getxattr.hpp => fs_lgetxattr.hpp} (69%) rename src/{fs_base_link.hpp => fs_link.hpp} (100%) rename src/{fs_base_listxattr.hpp => fs_llistxattr.hpp} (85%) rename src/{fs_base_removexattr.hpp => fs_lremovexattr.hpp} (100%) rename src/{fs_base_lseek.hpp => fs_lseek.hpp} (100%) rename src/{fs_base_setxattr.hpp => fs_lsetxattr.hpp} (77%) create mode 100644 src/fs_lstat.hpp create mode 100644 src/fs_lutimens.hpp rename src/{fs_base_mkdir.hpp => fs_mkdir.hpp} (100%) rename src/{fs_base_mknod.hpp => fs_mknod.hpp} (100%) rename src/{fs_base_open.hpp => fs_open.hpp} (100%) rename src/{fs_base_opendir.hpp => fs_opendir.hpp} (100%) rename src/{fs_base_read.hpp => fs_read.hpp} (100%) rename src/{fs_base_readdir.hpp => fs_readdir.hpp} (100%) rename src/{fs_base_readlink.hpp => fs_readlink.hpp} (100%) rename src/{fs_base_realpath.hpp => fs_realpath.hpp} (100%) rename src/{fs_base_remove.hpp => fs_remove.hpp} (100%) rename src/{fs_base_rename.hpp => fs_rename.hpp} (100%) rename src/{fs_base_rmdir.hpp => fs_rmdir.hpp} (100%) create mode 100644 src/fs_stat.hpp rename src/{fs_base_stat.hpp => fs_stat_utils.hpp} (68%) rename src/{fs_base_statvfs.hpp => fs_statvfs.hpp} (96%) rename src/{fs_base_symlink.hpp => fs_symlink.hpp} (100%) rename src/{fs_base_truncate.hpp => fs_truncate.hpp} (100%) rename src/{fs_base_unlink.hpp => fs_unlink.hpp} (100%) create mode 100644 src/fs_utimensat.hpp rename src/{fs_base_access.hpp => fs_utimensat_freebsd.hpp} (59%) create mode 100644 src/fs_utimensat_generic.hpp create mode 100644 src/fs_utimensat_linux.hpp rename src/{fs_base_write.hpp => fs_write.hpp} (100%) diff --git a/src/fs_acl.cpp b/src/fs_acl.cpp index 8c20c2b6..50e2795c 100644 --- a/src/fs_acl.cpp +++ b/src/fs_acl.cpp @@ -16,11 +16,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include - -#include "fs_base_getxattr.hpp" +#include "fs_lgetxattr.hpp" #include "fs_path.hpp" +#include + const char POSIX_ACL_DEFAULT_XATTR[] = "system.posix_acl_default"; namespace fs @@ -31,7 +31,7 @@ namespace fs dir_has_defaults(const std::string &fullpath_) { int rv; - std::string dirpath; + std::string dirpath; dirpath = fs::path::dirname(fullpath_); diff --git a/src/fs_attr_linux.icpp b/src/fs_attr_linux.icpp index 6cac839f..8d346190 100644 --- a/src/fs_attr_linux.icpp +++ b/src/fs_attr_linux.icpp @@ -14,15 +14,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include +#include "errno.hpp" +#include "fs_close.hpp" +#include "fs_open.hpp" +#include "fs_ioctl.hpp" #include -#include "errno.hpp" -#include "fs_base_close.hpp" -#include "fs_base_open.hpp" -#include "fs_base_ioctl.hpp" +#include +#include using std::string; diff --git a/src/fs_attr_unsupported.icpp b/src/fs_attr_unsupported.icpp index 63ca83f0..852038fc 100644 --- a/src/fs_attr_unsupported.icpp +++ b/src/fs_attr_unsupported.icpp @@ -14,10 +14,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include - #include "errno.hpp" +#include + namespace fs { namespace attr diff --git a/src/fs_base_utime.hpp b/src/fs_base_utime.hpp deleted file mode 100644 index 6c87759b..00000000 --- a/src/fs_base_utime.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - 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. -*/ - -#pragma once - -#ifdef __linux__ -# include "fs_base_utime_utimensat.hpp" -#elif __FreeBSD__ >= 11 -# include "fs_base_utime_utimensat.hpp" -#else -# include "fs_base_utime_generic.hpp" -#endif - -#include "fs_base_stat.hpp" - -namespace fs -{ - static - inline - int - utime(const std::string &path_, - const struct stat &st_) - { - struct timespec times[2]; - - times[0] = *fs::stat_atime(&st_); - times[1] = *fs::stat_mtime(&st_); - - return fs::utime(AT_FDCWD,path_,times,0); - } - - static - inline - int - futime(const int fd_, - const struct stat &st_) - { - struct timespec ts[2]; - - ts[0] = *fs::stat_atime(&st_); - ts[1] = *fs::stat_mtime(&st_); - - return fs::futimens(fd_,ts); - } - - static - inline - int - lutime(const std::string &path_, - const struct timespec times_[2]) - { - return fs::utime(AT_FDCWD,path_,times_,AT_SYMLINK_NOFOLLOW); - } -} diff --git a/src/fs_base_utime_generic.hpp b/src/fs_base_utime_generic.hpp deleted file mode 100644 index b950d45c..00000000 --- a/src/fs_base_utime_generic.hpp +++ /dev/null @@ -1,313 +0,0 @@ -/* - 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. -*/ - -#pragma once - -#include "fs_base_futimesat.hpp" -#include "fs_base_stat.hpp" - -#include - -#include -#include -#include - -#ifndef UTIME_NOW -# define UTIME_NOW ((1l << 30) - 1l) -#endif - -#ifndef UTIME_OMIT -# define UTIME_OMIT ((1l << 30) - 2l) -#endif - -static -inline -bool -_can_call_lutimes(const int dirfd_, - const std::string &path_, - const int flags_) -{ - return ((flags_ == AT_SYMLINK_NOFOLLOW) && - ((dirfd_ == AT_FDCWD) || - (path_[0] == '/'))); -} - -static -inline -bool -_should_ignore(const struct timespec ts_[2]) -{ - return ((ts_ != NULL) && - (ts_[0].tv_nsec == UTIME_OMIT) && - (ts_[1].tv_nsec == UTIME_OMIT)); -} - -static -inline -bool -_should_be_set_to_now(const struct timespec ts_[2]) -{ - return ((ts_ == NULL) || - ((ts_[0].tv_nsec == UTIME_NOW) && - (ts_[1].tv_nsec == UTIME_NOW))); -} - -static -inline -bool -_timespec_invalid(const struct timespec &ts_) -{ - return (((ts_.tv_nsec < 0) || - (ts_.tv_nsec > 999999999)) && - ((ts_.tv_nsec != UTIME_NOW) && - (ts_.tv_nsec != UTIME_OMIT))); -} - -static -inline -bool -_timespec_invalid(const struct timespec ts_[2]) -{ - return ((ts_ != NULL) && - (_timespec_invalid(ts_[0]) || - _timespec_invalid(ts_[1]))); -} - -static -inline -bool -_flags_invalid(const int flags) -{ - return ((flags & ~AT_SYMLINK_NOFOLLOW) != 0); -} - -static -inline -bool -_any_timespec_is_utime_omit(const struct timespec ts_[2]) -{ - return ((ts_[0].tv_nsec == UTIME_OMIT) || - (ts_[1].tv_nsec == UTIME_OMIT)); -} - -static -inline -bool -_any_timespec_is_utime_now(const struct timespec ts_[2]) -{ - return ((ts_[0].tv_nsec == UTIME_NOW) || - (ts_[1].tv_nsec == UTIME_NOW)); -} - -static -inline -int -_set_utime_omit_to_current_value(const int dirfd, - const std::string &path, - const struct timespec ts_[2], - struct timeval tv[2], - const int flags) -{ - int rv; - struct stat st; - timespec *atime; - timespec *mtime; - - if(!_any_timespec_is_utime_omit(ts_)) - return 0; - - rv = ::fstatat(dirfd,path.c_str(),&st,flags); - if(rv == -1) - return -1; - - atime = fs::stat_atime(st); - mtime = fs::stat_mtime(st); - - if(ts_[0].tv_nsec == UTIME_OMIT) - TIMESPEC_TO_TIMEVAL(&tv[0],atime); - if(ts_[1].tv_nsec == UTIME_OMIT) - TIMESPEC_TO_TIMEVAL(&tv[1],mtime); - - return 0; -} - -static -inline -int -_set_utime_omit_to_current_value(const int fd, - const struct timespec ts_[2], - struct timeval tv[2]) -{ - int rv; - struct stat st; - timespec *atime; - timespec *mtime; - - if(!_any_timespec_is_utime_omit(ts_)) - return 0; - - rv = ::fstat(fd,&st); - if(rv == -1) - return -1; - - atime = fs::stat_atime(st); - mtime = fs::stat_mtime(st); - - if(ts_[0].tv_nsec == UTIME_OMIT) - TIMESPEC_TO_TIMEVAL(&tv[0],atime); - if(ts_[1].tv_nsec == UTIME_OMIT) - TIMESPEC_TO_TIMEVAL(&tv[1],mtime); - - return 0; -} - -static -inline -int -_set_utime_now_to_now(const struct timespec ts_[2], - struct timeval tv[2]) -{ - int rv; - struct timeval now; - - if(_any_timespec_is_utime_now(ts_)) - return 0; - - rv = ::gettimeofday(&now,NULL); - if(rv == -1) - return -1; - - if(ts_[0].tv_nsec == UTIME_NOW) - tv[0] = now; - if(ts_[1].tv_nsec == UTIME_NOW) - tv[1] = now; - - return 0; -} - -static -inline -int -_convert_timespec_to_timeval(const int dirfd, - const std::string &path, - const struct timespec ts_[2], - struct timeval tv[2], - struct timeval *&tvp, - const int flags) -{ - int rv; - - if(_should_be_set_to_now(ts_)) - return (tvp=NULL,0); - - TIMESPEC_TO_TIMEVAL(&tv[0],&ts_[0]); - TIMESPEC_TO_TIMEVAL(&tv[1],&ts_[1]); - - rv = _set_utime_omit_to_current_value(dirfd,path,ts_,tv,flags); - if(rv == -1) - return -1; - - rv = _set_utime_now_to_now(ts_,tv); - if(rv == -1) - return -1; - - return (tvp=tv,0); -} - -static -inline -int -_convert_timespec_to_timeval(const int fd, - const struct timespec ts_[2], - struct timeval tv[2], - struct timeval *&tvp) -{ - int rv; - - if(_should_be_set_to_now(ts_)) - return (tvp=NULL,0); - - TIMESPEC_TO_TIMEVAL(&tv[0],&ts_[0]); - TIMESPEC_TO_TIMEVAL(&tv[1],&ts_[1]); - - rv = _set_utime_omit_to_current_value(fd,ts_,tv); - if(rv == -1) - return -1; - - rv = _set_utime_now_to_now(ts_,tv); - if(rv == -1) - return -1; - - return (tvp=tv,0); -} - -namespace fs -{ - static - inline - int - utime(const int dirfd, - const std::string &path, - const struct timespec ts_[2], - const int flags) - { - int rv; - struct timeval tv[2]; - struct timeval *tvp; - - if(_flags_invalid(flags)) - return (errno=EINVAL,-1); - if(_timespec_invalid(ts_)) - return (errno=EINVAL,-1); - if(_should_ignore(ts_)) - return 0; - - rv = _convert_timespec_to_timeval(dirfd,path,ts_,tv,tvp,flags); - if(rv == -1) - return -1; - - if((flags & AT_SYMLINK_NOFOLLOW) == 0) - return fs::futimesat(dirfd,path.c_str(),tvp); - if(_can_call_lutimes(dirfd,path,flags)) - return ::lutimes(path.c_str(),tvp); - - return (errno=ENOTSUP,-1); - } - - static - inline - int - futimens(const int fd_, - const struct timespec ts_[2]) - { - int rv; - struct timeval tv[2]; - struct timeval *tvp; - - if(_timespec_invalid(ts_)) - return (errno=EINVAL,-1); - if(_should_ignore(ts_)) - return 0; - - rv = _convert_timespec_to_timeval(fd_,ts_,tv,tvp); - if(rv == -1) - return -1; - - return ::futimes(fd_,tvp); - } -} diff --git a/src/fs_clonefile.cpp b/src/fs_clonefile.cpp index 1064d9fa..6dabde05 100644 --- a/src/fs_clonefile.cpp +++ b/src/fs_clonefile.cpp @@ -14,52 +14,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "errno.hpp" +#include "fs_fstat.hpp" +#include "fs_copydata.hpp" #include "fs_attr.hpp" -#include "fs_base_chmod.hpp" -#include "fs_base_chown.hpp" -#include "fs_base_fadvise.hpp" -#include "fs_base_fallocate.hpp" -#include "fs_base_fchmod.hpp" -#include "fs_base_fchown.hpp" -#include "fs_base_ftruncate.hpp" -#include "fs_base_stat.hpp" -#include "fs_base_utime.hpp" -#include "fs_copy_file_range.hpp" -#include "fs_copydata_copy_file_range.hpp" -#include "fs_copydata_readwrite.hpp" -#include "fs_ficlone.hpp" -#include "fs_sendfile.hpp" #include "fs_xattr.hpp" +#include "fs_fchown.hpp" +#include "fs_fchmod.hpp" +#include "fs_futimens.hpp" namespace l { - static - int - copydata(const int src_fd_, - const int dst_fd_, - const size_t count_) - { - int rv; - - rv = fs::ftruncate(dst_fd_,count_); - if(rv == -1) - return -1; - - rv = fs::ficlone(src_fd_,dst_fd_); - if(rv != -1) - return rv; - - fs::fadvise_willneed(src_fd_,0,count_); - fs::fadvise_sequential(src_fd_,0,count_); - - rv = fs::copydata_copy_file_range(src_fd_,dst_fd_); - if(rv != -1) - return rv; - - return fs::copydata_readwrite(src_fd_,dst_fd_); - } - static bool ignorable_error(const int err_) @@ -91,7 +55,7 @@ namespace fs if(rv == -1) return -1; - rv = l::copydata(src_fd_,dst_fd_,src_st.st_size); + rv = fs::copydata(src_fd_,dst_fd_,src_st.st_size); if(rv == -1) return -1; @@ -111,7 +75,7 @@ namespace fs if(rv == -1) return -1; - rv = fs::futime(dst_fd_,src_st); + rv = fs::futimens(dst_fd_,src_st); if(rv == -1) return -1; diff --git a/src/fs_clonepath.cpp b/src/fs_clonepath.cpp index 8966f00d..ec71344b 100644 --- a/src/fs_clonepath.cpp +++ b/src/fs_clonepath.cpp @@ -18,33 +18,35 @@ #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_utime.hpp" #include "fs_clonepath.hpp" +#include "fs_lchown.hpp" +#include "fs_lstat.hpp" +#include "fs_lutimens.hpp" +#include "fs_mkdir.hpp" #include "fs_path.hpp" #include "fs_xattr.hpp" #include "ugid.hpp" using std::string; -static -bool -ignorable_error(const int err) +namespace l { - switch(err) - { - case ENOTTY: - case ENOTSUP: + static + bool + ignorable_error(const int err_) + { + switch(err_) + { + case ENOTTY: + case ENOTSUP: #if ENOTSUP != EOPNOTSUPP - case EOPNOTSUPP: + case EOPNOTSUPP: #endif - return true; - } + return true; + } - return false; + return false; + } } namespace fs @@ -54,12 +56,12 @@ namespace fs The directories which already exist are left alone. The new directories have metadata set to match the original if possible. Optionally ignore errors on metadata copies. - */ + */ int - clonepath(const string &fromsrc, - const string &tosrc, - const char *relative, - const bool return_metadata_errors) + clonepath(const string &fromsrc_, + const string &tosrc_, + const char *relative_, + const bool return_metadata_errors_) { int rv; struct stat st; @@ -67,25 +69,25 @@ namespace fs string frompath; string dirname; - if((relative == NULL) || (relative[0] == '\0')) + if((relative_ == NULL) || (relative_[0] == '\0')) return 0; - dirname = fs::path::dirname(relative); + dirname = fs::path::dirname(relative_); if(!dirname.empty()) { - rv = fs::clonepath(fromsrc,tosrc,dirname); + rv = fs::clonepath(fromsrc_,tosrc_,dirname,return_metadata_errors_); if(rv == -1) return -1; } - frompath = fs::path::make(fromsrc,relative); - rv = fs::stat(frompath,&st); + frompath = fs::path::make(fromsrc_,relative_); + rv = fs::lstat(frompath,&st); if(rv == -1) return -1; else if(!S_ISDIR(st.st_mode)) return (errno=ENOTDIR,-1); - topath = fs::path::make(tosrc,relative); + topath = fs::path::make(tosrc_,relative_); rv = fs::mkdir(topath,st.st_mode); if(rv == -1) { @@ -97,58 +99,61 @@ namespace fs // it may not support it... it's fine... rv = fs::attr::copy(frompath,topath); - if(return_metadata_errors && (rv == -1) && !ignorable_error(errno)) + if(return_metadata_errors_ && (rv == -1) && !l::ignorable_error(errno)) return -1; // it may not support it... it's fine... rv = fs::xattr::copy(frompath,topath); - if(return_metadata_errors && (rv == -1) && !ignorable_error(errno)) + if(return_metadata_errors_ && (rv == -1) && !l::ignorable_error(errno)) return -1; rv = fs::lchown_check_on_error(topath,st); - if(return_metadata_errors && (rv == -1)) + if(return_metadata_errors_ && (rv == -1)) return -1; - rv = fs::utime(topath,st); - if(return_metadata_errors && (rv == -1)) + rv = fs::lutimens(topath,st); + if(return_metadata_errors_ && (rv == -1)) return -1; return 0; } int - clonepath(const string &from, - const string &to, - const string &relative, - const bool return_metadata_errors) + clonepath(const string &from_, + const string &to_, + const string &relative_, + const bool return_metadata_errors_) { - return fs::clonepath(from,to,relative.c_str(),return_metadata_errors); + return fs::clonepath(from_, + to_, + relative_.c_str(), + return_metadata_errors_); } int - clonepath_as_root(const string &from, - const string &to, - const char *relative, - const bool return_metadata_errors) + clonepath_as_root(const string &from_, + const string &to_, + const char *relative_, + const bool return_metadata_errors_) { - if((relative == NULL) || (relative[0] == '\0')) + if((relative_ == NULL) || (relative_[0] == '\0')) return 0; - if(from == to) + if(from_ == to_) return 0; { const ugid::SetRootGuard ugidGuard; - return fs::clonepath(from,to,relative,return_metadata_errors); + return fs::clonepath(from_,to_,relative_,return_metadata_errors_); } } int - clonepath_as_root(const string &from, - const string &to, - const string &relative, - const bool return_metadata_errors) + clonepath_as_root(const string &from_, + const string &to_, + const string &relative_, + const bool return_metadata_errors_) { - return fs::clonepath_as_root(from,to,relative.c_str(),return_metadata_errors); + return fs::clonepath_as_root(from_,to_,relative_.c_str(),return_metadata_errors_); } } diff --git a/src/fs_base_close.hpp b/src/fs_close.hpp similarity index 100% rename from src/fs_base_close.hpp rename to src/fs_close.hpp diff --git a/src/fs_base_closedir.hpp b/src/fs_closedir.hpp similarity index 100% rename from src/fs_base_closedir.hpp rename to src/fs_closedir.hpp diff --git a/src/fs_copydata.cpp b/src/fs_copydata.cpp new file mode 100644 index 00000000..979b31b7 --- /dev/null +++ b/src/fs_copydata.cpp @@ -0,0 +1,53 @@ +/* + ISC License + + Copyright (c) 2020, 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 "fs_copydata_copy_file_range.hpp" +#include "fs_copydata_readwrite.hpp" +#include "fs_fadvise.hpp" +#include "fs_ficlone.hpp" +#include "fs_ftruncate.hpp" + +#include + +namespace fs +{ + int + copydata(const int src_fd_, + const int dst_fd_, + const size_t count_) + { + int rv; + + rv = fs::ftruncate(dst_fd_,count_); + if(rv == -1) + return -1; + + rv = fs::ficlone(src_fd_,dst_fd_); + if(rv != -1) + return rv; + + fs::fadvise_willneed(src_fd_,0,count_); + fs::fadvise_sequential(src_fd_,0,count_); + + rv = fs::copydata_copy_file_range(src_fd_,dst_fd_); + if(rv != -1) + return rv; + + return fs::copydata_readwrite(src_fd_,dst_fd_); + } +} diff --git a/src/fs_copydata.hpp b/src/fs_copydata.hpp new file mode 100644 index 00000000..48e0784d --- /dev/null +++ b/src/fs_copydata.hpp @@ -0,0 +1,29 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include + +namespace fs +{ + int + copydata(const int src_fd, + const int dst_fd, + const size_t count); +} diff --git a/src/fs_copydata_copy_file_range.cpp b/src/fs_copydata_copy_file_range.cpp index 83c6b1d4..f8e7c388 100644 --- a/src/fs_copydata_copy_file_range.cpp +++ b/src/fs_copydata_copy_file_range.cpp @@ -15,8 +15,8 @@ */ #include "errno.hpp" -#include "fs_base_stat.hpp" #include "fs_copy_file_range.hpp" +#include "fs_fstat.hpp" #include diff --git a/src/fs_copydata_readwrite.cpp b/src/fs_copydata_readwrite.cpp index fc8f361f..c119585d 100644 --- a/src/fs_copydata_readwrite.cpp +++ b/src/fs_copydata_readwrite.cpp @@ -15,10 +15,10 @@ */ #include "errno.hpp" -#include "fs_base_stat.hpp" -#include "fs_base_lseek.hpp" -#include "fs_base_read.hpp" -#include "fs_base_write.hpp" +#include "fs_fstat.hpp" +#include "fs_lseek.hpp" +#include "fs_read.hpp" +#include "fs_write.hpp" #include diff --git a/src/fs_cow.cpp b/src/fs_cow.cpp index cc9be43b..63379fe5 100644 --- a/src/fs_cow.cpp +++ b/src/fs_cow.cpp @@ -16,18 +16,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "errno.hpp" #include "fs_clonefile.hpp" +#include "fs_close.hpp" +#include "fs_lstat.hpp" #include "fs_mktemp.hpp" - -#include "fs_base_close.hpp" -#include "fs_base_open.hpp" -#include "fs_base_rename.hpp" -#include "fs_base_stat.hpp" -#include "fs_base_unlink.hpp" +#include "fs_open.hpp" +#include "fs_rename.hpp" +#include "fs_unlink.hpp" #include -#include #include #include #include @@ -35,27 +34,29 @@ using std::string; -static -int -cleanup_on_error(const int src_fd_, - const int dst_fd_ = -1, - const string &dst_fullpath_ = string()) +namespace l { - int error = errno; + static + int + cleanup_on_error(const int src_fd_, + const int dst_fd_ = -1, + const string &dst_fullpath_ = string()) + { + int error = errno; - if(src_fd_ >= 0) - fs::close(src_fd_); - if(dst_fd_ >= 0) - fs::close(dst_fd_); - if(!dst_fullpath_.empty()) - fs::unlink(dst_fullpath_); + if(src_fd_ >= 0) + fs::close(src_fd_); + if(dst_fd_ >= 0) + fs::close(dst_fd_); + if(!dst_fullpath_.empty()) + fs::unlink(dst_fullpath_); - errno = error; + errno = error; - return -1; + return -1; + } } - namespace fs { namespace cow @@ -91,7 +92,7 @@ namespace fs int rv; struct stat st; - if(!is_eligible(flags_)) + if(!fs::cow::is_eligible(flags_)) return false; rv = fs::lstat(fullpath_,&st); @@ -117,15 +118,15 @@ namespace fs dst_fd = fs::mktemp(&dst_fullpath,O_WRONLY); if(dst_fd == -1) - return cleanup_on_error(src_fd); + return l::cleanup_on_error(src_fd); rv = fs::clonefile(src_fd,dst_fd); if(rv == -1) - return cleanup_on_error(src_fd,dst_fd,dst_fullpath); + return l::cleanup_on_error(src_fd,dst_fd,dst_fullpath); rv = fs::rename(dst_fullpath,src_fullpath_); if(rv == -1) - return cleanup_on_error(src_fd,dst_fd,dst_fullpath); + return l::cleanup_on_error(src_fd,dst_fd,dst_fullpath); fs::close(src_fd); fs::close(dst_fd); diff --git a/src/fs_devid.hpp b/src/fs_devid.hpp index cf897ce6..2f9bde05 100644 --- a/src/fs_devid.hpp +++ b/src/fs_devid.hpp @@ -18,9 +18,7 @@ #pragma once -#include -#include -#include +#include "fs_fstat.hpp" namespace fs { @@ -32,7 +30,7 @@ namespace fs int rv; struct stat st; - rv = ::fstat(fd_,&st); + rv = fs::fstat(fd_,&st); if(rv == -1) return -1; diff --git a/src/fs_base_dirfd.hpp b/src/fs_dirfd.hpp similarity index 100% rename from src/fs_base_dirfd.hpp rename to src/fs_dirfd.hpp diff --git a/src/fs_base_dup.hpp b/src/fs_dup.hpp similarity index 100% rename from src/fs_base_dup.hpp rename to src/fs_dup.hpp diff --git a/src/fs_eaccess.hpp b/src/fs_eaccess.hpp new file mode 100644 index 00000000..f661566a --- /dev/null +++ b/src/fs_eaccess.hpp @@ -0,0 +1,42 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include "fs_faccessat.hpp" + +namespace fs +{ + static + inline + int + eaccess(const char *path_, + const int mode_) + { + return fs::faccessat(AT_FDCWD,path_,mode_,AT_EACCESS); + } + + static + inline + int + eaccess(const std::string &path_, + const int mode_) + { + return fs::eaccess(path_.c_str(),mode_); + } +} diff --git a/src/fs_exists.hpp b/src/fs_exists.hpp index 1fe051ae..808bc8b1 100644 --- a/src/fs_exists.hpp +++ b/src/fs_exists.hpp @@ -18,7 +18,7 @@ #pragma once -#include "fs_base_stat.hpp" +#include "fs_lstat.hpp" #include "fs_path.hpp" #include diff --git a/src/fs_base_utime_utimensat.hpp b/src/fs_faccessat.hpp similarity index 69% rename from src/fs_base_utime_utimensat.hpp rename to src/fs_faccessat.hpp index a49ba8b4..02729b87 100644 --- a/src/fs_base_utime_utimensat.hpp +++ b/src/fs_faccessat.hpp @@ -21,27 +21,29 @@ #include #include -#include +#include namespace fs { static inline int - utime(const int dirfd_, - const std::string &path_, - const struct timespec times_[2], - const int flags_) + faccessat(const int dirfd_, + const char *path_, + const int mode_, + const int flags_) { - return ::utimensat(dirfd_,path_.c_str(),times_,flags_); + return ::faccessat(dirfd_,path_,mode_,flags_); } static inline int - futimens(const int fd_, - const struct timespec ts_[2]) + faccessat(const int dirfd_, + const std::string &path_, + const int mode_, + const int flags_) { - return ::futimens(fd_,ts_); + return fs::faccessat(dirfd_,path_.c_str(),mode_,flags_); } } diff --git a/src/fs_base_fadvise.cpp b/src/fs_fadvise.cpp similarity index 68% rename from src/fs_base_fadvise.cpp rename to src/fs_fadvise.cpp index 8b5248d9..4c093aa5 100644 --- a/src/fs_base_fadvise.cpp +++ b/src/fs_fadvise.cpp @@ -17,9 +17,9 @@ #include #if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L -# include "fs_base_fadvise_posix.icpp" +# include "fs_fadvise_posix.icpp" #else -# include "fs_base_fadvise_unsupported.icpp" +# include "fs_fadvise_unsupported.icpp" #endif #ifndef POSIX_FADV_NORMAL @@ -49,26 +49,26 @@ namespace fs { int - fadvise_dontneed(const int fd, - const off_t offset, - const off_t len) + fadvise_dontneed(const int fd_, + const off_t offset_, + const off_t len_) { - return fs::fadvise(fd,offset,len,POSIX_FADV_DONTNEED); + return fs::fadvise(fd_,offset_,len_,POSIX_FADV_DONTNEED); } int - fadvise_willneed(const int fd, - const off_t offset, - const off_t len) + fadvise_willneed(const int fd_, + const off_t offset_, + const off_t len_) { - return fs::fadvise(fd,offset,len,POSIX_FADV_WILLNEED); + return fs::fadvise(fd_,offset_,len_,POSIX_FADV_WILLNEED); } int - fadvise_sequential(const int fd, - const off_t offset, - const off_t len) + fadvise_sequential(const int fd_, + const off_t offset_, + const off_t len_) { - return fs::fadvise(fd,offset,len,POSIX_FADV_SEQUENTIAL); + return fs::fadvise(fd_,offset_,len_,POSIX_FADV_SEQUENTIAL); } } diff --git a/src/fs_base_fadvise.hpp b/src/fs_fadvise.hpp similarity index 98% rename from src/fs_base_fadvise.hpp rename to src/fs_fadvise.hpp index 56335082..96fa8360 100644 --- a/src/fs_base_fadvise.hpp +++ b/src/fs_fadvise.hpp @@ -16,6 +16,8 @@ #pragma once +#include + namespace fs { int diff --git a/src/fs_base_fadvise_posix.icpp b/src/fs_fadvise_posix.icpp similarity index 82% rename from src/fs_base_fadvise_posix.icpp rename to src/fs_fadvise_posix.icpp index d1b115eb..a51e5de5 100644 --- a/src/fs_base_fadvise_posix.icpp +++ b/src/fs_fadvise_posix.icpp @@ -16,17 +16,15 @@ #include -#include "errno.hpp" - namespace fs { static int - fadvise(const int fd, - const off_t offset, - const off_t len, - const int advice) + fadvise(const int fd_, + const off_t offset_, + const off_t len_, + const int advice_) { - return ::posix_fadvise(fd,offset,len,advice); + return ::posix_fadvise(fd_,offset_,len_,advice_); } } diff --git a/src/fs_base_fadvise_unsupported.icpp b/src/fs_fadvise_unsupported.icpp similarity index 88% rename from src/fs_base_fadvise_unsupported.icpp rename to src/fs_fadvise_unsupported.icpp index 544cbd3a..b25aebcb 100644 --- a/src/fs_base_fadvise_unsupported.icpp +++ b/src/fs_fadvise_unsupported.icpp @@ -20,10 +20,10 @@ namespace fs { static int - fadvise(const int fd, - const off_t offset, - const off_t len, - const int advice) + fadvise(const int fd_, + const off_t offset_, + const off_t len_, + const int advice_) { return (errno=EOPNOTSUPP,-1); } diff --git a/src/fs_base_fallocate.cpp b/src/fs_fallocate.cpp similarity index 84% rename from src/fs_base_fallocate.cpp rename to src/fs_fallocate.cpp index 500ec090..9bd15e9e 100644 --- a/src/fs_base_fallocate.cpp +++ b/src/fs_fallocate.cpp @@ -17,11 +17,11 @@ #include #ifdef __linux__ -# include "fs_base_fallocate_linux.icpp" +# include "fs_fallocate_linux.icpp" #elif _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L -# include "fs_base_fallocate_posix.icpp" +# include "fs_fallocate_posix.icpp" #elif __APPLE__ -# include "fs_base_fallocate_osx.icpp" +# include "fs_fallocate_osx.icpp" #else -# include "fs_base_fallocate_unsupported.icpp" +# include "fs_fallocate_unsupported.icpp" #endif diff --git a/src/fs_base_fallocate.hpp b/src/fs_fallocate.hpp similarity index 100% rename from src/fs_base_fallocate.hpp rename to src/fs_fallocate.hpp diff --git a/src/fs_base_fallocate_linux.icpp b/src/fs_fallocate_linux.icpp similarity index 81% rename from src/fs_base_fallocate_linux.icpp rename to src/fs_fallocate_linux.icpp index 84e454a1..ae274eeb 100644 --- a/src/fs_base_fallocate_linux.icpp +++ b/src/fs_fallocate_linux.icpp @@ -16,16 +16,14 @@ #include -#include "errno.hpp" - namespace fs { int - fallocate(const int fd, - const int mode, - const off_t offset, - const off_t len) + fallocate(const int fd_, + const int mode_, + const off_t offset_, + const off_t len_) { - return ::fallocate(fd,mode,offset,len); + return ::fallocate(fd_,mode_,offset_,len_); } } diff --git a/src/fs_base_fallocate_osx.icpp b/src/fs_fallocate_osx.icpp similarity index 58% rename from src/fs_base_fallocate_osx.icpp rename to src/fs_fallocate_osx.icpp index ae3a06eb..d98c2795 100644 --- a/src/fs_base_fallocate_osx.icpp +++ b/src/fs_fallocate_osx.icpp @@ -19,39 +19,42 @@ #include "errno.hpp" -static -int -_fallocate_core(const int fd, - const off_t offset, - const off_t len) +namespace l { - int rv; - fstore_t store = {F_ALLOCATECONTIG,F_PEOFPOSMODE,offset,len,0}; + static + int + fallocate_core(const int fd_, + const off_t offset_, + const off_t len_) + { + int rv; + fstore_t store = {F_ALLOCATECONTIG,F_PEOFPOSMODE,offset,len,0}; - rv = ::fcntl(fd,F_PREALLOCATE,&store); - if(rv == -1) - { - store.fst_flags = F_ALLOCATEALL; - rv = ::fcntl(fd,F_PREALLOCATE,&store); - } + rv = ::fcntl(fd_,F_PREALLOCATE,&store); + if(rv == -1) + { + store.fst_flags = F_ALLOCATEALL; + rv = ::fcntl(fd_,F_PREALLOCATE,&store); + } - if(rv == -1) - return rv; + if(rv == -1) + return rv; - return ::ftruncate(fd,(offset+len)); + return ::ftruncate(fd_,(offset_+len_)); + } } namespace fs { int - fallocate(const int fd, - const int mode, - const off_t offset, - const off_t len) + fallocate(const int fd_, + const int mode_, + const off_t offset_, + const off_t len_) { - if(mode) + if(mode_) return (errno=EOPNOTSUPP,-1); - return ::_fallocate_core(fd,offset,len); + return l::fallocate_core(fd_,offset_,len_); } } diff --git a/src/fs_base_fallocate_posix.icpp b/src/fs_fallocate_posix.icpp similarity index 79% rename from src/fs_base_fallocate_posix.icpp rename to src/fs_fallocate_posix.icpp index 4af1183e..17f99e95 100644 --- a/src/fs_base_fallocate_posix.icpp +++ b/src/fs_fallocate_posix.icpp @@ -14,20 +14,21 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include - #include "errno.hpp" +#include + namespace fs { int - fallocate(const int fd, - const int mode, - const off_t offset, - const off_t len) + fallocate(const int fd_, + const int mode_, + const off_t offset_, + const off_t len_) { - return (mode ? - (errno=EOPNOTSUPP,-1) : - (::posix_fallocate(fd,offset,len))); + if(mode_) + return (errno=EOPNOTSUPP,-1); + + return ::posix_fallocate(fd_,offset_,len_); } } diff --git a/src/fs_base_fallocate_unsupported.icpp b/src/fs_fallocate_unsupported.icpp similarity index 87% rename from src/fs_base_fallocate_unsupported.icpp rename to src/fs_fallocate_unsupported.icpp index e5cae483..9c913e84 100644 --- a/src/fs_base_fallocate_unsupported.icpp +++ b/src/fs_fallocate_unsupported.icpp @@ -19,10 +19,10 @@ namespace fs { int - fallocate(const int fd, - const int mode, - const off_t offset, - const off_t len) + fallocate(const int fd_, + const int mode_, + const off_t offset_, + const off_t len_) { return (errno=EOPNOTSUPP,-1); } diff --git a/src/fs_base_fchmod.hpp b/src/fs_fchmod.hpp similarity index 98% rename from src/fs_base_fchmod.hpp rename to src/fs_fchmod.hpp index 3780d28e..5300d43d 100644 --- a/src/fs_base_fchmod.hpp +++ b/src/fs_fchmod.hpp @@ -18,7 +18,7 @@ #pragma once -#include "fs_base_stat.hpp" +#include "fs_fstat.hpp" #include diff --git a/src/fs_fchmodat.hpp b/src/fs_fchmodat.hpp new file mode 100644 index 00000000..209efbc6 --- /dev/null +++ b/src/fs_fchmodat.hpp @@ -0,0 +1,49 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include + +#include +#include + +namespace fs +{ + static + inline + int + fchmodat(const int dirfd_, + const char *pathname_, + const mode_t mode_, + const int flags_) + { + return ::fchmodat(dirfd_,pathname_,mode_,flags_); + } + + static + inline + int + fchmodat(const int dirfd_, + const std::string &pathname_, + const mode_t mode_, + const int flags_) + { + return fs::fchmodat(dirfd_,pathname_.c_str(),mode_,flags_); + } +} diff --git a/src/fs_base_fchown.hpp b/src/fs_fchown.hpp similarity index 97% rename from src/fs_base_fchown.hpp rename to src/fs_fchown.hpp index be2303e9..1b879e07 100644 --- a/src/fs_base_fchown.hpp +++ b/src/fs_fchown.hpp @@ -18,7 +18,8 @@ #pragma once -#include "fs_base_stat.hpp" +#include "errno.hpp" +#include "fs_fstat.hpp" #include #include diff --git a/src/fs_base_fsync.hpp b/src/fs_fdatasync.hpp similarity index 93% rename from src/fs_base_fsync.hpp rename to src/fs_fdatasync.hpp index e2fd1c0e..7b7fa72f 100644 --- a/src/fs_base_fsync.hpp +++ b/src/fs_fdatasync.hpp @@ -28,14 +28,6 @@ namespace fs { - static - inline - int - fsync(const int fd_) - { - return ::fsync(fd_); - } - static inline int diff --git a/src/fs_fgetxattr.hpp b/src/fs_fgetxattr.hpp new file mode 100644 index 00000000..57541eb0 --- /dev/null +++ b/src/fs_fgetxattr.hpp @@ -0,0 +1,61 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include "errno.hpp" +#include "xattr.hpp" + +#include + +#include + +namespace fs +{ + static + inline + int + fgetxattr(const int fd_, + const char *attrname_, + void *value_, + const size_t size_) + { +#ifdef USE_XATTR + return ::fgetxattr(fd_, + attrname_, + value_, + size_); +#else + return (errno=ENOTSUP,-1); +#endif + } + + static + inline + int + fgetxattr(const int fd_, + const std::string &attrname_, + void *value_, + const size_t size_) + { + return fs::fgetxattr(fd_, + attrname_.c_str(), + value_, + size_); + } +} diff --git a/src/fs_ficlone_linux.icpp b/src/fs_ficlone_linux.icpp index dfd8f58b..a36196fd 100644 --- a/src/fs_ficlone_linux.icpp +++ b/src/fs_ficlone_linux.icpp @@ -17,7 +17,7 @@ */ #include "errno.hpp" -#include "fs_base_ioctl.hpp" +#include "fs_ioctl.hpp" #include diff --git a/src/fs_file_size.cpp b/src/fs_file_size.cpp index b757f057..d06b7007 100644 --- a/src/fs_file_size.cpp +++ b/src/fs_file_size.cpp @@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "fs_base_stat.hpp" +#include "fs_fstat.hpp" #include diff --git a/src/fs_findonfs.cpp b/src/fs_findonfs.cpp index 26358797..ce2bc1ae 100644 --- a/src/fs_findonfs.cpp +++ b/src/fs_findonfs.cpp @@ -18,7 +18,8 @@ #include "branch.hpp" #include "errno.hpp" -#include "fs_base_stat.hpp" +#include "fs_fstat.hpp" +#include "fs_lstat.hpp" #include "fs_path.hpp" #include diff --git a/src/fs_flistxattr.hpp b/src/fs_flistxattr.hpp new file mode 100644 index 00000000..cbfa3425 --- /dev/null +++ b/src/fs_flistxattr.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. +*/ + +#pragma once + +#include "errno.hpp" +#include "xattr.hpp" + +#include + +namespace fs +{ + static + inline + int + flistxattr(const int fd_, + char *list_, + const size_t size_) + { +#ifdef USE_XATTR + return ::flistxattr(fd_,list_,size_); +#else + return (errno=ENOTSUP,-1); +#endif + } +} diff --git a/src/fs_base_flock.hpp b/src/fs_flock.hpp similarity index 100% rename from src/fs_base_flock.hpp rename to src/fs_flock.hpp diff --git a/src/fs_fsetxattr.hpp b/src/fs_fsetxattr.hpp new file mode 100644 index 00000000..d2cfb023 --- /dev/null +++ b/src/fs_fsetxattr.hpp @@ -0,0 +1,61 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include "errno.hpp" +#include "xattr.hpp" + +#include + +#include + +namespace fs +{ + static + inline + int + fsetxattr(const int fd_, + const char *name_, + const void *value_, + const size_t size_, + const int flags_) + { +#ifdef USE_XATTR + return ::fsetxattr(fd_,name_,value_,size_,flags_); +#else + return (errno=ENOTSUP,-1); +#endif + } + + static + inline + int + fsetxattr(const int fd_, + const std::string &name_, + const void *value_, + const size_t size_, + const int flags_) + { + return fs::fsetxattr(fd_, + name_.c_str(), + value_, + size_, + flags_); + } +} diff --git a/src/fs_fstat.hpp b/src/fs_fstat.hpp new file mode 100644 index 00000000..233d72fb --- /dev/null +++ b/src/fs_fstat.hpp @@ -0,0 +1,36 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + + +#pragma once + +#include +#include +#include + +namespace fs +{ + static + inline + int + fstat(const int fd_, + struct stat *st_) + { + return ::fstat(fd_,st_); + } +} diff --git a/src/fs_base_fstatat.hpp b/src/fs_fstatat.hpp similarity index 100% rename from src/fs_base_fstatat.hpp rename to src/fs_fstatat.hpp diff --git a/src/fs_fsync.hpp b/src/fs_fsync.hpp new file mode 100644 index 00000000..c91e0181 --- /dev/null +++ b/src/fs_fsync.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. +*/ + +#pragma once + +#include + +namespace fs +{ + static + inline + int + fsync(const int fd_) + { + return ::fsync(fd_); + } +} diff --git a/src/fs_base_ftruncate.hpp b/src/fs_ftruncate.hpp similarity index 100% rename from src/fs_base_ftruncate.hpp rename to src/fs_ftruncate.hpp diff --git a/src/fs_futimens.hpp b/src/fs_futimens.hpp new file mode 100644 index 00000000..c86e279b --- /dev/null +++ b/src/fs_futimens.hpp @@ -0,0 +1,48 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include "fs_stat_utils.hpp" + +#include + +#ifdef __linux__ +# include "fs_futimens_linux.hpp" +#elif __FreeBSD__ >= 11 +# include "fs_futimens_freebsd_11.hpp" +#else +# include "fs_futimens_generic.hpp" +#endif + +namespace fs +{ + static + inline + int + futimens(const int fd_, + const struct stat &st_) + { + struct timespec ts[2]; + + ts[0] = *fs::stat_atime(&st_); + ts[1] = *fs::stat_mtime(&st_); + + return fs::futimens(fd_,ts); + } +} diff --git a/src/fs_futimens_freebsd_11.hpp b/src/fs_futimens_freebsd_11.hpp new file mode 100644 index 00000000..745bedee --- /dev/null +++ b/src/fs_futimens_freebsd_11.hpp @@ -0,0 +1,33 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include + +namespace fs +{ + static + inline + int + futimens(const int fd_, + const struct timespec ts_[2]) + { + return ::futimens(fd_,ts_); + } +} diff --git a/src/fs_futimens_generic.hpp b/src/fs_futimens_generic.hpp new file mode 100644 index 00000000..d6124151 --- /dev/null +++ b/src/fs_futimens_generic.hpp @@ -0,0 +1,283 @@ +/* + ISC License + + Copyright (c) 2020, 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 "fs_futimesat.hpp" +#include "fs_stat_utils.hpp" + +#include + +#include +#include +#include + +#ifndef UTIME_NOW +# define UTIME_NOW ((1l << 30) - 1l) +#endif + +#ifndef UTIME_OMIT +# define UTIME_OMIT ((1l << 30) - 2l) +#endif + +namespace l +{ + static + inline + bool + can_call_lutimes(const int dirfd_, + const std::string &path_, + const int flags_) + { + return ((flags_ == AT_SYMLINK_NOFOLLOW) && + ((dirfd_ == AT_FDCWD) || + (path_[0] == '/'))); + } + + static + inline + bool + should_ignore(const struct timespec ts_[2]) + { + return ((ts_ != NULL) && + (ts_[0].tv_nsec == UTIME_OMIT) && + (ts_[1].tv_nsec == UTIME_OMIT)); + } + + static + inline + bool + should_be_set_to_now(const struct timespec ts_[2]) + { + return ((ts_ == NULL) || + ((ts_[0].tv_nsec == UTIME_NOW) && + (ts_[1].tv_nsec == UTIME_NOW))); + } + + static + inline + bool + timespec_invalid(const struct timespec &ts_) + { + return (((ts_.tv_nsec < 0) || + (ts_.tv_nsec > 999999999)) && + ((ts_.tv_nsec != UTIME_NOW) && + (ts_.tv_nsec != UTIME_OMIT))); + } + + static + inline + bool + timespec_invalid(const struct timespec ts_[2]) + { + return ((ts_ != NULL) && + (l::timespec_invalid(ts_[0]) || + l::timespec_invalid(ts_[1]))); + } + + static + inline + bool + flags_invalid(const int flags_) + { + return ((flags_ & ~AT_SYMLINK_NOFOLLOW) != 0); + } + + static + inline + bool + any_timespec_is_utime_omit(const struct timespec ts_[2]) + { + return ((ts_[0].tv_nsec == UTIME_OMIT) || + (ts_[1].tv_nsec == UTIME_OMIT)); + } + + static + inline + bool + any_timespec_is_utime_now(const struct timespec ts_[2]) + { + return ((ts_[0].tv_nsec == UTIME_NOW) || + (ts_[1].tv_nsec == UTIME_NOW)); + } + + static + inline + int + set_utime_omit_to_current_value(const int dirfd_, + const std::string &path_, + const struct timespec ts_[2], + struct timeval tv_[2], + const int flags_) + { + int rv; + struct stat st; + timespec *atime; + timespec *mtime; + + if(!l::any_timespec_is_utime_omit(ts_)) + return 0; + + rv = fs::fstatat(dirfd_,path_,&st,flags_); + if(rv == -1) + return -1; + + atime = fs::stat_atime(st); + mtime = fs::stat_mtime(st); + + if(ts_[0].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv[0],atime); + if(ts_[1].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv[1],mtime); + + return 0; + } + + static + inline + int + set_utime_omit_to_current_value(const int fd_, + const struct timespec ts_[2], + struct timeval tv_[2]) + { + int rv; + struct stat st; + timespec *atime; + timespec *mtime; + + if(!l::any_timespec_is_utime_omit(ts_)) + return 0; + + rv = fs::fstat(fd_,&st); + if(rv == -1) + return -1; + + atime = fs::stat_atime(st); + mtime = fs::stat_mtime(st); + + if(ts_[0].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv_[0],atime); + if(ts_[1].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv_[1],mtime); + + return 0; + } + + static + inline + int + set_utime_now_to_now(const struct timespec ts_[2], + struct timeval tv_[2]) + { + int rv; + struct timeval now; + + if(l::any_timespec_is_utime_now(ts_)) + return 0; + + rv = time::gettimeofday(&now,NULL); + if(rv == -1) + return -1; + + if(ts_[0].tv_nsec == UTIME_NOW) + tv_[0] = now; + if(ts_[1].tv_nsec == UTIME_NOW) + tv_[1] = now; + + return 0; + } + + static + inline + int + convert_timespec_to_timeval(const int dirfd_, + const std::string &path_, + const struct timespec ts_[2], + struct timeval tv_[2], + struct timeval **tvp_, + const int flags_) + { + int rv; + + if(l::should_be_set_to_now(ts_)) + return (tvp=NULL,0); + + TIMESPEC_TO_TIMEVAL(&tv_[0],&ts_[0]); + TIMESPEC_TO_TIMEVAL(&tv_[1],&ts_[1]); + + rv = l::set_utime_omit_to_current_value(dirfd_,path_,ts_,tv_,flags_); + if(rv == -1) + return -1; + + rv = l::set_utime_now_to_now(ts_,tv_); + if(rv == -1) + return -1; + + return (*tvp_=tv_,0); + } + + static + inline + int + convert_timespec_to_timeval(const int fd_, + const struct timespec ts_[2], + struct timeval tv_[2], + struct timeval **tvp_) + { + int rv; + + if(l::should_be_set_to_now(ts_)) + return (*tvp=NULL,0); + + TIMESPEC_TO_TIMEVAL(&tv_[0],&ts_[0]); + TIMESPEC_TO_TIMEVAL(&tv_[1],&ts_[1]); + + rv = l::set_utime_omit_to_current_value(fd_,ts_,tv_); + if(rv == -1) + return -1; + + rv = l::set_utime_now_to_now(ts_,tv_); + if(rv == -1) + return -1; + + return (*tvp=tv,0); + } +} + +namespace fs +{ + static + inline + int + futimens(const int fd_, + const struct timespec ts_[2]) + { + int rv; + struct timeval tv[2]; + struct timeval *tvp; + + if(l::timespec_invalid(ts_)) + return (errno=EINVAL,-1); + if(l::should_ignore(ts_)) + return 0; + + rv = l::convert_timespec_to_timeval(fd_,ts_,tv,&tvp); + if(rv == -1) + return -1; + + return ::futimes(fd_,tvp); + } +} diff --git a/src/fs_futimens_linux.hpp b/src/fs_futimens_linux.hpp new file mode 100644 index 00000000..745bedee --- /dev/null +++ b/src/fs_futimens_linux.hpp @@ -0,0 +1,33 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include + +namespace fs +{ + static + inline + int + futimens(const int fd_, + const struct timespec ts_[2]) + { + return ::futimens(fd_,ts_); + } +} diff --git a/src/fs_base_futimesat.cpp b/src/fs_futimesat.cpp similarity index 91% rename from src/fs_base_futimesat.cpp rename to src/fs_futimesat.cpp index c254f4b9..c88e0966 100644 --- a/src/fs_base_futimesat.cpp +++ b/src/fs_futimesat.cpp @@ -17,7 +17,7 @@ */ #if __APPLE__ -# include "fs_base_futimesat_osx.icpp" +# include "fs_futimesat_osx.icpp" #else -# include "fs_base_futimesat_generic.icpp" +# include "fs_futimesat_generic.icpp" #endif diff --git a/src/fs_base_futimesat.hpp b/src/fs_futimesat.hpp similarity index 100% rename from src/fs_base_futimesat.hpp rename to src/fs_futimesat.hpp diff --git a/src/fs_base_futimesat_generic.icpp b/src/fs_futimesat_generic.icpp similarity index 82% rename from src/fs_base_futimesat_generic.icpp rename to src/fs_futimesat_generic.icpp index bfcd5e57..4f2b2134 100644 --- a/src/fs_base_futimesat_generic.icpp +++ b/src/fs_futimesat_generic.icpp @@ -22,10 +22,10 @@ namespace fs { int - futimesat(const int dirfd, - const char *pathname, - const struct timeval times[2]) + futimesat(const int dirfd_, + const char *pathname_, + const struct timeval times_[2]) { - return ::futimesat(dirfd,pathname,times); + return ::futimesat(dirfd_,pathname_,times_); } } diff --git a/src/fs_base_futimesat_osx.icpp b/src/fs_futimesat_osx.icpp similarity index 54% rename from src/fs_base_futimesat_osx.icpp rename to src/fs_futimesat_osx.icpp index 1efc5d8f..e00c4ddd 100644 --- a/src/fs_base_futimesat_osx.icpp +++ b/src/fs_futimesat_osx.icpp @@ -26,59 +26,62 @@ #include #include -static -int -getpath(const int dirfd, - const char *path, - char *fullpath) +namespace l { - int rv; - struct stat st; + static + int + getpath(const int dirfd_, + const char *path_, + char *fullpath_) + { + int rv; + struct stat st; - rv = ::fstat(dirfd,&st); - if(rv == -1) - return -1; + rv = ::fstat(dirfd_,&st); + if(rv == -1) + return -1; - if(!S_ISDIR(st.st_mode)) - return (errno=ENOTDIR,-1); + if(!S_ISDIR(st.st_mode)) + return (errno=ENOTDIR,-1); - rv = ::fcntl(dirfd,F_GETPATH,fullpath); - if(rv == -1) - return -1; + rv = ::fcntl(dirfd_,F_GETPATH,fullpath); + if(rv == -1) + return -1; - rv = ::strlcat(fullpath,"/",MAXPATHLEN); - if(rv > MAXPATHLEN) - return (errno=ENAMETOOLONG,-1); + rv = ::strlcat(fullpath_,"/",MAXPATHLEN); + if(rv > MAXPATHLEN) + return (errno=ENAMETOOLONG,-1); - rv = ::strlcat(fullpath,path,MAXPATHLEN); - if(rv > MAXPATHLEN) - return (errno=ENAMETOOLONG,-1); + rv = ::strlcat(fullpath_,path_,MAXPATHLEN); + if(rv > MAXPATHLEN) + return (errno=ENAMETOOLONG,-1); - return 0; + return 0; + } } namespace fs { int - futimesat(const int dirfd, - const char *pathname, - const struct timeval times[2]) + futimesat(const int dirfd_, + const char *pathname_, + const struct timeval times_[2]) { int rv; char fullpath[MAXPATHLEN]; - if((dirfd == AT_FDCWD) || - ((pathname != NULL) && - (pathname[0] == '/'))) - return ::utimes(pathname,times); + if((dirfd_ == AT_FDCWD) || + ((pathname_ != NULL) && + (pathname_[0] == '/'))) + return ::utimes(pathname_,times_); - if(dirfd < 0) + if(dirfd_ < 0) return (errno=EBADF,-1); - rv = getpath(dirfd,pathname,fullpath); + rv = l::getpath(dirfd_,pathname_,fullpath); if(rv == -1) return -1; - return ::utimes(fullpath,times); + return ::utimes(fullpath,times_); } } diff --git a/src/fs_base_getdents.cpp b/src/fs_getdents64.cpp similarity index 91% rename from src/fs_base_getdents.cpp rename to src/fs_getdents64.cpp index 2ba20680..a955fa12 100644 --- a/src/fs_base_getdents.cpp +++ b/src/fs_getdents64.cpp @@ -26,9 +26,9 @@ namespace fs { int - getdents64(unsigned int fd_, - void *dirp_, - unsigned int count_) + getdents_64(unsigned int fd_, + void *dirp_, + unsigned int count_) { #if defined SYS_getdents64 return ::syscall(SYS_getdents64,fd_,dirp_,count_); diff --git a/src/fs_base_getdents.hpp b/src/fs_getdents64.hpp similarity index 89% rename from src/fs_base_getdents.hpp rename to src/fs_getdents64.hpp index 35febd7c..e1c12d6a 100644 --- a/src/fs_base_getdents.hpp +++ b/src/fs_getdents64.hpp @@ -21,7 +21,7 @@ namespace fs { int - getdents64(unsigned int fd, - void *dirp, - unsigned int count); + getdents_64(unsigned int fd, + void *dirp, + unsigned int count); } diff --git a/src/fs_has_space.cpp b/src/fs_has_space.cpp index ba2dd8dc..f41ee8b5 100644 --- a/src/fs_has_space.cpp +++ b/src/fs_has_space.cpp @@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "fs_base_statvfs.hpp" +#include "fs_statvfs.hpp" #include "statvfs_util.hpp" #include diff --git a/src/fs_info.cpp b/src/fs_info.cpp index 1a58b155..e36d41f7 100644 --- a/src/fs_info.cpp +++ b/src/fs_info.cpp @@ -16,10 +16,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "fs_base_stat.hpp" -#include "fs_base_statvfs.hpp" #include "fs_info_t.hpp" #include "fs_path.hpp" +#include "fs_stat.hpp" +#include "fs_statvfs.hpp" #include "fs_statvfs_cache.hpp" #include "statvfs_util.hpp" diff --git a/src/fs_base_ioctl.hpp b/src/fs_ioctl.hpp similarity index 100% rename from src/fs_base_ioctl.hpp rename to src/fs_ioctl.hpp diff --git a/src/fs_base_chmod.hpp b/src/fs_lchmod.hpp similarity index 66% rename from src/fs_base_chmod.hpp rename to src/fs_lchmod.hpp index eb3769ff..8408ed32 100644 --- a/src/fs_base_chmod.hpp +++ b/src/fs_lchmod.hpp @@ -1,7 +1,7 @@ /* ISC License - Copyright (c) 2016, Antonio SJ Musumeci + Copyright (c) 2020, 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 @@ -18,9 +18,10 @@ #pragma once -#include "fs_base_stat.hpp" +#include "fs_fchmodat.hpp" +#include "fs_lstat.hpp" -#include +#include #define MODE_BITS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) @@ -29,28 +30,37 @@ namespace fs static inline int - chmod(const std::string &path_, - const mode_t mode_) + lchmod(const char *pathname_, + const mode_t mode_) { - return ::chmod(path_.c_str(),mode_); + return fs::fchmodat(AT_FDCWD,pathname_,mode_,AT_SYMLINK_NOFOLLOW); } static inline int - chmod_check_on_error(const std::string &path_, - const mode_t mode_) + lchmod(const std::string &pathname_, + const mode_t mode_) + { + return fs::lchmod(pathname_.c_str(),mode_); + } + + static + inline + int + lchmod_check_on_error(const std::string &path_, + const mode_t mode_) { int rv; - rv = fs::chmod(path_,mode_); + rv = fs::lchmod(path_,mode_); if(rv == -1) { int error; struct stat st; error = errno; - rv = fs::stat(path_,&st); + rv = fs::lstat(path_,&st); if(rv == -1) return -1; diff --git a/src/fs_base_chown.hpp b/src/fs_lchown.hpp similarity index 72% rename from src/fs_base_chown.hpp rename to src/fs_lchown.hpp index 825e6733..83fa30d8 100644 --- a/src/fs_base_chown.hpp +++ b/src/fs_lchown.hpp @@ -1,7 +1,7 @@ /* ISC License - Copyright (c) 2016, Antonio SJ Musumeci + Copyright (c) 2020, 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 @@ -18,12 +18,8 @@ #pragma once -#include "fs_base_stat.hpp" +#include "fs_lstat.hpp" -#include - -#include -#include #include namespace fs @@ -31,39 +27,39 @@ namespace fs static inline int - chown(const std::string &path_, - const uid_t uid_, - const gid_t gid_) + lchown(const char *pathname_, + const uid_t uid_, + const gid_t gid_) { - return ::chown(path_.c_str(),uid_,gid_); + return ::lchown(pathname_,uid_,gid_); } static inline int - chown(const std::string &path_, - const struct stat &st_) + lchown(const std::string &pathname_, + const uid_t uid_, + const gid_t gid_) { - return fs::chown(path_,st_.st_uid,st_.st_gid); + return fs::lchown(pathname_.c_str(),uid_,gid_); } static inline int - lchown(const std::string &path_, - const uid_t uid_, - const gid_t gid_) + lchown(const char *pathname_, + const struct stat &st_) { - return ::lchown(path_.c_str(),uid_,gid_); + return fs::lchown(pathname_,st_.st_uid,st_.st_gid); } static inline int - lchown(const std::string &path_, + lchown(const std::string &pathname_, const struct stat &st_) { - return fs::lchown(path_,st_.st_uid,st_.st_gid); + return fs::lchown(pathname_.c_str(),st_); } static diff --git a/src/fs_base_getxattr.hpp b/src/fs_lgetxattr.hpp similarity index 69% rename from src/fs_base_getxattr.hpp rename to src/fs_lgetxattr.hpp index 65dd5137..482fa35c 100644 --- a/src/fs_base_getxattr.hpp +++ b/src/fs_lgetxattr.hpp @@ -1,7 +1,7 @@ /* ISC License - Copyright (c) 2016, Antonio SJ Musumeci + Copyright (c) 2020, 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 @@ -36,7 +36,10 @@ namespace fs const size_t size_) { #ifdef USE_XATTR - return ::lgetxattr(path_,attrname_,value_,size_); + return ::lgetxattr(path_, + attrname_, + value_, + size_); #else return (errno=ENOTSUP,-1); #endif @@ -50,7 +53,10 @@ namespace fs void *value_, const size_t size_) { - return fs::lgetxattr(path_.c_str(),attrname_,value_,size_); + return fs::lgetxattr(path_.c_str(), + attrname_, + value_, + size_); } static @@ -66,30 +72,4 @@ namespace fs value_, size_); } - - static - inline - int - fgetxattr(const int fd_, - const char *attrname_, - void *value_, - const size_t size_) - { -#ifdef USE_XATTR - return ::fgetxattr(fd_,attrname_,value_,size_); -#else - return (errno=ENOTSUP,-1); -#endif - } - - static - inline - int - fgetxattr(const int fd_, - const std::string &attrname_, - void *value_, - const size_t size_) - { - return fs::fgetxattr(fd_,attrname_.c_str(),value_,size_); - } } diff --git a/src/fs_base_link.hpp b/src/fs_link.hpp similarity index 100% rename from src/fs_base_link.hpp rename to src/fs_link.hpp diff --git a/src/fs_base_listxattr.hpp b/src/fs_llistxattr.hpp similarity index 85% rename from src/fs_base_listxattr.hpp rename to src/fs_llistxattr.hpp index ea5c5b7b..e8c83dc4 100644 --- a/src/fs_base_listxattr.hpp +++ b/src/fs_llistxattr.hpp @@ -50,18 +50,4 @@ namespace fs { return fs::llistxattr(path_.c_str(),list_,size_); } - - static - inline - int - flistxattr(const int fd_, - char *list_, - const size_t size_) - { -#ifdef USE_XATTR - return ::flistxattr(fd_,list_,size_); -#else - return (errno=ENOTSUP,-1); -#endif - } } diff --git a/src/fs_base_removexattr.hpp b/src/fs_lremovexattr.hpp similarity index 100% rename from src/fs_base_removexattr.hpp rename to src/fs_lremovexattr.hpp diff --git a/src/fs_base_lseek.hpp b/src/fs_lseek.hpp similarity index 100% rename from src/fs_base_lseek.hpp rename to src/fs_lseek.hpp diff --git a/src/fs_base_setxattr.hpp b/src/fs_lsetxattr.hpp similarity index 77% rename from src/fs_base_setxattr.hpp rename to src/fs_lsetxattr.hpp index 29f05cd7..41baf862 100644 --- a/src/fs_base_setxattr.hpp +++ b/src/fs_lsetxattr.hpp @@ -1,7 +1,7 @@ /* ISC License - Copyright (c) 2016, Antonio SJ Musumeci + Copyright (c) 2020, 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 @@ -37,7 +37,11 @@ namespace fs const int flags_) { #ifdef USE_XATTR - return ::lsetxattr(path_,name_,value_,size_,flags_); + return ::lsetxattr(path_, + name_, + value_, + size_, + flags_); #else return (errno=ENOTSUP,-1); #endif @@ -58,20 +62,4 @@ namespace fs size_, flags_); } - - static - inline - int - fsetxattr(const int fd_, - const char *name_, - const void *value_, - const size_t size_, - const int flags_) - { -#ifdef USE_XATTR - return ::fsetxattr(fd_,name_,value_,size_,flags_); -#else - return (errno=ENOTSUP,-1); -#endif - } } diff --git a/src/fs_lstat.hpp b/src/fs_lstat.hpp new file mode 100644 index 00000000..83254b83 --- /dev/null +++ b/src/fs_lstat.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. +*/ + +#pragma once + +#include + +#include +#include +#include + +namespace fs +{ + static + inline + int + lstat(const char *path_, + struct stat *st_) + { + return ::lstat(path_,st_); + } + + static + inline + int + lstat(const std::string &path_, + struct stat *st_) + { + return fs::lstat(path_.c_str(),st_); + } +} diff --git a/src/fs_lutimens.hpp b/src/fs_lutimens.hpp new file mode 100644 index 00000000..ab1ce218 --- /dev/null +++ b/src/fs_lutimens.hpp @@ -0,0 +1,48 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include "fs_utimensat.hpp" +#include "fs_stat_utils.hpp" + +namespace fs +{ + static + inline + int + lutimens(const std::string &path_, + const struct timespec ts_[2]) + { + return fs::utimensat(AT_FDCWD,path_,ts_,AT_SYMLINK_NOFOLLOW); + } + + static + inline + int + lutimens(const std::string &path_, + const struct stat &st_) + { + struct timespec ts[2]; + + ts[0] = *fs::stat_atime(&st_); + ts[1] = *fs::stat_mtime(&st_); + + return fs::lutimens(path_,ts); + } +} diff --git a/src/fs_base_mkdir.hpp b/src/fs_mkdir.hpp similarity index 100% rename from src/fs_base_mkdir.hpp rename to src/fs_mkdir.hpp diff --git a/src/fs_base_mknod.hpp b/src/fs_mknod.hpp similarity index 100% rename from src/fs_base_mknod.hpp rename to src/fs_mknod.hpp diff --git a/src/fs_mktemp.cpp b/src/fs_mktemp.cpp index 0a8b567c..1f2166eb 100644 --- a/src/fs_mktemp.cpp +++ b/src/fs_mktemp.cpp @@ -17,7 +17,7 @@ */ #include "errno.hpp" -#include "fs_base_open.hpp" +#include "fs_open.hpp" #include #include diff --git a/src/fs_movefile.cpp b/src/fs_movefile.cpp index 6ec357e3..059e044f 100644 --- a/src/fs_movefile.cpp +++ b/src/fs_movefile.cpp @@ -15,19 +15,19 @@ */ #include "errno.hpp" -#include "fs_base_close.hpp" -#include "fs_base_open.hpp" -#include "fs_base_rename.hpp" -#include "fs_base_stat.hpp" -#include "fs_base_unlink.hpp" #include "fs_clonefile.hpp" #include "fs_clonepath.hpp" +#include "fs_close.hpp" #include "fs_file_size.hpp" #include "fs_findonfs.hpp" #include "fs_getfl.hpp" #include "fs_has_space.hpp" #include "fs_mktemp.hpp" +#include "fs_open.hpp" #include "fs_path.hpp" +#include "fs_rename.hpp" +#include "fs_stat.hpp" +#include "fs_unlink.hpp" #include "policy.hpp" #include "ugid.hpp" diff --git a/src/fs_base_open.hpp b/src/fs_open.hpp similarity index 100% rename from src/fs_base_open.hpp rename to src/fs_open.hpp diff --git a/src/fs_base_opendir.hpp b/src/fs_opendir.hpp similarity index 100% rename from src/fs_base_opendir.hpp rename to src/fs_opendir.hpp diff --git a/src/fs_base_read.hpp b/src/fs_read.hpp similarity index 100% rename from src/fs_base_read.hpp rename to src/fs_read.hpp diff --git a/src/fs_base_readdir.hpp b/src/fs_readdir.hpp similarity index 100% rename from src/fs_base_readdir.hpp rename to src/fs_readdir.hpp diff --git a/src/fs_base_readlink.hpp b/src/fs_readlink.hpp similarity index 100% rename from src/fs_base_readlink.hpp rename to src/fs_readlink.hpp diff --git a/src/fs_base_realpath.hpp b/src/fs_realpath.hpp similarity index 100% rename from src/fs_base_realpath.hpp rename to src/fs_realpath.hpp diff --git a/src/fs_realpathize.cpp b/src/fs_realpathize.cpp index a7c1f5d0..42db33b6 100644 --- a/src/fs_realpathize.cpp +++ b/src/fs_realpathize.cpp @@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "fs_base_realpath.hpp" +#include "fs_realpath.hpp" #include #include diff --git a/src/fs_base_remove.hpp b/src/fs_remove.hpp similarity index 100% rename from src/fs_base_remove.hpp rename to src/fs_remove.hpp diff --git a/src/fs_base_rename.hpp b/src/fs_rename.hpp similarity index 100% rename from src/fs_base_rename.hpp rename to src/fs_rename.hpp diff --git a/src/fs_base_rmdir.hpp b/src/fs_rmdir.hpp similarity index 100% rename from src/fs_base_rmdir.hpp rename to src/fs_rmdir.hpp diff --git a/src/fs_stat.hpp b/src/fs_stat.hpp new file mode 100644 index 00000000..5b5fed7c --- /dev/null +++ b/src/fs_stat.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. +*/ + +#pragma once + +#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_); + } +} diff --git a/src/fs_base_stat.hpp b/src/fs_stat_utils.hpp similarity index 68% rename from src/fs_base_stat.hpp rename to src/fs_stat_utils.hpp index 4292f697..42f13dd8 100644 --- a/src/fs_base_stat.hpp +++ b/src/fs_stat_utils.hpp @@ -1,7 +1,7 @@ /* ISC License - Copyright (c) 2016, Antonio SJ Musumeci + Copyright (c) 2020, 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 @@ -26,51 +26,6 @@ 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 char *path_, - struct stat *st_) - { - return ::lstat(path_,st_); - } - - static - inline - int - lstat(const std::string &path_, - struct stat *st_) - { - return fs::lstat(path_.c_str(),st_); - } - - static - inline - int - fstat(const int fd_, - struct stat *st_) - { - return ::fstat(fd_,st_); - } - static inline timespec * diff --git a/src/fs_base_statvfs.hpp b/src/fs_statvfs.hpp similarity index 96% rename from src/fs_base_statvfs.hpp rename to src/fs_statvfs.hpp index 25d1cbbb..26f8a054 100644 --- a/src/fs_base_statvfs.hpp +++ b/src/fs_statvfs.hpp @@ -19,8 +19,8 @@ #pragma once #include "errno.hpp" -#include "fs_base_close.hpp" -#include "fs_base_open.hpp" +#include "fs_close.hpp" +#include "fs_open.hpp" #include diff --git a/src/fs_statvfs_cache.cpp b/src/fs_statvfs_cache.cpp index 4fde2fb5..4cea84d0 100644 --- a/src/fs_statvfs_cache.cpp +++ b/src/fs_statvfs_cache.cpp @@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "fs_base_statvfs.hpp" +#include "fs_statvfs.hpp" #include "statvfs_util.hpp" #include diff --git a/src/fs_base_symlink.hpp b/src/fs_symlink.hpp similarity index 100% rename from src/fs_base_symlink.hpp rename to src/fs_symlink.hpp diff --git a/src/fs_base_truncate.hpp b/src/fs_truncate.hpp similarity index 100% rename from src/fs_base_truncate.hpp rename to src/fs_truncate.hpp diff --git a/src/fs_base_unlink.hpp b/src/fs_unlink.hpp similarity index 100% rename from src/fs_base_unlink.hpp rename to src/fs_unlink.hpp diff --git a/src/fs_utimensat.hpp b/src/fs_utimensat.hpp new file mode 100644 index 00000000..6b103c84 --- /dev/null +++ b/src/fs_utimensat.hpp @@ -0,0 +1,27 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#ifdef __linux__ +# include "fs_utimensat_linux.hpp" +#elif __FreeBSD__ +# include "fs_utimensat_freebsd.hpp" +#else +# include "fs_utimensat_generic.hpp" +#endif diff --git a/src/fs_base_access.hpp b/src/fs_utimensat_freebsd.hpp similarity index 59% rename from src/fs_base_access.hpp rename to src/fs_utimensat_freebsd.hpp index 8e9e5765..ef3935ff 100644 --- a/src/fs_base_access.hpp +++ b/src/fs_utimensat_freebsd.hpp @@ -1,7 +1,7 @@ /* ISC License - Copyright (c) 2016, Antonio SJ Musumeci + Copyright (c) 2020, 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 @@ -21,37 +21,29 @@ #include #include -#include +#include namespace fs { static inline int - access(const int dirfd_, - const std::string &path_, - const int mode_, - const int flags_) + utimensat(const int dirfd_, + const char *pathname_, + const struct timespec times_[2], + const int flags_) { - return ::faccessat(dirfd_,path_.c_str(),mode_,flags_); + return ::utimensat(dirfd_,pathname_,times_,flags_); } static inline int - access(const std::string &path_, - const int mode_, - const int flags_) + utimensat(const int dirfd_, + const std::string &pathname_, + const struct timespec times_[2], + const int flags_) { - return fs::access(AT_FDCWD,path_,mode_,flags_); - } - - static - inline - int - eaccess(const std::string &path_, - const int mode_) - { - return fs::access(path_,mode_,AT_EACCESS); + return fs::utimensat(dirfd_,pathname_.c_str(),times_,flags_); } } diff --git a/src/fs_utimensat_generic.hpp b/src/fs_utimensat_generic.hpp new file mode 100644 index 00000000..1834c0c3 --- /dev/null +++ b/src/fs_utimensat_generic.hpp @@ -0,0 +1,295 @@ +/* + ISC License + + Copyright (c) 2020, 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 "fs_fstat.hpp" +#include "fs_fstatat.hpp" +#include "fs_futimesat.hpp" +#include "fs_lutimens.hpp" +#include "fs_stat_utils.hpp" + +#include + +#include +#include +#include + +#ifndef UTIME_NOW +# define UTIME_NOW ((1l << 30) - 1l) +#endif + +#ifndef UTIME_OMIT +# define UTIME_OMIT ((1l << 30) - 2l) +#endif + +namespace l +{ + static + inline + bool + can_call_lutimes(const int dirfd_, + const std::string &path_, + const int flags_) + { + return ((flags_ == AT_SYMLINK_NOFOLLOW) && + ((dirfd_ == AT_FDCWD) || + (path_[0] == '/'))); + } + + static + inline + bool + should_ignore(const struct timespec ts_[2]) + { + return ((ts_ != NULL) && + (ts_[0].tv_nsec == UTIME_OMIT) && + (ts_[1].tv_nsec == UTIME_OMIT)); + } + + static + inline + bool + should_be_set_to_now(const struct timespec ts_[2]) + { + return ((ts_ == NULL) || + ((ts_[0].tv_nsec == UTIME_NOW) && + (ts_[1].tv_nsec == UTIME_NOW))); + } + + static + inline + bool + timespec_invalid(const struct timespec &ts_) + { + return (((ts_.tv_nsec < 0) || + (ts_.tv_nsec > 999999999)) && + ((ts_.tv_nsec != UTIME_NOW) && + (ts_.tv_nsec != UTIME_OMIT))); + } + + static + inline + bool + timespec_invalid(const struct timespec ts_[2]) + { + return ((ts_ != NULL) && + (l::timespec_invalid(ts_[0]) || + l::timespec_invalid(ts_[1]))); + } + + static + inline + bool + flags_invalid(const int flags_) + { + return ((flags_ & ~AT_SYMLINK_NOFOLLOW) != 0); + } + + static + inline + bool + any_timespec_is_utime_omit(const struct timespec ts_[2]) + { + return ((ts_[0].tv_nsec == UTIME_OMIT) || + (ts_[1].tv_nsec == UTIME_OMIT)); + } + + static + inline + bool + any_timespec_is_utime_now(const struct timespec ts_[2]) + { + return ((ts_[0].tv_nsec == UTIME_NOW) || + (ts_[1].tv_nsec == UTIME_NOW)); + } + + static + inline + int + set_utime_omit_to_current_value(const int dirfd_, + const std::string &path_, + const struct timespec ts_[2], + struct timeval tv_[2], + const int flags_) + { + int rv; + struct stat st; + timespec *atime; + timespec *mtime; + + if(!l::any_timespec_is_utime_omit(ts_)) + return 0; + + rv = fs::fstatat(dirfd_,path_,&st,flags_); + if(rv == -1) + return -1; + + atime = fs::stat_atime(st); + mtime = fs::stat_mtime(st); + + if(ts_[0].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv[0],atime); + if(ts_[1].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv[1],mtime); + + return 0; + } + + static + inline + int + set_utime_omit_to_current_value(const int fd_, + const struct timespec ts_[2], + struct timeval tv_[2]) + { + int rv; + struct stat st; + timespec *atime; + timespec *mtime; + + if(!l::any_timespec_is_utime_omit(ts_)) + return 0; + + rv = fs::fstat(fd_,&st); + if(rv == -1) + return -1; + + atime = fs::stat_atime(st); + mtime = fs::stat_mtime(st); + + if(ts_[0].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv_[0],atime); + if(ts_[1].tv_nsec == UTIME_OMIT) + TIMESPEC_TO_TIMEVAL(&tv_[1],mtime); + + return 0; + } + + static + inline + int + set_utime_now_to_now(const struct timespec ts_[2], + struct timeval tv_[2]) + { + int rv; + struct timeval now; + + if(l::any_timespec_is_utime_now(ts_)) + return 0; + + rv = time::gettimeofday(&now,NULL); + if(rv == -1) + return -1; + + if(ts_[0].tv_nsec == UTIME_NOW) + tv_[0] = now; + if(ts_[1].tv_nsec == UTIME_NOW) + tv_[1] = now; + + return 0; + } + + static + inline + int + convert_timespec_to_timeval(const int dirfd_, + const std::string &path_, + const struct timespec ts_[2], + struct timeval tv_[2], + struct timeval **tvp_, + const int flags_) + { + int rv; + + if(l::should_be_set_to_now(ts_)) + return (tvp=NULL,0); + + TIMESPEC_TO_TIMEVAL(&tv_[0],&ts_[0]); + TIMESPEC_TO_TIMEVAL(&tv_[1],&ts_[1]); + + rv = l::set_utime_omit_to_current_value(dirfd_,path_,ts_,tv_,flags_); + if(rv == -1) + return -1; + + rv = l::set_utime_now_to_now(ts_,tv_); + if(rv == -1) + return -1; + + return (*tvp_=tv_,0); + } + + static + inline + int + convert_timespec_to_timeval(const int fd_, + const struct timespec ts_[2], + struct timeval tv_[2], + struct timeval **tvp_) + { + int rv; + + if(l::should_be_set_to_now(ts_)) + return (*tvp=NULL,0); + + TIMESPEC_TO_TIMEVAL(&tv_[0],&ts_[0]); + TIMESPEC_TO_TIMEVAL(&tv_[1],&ts_[1]); + + rv = l::set_utime_omit_to_current_value(fd_,ts_,tv_); + if(rv == -1) + return -1; + + rv = l::set_utime_now_to_now(ts_,tv_); + if(rv == -1) + return -1; + + return (*tvp=tv,0); + } +} + +namespace fs +{ + static + inline + int + utimensat(const int dirfd_, + const std::string &path_, + const struct timespec ts_[2], + const int flags_) + { + int rv; + struct timeval tv[2]; + struct timeval *tvp; + + if(l::flags_invalid(flags)) + return (errno=EINVAL,-1); + if(l::timespec_invalid(ts_)) + return (errno=EINVAL,-1); + if(l::should_ignore(ts_)) + return 0; + + rv = l::convert_timespec_to_timeval(dirfd_,path_,ts_,tv,&tvp,flags_); + if(rv == -1) + return -1; + + if((flags_ & AT_SYMLINK_NOFOLLOW) == 0) + return fs::futimesat(dirfd_,path_,tvp); + if(l::can_call_lutimes(dirfd_,path_,flags)) + return fs::lutimes(path_,tvp); + + return (errno=ENOTSUP,-1); + } +} diff --git a/src/fs_utimensat_linux.hpp b/src/fs_utimensat_linux.hpp new file mode 100644 index 00000000..ef3935ff --- /dev/null +++ b/src/fs_utimensat_linux.hpp @@ -0,0 +1,49 @@ +/* + ISC License + + Copyright (c) 2020, 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. +*/ + +#pragma once + +#include + +#include +#include + +namespace fs +{ + static + inline + int + utimensat(const int dirfd_, + const char *pathname_, + const struct timespec times_[2], + const int flags_) + { + return ::utimensat(dirfd_,pathname_,times_,flags_); + } + + static + inline + int + utimensat(const int dirfd_, + const std::string &pathname_, + const struct timespec times_[2], + const int flags_) + { + return fs::utimensat(dirfd_,pathname_.c_str(),times_,flags_); + } +} diff --git a/src/fs_base_write.hpp b/src/fs_write.hpp similarity index 100% rename from src/fs_base_write.hpp rename to src/fs_write.hpp diff --git a/src/fs_xattr.cpp b/src/fs_xattr.cpp index 11286182..c73766d6 100644 --- a/src/fs_xattr.cpp +++ b/src/fs_xattr.cpp @@ -15,18 +15,21 @@ */ #include "errno.hpp" -#include "fs_base_close.hpp" -#include "fs_base_getxattr.hpp" -#include "fs_base_listxattr.hpp" -#include "fs_base_open.hpp" -#include "fs_base_removexattr.hpp" -#include "fs_base_setxattr.hpp" +#include "fs_close.hpp" +#include "fs_fgetxattr.hpp" +#include "fs_flistxattr.hpp" +#include "fs_fsetxattr.hpp" +#include "fs_lgetxattr.hpp" +#include "fs_llistxattr.hpp" +#include "fs_lremovexattr.hpp" +#include "fs_lsetxattr.hpp" +#include "fs_open.hpp" #include "str.hpp" -#include -#include #include #include +#include +#include using std::string; @@ -283,7 +286,7 @@ namespace fs const int flags_) { return fs::fsetxattr(fd_, - key_.c_str(), + key_, value_.data(), value_.size(), flags_); diff --git a/src/fuse_access.cpp b/src/fuse_access.cpp index 74f746c9..44c1ad7a 100644 --- a/src/fuse_access.cpp +++ b/src/fuse_access.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_access.hpp" +#include "fs_eaccess.hpp" #include "fs_path.hpp" #include "ugid.hpp" diff --git a/src/fuse_chmod.cpp b/src/fuse_chmod.cpp index c94f7955..1f9ad487 100644 --- a/src/fuse_chmod.cpp +++ b/src/fuse_chmod.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_chmod.hpp" +#include "fs_lchmod.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" @@ -45,7 +45,7 @@ namespace l fullpath = fs::path::make(basepath_,fusepath_); - rv = fs::chmod(fullpath,mode_); + rv = fs::lchmod(fullpath,mode_); return error::calc(rv,error_,errno); } diff --git a/src/fuse_chown.cpp b/src/fuse_chown.cpp index 59421792..947451a5 100644 --- a/src/fuse_chown.cpp +++ b/src/fuse_chown.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_chown.hpp" +#include "fs_lchown.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_create.cpp b/src/fuse_create.cpp index b1f8c281..2d039773 100644 --- a/src/fuse_create.cpp +++ b/src/fuse_create.cpp @@ -18,8 +18,8 @@ #include "errno.hpp" #include "fileinfo.hpp" #include "fs_acl.hpp" -#include "fs_base_open.hpp" #include "fs_clonepath.hpp" +#include "fs_open.hpp" #include "fs_path.hpp" #include "ugid.hpp" diff --git a/src/fuse_fallocate.cpp b/src/fuse_fallocate.cpp index 2bae361a..4a8e3e9e 100644 --- a/src/fuse_fallocate.cpp +++ b/src/fuse_fallocate.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_fallocate.hpp" +#include "fs_fallocate.hpp" #include diff --git a/src/fuse_fchmod.cpp b/src/fuse_fchmod.cpp index dcd2b863..482869a3 100644 --- a/src/fuse_fchmod.cpp +++ b/src/fuse_fchmod.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_fchmod.hpp" +#include "fs_fchmod.hpp" #include diff --git a/src/fuse_fchown.cpp b/src/fuse_fchown.cpp index 45fce5d9..ca447db9 100644 --- a/src/fuse_fchown.cpp +++ b/src/fuse_fchown.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_fchown.hpp" +#include "fs_fchown.hpp" #include diff --git a/src/fuse_fgetattr.cpp b/src/fuse_fgetattr.cpp index 2ee99883..7cb0ca44 100644 --- a/src/fuse_fgetattr.cpp +++ b/src/fuse_fgetattr.cpp @@ -17,7 +17,7 @@ #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_stat.hpp" +#include "fs_fstat.hpp" #include "fs_inode.hpp" #include diff --git a/src/fuse_flock.cpp b/src/fuse_flock.cpp index 8361c4d8..78065207 100644 --- a/src/fuse_flock.cpp +++ b/src/fuse_flock.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_flock.hpp" +#include "fs_flock.hpp" #include diff --git a/src/fuse_flush.cpp b/src/fuse_flush.cpp index ee0485b3..277a3218 100644 --- a/src/fuse_flush.cpp +++ b/src/fuse_flush.cpp @@ -16,8 +16,8 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_close.hpp" -#include "fs_base_dup.hpp" +#include "fs_close.hpp" +#include "fs_dup.hpp" #include diff --git a/src/fuse_free_hide.cpp b/src/fuse_free_hide.cpp index 417ea5b5..778d4bf7 100644 --- a/src/fuse_free_hide.cpp +++ b/src/fuse_free_hide.cpp @@ -17,7 +17,7 @@ */ #include "fileinfo.hpp" -#include "fs_base_close.hpp" +#include "fs_close.hpp" #include diff --git a/src/fuse_fsync.cpp b/src/fuse_fsync.cpp index 84c423cb..a8d7c793 100644 --- a/src/fuse_fsync.cpp +++ b/src/fuse_fsync.cpp @@ -16,7 +16,8 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_fsync.hpp" +#include "fs_fdatasync.hpp" +#include "fs_fsync.hpp" #include diff --git a/src/fuse_fsyncdir.cpp b/src/fuse_fsyncdir.cpp index 7acdb591..12b9f727 100644 --- a/src/fuse_fsyncdir.cpp +++ b/src/fuse_fsyncdir.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "dirinfo.hpp" -#include "fs_base_fsync.hpp" +#include "fs_fsync.hpp" #include diff --git a/src/fuse_ftruncate.cpp b/src/fuse_ftruncate.cpp index aeca910f..d7879e7d 100644 --- a/src/fuse_ftruncate.cpp +++ b/src/fuse_ftruncate.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_ftruncate.hpp" +#include "fs_ftruncate.hpp" #include diff --git a/src/fuse_futimens.cpp b/src/fuse_futimens.cpp index 09947932..fac6768a 100644 --- a/src/fuse_futimens.cpp +++ b/src/fuse_futimens.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_utime.hpp" +#include "fs_futimens.hpp" #include diff --git a/src/fuse_getattr.cpp b/src/fuse_getattr.cpp index f78dab72..c7b38632 100644 --- a/src/fuse_getattr.cpp +++ b/src/fuse_getattr.cpp @@ -16,8 +16,8 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_stat.hpp" #include "fs_inode.hpp" +#include "fs_lstat.hpp" #include "fs_path.hpp" #include "symlinkify.hpp" #include "ugid.hpp" diff --git a/src/fuse_getxattr.cpp b/src/fuse_getxattr.cpp index 98f730b7..1493f995 100644 --- a/src/fuse_getxattr.cpp +++ b/src/fuse_getxattr.cpp @@ -16,8 +16,8 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_getxattr.hpp" #include "fs_findallfiles.hpp" +#include "fs_lgetxattr.hpp" #include "fs_path.hpp" #include "fs_statvfs_cache.hpp" #include "str.hpp" diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index d187eddc..2bbf94c3 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -19,10 +19,10 @@ #include "endian.hpp" #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_close.hpp" -#include "fs_base_ioctl.hpp" -#include "fs_base_open.hpp" +#include "fs_close.hpp" #include "fs_findallfiles.hpp" +#include "fs_ioctl.hpp" +#include "fs_open.hpp" #include "fs_path.hpp" #include "str.hpp" #include "ugid.hpp" diff --git a/src/fuse_link.cpp b/src/fuse_link.cpp index c07b8dde..8f7bf6d8 100644 --- a/src/fuse_link.cpp +++ b/src/fuse_link.cpp @@ -16,8 +16,8 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_link.hpp" #include "fs_clonepath.hpp" +#include "fs_link.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_listxattr.cpp b/src/fuse_listxattr.cpp index 5595eeda..a68d8a4f 100644 --- a/src/fuse_listxattr.cpp +++ b/src/fuse_listxattr.cpp @@ -18,7 +18,7 @@ #include "category.hpp" #include "config.hpp" #include "errno.hpp" -#include "fs_base_listxattr.hpp" +#include "fs_llistxattr.hpp" #include "fs_path.hpp" #include "ugid.hpp" #include "xattr.hpp" diff --git a/src/fuse_mkdir.cpp b/src/fuse_mkdir.cpp index 695a8213..b6ff1e70 100644 --- a/src/fuse_mkdir.cpp +++ b/src/fuse_mkdir.cpp @@ -17,8 +17,8 @@ #include "config.hpp" #include "errno.hpp" #include "fs_acl.hpp" -#include "fs_base_mkdir.hpp" #include "fs_clonepath.hpp" +#include "fs_mkdir.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_mknod.cpp b/src/fuse_mknod.cpp index 28f26aaf..02477090 100644 --- a/src/fuse_mknod.cpp +++ b/src/fuse_mknod.cpp @@ -17,7 +17,7 @@ #include "config.hpp" #include "errno.hpp" #include "fs_acl.hpp" -#include "fs_base_mknod.hpp" +#include "fs_mknod.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rv.hpp" diff --git a/src/fuse_open.cpp b/src/fuse_open.cpp index 154c714b..d0aded13 100644 --- a/src/fuse_open.cpp +++ b/src/fuse_open.cpp @@ -17,12 +17,12 @@ #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_chmod.hpp" -#include "fs_base_fchmod.hpp" -#include "fs_base_open.hpp" -#include "fs_base_stat.hpp" +#include "fs_lchmod.hpp" #include "fs_cow.hpp" +#include "fs_fchmod.hpp" +#include "fs_open.hpp" #include "fs_path.hpp" +#include "fs_stat.hpp" #include "policy_cache.hpp" #include "stat_util.hpp" #include "ugid.hpp" @@ -46,8 +46,8 @@ namespace l static int - chmod_and_open_if_not_writable_and_empty(const string &fullpath_, - const int flags_) + lchmod_and_open_if_not_writable_and_empty(const string &fullpath_, + const int flags_) { int rv; struct stat st; @@ -59,7 +59,7 @@ namespace l if(StatUtil::writable(st)) return (errno=EACCES,-1); - rv = fs::chmod(fullpath_,(st.st_mode|S_IWUSR|S_IWGRP)); + rv = fs::lchmod(fullpath_,(st.st_mode|S_IWUSR|S_IWGRP)); if(rv == -1) return (errno=EACCES,-1); @@ -88,11 +88,11 @@ namespace l return (errno=EACCES,-1); if(fullpath_.find("/.git/") == string::npos) return (errno=EACCES,-1); - return l::chmod_and_open_if_not_writable_and_empty(fullpath_,flags_); + return l::lchmod_and_open_if_not_writable_and_empty(fullpath_,flags_); case NFSOpenHack::ENUM::ALL: if(l::rdonly(flags_)) return (errno=EACCES,-1); - return l::chmod_and_open_if_not_writable_and_empty(fullpath_,flags_); + return l::lchmod_and_open_if_not_writable_and_empty(fullpath_,flags_); } } diff --git a/src/fuse_read.cpp b/src/fuse_read.cpp index eab02747..3b76e52f 100644 --- a/src/fuse_read.cpp +++ b/src/fuse_read.cpp @@ -16,7 +16,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_read.hpp" +#include "fs_read.hpp" #include diff --git a/src/fuse_readdir_linux.cpp b/src/fuse_readdir_linux.cpp index 63c1eaac..e2544602 100644 --- a/src/fuse_readdir_linux.cpp +++ b/src/fuse_readdir_linux.cpp @@ -16,13 +16,13 @@ #include "branch.hpp" #include "errno.hpp" -#include "fs_base_close.hpp" -#include "fs_base_getdents.hpp" -#include "fs_base_open.hpp" -#include "fs_base_stat.hpp" +#include "fs_close.hpp" #include "fs_devid.hpp" +#include "fs_getdents64.hpp" #include "fs_inode.hpp" +#include "fs_open.hpp" #include "fs_path.hpp" +#include "fs_stat.hpp" #include "hashset.hpp" #include "linux_dirent64.h" #include "mempools.hpp" @@ -86,7 +86,7 @@ namespace l for(;;) { - nread = fs::getdents64(dirfd,buf,g_DENTS_BUF_POOL.size()); + nread = fs::getdents_64(dirfd,buf,g_DENTS_BUF_POOL.size()); if(nread == -1) break; if(nread == 0) diff --git a/src/fuse_readdir_plus_linux.cpp b/src/fuse_readdir_plus_linux.cpp index 76e3ce2e..b399ba05 100644 --- a/src/fuse_readdir_plus_linux.cpp +++ b/src/fuse_readdir_plus_linux.cpp @@ -16,14 +16,14 @@ #include "branch.hpp" #include "errno.hpp" -#include "fs_base_close.hpp" -#include "fs_base_fstatat.hpp" -#include "fs_base_getdents.hpp" -#include "fs_base_open.hpp" -#include "fs_base_stat.hpp" +#include "fs_close.hpp" #include "fs_devid.hpp" +#include "fs_fstatat.hpp" +#include "fs_getdents64.hpp" #include "fs_inode.hpp" +#include "fs_open.hpp" #include "fs_path.hpp" +#include "fs_stat.hpp" #include "hashset.hpp" #include "linux_dirent64.h" #include "mempools.hpp" @@ -95,7 +95,7 @@ namespace l for(;;) { - nread = fs::getdents64(dirfd,buf,g_DENTS_BUF_POOL.size()); + nread = fs::getdents_64(dirfd,buf,g_DENTS_BUF_POOL.size()); if(nread == -1) break; if(nread == 0) diff --git a/src/fuse_readdir_plus_posix.cpp b/src/fuse_readdir_plus_posix.cpp index 363ac217..ba801fc3 100644 --- a/src/fuse_readdir_plus_posix.cpp +++ b/src/fuse_readdir_plus_posix.cpp @@ -18,15 +18,15 @@ #include "branch.hpp" #include "errno.hpp" -#include "fs_base_closedir.hpp" -#include "fs_base_dirfd.hpp" -#include "fs_base_opendir.hpp" -#include "fs_base_readdir.hpp" -#include "fs_base_fstatat.hpp" -#include "fs_base_stat.hpp" +#include "fs_closedir.hpp" #include "fs_devid.hpp" +#include "fs_dirfd.hpp" +#include "fs_fstatat.hpp" #include "fs_inode.hpp" +#include "fs_opendir.hpp" #include "fs_path.hpp" +#include "fs_readdir.hpp" +#include "fs_stat.hpp" #include "hashset.hpp" #include diff --git a/src/fuse_readdir_posix.cpp b/src/fuse_readdir_posix.cpp index 4579d5e0..2bf916ae 100644 --- a/src/fuse_readdir_posix.cpp +++ b/src/fuse_readdir_posix.cpp @@ -18,11 +18,11 @@ #include "branch.hpp" #include "errno.hpp" -#include "fs_base_closedir.hpp" -#include "fs_base_dirfd.hpp" -#include "fs_base_opendir.hpp" -#include "fs_base_readdir.hpp" -#include "fs_base_stat.hpp" +#include "fs_closedir.hpp" +#include "fs_dirfd.hpp" +#include "fs_opendir.hpp" +#include "fs_readdir.hpp" +#include "fs_stat.hpp" #include "fs_devid.hpp" #include "fs_inode.hpp" #include "fs_path.hpp" diff --git a/src/fuse_readlink.cpp b/src/fuse_readlink.cpp index aeeba3f4..bec7de49 100644 --- a/src/fuse_readlink.cpp +++ b/src/fuse_readlink.cpp @@ -16,9 +16,9 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_readlink.hpp" -#include "fs_base_stat.hpp" +#include "fs_lstat.hpp" #include "fs_path.hpp" +#include "fs_readlink.hpp" #include "symlinkify.hpp" #include "ugid.hpp" diff --git a/src/fuse_release.cpp b/src/fuse_release.cpp index 584a3c64..5aff7b44 100644 --- a/src/fuse_release.cpp +++ b/src/fuse_release.cpp @@ -17,8 +17,8 @@ #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_close.hpp" -#include "fs_base_fadvise.hpp" +#include "fs_close.hpp" +#include "fs_fadvise.hpp" #include diff --git a/src/fuse_removexattr.cpp b/src/fuse_removexattr.cpp index b7a72eee..987108c4 100644 --- a/src/fuse_removexattr.cpp +++ b/src/fuse_removexattr.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_removexattr.hpp" +#include "fs_lremovexattr.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_rename.cpp b/src/fuse_rename.cpp index bf52e038..13c9852b 100644 --- a/src/fuse_rename.cpp +++ b/src/fuse_rename.cpp @@ -16,10 +16,10 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_remove.hpp" -#include "fs_base_rename.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" +#include "fs_remove.hpp" +#include "fs_rename.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_rmdir.cpp b/src/fuse_rmdir.cpp index 5aa36a67..a6fc5353 100644 --- a/src/fuse_rmdir.cpp +++ b/src/fuse_rmdir.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_rmdir.hpp" +#include "fs_rmdir.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_setxattr.cpp b/src/fuse_setxattr.cpp index 57169943..4fcd0b66 100644 --- a/src/fuse_setxattr.cpp +++ b/src/fuse_setxattr.cpp @@ -16,8 +16,8 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_setxattr.hpp" #include "fs_glob.hpp" +#include "fs_lsetxattr.hpp" #include "fs_path.hpp" #include "fs_statvfs_cache.hpp" #include "num.hpp" diff --git a/src/fuse_statfs.cpp b/src/fuse_statfs.cpp index 972e3140..1ba6afa5 100644 --- a/src/fuse_statfs.cpp +++ b/src/fuse_statfs.cpp @@ -16,9 +16,9 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_stat.hpp" -#include "fs_base_statvfs.hpp" +#include "fs_lstat.hpp" #include "fs_path.hpp" +#include "fs_statvfs.hpp" #include "statvfs_util.hpp" #include "ugid.hpp" diff --git a/src/fuse_symlink.cpp b/src/fuse_symlink.cpp index 8c2ba8a5..efd6b421 100644 --- a/src/fuse_symlink.cpp +++ b/src/fuse_symlink.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_symlink.hpp" +#include "fs_symlink.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" #include "rv.hpp" diff --git a/src/fuse_truncate.cpp b/src/fuse_truncate.cpp index a235f1e1..aa118fc4 100644 --- a/src/fuse_truncate.cpp +++ b/src/fuse_truncate.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_truncate.hpp" +#include "fs_truncate.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_unlink.cpp b/src/fuse_unlink.cpp index 681e74e6..291bd199 100644 --- a/src/fuse_unlink.cpp +++ b/src/fuse_unlink.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_unlink.hpp" +#include "fs_unlink.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" diff --git a/src/fuse_utimens.cpp b/src/fuse_utimens.cpp index f9dd789f..c6d8bbf9 100644 --- a/src/fuse_utimens.cpp +++ b/src/fuse_utimens.cpp @@ -16,7 +16,7 @@ #include "config.hpp" #include "errno.hpp" -#include "fs_base_utime.hpp" +#include "fs_lutimens.hpp" #include "fs_path.hpp" #include "rv.hpp" #include "ugid.hpp" @@ -45,7 +45,7 @@ namespace l fullpath = fs::path::make(basepath_,fusepath_); - rv = fs::lutime(fullpath,ts_); + rv = fs::lutimens(fullpath,ts_); return error::calc(rv,error_,errno); } diff --git a/src/fuse_write.cpp b/src/fuse_write.cpp index 00bcfefc..f1806f66 100644 --- a/src/fuse_write.cpp +++ b/src/fuse_write.cpp @@ -17,8 +17,8 @@ #include "config.hpp" #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_base_write.hpp" #include "fs_movefile.hpp" +#include "fs_write.hpp" #include "ugid.hpp" #include