mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-19 16:16:48 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ee3d4eec2 | ||
|
|
aafc1e9394 | ||
|
|
eebfe456f6 | ||
|
|
b3109ac506 | ||
|
|
54484f35fc | ||
|
|
d079856e09 | ||
|
|
c101430b98 | ||
|
|
1d798ad285 | ||
|
|
b2cd79154a | ||
|
|
0c60701b29 | ||
|
|
51b6d3f647 | ||
|
|
a5bf48c8ae | ||
|
|
6ca43893ea | ||
|
|
3c8f12281f | ||
|
|
2bd44568a1 | ||
|
|
23cca83742 | ||
|
|
8e5b79647b | ||
|
|
9ea4bf2828 | ||
|
|
58167c3636 | ||
|
|
6578b93190 | ||
|
|
ccb22c1fbe | ||
|
|
ad7ce487bb | ||
|
|
fd2ba50cad | ||
|
|
fe0f442c3d | ||
|
|
1879c9c4a9 | ||
|
|
247bac76eb | ||
|
|
45b73e53be | ||
|
|
ffc90f52bc | ||
|
|
5fb277529f | ||
|
|
7552ad6781 | ||
|
|
4b204b8fba | ||
|
|
4ea49fcfbb | ||
|
|
33c837a560 | ||
|
|
3725387132 | ||
|
|
951b22b671 | ||
|
|
0a0e8fdefc | ||
|
|
74c334c372 | ||
|
|
711261bb02 | ||
|
|
08366a35be | ||
|
|
8b41dca91a | ||
|
|
91671d7364 | ||
|
|
15b2c8be1b | ||
|
|
c022741ffb | ||
|
|
a359c88173 | ||
|
|
12f393a55e | ||
|
|
e0f0bb53f7 | ||
|
|
283a2b2285 | ||
|
|
dba9e00adc | ||
|
|
1a1c9db37b | ||
|
|
f3f5a18ef5 | ||
|
|
d30cae217b | ||
|
|
dbe630c37d | ||
|
|
2e95c6e78e | ||
|
|
58ec83dcd8 | ||
|
|
b411c63df1 | ||
|
|
1f61a662ad | ||
|
|
1f90203025 | ||
|
|
805bc2d2e6 | ||
|
|
c2cbb93c25 | ||
|
|
6276ce9779 | ||
|
|
d1f3bd82e8 | ||
|
|
031b87f674 | ||
|
|
233c216e66 | ||
|
|
5dd072962b | ||
|
|
90b0fcd5f5 | ||
|
|
66563aa142 | ||
|
|
6c3ff01a0a | ||
|
|
d7ede20abe | ||
|
|
19051925db | ||
|
|
613b996296 | ||
|
|
39c750b368 | ||
|
|
47522a25cc | ||
|
|
6c31efc964 | ||
|
|
075d62d647 | ||
|
|
cfe7609bcd | ||
|
|
8f35406000 | ||
|
|
4ea1adbf96 | ||
|
|
15f88494e4 | ||
|
|
7e9ccd0317 |
@@ -11,3 +11,7 @@
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
|
||||
# Debian files
|
||||
debian/files
|
||||
debian/changelog
|
||||
|
||||
@@ -21,17 +21,20 @@
|
||||
# THE SOFTWARE.
|
||||
|
||||
PKGCONFIG = $(shell which pkg-config)
|
||||
GIT = $(shell which git)
|
||||
TAR = $(shell which tar)
|
||||
MKDIR = $(shell which mkdir)
|
||||
TOUCH = $(shell which touch)
|
||||
CP = $(shell which cp)
|
||||
RM = $(shell which rm)
|
||||
FIND = $(shell which find)
|
||||
INSTALL = $(shell which install)
|
||||
MKTEMP = $(shell which mktemp)
|
||||
STRIP = $(shell which strip)
|
||||
PANDOC = $(shell which pandoc)
|
||||
GIT = $(shell which git)
|
||||
TAR = $(shell which tar)
|
||||
MKDIR = $(shell which mkdir)
|
||||
TOUCH = $(shell which touch)
|
||||
CP = $(shell which cp)
|
||||
RM = $(shell which rm)
|
||||
LN = $(shell which ln)
|
||||
FIND = $(shell which find)
|
||||
INSTALL = $(shell which install)
|
||||
MKTEMP = $(shell which mktemp)
|
||||
STRIP = $(shell which strip)
|
||||
PANDOC = $(shell which pandoc)
|
||||
GIT2DEBCL = ./tools/git2debcl
|
||||
CPPFIND = ./tools/cppfind
|
||||
|
||||
ifeq ($(PKGCONFIG),"")
|
||||
$(error "pkg-config not installed"
|
||||
@@ -53,38 +56,42 @@ ifeq ($(FUSE_AVAILABLE),0)
|
||||
$(error "FUSE development package doesn't appear available")
|
||||
endif
|
||||
|
||||
OPTS = -O2
|
||||
SRC = $(wildcard src/*.cpp)
|
||||
OBJ = $(SRC:src/%.cpp=obj/%.o)
|
||||
DEPS = $(OBJ:obj/%.o=obj/%.d)
|
||||
TARGET = mergerfs
|
||||
MANPAGE = $(TARGET).1
|
||||
CFLAGS = -g -Wall \
|
||||
$(OPTS) \
|
||||
$(shell $(PKGCONFIG) fuse --cflags) \
|
||||
-DFUSE_USE_VERSION=26 \
|
||||
-MMD
|
||||
LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
|
||||
FLAG_NOPATH = $(shell $(CPPFIND) "flag_nopath")
|
||||
FALLOCATE = $(shell $(CPPFIND) "fuse_fs_fallocate")
|
||||
FLOCK = $(shell $(CPPFIND) "fuse_fs_flock")
|
||||
READ_BUF = $(shell $(CPPFIND) "fuse_fs_read_buf")
|
||||
WRITE_BUF = $(shell $(CPPFIND) "fuse_fs_write_buf")
|
||||
|
||||
BINDIR = $(PREFIX)/usr/bin
|
||||
MANDIR = $(PREFIX)/usr/share/man/man1
|
||||
INSTALLTARGET = $(DESTDIR)/$(BINDIR)/$(TARGET)
|
||||
MANTARGET = $(DESTDIR)/$(MANDIR)/$(MANPAGE)
|
||||
OPTS = -O2
|
||||
SRC = $(wildcard src/*.cpp)
|
||||
OBJ = $(SRC:src/%.cpp=obj/%.o)
|
||||
DEPS = $(OBJ:obj/%.o=obj/%.d)
|
||||
TARGET = mergerfs
|
||||
MANPAGE = $(TARGET).1
|
||||
FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
|
||||
CFLAGS = -g -Wall \
|
||||
$(OPTS) \
|
||||
$(FUSE_CFLAGS) \
|
||||
-DFUSE_USE_VERSION=26 \
|
||||
-MMD \
|
||||
-DFLAG_NOPATH=$(FLAG_NOPATH) \
|
||||
-DFALLOCATE=$(FALLOCATE) \
|
||||
-DFLOCK=$(FLOCK) \
|
||||
-DREAD_BUF=$(READ_BUF) \
|
||||
-DWRITE_BUF=$(WRITE_BUF)
|
||||
LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
|
||||
|
||||
BINDIR = $(PREFIX)/usr/bin
|
||||
MANDIR = $(PREFIX)/usr/share/man/man1
|
||||
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
|
||||
INSTALLMANDIR = $(DESTDIR)$(MANDIR)
|
||||
|
||||
ifeq ($(XATTR_AVAILABLE),0)
|
||||
$(warning "xattr not available: disabling")
|
||||
CFLAGS += -DWITHOUT_XATTR
|
||||
endif
|
||||
|
||||
KERNEL = $(shell uname -s)
|
||||
ifeq ($(KERNEL),Linux)
|
||||
CFLAGS += -DLINUX
|
||||
endif
|
||||
ifeq ($(KERNEL),Darwin)
|
||||
CFLAGS += -DOSX
|
||||
endif
|
||||
|
||||
all: $(TARGET)
|
||||
all: $(TARGET) clonepath
|
||||
|
||||
help:
|
||||
@echo "usage: make"
|
||||
@@ -93,6 +100,9 @@ help:
|
||||
$(TARGET): obj/obj-stamp $(OBJ)
|
||||
$(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
|
||||
|
||||
clonepath: $(TARGET)
|
||||
$(LN) -s $< $@
|
||||
|
||||
changelog:
|
||||
$(GIT) log --pretty --numstat --summary | git2cl > ChangeLog
|
||||
|
||||
@@ -104,22 +114,37 @@ obj/%.o: src/%.cpp
|
||||
$(CXX) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) -rf obj "$(TARGET)" "$(MANPAGE)"
|
||||
$(RM) -rf obj
|
||||
$(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
|
||||
$(FIND) -name "*~" -delete
|
||||
|
||||
distclean: clean
|
||||
$(GIT) clean -ifd
|
||||
$(GIT) clean -fd
|
||||
|
||||
install: $(TARGET) $(MANPAGE)
|
||||
$(INSTALL) -m 0755 -D "$(TARGET)" "$(INSTALLTARGET)"
|
||||
$(INSTALL) -m 0644 -D "$(MANPAGE)" "$(MANTARGET)"
|
||||
install: install-base install-clonepath install-man
|
||||
|
||||
install-strip: install
|
||||
$(STRIP) "$(INSTALLTARGET)"
|
||||
install-base: $(TARGET)
|
||||
$(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
uninstall:
|
||||
$(RM) "$(INSTALLTARGET)"
|
||||
$(RM) "$(MANTARGET)"
|
||||
install-clonepath: clonepath
|
||||
$(CP) -a $< "$(INSTALLBINDIR)/$<"
|
||||
|
||||
install-man: $(MANPAGE)
|
||||
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMANDIR)/$(MANPAGE)"
|
||||
|
||||
install-strip: install-base
|
||||
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
uninstall: uninstall-base uninstall-clonepath uninstall-man
|
||||
|
||||
uninstall-base:
|
||||
$(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
uninstall-clonepath:
|
||||
$(RM) -f "$(INSTALLBINDIR)/clonepath"
|
||||
|
||||
uninstall-man:
|
||||
$(RM) -f "$(INSTALLMANDIR)/$(MANPAGE")
|
||||
|
||||
$(MANPAGE): README.md
|
||||
$(PANDOC) -s -t man -o $(MANPAGE) README.md
|
||||
@@ -137,7 +162,7 @@ tarball: clean changelog man
|
||||
|
||||
deb:
|
||||
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
|
||||
$(GIT) dch --auto --release --new-version="$(VERSION)"
|
||||
$(GIT2DEBCL) $(TARGET) $(VERSION) > debian/changelog
|
||||
$(GIT) buildpackage --git-ignore-new
|
||||
|
||||
.PHONY: all clean install help
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
% mergerfs(1) mergerfs user manual
|
||||
% Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
% June 9, 2014
|
||||
% 2015-07-03
|
||||
|
||||
# NAME
|
||||
|
||||
@@ -8,23 +8,23 @@ mergerfs - another FUSE union filesystem
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
mergerfs -ocreate=epmfs,search=ff,action=ff <srcpoints> <mountpoint>
|
||||
mergerfs -o<options> <srcpoints> <mountpoint>
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
mergerfs is similar to mhddfs, unionfs, and aufs. Like mhddfs in that it too uses FUSE. Like aufs in that it provides multiple policies for how to handle behavior.
|
||||
mergerfs is similar to mhddfs, unionfs, and aufs. Like mhddfs in that it too uses [FUSE](http://en.wikipedia.org/wiki/Filesystem_in_Userspace). Like aufs in that it provides multiple policies for how to handle behavior.
|
||||
|
||||
Why create mergerfs when those exist? mhddfs isn't really maintained or flexible. There are also issues with running as root. aufs is more flexible but contains some hard to debug inconsistencies in behavior. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
|
||||
Why create mergerfs when those exist? mhddfs isn't really maintained or flexible. There are also security issues when with running as root. aufs is more flexible than mhddfs but contains some hard to debug inconsistencies in behavior on account of it being a kernel driver. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
|
||||
|
||||
# OPTIONS
|
||||
|
||||
###options###
|
||||
|
||||
| Option | Default |
|
||||
|--------|--------|
|
||||
| search | ff |
|
||||
| action | ff |
|
||||
| create | epmfs |
|
||||
* `defaults` is a shortcut for `big_writes`, `auto_cache`, `atomic_o_trunc`, `splice_read`, `splice_write`, and `splice_move`. These options seem to provide the best performance.
|
||||
* `minfreespace` (defaults to `4G`) is the minimum space value used for the `lfs` and `fwfs` policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively.
|
||||
* All [FUSE](http://fuse.sourceforge.net) functions which have a category (see below) are option keys. The syntax being `func.<func>=<policy>`.
|
||||
* To set all function policies in a category use `category.<category>=<policy>` such as `category.create=mfs`.
|
||||
* They are evaluated in the order listed so if the options are `func.rmdir=rand,category.action=ff` the `action` category setting will override the `rmdir` setting.
|
||||
|
||||
###srcpoints###
|
||||
|
||||
@@ -39,40 +39,60 @@ The above line will use all points in /mnt prefixed with *disk* and the director
|
||||
In /etc/fstab it'd look like the following:
|
||||
|
||||
```
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs allow_other 0 0
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other 0 0
|
||||
```
|
||||
|
||||
**NOTE:** the globbing is done at mount time. If a new directory is added matching the glob after the fact it will not be included.
|
||||
**NOTE:** the globbing is done at mount or xattr update time. If a new directory is added matching the glob after the fact it will not be included.
|
||||
|
||||
# POLICIES
|
||||
|
||||
Filesystem calls are broken up into 4 functional categories: search, action, create, and none. These categories can be assigned a policy which dictates how [mergerfs](http://github.com/trapexit/mergerfs) behaves while when action on the filesystem. Any policy can be assigned to a category though some aren't terribly practical. For instance: rand (Random) may be useful for **create** but could lead to very odd behavior if used for **search** or **action**. Since the input for any policy is the source mounts and fusepath and the output a vector of targets the choice was made to simplify the implementation and allow a policies usage in any category. **NOTE:** In any policy which can return more than one location (currently only **all**) the first value will be used in **search** and **create** policies since they can only ever act on 1 filepath.
|
||||
Filesystem calls are broken up into 3 categories: action, create, search. There are also some calls which have no policy attached due to state being kept between calls. These categories can be assigned a policy which dictates how [mergerfs](http://github.com/trapexit/mergerfs) behaves. Any policy can be assigned to a category though some aren't terribly practical. For instance: rand (Random) may be useful for **create** but could lead to very odd behavior if used for **search**.
|
||||
|
||||
#### Functional classifications ####
|
||||
| Class | FUSE calls |
|
||||
|-------|------------|
|
||||
| search | access, getattr, getxattr, listxattr, open, readlink |
|
||||
| action | chmod, link, removexattr, rmdir, setxattr, truncate, unlink, utimens |
|
||||
| create | create, mkdir, mknod |
|
||||
| none | fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, rename, statfs, symlink, write, release |
|
||||
#### Functional classifications ####
|
||||
|
||||
| Category | FUSE Functions |
|
||||
|----------|----------------|
|
||||
| action | chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate, unlink, utimens |
|
||||
| create | create, mkdir, mknod, symlink |
|
||||
| search | access, getattr, getxattr, ioctl*, listxattr, open, readlink |
|
||||
| N/A | fallocate, fgetattr, fsync, ftruncate, ioctl*, read, readdir, release, statfs, write |
|
||||
|
||||
`ioctl` behaves differently if its acting on a directory. It'll use the `getattr` policy to find and open the directory before issuing the `ioctl`. In other cases where something may be searched (to confirm a directory exists across all source mounts) then `getattr` will be used.
|
||||
|
||||
#### Policy descriptions ####
|
||||
|
||||
| Policy | Description |
|
||||
|--------------|-------------|
|
||||
| ff (first found) | Given the order the paths were provided at mount time act on the first one found (regardless if stat would return EACCES). |
|
||||
| ffwp (first found w/ permissions) | Given the order the paths were provided at mount time act on the first one found which you have access (stat does not error with EACCES). |
|
||||
| ff (first found) | Given the order of the paths act on the first one found (regardless if stat would return EACCES). |
|
||||
| ffwp (first found w/ permissions) | Given the order of the paths act on the first one found which you have access (stat does not error with EACCES). |
|
||||
| newest (newest file) | If multiple files exist return the one with the most recent mtime. |
|
||||
| all (all files found) | Attempt to apply the call to each file found. If any sub call succeeds the entire operation succeeds and other errors ignored. If all fail then the last error is reported. |
|
||||
| mfs (most free space) | Assuming the path is found to exist (ENOENT would not be returned) use the drive with the most free space available. |
|
||||
| mfs (most free space) | Use the drive with the most free space available. |
|
||||
| epmfs (existing path, most free space) | If the path exists in multiple locations use the one with the most free space. Otherwise fall back to mfs. |
|
||||
| rand (random) | Pick a destination at random. Again the dirname of the full path must exist somewhere. |
|
||||
| fwfs (first with free space) | Pick the first path which has at least `minfreespace`. |
|
||||
| lfs (least free space) | Pick the path with least available space but more than `minfreespace`. |
|
||||
| rand (random) | Pick an existing destination at random. |
|
||||
| all | Applies action to all found. For searches it will behave like first found `ff`. |
|
||||
|
||||
#### Defaults ####
|
||||
|
||||
| Category | Policy |
|
||||
|----------|--------|
|
||||
| action | all |
|
||||
| create | epmfs |
|
||||
| search | ff |
|
||||
|
||||
#### readdir ####
|
||||
|
||||
[readdir](http://linux.die.net/man/3/readdir) is very different from most functions in this realm. It certainly could have it's own set of policies to tweak its behavior. At this time it provides a simple `first found` merging of directories and file found. That is: only the first file or directory found for a directory is returned. Given how FUSE works though the data representing the returned entry comes from `getattr`.
|
||||
|
||||
It could be extended to offer the ability to see all files found. Perhaps concatinating `#` and a number to the name. But to really be useful you'd need to be able to access them which would complicate file lookup.
|
||||
|
||||
#### statvfs ####
|
||||
|
||||
It normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple points on the same drive will not result in double counting it's space.
|
||||
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple points on the same drive will not result in double counting it's space.
|
||||
|
||||
**NOTE:** create is really a search for existence and then create. The 'search' policy applies to the first part. If the [dirname](http://linux.die.net/man/3/dirname) of the full path is not found to exist [ENOENT](http://linux.die.net/man/3/errno) is returned.
|
||||
**NOTE:** Since we can not (easily) replicate the atomicity of an `mkdir` or `mknod` without side effects those calls will first do a scan to see if the file exists and then attempts a create. This means there is a slight race condition. Worse case you'd end up with the directory or file on more than one mount.
|
||||
|
||||
# BUILDING
|
||||
|
||||
@@ -93,36 +113,151 @@ make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto dis
|
||||
<mountpoint>/.mergerfs
|
||||
```
|
||||
|
||||
There is a pseudo file available at the mountpoint which allows for the runtime modification of certain mergerfs options. The file will not show up in readdirs but can be stat'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
|
||||
There is a pseudo file available at the mountpoint which allows for the runtime modification of certain mergerfs options. The file will not show up in readdirs but can be stat'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
|
||||
|
||||
Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
|
||||
|
||||
The keys are **user.mergerfs.action**, **user.mergerfs.create**, and **user.mergerfs.search**.
|
||||
##### Keys #####
|
||||
|
||||
* user.mergerfs.srcmounts
|
||||
* user.mergerfs.minfreespace
|
||||
* user.mergerfs.category.action
|
||||
* user.mergerfs.category.create
|
||||
* user.mergerfs.category.search
|
||||
* user.mergerfs.func.access
|
||||
* user.mergerfs.func.chmod
|
||||
* user.mergerfs.func.chown
|
||||
* user.mergerfs.func.create
|
||||
* user.mergerfs.func.getattr
|
||||
* user.mergerfs.func.getxattr
|
||||
* user.mergerfs.func.link
|
||||
* user.mergerfs.func.listxattr
|
||||
* user.mergerfs.func.mkdir
|
||||
* user.mergerfs.func.mknod
|
||||
* user.mergerfs.func.open
|
||||
* user.mergerfs.func.readlink
|
||||
* user.mergerfs.func.removexattr
|
||||
* user.mergerfs.func.rename
|
||||
* user.mergerfs.func.rmdir
|
||||
* user.mergerfs.func.setxattr
|
||||
* user.mergerfs.func.symlink
|
||||
* user.mergerfs.func.truncate
|
||||
* user.mergerfs.func.unlink
|
||||
* user.mergerfs.func.utimens
|
||||
|
||||
##### Example #####
|
||||
|
||||
```
|
||||
[trapexit:/tmp/mount] $ xattr -l .mergerfs
|
||||
user.mergerfs.action: ff
|
||||
user.mergerfs.create: epmfs
|
||||
user.mergerfs.search: ff
|
||||
user.mergerfs.srcmounts: /tmp/a:/tmp/b
|
||||
user.mergerfs.minfreespace: 4294967295
|
||||
user.mergerfs.category.action: all
|
||||
user.mergerfs.category.create: epmfs
|
||||
user.mergerfs.category.search: ff
|
||||
user.mergerfs.func.access: ff
|
||||
user.mergerfs.func.chmod: all
|
||||
user.mergerfs.func.chown: all
|
||||
user.mergerfs.func.create: epmfs
|
||||
user.mergerfs.func.getattr: ff
|
||||
user.mergerfs.func.getxattr: ff
|
||||
user.mergerfs.func.link: all
|
||||
user.mergerfs.func.listxattr: ff
|
||||
user.mergerfs.func.mkdir: epmfs
|
||||
user.mergerfs.func.mknod: epmfs
|
||||
user.mergerfs.func.open: ff
|
||||
user.mergerfs.func.readlink: ff
|
||||
user.mergerfs.func.removexattr: all
|
||||
user.mergerfs.func.rename: all
|
||||
user.mergerfs.func.rmdir: all
|
||||
user.mergerfs.func.setxattr: all
|
||||
user.mergerfs.func.symlink: epmfs
|
||||
user.mergerfs.func.truncate: all
|
||||
user.mergerfs.func.unlink: all
|
||||
user.mergerfs.func.utimens: all
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.action .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
|
||||
ff
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.action ffwp .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.action .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search ffwp .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
|
||||
ffwp
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts =/tmp/c .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/c
|
||||
|
||||
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts '+</tmp/a:/tmp/b' .mergerfs
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
```
|
||||
|
||||
#### mergerfs xattrs ####
|
||||
##### user.mergerfs.srcmounts #####
|
||||
|
||||
For **user.mergerfs.srcmounts** there are several instructions available for manipulating the list. The value provided is just as the value used at mount time. A colon (':') delimited list of full path globs.
|
||||
|
||||
| Instruction | Description |
|
||||
|--------------|-------------|
|
||||
| +[list] | append |
|
||||
| +<[list] | prepend |
|
||||
| +>[list] | append |
|
||||
| -[list] | remove all values provided |
|
||||
| -< | remove first in list |
|
||||
| -> | remove last in list |
|
||||
| =[list] | set |
|
||||
| [list] | set |
|
||||
|
||||
##### misc #####
|
||||
|
||||
Categories and funcs take a policy as described in the previous section. When reading funcs you'll get the policy string. However, with categories you'll get a coma separated list of policies for each type found. For example: if all search functions are `ff` except for `access` which is `ffwp` the value for `user.mergerfs.category.search` will be `ff,ffwp`.
|
||||
|
||||
#### mergerfs file xattrs ####
|
||||
|
||||
While they won't show up when using [listxattr](http://linux.die.net/man/2/listxattr) mergerfs offers a number of special xattrs to query information about the files served. To access the values you will need to issue a [getxattr](http://linux.die.net/man/2/getxattr) for one of the following:
|
||||
|
||||
* user.mergerfs.basepath : gives you the base mount point for the file given the current search policy
|
||||
* user.mergerfs.fullpath : gives you the full path of the original file given the search policy
|
||||
* **user.mergerfs.basepath:** the base mount point for the file given the current search policy
|
||||
* **user.mergerfs.relpath:** the relative path of the file from the perspective of the mount point
|
||||
* **user.mergerfs.fullpath:** the full path of the original file given the search policy
|
||||
* **user.mergerfs.allpaths:** a NUL ('\0') separated list of full paths to all files found
|
||||
|
||||
```
|
||||
[trapexit:/tmp/mount] $ ls
|
||||
A B C
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.fullpath A
|
||||
/mnt/full/path/to/A
|
||||
/mnt/a/full/path/to/A
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.basepath A
|
||||
/mnt/a
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.relpath A
|
||||
/full/path/to/A
|
||||
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.allpaths A | tr '\0' '\n'
|
||||
/mnt/a/full/path/to/A
|
||||
/mnt/b/full/path/to/A
|
||||
```
|
||||
|
||||
# Tips / Notes
|
||||
|
||||
* The recommended options are `defaults,allow_other`. The `allow_other` is to allow users who are not the one which executed mergerfs access to the mountpoint. `defaults` is described above and should offer the best performance. It's possible that if you're running on an older platform the `splice` features aren't available and could error. In that case simply use the other options manually.
|
||||
* Remember that some policies mixed with some functions may result in strange behaviors. Not that some of these behaviors and race conditions couldn't happen outside [mergerfs](http://github.com/trapexit/mergerfs) but that they are far more likely to occur on account of attempt to merge together multiple sources of data which could be out of sync due to the different policies.
|
||||
* An example: [Kodi](http://kodi.tv) can apparently use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether or not to scan for new content rather than simply performing a full scan. If using the current default `getattr` policy of `ff` it's possible Kodi will miss an update on account of it returning the first directory found's `stat` info and its a later directory on another mount which had the `mtime` recently updated. To fix this you will want to set `func.getattr=newest`. Remember though that this is just `stat`. If the file is later `open`ed or `unlink`ed and the policy is different for those then a completely different file or directory could be acted on.
|
||||
* Due to previously mentioned issues its generally best to set `category` wide policies rather than individual `func`s. This will help limit the confusion of tools such as [rsync](http://linux.die.net/man/1/rsync).
|
||||
|
||||
# FAQ
|
||||
|
||||
#### It's mentioned that there are some security issues with `mhddfs`. What are they? How does `mergerfs` address them?
|
||||
|
||||
[mhddfs](https://github.com/trapexit/mhddfs) trys to handle being run as `root` by calling [getuid()](https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319) and if it returns `0` then it will [chown](http://linux.die.net/man/1/chown) the file. Not only is that a race condition but it doesn't handle many other situtations. Rather than attempting to simulate POSIX ACL behaviors the proper behavior is to use [seteuid](http://linux.die.net/man/2/seteuid) and [setegid](http://linux.die.net/man/2/setegid), become the user making the original call and perform the action as them. This is how [mergerfs](https://github.com/trapexit/mergerfs) handles things.
|
||||
|
||||
If you are familiar with POSIX standards you'll know that this behavior poses a problem. `seteuid` and `setegid` affect the whole process and `libfuse` is multithreaded by default. We'd need to lock access to `seteuid` and `setegid` with a mutex so that the several threads aren't stepping on one another and files end up with weird permissions and ownership. This however wouldn't scale well. With lots of calls the contention on that mutex would be extremely high. Thankfully on Linux and OSX we have a better solution.
|
||||
|
||||
OSX has a [non-portable pthread extension](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html) for per-thread user and group impersonation. When building on OSX mergerfs will use this without any mutexes.
|
||||
|
||||
Linux does not support [pthread_setugid_np](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html) but user and group IDs are a per-thread attribute though documention on that fact or how to manipulate them is not well distributed. From the `4.00` release of the Linux man-pages project for [setuid](http://man7.org/linux/man-pages/man2/setuid.2.html)
|
||||
|
||||
> At the kernel level, user IDs and group IDs are a per-thread attribute. However, POSIX requires that all threads in a process share the same credentials. The NPTL threading implementation handles the POSIX requirements by providing wrapper functions for the various system calls that change process UIDs and GIDs. These wrapper functions (including the one for setuid()) employ a signal-based technique to ensure that when one thread changes credentials, all of the other threads in the process also change their credentials. For details, see nptl(7).
|
||||
|
||||
Turns out the setreuid syscalls apply only to the thread. GLIBC hides this away using RT signals and other tricks. Taking after Samba mergerfs uses `syscall(SYS_setreuid,...)` to set the callers credentials for that thread only. Jumping back to `root` as necessary should escalated privilages be needed (for instance: to clone paths).
|
||||
|
||||
|
||||
|
||||
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
mergerfs (1.1.0) trusty; urgency=medium
|
||||
|
||||
* initial code commit
|
||||
* fix building without libattr
|
||||
* update build instructions in readme
|
||||
* use {get,list,set}xattr to modify runtime
|
||||
* use long instead of int to limit possibility of overflow in switch, closes #1
|
||||
* add FS_IOC_{GET}VERSION to ioctl
|
||||
* remove statfs policy
|
||||
* fs::make_path should check for forward slashes, add if missing
|
||||
* remove stat'ing of files in readdir. closes #3
|
||||
* use eaccess to determine permissions for ffwp. closes #2
|
||||
* rework policy code
|
||||
* add fgetattr. closes #5
|
||||
* when readdir's filler returns non-zero return ENOMEM. closes #7
|
||||
* enhance Makefile
|
||||
* further Makefile enhancements
|
||||
* fix free space calculations. closes #8
|
||||
* add debian package building
|
||||
|
||||
-- Antonio SJ Musumeci <trapexit@spawn.link> Fri, 30 May 2014 21:32:19 -0400
|
||||
|
||||
mergerfs (1.0.0) trusty; urgency=medium
|
||||
|
||||
* Initial commit
|
||||
|
||||
-- Antonio SJ Musumeci <trapexit@spawn.link> Fri, 30 May 2014 21:28:09 -0400
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
mergerfs_1.1.0_amd64.deb utils optional
|
||||
+15
-9
@@ -37,27 +37,31 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_access(const fs::SearchFunc searchFunc,
|
||||
_access(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const int mask)
|
||||
{
|
||||
int rv;
|
||||
fs::PathVector path;
|
||||
vector<string> path;
|
||||
|
||||
searchFunc(srcmounts,fusepath,path);
|
||||
if(path.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = ::eaccess(path[0].full.c_str(),mask);
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
rv = ::eaccess(path[0].c_str(),mask);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
@@ -73,9 +77,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _access(*config.search,
|
||||
return _access(config.access,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mask);
|
||||
}
|
||||
|
||||
+5
-5
@@ -38,16 +38,16 @@ namespace mergerfs
|
||||
(CATEGORY(action))
|
||||
(CATEGORY(create))
|
||||
(CATEGORY(search));
|
||||
|
||||
|
||||
const Category * const Category::categories = &_categories_[1];
|
||||
|
||||
const Category &Category::invalid = Category::categories[Category::Enum::invalid];
|
||||
const Category &Category::action = Category::categories[Category::Enum::action];
|
||||
const Category &Category::create = Category::categories[Category::Enum::create];
|
||||
const Category &Category::search = Category::categories[Category::Enum::search];
|
||||
|
||||
const Category &Category::search = Category::categories[Category::Enum::search];
|
||||
|
||||
const Category&
|
||||
Category::find(const std::string str)
|
||||
Category::find(const std::string &str)
|
||||
{
|
||||
for(int i = Enum::BEGIN; i != Enum::END; ++i)
|
||||
{
|
||||
@@ -66,5 +66,5 @@ namespace mergerfs
|
||||
return categories[i];
|
||||
|
||||
return invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -57,8 +57,8 @@ namespace mergerfs
|
||||
{
|
||||
}
|
||||
|
||||
Category(const Enum::Type enum_,
|
||||
const std::string str_)
|
||||
Category(const Enum::Type enum_,
|
||||
const std::string &str_)
|
||||
: _enum(enum_),
|
||||
_str(str_)
|
||||
{
|
||||
@@ -66,15 +66,15 @@ namespace mergerfs
|
||||
|
||||
public:
|
||||
operator const Enum::Type() const { return _enum; }
|
||||
operator const std::string() const { return _str; }
|
||||
operator const std::string&() const { return _str; }
|
||||
operator const Category*() const { return this; }
|
||||
|
||||
bool operator==(const std::string str_) const
|
||||
bool operator==(const std::string &str_) const
|
||||
{ return _str == str_; }
|
||||
|
||||
bool operator==(const Enum::Type enum_) const
|
||||
{ return _enum == enum_; }
|
||||
|
||||
{ return _enum == enum_; }
|
||||
|
||||
bool operator!=(const Category &r) const
|
||||
{ return _enum != r._enum; }
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace mergerfs
|
||||
{ return _enum < r._enum; }
|
||||
|
||||
public:
|
||||
static const Category &find(const std::string);
|
||||
static const Category &find(const std::string&);
|
||||
static const Category &find(const Enum::Type);
|
||||
|
||||
public:
|
||||
|
||||
+18
-15
@@ -31,7 +31,7 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -39,30 +39,31 @@ using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_chmod(const fs::SearchFunc searchFunc,
|
||||
_chmod(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::chmod(i->full.c_str(),mode);
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::chmod(paths[i].c_str(),mode);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -74,11 +75,13 @@ namespace mergerfs
|
||||
mode_t mode)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _chmod(*config.action,
|
||||
return _chmod(config.chmod,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
mode);
|
||||
}
|
||||
|
||||
+17
-14
@@ -32,7 +32,7 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -40,31 +40,32 @@ using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_chown(const fs::SearchFunc searchFunc,
|
||||
_chown(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::lchown(i->full.c_str(),uid,gid);
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::lchown(paths[i].c_str(),uid,gid);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -79,9 +80,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _chown(*config.action,
|
||||
return _chown(config.chown,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
uid,
|
||||
gid);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "fs.hpp"
|
||||
|
||||
namespace clonepath
|
||||
{
|
||||
static
|
||||
void
|
||||
print_usage_and__exit(void)
|
||||
{
|
||||
std::cerr << "usage: clonepath "
|
||||
<< "<sourcedir> <destdir> <relativepath>"
|
||||
<< std::endl;
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(const int argc,
|
||||
char * const argv[])
|
||||
{
|
||||
if(argc != 4)
|
||||
print_usage_and__exit();
|
||||
|
||||
return fs::clonepath(argv[1],
|
||||
argv[2],
|
||||
argv[3]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace clonepath
|
||||
{
|
||||
int
|
||||
main(const int argc,
|
||||
char * const *argv);
|
||||
}
|
||||
+90
-10
@@ -22,34 +22,114 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "fs.hpp"
|
||||
|
||||
#define POLICYINIT(X) X(policies[FuseFunc::Enum::X])
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace config
|
||||
{
|
||||
Config::Config()
|
||||
: action(policies[0]),
|
||||
create(policies[1]),
|
||||
search(policies[2]),
|
||||
: destmount(),
|
||||
srcmounts(),
|
||||
srcmountslock(),
|
||||
minfreespace(UINT32_MAX),
|
||||
POLICYINIT(access),
|
||||
POLICYINIT(chmod),
|
||||
POLICYINIT(chown),
|
||||
POLICYINIT(create),
|
||||
POLICYINIT(getattr),
|
||||
POLICYINIT(getxattr),
|
||||
POLICYINIT(link),
|
||||
POLICYINIT(listxattr),
|
||||
POLICYINIT(mkdir),
|
||||
POLICYINIT(mknod),
|
||||
POLICYINIT(open),
|
||||
POLICYINIT(readlink),
|
||||
POLICYINIT(removexattr),
|
||||
POLICYINIT(rename),
|
||||
POLICYINIT(rmdir),
|
||||
POLICYINIT(setxattr),
|
||||
POLICYINIT(symlink),
|
||||
POLICYINIT(truncate),
|
||||
POLICYINIT(unlink),
|
||||
POLICYINIT(utimens),
|
||||
controlfile("/.mergerfs")
|
||||
{
|
||||
action = &Policy::ff;
|
||||
create = &Policy::epmfs;
|
||||
search = &Policy::ff;
|
||||
pthread_rwlock_init(&srcmountslock,NULL);
|
||||
|
||||
set_category_policy("action","all");
|
||||
set_category_policy("create","epmfs");
|
||||
set_category_policy("search","ff");
|
||||
}
|
||||
|
||||
int
|
||||
Config::set_func_policy(const string &fusefunc_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const FuseFunc *fusefunc;
|
||||
|
||||
fusefunc = FuseFunc::find(fusefunc_);
|
||||
if(fusefunc == FuseFunc::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
|
||||
policies[(FuseFunc::Enum::Type)*fusefunc] = policy;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Config::set_category_policy(const string &category_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const Category *category;
|
||||
|
||||
category = Category::find(category_);
|
||||
if(category == Category::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
|
||||
for(int i = 0; i < FuseFunc::Enum::END; i++)
|
||||
{
|
||||
if(FuseFunc::fusefuncs[i] == (Category::Enum::Type)*category)
|
||||
policies[(FuseFunc::Enum::Type)FuseFunc::fusefuncs[i]] = policy;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Config&
|
||||
get(const struct fuse_context *fc)
|
||||
{
|
||||
return *((Config*)fc->private_data);
|
||||
}
|
||||
|
||||
const Config&
|
||||
get(void)
|
||||
{
|
||||
return (*((Config*)fuse_get_context()->private_data));
|
||||
return get(fuse_get_context());
|
||||
}
|
||||
|
||||
Config&
|
||||
|
||||
+34
-4
@@ -25,13 +25,16 @@
|
||||
#ifndef __CONFIG_HPP__
|
||||
#define __CONFIG_HPP__
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
#include "category.hpp"
|
||||
#include "fusefunc.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
@@ -42,19 +45,46 @@ namespace mergerfs
|
||||
public:
|
||||
Config();
|
||||
|
||||
public:
|
||||
int set_func_policy(const std::string &fusefunc_,
|
||||
const std::string &policy_);
|
||||
int set_category_policy(const std::string &category,
|
||||
const std::string &policy);
|
||||
|
||||
public:
|
||||
std::string destmount;
|
||||
std::vector<std::string> srcmounts;
|
||||
mutable pthread_rwlock_t srcmountslock;
|
||||
size_t minfreespace;
|
||||
|
||||
const Policy *policies[Category::Enum::END];
|
||||
const Policy *&action;
|
||||
public:
|
||||
const Policy *policies[FuseFunc::Enum::END];
|
||||
const Policy *&access;
|
||||
const Policy *&chmod;
|
||||
const Policy *&chown;
|
||||
const Policy *&create;
|
||||
const Policy *&search;
|
||||
const Policy *&getattr;
|
||||
const Policy *&getxattr;
|
||||
const Policy *&link;
|
||||
const Policy *&listxattr;
|
||||
const Policy *&mkdir;
|
||||
const Policy *&mknod;
|
||||
const Policy *&open;
|
||||
const Policy *&readlink;
|
||||
const Policy *&removexattr;
|
||||
const Policy *&rename;
|
||||
const Policy *&rmdir;
|
||||
const Policy *&setxattr;
|
||||
const Policy *&symlink;
|
||||
const Policy *&truncate;
|
||||
const Policy *&unlink;
|
||||
const Policy *&utimens;
|
||||
|
||||
public:
|
||||
const std::string controlfile;
|
||||
};
|
||||
|
||||
const Config &get(const struct fuse_context *fc);
|
||||
const Config &get(void);
|
||||
Config &get_writable(void);
|
||||
}
|
||||
|
||||
+27
-23
@@ -34,50 +34,52 @@
|
||||
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::FileInfo;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_create(const fs::SearchFunc searchFunc,
|
||||
const fs::SearchFunc createPathFunc,
|
||||
_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
{
|
||||
int fd;
|
||||
string path;
|
||||
int rv;
|
||||
string dirname;
|
||||
fs::PathVector createpath;
|
||||
fs::PathVector existingpath;
|
||||
vector<string> createpath;
|
||||
vector<string> existingpath;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
searchFunc(srcmounts,dirname,existingpath);
|
||||
if(existingpath.empty())
|
||||
return -ENOENT;
|
||||
dirname = fs::path::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
createPathFunc(srcmounts,dirname,createpath);
|
||||
if(createpath.empty())
|
||||
return -ENOSPC;
|
||||
rv = createFunc(srcmounts,dirname,minfreespace,createpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
if(createpath[0].base != existingpath[0].base)
|
||||
fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
|
||||
if(createpath[0] != existingpath[0])
|
||||
{
|
||||
const mergerfs::ugid::SetResetGuard ugid(0,0);
|
||||
fs::clonepath(existingpath[0],createpath[0],dirname);
|
||||
}
|
||||
|
||||
path = fs::make_path(createpath[0].base,fusepath);
|
||||
fs::path::append(createpath[0],fusepath);
|
||||
|
||||
fd = ::open(path.c_str(),flags,mode);
|
||||
fd = ::open(createpath[0].c_str(),flags,mode);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
fh = (uint64_t)new FileInfo(fd,flags,path);
|
||||
fh = fd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -94,10 +96,12 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _create(*config.search,
|
||||
*config.create,
|
||||
return _create(config.getattr,
|
||||
config.create,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
(mode & ~fc->umask),
|
||||
fileinfo->flags,
|
||||
|
||||
@@ -24,7 +24,12 @@
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
test(const struct fuse_args &args,
|
||||
const mergerfs::config::Config &config);
|
||||
namespace destroy
|
||||
{
|
||||
void
|
||||
destroy(void *)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace destroy
|
||||
{
|
||||
void
|
||||
destroy(void *);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -22,6 +22,8 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#if FALLOCATE
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
@@ -31,8 +33,6 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_fallocate(const int fd,
|
||||
@@ -73,12 +73,12 @@ namespace mergerfs
|
||||
off_t len,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
||||
|
||||
return _fallocate(fileinfo->fd,
|
||||
return _fallocate(ffi->fh,
|
||||
mode,
|
||||
offset,
|
||||
len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+1
-5
@@ -29,8 +29,6 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_fgetattr(const int fd,
|
||||
@@ -52,9 +50,7 @@ namespace mergerfs
|
||||
struct stat *st,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
||||
|
||||
return _fgetattr(fileinfo->fd,
|
||||
return _fgetattr(ffi->fh,
|
||||
*st);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -27,8 +27,6 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_flush(const int fd)
|
||||
@@ -52,7 +50,7 @@ namespace mergerfs
|
||||
flush(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return _flush(((FileInfo*)ffi->fh)->fd);
|
||||
return _flush(ffi->fh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+164
-365
@@ -38,30 +38,17 @@
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <glob.h>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "xattr.hpp"
|
||||
#include "str.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::map;
|
||||
using std::istringstream;
|
||||
|
||||
template<typename Container>
|
||||
Container&
|
||||
split(Container &result,
|
||||
const typename Container::value_type &s,
|
||||
typename Container::value_type::value_type delimiter)
|
||||
{
|
||||
string str;
|
||||
istringstream ss(s);
|
||||
|
||||
while(std::getline(ss,str,delimiter))
|
||||
result.push_back(str);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Iter>
|
||||
Iter
|
||||
random_element(Iter begin,
|
||||
@@ -76,105 +63,108 @@ random_element(Iter begin,
|
||||
|
||||
namespace fs
|
||||
{
|
||||
string
|
||||
dirname(const string path)
|
||||
namespace path
|
||||
{
|
||||
string parent = path;
|
||||
string::reverse_iterator i;
|
||||
string::reverse_iterator bi;
|
||||
string
|
||||
dirname(const string &path)
|
||||
{
|
||||
string parent = path;
|
||||
string::reverse_iterator i;
|
||||
string::reverse_iterator bi;
|
||||
|
||||
bi = parent.rend();
|
||||
i = parent.rbegin();
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
bi = parent.rend();
|
||||
i = parent.rbegin();
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
|
||||
while(*i != '/' && i != bi)
|
||||
i++;
|
||||
while(*i != '/' && i != bi)
|
||||
i++;
|
||||
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
while(*i == '/' && i != bi)
|
||||
i++;
|
||||
|
||||
parent.erase(i.base(),parent.end());
|
||||
parent.erase(i.base(),parent.end());
|
||||
|
||||
return parent;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
string
|
||||
basename(const string path)
|
||||
{
|
||||
return path.substr(path.find_last_of('/')+1);
|
||||
}
|
||||
string
|
||||
basename(const string &path)
|
||||
{
|
||||
return path.substr(path.find_last_of('/')+1);
|
||||
}
|
||||
|
||||
bool
|
||||
dir_is_empty(const string path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
|
||||
dir = ::opendir(path.c_str());
|
||||
if(!dir)
|
||||
return false;
|
||||
|
||||
while((de = ::readdir(dir)))
|
||||
{
|
||||
const char *d_name = de->d_name;
|
||||
|
||||
if(d_name[0] == '.' &&
|
||||
((d_name[1] == '\0') ||
|
||||
(d_name[1] == '.' && d_name[2] == '\0')))
|
||||
continue;
|
||||
|
||||
::closedir(dir);
|
||||
bool
|
||||
is_empty(const string &path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
|
||||
dir = ::opendir(path.c_str());
|
||||
if(!dir)
|
||||
return false;
|
||||
}
|
||||
|
||||
::closedir(dir);
|
||||
while((de = ::readdir(dir)))
|
||||
{
|
||||
const char *d_name = de->d_name;
|
||||
|
||||
return true;
|
||||
if(d_name[0] == '.' &&
|
||||
((d_name[1] == '\0') ||
|
||||
(d_name[1] == '.' && d_name[2] == '\0')))
|
||||
continue;
|
||||
|
||||
::closedir(dir);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
::closedir(dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
exists(const vector<string> &paths,
|
||||
const string &fusepath)
|
||||
{
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
struct stat st;
|
||||
|
||||
path = fs::path::make(paths[i],fusepath);
|
||||
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
make_path(const string base,
|
||||
const string suffix)
|
||||
void
|
||||
findallfiles(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(suffix[0] == '/' ||
|
||||
*base.rbegin() == '/')
|
||||
return base + suffix;
|
||||
return base + '/' + suffix;
|
||||
}
|
||||
|
||||
bool
|
||||
path_exists(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string fusepath)
|
||||
{
|
||||
for(vector<string>::const_iterator
|
||||
iter = begin; iter != end; ++iter)
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
int rv;
|
||||
string fullpath;
|
||||
struct stat st;
|
||||
|
||||
path = fs::make_path(*iter,fusepath);
|
||||
rv = ::eaccess(path.c_str(),F_OK);
|
||||
fullpath = fs::path::make(srcmounts[i],fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == 0)
|
||||
return true;
|
||||
paths.push_back(fullpath);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
path_exists(const vector<string> &srcmounts,
|
||||
const string fusepath)
|
||||
{
|
||||
return path_exists(srcmounts.begin(),
|
||||
srcmounts.end(),
|
||||
fusepath);
|
||||
}
|
||||
|
||||
int
|
||||
listxattr(const string path,
|
||||
listxattr(const string &path,
|
||||
vector<char> &attrs)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
@@ -198,7 +188,7 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
listxattr(const string path,
|
||||
listxattr(const string &path,
|
||||
vector<string> &attrvector)
|
||||
{
|
||||
int rv;
|
||||
@@ -208,15 +198,15 @@ namespace fs
|
||||
if(rv != -1)
|
||||
{
|
||||
string tmp(attrs.begin(),attrs.end());
|
||||
split(attrvector,tmp,'\0');
|
||||
str::split(attrvector,tmp,'\0');
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
listxattr(const string path,
|
||||
string &attrstr)
|
||||
listxattr(const string &path,
|
||||
string &attrstr)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
@@ -229,8 +219,8 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
getxattr(const string path,
|
||||
const string attr,
|
||||
getxattr(const string &path,
|
||||
const string &attr,
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
@@ -254,8 +244,8 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
getxattr(const string path,
|
||||
const string attr,
|
||||
getxattr(const string &path,
|
||||
const string &attr,
|
||||
string &value)
|
||||
{
|
||||
int rv;
|
||||
@@ -270,7 +260,7 @@ namespace fs
|
||||
|
||||
|
||||
int
|
||||
getxattrs(const string path,
|
||||
getxattrs(const string &path,
|
||||
map<string,string> &attrs)
|
||||
{
|
||||
int rv;
|
||||
@@ -298,10 +288,10 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
setxattr(const string path,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags)
|
||||
setxattr(const string &path,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::setxattr(path.c_str(),
|
||||
@@ -316,10 +306,10 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
setxattr(const int fd,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags)
|
||||
setxattr(const int fd,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::fsetxattr(fd,
|
||||
@@ -334,7 +324,7 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
setxattrs(const string path,
|
||||
setxattrs(const string &path,
|
||||
const map<string,string> &attrs)
|
||||
{
|
||||
int fd;
|
||||
@@ -353,8 +343,8 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
copyxattrs(const string from,
|
||||
const string to)
|
||||
copyxattrs(const string &from,
|
||||
const string &to)
|
||||
{
|
||||
int rv;
|
||||
map<string,string> attrs;
|
||||
@@ -366,37 +356,48 @@ namespace fs
|
||||
return setxattrs(to,attrs);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copyattr(const string from,
|
||||
const string to)
|
||||
get_fs_ioc_flags(const string &file,
|
||||
int &flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
int flags;
|
||||
int error;
|
||||
const int openflags = O_RDONLY|O_NONBLOCK;
|
||||
|
||||
fd = ::open(from.c_str(),openflags);
|
||||
fd = ::open(file.c_str(),openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
error = errno;
|
||||
int error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = ::open(to.c_str(),openflags);
|
||||
return ::close(fd);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
set_fs_ioc_flags(const string &file,
|
||||
const int flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
const int openflags = O_RDONLY|O_NONBLOCK;
|
||||
|
||||
fd = ::open(file.c_str(),openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
error = errno;
|
||||
int error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
@@ -406,9 +407,23 @@ namespace fs
|
||||
}
|
||||
|
||||
int
|
||||
clonepath(const string fromsrc,
|
||||
const string tosrc,
|
||||
const string relative)
|
||||
copyattr(const string &from,
|
||||
const string &to)
|
||||
{
|
||||
int rv;
|
||||
int flags;
|
||||
|
||||
rv = get_fs_ioc_flags(from,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return set_fs_ioc_flags(to,flags);
|
||||
}
|
||||
|
||||
int
|
||||
clonepath(const string &fromsrc,
|
||||
const string &tosrc,
|
||||
const string &relative)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
@@ -416,7 +431,7 @@ namespace fs
|
||||
string frompath;
|
||||
string dirname;
|
||||
|
||||
dirname = fs::dirname(relative);
|
||||
dirname = fs::path::dirname(relative);
|
||||
if(!dirname.empty())
|
||||
{
|
||||
rv = clonepath(fromsrc,tosrc,dirname);
|
||||
@@ -424,18 +439,24 @@ namespace fs
|
||||
return -1;
|
||||
}
|
||||
|
||||
frompath = fs::make_path(fromsrc,relative);
|
||||
|
||||
frompath = fs::path::make(fromsrc,relative);
|
||||
rv = ::stat(frompath.c_str(),&st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
else if(!S_ISDIR(st.st_mode))
|
||||
return (errno = ENOTDIR,-1);
|
||||
|
||||
topath = fs::make_path(tosrc,relative);
|
||||
topath = fs::path::make(tosrc,relative);
|
||||
rv = ::mkdir(topath.c_str(),st.st_mode);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
{
|
||||
if(errno != EEXIST)
|
||||
return -1;
|
||||
|
||||
rv = ::chmod(topath.c_str(),st.st_mode);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
|
||||
if(rv == -1)
|
||||
@@ -450,248 +471,26 @@ namespace fs
|
||||
if(rv == -1 && errno != ENOTTY)
|
||||
return -1;
|
||||
|
||||
return (errno = 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace find
|
||||
void
|
||||
glob(const vector<string> &patterns,
|
||||
vector<string> &strs)
|
||||
{
|
||||
void
|
||||
invalid(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int flags;
|
||||
glob_t gbuf;
|
||||
|
||||
void
|
||||
ff(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
for(vector<string>::const_iterator
|
||||
iter = basepaths.begin(), eiter = basepaths.end();
|
||||
iter != eiter;
|
||||
++iter)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
flags = 0;
|
||||
for(size_t i = 0; i < patterns.size(); i++)
|
||||
{
|
||||
glob(patterns[i].c_str(),flags,NULL,&gbuf);
|
||||
flags = GLOB_APPEND;
|
||||
}
|
||||
|
||||
path = fs::make_path(*iter,fusepath);
|
||||
rv = ::eaccess(path.c_str(),F_OK);
|
||||
if(rv == 0)
|
||||
{
|
||||
paths.push_back(Path(*iter,path));
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
|
||||
strs.push_back(gbuf.gl_pathv[i]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
ffwp(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
Path fallback;
|
||||
|
||||
for(vector<string>::const_iterator
|
||||
iter = basepaths.begin(), eiter = basepaths.end();
|
||||
iter != eiter;
|
||||
++iter)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
|
||||
path = fs::make_path(*iter,fusepath);
|
||||
|
||||
rv = ((::eaccess(path.c_str(),R_OK) == 0) ||
|
||||
(::eaccess(path.c_str(),X_OK) == 0) ||
|
||||
(::eaccess(path.c_str(),W_OK) == 0));
|
||||
|
||||
if(rv)
|
||||
{
|
||||
paths.push_back(Path(*iter,path));
|
||||
return;
|
||||
}
|
||||
else if(errno == EACCES)
|
||||
{
|
||||
fallback.base = *iter;
|
||||
fallback.full = path;
|
||||
}
|
||||
}
|
||||
|
||||
if(!fallback.base.empty())
|
||||
paths.push_back(fallback);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
newest(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
time_t newest;
|
||||
string npath;
|
||||
vector<string>::const_iterator niter;
|
||||
|
||||
newest = 0;
|
||||
for(vector<string>::const_iterator
|
||||
iter = basepaths.begin(), eiter = basepaths.end();
|
||||
iter != eiter;
|
||||
++iter)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
const string path = fs::make_path(*iter,fusepath);
|
||||
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
if(rv == 0 && st.st_mtime > newest)
|
||||
{
|
||||
newest = st.st_mtime;
|
||||
niter = iter;
|
||||
npath = path;
|
||||
}
|
||||
}
|
||||
|
||||
if(newest)
|
||||
paths.push_back(Path(*niter,npath));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
all(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
for(vector<string>::const_iterator
|
||||
iter = basepaths.begin(), eiter = basepaths.end();
|
||||
iter != eiter;
|
||||
++iter)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
|
||||
path = fs::make_path(*iter,fusepath);
|
||||
rv = ::eaccess(path.c_str(),F_OK);
|
||||
if(rv == 0)
|
||||
paths.push_back(Path(*iter,path));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
mfs(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
fsblkcnt_t mfs = 0;
|
||||
string mfspath;
|
||||
string fullmfspath;
|
||||
|
||||
for(vector<string>::const_iterator
|
||||
iter = basepaths.begin(), eiter = basepaths.end();
|
||||
iter != eiter;
|
||||
++iter)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string mountpoint = *iter;
|
||||
|
||||
rv = ::statvfs(mountpoint.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_bsize * fsstats.f_bavail);
|
||||
if(spaceavail > mfs)
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfspath = mountpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fullmfspath = fs::make_path(mfspath,fusepath);
|
||||
|
||||
paths.push_back(Path(mfspath,fullmfspath));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
epmfs(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
fsblkcnt_t existingmfs = 0;
|
||||
fsblkcnt_t generalmfs = 0;
|
||||
string path;
|
||||
string generalmfspath;
|
||||
string existingmfspath;
|
||||
vector<string>::const_iterator iter = basepaths.begin();
|
||||
vector<string>::const_iterator eiter = basepaths.end();
|
||||
|
||||
do
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string mountpoint = *iter;
|
||||
|
||||
rv = ::statvfs(mountpoint.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_bsize * fsstats.f_bavail);
|
||||
if(spaceavail > generalmfs)
|
||||
{
|
||||
generalmfs = spaceavail;
|
||||
generalmfspath = mountpoint;
|
||||
}
|
||||
|
||||
path = fs::make_path(mountpoint,fusepath);
|
||||
rv = ::eaccess(path.c_str(),F_OK);
|
||||
if(rv == 0)
|
||||
{
|
||||
if(spaceavail > existingmfs)
|
||||
{
|
||||
existingmfs = spaceavail;
|
||||
existingmfspath = mountpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
while(iter != eiter);
|
||||
|
||||
if(existingmfspath.empty())
|
||||
existingmfspath = generalmfspath;
|
||||
|
||||
paths.push_back(Path(existingmfspath,path));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
rand(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths)
|
||||
{
|
||||
string randombasepath;
|
||||
string randomfullpath;
|
||||
|
||||
randombasepath = *random_element(basepaths.begin(),
|
||||
basepaths.end());
|
||||
|
||||
randomfullpath = fs::make_path(randombasepath,
|
||||
fusepath);
|
||||
|
||||
paths.push_back(Path(randombasepath,randomfullpath));
|
||||
}
|
||||
globfree(&gbuf);
|
||||
}
|
||||
};
|
||||
|
||||
+56
-74
@@ -29,108 +29,90 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "path.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
using std::size_t;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
struct Path
|
||||
namespace path
|
||||
{
|
||||
Path() {}
|
||||
Path(const string b,
|
||||
const string f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
string dirname(const string &path);
|
||||
string basename(const string &path);
|
||||
|
||||
string base;
|
||||
string full;
|
||||
};
|
||||
bool is_empty(const string &path);
|
||||
|
||||
typedef vector<Path> PathVector;
|
||||
typedef void (*SearchFunc)(const vector<string>&,const string,PathVector&);
|
||||
bool exists(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string &fusepath);
|
||||
bool exists(const vector<string> &srcmounts,
|
||||
const string &fusepath);
|
||||
|
||||
string dirname(const string path);
|
||||
string basename(const string path);
|
||||
inline
|
||||
string
|
||||
make(const string &base,
|
||||
const string &suffix)
|
||||
{
|
||||
return base + suffix;
|
||||
}
|
||||
|
||||
bool dir_is_empty(const string path);
|
||||
inline
|
||||
void
|
||||
append(string &base,
|
||||
const string &suffix)
|
||||
{
|
||||
base += suffix;
|
||||
}
|
||||
}
|
||||
|
||||
string make_path(const string base,
|
||||
const string suffix);
|
||||
void findallfiles(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
vector<string> &paths);
|
||||
|
||||
bool path_exists(vector<string>::const_iterator begin,
|
||||
vector<string>::const_iterator end,
|
||||
const string fusepath);
|
||||
bool path_exists(const vector<string> &srcmounts,
|
||||
const string fusepath);
|
||||
int clonepath(const string &srcfrom,
|
||||
const string &srcto,
|
||||
const string &relative);
|
||||
|
||||
int clonepath(const string srcfrom,
|
||||
const string srcto,
|
||||
const string relative);
|
||||
|
||||
int listxattr(const string path,
|
||||
int listxattr(const string &path,
|
||||
vector<char> &attrs);
|
||||
int listxattr(const string path,
|
||||
int listxattr(const string &path,
|
||||
string &attrs);
|
||||
int listxattr(const string path,
|
||||
int listxattr(const string &path,
|
||||
vector<string> &attrs);
|
||||
|
||||
int getxattr(const string path,
|
||||
const string attr,
|
||||
int getxattr(const string &path,
|
||||
const string &attr,
|
||||
vector<char> &value);
|
||||
int getxattr(const string path,
|
||||
const string attr,
|
||||
int getxattr(const string &path,
|
||||
const string &attr,
|
||||
string &value);
|
||||
|
||||
int getxattrs(const string path,
|
||||
int getxattrs(const string &path,
|
||||
map<string,string> &attrs);
|
||||
|
||||
int setxattr(const string path,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags);
|
||||
int setxattr(const int fd,
|
||||
const string key,
|
||||
const string value,
|
||||
const int flags);
|
||||
int setxattr(const string &path,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags);
|
||||
int setxattr(const int fd,
|
||||
const string &key,
|
||||
const string &value,
|
||||
const int flags);
|
||||
|
||||
int setxattrs(const string path,
|
||||
int setxattrs(const string &path,
|
||||
const map<string,string> &attrs);
|
||||
|
||||
int copyxattrs(const string from,
|
||||
const string to);
|
||||
int copyxattrs(const string &from,
|
||||
const string &to);
|
||||
|
||||
int copyattr(const string from,
|
||||
const string to);
|
||||
int copyattr(const string &from,
|
||||
const string &to);
|
||||
|
||||
namespace find
|
||||
{
|
||||
void invalid(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths);
|
||||
void ff(const vector<string> &basepaths,
|
||||
const string fusepath,
|
||||
PathVector &paths);
|
||||
void ffwp(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
PathVector &rv);
|
||||
void newest(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
PathVector &rv);
|
||||
void all(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
PathVector &rv);
|
||||
void mfs(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
PathVector &rv);
|
||||
void epmfs(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
PathVector &rv);
|
||||
void rand(const vector<string> &paths,
|
||||
const string fusepath,
|
||||
PathVector &rv);
|
||||
}
|
||||
void glob(const vector<string> &patterns,
|
||||
vector<string> &strs);
|
||||
};
|
||||
|
||||
#endif // __FS_HPP__
|
||||
|
||||
+1
-5
@@ -34,8 +34,6 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_fsync(const int fd,
|
||||
@@ -59,9 +57,7 @@ namespace mergerfs
|
||||
int isdatasync,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
||||
|
||||
return _fsync(fileinfo->fd,
|
||||
return _fsync(ffi->fh,
|
||||
isdatasync);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -28,8 +28,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_ftruncate(const int fd,
|
||||
@@ -51,9 +49,7 @@ namespace mergerfs
|
||||
off_t size,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
||||
|
||||
return _ftruncate(fileinfo->fd,
|
||||
return _ftruncate(ffi->fh,
|
||||
size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fusefunc.hpp"
|
||||
#include "category.hpp"
|
||||
#include "buildvector.hpp"
|
||||
|
||||
#define FUSEFUNC(X,Y) FuseFunc(FuseFunc::Enum::X,#X,Category::Enum::Y)
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
const std::vector<FuseFunc> FuseFunc::_fusefuncs_ =
|
||||
buildvector<FuseFunc,true>
|
||||
(FUSEFUNC(invalid,invalid))
|
||||
(FUSEFUNC(access,search))
|
||||
(FUSEFUNC(chmod,action))
|
||||
(FUSEFUNC(chown,action))
|
||||
(FUSEFUNC(create,create))
|
||||
(FUSEFUNC(getattr,search))
|
||||
(FUSEFUNC(getxattr,search))
|
||||
(FUSEFUNC(link,action))
|
||||
(FUSEFUNC(listxattr,search))
|
||||
(FUSEFUNC(mkdir,create))
|
||||
(FUSEFUNC(mknod,create))
|
||||
(FUSEFUNC(open,search))
|
||||
(FUSEFUNC(readlink,search))
|
||||
(FUSEFUNC(removexattr,action))
|
||||
(FUSEFUNC(rename,action))
|
||||
(FUSEFUNC(rmdir,action))
|
||||
(FUSEFUNC(setxattr,action))
|
||||
(FUSEFUNC(symlink,create))
|
||||
(FUSEFUNC(truncate,action))
|
||||
(FUSEFUNC(unlink,action))
|
||||
(FUSEFUNC(utimens,action))
|
||||
;
|
||||
|
||||
const FuseFunc * const FuseFunc::fusefuncs = &_fusefuncs_[1];
|
||||
|
||||
const FuseFunc &FuseFunc::invalid = FuseFunc::fusefuncs[FuseFunc::Enum::invalid];
|
||||
const FuseFunc &FuseFunc::access = FuseFunc::fusefuncs[FuseFunc::Enum::access];
|
||||
const FuseFunc &FuseFunc::chmod = FuseFunc::fusefuncs[FuseFunc::Enum::chmod];
|
||||
const FuseFunc &FuseFunc::chown = FuseFunc::fusefuncs[FuseFunc::Enum::chown];
|
||||
const FuseFunc &FuseFunc::create = FuseFunc::fusefuncs[FuseFunc::Enum::create];
|
||||
const FuseFunc &FuseFunc::getattr = FuseFunc::fusefuncs[FuseFunc::Enum::getattr];
|
||||
const FuseFunc &FuseFunc::getxattr = FuseFunc::fusefuncs[FuseFunc::Enum::getxattr];
|
||||
const FuseFunc &FuseFunc::link = FuseFunc::fusefuncs[FuseFunc::Enum::link];
|
||||
const FuseFunc &FuseFunc::listxattr = FuseFunc::fusefuncs[FuseFunc::Enum::listxattr];
|
||||
const FuseFunc &FuseFunc::mkdir = FuseFunc::fusefuncs[FuseFunc::Enum::mkdir];
|
||||
const FuseFunc &FuseFunc::mknod = FuseFunc::fusefuncs[FuseFunc::Enum::mknod];
|
||||
const FuseFunc &FuseFunc::open = FuseFunc::fusefuncs[FuseFunc::Enum::open];
|
||||
const FuseFunc &FuseFunc::readlink = FuseFunc::fusefuncs[FuseFunc::Enum::readlink];
|
||||
const FuseFunc &FuseFunc::removexattr = FuseFunc::fusefuncs[FuseFunc::Enum::removexattr];
|
||||
const FuseFunc &FuseFunc::rmdir = FuseFunc::fusefuncs[FuseFunc::Enum::rmdir];
|
||||
const FuseFunc &FuseFunc::setxattr = FuseFunc::fusefuncs[FuseFunc::Enum::setxattr];
|
||||
const FuseFunc &FuseFunc::symlink = FuseFunc::fusefuncs[FuseFunc::Enum::symlink];
|
||||
const FuseFunc &FuseFunc::truncate = FuseFunc::fusefuncs[FuseFunc::Enum::truncate];
|
||||
const FuseFunc &FuseFunc::unlink = FuseFunc::fusefuncs[FuseFunc::Enum::unlink];
|
||||
const FuseFunc &FuseFunc::utimens = FuseFunc::fusefuncs[FuseFunc::Enum::utimens];
|
||||
|
||||
const FuseFunc&
|
||||
FuseFunc::find(const std::string &str)
|
||||
{
|
||||
for(int i = Enum::BEGIN; i != Enum::END; ++i)
|
||||
{
|
||||
if(fusefuncs[i] == str)
|
||||
return fusefuncs[i];
|
||||
}
|
||||
|
||||
return invalid;
|
||||
}
|
||||
|
||||
const FuseFunc&
|
||||
FuseFunc::find(const FuseFunc::Enum::Type i)
|
||||
{
|
||||
if(i >= FuseFunc::Enum::BEGIN &&
|
||||
i < FuseFunc::Enum::END)
|
||||
return fusefuncs[i];
|
||||
|
||||
return invalid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FUSEFUNC_HPP__
|
||||
#define __FUSEFUNC_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "category.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
class FuseFunc
|
||||
{
|
||||
public:
|
||||
struct Enum
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
invalid = -1,
|
||||
BEGIN = 0,
|
||||
access = BEGIN,
|
||||
chmod,
|
||||
chown,
|
||||
create,
|
||||
getattr,
|
||||
getxattr,
|
||||
link,
|
||||
listxattr,
|
||||
mkdir,
|
||||
mknod,
|
||||
open,
|
||||
readlink,
|
||||
removexattr,
|
||||
rename,
|
||||
rmdir,
|
||||
setxattr,
|
||||
symlink,
|
||||
truncate,
|
||||
unlink,
|
||||
utimens,
|
||||
END
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
Enum::Type _enum;
|
||||
std::string _str;
|
||||
Category::Enum::Type _category;
|
||||
|
||||
public:
|
||||
FuseFunc()
|
||||
: _enum(invalid),
|
||||
_str(invalid),
|
||||
_category(Category::Enum::invalid)
|
||||
{
|
||||
}
|
||||
|
||||
FuseFunc(const Enum::Type enum_,
|
||||
const std::string &str_,
|
||||
const Category::Enum::Type category_)
|
||||
: _enum(enum_),
|
||||
_str(str_),
|
||||
_category(category_)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
operator const Enum::Type() const { return _enum; }
|
||||
operator const std::string&() const { return _str; }
|
||||
operator const Category::Enum::Type() const { return _category; }
|
||||
operator const FuseFunc*() const { return this; }
|
||||
|
||||
bool operator==(const std::string &str_) const
|
||||
{ return _str == str_; }
|
||||
|
||||
bool operator==(const Enum::Type enum_) const
|
||||
{ return _enum == enum_; }
|
||||
|
||||
bool operator!=(const FuseFunc &r) const
|
||||
{ return _enum != r._enum; }
|
||||
|
||||
bool operator<(const FuseFunc &r) const
|
||||
{ return _enum < r._enum; }
|
||||
|
||||
public:
|
||||
static const FuseFunc &find(const std::string&);
|
||||
static const FuseFunc &find(const Enum::Type);
|
||||
|
||||
public:
|
||||
static const std::vector<FuseFunc> _fusefuncs_;
|
||||
static const FuseFunc * const fusefuncs;
|
||||
static const FuseFunc &invalid;
|
||||
static const FuseFunc &access;
|
||||
static const FuseFunc &chmod;
|
||||
static const FuseFunc &chown;
|
||||
static const FuseFunc &create;
|
||||
static const FuseFunc &getattr;
|
||||
static const FuseFunc &getxattr;
|
||||
static const FuseFunc &link;
|
||||
static const FuseFunc &listxattr;
|
||||
static const FuseFunc &mkdir;
|
||||
static const FuseFunc &mknod;
|
||||
static const FuseFunc &open;
|
||||
static const FuseFunc &readlink;
|
||||
static const FuseFunc &removexattr;
|
||||
static const FuseFunc &rename;
|
||||
static const FuseFunc &rmdir;
|
||||
static const FuseFunc &setxattr;
|
||||
static const FuseFunc &symlink;
|
||||
static const FuseFunc &truncate;
|
||||
static const FuseFunc &unlink;
|
||||
static const FuseFunc &utimens;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+22
-15
@@ -35,10 +35,11 @@
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
@@ -48,10 +49,10 @@ _getattr_controlfile(struct stat &buf)
|
||||
|
||||
buf.st_dev = 0;
|
||||
buf.st_ino = 0;
|
||||
buf.st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
buf.st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
|
||||
buf.st_nlink = 1;
|
||||
buf.st_uid = ::geteuid();
|
||||
buf.st_gid = ::getegid();
|
||||
buf.st_uid = ::getuid();
|
||||
buf.st_gid = ::getgid();
|
||||
buf.st_rdev = 0;
|
||||
buf.st_size = 0;
|
||||
buf.st_blksize = 1024;
|
||||
@@ -65,19 +66,22 @@ _getattr_controlfile(struct stat &buf)
|
||||
|
||||
static
|
||||
int
|
||||
_getattr(const fs::SearchFunc searchFunc,
|
||||
_getattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
struct stat &buf)
|
||||
{
|
||||
int rv;
|
||||
fs::PathVector paths;
|
||||
vector<string> path;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = ::lstat(paths[0].full.c_str(),&buf);
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
rv = ::lstat(path[0].c_str(),&buf);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
@@ -90,15 +94,18 @@ namespace mergerfs
|
||||
getattr(const char *fusepath,
|
||||
struct stat *st)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const config::Config &config = config::get();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _getattr_controlfile(*st);
|
||||
|
||||
return _getattr(*config.search,
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _getattr(config.getattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
*st);
|
||||
}
|
||||
|
||||
+139
-23
@@ -26,7 +26,10 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
@@ -34,29 +37,96 @@
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "xattr.hpp"
|
||||
#include "str.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
using namespace mergerfs;
|
||||
using namespace mergerfs::config;
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_fusefunc_policy(const Config &config,
|
||||
const char *attrbasename,
|
||||
string &attrvalue)
|
||||
{
|
||||
FuseFunc fusefunc;
|
||||
|
||||
fusefunc = FuseFunc::find(attrbasename);
|
||||
if(fusefunc != FuseFunc::invalid)
|
||||
attrvalue = (std::string)*config.policies[(FuseFunc::Enum::Type)*fusefunc];
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_category_policy(const Config &config,
|
||||
const char *attrbasename,
|
||||
string &attrvalue)
|
||||
{
|
||||
Category cat;
|
||||
|
||||
cat = Category::find(attrbasename);
|
||||
if(cat != Category::invalid)
|
||||
{
|
||||
vector<string> policies;
|
||||
for(int i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
|
||||
{
|
||||
if(cat == (Category::Enum::Type)*FuseFunc::fusefuncs[i])
|
||||
policies.push_back(*config.policies[i]);
|
||||
}
|
||||
|
||||
std::sort(policies.begin(),policies.end());
|
||||
policies.erase(std::unique(policies.begin(),policies.end()),
|
||||
policies.end());
|
||||
attrvalue = str::join(policies,',');
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_srcmounts(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
attrvalue = str::join(config.srcmounts,':');
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_minfreespace(const Config &config,
|
||||
string &attrvalue)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
snprintf(buf,sizeof(buf),"%li",config.minfreespace);
|
||||
|
||||
attrvalue = buf;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr_controlfile(const Config &config,
|
||||
const string attrname,
|
||||
const char *attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
size_t len;
|
||||
string attrvalue;
|
||||
const char *attrbasename = &attrname[sizeof("user.mergerfs.")-1];
|
||||
|
||||
if(attrname == "user.mergerfs.action")
|
||||
attrvalue = (std::string)*config.action;
|
||||
else if(attrname == "user.mergerfs.create")
|
||||
attrvalue = (std::string)*config.create;
|
||||
else if(attrname == "user.mergerfs.search")
|
||||
attrvalue = (std::string)*config.search;
|
||||
if(strncmp("user.mergerfs.",attrname,sizeof("user.mergerfs.")-1))
|
||||
return -ENOATTR;
|
||||
|
||||
if(!strcmp("srcmounts",attrbasename))
|
||||
_getxattr_controlfile_srcmounts(config,attrvalue);
|
||||
else if(!strcmp("minfreespace",attrbasename))
|
||||
_getxattr_controlfile_minfreespace(config,attrvalue);
|
||||
else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
|
||||
_getxattr_controlfile_category_policy(config,&attrbasename[sizeof("category.")-1],attrvalue);
|
||||
else if(!strncmp("func.",attrbasename,sizeof("func.")-1))
|
||||
_getxattr_controlfile_fusefunc_policy(config,&attrbasename[sizeof("func.")-1],attrvalue);
|
||||
|
||||
if(attrvalue.empty())
|
||||
return -ENOATTR;
|
||||
@@ -95,27 +165,70 @@ _getxattr_from_string(char *destbuf,
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr(const fs::SearchFunc searchFunc,
|
||||
_getxattr_user_mergerfs_allpaths(const vector<string> &srcmounts,
|
||||
const string &fusepath,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
string concated;
|
||||
vector<string> paths;
|
||||
|
||||
fs::findallfiles(srcmounts,fusepath,paths);
|
||||
|
||||
concated = str::join(paths,'\0');
|
||||
|
||||
return ::_getxattr_from_string(buf,count,concated);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr_user_mergerfs(const string &basepath,
|
||||
const string &fusepath,
|
||||
const string &fullpath,
|
||||
const vector<string> &srcmounts,
|
||||
const char *attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
const char *attrbasename = &attrname[sizeof("user.mergerfs")];
|
||||
|
||||
if(!strcmp(attrbasename,"basepath"))
|
||||
return ::_getxattr_from_string(buf,count,basepath);
|
||||
else if(!strcmp(attrbasename,"fullpath"))
|
||||
return ::_getxattr_from_string(buf,count,fullpath);
|
||||
else if(!strcmp(attrbasename,"relpath"))
|
||||
return ::_getxattr_from_string(buf,count,fusepath);
|
||||
else if(!strcmp(attrbasename,"allpaths"))
|
||||
return ::_getxattr_user_mergerfs_allpaths(srcmounts,fusepath,buf,count);
|
||||
|
||||
return ::lgetxattr(fullpath.c_str(),attrname,buf,count);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getxattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const char *attrname,
|
||||
char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
fs::PathVector paths;
|
||||
vector<string> basepath;
|
||||
string fullpath;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,basepath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
if(!strcmp(attrname,"user.mergerfs.basepath"))
|
||||
rv = ::_getxattr_from_string(buf,count,paths[0].base);
|
||||
else if(!strcmp(attrname,"user.mergerfs.fullpath"))
|
||||
rv = ::_getxattr_from_string(buf,count,paths[0].full);
|
||||
fullpath = fs::path::make(basepath[0],fusepath);
|
||||
|
||||
if(!strncmp("user.mergerfs.",attrname,sizeof("user.mergerfs.")-1))
|
||||
rv = _getxattr_user_mergerfs(basepath[0],fusepath,fullpath,srcmounts,attrname,buf,count);
|
||||
else
|
||||
rv = ::lgetxattr(paths[0].full.c_str(),attrname,buf,count);
|
||||
rv = ::lgetxattr(fullpath.c_str(),attrname,buf,count);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
#else
|
||||
@@ -133,9 +246,7 @@ namespace mergerfs
|
||||
char *buf,
|
||||
size_t count)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const config::Config &config = config::get();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _getxattr_controlfile(config,
|
||||
@@ -143,8 +254,13 @@ namespace mergerfs
|
||||
buf,
|
||||
count);
|
||||
|
||||
return _getxattr(*config.search,
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _getxattr(config.getxattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname,
|
||||
buf,
|
||||
|
||||
+10
-22
@@ -22,34 +22,22 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <string.h>
|
||||
#include <fuse.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "readdir.hpp"
|
||||
#include "fs.hpp"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
test(const struct fuse_args &args,
|
||||
const mergerfs::config::Config &config)
|
||||
namespace init
|
||||
{
|
||||
void *
|
||||
init(struct fuse_conn_info *conn)
|
||||
{
|
||||
#ifdef FUSE_CAP_IOCTL_DIR
|
||||
conn->want |= FUSE_CAP_IOCTL_DIR;
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
return &config::get_writable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace init
|
||||
{
|
||||
void *
|
||||
init(struct fuse_conn_info *conn);
|
||||
}
|
||||
}
|
||||
+74
-3
@@ -25,12 +25,19 @@
|
||||
#include <fuse.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
@@ -72,6 +79,63 @@ _ioctl(const int fd,
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
}
|
||||
|
||||
#ifdef FUSE_IOCTL_DIR
|
||||
static
|
||||
int
|
||||
_ioctl_dir_base(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const int cmd,
|
||||
void *arg,
|
||||
const unsigned int flags,
|
||||
void *data)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
vector<string> path;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
fd = ::open(path[0].c_str(),flags);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
rv = _ioctl(fd,cmd,arg,flags,data);
|
||||
|
||||
::close(fd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_ioctl_dir(const string &fusepath,
|
||||
const int cmd,
|
||||
void *arg,
|
||||
const unsigned int flags,
|
||||
void *data)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _ioctl_dir_base(config.getattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
cmd,
|
||||
arg,
|
||||
flags,
|
||||
data);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ioctl
|
||||
@@ -84,9 +148,16 @@ namespace mergerfs
|
||||
unsigned int flags,
|
||||
void *data)
|
||||
{
|
||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
||||
#ifdef FUSE_IOCTL_DIR
|
||||
if(flags & FUSE_IOCTL_DIR)
|
||||
return _ioctl_dir(fusepath,
|
||||
cmd,
|
||||
arg,
|
||||
flags,
|
||||
data);
|
||||
#endif
|
||||
|
||||
return _ioctl(fileinfo->fd,
|
||||
return _ioctl(ffi->fh,
|
||||
cmd,
|
||||
arg,
|
||||
flags,
|
||||
|
||||
+53
-34
@@ -33,7 +33,7 @@
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -41,49 +41,65 @@ using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_link(const fs::SearchFunc searchFunc,
|
||||
_single_link(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &base,
|
||||
const string &oldpath,
|
||||
const string &newpath)
|
||||
{
|
||||
int rv;
|
||||
const string fulloldpath = fs::path::make(base,oldpath);
|
||||
const string fullnewpath = fs::path::make(base,newpath);
|
||||
|
||||
rv = ::link(fulloldpath.c_str(),fullnewpath.c_str());
|
||||
if(rv == -1 && errno == ENOENT)
|
||||
{
|
||||
string newpathdir;
|
||||
vector<string> foundpath;
|
||||
|
||||
newpathdir = fs::path::dirname(newpath);
|
||||
rv = searchFunc(srcmounts,newpathdir,minfreespace,foundpath);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
{
|
||||
const mergerfs::ugid::SetResetGuard ugid(0,0);
|
||||
fs::clonepath(foundpath[0],base,newpathdir);
|
||||
}
|
||||
|
||||
rv = ::link(fulloldpath.c_str(),fullnewpath.c_str());
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_link(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string from,
|
||||
const string to)
|
||||
const size_t minfreespace,
|
||||
const string &oldpath,
|
||||
const string &newpath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> oldpaths;
|
||||
|
||||
searchFunc(srcmounts,from,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = oldpaths.size(); i != ei; i++)
|
||||
{
|
||||
int lrv;
|
||||
const string pathfrom = fs::make_path(i->base,from);
|
||||
const string pathto = fs::make_path(i->base,to);
|
||||
|
||||
lrv = ::link(pathfrom.c_str(),pathto.c_str());
|
||||
if(lrv == -1 && errno == ENOENT)
|
||||
{
|
||||
string todir;
|
||||
fs::PathVector topaths;
|
||||
|
||||
todir = fs::dirname(to);
|
||||
fs::find::ffwp(srcmounts,todir,topaths);
|
||||
if(topaths.size() > 0)
|
||||
{
|
||||
fs::clonepath(topaths[0].base,i->base,todir);
|
||||
lrv = ::link(pathfrom.c_str(),pathto.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
rv &= lrv;
|
||||
rv = _single_link(searchFunc,srcmounts,minfreespace,oldpaths[i],oldpath,newpath);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -97,9 +113,12 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _link(*config.action,
|
||||
return _link(config.getattr,
|
||||
config.link,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
from,
|
||||
to);
|
||||
}
|
||||
|
||||
+35
-23
@@ -35,8 +35,9 @@
|
||||
#include "category.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "xattr.hpp"
|
||||
#include "buildvector.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -47,42 +48,51 @@ int
|
||||
_listxattr_controlfile(char *list,
|
||||
const size_t size)
|
||||
{
|
||||
size_t xattrssize;
|
||||
string xattrs;
|
||||
const vector<string> strs =
|
||||
buildvector<string>
|
||||
("user.mergerfs.srcmounts")
|
||||
("user.mergerfs.minfreespace");
|
||||
|
||||
for(int i = Category::Enum::BEGIN; i < Category::Enum::END; ++i)
|
||||
xattrs += "user.mergerfs." + (string)Category::categories[i] + '\0';
|
||||
|
||||
xattrssize = xattrs.size();
|
||||
xattrs.reserve(512);
|
||||
for(size_t i = 0; i < strs.size(); i++)
|
||||
xattrs += (strs[i] + '\0');
|
||||
for(size_t i = Category::Enum::BEGIN; i < Category::Enum::END; i++)
|
||||
xattrs += ("user.mergerfs.category." + (std::string)*Category::categories[i] + '\0');
|
||||
for(size_t i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
|
||||
xattrs += ("user.mergerfs.func." + (std::string)*FuseFunc::fusefuncs[i] + '\0');
|
||||
|
||||
if(size == 0)
|
||||
return xattrssize;
|
||||
return xattrs.size();
|
||||
|
||||
if(size < xattrssize)
|
||||
if(size < xattrs.size())
|
||||
return -ERANGE;
|
||||
|
||||
memcpy(list,xattrs.data(),xattrssize);
|
||||
memcpy(list,xattrs.c_str(),xattrs.size());
|
||||
|
||||
return xattrssize;
|
||||
return xattrs.size();
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_listxattr(const fs::SearchFunc searchFunc,
|
||||
_listxattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
char *list,
|
||||
const size_t size)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
fs::PathVector paths;
|
||||
vector<string> path;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = ::llistxattr(paths[0].full.c_str(),list,size);
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
rv = ::llistxattr(path[0].c_str(),list,size);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
#else
|
||||
@@ -99,16 +109,18 @@ namespace mergerfs
|
||||
char *list,
|
||||
size_t size)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const config::Config &config = config::get();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _listxattr_controlfile(list,
|
||||
size);
|
||||
return _listxattr_controlfile(list,size);
|
||||
|
||||
return _listxattr(*config.search,
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _listxattr(config.listxattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
list,
|
||||
size);
|
||||
|
||||
+108
-69
@@ -32,12 +32,14 @@
|
||||
#include "option_parser.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "test.hpp"
|
||||
|
||||
#include "clonepath.hpp"
|
||||
|
||||
#include "access.hpp"
|
||||
#include "chmod.hpp"
|
||||
#include "chown.hpp"
|
||||
#include "create.hpp"
|
||||
#include "destroy.hpp"
|
||||
#include "fallocate.hpp"
|
||||
#include "fgetattr.hpp"
|
||||
#include "flush.hpp"
|
||||
@@ -45,17 +47,20 @@
|
||||
#include "ftruncate.hpp"
|
||||
#include "getattr.hpp"
|
||||
#include "getxattr.hpp"
|
||||
#include "init.hpp"
|
||||
#include "ioctl.hpp"
|
||||
#include "link.hpp"
|
||||
#include "listxattr.hpp"
|
||||
#include "mkdir.hpp"
|
||||
#include "mknod.hpp"
|
||||
#include "open.hpp"
|
||||
#include "opendir.hpp"
|
||||
#include "read.hpp"
|
||||
#include "read_buf.hpp"
|
||||
#include "readdir.hpp"
|
||||
#include "readlink.hpp"
|
||||
#include "release.hpp"
|
||||
#include "releasedir.hpp"
|
||||
#include "removexattr.hpp"
|
||||
#include "rename.hpp"
|
||||
#include "rmdir.hpp"
|
||||
@@ -68,77 +73,113 @@
|
||||
#include "write.hpp"
|
||||
#include "write_buf.hpp"
|
||||
|
||||
static
|
||||
struct fuse_operations
|
||||
get_fuse_operations()
|
||||
namespace local
|
||||
{
|
||||
struct fuse_operations ops = {};
|
||||
static
|
||||
std::string
|
||||
getappname(const int argc,
|
||||
char * const *argv)
|
||||
{
|
||||
return fs::path::basename(argv[0]);
|
||||
}
|
||||
|
||||
ops.flag_nopath = false;
|
||||
ops.flag_nullpath_ok = false;
|
||||
static
|
||||
void
|
||||
get_fuse_operations(struct fuse_operations &ops)
|
||||
{
|
||||
#if FLAG_NOPATH
|
||||
ops.flag_nopath = false;
|
||||
#endif
|
||||
ops.flag_nullpath_ok = false;
|
||||
|
||||
ops.access = mergerfs::access::access;
|
||||
ops.bmap = NULL;
|
||||
ops.chmod = mergerfs::chmod::chmod;
|
||||
ops.chown = mergerfs::chown::chown;
|
||||
ops.create = mergerfs::create::create;
|
||||
ops.destroy = NULL;
|
||||
ops.fallocate = mergerfs::fallocate::fallocate;
|
||||
ops.fgetattr = mergerfs::fgetattr::fgetattr;
|
||||
ops.flock = NULL;
|
||||
ops.flush = mergerfs::flush::flush;
|
||||
ops.fsync = mergerfs::fsync::fsync;
|
||||
ops.fsyncdir = NULL;
|
||||
ops.ftruncate = mergerfs::ftruncate::ftruncate;
|
||||
ops.getattr = mergerfs::getattr::getattr;
|
||||
ops.getdir = NULL; /* deprecated; use readdir */
|
||||
ops.getxattr = mergerfs::getxattr::getxattr;
|
||||
ops.init = NULL;
|
||||
ops.ioctl = mergerfs::ioctl::ioctl;
|
||||
ops.link = mergerfs::link::link;
|
||||
ops.listxattr = mergerfs::listxattr::listxattr;
|
||||
ops.lock = NULL;
|
||||
ops.mkdir = mergerfs::mkdir::mkdir;
|
||||
ops.mknod = mergerfs::mknod::mknod;
|
||||
ops.open = mergerfs::open::open;
|
||||
ops.opendir = NULL;
|
||||
ops.poll = NULL;
|
||||
ops.read = mergerfs::read::read;
|
||||
ops.read_buf = mergerfs::read_buf::read_buf;
|
||||
ops.readdir = mergerfs::readdir::readdir;
|
||||
ops.readlink = mergerfs::readlink::readlink;
|
||||
ops.release = mergerfs::release::release;
|
||||
ops.releasedir = NULL;
|
||||
ops.removexattr = mergerfs::removexattr::removexattr;
|
||||
ops.rename = mergerfs::rename::rename;
|
||||
ops.rmdir = mergerfs::rmdir::rmdir;
|
||||
ops.setxattr = mergerfs::setxattr::setxattr;
|
||||
ops.statfs = mergerfs::statfs::statfs;
|
||||
ops.symlink = mergerfs::symlink::symlink;
|
||||
ops.truncate = mergerfs::truncate::truncate;
|
||||
ops.unlink = mergerfs::unlink::unlink;
|
||||
ops.utime = NULL; /* deprecated; use utimens() */
|
||||
ops.utimens = mergerfs::utimens::utimens;
|
||||
ops.write = mergerfs::write::write;
|
||||
ops.write_buf = mergerfs::write_buf::write_buf;
|
||||
ops.access = mergerfs::access::access;
|
||||
ops.bmap = NULL;
|
||||
ops.chmod = mergerfs::chmod::chmod;
|
||||
ops.chown = mergerfs::chown::chown;
|
||||
ops.create = mergerfs::create::create;
|
||||
ops.destroy = mergerfs::destroy::destroy;
|
||||
#if FALLOCATE
|
||||
ops.fallocate = mergerfs::fallocate::fallocate;
|
||||
#endif
|
||||
ops.fgetattr = mergerfs::fgetattr::fgetattr;
|
||||
#if FLOCK
|
||||
ops.flock = NULL;
|
||||
#endif
|
||||
ops.flush = mergerfs::flush::flush;
|
||||
ops.fsync = mergerfs::fsync::fsync;
|
||||
ops.fsyncdir = NULL;
|
||||
ops.ftruncate = mergerfs::ftruncate::ftruncate;
|
||||
ops.getattr = mergerfs::getattr::getattr;
|
||||
ops.getdir = NULL; /* deprecated; use readdir */
|
||||
ops.getxattr = mergerfs::getxattr::getxattr;
|
||||
ops.init = mergerfs::init::init;
|
||||
ops.ioctl = mergerfs::ioctl::ioctl;
|
||||
ops.link = mergerfs::link::link;
|
||||
ops.listxattr = mergerfs::listxattr::listxattr;
|
||||
ops.lock = NULL;
|
||||
ops.mkdir = mergerfs::mkdir::mkdir;
|
||||
ops.mknod = mergerfs::mknod::mknod;
|
||||
ops.open = mergerfs::open::open;
|
||||
ops.opendir = mergerfs::opendir::opendir;
|
||||
ops.poll = NULL;
|
||||
ops.read = mergerfs::read::read;
|
||||
#if READ_BUF
|
||||
ops.read_buf = mergerfs::read_buf::read_buf;
|
||||
#endif
|
||||
ops.readdir = mergerfs::readdir::readdir;
|
||||
ops.readlink = mergerfs::readlink::readlink;
|
||||
ops.release = mergerfs::release::release;
|
||||
ops.releasedir = mergerfs::releasedir::releasedir;
|
||||
ops.removexattr = mergerfs::removexattr::removexattr;
|
||||
ops.rename = mergerfs::rename::rename;
|
||||
ops.rmdir = mergerfs::rmdir::rmdir;
|
||||
ops.setxattr = mergerfs::setxattr::setxattr;
|
||||
ops.statfs = mergerfs::statfs::statfs;
|
||||
ops.symlink = mergerfs::symlink::symlink;
|
||||
ops.truncate = mergerfs::truncate::truncate;
|
||||
ops.unlink = mergerfs::unlink::unlink;
|
||||
ops.utime = NULL; /* deprecated; use utimens() */
|
||||
ops.utimens = mergerfs::utimens::utimens;
|
||||
ops.write = mergerfs::write::write;
|
||||
#if WRITE_BUF
|
||||
ops.write_buf = mergerfs::write_buf::write_buf;
|
||||
#endif
|
||||
|
||||
return ops;
|
||||
return;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
setup_resources(void)
|
||||
{
|
||||
const int prio = -10;
|
||||
|
||||
std::srand(time(NULL));
|
||||
mergerfs::resources::reset_umask();
|
||||
mergerfs::resources::maxout_rlimit_nofile();
|
||||
mergerfs::resources::maxout_rlimit_fsize();
|
||||
mergerfs::resources::setpriority(prio);
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
main(const struct fuse_args &args,
|
||||
config::Config &config)
|
||||
main(const int argc,
|
||||
char **argv)
|
||||
{
|
||||
struct fuse_operations ops;
|
||||
struct fuse_args args;
|
||||
struct fuse_operations ops = {0};
|
||||
mergerfs::config::Config config;
|
||||
|
||||
ops = get_fuse_operations();
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
args.allocated = 0;
|
||||
|
||||
std::srand(time(NULL));
|
||||
resources::reset_umask();
|
||||
resources::maxout_rlimit_nofile();
|
||||
resources::maxout_rlimit_fsize();
|
||||
mergerfs::options::parse(args,config);
|
||||
|
||||
local::setup_resources();
|
||||
local::get_fuse_operations(ops);
|
||||
|
||||
return fuse_main(args.argc,
|
||||
args.argv,
|
||||
@@ -148,16 +189,14 @@ namespace mergerfs
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc,
|
||||
char *argv[])
|
||||
main(int argc,
|
||||
char **argv)
|
||||
{
|
||||
int rv;
|
||||
mergerfs::config::Config config;
|
||||
struct fuse_args args = FUSE_ARGS_INIT(argc,argv);
|
||||
std::string appname;
|
||||
|
||||
mergerfs::options::parse(args,config);
|
||||
appname = local::getappname(argc,argv);
|
||||
if(appname == "clonepath")
|
||||
return clonepath::main(argc,argv);
|
||||
|
||||
rv = mergerfs::main(args,config);
|
||||
|
||||
return rv;
|
||||
return mergerfs::main(argc,argv);
|
||||
}
|
||||
|
||||
+37
-22
@@ -32,45 +32,58 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_mkdir(const fs::SearchFunc searchFunc,
|
||||
const fs::SearchFunc createPathFunc,
|
||||
_mkdir(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
int error;
|
||||
string dirname;
|
||||
fs::PathVector createpath;
|
||||
fs::PathVector existingpath;
|
||||
string fullpath;
|
||||
vector<string> createpaths;
|
||||
vector<string> existingpath;
|
||||
|
||||
if(fs::path_exists(srcmounts,fusepath))
|
||||
return -EEXIST;
|
||||
dirname = fs::path::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
searchFunc(srcmounts,dirname,existingpath);
|
||||
if(existingpath.empty())
|
||||
return -ENOENT;
|
||||
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
createPathFunc(srcmounts,dirname,createpath);
|
||||
if(createpath[0].base != existingpath[0].base)
|
||||
fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
|
||||
{
|
||||
string &createpath = createpaths[i];
|
||||
|
||||
path = fs::make_path(createpath[0].base,fusepath);
|
||||
if(createpath != existingpath[0])
|
||||
{
|
||||
const mergerfs::ugid::SetResetGuard ugid(0,0);
|
||||
fs::clonepath(existingpath[0],createpath,dirname);
|
||||
}
|
||||
|
||||
rv = ::mkdir(path.c_str(),mode);
|
||||
fs::path::append(createpath,fusepath);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
rv = ::mkdir(createpath.c_str(),mode);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -84,10 +97,12 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _mkdir(*config.search,
|
||||
*config.create,
|
||||
return _mkdir(config.getattr,
|
||||
config.mkdir,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
(mode & ~fc->umask));
|
||||
}
|
||||
|
||||
+36
-21
@@ -36,43 +36,56 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_mknod(const fs::SearchFunc searchFunc,
|
||||
const fs::SearchFunc createPathFunc,
|
||||
_mknod(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const mode_t mode,
|
||||
const dev_t dev)
|
||||
{
|
||||
int rv;
|
||||
string path;
|
||||
int error;
|
||||
string dirname;
|
||||
fs::PathVector createpath;
|
||||
fs::PathVector existingpath;
|
||||
vector<string> createpaths;
|
||||
vector<string> existingpath;
|
||||
|
||||
if(fs::path_exists(srcmounts,fusepath))
|
||||
return -EEXIST;
|
||||
dirname = fs::path::dirname(fusepath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
dirname = fs::dirname(fusepath);
|
||||
searchFunc(srcmounts,dirname,existingpath);
|
||||
if(existingpath.empty())
|
||||
return -ENOENT;
|
||||
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
createPathFunc(srcmounts,dirname,createpath);
|
||||
if(existingpath[0].base != createpath[0].base)
|
||||
fs::clonepath(existingpath[0].base,createpath[0].base,dirname);
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
|
||||
{
|
||||
string &createpath = createpaths[0];
|
||||
|
||||
path = fs::make_path(createpath[0].base,fusepath);
|
||||
if(createpath != existingpath[0])
|
||||
{
|
||||
const mergerfs::ugid::SetResetGuard ugid(0,0);
|
||||
fs::clonepath(existingpath[0],createpath,dirname);
|
||||
}
|
||||
|
||||
rv = ::mknod(path.c_str(),mode,dev);
|
||||
fs::path::append(createpath,fusepath);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
rv = ::mknod(createpath.c_str(),mode,dev);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -87,10 +100,12 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _mknod(*config.search,
|
||||
*config.create,
|
||||
return _mknod(config.getattr,
|
||||
config.mknod,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
(mode & ~fc->umask),
|
||||
rdev);
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace num
|
||||
{
|
||||
int
|
||||
to_size_t(const std::string &str,
|
||||
size_t &value)
|
||||
{
|
||||
size_t tmp;
|
||||
char *endptr;
|
||||
|
||||
tmp = strtoll(str.c_str(),&endptr,10);
|
||||
switch(*endptr)
|
||||
{
|
||||
case 'k':
|
||||
case 'K':
|
||||
tmp *= 1024;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
case 'M':
|
||||
tmp *= (1024 * 1024);
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
case 'G':
|
||||
tmp *= (1024 * 1024 * 1024);
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = tmp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace num
|
||||
{
|
||||
int to_size_t(const std::string &str, size_t &value);
|
||||
}
|
||||
+17
-14
@@ -32,35 +32,36 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::FileInfo;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_open(const fs::SearchFunc searchFunc,
|
||||
_open(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
{
|
||||
int fd;
|
||||
fs::PathVector paths;
|
||||
int fd;
|
||||
int rv;
|
||||
vector<string> path;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fd = ::open(paths[0].full.c_str(),flags);
|
||||
fd = ::open(path[0].c_str(),flags);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
fh = (uint64_t)new FileInfo(fd,flags,paths[0].full);
|
||||
fh = fd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -75,10 +76,12 @@ namespace mergerfs
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);;
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _open(*config.search,
|
||||
return _open(config.open,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
fileinfo->flags,
|
||||
fileinfo->fh);
|
||||
|
||||
@@ -22,32 +22,19 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FILEINFO_H__
|
||||
#define __FILEINFO_H__
|
||||
|
||||
#include <string>
|
||||
#include <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
struct FileInfo
|
||||
namespace opendir
|
||||
{
|
||||
public:
|
||||
FileInfo(int fd_,
|
||||
int flags_,
|
||||
std::string realpath_) :
|
||||
fd(fd_),
|
||||
flags(flags_),
|
||||
realpath(realpath_)
|
||||
int
|
||||
opendir(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
ffi->fh = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd;
|
||||
int flags;
|
||||
std::string realpath;
|
||||
|
||||
private:
|
||||
FileInfo() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __FILEINFO_H__ */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace opendir
|
||||
{
|
||||
int
|
||||
opendir(const char *fusepath,
|
||||
struct fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
+144
-62
@@ -27,13 +27,15 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <glob.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "str.hpp"
|
||||
#include "num.hpp"
|
||||
#include "config.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
@@ -41,45 +43,142 @@ using std::string;
|
||||
using std::vector;
|
||||
using namespace mergerfs;
|
||||
|
||||
template<typename Container>
|
||||
Container&
|
||||
split(Container &result,
|
||||
const typename Container::value_type &s,
|
||||
typename Container::value_type::value_type delimiter)
|
||||
static
|
||||
void
|
||||
set_option(struct fuse_args &args,
|
||||
const std::string &option_)
|
||||
{
|
||||
std::istringstream ss(s);
|
||||
while(!ss.eof())
|
||||
string option;
|
||||
|
||||
option = "-o" + option_;
|
||||
|
||||
fuse_opt_insert_arg(&args,1,option.c_str());
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_kv_option(struct fuse_args &args,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
{
|
||||
std::string option;
|
||||
|
||||
option = key + '=' + value;
|
||||
|
||||
set_option(args,option);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_fsname(struct fuse_args &args,
|
||||
const vector<string> &srcmounts)
|
||||
{
|
||||
if(srcmounts.size() > 0)
|
||||
{
|
||||
typename Container::value_type field;
|
||||
std::getline(ss,field,delimiter);
|
||||
if(field.empty())
|
||||
continue;
|
||||
result.push_back(field);
|
||||
std::string fsname;
|
||||
|
||||
fsname = str::remove_common_prefix_and_join(srcmounts,':');
|
||||
|
||||
set_kv_option(args,"fsname",fsname);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_subtype(struct fuse_args &args)
|
||||
{
|
||||
set_kv_option(args,"subtype","mergerfs");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_default_options(struct fuse_args &args)
|
||||
{
|
||||
set_option(args,"big_writes");
|
||||
set_option(args,"splice_read");
|
||||
set_option(args,"splice_write");
|
||||
set_option(args,"splice_move");
|
||||
set_option(args,"auto_cache");
|
||||
set_option(args,"atomic_o_trunc");
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_minfreespace(const std::string &value,
|
||||
size_t &minfreespace)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = num::to_size_t(value,minfreespace);
|
||||
if(rv == -1)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_arg(config::Config &config,
|
||||
const std::string &arg,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
if(arg == "defaults")
|
||||
{
|
||||
set_default_options(*outargs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_kv_arg(config::Config &config,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
{
|
||||
int rv = -1;
|
||||
std::vector<std::string> keypart;
|
||||
|
||||
str::split(keypart,key,'.');
|
||||
if(keypart.size() == 2)
|
||||
{
|
||||
if(keypart[0] == "func")
|
||||
rv = config.set_func_policy(keypart[1],value);
|
||||
else if(keypart[0] == "category")
|
||||
rv = config.set_category_policy(keypart[1],value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(key == "minfreespace")
|
||||
rv = parse_and_process_minfreespace(value,config.minfreespace);
|
||||
}
|
||||
|
||||
if(rv == -1)
|
||||
rv = 1;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
process_opt(config::Config &config,
|
||||
const std::string arg)
|
||||
const std::string &arg,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
int rv = 0;
|
||||
int rv;
|
||||
std::vector<std::string> argvalue;
|
||||
|
||||
split(argvalue,arg,'=');
|
||||
rv = 1;
|
||||
str::split(argvalue,arg,'=');
|
||||
switch(argvalue.size())
|
||||
{
|
||||
case 1:
|
||||
rv = parse_and_process_arg(config,argvalue[0],outargs);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(argvalue[0] == "create")
|
||||
config.create = Policy::find(argvalue[1]);
|
||||
else if(argvalue[0] == "search")
|
||||
config.search = Policy::find(argvalue[1]);
|
||||
else if(argvalue[0] == "action")
|
||||
config.action = Policy::find(argvalue[1]);
|
||||
else
|
||||
rv = 1;
|
||||
rv = parse_and_process_kv_arg(config,argvalue[0],argvalue[1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -91,26 +190,27 @@ process_opt(config::Config &config,
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
process_srcmounts(const char *arg,
|
||||
config::Config &config)
|
||||
{
|
||||
int flags;
|
||||
glob_t gbuf;
|
||||
vector<string> paths;
|
||||
|
||||
flags = 0;
|
||||
split(paths,arg,':');
|
||||
for(size_t i = 0; i < paths.size(); i++)
|
||||
{
|
||||
glob(paths[i].c_str(),flags,NULL,&gbuf);
|
||||
flags = GLOB_APPEND;
|
||||
}
|
||||
str::split(paths,arg,':');
|
||||
|
||||
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
|
||||
config.srcmounts.push_back(gbuf.gl_pathv[i]);
|
||||
fs::glob(paths,config.srcmounts);
|
||||
|
||||
globfree(&gbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
process_destmounts(const char *arg,
|
||||
config::Config &config)
|
||||
{
|
||||
config.destmount = arg;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
@@ -126,14 +226,13 @@ option_processor(void *data,
|
||||
switch(key)
|
||||
{
|
||||
case FUSE_OPT_KEY_OPT:
|
||||
rv = process_opt(config,arg);
|
||||
rv = process_opt(config,arg,outargs);
|
||||
break;
|
||||
|
||||
case FUSE_OPT_KEY_NONOPT:
|
||||
if(config.srcmounts.empty())
|
||||
process_srcmounts(arg,config);
|
||||
else
|
||||
rv = (config.destmount = arg,1);
|
||||
rv = config.srcmounts.empty() ?
|
||||
process_srcmounts(arg,config) :
|
||||
process_destmounts(arg,config);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -143,24 +242,6 @@ option_processor(void *data,
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_fsname(struct fuse_args &args,
|
||||
const config::Config &config)
|
||||
{
|
||||
if(config.srcmounts.size() > 0)
|
||||
{
|
||||
std::string fsname;
|
||||
|
||||
fsname = "-ofsname=";
|
||||
fsname += config.srcmounts[0];
|
||||
for(size_t i = 1; i < config.srcmounts.size(); i++)
|
||||
fsname += ';' + config.srcmounts[i];
|
||||
|
||||
fuse_opt_insert_arg(&args,1,fsname.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace options
|
||||
@@ -175,7 +256,8 @@ namespace mergerfs
|
||||
NULL,
|
||||
::option_processor);
|
||||
|
||||
set_fsname(args,config);
|
||||
set_fsname(args,config.srcmounts);
|
||||
set_subtype(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __PATH_HPP__
|
||||
#define __PATH_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct Path
|
||||
{
|
||||
Path() {}
|
||||
|
||||
explicit
|
||||
Path(const std::string &b,
|
||||
const std::string &f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Path(const char *b,
|
||||
const std::string &f)
|
||||
: base(b),
|
||||
full(f)
|
||||
{}
|
||||
|
||||
std::string base;
|
||||
std::string full;
|
||||
};
|
||||
|
||||
typedef std::vector<Path> Paths;
|
||||
|
||||
#endif /* __PATH_HPP__ */
|
||||
+6
-2
@@ -28,7 +28,7 @@
|
||||
#include "fs.hpp"
|
||||
#include "buildvector.hpp"
|
||||
|
||||
#define POLICY(X) (Policy(Policy::Enum::X,#X,fs::find::X))
|
||||
#define POLICY(X) (Policy(Policy::Enum::X,#X,Policy::Func::X))
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
@@ -39,6 +39,8 @@ namespace mergerfs
|
||||
(POLICY(epmfs))
|
||||
(POLICY(ff))
|
||||
(POLICY(ffwp))
|
||||
(POLICY(fwfs))
|
||||
(POLICY(lfs))
|
||||
(POLICY(mfs))
|
||||
(POLICY(newest))
|
||||
(POLICY(rand));
|
||||
@@ -50,12 +52,14 @@ namespace mergerfs
|
||||
const Policy &Policy::epmfs = Policy::policies[Policy::Enum::epmfs];
|
||||
const Policy &Policy::ff = Policy::policies[Policy::Enum::ff];
|
||||
const Policy &Policy::ffwp = Policy::policies[Policy::Enum::ffwp];
|
||||
const Policy &Policy::fwfs = Policy::policies[Policy::Enum::fwfs];
|
||||
const Policy &Policy::lfs = Policy::policies[Policy::Enum::lfs];
|
||||
const Policy &Policy::mfs = Policy::policies[Policy::Enum::mfs];
|
||||
const Policy &Policy::newest = Policy::policies[Policy::Enum::newest];
|
||||
const Policy &Policy::rand = Policy::policies[Policy::Enum::rand];
|
||||
|
||||
const Policy&
|
||||
Policy::find(const std::string str)
|
||||
Policy::find(const std::string &str)
|
||||
{
|
||||
for(int i = Enum::BEGIN; i != Enum::END; ++i)
|
||||
{
|
||||
|
||||
+103
-20
@@ -26,9 +26,12 @@
|
||||
#define __POLICY_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "path.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "category.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
@@ -45,6 +48,8 @@ namespace mergerfs
|
||||
epmfs,
|
||||
ff,
|
||||
ffwp,
|
||||
fwfs,
|
||||
lfs,
|
||||
mfs,
|
||||
newest,
|
||||
rand,
|
||||
@@ -52,10 +57,85 @@ namespace mergerfs
|
||||
};
|
||||
};
|
||||
|
||||
struct Func
|
||||
{
|
||||
typedef std::string string;
|
||||
typedef std::size_t size_t;
|
||||
typedef std::vector<string> strvec;
|
||||
typedef const string cstring;
|
||||
typedef const size_t csize_t;
|
||||
typedef const strvec cstrvec;
|
||||
typedef const Category::Enum::Type CType;
|
||||
|
||||
typedef int (*Ptr)(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
Action(const Policy *p)
|
||||
: func(p->_func)
|
||||
{}
|
||||
|
||||
int
|
||||
operator()(cstrvec& b,cstring& c,csize_t d,strvec& e)
|
||||
{
|
||||
return func(Category::Enum::action,b,c,d,e);
|
||||
}
|
||||
|
||||
private:
|
||||
const Ptr func;
|
||||
};
|
||||
|
||||
class Create
|
||||
{
|
||||
public:
|
||||
Create(const Policy *p)
|
||||
: func(p->_func)
|
||||
{}
|
||||
|
||||
int
|
||||
operator()(cstrvec& b,cstring& c,csize_t d,strvec& e)
|
||||
{
|
||||
return func(Category::Enum::create,b,c,d,e);
|
||||
}
|
||||
|
||||
private:
|
||||
const Ptr func;
|
||||
};
|
||||
|
||||
class Search
|
||||
{
|
||||
public:
|
||||
Search(const Policy *p)
|
||||
: func(p->_func)
|
||||
{}
|
||||
|
||||
int
|
||||
operator()(cstrvec& b,cstring& c,csize_t d,strvec& e)
|
||||
{
|
||||
return func(Category::Enum::search,b,c,d,e);
|
||||
}
|
||||
|
||||
private:
|
||||
const Ptr func;
|
||||
};
|
||||
|
||||
static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int all(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int epmfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int ff(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int ffwp(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int fwfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int lfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int mfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int newest(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int rand(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
};
|
||||
|
||||
private:
|
||||
Enum::Type _enum;
|
||||
std::string _str;
|
||||
fs::SearchFunc _func;
|
||||
Enum::Type _enum;
|
||||
std::string _str;
|
||||
Func::Ptr _func;
|
||||
|
||||
public:
|
||||
Policy()
|
||||
@@ -65,9 +145,9 @@ namespace mergerfs
|
||||
{
|
||||
}
|
||||
|
||||
Policy(const Enum::Type enum_,
|
||||
const std::string str_,
|
||||
const fs::SearchFunc func_)
|
||||
Policy(const Enum::Type enum_,
|
||||
const std::string &str_,
|
||||
const Func::Ptr func_)
|
||||
: _enum(enum_),
|
||||
_str(str_),
|
||||
_func(func_)
|
||||
@@ -76,17 +156,17 @@ namespace mergerfs
|
||||
|
||||
public:
|
||||
operator const Enum::Type() const { return _enum; }
|
||||
operator const std::string() const { return _str; }
|
||||
operator const fs::SearchFunc() const { return _func; }
|
||||
operator const std::string&() const { return _str; }
|
||||
operator const Func::Ptr() const { return _func; }
|
||||
operator const Policy*() const { return this; }
|
||||
|
||||
bool operator==(const Enum::Type enum_) const
|
||||
{ return _enum == enum_; }
|
||||
bool operator==(const std::string str_) const
|
||||
bool operator==(const std::string &str_) const
|
||||
{ return _str == str_; }
|
||||
bool operator==(const fs::SearchFunc func_) const
|
||||
bool operator==(const Func::Ptr func_) const
|
||||
{ return _func == func_; }
|
||||
|
||||
|
||||
bool operator!=(const Policy &r) const
|
||||
{ return _enum != r._enum; }
|
||||
|
||||
@@ -94,20 +174,23 @@ namespace mergerfs
|
||||
{ return _enum < r._enum; }
|
||||
|
||||
public:
|
||||
static const Policy &find(const std::string);
|
||||
static const Policy &find(const std::string&);
|
||||
static const Policy &find(const Enum::Type);
|
||||
|
||||
public:
|
||||
static const std::vector<Policy> _policies_;
|
||||
static const Policy * const policies;
|
||||
static const Policy &invalid;
|
||||
static const Policy &all;
|
||||
static const Policy &epmfs;
|
||||
static const Policy &ff;
|
||||
static const Policy &ffwp;
|
||||
static const Policy &mfs;
|
||||
static const Policy &newest;
|
||||
static const Policy &rand;
|
||||
|
||||
static const Policy &invalid;
|
||||
static const Policy &all;
|
||||
static const Policy &epmfs;
|
||||
static const Policy &ff;
|
||||
static const Policy &ffwp;
|
||||
static const Policy &fwfs;
|
||||
static const Policy &lfs;
|
||||
static const Policy &mfs;
|
||||
static const Policy &newest;
|
||||
static const Policy &rand;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_all(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const char *basepath;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == 0)
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
|
||||
return paths.empty() ? (errno=ENOENT,-1) : 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::all(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return _all(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
inline
|
||||
void
|
||||
_calc_epmfs(const struct statvfs &fsstats,
|
||||
const char *basepath,
|
||||
fsblkcnt_t &epmfs,
|
||||
const char *&epmfsbasepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail > epmfs)
|
||||
{
|
||||
epmfs = spaceavail;
|
||||
epmfsbasepath = basepath;
|
||||
}
|
||||
|
||||
if(spaceavail > mfs)
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfsbasepath = basepath;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
void
|
||||
_calc_mfs(const struct statvfs &fsstats,
|
||||
const char *basepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail > mfs)
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfsbasepath = basepath;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_try_statvfs(const char *basepath,
|
||||
const string &fullpath,
|
||||
fsblkcnt_t &epmfs,
|
||||
const char *&epmfsbasepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
_calc_epmfs(fsstats,basepath,epmfs,epmfsbasepath,mfs,mfsbasepath);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_try_statvfs(const char *basepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
if(rv == 0)
|
||||
_calc_mfs(fsstats,basepath,mfs,mfsbasepath);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epmfs_create(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
|
||||
{
|
||||
fsblkcnt_t epmfs;
|
||||
fsblkcnt_t mfs;
|
||||
const char *basepath;
|
||||
const char *mfsbasepath;
|
||||
const char *epmfsbasepath;
|
||||
string fullpath;
|
||||
|
||||
mfs = 0;
|
||||
epmfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = _try_statvfs(basepath,fusepath,epmfs,epmfsbasepath,mfs,mfsbasepath);
|
||||
if(rv == -1)
|
||||
_try_statvfs(basepath,mfs,mfsbasepath);
|
||||
}
|
||||
|
||||
if(epmfsbasepath == NULL)
|
||||
epmfsbasepath = mfsbasepath;
|
||||
|
||||
paths.push_back(epmfsbasepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epmfs(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
|
||||
{
|
||||
fsblkcnt_t epmfs;
|
||||
const char *basepath;
|
||||
const char *epmfsbasepath;
|
||||
string fullpath;
|
||||
|
||||
epmfs = 0;
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
_calc_mfs(fsstats,basepath,epmfs,epmfsbasepath);
|
||||
}
|
||||
|
||||
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 string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _epmfs_create(basepaths,fusepath,paths);
|
||||
|
||||
return _epmfs(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_ff(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
const char *basepath;
|
||||
string fullpath;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (errno=ENOENT,-1);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::ff(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return _ff(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_ffwp(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
const char *fallback;
|
||||
|
||||
fallback = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
const char *basepath;
|
||||
string fullpath;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == 0)
|
||||
{
|
||||
paths.push_back(basepath);
|
||||
return 0;
|
||||
}
|
||||
else if(errno == EACCES)
|
||||
{
|
||||
fallback = basepath;
|
||||
}
|
||||
}
|
||||
|
||||
if(fallback == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(fallback);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::ffwp(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return _ffwp(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_fwfs_create(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
||||
{
|
||||
int rv;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_fwfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::fwfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _fwfs_create(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _fwfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::invalid(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &rv)
|
||||
{
|
||||
return (errno = EINVAL,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_lfs_create(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t lfs;
|
||||
const char *lfsstr;
|
||||
|
||||
lfs = -1;
|
||||
lfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if((spaceavail > minfreespace) &&
|
||||
(spaceavail < lfs))
|
||||
{
|
||||
lfs = spaceavail;
|
||||
lfsstr = basepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(lfsstr == NULL)
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
paths.push_back(lfsstr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_lfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t lfs;
|
||||
const char *lfsstr;
|
||||
|
||||
lfs = -1;
|
||||
lfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if((spaceavail > minfreespace) &&
|
||||
(spaceavail < lfs))
|
||||
{
|
||||
lfs = spaceavail;
|
||||
lfsstr = basepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(lfsstr == NULL)
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
paths.push_back(lfsstr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::lfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _lfs_create(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _lfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_mfs_create(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t mfs;
|
||||
const char *mfsstr;
|
||||
|
||||
mfs = 0;
|
||||
mfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail > mfs)
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfsstr = basepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mfsstr == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(mfsstr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_mfs(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t mfs;
|
||||
const char *mfsstr;
|
||||
|
||||
mfs = 0;
|
||||
mfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||
if(spaceavail > mfs)
|
||||
{
|
||||
mfs = spaceavail;
|
||||
mfsstr = basepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mfsstr == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(mfsstr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::mfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _mfs_create(basepaths,fusepath,paths);
|
||||
|
||||
return _mfs(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_newest(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
time_t newest;
|
||||
const char *neweststr;
|
||||
|
||||
newest = 0;
|
||||
neweststr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
const char *basepath;
|
||||
string fullpath;
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(rv == 0 && st.st_mtime > newest)
|
||||
{
|
||||
newest = st.st_mtime;
|
||||
neweststr = basepath;
|
||||
}
|
||||
}
|
||||
|
||||
if(neweststr == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(neweststr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::newest(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return _newest(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::rand(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = Policy::Func::all(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
std::random_shuffle(paths.begin(),paths.end());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -29,9 +29,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
@@ -58,7 +55,7 @@ namespace mergerfs
|
||||
off_t offset,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return _read(((FileInfo*)ffi->fh)->fd,
|
||||
return _read(ffi->fh,
|
||||
buf,
|
||||
count,
|
||||
offset);
|
||||
|
||||
+5
-3
@@ -22,14 +22,14 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#if READ_BUF
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_read_buf(const int fd,
|
||||
@@ -65,10 +65,12 @@ namespace mergerfs
|
||||
off_t offset,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return _read_buf(((FileInfo*)ffi->fh)->fd,
|
||||
return _read_buf(ffi->fh,
|
||||
bufp,
|
||||
size,
|
||||
offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+12
-11
@@ -22,6 +22,8 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define _BSD_SOURCE
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <string>
|
||||
@@ -35,6 +37,7 @@
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -47,33 +50,30 @@ using mergerfs::readdir::FileData;
|
||||
static
|
||||
int
|
||||
_readdir(const vector<string> &srcmounts,
|
||||
const string dirname,
|
||||
const string &dirname,
|
||||
void *buf,
|
||||
const fuse_fill_dir_t filler)
|
||||
{
|
||||
set<string> found;
|
||||
struct stat st = {0};
|
||||
|
||||
for(vector<string>::const_iterator
|
||||
iter = srcmounts.begin(), enditer = srcmounts.end();
|
||||
iter != enditer;
|
||||
++iter)
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
DIR *dh;
|
||||
string basepath;
|
||||
|
||||
basepath = fs::make_path(*iter,dirname);
|
||||
basepath = fs::path::make(srcmounts[i],dirname);
|
||||
dh = ::opendir(basepath.c_str());
|
||||
if(!dh)
|
||||
continue;
|
||||
|
||||
for(struct dirent *de = ::readdir(dh); de != NULL; de = ::readdir(dh))
|
||||
{
|
||||
string d_name(de->d_name);
|
||||
|
||||
if(found.insert(d_name).second == false)
|
||||
if(found.insert(de->d_name).second == false)
|
||||
continue;
|
||||
|
||||
if(filler(buf,de->d_name,NULL,NO_OFFSET) != 0)
|
||||
st.st_mode = DTTOIF(de->d_type);
|
||||
if(filler(buf,de->d_name,&st,NO_OFFSET) != 0)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
readdir(const vector<string> &srcmounts,
|
||||
const string dirname,
|
||||
const string &dirname,
|
||||
vector<FileData> &stats)
|
||||
{
|
||||
return _readdir(srcmounts,
|
||||
@@ -125,6 +125,7 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _readdir(config.srcmounts,
|
||||
fusepath,
|
||||
|
||||
+3
-3
@@ -40,8 +40,8 @@ namespace mergerfs
|
||||
{
|
||||
struct FileData
|
||||
{
|
||||
FileData(std::string filename_,
|
||||
struct stat stats_)
|
||||
FileData(const std::string &filename_,
|
||||
const struct stat &stats_)
|
||||
: filename(filename_),
|
||||
stats(stats_)
|
||||
{}
|
||||
@@ -59,7 +59,7 @@ namespace mergerfs
|
||||
|
||||
int
|
||||
readdir(const std::vector<std::string> &srcmounts,
|
||||
const std::string dirname,
|
||||
const std::string &dirname,
|
||||
std::vector<FileData> &stats);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-12
@@ -33,7 +33,7 @@
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -41,20 +41,23 @@ using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_readlink(const fs::SearchFunc searchFunc,
|
||||
const vector<string>& srcmounts,
|
||||
const string fusepath,
|
||||
char *buf,
|
||||
const size_t size)
|
||||
_readlink(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
char *buf,
|
||||
const size_t size)
|
||||
{
|
||||
int rv;
|
||||
fs::PathVector paths;
|
||||
vector<string> path;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = ::readlink(paths[0].full.c_str(),buf,size);
|
||||
fs::path::append(path[0],fusepath);
|
||||
|
||||
rv = ::readlink(path[0].c_str(),buf,size);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -75,9 +78,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _readlink(*config.search,
|
||||
return _readlink(config.readlink,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
buf,
|
||||
size);
|
||||
|
||||
+3
-11
@@ -29,19 +29,11 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
using mergerfs::FileInfo;
|
||||
|
||||
static
|
||||
int
|
||||
_release(uint64_t &fh)
|
||||
{
|
||||
const FileInfo *fileinfo = (FileInfo*)fh;
|
||||
|
||||
::close(fileinfo->fd);
|
||||
|
||||
delete fileinfo;
|
||||
::close(fh);
|
||||
|
||||
fh = 0;
|
||||
|
||||
@@ -54,9 +46,9 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
release(const char *fusepath,
|
||||
struct fuse_file_info *fi)
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return _release(fi->fh);
|
||||
return _release(ffi->fh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace releasedir
|
||||
{
|
||||
int
|
||||
releasedir(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace releasedir
|
||||
{
|
||||
int
|
||||
releasedir(const char *fusepath,
|
||||
struct fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
+22
-17
@@ -33,39 +33,41 @@
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_removexattr(const fs::SearchFunc searchFunc,
|
||||
_removexattr(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const char *attrname)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::lremovexattr(i->full.c_str(),attrname);
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::lremovexattr(paths[i].c_str(),attrname);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
@@ -79,15 +81,18 @@ namespace mergerfs
|
||||
removexattr(const char *fusepath,
|
||||
const char *attrname)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const config::Config &config = config::get();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -ENOTSUP;
|
||||
|
||||
return _removexattr(*config.action,
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _removexattr(config.removexattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname);
|
||||
}
|
||||
|
||||
+66
-20
@@ -34,32 +34,75 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_rename(const fs::SearchFunc searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string from,
|
||||
const string to)
|
||||
_single_rename(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const string &oldfullpath,
|
||||
const string &newpath)
|
||||
{
|
||||
int rv;
|
||||
string pathto;
|
||||
fs::PathVector pathfrom;
|
||||
const string newfullpath = fs::path::make(oldbasepath,newpath);
|
||||
|
||||
searchFunc(srcmounts,from,pathfrom);
|
||||
if(pathfrom.empty())
|
||||
return -ENOENT;
|
||||
|
||||
pathto = fs::make_path(pathfrom[0].base,to);
|
||||
|
||||
rv = ::rename(pathfrom[0].full.c_str(),pathto.c_str());
|
||||
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str());
|
||||
if(rv == -1 && errno == ENOENT)
|
||||
return -EXDEV;
|
||||
{
|
||||
string dirname;
|
||||
vector<string> newpathdir;
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
dirname = fs::path::dirname(newpath);
|
||||
rv = searchFunc(srcmounts,dirname,minfreespace,newpathdir);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
{
|
||||
const mergerfs::ugid::SetResetGuard ugid(0,0);
|
||||
fs::clonepath(newpathdir[0],oldbasepath,dirname);
|
||||
}
|
||||
|
||||
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str());
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_rename(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &oldfusepath,
|
||||
const string &newfusepath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
vector<string> oldbasepaths;
|
||||
|
||||
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = oldbasepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string oldfullpath = fs::path::make(oldbasepaths[i],oldfusepath);
|
||||
|
||||
rv = _single_rename(searchFunc,srcmounts,minfreespace,
|
||||
oldbasepaths[i],oldfullpath,newfusepath);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -67,17 +110,20 @@ namespace mergerfs
|
||||
namespace rename
|
||||
{
|
||||
int
|
||||
rename(const char *from,
|
||||
const char *to)
|
||||
rename(const char *oldpath,
|
||||
const char *newpath)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _rename(*config.search,
|
||||
return _rename(config.getattr,
|
||||
config.rename,
|
||||
config.srcmounts,
|
||||
from,
|
||||
to);
|
||||
config.minfreespace,
|
||||
oldpath,
|
||||
newpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-14
@@ -40,27 +40,31 @@ namespace mergerfs
|
||||
}
|
||||
|
||||
int
|
||||
maxout_rlimit(int resource)
|
||||
maxout_rlimit(const int resource)
|
||||
{
|
||||
int rv;
|
||||
struct rlimit rlim;
|
||||
|
||||
if(geteuid() == 0)
|
||||
{
|
||||
rlim.rlim_cur = RLIM_INFINITY;
|
||||
rlim.rlim_max = RLIM_INFINITY;
|
||||
}
|
||||
else
|
||||
{
|
||||
int rv;
|
||||
rlim.rlim_cur = RLIM_INFINITY;
|
||||
rlim.rlim_max = RLIM_INFINITY;
|
||||
rv = ::setrlimit(resource,&rlim);
|
||||
if(rv == 0)
|
||||
return 0;
|
||||
|
||||
rv = ::getrlimit(resource,&rlim);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
rv = ::getrlimit(resource,&rlim);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rlim.rlim_cur = rlim.rlim_max;
|
||||
rv = 0;
|
||||
rlim.rlim_cur = rlim.rlim_max;
|
||||
while(rv == 0)
|
||||
{
|
||||
rv = ::setrlimit(resource,&rlim);
|
||||
rlim.rlim_max *= 2;
|
||||
rlim.rlim_cur = rlim.rlim_max;
|
||||
}
|
||||
|
||||
return ::setrlimit(resource,&rlim);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -74,5 +78,13 @@ namespace mergerfs
|
||||
{
|
||||
return maxout_rlimit(RLIMIT_FSIZE);
|
||||
}
|
||||
|
||||
int
|
||||
setpriority(const int prio)
|
||||
{
|
||||
const int SELF = 0;
|
||||
|
||||
return ::setpriority(PRIO_PROCESS,SELF,prio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -27,8 +27,9 @@ namespace mergerfs
|
||||
namespace resources
|
||||
{
|
||||
int reset_umask(void);
|
||||
int maxout_rlimit(int resource);
|
||||
int maxout_rlimit(const int resource);
|
||||
int maxout_rlimit_nofile(void);
|
||||
int maxout_rlimit_fsize(void);
|
||||
int setpriority(const int prio);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-13
@@ -32,6 +32,7 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -39,29 +40,30 @@ using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_rmdir(const fs::SearchFunc searchFunc,
|
||||
_rmdir(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath)
|
||||
const size_t minfreespace,
|
||||
const string &fusepath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::rmdir(i->full.c_str());
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::rmdir(paths[i].c_str());
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -74,9 +76,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readguard(&config.srcmountslock);
|
||||
|
||||
return _rmdir(*config.action,
|
||||
return _rmdir(config.rmdir,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace rwlock
|
||||
{
|
||||
class ReadGuard
|
||||
{
|
||||
public:
|
||||
ReadGuard(pthread_rwlock_t *lock)
|
||||
{
|
||||
_lock = lock;
|
||||
pthread_rwlock_rdlock(_lock);
|
||||
}
|
||||
|
||||
~ReadGuard()
|
||||
{
|
||||
pthread_rwlock_unlock(_lock);
|
||||
}
|
||||
|
||||
private:
|
||||
ReadGuard();
|
||||
|
||||
private:
|
||||
pthread_rwlock_t *_lock;
|
||||
};
|
||||
|
||||
class WriteGuard
|
||||
{
|
||||
public:
|
||||
WriteGuard(pthread_rwlock_t *lock)
|
||||
{
|
||||
_lock = lock;
|
||||
pthread_rwlock_wrlock(_lock);
|
||||
}
|
||||
|
||||
~WriteGuard()
|
||||
{
|
||||
pthread_rwlock_unlock(_lock);
|
||||
}
|
||||
|
||||
private:
|
||||
WriteGuard();
|
||||
|
||||
private:
|
||||
pthread_rwlock_t *_lock;
|
||||
};
|
||||
}
|
||||
}
|
||||
+246
-72
@@ -30,78 +30,243 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "xattr.hpp"
|
||||
#include "str.hpp"
|
||||
#include "num.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
using mergerfs::FuseFunc;
|
||||
using namespace mergerfs;
|
||||
|
||||
template<typename Container>
|
||||
Container&
|
||||
split(Container &result,
|
||||
const typename Container::value_type &s,
|
||||
typename Container::value_type::value_type delimiter)
|
||||
{
|
||||
std::string str;
|
||||
std::istringstream ss(s);
|
||||
|
||||
while(std::getline(ss,str,delimiter))
|
||||
result.push_back(str);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile(config::Config &config,
|
||||
const string attrname,
|
||||
const string attrval,
|
||||
const size_t attrvalsize,
|
||||
const int flags)
|
||||
_add_srcmounts(vector<string> &srcmounts,
|
||||
pthread_rwlock_t &srcmountslock,
|
||||
const string &destmount,
|
||||
const string &values,
|
||||
vector<string>::iterator pos)
|
||||
{
|
||||
const Category *cat;
|
||||
const Policy *policy;
|
||||
vector<string> nameparts;
|
||||
vector<string> patterns;
|
||||
vector<string> additions;
|
||||
|
||||
split(nameparts,attrname,'.');
|
||||
str::split(patterns,values,':');
|
||||
fs::glob(patterns,additions);
|
||||
|
||||
if(nameparts.size() != 3)
|
||||
return -EINVAL;
|
||||
|
||||
if(nameparts[0] != "user")
|
||||
return -ENOATTR;
|
||||
|
||||
if(nameparts[1] != "mergerfs")
|
||||
return -ENOATTR;
|
||||
if(!additions.empty())
|
||||
{
|
||||
const rwlock::WriteGuard wrg(&srcmountslock);
|
||||
|
||||
cat = Category::find(nameparts[2]);
|
||||
if(cat == Category::invalid)
|
||||
return -ENOATTR;
|
||||
|
||||
if((flags & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
policy = Policy::find(attrval);
|
||||
if(policy == Policy::invalid)
|
||||
return -EINVAL;
|
||||
|
||||
config.policies[*cat] = policy;
|
||||
srcmounts.insert(pos,
|
||||
additions.begin(),
|
||||
additions.end());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr(const fs::SearchFunc searchFunc,
|
||||
_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);
|
||||
|
||||
{
|
||||
const rwlock::WriteGuard wrg(&srcmountslock);
|
||||
|
||||
srcmounts.swap(newmounts);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_split_attrval(const string &attrval,
|
||||
string &instruction,
|
||||
string &values)
|
||||
{
|
||||
size_t offset;
|
||||
|
||||
offset = attrval.find_first_of('/');
|
||||
instruction = attrval.substr(0,offset);
|
||||
if(offset != string::npos)
|
||||
values = attrval.substr(offset);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_srcmounts(vector<string> &srcmounts,
|
||||
pthread_rwlock_t &srcmountslock,
|
||||
const string &destmount,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
string instruction;
|
||||
string values;
|
||||
|
||||
if((flags & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
_split_attrval(attrval,instruction,values);
|
||||
|
||||
if(instruction == "+")
|
||||
return _add_srcmounts(srcmounts,srcmountslock,destmount,values,srcmounts.end());
|
||||
else if(instruction == "+<")
|
||||
return _add_srcmounts(srcmounts,srcmountslock,destmount,values,srcmounts.begin());
|
||||
else if(instruction == "+>")
|
||||
return _add_srcmounts(srcmounts,srcmountslock,destmount,values,srcmounts.end());
|
||||
else if(instruction == "-")
|
||||
return _erase_srcmounts(srcmounts,srcmountslock,values);
|
||||
else if(instruction == "-<")
|
||||
return _erase_srcmounts(srcmounts,srcmountslock,srcmounts.front());
|
||||
else if(instruction == "->")
|
||||
return _erase_srcmounts(srcmounts,srcmountslock,srcmounts.back());
|
||||
else if(instruction == "=")
|
||||
return _replace_srcmounts(srcmounts,srcmountslock,destmount,values);
|
||||
else if(instruction.empty())
|
||||
return _replace_srcmounts(srcmounts,srcmountslock,destmount,values);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_minfreespace(config::Config &config,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if((flags & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
rv = num::to_size_t(attrval,config.minfreespace);
|
||||
if(rv == -1)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile_func_policy(config::Config &config,
|
||||
const char *funcname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if((flags & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
rv = config.set_func_policy(funcname,attrval);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile_category_policy(config::Config &config,
|
||||
const char *categoryname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if((flags & XATTR_CREATE) == XATTR_CREATE)
|
||||
return -EEXIST;
|
||||
|
||||
rv = config.set_category_policy(categoryname,attrval);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile(config::Config &config,
|
||||
const char *attrname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
const char *attrbasename = &attrname[sizeof("user.mergerfs.")-1];
|
||||
|
||||
if(strncmp("user.mergerfs.",attrname,sizeof("user.mergerfs.")-1))
|
||||
return -ENOATTR;
|
||||
|
||||
if(attrval.empty())
|
||||
return -EINVAL;
|
||||
|
||||
if(!strcmp("srcmounts",attrbasename))
|
||||
return _setxattr_srcmounts(config.srcmounts,
|
||||
config.srcmountslock,
|
||||
config.destmount,
|
||||
attrval,
|
||||
flags);
|
||||
else if(!strcmp("minfreespace",attrbasename))
|
||||
return _setxattr_minfreespace(config,
|
||||
attrval,
|
||||
flags);
|
||||
else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
|
||||
return _setxattr_controlfile_category_policy(config,
|
||||
&attrbasename[sizeof("category.")-1],
|
||||
attrval,
|
||||
flags);
|
||||
else if(!strncmp("func.",attrbasename,sizeof("func.")-1))
|
||||
return _setxattr_controlfile_func_policy(config,
|
||||
&attrbasename[sizeof("func.")-1],
|
||||
attrval,
|
||||
flags);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_setxattr(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const char *attrname,
|
||||
const char *attrval,
|
||||
const size_t attrvalsize,
|
||||
@@ -110,23 +275,23 @@ _setxattr(const fs::SearchFunc searchFunc,
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::lsetxattr(i->full.c_str(),attrname,attrval,attrvalsize,flags);
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::lsetxattr(paths[i].c_str(),attrname,attrval,attrvalsize,flags);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
@@ -142,24 +307,33 @@ namespace mergerfs
|
||||
size_t attrvalsize,
|
||||
int flags)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _setxattr_controlfile(config::get_writable(),
|
||||
attrname,
|
||||
string(attrval,attrvalsize),
|
||||
attrvalsize,
|
||||
flags);
|
||||
{
|
||||
if((fc->uid != ::getuid()) && (fc->gid != ::getgid()))
|
||||
return -EPERM;
|
||||
|
||||
return _setxattr(*config.action,
|
||||
config.srcmounts,
|
||||
fusepath,
|
||||
attrname,
|
||||
attrval,
|
||||
attrvalsize,
|
||||
flags);
|
||||
return _setxattr_controlfile(config::get_writable(),
|
||||
attrname,
|
||||
string(attrval,attrvalsize),
|
||||
flags);
|
||||
}
|
||||
|
||||
{
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _setxattr(config.setxattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname,
|
||||
attrval,
|
||||
attrvalsize,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "ugid.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -81,11 +82,11 @@ _statfs(const vector<string> &srcmounts,
|
||||
vector<string>::const_iterator iter;
|
||||
vector<string>::const_iterator enditer;
|
||||
|
||||
for(iter = srcmounts.begin(), enditer = srcmounts.end(); iter != enditer; ++iter)
|
||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstat;
|
||||
rv = ::statvfs(iter->c_str(),&fsstat);
|
||||
rv = ::statvfs(srcmounts[i].c_str(),&fsstat);
|
||||
if(rv != 0)
|
||||
continue;
|
||||
|
||||
@@ -126,6 +127,7 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _statfs(config.srcmounts,
|
||||
*stat);
|
||||
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include <fnmatch.h>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::istringstream;
|
||||
|
||||
namespace str
|
||||
{
|
||||
void
|
||||
split(vector<string> &result,
|
||||
const string &str,
|
||||
const char delimiter)
|
||||
{
|
||||
string part;
|
||||
istringstream ss(str);
|
||||
|
||||
while(std::getline(ss,part,delimiter))
|
||||
result.push_back(part);
|
||||
}
|
||||
|
||||
string
|
||||
join(const vector<string> &vec,
|
||||
const size_t substridx,
|
||||
const char sep)
|
||||
{
|
||||
if(vec.empty())
|
||||
return string();
|
||||
|
||||
string rv = vec[0].substr(substridx);
|
||||
for(size_t i = 1; i < vec.size(); i++)
|
||||
rv += sep + vec[i].substr(substridx);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
string
|
||||
join(const vector<string> &vec,
|
||||
const char sep)
|
||||
{
|
||||
return str::join(vec,0,sep);
|
||||
}
|
||||
|
||||
size_t
|
||||
longest_common_prefix_index(const vector<string> &vec)
|
||||
{
|
||||
if(vec.empty())
|
||||
return string::npos;
|
||||
|
||||
for(size_t n = 0; n < vec[0].size(); n++)
|
||||
{
|
||||
char chr = vec[0][n];
|
||||
for(size_t i = 1; i < vec.size(); i++)
|
||||
{
|
||||
if(n >= vec[i].size())
|
||||
return n;
|
||||
if(vec[i][n] != chr)
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
string
|
||||
longest_common_prefix(const vector<string> &vec)
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
idx = longest_common_prefix_index(vec);
|
||||
if(idx != string::npos)
|
||||
return vec[0].substr(0,idx);
|
||||
|
||||
return string();
|
||||
}
|
||||
|
||||
string
|
||||
remove_common_prefix_and_join(const vector<string> &vec,
|
||||
const char sep)
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
idx = str::longest_common_prefix_index(vec);
|
||||
if(idx == string::npos)
|
||||
idx = 0;
|
||||
|
||||
return str::join(vec,idx,sep);
|
||||
}
|
||||
|
||||
void
|
||||
erase_fnmatches(const vector<string> &patterns,
|
||||
vector<string> &strs)
|
||||
{
|
||||
vector<string>::iterator si;
|
||||
vector<string>::const_iterator pi;
|
||||
|
||||
si = strs.begin();
|
||||
while(si != strs.end())
|
||||
{
|
||||
int match = FNM_NOMATCH;
|
||||
|
||||
for(pi = patterns.begin();
|
||||
pi != patterns.end() && match != 0;
|
||||
++pi)
|
||||
{
|
||||
match = fnmatch(pi->c_str(),si->c_str(),0);
|
||||
}
|
||||
|
||||
if(match == 0)
|
||||
si = strs.erase(si);
|
||||
else
|
||||
++si;
|
||||
}
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace str
|
||||
{
|
||||
void
|
||||
split(std::vector<std::string> &result,
|
||||
const std::string &str,
|
||||
const char delimiter);
|
||||
|
||||
std::string
|
||||
join(const std::vector<std::string> &vec,
|
||||
const size_t substridx,
|
||||
const char sep);
|
||||
|
||||
std::string
|
||||
join(const std::vector<std::string> &vec,
|
||||
const char sep);
|
||||
|
||||
size_t
|
||||
longest_common_prefix_index(const std::vector<std::string> &vec);
|
||||
|
||||
std::string
|
||||
longest_common_prefix(const std::vector<std::string> &vec);
|
||||
|
||||
std::string
|
||||
remove_common_prefix_and_join(const std::vector<std::string> &vec,
|
||||
const char sep);
|
||||
|
||||
void
|
||||
erase_fnmatches(const std::vector<std::string> &pattern,
|
||||
std::vector<std::string> &strs);
|
||||
}
|
||||
+27
-11
@@ -32,28 +32,41 @@
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_symlink(const vector<string> &srcmounts,
|
||||
const string from,
|
||||
const string to)
|
||||
_symlink(Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &oldpath,
|
||||
const string &newpath)
|
||||
{
|
||||
int rv;
|
||||
fs::PathVector paths;
|
||||
int error;
|
||||
string newpathdir;
|
||||
vector<string> newpathdirs;
|
||||
|
||||
fs::find::ff(srcmounts,fs::dirname(to),paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
newpathdir = fs::path::dirname(newpath);
|
||||
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
paths[0].full = fs::make_path(paths[0].base,to);
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = newpathdirs.size(); i != ei; i++)
|
||||
{
|
||||
fs::path::append(newpathdirs[i],newpath);
|
||||
|
||||
rv = symlink(from.c_str(),paths[0].full.c_str());
|
||||
rv = symlink(oldpath.c_str(),newpathdirs[i].c_str());
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -67,8 +80,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _symlink(config.srcmounts,
|
||||
return _symlink(config.symlink,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
oldpath,
|
||||
newpath);
|
||||
}
|
||||
|
||||
+18
-13
@@ -34,36 +34,39 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_truncate(const fs::SearchFunc searchFunc,
|
||||
_truncate(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const off_t size)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::truncate(i->full.c_str(),size);
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::truncate(paths[i].c_str(),size);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -77,9 +80,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _truncate(*config.action,
|
||||
return _truncate(config.truncate,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
size);
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@
|
||||
|
||||
#include "ugid.hpp"
|
||||
|
||||
#if defined LINUX
|
||||
#elif defined OSX
|
||||
#if defined __linux__
|
||||
#elif defined __APPLE__
|
||||
#else
|
||||
pthread_mutex_t mergerfs::ugid::SetResetGuard::lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -25,9 +25,9 @@
|
||||
#ifndef __UGID_HPP__
|
||||
#define __UGID_HPP__
|
||||
|
||||
#if defined LINUX
|
||||
#if defined __linux__
|
||||
#include "ugid_linux.hpp"
|
||||
#elif defined OSX
|
||||
#elif defined __APPLE__
|
||||
#include "ugid_osx.hpp"
|
||||
#else
|
||||
#include "ugid_mutex.hpp"
|
||||
|
||||
+18
-13
@@ -33,35 +33,38 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_unlink(const fs::SearchFunc searchFunc,
|
||||
_unlink(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath)
|
||||
const size_t minfreespace,
|
||||
const string &fusepath)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::unlink(i->full.c_str());
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::unlink(paths[i].c_str());
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -74,9 +77,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _unlink(*config.action,
|
||||
return _unlink(config.unlink,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-15
@@ -34,36 +34,39 @@
|
||||
#include "ugid.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_utimens(const fs::SearchFunc searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const struct timespec ts[2])
|
||||
_utimens(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const struct timespec ts[2])
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::PathVector paths;
|
||||
vector<string> paths;
|
||||
|
||||
searchFunc(srcmounts,fusepath,paths);
|
||||
if(paths.empty())
|
||||
return -ENOENT;
|
||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
rv = -1;
|
||||
error = 0;
|
||||
for(fs::PathVector::const_iterator
|
||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||
error = 0;
|
||||
for(size_t i = 0, ei = paths.size(); i != ei; i++)
|
||||
{
|
||||
rv &= ::utimensat(0,i->full.c_str(),ts,AT_SYMLINK_NOFOLLOW);
|
||||
fs::path::append(paths[i],fusepath);
|
||||
|
||||
rv = ::utimensat(0,paths[i].c_str(),ts,AT_SYMLINK_NOFOLLOW);
|
||||
if(rv == -1)
|
||||
error = errno;
|
||||
}
|
||||
|
||||
return ((rv == -1) ? -error : 0);
|
||||
return -error;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@@ -77,9 +80,11 @@ namespace mergerfs
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _utimens(*config.action,
|
||||
return _utimens(config.utimens,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
ts);
|
||||
}
|
||||
|
||||
+2
-4
@@ -27,8 +27,6 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_write(const int fd,
|
||||
@@ -52,9 +50,9 @@ namespace mergerfs
|
||||
const char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return _write(((FileInfo*)fi->fh)->fd,
|
||||
return _write(ffi->fh,
|
||||
buf,
|
||||
count,
|
||||
offset);
|
||||
|
||||
+5
-2
@@ -22,11 +22,12 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#if WRITE_BUF
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
#include "write.hpp"
|
||||
|
||||
static
|
||||
@@ -57,9 +58,11 @@ namespace mergerfs
|
||||
off_t offset,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return _write_buf(((FileInfo*)ffi->fh)->fd,
|
||||
return _write_buf(ffi->fh,
|
||||
*src,
|
||||
offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
FUSE_CFLAGS=$(pkg-config --cflags fuse)
|
||||
|
||||
echo "#include <fuse.h>" | cpp ${FUSE_CFLAGS} | grep -q "${1}"
|
||||
|
||||
[ "$?" != "0" ]; echo $?
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# The MIT License (MIT)
|
||||
|
||||
# Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
packagename = sys.argv[1]
|
||||
version = sys.argv[2]
|
||||
|
||||
args = ["git", "tag", '-l']
|
||||
tags = subprocess.check_output(args)
|
||||
tags = tags.split()
|
||||
tags.reverse()
|
||||
|
||||
if version in tags:
|
||||
idx = tags.index(version)
|
||||
tags = tags[idx:]
|
||||
tags = zip(tags,tags)
|
||||
else:
|
||||
tags = zip(tags,tags)
|
||||
tags.insert(0,(version,'HEAD'))
|
||||
|
||||
tag = tags[0]
|
||||
for prev in tags[1:]:
|
||||
print packagename, "("+tag[0]+")", "trusty;", "urgency=medium"
|
||||
print
|
||||
|
||||
args = ['git','log','--no-merges','--oneline',tag[1]+'...'+prev[1]]
|
||||
for line in subprocess.check_output(args).strip().split('\n'):
|
||||
print " * " + line
|
||||
print
|
||||
|
||||
args = ['git','log','-1','--format=-- %an <%ae> %cD',tag[1]]
|
||||
authorandtime = subprocess.check_output(args).strip()
|
||||
print ' ' + authorandtime + '\n'
|
||||
|
||||
tag = prev
|
||||
Reference in New Issue
Block a user