mirror of https://github.com/trapexit/mergerfs.git
trapexit
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
248 changed files with 2941 additions and 2181 deletions
-
77.cirrus.yml
-
14src/branch.cpp
-
13src/buildmap.hpp
-
8src/buildvector.hpp
-
59src/category.cpp
-
68src/category.hpp
-
1src/config.cpp
-
1src/config_statfsignore.hpp
-
156src/fs.cpp
-
43src/fs.hpp
-
6src/fs_acl.cpp
-
2src/fs_acl.hpp
-
6src/fs_attr.cpp
-
8src/fs_attr.hpp
-
12src/fs_attr_linux.icpp
-
4src/fs_attr_unsupported.icpp
-
35src/fs_base_fadvise.hpp
-
33src/fs_base_fallocate_posix.icpp
-
67src/fs_base_utime.hpp
-
313src/fs_base_utime_generic.hpp
-
50src/fs_clonefile.cpp
-
4src/fs_clonefile.hpp
-
87src/fs_clonepath.cpp
-
0src/fs_close.hpp
-
0src/fs_closedir.hpp
-
6src/fs_copy_file_range.cpp
-
53src/fs_copydata.cpp
-
29src/fs_copydata.hpp
-
2src/fs_copydata_copy_file_range.cpp
-
8src/fs_copydata_readwrite.cpp
-
35src/fs_cow.cpp
-
10src/fs_cow.hpp
-
6src/fs_devid.hpp
-
0src/fs_dirfd.hpp
-
0src/fs_dup.hpp
-
42src/fs_eaccess.hpp
-
4src/fs_exists.hpp
-
20src/fs_faccessat.hpp
-
30src/fs_fadvise.cpp
-
37src/fs_fadvise.hpp
-
12src/fs_fadvise_posix.icpp
-
8src/fs_fadvise_unsupported.icpp
-
8src/fs_fallocate.cpp
-
9src/fs_fallocate.hpp
-
7src/fs_fallocate_linux.icpp
-
31src/fs_fallocate_osx.icpp
-
17src/fs_fallocate_posix.icpp
-
29src/fs_fallocate_unsupported.icpp
-
2src/fs_fchmod.hpp
-
49src/fs_fchmodat.hpp
-
3src/fs_fchown.hpp
-
8src/fs_fdatasync.hpp
-
61src/fs_fgetxattr.hpp
-
6src/fs_ficlone.cpp
-
4src/fs_ficlone.hpp
-
2src/fs_ficlone_linux.icpp
-
2src/fs_file_size.cpp
-
44src/fs_findallfiles.cpp
-
30src/fs_findallfiles.hpp
-
3src/fs_findonfs.cpp
-
41src/fs_flistxattr.hpp
-
0src/fs_flock.hpp
-
61src/fs_fsetxattr.hpp
-
36src/fs_fstat.hpp
-
28src/fs_fstatat.hpp
-
32src/fs_fsync.hpp
-
0src/fs_ftruncate.hpp
-
51src/fs_futimens.hpp
-
33src/fs_futimens_freebsd_11.hpp
-
283src/fs_futimens_generic.hpp
-
33src/fs_futimens_linux.hpp
-
6src/fs_futimesat.cpp
-
8src/fs_futimesat.hpp
-
8src/fs_futimesat_generic.icpp
-
41src/fs_futimesat_osx.icpp
-
2src/fs_getdents64.cpp
-
27src/fs_getdents64.hpp
-
28src/fs_getfl.cpp
-
24src/fs_getfl.hpp
-
4src/fs_glob.cpp
-
4src/fs_glob.hpp
-
2src/fs_has_space.cpp
-
8src/fs_info.cpp
-
4src/fs_info.hpp
-
0src/fs_ioctl.hpp
-
26src/fs_lchmod.hpp
-
30src/fs_lchown.hpp
-
38src/fs_lgetxattr.hpp
-
0src/fs_link.hpp
-
14src/fs_llistxattr.hpp
-
0src/fs_lremovexattr.hpp
-
0src/fs_lseek.hpp
-
24src/fs_lsetxattr.hpp
-
46src/fs_lstat.hpp
-
48src/fs_lutimens.hpp
-
0src/fs_mkdir.hpp
-
0src/fs_mknod.hpp
-
8src/fs_mktemp.cpp
-
4src/fs_mktemp.hpp
-
14src/fs_movefile.cpp
@ -1,59 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
#include "category.hpp"
|
|
||||
#include "buildvector.hpp"
|
|
||||
|
|
||||
#define CATEGORY(X) Category(Category::Enum::X,#X)
|
|
||||
|
|
||||
const std::vector<Category> Category::_categories_ = |
|
||||
buildvector<Category,true> |
|
||||
(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; |
|
||||
} |
|
@ -1,156 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
#include <fcntl.h>
|
|
||||
#include <limits.h>
|
|
||||
#include <stdint.h>
|
|
||||
#include <stdlib.h>
|
|
||||
|
|
||||
#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<string> &basepaths, |
|
||||
const char *fusepath, |
|
||||
vector<string> &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<string> &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<string> &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<string> &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; |
|
||||
} |
|
||||
}; |
|
@ -1,43 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
#include <fcntl.h>
|
|
||||
#include <stdint.h>
|
|
||||
|
|
||||
namespace fs |
|
||||
{ |
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
void findallfiles(const vector<string> &basepaths_, |
|
||||
const char *fusepath_, |
|
||||
vector<string> &paths_); |
|
||||
|
|
||||
void realpathize(vector<string> &strs_); |
|
||||
|
|
||||
int getfl(const int fd_); |
|
||||
int setfl(const int fd_, |
|
||||
const mode_t mode_); |
|
||||
|
|
||||
int mfs(const vector<string> &srcs_, |
|
||||
const uint64_t minfreespace_, |
|
||||
string &path_); |
|
||||
} |
|
@ -1,35 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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); |
|
||||
} |
|
@ -1,33 +0,0 @@ |
|||||
/* |
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 <fcntl.h> |
|
||||
|
|
||||
#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))); |
|
||||
} |
|
||||
} |
|
@ -1,67 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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); |
|
||||
} |
|
||||
} |
|
@ -1,313 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 <string>
|
|
||||
|
|
||||
#include <fcntl.h>
|
|
||||
#include <sys/stat.h>
|
|
||||
#include <sys/time.h>
|
|
||||
|
|
||||
#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); |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,53 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <stddef.h>
|
||||
|
|
||||
|
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_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <stddef.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
int |
||||
|
copydata(const int src_fd, |
||||
|
const int dst_fd, |
||||
|
const size_t count); |
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
/*
|
||||
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <sys/types.h>
|
||||
|
|
||||
|
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); |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
/* |
||||
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
} |
@ -0,0 +1,49 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <string>
|
||||
|
|
||||
|
#include <fcntl.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
|
||||
|
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_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,61 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <string>
|
||||
|
|
||||
|
#include <sys/types.h>
|
||||
|
|
||||
|
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_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <string>
|
||||
|
#include <vector>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
void |
||||
|
findallfiles(const std::vector<std::string> &basepaths_, |
||||
|
const char *fusepath_, |
||||
|
std::vector<std::string> *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); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <string>
|
||||
|
#include <vector>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
void |
||||
|
findallfiles(const std::vector<std::string> &basepaths, |
||||
|
const char *fusepath, |
||||
|
std::vector<std::string> *paths); |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <sys/types.h>
|
||||
|
|
||||
|
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
|
||||
|
} |
||||
|
} |
@ -0,0 +1,61 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <string>
|
||||
|
|
||||
|
#include <sys/types.h>
|
||||
|
|
||||
|
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_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <sys/stat.h>
|
||||
|
#include <sys/types.h>
|
||||
|
#include <unistd.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
fstat(const int fd_, |
||||
|
struct stat *st_) |
||||
|
{ |
||||
|
return ::fstat(fd_,st_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <unistd.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
fsync(const int fd_) |
||||
|
{ |
||||
|
return ::fsync(fd_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <sys/stat.h>
|
||||
|
|
||||
|
#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); |
||||
|
} |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <sys/stat.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
futimens(const int fd_, |
||||
|
const struct timespec ts_[2]) |
||||
|
{ |
||||
|
return ::futimens(fd_,ts_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,283 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <string>
|
||||
|
|
||||
|
#include <fcntl.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
#include <sys/time.h>
|
||||
|
|
||||
|
#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); |
||||
|
} |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <sys/stat.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
static |
||||
|
inline |
||||
|
int |
||||
|
futimens(const int fd_, |
||||
|
const struct timespec ts_[2]) |
||||
|
{ |
||||
|
return ::futimens(fd_,ts_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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); |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <fcntl.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
int |
||||
|
getfl(const int fd_) |
||||
|
{ |
||||
|
return ::fcntl(fd_,F_GETFL,0); |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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); |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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 <string>
|
||||
|
|
||||
|
#include <sys/stat.h>
|
||||
|
#include <sys/types.h>
|
||||
|
#include <unistd.h>
|
||||
|
|
||||
|
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_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue