mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-20 00:17:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
606d9c4d3f | ||
|
|
c46134c03a | ||
|
|
0abb2a960c | ||
|
|
3631ab7df2 | ||
|
|
b8b3ab06a7 | ||
|
|
680f8194f9 | ||
|
|
3d33428a4e | ||
|
|
7524e57262 | ||
|
|
1195e66a8a | ||
|
|
b55ebba4ed | ||
|
|
8dd0dc11ee | ||
|
|
8eacb008b3 | ||
|
|
9c16ab6999 | ||
|
|
9e0ab1f518 | ||
|
|
47bf58eae9 | ||
|
|
8a48b74cb4 | ||
|
|
570c93ec2c | ||
|
|
85026d5780 | ||
|
|
bb2e6eb605 | ||
|
|
1885a82cce | ||
|
|
602a37b231 | ||
|
|
65f482e483 | ||
|
|
6ee44e451c | ||
|
|
8d1a1564bf | ||
|
|
4af9248eba | ||
|
|
93f7d7d927 | ||
|
|
19a7d43b31 | ||
|
|
9afefef032 | ||
|
|
8c3462caf2 | ||
|
|
340f3c85c9 | ||
|
|
ff04098319 | ||
|
|
f8563369bc | ||
|
|
4152769182 | ||
|
|
057eafef7f | ||
|
|
c7e93720ff | ||
|
|
587ab62583 | ||
|
|
a894360402 | ||
|
|
756d4ff0ff | ||
|
|
ec6adaa376 | ||
|
|
dee2c3e23b | ||
|
|
fc52f89ddc | ||
|
|
fdbafa63ba | ||
|
|
e987ff46c2 | ||
|
|
b1ecc58114 | ||
|
|
39d5ab8e83 | ||
|
|
4b1f9afe1e | ||
|
|
c005463111 | ||
|
|
50384f4e86 | ||
|
|
73e8867400 | ||
|
|
0545da67ff | ||
|
|
24e690b995 | ||
|
|
89200a0ab8 | ||
|
|
e521833cec | ||
|
|
737d941941 | ||
|
|
9830e29945 | ||
|
|
6418b00ac3 | ||
|
|
cfe9c28a10 | ||
|
|
aa6e4c1865 | ||
|
|
f48c16d162 | ||
|
|
62ae871d51 | ||
|
|
906702de77 | ||
|
|
db27a91a58 | ||
|
|
b4a003c5a8 | ||
|
|
b48054fa2c | ||
|
|
d8f05ac8ae | ||
|
|
8843ace757 | ||
|
|
7d93d5917e | ||
|
|
8846a135bc | ||
|
|
7207e7fdd6 | ||
|
|
a8e6128034 | ||
|
|
f72bb1e1ed | ||
|
|
cf5d28ea4a | ||
|
|
bd14f33c31 | ||
|
|
73561c1861 | ||
|
|
43d50ca471 |
@@ -0,0 +1,34 @@
|
||||
General description
|
||||
===================
|
||||
|
||||
|
||||
|
||||
Expected behavior
|
||||
=================
|
||||
|
||||
|
||||
|
||||
Actual behavior
|
||||
===============
|
||||
|
||||
|
||||
|
||||
**Precise** steps to reproduce the behavior
|
||||
===========================================
|
||||
|
||||
> Explicitly list **all** steps to reproduce. Preferably create a minimal example of the problem using standard command line tools. The more variables (apps, settings, etc.) that are involved the more difficult it is to debug. Also, **please** be sure to have read all of the README. It contains a lot of information regarding known system and user issues.
|
||||
|
||||
|
||||
|
||||
System information
|
||||
==================
|
||||
Please provide as much of the following information as possible:
|
||||
|
||||
* [ ] mergerfs version: `mergerfs -V`
|
||||
* [ ] mergerfs settings: `cat /etc/fstab` or the command line arguments
|
||||
* [ ] Linux version: `uname -a`
|
||||
* [ ] Versions of any additional software being used
|
||||
* [ ] List of drives, filesystems, & sizes: `df -h`
|
||||
* [ ] strace of application having problem: `strace -f -o /tmp/app.strace.txt <cmd>` or `strace -f -p <appPID> -o /tmp/app.strace.txt`
|
||||
* [ ] strace of mergerfs while app tried to do it's thing: `strace -f -p <mergerfsPID> -o /tmp/mergerfs.strace.txt`
|
||||
|
||||
@@ -18,13 +18,6 @@ matrix:
|
||||
dist: trusty
|
||||
compiler: clang
|
||||
sudo: required
|
||||
- os: osx
|
||||
compiler: clang
|
||||
|
||||
before_script:
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew tap caskroom/cask; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew cask install osxfuse; fi
|
||||
|
||||
script:
|
||||
- sudo -E make install-build-pkgs
|
||||
|
||||
@@ -28,6 +28,7 @@ SED = $(shell which sed)
|
||||
GZIP = $(shell which gzip)
|
||||
RPMBUILD = $(shell which rpmbuild)
|
||||
GIT2DEBCL = ./tools/git2debcl
|
||||
PKGCONFIG = pkg-config
|
||||
|
||||
GIT_REPO = 0
|
||||
ifneq ($(GIT),)
|
||||
@@ -40,7 +41,23 @@ ifeq ($(PANDOC),)
|
||||
$(warning "pandoc does not appear available: manpage won't be buildable")
|
||||
endif
|
||||
|
||||
XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
|
||||
USE_XATTR = 1
|
||||
|
||||
INTERNAL_FUSE = 1
|
||||
EXTERNAL_FUSE_MIN_REQ = 2.9.7
|
||||
|
||||
ifeq ($(INTERNAL_FUSE),1)
|
||||
FUSE_CFLAGS = -D_FILE_OFFSET_BITS=64 -Ilibfuse/include
|
||||
FUSE_LIBS = libfuse/lib/.libs/libfuse.a
|
||||
FUSE_TARGET = $(FUSE_LIBS)
|
||||
else
|
||||
FUSE_CFLAGS := $(shell $(PKGCONFIG) --cflags 'fuse >= $(EXTERNAL_FUSE_MIN_REQ)')
|
||||
FUSE_LIBS := $(shell $(PKGCONFIG) --libs 'fuse >= $(EXTERNAL_FUSE_MIN_REQ)')
|
||||
FUSE_TARGET :=
|
||||
ifeq ($(FUSE_CFLAGS)$(FUSE_LIBS),)
|
||||
$(error "Use of external FUSE requested, but no libfuse >= $(EXTERNAL_FUSE_MIN_REQ) found.")
|
||||
endif
|
||||
endif
|
||||
|
||||
UGID_USE_RWLOCK = 0
|
||||
|
||||
@@ -50,15 +67,14 @@ OBJ = $(SRC:src/%.cpp=obj/%.o)
|
||||
DEPS = $(OBJ:obj/%.o=obj/%.d)
|
||||
TARGET = mergerfs
|
||||
MANPAGE = $(TARGET).1
|
||||
FUSE_CFLAGS = -D_FILE_OFFSET_BITS=64 -Ilibfuse/include
|
||||
CFLAGS = -g -Wall \
|
||||
$(OPTS) \
|
||||
-Wno-unused-result \
|
||||
$(FUSE_CFLAGS) \
|
||||
-DFUSE_USE_VERSION=29 \
|
||||
-MMD \
|
||||
-DUSE_XATTR=$(USE_XATTR) \
|
||||
-DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
|
||||
LDFLAGS = -pthread -lrt
|
||||
|
||||
PREFIX = /usr/local
|
||||
EXEC_PREFIX = $(PREFIX)
|
||||
@@ -73,20 +89,15 @@ INSTALLBINDIR = $(DESTDIR)$(BINDIR)
|
||||
INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
|
||||
INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
|
||||
|
||||
ifeq ($(XATTR_AVAILABLE),0)
|
||||
$(warning "xattr not available: disabling")
|
||||
CFLAGS += -DWITHOUT_XATTR
|
||||
endif
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
help:
|
||||
@echo "usage: make"
|
||||
@echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
|
||||
@echo "make USE_XATTR=0 - build program without xattrs functionality"
|
||||
@echo "make INTERNAL_FUSE=0 - to build program with external (system) libfuse rather than the bundled one ('-o threads=' option will be unavailable)"
|
||||
|
||||
$(TARGET): src/version.hpp obj/obj-stamp libfuse/lib/.libs/libfuse.a $(OBJ)
|
||||
cd libfuse && make
|
||||
$(CXX) $(CFLAGS) $(OBJ) -o $@ libfuse/lib/.libs/libfuse.a -ldl $(LDFLAGS)
|
||||
$(TARGET): version obj/obj-stamp $(FUSE_TARGET) $(OBJ)
|
||||
$(CXX) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@ $(FUSE_LIBS) -ldl -pthread -lrt
|
||||
|
||||
mount.mergerfs: $(TARGET)
|
||||
$(LN) -fs "$<" "$@"
|
||||
@@ -102,15 +113,7 @@ ifeq ($(GIT_REPO),1)
|
||||
endif
|
||||
|
||||
version:
|
||||
ifeq ($(GIT_REPO),1)
|
||||
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
|
||||
@echo "$(VERSION)" > VERSION
|
||||
endif
|
||||
|
||||
src/version.hpp: version
|
||||
$(eval VERSION := $(shell cat VERSION))
|
||||
@echo "#pragma once" > src/version.hpp
|
||||
@echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
|
||||
tools/update-version
|
||||
|
||||
obj/obj-stamp:
|
||||
$(MKDIR) -p obj
|
||||
@@ -124,10 +127,14 @@ clean: rpm-clean libfuse_Makefile
|
||||
$(RM) -rf obj
|
||||
$(RM) -f "$(TARGET)" mount.mergerfs
|
||||
$(FIND) . -name "*~" -delete
|
||||
ifeq ($(INTERNAL_FUSE),1)
|
||||
cd libfuse && $(MAKE) clean
|
||||
endif
|
||||
|
||||
distclean: clean libfuse_Makefile
|
||||
ifeq ($(INTERNAL_FUSE),1)
|
||||
cd libfuse && $(MAKE) distclean
|
||||
endif
|
||||
ifeq ($(GIT_REPO),1)
|
||||
$(GIT) clean -fd
|
||||
endif
|
||||
@@ -207,28 +214,30 @@ install-build-pkgs:
|
||||
ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0)
|
||||
apt-get -qy update
|
||||
apt-get -qy --no-install-suggests --no-install-recommends --force-yes \
|
||||
install build-essential git g++ debhelper libattr1-dev python automake libtool lsb-release
|
||||
install build-essential git g++ debhelper python automake libtool lsb-release
|
||||
else ifeq ($(shell test -e /usr/bin/dnf; echo $$?),0)
|
||||
dnf -y update
|
||||
dnf -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
|
||||
dnf -y install git rpm-build gcc-c++ make which python automake libtool gettext-devel
|
||||
else ifeq ($(shell test -e /usr/bin/yum; echo $$?),0)
|
||||
yum -y update
|
||||
yum -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
|
||||
yum -y install git rpm-build gcc-c++ make which python automake libtool gettext-devel
|
||||
endif
|
||||
|
||||
unexport CFLAGS LDFLAGS
|
||||
unexport CFLAGS
|
||||
.PHONY: libfuse_Makefile
|
||||
libfuse_Makefile:
|
||||
ifeq ($(INTERNAL_FUSE),1)
|
||||
ifeq ($(shell test -e libfuse/Makefile; echo $$?),1)
|
||||
cd libfuse && \
|
||||
$(MKDIR) -p m4 && \
|
||||
autoreconf --force --install && \
|
||||
./configure --enable-lib --disable-util --disable-example
|
||||
endif
|
||||
endif
|
||||
|
||||
libfuse/lib/.libs/libfuse.a: libfuse_Makefile
|
||||
cd libfuse && $(MAKE)
|
||||
|
||||
.PHONY: all clean install help
|
||||
.PHONY: all clean install help version
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
% mergerfs(1) mergerfs user manual
|
||||
% Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
% 2017-05-26
|
||||
% 2018-10-31
|
||||
|
||||
# NAME
|
||||
|
||||
@@ -8,7 +8,7 @@ mergerfs - a featureful union filesystem
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
mergerfs -o<options> <srcmounts> <mountpoint>
|
||||
mergerfs -o<options> <branches> <mountpoint>
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
@@ -28,32 +28,68 @@ mergerfs -o<options> <srcmounts> <mountpoint>
|
||||
* Handles pool of readonly and read/write drives
|
||||
* Turn read-only files into symlinks to increase read performance
|
||||
|
||||
# How it works
|
||||
|
||||
mergerfs logically merges multiple paths together. Think a union of sets. The file/s or directory/s acted on or presented through mergerfs are based on the policy chosen for that particular action. Read more about policies below.
|
||||
|
||||
```
|
||||
A + B = C
|
||||
/disk1 /disk2 /merged
|
||||
| | |
|
||||
+-- /dir1 +-- /dir1 +-- /dir1
|
||||
| | | | | |
|
||||
| +-- file1 | +-- file2 | +-- file1
|
||||
| | +-- file3 | +-- file2
|
||||
+-- /dir2 | | +-- file3
|
||||
| | +-- /dir3 |
|
||||
| +-- file4 | +-- /dir2
|
||||
| +-- file5 | |
|
||||
+-- file6 | +-- file4
|
||||
|
|
||||
+-- /dir3
|
||||
| |
|
||||
| +-- file5
|
||||
|
|
||||
+-- file6
|
||||
```
|
||||
|
||||
mergerfs does **not** support the copy-on-write (CoW) behavior found in **aufs** and **overlayfs**. You can **not** mount a read-only filesystem and write to it. However, mergerfs will ignore read-only drives when creating new files so you can mix rw and ro drives.
|
||||
|
||||
# OPTIONS
|
||||
|
||||
### mount options
|
||||
|
||||
* **defaults**: a shortcut for FUSE's **atomic_o_trunc**, **auto_cache**, **big_writes**, **default_permissions**, **splice_move**, **splice_read**, and **splice_write**. These options seem to provide the best performance.
|
||||
* **direct_io**: causes FUSE to bypass caching which can increase write speeds at the detriment of reads. Note that not enabling `direct_io` will cause double caching of files and therefore less memory for caching generally. However, `mmap` does not work when `direct_io` is enabled.
|
||||
* **allow_other**: a libfuse option which allows users besides the one which ran mergerfs to see the filesystem. This is required for most use-cases.
|
||||
* **direct_io**: causes FUSE to bypass caching which can increase write speeds at the detriment of reads. Note that not enabling `direct_io` will cause double caching of files and therefore less memory for caching generally (enable **dropcacheonclose** to help with this problem). However, `mmap` does not work when `direct_io` is enabled.
|
||||
* **minfreespace=value**: the minimum space value used for creation policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively. (default: 4G)
|
||||
* **moveonenospc=true|false**: when enabled (set to **true**) if a **write** fails with **ENOSPC** or **EDQUOT** a scan of all drives will be done looking for the drive with most free space which is at least the size of the file plus the amount which failed to write. An attempt to move the file to that drive will occur (keeping all metadata possible) and if successful the original is unlinked and the write retried. (default: false)
|
||||
* **moveonenospc=true|false**: when enabled (set to **true**) if a **write** fails with **ENOSPC** or **EDQUOT** a scan of all drives will be done looking for the drive with the most free space which is at least the size of the file plus the amount which failed to write. An attempt to move the file to that drive will occur (keeping all metadata possible) and if successful the original is unlinked and the write retried. (default: false)
|
||||
* **use_ino**: causes mergerfs to supply file/directory inodes rather than libfuse. While not a default it is generally recommended it be enabled so that hard linked files share the same inode value.
|
||||
* **hard_remove**: force libfuse to immedately remove files when unlinked. This will keep the `.fuse_hidden` files from showing up but if software uses an opened but unlinked file in certain ways it could result in errors.
|
||||
* **dropcacheonclose=true|false**: when a file is requested to be closed call `posix_fadvise` on it first to instruct the kernel that we no longer need the data and it can drop its cache. Recommended when **direct_io** is not enabled to limit double caching. (default: false)
|
||||
* **symlinkify=true|false**: when enabled (set to **true**) and a file is not writable and its mtime or ctime is older than **symlinkify_timeout** files will be reported as symlinks to the original files. Please read more below before using. (default: false)
|
||||
* **symlinkify_timeout=value**: time to wait, in seconds, to activate the **symlinkify** behavior. (default: 3600)
|
||||
* **nullrw=true|false**: turns reads and writes into no-ops. The request will succeed but do nothing. Useful for benchmarking mergerfs. (default: false)
|
||||
* **ignorepponrename=true|false**: ignore path preserving on rename. Typically rename and link act differently depending on the policy of `create` (read below). Enabling this will cause rename and link to always use the non-path preserving behavior. This means files, when renamed or linked, will stay on the same drive. (default: false)
|
||||
* **threads=num**: number of threads to use in multithreaded mode. When set to zero (the default) it will attempt to discover and use the number of logical cores. If the lookup fails it will fall back to using 4. If the thread count is set negative it will look up the number of cores then divide by the absolute value. ie. threads=-2 on an 8 core machine will result in 8 / 2 = 4 threads. There will always be at least 1 thread. NOTE: higher number of threads increases parallelism but usually decreases throughput. (default: number of cores)
|
||||
* **security_capability=true|false**: If false return ENOATTR when xattr security.capability is queried. (default: true)
|
||||
* **xattr=passthrough|noattr|notsup**: Runtime control of xattrs. Default is to passthrough xattr requests. 'noattr' will short circuit as if nothing exists. 'notsup' will respond with ENOTSUP as if xattrs are not supported or disabled. (default: passthrough)
|
||||
* **link_cow=true|false**: When enabled if a regular file is opened which has a link count > 1 it will copy the file to a temporary file and rename over the original. Breaking the link and providing a basic copy-on-write function similar to cow-shell. (default: false)
|
||||
* **statfs=base|full**: Controls how statfs works. 'base' means it will always use all branches in statfs calculations. 'full' is in effect path preserving and only includes drives where the path exists. (default: base)
|
||||
* **statfs_ignore=none|ro|nc**: 'ro' will cause statfs calculations to ignore available space for branches mounted or tagged as 'read only' or 'no create'. 'nc' will ignore available space for branches tagged as 'no create'. (default: none)
|
||||
* **threads=num**: number of threads to use in multithreaded mode. When set to zero (the default) it will attempt to discover and use the number of logical cores. If the lookup fails it will fall back to using 4. If the thread count is set negative it will look up the number of cores then divide by the absolute value. ie. threads=-2 on an 8 core machine will result in 8 / 2 = 4 threads. There will always be at least 1 thread. NOTE: higher number of threads increases parallelism but usually decreases throughput. (default: number of cores) *NOTE2:* the option is unavailable when built with system libfuse.
|
||||
* **fsname=name**: sets the name of the filesystem as seen in **mount**, **df**, etc. Defaults to a list of the source paths concatenated together with the longest common prefix removed.
|
||||
* **func.<func>=<policy>**: sets the specific FUSE function's policy. See below for the list of value types. Example: **func.getattr=newest**
|
||||
* **category.<category>=<policy>**: Sets policy of all FUSE functions in the provided category. Example: **category.create=mfs**
|
||||
|
||||
**NOTE:** Options are evaluated in the order listed so if the options are **func.rmdir=rand,category.action=ff** the **action** category setting will override the **rmdir** setting.
|
||||
|
||||
### srcmounts
|
||||
### branches
|
||||
|
||||
The srcmounts (source mounts) argument is a colon (':') delimited list of paths to be included in the pool. It does not matter if the paths are on the same or different drives nor does it matter the filesystem. Used and available space will not be duplicated for paths on the same device and any features which aren't supported by the underlying filesystem (such as file attributes or extended attributes) will return the appropriate errors.
|
||||
The 'branches' (formerly 'srcmounts') argument is a colon (':') delimited list of paths to be pooled together. It does not matter if the paths are on the same or different drives nor does it matter the filesystem. Used and available space will not be duplicated for paths on the same device and any features which aren't supported by the underlying filesystem (such as file attributes or extended attributes) will return the appropriate errors.
|
||||
|
||||
To make it easier to include multiple source mounts mergerfs supports [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will expand it.**
|
||||
To make it easier to include multiple branches mergerfs supports [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will apply the glob itself.**
|
||||
|
||||
Each branch can have a suffix of `=RW` (read / write), `=RO` (read only), or `=NC` (no create). These suffixes work with globs as well and will apply to each path found. `RW` is the default behavior and those paths will be eligible for all policy categories. `RO` will exclude those paths from `create` and `action` policies (just as a filesystem being mounted `ro` would). `NC` will exclude those paths from `create` policies (you can't create but you can change / delete).
|
||||
|
||||
```
|
||||
$ mergerfs -o defaults,allow_other,use_ino /mnt/disk\*:/mnt/cdrom /media/drives
|
||||
@@ -64,8 +100,8 @@ The above line will use all mount points in /mnt prefixed with **disk** and the
|
||||
To have the pool mounted at boot or otherwise accessable from related tools use **/etc/fstab**.
|
||||
|
||||
```
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other,use_ino 0 0
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other,use_ino 0 0
|
||||
```
|
||||
|
||||
**NOTE:** the globbing is done at mount or xattr update time (see below). If a new directory is added matching the glob after the fact it will not be automatically included.
|
||||
@@ -111,12 +147,22 @@ $ dd if=/path/to/mergerfs/mount/benchmark of=/dev/null bs=1M count=1024
|
||||
|
||||
It's important to test with different `obs` (output block size) values since the relative overhead is greater with smaller values. As you can see above the size of a read or write can massively impact theoretical performance. If an application performs much worse through mergerfs it could very well be that it doesn't optimally size its read and write requests.
|
||||
|
||||
### xattr
|
||||
|
||||
Runtime extended attribute support can be managed via the `xattr` option. By default it will passthrough any xattr calls. Given xattr support is rarely used and can have significant performance implications mergerfs allows it to be disabled at runtime.
|
||||
|
||||
`noattr` will cause mergerfs to short circuit all xattr calls and return ENOATTR where appropriate. mergerfs still gets all the requests but they will not be forwarded on to the underlying filesystems. The runtime control will still function in this mode.
|
||||
|
||||
`notsup` will cause mergerfs to return ENOTSUP for any xattr call. The difference with `noattr` is that the kernel will cache this fact and itself short circuit future calls. This will be more efficient than `noattr` but will cause mergerfs' runtime control via the hidden file to stop working.
|
||||
|
||||
# FUNCTIONS / POLICIES / CATEGORIES
|
||||
|
||||
The POSIX filesystem API has a number of functions. **creat**, **stat**, **chown**, etc. In mergerfs these functions are grouped into 3 categories: **action**, **create**, and **search**. Functions and categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a function or category though some may not be very useful in practice. For instance: **rand** (random) may be useful for file creation (create) but could lead to very odd behavior if used for `chmod` (though only if there were more than one copy of the file).
|
||||
|
||||
Policies, when called to create, will ignore drives which are readonly. This allows for readonly and read/write drives to be mixed together. Note that the drive must be explicitly mounted with the **ro** mount option for this to work.
|
||||
|
||||
When using policies which are based on a device's available space the base path provided is used. Not the full path to the file in question. Meaning that sub mounts won't be considered in the space calculations. The reason is that it doesn't really work for non-path preserving policies and can lead to non-obvious behaviors.
|
||||
|
||||
#### Function / Category classifications
|
||||
|
||||
| Category | FUSE Functions |
|
||||
@@ -134,34 +180,38 @@ Policies, as described below, are of two core types. `path preserving` and `non-
|
||||
|
||||
All policies which start with `ep` (**epff**, **eplfs**, **eplus**, **epmfs**, **eprand**) are `path preserving`. `ep` stands for `existing path`.
|
||||
|
||||
As the descriptions explain a path preserving policy will only consider drives where the relative path being accessed already exists.
|
||||
A path preserving policy will only consider drives where the relative path being accessed already exists.
|
||||
|
||||
When using non-path preserving policies where something is created paths will be copied to target drives as necessary.
|
||||
When using non-path preserving policies paths will be cloned to target drives as necessary.
|
||||
|
||||
#### Policy descriptions
|
||||
|
||||
All **create** policies will filter out branches which are mounted **read only** or tagged as **read only** or **no create**. All **action** policies will filter out branches which are mounted or tagged as **read only**.
|
||||
|
||||
If all branches are filtered an error will be returned. Typically EROFS or ENOSPC.
|
||||
|
||||
| Policy | Description |
|
||||
|------------------|------------------------------------------------------------|
|
||||
| all | Search category: acts like **ff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **ff**. It will exclude readonly drives and those with free space less than **minfreespace**. |
|
||||
| epall (existing path, all) | Search category: acts like **epff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all existing paths found. **create** works like **epff**. Excludes readonly drives and those with free space less than **minfreespace**. |
|
||||
| epff (existing path, first found) | Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found where the relative path already exists. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). Falls back to **ff**. |
|
||||
| eplfs (existing path, least free space) | Of all the drives on which the relative path exists choose the drive with the least free space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lfs**. |
|
||||
| eplus (existing path, least used space) | Of all the drives on which the relative path exists choose the drive with the least used space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lus**. |
|
||||
| epmfs (existing path, most free space) | Of all the drives on which the relative path exists choose the drive with the most free space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
|
||||
| all | Search category: acts like **ff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all branches. **create** works like **ff**. It will exclude branches with free space less than **minfreespace**. |
|
||||
| epall (existing path, all) | Search category: acts like **epff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all existing paths found. **create** works like **epff**. Excludes branches with free space less than **minfreespace**. |
|
||||
| epff (existing path, first found) | Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found where the relative path already exists. For **create** category functions it will exclude branches with free space less than **minfreespace**. |
|
||||
| eplfs (existing path, least free space) | Of all the drives on which the relative path exists choose the drive with the least free space. For **create** category functions it will exclude those with free space less than **minfreespace**. |
|
||||
| eplus (existing path, least used space) | Of all the drives on which the relative path exists choose the drive with the least used space. For **create** category functions it will exclude those with free space less than **minfreespace**. |
|
||||
| epmfs (existing path, most free space) | Of all the drives on which the relative path exists choose the drive with the most free space. For **create** category functions it will exclude those with free space less than **minfreespace**. |
|
||||
| eprand (existing path, random) | Calls **epall** and then randomizes. Otherwise behaves the same as **epall**. |
|
||||
| erofs | Exclusively return **-1** with **errno** set to **EROFS** (Read-only filesystem). By setting **create** functions to this you can in effect turn the filesystem mostly readonly. |
|
||||
| ff (first found) | Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
|
||||
| lfs (least free space) | Pick the drive with the least available free space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
|
||||
| lus (least used space) | Pick the drive with the least used space. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
|
||||
| mfs (most free space) | Pick the drive with the most available free space. For **create** category functions it will exclude readonly drives. Falls back to **ff**. |
|
||||
| newest | Pick the file / directory with the largest mtime. For **create** category functions it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
|
||||
| erofs | Exclusively return **-1** with **errno** set to **EROFS** (Read-only filesystem). |
|
||||
| ff (first found) | Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found. For **create** category functions it will exclude those with free space less than **minfreespace**. |
|
||||
| lfs (least free space) | Pick the drive with the least available free space. For **create** category functions it will exclude those with free space less than **minfreespace**. |
|
||||
| lus (least used space) | Pick the drive with the least used space. For **create** category functions it will exclude those with free space less than **minfreespace**. |
|
||||
| mfs (most free space) | Pick the drive with the most available free space. |
|
||||
| newest | Pick the file / directory with the largest mtime. For **create** category functions it will exclude those with free space less than **minfreespace**. |
|
||||
| rand (random) | Calls **all** and then randomizes. |
|
||||
|
||||
#### Defaults ####
|
||||
|
||||
| Category | Policy |
|
||||
|----------|--------|
|
||||
| action | all |
|
||||
| action | epall |
|
||||
| create | epmfs |
|
||||
| search | ff |
|
||||
|
||||
@@ -211,7 +261,7 @@ The above behavior will help minimize the likelihood of EXDEV being returned but
|
||||
|
||||
#### 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 sources on the same drive will not result in double counting it's space.
|
||||
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple sources on the same drive will not result in double counting it's space. Filesystems mounted further down the tree of the branch will not be included.
|
||||
|
||||
# BUILDING
|
||||
|
||||
@@ -231,7 +281,7 @@ $ sudo apt-get -y update
|
||||
$ sudo apt-get -y install git make
|
||||
$ cd mergerfs
|
||||
$ make install-build-pkgs
|
||||
$ # build-essential git g++ debhelper libattr1-dev python automake libtool lsb-release
|
||||
$ # build-essential git g++ debhelper python automake libtool lsb-release
|
||||
$ make deb
|
||||
$ sudo dpkg -i ../mergerfs_version_arch.deb
|
||||
```
|
||||
@@ -243,14 +293,14 @@ $ su -
|
||||
# dnf -y install git make
|
||||
# cd mergerfs
|
||||
# make install-build-pkgs
|
||||
# # rpm-build libattr-devel gcc-c++ which python automake libtool gettext-devel
|
||||
# # rpm-build gcc-c++ which python automake libtool gettext-devel
|
||||
# make rpm
|
||||
# rpm -i rpmbuild/RPMS/<arch>/mergerfs-<verion>.<arch>.rpm
|
||||
```
|
||||
|
||||
#### Generically
|
||||
|
||||
Have git, g++, make, python, libattr1, automake, libtool installed.
|
||||
Have git, g++, make, python, automake, libtool installed.
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
@@ -258,6 +308,19 @@ $ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
#### Generically with system libfuse
|
||||
|
||||
**NOTE:** Configurable threading and thus `-o threads=num` option will be unavailable when built with system libfuse.
|
||||
|
||||
Have git, g++, make, python, pkg-config installed.
|
||||
Also, install libfuse >= 2.9.7 (but not libfuse-3.x) and matching libfuse-dev (or libfuse-devel).
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
$ make INTERNAL_FUSE=0
|
||||
$ sudo make INTERNAL_FUSE=0 install
|
||||
```
|
||||
|
||||
# RUNTIME
|
||||
|
||||
#### .mergerfs pseudo file ####
|
||||
@@ -267,15 +330,15 @@ $ sudo make install
|
||||
|
||||
There is a pseudo file available at the mount point which allows for the runtime modification of certain **mergerfs** options. The file will not show up in **readdir** but can be **stat**'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
|
||||
|
||||
Even if xattrs are disabled for mergerfs the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls against this pseudo file will still work.
|
||||
|
||||
Any changes made at runtime are **not** persisted. If you wish for values to persist they must be included as options wherever you configure the mounting of mergerfs (fstab).
|
||||
Any changes made at runtime are **not** persisted. If you wish for values to persist they must be included as options wherever you configure the mounting of mergerfs (/etc/fstab).
|
||||
|
||||
##### Keys #####
|
||||
|
||||
Use `xattr -l /mount/point/.mergerfs` to see all supported keys. Some are informational and therefore readonly.
|
||||
|
||||
###### user.mergerfs.srcmounts ######
|
||||
###### user.mergerfs.branches ######
|
||||
|
||||
**NOTE:** formerly `user.mergerfs.srcmounts` but said key is still supported.
|
||||
|
||||
Used to query or modify the list of source mounts. When modifying there are several shortcuts to easy manipulation of the list.
|
||||
|
||||
@@ -288,6 +351,8 @@ Used to query or modify the list of source mounts. When modifying there are seve
|
||||
| -< | remove first in list |
|
||||
| -> | remove last in list |
|
||||
|
||||
`xattr -w user.mergerfs.branches +</mnt/drive3 /mnt/pool/.mergerfs`
|
||||
|
||||
###### minfreespace ######
|
||||
|
||||
Input: interger with an optional multiplier suffix. **K**, **M**, or **G**.
|
||||
@@ -309,30 +374,30 @@ Output: the policy string except for categories where its funcs have multiple ty
|
||||
##### Example #####
|
||||
|
||||
```
|
||||
[trapexit:/tmp/mount] $ xattr -l .mergerfs
|
||||
user.mergerfs.srcmounts: /tmp/a:/tmp/b
|
||||
[trapexit:/mnt/mergerfs] $ xattr -l .mergerfs
|
||||
user.mergerfs.branches: /mnt/a:/mnt/b
|
||||
user.mergerfs.minfreespace: 4294967295
|
||||
user.mergerfs.moveonenospc: false
|
||||
...
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.category.search .mergerfs
|
||||
ff
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search newest .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ xattr -w user.mergerfs.category.search newest .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.category.search .mergerfs
|
||||
newest
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
[trapexit:/mnt/mergerfs] $ xattr -w user.mergerfs.branches +/mnt/c .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.branches .mergerfs
|
||||
/mnt/a:/mnt/b:/mnt/c
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts =/tmp/c .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/c
|
||||
[trapexit:/mnt/mergerfs] $ xattr -w user.mergerfs.branches =/mnt/c .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.branches .mergerfs
|
||||
/mnt/c
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts '+</tmp/a:/tmp/b' .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
[trapexit:/mnt/mergerfs] $ xattr -w user.mergerfs.branches '+</mnt/a:/mnt/b' .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.branches .mergerfs
|
||||
/mnt/a:/mnt/b:/mnt/c
|
||||
```
|
||||
|
||||
#### file / directory xattrs ####
|
||||
@@ -345,15 +410,15 @@ While they won't show up when using [listxattr](http://linux.die.net/man/2/listx
|
||||
* **user.mergerfs.allpaths:** a NUL ('\0') separated list of full paths to all files found
|
||||
|
||||
```
|
||||
[trapexit:/tmp/mount] $ ls
|
||||
[trapexit:/mnt/mergerfs] $ ls
|
||||
A B C
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.fullpath A
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.fullpath A
|
||||
/mnt/a/full/path/to/A
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.basepath A
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.basepath A
|
||||
/mnt/a
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.relpath A
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.relpath A
|
||||
/full/path/to/A
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.allpaths A | tr '\0' '\n'
|
||||
[trapexit:/mnt/mergerfs] $ xattr -p user.mergerfs.allpaths A | tr '\0' '\n'
|
||||
/mnt/a/full/path/to/A
|
||||
/mnt/b/full/path/to/A
|
||||
```
|
||||
@@ -364,10 +429,11 @@ A B C
|
||||
* mergerfs.ctl: A tool to make it easier to query and configure mergerfs at runtime
|
||||
* mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
|
||||
* mergerfs.dedup: Will help identify and optionally remove duplicate files
|
||||
* mergerfs.dup: Ensure there are at least N copies of a file across the pool
|
||||
* mergerfs.balance: Rebalance files across drives by moving them from the most filled to the least filled
|
||||
* mergerfs.mktrash: Creates FreeDesktop.org Trash specification compatible directories on a mergerfs mount
|
||||
* https://github.com/trapexit/scorch
|
||||
* scorch: A tool to help discover silent corruption of files
|
||||
* scorch: A tool to help discover silent corruption of files and keep track of files
|
||||
* https://github.com/trapexit/bbf
|
||||
* bbf (bad block finder): a tool to scan for and 'fix' hard drive bad blocks and find the files using those blocks
|
||||
|
||||
@@ -438,14 +504,14 @@ done
|
||||
|
||||
# TIPS / NOTES
|
||||
|
||||
* The recommended options are **defaults,allow_other,direct_io,use_ino**. (**use_ino** will only work when used with mergerfs 2.18.0 and above.)
|
||||
* The recommended base options are **defaults,allow_other,direct_io,use_ino**. (**use_ino** will only work when used with mergerfs 2.18.0 and above.)
|
||||
* Run mergerfs as `root` unless you're merging paths which are owned by the same user otherwise strange permission issues may arise.
|
||||
* https://github.com/trapexit/backup-and-recovery-howtos : A set of guides / howtos on creating a data storage system, backing it up, maintaining it, and recovering from failure.
|
||||
* If you don't see some directories and files you expect in a merged point or policies seem to skip drives be sure the user has permission to all the underlying directories. Use `mergerfs.fsck` to audit the drive for out of sync permissions.
|
||||
* Do *not* use `direct_io` if you expect applications (such as rtorrent) to [mmap](http://linux.die.net/man/2/mmap) files. It is not currently supported in FUSE w/ `direct_io` enabled.
|
||||
* Do **not** use `direct_io` if you expect applications (such as rtorrent) to [mmap](http://linux.die.net/man/2/mmap) files. It is not currently supported in FUSE w/ `direct_io` enabled. Enabling `dropcacheonclose` is recommended when `direct_io` is disabled.
|
||||
* Since POSIX gives you only error or success on calls its difficult to determine the proper behavior when applying the behavior to multiple targets. **mergerfs** will return an error only if all attempts of an action fail. Any success will lead to a success returned. This means however that some odd situations may arise.
|
||||
* [Kodi](http://kodi.tv), [Plex](http://plex.tv), [Subsonic](http://subsonic.org), etc. can use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether to scan for new content rather than simply performing a full scan. If using the default **getattr** policy of **ff** its possible **Kodi** will miss an update on account of it returning the first directory found's **stat** info and its a later directory on another mount which had the **mtime** recently updated. To fix this you will want to set **func.getattr=newest**. Remember though that this is just **stat**. If the file is later **open**'ed or **unlink**'ed and the policy is different for those then a completely different file or directory could be acted on.
|
||||
* Some policies mixed with some functions may result in strange behaviors. Not that some of these behaviors and race conditions couldn't happen outside **mergerfs** but that they are far more likely to occur on account of attempt to merge together multiple sources of data which could be out of sync due to the different policies.
|
||||
* [Kodi](http://kodi.tv), [Plex](http://plex.tv), [Subsonic](http://subsonic.org), etc. can use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether to scan for new content rather than simply performing a full scan. If using the default **getattr** policy of **ff** its possible those programs will miss an update on account of it returning the first directory found's **stat** info and its a later directory on another mount which had the **mtime** recently updated. To fix this you will want to set **func.getattr=newest**. Remember though that this is just **stat**. If the file is later **open**'ed or **unlink**'ed and the policy is different for those then a completely different file or directory could be acted on.
|
||||
* Some policies mixed with some functions may result in strange behaviors. Not that some of these behaviors and race conditions couldn't happen outside **mergerfs** but that they are far more likely to occur on account of the attempt to merge together multiple sources of data which could be out of sync due to the different policies.
|
||||
* For consistency its generally best to set **category** wide policies rather than individual **func**'s. This will help limit the confusion of tools such as [rsync](http://linux.die.net/man/1/rsync). However, the flexibility is there if needed.
|
||||
|
||||
# KNOWN ISSUES / BUGS
|
||||
@@ -510,6 +576,10 @@ This is the same issue as with Samba. `rename` returns `EXDEV` (in our case that
|
||||
|
||||
To create a `$topdir/.Trash` directory as defined in the standard use the [mergerfs-tools](https://github.com/trapexit/mergerfs-tools) tool `mergerfs.mktrash`.
|
||||
|
||||
#### tar: Directory renamed before its status could be extracted
|
||||
|
||||
Make sure to use the `use_ino` option.
|
||||
|
||||
#### Supplemental user groups
|
||||
|
||||
Due to the overhead of [getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs utilizes a cache. This cache is opportunistic and per thread. Each thread will query the supplemental groups for a user when that particular thread needs to change credentials and will keep that data for the lifetime of the thread. This means that if a user is added to a group it may not be picked up without the restart of mergerfs. However, since the high level FUSE API's (at least the standard version) thread pool dynamically grows and shrinks it's possible that over time a thread will be killed and later a new thread with no cache will start and query the new data.
|
||||
@@ -518,7 +588,7 @@ The gid cache uses fixed storage to simplify the design and be compatible with o
|
||||
|
||||
#### mergerfs or libfuse crashing
|
||||
|
||||
**NOTE:** as of mergerfs 2.22.0 it includes the most recent version of libfuse so any crash should be reported. For older releases continue reading...
|
||||
**NOTE:** as of mergerfs 2.22.0 it includes the most recent version of libfuse (or requires libfuse-2.9.7) so any crash should be reported. For older releases continue reading...
|
||||
|
||||
If suddenly the mergerfs mount point disappears and `Transport endpoint is not connected` is returned when attempting to perform actions within the mount directory **and** the version of libfuse (use `mergerfs -v` to find the version) is older than `2.9.4` its likely due to a bug in libfuse. Affected versions of libfuse can be found in Debian Wheezy, Ubuntu Precise and others.
|
||||
|
||||
@@ -570,21 +640,77 @@ https://lkml.org/lkml/2016/9/14/527
|
||||
|
||||
There is a bug in the kernel. A work around appears to be turning off `splice`. Add `no_splice_write,no_splice_move,no_splice_read` to mergerfs' options. Should be placed after `defaults` if it is used since it will turn them on. This however is not guaranteed to work.
|
||||
|
||||
#### rm: fts_read failed: No such file or directory
|
||||
|
||||
Not *really* a bug. The FUSE library will move files when asked to delete them as a way to deal with certain edge cases and then later delete that file when its clear the file is no longer needed. This however can lead to two issues. One is that these hidden files are noticed by `rm -rf` or `find` when scanning directories and they may try to remove them and they might have disappeared already. There is nothing *wrong* about this happening but it can be annoying. The second issue is that a directory might not be able to removed on account of the hidden file being still there.
|
||||
|
||||
Using the **hard_remove** option will make it so these temporary files are not used and files are deleted immedately. That has a side effect however. Files which are unlinked and then they are still used (in certain forms) will result in an error.
|
||||
|
||||
# FAQ
|
||||
|
||||
#### How well does mergerfs scale? Is it "production ready?"
|
||||
|
||||
Users have reported running mergerfs on everything from a Raspberry Pi to dual socket Xeon systems with >20 cores. I'm aware of at least a few companies which use mergerfs in production. [Open Media Vault](https://www.openmediavault.org) includes mergerfs is it's sole solution for pooling drives.
|
||||
|
||||
#### Can mergerfs be used with drives which already have data / are in use?
|
||||
|
||||
Yes. MergerFS is a proxy and does **NOT** interfere with the normal form or function of the drives / mounts / paths it manages.
|
||||
|
||||
MergerFS is **not** a traditional filesystem. MergerFS is **not** RAID. It does **not** manipulate the data that passes through it. It does **not** shard data across drives. It merely shards some **behavior** and aggregates others.
|
||||
|
||||
#### Can mergerfs be removed without affecting the data?
|
||||
|
||||
See the previous question's answer.
|
||||
|
||||
#### Do hard links work?
|
||||
|
||||
Yes. You need to use `use_ino` to support proper reporting of inodes. Read the section "rename & link" for caveats.
|
||||
|
||||
#### Does mergerfs support CoW / copy-on-write?
|
||||
|
||||
Not in the sense of a filesystem like BTRFS or ZFS nor in the overlayfs or aufs sense. It does offer a [cow-shell](http://manpages.ubuntu.com/manpages/bionic/man1/cow-shell.1.html) like hardlink breaking (copy to temp file then rename over original) which can be useful when wanting to save space by hardlinking duplicate files but wish to treat each name as if it were a unique and separate file.
|
||||
|
||||
#### Why can't I see my files / directories?
|
||||
|
||||
It's almost always a permissions issue. Unlike mhddfs, which runs as root and attempts to access content as such, mergerfs always changes it's credentials to that of the caller. This means that if the user does not have access to a file or directory than neither will mergerfs. However, because mergerfs is creating a union of paths it may be able to read some files and directories on one drive but not another resulting in an incomplete set.
|
||||
|
||||
Whenever you run into a split permission issue (seeing some but not all files) try using [mergerfs.fsck](https://github.com/trapexit/mergerfs-tools) tool to check for and fix the mismatch. If you aren't seeing anything at all be sure that the basic permissions are correct. The user and group values are correct and that directories have their executable bit set. A common mistake by users new to Linux is to `chmod -R 644` when they should have `chmod -R u=rwX,go=rX`.
|
||||
|
||||
If using a network filesystem such as NFS, SMB, CIFS (Samba) be sure to pay close attention to anything regarding permissioning and users. Root squashing and user translation for instance has bitten a few mergerfs users. Some of these also affect the use of mergerfs from container platforms such as Docker.
|
||||
|
||||
#### Why is only one drive being used?
|
||||
|
||||
Are you using a path preserving policy? The default policy for file creation is `epmfs`. That means only the drives with the path preexisting will be considered when creating a file. If you don't care about where files and directories are created you likely shouldn't be using a path preserving policy and instead something like `mfs`.
|
||||
|
||||
This can be especially apparent when filling an empty pool from an external source. If you do want path preservation you'll need to perform the manual act of creating paths on the drives you want the data to land on before transfering your data.
|
||||
|
||||
#### Why was libfuse embedded into mergerfs?
|
||||
|
||||
A significant number of users use mergerfs on distros with very old versions of libfuse which have serious bugs. Requiring updated versions of libfuse on those distros isn't pratical (no package offered, user inexperience, etc.). The only practical way to provide a stable runtime on those systems was to "vendor" the library into the project.
|
||||
|
||||
#### Why use mergerfs over mhddfs?
|
||||
|
||||
mhddfs is no longer maintained and has some known stability and security issues (see below). MergerFS provides a superset of mhddfs' features and should offer the same or maybe better performance.
|
||||
|
||||
If you wish to get similar behavior to mhddfs from mergerfs then set `category.create=ff`.
|
||||
Below is an example of mhddfs and mergerfs setup to work similarly.
|
||||
|
||||
`mhddfs -o mlimit=4G,allow_other /mnt/drive1,/mnt/drive2 /mnt/pool`
|
||||
|
||||
`mergerfs -o minfreespace=4G,defaults,allow_other,category.create=ff /mnt/drive1:/mnt/drive2 /mnt/pool`
|
||||
|
||||
#### Why use mergerfs over aufs?
|
||||
|
||||
While aufs can offer better peak performance mergerfs provides more configurability and is generally easier to use. mergerfs however does not offer the overlay / copy-on-write (COW) features which aufs and overlayfs have.
|
||||
aufs is mostly abandoned and no longer available in many distros.
|
||||
|
||||
While aufs can offer better peak performance mergerfs provides more configurability and is generally easier to use. mergerfs however does not offer the overlay / copy-on-write (CoW) features which aufs and overlayfs have.
|
||||
|
||||
#### Why use mergerfs over unionfs?
|
||||
|
||||
UnionFS is more like aufs then mergerfs in that it offers overlay / CoW features. If you're just looking to create a union of drives and want flexibility in file/directory placement then mergerfs offers that whereas unionfs is more for overlaying RW filesystems over RO ones.
|
||||
|
||||
#### Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation / striping?
|
||||
|
||||
With simple JBOD / drive concatenation / stripping / RAID0 a single drive failure will result in full pool failure. mergerfs performs a similar behavior without the possibility of catastrophic failure and difficulties in recovery. Drives may fail however all other data will continue to be accessable.
|
||||
With simple JBOD / drive concatenation / stripping / RAID0 a single drive failure will result in full pool failure. mergerfs performs a similar behavior without the possibility of catastrophic failure and the difficulties in recovery. Drives may fail however all other data will continue to be accessable.
|
||||
|
||||
When combined with something like [SnapRaid](http://www.snapraid.it) and/or an offsite backup solution you can have the flexibilty of JBOD without the single point of failure.
|
||||
|
||||
@@ -600,7 +726,7 @@ Yes. It will be represented immediately in the pool as the policies perscribe.
|
||||
|
||||
First make sure you've read the sections above about policies, path preserving, and the **moveonenospc** option.
|
||||
|
||||
Remember that mergerfs is simply presenting a logical merging of the contents of the pooled drives. The reported free space is the aggregate space available **not** the contiguous space available. MergerFS does not split files across drives. If the writing of a file fills a drive and **moveonenospc** is disabled it will return an ENOSPC error.
|
||||
Remember that mergerfs is simply presenting a logical merging of the contents of the pooled drives. The reported free space is the aggregate space available **not** the contiguous space available. MergerFS does not split files across drives. If the writing of a file fills an underlying drive and **moveonenospc** is disabled it will return an ENOSPC (No space left on device) error.
|
||||
|
||||
If **moveonenospc** is enabled but there exists no drives with enough space for the file and the data to be written (or the drive happened to fill up as the file was being moved) it will error indicating there isn't enough space.
|
||||
|
||||
@@ -612,7 +738,7 @@ Yes. Some clients (Kodi) have issues in which the contents of the NFS mount will
|
||||
|
||||
#### Can mergerfs mounts be exported over Samba / SMB?
|
||||
|
||||
Yes.
|
||||
Yes. While some users have reported problems it appears to always be related to how Samba is setup in relation to permissions.
|
||||
|
||||
#### How are inodes calculated?
|
||||
|
||||
@@ -620,6 +746,33 @@ mergerfs-inode = (original-inode | (device-id << 32))
|
||||
|
||||
While `ino_t` is 64 bits only a few filesystems use more than 32. Similarly, while `dev_t` is also 64 bits it was traditionally 16 bits. Bitwise or'ing them together should work most of the time. While totally unique inodes are preferred the overhead which would be needed does not seem to outweighted by the benefits.
|
||||
|
||||
While atypical, yes, inodes can be reused and not refer to the same file. The internal id used to reference a file in FUSE is different from the inode value presented. The former is the `nodeid` and is actually a tuple of (nodeid,generation). That tuple is not user facing. The inode is merely metadata passed through the kernel and found using the `stat` family of calls or `readdir`.
|
||||
|
||||
From FUSE docs regarding `use_ino`:
|
||||
|
||||
```
|
||||
Honor the st_ino field in the functions getattr() and
|
||||
fill_dir(). This value is used to fill in the st_ino field
|
||||
in the stat(2), lstat(2), fstat(2) functions and the d_ino
|
||||
field in the readdir(2) function. The filesystem does not
|
||||
have to guarantee uniqueness, however some applications
|
||||
rely on this value being unique for the whole filesystem.
|
||||
Note that this does *not* affect the inode that libfuse
|
||||
and the kernel use internally (also called the "nodeid").
|
||||
```
|
||||
|
||||
#### I notice massive slowdowns of writes over NFS
|
||||
|
||||
Due to how NFS works and interacts with FUSE when not using `direct_io` its possible that a getxattr for `security.capability` will be issued prior to any write. This will usually result in a massive slowdown for writes. Using `direct_io` will keep this from happening (and generally good to enable unless you need the features it disables) but the `security_capability` option can also help by short circuiting the call and returning `ENOATTR`.
|
||||
|
||||
You could also set `xattr` to `noattr` or `notsup` to short circuit or stop all xattr requests.
|
||||
|
||||
#### What are these .fuse_hidden files?
|
||||
|
||||
When not using `hard_remove` libfuse will create .fuse_hiddenXXXXXXXX files when an opened file is unlinked. This is to simplify "use after unlink" usecases. There is a possibility these files end up being picked up by software scanning directories and not ignoring hidden files. This is rarely a problem but a solution is in the works.
|
||||
|
||||
The files are cleaned up once the file is finally closed. Only if mergerfs crashes or is killed would they be left around.
|
||||
|
||||
#### It's mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?
|
||||
|
||||
[mhddfs](https://github.com/trapexit/mhddfs) manages running as **root** by calling [getuid()](https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319) and if it returns **0** then it will [chown](http://linux.die.net/man/1/chown) the file. Not only is that a race condition but it doesn't handle many other situations. Rather than attempting to simulate POSIX ACL behavior the proper way to manage this is to use [seteuid](http://linux.die.net/man/2/seteuid) and [setegid](http://linux.die.net/man/2/setegid), in effect becoming the user making the original call, and perform the action as them. This is what mergerfs does.
|
||||
@@ -628,18 +781,51 @@ In Linux setreuid syscalls apply only to the thread. GLIBC hides this away by us
|
||||
|
||||
For non-Linux systems mergerfs uses a read-write lock and changes credentials only when necessary. If multiple threads are to be user X then only the first one will need to change the processes credentials. So long as the other threads need to be user X they will take a readlock allowing multiple threads to share the credentials. Once a request comes in to run as user Y that thread will attempt a write lock and change to Y's credentials when it can. If the ability to give writers priority is supported then that flag will be used so threads trying to change credentials don't starve. This isn't the best solution but should work reasonably well assuming there are few users.
|
||||
|
||||
# PERFORMANCE TWEAKING
|
||||
|
||||
* try adding (or removing) `direct_io`
|
||||
* try adding (or removing) `auto_cache` / `noauto_cache` (included in `defaults`)
|
||||
* try adding (or removing) `kernel_cache` (don't use the underlying filesystems directly if enabling `kernel_cache`)
|
||||
* try adding (or removing) `splice_move`, `splice_read`, and `splice_write` (all three included in `defaults`)
|
||||
* try changing the number of worker threads
|
||||
* try disabling `security_capability` or `xattr`
|
||||
* test theoretical performance using `nullrw` or mounting a ram disk
|
||||
* use `symlinkify` if your data is largely static and you need native speed reads
|
||||
* use lvm and lvm cache to place a SSD in front of your HDDs (howto coming)
|
||||
|
||||
# SUPPORT
|
||||
|
||||
#### Issues with the software
|
||||
Filesystems are very complex and difficult to debug. mergerfs, while being just a proxy of sorts, is also very difficult to debug given the large number of possible settings it can have itself and the massive number of environments it can run in. When reporting on a suspected issue **please, please** include as much of the below information as possible otherwise it will be difficult or impossible to diagnose. Also please make sure to read all of the above documentation as it includes nearly every known system or user issue previously encountered.
|
||||
|
||||
#### Information to include in bug reports
|
||||
* Version of mergerfs: `mergerfs -V`
|
||||
* mergerfs settings: from `/etc/fstab` or command line execution
|
||||
* Version of Linux: `uname -a`
|
||||
* Versions of any additional software being used
|
||||
* List of drives, their filesystems, and sizes (before and after issue): `df -h`
|
||||
* A `strace` of the app having problems:
|
||||
* `strace -f -o /tmp/app.strace.txt <cmd>`
|
||||
* A `strace` of mergerfs while the program is trying to do whatever it's failing to do:
|
||||
* `strace -f -p <mergerfsPID> -o /tmp/mergerfs.strace.txt`
|
||||
* **Precise** directions on replicating the issue. Do not leave **anything** out.
|
||||
* Try to recreate the problem in the simplist way using standard programs.
|
||||
|
||||
#### Contact / Issue submission
|
||||
* github.com: https://github.com/trapexit/mergerfs/issues
|
||||
* email: trapexit@spawn.link
|
||||
* twitter: https://twitter.com/_trapexit
|
||||
|
||||
#### Support development
|
||||
* BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
|
||||
This software is free to use and released under a very liberal license. That said if you like this software and would like to support its development donations are welcome.
|
||||
|
||||
* Bitcoin (BTC): 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
* Bitcoin Cash (BCH): 1AjPqZZhu7GVEs6JFPjHmtsvmDL4euzMzp
|
||||
* Ethereum (ETH): 0x09A166B11fCC127324C7fc5f1B572255b3046E94
|
||||
* Litecoin (LTC): LXAsq6yc6zYU3EbcqyWtHBrH1Ypx4GjUjm
|
||||
* Ripple (XRP): rNACR2hqGjpbHuCKwmJ4pDpd2zRfuRATcE
|
||||
* PayPal: trapexit@spawn.link
|
||||
* Patreon: https://www.patreon.com/trapexit
|
||||
* Gratipay: https://gratipay.com/~trapexit
|
||||
|
||||
# LINKS
|
||||
|
||||
|
||||
Vendored
+6
-6
@@ -2,16 +2,16 @@ Source: mergerfs
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Maintainer: Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Build-Depends: debhelper (>= 8.0.0),
|
||||
libattr1-dev
|
||||
Build-Depends: debhelper (>= 8.0.0)
|
||||
Standards-Version: 3.9.4
|
||||
Homepage: http://github.com/trapexit/mergerfs
|
||||
|
||||
Package: mergerfs
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends}
|
||||
${misc:Depends},
|
||||
fuse [linux-any] | fuse4bsd [kfreebsd-any]
|
||||
Description: another FUSE union filesystem
|
||||
mergerfs is similar to mhddfs, unionfs, and aufs. Like mhddfs in that it too
|
||||
uses FUSE. Like aufs in that it provides multiple policies for how to handle
|
||||
behavior.
|
||||
mergerfs is a union filesystem geared towards simplifying storage and
|
||||
management of files across numerous commodity storage devices. It is
|
||||
similar to mhddfs, unionfs, and aufs.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
AC_INIT(fuse, 2.9.7)
|
||||
AC_INIT(fuse, 2.9.8-mergerfs)
|
||||
|
||||
AC_PREREQ(2.59d)
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
@@ -4432,6 +4432,9 @@ static void fuse_lib_help(void)
|
||||
" -o intr allow requests to be interrupted\n"
|
||||
" -o intr_signal=NUM signal to send on interrupt (%i)\n"
|
||||
" -o modules=M1[:M2...] names of modules to push onto filesystem stack\n"
|
||||
" -o threads=NUM number of worker threads. 0 = autodetect.\n"
|
||||
" Negative values autodetect then divide by\n"
|
||||
" absolute value. default = 0\n"
|
||||
"\n", FUSE_DEFAULT_INTR_SIGNAL);
|
||||
}
|
||||
|
||||
|
||||
+486
-97
@@ -1,14 +1,14 @@
|
||||
.\"t
|
||||
.\" Automatically generated by Pandoc 1.16.0.2
|
||||
.\" Automatically generated by Pandoc 1.19.2.4
|
||||
.\"
|
||||
.TH "mergerfs" "1" "2017\-05\-26" "mergerfs user manual" ""
|
||||
.TH "mergerfs" "1" "2018\-10\-31" "mergerfs user manual" ""
|
||||
.hy
|
||||
.SH NAME
|
||||
.PP
|
||||
mergerfs \- a featureful union filesystem
|
||||
.SH SYNOPSIS
|
||||
.PP
|
||||
mergerfs \-o<options> <srcmounts> <mountpoint>
|
||||
mergerfs \-o<options> <branches> <mountpoint>
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
\f[B]mergerfs\f[] is a union filesystem geared towards simplifying
|
||||
@@ -39,6 +39,42 @@ capacity)
|
||||
Handles pool of readonly and read/write drives
|
||||
.IP \[bu] 2
|
||||
Turn read\-only files into symlinks to increase read performance
|
||||
.SH How it works
|
||||
.PP
|
||||
mergerfs logically merges multiple paths together.
|
||||
Think a union of sets.
|
||||
The file/s or directory/s acted on or presented through mergerfs are
|
||||
based on the policy chosen for that particular action.
|
||||
Read more about policies below.
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
A\ \ \ \ \ \ \ \ \ +\ \ \ \ \ \ B\ \ \ \ \ \ \ \ =\ \ \ \ \ \ \ C
|
||||
/disk1\ \ \ \ \ \ \ \ \ \ \ /disk2\ \ \ \ \ \ \ \ \ \ \ /merged
|
||||
|\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |
|
||||
+\-\-\ /dir1\ \ \ \ \ \ \ \ +\-\-\ /dir1\ \ \ \ \ \ \ \ +\-\-\ /dir1
|
||||
|\ \ \ |\ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ |\ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ |
|
||||
|\ \ \ +\-\-\ file1\ \ \ \ |\ \ \ +\-\-\ file2\ \ \ \ |\ \ \ +\-\-\ file1
|
||||
|\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ +\-\-\ file3\ \ \ \ |\ \ \ +\-\-\ file2
|
||||
+\-\-\ /dir2\ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ +\-\-\ file3
|
||||
|\ \ \ |\ \ \ \ \ \ \ \ \ \ \ \ +\-\-\ /dir3\ \ \ \ \ \ \ \ |
|
||||
|\ \ \ +\-\-\ file4\ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ \ \ \ \ +\-\-\ /dir2
|
||||
|\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +\-\-\ file5\ \ \ |\ \ \ |
|
||||
+\-\-\ file6\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ +\-\-\ file4
|
||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |
|
||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +\-\-\ /dir3
|
||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ |
|
||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |\ \ \ +\-\-\ file5
|
||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |
|
||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +\-\-\ file6
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
mergerfs does \f[B]not\f[] support the copy\-on\-write (CoW) behavior
|
||||
found in \f[B]aufs\f[] and \f[B]overlayfs\f[].
|
||||
You can \f[B]not\f[] mount a read\-only filesystem and write to it.
|
||||
However, mergerfs will ignore read\-only drives when creating new files
|
||||
so you can mix rw and ro drives.
|
||||
.SH OPTIONS
|
||||
.SS mount options
|
||||
.IP \[bu] 2
|
||||
@@ -47,10 +83,15 @@ Turn read\-only files into symlinks to increase read performance
|
||||
\f[B]splice_move\f[], \f[B]splice_read\f[], and \f[B]splice_write\f[].
|
||||
These options seem to provide the best performance.
|
||||
.IP \[bu] 2
|
||||
\f[B]allow_other\f[]: a libfuse option which allows users besides the
|
||||
one which ran mergerfs to see the filesystem.
|
||||
This is required for most use\-cases.
|
||||
.IP \[bu] 2
|
||||
\f[B]direct_io\f[]: causes FUSE to bypass caching which can increase
|
||||
write speeds at the detriment of reads.
|
||||
Note that not enabling \f[C]direct_io\f[] will cause double caching of
|
||||
files and therefore less memory for caching generally.
|
||||
files and therefore less memory for caching generally (enable
|
||||
\f[B]dropcacheonclose\f[] to help with this problem).
|
||||
However, \f[C]mmap\f[] does not work when \f[C]direct_io\f[] is enabled.
|
||||
.IP \[bu] 2
|
||||
\f[B]minfreespace=value\f[]: the minimum space value used for creation
|
||||
@@ -61,8 +102,9 @@ kilobyte, megabyte, and gigabyte respectively.
|
||||
.IP \[bu] 2
|
||||
\f[B]moveonenospc=true|false\f[]: when enabled (set to \f[B]true\f[]) if
|
||||
a \f[B]write\f[] fails with \f[B]ENOSPC\f[] or \f[B]EDQUOT\f[] a scan of
|
||||
all drives will be done looking for the drive with most free space which
|
||||
is at least the size of the file plus the amount which failed to write.
|
||||
all drives will be done looking for the drive with the most free space
|
||||
which is at least the size of the file plus the amount which failed to
|
||||
write.
|
||||
An attempt to move the file to that drive will occur (keeping all
|
||||
metadata possible) and if successful the original is unlinked and the
|
||||
write retried.
|
||||
@@ -73,6 +115,12 @@ than libfuse.
|
||||
While not a default it is generally recommended it be enabled so that
|
||||
hard linked files share the same inode value.
|
||||
.IP \[bu] 2
|
||||
\f[B]hard_remove\f[]: force libfuse to immedately remove files when
|
||||
unlinked.
|
||||
This will keep the \f[C]\&.fuse_hidden\f[] files from showing up but if
|
||||
software uses an opened but unlinked file in certain ways it could
|
||||
result in errors.
|
||||
.IP \[bu] 2
|
||||
\f[B]dropcacheonclose=true|false\f[]: when a file is requested to be
|
||||
closed call \f[C]posix_fadvise\f[] on it first to instruct the kernel
|
||||
that we no longer need the data and it can drop its cache.
|
||||
@@ -104,6 +152,38 @@ preserving behavior.
|
||||
This means files, when renamed or linked, will stay on the same drive.
|
||||
(default: false)
|
||||
.IP \[bu] 2
|
||||
\f[B]security_capability=true|false\f[]: If false return ENOATTR when
|
||||
xattr security.capability is queried.
|
||||
(default: true)
|
||||
.IP \[bu] 2
|
||||
\f[B]xattr=passthrough|noattr|notsup\f[]: Runtime control of xattrs.
|
||||
Default is to passthrough xattr requests.
|
||||
\[aq]noattr\[aq] will short circuit as if nothing exists.
|
||||
\[aq]notsup\[aq] will respond with ENOTSUP as if xattrs are not
|
||||
supported or disabled.
|
||||
(default: passthrough)
|
||||
.IP \[bu] 2
|
||||
\f[B]link_cow=true|false\f[]: When enabled if a regular file is opened
|
||||
which has a link count > 1 it will copy the file to a temporary file and
|
||||
rename over the original.
|
||||
Breaking the link and providing a basic copy\-on\-write function similar
|
||||
to cow\-shell.
|
||||
(default: false)
|
||||
.IP \[bu] 2
|
||||
\f[B]statfs=base|full\f[]: Controls how statfs works.
|
||||
\[aq]base\[aq] means it will always use all branches in statfs
|
||||
calculations.
|
||||
\[aq]full\[aq] is in effect path preserving and only includes drives
|
||||
where the path exists.
|
||||
(default: base)
|
||||
.IP \[bu] 2
|
||||
\f[B]statfs_ignore=none|ro|nc\f[]: \[aq]ro\[aq] will cause statfs
|
||||
calculations to ignore available space for branches mounted or tagged as
|
||||
\[aq]read only\[aq] or \[aq]no create\[aq].
|
||||
\[aq]nc\[aq] will ignore available space for branches tagged as \[aq]no
|
||||
create\[aq].
|
||||
(default: none)
|
||||
.IP \[bu] 2
|
||||
\f[B]threads=num\f[]: number of threads to use in multithreaded mode.
|
||||
When set to zero (the default) it will attempt to discover and use the
|
||||
number of logical cores.
|
||||
@@ -115,7 +195,8 @@ threads=\-2 on an 8 core machine will result in 8 / 2 = 4 threads.
|
||||
There will always be at least 1 thread.
|
||||
NOTE: higher number of threads increases parallelism but usually
|
||||
decreases throughput.
|
||||
(default: number of cores)
|
||||
(default: number of cores) \f[I]NOTE2:\f[] the option is unavailable
|
||||
when built with system libfuse.
|
||||
.IP \[bu] 2
|
||||
\f[B]fsname=name\f[]: sets the name of the filesystem as seen in
|
||||
\f[B]mount\f[], \f[B]df\f[], etc.
|
||||
@@ -135,10 +216,10 @@ Example: \f[B]category.create=mfs\f[]
|
||||
options are \f[B]func.rmdir=rand,category.action=ff\f[] the
|
||||
\f[B]action\f[] category setting will override the \f[B]rmdir\f[]
|
||||
setting.
|
||||
.SS srcmounts
|
||||
.SS branches
|
||||
.PP
|
||||
The srcmounts (source mounts) argument is a colon (\[aq]:\[aq])
|
||||
delimited list of paths to be included in the pool.
|
||||
The \[aq]branches\[aq] (formerly \[aq]srcmounts\[aq]) argument is a
|
||||
colon (\[aq]:\[aq]) delimited list of paths to be pooled together.
|
||||
It does not matter if the paths are on the same or different drives nor
|
||||
does it matter the filesystem.
|
||||
Used and available space will not be duplicated for paths on the same
|
||||
@@ -146,10 +227,22 @@ device and any features which aren\[aq]t supported by the underlying
|
||||
filesystem (such as file attributes or extended attributes) will return
|
||||
the appropriate errors.
|
||||
.PP
|
||||
To make it easier to include multiple source mounts mergerfs supports
|
||||
To make it easier to include multiple branches mergerfs supports
|
||||
globbing (http://linux.die.net/man/7/glob).
|
||||
\f[B]The globbing tokens MUST be escaped when using via the shell else
|
||||
the shell itself will expand it.\f[]
|
||||
the shell itself will apply the glob itself.\f[]
|
||||
.PP
|
||||
Each branch can have a suffix of \f[C]=RW\f[] (read / write),
|
||||
\f[C]=RO\f[] (read only), or \f[C]=NC\f[] (no create).
|
||||
These suffixes work with globs as well and will apply to each path
|
||||
found.
|
||||
\f[C]RW\f[] is the default behavior and those paths will be eligible for
|
||||
all policy categories.
|
||||
\f[C]RO\f[] will exclude those paths from \f[C]create\f[] and
|
||||
\f[C]action\f[] policies (just as a filesystem being mounted \f[C]ro\f[]
|
||||
would).
|
||||
\f[C]NC\f[] will exclude those paths from \f[C]create\f[] policies (you
|
||||
can\[aq]t create but you can change / delete).
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
@@ -165,8 +258,8 @@ tools use \f[B]/etc/fstab\f[].
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
#\ <file\ system>\ \ \ \ \ \ \ \ <mount\ point>\ \ <type>\ \ \ \ \ \ \ \ \ <options>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <dump>\ \ <pass>
|
||||
/mnt/disk*:/mnt/cdrom\ \ /media/drives\ \ fuse.mergerfs\ \ defaults,allow_other,use_ino\ \ 0\ \ \ \ \ \ \ 0
|
||||
#\ <file\ system>\ \ \ \ \ \ \ \ <mount\ point>\ \ <type>\ \ \ \ \ \ \ \ \ <options>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <dump>\ \ <pass>
|
||||
/mnt/disk*:/mnt/cdrom\ \ /media/drives\ \ fuse.mergerfs\ \ defaults,allow_other,use_ino\ \ \ 0\ \ \ \ \ \ \ 0
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
@@ -249,6 +342,26 @@ As you can see above the size of a read or write can massively impact
|
||||
theoretical performance.
|
||||
If an application performs much worse through mergerfs it could very
|
||||
well be that it doesn\[aq]t optimally size its read and write requests.
|
||||
.SS xattr
|
||||
.PP
|
||||
Runtime extended attribute support can be managed via the \f[C]xattr\f[]
|
||||
option.
|
||||
By default it will passthrough any xattr calls.
|
||||
Given xattr support is rarely used and can have significant performance
|
||||
implications mergerfs allows it to be disabled at runtime.
|
||||
.PP
|
||||
\f[C]noattr\f[] will cause mergerfs to short circuit all xattr calls and
|
||||
return ENOATTR where appropriate.
|
||||
mergerfs still gets all the requests but they will not be forwarded on
|
||||
to the underlying filesystems.
|
||||
The runtime control will still function in this mode.
|
||||
.PP
|
||||
\f[C]notsup\f[] will cause mergerfs to return ENOTSUP for any xattr
|
||||
call.
|
||||
The difference with \f[C]noattr\f[] is that the kernel will cache this
|
||||
fact and itself short circuit future calls.
|
||||
This will be more efficient than \f[C]noattr\f[] but will cause
|
||||
mergerfs\[aq] runtime control via the hidden file to stop working.
|
||||
.SH FUNCTIONS / POLICIES / CATEGORIES
|
||||
.PP
|
||||
The POSIX filesystem API has a number of functions.
|
||||
@@ -267,6 +380,14 @@ Policies, when called to create, will ignore drives which are readonly.
|
||||
This allows for readonly and read/write drives to be mixed together.
|
||||
Note that the drive must be explicitly mounted with the \f[B]ro\f[]
|
||||
mount option for this to work.
|
||||
.PP
|
||||
When using policies which are based on a device\[aq]s available space
|
||||
the base path provided is used.
|
||||
Not the full path to the file in question.
|
||||
Meaning that sub mounts won\[aq]t be considered in the space
|
||||
calculations.
|
||||
The reason is that it doesn\[aq]t really work for non\-path preserving
|
||||
policies and can lead to non\-obvious behaviors.
|
||||
.SS Function / Category classifications
|
||||
.PP
|
||||
.TS
|
||||
@@ -318,13 +439,22 @@ All policies which start with \f[C]ep\f[] (\f[B]epff\f[],
|
||||
\f[C]path\ preserving\f[].
|
||||
\f[C]ep\f[] stands for \f[C]existing\ path\f[].
|
||||
.PP
|
||||
As the descriptions explain a path preserving policy will only consider
|
||||
drives where the relative path being accessed already exists.
|
||||
A path preserving policy will only consider drives where the relative
|
||||
path being accessed already exists.
|
||||
.PP
|
||||
When using non\-path preserving policies where something is created
|
||||
paths will be copied to target drives as necessary.
|
||||
When using non\-path preserving policies paths will be cloned to target
|
||||
drives as necessary.
|
||||
.SS Policy descriptions
|
||||
.PP
|
||||
All \f[B]create\f[] policies will filter out branches which are mounted
|
||||
\f[B]read only\f[] or tagged as \f[B]read only\f[] or \f[B]no
|
||||
create\f[].
|
||||
All \f[B]action\f[] policies will filter out branches which are mounted
|
||||
or tagged as \f[B]read only\f[].
|
||||
.PP
|
||||
If all branches are filtered an error will be returned.
|
||||
Typically EROFS or ENOSPC.
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
lw(16.6n) lw(53.4n).
|
||||
@@ -340,9 +470,9 @@ T}@T{
|
||||
Search category: acts like \f[B]ff\f[].
|
||||
Action category: apply to all found.
|
||||
Create category: for \f[B]mkdir\f[], \f[B]mknod\f[], and
|
||||
\f[B]symlink\f[] it will apply to all found.
|
||||
\f[B]symlink\f[] it will apply to all branches.
|
||||
\f[B]create\f[] works like \f[B]ff\f[].
|
||||
It will exclude readonly drives and those with free space less than
|
||||
It will exclude branches with free space less than
|
||||
\f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
@@ -353,8 +483,7 @@ Action category: apply to all found.
|
||||
Create category: for \f[B]mkdir\f[], \f[B]mknod\f[], and
|
||||
\f[B]symlink\f[] it will apply to all existing paths found.
|
||||
\f[B]create\f[] works like \f[B]epff\f[].
|
||||
Excludes readonly drives and those with free space less than
|
||||
\f[B]minfreespace\f[].
|
||||
Excludes branches with free space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
epff (existing path, first found)
|
||||
@@ -362,37 +491,32 @@ T}@T{
|
||||
Given the order of the drives, as defined at mount time or configured at
|
||||
runtime, act on the first one found where the relative path already
|
||||
exists.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[] (unless there
|
||||
is no other option).
|
||||
Falls back to \f[B]ff\f[].
|
||||
For \f[B]create\f[] category functions it will exclude branches with
|
||||
free space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
eplfs (existing path, least free space)
|
||||
T}@T{
|
||||
Of all the drives on which the relative path exists choose the drive
|
||||
with the least free space.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]lfs\f[].
|
||||
For \f[B]create\f[] category functions it will exclude those with free
|
||||
space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
eplus (existing path, least used space)
|
||||
T}@T{
|
||||
Of all the drives on which the relative path exists choose the drive
|
||||
with the least used space.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]lus\f[].
|
||||
For \f[B]create\f[] category functions it will exclude those with free
|
||||
space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
epmfs (existing path, most free space)
|
||||
T}@T{
|
||||
Of all the drives on which the relative path exists choose the drive
|
||||
with the most free space.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]mfs\f[].
|
||||
For \f[B]create\f[] category functions it will exclude those with free
|
||||
space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
eprand (existing path, random)
|
||||
@@ -405,48 +529,40 @@ erofs
|
||||
T}@T{
|
||||
Exclusively return \f[B]\-1\f[] with \f[B]errno\f[] set to
|
||||
\f[B]EROFS\f[] (Read\-only filesystem).
|
||||
By setting \f[B]create\f[] functions to this you can in effect turn the
|
||||
filesystem mostly readonly.
|
||||
T}
|
||||
T{
|
||||
ff (first found)
|
||||
T}@T{
|
||||
Given the order of the drives, as defined at mount time or configured at
|
||||
runtime, act on the first one found.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[] (unless there
|
||||
is no other option).
|
||||
For \f[B]create\f[] category functions it will exclude those with free
|
||||
space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
lfs (least free space)
|
||||
T}@T{
|
||||
Pick the drive with the least available free space.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]mfs\f[].
|
||||
For \f[B]create\f[] category functions it will exclude those with free
|
||||
space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
lus (least used space)
|
||||
T}@T{
|
||||
Pick the drive with the least used space.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]mfs\f[].
|
||||
For \f[B]create\f[] category functions it will exclude those with free
|
||||
space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
mfs (most free space)
|
||||
T}@T{
|
||||
Pick the drive with the most available free space.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives.
|
||||
Falls back to \f[B]ff\f[].
|
||||
T}
|
||||
T{
|
||||
newest
|
||||
T}@T{
|
||||
Pick the file / directory with the largest mtime.
|
||||
For \f[B]create\f[] category functions it will exclude readonly drives
|
||||
and those with free space less than \f[B]minfreespace\f[] (unless there
|
||||
is no other option).
|
||||
For \f[B]create\f[] category functions it will exclude those with free
|
||||
space less than \f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
rand (random)
|
||||
@@ -468,7 +584,7 @@ _
|
||||
T{
|
||||
action
|
||||
T}@T{
|
||||
all
|
||||
epall
|
||||
T}
|
||||
T{
|
||||
create
|
||||
@@ -599,6 +715,8 @@ This means you will see the combined space of all sources.
|
||||
Total, used, and free.
|
||||
The sources however are dedupped based on the drive so multiple sources
|
||||
on the same drive will not result in double counting it\[aq]s space.
|
||||
Filesystems mounted further down the tree of the branch will not be
|
||||
included.
|
||||
.SH BUILDING
|
||||
.PP
|
||||
\f[B]NOTE:\f[] Prebuilt packages can be found at:
|
||||
@@ -621,7 +739,7 @@ $\ sudo\ apt\-get\ \-y\ update
|
||||
$\ sudo\ apt\-get\ \-y\ install\ git\ make
|
||||
$\ cd\ mergerfs
|
||||
$\ make\ install\-build\-pkgs
|
||||
$\ #\ build\-essential\ git\ g++\ debhelper\ libattr1\-dev\ python\ automake\ libtool\ lsb\-release
|
||||
$\ #\ build\-essential\ git\ g++\ debhelper\ python\ automake\ libtool\ lsb\-release
|
||||
$\ make\ deb
|
||||
$\ sudo\ dpkg\ \-i\ ../mergerfs_version_arch.deb
|
||||
\f[]
|
||||
@@ -635,14 +753,14 @@ $\ su\ \-
|
||||
#\ dnf\ \-y\ install\ git\ make
|
||||
#\ cd\ mergerfs
|
||||
#\ make\ install\-build\-pkgs
|
||||
#\ #\ rpm\-build\ libattr\-devel\ gcc\-c++\ which\ python\ automake\ libtool\ gettext\-devel
|
||||
#\ #\ rpm\-build\ gcc\-c++\ which\ python\ automake\ libtool\ gettext\-devel
|
||||
#\ make\ rpm
|
||||
#\ rpm\ \-i\ rpmbuild/RPMS/<arch>/mergerfs\-<verion>.<arch>.rpm
|
||||
\f[]
|
||||
.fi
|
||||
.SS Generically
|
||||
.PP
|
||||
Have git, g++, make, python, libattr1, automake, libtool installed.
|
||||
Have git, g++, make, python, automake, libtool installed.
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
@@ -651,8 +769,24 @@ $\ make
|
||||
$\ sudo\ make\ install
|
||||
\f[]
|
||||
.fi
|
||||
.SS Generically with system libfuse
|
||||
.PP
|
||||
\f[B]NOTE:\f[] Configurable threading and thus \f[C]\-o\ threads=num\f[]
|
||||
option will be unavailable when built with system libfuse.
|
||||
.PP
|
||||
Have git, g++, make, python, pkg\-config installed.
|
||||
Also, install libfuse >= 2.9.7 (but not libfuse\-3.x) and matching
|
||||
libfuse\-dev (or libfuse\-devel).
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$\ cd\ mergerfs
|
||||
$\ make\ INTERNAL_FUSE=0
|
||||
$\ sudo\ make\ INTERNAL_FUSE=0\ install
|
||||
\f[]
|
||||
.fi
|
||||
.SH RUNTIME
|
||||
.SS \&.mergerfs pseudo file
|
||||
.SS .mergerfs pseudo file
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
@@ -666,19 +800,18 @@ The file will not show up in \f[B]readdir\f[] but can be
|
||||
\f[B]stat\f[]\[aq]ed and manipulated via
|
||||
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls.
|
||||
.PP
|
||||
Even if xattrs are disabled for mergerfs the
|
||||
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls
|
||||
against this pseudo file will still work.
|
||||
.PP
|
||||
Any changes made at runtime are \f[B]not\f[] persisted.
|
||||
If you wish for values to persist they must be included as options
|
||||
wherever you configure the mounting of mergerfs (fstab).
|
||||
wherever you configure the mounting of mergerfs (/etc/fstab).
|
||||
.SS Keys
|
||||
.PP
|
||||
Use \f[C]xattr\ \-l\ /mount/point/.mergerfs\f[] to see all supported
|
||||
keys.
|
||||
Some are informational and therefore readonly.
|
||||
.SS user.mergerfs.srcmounts
|
||||
.SS user.mergerfs.branches
|
||||
.PP
|
||||
\f[B]NOTE:\f[] formerly \f[C]user.mergerfs.srcmounts\f[] but said key is
|
||||
still supported.
|
||||
.PP
|
||||
Used to query or modify the list of source mounts.
|
||||
When modifying there are several shortcuts to easy manipulation of the
|
||||
@@ -724,6 +857,8 @@ T}@T{
|
||||
remove last in list
|
||||
T}
|
||||
.TE
|
||||
.PP
|
||||
\f[C]xattr\ \-w\ user.mergerfs.branches\ +</mnt/drive3\ /mnt/pool/.mergerfs\f[]
|
||||
.SS minfreespace
|
||||
.PP
|
||||
Input: interger with an optional multiplier suffix.
|
||||
@@ -746,30 +881,30 @@ In that case it will be a comma separated list
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-l\ .mergerfs
|
||||
user.mergerfs.srcmounts:\ /tmp/a:/tmp/b
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-l\ .mergerfs
|
||||
user.mergerfs.branches:\ /mnt/a:/mnt/b
|
||||
user.mergerfs.minfreespace:\ 4294967295
|
||||
user.mergerfs.moveonenospc:\ false
|
||||
\&...
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
|
||||
ff
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.category.search\ newest\ .mergerfs
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-w\ user.mergerfs.category.search\ newest\ .mergerfs
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
|
||||
newest
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ +/tmp/c\ .mergerfs
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-w\ user.mergerfs.branches\ +/mnt/c\ .mergerfs
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.branches\ .mergerfs
|
||||
/mnt/a:/mnt/b:/mnt/c
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ =/tmp/c\ .mergerfs
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
|
||||
/tmp/c
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-w\ user.mergerfs.branches\ =/mnt/c\ .mergerfs
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.branches\ .mergerfs
|
||||
/mnt/c
|
||||
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ \[aq]+</tmp/a:/tmp/b\[aq]\ .mergerfs
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-w\ user.mergerfs.branches\ \[aq]+</mnt/a:/mnt/b\[aq]\ .mergerfs
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.branches\ .mergerfs
|
||||
/mnt/a:/mnt/b:/mnt/c
|
||||
\f[]
|
||||
.fi
|
||||
.SS file / directory xattrs
|
||||
@@ -795,15 +930,15 @@ full paths to all files found
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
[trapexit:/tmp/mount]\ $\ ls
|
||||
[trapexit:/mnt/mergerfs]\ $\ ls
|
||||
A\ B\ C
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.fullpath\ A
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.fullpath\ A
|
||||
/mnt/a/full/path/to/A
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.basepath\ A
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.basepath\ A
|
||||
/mnt/a
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.relpath\ A
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.relpath\ A
|
||||
/full/path/to/A
|
||||
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.allpaths\ A\ |\ tr\ \[aq]\\0\[aq]\ \[aq]\\n\[aq]
|
||||
[trapexit:/mnt/mergerfs]\ $\ xattr\ \-p\ user.mergerfs.allpaths\ A\ |\ tr\ \[aq]\\0\[aq]\ \[aq]\\n\[aq]
|
||||
/mnt/a/full/path/to/A
|
||||
/mnt/b/full/path/to/A
|
||||
\f[]
|
||||
@@ -820,6 +955,9 @@ ability to fix them
|
||||
.IP \[bu] 2
|
||||
mergerfs.dedup: Will help identify and optionally remove duplicate files
|
||||
.IP \[bu] 2
|
||||
mergerfs.dup: Ensure there are at least N copies of a file across the
|
||||
pool
|
||||
.IP \[bu] 2
|
||||
mergerfs.balance: Rebalance files across drives by moving them from the
|
||||
most filled to the least filled
|
||||
.IP \[bu] 2
|
||||
@@ -828,7 +966,8 @@ directories on a mergerfs mount
|
||||
.IP \[bu] 2
|
||||
https://github.com/trapexit/scorch
|
||||
.IP \[bu] 2
|
||||
scorch: A tool to help discover silent corruption of files
|
||||
scorch: A tool to help discover silent corruption of files and keep
|
||||
track of files
|
||||
.IP \[bu] 2
|
||||
https://github.com/trapexit/bbf
|
||||
.IP \[bu] 2
|
||||
@@ -934,7 +1073,7 @@ done
|
||||
.fi
|
||||
.SH TIPS / NOTES
|
||||
.IP \[bu] 2
|
||||
The recommended options are
|
||||
The recommended base options are
|
||||
\f[B]defaults,allow_other,direct_io,use_ino\f[].
|
||||
(\f[B]use_ino\f[] will only work when used with mergerfs 2.18.0 and
|
||||
above.)
|
||||
@@ -952,9 +1091,11 @@ all the underlying directories.
|
||||
Use \f[C]mergerfs.fsck\f[] to audit the drive for out of sync
|
||||
permissions.
|
||||
.IP \[bu] 2
|
||||
Do \f[I]not\f[] use \f[C]direct_io\f[] if you expect applications (such
|
||||
Do \f[B]not\f[] use \f[C]direct_io\f[] if you expect applications (such
|
||||
as rtorrent) to mmap (http://linux.die.net/man/2/mmap) files.
|
||||
It is not currently supported in FUSE w/ \f[C]direct_io\f[] enabled.
|
||||
Enabling \f[C]dropcacheonclose\f[] is recommended when
|
||||
\f[C]direct_io\f[] is disabled.
|
||||
.IP \[bu] 2
|
||||
Since POSIX gives you only error or success on calls its difficult to
|
||||
determine the proper behavior when applying the behavior to multiple
|
||||
@@ -970,7 +1111,7 @@ can use directory mtime (http://linux.die.net/man/2/stat) to more
|
||||
efficiently determine whether to scan for new content rather than simply
|
||||
performing a full scan.
|
||||
If using the default \f[B]getattr\f[] policy of \f[B]ff\f[] its possible
|
||||
\f[B]Kodi\f[] will miss an update on account of it returning the first
|
||||
those programs will miss an update on account of it returning the first
|
||||
directory found\[aq]s \f[B]stat\f[] info and its a later directory on
|
||||
another mount which had the \f[B]mtime\f[] recently updated.
|
||||
To fix this you will want to set \f[B]func.getattr=newest\f[].
|
||||
@@ -982,7 +1123,7 @@ directory could be acted on.
|
||||
Some policies mixed with some functions may result in strange behaviors.
|
||||
Not that some of these behaviors and race conditions couldn\[aq]t happen
|
||||
outside \f[B]mergerfs\f[] but that they are far more likely to occur on
|
||||
account of attempt to merge together multiple sources of data which
|
||||
account of the attempt to merge together multiple sources of data which
|
||||
could be out of sync due to the different policies.
|
||||
.IP \[bu] 2
|
||||
For consistency its generally best to set \f[B]category\f[] wide
|
||||
@@ -1125,6 +1266,9 @@ which many probably do.
|
||||
To create a \f[C]$topdir/.Trash\f[] directory as defined in the standard
|
||||
use the mergerfs\-tools (https://github.com/trapexit/mergerfs-tools)
|
||||
tool \f[C]mergerfs.mktrash\f[].
|
||||
.SS tar: Directory renamed before its status could be extracted
|
||||
.PP
|
||||
Make sure to use the \f[C]use_ino\f[] option.
|
||||
.SS Supplemental user groups
|
||||
.PP
|
||||
Due to the overhead of
|
||||
@@ -1161,7 +1305,7 @@ Note that doing so will increase the memory needed by each thread.
|
||||
.SS mergerfs or libfuse crashing
|
||||
.PP
|
||||
\f[B]NOTE:\f[] as of mergerfs 2.22.0 it includes the most recent version
|
||||
of libfuse so any crash should be reported.
|
||||
of libfuse (or requires libfuse\-2.9.7) so any crash should be reported.
|
||||
For older releases continue reading...
|
||||
.PP
|
||||
If suddenly the mergerfs mount point disappears and
|
||||
@@ -1236,7 +1380,117 @@ mergerfs\[aq] options.
|
||||
Should be placed after \f[C]defaults\f[] if it is used since it will
|
||||
turn them on.
|
||||
This however is not guaranteed to work.
|
||||
.SS rm: fts_read failed: No such file or directory
|
||||
.PP
|
||||
Not \f[I]really\f[] a bug.
|
||||
The FUSE library will move files when asked to delete them as a way to
|
||||
deal with certain edge cases and then later delete that file when its
|
||||
clear the file is no longer needed.
|
||||
This however can lead to two issues.
|
||||
One is that these hidden files are noticed by \f[C]rm\ \-rf\f[] or
|
||||
\f[C]find\f[] when scanning directories and they may try to remove them
|
||||
and they might have disappeared already.
|
||||
There is nothing \f[I]wrong\f[] about this happening but it can be
|
||||
annoying.
|
||||
The second issue is that a directory might not be able to removed on
|
||||
account of the hidden file being still there.
|
||||
.PP
|
||||
Using the \f[B]hard_remove\f[] option will make it so these temporary
|
||||
files are not used and files are deleted immedately.
|
||||
That has a side effect however.
|
||||
Files which are unlinked and then they are still used (in certain forms)
|
||||
will result in an error.
|
||||
.SH FAQ
|
||||
.SS How well does mergerfs scale? Is it "production ready?"
|
||||
.PP
|
||||
Users have reported running mergerfs on everything from a Raspberry Pi
|
||||
to dual socket Xeon systems with >20 cores.
|
||||
I\[aq]m aware of at least a few companies which use mergerfs in
|
||||
production.
|
||||
Open Media Vault (https://www.openmediavault.org) includes mergerfs is
|
||||
it\[aq]s sole solution for pooling drives.
|
||||
.SS Can mergerfs be used with drives which already have data / are in
|
||||
use?
|
||||
.PP
|
||||
Yes.
|
||||
MergerFS is a proxy and does \f[B]NOT\f[] interfere with the normal form
|
||||
or function of the drives / mounts / paths it manages.
|
||||
.PP
|
||||
MergerFS is \f[B]not\f[] a traditional filesystem.
|
||||
MergerFS is \f[B]not\f[] RAID.
|
||||
It does \f[B]not\f[] manipulate the data that passes through it.
|
||||
It does \f[B]not\f[] shard data across drives.
|
||||
It merely shards some \f[B]behavior\f[] and aggregates others.
|
||||
.SS Can mergerfs be removed without affecting the data?
|
||||
.PP
|
||||
See the previous question\[aq]s answer.
|
||||
.SS Do hard links work?
|
||||
.PP
|
||||
Yes.
|
||||
You need to use \f[C]use_ino\f[] to support proper reporting of inodes.
|
||||
Read the section "rename & link" for caveats.
|
||||
.SS Does mergerfs support CoW / copy\-on\-write?
|
||||
.PP
|
||||
Not in the sense of a filesystem like BTRFS or ZFS nor in the overlayfs
|
||||
or aufs sense.
|
||||
It does offer a
|
||||
cow\-shell (http://manpages.ubuntu.com/manpages/bionic/man1/cow-shell.1.html)
|
||||
like hardlink breaking (copy to temp file then rename over original)
|
||||
which can be useful when wanting to save space by hardlinking duplicate
|
||||
files but wish to treat each name as if it were a unique and separate
|
||||
file.
|
||||
.SS Why can\[aq]t I see my files / directories?
|
||||
.PP
|
||||
It\[aq]s almost always a permissions issue.
|
||||
Unlike mhddfs, which runs as root and attempts to access content as
|
||||
such, mergerfs always changes it\[aq]s credentials to that of the
|
||||
caller.
|
||||
This means that if the user does not have access to a file or directory
|
||||
than neither will mergerfs.
|
||||
However, because mergerfs is creating a union of paths it may be able to
|
||||
read some files and directories on one drive but not another resulting
|
||||
in an incomplete set.
|
||||
.PP
|
||||
Whenever you run into a split permission issue (seeing some but not all
|
||||
files) try using
|
||||
mergerfs.fsck (https://github.com/trapexit/mergerfs-tools) tool to check
|
||||
for and fix the mismatch.
|
||||
If you aren\[aq]t seeing anything at all be sure that the basic
|
||||
permissions are correct.
|
||||
The user and group values are correct and that directories have their
|
||||
executable bit set.
|
||||
A common mistake by users new to Linux is to \f[C]chmod\ \-R\ 644\f[]
|
||||
when they should have \f[C]chmod\ \-R\ u=rwX,go=rX\f[].
|
||||
.PP
|
||||
If using a network filesystem such as NFS, SMB, CIFS (Samba) be sure to
|
||||
pay close attention to anything regarding permissioning and users.
|
||||
Root squashing and user translation for instance has bitten a few
|
||||
mergerfs users.
|
||||
Some of these also affect the use of mergerfs from container platforms
|
||||
such as Docker.
|
||||
.SS Why is only one drive being used?
|
||||
.PP
|
||||
Are you using a path preserving policy?
|
||||
The default policy for file creation is \f[C]epmfs\f[].
|
||||
That means only the drives with the path preexisting will be considered
|
||||
when creating a file.
|
||||
If you don\[aq]t care about where files and directories are created you
|
||||
likely shouldn\[aq]t be using a path preserving policy and instead
|
||||
something like \f[C]mfs\f[].
|
||||
.PP
|
||||
This can be especially apparent when filling an empty pool from an
|
||||
external source.
|
||||
If you do want path preservation you\[aq]ll need to perform the manual
|
||||
act of creating paths on the drives you want the data to land on before
|
||||
transfering your data.
|
||||
.SS Why was libfuse embedded into mergerfs?
|
||||
.PP
|
||||
A significant number of users use mergerfs on distros with very old
|
||||
versions of libfuse which have serious bugs.
|
||||
Requiring updated versions of libfuse on those distros isn\[aq]t
|
||||
pratical (no package offered, user inexperience, etc.).
|
||||
The only practical way to provide a stable runtime on those systems was
|
||||
to "vendor" the library into the project.
|
||||
.SS Why use mergerfs over mhddfs?
|
||||
.PP
|
||||
mhddfs is no longer maintained and has some known stability and security
|
||||
@@ -1244,21 +1498,33 @@ issues (see below).
|
||||
MergerFS provides a superset of mhddfs\[aq] features and should offer
|
||||
the same or maybe better performance.
|
||||
.PP
|
||||
If you wish to get similar behavior to mhddfs from mergerfs then set
|
||||
\f[C]category.create=ff\f[].
|
||||
Below is an example of mhddfs and mergerfs setup to work similarly.
|
||||
.PP
|
||||
\f[C]mhddfs\ \-o\ mlimit=4G,allow_other\ /mnt/drive1,/mnt/drive2\ /mnt/pool\f[]
|
||||
.PP
|
||||
\f[C]mergerfs\ \-o\ minfreespace=4G,defaults,allow_other,category.create=ff\ /mnt/drive1:/mnt/drive2\ /mnt/pool\f[]
|
||||
.SS Why use mergerfs over aufs?
|
||||
.PP
|
||||
aufs is mostly abandoned and no longer available in many distros.
|
||||
.PP
|
||||
While aufs can offer better peak performance mergerfs provides more
|
||||
configurability and is generally easier to use.
|
||||
mergerfs however does not offer the overlay / copy\-on\-write (COW)
|
||||
mergerfs however does not offer the overlay / copy\-on\-write (CoW)
|
||||
features which aufs and overlayfs have.
|
||||
.SS Why use mergerfs over unionfs?
|
||||
.PP
|
||||
UnionFS is more like aufs then mergerfs in that it offers overlay / CoW
|
||||
features.
|
||||
If you\[aq]re just looking to create a union of drives and want
|
||||
flexibility in file/directory placement then mergerfs offers that
|
||||
whereas unionfs is more for overlaying RW filesystems over RO ones.
|
||||
.SS Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation /
|
||||
striping?
|
||||
.PP
|
||||
With simple JBOD / drive concatenation / stripping / RAID0 a single
|
||||
drive failure will result in full pool failure.
|
||||
mergerfs performs a similar behavior without the possibility of
|
||||
catastrophic failure and difficulties in recovery.
|
||||
catastrophic failure and the difficulties in recovery.
|
||||
Drives may fail however all other data will continue to be accessable.
|
||||
.PP
|
||||
When combined with something like SnapRaid (http://www.snapraid.it)
|
||||
@@ -1291,8 +1557,9 @@ contents of the pooled drives.
|
||||
The reported free space is the aggregate space available \f[B]not\f[]
|
||||
the contiguous space available.
|
||||
MergerFS does not split files across drives.
|
||||
If the writing of a file fills a drive and \f[B]moveonenospc\f[] is
|
||||
disabled it will return an ENOSPC error.
|
||||
If the writing of a file fills an underlying drive and
|
||||
\f[B]moveonenospc\f[] is disabled it will return an ENOSPC (No space
|
||||
left on device) error.
|
||||
.PP
|
||||
If \f[B]moveonenospc\f[] is enabled but there exists no drives with
|
||||
enough space for the file and the data to be written (or the drive
|
||||
@@ -1314,6 +1581,8 @@ will not be presented but users have found that enabling the
|
||||
.SS Can mergerfs mounts be exported over Samba / SMB?
|
||||
.PP
|
||||
Yes.
|
||||
While some users have reported problems it appears to always be related
|
||||
to how Samba is setup in relation to permissions.
|
||||
.SS How are inodes calculated?
|
||||
.PP
|
||||
mergerfs\-inode = (original\-inode | (device\-id << 32))
|
||||
@@ -1324,6 +1593,55 @@ bits.
|
||||
Bitwise or\[aq]ing them together should work most of the time.
|
||||
While totally unique inodes are preferred the overhead which would be
|
||||
needed does not seem to outweighted by the benefits.
|
||||
.PP
|
||||
While atypical, yes, inodes can be reused and not refer to the same
|
||||
file.
|
||||
The internal id used to reference a file in FUSE is different from the
|
||||
inode value presented.
|
||||
The former is the \f[C]nodeid\f[] and is actually a tuple of
|
||||
(nodeid,generation).
|
||||
That tuple is not user facing.
|
||||
The inode is merely metadata passed through the kernel and found using
|
||||
the \f[C]stat\f[] family of calls or \f[C]readdir\f[].
|
||||
.PP
|
||||
From FUSE docs regarding \f[C]use_ino\f[]:
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
Honor\ the\ st_ino\ field\ in\ the\ functions\ getattr()\ and
|
||||
fill_dir().\ This\ value\ is\ used\ to\ fill\ in\ the\ st_ino\ field
|
||||
in\ the\ stat(2),\ lstat(2),\ fstat(2)\ functions\ and\ the\ d_ino
|
||||
field\ in\ the\ readdir(2)\ function.\ The\ filesystem\ does\ not
|
||||
have\ to\ guarantee\ uniqueness,\ however\ some\ applications
|
||||
rely\ on\ this\ value\ being\ unique\ for\ the\ whole\ filesystem.
|
||||
Note\ that\ this\ does\ *not*\ affect\ the\ inode\ that\ libfuse
|
||||
and\ the\ kernel\ use\ internally\ (also\ called\ the\ "nodeid").
|
||||
\f[]
|
||||
.fi
|
||||
.SS I notice massive slowdowns of writes over NFS
|
||||
.PP
|
||||
Due to how NFS works and interacts with FUSE when not using
|
||||
\f[C]direct_io\f[] its possible that a getxattr for
|
||||
\f[C]security.capability\f[] will be issued prior to any write.
|
||||
This will usually result in a massive slowdown for writes.
|
||||
Using \f[C]direct_io\f[] will keep this from happening (and generally
|
||||
good to enable unless you need the features it disables) but the
|
||||
\f[C]security_capability\f[] option can also help by short circuiting
|
||||
the call and returning \f[C]ENOATTR\f[].
|
||||
.PP
|
||||
You could also set \f[C]xattr\f[] to \f[C]noattr\f[] or \f[C]notsup\f[]
|
||||
to short circuit or stop all xattr requests.
|
||||
.SS What are these .fuse_hidden files?
|
||||
.PP
|
||||
When not using \f[C]hard_remove\f[] libfuse will create
|
||||
\&.fuse_hiddenXXXXXXXX files when an opened file is unlinked.
|
||||
This is to simplify "use after unlink" usecases.
|
||||
There is a possibility these files end up being picked up by software
|
||||
scanning directories and not ignoring hidden files.
|
||||
This is rarely a problem but a solution is in the works.
|
||||
.PP
|
||||
The files are cleaned up once the file is finally closed.
|
||||
Only if mergerfs crashes or is killed would they be left around.
|
||||
.SS It\[aq]s mentioned that there are some security issues with mhddfs.
|
||||
What are they? How does mergerfs address them?
|
||||
.PP
|
||||
@@ -1361,8 +1679,69 @@ If the ability to give writers priority is supported then that flag will
|
||||
be used so threads trying to change credentials don\[aq]t starve.
|
||||
This isn\[aq]t the best solution but should work reasonably well
|
||||
assuming there are few users.
|
||||
.SH PERFORMANCE TWEAKING
|
||||
.IP \[bu] 2
|
||||
try adding (or removing) \f[C]direct_io\f[]
|
||||
.IP \[bu] 2
|
||||
try adding (or removing) \f[C]auto_cache\f[] / \f[C]noauto_cache\f[]
|
||||
(included in \f[C]defaults\f[])
|
||||
.IP \[bu] 2
|
||||
try adding (or removing) \f[C]kernel_cache\f[] (don\[aq]t use the
|
||||
underlying filesystems directly if enabling \f[C]kernel_cache\f[])
|
||||
.IP \[bu] 2
|
||||
try adding (or removing) \f[C]splice_move\f[], \f[C]splice_read\f[], and
|
||||
\f[C]splice_write\f[] (all three included in \f[C]defaults\f[])
|
||||
.IP \[bu] 2
|
||||
try changing the number of worker threads
|
||||
.IP \[bu] 2
|
||||
try disabling \f[C]security_capability\f[] or \f[C]xattr\f[]
|
||||
.IP \[bu] 2
|
||||
test theoretical performance using \f[C]nullrw\f[] or mounting a ram
|
||||
disk
|
||||
.IP \[bu] 2
|
||||
use \f[C]symlinkify\f[] if your data is largely static and you need
|
||||
native speed reads
|
||||
.IP \[bu] 2
|
||||
use lvm and lvm cache to place a SSD in front of your HDDs (howto
|
||||
coming)
|
||||
.SH SUPPORT
|
||||
.SS Issues with the software
|
||||
.PP
|
||||
Filesystems are very complex and difficult to debug.
|
||||
mergerfs, while being just a proxy of sorts, is also very difficult to
|
||||
debug given the large number of possible settings it can have itself and
|
||||
the massive number of environments it can run in.
|
||||
When reporting on a suspected issue \f[B]please, please\f[] include as
|
||||
much of the below information as possible otherwise it will be difficult
|
||||
or impossible to diagnose.
|
||||
Also please make sure to read all of the above documentation as it
|
||||
includes nearly every known system or user issue previously encountered.
|
||||
.SS Information to include in bug reports
|
||||
.IP \[bu] 2
|
||||
Version of mergerfs: \f[C]mergerfs\ \-V\f[]
|
||||
.IP \[bu] 2
|
||||
mergerfs settings: from \f[C]/etc/fstab\f[] or command line execution
|
||||
.IP \[bu] 2
|
||||
Version of Linux: \f[C]uname\ \-a\f[]
|
||||
.IP \[bu] 2
|
||||
Versions of any additional software being used
|
||||
.IP \[bu] 2
|
||||
List of drives, their filesystems, and sizes (before and after issue):
|
||||
\f[C]df\ \-h\f[]
|
||||
.IP \[bu] 2
|
||||
A \f[C]strace\f[] of the app having problems:
|
||||
.IP \[bu] 2
|
||||
\f[C]strace\ \-f\ \-o\ /tmp/app.strace.txt\ <cmd>\f[]
|
||||
.IP \[bu] 2
|
||||
A \f[C]strace\f[] of mergerfs while the program is trying to do whatever
|
||||
it\[aq]s failing to do:
|
||||
.IP \[bu] 2
|
||||
\f[C]strace\ \-f\ \-p\ <mergerfsPID>\ \-o\ /tmp/mergerfs.strace.txt\f[]
|
||||
.IP \[bu] 2
|
||||
\f[B]Precise\f[] directions on replicating the issue.
|
||||
Do not leave \f[B]anything\f[] out.
|
||||
.IP \[bu] 2
|
||||
Try to recreate the problem in the simplist way using standard programs.
|
||||
.SS Contact / Issue submission
|
||||
.IP \[bu] 2
|
||||
github.com: https://github.com/trapexit/mergerfs/issues
|
||||
.IP \[bu] 2
|
||||
@@ -1370,14 +1749,24 @@ email: trapexit\@spawn.link
|
||||
.IP \[bu] 2
|
||||
twitter: https://twitter.com/_trapexit
|
||||
.SS Support development
|
||||
.PP
|
||||
This software is free to use and released under a very liberal license.
|
||||
That said if you like this software and would like to support its
|
||||
development donations are welcome.
|
||||
.IP \[bu] 2
|
||||
BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
Bitcoin (BTC): 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
.IP \[bu] 2
|
||||
Bitcoin Cash (BCH): 1AjPqZZhu7GVEs6JFPjHmtsvmDL4euzMzp
|
||||
.IP \[bu] 2
|
||||
Ethereum (ETH): 0x09A166B11fCC127324C7fc5f1B572255b3046E94
|
||||
.IP \[bu] 2
|
||||
Litecoin (LTC): LXAsq6yc6zYU3EbcqyWtHBrH1Ypx4GjUjm
|
||||
.IP \[bu] 2
|
||||
Ripple (XRP): rNACR2hqGjpbHuCKwmJ4pDpd2zRfuRATcE
|
||||
.IP \[bu] 2
|
||||
PayPal: trapexit\@spawn.link
|
||||
.IP \[bu] 2
|
||||
Patreon: https://www.patreon.com/trapexit
|
||||
.IP \[bu] 2
|
||||
Gratipay: https://gratipay.com/~trapexit
|
||||
.SH LINKS
|
||||
.IP \[bu] 2
|
||||
http://github.com/trapexit/mergerfs
|
||||
|
||||
@@ -10,7 +10,6 @@ URL: https://github.com/trapexit/mergerfs
|
||||
Source: mergerfs-%{version}.tar.gz
|
||||
|
||||
BuildRequires: gcc-c++
|
||||
BuildRequires: libattr-devel
|
||||
# rpmbuild driven by the Makefile uses git to generate a version number
|
||||
BuildRequires: git
|
||||
|
||||
|
||||
+4
-4
@@ -32,7 +32,7 @@ using mergerfs::Category;
|
||||
static
|
||||
int
|
||||
_access(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const int mask)
|
||||
@@ -41,7 +41,7 @@ _access(Policy::Func::Search searchFunc,
|
||||
string fullpath;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = searchFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -63,10 +63,10 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _access(config.access,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mask);
|
||||
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "branch.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_glob.hpp"
|
||||
#include "str.hpp"
|
||||
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
bool
|
||||
Branch::ro(void) const
|
||||
{
|
||||
return (mode == Branch::RO);
|
||||
}
|
||||
|
||||
bool
|
||||
Branch::nc(void) const
|
||||
{
|
||||
return (mode == Branch::NC);
|
||||
}
|
||||
|
||||
bool
|
||||
Branch::ro_or_nc(void) const
|
||||
{
|
||||
return ((mode == Branch::RO) ||
|
||||
(mode == Branch::NC));
|
||||
}
|
||||
|
||||
string
|
||||
Branches::to_string(const bool mode_) const
|
||||
{
|
||||
string tmp;
|
||||
|
||||
for(size_t i = 0; i < size(); i++)
|
||||
{
|
||||
const Branch &branch = (*this)[i];
|
||||
|
||||
tmp += branch.path;
|
||||
|
||||
if(mode_)
|
||||
{
|
||||
tmp += '=';
|
||||
switch(branch.mode)
|
||||
{
|
||||
default:
|
||||
case Branch::RW:
|
||||
tmp += "RW";
|
||||
break;
|
||||
case Branch::RO:
|
||||
tmp += "RO";
|
||||
break;
|
||||
case Branch::NC:
|
||||
tmp += "NC";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tmp += ':';
|
||||
}
|
||||
|
||||
if(*tmp.rbegin() == ':')
|
||||
tmp.erase(tmp.size() - 1);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void
|
||||
Branches::to_paths(vector<string> &vec_) const
|
||||
{
|
||||
for(size_t i = 0; i < size(); i++)
|
||||
{
|
||||
const Branch &branch = (*this)[i];
|
||||
|
||||
vec_.push_back(branch.path);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
parse(const string &str_,
|
||||
Branches &branches_)
|
||||
{
|
||||
string str;
|
||||
Branch branch;
|
||||
vector<string> globbed;
|
||||
|
||||
str = str_;
|
||||
branch.mode = Branch::INVALID;
|
||||
if(str::ends_with(str,"=RO"))
|
||||
branch.mode = Branch::RO;
|
||||
else if(str::ends_with(str,"=RW"))
|
||||
branch.mode = Branch::RW;
|
||||
else if(str::ends_with(str,"=NC"))
|
||||
branch.mode = Branch::NC;
|
||||
|
||||
if(branch.mode != Branch::INVALID)
|
||||
str.resize(str.size() - 3);
|
||||
else
|
||||
branch.mode = Branch::RW;
|
||||
|
||||
fs::glob(str,globbed);
|
||||
fs::realpathize(globbed);
|
||||
for(size_t i = 0; i < globbed.size(); i++)
|
||||
{
|
||||
branch.path = globbed[i];
|
||||
branches_.push_back(branch);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Branches::set(const std::string &str_)
|
||||
{
|
||||
vector<string> paths;
|
||||
|
||||
clear();
|
||||
|
||||
str::split(paths,str_,':');
|
||||
|
||||
for(size_t i = 0; i < paths.size(); i++)
|
||||
{
|
||||
Branches branches;
|
||||
|
||||
parse(paths[i],branches);
|
||||
|
||||
insert(end(),
|
||||
branches.begin(),
|
||||
branches.end());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Branches::add_begin(const std::string &str_)
|
||||
{
|
||||
vector<string> paths;
|
||||
|
||||
str::split(paths,str_,':');
|
||||
|
||||
for(size_t i = 0; i < paths.size(); i++)
|
||||
{
|
||||
Branches branches;
|
||||
|
||||
parse(paths[i],branches);
|
||||
|
||||
insert(begin(),
|
||||
branches.begin(),
|
||||
branches.end());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Branches::add_end(const std::string &str_)
|
||||
{
|
||||
vector<string> paths;
|
||||
|
||||
str::split(paths,str_,':');
|
||||
|
||||
for(size_t i = 0; i < paths.size(); i++)
|
||||
{
|
||||
Branches branches;
|
||||
|
||||
parse(paths[i],branches);
|
||||
|
||||
insert(end(),
|
||||
branches.begin(),
|
||||
branches.end());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Branches::erase_begin(void)
|
||||
{
|
||||
erase(begin());
|
||||
}
|
||||
|
||||
void
|
||||
Branches::erase_end(void)
|
||||
{
|
||||
pop_back();
|
||||
}
|
||||
|
||||
void
|
||||
Branches::erase_fnmatch(const std::string &str_)
|
||||
{
|
||||
vector<string> patterns;
|
||||
|
||||
str::split(patterns,str_,':');
|
||||
|
||||
for(iterator i = begin(); i != end();)
|
||||
{
|
||||
int match = FNM_NOMATCH;
|
||||
|
||||
for(vector<string>::const_iterator pi = patterns.begin();
|
||||
pi != patterns.end() && match != 0;
|
||||
++pi)
|
||||
{
|
||||
match = ::fnmatch(pi->c_str(),i->path.c_str(),0);
|
||||
}
|
||||
|
||||
i = ((match == 0) ? erase(i) : (i+1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct Branch
|
||||
{
|
||||
enum Mode
|
||||
{
|
||||
INVALID,
|
||||
RO,
|
||||
RW,
|
||||
NC
|
||||
};
|
||||
|
||||
Mode mode;
|
||||
std::string path;
|
||||
|
||||
bool ro(void) const;
|
||||
bool nc(void) const;
|
||||
bool ro_or_nc(void) const;
|
||||
};
|
||||
|
||||
class Branches : public std::vector<Branch>
|
||||
{
|
||||
public:
|
||||
std::string to_string(const bool mode_ = false) const;
|
||||
|
||||
void to_paths(std::vector<std::string> &vec_) const;
|
||||
|
||||
public:
|
||||
void set(const std::string &str_);
|
||||
void add_begin(const std::string &str_);
|
||||
void add_end(const std::string &str_);
|
||||
void erase_begin(void);
|
||||
void erase_end(void);
|
||||
void erase_fnmatch(const std::string &str_);
|
||||
};
|
||||
+4
-4
@@ -68,7 +68,7 @@ _chmod_loop(const vector<const string*> &basepaths,
|
||||
static
|
||||
int
|
||||
_chmod(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode)
|
||||
@@ -76,7 +76,7 @@ _chmod(Policy::Func::Action actionFunc,
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = actionFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -94,10 +94,10 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _chmod(config.chmod,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode);
|
||||
|
||||
+4
-4
@@ -71,7 +71,7 @@ _chown_loop(const vector<const string*> &basepaths,
|
||||
static
|
||||
int
|
||||
_chown(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const uid_t uid,
|
||||
@@ -80,7 +80,7 @@ _chown(Policy::Func::Action actionFunc,
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = actionFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -99,10 +99,10 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _chown(config.chown,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
uid,
|
||||
|
||||
+9
-4
@@ -35,8 +35,8 @@ namespace mergerfs
|
||||
{
|
||||
Config::Config()
|
||||
: destmount(),
|
||||
srcmounts(),
|
||||
srcmountslock(),
|
||||
branches(),
|
||||
branches_lock(),
|
||||
minfreespace(MINFREESPACE_DEFAULT),
|
||||
moveonenospc(false),
|
||||
direct_io(false),
|
||||
@@ -45,6 +45,11 @@ namespace mergerfs
|
||||
symlinkify_timeout(3600),
|
||||
nullrw(false),
|
||||
ignorepponrename(false),
|
||||
security_capability(true),
|
||||
link_cow(false),
|
||||
xattr(0),
|
||||
statfs(StatFS::BASE),
|
||||
statfs_ignore(StatFSIgnore::NONE),
|
||||
POLICYINIT(access),
|
||||
POLICYINIT(chmod),
|
||||
POLICYINIT(chown),
|
||||
@@ -67,9 +72,9 @@ namespace mergerfs
|
||||
POLICYINIT(utimens),
|
||||
controlfile("/.mergerfs")
|
||||
{
|
||||
pthread_rwlock_init(&srcmountslock,NULL);
|
||||
pthread_rwlock_init(&branches_lock,NULL);
|
||||
|
||||
set_category_policy("action","all");
|
||||
set_category_policy("action","epall");
|
||||
set_category_policy("create","epmfs");
|
||||
set_category_policy("search","ff");
|
||||
}
|
||||
|
||||
+34
-8
@@ -16,34 +16,55 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "branch.hpp"
|
||||
#include "fusefunc.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
#include "fusefunc.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
struct StatFS
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
BASE,
|
||||
FULL
|
||||
};
|
||||
};
|
||||
|
||||
struct StatFSIgnore
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
NONE,
|
||||
RO,
|
||||
NC
|
||||
};
|
||||
};
|
||||
|
||||
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);
|
||||
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;
|
||||
Branches branches;
|
||||
mutable pthread_rwlock_t branches_lock;
|
||||
uint64_t minfreespace;
|
||||
bool moveonenospc;
|
||||
bool direct_io;
|
||||
@@ -52,6 +73,11 @@ namespace mergerfs
|
||||
time_t symlinkify_timeout;
|
||||
bool nullrw;
|
||||
bool ignorepponrename;
|
||||
bool security_capability;
|
||||
bool link_cow;
|
||||
int xattr;
|
||||
StatFS::Enum statfs;
|
||||
StatFSIgnore::Enum statfs_ignore;
|
||||
|
||||
public:
|
||||
const Policy *policies[FuseFunc::Enum::END];
|
||||
|
||||
+13
-23
@@ -34,7 +34,6 @@ using std::vector;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_create_core(const string &fullpath,
|
||||
mode_t mode,
|
||||
@@ -49,10 +48,8 @@ _create_core(const string &fullpath,
|
||||
|
||||
static
|
||||
int
|
||||
_create_core(const string &existingpath,
|
||||
const string &createpath,
|
||||
_create_core(const string &createpath,
|
||||
const char *fusepath,
|
||||
const char *fusedirpath,
|
||||
const mode_t mode,
|
||||
const mode_t umask,
|
||||
const int flags,
|
||||
@@ -61,14 +58,6 @@ _create_core(const string &existingpath,
|
||||
int rv;
|
||||
string fullpath;
|
||||
|
||||
if(createpath != existingpath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
rv = fs::clonepath(existingpath,createpath,fusedirpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
}
|
||||
|
||||
fs::path::make(&createpath,fusepath,fullpath);
|
||||
|
||||
rv = _create_core(fullpath,mode,umask,flags);
|
||||
@@ -84,7 +73,7 @@ static
|
||||
int
|
||||
_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode,
|
||||
@@ -95,24 +84,25 @@ _create(Policy::Func::Search searchFunc,
|
||||
int rv;
|
||||
string fullpath;
|
||||
string fusedirpath;
|
||||
const char *fusedirpathcstr;
|
||||
vector<const string*> createpaths;
|
||||
vector<const string*> existingpaths;
|
||||
|
||||
fusedirpath = fusepath;
|
||||
fs::path::dirname(fusedirpath);
|
||||
fusedirpathcstr = fusedirpath.c_str();
|
||||
fusedirpath = fs::path::dirname(fusepath);
|
||||
|
||||
rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths);
|
||||
rv = searchFunc(branches_,fusedirpath,minfreespace,existingpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths);
|
||||
rv = createFunc(branches_,fusedirpath,minfreespace,createpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return _create_core(*existingpaths[0],*createpaths[0],
|
||||
fusepath,fusedirpathcstr,
|
||||
rv = fs::clonepath_as_root(*existingpaths[0],*createpaths[0],fusedirpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return _create_core(*createpaths[0],
|
||||
fusepath,
|
||||
mode,umask,flags,fh);
|
||||
}
|
||||
|
||||
@@ -128,11 +118,11 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _create(config.getattr,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode,
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/* The MIT License
|
||||
|
||||
Copyright (C) 2012 Zilong Tan (eric.zltan@gmail.com)
|
||||
|
||||
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 "fasthash.h"
|
||||
|
||||
// Compression function for Merkle-Damgard construction.
|
||||
// This function is generated using the framework provided.
|
||||
#define mix(h) ({ \
|
||||
(h) ^= (h) >> 23; \
|
||||
(h) *= 0x2127599bf4325c37ULL; \
|
||||
(h) ^= (h) >> 47; })
|
||||
|
||||
uint64_t
|
||||
fasthash64(const void *buf,
|
||||
size_t len,
|
||||
uint64_t seed)
|
||||
{
|
||||
const uint64_t m = 0x880355f21e6d1965ULL;
|
||||
const uint64_t *pos = (const uint64_t *)buf;
|
||||
const uint64_t *end = pos + (len / 8);
|
||||
const unsigned char *pos2;
|
||||
uint64_t h = seed ^ (len * m);
|
||||
uint64_t v;
|
||||
|
||||
while (pos != end) {
|
||||
v = *pos++;
|
||||
h ^= mix(v);
|
||||
h *= m;
|
||||
}
|
||||
|
||||
pos2 = (const unsigned char*)pos;
|
||||
v = 0;
|
||||
|
||||
switch (len & 7) {
|
||||
case 7: v ^= (uint64_t)pos2[6] << 48;
|
||||
case 6: v ^= (uint64_t)pos2[5] << 40;
|
||||
case 5: v ^= (uint64_t)pos2[4] << 32;
|
||||
case 4: v ^= (uint64_t)pos2[3] << 24;
|
||||
case 3: v ^= (uint64_t)pos2[2] << 16;
|
||||
case 2: v ^= (uint64_t)pos2[1] << 8;
|
||||
case 1: v ^= (uint64_t)pos2[0];
|
||||
h ^= mix(v);
|
||||
h *= m;
|
||||
}
|
||||
|
||||
return mix(h);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
fasthash32(const void *buf,
|
||||
size_t len,
|
||||
uint32_t seed)
|
||||
{
|
||||
// the following trick converts the 64-bit hashcode to Fermat
|
||||
// residue, which shall retain information from both the higher
|
||||
// and lower parts of hashcode.
|
||||
uint64_t h;
|
||||
|
||||
h = fasthash64(buf, len, seed);
|
||||
|
||||
return (h - (h >> 32));
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* The MIT License
|
||||
|
||||
Copyright (C) 2012 Zilong Tan (eric.zltan@gmail.com)
|
||||
|
||||
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 _FASTHASH_H
|
||||
#define _FASTHASH_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* fasthash32 - 32-bit implementation of fasthash
|
||||
* @buf: data buffer
|
||||
* @len: data size
|
||||
* @seed: the seed
|
||||
*/
|
||||
uint32_t fasthash32(const void *buf, size_t len, uint32_t seed);
|
||||
|
||||
/**
|
||||
* fasthash64 - 64-bit implementation of fasthash
|
||||
* @buf: data buffer
|
||||
* @len: data size
|
||||
* @seed: the seed
|
||||
*/
|
||||
uint64_t fasthash64(const void *buf, size_t len, uint64_t seed);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+37
-97
@@ -18,7 +18,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -28,105 +27,69 @@
|
||||
#include "fs_base_realpath.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_statvfs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
#include "str.hpp"
|
||||
#include "success_fail.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
bool
|
||||
exists(const string &path,
|
||||
struct stat &st)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::lstat(path,st);
|
||||
|
||||
return LSTAT_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
exists(const string &path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
return exists(path,st);
|
||||
}
|
||||
|
||||
bool
|
||||
info(const string &path,
|
||||
bool &readonly,
|
||||
uint64_t &spaceavail,
|
||||
uint64_t &spaceused)
|
||||
int
|
||||
readonly(const string *path_,
|
||||
bool *readonly_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
{
|
||||
readonly = StatVFS::readonly(st);
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
}
|
||||
rv = fs::statvfs(*path_,st);
|
||||
if(rv == 0)
|
||||
*readonly_ = StatVFS::readonly(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
readonly(const string &path)
|
||||
int
|
||||
spaceavail(const string *path_,
|
||||
uint64_t *spaceavail_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
rv = fs::statvfs(*path_,st);
|
||||
if(rv == 0)
|
||||
*spaceavail_ = StatVFS::spaceavail(st);
|
||||
|
||||
return (STATVFS_SUCCEEDED(rv) && StatVFS::readonly(st));
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
spaceavail(const string &path,
|
||||
uint64_t &spaceavail)
|
||||
int
|
||||
spaceused(const string *path_,
|
||||
uint64_t *spaceused_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
rv = fs::statvfs(*path_,st);
|
||||
if(rv == 0)
|
||||
*spaceused_ = StatVFS::spaceused(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
spaceused(const string &path,
|
||||
uint64_t &spaceused)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
findallfiles(const vector<string> &srcmounts,
|
||||
findallfiles(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||
fs::path::make(&basepaths[i],fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
@@ -136,7 +99,7 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
findonfs(const vector<string> &srcmounts,
|
||||
findonfs(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const int fd,
|
||||
string &basepath)
|
||||
@@ -147,22 +110,22 @@ namespace fs
|
||||
struct stat st;
|
||||
|
||||
rv = fs::fstat(fd,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
dev = st.st_dev;
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||
fs::path::make(&basepaths[i],fusepath,fullpath);
|
||||
|
||||
rv = fs::lstat(fullpath,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
if(st.st_dev != dev)
|
||||
continue;
|
||||
|
||||
basepath = srcmounts[i];
|
||||
basepath = basepaths[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -170,31 +133,6 @@ namespace fs
|
||||
return (errno=ENOENT,-1);
|
||||
}
|
||||
|
||||
void
|
||||
glob(const vector<string> &patterns,
|
||||
vector<string> &strs)
|
||||
{
|
||||
int flags;
|
||||
size_t veclen;
|
||||
glob_t gbuf = {0};
|
||||
|
||||
veclen = patterns.size();
|
||||
if(veclen == 0)
|
||||
return;
|
||||
|
||||
flags = 0;
|
||||
glob(patterns[0].c_str(),flags,NULL,&gbuf);
|
||||
|
||||
flags = GLOB_APPEND;
|
||||
for(size_t i = 1; i < veclen; i++)
|
||||
glob(patterns[i].c_str(),flags,NULL,&gbuf);
|
||||
|
||||
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
|
||||
strs.push_back(gbuf.gl_pathv[i]);
|
||||
|
||||
globfree(&gbuf);
|
||||
}
|
||||
|
||||
void
|
||||
realpathize(vector<string> &strs)
|
||||
{
|
||||
@@ -230,19 +168,21 @@ namespace fs
|
||||
const uint64_t minfreespace,
|
||||
string &path)
|
||||
{
|
||||
int rv;
|
||||
uint64_t mfs;
|
||||
uint64_t spaceavail;
|
||||
const string *basepath;
|
||||
const string *mfsbasepath;
|
||||
|
||||
mfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceavail;
|
||||
const string &basepath = basepaths[i];
|
||||
basepath = &basepaths[i];
|
||||
|
||||
if(!fs::spaceavail(basepath,spaceavail))
|
||||
rv = fs::spaceavail(basepath,&spaceavail);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceavail <= mfs)
|
||||
|
||||
+8
-19
@@ -27,35 +27,24 @@ namespace fs
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
bool exists(const string &path,
|
||||
struct stat &st);
|
||||
bool exists(const string &path);
|
||||
int readonly(const string *path_,
|
||||
bool *readonly_);
|
||||
|
||||
bool info(const string &path,
|
||||
bool &readonly,
|
||||
uint64_t &spaceavail,
|
||||
uint64_t &spaceused);
|
||||
int spaceavail(const string *path_,
|
||||
uint64_t *spaceavail_);
|
||||
|
||||
bool readonly(const string &path);
|
||||
int spaceused(const string *path_,
|
||||
uint64_t *spaceavail_);
|
||||
|
||||
bool spaceavail(const string &path,
|
||||
uint64_t &spaceavail);
|
||||
|
||||
bool spaceused(const string &path,
|
||||
uint64_t &spaceavail);
|
||||
|
||||
void findallfiles(const vector<string> &srcmounts,
|
||||
void findallfiles(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<string> &paths);
|
||||
|
||||
int findonfs(const vector<string> &srcmounts,
|
||||
int findonfs(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const int fd,
|
||||
string &basepath);
|
||||
|
||||
void glob(const vector<string> &patterns,
|
||||
vector<string> &strs);
|
||||
|
||||
void realpathize(vector<string> &strs);
|
||||
|
||||
int getfl(const int fd);
|
||||
|
||||
+3
-3
@@ -28,12 +28,12 @@ namespace fs
|
||||
namespace acl
|
||||
{
|
||||
bool
|
||||
dir_has_defaults(const std::string &fullpath)
|
||||
dir_has_defaults(const std::string &fullpath_)
|
||||
{
|
||||
int rv;
|
||||
std::string dirpath = fullpath;
|
||||
std::string dirpath;
|
||||
|
||||
fs::path::dirname(dirpath);
|
||||
dirpath = fs::path::dirname(&fullpath_);
|
||||
|
||||
rv = fs::lgetxattr(dirpath,POSIX_ACL_DEFAULT_XATTR,NULL,0);
|
||||
|
||||
|
||||
@@ -18,25 +18,78 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
lgetxattr(const std::string &path,
|
||||
const char *attrname,
|
||||
void *value,
|
||||
const size_t size)
|
||||
lgetxattr(const char *path_,
|
||||
const char *attrname_,
|
||||
void *value_,
|
||||
const size_t size_)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::lgetxattr(path.c_str(),attrname,value,size);
|
||||
#ifdef USE_XATTR
|
||||
return ::lgetxattr(path_,attrname_,value_,size_);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lgetxattr(const std::string &path_,
|
||||
const char *attrname_,
|
||||
void *value_,
|
||||
const size_t size_)
|
||||
{
|
||||
return fs::lgetxattr(path_.c_str(),attrname_,value_,size_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lgetxattr(const std::string &path_,
|
||||
const std::string &attrname_,
|
||||
void *value_,
|
||||
const size_t size_)
|
||||
{
|
||||
return fs::lgetxattr(path_.c_str(),
|
||||
attrname_.c_str(),
|
||||
value_,
|
||||
size_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fgetxattr(const int fd_,
|
||||
const char *attrname_,
|
||||
void *value_,
|
||||
const size_t size_)
|
||||
{
|
||||
#ifdef USE_XATTR
|
||||
return ::fgetxattr(fd_,attrname_,value_,size_);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fgetxattr(const int fd_,
|
||||
const std::string &attrname_,
|
||||
void *value_,
|
||||
const size_t size_)
|
||||
{
|
||||
return fs::fgetxattr(fd_,attrname_.c_str(),value_,size_);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-4
@@ -25,10 +25,20 @@ namespace fs
|
||||
static
|
||||
inline
|
||||
int
|
||||
ioctl(const int fd,
|
||||
const unsigned long request,
|
||||
void *data)
|
||||
ioctl(const int fd_,
|
||||
const unsigned long request_,
|
||||
void *data_)
|
||||
{
|
||||
return ::ioctl(fd,request,data);
|
||||
return ::ioctl(fd_,request_,data_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
ioctl(const int fd_,
|
||||
const unsigned long request_,
|
||||
const int int_)
|
||||
{
|
||||
return ::ioctl(fd_,request_,int_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,22 +18,48 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
llistxattr(const std::string &path,
|
||||
char *list,
|
||||
const size_t size)
|
||||
llistxattr(const char *path_,
|
||||
char *list_,
|
||||
const size_t size_)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::llistxattr(path.c_str(),list,size);
|
||||
#ifdef USE_XATTR
|
||||
return ::llistxattr(path_,list_,size_);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
llistxattr(const std::string &path_,
|
||||
char *list_,
|
||||
const size_t size_)
|
||||
{
|
||||
return fs::llistxattr(path_.c_str(),list_,size_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
flistxattr(const int fd_,
|
||||
char *list_,
|
||||
const size_t size_)
|
||||
{
|
||||
#ifdef USE_XATTR
|
||||
return ::flistxattr(fd_,list_,size_);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
|
||||
+28
-9
@@ -18,30 +18,49 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
open(const std::string &path,
|
||||
const int flags)
|
||||
open(const char *path_,
|
||||
const int flags_)
|
||||
{
|
||||
return ::open(path.c_str(),flags);
|
||||
return ::open(path_,flags_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
open(const std::string &path,
|
||||
const int flags,
|
||||
const mode_t mode)
|
||||
open(const char *path_,
|
||||
const int flags_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
return ::open(path.c_str(),flags,mode);
|
||||
return ::open(path_,flags_,mode_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
open(const std::string &path_,
|
||||
const int flags_)
|
||||
{
|
||||
return fs::open(path_.c_str(),flags_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
open(const std::string &path_,
|
||||
const int flags_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
return fs::open(path_.c_str(),flags_,mode_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace fs
|
||||
lremovexattr(const std::string &path,
|
||||
const char *attrname)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
#ifdef USE_XATTR
|
||||
return ::lremovexattr(path.c_str(),attrname);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
|
||||
+12
-3
@@ -25,9 +25,18 @@ namespace fs
|
||||
static
|
||||
inline
|
||||
int
|
||||
rename(const std::string &oldpath,
|
||||
const std::string &newpath)
|
||||
rename(const char *oldpath_,
|
||||
const char *newpath_)
|
||||
{
|
||||
return ::rename(oldpath.c_str(),newpath.c_str());
|
||||
return ::rename(oldpath_,newpath_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
rename(const std::string &oldpath_,
|
||||
const std::string &newpath_)
|
||||
{
|
||||
return fs::rename(oldpath_.c_str(),newpath_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,24 +18,58 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
lsetxattr(const std::string &path,
|
||||
const char *name,
|
||||
const void *value,
|
||||
const size_t size,
|
||||
const int flags)
|
||||
lsetxattr(const char *path_,
|
||||
const char *name_,
|
||||
const void *value_,
|
||||
const size_t size_,
|
||||
const int flags_)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::lsetxattr(path.c_str(),name,value,size,flags);
|
||||
#ifdef USE_XATTR
|
||||
return ::lsetxattr(path_,name_,value_,size_,flags_);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lsetxattr(const std::string &path_,
|
||||
const std::string &name_,
|
||||
const void *value_,
|
||||
const size_t size_,
|
||||
const int flags_)
|
||||
{
|
||||
return fs::lsetxattr(path_.c_str(),
|
||||
name_.c_str(),
|
||||
value_,
|
||||
size_,
|
||||
flags_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fsetxattr(const int fd_,
|
||||
const char *name_,
|
||||
const void *value_,
|
||||
const size_t size_,
|
||||
const int flags_)
|
||||
{
|
||||
#ifdef USE_XATTR
|
||||
return ::fsetxattr(fd_,name_,value_,size_,flags_);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
|
||||
+38
-1
@@ -18,10 +18,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifndef O_PATH
|
||||
# define O_PATH 0
|
||||
#endif
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
@@ -41,4 +49,33 @@ namespace fs
|
||||
{
|
||||
return fs::statvfs(path.c_str(),st);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fstatvfs(const int fd_,
|
||||
struct statvfs &st_)
|
||||
{
|
||||
return ::fstatvfs(fd_,&st_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lstatvfs(const std::string &path_,
|
||||
struct statvfs &st_)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
|
||||
fd = fs::open(path_,O_RDONLY|O_NOFOLLOW|O_PATH);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::fstatvfs(fd,st_);
|
||||
|
||||
fs::close(fd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -27,8 +27,16 @@ namespace fs
|
||||
static
|
||||
inline
|
||||
int
|
||||
unlink(const std::string &path)
|
||||
unlink(const char *path_)
|
||||
{
|
||||
return ::unlink(path.c_str());
|
||||
return ::unlink(path_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
unlink(const std::string &path_)
|
||||
{
|
||||
return fs::unlink(path_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
+35
-139
@@ -14,130 +14,55 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_base_chmod.hpp"
|
||||
#include "fs_base_chown.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_fadvise.hpp"
|
||||
#include "fs_base_fallocate.hpp"
|
||||
#include "fs_base_lseek.hpp"
|
||||
#include "fs_base_mkdir.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_read.hpp"
|
||||
#include "fs_base_ftruncate.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_utime.hpp"
|
||||
#include "fs_base_write.hpp"
|
||||
#include "fs_copy_file_range.hpp"
|
||||
#include "fs_copyfile.hpp"
|
||||
#include "fs_ficlone.hpp"
|
||||
#include "fs_sendfile.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
|
||||
#ifndef O_LARGEFILE
|
||||
# define O_LARGEFILE 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOATIME
|
||||
# define O_NOATIME 0
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
int
|
||||
writen(const int fd,
|
||||
const char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
size_t nleft;
|
||||
ssize_t nwritten;
|
||||
|
||||
nleft = count;
|
||||
do
|
||||
{
|
||||
nwritten = fs::write(fd,buf,nleft);
|
||||
if((nwritten == -1) && (errno == EINTR))
|
||||
continue;
|
||||
if(nwritten == -1)
|
||||
return -1;
|
||||
|
||||
nleft -= nwritten;
|
||||
buf += nwritten;
|
||||
}
|
||||
while(nleft > 0);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copyfile_rw(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count,
|
||||
const size_t blocksize)
|
||||
{
|
||||
ssize_t nr;
|
||||
ssize_t nw;
|
||||
ssize_t bufsize;
|
||||
size_t totalwritten;
|
||||
vector<char> buf;
|
||||
|
||||
bufsize = (blocksize * 16);
|
||||
buf.resize(bufsize);
|
||||
|
||||
fs::lseek(fdin,0,SEEK_SET);
|
||||
|
||||
totalwritten = 0;
|
||||
while(totalwritten < count)
|
||||
{
|
||||
nr = fs::read(fdin,&buf[0],bufsize);
|
||||
if(nr == 0)
|
||||
return totalwritten;
|
||||
if((nr == -1) && (errno == EINTR))
|
||||
continue;
|
||||
if(nr == -1)
|
||||
return -1;
|
||||
|
||||
nw = writen(fdout,&buf[0],nr);
|
||||
if(nw == -1)
|
||||
return -1;
|
||||
|
||||
totalwritten += nw;
|
||||
}
|
||||
|
||||
return totalwritten;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copydata(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count,
|
||||
const size_t blocksize)
|
||||
copydata(const int src_fd_,
|
||||
const int dst_fd_,
|
||||
const size_t count_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
fs::fadvise_willneed(fdin,0,count);
|
||||
fs::fadvise_sequential(fdin,0,count);
|
||||
fs::fadvise_willneed(src_fd_,0,count_);
|
||||
fs::fadvise_sequential(src_fd_,0,count_);
|
||||
|
||||
fs::fallocate(fdout,0,0,count);
|
||||
fs::fallocate(dst_fd_,0,0,count_);
|
||||
fs::ftruncate(dst_fd_,count_);
|
||||
|
||||
rv = fs::sendfile(fdin,fdout,count);
|
||||
if((rv == -1) && ((errno == EINVAL) || (errno == ENOSYS)))
|
||||
return ::copyfile_rw(fdin,fdout,count,blocksize);
|
||||
rv = fs::ficlone(src_fd_,dst_fd_);
|
||||
if((rv != -1) || ((rv == -1) && (errno != EOPNOTSUPP)))
|
||||
return rv;
|
||||
|
||||
return rv;
|
||||
rv = fs::copy_file_range(src_fd_,dst_fd_,count_);
|
||||
if((rv != -1) || ((rv == -1) && (errno != EOPNOTSUPP)))
|
||||
return rv;
|
||||
|
||||
rv = fs::sendfile(src_fd_,dst_fd_,count_);
|
||||
if((rv != -1) || ((rv == -1) && (errno != EINVAL) && (errno != ENOSYS)))
|
||||
return rv;
|
||||
|
||||
return fs::copyfile(src_fd_,dst_fd_);
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
ignorable_error(const int err)
|
||||
ignorable_error(const int err_)
|
||||
{
|
||||
switch(err)
|
||||
switch(err_)
|
||||
{
|
||||
case ENOTTY:
|
||||
case ENOTSUP:
|
||||
@@ -153,69 +78,40 @@ ignorable_error(const int err)
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
clonefile(const int fdin,
|
||||
const int fdout)
|
||||
clonefile(const int src_fd_,
|
||||
const int dst_fd_)
|
||||
{
|
||||
int rv;
|
||||
struct stat stin;
|
||||
struct stat src_st;
|
||||
|
||||
rv = fs::fstat(fdin,stin);
|
||||
rv = fs::fstat(src_fd_,src_st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::copydata(fdin,fdout,stin.st_size,stin.st_blksize);
|
||||
rv = ::copydata(src_fd_,dst_fd_,src_st.st_size);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::attr::copy(fdin,fdout);
|
||||
rv = fs::attr::copy(src_fd_,dst_fd_);
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::xattr::copy(fdin,fdout);
|
||||
rv = fs::xattr::copy(src_fd_,dst_fd_);
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::fchown_check_on_error(fdout,stin);
|
||||
rv = fs::fchown_check_on_error(dst_fd_,src_st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::fchmod_check_on_error(fdout,stin);
|
||||
rv = fs::fchmod_check_on_error(dst_fd_,src_st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::utime(fdout,stin);
|
||||
rv = fs::utime(dst_fd_,src_st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
clonefile(const string &in,
|
||||
const string &out)
|
||||
{
|
||||
int rv;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int error;
|
||||
|
||||
fdin = fs::open(in,O_RDONLY|O_NOFOLLOW);
|
||||
if(fdin == -1)
|
||||
return -1;
|
||||
|
||||
const int flags = O_CREAT|O_LARGEFILE|O_NOATIME|O_NOFOLLOW|O_TRUNC|O_WRONLY;
|
||||
const mode_t mode = S_IWUSR;
|
||||
fdout = fs::open(out,flags,mode);
|
||||
if(fdout == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::clonefile(fdin,fdout);
|
||||
error = errno;
|
||||
|
||||
fs::close(fdin);
|
||||
fs::close(fdout);
|
||||
|
||||
errno = error;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int clonefile(const int fdin,
|
||||
const int fdout);
|
||||
int clonefile(const std::string &from,
|
||||
const std::string &to);
|
||||
int
|
||||
clonefile(const int src_fd_,
|
||||
const int dst_fd_);
|
||||
}
|
||||
|
||||
+52
-15
@@ -26,6 +26,7 @@
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -48,10 +49,17 @@ ignorable_error(const int err)
|
||||
|
||||
namespace fs
|
||||
{
|
||||
/*
|
||||
Attempts to clone a path.
|
||||
The directories which already exist are left alone.
|
||||
The new directories have metadata set to match the original if
|
||||
possible. Optionally ignore errors on metadata copies.
|
||||
*/
|
||||
int
|
||||
clonepath(const string &fromsrc,
|
||||
const string &tosrc,
|
||||
const char *relative)
|
||||
const char *relative,
|
||||
const bool return_metadata_errors)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
@@ -59,8 +67,10 @@ namespace fs
|
||||
string frompath;
|
||||
string dirname;
|
||||
|
||||
dirname = relative;
|
||||
fs::path::dirname(dirname);
|
||||
if((relative == NULL) || (relative[0] == '\0'))
|
||||
return 0;
|
||||
|
||||
dirname = fs::path::dirname(relative);
|
||||
if(!dirname.empty())
|
||||
{
|
||||
rv = fs::clonepath(fromsrc,tosrc,dirname);
|
||||
@@ -79,29 +89,28 @@ namespace fs
|
||||
rv = fs::mkdir(topath,st.st_mode);
|
||||
if(rv == -1)
|
||||
{
|
||||
if(errno != EEXIST)
|
||||
return -1;
|
||||
|
||||
rv = fs::chmod_check_on_error(topath,st.st_mode);
|
||||
if(rv == -1)
|
||||
if(errno == EEXIST)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
// It may not support it... it's fine...
|
||||
// it may not support it... it's fine...
|
||||
rv = fs::attr::copy(frompath,topath);
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
if(return_metadata_errors && (rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
// it may not support it... it's fine...
|
||||
rv = fs::xattr::copy(frompath,topath);
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
if(return_metadata_errors && (rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::lchown_check_on_error(topath,st);
|
||||
if(rv == -1)
|
||||
if(return_metadata_errors && (rv == -1))
|
||||
return -1;
|
||||
|
||||
rv = fs::utime(topath,st);
|
||||
if(rv == -1)
|
||||
if(return_metadata_errors && (rv == -1))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -110,8 +119,36 @@ namespace fs
|
||||
int
|
||||
clonepath(const std::string &from,
|
||||
const std::string &to,
|
||||
const std::string &relative)
|
||||
const std::string &relative,
|
||||
const bool return_metadata_errors)
|
||||
{
|
||||
return fs::clonepath(from,to,relative.c_str());
|
||||
return fs::clonepath(from,to,relative.c_str(),return_metadata_errors);
|
||||
}
|
||||
|
||||
int
|
||||
clonepath_as_root(const string &from,
|
||||
const string &to,
|
||||
const char *relative,
|
||||
const bool return_metadata_errors)
|
||||
{
|
||||
if((relative == NULL) || (relative[0] == '\0'))
|
||||
return 0;
|
||||
if(from == to)
|
||||
return 0;
|
||||
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
|
||||
return fs::clonepath(from,to,relative,return_metadata_errors);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
clonepath_as_root(const std::string &from,
|
||||
const std::string &to,
|
||||
const std::string &relative,
|
||||
const bool return_metadata_errors)
|
||||
{
|
||||
return fs::clonepath_as_root(from,to,relative.c_str(),return_metadata_errors);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -22,8 +22,19 @@ namespace fs
|
||||
{
|
||||
int clonepath(const std::string &from,
|
||||
const std::string &to,
|
||||
const char *relative);
|
||||
const char *relative,
|
||||
const bool return_metadata_errors = false);
|
||||
int clonepath(const std::string &from,
|
||||
const std::string &to,
|
||||
const std::string &relative);
|
||||
const std::string &relative,
|
||||
const bool return_metadata_errors = false);
|
||||
|
||||
int clonepath_as_root(const std::string &from,
|
||||
const std::string &to,
|
||||
const char *relative,
|
||||
const bool return_metadata_errors = false);
|
||||
int clonepath_as_root(const std::string &from,
|
||||
const std::string &to,
|
||||
const std::string &relative,
|
||||
const bool return_metadata_errors = false);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
# include "fs_copy_file_range_linux.icpp"
|
||||
#else
|
||||
# include "fs_copy_file_range_unsupported.icpp"
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
loff_t *off_in_,
|
||||
const int fd_out_,
|
||||
loff_t *off_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_);
|
||||
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
const int fd_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_ = 0);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static
|
||||
loff_t
|
||||
copy_file_range_(int fd_in_,
|
||||
loff_t *off_in_,
|
||||
int fd_out_,
|
||||
loff_t *off_out_,
|
||||
size_t len_,
|
||||
unsigned int flags_)
|
||||
{
|
||||
#ifdef SYS_copy_file_range
|
||||
return ::syscall(SYS_copy_file_range,
|
||||
fd_in_,
|
||||
off_in_,
|
||||
fd_out_,
|
||||
off_out_,
|
||||
len_,
|
||||
flags_);
|
||||
#else
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
loff_t *off_in_,
|
||||
const int fd_out_,
|
||||
loff_t *off_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_)
|
||||
{
|
||||
return ::copy_file_range_(fd_in_,
|
||||
off_in_,
|
||||
fd_out_,
|
||||
off_out_,
|
||||
len_,
|
||||
flags_);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
const int fd_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_)
|
||||
{
|
||||
loff_t off_in;
|
||||
loff_t off_out;
|
||||
|
||||
off_in = 0;
|
||||
off_out = 0;
|
||||
|
||||
return fs::copy_file_range(fd_in_,
|
||||
&off_in,
|
||||
fd_out_,
|
||||
&off_out,
|
||||
len_,
|
||||
flags_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
loff_t *off_in_,
|
||||
const int fd_out_,
|
||||
loff_t *off_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_)
|
||||
{
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
copy_file_range(const int fd_in_,
|
||||
const int fd_out_,
|
||||
const size_t len_,
|
||||
const unsigned int flags_)
|
||||
{
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_lseek.hpp"
|
||||
#include "fs_base_read.hpp"
|
||||
#include "fs_base_write.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
|
||||
static
|
||||
int
|
||||
writen(const int fd_,
|
||||
const char *buf_,
|
||||
const size_t count_)
|
||||
{
|
||||
size_t nleft;
|
||||
ssize_t nwritten;
|
||||
|
||||
nleft = count_;
|
||||
do
|
||||
{
|
||||
nwritten = fs::write(fd_,buf_,nleft);
|
||||
if((nwritten == -1) && (errno == EINTR))
|
||||
continue;
|
||||
if(nwritten == -1)
|
||||
return -1;
|
||||
|
||||
nleft -= nwritten;
|
||||
buf_ += nwritten;
|
||||
}
|
||||
while(nleft > 0);
|
||||
|
||||
return count_;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copyfile(const int src_fd_,
|
||||
const int dst_fd_,
|
||||
const size_t count_,
|
||||
const size_t blocksize_)
|
||||
{
|
||||
ssize_t nr;
|
||||
ssize_t nw;
|
||||
ssize_t bufsize;
|
||||
size_t totalwritten;
|
||||
vector<char> buf;
|
||||
|
||||
bufsize = (blocksize_ * 16);
|
||||
buf.resize(bufsize);
|
||||
|
||||
fs::lseek(src_fd_,0,SEEK_SET);
|
||||
|
||||
totalwritten = 0;
|
||||
while(totalwritten < count_)
|
||||
{
|
||||
nr = fs::read(src_fd_,&buf[0],bufsize);
|
||||
if(nr == 0)
|
||||
return totalwritten;
|
||||
if((nr == -1) && (errno == EINTR))
|
||||
continue;
|
||||
if(nr == -1)
|
||||
return -1;
|
||||
|
||||
nw = writen(dst_fd_,&buf[0],nr);
|
||||
if(nw == -1)
|
||||
return -1;
|
||||
|
||||
totalwritten += nw;
|
||||
}
|
||||
|
||||
return totalwritten;
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
copyfile(const int src_fd_,
|
||||
const int dst_fd_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
||||
rv = fs::fstat(src_fd_,st);
|
||||
if(rv == -1)
|
||||
return rv;
|
||||
|
||||
return ::copyfile(src_fd_,
|
||||
dst_fd_,
|
||||
st.st_size,
|
||||
st.st_blksize);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
copyfile(const int src_fd_,
|
||||
const int dst_fd_);
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "fs_clonefile.hpp"
|
||||
#include "fs_mktemp.hpp"
|
||||
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_rename.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_unlink.hpp"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
static
|
||||
int
|
||||
cleanup_on_error(const int src_fd_,
|
||||
const int dst_fd_ = -1,
|
||||
const string &dst_fullpath_ = string())
|
||||
{
|
||||
int error = errno;
|
||||
|
||||
if(src_fd_ >= 0)
|
||||
fs::close(src_fd_);
|
||||
if(dst_fd_ >= 0)
|
||||
fs::close(dst_fd_);
|
||||
if(!dst_fullpath_.empty())
|
||||
fs::unlink(dst_fullpath_);
|
||||
|
||||
errno = error;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace cow
|
||||
{
|
||||
bool
|
||||
is_eligible(const int flags_,
|
||||
const struct stat &st_)
|
||||
{
|
||||
return (((flags_ & O_RDWR) || (flags_ & O_WRONLY)) &&
|
||||
(S_ISREG(st_.st_mode)) &&
|
||||
(st_.st_nlink > 1));
|
||||
}
|
||||
|
||||
bool
|
||||
is_eligible(const char *fullpath_,
|
||||
const int flags_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
||||
rv = fs::stat(fullpath_,st);
|
||||
if(rv == -1)
|
||||
return false;
|
||||
|
||||
return fs::cow::is_eligible(flags_,st);
|
||||
}
|
||||
|
||||
int
|
||||
break_link(const char *src_fullpath_)
|
||||
{
|
||||
int rv;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
string dst_fullpath;
|
||||
|
||||
src_fd = fs::open(src_fullpath_,O_RDONLY|O_NOFOLLOW|O_LARGEFILE);
|
||||
if(src_fd == -1)
|
||||
return -1;
|
||||
|
||||
dst_fullpath = src_fullpath_;
|
||||
|
||||
dst_fd = fs::mktemp(dst_fullpath,O_WRONLY|O_LARGEFILE);
|
||||
if(dst_fd == -1)
|
||||
return cleanup_on_error(src_fd);
|
||||
|
||||
rv = fs::clonefile(src_fd,dst_fd);
|
||||
if(rv == -1)
|
||||
return cleanup_on_error(src_fd,dst_fd,dst_fullpath);
|
||||
|
||||
rv = fs::rename(dst_fullpath,src_fullpath_);
|
||||
if(rv == -1)
|
||||
return cleanup_on_error(src_fd,dst_fd,dst_fullpath);
|
||||
|
||||
fs::close(src_fd);
|
||||
fs::close(dst_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace cow
|
||||
{
|
||||
bool is_eligible(const int flags_, const struct stat &st_);
|
||||
bool is_eligible(const char *fullpath_, const int flags_);
|
||||
|
||||
int break_link(const char *fullpath_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const std::string &path_,
|
||||
struct stat &st_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::lstat(path_,st_);
|
||||
|
||||
return (rv == 0);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const std::string &path_)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
return fs::exists(path_,st);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const std::string &basepath_,
|
||||
const char *relpath_,
|
||||
struct stat &st_)
|
||||
{
|
||||
std::string fullpath;
|
||||
|
||||
fullpath = fs::path::make(&basepath_,relpath_);
|
||||
|
||||
return fs::exists(fullpath,st_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const std::string &basepath_,
|
||||
const char *relpath_)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
return fs::exists(basepath_,relpath_,st);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
# include "fs_ficlone_linux.icpp"
|
||||
#else
|
||||
# include "fs_ficlone_unsupported.icpp"
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
ficlone(const int src_fd_,
|
||||
const int dst_fd_);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_ioctl.hpp"
|
||||
|
||||
#include <linux/fs.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
ficlone(const int src_fd_,
|
||||
const int dst_fd_)
|
||||
{
|
||||
#ifdef FICLONE
|
||||
return fs::ioctl(dst_fd_,FICLONE,src_fd_);
|
||||
#else
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
ficlone(const int src_fd_,
|
||||
const int dst_fd_)
|
||||
{
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <glob.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
void
|
||||
glob(const string &pattern_,
|
||||
vector<string> &strs_)
|
||||
{
|
||||
int flags;
|
||||
glob_t gbuf = {0};
|
||||
|
||||
flags = GLOB_NOCHECK;
|
||||
::glob(pattern_.c_str(),flags,NULL,&gbuf);
|
||||
|
||||
for(size_t i = 0; i < gbuf.gl_pathc; i++)
|
||||
strs_.push_back(gbuf.gl_pathv[i]);
|
||||
|
||||
::globfree(&gbuf);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
void
|
||||
glob(const string &pattern_,
|
||||
vector<string> &strs_);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_statvfs.hpp"
|
||||
#include "fs_info_t.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
info(const string *path_,
|
||||
fs::info_t *info_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(*path_,st);
|
||||
if(rv == 0)
|
||||
{
|
||||
info_->readonly = StatVFS::readonly(st);
|
||||
info_->spaceavail = StatVFS::spaceavail(st);
|
||||
info_->spaceused = StatVFS::spaceused(st);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fs_info_t.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
info(const std::string *path_,
|
||||
fs::info_t *info_);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
struct info_t
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t spaceused;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using std::string;
|
||||
|
||||
static
|
||||
string
|
||||
generate_tmp_path(const string &base_)
|
||||
{
|
||||
string tmp;
|
||||
|
||||
tmp = base_;
|
||||
tmp += '_';
|
||||
for(int i = 0; i < 6; i++)
|
||||
tmp += ('A' + (std::rand() % 26));
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
mktemp(string &base_,
|
||||
const int flags_)
|
||||
{
|
||||
int fd;
|
||||
int count;
|
||||
int flags;
|
||||
string tmppath;
|
||||
|
||||
fd = -1;
|
||||
count = 10;
|
||||
flags = (flags_ | O_EXCL | O_CREAT);
|
||||
while(count-- > 0)
|
||||
{
|
||||
tmppath = generate_tmp_path(base_);
|
||||
|
||||
fd = fs::open(tmppath,flags,S_IWUSR);
|
||||
if((fd == -1) && (errno == EEXIST))
|
||||
continue;
|
||||
else if(fd != -1)
|
||||
base_ = tmppath;
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
return (errno=EEXIST,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
mktemp(std::string &base_,
|
||||
const int flags_);
|
||||
}
|
||||
+2
-2
@@ -75,8 +75,8 @@ namespace fs
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
fusedir = fusepath;
|
||||
fs::path::dirname(fusedir);
|
||||
fusedir = fs::path::dirname(&fusepath);
|
||||
|
||||
rv = fs::clonepath(fdin_path,fdout_path,fusedir);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
+22
-9
@@ -29,24 +29,37 @@ namespace fs
|
||||
{
|
||||
namespace path
|
||||
{
|
||||
void
|
||||
dirname(string &path)
|
||||
string
|
||||
dirname(const char *path_)
|
||||
{
|
||||
string path(path_);
|
||||
|
||||
return fs::path::dirname(&path);
|
||||
}
|
||||
|
||||
string
|
||||
dirname(const string *path_)
|
||||
{
|
||||
string rv;
|
||||
string::reverse_iterator i;
|
||||
string::reverse_iterator bi;
|
||||
string::reverse_iterator ei;
|
||||
|
||||
bi = path.rend();
|
||||
i = path.rbegin();
|
||||
while(*i == '/' && i != bi)
|
||||
rv = *path_;
|
||||
|
||||
i = rv.rbegin();
|
||||
ei = rv.rend();
|
||||
while(*i == '/' && i != ei)
|
||||
i++;
|
||||
|
||||
while(*i != '/' && i != bi)
|
||||
while(*i != '/' && i != ei)
|
||||
i++;
|
||||
|
||||
while(*i == '/' && i != bi)
|
||||
while(*i == '/' && i != ei)
|
||||
i++;
|
||||
|
||||
path.erase(i.base(),path.end());
|
||||
rv.erase(i.base(),rv.end());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
string
|
||||
|
||||
+19
-1
@@ -25,7 +25,8 @@ namespace fs
|
||||
{
|
||||
using std::string;
|
||||
|
||||
void dirname(string &path);
|
||||
string dirname(const char *path_);
|
||||
string dirname(const string *path_);
|
||||
|
||||
string basename(const string &path);
|
||||
|
||||
@@ -64,5 +65,22 @@ namespace fs
|
||||
output = *base;
|
||||
output += suffix;
|
||||
}
|
||||
|
||||
inline
|
||||
string
|
||||
make(const string *base_,
|
||||
const char *suffix_)
|
||||
{
|
||||
return (*base_ + suffix_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
string
|
||||
make(const string *base_,
|
||||
const string *suffix_)
|
||||
{
|
||||
return (*base_ + *suffix_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+27
-53
@@ -14,22 +14,20 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_getxattr.hpp"
|
||||
#include "fs_base_listxattr.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_removexattr.hpp"
|
||||
#include "fs_base_setxattr.hpp"
|
||||
#include "str.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "str.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -44,57 +42,49 @@ namespace fs
|
||||
list(const int fd,
|
||||
vector<char> &attrs)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
ssize_t rv;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
rv = ::flistxattr(fd,NULL,0);
|
||||
rv = fs::flistxattr(fd,NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
attrs.resize(rv);
|
||||
|
||||
rv = ::flistxattr(fd,&attrs[0],rv);
|
||||
rv = fs::flistxattr(fd,&attrs[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
list(const string &path,
|
||||
vector<char> &attrs)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
ssize_t rv;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
rv = ::llistxattr(path.c_str(),NULL,0);
|
||||
rv = fs::llistxattr(path,NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
attrs.resize(rv);
|
||||
|
||||
rv = ::llistxattr(path.c_str(),&attrs[0],rv);
|
||||
rv = fs::llistxattr(path,&attrs[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
list(const int fd,
|
||||
vector<string> &attrvector)
|
||||
vector<string> &attrvector)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
@@ -159,26 +149,22 @@ namespace fs
|
||||
const string &attr,
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
ssize_t rv;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
rv = ::fgetxattr(fd,attr.c_str(),NULL,0);
|
||||
rv = fs::fgetxattr(fd,attr,NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
value.resize(rv);
|
||||
|
||||
rv = ::fgetxattr(fd,attr.c_str(),&value[0],rv);
|
||||
rv = fs::fgetxattr(fd,attr,&value[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@@ -186,26 +172,22 @@ namespace fs
|
||||
const string &attr,
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
ssize_t rv;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
rv = ::lgetxattr(path.c_str(),attr.c_str(),NULL,0);
|
||||
rv = fs::lgetxattr(path,attr,NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
value.resize(rv);
|
||||
|
||||
rv = ::lgetxattr(path.c_str(),attr.c_str(),&value[0],rv);
|
||||
rv = fs::lgetxattr(path,attr,&value[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@@ -300,15 +282,11 @@ namespace fs
|
||||
const string &value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::fsetxattr(fd,
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
return fs::fsetxattr(fd,
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -317,15 +295,11 @@ namespace fs
|
||||
const string &value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::lsetxattr(path.c_str(),
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
return fs::lsetxattr(path,
|
||||
key,
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
+4
-4
@@ -60,7 +60,7 @@ _getattr_controlfile(struct stat &st)
|
||||
static
|
||||
int
|
||||
_getattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
struct stat &st,
|
||||
@@ -71,7 +71,7 @@ _getattr(Policy::Func::Search searchFunc,
|
||||
string fullpath;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = searchFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -104,10 +104,10 @@ namespace mergerfs
|
||||
return _getattr_controlfile(*st);
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _getattr(config.getattr,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
*st,
|
||||
|
||||
+118
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -34,11 +34,20 @@
|
||||
#include "ugid.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
static const char SECURITY_CAPABILITY[] = "security.capability";
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
bool
|
||||
_is_attrname_security_capability(const char *attrname_)
|
||||
{
|
||||
return (strcmp(attrname_,SECURITY_CAPABILITY) == 0);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_lgetxattr(const string &path,
|
||||
@@ -96,7 +105,15 @@ void
|
||||
_getxattr_controlfile_srcmounts(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
attrvalue = str::join(config.srcmounts,':');
|
||||
attrvalue = config.branches.to_string();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_branches(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
attrvalue = config.branches.to_string(true);
|
||||
}
|
||||
|
||||
static
|
||||
@@ -131,6 +148,69 @@ _getxattr_controlfile_bool(const bool boolvalue,
|
||||
attrvalue = (boolvalue ? "true" : "false");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_errno(const int errno_,
|
||||
string &attrvalue)
|
||||
{
|
||||
switch(errno_)
|
||||
{
|
||||
case 0:
|
||||
attrvalue = "passthrough";
|
||||
break;
|
||||
case ENOATTR:
|
||||
attrvalue = "noattr";
|
||||
break;
|
||||
case ENOTSUP:
|
||||
attrvalue = "notsup";
|
||||
break;
|
||||
default:
|
||||
attrvalue = "ERROR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_statfs(const Config::StatFS::Enum enum_,
|
||||
string &attrvalue_)
|
||||
{
|
||||
switch(enum_)
|
||||
{
|
||||
case Config::StatFS::BASE:
|
||||
attrvalue_ = "base";
|
||||
break;
|
||||
case Config::StatFS::FULL:
|
||||
attrvalue_ = "full";
|
||||
break;
|
||||
default:
|
||||
attrvalue_ = "ERROR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_statfsignore(const Config::StatFSIgnore::Enum enum_,
|
||||
string &attrvalue_)
|
||||
{
|
||||
switch(enum_)
|
||||
{
|
||||
case Config::StatFSIgnore::NONE:
|
||||
attrvalue_ = "none";
|
||||
break;
|
||||
case Config::StatFSIgnore::RO:
|
||||
attrvalue_ = "ro";
|
||||
break;
|
||||
case Config::StatFSIgnore::NC:
|
||||
attrvalue_ = "nc";
|
||||
break;
|
||||
default:
|
||||
attrvalue_ = "ERROR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_policies(const Config &config,
|
||||
@@ -148,6 +228,8 @@ void
|
||||
_getxattr_controlfile_version(string &attrvalue)
|
||||
{
|
||||
attrvalue = MERGERFS_VERSION;
|
||||
if(attrvalue.empty())
|
||||
attrvalue = "unknown_possible_problem_with_build";
|
||||
}
|
||||
|
||||
static
|
||||
@@ -183,6 +265,8 @@ _getxattr_controlfile(const Config &config,
|
||||
case 3:
|
||||
if(attr[2] == "srcmounts")
|
||||
_getxattr_controlfile_srcmounts(config,attrvalue);
|
||||
else if(attr[2] == "branches")
|
||||
_getxattr_controlfile_branches(config,attrvalue);
|
||||
else if(attr[2] == "minfreespace")
|
||||
_getxattr_controlfile_uint64_t(config.minfreespace,attrvalue);
|
||||
else if(attr[2] == "moveonenospc")
|
||||
@@ -197,6 +281,16 @@ _getxattr_controlfile(const Config &config,
|
||||
_getxattr_controlfile_bool(config.nullrw,attrvalue);
|
||||
else if(attr[2] == "ignorepponrename")
|
||||
_getxattr_controlfile_bool(config.ignorepponrename,attrvalue);
|
||||
else if(attr[2] == "security_capability")
|
||||
_getxattr_controlfile_bool(config.security_capability,attrvalue);
|
||||
else if(attr[2] == "xattr")
|
||||
_getxattr_controlfile_errno(config.xattr,attrvalue);
|
||||
else if(attr[2] == "link_cow")
|
||||
_getxattr_controlfile_bool(config.link_cow,attrvalue);
|
||||
else if(attr[2] == "statfs")
|
||||
_getxattr_controlfile_statfs(config.statfs,attrvalue);
|
||||
else if(attr[2] == "statfs_ignore")
|
||||
_getxattr_controlfile_statfsignore(config.statfs_ignore,attrvalue);
|
||||
else if(attr[2] == "policies")
|
||||
_getxattr_controlfile_policies(config,attrvalue);
|
||||
else if(attr[2] == "version")
|
||||
@@ -250,15 +344,18 @@ _getxattr_from_string(char *destbuf,
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr_user_mergerfs_allpaths(const vector<string> &srcmounts,
|
||||
const char *fusepath,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
_getxattr_user_mergerfs_allpaths(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
string concated;
|
||||
vector<string> paths;
|
||||
vector<string> branches;
|
||||
|
||||
fs::findallfiles(srcmounts,fusepath,paths);
|
||||
branches_.to_paths(branches);
|
||||
|
||||
fs::findallfiles(branches,fusepath,paths);
|
||||
|
||||
concated = str::join(paths,'\0');
|
||||
|
||||
@@ -270,7 +367,7 @@ int
|
||||
_getxattr_user_mergerfs(const string &basepath,
|
||||
const char *fusepath,
|
||||
const string &fullpath,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const char *attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
@@ -286,7 +383,7 @@ _getxattr_user_mergerfs(const string &basepath,
|
||||
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 _getxattr_user_mergerfs_allpaths(branches_,fusepath,buf,count);
|
||||
|
||||
return -ENOATTR;
|
||||
}
|
||||
@@ -294,7 +391,7 @@ _getxattr_user_mergerfs(const string &basepath,
|
||||
static
|
||||
int
|
||||
_getxattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const size_t minfreespace,
|
||||
const char *fusepath,
|
||||
const char *attrname,
|
||||
@@ -305,14 +402,14 @@ _getxattr(Policy::Func::Search searchFunc,
|
||||
string fullpath;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = searchFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fs::path::make(basepaths[0],fusepath,fullpath);
|
||||
|
||||
if(str::isprefix(attrname,"user.mergerfs."))
|
||||
rv = _getxattr_user_mergerfs(*basepaths[0],fusepath,fullpath,srcmounts,attrname,buf,count);
|
||||
rv = _getxattr_user_mergerfs(*basepaths[0],fusepath,fullpath,branches_,attrname,buf,count);
|
||||
else
|
||||
rv = _lgetxattr(fullpath,attrname,buf,count);
|
||||
|
||||
@@ -338,11 +435,18 @@ namespace mergerfs
|
||||
buf,
|
||||
count);
|
||||
|
||||
if((config.security_capability == false) &&
|
||||
_is_attrname_security_capability(attrname))
|
||||
return -ENOATTR;
|
||||
|
||||
if(config.xattr)
|
||||
return -config.xattr;
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _getxattr(config.getxattr,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,45 +18,50 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "khash.h"
|
||||
#include "fasthash.h"
|
||||
|
||||
KHASH_SET_INIT_STR(strset);
|
||||
KHASH_SET_INIT_INT64(hashset);
|
||||
|
||||
class StrSet
|
||||
class HashSet
|
||||
{
|
||||
public:
|
||||
StrSet()
|
||||
HashSet()
|
||||
{
|
||||
_set = kh_init(strset);
|
||||
_set = kh_init(hashset);
|
||||
}
|
||||
|
||||
~StrSet()
|
||||
~HashSet()
|
||||
{
|
||||
for(khint_t k = kh_begin(_set), ek = kh_end(_set); k != ek; k++)
|
||||
if(kh_exist(_set,k))
|
||||
free((char*)kh_key(_set,k));
|
||||
|
||||
kh_destroy(strset,_set);
|
||||
kh_destroy(hashset,_set);
|
||||
}
|
||||
|
||||
inline
|
||||
int
|
||||
put(const char *str)
|
||||
put(const char *str_)
|
||||
{
|
||||
int rv;
|
||||
uint64_t h;
|
||||
khint_t key;
|
||||
|
||||
key = kh_put(strset,_set,str,&rv);
|
||||
h = fasthash64(str_,strlen(str_),0x7472617065786974);
|
||||
|
||||
key = kh_put(hashset,_set,h,&rv);
|
||||
if(rv == 0)
|
||||
return 0;
|
||||
|
||||
kh_key(_set,key) = strdup(str);
|
||||
kh_key(_set,key) = h;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline
|
||||
int
|
||||
size(void)
|
||||
{
|
||||
return kh_size(_set);
|
||||
}
|
||||
|
||||
private:
|
||||
khash_t(strset) *_set;
|
||||
khash_t(hashset) *_set;
|
||||
};
|
||||
+4
-4
@@ -69,7 +69,7 @@ _ioctl_file(fuse_file_info *ffi,
|
||||
static
|
||||
int
|
||||
_ioctl_dir_base(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const unsigned long cmd,
|
||||
@@ -80,7 +80,7 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,
|
||||
string fullpath;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = searchFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -108,10 +108,10 @@ _ioctl_dir(fuse_file_info *ffi,
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _ioctl_dir_base(config.getattr,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
di->fusepath.c_str(),
|
||||
cmd,
|
||||
|
||||
+28
-28
@@ -130,7 +130,6 @@ int main() {
|
||||
#include <limits.h>
|
||||
|
||||
/* compiler specific configuration */
|
||||
typedef unsigned char khint8_t;
|
||||
|
||||
#if UINT_MAX == 0xffffffffu
|
||||
typedef unsigned int khint32_t;
|
||||
@@ -163,17 +162,15 @@ typedef unsigned long long khint64_t;
|
||||
typedef khint32_t khint_t;
|
||||
typedef khint_t khiter_t;
|
||||
|
||||
#define __ac_bit_empty 0b00000010
|
||||
#define __ac_bit_deleted 0b00000001
|
||||
#define __ac_bit_any 0b11111111
|
||||
#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2)
|
||||
#define __ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1)
|
||||
#define __ac_iseither(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3)
|
||||
#define __ac_set_isdel_false(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isempty_false(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isboth_false(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isdel_true(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1))
|
||||
|
||||
#define __ac_isempty(flag, i) (flag[i]&__ac_bit_empty)
|
||||
#define __ac_isdel(flag, i) (flag[i]&__ac_bit_deleted)
|
||||
#define __ac_iseither(flag, i) (flag[i]&__ac_bit_any)
|
||||
#define __ac_set_isdel_false(flag, i) (flag[i]&=~__ac_bit_deleted)
|
||||
#define __ac_set_isempty_false(flag, i) (flag[i]&=~__ac_bit_empty)
|
||||
#define __ac_set_isboth_false(flag, i) (flag[i]=0)
|
||||
#define __ac_set_isdel_true(flag, i) (flag[i]|=__ac_bit_deleted)
|
||||
#define __ac_fsize(m) ((m) < 16? 1 : (m)>>4)
|
||||
|
||||
#ifndef kroundup32
|
||||
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
|
||||
@@ -197,7 +194,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
||||
#define __KHASH_TYPE(name, khkey_t, khval_t) \
|
||||
typedef struct kh_##name##_s { \
|
||||
khint_t n_buckets, size, n_occupied, upper_bound; \
|
||||
khint8_t *flags; \
|
||||
khint32_t *flags; \
|
||||
khkey_t *keys; \
|
||||
khval_t *vals; \
|
||||
} kh_##name##_t;
|
||||
@@ -226,7 +223,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
||||
SCOPE void kh_clear_##name(kh_##name##_t *h) \
|
||||
{ \
|
||||
if (h && h->flags) { \
|
||||
memset(h->flags, __ac_bit_empty, h->n_buckets); \
|
||||
memset(h->flags, 0xaa, __ac_fsize(h->n_buckets) * sizeof(khint32_t)); \
|
||||
h->size = h->n_occupied = 0; \
|
||||
} \
|
||||
} \
|
||||
@@ -246,16 +243,16 @@ static const double __ac_HASH_UPPER = 0.77;
|
||||
} \
|
||||
SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
|
||||
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
|
||||
khint8_t *new_flags = 0; \
|
||||
khint32_t *new_flags = 0; \
|
||||
khint_t j = 1; \
|
||||
{ \
|
||||
kroundup32(new_n_buckets); \
|
||||
if (new_n_buckets < 4) new_n_buckets = 4; \
|
||||
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
|
||||
else { /* hash table size to be changed (shrink or expand); rehash */ \
|
||||
new_flags = (khint8_t*)kmalloc(new_n_buckets); \
|
||||
new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
if (!new_flags) return -1; \
|
||||
memset(new_flags, __ac_bit_empty, new_n_buckets); \
|
||||
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
if (h->n_buckets < new_n_buckets) { /* expand */ \
|
||||
khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
|
||||
if (!new_keys) { kfree(new_flags); return -1; } \
|
||||
@@ -322,16 +319,19 @@ static const double __ac_HASH_UPPER = 0.77;
|
||||
{ \
|
||||
khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \
|
||||
x = site = h->n_buckets; k = __hash_func(key); i = k & mask; \
|
||||
last = i; \
|
||||
while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
|
||||
if (__ac_isdel(h->flags, i)) site = i; \
|
||||
i = (i + (++step)) & mask; \
|
||||
if (i == last) { x = site; break; } \
|
||||
} \
|
||||
if (x == h->n_buckets) { \
|
||||
if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \
|
||||
else x = i; \
|
||||
} \
|
||||
if (__ac_isempty(h->flags, i)) x = i; /* for speed up */ \
|
||||
else { \
|
||||
last = i; \
|
||||
while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
|
||||
if (__ac_isdel(h->flags, i)) site = i; \
|
||||
i = (i + (++step)) & mask; \
|
||||
if (i == last) { x = site; break; } \
|
||||
} \
|
||||
if (x == h->n_buckets) { \
|
||||
if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \
|
||||
else x = i; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
if (__ac_isempty(h->flags, x)) { /* not present at all */ \
|
||||
h->keys[x] = key; \
|
||||
@@ -576,7 +576,7 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
|
||||
code; \
|
||||
} }
|
||||
|
||||
/* More conenient interfaces */
|
||||
/* More convenient interfaces */
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash set containing integer keys
|
||||
@@ -594,7 +594,7 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
|
||||
KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing 64-bit integer keys
|
||||
@abstract Instantiate a hash set containing 64-bit integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define KHASH_SET_INIT_INT64(name) \
|
||||
|
||||
+28
-37
@@ -39,21 +39,12 @@ _link_create_path_core(const string &oldbasepath,
|
||||
const string &newbasepath,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath,
|
||||
const string &newfusedirpath,
|
||||
const int error)
|
||||
{
|
||||
int rv;
|
||||
string oldfullpath;
|
||||
string newfullpath;
|
||||
|
||||
if(oldbasepath != newbasepath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath);
|
||||
if(rv == -1)
|
||||
return errno;
|
||||
}
|
||||
|
||||
fs::path::make(&oldbasepath,oldfusepath,oldfullpath);
|
||||
fs::path::make(&oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
@@ -70,15 +61,19 @@ _link_create_path_loop(const vector<const string*> &oldbasepaths,
|
||||
const char *newfusepath,
|
||||
const string &newfusedirpath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = oldbasepaths.size(); i != ei; i++)
|
||||
{
|
||||
error = _link_create_path_core(*oldbasepaths[i],newbasepath,
|
||||
oldfusepath,newfusepath,
|
||||
newfusedirpath,
|
||||
error);
|
||||
rv = fs::clonepath_as_root(newbasepath,*oldbasepaths[i],newfusedirpath);
|
||||
if(rv == -1)
|
||||
error = error::calc(rv,error,errno);
|
||||
else
|
||||
error = _link_create_path_core(*oldbasepaths[i],newbasepath,
|
||||
oldfusepath,newfusepath,
|
||||
error);
|
||||
}
|
||||
|
||||
return -error;
|
||||
@@ -88,7 +83,7 @@ static
|
||||
int
|
||||
_link_create_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
@@ -98,13 +93,13 @@ _link_create_path(Policy::Func::Search searchFunc,
|
||||
vector<const string*> oldbasepaths;
|
||||
vector<const string*> newbasepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
|
||||
rv = actionFunc(branches_,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
newfusedirpath = newfusepath;
|
||||
fs::path::dirname(newfusedirpath);
|
||||
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepaths);
|
||||
newfusedirpath = fs::path::dirname(newfusepath);
|
||||
|
||||
rv = searchFunc(branches_,newfusedirpath,minfreespace,newbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -117,7 +112,7 @@ static
|
||||
int
|
||||
_clonepath_if_would_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const char *oldfusepath,
|
||||
@@ -125,33 +120,29 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc,
|
||||
{
|
||||
int rv;
|
||||
string newfusedirpath;
|
||||
const char *newfusedirpathcstr;
|
||||
vector<const string*> newbasepath;
|
||||
|
||||
newfusedirpath = newfusepath;
|
||||
fs::path::dirname(newfusedirpath);
|
||||
newfusedirpathcstr = newfusedirpath.c_str();
|
||||
newfusedirpath = fs::path::dirname(newfusepath);
|
||||
|
||||
rv = createFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath);
|
||||
rv = createFunc(branches_,newfusedirpath,minfreespace,newbasepath);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
if(oldbasepath != *newbasepath[0])
|
||||
return (errno=EXDEV,-1);
|
||||
|
||||
rv = searchFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath);
|
||||
rv = searchFunc(branches_,newfusedirpath,minfreespace,newbasepath);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
return fs::clonepath(*newbasepath[0],oldbasepath,newfusedirpathcstr);
|
||||
return fs::clonepath_as_root(*newbasepath[0],oldbasepath,newfusedirpath);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_link_preserve_path_core(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const char *oldfusepath,
|
||||
@@ -169,7 +160,7 @@ _link_preserve_path_core(Policy::Func::Search searchFunc,
|
||||
if((rv == -1) && (errno == ENOENT))
|
||||
{
|
||||
rv = _clonepath_if_would_create(searchFunc,createFunc,
|
||||
srcmounts,minfreespace,
|
||||
branches_,minfreespace,
|
||||
oldbasepath,
|
||||
oldfusepath,newfusepath);
|
||||
if(rv != -1)
|
||||
@@ -183,7 +174,7 @@ static
|
||||
int
|
||||
_link_preserve_path_loop(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath,
|
||||
@@ -195,7 +186,7 @@ _link_preserve_path_loop(Policy::Func::Search searchFunc,
|
||||
for(size_t i = 0, ei = oldbasepaths.size(); i != ei; i++)
|
||||
{
|
||||
error = _link_preserve_path_core(searchFunc,createFunc,
|
||||
srcmounts,minfreespace,
|
||||
branches_,minfreespace,
|
||||
*oldbasepaths[i],
|
||||
oldfusepath,newfusepath,
|
||||
error);
|
||||
@@ -209,7 +200,7 @@ int
|
||||
_link_preserve_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
@@ -217,12 +208,12 @@ _link_preserve_path(Policy::Func::Search searchFunc,
|
||||
int rv;
|
||||
vector<const string*> oldbasepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
|
||||
rv = actionFunc(branches_,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return _link_preserve_path_loop(searchFunc,createFunc,
|
||||
srcmounts,minfreespace,
|
||||
branches_,minfreespace,
|
||||
oldfusepath,newfusepath,
|
||||
oldbasepaths);
|
||||
}
|
||||
@@ -238,20 +229,20 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
if(config.create->path_preserving() && !config.ignorepponrename)
|
||||
return _link_preserve_path(config.getattr,
|
||||
config.link,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
from,
|
||||
to);
|
||||
|
||||
return _link_create_path(config.link,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
from,
|
||||
to);
|
||||
|
||||
+21
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -44,6 +44,7 @@ _listxattr_controlfile(char *list,
|
||||
const vector<string> strs =
|
||||
buildvector<string>
|
||||
("user.mergerfs.srcmounts")
|
||||
("user.mergerfs.branches")
|
||||
("user.mergerfs.minfreespace")
|
||||
("user.mergerfs.moveonenospc")
|
||||
("user.mergerfs.dropcacheonclose")
|
||||
@@ -51,6 +52,11 @@ _listxattr_controlfile(char *list,
|
||||
("user.mergerfs.symlinkify_timeout")
|
||||
("user.mergerfs.nullrw")
|
||||
("user.mergerfs.ignorepponrename")
|
||||
("user.mergerfs.link_cow")
|
||||
("user.mergerfs.security_capability")
|
||||
("user.mergerfs.xattr")
|
||||
("user.mergerfs.statfs")
|
||||
("user.mergerfs.statfs_ignore")
|
||||
("user.mergerfs.policies")
|
||||
("user.mergerfs.version")
|
||||
("user.mergerfs.pid");
|
||||
@@ -77,7 +83,7 @@ _listxattr_controlfile(char *list,
|
||||
static
|
||||
int
|
||||
_listxattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
char *list,
|
||||
@@ -87,7 +93,7 @@ _listxattr(Policy::Func::Search searchFunc,
|
||||
string fullpath;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = searchFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -113,11 +119,21 @@ namespace mergerfs
|
||||
if(fusepath == config.controlfile)
|
||||
return _listxattr_controlfile(list,size);
|
||||
|
||||
switch(config.xattr)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case ENOATTR:
|
||||
return 0;
|
||||
default:
|
||||
return -config.xattr;
|
||||
}
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _listxattr(config.listxattr,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
list,
|
||||
|
||||
+17
-25
@@ -34,7 +34,6 @@ using std::vector;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_mkdir_core(const string &fullpath,
|
||||
mode_t mode,
|
||||
@@ -48,10 +47,8 @@ _mkdir_core(const string &fullpath,
|
||||
|
||||
static
|
||||
int
|
||||
_mkdir_loop_core(const string &existingpath,
|
||||
const string &createpath,
|
||||
_mkdir_loop_core(const string &createpath,
|
||||
const char *fusepath,
|
||||
const char *fusedirpath,
|
||||
const mode_t mode,
|
||||
const mode_t umask,
|
||||
const int error)
|
||||
@@ -59,14 +56,6 @@ _mkdir_loop_core(const string &existingpath,
|
||||
int rv;
|
||||
string fullpath;
|
||||
|
||||
if(createpath != existingpath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
rv = fs::clonepath(existingpath,createpath,fusedirpath);
|
||||
if(rv == -1)
|
||||
return errno;
|
||||
}
|
||||
|
||||
fs::path::make(&createpath,fusepath,fullpath);
|
||||
|
||||
rv = _mkdir_core(fullpath,mode,umask);
|
||||
@@ -79,17 +68,23 @@ int
|
||||
_mkdir_loop(const string &existingpath,
|
||||
const vector<const string*> &createpaths,
|
||||
const char *fusepath,
|
||||
const char *fusedirpath,
|
||||
const string &fusedirpath,
|
||||
const mode_t mode,
|
||||
const mode_t umask)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
|
||||
{
|
||||
error = _mkdir_loop_core(existingpath,*createpaths[i],
|
||||
fusepath,fusedirpath,mode,umask,error);
|
||||
rv = fs::clonepath_as_root(existingpath,*createpaths[i],fusedirpath);
|
||||
if(rv == -1)
|
||||
error = error::calc(rv,error,errno);
|
||||
else
|
||||
error = _mkdir_loop_core(*createpaths[i],
|
||||
fusepath,
|
||||
mode,umask,error);
|
||||
}
|
||||
|
||||
return -error;
|
||||
@@ -99,7 +94,7 @@ static
|
||||
int
|
||||
_mkdir(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode,
|
||||
@@ -107,24 +102,21 @@ _mkdir(Policy::Func::Search searchFunc,
|
||||
{
|
||||
int rv;
|
||||
string fusedirpath;
|
||||
const char *fusedirpathcstr;
|
||||
vector<const string*> createpaths;
|
||||
vector<const string*> existingpaths;
|
||||
|
||||
fusedirpath = fusepath;
|
||||
fs::path::dirname(fusedirpath);
|
||||
fusedirpathcstr = fusedirpath.c_str();
|
||||
fusedirpath = fs::path::dirname(fusepath);
|
||||
|
||||
rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths);
|
||||
rv = searchFunc(branches_,fusedirpath,minfreespace,existingpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths);
|
||||
rv = createFunc(branches_,fusedirpath,minfreespace,createpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return _mkdir_loop(*existingpaths[0],createpaths,
|
||||
fusepath,fusedirpathcstr,mode,umask);
|
||||
fusepath,fusedirpath,mode,umask);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -138,11 +130,11 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _mkdir(config.getattr,
|
||||
config.mkdir,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode,
|
||||
|
||||
+17
-25
@@ -49,10 +49,8 @@ _mknod_core(const string &fullpath,
|
||||
|
||||
static
|
||||
int
|
||||
_mknod_loop_core(const string &existingpath,
|
||||
const string &createpath,
|
||||
_mknod_loop_core(const string &createpath,
|
||||
const char *fusepath,
|
||||
const char *fusedirpath,
|
||||
const mode_t mode,
|
||||
const mode_t umask,
|
||||
const dev_t dev,
|
||||
@@ -61,14 +59,6 @@ _mknod_loop_core(const string &existingpath,
|
||||
int rv;
|
||||
string fullpath;
|
||||
|
||||
if(createpath != existingpath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
rv = fs::clonepath(existingpath,createpath,fusedirpath);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path::make(&createpath,fusepath,fullpath);
|
||||
|
||||
rv = _mknod_core(fullpath,mode,umask,dev);
|
||||
@@ -81,19 +71,24 @@ int
|
||||
_mknod_loop(const string &existingpath,
|
||||
const vector<const string*> &createpaths,
|
||||
const char *fusepath,
|
||||
const char *fusedirpath,
|
||||
const string &fusedirpath,
|
||||
const mode_t mode,
|
||||
const mode_t umask,
|
||||
const dev_t dev)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
|
||||
{
|
||||
error = _mknod_loop_core(existingpath,*createpaths[i],
|
||||
fusepath,fusedirpath,
|
||||
mode,umask,dev,error);
|
||||
rv = fs::clonepath_as_root(existingpath,*createpaths[i],fusedirpath);
|
||||
if(rv == -1)
|
||||
error = error::calc(rv,error,errno);
|
||||
else
|
||||
error = _mknod_loop_core(*createpaths[i],
|
||||
fusepath,
|
||||
mode,umask,dev,error);
|
||||
}
|
||||
|
||||
return -error;
|
||||
@@ -103,7 +98,7 @@ static
|
||||
int
|
||||
_mknod(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode,
|
||||
@@ -112,24 +107,21 @@ _mknod(Policy::Func::Search searchFunc,
|
||||
{
|
||||
int rv;
|
||||
string fusedirpath;
|
||||
const char *fusedirpathcstr;
|
||||
vector<const string*> createpaths;
|
||||
vector<const string*> existingpaths;
|
||||
|
||||
fusedirpath = fusepath;
|
||||
fs::path::dirname(fusedirpath);
|
||||
fusedirpathcstr = fusedirpath.c_str();
|
||||
fusedirpath = fs::path::dirname(fusepath);
|
||||
|
||||
rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths);
|
||||
rv = searchFunc(branches_,fusedirpath,minfreespace,existingpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths);
|
||||
rv = createFunc(branches_,fusedirpath,minfreespace,createpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return _mknod_loop(*existingpaths[0],createpaths,
|
||||
fusepath,fusedirpathcstr,
|
||||
fusepath,fusedirpath,
|
||||
mode,umask,dev);
|
||||
}
|
||||
|
||||
@@ -145,11 +137,11 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _mknod(config.getattr,
|
||||
config.mknod,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode,
|
||||
|
||||
+34
-27
@@ -16,61 +16,67 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_cow.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_open_core(const string *basepath,
|
||||
const char *fusepath,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
_open_core(const string *basepath_,
|
||||
const char *fusepath_,
|
||||
const int flags_,
|
||||
const bool link_cow_,
|
||||
uint64_t &fh_)
|
||||
{
|
||||
int fd;
|
||||
string fullpath;
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
fs::path::make(basepath_,fusepath_,fullpath);
|
||||
|
||||
fd = fs::open(fullpath,flags);
|
||||
if(link_cow_ && fs::cow::is_eligible(fullpath.c_str(),flags_))
|
||||
fs::cow::break_link(fullpath.c_str());
|
||||
|
||||
fd = fs::open(fullpath,flags_);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
fh = reinterpret_cast<uint64_t>(new FileInfo(fd,fusepath));
|
||||
fh_ = reinterpret_cast<uint64_t>(new FileInfo(fd,fusepath_));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_open(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
_open(Policy::Func::Search searchFunc_,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace_,
|
||||
const char *fusepath_,
|
||||
const int flags_,
|
||||
const bool link_cow_,
|
||||
uint64_t &fh_)
|
||||
{
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = searchFunc_(branches_,fusepath_,minfreespace_,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return _open_core(basepaths[0],fusepath,flags,fh);
|
||||
return _open_core(basepaths[0],fusepath_,flags_,link_cow_,fh_);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -78,20 +84,21 @@ namespace mergerfs
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
open(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
open(const char *fusepath_,
|
||||
fuse_file_info *ffi_)
|
||||
{
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _open(config.open,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
ffi->flags,
|
||||
ffi->fh);
|
||||
fusepath_,
|
||||
ffi_->flags,
|
||||
config.link_cow,
|
||||
ffi_->fh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+107
-35
@@ -29,6 +29,8 @@
|
||||
#include <iomanip>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_glob.hpp"
|
||||
#include "num.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "str.hpp"
|
||||
@@ -71,14 +73,18 @@ set_kv_option(fuse_args &args,
|
||||
|
||||
static
|
||||
void
|
||||
set_fsname(fuse_args &args,
|
||||
const vector<string> &srcmounts)
|
||||
set_fsname(fuse_args &args,
|
||||
const Branches &branches_)
|
||||
{
|
||||
if(srcmounts.size() > 0)
|
||||
vector<string> branches;
|
||||
|
||||
branches_.to_paths(branches);
|
||||
|
||||
if(branches.size() > 0)
|
||||
{
|
||||
std::string fsname;
|
||||
|
||||
fsname = str::remove_common_prefix_and_join(srcmounts,':');
|
||||
fsname = str::remove_common_prefix_and_join(branches,':');
|
||||
|
||||
set_kv_option(args,"fsname",fsname);
|
||||
}
|
||||
@@ -147,6 +153,55 @@ parse_and_process(const std::string &value,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_errno(const std::string &value_,
|
||||
int &errno_)
|
||||
{
|
||||
if(value_ == "passthrough")
|
||||
errno_ = 0;
|
||||
else if(value_ == "notsup")
|
||||
errno_ = ENOTSUP;
|
||||
else if(value_ == "noattr")
|
||||
errno_ = ENOATTR;
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_statfs(const std::string &value_,
|
||||
Config::StatFS::Enum &enum_)
|
||||
{
|
||||
if(value_ == "base")
|
||||
enum_ = Config::StatFS::BASE;
|
||||
else if(value_ == "full")
|
||||
enum_ = Config::StatFS::FULL;
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_statfsignore(const std::string &value_,
|
||||
Config::StatFSIgnore::Enum &enum_)
|
||||
{
|
||||
if(value_ == "none")
|
||||
enum_ = Config::StatFSIgnore::NONE;
|
||||
else if(value_ == "ro")
|
||||
enum_ = Config::StatFSIgnore::RO;
|
||||
else if(value_ == "nc")
|
||||
enum_ = Config::StatFSIgnore::NC;
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_arg(Config &config,
|
||||
@@ -167,9 +222,10 @@ parse_and_process_kv_arg(Config &config,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
{
|
||||
int rv = -1;
|
||||
int rv;
|
||||
std::vector<std::string> keypart;
|
||||
|
||||
rv = -1;
|
||||
str::split(keypart,key,'.');
|
||||
if(keypart.size() == 2)
|
||||
{
|
||||
@@ -194,6 +250,16 @@ parse_and_process_kv_arg(Config &config,
|
||||
rv = parse_and_process(value,config.nullrw);
|
||||
else if(key == "ignorepponrename")
|
||||
rv = parse_and_process(value,config.ignorepponrename);
|
||||
else if(key == "security_capability")
|
||||
rv = parse_and_process(value,config.security_capability);
|
||||
else if(key == "link_cow")
|
||||
rv = parse_and_process(value,config.link_cow);
|
||||
else if(key == "xattr")
|
||||
rv = parse_and_process_errno(value,config.xattr);
|
||||
else if(key == "statfs")
|
||||
rv = parse_and_process_statfs(value,config.statfs);
|
||||
else if(key == "statfs_ignore")
|
||||
rv = parse_and_process_statfsignore(value,config.statfs_ignore);
|
||||
}
|
||||
|
||||
if(rv == -1)
|
||||
@@ -232,16 +298,10 @@ process_opt(Config &config,
|
||||
|
||||
static
|
||||
int
|
||||
process_srcmounts(const char *arg,
|
||||
Config &config)
|
||||
process_branches(const char *arg,
|
||||
Config &config)
|
||||
{
|
||||
vector<string> paths;
|
||||
|
||||
str::split(paths,arg,':');
|
||||
|
||||
fs::glob(paths,config.srcmounts);
|
||||
|
||||
fs::realpathize(config.srcmounts);
|
||||
config.branches.set(arg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -282,35 +342,45 @@ usage(void)
|
||||
" -o use_ino Have mergerfs generate inode values rather than\n"
|
||||
" autogenerated by libfuse. Suggested.\n"
|
||||
" -o minfreespace=<int> minimum free space needed for certain policies.\n"
|
||||
" default=4G\n"
|
||||
" default = 4G\n"
|
||||
" -o moveonenospc=<bool> Try to move file to another drive when ENOSPC\n"
|
||||
" on write. default=false\n"
|
||||
" on write. default = false\n"
|
||||
" -o dropcacheonclose=<bool>\n"
|
||||
" When a file is closed suggest to OS it drop\n"
|
||||
" the file's cache. This is useful when direct_io\n"
|
||||
" is disabled. default=false\n"
|
||||
" is disabled. default = false\n"
|
||||
" -o symlinkify=<bool> Read-only files, after a timeout, will be turned\n"
|
||||
" into symlinks. Read docs for limitations and\n"
|
||||
" possible issues. default=false\n"
|
||||
" possible issues. default = false\n"
|
||||
" -o symlinkify_timeout=<int>\n"
|
||||
" timeout in seconds before will turn to symlinks.\n"
|
||||
" default=3600\n"
|
||||
" default = 3600\n"
|
||||
" -o nullrw=<bool> Disables reads and writes. For benchmarking.\n"
|
||||
" default = false\n"
|
||||
" -o ignorepponrename=<bool>\n"
|
||||
" Ignore path preserving when performing renames\n"
|
||||
" and links. default = false\n"
|
||||
" -o threads=<int> number of worker threads. 0 = autodetect.\n"
|
||||
" Negative values autodetect then divide by\n"
|
||||
" absolute value. default = 0\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
version(void)
|
||||
{
|
||||
std::cout << "mergerfs version: "
|
||||
<< MERGERFS_VERSION
|
||||
" -o link_cow=<bool> delink/clone file on open to simulate CoW.\n"
|
||||
" default = false\n"
|
||||
" -o security_capability=<bool>\n"
|
||||
" When disabled return ENOATTR when the xattr\n"
|
||||
" security.capability is queried. default = true\n"
|
||||
" -o xattr=passthrough|noattr|notsup\n"
|
||||
" Runtime control of xattrs. By default xattr\n"
|
||||
" requests will pass through to the underlying\n"
|
||||
" filesystems. notattr will short circuit as if\n"
|
||||
" nothing exists. notsup will respond as if not\n"
|
||||
" supported or disabled. default = passthrough\n"
|
||||
" -o statfs=base|full When set to 'base' statfs will use all branches\n"
|
||||
" when performing statfs calculations. 'full' will\n"
|
||||
" only include branches on which that path is\n"
|
||||
" available. default = base\n"
|
||||
" -o statfs_ignore=none|ro|nc\n"
|
||||
" 'ro' will cause statfs calculations to ignore\n"
|
||||
" available space for branches mounted or tagged\n"
|
||||
" as 'read only' or 'no create'. 'nc' will ignore\n"
|
||||
" available space for branches tagged as\n"
|
||||
" 'no create'. default = none\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -331,8 +401,8 @@ option_processor(void *data,
|
||||
break;
|
||||
|
||||
case FUSE_OPT_KEY_NONOPT:
|
||||
rv = config.srcmounts.empty() ?
|
||||
process_srcmounts(arg,config) :
|
||||
rv = config.branches.empty() ?
|
||||
process_branches(arg,config) :
|
||||
process_destmounts(arg,config);
|
||||
break;
|
||||
|
||||
@@ -344,7 +414,9 @@ option_processor(void *data,
|
||||
break;
|
||||
|
||||
case MERGERFS_OPT_VERSION:
|
||||
version();
|
||||
std::cout << "mergerfs version: "
|
||||
<< (MERGERFS_VERSION[0] ? MERGERFS_VERSION : "unknown")
|
||||
<< std::endl;
|
||||
fuse_opt_add_arg(outargs,"--version");
|
||||
break;
|
||||
|
||||
@@ -379,7 +451,7 @@ namespace mergerfs
|
||||
opts,
|
||||
::option_processor);
|
||||
|
||||
set_fsname(args,config.srcmounts);
|
||||
set_fsname(args,config.branches);
|
||||
set_subtype(args);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-28
@@ -16,19 +16,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "branch.hpp"
|
||||
#include "category.hpp"
|
||||
#include "fs.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "category.hpp"
|
||||
|
||||
#define POLICY_SUCCESS 0
|
||||
#define POLICY_FAIL -1
|
||||
#define POLICY_SUCCEEDED(RV) ((RV) == POLICY_SUCCESS)
|
||||
#define POLICY_FAILED(RV) ((RV) == POLICY_FAIL)
|
||||
#define POLICY_FAIL_ERRNO(ERRNO) (errno=ERRNO,POLICY_FAIL)
|
||||
#define POLICY_FAIL_ENOENT POLICY_FAIL_ERRNO(ENOENT)
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
@@ -72,7 +66,7 @@ namespace mergerfs
|
||||
typedef const strvec cstrvec;
|
||||
typedef const Category::Enum::Type CType;
|
||||
|
||||
typedef int (*Ptr)(CType,cstrvec &,const char *,cuint64_t,cstrptrvec &);
|
||||
typedef int (*Ptr)(CType,const Branches &,const char *,cuint64_t,cstrptrvec &);
|
||||
|
||||
template <CType T>
|
||||
class Base
|
||||
@@ -83,11 +77,17 @@ namespace mergerfs
|
||||
{}
|
||||
|
||||
int
|
||||
operator()(cstrvec &b,const char *c,cuint64_t d,cstrptrvec &e)
|
||||
operator()(const Branches &b,const char *c,cuint64_t d,cstrptrvec &e)
|
||||
{
|
||||
return func(T,b,c,d,e);
|
||||
}
|
||||
|
||||
int
|
||||
operator()(const Branches &b,const string &c,cuint64_t d,cstrptrvec &e)
|
||||
{
|
||||
return func(T,b,c.c_str(),d,e);
|
||||
}
|
||||
|
||||
private:
|
||||
const Ptr func;
|
||||
};
|
||||
@@ -96,21 +96,21 @@ namespace mergerfs
|
||||
typedef Base<Category::Enum::create> Create;
|
||||
typedef Base<Category::Enum::search> Search;
|
||||
|
||||
static int invalid(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int all(CType,cstrvec&,const char*,cuint64_t,cstrptrvec&);
|
||||
static int epall(CType,cstrvec&,const char*,cuint64_t,cstrptrvec&);
|
||||
static int epff(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eplfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eplus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int epmfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eprand(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int erofs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int ff(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int lfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int lus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int mfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int newest(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int rand(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int invalid(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int all(CType,const Branches&,const char*,cuint64_t,cstrptrvec&);
|
||||
static int epall(CType,const Branches&,const char*,cuint64_t,cstrptrvec&);
|
||||
static int epff(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eplfs(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eplus(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int epmfs(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eprand(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int erofs(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int ff(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int lfs(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int lus(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int mfs(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int newest(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int rand(CType,const Branches&,const char *,cuint64_t,cstrptrvec&);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
+39
-54
@@ -14,84 +14,69 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
static
|
||||
int
|
||||
_all_create(const vector<string> &basepaths,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace all
|
||||
{
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
error = ENOENT;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
|
||||
if(paths.empty())
|
||||
return POLICY_FAIL_ENOENT;
|
||||
paths.push_back(&branch->path);
|
||||
}
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
if(paths.empty())
|
||||
return (errno=error,-1);
|
||||
|
||||
static
|
||||
int
|
||||
_all_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
|
||||
if(paths.empty())
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::all(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _all_create(basepaths,minfreespace,paths);
|
||||
return all::create(branches_,minfreespace,paths);
|
||||
|
||||
return _all_other(basepaths,fusepath,paths);
|
||||
return Policy::Func::epall(type,branches_,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
|
||||
+101
-54
@@ -14,91 +14,138 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
static
|
||||
int
|
||||
_epall_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace epall
|
||||
{
|
||||
string fullpath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
paths.push_back(&branch->path);
|
||||
}
|
||||
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
if(paths.empty())
|
||||
return (errno=error,-1);
|
||||
|
||||
if(paths.empty())
|
||||
return POLICY_FAIL_ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
static
|
||||
int
|
||||
action(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
bool readonly;
|
||||
const Branch *branch;
|
||||
|
||||
static
|
||||
int
|
||||
_epall_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
error = ENOENT;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string *basepath = &basepaths[i];
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::readonly(&branch->path,&readonly);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
paths.push_back(&branch->path);
|
||||
}
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(paths.empty())
|
||||
return (errno=error,-1);
|
||||
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(paths.empty())
|
||||
return POLICY_FAIL_ENOENT;
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
const Branch *branch;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
continue;
|
||||
|
||||
paths.push_back(&branch->path);
|
||||
}
|
||||
|
||||
if(paths.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::epall(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _epall_create(basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _epall_other(basepaths,fusepath,paths);
|
||||
switch(type)
|
||||
{
|
||||
case Category::Enum::create:
|
||||
return epall::create(branches_,fusepath,minfreespace,paths);
|
||||
case Category::Enum::action:
|
||||
return epall::action(branches_,fusepath,paths);
|
||||
case Category::Enum::search:
|
||||
default:
|
||||
return epall::search(branches_,fusepath,paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+103
-84
@@ -14,117 +14,136 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_epff_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace epff
|
||||
{
|
||||
string fullpath;
|
||||
const string *fallback;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
|
||||
fallback = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(fallback == NULL)
|
||||
fallback = basepath;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
paths.push_back(&branch->path);
|
||||
|
||||
paths.push_back(basepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
return (errno=error,-1);
|
||||
}
|
||||
|
||||
if(fallback == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
static
|
||||
int
|
||||
action(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
bool readonly;
|
||||
const Branch *branch;
|
||||
|
||||
paths.push_back(fallback);
|
||||
error = ENOENT;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::readonly(&branch->path,&readonly);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
|
||||
paths.push_back(&branch->path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (errno=error,-1);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
const Branch *branch;
|
||||
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
continue;
|
||||
|
||||
paths.push_back(&branch->path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (errno=ENOENT,-1);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epff_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
return POLICY_FAIL_ENOENT;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epff(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _epff_create(basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _epff_other(basepaths,fusepath,paths);
|
||||
}
|
||||
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::epff(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = _epff(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
switch(type)
|
||||
{
|
||||
case Category::Enum::create:
|
||||
return epff::create(branches_,fusepath,minfreespace,paths);
|
||||
case Category::Enum::action:
|
||||
return epff::action(branches_,fusepath,paths);
|
||||
case Category::Enum::search:
|
||||
default:
|
||||
return epff::search(branches_,fusepath,paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+131
-90
@@ -14,131 +14,172 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_eplfs_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace eplfs
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t eplfs;
|
||||
const string *eplfsbasepath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplfs;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *eplfsbasepath;
|
||||
|
||||
eplfs = std::numeric_limits<uint64_t>::max();
|
||||
eplfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
eplfs = std::numeric_limits<uint64_t>::max();
|
||||
eplfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceavail > eplfs)
|
||||
continue;
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceavail > eplfs)
|
||||
continue;
|
||||
eplfs = info.spaceavail;
|
||||
eplfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
eplfs = spaceavail;
|
||||
eplfsbasepath = basepath;
|
||||
}
|
||||
if(eplfsbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
if(eplfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
paths.push_back(eplfsbasepath);
|
||||
|
||||
paths.push_back(eplfsbasepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
static
|
||||
int
|
||||
action(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplfs;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *eplfsbasepath;
|
||||
|
||||
static
|
||||
int
|
||||
_eplfs_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t eplfs;
|
||||
const string *eplfsbasepath;
|
||||
error = ENOENT;
|
||||
eplfs = std::numeric_limits<uint64_t>::max();
|
||||
eplfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
eplfs = std::numeric_limits<uint64_t>::max();
|
||||
eplfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceavail;
|
||||
const string *basepath = &basepaths[i];
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail > eplfs)
|
||||
continue;
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
eplfs = info.spaceavail;
|
||||
eplfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::spaceavail(*basepath,spaceavail))
|
||||
continue;
|
||||
if(spaceavail > eplfs)
|
||||
continue;
|
||||
if(eplfsbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
eplfs = spaceavail;
|
||||
eplfsbasepath = basepath;
|
||||
}
|
||||
paths.push_back(eplfsbasepath);
|
||||
|
||||
if(eplfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
paths.push_back(eplfsbasepath);
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
uint64_t eplfs;
|
||||
uint64_t spaceavail;
|
||||
const Branch *branch;
|
||||
const string *eplfsbasepath;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
eplfs = std::numeric_limits<uint64_t>::max();
|
||||
eplfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
static
|
||||
int
|
||||
_eplfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _eplfs_create(basepaths,fusepath,minfreespace,paths);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
continue;
|
||||
rv = fs::spaceavail(&branch->path,&spaceavail);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
if(spaceavail > eplfs)
|
||||
continue;
|
||||
|
||||
return _eplfs_other(basepaths,fusepath,paths);
|
||||
eplfs = spaceavail;
|
||||
eplfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(eplfsbasepath == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(eplfsbasepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::eplfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = _eplfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::lfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
switch(type)
|
||||
{
|
||||
case Category::Enum::create:
|
||||
return eplfs::create(branches_,fusepath,minfreespace,paths);
|
||||
case Category::Enum::action:
|
||||
return eplfs::action(branches_,fusepath,paths);
|
||||
case Category::Enum::search:
|
||||
default:
|
||||
return eplfs::search(branches_,fusepath,paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+131
-90
@@ -14,131 +14,172 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_eplus_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace eplus
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t eplus;
|
||||
const string *eplusbasepath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *eplusbasepath;
|
||||
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
eplusbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
eplusbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail,spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceused >= eplus)
|
||||
continue;
|
||||
eplus = info.spaceused;
|
||||
eplusbasepath = &branch->path;
|
||||
}
|
||||
|
||||
eplus = spaceused;
|
||||
eplusbasepath = basepath;
|
||||
}
|
||||
if(eplusbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
if(eplusbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
paths.push_back(eplusbasepath);
|
||||
|
||||
paths.push_back(eplusbasepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
static
|
||||
int
|
||||
action(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *eplusbasepath;
|
||||
|
||||
static
|
||||
int
|
||||
_eplus_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t eplus;
|
||||
const string *eplusbasepath;
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
eplusbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
eplus = 0;
|
||||
eplusbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
eplus = info.spaceused;
|
||||
eplusbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::spaceused(*basepath,spaceused))
|
||||
continue;
|
||||
if(spaceused >= eplus)
|
||||
continue;
|
||||
if(eplusbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
eplus = spaceused;
|
||||
eplusbasepath = basepath;
|
||||
}
|
||||
paths.push_back(eplusbasepath);
|
||||
|
||||
if(eplusbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
paths.push_back(eplusbasepath);
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
uint64_t eplus;
|
||||
uint64_t spaceused;
|
||||
const Branch *branch;
|
||||
const string *eplusbasepath;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
eplus = 0;
|
||||
eplusbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
static
|
||||
int
|
||||
_eplus(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _eplus_create(basepaths,fusepath,minfreespace,paths);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
continue;
|
||||
rv = fs::spaceused(&branch->path,&spaceused);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
if(spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
return _eplus_other(basepaths,fusepath,paths);
|
||||
eplus = spaceused;
|
||||
eplusbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(eplusbasepath == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(eplusbasepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::eplus(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = _eplus(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::lus(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
switch(type)
|
||||
{
|
||||
case Category::Enum::create:
|
||||
return eplus::create(branches_,fusepath,minfreespace,paths);
|
||||
case Category::Enum::action:
|
||||
return eplus::action(branches_,fusepath,paths);
|
||||
case Category::Enum::search:
|
||||
default:
|
||||
return eplus::search(branches_,fusepath,paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+131
-90
@@ -14,131 +14,172 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_epmfs_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace epmfs
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t epmfs;
|
||||
const string *epmfsbasepath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t epmfs;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *epmfsbasepath;
|
||||
|
||||
epmfs = std::numeric_limits<uint64_t>::min();
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
epmfs = std::numeric_limits<uint64_t>::min();
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceavail < epmfs)
|
||||
continue;
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceavail < epmfs)
|
||||
continue;
|
||||
epmfs = info.spaceavail;
|
||||
epmfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
epmfs = spaceavail;
|
||||
epmfsbasepath = basepath;
|
||||
}
|
||||
if(epmfsbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
if(epmfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
paths.push_back(epmfsbasepath);
|
||||
|
||||
paths.push_back(epmfsbasepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
static
|
||||
int
|
||||
action(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t epmfs;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *epmfsbasepath;
|
||||
|
||||
static
|
||||
int
|
||||
_epmfs_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t epmfs;
|
||||
const string *epmfsbasepath;
|
||||
error = ENOENT;
|
||||
epmfs = std::numeric_limits<uint64_t>::min();
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
epmfs = 0;
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceavail;
|
||||
const string *basepath = &basepaths[i];
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < epmfs)
|
||||
continue;
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
epmfs = info.spaceavail;
|
||||
epmfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::spaceavail(*basepath,spaceavail))
|
||||
continue;
|
||||
if(spaceavail < epmfs)
|
||||
continue;
|
||||
if(epmfsbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
epmfs = spaceavail;
|
||||
epmfsbasepath = basepath;
|
||||
}
|
||||
paths.push_back(epmfsbasepath);
|
||||
|
||||
if(epmfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
paths.push_back(epmfsbasepath);
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
uint64_t epmfs;
|
||||
uint64_t spaceavail;
|
||||
const Branch *branch;
|
||||
const string *epmfsbasepath;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
epmfs = 0;
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
static
|
||||
int
|
||||
_epmfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _epmfs_create(basepaths,fusepath,minfreespace,paths);
|
||||
if(!fs::exists(branch->path,fusepath))
|
||||
continue;
|
||||
rv = fs::spaceavail(&branch->path,&spaceavail);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
if(spaceavail < epmfs)
|
||||
continue;
|
||||
|
||||
return _epmfs_other(basepaths,fusepath,paths);
|
||||
epmfs = spaceavail;
|
||||
epmfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(epmfsbasepath == NULL)
|
||||
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 Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = _epmfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
switch(type)
|
||||
{
|
||||
case Category::Enum::create:
|
||||
return epmfs::create(branches_,fusepath,minfreespace,paths);
|
||||
case Category::Enum::action:
|
||||
return epmfs::action(branches_,fusepath,paths);
|
||||
case Category::Enum::search:
|
||||
default:
|
||||
return epmfs::search(branches_,fusepath,paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "success_fail.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
@@ -29,15 +28,15 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::eprand(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = Policy::Func::epall(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_SUCCEEDED(rv))
|
||||
rv = Policy::Func::epall(type,branches_,fusepath,minfreespace,paths);
|
||||
if(rv == 0)
|
||||
std::random_shuffle(paths.begin(),paths.end());
|
||||
|
||||
return rv;
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
@@ -27,11 +27,11 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::erofs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
return POLICY_FAIL_ERRNO(EROFS);
|
||||
return (errno=EROFS,-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define error_and_continue(CUR,ERR) \
|
||||
{ \
|
||||
policy::calc_error(CUR,ERR); \
|
||||
continue; \
|
||||
}
|
||||
|
||||
namespace policy
|
||||
{
|
||||
static
|
||||
inline
|
||||
void
|
||||
calc_error(int &cur_,
|
||||
int err_)
|
||||
{
|
||||
switch(cur_)
|
||||
{
|
||||
default:
|
||||
case ENOENT:
|
||||
cur_ = err_;
|
||||
break;
|
||||
case ENOSPC:
|
||||
if(err_ != ENOENT)
|
||||
cur_ = err_;
|
||||
break;
|
||||
case EROFS:
|
||||
if((err_ != ENOENT) && (err_ != ENOSPC))
|
||||
cur_ = err_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
-61
@@ -14,92 +14,69 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
static
|
||||
int
|
||||
_ff_create(const vector<string> &basepaths,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace ff
|
||||
{
|
||||
const string *fallback;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
|
||||
fallback = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(fallback == NULL)
|
||||
fallback = basepath;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
|
||||
paths.push_back(basepath);
|
||||
paths.push_back(&branch->path);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(fallback == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
paths.push_back(fallback);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_ff_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
return POLICY_FAIL_ENOENT;
|
||||
return (errno=error,-1);
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::ff(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _ff_create(basepaths,minfreespace,paths);
|
||||
return ff::create(branches_,minfreespace,paths);
|
||||
|
||||
return _ff_other(basepaths,fusepath,paths);
|
||||
return Policy::Func::epff(type,branches_,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
@@ -27,11 +27,11 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::invalid(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
return POLICY_FAIL_ERRNO(EINVAL);
|
||||
return (errno=EINVAL,-1);
|
||||
}
|
||||
}
|
||||
|
||||
+50
-96
@@ -14,127 +14,81 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_lfs_create(const vector<string> &basepaths,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace lfs
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t lfs;
|
||||
const string *lfsbasepath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t lfs;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *lfsbasepath;
|
||||
|
||||
lfs = std::numeric_limits<uint64_t>::max();
|
||||
lfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
lfs = std::numeric_limits<uint64_t>::max();
|
||||
lfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceavail > lfs)
|
||||
continue;
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceavail > lfs)
|
||||
continue;
|
||||
|
||||
lfs = spaceavail;
|
||||
lfsbasepath = basepath;
|
||||
}
|
||||
lfs = info.spaceavail;
|
||||
lfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(lfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
if(lfsbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths.push_back(lfsbasepath);
|
||||
paths.push_back(lfsbasepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_lfs_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t lfs;
|
||||
const string *lfsbasepath;
|
||||
|
||||
lfs = std::numeric_limits<uint64_t>::max();
|
||||
lfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceavail;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::spaceavail(*basepath,spaceavail))
|
||||
continue;
|
||||
if(spaceavail > lfs)
|
||||
continue;
|
||||
|
||||
lfs = spaceavail;
|
||||
lfsbasepath = basepath;
|
||||
}
|
||||
|
||||
if(lfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
paths.push_back(lfsbasepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_lfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _lfs_create(basepaths,minfreespace,paths);
|
||||
|
||||
return _lfs_other(basepaths,fusepath,paths);
|
||||
}
|
||||
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::lfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
if(type == Category::Enum::create)
|
||||
return lfs::create(branches_,minfreespace,paths);
|
||||
|
||||
rv = _lfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
return Policy::Func::eplfs(type,branches_,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
|
||||
+50
-95
@@ -14,126 +14,81 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_lus_create(const vector<string> &basepaths,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
namespace lus
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t lus;
|
||||
const string *lusbasepath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t lus;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *lusbasepath;
|
||||
|
||||
lus = std::numeric_limits<uint64_t>::max();
|
||||
lusbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceused;
|
||||
uint64_t spaceavail;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
lus = std::numeric_limits<uint64_t>::max();
|
||||
lusbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::info(*basepath,readonly,spaceavail,spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceused >= lus)
|
||||
continue;
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceused >= lus)
|
||||
continue;
|
||||
|
||||
lus = spaceused;
|
||||
lusbasepath = basepath;
|
||||
}
|
||||
lus = info.spaceused;
|
||||
lusbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(lusbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
if(lusbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths.push_back(lusbasepath);
|
||||
paths.push_back(lusbasepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_lus_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t lus;
|
||||
const string *lusbasepath;
|
||||
|
||||
lus = 0;
|
||||
lusbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::spaceused(*basepath,spaceused))
|
||||
continue;
|
||||
if(spaceused >= lus)
|
||||
continue;
|
||||
|
||||
lus = spaceused;
|
||||
lusbasepath = basepath;
|
||||
}
|
||||
|
||||
if(lusbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
paths.push_back(lusbasepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_lus(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _lus_create(basepaths,minfreespace,paths);
|
||||
|
||||
return _lus_other(basepaths,fusepath,paths);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::lus(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
if(type == Category::Enum::create)
|
||||
return lus::create(branches_,minfreespace,paths);
|
||||
|
||||
rv = _lus(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
return Policy::Func::eplus(type,branches_,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
|
||||
+48
-89
@@ -14,121 +14,80 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_mfs_create(const vector<string> &basepaths,
|
||||
vector<const string*> &paths)
|
||||
namespace mfs
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t mfs;
|
||||
const string *mfsbasepath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t mfs;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *mfsbasepath;
|
||||
|
||||
mfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
error = ENOENT;
|
||||
mfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < mfs)
|
||||
continue;
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(&branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace)
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceavail < mfs)
|
||||
continue;
|
||||
|
||||
mfs = spaceavail;
|
||||
mfsbasepath = basepath;
|
||||
}
|
||||
mfs = info.spaceavail;
|
||||
mfsbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(mfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
if(mfsbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths.push_back(mfsbasepath);
|
||||
paths.push_back(mfsbasepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_mfs_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
uint64_t mfs;
|
||||
const string *mfsbasepath;
|
||||
|
||||
mfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceavail;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::spaceavail(*basepath,spaceavail))
|
||||
continue;
|
||||
if(spaceavail < mfs)
|
||||
continue;
|
||||
|
||||
mfs = spaceavail;
|
||||
mfsbasepath = basepath;
|
||||
}
|
||||
|
||||
if(mfsbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
paths.push_back(mfsbasepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_mfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _mfs_create(basepaths,paths);
|
||||
|
||||
return _mfs_other(basepaths,fusepath,paths);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::mfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
if(type == Category::Enum::create)
|
||||
return mfs::create(branches_,minfreespace,paths);
|
||||
|
||||
rv = _mfs(type,basepaths,fusepath,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
return Policy::Func::epmfs(type,branches_,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
|
||||
+126
-67
@@ -14,108 +14,167 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "policy_error.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "success_fail.hpp"
|
||||
#include <sys/stat.h>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
static
|
||||
int
|
||||
_newest_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
namespace newest
|
||||
{
|
||||
time_t newest;
|
||||
string fullpath;
|
||||
const string *newestbasepath;
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
bool readonly;
|
||||
time_t newest;
|
||||
struct stat st;
|
||||
const Branch *branch;
|
||||
const string *newestbasepath;
|
||||
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
error = ENOENT;
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
struct stat st;
|
||||
const string *basepath = &basepaths[i];
|
||||
if(!fs::exists(branch->path,fusepath,st))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
rv = fs::readonly(&branch->path,&readonly);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(!fs::exists(fullpath,st))
|
||||
continue;
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
if(fs::readonly(*basepath))
|
||||
continue;
|
||||
if(newestbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = basepath;
|
||||
}
|
||||
paths.push_back(newestbasepath);
|
||||
|
||||
if(newestbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
paths.push_back(newestbasepath);
|
||||
static
|
||||
int
|
||||
action(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
bool readonly;
|
||||
time_t newest;
|
||||
struct stat st;
|
||||
const Branch *branch;
|
||||
const string *newestbasepath;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
error = ENOENT;
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
static
|
||||
int
|
||||
_newest_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
time_t newest;
|
||||
string fullpath;
|
||||
const string *newestbasepath;
|
||||
if(!fs::exists(branch->path,fusepath,st))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
rv = fs::readonly(&branch->path,&readonly);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
struct stat st;
|
||||
const string *basepath = &basepaths[i];
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = &branch->path;
|
||||
}
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
if(newestbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
if(!fs::exists(fullpath,st))
|
||||
continue;
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
paths.push_back(newestbasepath);
|
||||
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = basepath;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(newestbasepath == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
time_t newest;
|
||||
struct stat st;
|
||||
const Branch *branch;
|
||||
const string *newestbasepath;
|
||||
|
||||
paths.push_back(newestbasepath);
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
if(!fs::exists(branch->path,fusepath,st))
|
||||
continue;
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(newestbasepath == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(newestbasepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::newest(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _newest_create(basepaths,fusepath,paths);
|
||||
|
||||
return _newest_other(basepaths,fusepath,paths);
|
||||
switch(type)
|
||||
{
|
||||
case Category::Enum::create:
|
||||
return newest::create(branches_,fusepath,paths);
|
||||
case Category::Enum::action:
|
||||
return newest::action(branches_,fusepath,paths);
|
||||
case Category::Enum::search:
|
||||
default:
|
||||
return newest::search(branches_,fusepath,paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -14,14 +14,13 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "success_fail.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
@@ -29,15 +28,15 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::rand(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = Policy::Func::all(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_SUCCEEDED(rv))
|
||||
rv = Policy::Func::all(type,branches_,fusepath,minfreespace,paths);
|
||||
if(rv == 0)
|
||||
std::random_shuffle(paths.begin(),paths.end());
|
||||
|
||||
return rv;
|
||||
|
||||
+8
-9
@@ -14,12 +14,11 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#define _BSD_SOURCE
|
||||
#define _DEFAULT_SOURCE
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
@@ -33,9 +32,9 @@
|
||||
#include "fs_devid.hpp"
|
||||
#include "fs_inode.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "hashset.hpp"
|
||||
#include "readdir.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "strset.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
@@ -45,22 +44,22 @@ using std::vector;
|
||||
|
||||
static
|
||||
int
|
||||
_readdir(const vector<string> &srcmounts,
|
||||
_readdir(const Branches &branches_,
|
||||
const char *dirname,
|
||||
void *buf,
|
||||
const fuse_fill_dir_t filler)
|
||||
{
|
||||
StrSet names;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
struct stat st = {0};
|
||||
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
int dirfd;
|
||||
DIR *dh;
|
||||
|
||||
fs::path::make(&srcmounts[i],dirname,basepath);
|
||||
basepath = fs::path::make(&branches_[i].path,dirname);
|
||||
|
||||
dh = fs::opendir(basepath);
|
||||
if(!dh)
|
||||
@@ -109,9 +108,9 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return ::_readdir(config.srcmounts,
|
||||
return ::_readdir(config.branches,
|
||||
di->fusepath.c_str(),
|
||||
buf,
|
||||
filler);
|
||||
|
||||
+4
-4
@@ -93,7 +93,7 @@ _readlink_core(const string *basepath,
|
||||
static
|
||||
int
|
||||
_readlink(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
char *buf,
|
||||
@@ -104,7 +104,7 @@ _readlink(Policy::Func::Search searchFunc,
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = searchFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -124,10 +124,10 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _readlink(config.readlink,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
buf,
|
||||
|
||||
+7
-5
@@ -69,7 +69,7 @@ _removexattr_loop(const vector<const string*> &basepaths,
|
||||
static
|
||||
int
|
||||
_removexattr(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const char *attrname)
|
||||
@@ -77,7 +77,7 @@ _removexattr(Policy::Func::Action actionFunc,
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = actionFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -96,13 +96,15 @@ namespace mergerfs
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -ENOTSUP;
|
||||
return -ENOATTR;
|
||||
if(config.xattr)
|
||||
return -config.xattr;
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _removexattr(config.removexattr,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname);
|
||||
|
||||
+53
-71
@@ -27,7 +27,6 @@
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "success_fail.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
@@ -57,27 +56,6 @@ _remove(const vector<string> &toremove)
|
||||
fs::remove(toremove[i]);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_rename(const std::string &oldbasepath,
|
||||
const std::string &oldfullpath,
|
||||
const std::string &newbasepath,
|
||||
const std::string &newfusedirpath,
|
||||
const std::string &newfullpath)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if(oldbasepath != newbasepath)
|
||||
{
|
||||
const ugid::SetRootGuard guard;
|
||||
rv = fs::clonepath(newbasepath,oldbasepath,newfusedirpath);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fs::rename(oldfullpath,newfullpath);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_rename_create_path_core(const vector<const string*> &oldbasepaths,
|
||||
@@ -94,21 +72,26 @@ _rename_create_path_core(const vector<const string*> &oldbasepaths,
|
||||
string oldfullpath;
|
||||
string newfullpath;
|
||||
|
||||
fs::path::make(&oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
ismember = member(oldbasepaths,oldbasepath);
|
||||
if(ismember)
|
||||
{
|
||||
fs::path::make(&oldbasepath,oldfusepath,oldfullpath);
|
||||
rv = fs::clonepath_as_root(newbasepath,oldbasepath,newfusedirpath);
|
||||
if(rv != -1)
|
||||
{
|
||||
fs::path::make(&oldbasepath,oldfusepath,oldfullpath);
|
||||
fs::path::make(&oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
rv = fs::rename(oldfullpath,newfullpath);
|
||||
}
|
||||
|
||||
rv = _rename(oldbasepath,oldfullpath,
|
||||
newbasepath,newfusedirpath,newfullpath);
|
||||
error = error::calc(rv,error,errno);
|
||||
if(RENAME_FAILED(rv))
|
||||
if(rv == -1)
|
||||
tounlink.push_back(oldfullpath);
|
||||
}
|
||||
else
|
||||
{
|
||||
fs::path::make(&oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
tounlink.push_back(newfullpath);
|
||||
}
|
||||
}
|
||||
@@ -117,31 +100,32 @@ static
|
||||
int
|
||||
_rename_create_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
string newfusedirpath;
|
||||
vector<string> toremove;
|
||||
vector<const string*> newbasepath;
|
||||
vector<const string*> oldbasepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = actionFunc(branches_,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
string newfusedirpath = newfusepath;
|
||||
fs::path::dirname(newfusedirpath);
|
||||
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath);
|
||||
if(POLICY_FAILED(rv))
|
||||
newfusedirpath = fs::path::dirname(newfusepath);
|
||||
|
||||
rv = searchFunc(branches_,newfusedirpath,minfreespace,newbasepath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = RENAME_FAIL;
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
const string &oldbasepath = srcmounts[i];
|
||||
const string &oldbasepath = branches_[i].path;
|
||||
|
||||
_rename_create_path_core(oldbasepaths,
|
||||
oldbasepath,*newbasepath[0],
|
||||
@@ -150,7 +134,8 @@ _rename_create_path(Policy::Func::Search searchFunc,
|
||||
error,toremove);
|
||||
}
|
||||
|
||||
if(RENAME_SUCCEEDED(error))
|
||||
|
||||
if(error == 0)
|
||||
_remove(toremove);
|
||||
|
||||
return -error;
|
||||
@@ -159,7 +144,7 @@ _rename_create_path(Policy::Func::Search searchFunc,
|
||||
static
|
||||
int
|
||||
_clonepath(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const string &dstbasepath,
|
||||
const string &fusedirpath)
|
||||
@@ -167,23 +152,20 @@ _clonepath(Policy::Func::Search searchFunc,
|
||||
int rv;
|
||||
vector<const string*> srcbasepath;
|
||||
|
||||
rv = searchFunc(srcmounts,fusedirpath.c_str(),minfreespace,srcbasepath);
|
||||
if(POLICY_FAILED(rv))
|
||||
return rv;
|
||||
rv = searchFunc(branches_,fusedirpath,minfreespace,srcbasepath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
fs::clonepath(*srcbasepath[0],dstbasepath,fusedirpath);
|
||||
}
|
||||
fs::clonepath_as_root(*srcbasepath[0],dstbasepath,fusedirpath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_clonepath_if_would_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const char *oldfusepath,
|
||||
@@ -193,23 +175,23 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc,
|
||||
string newfusedirpath;
|
||||
vector<const string*> newbasepath;
|
||||
|
||||
newfusedirpath = newfusepath;
|
||||
fs::path::dirname(newfusedirpath);
|
||||
rv = createFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath);
|
||||
if(POLICY_FAILED(rv))
|
||||
newfusedirpath = fs::path::dirname(newfusepath);
|
||||
|
||||
rv = createFunc(branches_,newfusedirpath,minfreespace,newbasepath);
|
||||
if(rv == -1)
|
||||
return rv;
|
||||
|
||||
if(oldbasepath == *newbasepath[0])
|
||||
return _clonepath(searchFunc,srcmounts,minfreespace,oldbasepath,newfusedirpath);
|
||||
return _clonepath(searchFunc,branches_,minfreespace,oldbasepath,newfusedirpath);
|
||||
|
||||
return POLICY_FAIL_ERRNO(EXDEV);
|
||||
return (errno=EXDEV,-1);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_rename_preserve_path_core(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const vector<const string*> &oldbasepaths,
|
||||
const string &oldbasepath,
|
||||
@@ -232,17 +214,17 @@ _rename_preserve_path_core(Policy::Func::Search searchFunc,
|
||||
fs::path::make(&oldbasepath,oldfusepath,oldfullpath);
|
||||
|
||||
rv = fs::rename(oldfullpath,newfullpath);
|
||||
if(RENAME_FAILED_WITH(rv,ENOENT))
|
||||
if((rv == -1) && (errno == ENOENT))
|
||||
{
|
||||
rv = _clonepath_if_would_create(searchFunc,createFunc,
|
||||
srcmounts,minfreespace,
|
||||
branches_,minfreespace,
|
||||
oldbasepath,oldfusepath,newfusepath);
|
||||
if(POLICY_SUCCEEDED(rv))
|
||||
if(rv == 0)
|
||||
rv = fs::rename(oldfullpath,newfullpath);
|
||||
}
|
||||
|
||||
error = error::calc(rv,error,errno);
|
||||
if(RENAME_FAILED(rv))
|
||||
if(rv == -1)
|
||||
toremove.push_back(oldfullpath);
|
||||
}
|
||||
else
|
||||
@@ -256,7 +238,7 @@ int
|
||||
_rename_preserve_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
@@ -266,23 +248,23 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
|
||||
vector<string> toremove;
|
||||
vector<const string*> oldbasepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = actionFunc(branches_,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = RENAME_FAIL;
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
const string &oldbasepath = srcmounts[i];
|
||||
const string &oldbasepath = branches_[i].path;
|
||||
|
||||
_rename_preserve_path_core(searchFunc,createFunc,
|
||||
srcmounts,minfreespace,
|
||||
branches_,minfreespace,
|
||||
oldbasepaths,oldbasepath,
|
||||
oldfusepath,newfusepath,
|
||||
error,toremove);
|
||||
}
|
||||
|
||||
if(RENAME_SUCCEEDED(error))
|
||||
if(error == 0)
|
||||
_remove(toremove);
|
||||
|
||||
return -error;
|
||||
@@ -299,20 +281,20 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
if(config.create->path_preserving() && !config.ignorepponrename)
|
||||
return _rename_preserve_path(config.getattr,
|
||||
config.rename,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
oldpath,
|
||||
newpath);
|
||||
|
||||
return _rename_create_path(config.getattr,
|
||||
config.rename,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
oldpath,
|
||||
newpath);
|
||||
|
||||
+4
-4
@@ -68,14 +68,14 @@ _rmdir_loop(const vector<const string*> &basepaths,
|
||||
static
|
||||
int
|
||||
_rmdir(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath)
|
||||
{
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = actionFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -92,10 +92,10 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readguard(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readguard(&config.branches_lock);
|
||||
|
||||
return _rmdir(config.rmdir,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath);
|
||||
}
|
||||
|
||||
+121
-88
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_setxattr.hpp"
|
||||
#include "fs_glob.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "num.hpp"
|
||||
#include "rv.hpp"
|
||||
@@ -32,6 +33,8 @@
|
||||
#include "str.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
static const char SECURITY_CAPABILITY[] = "security.capability";
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
@@ -39,75 +42,10 @@ using mergerfs::FuseFunc;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_add_srcmounts(vector<string> &srcmounts,
|
||||
pthread_rwlock_t &srcmountslock,
|
||||
const string &destmount,
|
||||
const string &values,
|
||||
vector<string>::iterator pos)
|
||||
bool
|
||||
_is_attrname_security_capability(const char *attrname_)
|
||||
{
|
||||
vector<string> patterns;
|
||||
vector<string> additions;
|
||||
|
||||
str::split(patterns,values,':');
|
||||
fs::glob(patterns,additions);
|
||||
fs::realpathize(additions);
|
||||
|
||||
if(!additions.empty())
|
||||
{
|
||||
const rwlock::WriteGuard wrg(&srcmountslock);
|
||||
|
||||
srcmounts.insert(pos,
|
||||
additions.begin(),
|
||||
additions.end());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_erase_srcmounts(vector<string> &srcmounts,
|
||||
pthread_rwlock_t &srcmountslock,
|
||||
const string &values)
|
||||
{
|
||||
if(srcmounts.empty())
|
||||
return 0;
|
||||
|
||||
vector<string> patterns;
|
||||
|
||||
str::split(patterns,values,':');
|
||||
|
||||
{
|
||||
const rwlock::WriteGuard wrg(&srcmountslock);
|
||||
|
||||
str::erase_fnmatches(patterns,srcmounts);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_replace_srcmounts(vector<string> &srcmounts,
|
||||
pthread_rwlock_t &srcmountslock,
|
||||
const string &destmount,
|
||||
const string &values)
|
||||
{
|
||||
vector<string> patterns;
|
||||
vector<string> newmounts;
|
||||
|
||||
str::split(patterns,values,':');
|
||||
fs::glob(patterns,newmounts);
|
||||
fs::realpathize(newmounts);
|
||||
|
||||
{
|
||||
const rwlock::WriteGuard wrg(&srcmountslock);
|
||||
|
||||
srcmounts.swap(newmounts);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (strcmp(attrname_,SECURITY_CAPABILITY) == 0);
|
||||
}
|
||||
|
||||
static
|
||||
@@ -128,10 +66,11 @@ static
|
||||
int
|
||||
_setxattr_srcmounts(const string &attrval,
|
||||
const int flags,
|
||||
vector<string> &srcmounts,
|
||||
pthread_rwlock_t &srcmountslock,
|
||||
const string &destmount)
|
||||
Branches &branches_,
|
||||
pthread_rwlock_t &branches_lock)
|
||||
{
|
||||
const rwlock::WriteGuard wrg(&branches_lock);
|
||||
|
||||
string instruction;
|
||||
string values;
|
||||
|
||||
@@ -141,23 +80,25 @@ _setxattr_srcmounts(const string &attrval,
|
||||
_split_attrval(attrval,instruction,values);
|
||||
|
||||
if(instruction == "+")
|
||||
return _add_srcmounts(srcmounts,srcmountslock,destmount,values,srcmounts.end());
|
||||
branches_.add_end(values);
|
||||
else if(instruction == "+<")
|
||||
return _add_srcmounts(srcmounts,srcmountslock,destmount,values,srcmounts.begin());
|
||||
branches_.add_begin(values);
|
||||
else if(instruction == "+>")
|
||||
return _add_srcmounts(srcmounts,srcmountslock,destmount,values,srcmounts.end());
|
||||
branches_.add_end(values);
|
||||
else if(instruction == "-")
|
||||
return _erase_srcmounts(srcmounts,srcmountslock,values);
|
||||
branches_.erase_fnmatch(values);
|
||||
else if(instruction == "-<")
|
||||
return _erase_srcmounts(srcmounts,srcmountslock,srcmounts.front());
|
||||
branches_.erase_begin();
|
||||
else if(instruction == "->")
|
||||
return _erase_srcmounts(srcmounts,srcmountslock,srcmounts.back());
|
||||
branches_.erase_end();
|
||||
else if(instruction == "=")
|
||||
return _replace_srcmounts(srcmounts,srcmountslock,destmount,values);
|
||||
branches_.set(values);
|
||||
else if(instruction.empty())
|
||||
return _replace_srcmounts(srcmounts,srcmountslock,destmount,values);
|
||||
branches_.set(values);
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
@@ -215,6 +156,67 @@ _setxattr_bool(const string &attrval,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_xattr(const string &attrval_,
|
||||
const int flags_,
|
||||
int xattr_)
|
||||
{
|
||||
if((flags_ & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
if(attrval_ == "passthrough")
|
||||
xattr_ = 0;
|
||||
else if(attrval_ == "noattr")
|
||||
xattr_ = ENOATTR;
|
||||
else if(attrval_ == "notsup")
|
||||
xattr_ = ENOTSUP;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_statfs(const string &attrval_,
|
||||
const int flags_,
|
||||
Config::StatFS::Enum &enum_)
|
||||
{
|
||||
if((flags_ & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
if(attrval_ == "base")
|
||||
enum_ = Config::StatFS::BASE;
|
||||
else if(attrval_ == "full")
|
||||
enum_ = Config::StatFS::FULL;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_statfsignore(const string &attrval_,
|
||||
const int flags_,
|
||||
Config::StatFSIgnore::Enum &enum_)
|
||||
{
|
||||
if((flags_ & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
if(attrval_ == "none")
|
||||
enum_ = Config::StatFSIgnore::NONE;
|
||||
else if(attrval_ == "ro")
|
||||
enum_ = Config::StatFSIgnore::RO;
|
||||
else if(attrval_ == "nc")
|
||||
enum_ = Config::StatFSIgnore::NC;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile_func_policy(Config &config,
|
||||
@@ -270,9 +272,13 @@ _setxattr_controlfile(Config &config,
|
||||
if(attr[2] == "srcmounts")
|
||||
return _setxattr_srcmounts(attrval,
|
||||
flags,
|
||||
config.srcmounts,
|
||||
config.srcmountslock,
|
||||
config.destmount);
|
||||
config.branches,
|
||||
config.branches_lock);
|
||||
else if(attr[2] == "branches")
|
||||
return _setxattr_srcmounts(attrval,
|
||||
flags,
|
||||
config.branches,
|
||||
config.branches_lock);
|
||||
else if(attr[2] == "minfreespace")
|
||||
return _setxattr_uint64_t(attrval,
|
||||
flags,
|
||||
@@ -297,6 +303,26 @@ _setxattr_controlfile(Config &config,
|
||||
return _setxattr_bool(attrval,
|
||||
flags,
|
||||
config.ignorepponrename);
|
||||
else if(attr[2] == "security_capability")
|
||||
return _setxattr_bool(attrval,
|
||||
flags,
|
||||
config.security_capability);
|
||||
else if(attr[2] == "xattr")
|
||||
return _setxattr_xattr(attrval,
|
||||
flags,
|
||||
config.xattr);
|
||||
else if(attr[2] == "link_cow")
|
||||
return _setxattr_bool(attrval,
|
||||
flags,
|
||||
config.link_cow);
|
||||
else if(attr[2] == "statfs")
|
||||
return _setxattr_statfs(attrval,
|
||||
flags,
|
||||
config.statfs);
|
||||
else if(attr[2] == "statfs_ignore")
|
||||
return _setxattr_statfsignore(attrval,
|
||||
flags,
|
||||
config.statfs_ignore);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
@@ -364,7 +390,7 @@ _setxattr_loop(const vector<const string*> &basepaths,
|
||||
static
|
||||
int
|
||||
_setxattr(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const char *attrname,
|
||||
@@ -375,7 +401,7 @@ _setxattr(Policy::Func::Action actionFunc,
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = actionFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -402,11 +428,18 @@ namespace mergerfs
|
||||
string(attrval,attrvalsize),
|
||||
flags);
|
||||
|
||||
if((config.security_capability == false) &&
|
||||
_is_attrname_security_capability(attrname))
|
||||
return -ENOATTR;
|
||||
|
||||
if(config.xattr)
|
||||
return -config.xattr;
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _setxattr(config.setxattr,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname,
|
||||
|
||||
+62
-39
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <fuse.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -26,13 +26,17 @@
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_statvfs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "success_fail.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::map;
|
||||
using std::vector;
|
||||
using mergerfs::Config;
|
||||
typedef Config::StatFS StatFS;
|
||||
typedef Config::StatFSIgnore StatFSIgnore;
|
||||
|
||||
static
|
||||
void
|
||||
@@ -42,7 +46,7 @@ _normalize_statvfs(struct statvfs *fsstat,
|
||||
const unsigned long min_namemax)
|
||||
{
|
||||
fsstat->f_blocks = (fsblkcnt_t)((fsstat->f_blocks * fsstat->f_frsize) / min_frsize);
|
||||
fsstat->f_bfree = (fsblkcnt_t)((fsstat->f_bfree * fsstat->f_frsize) / min_frsize);
|
||||
fsstat->f_bfree = (fsblkcnt_t)((fsstat->f_bfree * fsstat->f_frsize) / min_frsize);
|
||||
fsstat->f_bavail = (fsblkcnt_t)((fsstat->f_bavail * fsstat->f_frsize) / min_frsize);
|
||||
fsstat->f_bsize = min_bsize;
|
||||
fsstat->f_frsize = min_frsize;
|
||||
@@ -64,48 +68,64 @@ _merge_statvfs(struct statvfs * const out,
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_statfs_core(const char *srcmount,
|
||||
unsigned long &min_bsize,
|
||||
unsigned long &min_frsize,
|
||||
unsigned long &min_namemax,
|
||||
map<dev_t,struct statvfs> &fsstats)
|
||||
bool
|
||||
_should_ignore(const StatFSIgnore::Enum ignore_,
|
||||
const Branch *branch_,
|
||||
const bool readonly_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
struct statvfs fsstat;
|
||||
|
||||
rv = fs::statvfs(srcmount,fsstat);
|
||||
if(STATVFS_FAILED(rv))
|
||||
return;
|
||||
|
||||
rv = fs::stat(srcmount,st);
|
||||
if(STAT_FAILED(rv))
|
||||
return;
|
||||
|
||||
if(fsstat.f_bsize && (min_bsize > fsstat.f_bsize))
|
||||
min_bsize = fsstat.f_bsize;
|
||||
if(fsstat.f_frsize && (min_frsize > fsstat.f_frsize))
|
||||
min_frsize = fsstat.f_frsize;
|
||||
if(fsstat.f_namemax && (min_namemax > fsstat.f_namemax))
|
||||
min_namemax = fsstat.f_namemax;
|
||||
|
||||
fsstats.insert(std::make_pair(st.st_dev,fsstat));
|
||||
return ((((ignore_ == StatFSIgnore::RO) || readonly_) &&
|
||||
(branch_->ro_or_nc())) ||
|
||||
((ignore_ == StatFSIgnore::NC) && (branch_->nc())));
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_statfs(const vector<string> &srcmounts,
|
||||
struct statvfs &fsstat)
|
||||
_statfs(const Branches &branches_,
|
||||
const char *fusepath,
|
||||
const StatFS::Enum mode,
|
||||
const StatFSIgnore::Enum ignore,
|
||||
struct statvfs &fsstat)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
struct stat st;
|
||||
struct statvfs stvfs;
|
||||
unsigned long min_bsize;
|
||||
unsigned long min_frsize;
|
||||
unsigned long min_namemax;
|
||||
map<dev_t,struct statvfs> fsstats;
|
||||
unsigned long min_bsize = ULONG_MAX;
|
||||
unsigned long min_frsize = ULONG_MAX;
|
||||
unsigned long min_namemax = ULONG_MAX;
|
||||
|
||||
for(size_t i = 0, ei = srcmounts.size(); i < ei; i++)
|
||||
min_bsize = std::numeric_limits<unsigned long>::max();
|
||||
min_frsize = std::numeric_limits<unsigned long>::max();
|
||||
min_namemax = std::numeric_limits<unsigned long>::max();
|
||||
for(size_t i = 0, ei = branches_.size(); i < ei; i++)
|
||||
{
|
||||
_statfs_core(srcmounts[i].c_str(),min_bsize,min_frsize,min_namemax,fsstats);
|
||||
fullpath = ((mode == StatFS::FULL) ?
|
||||
fs::path::make(&branches_[i].path,fusepath) :
|
||||
branches_[i].path);
|
||||
|
||||
rv = fs::lstat(fullpath,st);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
rv = fs::lstatvfs(fullpath,stvfs);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
if(stvfs.f_bsize && (min_bsize > stvfs.f_bsize))
|
||||
min_bsize = stvfs.f_bsize;
|
||||
if(stvfs.f_frsize && (min_frsize > stvfs.f_frsize))
|
||||
min_frsize = stvfs.f_frsize;
|
||||
if(stvfs.f_namemax && (min_namemax > stvfs.f_namemax))
|
||||
min_namemax = stvfs.f_namemax;
|
||||
|
||||
if(_should_ignore(ignore,&branches_[i],StatVFS::readonly(stvfs)))
|
||||
{
|
||||
stvfs.f_bavail = 0;
|
||||
stvfs.f_favail = 0;
|
||||
}
|
||||
|
||||
fsstats.insert(std::make_pair(st.st_dev,stvfs));
|
||||
}
|
||||
|
||||
map<dev_t,struct statvfs>::iterator iter = fsstats.begin();
|
||||
@@ -136,9 +156,12 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _statfs(config.srcmounts,
|
||||
return _statfs(config.branches,
|
||||
fusepath,
|
||||
config.statfs,
|
||||
config.statfs_ignore,
|
||||
*stat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include "success_fail.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace StatVFS
|
||||
{
|
||||
|
||||
+12
@@ -147,4 +147,16 @@ namespace str
|
||||
return ((s0.size() >= s1.size()) &&
|
||||
(s0.compare(0,s1.size(),s1) == 0));
|
||||
}
|
||||
|
||||
bool
|
||||
ends_with(const string &str_,
|
||||
const string &suffix_)
|
||||
{
|
||||
if(suffix_.size() > str_.size())
|
||||
return false;
|
||||
|
||||
return std::equal(suffix_.rbegin(),
|
||||
suffix_.rend(),
|
||||
str_.rbegin());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +56,8 @@ namespace str
|
||||
bool
|
||||
isprefix(const std::string &s0,
|
||||
const std::string &s1);
|
||||
|
||||
bool
|
||||
ends_with(const std::string &str_,
|
||||
const std::string &suffix_);
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define STATVFS_SUCCESS 0
|
||||
#define STATVFS_SUCCEEDED(RV) ((RV) == STATVFS_SUCCESS)
|
||||
#define STATVFS_FAIL -1
|
||||
#define STATVFS_FAILED(RV) ((RV) == STATVFS_FAIL)
|
||||
|
||||
#define STAT_SUCCESS 0
|
||||
#define STAT_SUCCEEDED(RV) ((RV) == STAT_SUCCESS)
|
||||
#define STAT_FAIL -1
|
||||
#define STAT_FAILED(RV) ((RV) == STAT_FAIL)
|
||||
|
||||
#define LSTAT_SUCCESS 0
|
||||
#define LSTAT_SUCCEEDED(RV) ((RV) == LSTAT_SUCCESS)
|
||||
#define LSTAT_FAIL -1
|
||||
#define LSTAT_FAILED(RV) ((RV) == LSTAT_FAIL)
|
||||
|
||||
#define FSTAT_SUCCESS 0
|
||||
#define FSTAT_SUCCEEDED(RV) ((RV) == FSTAT_SUCCESS)
|
||||
#define FSTAT_FAIL -1
|
||||
#define FSTAT_FAILED(RV) ((RV) == FSTAT_FAIL)
|
||||
|
||||
#define RENAME_SUCCESS 0
|
||||
#define RENAME_SUCCEEDED(RV) ((RV) == RENAME_SUCCESS)
|
||||
#define RENAME_FAIL -1
|
||||
#define RENAME_FAILED(RV) ((RV) == RENAME_FAIL)
|
||||
#define RENAME_FAILED_WITH(RV,ERRNO) (((RV) == RENAME_FAIL) && (errno == ERRNO))
|
||||
+18
-25
@@ -36,24 +36,14 @@ using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
_symlink_loop_core(const string &existingpath,
|
||||
const string &newbasepath,
|
||||
_symlink_loop_core(const string &newbasepath,
|
||||
const char *oldpath,
|
||||
const char *newpath,
|
||||
const char *newdirpath,
|
||||
const int error)
|
||||
{
|
||||
int rv;
|
||||
string fullnewpath;
|
||||
|
||||
if(newbasepath != existingpath)
|
||||
{
|
||||
const ugid::SetRootGuard ugidGuard;
|
||||
rv = fs::clonepath(existingpath,newbasepath,newdirpath);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path::make(&newbasepath,newpath,fullnewpath);
|
||||
|
||||
rv = fs::symlink(oldpath,fullnewpath);
|
||||
@@ -67,16 +57,22 @@ _symlink_loop(const string &existingpath,
|
||||
const vector<const string*> newbasepaths,
|
||||
const char *oldpath,
|
||||
const char *newpath,
|
||||
const char *newdirpath)
|
||||
const string &newdirpath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
|
||||
error = -1;
|
||||
for(size_t i = 0, ei = newbasepaths.size(); i != ei; i++)
|
||||
{
|
||||
error = _symlink_loop_core(existingpath,*newbasepaths[i],
|
||||
oldpath,newpath,newdirpath,
|
||||
error);
|
||||
rv = fs::clonepath_as_root(existingpath,*newbasepaths[i],newdirpath);
|
||||
if(rv == -1)
|
||||
error = error::calc(rv,error,errno);
|
||||
else
|
||||
error = _symlink_loop_core(*newbasepaths[i],
|
||||
oldpath,
|
||||
newpath,
|
||||
error);
|
||||
}
|
||||
|
||||
return -error;
|
||||
@@ -86,31 +82,28 @@ static
|
||||
int
|
||||
_symlink(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldpath,
|
||||
const char *newpath)
|
||||
{
|
||||
int rv;
|
||||
string newdirpath;
|
||||
const char *newdirpathcstr;
|
||||
vector<const string*> newbasepaths;
|
||||
vector<const string*> existingpaths;
|
||||
|
||||
newdirpath = newpath;
|
||||
fs::path::dirname(newdirpath);
|
||||
newdirpathcstr = newdirpath.c_str();
|
||||
newdirpath = fs::path::dirname(newpath);
|
||||
|
||||
rv = searchFunc(srcmounts,newdirpathcstr,minfreespace,existingpaths);
|
||||
rv = searchFunc(branches_,newdirpath,minfreespace,existingpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = createFunc(srcmounts,newdirpathcstr,minfreespace,newbasepaths);
|
||||
rv = createFunc(branches_,newdirpath,minfreespace,newbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return _symlink_loop(*existingpaths[0],newbasepaths,
|
||||
oldpath,newpath,newdirpathcstr);
|
||||
oldpath,newpath,newdirpath);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -124,11 +117,11 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _symlink(config.getattr,
|
||||
config.symlink,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
oldpath,
|
||||
newpath);
|
||||
|
||||
+4
-4
@@ -71,7 +71,7 @@ _truncate_loop(const vector<const string*> &basepaths,
|
||||
static
|
||||
int
|
||||
_truncate(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const Branches &branches_,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const off_t size)
|
||||
@@ -79,7 +79,7 @@ _truncate(Policy::Func::Action actionFunc,
|
||||
int rv;
|
||||
vector<const string*> basepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,basepaths);
|
||||
rv = actionFunc(branches_,fusepath,minfreespace,basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -97,10 +97,10 @@ namespace mergerfs
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const rwlock::ReadGuard readlock(&config.branches_lock);
|
||||
|
||||
return _truncate(config.truncate,
|
||||
config.srcmounts,
|
||||
config.branches,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
size);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user