mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-19 16:16:48 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
f844daa76c | ||
|
|
c289dafadc | ||
|
|
2e538068ef | ||
|
|
5808ab7795 | ||
|
|
4e5578de9c | ||
|
|
4b375faf12 | ||
|
|
9542e6340b | ||
|
|
de583b70f7 | ||
|
|
8bf0f755e1 | ||
|
|
5850fbe3f1 | ||
|
|
1cc1b1f746 | ||
|
|
a960a7ef46 | ||
|
|
9afd0654b7 | ||
|
|
e0cf97261c | ||
|
|
1782910437 | ||
|
|
f4e3f28153 | ||
|
|
6a96d3b69b | ||
|
|
08c0c2dfae | ||
|
|
ad5380d69e | ||
|
|
3163258a33 | ||
|
|
b194272e39 | ||
|
|
c131310c55 | ||
|
|
8323e16ad2 | ||
|
|
ce9352987c | ||
|
|
accd2d4ae0 | ||
|
|
2d899479c3 | ||
|
|
803b2ae999 | ||
|
|
e98b801c9d | ||
|
|
27cf7f8148 | ||
|
|
b22528bac4 | ||
|
|
adf983c8c3 | ||
|
|
e377d54c93 | ||
|
|
7bee6230ba | ||
|
|
08d07b71e1 | ||
|
|
ce2462042f | ||
|
|
305f190f09 | ||
|
|
d89735abf6 | ||
|
|
8178bf518c | ||
|
|
22d254e8df | ||
|
|
aea5e440d7 | ||
|
|
908a2f61f7 | ||
|
|
bc77b0fd2a | ||
|
|
4141181243 | ||
|
|
1f1e481075 | ||
|
|
6b5b7c38f4 | ||
|
|
7a93198d4a | ||
|
|
fd26793305 | ||
|
|
bbc75f6ff1 | ||
|
|
cac5f1b827 | ||
|
|
126df0fbf1 | ||
|
|
2cc9b42c9c | ||
|
|
ab68ac0cb1 | ||
|
|
f3a3609998 | ||
|
|
e73ea33e9c | ||
|
|
c2164457bc | ||
|
|
95192511b1 | ||
|
|
7775d6830c | ||
|
|
8767db971a | ||
|
|
838c081b8c | ||
|
|
ac41bc43f3 | ||
|
|
267f2d291c | ||
|
|
f130d07fd8 | ||
|
|
81dbafdc19 | ||
|
|
52d80299b5 | ||
|
|
416cb4a084 | ||
|
|
c60d03831f | ||
|
|
ac03e08d31 | ||
|
|
80b2c35175 | ||
|
|
f8f63cdbd1 | ||
|
|
983fa9100d | ||
|
|
efadd2c8d8 | ||
|
|
c505ec0cdb | ||
|
|
e5359ebd05 | ||
|
|
f00cd1467e | ||
|
|
e4be3aac2a | ||
|
|
4d605388a4 | ||
|
|
2ee3d4eec2 | ||
|
|
aafc1e9394 | ||
|
|
eebfe456f6 | ||
|
|
b3109ac506 | ||
|
|
54484f35fc | ||
|
|
d079856e09 | ||
|
|
c101430b98 | ||
|
|
1d798ad285 | ||
|
|
b2cd79154a | ||
|
|
0c60701b29 | ||
|
|
51b6d3f647 | ||
|
|
a5bf48c8ae | ||
|
|
6ca43893ea | ||
|
|
3c8f12281f | ||
|
|
2bd44568a1 | ||
|
|
23cca83742 | ||
|
|
8e5b79647b | ||
|
|
9ea4bf2828 | ||
|
|
58167c3636 | ||
|
|
6578b93190 | ||
|
|
ccb22c1fbe | ||
|
|
ad7ce487bb | ||
|
|
fd2ba50cad | ||
|
|
fe0f442c3d | ||
|
|
1879c9c4a9 | ||
|
|
247bac76eb | ||
|
|
45b73e53be | ||
|
|
ffc90f52bc | ||
|
|
5fb277529f | ||
|
|
7552ad6781 | ||
|
|
4b204b8fba | ||
|
|
4ea49fcfbb | ||
|
|
33c837a560 | ||
|
|
3725387132 | ||
|
|
951b22b671 | ||
|
|
0a0e8fdefc | ||
|
|
74c334c372 | ||
|
|
711261bb02 | ||
|
|
08366a35be | ||
|
|
8b41dca91a | ||
|
|
91671d7364 | ||
|
|
15b2c8be1b | ||
|
|
c022741ffb | ||
|
|
a359c88173 | ||
|
|
12f393a55e | ||
|
|
e0f0bb53f7 | ||
|
|
283a2b2285 | ||
|
|
dba9e00adc | ||
|
|
1a1c9db37b | ||
|
|
f3f5a18ef5 | ||
|
|
d30cae217b | ||
|
|
dbe630c37d | ||
|
|
2e95c6e78e | ||
|
|
58ec83dcd8 | ||
|
|
b411c63df1 | ||
|
|
1f61a662ad | ||
|
|
1f90203025 | ||
|
|
805bc2d2e6 | ||
|
|
c2cbb93c25 | ||
|
|
6276ce9779 | ||
|
|
d1f3bd82e8 | ||
|
|
031b87f674 | ||
|
|
233c216e66 | ||
|
|
5dd072962b | ||
|
|
90b0fcd5f5 | ||
|
|
66563aa142 | ||
|
|
6c3ff01a0a | ||
|
|
d7ede20abe | ||
|
|
19051925db | ||
|
|
613b996296 | ||
|
|
39c750b368 | ||
|
|
47522a25cc | ||
|
|
6c31efc964 | ||
|
|
075d62d647 | ||
|
|
cfe7609bcd | ||
|
|
8f35406000 | ||
|
|
4ea1adbf96 | ||
|
|
15f88494e4 | ||
|
|
7e9ccd0317 | ||
|
|
992e05e897 | ||
|
|
b82db46e29 | ||
|
|
7b0d703f00 | ||
|
|
45cec2d301 | ||
|
|
2295714548 | ||
|
|
ccb0ac1463 | ||
|
|
15a0416eed | ||
|
|
ec38a9c783 | ||
|
|
3b6c74878c | ||
|
|
f385f02d0f | ||
|
|
0e12d79659 | ||
|
|
716453596a | ||
|
|
dd666079b6 | ||
|
|
0f8fe47016 | ||
|
|
45a2e09fbe | ||
|
|
645c823778 | ||
|
|
18358261af | ||
|
|
4a0bc4aef7 | ||
|
|
e2e0359eb2 | ||
|
|
655436f258 | ||
|
|
a7d9a9bf61 | ||
|
|
36887e456f | ||
|
|
652a299ac1 | ||
|
|
aab90b0503 | ||
|
|
345d0bbdc4 | ||
|
|
4c7095ccf6 | ||
|
|
bbc4b594fe | ||
|
|
16fe0cf90c | ||
|
|
29ed2bca01 | ||
|
|
243a193e66 | ||
|
|
97ce6f5f21 | ||
|
|
428dd8c877 |
+12
@@ -11,3 +11,15 @@
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
|
||||
# build artifacts
|
||||
mergerfs
|
||||
obj/
|
||||
src/version.hpp
|
||||
|
||||
# Debian files
|
||||
debian/files
|
||||
debian/changelog
|
||||
|
||||
# RPM files
|
||||
rpmbuild/
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -1,60 +1,212 @@
|
||||
# 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.
|
||||
|
||||
SRC = $(wildcard src/*.cpp)
|
||||
OBJ = $(SRC:src/%.cpp=obj/%.o)
|
||||
DEPS = $(OBJ:obj/%.o=obj/%.d)
|
||||
TARGET = mergerfs
|
||||
CFLAGS = -g -Wall \
|
||||
$(shell pkg-config fuse --cflags) \
|
||||
-DFUSE_USE_VERSION=26 \
|
||||
-MMD
|
||||
|
||||
ifdef WITHOUT_XATTR
|
||||
CFLAGS += -DWITHOUT_XATTR
|
||||
PKGCONFIG = $(shell which pkg-config)
|
||||
GIT = $(shell which git)
|
||||
TAR = $(shell which tar)
|
||||
MKDIR = $(shell which mkdir)
|
||||
TOUCH = $(shell which touch)
|
||||
CP = $(shell which cp)
|
||||
RM = $(shell which rm)
|
||||
LN = $(shell which ln)
|
||||
FIND = $(shell which find)
|
||||
INSTALL = $(shell which install)
|
||||
MKTEMP = $(shell which mktemp)
|
||||
STRIP = $(shell which strip)
|
||||
PANDOC = $(shell which pandoc)
|
||||
SED = $(shell which sed)
|
||||
GZIP = $(shell which gzip)
|
||||
RPMBUILD = $(shell which rpmbuild)
|
||||
GIT2DEBCL = ./tools/git2debcl
|
||||
CPPFIND = ./tools/cppfind
|
||||
|
||||
ifeq ($(PKGCONFIG),"")
|
||||
$(error "pkg-config not installed")
|
||||
endif
|
||||
|
||||
LDFLAGS = $(shell pkg-config fuse --libs)
|
||||
ifeq ($(PANDOC),"")
|
||||
$(warning "pandoc does not appear available: manpage won't be buildable")
|
||||
endif
|
||||
|
||||
XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
|
||||
|
||||
FUSE_AVAILABLE = $(shell ! pkg-config --exists fuse; echo $$?)
|
||||
|
||||
ifeq ($(FUSE_AVAILABLE),0)
|
||||
FUSE_AVAILABLE = $(shell test ! -e /usr/include/fuse.h; echo $$?)
|
||||
endif
|
||||
|
||||
ifeq ($(FUSE_AVAILABLE),0)
|
||||
$(error "FUSE development package doesn't appear available")
|
||||
endif
|
||||
|
||||
FLAG_NOPATH = $(shell $(CPPFIND) "flag_nopath")
|
||||
FALLOCATE = $(shell $(CPPFIND) "fuse_fs_fallocate")
|
||||
FLOCK = $(shell $(CPPFIND) "fuse_fs_flock")
|
||||
READ_BUF = $(shell $(CPPFIND) "fuse_fs_read_buf")
|
||||
WRITE_BUF = $(shell $(CPPFIND) "fuse_fs_write_buf")
|
||||
|
||||
UGID_USE_RWLOCK = 0
|
||||
|
||||
OPTS = -O2
|
||||
SRC = $(wildcard src/*.cpp)
|
||||
OBJ = $(SRC:src/%.cpp=obj/%.o)
|
||||
DEPS = $(OBJ:obj/%.o=obj/%.d)
|
||||
TARGET = mergerfs
|
||||
MANPAGE = $(TARGET).1
|
||||
FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
|
||||
CFLAGS = -g -Wall \
|
||||
$(OPTS) \
|
||||
-Wno-unused-result \
|
||||
$(FUSE_CFLAGS) \
|
||||
-DFUSE_USE_VERSION=26 \
|
||||
-MMD \
|
||||
-DFLAG_NOPATH=$(FLAG_NOPATH) \
|
||||
-DFALLOCATE=$(FALLOCATE) \
|
||||
-DFLOCK=$(FLOCK) \
|
||||
-DREAD_BUF=$(READ_BUF) \
|
||||
-DWRITE_BUF=$(WRITE_BUF) \
|
||||
-DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
|
||||
LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
|
||||
|
||||
PREFIX = /usr/local
|
||||
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)
|
||||
$(warning "xattr not available: disabling")
|
||||
CFLAGS += -DWITHOUT_XATTR
|
||||
endif
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
help:
|
||||
@echo usage: make
|
||||
@echo make WITHOUT_XATTR=1 - to build program without xattrs functionality
|
||||
@echo "usage: make"
|
||||
@echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
|
||||
|
||||
$(TARGET): obj/obj-stamp $(OBJ)
|
||||
g++ $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
|
||||
$(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
|
||||
$(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
|
||||
|
||||
mount.mergerfs: $(TARGET)
|
||||
$(LN) -fs "$<" "$@"
|
||||
|
||||
changelog:
|
||||
$(GIT2DEBCL) --name $(TARGET) > ChangeLog
|
||||
|
||||
authors:
|
||||
$(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
|
||||
|
||||
src/version.hpp:
|
||||
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
|
||||
@echo "#ifndef _VERSION_HPP" > src/version.hpp
|
||||
@echo "#define _VERSION_HPP" >> src/version.hpp
|
||||
@echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
|
||||
@echo "#endif" >> src/version.hpp
|
||||
|
||||
obj/obj-stamp:
|
||||
mkdir -p obj
|
||||
touch $@
|
||||
$(MKDIR) -p obj
|
||||
$(TOUCH) $@
|
||||
|
||||
obj/%.o: src/%.cpp
|
||||
g++ $(CFLAGS) -c $< -o $@
|
||||
$(CXX) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf obj "$(TARGET)"
|
||||
find -name "*~" -delete
|
||||
clean: rpm-clean
|
||||
$(RM) -rf obj
|
||||
$(RM) -f src/version.hpp
|
||||
$(RM) -f "$(TARGET)" "$(MANPAGE)" mount.mergerfs
|
||||
$(FIND) . -name "*~" -delete
|
||||
|
||||
.PHONY: all clean help
|
||||
distclean: clean
|
||||
$(GIT) clean -fd
|
||||
|
||||
install: install-base install-mount.mergerfs install-man
|
||||
|
||||
install-base: $(TARGET)
|
||||
$(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
install-mount.mergerfs: mount.mergerfs
|
||||
$(MKDIR) -p "$(INSTALLBINDIR)"
|
||||
$(CP) -a "$<" "$(INSTALLBINDIR)/$<"
|
||||
|
||||
install-man: $(MANPAGE)
|
||||
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
|
||||
|
||||
install-strip: install-base
|
||||
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
|
||||
|
||||
uninstall-base:
|
||||
$(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
uninstall-mount.mergerfs:
|
||||
$(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
|
||||
|
||||
uninstall-man:
|
||||
$(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
|
||||
|
||||
$(MANPAGE): README.md
|
||||
ifneq (,$(PANDOC))
|
||||
$(PANDOC) -s -t man -o $(MANPAGE) README.md
|
||||
else
|
||||
$(CP) man/mergerfs.1 .
|
||||
endif
|
||||
|
||||
man: $(MANPAGE)
|
||||
|
||||
tarball: clean man changelog authors src/version.hpp
|
||||
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
|
||||
$(eval VERSION := $(subst -,_,$(VERSION)))
|
||||
$(eval FILENAME := $(TARGET)-$(VERSION))
|
||||
$(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
|
||||
$(MKDIR) $(TMPDIR)/$(FILENAME)
|
||||
$(CP) -ar . $(TMPDIR)/$(FILENAME)
|
||||
$(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
|
||||
$(RM) -rf $(TMPDIR)
|
||||
|
||||
debian-changelog:
|
||||
$(GIT2DEBCL) --name $(TARGET) > debian/changelog
|
||||
|
||||
signed-deb: debian-changelog
|
||||
dpkg-buildpackage
|
||||
|
||||
deb: debian-changelog
|
||||
dpkg-buildpackage -uc -us
|
||||
|
||||
rpm-clean:
|
||||
$(RM) -rf rpmbuild
|
||||
|
||||
rpm: tarball
|
||||
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
|
||||
$(eval VERSION := $(subst -,_,$(VERSION)))
|
||||
$(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
|
||||
$(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
|
||||
--define "_topdir $(CURDIR)/rpmbuild"
|
||||
|
||||
.PHONY: all clean install help
|
||||
|
||||
include $(wildcard obj/*.d)
|
||||
|
||||
@@ -1,101 +1,367 @@
|
||||
mergerfs
|
||||
========
|
||||
% mergerfs(1) mergerfs user manual
|
||||
% Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
% 2016-01-21
|
||||
|
||||
another FUSE union filesystem
|
||||
# NAME
|
||||
|
||||
mergerfs is similar to mhddfs, unionfs, and aufs. Like mhddfs in that it too uses FUSE. Like aufs in that it provides multiple policies for how to handle behavior.
|
||||
mergerfs - another (FUSE based) union filesystem
|
||||
|
||||
Why create mergerfs when those exist? mhddfs isn't really maintained or flexible. There are also issues with running as root. aufs is more flexible but contains some hard to debug inconsistencies in behavior. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
|
||||
# SYNOPSIS
|
||||
|
||||
Policies
|
||||
========
|
||||
mergerfs -o<options> <srcmounts> <mountpoint>
|
||||
|
||||
Filesystem calls are broken up into 5 classes of policies: search, action, create, statfs, and none.
|
||||
# DESCRIPTION
|
||||
|
||||
Below shows each policy class, the FUSE calls they impact, and the policy names.
|
||||
**mergerfs** is a union filesystem geared towards simplifing storage and management of files across numerous commodity storage devices. It is similar to **mhddfs**, **unionfs**, and **aufs**.
|
||||
|
||||
####Policy classifications####
|
||||
| Class | FUSE calls | Policies |
|
||||
|-------|------------|----------|
|
||||
| search | access, getattr, getxattr, listxattr, open, readlink | First Found (ff), First Found w/ Permission (ffwp), Newest (newest) |
|
||||
| action | chmod, link, removexattr, rmdir, setxattr, truncate, unlink, utimens | First Found (ff), First Found w/ Permission (ffwp), Newest (newest), All Found (all) |
|
||||
| create | create, mkdir, mknod | Existing Path (ep), Most Free Space (mfs), Existing Path Most Free Space (epmfs), Random (rand) |
|
||||
| statfs | statfs | Sum Used Max Free (sumf), Sum Used Sum Free (susf) |
|
||||
| none | fallocate, fsync, ftruncate, ioctl, read, readdir, rename, symlink, write, release | |
|
||||
# FEATURES
|
||||
|
||||
####Descriptions####
|
||||
| Class/Policy | Description |
|
||||
* Runs in userspace (FUSE)
|
||||
* Configurable behaviors
|
||||
* Support for extended attributes (xattrs)
|
||||
* Support for file attributes (chattr)
|
||||
* Runtime configurable (via xattrs)
|
||||
* Safe to run as root
|
||||
* Opportunistic credential caching
|
||||
* Works with heterogeneous filesystem types
|
||||
* Handling of writes to full drives
|
||||
|
||||
# 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)
|
||||
* **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.
|
||||
|
||||
###srcmounts###
|
||||
|
||||
The source mounts argument is a colon (':') delimited list of paths. To make it simpler to include multiple source mounts 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.**
|
||||
|
||||
```
|
||||
$ mergerfs /mnt/disk\*:/mnt/cdrom /media/drives
|
||||
```
|
||||
|
||||
The above line will use all mount points in /mnt prefixed with *disk* and the directory *cdrom*.
|
||||
|
||||
In /etc/fstab it'd look like the following:
|
||||
|
||||
```
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other 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.
|
||||
|
||||
# POLICIES
|
||||
|
||||
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**.
|
||||
|
||||
#### Functional classifications ####
|
||||
|
||||
| Category | FUSE Functions |
|
||||
|----------|----------------|
|
||||
| action | chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate, unlink, utimens |
|
||||
| create | create, mkdir, mknod, symlink |
|
||||
| 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.
|
||||
|
||||
#### Policy descriptions ####
|
||||
|
||||
| Policy | Description |
|
||||
|--------------|-------------|
|
||||
| search/ff | Given the order the paths were provided at mount time act on the first one found (regardless if stat would return EACCES). |
|
||||
| search/ffwp | Given the order the paths were provided at mount time act on the first one found which you have access (stat does not error with EACCES). |
|
||||
| search/newest | If multiple files exist return the one with the most recent mtime. |
|
||||
| action/ff | (same as search/ff) |
|
||||
| action/ffwp | (same as search/ffwp) |
|
||||
| action/newest | (same as search/newest) |
|
||||
| action/all | Attempt to apply the call to each file found. If any sub call succeeds the entire operation succeeds and other errors ignored. If all fail then the last error is reported. |
|
||||
| create/ep | Choose the first path which is found. |
|
||||
| create/mfs | Assuming the path is found to exist (ENOENT would not be returned) use the drive with the most free space available. |
|
||||
| create/epmfs | If the path exists in multiple locations use the one with the most free space. Otherwise fall back to mfs. |
|
||||
| create/rand | Pick a destination at random. Again the dirname of the full path must exist somewhere. |
|
||||
| statfs/sumf | When reporting the size of the filesystem it will show the sum of all used but the available space will be reported as the max available across the filesystems mounted. |
|
||||
| statfs/susf | As above but will report the sum of available space. Since the largest usable space is that of the filesystem with the most usable space this option is deceptive. |
|
||||
| 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. |
|
||||
|
||||
**NOTE:** create is really a search for existence and then create. The 'search' policy applies to the first part. If the [dirname](http://linux.die.net/man/3/dirname) of the full path is not found to exist [ENOENT](http://linux.die.net/man/3/errno) is returned.
|
||||
#### Defaults ####
|
||||
|
||||
Usage
|
||||
=====
|
||||
| Category | Policy |
|
||||
|----------|--------|
|
||||
| action | all |
|
||||
| create | epmfs |
|
||||
| search | ff |
|
||||
|
||||
#### 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 source and destination 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. This can lead to several undesirable situtations with or without errors and it's not entirely obvious what to do when an error occurs.
|
||||
|
||||
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 they only partially support EXDEV (don't respond the same as `mv` would). 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.
|
||||
|
||||
* If using a policy which tries to preserve directories (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 policy which does **not** try to preserve directories
|
||||
* 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. To remove the possibility all together mergerfs would need to perform the as `mv` does when it receives EXDEV normally.
|
||||
|
||||
`link` uses the same basic strategy.
|
||||
|
||||
#### readdir ####
|
||||
|
||||
[readdir](http://linux.die.net/man/3/readdir) is different from all other filesystem functions. 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 files 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.
|
||||
|
||||
#### 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 mount points on the same drive will not result in double counting it's space. It is possible due to a race condition that the same drive could be double counted but it's rather unlikely.
|
||||
|
||||
# BUILDING
|
||||
|
||||
**NOTE:** Prebuilt packages can be found at: https://github.com/trapexit/mergerfs/releases
|
||||
|
||||
First get the code from [github](http://github.com/trapexit/mergerfs).
|
||||
|
||||
```
|
||||
$ mergerfs -o create=epmfs,search=ff,action=ff,statfs=sumf <mountpoint> <dir0>:<dir1>:<dir2>
|
||||
$ git clone https://github.com/trapexit/mergerfs.git
|
||||
$ # or
|
||||
$ wget https://github.com/trapexit/mergerfs/archive/master.zip
|
||||
```
|
||||
|
||||
| Option | Values | Default |
|
||||
|--------|--------|---------|
|
||||
| search | ff, ffwp, newest | ff |
|
||||
| action | ff, ffwp, newest, all | ff |
|
||||
| create | ep, mfs, epmfs, rand | epmfs |
|
||||
| statfs | sumf, susf | sumf |
|
||||
|
||||
Building
|
||||
========
|
||||
|
||||
Need to install FUSE development libraries.
|
||||
|
||||
|
||||
#### Debian / Ubuntu
|
||||
```
|
||||
[trapexit:~/dev/mergerfs] $ make help
|
||||
usage: make
|
||||
make WITHOUT_XATTR=1 - to build program without xattrs functionality
|
||||
$ 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
|
||||
```
|
||||
|
||||
Runtime Settings
|
||||
================
|
||||
#### Fedora
|
||||
```
|
||||
$ su -
|
||||
# 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
|
||||
```
|
||||
|
||||
#### Generically
|
||||
|
||||
Have git, python, pkg-config, pandoc, libfuse, libattr1 installed.
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
$ make
|
||||
$ make man
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
# RUNTIME
|
||||
|
||||
#### .mergerfs pseudo file ####
|
||||
```
|
||||
<mountpoint>/.mergerfs
|
||||
```
|
||||
|
||||
There is a pseudo file available at the mountpoint which currently allows for the runtime modification of policies. The file will not show up in readdirs but can be stat'ed, read, and writen. Most other calls will fail with EPERM, EINVAL, or whatever may be appropriate for that call. Anything not understood while writing will result in EINVAL otherwise the number of bytes written will be returned.
|
||||
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.
|
||||
|
||||
Reading the file will result in a newline delimited list of current settings as followed:
|
||||
Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
|
||||
|
||||
##### Keys #####
|
||||
|
||||
Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
|
||||
|
||||
##### Example #####
|
||||
|
||||
```
|
||||
[trapexit:/tmp/mount] $ cat .mergerfs
|
||||
action=ff
|
||||
create=epmfs
|
||||
search=ff
|
||||
statfs=sumf
|
||||
[trapexit:/tmp/mount] $ xattr -l .mergerfs
|
||||
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 -p user.mergerfs.category.search .mergerfs
|
||||
ffwp
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts =/tmp/c .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/c
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts '+</tmp/a:/tmp/b' .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
```
|
||||
|
||||
Writing to the file is buffered and waits till a newline to process. Meaning echo works well.
|
||||
##### 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 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.
|
||||
|
||||
#### mergerfs file 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 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 getattr policy
|
||||
* **user.mergerfs.allpaths:** a NUL ('\0') separated list of full paths to all files found
|
||||
|
||||
```
|
||||
[trapexit:/tmp/mount] $ echo "search=newest" >> .mergerfs
|
||||
[trapexit:/tmp/mount] $ cat .mergerfs
|
||||
action=ff
|
||||
create=epmfs
|
||||
search=newest
|
||||
statfs=sumf
|
||||
[trapexit:/tmp/mount] $ ls
|
||||
A B C
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.fullpath A
|
||||
/mnt/a/full/path/to/A
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.basepath A
|
||||
/mnt/a
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.relpath A
|
||||
/full/path/to/A
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.allpaths A | tr '\0' '\n'
|
||||
/mnt/a/full/path/to/A
|
||||
/mnt/b/full/path/to/A
|
||||
```
|
||||
|
||||
*NOTE:* offset is not supported and ignored in both read and write. There is also a safety check which limits buffered + incoming length to a max of 1024 bytes.
|
||||
# TOOLING
|
||||
|
||||
Find extra tooling to help with managing `mergerfs` at: https://github.com/trapexit/mergerfs-tools
|
||||
|
||||
* fsck.mergerfs: Provides permissions and ownership auditing and the ability to fix them
|
||||
|
||||
# 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`. Use `fsck.mergerfs` to audit the drive for out of sync permissions.
|
||||
* 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.
|
||||
* 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.
|
||||
* If write performance is valued more than read it may be useful to enable **direct_io**. Best to benchmark with and without and choose appropriately.
|
||||
* Remember: 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 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 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).
|
||||
|
||||
# Known Issues / Bugs
|
||||
|
||||
#### Samba
|
||||
* Moving files or directories between some directories on a SMB share fail with IO errors.
|
||||
|
||||
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 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 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.
|
||||
|
||||
The gid cache uses fixed storage to simplify the design and be compatible with older systems which may not have C++11 compilers (as the original design required). 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.
|
||||
|
||||
# FAQ
|
||||
|
||||
*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) 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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
> 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).
|
||||
|
||||
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).
|
||||
|
||||
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.
|
||||
|
||||
# SUPPORT
|
||||
|
||||
#### Issues with the software
|
||||
* github.com: https://github.com/trapexit/mergerfs/issues
|
||||
* email: trapexit@spawn.link
|
||||
|
||||
#### Support development
|
||||
* Gratipay: https://gratipay.com/~trapexit
|
||||
* BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
* logging
|
||||
* dynamic changing of source mounts
|
||||
* policies for readdir
|
||||
* first found
|
||||
* all found
|
||||
* all found w/ permission
|
||||
* newest
|
||||
* unit tests
|
||||
* add more to ioctl
|
||||
* use {list,set}xattr for setting runtime values via .mergerfs pseudofile
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
9
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
Source: mergerfs
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Maintainer: Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Build-Depends: debhelper (>= 8.0.0),
|
||||
libfuse-dev,
|
||||
libattr1-dev,
|
||||
pkg-config
|
||||
Standards-Version: 3.9.4
|
||||
Homepage: http://github.com/trapexit/mergerfs
|
||||
|
||||
Package: mergerfs
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
libfuse2
|
||||
Description: another FUSE union filesystem
|
||||
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.
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: mergerfs-1.1.0
|
||||
Source: http://github.com/trapexit/mergerfs
|
||||
|
||||
Files: *
|
||||
Copyright: 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
License: ISC
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
License: ISC
|
||||
|
||||
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
@@ -0,0 +1 @@
|
||||
README.md
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/make -f
|
||||
# -*- makefile -*-
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
||||
override_dh_auto_install:
|
||||
$(MAKE) DESTDIR=$(CURDIR)/debian/mergerfs PREFIX=/usr install
|
||||
+828
@@ -0,0 +1,828 @@
|
||||
.\"t
|
||||
.TH "mergerfs" "1" "2016\-01\-21" "mergerfs user manual" ""
|
||||
.SH NAME
|
||||
.PP
|
||||
mergerfs \- another (FUSE based) union filesystem
|
||||
.SH SYNOPSIS
|
||||
.PP
|
||||
mergerfs \-o<options> <srcmounts> <mountpoint>
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
\f[B]mergerfs\f[] is a union filesystem geared towards simplifing
|
||||
storage and management of files across numerous commodity storage
|
||||
devices.
|
||||
It is similar to \f[B]mhddfs\f[], \f[B]unionfs\f[], and \f[B]aufs\f[].
|
||||
.SH FEATURES
|
||||
.IP \[bu] 2
|
||||
Runs in userspace (FUSE)
|
||||
.IP \[bu] 2
|
||||
Configurable behaviors
|
||||
.IP \[bu] 2
|
||||
Support for extended attributes (xattrs)
|
||||
.IP \[bu] 2
|
||||
Support for file attributes (chattr)
|
||||
.IP \[bu] 2
|
||||
Runtime configurable (via xattrs)
|
||||
.IP \[bu] 2
|
||||
Safe to run as root
|
||||
.IP \[bu] 2
|
||||
Opportunistic credential caching
|
||||
.IP \[bu] 2
|
||||
Works with heterogeneous filesystem types
|
||||
.IP \[bu] 2
|
||||
Handling of writes to full drives
|
||||
.SH OPTIONS
|
||||
.SS options
|
||||
.IP \[bu] 2
|
||||
\f[B]defaults\f[]: a shortcut for FUSE\[aq]s \f[B]atomic_o_trunc\f[],
|
||||
\f[B]auto_cache\f[], \f[B]big_writes\f[], \f[B]default_permissions\f[],
|
||||
\f[B]splice_move\f[], \f[B]splice_read\f[], and \f[B]splice_write\f[].
|
||||
These options seem to provide the best performance.
|
||||
.IP \[bu] 2
|
||||
\f[B]direct_io\f[]: causes FUSE to bypass an addition caching step which
|
||||
can increase write speeds at the detriment of read speed.
|
||||
.IP \[bu] 2
|
||||
\f[B]minfreespace\f[]: the minimum space value used for the
|
||||
\f[B]lfs\f[], \f[B]fwfs\f[], and \f[B]epmfs\f[] policies.
|
||||
Understands \[aq]K\[aq], \[aq]M\[aq], and \[aq]G\[aq] to represent
|
||||
kilobyte, megabyte, and gigabyte respectively.
|
||||
(default: 4G)
|
||||
.IP \[bu] 2
|
||||
\f[B]moveonenospc\f[]: when enabled (set to \f[B]true\f[]) if a
|
||||
\f[B]write\f[] fails with \f[B]ENOSPC\f[] 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)
|
||||
.IP \[bu] 2
|
||||
\f[B]func.<func>=<policy>\f[]: sets the specific FUSE function\[aq]s
|
||||
policy.
|
||||
See below for the list of value types.
|
||||
Example: \f[B]func.getattr=newest\f[]
|
||||
.IP \[bu] 2
|
||||
\f[B]category.<category>=<policy>\f[]: Sets policy of all FUSE functions
|
||||
in the provided category.
|
||||
Example: \f[B]category.create=mfs\f[]
|
||||
.PP
|
||||
\f[B]NOTE:\f[] Options are evaluated in the order listed so if the
|
||||
options are \f[B]func.rmdir=rand,category.action=ff\f[] the
|
||||
\f[B]action\f[] category setting will override the \f[B]rmdir\f[]
|
||||
setting.
|
||||
.SS srcmounts
|
||||
.PP
|
||||
The source mounts argument is a colon (\[aq]:\[aq]) delimited list of
|
||||
paths.
|
||||
To make it simpler to include multiple source mounts without having to
|
||||
modify your fstab (http://linux.die.net/man/5/fstab) we also support
|
||||
globbing (http://linux.die.net/man/7/glob).
|
||||
\f[B]The globbing tokens MUST be escaped when using via the shell else
|
||||
the shell itself will probably expand it.\f[]
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$\ mergerfs\ /mnt/disk\\*:/mnt/cdrom\ /media/drives
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
The above line will use all mount points in /mnt prefixed with
|
||||
\f[I]disk\f[] and the directory \f[I]cdrom\f[].
|
||||
.PP
|
||||
In /etc/fstab it\[aq]d look like the following:
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
#\ <file\ system>\ \ \ \ \ \ \ \ <mount\ point>\ \ <type>\ \ \ \ \ \ \ \ \ <options>\ \ \ \ \ \ \ \ \ \ \ \ \ <dump>\ \ <pass>
|
||||
/mnt/disk*:/mnt/cdrom\ \ /media/drives\ \ fuse.mergerfs\ \ defaults,allow_other\ \ 0\ \ \ \ \ \ \ 0
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
\f[B]NOTE:\f[] 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.
|
||||
.SH POLICIES
|
||||
.PP
|
||||
Filesystem calls are broken up into 3 categories: \f[B]action\f[],
|
||||
\f[B]create\f[], \f[B]search\f[].
|
||||
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
|
||||
\f[B]mergerfs\f[] behaves.
|
||||
Any policy can be assigned to a category though some aren\[aq]t terribly
|
||||
practical.
|
||||
For instance: \f[B]rand\f[] (Random) may be useful for \f[B]create\f[]
|
||||
but could lead to very odd behavior if used for \f[B]search\f[].
|
||||
.SS Functional classifications
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
l l.
|
||||
T{
|
||||
Category
|
||||
T}@T{
|
||||
FUSE Functions
|
||||
T}
|
||||
_
|
||||
T{
|
||||
action
|
||||
T}@T{
|
||||
chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate,
|
||||
unlink, utimens
|
||||
T}
|
||||
T{
|
||||
create
|
||||
T}@T{
|
||||
create, mkdir, mknod, symlink
|
||||
T}
|
||||
T{
|
||||
search
|
||||
T}@T{
|
||||
access, getattr, getxattr, ioctl, listxattr, open, readlink
|
||||
T}
|
||||
T{
|
||||
N/A
|
||||
T}@T{
|
||||
fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, release,
|
||||
statfs, write
|
||||
T}
|
||||
.TE
|
||||
.PP
|
||||
\f[B]ioctl\f[] behaves differently if its acting on a directory.
|
||||
It\[aq]ll use the \f[B]getattr\f[] policy to find and open the directory
|
||||
before issuing the \f[B]ioctl\f[].
|
||||
In other cases where something may be searched (to confirm a directory
|
||||
exists across all source mounts) then \f[B]getattr\f[] will be used.
|
||||
.SS Policy descriptions
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
l l.
|
||||
T{
|
||||
Policy
|
||||
T}@T{
|
||||
Description
|
||||
T}
|
||||
_
|
||||
T{
|
||||
ff (first found)
|
||||
T}@T{
|
||||
Given the order of the drives act on the first one found (regardless if
|
||||
stat would return EACCES).
|
||||
T}
|
||||
T{
|
||||
ffwp (first found w/ permissions)
|
||||
T}@T{
|
||||
Given the order of the drives act on the first one found which you have
|
||||
access (stat does not error with EACCES).
|
||||
T}
|
||||
T{
|
||||
newest (newest file)
|
||||
T}@T{
|
||||
If multiple files exist return the one with the most recent mtime.
|
||||
T}
|
||||
T{
|
||||
mfs (most free space)
|
||||
T}@T{
|
||||
Use the drive with the most free space available.
|
||||
T}
|
||||
T{
|
||||
epmfs (existing path, most free space)
|
||||
T}@T{
|
||||
If the path exists on multiple drives use the one with the most free
|
||||
space and is greater than \f[B]minfreespace\f[].
|
||||
If no drive has at least \f[B]minfreespace\f[] then fallback to
|
||||
\f[B]mfs\f[].
|
||||
T}
|
||||
T{
|
||||
fwfs (first with free space)
|
||||
T}@T{
|
||||
Pick the first drive which has at least \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
lfs (least free space)
|
||||
T}@T{
|
||||
Pick the drive with least available space but more than
|
||||
\f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
rand (random)
|
||||
T}@T{
|
||||
Pick an existing drive at random.
|
||||
T}
|
||||
T{
|
||||
all
|
||||
T}@T{
|
||||
Applies action to all found.
|
||||
For searches it will behave like first found \f[B]ff\f[].
|
||||
T}
|
||||
T{
|
||||
enosys, einval, enotsup, exdev, erofs
|
||||
T}@T{
|
||||
Exclusively return \f[C]\-1\f[] with \f[C]errno\f[] set to the
|
||||
respective value.
|
||||
Useful for debugging other applications\[aq] behavior to errors.
|
||||
T}
|
||||
.TE
|
||||
.SS Defaults
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
l l.
|
||||
T{
|
||||
Category
|
||||
T}@T{
|
||||
Policy
|
||||
T}
|
||||
_
|
||||
T{
|
||||
action
|
||||
T}@T{
|
||||
all
|
||||
T}
|
||||
T{
|
||||
create
|
||||
T}@T{
|
||||
epmfs
|
||||
T}
|
||||
T{
|
||||
search
|
||||
T}@T{
|
||||
ff
|
||||
T}
|
||||
.TE
|
||||
.SS rename & link
|
||||
.PP
|
||||
rename (http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky
|
||||
function in a merged system.
|
||||
Normally if a rename can\[aq]t be done atomically due to the source and
|
||||
destination paths existing on different mount points it will return
|
||||
\f[C]\-1\f[] with \f[C]errno\ =\ EXDEV\f[].
|
||||
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.
|
||||
This can lead to several undesirable situtations with or without errors
|
||||
and it\[aq]s not entirely obvious what to do when an error occurs.
|
||||
.PP
|
||||
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 they only partially support EXDEV (don\[aq]t respond the
|
||||
same as \f[C]mv\f[] would).
|
||||
Such apps include: gvfsd\-fuse v1.20.3 and prior, Finder / CIFS/SMB
|
||||
client in Apple OSX 10.9+, NZBGet, Samba\[aq]s recycling bin feature.
|
||||
.IP \[bu] 2
|
||||
If using a policy which tries to preserve directories (epmfs)
|
||||
.IP \[bu] 2
|
||||
Using the \f[C]rename\f[] policy get the list of files to rename
|
||||
.IP \[bu] 2
|
||||
For each file attempt rename:
|
||||
.RS 2
|
||||
.IP \[bu] 2
|
||||
If failure with ENOENT run \f[C]create\f[] policy
|
||||
.IP \[bu] 2
|
||||
If create policy returns the same drive as currently evaluating then
|
||||
clone the path
|
||||
.IP \[bu] 2
|
||||
Re\-attempt rename
|
||||
.RE
|
||||
.IP \[bu] 2
|
||||
If \f[B]any\f[] of the renames succeed the higher level rename is
|
||||
considered a success
|
||||
.IP \[bu] 2
|
||||
If \f[B]no\f[] renames succeed the first error encountered will be
|
||||
returned
|
||||
.IP \[bu] 2
|
||||
On success:
|
||||
.RS 2
|
||||
.IP \[bu] 2
|
||||
Remove the target from all drives with no source file
|
||||
.IP \[bu] 2
|
||||
Remove the source from all drives which failed to rename
|
||||
.RE
|
||||
.IP \[bu] 2
|
||||
If using a policy which does \f[B]not\f[] try to preserve directories
|
||||
.IP \[bu] 2
|
||||
Using the \f[C]rename\f[] policy get the list of files to rename
|
||||
.IP \[bu] 2
|
||||
Using the \f[C]getattr\f[] policy get the target path
|
||||
.IP \[bu] 2
|
||||
For each file attempt rename:
|
||||
.RS 2
|
||||
.IP \[bu] 2
|
||||
If the source drive != target drive:
|
||||
.IP \[bu] 2
|
||||
Clone target path from target drive to source drive
|
||||
.IP \[bu] 2
|
||||
Rename
|
||||
.RE
|
||||
.IP \[bu] 2
|
||||
If \f[B]any\f[] of the renames succeed the higher level rename is
|
||||
considered a success
|
||||
.IP \[bu] 2
|
||||
If \f[B]no\f[] renames succeed the first error encountered will be
|
||||
returned
|
||||
.IP \[bu] 2
|
||||
On success:
|
||||
.RS 2
|
||||
.IP \[bu] 2
|
||||
Remove the target from all drives with no source file
|
||||
.IP \[bu] 2
|
||||
Remove the source from all drives which failed to rename
|
||||
.RE
|
||||
.PP
|
||||
The the removals are subject to normal entitlement checks.
|
||||
.PP
|
||||
The above behavior will help minimize the likelihood of EXDEV being
|
||||
returned but it will still be possible.
|
||||
To remove the possibility all together mergerfs would need to perform
|
||||
the as \f[C]mv\f[] does when it receives EXDEV normally.
|
||||
.PP
|
||||
\f[C]link\f[] uses the same basic strategy.
|
||||
.SS readdir
|
||||
.PP
|
||||
readdir (http://linux.die.net/man/3/readdir) is different from all other
|
||||
filesystem functions.
|
||||
It certainly could have it\[aq]s own set of policies to tweak its
|
||||
behavior.
|
||||
At this time it provides a simple \f[B]first found\f[] merging of
|
||||
directories and files 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 \f[B]getattr\f[].
|
||||
.PP
|
||||
It could be extended to offer the ability to see all files found.
|
||||
Perhaps concatenating \f[B]#\f[] and a number to the name.
|
||||
But to really be useful you\[aq]d need to be able to access them which
|
||||
would complicate file lookup.
|
||||
.SS statvfs
|
||||
.PP
|
||||
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 mount
|
||||
points on the same drive will not result in double counting it\[aq]s
|
||||
space.
|
||||
It is possible due to a race condition that the same drive could be
|
||||
double counted but it\[aq]s rather unlikely.
|
||||
.SH BUILDING
|
||||
.PP
|
||||
\f[B]NOTE:\f[] Prebuilt packages can be found at:
|
||||
https://github.com/trapexit/mergerfs/releases
|
||||
.PP
|
||||
First get the code from github (http://github.com/trapexit/mergerfs).
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$\ git\ clone\ https://github.com/trapexit/mergerfs.git
|
||||
$\ #\ or
|
||||
$\ wget\ https://github.com/trapexit/mergerfs/archive/master.zip
|
||||
\f[]
|
||||
.fi
|
||||
.SS Debian / Ubuntu
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$\ 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
|
||||
\f[]
|
||||
.fi
|
||||
.SS Fedora
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$\ su\ \-
|
||||
#\ 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
|
||||
\f[]
|
||||
.fi
|
||||
.SS Generically
|
||||
.PP
|
||||
Have git, python, pkg\-config, pandoc, libfuse, libattr1 installed.
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$\ cd\ mergerfs
|
||||
$\ make
|
||||
$\ make\ man
|
||||
$\ sudo\ make\ install
|
||||
\f[]
|
||||
.fi
|
||||
.SH RUNTIME
|
||||
.SS \&.mergerfs pseudo file
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
<mountpoint>/.mergerfs
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
There is a pseudo file available at the mount point which allows for the
|
||||
runtime modification of certain \f[B]mergerfs\f[] options.
|
||||
The file will not show up in \f[B]readdir\f[] but can be
|
||||
\f[B]stat\f[]\[aq]ed and manipulated via
|
||||
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls.
|
||||
.PP
|
||||
Even if xattrs are disabled the
|
||||
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls will
|
||||
still work.
|
||||
.SS Keys
|
||||
.PP
|
||||
Use \f[C]xattr\ \-l\ /mount/point/.mergerfs\f[] to see all supported
|
||||
keys.
|
||||
.SS Example
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-l\ .mergerfs
|
||||
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\ \-p\ user.mergerfs.category.search\ .mergerfs
|
||||
ffwp
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ +/tmp/c\ .mergerfs
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ =/tmp/c\ .mergerfs
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
|
||||
/tmp/c
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ \[aq]+</tmp/a:/tmp/b\[aq]\ .mergerfs
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
\f[]
|
||||
.fi
|
||||
.SS user.mergerfs.srcmounts
|
||||
.PP
|
||||
For \f[B]user.mergerfs.srcmounts\f[] there are several instructions
|
||||
available for manipulating the list.
|
||||
The value provided is just as the value used at mount time.
|
||||
A colon (\[aq]:\[aq]) delimited list of full path globs.
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
l l.
|
||||
T{
|
||||
Instruction
|
||||
T}@T{
|
||||
Description
|
||||
T}
|
||||
_
|
||||
T{
|
||||
[list]
|
||||
T}@T{
|
||||
set
|
||||
T}
|
||||
T{
|
||||
+<[list]
|
||||
T}@T{
|
||||
prepend
|
||||
T}
|
||||
T{
|
||||
+>[list]
|
||||
T}@T{
|
||||
append
|
||||
T}
|
||||
T{
|
||||
\-[list]
|
||||
T}@T{
|
||||
remove all values provided
|
||||
T}
|
||||
T{
|
||||
\-<
|
||||
T}@T{
|
||||
remove first in list
|
||||
T}
|
||||
T{
|
||||
\->
|
||||
T}@T{
|
||||
remove last in list
|
||||
T}
|
||||
.TE
|
||||
.SS minfreespace
|
||||
.PP
|
||||
Input: interger with an optional multiplier suffix.
|
||||
\f[B]K\f[], \f[B]M\f[], or \f[B]G\f[].
|
||||
.PP
|
||||
Output: value in bytes
|
||||
.SS moveonenospc
|
||||
.PP
|
||||
Input: \f[B]true\f[] and \f[B]false\f[]
|
||||
.PP
|
||||
Ouput: \f[B]true\f[] or \f[B]false\f[]
|
||||
.SS categories / funcs
|
||||
.PP
|
||||
Input: short policy string as described elsewhere in this document
|
||||
.PP
|
||||
Output: the policy string except for categories where its funcs have
|
||||
multiple types.
|
||||
In that case it will be a comma separated list.
|
||||
.SS mergerfs file xattrs
|
||||
.PP
|
||||
While they won\[aq]t show up when using
|
||||
listxattr (http://linux.die.net/man/2/listxattr) \f[B]mergerfs\f[]
|
||||
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:
|
||||
.IP \[bu] 2
|
||||
\f[B]user.mergerfs.basepath:\f[] the base mount point for the file given
|
||||
the current getattr policy
|
||||
.IP \[bu] 2
|
||||
\f[B]user.mergerfs.relpath:\f[] the relative path of the file from the
|
||||
perspective of the mount point
|
||||
.IP \[bu] 2
|
||||
\f[B]user.mergerfs.fullpath:\f[] the full path of the original file
|
||||
given the getattr policy
|
||||
.IP \[bu] 2
|
||||
\f[B]user.mergerfs.allpaths:\f[] a NUL (\[aq]\[aq]) separated list of
|
||||
full paths to all files found
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
[trapexit:/tmp/mount]\ $\ ls
|
||||
A\ B\ C
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.fullpath\ A
|
||||
/mnt/a/full/path/to/A
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.basepath\ A
|
||||
/mnt/a
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.relpath\ A
|
||||
/full/path/to/A
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.allpaths\ A\ |\ tr\ \[aq]\\0\[aq]\ \[aq]\\n\[aq]
|
||||
/mnt/a/full/path/to/A
|
||||
/mnt/b/full/path/to/A
|
||||
\f[]
|
||||
.fi
|
||||
.SH TOOLING
|
||||
.PP
|
||||
Find extra tooling to help with managing \f[C]mergerfs\f[] at:
|
||||
https://github.com/trapexit/mergerfs\-tools
|
||||
.IP \[bu] 2
|
||||
fsck.mergerfs: Provides permissions and ownership auditing and the
|
||||
ability to fix them
|
||||
.SH TIPS / NOTES
|
||||
.IP \[bu] 2
|
||||
If you don\[aq]t see some directories / files you expect in a merged
|
||||
point be sure the user has permission to all the underlying directories.
|
||||
If \f[C]/drive0/a\f[] has is owned by \f[C]root:root\f[] with ACLs set
|
||||
to \f[C]0700\f[] and \f[C]/drive1/a\f[] is \f[C]root:root\f[] and
|
||||
\f[C]0755\f[] you\[aq]ll see only \f[C]/drive1/a\f[].
|
||||
Use \f[C]fsck.mergerfs\f[] to audit the drive for out of sync
|
||||
permissions.
|
||||
.IP \[bu] 2
|
||||
Since POSIX gives you only error or success on calls its difficult to
|
||||
determine the proper behavior when applying the behavior to multiple
|
||||
targets.
|
||||
\f[B]mergerfs\f[] will return an error only if all attempts of an action
|
||||
fail.
|
||||
Any success will lead to a success returned.
|
||||
.IP \[bu] 2
|
||||
The recommended options are \f[B]defaults,allow_other\f[].
|
||||
The \f[B]allow_other\f[] is to allow users who are not the one which
|
||||
executed mergerfs access to the mountpoint.
|
||||
\f[B]defaults\f[] is described above and should offer the best
|
||||
performance.
|
||||
It\[aq]s possible that if you\[aq]re running on an older platform the
|
||||
\f[B]splice\f[] features aren\[aq]t available and could error.
|
||||
In that case simply use the other options manually.
|
||||
.IP \[bu] 2
|
||||
If write performance is valued more than read it may be useful to enable
|
||||
\f[B]direct_io\f[].
|
||||
Best to benchmark with and without and choose appropriately.
|
||||
.IP \[bu] 2
|
||||
Remember: some policies mixed with some functions may result in strange
|
||||
behaviors.
|
||||
Not that some of these behaviors and race conditions couldn\[aq]t happen
|
||||
outside \f[B]mergerfs\f[] 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.
|
||||
.IP \[bu] 2
|
||||
An example: Kodi (http://kodi.tv) and Plex (http://plex.tv) 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 current default \f[B]getattr\f[] policy of \f[B]ff\f[] its
|
||||
possible \f[B]Kodi\f[] will miss an update on account of it returning
|
||||
the first directory found\[aq]s \f[B]stat\f[] info and its a later
|
||||
directory on another mount which had the \f[B]mtime\f[] recently
|
||||
updated.
|
||||
To fix this you will want to set \f[B]func.getattr=newest\f[].
|
||||
Remember though that this is just \f[B]stat\f[].
|
||||
If the file is later \f[B]open\f[]\[aq]ed or \f[B]unlink\f[]\[aq]ed and
|
||||
the policy is different for those then a completely different file or
|
||||
directory could be acted on.
|
||||
.IP \[bu] 2
|
||||
Due to previously mentioned issues its generally best to set
|
||||
\f[B]category\f[] wide policies rather than individual
|
||||
\f[B]func\f[]\[aq]s.
|
||||
This will help limit the confusion of tools such as
|
||||
rsync (http://linux.die.net/man/1/rsync).
|
||||
.SH Known Issues / Bugs
|
||||
.SS Samba
|
||||
.IP \[bu] 2
|
||||
Moving files or directories between some directories on a SMB share fail
|
||||
with IO errors.
|
||||
.RS 2
|
||||
.PP
|
||||
Workaround: Copy the file/directory and then remove the original rather
|
||||
than move.
|
||||
.PP
|
||||
This isn\[aq]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 \f[B]STATUS_NOT_SAME_DEVICE\f[] which comes from the
|
||||
\f[B]EXDEV\f[] which is returned by \f[B]rename\f[] when the call is
|
||||
crossing mount points.
|
||||
When a program gets an \f[B]EXDEV\f[] it needs to explicitly take an
|
||||
alternate action to accomplish it\[aq]s goal.
|
||||
In the case of \f[B]mv\f[] or similar it tries \f[B]rename\f[] and on
|
||||
\f[B]EXDEV\f[] 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 \f[B]EXDEV\f[] it
|
||||
would translate that into \f[B]EIO\f[].
|
||||
This would cause \f[B]mv\f[] or most any application attempting to move
|
||||
files around on that SMB share to fail with a IO error.
|
||||
.PP
|
||||
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
|
||||
\f[C]apt\-cache\ showpkg\ gvfs\-fuse\f[].
|
||||
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.
|
||||
.PP
|
||||
In Apple\[aq]s MacOSX 10.9 they replaced Samba (client and server) with
|
||||
their own product.
|
||||
It appears their new client does not handle \f[B]EXDEV\f[] either and
|
||||
responds similar to older release of gvfs on Linux.
|
||||
.RE
|
||||
.SS Supplemental groups
|
||||
.IP \[bu] 2
|
||||
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 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\[aq]s (at least the standard
|
||||
version) thread pool dynamically grows and shrinks it\[aq]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.
|
||||
.RS 2
|
||||
.PP
|
||||
The gid cache uses fixed storage to simplify the design and be
|
||||
compatible with older systems which may not have C++11 compilers (as the
|
||||
original design required).
|
||||
There is enough storage for 256 users\[aq] 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\[aq]s cache at random.
|
||||
So long as there aren\[aq]t more than 256 active users this should be
|
||||
fine.
|
||||
If either value is too low for your needs you will have to modify
|
||||
\f[C]gidcache.hpp\f[] to increase the values.
|
||||
Note that doing so will increase the memory needed by each thread.
|
||||
.RE
|
||||
.SH FAQ
|
||||
.PP
|
||||
\f[I]It\[aq]s mentioned that there are some security issues with mhddfs.
|
||||
What are they? How does mergerfs address them?\f[]
|
||||
.PP
|
||||
mhddfs (https://github.com/trapexit/mhddfs) tries to handle being run as
|
||||
\f[B]root\f[] by calling
|
||||
getuid() (https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319)
|
||||
and if it returns \f[B]0\f[] then it will
|
||||
chown (http://linux.die.net/man/1/chown) the file.
|
||||
Not only is that a race condition but it doesn\[aq]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.
|
||||
.PP
|
||||
If you are familiar with POSIX standards you\[aq]ll know that this
|
||||
behavior poses a problem.
|
||||
\f[B]seteuid\f[] and \f[B]setegid\f[] affect the whole process and
|
||||
\f[B]libfuse\f[] is multithreaded by default.
|
||||
We\[aq]d need to lock access to \f[B]seteuid\f[] and \f[B]setegid\f[]
|
||||
with a mutex so that the several threads aren\[aq]t stepping on one
|
||||
another and files end up with weird permissions and ownership.
|
||||
This however wouldn\[aq]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.
|
||||
.PP
|
||||
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.
|
||||
.PP
|
||||
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 \f[B]4.00\f[] release of the Linux man\-pages project for
|
||||
setuid (http://man7.org/linux/man-pages/man2/setuid.2.html)
|
||||
.RS
|
||||
.PP
|
||||
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).
|
||||
.RE
|
||||
.PP
|
||||
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 \f[B]Samba\f[] mergerfs uses
|
||||
\f[B]syscall(SYS_setreuid,...)\f[] to set the callers credentials for
|
||||
that thread only.
|
||||
Jumping back to \f[B]root\f[] as necessary should escalated privileges
|
||||
be needed (for instance: to clone paths).
|
||||
.PP
|
||||
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\[aq]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\[aq]t starve.
|
||||
This isn\[aq]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.
|
||||
.SH SUPPORT
|
||||
.SS Issues with the software
|
||||
.IP \[bu] 2
|
||||
github.com: https://github.com/trapexit/mergerfs/issues
|
||||
.IP \[bu] 2
|
||||
email: trapexit\@spawn.link
|
||||
.SS Support development
|
||||
.IP \[bu] 2
|
||||
Gratipay: https://gratipay.com/~trapexit
|
||||
.IP \[bu] 2
|
||||
BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
.SH AUTHORS
|
||||
Antonio SJ Musumeci <trapexit@spawn.link>.
|
||||
@@ -0,0 +1,49 @@
|
||||
Name: mergerfs
|
||||
Version: __VERSION__
|
||||
Release: 1%{?dist}
|
||||
Summary: A FUSE union filesystem
|
||||
|
||||
Group: Applications/System
|
||||
License: ISC
|
||||
URL: https://github.com/trapexit/mergerfs
|
||||
|
||||
Source: mergerfs-%{version}.tar.gz
|
||||
|
||||
BuildRequires: gcc-c++
|
||||
BuildRequires: libattr-devel
|
||||
BuildRequires: fuse-devel
|
||||
# rpmbuild driven by the Makefile uses git to generate a version number
|
||||
BuildRequires: git
|
||||
|
||||
Requires: fuse
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%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.
|
||||
|
||||
%build
|
||||
make %{?_smp_mflags}
|
||||
|
||||
%install
|
||||
make install PREFIX=%{_prefix} DESTDIR=%{buildroot}
|
||||
|
||||
%files
|
||||
%{_bindir}/*
|
||||
%{_sbindir}/*
|
||||
%doc %{_mandir}/*
|
||||
|
||||
%changelog
|
||||
* Sat Sep 05 2015 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
- Include PREFIX to install
|
||||
|
||||
* Mon Dec 29 2014 Joe Lawrence <joe.lawrence@stratus.com>
|
||||
- Tweak rpmbuild to archive current git HEAD into a tarball, then (re)build in
|
||||
the rpmbuild directory -- more complicated but seemingly better suited to
|
||||
generate source and debug rpms.
|
||||
|
||||
* Fri Jun 20 2014 Joe Lawrence <joe.lawrence@stratus.com>
|
||||
- Initial rpm spec file.
|
||||
+32
-42
@@ -1,61 +1,51 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_access(const Policy::Search::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const int mask)
|
||||
_access(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const int mask)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
|
||||
path = searchFunc(srcmounts,fusepath).full;
|
||||
if(path.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fs::path::append(path,fusepath);
|
||||
|
||||
rv = ::eaccess(path.c_str(),mask);
|
||||
|
||||
@@ -64,20 +54,20 @@ _access(const Policy::Search::Func searchFunc,
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace access
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
access(const char *fusepath,
|
||||
int mask)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return 0;
|
||||
|
||||
return _access(config.policy.search,
|
||||
return _access(config.access,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mask);
|
||||
}
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace access
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
access(const char *fusepath,
|
||||
|
||||
+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.
|
||||
*/
|
||||
|
||||
#define STATIC_ASSERT(cond) assert::StaticAssert< (cond) >()
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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 <algorithm>
|
||||
|
||||
template<typename K,typename V>
|
||||
class buildmap
|
||||
{
|
||||
public:
|
||||
buildmap(const K &key,
|
||||
const V &val)
|
||||
{
|
||||
_map.insert(std::make_pair(key,val));
|
||||
}
|
||||
|
||||
buildmap<K,V> &operator()(const K &key,
|
||||
const V &val)
|
||||
{
|
||||
_map.insert(std::make_pair(key,val));
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator std::map<K,V>()
|
||||
{
|
||||
return _map;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<K,V> _map;
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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 <algorithm>
|
||||
|
||||
template<typename V, bool SORT = false>
|
||||
class buildvector
|
||||
{
|
||||
public:
|
||||
buildvector(const V &val)
|
||||
{
|
||||
_vector.push_back(val);
|
||||
}
|
||||
|
||||
buildvector<V,SORT> &operator()(const V &val)
|
||||
{
|
||||
_vector.push_back(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator std::vector<V>()
|
||||
{
|
||||
if(SORT == true)
|
||||
std::sort(_vector.begin(),_vector.end());
|
||||
return _vector;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<V> _vector;
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "category.hpp"
|
||||
#include "buildvector.hpp"
|
||||
|
||||
#define CATEGORY(X) Category(Category::Enum::X,#X)
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
const std::vector<Category> Category::_categories_ =
|
||||
buildvector<Category,true>
|
||||
(CATEGORY(invalid))
|
||||
(CATEGORY(action))
|
||||
(CATEGORY(create))
|
||||
(CATEGORY(search));
|
||||
|
||||
const Category * const Category::categories = &_categories_[1];
|
||||
|
||||
const Category &Category::invalid = Category::categories[Category::Enum::invalid];
|
||||
const Category &Category::action = Category::categories[Category::Enum::action];
|
||||
const Category &Category::create = Category::categories[Category::Enum::create];
|
||||
const Category &Category::search = Category::categories[Category::Enum::search];
|
||||
|
||||
const Category&
|
||||
Category::find(const std::string &str)
|
||||
{
|
||||
for(int i = Enum::BEGIN; i != Enum::END; ++i)
|
||||
{
|
||||
if(categories[i] == str)
|
||||
return categories[i];
|
||||
}
|
||||
|
||||
return invalid;
|
||||
}
|
||||
|
||||
const Category&
|
||||
Category::find(const Category::Enum::Type i)
|
||||
{
|
||||
if(i >= Category::Enum::BEGIN &&
|
||||
i < Category::Enum::END)
|
||||
return categories[i];
|
||||
|
||||
return invalid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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 __CATEGORY_HPP__
|
||||
#define __CATEGORY_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
class Category
|
||||
{
|
||||
public:
|
||||
struct Enum
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
invalid = -1,
|
||||
BEGIN = 0,
|
||||
action = BEGIN,
|
||||
create,
|
||||
search,
|
||||
END
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
Enum::Type _enum;
|
||||
std::string _str;
|
||||
|
||||
public:
|
||||
Category()
|
||||
: _enum(invalid),
|
||||
_str(invalid)
|
||||
{
|
||||
}
|
||||
|
||||
Category(const Enum::Type enum_,
|
||||
const std::string &str_)
|
||||
: _enum(enum_),
|
||||
_str(str_)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
operator const Enum::Type() const { return _enum; }
|
||||
operator const std::string&() const { return _str; }
|
||||
operator const Category*() const { return this; }
|
||||
|
||||
bool operator==(const std::string &str_) const
|
||||
{ return _str == str_; }
|
||||
|
||||
bool operator==(const Enum::Type enum_) const
|
||||
{ return _enum == enum_; }
|
||||
|
||||
bool operator!=(const Category &r) const
|
||||
{ return _enum != r._enum; }
|
||||
|
||||
bool operator<(const Category &r) const
|
||||
{ return _enum < r._enum; }
|
||||
|
||||
public:
|
||||
static const Category &find(const std::string&);
|
||||
static const Category &find(const Enum::Type);
|
||||
|
||||
public:
|
||||
static const std::vector<Category> _categories_;
|
||||
static const Category * const categories;
|
||||
static const Category &invalid;
|
||||
static const Category &action;
|
||||
static const Category &create;
|
||||
static const Category &search;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+39
-45
@@ -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 <fuse.h>
|
||||
@@ -28,10 +20,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -39,48 +32,49 @@ using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_chmod(const Policy::Action::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const mode_t mode)
|
||||
_chmod(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
vector<fs::Path> paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(vector<fs::Path>::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::chmod(i->full.c_str(),mode);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::chmod(paths[i].c_str(),mode);
|
||||
|
||||
error = calc_error(rv,error,errno);
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace chmod
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
chmod(const char *fusepath,
|
||||
mode_t mode)
|
||||
{
|
||||
ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -EPERM;
|
||||
|
||||
return _chmod(config.policy.action,
|
||||
return _chmod(config.chmod,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode);
|
||||
}
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace chmod
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
chmod(const char *fusepath,
|
||||
|
||||
+41
-46
@@ -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 <fuse.h>
|
||||
@@ -29,61 +21,64 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Config;
|
||||
|
||||
static
|
||||
int
|
||||
_chown(const Policy::Action::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const uid_t uid,
|
||||
const gid_t gid)
|
||||
_chown(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
vector<fs::Path> paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(vector<fs::Path>::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::lchown(i->full.c_str(),uid,gid);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::lchown(paths[i].c_str(),uid,gid);
|
||||
|
||||
error = calc_error(rv,error,errno);
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace chown
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
chown(const char *fusepath,
|
||||
uid_t uid,
|
||||
gid_t gid)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -EPERM;
|
||||
|
||||
return _chown(config.policy.action,
|
||||
return _chown(config.chown,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
uid,
|
||||
gid);
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace chown
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
chown(const char *fusepath,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
namespace clonetool
|
||||
{
|
||||
int
|
||||
main(const int argc,
|
||||
char * const *argv);
|
||||
}
|
||||
+91
-68
@@ -1,91 +1,114 @@
|
||||
/*
|
||||
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 <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "fs.hpp"
|
||||
|
||||
#define MINFREESPACE_DEFAULT (4294967295ULL)
|
||||
#define POLICYINIT(X) X(policies[FuseFunc::Enum::X])
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace config
|
||||
Config::Config()
|
||||
: destmount(),
|
||||
srcmounts(),
|
||||
srcmountslock(),
|
||||
minfreespace(MINFREESPACE_DEFAULT),
|
||||
moveonenospc(false),
|
||||
POLICYINIT(access),
|
||||
POLICYINIT(chmod),
|
||||
POLICYINIT(chown),
|
||||
POLICYINIT(create),
|
||||
POLICYINIT(getattr),
|
||||
POLICYINIT(getxattr),
|
||||
POLICYINIT(link),
|
||||
POLICYINIT(listxattr),
|
||||
POLICYINIT(mkdir),
|
||||
POLICYINIT(mknod),
|
||||
POLICYINIT(open),
|
||||
POLICYINIT(readlink),
|
||||
POLICYINIT(removexattr),
|
||||
POLICYINIT(rename),
|
||||
POLICYINIT(rmdir),
|
||||
POLICYINIT(setxattr),
|
||||
POLICYINIT(symlink),
|
||||
POLICYINIT(truncate),
|
||||
POLICYINIT(unlink),
|
||||
POLICYINIT(utimens),
|
||||
controlfile("/.mergerfs")
|
||||
{
|
||||
Config::Config()
|
||||
: controlfile("/.mergerfs"),
|
||||
testmode(false)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
pthread_rwlock_init(&srcmountslock,NULL);
|
||||
|
||||
controlfilestat.st_dev = 0;
|
||||
controlfilestat.st_ino = 0;
|
||||
controlfilestat.st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
controlfilestat.st_nlink = 1;
|
||||
controlfilestat.st_uid = ::getuid();
|
||||
controlfilestat.st_gid = ::getgid();
|
||||
controlfilestat.st_rdev = 0;
|
||||
controlfilestat.st_size = 0;
|
||||
controlfilestat.st_blksize = 1024;
|
||||
controlfilestat.st_blocks = 0;
|
||||
controlfilestat.st_atime = now;
|
||||
controlfilestat.st_mtime = now;
|
||||
controlfilestat.st_ctime = now;
|
||||
}
|
||||
set_category_policy("action","all");
|
||||
set_category_policy("create","epmfs");
|
||||
set_category_policy("search","ff");
|
||||
}
|
||||
|
||||
std::string
|
||||
Config::generateReadStr() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
int
|
||||
Config::set_func_policy(const string &fusefunc_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const FuseFunc *fusefunc;
|
||||
|
||||
ss << "action=" << policy.action.str() << std::endl
|
||||
<< "create=" << policy.create.str() << std::endl
|
||||
<< "search=" << policy.search.str() << std::endl
|
||||
<< "statfs=" << policy.statfs.str() << std::endl;
|
||||
fusefunc = FuseFunc::find(fusefunc_);
|
||||
if(fusefunc == FuseFunc::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
|
||||
void
|
||||
Config::updateReadStr()
|
||||
{
|
||||
readstr = generateReadStr();
|
||||
controlfilestat.st_size = readstr.size();
|
||||
}
|
||||
policies[(FuseFunc::Enum::Type)*fusefunc] = policy;
|
||||
|
||||
const Config&
|
||||
get(void)
|
||||
{
|
||||
return (*((Config*)fuse_get_context()->private_data));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Config&
|
||||
get_writable(void)
|
||||
{
|
||||
return (*((Config*)fuse_get_context()->private_data));
|
||||
}
|
||||
int
|
||||
Config::set_category_policy(const string &category_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const Category *category;
|
||||
|
||||
category = Category::find(category_);
|
||||
if(category == Category::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
|
||||
for(int i = 0; i < FuseFunc::Enum::END; i++)
|
||||
{
|
||||
if(FuseFunc::fusefuncs[i] == (Category::Enum::Type)*category)
|
||||
policies[(FuseFunc::Enum::Type)FuseFunc::fusefuncs[i]] = policy;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+71
-41
@@ -1,64 +1,94 @@
|
||||
/*
|
||||
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__
|
||||
#define __CONFIG_HPP__
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
#include "fusefunc.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace config
|
||||
class Config
|
||||
{
|
||||
class Config
|
||||
public:
|
||||
Config();
|
||||
|
||||
public:
|
||||
int set_func_policy(const std::string &fusefunc_,
|
||||
const std::string &policy_);
|
||||
int set_category_policy(const std::string &category,
|
||||
const std::string &policy);
|
||||
|
||||
public:
|
||||
std::string destmount;
|
||||
std::vector<std::string> srcmounts;
|
||||
mutable pthread_rwlock_t srcmountslock;
|
||||
size_t minfreespace;
|
||||
bool moveonenospc;
|
||||
|
||||
public:
|
||||
const Policy *policies[FuseFunc::Enum::END];
|
||||
const Policy *&access;
|
||||
const Policy *&chmod;
|
||||
const Policy *&chown;
|
||||
const Policy *&create;
|
||||
const Policy *&getattr;
|
||||
const Policy *&getxattr;
|
||||
const Policy *&link;
|
||||
const Policy *&listxattr;
|
||||
const Policy *&mkdir;
|
||||
const Policy *&mknod;
|
||||
const Policy *&open;
|
||||
const Policy *&readlink;
|
||||
const Policy *&removexattr;
|
||||
const Policy *&rename;
|
||||
const Policy *&rmdir;
|
||||
const Policy *&setxattr;
|
||||
const Policy *&symlink;
|
||||
const Policy *&truncate;
|
||||
const Policy *&unlink;
|
||||
const Policy *&utimens;
|
||||
|
||||
public:
|
||||
const std::string controlfile;
|
||||
|
||||
public:
|
||||
static
|
||||
const Config &
|
||||
get(const fuse_context *fc)
|
||||
{
|
||||
public:
|
||||
Config();
|
||||
return *((Config*)fc->private_data);
|
||||
}
|
||||
|
||||
std::string generateReadStr() const;
|
||||
void updateReadStr();
|
||||
|
||||
public:
|
||||
std::string destmount;
|
||||
std::vector<std::string> srcmounts;
|
||||
Policy policy;
|
||||
|
||||
const std::string controlfile;
|
||||
struct stat controlfilestat;
|
||||
std::string readstr;
|
||||
|
||||
bool testmode;
|
||||
};
|
||||
|
||||
const Config &get(void);
|
||||
Config &get_writable(void);
|
||||
}
|
||||
static
|
||||
Config &
|
||||
get_writable(void)
|
||||
{
|
||||
return (*((Config*)fuse_get_context()->private_data));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+57
-66
@@ -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 <fuse.h>
|
||||
@@ -33,83 +25,82 @@
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::FileInfo;
|
||||
using mergerfs::Policy;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_create_controlfile(uint64_t &fh)
|
||||
{
|
||||
fh = (uint64_t)new string;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_create(const Policy::Search::Func searchFunc,
|
||||
const Policy::Create::Func createPathFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const mode_t mode,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
{
|
||||
int fd;
|
||||
string path;
|
||||
int rv;
|
||||
string dirname;
|
||||
fs::Path createpath;
|
||||
fs::Path existingpath;
|
||||
vector<string> createpath;
|
||||
vector<string> existingpath;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
existingpath = searchFunc(srcmounts,dirname);
|
||||
if(existingpath.base.empty())
|
||||
return -ENOENT;
|
||||
dirname = fs::path::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
createpath = createPathFunc(srcmounts,dirname);
|
||||
if(createpath.base != existingpath.base)
|
||||
fs::clonepath(existingpath.base,createpath.base,dirname);
|
||||
rv = createFunc(srcmounts,dirname,minfreespace,createpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
path = fs::make_path(createpath.base,fusepath);
|
||||
if(createpath[0] != existingpath[0])
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
fs::clonepath(existingpath[0],createpath[0],dirname);
|
||||
}
|
||||
|
||||
fd = ::open(path.c_str(),flags,mode);
|
||||
fs::path::append(createpath[0],fusepath);
|
||||
|
||||
fd = ::open(createpath[0].c_str(),flags,mode);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
fh = (uint64_t)new FileInfo(fd,flags,path);
|
||||
fh = reinterpret_cast<uint64_t>(new FileInfo(fd));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace create
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
struct fuse_file_info *fileinfo)
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _create_controlfile(fileinfo->fh);
|
||||
|
||||
return _create(config.policy.search,
|
||||
config.policy.create,
|
||||
return _create(config.getattr,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode,
|
||||
fileinfo->flags,
|
||||
fileinfo->fh);
|
||||
(mode & ~fc->umask),
|
||||
ffi->flags,
|
||||
ffi->fh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -27,11 +19,11 @@
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace create
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
struct fuse_file_info *fileinfo);
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
void
|
||||
destroy(void *)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
void
|
||||
destroy(void *);
|
||||
}
|
||||
}
|
||||
+23
-36
@@ -1,27 +1,21 @@
|
||||
/*
|
||||
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
|
||||
@@ -31,12 +25,8 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "config.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_fallocate(const int fd,
|
||||
@@ -68,26 +58,23 @@ _fallocate(const int fd,
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fallocate
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
struct fuse_file_info *fi)
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const FileInfo *fileinfo = (FileInfo*)fi->fh;
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -EINVAL;
|
||||
|
||||
return _fallocate(fileinfo->fd,
|
||||
return _fallocate(fi->fd,
|
||||
mode,
|
||||
offset,
|
||||
len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+17
-25
@@ -1,36 +1,28 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fallocate
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
struct fuse_file_info *fi);
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_fgetattr(const int fd,
|
||||
struct stat &st)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::fstat(fd,&st);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
fgetattr(const char *fusepath,
|
||||
struct stat *st,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
return _fgetattr(fi->fd,
|
||||
*st);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
fgetattr(const char *fusepath,
|
||||
struct stat *st,
|
||||
fuse_file_info *fileinfo);
|
||||
}
|
||||
}
|
||||
+22
-43
@@ -1,53 +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 __FILEINFO_H__
|
||||
#define __FILEINFO_H__
|
||||
#ifndef __FILEINFO_HPP__
|
||||
#define __FILEINFO_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mergerfs
|
||||
class FileInfo
|
||||
{
|
||||
struct FileInfo
|
||||
public:
|
||||
FileInfo(int _fd) :
|
||||
fd(_fd)
|
||||
{
|
||||
public:
|
||||
FileInfo(int fd_,
|
||||
int flags_,
|
||||
std::string realpath_) :
|
||||
fd(fd_),
|
||||
flags(flags_),
|
||||
realpath(realpath_)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
int fd;
|
||||
int flags;
|
||||
std::string realpath;
|
||||
public:
|
||||
int fd;
|
||||
};
|
||||
|
||||
private:
|
||||
FileInfo() {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __FILEINFO_H__ */
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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 <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_flush(const int fd)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = dup(fd);
|
||||
if(rv == -1)
|
||||
errno = EIO;
|
||||
else
|
||||
rv = close(rv);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
flush(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
return _flush(fi->fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
flush(const char *path,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
+128
-679
@@ -1,724 +1,173 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "xattr.hpp"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
#include "str.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::map;
|
||||
using std::istringstream;
|
||||
|
||||
template<typename Container>
|
||||
Container&
|
||||
split(Container &result,
|
||||
const typename Container::value_type &s,
|
||||
typename Container::value_type::value_type delimiter)
|
||||
{
|
||||
string str;
|
||||
istringstream ss(s);
|
||||
|
||||
while(std::getline(ss,str,delimiter))
|
||||
result.push_back(str);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Iter>
|
||||
Iter
|
||||
random_element(Iter begin,
|
||||
Iter end)
|
||||
{
|
||||
const unsigned long n = std::distance(begin, end);
|
||||
|
||||
std::advance(begin, (std::rand() % n));
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
string
|
||||
dirname(const string path)
|
||||
{
|
||||
string parent = path;
|
||||
string::reverse_iterator i;
|
||||
string::reverse_iterator bi;
|
||||
|
||||
bi = parent.rend();
|
||||
i = parent.rbegin();
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
|
||||
while(*i != '/' && i != bi)
|
||||
i++;
|
||||
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
|
||||
parent.erase(i.base(),parent.end());
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
string
|
||||
basename(const string path)
|
||||
{
|
||||
return path.substr(path.find_last_of('/')+1);
|
||||
}
|
||||
|
||||
bool
|
||||
dir_is_empty(const string path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
|
||||
dir = ::opendir(path.c_str());
|
||||
if(!dir)
|
||||
return false;
|
||||
|
||||
while((de = ::readdir(dir)))
|
||||
{
|
||||
const char *d_name = de->d_name;
|
||||
|
||||
if(d_name[0] == '.' &&
|
||||
((d_name[1] == '\0') ||
|
||||
(d_name[1] == '.' && d_name[2] == '\0')))
|
||||
continue;
|
||||
|
||||
::closedir(dir);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
::closedir(dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string
|
||||
make_path(const string base,
|
||||
const string suffix)
|
||||
{
|
||||
return base + suffix;
|
||||
}
|
||||
|
||||
bool
|
||||
path_exists(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string fusepath)
|
||||
{
|
||||
for(vector<string>::const_iterator
|
||||
iter = begin; iter != end; ++iter)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string path;
|
||||
|
||||
path = make_path(*iter,fusepath);
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
path_exists(const vector<string> &srcmounts,
|
||||
const string fusepath)
|
||||
{
|
||||
return path_exists(srcmounts.begin(),
|
||||
srcmounts.end(),
|
||||
fusepath);
|
||||
}
|
||||
|
||||
Path
|
||||
find_first(vector<string>::const_iterator beginiter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string suffix)
|
||||
{
|
||||
for(vector<string>::const_iterator
|
||||
iter = beginiter; iter != enditer; ++iter)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string path;
|
||||
|
||||
path = fs::make_path(*iter,suffix);
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0 || (rv == -1 && errno == EACCES))
|
||||
return Path(*iter,path);
|
||||
}
|
||||
|
||||
return Path();
|
||||
}
|
||||
|
||||
Path
|
||||
find_first(const vector<string> &basepaths,
|
||||
const string suffix)
|
||||
{
|
||||
return find_first(basepaths.begin(),
|
||||
basepaths.end(),
|
||||
suffix);
|
||||
}
|
||||
|
||||
void
|
||||
find_first(const vector<string> &basepaths,
|
||||
const string suffix,
|
||||
vector<Path> &paths)
|
||||
findallfiles(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
paths.push_back(find_first(basepaths,suffix));
|
||||
}
|
||||
|
||||
Path
|
||||
find_first_with_permission(vector<string>::const_iterator beginiter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string suffix)
|
||||
{
|
||||
for(vector<string>::const_iterator
|
||||
iter = beginiter; iter != enditer; ++iter)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string path;
|
||||
|
||||
path = make_path(*iter,suffix);
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0)
|
||||
return Path(*iter,path);
|
||||
}
|
||||
|
||||
return Path();
|
||||
}
|
||||
|
||||
Path
|
||||
find_first_with_permission(const vector<string> &basepaths,
|
||||
const string suffix)
|
||||
{
|
||||
return find_first_with_permission(basepaths.begin(),
|
||||
basepaths.end(),
|
||||
suffix);
|
||||
}
|
||||
|
||||
void
|
||||
find_first_with_permission(const vector<string> &basepaths,
|
||||
const string suffix,
|
||||
vector<Path> &paths)
|
||||
{
|
||||
paths.push_back(find_first_with_permission(basepaths,suffix));
|
||||
}
|
||||
|
||||
Path
|
||||
find_newest(vector<string>::const_iterator beginiter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string suffix)
|
||||
{
|
||||
time_t newest;
|
||||
string npath;
|
||||
vector<string>::const_iterator niter;
|
||||
|
||||
newest = 0;
|
||||
for(vector<string>::const_iterator
|
||||
iter = beginiter; iter != enditer; ++iter)
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
struct stat st;
|
||||
const string path = make_path(*iter,suffix);
|
||||
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0 && st.st_mtime > newest)
|
||||
{
|
||||
newest = st.st_mtime;
|
||||
niter = iter;
|
||||
npath = path;
|
||||
}
|
||||
}
|
||||
fs::path::make(srcmounts[i],fusepath,fullpath);
|
||||
|
||||
if(newest)
|
||||
return Path(*niter,npath);
|
||||
|
||||
return Path();
|
||||
}
|
||||
|
||||
Path
|
||||
find_newest(const vector<string> &basepaths,
|
||||
const string suffix)
|
||||
{
|
||||
return find_newest(basepaths.begin(),
|
||||
basepaths.end(),
|
||||
suffix);
|
||||
}
|
||||
|
||||
void
|
||||
find_newest(const vector<string> &basepaths,
|
||||
const string suffix,
|
||||
vector<Path> &paths)
|
||||
{
|
||||
paths.push_back(find_newest(basepaths,suffix));
|
||||
}
|
||||
|
||||
void
|
||||
find_all(const vector<string> &basepaths,
|
||||
const string suffix,
|
||||
vector<Path> &paths)
|
||||
{
|
||||
for(vector<string>::const_iterator
|
||||
i = basepaths.begin(), ei = basepaths.end(); i != ei; ++i)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string path;
|
||||
|
||||
path = fs::make_path(*i,suffix);
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0 || (rv == -1 && errno == EACCES))
|
||||
paths.push_back(Path(*i,path));
|
||||
}
|
||||
}
|
||||
|
||||
Path
|
||||
find_mfs(vector<string>::const_iterator iter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string fusepath)
|
||||
{
|
||||
fsblkcnt_t mfs = 0;
|
||||
string mfspath;
|
||||
string fullmfspath;
|
||||
|
||||
for(;iter != enditer; ++iter)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string mountpoint = *iter;
|
||||
|
||||
rv = ::statvfs(mountpoint.c_str(),&fsstats);
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_bsize * fsstats.f_bavail);
|
||||
if(spaceavail > mfs)
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfspath = mountpoint;
|
||||
}
|
||||
}
|
||||
paths.push_back(fullpath);
|
||||
}
|
||||
|
||||
fullmfspath = make_path(mfspath,fusepath);
|
||||
|
||||
return Path(mfspath,fullmfspath);
|
||||
}
|
||||
|
||||
Path
|
||||
find_mfs(const vector<string> &paths,
|
||||
const string fusepath)
|
||||
{
|
||||
return find_mfs(paths.begin(),
|
||||
paths.end(),
|
||||
fusepath);
|
||||
}
|
||||
|
||||
Path
|
||||
find_mfs_existing(vector<string>::const_iterator iter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string fusepath)
|
||||
{
|
||||
fsblkcnt_t existingmfs = 0;
|
||||
fsblkcnt_t generalmfs = 0;
|
||||
string path;
|
||||
string generalmfspath;
|
||||
string existingmfspath;
|
||||
|
||||
do
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string mountpoint = *iter;
|
||||
|
||||
rv = ::statvfs(mountpoint.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
struct stat filestats;
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_bsize * fsstats.f_bavail);
|
||||
if(spaceavail > generalmfs)
|
||||
{
|
||||
generalmfs = spaceavail;
|
||||
generalmfspath = mountpoint;
|
||||
}
|
||||
|
||||
path = make_path(mountpoint,fusepath);
|
||||
rv = ::lstat(path.c_str(),&filestats);
|
||||
if(rv == 0)
|
||||
{
|
||||
if(spaceavail > existingmfs)
|
||||
{
|
||||
existingmfs = spaceavail;
|
||||
existingmfspath = mountpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
while(iter != enditer);
|
||||
|
||||
if(existingmfspath.empty())
|
||||
existingmfspath = generalmfspath;
|
||||
|
||||
return Path(existingmfspath,path);
|
||||
}
|
||||
|
||||
Path
|
||||
find_mfs_existing(const vector<string> &paths,
|
||||
const string fusepath)
|
||||
{
|
||||
return find_mfs_existing(paths.begin(),
|
||||
paths.end(),
|
||||
fusepath);
|
||||
}
|
||||
|
||||
Path
|
||||
find_random(vector<string>::const_iterator iter,
|
||||
vector<string>::const_iterator enditer,
|
||||
string fusepath)
|
||||
{
|
||||
string randombasepath;
|
||||
string randomfullpath;
|
||||
|
||||
randombasepath = *random_element(iter,enditer);
|
||||
randomfullpath = make_path(randombasepath,fusepath);
|
||||
|
||||
return Path(randombasepath,randomfullpath);
|
||||
}
|
||||
|
||||
Path
|
||||
find_random(const vector<string> &paths,
|
||||
const string fusepath)
|
||||
{
|
||||
return find_random(paths.begin(),
|
||||
paths.end(),
|
||||
fusepath);
|
||||
}
|
||||
|
||||
int
|
||||
listxattr(const string path,
|
||||
vector<char> &attrs)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
{
|
||||
size = ::listxattr(path.c_str(),NULL,0);
|
||||
attrs.resize(size);
|
||||
rv = ::listxattr(path.c_str(),&attrs[0],size);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
listxattr(const string path,
|
||||
vector<string> &attrvector)
|
||||
findonfs(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
const int fd,
|
||||
string &basepath)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
string tmppath;
|
||||
unsigned long fsid;
|
||||
struct statvfs buf;
|
||||
|
||||
rv = listxattr(path,attrs);
|
||||
if(rv != -1)
|
||||
{
|
||||
string tmp(attrs.begin(),attrs.end());
|
||||
split(attrvector,tmp,'\0');
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
listxattr(const string path,
|
||||
string &attrstr)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
|
||||
rv = listxattr(path,attrs);
|
||||
if(rv != -1)
|
||||
attrstr = string(attrs.begin(),attrs.end());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
getxattr(const string path,
|
||||
const string attr,
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
{
|
||||
size = ::getxattr(path.c_str(),attr.c_str(),NULL,0);
|
||||
value.resize(size);
|
||||
rv = ::getxattr(path.c_str(),attr.c_str(),&value[0],size);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
getxattr(const string path,
|
||||
const string attr,
|
||||
string &value)
|
||||
{
|
||||
int rv;
|
||||
vector<char> tmpvalue;
|
||||
|
||||
rv = getxattr(path,attr,tmpvalue);
|
||||
if(rv != -1)
|
||||
value = string(tmpvalue.begin(),tmpvalue.end());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
getxattrs(const string path,
|
||||
map<string,string> &attrs)
|
||||
{
|
||||
int rv;
|
||||
string attrstr;
|
||||
|
||||
rv = listxattr(path,attrstr);
|
||||
rv = ::fstatvfs(fd,&buf);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
{
|
||||
string key;
|
||||
istringstream ss(attrstr);
|
||||
fsid = buf.f_fsid;
|
||||
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
fs::path::make(srcmounts[i],fusepath,tmppath);
|
||||
|
||||
while(getline(ss,key,'\0'))
|
||||
{
|
||||
string value;
|
||||
rv = ::statvfs(tmppath.c_str(),&buf);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
rv = getxattr(path,key,value);
|
||||
if(rv != -1)
|
||||
attrs[key] = value;
|
||||
}
|
||||
}
|
||||
if(buf.f_fsid == fsid)
|
||||
{
|
||||
basepath = srcmounts[i];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (errno=ENOENT,-1);
|
||||
}
|
||||
|
||||
void
|
||||
glob(const vector<string> &patterns,
|
||||
vector<string> &strs)
|
||||
{
|
||||
int flags;
|
||||
glob_t gbuf = {0};
|
||||
|
||||
flags = 0;
|
||||
for(size_t i = 0; i < patterns.size(); i++)
|
||||
{
|
||||
glob(patterns[i].c_str(),flags,NULL,&gbuf);
|
||||
flags = GLOB_APPEND;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
|
||||
strs.push_back(gbuf.gl_pathv[i]);
|
||||
|
||||
globfree(&gbuf);
|
||||
}
|
||||
|
||||
void
|
||||
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);
|
||||
if(rv == NULL)
|
||||
continue;
|
||||
|
||||
strs[i] = buf;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
getfl(const int fd)
|
||||
{
|
||||
return ::fcntl(fd,F_GETFL,0);
|
||||
}
|
||||
|
||||
int
|
||||
mfs(const vector<string> &basepaths,
|
||||
const size_t minfreespace,
|
||||
string &path)
|
||||
{
|
||||
fsblkcnt_t mfs;
|
||||
ssize_t mfsidx;
|
||||
|
||||
mfs = 0;
|
||||
mfsidx = -1;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if((spaceavail > mfs) && (spaceavail >= minfreespace))
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfsidx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mfsidx == -1)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
path = basepaths[mfsidx];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
setxattr(const string path,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::setxattr(path.c_str(),
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
setxattr(const int fd,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::fsetxattr(fd,
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
setxattrs(const string path,
|
||||
const map<string,string> &attrs)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = ::open(path.c_str(),O_RDONLY|O_NONBLOCK);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
for(map<string,string>::const_iterator
|
||||
i = attrs.begin(), ei = attrs.end(); i != ei; ++i)
|
||||
{
|
||||
setxattr(fd,i->first,i->second,0);
|
||||
}
|
||||
|
||||
return ::close(fd);
|
||||
}
|
||||
|
||||
int
|
||||
copyxattrs(const string from,
|
||||
const string to)
|
||||
{
|
||||
int rv;
|
||||
map<string,string> attrs;
|
||||
|
||||
rv = getxattrs(from,attrs);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return setxattrs(to,attrs);
|
||||
}
|
||||
|
||||
int
|
||||
copyattr(const string from,
|
||||
const string to)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
int flags;
|
||||
int error;
|
||||
const int openflags = O_RDONLY|O_NONBLOCK;
|
||||
|
||||
fd = ::open(from.c_str(),openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = ::open(to.c_str(),openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ::close(fd);
|
||||
}
|
||||
|
||||
int
|
||||
clonepath(const string fromsrc,
|
||||
const string tosrc,
|
||||
const string relative)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string topath;
|
||||
string frompath;
|
||||
string dirname;
|
||||
|
||||
dirname = fs::dirname(relative);
|
||||
if(!dirname.empty())
|
||||
{
|
||||
rv = clonepath(fromsrc,tosrc,dirname);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
frompath = make_path(fromsrc,relative);
|
||||
|
||||
rv = ::stat(frompath.c_str(),&st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
else if(!S_ISDIR(st.st_mode))
|
||||
return (errno = ENOTDIR,-1);
|
||||
|
||||
topath = make_path(tosrc,relative);
|
||||
rv = ::mkdir(topath.c_str(),st.st_mode);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
// It may not support it... it's fine...
|
||||
rv = copyattr(frompath,topath);
|
||||
if(rv == -1 && errno != ENOTTY)
|
||||
return -1;
|
||||
|
||||
rv = copyxattrs(frompath,topath);
|
||||
if(rv == -1 && errno != ENOTTY)
|
||||
return -1;
|
||||
|
||||
return (errno = 0);
|
||||
}
|
||||
};
|
||||
|
||||
+26
-135
@@ -1,25 +1,17 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FS_HPP__
|
||||
@@ -27,133 +19,32 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
using std::size_t;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
struct Path
|
||||
{
|
||||
Path() {}
|
||||
Path(const string b,
|
||||
const string f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
void findallfiles(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
vector<string> &paths);
|
||||
|
||||
string base;
|
||||
string full;
|
||||
};
|
||||
int findonfs(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
const int fd,
|
||||
string &basepath);
|
||||
|
||||
typedef fs::Path (*SearchFunc)(const vector<string>&,const string);
|
||||
typedef void (*VecSearchFunc)(const vector<string>&,const string,vector<Path>&);
|
||||
void glob(const vector<string> &patterns,
|
||||
vector<string> &strs);
|
||||
|
||||
string dirname(const string path);
|
||||
string basename(const string path);
|
||||
void realpathize(vector<string> &strs);
|
||||
|
||||
bool dir_is_empty(const string path);
|
||||
int getfl(const int fd);
|
||||
|
||||
string make_path(const string base,
|
||||
const string suffix);
|
||||
|
||||
bool path_exists(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string fusepath);
|
||||
bool path_exists(const vector<string> &srcmounts,
|
||||
const string fusepath);
|
||||
|
||||
Path find_first(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string fusepath);
|
||||
Path find_first(const vector<string> &paths,
|
||||
const string fusepath);
|
||||
void find_first(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
vector<Path> &rv);
|
||||
|
||||
Path find_first_with_permission(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string fusepath);
|
||||
Path find_first_with_permission(const vector<string> &paths,
|
||||
const string fusepath);
|
||||
void find_first_with_permission(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
vector<Path> &rv);
|
||||
|
||||
Path find_newest(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string fusepath);
|
||||
Path find_newest(const vector<string> &paths,
|
||||
const string fusepath);
|
||||
void find_newest(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
vector<Path> &rv);
|
||||
|
||||
void find_all(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
vector<Path> &rv);
|
||||
|
||||
Path find_mfs(vector<string>::const_iterator iter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string fusepath);
|
||||
Path find_mfs(const vector<string> &paths,
|
||||
const string fusepath);
|
||||
|
||||
Path find_mfs_existing(vector<string>::const_iterator iter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string fusepath);
|
||||
Path find_mfs_existing(const vector<string> &paths,
|
||||
const string fusepath);
|
||||
|
||||
Path find_random(vector<string>::const_iterator iter,
|
||||
vector<string>::const_iterator enditer,
|
||||
const string fusepath);
|
||||
Path find_random(const vector<string> &paths,
|
||||
const string fusepath);
|
||||
|
||||
|
||||
|
||||
int clonepath(const string srcfrom,
|
||||
const string srcto,
|
||||
const string relative);
|
||||
|
||||
int listxattr(const string path,
|
||||
vector<char> &attrs);
|
||||
int listxattr(const string path,
|
||||
string &attrs);
|
||||
int listxattr(const string path,
|
||||
vector<string> &attrs);
|
||||
|
||||
int getxattr(const string path,
|
||||
const string attr,
|
||||
vector<char> &value);
|
||||
int getxattr(const string path,
|
||||
const string attr,
|
||||
string &value);
|
||||
|
||||
int getxattrs(const string path,
|
||||
map<string,string> &attrs);
|
||||
|
||||
int setxattr(const string path,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags);
|
||||
int setxattr(const int fd,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags);
|
||||
|
||||
int setxattrs(const string path,
|
||||
const map<string,string> &attrs);
|
||||
|
||||
int copyxattrs(const string from,
|
||||
const string to);
|
||||
|
||||
int copyattr(const string from,
|
||||
const string to);
|
||||
int mfs(const vector<string> &srcs,
|
||||
const size_t minfreespace,
|
||||
string &path);
|
||||
};
|
||||
|
||||
#endif // __FS_HPP__
|
||||
|
||||
+127
@@ -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 <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FS_ATTR_HPP__
|
||||
#define __FS_ATTR_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace attr
|
||||
{
|
||||
using std::string;
|
||||
|
||||
int copy(const int fdin,
|
||||
const int fdout);
|
||||
int copy(const string &from,
|
||||
const string &to);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __FS_ATTR_HPP__
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
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 <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 <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
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)
|
||||
{
|
||||
int rv;
|
||||
struct stat stin;
|
||||
|
||||
rv = ::fstat(fdin,&stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = copydata(fdin,fdout,stin.st_size,stin.st_blksize);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::attr::copy(fdin,fdout);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::xattr::copy(fdin,fdout);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = ::fchown(fdout,stin.st_uid,stin.st_gid);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::fchmod(fdout,stin.st_mode);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
struct timespec times[2];
|
||||
times[0] = stin.st_atim;
|
||||
times[1] = stin.st_mtim;
|
||||
rv = ::futimens(fdout,times);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
clonefile(const string &in,
|
||||
const string &out)
|
||||
{
|
||||
int rv;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int error;
|
||||
|
||||
fdin = ::open(in.c_str(),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);
|
||||
if(fdout == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::clonefile(fdin,fdout);
|
||||
error = errno;
|
||||
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
|
||||
errno = error;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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
|
||||
{
|
||||
int clonefile(const int fdin,
|
||||
const int fdout);
|
||||
int clonefile(const std::string &from,
|
||||
const std::string &to);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
|
||||
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)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string topath;
|
||||
string frompath;
|
||||
string dirname;
|
||||
|
||||
dirname = fs::path::dirname(relative);
|
||||
if(!dirname.empty())
|
||||
{
|
||||
rv = clonepath(fromsrc,tosrc,dirname);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path::make(fromsrc,relative,frompath);
|
||||
rv = ::stat(frompath.c_str(),&st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
else if(!S_ISDIR(st.st_mode))
|
||||
return (errno = ENOTDIR,-1);
|
||||
|
||||
fs::path::make(tosrc,relative,topath);
|
||||
rv = ::mkdir(topath.c_str(),st.st_mode);
|
||||
if(rv == -1)
|
||||
{
|
||||
if(errno != EEXIST)
|
||||
return -1;
|
||||
|
||||
rv = ::chmod(topath.c_str(),st.st_mode);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// It may not support it... it's fine...
|
||||
rv = fs::attr::copy(frompath,topath);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::xattr::copy(frompath,topath);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
|
||||
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);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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
|
||||
{
|
||||
int clonepath(const std::string &from,
|
||||
const std::string &to,
|
||||
const std::string &relative);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_clonefile.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
movefile(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const size_t additional_size,
|
||||
int &origfd)
|
||||
{
|
||||
int rv;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int fdin_flags;
|
||||
string fusedir;
|
||||
string fdin_path;
|
||||
string fdout_path;
|
||||
struct stat fdin_st;
|
||||
|
||||
fdin = origfd;
|
||||
|
||||
rv = fstat(fdin,&fdin_st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
fdin_flags = fs::getfl(fdin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::findonfs(basepaths,fusepath,fdin,fdin_path);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
fdin_st.st_size += additional_size;
|
||||
rv = fs::mfs(basepaths,fdin_st.st_size,fdout_path);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
fusedir = fs::path::dirname(fusepath);
|
||||
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);
|
||||
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);
|
||||
if(fdout == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::clonefile(fdin,fdout);
|
||||
if(rv == -1)
|
||||
{
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
::unlink(fdout_path.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ::unlink(fdin_path.c_str());
|
||||
if(rv == -1)
|
||||
{
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
::unlink(fdout_path.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
::close(fdin);
|
||||
::close(origfd);
|
||||
|
||||
origfd = fdout;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FS_MOVEFILE_HPP__
|
||||
#define __FS_MOVEFILE_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
movefile(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const size_t additional_size,
|
||||
int &origfd);
|
||||
}
|
||||
|
||||
#endif
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
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 <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace path
|
||||
{
|
||||
string
|
||||
dirname(const string &path)
|
||||
{
|
||||
string parent = path;
|
||||
string::reverse_iterator i;
|
||||
string::reverse_iterator bi;
|
||||
|
||||
bi = parent.rend();
|
||||
i = parent.rbegin();
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
|
||||
while(*i != '/' && i != bi)
|
||||
i++;
|
||||
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
|
||||
parent.erase(i.base(),parent.end());
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
string
|
||||
basename(const string &path)
|
||||
{
|
||||
return path.substr(path.find_last_of('/')+1);
|
||||
}
|
||||
|
||||
bool
|
||||
is_empty(const string &path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
|
||||
dir = ::opendir(path.c_str());
|
||||
if(!dir)
|
||||
return false;
|
||||
|
||||
while((de = ::readdir(dir)))
|
||||
{
|
||||
const char *d_name = de->d_name;
|
||||
|
||||
if(d_name[0] == '.' &&
|
||||
((d_name[1] == '\0') ||
|
||||
(d_name[1] == '.' && d_name[2] == '\0')))
|
||||
continue;
|
||||
|
||||
::closedir(dir);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
::closedir(dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
exists(const vector<string> &paths,
|
||||
const string &fusepath)
|
||||
{
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
struct stat st;
|
||||
|
||||
fs::path::make(paths[i],fusepath,path);
|
||||
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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_PATH_HPP__
|
||||
#define __FS_PATH_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace path
|
||||
{
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
string dirname(const string &path);
|
||||
string basename(const string &path);
|
||||
|
||||
bool is_empty(const string &path);
|
||||
|
||||
bool exists(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string &fusepath);
|
||||
bool exists(const vector<string> &srcmounts,
|
||||
const string &fusepath);
|
||||
|
||||
inline
|
||||
string
|
||||
make(const string &base,
|
||||
const string &suffix)
|
||||
{
|
||||
return base + suffix;
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
make(const string &base,
|
||||
const string &suffix,
|
||||
string &output)
|
||||
{
|
||||
output = base + suffix;
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
append(string &base,
|
||||
const string &suffix)
|
||||
{
|
||||
base += suffix;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __FS_PATH_HPP__
|
||||
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
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.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
#include "str.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::map;
|
||||
using std::istringstream;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace xattr
|
||||
{
|
||||
int
|
||||
list(const int fd,
|
||||
vector<char> &attrs)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
ssize_t rv;
|
||||
ssize_t size;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
{
|
||||
size = ::flistxattr(fd,NULL,0);
|
||||
attrs.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::flistxattr(fd,&attrs[0],size);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
list(const string &path,
|
||||
vector<char> &attrs)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
{
|
||||
size = ::listxattr(path.c_str(),NULL,0);
|
||||
attrs.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::listxattr(path.c_str(),&attrs[0],size);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
list(const int fd,
|
||||
vector<string> &attrvector)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
|
||||
rv = list(fd,attrs);
|
||||
if(rv != -1)
|
||||
{
|
||||
string tmp(attrs.begin(),attrs.end());
|
||||
str::split(attrvector,tmp,'\0');
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
list(const string &path,
|
||||
vector<string> &attrvector)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
|
||||
rv = list(path,attrs);
|
||||
if(rv != -1)
|
||||
{
|
||||
string tmp(attrs.begin(),attrs.end());
|
||||
str::split(attrvector,tmp,'\0');
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
list(const int fd,
|
||||
string &attrstr)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
|
||||
rv = list(fd,attrs);
|
||||
if(rv != -1)
|
||||
attrstr = string(attrs.begin(),attrs.end());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
list(const string &path,
|
||||
string &attrstr)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
|
||||
rv = list(path,attrs);
|
||||
if(rv != -1)
|
||||
attrstr = string(attrs.begin(),attrs.end());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
get(const int fd,
|
||||
const string &attr,
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
{
|
||||
size = ::fgetxattr(fd,attr.c_str(),NULL,0);
|
||||
value.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::fgetxattr(fd,attr.c_str(),&value[0],size);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
get(const string &path,
|
||||
const string &attr,
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
{
|
||||
size = ::getxattr(path.c_str(),attr.c_str(),NULL,0);
|
||||
value.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::getxattr(path.c_str(),attr.c_str(),&value[0],size);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
get(const int fd,
|
||||
const string &attr,
|
||||
string &value)
|
||||
{
|
||||
int rv;
|
||||
vector<char> tmpvalue;
|
||||
|
||||
rv = get(fd,attr,tmpvalue);
|
||||
if(rv != -1)
|
||||
value = string(tmpvalue.begin(),tmpvalue.end());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
get(const string &path,
|
||||
const string &attr,
|
||||
string &value)
|
||||
{
|
||||
int rv;
|
||||
vector<char> tmpvalue;
|
||||
|
||||
rv = get(path,attr,tmpvalue);
|
||||
if(rv != -1)
|
||||
value = string(tmpvalue.begin(),tmpvalue.end());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
get(const int fd,
|
||||
map<string,string> &attrs)
|
||||
{
|
||||
int rv;
|
||||
string attrstr;
|
||||
|
||||
rv = list(fd,attrstr);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
{
|
||||
string key;
|
||||
istringstream ss(attrstr);
|
||||
|
||||
while(getline(ss,key,'\0'))
|
||||
{
|
||||
string value;
|
||||
|
||||
rv = get(fd,key,value);
|
||||
if(rv != -1)
|
||||
attrs[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
get(const string &path,
|
||||
map<string,string> &attrs)
|
||||
{
|
||||
int rv;
|
||||
string attrstr;
|
||||
|
||||
rv = list(path,attrstr);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
{
|
||||
string key;
|
||||
istringstream ss(attrstr);
|
||||
|
||||
while(getline(ss,key,'\0'))
|
||||
{
|
||||
string value;
|
||||
|
||||
rv = get(path,key,value);
|
||||
if(rv != -1)
|
||||
attrs[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
set(const int fd,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::fsetxattr(fd,
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
set(const string &path,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::setxattr(path.c_str(),
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
set(const int fd,
|
||||
const map<string,string> &attrs)
|
||||
{
|
||||
int rv;
|
||||
|
||||
for(map<string,string>::const_iterator
|
||||
i = attrs.begin(), ei = attrs.end(); i != ei; ++i)
|
||||
{
|
||||
rv = set(fd,i->first,i->second,0);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
set(const string &path,
|
||||
const map<string,string> &attrs)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = ::open(path.c_str(),O_RDONLY|O_NONBLOCK);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
set(fd,attrs);
|
||||
|
||||
return ::close(fd);
|
||||
}
|
||||
|
||||
int
|
||||
copy(const int fdin,
|
||||
const int fdout)
|
||||
{
|
||||
int rv;
|
||||
map<string,string> attrs;
|
||||
|
||||
rv = get(fdin,attrs);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return set(fdout,attrs);
|
||||
}
|
||||
|
||||
int
|
||||
copy(const string &from,
|
||||
const string &to)
|
||||
{
|
||||
int rv;
|
||||
map<string,string> attrs;
|
||||
|
||||
rv = get(from,attrs);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return set(to,attrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
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_XATTR_HPP__
|
||||
#define __FS_XATTR_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace xattr
|
||||
{
|
||||
using std::size_t;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
|
||||
int list(const string &path,
|
||||
vector<char> &attrs);
|
||||
int list(const string &path,
|
||||
string &attrs);
|
||||
int list(const string &path,
|
||||
vector<string> &attrs);
|
||||
|
||||
int get(const string &path,
|
||||
const string &attr,
|
||||
vector<char> &value);
|
||||
int get(const string &path,
|
||||
const string &attr,
|
||||
string &value);
|
||||
|
||||
int get(const string &path,
|
||||
map<string,string> &attrs);
|
||||
|
||||
int set(const string &path,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags);
|
||||
int set(const int fd,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags);
|
||||
|
||||
int set(const string &path,
|
||||
const map<string,string> &attrs);
|
||||
|
||||
int copy(const int fdin,
|
||||
const int fdout);
|
||||
int copy(const string &from,
|
||||
const string &to);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __FS_HPP__
|
||||
+17
-32
@@ -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 _GNU_SOURCE
|
||||
@@ -34,8 +26,6 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
@@ -54,21 +44,16 @@ _fsync(const int fd,
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fsync
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
struct fuse_file_info *fi)
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const FileInfo *fileinfo = (FileInfo*)fi->fh;
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return 0;
|
||||
|
||||
return _fsync(fileinfo->fd,
|
||||
return _fsync(fi->fd,
|
||||
isdatasync);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-23
@@ -1,36 +1,28 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fsync
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
struct fuse_file_info *fi);
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-32
@@ -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 <fuse.h>
|
||||
@@ -28,8 +20,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
@@ -46,21 +36,16 @@ _ftruncate(const int fd,
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ftruncate
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
struct fuse_file_info *fi)
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const FileInfo *fileinfo = (FileInfo*)fi->fh;
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -EPERM;
|
||||
|
||||
return _ftruncate(fileinfo->fd,
|
||||
return _ftruncate(fi->fd,
|
||||
size);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-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.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
@@ -29,11 +21,11 @@
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ftruncate
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
struct fuse_file_info *fi);
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fusefunc.hpp"
|
||||
#include "category.hpp"
|
||||
#include "buildvector.hpp"
|
||||
|
||||
#define FUSEFUNC(X,Y) FuseFunc(FuseFunc::Enum::X,#X,Category::Enum::Y)
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
const std::vector<FuseFunc> FuseFunc::_fusefuncs_ =
|
||||
buildvector<FuseFunc,true>
|
||||
(FUSEFUNC(invalid,invalid))
|
||||
(FUSEFUNC(access,search))
|
||||
(FUSEFUNC(chmod,action))
|
||||
(FUSEFUNC(chown,action))
|
||||
(FUSEFUNC(create,create))
|
||||
(FUSEFUNC(getattr,search))
|
||||
(FUSEFUNC(getxattr,search))
|
||||
(FUSEFUNC(link,action))
|
||||
(FUSEFUNC(listxattr,search))
|
||||
(FUSEFUNC(mkdir,create))
|
||||
(FUSEFUNC(mknod,create))
|
||||
(FUSEFUNC(open,search))
|
||||
(FUSEFUNC(readlink,search))
|
||||
(FUSEFUNC(removexattr,action))
|
||||
(FUSEFUNC(rename,action))
|
||||
(FUSEFUNC(rmdir,action))
|
||||
(FUSEFUNC(setxattr,action))
|
||||
(FUSEFUNC(symlink,create))
|
||||
(FUSEFUNC(truncate,action))
|
||||
(FUSEFUNC(unlink,action))
|
||||
(FUSEFUNC(utimens,action))
|
||||
;
|
||||
|
||||
const FuseFunc * const FuseFunc::fusefuncs = &_fusefuncs_[1];
|
||||
|
||||
const FuseFunc &FuseFunc::invalid = FuseFunc::fusefuncs[FuseFunc::Enum::invalid];
|
||||
const FuseFunc &FuseFunc::access = FuseFunc::fusefuncs[FuseFunc::Enum::access];
|
||||
const FuseFunc &FuseFunc::chmod = FuseFunc::fusefuncs[FuseFunc::Enum::chmod];
|
||||
const FuseFunc &FuseFunc::chown = FuseFunc::fusefuncs[FuseFunc::Enum::chown];
|
||||
const FuseFunc &FuseFunc::create = FuseFunc::fusefuncs[FuseFunc::Enum::create];
|
||||
const FuseFunc &FuseFunc::getattr = FuseFunc::fusefuncs[FuseFunc::Enum::getattr];
|
||||
const FuseFunc &FuseFunc::getxattr = FuseFunc::fusefuncs[FuseFunc::Enum::getxattr];
|
||||
const FuseFunc &FuseFunc::link = FuseFunc::fusefuncs[FuseFunc::Enum::link];
|
||||
const FuseFunc &FuseFunc::listxattr = FuseFunc::fusefuncs[FuseFunc::Enum::listxattr];
|
||||
const FuseFunc &FuseFunc::mkdir = FuseFunc::fusefuncs[FuseFunc::Enum::mkdir];
|
||||
const FuseFunc &FuseFunc::mknod = FuseFunc::fusefuncs[FuseFunc::Enum::mknod];
|
||||
const FuseFunc &FuseFunc::open = FuseFunc::fusefuncs[FuseFunc::Enum::open];
|
||||
const FuseFunc &FuseFunc::readlink = FuseFunc::fusefuncs[FuseFunc::Enum::readlink];
|
||||
const FuseFunc &FuseFunc::removexattr = FuseFunc::fusefuncs[FuseFunc::Enum::removexattr];
|
||||
const FuseFunc &FuseFunc::rmdir = FuseFunc::fusefuncs[FuseFunc::Enum::rmdir];
|
||||
const FuseFunc &FuseFunc::setxattr = FuseFunc::fusefuncs[FuseFunc::Enum::setxattr];
|
||||
const FuseFunc &FuseFunc::symlink = FuseFunc::fusefuncs[FuseFunc::Enum::symlink];
|
||||
const FuseFunc &FuseFunc::truncate = FuseFunc::fusefuncs[FuseFunc::Enum::truncate];
|
||||
const FuseFunc &FuseFunc::unlink = FuseFunc::fusefuncs[FuseFunc::Enum::unlink];
|
||||
const FuseFunc &FuseFunc::utimens = FuseFunc::fusefuncs[FuseFunc::Enum::utimens];
|
||||
|
||||
const FuseFunc&
|
||||
FuseFunc::find(const std::string &str)
|
||||
{
|
||||
for(int i = Enum::BEGIN; i != Enum::END; ++i)
|
||||
{
|
||||
if(fusefuncs[i] == str)
|
||||
return fusefuncs[i];
|
||||
}
|
||||
|
||||
return invalid;
|
||||
}
|
||||
|
||||
const FuseFunc&
|
||||
FuseFunc::find(const FuseFunc::Enum::Type i)
|
||||
{
|
||||
if(i >= FuseFunc::Enum::BEGIN &&
|
||||
i < FuseFunc::Enum::END)
|
||||
return fusefuncs[i];
|
||||
|
||||
return invalid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
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 __FUSEFUNC_HPP__
|
||||
#define __FUSEFUNC_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "category.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
class FuseFunc
|
||||
{
|
||||
public:
|
||||
struct Enum
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
invalid = -1,
|
||||
BEGIN = 0,
|
||||
access = BEGIN,
|
||||
chmod,
|
||||
chown,
|
||||
create,
|
||||
getattr,
|
||||
getxattr,
|
||||
link,
|
||||
listxattr,
|
||||
mkdir,
|
||||
mknod,
|
||||
open,
|
||||
readlink,
|
||||
removexattr,
|
||||
rename,
|
||||
rmdir,
|
||||
setxattr,
|
||||
symlink,
|
||||
truncate,
|
||||
unlink,
|
||||
utimens,
|
||||
END
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
Enum::Type _enum;
|
||||
std::string _str;
|
||||
Category::Enum::Type _category;
|
||||
|
||||
public:
|
||||
FuseFunc()
|
||||
: _enum(invalid),
|
||||
_str(invalid),
|
||||
_category(Category::Enum::invalid)
|
||||
{
|
||||
}
|
||||
|
||||
FuseFunc(const Enum::Type enum_,
|
||||
const std::string &str_,
|
||||
const Category::Enum::Type category_)
|
||||
: _enum(enum_),
|
||||
_str(str_),
|
||||
_category(category_)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
operator const Enum::Type() const { return _enum; }
|
||||
operator const std::string&() const { return _str; }
|
||||
operator const Category::Enum::Type() const { return _category; }
|
||||
operator const FuseFunc*() const { return this; }
|
||||
|
||||
bool operator==(const std::string &str_) const
|
||||
{ return _str == str_; }
|
||||
|
||||
bool operator==(const Enum::Type enum_) const
|
||||
{ return _enum == enum_; }
|
||||
|
||||
bool operator!=(const FuseFunc &r) const
|
||||
{ return _enum != r._enum; }
|
||||
|
||||
bool operator<(const FuseFunc &r) const
|
||||
{ return _enum < r._enum; }
|
||||
|
||||
public:
|
||||
static const FuseFunc &find(const std::string&);
|
||||
static const FuseFunc &find(const Enum::Type);
|
||||
|
||||
public:
|
||||
static const std::vector<FuseFunc> _fusefuncs_;
|
||||
static const FuseFunc * const fusefuncs;
|
||||
static const FuseFunc &invalid;
|
||||
static const FuseFunc &access;
|
||||
static const FuseFunc &chmod;
|
||||
static const FuseFunc &chown;
|
||||
static const FuseFunc &create;
|
||||
static const FuseFunc &getattr;
|
||||
static const FuseFunc &getxattr;
|
||||
static const FuseFunc &link;
|
||||
static const FuseFunc &listxattr;
|
||||
static const FuseFunc &mkdir;
|
||||
static const FuseFunc &mknod;
|
||||
static const FuseFunc &open;
|
||||
static const FuseFunc &readlink;
|
||||
static const FuseFunc &removexattr;
|
||||
static const FuseFunc &rename;
|
||||
static const FuseFunc &rmdir;
|
||||
static const FuseFunc &setxattr;
|
||||
static const FuseFunc &symlink;
|
||||
static const FuseFunc &truncate;
|
||||
static const FuseFunc &unlink;
|
||||
static const FuseFunc &utimens;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+61
-37
@@ -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 <fuse.h>
|
||||
@@ -33,9 +25,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -43,41 +35,73 @@ using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_getattr(const Policy::Search::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
struct stat &buf)
|
||||
_getattr_controlfile(struct stat &buf)
|
||||
{
|
||||
static const uid_t uid = ::getuid();
|
||||
static const gid_t gid = ::getgid();
|
||||
static const time_t now = ::time(NULL);
|
||||
|
||||
buf.st_dev = 0;
|
||||
buf.st_ino = 0;
|
||||
buf.st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
|
||||
buf.st_nlink = 1;
|
||||
buf.st_uid = uid;
|
||||
buf.st_gid = gid;
|
||||
buf.st_rdev = 0;
|
||||
buf.st_size = 0;
|
||||
buf.st_blksize = 1024;
|
||||
buf.st_blocks = 0;
|
||||
buf.st_atime = now;
|
||||
buf.st_mtime = now;
|
||||
buf.st_ctime = now;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
struct stat &buf)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
vector<string> path;
|
||||
|
||||
path = searchFunc(srcmounts,fusepath).full;
|
||||
if(path.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = ::lstat(path.c_str(),&buf);
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
rv = ::lstat(path[0].c_str(),&buf);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace getattr
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
getattr(const char *fusepath,
|
||||
struct stat *buf)
|
||||
struct stat *st)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return (*buf = config.controlfilestat,0);
|
||||
return _getattr_controlfile(*st);
|
||||
|
||||
return _getattr(config.policy.search,
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _getattr(config.getattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
*buf);
|
||||
*st);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -28,7 +20,7 @@
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace getattr
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
getattr(const char *fusepath,
|
||||
|
||||
+287
-39
@@ -1,61 +1,56 @@
|
||||
/*
|
||||
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 <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "str.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "version.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using std::set;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr(const Policy::Search::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const char *attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
_lgetxattr(const string &path,
|
||||
const string &name,
|
||||
void *value,
|
||||
const size_t size)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
string path;
|
||||
|
||||
path = searchFunc(srcmounts,fusepath).full;
|
||||
if(path.empty())
|
||||
return -ENOENT;
|
||||
|
||||
rv = ::lgetxattr(path.c_str(),attrname,buf,count);
|
||||
rv = ::lgetxattr(path.c_str(),name.c_str(),value,size);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
#else
|
||||
@@ -63,9 +58,255 @@ _getxattr(const Policy::Search::Func searchFunc,
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_fusefunc_policy(const Config &config,
|
||||
const string &attr,
|
||||
string &attrvalue)
|
||||
{
|
||||
FuseFunc fusefunc;
|
||||
|
||||
fusefunc = FuseFunc::find(attr);
|
||||
if(fusefunc != FuseFunc::invalid)
|
||||
attrvalue = (std::string)*config.policies[(FuseFunc::Enum::Type)*fusefunc];
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_category_policy(const Config &config,
|
||||
const string &attr,
|
||||
string &attrvalue)
|
||||
{
|
||||
Category cat;
|
||||
|
||||
cat = Category::find(attr);
|
||||
if(cat != Category::invalid)
|
||||
{
|
||||
vector<string> policies;
|
||||
for(int i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
|
||||
{
|
||||
if(cat == (Category::Enum::Type)*FuseFunc::fusefuncs[i])
|
||||
policies.push_back(*config.policies[i]);
|
||||
}
|
||||
|
||||
std::sort(policies.begin(),policies.end());
|
||||
policies.erase(std::unique(policies.begin(),policies.end()),
|
||||
policies.end());
|
||||
attrvalue = str::join(policies,',');
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_srcmounts(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
attrvalue = str::join(config.srcmounts,':');
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_minfreespace(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
char buf[64];
|
||||
unsigned long long minfreespace;
|
||||
|
||||
minfreespace = (unsigned long long)config.minfreespace;
|
||||
snprintf(buf,sizeof(buf),"%llu",minfreespace);
|
||||
|
||||
attrvalue = buf;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_moveonenospc(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
attrvalue = (config.moveonenospc ? "true" : "false");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_policies(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
size_t i = Policy::Enum::begin();
|
||||
|
||||
attrvalue = (string)Policy::policies[i];
|
||||
for(i++; i < Policy::Enum::end(); i++)
|
||||
attrvalue += ',' + (string)Policy::policies[i];
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_version(string &attrvalue)
|
||||
{
|
||||
attrvalue = MERGERFS_VERSION;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_pid(string &attrvalue)
|
||||
{
|
||||
int pid;
|
||||
char buf[32];
|
||||
|
||||
pid = getpid();
|
||||
snprintf(buf,sizeof(buf),"%d",pid);
|
||||
|
||||
attrvalue = buf;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr_controlfile(const Config &config,
|
||||
const string &attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
size_t len;
|
||||
string attrvalue;
|
||||
vector<string> attr;
|
||||
|
||||
str::split(attr,attrname,'.');
|
||||
if((attr[0] != "user") || (attr[1] != "mergerfs"))
|
||||
return -ENOATTR;
|
||||
|
||||
switch(attr.size())
|
||||
{
|
||||
case 3:
|
||||
if(attr[2] == "srcmounts")
|
||||
_getxattr_controlfile_srcmounts(config,attrvalue);
|
||||
else if(attr[2] == "minfreespace")
|
||||
_getxattr_controlfile_minfreespace(config,attrvalue);
|
||||
else if(attr[2] == "moveonenospc")
|
||||
_getxattr_controlfile_moveonenospc(config,attrvalue);
|
||||
else if(attr[2] == "policies")
|
||||
_getxattr_controlfile_policies(config,attrvalue);
|
||||
else if(attr[2] == "version")
|
||||
_getxattr_controlfile_version(attrvalue);
|
||||
else if(attr[2] == "pid")
|
||||
_getxattr_pid(attrvalue);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if(attr[2] == "category")
|
||||
_getxattr_controlfile_category_policy(config,attr[3],attrvalue);
|
||||
else if(attr[2] == "func")
|
||||
_getxattr_controlfile_fusefunc_policy(config,attr[3],attrvalue);
|
||||
break;
|
||||
}
|
||||
|
||||
if(attrvalue.empty())
|
||||
return -ENOATTR;
|
||||
|
||||
len = attrvalue.size();
|
||||
|
||||
if(count == 0)
|
||||
return len;
|
||||
|
||||
if(count < len)
|
||||
return -ERANGE;
|
||||
|
||||
memcpy(buf,attrvalue.c_str(),len);
|
||||
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr_from_string(char *destbuf,
|
||||
const size_t destbufsize,
|
||||
const string &src)
|
||||
{
|
||||
const size_t srcbufsize = src.size();
|
||||
|
||||
if(destbufsize == 0)
|
||||
return srcbufsize;
|
||||
|
||||
if(srcbufsize > destbufsize)
|
||||
return -ERANGE;
|
||||
|
||||
memcpy(destbuf,src.data(),srcbufsize);
|
||||
|
||||
return srcbufsize;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr_user_mergerfs_allpaths(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
string concated;
|
||||
vector<string> paths;
|
||||
|
||||
fs::findallfiles(srcmounts,fusepath,paths);
|
||||
|
||||
concated = str::join(paths,'\0');
|
||||
|
||||
return _getxattr_from_string(buf,count,concated);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr_user_mergerfs(const string &basepath,
|
||||
const string &fusepath,
|
||||
const string &fullpath,
|
||||
const vector<string> &srcmounts,
|
||||
const string &attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
vector<string> attr;
|
||||
|
||||
str::split(attr,attrname,'.');
|
||||
|
||||
if(attr[2] == "basepath")
|
||||
return _getxattr_from_string(buf,count,basepath);
|
||||
else if(attr[2] == "relpath")
|
||||
return _getxattr_from_string(buf,count,fusepath);
|
||||
else if(attr[2] == "fullpath")
|
||||
return _getxattr_from_string(buf,count,fullpath);
|
||||
else if(attr[2] == "allpaths")
|
||||
return _getxattr_user_mergerfs_allpaths(srcmounts,fusepath,buf,count);
|
||||
|
||||
return -ENOATTR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const string &attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
vector<string> basepath;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fs::path::make(basepath[0],fusepath,fullpath);
|
||||
|
||||
if(str::isprefix(attrname,"user.mergerfs."))
|
||||
rv = _getxattr_user_mergerfs(basepath[0],fusepath,fullpath,srcmounts,attrname,buf,count);
|
||||
else
|
||||
rv = _lgetxattr(fullpath,attrname,buf,count);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace getxattr
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
getxattr(const char *fusepath,
|
||||
@@ -73,14 +314,21 @@ namespace mergerfs
|
||||
char *buf,
|
||||
size_t count)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -ENOTSUP;
|
||||
return _getxattr_controlfile(config,
|
||||
attrname,
|
||||
buf,
|
||||
count);
|
||||
|
||||
return _getxattr(config.policy.search,
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _getxattr(config.getxattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname,
|
||||
buf,
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace getxattr
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
getxattr(const char *fusepath,
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
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 <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined __linux__ and UGID_USE_RWLOCK == 0
|
||||
# include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
|
||||
#include "gidcache.hpp"
|
||||
|
||||
inline
|
||||
bool
|
||||
gid_t_rec::operator<(const struct gid_t_rec &b) const
|
||||
{
|
||||
return uid < b.uid;
|
||||
}
|
||||
|
||||
inline
|
||||
gid_t_rec *
|
||||
gid_t_cache::begin(void)
|
||||
{
|
||||
return recs;
|
||||
}
|
||||
|
||||
inline
|
||||
gid_t_rec *
|
||||
gid_t_cache::end(void)
|
||||
{
|
||||
return recs + size;
|
||||
}
|
||||
|
||||
inline
|
||||
gid_t_rec *
|
||||
gid_t_cache::allocrec(void)
|
||||
{
|
||||
if(size == MAXRECS)
|
||||
return &recs[rand() % MAXRECS];
|
||||
else
|
||||
return &recs[size++];
|
||||
}
|
||||
|
||||
inline
|
||||
gid_t_rec *
|
||||
gid_t_cache::lower_bound(gid_t_rec *begin,
|
||||
gid_t_rec *end,
|
||||
const uid_t uid)
|
||||
{
|
||||
int step;
|
||||
int count;
|
||||
gid_t_rec *iter;
|
||||
|
||||
count = std::distance(begin,end);
|
||||
while(count > 0)
|
||||
{
|
||||
iter = begin;
|
||||
step = count / 2;
|
||||
std::advance(iter,step);
|
||||
if(iter->uid < uid)
|
||||
{
|
||||
begin = ++iter;
|
||||
count -= step + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = step;
|
||||
}
|
||||
}
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
gid_t_rec *
|
||||
gid_t_cache::cache(const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
int rv;
|
||||
char buf[4096];
|
||||
struct passwd pwd;
|
||||
struct passwd *pwdrv;
|
||||
gid_t_rec *rec;
|
||||
|
||||
rec = allocrec();
|
||||
|
||||
rec->uid = uid;
|
||||
rv = ::getpwuid_r(uid,&pwd,buf,sizeof(buf),&pwdrv);
|
||||
if(pwdrv != NULL && rv == 0)
|
||||
{
|
||||
rec->size = 0;
|
||||
::getgrouplist(pwd.pw_name,gid,NULL,&rec->size);
|
||||
rec->size = std::min(MAXGIDS,rec->size);
|
||||
rv = ::getgrouplist(pwd.pw_name,gid,rec->gids,&rec->size);
|
||||
if(rv == -1)
|
||||
{
|
||||
rec->gids[0] = gid;
|
||||
rec->size = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
setgroups(const gid_t_rec *rec)
|
||||
{
|
||||
#if defined __linux__ and UGID_USE_RWLOCK == 0
|
||||
return ::syscall(SYS_setgroups,rec->size,rec->gids);
|
||||
#else
|
||||
return ::setgroups(rec->size,rec->gids);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
gid_t_cache::initgroups(const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
int rv;
|
||||
gid_t_rec *rec;
|
||||
|
||||
rec = lower_bound(begin(),end(),uid);
|
||||
if(rec == end() || rec->uid != uid)
|
||||
{
|
||||
rec = cache(uid,gid);
|
||||
rv = ::setgroups(rec);
|
||||
std::sort(begin(),end());
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = ::setgroups(rec);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 __GIDCACHE_HPP__
|
||||
#define __GIDCACHE_HPP__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAXGIDS 32
|
||||
#define MAXRECS 256
|
||||
|
||||
struct gid_t_rec
|
||||
{
|
||||
uid_t uid;
|
||||
int size;
|
||||
gid_t gids[MAXGIDS];
|
||||
|
||||
bool
|
||||
operator<(const struct gid_t_rec &b) const;
|
||||
};
|
||||
|
||||
struct gid_t_cache
|
||||
{
|
||||
public:
|
||||
size_t size;
|
||||
gid_t_rec recs[MAXRECS];
|
||||
|
||||
private:
|
||||
gid_t_rec * begin(void);
|
||||
gid_t_rec * end(void);
|
||||
gid_t_rec * allocrec(void);
|
||||
gid_t_rec * lower_bound(gid_t_rec *begin,
|
||||
gid_t_rec *end,
|
||||
const uid_t uid);
|
||||
gid_t_rec * cache(const uid_t uid,
|
||||
const gid_t gid);
|
||||
|
||||
public:
|
||||
int
|
||||
initgroups(const uid_t uid,
|
||||
const gid_t gid);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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 "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
void *
|
||||
init(fuse_conn_info *conn)
|
||||
{
|
||||
ugid::init();
|
||||
|
||||
#ifdef FUSE_CAP_IOCTL_DIR
|
||||
conn->want |= FUSE_CAP_IOCTL_DIR;
|
||||
#endif
|
||||
|
||||
return &Config::get_writable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
void *
|
||||
init(fuse_conn_info *conn);
|
||||
}
|
||||
}
|
||||
+97
-52
@@ -1,30 +1,23 @@
|
||||
/*
|
||||
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 <string>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -32,57 +25,109 @@
|
||||
|
||||
#include "config.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_ioctl(const int fd,
|
||||
const int cmd,
|
||||
void *arg,
|
||||
const unsigned int flags,
|
||||
void *data)
|
||||
_ioctl(const int fd,
|
||||
const int cmd,
|
||||
void *data)
|
||||
{
|
||||
int rv;
|
||||
|
||||
switch(cmd)
|
||||
{
|
||||
case FS_IOC_GETFLAGS:
|
||||
case FS_IOC_SETFLAGS:
|
||||
rv = ::ioctl(fd,cmd,data);
|
||||
break;
|
||||
|
||||
default:
|
||||
rv = -1;
|
||||
errno = ENOTTY;
|
||||
break;
|
||||
}
|
||||
rv = ::ioctl(fd,cmd,data);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
}
|
||||
|
||||
#ifdef FUSE_IOCTL_DIR
|
||||
|
||||
#ifndef O_DIRECTORY
|
||||
#define O_DIRECTORY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOATIME
|
||||
#define O_NOATIME 0
|
||||
#endif
|
||||
|
||||
static
|
||||
int
|
||||
_ioctl_dir_base(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const int cmd,
|
||||
void *data)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
vector<string> path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
fd = ::open(path[0].c_str(),O_RDWR|O_NOATIME|O_DIRECTORY);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
rv = _ioctl(fd,cmd,data);
|
||||
|
||||
::close(fd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_ioctl_dir(const string &fusepath,
|
||||
const int cmd,
|
||||
void *data)
|
||||
{
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _ioctl_dir_base(config.getattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
cmd,
|
||||
data);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ioctl
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
struct fuse_file_info *fi,
|
||||
unsigned int flags,
|
||||
void *data)
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
fuse_file_info *ffi,
|
||||
unsigned int flags,
|
||||
void *data)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const FileInfo *fileinfo = (FileInfo*)fi->fh;
|
||||
#ifdef FUSE_IOCTL_DIR
|
||||
if(flags & FUSE_IOCTL_DIR)
|
||||
return _ioctl_dir(fusepath,
|
||||
cmd,
|
||||
data);
|
||||
#endif
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -EINVAL;
|
||||
|
||||
return _ioctl(fileinfo->fd,
|
||||
return _ioctl(fi->fd,
|
||||
cmd,
|
||||
arg,
|
||||
flags,
|
||||
data);
|
||||
}
|
||||
}
|
||||
|
||||
+18
-26
@@ -1,37 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ioctl
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
struct fuse_file_info *fi,
|
||||
unsigned int flags,
|
||||
void *data);
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
fuse_file_info *fi,
|
||||
unsigned int flags,
|
||||
void *data);
|
||||
}
|
||||
}
|
||||
|
||||
+192
-48
@@ -1,27 +1,21 @@
|
||||
/*
|
||||
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 <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -29,63 +23,213 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_link(const Policy::Action::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string from,
|
||||
const string to)
|
||||
_link_create_path_one(const string &oldbasepath,
|
||||
const string &newbasepath,
|
||||
const string &oldfusepath,
|
||||
const string &newfusepath,
|
||||
const string &newfusedirpath,
|
||||
const int error)
|
||||
{
|
||||
int rv;
|
||||
string oldfullpath;
|
||||
string newfullpath;
|
||||
|
||||
if(oldbasepath != newbasepath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
fs::clonepath(newbasepath,oldbasepath,newfusedirpath);
|
||||
}
|
||||
|
||||
fs::path::make(oldbasepath,oldfusepath,oldfullpath);
|
||||
fs::path::make(oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
rv = ::link(oldfullpath.c_str(),newfullpath.c_str());
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_link_create_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &oldfusepath,
|
||||
const string &newfusepath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
vector<fs::Path> paths;
|
||||
string newbasepath;
|
||||
vector<string> toremove;
|
||||
vector<string> oldbasepaths;
|
||||
|
||||
searchFunc(srcmounts,from,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(vector<fs::Path>::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
const string newfusedirpath = fs::path::dirname(newfusepath);
|
||||
rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = oldbasepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string pathfrom = fs::make_path(i->base,from);
|
||||
const string pathto = fs::make_path(i->base,to);
|
||||
const string &oldbasepath = oldbasepaths[i];
|
||||
|
||||
rv &= ::link(pathfrom.c_str(),pathto.c_str());
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
error = _link_create_path_one(oldbasepath,newbasepath,
|
||||
oldfusepath,newfusepath,
|
||||
newfusedirpath,
|
||||
error);
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_clonepath_if_would_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const string &oldfusepath,
|
||||
const string &newfusepath)
|
||||
{
|
||||
int rv;
|
||||
string newbasepath;
|
||||
string newfusedirpath;
|
||||
|
||||
newfusedirpath = fs::path::dirname(newfusepath);
|
||||
|
||||
rv = createFunc(srcmounts,newfusedirpath,minfreespace,newbasepath);
|
||||
if(rv != -1)
|
||||
{
|
||||
if(oldbasepath == newbasepath)
|
||||
{
|
||||
rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath);
|
||||
if(rv != -1)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
fs::clonepath(newbasepath,oldbasepath,newfusedirpath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = -1;
|
||||
errno = EXDEV;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_link_preserve_path_one(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const string &oldfusepath,
|
||||
const string &newfusepath,
|
||||
const int error)
|
||||
{
|
||||
int rv;
|
||||
string oldfullpath;
|
||||
string newfullpath;
|
||||
|
||||
fs::path::make(oldbasepath,oldfusepath,oldfullpath);
|
||||
fs::path::make(oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
rv = ::link(oldfullpath.c_str(),newfullpath.c_str());
|
||||
if((rv == -1) && (errno == ENOENT))
|
||||
{
|
||||
rv = _clonepath_if_would_create(searchFunc,createFunc,
|
||||
srcmounts,minfreespace,
|
||||
oldbasepath,oldfusepath,newfusepath);
|
||||
if(rv != -1)
|
||||
rv = ::link(oldfullpath.c_str(),newfullpath.c_str());
|
||||
}
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_link_preserve_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &oldfusepath,
|
||||
const string &newfusepath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
vector<string> toremove;
|
||||
vector<string> oldbasepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = oldbasepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string &oldbasepath = oldbasepaths[i];
|
||||
|
||||
error = _link_preserve_path_one(searchFunc,createFunc,
|
||||
srcmounts,minfreespace,
|
||||
oldbasepath,
|
||||
oldfusepath,newfusepath,
|
||||
error);
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace link
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
link(const char *from,
|
||||
const char *to)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(from == config.controlfile)
|
||||
return -EPERM;
|
||||
if(config.create != Policy::epmfs)
|
||||
return _link_create_path(config.link,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
from,
|
||||
to);
|
||||
|
||||
return _link(config.policy.action,
|
||||
config.srcmounts,
|
||||
from,
|
||||
to);
|
||||
return _link_preserve_path(config.getattr,
|
||||
config.link,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
from,
|
||||
to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace link
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
link(const char *from,
|
||||
|
||||
+75
-37
@@ -1,60 +1,94 @@
|
||||
/*
|
||||
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 <string>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "buildvector.hpp"
|
||||
#include "category.hpp"
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_listxattr(const Policy::Search::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
char *list,
|
||||
const size_t size)
|
||||
_listxattr_controlfile(char *list,
|
||||
const size_t size)
|
||||
{
|
||||
string xattrs;
|
||||
const vector<string> strs =
|
||||
buildvector<string>
|
||||
("user.mergerfs.srcmounts")
|
||||
("user.mergerfs.minfreespace")
|
||||
("user.mergerfs.moveonenospc")
|
||||
("user.mergerfs.policies")
|
||||
("user.mergerfs.version")
|
||||
("user.mergerfs.pid");
|
||||
|
||||
xattrs.reserve(1024);
|
||||
for(size_t i = 0; i < strs.size(); i++)
|
||||
xattrs += (strs[i] + '\0');
|
||||
for(size_t i = Category::Enum::BEGIN; i < Category::Enum::END; i++)
|
||||
xattrs += ("user.mergerfs.category." + (std::string)*Category::categories[i] + '\0');
|
||||
for(size_t i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
|
||||
xattrs += ("user.mergerfs.func." + (std::string)*FuseFunc::fusefuncs[i] + '\0');
|
||||
|
||||
if(size == 0)
|
||||
return xattrs.size();
|
||||
|
||||
if(size < xattrs.size())
|
||||
return -ERANGE;
|
||||
|
||||
memcpy(list,xattrs.c_str(),xattrs.size());
|
||||
|
||||
return xattrs.size();
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_listxattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
char *list,
|
||||
const size_t size)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
string path;
|
||||
vector<string> path;
|
||||
|
||||
path = searchFunc(srcmounts,fusepath).full;
|
||||
if(path.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = ::llistxattr(path.c_str(),list,size);
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
rv = ::llistxattr(path[0].c_str(),list,size);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
#else
|
||||
@@ -64,21 +98,25 @@ _listxattr(const Policy::Search::Func searchFunc,
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace listxattr
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
listxattr(const char *fusepath,
|
||||
char *list,
|
||||
size_t size)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -ENOTSUP;
|
||||
return _listxattr_controlfile(list,size);
|
||||
|
||||
return _listxattr(config.policy.search,
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _listxattr(config.listxattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
list,
|
||||
size);
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace listxattr
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
listxattr(const char *fusepath,
|
||||
|
||||
+125
-94
@@ -1,26 +1,18 @@
|
||||
/*
|
||||
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 <string.h>
|
||||
@@ -31,28 +23,36 @@
|
||||
#include "mergerfs.hpp"
|
||||
#include "option_parser.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "test.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include "clone.hpp"
|
||||
|
||||
#include "access.hpp"
|
||||
#include "chmod.hpp"
|
||||
#include "chown.hpp"
|
||||
#include "create.hpp"
|
||||
#include "destroy.hpp"
|
||||
#include "fallocate.hpp"
|
||||
#include "fgetattr.hpp"
|
||||
#include "flush.hpp"
|
||||
#include "fsync.hpp"
|
||||
#include "ftruncate.hpp"
|
||||
#include "getattr.hpp"
|
||||
#include "getxattr.hpp"
|
||||
#include "init.hpp"
|
||||
#include "ioctl.hpp"
|
||||
#include "link.hpp"
|
||||
#include "listxattr.hpp"
|
||||
#include "mkdir.hpp"
|
||||
#include "mknod.hpp"
|
||||
#include "open.hpp"
|
||||
#include "opendir.hpp"
|
||||
#include "read.hpp"
|
||||
#include "read_buf.hpp"
|
||||
#include "readdir.hpp"
|
||||
#include "readlink.hpp"
|
||||
#include "release.hpp"
|
||||
#include "releasedir.hpp"
|
||||
#include "removexattr.hpp"
|
||||
#include "rename.hpp"
|
||||
#include "rmdir.hpp"
|
||||
@@ -63,79 +63,115 @@
|
||||
#include "unlink.hpp"
|
||||
#include "utimens.hpp"
|
||||
#include "write.hpp"
|
||||
#include "write_buf.hpp"
|
||||
|
||||
static
|
||||
struct fuse_operations
|
||||
get_fuse_operations()
|
||||
namespace local
|
||||
{
|
||||
struct fuse_operations ops = {};
|
||||
static
|
||||
std::string
|
||||
getappname(const int argc,
|
||||
char * const *argv)
|
||||
{
|
||||
return fs::path::basename(argv[0]);
|
||||
}
|
||||
|
||||
ops.flag_nopath = false;
|
||||
ops.flag_nullpath_ok = false;
|
||||
static
|
||||
void
|
||||
get_fuse_operations(struct fuse_operations &ops)
|
||||
{
|
||||
#if FLAG_NOPATH
|
||||
ops.flag_nopath = false;
|
||||
#endif
|
||||
ops.flag_nullpath_ok = false;
|
||||
|
||||
ops.access = mergerfs::access::access;
|
||||
ops.bmap = NULL;
|
||||
ops.chmod = mergerfs::chmod::chmod;
|
||||
ops.chown = mergerfs::chown::chown;
|
||||
ops.create = mergerfs::create::create;
|
||||
ops.destroy = NULL;
|
||||
ops.fallocate = mergerfs::fallocate::fallocate;
|
||||
ops.fgetattr = NULL;
|
||||
ops.flock = NULL;
|
||||
ops.flush = NULL; /* called on close() of fd */
|
||||
ops.fsync = mergerfs::fsync::fsync;
|
||||
ops.fsyncdir = NULL;
|
||||
ops.ftruncate = mergerfs::ftruncate::ftruncate;
|
||||
ops.getattr = mergerfs::getattr::getattr;
|
||||
ops.getdir = NULL; /* deprecated; use readdir */
|
||||
ops.getxattr = mergerfs::getxattr::getxattr;
|
||||
ops.init = NULL;
|
||||
ops.ioctl = NULL;
|
||||
ops.ioctl = mergerfs::ioctl::ioctl;
|
||||
ops.link = mergerfs::link::link;
|
||||
ops.listxattr = mergerfs::listxattr::listxattr;
|
||||
ops.lock = NULL;
|
||||
ops.mkdir = mergerfs::mkdir::mkdir;
|
||||
ops.mknod = mergerfs::mknod::mknod;
|
||||
ops.open = mergerfs::open::open;
|
||||
ops.opendir = NULL;
|
||||
ops.poll = NULL;
|
||||
ops.read = mergerfs::read::read;
|
||||
ops.read_buf = NULL;
|
||||
ops.readdir = mergerfs::readdir::readdir;
|
||||
ops.readlink = mergerfs::readlink::readlink;
|
||||
ops.release = mergerfs::release::release;
|
||||
ops.releasedir = NULL;
|
||||
ops.removexattr = mergerfs::removexattr::removexattr;
|
||||
ops.rename = mergerfs::rename::rename;
|
||||
ops.rmdir = mergerfs::rmdir::rmdir;
|
||||
ops.setxattr = mergerfs::setxattr::setxattr;
|
||||
ops.statfs = mergerfs::statfs::statfs;
|
||||
ops.symlink = mergerfs::symlink::symlink;
|
||||
ops.truncate = mergerfs::truncate::truncate;
|
||||
ops.unlink = mergerfs::unlink::unlink;
|
||||
ops.utime = NULL; /* deprecated; use utimens() */
|
||||
ops.utimens = mergerfs::utimens::utimens;
|
||||
ops.write = mergerfs::write::write;
|
||||
ops.write_buf = NULL;
|
||||
ops.access = mergerfs::fuse::access;
|
||||
ops.bmap = NULL;
|
||||
ops.chmod = mergerfs::fuse::chmod;
|
||||
ops.chown = mergerfs::fuse::chown;
|
||||
ops.create = mergerfs::fuse::create;
|
||||
ops.destroy = mergerfs::fuse::destroy;
|
||||
#if FALLOCATE
|
||||
ops.fallocate = mergerfs::fuse::fallocate;
|
||||
#endif
|
||||
ops.fgetattr = mergerfs::fuse::fgetattr;
|
||||
#if FLOCK
|
||||
ops.flock = NULL;
|
||||
#endif
|
||||
ops.flush = mergerfs::fuse::flush;
|
||||
ops.fsync = mergerfs::fuse::fsync;
|
||||
ops.fsyncdir = NULL;
|
||||
ops.ftruncate = mergerfs::fuse::ftruncate;
|
||||
ops.getattr = mergerfs::fuse::getattr;
|
||||
ops.getdir = NULL; /* deprecated; use readdir */
|
||||
ops.getxattr = mergerfs::fuse::getxattr;
|
||||
ops.init = mergerfs::fuse::init;
|
||||
ops.ioctl = mergerfs::fuse::ioctl;
|
||||
ops.link = mergerfs::fuse::link;
|
||||
ops.listxattr = mergerfs::fuse::listxattr;
|
||||
ops.lock = NULL;
|
||||
ops.mkdir = mergerfs::fuse::mkdir;
|
||||
ops.mknod = mergerfs::fuse::mknod;
|
||||
ops.open = mergerfs::fuse::open;
|
||||
ops.opendir = mergerfs::fuse::opendir;
|
||||
ops.poll = NULL;
|
||||
ops.read = mergerfs::fuse::read;
|
||||
#if READ_BUF
|
||||
ops.read_buf = mergerfs::fuse::read_buf;
|
||||
#endif
|
||||
ops.readdir = mergerfs::fuse::readdir;
|
||||
ops.readlink = mergerfs::fuse::readlink;
|
||||
ops.release = mergerfs::fuse::release;
|
||||
ops.releasedir = mergerfs::fuse::releasedir;
|
||||
ops.removexattr = mergerfs::fuse::removexattr;
|
||||
ops.rename = mergerfs::fuse::rename;
|
||||
ops.rmdir = mergerfs::fuse::rmdir;
|
||||
ops.setxattr = mergerfs::fuse::setxattr;
|
||||
ops.statfs = mergerfs::fuse::statfs;
|
||||
ops.symlink = mergerfs::fuse::symlink;
|
||||
ops.truncate = mergerfs::fuse::truncate;
|
||||
ops.unlink = mergerfs::fuse::unlink;
|
||||
ops.utime = NULL; /* deprecated; use utimens() */
|
||||
ops.utimens = mergerfs::fuse::utimens;
|
||||
ops.write = mergerfs::fuse::write;
|
||||
#if WRITE_BUF
|
||||
ops.write_buf = mergerfs::fuse::write_buf;
|
||||
#endif
|
||||
|
||||
return ops;
|
||||
return;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
setup_resources(void)
|
||||
{
|
||||
const int prio = -10;
|
||||
|
||||
std::srand(time(NULL));
|
||||
mergerfs::resources::reset_umask();
|
||||
mergerfs::resources::maxout_rlimit_nofile();
|
||||
mergerfs::resources::maxout_rlimit_fsize();
|
||||
mergerfs::resources::setpriority(prio);
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
main(const struct fuse_args &args,
|
||||
config::Config &config)
|
||||
main(const int argc,
|
||||
char **argv)
|
||||
{
|
||||
struct fuse_operations ops;
|
||||
fuse_args args;
|
||||
fuse_operations ops = {0};
|
||||
Config config;
|
||||
|
||||
ops = get_fuse_operations();
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
args.allocated = 0;
|
||||
|
||||
std::srand(time(NULL));
|
||||
resources::reset_umask();
|
||||
resources::maxout_rlimit_nofile();
|
||||
resources::maxout_rlimit_fsize();
|
||||
mergerfs::options::parse(args,config);
|
||||
|
||||
local::setup_resources();
|
||||
local::get_fuse_operations(ops);
|
||||
|
||||
return fuse_main(args.argc,
|
||||
args.argv,
|
||||
@@ -145,19 +181,14 @@ namespace mergerfs
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc,
|
||||
char *argv[])
|
||||
main(int argc,
|
||||
char **argv)
|
||||
{
|
||||
int rv;
|
||||
mergerfs::config::Config config;
|
||||
struct fuse_args args = FUSE_ARGS_INIT(argc,argv);
|
||||
std::string appname;
|
||||
|
||||
mergerfs::options::parse(args,config);
|
||||
appname = local::getappname(argc,argv);
|
||||
if(appname == "clone")
|
||||
return clonetool::main(argc,argv);
|
||||
|
||||
if(config.testmode == false)
|
||||
rv = mergerfs::main(args,config);
|
||||
else
|
||||
rv = mergerfs::test(args,config);
|
||||
|
||||
return rv;
|
||||
return mergerfs::main(argc,argv);
|
||||
}
|
||||
|
||||
+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 __MERGER_HPP__
|
||||
|
||||
+58
-52
@@ -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 <fuse.h>
|
||||
@@ -31,68 +23,82 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_mkdir(const Policy::Search::Func searchFunc,
|
||||
const Policy::Create::Func createPathFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const mode_t mode)
|
||||
_mkdir(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
int error;
|
||||
string dirname;
|
||||
fs::Path createpath;
|
||||
fs::Path existingpath;
|
||||
string existingpath;
|
||||
vector<string> createpaths;
|
||||
|
||||
if(fs::path_exists(srcmounts,fusepath))
|
||||
return -EEXIST;
|
||||
dirname = fs::path::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
existingpath = searchFunc(srcmounts,dirname);
|
||||
if(existingpath.base.empty())
|
||||
return -ENOENT;
|
||||
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
createpath = createPathFunc(srcmounts,dirname);
|
||||
if(createpath.base != existingpath.base)
|
||||
fs::clonepath(existingpath.base,createpath.base,dirname);
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
|
||||
{
|
||||
string &createpath = createpaths[i];
|
||||
|
||||
path = fs::make_path(createpath.base,fusepath);
|
||||
if(createpath != existingpath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
fs::clonepath(existingpath,createpath,dirname);
|
||||
}
|
||||
|
||||
rv = ::mkdir(path.c_str(),mode);
|
||||
fs::path::append(createpath,fusepath);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
rv = ::mkdir(createpath.c_str(),mode);
|
||||
|
||||
error = calc_error(rv,error,errno);
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace mkdir
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
mkdir(const char *fusepath,
|
||||
mode_t mode)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -EEXIST;
|
||||
|
||||
return _mkdir(config.policy.search,
|
||||
config.policy.create,
|
||||
return _mkdir(config.getattr,
|
||||
config.mkdir,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode);
|
||||
(mode & ~fc->umask));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace mkdir
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
mkdir(const char *fusepath,
|
||||
|
||||
+59
-53
@@ -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 <fuse.h>
|
||||
@@ -33,69 +25,83 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_mknod(const Policy::Search::Func searchFunc,
|
||||
const Policy::Create::Func createPathFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const mode_t mode,
|
||||
const dev_t dev)
|
||||
_mknod(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode,
|
||||
const dev_t dev)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
int error;
|
||||
string dirname;
|
||||
fs::Path createpath;
|
||||
fs::Path existingpath;
|
||||
string existingpath;
|
||||
vector<string> createpaths;
|
||||
|
||||
if(fs::path_exists(srcmounts,fusepath))
|
||||
return -EEXIST;
|
||||
dirname = fs::path::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
existingpath = searchFunc(srcmounts,dirname);
|
||||
if(existingpath.base.empty())
|
||||
return -ENOENT;
|
||||
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
createpath = createPathFunc(srcmounts,dirname);
|
||||
if(existingpath.base != createpath.base)
|
||||
fs::clonepath(existingpath.base,createpath.base,dirname);
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
|
||||
{
|
||||
string &createpath = createpaths[i];
|
||||
|
||||
path = fs::make_path(createpath.base,fusepath);
|
||||
if(createpath != existingpath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
fs::clonepath(existingpath,createpath,dirname);
|
||||
}
|
||||
|
||||
rv = ::mknod(path.c_str(),mode,dev);
|
||||
fs::path::append(createpath,fusepath);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
rv = ::mknod(createpath.c_str(),mode,dev);
|
||||
|
||||
error = calc_error(rv,error,errno);
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace mknod
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
mknod(const char *fusepath,
|
||||
mode_t mode,
|
||||
dev_t rdev)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -EEXIST;
|
||||
|
||||
return _mknod(config.policy.search,
|
||||
config.policy.create,
|
||||
return _mknod(config.getattr,
|
||||
config.mknod,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode,
|
||||
(mode & ~fc->umask),
|
||||
rdev);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-20
@@ -1,30 +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.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace mknod
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
mknod(const char *fusepath,
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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 <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace num
|
||||
{
|
||||
int
|
||||
to_size_t(const std::string &str,
|
||||
size_t &value)
|
||||
{
|
||||
size_t tmp;
|
||||
char *endptr;
|
||||
|
||||
tmp = strtoll(str.c_str(),&endptr,10);
|
||||
switch(*endptr)
|
||||
{
|
||||
case 'k':
|
||||
case 'K':
|
||||
tmp *= 1024;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
case 'M':
|
||||
tmp *= (1024 * 1024);
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
case 'G':
|
||||
tmp *= (1024 * 1024 * 1024);
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = tmp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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 num
|
||||
{
|
||||
int to_size_t(const std::string &str, size_t &value);
|
||||
}
|
||||
+41
-55
@@ -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 <fuse.h>
|
||||
@@ -31,69 +23,63 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::FileInfo;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_open_controlfile(uint64_t &fh)
|
||||
_open(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
{
|
||||
fh = (uint64_t)new string;
|
||||
int fd;
|
||||
int rv;
|
||||
vector<string> path;
|
||||
|
||||
return 0;
|
||||
}
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
static
|
||||
int
|
||||
_open(const Policy::Search::Func searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
{
|
||||
int fd;
|
||||
fs::Path path;
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
path = searchFunc(srcmounts,fusepath);
|
||||
if(path.full.empty())
|
||||
return -ENOENT;
|
||||
|
||||
fd = ::open(path.full.c_str(),flags);
|
||||
fd = ::open(path[0].c_str(),flags);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
fh = (uint64_t)new FileInfo(fd,flags,path.full);
|
||||
fh = reinterpret_cast<uint64_t>(new FileInfo(fd));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace open
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
open(const char *fusepath,
|
||||
struct fuse_file_info *fileinfo)
|
||||
open(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
const ugid::SetResetGuard ugid;
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _open_controlfile(fileinfo->fh);
|
||||
|
||||
return _open(config.policy.search,
|
||||
return _open(config.open,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
fileinfo->flags,
|
||||
fileinfo->fh);
|
||||
ffi->flags,
|
||||
ffi->fh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-22
@@ -1,35 +1,27 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace open
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
open(const char *fusepath,
|
||||
struct fuse_file_info *fileinfo);
|
||||
open(const char *fusepath,
|
||||
fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
opendir(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
ffi->fh = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <vector>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
opendir(const char *fusepath,
|
||||
fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
+273
-77
@@ -1,91 +1,206 @@
|
||||
/*
|
||||
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 <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "num.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "str.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using namespace mergerfs;
|
||||
|
||||
template<typename Container>
|
||||
Container&
|
||||
split(Container &result,
|
||||
const typename Container::value_type &s,
|
||||
typename Container::value_type::value_type delimiter)
|
||||
{
|
||||
std::istringstream ss(s);
|
||||
while(!ss.eof())
|
||||
{
|
||||
typename Container::value_type field;
|
||||
std::getline(ss,field,delimiter);
|
||||
if(field.empty())
|
||||
continue;
|
||||
result.push_back(field);
|
||||
}
|
||||
enum
|
||||
{
|
||||
MERGERFS_OPT_HELP,
|
||||
MERGERFS_OPT_VERSION
|
||||
};
|
||||
|
||||
return result;
|
||||
static
|
||||
void
|
||||
set_option(fuse_args &args,
|
||||
const std::string &option_)
|
||||
{
|
||||
string option;
|
||||
|
||||
option = "-o" + option_;
|
||||
|
||||
fuse_opt_insert_arg(&args,1,option.c_str());
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_kv_option(fuse_args &args,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
{
|
||||
std::string option;
|
||||
|
||||
option = key + '=' + value;
|
||||
|
||||
set_option(args,option);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_fsname(fuse_args &args,
|
||||
const vector<string> &srcmounts)
|
||||
{
|
||||
if(srcmounts.size() > 0)
|
||||
{
|
||||
std::string fsname;
|
||||
|
||||
fsname = str::remove_common_prefix_and_join(srcmounts,':');
|
||||
|
||||
set_kv_option(args,"fsname",fsname);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_subtype(fuse_args &args)
|
||||
{
|
||||
set_kv_option(args,"subtype","mergerfs");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_default_options(fuse_args &args)
|
||||
{
|
||||
set_option(args,"atomic_o_trunc");
|
||||
set_option(args,"auto_cache");
|
||||
set_option(args,"big_writes");
|
||||
set_option(args,"default_permissions");
|
||||
set_option(args,"splice_move");
|
||||
set_option(args,"splice_read");
|
||||
set_option(args,"splice_write");
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
process_opt(config::Config &config,
|
||||
const std::string arg)
|
||||
parse_and_process_minfreespace(const std::string &value,
|
||||
size_t &minfreespace)
|
||||
{
|
||||
int rv = 0;
|
||||
std::vector<std::string> argvalue;
|
||||
Policy &policy = config.policy;
|
||||
int rv;
|
||||
|
||||
split(argvalue,arg,'=');
|
||||
rv = num::to_size_t(value,minfreespace);
|
||||
if(rv == -1)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_moveonenospc(const std::string &value,
|
||||
bool &moveonenospc)
|
||||
{
|
||||
if(value == "false")
|
||||
moveonenospc = false;
|
||||
else if(value == "true")
|
||||
moveonenospc = true;
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_arg(Config &config,
|
||||
const std::string &arg,
|
||||
fuse_args *outargs)
|
||||
{
|
||||
if(arg == "defaults")
|
||||
{
|
||||
set_default_options(*outargs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_kv_arg(Config &config,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
{
|
||||
int rv = -1;
|
||||
std::vector<std::string> keypart;
|
||||
|
||||
str::split(keypart,key,'.');
|
||||
if(keypart.size() == 2)
|
||||
{
|
||||
if(keypart[0] == "func")
|
||||
rv = config.set_func_policy(keypart[1],value);
|
||||
else if(keypart[0] == "category")
|
||||
rv = config.set_category_policy(keypart[1],value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(key == "minfreespace")
|
||||
rv = parse_and_process_minfreespace(value,config.minfreespace);
|
||||
else if(key == "moveonenospc")
|
||||
rv = parse_and_process_moveonenospc(value,config.moveonenospc);
|
||||
}
|
||||
|
||||
if(rv == -1)
|
||||
rv = 1;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
process_opt(Config &config,
|
||||
const std::string &arg,
|
||||
fuse_args *outargs)
|
||||
{
|
||||
int rv;
|
||||
std::vector<std::string> argvalue;
|
||||
|
||||
str::split(argvalue,arg,'=');
|
||||
switch(argvalue.size())
|
||||
{
|
||||
case 1:
|
||||
rv = parse_and_process_arg(config,argvalue[0],outargs);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(argvalue[0] == "statfs")
|
||||
policy.statfs.fromString(argvalue[1]);
|
||||
else if(argvalue[0] == "create")
|
||||
policy.create.fromString(argvalue[1]);
|
||||
else if(argvalue[0] == "search")
|
||||
policy.search.fromString(argvalue[1]);
|
||||
else if(argvalue[0] == "action")
|
||||
policy.action.fromString(argvalue[1]);
|
||||
else
|
||||
rv = 1;
|
||||
rv = parse_and_process_kv_arg(config,argvalue[0],argvalue[1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
case 1:
|
||||
if(argvalue[0] == "test")
|
||||
config.testmode = true;
|
||||
else
|
||||
rv = 1;
|
||||
rv = 1;
|
||||
break;
|
||||
};
|
||||
|
||||
@@ -94,30 +209,99 @@ process_opt(config::Config &config,
|
||||
|
||||
static
|
||||
int
|
||||
option_processor(void *data,
|
||||
const char *arg,
|
||||
int key,
|
||||
struct fuse_args *outargs)
|
||||
process_srcmounts(const char *arg,
|
||||
Config &config)
|
||||
{
|
||||
int rv = 0;
|
||||
config::Config &config = *(config::Config*)data;
|
||||
vector<string> paths;
|
||||
|
||||
str::split(paths,arg,':');
|
||||
|
||||
fs::glob(paths,config.srcmounts);
|
||||
|
||||
fs::realpathize(config.srcmounts);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
process_destmounts(const char *arg,
|
||||
Config &config)
|
||||
{
|
||||
config.destmount = arg;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
std::cout <<
|
||||
"Usage: mergerfs [options] <srcpaths> <destpath>\n"
|
||||
"\n"
|
||||
" -o [opt,...] mount options\n"
|
||||
" -h --help print help\n"
|
||||
" -v --version print version\n"
|
||||
"\n"
|
||||
"mergerfs options:\n"
|
||||
" <srcpaths> ':' delimited list of directories. Supports\n"
|
||||
" shell globbing (must be escaped in shell)\n"
|
||||
" -o defaults default FUSE options which seem to provide the\n"
|
||||
" best performance: atomic_o_trunc, auto_cache,\n"
|
||||
" big_writes, default_permissions, splice_read,\n"
|
||||
" splice_write, splice_move\n"
|
||||
" -o direct_io bypass additional caching, increases write\n"
|
||||
" speeds at the cost of reads\n"
|
||||
" -o minfreespace=<int> minimum free space needed for certain policies:\n"
|
||||
" default 4G\n"
|
||||
" -o moveonenospc=<bool> try to move file to another drive when ENOSPC\n"
|
||||
" on write: default false\n"
|
||||
" -o func.<f>=<p> set function <f> to policy <p>\n"
|
||||
" -o category.<c>=<p> set functions in category <c> to <p>\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
version(void)
|
||||
{
|
||||
std::cout << "mergerfs version: " << MERGERFS_VERSION
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
option_processor(void *data,
|
||||
const char *arg,
|
||||
int key,
|
||||
fuse_args *outargs)
|
||||
{
|
||||
int rv = 0;
|
||||
Config &config = *(Config*)data;
|
||||
|
||||
switch(key)
|
||||
{
|
||||
case FUSE_OPT_KEY_OPT:
|
||||
rv = process_opt(config,arg);
|
||||
rv = process_opt(config,arg,outargs);
|
||||
break;
|
||||
|
||||
case FUSE_OPT_KEY_NONOPT:
|
||||
if(config.destmount.empty())
|
||||
{
|
||||
rv = 1;
|
||||
config.destmount = arg;
|
||||
}
|
||||
else
|
||||
{
|
||||
split(config.srcmounts,arg,':');
|
||||
}
|
||||
rv = config.srcmounts.empty() ?
|
||||
process_srcmounts(arg,config) :
|
||||
process_destmounts(arg,config);
|
||||
break;
|
||||
|
||||
case MERGERFS_OPT_HELP:
|
||||
usage();
|
||||
close(2);
|
||||
dup(1);
|
||||
fuse_opt_add_arg(outargs,"-ho");
|
||||
break;
|
||||
|
||||
case MERGERFS_OPT_VERSION:
|
||||
version();
|
||||
fuse_opt_add_arg(outargs,"--version");
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -132,14 +316,26 @@ namespace mergerfs
|
||||
namespace options
|
||||
{
|
||||
void
|
||||
parse(struct fuse_args &args,
|
||||
config::Config &config)
|
||||
parse(fuse_args &args,
|
||||
Config &config)
|
||||
{
|
||||
const struct fuse_opt opts[] =
|
||||
{
|
||||
FUSE_OPT_KEY("-h",MERGERFS_OPT_HELP),
|
||||
FUSE_OPT_KEY("--help",MERGERFS_OPT_HELP),
|
||||
FUSE_OPT_KEY("-v",MERGERFS_OPT_VERSION),
|
||||
FUSE_OPT_KEY("--version",MERGERFS_OPT_VERSION),
|
||||
{NULL,-1U,0}
|
||||
};
|
||||
|
||||
|
||||
fuse_opt_parse(&args,
|
||||
&config,
|
||||
NULL,
|
||||
opts,
|
||||
::option_processor);
|
||||
config.updateReadStr();
|
||||
|
||||
set_fsname(args,config.srcmounts);
|
||||
set_subtype(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-21
@@ -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 <fuse.h>
|
||||
@@ -31,7 +23,7 @@ namespace mergerfs
|
||||
namespace options
|
||||
{
|
||||
void
|
||||
parse(struct fuse_args &args,
|
||||
mergerfs::config::Config &config);
|
||||
parse(fuse_args &args,
|
||||
Config &config);
|
||||
}
|
||||
}
|
||||
|
||||
+67
-287
@@ -1,306 +1,86 @@
|
||||
/*
|
||||
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 <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "buildvector.hpp"
|
||||
|
||||
#define POLICY(X) (Policy(Policy::Enum::X,#X,Policy::Func::X))
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
Policy::Create::Create(Type value)
|
||||
const std::vector<Policy> Policy::_policies_ =
|
||||
buildvector<Policy,true>
|
||||
(POLICY(invalid))
|
||||
(POLICY(all))
|
||||
(POLICY(einval))
|
||||
(POLICY(enosys))
|
||||
(POLICY(enotsup))
|
||||
(POLICY(epmfs))
|
||||
(POLICY(erofs))
|
||||
(POLICY(exdev))
|
||||
(POLICY(ff))
|
||||
(POLICY(ffwp))
|
||||
(POLICY(fwfs))
|
||||
(POLICY(lfs))
|
||||
(POLICY(mfs))
|
||||
(POLICY(newest))
|
||||
(POLICY(rand));
|
||||
|
||||
const Policy * const Policy::policies = &_policies_[1];
|
||||
|
||||
#define CONST_POLICY(X) const Policy &Policy::X = Policy::policies[Policy::Enum::X]
|
||||
|
||||
CONST_POLICY(invalid);
|
||||
CONST_POLICY(all);
|
||||
CONST_POLICY(einval);
|
||||
CONST_POLICY(enosys);
|
||||
CONST_POLICY(enotsup);
|
||||
CONST_POLICY(epmfs);
|
||||
CONST_POLICY(erofs);
|
||||
CONST_POLICY(exdev);
|
||||
CONST_POLICY(ff);
|
||||
CONST_POLICY(ffwp);
|
||||
CONST_POLICY(fwfs);
|
||||
CONST_POLICY(lfs);
|
||||
CONST_POLICY(mfs);
|
||||
CONST_POLICY(newest);
|
||||
CONST_POLICY(rand);
|
||||
|
||||
const Policy&
|
||||
Policy::find(const std::string &str)
|
||||
{
|
||||
*this = value;
|
||||
}
|
||||
|
||||
Policy::Create&
|
||||
Policy::Create::operator=(const Policy::Create::Type value)
|
||||
{
|
||||
_str = toString(value);
|
||||
_value = fromString(_str);
|
||||
_func = findFunc(_value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::Create&
|
||||
Policy::Create::operator=(const std::string str)
|
||||
{
|
||||
_value = fromString(str);
|
||||
_str = toString(_value);
|
||||
_func = findFunc(_value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::Create::Type
|
||||
Policy::Create::fromString(const std::string str)
|
||||
{
|
||||
if(str == "ep")
|
||||
return Policy::Create::ExistingPath;
|
||||
else if(str == "mfs")
|
||||
return Policy::Create::MostFreeSpace;
|
||||
else if(str == "epmfs")
|
||||
return Policy::Create::ExistingPathMostFreeSpace;
|
||||
else if(str == "rand")
|
||||
return Policy::Create::Random;
|
||||
|
||||
return Policy::Create::Invalid;
|
||||
}
|
||||
|
||||
std::string
|
||||
Policy::Create::toString(const Type value)
|
||||
{
|
||||
switch(value)
|
||||
for(int i = Enum::BEGIN; i != Enum::END; ++i)
|
||||
{
|
||||
case Policy::Create::ExistingPath:
|
||||
return "ep";
|
||||
case Policy::Create::ExistingPathMostFreeSpace:
|
||||
return "epmfs";
|
||||
case Policy::Create::MostFreeSpace:
|
||||
return "mfs";
|
||||
case Policy::Create::Random:
|
||||
return "rand";
|
||||
case Policy::Create::Invalid:
|
||||
default:
|
||||
return "invalid";
|
||||
if(policies[i] == str)
|
||||
return policies[i];
|
||||
}
|
||||
|
||||
return invalid;
|
||||
}
|
||||
|
||||
Policy::Create::Func
|
||||
Policy::Create::findFunc(Policy::Create::Type value)
|
||||
const Policy&
|
||||
Policy::find(const Policy::Enum::Type i)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case Policy::Create::ExistingPath:
|
||||
return fs::find_first;
|
||||
case Policy::Create::ExistingPathMostFreeSpace:
|
||||
return fs::find_mfs_existing;
|
||||
case Policy::Create::MostFreeSpace:
|
||||
return fs::find_mfs;
|
||||
case Policy::Create::Random:
|
||||
return fs::find_random;
|
||||
case Policy::Create::Invalid:
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if(i >= Policy::Enum::BEGIN &&
|
||||
i < Policy::Enum::END)
|
||||
return policies[i];
|
||||
|
||||
Policy::Search::Search(Type value)
|
||||
{
|
||||
*this = value;
|
||||
}
|
||||
|
||||
Policy::Search&
|
||||
Policy::Search::operator=(const Policy::Search::Type value)
|
||||
{
|
||||
_str = toString(value);
|
||||
_value = fromString(_str);
|
||||
_func = findFunc(_value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::Search&
|
||||
Policy::Search::operator=(const std::string str)
|
||||
{
|
||||
_value = fromString(str);
|
||||
_str = toString(_value);
|
||||
_func = findFunc(_value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::Search::Type
|
||||
Policy::Search::fromString(const std::string str)
|
||||
{
|
||||
if(str == "ff")
|
||||
return Policy::Search::FirstFound;
|
||||
else if(str == "ffwp")
|
||||
return Policy::Search::FirstFoundWithPermissions;
|
||||
else if(str == "newest")
|
||||
return Policy::Search::Newest;
|
||||
|
||||
return Policy::Search::Invalid;
|
||||
}
|
||||
|
||||
std::string
|
||||
Policy::Search::toString(Policy::Search::Type value)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case Policy::Search::FirstFound:
|
||||
return "ff";
|
||||
case Policy::Search::FirstFoundWithPermissions:
|
||||
return "ffwp";
|
||||
case Policy::Search::Newest:
|
||||
return "newest";
|
||||
case Policy::Search::Invalid:
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
Policy::Search::Func
|
||||
Policy::Search::findFunc(Policy::Search::Type value)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case Policy::Search::FirstFound:
|
||||
return fs::find_first;
|
||||
case Policy::Search::FirstFoundWithPermissions:
|
||||
return fs::find_first_with_permission;
|
||||
case Policy::Search::Newest:
|
||||
return fs::find_newest;
|
||||
case Policy::Search::Invalid:
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Policy::Action::Action(const Policy::Action::Type value)
|
||||
{
|
||||
*this = value;
|
||||
}
|
||||
|
||||
Policy::Action&
|
||||
Policy::Action::operator=(const Policy::Action::Type value)
|
||||
{
|
||||
_str = toString(value);
|
||||
_value = fromString(_str);
|
||||
_func = findFunc(_value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::Action&
|
||||
Policy::Action::operator=(const std::string str)
|
||||
{
|
||||
_value = fromString(str);
|
||||
_str = toString(_value);
|
||||
_func = findFunc(_value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::Action::Type
|
||||
Policy::Action::fromString(const std::string str)
|
||||
{
|
||||
if(str == "ff")
|
||||
return Policy::Action::FirstFound;
|
||||
else if(str == "ffwp")
|
||||
return Policy::Action::FirstFoundWithPermissions;
|
||||
else if(str == "newest")
|
||||
return Policy::Action::Newest;
|
||||
else if(str == "all")
|
||||
return Policy::Action::All;
|
||||
|
||||
return Policy::Action::Invalid;
|
||||
}
|
||||
|
||||
std::string
|
||||
Policy::Action::toString(Policy::Action::Type value)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case Policy::Action::FirstFound:
|
||||
return "ff";
|
||||
case Policy::Action::FirstFoundWithPermissions:
|
||||
return "ffwp";
|
||||
case Policy::Action::Newest:
|
||||
return "newest";
|
||||
case Policy::Action::All:
|
||||
return "all";
|
||||
case Policy::Action::Invalid:
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
Policy::Action::Func
|
||||
Policy::Action::findFunc(const Policy::Action::Type value)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case Policy::Action::FirstFound:
|
||||
return fs::find_first;
|
||||
case Policy::Action::FirstFoundWithPermissions:
|
||||
return fs::find_first_with_permission;
|
||||
case Policy::Action::Newest:
|
||||
return fs::find_newest;
|
||||
case Policy::Action::All:
|
||||
return fs::find_all;
|
||||
case Policy::Action::Invalid:
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Policy::StatFS::StatFS(const Policy::StatFS::Type value)
|
||||
{
|
||||
*this = value;
|
||||
}
|
||||
|
||||
Policy::StatFS&
|
||||
Policy::StatFS::operator=(Policy::StatFS::Type value)
|
||||
{
|
||||
_str = toString(value);
|
||||
_value = fromString(_str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::StatFS&
|
||||
Policy::StatFS::operator=(const std::string str)
|
||||
{
|
||||
_value = fromString(str);
|
||||
_str = toString(_value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Policy::StatFS::Type
|
||||
Policy::StatFS::fromString(const std::string str)
|
||||
{
|
||||
if(str == "susf")
|
||||
return Policy::StatFS::SumUsedSumFree;
|
||||
else if(str == "sumf")
|
||||
return Policy::StatFS::SumUsedMaxFree;
|
||||
|
||||
return Policy::StatFS::Invalid;
|
||||
}
|
||||
|
||||
std::string
|
||||
Policy::StatFS::toString(const Policy::StatFS::Type value)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case Policy::StatFS::SumUsedSumFree:
|
||||
return "susf";
|
||||
case Policy::StatFS::SumUsedMaxFree:
|
||||
return "sumf";
|
||||
case Policy::StatFS::Invalid:
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
return invalid;
|
||||
}
|
||||
}
|
||||
|
||||
+159
-176
@@ -1,206 +1,189 @@
|
||||
/*
|
||||
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 __POLICY_HPP__
|
||||
#define __POLICY_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "category.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
class Policy
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
struct Enum
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
invalid = -1,
|
||||
BEGIN = 0,
|
||||
all = BEGIN,
|
||||
einval,
|
||||
enosys,
|
||||
enotsup,
|
||||
epmfs,
|
||||
erofs,
|
||||
exdev,
|
||||
ff,
|
||||
ffwp,
|
||||
fwfs,
|
||||
lfs,
|
||||
mfs,
|
||||
newest,
|
||||
rand,
|
||||
END
|
||||
};
|
||||
|
||||
static size_t begin() { return BEGIN; }
|
||||
static size_t end() { return END; }
|
||||
};
|
||||
|
||||
struct Func
|
||||
{
|
||||
typedef std::string string;
|
||||
typedef std::size_t size_t;
|
||||
typedef std::vector<string> strvec;
|
||||
typedef const string cstring;
|
||||
typedef const size_t csize_t;
|
||||
typedef const strvec cstrvec;
|
||||
typedef const Category::Enum::Type CType;
|
||||
|
||||
typedef int (*Ptr)(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
|
||||
template <CType T>
|
||||
class Base
|
||||
{
|
||||
STATFS,
|
||||
ACTION,
|
||||
CREATE,
|
||||
SEARCH
|
||||
public:
|
||||
Base(const Policy *p)
|
||||
: func(p->_func)
|
||||
{}
|
||||
|
||||
int
|
||||
operator()(cstrvec& b,cstring& c,csize_t d,strvec& e)
|
||||
{
|
||||
return func(T,b,c,d,e);
|
||||
}
|
||||
|
||||
int
|
||||
operator()(cstrvec& b,cstring& c,csize_t d,string& e)
|
||||
{
|
||||
int rv;
|
||||
strvec vec;
|
||||
|
||||
rv = func(T,b,c,d,vec);
|
||||
if(!vec.empty())
|
||||
e = vec[0];
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
private:
|
||||
const Ptr func;
|
||||
};
|
||||
|
||||
public:
|
||||
class StatFS
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
Invalid = -1,
|
||||
SumUsedSumFree,
|
||||
SumUsedMaxFree,
|
||||
Max
|
||||
};
|
||||
typedef Base<Category::Enum::action> Action;
|
||||
typedef Base<Category::Enum::create> Create;
|
||||
typedef Base<Category::Enum::search> Search;
|
||||
|
||||
StatFS(Type _value);
|
||||
|
||||
public:
|
||||
operator Type() const { return _value; }
|
||||
operator std::string() const { return _str; }
|
||||
std::string str() const { return _str; }
|
||||
|
||||
StatFS& operator=(const Type);
|
||||
StatFS& operator=(const std::string);
|
||||
|
||||
static Type fromString(const std::string);
|
||||
static std::string toString(const Type);
|
||||
|
||||
private:
|
||||
StatFS();
|
||||
|
||||
private:
|
||||
Type _value;
|
||||
std::string _str;
|
||||
static int all(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int einval(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int enosys(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int enotsup(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int epmfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int erofs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int exdev(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int ff(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int ffwp(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int fwfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int lfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int mfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int newest(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int rand(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
};
|
||||
|
||||
class Create
|
||||
{
|
||||
public:
|
||||
typedef fs::SearchFunc Func;
|
||||
enum Type
|
||||
{
|
||||
Invalid = -1,
|
||||
ExistingPath,
|
||||
MostFreeSpace,
|
||||
ExistingPathMostFreeSpace,
|
||||
Random,
|
||||
Max
|
||||
};
|
||||
|
||||
public:
|
||||
Create(Type);
|
||||
|
||||
operator Type() const { return _value; }
|
||||
operator Func() const { return _func; }
|
||||
operator std::string() const { return _str; }
|
||||
std::string str() const { return _str; }
|
||||
|
||||
Create& operator=(const Type);
|
||||
Create& operator=(const std::string);
|
||||
|
||||
static Type fromString(const std::string);
|
||||
static std::string toString(const Type);
|
||||
static Func findFunc(const Type);
|
||||
|
||||
private:
|
||||
Create();
|
||||
|
||||
private:
|
||||
Type _value;
|
||||
std::string _str;
|
||||
Func _func;
|
||||
};
|
||||
|
||||
class Search
|
||||
{
|
||||
public:
|
||||
typedef fs::SearchFunc Func;
|
||||
enum Type
|
||||
{
|
||||
Invalid = -1,
|
||||
FirstFound,
|
||||
FirstFoundWithPermissions,
|
||||
Newest,
|
||||
Max
|
||||
};
|
||||
|
||||
public:
|
||||
Search(Type);
|
||||
|
||||
operator Type() const { return _value; }
|
||||
operator Func() const { return _func; }
|
||||
operator std::string() const { return _str; }
|
||||
std::string str() const { return _str; }
|
||||
|
||||
Search& operator=(const Type);
|
||||
Search& operator=(const std::string);
|
||||
|
||||
static Type fromString(const std::string);
|
||||
static std::string toString(const Type);
|
||||
static Func findFunc(const Type);
|
||||
|
||||
private:
|
||||
Search();
|
||||
|
||||
private:
|
||||
Type _value;
|
||||
std::string _str;
|
||||
Func _func;
|
||||
};
|
||||
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
typedef fs::VecSearchFunc Func;
|
||||
enum Type
|
||||
{
|
||||
Invalid = -1,
|
||||
FirstFound,
|
||||
FirstFoundWithPermissions,
|
||||
Newest,
|
||||
All,
|
||||
Max
|
||||
};
|
||||
|
||||
public:
|
||||
Action(Type);
|
||||
|
||||
operator Type() const { return _value; }
|
||||
operator Func() const { return _func; }
|
||||
operator std::string() const { return _str; }
|
||||
std::string str() const { return _str; }
|
||||
|
||||
Action& operator=(const Type);
|
||||
Action& operator=(const std::string);
|
||||
|
||||
static Type fromString(const std::string);
|
||||
static std::string toString(const Type);
|
||||
static Func findFunc(const Type);
|
||||
|
||||
private:
|
||||
Action();
|
||||
|
||||
private:
|
||||
Type _value;
|
||||
std::string _str;
|
||||
Func _func;
|
||||
};
|
||||
private:
|
||||
Enum::Type _enum;
|
||||
std::string _str;
|
||||
Func::Ptr _func;
|
||||
|
||||
public:
|
||||
Policy() :
|
||||
statfs(StatFS::SumUsedMaxFree),
|
||||
create(Create::ExistingPathMostFreeSpace),
|
||||
search(Search::FirstFound),
|
||||
action(Action::FirstFound)
|
||||
{}
|
||||
Policy()
|
||||
: _enum(invalid),
|
||||
_str(invalid),
|
||||
_func(invalid)
|
||||
{
|
||||
}
|
||||
|
||||
Policy(const Enum::Type enum_,
|
||||
const std::string &str_,
|
||||
const Func::Ptr func_)
|
||||
: _enum(enum_),
|
||||
_str(str_),
|
||||
_func(func_)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
StatFS statfs;
|
||||
Create create;
|
||||
Search search;
|
||||
Action action;
|
||||
operator const Enum::Type() const { return _enum; }
|
||||
operator const std::string&() const { return _str; }
|
||||
operator const Func::Ptr() const { return _func; }
|
||||
operator const Policy*() const { return this; }
|
||||
|
||||
bool operator==(const Enum::Type enum_) const
|
||||
{ return _enum == enum_; }
|
||||
bool operator==(const std::string &str_) const
|
||||
{ return _str == str_; }
|
||||
bool operator==(const Func::Ptr func_) const
|
||||
{ return _func == func_; }
|
||||
|
||||
bool operator!=(const Policy &r) const
|
||||
{ return _enum != r._enum; }
|
||||
|
||||
bool operator<(const Policy &r) const
|
||||
{ return _enum < r._enum; }
|
||||
|
||||
public:
|
||||
static const Policy &find(const std::string&);
|
||||
static const Policy &find(const Enum::Type);
|
||||
|
||||
public:
|
||||
static const std::vector<Policy> _policies_;
|
||||
static const Policy * const policies;
|
||||
|
||||
static const Policy &invalid;
|
||||
static const Policy &all;
|
||||
static const Policy &einval;
|
||||
static const Policy &enosys;
|
||||
static const Policy &enotsup;
|
||||
static const Policy &epmfs;
|
||||
static const Policy &erofs;
|
||||
static const Policy &exdev;
|
||||
static const Policy &ff;
|
||||
static const Policy &ffwp;
|
||||
static const Policy &fwfs;
|
||||
static const Policy &lfs;
|
||||
static const Policy &mfs;
|
||||
static const Policy &newest;
|
||||
static const Policy &rand;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_all(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == 0)
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
|
||||
if(paths.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_all_create(const vector<string> &basepaths,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(basepaths.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths = basepaths;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::all(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _all_create(basepaths,paths);
|
||||
|
||||
return _all(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::einval(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=EINVAL,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::enosys(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=ENOSYS,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::enotsup(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=ENOTSUP,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
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.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
typedef struct statvfs statvfs_t;
|
||||
|
||||
static
|
||||
inline
|
||||
void
|
||||
_calc_mfs(const statvfs_t &fsstats,
|
||||
const string &basepath,
|
||||
const size_t minfreespace,
|
||||
fsblkcnt_t &mfs,
|
||||
string &mfsbasepath)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if((spaceavail > minfreespace) && (spaceavail > mfs))
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfsbasepath = basepath;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epmfs_create(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
|
||||
{
|
||||
int rv;
|
||||
fsblkcnt_t epmfs;
|
||||
string epmfsbasepath;
|
||||
string fullpath;
|
||||
statvfs_t fsstats;
|
||||
|
||||
epmfs = 0;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
_calc_mfs(fsstats,basepath,minfreespace,epmfs,epmfsbasepath);
|
||||
}
|
||||
|
||||
if(epmfsbasepath.empty())
|
||||
return Policy::Func::mfs(Category::Enum::create,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
paths.push_back(epmfsbasepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epmfs(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
|
||||
{
|
||||
int rv;
|
||||
fsblkcnt_t epmfs;
|
||||
string epmfsbasepath;
|
||||
string fullpath;
|
||||
statvfs_t fsstats;
|
||||
|
||||
epmfs = 0;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
_calc_mfs(fsstats,basepath,0,epmfs,epmfsbasepath);
|
||||
}
|
||||
|
||||
if(epmfsbasepath.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(epmfsbasepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::epmfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _epmfs_create(basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _epmfs(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::erofs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=EROFS,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::exdev(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=EXDEV,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_ff(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string fullpath;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (errno=ENOENT,-1);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_ff_create(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(basepaths.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(basepaths[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::ff(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _ff_create(basepaths,fusepath,paths);
|
||||
|
||||
return _ff(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_ffwp(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
string fallback;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string fullpath;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == 0)
|
||||
{
|
||||
paths.push_back(basepath);
|
||||
return 0;
|
||||
}
|
||||
else if(errno == EACCES)
|
||||
{
|
||||
fallback = basepath;
|
||||
}
|
||||
}
|
||||
|
||||
if(fallback.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(fallback);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::ffwp(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return _ffwp(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
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 <sys/statvfs.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_fwfs_create(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_fwfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::fwfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _fwfs_create(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _fwfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
@@ -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 <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::invalid(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &rv)
|
||||
{
|
||||
return (errno=EINVAL,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_lfs_create(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t lfs;
|
||||
string lfsstr;
|
||||
|
||||
lfs = -1;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if((spaceavail > minfreespace) &&
|
||||
(spaceavail < lfs))
|
||||
{
|
||||
lfs = spaceavail;
|
||||
lfsstr = basepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(lfsstr.empty())
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
paths.push_back(lfsstr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_lfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t lfs;
|
||||
string lfsstr;
|
||||
|
||||
lfs = -1;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if((spaceavail > minfreespace) &&
|
||||
(spaceavail < lfs))
|
||||
{
|
||||
lfs = spaceavail;
|
||||
lfsstr = basepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(lfsstr.empty())
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
paths.push_back(lfsstr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::lfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _lfs_create(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _lfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user