Compare commits

...
293 Commits
Author SHA1 Message Date
Antonio SJ Musumeci 38e5815ba7 Merge pull request #379 from trapexit/docs
add info on inodes running out to faq on filled drives
2017-03-13 13:43:22 -04:00
Antonio SJ Musumeci cf2cb54e2a add info on inodes running out to faq on filled drives 2017-03-13 13:42:46 -04:00
Antonio SJ Musumeci b7269e9963 Merge pull request #378 from trapexit/docs
try to clarify how path preserving policies work and other tweaks to docs
2017-03-11 15:08:46 -05:00
Antonio SJ Musumeci 94ebccc6ed try to clarify how path preserving policies work and other tweaks to docs 2017-03-11 15:07:48 -05:00
Antonio SJ Musumeci 09dabc7b4c Merge pull request #376 from trapexit/docs
update docs to include dropcacheonclose and warn about directory mtime
2017-02-18 20:06:54 -05:00
Antonio SJ Musumeci 4e7e74d6f0 update docs to include dropcacheonclose and warn about directory mtime 2017-02-18 20:05:06 -05:00
Antonio SJ Musumeci dca6cb4826 Merge pull request #374 from trapexit/flush-cache-on-close
add option to drop file caches before closing files
2017-02-18 16:59:49 -05:00
Antonio SJ Musumeci 6aa62d03ff add option to drop file caches before closing files 2017-02-18 16:06:29 -05:00
Antonio SJ Musumeci 3a89491507 Merge pull request #372 from trapexit/apply-but-check
check metadata on chown/chmod errors when cloning
2017-02-15 23:32:38 -05:00
Antonio SJ Musumeci 492d895632 check metadata on chown/chmod errors when cloning 2017-02-15 09:08:27 -05:00
Antonio SJ Musumeci 899670bc93 Merge pull request #365 from trapexit/docs
misc document updates
2017-01-31 19:24:48 -05:00
Antonio SJ Musumeci 9cc9bb9de2 misc document updates 2017-01-31 19:10:54 -05:00
Antonio SJ Musumeci c25974de68 Merge pull request #362 from trapexit/docs
update documentation, focus on explaining double caching & direct_io
2017-01-19 12:01:10 -05:00
Antonio SJ Musumeci 16e7c72e99 update documentation, focus on explaining double caching & direct_io 2017-01-19 11:49:52 -05:00
Antonio SJ Musumeci 011febcb91 Merge pull request #361 from trapexit/cleanup
Cleanup
2017-01-18 23:30:30 -05:00
Antonio SJ Musumeci a60d815e92 add ifndefs to all headers 2017-01-17 11:45:44 -05:00
Antonio SJ Musumeci e93c946198 limit need to explicitly call .c_str() 2017-01-17 11:45:44 -05:00
Antonio SJ Musumeci 7b4e1ea36d remove clone command 2017-01-17 11:45:44 -05:00
Antonio SJ Musumeci 726b88e039 restructure error calculation 2017-01-17 11:45:43 -05:00
Antonio SJ Musumeci 078e4bab49 Merge pull request #360 from trapexit/posix-acl
check for system.posix_acl_default before setting umask
2017-01-16 23:21:51 -05:00
Antonio SJ Musumeci d67d5dec77 check for system.posix_acl_default before setting umask 2017-01-16 12:19:58 -05:00
Antonio SJ Musumeci 10a9918d20 Merge pull request #352 from trapexit/directio
use different read and write functions when using direct_io
2016-12-20 17:08:20 -05:00
Antonio SJ Musumeci 1aa76a54c2 use different read and write functions when using direct_io 2016-12-20 17:06:34 -05:00
Antonio SJ Musumeci 437067b5e0 Merge pull request #351 from trapexit/inode
compute inode in readdir
2016-12-16 11:16:59 -05:00
Antonio SJ Musumeci 67b48fcb3a compute inode in readdir 2016-12-16 10:57:24 -05:00
Antonio SJ Musumeci ea403b4f5a Merge pull request #350 from trapexit/versionfile
only remove src/version.hpp if git repo and git available
2016-12-14 21:42:58 -05:00
Antonio SJ Musumeci b1459c6cdc only remove src/version.hpp if git repo and git available 2016-12-14 21:42:43 -05:00
Antonio SJ Musumeci 953bca02fc Merge pull request #349 from trapexit/inode
support setting of inodes (using use_ino option)
2016-12-14 18:55:15 -05:00
Antonio SJ Musumeci c8fa51c81a support setting of inodes (using use_ino option)
creates a 64bit inode value from the underlying device value + original inode

final_ino = orig_ino | (dev << 32)

not perfect but given few filesystems use 64bit inodes nor is st_dev more than 16bit usually it should be fine
2016-12-14 18:53:21 -05:00
Antonio SJ Musumeci 365e153ae7 Merge pull request #348 from trapexit/readdir-set
replace std::set with klib's khash to increase readdir performance
2016-12-14 17:29:13 -05:00
Antonio SJ Musumeci 822204ff34 replace std::set with klib's khash to increase readdir performance 2016-12-14 17:24:48 -05:00
Antonio SJ Musumeci 9a261a7864 Merge pull request #341 from trapexit/docs
note that mergerfs should be run as root
2016-12-06 17:04:51 -05:00
Antonio SJ Musumeci 5f7a168d0b note that mergerfs should be run as root 2016-12-06 17:04:10 -05:00
Antonio SJ Musumeci aa71116928 Merge pull request #340 from trapexit/clonepath-errors
return clonepath errors
2016-12-06 16:54:39 -05:00
Antonio SJ Musumeci 35075bb0cd return clonepath errors
currently the error is ignored and it was expected the primary call would
fail. problem is it returns confusing errors as a result. (eg ENOENT vs EPERM)
2016-12-06 16:48:52 -05:00
Antonio SJ Musumeci 05d81dbc23 update manpage 2016-11-15 23:35:06 -05:00
Antonio SJ Musumeci 00235c15bf Merge pull request #336 from trapexit/sigfpe
ignore filesystems which return zeros for statfs. closes #335
2016-11-15 23:27:49 -05:00
Antonio SJ Musumeci 3c5351af93 ignore filesystems which return zeros for statfs. closes #335 2016-11-15 23:27:17 -05:00
Antonio SJ Musumeci 12b9fc1750 Merge pull request #334 from trapexit/freebsd
changes to allow compiling on FreeBSD
2016-11-01 15:47:37 -04:00
Antonio SJ Musumeci 3d2283f10f clang cpp doesn't like grep exiting early 2016-10-31 09:39:10 -04:00
Antonio SJ Musumeci 192bb9c57e remove usage of -D from install 2016-10-28 22:04:15 -04:00
Antonio SJ Musumeci 157dae0d2f define O_LARGEFILE and O_NOATIME if needed 2016-10-28 22:04:15 -04:00
Antonio SJ Musumeci 00c814dc58 consolidate and simplify utime 2016-10-28 22:04:09 -04:00
Antonio SJ Musumeci 6d6fb45a3b check if fdatasync is available and return ENOSYS if not 2016-10-27 16:59:04 -04:00
Antonio SJ Musumeci f954be60a4 Merge pull request #333 from yatesco/patch-1
minor correction of spelling mistake
2016-10-24 17:18:36 -04:00
Colin Yates 897f20bff8 minor correction of spelling mistake
:%s/cateogry/category/g
2016-10-24 09:32:41 +01:00
Antonio SJ Musumeci c7c5b07389 Merge pull request #330 from trapexit/cleanup
further abstraction of system calls
2016-10-20 16:52:32 -04:00
Antonio SJ Musumeci d0b6cd1f38 further abstraction of system calls 2016-10-20 16:51:49 -04:00
Antonio SJ Musumeci 1ad05d7783 Merge pull request #329 from trapexit/namespace
wrap most posix filesystem functions
2016-10-19 17:10:31 -04:00
Antonio SJ Musumeci 1dc7bff6e6 wrap most posix filesystem functions 2016-10-19 16:58:52 -04:00
Antonio SJ Musumeci 18d684cd16 Merge pull request #328 from trapexit/flock
add flock
2016-10-19 12:17:23 -04:00
Antonio SJ Musumeci 8f594e17d7 add flock 2016-10-19 11:58:44 -04:00
Antonio SJ Musumeci 77269a8bac Merge pull request #327 from trapexit/mhddfs
add some more explination to the FAQ
2016-10-19 09:39:25 -04:00
Antonio SJ Musumeci cd90193deb add some more explination to the FAQ 2016-10-19 09:38:48 -04:00
Antonio SJ Musumeci 35fca6364f Merge pull request #325 from trapexit/readme
add mergerfs.ctl and scorch to tooling section
2016-10-14 13:27:18 -04:00
Antonio SJ Musumeci cd71af8c5b add mergerfs.ctl and scorch to tooling section 2016-10-13 11:02:20 -04:00
Antonio SJ Musumeci a7f26d3769 Merge pull request #324 from trapexit/edquota
add EDQUOT to errors which trigger moveonenospc
2016-10-07 10:27:31 -04:00
Antonio SJ Musumeci 3fb7f8919a add EDQUOT to errors which trigger moveonenospc 2016-10-06 13:54:57 -04:00
Antonio SJ Musumeci abc4ed4d9f Merge pull request #321 from trapexit/manpage
update manpage
2016-09-19 17:07:42 -04:00
Antonio SJ Musumeci dfa82699b9 update manpage 2016-09-19 17:07:41 -04:00
Antonio SJ Musumeci b8beeaceb3 Merge pull request #320 from trapexit/setgroups-arm
use SYS_setgroup32 syscall if available. closes #319
2016-09-19 17:05:10 -04:00
Antonio SJ Musumeci d9a79062b8 use SYS_setgroup32 syscall if available. closes #319 2016-09-19 17:04:11 -04:00
Antonio SJ Musumeci a22b79c416 Merge pull request #318 from trapexit/pagecache-bug
add information about page cache kernel panic bug
2016-09-14 11:20:25 -04:00
Antonio SJ Musumeci b1f2e94a2f add information about page cache kernel panic bug
https://lkml.org/lkml/2016/9/14/527
2016-09-14 11:20:13 -04:00
Antonio SJ Musumeci 2ebd386b5b Merge pull request #317 from trapexit/manpage
recreate manpage
2016-09-14 08:50:51 -04:00
Antonio SJ Musumeci a8cd9b710e recreate manpage 2016-09-14 08:50:42 -04:00
Antonio SJ Musumeci 12d2cf7464 Merge pull request #316 from trapexit/debian-kfreebsd
small tweaks to build on Debian kFreeBSD
2016-09-14 08:36:25 -04:00
Antonio SJ Musumeci 7e423cd9ce small tweaks to build on Debian kFreeBSD 2016-09-14 08:36:06 -04:00
Antonio SJ Musumeci fa3218cb72 Merge pull request #315 from trapexit/futimes
fix futimes version of utimes wrapper
2016-09-13 21:36:58 -04:00
Antonio SJ Musumeci 0395e7c776 fix futimes version of utimes wrapper 2016-09-13 21:30:45 -04:00
Antonio SJ Musumeci a575cf76c2 Merge pull request #314 from trapexit/fadvise
fix #define typo
2016-09-13 17:40:28 -04:00
Antonio SJ Musumeci 93923177ee fix #define typo 2016-09-13 17:40:23 -04:00
Antonio SJ Musumeci 51858114b2 Merge pull request #313 from trapexit/fadvise
abstract posix_fadvise
2016-09-13 17:36:49 -04:00
Antonio SJ Musumeci 1513c92cbc abstract posix_fadvise 2016-09-13 17:36:28 -04:00
Antonio SJ Musumeci 7824586f76 Merge pull request #309 from jfreax/patch-1
Fix minor typo
2016-09-03 22:24:31 -04:00
Jens Dieskau 158dda9f23 Fix minor typo 2016-09-03 22:33:36 +02:00
Antonio SJ Musumeci 577bc67fa7 Merge pull request #305 from trapexit/ugid
rename include cpp files to have icpp extension
2016-08-26 14:44:43 -04:00
Antonio SJ Musumeci 1a698e5ef5 rename include cpp files to have icpp extension 2016-08-26 14:41:56 -04:00
Antonio SJ Musumeci a0885e33dc Merge pull request #304 from trapexit/freebsd
fix some build issues with Debian/kFreeBSD
2016-08-26 13:10:41 -04:00
Antonio SJ Musumeci 2ee6b4f581 include sys/types.h to pick up ssize_t 2016-08-26 13:09:15 -04:00
Antonio SJ Musumeci 709dda5069 support systems without ENODATA 2016-08-26 12:59:32 -04:00
Antonio SJ Musumeci f0f8e527b4 Merge pull request #301 from trapexit/time
make futimes crossplatform
2016-08-07 14:46:43 -04:00
Antonio SJ Musumeci 49474f01ca make futimes crossplatform 2016-08-07 14:42:54 -04:00
Antonio SJ Musumeci 9e8b309a90 Merge pull request #300 from trapexit/fuseversion
bump FUSE_USE_VERSION to 29
2016-08-04 17:15:37 -04:00
Antonio SJ Musumeci f7547d7cf5 Merge pull request #299 from trapexit/realpath
use dynamic buffer for realpath
2016-08-04 17:14:09 -04:00
Antonio SJ Musumeci bb02ab2cba Merge pull request #298 from trapexit/fssendfile
split sendfile wrapper into separate files
2016-08-04 17:13:28 -04:00
Antonio SJ Musumeci fb1432e14e Merge pull request #297 from trapexit/fsattr
make fs_attr compile on unsupported platforms
2016-08-04 17:12:33 -04:00
Antonio SJ Musumeci 34d38cb0fb split sendfile wrapper into separate files 2016-08-04 17:11:23 -04:00
Antonio SJ Musumeci 192a9d54d1 make fs_attr compile on unsupported platforms 2016-08-04 17:10:02 -04:00
Antonio SJ Musumeci 40574bd138 use dynamic buffer for realpath 2016-08-04 14:52:27 -04:00
Antonio SJ Musumeci 064fd5560f bump FUSE_USE_VERSION to 29 2016-08-04 14:02:59 -04:00
Antonio SJ Musumeci 073d1b6f6f Merge pull request #296 from trapexit/fallocate
add osx version of fallocate
2016-08-02 23:46:21 -04:00
Antonio SJ Musumeci 45f757dc60 add osx version of fallocate 2016-08-02 17:14:45 -04:00
Antonio SJ Musumeci 939b4a0fe5 Merge pull request #294 from trapexit/eprand
add epall and eprand policies
2016-08-02 11:29:20 -04:00
Antonio SJ Musumeci 0fceb8e0a3 add epall and eprand policies 2016-08-01 16:08:02 -04:00
Antonio SJ Musumeci 34662da806 Merge pull request #293 from trapexit/faccessat
replace nonstandard eaccess with POSIX.1-2008 faccessat
2016-07-29 12:48:08 -04:00
Antonio SJ Musumeci 7634eb1440 replace nonstandard eaccess with POSIX.1-2008 faccessat 2016-07-29 12:39:44 -04:00
Antonio SJ Musumeci 08cd5f89ff Merge pull request #291 from trapexit/typo
fix typo and clarify feature
2016-07-26 09:09:31 -04:00
Antonio SJ Musumeci 47f184a944 fix typo and clarify feature 2016-07-26 09:09:10 -04:00
Antonio SJ Musumeci 920f7fd049 Merge pull request #290 from trapexit/epff
add existing path first found policy. closes #289
2016-07-11 20:50:32 -04:00
Antonio SJ Musumeci a93ab6c2f5 add existing path first found policy. closes #289 2016-07-11 20:42:56 -04:00
Antonio SJ Musumeci a375f33eb4 Merge pull request #288 from trapexit/uint64_t
move size calculations to use uint64_t. fixes #287
2016-07-11 09:14:14 -04:00
Antonio SJ Musumeci 1e7b84f7fd Merge pull request #285 from waldyrious/patch-1
add license title
2016-07-11 09:13:36 -04:00
Antonio SJ Musumeci 43cbd9c670 move size calculations to use uint64_t. fixes #287 2016-07-11 09:04:47 -04:00
Waldir Pimenta 9f36eada14 add license title
It's not strictly required, but it's useful metadata, and part of the recommended license template text (see http://choosealicense.com/licenses/isc/ and https://opensource.org/licenses/isc-license)
2016-07-01 00:28:12 +01:00
Antonio SJ Musumeci 30cdfa64b8 reiterate path preserving policies 2016-06-07 20:51:18 -04:00
Antonio SJ Musumeci 81e9544f7d Merge pull request #281 from trapexit/update-man
update man page
2016-05-19 17:30:07 -04:00
Antonio SJ Musumeci 3cb2045ebb update man page 2016-05-19 17:28:37 -04:00
Antonio SJ Musumeci 652440fd8c Merge pull request #280 from trapexit/mmapbug
update info on mmap bug and when it was fixed
2016-05-17 16:09:38 -04:00
Antonio SJ Musumeci 6dc6fde641 update info on mmap bug and when it was fixed 2016-05-17 16:09:22 -04:00
Antonio SJ Musumeci 66fdcc4ef7 Merge pull request #279 from trapexit/fallocate
rework fallocate logic
2016-05-11 13:23:33 -04:00
Antonio SJ Musumeci cb35a374ac rework fallocate logic 2016-05-11 13:19:44 -04:00
Antonio SJ Musumeci 68210d9252 Merge pull request #278 from trapexit/ioctl-dir
fix ioctl on directories
2016-05-11 13:12:50 -04:00
Antonio SJ Musumeci 23b8e4582e fix ioctl on directories 2016-05-11 11:22:00 -04:00
Antonio SJ Musumeci 13511ea72a Merge pull request #275 from trapexit/updateman
update man page
2016-05-07 15:19:34 -04:00
Antonio SJ Musumeci 3a50344cb9 update man page 2016-05-07 15:18:48 -04:00
Antonio SJ Musumeci 9f27ad448a Merge pull request #274 from trapexit/lus
add least used space and existing path, least used space policies
2016-05-07 15:17:58 -04:00
Antonio SJ Musumeci be6341e6f0 create eplus (existing path, least used space) policy. closes #273 2016-05-07 15:15:51 -04:00
Antonio SJ Musumeci f7d3e8bf47 create lus (least used space) policy. closes #273 2016-05-07 14:59:42 -04:00
Antonio SJ Musumeci e541cdb755 Merge pull request #272 from trapexit/faq-direct-reads
faq update on direct writes
2016-05-03 11:44:24 -04:00
Antonio SJ Musumeci 74ed1b09ee faq update on direct writes 2016-05-03 11:44:04 -04:00
Antonio SJ Musumeci 9987111fa4 Merge pull request #271 from trapexit/fstabdocs
clean up information regarding fstab
2016-04-27 07:13:28 -04:00
Antonio SJ Musumeci d0414d7c78 clean up information regarding fstab 2016-04-27 07:13:05 -04:00
Antonio SJ Musumeci 8f6a7ba79a Merge pull request #270 from trapexit/fsname
add fsname to readme
2016-04-25 16:58:27 -04:00
Antonio SJ Musumeci ef8d8f306e add fsname to readme 2016-04-25 16:58:18 -04:00
Antonio SJ Musumeci 1de01684e0 Merge pull request #269 from trapexit/createcatdesc
further tweak language regarding policies wrt create category
2016-04-13 13:06:49 -04:00
Antonio SJ Musumeci cd15b7a66a further tweak language regarding policies wrt create category 2016-04-13 13:06:35 -04:00
Antonio SJ Musumeci 6b88258d81 Merge pull request #268 from trapexit/policy-desc
make policy descriptions more explicit
2016-04-13 12:46:26 -04:00
Antonio SJ Musumeci 8643d35ebf make policy descriptions more explicit 2016-04-13 12:45:49 -04:00
Antonio SJ Musumeci b7d7ace9bf Merge pull request #266 from trapexit/tweakreadme
tweak doc language
2016-04-06 14:57:21 -04:00
Antonio SJ Musumeci 1cfe1c3715 tweak doc language 2016-04-06 14:57:02 -04:00
Antonio SJ Musumeci 63b02b327b Merge pull request #265 from trapexit/mmap-bug
add details of mmap cache bug
2016-04-03 16:57:06 -04:00
Antonio SJ Musumeci dbb13ef7ad add details of mmap cache bug 2016-04-03 16:56:47 -04:00
Antonio SJ Musumeci 6aec6c939a Merge pull request #263 from trapexit/dualmount
add dual mount suggestion to mmap problem
2016-03-15 16:45:06 -04:00
Antonio SJ Musumeci 90ca14afff add dual mount suggestion to mmap problem 2016-03-15 16:44:49 -04:00
Antonio SJ Musumeci c7328293a0 Merge pull request #262 from trapexit/mmap-direct_io
add details regarding rtorrent, mmap, and direct_io
2016-03-15 08:25:06 -04:00
Antonio SJ Musumeci cfaf812c62 add details regarding rtorrent, mmap, and direct_io 2016-03-15 08:24:35 -04:00
Antonio SJ Musumeci 47fb6e29c6 Merge pull request #259 from trapexit/dedup-tool
update readme to include mergerfs.dedup
2016-03-11 18:03:33 -05:00
Antonio SJ Musumeci 0c6c69e02e update readme to include mergerfs.dedup 2016-03-11 18:03:22 -05:00
Antonio SJ Musumeci 4b6cfdc68a Merge pull request #258 from trapexit/tarball-url
change tar.gz build url
2016-03-11 16:55:26 -05:00
Antonio SJ Musumeci 309cfee52b change tar.gz build url 2016-03-11 16:55:10 -05:00
Antonio SJ Musumeci 9b3c085cf3 Merge pull request #257 from trapexit/man
tweak man page creation
2016-03-10 18:43:12 -05:00
Antonio SJ Musumeci 382ca876ca tweak man page creation 2016-03-10 18:42:32 -05:00
Antonio SJ Musumeci 93acfb015c Merge pull request #256 from trapexit/xattr
properly check errors of xattr. closes #255
2016-03-10 18:38:05 -05:00
Antonio SJ Musumeci 070ed08caa properly check errors of xattr. closes #255 2016-03-10 18:37:09 -05:00
Antonio SJ Musumeci 5d44161e77 Merge pull request #251 from trapexit/man
update precompiled man page
2016-03-06 02:23:47 -05:00
Antonio SJ Musumeci 6492fda483 update precompiled man page 2016-03-06 02:22:58 -05:00
Antonio SJ Musumeci 447fd8b2fb Merge pull request #250 from trapexit/rename
fix rename failing on non-path preserving policies
2016-03-06 02:22:23 -05:00
Antonio SJ Musumeci 2061211894 fix rename failing on non-path preserving policies 2016-03-06 02:21:23 -05:00
Antonio SJ Musumeci 5030d5a5b4 Merge pull request #249 from trapexit/clarify-rename
clarify that rename uses the create policy to make decisions
2016-03-04 20:33:10 -05:00
Antonio SJ Musumeci 4928944167 clarify that rename uses the create policy to make decisions 2016-03-04 20:32:52 -05:00
Antonio SJ Musumeci 6957cf39d1 Merge pull request #247 from trapexit/epmfs
re-add minfreespace check to epmfs policy
2016-03-04 13:56:15 -05:00
Antonio SJ Musumeci 12cf57dc5a re-add minfreespace check to epmfs policy 2016-03-04 13:52:31 -05:00
Antonio SJ Musumeci 26c2ebc843 Merge pull request #245 from trapexit/readme
change tooling names and add guide link
2016-03-03 10:47:45 -05:00
Antonio SJ Musumeci 59b08a5bc3 change tooling names and add guide link 2016-03-03 10:46:53 -05:00
Antonio SJ Musumeci 8ac3518725 Merge pull request #244 from trapexit/gitdebcl
fix building of platform specific deb packages
2016-03-01 00:19:59 -05:00
Antonio SJ Musumeci f4a4cc5812 fix building of platform specific deb packages 2016-03-01 00:19:05 -05:00
Antonio SJ Musumeci b93783ede0 Merge pull request #243 from trapexit/git2dbcl
fix printing of versions with no changes
2016-02-29 23:56:29 -05:00
Antonio SJ Musumeci ef4c583b3f fix printing of versions with no changes 2016-02-29 23:55:36 -05:00
Antonio SJ Musumeci 6d049c16d1 Merge pull request #242 from trapexit/statvfs
clearly separate usage of statvfs from stat for file existance
2016-02-29 23:11:00 -05:00
Antonio SJ Musumeci 4ecf3c5797 clearly separate usage of statvfs from stat for file existance
Used statvfs to also check for existance vs lstat. On dead symlinks
this resulted in ENOENT making certain functions fail.

closes #239
2016-02-29 23:04:59 -05:00
Antonio SJ Musumeci 4a63c000ca Merge pull request #241 from trapexit/policy-ff
add minfreespace checks to policy ff's create and remove fwfs
2016-02-29 18:15:12 -05:00
Antonio SJ Musumeci 779143f4b6 add minfreespace checks to policy ff's create and remove fwfs
fwfs is now covered by ff with the minfreespace and readonly checks
2016-02-29 18:06:59 -05:00
Antonio SJ Musumeci ccd3b5d2d0 Merge pull request #240 from trapexit/readme
update readme with minfreespace and readonly details
2016-02-29 15:15:10 -05:00
Antonio SJ Musumeci 4d7148cdd1 update readme with minfreespace and readonly details 2016-02-29 15:14:31 -05:00
Antonio SJ Musumeci 98a051b161 Merge pull request #238 from trapexit/policy-all
add readonly and minfreespace filters to all policy for creates. clos…
2016-02-29 10:55:55 -05:00
Antonio SJ Musumeci 14886a27f4 add readonly and minfreespace filters to all policy for creates. closes #236 2016-02-29 10:15:53 -05:00
Antonio SJ Musumeci 81b9918f6b Merge pull request #237 from trapexit/renamefix 2016-02-26 17:18:39 -05:00
Antonio SJ Musumeci 9819cf6133 fix clonepath being called on wrong source 2016-02-26 17:16:09 -05:00
Antonio SJ Musumeci c5e584fa5a Merge pull request #235 from trapexit/changeloger
fix creation of changelog
2016-02-25 17:53:24 -05:00
Antonio SJ Musumeci c56b488c8d fix creation of changelog 2016-02-25 17:52:47 -05:00
Antonio SJ Musumeci cd50a0b0c8 Merge pull request #234 from trapexit/renametweaks
normalize error handling in rename policy
2016-02-24 17:11:58 -05:00
Antonio SJ Musumeci e593927095 normalize error handling in rename policy 2016-02-24 17:10:56 -05:00
Antonio SJ Musumeci 12251cf7c2 Merge pull request #233 from trapexit/ffopt
ff policy tweaks
2016-02-24 13:02:24 -05:00
Antonio SJ Musumeci 7c85cd906a ff policy tweaks 2016-02-24 12:40:02 -05:00
Antonio SJ Musumeci 32c4b1ad1c Merge pull request #232 from trapexit/version
override standard libfuse version flag
2016-02-24 08:39:56 -05:00
Antonio SJ Musumeci 5cf3bb7c98 override standard libfuse version flag 2016-02-24 06:36:33 -05:00
Antonio SJ Musumeci 3f8a6525b3 Merge pull request #231 from trapexit/fstweaks
minor tweaks to filesystem utility functions
2016-02-23 12:35:42 -05:00
Antonio SJ Musumeci 25a039942c minor tweaks to filesystem utility functions 2016-02-23 12:28:20 -05:00
Antonio SJ Musumeci 400537d711 Merge pull request #230 from trapexit/findonfs
use stat/2 rather than statvfs/2 to find file drive
2016-02-23 12:07:31 -05:00
Antonio SJ Musumeci 792c9b9808 use stat/2 rather than statvfs/2 to find file drive 2016-02-23 12:06:16 -05:00
Antonio SJ Musumeci 476a8a50ea Merge pull request #228 from trapexit/readme
update / tweak readme
2016-02-21 18:31:02 -05:00
Antonio SJ Musumeci a698a8a545 update / tweak readme 2016-02-21 18:30:25 -05:00
Antonio SJ Musumeci 5b06bb24fb Merge pull request #227 from trapexit/policy-cleanup
remove unnecessary policies
2016-02-21 18:25:11 -05:00
Antonio SJ Musumeci d4ec341c4f remove unnecessary policies 2016-02-21 18:24:15 -05:00
Antonio SJ Musumeci 1bbe3a8879 Merge pull request #226 from trapexit/readonly
ignore drives mounted as readonly from create policies. closes #224
2016-02-21 14:35:53 -05:00
Antonio SJ Musumeci 5813d1e477 ignore drives mounted as readonly from create policies. closes #224 2016-02-21 14:34:40 -05:00
Antonio SJ Musumeci 81e77216fc Merge pull request #225 from trapexit/eplfs-readme
add eplfs info to readme
2016-02-18 13:32:44 -05:00
Antonio SJ Musumeci a4e60d7471 add eplfs info to readme 2016-02-18 13:32:30 -05:00
Antonio SJ Musumeci 8edb7c1e1c Merge pull request #223 from trapexit/statvfs
use stat.st_dev to uniquely identify mounts for statfs. closes #213
2016-02-15 22:57:35 -05:00
Antonio SJ Musumeci f3e75a0544 use stat.st_dev to uniquely identify mounts for statfs. closes #213 2016-02-15 22:55:47 -05:00
Antonio SJ Musumeci eed2bbf913 Merge pull request #222 from trapexit/policy
simplify policies
2016-02-15 02:14:48 -05:00
Antonio SJ Musumeci b3248a8f78 simplify policies 2016-02-15 02:06:58 -05:00
Antonio SJ Musumeci fc100006f9 Merge pull request #220 from trapexit/eplfs
add existing path, least free space policy. closes #216
2016-02-12 10:08:15 -05:00
Antonio SJ Musumeci 7bf1ca45e4 add existing path, least free space policy. closes #216 2016-02-12 10:06:41 -05:00
Antonio SJ Musumeci c568a6d356 Merge pull request #219 from trapexit/pathmake
use references to srcmounts rather than copies
2016-02-11 21:14:45 -05:00
Antonio SJ Musumeci 6086620e23 use references to srcmounts rather than copies 2016-02-11 21:09:31 -05:00
Antonio SJ Musumeci f7c37d2974 Merge pull request #218 from trapexit/why-mergerfs
add some "why mergerfs instead of X" sections to the FAQ
2016-02-11 15:51:55 -05:00
Antonio SJ Musumeci 3a51ceb327 add some "why mergerfs instead of X" sections to the FAQ 2016-02-11 15:51:22 -05:00
Antonio SJ Musumeci f510e539ab Merge pull request #215 from trapexit/trashdirs
add section to readme about trash directories
2016-02-11 15:08:28 -05:00
Antonio SJ Musumeci 681f3d7492 add section to readme about trash directories 2016-02-11 15:07:55 -05:00
Antonio SJ Musumeci a7c1b88bfe Merge pull request #212 from trapexit/libfuse-crashes
add information on fixing libfuse crashes
2016-02-01 09:47:14 -05:00
Antonio SJ Musumeci 0bac344c8b add information on fixing libfuse crashes 2016-02-01 09:45:40 -05:00
Antonio SJ Musumeci 40e41e472d Merge pull request #211 from trapexit/rpmspec
remove sbin from rpm spec file
2016-01-25 09:43:07 -05:00
Antonio SJ Musumeci 840f9b8593 remove sbin from rpm spec file 2016-01-25 09:42:27 -05:00
Antonio SJ Musumeci 1160868243 Merge pull request #210 from trapexit/statvfs
fix statvfs drive dedup. closes #209
2016-01-22 10:16:01 -05:00
Antonio SJ Musumeci f779f82ed6 fix statvfs drive dedup. closes #209 2016-01-22 10:15:24 -05:00
Antonio SJ Musumeci a629e60f5c Merge pull request #208 from trapexit/remove-clone
remove clone test tool
2016-01-21 14:55:15 -05:00
Antonio SJ Musumeci 3e20adb109 remove clone test tool 2016-01-21 14:48:12 -05:00
Antonio SJ Musumeci 1931e263be Merge pull request #207 from trapexit/update-man
update the precompiled man page
2016-01-21 12:49:44 -05:00
Antonio SJ Musumeci e285bde962 update the precompiled man page 2016-01-21 12:49:04 -05:00
Antonio SJ Musumeci d058a366ee Merge pull request #206 from trapexit/readme-tweaks
general tweaks to readme
2016-01-21 12:47:50 -05:00
Antonio SJ Musumeci 853769bd7c general tweaks to readme 2016-01-21 12:47:13 -05:00
Antonio SJ Musumeci a3e693c30e Merge pull request #205 from trapexit/symlink
make symlink function like mknod/mkdir. closes #204
2016-01-20 17:56:03 -05:00
Antonio SJ Musumeci ea325755a7 make symlink function like mknod/mkdir. closes #204 2016-01-20 17:55:20 -05:00
Antonio SJ Musumeci 091cc230d8 Merge pull request #203 from trapexit/mknod-fix
fix indexing of mknod targets. closes #202
2016-01-20 17:27:19 -05:00
Antonio SJ Musumeci 1d1694bbb5 fix indexing of mknod targets. closes #202 2016-01-20 17:24:50 -05:00
Antonio SJ Musumeci 8287f7f119 Merge pull request #201 from trapexit/remove-warning
remove incorrect warning about race condition with mkdir/mknod
2016-01-20 17:08:04 -05:00
Antonio SJ Musumeci 93397ea170 remove incorrect warning about race condition with mkdir/mknod 2016-01-20 17:07:33 -05:00
Antonio SJ Musumeci da6d9b8eab Merge pull request #200 from trapexit/statfs
dedup based on full statvfs struct rather than fsid. closes #183
2016-01-20 16:45:58 -05:00
Antonio SJ Musumeci 25265f4e85 dedup based on full statvfs struct rather than fsid. closes #183 2016-01-20 16:44:05 -05:00
Antonio SJ Musumeci d4caecacbd Merge pull request #199 from trapexit/remove-tools
remove tooling from repo. closes #198
2016-01-19 16:32:46 -05:00
Antonio SJ Musumeci de776b7cf0 remove tooling from repo. closes #198 2016-01-19 16:29:51 -05:00
Antonio SJ Musumeci 02c1ce5181 Merge pull request #197 from trapexit/link
have link act similar to rename
2016-01-19 16:14:06 -05:00
Antonio SJ Musumeci 62f8fc524e have link act similar to rename
closes #193
2016-01-19 16:08:02 -05:00
Antonio SJ Musumeci 2fe465a29c Merge pull request #196 from trapexit/license
move from MIT to ISC license. closes #194
2016-01-14 16:57:43 -05:00
Antonio SJ Musumeci 242af777be move from MIT to ISC license. closes #194 2016-01-14 16:56:38 -05:00
Antonio SJ Musumeci fe7d841500 Merge pull request #195 from trapexit/rv
all action functions return success should at least one succeed
2016-01-14 08:26:16 -05:00
Antonio SJ Musumeci 4c77ac4d24 all action functions return success should at least one succeed. closes #189 2016-01-14 07:58:57 -05:00
Antonio SJ Musumeci f905116c3d Merge pull request #192 from trapexit/manpage
update man page
2016-01-12 23:37:10 -05:00
Antonio SJ Musumeci b811522474 update man page 2016-01-12 23:36:32 -05:00
Antonio SJ Musumeci 9b80d6905b Merge pull request #191 from trapexit/srcmounts
replace srcpoints with srcmounts
2016-01-12 16:28:27 -05:00
Antonio SJ Musumeci 8a5c5240f2 replace srcpoints with srcmounts 2016-01-12 16:27:47 -05:00
Antonio SJ Musumeci 8257a1f765 Merge pull request #190 from trapexit/rename
rework rename algo to minimize likelihood of EXDEV being returned. cl…
2016-01-12 16:24:08 -05:00
Antonio SJ Musumeci a3e6a0352d rework rename algo to minimize likelihood of EXDEV being returned. closes #187 2016-01-12 16:23:12 -05:00
Antonio SJ Musumeci 47dc59bff2 Merge pull request #185 from trapexit/policy_template
change to using template for policy class
2015-12-29 16:23:10 -05:00
Antonio SJ Musumeci eb6d1a1bc2 change to using template for policy class 2015-12-29 16:14:37 -05:00
Antonio SJ Musumeci fbc2cd95cd Merge pull request #180 from trapexit/nonbash
Nonbash
2015-12-14 23:51:26 -05:00
Antonio SJ Musumeci 55c4a32614 add artifacts to gitignore 2015-12-14 23:50:35 -05:00
Antonio SJ Musumeci 51ae7d1980 change make to work with non-bash shells 2015-12-14 23:50:02 -05:00
Antonio SJ Musumeci 4adeb6348b Merge pull request #179 from trapexit/fix-noxattr
fix building without xattr
2015-12-14 19:02:05 -05:00
Antonio SJ Musumeci c731b7035c fix building without xattr 2015-12-14 18:48:04 -05:00
Antonio SJ Musumeci 0165fb24d4 Merge pull request #177 from trapexit/xattr-pid
add mergerfs pid to xattrs
2015-12-07 23:57:24 -05:00
Antonio SJ Musumeci 9e24796429 add mergerfs pid to xattrs 2015-12-07 21:20:12 -05:00
Antonio SJ Musumeci 2d71229fe9 Merge pull request #172 from trapexit/setgroups
use SYS_setgroups rather than setgroups on linux
2015-10-29 23:38:45 -04:00
Antonio SJ Musumeci 5e880bddba use SYS_setgroups rather than setgroups 2015-10-29 23:20:37 -04:00
Antonio SJ Musumeci af24bdb426 Merge pull request #171 from trapexit/support
add support section to readme and manpage
2015-10-29 15:27:56 -04:00
Antonio SJ Musumeci 8a651b0372 add support section to readme and manpage 2015-10-29 15:27:05 -04:00
Antonio SJ Musumeci 762a04242f Merge pull request #169 from trapexit/scan-check-cleanup
fix misc issues flagged by clang scan-build
2015-10-22 18:08:41 -04:00
Antonio SJ Musumeci 8cd747e673 Merge pull request #168 from trapexit/debversion
include distro and codename in deb package versions
2015-10-22 18:06:40 -04:00
Antonio SJ Musumeci 93cedabe9c fix misc issues flagged by clang scan-build 2015-10-22 18:06:11 -04:00
Antonio SJ Musumeci fd4ce1b5fa include distro and codename in deb package versions 2015-10-22 18:05:16 -04:00
Antonio SJ Musumeci f3a6876362 remove pandoc from build requirements 2015-10-18 00:15:28 -04:00
Antonio SJ Musumeci 61dbb85f35 Merge pull request #165 from trapexit/manpage
remove manpage from root directory
2015-10-17 22:08:46 -04:00
Antonio SJ Musumeci 30c29c9fae remove manpage from root directory 2015-10-17 22:07:40 -04:00
Antonio SJ Musumeci 10eb05a14b Merge pull request #164 from trapexit/manpage
if pandoc doesn't exist copy premade version
2015-10-17 21:38:52 -04:00
Antonio SJ Musumeci 8ed11a0e8f if pandoc doesn't exist copy premade version 2015-10-17 21:38:15 -04:00
Antonio SJ Musumeci 74f2a88ed2 Merge pull request #163 from trapexit/manpage
offer prebuilt manpage for platforms without easy access to pandoc
2015-10-16 18:57:27 -04:00
Antonio SJ Musumeci 46c8361fa9 offer prebuilt manpage for platforms without easy access to pandoc 2015-10-16 18:50:51 -04:00
Antonio SJ Musumeci 02df44129d update info on Samba client EXDEV issue 2015-10-16 08:30:54 -04:00
Antonio SJ Musumeci fe7960974d fix typo 2015-10-14 08:07:05 -04:00
Antonio SJ Musumeci 873c4a9840 add link to gvfs-fuse patch 2015-10-14 06:48:40 -04:00
Antonio SJ Musumeci 4df9b2e6f1 add documentation on SMB client EXDEV / EIO issue 2015-10-14 00:27:26 -04:00
Antonio SJ Musumeci e84c458cad Merge pull request #162 from trapexit/intsizes
fix minor integer casting issues
2015-10-13 23:34:18 -04:00
Antonio SJ Musumeci 1c7de2d83e fix minor integer casting issues 2015-10-13 23:33:33 -04:00
Antonio SJ Musumeci a10de2aaf9 update build dependencies for Fedora 2015-10-13 09:07:38 -04:00
Antonio SJ Musumeci f83cdc215f Merge pull request #160 from trapexit/rpm
add sbin directory to rpm spec
2015-10-13 07:14:23 -04:00
Antonio SJ Musumeci 3d7d2cf80a add sbin directory to rpm spec 2015-10-13 07:13:17 -04:00
Antonio SJ Musumeci 5d5428fbb3 Merge pull request #159 from trapexit/git2dbcl
enhance git2debcl to work with older python releases
2015-10-13 00:21:14 -04:00
Antonio SJ Musumeci 5489952aa8 enhance git2debcl to work with older python releases 2015-10-13 00:20:47 -04:00
Antonio SJ Musumeci 280309ad6d Merge pull request #158 from trapexit/fusedep
set rpm dependency to fuse
2015-10-12 23:52:16 -04:00
Antonio SJ Musumeci 068fbc0269 set rpm dependency to fuse 2015-10-12 23:51:52 -04:00
Antonio SJ Musumeci 6709791156 Merge pull request #157 from trapexit/mount.mergerfs
create mount.mergerfs symlink. closes #149
2015-10-12 23:45:04 -04:00
Antonio SJ Musumeci 5a76c41236 create mount.mergerfs symlink. closes #149 2015-10-12 23:43:17 -04:00
Antonio SJ Musumeci 3ccc94a560 Merge pull request #156 from trapexit/cisms
misc fixes to compile on older platforms
2015-10-12 19:52:34 -04:00
Antonio SJ Musumeci 58446f9124 misc fixes to compile on older platforms 2015-10-12 19:51:57 -04:00
Antonio SJ Musumeci ce2ec89964 Merge pull request #155 from trapexit/gidcache
rewrite gid cache system
2015-10-11 15:07:24 -04:00
Antonio SJ Musumeci 40f569be37 rewrite gid cache system
Uses fixed storage so as to not require C++11 local thread storage or memory allocation.
2015-10-11 15:01:57 -04:00
Antonio SJ Musumeci db85a7d3f2 Merge pull request #152 from trapexit/fsck
audit (and fix) file permissions and ownership. closes #148
2015-10-06 00:38:22 -04:00
Antonio SJ Musumeci f6d396c30d audit (and fix) file permissions and ownership. closes #148 2015-10-06 00:37:03 -04:00
Antonio SJ Musumeci 95e6ebf607 Merge pull request #151 from trapexit/uint32
remove usage of UINT32_MAX macro
2015-10-01 23:37:46 -04:00
Antonio SJ Musumeci 53e3284b26 remove usage of UINT32_MAX macro 2015-10-01 10:26:12 -04:00
Antonio SJ Musumeci 746bb68a0c Merge pull request #147 from trapexit/usage
provide usage text and version info. closes #146
2015-09-29 07:30:02 -04:00
Antonio SJ Musumeci 09ffc8c903 provide usage text and version info. closes #146 2015-09-29 07:29:10 -04:00
Antonio SJ Musumeci f844daa76c Merge pull request #145 from trapexit/debswap
swap deb and unsigned-deb make tagets. closes #140
2015-09-26 14:14:04 -04:00
Antonio SJ Musumeci c289dafadc swap deb and unsigned-deb make tagets. closes #140 2015-09-26 14:12:10 -04:00
Antonio SJ Musumeci 2e538068ef Merge pull request #144 from trapexit/enospc
move on enospc when writing feature. closes #141
2015-09-25 15:41:24 -04:00
Antonio SJ Musumeci 5808ab7795 move on enospc when writing feature. closes #141
This feature mimics the standard mhddfs behavior but is more thorough.
If a write fails and the errno is set to ENOSPC then mergerfs will (if
the feature is enabled) attempt to move the file to the drive with
the most free space but only if it has enough room for the file plus
the amount to be written. If that transfer is successful it will then
unlink the original file and attempt the previously failed write again.

The copy includes copying the path and file including the acls, owners,
attributes, extended attributes, and timestamps.
2015-09-25 15:14:17 -04:00
Antonio SJ Musumeci 4e5578de9c make note about escaping glob tokens more explicit 2015-09-25 13:48:03 -04:00
Antonio SJ Musumeci 4b375faf12 include rpm-build in Fedora dependencies 2015-09-24 17:59:49 -04:00
Antonio SJ Musumeci 9542e6340b include link to release page in readme 2015-09-24 15:07:39 -04:00
Antonio SJ Musumeci de583b70f7 clean up options listing 2015-09-23 16:42:36 -04:00
Antonio SJ Musumeci 8bf0f755e1 create summary feature section
And tweak intro.
2015-09-22 12:46:47 -04:00
221 changed files with 11652 additions and 4775 deletions
+8
View File
@@ -12,6 +12,14 @@
*.la
*.a
# build artifacts
mergerfs
obj/
src/version.hpp
# Debian files
debian/files
debian/changelog
# RPM files
rpmbuild/
+12 -18
View File
@@ -1,23 +1,17 @@
/*
The MIT License (MIT)
ISC License
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
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 above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
+41 -37
View File
@@ -1,24 +1,17 @@
# The MIT License (MIT)
# Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
#
# Copyright (c) 2014 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.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# 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.
PKGCONFIG = $(shell which pkg-config)
GIT = $(shell which git)
@@ -78,7 +71,7 @@ CFLAGS = -g -Wall \
$(OPTS) \
-Wno-unused-result \
$(FUSE_CFLAGS) \
-DFUSE_USE_VERSION=26 \
-DFUSE_USE_VERSION=29 \
-MMD \
-DFLAG_NOPATH=$(FLAG_NOPATH) \
-DFALLOCATE=$(FALLOCATE) \
@@ -93,10 +86,12 @@ EXEC_PREFIX = $(PREFIX)
DATAROOTDIR = $(PREFIX)/share
DATADIR = $(DATAROOTDIR)
BINDIR = $(EXEC_PREFIX)/bin
SBINDIR = $(EXEC_PREFIX)/sbin
MANDIR = $(DATAROOTDIR)/man
MAN1DIR = $(MANDIR)/man1
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
ifeq ($(XATTR_AVAILABLE),0)
@@ -104,7 +99,7 @@ $(warning "xattr not available: disabling")
CFLAGS += -DWITHOUT_XATTR
endif
all: $(TARGET) clonepath
all: $(TARGET)
help:
@echo "usage: make"
@@ -113,8 +108,8 @@ help:
$(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
$(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
clonepath: $(TARGET)
$(LN) -s $< $@
mount.mergerfs: $(TARGET)
$(LN) -fs "$<" "$@"
changelog:
$(GIT2DEBCL) --name $(TARGET) > ChangeLog
@@ -137,41 +132,50 @@ obj/%.o: src/%.cpp
$(CXX) $(CFLAGS) -c $< -o $@
clean: rpm-clean
$(RM) -rf obj
ifneq ($(GIT),)
ifeq ($(shell test -e .git; echo $$?),0)
$(RM) -f src/version.hpp
$(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
endif
endif
$(RM) -rf obj
$(RM) -f "$(TARGET)" mount.mergerfs
$(FIND) . -name "*~" -delete
distclean: clean
$(GIT) clean -fd
install: install-base install-clonepath install-man
install: install-base install-mount.mergerfs install-man
install-base: $(TARGET)
$(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
$(MKDIR) -p "$(INSTALLBINDIR)"
$(INSTALL) -v -m 0755 "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
install-clonepath: clonepath
$(CP) -a $< "$(INSTALLBINDIR)/$<"
install-mount.mergerfs: mount.mergerfs
$(MKDIR) -p "$(INSTALLBINDIR)"
$(CP) -a "$<" "$(INSTALLBINDIR)/$<"
install-man: $(MANPAGE)
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
$(MKDIR) -p "$(INSTALLMAN1DIR)"
$(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
install-strip: install-base
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
uninstall: uninstall-base uninstall-clonepath uninstall-man
uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
uninstall-base:
$(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
uninstall-clonepath:
$(RM) -f "$(INSTALLBINDIR)/clonepath"
uninstall-mount.mergerfs:
$(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
uninstall-man:
$(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
$(MANPAGE): README.md
$(PANDOC) -s -t man -o $(MANPAGE) README.md
ifneq (,$(PANDOC))
$(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
endif
man: $(MANPAGE)
@@ -188,10 +192,10 @@ tarball: clean man changelog authors src/version.hpp
debian-changelog:
$(GIT2DEBCL) --name $(TARGET) > debian/changelog
deb: debian-changelog
signed-deb: debian-changelog
dpkg-buildpackage
unsigned-deb: debian-changelog
deb: debian-changelog
dpkg-buildpackage -uc -us
rpm-clean:
@@ -200,7 +204,7 @@ rpm-clean:
rpm: tarball
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
$(eval VERSION := $(subst -,_,$(VERSION)))
$(MKDIR) -p rpmbuild/{BUILD,RPMS,SOURCES}
$(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
$(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
rpmbuild/SOURCES/$(TARGET).spec
cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
+339 -110
View File
@@ -1,55 +1,78 @@
% mergerfs(1) mergerfs user manual
% Antonio SJ Musumeci <trapexit@spawn.link>
% 2015-09-14
% 2017-02-18
# NAME
mergerfs - another FUSE union filesystem
mergerfs - another (FUSE based) union filesystem
# SYNOPSIS
mergerfs -o&lt;options&gt; &lt;srcpoints&gt; &lt;mountpoint&gt;
mergerfs -o&lt;options&gt; &lt;srcmounts&gt; &lt;mountpoint&gt;
# DESCRIPTION
**mergerfs** is similar to **mhddfs**, **unionfs**, and **aufs**. Like **mhddfs** in that it too uses **FUSE**. Like **aufs** in that it provides multiple policies for how to handle behavior.
**mergerfs** is a union filesystem geared towards simplifying storage and management of files across numerous commodity storage devices. It is similar to **mhddfs**, **unionfs**, and **aufs**.
Why create **mergerfs** when those exist? **mhddfs** has not been updated in some time nor very flexible. There are also security issues when with running as root. **aufs** is more flexible than **mhddfs** but contains some hard to debug inconsistencies in behavior on account of it being a kernel driver. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
# FEATURES
* Runs in userspace (FUSE)
* Configurable behaviors
* Support for extended attributes (xattrs)
* Support for file attributes (chattr)
* Runtime configurable (via xattrs)
* Safe to run as root
* Opportunistic credential caching
* Works with heterogeneous filesystem types
* Handling of writes to full drives (transparently move file to drive with capacity)
* Handles pool of readonly and read/write drives
# OPTIONS
###options###
* **defaults** is a shortcut for FUSE's **atomic_o_trunc**, **auto_cache**, **big_writes**, **default_permissions**, **splice_move**, **splice_read**, and **splice_write**. These options seem to provide the best performance.
* **minfreespace** (defaults to **4G**) is the minimum space value used for the **lfs**, **fwfs**, and **epmfs** policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively.
* All FUSE functions which have a category (see below) are option keys. The syntax being **func.&lt;func&gt;=&lt;policy&gt;**. Example: **func.getattr=newest**.
* To set all function policies in a category use **category.&lt;category&gt;=&lt;policy&gt;**. Example: **category.create=mfs**.
* Options are evaluated in the order listed so if the options are **func.rmdir=rand,category.action=ff** the **action** category setting will override the **rmdir** setting.
* **defaults**: a shortcut for FUSE's **atomic_o_trunc**, **auto_cache**, **big_writes**, **default_permissions**, **splice_move**, **splice_read**, and **splice_write**. These options seem to provide the best performance.
* **direct_io**: causes FUSE to bypass caching which can increase write speeds at the detriment of reads. Note that not enabling `direct_io` will cause double caching of files and therefore less memory for caching generally. However, `mmap` does not work when `direct_io` is enabled.
* **minfreespace**: the minimum space value used for creation policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively. (default: 4G)
* **moveonenospc**: when enabled (set to **true**) if a **write** fails with **ENOSPC** or **EDQUOT** a scan of all drives will be done looking for the drive with most free space which is at least the size of the file plus the amount which failed to write. An attempt to move the file to that drive will occur (keeping all metadata possible) and if successful the original is unlinked and the write retried. (default: false)
* **use_ino**: causes mergerfs to supply file/directory inodes rather than libfuse. While not a default it is generally recommended it be enabled so that hard linked files share the same inode value.
* **dropcacheonclose**: when a file is requested to be closed call `posix_fadvise` on it first to instruct the kernel that we no longer need the data and it can drop its cache. Recommended when **direct_io** is not enabled to limit double caching. (default: false)
* **fsname**: sets the name of the filesystem as seen in **mount**, **df**, etc. Defaults to a list of the source paths concatenated together with the longest common prefix removed.
* **func.&lt;func&gt;=&lt;policy&gt;**: sets the specific FUSE function's policy. See below for the list of value types. Example: **func.getattr=newest**
* **category.&lt;category&gt;=&lt;policy&gt;**: Sets policy of all FUSE functions in the provided category. Example: **category.create=mfs**
###srcpoints###
**NOTE:** Options are evaluated in the order listed so if the options are **func.rmdir=rand,category.action=ff** the **action** category setting will override the **rmdir** setting.
The source points argument is a colon (':') delimited list of paths. To make it simpler to include multiple source points without having to modify your [fstab](http://linux.die.net/man/5/fstab) we also support [globbing](http://linux.die.net/man/7/glob).
###srcmounts###
The srcmounts (source mounts) argument is a colon (':') delimited list of paths to be included in the pool. It does not matter if the paths are on the same or different drives nor does it matter the filesystem. Used and available space will not be duplicated for paths on the same device and any features which aren't supported by the underlying filesystem (such as file attributes or extended attributes) will return the appropriate errors.
To make it easier to include multiple source mounts mergerfs supports [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will expand it.**
```
$ mergerfs /mnt/disk\*:/mnt/cdrom /media/drives
$ mergerfs -o defaults,allow_other,use_ino /mnt/disk\*:/mnt/cdrom /media/drives
```
The above line will use all points in /mnt prefixed with *disk* and the directory *cdrom*. The `*` (or any glob tokens) must be escaped on the command line else the shell resolve them.
The above line will use all mount points in /mnt prefixed with **disk** and the **cdrom**.
In /etc/fstab it'd look like the following:
To have the pool mounted at boot or otherwise accessable from related tools use **/etc/fstab**.
```
# <file system> <mount point> <type> <options> <dump> <pass>
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other 0 0
# <file system> <mount point> <type> <options> <dump> <pass>
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other,use_ino 0 0
```
**NOTE:** the globbing is done at mount or xattr update time. If a new directory is added matching the glob after the fact it will not be included.
**NOTE:** the globbing is done at mount or xattr update time (see below). If a new directory is added matching the glob after the fact it will not be automatically included.
# POLICIES
**NOTE:** for mounting via **fstab** to work you must have **mount.fuse** installed. For Ubuntu/Debian it is included in the **fuse** package.
Filesystem calls are broken up into 3 categories: **action**, **create**, **search**. There are also some calls which have no policy attached due to state being kept between calls. These categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a category though some aren't terribly practical. For instance: **rand** (Random) may be useful for **create** but could lead to very odd behavior if used for **search**.
# FUNCTIONS / POLICIES / CATEGORIES
#### Functional classifications ####
The POSIX filesystem API has a number of functions. **creat**, **stat**, **chown**, etc. In mergerfs these functions are grouped into 3 categories: **action**, **create**, and **search**. Functions and categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a function or category though some may not be very useful in practice. For instance: **rand** (random) may be useful for file creation (create) but could lead to very odd behavior if used for `chmod` (though only if there were more than one copy of the file).
Policies, when called to create, will ignore drives which are readonly. This allows for readonly and read/write drives to be mixed together. Note that the drive must be explicitly mounted with the **ro** mount option for this to work.
#### Function / Category classifications ####
| Category | FUSE Functions |
|----------|----------------|
@@ -58,22 +81,28 @@ Filesystem calls are broken up into 3 categories: **action**, **create**, **sear
| search | access, getattr, getxattr, ioctl, listxattr, open, readlink |
| N/A | fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, release, statfs, write |
**ioctl** behaves differently if its acting on a directory. It'll use the **getattr** policy to find and open the directory before issuing the **ioctl**. In other cases where something may be searched (to confirm a directory exists across all source mounts) then **getattr** will be used.
Due to FUSE limitations **ioctl** behaves differently if its acting on a directory. It'll use the **getattr** policy to find and open the directory before issuing the **ioctl**. In other cases where something may be searched (to confirm a directory exists across all source mounts) **getattr** will also be used.
#### Policy descriptions ####
| Policy | Description |
|--------------|-------------|
| ff (first found) | Given the order of the drives act on the first one found (regardless if stat would return EACCES). |
| ffwp (first found w/ permissions) | Given the order of the drives act on the first one found which you have access (stat does not error with EACCES). |
| newest (newest file) | If multiple files exist return the one with the most recent mtime. |
| mfs (most free space) | Use the drive with the most free space available. |
| epmfs (existing path, most free space) | If the path exists on multiple drives use the one with the most free space and is greater than **minfreespace**. If no drive has at least **minfreespace** then fallback to **mfs**. |
| fwfs (first with free space) | Pick the first drive which has at least **minfreespace**. |
| lfs (least free space) | Pick the drive with least available space but more than **minfreespace**. |
| rand (random) | Pick an existing drive at random. |
| all | Applies action to all found. For searches it will behave like first found **ff**. |
| enosys, einval, enotsup, exdev, erofs | Exclusively return `-1` with `errno` set to the respective value. Useful for debugging other applications' behavior to errors. |
| all | Search category: acts like **ff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **ff**. It will exclude readonly drives and those with free space less than **minfreespace**. |
| epall (existing path, all) | Search category: acts like **epff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all existing paths found. **create** works like **epff**. Excludes readonly drives and those with free space less than **minfreespace**. |
| epff (existing path, first found) | Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found where the relative path already exists. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). Falls back to **ff**. |
| eplfs (existing path, least free space) | Of all the drives on which the relative path exists choose the drive with the least free space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lfs**. |
| eplus (existing path, least used space) | Of all the drives on which the relative path exists choose the drive with the least used space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lus**. |
| epmfs (existing path, most free space) | Of all the drives on which the relative path exists choose the drive with the most free space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
| eprand (existing path, random) | Calls **epall** and then randomizes. Otherwise behaves the same as **epall**. |
| erofs | Exclusively return **-1** with **errno** set to **EROFS** (Read-only filesystem). By setting **create** functions to this you can in effect turn the filesystem mostly readonly. |
| ff (first found) | Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
| lfs (least free space) | Pick the drive with the least available free space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
| lus (least used space) | Pick the drive with the least used space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
| mfs (most free space) | Pick the drive with the most available free space. For **create** category functions it will exclude readonly drives. Falls back to **ff**. |
| newest | Pick the file / directory with the largest mtime. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
| rand (random) | Calls **all** and then randomizes. |
**epff**, **eplfs**, **eplus**, **epmf**, **eprand** are `path preserving` policies. As the descriptions above explain they will only consider drives where the relative path being accessed already exists. Non-path preserving policies will result in paths being copied to drives as necessary.
#### Defaults ####
@@ -83,35 +112,69 @@ Filesystem calls are broken up into 3 categories: **action**, **create**, **sear
| create | epmfs |
| search | ff |
#### rename ####
#### rename & link ####
[rename](http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky function in a merged system. Normally if a rename can't be done atomically due to the from and to paths existing on different mount points it will return `-1` with `errno = EXDEV`. The atomic rename is most critical for replacing files in place atomically (such as securing writing to a temp file and then replacing a target). The problem is that by merging multiple paths you can have N instances of the source and destinations on different drives. Meaning that if you just renamed each source locally you could end up with the destination files not overwriten / replaced. To address this mergerfs works in the following way. If the source and destination exist in different directories it will immediately return `EXDEV`. Generally it's not expected for cross directory renames to work so it should be fine for most instances (mv,rsync,etc.). If they do belong to the same directory it then runs the `rename` policy to get the files to rename. It iterates through and renames each file while keeping track of those paths which have not been renamed. If all the renames succeed it will then `unlink` or `rmdir` the other paths to clean up any preexisting target files. This allows the new file to be found without the file itself ever disappearing. There may still be some issues with this behavior. Particularly on error. At the moment however this seems the best policy.
[rename](http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky function in a merged system. Under normal situations rename only works within a single filesystem or device. If a rename can't be done atomically due to the source and destination paths existing on different mount points it will return **-1** with **errno = EXDEV** (cross device).
Originally mergerfs would return EXDEV whenever a rename was requested which was cross directory in any way. This made the code simple and was technically complient with POSIX requirements. However, many applications fail to handle EXDEV at all and treat it as a normal error or otherwise handle it poorly. Such apps include: gvfsd-fuse v1.20.3 and prior, Finder / CIFS/SMB client in Apple OSX 10.9+, NZBGet, Samba's recycling bin feature.
As a result a compromise was made in order to get most software to work while still obeying mergerfs' policies. Below is the rather complicated logic.
* If using a **create** policy which tries to preserve directory paths (epff,eplfs,eplus,epmfs)
* Using the **rename** policy get the list of files to rename
* For each file attempt rename:
* If failure with ENOENT run **create** policy
* If create policy returns the same drive as currently evaluating then clone the path
* Re-attempt rename
* If **any** of the renames succeed the higher level rename is considered a success
* If **no** renames succeed the first error encountered will be returned
* On success:
* Remove the target from all drives with no source file
* Remove the source from all drives which failed to rename
* If using a **create** policy which does **not** try to preserve directory paths
* Using the **rename** policy get the list of files to rename
* Using the **getattr** policy get the target path
* For each file attempt rename:
* If the source drive != target drive:
* Clone target path from target drive to source drive
* Rename
* If **any** of the renames succeed the higher level rename is considered a success
* If **no** renames succeed the first error encountered will be returned
* On success:
* Remove the target from all drives with no source file
* Remove the source from all drives which failed to rename
The the removals are subject to normal entitlement checks.
The above behavior will help minimize the likelihood of EXDEV being returned but it will still be possible.
**link** uses the same basic strategy.
If you're receiving errors from software when files are moved / renamed then you should consider changing the create policy to one which is **not** path preserving.
#### readdir ####
[readdir](http://linux.die.net/man/3/readdir) is very different from most functions in this realm. It certainly could have it's own set of policies to tweak its behavior. At this time it provides a simple **first found** merging of directories and file found. That is: only the first file or directory found for a directory is returned. Given how FUSE works though the data representing the returned entry comes from **getattr**.
It could be extended to offer the ability to see all files found. Perhaps concatenating **#** and a number to the name. But to really be useful you'd need to be able to access them which would complicate file lookup.
[readdir](http://linux.die.net/man/3/readdir) is different from all other filesystem functions. While it could have it's own set of policies to tweak its behavior at this time it provides a simple union of files and directories found. Remember that any action or information queried about these files and directories come from the respective function. For instance: an **ls** is a **readdir** and for each file/directory returned **getattr** is called. Meaning the policy of **getattr** is responsible for choosing the file/directory which is the source of the metadata you see in an **ls**.
#### statvfs ####
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple points on the same drive will not result in double counting it's space.
**NOTE:** Since we can not (easily) replicate the atomicity of an **mkdir** or **mknod** without side effects those calls will first do a scan to see if the file exists and then attempts a create. This means there is a slight race condition. Worse case you'd end up with the directory or file on more than one mount.
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple sources on the same drive will not result in double counting it's space.
# BUILDING
**NOTE:** Prebuilt packages can be found at: https://github.com/trapexit/mergerfs/releases
First get the code from [github](http://github.com/trapexit/mergerfs).
```
$ git clone https://github.com/trapexit/mergerfs.git
$ # or
$ wget https://github.com/trapexit/mergerfs/archive/master.zip
$ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.tar.gz
```
#### Debian / Ubuntu
```
$ sudo apt-get install g++ pkg-config git git-buildpackage pandoc debhelper libfuse-dev libattr1-dev
$ sudo apt-get install g++ pkg-config git git-buildpackage pandoc debhelper libfuse-dev libattr1-dev python
$ cd mergerfs
$ make deb
$ sudo dpkg -i ../mergerfs_version_arch.deb
@@ -120,7 +183,7 @@ $ sudo dpkg -i ../mergerfs_version_arch.deb
#### Fedora
```
$ su -
# dnf install fuse-devel libattr-devel pandoc gcc-c++
# dnf install rpm-build fuse-devel libattr-devel pandoc gcc-c++ git make which python
# cd mergerfs
# make rpm
# rpm -i rpmbuild/RPMS/<arch>/mergerfs-<verion>.<arch>.rpm
@@ -128,7 +191,7 @@ $ su -
#### Generically
Have pkg-config, pandoc, libfuse, libattr1 installed.
Have git, python, pkg-config, pandoc, libfuse, libattr1 installed.
```
$ cd mergerfs
@@ -146,11 +209,44 @@ $ sudo make install
There is a pseudo file available at the mount point which allows for the runtime modification of certain **mergerfs** options. The file will not show up in **readdir** but can be **stat**'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
Even if xattrs are disabled for mergerfs the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls against this pseudo file will still work.
Any changes made at runtime are **not** persisted. If you wish for values to persist they must be included as options wherever you configure the mounting of mergerfs (fstab).
##### Keys #####
Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
Use `xattr -l /mount/point/.mergerfs` to see all supported keys. Some are informational and therefore readonly.
###### user.mergerfs.srcmounts ######
Used to query or modify the list of source mounts. When modifying there are several shortcuts to easy manipulation of the list.
| Value | Description |
|--------------|-------------|
| [list] | set |
| +<[list] | prepend |
| +>[list] | append |
| -[list] | remove all values provided |
| -< | remove first in list |
| -> | remove last in list |
###### minfreespace ######
Input: interger with an optional multiplier suffix. **K**, **M**, or **G**.
Output: value in bytes
###### moveonenospc ######
Input: **true** and **false**
Ouput: **true** or **false**
###### categories / funcs ######
Input: short policy string as described elsewhere in this document
Output: the policy string except for categories where its funcs have multiple types. In that case it will be a comma separated list
##### Example #####
@@ -158,38 +254,15 @@ Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
[trapexit:/tmp/mount] $ xattr -l .mergerfs
user.mergerfs.srcmounts: /tmp/a:/tmp/b
user.mergerfs.minfreespace: 4294967295
user.mergerfs.policies: all,einval,enosys,enotsup,epmfs,erofs,exdev,ff,ffwp,fwfs,lfs,mfs,newest,rand
user.mergerfs.version: 2.5.0
user.mergerfs.category.action: all
user.mergerfs.category.create: epmfs
user.mergerfs.category.search: ff
user.mergerfs.func.access: ff
user.mergerfs.func.chmod: all
user.mergerfs.func.chown: all
user.mergerfs.func.create: epmfs
user.mergerfs.func.getattr: ff
user.mergerfs.func.getxattr: ff
user.mergerfs.func.link: all
user.mergerfs.func.listxattr: ff
user.mergerfs.func.mkdir: epmfs
user.mergerfs.func.mknod: epmfs
user.mergerfs.func.open: ff
user.mergerfs.func.readlink: ff
user.mergerfs.func.removexattr: all
user.mergerfs.func.rename: all
user.mergerfs.func.rmdir: all
user.mergerfs.func.setxattr: all
user.mergerfs.func.symlink: epmfs
user.mergerfs.func.truncate: all
user.mergerfs.func.unlink: all
user.mergerfs.func.utimens: all
user.mergerfs.moveonenospc: false
...
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
ff
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search ffwp .mergerfs
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search newest .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
ffwp
newest
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
@@ -204,31 +277,13 @@ ffwp
/tmp/a:/tmp/b:/tmp/c
```
##### user.mergerfs.srcmounts #####
For **user.mergerfs.srcmounts** there are several instructions available for manipulating the list. The value provided is just as the value used at mount time. A colon (':') delimited list of full path globs.
| Instruction | Description |
|--------------|-------------|
| [list] | set |
| +<[list] | prepend |
| +>[list] | append |
| -[list] | remove all values provided |
| -< | remove first in list |
| -> | remove last in list |
##### misc #####
Categories and funcs take a policy as described in the previous section. When reading funcs you'll get the policy string. However, with categories you'll get a comma separated list of policies for each type found. For example: if all search functions are **ff** except for **access** which is **ffwp** the value for **user.mergerfs.category.search** will be **ff,ffwp**.
#### mergerfs file xattrs ####
#### file / directory xattrs ####
While they won't show up when using [listxattr](http://linux.die.net/man/2/listxattr) **mergerfs** offers a number of special xattrs to query information about the files served. To access the values you will need to issue a [getxattr](http://linux.die.net/man/2/getxattr) for one of the following:
* **user.mergerfs.basepath:** the base mount point for the file given the current search policy
* **user.mergerfs.basepath:** the base mount point for the file given the current getattr policy
* **user.mergerfs.relpath:** the relative path of the file from the perspective of the mount point
* **user.mergerfs.fullpath:** the full path of the original file given the search policy
* **user.mergerfs.fullpath:** the full path of the original file given the getattr policy
* **user.mergerfs.allpaths:** a NUL ('\0') separated list of full paths to all files found
```
@@ -245,33 +300,207 @@ A B C
/mnt/b/full/path/to/A
```
# TOOLING
* https://github.com/trapexit/mergerfs-tools
* mergerfs.ctl: A tool to make it easier to query and configure mergerfs at runtime
* mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
* mergerfs.dedup: Will help identify and optionally remove duplicate files
* mergerfs.balance: Rebalance files across drives by moving them from the most filled to the least filled
* mergerfs.mktrash: Creates FreeDesktop.org Trash specification compatible directories on a mergerfs mount
* https://github.com/trapexit/scorch
* scorch: A tool to help discover silent corruption of files
* https://github.com/trapexit/bbf
* bbf (bad block finder): a tool to scan for and 'fix' hard drive bad blocks and find the files using those blocks
# TIPS / NOTES
* If you don't see some directories / files you expect in a merged point be sure the user has permission to all the underlying directories. If `/drive0/a` has is owned by `root:root` with ACLs set to `0700` and `/drive1/a` is `root:root` and `0755` you'll see only `/drive1/a`.
* Since POSIX gives you only error or success on calls its difficult to determine the proper behavior when applying the behavior to multiple targets. Generally if something succeeds when reading it returns the data it can. If something fails when making an action we continue on and return the last error.
* The recommended options are **defaults,allow_other**. The **allow_other** is to allow users who are not the one which executed mergerfs access to the mountpoint. **defaults** is described above and should offer the best performance. It's possible that if you're running on an older platform the **splice** features aren't available and could error. In that case simply use the other options manually.
* Remember that some policies mixed with some functions may result in strange behaviors. Not that some of these behaviors and race conditions couldn't happen outside **mergerfs** but that they are far more likely to occur on account of attempt to merge together multiple sources of data which could be out of sync due to the different policies.
* An example: [Kodi](http://kodi.tv) and [Plex](http://plex.tv) can apparently use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether or not to scan for new content rather than simply performing a full scan. If using the current default **getattr** policy of **ff** its possible **Kodi** will miss an update on account of it returning the first directory found's **stat** info and its a later directory on another mount which had the **mtime** recently updated. To fix this you will want to set **func.getattr=newest**. Remember though that this is just **stat**. If the file is later **open**'ed or **unlink**'ed and the policy is different for those then a completely different file or directory could be acted on.
* Due to previously mentioned issues its generally best to set **category** wide policies rather than individual **func**'s. This will help limit the confusion of tools such as [rsync](http://linux.die.net/man/1/rsync).
* The recommended options are **defaults,allow_other,direct_io,use_ino**.
* Run mergerfs as `root` unless you're merging paths which are owned by the same user otherwise strange permission issues may arise.
* https://github.com/trapexit/backup-and-recovery-howtos : A set of guides / howtos on creating a data storage system, backing it up, maintaining it, and recovering from failure.
* If you don't see some directories and files you expect in a merged point or policies seem to skip drives be sure the user has permission to all the underlying directories. Use `mergerfs.fsck` to audit the drive for out of sync permissions.
* Do *not* use `direct_io` if you expect applications (such as rtorrent) to [mmap](http://linux.die.net/man/2/mmap) files. It is not currently supported in FUSE w/ `direct_io` enabled.
* Since POSIX gives you only error or success on calls its difficult to determine the proper behavior when applying the behavior to multiple targets. **mergerfs** will return an error only if all attempts of an action fail. Any success will lead to a success returned. This means however that some odd situations may arise.
* [Kodi](http://kodi.tv), [Plex](http://plex.tv), [Subsonic](http://subsonic.org), etc. can use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether to scan for new content rather than simply performing a full scan. If using the default **getattr** policy of **ff** its possible **Kodi** will miss an update on account of it returning the first directory found's **stat** info and its a later directory on another mount which had the **mtime** recently updated. To fix this you will want to set **func.getattr=newest**. Remember though that this is just **stat**. If the file is later **open**'ed or **unlink**'ed and the policy is different for those then a completely different file or directory could be acted on.
* Some policies mixed with some functions may result in strange behaviors. Not that some of these behaviors and race conditions couldn't happen outside **mergerfs** but that they are far more likely to occur on account of attempt to merge together multiple sources of data which could be out of sync due to the different policies.
* For consistency its generally best to set **category** wide policies rather than individual **func**'s. This will help limit the confusion of tools such as [rsync](http://linux.die.net/man/1/rsync). However, the flexibility is there if needed.
# Known Issues / Bugs
# KNOWN ISSUES / BUGS
* Due to the overhead of [getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs utilizes a cache. This cache is opportunistic and per thread. This means each thread will query the supplemental groups for a user when that particular thread needs to change credentials and currently it will keep that data for the lifetime of the mount or thread. This means that if a user is added to a group it may not be picked up without the restart of mergerfs. However, since the high level FUSE API's (at least the standard version) thread pool dynamically grows and shrinks it's possible that over time a thread will be killed and later a new thread with no cache will start and query the new data.
#### directory mtime is not being updated
Remember that the default policy for `getattr` is `ff`. The information for the first directory found will be returned. If it wasn't the directory which had been updated then it will appear outdated.
The reason this is the default is because any other policy would be far more expensive and for many applications it is unnecessary. To always return the directory with the most recent mtime or a faked value based on all found would require a scan of all drives. That alone is far more expensive than `ff` but would also possibly spin up sleeping drives.
If you always want the directory information from the one with the most recent mtime then use the `newest` policy for `getattr`.
#### cached memory appears greater than it should be
Use the `direct_io` option as described above. Due to what mergerfs is doing there ends up being two caches of a file under normal usage. One from the underlying filesystem and one from mergerfs. Enabling `direct_io` removes the mergerfs cache. This saves on memory but means the kernel needs to communicate with mergerfs more often and can therefore result in slower speeds.
Since enabling `direct_io` disables `mmap` this is not an ideal situation however write speeds should be increased.
If `direct_io` is disabled it is probably a good idea to enable `dropcacheonclose` to minimize double caching.
#### NFS clients don't work
Some NFS clients appear to fail when a mergerfs mount is exported. Kodi in particular seems to have issues.
Try enabling the `use_ino` option. Some have reported that it fixes the issue.
#### rtorrent fails with ENODEV (No such device)
Be sure to turn off `direct_io`. rtorrent and some other applications use [mmap](http://linux.die.net/man/2/mmap) to read and write to files and offer no failback to traditional methods. FUSE does not currently support mmap while using `direct_io`. There will be a performance penalty on writes with `direct_io` off as well as the problem of double caching but it's the only way to get such applications to work. If the performance loss is too high for other apps you can mount mergerfs twice. Once with `direct_io` enabled and one without it.
#### mmap performance is really bad
There [is a bug](https://lkml.org/lkml/2016/3/16/260) in caching which affects overall performance of mmap through FUSE in Linux 4.x kernels. It is fixed in [4.4.10 and 4.5.4](https://lkml.org/lkml/2016/5/11/59).
#### Trashing files occasionally fails
This is the same issue as with Samba. `rename` returns `EXDEV` (in our case that will really only happen with path preserving policies like `epmfs`) and the software doesn't handle the situtation well. This is unfortunately a common failure of software which moves files around. The standard indicates that an implementation `MAY` choose to support non-user home directory trashing of files (which is a `MUST`). The implementation `MAY` also support "top directory trashes" which many probably do.
To create a `$topdir/.Trash` directory as defined in the standard use the [mergerfs-tools](https://github.com/trapexit/mergerfs-tools) tool `mergerfs.mktrash`.
#### Samba: Moving files / directories fails
Workaround: Copy the file/directory and then remove the original rather than move.
This isn't an issue with Samba but some SMB clients. GVFS-fuse v1.20.3 and prior (found in Ubuntu 14.04 among others) failed to handle certain error codes correctly. Particularly **STATUS_NOT_SAME_DEVICE** which comes from the **EXDEV** which is returned by **rename** when the call is crossing mount points. When a program gets an **EXDEV** it needs to explicitly take an alternate action to accomplish it's goal. In the case of **mv** or similar it tries **rename** and on **EXDEV** falls back to a manual copying of data between the two locations and unlinking the source. In these older versions of GVFS-fuse if it received **EXDEV** it would translate that into **EIO**. This would cause **mv** or most any application attempting to move files around on that SMB share to fail with a IO error.
[GVFS-fuse v1.22.0](https://bugzilla.gnome.org/show_bug.cgi?id=734568) and above fixed this issue but a large number of systems use the older release. On Ubuntu the version can be checked by issuing `apt-cache showpkg gvfs-fuse`. Most distros released in 2015 seem to have the updated release and will work fine but older systems may not. Upgrading gvfs-fuse or the distro in general will address the problem.
In Apple's MacOSX 10.9 they replaced Samba (client and server) with their own product. It appears their new client does not handle **EXDEV** either and responds similar to older release of gvfs on Linux.
#### Supplemental user groups
Due to the overhead of [getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs utilizes a cache. This cache is opportunistic and per thread. Each thread will query the supplemental groups for a user when that particular thread needs to change credentials and will keep that data for the lifetime of the thread. This means that if a user is added to a group it may not be picked up without the restart of mergerfs. However, since the high level FUSE API's (at least the standard version) thread pool dynamically grows and shrinks it's possible that over time a thread will be killed and later a new thread with no cache will start and query the new data.
The gid cache uses fixed storage to simplify the design and be compatible with older systems which may not have C++11 compilers. There is enough storage for 256 users' supplemental groups. Each user is allowed upto 32 supplemental groups. Linux >= 2.6.3 allows upto 65535 groups per user but most other *nixs allow far less. NFS allowing only 16. The system does handle overflow gracefully. If the user has more than 32 supplemental groups only the first 32 will be used. If more than 256 users are using the system when an uncached user is found it will evict an existing user's cache at random. So long as there aren't more than 256 active users this should be fine. If either value is too low for your needs you will have to modify `gidcache.hpp` to increase the values. Note that doing so will increase the memory needed by each thread.
#### mergerfs or libfuse crashing
If suddenly the mergerfs mount point disappears and `Transport endpoint is not connected` is returned when attempting to perform actions within the mount directory **and** the version of libfuse (use `mergerfs -v` to find the version) is older than `2.9.4` its likely due to a bug in libfuse. Affected versions of libfuse can be found in Debian Wheezy, Ubuntu Precise and others.
In order to fix this please install newer versions of libfuse. If using a Debian based distro (Debian,Ubuntu,Mint) you can likely just install newer versions of [libfuse](https://packages.debian.org/unstable/libfuse2) and [fuse](https://packages.debian.org/unstable/fuse) from the repo of a newer release.
#### mergerfs appears to be crashing or exiting
There seems to be an issue with Linux version `4.9.0` and above in which an invalid message appears to be transmitted to libfuse (used by mergerfs) causing it to exit. No messages will be printed in any logs as its not a proper crash. Debugging of the issue is still ongoing and can be followed via the [fuse-devel thread](https://sourceforge.net/p/fuse/mailman/message/35662577).
#### mergerfs under heavy load and memory preasure leads to kernel panic
https://lkml.org/lkml/2016/9/14/527
```
[25192.515454] kernel BUG at /build/linux-a2WvEb/linux-4.4.0/mm/workingset.c:346!
[25192.517521] invalid opcode: 0000 [#1] SMP
[25192.519602] Modules linked in: netconsole ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 configfs binfmt_misc veth bridge stp llc nf_conntrack_ipv6 nf_defrag_ipv6 xt_conntrack ip6table_filter ip6_tables xt_multiport iptable_filter ipt_MASQUERADE nf_nat_masquerade_ipv4 xt_comment xt_nat iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack xt_CHECKSUM xt_tcpudp iptable_mangle ip_tables x_tables intel_rapl x86_pkg_temp_thermal intel_powerclamp eeepc_wmi asus_wmi coretemp sparse_keymap kvm_intel ppdev kvm irqbypass mei_me 8250_fintek input_leds serio_raw parport_pc tpm_infineon mei shpchp mac_hid parport lpc_ich autofs4 drbg ansi_cprng dm_crypt algif_skcipher af_alg btrfs raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor raid6_pq libcrc32c raid0 multipath linear raid10 raid1 i915 crct10dif_pclmul crc32_pclmul aesni_intel i2c_algo_bit aes_x86_64 drm_kms_helper lrw gf128mul glue_helper ablk_helper syscopyarea cryptd sysfillrect sysimgblt fb_sys_fops drm ahci r8169 libahci mii wmi fjes video [last unloaded: netconsole]
[25192.540910] CPU: 2 PID: 63 Comm: kswapd0 Not tainted 4.4.0-36-generic #55-Ubuntu
[25192.543411] Hardware name: System manufacturer System Product Name/P8H67-M PRO, BIOS 3904 04/27/2013
[25192.545840] task: ffff88040cae6040 ti: ffff880407488000 task.ti: ffff880407488000
[25192.548277] RIP: 0010:[<ffffffff811ba501>] [<ffffffff811ba501>] shadow_lru_isolate+0x181/0x190
[25192.550706] RSP: 0018:ffff88040748bbe0 EFLAGS: 00010002
[25192.553127] RAX: 0000000000001c81 RBX: ffff8802f91ee928 RCX: ffff8802f91eeb38
[25192.555544] RDX: ffff8802f91ee938 RSI: ffff8802f91ee928 RDI: ffff8804099ba2c0
[25192.557914] RBP: ffff88040748bc08 R08: 000000000001a7b6 R09: 000000000000003f
[25192.560237] R10: 000000000001a750 R11: 0000000000000000 R12: ffff8804099ba2c0
[25192.562512] R13: ffff8803157e9680 R14: ffff8803157e9668 R15: ffff8804099ba2c8
[25192.564724] FS: 0000000000000000(0000) GS:ffff88041f280000(0000) knlGS:0000000000000000
[25192.566990] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[25192.569201] CR2: 00007ffabb690000 CR3: 0000000001e0a000 CR4: 00000000000406e0
[25192.571419] Stack:
[25192.573550] ffff8804099ba2c0 ffff88039e4f86f0 ffff8802f91ee928 ffff8804099ba2c8
[25192.575695] ffff88040748bd08 ffff88040748bc58 ffffffff811b99bf 0000000000000052
[25192.577814] 0000000000000000 ffffffff811ba380 000000000000008a 0000000000000080
[25192.579947] Call Trace:
[25192.582022] [<ffffffff811b99bf>] __list_lru_walk_one.isra.3+0x8f/0x130
[25192.584137] [<ffffffff811ba380>] ? memcg_drain_all_list_lrus+0x190/0x190
[25192.586165] [<ffffffff811b9a83>] list_lru_walk_one+0x23/0x30
[25192.588145] [<ffffffff811ba544>] scan_shadow_nodes+0x34/0x50
[25192.590074] [<ffffffff811a0e9d>] shrink_slab.part.40+0x1ed/0x3d0
[25192.591985] [<ffffffff811a53da>] shrink_zone+0x2ca/0x2e0
[25192.593863] [<ffffffff811a64ce>] kswapd+0x51e/0x990
[25192.595737] [<ffffffff811a5fb0>] ? mem_cgroup_shrink_node_zone+0x1c0/0x1c0
[25192.597613] [<ffffffff810a0808>] kthread+0xd8/0xf0
[25192.599495] [<ffffffff810a0730>] ? kthread_create_on_node+0x1e0/0x1e0
[25192.601335] [<ffffffff8182e34f>] ret_from_fork+0x3f/0x70
[25192.603193] [<ffffffff810a0730>] ? kthread_create_on_node+0x1e0/0x1e0
```
There is a bug in the kernel. A work around appears to be turning off `splice`. Add `no_splice_write,no_splice_move,no_splice_read` to mergerfs' options. Should be placed after `defaults` if it is used since it will turn them on. This however is not guaranteed to work.
# FAQ
*It's mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?*
#### Why use mergerfs over mhddfs?
[mhddfs](https://github.com/trapexit/mhddfs) tries to handle being run as **root** by calling [getuid()](https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319) and if it returns **0** then it will [chown](http://linux.die.net/man/1/chown) the file. Not only is that a race condition but it doesn't handle many other situations. Rather than attempting to simulate POSIX ACL behaviors the proper behavior is to use [seteuid](http://linux.die.net/man/2/seteuid) and [setegid](http://linux.die.net/man/2/setegid), become the user making the original call and perform the action as them. This is how [mergerfs](https://github.com/trapexit/mergerfs) handles things.
mhddfs is no longer maintained and has some known stability and security issues (see below). MergerFS provides a superset of mhddfs' features and should offer the same or maybe better performance.
If you are familiar with POSIX standards you'll know that this behavior poses a problem. **seteuid** and **setegid** affect the whole process and **libfuse** is multithreaded by default. We'd need to lock access to **seteuid** and **setegid** with a mutex so that the several threads aren't stepping on one another and files end up with weird permissions and ownership. This however wouldn't scale well. With lots of calls the contention on that mutex would be extremely high. Thankfully on Linux and OSX we have a better solution.
#### Why use mergerfs over aufs?
OSX has a [non-portable pthread extension](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html) for per-thread user and group impersonation.
While aufs can offer better peak performance mergerfs provides more configurability and is generally easier to use. mergerfs however does not offer the overlay / copy-on-write (COW) features which aufs and overlayfs have.
Linux does not support [pthread_setugid_np](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html) but user and group IDs are a per-thread attribute though documentation on that fact or how to manipulate them is not well distributed. From the **4.00** release of the Linux man-pages project for [setuid](http://man7.org/linux/man-pages/man2/setuid.2.html)
#### Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation / striping?
> At the kernel level, user IDs and group IDs are a per-thread attribute. However, POSIX requires that all threads in a process share the same credentials. The NPTL threading implementation handles the POSIX requirements by providing wrapper functions for the various system calls that change process UIDs and GIDs. These wrapper functions (including the one for setuid()) employ a signal-based technique to ensure that when one thread changes credentials, all of the other threads in the process also change their credentials. For details, see nptl(7).
With simple JBOD / drive concatenation / stripping / RAID0 a single drive failure will result in full pool failure. mergerfs performs a similar behavior without the possibility of catastrophic failure and difficulties in recovery. Drives may fail however all other data will continue to be accessable.
Turns out the setreuid syscalls apply only to the thread. GLIBC hides this away using RT signals to inform all threads to change credentials. Taking after **Samba** mergerfs uses **syscall(SYS_setreuid,...)** to set the callers credentials for that thread only. Jumping back to **root** as necessary should escalated privileges be needed (for instance: to clone paths).
When combined with something like [SnapRaid](http://www.snapraid.it) and/or an offsite backup solution you can have the flexibilty of JBOD without the single point of failure.
For non-Linux systems mergerfs uses a read-write lock and changes credentials only when necessary. If multiple threads are to be user X then only the first one will need to change the processes credentials. So long as the other threads need to be user X they will take a readlock allow multiple threads to share the credentials. Once a request comes in to run as user Y that thread will attempt a write lock and change to Y's credentials when it can. If the ability to give writers priority is supported then that flag will be used so threads trying to change credentials don't starve. This isn't the best solution but should work reasonably well. As new platforms are supported if they offer per thread credentials those APIs will be adopted.
#### Why use mergerfs over ZFS?
MergerFS is not intended to be a replacement for ZFS. MergerFS is intended to provide flexible pooling of arbitrary drives (local or remote), of arbitrary sizes, and arbitrary filesystems. For `write once, read many` usecases such as bulk media storage. Where data integrity and backup is managed in other ways. In that situation ZFS can introduce major maintance and cost burdens as described [here](http://louwrentius.com/the-hidden-cost-of-using-zfs-for-your-home-nas.html).
#### Can drives be written to directly? Outside of mergerfs while pooled?
Yes. It will be represented immediately in the pool as the policies perscribe.
#### Why do I get an "out of space" error even though the system says there's lots of space left?
First make sure you've read the sections above about policies, path preserving, and the **moveonenospc** option.
Remember that mergerfs is simply presenting a logical merging of the contents of the pooled drives. The reported free space is the aggregate space available **not** the contiguous space available. MergerFS does not split files across drives. If the writing of a file fills a drive and **moveonenospc** is disabled it will return an ENOSPC error.
If **moveonenospc** is enabled but there exists no drives with enough space for the file and the data to be written (or the drive happened to fill up as the file was being moved) it will error indicating there isn't enough space.
It is also possible that the filesystem selected has run out of inodes. Use `df -i` to list the total and available inodes per filesystem. In the future it might be worth considering the number of inodes available when making placement decisions in order to minimize this situation.
#### Can mergerfs mounts be exported over NFS?
Yes. Some clients (Kodi) have issues in which the contents of the NFS mount will not be presented but users have found that enabling the `use_ino` option often fixes that problem.
#### Can mergerfs mounts be exported over Samba / SMB?
Yes.
#### How are inodes calculated?
mergerfs-inode = (original-inode | (device-id << 32))
While `ino_t` is 64 bits only a few filesystems use more than 32. Similarly, while `dev_t` is also 64 bits it was traditionally 16 bits. Bitwise or'ing them together should work most of the time. While totally unique inodes are preferred the overhead which would be needed does not seem to outweighted by the benefits.
#### It's mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?
[mhddfs](https://github.com/trapexit/mhddfs) manages running as **root** by calling [getuid()](https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319) and if it returns **0** then it will [chown](http://linux.die.net/man/1/chown) the file. Not only is that a race condition but it doesn't handle many other situations. Rather than attempting to simulate POSIX ACL behavior the proper way to manage this is to use [seteuid](http://linux.die.net/man/2/seteuid) and [setegid](http://linux.die.net/man/2/setegid), in effect becoming the user making the original call, and perform the action as them. This is what mergerfs does.
In Linux setreuid syscalls apply only to the thread. GLIBC hides this away by using realtime signals to inform all threads to change credentials. Taking after **Samba**, mergerfs uses **syscall(SYS_setreuid,...)** to set the callers credentials for that thread only. Jumping back to **root** as necessary should escalated privileges be needed (for instance: to clone paths between drives).
For non-Linux systems mergerfs uses a read-write lock and changes credentials only when necessary. If multiple threads are to be user X then only the first one will need to change the processes credentials. So long as the other threads need to be user X they will take a readlock allowing multiple threads to share the credentials. Once a request comes in to run as user Y that thread will attempt a write lock and change to Y's credentials when it can. If the ability to give writers priority is supported then that flag will be used so threads trying to change credentials don't starve. This isn't the best solution but should work reasonably well assuming there are few users.
# SUPPORT
#### Issues with the software
* github.com: https://github.com/trapexit/mergerfs/issues
* email: trapexit@spawn.link
* twitter: https://twitter.com/_trapexit
#### Support development
* Gratipay: https://gratipay.com/~trapexit
* BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
# LINKS
* http://github.com/trapexit/mergerfs
* http://github.com/trapexit/mergerfs-tools
* http://github.com/trapexit/scorch
* http://github.com/trapexit/backup-and-recovery-howtos
+15 -21
View File
@@ -4,28 +4,22 @@ Source: http://github.com/trapexit/mergerfs
Files: *
Copyright: 2014 Antonio SJ Musumeci <trapexit@spawn.link>
License: MIT
License: ISC
Files: debian/*
Copyright: 2014 Antonio SJ Musumeci <trapexit@spawn.link>
License: MIT
License: ISC
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
n
License: ISC
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.
n
+1 -1
View File
@@ -8,4 +8,4 @@
dh $@
override_dh_auto_install:
$(MAKE) PREFIX=$(CURDIR)/debian/mergerfs/usr install
$(MAKE) DESTDIR=$(CURDIR)/debian/mergerfs PREFIX=/usr install
+1115
View File
File diff suppressed because it is too large Load Diff
+5 -4
View File
@@ -4,7 +4,7 @@ Release: 1%{?dist}
Summary: A FUSE union filesystem
Group: Applications/System
License: MIT
License: ISC
URL: https://github.com/trapexit/mergerfs
Source: mergerfs-%{version}.tar.gz
@@ -14,10 +14,8 @@ BuildRequires: libattr-devel
BuildRequires: fuse-devel
# rpmbuild driven by the Makefile uses git to generate a version number
BuildRequires: git
# pandoc pulls in ~60 packages (87M installed) from EPEL :(
BuildRequires: pandoc
Requires: fuse-libs
Requires: fuse
%prep
%setup -q
@@ -38,6 +36,9 @@ make install PREFIX=%{_prefix} DESTDIR=%{buildroot}
%doc %{_mandir}/*
%changelog
* Mon Jan 25 2016 Antonio SJ Musumeci <trapexit@spawn.link>
- Remove sbin files
* Sat Sep 05 2015 Antonio SJ Musumeci <trapexit@spawn.link>
- Include PREFIX to install
+22 -36
View File
@@ -1,43 +1,28 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <fuse.h>
#include <string>
#include <vector>
#include <unistd.h>
#include <errno.h>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "errno.hpp"
#include "fs_base_access.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -48,20 +33,21 @@ static
int
_access(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const uint64_t minfreespace,
const char *fusepath,
const int mask)
{
int rv;
vector<string> path;
string fullpath;
vector<const string*> basepaths;
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
if(rv == -1)
return -errno;
fs::path::append(path[0],fusepath);
fs::path::make(basepaths[0],fusepath,fullpath);
rv = ::eaccess(path[0].c_str(),mask);
rv = fs::eaccess(fullpath,mask);
return ((rv == -1) ? -errno : 0);
}
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __ACCESS_HPP__
#define __ACCESS_HPP__
namespace mergerfs
{
namespace fuse
@@ -31,3 +26,5 @@ namespace mergerfs
int mask);
}
}
#endif
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __ASSERT_HPP__
#define __ASSERT_HPP__
#define STATIC_ASSERT(cond) assert::StaticAssert< (cond) >()
#define STATIC_ARRAYLENGTH_ASSERT(array,size) STATIC_ASSERT(((sizeof(array)/sizeof(array[0]))==(size)))
@@ -34,3 +29,5 @@ namespace assert
struct StaticAssert<true>
{};
}
#endif
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __BUILDMAP_HPP__
#define __BUILDMAP_HPP__
#include <algorithm>
template<typename K,typename V>
@@ -49,3 +44,5 @@ public:
private:
std::map<K,V> _map;
};
#endif
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __BUILDVECTOR_HPP__
#define __BUILDVECTOR_HPP__
#include <algorithm>
template<typename V, bool SORT = false>
@@ -49,3 +44,5 @@ public:
private:
std::vector<V> _vector;
};
#endif
+11 -19
View File
@@ -1,25 +1,17 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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>
+11 -19
View File
@@ -1,25 +1,17 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __CATEGORY_HPP__
+56 -39
View File
@@ -1,37 +1,31 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <fuse.h>
#include <errno.h>
#include <string>
#include <vector>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "errno.hpp"
#include "fs_base_chmod.hpp"
#include "fs_path.hpp"
#include "rv.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -39,33 +33,56 @@ using mergerfs::Policy;
static
int
_chmod(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const mode_t mode)
_chmod_loop_core(const string *basepath,
const char *fusepath,
const mode_t mode,
const int error)
{
int rv;
string fullpath;
fs::path::make(basepath,fusepath,fullpath);
rv = fs::chmod(fullpath,mode);
return error::calc(rv,error,errno);
}
static
int
_chmod_loop(const vector<const string*> &basepaths,
const char *fusepath,
const mode_t mode)
{
int error;
vector<string> paths;
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1)
return -errno;
error = 0;
for(size_t i = 0, ei = paths.size(); i != ei; i++)
error = -1;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
fs::path::append(paths[i],fusepath);
rv = ::chmod(paths[i].c_str(),mode);
if(rv == -1)
error = errno;
error = _chmod_loop_core(basepaths[i],fusepath,mode,error);
}
return -error;
}
static
int
_chmod(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode)
{
int rv;
vector<const string*> basepaths;
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
if(rv == -1)
return -errno;
return _chmod_loop(basepaths,fusepath,mode);
}
namespace mergerfs
{
namespace fuse
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __CHMOD_HPP__
#define __CHMOD_HPP__
namespace mergerfs
{
namespace fuse
@@ -31,3 +26,5 @@ namespace mergerfs
mode_t mode);
}
}
#endif
+57 -39
View File
@@ -1,72 +1,90 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <fuse.h>
#include <errno.h>
#include <string>
#include <vector>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "errno.hpp"
#include "fs_base_chown.hpp"
#include "fs_path.hpp"
#include "rv.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using mergerfs::Policy;
using mergerfs::Config;
static
int
_chown_loop_core(const string *basepath,
const char *fusepath,
const uid_t uid,
const gid_t gid,
const int error)
{
int rv;
string fullpath;
fs::path::make(basepath,fusepath,fullpath);
rv = fs::lchown(fullpath,uid,gid);
return error::calc(rv,error,errno);
}
static
int
_chown_loop(const vector<const string*> &basepaths,
const char *fusepath,
const uid_t uid,
const gid_t gid)
{
int error;
error = -1;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
error = _chown_loop_core(basepaths[i],fusepath,uid,gid,error);
}
return -error;
}
static
int
_chown(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const uint64_t minfreespace,
const char *fusepath,
const uid_t uid,
const gid_t gid)
{
int rv;
int error;
vector<string> paths;
vector<const string*> basepaths;
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
if(rv == -1)
return -errno;
error = 0;
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
fs::path::append(paths[i],fusepath);
rv = ::lchown(paths[i].c_str(),uid,gid);
if(rv == -1)
error = errno;
}
return -error;
return _chown_loop(basepaths,fusepath,uid,gid);
}
namespace mergerfs
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __CHOWN_HPP__
#define __CHOWN_HPP__
namespace mergerfs
{
namespace fuse
@@ -32,3 +27,5 @@ namespace mergerfs
gid_t gid);
}
}
#endif
-54
View File
@@ -1,54 +0,0 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "fs.hpp"
namespace clonepath
{
static
void
print_usage_and__exit(void)
{
std::cerr << "usage: clonepath "
<< "<sourcedir> <destdir> <relativepath>"
<< std::endl;
_exit(1);
}
int
main(const int argc,
char * const argv[])
{
if(argc != 4)
print_usage_and__exit();
return fs::clonepath(argv[1],
argv[2],
argv[3]);
}
}
-30
View File
@@ -1,30 +0,0 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
namespace clonepath
{
int
main(const int argc,
char * const *argv);
}
+23 -27
View File
@@ -1,25 +1,17 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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>
@@ -27,12 +19,13 @@
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include "config.hpp"
#include "rwlock.hpp"
#include "errno.hpp"
#include "fs.hpp"
#include "rwlock.hpp"
#define MINFREESPACE_DEFAULT (4294967295ULL)
#define POLICYINIT(X) X(policies[FuseFunc::Enum::X])
using std::string;
@@ -44,7 +37,10 @@ namespace mergerfs
: destmount(),
srcmounts(),
srcmountslock(),
minfreespace(UINT32_MAX),
minfreespace(MINFREESPACE_DEFAULT),
moveonenospc(false),
direct_io(false),
dropcacheonclose(false),
POLICYINIT(access),
POLICYINIT(chmod),
POLICYINIT(chown),
@@ -61,11 +57,11 @@ namespace mergerfs
POLICYINIT(rename),
POLICYINIT(rmdir),
POLICYINIT(setxattr),
POLICYINIT(symlink),
POLICYINIT(truncate),
POLICYINIT(unlink),
POLICYINIT(utimens),
controlfile("/.mergerfs")
POLICYINIT(symlink),
POLICYINIT(truncate),
POLICYINIT(unlink),
POLICYINIT(utimens),
controlfile("/.mergerfs")
{
pthread_rwlock_init(&srcmountslock,NULL);
+15 -20
View File
@@ -1,25 +1,17 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __CONFIG_HPP__
@@ -53,7 +45,10 @@ namespace mergerfs
std::string destmount;
std::vector<std::string> srcmounts;
mutable pthread_rwlock_t srcmountslock;
size_t minfreespace;
uint64_t minfreespace;
bool moveonenospc;
bool direct_io;
bool dropcacheonclose;
public:
const Policy *policies[FuseFunc::Enum::END];
+87 -55
View File
@@ -1,88 +1,119 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <fuse.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string>
#include <vector>
#include "config.hpp"
#include "ugid.hpp"
#include "fs.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_acl.hpp"
#include "fs_base_open.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using mergerfs::Policy;
using namespace mergerfs;
static
inline
int
_create_core(const string &fullpath,
mode_t mode,
const mode_t umask,
const int flags)
{
if(!fs::acl::dir_has_defaults(fullpath))
mode &= ~umask;
return fs::open(fullpath,flags,mode);
}
static
int
_create_core(const string &existingpath,
const string &createpath,
const char *fusepath,
const char *fusedirpath,
const mode_t mode,
const mode_t umask,
const int flags,
uint64_t &fh)
{
int rv;
string fullpath;
if(createpath != existingpath)
{
const ugid::SetRootGuard ugidGuard;
rv = fs::clonepath(existingpath,createpath,fusedirpath);
if(rv == -1)
return -errno;
}
fs::path::make(&createpath,fusepath,fullpath);
rv = _create_core(fullpath,mode,umask,flags);
if(rv == -1)
return -errno;
fh = reinterpret_cast<uint64_t>(new FileInfo(rv));
return 0;
}
static
int
_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode,
const mode_t umask,
const int flags,
uint64_t &fh)
{
int fd;
int rv;
string dirname;
vector<string> createpath;
vector<string> existingpath;
string fullpath;
string fusedirpath;
const char *fusedirpathcstr;
vector<const string*> createpaths;
vector<const string*> existingpaths;
dirname = fs::path::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
fusedirpath = fusepath;
fs::path::dirname(fusedirpath);
fusedirpathcstr = fusedirpath.c_str();
rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths);
if(rv == -1)
return -errno;
rv = createFunc(srcmounts,dirname,minfreespace,createpath);
rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths);
if(rv == -1)
return -errno;
if(createpath[0] != existingpath[0])
{
const ugid::SetRootGuard ugidGuard;
fs::clonepath(existingpath[0],createpath[0],dirname);
}
fs::path::append(createpath[0],fusepath);
fd = ::open(createpath[0].c_str(),flags,mode);
if(fd == -1)
return -errno;
fh = fd;
return 0;
return _create_core(*existingpaths[0],*createpaths[0],
fusepath,fusedirpathcstr,
mode,umask,flags,fh);
}
namespace mergerfs
@@ -92,7 +123,7 @@ namespace mergerfs
int
create(const char *fusepath,
mode_t mode,
fuse_file_info *fileinfo)
fuse_file_info *ffi)
{
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
@@ -104,9 +135,10 @@ namespace mergerfs
config.srcmounts,
config.minfreespace,
fusepath,
(mode & ~fc->umask),
fileinfo->flags,
fileinfo->fh);
mode,
fc->umask,
ffi->flags,
ffi->fh);
}
}
}
+19 -21
View File
@@ -1,30 +1,26 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <sys/types.h>
#ifndef __CREATE_HPP__
#define __CREATE_HPP__
#include <fuse.h>
#include <sys/types.h>
namespace mergerfs
{
namespace fuse
@@ -32,6 +28,8 @@ namespace mergerfs
int
create(const char *fusepath,
mode_t mode,
fuse_file_info *fileinfo);
fuse_file_info *ffi);
}
}
#endif
+11 -19
View File
@@ -1,25 +1,17 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
namespace mergerfs
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __DESTROY_HPP__
#define __DESTROY_HPP__
namespace mergerfs
{
namespace fuse
@@ -30,3 +25,5 @@ namespace mergerfs
destroy(void *);
}
}
#endif
+34
View File
@@ -0,0 +1,34 @@
/*
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.
*/
#ifndef __ERRNO_HPP__
#define __ERRNO_HPP__
#include <errno.h>
#if defined(ENODATA) && !defined(ENOATTR)
#define ENOATTR ENODATA
#endif
#if defined(ENOATTR) && !defined(ENODATA)
#define ENODATA ENOATTR
#endif
#if !defined(ENOATTR) && !defined(ENODATA)
#error "Neither ENOATTR or ENODATA defined: please contact mergerfs author with platform information"
#endif
#endif
+18 -42
View File
@@ -1,37 +1,26 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#if FALLOCATE
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <fuse.h>
#include <errno.h>
#include <fcntl.h>
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_fallocate.hpp"
static
int
@@ -42,22 +31,7 @@ _fallocate(const int fd,
{
int rv;
#ifdef _GNU_SOURCE
rv = ::fallocate(fd,mode,offset,len);
#elif defined _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
if(mode)
{
rv = -1;
errno = EOPNOTSUPP;
}
else
{
rv = ::posix_fallocate(fd,offset,len);
}
#else
rv = -1;
errno = EOPNOTSUPP;
#endif
rv = fs::fallocate(fd,mode,offset,len);
return ((rv == -1) ? -errno : 0);
}
@@ -73,7 +47,9 @@ namespace mergerfs
off_t len,
fuse_file_info *ffi)
{
return _fallocate(ffi->fh,
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _fallocate(fi->fd,
mode,
offset,
len);
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __FALLOCATE_HPP__
#define __FALLOCATE_HPP__
namespace mergerfs
{
namespace fuse
@@ -34,3 +29,5 @@ namespace mergerfs
fuse_file_info *fi);
}
}
#endif
+24 -27
View File
@@ -1,33 +1,25 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <fuse.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_stat.hpp"
#include "fs_inode.hpp"
static
int
@@ -36,9 +28,13 @@ _fgetattr(const int fd,
{
int rv;
rv = ::fstat(fd,&st);
rv = fs::fstat(fd,st);
if(rv == -1)
return -errno;
return ((rv == -1) ? -errno : 0);
fs::inode::recompute(st);
return 0;
}
namespace mergerfs
@@ -50,8 +46,9 @@ namespace mergerfs
struct stat *st,
fuse_file_info *ffi)
{
return _fgetattr(ffi->fh,
*st);
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _fgetattr(fi->fd,*st);
}
}
}
+17 -20
View File
@@ -1,29 +1,24 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <sys/types.h>
#ifndef __FGETATTR_HPP__
#define __FGETATTR_HPP__
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
namespace mergerfs
@@ -36,3 +31,5 @@ namespace mergerfs
fuse_file_info *fileinfo);
}
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/*
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.
*/
#ifndef __FILEINFO_HPP__
#define __FILEINFO_HPP__
class FileInfo
{
public:
FileInfo(int _fd) :
fd(_fd)
{
}
public:
int fd;
};
#endif
+49
View File
@@ -0,0 +1,49 @@
/*
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 <fuse.h>
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_flock.hpp"
static
int
_flock(const int fd,
const int operation)
{
int rv;
rv = fs::flock(fd,operation);
return ((rv == -1) ? -errno : 0);
}
namespace mergerfs
{
namespace fuse
{
int
flock(const char *fusepath,
fuse_file_info *ffi,
int op)
{
FileInfo* fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _flock(fi->fd,op);
}
}
}
+31
View File
@@ -0,0 +1,31 @@
/*
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.
*/
#ifndef __FLOCK_HPP__
#define __FLOCK_HPP__
namespace mergerfs
{
namespace fuse
{
int
flock(const char *fusepath,
fuse_file_info *ffi,
int op);
}
}
#endif
+20 -24
View File
@@ -1,31 +1,25 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <fuse.h>
#include <unistd.h>
#include <errno.h>
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_close.hpp"
#include "fs_base_dup.hpp"
static
int
@@ -33,11 +27,11 @@ _flush(const int fd)
{
int rv;
rv = dup(fd);
rv = fs::dup(fd);
if(rv == -1)
errno = EIO;
else
rv = close(rv);
rv = fs::close(rv);
return ((rv == -1) ? -errno : 0);
}
@@ -50,7 +44,9 @@ namespace mergerfs
flush(const char *fusepath,
fuse_file_info *ffi)
{
return _flush(ffi->fh);
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _flush(fi->fd);
}
}
}
+16 -19
View File
@@ -1,27 +1,22 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __FLUSH_HPP__
#define __FLUSH_HPP__
namespace mergerfs
{
namespace fuse
@@ -31,3 +26,5 @@ namespace mergerfs
fuse_file_info *fi);
}
}
#endif
+170 -446
View File
@@ -1,496 +1,173 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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 <map>
#include <sstream>
#include <cstdlib>
#include <iterator>
#include <stdlib.h>
#include <limits.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>
#include <glob.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include "fs.hpp"
#include "xattr.hpp"
#include "errno.hpp"
#include "fs_attr.hpp"
#include "fs_base_realpath.hpp"
#include "fs_base_stat.hpp"
#include "fs_base_statvfs.hpp"
#include "fs_path.hpp"
#include "fs_xattr.hpp"
#include "statvfs_util.hpp"
#include "str.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
using std::map;
using std::istringstream;
template <typename Iter>
Iter
random_element(Iter begin,
Iter end)
{
const unsigned long n = std::distance(begin, end);
std::advance(begin, (std::rand() % n));
return begin;
}
namespace fs
{
namespace path
bool
exists(const string &path,
struct stat &st)
{
string
dirname(const string &path)
{
string parent = path;
string::reverse_iterator i;
string::reverse_iterator bi;
int rv;
bi = parent.rend();
i = parent.rbegin();
while(*i == '/' && i != bi)
i++;
rv = fs::lstat(path,st);
while(*i != '/' && i != bi)
i++;
return LSTAT_SUCCEEDED(rv);
}
while(*i == '/' && i != bi)
i++;
bool
exists(const string &path)
{
struct stat st;
parent.erase(i.base(),parent.end());
return exists(path,st);
}
return parent;
}
bool
info(const string &path,
bool &readonly,
uint64_t &spaceavail,
uint64_t &spaceused)
{
int rv;
struct statvfs st;
string
basename(const string &path)
{
return path.substr(path.find_last_of('/')+1);
}
rv = fs::statvfs(path,st);
if(STATVFS_SUCCEEDED(rv))
{
readonly = StatVFS::readonly(st);
spaceavail = StatVFS::spaceavail(st);
spaceused = StatVFS::spaceused(st);
}
bool
is_empty(const string &path)
{
DIR *dir;
struct dirent *de;
return STATVFS_SUCCEEDED(rv);
}
dir = ::opendir(path.c_str());
if(!dir)
return false;
bool
readonly(const string &path)
{
int rv;
struct statvfs st;
while((de = ::readdir(dir)))
{
const char *d_name = de->d_name;
rv = fs::statvfs(path,st);
if(d_name[0] == '.' &&
((d_name[1] == '\0') ||
(d_name[1] == '.' && d_name[2] == '\0')))
continue;
return (STATVFS_SUCCEEDED(rv) && StatVFS::readonly(st));
}
::closedir(dir);
bool
spaceavail(const string &path,
uint64_t &spaceavail)
{
int rv;
struct statvfs st;
return false;
}
rv = fs::statvfs(path,st);
if(STATVFS_SUCCEEDED(rv))
spaceavail = StatVFS::spaceavail(st);
::closedir(dir);
return STATVFS_SUCCEEDED(rv);
}
return true;
}
bool
spaceused(const string &path,
uint64_t &spaceused)
{
int rv;
struct statvfs st;
bool
exists(const vector<string> &paths,
const string &fusepath)
{
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
int rv;
string path;
struct stat st;
rv = fs::statvfs(path,st);
if(STATVFS_SUCCEEDED(rv))
spaceused = StatVFS::spaceused(st);
fs::path::make(paths[i],fusepath,path);
rv = ::lstat(path.c_str(),&st);
if(rv == 0)
return true;
}
return false;
}
return STATVFS_SUCCEEDED(rv);
}
void
findallfiles(const vector<string> &srcmounts,
const string &fusepath,
const char *fusepath,
vector<string> &paths)
{
string fullpath;
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
int rv;
string fullpath;
struct stat st;
fs::path::make(&srcmounts[i],fusepath,fullpath);
fs::path::make(srcmounts[i],fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
paths.push_back(fullpath);
paths.push_back(fullpath);
}
}
int
listxattr(const string &path,
vector<char> &attrs)
{
#ifndef WITHOUT_XATTR
int rv;
int size;
rv = -1;
errno = ERANGE;
while(rv == -1 && errno == ERANGE)
{
size = ::listxattr(path.c_str(),NULL,0);
attrs.resize(size);
rv = ::listxattr(path.c_str(),&attrs[0],size);
}
return rv;
#else
errno = ENOTSUP;
return -1;
#endif
}
int
listxattr(const string &path,
vector<string> &attrvector)
findonfs(const vector<string> &srcmounts,
const char *fusepath,
const int fd,
string &basepath)
{
int rv;
vector<char> attrs;
rv = listxattr(path,attrs);
if(rv != -1)
{
string tmp(attrs.begin(),attrs.end());
str::split(attrvector,tmp,'\0');
}
return rv;
}
int
listxattr(const string &path,
string &attrstr)
{
int rv;
vector<char> attrs;
rv = listxattr(path,attrs);
if(rv != -1)
attrstr = string(attrs.begin(),attrs.end());
return rv;
}
int
getxattr(const string &path,
const string &attr,
vector<char> &value)
{
#ifndef WITHOUT_XATTR
int rv;
int size;
rv = -1;
errno = ERANGE;
while(rv == -1 && errno == ERANGE)
{
size = ::getxattr(path.c_str(),attr.c_str(),NULL,0);
value.resize(size);
rv = ::getxattr(path.c_str(),attr.c_str(),&value[0],size);
}
return rv;
#else
errno = ENOTSUP;
return -1;
#endif
}
int
getxattr(const string &path,
const string &attr,
string &value)
{
int rv;
vector<char> tmpvalue;
rv = getxattr(path,attr,tmpvalue);
if(rv != -1)
value = string(tmpvalue.begin(),tmpvalue.end());
return rv;
}
int
getxattrs(const string &path,
map<string,string> &attrs)
{
int rv;
string attrstr;
rv = listxattr(path,attrstr);
if(rv == -1)
return -1;
{
string key;
istringstream ss(attrstr);
while(getline(ss,key,'\0'))
{
string value;
rv = getxattr(path,key,value);
if(rv != -1)
attrs[key] = value;
}
}
return 0;
}
int
setxattr(const string &path,
const string &key,
const string &value,
const int flags)
{
#ifndef WITHOUT_XATTR
return ::setxattr(path.c_str(),
key.c_str(),
value.data(),
value.size(),
flags);
#else
errno = ENOTSUP;
return -1;
#endif
}
int
setxattr(const int fd,
const string &key,
const string &value,
const int flags)
{
#ifndef WITHOUT_XATTR
return ::fsetxattr(fd,
key.c_str(),
value.data(),
value.size(),
flags);
#else
errno = ENOTSUP;
return -1;
#endif
}
int
setxattrs(const string &path,
const map<string,string> &attrs)
{
int fd;
fd = ::open(path.c_str(),O_RDONLY|O_NONBLOCK);
if(fd == -1)
return -1;
for(map<string,string>::const_iterator
i = attrs.begin(), ei = attrs.end(); i != ei; ++i)
{
setxattr(fd,i->first,i->second,0);
}
return ::close(fd);
}
int
copyxattrs(const string &from,
const string &to)
{
int rv;
map<string,string> attrs;
rv = getxattrs(from,attrs);
if(rv == -1)
return -1;
return setxattrs(to,attrs);
}
static
int
get_fs_ioc_flags(const string &file,
int &flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
static
int
set_fs_ioc_flags(const string &file,
const int flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
int
copyattr(const string &from,
const string &to)
{
int rv;
int flags;
rv = get_fs_ioc_flags(from,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(to,flags);
}
static
bool
ignorable_error(const int err)
{
switch(err)
{
case ENOTTY:
case ENOTSUP:
#if ENOTSUP != EOPNOTSUPP
case EOPNOTSUPP:
#endif
return true;
}
return false;
}
int
clonepath(const string &fromsrc,
const string &tosrc,
const string &relative)
{
int rv;
dev_t dev;
string fullpath;
struct stat st;
string topath;
string frompath;
string dirname;
dirname = fs::path::dirname(relative);
if(!dirname.empty())
rv = fs::fstat(fd,st);
if(FSTAT_FAILED(rv))
return -1;
dev = st.st_dev;
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
{
rv = clonepath(fromsrc,tosrc,dirname);
if(rv == -1)
return -1;
fs::path::make(&srcmounts[i],fusepath,fullpath);
rv = fs::lstat(fullpath,st);
if(FSTAT_FAILED(rv))
continue;
if(st.st_dev != dev)
continue;
basepath = srcmounts[i];
return 0;
}
fs::path::make(fromsrc,relative,frompath);
rv = ::stat(frompath.c_str(),&st);
if(rv == -1)
return -1;
else if(!S_ISDIR(st.st_mode))
return (errno = ENOTDIR,-1);
fs::path::make(tosrc,relative,topath);
rv = ::mkdir(topath.c_str(),st.st_mode);
if(rv == -1)
{
if(errno != EEXIST)
return -1;
rv = ::chmod(topath.c_str(),st.st_mode);
if(rv == -1)
return -1;
}
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
if(rv == -1)
return -1;
// It may not support it... it's fine...
rv = copyattr(frompath,topath);
if(rv == -1 && !ignorable_error(errno))
return -1;
rv = copyxattrs(frompath,topath);
if(rv == -1 && !ignorable_error(errno))
return -1;
return 0;
return (errno=ENOENT,-1);
}
void
@@ -498,14 +175,19 @@ namespace fs
vector<string> &strs)
{
int flags;
glob_t gbuf;
size_t veclen;
glob_t gbuf = {0};
veclen = patterns.size();
if(veclen == 0)
return;
flags = 0;
for(size_t i = 0; i < patterns.size(); i++)
{
glob(patterns[i].c_str(),flags,NULL,&gbuf);
flags = GLOB_APPEND;
}
glob(patterns[0].c_str(),flags,NULL,&gbuf);
flags = GLOB_APPEND;
for(size_t i = 1; i < veclen; i++)
glob(patterns[i].c_str(),flags,NULL,&gbuf);
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
strs.push_back(gbuf.gl_pathv[i]);
@@ -517,15 +199,57 @@ namespace fs
realpathize(vector<string> &strs)
{
char *rv;
char buf[PATH_MAX];
for(size_t i = 0; i < strs.size(); i++)
{
rv = ::realpath(strs[i].c_str(),buf);
rv = fs::realpath(strs[i]);
if(rv == NULL)
continue;
strs[i] = buf;
strs[i] = rv;
::free(rv);
}
}
int
getfl(const int fd)
{
return ::fcntl(fd,F_GETFL,0);
}
int
mfs(const vector<string> &basepaths,
const uint64_t minfreespace,
string &path)
{
fsblkcnt_t mfs;
const string *mfsbasepath;
mfs = 0;
mfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
uint64_t spaceavail;
const string &basepath = basepaths[i];
if(!fs::spaceavail(basepath,spaceavail))
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;
}
};
+35 -96
View File
@@ -1,25 +1,17 @@
/*
The MIT License (MIT)
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Copyright (c) 2014 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.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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.
*/
#ifndef __FS_HPP__
@@ -27,103 +19,50 @@
#include <string>
#include <vector>
#include <map>
#include "path.hpp"
#include <stdint.h>
namespace fs
{
using std::size_t;
using std::string;
using std::vector;
using std::map;
namespace path
{
string dirname(const string &path);
string basename(const string &path);
bool exists(const string &path,
struct stat &st);
bool exists(const string &path);
bool is_empty(const string &path);
bool info(const string &path,
bool &readonly,
uint64_t &spaceavail,
uint64_t &spaceused);
bool exists(vector<string>::const_iterator begin,
vector<string>::const_iterator end,
const string &fusepath);
bool exists(const vector<string> &srcmounts,
const string &fusepath);
bool readonly(const string &path);
inline
string
make(const string &base,
const string &suffix)
{
return base + suffix;
}
bool spaceavail(const string &path,
uint64_t &spaceavail);
inline
void
make(const string &base,
const string &suffix,
string &output)
{
output = base + suffix;
}
inline
void
append(string &base,
const string &suffix)
{
base += suffix;
}
}
bool spaceused(const string &path,
uint64_t &spaceavail);
void findallfiles(const vector<string> &srcmounts,
const string &fusepath,
const char *fusepath,
vector<string> &paths);
int clonepath(const string &srcfrom,
const string &srcto,
const string &relative);
int listxattr(const string &path,
vector<char> &attrs);
int listxattr(const string &path,
string &attrs);
int listxattr(const string &path,
vector<string> &attrs);
int getxattr(const string &path,
const string &attr,
vector<char> &value);
int getxattr(const string &path,
const string &attr,
string &value);
int getxattrs(const string &path,
map<string,string> &attrs);
int setxattr(const string &path,
const string &key,
const string &value,
const int flags);
int setxattr(const int fd,
const string &key,
const string &value,
const int flags);
int setxattrs(const string &path,
const map<string,string> &attrs);
int copyxattrs(const string &from,
const string &to);
int copyattr(const string &from,
const string &to);
int findonfs(const vector<string> &srcmounts,
const char *fusepath,
const int fd,
string &basepath);
void glob(const vector<string> &patterns,
vector<string> &strs);
void realpathize(vector<string> &strs);
int getfl(const int fd);
int mfs(const vector<string> &srcs,
const uint64_t minfreespace,
string &path);
};
#endif // __FS_HPP__
+43
View File
@@ -0,0 +1,43 @@
/*
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.
*/
#include <string>
#include "fs_base_getxattr.hpp"
#include "fs_path.hpp"
const char POSIX_ACL_DEFAULT_XATTR[] = "system.posix_acl_default";
namespace fs
{
namespace acl
{
bool
dir_has_defaults(const std::string &fullpath)
{
int rv;
std::string dirpath = fullpath;
fs::path::dirname(dirpath);
rv = fs::lgetxattr(dirpath,POSIX_ACL_DEFAULT_XATTR,NULL,0);
return (rv != -1);
}
}
}
+28
View File
@@ -0,0 +1,28 @@
/*
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.
*/
#include <string>
namespace fs
{
namespace acl
{
bool
dir_has_defaults(const std::string &fullpath);
}
}
+21
View File
@@ -0,0 +1,21 @@
/*
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.
*/
#ifdef __linux__
# include "fs_attr_linux.icpp"
#else
# include "fs_attr_unsupported.icpp"
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
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.
*/
#ifndef __FS_ATTR_HPP__
#define __FS_ATTR_HPP__
#include <string>
namespace fs
{
namespace attr
{
using std::string;
int copy(const int fdin,
const int fdout);
int copy(const string &from,
const string &to);
}
}
#endif // __FS_ATTR_HPP__
+127
View File
@@ -0,0 +1,127 @@
/*
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 <linux/fs.h>
#include <string>
#include "errno.hpp"
#include "fs_base_close.hpp"
#include "fs_base_open.hpp"
#include "fs_base_ioctl.hpp"
using std::string;
namespace fs
{
namespace attr
{
static
int
get_fs_ioc_flags(const int fd,
int &flags)
{
return fs::ioctl(fd,FS_IOC_GETFLAGS,(void*)&flags);
}
static
int
get_fs_ioc_flags(const string &file,
int &flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = fs::open(file,openflags);
if(fd == -1)
return -1;
rv = get_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
fs::close(fd);
errno = error;
return -1;
}
return fs::close(fd);
}
static
int
set_fs_ioc_flags(const int fd,
const int flags)
{
return fs::ioctl(fd,FS_IOC_SETFLAGS,(void*)&flags);
}
static
int
set_fs_ioc_flags(const string &file,
const int flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = fs::open(file,openflags);
if(fd == -1)
return -1;
rv = set_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
fs::close(fd);
errno = error;
return -1;
}
return fs::close(fd);
}
int
copy(const int fdin,
const int fdout)
{
int rv;
int flags;
rv = get_fs_ioc_flags(fdin,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(fdout,flags);
}
int
copy(const string &from,
const string &to)
{
int rv;
int flags;
rv = get_fs_ioc_flags(from,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(to,flags);
}
}
}
+39
View File
@@ -0,0 +1,39 @@
/*
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 "errno.hpp"
namespace fs
{
namespace attr
{
int
copy(const int fdin,
const int fdout)
{
return ENOTSUP;
}
int
copy(const std::string &from,
const std::string &to)
{
return ENOTSUP;
}
}
}
+60
View File
@@ -0,0 +1,60 @@
/*
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.
*/
#ifndef __FS_BASE_ACCESS_HPP__
#define __FS_BASE_ACCESS_HPP__
#include <string>
#include <fcntl.h>
#include <unistd.h>
namespace fs
{
static
inline
int
access(const int dirfd,
const std::string &path,
const int mode,
const int flags)
{
return ::faccessat(dirfd,path.c_str(),mode,flags);
}
static
inline
int
access(const std::string &path,
const int mode,
const int flags)
{
return fs::access(AT_FDCWD,path,mode,flags);
}
static
inline
int
eaccess(const std::string &path,
const int mode)
{
return fs::access(path,mode,AT_EACCESS);
}
}
#endif
+110
View File
@@ -0,0 +1,110 @@
/*
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.
*/
#ifndef __FS_BASE_CHMOD_HPP__
#define __FS_BASE_CHMOD_HPP__
#include <sys/stat.h>
#include "fs_base_stat.hpp"
#define MODE_BITS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
namespace fs
{
static
inline
int
chmod(const std::string &path,
const mode_t mode)
{
return ::chmod(path.c_str(),mode);
}
static
inline
int
fchmod(const int fd,
const mode_t mode)
{
return ::fchmod(fd,mode);
}
static
inline
int
fchmod(const int fd,
const struct stat &st)
{
return ::fchmod(fd,st.st_mode);
}
static
inline
int
chmod_check_on_error(const std::string &path,
const mode_t mode)
{
int rv;
rv = fs::chmod(path,mode);
if(rv == -1)
{
int error;
struct stat st;
error = errno;
rv = fs::stat(path,st);
if(rv == -1)
return -1;
if((st.st_mode & MODE_BITS) != (mode & MODE_BITS))
return (errno=error,-1);
}
return 0;
}
static
inline
int
fchmod_check_on_error(const int fd,
const struct stat &st)
{
int rv;
rv = fs::fchmod(fd,st);
if(rv == -1)
{
int error;
struct stat tmpst;
error = errno;
rv = fs::fstat(fd,tmpst);
if(rv == -1)
return -1;
if((st.st_mode & MODE_BITS) != (tmpst.st_mode & MODE_BITS))
return (errno=error,-1);
}
return 0;
}
}
#endif
+144
View File
@@ -0,0 +1,144 @@
/*
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.
*/
#ifndef __FS_BASE_CHOWN_HPP__
#define __FS_BASE_CHOWN_HPP__
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "fs_base_stat.hpp"
namespace fs
{
static
inline
int
chown(const std::string &path,
const uid_t uid,
const gid_t gid)
{
return ::chown(path.c_str(),uid,gid);
}
static
inline
int
chown(const std::string &path,
const struct stat &st)
{
return fs::chown(path,st.st_uid,st.st_gid);
}
static
inline
int
lchown(const std::string &path,
const uid_t uid,
const gid_t gid)
{
return ::lchown(path.c_str(),uid,gid);
}
static
inline
int
lchown(const std::string &path,
const struct stat &st)
{
return fs::lchown(path,st.st_uid,st.st_gid);
}
static
inline
int
fchown(const int fd,
const uid_t uid,
const gid_t gid)
{
return ::fchown(fd,uid,gid);
}
static
inline
int
fchown(const int fd,
const struct stat &st)
{
return fs::fchown(fd,st.st_uid,st.st_gid);
}
static
inline
int
lchown_check_on_error(const std::string &path,
const struct stat &st)
{
int rv;
rv = fs::lchown(path,st);
if(rv == -1)
{
int error;
struct stat tmpst;
error = errno;
rv = fs::lstat(path,tmpst);
if(rv == -1)
return -1;
if((st.st_uid != tmpst.st_uid) ||
(st.st_gid != tmpst.st_gid))
return (errno=error,-1);
}
return 0;
}
static
inline
int
fchown_check_on_error(const int fd,
const struct stat &st)
{
int rv;
rv = fs::fchown(fd,st);
if(rv == -1)
{
int error;
struct stat tmpst;
error = errno;
rv = fs::fstat(fd,tmpst);
if(rv == -1)
return -1;
if((st.st_uid != tmpst.st_uid) ||
(st.st_gid != tmpst.st_gid))
return (errno=error,-1);
}
return 0;
}
}
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
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.
*/
#ifndef __FS_BASE_CLOSE_HPP__
#define __FS_BASE_CLOSE_HPP__
#include <unistd.h>
namespace fs
{
static
inline
int
close(const int fd)
{
return ::close(fd);
}
}
#endif
+36
View File
@@ -0,0 +1,36 @@
/*
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.
*/
#ifndef __FS_BASE_CLOSEDIR_HPP__
#define __FS_BASE_CLOSEDIR_HPP__
#include <dirent.h>
#include <sys/types.h>
namespace fs
{
static
inline
int
closedir(DIR *dirp)
{
return ::closedir(dirp);
}
}
#endif
+36
View File
@@ -0,0 +1,36 @@
/*
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.
*/
#ifndef __FS_DIRFD_HPP__
#define __FS_DIRFD_HPP__
#include <dirent.h>
#include <sys/types.h>
namespace fs
{
static
inline
int
dirfd(DIR *dirp)
{
return ::dirfd(dirp);
}
}
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
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.
*/
#ifndef __FS_BASE_DUP_HPP__
#define __FS_BASE_DUP_HPP__
#include <unistd.h>
namespace fs
{
static
inline
int
dup(const int fd)
{
return ::dup(fd);
}
}
#endif
+36
View File
@@ -0,0 +1,36 @@
/*
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.
*/
#ifndef __FS_BASE_FLOCK_HPP__
#define __FS_BASE_FLOCK_HPP__
#include <sys/file.h>
namespace fs
{
static
inline
int
flock(const int fd,
const int operation)
{
return ::flock(fd,operation);
}
}
#endif
+49
View File
@@ -0,0 +1,49 @@
/*
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.
*/
#ifndef __FS_BASE_FSYNC_HPP__
#define __FS_BASE_FSYNC_HPP__
#include <unistd.h>
#include "errno.hpp"
namespace fs
{
static
inline
int
fsync(const int fd)
{
return ::fsync(fd);
}
static
inline
int
fdatasync(const int fd)
{
#if _POSIX_SYNCHRONIZED_IO > 0
return ::fdatasync(fd);
#else
return (errno=ENOSYS,-1);
#endif
}
}
#endif
+37
View File
@@ -0,0 +1,37 @@
/*
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.
*/
#ifndef __FS_BASE_FTRUNCATE_HPP__
#define __FS_BASE_FTRUNCATE_HPP__
#include <sys/types.h>
#include <unistd.h>
namespace fs
{
static
inline
int
ftruncate(const int fd,
const off_t size)
{
return ::ftruncate(fd,size);
}
}
#endif
+45
View File
@@ -0,0 +1,45 @@
/*
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.
*/
#ifndef __FS_BASE_GETXATTR_HPP__
#define __FS_BASE_GETXATTR_HPP__
#include <sys/types.h>
#include "errno.hpp"
#include "xattr.hpp"
namespace fs
{
static
inline
int
lgetxattr(const std::string &path,
const char *attrname,
void *value,
const size_t size)
{
#ifndef WITHOUT_XATTR
return ::lgetxattr(path.c_str(),attrname,value,size);
#else
return (errno=ENOTSUP,-1);
#endif
}
}
#endif
+37
View File
@@ -0,0 +1,37 @@
/*
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.
*/
#ifndef __FS_BASE_IOCTL_HPP__
#define __FS_BASE_IOCTL_HPP__
#include <sys/ioctl.h>
namespace fs
{
static
inline
int
ioctl(const int fd,
const int request,
void *data)
{
return ::ioctl(fd,request,data);
}
}
#endif
+38
View File
@@ -0,0 +1,38 @@
/*
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.
*/
#ifndef __FS_BASE_LINK_HPP__
#define __FS_BASE_LINK_HPP__
#include <string>
#include <unistd.h>
namespace fs
{
static
inline
int
link(const std::string &oldpath,
const std::string &newpath)
{
return ::link(oldpath.c_str(),newpath.c_str());
}
}
#endif
+44
View File
@@ -0,0 +1,44 @@
/*
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.
*/
#ifndef __FS_BASE_LISTXATTR_HPP__
#define __FS_BASE_LISTXATTR_HPP__
#include <sys/types.h>
#include "errno.hpp"
#include "xattr.hpp"
namespace fs
{
static
inline
int
llistxattr(const std::string &path,
char *list,
const size_t size)
{
#ifndef WITHOUT_XATTR
return ::llistxattr(path.c_str(),list,size);
#else
return (errno=ENOTSUP,-1);
#endif
}
}
#endif
+38
View File
@@ -0,0 +1,38 @@
/*
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.
*/
#ifndef __FS_BASE_LSEEK_HPP__
#define __FS_BASE_LSEEK_HPP__
#include <sys/types.h>
#include <unistd.h>
namespace fs
{
static
inline
off_t
lseek(const int fd,
const off_t offset,
const int whence)
{
return ::lseek(fd,offset,whence);
}
}
#endif
+39
View File
@@ -0,0 +1,39 @@
/*
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.
*/
#ifndef __FS_BASE_MKDIR_HPP__
#define __FS_BASE_MKDIR_HPP__
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
namespace fs
{
static
inline
int
mkdir(const std::string &path,
const mode_t mode)
{
return ::mkdir(path.c_str(),mode);
}
}
#endif
+40
View File
@@ -0,0 +1,40 @@
/*
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.
*/
#ifndef __FS_BASE_MKNOD_HPP__
#define __FS_BASE_MKNOD_HPP__
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
namespace fs
{
static
inline
int
mknod(const std::string &path,
const mode_t mode,
const dev_t dev)
{
return ::mknod(path.c_str(),mode,dev);
}
}
#endif
+50
View File
@@ -0,0 +1,50 @@
/*
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.
*/
#ifndef __FS_BASE_OPEN_HPP__
#define __FS_BASE_OPEN_HPP__
#include <string>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
namespace fs
{
static
inline
int
open(const std::string &path,
const int flags)
{
return ::open(path.c_str(),flags);
}
static
inline
int
open(const std::string &path,
const int flags,
const mode_t mode)
{
return ::open(path.c_str(),flags,mode);
}
}
#endif
+38
View File
@@ -0,0 +1,38 @@
/*
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.
*/
#ifndef __FS_BASE_OPENDIR_HPP__
#define __FS_BASE_OPENDIR_HPP__
#include <string>
#include <dirent.h>
#include <sys/types.h>
namespace fs
{
static
inline
DIR *
opendir(const std::string &name)
{
return ::opendir(name.c_str());
}
}
#endif
+48
View File
@@ -0,0 +1,48 @@
/*
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.
*/
#ifndef __FS_BASE_READ_HPP__
#define __FS_BASE_READ_HPP__
#include <unistd.h>
namespace fs
{
static
inline
ssize_t
read(const int fd,
void *buf,
const size_t count)
{
return ::read(fd,buf,count);
}
static
inline
ssize_t
pread(const int fd,
void *buf,
const size_t count,
const off_t offset)
{
return ::pread(fd,buf,count,offset);
}
}
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
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.
*/
#ifndef __FS_BASE_READDIR_HPP__
#define __FS_BASE_READDIR_HPP__
#include <dirent.h>
namespace fs
{
static
inline
struct dirent *
readdir(DIR *dirp)
{
return ::readdir(dirp);
}
}
#endif
+39
View File
@@ -0,0 +1,39 @@
/*
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.
*/
#ifndef __FS_BASE_READLINK_HPP__
#define __FS_BASE_READLINK_HPP__
#include <string>
#include <unistd.h>
namespace fs
{
static
inline
int
readlink(const std::string &path,
char *buf,
const size_t bufsiz)
{
return ::readlink(path.c_str(),buf,bufsiz);
}
}
#endif
+47
View File
@@ -0,0 +1,47 @@
/*
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.
*/
#ifndef __FS_BASE_REALPATH_HPP__
#define __FS_BASE_REALPATH_HPP__
#include <string>
#include <limits.h>
#include <stdlib.h>
namespace fs
{
static
inline
char *
realpath(const std::string &path,
char *resolved_path)
{
return ::realpath(path.c_str(),resolved_path);
}
static
inline
char *
realpath(const std::string &path)
{
return fs::realpath(path,NULL);
}
}
#endif
+37
View File
@@ -0,0 +1,37 @@
/*
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.
*/
#ifndef __FS_BASE_REMOVE_HPP__
#define __FS_BASE_REMOVE_HPP__
#include <string>
#include <stdio.h>
namespace fs
{
static
inline
int
remove(const std::string &pathname)
{
return ::remove(pathname.c_str());
}
}
#endif
+43
View File
@@ -0,0 +1,43 @@
/*
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.
*/
#ifndef __FS_BASE_REMOVEXATTR_HPP__
#define __FS_BASE_REMOVEXATTR_HPP__
#include <sys/types.h>
#include "errno.hpp"
#include "xattr.hpp"
namespace fs
{
static
inline
int
lremovexattr(const std::string &path,
const char *attrname)
{
#ifndef WITHOUT_XATTR
return ::lremovexattr(path.c_str(),attrname);
#else
return (errno=ENOTSUP,-1);
#endif
}
}
#endif
+36
View File
@@ -0,0 +1,36 @@
/*
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.
*/
#ifndef __FS_BASE_RENAME_HPP__
#define __FS_BASE_RENAME_HPP__
#include <stdio.h>
namespace fs
{
static
inline
int
rename(const std::string &oldpath,
const std::string &newpath)
{
return ::rename(oldpath.c_str(),newpath.c_str());
}
}
#endif
+37
View File
@@ -0,0 +1,37 @@
/*
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.
*/
#ifndef __FS_BASE_RMDIR_HPP__
#define __FS_BASE_RMDIR_HPP__
#include <string>
#include <unistd.h>
namespace fs
{
static
inline
int
rmdir(const std::string &path)
{
return ::rmdir(path.c_str());
}
}
#endif
+46
View File
@@ -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.
*/
#ifndef __FS_BASE_SETXATTR_HPP__
#define __FS_BASE_SETXATTR_HPP__
#include <sys/types.h>
#include "errno.hpp"
#include "xattr.hpp"
namespace fs
{
static
inline
int
lsetxattr(const std::string &path,
const char *name,
const void *value,
const size_t size,
const int flags)
{
#ifndef WITHOUT_XATTR
return ::lsetxattr(path.c_str(),name,value,size,flags);
#else
return (errno=ENOTSUP,-1);
#endif
}
}
#endif
+67
View File
@@ -0,0 +1,67 @@
/*
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.
*/
#ifndef __FS_BASE_STAT_HPP__
#define __FS_BASE_STAT_HPP__
#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);
}
static
inline
int
lstat(const std::string &path,
struct stat &st)
{
return ::lstat(path.c_str(),&st);
}
static
inline
int
fstat(const int fd,
struct stat &st)
{
return ::fstat(fd,&st);
}
}
#endif
+47
View File
@@ -0,0 +1,47 @@
/*
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.
*/
#ifndef __FS_BASE_STATVFS_HPP__
#define __FS_BASE_STATVFS_HPP__
#include <string>
#include <sys/statvfs.h>
namespace fs
{
static
inline
int
statvfs(const char *path,
struct statvfs &st)
{
return ::statvfs(path,&st);
}
static
inline
int
statvfs(const std::string &path,
struct statvfs &st)
{
return fs::statvfs(path.c_str(),st);
}
}
#endif
+47
View File
@@ -0,0 +1,47 @@
/*
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.
*/
#ifndef __FS_BASE_SYMLINK_HPP__
#define __FS_BASE_SYMLINK_HPP__
#include <string>
#include <unistd.h>
namespace fs
{
static
inline
int
symlink(const std::string &oldpath,
const std::string &newpath)
{
return ::symlink(oldpath.c_str(),newpath.c_str());
}
static
inline
int
symlink(const char *oldpath,
const std::string &newpath)
{
return ::symlink(oldpath,newpath.c_str());
}
}
#endif
+39
View File
@@ -0,0 +1,39 @@
/*
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.
*/
#ifndef __FS_BASE_TRUNCATE_HPP__
#define __FS_BASE_TRUNCATE_HPP__
#include <string>
#include <sys/types.h>
#include <unistd.h>
namespace fs
{
static
inline
int
truncate(const std::string &path,
const off_t length)
{
return ::truncate(path.c_str(),length);
}
}
#endif
+37
View File
@@ -0,0 +1,37 @@
/*
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.
*/
#ifndef __FS_BASE_UNLINK_HPP__
#define __FS_BASE_UNLINK_HPP__
#include <string>
#include <unistd.h>
namespace fs
{
static
inline
int
unlink(const std::string &path)
{
return ::unlink(path.c_str());
}
}
#endif
+68
View File
@@ -0,0 +1,68 @@
/*
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.
*/
#ifndef __FS_BASE_UTIME_HPP__
#define __FS_BASE_UTIME_HPP__
#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
namespace fs
{
static
inline
int
utime(const std::string &path,
const struct stat &st)
{
struct timespec times[2];
times[0] = st.st_atim;
times[1] = st.st_mtim;
return fs::utime(AT_FDCWD,path,times,0);
}
static
inline
int
utime(const int fd,
const struct stat &st)
{
struct timespec times[2];
times[0] = st.st_atim;
times[1] = st.st_mtim;
return fs::utime(fd,times);
}
static
inline
int
lutime(const std::string &path,
const struct timespec times[2])
{
return fs::utime(AT_FDCWD,path,times,AT_SYMLINK_NOFOLLOW);
}
}
#endif
+303
View File
@@ -0,0 +1,303 @@
/*
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.
*/
#ifndef __FS_BASE_UTIME_GENERIC_HPP__
#define __FS_BASE_UTIME_GENERIC_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;
if(!_any_timespec_is_utime_omit(ts))
return 0;
rv = ::fstatat(dirfd,path.c_str(),&st,flags);
if(rv == -1)
return -1;
if(ts[0].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[0],&st.st_atim);
if(ts[1].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[1],&st.st_mtim);
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;
if(!_any_timespec_is_utime_omit(ts))
return 0;
rv = ::fstat(fd,&st);
if(rv == -1)
return -1;
if(ts[0].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[0],&st.st_atim);
if(ts[1].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[1],&st.st_mtim);
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 ::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
utime(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);
}
}
#endif
+50
View File
@@ -0,0 +1,50 @@
/*
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.
*/
#ifndef __FS_BASE_UTIME_UTIMENSAT_HPP__
#define __FS_BASE_UTIME_UTIMENSAT_HPP__
#include <string>
#include <fcntl.h>
#include <sys/stat.h>
namespace fs
{
static
inline
int
utime(const int dirfd,
const std::string &path,
const struct timespec times[2],
const int flags)
{
return ::utimensat(dirfd,path.c_str(),times,flags);
}
static
inline
int
utime(const int fd,
const struct timespec times[2])
{
return ::futimens(fd,times);
}
}
#endif
+48
View File
@@ -0,0 +1,48 @@
/*
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.
*/
#ifndef __FS_BASE_WRITE_HPP__
#define __FS_BASE_WRITE_HPP__
#include <unistd.h>
namespace fs
{
static
inline
ssize_t
write(const int fd,
const void *buf,
const size_t count)
{
return ::write(fd,buf,count);
}
static
inline
ssize_t
pwrite(const int fd,
const void *buf,
const size_t count,
const off_t offset)
{
return ::pwrite(fd,buf,count,offset);
}
}
#endif
+222
View File
@@ -0,0 +1,222 @@
/*
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 <stdlib.h>
#include <string>
#include <vector>
#include "errno.hpp"
#include "fs_attr.hpp"
#include "fs_base_chmod.hpp"
#include "fs_base_chown.hpp"
#include "fs_base_close.hpp"
#include "fs_base_lseek.hpp"
#include "fs_base_mkdir.hpp"
#include "fs_base_open.hpp"
#include "fs_base_read.hpp"
#include "fs_base_stat.hpp"
#include "fs_base_utime.hpp"
#include "fs_base_write.hpp"
#include "fs_fadvise.hpp"
#include "fs_fallocate.hpp"
#include "fs_sendfile.hpp"
#include "fs_xattr.hpp"
#ifndef O_LARGEFILE
# define O_LARGEFILE 0
#endif
#ifndef O_NOATIME
# define O_NOATIME 0
#endif
using std::string;
using std::vector;
int
writen(const int fd,
const char *buf,
const size_t count)
{
size_t nleft;
ssize_t nwritten;
nleft = count;
while(nleft > 0)
{
nwritten = fs::write(fd,buf,nleft);
if(nwritten == -1)
{
if(errno == EINTR)
continue;
return -1;
}
nleft -= nwritten;
buf += nwritten;
}
return count;
}
static
int
copyfile_rw(const int fdin,
const int fdout,
const size_t count,
const size_t blocksize)
{
ssize_t nr;
ssize_t nw;
ssize_t bufsize;
size_t totalwritten;
vector<char> buf;
bufsize = (blocksize * 16);
buf.resize(bufsize);
fs::lseek(fdin,0,SEEK_SET);
totalwritten = 0;
while(totalwritten < count)
{
nr = fs::read(fdin,&buf[0],bufsize);
if(nr == -1)
{
if(errno == EINTR)
continue;
return -1;
}
nw = writen(fdout,&buf[0],nr);
if(nw == -1)
return -1;
totalwritten += nw;
}
return count;
}
static
int
copydata(const int fdin,
const int fdout,
const size_t count,
const size_t blocksize)
{
int rv;
fs::fadvise(fdin,0,count,POSIX_FADV_WILLNEED);
fs::fadvise(fdin,0,count,POSIX_FADV_SEQUENTIAL);
fs::fallocate(fdout,0,0,count);
rv = fs::sendfile(fdin,fdout,count);
if((rv == -1) && ((errno == EINVAL) || (errno == ENOSYS)))
return ::copyfile_rw(fdin,fdout,count,blocksize);
return rv;
}
static
bool
ignorable_error(const int err)
{
switch(err)
{
case ENOTTY:
case ENOTSUP:
#if ENOTSUP != EOPNOTSUPP
case EOPNOTSUPP:
#endif
return true;
}
return false;
}
namespace fs
{
int
clonefile(const int fdin,
const int fdout)
{
int rv;
struct stat stin;
rv = fs::fstat(fdin,stin);
if(rv == -1)
return -1;
rv = ::copydata(fdin,fdout,stin.st_size,stin.st_blksize);
if(rv == -1)
return -1;
rv = fs::attr::copy(fdin,fdout);
if((rv == -1) && !ignorable_error(errno))
return -1;
rv = fs::xattr::copy(fdin,fdout);
if((rv == -1) && !ignorable_error(errno))
return -1;
rv = fs::fchown_check_on_error(fdout,stin);
if(rv == -1)
return -1;
rv = fs::fchmod_check_on_error(fdout,stin);
if(rv == -1)
return -1;
rv = fs::utime(fdout,stin);
if(rv == -1)
return -1;
return 0;
}
int
clonefile(const string &in,
const string &out)
{
int rv;
int fdin;
int fdout;
int error;
fdin = fs::open(in,O_RDONLY|O_NOFOLLOW);
if(fdin == -1)
return -1;
const int flags = O_CREAT|O_LARGEFILE|O_NOATIME|O_NOFOLLOW|O_TRUNC|O_WRONLY;
const mode_t mode = S_IWUSR;
fdout = fs::open(out,flags,mode);
if(fdout == -1)
return -1;
rv = fs::clonefile(fdin,fdout);
error = errno;
fs::close(fdin);
fs::close(fdout);
errno = error;
return rv;
}
}
+30
View File
@@ -0,0 +1,30 @@
/*
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.
*/
#ifndef __FS_CLONEFILE_HPP__
#define __FS_CLONEFILE_HPP__
#include <string>
namespace fs
{
int clonefile(const int fdin,
const int fdout);
int clonefile(const std::string &from,
const std::string &to);
}
#endif
+117
View File
@@ -0,0 +1,117 @@
/*
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 "errno.h"
#include "fs_attr.hpp"
#include "fs_base_chmod.hpp"
#include "fs_base_chown.hpp"
#include "fs_base_mkdir.hpp"
#include "fs_base_stat.hpp"
#include "fs_base_utime.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
#include "fs_xattr.hpp"
using std::string;
static
bool
ignorable_error(const int err)
{
switch(err)
{
case ENOTTY:
case ENOTSUP:
#if ENOTSUP != EOPNOTSUPP
case EOPNOTSUPP:
#endif
return true;
}
return false;
}
namespace fs
{
int
clonepath(const string &fromsrc,
const string &tosrc,
const char *relative)
{
int rv;
struct stat st;
string topath;
string frompath;
string dirname;
dirname = relative;
fs::path::dirname(dirname);
if(!dirname.empty())
{
rv = fs::clonepath(fromsrc,tosrc,dirname);
if(rv == -1)
return -1;
}
fs::path::make(&fromsrc,relative,frompath);
rv = fs::stat(frompath,st);
if(rv == -1)
return -1;
else if(!S_ISDIR(st.st_mode))
return (errno=ENOTDIR,-1);
fs::path::make(&tosrc,relative,topath);
rv = fs::mkdir(topath,st.st_mode);
if(rv == -1)
{
if(errno != EEXIST)
return -1;
rv = fs::chmod_check_on_error(topath,st.st_mode);
if(rv == -1)
return -1;
}
// It may not support it... it's fine...
rv = fs::attr::copy(frompath,topath);
if((rv == -1) && !ignorable_error(errno))
return -1;
rv = fs::xattr::copy(frompath,topath);
if((rv == -1) && !ignorable_error(errno))
return -1;
rv = fs::lchown_check_on_error(topath,st);
if(rv == -1)
return -1;
rv = fs::utime(topath,st);
if(rv == -1)
return -1;
return 0;
}
int
clonepath(const std::string &from,
const std::string &to,
const std::string &relative)
{
return fs::clonepath(from,to,relative.c_str());
}
}
+32
View File
@@ -0,0 +1,32 @@
/*
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.
*/
#ifndef __FS_CLONEPATH_HPP__
#define __FS_CLONEPATH_HPP__
#include <string>
namespace fs
{
int clonepath(const std::string &from,
const std::string &to,
const char *relative);
int clonepath(const std::string &from,
const std::string &to,
const std::string &relative);
}
#endif
+44
View File
@@ -0,0 +1,44 @@
/*
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.
*/
#ifndef __FS_DEVID_HPP__
#define __FS_DEVID_HPP__
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
namespace fs
{
static
inline
dev_t
devid(const int fd)
{
int rv;
struct stat st;
rv = ::fstat(fd,&st);
if(rv == -1)
return -1;
return st.st_dev;
}
}
#endif
+23
View File
@@ -0,0 +1,23 @@
/*
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>
#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
# include "fs_fadvise_posix.icpp"
#else
# include "fs_fadvise_unsupported.icpp"
#endif
+53
View File
@@ -0,0 +1,53 @@
/*
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.
*/
#ifndef __FS_FADVISE_HPP__
#define __FS_FADVISE_HPP__
#ifndef POSIX_FADV_NORMAL
# define POSIX_FADV_NORMAL 0
#endif
#ifndef POSIX_FADV_RANDOM
# define POSIX_FADV_RANDOM 1
#endif
#ifndef POSIX_FADV_SEQUENTIAL
# define POSIX_FADV_SEQUENTIAL 2
#endif
#ifndef POSIX_FADV_WILLNEED
# define POSIX_FADV_WILLNEED 3
#endif
#ifndef POSIX_FADV_DONTNEED
# define POSIX_FADV_DONTNEED 4
#endif
#ifndef POSIX_FADV_NOREUSE
# define POSIX_FADV_NOREUSE 5
#endif
namespace fs
{
int
fadvise(const int fd,
const off_t offset,
const off_t len,
const int advice);
}
#endif // __FS_FADVISE_HPP__
+29
View File
@@ -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
fadvise(const int fd,
const off_t offset,
const off_t len,
const int advice)
{
return ::posix_fadvise(fd,offset,len,advice);
}
}
+29
View File
@@ -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
fadvise(const int fd,
const off_t offset,
const off_t len,
const int advice)
{
return (errno=EOPNOTSUPP,-1);
}
}
+27
View File
@@ -0,0 +1,27 @@
/*
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>
#ifdef __linux__
# include "fs_fallocate_linux.icpp"
#elif _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
# include "fs_fallocate_posix.icpp"
#elif __APPLE__
# include "fs_fallocate_osx.icpp"
#else
# include "fs_fallocate_unsupported.icpp"
#endif
+31
View File
@@ -0,0 +1,31 @@
/*
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.
*/
#ifndef __FS_FALLOCATE_HPP__
#define __FS_FALLOCATE_HPP__
#include <fcntl.h>
namespace fs
{
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len);
}
#endif // __FS_FALLOCATE_HPP__
+32
View File
@@ -0,0 +1,32 @@
/*
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"
#include "fs_fallocate.hpp"
namespace fs
{
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len)
{
return ::fallocate(fd,mode,offset,len);
}
}
+57
View File
@@ -0,0 +1,57 @@
/*
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"
#include "fs_fallocate.hpp"
namespace fs
{
static
int
_fallocate_core(const int fd,
const off_t offset,
const off_t len)
{
int rv;
fstore_t store = {F_ALLOCATECONTIG,F_PEOFPOSMODE,offset,len,0};
rv = ::fcntl(fd,F_PREALLOCATE,&store);
if(rv == -1)
{
store.fst_flags = F_ALLOCATEALL;
rv = ::fcntl(fd,F_PREALLOCATE,&store);
}
if(rv == -1)
return rv;
return ::ftruncate(fd,(offset+len));
}
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len)
{
if(mode)
return (errno=EOPNOTSUPP,-1);
return ::_fallocate_core(fd,offset,len);
}
}
+34
View File
@@ -0,0 +1,34 @@
/*
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"
#include "fs_fallocate.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)));
}
}
+30
View File
@@ -0,0 +1,30 @@
/*
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"
#include "fs_fallocate.hpp"
namespace fs
{
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len)
{
return (errno=EOPNOTSUPP,-1);
}
}
+42
View File
@@ -0,0 +1,42 @@
/*
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.
*/
#ifndef __FS_INODE_HPP__
#define __FS_INODE_HPP__
#include <sys/stat.h>
namespace fs
{
namespace inode
{
enum
{
MAGIC = 0x7472617065786974
};
inline
void
recompute(struct stat &st)
{
st.st_ino |= (st.st_dev << 32);
}
}
}
#endif
+114
View File
@@ -0,0 +1,114 @@
/*
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 <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_base_open.hpp"
#include "fs_base_close.hpp"
#include "fs_base_unlink.hpp"
#include "fs_base_stat.hpp"
#include "fs_clonefile.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
using std::string;
using std::vector;
namespace fs
{
int
movefile(const vector<string> &basepaths,
const char *fusepath,
const size_t additional_size,
int &origfd)
{
int rv;
int fdin;
int fdout;
int fdin_flags;
string fusedir;
string fdin_path;
string fdout_path;
struct stat fdin_st;
fdin = origfd;
rv = fs::fstat(fdin,fdin_st);
if(rv == -1)
return -1;
fdin_flags = fs::getfl(fdin);
if(rv == -1)
return -1;
rv = fs::findonfs(basepaths,fusepath,fdin,fdin_path);
if(rv == -1)
return -1;
fdin_st.st_size += additional_size;
rv = fs::mfs(basepaths,fdin_st.st_size,fdout_path);
if(rv == -1)
return -1;
fusedir = fusepath;
fs::path::dirname(fusedir);
rv = fs::clonepath(fdin_path,fdout_path,fusedir);
if(rv == -1)
return -1;
fs::path::append(fdin_path,fusepath);
fdin = fs::open(fdin_path,O_RDONLY);
if(fdin == -1)
return -1;
fs::path::append(fdout_path,fusepath);
fdout = fs::open(fdout_path,fdin_flags|O_CREAT,fdin_st.st_mode);
if(fdout == -1)
return -1;
rv = fs::clonefile(fdin,fdout);
if(rv == -1)
{
fs::close(fdin);
fs::close(fdout);
fs::unlink(fdout_path);
return -1;
}
rv = fs::unlink(fdin_path);
if(rv == -1)
{
fs::close(fdin);
fs::close(fdout);
fs::unlink(fdout_path);
return -1;
}
fs::close(fdin);
fs::close(origfd);
origfd = fdout;
return 0;
}
}
+32
View File
@@ -0,0 +1,32 @@
/*
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.
*/
#ifndef __FS_MOVEFILE_HPP__
#define __FS_MOVEFILE_HPP__
#include <string>
#include <vector>
namespace fs
{
int
movefile(const vector<string> &basepaths,
const char *fusepath,
const size_t additional_size,
int &origfd);
}
#endif

Some files were not shown because too many files have changed in this diff Show More