Compare commits

...
74 Commits
Author SHA1 Message Date
Antonio SJ Musumeci f844daa76c Merge pull request #145 from trapexit/debswap
swap deb and unsigned-deb make tagets. closes #140
2015-09-26 14:14:04 -04:00
Antonio SJ Musumeci c289dafadc swap deb and unsigned-deb make tagets. closes #140 2015-09-26 14:12:10 -04:00
Antonio SJ Musumeci 2e538068ef Merge pull request #144 from trapexit/enospc
move on enospc when writing feature. closes #141
2015-09-25 15:41:24 -04:00
Antonio SJ Musumeci 5808ab7795 move on enospc when writing feature. closes #141
This feature mimics the standard mhddfs behavior but is more thorough.
If a write fails and the errno is set to ENOSPC then mergerfs will (if
the feature is enabled) attempt to move the file to the drive with
the most free space but only if it has enough room for the file plus
the amount to be written. If that transfer is successful it will then
unlink the original file and attempt the previously failed write again.

The copy includes copying the path and file including the acls, owners,
attributes, extended attributes, and timestamps.
2015-09-25 15:14:17 -04:00
Antonio SJ Musumeci 4e5578de9c make note about escaping glob tokens more explicit 2015-09-25 13:48:03 -04:00
Antonio SJ Musumeci 4b375faf12 include rpm-build in Fedora dependencies 2015-09-24 17:59:49 -04:00
Antonio SJ Musumeci 9542e6340b include link to release page in readme 2015-09-24 15:07:39 -04:00
Antonio SJ Musumeci de583b70f7 clean up options listing 2015-09-23 16:42:36 -04:00
Antonio SJ Musumeci 8bf0f755e1 create summary feature section
And tweak intro.
2015-09-22 12:46:47 -04:00
Antonio SJ Musumeci 5850fbe3f1 bump README date 2015-09-14 22:45:45 -04:00
Antonio SJ Musumeci 1cc1b1f746 Merge pull request #139 from trapexit/setxattr-cleanup
cleanup controlfile manipulation
2015-09-14 22:42:06 -04:00
Antonio SJ Musumeci a960a7ef46 cleanup controlfile manipulation 2015-09-14 22:40:49 -04:00
Antonio SJ Musumeci 9afd0654b7 Merge pull request #138 from trapexit/defaults
include default_permissions in default arguments
2015-09-14 22:13:37 -04:00
Antonio SJ Musumeci e0cf97261c include default_permissions in default arguments
closes #130
2015-09-14 22:12:24 -04:00
Antonio SJ Musumeci 1782910437 Merge pull request #137 from trapexit/setgroups-docs
change README regarding setgroups cache and new rwlock ugid fallback
2015-09-14 19:34:22 -04:00
Antonio SJ Musumeci f4e3f28153 change README regarding setgroups cache and new rwlock ugid fallback 2015-09-14 19:33:30 -04:00
Antonio SJ Musumeci 6a96d3b69b Merge pull request #136 from trapexit/typo
fix typo in README
2015-09-14 19:06:37 -04:00
Antonio SJ Musumeci 08c0c2dfae fix typo in README. closes #134 2015-09-14 19:05:42 -04:00
Antonio SJ Musumeci ad5380d69e Merge pull request #135 from trapexit/op-ugid
make changing credentials opportunistic + per thread setgroups cache
2015-09-14 19:01:23 -04:00
Antonio SJ Musumeci 3163258a33 make changing credentials opportunistic + per thread setgroups cache
closes #129,#131
2015-09-14 19:00:07 -04:00
Antonio SJ Musumeci b194272e39 add notes on permissions and errors to readme 2015-09-08 18:06:32 -04:00
Antonio SJ Musumeci c131310c55 include known issues section to readme 2015-09-07 19:58:10 -04:00
Antonio SJ Musumeci 8323e16ad2 Merge pull request #126 from trapexit/realpathize
realpath'ize all source mount points. closes #117
2015-09-06 18:25:21 -04:00
Antonio SJ Musumeci ce9352987c realpath'ize all source mount points. closes #117 2015-09-06 18:24:36 -04:00
Antonio SJ Musumeci accd2d4ae0 Merge pull request #125 from trapexit/xattr-minfreespace
fix non-suffixed setxattr of user.mergerfs.minfreespace
2015-09-06 12:07:43 -04:00
Antonio SJ Musumeci 2d899479c3 fix non-suffixed setxattr of user.mergerfs.minfreespace 2015-09-05 23:08:11 -04:00
Antonio SJ Musumeci 803b2ae999 Merge pull request #122 from trapexit/clean-version
remove version.hpp on clean
2015-09-05 22:30:49 -04:00
Antonio SJ Musumeci e98b801c9d remove version.hpp on clean 2015-09-05 22:29:28 -04:00
Antonio SJ Musumeci 27cf7f8148 Merge pull request #121 from trapexit/xattr-version
add user.mergerfs.version xattr
2015-09-05 21:55:43 -04:00
Antonio SJ Musumeci b22528bac4 add user.mergerfs.version xattr 2015-09-05 21:48:15 -04:00
Antonio SJ Musumeci adf983c8c3 Merge pull request #120 from trapexit/policies-xattr
add user.mergerfs.policies xattr
2015-09-05 20:04:12 -04:00
Antonio SJ Musumeci e377d54c93 add user.mergerfs.policies xattr 2015-09-05 19:49:08 -04:00
Antonio SJ Musumeci 7bee6230ba Merge pull request #119 from trapexit/rpm
add building of rpm
2015-09-05 18:44:14 -04:00
Antonio SJ Musumeci 08d07b71e1 add building of rpm 2015-09-05 18:41:18 -04:00
Antonio SJ Musumeci ce2462042f Merge pull request #118 from trapexit/basic-fedora-build
add basic instructions for building on Fedora
2015-09-05 16:35:40 -04:00
Antonio SJ Musumeci 305f190f09 add basic instructions for building on Fedora 2015-09-05 16:34:59 -04:00
Antonio SJ Musumeci d89735abf6 Merge pull request #114 from trapexit/xattr
refactor and simplify getxattr for user.mergerfs.\*
2015-09-03 17:24:57 -04:00
Antonio SJ Musumeci 8178bf518c refactor and simplify getxattr for user.mergerfs.\* 2015-09-03 16:56:54 -04:00
Antonio SJ Musumeci 22d254e8df Merge pull request #113 from trapexit/git2dbcl
use correct variable for finding version
2015-09-02 08:02:26 -04:00
Antonio SJ Musumeci aea5e440d7 use correct variable for finding version 2015-09-02 08:02:12 -04:00
Antonio SJ Musumeci 908a2f61f7 Merge pull request #112 from trapexit/epmfs+minfreespace
add minfreespace check to epmfs create policy
2015-09-01 22:37:45 -04:00
Antonio SJ Musumeci bc77b0fd2a add minfreespace check to epmfs create policy 2015-09-01 22:28:35 -04:00
Antonio SJ Musumeci 4141181243 Merge pull request #111 from trapexit/rename
rework rename
2015-09-01 18:35:22 -04:00
Antonio SJ Musumeci 1f1e481075 rework rename
Return EXDEV if directories of tragets differ. If the old and new path exist in the same directory first rename each old found by the policy and then unlink/rmdir any new on a drive which didn't rename. The unlink/rmdir will occur only if there were no rename errors. Any failures of unlink/rmdir are ignored. The last rename error is returned.
2015-09-01 18:32:31 -04:00
Antonio SJ Musumeci 6b5b7c38f4 Merge pull request #109 from trapexit/einval
forgot to add einval to policy
2015-08-30 17:08:58 -04:00
Antonio SJ Musumeci 7a93198d4a forgot to add einval to policy 2015-08-30 17:08:24 -04:00
Antonio SJ Musumeci fd26793305 Merge pull request #108 from trapexit/error-policies
create errno policies for simulating errors. closes #107
2015-08-27 22:52:20 -04:00
Antonio SJ Musumeci bbc75f6ff1 create errno policies for simulating errors. closes #107 2015-08-27 22:38:23 -04:00
Antonio SJ Musumeci cac5f1b827 Merge pull request #106 from trapexit/epmfs-fix
fix epmfs failing to pick the existing path. closes #102
2015-08-24 15:52:47 -04:00
Antonio SJ Musumeci 126df0fbf1 fix epmfs failing to pick the existing path. closes #102 2015-08-24 15:51:17 -04:00
Antonio SJ Musumeci 2cc9b42c9c Merge pull request #101 from trapexit/buildupdate
enhance deb building
2015-08-07 21:05:52 -04:00
Antonio SJ Musumeci ab68ac0cb1 enhance deb building 2015-08-07 21:03:39 -04:00
Antonio SJ Musumeci f3a3609998 Merge pull request #100 from trapexit/readme
format README better for man pages
2015-08-07 21:02:28 -04:00
Antonio SJ Musumeci e73ea33e9c format README better for man pages 2015-08-07 20:59:43 -04:00
Antonio SJ Musumeci c2164457bc Merge pull request #97 from trapexit/option-docs
update README regarding options
2015-08-05 12:30:14 -04:00
Antonio SJ Musumeci 95192511b1 update README regarding options 2015-08-05 12:29:53 -04:00
Antonio SJ Musumeci 7775d6830c Merge pull request #96 from trapexit/epmfs-fix
remove unused variable
2015-08-05 12:00:03 -04:00
Antonio SJ Musumeci 8767db971a remove unused variable 2015-08-05 11:59:39 -04:00
Antonio SJ Musumeci 838c081b8c Merge pull request #94 from trapexit/config-cleanup
config get and struct naming cleanup
2015-08-05 11:51:33 -04:00
Antonio SJ Musumeci ac41bc43f3 Merge pull request #95 from trapexit/flags
move requesting of FUSE flags to init from cli args
2015-08-05 11:50:54 -04:00
Antonio SJ Musumeci 267f2d291c move requesting of FUSE flags to init from cli args 2015-08-05 11:50:21 -04:00
Antonio SJ Musumeci f130d07fd8 config get and struct naming cleanup 2015-08-05 09:28:53 -04:00
Antonio SJ Musumeci 81dbafdc19 Merge pull request #93 from trapexit/ioctlfixes
passthrough ioctl args without processing. closes #90
2015-08-05 09:23:23 -04:00
Antonio SJ Musumeci 52d80299b5 passthrough ioctl args without processing. closes #90 2015-08-05 09:18:34 -04:00
Antonio SJ Musumeci 416cb4a084 Merge pull request #92 from trapexit/timecompare
use gte rather than gt for mtime comparisons. fixes #91
2015-08-04 14:09:20 -04:00
Antonio SJ Musumeci c60d03831f use gte rather than gt for mtime comparisons. fixes #91 2015-08-04 14:03:44 -04:00
Antonio SJ Musumeci ac03e08d31 Merge pull request #89 from trapexit/openpath
add creation of full path for open
2015-07-16 16:58:14 -04:00
Antonio SJ Musumeci 80b2c35175 add creation of full path for open 2015-07-16 16:57:01 -04:00
Antonio SJ Musumeci f8f63cdbd1 Merge pull request #87 from trapexit/namespaces
change fuse functions to use the fuse namespace
2015-07-15 10:54:23 -04:00
Antonio SJ Musumeci 983fa9100d change fuse functions to use the fuse namespace 2015-07-15 10:53:13 -04:00
Antonio SJ Musumeci efadd2c8d8 Merge pull request #86 from trapexit/readdir-cleanup
remove unused readdir function
2015-07-15 10:51:43 -04:00
Antonio SJ Musumeci c505ec0cdb Merge pull request #85 from trapexit/pthread_getugid_np
use pthread_getugid_np instead of gete{u,g}id on OSX. fixes #84
2015-07-15 10:51:20 -04:00
Antonio SJ Musumeci e5359ebd05 remove unused readdir function 2015-07-15 10:50:25 -04:00
Antonio SJ Musumeci f00cd1467e use pthread_getugid_np instead of gete{u,g}id on OSX. fixes #84 2015-07-15 10:39:47 -04:00
127 changed files with 3537 additions and 1736 deletions
+67 -25
View File
@@ -33,11 +33,14 @@ 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"
$(error "pkg-config not installed")
endif
ifeq ($(PANDOC),"")
@@ -62,6 +65,8 @@ 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)
@@ -71,6 +76,7 @@ MANPAGE = $(TARGET).1
FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
CFLAGS = -g -Wall \
$(OPTS) \
-Wno-unused-result \
$(FUSE_CFLAGS) \
-DFUSE_USE_VERSION=26 \
-MMD \
@@ -78,33 +84,50 @@ CFLAGS = -g -Wall \
-DFALLOCATE=$(FALLOCATE) \
-DFLOCK=$(FLOCK) \
-DREAD_BUF=$(READ_BUF) \
-DWRITE_BUF=$(WRITE_BUF)
-DWRITE_BUF=$(WRITE_BUF) \
-DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
BINDIR = $(PREFIX)/usr/bin
MANDIR = $(PREFIX)/usr/share/man/man1
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
INSTALLMANDIR = $(DESTDIR)$(MANDIR)
PREFIX = /usr/local
EXEC_PREFIX = $(PREFIX)
DATAROOTDIR = $(PREFIX)/share
DATADIR = $(DATAROOTDIR)
BINDIR = $(EXEC_PREFIX)/bin
MANDIR = $(DATAROOTDIR)/man
MAN1DIR = $(MANDIR)/man1
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
ifeq ($(XATTR_AVAILABLE),0)
$(warning "xattr not available: disabling")
CFLAGS += -DWITHOUT_XATTR
endif
all: $(TARGET) clonepath
all: $(TARGET) clone
help:
@echo "usage: make"
@echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
$(TARGET): obj/obj-stamp $(OBJ)
$(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
$(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
clonepath: $(TARGET)
clone: $(TARGET)
$(LN) -s $< $@
changelog:
$(GIT) log --pretty --numstat --summary | git2cl > 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
@@ -113,57 +136,76 @@ obj/obj-stamp:
obj/%.o: src/%.cpp
$(CXX) $(CFLAGS) -c $< -o $@
clean:
clean: rpm-clean
$(RM) -rf obj
$(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
$(FIND) -name "*~" -delete
$(RM) -f src/version.hpp
$(RM) -f "$(TARGET)" "$(MANPAGE)" clone
$(FIND) . -name "*~" -delete
distclean: clean
$(GIT) clean -fd
install: install-base install-clonepath install-man
install: install-base install-clone install-man
install-base: $(TARGET)
$(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
install-clonepath: clonepath
install-clone: clone
$(CP) -a $< "$(INSTALLBINDIR)/$<"
install-man: $(MANPAGE)
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMANDIR)/$(MANPAGE)"
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
install-strip: install-base
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
uninstall: uninstall-base uninstall-clonepath uninstall-man
uninstall: uninstall-base uninstall-clone uninstall-man
uninstall-base:
$(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
uninstall-clonepath:
$(RM) -f "$(INSTALLBINDIR)/clonepath"
uninstall-clone:
$(RM) -f "$(INSTALLBINDIR)/clone"
uninstall-man:
$(RM) -f "$(INSTALLMANDIR)/$(MANPAGE")
$(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
$(MANPAGE): README.md
$(PANDOC) -s -t man -o $(MANPAGE) README.md
man: $(MANPAGE)
tarball: clean changelog man
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)
$(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
$(RM) -rf $(TMPDIR)
deb:
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))
$(GIT2DEBCL) $(TARGET) $(VERSION) > debian/changelog
$(GIT) buildpackage --git-ignore-new
$(eval VERSION := $(subst -,_,$(VERSION)))
$(MKDIR) -p rpmbuild/{BUILD,RPMS,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
+122 -81
View File
@@ -1,6 +1,6 @@
% mergerfs(1) mergerfs user manual
% Antonio SJ Musumeci <trapexit@spawn.link>
% 2015-07-03
% 2015-09-14
# NAME
@@ -12,26 +12,40 @@ mergerfs -o&lt;options&gt; &lt;srcpoints&gt; &lt;mountpoint&gt;
# DESCRIPTION
mergerfs is similar to mhddfs, unionfs, and aufs. Like mhddfs in that it too uses [FUSE](http://en.wikipedia.org/wiki/Filesystem_in_Userspace). Like aufs in that it provides multiple policies for how to handle behavior.
**mergerfs** is similar to **mhddfs**, **unionfs**, and **aufs**. Like **mhddfs** in that it too uses **FUSE**. Like **aufs** in that it provides multiple policies for how to handle behavior.
Why create mergerfs when those exist? mhddfs isn't really maintained or flexible. There are also security issues when with running as root. aufs is more flexible than mhddfs but contains some hard to debug inconsistencies in behavior on account of it being a kernel driver. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
Why **mergerfs** when those exist? **mhddfs** has not been updated in some time nor very flexible. There are also security issues when with running as root. **aufs** is more flexible than **mhddfs** but kernel based and difficult to debug when problems arise and slower to evolve as a result. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
# FEATURES
* Runs in userspace (FUSE)
* Configurable behaviors
* Supports extended attributes (xattrs)
* Supports file attributes (chattr)
* Dynamically configurable (via xattrs)
* Safe to run as root
* Opportunistic credential caching
* Works with heterogeneous filesystem types
# OPTIONS
###options###
* `defaults` is a shortcut for `big_writes`, `auto_cache`, `atomic_o_trunc`, `splice_read`, `splice_write`, and `splice_move`. These options seem to provide the best performance.
* `minfreespace` (defaults to `4G`) is the minimum space value used for the `lfs` and `fwfs` policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively.
* All [FUSE](http://fuse.sourceforge.net) functions which have a category (see below) are option keys. The syntax being `func.<func>=<policy>`.
* To set all function policies in a category use `category.<category>=<policy>` such as `category.create=mfs`.
* They are evaluated in the order listed so if the options are `func.rmdir=rand,category.action=ff` the `action` category setting will override the `rmdir` setting.
* **defaults**: a shortcut for FUSE's **atomic_o_trunc**, **auto_cache**, **big_writes**, **default_permissions**, **splice_move**, **splice_read**, and **splice_write**. These options seem to provide the best performance.
* **direct_io**: causes FUSE to bypass 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.&lt;func&gt;=&lt;policy&gt;**: sets the specific FUSE function's policy. See below for the list of value types. Example: **func.getattr=newest**
* **category.&lt;category&gt;=&lt;policy&gt;**: Sets policy of all FUSE functions in the provided category. Example: **category.create=mfs**
**NOTE:** Options are evaluated in the order listed so if the options are **func.rmdir=rand,category.action=ff** the **action** category setting will override the **rmdir** setting.
###srcpoints###
The source points argument is a colon (':') delimited list of paths. To make it simplier to include multiple source points without having to modify your [fstab](http://linux.die.net/man/5/fstab) we also support [globbing](http://linux.die.net/man/7/glob).
The source points argument is a colon (':') delimited list of paths. To make it simpler to include multiple source points without having to modify your [fstab](http://linux.die.net/man/5/fstab) we also support [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will probably expand it.**
```
$ mergerfs /mnt/disk*:/mnt/cdrom /media/drives
$ mergerfs /mnt/disk\*:/mnt/cdrom /media/drives
```
The above line will use all points in /mnt prefixed with *disk* and the directory *cdrom*.
@@ -47,7 +61,7 @@ In /etc/fstab it'd look like the following:
# 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](http://github.com/trapexit/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**.
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 ####
@@ -55,24 +69,25 @@ Filesystem calls are broken up into 3 categories: action, create, search. There
|----------|----------------|
| 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 |
| 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.
**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 |
|--------------|-------------|
| ff (first found) | Given the order of the paths act on the first one found (regardless if stat would return EACCES). |
| ffwp (first found w/ permissions) | Given the order of the paths act on the first one found which you have access (stat does not error with EACCES). |
| 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 in multiple locations use the one with the most free space. Otherwise fall back to mfs. |
| fwfs (first with free space) | Pick the first path which has at least `minfreespace`. |
| lfs (least free space) | Pick the path with least available space but more than `minfreespace`. |
| rand (random) | Pick an existing destination at random. |
| all | Applies action to all found. For searches it will behave like first found `ff`. |
| 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. |
#### Defaults ####
@@ -82,68 +97,76 @@ Filesystem calls are broken up into 3 categories: action, create, search. There
| create | epmfs |
| search | ff |
#### rename ####
[rename](http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky function in a merged system. Normally if a rename can't be done atomically due to the from and to paths existing on different mount points it will return `-1` with `errno = EXDEV`. The atomic rename is most critical for replacing files in place atomically (such as securing writing to a temp file and then replacing a target). The problem is that by merging multiple paths you can have N instances of the source and destinations on different drives. Meaning that if you just renamed each source locally you could end up with the destination files not overwriten / replaced. To address this mergerfs works in the following way. If the source and destination exist in different directories it will immediately return `EXDEV`. Generally it's not expected for cross directory renames to work so it should be fine for most instances (mv,rsync,etc.). If they do belong to the same directory it then runs the `rename` policy to get the files to rename. It iterates through and renames each file while keeping track of those paths which have not been renamed. If all the renames succeed it will then `unlink` or `rmdir` the other paths to clean up any preexisting target files. This allows the new file to be found without the file itself ever disappearing. There may still be some issues with this behavior. Particularly on error. At the moment however this seems the best policy.
#### readdir ####
[readdir](http://linux.die.net/man/3/readdir) is very different from most functions in this realm. It certainly could have it's own set of policies to tweak its behavior. At this time it provides a simple `first found` merging of directories and file found. That is: only the first file or directory found for a directory is returned. Given how FUSE works though the data representing the returned entry comes from `getattr`.
[readdir](http://linux.die.net/man/3/readdir) is very different from most functions in this realm. It certainly could have it's own set of policies to tweak its behavior. At this time it provides a simple **first found** merging of directories and file found. That is: only the first file or directory found for a directory is returned. Given how FUSE works though the data representing the returned entry comes from **getattr**.
It could be extended to offer the ability to see all files found. Perhaps concatinating `#` 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.
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 points on the same drive will not result in double counting it's space.
**NOTE:** Since we can not (easily) replicate the atomicity of an `mkdir` or `mknod` without side effects those calls will first do a scan to see if the file exists and then attempts a create. This means there is a slight race condition. Worse case you'd end up with the directory or file on more than one mount.
**NOTE:** Since we can not (easily) replicate the atomicity of an **mkdir** or **mknod** without side effects those calls will first do a scan to see if the file exists and then attempts a create. This means there is a slight race condition. Worse case you'd end up with the directory or file on more than one mount.
# BUILDING
* Need to install FUSE development libraries (libfuse-dev).
* Optionally need libattr1 (libattr1-dev).
**NOTE:** Prebuilt packages can be found at: https://github.com/trapexit/mergerfs/releases
First get the code from [github](http://github.com/trapexit/mergerfs).
```
[trapexit:~/dev/mergerfs] $ make help
usage: make
make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)
$ git clone https://github.com/trapexit/mergerfs.git
$ # or
$ wget https://github.com/trapexit/mergerfs/archive/master.zip
```
# Runtime Settings
#### Debian / Ubuntu
```
$ sudo apt-get install g++ pkg-config git git-buildpackage pandoc debhelper libfuse-dev libattr1-dev
$ cd mergerfs
$ make deb
$ sudo dpkg -i ../mergerfs_version_arch.deb
```
#### /.mergerfs pseudo file ####
#### Fedora
```
$ su -
# dnf install rpm-build fuse-devel libattr-devel pandoc gcc-c++
# cd mergerfs
# make rpm
# rpm -i rpmbuild/RPMS/<arch>/mergerfs-<verion>.<arch>.rpm
```
#### Generically
Have 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 allows for the runtime modification of certain mergerfs options. The file will not show up in readdirs but can be stat'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
There is a pseudo file available at the mount point which allows for the runtime modification of certain **mergerfs** options. The file will not show up in **readdir** but can be **stat**'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
##### Keys #####
* user.mergerfs.srcmounts
* user.mergerfs.minfreespace
* user.mergerfs.category.action
* user.mergerfs.category.create
* user.mergerfs.category.search
* user.mergerfs.func.access
* user.mergerfs.func.chmod
* user.mergerfs.func.chown
* user.mergerfs.func.create
* user.mergerfs.func.getattr
* user.mergerfs.func.getxattr
* user.mergerfs.func.link
* user.mergerfs.func.listxattr
* user.mergerfs.func.mkdir
* user.mergerfs.func.mknod
* user.mergerfs.func.open
* user.mergerfs.func.readlink
* user.mergerfs.func.removexattr
* user.mergerfs.func.rename
* user.mergerfs.func.rmdir
* user.mergerfs.func.setxattr
* user.mergerfs.func.symlink
* user.mergerfs.func.truncate
* user.mergerfs.func.unlink
* user.mergerfs.func.utimens
Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
##### Example #####
@@ -151,6 +174,9 @@ Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/
[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
@@ -201,22 +227,31 @@ For **user.mergerfs.srcmounts** there are several instructions available for man
| Instruction | Description |
|--------------|-------------|
| +[list] | append |
| +<[list] | prepend |
| +>[list] | append |
| -[list] | remove all values provided |
| -< | remove first in list |
| -> | remove last in list |
| =[list] | set |
| [list] | set |
| [list] | set |
| +<[list] | prepend |
| +>[list] | append |
| -[list] | remove all values provided |
| -< | remove first in list |
| -> | remove last in list |
##### misc #####
##### minfreespace #####
Categories and funcs take a policy as described in the previous section. When reading funcs you'll get the policy string. However, with categories you'll get a coma separated list of policies for each type found. For example: if all search functions are `ff` except for `access` which is `ffwp` the value for `user.mergerfs.category.search` will be `ff,ffwp`.
Input: interger with an optional suffix. **K**, **M**, or **G**.
Output: value in bytes
##### moveonenospc #####
Input: **true** and **false**
Ouput: **true** or **false**
##### categories / funcs #####
Input: short policy string as described elsewhere in this document
Output: the policy string except for categories where its funcs have multiple types. In that case it will be a comma separated list.
#### mergerfs file xattrs ####
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:
While they won't show up when using [listxattr](http://linux.die.net/man/2/listxattr) **mergerfs** offers a number of special xattrs to query information about the files served. To access the values you will need to issue a [getxattr](http://linux.die.net/man/2/getxattr) for one of the following:
* **user.mergerfs.basepath:** the base mount point for the file given the current search policy
* **user.mergerfs.relpath:** the relative path of the file from the perspective of the mount point
@@ -237,27 +272,33 @@ A B C
/mnt/b/full/path/to/A
```
# Tips / Notes
# TIPS / NOTES
* The recommended options are `defaults,allow_other`. The `allow_other` is to allow users who are not the one which executed mergerfs access to the mountpoint. `defaults` is described above and should offer the best performance. It's possible that if you're running on an older platform the `splice` features aren't available and could error. In that case simply use the other options manually.
* Remember that some policies mixed with some functions may result in strange behaviors. Not that some of these behaviors and race conditions couldn't happen outside [mergerfs](http://github.com/trapexit/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) can apparently use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether or not to scan for new content rather than simply performing a full scan. If using the current default `getattr` policy of `ff` it's 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).
* If you don't see some directories / files you expect in a merged point be sure the user has permission to all the underlying directories. If `/drive0/a` has is owned by `root:root` with ACLs set to `0700` and `/drive1/a` is `root:root` and `0755` you'll see only `/drive1/a`.
* Since POSIX gives you only error or success on calls its difficult to determine the proper behavior when applying the behavior to multiple targets. Generally if something succeeds when reading it returns the data it can. If something fails when making an action we continue on and return the last error.
* The recommended options are **defaults,allow_other**. The **allow_other** is to allow users who are not the one which executed mergerfs access to the mountpoint. **defaults** is described above and should offer the best performance. It's possible that if you're running on an older platform the **splice** features aren't available and could error. In that case simply use the other options manually.
* Remember that some policies mixed with some functions may result in strange behaviors. Not that some of these behaviors and race conditions couldn't happen outside **mergerfs** but that they are far more likely to occur on account of attempt to merge together multiple sources of data which could be out of sync due to the different policies.
* An example: [Kodi](http://kodi.tv) and [Plex](http://plex.tv) can apparently use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether or not to scan for new content rather than simply performing a full scan. If using the current default **getattr** policy of **ff** its possible **Kodi** will miss an update on account of it returning the first directory found's **stat** info and its a later directory on another mount which had the **mtime** recently updated. To fix this you will want to set **func.getattr=newest**. Remember though that this is just **stat**. If the file is later **open**'ed or **unlink**'ed and the policy is different for those then a completely different file or directory could be acted on.
* Due to previously mentioned issues its generally best to set **category** wide policies rather than individual **func**'s. This will help limit the confusion of tools such as [rsync](http://linux.die.net/man/1/rsync).
# Known Issues / Bugs
* Due to the overhead of [getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs utilizes a cache. This cache is opportunistic and per thread. This means each thread will query the supplemental groups for a user when that particular thread needs to change credentials and currently it will keep that data for the lifetime of the mount or thread. This means that if a user is added to a group it may not be picked up without the restart of mergerfs. However, since the high level FUSE API's (at least the standard version) thread pool dynamically grows and shrinks it's possible that over time a thread will be killed and later a new thread with no cache will start and query the new data.
# FAQ
#### It's mentioned that there are some security issues with `mhddfs`. What are they? How does `mergerfs` address them?
*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) trys 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 situtations. Rather than attempting to simulate POSIX ACL behaviors the proper behavior is to use [seteuid](http://linux.die.net/man/2/seteuid) and [setegid](http://linux.die.net/man/2/setegid), become the user making the original call and perform the action as them. This is how [mergerfs](https://github.com/trapexit/mergerfs) handles things.
[mhddfs](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.
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. When building on OSX mergerfs will use this without any mutexes.
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 documention 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)
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 and other tricks. 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 privilages be needed (for instance: to clone paths).
> 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.
+3
View File
@@ -6,3 +6,6 @@
%:
dh $@
override_dh_auto_install:
$(MAKE) PREFIX=$(CURDIR)/debian/mergerfs/usr install
+50
View File
@@ -0,0 +1,50 @@
Name: mergerfs
Version: __VERSION__
Release: 1%{?dist}
Summary: A FUSE union filesystem
Group: Applications/System
License: MIT
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
# pandoc pulls in ~60 packages (87M installed) from EPEL :(
BuildRequires: pandoc
Requires: fuse-libs
%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}/*
%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.
+7 -7
View File
@@ -34,10 +34,10 @@
#include <unistd.h>
#include <errno.h>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -68,16 +68,16 @@ _access(Policy::Func::Search searchFunc,
namespace mergerfs
{
namespace access
namespace fuse
{
int
access(const char *fusepath,
int mask)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _access(config.access,
config.srcmounts,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace access
namespace fuse
{
int
access(const char *fusepath,
+7 -7
View File
@@ -28,10 +28,10 @@
#include <string>
#include <vector>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -68,16 +68,16 @@ _chmod(Policy::Func::Action actionFunc,
namespace mergerfs
{
namespace chmod
namespace fuse
{
int
chmod(const char *fusepath,
mode_t mode)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _chmod(config.chmod,
config.srcmounts,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace chmod
namespace fuse
{
int
chmod(const char *fusepath,
+8 -7
View File
@@ -29,14 +29,15 @@
#include <string>
#include <vector>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using mergerfs::Policy;
using mergerfs::Config;
static
int
@@ -70,17 +71,17 @@ _chown(Policy::Func::Action actionFunc,
namespace mergerfs
{
namespace chown
namespace fuse
{
int
chown(const char *fusepath,
uid_t uid,
gid_t gid)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _chown(config.chown,
config.srcmounts,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace chown
namespace fuse
{
int
chown(const char *fusepath,
+69
View File
@@ -0,0 +1,69 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
#include "fs.hpp"
#include "fs_clonefile.hpp"
#include "fs_clonepath.hpp"
namespace clonetool
{
static
void
print_usage_and__exit(void)
{
std::cerr << "usage: clone "
<< "[path <sourcedir> <destdir> <relativepath>]"
<< " | "
<< "[file <source> <dest>]"
<< std::endl;
_exit(1);
}
int
main(const int argc,
char * const argv[])
{
int rv = 0;
if(argc == 4 && !strcmp(argv[1],"file"))
rv = fs::clonefile(argv[2],argv[3]);
else if(argc == 5 && !strcmp(argv[1],"path"))
rv = fs::clonepath(argv[2],argv[3],argv[4]);
else
print_usage_and__exit();
if(rv == -1)
std::cerr << "error: "
<< strerror(errno)
<< std::endl;
return 0;
}
}
+1 -1
View File
@@ -22,7 +22,7 @@
THE SOFTWARE.
*/
namespace clonepath
namespace clonetool
{
int
main(const int argc,
+65 -85
View File
@@ -40,102 +40,82 @@ using std::vector;
namespace mergerfs
{
namespace config
Config::Config()
: destmount(),
srcmounts(),
srcmountslock(),
minfreespace(UINT32_MAX),
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()
: destmount(),
srcmounts(),
srcmountslock(),
minfreespace(UINT32_MAX),
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")
{
pthread_rwlock_init(&srcmountslock,NULL);
pthread_rwlock_init(&srcmountslock,NULL);
set_category_policy("action","all");
set_category_policy("create","epmfs");
set_category_policy("search","ff");
}
set_category_policy("action","all");
set_category_policy("create","epmfs");
set_category_policy("search","ff");
}
int
Config::set_func_policy(const string &fusefunc_,
const string &policy_)
{
const Policy *policy;
const FuseFunc *fusefunc;
int
Config::set_func_policy(const string &fusefunc_,
const string &policy_)
{
const Policy *policy;
const FuseFunc *fusefunc;
fusefunc = FuseFunc::find(fusefunc_);
if(fusefunc == FuseFunc::invalid)
return (errno=ENODATA,-1);
fusefunc = FuseFunc::find(fusefunc_);
if(fusefunc == FuseFunc::invalid)
return (errno=ENODATA,-1);
policy = Policy::find(policy_);
if(policy == Policy::invalid)
return (errno=EINVAL,-1);
policy = Policy::find(policy_);
if(policy == Policy::invalid)
return (errno=EINVAL,-1);
policies[(FuseFunc::Enum::Type)*fusefunc] = policy;
policies[(FuseFunc::Enum::Type)*fusefunc] = policy;
return 0;
}
return 0;
}
int
Config::set_category_policy(const string &category_,
const string &policy_)
{
const Policy *policy;
const Category *category;
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);
category = Category::find(category_);
if(category == Category::invalid)
return (errno=ENODATA,-1);
policy = Policy::find(policy_);
if(policy == Policy::invalid)
return (errno=EINVAL,-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;
}
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;
}
const Config&
get(const struct fuse_context *fc)
{
return *((Config*)fc->private_data);
}
const Config&
get(void)
{
return get(fuse_get_context());
}
Config&
get_writable(void)
{
return (*((Config*)fuse_get_context()->private_data));
}
return 0;
}
}
+56 -47
View File
@@ -38,56 +38,65 @@
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);
}
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;
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;
};
const Config &get(const struct fuse_context *fc);
const Config &get(void);
Config &get_writable(void);
}
static
Config &
get_writable(void)
{
return (*((Config*)fuse_get_context()->private_data));
}
};
}
#endif
+17 -14
View File
@@ -33,13 +33,16 @@
#include <vector>
#include "config.hpp"
#include "ugid.hpp"
#include "fs.hpp"
#include "fileinfo.hpp"
#include "fs_path.hpp"
#include "fs_clonepath.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using mergerfs::Policy;
using namespace mergerfs;
static
int
@@ -69,7 +72,7 @@ _create(Policy::Func::Search searchFunc,
if(createpath[0] != existingpath[0])
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
const ugid::SetRootGuard ugidGuard;
fs::clonepath(existingpath[0],createpath[0],dirname);
}
@@ -79,24 +82,24 @@ _create(Policy::Func::Search searchFunc,
if(fd == -1)
return -errno;
fh = fd;
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)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _create(config.getattr,
config.create,
@@ -104,8 +107,8 @@ namespace mergerfs
config.minfreespace,
fusepath,
(mode & ~fc->umask),
fileinfo->flags,
fileinfo->fh);
ffi->flags,
ffi->fh);
}
}
}
+4 -4
View File
@@ -27,11 +27,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);
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace destroy
namespace fuse
{
void
destroy(void *)
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace destroy
namespace fuse
{
void
destroy(void *);
+11 -7
View File
@@ -33,6 +33,8 @@
#include <errno.h>
#include <fcntl.h>
#include "fileinfo.hpp"
static
int
_fallocate(const int fd,
@@ -64,16 +66,18 @@ _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 *ffi)
fallocate(const char *fusepath,
int mode,
off_t offset,
off_t len,
fuse_file_info *ffi)
{
return _fallocate(ffi->fh,
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _fallocate(fi->fd,
mode,
offset,
len);
+6 -6
View File
@@ -24,13 +24,13 @@
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);
}
}
+9 -5
View File
@@ -29,6 +29,8 @@
#include <unistd.h>
#include <errno.h>
#include "fileinfo.hpp"
static
int
_fgetattr(const int fd,
@@ -43,14 +45,16 @@ _fgetattr(const int fd,
namespace mergerfs
{
namespace fgetattr
namespace fuse
{
int
fgetattr(const char *fusepath,
struct stat *st,
struct fuse_file_info *ffi)
fgetattr(const char *fusepath,
struct stat *st,
fuse_file_info *ffi)
{
return _fgetattr(ffi->fh,
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _fgetattr(fi->fd,
*st);
}
}
+4 -4
View File
@@ -28,11 +28,11 @@
namespace mergerfs
{
namespace fgetattr
namespace fuse
{
int
fgetattr(const char *fusepath,
struct stat *st,
struct fuse_file_info *fileinfo);
fgetattr(const char *fusepath,
struct stat *st,
fuse_file_info *fileinfo);
}
}
+40
View File
@@ -0,0 +1,40 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef __FILEINFO_HPP__
#define __FILEINFO_HPP__
class FileInfo
{
public:
FileInfo(int _fd) :
fd(_fd)
{
}
public:
int fd;
};
#endif
+8 -4
View File
@@ -27,6 +27,8 @@
#include <unistd.h>
#include <errno.h>
#include "fileinfo.hpp"
static
int
_flush(const int fd)
@@ -44,13 +46,15 @@ _flush(const int fd)
namespace mergerfs
{
namespace flush
namespace fuse
{
int
flush(const char *fusepath,
struct fuse_file_info *ffi)
flush(const char *fusepath,
fuse_file_info *ffi)
{
return _flush(ffi->fh);
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _flush(fi->fd);
}
}
}
+3 -3
View File
@@ -24,10 +24,10 @@
namespace mergerfs
{
namespace flush
namespace fuse
{
int
flush(const char *path,
struct fuse_file_info *fi);
flush(const char *path,
fuse_file_info *fi);
}
}
+88 -420
View File
@@ -24,126 +24,28 @@
#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 <glob.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 Iter>
Iter
random_element(Iter begin,
Iter end)
{
const unsigned long n = std::distance(begin, end);
std::advance(begin, (std::rand() % n));
return begin;
}
namespace fs
{
namespace path
{
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;
path = fs::path::make(paths[i],fusepath);
rv = ::lstat(path.c_str(),&st);
if(rv == 0)
return true;
}
return false;
}
}
void
findallfiles(const vector<string> &srcmounts,
const string &fusepath,
@@ -155,7 +57,7 @@ namespace fs
string fullpath;
struct stat st;
fullpath = fs::path::make(srcmounts[i],fusepath);
fs::path::make(srcmounts[i],fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
@@ -164,331 +66,37 @@ namespace fs
}
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());
str::split(attrvector,tmp,'\0');
}
return rv;
}
int
listxattr(const string &path,
string &attrstr)
{
int rv;
vector<char> attrs;
rv = listxattr(path,attrs);
if(rv != -1)
attrstr = string(attrs.begin(),attrs.end());
return rv;
}
int
getxattr(const string &path,
const string &attr,
vector<char> &value)
{
#ifndef WITHOUT_XATTR
int rv;
int size;
rv = -1;
errno = ERANGE;
while(rv == -1 && errno == ERANGE)
{
size = ::getxattr(path.c_str(),attr.c_str(),NULL,0);
value.resize(size);
rv = ::getxattr(path.c_str(),attr.c_str(),&value[0],size);
}
return rv;
#else
errno = ENOTSUP;
return -1;
#endif
}
int
getxattr(const string &path,
const string &attr,
string &value)
{
int rv;
vector<char> tmpvalue;
rv = getxattr(path,attr,tmpvalue);
if(rv != -1)
value = string(tmpvalue.begin(),tmpvalue.end());
return rv;
}
int
getxattrs(const string &path,
map<string,string> &attrs)
{
int rv;
string attrstr;
rv = listxattr(path,attrstr);
rv = ::fstatvfs(fd,&buf);
if(rv == -1)
return -1;
{
string key;
istringstream ss(attrstr);
while(getline(ss,key,'\0'))
{
string value;
rv = getxattr(path,key,value);
if(rv != -1)
attrs[key] = value;
}
}
return 0;
}
int
setxattr(const string &path,
const string &key,
const string &value,
const int flags)
{
#ifndef WITHOUT_XATTR
return ::setxattr(path.c_str(),
key.c_str(),
value.data(),
value.size(),
flags);
#else
errno = ENOTSUP;
return -1;
#endif
}
int
setxattr(const int fd,
const string &key,
const string &value,
const int flags)
{
#ifndef WITHOUT_XATTR
return ::fsetxattr(fd,
key.c_str(),
value.data(),
value.size(),
flags);
#else
errno = ENOTSUP;
return -1;
#endif
}
int
setxattrs(const string &path,
const map<string,string> &attrs)
{
int fd;
fd = ::open(path.c_str(),O_RDONLY|O_NONBLOCK);
if(fd == -1)
return -1;
for(map<string,string>::const_iterator
i = attrs.begin(), ei = attrs.end(); i != ei; ++i)
fsid = buf.f_fsid;
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
{
setxattr(fd,i->first,i->second,0);
}
fs::path::make(srcmounts[i],fusepath,tmppath);
return ::close(fd);
}
int
copyxattrs(const string &from,
const string &to)
{
int rv;
map<string,string> attrs;
rv = getxattrs(from,attrs);
if(rv == -1)
return -1;
return setxattrs(to,attrs);
}
static
int
get_fs_ioc_flags(const string &file,
int &flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
static
int
set_fs_ioc_flags(const string &file,
const int flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
int
copyattr(const string &from,
const string &to)
{
int rv;
int flags;
rv = get_fs_ioc_flags(from,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(to,flags);
}
static
bool
ignorable_error(const int err)
{
switch(err)
{
case ENOTTY:
case ENOTSUP:
#if ENOTSUP != EOPNOTSUPP
case EOPNOTSUPP:
#endif
return true;
}
return false;
}
int
clonepath(const string &fromsrc,
const string &tosrc,
const string &relative)
{
int rv;
struct stat st;
string topath;
string frompath;
string dirname;
dirname = fs::path::dirname(relative);
if(!dirname.empty())
{
rv = clonepath(fromsrc,tosrc,dirname);
rv = ::statvfs(tmppath.c_str(),&buf);
if(rv == -1)
return -1;
continue;
if(buf.f_fsid == fsid)
{
basepath = srcmounts[i];
return 0;
}
}
frompath = fs::path::make(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 = fs::path::make(tosrc,relative);
rv = ::mkdir(topath.c_str(),st.st_mode);
if(rv == -1)
{
if(errno != EEXIST)
return -1;
rv = ::chmod(topath.c_str(),st.st_mode);
if(rv == -1)
return -1;
}
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
if(rv == -1)
return -1;
// It may not support it... it's fine...
rv = copyattr(frompath,topath);
if(rv == -1 && !ignorable_error(errno))
return -1;
rv = copyxattrs(frompath,topath);
if(rv == -1 && !ignorable_error(errno))
return -1;
return 0;
return (errno=ENOENT,-1);
}
void
@@ -510,4 +118,64 @@ namespace fs
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;
}
};
+12 -72
View File
@@ -27,92 +27,32 @@
#include <string>
#include <vector>
#include <map>
#include "path.hpp"
namespace fs
{
using std::size_t;
using std::string;
using std::vector;
using std::map;
namespace path
{
string dirname(const string &path);
string basename(const string &path);
bool 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
append(string &base,
const string &suffix)
{
base += suffix;
}
}
void findallfiles(const vector<string> &srcmounts,
const string &fusepath,
vector<string> &paths);
int clonepath(const string &srcfrom,
const string &srcto,
const string &relative);
int listxattr(const string &path,
vector<char> &attrs);
int listxattr(const string &path,
string &attrs);
int listxattr(const string &path,
vector<string> &attrs);
int getxattr(const string &path,
const string &attr,
vector<char> &value);
int getxattr(const string &path,
const string &attr,
string &value);
int getxattrs(const string &path,
map<string,string> &attrs);
int setxattr(const string &path,
const string &key,
const string &value,
const int flags);
int setxattr(const int fd,
const string &key,
const string &value,
const int flags);
int setxattrs(const string &path,
const map<string,string> &attrs);
int copyxattrs(const string &from,
const string &to);
int copyattr(const string &from,
const string &to);
int findonfs(const vector<string> &srcmounts,
const string &fusepath,
const int fd,
string &basepath);
void glob(const vector<string> &patterns,
vector<string> &strs);
void realpathize(vector<string> &strs);
int getfl(const int fd);
int mfs(const vector<string> &srcs,
const size_t minfreespace,
string &path);
};
#endif // __FS_HPP__
+135
View File
@@ -0,0 +1,135 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <errno.h>
#include <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);
}
}
}
+43
View File
@@ -0,0 +1,43 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#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__
+231
View File
@@ -0,0 +1,231 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <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;
}
}
+33
View File
@@ -0,0 +1,33 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <string>
namespace fs
{
int clonefile(const int fdin,
const int fdout);
int clonefile(const std::string &from,
const std::string &to);
}
+117
View File
@@ -0,0 +1,117 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <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;
}
}
+32
View File
@@ -0,0 +1,32 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <string>
namespace fs
{
int clonepath(const std::string &from,
const std::string &to,
const std::string &relative);
}
+117
View File
@@ -0,0 +1,117 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <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;
}
}
+10 -25
View File
@@ -22,34 +22,19 @@
THE SOFTWARE.
*/
#ifndef __PATH_HPP__
#define __PATH_HPP__
#ifndef __FS_MOVEFILE_HPP__
#define __FS_MOVEFILE_HPP__
#include <string>
#include <vector>
struct Path
namespace fs
{
Path() {}
int
movefile(const vector<string> &basepaths,
const char *fusepath,
const size_t additional_size,
int &origfd);
}
explicit
Path(const std::string &b,
const std::string &f)
: base(b),
full(f)
{}
explicit
Path(const char *b,
const std::string &f)
: base(b),
full(f)
{}
std::string base;
std::string full;
};
typedef std::vector<Path> Paths;
#endif /* __PATH_HPP__ */
#endif
+118
View File
@@ -0,0 +1,118 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <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;
}
}
}
+76
View File
@@ -0,0 +1,76 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#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__
+399
View File
@@ -0,0 +1,399 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <attr/xattr.h>
#include <sys/stat.h>
#include <fcntl.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);
}
}
}
+78
View File
@@ -0,0 +1,78 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#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__
+9 -5
View File
@@ -34,6 +34,8 @@
#include <unistd.h>
#include <errno.h>
#include "fileinfo.hpp"
static
int
_fsync(const int fd,
@@ -50,14 +52,16 @@ _fsync(const int fd,
namespace mergerfs
{
namespace fsync
namespace fuse
{
int
fsync(const char *fusepath,
int isdatasync,
struct fuse_file_info *ffi)
fsync(const char *fusepath,
int isdatasync,
fuse_file_info *ffi)
{
return _fsync(ffi->fh,
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _fsync(fi->fd,
isdatasync);
}
}
+4 -4
View File
@@ -26,11 +26,11 @@
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);
}
}
+9 -5
View File
@@ -28,6 +28,8 @@
#include <sys/types.h>
#include <errno.h>
#include "fileinfo.hpp"
static
int
_ftruncate(const int fd,
@@ -42,14 +44,16 @@ _ftruncate(const int fd,
namespace mergerfs
{
namespace ftruncate
namespace fuse
{
int
ftruncate(const char *fusepath,
off_t size,
struct fuse_file_info *ffi)
ftruncate(const char *fusepath,
off_t size,
fuse_file_info *ffi)
{
return _ftruncate(ffi->fh,
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _ftruncate(fi->fd,
size);
}
}
+4 -4
View File
@@ -29,11 +29,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);
}
}
+12 -10
View File
@@ -33,9 +33,9 @@
#include <errno.h>
#include "config.hpp"
#include "fs.hpp"
#include "ugid.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -45,14 +45,16 @@ static
int
_getattr_controlfile(struct stat &buf)
{
time_t now = time(NULL);
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 = ::getuid();
buf.st_gid = ::getgid();
buf.st_uid = uid;
buf.st_gid = gid;
buf.st_rdev = 0;
buf.st_size = 0;
buf.st_blksize = 1024;
@@ -88,20 +90,20 @@ _getattr(Policy::Func::Search searchFunc,
namespace mergerfs
{
namespace getattr
namespace fuse
{
int
getattr(const char *fusepath,
struct stat *st)
{
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
if(fusepath == config.controlfile)
return _getattr_controlfile(*st);
const struct fuse_context *fc = fuse_get_context();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _getattr(config.getattr,
config.srcmounts,
+1 -1
View File
@@ -28,7 +28,7 @@
namespace mergerfs
{
namespace getattr
namespace fuse
{
int
getattr(const char *fusepath,
+105 -47
View File
@@ -35,27 +35,45 @@
#include <string.h>
#include "config.hpp"
#include "fs.hpp"
#include "ugid.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "xattr.hpp"
#include "str.hpp"
#include "ugid.hpp"
#include "version.hpp"
#include "xattr.hpp"
using std::string;
using std::vector;
using std::set;
using namespace mergerfs;
using namespace mergerfs::config;
static
int
_lgetxattr(const string &path,
const string &name,
void *value,
const size_t size)
{
#ifndef WITHOUT_XATTR
int rv;
rv = ::lgetxattr(path.c_str(),name.c_str(),value,size);
return ((rv == -1) ? -errno : rv);
#else
return -ENOSUP;
#endif
}
static
void
_getxattr_controlfile_fusefunc_policy(const Config &config,
const char *attrbasename,
const string &attr,
string &attrvalue)
{
FuseFunc fusefunc;
fusefunc = FuseFunc::find(attrbasename);
fusefunc = FuseFunc::find(attr);
if(fusefunc != FuseFunc::invalid)
attrvalue = (std::string)*config.policies[(FuseFunc::Enum::Type)*fusefunc];
}
@@ -63,12 +81,12 @@ _getxattr_controlfile_fusefunc_policy(const Config &config,
static
void
_getxattr_controlfile_category_policy(const Config &config,
const char *attrbasename,
const string &attr,
string &attrvalue)
{
Category cat;
cat = Category::find(attrbasename);
cat = Category::find(attr);
if(cat != Category::invalid)
{
vector<string> policies;
@@ -105,28 +123,70 @@ _getxattr_controlfile_minfreespace(const Config &config,
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
int
_getxattr_controlfile(const Config &config,
const char *attrname,
const string &attrname,
char *buf,
const size_t count)
{
size_t len;
string attrvalue;
const char *attrbasename = &attrname[sizeof("user.mergerfs.")-1];
vector<string> attr;
if(strncmp("user.mergerfs.",attrname,sizeof("user.mergerfs.")-1))
str::split(attr,attrname,'.');
if((attr[0] != "user") || (attr[1] != "mergerfs"))
return -ENOATTR;
if(!strcmp("srcmounts",attrbasename))
_getxattr_controlfile_srcmounts(config,attrvalue);
else if(!strcmp("minfreespace",attrbasename))
_getxattr_controlfile_minfreespace(config,attrvalue);
else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
_getxattr_controlfile_category_policy(config,&attrbasename[sizeof("category.")-1],attrvalue);
else if(!strncmp("func.",attrbasename,sizeof("func.")-1))
_getxattr_controlfile_fusefunc_policy(config,&attrbasename[sizeof("func.")-1],attrvalue);
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);
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;
@@ -156,7 +216,7 @@ _getxattr_from_string(char *destbuf,
return srcbufsize;
if(srcbufsize > destbufsize)
return (errno = ERANGE, -1);
return -ERANGE;
memcpy(destbuf,src.data(),srcbufsize);
@@ -177,7 +237,7 @@ _getxattr_user_mergerfs_allpaths(const vector<string> &srcmounts,
concated = str::join(paths,'\0');
return ::_getxattr_from_string(buf,count,concated);
return _getxattr_from_string(buf,count,concated);
}
static
@@ -186,22 +246,24 @@ _getxattr_user_mergerfs(const string &basepath,
const string &fusepath,
const string &fullpath,
const vector<string> &srcmounts,
const char *attrname,
const string &attrname,
char *buf,
const size_t count)
{
const char *attrbasename = &attrname[sizeof("user.mergerfs")];
vector<string> attr;
if(!strcmp(attrbasename,"basepath"))
return ::_getxattr_from_string(buf,count,basepath);
else if(!strcmp(attrbasename,"fullpath"))
return ::_getxattr_from_string(buf,count,fullpath);
else if(!strcmp(attrbasename,"relpath"))
return ::_getxattr_from_string(buf,count,fusepath);
else if(!strcmp(attrbasename,"allpaths"))
return ::_getxattr_user_mergerfs_allpaths(srcmounts,fusepath,buf,count);
str::split(attr,attrname,'.');
return ::lgetxattr(fullpath.c_str(),attrname,buf,count);
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
@@ -210,35 +272,31 @@ _getxattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const char *attrname,
const string &attrname,
char *buf,
const size_t count)
{
#ifndef WITHOUT_XATTR
int rv;
vector<string> basepath;
string fullpath;
vector<string> basepath;
rv = searchFunc(srcmounts,fusepath,minfreespace,basepath);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepath[0],fusepath);
fs::path::make(basepath[0],fusepath,fullpath);
if(!strncmp("user.mergerfs.",attrname,sizeof("user.mergerfs.")-1))
if(str::isprefix(attrname,"user.mergerfs."))
rv = _getxattr_user_mergerfs(basepath[0],fusepath,fullpath,srcmounts,attrname,buf,count);
else
rv = ::lgetxattr(fullpath.c_str(),attrname,buf,count);
rv = _lgetxattr(fullpath,attrname,buf,count);
return ((rv == -1) ? -errno : rv);
#else
return -ENOTSUP;
#endif
return rv;
}
namespace mergerfs
{
namespace getxattr
namespace fuse
{
int
getxattr(const char *fusepath,
@@ -246,7 +304,8 @@ namespace mergerfs
char *buf,
size_t count)
{
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
if(fusepath == config.controlfile)
return _getxattr_controlfile(config,
@@ -254,9 +313,8 @@ namespace mergerfs
buf,
count);
const struct fuse_context *fc = fuse_get_context();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _getxattr(config.getxattr,
config.srcmounts,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace getxattr
namespace fuse
{
int
getxattr(const char *fusepath,
+6 -3
View File
@@ -25,19 +25,22 @@
#include <fuse.h>
#include "config.hpp"
#include "ugid.hpp"
namespace mergerfs
{
namespace init
namespace fuse
{
void *
init(struct fuse_conn_info *conn)
init(fuse_conn_info *conn)
{
ugid::init();
#ifdef FUSE_CAP_IOCTL_DIR
conn->want |= FUSE_CAP_IOCTL_DIR;
#endif
return &config::get_writable();
return &Config::get_writable();
}
}
}
+2 -2
View File
@@ -24,9 +24,9 @@
namespace mergerfs
{
namespace init
namespace fuse
{
void *
init(struct fuse_conn_info *conn);
init(fuse_conn_info *conn);
}
}
+34 -59
View File
@@ -32,8 +32,10 @@
#include <linux/fs.h>
#include "config.hpp"
#include "ugid.hpp"
#include "fileinfo.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -41,45 +43,27 @@ 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)
{
#ifdef FS_IOC_GETFLAGS
case FS_IOC_GETFLAGS:
case FS_IOC_SETFLAGS:
#endif
#ifdef FS_IOC32_GETFLAGS
case FS_IOC32_SETFLAGS:
case FS_IOC32_GETFLAGS:
#endif
#ifdef FS_IOC_GETVERSION
case FS_IOC_GETVERSION:
case FS_IOC_SETVERSION:
#endif
#ifdef FS_IOC32_GETVERSION
case FS_IOC32_GETVERSION:
case FS_IOC32_SETVERSION:
#endif
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,
@@ -87,8 +71,6 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,
const size_t minfreespace,
const string &fusepath,
const int cmd,
void *arg,
const unsigned int flags,
void *data)
{
int fd;
@@ -101,11 +83,11 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,
fs::path::append(path[0],fusepath);
fd = ::open(path[0].c_str(),flags);
fd = ::open(path[0].c_str(),O_RDWR|O_NOATIME|O_DIRECTORY);
if(fd == -1)
return -errno;
rv = _ioctl(fd,cmd,arg,flags,data);
rv = _ioctl(fd,cmd,data);
::close(fd);
@@ -114,53 +96,46 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,
static
int
_ioctl_dir(const string &fusepath,
const int cmd,
void *arg,
const unsigned int flags,
void *data)
_ioctl_dir(const string &fusepath,
const int cmd,
void *data)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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,
arg,
flags,
data);
}
#endif
namespace mergerfs
{
namespace ioctl
namespace fuse
{
int
ioctl(const char *fusepath,
int cmd,
void *arg,
struct fuse_file_info *ffi,
unsigned int flags,
void *data)
ioctl(const char *fusepath,
int cmd,
void *arg,
fuse_file_info *ffi,
unsigned int flags,
void *data)
{
#ifdef FUSE_IOCTL_DIR
if(flags & FUSE_IOCTL_DIR)
return _ioctl_dir(fusepath,
cmd,
arg,
flags,
data);
#endif
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _ioctl(ffi->fh,
return _ioctl(fi->fd,
cmd,
arg,
flags,
data);
}
}
+7 -7
View File
@@ -24,14 +24,14 @@
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);
}
}
+10 -8
View File
@@ -31,13 +31,15 @@
#include <unistd.h>
#include "config.hpp"
#include "fs.hpp"
#include "ugid.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using mergerfs::Policy;
using namespace mergerfs;
static
int
@@ -64,7 +66,7 @@ _single_link(Policy::Func::Search searchFunc,
return -1;
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
const ugid::SetRootGuard ugidGuard;
fs::clonepath(foundpath[0],base,newpathdir);
}
@@ -104,16 +106,16 @@ _link(Policy::Func::Search searchFunc,
namespace mergerfs
{
namespace link
namespace fuse
{
int
link(const char *from,
const char *to)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _link(config.getattr,
config.link,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace link
namespace fuse
{
int
link(const char *from,
+16 -13
View File
@@ -31,13 +31,13 @@
#include <errno.h>
#include <string.h>
#include "config.hpp"
#include "category.hpp"
#include "fs.hpp"
#include "ugid.hpp"
#include "rwlock.hpp"
#include "xattr.hpp"
#include "buildvector.hpp"
#include "category.hpp"
#include "config.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
#include "xattr.hpp"
using std::string;
using std::vector;
@@ -52,9 +52,12 @@ _listxattr_controlfile(char *list,
const vector<string> strs =
buildvector<string>
("user.mergerfs.srcmounts")
("user.mergerfs.minfreespace");
("user.mergerfs.minfreespace")
("user.mergerfs.moveonenospc")
("user.mergerfs.policies")
("user.mergerfs.version");
xattrs.reserve(512);
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++)
@@ -102,21 +105,21 @@ _listxattr(Policy::Func::Search searchFunc,
namespace mergerfs
{
namespace listxattr
namespace fuse
{
int
listxattr(const char *fusepath,
char *list,
size_t size)
{
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
if(fusepath == config.controlfile)
return _listxattr_controlfile(list,size);
const struct fuse_context *fc = fuse_get_context();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _listxattr(config.listxattr,
config.srcmounts,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace listxattr
namespace fuse
{
int
listxattr(const char *fusepath,
+44 -44
View File
@@ -31,9 +31,9 @@
#include "mergerfs.hpp"
#include "option_parser.hpp"
#include "resources.hpp"
#include "fs.hpp"
#include "fs_path.hpp"
#include "clonepath.hpp"
#include "clone.hpp"
#include "access.hpp"
#include "chmod.hpp"
@@ -92,57 +92,57 @@ namespace local
#endif
ops.flag_nullpath_ok = false;
ops.access = mergerfs::access::access;
ops.access = mergerfs::fuse::access;
ops.bmap = NULL;
ops.chmod = mergerfs::chmod::chmod;
ops.chown = mergerfs::chown::chown;
ops.create = mergerfs::create::create;
ops.destroy = mergerfs::destroy::destroy;
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::fallocate::fallocate;
ops.fallocate = mergerfs::fuse::fallocate;
#endif
ops.fgetattr = mergerfs::fgetattr::fgetattr;
ops.fgetattr = mergerfs::fuse::fgetattr;
#if FLOCK
ops.flock = NULL;
#endif
ops.flush = mergerfs::flush::flush;
ops.fsync = mergerfs::fsync::fsync;
ops.flush = mergerfs::fuse::flush;
ops.fsync = mergerfs::fuse::fsync;
ops.fsyncdir = NULL;
ops.ftruncate = mergerfs::ftruncate::ftruncate;
ops.getattr = mergerfs::getattr::getattr;
ops.ftruncate = mergerfs::fuse::ftruncate;
ops.getattr = mergerfs::fuse::getattr;
ops.getdir = NULL; /* deprecated; use readdir */
ops.getxattr = mergerfs::getxattr::getxattr;
ops.init = mergerfs::init::init;
ops.ioctl = mergerfs::ioctl::ioctl;
ops.link = mergerfs::link::link;
ops.listxattr = mergerfs::listxattr::listxattr;
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::mkdir::mkdir;
ops.mknod = mergerfs::mknod::mknod;
ops.open = mergerfs::open::open;
ops.opendir = mergerfs::opendir::opendir;
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::read::read;
ops.read = mergerfs::fuse::read;
#if READ_BUF
ops.read_buf = mergerfs::read_buf::read_buf;
ops.read_buf = mergerfs::fuse::read_buf;
#endif
ops.readdir = mergerfs::readdir::readdir;
ops.readlink = mergerfs::readlink::readlink;
ops.release = mergerfs::release::release;
ops.releasedir = mergerfs::releasedir::releasedir;
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.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::utimens::utimens;
ops.write = mergerfs::write::write;
ops.utimens = mergerfs::fuse::utimens;
ops.write = mergerfs::fuse::write;
#if WRITE_BUF
ops.write_buf = mergerfs::write_buf::write_buf;
ops.write_buf = mergerfs::fuse::write_buf;
#endif
return;
@@ -168,9 +168,9 @@ namespace mergerfs
main(const int argc,
char **argv)
{
struct fuse_args args;
struct fuse_operations ops = {0};
mergerfs::config::Config config;
fuse_args args;
fuse_operations ops = {0};
Config config;
args.argc = argc;
args.argv = argv;
@@ -195,8 +195,8 @@ main(int argc,
std::string appname;
appname = local::getappname(argc,argv);
if(appname == "clonepath")
return clonepath::main(argc,argv);
if(appname == "clone")
return clonetool::main(argc,argv);
return mergerfs::main(argc,argv);
}
+10 -8
View File
@@ -31,14 +31,16 @@
#include <string>
#include <vector>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using mergerfs::Policy;
using namespace mergerfs;
static
int
@@ -72,7 +74,7 @@ _mkdir(Policy::Func::Search searchFunc,
if(createpath != existingpath[0])
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
const ugid::SetRootGuard ugidGuard;
fs::clonepath(existingpath[0],createpath,dirname);
}
@@ -88,16 +90,16 @@ _mkdir(Policy::Func::Search searchFunc,
namespace mergerfs
{
namespace mkdir
namespace fuse
{
int
mkdir(const char *fusepath,
mode_t mode)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _mkdir(config.getattr,
config.mkdir,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace mkdir
namespace fuse
{
int
mkdir(const char *fusepath,
+10 -9
View File
@@ -33,14 +33,15 @@
#include <fcntl.h>
#include <unistd.h>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using mergerfs::Policy;
using namespace mergerfs;
static
int
@@ -74,7 +75,7 @@ _mknod(Policy::Func::Search searchFunc,
if(createpath != existingpath[0])
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
const ugid::SetRootGuard ugidGuard;
fs::clonepath(existingpath[0],createpath,dirname);
}
@@ -90,17 +91,17 @@ _mknod(Policy::Func::Search searchFunc,
namespace mergerfs
{
namespace mknod
namespace fuse
{
int
mknod(const char *fusepath,
mode_t mode,
dev_t rdev)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _mknod(config.getattr,
config.mknod,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace mknod
namespace fuse
{
int
mknod(const char *fusepath,
+3
View File
@@ -53,6 +53,9 @@ namespace num
tmp *= (1024 * 1024 * 1024);
break;
case '\0':
break;
default:
return -1;
}
+15 -12
View File
@@ -31,10 +31,11 @@
#include <string>
#include <vector>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fileinfo.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -57,34 +58,36 @@ _open(Policy::Func::Search searchFunc,
if(rv == -1)
return -errno;
fs::path::append(path[0],fusepath);
fd = ::open(path[0].c_str(),flags);
if(fd == -1)
return -errno;
fh = fd;
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 struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _open(config.open,
config.srcmounts,
config.minfreespace,
fusepath,
fileinfo->flags,
fileinfo->fh);
ffi->flags,
ffi->fh);
}
}
}
+3 -3
View File
@@ -26,10 +26,10 @@
namespace mergerfs
{
namespace open
namespace fuse
{
int
open(const char *fusepath,
struct fuse_file_info *fileinfo);
open(const char *fusepath,
fuse_file_info *ffi);
}
}
+3 -3
View File
@@ -26,11 +26,11 @@
namespace mergerfs
{
namespace opendir
namespace fuse
{
int
opendir(const char *fusepath,
struct fuse_file_info *ffi)
opendir(const char *fusepath,
fuse_file_info *ffi)
{
ffi->fh = 0;
+3 -3
View File
@@ -26,10 +26,10 @@
namespace mergerfs
{
namespace opendir
namespace fuse
{
int
opendir(const char *fusepath,
struct fuse_file_info *ffi);
opendir(const char *fusepath,
fuse_file_info *ffi);
}
}
+45 -25
View File
@@ -45,7 +45,7 @@ using namespace mergerfs;
static
void
set_option(struct fuse_args &args,
set_option(fuse_args &args,
const std::string &option_)
{
string option;
@@ -57,7 +57,7 @@ set_option(struct fuse_args &args,
static
void
set_kv_option(struct fuse_args &args,
set_kv_option(fuse_args &args,
const std::string &key,
const std::string &value)
{
@@ -70,7 +70,7 @@ set_kv_option(struct fuse_args &args,
static
void
set_fsname(struct fuse_args &args,
set_fsname(fuse_args &args,
const vector<string> &srcmounts)
{
if(srcmounts.size() > 0)
@@ -85,21 +85,22 @@ set_fsname(struct fuse_args &args,
static
void
set_subtype(struct fuse_args &args)
set_subtype(fuse_args &args)
{
set_kv_option(args,"subtype","mergerfs");
}
static
void
set_default_options(struct fuse_args &args)
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");
set_option(args,"splice_move");
set_option(args,"auto_cache");
set_option(args,"atomic_o_trunc");
}
static
@@ -118,9 +119,24 @@ parse_and_process_minfreespace(const std::string &value,
static
int
parse_and_process_arg(config::Config &config,
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,
struct fuse_args *outargs)
fuse_args *outargs)
{
if(arg == "defaults")
{
@@ -133,7 +149,7 @@ parse_and_process_arg(config::Config &config,
static
int
parse_and_process_kv_arg(config::Config &config,
parse_and_process_kv_arg(Config &config,
const std::string &key,
const std::string &value)
{
@@ -152,6 +168,8 @@ parse_and_process_kv_arg(config::Config &config,
{
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)
@@ -162,9 +180,9 @@ parse_and_process_kv_arg(config::Config &config,
static
int
process_opt(config::Config &config,
process_opt(Config &config,
const std::string &arg,
struct fuse_args *outargs)
fuse_args *outargs)
{
int rv;
std::vector<std::string> argvalue;
@@ -191,8 +209,8 @@ process_opt(config::Config &config,
static
int
process_srcmounts(const char *arg,
config::Config &config)
process_srcmounts(const char *arg,
Config &config)
{
vector<string> paths;
@@ -200,13 +218,15 @@ process_srcmounts(const char *arg,
fs::glob(paths,config.srcmounts);
fs::realpathize(config.srcmounts);
return 0;
}
static
int
process_destmounts(const char *arg,
config::Config &config)
process_destmounts(const char *arg,
Config &config)
{
config.destmount = arg;
@@ -215,13 +235,13 @@ process_destmounts(const char *arg,
static
int
option_processor(void *data,
const char *arg,
int key,
struct fuse_args *outargs)
option_processor(void *data,
const char *arg,
int key,
fuse_args *outargs)
{
int rv = 0;
config::Config &config = *(config::Config*)data;
int rv = 0;
Config &config = *(Config*)data;
switch(key)
{
@@ -247,8 +267,8 @@ namespace mergerfs
namespace options
{
void
parse(struct fuse_args &args,
config::Config &config)
parse(fuse_args &args,
Config &config)
{
fuse_opt_parse(&args,
+2 -2
View File
@@ -31,7 +31,7 @@ namespace mergerfs
namespace options
{
void
parse(struct fuse_args &args,
mergerfs::config::Config &config);
parse(fuse_args &args,
Config &config);
}
}
+22 -10
View File
@@ -36,7 +36,12 @@ namespace mergerfs
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))
@@ -47,16 +52,23 @@ namespace mergerfs
const Policy * const Policy::policies = &_policies_[1];
const Policy &Policy::invalid = Policy::policies[Policy::Enum::invalid];
const Policy &Policy::all = Policy::policies[Policy::Enum::all];
const Policy &Policy::epmfs = Policy::policies[Policy::Enum::epmfs];
const Policy &Policy::ff = Policy::policies[Policy::Enum::ff];
const Policy &Policy::ffwp = Policy::policies[Policy::Enum::ffwp];
const Policy &Policy::fwfs = Policy::policies[Policy::Enum::fwfs];
const Policy &Policy::lfs = Policy::policies[Policy::Enum::lfs];
const Policy &Policy::mfs = Policy::policies[Policy::Enum::mfs];
const Policy &Policy::newest = Policy::policies[Policy::Enum::newest];
const Policy &Policy::rand = Policy::policies[Policy::Enum::rand];
#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)
+19 -2
View File
@@ -29,7 +29,6 @@
#include <vector>
#include <map>
#include "path.hpp"
#include "fs.hpp"
#include "category.hpp"
@@ -45,7 +44,12 @@ namespace mergerfs
invalid = -1,
BEGIN = 0,
all = BEGIN,
einval,
enosys,
enotsup,
epmfs,
erofs,
exdev,
ff,
ffwp,
fwfs,
@@ -55,6 +59,9 @@ namespace mergerfs
rand,
END
};
static size_t begin() { return BEGIN; }
static size_t end() { return END; }
};
struct Func
@@ -120,12 +127,17 @@ namespace mergerfs
const Ptr func;
};
static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&);
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&);
@@ -183,7 +195,12 @@ namespace mergerfs
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;
+23 -4
View File
@@ -30,6 +30,7 @@
#include <string>
#include <vector>
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
@@ -48,17 +49,32 @@ _all(const vector<string> &basepaths,
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const char *basepath;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
fs::path::make(basepath,fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
paths.push_back(basepath);
}
return paths.empty() ? (errno=ENOENT,-1) : 0;
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
@@ -70,6 +86,9 @@ namespace mergerfs
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _all_create(basepaths,paths);
return _all(basepaths,fusepath,paths);
}
}
+16 -28
View File
@@ -22,37 +22,25 @@
THE SOFTWARE.
*/
#include <sys/types.h>
#include <sys/unistd.h>
#include <errno.h>
#include <string>
#include <vector>
#include "policy.hpp"
using std::string;
using std::vector;
namespace mergerfs
{
namespace ugid
int
Policy::Func::einval(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
struct SetResetGuard
{
SetResetGuard(const uid_t _newuid,
const gid_t _newgid)
{
olduid = ::geteuid();
oldgid = ::getegid();
newuid = _newuid;
newgid = _newgid;
if(newgid != oldgid || newuid != olduid)
pthread_setugid_np(newuid,newgid);
}
~SetResetGuard()
{
if(newgid != oldgid || newuid != olduid)
pthread_setugid_np(newuid,newgid);
}
uid_t olduid;
gid_t oldgid;
uid_t newuid;
gid_t newgid;
};
return (errno=EINVAL,-1);
}
}
+46
View File
@@ -0,0 +1,46 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <errno.h>
#include <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);
}
}
+46
View File
@@ -0,0 +1,46 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <errno.h>
#include <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);
}
}
+33 -97
View File
@@ -31,125 +31,63 @@
#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_epmfs(const struct statvfs &fsstats,
const char *basepath,
fsblkcnt_t &epmfs,
const char *&epmfsbasepath,
fsblkcnt_t &mfs,
const char *&mfsbasepath)
_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 > epmfs)
{
epmfs = spaceavail;
epmfsbasepath = basepath;
}
if(spaceavail > mfs)
if((spaceavail > minfreespace) && (spaceavail > mfs))
{
mfs = spaceavail;
mfsbasepath = basepath;
}
}
static
inline
void
_calc_mfs(const struct statvfs &fsstats,
const char *basepath,
fsblkcnt_t &mfs,
const char *&mfsbasepath)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail > mfs)
{
mfs = spaceavail;
mfsbasepath = basepath;
}
}
static
inline
int
_try_statvfs(const char *basepath,
const string &fullpath,
fsblkcnt_t &epmfs,
const char *&epmfsbasepath,
fsblkcnt_t &mfs,
const char *&mfsbasepath)
{
int rv;
struct statvfs fsstats;
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
_calc_epmfs(fsstats,basepath,epmfs,epmfsbasepath,mfs,mfsbasepath);
return rv;
}
static
inline
int
_try_statvfs(const char *basepath,
fsblkcnt_t &mfs,
const char *&mfsbasepath)
{
int rv;
struct statvfs fsstats;
rv = ::statvfs(basepath,&fsstats);
if(rv == 0)
_calc_mfs(fsstats,basepath,mfs,mfsbasepath);
return rv;
}
static
int
_epmfs_create(const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
fsblkcnt_t epmfs;
fsblkcnt_t mfs;
const char *basepath;
const char *mfsbasepath;
const char *epmfsbasepath;
string fullpath;
int rv;
fsblkcnt_t epmfs;
string epmfsbasepath;
string fullpath;
statvfs_t fsstats;
mfs = 0;
epmfs = 0;
mfsbasepath = NULL;
epmfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
fs::path::make(basepath,fusepath,fullpath);
rv = _try_statvfs(basepath,fusepath,epmfs,epmfsbasepath,mfs,mfsbasepath);
if(rv == -1)
_try_statvfs(basepath,mfs,mfsbasepath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
_calc_mfs(fsstats,basepath,minfreespace,epmfs,epmfsbasepath);
}
if(epmfsbasepath == NULL)
epmfsbasepath = mfsbasepath;
if(epmfsbasepath.empty())
return Policy::Func::mfs(Category::Enum::create,basepaths,fusepath,minfreespace,paths);
paths.push_back(epmfsbasepath);
@@ -163,27 +101,25 @@ _epmfs(const vector<string> &basepaths,
vector<string> &paths)
{
fsblkcnt_t epmfs;
const char *basepath;
const char *epmfsbasepath;
string fullpath;
int rv;
fsblkcnt_t epmfs;
string epmfsbasepath;
string fullpath;
statvfs_t fsstats;
epmfs = 0;
epmfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct statvfs fsstats;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
fs::path::make(basepath,fusepath,fullpath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
_calc_mfs(fsstats,basepath,epmfs,epmfsbasepath);
_calc_mfs(fsstats,basepath,0,epmfs,epmfsbasepath);
}
if(epmfsbasepath == NULL)
if(epmfsbasepath.empty())
return (errno=ENOENT,-1);
paths.push_back(epmfsbasepath);
@@ -201,7 +137,7 @@ namespace mergerfs
vector<string> &paths)
{
if(type == Category::Enum::create)
return _epmfs_create(basepaths,fusepath,paths);
return _epmfs_create(basepaths,fusepath,minfreespace,paths);
return _epmfs(basepaths,fusepath,paths);
}
+46
View File
@@ -0,0 +1,46 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <errno.h>
#include <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);
}
}
+46
View File
@@ -0,0 +1,46 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <errno.h>
#include <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);
}
}
+22 -6
View File
@@ -30,7 +30,7 @@
#include <string>
#include <vector>
#include "path.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
@@ -45,12 +45,11 @@ _ff(const vector<string> &basepaths,
{
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct stat st;
const char *basepath;
string fullpath;
int rv;
struct stat st;
string fullpath;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
@@ -65,6 +64,20 @@ _ff(const vector<string> &basepaths,
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
@@ -74,6 +87,9 @@ namespace mergerfs
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _ff_create(basepaths,fusepath,paths);
return _ff(basepaths,fusepath,paths);
}
}
+8 -9
View File
@@ -30,6 +30,7 @@
#include <string>
#include <vector>
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
@@ -42,18 +43,16 @@ _ffwp(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
const char *fallback;
string fallback;
fallback = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct stat st;
const char *basepath;
string fullpath;
int rv;
struct stat st;
string fullpath;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
fs::path::make(basepath,fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
@@ -67,7 +66,7 @@ _ffwp(const vector<string> &basepaths,
}
}
if(fallback == NULL)
if(fallback.empty())
return (errno=ENOENT,-1);
paths.push_back(fallback);
+6 -6
View File
@@ -28,6 +28,7 @@
#include <string>
#include <vector>
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
@@ -47,11 +48,10 @@ _fwfs_create(const Category::Enum::Type type,
for(size_t i = 0, size = basepaths.size(); i != size; i++)
{
int rv;
const char *basepath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
rv = ::statvfs(basepath,&fsstats);
rv = ::statvfs(basepath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
@@ -81,11 +81,11 @@ _fwfs(const Category::Enum::Type type,
{
int rv;
string fullpath;
const char *basepath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
{
+1 -1
View File
@@ -42,6 +42,6 @@ namespace mergerfs
const size_t minfreespace,
vector<string> &rv)
{
return (errno = EINVAL,-1);
return (errno=EINVAL,-1);
}
}
+12 -14
View File
@@ -31,6 +31,7 @@
#include <string>
#include <vector>
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
@@ -47,19 +48,17 @@ _lfs_create(const Category::Enum::Type type,
const size_t minfreespace,
vector<string> &paths)
{
fsblkcnt_t lfs;
const char *lfsstr;
fsblkcnt_t lfs;
string lfsstr;
lfs = -1;
lfsstr = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
const char *basepath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
rv = ::statvfs(basepath,&fsstats);
rv = ::statvfs(basepath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
@@ -74,7 +73,7 @@ _lfs_create(const Category::Enum::Type type,
}
}
if(lfsstr == NULL)
if(lfsstr.empty())
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
paths.push_back(lfsstr);
@@ -90,20 +89,19 @@ _lfs(const Category::Enum::Type type,
const size_t minfreespace,
vector<string> &paths)
{
fsblkcnt_t lfs;
const char *lfsstr;
fsblkcnt_t lfs;
string lfsstr;
lfs = -1;
lfsstr = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
string fullpath;
const char *basepath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
{
@@ -119,7 +117,7 @@ _lfs(const Category::Enum::Type type,
}
}
if(lfsstr == NULL)
if(lfsstr.empty())
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
paths.push_back(lfsstr);
+12 -14
View File
@@ -28,6 +28,7 @@
#include <string>
#include <vector>
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
@@ -40,19 +41,17 @@ _mfs_create(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
fsblkcnt_t mfs;
const char *mfsstr;
fsblkcnt_t mfs;
string mfsstr;
mfs = 0;
mfsstr = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
const char *basepath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
rv = ::statvfs(basepath,&fsstats);
rv = ::statvfs(basepath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
@@ -66,7 +65,7 @@ _mfs_create(const vector<string> &basepaths,
}
}
if(mfsstr == NULL)
if(mfsstr.empty())
return (errno=ENOENT,-1);
paths.push_back(mfsstr);
@@ -80,20 +79,19 @@ _mfs(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
fsblkcnt_t mfs;
const char *mfsstr;
fsblkcnt_t mfs;
string mfsstr;
mfs = 0;
mfsstr = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
string fullpath;
const char *basepath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
{
@@ -108,7 +106,7 @@ _mfs(const vector<string> &basepaths,
}
}
if(mfsstr == NULL)
if(mfsstr.empty())
return (errno=ENOENT,-1);
paths.push_back(mfsstr);
+11 -12
View File
@@ -29,7 +29,9 @@
#include <string>
#include <vector>
#include <limits>
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
@@ -42,30 +44,27 @@ _newest(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
time_t newest;
const char *neweststr;
time_t newest = std::numeric_limits<time_t>::min();
string neweststr;
newest = 0;
neweststr = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct stat st;
const char *basepath;
string fullpath;
int rv;
struct stat st;
string fullpath;
const string &basepath = basepaths[i];
basepath = basepaths[i].c_str();
fullpath = fs::path::make(basepath,fusepath);
fs::path::make(basepath,fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0 && st.st_mtime > newest)
if(rv == 0 && st.st_mtime >= newest)
{
newest = st.st_mtime;
neweststr = basepath;
}
}
if(neweststr == NULL)
if(neweststr.empty())
return (errno=ENOENT,-1);
paths.push_back(neweststr);
+11 -7
View File
@@ -30,6 +30,8 @@
#include <string>
#include "fileinfo.hpp"
static
int
_read(const int fd,
@@ -46,16 +48,18 @@ _read(const int fd,
namespace mergerfs
{
namespace read
namespace fuse
{
int
read(const char *fusepath,
char *buf,
size_t count,
off_t offset,
struct fuse_file_info *ffi)
read(const char *fusepath,
char *buf,
size_t count,
off_t offset,
fuse_file_info *ffi)
{
return _read(ffi->fh,
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _read(fi->fd,
buf,
count,
offset);
+6 -6
View File
@@ -24,13 +24,13 @@
namespace mergerfs
{
namespace read
namespace fuse
{
int
read(const char *fusepath,
char *buf,
size_t count,
off_t offset,
struct fuse_file_info *fi);
read(const char *fusepath,
char *buf,
size_t count,
off_t offset,
fuse_file_info *fi);
}
}
+17 -13
View File
@@ -30,16 +30,18 @@
#include <errno.h>
#include <string.h>
#include "fileinfo.hpp"
static
int
_read_buf(const int fd,
struct fuse_bufvec **bufp,
const size_t size,
const off_t offset)
_read_buf(const int fd,
fuse_bufvec **bufp,
const size_t size,
const off_t offset)
{
struct fuse_bufvec *src;
fuse_bufvec *src;
src = (fuse_bufvec*)malloc(sizeof(struct fuse_bufvec));
src = (fuse_bufvec*)malloc(sizeof(fuse_bufvec));
if(src == NULL)
return -ENOMEM;
@@ -56,16 +58,18 @@ _read_buf(const int fd,
namespace mergerfs
{
namespace read_buf
namespace fuse
{
int
read_buf(const char *fusepath,
struct fuse_bufvec **bufp,
size_t size,
off_t offset,
struct fuse_file_info *ffi)
read_buf(const char *fusepath,
fuse_bufvec **bufp,
size_t size,
off_t offset,
fuse_file_info *ffi)
{
return _read_buf(ffi->fh,
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _read_buf(fi->fd,
bufp,
size,
offset);
+6 -6
View File
@@ -24,13 +24,13 @@
namespace mergerfs
{
namespace read_buf
namespace fuse
{
int
read_buf(const char *fusepath,
struct fuse_bufvec **buf,
size_t size,
off_t offset,
struct fuse_file_info *fi);
read_buf(const char *fusepath,
fuse_bufvec **buf,
size_t size,
off_t offset,
fuse_file_info *fi);
}
}
+14 -40
View File
@@ -33,17 +33,16 @@
#include <errno.h>
#include <dirent.h>
#include "readdir.hpp"
#include "config.hpp"
#include "ugid.hpp"
#include "fs.hpp"
#include "fs_path.hpp"
#include "readdir.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using std::set;
using std::pair;
using mergerfs::readdir::FileData;
#define NO_OFFSET 0
@@ -62,7 +61,7 @@ _readdir(const vector<string> &srcmounts,
DIR *dh;
string basepath;
basepath = fs::path::make(srcmounts[i],dirname);
fs::path::make(srcmounts[i],dirname,basepath);
dh = ::opendir(basepath.c_str());
if(!dh)
continue;
@@ -86,46 +85,21 @@ _readdir(const vector<string> &srcmounts,
return 0;
}
static
int
stat_vector_filler(void *buf,
const char *name,
const struct stat *stbuf,
off_t off)
{
vector<FileData> *stats = (vector<FileData>*)buf;
stats->push_back(FileData(name,*stbuf));
return 0;
}
namespace mergerfs
{
namespace readdir
namespace fuse
{
int
readdir(const vector<string> &srcmounts,
const string &dirname,
vector<FileData> &stats)
readdir(const char *fusepath,
void *buf,
fuse_fill_dir_t filler,
off_t offset,
fuse_file_info *fi)
{
return _readdir(srcmounts,
dirname,
&stats,
stat_vector_filler);
}
int
readdir(const char *fusepath,
void *buf,
fuse_fill_dir_t filler,
off_t offset,
struct fuse_file_info *fi)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _readdir(config.srcmounts,
fusepath,
+6 -23
View File
@@ -36,31 +36,14 @@
namespace mergerfs
{
namespace readdir
namespace fuse
{
struct FileData
{
FileData(const std::string &filename_,
const struct stat &stats_)
: filename(filename_),
stats(stats_)
{}
std::string filename;
struct stat stats;
};
int
readdir(const char *fusepath,
void *buf,
fuse_fill_dir_t filler,
off_t offset,
struct fuse_file_info *fi);
int
readdir(const std::vector<std::string> &srcmounts,
const std::string &dirname,
std::vector<FileData> &stats);
readdir(const char *fusepath,
void *buf,
fuse_fill_dir_t filler,
off_t offset,
fuse_file_info *fi);
}
}
+7 -7
View File
@@ -31,9 +31,9 @@
#include <string>
#include "config.hpp"
#include "ugid.hpp"
#include "fs.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -68,17 +68,17 @@ _readlink(Policy::Func::Search searchFunc,
namespace mergerfs
{
namespace readlink
namespace fuse
{
int
readlink(const char *fusepath,
char *buf,
size_t size)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _readlink(config.readlink,
config.srcmounts,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace readlink
namespace fuse
{
int
readlink(const char *fusepath,
+11 -7
View File
@@ -29,26 +29,30 @@
#include <string>
#include "fileinfo.hpp"
static
int
_release(uint64_t &fh)
_release(FileInfo *fi)
{
::close(fh);
::close(fi->fd);
fh = 0;
delete fi;
return 0;
}
namespace mergerfs
{
namespace release
namespace fuse
{
int
release(const char *fusepath,
struct fuse_file_info *ffi)
release(const char *fusepath,
fuse_file_info *ffi)
{
return _release(ffi->fh);
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _release(fi);
}
}
}
+3 -3
View File
@@ -24,10 +24,10 @@
namespace mergerfs
{
namespace release
namespace fuse
{
int
release(const char *fusepath,
struct fuse_file_info *fi);
release(const char *fusepath,
fuse_file_info *fi);
}
}
+3 -3
View File
@@ -26,11 +26,11 @@
namespace mergerfs
{
namespace releasedir
namespace fuse
{
int
releasedir(const char *fusepath,
struct fuse_file_info *ffi)
releasedir(const char *fusepath,
fuse_file_info *ffi)
{
return 0;
}
+3 -3
View File
@@ -26,10 +26,10 @@
namespace mergerfs
{
namespace releasedir
namespace fuse
{
int
releasedir(const char *fusepath,
struct fuse_file_info *ffi);
releasedir(const char *fusepath,
fuse_file_info *ffi);
}
}
+7 -7
View File
@@ -31,9 +31,9 @@
#include <sys/types.h>
#include "config.hpp"
#include "ugid.hpp"
#include "fs.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
#include "xattr.hpp"
using std::string;
@@ -75,20 +75,20 @@ _removexattr(Policy::Func::Action actionFunc,
namespace mergerfs
{
namespace removexattr
namespace fuse
{
int
removexattr(const char *fusepath,
const char *attrname)
{
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;
const struct fuse_context *fc = fuse_get_context();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _removexattr(config.removexattr,
config.srcmounts,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace removexattr
namespace fuse
{
int
removexattr(const char *fusepath,
+58 -41
View File
@@ -30,48 +30,74 @@
#include <string>
#include <vector>
#include <set>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
using std::set;
using mergerfs::Policy;
static
int
_single_rename(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &oldbasepath,
const string &oldfullpath,
const string &newpath)
bool
_different_dirname(const string &path0,
const string &path1)
{
return (fs::path::dirname(path0) != fs::path::dirname(path1));
}
static
void
_unlink(const set<string> &tounlink,
const string &newfusepath)
{
int rv;
const string newfullpath = fs::path::make(oldbasepath,newpath);
string fullpath;
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str());
if(rv == -1 && errno == ENOENT)
for(set<string>::const_iterator i = tounlink.begin(), ei = tounlink.end(); i != ei; i++)
{
string dirname;
vector<string> newpathdir;
fs::path::make(*i,newfusepath,fullpath);
dirname = fs::path::dirname(newpath);
rv = searchFunc(srcmounts,dirname,minfreespace,newpathdir);
if(rv == -1)
return -1;
rv = ::unlink(fullpath.c_str());
if(rv == -1 && errno == EISDIR)
::rmdir(fullpath.c_str());
}
}
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(newpathdir[0],oldbasepath,dirname);
}
static
int
_rename(const vector<string> &srcmounts,
const vector<string> &basepaths,
const string &oldfusepath,
const string &newfusepath)
{
int rv;
int error;
string oldfullpath;
string newfullpath;
set<string> tounlink;
error = 0;
tounlink.insert(srcmounts.begin(),srcmounts.end());
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
fs::path::make(basepaths[i],oldfusepath,oldfullpath);
fs::path::make(basepaths[i],newfusepath,newfullpath);
tounlink.erase(basepaths[i]);
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str());
if(rv == -1)
error = errno;
}
return rv;
if(error == 0)
_unlink(tounlink,newfusepath);
return -error;
}
static
@@ -84,39 +110,30 @@ _rename(Policy::Func::Search searchFunc,
const string &newfusepath)
{
int rv;
int error;
vector<string> oldbasepaths;
if(_different_dirname(oldfusepath,newfusepath))
return -EXDEV;
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
if(rv == -1)
return -errno;
error = 0;
for(size_t i = 0, ei = oldbasepaths.size(); i != ei; i++)
{
const string oldfullpath = fs::path::make(oldbasepaths[i],oldfusepath);
rv = _single_rename(searchFunc,srcmounts,minfreespace,
oldbasepaths[i],oldfullpath,newfusepath);
if(rv == -1)
error = errno;
}
return -error;
return _rename(srcmounts,oldbasepaths,oldfusepath,newfusepath);
}
namespace mergerfs
{
namespace rename
namespace fuse
{
int
rename(const char *oldpath,
const char *newpath)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
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 _rename(config.getattr,
config.rename,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace rename
namespace fuse
{
int
rename(const char *from,
+7 -7
View File
@@ -29,10 +29,10 @@
#include <string>
#include "ugid.hpp"
#include "fs.hpp"
#include "config.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
using std::string;
using std::vector;
@@ -68,15 +68,15 @@ _rmdir(Policy::Func::Action actionFunc,
namespace mergerfs
{
namespace rmdir
namespace fuse
{
int
rmdir(const char *fusepath)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readguard(&config.srcmountslock);
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readguard(&config.srcmountslock);
return _rmdir(config.rmdir,
config.srcmounts,

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