Compare commits

...
75 Commits
Author SHA1 Message Date
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
Antonio SJ Musumeci e4be3aac2a Merge pull request #83 from trapexit/enotsup
ignore ENOTSUP errors when cloning paths. fixes #82
2015-07-13 12:21:48 -04:00
Antonio SJ Musumeci 4d605388a4 ignore ENOTSUP errors when cloning paths. fixes #82 2015-07-13 12:20:19 -04:00
Antonio SJ Musumeci 2ee3d4eec2 Merge pull request #81 from trapexit/num
add str to size_t conversion code
2015-07-05 21:03:34 -04:00
Antonio SJ Musumeci aafc1e9394 add str to size_t conversion code 2015-07-05 21:02:42 -04:00
Antonio SJ Musumeci eebfe456f6 Merge pull request #80 from trapexit/minfreespace-xattr
add minfreespace to xattr interface
2015-07-05 20:01:12 -04:00
Antonio SJ Musumeci b3109ac506 add minfreespace to xattr interface 2015-07-05 19:36:23 -04:00
Antonio SJ Musumeci 54484f35fc Merge pull request #79 from trapexit/readme
Readme
2015-07-03 10:51:29 -04:00
Antonio SJ Musumeci d079856e09 add info on lfs and fwfs policies and minfreespace option 2015-07-03 10:49:18 -04:00
Antonio SJ Musumeci c101430b98 rework category -> fuse function table 2015-07-03 10:49:18 -04:00
Antonio SJ Musumeci 1d798ad285 Merge pull request #78 from trapexit/typed-policies
Typed policies
2015-07-03 10:47:02 -04:00
Antonio SJ Musumeci b2cd79154a stop auto calculating and storing fullpath in policies 2015-07-03 10:40:47 -04:00
Antonio SJ Musumeci 0c60701b29 create different policies based on category of use 2015-07-03 08:53:36 -04:00
Antonio SJ Musumeci 51b6d3f647 add category to policies so as to distinguish between creates and searches 2015-07-03 08:51:19 -04:00
Antonio SJ Musumeci a5bf48c8ae Merge pull request #77 from trapexit/paths
Paths
2015-06-23 22:30:35 -04:00
Antonio SJ Musumeci 6ca43893ea separate policies into individual modules 2015-06-23 22:27:01 -04:00
Antonio SJ Musumeci 3c8f12281f move policy function type from fs to policy 2015-06-23 00:24:14 -04:00
Antonio SJ Musumeci 2bd44568a1 move Path object to separate file 2015-06-22 23:22:51 -04:00
Antonio SJ Musumeci 23cca83742 Merge pull request #76 from trapexit/lfs
create lfs policy. closes #73
2015-06-22 11:27:58 -04:00
Antonio SJ Musumeci 8e5b79647b create lfs policy. closes #73 2015-06-22 11:06:36 -04:00
Antonio SJ Musumeci 9ea4bf2828 Merge pull request #75 from trapexit/fwfs
first w/ free space policy. closes #72
2015-06-22 11:03:49 -04:00
Antonio SJ Musumeci 58167c3636 first w/ free space policy. closes #72 2015-06-22 10:53:39 -04:00
Antonio SJ Musumeci 6578b93190 Merge pull request #74 from trapexit/minfreespace
create minfreespace option. closes #71
2015-06-22 10:19:03 -04:00
Antonio SJ Musumeci ccb22c1fbe create minfreespace option. closes #71 2015-06-22 09:59:16 -04:00
110 changed files with 2908 additions and 1414 deletions
+54 -16
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),"")
@@ -81,10 +84,16 @@ CFLAGS = -g -Wall \
-DWRITE_BUF=$(WRITE_BUF)
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")
@@ -97,14 +106,24 @@ 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)
$(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,10 +132,11 @@ obj/obj-stamp:
obj/%.o: src/%.cpp
$(CXX) $(CFLAGS) -c $< -o $@
clean:
clean: rpm-clean
$(RM) -rf obj
$(RM) -f src/version.hpp
$(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
$(FIND) -name "*~" -delete
$(FIND) . -name "*~" -delete
distclean: clean
$(GIT) clean -fd
@@ -130,7 +150,7 @@ install-clonepath: clonepath
$(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)"
@@ -144,26 +164,44 @@ uninstall-clonepath:
$(RM) -f "$(INSTALLBINDIR)/clonepath"
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
deb: debian-changelog
dpkg-buildpackage
unsigned-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
+96 -112
View File
@@ -1,6 +1,6 @@
% mergerfs(1) mergerfs user manual
% Antonio SJ Musumeci <trapexit@spawn.link>
% 2015-06-05
% 2015-07-03
# NAME
@@ -12,25 +12,23 @@ 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 create **mergerfs** when those exist? **mhddfs** has not been updated in some time nor very flexible. There are also security issues when with running as root. **aufs** is more flexible than **mhddfs** but contains some hard to debug inconsistencies in behavior on account of it being a kernel driver. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
# 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.
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** is a shortcut for **auto_cache**. **big_writes**, **atomic_o_trunc**, **splice_read**, **splice_write**, and **splice_move** are in effect also enabled (by asking **FUSE** internally for such features) but if unavailable will be ignored. These options seem to provide the best performance.
* **minfreespace** (defaults to **4G**) is the minimum space value used for the **lfs**, **fwfs**, and **epmfs** policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively.
* All FUSE functions which have a category (see below) are option keys. The syntax being **func.&lt;func&gt;=&lt;policy&gt;**. Example: **func.getattr=newest**.
* To set all function policies in a category use **categor.&lt;category&gt;=&lt;policy&gt;**. Example: **category.create=mfs**.
* Options are evaluated in the order listed so if the options are **func.rmdir=rand,category.action=ff** the **action** category setting will override the **rmdir** setting.
###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).
```
$ mergerfs /mnt/disk*:/mnt/cdrom /media/drives
@@ -45,132 +43,121 @@ In /etc/fstab it'd look like the following:
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other 0 0
```
**NOTE:** the globbing is done at mount time. If a new directory is added matching the glob after the fact it will not be included.
**NOTE:** the globbing is done at mount or xattr update time. If a new directory is added matching the glob after the fact it will not be included.
# POLICIES
Filesystem calls are broken up into 3 categories: action, create, search. There are also some calls which have no policy attached due to state being kept between calls. These categories can be assigned a policy which dictates how [mergerfs](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 ####
| FUSE Function | Class |
|-------------|---------|
| access | search |
| chmod | action |
| chown | action |
| create | create |
| fallocate | N/A |
| fgetattr | N/A |
| fsync | N/A |
| ftruncate | N/A |
| getattr | search |
| getxattr | search |
| ioctl | N/A* |
| link | action |
| listxattr | search |
| mkdir | create |
| mknod | create |
| open | search |
| read | N/A |
| readdir | N/A |
| readlink | search |
| release | N/A |
| removexattr | action |
| rename | action |
| rmdir | action |
| setxattr | action |
| statfs | N/A |
| symlink | create |
| truncate | action |
| unlink | action |
| utimens | action |
| write | N/A |
`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.
| Category | FUSE Functions |
|----------|----------------|
| action | chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate, unlink, utimens |
| create | create, mkdir, mknod, symlink |
| search | access, getattr, getxattr, ioctl, listxattr, open, readlink |
| N/A | fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, release, statfs, write |
**ioctl** behaves differently if its acting on a directory. It'll use the **getattr** policy to find and open the directory before issuing the **ioctl**. In other cases where something may be searched (to confirm a directory exists across all source mounts) then **getattr** will be used.
#### Policy descriptions ####
| Policy | Description |
|--------------|-------------|
| 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) | Assuming the path is found to exist (ENOENT would not be returned) 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. |
| rand (random) | Pick an existing destination at random. |
| all | Applies action to all found. For searches it will behave like first found `ff`. |
| mfs (most free space) | Use the drive with the most free space available. |
| epmfs (existing path, most free space) | If the path exists on multiple drives use the one with the most free space and is greater than **minfreespace**. If no drive has at least **minfreespace** then fallback to **mfs**. |
| fwfs (first with free space) | Pick the first drive which has at least **minfreespace**. |
| lfs (least free space) | Pick the drive with least available space but more than **minfreespace**. |
| rand (random) | Pick an existing drive at random. |
| all | Applies action to all found. For searches it will behave like first found **ff**. |
| enosys, einval, enotsup, exdev, erofs | Exclusively return `-1` with `errno` set to the respective value. Useful for debugging other applications' behavior to errors. |
#### Defaults ####
| Category | Policy |
|----------|--------|
| action | all |
| 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).
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 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.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 #####
```
[trapexit:/tmp/mount] $ xattr -l .mergerfs
user.mergerfs.srcmounts: /tmp/a:/tmp/b
user.mergerfs.minfreespace: 4294967295
user.mergerfs.category.action: all
user.mergerfs.category.create: epmfs
user.mergerfs.category.search: ff
@@ -221,22 +208,21 @@ 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 #####
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`.
Categories and funcs take a policy as described in the previous section. When reading funcs you'll get the policy string. However, with categories you'll get a comma separated list of policies for each type found. For example: if all search functions are **ff** except for **access** which is **ffwp** the value for **user.mergerfs.category.search** will be **ff,ffwp**.
#### mergerfs file xattrs ####
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
@@ -257,27 +243,25 @@ 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).
* 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) 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).
# 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. When building on OSX mergerfs will use this without any mutexes.
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)
> 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).
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 privileges be needed (for instance: to clone paths).
+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.
+13 -8
View File
@@ -42,41 +42,46 @@
using std::string;
using std::vector;
using mergerfs::Policy;
using mergerfs::Category;
static
int
_access(const fs::find::Func searchFunc,
_access(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const int mask)
{
int rv;
fs::Paths paths;
vector<string> path;
rv = searchFunc(srcmounts,fusepath,paths,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1)
return -errno;
rv = ::eaccess(paths[0].full.c_str(),mask);
fs::path::append(path[0],fusepath);
rv = ::eaccess(path[0].c_str(),mask);
return ((rv == -1) ? -errno : 0);
}
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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _access(*config.access,
return _access(config.access,
config.srcmounts,
config.minfreespace,
fusepath,
mask);
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace access
namespace fuse
{
int
access(const char *fusepath,
+13 -10
View File
@@ -39,24 +39,26 @@ using mergerfs::Policy;
static
int
_chmod(const fs::find::Func actionFunc,
_chmod(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const mode_t mode)
{
int rv;
int error;
fs::Paths paths;
vector<string> paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = paths.begin(), ei = paths.end(); i != ei; ++i)
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
rv = ::chmod(i->full.c_str(),mode);
fs::path::append(paths[i],fusepath);
rv = ::chmod(paths[i].c_str(),mode);
if(rv == -1)
error = errno;
}
@@ -66,19 +68,20 @@ _chmod(const fs::find::Func actionFunc,
namespace mergerfs
{
namespace chmod
namespace fuse
{
int
chmod(const char *fusepath,
mode_t mode)
{
const struct fuse_context *fc = fuse_get_context();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const config::Config &config = config::get();
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _chmod(*config.chmod,
return _chmod(config.chmod,
config.srcmounts,
config.minfreespace,
fusepath,
mode);
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace chmod
namespace fuse
{
int
chmod(const char *fusepath,
+14 -10
View File
@@ -37,28 +37,31 @@
using std::string;
using std::vector;
using mergerfs::Policy;
using mergerfs::Config;
static
int
_chown(const fs::find::Func actionFunc,
_chown(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const uid_t uid,
const gid_t gid)
{
int rv;
int error;
fs::Paths paths;
vector<string> paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = paths.begin(), ei = paths.end(); i != ei; ++i)
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
rv = ::lchown(i->full.c_str(),uid,gid);
fs::path::append(paths[i],fusepath);
rv = ::lchown(paths[i].c_str(),uid,gid);
if(rv == -1)
error = errno;
}
@@ -68,20 +71,21 @@ _chown(const fs::find::Func 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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _chown(*config.chown,
return _chown(config.chown,
config.srcmounts,
config.minfreespace,
fusepath,
uid,
gid);
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace chown
namespace fuse
{
int
chown(const char *fusepath,
+64 -84
View File
@@ -40,101 +40,81 @@ using std::vector;
namespace mergerfs
{
namespace config
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")
{
Config::Config()
: destmount(),
srcmounts(),
srcmountslock(),
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 -46
View File
@@ -28,6 +28,7 @@
#include <fuse.h>
#include <sys/stat.h>
#include <stdint.h>
#include <string>
#include <vector>
@@ -37,55 +38,64 @@
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;
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;
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
+21 -20
View File
@@ -43,9 +43,10 @@ using mergerfs::Policy;
static
int
_create(const fs::find::Func searchFunc,
const fs::find::Func createFunc,
_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const mode_t mode,
const int flags,
@@ -53,29 +54,28 @@ _create(const fs::find::Func searchFunc,
{
int fd;
int rv;
string path;
string dirname;
fs::Paths createpath;
fs::Paths existingpath;
vector<string> createpath;
vector<string> existingpath;
dirname = fs::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,existingpath,1);
dirname = fs::path::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
if(rv == -1)
return -errno;
rv = createFunc(srcmounts,dirname,createpath,1);
rv = createFunc(srcmounts,dirname,minfreespace,createpath);
if(rv == -1)
return -errno;
if(createpath[0].base != existingpath[0].base)
if(createpath[0] != existingpath[0])
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
fs::clonepath(existingpath[0],createpath[0],dirname);
}
path = fs::make_path(createpath[0].base,fusepath);
fs::path::append(createpath[0],fusepath);
fd = ::open(path.c_str(),flags,mode);
fd = ::open(createpath[0].c_str(),flags,mode);
if(fd == -1)
return -errno;
@@ -86,21 +86,22 @@ _create(const fs::find::Func searchFunc,
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 *fileinfo)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _create(*config.getattr,
*config.create,
return _create(config.getattr,
config.create,
config.srcmounts,
config.minfreespace,
fusepath,
(mode & ~fc->umask),
fileinfo->flags,
+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 *fileinfo);
}
}
+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 *);
+6 -6
View File
@@ -64,14 +64,14 @@ _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,
mode,
+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);
}
}
+4 -4
View File
@@ -43,12 +43,12 @@ _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,
*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);
}
}
+3 -3
View File
@@ -44,11 +44,11 @@ _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);
}
+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);
}
}
+100 -353
View File
@@ -28,8 +28,9 @@
#include <sstream>
#include <cstdlib>
#include <iterator>
#include <algorithm>
#include <stdlib.h>
#include <limits.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -64,102 +65,85 @@ random_element(Iter begin,
namespace fs
{
string
dirname(const string &path)
namespace path
{
string parent = path;
string::reverse_iterator i;
string::reverse_iterator bi;
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++;
bi = parent.rend();
i = parent.rbegin();
while(*i == '/' && i != bi)
i++;
while(*i != '/' && i != bi)
i++;
while(*i != '/' && i != bi)
i++;
while(*i == '/' && i != bi)
i++;
while(*i == '/' && i != bi)
i++;
parent.erase(i.base(),parent.end());
parent.erase(i.base(),parent.end());
return parent;
}
return parent;
}
string
basename(const string &path)
{
return path.substr(path.find_last_of('/')+1);
}
string
basename(const string &path)
{
return path.substr(path.find_last_of('/')+1);
}
bool
dir_is_empty(const string &path)
{
DIR *dir;
struct dirent *de;
dir = ::opendir(path.c_str());
if(!dir)
return false;
while((de = ::readdir(dir)))
{
const char *d_name = de->d_name;
if(d_name[0] == '.' &&
((d_name[1] == '\0') ||
(d_name[1] == '.' && d_name[2] == '\0')))
continue;
::closedir(dir);
bool
is_empty(const string &path)
{
DIR *dir;
struct dirent *de;
dir = ::opendir(path.c_str());
if(!dir)
return false;
}
::closedir(dir);
while((de = ::readdir(dir)))
{
const char *d_name = de->d_name;
return true;
}
if(d_name[0] == '.' &&
((d_name[1] == '\0') ||
(d_name[1] == '.' && d_name[2] == '\0')))
continue;
string
make_path(const string &base,
const string &suffix)
{
if(suffix[0] == '/' ||
*base.rbegin() == '/')
return base + suffix;
return base + '/' + suffix;
}
::closedir(dir);
bool
path_exists(vector<string>::const_iterator begin,
vector<string>::const_iterator end,
const string &fusepath)
{
for(vector<string>::const_iterator
iter = begin; iter != end; ++iter)
{
int rv;
string path;
struct stat st;
return false;
}
path = fs::make_path(*iter,fusepath);
rv = ::lstat(path.c_str(),&st);
if(rv == 0)
return true;
}
::closedir(dir);
return false;
}
return true;
}
bool
path_exists(const vector<string> &srcmounts,
const string &fusepath)
{
return path_exists(srcmounts.begin(),
srcmounts.end(),
fusepath);
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;
}
}
void
@@ -167,16 +151,14 @@ namespace fs
const string &fusepath,
vector<string> &paths)
{
for(vector<string>::const_iterator
iter = srcmounts.begin(), eiter = srcmounts.end();
iter != eiter;
++iter)
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
int rv;
string fullpath;
struct stat st;
fullpath = fs::make_path(*iter,fusepath);
fs::path::make(srcmounts[i],fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
paths.push_back(fullpath);
@@ -440,6 +422,23 @@ namespace fs
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,
@@ -451,7 +450,7 @@ namespace fs
string frompath;
string dirname;
dirname = fs::dirname(relative);
dirname = fs::path::dirname(relative);
if(!dirname.empty())
{
rv = clonepath(fromsrc,tosrc,dirname);
@@ -459,15 +458,14 @@ namespace fs
return -1;
}
frompath = fs::make_path(fromsrc,relative);
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);
topath = fs::make_path(tosrc,relative);
fs::path::make(tosrc,relative,topath);
rv = ::mkdir(topath.c_str(),st.st_mode);
if(rv == -1)
{
@@ -485,11 +483,11 @@ namespace fs
// It may not support it... it's fine...
rv = copyattr(frompath,topath);
if(rv == -1 && errno != ENOTTY)
if(rv == -1 && !ignorable_error(errno))
return -1;
rv = copyxattrs(frompath,topath);
if(rv == -1 && errno != ENOTTY)
if(rv == -1 && !ignorable_error(errno))
return -1;
return 0;
@@ -515,270 +513,19 @@ namespace fs
globfree(&gbuf);
}
namespace find
void
realpathize(vector<string> &strs)
{
int
invalid(const vector<string> &basepaths,
const string &fusepath,
Paths &rv,
size_t count)
{
return (errno = EINVAL,-1);
}
char *rv;
char buf[PATH_MAX];
int
ff(const vector<string> &basepaths,
const string &fusepath,
Paths &paths,
size_t count)
{
errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
++iter)
{
int rv;
struct stat st;
string fullpath;
for(size_t i = 0; i < strs.size(); i++)
{
rv = ::realpath(strs[i].c_str(),buf);
if(rv == NULL)
continue;
fullpath = fs::make_path(*iter,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
{
paths.push_back(Path(*iter,fullpath));
return 0;
}
}
return -1;
}
int
ffwp(const vector<string> &basepaths,
const string &fusepath,
Paths &paths,
size_t count)
{
Path fallback;
errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
++iter)
{
int rv;
struct stat st;
string fullpath;
fullpath = fs::make_path(*iter,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
{
paths.push_back(Path(*iter,fullpath));
return 0;
}
else if(errno == EACCES)
{
fallback.base = *iter;
fallback.full = fullpath;
}
}
if(!fallback.base.empty())
return (paths.push_back(fallback),0);
return -1;
}
int
newest(const vector<string> &basepaths,
const string &fusepath,
Paths &paths,
size_t count)
{
time_t newest;
string npath;
vector<string>::const_iterator niter;
newest = 0;
errno = ENOENT;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter;
++iter)
{
int rv;
struct stat st;
string fullpath;
fullpath = fs::make_path(*iter,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0 && st.st_mtime > newest)
{
newest = st.st_mtime;
niter = iter;
npath = fullpath;
}
}
if(newest)
return (paths.push_back(Path(*niter,npath)),0);
return -1;
}
int
mfs(const vector<string> &basepaths,
const string &fusepath,
Paths &paths,
size_t count)
{
fsblkcnt_t mfs;
size_t mfsidx;
mfs = 0;
for(size_t i = 0, size = basepaths.size();
i != size;
i++)
{
int rv;
struct statvfs fsstats;
rv = ::statvfs(basepaths[i].c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail > mfs)
{
mfs = spaceavail;
mfsidx = i;
}
}
}
if(mfs == 0)
return (errno=ENOENT,-1);
paths.push_back(Path(basepaths[mfsidx],
fs::make_path(basepaths[mfsidx],fusepath)));
return 0;
}
int
epmfs(const vector<string> &basepaths,
const string &fusepath,
Paths &paths,
size_t count)
{
fsblkcnt_t existingmfs = 0;
fsblkcnt_t generalmfs = 0;
string fullpath;
string generalmfspath;
string existingmfspath;
vector<string>::const_iterator iter = basepaths.begin();
vector<string>::const_iterator eiter = basepaths.end();
if(iter == eiter)
return (errno = ENOENT,-1);
do
{
int rv;
struct statvfs fsstats;
const string &mountpoint = *iter;
rv = ::statvfs(mountpoint.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
struct stat st;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail > generalmfs)
{
generalmfs = spaceavail;
generalmfspath = mountpoint;
}
fullpath = fs::make_path(mountpoint,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
{
if(spaceavail > existingmfs)
{
existingmfs = spaceavail;
existingmfspath = mountpoint;
}
}
}
++iter;
}
while(iter != eiter);
if(existingmfspath.empty())
existingmfspath = generalmfspath;
paths.push_back(Path(existingmfspath,
fullpath));
return 0;
}
int
all(const vector<string> &basepaths,
const string &fusepath,
Paths &paths,
size_t count)
{
int rv;
struct stat st;
string fullpath;
for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter && count;
++iter)
{
fullpath = fs::make_path(*iter,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
{
paths.push_back(Path(*iter,fullpath));
count--;
}
}
return paths.empty() ? (errno=ENOENT,-1) : 0;
}
int
rand(const vector<string> &basepaths,
const string &fusepath,
Paths &paths,
size_t count)
{
int rv;
rv = all(basepaths,fusepath,paths,-1);
if(rv == -1)
return -1;
std::random_shuffle(paths.begin(),paths.end());
if(paths.size() > count)
paths.resize(count);
return 0;
}
strs[i] = buf;
}
}
};
+35 -59
View File
@@ -29,6 +29,8 @@
#include <vector>
#include <map>
#include "path.hpp"
namespace fs
{
using std::size_t;
@@ -36,34 +38,44 @@ namespace fs
using std::vector;
using std::map;
struct Path
namespace path
{
Path() {}
Path(const string &b,
const string &f)
: base(b),
full(f)
{}
string dirname(const string &path);
string basename(const string &path);
string base;
string full;
};
bool is_empty(const string &path);
typedef vector<Path> Paths;
bool exists(vector<string>::const_iterator begin,
vector<string>::const_iterator end,
const string &fusepath);
bool exists(const vector<string> &srcmounts,
const string &fusepath);
string dirname(const string &path);
string basename(const string &path);
inline
string
make(const string &base,
const string &suffix)
{
return base + suffix;
}
bool dir_is_empty(const string &path);
inline
void
make(const string &base,
const string &suffix,
string &output)
{
output = base + suffix;
}
string make_path(const string &base,
const string &suffix);
bool path_exists(vector<string>::const_iterator begin,
vector<string>::const_iterator end,
const string &fusepath);
bool path_exists(const vector<string> &srcmounts,
const string &fusepath);
inline
void
append(string &base,
const string &suffix)
{
base += suffix;
}
}
void findallfiles(const vector<string> &srcmounts,
const string &fusepath,
@@ -111,43 +123,7 @@ namespace fs
void glob(const vector<string> &patterns,
vector<string> &strs);
namespace find
{
typedef int (*Func)(const vector<string>&,const string&,Paths&,size_t);
int invalid(const vector<string> &basepaths,
const string &fusepath,
Paths &path,
size_t max);
int all(const vector<string> &basepaths,
const string &fusepath,
Paths &path,
size_t max);
int ff(const vector<string> &basepaths,
const string &fusepath,
Paths &path,
size_t max);
int ffwp(const vector<string> &paths,
const string &fusepath,
Paths &path,
size_t max);
int newest(const vector<string> &paths,
const string &fusepath,
Paths &path,
size_t max);
int mfs(const vector<string> &paths,
const string &fusepath,
Paths &path,
size_t max);
int epmfs(const vector<string> &paths,
const string &fusepath,
Paths &path,
size_t max);
int rand(const vector<string> &paths,
const string &fusepath,
Paths &path,
size_t max);
}
void realpathize(vector<string> &strs);
};
#endif // __FS_HPP__
+4 -4
View File
@@ -50,12 +50,12 @@ _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,
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);
}
}
+4 -4
View File
@@ -42,12 +42,12 @@ _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,
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);
}
}
+13 -8
View File
@@ -39,6 +39,7 @@
using std::string;
using std::vector;
using mergerfs::Policy;
static
int
@@ -65,42 +66,46 @@ _getattr_controlfile(struct stat &buf)
static
int
_getattr(const fs::find::Func searchFunc,
_getattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
struct stat &buf)
{
int rv;
fs::Paths path;
vector<string> path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1)
return -errno;
rv = ::lstat(path[0].full.c_str(),&buf);
fs::path::append(path[0],fusepath);
rv = ::lstat(path[0].c_str(),&buf);
return ((rv == -1) ? -errno : 0);
}
namespace mergerfs
{
namespace getattr
namespace fuse
{
int
getattr(const char *fusepath,
struct stat *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);
return _getattr(*config.getattr,
return _getattr(config.getattr,
config.srcmounts,
config.minfreespace,
fusepath,
*st);
}
+1 -1
View File
@@ -28,7 +28,7 @@
namespace mergerfs
{
namespace getattr
namespace fuse
{
int
getattr(const char *fusepath,
+117 -48
View File
@@ -29,6 +29,7 @@
#include <set>
#include <algorithm>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
@@ -39,22 +40,40 @@
#include "rwlock.hpp"
#include "xattr.hpp"
#include "str.hpp"
#include "version.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];
}
@@ -62,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;
@@ -92,26 +111,72 @@ _getxattr_controlfile_srcmounts(const Config &config,
attrvalue = str::join(config.srcmounts,':');
}
static
void
_getxattr_controlfile_minfreespace(const Config &config,
string &attrvalue)
{
char buf[64];
snprintf(buf,sizeof(buf),"%li",config.minfreespace);
attrvalue = buf;
}
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(!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] == "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;
@@ -141,7 +206,7 @@ _getxattr_from_string(char *destbuf,
return srcbufsize;
if(srcbufsize > destbufsize)
return (errno = ERANGE, -1);
return -ERANGE;
memcpy(destbuf,src.data(),srcbufsize);
@@ -162,63 +227,66 @@ _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
int
_getxattr_user_mergerfs(const fs::Path &path,
const vector<string> &srcmounts,
_getxattr_user_mergerfs(const string &basepath,
const string &fusepath,
const char *attrname,
const string &fullpath,
const vector<string> &srcmounts,
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,path.base);
else if(!strcmp(attrbasename,"fullpath"))
return ::_getxattr_from_string(buf,count,path.full);
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(path.full.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
int
_getxattr(const fs::find::Func searchFunc,
_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;
fs::Paths path;
string fullpath;
vector<string> basepath;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,basepath);
if(rv == -1)
return -errno;
if(!strncmp("user.mergerfs.",attrname,sizeof("user.mergerfs.")-1))
rv = _getxattr_user_mergerfs(path[0],srcmounts,fusepath,attrname,buf,count);
else
rv = ::lgetxattr(path[0].full.c_str(),attrname,buf,count);
fs::path::make(basepath[0],fusepath,fullpath);
return ((rv == -1) ? -errno : rv);
#else
return -ENOTSUP;
#endif
if(str::isprefix(attrname,"user.mergerfs."))
rv = _getxattr_user_mergerfs(basepath[0],fusepath,fullpath,srcmounts,attrname,buf,count);
else
rv = _lgetxattr(fullpath,attrname,buf,count);
return rv;
}
namespace mergerfs
{
namespace getxattr
namespace fuse
{
int
getxattr(const char *fusepath,
@@ -226,7 +294,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,
@@ -234,12 +303,12 @@ 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::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _getxattr(*config.getxattr,
return _getxattr(config.getxattr,
config.srcmounts,
config.minfreespace,
fusepath,
attrname,
buf,
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace getxattr
namespace fuse
{
int
getxattr(const char *fusepath,
+21 -3
View File
@@ -28,16 +28,34 @@
namespace mergerfs
{
namespace init
namespace fuse
{
void *
init(struct fuse_conn_info *conn)
init(fuse_conn_info *conn)
{
#ifdef FUSE_CAP_ASYNC_READ
conn->want |= FUSE_CAP_ASYNC_READ;
#endif
#ifdef FUSE_CAP_IOCTL_DIR
conn->want |= FUSE_CAP_IOCTL_DIR;
#endif
#ifdef FUSE_CAP_ATOMIC_O_TRUNC
conn->want |= FUSE_CAP_ATOMIC_O_TRUNC;
#endif
#ifdef FUSE_CAP_BIG_WRITES
conn->want |= FUSE_CAP_BIG_WRITES;
#endif
#ifdef FUSE_CAP_SPLICE_WRITE
conn->want |= FUSE_CAP_SPLICE_WRITE;
#endif
#ifdef FUSE_CAP_SPLICE_READ
conn->want |= FUSE_CAP_SPLICE_READ;
#endif
#ifdef FUSE_CAP_SPLICE_MOVE
conn->want |= FUSE_CAP_SPLICE_MOVE;
#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);
}
}
+33 -57
View File
@@ -43,120 +43,96 @@ static
int
_ioctl(const int fd,
const int cmd,
void *arg,
const unsigned int flags,
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(const fs::find::Func searchFunc,
_ioctl_dir_base(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const int cmd,
void *arg,
const unsigned int flags,
void *data)
{
int fd;
int rv;
fs::Paths path;
vector<string> path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1)
return -errno;
fd = ::open(path[0].full.c_str(),flags);
fs::path::append(path[0],fusepath);
fd = ::open(path[0].c_str(),O_RDWR|O_NOATIME|O_DIRECTORY);
if(fd == -1)
return -errno;
rv = _ioctl(fd,cmd,arg,flags,data);
rv = _ioctl(fd,cmd,data);
close(fd);
::close(fd);
return rv;
}
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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _ioctl_dir_base(*config.getattr,
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
return _ioctl(ffi->fh,
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);
}
}
+21 -19
View File
@@ -41,30 +41,31 @@ using mergerfs::Policy;
static
int
_single_link(const fs::find::Func searchFunc,
_single_link(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &base,
const string &oldpath,
const string &newpath)
{
int rv;
const string fulloldpath = fs::make_path(base,oldpath);
const string fullnewpath = fs::make_path(base,newpath);
const string fulloldpath = fs::path::make(base,oldpath);
const string fullnewpath = fs::path::make(base,newpath);
rv = ::link(fulloldpath.c_str(),fullnewpath.c_str());
if(rv == -1 && errno == ENOENT)
{
string newpathdir;
fs::Paths foundpath;
vector<string> foundpath;
newpathdir = fs::dirname(newpath);
rv = searchFunc(srcmounts,newpathdir,foundpath,1);
newpathdir = fs::path::dirname(newpath);
rv = searchFunc(srcmounts,newpathdir,minfreespace,foundpath);
if(rv == -1)
return -1;
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(foundpath[0].base,base,newpathdir);
fs::clonepath(foundpath[0],base,newpathdir);
}
rv = ::link(fulloldpath.c_str(),fullnewpath.c_str());
@@ -75,25 +76,25 @@ _single_link(const fs::find::Func searchFunc,
static
int
_link(const fs::find::Func searchFunc,
const fs::find::Func actionFunc,
_link(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &oldpath,
const string &newpath)
{
int rv;
int error;
fs::Paths oldpaths;
vector<string> oldpaths;
rv = actionFunc(srcmounts,oldpath,oldpaths,-1);
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
for(size_t i = 0, ei = oldpaths.size(); i != ei; i++)
{
rv = _single_link(searchFunc,srcmounts,i->base,oldpath,newpath);
rv = _single_link(searchFunc,srcmounts,minfreespace,oldpaths[i],oldpath,newpath);
if(rv == -1)
error = errno;
}
@@ -103,20 +104,21 @@ _link(const fs::find::Func 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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _link(*config.getattr,
*config.link,
return _link(config.getattr,
config.link,
config.srcmounts,
config.minfreespace,
from,
to);
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace link
namespace fuse
{
int
link(const char *from,
+24 -13
View File
@@ -37,6 +37,7 @@
#include "ugid.hpp"
#include "rwlock.hpp"
#include "xattr.hpp"
#include "buildvector.hpp"
using std::string;
using std::vector;
@@ -48,12 +49,19 @@ _listxattr_controlfile(char *list,
const size_t size)
{
string xattrs;
const vector<string> strs =
buildvector<string>
("user.mergerfs.srcmounts")
("user.mergerfs.minfreespace")
("user.mergerfs.policies")
("user.mergerfs.version");
xattrs.reserve(512);
xattrs.append("user.mergerfs.srcmounts",sizeof("user.mergerfs.srcmounts"));
for(int i = Category::Enum::BEGIN; i < Category::Enum::END; i++)
for(size_t i = 0; i < strs.size(); i++)
xattrs += (strs[i] + '\0');
for(size_t i = Category::Enum::BEGIN; i < Category::Enum::END; i++)
xattrs += ("user.mergerfs.category." + (std::string)*Category::categories[i] + '\0');
for(int i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
for(size_t i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
xattrs += ("user.mergerfs.func." + (std::string)*FuseFunc::fusefuncs[i] + '\0');
if(size == 0)
@@ -69,21 +77,24 @@ _listxattr_controlfile(char *list,
static
int
_listxattr(const fs::find::Func searchFunc,
_listxattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
char *list,
const size_t size)
{
#ifndef WITHOUT_XATTR
int rv;
fs::Paths path;
vector<string> path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1)
return -errno;
rv = ::llistxattr(path[0].full.c_str(),list,size);
fs::path::append(path[0],fusepath);
rv = ::llistxattr(path[0].c_str(),list,size);
return ((rv == -1) ? -errno : rv);
#else
@@ -93,25 +104,25 @@ _listxattr(const fs::find::Func 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);
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);
return _listxattr(*config.listxattr,
return _listxattr(config.listxattr,
config.srcmounts,
config.minfreespace,
fusepath,
list,
size);
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace listxattr
namespace fuse
{
int
listxattr(const char *fusepath,
+41 -41
View File
@@ -80,7 +80,7 @@ namespace local
getappname(const int argc,
char * const *argv)
{
return fs::basename(argv[0]);
return fs::path::basename(argv[0]);
}
static
@@ -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;
+22 -18
View File
@@ -38,12 +38,14 @@
using std::string;
using std::vector;
using mergerfs::Policy;
static
int
_mkdir(const fs::find::Func searchFunc,
const fs::find::Func createFunc,
_mkdir(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const mode_t mode)
{
@@ -51,31 +53,32 @@ _mkdir(const fs::find::Func searchFunc,
int error;
string dirname;
string fullpath;
fs::Paths createpaths;
fs::Paths existingpath;
vector<string> createpaths;
vector<string> existingpath;
dirname = fs::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,existingpath,1);
dirname = fs::path::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
if(rv == -1)
return -errno;
rv = createFunc(srcmounts,dirname,createpaths,-1);
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
{
if(i->base != existingpath[0].base)
string &createpath = createpaths[i];
if(createpath != existingpath[0])
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(existingpath[0].base,i->base,dirname);
fs::clonepath(existingpath[0],createpath,dirname);
}
fullpath = fs::make_path(i->base,fusepath);
fs::path::append(createpath,fusepath);
rv = ::mkdir(fullpath.c_str(),mode);
rv = ::mkdir(createpath.c_str(),mode);
if(rv == -1)
error = errno;
}
@@ -85,20 +88,21 @@ _mkdir(const fs::find::Func 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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _mkdir(*config.getattr,
*config.mkdir,
return _mkdir(config.getattr,
config.mkdir,
config.srcmounts,
config.minfreespace,
fusepath,
(mode & ~fc->umask));
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace mkdir
namespace fuse
{
int
mkdir(const char *fusepath,
+22 -19
View File
@@ -40,12 +40,14 @@
using std::string;
using std::vector;
using mergerfs::Policy;
static
int
_mknod(const fs::find::Func searchFunc,
const fs::find::Func createFunc,
_mknod(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const mode_t mode,
const dev_t dev)
@@ -53,32 +55,32 @@ _mknod(const fs::find::Func searchFunc,
int rv;
int error;
string dirname;
string fullpath;
fs::Paths createpaths;
fs::Paths existingpath;
vector<string> createpaths;
vector<string> existingpath;
dirname = fs::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,existingpath,1);
dirname = fs::path::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
if(rv == -1)
return -errno;
rv = createFunc(srcmounts,dirname,createpaths,-1);
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
{
if(i->base != existingpath[0].base)
string &createpath = createpaths[0];
if(createpath != existingpath[0])
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(existingpath[0].base,i->base,dirname);
fs::clonepath(existingpath[0],createpath,dirname);
}
fullpath = fs::make_path(i->base,fusepath);
fs::path::append(createpath,fusepath);
rv = ::mknod(fullpath.c_str(),mode,dev);
rv = ::mknod(createpath.c_str(),mode,dev);
if(rv == -1)
error = errno;
}
@@ -88,21 +90,22 @@ _mknod(const fs::find::Func 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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _mknod(*config.getattr,
*config.mknod,
return _mknod(config.getattr,
config.mknod,
config.srcmounts,
config.minfreespace,
fusepath,
(mode & ~fc->umask),
rdev);
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace mknod
namespace fuse
{
int
mknod(const char *fusepath,
+67
View File
@@ -0,0 +1,67 @@
/*
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 <string>
namespace num
{
int
to_size_t(const std::string &str,
size_t &value)
{
size_t tmp;
char *endptr;
tmp = strtoll(str.c_str(),&endptr,10);
switch(*endptr)
{
case 'k':
case 'K':
tmp *= 1024;
break;
case 'm':
case 'M':
tmp *= (1024 * 1024);
break;
case 'g':
case 'G':
tmp *= (1024 * 1024 * 1024);
break;
case '\0':
break;
default:
return -1;
}
value = tmp;
return 0;
}
}
+30
View File
@@ -0,0 +1,30 @@
/*
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 num
{
int to_size_t(const std::string &str, size_t &value);
}
+15 -10
View File
@@ -38,24 +38,28 @@
using std::string;
using std::vector;
using mergerfs::Policy;
static
int
_open(const fs::find::Func searchFunc,
_open(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const int flags,
uint64_t &fh)
{
int fd;
int rv;
fs::Paths path;
vector<string> path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1)
return -errno;
fd = ::open(path[0].full.c_str(),flags);
fs::path::append(path[0],fusepath);
fd = ::open(path[0].c_str(),flags);
if(fd == -1)
return -errno;
@@ -66,19 +70,20 @@ _open(const fs::find::Func searchFunc,
namespace mergerfs
{
namespace open
namespace fuse
{
int
open(const char *fusepath,
struct fuse_file_info *fileinfo)
open(const char *fusepath,
fuse_file_info *fileinfo)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _open(*config.open,
return _open(config.open,
config.srcmounts,
config.minfreespace,
fusepath,
fileinfo->flags,
fileinfo->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 *fileinfo);
}
}
+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);
}
}
+57 -36
View File
@@ -27,6 +27,7 @@
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
@@ -34,6 +35,7 @@
#include <iostream>
#include "str.hpp"
#include "num.hpp"
#include "config.hpp"
#include "policy.hpp"
@@ -43,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;
@@ -55,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)
{
@@ -68,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)
@@ -83,28 +85,42 @@ 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,"big_writes");
set_option(args,"splice_read");
set_option(args,"splice_write");
set_option(args,"splice_move");
// set_option(args,"big_writes");
// 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");
// set_option(args,"atomic_o_trunc");
}
static
int
parse_and_process_arg(config::Config &config,
parse_and_process_minfreespace(const std::string &value,
size_t &minfreespace)
{
int rv;
rv = num::to_size_t(value,minfreespace);
if(rv == -1)
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")
{
@@ -117,23 +133,26 @@ 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)
{
int rv;
int rv = -1;
std::vector<std::string> keypart;
str::split(keypart,key,'.');
if(keypart.size() != 2)
return 1;
if(keypart[0] == "func")
rv = config.set_func_policy(keypart[1],value);
else if(keypart[0] == "category")
rv = config.set_category_policy(keypart[1],value);
if(keypart.size() == 2)
{
if(keypart[0] == "func")
rv = config.set_func_policy(keypart[1],value);
else if(keypart[0] == "category")
rv = config.set_category_policy(keypart[1],value);
}
else
rv = -1;
{
if(key == "minfreespace")
rv = parse_and_process_minfreespace(value,config.minfreespace);
}
if(rv == -1)
rv = 1;
@@ -143,9 +162,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;
@@ -172,8 +191,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;
@@ -181,13 +200,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;
@@ -196,13 +217,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)
{
@@ -228,8 +249,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);
}
}
+55
View File
@@ -0,0 +1,55 @@
/*
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 __PATH_HPP__
#define __PATH_HPP__
#include <string>
#include <vector>
struct Path
{
Path() {}
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__ */
+25 -9
View File
@@ -28,7 +28,7 @@
#include "fs.hpp"
#include "buildvector.hpp"
#define POLICY(X) (Policy(Policy::Enum::X,#X,fs::find::X))
#define POLICY(X) (Policy(Policy::Enum::X,#X,Policy::Func::X))
namespace mergerfs
{
@@ -36,23 +36,39 @@ 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))
(POLICY(lfs))
(POLICY(mfs))
(POLICY(newest))
(POLICY(rand));
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::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)
+117 -16
View File
@@ -26,9 +26,12 @@
#define __POLICY_HPP__
#include <string>
#include <vector>
#include <map>
#include "path.hpp"
#include "fs.hpp"
#include "category.hpp"
namespace mergerfs
{
@@ -42,20 +45,110 @@ namespace mergerfs
invalid = -1,
BEGIN = 0,
all = BEGIN,
einval,
enosys,
enotsup,
epmfs,
erofs,
exdev,
ff,
ffwp,
fwfs,
lfs,
mfs,
newest,
rand,
END
};
static size_t begin() { return BEGIN; }
static size_t end() { return END; }
};
struct Func
{
typedef std::string string;
typedef std::size_t size_t;
typedef std::vector<string> strvec;
typedef const string cstring;
typedef const size_t csize_t;
typedef const strvec cstrvec;
typedef const Category::Enum::Type CType;
typedef int (*Ptr)(CType,cstrvec&,cstring&,csize_t,strvec&);
class Action
{
public:
Action(const Policy *p)
: func(p->_func)
{}
int
operator()(cstrvec& b,cstring& c,csize_t d,strvec& e)
{
return func(Category::Enum::action,b,c,d,e);
}
private:
const Ptr func;
};
class Create
{
public:
Create(const Policy *p)
: func(p->_func)
{}
int
operator()(cstrvec& b,cstring& c,csize_t d,strvec& e)
{
return func(Category::Enum::create,b,c,d,e);
}
private:
const Ptr func;
};
class Search
{
public:
Search(const Policy *p)
: func(p->_func)
{}
int
operator()(cstrvec& b,cstring& c,csize_t d,strvec& e)
{
return func(Category::Enum::search,b,c,d,e);
}
private:
const Ptr func;
};
static int all(CType,cstrvec&,cstring&,csize_t,strvec&);
static int einval(CType,cstrvec&,cstring&,csize_t,strvec&);
static int enosys(CType,cstrvec&,cstring&,csize_t,strvec&);
static int enotsup(CType,cstrvec&,cstring&,csize_t,strvec&);
static int epmfs(CType,cstrvec&,cstring&,csize_t,strvec&);
static int erofs(CType,cstrvec&,cstring&,csize_t,strvec&);
static int exdev(CType,cstrvec&,cstring&,csize_t,strvec&);
static int ff(CType,cstrvec&,cstring&,csize_t,strvec&);
static int ffwp(CType,cstrvec&,cstring&,csize_t,strvec&);
static int fwfs(CType,cstrvec&,cstring&,csize_t,strvec&);
static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&);
static int lfs(CType,cstrvec&,cstring&,csize_t,strvec&);
static int mfs(CType,cstrvec&,cstring&,csize_t,strvec&);
static int newest(CType,cstrvec&,cstring&,csize_t,strvec&);
static int rand(CType,cstrvec&,cstring&,csize_t,strvec&);
};
private:
Enum::Type _enum;
std::string _str;
fs::find::Func _func;
Enum::Type _enum;
std::string _str;
Func::Ptr _func;
public:
Policy()
@@ -65,9 +158,9 @@ namespace mergerfs
{
}
Policy(const Enum::Type enum_,
const std::string &str_,
const fs::find::Func func_)
Policy(const Enum::Type enum_,
const std::string &str_,
const Func::Ptr func_)
: _enum(enum_),
_str(str_),
_func(func_)
@@ -77,14 +170,14 @@ namespace mergerfs
public:
operator const Enum::Type() const { return _enum; }
operator const std::string&() const { return _str; }
operator const fs::find::Func() const { return _func; }
operator const Func::Ptr() const { return _func; }
operator const Policy*() const { return this; }
bool operator==(const Enum::Type enum_) const
{ return _enum == enum_; }
bool operator==(const std::string &str_) const
{ return _str == str_; }
bool operator==(const fs::find::Func func_) const
bool operator==(const Func::Ptr func_) const
{ return _func == func_; }
bool operator!=(const Policy &r) const
@@ -100,14 +193,22 @@ namespace mergerfs
public:
static const std::vector<Policy> _policies_;
static const Policy * const policies;
static const Policy &invalid;
static const Policy &all;
static const Policy &epmfs;
static const Policy &ff;
static const Policy &ffwp;
static const Policy &mfs;
static const Policy &newest;
static const Policy &rand;
static const Policy &invalid;
static const Policy &all;
static const Policy &einval;
static const Policy &enosys;
static const Policy &enotsup;
static const Policy &epmfs;
static const Policy &erofs;
static const Policy &exdev;
static const Policy &ff;
static const Policy &ffwp;
static const Policy &fwfs;
static const Policy &lfs;
static const Policy &mfs;
static const Policy &newest;
static const Policy &rand;
};
}
+93
View File
@@ -0,0 +1,93 @@
/*
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 <errno.h>
#include <string>
#include <vector>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
static
int
_all(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
int rv;
struct stat st;
string fullpath;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const string &basepath = basepaths[i];
fullpath = fs::path::make(basepath,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
paths.push_back(basepath);
}
if(paths.empty())
return (errno=ENOENT,-1);
return 0;
}
static
int
_all_create(const vector<string> &basepaths,
vector<string> &paths)
{
if(basepaths.empty())
return (errno=ENOENT,-1);
paths = basepaths;
return 0;
}
namespace mergerfs
{
int
Policy::Func::all(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _all_create(basepaths,paths);
return _all(basepaths,fusepath,paths);
}
}
+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::einval(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
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);
}
}
+143
View File
@@ -0,0 +1,143 @@
/*
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 <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <string>
#include <vector>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Policy;
using mergerfs::Category;
typedef struct statvfs statvfs_t;
static
inline
void
_calc_mfs(const statvfs_t &fsstats,
const string &basepath,
const size_t minfreespace,
fsblkcnt_t &mfs,
string &mfsbasepath)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > minfreespace) && (spaceavail > mfs))
{
mfs = spaceavail;
mfsbasepath = basepath;
}
}
static
int
_epmfs_create(const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
int rv;
fsblkcnt_t epmfs;
string epmfsbasepath;
string fullpath;
statvfs_t fsstats;
epmfs = 0;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const string &basepath = basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
_calc_mfs(fsstats,basepath,minfreespace,epmfs,epmfsbasepath);
}
if(epmfsbasepath.empty())
return Policy::Func::mfs(Category::Enum::create,basepaths,fusepath,minfreespace,paths);
paths.push_back(epmfsbasepath);
return 0;
}
static
int
_epmfs(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
int rv;
fsblkcnt_t epmfs;
string epmfsbasepath;
string fullpath;
statvfs_t fsstats;
epmfs = 0;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const string &basepath = basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
_calc_mfs(fsstats,basepath,0,epmfs,epmfsbasepath);
}
if(epmfsbasepath.empty())
return (errno=ENOENT,-1);
paths.push_back(epmfsbasepath);
return 0;
}
namespace mergerfs
{
int
Policy::Func::epmfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _epmfs_create(basepaths,fusepath,minfreespace,paths);
return _epmfs(basepaths,fusepath,paths);
}
}
+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);
}
}
+95
View File
@@ -0,0 +1,95 @@
/*
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 <errno.h>
#include <string>
#include <vector>
#include "path.hpp"
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
static
int
_ff(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct stat st;
string fullpath;
const string &basepath = basepaths[i];
fullpath = fs::path::make(basepath,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == -1)
continue;
paths.push_back(basepath);
return 0;
}
return (errno=ENOENT,-1);
}
static
int
_ff_create(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
if(basepaths.empty())
return (errno=ENOENT,-1);
paths.push_back(basepaths[0]);
return 0;
}
namespace mergerfs
{
int
Policy::Func::ff(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _ff_create(basepaths,fusepath,paths);
return _ff(basepaths,fusepath,paths);
}
}
+87
View File
@@ -0,0 +1,87 @@
/*
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 <errno.h>
#include <string>
#include <vector>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
static
int
_ffwp(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
string fallback;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct stat st;
string fullpath;
const string &basepath = basepaths[i];
fullpath = fs::path::make(basepath,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
{
paths.push_back(basepath);
return 0;
}
else if(errno == EACCES)
{
fallback = basepath;
}
}
if(fallback.empty())
return (errno=ENOENT,-1);
paths.push_back(fallback);
return 0;
}
namespace mergerfs
{
int
Policy::Func::ffwp(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
return _ffwp(basepaths,fusepath,paths);
}
}
+120
View File
@@ -0,0 +1,120 @@
/*
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/statvfs.h>
#include <errno.h>
#include <string>
#include <vector>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Policy;
using mergerfs::Category;
static
int
_fwfs_create(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
for(size_t i = 0, size = basepaths.size(); i != size; i++)
{
int rv;
struct statvfs fsstats;
const string &basepath = basepaths[i];
rv = ::statvfs(basepath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail < minfreespace)
continue;
paths.push_back(basepath);
return 0;
}
}
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
}
static
int
_fwfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
for(size_t i = 0, size = basepaths.size(); i != size; i++)
{
int rv;
string fullpath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
fullpath = fs::path::make(basepath,fusepath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail < minfreespace)
continue;
paths.push_back(basepath);
return 0;
}
}
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
}
namespace mergerfs
{
int
Policy::Func::fwfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _fwfs_create(type,basepaths,fusepath,minfreespace,paths);
return _fwfs(type,basepaths,fusepath,minfreespace,paths);
}
}
+47
View File
@@ -0,0 +1,47 @@
/*
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;
using std::size_t;
namespace mergerfs
{
int
Policy::Func::invalid(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &rv)
{
return (errno=EINVAL,-1);
}
}
+141
View File
@@ -0,0 +1,141 @@
/*
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 <sys/statvfs.h>
#include <unistd.h>
#include <errno.h>
#include <string>
#include <vector>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Policy;
using mergerfs::Category;
static
int
_lfs_create(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
fsblkcnt_t lfs;
string lfsstr;
lfs = -1;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct statvfs fsstats;
const string &basepath = basepaths[i];
rv = ::statvfs(basepath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > minfreespace) &&
(spaceavail < lfs))
{
lfs = spaceavail;
lfsstr = basepath;
}
}
}
if(lfsstr.empty())
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
paths.push_back(lfsstr);
return 0;
}
static
int
_lfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
fsblkcnt_t lfs;
string lfsstr;
lfs = -1;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
string fullpath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
fullpath = fs::path::make(basepath,fusepath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > minfreespace) &&
(spaceavail < lfs))
{
lfs = spaceavail;
lfsstr = basepath;
}
}
}
if(lfsstr.empty())
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
paths.push_back(lfsstr);
return 0;
}
namespace mergerfs
{
int
Policy::Func::lfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _lfs_create(type,basepaths,fusepath,minfreespace,paths);
return _lfs(type,basepaths,fusepath,minfreespace,paths);
}
}
+130
View File
@@ -0,0 +1,130 @@
/*
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/statvfs.h>
#include <errno.h>
#include <string>
#include <vector>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
static
int
_mfs_create(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
fsblkcnt_t mfs;
string mfsstr;
mfs = 0;
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)
{
mfs = spaceavail;
mfsstr = basepath;
}
}
}
if(mfsstr.empty())
return (errno=ENOENT,-1);
paths.push_back(mfsstr);
return 0;
}
static
int
_mfs(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
fsblkcnt_t mfs;
string mfsstr;
mfs = 0;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
string fullpath;
struct statvfs fsstats;
const string &basepath = basepaths[i];
fullpath = fs::path::make(basepath,fusepath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail > mfs)
{
mfs = spaceavail;
mfsstr = basepath;
}
}
}
if(mfsstr.empty())
return (errno=ENOENT,-1);
paths.push_back(mfsstr);
return 0;
}
namespace mergerfs
{
int
Policy::Func::mfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
if(type == Category::Enum::create)
return _mfs_create(basepaths,fusepath,paths);
return _mfs(basepaths,fusepath,paths);
}
}
+85
View File
@@ -0,0 +1,85 @@
/*
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 <errno.h>
#include <string>
#include <vector>
#include <limits>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
static
int
_newest(const vector<string> &basepaths,
const string &fusepath,
vector<string> &paths)
{
time_t newest = std::numeric_limits<time_t>::min();
string neweststr;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct stat st;
string fullpath;
const string &basepath = basepaths[i];
fullpath = fs::path::make(basepath,fusepath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0 && st.st_mtime >= newest)
{
newest = st.st_mtime;
neweststr = basepath;
}
}
if(neweststr.empty())
return (errno=ENOENT,-1);
paths.push_back(neweststr);
return 0;
}
namespace mergerfs
{
int
Policy::Func::newest(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
return _newest(basepaths,fusepath,paths);
}
}
+56
View File
@@ -0,0 +1,56 @@
/*
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 <algorithm>
#include "policy.hpp"
using std::string;
using std::vector;
using std::size_t;
namespace mergerfs
{
int
Policy::Func::rand(const Category::Enum::Type type,
const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
vector<string> &paths)
{
int rv;
rv = Policy::Func::all(type,basepaths,fusepath,minfreespace,paths);
if(rv == -1)
return -1;
std::random_shuffle(paths.begin(),paths.end());
return 0;
}
}
+6 -6
View File
@@ -46,14 +46,14 @@ _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,
buf,
+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);
}
}
+12 -12
View File
@@ -32,14 +32,14 @@
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,14 +56,14 @@ _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,
bufp,
+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);
}
}
+10 -39
View File
@@ -43,7 +43,6 @@ using std::string;
using std::vector;
using std::set;
using std::pair;
using mergerfs::readdir::FileData;
#define NO_OFFSET 0
@@ -57,15 +56,12 @@ _readdir(const vector<string> &srcmounts,
set<string> found;
struct stat st = {0};
for(vector<string>::const_iterator
iter = srcmounts.begin(), enditer = srcmounts.end();
iter != enditer;
++iter)
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
DIR *dh;
string basepath;
basepath = fs::make_path(*iter,dirname);
basepath = fs::path::make(srcmounts[i],dirname);
dh = ::opendir(basepath.c_str());
if(!dh)
continue;
@@ -89,44 +85,19 @@ _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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
+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);
}
}
+16 -12
View File
@@ -41,20 +41,23 @@ using mergerfs::Policy;
static
int
_readlink(const fs::find::Func searchFunc,
const vector<string> &srcmounts,
const string &fusepath,
char *buf,
const size_t size)
_readlink(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
char *buf,
const size_t size)
{
int rv;
fs::Paths path;
vector<string> path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1)
return -errno;
rv = ::readlink(path[0].full.c_str(),buf,size);
fs::path::append(path[0],fusepath);
rv = ::readlink(path[0].c_str(),buf,size);
if(rv == -1)
return -errno;
@@ -65,20 +68,21 @@ _readlink(const fs::find::Func 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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _readlink(*config.readlink,
return _readlink(config.readlink,
config.srcmounts,
config.minfreespace,
fusepath,
buf,
size);
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace readlink
namespace fuse
{
int
readlink(const char *fusepath,
+3 -3
View File
@@ -42,11 +42,11 @@ _release(uint64_t &fh)
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);
}
+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);
}
}
+16 -12
View File
@@ -38,28 +38,31 @@
using std::string;
using std::vector;
using mergerfs::Policy;
static
int
_removexattr(const fs::find::Func actionFunc,
_removexattr(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const char *attrname)
{
#ifndef WITHOUT_XATTR
int rv;
int error;
fs::Paths paths;
vector<string> paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = paths.begin(), ei = paths.end(); i != ei; ++i)
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
rv = ::lremovexattr(i->full.c_str(),attrname);
fs::path::append(paths[i],fusepath);
rv = ::lremovexattr(paths[i].c_str(),attrname);
if(rv == -1)
error = errno;
}
@@ -72,23 +75,24 @@ _removexattr(const fs::find::Func 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::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _removexattr(*config.removexattr,
return _removexattr(config.removexattr,
config.srcmounts,
config.minfreespace,
fusepath,
attrname);
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace removexattr
namespace fuse
{
int
removexattr(const char *fusepath,
+65 -41
View File
@@ -30,6 +30,7 @@
#include <string>
#include <vector>
#include <set>
#include "ugid.hpp"
#include "fs.hpp"
@@ -38,83 +39,106 @@
using std::string;
using std::vector;
using std::set;
using mergerfs::Policy;
static
int
_single_rename(const fs::find::Func searchFunc,
const vector<string> &srcmounts,
const fs::Path &oldpath,
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 fullnewpath = fs::make_path(oldpath.base,newpath);
string fullpath;
rv = ::rename(oldpath.full.c_str(),fullnewpath.c_str());
if(rv == -1 && errno == ENOENT)
for(set<string>::const_iterator i = tounlink.begin(), ei = tounlink.end(); i != ei; i++)
{
string dirname;
fs::Paths newpathdir;
fs::path::make(*i,newfusepath,fullpath);
dirname = fs::dirname(newpath);
rv = searchFunc(srcmounts,dirname,newpathdir,1);
if(rv == -1)
return -1;
{
const mergerfs::ugid::SetResetGuard ugid(0,0);
fs::clonepath(newpathdir[0].base,oldpath.base,dirname);
}
rv = ::rename(oldpath.full.c_str(),fullnewpath.c_str());
rv = ::unlink(fullpath.c_str());
if(rv == -1 && errno == EISDIR)
::rmdir(fullpath.c_str());
}
return rv;
}
static
int
_rename(const fs::find::Func searchFunc,
const fs::find::Func actionFunc,
const vector<string> &srcmounts,
const string &oldpath,
const string &newpath)
_rename(const vector<string> &srcmounts,
const vector<string> &basepaths,
const string &oldfusepath,
const string &newfusepath)
{
int rv;
int error;
fs::Paths oldpaths;
rv = actionFunc(srcmounts,oldpath,oldpaths,-1);
if(rv == -1)
return -errno;
string oldfullpath;
string newfullpath;
set<string> tounlink;
error = 0;
for(fs::Paths::const_iterator
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
tounlink.insert(srcmounts.begin(),srcmounts.end());
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
rv = _single_rename(searchFunc,srcmounts,*i,newpath);
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;
}
if(error == 0)
_unlink(tounlink,newfusepath);
return -error;
}
static
int
_rename(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &oldfusepath,
const string &newfusepath)
{
int rv;
vector<string> oldbasepaths;
if(_different_dirname(oldfusepath,newfusepath))
return -EXDEV;
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
if(rv == -1)
return -errno;
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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _rename(*config.getattr,
*config.rename,
return _rename(config.getattr,
config.rename,
config.srcmounts,
config.minfreespace,
oldpath,
newpath);
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace rename
namespace fuse
{
int
rename(const char *from,
+13 -10
View File
@@ -40,23 +40,25 @@ using mergerfs::Policy;
static
int
_rmdir(const fs::find::Func actionFunc,
_rmdir(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath)
{
int rv;
int error;
fs::Paths paths;
vector<string> paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = paths.begin(), ei = paths.end(); i != ei; ++i)
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
rv = ::rmdir(i->full.c_str());
fs::path::append(paths[i],fusepath);
rv = ::rmdir(paths[i].c_str());
if(rv == -1)
error = errno;
}
@@ -66,18 +68,19 @@ _rmdir(const fs::find::Func 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 fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readguard(&config.srcmountslock);
return _rmdir(*config.rmdir,
return _rmdir(config.rmdir,
config.srcmounts,
config.minfreespace,
fusepath);
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace rmdir
namespace fuse
{
int
rmdir(const char *fusepath);
+59 -33
View File
@@ -38,6 +38,7 @@
#include "rwlock.hpp"
#include "xattr.hpp"
#include "str.hpp"
#include "num.hpp"
using std::string;
using std::vector;
@@ -58,6 +59,7 @@ _add_srcmounts(vector<string> &srcmounts,
str::split(patterns,values,':');
fs::glob(patterns,additions);
fs::realpathize(additions);
if(!additions.empty())
{
@@ -105,6 +107,7 @@ _replace_srcmounts(vector<string> &srcmounts,
str::split(patterns,values,':');
fs::glob(patterns,newmounts);
fs::realpathize(newmounts);
{
const rwlock::WriteGuard wrg(&srcmountslock);
@@ -167,10 +170,28 @@ _setxattr_srcmounts(vector<string> &srcmounts,
static
int
_setxattr_controlfile_func_policy(config::Config &config,
const char *funcname,
const string &attrval,
const int flags)
_setxattr_minfreespace(Config &config,
const string &attrval,
const int flags)
{
int rv;
if((flags & XATTR_CREATE) == XATTR_CREATE)
return -EEXIST;
rv = num::to_size_t(attrval,config.minfreespace);
if(rv == -1)
return -EINVAL;
return 0;
}
static
int
_setxattr_controlfile_func_policy(Config &config,
const char *funcname,
const string &attrval,
const int flags)
{
int rv;
@@ -186,10 +207,10 @@ _setxattr_controlfile_func_policy(config::Config &config,
static
int
_setxattr_controlfile_category_policy(config::Config &config,
const char *categoryname,
const string &attrval,
const int flags)
_setxattr_controlfile_category_policy(Config &config,
const char *categoryname,
const string &attrval,
const int flags)
{
int rv;
@@ -205,10 +226,10 @@ _setxattr_controlfile_category_policy(config::Config &config,
static
int
_setxattr_controlfile(config::Config &config,
const char *attrname,
const string &attrval,
const int flags)
_setxattr_controlfile(Config &config,
const char *attrname,
const string &attrval,
const int flags)
{
const char *attrbasename = &attrname[sizeof("user.mergerfs.")-1];
@@ -224,6 +245,10 @@ _setxattr_controlfile(config::Config &config,
config.destmount,
attrval,
flags);
else if(!strcmp("minfreespace",attrbasename))
return _setxattr_minfreespace(config,
attrval,
flags);
else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
return _setxattr_controlfile_category_policy(config,
&attrbasename[sizeof("category.")-1],
@@ -240,8 +265,9 @@ _setxattr_controlfile(config::Config &config,
static
int
_setxattr(const fs::find::Func actionFunc,
_setxattr(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const char *attrname,
const char *attrval,
@@ -251,17 +277,18 @@ _setxattr(const fs::find::Func actionFunc,
#ifndef WITHOUT_XATTR
int rv;
int error;
fs::Paths paths;
vector<string> paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = paths.begin(), ei = paths.end(); i != ei; ++i)
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
rv = ::lsetxattr(i->full.c_str(),attrname,attrval,attrvalsize,flags);
fs::path::append(paths[i],fusepath);
rv = ::lsetxattr(paths[i].c_str(),attrname,attrval,attrvalsize,flags);
if(rv == -1)
error = errno;
}
@@ -273,7 +300,7 @@ _setxattr(const fs::find::Func actionFunc,
}
namespace mergerfs
{
namespace setxattr
namespace fuse
{
int
setxattr(const char *fusepath,
@@ -282,32 +309,31 @@ namespace mergerfs
size_t attrvalsize,
int flags)
{
const config::Config &config = config::get();
const struct fuse_context *fc = fuse_get_context();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
if(fusepath == config.controlfile)
{
if((fc->uid != ::getuid()) && (fc->gid != ::getgid()))
return -EPERM;
return _setxattr_controlfile(config::get_writable(),
return _setxattr_controlfile(Config::get_writable(),
attrname,
string(attrval,attrvalsize),
flags);
}
{
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _setxattr(*config.setxattr,
config.srcmounts,
fusepath,
attrname,
attrval,
attrvalsize,
flags);
}
return _setxattr(config.setxattr,
config.srcmounts,
config.minfreespace,
fusepath,
attrname,
attrval,
attrvalsize,
flags);
}
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace setxattr
namespace fuse
{
int
setxattr(const char *fusepath,
+5 -5
View File
@@ -82,11 +82,11 @@ _statfs(const vector<string> &srcmounts,
vector<string>::const_iterator iter;
vector<string>::const_iterator enditer;
for(iter = srcmounts.begin(), enditer = srcmounts.end(); iter != enditer; ++iter)
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
int rv;
struct statvfs fsstat;
rv = ::statvfs(iter->c_str(),&fsstat);
rv = ::statvfs(srcmounts[i].c_str(),&fsstat);
if(rv != 0)
continue;
@@ -118,14 +118,14 @@ _statfs(const vector<string> &srcmounts,
namespace mergerfs
{
namespace statfs
namespace fuse
{
int
statfs(const char *fusepath,
struct statvfs *stat)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace statfs
namespace fuse
{
int
statfs(const char *fusepath,
+8
View File
@@ -139,4 +139,12 @@ namespace str
++si;
}
}
bool
isprefix(const string &s0,
const string &s1)
{
return ((s0.size() >= s1.size()) &&
(s0.compare(0,s1.size(),s1) == 0));
}
}
+4
View File
@@ -54,4 +54,8 @@ namespace str
void
erase_fnmatches(const std::vector<std::string> &pattern,
std::vector<std::string> &strs);
bool
isprefix(const std::string &s0,
const std::string &s1);
}
+14 -12
View File
@@ -36,31 +36,32 @@
using std::string;
using std::vector;
using mergerfs::Policy;
static
int
_symlink(const fs::find::Func createFunc,
_symlink(Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &oldpath,
const string &newpath)
{
int rv;
int error;
string newpathdir;
fs::Paths newpathdirs;
vector<string> newpathdirs;
newpathdir = fs::dirname(newpath);
rv = createFunc(srcmounts,newpathdir,newpathdirs,-1);
newpathdir = fs::path::dirname(newpath);
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::iterator
i = newpathdirs.begin(), ei = newpathdirs.end(); i != ei; ++i)
for(size_t i = 0, ei = newpathdirs.size(); i != ei; i++)
{
i->full = fs::make_path(i->base,newpath);
fs::path::append(newpathdirs[i],newpath);
rv = symlink(oldpath.c_str(),i->full.c_str());
rv = symlink(oldpath.c_str(),newpathdirs[i].c_str());
if(rv == -1)
error = errno;
}
@@ -70,19 +71,20 @@ _symlink(const fs::find::Func createFunc,
namespace mergerfs
{
namespace symlink
namespace fuse
{
int
symlink(const char *oldpath,
const char *newpath)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _symlink(*config.symlink,
return _symlink(config.symlink,
config.srcmounts,
config.minfreespace,
oldpath,
newpath);
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace mergerfs
{
namespace symlink
namespace fuse
{
int
symlink(const char *oldpath,
+14 -10
View File
@@ -38,27 +38,30 @@
using std::string;
using std::vector;
using mergerfs::Policy;
static
int
_truncate(const fs::find::Func actionFunc,
_truncate(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath,
const off_t size)
{
int rv;
int error;
fs::Paths paths;
vector<string> paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1)
return -errno;
error = 0;
for(fs::Paths::const_iterator
i = paths.begin(), ei = paths.end(); i != ei; ++i)
for(size_t i = 0, ei = paths.size(); i != ei; i++)
{
rv = ::truncate(i->full.c_str(),size);
fs::path::append(paths[i],fusepath);
rv = ::truncate(paths[i].c_str(),size);
if(rv == -1)
error = errno;
}
@@ -68,19 +71,20 @@ _truncate(const fs::find::Func actionFunc,
namespace mergerfs
{
namespace truncate
namespace fuse
{
int
truncate(const char *fusepath,
off_t size)
{
const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get();
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock);
return _truncate(*config.truncate,
return _truncate(config.truncate,
config.srcmounts,
config.minfreespace,
fusepath,
size);
}
+1 -1
View File
@@ -26,7 +26,7 @@
namespace mergerfs
{
namespace truncate
namespace fuse
{
int
truncate(const char *fusepath,
+1 -2
View File
@@ -34,8 +34,7 @@ namespace mergerfs
SetResetGuard(const uid_t _newuid,
const gid_t _newgid)
{
olduid = ::geteuid();
oldgid = ::getegid();
pthread_getugid_np(&olduid,&oldgid);
newuid = _newuid;
newgid = _newgid;

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