diff --git a/.cirrus.yml b/.cirrus.yml index 11b9ec5b..81d90685 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -6,7 +6,14 @@ freebsd_task: ASSUME_ALWAYS_YES: yes script: - tools/install-build-pkgs - - gmake + - gmake -j4 + +#macos_task: +# osx_instance: +# image: catalina-base +# script: +# - tools/install-build-pkgs +# - gmake -j4 linux_task: name: "alpine:3.11" @@ -56,9 +63,45 @@ linux_task: - make rpm linux_task: - name: "ubuntu:20.04" + name: "fedora:30" container: - image: ubuntu:20.04 + image: fedora:30 + cpu: 4 + memory: 2G + timeout_in: 10m + script: + - tools/install-build-pkgs + - make + - make rpm + +linux_task: + name: "fedora:31" + container: + image: fedora:31 + cpu: 4 + memory: 2G + timeout_in: 10m + script: + - tools/install-build-pkgs + - make + - make rpm + +linux_task: + name: "fedora:32" + container: + image: fedora:32 + cpu: 4 + memory: 2G + timeout_in: 10m + script: + - tools/install-build-pkgs + - make + - make rpm + +linux_task: + name: "ubuntu:14.04" + container: + image: ubuntu:14.04 cpu: 4 memory: 2G timeout_in: 10m @@ -71,9 +114,9 @@ linux_task: - mergerfs -v || true linux_task: - name: "ubuntu:19.10" + name: "ubuntu:16.04" container: - image: ubuntu:19.10 + image: ubuntu:16.04 cpu: 4 memory: 2G timeout_in: 10m @@ -101,9 +144,9 @@ linux_task: - mergerfs -v || true linux_task: - name: "ubuntu:16.04" + name: "ubuntu:19.10" container: - image: ubuntu:16.04 + image: ubuntu:19.10 cpu: 4 memory: 2G timeout_in: 10m @@ -116,9 +159,9 @@ linux_task: - mergerfs -v || true linux_task: - name: "ubuntu:14.04" + name: "ubuntu:20.04" container: - image: ubuntu:14.04 + image: ubuntu:20.04 cpu: 4 memory: 2G timeout_in: 10m @@ -131,9 +174,9 @@ linux_task: - mergerfs -v || true linux_task: - name: "debian:10" + name: "debian:7" container: - image: debian:10 + image: debian:8 cpu: 4 memory: 2G timeout_in: 10m @@ -146,9 +189,9 @@ linux_task: - mergerfs -v || true linux_task: - name: "debian:9" + name: "debian:8" container: - image: debian:9 + image: debian:8 cpu: 4 memory: 2G timeout_in: 10m @@ -161,9 +204,9 @@ linux_task: - mergerfs -v || true linux_task: - name: "debian:8" + name: "debian:9" container: - image: debian:8 + image: debian:9 cpu: 4 memory: 2G timeout_in: 10m @@ -176,9 +219,9 @@ linux_task: - mergerfs -v || true linux_task: - name: "debian:7" + name: "debian:10" container: - image: debian:8 + image: debian:10 cpu: 4 memory: 2G timeout_in: 10m diff --git a/src/branch.cpp b/src/branch.cpp index 11b2afd4..943e967f 100644 --- a/src/branch.cpp +++ b/src/branch.cpp @@ -18,8 +18,8 @@ #include "branch.hpp" #include "ef.hpp" -#include "fs.hpp" #include "fs_glob.hpp" +#include "fs_realpathize.hpp" #include "str.hpp" #include @@ -91,8 +91,8 @@ parse(const string &str_, else branch.mode = Branch::RW; - fs::glob(str,globbed); - fs::realpathize(globbed); + fs::glob(str,&globbed); + fs::realpathize(&globbed); for(size_t i = 0; i < globbed.size(); i++) { branch.path = globbed[i]; @@ -109,7 +109,7 @@ set(Branches &branches_, branches_.clear(); - str::split(paths,str_,':'); + str::split(str_,':',&paths); for(size_t i = 0; i < paths.size(); i++) { @@ -130,7 +130,7 @@ add_begin(Branches &branches_, { vector paths; - str::split(paths,str_,':'); + str::split(str_,':',&paths); for(size_t i = 0; i < paths.size(); i++) { @@ -151,7 +151,7 @@ add_end(Branches &branches_, { vector paths; - str::split(paths,str_,':'); + str::split(str_,':',&paths); for(size_t i = 0; i < paths.size(); i++) { @@ -186,7 +186,7 @@ erase_fnmatch(Branches &branches_, { vector patterns; - str::split(patterns,str_,':'); + str::split(str_,':',&patterns); for(Branches::iterator i = branches_.begin(); i != branches_.end();) diff --git a/src/buildmap.hpp b/src/buildmap.hpp index 87a57d7f..49ad3e39 100644 --- a/src/buildmap.hpp +++ b/src/buildmap.hpp @@ -17,21 +17,22 @@ #pragma once #include +#include template class buildmap { public: - buildmap(const K &key, - const V &val) + buildmap(const K &key_, + const V &val_) { - _map.insert(std::make_pair(key,val)); + _map.insert(std::make_pair(key_,val_)); } - buildmap &operator()(const K &key, - const V &val) + buildmap &operator()(const K &key_, + const V &val_) { - _map.insert(std::make_pair(key,val)); + _map.insert(std::make_pair(key_,val_)); return *this; } diff --git a/src/buildvector.hpp b/src/buildvector.hpp index b6a6d4a2..7f97f750 100644 --- a/src/buildvector.hpp +++ b/src/buildvector.hpp @@ -23,14 +23,14 @@ template class buildvector { public: - buildvector(const V &val) + buildvector(const V &val_) { - _vector.push_back(val); + _vector.push_back(val_); } - buildvector &operator()(const V &val) + buildvector &operator()(const V &val_) { - _vector.push_back(val); + _vector.push_back(val_); return *this; } diff --git a/src/category.cpp b/src/category.cpp deleted file mode 100644 index 9985b586..00000000 --- a/src/category.cpp +++ /dev/null @@ -1,59 +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. -*/ - -#include -#include - -#include "category.hpp" -#include "buildvector.hpp" - -#define CATEGORY(X) Category(Category::Enum::X,#X) - -const std::vector Category::_categories_ = - buildvector - (CATEGORY(invalid)) - (CATEGORY(action)) - (CATEGORY(create)) - (CATEGORY(search)); - -const Category * const Category::categories = &_categories_[1]; - -const Category &Category::invalid = Category::categories[Category::Enum::invalid]; -const Category &Category::action = Category::categories[Category::Enum::action]; -const Category &Category::create = Category::categories[Category::Enum::create]; -const Category &Category::search = Category::categories[Category::Enum::search]; - -const Category& -Category::find(const std::string &str) -{ - for(int i = Enum::BEGIN; i != Enum::END; ++i) - { - if(categories[i] == str) - return categories[i]; - } - - return invalid; -} - -const Category& -Category::find(const Category::Enum::Type i) -{ - if(i >= Category::Enum::BEGIN && - i < Category::Enum::END) - return categories[i]; - - return invalid; -} diff --git a/src/category.hpp b/src/category.hpp index d031f01d..08a7c00a 100644 --- a/src/category.hpp +++ b/src/category.hpp @@ -16,69 +16,9 @@ #pragma once -#include -#include - -class Category -{ -public: - struct Enum +enum class Category { - enum Type - { - invalid = -1, - BEGIN = 0, - action = BEGIN, - create, - search, - END - }; + ACTION, + CREATE, + SEARCH }; - -private: - Enum::Type _enum; - std::string _str; - -public: - Category() - : _enum(invalid), - _str(invalid) - { - } - - Category(const Enum::Type enum_, - const std::string &str_) - : _enum(enum_), - _str(str_) - { - } - -public: - operator const Enum::Type() const { return _enum; } - operator const std::string&() const { return _str; } - operator const Category*() const { return this; } - - bool operator==(const std::string &str_) const - { return _str == str_; } - - bool operator==(const Enum::Type enum_) const - { return _enum == enum_; } - - bool operator!=(const Category &r) const - { return _enum != r._enum; } - - bool operator<(const Category &r) const - { return _enum < r._enum; } - -public: - static const Category &find(const std::string&); - static const Category &find(const Enum::Type); - -public: - static const std::vector _categories_; - static const Category * const categories; - static const Category &invalid; - static const Category &action; - static const Category &create; - static const Category &search; -}; diff --git a/src/config.cpp b/src/config.cpp index 7bade626..28bec9a6 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -18,7 +18,6 @@ #include "ef.hpp" #include "errno.hpp" #include "from_string.hpp" -#include "fs.hpp" #include "num.hpp" #include "rwlock.hpp" #include "to_string.hpp" diff --git a/src/config_statfsignore.hpp b/src/config_statfsignore.hpp index caeb7269..6749f8d6 100644 --- a/src/config_statfsignore.hpp +++ b/src/config_statfsignore.hpp @@ -26,4 +26,5 @@ enum class StatFSIgnoreEnum RO, NC }; + typedef Enum StatFSIgnore; diff --git a/src/fs.cpp b/src/fs.cpp deleted file mode 100644 index f6c6daf3..00000000 --- a/src/fs.cpp +++ /dev/null @@ -1,156 +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. -*/ - -#include -#include - -#include -#include -#include -#include - -#include "errno.hpp" -#include "fs_attr.hpp" -#include "fs_base_realpath.hpp" -#include "fs_base_stat.hpp" -#include "fs_exists.hpp" -#include "fs_path.hpp" -#include "fs_statvfs_cache.hpp" -#include "fs_xattr.hpp" -#include "str.hpp" - -using std::string; -using std::vector; - -namespace fs -{ - void - findallfiles(const vector &basepaths, - const char *fusepath, - vector &paths) - { - string fullpath; - - for(size_t i = 0, ei = basepaths.size(); i != ei; i++) - { - fullpath = fs::path::make(basepaths[i],fusepath); - - if(!fs::exists(fullpath)) - continue; - - paths.push_back(fullpath); - } - } - - int - findonfs(const vector &basepaths, - const string &fusepath, - const int fd, - string &basepath) - { - int rv; - dev_t dev; - string fullpath; - struct stat st; - - rv = fs::fstat(fd,&st); - if(rv == -1) - return -1; - - dev = st.st_dev; - for(size_t i = 0, ei = basepaths.size(); i != ei; i++) - { - fullpath = fs::path::make(basepaths[i],fusepath); - - rv = fs::lstat(fullpath,&st); - if(rv == -1) - continue; - - if(st.st_dev != dev) - continue; - - basepath = basepaths[i]; - - return 0; - } - - return (errno=ENOENT,-1); - } - - void - realpathize(vector &strs) - { - char *rv; - - for(size_t i = 0; i < strs.size(); i++) - { - rv = fs::realpath(strs[i]); - if(rv == NULL) - continue; - - strs[i] = rv; - - ::free(rv); - } - } - - int - getfl(const int fd) - { - return ::fcntl(fd,F_GETFL,0); - } - - int - setfl(const int fd, - const mode_t mode) - { - return ::fcntl(fd,F_SETFL,mode); - } - - int - mfs(const vector &basepaths, - const uint64_t minfreespace, - string &path) - { - int rv; - uint64_t mfs; - uint64_t spaceavail; - const string *mfsbasepath; - - mfs = 0; - mfsbasepath = NULL; - for(size_t i = 0, ei = basepaths.size(); i != ei; i++) - { - rv = fs::statvfs_cache_spaceavail(basepaths[i],&spaceavail); - if(rv == -1) - continue; - if(spaceavail < minfreespace) - continue; - if(spaceavail <= mfs) - continue; - - mfs = spaceavail; - mfsbasepath = &basepaths[i]; - } - - if(mfsbasepath == NULL) - return (errno=ENOENT,-1); - - path = *mfsbasepath; - - return 0; - } -}; diff --git a/src/fs.hpp b/src/fs.hpp deleted file mode 100644 index 9f122e6d..00000000 --- a/src/fs.hpp +++ /dev/null @@ -1,43 +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 - -#include -#include - -#include -#include - -namespace fs -{ - using std::string; - using std::vector; - - void findallfiles(const vector &basepaths_, - const char *fusepath_, - vector &paths_); - - void realpathize(vector &strs_); - - int getfl(const int fd_); - int setfl(const int fd_, - const mode_t mode_); - - int mfs(const vector &srcs_, - const uint64_t minfreespace_, - string &path_); -} 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_acl.hpp b/src/fs_acl.hpp index 95546075..f3b16e43 100644 --- a/src/fs_acl.hpp +++ b/src/fs_acl.hpp @@ -25,6 +25,6 @@ namespace fs namespace acl { bool - dir_has_defaults(const std::string &fullpath_); + dir_has_defaults(const std::string &fullpath); } } diff --git a/src/fs_attr.cpp b/src/fs_attr.cpp index 6a5ea619..47a9291a 100644 --- a/src/fs_attr.cpp +++ b/src/fs_attr.cpp @@ -15,7 +15,9 @@ */ #ifdef __linux__ -# include "fs_attr_linux.icpp" +#warning "using fs_attr_linux.icpp" +#include "fs_attr_linux.icpp" #else -# include "fs_attr_unsupported.icpp" +#warning "using fs_attr_unsupported.icpp" +#include "fs_attr_unsupported.icpp" #endif diff --git a/src/fs_attr.hpp b/src/fs_attr.hpp index e92491bf..c9bee84e 100644 --- a/src/fs_attr.hpp +++ b/src/fs_attr.hpp @@ -22,9 +22,9 @@ namespace fs { namespace attr { - int copy(const int fdin_, - const int fdout_); - int copy(const std::string &from_, - const std::string &to_); + int copy(const int fdin, + const int fdout); + int copy(const std::string &from, + const std::string &to); } } 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_fadvise.hpp b/src/fs_base_fadvise.hpp deleted file mode 100644 index 3a89caa2..00000000 --- a/src/fs_base_fadvise.hpp +++ /dev/null @@ -1,35 +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 - -namespace fs -{ - int - fadvise_dontneed(const int fd_, - const off_t offset_ = 0, - const off_t len_ = 0); - - int - fadvise_willneed(const int fd_, - const off_t offset_ = 0, - const off_t len_ = 0); - - int - fadvise_sequential(const int fd_, - const off_t offset_ = 0, - const off_t len_ = 0); -} diff --git a/src/fs_base_fallocate_posix.icpp b/src/fs_base_fallocate_posix.icpp deleted file mode 100644 index 4af1183e..00000000 --- a/src/fs_base_fallocate_posix.icpp +++ /dev/null @@ -1,33 +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. -*/ - -#include - -#include "errno.hpp" - -namespace fs -{ - int - 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))); - } -} 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_clonefile.hpp b/src/fs_clonefile.hpp index 42ff0278..a9835e57 100644 --- a/src/fs_clonefile.hpp +++ b/src/fs_clonefile.hpp @@ -19,6 +19,6 @@ namespace fs { int - clonefile(const int src_fd_, - const int dst_fd_); + clonefile(const int src_fd, + const int dst_fd); } 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_copy_file_range.cpp b/src/fs_copy_file_range.cpp index 41300db5..84372ab7 100644 --- a/src/fs_copy_file_range.cpp +++ b/src/fs_copy_file_range.cpp @@ -17,7 +17,9 @@ */ #ifdef __linux__ -# include "fs_copy_file_range_linux.icpp" +#warning "using fs_copy_file_range_linux.icpp" +#include "fs_copy_file_range_linux.icpp" #else -# include "fs_copy_file_range_unsupported.icpp" +#warning "using fs_copy_file_range_unsupported.icpp" +#include "fs_copy_file_range_unsupported.icpp" #endif 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 59bea813..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); @@ -115,17 +116,17 @@ namespace fs dst_fullpath = src_fullpath_; - dst_fd = fs::mktemp(dst_fullpath,O_WRONLY); + 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_cow.hpp b/src/fs_cow.hpp index 8d41fdb4..5cb9353d 100644 --- a/src/fs_cow.hpp +++ b/src/fs_cow.hpp @@ -25,12 +25,12 @@ namespace fs { namespace cow { - bool is_eligible(const int flags_); - bool is_eligible(const struct stat &st_); - bool is_eligible(const int flags_, const struct stat &st_); + bool is_eligible(const int flags); + bool is_eligible(const struct stat &st); + bool is_eligible(const int flags, const struct stat &st); - bool is_eligible(const char *fullpath_, const int flags_); + bool is_eligible(const char *fullpath, const int flags); - int break_link(const char *fullpath_); + int break_link(const char *fullpath); } } 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 0c62846e..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 @@ -70,7 +70,7 @@ namespace fs { std::string fullpath; - fullpath = fs::path::make(&basepath_,relpath_); + fullpath = fs::path::make(basepath_,relpath_); return fs::exists(fullpath,st_); } 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 ba614afb..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 65% rename from src/fs_base_fadvise.cpp rename to src/fs_fadvise.cpp index 8b5248d9..630df585 100644 --- a/src/fs_base_fadvise.cpp +++ b/src/fs_fadvise.cpp @@ -17,9 +17,11 @@ #include #if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L -# include "fs_base_fadvise_posix.icpp" +#warning "using fs_fadvise_posix.icpp" +#include "fs_fadvise_posix.icpp" #else -# include "fs_base_fadvise_unsupported.icpp" +#warning "using fs_fadvise_unsupported.icpp" +#include "fs_fadvise_unsupported.icpp" #endif #ifndef POSIX_FADV_NORMAL @@ -49,26 +51,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_fadvise.hpp b/src/fs_fadvise.hpp new file mode 100644 index 00000000..96fa8360 --- /dev/null +++ b/src/fs_fadvise.hpp @@ -0,0 +1,37 @@ +/* + 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 +{ + int + fadvise_dontneed(const int fd, + const off_t offset = 0, + const off_t len = 0); + + int + fadvise_willneed(const int fd, + const off_t offset = 0, + const off_t len = 0); + + int + fadvise_sequential(const int fd, + const off_t offset = 0, + const off_t len = 0); +} 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_unsupported.icpp b/src/fs_fallocate.hpp similarity index 90% rename from src/fs_base_fallocate_unsupported.icpp rename to src/fs_fallocate.hpp index e5cae483..d6691472 100644 --- a/src/fs_base_fallocate_unsupported.icpp +++ b/src/fs_fallocate.hpp @@ -14,7 +14,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "errno.hpp" +#pragma once + +#include namespace fs { @@ -22,8 +24,5 @@ namespace fs fallocate(const int fd, const int mode, const off_t offset, - const off_t len) - { - return (errno=EOPNOTSUPP,-1); - } + const off_t len); } diff --git a/src/fs_base_fallocate.hpp b/src/fs_fallocate_linux.icpp similarity index 91% rename from src/fs_base_fallocate.hpp rename to src/fs_fallocate_linux.icpp index cd10cbb2..ae274eeb 100644 --- a/src/fs_base_fallocate.hpp +++ b/src/fs_fallocate_linux.icpp @@ -14,8 +14,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma once - #include namespace fs @@ -24,5 +22,8 @@ namespace fs fallocate(const int fd_, const int mode_, const off_t offset_, - const off_t len_); + const off_t 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_linux.icpp b/src/fs_fallocate_posix.icpp similarity index 79% rename from src/fs_base_fallocate_linux.icpp rename to src/fs_fallocate_posix.icpp index 84e454a1..17f99e95 100644 --- a/src/fs_base_fallocate_linux.icpp +++ b/src/fs_fallocate_posix.icpp @@ -14,18 +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 ::fallocate(fd,mode,offset,len); + if(mode_) + return (errno=EOPNOTSUPP,-1); + + return ::posix_fallocate(fd_,offset_,len_); } } diff --git a/src/fs_fallocate_unsupported.icpp b/src/fs_fallocate_unsupported.icpp new file mode 100644 index 00000000..9c913e84 --- /dev/null +++ b/src/fs_fallocate_unsupported.icpp @@ -0,0 +1,29 @@ +/* + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "errno.hpp" + +namespace fs +{ + int + 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.cpp b/src/fs_ficlone.cpp index 023345d2..58310e20 100644 --- a/src/fs_ficlone.cpp +++ b/src/fs_ficlone.cpp @@ -17,7 +17,9 @@ */ #ifdef __linux__ -# include "fs_ficlone_linux.icpp" +#warning "using fs_ficlone_linux.icpp" +#include "fs_ficlone_linux.icpp" #else -# include "fs_ficlone_unsupported.icpp" +#warning "using fs_ficlone_unsupported.icpp" +#include "fs_ficlone_unsupported.icpp" #endif diff --git a/src/fs_ficlone.hpp b/src/fs_ficlone.hpp index 879ca3ad..6900a82b 100644 --- a/src/fs_ficlone.hpp +++ b/src/fs_ficlone.hpp @@ -21,6 +21,6 @@ namespace fs { int - ficlone(const int src_fd_, - const int dst_fd_); + ficlone(const int src_fd, + const int dst_fd); } 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_findallfiles.cpp b/src/fs_findallfiles.cpp new file mode 100644 index 00000000..a7a60d42 --- /dev/null +++ b/src/fs_findallfiles.cpp @@ -0,0 +1,44 @@ +/* + 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_exists.hpp" +#include "fs_path.hpp" + +#include +#include + +namespace fs +{ + void + findallfiles(const std::vector &basepaths_, + const char *fusepath_, + std::vector *paths_) + { + std::string fullpath; + + for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + { + fullpath = fs::path::make(basepaths_[i],fusepath_); + + if(!fs::exists(fullpath)) + continue; + + paths_->push_back(fullpath); + } + } +} diff --git a/src/fs_findallfiles.hpp b/src/fs_findallfiles.hpp new file mode 100644 index 00000000..ff3d81ed --- /dev/null +++ b/src/fs_findallfiles.hpp @@ -0,0 +1,30 @@ +/* + 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 + +namespace fs +{ + void + findallfiles(const std::vector &basepaths, + const char *fusepath, + std::vector *paths); +} 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 68% rename from src/fs_base_fstatat.hpp rename to src/fs_fstatat.hpp index 5429c50a..6148d9d5 100644 --- a/src/fs_base_fstatat.hpp +++ b/src/fs_fstatat.hpp @@ -28,27 +28,27 @@ namespace fs static inline int - fstatat(const int dirfd, - const char *pathname, - struct stat *statbuf, - const int flags) + fstatat(const int dirfd_, + const char *pathname_, + struct stat *statbuf_, + const int flags_) { - return ::fstatat(dirfd, - pathname, - statbuf, - flags); + return ::fstatat(dirfd_, + pathname_, + statbuf_, + flags_); } static inline int - fstatat_nofollow(const int dirfd, - const char *pathname, - struct stat *statbuf) + fstatat_nofollow(const int dirfd_, + const char *pathname_, + struct stat *statbuf_) { - return fs::fstatat(dirfd, - pathname, - statbuf, + return fs::fstatat(dirfd_, + pathname_, + statbuf_, AT_SYMLINK_NOFOLLOW); } } 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..9f223303 --- /dev/null +++ b/src/fs_futimens.hpp @@ -0,0 +1,51 @@ +/* + 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__ +#warning "using fs_futimens_linux.hpp" +#include "fs_futimens_linux.hpp" +#elif __FreeBSD__ >= 11 +#warning "using fs_futimens_freebsd_11.hpp" +#include "fs_futimens_freebsd_11.hpp" +#else +#warning "using fs_futimens_generic.hpp" +#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 84% rename from src/fs_base_futimesat.cpp rename to src/fs_futimesat.cpp index c254f4b9..67867e15 100644 --- a/src/fs_base_futimesat.cpp +++ b/src/fs_futimesat.cpp @@ -17,7 +17,9 @@ */ #if __APPLE__ -# include "fs_base_futimesat_osx.icpp" +#warning "using fs_futimesat_osx.icpp" +#include "fs_futimesat_osx.icpp" #else -# include "fs_base_futimesat_generic.icpp" +#warning "using fs_futimesat_generic.icpp" +#include "fs_futimesat_generic.icpp" #endif diff --git a/src/fs_base_futimesat_generic.icpp b/src/fs_futimesat.hpp similarity index 88% rename from src/fs_base_futimesat_generic.icpp rename to src/fs_futimesat.hpp index bfcd5e57..d18c44c4 100644 --- a/src/fs_base_futimesat_generic.icpp +++ b/src/fs_futimesat.hpp @@ -16,7 +16,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#pragma once + #include namespace fs @@ -24,8 +25,5 @@ namespace fs int futimesat(const int dirfd, const char *pathname, - const struct timeval times[2]) - { - return ::futimesat(dirfd,pathname,times); - } + const struct timeval times[2]); } diff --git a/src/fs_base_futimesat.hpp b/src/fs_futimesat_generic.icpp similarity index 88% rename from src/fs_base_futimesat.hpp rename to src/fs_futimesat_generic.icpp index a6de50a4..4f2b2134 100644 --- a/src/fs_base_futimesat.hpp +++ b/src/fs_futimesat_generic.icpp @@ -16,8 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma once - +#include #include namespace fs @@ -25,5 +24,8 @@ namespace fs int futimesat(const int dirfd_, const char *pathname_, - const struct timeval times_[2]); + const struct timeval times_[2]) + { + 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 1805a78d..a955fa12 100644 --- a/src/fs_base_getdents.cpp +++ b/src/fs_getdents64.cpp @@ -26,9 +26,9 @@ namespace fs { int - getdents(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_getdents64.hpp b/src/fs_getdents64.hpp new file mode 100644 index 00000000..e1c12d6a --- /dev/null +++ b/src/fs_getdents64.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 + +namespace fs +{ + int + getdents_64(unsigned int fd, + void *dirp, + unsigned int count); +} diff --git a/src/fs_getfl.cpp b/src/fs_getfl.cpp new file mode 100644 index 00000000..891561db --- /dev/null +++ b/src/fs_getfl.cpp @@ -0,0 +1,28 @@ +/* + 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 + +namespace fs +{ + int + getfl(const int fd_) + { + return ::fcntl(fd_,F_GETFL,0); + } +} diff --git a/src/fs_getfl.hpp b/src/fs_getfl.hpp new file mode 100644 index 00000000..ddb30034 --- /dev/null +++ b/src/fs_getfl.hpp @@ -0,0 +1,24 @@ +/* + 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 + +namespace fs +{ + int getfl(const int fd); +} diff --git a/src/fs_glob.cpp b/src/fs_glob.cpp index 4cf08a66..02efe6c5 100644 --- a/src/fs_glob.cpp +++ b/src/fs_glob.cpp @@ -28,7 +28,7 @@ namespace fs { void glob(const string &pattern_, - vector &strs_) + vector *strs_) { int flags; glob_t gbuf = {0}; @@ -37,7 +37,7 @@ namespace fs ::glob(pattern_.c_str(),flags,NULL,&gbuf); for(size_t i = 0; i < gbuf.gl_pathc; i++) - strs_.push_back(gbuf.gl_pathv[i]); + strs_->push_back(gbuf.gl_pathv[i]); ::globfree(&gbuf); } diff --git a/src/fs_glob.hpp b/src/fs_glob.hpp index 4f5f92d3..ed16c95c 100644 --- a/src/fs_glob.hpp +++ b/src/fs_glob.hpp @@ -22,6 +22,6 @@ namespace fs { void - glob(const std::string &pattern_, - std::vector &strs_); + glob(const std::string &pattern, + std::vector *strs); } 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 1c29c205..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" @@ -32,13 +32,13 @@ using std::string; namespace fs { int - info(const string *path_, + info(const string &path_, fs::info_t *info_) { int rv; struct statvfs st; - rv = fs::statvfs_cache(path_->c_str(),&st); + rv = fs::statvfs_cache(path_.c_str(),&st); if(rv == 0) { info_->readonly = StatVFS::readonly(st); diff --git a/src/fs_info.hpp b/src/fs_info.hpp index 0dd8ed2e..cc8639a3 100644 --- a/src/fs_info.hpp +++ b/src/fs_info.hpp @@ -25,6 +25,6 @@ namespace fs { int - info(const std::string *path_, - fs::info_t *info_); + info(const std::string &path, + fs::info_t *info); } 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 c0e34353..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 @@ -48,7 +48,7 @@ generate_tmp_path(const string &base_) namespace fs { int - mktemp(string &base_, + mktemp(string *base_, const int flags_) { int fd; @@ -61,13 +61,13 @@ namespace fs flags = (flags_ | O_EXCL | O_CREAT); while(count-- > 0) { - tmppath = generate_tmp_path(base_); + tmppath = generate_tmp_path(*base_); fd = fs::open(tmppath,flags,S_IWUSR); if((fd == -1) && (errno == EEXIST)) continue; else if(fd != -1) - base_ = tmppath; + *base_ = tmppath; return fd; } diff --git a/src/fs_mktemp.hpp b/src/fs_mktemp.hpp index 64aaa5f8..2bd19b16 100644 --- a/src/fs_mktemp.hpp +++ b/src/fs_mktemp.hpp @@ -23,6 +23,6 @@ namespace fs { int - mktemp(std::string &base_, - const int flags_); + mktemp(std::string *base, + const int flags); } diff --git a/src/fs_movefile.cpp b/src/fs_movefile.cpp index 4cfdc3bc..059e044f 100644 --- a/src/fs_movefile.cpp +++ b/src/fs_movefile.cpp @@ -15,19 +15,19 @@ */ #include "errno.hpp" -#include "fs.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" @@ -97,7 +97,7 @@ namespace l fs::path::append(fdout_path[0],fusepath_); fdout_temp = fdout_path[0]; - fdout = fs::mktemp(fdout_temp,fdin_flags); + fdout = fs::mktemp(&fdout_temp,fdin_flags); if(fdout == -1) return -1; 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_path.hpp b/src/fs_path.hpp index 6c117469..531c21df 100644 --- a/src/fs_path.hpp +++ b/src/fs_path.hpp @@ -23,39 +23,37 @@ namespace fs { namespace path { - using std::string; + std::string dirname(const char *path); + std::string dirname(const std::string &path); - string dirname(const char *path); - string dirname(const string &path); - - string basename(const string &path); + std::string basename(const std::string &path); static inline void - append(string &base, - const char *suffix) + append(std::string &base_, + const char *suffix_) { - base += suffix; + base_ += suffix_; } static inline void - append(string &base, - const string &suffix) + append(std::string &base_, + const std::string &suffix_) { - base += suffix; + base_ += suffix_; } static inline - string + std::string make(const char *base_, const char *suffix_) { char back; - string path(base_); + std::string path(base_); back = *path.rbegin(); if((back != '/') && (suffix_[0] != '/')) @@ -67,36 +65,18 @@ namespace fs static inline - string - make(const string &base_, - const char *suffix_) + std::string + make(const std::string &base_, + const char *suffix_) { return (base_ + suffix_); } static inline - string - make(const string *base_, - const char *suffix_) - { - return (*base_ + suffix_); - } - - static - inline - string - make(const string *base_, - const string *suffix_) - { - return (*base_ + *suffix_); - } - - static - inline - string - make(const string &base_, - const string &suffix_) + std::string + make(const std::string &base_, + const std::string &suffix_) { return (base_ + suffix_); } 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 new file mode 100644 index 00000000..42db33b6 --- /dev/null +++ b/src/fs_realpathize.cpp @@ -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. +*/ + +#include "fs_realpath.hpp" + +#include +#include + +namespace fs +{ + void + realpathize(std::vector *strs_) + { + char *rv; + + for(size_t i = 0; i < strs_->size(); i++) + { + rv = fs::realpath((*strs_)[i]); + if(rv == NULL) + continue; + + (*strs_)[i] = rv; + + ::free(rv); + } + } +} diff --git a/src/fs_realpathize.hpp b/src/fs_realpathize.hpp new file mode 100644 index 00000000..dfd6270d --- /dev/null +++ b/src/fs_realpathize.hpp @@ -0,0 +1,28 @@ +/* + 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 + +namespace fs +{ + void + realpathize(std::vector *strs); +} 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_sendfile.cpp b/src/fs_sendfile.cpp index 1af25458..3bb52dec 100644 --- a/src/fs_sendfile.cpp +++ b/src/fs_sendfile.cpp @@ -15,7 +15,9 @@ */ #ifdef __linux__ -# include "fs_sendfile_linux.icpp" +#warning "using fs_sendfile_linux.icpp" +#include "fs_sendfile_linux.icpp" #else -# include "fs_sendfile_unsupported.icpp" +#warning "using fs_sendfile_unsupported.icpp" +#include "fs_sendfile_unsupported.icpp" #endif diff --git a/src/fs_setfl.cpp b/src/fs_setfl.cpp new file mode 100644 index 00000000..faf1b2e4 --- /dev/null +++ b/src/fs_setfl.cpp @@ -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. +*/ + +#include + +namespace fs +{ + int + setfl(const int fd_, + const mode_t mode_) + { + return ::fcntl(fd_,F_SETFL,mode_); + } +} diff --git a/src/fs_base_getdents.hpp b/src/fs_setfl.hpp similarity index 90% rename from src/fs_base_getdents.hpp rename to src/fs_setfl.hpp index fbaed28f..9b146f10 100644 --- a/src/fs_base_getdents.hpp +++ b/src/fs_setfl.hpp @@ -18,10 +18,11 @@ #pragma once +#include + namespace fs { int - getdents(unsigned int fd, - void *dirp, - unsigned int count); + setfl(const int fd, + const mode_t mode); } 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_statvfs_cache.hpp b/src/fs_statvfs_cache.hpp index a97f4e60..1beb46f3 100644 --- a/src/fs_statvfs_cache.hpp +++ b/src/fs_statvfs_cache.hpp @@ -26,21 +26,21 @@ namespace fs uint64_t statvfs_cache_timeout(void); void - statvfs_cache_timeout(const uint64_t timeout_); + statvfs_cache_timeout(const uint64_t timeout); int - statvfs_cache(const char *path_, - struct statvfs *st_); + statvfs_cache(const char *path, + struct statvfs *st); int - statvfs_cache_readonly(const std::string &path_, - bool *readonly_); + statvfs_cache_readonly(const std::string &path, + bool *readonly); int - statvfs_cache_spaceavail(const std::string &path_, - uint64_t *spaceavail_); + statvfs_cache_spaceavail(const std::string &path, + uint64_t *spaceavail); int - statvfs_cache_spaceused(const std::string &path_, - uint64_t *spaceused_); + statvfs_cache_spaceused(const std::string &path, + uint64_t *spaceused); } 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..bd44fdf7 --- /dev/null +++ b/src/fs_utimensat.hpp @@ -0,0 +1,30 @@ +/* + 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__ +#warning "using fs_utimensat_linux.hpp" +#include "fs_utimensat_linux.hpp" +#elif __FreeBSD__ +#warning "using fs_utimensat_freebsd.hpp" +#include "fs_utimensat_freebsd.hpp" +#else +#warning "using fs_utimensat_generic.hpp" +#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 76% rename from src/fs_base_write.hpp rename to src/fs_write.hpp index d5463205..96eebbb1 100644 --- a/src/fs_base_write.hpp +++ b/src/fs_write.hpp @@ -25,21 +25,21 @@ namespace fs static inline ssize_t - write(const int fd, - const void *buf, - const size_t count) + write(const int fd_, + const void *buf_, + const size_t count_) { - return ::write(fd,buf,count); + return ::write(fd_,buf_,count_); } static inline ssize_t - pwrite(const int fd, - const void *buf, - const size_t count, - const off_t offset) + pwrite(const int fd_, + const void *buf_, + const size_t count_, + const off_t offset_) { - return ::pwrite(fd,buf,count,offset); + return ::pwrite(fd_,buf_,count_,offset_); } } diff --git a/src/fs_xattr.cpp b/src/fs_xattr.cpp index f2b52a04..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; @@ -39,8 +42,8 @@ namespace fs namespace xattr { int - list(const int fd, - vector &attrs) + list(const int fd_, + vector *attrs_) { ssize_t rv; @@ -48,21 +51,21 @@ namespace fs errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = fs::flistxattr(fd,NULL,0); + rv = fs::flistxattr(fd_,NULL,0); if(rv <= 0) return rv; - attrs.resize(rv); + attrs_->resize(rv); - rv = fs::flistxattr(fd,&attrs[0],rv); + rv = fs::flistxattr(fd_,&(*attrs_)[0],rv); } return rv; } int - list(const string &path, - vector &attrs) + list(const string &path_, + vector *attrs_) { ssize_t rv; @@ -70,84 +73,84 @@ namespace fs errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = fs::llistxattr(path,NULL,0); + rv = fs::llistxattr(path_,NULL,0); if(rv <= 0) return rv; - attrs.resize(rv); + attrs_->resize(rv); - rv = fs::llistxattr(path,&attrs[0],rv); + rv = fs::llistxattr(path_,&(*attrs_)[0],rv); } return rv; } int - list(const int fd, - vector &attrvector) + list(const int fd_, + vector *attrvector_) { int rv; vector attrs; - rv = list(fd,attrs); + rv = fs::xattr::list(fd_,&attrs); if(rv != -1) { string tmp(attrs.begin(),attrs.end()); - str::split(attrvector,tmp,'\0'); + str::split(tmp,'\0',attrvector_); } return rv; } int - list(const string &path, - vector &attrvector) + list(const string &path_, + vector *attrvector_) { int rv; vector attrs; - rv = list(path,attrs); + rv = fs::xattr::list(path_,&attrs); if(rv != -1) { string tmp(attrs.begin(),attrs.end()); - str::split(attrvector,tmp,'\0'); + str::split(tmp,'\0',attrvector_); } return rv; } int - list(const int fd, - string &attrstr) + list(const int fd_, + string *attrstr_) { int rv; vector attrs; - rv = list(fd,attrs); + rv = fs::xattr::list(fd_,&attrs); if(rv != -1) - attrstr = string(attrs.begin(),attrs.end()); + *attrstr_ = string(attrs.begin(),attrs.end()); return rv; } int - list(const string &path, - string &attrstr) + list(const string &path_, + string *attrstr_) { int rv; vector attrs; - rv = list(path,attrs); + rv = fs::xattr::list(path_,&attrs); if(rv != -1) - attrstr = string(attrs.begin(),attrs.end()); + *attrstr_ = string(attrs.begin(),attrs.end()); return rv; } int - get(const int fd, - const string &attr, - vector &value) + get(const int fd_, + const string &attr_, + vector *value_) { ssize_t rv; @@ -155,22 +158,22 @@ namespace fs errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = fs::fgetxattr(fd,attr,NULL,0); + rv = fs::fgetxattr(fd_,attr_,NULL,0); if(rv <= 0) return rv; - value.resize(rv); + value_->resize(rv); - rv = fs::fgetxattr(fd,attr,&value[0],rv); + rv = fs::fgetxattr(fd_,attr_,&(*value_)[0],rv); } return rv; } int - get(const string &path, - const string &attr, - vector &value) + get(const string &path_, + const string &attr_, + vector *value_) { ssize_t rv; @@ -178,56 +181,56 @@ namespace fs errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = fs::lgetxattr(path,attr,NULL,0); + rv = fs::lgetxattr(path_,attr_,NULL,0); if(rv <= 0) return rv; - value.resize(rv); + value_->resize(rv); - rv = fs::lgetxattr(path,attr,&value[0],rv); + rv = fs::lgetxattr(path_,attr_,&(*value_)[0],rv); } return rv; } int - get(const int fd, - const string &attr, - string &value) + get(const int fd_, + const string &attr_, + string *value_) { int rv; vector tmpvalue; - rv = get(fd,attr,tmpvalue); + rv = get(fd_,attr_,&tmpvalue); if(rv != -1) - value = string(tmpvalue.begin(),tmpvalue.end()); + *value_ = string(tmpvalue.begin(),tmpvalue.end()); return rv; } int - get(const string &path, - const string &attr, - string &value) + get(const string &path_, + const string &attr_, + string *value_) { int rv; vector tmpvalue; - rv = get(path,attr,tmpvalue); + rv = fs::xattr::get(path_,attr_,&tmpvalue); if(rv != -1) - value = string(tmpvalue.begin(),tmpvalue.end()); + *value_ = string(tmpvalue.begin(),tmpvalue.end()); return rv; } int - get(const int fd, - map &attrs) + get(const int fd_, + map *attrs_) { int rv; string attrstr; - rv = list(fd,attrstr); + rv = fs::xattr::list(fd_,&attrstr); if(rv == -1) return -1; @@ -239,9 +242,9 @@ namespace fs { string value; - rv = get(fd,key,value); + rv = fs::xattr::get(fd_,key,&value); if(rv != -1) - attrs[key] = value; + (*attrs_)[key] = value; } } @@ -249,13 +252,13 @@ namespace fs } int - get(const string &path, - map &attrs) + get(const string &path_, + map *attrs_) { int rv; string attrstr; - rv = list(path,attrstr); + rv = fs::xattr::list(path_,&attrstr); if(rv == -1) return -1; @@ -267,9 +270,9 @@ namespace fs { string value; - rv = get(path,key,value); + rv = fs::xattr::get(path_,key,&value); if(rv != -1) - attrs[key] = value; + (*attrs_)[key] = value; } } @@ -277,41 +280,41 @@ namespace fs } int - set(const int fd, - const string &key, - const string &value, - const int flags) + set(const int fd_, + const string &key_, + const string &value_, + const int flags_) { - return fs::fsetxattr(fd, - key.c_str(), - value.data(), - value.size(), - flags); + return fs::fsetxattr(fd_, + key_, + value_.data(), + value_.size(), + flags_); } int - set(const string &path, - const string &key, - const string &value, - const int flags) + set(const string &path_, + const string &key_, + const string &value_, + const int flags_) { - return fs::lsetxattr(path, - key, - value.data(), - value.size(), - flags); + return fs::lsetxattr(path_, + key_, + value_.data(), + value_.size(), + flags_); } int - set(const int fd, - const map &attrs) + set(const int fd_, + const map &attrs_) { int rv; for(map::const_iterator - i = attrs.begin(), ei = attrs.end(); i != ei; ++i) + i = attrs_.begin(), ei = attrs_.end(); i != ei; ++i) { - rv = set(fd,i->first,i->second,0); + rv = fs::xattr::set(fd_,i->first,i->second,0); if(rv == -1) return -1; } @@ -320,46 +323,46 @@ namespace fs } int - set(const string &path, - const map &attrs) + set(const string &path_, + const map &attrs_) { int fd; - fd = fs::open(path,O_RDONLY|O_NONBLOCK); + fd = fs::open(path_,O_RDONLY|O_NONBLOCK); if(fd == -1) return -1; - set(fd,attrs); + fs::xattr::set(fd,attrs_); return fs::close(fd); } int - copy(const int fdin, - const int fdout) + copy(const int fdin_, + const int fdout_) { int rv; map attrs; - rv = get(fdin,attrs); + rv = fs::xattr::get(fdin_,&attrs); if(rv == -1) return -1; - return set(fdout,attrs); + return fs::xattr::set(fdout_,attrs); } int - copy(const string &from, - const string &to) + copy(const string &from_, + const string &to_) { int rv; map attrs; - rv = get(from,attrs); + rv = fs::xattr::get(from_,&attrs); if(rv == -1) return -1; - return set(to,attrs); + return fs::xattr::set(to_,attrs); } } } diff --git a/src/fs_xattr.hpp b/src/fs_xattr.hpp index cff2eacd..caad0749 100644 --- a/src/fs_xattr.hpp +++ b/src/fs_xattr.hpp @@ -30,21 +30,21 @@ namespace fs int list(const string &path, - vector &attrs); + vector *attrs); int list(const string &path, - string &attrs); + string *attrs); int list(const string &path, - vector &attrs); + vector *attrs); int get(const string &path, const string &attr, - vector &value); + vector *value); int get(const string &path, const string &attr, - string &value); + string *value); int get(const string &path, - map &attrs); + map *attrs); int set(const string &path, const string &key, 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_access.hpp b/src/fuse_access.hpp index f1586a69..7fc64277 100644 --- a/src/fuse_access.hpp +++ b/src/fuse_access.hpp @@ -19,6 +19,6 @@ namespace FUSE { int - access(const char *fusepath_, - int mask_); + access(const char *fusepath, + int mask); } 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_chmod.hpp b/src/fuse_chmod.hpp index 6466036b..6bbcdb40 100644 --- a/src/fuse_chmod.hpp +++ b/src/fuse_chmod.hpp @@ -19,6 +19,6 @@ namespace FUSE { int - chmod(const char *fusepath_, - mode_t mode_); + chmod(const char *fusepath, + mode_t mode); } 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_chown.hpp b/src/fuse_chown.hpp index 189052af..cda0058d 100644 --- a/src/fuse_chown.hpp +++ b/src/fuse_chown.hpp @@ -19,7 +19,7 @@ namespace FUSE { int - chown(const char *fusepath_, - uid_t uid_, - gid_t gid_); + chown(const char *fusepath, + uid_t uid, + gid_t gid); } 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_create.hpp b/src/fuse_create.hpp index bf42d3d0..b5420118 100644 --- a/src/fuse_create.hpp +++ b/src/fuse_create.hpp @@ -23,7 +23,7 @@ namespace FUSE { int - create(const char *fusepath_, - mode_t mode_, - fuse_file_info *ffi_); + create(const char *fusepath, + mode_t mode, + fuse_file_info *ffi); } 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_fallocate.hpp b/src/fuse_fallocate.hpp index b00ef33f..94bc14e5 100644 --- a/src/fuse_fallocate.hpp +++ b/src/fuse_fallocate.hpp @@ -16,11 +16,13 @@ #pragma once +#include "fuse.h" + namespace FUSE { int - fallocate(int mode_, - off_t offset_, - off_t len_, - fuse_file_info *ffi_); + fallocate(int mode, + off_t offset, + off_t len, + fuse_file_info *ffi); } 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_fchmod.hpp b/src/fuse_fchmod.hpp index 20cd0f28..17535416 100644 --- a/src/fuse_fchmod.hpp +++ b/src/fuse_fchmod.hpp @@ -23,6 +23,6 @@ namespace FUSE { int - fchmod(const struct fuse_file_info *ffi_, - const mode_t mode_); + fchmod(const fuse_file_info *ffi, + const mode_t mode); } 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_fchown.hpp b/src/fuse_fchown.hpp index 2684d6e5..5a7bb401 100644 --- a/src/fuse_fchown.hpp +++ b/src/fuse_fchown.hpp @@ -21,7 +21,7 @@ namespace FUSE { int - fchown(const struct fuse_file_info *ffi_, - uid_t uid_, - gid_t gid_); + fchown(const fuse_file_info *ffi, + uid_t uid, + gid_t gid); } 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_flock.hpp b/src/fuse_flock.hpp index fdf12f45..a1124677 100644 --- a/src/fuse_flock.hpp +++ b/src/fuse_flock.hpp @@ -21,7 +21,7 @@ namespace FUSE { int - flock(const char *fusepath_, - fuse_file_info *ffi_, - int op_); + flock(const char *fusepath, + fuse_file_info *ffi, + int op); } 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_flush.hpp b/src/fuse_flush.hpp index 1785a2c5..b13d21f7 100644 --- a/src/fuse_flush.hpp +++ b/src/fuse_flush.hpp @@ -21,5 +21,5 @@ namespace FUSE { int - flush(fuse_file_info *ffi_); + flush(fuse_file_info *ffi); } 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_free_hide.hpp b/src/fuse_free_hide.hpp index 3419894a..c8f7c471 100644 --- a/src/fuse_free_hide.hpp +++ b/src/fuse_free_hide.hpp @@ -23,5 +23,5 @@ namespace FUSE { int - free_hide(const uint64_t fh_); + free_hide(const uint64_t fh); } 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_fsync.hpp b/src/fuse_fsync.hpp index 6323ab21..9f05ff48 100644 --- a/src/fuse_fsync.hpp +++ b/src/fuse_fsync.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - fsync(int isdatasync_, - fuse_file_info *ffi_); + fsync(int isdatasync, + fuse_file_info *ffi); } 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_fsyncdir.hpp b/src/fuse_fsyncdir.hpp index 4cf878ef..677dea7c 100644 --- a/src/fuse_fsyncdir.hpp +++ b/src/fuse_fsyncdir.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - fsyncdir(int isdatasync_, - fuse_file_info *ffi_); + fsyncdir(int isdatasync, + fuse_file_info *ffi); } 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_ftruncate.hpp b/src/fuse_ftruncate.hpp index 65e0e283..312764c9 100644 --- a/src/fuse_ftruncate.hpp +++ b/src/fuse_ftruncate.hpp @@ -24,6 +24,6 @@ namespace FUSE { int - ftruncate(off_t size_, - fuse_file_info *ffi_); + ftruncate(off_t size, + fuse_file_info *ffi); } 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_futimens.hpp b/src/fuse_futimens.hpp index 52eef8e6..100c8bca 100644 --- a/src/fuse_futimens.hpp +++ b/src/fuse_futimens.hpp @@ -23,6 +23,6 @@ namespace FUSE { int - futimens(const struct fuse_file_info *ffi_, - const timespec ts_[2]); + futimens(const fuse_file_info *ffi, + const timespec ts[2]); } 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 4ff08e1b..1493f995 100644 --- a/src/fuse_getxattr.cpp +++ b/src/fuse_getxattr.cpp @@ -16,7 +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" @@ -63,10 +64,10 @@ namespace l static int - getxattr_controlfile(const Config &config, - const char *attrname, - char *buf, - const size_t count) + getxattr_controlfile(const Config &config_, + const char *attrname_, + char *buf_, + const size_t count_) { int rv; size_t len; @@ -74,42 +75,42 @@ namespace l string val; vector attr; - if(!str::startswith(attrname,"user.mergerfs.")) + if(!str::startswith(attrname_,"user.mergerfs.")) return -ENOATTR; - key = &attrname[14]; - rv = config.get(key,&val); + key = &attrname_[14]; + rv = config_.get(key,&val); if(rv < 0) return rv; len = val.size(); - if(count == 0) + if(count_ == 0) return len; - if(count < len) + if(count_ < len) return -ERANGE; - memcpy(buf,val.c_str(),len); + memcpy(buf_,val.c_str(),len); return (int)len; } static int - getxattr_from_string(char *destbuf, - const size_t destbufsize, - const string &src) + getxattr_from_string(char *destbuf_, + const size_t destbufsize_, + const string &src_) { - const size_t srcbufsize = src.size(); + const size_t srcbufsize = src_.size(); - if(destbufsize == 0) + if(destbufsize_ == 0) return srcbufsize; - if(srcbufsize > destbufsize) + if(srcbufsize > destbufsize_) return -ERANGE; - memcpy(destbuf,src.data(),srcbufsize); + memcpy(destbuf_,src_.data(),srcbufsize); return srcbufsize; } @@ -117,9 +118,9 @@ namespace l static int getxattr_user_mergerfs_allpaths(const Branches &branches_, - const char *fusepath, - char *buf, - const size_t count) + const char *fusepath_, + char *buf_, + const size_t count_) { string concated; vector paths; @@ -127,90 +128,90 @@ namespace l branches_.to_paths(branches); - fs::findallfiles(branches,fusepath,paths); + fs::findallfiles(branches,fusepath_,&paths); concated = str::join(paths,'\0'); - return l::getxattr_from_string(buf,count,concated); + return l::getxattr_from_string(buf_,count_,concated); } static int - getxattr_user_mergerfs(const string &basepath, - const char *fusepath, - const string &fullpath, + getxattr_user_mergerfs(const string &basepath_, + const char *fusepath_, + const string &fullpath_, const Branches &branches_, - const char *attrname, - char *buf, - const size_t count) + const char *attrname_, + char *buf_, + const size_t count_) { vector attr; - str::split(attr,attrname,'.'); + str::split(attrname_,'.',&attr); if(attr[2] == "basepath") - return l::getxattr_from_string(buf,count,basepath); + return l::getxattr_from_string(buf_,count_,basepath_); else if(attr[2] == "relpath") - return l::getxattr_from_string(buf,count,fusepath); + return l::getxattr_from_string(buf_,count_,fusepath_); else if(attr[2] == "fullpath") - return l::getxattr_from_string(buf,count,fullpath); + return l::getxattr_from_string(buf_,count_,fullpath_); else if(attr[2] == "allpaths") - return l::getxattr_user_mergerfs_allpaths(branches_,fusepath,buf,count); + return l::getxattr_user_mergerfs_allpaths(branches_,fusepath_,buf_,count_); return -ENOATTR; } static int - getxattr(Policy::Func::Search searchFunc, + getxattr(Policy::Func::Search searchFunc_, const Branches &branches_, - const size_t minfreespace, - const char *fusepath, - const char *attrname, - char *buf, - const size_t count) + const size_t minfreespace_, + const char *fusepath_, + const char *attrname_, + char *buf_, + const size_t count_) { int rv; string fullpath; vector basepaths; - rv = searchFunc(branches_,fusepath,minfreespace,&basepaths); + rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath); + fullpath = fs::path::make(basepaths[0],fusepath_); - if(str::startswith(attrname,"user.mergerfs.")) + if(str::startswith(attrname_,"user.mergerfs.")) return l::getxattr_user_mergerfs(basepaths[0], - fusepath, + fusepath_, fullpath, branches_, - attrname, - buf, - count); + attrname_, + buf_, + count_); - return l::lgetxattr(fullpath,attrname,buf,count); + return l::lgetxattr(fullpath,attrname_,buf_,count_); } } namespace FUSE { int - getxattr(const char *fusepath, - const char *attrname, - char *buf, - size_t count) + getxattr(const char *fusepath_, + const char *attrname_, + char *buf_, + size_t count_) { const Config &config = Config::ro(); - if(fusepath == config.controlfile) + if(fusepath_ == config.controlfile) return l::getxattr_controlfile(config, - attrname, - buf, - count); + attrname_, + buf_, + count_); if((config.security_capability == false) && - l::is_attrname_security_capability(attrname)) + l::is_attrname_security_capability(attrname_)) return -ENOATTR; if(config.xattr.to_int()) @@ -222,9 +223,9 @@ namespace FUSE return l::getxattr(config.func.getxattr.policy, config.branches, config.minfreespace, - fusepath, - attrname, - buf, - count); + fusepath_, + attrname_, + buf_, + count_); } } diff --git a/src/fuse_getxattr.hpp b/src/fuse_getxattr.hpp index 854e26e8..4ff565c0 100644 --- a/src/fuse_getxattr.hpp +++ b/src/fuse_getxattr.hpp @@ -19,8 +19,8 @@ namespace FUSE { int - getxattr(const char *fusepath_, - const char *attrname_, - char *buf_, - size_t count_); + getxattr(const char *fusepath, + const char *attrname, + char *buf, + size_t count); } diff --git a/src/fuse_init.hpp b/src/fuse_init.hpp index ea8f0d39..d36b9070 100644 --- a/src/fuse_init.hpp +++ b/src/fuse_init.hpp @@ -21,5 +21,5 @@ namespace FUSE { void * - init(fuse_conn_info *conn_); + init(fuse_conn_info *conn); } diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index 858f6b63..2bbf94c3 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -19,9 +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" @@ -344,7 +345,7 @@ namespace l config.branches.to_paths(branches); - fs::findallfiles(branches,fusepath.c_str(),paths); + fs::findallfiles(branches,fusepath.c_str(),&paths); concated = str::join(paths,'\0'); diff --git a/src/fuse_ioctl.hpp b/src/fuse_ioctl.hpp index 23550d58..67db5355 100644 --- a/src/fuse_ioctl.hpp +++ b/src/fuse_ioctl.hpp @@ -21,10 +21,10 @@ namespace FUSE { int - ioctl(unsigned long cmd_, - void *arg_, - fuse_file_info *ffi_, - unsigned int flags_, - void *data_, - uint32_t *out_bufsz_); + ioctl(unsigned long cmd, + void *arg, + fuse_file_info *ffi, + unsigned int flags, + void *data, + uint32_t *out_bufsz); } diff --git a/src/fuse_link.cpp b/src/fuse_link.cpp index fb44c539..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" @@ -44,8 +44,8 @@ namespace l string oldfullpath; string newfullpath; - oldfullpath = fs::path::make(&oldbasepath_,oldfusepath_); - newfullpath = fs::path::make(&oldbasepath_,newfusepath_); + oldfullpath = fs::path::make(oldbasepath_,oldfusepath_); + newfullpath = fs::path::make(oldbasepath_,newfusepath_); rv = fs::link(oldfullpath,newfullpath); @@ -152,8 +152,8 @@ namespace l string oldfullpath; string newfullpath; - oldfullpath = fs::path::make(&oldbasepath_,oldfusepath_); - newfullpath = fs::path::make(&oldbasepath_,newfusepath_); + oldfullpath = fs::path::make(oldbasepath_,oldfusepath_); + newfullpath = fs::path::make(oldbasepath_,newfusepath_); rv = fs::link(oldfullpath,newfullpath); if((rv == -1) && (errno == ENOENT)) diff --git a/src/fuse_link.hpp b/src/fuse_link.hpp index 843b752d..bb1eb2ec 100644 --- a/src/fuse_link.hpp +++ b/src/fuse_link.hpp @@ -19,6 +19,6 @@ namespace FUSE { int - link(const char *from_, - const char *to_); + link(const char *from, + const char *to); } 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_listxattr.hpp b/src/fuse_listxattr.hpp index 3ce0aec8..cef0b91c 100644 --- a/src/fuse_listxattr.hpp +++ b/src/fuse_listxattr.hpp @@ -19,7 +19,7 @@ namespace FUSE { int - listxattr(const char *fusepath_, - char *buf_, - size_t count_); + listxattr(const char *fusepath, + char *buf, + size_t count); } 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_mkdir.hpp b/src/fuse_mkdir.hpp index 4b8ee8a9..e70fa64e 100644 --- a/src/fuse_mkdir.hpp +++ b/src/fuse_mkdir.hpp @@ -19,6 +19,6 @@ namespace FUSE { int - mkdir(const char *fusepath_, - mode_t mode_); + mkdir(const char *fusepath, + mode_t mode); } diff --git a/src/fuse_mknod.cpp b/src/fuse_mknod.cpp index 236dae05..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" @@ -59,7 +59,7 @@ namespace l int rv; string fullpath; - fullpath = fs::path::make(&createpath_,fusepath_); + fullpath = fs::path::make(createpath_,fusepath_); rv = l::mknod_core(fullpath,mode_,umask_,dev_); diff --git a/src/fuse_mknod.hpp b/src/fuse_mknod.hpp index aba67b5a..adb56d8d 100644 --- a/src/fuse_mknod.hpp +++ b/src/fuse_mknod.hpp @@ -20,7 +20,7 @@ namespace FUSE { int - mknod(const char *fusepath_, - mode_t mode_, - dev_t rdev_); + mknod(const char *fusepath, + mode_t mode, + dev_t rdev); } 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_open.hpp b/src/fuse_open.hpp index 3a8c1662..bb20d86e 100644 --- a/src/fuse_open.hpp +++ b/src/fuse_open.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - open(const char *fusepath_, - fuse_file_info *ffi_); + open(const char *fusepath, + fuse_file_info *ffi); } diff --git a/src/fuse_opendir.hpp b/src/fuse_opendir.hpp index aedb2204..372dc389 100644 --- a/src/fuse_opendir.hpp +++ b/src/fuse_opendir.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - opendir(const char *fusepath_, - fuse_file_info *ffi_); + opendir(const char *fusepath, + fuse_file_info *ffi); } diff --git a/src/fuse_prepare_hide.hpp b/src/fuse_prepare_hide.hpp index 3756b5aa..696f5819 100644 --- a/src/fuse_prepare_hide.hpp +++ b/src/fuse_prepare_hide.hpp @@ -23,6 +23,6 @@ namespace FUSE { int - prepare_hide(const char *name_, - uint64_t *fh_); + prepare_hide(const char *name, + uint64_t *fh); } 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_read.hpp b/src/fuse_read.hpp index ac1ceddd..5276c0a6 100644 --- a/src/fuse_read.hpp +++ b/src/fuse_read.hpp @@ -21,14 +21,14 @@ namespace FUSE { int - read(char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_); + read(char *buf, + size_t count, + off_t offset, + fuse_file_info *ffi); int - read_null(char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_); + read_null(char *buf, + size_t count, + off_t offset, + fuse_file_info *ffi); } diff --git a/src/fuse_read_buf.hpp b/src/fuse_read_buf.hpp index a6f4ca6b..6c0ec316 100644 --- a/src/fuse_read_buf.hpp +++ b/src/fuse_read_buf.hpp @@ -23,8 +23,8 @@ namespace FUSE { int - read_buf(struct fuse_bufvec **buf_, - size_t size_, - off_t offset_, - fuse_file_info *ffi_); + read_buf(struct fuse_bufvec **buf, + size_t size, + off_t offset, + fuse_file_info *ffi); } diff --git a/src/fuse_readdir.hpp b/src/fuse_readdir.hpp index d9dbc593..1e87f932 100644 --- a/src/fuse_readdir.hpp +++ b/src/fuse_readdir.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - readdir(fuse_file_info *ffi_, - fuse_dirents_t *buf_); + readdir(fuse_file_info *ffi, + fuse_dirents_t *buf); } diff --git a/src/fuse_readdir_linux.cpp b/src/fuse_readdir_linux.cpp index b88a80c4..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" @@ -74,7 +74,7 @@ namespace l int dirfd; int64_t nread; - basepath = fs::path::make(&branches_[i].path,dirname_); + basepath = fs::path::make(branches_[i].path,dirname_); dirfd = fs::open_dir_ro(basepath); if(dirfd == -1) @@ -86,7 +86,7 @@ namespace l for(;;) { - nread = fs::getdents(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.hpp b/src/fuse_readdir_plus.hpp index 17f198e9..dd33c3da 100644 --- a/src/fuse_readdir_plus.hpp +++ b/src/fuse_readdir_plus.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - readdir_plus(fuse_file_info *ffi_, - fuse_dirents_t *buf_); + readdir_plus(fuse_file_info *ffi, + fuse_dirents_t *buf); } diff --git a/src/fuse_readdir_plus_linux.cpp b/src/fuse_readdir_plus_linux.cpp index 49103227..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" @@ -83,7 +83,7 @@ namespace l int dirfd; int64_t nread; - basepath = fs::path::make(&branches_[i].path,dirname_); + basepath = fs::path::make(branches_[i].path,dirname_); dirfd = fs::open_dir_ro(basepath); if(dirfd == -1) @@ -95,7 +95,7 @@ namespace l for(;;) { - nread = fs::getdents(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.hpp b/src/fuse_readdir_plus_linux.hpp index 132ca77a..68020b7f 100644 --- a/src/fuse_readdir_plus_linux.hpp +++ b/src/fuse_readdir_plus_linux.hpp @@ -27,9 +27,9 @@ namespace FUSE { int - readdir_plus_linux(const Branches &branches_, - const char *dirname_, - const uint64_t entry_timeout_, - const uint64_t attr_timeout_, - fuse_dirents_t *buf_); + readdir_plus_linux(const Branches &branches, + const char *dirname, + const uint64_t entry_timeout, + const uint64_t attr_timeout, + fuse_dirents_t *buf); } diff --git a/src/fuse_readdir_plus_posix.cpp b/src/fuse_readdir_plus_posix.cpp index 32ad0c5c..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 @@ -83,7 +83,7 @@ namespace l int dirfd; DIR *dh; - basepath = fs::path::make(&branches_[i].path,dirname_); + basepath = fs::path::make(branches_[i].path,dirname_); dh = fs::opendir(basepath); if(!dh) diff --git a/src/fuse_readdir_plus_posix.hpp b/src/fuse_readdir_plus_posix.hpp index 236f5b80..ac040673 100644 --- a/src/fuse_readdir_plus_posix.hpp +++ b/src/fuse_readdir_plus_posix.hpp @@ -27,9 +27,9 @@ namespace FUSE { int - readdir_plus_posix(const Branches &branches_, - const char *dirname_, - const uint64_t entry_timeout_, - const uint64_t attr_timeout_, - fuse_dirents_t *buf_); + readdir_plus_posix(const Branches &branches, + const char *dirname, + const uint64_t entry_timeout, + const uint64_t attr_timeout, + fuse_dirents_t *buf); } diff --git a/src/fuse_readdir_posix.cpp b/src/fuse_readdir_posix.cpp index cab4f21b..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" @@ -72,7 +72,7 @@ namespace l int dirfd; DIR *dh; - basepath = fs::path::make(&branches_[i].path,dirname_); + basepath = fs::path::make(branches_[i].path,dirname_); dh = fs::opendir(basepath); if(!dh) 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_readlink.hpp b/src/fuse_readlink.hpp index 336bd613..e9f37a15 100644 --- a/src/fuse_readlink.hpp +++ b/src/fuse_readlink.hpp @@ -19,7 +19,7 @@ namespace FUSE { int - readlink(const char *fusepath_, - char *buf_, - size_t size_); + readlink(const char *fusepath, + char *buf, + size_t size); } 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_release.hpp b/src/fuse_release.hpp index 47592b5c..43d64e21 100644 --- a/src/fuse_release.hpp +++ b/src/fuse_release.hpp @@ -21,5 +21,5 @@ namespace FUSE { int - release(fuse_file_info *ffi_); + release(fuse_file_info *ffi); } diff --git a/src/fuse_releasedir.hpp b/src/fuse_releasedir.hpp index 1b02fb61..579e0d1b 100644 --- a/src/fuse_releasedir.hpp +++ b/src/fuse_releasedir.hpp @@ -21,5 +21,5 @@ namespace FUSE { int - releasedir(fuse_file_info *ffi_); + releasedir(fuse_file_info *ffi); } 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_removexattr.hpp b/src/fuse_removexattr.hpp index 3d0c13e2..7dbef5de 100644 --- a/src/fuse_removexattr.hpp +++ b/src/fuse_removexattr.hpp @@ -19,6 +19,6 @@ namespace FUSE { int - removexattr(const char *fusepath_, - const char *attrname_); + removexattr(const char *fusepath, + const char *attrname); } 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_rename.hpp b/src/fuse_rename.hpp index 9f26b018..affa01d2 100644 --- a/src/fuse_rename.hpp +++ b/src/fuse_rename.hpp @@ -19,6 +19,6 @@ namespace FUSE { int - rename(const char *from_, - const char *to_); + rename(const char *from, + const char *to); } 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_rmdir.hpp b/src/fuse_rmdir.hpp index 58e6813c..0c59659c 100644 --- a/src/fuse_rmdir.hpp +++ b/src/fuse_rmdir.hpp @@ -19,5 +19,5 @@ namespace FUSE { int - rmdir(const char *fusepath_); + rmdir(const char *fusepath); } 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_setxattr.hpp b/src/fuse_setxattr.hpp index d0cbc243..2b882b66 100644 --- a/src/fuse_setxattr.hpp +++ b/src/fuse_setxattr.hpp @@ -19,9 +19,9 @@ namespace FUSE { int - setxattr(const char *fusepath_, - const char *attrname_, - const char *attrval_, - size_t attrvalsize_, - int flags_); + setxattr(const char *fusepath, + const char *attrname, + const char *attrval, + size_t attrvalize, + int flags); } diff --git a/src/fuse_statfs.cpp b/src/fuse_statfs.cpp index 82476d06..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" @@ -99,7 +99,7 @@ namespace l for(size_t i = 0, ei = branches_.size(); i < ei; i++) { fullpath = ((mode_ == StatFS::ENUM::FULL) ? - fs::path::make(&branches_[i].path,fusepath_) : + fs::path::make(branches_[i].path,fusepath_) : branches_[i].path); rv = fs::lstat(fullpath,&st); diff --git a/src/fuse_statfs.hpp b/src/fuse_statfs.hpp index 816c297d..8d0933bb 100644 --- a/src/fuse_statfs.hpp +++ b/src/fuse_statfs.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - statfs(const char *fusepath_, - struct statvfs *fsstat_); + statfs(const char *fusepath, + struct statvfs *fsstat); } diff --git a/src/fuse_symlink.cpp b/src/fuse_symlink.cpp index 50f86305..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" @@ -44,7 +44,7 @@ namespace l int rv; string fullnewpath; - fullnewpath = fs::path::make(&newbasepath_,newpath_); + fullnewpath = fs::path::make(newbasepath_,newpath_); rv = fs::symlink(oldpath_,fullnewpath); diff --git a/src/fuse_symlink.hpp b/src/fuse_symlink.hpp index c598cd22..561a8300 100644 --- a/src/fuse_symlink.hpp +++ b/src/fuse_symlink.hpp @@ -19,6 +19,6 @@ namespace FUSE { int - symlink(const char *oldpath_, - const char *newpath_); + symlink(const char *oldpath, + const char *newpath); } 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_truncate.hpp b/src/fuse_truncate.hpp index 8c2e6d0c..ea7557db 100644 --- a/src/fuse_truncate.hpp +++ b/src/fuse_truncate.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - truncate(const char *fusepath_, - off_t size_); + truncate(const char *fusepath, + off_t size); } 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_unlink.hpp b/src/fuse_unlink.hpp index 60260882..e7f1a272 100644 --- a/src/fuse_unlink.hpp +++ b/src/fuse_unlink.hpp @@ -19,5 +19,5 @@ namespace FUSE { int - unlink(const char *fusepath_); + unlink(const char *fusepath); } 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_utimens.hpp b/src/fuse_utimens.hpp index 6a122c7b..cb78c181 100644 --- a/src/fuse_utimens.hpp +++ b/src/fuse_utimens.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - utimens(const char *fusepath_, - const timespec ts_[2]); + utimens(const char *fusepath, + const timespec ts[2]); } 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 diff --git a/src/fuse_write.hpp b/src/fuse_write.hpp index 2725ee47..a94ad55b 100644 --- a/src/fuse_write.hpp +++ b/src/fuse_write.hpp @@ -21,14 +21,14 @@ namespace FUSE { int - write(const char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_); + write(const char *buf, + size_t count, + off_t offset, + fuse_file_info *ffi); int - write_null(const char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_); + write_null(const char *buf, + size_t count, + off_t offset, + fuse_file_info *ffi); } diff --git a/src/fuse_write_buf.hpp b/src/fuse_write_buf.hpp index c0232ddc..1e1a403e 100644 --- a/src/fuse_write_buf.hpp +++ b/src/fuse_write_buf.hpp @@ -23,12 +23,12 @@ namespace FUSE { int - write_buf(struct fuse_bufvec *buf_, - off_t offset_, - fuse_file_info *ffi_); + write_buf(struct fuse_bufvec *buf, + off_t offset, + fuse_file_info *ffi); int - write_buf_null(struct fuse_bufvec *buf_, - off_t offset_, - fuse_file_info *ffi_); + write_buf_null(struct fuse_bufvec *buf, + off_t offset, + fuse_file_info *ffi); } diff --git a/src/mergerfs.cpp b/src/mergerfs.cpp index 33041e4c..a5b65a15 100644 --- a/src/mergerfs.cpp +++ b/src/mergerfs.cpp @@ -77,59 +77,59 @@ namespace l { static void - get_fuse_operations(struct fuse_operations &ops, - const bool nullrw) + get_fuse_operations(struct fuse_operations &ops_, + const bool nullrw_) { - ops.access = FUSE::access; - ops.bmap = NULL; - ops.chmod = FUSE::chmod; - ops.chown = FUSE::chown; - ops.copy_file_range = FUSE::copy_file_range; - ops.create = FUSE::create; - ops.destroy = FUSE::destroy; - ops.fallocate = FUSE::fallocate; - ops.fchmod = FUSE::fchmod; - ops.fchown = FUSE::fchown; - ops.fgetattr = FUSE::fgetattr; - ops.flock = NULL; // FUSE::flock; - ops.flush = FUSE::flush; - ops.free_hide = FUSE::free_hide; - ops.fsync = FUSE::fsync; - ops.fsyncdir = FUSE::fsyncdir; - ops.ftruncate = FUSE::ftruncate; - ops.futimens = FUSE::futimens; - ops.getattr = FUSE::getattr; - ops.getxattr = FUSE::getxattr; - ops.init = FUSE::init; - ops.ioctl = FUSE::ioctl; - ops.link = FUSE::link; - ops.listxattr = FUSE::listxattr; - ops.lock = NULL; - ops.mkdir = FUSE::mkdir; - ops.mknod = FUSE::mknod; - ops.open = FUSE::open; - ops.opendir = FUSE::opendir; - ops.poll = NULL; - ops.prepare_hide = FUSE::prepare_hide; - ops.read = (nullrw ? FUSE::read_null : FUSE::read); - ops.read_buf = (nullrw ? NULL : FUSE::read_buf); - ops.readdir = FUSE::readdir; - ops.readdir_plus = FUSE::readdir_plus; - ops.readlink = FUSE::readlink; - ops.release = FUSE::release; - ops.releasedir = FUSE::releasedir; - ops.removexattr = FUSE::removexattr; - ops.rename = FUSE::rename; - ops.rmdir = FUSE::rmdir; - ops.setxattr = FUSE::setxattr; - ops.statfs = FUSE::statfs; - ops.symlink = FUSE::symlink; - ops.truncate = FUSE::truncate; - ops.unlink = FUSE::unlink; - ops.utime = NULL; /* deprecated; use utimens() */ - ops.utimens = FUSE::utimens; - ops.write = (nullrw ? FUSE::write_null : FUSE::write); - ops.write_buf = (nullrw ? FUSE::write_buf_null : FUSE::write_buf); + ops_.access = FUSE::access; + ops_.bmap = NULL; + ops_.chmod = FUSE::chmod; + ops_.chown = FUSE::chown; + ops_.copy_file_range = FUSE::copy_file_range; + ops_.create = FUSE::create; + ops_.destroy = FUSE::destroy; + ops_.fallocate = FUSE::fallocate; + ops_.fchmod = FUSE::fchmod; + ops_.fchown = FUSE::fchown; + ops_.fgetattr = FUSE::fgetattr; + ops_.flock = NULL; // FUSE::flock; + ops_.flush = FUSE::flush; + ops_.free_hide = FUSE::free_hide; + ops_.fsync = FUSE::fsync; + ops_.fsyncdir = FUSE::fsyncdir; + ops_.ftruncate = FUSE::ftruncate; + ops_.futimens = FUSE::futimens; + ops_.getattr = FUSE::getattr; + ops_.getxattr = FUSE::getxattr; + ops_.init = FUSE::init; + ops_.ioctl = FUSE::ioctl; + ops_.link = FUSE::link; + ops_.listxattr = FUSE::listxattr; + ops_.lock = NULL; + ops_.mkdir = FUSE::mkdir; + ops_.mknod = FUSE::mknod; + ops_.open = FUSE::open; + ops_.opendir = FUSE::opendir; + ops_.poll = NULL; + ops_.prepare_hide = FUSE::prepare_hide; + ops_.read = (nullrw_ ? FUSE::read_null : FUSE::read); + ops_.read_buf = (nullrw_ ? NULL : FUSE::read_buf); + ops_.readdir = FUSE::readdir; + ops_.readdir_plus = FUSE::readdir_plus; + ops_.readlink = FUSE::readlink; + ops_.release = FUSE::release; + ops_.releasedir = FUSE::releasedir; + ops_.removexattr = FUSE::removexattr; + ops_.rename = FUSE::rename; + ops_.rmdir = FUSE::rmdir; + ops_.setxattr = FUSE::setxattr; + ops_.statfs = FUSE::statfs; + ops_.symlink = FUSE::symlink; + ops_.truncate = FUSE::truncate; + ops_.unlink = FUSE::unlink; + ops_.utime = NULL; /* deprecated; use utimens() */ + ops_.utimens = FUSE::utimens; + ops_.write = (nullrw_ ? FUSE::write_null : FUSE::write); + ops_.write_buf = (nullrw_ ? FUSE::write_buf_null : FUSE::write_buf); return; } @@ -182,8 +182,8 @@ namespace l } int -main(int argc, - char **argv) +main(int argc_, + char **argv_) { - return l::main(argc,argv); + return l::main(argc_,argv_); } diff --git a/src/num.hpp b/src/num.hpp index c3e3b1e7..2dc3f811 100644 --- a/src/num.hpp +++ b/src/num.hpp @@ -22,7 +22,7 @@ namespace num { - int to_uint64_t(const std::string &str_, uint64_t &value_); - int to_double(const std::string &str_, double *value_); - int to_time_t(const std::string &str_, time_t &value_); + int to_uint64_t(const std::string &str, uint64_t *value); + int to_double(const std::string &str, double *value); + int to_time_t(const std::string &str, time_t *value); } diff --git a/src/policy.cpp b/src/policy.cpp index 2059cbf9..3e62a638 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -17,7 +17,6 @@ #include #include "buildvector.hpp" -#include "fs.hpp" #include "policy.hpp" #define POLICY(X,PP) (Policy(Policy::Enum::X,#X,Policy::Func::X,PP)) diff --git a/src/policy.hpp b/src/policy.hpp index 39a51d35..9e722cd6 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -18,7 +18,6 @@ #include "branch.hpp" #include "category.hpp" -#include "fs.hpp" #include #include @@ -63,11 +62,10 @@ public: typedef const string cstring; typedef const uint64_t cuint64_t; typedef const strvec cstrvec; - typedef const Category::Enum::Type CType; - typedef int (*Ptr)(CType,const Branches &,const char *,cuint64_t,strvec *); + typedef int (*Ptr)(Category,const Branches &,const char *,cuint64_t,strvec *); - template + template class Base { public: @@ -108,28 +106,28 @@ public: const Ptr func; }; - typedef Base Action; - typedef Base Create; - typedef Base Search; - - static int invalid(CType,const Branches&,const char *,cuint64_t,strvec*); - static int all(CType,const Branches&,const char*,cuint64_t,strvec*); - static int epall(CType,const Branches&,const char*,cuint64_t,strvec*); - static int epff(CType,const Branches&,const char *,cuint64_t,strvec*); - static int eplfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int eplus(CType,const Branches&,const char *,cuint64_t,strvec*); - static int epmfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int eprand(CType,const Branches&,const char *,cuint64_t,strvec*); - static int erofs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int ff(CType,const Branches&,const char *,cuint64_t,strvec*); - static int lfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int lus(CType,const Branches&,const char *,cuint64_t,strvec*); - static int mfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int msplfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int msplus(CType,const Branches&,const char *,cuint64_t,strvec*); - static int mspmfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int newest(CType,const Branches&,const char *,cuint64_t,strvec*); - static int rand(CType,const Branches&,const char *,cuint64_t,strvec*); + typedef Base Action; + typedef Base Create; + typedef Base Search; + + static int invalid(Category,const Branches&,const char *,cuint64_t,strvec*); + static int all(Category,const Branches&,const char*,cuint64_t,strvec*); + static int epall(Category,const Branches&,const char*,cuint64_t,strvec*); + static int epff(Category,const Branches&,const char *,cuint64_t,strvec*); + static int eplfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int eplus(Category,const Branches&,const char *,cuint64_t,strvec*); + static int epmfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int eprand(Category,const Branches&,const char *,cuint64_t,strvec*); + static int erofs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int ff(Category,const Branches&,const char *,cuint64_t,strvec*); + static int lfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int lus(Category,const Branches&,const char *,cuint64_t,strvec*); + static int mfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int msplfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int msplus(Category,const Branches&,const char *,cuint64_t,strvec*); + static int mspmfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int newest(Category,const Branches&,const char *,cuint64_t,strvec*); + static int rand(Category,const Branches&,const char *,cuint64_t,strvec*); }; private: diff --git a/src/policy_all.cpp b/src/policy_all.cpp index edb54e83..b417ebfd 100644 --- a/src/policy_all.cpp +++ b/src/policy_all.cpp @@ -50,7 +50,7 @@ namespace all if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -69,13 +69,13 @@ namespace all } int -Policy::Func::all(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::all(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return all::create(branches_,minfreespace_,paths_); return Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_cache.hpp b/src/policy_cache.hpp index d965264d..bcf66b98 100644 --- a/src/policy_cache.hpp +++ b/src/policy_cache.hpp @@ -41,16 +41,16 @@ public: PolicyCache(void); public: - void erase(const char *fusepath_); - void cleanup(const int prob_ = 1); + void erase(const char *fusepath); + void cleanup(const int prob = 1); void clear(void); public: - int operator()(Policy::Func::Search &func_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - std::string *branch_); + int operator()(Policy::Func::Search &func, + const Branches &branches, + const char *fusepath, + const uint64_t minfreespace, + std::string *branch); public: uint64_t timeout; diff --git a/src/policy_epall.cpp b/src/policy_epall.cpp index e932b341..353395f8 100644 --- a/src/policy_epall.cpp +++ b/src/policy_epall.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -35,9 +34,9 @@ namespace epall static int create(const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -51,22 +50,22 @@ namespace epall { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) error_and_continue(error,ENOENT); if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) error_and_continue(error,EROFS); - if(info.spaceavail < minfreespace) + if(info.spaceavail < minfreespace_) error_and_continue(error,ENOSPC); - paths->push_back(branch->path); + paths_->push_back(branch->path); } - if(paths->empty()) + if(paths_->empty()) return (errno=error,-1); return 0; @@ -75,8 +74,8 @@ namespace epall static int action(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -90,7 +89,7 @@ namespace epall { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) error_and_continue(error,ENOENT); if(branch->ro()) error_and_continue(error,EROFS); @@ -100,10 +99,10 @@ namespace epall if(readonly) error_and_continue(error,EROFS); - paths->push_back(branch->path); + paths_->push_back(branch->path); } - if(paths->empty()) + if(paths_->empty()) return (errno=error,-1); return 0; @@ -112,8 +111,8 @@ namespace epall static int search(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -123,13 +122,13 @@ namespace epall { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) continue; - paths->push_back(branch->path); + paths_->push_back(branch->path); } - if(paths->empty()) + if(paths_->empty()) return (errno=ENOENT,-1); return 0; @@ -137,20 +136,20 @@ namespace epall } int -Policy::Func::epall(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::epall(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - switch(type) + switch(type_) { - case Category::Enum::create: - return epall::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: - return epall::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::CREATE: + return epall::create(branches_,fusepath_,minfreespace_,paths_); + case Category::ACTION: + return epall::action(branches_,fusepath_,paths_); + case Category::SEARCH: default: - return epall::search(branches_,fusepath,paths); + return epall::search(branches_,fusepath_,paths_); } } diff --git a/src/policy_epff.cpp b/src/policy_epff.cpp index 2361e7fd..ea360f69 100644 --- a/src/policy_epff.cpp +++ b/src/policy_epff.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -55,7 +54,7 @@ namespace epff error_and_continue(error,ENOENT); if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -134,19 +133,19 @@ namespace epff } int -Policy::Func::epff(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::epff(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { switch(type_) { - case Category::Enum::create: + case Category::CREATE: return epff::create(branches_,fusepath_,minfreespace_,paths_); - case Category::Enum::action: + case Category::ACTION: return epff::action(branches_,fusepath_,paths_); - case Category::Enum::search: + case Category::SEARCH: default: return epff::search(branches_,fusepath_,paths_); } diff --git a/src/policy_eplfs.cpp b/src/policy_eplfs.cpp index dc424da5..f44581bb 100644 --- a/src/policy_eplfs.cpp +++ b/src/policy_eplfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -36,9 +35,9 @@ namespace eplfs static int create(const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -56,16 +55,16 @@ namespace eplfs { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) error_and_continue(error,ENOENT); if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) error_and_continue(error,EROFS); - if(info.spaceavail < minfreespace) + if(info.spaceavail < minfreespace_) error_and_continue(error,ENOSPC); if(info.spaceavail > eplfs) continue; @@ -77,7 +76,7 @@ namespace eplfs if(eplfsbasepath == NULL) return (errno=error,-1); - paths->push_back(*eplfsbasepath); + paths_->push_back(*eplfsbasepath); return 0; } @@ -85,8 +84,8 @@ namespace eplfs static int action(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -104,11 +103,11 @@ namespace eplfs { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) error_and_continue(error,ENOENT); if(branch->ro()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -123,7 +122,7 @@ namespace eplfs if(eplfsbasepath == NULL) return (errno=error,-1); - paths->push_back(*eplfsbasepath); + paths_->push_back(*eplfsbasepath); return 0; } @@ -131,8 +130,8 @@ namespace eplfs static int search(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -148,7 +147,7 @@ namespace eplfs { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) continue; rv = fs::statvfs_cache_spaceavail(branch->path,&spaceavail); if(rv == -1) @@ -163,27 +162,27 @@ namespace eplfs if(eplfsbasepath == NULL) return (errno=ENOENT,-1); - paths->push_back(*eplfsbasepath); + paths_->push_back(*eplfsbasepath); return 0; } } int -Policy::Func::eplfs(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::eplfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - switch(type) + switch(type_) { - case Category::Enum::create: - return eplfs::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: - return eplfs::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::CREATE: + return eplfs::create(branches_,fusepath_,minfreespace_,paths_); + case Category::ACTION: + return eplfs::action(branches_,fusepath_,paths_); + case Category::SEARCH: default: - return eplfs::search(branches_,fusepath,paths); + return eplfs::search(branches_,fusepath_,paths_); } } diff --git a/src/policy_eplus.cpp b/src/policy_eplus.cpp index 7b0379b4..65a4ca3a 100644 --- a/src/policy_eplus.cpp +++ b/src/policy_eplus.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -36,9 +35,9 @@ namespace eplus static int create(const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -56,16 +55,16 @@ namespace eplus { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) error_and_continue(error,ENOENT); if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) error_and_continue(error,EROFS); - if(info.spaceavail < minfreespace) + if(info.spaceavail < minfreespace_) error_and_continue(error,ENOSPC); if(info.spaceused >= eplus) continue; @@ -77,7 +76,7 @@ namespace eplus if(eplusbasepath == NULL) return (errno=error,-1); - paths->push_back(*eplusbasepath); + paths_->push_back(*eplusbasepath); return 0; } @@ -85,8 +84,8 @@ namespace eplus static int action(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -104,11 +103,11 @@ namespace eplus { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) error_and_continue(error,ENOENT); if(branch->ro()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -123,7 +122,7 @@ namespace eplus if(eplusbasepath == NULL) return (errno=error,-1); - paths->push_back(*eplusbasepath); + paths_->push_back(*eplusbasepath); return 0; } @@ -131,8 +130,8 @@ namespace eplus static int search(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -148,7 +147,7 @@ namespace eplus { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath)) + if(!fs::exists(branch->path,fusepath_)) continue; rv = fs::statvfs_cache_spaceused(branch->path,&spaceused); if(rv == -1) @@ -163,27 +162,27 @@ namespace eplus if(eplusbasepath == NULL) return (errno=ENOENT,-1); - paths->push_back(*eplusbasepath); + paths_->push_back(*eplusbasepath); return 0; } } int -Policy::Func::eplus(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::eplus(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - switch(type) + switch(type_) { - case Category::Enum::create: - return eplus::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: - return eplus::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::CREATE: + return eplus::create(branches_,fusepath_,minfreespace_,paths_); + case Category::ACTION: + return eplus::action(branches_,fusepath_,paths_); + case Category::SEARCH: default: - return eplus::search(branches_,fusepath,paths); + return eplus::search(branches_,fusepath_,paths_); } } diff --git a/src/policy_epmfs.cpp b/src/policy_epmfs.cpp index c91b7d7e..b77604fa 100644 --- a/src/policy_epmfs.cpp +++ b/src/policy_epmfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -60,7 +59,7 @@ namespace epmfs error_and_continue(error,ENOENT); if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -108,7 +107,7 @@ namespace epmfs error_and_continue(error,ENOENT); if(branch->ro()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -170,19 +169,19 @@ namespace epmfs } int -Policy::Func::epmfs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::epmfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { switch(type_) { - case Category::Enum::create: + case Category::CREATE: return epmfs::create(branches_,fusepath_,minfreespace_,paths_); - case Category::Enum::action: + case Category::ACTION: return epmfs::action(branches_,fusepath_,paths_); - case Category::Enum::search: + case Category::SEARCH: default: return epmfs::search(branches_,fusepath_,paths_); } diff --git a/src/policy_eprand.cpp b/src/policy_eprand.cpp index eaa154e6..099162f1 100644 --- a/src/policy_eprand.cpp +++ b/src/policy_eprand.cpp @@ -25,11 +25,11 @@ using std::string; using std::vector; int -Policy::Func::eprand(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::eprand(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { int rv; diff --git a/src/policy_erofs.cpp b/src/policy_erofs.cpp index 8daea427..aa85d219 100644 --- a/src/policy_erofs.cpp +++ b/src/policy_erofs.cpp @@ -24,11 +24,11 @@ using std::string; using std::vector; int -Policy::Func::erofs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths) +Policy::Func::erofs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths) { return (errno=EROFS,-1); } diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index e55fa28e..ea772a35 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -34,8 +33,8 @@ namespace ff static int create(const Branches &branches_, - const uint64_t minfreespace, - vector *paths) + const uint64_t minfreespace_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -51,15 +50,15 @@ namespace ff if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) error_and_continue(error,EROFS); - if(info.spaceavail < minfreespace) + if(info.spaceavail < minfreespace_) error_and_continue(error,ENOSPC); - paths->push_back(branch->path); + paths_->push_back(branch->path); return 0; } @@ -69,14 +68,14 @@ namespace ff } int -Policy::Func::ff(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::ff(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type == Category::Enum::create) - return ff::create(branches_,minfreespace,paths); + if(type_ == Category::CREATE) + return ff::create(branches_,minfreespace_,paths_); - return Policy::Func::epff(type,branches_,fusepath,minfreespace,paths); + return Policy::Func::epff(type_,branches_,fusepath_,minfreespace_,paths_); } diff --git a/src/policy_invalid.cpp b/src/policy_invalid.cpp index 7d0d97b8..588e424d 100644 --- a/src/policy_invalid.cpp +++ b/src/policy_invalid.cpp @@ -24,11 +24,11 @@ using std::string; using std::vector; int -Policy::Func::invalid(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::invalid(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { return (errno=EINVAL,-1); } diff --git a/src/policy_lfs.cpp b/src/policy_lfs.cpp index 4fb5d135..45e096d1 100644 --- a/src/policy_lfs.cpp +++ b/src/policy_lfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -56,7 +55,7 @@ namespace lfs if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -80,14 +79,14 @@ namespace lfs } int -Policy::Func::lfs(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::lfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type == Category::Enum::create) - return lfs::create(branches_,minfreespace,paths); + if(type_ == Category::CREATE) + return lfs::create(branches_,minfreespace_,paths_); - return Policy::Func::eplfs(type,branches_,fusepath,minfreespace,paths); + return Policy::Func::eplfs(type_,branches_,fusepath_,minfreespace_,paths_); } diff --git a/src/policy_lus.cpp b/src/policy_lus.cpp index 450ea227..74cca0f1 100644 --- a/src/policy_lus.cpp +++ b/src/policy_lus.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -35,8 +34,8 @@ namespace lus static int create(const Branches &branches_, - const uint64_t minfreespace, - vector *paths) + const uint64_t minfreespace_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -56,12 +55,12 @@ namespace lus if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) error_and_continue(error,EROFS); - if(info.spaceavail < minfreespace) + if(info.spaceavail < minfreespace_) error_and_continue(error,ENOSPC); if(info.spaceused >= lus) continue; @@ -73,21 +72,21 @@ namespace lus if(lusbasepath == NULL) return (errno=error,-1); - paths->push_back(*lusbasepath); + paths_->push_back(*lusbasepath); return 0; } } int -Policy::Func::lus(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::lus(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type == Category::Enum::create) - return lus::create(branches_,minfreespace,paths); + if(type_ == Category::CREATE) + return lus::create(branches_,minfreespace_,paths_); - return Policy::Func::eplus(type,branches_,fusepath,minfreespace,paths); + return Policy::Func::eplus(type_,branches_,fusepath_,minfreespace_,paths_); } diff --git a/src/policy_mfs.cpp b/src/policy_mfs.cpp index e60c194d..d286cf1b 100644 --- a/src/policy_mfs.cpp +++ b/src/policy_mfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -55,7 +54,7 @@ namespace mfs if(branch->ro_or_nc()) error_and_continue(error,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) @@ -79,14 +78,14 @@ namespace mfs } int -Policy::Func::mfs(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::mfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type == Category::Enum::create) - return mfs::create(branches_,minfreespace,paths); + if(type_ == Category::CREATE) + return mfs::create(branches_,minfreespace_,paths_); - return Policy::Func::epmfs(type,branches_,fusepath,minfreespace,paths); + return Policy::Func::epmfs(type_,branches_,fusepath_,minfreespace_,paths_); } diff --git a/src/policy_msplfs.cpp b/src/policy_msplfs.cpp index ea9e2a40..a479e5eb 100644 --- a/src/policy_msplfs.cpp +++ b/src/policy_msplfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -59,7 +58,7 @@ namespace msplfs error_and_continue(*err_,ENOENT); if(branch->ro_or_nc()) error_and_continue(*err_,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(*err_,ENOENT); if(info.readonly) @@ -110,13 +109,13 @@ namespace msplfs } int -Policy::Func::msplfs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::msplfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return msplfs::create(branches_,fusepath_,minfreespace_,paths_); return Policy::Func::eplfs(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_msplus.cpp b/src/policy_msplus.cpp index 7405eb55..6fc641dd 100644 --- a/src/policy_msplus.cpp +++ b/src/policy_msplus.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -59,7 +58,7 @@ namespace msplus error_and_continue(*err_,ENOENT); if(branch->ro_or_nc()) error_and_continue(*err_,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(*err_,ENOENT); if(info.readonly) @@ -110,13 +109,13 @@ namespace msplus } int -Policy::Func::msplus(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::msplus(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return msplus::create(branches_,fusepath_,minfreespace_,paths_); return Policy::Func::eplus(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_mspmfs.cpp b/src/policy_mspmfs.cpp index 685980d8..f93a4439 100644 --- a/src/policy_mspmfs.cpp +++ b/src/policy_mspmfs.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -59,7 +58,7 @@ namespace mspmfs error_and_continue(*err_,ENOENT); if(branch->ro_or_nc()) error_and_continue(*err_,EROFS); - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(*err_,ENOENT); if(info.readonly) @@ -110,13 +109,13 @@ namespace mspmfs } int -Policy::Func::mspmfs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::mspmfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return mspmfs::create(branches_,fusepath_,minfreespace_,paths_); return Policy::Func::epmfs(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_newest.cpp b/src/policy_newest.cpp index d0416c28..c3eced2b 100644 --- a/src/policy_newest.cpp +++ b/src/policy_newest.cpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs.hpp" #include "fs_exists.hpp" #include "fs_info.hpp" #include "fs_path.hpp" @@ -38,9 +37,9 @@ namespace newest static int create(const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -59,18 +58,18 @@ namespace newest { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath,&st)) + if(!fs::exists(branch->path,fusepath_,&st)) error_and_continue(error,ENOENT); if(branch->ro_or_nc()) error_and_continue(error,EROFS); if(st.st_mtime < newest) continue; - rv = fs::info(&branch->path,&info); + rv = fs::info(branch->path,&info); if(rv == -1) error_and_continue(error,ENOENT); if(info.readonly) error_and_continue(error,EROFS); - if(info.spaceavail < minfreespace) + if(info.spaceavail < minfreespace_) error_and_continue(error,ENOSPC); newest = st.st_mtime; @@ -80,7 +79,7 @@ namespace newest if(newestbasepath == NULL) return (errno=error,-1); - paths->push_back(*newestbasepath); + paths_->push_back(*newestbasepath); return 0; } @@ -88,8 +87,8 @@ namespace newest static int action(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -108,7 +107,7 @@ namespace newest { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath,&st)) + if(!fs::exists(branch->path,fusepath_,&st)) error_and_continue(error,ENOENT); if(branch->ro()) error_and_continue(error,EROFS); @@ -127,7 +126,7 @@ namespace newest if(newestbasepath == NULL) return (errno=error,-1); - paths->push_back(*newestbasepath); + paths_->push_back(*newestbasepath); return 0; } @@ -135,8 +134,8 @@ namespace newest static int search(const Branches &branches_, - const char *fusepath, - vector *paths) + const char *fusepath_, + vector *paths_) { rwlock::ReadGuard guard(&branches_.lock); @@ -151,7 +150,7 @@ namespace newest { branch = &branches_[i]; - if(!fs::exists(branch->path,fusepath,&st)) + if(!fs::exists(branch->path,fusepath_,&st)) continue; if(st.st_mtime < newest) continue; @@ -163,27 +162,27 @@ namespace newest if(newestbasepath == NULL) return (errno=ENOENT,-1); - paths->push_back(*newestbasepath); + paths_->push_back(*newestbasepath); return 0; } } int -Policy::Func::newest(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::newest(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - switch(type) + switch(type_) { - case Category::Enum::create: - return newest::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: - return newest::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::CREATE: + return newest::create(branches_,fusepath_,minfreespace_,paths_); + case Category::ACTION: + return newest::action(branches_,fusepath_,paths_); + case Category::SEARCH: default: - return newest::search(branches_,fusepath,paths); + return newest::search(branches_,fusepath_,paths_); } } diff --git a/src/policy_rand.cpp b/src/policy_rand.cpp index 7d38db94..2ffb2a92 100644 --- a/src/policy_rand.cpp +++ b/src/policy_rand.cpp @@ -25,11 +25,11 @@ using std::string; using std::vector; int -Policy::Func::rand(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::rand(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { int rv; diff --git a/src/resources.hpp b/src/resources.hpp index faafaeff..fea5d5d1 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -19,8 +19,8 @@ namespace resources { int reset_umask(void); - int maxout_rlimit(const int resource_); + int maxout_rlimit(const int resource); int maxout_rlimit_nofile(void); int maxout_rlimit_fsize(void); - int setpriority(const int prio_); + int setpriority(const int prio); } diff --git a/src/rv.hpp b/src/rv.hpp index 68e63fc6..182bc3e8 100644 --- a/src/rv.hpp +++ b/src/rv.hpp @@ -21,15 +21,15 @@ namespace error static inline int - calc(const int rv, - const int prev, - const int cur) + calc(const int rv_, + const int prev_, + const int cur_) { - if(rv == -1) + if(rv_ == -1) { - if(prev == 0) + if(prev_ == 0) return 0; - return cur; + return cur_; } return 0; diff --git a/src/statvfs_util.hpp b/src/statvfs_util.hpp index 29b02188..0447d181 100644 --- a/src/statvfs_util.hpp +++ b/src/statvfs_util.hpp @@ -26,24 +26,24 @@ namespace StatVFS static inline bool - readonly(const struct statvfs &st) + readonly(const struct statvfs &st_) { - return (st.f_flag & ST_RDONLY); + return (st_.f_flag & ST_RDONLY); } static inline int64_t - spaceavail(const struct statvfs &st) + spaceavail(const struct statvfs &st_) { - return (st.f_frsize * st.f_bavail); + return (st_.f_frsize * st_.f_bavail); } static inline int64_t - spaceused(const struct statvfs &st) + spaceused(const struct statvfs &st_) { - return (st.f_frsize * (st.f_blocks - st.f_bavail)); + return (st_.f_frsize * (st_.f_blocks - st_.f_bavail)); } } diff --git a/src/str.cpp b/src/str.cpp index 5ff73ee2..9d234048 100644 --- a/src/str.cpp +++ b/src/str.cpp @@ -27,23 +27,23 @@ using std::istringstream; namespace str { void - split(vector &result, - const char *str, - const char delimiter) + split(const char *str_, + const char delimiter_, + vector *result_) { string part; - istringstream ss(str); + istringstream ss(str_); - while(std::getline(ss,part,delimiter)) - result.push_back(part); + while(std::getline(ss,part,delimiter_)) + result_->push_back(part); } void - split(vector &result, - const string &str, - const char delimiter) + split(const string &str_, + const char delimiter_, + vector *result_) { - return str::split(result,str.c_str(),delimiter); + return str::split(str_.c_str(),delimiter_,result_); } void @@ -65,41 +65,41 @@ namespace str } string - join(const vector &vec, - const size_t substridx, - const char sep) + join(const vector &vec_, + const size_t substridx_, + const char sep_) { - if(vec.empty()) + if(vec_.empty()) return string(); - string rv = vec[0].substr(substridx); - for(size_t i = 1; i < vec.size(); i++) - rv += sep + vec[i].substr(substridx); + string rv = vec_[0].substr(substridx_); + for(size_t i = 1; i < vec_.size(); i++) + rv += sep_ + vec_[i].substr(substridx_); return rv; } string - join(const vector &vec, - const char sep) + join(const vector &vec_, + const char sep_) { - return str::join(vec,0,sep); + return str::join(vec_,0,sep_); } size_t - longest_common_prefix_index(const vector &vec) + longest_common_prefix_index(const vector &vec_) { - if(vec.empty()) + if(vec_.empty()) return string::npos; - for(size_t n = 0; n < vec[0].size(); n++) + for(size_t n = 0; n < vec_[0].size(); n++) { - char chr = vec[0][n]; - for(size_t i = 1; i < vec.size(); i++) + char chr = vec_[0][n]; + for(size_t i = 1; i < vec_.size(); i++) { - if(n >= vec[i].size()) + if(n >= vec_[i].size()) return n; - if(vec[i][n] != chr) + if(vec_[i][n] != chr) return n; } } @@ -108,62 +108,62 @@ namespace str } string - longest_common_prefix(const vector &vec) + longest_common_prefix(const vector &vec_) { size_t idx; - idx = longest_common_prefix_index(vec); + idx = longest_common_prefix_index(vec_); if(idx != string::npos) - return vec[0].substr(0,idx); + return vec_[0].substr(0,idx); return string(); } string - remove_common_prefix_and_join(const vector &vec, - const char sep) + remove_common_prefix_and_join(const vector &vec_, + const char sep_) { size_t idx; - idx = str::longest_common_prefix_index(vec); + idx = str::longest_common_prefix_index(vec_); if(idx == string::npos) idx = 0; - return str::join(vec,idx,sep); + return str::join(vec_,idx,sep_); } void - erase_fnmatches(const vector &patterns, - vector &strs) + erase_fnmatches(const vector &patterns_, + vector &strs_) { vector::iterator si; vector::const_iterator pi; - si = strs.begin(); - while(si != strs.end()) + si = strs_.begin(); + while(si != strs_.end()) { int match = FNM_NOMATCH; - for(pi = patterns.begin(); - pi != patterns.end() && match != 0; + for(pi = patterns_.begin(); + pi != patterns_.end() && match != 0; ++pi) { match = fnmatch(pi->c_str(),si->c_str(),0); } if(match == 0) - si = strs.erase(si); + si = strs_.erase(si); else ++si; } } bool - isprefix(const string &s0, - const string &s1) + isprefix(const string &s0_, + const string &s1_) { - return ((s0.size() >= s1.size()) && - (s0.compare(0,s1.size(),s1) == 0)); + return ((s0_.size() >= s1_.size()) && + (s0_.compare(0,s1_.size(),s1_) == 0)); } bool diff --git a/src/str.hpp b/src/str.hpp index 2b14af90..10f4b305 100644 --- a/src/str.hpp +++ b/src/str.hpp @@ -22,13 +22,13 @@ namespace str { void - split(std::vector &result, - const char *str, - const char delimiter); + split(const char *str, + const char delimiter, + std::vector *result); void - split(std::vector &result, - const std::string &str, - const char delimiter); + split(const std::string &str, + const char delimiter, + std::vector *result); void splitkv(const std::string &str, diff --git a/src/symlinkify.hpp b/src/symlinkify.hpp index 9a10cd93..628e1725 100644 --- a/src/symlinkify.hpp +++ b/src/symlinkify.hpp @@ -26,24 +26,24 @@ namespace symlinkify static inline bool - can_be_symlink(const struct stat &st, - const time_t timeout) + can_be_symlink(const struct stat &st_, + const time_t timeout_) { - if(S_ISDIR(st.st_mode) || - (st.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH))) + if(S_ISDIR(st_.st_mode) || + (st_.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH))) return false; const time_t now = ::time(NULL); - return (((now - st.st_mtime) > timeout) && - ((now - st.st_ctime) > timeout)); + return (((now - st_.st_mtime) > timeout_) && + ((now - st_.st_ctime) > timeout_)); } static inline mode_t - convert(const mode_t mode) + convert(const mode_t mode_) { - return ((mode & ~S_IFMT) | S_IFLNK); + return ((mode_ & ~S_IFMT) | S_IFLNK); } } diff --git a/src/tofrom_string.hpp b/src/tofrom_string.hpp index 1cf35cda..ad00a4cf 100644 --- a/src/tofrom_string.hpp +++ b/src/tofrom_string.hpp @@ -26,22 +26,3 @@ public: virtual std::string to_string() const = 0; virtual int from_string(const std::string &) = 0; }; - -namespace std -{ - inline - static - std::string - to_string(const ToFromString *o_) - { - return o_->to_string(); - } - - inline - static - std::string - to_string(const ToFromString &o_) - { - return o_.to_string(); - } -} diff --git a/src/ugid.cpp b/src/ugid.cpp index 70ce91ad..368bbf8c 100644 --- a/src/ugid.cpp +++ b/src/ugid.cpp @@ -25,11 +25,11 @@ namespace ugid { void - initgroups(const uid_t uid, - const gid_t gid) + initgroups(const uid_t uid_, + const gid_t gid_) { static __thread gid_t_cache cache = {0}; - cache.initgroups(uid,gid); + cache.initgroups(uid_,gid_); } } diff --git a/src/ugid.hpp b/src/ugid.hpp index 9edde0c6..620e8b45 100644 --- a/src/ugid.hpp +++ b/src/ugid.hpp @@ -28,7 +28,9 @@ namespace ugid } #if defined __linux__ and UGID_USE_RWLOCK == 0 +#warning "using ugid_linux.hpp" #include "ugid_linux.hpp" #else +#warning "using ugid_rwlock.hpp" #include "ugid_rwlock.hpp" #endif diff --git a/src/ugid_linux.hpp b/src/ugid_linux.hpp index 06a872a4..17a1803e 100644 --- a/src/ugid_linux.hpp +++ b/src/ugid_linux.hpp @@ -59,8 +59,8 @@ namespace ugid struct Set { - Set(const uid_t newuid, - const gid_t newgid) + Set(const uid_t newuid_, + const gid_t newgid_) { if(!initialized) { @@ -69,7 +69,7 @@ namespace ugid initialized = true; } - if(newuid == currentuid && newgid == currentgid) + if((newuid_ == currentuid) && (newgid_ == currentgid)) return; if(currentuid != 0) @@ -78,17 +78,17 @@ namespace ugid SETREGID(-1,0); } - if(newgid) + if(newgid_) { - SETREGID(-1,newgid); - initgroups(newuid,newgid); + SETREGID(-1,newgid_); + initgroups(newuid_,newgid_); } - if(newuid) - SETREUID(-1,newuid); + if(newuid_) + SETREUID(-1,newuid_); - currentuid = newuid; - currentgid = newgid; + currentuid = newuid_; + currentgid = newgid_; } }; diff --git a/src/ugid_rwlock.hpp b/src/ugid_rwlock.hpp index 9ac08f83..e37dbce7 100644 --- a/src/ugid_rwlock.hpp +++ b/src/ugid_rwlock.hpp @@ -29,18 +29,18 @@ namespace ugid static void - ugid_set(const uid_t newuid, - const gid_t newgid) + ugid_set(const uid_t newuid_, + const gid_t newgid_) { pthread_rwlock_rdlock(&rwlock); - if(newuid == currentuid && newgid == currentgid) + if((newuid_ == currentuid) && (newgid_ == currentgid)) return; pthread_rwlock_unlock(&rwlock); pthread_rwlock_wrlock(&rwlock); - if(newuid == currentuid && newgid == currentgid) + if((newuid_ == currentuid) && (newgid_ == currentgid)) return; if(currentuid != 0) @@ -49,25 +49,25 @@ namespace ugid ::setegid(0); } - if(newgid) + if(newgid_) { - ::setegid(newgid); - initgroups(newuid,newgid); + ::setegid(newgid_); + initgroups(newuid_,newgid_); } - if(newuid) - ::seteuid(newuid); + if(newuid_) + ::seteuid(newuid_); - currentuid = newuid; - currentgid = newgid; + currentuid = newuid_; + currentgid = newgid_; } struct Set { - Set(const uid_t newuid, - const gid_t newgid) + Set(const uid_t newuid_, + const gid_t newgid_) { - ugid_set(newuid,newgid); + ugid_set(newuid_,newgid_); } ~Set()