mirror of https://github.com/trapexit/mergerfs.git
Antonio SJ Musumeci
4 years ago
135 changed files with 1722 additions and 910 deletions
-
8src/fs_acl.cpp
-
12src/fs_attr_linux.icpp
-
4src/fs_attr_unsupported.icpp
-
67src/fs_base_utime.hpp
-
313src/fs_base_utime_generic.hpp
-
50src/fs_clonefile.cpp
-
103src/fs_clonepath.cpp
-
0src/fs_close.hpp
-
0src/fs_closedir.hpp
-
53src/fs_copydata.cpp
-
29src/fs_copydata.hpp
-
2src/fs_copydata_copy_file_range.cpp
-
8src/fs_copydata_readwrite.cpp
-
53src/fs_cow.cpp
-
6src/fs_devid.hpp
-
0src/fs_dirfd.hpp
-
0src/fs_dup.hpp
-
42src/fs_eaccess.hpp
-
2src/fs_exists.hpp
-
20src/fs_faccessat.hpp
-
28src/fs_fadvise.cpp
-
2src/fs_fadvise.hpp
-
12src/fs_fadvise_posix.icpp
-
8src/fs_fadvise_unsupported.icpp
-
8src/fs_fallocate.cpp
-
0src/fs_fallocate.hpp
-
12src/fs_fallocate_linux.icpp
-
47src/fs_fallocate_osx.icpp
-
19src/fs_fallocate_posix.icpp
-
8src/fs_fallocate_unsupported.icpp
-
2src/fs_fchmod.hpp
-
49src/fs_fchmodat.hpp
-
3src/fs_fchown.hpp
-
8src/fs_fdatasync.hpp
-
61src/fs_fgetxattr.hpp
-
2src/fs_ficlone_linux.icpp
-
2src/fs_file_size.cpp
-
3src/fs_findonfs.cpp
-
41src/fs_flistxattr.hpp
-
0src/fs_flock.hpp
-
61src/fs_fsetxattr.hpp
-
36src/fs_fstat.hpp
-
0src/fs_fstatat.hpp
-
32src/fs_fsync.hpp
-
0src/fs_ftruncate.hpp
-
48src/fs_futimens.hpp
-
33src/fs_futimens_freebsd_11.hpp
-
283src/fs_futimens_generic.hpp
-
33src/fs_futimens_linux.hpp
-
4src/fs_futimesat.cpp
-
0src/fs_futimesat.hpp
-
8src/fs_futimesat_generic.icpp
-
67src/fs_futimesat_osx.icpp
-
6src/fs_getdents64.cpp
-
6src/fs_getdents64.hpp
-
2src/fs_has_space.cpp
-
4src/fs_info.cpp
-
0src/fs_ioctl.hpp
-
30src/fs_lchmod.hpp
-
34src/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
-
2src/fs_mktemp.cpp
-
10src/fs_movefile.cpp
-
0src/fs_open.hpp
-
0src/fs_opendir.hpp
-
0src/fs_read.hpp
-
0src/fs_readdir.hpp
-
0src/fs_readlink.hpp
-
0src/fs_realpath.hpp
-
2src/fs_realpathize.cpp
-
0src/fs_remove.hpp
-
0src/fs_rename.hpp
-
0src/fs_rmdir.hpp
-
46src/fs_stat.hpp
-
47src/fs_stat_utils.hpp
-
4src/fs_statvfs.hpp
-
2src/fs_statvfs_cache.cpp
-
0src/fs_symlink.hpp
-
0src/fs_truncate.hpp
-
0src/fs_unlink.hpp
-
27src/fs_utimensat.hpp
-
32src/fs_utimensat_freebsd.hpp
-
295src/fs_utimensat_generic.hpp
-
49src/fs_utimensat_linux.hpp
-
0src/fs_write.hpp
-
21src/fs_xattr.cpp
-
2src/fuse_access.cpp
-
4src/fuse_chmod.cpp
-
2src/fuse_chown.cpp
-
2src/fuse_create.cpp
-
2src/fuse_fallocate.cpp
@ -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,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,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,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_stat_utils.hpp"
|
|||
|
|||
#include <sys/stat.h>
|
|||
|
|||
#ifdef __linux__
|
|||
# include "fs_futimens_linux.hpp"
|
|||
#elif __FreeBSD__ >= 11
|
|||
# include "fs_futimens_freebsd_11.hpp"
|
|||
#else
|
|||
# include "fs_futimens_generic.hpp"
|
|||
#endif
|
|||
|
|||
namespace fs |
|||
{ |
|||
static |
|||
inline |
|||
int |
|||
futimens(const int fd_, |
|||
const struct stat &st_) |
|||
{ |
|||
struct timespec ts[2]; |
|||
|
|||
ts[0] = *fs::stat_atime(&st_); |
|||
ts[1] = *fs::stat_mtime(&st_); |
|||
|
|||
return fs::futimens(fd_,ts); |
|||
} |
|||
} |
@ -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,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); |
|||
} |
|||
} |
@ -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 |
|||
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_); |
|||
} |
|||
} |
@ -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
|
|||
|
|||
#ifdef __linux__
|
|||
# include "fs_utimensat_linux.hpp"
|
|||
#elif __FreeBSD__
|
|||
# include "fs_utimensat_freebsd.hpp"
|
|||
#else
|
|||
# include "fs_utimensat_generic.hpp"
|
|||
#endif
|
@ -0,0 +1,295 @@ |
|||
/*
|
|||
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_fstat.hpp"
|
|||
#include "fs_fstatat.hpp"
|
|||
#include "fs_futimesat.hpp"
|
|||
#include "fs_lutimens.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 |
|||
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); |
|||
} |
|||
} |
@ -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 |
|||
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_); |
|||
} |
|||
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue