mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-20 00:17:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38e5815ba7 | ||
|
|
cf2cb54e2a | ||
|
|
b7269e9963 | ||
|
|
94ebccc6ed | ||
|
|
09dabc7b4c | ||
|
|
4e7e74d6f0 | ||
|
|
dca6cb4826 | ||
|
|
6aa62d03ff | ||
|
|
3a89491507 | ||
|
|
492d895632 | ||
|
|
899670bc93 | ||
|
|
9cc9bb9de2 | ||
|
|
c25974de68 | ||
|
|
16e7c72e99 | ||
|
|
011febcb91 | ||
|
|
a60d815e92 | ||
|
|
e93c946198 | ||
|
|
7b4e1ea36d | ||
|
|
726b88e039 | ||
|
|
078e4bab49 | ||
|
|
d67d5dec77 | ||
|
|
10a9918d20 | ||
|
|
1aa76a54c2 | ||
|
|
437067b5e0 | ||
|
|
67b48fcb3a | ||
|
|
ea403b4f5a | ||
|
|
b1459c6cdc | ||
|
|
953bca02fc | ||
|
|
c8fa51c81a | ||
|
|
365e153ae7 | ||
|
|
822204ff34 | ||
|
|
9a261a7864 | ||
|
|
5f7a168d0b | ||
|
|
aa71116928 | ||
|
|
35075bb0cd | ||
|
|
05d81dbc23 | ||
|
|
00235c15bf | ||
|
|
3c5351af93 | ||
|
|
12b9fc1750 | ||
|
|
3d2283f10f | ||
|
|
192bb9c57e | ||
|
|
157dae0d2f | ||
|
|
00c814dc58 | ||
|
|
6d6fb45a3b | ||
|
|
f954be60a4 | ||
|
|
897f20bff8 | ||
|
|
c7c5b07389 | ||
|
|
d0b6cd1f38 | ||
|
|
1ad05d7783 | ||
|
|
1dc7bff6e6 | ||
|
|
18d684cd16 | ||
|
|
8f594e17d7 | ||
|
|
77269a8bac | ||
|
|
cd90193deb | ||
|
|
35fca6364f | ||
|
|
cd71af8c5b | ||
|
|
a7f26d3769 | ||
|
|
3fb7f8919a | ||
|
|
abc4ed4d9f | ||
|
|
dfa82699b9 | ||
|
|
b8beeaceb3 | ||
|
|
d9a79062b8 | ||
|
|
a22b79c416 | ||
|
|
b1f2e94a2f | ||
|
|
2ebd386b5b | ||
|
|
a8cd9b710e | ||
|
|
12d2cf7464 | ||
|
|
7e423cd9ce | ||
|
|
fa3218cb72 | ||
|
|
0395e7c776 | ||
|
|
a575cf76c2 | ||
|
|
93923177ee | ||
|
|
51858114b2 | ||
|
|
1513c92cbc | ||
|
|
7824586f76 | ||
|
|
158dda9f23 | ||
|
|
577bc67fa7 | ||
|
|
1a698e5ef5 | ||
|
|
a0885e33dc | ||
|
|
2ee6b4f581 | ||
|
|
709dda5069 | ||
|
|
f0f8e527b4 | ||
|
|
49474f01ca | ||
|
|
9e8b309a90 | ||
|
|
f7547d7cf5 | ||
|
|
bb02ab2cba | ||
|
|
fb1432e14e | ||
|
|
34d38cb0fb | ||
|
|
192a9d54d1 | ||
|
|
40574bd138 | ||
|
|
064fd5560f | ||
|
|
073d1b6f6f | ||
|
|
45f757dc60 | ||
|
|
939b4a0fe5 | ||
|
|
0fceb8e0a3 | ||
|
|
34662da806 | ||
|
|
7634eb1440 | ||
|
|
08cd5f89ff | ||
|
|
47f184a944 | ||
|
|
920f7fd049 | ||
|
|
a93ab6c2f5 | ||
|
|
a375f33eb4 | ||
|
|
1e7b84f7fd | ||
|
|
43cbd9c670 | ||
|
|
9f36eada14 | ||
|
|
30cdfa64b8 | ||
|
|
81e9544f7d | ||
|
|
3cb2045ebb | ||
|
|
652440fd8c | ||
|
|
6dc6fde641 | ||
|
|
66fdcc4ef7 | ||
|
|
cb35a374ac | ||
|
|
68210d9252 | ||
|
|
23b8e4582e | ||
|
|
13511ea72a | ||
|
|
3a50344cb9 | ||
|
|
9f27ad448a | ||
|
|
be6341e6f0 | ||
|
|
f7d3e8bf47 | ||
|
|
e541cdb755 | ||
|
|
74ed1b09ee | ||
|
|
9987111fa4 | ||
|
|
d0414d7c78 | ||
|
|
8f6a7ba79a | ||
|
|
ef8d8f306e | ||
|
|
1de01684e0 | ||
|
|
cd15b7a66a | ||
|
|
6b88258d81 | ||
|
|
8643d35ebf | ||
|
|
b7d7ace9bf | ||
|
|
1cfe1c3715 | ||
|
|
63b02b327b | ||
|
|
dbb13ef7ad | ||
|
|
6aec6c939a | ||
|
|
90ca14afff | ||
|
|
c7328293a0 | ||
|
|
cfaf812c62 | ||
|
|
47fb6e29c6 | ||
|
|
0c6c69e02e | ||
|
|
4b6cfdc68a | ||
|
|
309cfee52b | ||
|
|
9b3c085cf3 | ||
|
|
382ca876ca | ||
|
|
93acfb015c | ||
|
|
070ed08caa | ||
|
|
5d44161e77 | ||
|
|
6492fda483 | ||
|
|
447fd8b2fb | ||
|
|
2061211894 | ||
|
|
5030d5a5b4 | ||
|
|
4928944167 | ||
|
|
6957cf39d1 | ||
|
|
12cf57dc5a | ||
|
|
26c2ebc843 | ||
|
|
59b08a5bc3 | ||
|
|
8ac3518725 | ||
|
|
f4a4cc5812 | ||
|
|
b93783ede0 | ||
|
|
ef4c583b3f | ||
|
|
6d049c16d1 | ||
|
|
4ecf3c5797 | ||
|
|
4a63c000ca | ||
|
|
779143f4b6 | ||
|
|
ccd3b5d2d0 | ||
|
|
4d7148cdd1 | ||
|
|
98a051b161 | ||
|
|
14886a27f4 | ||
|
|
81b9918f6b | ||
|
|
9819cf6133 | ||
|
|
c5e584fa5a | ||
|
|
c56b488c8d | ||
|
|
cd50a0b0c8 | ||
|
|
e593927095 | ||
|
|
12251cf7c2 | ||
|
|
7c85cd906a | ||
|
|
32c4b1ad1c | ||
|
|
5cf3bb7c98 | ||
|
|
3f8a6525b3 | ||
|
|
25a039942c | ||
|
|
400537d711 | ||
|
|
792c9b9808 | ||
|
|
476a8a50ea | ||
|
|
a698a8a545 | ||
|
|
5b06bb24fb | ||
|
|
d4ec341c4f | ||
|
|
1bbe3a8879 | ||
|
|
5813d1e477 | ||
|
|
81e77216fc | ||
|
|
a4e60d7471 | ||
|
|
8edb7c1e1c | ||
|
|
f3e75a0544 | ||
|
|
eed2bbf913 | ||
|
|
b3248a8f78 | ||
|
|
fc100006f9 | ||
|
|
7bf1ca45e4 | ||
|
|
c568a6d356 | ||
|
|
6086620e23 | ||
|
|
f7c37d2974 | ||
|
|
3a51ceb327 | ||
|
|
f510e539ab | ||
|
|
681f3d7492 | ||
|
|
a7c1b88bfe | ||
|
|
0bac344c8b | ||
|
|
40e41e472d | ||
|
|
840f9b8593 | ||
|
|
1160868243 | ||
|
|
f779f82ed6 | ||
|
|
a629e60f5c | ||
|
|
3e20adb109 | ||
|
|
1931e263be | ||
|
|
e285bde962 | ||
|
|
d058a366ee | ||
|
|
853769bd7c | ||
|
|
a3e693c30e | ||
|
|
ea325755a7 | ||
|
|
091cc230d8 | ||
|
|
1d1694bbb5 | ||
|
|
8287f7f119 | ||
|
|
93397ea170 | ||
|
|
da6d9b8eab | ||
|
|
25265f4e85 | ||
|
|
d4caecacbd | ||
|
|
de776b7cf0 | ||
|
|
02c1ce5181 | ||
|
|
62f8fc524e | ||
|
|
2fe465a29c | ||
|
|
242af777be | ||
|
|
fe7d841500 | ||
|
|
4c77ac4d24 | ||
|
|
f905116c3d | ||
|
|
b811522474 | ||
|
|
9b80d6905b | ||
|
|
8a5c5240f2 | ||
|
|
8257a1f765 | ||
|
|
a3e6a0352d | ||
|
|
47dc59bff2 | ||
|
|
eb6d1a1bc2 | ||
|
|
fbc2cd95cd | ||
|
|
55c4a32614 | ||
|
|
51ae7d1980 | ||
|
|
4adeb6348b | ||
|
|
c731b7035c | ||
|
|
0165fb24d4 | ||
|
|
9e24796429 | ||
|
|
2d71229fe9 | ||
|
|
5e880bddba | ||
|
|
af24bdb426 | ||
|
|
8a651b0372 | ||
|
|
762a04242f | ||
|
|
8cd747e673 | ||
|
|
93cedabe9c | ||
|
|
fd4ce1b5fa | ||
|
|
f3a6876362 | ||
|
|
61dbb85f35 | ||
|
|
30c29c9fae | ||
|
|
10eb05a14b | ||
|
|
8ed11a0e8f | ||
|
|
74f2a88ed2 | ||
|
|
46c8361fa9 | ||
|
|
02df44129d | ||
|
|
fe7960974d | ||
|
|
873c4a9840 | ||
|
|
4df9b2e6f1 | ||
|
|
e84c458cad | ||
|
|
1c7de2d83e | ||
|
|
a10de2aaf9 | ||
|
|
f83cdc215f | ||
|
|
3d7d2cf80a | ||
|
|
5d5428fbb3 | ||
|
|
5489952aa8 | ||
|
|
280309ad6d | ||
|
|
068fbc0269 | ||
|
|
6709791156 | ||
|
|
5a76c41236 | ||
|
|
3ccc94a560 | ||
|
|
58446f9124 | ||
|
|
ce2ec89964 | ||
|
|
40f569be37 | ||
|
|
db85a7d3f2 | ||
|
|
f6d396c30d | ||
|
|
95e6ebf607 | ||
|
|
53e3284b26 | ||
|
|
746bb68a0c | ||
|
|
09ffc8c903 |
@@ -12,6 +12,14 @@
|
||||
*.la
|
||||
*.a
|
||||
|
||||
# build artifacts
|
||||
mergerfs
|
||||
obj/
|
||||
src/version.hpp
|
||||
|
||||
# Debian files
|
||||
debian/files
|
||||
debian/changelog
|
||||
|
||||
# RPM files
|
||||
rpmbuild/
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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) clone
|
||||
all: $(TARGET)
|
||||
|
||||
help:
|
||||
@echo "usage: make"
|
||||
@@ -113,8 +108,8 @@ help:
|
||||
$(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
|
||||
$(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
|
||||
|
||||
clone: $(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)" clone
|
||||
endif
|
||||
endif
|
||||
$(RM) -rf obj
|
||||
$(RM) -f "$(TARGET)" mount.mergerfs
|
||||
$(FIND) . -name "*~" -delete
|
||||
|
||||
distclean: clean
|
||||
$(GIT) clean -fd
|
||||
|
||||
install: install-base install-clone 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-clone: clone
|
||||
$(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-clone uninstall-man
|
||||
uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
|
||||
|
||||
uninstall-base:
|
||||
$(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
uninstall-clone:
|
||||
$(RM) -f "$(INSTALLBINDIR)/clone"
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,69 +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<options> <srcpoints> <mountpoint>
|
||||
mergerfs -o<options> <srcmounts> <mountpoint>
|
||||
|
||||
# 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.
|
||||
|
||||
Why **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 kernel based and difficult to debug when problems arise and slower to evolve as a result. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
|
||||
**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**.
|
||||
|
||||
# FEATURES
|
||||
|
||||
* Runs in userspace (FUSE)
|
||||
* Configurable behaviors
|
||||
* Supports extended attributes (xattrs)
|
||||
* Supports file attributes (chattr)
|
||||
* Dynamically configurable (via xattrs)
|
||||
* 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**: 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 an addition caching step which can increase write speeds at the detriment of read speed.
|
||||
* **minfreespace**: the minimum space value used for the **lfs**, **fwfs**, and **epmfs** 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** 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)
|
||||
* **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.<func>=<policy>**: sets the specific FUSE function's policy. See below for the list of value types. Example: **func.getattr=newest**
|
||||
* **category.<category>=<policy>**: Sets policy of all FUSE functions in the provided category. Example: **category.create=mfs**
|
||||
|
||||
**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.
|
||||
|
||||
###srcpoints###
|
||||
###srcmounts###
|
||||
|
||||
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). **The globbing tokens MUST be escaped when using via the shell else the shell itself will probably expand it.**
|
||||
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 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 |
|
||||
|----------|----------------|
|
||||
@@ -72,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 ####
|
||||
|
||||
@@ -97,21 +112,53 @@ 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
|
||||
|
||||
@@ -122,12 +169,12 @@ 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
|
||||
@@ -136,7 +183,7 @@ $ sudo dpkg -i ../mergerfs_version_arch.deb
|
||||
#### Fedora
|
||||
```
|
||||
$ su -
|
||||
# dnf install rpm-build 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
|
||||
@@ -144,7 +191,7 @@ $ su -
|
||||
|
||||
#### Generically
|
||||
|
||||
Have pkg-config, pandoc, libfuse, libattr1 installed.
|
||||
Have git, python, pkg-config, pandoc, libfuse, libattr1 installed.
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
@@ -162,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 #####
|
||||
|
||||
@@ -175,38 +255,14 @@ Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
|
||||
user.mergerfs.srcmounts: /tmp/a:/tmp/b
|
||||
user.mergerfs.minfreespace: 4294967295
|
||||
user.mergerfs.moveonenospc: false
|
||||
user.mergerfs.policies: all,einval,enosys,enotsup,epmfs,erofs,exdev,ff,ffwp,fwfs,lfs,mfs,newest,rand
|
||||
user.mergerfs.version: x.y.z
|
||||
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
|
||||
...
|
||||
|
||||
[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
|
||||
@@ -221,41 +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 |
|
||||
|
||||
##### minfreespace #####
|
||||
|
||||
Input: interger with an optional 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.
|
||||
|
||||
#### 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
|
||||
|
||||
```
|
||||
@@ -272,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
|
||||
|
||||
Vendored
+15
-21
@@ -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
|
||||
|
||||
Vendored
+1
-1
@@ -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
File diff suppressed because it is too large
Load Diff
+5
-4
@@ -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
|
||||
|
||||
|
||||
+20
-34
@@ -1,40 +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.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_access.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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__
|
||||
|
||||
+54
-37
@@ -1,35 +1,29 @@
|
||||
/*
|
||||
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 "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_chmod.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
+55
-37
@@ -1,36 +1,29 @@
|
||||
/*
|
||||
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 "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_chown.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
@@ -39,34 +32,59 @@ 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
@@ -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
|
||||
|
||||
@@ -1,69 +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 <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "fs_clonefile.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
|
||||
namespace clonetool
|
||||
{
|
||||
static
|
||||
void
|
||||
print_usage_and__exit(void)
|
||||
{
|
||||
std::cerr << "usage: clone "
|
||||
<< "[path <sourcedir> <destdir> <relativepath>]"
|
||||
<< " | "
|
||||
<< "[file <source> <dest>]"
|
||||
<< std::endl;
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(const int argc,
|
||||
char * const argv[])
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
if(argc == 4 && !strcmp(argv[1],"file"))
|
||||
rv = fs::clonefile(argv[2],argv[3]);
|
||||
else if(argc == 5 && !strcmp(argv[1],"path"))
|
||||
rv = fs::clonepath(argv[2],argv[3],argv[4]);
|
||||
else
|
||||
print_usage_and__exit();
|
||||
|
||||
if(rv == -1)
|
||||
std::cerr << "error: "
|
||||
<< strerror(errno)
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -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 clonetool
|
||||
{
|
||||
int
|
||||
main(const int argc,
|
||||
char * const *argv);
|
||||
}
|
||||
+17
-22
@@ -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,8 +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),
|
||||
|
||||
+14
-20
@@ -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,8 +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];
|
||||
|
||||
+81
-51
@@ -1,90 +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 "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_path.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 = reinterpret_cast<uint64_t>(new FileInfo(fd));
|
||||
|
||||
return 0;
|
||||
return _create_core(*existingpaths[0],*createpaths[0],
|
||||
fusepath,fusedirpathcstr,
|
||||
mode,umask,flags,fh);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -106,7 +135,8 @@ namespace mergerfs
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
(mode & ~fc->umask),
|
||||
mode,
|
||||
fc->umask,
|
||||
ffi->flags,
|
||||
ffi->fh);
|
||||
}
|
||||
|
||||
+18
-20
@@ -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
|
||||
@@ -35,3 +31,5 @@ namespace mergerfs
|
||||
fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+11
-19
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
+14
-42
@@ -1,39 +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
|
||||
@@ -44,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);
|
||||
}
|
||||
|
||||
+16
-19
@@ -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
|
||||
|
||||
+21
-28
@@ -1,35 +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
|
||||
@@ -38,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
|
||||
@@ -54,8 +48,7 @@ namespace mergerfs
|
||||
{
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
return _fgetattr(fi->fd,
|
||||
*st);
|
||||
return _fgetattr(fi->fd,*st);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
-20
@@ -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
|
||||
|
||||
+11
-19
@@ -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 __FILEINFO_HPP__
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
+16
-24
@@ -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 <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_dup.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
@@ -35,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);
|
||||
}
|
||||
|
||||
+16
-19
@@ -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
|
||||
|
||||
+150
-76
@@ -1,99 +1,170 @@
|
||||
/*
|
||||
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 <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fcntl.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
bool
|
||||
exists(const string &path,
|
||||
struct stat &st)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::lstat(path,st);
|
||||
|
||||
return LSTAT_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
exists(const string &path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
return exists(path,st);
|
||||
}
|
||||
|
||||
bool
|
||||
info(const string &path,
|
||||
bool &readonly,
|
||||
uint64_t &spaceavail,
|
||||
uint64_t &spaceused)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
{
|
||||
readonly = StatVFS::readonly(st);
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
}
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
readonly(const string &path)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
|
||||
return (STATVFS_SUCCEEDED(rv) && StatVFS::readonly(st));
|
||||
}
|
||||
|
||||
bool
|
||||
spaceavail(const string &path,
|
||||
uint64_t &spaceavail)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
spaceused(const string &path,
|
||||
uint64_t &spaceused)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
|
||||
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
|
||||
findonfs(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
const char *fusepath,
|
||||
const int fd,
|
||||
string &basepath)
|
||||
{
|
||||
int rv;
|
||||
string tmppath;
|
||||
unsigned long fsid;
|
||||
struct statvfs buf;
|
||||
dev_t dev;
|
||||
string fullpath;
|
||||
struct stat st;
|
||||
|
||||
rv = ::fstatvfs(fd,&buf);
|
||||
if(rv == -1)
|
||||
rv = fs::fstat(fd,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
fsid = buf.f_fsid;
|
||||
dev = st.st_dev;
|
||||
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
fs::path::make(srcmounts[i],fusepath,tmppath);
|
||||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||
|
||||
rv = ::statvfs(tmppath.c_str(),&buf);
|
||||
if(rv == -1)
|
||||
rv = fs::lstat(fullpath,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
continue;
|
||||
|
||||
if(buf.f_fsid == fsid)
|
||||
{
|
||||
basepath = srcmounts[i];
|
||||
return 0;
|
||||
}
|
||||
if(st.st_dev != dev)
|
||||
continue;
|
||||
|
||||
basepath = srcmounts[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (errno=ENOENT,-1);
|
||||
@@ -104,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]);
|
||||
@@ -123,15 +199,16 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,38 +220,35 @@ namespace fs
|
||||
|
||||
int
|
||||
mfs(const vector<string> &basepaths,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
string &path)
|
||||
{
|
||||
fsblkcnt_t mfs;
|
||||
ssize_t mfsidx;
|
||||
const string *mfsbasepath;
|
||||
|
||||
mfs = 0;
|
||||
mfsidx = -1;
|
||||
mfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
uint64_t spaceavail;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
if(!fs::spaceavail(basepath,spaceavail))
|
||||
continue;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if((spaceavail > mfs) && (spaceavail >= minfreespace))
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfsidx = i;
|
||||
}
|
||||
}
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceavail <= mfs)
|
||||
continue;
|
||||
|
||||
mfs = spaceavail;
|
||||
mfsbasepath = &basepaths[i];
|
||||
}
|
||||
|
||||
if(mfsidx == -1)
|
||||
if(mfsbasepath == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
path = basepaths[mfsidx];
|
||||
path = *mfsbasepath;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+33
-23
@@ -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__
|
||||
@@ -28,18 +20,36 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
using std::size_t;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
bool exists(const string &path,
|
||||
struct stat &st);
|
||||
bool exists(const string &path);
|
||||
|
||||
bool info(const string &path,
|
||||
bool &readonly,
|
||||
uint64_t &spaceavail,
|
||||
uint64_t &spaceused);
|
||||
|
||||
bool readonly(const string &path);
|
||||
|
||||
bool spaceavail(const string &path,
|
||||
uint64_t &spaceavail);
|
||||
|
||||
bool spaceused(const string &path,
|
||||
uint64_t &spaceavail);
|
||||
|
||||
void findallfiles(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
const char *fusepath,
|
||||
vector<string> &paths);
|
||||
|
||||
int findonfs(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
const char *fusepath,
|
||||
const int fd,
|
||||
string &basepath);
|
||||
|
||||
@@ -51,7 +61,7 @@ namespace fs
|
||||
int getfl(const int fd);
|
||||
|
||||
int mfs(const vector<string> &srcs,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
string &path);
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+16
-130
@@ -1,135 +1,21 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2015 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 <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace attr
|
||||
{
|
||||
static
|
||||
int
|
||||
get_fs_ioc_flags(const int fd,
|
||||
int &flags)
|
||||
{
|
||||
return ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
|
||||
}
|
||||
|
||||
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 = get_fs_ioc_flags(fd,flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ::close(fd);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
set_fs_ioc_flags(const int fd,
|
||||
const int flags)
|
||||
{
|
||||
return ::ioctl(fd,FS_IOC_SETFLAGS,&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 = ::open(file.c_str(),openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = set_fs_ioc_flags(fd,flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef __linux__
|
||||
# include "fs_attr_linux.icpp"
|
||||
#else
|
||||
# include "fs_attr_unsupported.icpp"
|
||||
#endif
|
||||
|
||||
+11
-19
@@ -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_ATTR_HPP__
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
+150
-159
@@ -1,164 +1,158 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2015 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 <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#ifdef __linux__
|
||||
#include <sys/sendfile.h>
|
||||
#endif
|
||||
#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
|
||||
{
|
||||
static
|
||||
ssize_t
|
||||
sendfile(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count)
|
||||
{
|
||||
#if defined __linux__
|
||||
off_t offset = 0;
|
||||
return ::sendfile(fdout,fdin,&offset,count);
|
||||
#else
|
||||
return (errno=EINVAL,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
writen(const int fd,
|
||||
const char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
size_t nleft;
|
||||
ssize_t nwritten;
|
||||
|
||||
nleft = count;
|
||||
while(nleft > 0)
|
||||
{
|
||||
nwritten = ::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);
|
||||
|
||||
totalwritten = 0;
|
||||
while(totalwritten < count)
|
||||
{
|
||||
nr = ::read(fdin,&buf[0],bufsize);
|
||||
if(nr == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
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;
|
||||
|
||||
::posix_fadvise(fdin,0,count,POSIX_FADV_WILLNEED);
|
||||
::posix_fadvise(fdin,0,count,POSIX_FADV_SEQUENTIAL);
|
||||
|
||||
::posix_fallocate(fdout,0,count);
|
||||
|
||||
rv = fs::sendfile(fdin,fdout,count);
|
||||
if((rv == -1) && ((errno == EINVAL) || (errno == ENOSYS)))
|
||||
return fs::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;
|
||||
}
|
||||
|
||||
int
|
||||
clonefile(const int fdin,
|
||||
const int fdout)
|
||||
@@ -166,34 +160,31 @@ namespace fs
|
||||
int rv;
|
||||
struct stat stin;
|
||||
|
||||
rv = ::fstat(fdin,&stin);
|
||||
rv = fs::fstat(fdin,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = copydata(fdin,fdout,stin.st_size,stin.st_blksize);
|
||||
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))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::xattr::copy(fdin,fdout);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = ::fchown(fdout,stin.st_uid,stin.st_gid);
|
||||
rv = fs::fchown_check_on_error(fdout,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::fchmod(fdout,stin.st_mode);
|
||||
rv = fs::fchmod_check_on_error(fdout,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
struct timespec times[2];
|
||||
times[0] = stin.st_atim;
|
||||
times[1] = stin.st_mtim;
|
||||
rv = ::futimens(fdout,times);
|
||||
rv = fs::utime(fdout,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
@@ -209,21 +200,21 @@ namespace fs
|
||||
int fdout;
|
||||
int error;
|
||||
|
||||
fdin = ::open(in.c_str(),O_RDONLY|O_NOFOLLOW);
|
||||
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 int mode = S_IWUSR;
|
||||
fdout = ::open(out.c_str(),flags,mode);
|
||||
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;
|
||||
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
fs::close(fdin);
|
||||
fs::close(fdout);
|
||||
|
||||
errno = error;
|
||||
return rv;
|
||||
|
||||
+16
-19
@@ -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 __FS_CLONEFILE_HPP__
|
||||
#define __FS_CLONEFILE_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
@@ -31,3 +26,5 @@ namespace fs
|
||||
int clonefile(const std::string &from,
|
||||
const std::string &to);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+58
-58
@@ -1,63 +1,57 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2015 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>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#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
|
||||
{
|
||||
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)
|
||||
const char *relative)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
@@ -65,53 +59,59 @@ namespace fs
|
||||
string frompath;
|
||||
string dirname;
|
||||
|
||||
dirname = fs::path::dirname(relative);
|
||||
dirname = relative;
|
||||
fs::path::dirname(dirname);
|
||||
if(!dirname.empty())
|
||||
{
|
||||
rv = clonepath(fromsrc,tosrc,dirname);
|
||||
rv = fs::clonepath(fromsrc,tosrc,dirname);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path::make(fromsrc,relative,frompath);
|
||||
rv = ::stat(frompath.c_str(),&st);
|
||||
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);
|
||||
return (errno=ENOTDIR,-1);
|
||||
|
||||
fs::path::make(tosrc,relative,topath);
|
||||
rv = ::mkdir(topath.c_str(),st.st_mode);
|
||||
fs::path::make(&tosrc,relative,topath);
|
||||
rv = fs::mkdir(topath,st.st_mode);
|
||||
if(rv == -1)
|
||||
{
|
||||
if(errno != EEXIST)
|
||||
return -1;
|
||||
|
||||
rv = ::chmod(topath.c_str(),st.st_mode);
|
||||
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))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::xattr::copy(frompath,topath);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
|
||||
rv = fs::lchown_check_on_error(topath,st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
struct timespec times[2];
|
||||
times[0] = st.st_atim;
|
||||
times[1] = st.st_mtim;
|
||||
rv = ::utimensat(-1,topath.c_str(),times,0);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
+19
-19
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
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_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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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__
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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__
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
+34
-37
@@ -1,39 +1,35 @@
|
||||
/*
|
||||
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>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_clonepath.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;
|
||||
@@ -57,7 +53,7 @@ namespace fs
|
||||
|
||||
fdin = origfd;
|
||||
|
||||
rv = fstat(fdin,&fdin_st);
|
||||
rv = fs::fstat(fdin,fdin_st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
@@ -74,41 +70,42 @@ namespace fs
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
fusedir = fs::path::dirname(fusepath);
|
||||
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 = ::open(fdin_path.c_str(),O_RDONLY);
|
||||
fdin = fs::open(fdin_path,O_RDONLY);
|
||||
if(fdin == -1)
|
||||
return -1;
|
||||
|
||||
fs::path::append(fdout_path,fusepath);
|
||||
fdout = ::open(fdout_path.c_str(),fdin_flags|O_CREAT,fdin_st.st_mode);
|
||||
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)
|
||||
{
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
::unlink(fdout_path.c_str());
|
||||
fs::close(fdin);
|
||||
fs::close(fdout);
|
||||
fs::unlink(fdout_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ::unlink(fdin_path.c_str());
|
||||
rv = fs::unlink(fdin_path);
|
||||
if(rv == -1)
|
||||
{
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
::unlink(fdout_path.c_str());
|
||||
fs::close(fdin);
|
||||
fs::close(fdout);
|
||||
fs::unlink(fdout_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
::close(fdin);
|
||||
::close(origfd);
|
||||
fs::close(fdin);
|
||||
fs::close(origfd);
|
||||
|
||||
origfd = fdout;
|
||||
|
||||
|
||||
+11
-19
@@ -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_MOVEFILE_HPP__
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user