mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-20 00:17:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be5909a906 | ||
|
|
7f410073d4 | ||
|
|
92ae63e842 | ||
|
|
d31e97e64c | ||
|
|
579690f411 | ||
|
|
ca449a73be | ||
|
|
2d86ed946a | ||
|
|
3e454f528c | ||
|
|
a4fdbae1ca | ||
|
|
aff66812c0 | ||
|
|
6472ac51e9 | ||
|
|
d3770802b1 | ||
|
|
bcbff5c82e | ||
|
|
09743ee187 | ||
|
|
3a33a6db2b | ||
|
|
c0d5f4795a | ||
|
|
ef9074ab4a | ||
|
|
2d03b89c2d | ||
|
|
64cc63b2bc | ||
|
|
514c478a39 | ||
|
|
8179f91c48 | ||
|
|
371764d800 | ||
|
|
1c44ef7967 | ||
|
|
aa97bac533 | ||
|
|
12d6302457 | ||
|
|
740fc3f84a | ||
|
|
f18719ced2 | ||
|
|
366f5fcc4c | ||
|
|
1729835b8c | ||
|
|
1180fd6dd3 | ||
|
|
19509e33d2 | ||
|
|
8f355d7dd5 | ||
|
|
2aa9697c87 | ||
|
|
978d067921 | ||
|
|
b83bd5fd14 | ||
|
|
dd906c8a4c | ||
|
|
6fb9111c03 | ||
|
|
bc382e0fd2 | ||
|
|
0197984db3 | ||
|
|
248b1aca1c | ||
|
|
9056898bbf | ||
|
|
5e584f246a | ||
|
|
7e964283b9 | ||
|
|
03dc17fff2 | ||
|
|
8cb68dce4a | ||
|
|
28260c434a | ||
|
|
fae9b993fe | ||
|
|
171eb9c7c0 | ||
|
|
174e703d2e | ||
|
|
efd0dfaa2f | ||
|
|
75d7a93724 | ||
|
|
50fa7ac694 | ||
|
|
7d64a47b88 | ||
|
|
5fba42f076 | ||
|
|
b0bb7ef38c | ||
|
|
85ce7d6178 | ||
|
|
40359df453 | ||
|
|
9b2a5a75ee | ||
|
|
b21172c609 | ||
|
|
f0444a1ca9 | ||
|
|
977d04229f | ||
|
|
757ae66327 | ||
|
|
42d0b5734c | ||
|
|
78050ed6b0 | ||
|
|
19ee44afe7 | ||
|
|
a234e9446c | ||
|
|
951eb9540d | ||
|
|
85a936c95e | ||
|
|
8210e63a66 | ||
|
|
facdb66746 | ||
|
|
1916e54a24 | ||
|
|
7fabe515f4 | ||
|
|
0ca5d6aad0 | ||
|
|
0c1aeb411d | ||
|
|
17fdbf7f42 | ||
|
|
27349e41ef | ||
|
|
b3ce95c422 | ||
|
|
cedc9f0f25 | ||
|
|
d68ad9ac01 |
+19
-396
@@ -1,128 +1,3 @@
|
||||
freebsd_task:
|
||||
name: "freebsd:11.4"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-11-4
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
freebsd_task:
|
||||
name: "freebsd:12.1"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-12-1
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
freebsd_task:
|
||||
name: "freebsd:12.2"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-12-2
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
freebsd_task:
|
||||
name: "freebsd:13.0"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-13-0
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
|
||||
#macos_task:
|
||||
# osx_instance:
|
||||
# image: catalina-base
|
||||
# script:
|
||||
# - buildtools/install-build-pkgs
|
||||
# - gmake -j4
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.11"
|
||||
container:
|
||||
image: alpine:3.11
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.12"
|
||||
container:
|
||||
image: alpine:3.12
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.13"
|
||||
container:
|
||||
image: alpine:3.13
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.14"
|
||||
container:
|
||||
image: alpine:3.14
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.15"
|
||||
container:
|
||||
image: alpine:3.15
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.16"
|
||||
container:
|
||||
image: alpine:3.16
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.17"
|
||||
container:
|
||||
image: alpine:3.17
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:latest"
|
||||
container:
|
||||
@@ -146,9 +21,9 @@ linux_task:
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "centos:7"
|
||||
name: "fedora:41"
|
||||
container:
|
||||
image: centos:7
|
||||
image: fedora:41
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
@@ -158,141 +33,9 @@ linux_task:
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "rocky:8"
|
||||
container:
|
||||
image: rocky:8
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:30"
|
||||
container:
|
||||
image: fedora:30
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:31"
|
||||
container:
|
||||
image: fedora:31
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:32"
|
||||
container:
|
||||
image: fedora:32
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:33"
|
||||
container:
|
||||
image: fedora:33
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:34"
|
||||
container:
|
||||
image: fedora:34
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:35"
|
||||
container:
|
||||
image: fedora:35
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:36"
|
||||
container:
|
||||
image: fedora:36
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:37"
|
||||
container:
|
||||
image: fedora:37
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:38"
|
||||
container:
|
||||
image: fedora:38
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:latest"
|
||||
container:
|
||||
image: fedora:latest
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora-arm:latest"
|
||||
name: "fedora-arm:41"
|
||||
arm_container:
|
||||
image: fedora:latest
|
||||
image: fedora:41
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
@@ -301,66 +44,6 @@ linux_task:
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:14.04"
|
||||
container:
|
||||
image: ubuntu:14.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:16.04"
|
||||
container:
|
||||
image: ubuntu:16.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:18.04"
|
||||
container:
|
||||
image: ubuntu:18.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:20.04"
|
||||
container:
|
||||
image: ubuntu:20.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:22.04"
|
||||
container:
|
||||
@@ -376,6 +59,21 @@ linux_task:
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:24.04"
|
||||
container:
|
||||
image: ubuntu:24.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:latest"
|
||||
container:
|
||||
@@ -406,81 +104,6 @@ linux_task:
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:7"
|
||||
container:
|
||||
image: debian:8
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:8"
|
||||
container:
|
||||
image: debian:8
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:9"
|
||||
container:
|
||||
image: debian:9
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:10"
|
||||
container:
|
||||
image: debian:10
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:11"
|
||||
container:
|
||||
image: debian:11
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:12"
|
||||
container:
|
||||
|
||||
+1
-6
@@ -1,7 +1,2 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [trapexit]
|
||||
patreon: trapexit
|
||||
custom: ['https://paypal.me/trapexit','https://buymeacoff.ee/trapexit']
|
||||
ko_fi: trapexit
|
||||
open_collective: trapexit
|
||||
custom: ['https://github.com/trapexit/support']
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
name: "mkdocs"
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Configure Git Credentials
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: pip install --no-cache-dir mkdocs mkdocs-material pymdown-extensions
|
||||
working-directory: ./mkdocs
|
||||
- run: mkdocs gh-deploy --force
|
||||
working-directory: ./mkdocs
|
||||
@@ -23,3 +23,7 @@ debian/changelog
|
||||
|
||||
# RPM files
|
||||
rpmbuild/
|
||||
|
||||
# mkdocs files
|
||||
mkdocs/venv
|
||||
__pycache__/
|
||||
|
||||
@@ -210,15 +210,6 @@ uninstall-mount.mergerfs:
|
||||
uninstall-man:
|
||||
$(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
|
||||
|
||||
$(MANPAGE): README.md
|
||||
ifneq ($(shell $(PANDOC) --version 2> /dev/null),)
|
||||
$(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
|
||||
else
|
||||
$(warning "pandoc does not appear available: unable to build manpage")
|
||||
endif
|
||||
|
||||
man: $(MANPAGE)
|
||||
|
||||
.PHONY: tarball
|
||||
tarball: man changelog version
|
||||
$(eval VERSION := $(shell cat VERSION))
|
||||
|
||||
@@ -71,6 +71,8 @@ CFLAGS := \
|
||||
-Wall \
|
||||
-pipe \
|
||||
-MMD
|
||||
CXXFLAGS ?= \
|
||||
$(OPT_FLAGS)
|
||||
CXXFLAGS := \
|
||||
${CXXFLAGS} \
|
||||
$(LTO_FLAGS) \
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#endif
|
||||
|
||||
#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
|
||||
#define FUSE_MAX_MAX_PAGES 256
|
||||
#define FUSE_DEFAULT_MAX_MAX_PAGES 256
|
||||
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
@@ -108,23 +108,26 @@ struct fuse_file_info_t
|
||||
* FUSE_CAP_IOCTL_DIR: ioctl support on directories
|
||||
* FUSE_CAP_CACHE_SYMLINKS: cache READLINK responses
|
||||
*/
|
||||
#define FUSE_CAP_ASYNC_READ (1 << 0)
|
||||
#define FUSE_CAP_POSIX_LOCKS (1 << 1)
|
||||
#define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
|
||||
#define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
|
||||
#define FUSE_CAP_BIG_WRITES (1 << 5)
|
||||
#define FUSE_CAP_DONT_MASK (1 << 6)
|
||||
#define FUSE_CAP_FLOCK_LOCKS (1 << 10)
|
||||
#define FUSE_CAP_IOCTL_DIR (1 << 11)
|
||||
#define FUSE_CAP_READDIR_PLUS (1 << 13)
|
||||
#define FUSE_CAP_READDIR_PLUS_AUTO (1 << 14)
|
||||
#define FUSE_CAP_ASYNC_DIO (1 << 15)
|
||||
#define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
|
||||
#define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
|
||||
#define FUSE_CAP_POSIX_ACL (1 << 19)
|
||||
#define FUSE_CAP_CACHE_SYMLINKS (1 << 20)
|
||||
#define FUSE_CAP_MAX_PAGES (1 << 21)
|
||||
#define FUSE_CAP_SETXATTR_EXT (1 << 22)
|
||||
#define FUSE_CAP_ASYNC_READ (1ULL << 0)
|
||||
#define FUSE_CAP_POSIX_LOCKS (1ULL << 1)
|
||||
#define FUSE_CAP_ATOMIC_O_TRUNC (1ULL << 3)
|
||||
#define FUSE_CAP_EXPORT_SUPPORT (1ULL << 4)
|
||||
#define FUSE_CAP_BIG_WRITES (1ULL << 5)
|
||||
#define FUSE_CAP_DONT_MASK (1ULL << 6)
|
||||
#define FUSE_CAP_FLOCK_LOCKS (1ULL << 10)
|
||||
#define FUSE_CAP_IOCTL_DIR (1ULL << 11)
|
||||
#define FUSE_CAP_READDIR_PLUS (1ULL << 13)
|
||||
#define FUSE_CAP_READDIR_PLUS_AUTO (1ULL << 14)
|
||||
#define FUSE_CAP_ASYNC_DIO (1ULL << 15)
|
||||
#define FUSE_CAP_WRITEBACK_CACHE (1ULL << 16)
|
||||
#define FUSE_CAP_PARALLEL_DIROPS (1ULL << 18)
|
||||
#define FUSE_CAP_POSIX_ACL (1ULL << 19)
|
||||
#define FUSE_CAP_CACHE_SYMLINKS (1ULL << 20)
|
||||
#define FUSE_CAP_MAX_PAGES (1ULL << 21)
|
||||
#define FUSE_CAP_SETXATTR_EXT (1ULL << 22)
|
||||
#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP (1ULL << 23)
|
||||
#define FUSE_CAP_CREATE_SUPP_GROUP (1ULL << 24)
|
||||
|
||||
|
||||
/**
|
||||
* Ioctl flags
|
||||
@@ -150,56 +153,17 @@ struct fuse_file_info_t
|
||||
* indicate the value requested by the filesystem. The requested
|
||||
* value must usually be smaller than the indicated value.
|
||||
*/
|
||||
struct fuse_conn_info {
|
||||
/**
|
||||
* Major version of the protocol (read-only)
|
||||
*/
|
||||
struct fuse_conn_info
|
||||
{
|
||||
unsigned proto_major;
|
||||
|
||||
/**
|
||||
* Minor version of the protocol (read-only)
|
||||
*/
|
||||
unsigned proto_minor;
|
||||
|
||||
/**
|
||||
* Maximum size of the write buffer
|
||||
*/
|
||||
unsigned max_write;
|
||||
|
||||
/**
|
||||
* Maximum readahead
|
||||
*/
|
||||
unsigned max_readahead;
|
||||
|
||||
/**
|
||||
* Capability flags, that the kernel supports
|
||||
*/
|
||||
unsigned capable;
|
||||
|
||||
/**
|
||||
* Capability flags, that the filesystem wants to enable
|
||||
*/
|
||||
unsigned want;
|
||||
|
||||
/**
|
||||
* Maximum number of backgrounded requests
|
||||
*/
|
||||
uint64_t capable;
|
||||
uint64_t want;
|
||||
unsigned max_background;
|
||||
|
||||
/**
|
||||
* Kernel congestion threshold parameter
|
||||
*/
|
||||
unsigned congestion_threshold;
|
||||
|
||||
/**
|
||||
* Max pages
|
||||
*/
|
||||
uint16_t max_pages;
|
||||
|
||||
/**
|
||||
* For future use.
|
||||
*/
|
||||
unsigned reserved[22];
|
||||
};
|
||||
|
||||
struct fuse_session;
|
||||
|
||||
+119
-56
@@ -206,6 +206,11 @@
|
||||
* - add extension header
|
||||
* - add FUSE_EXT_GROUPS
|
||||
* - add FUSE_CREATE_SUPP_GROUP
|
||||
* - add FUSE_HAS_EXPIRE_ONLY
|
||||
*
|
||||
* 7.39
|
||||
* - add FUSE_DIRECT_IO_ALLOW_MMAP
|
||||
* - add FUSE_STATX and related structures
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_FUSE_H
|
||||
@@ -241,7 +246,7 @@
|
||||
#define FUSE_KERNEL_VERSION 7
|
||||
|
||||
/** Minor version number of this interface */
|
||||
#define FUSE_KERNEL_MINOR_VERSION 38
|
||||
#define FUSE_KERNEL_MINOR_VERSION 39
|
||||
|
||||
/** The node ID of the root inode */
|
||||
#define FUSE_ROOT_ID 1
|
||||
@@ -268,6 +273,40 @@ struct fuse_attr {
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
/*
|
||||
* The following structures are bit-for-bit compatible with the statx(2) ABI in
|
||||
* Linux.
|
||||
*/
|
||||
struct fuse_sx_time {
|
||||
int64_t tv_sec;
|
||||
uint32_t tv_nsec;
|
||||
int32_t __reserved;
|
||||
};
|
||||
|
||||
struct fuse_statx {
|
||||
uint32_t mask;
|
||||
uint32_t blksize;
|
||||
uint64_t attributes;
|
||||
uint32_t nlink;
|
||||
uint32_t uid;
|
||||
uint32_t gid;
|
||||
uint16_t mode;
|
||||
uint16_t __spare0[1];
|
||||
uint64_t ino;
|
||||
uint64_t size;
|
||||
uint64_t blocks;
|
||||
uint64_t attributes_mask;
|
||||
struct fuse_sx_time atime;
|
||||
struct fuse_sx_time btime;
|
||||
struct fuse_sx_time ctime;
|
||||
struct fuse_sx_time mtime;
|
||||
uint32_t rdev_major;
|
||||
uint32_t rdev_minor;
|
||||
uint32_t dev_major;
|
||||
uint32_t dev_minor;
|
||||
uint64_t __spare2[14];
|
||||
};
|
||||
|
||||
struct fuse_kstatfs {
|
||||
uint64_t blocks;
|
||||
uint64_t bfree;
|
||||
@@ -291,18 +330,18 @@ struct fuse_file_lock {
|
||||
/**
|
||||
* Bitmasks for fuse_setattr_in.valid
|
||||
*/
|
||||
#define FATTR_MODE (1 << 0)
|
||||
#define FATTR_UID (1 << 1)
|
||||
#define FATTR_GID (1 << 2)
|
||||
#define FATTR_SIZE (1 << 3)
|
||||
#define FATTR_ATIME (1 << 4)
|
||||
#define FATTR_MTIME (1 << 5)
|
||||
#define FATTR_FH (1 << 6)
|
||||
#define FATTR_ATIME_NOW (1 << 7)
|
||||
#define FATTR_MTIME_NOW (1 << 8)
|
||||
#define FATTR_LOCKOWNER (1 << 9)
|
||||
#define FATTR_CTIME (1 << 10)
|
||||
#define FATTR_KILL_SUIDGID (1 << 11)
|
||||
#define FATTR_MODE (1 << 0)
|
||||
#define FATTR_UID (1 << 1)
|
||||
#define FATTR_GID (1 << 2)
|
||||
#define FATTR_SIZE (1 << 3)
|
||||
#define FATTR_ATIME (1 << 4)
|
||||
#define FATTR_MTIME (1 << 5)
|
||||
#define FATTR_FH (1 << 6)
|
||||
#define FATTR_ATIME_NOW (1 << 7)
|
||||
#define FATTR_MTIME_NOW (1 << 8)
|
||||
#define FATTR_LOCKOWNER (1 << 9)
|
||||
#define FATTR_CTIME (1 << 10)
|
||||
#define FATTR_KILL_SUIDGID (1 << 11)
|
||||
|
||||
/**
|
||||
* Flags returned by the OPEN request
|
||||
@@ -315,13 +354,13 @@ struct fuse_file_lock {
|
||||
* FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE)
|
||||
* FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the same inode
|
||||
*/
|
||||
#define FOPEN_DIRECT_IO (1 << 0)
|
||||
#define FOPEN_KEEP_CACHE (1 << 1)
|
||||
#define FOPEN_NONSEEKABLE (1 << 2)
|
||||
#define FOPEN_CACHE_DIR (1 << 3)
|
||||
#define FOPEN_STREAM (1 << 4)
|
||||
#define FOPEN_NOFLUSH (1 << 5)
|
||||
#define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6)
|
||||
#define FOPEN_DIRECT_IO (1 << 0)
|
||||
#define FOPEN_KEEP_CACHE (1 << 1)
|
||||
#define FOPEN_NONSEEKABLE (1 << 2)
|
||||
#define FOPEN_CACHE_DIR (1 << 3)
|
||||
#define FOPEN_STREAM (1 << 4)
|
||||
#define FOPEN_NOFLUSH (1 << 5)
|
||||
#define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6)
|
||||
|
||||
/**
|
||||
* INIT request/reply flags
|
||||
@@ -369,43 +408,50 @@ struct fuse_file_lock {
|
||||
* FUSE_HAS_INODE_DAX: use per inode DAX
|
||||
* FUSE_CREATE_SUPP_GROUP: add supplementary group info to create, mkdir,
|
||||
* symlink and mknod (single group that matches parent)
|
||||
* FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
|
||||
* FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
|
||||
*/
|
||||
#define FUSE_ASYNC_READ (1 << 0)
|
||||
#define FUSE_POSIX_LOCKS (1 << 1)
|
||||
#define FUSE_FILE_OPS (1 << 2)
|
||||
#define FUSE_ATOMIC_O_TRUNC (1 << 3)
|
||||
#define FUSE_EXPORT_SUPPORT (1 << 4)
|
||||
#define FUSE_BIG_WRITES (1 << 5)
|
||||
#define FUSE_DONT_MASK (1 << 6)
|
||||
#define FUSE_SPLICE_WRITE (1 << 7)
|
||||
#define FUSE_SPLICE_MOVE (1 << 8)
|
||||
#define FUSE_SPLICE_READ (1 << 9)
|
||||
#define FUSE_FLOCK_LOCKS (1 << 10)
|
||||
#define FUSE_HAS_IOCTL_DIR (1 << 11)
|
||||
#define FUSE_AUTO_INVAL_DATA (1 << 12)
|
||||
#define FUSE_DO_READDIRPLUS (1 << 13)
|
||||
#define FUSE_READDIRPLUS_AUTO (1 << 14)
|
||||
#define FUSE_ASYNC_DIO (1 << 15)
|
||||
#define FUSE_WRITEBACK_CACHE (1 << 16)
|
||||
#define FUSE_NO_OPEN_SUPPORT (1 << 17)
|
||||
#define FUSE_PARALLEL_DIROPS (1 << 18)
|
||||
#define FUSE_HANDLE_KILLPRIV (1 << 19)
|
||||
#define FUSE_POSIX_ACL (1 << 20)
|
||||
#define FUSE_ABORT_ERROR (1 << 21)
|
||||
#define FUSE_MAX_PAGES (1 << 22)
|
||||
#define FUSE_CACHE_SYMLINKS (1 << 23)
|
||||
#define FUSE_NO_OPENDIR_SUPPORT (1 << 24)
|
||||
#define FUSE_ASYNC_READ (1 << 0)
|
||||
#define FUSE_POSIX_LOCKS (1 << 1)
|
||||
#define FUSE_FILE_OPS (1 << 2)
|
||||
#define FUSE_ATOMIC_O_TRUNC (1 << 3)
|
||||
#define FUSE_EXPORT_SUPPORT (1 << 4)
|
||||
#define FUSE_BIG_WRITES (1 << 5)
|
||||
#define FUSE_DONT_MASK (1 << 6)
|
||||
#define FUSE_SPLICE_WRITE (1 << 7)
|
||||
#define FUSE_SPLICE_MOVE (1 << 8)
|
||||
#define FUSE_SPLICE_READ (1 << 9)
|
||||
#define FUSE_FLOCK_LOCKS (1 << 10)
|
||||
#define FUSE_HAS_IOCTL_DIR (1 << 11)
|
||||
#define FUSE_AUTO_INVAL_DATA (1 << 12)
|
||||
#define FUSE_DO_READDIRPLUS (1 << 13)
|
||||
#define FUSE_READDIRPLUS_AUTO (1 << 14)
|
||||
#define FUSE_ASYNC_DIO (1 << 15)
|
||||
#define FUSE_WRITEBACK_CACHE (1 << 16)
|
||||
#define FUSE_NO_OPEN_SUPPORT (1 << 17)
|
||||
#define FUSE_PARALLEL_DIROPS (1 << 18)
|
||||
#define FUSE_HANDLE_KILLPRIV (1 << 19)
|
||||
#define FUSE_POSIX_ACL (1 << 20)
|
||||
#define FUSE_ABORT_ERROR (1 << 21)
|
||||
#define FUSE_MAX_PAGES (1 << 22)
|
||||
#define FUSE_CACHE_SYMLINKS (1 << 23)
|
||||
#define FUSE_NO_OPENDIR_SUPPORT (1 << 24)
|
||||
#define FUSE_EXPLICIT_INVAL_DATA (1 << 25)
|
||||
#define FUSE_MAP_ALIGNMENT (1 << 26)
|
||||
#define FUSE_SUBMOUNTS (1 << 27)
|
||||
#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)
|
||||
#define FUSE_SETXATTR_EXT (1 << 29)
|
||||
#define FUSE_INIT_EXT (1 << 30)
|
||||
#define FUSE_INIT_RESERVED (1 << 31)
|
||||
#define FUSE_MAP_ALIGNMENT (1 << 26)
|
||||
#define FUSE_SUBMOUNTS (1 << 27)
|
||||
#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)
|
||||
#define FUSE_SETXATTR_EXT (1 << 29)
|
||||
#define FUSE_INIT_EXT (1 << 30)
|
||||
#define FUSE_INIT_RESERVED (1ULL << 31)
|
||||
/* bits 32..63 get shifted down 32 bits into the flags2 field */
|
||||
#define FUSE_SECURITY_CTX (1ULL << 32)
|
||||
#define FUSE_HAS_INODE_DAX (1ULL << 33)
|
||||
#define FUSE_CREATE_SUPP_GROUP (1ULL << 34)
|
||||
#define FUSE_SECURITY_CTX (1ULL << 32)
|
||||
#define FUSE_HAS_INODE_DAX (1ULL << 33)
|
||||
#define FUSE_CREATE_SUPP_GROUP (1ULL << 34)
|
||||
#define FUSE_HAS_EXPIRE_ONLY (1ULL << 35)
|
||||
#define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
|
||||
|
||||
/* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
|
||||
#define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP
|
||||
|
||||
/**
|
||||
* CUSE INIT request/reply flags
|
||||
@@ -417,8 +463,8 @@ struct fuse_file_lock {
|
||||
/**
|
||||
* Release flags
|
||||
*/
|
||||
#define FUSE_RELEASE_FLUSH (1 << 0)
|
||||
#define FUSE_RELEASE_FLOCK_UNLOCK (1 << 1)
|
||||
#define FUSE_RELEASE_FLUSH (1 << 0)
|
||||
#define FUSE_RELEASE_FLOCK_UNLOCK (1 << 1)
|
||||
|
||||
/**
|
||||
* Getattr flags
|
||||
@@ -572,6 +618,7 @@ enum fuse_opcode {
|
||||
FUSE_REMOVEMAPPING = 49,
|
||||
FUSE_SYNCFS = 50,
|
||||
FUSE_TMPFILE = 51,
|
||||
FUSE_STATX = 52,
|
||||
|
||||
/* CUSE specific operations */
|
||||
CUSE_INIT = 4096,
|
||||
@@ -636,6 +683,22 @@ struct fuse_attr_out {
|
||||
struct fuse_attr attr;
|
||||
};
|
||||
|
||||
struct fuse_statx_in {
|
||||
uint32_t getattr_flags;
|
||||
uint32_t reserved;
|
||||
uint64_t fh;
|
||||
uint32_t sx_flags;
|
||||
uint32_t sx_mask;
|
||||
};
|
||||
|
||||
struct fuse_statx_out {
|
||||
uint64_t attr_valid; /* Cache timeout for the attributes */
|
||||
uint32_t attr_valid_nsec;
|
||||
uint32_t flags;
|
||||
uint64_t spare[2];
|
||||
struct fuse_statx stat;
|
||||
};
|
||||
|
||||
#define FUSE_COMPAT_MKNOD_IN_SIZE 8
|
||||
|
||||
struct fuse_mknod_in {
|
||||
|
||||
+48
-884
@@ -131,891 +131,55 @@ struct fuse_ctx
|
||||
*/
|
||||
struct fuse_lowlevel_ops
|
||||
{
|
||||
/**
|
||||
* Initialize filesystem
|
||||
*
|
||||
* Called before any other filesystem method
|
||||
*
|
||||
* There's no reply to this function
|
||||
*
|
||||
* @param userdata the user data passed to fuse_lowlevel_new()
|
||||
*/
|
||||
void (*init)(void *userdata, struct fuse_conn_info *conn);
|
||||
|
||||
/**
|
||||
* Clean up filesystem
|
||||
*
|
||||
* Called on filesystem exit
|
||||
*
|
||||
* There's no reply to this function
|
||||
*
|
||||
* @param userdata the user data passed to fuse_lowlevel_new()
|
||||
*/
|
||||
void (*access)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*bmap)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*copy_file_range)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*create)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*destroy)(void *userdata);
|
||||
|
||||
/**
|
||||
* Look up a directory entry by name and get its attributes.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_entry
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param parent inode number of the parent directory
|
||||
* @param name the name to look up
|
||||
*/
|
||||
void (*lookup)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Forget about an inode
|
||||
*
|
||||
* This function is called when the kernel removes an inode
|
||||
* from its internal caches.
|
||||
*
|
||||
* The inode's lookup count increases by one for every call to
|
||||
* fuse_reply_entry and fuse_reply_create. The nlookup parameter
|
||||
* indicates by how much the lookup count should be decreased.
|
||||
*
|
||||
* Inodes with a non-zero lookup count may receive request from
|
||||
* the kernel even after calls to unlink, rmdir or (when
|
||||
* overwriting an existing file) rename. Filesystems must handle
|
||||
* such requests properly and it is recommended to defer removal
|
||||
* of the inode until the lookup count reaches zero. Calls to
|
||||
* unlink, remdir or rename will be followed closely by forget
|
||||
* unless the file or directory is open, in which case the
|
||||
* kernel issues forget only after the release or releasedir
|
||||
* calls.
|
||||
*
|
||||
* Note that if a file system will be exported over NFS the
|
||||
* inodes lifetime must extend even beyond forget. See the
|
||||
* generation field in struct fuse_entry_param above.
|
||||
*
|
||||
* On unmount the lookup count for all inodes implicitly drops
|
||||
* to zero. It is not guaranteed that the file system will
|
||||
* receive corresponding forget messages for the affected
|
||||
* inodes.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_none
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param nlookup the number of lookups to forget
|
||||
*/
|
||||
void (*forget)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Get file attributes
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_attr
|
||||
* fuse_reply_err
|
||||
*/
|
||||
void (*getattr)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Set file attributes
|
||||
*
|
||||
* In the 'attr' argument only members indicated by the 'to_set'
|
||||
* bitmask contain valid values. Other members contain undefined
|
||||
* values.
|
||||
*
|
||||
* If the setattr was invoked from the ftruncate() system call
|
||||
* under Linux kernel versions 2.6.15 or later, the fi->fh will
|
||||
* contain the value set by the open method or will be undefined
|
||||
* if the open method didn't set any value. Otherwise (not
|
||||
* ftruncate call, or kernel version earlier than 2.6.15) the fi
|
||||
* parameter will be NULL.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_attr
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param attr the attributes
|
||||
* @param to_set bit mask of attributes which should be set
|
||||
* @param fi file information, or NULL
|
||||
*
|
||||
* Changed in version 2.5:
|
||||
* file information filled in for ftruncate
|
||||
*/
|
||||
void (*setattr)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Read symbolic link
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_readlink
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
*/
|
||||
void (*readlink)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Create file node
|
||||
*
|
||||
* Create a regular file, character device, block device, fifo or
|
||||
* socket node.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_entry
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param parent inode number of the parent directory
|
||||
* @param name to create
|
||||
* @param mode file type and mode with which to create the new file
|
||||
* @param rdev the device number (only valid if created file is a device)
|
||||
*/
|
||||
void (*mknod)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Create a directory
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_entry
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param parent inode number of the parent directory
|
||||
* @param name to create
|
||||
* @param mode with which to create the new file
|
||||
*/
|
||||
void (*mkdir)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Remove a file
|
||||
*
|
||||
* If the file's inode's lookup count is non-zero, the file
|
||||
* system is expected to postpone any removal of the inode
|
||||
* until the lookup count reaches zero (see description of the
|
||||
* forget function).
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param parent inode number of the parent directory
|
||||
* @param name to remove
|
||||
*/
|
||||
void (*unlink)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Remove a directory
|
||||
*
|
||||
* If the directory's inode's lookup count is non-zero, the
|
||||
* file system is expected to postpone any removal of the
|
||||
* inode until the lookup count reaches zero (see description
|
||||
* of the forget function).
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param parent inode number of the parent directory
|
||||
* @param name to remove
|
||||
*/
|
||||
void (*rmdir)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Create a symbolic link
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_entry
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param link the contents of the symbolic link
|
||||
* @param parent inode number of the parent directory
|
||||
* @param name to create
|
||||
*/
|
||||
void (*symlink)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/** Rename a file
|
||||
*
|
||||
* If the target exists it should be atomically replaced. If
|
||||
* the target's inode's lookup count is non-zero, the file
|
||||
* system is expected to postpone any removal of the inode
|
||||
* until the lookup count reaches zero (see description of the
|
||||
* forget function).
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param parent inode number of the old parent directory
|
||||
* @param name old name
|
||||
* @param newparent inode number of the new parent directory
|
||||
* @param newname new name
|
||||
*/
|
||||
void (*rename)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Create a hard link
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_entry
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the old inode number
|
||||
* @param newparent inode number of the new parent directory
|
||||
* @param newname new name to create
|
||||
*/
|
||||
void (*link)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Open a file
|
||||
*
|
||||
* Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
|
||||
* O_TRUNC) are available in fi->flags.
|
||||
*
|
||||
* Filesystem may store an arbitrary file handle (pointer, index,
|
||||
* etc) in fi->fh, and use this in other all other file operations
|
||||
* (read, write, flush, release, fsync).
|
||||
*
|
||||
* Filesystem may also implement stateless file I/O and not store
|
||||
* anything in fi->fh.
|
||||
*
|
||||
* There are also some flags (direct_io, keep_cache) which the
|
||||
* filesystem may set in fi, to change the way the file is opened.
|
||||
* See fuse_file_info structure in <fuse_common.h> for more details.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_open
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*open)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Read data
|
||||
*
|
||||
* Read should send exactly the number of bytes requested except
|
||||
* on EOF or error, otherwise the rest of the data will be
|
||||
* substituted with zeroes. An exception to this is when the file
|
||||
* has been opened in 'direct_io' mode, in which case the return
|
||||
* value of the read system call will reflect the return value of
|
||||
* this operation.
|
||||
*
|
||||
* fi->fh will contain the value set by the open method, or will
|
||||
* be undefined if the open method didn't set any value.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_buf
|
||||
* fuse_reply_iov
|
||||
* fuse_reply_data
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param size number of bytes to read
|
||||
* @param off offset to read from
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*read)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Write data
|
||||
*
|
||||
* Write should return exactly the number of bytes requested
|
||||
* except on error. An exception to this is when the file has
|
||||
* been opened in 'direct_io' mode, in which case the return value
|
||||
* of the write system call will reflect the return value of this
|
||||
* operation.
|
||||
*
|
||||
* fi->fh will contain the value set by the open method, or will
|
||||
* be undefined if the open method didn't set any value.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_write
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param buf data to write
|
||||
* @param size number of bytes to write
|
||||
* @param off offset to write to
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*write)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Flush method
|
||||
*
|
||||
* This is called on each close() of the opened file.
|
||||
*
|
||||
* Since file descriptors can be duplicated (dup, dup2, fork), for
|
||||
* one open call there may be many flush calls.
|
||||
*
|
||||
* Filesystems shouldn't assume that flush will always be called
|
||||
* after some writes, or that if will be called at all.
|
||||
*
|
||||
* fi->fh will contain the value set by the open method, or will
|
||||
* be undefined if the open method didn't set any value.
|
||||
*
|
||||
* NOTE: the name of the method is misleading, since (unlike
|
||||
* fsync) the filesystem is not forced to flush pending writes.
|
||||
* One reason to flush data, is if the filesystem wants to return
|
||||
* write errors.
|
||||
*
|
||||
* If the filesystem supports file locking operations (setlk,
|
||||
* getlk) it should remove all locks belonging to 'fi->owner'.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*flush)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Release an open file
|
||||
*
|
||||
* Release is called when there are no more references to an open
|
||||
* file: all file descriptors are closed and all memory mappings
|
||||
* are unmapped.
|
||||
*
|
||||
* For every open call there will be exactly one release call.
|
||||
*
|
||||
* The filesystem may reply with an error, but error values are
|
||||
* not returned to close() or munmap() which triggered the
|
||||
* release.
|
||||
*
|
||||
* fi->fh will contain the value set by the open method, or will
|
||||
* be undefined if the open method didn't set any value.
|
||||
* fi->flags will contain the same flags as for open.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*release)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Synchronize file contents
|
||||
*
|
||||
* If the datasync parameter is non-zero, then only the user data
|
||||
* should be flushed, not the meta data.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param datasync flag indicating if only data should be flushed
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*fsync)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Open a directory
|
||||
*
|
||||
* Filesystem may store an arbitrary file handle (pointer, index,
|
||||
* etc) in fi->fh, and use this in other all other directory
|
||||
* stream operations (readdir, releasedir, fsyncdir).
|
||||
*
|
||||
* Filesystem may also implement stateless directory I/O and not
|
||||
* store anything in fi->fh, though that makes it impossible to
|
||||
* implement standard conforming directory stream operations in
|
||||
* case the contents of the directory can change between opendir
|
||||
* and releasedir.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_open
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*opendir)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Read directory
|
||||
*
|
||||
* Send a buffer filled using fuse_add_direntry(), with size not
|
||||
* exceeding the requested size. Send an empty buffer on end of
|
||||
* stream.
|
||||
*
|
||||
* fi->fh will contain the value set by the opendir method, or
|
||||
* will be undefined if the opendir method didn't set any value.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_buf
|
||||
* fuse_reply_data
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param size maximum number of bytes to send
|
||||
* @param off offset to continue reading the directory stream
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*readdir)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
void (*readdir_plus)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Release an open directory
|
||||
*
|
||||
* For every opendir call there will be exactly one releasedir
|
||||
* call.
|
||||
*
|
||||
* fi->fh will contain the value set by the opendir method, or
|
||||
* will be undefined if the opendir method didn't set any value.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*releasedir)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Synchronize directory contents
|
||||
*
|
||||
* If the datasync parameter is non-zero, then only the directory
|
||||
* contents should be flushed, not the meta data.
|
||||
*
|
||||
* fi->fh will contain the value set by the opendir method, or
|
||||
* will be undefined if the opendir method didn't set any value.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param datasync flag indicating if only data should be flushed
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*fsyncdir)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Get file system statistics
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_statfs
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number, zero means "undefined"
|
||||
*/
|
||||
void (*statfs)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Set an extended attribute
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*/
|
||||
void (*setxattr)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Get an extended attribute
|
||||
*
|
||||
* If size is zero, the size of the value should be sent with
|
||||
* fuse_reply_xattr.
|
||||
*
|
||||
* If the size is non-zero, and the value fits in the buffer, the
|
||||
* value should be sent with fuse_reply_buf.
|
||||
*
|
||||
* If the size is too small for the value, the ERANGE error should
|
||||
* be sent.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_buf
|
||||
* fuse_reply_data
|
||||
* fuse_reply_xattr
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param name of the extended attribute
|
||||
* @param size maximum size of the value to send
|
||||
*/
|
||||
void (*getxattr)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* List extended attribute names
|
||||
*
|
||||
* If size is zero, the total size of the attribute list should be
|
||||
* sent with fuse_reply_xattr.
|
||||
*
|
||||
* If the size is non-zero, and the null character separated
|
||||
* attribute list fits in the buffer, the list should be sent with
|
||||
* fuse_reply_buf.
|
||||
*
|
||||
* If the size is too small for the list, the ERANGE error should
|
||||
* be sent.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_buf
|
||||
* fuse_reply_data
|
||||
* fuse_reply_xattr
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param size maximum size of the list to send
|
||||
*/
|
||||
void (*listxattr)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Remove an extended attribute
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param name of the extended attribute
|
||||
*/
|
||||
void (*removexattr)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Check file access permissions
|
||||
*
|
||||
* This will be called for the access() system call. If the
|
||||
* 'default_permissions' mount option is given, this method is not
|
||||
* called.
|
||||
*
|
||||
* This method is not called under Linux kernel versions 2.4.x
|
||||
*
|
||||
* Introduced in version 2.5
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param mask requested access mode
|
||||
*/
|
||||
void (*access)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Create and open a file
|
||||
*
|
||||
* If the file does not exist, first create it with the specified
|
||||
* mode, and then open it.
|
||||
*
|
||||
* Open flags (with the exception of O_NOCTTY) are available in
|
||||
* fi->flags.
|
||||
*
|
||||
* Filesystem may store an arbitrary file handle (pointer, index,
|
||||
* etc) in fi->fh, and use this in other all other file operations
|
||||
* (read, write, flush, release, fsync).
|
||||
*
|
||||
* There are also some flags (direct_io, keep_cache) which the
|
||||
* filesystem may set in fi, to change the way the file is opened.
|
||||
* See fuse_file_info structure in <fuse_common.h> for more details.
|
||||
*
|
||||
* If this method is not implemented or under Linux kernel
|
||||
* versions earlier than 2.6.15, the mknod() and open() methods
|
||||
* will be called instead.
|
||||
*
|
||||
* Introduced in version 2.5
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_create
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param parent inode number of the parent directory
|
||||
* @param name to create
|
||||
* @param mode file type and mode with which to create the new file
|
||||
* @param fi file information
|
||||
*/
|
||||
void (*create)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Test for a POSIX file lock
|
||||
*
|
||||
* Introduced in version 2.6
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_lock
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
* @param lock the region/type to test
|
||||
*/
|
||||
void (*getlk)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
/**
|
||||
* Acquire, modify or release a POSIX file lock
|
||||
*
|
||||
* For POSIX threads (NPTL) there's a 1-1 relation between pid and
|
||||
* owner, but otherwise this is not always the case. For checking
|
||||
* lock ownership, 'fi->owner' must be used. The l_pid field in
|
||||
* 'struct flock' should only be used to fill in this field in
|
||||
* getlk().
|
||||
*
|
||||
* Note: if the locking methods are not implemented, the kernel
|
||||
* will still allow file locking to work locally. Hence these are
|
||||
* only interesting for network filesystems and similar.
|
||||
*
|
||||
* Introduced in version 2.6
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
* @param lock the region/type to set
|
||||
* @param sleep locking operation may sleep
|
||||
*/
|
||||
void (*setlk)(fuse_req_t req, uint64_t ino,
|
||||
fuse_file_info_t *fi,
|
||||
struct flock *lock, int sleep);
|
||||
|
||||
/**
|
||||
* Map block index within file to block index within device
|
||||
*
|
||||
* Note: This makes sense only for block device backed filesystems
|
||||
* mounted with the 'blkdev' option
|
||||
*
|
||||
* Introduced in version 2.6
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_bmap
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param blocksize unit of block index
|
||||
* @param idx block index within file
|
||||
*/
|
||||
void (*bmap)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Ioctl
|
||||
*
|
||||
* Note: For unrestricted ioctls (not allowed for FUSE
|
||||
* servers), data in and out areas can be discovered by giving
|
||||
* iovs and setting FUSE_IOCTL_RETRY in @flags. For
|
||||
* restricted ioctls, kernel prepares in/out data area
|
||||
* according to the information encoded in cmd.
|
||||
*
|
||||
* Introduced in version 2.8
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_ioctl_retry
|
||||
* fuse_reply_ioctl
|
||||
* fuse_reply_ioctl_iov
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param cmd ioctl command
|
||||
* @param arg ioctl argument
|
||||
* @param fi file information
|
||||
* @param flags for FUSE_IOCTL_* flags
|
||||
* @param in_buf data fetched from the caller
|
||||
* @param in_bufsz number of fetched bytes
|
||||
* @param out_bufsz maximum size of output data
|
||||
*/
|
||||
void (*ioctl)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Poll for IO readiness
|
||||
*
|
||||
* Introduced in version 2.8
|
||||
*
|
||||
* Note: If ph is non-NULL, the client should notify
|
||||
* when IO readiness events occur by calling
|
||||
* fuse_lowelevel_notify_poll() with the specified ph.
|
||||
*
|
||||
* Regardless of the number of times poll with a non-NULL ph
|
||||
* is received, single notification is enough to clear all.
|
||||
* Notifying more times incurs overhead but doesn't harm
|
||||
* correctness.
|
||||
*
|
||||
* The callee is responsible for destroying ph with
|
||||
* fuse_pollhandle_destroy() when no longer in use.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_poll
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
* @param ph poll handle to be used for notification
|
||||
*/
|
||||
void (*poll)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Callback function for the retrieve request
|
||||
*
|
||||
* Introduced in version 2.9
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_none
|
||||
*
|
||||
* @param req request handle
|
||||
* @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
|
||||
* @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
|
||||
* @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
|
||||
* @param bufv the buffer containing the returned data
|
||||
*/
|
||||
void (*retrieve_reply)(fuse_req_t req,
|
||||
void *cookie,
|
||||
uint64_t ino,
|
||||
off_t offset);
|
||||
|
||||
/**
|
||||
* Forget about multiple inodes
|
||||
*
|
||||
* See description of the forget function for more
|
||||
* information.
|
||||
*
|
||||
* Introduced in version 2.9
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_none
|
||||
*
|
||||
* @param req request handle
|
||||
*/
|
||||
void (*forget_multi)(fuse_req_t req,
|
||||
struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Acquire, modify or release a BSD file lock
|
||||
*
|
||||
* Note: if the locking methods are not implemented, the kernel
|
||||
* will still allow file locking to work locally. Hence these are
|
||||
* only interesting for network filesystems and similar.
|
||||
*
|
||||
* Introduced in version 2.9
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param fi file information
|
||||
* @param op the locking operation, see flock(2)
|
||||
*/
|
||||
void (*flock)(fuse_req_t req, uint64_t ino,
|
||||
fuse_file_info_t *fi, int op);
|
||||
|
||||
/**
|
||||
* Allocate requested space. If this function returns success then
|
||||
* subsequent writes to the specified range shall not fail due to the lack
|
||||
* of free space on the file system storage media.
|
||||
*
|
||||
* Introduced in version 2.9
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino the inode number
|
||||
* @param offset starting point for allocated region
|
||||
* @param length size of allocated region
|
||||
* @param mode determines the operation to be performed on the given range,
|
||||
* see fallocate(2)
|
||||
*/
|
||||
void (*fallocate)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
|
||||
/**
|
||||
* Copy a range of data from one file to another
|
||||
*
|
||||
* Performs an optimized copy between two file descriptors without
|
||||
* the
|
||||
* additional cost of transferring data through the FUSE kernel
|
||||
* module
|
||||
* to user space (glibc) and then back into the FUSE filesystem
|
||||
* again.
|
||||
*
|
||||
* In case this method is not implemented, glibc falls back to
|
||||
* reading
|
||||
* data from the source and writing to the destination. Effectively
|
||||
* doing an inefficient copy of the data.
|
||||
*
|
||||
* If this request is answered with an error code of ENOSYS, this is
|
||||
* treated as a permanent failure with error code EOPNOTSUPP,
|
||||
* i.e. all
|
||||
* future copy_file_range() requests will fail with EOPNOTSUPP
|
||||
* without
|
||||
* being send to the filesystem process.
|
||||
*
|
||||
* Valid replies:
|
||||
* fuse_reply_write
|
||||
* fuse_reply_err
|
||||
*
|
||||
* @param req request handle
|
||||
* @param ino_in the inode number of the source file
|
||||
* @param off_in starting point from were the data should be read
|
||||
* @param fi_in file information of the source file
|
||||
* @param ino_out the inode number of the destination file
|
||||
* @param off_out starting point where the data should be written
|
||||
* @param fi_out file information of the destination file
|
||||
* @param len maximum size of the data to copy
|
||||
* @param flags passed along with the copy_file_range() syscall
|
||||
*/
|
||||
void (*copy_file_range)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
|
||||
void (*setupmapping)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
void (*removemapping)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
void (*syncfs)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
void (*tmpfile)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
void (*fallocate)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*flock)(fuse_req_t req, uint64_t ino, fuse_file_info_t *fi, int op);
|
||||
void (*flush)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*forget)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*forget_multi)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*fsync)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*fsyncdir)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*getattr)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*getlk)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*getxattr)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*init)(void *userdata, struct fuse_conn_info *conn);
|
||||
void (*ioctl)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*link)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*listxattr)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*lookup)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*lseek)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*mkdir)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*mknod)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*open)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*opendir)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*poll)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*read)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*readdir)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*readdir_plus)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*readlink)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*release)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*releasedir)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*removemapping)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*removexattr)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*rename)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*rename2)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*retrieve_reply)(fuse_req_t req, void *cookie, uint64_t ino, off_t offset);
|
||||
void (*rmdir)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*setattr)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*setlk)(fuse_req_t req, uint64_t ino, fuse_file_info_t *fi, struct flock *lock, int sleep);
|
||||
void (*setupmapping)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*setxattr)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*statfs)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*statx)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*symlink)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*syncfs)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*tmpfile)(fuse_req_t req, const struct fuse_in_header *hdr);
|
||||
void (*unlink)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
void (*write)(fuse_req_t req, struct fuse_in_header *hdr);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+25
-10
@@ -1,22 +1,37 @@
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2024, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "cpu.hpp"
|
||||
#include "ghc/filesystem.hpp"
|
||||
#include "fmt/core.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
int
|
||||
CPU::getaffinity(const pthread_t thread_id_,
|
||||
cpu_set_t *cpuset_)
|
||||
CPU::getaffinity(cpu_set_t *cpuset_)
|
||||
{
|
||||
const pid_t pid = 0;
|
||||
CPU_ZERO(cpuset_);
|
||||
return sched_getaffinity(thread_id_,
|
||||
return sched_getaffinity(pid,
|
||||
sizeof(cpu_set_t),
|
||||
cpuset_);
|
||||
}
|
||||
@@ -70,7 +85,7 @@ CPU::count()
|
||||
int rv;
|
||||
cpu_set_t cpuset;
|
||||
|
||||
rv = CPU::getaffinity(0,&cpuset);
|
||||
rv = CPU::getaffinity(&cpuset);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
@@ -83,7 +98,7 @@ CPU::cpus()
|
||||
cpu_set_t cpuset;
|
||||
CPU::CPUVec cpuvec;
|
||||
|
||||
CPU::getaffinity(0,&cpuset);
|
||||
CPU::getaffinity(&cpuset);
|
||||
|
||||
for(int i = 0; i < CPU_SETSIZE; i++)
|
||||
{
|
||||
@@ -102,7 +117,7 @@ CPU::cpu2core()
|
||||
cpu_set_t cpuset;
|
||||
CPU::CPU2CoreMap c2c;
|
||||
|
||||
CPU::getaffinity(0,&cpuset);
|
||||
CPU::getaffinity(&cpuset);
|
||||
|
||||
for(int i = 0; i < CPU_SETSIZE; i++)
|
||||
{
|
||||
@@ -135,7 +150,7 @@ CPU::core2cpus()
|
||||
cpu_set_t cpuset;
|
||||
CPU::Core2CPUsMap c2c;
|
||||
|
||||
CPU::getaffinity(0,&cpuset);
|
||||
CPU::getaffinity(&cpuset);
|
||||
|
||||
for(int i = 0; i < CPU_SETSIZE; i++)
|
||||
{
|
||||
|
||||
+4
-5
@@ -1,10 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
#ifdef __FreeBSD__
|
||||
#include <pthread_np.h>
|
||||
#endif
|
||||
#include <sched.h>
|
||||
|
||||
#include <set>
|
||||
@@ -22,7 +21,7 @@ public:
|
||||
|
||||
public:
|
||||
static int count();
|
||||
static int getaffinity(const pthread_t thread_id, cpu_set_t *cpuset);
|
||||
static int getaffinity(cpu_set_t *cpuset);
|
||||
static int setaffinity(const pthread_t thread_id, cpu_set_t *cpuset);
|
||||
static int setaffinity(const pthread_t thread_id, const int cpu);
|
||||
static int setaffinity(const pthread_t thread_id, const std::set<int> cpus);
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
#ifndef CRC32B_H_INCLUDED
|
||||
#define CRC32B_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef unsigned int crc32b_t;
|
||||
|
||||
crc32b_t crc32b_start(void);
|
||||
@@ -29,4 +34,8 @@ crc32b_t crc32b_finish(const crc32b_t crc);
|
||||
|
||||
crc32b_t crc32b(const void *buf, crc32b_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "fuse_kernel.h"
|
||||
|
||||
@@ -158,9 +160,9 @@ open_flag_to_str(const uint64_t offset_)
|
||||
static
|
||||
const
|
||||
char*
|
||||
fuse_flag_to_str(const uint32_t offset_)
|
||||
fuse_flag_to_str(const uint64_t offset_)
|
||||
{
|
||||
switch(1 << offset_)
|
||||
switch(1ULL << offset_)
|
||||
{
|
||||
FUSE_INIT_FLAG_CASE(ASYNC_READ);
|
||||
FUSE_INIT_FLAG_CASE(POSIX_LOCKS);
|
||||
@@ -189,6 +191,16 @@ fuse_flag_to_str(const uint32_t offset_)
|
||||
FUSE_INIT_FLAG_CASE(NO_OPENDIR_SUPPORT);
|
||||
FUSE_INIT_FLAG_CASE(EXPLICIT_INVAL_DATA);
|
||||
FUSE_INIT_FLAG_CASE(MAP_ALIGNMENT);
|
||||
FUSE_INIT_FLAG_CASE(SUBMOUNTS);
|
||||
FUSE_INIT_FLAG_CASE(HANDLE_KILLPRIV_V2);
|
||||
FUSE_INIT_FLAG_CASE(SETXATTR_EXT);
|
||||
FUSE_INIT_FLAG_CASE(INIT_EXT);
|
||||
FUSE_INIT_FLAG_CASE(INIT_RESERVED);
|
||||
FUSE_INIT_FLAG_CASE(SECURITY_CTX);
|
||||
FUSE_INIT_FLAG_CASE(HAS_INODE_DAX);
|
||||
FUSE_INIT_FLAG_CASE(CREATE_SUPP_GROUP);
|
||||
FUSE_INIT_FLAG_CASE(HAS_EXPIRE_ONLY);
|
||||
FUSE_INIT_FLAG_CASE(DIRECT_IO_ALLOW_MMAP);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -200,8 +212,8 @@ static
|
||||
void
|
||||
debug_open_flags(const uint32_t flags_)
|
||||
{
|
||||
fprintf(stderr,"%s,",open_accmode_to_str(flags_));
|
||||
for(int i = 0; i < (sizeof(flags_) * 8); i++)
|
||||
fprintf(stderr,"%s, ",open_accmode_to_str(flags_));
|
||||
for(size_t i = 0; i < (sizeof(flags_) * 8); i++)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
@@ -212,7 +224,7 @@ debug_open_flags(const uint32_t flags_)
|
||||
if(str == NULL)
|
||||
continue;
|
||||
|
||||
fprintf(stderr,"%s,",str);
|
||||
fprintf(stderr,"%s, ",str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,11 +254,11 @@ debug_fuse_open_out(const struct fuse_open_out *arg_)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"fuse_open_out:"
|
||||
" fh=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" open_flags=0x%X (",
|
||||
arg_->fh,
|
||||
arg_->open_flags);
|
||||
for(int i = 0; i < (sizeof(arg_->open_flags) * 8); i++)
|
||||
for(size_t i = 0; i < (sizeof(arg_->open_flags) * 8); i++)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
@@ -266,7 +278,7 @@ static
|
||||
void
|
||||
debug_fuse_lookup(const void *arg_)
|
||||
{
|
||||
const char *name = arg_;
|
||||
const char *name = (const char*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_lookup:"
|
||||
@@ -280,12 +292,12 @@ static
|
||||
void
|
||||
debug_fuse_getattr_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_getattr_in *arg = arg_;
|
||||
const struct fuse_getattr_in *arg = (const fuse_getattr_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_getattr_in:"
|
||||
" getattr_flags=0x%08X;"
|
||||
" fh=0x%"PRIx64";\n",
|
||||
" fh=0x%" PRIx64 ";\n",
|
||||
arg->getattr_flags,
|
||||
arg->fh);
|
||||
}
|
||||
@@ -294,12 +306,12 @@ static
|
||||
void
|
||||
debug_fuse_setattr_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_setattr_in *arg = arg_;
|
||||
const struct fuse_setattr_in *arg = (const fuse_setattr_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_setattr_in:"
|
||||
" valid=%u;"
|
||||
" fh=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" size=%zu;"
|
||||
" lock_owner=%zu;"
|
||||
" atime=%zu;"
|
||||
@@ -332,7 +344,7 @@ static
|
||||
void
|
||||
debug_fuse_access_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_access_in *arg = arg_;
|
||||
const struct fuse_access_in *arg = (const fuse_access_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_access_in:"
|
||||
@@ -346,7 +358,7 @@ static
|
||||
void
|
||||
debug_fuse_mknod_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_mknod_in *arg = arg_;
|
||||
const struct fuse_mknod_in *arg = (const fuse_mknod_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_mknod_in:"
|
||||
@@ -364,7 +376,7 @@ static
|
||||
void
|
||||
debug_fuse_mkdir_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_mkdir_in *arg = arg_;
|
||||
const struct fuse_mkdir_in *arg = (const fuse_mkdir_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_mkdir_in:"
|
||||
@@ -382,7 +394,7 @@ static
|
||||
void
|
||||
debug_fuse_unlink(const void *arg_)
|
||||
{
|
||||
const char *name = arg_;
|
||||
const char *name = (const char*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_unlink:"
|
||||
@@ -396,7 +408,7 @@ static
|
||||
void
|
||||
debug_fuse_rmdir(const void *arg_)
|
||||
{
|
||||
const char *name = arg_;
|
||||
const char *name = (const char*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_mkdir:"
|
||||
@@ -413,7 +425,7 @@ debug_fuse_symlink(const void *arg_)
|
||||
const char *name;
|
||||
const char *linkname;
|
||||
|
||||
name = arg_;
|
||||
name = (const char*)arg_;
|
||||
linkname = (name + (strlen(name) + 1));
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
@@ -432,7 +444,7 @@ debug_fuse_rename_in(const void *arg_)
|
||||
{
|
||||
const char *oldname;
|
||||
const char *newname;
|
||||
const struct fuse_rename_in *arg = arg_;
|
||||
const struct fuse_rename_in *arg = (const fuse_rename_in*)arg_;
|
||||
|
||||
oldname = PARAM(arg);
|
||||
newname = (oldname + strlen(oldname) + 1);
|
||||
@@ -454,7 +466,7 @@ void
|
||||
debug_fuse_link_in(const void *arg_)
|
||||
{
|
||||
const char *name;
|
||||
const struct fuse_link_in *arg = arg_;
|
||||
const struct fuse_link_in *arg = (const fuse_link_in*)arg_;
|
||||
|
||||
name = PARAM(arg);
|
||||
|
||||
@@ -473,7 +485,7 @@ void
|
||||
debug_fuse_create_in(const void *arg_)
|
||||
{
|
||||
const char *name;
|
||||
const struct fuse_create_in *arg = arg_;
|
||||
const struct fuse_create_in *arg = (const fuse_create_in*)arg_;
|
||||
|
||||
name = PARAM(arg);
|
||||
|
||||
@@ -495,7 +507,7 @@ static
|
||||
void
|
||||
debug_fuse_open_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_open_in *arg = arg_;
|
||||
const struct fuse_open_in *arg = (const fuse_open_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_open_in:"
|
||||
@@ -509,15 +521,15 @@ static
|
||||
void
|
||||
debug_fuse_read_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_read_in *arg = arg_;
|
||||
const struct fuse_read_in *arg = (const fuse_read_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_read_in:"
|
||||
" fh=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" offset=%zu;"
|
||||
" size=%u;"
|
||||
" read_flags=%X;"
|
||||
" lock_owner=0x%"PRIx64";"
|
||||
" lock_owner=0x%" PRIx64 ";"
|
||||
" flags=0x%X ("
|
||||
,
|
||||
arg->fh,
|
||||
@@ -534,14 +546,14 @@ static
|
||||
void
|
||||
debug_fuse_write_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_write_in *arg = arg_;
|
||||
const struct fuse_write_in *arg = (const fuse_write_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_write_in:"
|
||||
" fh=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" offset=%zu;"
|
||||
" size=%u;"
|
||||
" lock_owner=0x%"PRIx64";"
|
||||
" lock_owner=0x%" PRIx64 ";"
|
||||
" flags=0x%X ("
|
||||
,
|
||||
arg->fh,
|
||||
@@ -553,7 +565,7 @@ debug_fuse_write_in(const void *arg_)
|
||||
fprintf(g_OUTPUT,
|
||||
"); write_flags=0x%X (",
|
||||
arg->write_flags);
|
||||
for(int i = 0; i < (sizeof(arg->write_flags) * 8); i++)
|
||||
for(size_t i = 0; i < (sizeof(arg->write_flags) * 8); i++)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
@@ -573,12 +585,12 @@ static
|
||||
void
|
||||
debug_fuse_flush_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_flush_in *arg = arg_;
|
||||
const struct fuse_flush_in *arg = (const fuse_flush_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_flush_in:"
|
||||
" fh=0x%"PRIx64";"
|
||||
" lock_owner=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" lock_owner=0x%" PRIx64 ";"
|
||||
"\n"
|
||||
,
|
||||
arg->fh,
|
||||
@@ -589,13 +601,13 @@ static
|
||||
void
|
||||
debug_fuse_release_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_release_in *arg = arg_;
|
||||
const struct fuse_release_in *arg = (const fuse_release_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_release_in:"
|
||||
" fh=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" release_flags=0x%X;"
|
||||
" lock_owner=0x%"PRIx64";"
|
||||
" lock_owner=0x%" PRIx64 ";"
|
||||
" flags=0x%X ("
|
||||
,
|
||||
arg->fh,
|
||||
@@ -610,11 +622,11 @@ static
|
||||
void
|
||||
debug_fuse_fsync_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_fsync_in *arg = arg_;
|
||||
const struct fuse_fsync_in *arg = (const fuse_fsync_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_fsync_in:"
|
||||
" fh=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" fsync_flags=0x%X;"
|
||||
"\n"
|
||||
,
|
||||
@@ -628,7 +640,7 @@ debug_fuse_setxattr_in(const void *arg_)
|
||||
{
|
||||
const char *name;
|
||||
const char *value;
|
||||
const struct fuse_setxattr_in *arg = arg_;
|
||||
const struct fuse_setxattr_in *arg = (const fuse_setxattr_in*)arg_;
|
||||
|
||||
name = PARAM(arg);
|
||||
value = (name + strlen(name) + 1);
|
||||
@@ -652,7 +664,7 @@ void
|
||||
debug_fuse_getxattr_in(const void *arg_)
|
||||
{
|
||||
const char *name;
|
||||
const struct fuse_getxattr_in *arg = arg_;
|
||||
const struct fuse_getxattr_in *arg = (const fuse_getxattr_in*)arg_;
|
||||
|
||||
name = PARAM(arg);
|
||||
|
||||
@@ -670,7 +682,7 @@ static
|
||||
void
|
||||
debug_fuse_listxattr(const void *arg_)
|
||||
{
|
||||
const struct fuse_getxattr_in *arg = arg_;
|
||||
const struct fuse_getxattr_in *arg = (const fuse_getxattr_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_listxattr:"
|
||||
@@ -684,7 +696,7 @@ static
|
||||
void
|
||||
debug_fuse_removexattr(const void *arg_)
|
||||
{
|
||||
const char *name = arg_;
|
||||
const char *name = (const char*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_removexattr:"
|
||||
@@ -698,11 +710,11 @@ static
|
||||
void
|
||||
debug_fuse_fallocate_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_fallocate_in *arg = arg_;
|
||||
const struct fuse_fallocate_in *arg = (const fuse_fallocate_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_fallocate_in:"
|
||||
" fh=0x%"PRIx64";"
|
||||
" fh=0x%" PRIx64 ";"
|
||||
" offset=%zu;"
|
||||
" length=%zu;"
|
||||
" mode=%o;"
|
||||
@@ -717,28 +729,31 @@ debug_fuse_fallocate_in(const void *arg_)
|
||||
void
|
||||
debug_fuse_init_in(const struct fuse_init_in *arg_)
|
||||
{
|
||||
uint64_t flags;
|
||||
|
||||
flags = (((uint64_t)arg_->flags) | ((uint64_t)arg_->flags2) << 32);
|
||||
fprintf(g_OUTPUT,
|
||||
"FUSE_INIT_IN: "
|
||||
" major=%u;"
|
||||
" minor=%u;"
|
||||
" max_readahead=%u;"
|
||||
" flags=0x%08X (",
|
||||
" flags=0x%016lx (",
|
||||
arg_->major,
|
||||
arg_->minor,
|
||||
arg_->max_readahead,
|
||||
arg_->flags);
|
||||
for(uint64_t i = 0; i < (sizeof(arg_->flags)*8); i++)
|
||||
flags);
|
||||
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if(!(arg_->flags & (1ULL << i)))
|
||||
if(!(flags & (1ULL << i)))
|
||||
continue;
|
||||
|
||||
str = fuse_flag_to_str(i);
|
||||
if(str == NULL)
|
||||
continue;
|
||||
|
||||
fprintf(g_OUTPUT,"%s,",str);
|
||||
fprintf(g_OUTPUT,"%s, ",str);
|
||||
}
|
||||
fprintf(g_OUTPUT,")\n");
|
||||
}
|
||||
@@ -748,37 +763,40 @@ debug_fuse_init_out(const uint64_t unique_,
|
||||
const struct fuse_init_out *arg_,
|
||||
const uint64_t argsize_)
|
||||
{
|
||||
uint64_t flags;
|
||||
const struct fuse_init_out *arg = arg_;
|
||||
|
||||
flags = (((uint64_t)arg->flags) | ((uint64_t)arg->flags2) << 32);
|
||||
fprintf(g_OUTPUT,
|
||||
/* "unique=0x%016"PRIx64";" */
|
||||
/* "unique=0x%016" PRIx64 ";" */
|
||||
/* " opcode=RESPONSE;" */
|
||||
/* " error=0 (Success);" */
|
||||
/* " len=%"PRIu64"; || " */
|
||||
/* " len=%" PRIu64 "; || " */
|
||||
"FUSE_INIT_OUT:"
|
||||
" major=%u;"
|
||||
" minor=%u;"
|
||||
" max_readahead=%u;"
|
||||
" flags=0x%08X ("
|
||||
" flags=0x%016lx ("
|
||||
,
|
||||
/* unique_, */
|
||||
/* sizeof(struct fuse_out_header) + argsize_, */
|
||||
arg->major,
|
||||
arg->minor,
|
||||
arg->max_readahead,
|
||||
arg->flags);
|
||||
flags);
|
||||
|
||||
for(uint64_t i = 0; i < (sizeof(arg->flags)*8); i++)
|
||||
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if(!(arg->flags & (1ULL << i)))
|
||||
if(!(flags & (1ULL << i)))
|
||||
continue;
|
||||
|
||||
str = fuse_flag_to_str(i);
|
||||
if(str == NULL)
|
||||
continue;
|
||||
|
||||
fprintf(g_OUTPUT,"%s,",str);
|
||||
fprintf(g_OUTPUT,"%s, ",str);
|
||||
}
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
@@ -803,14 +821,14 @@ debug_fuse_attr(const struct fuse_attr *attr_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"attr:"
|
||||
" ino=0x%016"PRIx64";"
|
||||
" size=%"PRIu64";"
|
||||
" blocks=%"PRIu64";"
|
||||
" atime=%"PRIu64";"
|
||||
" ino=0x%016" PRIx64 ";"
|
||||
" size=%" PRIu64 ";"
|
||||
" blocks=%" PRIu64 ";"
|
||||
" atime=%" PRIu64 ";"
|
||||
" atimensec=%u;"
|
||||
" mtime=%"PRIu64";"
|
||||
" mtime=%" PRIu64 ";"
|
||||
" mtimensec=%u;"
|
||||
" ctime=%"PRIu64";"
|
||||
" ctime=%" PRIu64 ";"
|
||||
" ctimesec=%u;"
|
||||
" mode=%o;"
|
||||
" nlink=%u;"
|
||||
@@ -842,11 +860,11 @@ debug_fuse_entry(const struct fuse_entry_out *entry_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
" fuse_entry_out:"
|
||||
" nodeid=0x%016"PRIx64";"
|
||||
" generation=0x%016"PRIx64";"
|
||||
" entry_valid=%"PRIu64";"
|
||||
" nodeid=0x%016" PRIx64 ";"
|
||||
" generation=0x%016" PRIx64 ";"
|
||||
" entry_valid=%" PRIu64 ";"
|
||||
" entry_valid_nsec=%u;"
|
||||
" attr_valid=%"PRIu64";"
|
||||
" attr_valid=%" PRIu64 ";"
|
||||
" attr_valid_nsec=%u;"
|
||||
" ",
|
||||
entry_->nodeid,
|
||||
@@ -864,10 +882,10 @@ debug_fuse_entry_out(const uint64_t unique_,
|
||||
const uint64_t argsize_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
,
|
||||
unique_,
|
||||
sizeof(struct fuse_out_header) + argsize_);
|
||||
@@ -881,10 +899,10 @@ debug_fuse_attr_out(const uint64_t unique_,
|
||||
const uint64_t argsize_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
"fuse_attr_out:"
|
||||
" attr_valid=%zu;"
|
||||
" attr_valid_nsec=%u;"
|
||||
@@ -929,11 +947,11 @@ static
|
||||
void
|
||||
debug_fuse_interrupt_in(const void *arg_)
|
||||
{
|
||||
const struct fuse_interrupt_in *arg = arg_;
|
||||
const struct fuse_interrupt_in *arg = (const fuse_interrupt_in*)arg_;
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
"fuse_interrupt_in:"
|
||||
" unique=0x%016"PRIx64";"
|
||||
" unique=0x%016" PRIx64 ";"
|
||||
"\n"
|
||||
,
|
||||
arg->unique);
|
||||
@@ -946,53 +964,54 @@ opcode_name(enum fuse_opcode op_)
|
||||
{
|
||||
static const char *names[] =
|
||||
{
|
||||
[FUSE_LOOKUP] = "LOOKUP",
|
||||
[FUSE_FORGET] = "FORGET",
|
||||
[FUSE_GETATTR] = "GETATTR",
|
||||
[FUSE_SETATTR] = "SETATTR",
|
||||
[FUSE_READLINK] = "READLINK",
|
||||
[FUSE_SYMLINK] = "SYMLINK",
|
||||
[FUSE_MKNOD] = "MKNOD",
|
||||
[FUSE_MKDIR] = "MKDIR",
|
||||
[FUSE_UNLINK] = "UNLINK",
|
||||
[FUSE_RMDIR] = "RMDIR",
|
||||
[FUSE_RENAME] = "RENAME",
|
||||
[FUSE_LINK] = "LINK",
|
||||
[FUSE_OPEN] = "OPEN",
|
||||
[FUSE_READ] = "READ",
|
||||
[FUSE_WRITE] = "WRITE",
|
||||
[FUSE_STATFS] = "STATFS",
|
||||
[FUSE_RELEASE] = "RELEASE",
|
||||
[FUSE_FSYNC] = "FSYNC",
|
||||
[FUSE_SETXATTR] = "SETXATTR",
|
||||
[FUSE_GETXATTR] = "GETXATTR",
|
||||
[FUSE_LISTXATTR] = "LISTXATTR",
|
||||
[FUSE_REMOVEXATTR] = "REMOVEXATTR",
|
||||
[FUSE_FLUSH] = "FLUSH",
|
||||
[FUSE_INIT] = "INIT",
|
||||
[FUSE_OPENDIR] = "OPENDIR",
|
||||
[FUSE_READDIR] = "READDIR",
|
||||
[FUSE_RELEASEDIR] = "RELEASEDIR",
|
||||
[FUSE_FSYNCDIR] = "FSYNCDIR",
|
||||
[FUSE_GETLK] = "GETLK",
|
||||
[FUSE_SETLK] = "SETLK",
|
||||
[FUSE_SETLKW] = "SETLKW",
|
||||
[FUSE_ACCESS] = "ACCESS",
|
||||
[FUSE_CREATE] = "CREATE",
|
||||
[FUSE_INTERRUPT] = "INTERRUPT",
|
||||
[FUSE_BMAP] = "BMAP",
|
||||
[FUSE_DESTROY] = "DESTROY",
|
||||
[FUSE_IOCTL] = "IOCTL",
|
||||
[FUSE_POLL] = "POLL",
|
||||
[FUSE_NOTIFY_REPLY] = "NOTIFY_REPLY",
|
||||
[FUSE_BATCH_FORGET] = "BATCH_FORGET",
|
||||
[FUSE_FALLOCATE] = "FALLOCATE",
|
||||
[FUSE_READDIRPLUS] = "READDIRPLUS",
|
||||
[FUSE_RENAME2] = "RENAME2",
|
||||
[FUSE_LSEEK] = "LSEEK",
|
||||
[FUSE_COPY_FILE_RANGE] = "COPY_FILE_RANGE",
|
||||
[FUSE_SETUPMAPPING] = "SETUPMAPPING",
|
||||
[FUSE_REMOVEMAPPING] = "REMOVEMAPPING"
|
||||
"INVALID",
|
||||
"LOOKUP",
|
||||
"FORGET",
|
||||
"GETATTR",
|
||||
"SETATTR",
|
||||
"READLINK",
|
||||
"SYMLINK",
|
||||
"MKNOD",
|
||||
"MKDIR",
|
||||
"UNLINK",
|
||||
"RMDIR",
|
||||
"RENAME",
|
||||
"LINK",
|
||||
"OPEN",
|
||||
"READ",
|
||||
"WRITE",
|
||||
"STATFS",
|
||||
"RELEASE",
|
||||
"FSYNC",
|
||||
"SETXATTR",
|
||||
"GETXATTR",
|
||||
"LISTXATTR",
|
||||
"REMOVEXATTR",
|
||||
"FLUSH",
|
||||
"INIT",
|
||||
"OPENDIR",
|
||||
"READDIR",
|
||||
"RELEASEDIR",
|
||||
"FSYNCDIR",
|
||||
"GETLK",
|
||||
"SETLK",
|
||||
"SETLKW",
|
||||
"ACCESS",
|
||||
"CREATE",
|
||||
"INTERRUPT",
|
||||
"BMAP",
|
||||
"DESTROY",
|
||||
"IOCTL",
|
||||
"POLL",
|
||||
"NOTIFY_REPLY",
|
||||
"BATCH_FORGET",
|
||||
"FALLOCATE",
|
||||
"READDIRPLUS",
|
||||
"RENAME2",
|
||||
"LSEEK",
|
||||
"COPY_FILE_RANGE",
|
||||
"SETUPMAPPING",
|
||||
"REMOVEMAPPING"
|
||||
};
|
||||
|
||||
if(op_ >= (sizeof(names) / sizeof(names[0])))
|
||||
@@ -1007,14 +1026,14 @@ debug_fuse_in_header(const struct fuse_in_header *hdr_)
|
||||
const void *arg = &hdr_[1];
|
||||
|
||||
fprintf(stderr,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=%s (%u);"
|
||||
" nodeid=%zu;"
|
||||
" uid=%u;"
|
||||
" gid=%u;"
|
||||
" pid=%u; || ",
|
||||
hdr_->unique,
|
||||
opcode_name(hdr_->opcode),
|
||||
opcode_name((fuse_opcode)hdr_->opcode),
|
||||
hdr_->opcode,
|
||||
hdr_->nodeid,
|
||||
hdr_->uid,
|
||||
@@ -1027,7 +1046,7 @@ debug_fuse_in_header(const struct fuse_in_header *hdr_)
|
||||
debug_fuse_lookup(arg);
|
||||
break;
|
||||
case FUSE_INIT:
|
||||
debug_fuse_init_in(arg);
|
||||
debug_fuse_init_in((const fuse_init_in*)arg);
|
||||
break;
|
||||
case FUSE_GETATTR:
|
||||
debug_fuse_getattr_in(arg);
|
||||
@@ -1120,10 +1139,10 @@ void
|
||||
debug_fuse_out_header(const struct fuse_out_header *hdr_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=%d (%s);"
|
||||
" len=%"PRIu64";"
|
||||
" len=%" PRIu64 ";"
|
||||
,
|
||||
hdr_->unique,
|
||||
hdr_->error,
|
||||
@@ -1137,10 +1156,10 @@ debug_fuse_entry_open_out(const uint64_t unique_,
|
||||
const struct fuse_open_out *open_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
,
|
||||
unique_,
|
||||
sizeof(struct fuse_entry_out) + sizeof(struct fuse_open_out));
|
||||
@@ -1153,10 +1172,10 @@ debug_fuse_readlink(const uint64_t unique_,
|
||||
const char *linkname_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
"readlink: linkname=%s"
|
||||
"\n"
|
||||
,
|
||||
@@ -1170,10 +1189,10 @@ debug_fuse_write_out(const uint64_t unique_,
|
||||
const struct fuse_write_out *arg_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
" fuse_write_out:"
|
||||
" size=%u"
|
||||
"\n"
|
||||
@@ -1188,16 +1207,16 @@ debug_fuse_statfs_out(const uint64_t unique_,
|
||||
const struct fuse_statfs_out *arg_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
" fuse_statfs_out:"
|
||||
" blocks=%"PRIu64";"
|
||||
" bfree=%"PRIu64";"
|
||||
" bavail=%"PRIu64";"
|
||||
" files=%"PRIu64";"
|
||||
" ffree=%"PRIu64";"
|
||||
" blocks=%" PRIu64 ";"
|
||||
" bfree=%" PRIu64 ";"
|
||||
" bavail=%" PRIu64 ";"
|
||||
" files=%" PRIu64 ";"
|
||||
" ffree=%" PRIu64 ";"
|
||||
" bsize=%u;"
|
||||
" namelen=%u;"
|
||||
" frsize=%u;"
|
||||
@@ -1220,10 +1239,10 @@ debug_fuse_getxattr_out(const uint64_t unique_,
|
||||
const struct fuse_getxattr_out *arg_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
" fuse_getxattr_out:"
|
||||
" size=%u;"
|
||||
"\n"
|
||||
@@ -1239,13 +1258,13 @@ debug_fuse_lk_out(const uint64_t unique_,
|
||||
const struct fuse_lk_out *arg_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
" fuse_file_lock:"
|
||||
" start=%"PRIu64";"
|
||||
" end=%"PRIu64";"
|
||||
" start=%" PRIu64 ";"
|
||||
" end=%" PRIu64 ";"
|
||||
" type=%u;"
|
||||
" pid=%u;"
|
||||
"\n"
|
||||
@@ -1263,12 +1282,12 @@ debug_fuse_bmap_out(const uint64_t unique_,
|
||||
const struct fuse_bmap_out *arg_)
|
||||
{
|
||||
fprintf(g_OUTPUT,
|
||||
"unique=0x%016"PRIx64";"
|
||||
"unique=0x%016" PRIx64 ";"
|
||||
" opcode=RESPONSE;"
|
||||
" error=0 (Success);"
|
||||
" len=%"PRIu64"; || "
|
||||
" len=%" PRIu64 "; || "
|
||||
" fuse_bmap_out:"
|
||||
" block=%"PRIu64";"
|
||||
" block=%" PRIu64 ";"
|
||||
"\n"
|
||||
,
|
||||
unique_,
|
||||
+1
-1
@@ -328,7 +328,7 @@ fmp_gc_slab(fmp_t *fmp_,
|
||||
|
||||
slab_idx_ = (slab_idx_ % kv_size(fmp_->slabs));
|
||||
|
||||
slab = kv_A(fmp_->slabs,slab_idx_);
|
||||
slab = (char*)kv_A(fmp_->slabs,slab_idx_);
|
||||
|
||||
objs_per_slab = fmp_objs_per_slab(fmp_);
|
||||
objs_in_slab = fmp_objs_in_slab(fmp_,slab);
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
*/
|
||||
|
||||
/* For pthread_rwlock_t */
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "crc32b.h"
|
||||
#include "fuse_node.h"
|
||||
@@ -25,6 +27,9 @@
|
||||
#include "fuse_pollhandle.h"
|
||||
#include "fuse_msgbuf.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <assert.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -104,13 +109,6 @@ struct node_table
|
||||
size_t split;
|
||||
};
|
||||
|
||||
#define container_of(ptr,type,member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
#define list_entry(ptr,type,member) \
|
||||
container_of(ptr,type,member)
|
||||
|
||||
struct list_head
|
||||
{
|
||||
struct list_head *next;
|
||||
@@ -218,32 +216,32 @@ fuse_hdr_arg(const struct fuse_in_header *hdr_)
|
||||
|
||||
static
|
||||
void
|
||||
list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
list_add(struct list_head *new_,
|
||||
struct list_head *prev_,
|
||||
struct list_head *next_)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
next_->prev = new_;
|
||||
new_->next = next_;
|
||||
new_->prev = prev_;
|
||||
prev_->next = new_;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
void
|
||||
list_add_head(struct list_head *new,
|
||||
struct list_head *head)
|
||||
list_add_head(struct list_head *new_,
|
||||
struct list_head *head_)
|
||||
{
|
||||
list_add(new,head,head->next);
|
||||
list_add(new_,head_,head_->next);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
void
|
||||
list_add_tail(struct list_head *new,
|
||||
struct list_head *head)
|
||||
list_add_tail(struct list_head *new_,
|
||||
struct list_head *head_)
|
||||
{
|
||||
list_add(new,head->prev,head);
|
||||
list_add(new_,head_->prev,head_);
|
||||
}
|
||||
|
||||
static
|
||||
@@ -384,7 +382,7 @@ node_table_reduce(struct node_table *t)
|
||||
|
||||
newarray = realloc(t->array,sizeof(node_t*) * newsize);
|
||||
if(newarray != NULL)
|
||||
t->array = newarray;
|
||||
t->array = (node_t**)newarray;
|
||||
|
||||
t->size = newsize;
|
||||
t->split = t->size / 2;
|
||||
@@ -450,7 +448,7 @@ node_table_resize(struct node_table *t)
|
||||
if(newarray == NULL)
|
||||
return -1;
|
||||
|
||||
t->array = newarray;
|
||||
t->array = (node_t**)newarray;
|
||||
memset(t->array + t->size,0,t->size * sizeof(node_t*));
|
||||
t->size = newsize;
|
||||
t->split = 0;
|
||||
@@ -795,7 +793,7 @@ add_name(char **buf,
|
||||
newbufsize *= 2;
|
||||
}
|
||||
|
||||
newbuf = realloc(*buf,newbufsize);
|
||||
newbuf = (char*)realloc(*buf,newbufsize);
|
||||
if(newbuf == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -857,7 +855,7 @@ try_get_path(struct fuse *f,
|
||||
*path = NULL;
|
||||
|
||||
err = -ENOMEM;
|
||||
buf = malloc(bufsize);
|
||||
buf = (char*)malloc(bufsize);
|
||||
if(buf == NULL)
|
||||
goto out_err;
|
||||
|
||||
@@ -1375,7 +1373,7 @@ set_path_info(struct fuse *f,
|
||||
return -ENOMEM;
|
||||
|
||||
e->ino = node->nodeid;
|
||||
e->generation = f->nodeid_gen.generation;
|
||||
e->generation = ((e->ino == FUSE_ROOT_ID) ? 0 : f->nodeid_gen.generation);
|
||||
|
||||
pthread_mutex_lock(&f->lock);
|
||||
update_stat(node,&e->attr);
|
||||
@@ -1386,6 +1384,15 @@ set_path_info(struct fuse *f,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
lookup requests only come in for FUSE_ROOT_ID when a "parent of
|
||||
child of root node" request is made. This can happen when using
|
||||
EXPORT_SUPPORT=true and a file handle is used to keep a reference to
|
||||
a node which has been forgotten. Mostly a NFS concern but not
|
||||
excluslively. Root node always has a nodeid of 1 and generation of
|
||||
0. To ensure this set_path_info() explicitly ensures the root id has
|
||||
a generation of 0.
|
||||
*/
|
||||
static
|
||||
int
|
||||
lookup_path(struct fuse *f,
|
||||
@@ -1523,7 +1530,6 @@ fuse_lib_init(void *data,
|
||||
|
||||
memset(c,0,sizeof(*c));
|
||||
c->ctx.fuse = f;
|
||||
conn->want |= FUSE_CAP_EXPORT_SUPPORT;
|
||||
f->fs->op.init(conn);
|
||||
}
|
||||
|
||||
@@ -1554,7 +1560,7 @@ fuse_lib_lookup(fuse_req_t req,
|
||||
node_t *dot = NULL;
|
||||
struct fuse_entry_param e = {0};
|
||||
|
||||
name = fuse_hdr_arg(hdr_);
|
||||
name = (const char*)fuse_hdr_arg(hdr_);
|
||||
nodeid = hdr_->nodeid;
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
@@ -1620,7 +1626,7 @@ fuse_lib_forget(fuse_req_t req,
|
||||
struct fuse_forget_in *arg;
|
||||
|
||||
f = req_fuse(req);
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_forget_in*)fuse_hdr_arg(hdr_);
|
||||
|
||||
forget_node(f,hdr_->nodeid,arg->nlookup);
|
||||
|
||||
@@ -1637,8 +1643,8 @@ fuse_lib_forget_multi(fuse_req_t req,
|
||||
struct fuse_forget_one *entry;
|
||||
|
||||
f = req_fuse(req);
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
entry = PARAM(arg);
|
||||
arg = (fuse_batch_forget_in*)fuse_hdr_arg(hdr_);
|
||||
entry = (fuse_forget_one*)PARAM(arg);
|
||||
|
||||
for(uint32_t i = 0; i < arg->count; i++)
|
||||
{
|
||||
@@ -1665,7 +1671,7 @@ fuse_lib_getattr(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
const struct fuse_getattr_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_getattr_in*)fuse_hdr_arg(hdr_);
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
if(arg->getattr_flags & FUSE_GETATTR_FH)
|
||||
@@ -1727,7 +1733,7 @@ fuse_lib_setattr(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
struct fuse_setattr_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_setattr_in*)fuse_hdr_arg(hdr_);
|
||||
|
||||
fi = NULL;
|
||||
if(arg->valid & FATTR_FH)
|
||||
@@ -1788,12 +1794,12 @@ fuse_lib_setattr(fuse_req_t req,
|
||||
if(arg->valid & FATTR_ATIME_NOW)
|
||||
tv[0].tv_nsec = UTIME_NOW;
|
||||
else if(arg->valid & FATTR_ATIME)
|
||||
tv[0] = (struct timespec){ arg->atime, arg->atimensec };
|
||||
tv[0] = (struct timespec){ static_cast<time_t>(arg->atime), arg->atimensec };
|
||||
|
||||
if(arg->valid & FATTR_MTIME_NOW)
|
||||
tv[1].tv_nsec = UTIME_NOW;
|
||||
else if(arg->valid & FATTR_MTIME)
|
||||
tv[1] = (struct timespec){ arg->mtime, arg->mtimensec };
|
||||
tv[1] = (struct timespec){ static_cast<time_t>(arg->mtime), arg->mtimensec };
|
||||
|
||||
err = ((fi == NULL) ?
|
||||
f->fs->op.utimens(path,tv) :
|
||||
@@ -1845,7 +1851,7 @@ fuse_lib_access(fuse_req_t req,
|
||||
struct fuse *f;
|
||||
struct fuse_access_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_access_in*)fuse_hdr_arg(hdr_);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
@@ -1901,8 +1907,8 @@ fuse_lib_mknod(fuse_req_t req,
|
||||
struct fuse_entry_param e;
|
||||
struct fuse_mknod_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
name = PARAM(arg);
|
||||
arg = (fuse_mknod_in*)fuse_hdr_arg(hdr_);
|
||||
name = (const char*)PARAM(arg);
|
||||
if(req->f->conn.proto_minor >= 12)
|
||||
req->ctx.umask = arg->umask;
|
||||
else
|
||||
@@ -1953,8 +1959,8 @@ fuse_lib_mkdir(fuse_req_t req,
|
||||
struct fuse_entry_param e;
|
||||
struct fuse_mkdir_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
name = PARAM(arg);
|
||||
arg = (fuse_mkdir_in*)fuse_hdr_arg(hdr_);
|
||||
name = (const char*)PARAM(arg);
|
||||
if(req->f->conn.proto_minor >= 12)
|
||||
req->ctx.umask = arg->umask;
|
||||
|
||||
@@ -1983,7 +1989,7 @@ fuse_lib_unlink(fuse_req_t req,
|
||||
const char *name;
|
||||
node_t *wnode;
|
||||
|
||||
name = PARAM(hdr_);
|
||||
name = (const char*)PARAM(hdr_);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
err = get_path_wrlock(f,hdr_->nodeid,name,&path,&wnode);
|
||||
@@ -2016,7 +2022,7 @@ fuse_lib_rmdir(fuse_req_t req,
|
||||
const char *name;
|
||||
node_t *wnode;
|
||||
|
||||
name = PARAM(hdr_);
|
||||
name = (const char*)PARAM(hdr_);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
@@ -2044,7 +2050,7 @@ fuse_lib_symlink(fuse_req_t req_,
|
||||
const char *linkname;
|
||||
struct fuse_entry_param e = {0};
|
||||
|
||||
name = fuse_hdr_arg(hdr_);
|
||||
name = (const char*)fuse_hdr_arg(hdr_);
|
||||
linkname = (name + strlen(name) + 1);
|
||||
|
||||
f = req_fuse_prepare(req_);
|
||||
@@ -2076,8 +2082,8 @@ fuse_lib_rename(fuse_req_t req,
|
||||
node_t *wnode2;
|
||||
struct fuse_rename_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
oldname = PARAM(arg);
|
||||
arg = (fuse_rename_in*)fuse_hdr_arg(hdr_);
|
||||
oldname = (const char*)PARAM(arg);
|
||||
newname = (oldname + strlen(oldname) + 1);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
@@ -2114,8 +2120,8 @@ fuse_lib_link(fuse_req_t req,
|
||||
struct fuse_link_in *arg;
|
||||
struct fuse_entry_param e = {0};
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
newname = PARAM(arg);
|
||||
arg = (fuse_link_in*)fuse_hdr_arg(hdr_);
|
||||
newname = (const char*)PARAM(arg);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
@@ -2178,8 +2184,8 @@ fuse_lib_create(fuse_req_t req,
|
||||
struct fuse_entry_param e;
|
||||
struct fuse_create_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
name = PARAM(arg);
|
||||
arg = (fuse_create_in*)fuse_hdr_arg(hdr_);
|
||||
name = (const char*)PARAM(arg);
|
||||
|
||||
ffi.flags = arg->flags;
|
||||
|
||||
@@ -2279,7 +2285,7 @@ fuse_lib_open(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
struct fuse_open_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_open_in*)fuse_hdr_arg(hdr_);
|
||||
|
||||
ffi.flags = arg->flags;
|
||||
|
||||
@@ -2324,7 +2330,7 @@ fuse_lib_read(fuse_req_t req,
|
||||
struct fuse_read_in *arg;
|
||||
fuse_msgbuf_t *msgbuf;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_read_in*)fuse_hdr_arg(hdr_);
|
||||
ffi.fh = arg->fh;
|
||||
if(req->f->conn.proto_minor >= 9)
|
||||
{
|
||||
@@ -2357,7 +2363,7 @@ fuse_lib_write(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
struct fuse_write_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_write_in*)fuse_hdr_arg(hdr_);
|
||||
ffi.fh = arg->fh;
|
||||
ffi.writepage = !!(arg->write_flags & 1);
|
||||
if(req->f->conn.proto_minor < 9)
|
||||
@@ -2368,7 +2374,7 @@ fuse_lib_write(fuse_req_t req,
|
||||
{
|
||||
ffi.flags = arg->flags;
|
||||
ffi.lock_owner = arg->lock_owner;
|
||||
data = PARAM(arg);
|
||||
data = (char*)PARAM(arg);
|
||||
}
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
@@ -2392,7 +2398,7 @@ fuse_lib_fsync(fuse_req_t req,
|
||||
struct fuse_fsync_in *arg;
|
||||
fuse_file_info_t ffi = {0};
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_);
|
||||
ffi.fh = arg->fh;
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
@@ -2427,7 +2433,7 @@ fuse_lib_opendir(fuse_req_t req,
|
||||
struct fuse *f;
|
||||
struct fuse_open_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_open_in*)fuse_hdr_arg(hdr_);
|
||||
llffi.flags = arg->flags;
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
@@ -2514,7 +2520,7 @@ fuse_lib_readdir(fuse_req_t req_,
|
||||
fuse_file_info_t llffi = {0};
|
||||
struct fuse_read_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_read_in*)fuse_hdr_arg(hdr_);
|
||||
size = arg->size;
|
||||
llffi.fh = arg->fh;
|
||||
|
||||
@@ -2558,7 +2564,7 @@ fuse_lib_readdir_plus(fuse_req_t req_,
|
||||
fuse_file_info_t llffi = {0};
|
||||
struct fuse_read_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_read_in*)fuse_hdr_arg(hdr_);
|
||||
size = arg->size;
|
||||
llffi.fh = arg->fh;
|
||||
|
||||
@@ -2599,7 +2605,7 @@ fuse_lib_releasedir(fuse_req_t req_,
|
||||
fuse_file_info_t llffi = {0};
|
||||
struct fuse_release_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_release_in*)fuse_hdr_arg(hdr_);
|
||||
llffi.fh = arg->fh;
|
||||
llffi.flags = arg->flags;
|
||||
|
||||
@@ -2628,7 +2634,7 @@ fuse_lib_fsyncdir(fuse_req_t req,
|
||||
fuse_file_info_t llffi = {0};
|
||||
struct fuse_fsync_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_);
|
||||
llffi.fh = arg->fh;
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
@@ -2680,9 +2686,9 @@ fuse_lib_setxattr(fuse_req_t req,
|
||||
struct fuse *f;
|
||||
struct fuse_setxattr_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_setxattr_in*)fuse_hdr_arg(hdr_);
|
||||
if((req->f->conn.capable & FUSE_SETXATTR_EXT) && (req->f->conn.want & FUSE_SETXATTR_EXT))
|
||||
name = PARAM(arg);
|
||||
name = (const char*)PARAM(arg);
|
||||
else
|
||||
name = (((char*)arg) + FUSE_COMPAT_SETXATTR_IN_SIZE);
|
||||
|
||||
@@ -2733,8 +2739,8 @@ fuse_lib_getxattr(fuse_req_t req,
|
||||
const char* name;
|
||||
struct fuse_getxattr_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
name = PARAM(arg);
|
||||
arg = (fuse_getxattr_in*)fuse_hdr_arg(hdr_);
|
||||
name = (const char*)PARAM(arg);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
@@ -2794,7 +2800,7 @@ fuse_lib_listxattr(fuse_req_t req,
|
||||
struct fuse *f;
|
||||
struct fuse_getxattr_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_getxattr_in*)fuse_hdr_arg(hdr_);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
@@ -2834,7 +2840,7 @@ fuse_lib_removexattr(fuse_req_t req,
|
||||
const char *name;
|
||||
struct fuse *f;
|
||||
|
||||
name = fuse_hdr_arg(hdr_);
|
||||
name = (const char*)fuse_hdr_arg(hdr_);
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
|
||||
@@ -2859,7 +2865,7 @@ fuse_lib_copy_file_range(fuse_req_t req_,
|
||||
fuse_file_info_t ffi_out = {0};
|
||||
const struct fuse_copy_file_range_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_copy_file_range_in*)fuse_hdr_arg(hdr_);
|
||||
ffi_in.fh = arg->fh_in;
|
||||
ffi_out.fh = arg->fh_out;
|
||||
|
||||
@@ -2919,8 +2925,8 @@ fuse_lib_tmpfile(fuse_req_t req_,
|
||||
struct fuse_entry_param e;
|
||||
struct fuse_create_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
name = PARAM(arg);
|
||||
arg = (fuse_create_in*)fuse_hdr_arg(hdr_);
|
||||
name = (const char*)PARAM(arg);
|
||||
|
||||
ffi.flags = arg->flags;
|
||||
|
||||
@@ -3018,8 +3024,8 @@ locks_insert(node_t *node,
|
||||
|
||||
if(lock->type != F_UNLCK || lock->start != 0 || lock->end != OFFSET_MAX)
|
||||
{
|
||||
newl1 = malloc(sizeof(lock_t));
|
||||
newl2 = malloc(sizeof(lock_t));
|
||||
newl1 = (lock_t*)malloc(sizeof(lock_t));
|
||||
newl2 = (lock_t*)malloc(sizeof(lock_t));
|
||||
|
||||
if(!newl1 || !newl2)
|
||||
{
|
||||
@@ -3047,7 +3053,7 @@ locks_insert(node_t *node,
|
||||
lock->start = l->start;
|
||||
if(lock->end < l->end)
|
||||
lock->end = l->end;
|
||||
goto delete;
|
||||
goto delete_lock;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3056,7 +3062,7 @@ locks_insert(node_t *node,
|
||||
if(lock->end < l->start)
|
||||
break;
|
||||
if(lock->start <= l->start && l->end <= lock->end)
|
||||
goto delete;
|
||||
goto delete_lock;
|
||||
if(l->end <= lock->end)
|
||||
{
|
||||
l->end = lock->start - 1;
|
||||
@@ -3077,7 +3083,7 @@ locks_insert(node_t *node,
|
||||
lp = &l->next;
|
||||
continue;
|
||||
|
||||
delete:
|
||||
delete_lock:
|
||||
delete_lock(lp);
|
||||
}
|
||||
if(lock->type != F_UNLCK)
|
||||
@@ -3160,7 +3166,7 @@ fuse_lib_release(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
struct fuse_release_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_release_in*)fuse_hdr_arg(hdr_);
|
||||
ffi.fh = arg->fh;
|
||||
ffi.flags = arg->flags;
|
||||
if(req->f->conn.proto_minor >= 8)
|
||||
@@ -3198,7 +3204,7 @@ fuse_lib_flush(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
struct fuse_flush_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_flush_in*)fuse_hdr_arg(hdr_);
|
||||
|
||||
ffi.fh = arg->fh;
|
||||
ffi.flush = 1;
|
||||
@@ -3257,7 +3263,7 @@ fuse_lib_getlk(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
const struct fuse_lk_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_lk_in*)fuse_hdr_arg(hdr_);
|
||||
ffi.fh = arg->fh;
|
||||
ffi.lock_owner = arg->owner;
|
||||
|
||||
@@ -3333,7 +3339,7 @@ fuse_lib_bmap(fuse_req_t req,
|
||||
uint64_t block;
|
||||
const struct fuse_bmap_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_bmap_in*)fuse_hdr_arg(hdr_);
|
||||
block = arg->block;
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
@@ -3365,7 +3371,7 @@ fuse_lib_ioctl(fuse_req_t req,
|
||||
uint32_t out_size;
|
||||
const struct fuse_ioctl_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_ioctl_in*)fuse_hdr_arg(hdr_);
|
||||
if((arg->flags & FUSE_IOCTL_DIR) && !(req->f->conn.want & FUSE_CAP_IOCTL_DIR))
|
||||
{
|
||||
fuse_reply_err(req,ENOTTY);
|
||||
@@ -3395,7 +3401,7 @@ fuse_lib_ioctl(fuse_req_t req,
|
||||
if(out_size)
|
||||
{
|
||||
err = -ENOMEM;
|
||||
out_buf = malloc(out_size);
|
||||
out_buf = (char*)malloc(out_size);
|
||||
if(!out_buf)
|
||||
goto err;
|
||||
}
|
||||
@@ -3433,7 +3439,7 @@ fuse_lib_poll(fuse_req_t req,
|
||||
fuse_pollhandle_t *ph = NULL;
|
||||
const struct fuse_poll_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_poll_in*)fuse_hdr_arg(hdr_);
|
||||
ffi.fh = arg->fh;
|
||||
|
||||
if(arg->flags & FUSE_POLL_SCHEDULE_NOTIFY)
|
||||
@@ -3468,7 +3474,7 @@ fuse_lib_fallocate(fuse_req_t req,
|
||||
fuse_file_info_t ffi = {0};
|
||||
const struct fuse_fallocate_in *arg;
|
||||
|
||||
arg = fuse_hdr_arg(hdr_);
|
||||
arg = (fuse_fallocate_in*)fuse_hdr_arg(hdr_);
|
||||
ffi.fh = arg->fh;
|
||||
|
||||
f = req_fuse_prepare(req);
|
||||
@@ -3486,8 +3492,8 @@ int
|
||||
remembered_node_cmp(const void *a_,
|
||||
const void *b_)
|
||||
{
|
||||
const remembered_node_t *a = a_;
|
||||
const remembered_node_t *b = b_;
|
||||
const remembered_node_t *a = (const remembered_node_t*)a_;
|
||||
const remembered_node_t *b = (const remembered_node_t*)b_;
|
||||
|
||||
return (a->time - b->time);
|
||||
}
|
||||
@@ -3822,21 +3828,21 @@ metrics_log_nodes_info(struct fuse *f_,
|
||||
|
||||
snprintf(buf,sizeof(buf),
|
||||
"time: %s\n"
|
||||
"sizeof(node): %"PRIu64"\n"
|
||||
"node id_table size: %"PRIu64"\n"
|
||||
"node id_table usage: %"PRIu64"\n"
|
||||
"node id_table total allocated memory: %"PRIu64"\n"
|
||||
"node name_table size: %"PRIu64"\n"
|
||||
"node name_table usage: %"PRIu64"\n"
|
||||
"node name_table total allocated memory: %"PRIu64"\n"
|
||||
"node memory pool slab count: %"PRIu64"\n"
|
||||
"sizeof(node): %" PRIu64 "\n"
|
||||
"node id_table size: %" PRIu64 "\n"
|
||||
"node id_table usage: %" PRIu64 "\n"
|
||||
"node id_table total allocated memory: %" PRIu64 "\n"
|
||||
"node name_table size: %" PRIu64 "\n"
|
||||
"node name_table usage: %" PRIu64 "\n"
|
||||
"node name_table total allocated memory: %" PRIu64 "\n"
|
||||
"node memory pool slab count: %" PRIu64 "\n"
|
||||
"node memory pool usage ratio: %f\n"
|
||||
"node memory pool avail objs: %"PRIu64"\n"
|
||||
"node memory pool total allocated memory: %"PRIu64"\n"
|
||||
"msgbuf bufsize: %"PRIu64"\n"
|
||||
"msgbuf allocation count: %"PRIu64"\n"
|
||||
"msgbuf available count: %"PRIu64"\n"
|
||||
"msgbuf total allocated memory: %"PRIu64"\n"
|
||||
"node memory pool avail objs: %" PRIu64 "\n"
|
||||
"node memory pool total allocated memory: %" PRIu64 "\n"
|
||||
"msgbuf bufsize: %" PRIu64 "\n"
|
||||
"msgbuf allocation count: %" PRIu64 "\n"
|
||||
"msgbuf available count: %" PRIu64 "\n"
|
||||
"msgbuf total allocated memory: %" PRIu64 "\n"
|
||||
"\n"
|
||||
,
|
||||
time_str,
|
||||
@@ -3899,11 +3905,10 @@ void
|
||||
fuse_invalidate_all_nodes()
|
||||
{
|
||||
struct fuse *f = fuse_get_fuse_obj();
|
||||
|
||||
syslog(LOG_INFO,"invalidating file entries");
|
||||
std::vector<std::string> names;
|
||||
|
||||
pthread_mutex_lock(&f->lock);
|
||||
for(int i = 0; i < f->id_table.size; i++)
|
||||
for(size_t i = 0; i < f->id_table.size; i++)
|
||||
{
|
||||
node_t *node;
|
||||
|
||||
@@ -3911,16 +3916,28 @@ fuse_invalidate_all_nodes()
|
||||
{
|
||||
if(node->nodeid == FUSE_ROOT_ID)
|
||||
continue;
|
||||
if(node->name == NULL)
|
||||
continue;
|
||||
if(node->parent == NULL)
|
||||
continue;
|
||||
if(node->parent->nodeid != FUSE_ROOT_ID)
|
||||
continue;
|
||||
|
||||
fuse_lowlevel_notify_inval_entry(f->se->ch,
|
||||
node->parent->nodeid,
|
||||
node->name,
|
||||
strlen(node->name));
|
||||
names.emplace_back(node->name);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&f->lock);
|
||||
|
||||
syslog(LOG_INFO,
|
||||
"invalidating %ld file entries",
|
||||
names.size());
|
||||
for(auto &name : names)
|
||||
{
|
||||
fuse_lowlevel_notify_inval_entry(f->se->ch,
|
||||
FUSE_ROOT_ID,
|
||||
name.c_str(),
|
||||
name.size());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -6,12 +6,14 @@
|
||||
See the file COPYING.LIB
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "lfmp.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "debug.hpp"
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_kernel.h"
|
||||
#include "fuse_opt.h"
|
||||
@@ -41,7 +43,7 @@
|
||||
#define OFFSET_MAX 0x7fffffffffffffffLL
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type*)0)->member ) *__mptr = (ptr); \
|
||||
const decltype( ((type*)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char*)__mptr - offsetof(type,member) );})
|
||||
|
||||
static size_t pagesize;
|
||||
@@ -135,7 +137,7 @@ fuse_send_msg(struct fuse_ll *f,
|
||||
int count)
|
||||
{
|
||||
int rv;
|
||||
struct fuse_out_header *out = iov[0].iov_base;
|
||||
struct fuse_out_header *out = (fuse_out_header*)iov[0].iov_base;
|
||||
|
||||
out->len = iov_length(iov, count);
|
||||
|
||||
@@ -294,6 +296,11 @@ fuse_reply_entry(fuse_req_t req,
|
||||
|
||||
fill_entry(&arg, e);
|
||||
|
||||
#ifdef NDEBUG
|
||||
// TODO: Add checks for cases where a node could be marked bad by
|
||||
// the kernel.
|
||||
#endif
|
||||
|
||||
return send_reply_ok(req, &arg, size);
|
||||
}
|
||||
|
||||
@@ -405,7 +412,7 @@ fuse_send_data_iov_fallback(struct fuse_ll *f,
|
||||
return -ENOMEM;
|
||||
|
||||
mem_buf.buf[0].mem = msgbuf->mem;
|
||||
res = fuse_buf_copy(&mem_buf, buf, 0);
|
||||
res = fuse_buf_copy(&mem_buf, buf, (fuse_buf_copy_flags)0);
|
||||
if(res < 0)
|
||||
{
|
||||
msgbuf_free(msgbuf);
|
||||
@@ -545,7 +552,7 @@ fuse_ioctl_iovec_copy(const struct iovec *iov,
|
||||
struct fuse_ioctl_iovec *fiov;
|
||||
size_t i;
|
||||
|
||||
fiov = malloc(sizeof(fiov[0]) * count);
|
||||
fiov = (fuse_ioctl_iovec*)malloc(sizeof(fiov[0]) * count);
|
||||
if(!fiov)
|
||||
return NULL;
|
||||
|
||||
@@ -678,7 +685,7 @@ fuse_reply_ioctl_iov(fuse_req_t req,
|
||||
struct fuse_ioctl_out arg = {0};
|
||||
int res;
|
||||
|
||||
padded_iov = malloc((count + 2) * sizeof(struct iovec));
|
||||
padded_iov = (iovec*)malloc((count + 2) * sizeof(struct iovec));
|
||||
if(padded_iov == NULL)
|
||||
return fuse_reply_err(req, ENOMEM);
|
||||
|
||||
@@ -891,8 +898,8 @@ do_readdir(fuse_req_t req,
|
||||
|
||||
static
|
||||
void
|
||||
do_readdir_plus(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
do_readdirplus(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
req_->f->op.readdir_plus(req_,hdr_);
|
||||
}
|
||||
@@ -1092,6 +1099,11 @@ do_init(fuse_req_t req,
|
||||
struct fuse_init_in *arg = (struct fuse_init_in *) &hdr_[1];
|
||||
struct fuse_ll *f = req->f;
|
||||
size_t bufsize = fuse_chan_bufsize(req->ch);
|
||||
uint64_t inargflags;
|
||||
uint64_t outargflags;
|
||||
|
||||
inargflags = 0;
|
||||
outargflags = 0;
|
||||
|
||||
if(f->debug)
|
||||
debug_fuse_init_in(arg);
|
||||
@@ -1122,40 +1134,49 @@ do_init(fuse_req_t req,
|
||||
|
||||
if(arg->minor >= 6)
|
||||
{
|
||||
inargflags = arg->flags;
|
||||
if(inargflags & FUSE_INIT_EXT)
|
||||
inargflags |= (((uint64_t)arg->flags2) << 32);
|
||||
|
||||
if(arg->max_readahead < f->conn.max_readahead)
|
||||
f->conn.max_readahead = arg->max_readahead;
|
||||
if(arg->flags & FUSE_ASYNC_READ)
|
||||
|
||||
if(inargflags & FUSE_ASYNC_READ)
|
||||
f->conn.capable |= FUSE_CAP_ASYNC_READ;
|
||||
if(arg->flags & FUSE_POSIX_LOCKS)
|
||||
if(inargflags & FUSE_POSIX_LOCKS)
|
||||
f->conn.capable |= FUSE_CAP_POSIX_LOCKS;
|
||||
if(arg->flags & FUSE_ATOMIC_O_TRUNC)
|
||||
if(inargflags & FUSE_ATOMIC_O_TRUNC)
|
||||
f->conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC;
|
||||
if(arg->flags & FUSE_EXPORT_SUPPORT)
|
||||
if(inargflags & FUSE_EXPORT_SUPPORT)
|
||||
f->conn.capable |= FUSE_CAP_EXPORT_SUPPORT;
|
||||
if(arg->flags & FUSE_BIG_WRITES)
|
||||
if(inargflags & FUSE_BIG_WRITES)
|
||||
f->conn.capable |= FUSE_CAP_BIG_WRITES;
|
||||
if(arg->flags & FUSE_DONT_MASK)
|
||||
if(inargflags & FUSE_DONT_MASK)
|
||||
f->conn.capable |= FUSE_CAP_DONT_MASK;
|
||||
if(arg->flags & FUSE_FLOCK_LOCKS)
|
||||
if(inargflags & FUSE_FLOCK_LOCKS)
|
||||
f->conn.capable |= FUSE_CAP_FLOCK_LOCKS;
|
||||
if(arg->flags & FUSE_POSIX_ACL)
|
||||
if(inargflags & FUSE_POSIX_ACL)
|
||||
f->conn.capable |= FUSE_CAP_POSIX_ACL;
|
||||
if(arg->flags & FUSE_CACHE_SYMLINKS)
|
||||
if(inargflags & FUSE_CACHE_SYMLINKS)
|
||||
f->conn.capable |= FUSE_CAP_CACHE_SYMLINKS;
|
||||
if(arg->flags & FUSE_ASYNC_DIO)
|
||||
if(inargflags & FUSE_ASYNC_DIO)
|
||||
f->conn.capable |= FUSE_CAP_ASYNC_DIO;
|
||||
if(arg->flags & FUSE_PARALLEL_DIROPS)
|
||||
if(inargflags & FUSE_PARALLEL_DIROPS)
|
||||
f->conn.capable |= FUSE_CAP_PARALLEL_DIROPS;
|
||||
if(arg->flags & FUSE_MAX_PAGES)
|
||||
if(inargflags & FUSE_MAX_PAGES)
|
||||
f->conn.capable |= FUSE_CAP_MAX_PAGES;
|
||||
if(arg->flags & FUSE_WRITEBACK_CACHE)
|
||||
if(inargflags & FUSE_WRITEBACK_CACHE)
|
||||
f->conn.capable |= FUSE_CAP_WRITEBACK_CACHE;
|
||||
if(arg->flags & FUSE_DO_READDIRPLUS)
|
||||
if(inargflags & FUSE_DO_READDIRPLUS)
|
||||
f->conn.capable |= FUSE_CAP_READDIR_PLUS;
|
||||
if(arg->flags & FUSE_READDIRPLUS_AUTO)
|
||||
if(inargflags & FUSE_READDIRPLUS_AUTO)
|
||||
f->conn.capable |= FUSE_CAP_READDIR_PLUS_AUTO;
|
||||
if(arg->flags & FUSE_SETXATTR_EXT)
|
||||
if(inargflags & FUSE_SETXATTR_EXT)
|
||||
f->conn.capable |= FUSE_CAP_SETXATTR_EXT;
|
||||
if(inargflags & FUSE_DIRECT_IO_ALLOW_MMAP)
|
||||
f->conn.capable |= FUSE_CAP_DIRECT_IO_ALLOW_MMAP;
|
||||
if(inargflags & FUSE_CREATE_SUPP_GROUP)
|
||||
f->conn.capable |= FUSE_CAP_CREATE_SUPP_GROUP;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1186,44 +1207,57 @@ do_init(fuse_req_t req,
|
||||
if(f->op.init)
|
||||
f->op.init(f->userdata, &f->conn);
|
||||
|
||||
if((arg->flags & FUSE_MAX_PAGES) && (f->conn.want & FUSE_CAP_MAX_PAGES))
|
||||
outargflags = outarg.flags;
|
||||
if((inargflags & FUSE_MAX_PAGES) && (f->conn.want & FUSE_CAP_MAX_PAGES))
|
||||
{
|
||||
outarg.flags |= FUSE_MAX_PAGES;
|
||||
outargflags |= FUSE_MAX_PAGES;
|
||||
outarg.max_pages = f->conn.max_pages;
|
||||
|
||||
msgbuf_set_bufsize(outarg.max_pages + 1);
|
||||
}
|
||||
|
||||
if(f->conn.want & FUSE_CAP_ASYNC_READ)
|
||||
outarg.flags |= FUSE_ASYNC_READ;
|
||||
outargflags |= FUSE_ASYNC_READ;
|
||||
if(f->conn.want & FUSE_CAP_POSIX_LOCKS)
|
||||
outarg.flags |= FUSE_POSIX_LOCKS;
|
||||
outargflags |= FUSE_POSIX_LOCKS;
|
||||
if(f->conn.want & FUSE_CAP_ATOMIC_O_TRUNC)
|
||||
outarg.flags |= FUSE_ATOMIC_O_TRUNC;
|
||||
outargflags |= FUSE_ATOMIC_O_TRUNC;
|
||||
if(f->conn.want & FUSE_CAP_EXPORT_SUPPORT)
|
||||
outarg.flags |= FUSE_EXPORT_SUPPORT;
|
||||
outargflags |= FUSE_EXPORT_SUPPORT;
|
||||
if(f->conn.want & FUSE_CAP_BIG_WRITES)
|
||||
outarg.flags |= FUSE_BIG_WRITES;
|
||||
outargflags |= FUSE_BIG_WRITES;
|
||||
if(f->conn.want & FUSE_CAP_DONT_MASK)
|
||||
outarg.flags |= FUSE_DONT_MASK;
|
||||
outargflags |= FUSE_DONT_MASK;
|
||||
if(f->conn.want & FUSE_CAP_FLOCK_LOCKS)
|
||||
outarg.flags |= FUSE_FLOCK_LOCKS;
|
||||
outargflags |= FUSE_FLOCK_LOCKS;
|
||||
if(f->conn.want & FUSE_CAP_POSIX_ACL)
|
||||
outarg.flags |= FUSE_POSIX_ACL;
|
||||
outargflags |= FUSE_POSIX_ACL;
|
||||
if(f->conn.want & FUSE_CAP_CACHE_SYMLINKS)
|
||||
outarg.flags |= FUSE_CACHE_SYMLINKS;
|
||||
outargflags |= FUSE_CACHE_SYMLINKS;
|
||||
if(f->conn.want & FUSE_CAP_ASYNC_DIO)
|
||||
outarg.flags |= FUSE_ASYNC_DIO;
|
||||
outargflags |= FUSE_ASYNC_DIO;
|
||||
if(f->conn.want & FUSE_CAP_PARALLEL_DIROPS)
|
||||
outarg.flags |= FUSE_PARALLEL_DIROPS;
|
||||
outargflags |= FUSE_PARALLEL_DIROPS;
|
||||
if(f->conn.want & FUSE_CAP_WRITEBACK_CACHE)
|
||||
outarg.flags |= FUSE_WRITEBACK_CACHE;
|
||||
outargflags |= FUSE_WRITEBACK_CACHE;
|
||||
if(f->conn.want & FUSE_CAP_READDIR_PLUS)
|
||||
outarg.flags |= FUSE_DO_READDIRPLUS;
|
||||
outargflags |= FUSE_DO_READDIRPLUS;
|
||||
if(f->conn.want & FUSE_CAP_READDIR_PLUS_AUTO)
|
||||
outarg.flags |= FUSE_READDIRPLUS_AUTO;
|
||||
outargflags |= FUSE_READDIRPLUS_AUTO;
|
||||
if(f->conn.want & FUSE_CAP_SETXATTR_EXT)
|
||||
outarg.flags |= FUSE_SETXATTR_EXT;
|
||||
outargflags |= FUSE_SETXATTR_EXT;
|
||||
if(f->conn.want & FUSE_CAP_CREATE_SUPP_GROUP)
|
||||
outargflags |= FUSE_CREATE_SUPP_GROUP;
|
||||
if(f->conn.want & FUSE_CAP_DIRECT_IO_ALLOW_MMAP)
|
||||
outargflags |= FUSE_DIRECT_IO_ALLOW_MMAP;
|
||||
|
||||
if(inargflags & FUSE_INIT_EXT)
|
||||
{
|
||||
outargflags |= FUSE_INIT_EXT;
|
||||
outarg.flags2 = (outargflags >> 32);
|
||||
}
|
||||
|
||||
outarg.flags = outargflags;
|
||||
|
||||
outarg.max_readahead = f->conn.max_readahead;
|
||||
outarg.max_write = f->conn.max_write;
|
||||
@@ -1242,6 +1276,9 @@ do_init(fuse_req_t req,
|
||||
outarg.congestion_threshold = f->conn.congestion_threshold;
|
||||
}
|
||||
|
||||
if(f->conn.proto_minor >= 23)
|
||||
outarg.time_gran = 1;
|
||||
|
||||
size_t outargsize;
|
||||
if(arg->minor < 5)
|
||||
outargsize = FUSE_COMPAT_INIT_OUT_SIZE;
|
||||
@@ -1337,7 +1374,6 @@ void
|
||||
do_setupmapping(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("setupmapping\n");
|
||||
req_->f->op.setupmapping(req_,hdr_);
|
||||
}
|
||||
|
||||
@@ -1346,7 +1382,6 @@ void
|
||||
do_removemapping(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("removemapping\n");
|
||||
req_->f->op.removemapping(req_,hdr_);
|
||||
}
|
||||
|
||||
@@ -1355,7 +1390,6 @@ void
|
||||
do_syncfs(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("syncfs\n");
|
||||
req_->f->op.syncfs(req_,hdr_);
|
||||
}
|
||||
|
||||
@@ -1364,10 +1398,33 @@ void
|
||||
do_tmpfile(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("tmpfile\n");
|
||||
req_->f->op.tmpfile(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_statx(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
req_->f->op.statx(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_rename2(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
req_->f->op.rename2(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_lseek(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
req_->f->op.lseek(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
send_notify_iov(struct fuse_ll *f,
|
||||
@@ -1589,7 +1646,7 @@ fuse_lowlevel_notify_retrieve(struct fuse_chan *ch,
|
||||
if(f->conn.proto_minor < 15)
|
||||
return -ENOSYS;
|
||||
|
||||
rreq = malloc(sizeof(*rreq));
|
||||
rreq = (fuse_retrieve_req*)malloc(sizeof(*rreq));
|
||||
if(rreq == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1633,61 +1690,69 @@ fuse_req_ctx(fuse_req_t req)
|
||||
return &req->ctx;
|
||||
}
|
||||
|
||||
static struct {
|
||||
void (*func)(fuse_req_t, struct fuse_in_header *);
|
||||
const char *name;
|
||||
} fuse_ll_ops[] =
|
||||
#define FUSE_OPCODE_LEN (FUSE_STATX + 1)
|
||||
|
||||
typedef void (*fuse_ll_func)(fuse_req_t, struct fuse_in_header *);
|
||||
const
|
||||
fuse_ll_func
|
||||
fuse_ll_funcs[FUSE_OPCODE_LEN] =
|
||||
{
|
||||
[FUSE_LOOKUP] = { do_lookup, "LOOKUP" },
|
||||
[FUSE_FORGET] = { do_forget, "FORGET" },
|
||||
[FUSE_GETATTR] = { do_getattr, "GETATTR" },
|
||||
[FUSE_SETATTR] = { do_setattr, "SETATTR" },
|
||||
[FUSE_READLINK] = { do_readlink, "READLINK" },
|
||||
[FUSE_SYMLINK] = { do_symlink, "SYMLINK" },
|
||||
[FUSE_MKNOD] = { do_mknod, "MKNOD" },
|
||||
[FUSE_MKDIR] = { do_mkdir, "MKDIR" },
|
||||
[FUSE_UNLINK] = { do_unlink, "UNLINK" },
|
||||
[FUSE_RMDIR] = { do_rmdir, "RMDIR" },
|
||||
[FUSE_RENAME] = { do_rename, "RENAME" },
|
||||
[FUSE_LINK] = { do_link, "LINK" },
|
||||
[FUSE_OPEN] = { do_open, "OPEN" },
|
||||
[FUSE_READ] = { do_read, "READ" },
|
||||
[FUSE_WRITE] = { do_write, "WRITE" },
|
||||
[FUSE_STATFS] = { do_statfs, "STATFS" },
|
||||
[FUSE_RELEASE] = { do_release, "RELEASE" },
|
||||
[FUSE_FSYNC] = { do_fsync, "FSYNC" },
|
||||
[FUSE_SETXATTR] = { do_setxattr, "SETXATTR" },
|
||||
[FUSE_GETXATTR] = { do_getxattr, "GETXATTR" },
|
||||
[FUSE_LISTXATTR] = { do_listxattr, "LISTXATTR" },
|
||||
[FUSE_REMOVEXATTR] = { do_removexattr, "REMOVEXATTR" },
|
||||
[FUSE_FLUSH] = { do_flush, "FLUSH" },
|
||||
[FUSE_INIT] = { do_init, "INIT" },
|
||||
[FUSE_OPENDIR] = { do_opendir, "OPENDIR" },
|
||||
[FUSE_READDIR] = { do_readdir, "READDIR" },
|
||||
[FUSE_READDIRPLUS] = { do_readdir_plus, "READDIR_PLUS" },
|
||||
[FUSE_RELEASEDIR] = { do_releasedir, "RELEASEDIR" },
|
||||
[FUSE_FSYNCDIR] = { do_fsyncdir, "FSYNCDIR" },
|
||||
[FUSE_GETLK] = { do_getlk, "GETLK" },
|
||||
[FUSE_SETLK] = { do_setlk, "SETLK" },
|
||||
[FUSE_SETLKW] = { do_setlkw, "SETLKW" },
|
||||
[FUSE_ACCESS] = { do_access, "ACCESS" },
|
||||
[FUSE_CREATE] = { do_create, "CREATE" },
|
||||
[FUSE_INTERRUPT] = { do_interrupt, "INTERRUPT" },
|
||||
[FUSE_BMAP] = { do_bmap, "BMAP" },
|
||||
[FUSE_IOCTL] = { do_ioctl, "IOCTL" },
|
||||
[FUSE_POLL] = { do_poll, "POLL" },
|
||||
[FUSE_FALLOCATE] = { do_fallocate, "FALLOCATE" },
|
||||
[FUSE_DESTROY] = { do_destroy, "DESTROY" },
|
||||
[FUSE_NOTIFY_REPLY] = { do_notify_reply, "NOTIFY_REPLY" },
|
||||
[FUSE_BATCH_FORGET] = { do_batch_forget, "BATCH_FORGET" },
|
||||
[FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" },
|
||||
[FUSE_SETUPMAPPING] = { do_setupmapping, "SETUPMAPPING" },
|
||||
[FUSE_REMOVEMAPPING] = { do_removemapping, "REMOVEMAPPING" },
|
||||
[FUSE_SYNCFS] = { do_syncfs, "SYNCFS" },
|
||||
[FUSE_TMPFILE] = { do_tmpfile, "TMPFILE" }
|
||||
NULL,
|
||||
do_lookup,
|
||||
do_forget,
|
||||
do_getattr,
|
||||
do_setattr,
|
||||
do_readlink,
|
||||
do_symlink,
|
||||
NULL,
|
||||
do_mknod,
|
||||
do_mkdir,
|
||||
do_unlink,
|
||||
do_rmdir,
|
||||
do_rename,
|
||||
do_link,
|
||||
do_open,
|
||||
do_read,
|
||||
do_write,
|
||||
do_statfs,
|
||||
do_release,
|
||||
NULL,
|
||||
do_fsync,
|
||||
do_setxattr,
|
||||
do_getxattr,
|
||||
do_listxattr,
|
||||
do_removexattr,
|
||||
do_flush,
|
||||
do_init,
|
||||
do_opendir,
|
||||
do_readdir,
|
||||
do_releasedir,
|
||||
do_fsyncdir,
|
||||
do_getlk,
|
||||
do_setlk,
|
||||
do_setlkw,
|
||||
do_access,
|
||||
do_create,
|
||||
do_interrupt,
|
||||
do_bmap,
|
||||
do_destroy,
|
||||
do_ioctl,
|
||||
do_poll,
|
||||
do_notify_reply,
|
||||
do_batch_forget,
|
||||
do_fallocate,
|
||||
do_readdirplus,
|
||||
do_rename2,
|
||||
do_lseek,
|
||||
do_copy_file_range,
|
||||
do_setupmapping,
|
||||
do_removemapping,
|
||||
do_syncfs,
|
||||
do_tmpfile,
|
||||
do_statx
|
||||
};
|
||||
|
||||
#define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
|
||||
#define FUSE_MAXOPS (sizeof(fuse_ll_funcs) / sizeof(fuse_ll_funcs[0]))
|
||||
|
||||
enum {
|
||||
KEY_HELP,
|
||||
@@ -1781,7 +1846,7 @@ fuse_ll_destroy(void *data)
|
||||
f->op.destroy(f->userdata);
|
||||
}
|
||||
|
||||
llp = pthread_getspecific(f->pipe_key);
|
||||
llp = (fuse_ll_pipe*)pthread_getspecific(f->pipe_key);
|
||||
if(llp != NULL)
|
||||
fuse_ll_pipe_free(llp);
|
||||
pthread_key_delete(f->pipe_key);
|
||||
@@ -1795,7 +1860,7 @@ static
|
||||
void
|
||||
fuse_ll_pipe_destructor(void *data)
|
||||
{
|
||||
struct fuse_ll_pipe *llp = data;
|
||||
struct fuse_ll_pipe *llp = (fuse_ll_pipe*)data;
|
||||
fuse_ll_pipe_free(llp);
|
||||
}
|
||||
|
||||
@@ -1837,7 +1902,7 @@ fuse_ll_buf_receive_read(struct fuse_session *se_,
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
if(rv < sizeof(struct fuse_in_header))
|
||||
if(rv < (int)sizeof(struct fuse_in_header))
|
||||
{
|
||||
fprintf(stderr, "short read from fuse device\n");
|
||||
return -EIO;
|
||||
@@ -1857,8 +1922,6 @@ fuse_ll_buf_process_read(struct fuse_session *se_,
|
||||
|
||||
in = (struct fuse_in_header*)msgbuf_->mem;
|
||||
|
||||
// printf("%d\n",in->opcode);
|
||||
|
||||
req = fuse_ll_alloc_req(se_->f);
|
||||
if(req == NULL)
|
||||
return fuse_send_enomem(se_->f,se_->ch,in->unique);
|
||||
@@ -1870,12 +1933,12 @@ fuse_ll_buf_process_read(struct fuse_session *se_,
|
||||
req->ch = se_->ch;
|
||||
|
||||
err = ENOSYS;
|
||||
if(in->opcode >= FUSE_MAXOP)
|
||||
if(in->opcode >= FUSE_MAXOPS)
|
||||
goto reply_err;
|
||||
if(fuse_ll_ops[in->opcode].func == NULL)
|
||||
if(fuse_ll_funcs[in->opcode] == NULL)
|
||||
goto reply_err;
|
||||
|
||||
fuse_ll_ops[in->opcode].func(req, in);
|
||||
fuse_ll_funcs[in->opcode](req, in);
|
||||
|
||||
return;
|
||||
|
||||
@@ -1908,12 +1971,12 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_,
|
||||
err = EIO;
|
||||
if(in->opcode != FUSE_INIT)
|
||||
goto reply_err;
|
||||
if(fuse_ll_ops[in->opcode].func == NULL)
|
||||
if(fuse_ll_funcs[FUSE_INIT] == NULL)
|
||||
goto reply_err;
|
||||
|
||||
se_->process_buf = fuse_ll_buf_process_read;
|
||||
|
||||
fuse_ll_ops[in->opcode].func(req, in);
|
||||
fuse_ll_funcs[in->opcode](req,in);
|
||||
|
||||
return;
|
||||
|
||||
@@ -1972,9 +2035,9 @@ fuse_lowlevel_new_common(struct fuse_args *args,
|
||||
f->userdata = userdata;
|
||||
|
||||
se = fuse_session_new(f,
|
||||
fuse_ll_buf_receive_read,
|
||||
fuse_ll_buf_process_read_init,
|
||||
fuse_ll_destroy);
|
||||
(void*)fuse_ll_buf_receive_read,
|
||||
(void*)fuse_ll_buf_process_read_init,
|
||||
(void*)fuse_ll_destroy);
|
||||
|
||||
if(!se)
|
||||
goto out_key_destroy;
|
||||
@@ -73,7 +73,7 @@ msgbuf_constructor()
|
||||
{
|
||||
g_PAGESIZE = sysconf(_SC_PAGESIZE);
|
||||
// FUSE_MAX_MAX_PAGES for payload + 1 for message header
|
||||
msgbuf_set_bufsize(FUSE_MAX_MAX_PAGES + 1);
|
||||
msgbuf_set_bufsize(FUSE_DEFAULT_MAX_MAX_PAGES + 1);
|
||||
}
|
||||
|
||||
static
|
||||
|
||||
@@ -258,7 +258,7 @@ fuse_mount_common(const char *mountpoint_,
|
||||
return NULL;
|
||||
|
||||
pagesize = sysconf(_SC_PAGESIZE);
|
||||
bufsize = ((FUSE_MAX_MAX_PAGES + 1) * pagesize);
|
||||
bufsize = ((FUSE_DEFAULT_MAX_MAX_PAGES + 1) * pagesize);
|
||||
|
||||
ch = fuse_chan_new(fd,bufsize);
|
||||
if(!ch)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "lock.h"
|
||||
#include "lfmp.h"
|
||||
|
||||
@@ -23,8 +25,18 @@ struct node_s
|
||||
uint8_t is_stat_cache_valid:1;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
node_t *node_alloc();
|
||||
void node_free(node_t*);
|
||||
int node_gc1();
|
||||
void node_gc();
|
||||
lfmp_t *node_lfmp();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+231
-56
@@ -106,16 +106,22 @@ If you don\[cq]t already know that you have a special use case then just
|
||||
start with one of the following option sets.
|
||||
.SS You need \f[C]mmap\f[R] (used by rtorrent and many sqlite3 base software)
|
||||
.PP
|
||||
\f[C]cache.files=partial,dropcacheonclose=true,category.create=mfs\f[R]
|
||||
\f[C]cache.files=auto-full,dropcacheonclose=true,category.create=mfs\f[R]
|
||||
.PP
|
||||
or if you are on a Linux kernel >= 6.6.x mergerfs will enable a mode
|
||||
that allows shared mmap when \f[C]cache.files=off\f[R].
|
||||
To be sure of the best performance between \f[C]cache.files=off\f[R] and
|
||||
\f[C]cache.files=auto-full\f[R] you\[cq]ll need to do your own
|
||||
benchmarking but often \f[C]off\f[R] is faster.
|
||||
.SS You don\[cq]t need \f[C]mmap\f[R]
|
||||
.PP
|
||||
\f[C]cache.files=off,dropcacheonclose=true,category.create=mfs\f[R]
|
||||
.SS Command Line
|
||||
.PP
|
||||
\f[C]mergerfs -o cache.files=partial,dropcacheonclose=true,category.create=mfs /mnt/hdd0:/mnt/hdd1 /media\f[R]
|
||||
\f[C]mergerfs -o cache.files=auto-full,dropcacheonclose=true,category.create=mfs /mnt/hdd0:/mnt/hdd1 /media\f[R]
|
||||
.SS /etc/fstab
|
||||
.PP
|
||||
\f[C]/mnt/hdd0:/mnt/hdd1 /media fuse.mergerfs cache.files=partial,dropcacheonclose=true,category.create=mfs 0 0\f[R]
|
||||
\f[C]/mnt/hdd0:/mnt/hdd1 /media mergerfs cache.files=auto-full,dropcacheonclose=true,category.create=mfs 0 0\f[R]
|
||||
.SS systemd mount
|
||||
.PP
|
||||
https://github.com/trapexit/mergerfs/wiki/systemd
|
||||
@@ -130,7 +136,7 @@ Type=simple
|
||||
KillMode=none
|
||||
ExecStart=/usr/bin/mergerfs \[rs]
|
||||
-f \[rs]
|
||||
-o cache.files=partial \[rs]
|
||||
-o cache.files=auto-full \[rs]
|
||||
-o dropcacheonclose=true \[rs]
|
||||
-o category.create=mfs \[rs]
|
||||
/mnt/hdd0:/mnt/hdd1 \[rs]
|
||||
@@ -185,6 +191,13 @@ Recommended when
|
||||
caching.
|
||||
(default: false)
|
||||
.IP \[bu] 2
|
||||
\f[B]direct-io-allow-mmap=BOOL\f[R]: On newer kernels (>= 6.6) it is
|
||||
possible to disable file page caching while still allowing for shared
|
||||
mmap support.
|
||||
mergerfs will enable this feature if available but an option is provided
|
||||
to turn it off for testing and debugging purposes.
|
||||
(default: true)
|
||||
.IP \[bu] 2
|
||||
\f[B]symlinkify=BOOL\f[R]: When enabled and a file is not writable and
|
||||
its mtime or ctime is older than \f[B]symlinkify_timeout\f[R] files will
|
||||
be reported as symlinks to the original files.
|
||||
@@ -214,6 +227,10 @@ This means files, when renamed or linked, will stay on the same
|
||||
filesystem.
|
||||
(default: false)
|
||||
.IP \[bu] 2
|
||||
\f[B]export-support=BOOL\f[R]: Sets a low-level FUSE feature intended to
|
||||
indicate the filesystem can support being exported via NFS.
|
||||
(default: true)
|
||||
.IP \[bu] 2
|
||||
\f[B]security_capability=BOOL\f[R]: If false return ENOATTR when xattr
|
||||
security.capability is queried.
|
||||
(default: true)
|
||||
@@ -512,8 +529,8 @@ tools use \f[B]/etc/fstab\f[R].
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/hdd*:/mnt/ssd /media fuse.mergerfs minfreespace=16G 0 0
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/hdd*:/mnt/ssd /media mergerfs minfreespace=16G 0 0
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
@@ -547,7 +564,7 @@ Most software does not to care what the values are but those that do
|
||||
often break if a value changes unexpectedly.
|
||||
The tool \f[C]find\f[R] will abort a directory walk if it sees a
|
||||
directory inode change.
|
||||
NFS will return stale handle errors if the inode changes out of band.
|
||||
NFS can return stale handle errors if the inode changes out of band.
|
||||
File dedup tools will usually leverage device ids and inodes as a
|
||||
shortcut in searching for duplicate files and would resort to full file
|
||||
comparisons should it find different inode values.
|
||||
@@ -837,6 +854,18 @@ If set to \f[C]git\f[R] it will only perform the hack when the path in
|
||||
question includes \f[C]/.git/\f[R].
|
||||
\f[C]all\f[R] will result it applying anytime a read-only file which is
|
||||
empty is opened for writing.
|
||||
.SS export-support
|
||||
.PP
|
||||
In theory this flag should not be exposed to the end user.
|
||||
It is a low-level FUSE flag which indicates whether or not the kernel
|
||||
can send certain kinds of messages to it for the purposes of using with
|
||||
NFS.
|
||||
mergerfs does support these messages but due bugs and quirks found in
|
||||
the kernel and mergerfs this option is provided just in case it is
|
||||
needed for debugging.
|
||||
.PP
|
||||
Given that this flag is set when the FUSE connection is first initiated
|
||||
it is not possible to change during run time.
|
||||
.SH FUNCTIONS, CATEGORIES and POLICIES
|
||||
.PP
|
||||
The POSIX filesystem API is made up of a number of functions.
|
||||
@@ -1553,8 +1582,8 @@ apply those before mounting the new version.
|
||||
\f[C]
|
||||
$ sudo mount /mnt/mergerfs
|
||||
$ mount | grep mergerfs
|
||||
media on /mnt/mergerfs type fuse.mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type fuse.mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
@@ -1726,18 +1755,41 @@ unused files to be released from memory.
|
||||
.PP
|
||||
EXPERIMENTAL
|
||||
.PP
|
||||
This preloadable library overrides the creation and opening of files in
|
||||
order to simulate passthrough file IO.
|
||||
It catches the open/creat/fopen calls, lets mergerfs do the call,
|
||||
queries mergerfs for the branch the file exists on, and reopens the file
|
||||
on the underlying filesystem.
|
||||
Meaning that you will get native read/write performance.
|
||||
For some time there has been work to enable passthrough IO in FUSE.
|
||||
Passthrough IO would allow for near native performance with regards to
|
||||
reads and writes (at the expense of certain mergerfs features.) However,
|
||||
there have been several complications which have kept the feature from
|
||||
making it into the mainline Linux kernel.
|
||||
Until that feature is available there are two methods to provide similar
|
||||
functionality.
|
||||
One method is using the LD_PRELOAD feature of the dynamic linker.
|
||||
The other leveraging ptrace to intercept syscalls.
|
||||
Each has their disadvantages.
|
||||
At the moment only a preload based tool is available.
|
||||
A ptrace based tool may be developed later if there is a need.
|
||||
.PP
|
||||
This will only work on dynamically linked software.
|
||||
\f[C]/usr/lib/mergerfs/preload.so\f[R]
|
||||
.PP
|
||||
This preloadable
|
||||
library (https://man7.org/linux/man-pages/man8/ld.so.8.html#ENVIRONMENT)
|
||||
overrides the creation and opening of files in order to simulate
|
||||
passthrough file IO.
|
||||
It catches the open/creat/fopen calls, has mergerfs do the call, queries
|
||||
mergerfs for the branch the file exists on, reopens the file on the
|
||||
underlying filesystem and returns that instead.
|
||||
Meaning that you will get native read/write performance because mergerfs
|
||||
is no longer part of the workflow.
|
||||
Keep in mind that this also means certain mergerfs features that work by
|
||||
interrupting the read/write workflow, such as \f[C]moveonenospc\f[R],
|
||||
will no longer work.
|
||||
.PP
|
||||
Also understand that this will only work on dynamically linked software.
|
||||
Anything statically compiled will not work.
|
||||
Many GoLang and Rust apps are statically compiled.
|
||||
.PP
|
||||
The library will not interfere with non-mergerfs filesystems.
|
||||
The library is written to always fallback to returning the mergerfs
|
||||
opened file on error.
|
||||
.PP
|
||||
While the library was written to account for a number of edgecases there
|
||||
could be some yet accounted for so please report any oddities.
|
||||
@@ -1754,22 +1806,52 @@ LD_PRELOAD=/usr/lib/mergerfs/preload.so touch /mnt/mergerfs/filename
|
||||
.SS Docker usage
|
||||
.PP
|
||||
Assume \f[C]/mnt/fs0\f[R] and \f[C]/mnt/fs1\f[R] are pooled with
|
||||
mergerfs at \f[C]/mnt/mergerfs\f[R].
|
||||
mergerfs at \f[C]/media\f[R].
|
||||
.PP
|
||||
Remember that you must bind into the container the original host paths
|
||||
to the same locations otherwise the preload module will not be able to
|
||||
find the files.
|
||||
All mergerfs branch paths \f[I]must\f[R] be bind mounted into the
|
||||
container at the same path as found on the host so the preload library
|
||||
can see them.
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
docker run \[rs]
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \[rs]
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \[rs]
|
||||
-v /media:/data \[rs]
|
||||
-v /mnt:/mnt \[rs]
|
||||
ubuntu:latest \[rs]
|
||||
bash
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
or more explicitly
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
docker run \[rs]
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \[rs]
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \[rs]
|
||||
-v /media:/data \[rs]
|
||||
-v /mnt/fs0:/mnt/fs0 \[rs]
|
||||
-v /mnt/fs1:/mnt/fs1 \[rs]
|
||||
ubuntu:latest \[rs]
|
||||
bash
|
||||
\f[R]
|
||||
.fi
|
||||
.SS systemd unit
|
||||
.PP
|
||||
Use the \f[C]Environment\f[R] option to set the LD_PRELOAD variable.
|
||||
.IP \[bu] 2
|
||||
https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines
|
||||
.IP \[bu] 2
|
||||
https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
[Service]
|
||||
Environment=LD_PRELOAD=/usr/lib/mergerfs/preload.so
|
||||
\f[R]
|
||||
.fi
|
||||
.SS Misc
|
||||
.IP \[bu] 2
|
||||
https://github.com/trapexit/mergerfs-tools
|
||||
@@ -2322,18 +2404,13 @@ Use \f[C]cache.files=off\f[R] and/or \f[C]dropcacheonclose=true\f[R].
|
||||
See the section on page caching.
|
||||
.SS NFS clients returning ESTALE / Stale file handle
|
||||
.PP
|
||||
NFS does not like out of band changes.
|
||||
That is especially true of inode values.
|
||||
.PP
|
||||
Be sure to use the following options:
|
||||
.IP \[bu] 2
|
||||
noforget
|
||||
.IP \[bu] 2
|
||||
inodecalc=path-hash
|
||||
NFS generally does not like out of band changes.
|
||||
Take a look at the section on NFS in the #remote-filesystems for more
|
||||
details.
|
||||
.SS rtorrent fails with ENODEV (No such device)
|
||||
.PP
|
||||
Be sure to set \f[C]cache.files=partial|full|auto-full|per-processe\f[R]
|
||||
or turn off \f[C]direct_io\f[R].
|
||||
Be sure to set
|
||||
\f[C]cache.files=partial|full|auto-full|per-processe\f[R].
|
||||
rtorrent and some other applications use
|
||||
mmap (http://linux.die.net/man/2/mmap) to read and write to files and
|
||||
offer no fallback to traditional methods.
|
||||
@@ -2486,6 +2563,123 @@ There might be a hack to work around this (make mergerfs read the
|
||||
would be limited to Linux and the /etc/group DB.
|
||||
Preferably users would mount in the host group file into the containers
|
||||
or use a standard shared user & groups technology like NIS or LDAP.
|
||||
.SH Remote Filesystems
|
||||
.PP
|
||||
Many users ask about compatibility with remote filesystems.
|
||||
This section is to describe any known issues or quirks when using
|
||||
mergerfs with common remote filesystems.
|
||||
.PP
|
||||
Keep in mind that, like with caching, it is not a good idea to change
|
||||
the contents of the remote filesystem
|
||||
out-of-band (https://en.wikipedia.org/wiki/Out-of-band).
|
||||
Meaning that you really shouldn\[cq]t change the contents of the
|
||||
underlying filesystems or mergerfs on the server hosting the remote
|
||||
filesystem.
|
||||
Doing so can lead to weird behavior, inconsistency, errors, and even
|
||||
data corruption should multiple programs try to write or read the same
|
||||
data at the same time.
|
||||
This isn\[cq]t to say you can\[cq]t do it or that data corruption is
|
||||
likely but it \f[I]could\f[R] happen.
|
||||
It is better to always use the remote filesystem.
|
||||
Even on the machine serving it.
|
||||
.SS NFS
|
||||
.PP
|
||||
NFS (https://en.wikipedia.org/wiki/Network_File_System) is a common
|
||||
remote filesystem on Unix/POSIX systems.
|
||||
Due to how NFS works there are some settings which need to be set in
|
||||
order for mergerfs to work with it.
|
||||
.PP
|
||||
It should be noted that NFS and FUSE (the technology mergerfs uses) do
|
||||
not work perfectly with one another due to certain design choices in
|
||||
FUSE (and mergerfs.) Due to these issues it is generally recommended to
|
||||
use SMB when possible till situations change.
|
||||
That said mergerfs should generally work as an export of NFS and issues
|
||||
discovered should still be reported.
|
||||
.PP
|
||||
To ensure compatibility between mergerfs and NFS use the following
|
||||
settings.
|
||||
.PP
|
||||
mergerfs settings: * noforget * inodecalc=path-hash
|
||||
.PP
|
||||
NFS export settings: * fsid=UUID * no_root_squash
|
||||
.PP
|
||||
\f[C]noforget\f[R] is needed because NFS uses the
|
||||
\f[C]name_to_handle_at\f[R] and \f[C]open_by_handle_at\f[R] functions
|
||||
which allow a program to keep a reference to a file without technically
|
||||
having it open in the typical sense.
|
||||
The problem is that FUSE has no way to know that NFS has a handle that
|
||||
it will later use to open the file again.
|
||||
As a result it is possible for the kernel to tell mergerfs to forget
|
||||
about the node and should NFS ever ask for that node\[cq]s details in
|
||||
the future it would have nothing to respond with.
|
||||
Keeping nodes around forever is not ideal but at the moment the only way
|
||||
to manage the situation.
|
||||
.PP
|
||||
\f[C]inodecalc=path-hash\f[R] is needed because NFS is sensitive to
|
||||
out-of-band changes.
|
||||
FUSE doesn\[cq]t care if a file\[cq]s inode value changes but NFS, being
|
||||
stateful, does.
|
||||
So if you used the default inode calculation algorithm then it is
|
||||
possible that if you changed a file or updated a directory the file
|
||||
mergerfs will use will be on a different branch and therefore the inode
|
||||
would change.
|
||||
This isn\[cq]t an ideal solution and others are being considered but it
|
||||
works for most situations.
|
||||
.PP
|
||||
\f[C]fsid=UUID\f[R] is needed because FUSE filesystems don\[cq]t have
|
||||
different \f[C]st_dev\f[R] values which can cause issues when exporting.
|
||||
The easiest thing to do is set each mergerfs export \f[C]fsid\f[R] to
|
||||
some random value.
|
||||
An easy way to generate a random value is to use the command line tool
|
||||
\f[C]uuid\f[R] or \f[C]uuidgen\f[R] or through a website such as
|
||||
uuidgenerator.net (https://www.uuidgenerator.net/).
|
||||
.PP
|
||||
\f[C]no_root_squash\f[R] is not strictly necessary but can lead to
|
||||
confusing permission and ownership issues if root squashing is enabled.
|
||||
.SS SMB / CIFS
|
||||
.PP
|
||||
SMB (https://en.wikipedia.org/wiki/Server_Message_Block) is a protocol
|
||||
most used by Microsoft Windows systems to share file shares, printers,
|
||||
etc.
|
||||
However, due to the popularity for Windows, it is also supported on many
|
||||
other platforms including Linux.
|
||||
The most popular way of supporting SMB on Linux is via the software
|
||||
Samba.
|
||||
.PP
|
||||
Samba (https://en.wikipedia.org/wiki/Samba_(software)), and other ways
|
||||
of serving Linux filesystems, via SMB should work fine with mergerfs.
|
||||
The services do not tend to use the same technologies which NFS uses and
|
||||
therefore don\[cq]t have the same issues.
|
||||
There should not be an special settings required to use mergerfs with
|
||||
Samba.
|
||||
However, CIFSD (https://en.wikipedia.org/wiki/CIFSD) and other programs
|
||||
have not been extensively tested.
|
||||
If you use mergerfs with CIFSD or other SMB servers please submit your
|
||||
experiences so these docs can be updated.
|
||||
.SS SSHFS
|
||||
.PP
|
||||
SSHFS (https://en.wikipedia.org/wiki/SSHFS) is a FUSE filesystem
|
||||
leveraging SSH as the connection and transport layer.
|
||||
While often simpler to setup when compared to NFS or Samba the
|
||||
performance can be lacking and the project is very much in maintenance
|
||||
mode.
|
||||
.PP
|
||||
There are no known issues using sshfs with mergerfs.
|
||||
You may want to use the following arguments to improve performance but
|
||||
your millage may vary.
|
||||
.IP \[bu] 2
|
||||
\f[C]-o Ciphers=arcfour\f[R]
|
||||
.IP \[bu] 2
|
||||
\f[C]-o Compression=no\f[R]
|
||||
.PP
|
||||
More info can be found
|
||||
here (https://ideatrash.net/2016/08/odds-and-ends-optimizing-sshfs-moving.html).
|
||||
.SS Other
|
||||
.PP
|
||||
There are other remote filesystems but none popularly used to serve
|
||||
mergerfs.
|
||||
If you use something not listed above feel free to reach out and I will
|
||||
add it to the list.
|
||||
.SH FAQ
|
||||
.SS How well does mergerfs scale? Is it \[lq]production ready?\[rq]
|
||||
.PP
|
||||
@@ -2727,8 +2921,8 @@ executable bit set.
|
||||
A common mistake by users new to Linux is to \f[C]chmod -R 644\f[R] when
|
||||
they should have \f[C]chmod -R u=rwX,go=rX\f[R].
|
||||
.PP
|
||||
If using a network filesystem such as NFS, SMB, CIFS (Samba) be sure to
|
||||
pay close attention to anything regarding permissioning and users.
|
||||
If using a network filesystem such as NFS or SMB (Samba) be sure to pay
|
||||
close attention to anything regarding permissioning and users.
|
||||
Root squashing and user translation for instance has bitten a few
|
||||
mergerfs users.
|
||||
Some of these also affect the use of mergerfs from container platforms
|
||||
@@ -2853,33 +3047,14 @@ mergerfs uses available space for statfs calculations.
|
||||
If you\[cq]ve reserved space for root then it won\[cq]t show up.
|
||||
.PP
|
||||
You can remove the reserve by running: \f[C]tune2fs -m 0 <device>\f[R]
|
||||
.SS Can mergerfs mounts be exported over NFS?
|
||||
.PP
|
||||
Yes, however if you do anything which may changes files out of band
|
||||
(including for example using the \f[C]newest\f[R] policy) it will result
|
||||
in \[lq]stale file handle\[rq] errors unless properly setup.
|
||||
.PP
|
||||
Be sure to use the following options:
|
||||
.IP \[bu] 2
|
||||
noforget
|
||||
.IP \[bu] 2
|
||||
inodecalc=path-hash
|
||||
.SS Can mergerfs mounts be exported over Samba / SMB?
|
||||
.PP
|
||||
Yes.
|
||||
While some users have reported problems it appears to always be related
|
||||
to how Samba is setup in relation to permissions.
|
||||
.SS Can mergerfs mounts be used over SSHFS?
|
||||
.PP
|
||||
Yes.
|
||||
.SS I notice massive slowdowns of writes when enabling cache.files.
|
||||
.PP
|
||||
When file caching is enabled in any form (\f[C]cache.files!=off\f[R] or
|
||||
\f[C]direct_io=false\f[R]) it will issue \f[C]getxattr\f[R] requests for
|
||||
\f[C]security.capability\f[R] prior to \f[I]every single write\f[R].
|
||||
When file caching is enabled in any form (\f[C]cache.files!=off\f[R]) it
|
||||
will issue \f[C]getxattr\f[R] requests for \f[C]security.capability\f[R]
|
||||
prior to \f[I]every single write\f[R].
|
||||
This will usually result in a performance degradation, especially when
|
||||
using a network filesystem (such as NFS or CIFS/SMB/Samba.)
|
||||
Unfortunately at this moment the kernel is not caching the response.
|
||||
using a network filesystem (such as NFS or SMB.) Unfortunately at this
|
||||
moment the kernel is not caching the response.
|
||||
.PP
|
||||
To work around this situation mergerfs offers a few solutions.
|
||||
.IP "1." 3
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# mkdocs
|
||||
|
||||
## Getting started
|
||||
|
||||
```bash
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip3 install --no-cache-dir mkdocs mkdocs-material pymdown-extensions
|
||||
mkdocs serve
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* https://www.mkdocs.org/
|
||||
* https://squidfunk.github.io/mkdocs-material/
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# Benchmarking
|
||||
|
||||
Filesystems are complicated. They do many things and many of those are
|
||||
interconnected. Additionally, the OS, drivers, hardware, etc. can all
|
||||
impact performance. Therefore, when benchmarking, it is **necessary**
|
||||
that the test focuses as narrowly as possible.
|
||||
|
||||
For most throughput is the key benchmark. To test throughput `dd` is
|
||||
useful but **must** be used with the correct settings in order to
|
||||
ensure the filesystem or device is actually being tested. The OS can
|
||||
and will cache data. Without forcing synchronous reads and writes
|
||||
and/or disabling caching the values returned will not be
|
||||
representative of the device's true performance.
|
||||
|
||||
When benchmarking through mergerfs ensure you only use 1 branch to
|
||||
remove any possibility of the policies complicating the
|
||||
situation. Benchmark the underlying filesystem first and then mount
|
||||
mergerfs over it and test again. If you're experiencing speeds below
|
||||
your expectation you will need to narrow down precisely which
|
||||
component is leading to the slowdown. Preferably test the following in
|
||||
the order listed (but not combined).
|
||||
|
||||
1. Enable `nullrw` mode with `nullrw=true`. This will effectively make
|
||||
reads and writes no-ops. Removing the underlying device /
|
||||
filesystem from the equation. This will give us the top theoretical
|
||||
speeds.
|
||||
2. Mount mergerfs over `tmpfs`. `tmpfs` is a RAM disk. Extremely high
|
||||
speed and very low latency. This is a more realistic best case
|
||||
scenario. Example: `mount -t tmpfs -o size=2G tmpfs /tmp/tmpfs`
|
||||
3. Mount mergerfs over a local device. NVMe, SSD, HDD, etc. If you
|
||||
have more than one I'd suggest testing each of them as drives
|
||||
and/or controllers (their drivers) could impact performance.
|
||||
4. Finally, if you intend to use mergerfs with a network filesystem,
|
||||
either as the source of data or to combine with another through
|
||||
mergerfs, test each of those alone as above.
|
||||
|
||||
Once you find the component which has the performance issue you can do
|
||||
further testing with different options to see if they impact
|
||||
performance. For reads and writes the most relevant would be:
|
||||
`cache.files`, `async_read`. Less likely but relevant when using NFS
|
||||
or with certain filesystems would be `security_capability`, `xattr`,
|
||||
and `posix_acl`. If you find a specific system, device, filesystem,
|
||||
controller, etc. that performs poorly contact trapexit so he may
|
||||
investigate further.
|
||||
|
||||
Sometimes the problem is really the application accessing or writing
|
||||
data through mergerfs. Some software use small buffer sizes which can
|
||||
lead to more requests and therefore greater overhead. You can test
|
||||
this out yourself by replacing `bs=1M` in the examples below with `ibs`
|
||||
or `obs` and using a size of `512` instead of `1M`. In one example
|
||||
test using `nullrw` the write speed dropped from 4.9GB/s to 69.7MB/s
|
||||
when moving from `1M` to `512`. Similar results were had when testing
|
||||
reads. Small writes overhead may be improved by leveraging a write
|
||||
cache but in casual tests little gain was found. More tests will need
|
||||
to be done before this feature would become available. If you have an
|
||||
app that appears slow with mergerfs it could be due to this. Contact
|
||||
trapexit so he may investigate further.
|
||||
|
||||
### write benchmark
|
||||
|
||||
```
|
||||
$ dd if=/dev/zero of=/mnt/mergerfs/1GB.file bs=1M count=1024 oflag=nocache conv=fdatasync status=progress
|
||||
```
|
||||
|
||||
### read benchmark
|
||||
|
||||
```
|
||||
$ dd if=/mnt/mergerfs/1GB.file of=/dev/null bs=1M count=1024 iflag=nocache conv=fdatasync status=progress
|
||||
```
|
||||
|
||||
### other benchmarks
|
||||
|
||||
If you are attempting to benchmark other behaviors you must ensure you
|
||||
clear kernel caches before runs. In fact it would be a good deal to
|
||||
run before the read and write benchmarks as well just in case.
|
||||
|
||||
```
|
||||
sync
|
||||
echo 3 | sudo tee /proc/sys/vm/drop_caches
|
||||
```
|
||||
@@ -0,0 +1,54 @@
|
||||
# branches
|
||||
|
||||
The 'branches' argument is a colon (':') delimited list of paths to be
|
||||
pooled together. It does not matter if the paths are on the same or
|
||||
different filesystems nor does it matter the filesystem type (within
|
||||
reason). Used and available space will not be duplicated for paths on
|
||||
the same filesystem and any features which aren't supported by the
|
||||
underlying filesystem (such as file attributes or extended attributes)
|
||||
will return the appropriate errors.
|
||||
|
||||
Branches currently have two options which can be set. A type which
|
||||
impacts whether or not the branch is included in a policy calculation
|
||||
and a individual minfreespace value. The values are set by prepending
|
||||
an `=` at the end of a branch designation and using commas as
|
||||
delimiters. Example: `/mnt/drive=RW,1234`
|
||||
|
||||
### branch mode
|
||||
|
||||
- RW: (read/write) - Default behavior. Will be eligible in all policy
|
||||
categories.
|
||||
- RO: (read-only) - Will be excluded from `create` and `action`
|
||||
policies. Same as a read-only mounted filesystem would be (though
|
||||
faster to process).
|
||||
- NC: (no-create) - Will be excluded from `create` policies. You can't
|
||||
create on that branch but you can change or delete.
|
||||
|
||||
### minfreespace
|
||||
|
||||
Same purpose and syntax as the global option but specific to the
|
||||
branch. If not set the global value is used.
|
||||
|
||||
### globbing
|
||||
|
||||
To make it easier to include multiple branches mergerfs supports
|
||||
[globbing](http://linux.die.net/man/7/glob). **The globbing tokens
|
||||
MUST be escaped when using via the shell else the shell itself will
|
||||
apply the glob itself.**
|
||||
|
||||
```
|
||||
# mergerfs /mnt/hdd\*:/mnt/ssd /media
|
||||
```
|
||||
|
||||
The above line will use all mount points in /mnt prefixed with **hdd**
|
||||
and **ssd**.
|
||||
|
||||
To have the pool mounted at boot or otherwise accessible from related
|
||||
tools use `/etc/fstab`.
|
||||
|
||||
```
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/hdd*:/mnt/ssd /media mergerfs minfreespace=16G 0 0
|
||||
```
|
||||
|
||||
**NOTE:** The globbing is done at mount or when updated using the runtime API. If a new directory is added matching the glob after the fact it will not be automatically included.
|
||||
@@ -0,0 +1,187 @@
|
||||
# caching
|
||||
|
||||
## cache.files
|
||||
|
||||
Controls how [page caching](https://en.wikipedia.org/wiki/Page_cache)
|
||||
works for mergerfs itself. Not the underlying filesystems.
|
||||
|
||||
* `cache.files=off`: Disables page caching for mergerfs.
|
||||
* `cache.files=partial`: Enables page caching. Files are cached
|
||||
while open.
|
||||
* `cache.files=full`: Enables page caching. Files are cached across
|
||||
opens.
|
||||
* `cache.files=auto-full`: Enables page caching. Files are cached
|
||||
across opens if mtime and size are unchanged since previous open.
|
||||
* `cache.files=per-process`: Enable page caching (equivalent to
|
||||
`cache.files=partial`) only for processes whose 'comm' name matches
|
||||
one of the values defined in cache.files.process-names. If the name
|
||||
does not match the file open is equivalent to `cache.files=off`.
|
||||
|
||||
|
||||
Generally, enabling the page cache actually *harms*
|
||||
performance[^1]. In part because it can lead to buffer bloat due to
|
||||
the kernel caching both the underlying filesystem's file content as
|
||||
well as the file through mergerfs. However, if you want to confirm
|
||||
performance differences it is recommended that you perform some
|
||||
benchmark to confirm which option works best for your setup.
|
||||
|
||||
Why then would you want to enable page caching if it consumes ~2x the
|
||||
RAM as normal and is on average slower? Because it is the only way to
|
||||
support
|
||||
[mmap](https://man7.org/linux/man-pages/man2/mmap.2.html). `mmap` is a
|
||||
way for programs to treat a file as if it is a contiguous RAM buffer
|
||||
which is regularly used by a number of programs such as those that
|
||||
leverage **sqlite3**. Despite `mmap` not being supported by all
|
||||
filesystems it is unfortunately common for software to not have an
|
||||
option to use regular file IO instead of `mmap`.
|
||||
|
||||
The good thing is that in Linux v6.6[^2] and above FUSE can now
|
||||
transparently enable page caching when mmap is requested. This means
|
||||
it should be safe to set `cache.files=off`. However, on Linux v6.5 and
|
||||
below you will need to configure `cache.files` as you need.
|
||||
|
||||
|
||||
[^1]: This is not unique to mergerfs and affects all FUSE
|
||||
filesystems. It is something that the FUSE community hopes to
|
||||
investigate at some point but as of early 2025 there are a number
|
||||
of major reworking going on with FUSE which needs to be finished
|
||||
first.
|
||||
[^2]: [https://kernelnewbies.org/Linux_6.6#FUSE](https://kernelnewbies.org/Linux_6.6#FUSE)
|
||||
|
||||
|
||||
## cache.entry
|
||||
|
||||
* `cache.entry=UINT`: Sets the number of seconds to cache
|
||||
entry queries. Defaults to `1`.
|
||||
|
||||
The kernel must ask mergerfs about the existence of files. The entry
|
||||
cache caches that those details which limits the number of requests
|
||||
sent to mergerfs.
|
||||
|
||||
The risk of setting this value, as with most any cache, is related to
|
||||
[out-of-band](https://en.wikipedia.org/wiki/Out-of-band) changes. If
|
||||
the filesystems are changed outside mergerfs there is a risk of files
|
||||
which have been removed continuing to show as available. It will fail
|
||||
gracefully if a phantom file is actioned on in some way so there is
|
||||
little risk in setting the value much higher. Especially if there are
|
||||
no out-of-band changes.
|
||||
|
||||
|
||||
## cache.negative_entry
|
||||
|
||||
* `cache.negative_entry=UINT`: Sets the number of seconds to cache
|
||||
negative entry queries. Defaults to `1`.
|
||||
|
||||
This is a cache for negative entry query responses. Such as when a
|
||||
file which does not exist is referenced.
|
||||
|
||||
The risk of setting this value, as with most any cache, is related to
|
||||
[out-of-band](https://en.wikipedia.org/wiki/Out-of-band) changes. If
|
||||
the filesystems are changed outside mergerfs there is a risk of files
|
||||
which have been added outside mergerfs not appearing correctly till
|
||||
the cache entry times out if there had been a request for the same
|
||||
name within mergerfs which didn't exist. This is mostly an
|
||||
inconvenience.
|
||||
|
||||
|
||||
## cache.attr
|
||||
|
||||
* `cache.attr=UINT`: Sets the number of seconds to cache file
|
||||
attributes. Defaults to `1`.
|
||||
|
||||
This is a cache for file attributes and metadata such as that which is
|
||||
collected by the
|
||||
[stat](https://man7.org/linux/man-pages/man2/stat.2.html) system call
|
||||
which is used when you run commands such as `find` or `ls -lh`.
|
||||
|
||||
As with other caches the risk of enabling the attribute cache is if
|
||||
changes are made to the file out-of-band there could be
|
||||
inconsistencies between the actual file and the cached details which
|
||||
could result in different issues depending on how the data is used. If
|
||||
the simultaneous writing of a file from inside and outside is unlikely
|
||||
then you should be safe. That said any simultaneous, uncoordinated
|
||||
manipulation of a file can lead to unexpected results.
|
||||
|
||||
|
||||
## cache.statfs
|
||||
|
||||
* `cache.statfs=UINT`: Sets the number of seconds to cache `statfs`
|
||||
calls used by policies. Defaults to `0`.
|
||||
|
||||
A number of policies require looking up the available space of the
|
||||
branches being considered. This is accomplished by calling
|
||||
[statfs](https://man7.org/linux/man-pages/man2/statfs.2.html). This
|
||||
call however is a bit expensive so this cache reduces the overhead by
|
||||
limiting how often the calls are actually made.
|
||||
|
||||
This will mean that if the available space of branches changed
|
||||
somewhat rapidly there is a risk of `create` or `mkdir` calls made
|
||||
within the timeout period ending up on the same branch. This however
|
||||
should even itself out over time.
|
||||
|
||||
|
||||
## cache.symlinks
|
||||
|
||||
* `cache.symlinks=BOOL`: Enable kernel caching of symlink
|
||||
values. Defaults to `false`.
|
||||
|
||||
As of Linux v4.20 there is an ability to cache the value of symlinks
|
||||
so that the kernel does not need to make a request to mergerfs every
|
||||
single time a
|
||||
[readlink](https://man7.org/linux/man-pages/man2/readlink.2.html)
|
||||
request is made. While not a common usage pattern, if software very
|
||||
regularly queries symlink values, the use of this cache could
|
||||
significantly improve performance.
|
||||
|
||||
mergerfs will not error if the kernel used does not support symlink
|
||||
caching.
|
||||
|
||||
As with other caches the main risk in enabling it is if you are
|
||||
manipulating symlinks from both within and without the mergerfs
|
||||
mount. Should the value be changed outside of mergerfs then it will
|
||||
not be reflected in the mergerfs mount till the cached value is
|
||||
invalidated.
|
||||
|
||||
|
||||
## cache.readdir
|
||||
|
||||
* `cache.readdir=BOOL`: Enable kernel caching of readdir
|
||||
results. Defaults to `false`.
|
||||
|
||||
As of Linux v4.20 it supports readdir caching. This can have a
|
||||
significant impact on directory traversal. Especially when combined
|
||||
with entry (`cache.entry`) and attribute (`cache.attr`) caching. If
|
||||
the kernel doesn't support readdir caching setting the option to true
|
||||
has no effect. This option is configurable at runtime via xattr
|
||||
user.mergerfs.cache.readdir.
|
||||
|
||||
## cache.writeback
|
||||
|
||||
* `cache.writeback=BOOL`: Enable writeback cache. Defaults to `false`.
|
||||
|
||||
When `cache.files` is enabled the default is for it to perform
|
||||
writethrough caching. This behavior won't help improve performance as
|
||||
each write still goes one for one through the filesystem. By enabling
|
||||
the FUSE writeback cache small writes *may* be aggregated by the
|
||||
kernel and then sent to mergerfs as one larger request. This can
|
||||
greatly improve the throughput for apps which write to files
|
||||
inefficiently. The amount the kernel can aggregate is limited by the
|
||||
size of a FUSE message. Read the fuse_msg_size section for more
|
||||
details.
|
||||
|
||||
There is a side effect as a result of enabling writeback
|
||||
caching. Underlying files won't ever be opened with O_APPEND or
|
||||
O_WRONLY. The former because the kernel then manages append mode and
|
||||
the latter because the kernel may request file data from mergerfs to
|
||||
populate the write cache. The O_APPEND change means that if a file is
|
||||
changed outside of mergerfs it could lead to corruption as the kernel
|
||||
won't know the end of the file has changed. That said any time you use
|
||||
caching you should keep from writing to the same file outside of
|
||||
mergerfs at the same time.
|
||||
|
||||
Note that if an application is properly sizing writes then writeback
|
||||
caching will have little or no effect. It will only help with writes
|
||||
of sizes below the FUSE message size (128K on older kernels, 1M on
|
||||
newer). Even then its effectiveness might not be great. Given the side
|
||||
effects of enabling this feature it is recommended that its benefits
|
||||
be proved out with benchmarks.
|
||||
@@ -0,0 +1,21 @@
|
||||
# Deprecated Options
|
||||
|
||||
These are old, deprecated options which may no longer have any
|
||||
function or have been replaced. **They should not be used.**
|
||||
|
||||
* **direct_io**: Bypass page cache. Use `cache.files=off`
|
||||
instead.
|
||||
* **kernel_cache**: Do not invalidate data cache on file open. Use
|
||||
`cache.files=full` instead.
|
||||
* **auto_cache**: Invalidate data cache if file mtime or
|
||||
size change. Use `cache.files=auto-full` instead. (default: false)
|
||||
* **async_read**: Perform reads asynchronously. Use
|
||||
`async_read=true` instead.
|
||||
* **sync_read**: Perform reads synchronously. Use
|
||||
`async_read=false` instead.
|
||||
* **splice_read**: Does nothing.
|
||||
* **splice_write**: Does nothing.
|
||||
* **splice_move**: Does nothing.
|
||||
* **allow_other**: mergerfs v2.35.0 and above sets this FUSE option
|
||||
automatically if running as root.
|
||||
* **use_ino**: Effectively replaced with `inodecalc`.
|
||||
@@ -0,0 +1,14 @@
|
||||
# export-support
|
||||
|
||||
* `export-support=true|false`
|
||||
* Defaults to `true`.
|
||||
|
||||
In theory, this flag should not be exposed to the end user. It is a
|
||||
low-level FUSE flag which indicates whether or not the kernel can send
|
||||
certain kinds of messages to it for the purposes of using it with
|
||||
NFS. mergerfs does support these messages but due to bugs and quirks
|
||||
found in the kernel and mergerfs this option is provided just in case
|
||||
it is needed for debugging.
|
||||
|
||||
Given that this flag is set when the FUSE connection is first
|
||||
initiated it is not possible to change during run time.
|
||||
@@ -0,0 +1,21 @@
|
||||
# flush-on-close
|
||||
|
||||
By default, FUSE would issue a flush before the release of a file
|
||||
descriptor. This was considered a bit aggressive and a feature added
|
||||
to give the FUSE server the ability to choose when that happens.
|
||||
|
||||
* `flush-on-close=always`
|
||||
* `flush-on-close=never`
|
||||
* `flush-on-close=opened-for-write`
|
||||
* Defaults to `opened-for-write`.
|
||||
|
||||
For now it defaults to `opened-for-write` which is less aggressive
|
||||
than the behavior before this feature was added. It should not be a
|
||||
problem because the flush is really only relevant when a file is
|
||||
written to. Given flush is irrelevant for many filesystems in the
|
||||
future a branch specific flag may be added so only files opened on a
|
||||
specific branch would be flushed on close.
|
||||
|
||||
## References
|
||||
|
||||
* [https://lkml.kernel.org/linux-fsdevel/20211024132607.1636952-1-amir73il@gmail.com/T/](https://lkml.kernel.org/linux-fsdevel/20211024132607.1636952-1-amir73il@gmail.com/T/)
|
||||
@@ -0,0 +1,23 @@
|
||||
# follow-symlinks
|
||||
|
||||
This feature, when enabled, will cause symlinks to be interpreted by
|
||||
mergerfs as their target.
|
||||
|
||||
When there is a getattr/stat request for a file mergerfs will check if
|
||||
the file is a symlink and depending on the `follow-symlinks` setting
|
||||
will replace the information about the symlink with that of that which
|
||||
it points to.
|
||||
|
||||
When unlink'ing or rmdir'ing the followed symlink it will remove the
|
||||
symlink itself and not that which it points to.
|
||||
|
||||
* `follow-symlinks=never`: Behave as normal. Symlinks are treated as such.
|
||||
* `follow-symlinks=directory`: Resolve symlinks only which point to directories.
|
||||
* `follow-symlinks=regular`: Resolve symlinks only which point to regular files.
|
||||
* `follow-symlinks=all`: Resolve all symlinks to that which they point
|
||||
to. Symlinks which do not point to anything are left as is.
|
||||
* Defaults to `never`.
|
||||
|
||||
**WARNING:** This feature should be considered experimental. There
|
||||
might be edge cases yet found. If you find any odd behaviors please
|
||||
file a ticket on [github](https://github.com/trapexit/mergerfs/issues/new?assignees=&labels=bug%2C+investigating&projects=&template=bug_report.md&title=).
|
||||
@@ -0,0 +1,17 @@
|
||||
# func.readdir
|
||||
|
||||
examples: `func.readdir=seq`, `func.readdir=cor:4`
|
||||
|
||||
`readdir` has policies to control how it reads directory content.
|
||||
|
||||
| Policy | Description |
|
||||
| ------ | ----------- |
|
||||
| seq | "sequential" : Iterate sequentially over branches in the order defined in `branches`. This is the default and traditional behavior found prior to the readdir policy introduction. This will be increasingly slower as more branches are added to the pool. Especially if needing to wait for drives to spin up or network filesystems to respond. |
|
||||
| cosr | "concurrent open, sequential read" : Concurrently open branch directories using a thread pool and process them in the order defined in `branches`. This keeps memory and CPU usage low while also reducing the time spent waiting on branches to respond. Number of threads defaults to the number of logical cores. Can be overwritten via the syntax `func.readdir=cosr:N` where `N` is the number of threads. |
|
||||
| cor | "concurrent open and read" : Concurrently open branch directories and immediately start reading their contents using a thread pool. This will result in slightly higher memory and CPU usage but reduced latency. Particularly when using higher latency / slower speed network filesystem branches. Unlike `seq` and `cosr` the order of files could change due the async nature of the thread pool. This should not be a problem since the order of files listed in not guaranteed. Number of threads defaults to the number of logical cores. Can be overwritten via the syntax `func.readdir=cor:N` where `N` is the number of threads. |
|
||||
|
||||
Keep in mind that `readdir` mostly just provides a list of file names
|
||||
in a directory and possibly some basic metadata about said files. To
|
||||
know details about the files, as one would see from commands like
|
||||
`find` or `ls`, it is required to call `stat` on the file which is
|
||||
controlled by `fuse.getattr`.
|
||||
@@ -0,0 +1,139 @@
|
||||
# functions, categories and policies
|
||||
|
||||
The POSIX filesystem API is made up of a number of
|
||||
functions. **creat**, **stat**, **chown**, etc. For ease of
|
||||
configuration in mergerfs, most of the core functions are grouped into
|
||||
3 categories: **action**, **create**, and **search**. These functions
|
||||
and categories can be assigned a policy which dictates which branch is
|
||||
chosen when performing that function.
|
||||
|
||||
Some functions, listed in the category `N/A` below, can not be
|
||||
assigned the normal policies because they are directly related to a
|
||||
file which has already been opened.
|
||||
|
||||
When using policies which are based on a branch's available space the
|
||||
base path provided is used. Not the full path to the file in
|
||||
question. Meaning that mounts in the branch won't be considered in the
|
||||
space calculations. The reason is that it doesn't really work for
|
||||
non-path preserving policies and can lead to non-obvious behaviors.
|
||||
|
||||
NOTE: While any policy can be assigned to a function or category,
|
||||
some may not be very useful in practice. For instance: **rand**
|
||||
(random) may be useful for file creation (create) but could lead to
|
||||
very odd behavior if used for `chmod` if there were more than one copy
|
||||
of the file.
|
||||
|
||||
## Functions and their Category classifications
|
||||
|
||||
| Category | Functions |
|
||||
| -------- | --------- |
|
||||
| action | chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate, unlink, utimens |
|
||||
| create | create, mkdir, mknod, symlink |
|
||||
| search | access, getattr, getxattr, ioctl (directories), listxattr, open, readlink |
|
||||
| N/A | fchmod, fchown, futimens, ftruncate, fallocate, fgetattr, fsync, ioctl (files), read, readdir, release, statfs, write, copy_file_range |
|
||||
|
||||
In cases where something may be searched for (such as a path to clone)
|
||||
**getattr** will usually be used.
|
||||
|
||||
## Policies
|
||||
|
||||
A policy is the algorithm used to choose a branch or branches for a
|
||||
function to work on or generally how the function behaves.
|
||||
|
||||
Any function in the `create` category will clone the relative path if
|
||||
needed. Some other functions (`rename`,`link`,`ioctl`) have special
|
||||
requirements or behaviors which you can read more about below.
|
||||
|
||||
## Filtering
|
||||
|
||||
Most policies basically search branches and create a list of files / paths
|
||||
for functions to work on. The policy is responsible for filtering and
|
||||
sorting the branches. Filters include **minfreespace**, whether or not
|
||||
a branch is mounted read-only, and the branch tagging
|
||||
(RO,NC,RW). These filters are applied across most policies.
|
||||
|
||||
- No **search** function policies filter.
|
||||
- All **action** function policies filter out branches which are
|
||||
mounted **read-only** or tagged as **RO (read-only)**.
|
||||
- All **create** function policies filter out branches which are
|
||||
mounted **read-only**, tagged **RO (read-only)** or **NC (no
|
||||
create)**, or has available space less than `minfreespace`.
|
||||
|
||||
Policies may have their own additional filtering such as those that
|
||||
require existing paths to be present.
|
||||
|
||||
If all branches are filtered an error will be returned. Typically
|
||||
**EROFS** (read-only filesystem) or **ENOSPC** (no space left on
|
||||
device) depending on the most recent reason for filtering a
|
||||
branch. **ENOENT** will be returned if no eligible branch is found.
|
||||
|
||||
If **create**, **mkdir**, **mknod**, or **symlink** fail with `EROFS`
|
||||
or other fundamental errors then mergerfs will mark any branch found
|
||||
to be read-only as such (IE will set the mode `RO`) and will rerun the
|
||||
policy and try again. This is mostly for `ext4` filesystems that can
|
||||
suddenly become read-only when it encounters an error.
|
||||
|
||||
## Path Preservation
|
||||
|
||||
Policies, as described below, are of two basic classifications. `path
|
||||
preserving` and `non-path preserving`.
|
||||
|
||||
All policies which start with `ep` (**epff**, **eplfs**, **eplus**,
|
||||
**epmfs**, **eprand**) are `path preserving`. `ep` stands for
|
||||
`existing path`.
|
||||
|
||||
A path preserving policy will only consider branches where the relative
|
||||
path being accessed already exists.
|
||||
|
||||
When using non-path preserving policies paths will be cloned to target
|
||||
branches as necessary.
|
||||
|
||||
With the `msp` or `most shared path` policies they are defined as
|
||||
`path preserving` for the purpose of controlling `link` and `rename`'s
|
||||
behaviors since `ignorepponrename` is available to disable that
|
||||
behavior.
|
||||
|
||||
## Policy descriptions
|
||||
|
||||
A policy's behavior differs, as mentioned above, based on the function
|
||||
it is used with. Sometimes it really might not make sense to even
|
||||
offer certain policies because they are literally the same as others
|
||||
but it makes things a bit more uniform.
|
||||
|
||||
| Policy | Description |
|
||||
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| all | Search: For **mkdir**, **mknod**, and **symlink** it will apply to all branches. **create** works like **ff**. |
|
||||
| epall (existing path, all) | For **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **epff** (but more expensive because it doesn't stop after finding a valid branch). |
|
||||
| epff (existing path, first found) | Given the order of the branches, as defined at mount time or configured at runtime, act on the first one found where the relative path exists. |
|
||||
| eplfs (existing path, least free space) | Of all the branches on which the relative path exists choose the branch with the least free space. |
|
||||
| eplus (existing path, least used space) | Of all the branches on which the relative path exists choose the branch with the least used space. |
|
||||
| epmfs (existing path, most free space) | Of all the branches on which the relative path exists choose the branch with the most free space. |
|
||||
| eppfrd (existing path, percentage free random distribution) | Like **pfrd** but limited to existing paths. |
|
||||
| eprand (existing path, random) | Calls **epall** and then randomizes. Returns 1. |
|
||||
| ff (first found) | Given the order of the branches, as defined at mount time or configured at runtime, act on the first one found. |
|
||||
| lfs (least free space) | Pick the branch with the least available free space. |
|
||||
| lus (least used space) | Pick the branch with the least used space. |
|
||||
| mfs (most free space) | Pick the branch with the most available free space. |
|
||||
| msplfs (most shared path, least free space) | Like **eplfs** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| msplus (most shared path, least used space) | Like **eplus** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| mspmfs (most shared path, most free space) | Like **epmfs** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| msppfrd (most shared path, percentage free random distribution) | Like **eppfrd** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| newest | Pick the file / directory with the largest mtime. |
|
||||
| pfrd (percentage free random distribution) | Chooses a branch at random with the likelihood of selection based on a branch's available space relative to the total. |
|
||||
| rand (random) | Calls **all** and then randomizes. Returns 1 branch. |
|
||||
|
||||
**NOTE:** If you are using an underlying filesystem that reserves
|
||||
blocks such as ext2, ext3, or ext4 be aware that mergerfs respects the
|
||||
reservation by using `f_bavail` (number of free blocks for
|
||||
unprivileged users) rather than `f_bfree` (number of free blocks) in
|
||||
policy calculations. **df** does NOT use `f_bavail`, it uses
|
||||
`f_bfree`, so direct comparisons between **df** output and mergerfs'
|
||||
policies is not appropriate.
|
||||
|
||||
## Defaults
|
||||
|
||||
| Category | Policy |
|
||||
| -------- | ------ |
|
||||
| action | epall |
|
||||
| create | epmfs |
|
||||
| search | ff |
|
||||
@@ -0,0 +1,49 @@
|
||||
# fuse_msg_size
|
||||
|
||||
* `fuse_msg_size=UINT|SIZE`
|
||||
* Defaults to `1M`
|
||||
* Performance improvements often peak at about `4M`
|
||||
|
||||
FUSE applications communicate with the kernel over a special character
|
||||
device: `/dev/fuse`. A large portion of the overhead associated with
|
||||
FUSE is the cost of going back and forth between user space and kernel
|
||||
space over that device. Generally speaking, the fewer trips needed the
|
||||
better the performance will be. Reducing the number of trips can be
|
||||
done a number of ways. Kernel level caching and increasing message
|
||||
sizes being two significant ones. When it comes to reads and writes if
|
||||
the message size is doubled the number of trips are approximately
|
||||
halved.
|
||||
|
||||
In Linux v4.20 a new feature was added allowing the negotiation of the
|
||||
max message size. Since the size is in multiples of
|
||||
[pages](https://en.wikipedia.org/wiki/Page_(computer_memory)) the
|
||||
feature is called `max_pages`. In versions of Linux prior to v6.13
|
||||
there is a maximum `max_pages` value of 256 (1MiB) and minimum of 1
|
||||
(4KiB). In [Linux
|
||||
v6.13](https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2b3933b1e0a0a4b758fbc164bb31db0c113a7e2c)
|
||||
and above the max value supported by the kernel can range from 1
|
||||
(4KiB) to 65535 (~256MiB) (assuming a page size of 4KiB.) The default
|
||||
used by Linux >= 4.20, and hard coded value used before 4.20, is 32
|
||||
(128KiB). In mergerfs it is referred to as `fuse_msg_size` to make it
|
||||
clear what it impacts and provide some abstraction.
|
||||
|
||||
If the `fuse_msg_size` value provided is more than the system wide
|
||||
maximum mergerfs will attempt to increase the system wide value to keep
|
||||
the user from needing to set the value using `sysctl`,
|
||||
`/etc/sysctl.conf`, or `/proc/sys/fs/fuse/max_pages_limit`.
|
||||
|
||||
The main downside to increasing the value is that memory usage will
|
||||
increase approximately relative to the number of [processing
|
||||
threads](threads.md) configured. Keep this in mind for systems with
|
||||
lower amounts of memory like most SBCs. Performance improvements seem
|
||||
to peak around 4MiB.
|
||||
|
||||
On kernels before v4.20 the option has no effect. On kernels between
|
||||
v4.20 and v6.13 the max value is 256. On kernels >= v6.13 the maximum
|
||||
value is 65535.
|
||||
|
||||
Since page size can differ between systems mergerfs can take a value in
|
||||
bytes and will convert it to the proper number of pages (rounded up).
|
||||
|
||||
NOTE: If you intend to enable `cache.files` you should also set
|
||||
[readahead](readahead.md) to match `fuse_msg_size`.
|
||||
@@ -0,0 +1,75 @@
|
||||
# inodecalc
|
||||
|
||||
Inodes (`st_ino`) are unique identifiers within a filesystem. Each
|
||||
mounted filesystem has device ID (st_dev) as well and together they
|
||||
can uniquely identify a file on the whole of the system. Entries on
|
||||
the same device with the same inode are in fact references to the same
|
||||
underlying file. It is a many to one relationship between names and an
|
||||
inode. Directories, however, do not have multiple links on most
|
||||
systems due to the complexity they add.
|
||||
|
||||
FUSE allows the server (mergerfs) to set inode values but not device
|
||||
IDs. Creating an inode value is somewhat complex in mergerfs' case as
|
||||
files aren't really in its control. If a policy changes what directory
|
||||
or file is to be selected or something changes out of band it becomes
|
||||
unclear what value should be used. Most software does not to care what
|
||||
the values are but those that do often break if a value changes
|
||||
unexpectedly. The tool find will abort a directory walk if it sees a
|
||||
directory inode change. NFS can return stale handle errors if the
|
||||
inode changes out of band. File dedup tools will usually leverage
|
||||
device ids and inodes as a shortcut in searching for duplicate files
|
||||
and would resort to full file comparisons should it find different
|
||||
inode values.
|
||||
|
||||
mergerfs offers multiple ways to calculate the inode in hopes of
|
||||
covering different usecases.
|
||||
|
||||
* `passthrough`: Passes through the underlying inode value. Mostly
|
||||
intended for testing as using this does not address any of the
|
||||
problems mentioned above and could confuse file deduplication
|
||||
software as inodes from different filesystems can be the same.
|
||||
* `path-hash`: Hashes the relative path of the entry in question. The
|
||||
underlying file's values are completely ignored. This means the
|
||||
inode value will always be the same for that file path. This is
|
||||
useful when using NFS and you make changes out of band such as copy
|
||||
data between branches. This also means that entries that do point to
|
||||
the same file will not be recognizable via inodes. That does not
|
||||
mean hard links don't work. They will.
|
||||
* `path-hash32`: 32bit version of path-hash.
|
||||
* `devino-hash`: Hashes the device id and inode of the underlying
|
||||
entry. This won't prevent issues with NFS should the policy pick a
|
||||
different file or files move out of band but will present the same
|
||||
inode for underlying files that do too.
|
||||
* `devino-hash32`: 32bit version of devino-hash.
|
||||
* `hybrid-hash`: Performs path-hash on directories and devino-hash on
|
||||
other file types. Since directories can't have hard links the static
|
||||
value won't make a difference and the files will get values useful
|
||||
for finding duplicates. Probably the best to use if not using
|
||||
NFS. As such it is the default.
|
||||
* `hybrid-hash32`: 32bit version of hybrid-hash.
|
||||
|
||||
32bit versions are provided as there is some software which does not
|
||||
handle 64bit inodes well.
|
||||
|
||||
While there is a risk of hash collision in tests of a couple of
|
||||
million entries there were zero collisions. Unlike a typical
|
||||
filesystem FUSE filesystems can reuse inodes and not refer to the same
|
||||
entry. The internal identifier used to reference a file in FUSE is
|
||||
different from the inode value presented. The former is the nodeid and
|
||||
is actually a tuple of 2 64bit values: nodeid and generation. This
|
||||
tuple is not client facing. The inode that is presented to the client
|
||||
is passed through the kernel uninterpreted.
|
||||
|
||||
From FUSE docs for `use_ino`:
|
||||
|
||||
> Honor the st_ino field in the functions getattr() and
|
||||
> fill_dir(). This value is used to fill in the st_ino field
|
||||
> in the stat(2), lstat(2), fstat(2) functions and the d_ino
|
||||
> field in the readdir(2) function. The filesystem does not
|
||||
> have to guarantee uniqueness, however some applications
|
||||
> rely on this value being unique for the whole filesystem.
|
||||
> Note that this does *not* affect the inode that libfuse
|
||||
> and the kernel use internally (also called the "nodeid").
|
||||
|
||||
**NOTE:** As of version 2.35.0 the use_ino option has been
|
||||
removed. mergerfs should always be managing inode values.
|
||||
@@ -0,0 +1,17 @@
|
||||
# link-exdev
|
||||
|
||||
If using path preservation and a `link` fails with `EXDEV` make a call
|
||||
to `symlink` where the target is the `oldlink` and the `linkpath` is
|
||||
the newpath. The target value is determined by the value of
|
||||
`link-exdev`.
|
||||
|
||||
* `link-exdev=passthrough`: Return EXDEV as normal.
|
||||
* `link-exdev=rel-symlink`: A relative path from the newpath.
|
||||
* `link-exdev=abs-base-symlink`: An absolute value using the
|
||||
underlying branch.
|
||||
* `link-exdev=abs-pool-symlink`: An absolute value using the mergerfs
|
||||
mount point.
|
||||
* Defaults to `passthrough`.
|
||||
|
||||
**NOTE:** It is possible that some applications check the file they
|
||||
link. In those cases, it is possible it will error or complain.
|
||||
@@ -0,0 +1,13 @@
|
||||
# link_cow
|
||||
|
||||
* `link_cow=true|false`
|
||||
* Defaults to `false`
|
||||
|
||||
This feature offers similar functionality to what
|
||||
[cow-shell](https://manpages.ubuntu.com/manpages/noble/man1/cow-shell.1.html)
|
||||
offers.
|
||||
|
||||
When enabled if mergerfs is asked to open a file to write and the link
|
||||
count on the file is greater than 1 it will copy the file to a
|
||||
temporary new file and then rename it over the original. This will
|
||||
atomically "break" the link. After that it will open the new file.
|
||||
@@ -0,0 +1,26 @@
|
||||
# nfsopenhack
|
||||
|
||||
* `nfsopenhack=off`: No hack applied.
|
||||
* `nfsopenhack=git`: Apply hack if path includes `/.git/`.
|
||||
* `nfsopenhack=all`: Apply hack on all empty read-only files opened
|
||||
for writing.
|
||||
* Defaults to `off`.
|
||||
|
||||
NFS is not fully POSIX compliant and historically certain behaviors,
|
||||
such as opening files with `O_EXCL`, are not or not well
|
||||
supported. When mergerfs (or any FUSE filesystem) is exported over NFS
|
||||
some of these issues come up due to how NFS and FUSE interact.
|
||||
|
||||
This hack addresses the issue where the creation of a file with a
|
||||
read-only mode but with a read/write or write only flag. Normally this
|
||||
is perfectly valid but NFS chops the one open call into multiple
|
||||
calls. Exactly how it is translated depends on the configuration and
|
||||
versions of the NFS server and clients but it results in a permission
|
||||
error because a normal user is not allowed to open a read-only file as
|
||||
writable.
|
||||
|
||||
Even though it's a more niche situation this hack breaks normal
|
||||
security and behavior and as such is `off` by default. If set to `git`
|
||||
it will only perform the hack when the path in question includes
|
||||
`/.git/`. `all` will result in it applying anytime a read-only file
|
||||
which is empty is opened for writing.
|
||||
@@ -0,0 +1,20 @@
|
||||
# nullrw
|
||||
|
||||
* `nullrw=true|false`
|
||||
* Defaults to `false`.
|
||||
|
||||
Due to how FUSE works there is an overhead to all requests made to a
|
||||
FUSE filesystem that wouldn't exist for an in kernel one. Meaning that
|
||||
even a simple passthrough will have some slowdown. However, generally
|
||||
the overhead is minimal in comparison to the cost of the underlying
|
||||
I/O. By disabling the underlying I/O we can test the theoretical
|
||||
performance boundaries.
|
||||
|
||||
By enabling `nullrw` mergerfs will work as it always does **except**
|
||||
that all reads and writes will be no-ops. A write will succeed (the
|
||||
size of the write will be returned as if it were successful) but
|
||||
mergerfs does nothing with the data it was given. Similarly a read
|
||||
will return the size requested but won't touch the buffer.
|
||||
|
||||
See the [benchmarking](../benchmarking.md) section for suggestions on
|
||||
how to test.
|
||||
@@ -0,0 +1,197 @@
|
||||
# Options
|
||||
|
||||
These options are the same regardless of whether you use them with the
|
||||
`mergerfs` commandline program, in fstab, or in a config file.
|
||||
|
||||
### types
|
||||
|
||||
- BOOL = 'true' | 'false'
|
||||
- INT = [MIN_INT,MAX_INT]
|
||||
- UINT = [0,MAX_INT]
|
||||
- SIZE = 'NNM'; NN = INT, M = 'B' | 'K' | 'M' | 'G' | 'T'
|
||||
- PAGESIZE = UINT (representing number of pages) | SIZE (in bytes
|
||||
which will be converted to pages)
|
||||
- STR = string (may refer to an enumerated value, see details of
|
||||
argument)
|
||||
- FUNC = filesystem function
|
||||
- CATEGORY = function category
|
||||
- POLICY = mergerfs function policy
|
||||
|
||||
|
||||
### mount options
|
||||
|
||||
- **config**: Path to a config file. Same arguments as below in
|
||||
key=val / ini style format.
|
||||
- **[branches](branches.md)**: Colon delimited list of branches. Used
|
||||
primarily in config file.
|
||||
- **minfreespace=SIZE**: The minimum available space of a branch
|
||||
necessary to be considered for a create
|
||||
[policy](functions_categories_policies.md). This is a default value
|
||||
applied to all branches and can be overwritten when configuring
|
||||
[branches](branches.md). Understands 'K', 'M', and 'G' to represent
|
||||
kilobyte, megabyte, and gigabyte respectively. (default: 4G)
|
||||
- **moveonenospc=BOOL|POLICY**: When enabled if a **write** fails with
|
||||
**ENOSPC** (no space left on device) or **EDQUOT** (disk quota
|
||||
exceeded) the policy selected will run to find a new location for
|
||||
the file. An attempt to move the file to that branch will occur
|
||||
(keeping all metadata possible) and if successful the original is
|
||||
unlinked and the write retried. (default: false, true = mfs)
|
||||
- **[inodecalc](inodecalc.md)=passthrough|path-hash|devino-hash|hybrid-hash**:
|
||||
Selects the inode calculation algorithm. (default: hybrid-hash)
|
||||
- **dropcacheonclose=BOOL**: When a file is requested to be closed
|
||||
call `posix_fadvise` on it first to instruct the kernel that we no
|
||||
longer need the data and it can drop its cache. Recommended when
|
||||
**cache.files=partial|full|auto-full|per-process** to limit double
|
||||
caching. (default: false)
|
||||
- **direct-io-allow-mmap=BOOL**: On newer kernels (>= 6.6) it is
|
||||
possible to disable file page caching while still allowing for
|
||||
shared mmap support. mergerfs will enable this feature if available
|
||||
but an option is provided to turn it off for testing and debugging
|
||||
purposes. (default: true)
|
||||
- **[symlinkify](symlinkify.md)=BOOL**: When enabled and a file is not
|
||||
writable and its mtime or ctime is older than **symlinkify_timeout**
|
||||
files will be reported as symlinks to the original files. Please
|
||||
read more below before using. (default: false)
|
||||
- **[symlinkify_timeout](symlinkify.md)=UINT**: Time to wait, in
|
||||
seconds, to activate the **symlinkify** behavior. (default: 3600)
|
||||
- **nullrw=BOOL**: Turns reads and writes into no-ops. The request
|
||||
will succeed but do nothing. Useful for benchmarking
|
||||
mergerfs. (default: false)
|
||||
- **lazy-umount-mountpoint=BOOL**: mergerfs will attempt to "lazy
|
||||
umount" the mountpoint before mounting itself. Useful when
|
||||
performing live upgrades of mergerfs. May not work on
|
||||
FreeBSD. (default: false)
|
||||
- **ignorepponrename=BOOL**: Ignore path preserving on
|
||||
rename. Typically rename and link act differently depending on the
|
||||
policy of `create` (read below). Enabling this will cause rename and
|
||||
link to always use the non-path preserving behavior. This means
|
||||
files, when renamed or linked, will stay on the same
|
||||
filesystem. (default: false)
|
||||
- **[export-support](export-support.md)=BOOL**: Sets a low-level FUSE
|
||||
feature intended to indicate the filesystem can support being
|
||||
exported via NFS. (default: true)
|
||||
- **security_capability=BOOL**: If false return ENOATTR when xattr
|
||||
security.capability is queried. (default: true)
|
||||
- **[xattr](xattr.md)=passthrough|noattr|nosys**: Runtime control of
|
||||
xattrs. Default is to passthrough xattr requests. 'noattr' will
|
||||
short circuit as if nothing exists. 'nosys' will respond with ENOSYS
|
||||
as if xattrs are not supported or disabled. (default: passthrough)
|
||||
- **[link_cow](link_cow.md)=BOOL**: When enabled if a regular file is
|
||||
opened which has a link count > 1 it will copy the file to a
|
||||
temporary file and rename over the original. Breaking the link and
|
||||
providing a basic copy-on-write function similar to
|
||||
cow-shell. (default: false)
|
||||
- **[statfs](statfs.md)=base|full**: Controls how statfs works. 'base'
|
||||
means it will always use all branches in statfs calculations. 'full'
|
||||
is in effect path preserving and only includes branches where the
|
||||
path exists. (default: base)
|
||||
- **statfs_ignore=none|ro|nc**: 'ro' will cause statfs calculations to
|
||||
ignore available space for branches mounted or tagged as 'read-only'
|
||||
or 'no create'. 'nc' will ignore available space for branches tagged
|
||||
as 'no create'. (default: none)
|
||||
- **nfsopenhack=off|git|all**: A workaround for exporting mergerfs
|
||||
over NFS where there are issues with creating files for write while
|
||||
setting the mode to read-only. (default: off)
|
||||
- **branches-mount-timeout=UINT**: Number of seconds to wait at
|
||||
startup for branches to be a mount other than the mountpoint's
|
||||
filesystem. (default: 0)
|
||||
- **[follow-symlinks](follow-symlinks.md)=never|directory|regular|all**:
|
||||
Turns symlinks into what they point to. (default: never)
|
||||
- **[link-exdev](link-exdev.md)=passthrough|rel-symlink|abs-base-symlink|abs-pool-symlink**:
|
||||
When a link fails with EXDEV optionally create a symlink to the file
|
||||
instead.
|
||||
- **[rename-exdev](rename-exdev.md)=passthrough|rel-symlink|abs-symlink**:
|
||||
When a rename fails with EXDEV optionally move the file to a special
|
||||
directory and symlink to it.
|
||||
- **[readahead](readahead.md)=UINT**: Set readahead (in kilobytes) for
|
||||
mergerfs and branches if greater than 0. (default: 0)
|
||||
- **posix_acl=BOOL**: Enable POSIX ACL support (if supported by kernel
|
||||
and underlying filesystem). (default: false)
|
||||
- **async_read=BOOL**: Perform reads asynchronously. If disabled or
|
||||
unavailable the kernel will ensure there is at most one pending read
|
||||
request per file handle and will attempt to order requests by
|
||||
offset. (default: true)
|
||||
- **[fuse_msg_size](fuse_msg_size.md)=PAGESIZE**: Set the max number of
|
||||
pages per FUSE message. Only available on Linux >= 4.20 and ignored
|
||||
otherwise. (min: 1; max: 65535; default: "1M")
|
||||
- **[threads](threads.md)=INT**: Number of threads to use. When used
|
||||
alone (`process-thread-count=-1`) it sets the number of threads
|
||||
reading and processing FUSE messages. When used together it sets the
|
||||
number of threads reading from FUSE. When set to zero it will
|
||||
attempt to discover and use the number of logical cores. If the
|
||||
thread count is set negative it will look up the number of cores
|
||||
then divide by the absolute value. ie. threads=-2 on an 8 core
|
||||
machine will result in 8 / 2 = 4 threads. There will always be at
|
||||
least 1 thread. If set to -1 in combination with
|
||||
`process-thread-count` then it will try to pick reasonable values
|
||||
based on CPU thread count. NOTE: higher number of threads increases
|
||||
parallelism but usually decreases throughput. (default: 0)
|
||||
- **[read-thread-count](threads.md)=INT**: Alias for `threads`.
|
||||
- **[process-thread-count](threads.md)=INT**: Enables separate thread
|
||||
pool to asynchronously process FUSE requests. In this mode
|
||||
`read-thread-count` refers to the number of threads reading FUSE
|
||||
messages which are dispatched to process threads. -1 means disabled
|
||||
otherwise acts like `read-thread-count`. (default: -1)
|
||||
- **[process-thread-queue-depth](threads.md)=UINT**: Sets the number
|
||||
of requests any single process thread can have queued up at one
|
||||
time. Meaning the total memory usage of the queues is queue depth
|
||||
multiplied by the number of process threads plus read thread
|
||||
count. 0 sets the depth to the same as the process thread
|
||||
count. (default: 0)
|
||||
- **[pin-threads](pin-threads.md)=STR**: Selects a strategy to pin
|
||||
threads to CPUs (default: unset)
|
||||
- **[flush-on-close](flush-on-close.md)=never|always|opened-for-write**:
|
||||
Flush data cache on file close. Mostly for when writeback is enabled
|
||||
or merging network filesystems. (default: opened-for-write)
|
||||
- **scheduling-priority=INT**: Set mergerfs' scheduling
|
||||
priority. Valid values range from -20 to 19. See `setpriority` man
|
||||
page for more details. (default: -10)
|
||||
- **fsname=STR**: Sets the name of the filesystem as seen in
|
||||
**mount**, **df**, etc. Defaults to a list of the source paths
|
||||
concatenated together with the longest common prefix removed.
|
||||
- **[func.FUNC](functions_categories_policies.md)=POLICY**: Sets the
|
||||
specific FUSE function's policy. See below for the list of value
|
||||
types. Example: **func.getattr=newest**
|
||||
- **[func.readdir](func_readdir.md)=seq|cosr|cor|cosr:INT|cor:INT**: Sets `readdir`
|
||||
policy. INT value sets the number of threads to use for
|
||||
concurrency. (default: seq)
|
||||
- **[category.action](functions_categories_policies.md)=POLICY**: Sets
|
||||
policy of all FUSE functions in the action category. (default:
|
||||
epall)
|
||||
- **[category.create](functions_categories_policies.md)=POLICY**: Sets
|
||||
policy of all FUSE functions in the create category. (default:
|
||||
epmfs)
|
||||
- **[category.search](functions_categories_policies.md)=POLICY**: Sets
|
||||
policy of all FUSE functions in the search category. (default: ff)
|
||||
- **[cache.statfs](cache.md#cachestatfs)=UINT**: 'statfs' cache
|
||||
timeout in seconds. (default: 0)
|
||||
- **[cache.attr](cache.md#cacheattr)=UINT**: File attribute cache
|
||||
timeout in seconds. (default: 1)
|
||||
- **[cache.entry](cache.md#cacheentry)=UINT**: File name lookup cache
|
||||
timeout in seconds. (default: 1)
|
||||
- **[cache.negative_entry](cache.md#cachenegative_entry)=UINT**:
|
||||
Negative file name lookup cache timeout in seconds. (default: 0)
|
||||
- **[cache.files](cache.md#cachefiles)=libfuse|off|partial|full|auto-full|per-process**:
|
||||
File page caching mode (default: libfuse)
|
||||
- **cache.files.process-names=LIST**: A pipe | delimited list of
|
||||
process [comm](https://man7.org/linux/man-pages/man5/proc.5.html)
|
||||
names to enable page caching for when
|
||||
`cache.files=per-process`. (default: "rtorrent|qbittorrent-nox")
|
||||
- **[cache.writeback](cache.md#cachewriteback)=BOOL**: Enable kernel
|
||||
writeback caching (default: false)
|
||||
- **[cache.symlinks](cache.md#cachesymlinks)=BOOL**: Cache symlinks (if
|
||||
supported by kernel) (default: false)
|
||||
- **[cache.readdir](cache.md#cachereaddir)=BOOL**: Cache readdir (if
|
||||
supported by kernel) (default: false)
|
||||
- **parallel-direct-writes=BOOL**: Allow the kernel to dispatch
|
||||
multiple, parallel (non-extending) write requests for files opened
|
||||
with `cache.files=per-process` (if the process is not in
|
||||
`process-names`) or `cache.files=off`. (Is a kernel feature added in
|
||||
v6.2) (default: true)
|
||||
|
||||
**NOTE:** Options are evaluated in the order listed so if the options
|
||||
are **func.rmdir=rand,category.action=ff** the **action** category
|
||||
setting will override the **rmdir** setting.
|
||||
|
||||
**NOTE:** Always look at the documentation for the version of mergerfs
|
||||
you're using. Not all features are available in older releases.
|
||||
@@ -0,0 +1,23 @@
|
||||
# pin-threads
|
||||
|
||||
Simple strategies for pinning read and/or process threads. If process
|
||||
threads are not enabled then the strategy simply works on the read
|
||||
threads. Invalid values are ignored.
|
||||
|
||||
* `pin-threads=R1L`: All read threads pinned to a single logical CPU.
|
||||
* `pin-threads=R1P`: All read threads pinned to a single physical CPU.
|
||||
* `pin-threads=RP1L`: All read and process threads pinned to a single logical CPU.
|
||||
* `pin-threads=RP1P`: All read and process threads pinned to a single physical CPU.
|
||||
* `pin-threads=R1LP1L`: All read threads pinned to a single logical
|
||||
CPU, all process threads pinned to a (if possible) different logical
|
||||
CPU.
|
||||
* `pin-threads=R1PP1P`: All read threads pinned to a single physical
|
||||
CPU, all process threads pinned to a (if possible) different logical
|
||||
CPU.
|
||||
* `pin-threads=RPSL`: All read and process threads are spread across
|
||||
all logical CPUs.
|
||||
* `pin-threads=RPSP`: All read and process threads are spread across
|
||||
all physical CPUs.
|
||||
* `pin-threads=R1PPSP`: All read threads are pinned to a single
|
||||
physical CPU while process threads are spread across all other
|
||||
physical CPUs.
|
||||
@@ -0,0 +1,40 @@
|
||||
# readahead
|
||||
|
||||
Sets the mergerfs and underlying filesystem `readahead` values. The
|
||||
value unit is in kibibytes.
|
||||
|
||||
* `readahead=1024`
|
||||
|
||||
While the max size of messages sent between the kernel and mergerfs is
|
||||
configurable via the [fuse_msg_size](fuse_msg_size.md) option that
|
||||
doesn't mean that is the size used by the kernel for read and
|
||||
writes.
|
||||
|
||||
Linux has a max read/write size of 2GB. Since the max FUSE message
|
||||
size is just over 1MiB (by default on more recent kernels) the kernel
|
||||
will break up read and write requests with buffers larger than that
|
||||
1MiB.
|
||||
|
||||
When page caching is disabled (`cache.files=off`), besides the kernel
|
||||
breaking up requests with larger buffers, requests are effectively one
|
||||
for one to mergerfs. A read or write request for X bytes is made to
|
||||
the kernel and a request for X bytes is made to mergerfs. No
|
||||
[readahead](https://en.wikipedia.org/wiki/Readahead) behavior will
|
||||
occur because there is no page cache available for it to store that
|
||||
data. In FUSE this is referred to as "direct IO". Note that "direct
|
||||
IO" is not the same as `O_DIRECT`.
|
||||
|
||||
When page caching is enabled the kernel can and will utilize
|
||||
`readahead`. However, there are two values which impact the size of
|
||||
the `readahead` requests. The filesystem's `readahead` value and the
|
||||
FUSE `max_readahead` value. Whichever is lowest is used. The default
|
||||
`max_readahead` in mergerfs is maxed out meaning only the filesystem
|
||||
`readahead` value is relevant.
|
||||
|
||||
Preferably this value would be set by the user externally since it is
|
||||
a generic feature but there is no standard way to do so mergerfs added
|
||||
this feature to make it easier to set.
|
||||
|
||||
There is currently no way to set separate values for different
|
||||
branches through mergerfs. In fact at some point the feature may be
|
||||
changed to only set mergerfs' readahead.
|
||||
@@ -0,0 +1,21 @@
|
||||
# rename-exdev
|
||||
|
||||
If using path preservation and a `rename` fails with `EXDEV`:
|
||||
|
||||
1. Move file from `/branch/a/b/c` to `/branch/.mergerfs_rename_exdev/a/b/c`.
|
||||
2. symlink the rename's `newpath` to the moved file.
|
||||
|
||||
The `target` value is determined by the value of `rename-exdev`.
|
||||
|
||||
* `rename-exdev=passthrough`: Return `EXDEV` as normal.
|
||||
* `rename-exdev=rel-symlink`: A relative path from the `newpath`.
|
||||
* `rename-exdev=abs-symlink`: An absolute value using the mergerfs
|
||||
mount point.
|
||||
* Defaults to `passthrough`.
|
||||
|
||||
**NOTE:** It is possible that some applications check the file they
|
||||
rename. In those cases it is possible it will error or complain.
|
||||
|
||||
**NOTE:** The reason `abs-symlink` is not split into two like
|
||||
`link-exdev` is due to the complexities in managing absolute base
|
||||
symlinks when multiple `oldpaths` exist.
|
||||
@@ -0,0 +1,60 @@
|
||||
# rename and link
|
||||
|
||||
`rename` and `link` are arguably the most complicated functions to
|
||||
create in a union filesystem. `rename` only works within a single
|
||||
filesystem or device. If a `rename` can not be done due to the source
|
||||
and destination paths existing on different mount points it will
|
||||
return an error (EXDEV, cross device / improper link). So if a
|
||||
`rename`'s source and target are on different filesystems within the
|
||||
pool it creates an issue.
|
||||
|
||||
Originally mergerfs would return EXDEV whenever a rename was requested
|
||||
which was cross directory in any way. This made the code simple and
|
||||
was technically compliant with POSIX requirements. However, many
|
||||
applications fail to handle EXDEV at all and treat it as a normal
|
||||
error or otherwise handle it poorly. Such apps include: gvfsd-fuse
|
||||
v1.20.3 and prior, Finder / CIFS/SMB client in Apple OSX 10.9+,
|
||||
NZBGet, Samba's recycling bin feature.
|
||||
|
||||
As a result a compromise was made in order to get most software to
|
||||
work while still obeying mergerfs' policies. The behavior is explained
|
||||
below.
|
||||
|
||||
* If using a **create** policy which tries to preserve directory paths (epff,eplfs,eplus,epmfs)
|
||||
* Using the **rename** policy get the list of files to rename
|
||||
* For each file attempt rename:
|
||||
* If failure with ENOENT (no such file or directory) run **create** policy
|
||||
* If create policy returns the same branch as currently evaluating then clone the path
|
||||
* Re-attempt rename
|
||||
* If **any** of the renames succeed the higher level rename is considered a success
|
||||
* If **no** renames succeed the first error encountered will be returned
|
||||
* On success:
|
||||
* Remove the target from all branches with no source file
|
||||
* Remove the source from all branches which failed to rename
|
||||
* If using a **create** policy which does **not** try to preserve directory paths
|
||||
* Using the **rename** policy get the list of files to rename
|
||||
* Using the **getattr** policy get the target path
|
||||
* For each file attempt rename:
|
||||
* If the target path does not exist on the source branch:
|
||||
* Clone target path from target branch to source branch
|
||||
* rename
|
||||
* If **any** of the renames succeed the higher level rename is considered a success
|
||||
* If **no** renames succeed the first error encountered will be returned
|
||||
* On success:
|
||||
* Remove the target from all branches with no source file
|
||||
* Remove the source from all branches which failed to rename
|
||||
|
||||
The removals are subject to normal entitlement checks. If the unlink
|
||||
fails it will fail silently.
|
||||
|
||||
The above behavior will help minimize the likelihood of EXDEV being
|
||||
returned but it will still be possible.
|
||||
|
||||
**link** uses the same strategy but without the removals.
|
||||
|
||||
|
||||
## Additional Reading
|
||||
|
||||
* [Do hardlinks work?](../faq/technical_behavior_and_limitations.md#do-hardlinks-work)
|
||||
* [How does mergerfs handle moving and copying of files?](../faq/technical_behavior_and_limitations.md#how-does-mergerfs-handle-moving-and-copying-of-files)
|
||||
* [Why are file moves and renames failing?](../faq/why_isnt_it_working.md#why-are-file-moves-renames-linkshardlinks-failing)
|
||||
@@ -0,0 +1,26 @@
|
||||
# statfs / statvfs
|
||||
|
||||
* `statfs=base`: Aggregate details from all branches using their base directory.
|
||||
* `statfs=full`: Aggregate details using the full path of the file
|
||||
requested. Limiting it to only branches where the file exists.
|
||||
* Defaults to `base`.
|
||||
|
||||
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source
|
||||
filesystems 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 filesystem so multiple sources on the same drive will not result in
|
||||
double counting its space. Other filesystems mounted further down the tree
|
||||
of the branch will not be included when checking the mount's stats.
|
||||
|
||||
## statfs_ignore
|
||||
|
||||
Modifies how `statfs` works. Will cause it to ignore branches of a
|
||||
certain mode.
|
||||
|
||||
* `statfs_ignore=none`: Include all branches.
|
||||
* `statfs_ignore=ro`: Ignore available space for branches mounted as
|
||||
read-only or have a mode `RO` or `NC`.
|
||||
* `statfs_ignore=nc`: Ignore available space for branches with a mode
|
||||
of `NC`.
|
||||
* Defaults to `none`.
|
||||
@@ -0,0 +1,23 @@
|
||||
# symlinkify
|
||||
|
||||
* `symlinkify=true|false`
|
||||
* Defaults to `false`.
|
||||
|
||||
Due to the levels of indirection introduced by mergerfs and the
|
||||
underlying technology FUSE there can be varying levels of performance
|
||||
degradation. This feature will turn non-directories which are not
|
||||
writable into symlinks to the original file found by the `readlink`
|
||||
policy after the mtime and ctime are older than the timeout.
|
||||
|
||||
**WARNING:** The current implementation has a known issue in which if
|
||||
the file is open and being used when the file is converted to a
|
||||
symlink then the application which has that file open will receive an
|
||||
error when using it. This is unlikely to occur in practice but is
|
||||
something to keep in mind.
|
||||
|
||||
**WARNING:** Some backup solutions, such as CrashPlan, do not backup
|
||||
the target of a symlink. If using this feature it will be necessary to
|
||||
point any backup software to the original filesystems or configure the
|
||||
software to follow symlinks if such an option is
|
||||
available. Alternatively, create two mounts. One for backup and one
|
||||
for general consumption.
|
||||
@@ -0,0 +1,53 @@
|
||||
# threads
|
||||
|
||||
There are multiple thread pools used in mergerfs to provide
|
||||
parallel behaviors.
|
||||
|
||||
|
||||
## read-thread-count
|
||||
|
||||
The number of threads used to read (and possibly process) messages
|
||||
from the kernel.
|
||||
|
||||
* `read-thread-count=0`: Create a thread pool sized to the number of
|
||||
logical CPUs.
|
||||
* `read-thread-count=N` where `N>0`: Create a thread pool of `N` threads.
|
||||
* `read-thread-count=N` where `N<0`: Create a thread pool of `CPUCount /
|
||||
-N` threads.
|
||||
* `read-thread-count=-1` where `process-thread-count=-1`: Creates `2`
|
||||
read threads and `max(2,CPUCount-2)` process threads.
|
||||
* Defaults to `0`.
|
||||
|
||||
When `process-thread-count=-1` (the default) this option sets the
|
||||
number of threads which read and then process requests from the
|
||||
kernel.
|
||||
|
||||
When `process-thread-count` is set to anything else mergerfs will
|
||||
create two thread pools. A "read" thread pool which just reads from
|
||||
the kernel and hands off requests to the "process" thread pool.
|
||||
|
||||
Generally, only 1 or 2 "read" threads are necessary.
|
||||
|
||||
|
||||
## process-thread-count
|
||||
|
||||
When enabled this sets the number of threads in the message processing pool.
|
||||
|
||||
* `process-thread-count=-1`: Process thread pool is disabled.
|
||||
* `process-thread-count=0`: Create a thread pool sized to the number
|
||||
of logical CPUs.
|
||||
* `process-thread-count=N` where `N>0`: Create a thread pool of `N` threads.
|
||||
* `process-thread-count=N` where `N<-1`: Create a thread pool of `CPUCount /
|
||||
-N` threads.
|
||||
* Defaults to `-1`.
|
||||
|
||||
|
||||
## process-thread-queue-depth
|
||||
|
||||
* `process-thread-queue-depth=N` where `N>0`: Sets the number of outstanding
|
||||
requests that a process thread can have to N. If requests come in
|
||||
faster than can be processed and the max queue depth hit then
|
||||
queuing the request will block in order to limit memory growth.
|
||||
* `process-thread-queue-depth=0`: Sets the queue depth to the thread
|
||||
pool count.
|
||||
* Defaults to `0`.
|
||||
@@ -0,0 +1,27 @@
|
||||
# xattr
|
||||
|
||||
* `xattr=passthrough`: Passes through all requests to underlying file.
|
||||
* `xattr=noattr`: mergerfs receives the request but returns `NOATTR`.
|
||||
* `xattr=nosys`: Tells the kernel to reject all `xattr` requests.
|
||||
* Defaults to `passthrough`.
|
||||
|
||||
Runtime extended attribute support can be managed via the `xattr`
|
||||
option. By default it will passthrough any xattr calls. Given xattr
|
||||
support is rarely used and can have significant performance
|
||||
implications mergerfs allows it to be disabled at runtime. The
|
||||
performance problems mostly comes when file caching is enabled. The
|
||||
kernel will send a `getxattr` for `security.capability` *before every
|
||||
single write*. It doesn't cache the responses to any `getxattr`. This
|
||||
might be addressed in the future but for now mergerfs can really only
|
||||
offer the following workarounds.
|
||||
|
||||
`noattr` will cause mergerfs to short circuit all xattr calls and
|
||||
return ENOATTR where appropriate. mergerfs still gets all the requests
|
||||
but they will not be forwarded on to the underlying filesystems. The
|
||||
runtime control will still function in this mode.
|
||||
|
||||
`nosys` will cause mergerfs to return `ENOSYS` for any xattr call. The
|
||||
difference with `noattr` is that the kernel will cache this fact and
|
||||
itself short circuit future calls. This is more efficient than
|
||||
`noattr` but will cause mergerfs' runtime control via the hidden file
|
||||
to stop working.
|
||||
@@ -0,0 +1,52 @@
|
||||
# Error Handling and Logging
|
||||
|
||||
## Error Handling
|
||||
|
||||
POSIX filesystem functions offer a single return code meaning that
|
||||
there is some complication regarding the handling of multiple branches
|
||||
as mergerfs does. It tries to handle errors in a way that would
|
||||
generally return meaningful values for that particular function.
|
||||
|
||||
### chmod, chown, removexattr, setxattr, truncate, utimens
|
||||
|
||||
1. if no error: return 0 (success)
|
||||
2. if no successes: return first error
|
||||
3. if one of the files acted on was the same as the related search function: return its value
|
||||
4. return 0 (success)
|
||||
|
||||
While doing this increases the complexity and cost of error handling,
|
||||
particularly step 3, this provides probably the most reasonable return
|
||||
value.
|
||||
|
||||
### unlink, rmdir
|
||||
|
||||
1. if no errors: return 0 (success)
|
||||
2. return first error
|
||||
|
||||
Older versions of mergerfs would return success if any success occurred
|
||||
but for unlink and rmdir there are downstream assumptions that, while
|
||||
not impossible to occur, can confuse some software.
|
||||
|
||||
### others
|
||||
|
||||
For search functions, there is always a single thing acted on and as
|
||||
such whatever return value that comes from the single function call is
|
||||
returned.
|
||||
|
||||
For create functions `mkdir`, `mknod`, and `symlink` which don't
|
||||
return a file descriptor and therefore can have `all` or `epall`
|
||||
policies it will return success if any of the calls succeed and an
|
||||
error otherwise.
|
||||
|
||||
|
||||
## Logging
|
||||
|
||||
Filesystems, and therefore mergerfs, are doing lots of small actions
|
||||
at high speed. It simply isn't reasonable to log all the actions of
|
||||
the system. That said: certain details are logged at startup and when
|
||||
performing mainance tasks. These are logged via `syslog` and on
|
||||
`systemd` based systems can be viewed by running
|
||||
|
||||
```
|
||||
journalctl -t mergerfs
|
||||
```
|
||||
@@ -0,0 +1,107 @@
|
||||
# Compatibility and Integration
|
||||
|
||||
## What filesystems can be used as branches?
|
||||
|
||||
ext4, btrfs, xfs, f2fs, zfs, nfs, etc.
|
||||
|
||||
On the surface any filesystem should work but there could be issues
|
||||
with non-POSIX compliant filesystems such as vfat, ntfs, cifs, exfat,
|
||||
etc. When directories need to be created or files moved by mergerfs if
|
||||
the filesystem returns errors due to not supporting certain POSIX
|
||||
filesystem features it could result in the core functions failing.
|
||||
|
||||
Since mergerfs is not generally used with non-POSIX filesystems this
|
||||
has not been a problem for users and there are some checks for known
|
||||
edgecases but it is possible some are not accounted for. If use with a
|
||||
filesystem results in issues please [file a
|
||||
ticket](https://github.com/trapexit/mergerfs/issues) with the details.
|
||||
|
||||
|
||||
## Can I use mergerfs without SnapRAID? SnapRAID without mergerfs?
|
||||
|
||||
Yes. They are completely unrelated pieces of software that just happen
|
||||
to work well together.
|
||||
|
||||
|
||||
## Does mergerfs support CoW / copy-on-write / writes to read-only filesystems?
|
||||
|
||||
Not in the sense of a filesystem like BTRFS or ZFS nor in the
|
||||
overlayfs or aufs sense. It does offer a
|
||||
[cow-shell](http://manpages.ubuntu.com/manpages/bionic/man1/cow-shell.1.html)
|
||||
like hard link breaking (copy to temp file then rename over original)
|
||||
which can be useful when wanting to save space by hardlinking
|
||||
duplicate files but wish to treat each name as if it were a unique and
|
||||
separate file.
|
||||
|
||||
If you want to write to a read-only filesystem you should look at
|
||||
overlayfs. You can always include the overlayfs mount into a mergerfs
|
||||
pool.
|
||||
|
||||
|
||||
## Can mergerfs run via Docker, Podman, Kubernetes, etc.
|
||||
|
||||
Yes. With Docker you'll need to include `--cap-add=SYS_ADMIN
|
||||
--device=/dev/fuse --security-opt=apparmor:unconfined` or similar with
|
||||
other container runtimes. You should also be running it as root or
|
||||
given sufficient caps to allow mergerfs to change user and group
|
||||
identity as well as have root like filesystem permissions. This
|
||||
ability is critical to how mergerfs works.
|
||||
|
||||
Also, as mentioned by [hotio](https://hotio.dev/containers/mergerfs),
|
||||
with Docker you should probably be mounting with `bind-propagation`
|
||||
set to `slave`.
|
||||
|
||||
|
||||
## How does mergerfs interact with user namespaces?
|
||||
|
||||
FUSE does not have any special integration with Linux user namespaces
|
||||
used by container runtime platforms like Docker, Podman, etc. The
|
||||
uid/gid values passed to mergerfs will be the host level values rather
|
||||
than that seen inside the container. Meaning `root` in a container
|
||||
with user namespaces configured will not be `root` to mergerfs. Same
|
||||
with any other uid/gid. Meaning your permissions on your branches must
|
||||
work with the translated values from the id mapping.
|
||||
|
||||
It is generally recommended to not use user namespacing / id mapping
|
||||
given the complication it introduces.
|
||||
|
||||
|
||||
## Can mergerfs be used with NFS root squash?
|
||||
|
||||
If mergerfs is pooling a NFS mount then root squash should be disabled
|
||||
as mergerfs needs to be able to have elevated privileges to do what it
|
||||
does.
|
||||
|
||||
If you are exporting mergerfs over NFS then it is not really necessary.
|
||||
|
||||
See the [section on remote filesystems.](../remote_filesystems.md)
|
||||
|
||||
|
||||
## Does inotify and fanotify work?
|
||||
|
||||
Yes. You can test by using
|
||||
[inotifywait](https://man7.org/linux/man-pages/man1/inotifywait.1.html) or
|
||||
[inotifywatch](https://man7.org/linux/man-pages/man1/inotifywatch.1.html).
|
||||
|
||||
However, you can not get notifications for events that occur outside
|
||||
of the mergerfs mount. For instance if you are doing
|
||||
[out-of-band](usage_and_functionality.md#can-filesystems-be-removed-from-the-pool-without-affecting-them)
|
||||
changes it is not possible to get those events forwarded through
|
||||
mergerfs. FUSE offers no mechanism to publish events and even if it
|
||||
did it would require somewhat expensive
|
||||
[inotify](https://man7.org/linux/man-pages/man7/inotify.7.html) or
|
||||
[fanotify](https://man7.org/linux/man-pages/man7/fanotify.7.html)
|
||||
watches on all branches.
|
||||
|
||||
Most software which has the ability to actively monitor a filesystem
|
||||
(such as Plex, Emby, Jellyfin, Airsonic, etc.) are using `inotify` or
|
||||
`fanotify`.
|
||||
|
||||
If you must add content out-of-band the only way to get real-time
|
||||
updates (via inotify or fanotify) is to add the underlying branches to
|
||||
the software rather than using the mergerfs mount. An alternative is
|
||||
to enable regular library scanning. Plex, for instance, has "Scan my
|
||||
library periodically". Additionally, if you are using software such as
|
||||
Radarr, Sonarr, or Lidarr you can configure it to trigger library
|
||||
updates in a number of services. This can be found under `Settings >
|
||||
Connect`.
|
||||
@@ -0,0 +1,92 @@
|
||||
# Configuration and Policies
|
||||
|
||||
## What settings should I use?
|
||||
|
||||
Depends on what features you want. Generally, there are no "good",
|
||||
"bad", "inefficient", or "optimal" settings. Options are almost
|
||||
exclusively functional. Meaning they change the behavior of the
|
||||
software. It is best to read over the available options and choose
|
||||
what fits your use case. If something is not clear from the
|
||||
documentation please reach out and the documentation will be improved.
|
||||
|
||||
The settings described in the [Quick Start](../quickstart.md) are
|
||||
sufficient for most users.
|
||||
|
||||
Filesystems are complex and use cases numerous. There simply is no way
|
||||
to provide a singular setup that works for all situations. Since
|
||||
mergerfs [does not impact](usage_and_functionality.md) the underlying
|
||||
filesystems and can be added or removed without any impact it is
|
||||
extremely easy to test and experiment with different settings.
|
||||
|
||||
|
||||
## Why is epmfs the default create policy?
|
||||
|
||||
Because it is a strict policy and therefore does not increase entropy
|
||||
of the filesystem layout. If you don't explicitly choose a policy then
|
||||
the layout stays the same. It is far easier to stop being strict than
|
||||
fix the layout after having a loose policy.
|
||||
|
||||
|
||||
## How can I ensure files are collocated on the same branch?
|
||||
|
||||
Many people like the idea of ensuring related files, such as all the
|
||||
files to a TV show season or songs in an album, are stored on the same
|
||||
storage device. However, most people have no actual need for this
|
||||
behavior.
|
||||
|
||||
1. If you backup your data it is extremely likely your backup solution
|
||||
can restore only those files you are missing.
|
||||
2. Software such as **Sonarr** can manage the downloading and post
|
||||
processing of bespoke episodes which may be missing in a
|
||||
season. Either by downloading the episode individually if available
|
||||
or by downloading a full season.
|
||||
3. There is no benefit to keeping files collocated with regard to
|
||||
drive spinup, caching, or other secondary concern.
|
||||
|
||||
The main use case for wanting collocation is where the branch is going
|
||||
to be removed from the pool and you wish to have all data from some
|
||||
logical set on that device. Such as you intend to take a drive out of
|
||||
the pool to take on a trip and want a whole show on the
|
||||
drive. However, even in these situations you typically end up needing
|
||||
to curate the files anyway because it has show A but not show B.
|
||||
|
||||
All that said you can accomplish collocation to varying degrees using
|
||||
the following methods:
|
||||
|
||||
1. Use
|
||||
[mergerfs.consolidate](https://github.com/trapexit/mergerfs-tools/blob/master/src/mergerfs.consolidate)
|
||||
when consolidation is needed.
|
||||
2. Use a `msp` create policy.
|
||||
3. Use `epmfs` or other `ep` create policy and manually create paths
|
||||
on the branches directly.
|
||||
4. Use a `ep` `create` policy and `rand` for `mkdir`.
|
||||
|
||||
|
||||
## How can I balance files across the pool?
|
||||
|
||||
Similar to collocation there is generally little reason to balance
|
||||
files.
|
||||
|
||||
1. Since prediction of a filesystem's death or loss of data is near
|
||||
impossible there is little reason to balance in hopes of limiting
|
||||
data loss.
|
||||
2. While performance could be impacted by having too much reading or
|
||||
writing happen to singular underlying filesystems balancing won't
|
||||
help unless you have the ability to manage the access patterns to
|
||||
the pool.
|
||||
3. Over time most configurations will lead to a random distribution of
|
||||
files across the branches which is effectively "balancing."
|
||||
|
||||
If you wish to move files around or balance the pool you can:
|
||||
|
||||
1. Use `rand` or `pfrd` create policies and just use your system as
|
||||
normal.
|
||||
2. Write simple scripts using rsync or similar to move files around as
|
||||
you wish.
|
||||
3. Use
|
||||
[mergerfs.balance](https://github.com/trapexit/mergerfs-tools/blob/master/src/mergerfs.balance). Keep
|
||||
in mind that this tool is really just an example of how to
|
||||
accomplish such a task. The tool does not keep track of links so
|
||||
you may encounter an increase in used space if you rely on links to
|
||||
reduce redundency. However, you can run a file dedup program like
|
||||
[rdfind](https://github.com/pauldreik/rdfind) to restore the links.
|
||||
@@ -0,0 +1,79 @@
|
||||
# Limiting drive spinup
|
||||
|
||||
## How can I setup my system to limit drive spinup?
|
||||
|
||||
TL;DR: You really can't. Not through mergerfs alone. In fact mergerfs
|
||||
makes an attempt to do so more complicated.
|
||||
|
||||
|
||||
mergerfs is a proxy. Despite having some caching behaviors it is not
|
||||
designed to cache much more than metadata. It proxies calls between
|
||||
client software and underlying filesystems. If a client makes a
|
||||
request such as `open`, `readdir`, `stat`, etc. it must translate that
|
||||
into something that makes sense across multiple filesystems. For
|
||||
`readdir` that means running the call against all branches and
|
||||
aggregating the output. For `open` that means finding the file to open
|
||||
and doing so. The only way to find the file to open is to scan across
|
||||
all branches and sort the results and pick one. There is no practical
|
||||
way to do otherwise. Especially given so many mergerfs users expect
|
||||
out-of-band changes to "just work."
|
||||
|
||||
The best way to limit spinup of drives is to limit their usage at the
|
||||
client level. Meaning keeping software from interacting with the
|
||||
filesystem (and therefore the drive) all together.
|
||||
|
||||
|
||||
### What if you assume no out-of-band changes and cache everything?
|
||||
|
||||
This would require a significant rewrite of mergerfs. Everything is
|
||||
done on the fly right now and all those calls to underlying
|
||||
filesystems can cause a spinup. To work around that a database of some
|
||||
sort would have to be used to store ALL metadata about the underlying
|
||||
filesystems and on startup everything scanned and stored. From then on
|
||||
it would have to carefully update all the same data the filesystems
|
||||
do. It couldn't be kept in RAM because it would take up too much space
|
||||
so it'd have to be on a SSD or other storage device. If anything
|
||||
changed out of band it would break things in weird ways. It could
|
||||
rescan on occasion but that would require spinning up
|
||||
everything. Filesystem watches could be used to get updates when the
|
||||
filesystem changes but that would allow for race conditions and
|
||||
might keep the drives from spinning down. Something as "simple" as
|
||||
keeping the current available free space on each filesystem isn't as
|
||||
easy as one might think given reflinks, snapshots, and other block
|
||||
level dedup technologies as well as the space used includes not just
|
||||
raw file usage.
|
||||
|
||||
Even if all metadata (including xattrs) is cached some software will
|
||||
open files (media like videos and audio) to check their
|
||||
metadata. Granted a Plex or Jellyfin scan which may do that is
|
||||
different from a random directory listing but is still something to
|
||||
consider. Those "deep" scans can't be kept from waking drives.
|
||||
|
||||
|
||||
### What if you only query already active drives?
|
||||
|
||||
Let's assume that is plausible (it isn't because some drives actually
|
||||
will spin up if you ask if they are spun down... yes... really) you
|
||||
would have to either cache all the metadata on the filesystem or treat
|
||||
it like the filesystem doesn't exist. The former has all the problems
|
||||
mentioned prior and the latter would break a lot of things.
|
||||
|
||||
|
||||
### Is there anything that can be done where mergerfs is involved?
|
||||
|
||||
Yes, but whether it works for you depends on your tolerance for the
|
||||
complexity.
|
||||
|
||||
1. Cleanly separate writing, storing, and consuming the data.
|
||||
1. Use a SSD or dedicated and limited pool of drives for downloads / torrents.
|
||||
2. When downloaded move the files to the primary storage pool.
|
||||
3. When setting up software like Plex, Jellyfin, etc. point to the
|
||||
underlying filesystems. Not mergerfs.
|
||||
2. Add a bunch of bcache, lvmcache, dm-cache, or similar block level
|
||||
cache to your setup. After a bit of use, assuming sufficient
|
||||
storage space, you can limit the likelihood of the underlying
|
||||
spinning disks from needing to be hit.
|
||||
|
||||
Remember too that while it may be a tradeoff you are willing to live
|
||||
with there is decent evidence that spinning down drives puts increased
|
||||
wear on them and can lead to their death earlier than otherwise.
|
||||
@@ -0,0 +1,49 @@
|
||||
# Recommendations and Warnings
|
||||
|
||||
## What should mergerfs NOT be used for?
|
||||
|
||||
- databases: Even if the database stored data in separate files
|
||||
(mergerfs wouldn't offer much otherwise) the higher latency of the
|
||||
indirection will really harm performance. If it is a lightly used
|
||||
sqlite3 database then it should be fine.
|
||||
- VM images: For the same reasons as databases. VM images are accessed
|
||||
very aggressively and mergerfs will introduce a lot of extra latency.
|
||||
- As replacement for RAID: mergerfs is just for pooling branches. If
|
||||
you need that kind of device performance aggregation or high
|
||||
availability you should stick with RAID. However, it is fine to put
|
||||
a filesystem which is on a RAID setup in mergerfs.
|
||||
|
||||
|
||||
## It's mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?
|
||||
|
||||
[mhddfs](https://github.com/trapexit/mhddfs) manages running as
|
||||
`root` by calling
|
||||
[getuid()](https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319)
|
||||
and if it returns `0` then it will
|
||||
[chown](http://linux.die.net/man/1/chown) the file. Not only is that a
|
||||
race condition but it doesn't handle other situations. Rather than
|
||||
attempting to simulate POSIX ACL behavior the proper way to manage
|
||||
this is to use [seteuid](http://linux.die.net/man/2/seteuid) and
|
||||
[setegid](http://linux.die.net/man/2/setegid), in effect, becoming the
|
||||
user making the original call, and perform the action as them. This is
|
||||
what mergerfs does and why mergerfs should always run as root.
|
||||
|
||||
In Linux setreuid syscalls apply only to the thread. glibc hides this
|
||||
away by using realtime signals to inform all threads to change
|
||||
credentials. Taking after Samba, mergerfs uses
|
||||
`syscall(SYS_setreuid,...)` to set the callers credentials for that
|
||||
thread only. Jumping back to `root` as necessary should escalated
|
||||
privileges be needed (for instance: to clone paths between
|
||||
filesystems).
|
||||
|
||||
For non-Linux systems, mergerfs uses a read-write lock and changes
|
||||
credentials only when necessary. If multiple threads are to be user X
|
||||
then only the first one will need to change the processes
|
||||
credentials. So long as the other threads need to be user X they will
|
||||
take a readlock allowing multiple threads to share the
|
||||
credentials. Once a request comes in to run as user Y that thread will
|
||||
attempt a write lock and change to Y's credentials when it can. If the
|
||||
ability to give writers priority is supported then that flag will be
|
||||
used so threads trying to change credentials don't starve. This isn't
|
||||
the best solution but should work reasonably well assuming there are
|
||||
few users.
|
||||
@@ -0,0 +1,41 @@
|
||||
# Reliability and Scalability
|
||||
|
||||
## Is mergerfs "production ready?"
|
||||
|
||||
Yes.
|
||||
|
||||
mergerfs has been around for over a decade and used by many users on
|
||||
their systems. Typically running 24/7 with constant load.
|
||||
|
||||
At least a few companies are believed to use mergerfs in production
|
||||
environments. A number of [NAS focused operating
|
||||
systems](../related_projects.md) includes mergerfs as a solution for
|
||||
pooling filesystems.
|
||||
|
||||
Most serious issues (crashes or data corruption) have been due to
|
||||
[kernel bugs](../known_issues_bugs.md#fuse-and-linux-kernel). All of
|
||||
which are fixed in stable releases.
|
||||
|
||||
|
||||
## How well does mergerfs scale?
|
||||
|
||||
Users have reported running mergerfs on everything from OpenWRT
|
||||
routers and Raspberry Pi SBCs to multi-socket Xeon enterprise servers.
|
||||
|
||||
Users have pooled everything from USB thumb drives to enterprise NVME
|
||||
SSDs to remote filesystems and rclone mounts.
|
||||
|
||||
The cost of many calls can be `O(n)` meaning adding more branches to
|
||||
the pool will increase the cost of certain functions, such as reading
|
||||
directories or finding files to open, but there are a number of caches
|
||||
and strategies in place to limit overhead where possible.
|
||||
|
||||
|
||||
## Are there any limits?
|
||||
|
||||
There is no maximum capacity beyond what is imposed by the operating
|
||||
system itself. Any limit is practical rather than technical. As
|
||||
explained in the question about scale mergerfs is mostly limited by
|
||||
the tolerated cost of aggregating branches and the cost associated
|
||||
with interacting with them. If you pool slow network filesystem then
|
||||
that will naturally impact performance more than low latency SSDs.
|
||||
@@ -0,0 +1,224 @@
|
||||
# Technical Behavior and Limitations
|
||||
|
||||
## Do hardlinks work?
|
||||
|
||||
Yes. There is no option to enable or disable links (or renames.) They
|
||||
are fundamentally supported in compatible situations. That said the
|
||||
inode of a file is not necessarily indicative of two file names
|
||||
linking to the same underlying data. See also the option `inodecalc`
|
||||
for how inode values are calculated.
|
||||
|
||||
What mergerfs does not do is fake hard links across branches. Read the
|
||||
section [rename & link](../config/rename_and_link.md) for how it
|
||||
works.
|
||||
|
||||
Remember that hardlinks will **NOT** work across devices. That
|
||||
includes between the original filesystem and a mergerfs pool, between
|
||||
two separate pools of the same underlying filesystems, or bind mounts
|
||||
of paths within the mergerfs pool. The latter is common when using
|
||||
Docker or Podman. Multiple volumes (bind mounts) to the same
|
||||
underlying filesystem are considered different devices. There is no
|
||||
way to link or rename between them. You should mount in the highest
|
||||
directory in the mergerfs pool that includes all the paths you need if
|
||||
you want links and rename to work.
|
||||
|
||||
|
||||
## How does mergerfs handle moving and copying of files?
|
||||
|
||||
This is a _very_ common mistaken assumption regarding how filesystems
|
||||
work. There is no such thing as "move" or "copy." These concepts are
|
||||
high level behaviors made up of numerous independent steps and _not_
|
||||
individual filesystem functions.
|
||||
|
||||
A "move" can include a "copy" so lets describe copy first.
|
||||
|
||||
When an application copies a file from "source" to "destination" it
|
||||
can do so in a number of ways but the basics are the following.
|
||||
|
||||
1. `open` the source file.
|
||||
2. `create` the destination file.
|
||||
3. `read` a chunk of data from source and `write` to
|
||||
destination. Continue till it runs out of data to copy.
|
||||
4. Copy file metadata (`stat`) such as ownership (`chown`),
|
||||
permissions (`chmod`), timestamps (`utimes`), extended attributes
|
||||
(`getxattr`, `setxattr`), etc.
|
||||
5. `close` source and destination files.
|
||||
|
||||
"move" is typically a `rename(src,dst)` and if that errors with
|
||||
`EXDEV` (meaning the source and destination are on different
|
||||
filesystems) the application will "copy" the file as described above
|
||||
and then it removes (`unlink`) the source.
|
||||
|
||||
The `rename(src,dst)`, `open(src)`, `create(dst)`, data copying,
|
||||
metadata copying, `unlink(src)`, etc. are entirely distinct and
|
||||
separate events. There is really no practical way to know that what is
|
||||
ultimately occurring is the "copying" of a file or what the source
|
||||
file would be. Since the source is not known there is no way to know
|
||||
how large a created file is destined to become. This is why it is
|
||||
impossible for mergerfs to choose the branch for a `create` based on
|
||||
file size. The only context provided when a file is created, besides
|
||||
the name, is the permissions, if it is to be read and/or written, and
|
||||
some low level settings for the operating system.
|
||||
|
||||
All of this means that mergerfs can not make decisions when a file is
|
||||
created based on file size or the source of the data. That information
|
||||
is simply not available. At best mergerfs could respond to files
|
||||
reaching a certain size when writing data, a file is closed, or
|
||||
renamed.
|
||||
|
||||
Related: if a user wished to have mergerfs perform certain activities
|
||||
based on the name of a file it is common and even best practice for a
|
||||
program to write to a temporary file first and then rename to its
|
||||
final destination. That temporary file name will typically be random
|
||||
and have no indication of the type of file being written. At best
|
||||
something could be done on rename.
|
||||
|
||||
|
||||
## Does FICLONE or FICLONERANGE work?
|
||||
|
||||
Unfortunately not. FUSE, the technology mergerfs is based on, does not
|
||||
support the `clone_file_range` feature needed for it to work. mergerfs
|
||||
won't even know such a request is made. The kernel will simply return
|
||||
an error back to the application making the request.
|
||||
|
||||
Should FUSE gain the ability mergerfs will be updated to support it.
|
||||
|
||||
|
||||
## Why do I get an "out of space" / "no space left on device" / ENOSPC error even though there appears to be lots of space available?
|
||||
|
||||
First make sure you've read the sections above about policies, path
|
||||
preservation, branch filtering, and the options `minfreespace`,
|
||||
`moveonenospc`, `statfs`, and `statfs_ignore`.
|
||||
|
||||
mergerfs is simply presenting a union of the content within multiple
|
||||
branches. The reported free space is an aggregate of space available
|
||||
within the pool (behavior modified by `statfs` and
|
||||
`statfs_ignore`). It does not represent a contiguous space. In the
|
||||
same way that read-only filesystems, those with quotas, or reserved
|
||||
space report the full theoretical space available.
|
||||
|
||||
Due to path preservation, branch tagging, read-only status, and
|
||||
`minfreespace` settings it is perfectly valid that `ENOSPC` / "out of
|
||||
space" / "no space left on device" be returned. It is doing what was
|
||||
asked of it: filtering possible branches due to those settings. Only
|
||||
one error can be returned and if one of the reasons for filtering a
|
||||
branch was `minfreespace` then it will be returned as
|
||||
such. `moveonenospc` is only relevant to writing a file which is too
|
||||
large for the filesystem it's currently on.
|
||||
|
||||
It is also possible that the filesystem selected has run out of
|
||||
inodes. Use `df -i` to list the total and available inodes per
|
||||
filesystem.
|
||||
|
||||
If you don't care about path preservation then simply change the
|
||||
`create` policy to one which isn't. `mfs` is probably what most are
|
||||
looking for. The reason it's not default is because it was originally
|
||||
set to `epmfs` and changing it now would change people's setup. Such a
|
||||
setting change will likely occur in mergerfs 3.
|
||||
|
||||
|
||||
## Why does the total available space in mergerfs not equal outside?
|
||||
|
||||
Are you using ext2/3/4? With reserve for root? mergerfs uses available
|
||||
space for statfs calculations. If you've reserved space for root then
|
||||
it won't show up.
|
||||
|
||||
You can remove the reserve by running: `tune2fs -m 0 <device>`
|
||||
|
||||
|
||||
## I notice massive slowdowns of writes when enabling cache.files.
|
||||
|
||||
When file caching is enabled in any form (`cache.files!=off`) it will
|
||||
issue `getxattr` requests for `security.capability` prior to _every
|
||||
single write_. This will usually result in performance degradation,
|
||||
especially when using a network filesystem (such as NFS or SMB.)
|
||||
Unfortunately at this moment, the kernel is not caching the response.
|
||||
|
||||
To work around this situation mergerfs offers a few solutions.
|
||||
|
||||
1. Set `security_capability=false`. It will short circuit any call and
|
||||
return `ENOATTR`. This still means though that mergerfs will
|
||||
receive the request before every write but at least it doesn't get
|
||||
passed through to the underlying filesystem.
|
||||
2. Set `xattr=noattr`. Same as above but applies to _all_ calls to
|
||||
getxattr. Not just `security.capability`. This will not be cached
|
||||
by the kernel either but mergerfs' runtime config system will still
|
||||
function.
|
||||
3. Set `xattr=nosys`. Results in mergerfs returning `ENOSYS` which
|
||||
_will_ be cached by the kernel. No future xattr calls will be
|
||||
forwarded to mergerfs. The downside is that also means the xattr
|
||||
based config and query functionality won't work either.
|
||||
4. Disable file caching. If you aren't using applications which use
|
||||
`mmap` it's probably simpler to just disable it altogether. The
|
||||
kernel won't send the requests when caching is disabled.
|
||||
|
||||
|
||||
## Why use FUSE? Why not a kernel based solution?
|
||||
|
||||
As with any solution to a problem, there are advantages and
|
||||
disadvantages to each one.
|
||||
|
||||
A FUSE based solution has all the downsides of FUSE:
|
||||
|
||||
- Higher IO latency due to the trips in and out of kernel space
|
||||
- Higher general overhead due to trips in and out of kernel space
|
||||
- Double caching when using page caching
|
||||
- Misc limitations due to FUSE's design
|
||||
|
||||
But FUSE also has a lot of upsides:
|
||||
|
||||
- Easier to offer a cross platform solution
|
||||
- Easier forward and backward compatibility
|
||||
- Easier updates for users
|
||||
- Easier and faster release cadence
|
||||
- Allows more flexibility in design and features
|
||||
- Overall easier to write, secure, and maintain
|
||||
- Much lower barrier to entry (getting code into the kernel takes a
|
||||
lot of time and effort initially)
|
||||
|
||||
|
||||
## Is my OS's libfuse needed for mergerfs to work?
|
||||
|
||||
No. Normally `mount.fuse` is needed to get mergerfs (or any FUSE
|
||||
filesystem to mount using the `mount` command but in vendoring the
|
||||
libfuse library the `mount.fuse` app has been renamed to
|
||||
`mount.mergerfs` meaning the filesystem type in `fstab` can simply be
|
||||
`mergerfs`. That said there should be no harm in having it installed
|
||||
and continuing to using `fuse.mergerfs` as the type in `/etc/fstab`.
|
||||
|
||||
If `mergerfs` doesn't work as a type it could be due to how the
|
||||
`mount.mergerfs` tool was installed. Must be in `/sbin/` with proper
|
||||
permissions.
|
||||
|
||||
|
||||
## Why was splice support removed?
|
||||
|
||||
After a lot of testing over the years, splicing always appeared to
|
||||
at best, provide equivalent performance, and in some cases, worse
|
||||
performance. Splice is not supported on other platforms forcing a
|
||||
traditional read/write fallback to be provided. The splice code was
|
||||
removed to simplify the codebase.
|
||||
|
||||
|
||||
## How does mergerfs handle credentials?
|
||||
|
||||
|
||||
mergerfs is a multithreaded application in order to handle requests
|
||||
from the kernel concurrently. Each FUSE message has a header with
|
||||
certain details about the request include the process ID (pid) of the
|
||||
requesting application, the process' effective user id (uid), and
|
||||
group id (gid). To ensure proper POSIX filesystem behavior and
|
||||
security mergerfs must change its identity to match that of the
|
||||
requester when performing the core filesystem function on the
|
||||
underlying filesystem. On most Unix/POSIX based system a process and
|
||||
all its threads are under the same uid and gid. However, on Linux each
|
||||
thread may have its own credentials. This allows mergerfs to be
|
||||
multithreaded and for each thread to change to the credentials
|
||||
(seteuid,setegid) as required by the incoming message it is
|
||||
handling. However, on FreeBSD this is not possible at the moment
|
||||
(though there has been
|
||||
[discussions](https://wiki.freebsd.org/Per-Thread%20Credentials) and
|
||||
as such must change the credentials of the whole application when
|
||||
actioning messages. mergerfs does optimize this behavior by only
|
||||
changing credentials and locking the thread to do so if the process is
|
||||
currently not the same as what is necessary by the incoming request.
|
||||
@@ -0,0 +1,84 @@
|
||||
# Usage and Functionality
|
||||
|
||||
## Can mergerfs be used with filesystems which already have data?
|
||||
|
||||
Yes. mergerfs is really just a proxy and does **NOT** interfere with
|
||||
the normal form or function of the filesystems, mounts, or paths it
|
||||
manages. It literally is interacting with your filesystems as any
|
||||
other application does. It can not do anything that any other random
|
||||
piece of software can't do.
|
||||
|
||||
mergerfs is **not** a traditional filesystem that takes control over
|
||||
the underlying disk or block device. mergerfs is **not** RAID. It does
|
||||
**not** manipulate the data that passes through it. It does **not**
|
||||
shard data across filesystems. It only shards some **behavior** and
|
||||
aggregates others.
|
||||
|
||||
|
||||
## Can filesystems be removed from the pool without affecting them?
|
||||
|
||||
Yes. See previous question's answer.
|
||||
|
||||
|
||||
## Can mergerfs be removed without affecting the data?
|
||||
|
||||
Yes. See the previous question's answer.
|
||||
|
||||
|
||||
## Can filesystems be moved to another pool?
|
||||
|
||||
Yes. See the previous question's answer.
|
||||
|
||||
|
||||
## Can filesystems be part of multiple pools?
|
||||
|
||||
Yes.
|
||||
|
||||
|
||||
## How do I migrate data into or out of the pool when adding/removing filesystems?
|
||||
|
||||
There is no need to do so. See the previous questions.
|
||||
|
||||
|
||||
## How do I remove a filesystem but keep the data in the pool?
|
||||
|
||||
Nothing special needs to be done. Remove the branch from mergerfs'
|
||||
config and copy (rsync) the data from the removed filesystem into the
|
||||
pool. The same as if it were you transferring data from one filesystem
|
||||
to another.
|
||||
|
||||
If you wish to continue using the pool with all data available while
|
||||
performing the transfer simply create a temporary pool without the
|
||||
branch in question and then copy the data from the branch to the
|
||||
temporary pool. It would probably be a good idea to set the branch
|
||||
mode to `RO` prior to doing this to ensure no new content is written
|
||||
to the filesystem while performing the copy. However, it is typically
|
||||
good practice to run rsync or rclone again after the first copy
|
||||
finishes to ensure nothing is left behind.
|
||||
|
||||
NOTE: Above recommends to "copy" rather than "move" because you want
|
||||
to ensure that your data is transferred before wiping the drive or
|
||||
filesystem.
|
||||
|
||||
|
||||
## Can filesystems still be used directly? Outside of mergerfs while pooled?
|
||||
|
||||
Yes, [out-of-band](https://en.wikipedia.org/wiki/Out-of-band)
|
||||
interaction is generally fine. Remember that mergerfs is a userland
|
||||
application so any interaction with the underlying filesystem is the
|
||||
same as multiple normal applications interacting. However, it is not
|
||||
recommended to write to the same file from within the pool and from
|
||||
without at the same time. Especially if using page caching
|
||||
(`cache.files!=off`) or writeback caching
|
||||
(`cache.writeback=true`). That said this risk is really not different
|
||||
from the risk of two applications writing to the same file under
|
||||
normal conditions.
|
||||
|
||||
Keep in mind that if out-of-band changes are made while also
|
||||
leveraging any caching of the filesystem layout such as with
|
||||
`cache.entry`, `cache.negative_entry`, `cache.attr`, `cache.symlinks`,
|
||||
or `cache.readdir` you may experience temporary inconsistency till the
|
||||
cache expires. mergerfs is not actively watching all branches for
|
||||
changes and the kernel will have no way to know anything changed so as
|
||||
to clear or ignore the cache. This is the same issue you can have with
|
||||
[remote filesystems](../remote_filesystems.md).
|
||||
@@ -0,0 +1,217 @@
|
||||
# "Why isn't it working?"
|
||||
|
||||
## I modified mergerfs' config but it still behaves the same.
|
||||
|
||||
mergerfs, like most filesystems, are given their options/arguments
|
||||
at mount time. Unlike most filesystems, mergerfs also has the ability
|
||||
to modify certain options at [runtime](../runtime_interfaces.md).
|
||||
|
||||
That said: mergerfs does not actively try to monitor typical methods
|
||||
of configuration (nor should it.) As such if changes are made to
|
||||
`/etc/fstab`, a systemd unit file, etc. it will have no knowledge of
|
||||
those changes. It is the user's responsibility to
|
||||
[restart](../setup/upgrade.md) mergerfs to pick up the changes or use
|
||||
the [runtime interface](../runtime_interfaces.md).
|
||||
|
||||
|
||||
## Why are all my files ending up on 1 filesystem?!
|
||||
|
||||
Did you start with empty filesystems? Did you explicitly configure a
|
||||
`category.create` policy? Are you using an `existing path` / `path
|
||||
preserving` policy?
|
||||
|
||||
The default create policy is `epmfs`. That is a path preserving
|
||||
algorithm. With such a policy for `mkdir` and `create` with a set of
|
||||
empty filesystems it will select only 1 filesystem when the first
|
||||
directory is created. Anything, files or directories, created in that
|
||||
directory will be placed on the same branch because it is preserving
|
||||
paths. That is the expected behavior.
|
||||
|
||||
This may catch new users off guard but this policy is the safest
|
||||
policy to have as default as it will not change the general layout of
|
||||
the underlying branches. If you do not care about path preservation
|
||||
([most should
|
||||
not](configuration_and_policies.md#how-can-i-ensure-files-are-collocated-on-the-same-branch))
|
||||
and wish your files to be spread across all your filesystems change
|
||||
`create.category` to `pfrd`, `rand`, `mfs` or a similarly non-path
|
||||
restrictive [policy](../config/functions_categories_policies.md).
|
||||
|
||||
|
||||
## Why isn't the create policy working?
|
||||
|
||||
It probably is. The policies rather straight forward and well tested.
|
||||
|
||||
First, confirm the policy is configured as expected by using the
|
||||
[runtime interface](../runtime_interfaces.md).
|
||||
|
||||
```shell
|
||||
$ getfattr -n user.mergerfs.category.create /mnt/mergerfs/.mergerfs
|
||||
# file: mnt/mergerfs/.mergerfs
|
||||
user.mergerfs.category.create="mfs"
|
||||
```
|
||||
|
||||
Second, as discussed in the [support](../support.md) section, test the
|
||||
behavior using simple command line tools such as `touch` and then see
|
||||
where it was created.
|
||||
|
||||
|
||||
```shell
|
||||
$ touch /mnt/mergerfs/new-file
|
||||
$ getfattr -n user.mergerfs.allpaths /mnt/mergerfs/new-file
|
||||
# file: mnt/mergerfs/new-file
|
||||
user.mergerfs.allpaths="/mnt/hdd/drive1/new-file"
|
||||
```
|
||||
|
||||
If the location of the file is where it should be according to the
|
||||
state of the system at the time and the policy selected then the
|
||||
"problem" lies elsewhere.
|
||||
|
||||
[Keep in
|
||||
mind](technical_behavior_and_limitations.md/#how-does-mergerfs-handle-moving-and-copying-of-files)
|
||||
that files, when created, have no size. If a number of files are
|
||||
created at the same time, for example by a program downloading
|
||||
numerous files like a BitTorrent client, then depending on the policy
|
||||
the files could be created on the same branch. As the files are
|
||||
written to, or resized immediately afterwards to the total size of the
|
||||
file being downloaded, the files will take up more space but there is
|
||||
no mechanism to move them as they grow. Nor would it be a good idea to
|
||||
do so as it would be expensive to continuously calculate their size
|
||||
and perform the move while the file is still being written to. As such
|
||||
an imbalance will occur that wouldn't if the files had been created
|
||||
and resized one at a time.
|
||||
|
||||
If you wish to reduce the likelihood of this happening a policy that
|
||||
does not make decisions on available space alone such as `pfrd` or
|
||||
`rand` should be used.
|
||||
|
||||
|
||||
## Why can't I see my files / directories?
|
||||
|
||||
It's almost always a permissions issue. Unlike mhddfs and
|
||||
unionfs-fuse, which accesses content as root, mergerfs always changes
|
||||
its credentials to that of the caller. This is done as it is the only
|
||||
properly secure way to manage permissions. This means that if the user
|
||||
does not have access to a file or directory than neither will
|
||||
mergerfs. However, because mergerfs is creating a union of paths it
|
||||
may be able to read some files and directories on one filesystem but
|
||||
not another resulting in an incomplete set. And if one of the branches
|
||||
it can access is empty then it will return an empty list.
|
||||
|
||||
Try using [mergerfs.fsck](https://github.com/trapexit/mergerfs-tools)
|
||||
tool to check for and fix inconsistencies in permissions. If you
|
||||
aren't seeing anything at all be sure that the basic permissions are
|
||||
correct. The user and group values are correct and that directories
|
||||
have their executable bit set. A common mistake by users new to Linux
|
||||
is to `chmod -R 644` when they should have `chmod -R u=rwX,go=rX`.
|
||||
|
||||
If using a [network filesystem](../remote_filesystems.md) such as NFS
|
||||
or SMB (Samba) be sure to pay close attention to anything regarding
|
||||
permissioning and users. Root squashing and user translation for
|
||||
instance has bitten a few mergerfs users. Some of these also affect
|
||||
the use of mergerfs from [container platforms such as
|
||||
Docker.](compatibility_and_integration.md)
|
||||
|
||||
|
||||
## Why are file moves, renames, links/hardlinks failing?
|
||||
|
||||
mergerfs fully supports rename and link functions to the degree that
|
||||
is possible in a union filesystem. Problems related to rename and link
|
||||
are almost exclusively due to incorrect setup of software or poorly
|
||||
written software.
|
||||
|
||||
|
||||
### Docker, Podman, and other container runtimes
|
||||
|
||||
Keep in mind that [rename and link](../config/rename_and_link.md) will
|
||||
**NOT** work across devices. That includes between the original
|
||||
filesystem and a mergerfs pool, between two separate pools of the same
|
||||
underlying filesystems, or bind mounts of paths within the mergerfs
|
||||
pool. The latter is common when using Docker, Podman, or other
|
||||
container runtimes. Multiple volumes (bind mounts) to the same
|
||||
underlying filesystem are considered different devices. There is no
|
||||
way to link or rename between them despite them binding to the same
|
||||
underlying filesystem. Neither mergerfs or any other filesystem has a
|
||||
say in this behavior as the kernel is erroring out before the request
|
||||
even gets to the filesystems in question.
|
||||
|
||||
To work around this situation the highest directory in the mergerfs
|
||||
pool that includes all the paths you need is what should be bind'ed
|
||||
into the container if you want links and rename to work between the
|
||||
paths in question.
|
||||
|
||||
This is a common problem for users of Radarr, Sonarr, Lidarr,
|
||||
etc. when they use the default volume mount options suggested by
|
||||
projects like
|
||||
[LinuxServer.io](https://docs.linuxserver.io/images/docker-radarr/?h=radarr#docker-compose-recommended-click-here-for-more-info). Do
|
||||
not use separate "movies" and "downloads" volumes.
|
||||
|
||||
```
|
||||
# NO
|
||||
volumes:
|
||||
- /mnt/pool/movies:/movies
|
||||
- /mnt/pool/downloads:/downloads
|
||||
|
||||
# YES
|
||||
volumes:
|
||||
- /mnt/pool:/media
|
||||
# Then use /media/movies and /media/downloads in your software.
|
||||
```
|
||||
|
||||
|
||||
### Path-Preserving Create Policies
|
||||
|
||||
As described in the [rename and link](../config/rename_and_link.md)
|
||||
docs if a path-preserving create
|
||||
[policy](../config/functions_categories_policies.md) is configured
|
||||
then mergerfs, in order to follow that restrictive policy, must return
|
||||
an error
|
||||
([EXDEV](https://man7.org/linux/man-pages/man2/rename.2.html)) if the
|
||||
target path of a rename or link is not found on the target branch.
|
||||
|
||||
```
|
||||
EXDEV oldpath and newpath are not on the same mounted filesystem.
|
||||
(Linux permits a filesystem to be mounted at multiple
|
||||
points, but rename() does not work across different mount
|
||||
points, even if the same filesystem is mounted on both.)
|
||||
```
|
||||
|
||||
[Most
|
||||
users](configuration_and_policies.md#how-can-i-ensure-files-are-collocated-on-the-same-branch)
|
||||
do not have a need for path-preserving policies but if you intend on
|
||||
using path-preserving policies you must accept that `EXDEV` errors are
|
||||
more likely to occur. You could enable
|
||||
[ignorepponrename](../config/options.md) however doing so would
|
||||
contradict the intention of using a path restrictive policy.
|
||||
|
||||
|
||||
### Poorly written software
|
||||
|
||||
There are some pieces of software that do not properly handle `EXDEV`
|
||||
errors which `rename` and `link` may return even though they are
|
||||
perfectly valid situations and do not indicate actual device,
|
||||
filesystem, or OS problems. The error will rarely be returned by
|
||||
mergerfs if using a non-path preserving
|
||||
[policy](../config/functions_categories_policies.md) however there are
|
||||
edge cases where it may (such as mounting another filesystem into the
|
||||
mergerfs pool.) If you do not care about path preservation set the
|
||||
mergerfs policy to the non-path preserving variant. For example: `-o
|
||||
category.create=pfrd`. Ideally the offending software would be fixed
|
||||
and it is recommended that if you run into this problem you contact
|
||||
the software's author and request proper handling of `EXDEV` errors.
|
||||
|
||||
|
||||
### Additional Reading
|
||||
|
||||
* [rename and link](../config/rename_and_link.md)
|
||||
* [Do hardlinks work?](technical_behavior_and_limitations.md#do-hardlinks-work)
|
||||
* [How does mergerfs handle moving and copying of files?](technical_behavior_and_limitations.md#how-does-mergerfs-handle-moving-and-copying-of-files)
|
||||
* [Moving files and directories fails with Samba](../known_issues_bugs.md#moving-files-and-directories-fails-with-samba)
|
||||
|
||||
|
||||
## Why is rtorrent failing with ENODEV (No such device)?
|
||||
|
||||
Be sure to set
|
||||
[cache.files=partial|full|auto-full|per-process](../config/cache.md)
|
||||
or use Linux kernel v6.6 or above. rtorrent and some other
|
||||
applications use [mmap](http://linux.die.net/man/2/mmap) to read and
|
||||
write to files and offer no fallback to traditional methods.
|
||||
@@ -0,0 +1,79 @@
|
||||
# mergerfs - a featureful union filesystem
|
||||
|
||||
**mergerfs** is a
|
||||
[FUSE](https://en.wikipedia.org/wiki/Filesystem_in_Userspace) based
|
||||
[union filesystem](https://en.wikipedia.org/wiki/Union_mount) geared
|
||||
towards simplifying storage and management of files across numerous
|
||||
commodity storage devices. It is similar to **mhddfs**, **unionfs**,
|
||||
and **aufs**.
|
||||
|
||||
## Features
|
||||
|
||||
* Logically combine numerous filesystems/paths into a single
|
||||
mount point
|
||||
* Combine paths of the same or different filesystems
|
||||
* Ability to add or remove filesystems/paths without impacting the
|
||||
rest of the data
|
||||
* Unaffected by individual filesystem failure
|
||||
* Configurable file selection and creation placement
|
||||
* Works with filesystems of any size
|
||||
* Works with filesystems of almost any type
|
||||
* Ignore read-only filesystems when creating files
|
||||
* Hard link copy-on-write / CoW
|
||||
* Runtime configurable
|
||||
* Support for extended attributes (xattrs)
|
||||
* Support for file attributes (chattr)
|
||||
* Support for POSIX ACLs
|
||||
|
||||
|
||||
## Non-features
|
||||
|
||||
* Read/write overlay on top of read-only filesystem like OverlayFS
|
||||
* File whiteout
|
||||
* RAID like parity calculation
|
||||
* Redundancy
|
||||
* Splitting of files across branches
|
||||
|
||||
|
||||
## How it works
|
||||
|
||||
mergerfs logically merges multiple filesystem paths together. It acts
|
||||
as a proxy to the underlying filesystem paths. Combining the behaviors
|
||||
of some functions and being a selector for others.
|
||||
|
||||
When the contents of a directory are requested mergerfs combines the
|
||||
list of files from each directory, deduplicating entries, and returns
|
||||
that list.
|
||||
|
||||
When a file or directory is created a policy is first run to determine
|
||||
which branch will be selected for the creation.
|
||||
|
||||
For functions which change attributes or remove the file the behavior
|
||||
may be applied to all instances found.
|
||||
|
||||
Read more about [policies
|
||||
here](config/functions_categories_policies.md).
|
||||
|
||||
|
||||
### Visualization
|
||||
|
||||
```
|
||||
A + B = C
|
||||
/disk1 /disk2 /merged
|
||||
| | |
|
||||
+-- /dir1 +-- /dir1 +-- /dir1
|
||||
| | | | | |
|
||||
| +-- file1 | +-- file2 | +-- file1
|
||||
| | +-- file3 | +-- file2
|
||||
+-- /dir2 | | +-- file3
|
||||
| | +-- /dir3 |
|
||||
| +-- file4 | +-- /dir2
|
||||
| +-- file5 | |
|
||||
+-- file6 | +-- file4
|
||||
|
|
||||
+-- /dir3
|
||||
| |
|
||||
| +-- file5
|
||||
|
|
||||
+-- file6
|
||||
```
|
||||
@@ -0,0 +1,47 @@
|
||||
# Intro to Filesystems
|
||||
|
||||
WORK IN PROGRESS
|
||||
|
||||
mergerfs is a union filesystem that manages other filesystems. To
|
||||
understand how mergerfs works and what the features do and mean you
|
||||
must understand at least the basics of how filesystems work. Much of
|
||||
the confusion with mergerfs is based in a lack of knowledge about
|
||||
filesystems. This section of the documentation is provide a primer for
|
||||
those needing that knowledge.
|
||||
|
||||
|
||||
## terminology
|
||||
|
||||
|
||||
## files
|
||||
|
||||
### types
|
||||
|
||||
* regular:
|
||||
* directory:
|
||||
* symlink:
|
||||
* fifo:
|
||||
* unix domain socket:
|
||||
|
||||
|
||||
### inodes
|
||||
|
||||
### names
|
||||
|
||||
### permissions
|
||||
|
||||
### owership
|
||||
|
||||
|
||||
## functions
|
||||
|
||||
|
||||
## workflows
|
||||
|
||||
### creating a file
|
||||
|
||||
### reading or writing to a file
|
||||
|
||||
### copying a file
|
||||
|
||||
### moving a file
|
||||
@@ -0,0 +1,252 @@
|
||||
# Known Issues and Bugs
|
||||
|
||||
## mergerfs
|
||||
|
||||
### Supplemental user groups
|
||||
|
||||
Due to the overhead of
|
||||
[getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs
|
||||
utilizes a cache. This cache is opportunistic and per thread. Each
|
||||
thread will query the supplemental groups for a user when that
|
||||
particular thread needs to change credentials and will keep that data
|
||||
for the lifetime of the thread. This means that if a user is added to
|
||||
a group it may not be picked up without the restart of
|
||||
mergerfs. In the future this may be improved to allow a periodic or
|
||||
manual clearing of the cache.
|
||||
|
||||
While not a bug some users have found when using containers that
|
||||
supplemental groups defined inside the container don't work as
|
||||
expected. Since mergerfs lives outside the container it is querying
|
||||
the host's group database. Effectively containers have their own user
|
||||
and group definitions unless setup otherwise just as different systems
|
||||
would.
|
||||
|
||||
Users should mount in the host group file into the containers or use a
|
||||
standard shared user & groups technology like NIS or LDAP.
|
||||
|
||||
|
||||
### directory mtime is not being updated
|
||||
|
||||
Remember that the default policy for `getattr` is `ff`. The
|
||||
information for the first directory found will be returned. If it
|
||||
wasn't the directory which had been updated then it will appear
|
||||
outdated.
|
||||
|
||||
The reason this is the default is because any other policy would be
|
||||
more expensive and for many applications it is unnecessary. To always
|
||||
return the directory with the most recent mtime or a faked value based
|
||||
on all found would require a scan of all filesystems.
|
||||
|
||||
If you always want the directory information from the one with the
|
||||
most recent mtime then use the `newest` policy for `getattr`.
|
||||
|
||||
|
||||
### 'mv /mnt/pool/foo /mnt/disk1/foo' removes 'foo'
|
||||
|
||||
This is not a bug.
|
||||
|
||||
Run in verbose mode to better understand what's happening:
|
||||
|
||||
```
|
||||
$ mv -v /mnt/pool/foo /mnt/disk1/foo
|
||||
copied '/mnt/pool/foo' -> '/mnt/disk1/foo'
|
||||
removed '/mnt/pool/foo'
|
||||
$ ls /mnt/pool/foo
|
||||
ls: cannot access '/mnt/pool/foo': No such file or directory
|
||||
```
|
||||
|
||||
`mv`, when working across devices, is copying the source to target and
|
||||
then removing the source. Since the source **is** the target in this
|
||||
case, depending on the unlink policy, it will remove the just copied
|
||||
file and other files across the branches.
|
||||
|
||||
If you want to move files to one filesystem just copy them there and
|
||||
use mergerfs.dedup to clean up the old paths or manually remove them
|
||||
from the branches directly.
|
||||
|
||||
|
||||
### cached memory appears greater than it should be
|
||||
|
||||
Use `cache.files=off` and/or `dropcacheonclose=true`. See the section
|
||||
on [page caching](config/cache.md).
|
||||
|
||||
|
||||
## 3rd Party Software
|
||||
|
||||
### NFS clients returning ESTALE / Stale file handle
|
||||
|
||||
NFS generally does not like out of band changes. Take a look at the
|
||||
section on NFS in the [remote-filesystems](remote_filesystems.md) for
|
||||
more details.
|
||||
|
||||
|
||||
### SQLite3, Plex, Jellyfin do not work with mergerfs
|
||||
|
||||
It does. If you're trying to put the software's config / metadata /
|
||||
database on mergerfs you can't set
|
||||
[cache.files=off](config/cache.md) (unless you use Linux v6.6 or
|
||||
above) because they are using **sqlite3** with **mmap** enabled.
|
||||
|
||||
That said it is recommended that config and runtime files be stored on
|
||||
SSDs on a regular filesystem for performance reasons. See [What should
|
||||
mergerfs NOT be used for?](faq/recommendations_and_warnings.md).
|
||||
|
||||
Other software that leverages **sqlite3** which require **mmap**
|
||||
includes Radarr, Sonarr, and Lidarr. That said many programs use
|
||||
**sqlite3** and do not require **mmap**.
|
||||
|
||||
It is recommended that you reach out to the developers of the software
|
||||
you are having troubles with and asking them to add a fallback to
|
||||
regular file IO when **mmap** is unavailable. It is not only more
|
||||
compatible and resilient but also can be more performant in certain
|
||||
situations.
|
||||
|
||||
If the issue is that quick scanning doesn't seem to pick up media then
|
||||
be sure to set `func.getattr=newest`. That said a full scan will pick
|
||||
up all media and it will put less load on the host to use time based
|
||||
library scans or to configure downloading software to trigger a scan
|
||||
when files are added to the pool. See [Does inotify and fanotify
|
||||
work?](faq/compatibility_and_integration.md#does-inotify-and-fanotify-work)
|
||||
for more details.
|
||||
|
||||
|
||||
### my 32bit software has problems
|
||||
|
||||
Some software have problems with 64bit inode values. The symptoms can
|
||||
include EOVERFLOW errors when trying to list files. You can address
|
||||
this by setting `inodecalc` to one of the 32bit based algos as
|
||||
described in the relevant section.
|
||||
|
||||
### Moving files and directories fails with Samba
|
||||
|
||||
Workaround: Copy the file/directory and then remove the original
|
||||
rather than move.
|
||||
|
||||
This isn't an issue with Samba but some SMB clients. GVFS-fuse v1.20.3
|
||||
and prior (found in Ubuntu 14.04 among others) failed to handle
|
||||
certain error codes correctly. Particularly `STATUS_NOT_SAME_DEVICE`
|
||||
which comes from the `EXDEV` that is returned by `rename` when the
|
||||
call is crossing mount points. When a program gets an `EXDEV` it needs
|
||||
to explicitly take an alternate action to accomplish its goal. In the
|
||||
case of `mv` or similar it tries `rename` and on `EXDEV` falls back to
|
||||
a copying the file to the destination and deleting the source. In
|
||||
these older versions of GVFS-fuse if it received `EXDEV` it would
|
||||
translate that into `EIO`. This would cause `mv` or most any
|
||||
application attempting to move files around on that SMB share to fail
|
||||
with a generic IO error.
|
||||
|
||||
[GVFS-fuse v1.22.0](https://bugzilla.gnome.org/show_bug.cgi?id=734568)
|
||||
and above fixed this issue but a large number of systems use the older
|
||||
release. On Ubuntu, the version can be checked by issuing `apt-cache
|
||||
showpkg gvfs-fuse`. Most distros released in 2015 seem to have the
|
||||
updated release and will work fine but older systems may
|
||||
not. Upgrading gvfs-fuse or the distro in general will address the
|
||||
problem.
|
||||
|
||||
In Apple's MacOSX 10.9 they replaced Samba (client and server) with
|
||||
their own product. It appears their new client does not handle
|
||||
`EXDEV` either and responds similarly to older releases of gvfs on
|
||||
Linux.
|
||||
|
||||
|
||||
### Trashing files occasionally fails
|
||||
|
||||
This is the same issue as with Samba. `rename` returns `EXDEV` (in our
|
||||
case that will really only happen with path preserving policies like
|
||||
`epmfs`) and the software doesn't handle the situation well. This is
|
||||
unfortunately a common failure of software which moves files
|
||||
around. The standard indicates that an implementation **MAY** choose
|
||||
to support non-user home directory trashing of files (which is a
|
||||
**MUST**). The implementation **MAY** also support "top directory
|
||||
trashes" which many probably do.
|
||||
|
||||
To create a `$topdir/.Trash` directory as defined in the standard use
|
||||
the [mergerfs-tools](https://github.com/trapexit/mergerfs-tools) tool
|
||||
`mergerfs.mktrash`.
|
||||
|
||||
|
||||
## FUSE and Linux kernel
|
||||
|
||||
There have been a number of kernel issues / bugs over the years which
|
||||
mergerfs has run into. Here is a list of them for reference and
|
||||
posterity.
|
||||
|
||||
|
||||
### NFS and EIO errors
|
||||
|
||||
[https://lore.kernel.org/linux-fsdevel/20240228160213.1988854-1-mszeredi@redhat.com/T/](https://lore.kernel.org/linux-fsdevel/20240228160213.1988854-1-mszeredi@redhat.com/T/)
|
||||
|
||||
Over the years some users have reported that while exporting mergerfs
|
||||
via NFS, after significant filesystem activity, not only will the NFS
|
||||
client start returning ESTALE and EIO errors but mergerfs itself would
|
||||
start returning EIO errors. The problem was that no one could
|
||||
reliability reproduce the issue. After a string of reports in late
|
||||
2023 and early 2024 more investigation was done.
|
||||
|
||||
In Linux 5.14 new validation was put into FUSE which caught a few
|
||||
invalid situations and would tag a FUSE node as invalid if a check
|
||||
failed. Such checks include invalid file type, changing of type from
|
||||
one request to another, a size greater than 63bit, and the generation
|
||||
of a inode changing while in use.
|
||||
|
||||
What happened was that mergerfs was using a different fixed, non-zero
|
||||
value for the generation of all nodes as it was suggested that unique
|
||||
inode + generation pairs are needed for proper integration with
|
||||
NFS. That non-zero value was being sent back to the kernel when a
|
||||
lookup request was made for root. The reason this was hard to track
|
||||
down was because NFS almost uniquely uses an API which can lead to a
|
||||
lookup of the root node that simply won't happen under normal
|
||||
workloads and usage. And that lookup will only happen if child nodes
|
||||
of the root were forgotten but NFS still had a handle to that node and
|
||||
later asked for details about it. It would trigger a set of requests
|
||||
to lookup info on those nodes.
|
||||
|
||||
This wasn't a bug in FUSE but mergerfs. However, the incorrect
|
||||
behavior of mergerfs lead to FUSE behave in an unexpected and
|
||||
incorrect manner. It would issue a lookup of the "parent of a child of
|
||||
the root" and mergerfs would send the invalid generation value. As a
|
||||
result the kernel would mark the root node as "bad" which would then
|
||||
trigger the kernel to issue a "forget root" message. In between those
|
||||
it would issue a request for the parent of the root... which doesn't
|
||||
exist.
|
||||
|
||||
So the kernel was doing two invalid things. Requesting the parent of
|
||||
the root and then when that failed issuing a forget for the
|
||||
root. These led to chasing after the wrong possible causes.
|
||||
|
||||
The change was for FUSE to revert the marking of root node bad if the
|
||||
generation is non-zero and warn about it. It will mark the node bad
|
||||
but not unhash/forget/remove it.
|
||||
|
||||
mergerfs in v2.40.1 ensures that generation for root is always 0 on
|
||||
lookup which should work across any kernel version.
|
||||
|
||||
|
||||
### Truncated files
|
||||
|
||||
This was a bug with `mmap` and `FUSE` on 32bit platforms. Should be fixed in all LTS releases.
|
||||
|
||||
* [https://marc.info/?l=linux-fsdevel&m=155550785230874&w=2](https://marc.info/?l=linux-fsdevel&m=155550785230874&w=2)
|
||||
|
||||
|
||||
### Crashing on OpenVZ
|
||||
|
||||
There was a bug in the OpenVZ kernel with regard to how it handles `ioctl` calls. It was making invalid requests which would lead to crashes due to mergerfs not expecting them.
|
||||
|
||||
* [https://bugs.openvz.org/browse/OVZ-7145](https://bugs.openvz.org/browse/OVZ-7145)
|
||||
* [https://www.mail-archive.com/devel@openvz.org/msg37096.html](https://www.mail-archive.com/devel@openvz.org/msg37096.html)
|
||||
|
||||
|
||||
### Really bad mmap performance
|
||||
|
||||
There was a bug in caching which affects overall performance of `mmap` through `FUSE` in Linux 4.x kernels. It is fixed in 4.4.10 and 4.5.4.
|
||||
|
||||
* [https://lkml.org/lkml/2016/3/16/260](https://lkml.org/lkml/2016/3/16/260)
|
||||
* [https://lkml.org/lkml/2016/5/11/59](https://lkml.org/lkml/2016/5/11/59)
|
||||
|
||||
|
||||
### Heavy load and memory pressure leads to kernel panic
|
||||
|
||||
* [https://lkml.org/lkml/2016/9/14/527](https://lkml.org/lkml/2016/9/14/527)
|
||||
* [https://lkml.org/lkml/2016/10/4/1](https://lkml.org/lkml/2016/10/4/1)
|
||||
* [https://www.theregister.com/2016/10/05/linus_torvalds_admits_buggy_crap_made_it_into_linux_48/](https://www.theregister.com/2016/10/05/linus_torvalds_admits_buggy_crap_made_it_into_linux_48/)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
@@ -0,0 +1,80 @@
|
||||
# Media and Publicity
|
||||
|
||||
## Tutorials / Articles
|
||||
|
||||
- 2016-02-02 - [Linuxserver.io: The Perfect Media Server 2016](https://blog.linuxserver.io/2016/02/02/the-perfect-media-server-2016/)
|
||||
- 2016-08-31 - [ZackReed.me: Mergerfs – another good option to pool your SnapRAID disks](https://zackreed.me/mergerfs-another-good-option-to-pool-your-snapraid-disks/)
|
||||
- 2016-11-06 - [Linuxserver.io: Revisiting the HP ProLiant Gen8 G1610T Microserver](https://blog.linuxserver.io/2016/11/06/revisiting-the-hp-proliant-gen8-g1610t-microserver/)
|
||||
- 2017-01-17 - [Setting up mergerfs on JBOD's (or a poor mans storage array)](http://corywestropp.com/develop/articles/setting-up-mergerfs/)
|
||||
- 2017-06-24 - [Linuxserver.io: The Perfect Media Server 2017](https://blog.linuxserver.io/2017/06/24/the-perfect-media-server-2017/)
|
||||
- 2018-02-19 - [Teknophiles: Disk Pooling in Linux with mergerFS](https://web.archive.org/web/20210324184857/https://www.teknophiles.com/2018/02/19/disk-pooling-in-linux-with-mergerfs/)
|
||||
- 2018-02-20 - [Fortes.com: Using Rclone and MergerFS together across drives](https://fortes.com/2018/rclone-and-mergerfs/)
|
||||
- 2019-02-10 - [Medium: Migrating from ZFS to MergerFS and SnapRAID at home](https://medium.com/@pascal.brokmeier/migrating-from-zfs-to-mergerfs-and-snapraid-at-home-89c45fd5db02)
|
||||
- 2019-04-24 - [MichaelXander.com: DIY NAS with OMV, SnapRAID, MergerFS, and Disk Encryption](https://michaelxander.com/diy-nas/)
|
||||
- 2019-07-16 - [Linuxserver.io: The Perfect Media Server - 2019 Edition](https://blog.linuxserver.io/2019/07/16/perfect-media-server-2019/)
|
||||
- 2019-09-10 - [Rclone VFS and MergerFS Setup](https://docs.usbx.me/books/rclone/page/rclone-vfs-and-mergerfs-setup)
|
||||
- 2019-12-20 - [NetworkShinobi.com: SnapRAID and MergerFS on OpenMediaVault](https://www.networkshinobi.com/snapraid-and-mergerfs-on-openmediavault/)
|
||||
- 2020-01-14 - [Brandon Rozek's Blog](https://brandonrozek.com/blog/mergerfs/)
|
||||
- 2020-02-14 - [SelfHostedHome.com: Combining Different Sized Drives with mergerfs and SnapRAID](https://selfhostedhome.com/combining-different-sized-drives-with-mergerfs-and-snapraid/)
|
||||
- 2020-05-01 - [FedoraMagazine.org: Using mergerfs to increase your virtual storage](https://fedoramagazine.org/using-mergerfs-to-increase-your-virtual-storage/)
|
||||
- 2020-08-20 - [Setting up Rclone, Mergerfs and Crontab for automated cloud storage](https://bytesized-hosting.com/pages/setting-up-rclone-mergerfs-and-crontab-for-automated-cloud-storage)
|
||||
- 2020-11-22 - [Introducing… MergerFS – My FREE UNRAID alternative](https://supertechfreaks.com/introducing-mergerfs-free-unraid-alternative/)
|
||||
- 2020-12-30 - [Perfect Media Server](https://perfectmediaserver.com) (a new site with docs fully fleshing out the 'Perfect Media Server' blog series)
|
||||
- 2021-07-24 - [Building the Ultimate Linux Home Server - Part 1: Intro, MergerFS, and SnapRAID](https://blog.karaolidis.com/ultimate-home-server-part-1/)
|
||||
- 2021-10-31 - [Better Home Storage: MergerFS + SnapRAID on OpenMediaVault](https://blog.sakuragawa.moe/better-home-storage-mergerfs-snapraid-on-openmediavault/)
|
||||
- 2021-11-28 - [Linux Magazine: Come Together - Merging file systems for a simple NAS with MergerFS](https://www.linux-magazine.com/Issues/2022/254/MergerFS)
|
||||
- 2022-06-04 - [MergerFS + SnapRaid Study](https://crashlaker.github.io/2022/06/04/mergerfs_+_snapraid_study.html)
|
||||
- 2022-12-31 - [Merge Storages in CasaOS: A secret beta feature you know now](https://blog.casaos.io/blog/13.html)
|
||||
- 2023-02-03 - [(MergerFS + SnapRAID) is the new RAID 5](https://thenomadcode.tech/mergerfs-snapraid-is-the-new-raid-5)
|
||||
- 2024-02-07 - [Designing & Deploying MANS - A Hybrid NAS Approach with SnapRAID, MergerFS, and OpenZFS](https://blog.muffn.io/posts/part-3-mini-100tb-nas)
|
||||
- 2024-03-11 - [Using MergerFS to combine multiple hard drives into one unified media storage](https://fullmetalbrackets.com/blog/two-drives-mergerfs/)
|
||||
- 2024-12-20 - [Pooling multiple drives on my Raspberry Pi with mergerfs](https://sebi.io/posts/2024-12-20-pooling-multiple-drives-with-mergerfs/)
|
||||
|
||||
|
||||
## Videos
|
||||
|
||||
- 2017-06-23 - [Alex Kretzschmar: Part 1 - Perfect Media Server 2017 - Introduction](https://www.youtube.com/watch?v=L5MH8q3lmmk)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 2 - Perfect Media server 2017 - Installing Debian 9 Stretch](https://www.youtube.com/watch?v=YpVVYRN_L_A)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 3 - Perfect Media Server 2017 - Install MergerFS and setting up your drives](https://www.youtube.com/watch?v=tbCMfm-jJ5Y)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 4 - Perfect Media Server 2017 - Installing Docker](https://www.youtube.com/watch?v=WYI32kx4hPE)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 5 - Perfect Media Server 2017 - Installing and Automating SnapRAID](https://www.youtube.com/watch?v=Ir5ZsUIbHXA)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 6 - Perfect Media Server 2017 -Turning your server into a NAS with Samba and NFS](https://www.youtube.com/watch?v=1hVdWq758ZQ)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 7 - Perfect Media Server 2017 - Managing your apps with docker-compose](https://www.youtube.com/watch?v=aI2rdw7_AmE)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 8 - Perfect Media Server 2017 - Manging your server using a web UI (Cockpit and Portainer)](https://www.youtube.com/watch?v=aLyTWdzDiCg)
|
||||
- 2018-04-24 - [ElectronicsWizardy: How to setup a Linux Fileserver with Snapraid and Mergerfs Re-Export](https://www.youtube.com/watch?v=D2Klx-X7pFo)
|
||||
- 2019-03-01 - [Snapraid and Unionfs: Advanced Array Options on Openmediavault (Better than ZFS and Unraid)](https://www.youtube.com/watch?v=FYkdPyCt5FU)
|
||||
- 2019-03-22 - [Gamexplicit: The Perfect Plex Media Server 2019! Part 1 (Hardware)](https://www.youtube.com/watch?v=rJIRPhM2WcE)
|
||||
- 2019-05-13 - [Gamexplicit: The Perfect Plex Media Server 2019! Part 2 (Ubuntu Server 18.04.2 LTS)](https://www.youtube.com/watch?v=aLyTWdzDiCg)
|
||||
- 2019-05-20 - [Gamexplicit: The Perfect Plex Media Server 2019! Part 3 (SnapRaid, Samba, Plex)](https://www.youtube.com/watch?v=uW5y43XC-BI)
|
||||
- 2020-08-23 - [Installing OpenMediaVault and SnapRAID and UnionFS (mergerfs)](https://www.youtube.com/watch?v=nDvzXM8UjAI)
|
||||
- 2021-06-07 - [I ditched TrueNAS for MergerFS - Chia Plot Storage](https://www.youtube.com/watch?v=tpqFywkbZa4)
|
||||
- 2021-08-03 - [Install and configure mergerfs to merge more than one folder in the same place](https://www.youtube.com/watch?v=69zcqEy1674)
|
||||
- 2021-08-10 - [Instalando e configurando mergerfs para unir mais de uma pasta no mesmo lugar](https://www.youtube.com/watch?v=-RLxbBNBWhU)
|
||||
- 2021-08-13 - [Let's Convert an Old Laptop to a NAS - What you should do](https://www.youtube.com/watch?v=F1v-TSbOymI)
|
||||
- 2021-08-17 - [How to Combine Multiple Disks as One by using MergerFS | Ubuntu 20.04 LTS](https://www.youtube.com/watch?v=9e46pz5Seo4)
|
||||
- 2021-08-20 - [Vamos converter um Laptop antigo para um NAS – O que você deve fazer](https://www.youtube.com/watch?v=q8EK9vWCRTc)
|
||||
- 2021-10-29 - [Unlimited space for your Plex using Rclone to connect to your Cloud](https://www.youtube.com/watch?v=ghGconyrF3M)
|
||||
- 2022-12-01 - [Make Your Home Server Go FAST! SSD Caching, 10Gbit Networking, etc.](https://www.youtube.com/watch?v=eRfqC_q3lkM&t=784s)
|
||||
- 2022-12-07 - [Best RAID for mixed drive sizes. Unraid vs BTRFS vs Snapraid+Mergerfs vs Storage spaces.](https://www.youtube.com/watch?v=NQJkTiLXfgs)
|
||||
- 2023-02-21 - [MergerFS + SnapRAID : Forget about RAID 5 in your Home Server !](https://www.youtube.com/watch?v=tX5MA-c6Qq4)
|
||||
- 2023-06-26 - [How to install and setup MergerFS](https://www.youtube.com/watch?v=n7piuhTXeG4)
|
||||
- 2023-07-31 - [How to recover a dead drive using Snapraid](https://www.youtube.com/watch?v=fmuiRLPcuJE)
|
||||
- 2024-01-05 - [OpenMediaVault MergerFS Tutorial (Portuguese)](https://www.youtube.com/watch?v=V6Yw86dRUPQ)
|
||||
- 2024-02-19 - [Setup and Install MergerFS and SnapRAID (Part 1)](https://noted.lol/mergerfs-and-snapraid-setup-1/)
|
||||
- 2024-02-22 - [Setup and Install MergerFS and SnapRAID (Part 2)](https://noted.lol/mergerfs-and-snapraid-setup-part-2/)
|
||||
- 2024-11-15 - [Meu servidor NAS - Parte 18: Recuperando um HD, recuperando o MergerFS e os próximos passos do NAS!](https://www.youtube.com/watch?v=5fy98kPzE3s)
|
||||
|
||||
|
||||
## Podcasts
|
||||
|
||||
- 2019-11-04 - [Jupiter Extras: A Chat with mergerfs Developer Antonio Musumeci | Jupiter Extras 28](https://www.youtube.com/watch?v=VmJUAyyhSPk)
|
||||
- 2019-11-07 - [Jupiter Broadcasting: ZFS Isn’t the Only Option | Self-Hosted 5](https://www.youtube.com/watch?v=JEW7UuKhMJ8)
|
||||
- 2023-10-08 - [Self Hosted Episode 105 - Sleeper Storage Technology](https://selfhosted.show/105)
|
||||
|
||||
|
||||
## Social Media
|
||||
|
||||
- [Reddit](https://www.reddit.com/search/?q=mergerfs&sort=new)
|
||||
- [X](https://x.com/search?q=mergerfs&src=spelling_expansion_revert_click&f=live)
|
||||
- [YouTube](https://www.youtube.com/results?search_query=mergerfs&sp=CAI%253D)
|
||||
- [ServeTheHome Forum](https://forums.servethehome.com/index.php?search/3105813/&q=mergerfs&o=date)
|
||||
@@ -0,0 +1,47 @@
|
||||
# Tweaking Performance
|
||||
|
||||
mergerfs is at its is a proxy and therefore its theoretical max
|
||||
performance is that of the underlying devices. However, given it is a
|
||||
FUSE based filesystem working from userspace there is an increase in
|
||||
overhead relative to kernel based solutions. That said the performance
|
||||
can match the theoretical max but it depends greatly on the system's
|
||||
configuration. Especially when adding network filesystems into the mix
|
||||
there are many variables which can impact performance. Device speeds
|
||||
and latency, network speeds and latency, concurrency and parallel
|
||||
limits of the hardware, read/write sizes, etc.
|
||||
|
||||
While some settings can impact performance they are all **functional**
|
||||
in nature. Meaning they change mergerfs' behavior in some way. As a
|
||||
result there is no such thing as a "performance mode".
|
||||
|
||||
If you're having performance issues please look over the suggestions
|
||||
below and the [benchmarking section.](benchmarking.md)
|
||||
|
||||
NOTE: Be sure to [read about these features](config/options.md) before
|
||||
changing them to understand how functionality will change.
|
||||
|
||||
* test theoretical performance using `nullrw` or mounting a ram disk
|
||||
* change read or process [thread pools](config/threads.md)
|
||||
* change [func.readdir](config/func_readdir.md)
|
||||
* increase [readahead](config/readahead.md): `readahead=1024`
|
||||
* disable `security_capability` and/or `xattr`
|
||||
* increase cache timeouts [cache.attr](config/cache.md#cacheattr),
|
||||
[cache.entry](config/cache.md#cacheentry),
|
||||
[cache.negative_entry](config/cache.md#cachenegative_entry)
|
||||
* enable (or disable) page caching ([cache.files](config/cache.md#cachefiles))
|
||||
* enable `parallel-direct-writes`
|
||||
* enable [cache.writeback](config/cache.md#cachewriteback)
|
||||
* enable [cache.statfs](config/cache.md#cachestatfs)
|
||||
* enable [cache.symlinks](config/cache.md#cachesymlinks)
|
||||
* enable [cache.readdir](config/cache.md#cachereaddir)
|
||||
* disable `posix_acl`
|
||||
* disable `async_read`
|
||||
* use [symlinkify](config/symlinkify.md) if your data is largely
|
||||
static and read-only
|
||||
* use [tiered cache](usage_patterns.md) devices
|
||||
* use LVM and LVM cache to place a SSD in front of your HDDs
|
||||
|
||||
If you come across a setting that significantly impacts performance
|
||||
please [contact trapexit](support.md) so he may investigate further. Please test
|
||||
both against your normal setup, a singular branch, and with
|
||||
`nullrw=true`
|
||||
@@ -0,0 +1,206 @@
|
||||
# Project Comparisons
|
||||
|
||||
## mhddfs
|
||||
|
||||
* [https://romanrm.net/mhddfs](https://romanrm.net/mhddfs)
|
||||
|
||||
mhddfs had not been updated in over a decade and has known stability
|
||||
and security issues. mergerfs provides a super set of mhddfs' features
|
||||
and offers better performance. In fact, as of 2020, the author of
|
||||
mhddfs has [moved to using
|
||||
mergerfs.](https://romanrm.net/mhddfs#update)
|
||||
|
||||
Below is an example of mhddfs and mergerfs setup to work similarly.
|
||||
|
||||
`mhddfs -o mlimit=4G,allow_other /mnt/drive1,/mnt/drive2 /mnt/pool`
|
||||
|
||||
`mergerfs -o minfreespace=4G,category.create=ff /mnt/drive1:/mnt/drive2 /mnt/pool`
|
||||
|
||||
|
||||
## aufs
|
||||
|
||||
* [https://aufs.sourceforge.net](https://aufs.sourceforge.net)
|
||||
* [https://en.wikipedia.org/wiki/Aufs](https://en.wikipedia.org/wiki/Aufs)
|
||||
|
||||
While aufs still is maintained it failed to be included in the
|
||||
mainline kernel and is no longer available in most Linux distros
|
||||
making it harder to get installed for the average user.
|
||||
|
||||
While aufs can often offer better peak performance due to being
|
||||
primarily kernel based, mergerfs provides more configurability and is
|
||||
generally easier to use. mergerfs however does not offer the overlay /
|
||||
copy-on-write (CoW) features which aufs has.
|
||||
|
||||
|
||||
## unionfs
|
||||
|
||||
* [https://unionfs.filesystems.org](https://unionfs.filesystems.org)
|
||||
|
||||
unionfs for Linux is a "stackable unification file system" which
|
||||
functions like many other union filesystems. unionfs has not been
|
||||
maintained and was last released for Linux v3.14 back in 2014.
|
||||
|
||||
Documentation is sparse so a comparison of features is not possible
|
||||
but given the lack of maintenance and support for modern kernels there
|
||||
is little reason to consider it as a solution.
|
||||
|
||||
|
||||
## unionfs-fuse
|
||||
|
||||
* [https://github.com/rpodgorny/unionfs-fuse](https://github.com/rpodgorny/unionfs-fuse)
|
||||
|
||||
unionfs-fuse is more like unionfs, aufs, and overlayfs than mergerfs
|
||||
in that it offers overlay / copy-on-write (CoW) features. If you're
|
||||
just looking to create a union of filesystems and want flexibility in
|
||||
file/directory placement then mergerfs offers that whereas
|
||||
unionfs-fuse is more for overlaying read/write filesystems over
|
||||
read-only ones.
|
||||
|
||||
Since unionfs-fuse, as the name suggests, is a FUSE based technology
|
||||
it can be used without elevated privileges that kernel solutions such
|
||||
as unionfs, aufs, and overlayfs require.
|
||||
|
||||
|
||||
## overlayfs
|
||||
|
||||
* [https://docs.kernel.org/filesystems/overlayfs.html](https://docs.kernel.org/filesystems/overlayfs.html)
|
||||
|
||||
overlayfs is effectively the successor to unionfs, unionfs-fuse, and
|
||||
aufs and is widely used by Linux container platforms such as Docker and
|
||||
Podman. It was developed and is maintained by the same developer who
|
||||
created FUSE.
|
||||
|
||||
If your use case is layering a writable filesystem on top of read-only
|
||||
filesystems then you should look first to overlayfs. Its feature set
|
||||
however is very different from mergerfs and solve different problems.
|
||||
|
||||
|
||||
## RAID0, JBOD, SPAN, drive concatenation, striping
|
||||
|
||||
* [RAID0](https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_0)
|
||||
* [JBOD](https://en.wikipedia.org/wiki/Non-RAID_drive_architectures#JBOD)
|
||||
* [SPAN](https://en.wikipedia.org/wiki/Non-RAID_drive_architectures#Concatenation_(SPAN,_BIG))
|
||||
* [striping](https://en.wikipedia.org/wiki/Data_striping)
|
||||
|
||||
These are block device technologies which in some form aggregate
|
||||
devices into what appears to be a singular device on which a
|
||||
traditional filesystem can be used. The filesystem has no
|
||||
understanding of the underlying block layout and should one of those
|
||||
underlying devices fail or be removed the filesystem will be missing
|
||||
that chunk which could contain critical information and the whole
|
||||
filesystem may become unrecoverable. Even if the data from the
|
||||
filesystem is recoverable it will take using specialized tooling to do
|
||||
so.
|
||||
|
||||
In contrast, with mergerfs you can format devices as one normally
|
||||
would or take existing filesystems and then combine them in a pool to
|
||||
aggregate their storage. The failure of any one device will have no
|
||||
impact on the other devices. The downside to mergerfs' technique is
|
||||
the fact you don't actually have contiguous space as large as if you
|
||||
used those other technologies. Meaning you can't create a file greater
|
||||
than 1TB on a pool of 2 1TB filesystems.
|
||||
|
||||
|
||||
## RAID5, RAID6
|
||||
|
||||
* [RAID5](https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_5)
|
||||
* [RAID6](https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_6)
|
||||
|
||||
mergerfs offers no parity or redundancy features so in that regard the
|
||||
technologies are not comparable. [SnapRAID](https://www.snapraid.it)
|
||||
can be used in combination with mergerfs to provide redundancy. Unlike
|
||||
traditional RAID5 or RAID6 SnapRAID works with drives of different
|
||||
sizes and can have more than 2 parity drives. However, parity
|
||||
calculations are not done in real-time.
|
||||
|
||||
See [https://www.snapraid.it/compare](https://www.snapraid.it/compare)
|
||||
for more details and comparisons.
|
||||
|
||||
|
||||
## UnRAID
|
||||
|
||||
* [https://unraid.net](https://unraid.net)
|
||||
|
||||
UnRAID is a full OS and offers a (FUSE based?) filesystem which
|
||||
provides a union of filesystems like mergerfs but with the addition of
|
||||
live parity calculation and storage. Outside parity calculations
|
||||
mergerfs offers more features and due to the lack of real-time parity
|
||||
calculation can have higher peak performance. Some users also prefer
|
||||
an open source solution.
|
||||
|
||||
For semi-static data mergerfs + [SnapRAID](http://www.snapraid.it)
|
||||
provides a similar, but not real-time, solution.
|
||||
|
||||
|
||||
## ZFS
|
||||
|
||||
* [https://en.wikipedia.org/wiki/ZFS](https://en.wikipedia.org/wiki/ZFS)
|
||||
|
||||
mergerfs is very different from ZFS. mergerfs is intended to provide
|
||||
flexible pooling of arbitrary filesystems (local or remote), of
|
||||
arbitrary sizes, and arbitrary filesystems. Particularly in `write
|
||||
once, read many` use cases such as bulk media storage. Where data
|
||||
integrity and backup is managed in other ways. In those use cases ZFS
|
||||
can introduce a number of costs and limitations as described
|
||||
[here](http://louwrentius.com/the-hidden-cost-of-using-zfs-for-your-home-nas.html),
|
||||
[here](https://markmcb.com/2020/01/07/five-years-of-btrfs/), and
|
||||
[here](https://utcc.utoronto.ca/~cks/space/blog/solaris/ZFSWhyNoRealReshaping).
|
||||
|
||||
|
||||
## StableBit's DrivePool
|
||||
|
||||
* [https://stablebit.com](https://stablebit.com)
|
||||
|
||||
DrivePool works only on Windows so not as common an alternative as
|
||||
other Linux solutions. If you want to use Windows then DrivePool is a
|
||||
good option. Functionally the two projects work a bit
|
||||
differently. DrivePool always writes to the filesystem with the most
|
||||
free space and later rebalances. mergerfs does not currently offer
|
||||
rebalance but chooses a branch at file/directory create
|
||||
time. DrivePool's rebalancing can be done differently in any directory
|
||||
and has file pattern matching to further customize the
|
||||
behavior. mergerfs, not having rebalancing does not have these
|
||||
features, but similar features are planned for mergerfs v3. DrivePool
|
||||
has builtin file duplication which mergerfs does not natively support
|
||||
(but can be done via an external script.)
|
||||
|
||||
There are a lot of misc differences between the two projects but most
|
||||
features in DrivePool can be replicated with external tools in
|
||||
combination with mergerfs.
|
||||
|
||||
Additionally, DrivePool is a closed source commercial product vs
|
||||
mergerfs a ISC licensed open source project.
|
||||
|
||||
|
||||
## Plan9 binds
|
||||
|
||||
* [https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs#Union_directories_and_namespaces](https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs#Union_directories_and_namespaces)
|
||||
|
||||
Plan9 has the native ability to bind multiple paths/filesystems
|
||||
together to create a setup similar to simplified union
|
||||
filesystem. Such bind mounts choose files in a "first found" in the
|
||||
order they are listed similar to mergerfs' `ff` policy. Similar, when
|
||||
creating a file it will be created on the first directory in the
|
||||
union.
|
||||
|
||||
Plan 9 isn't a widely used OS so this comparison is mostly academic.
|
||||
|
||||
|
||||
## SnapRAID pooling
|
||||
|
||||
[SnapRAID](https://www.snapraid.it/manual) has a pooling feature which
|
||||
creates "a read-only virtual view of all the files in your array using
|
||||
symbolic links."
|
||||
|
||||
As mentioned in the description this "view" is just the creation of
|
||||
the same directory layout with symlinks to all files. This means that
|
||||
reads (and writes) to files are at native speeds but limited in that
|
||||
it can not practically be used as a target for writing new files and
|
||||
is only updated when `snapraid pool` is run. Note that some software
|
||||
treat symlinks differently than regular files. For instance some
|
||||
backup software will skip symlinks by default.
|
||||
|
||||
mergerfs has the feature [symlinkify](config/symlinkify.md) which
|
||||
provides a similar behavior but is more flexible in that it is not
|
||||
read-only. That said there can still be some software that won't like
|
||||
that kind of setup.
|
||||
@@ -0,0 +1,193 @@
|
||||
# QuickStart
|
||||
|
||||
## Install
|
||||
|
||||
First ensure you have the [latest version installed](setup/installation.md).
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
mergerfs has many [options](config/options.md) and effectively all of
|
||||
them are functional in nature. What that means is that there is no
|
||||
"best" or "fastest" configuration. No "make faster"
|
||||
options. Everything changes behavior. Sometimes those changes in
|
||||
behavior affect performance.
|
||||
|
||||
If you don't already know that you have special requirements then use
|
||||
one of the following option sets as it will cover the common use
|
||||
cases.
|
||||
|
||||
|
||||
### You use Linux v6.6 or above
|
||||
|
||||
* cache.files=off
|
||||
* category.create=pfrd
|
||||
* dropcacheonclose=false
|
||||
|
||||
In previous versions of Linux it was unable to support `mmap` if [page
|
||||
caching](config/cache.md) was disabled (ie:
|
||||
`cache.files=off`). However, it now will enable page caching if needed
|
||||
for a particular file if `mmap` is requested.
|
||||
|
||||
`mmap` is needed by certain software to read and write to a
|
||||
file. However, many software could work without it and fail to have
|
||||
proper error handling. Many programs that use sqlite3 will require
|
||||
`mmap` despite [sqlite3 working perfectly
|
||||
fine](known_issues_bugs.md#sqlite3-plex-jellyfin-do-not-work-with-mergerfs)
|
||||
without it (and in some cases can be more performant with regular file
|
||||
IO.)
|
||||
|
||||
|
||||
### You use Linux v6.5 or below
|
||||
|
||||
#### You need `mmap` (used by rtorrent and many sqlite3 base software)
|
||||
|
||||
* cache.files=auto-full
|
||||
* category.create=pfrd
|
||||
* dropcacheonclose=true
|
||||
|
||||
|
||||
#### You don't need `mmap`
|
||||
|
||||
* cache.files=off
|
||||
* category.create=pfrd
|
||||
* dropcacheonclose=false
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Command Line
|
||||
|
||||
```
|
||||
mergerfs -o cache.files=off,dropcacheonclose=false,category.create=pfrd /mnt/hdd0:/mnt/hdd1 /media
|
||||
```
|
||||
|
||||
|
||||
### /etc/fstab
|
||||
|
||||
```
|
||||
/mnt/hdd0:/mnt/hdd1 /media mergerfs cache.files=off,dropcacheonclose=false,category.create=pfrd 0 0
|
||||
```
|
||||
|
||||
### /etc/fstab w/ config file
|
||||
|
||||
For more complex setups it can be useful to separate out the config.
|
||||
|
||||
|
||||
#### /etc/fstab
|
||||
|
||||
```
|
||||
/etc/mergerfs/branches/media/* /media mergerfs config=/etc/mergerfs/config/media.ini
|
||||
```
|
||||
|
||||
|
||||
#### /etc/mergerfs/config/media.ini
|
||||
|
||||
```ini title="media.ini" linenums="1"
|
||||
cache.files=off
|
||||
category.create=pfrd
|
||||
dropcacheonclose=false
|
||||
```
|
||||
|
||||
#### /etc/mergerfs/branches/media/
|
||||
|
||||
Create a bunch of symlinks to point to the branch. mergerfs will
|
||||
resolve the symlinks and use the real path.
|
||||
|
||||
`ls -lh /etc/mergerfs/branches/media/*`
|
||||
|
||||
```text
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd00 -> /mnt/hdd/hdd00
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd01 -> /mnt/hdd/hdd01
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd02 -> /mnt/hdd/hdd02
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd03 -> /mnt/hdd/hdd03
|
||||
```
|
||||
|
||||
### systemd (simple)
|
||||
|
||||
`/etc/systemd/system/mergerfs-media.service`
|
||||
|
||||
```systemd title="mergerfs-media.service" linenums="1"
|
||||
[Unit]
|
||||
Description=mergerfs /media service
|
||||
After=local-fs.target network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
KillMode=none
|
||||
ExecStart=/usr/bin/mergerfs \
|
||||
-f \
|
||||
-o cache.files=off \
|
||||
-o category.create=pfrd \
|
||||
-o dropcacheonclose=false \
|
||||
/mnt/hdd0:/mnt/hdd1 \
|
||||
/media
|
||||
ExecStop=/bin/fusermount -uz /media
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
|
||||
### systemd (w/ setup script)
|
||||
|
||||
Since it isn't well documented otherwise: if you wish to do some setup before
|
||||
you mount mergerfs follow this example.
|
||||
|
||||
#### setup-for-mergerfs
|
||||
|
||||
`/usr/local/bin/setup-for-mergerfs`
|
||||
|
||||
```shell title="setup-for-mergerfs" linenums="1"
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Perform setup
|
||||
/bin/sleep 10
|
||||
|
||||
# Report back to systemd that things are ready
|
||||
/bin/systemd-notify --ready
|
||||
```
|
||||
|
||||
#### setup-for-mergerfs.service
|
||||
|
||||
`/etc/systemd/system/setup-for-mergerfs.service`
|
||||
|
||||
```systemd title="setup-for-mergerfs.service" linenums="1"
|
||||
[Unit]
|
||||
Description=mergerfs setup service
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/local/bin/setup-for-mergerfs
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
|
||||
#### mergerfs-media.service
|
||||
|
||||
`/etc/systemd/system/mergerfs-media.service`
|
||||
|
||||
```systemd title="mergerfs-media.service" linenums="1"
|
||||
[Unit]
|
||||
Description=mergerfs /media service
|
||||
Requires=setup-for-mergerfs.service
|
||||
After=local-fs.target network.target prepare-for-mergerfs.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
KillMode=none
|
||||
ExecStart=/usr/bin/mergerfs \
|
||||
-f \
|
||||
-o cache.files=off \
|
||||
-o category.create=pfrd \
|
||||
-o dropcacheonclose=false \
|
||||
/mnt/hdd0:/mnt/hdd1 \
|
||||
/media
|
||||
ExecStop=/bin/fusermount -uz /media
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
@@ -0,0 +1,83 @@
|
||||
# Related Projects
|
||||
|
||||
## Projects using mergerfs
|
||||
|
||||
* [Lakka.tv](https://lakka.tv/): A turnkey software emulation Linux
|
||||
distribution. Used to pool user and local storage. Also includes my
|
||||
other project [Opera](https://retroarch.com/). A 3DO emulator.
|
||||
* [OpenMediaVault](https://www.openmediavault.org): A network attached
|
||||
storage (NAS) solution based on Debian Linux. They provide plugins
|
||||
to manage mergerfs.
|
||||
* [CasaOS](https://casaos.io): "A simple, easy to use, elegant open
|
||||
source home cloud system." Has added initial integration with
|
||||
mergerfs to create pools from existing filesystems.
|
||||
* [ZimaOS](https://github.com/IceWhaleTech/zimaos-rauc): A more
|
||||
commercially focused NAS OS by the authors of CasaOS at [Ice
|
||||
Whale](https://www.zimaboard.com/).
|
||||
* [Cosmos Cloud](https://cosmos-cloud.io/): Cosmos "take the chore out
|
||||
of selfhosting, with automated maintenance and fully secured setup
|
||||
out of the box. It even integrates to your existing setup."
|
||||
|
||||
|
||||
## Software and services commonly used with mergerfs
|
||||
|
||||
* [snapraid](https://www.snapraid.it/): a backup program designed for
|
||||
disk arrays, storing parity information for data recovery in the
|
||||
event of up to six disk failures.
|
||||
* [rclone](https://rclone.org/): a command-line program to manage
|
||||
files on cloud storage. It is a feature-rich alternative to cloud
|
||||
vendors' web storage interfaces. rclone's
|
||||
[union](https://rclone.org/union/) feature is based on mergerfs
|
||||
policies.
|
||||
* [ZFS](https://openzfs.org/): A popular filesystem and volume
|
||||
management platform originally part of Sun Solaris and later ported
|
||||
to other operating systems. It is common to use ZFS with
|
||||
mergerfs. ZFS for important data and mergerfs pool for replacable
|
||||
media.
|
||||
* [Proxmox](https://www.proxmox.com/): Proxmox is a popular, Debian
|
||||
based, virtualization platform. Users tend to install mergerfs on
|
||||
the host and pass the mount into containers.
|
||||
* [UnRAID](https://unraid.net): "Unraid is a powerful, easy-to-use
|
||||
operating system for self-hosted servers and network-attached
|
||||
storage." While UnRAID has its own union filesystem it isn't
|
||||
uncommon to see UnRAID users leverage mergerfs given the differences
|
||||
in the technologies. There is a [plugin available by
|
||||
Rysz](https://forums.unraid.net/topic/144999-plugin-mergerfs-for-unraid-support-topic/)
|
||||
to ease installation and setup.
|
||||
* [TrueNAS SCALE](https://www.truenas.com/truenas-scale/): An
|
||||
enterprise focused NAS operating system with OpenZFS support. A Some
|
||||
users are requesting mergerfs be [made part
|
||||
of](https://forums.truenas.com/t/add-unionfs-or-mergerfs-and-rdam-enhancement-then-beat-all-other-nas-systems/23218)
|
||||
TrueNAS.
|
||||
* For a time there were a number of Chia miners recommending mergerfs.
|
||||
* [cloudboxes.io](https://cloudboxes.io): VPS provider. Includes
|
||||
details [on their
|
||||
wiki](https://cloudboxes.io/wiki/how-to/apps/set-up-mergerfs-using-ssh):
|
||||
on how to setup mergerfs.
|
||||
* [QNAP](https://www.myqnap.org/product/mergerfs-apache83/): A company
|
||||
known for their turnkey, consumer focused NAS devices. Someone has
|
||||
created builds of mergerfs for different QNAP devices.
|
||||
|
||||
|
||||
## Distributions including mergerfs
|
||||
|
||||
mergerfs can be found in the
|
||||
[repositories](https://pkgs.org/download/mergerfs) of [many
|
||||
Linux](https://repology.org/project/mergerfs/versions) distributions
|
||||
and FreeBSD.
|
||||
|
||||
Note: Any non-rolling release based distro is likely to have
|
||||
out-of-date versions.
|
||||
|
||||
* [Debian](https://packages.debian.org/bullseye/mergerfs)
|
||||
* [Ubuntu](https://launchpad.net/ubuntu/+source/mergerfs)
|
||||
* [Fedora](https://rpmsphere.github.io/)
|
||||
* [T2](https://t2sde.org/packages/mergerfs)
|
||||
* [Alpine](https://pkgs.alpinelinux.org/packages?name=mergerfs&branch=edge&repo=&arch=&maintainer=)
|
||||
* [Gentoo](https://packages.gentoo.org/packages/sys-fs/mergerfs)
|
||||
* [Arch (AUR)](https://aur.archlinux.org/packages/mergerfs)
|
||||
* [Void](https://voidlinux.org/packages/?arch=x86_64&q=mergerfs)
|
||||
* [NixOS](https://search.nixos.org/packages?type=packages&query=mergerfs)
|
||||
* [Guix]()
|
||||
* [Slackware](https://slackbuilds.org/repository/15.0/system/mergerfs/?search=mergerfs)
|
||||
* [FreeBSD](https://www.freshports.org/filesystems/mergerfs)
|
||||
@@ -0,0 +1,154 @@
|
||||
# Remote Filesystems
|
||||
|
||||
This section is to describe any known issues or quirks when using
|
||||
mergerfs with common remote filesystems.
|
||||
|
||||
There are two ways to use mergerfs with a network filesystem. One is
|
||||
to use it within the pool as a branch and one is the exporting of a
|
||||
mergerfs mount.
|
||||
|
||||
|
||||
## General Notes
|
||||
|
||||
### Do not change things out-of-band
|
||||
|
||||
Keep in mind that, like when using
|
||||
[caching](faq/usage_and_functionality.md#can-filesystems-still-be-used-directly-outside-of-mergerfs-while-pooled),
|
||||
it is **NOT** a good idea to change the contents of the remote
|
||||
filesystem
|
||||
[out-of-band](https://en.wikipedia.org/wiki/Out-of-band). Meaning that
|
||||
you should not change the contents of the underlying filesystems or
|
||||
mergerfs on the server hosting the remote filesystem. Files should
|
||||
exclusively be interacted with through the network filesystem. Doing
|
||||
otherwise can lead to weird behavior, inconsistency, errors, and even
|
||||
data corruption should multiple programs try to write or read the same
|
||||
data at the same time. This isn't to say you can't do it or that data
|
||||
corruption is likely but it _could_ happen. If you're only reading
|
||||
from those filesystems there is little risk but writing or modifying
|
||||
file layout will be a problem. Particularly with NFS. It is better to
|
||||
always use the remote filesystem. Even on the machine serving it.
|
||||
|
||||
|
||||
## NFS
|
||||
|
||||
[NFS](https://en.wikipedia.org/wiki/Network_File_System) is a common
|
||||
remote filesystem on Unix/POSIX systems. Due to how NFS works there
|
||||
are some settings which need to be set in order for mergerfs to work
|
||||
with it.
|
||||
|
||||
### NFS as branch
|
||||
|
||||
mergerfs settings:
|
||||
|
||||
* No special settings need to be set
|
||||
|
||||
NFS export settings:
|
||||
|
||||
* `no_root_squash`: mergerfs must be able to make requests that only
|
||||
root is permissioned to make. If any root squashing occurs, just as
|
||||
running mergerfs as a non-root user, there is no guarantee that
|
||||
mergerfs will be able to do what it needs to manage the underlying
|
||||
filesystem.
|
||||
|
||||
|
||||
### NFS exporting mergerfs
|
||||
|
||||
It should be noted that NFS and FUSE (the technology mergerfs uses) do
|
||||
not work perfectly with one another. They largely can be worked around
|
||||
but if you run into problems it may be worth trying Samba/SMB.
|
||||
|
||||
**mergerfs settings:**
|
||||
|
||||
* `noforget`
|
||||
* `inodecalc=path-hash`
|
||||
|
||||
`noforget` is needed because NFS uses the `name_to_handle_at` and
|
||||
`open_by_handle_at` functions which allow a program to keep a
|
||||
reference to a file without technically having it open in the typical
|
||||
sense. The problem is that FUSE has no way to know that NFS has a
|
||||
handle that it will later use to open the file again. As a result, it
|
||||
is possible for the kernel to tell mergerfs to forget about the file
|
||||
node and should NFS ever ask for that node's details in the future it
|
||||
would have nothing to respond with. Keeping nodes around forever is
|
||||
not ideal but at the moment the only way to manage the situation.
|
||||
|
||||
`inodecalc=path-hash` is needed because NFS is sensitive to
|
||||
out-of-band changes. FUSE doesn't care if a file's inode value changes
|
||||
but NFS, being stateful, does. So if you used the default inode
|
||||
calculation algorithm it is possible that if you changed a file or
|
||||
updated a directory the file mergerfs will use will be on a different
|
||||
branch and therefore the inode would change. This isn't an ideal
|
||||
solution and others are being considered but it works for most
|
||||
situations.
|
||||
|
||||
**NFS export settings:**
|
||||
|
||||
* `fsid=UUID`
|
||||
* `no_root_squash`
|
||||
|
||||
|
||||
`fsid=UUID` is needed because FUSE filesystems don't have different
|
||||
`st_dev` values which can cause issues when exporting. The easiest
|
||||
thing to do is set each mergerfs export `fsid` to some random
|
||||
value. An easy way to generate a random value is to use the command
|
||||
line tool `uuid` or `uuidgen` or through a website such as
|
||||
[uuidgenerator.net](https://www.uuidgenerator.net/).
|
||||
|
||||
`no_root_squash` is required for the same reason mergerfs needs to run
|
||||
as `root`. Certain behaviors of mergerfs require control over the
|
||||
filesystem that only `root` can preform. If squashing is enabled, or
|
||||
mergerfs was running as non-root, it would be unable to perform
|
||||
certain function and you will receive permission errors.
|
||||
|
||||
|
||||
## SMB / CIFS
|
||||
|
||||
[SMB](https://en.wikipedia.org/wiki/Server_Message_Block) is a
|
||||
protocol most used by Microsoft Windows systems to share file shares,
|
||||
printers, etc. However, due to the popularity of Windows, it is also
|
||||
supported on many other platforms including Linux. The most popular
|
||||
way of supporting SMB on Linux is via the software Samba.
|
||||
|
||||
### SMB as branch
|
||||
|
||||
Using a SMB mount as a branch in mergerfs may result in problems
|
||||
(permission errors) since it is not POSIX compliant. This setup is not
|
||||
common and has not been extensively tested.
|
||||
|
||||
|
||||
### SMB exporting mergerfs
|
||||
|
||||
[Samba](<https://en.wikipedia.org/wiki/Samba_(software)>) and other
|
||||
ways of serving Linux filesystems via SMB should work fine with
|
||||
mergerfs. The services do not tend to use the same technologies which
|
||||
NFS uses and therefore don't have the same issues. There should not be
|
||||
special settings required export mergerfs with Samba. However,
|
||||
[CIFSD](https://en.wikipedia.org/wiki/CIFSD) and other programs have
|
||||
not been extensively tested. If you use mergerfs with CIFSD or other
|
||||
SMB servers please submit your experiences so these docs can be
|
||||
updated.
|
||||
|
||||
|
||||
## SSHFS
|
||||
|
||||
[SSHFS](https://en.wikipedia.org/wiki/SSHFS) is a FUSE filesystem
|
||||
leveraging SSH as the connection and transport layer. While often
|
||||
simpler to setup when compared to NFS or Samba the performance can be
|
||||
lacking and the project is very much in maintenance mode.
|
||||
|
||||
There are no known issues using sshfs with mergerfs. You may want to
|
||||
use the following arguments to improve performance but your millage
|
||||
may vary.
|
||||
|
||||
* `-o Ciphers=arcfour`
|
||||
* `-o Compression=no`
|
||||
|
||||
More info can be found
|
||||
[here](https://ideatrash.net/2016/08/odds-and-ends-optimizing-sshfs-moving.html).
|
||||
|
||||
|
||||
## Other
|
||||
|
||||
There are other remote filesystems but none popularly used to serve
|
||||
mergerfs. If you use something not listed above feel free to reach out
|
||||
and I will add it to the list.
|
||||
@@ -0,0 +1,114 @@
|
||||
# Runtime Interfaces
|
||||
|
||||
## Runtime Config
|
||||
|
||||
### .mergerfs pseudo file
|
||||
|
||||
```
|
||||
<mountpoint>/.mergerfs
|
||||
```
|
||||
|
||||
There is a pseudo file available at the mount point which allows for
|
||||
the runtime modification of certain **mergerfs** options. The file
|
||||
will not show up in **readdir** but can be **stat**'ed and manipulated
|
||||
via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr)
|
||||
calls.
|
||||
|
||||
Any changes made at runtime are **not** persisted. If you wish for
|
||||
values to persist they must be included as options wherever you
|
||||
configure the mounting of mergerfs (/etc/fstab).
|
||||
|
||||
|
||||
#### Keys
|
||||
|
||||
Use `getfattr -d /mountpoint/.mergerfs` or `xattr -l
|
||||
/mountpoint/.mergerfs` to see all supported keys. Some are
|
||||
informational and therefore read-only. `setxattr` will return EINVAL
|
||||
(invalid argument) on read-only keys.
|
||||
|
||||
|
||||
#### Values
|
||||
|
||||
Same as the command line.
|
||||
|
||||
|
||||
##### user.mergerfs.branches
|
||||
|
||||
Used to query or modify the list of branches. When modifying there are
|
||||
several shortcuts to easy manipulation of the list.
|
||||
|
||||
| Value | Description |
|
||||
| -------- | -------------------------- |
|
||||
| [list] | set |
|
||||
| +<[list] | prepend |
|
||||
| +>[list] | append |
|
||||
| -[list] | remove all values provided |
|
||||
| -< | remove first in list |
|
||||
| -> | remove last in list |
|
||||
|
||||
`xattr -w user.mergerfs.branches +</mnt/drive3 /mnt/pool/.mergerfs`
|
||||
|
||||
The `=NC`, `=RO`, `=RW` syntax works just as on the command line.
|
||||
|
||||
##### Example
|
||||
|
||||
```
|
||||
[trapexit:/mnt/mergerfs] $ getfattr -d .mergerfs
|
||||
user.mergerfs.branches="/mnt/a=RW:/mnt/b=RW"
|
||||
user.mergerfs.minfreespace="4294967295"
|
||||
user.mergerfs.moveonenospc="false"
|
||||
...
|
||||
|
||||
[trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs
|
||||
user.mergerfs.category.search="ff"
|
||||
|
||||
[trapexit:/mnt/mergerfs] $ setfattr -n user.mergerfs.category.search -v newest .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs
|
||||
user.mergerfs.category.search="newest"
|
||||
```
|
||||
|
||||
### file / directory xattrs
|
||||
|
||||
While they won't show up when using `getfattr` **mergerfs** offers a
|
||||
number of special xattrs to query information about the files
|
||||
served. To access the values you will need to issue a
|
||||
[getxattr](http://linux.die.net/man/2/getxattr) for one of the
|
||||
following:
|
||||
|
||||
- **user.mergerfs.basepath**: the base mount point for the file given the current getattr policy
|
||||
- **user.mergerfs.relpath**: the relative path of the file from the perspective of the mount point
|
||||
- **user.mergerfs.fullpath**: the full path of the original file given the getattr policy
|
||||
- **user.mergerfs.allpaths**: a NUL ('\0') separated list of full paths to all files found
|
||||
|
||||
## Signals
|
||||
|
||||
- USR1: This will cause mergerfs to send invalidation notifications to
|
||||
the kernel for all files. This will cause all unused files to be
|
||||
released from memory.
|
||||
- USR2: Trigger a general cleanup of currently unused memory. A more
|
||||
thorough version of what happens every ~15 minutes.
|
||||
|
||||
## ioctl
|
||||
|
||||
Found in `fuse_ioctl.cpp`:
|
||||
|
||||
```C++
|
||||
typedef char IOCTL_BUF[4096];
|
||||
#define IOCTL_APP_TYPE 0xDF
|
||||
#define IOCTL_FILE_INFO _IOWR(IOCTL_APP_TYPE,0,IOCTL_BUF)
|
||||
#define IOCTL_GC _IO(IOCTL_APP_TYPE,1)
|
||||
#define IOCTL_GC1 _IO(IOCTL_APP_TYPE,2)
|
||||
#define IOCTL_INVALIDATE_ALL_NODES _IO(IOCTL_APP_TYPE,3)
|
||||
```
|
||||
|
||||
- IOCTL_FILE_INFO: Same as the "file / directory xattrs" mentioned
|
||||
above. Use a buffer size of 4096 bytes. Pass in a string of
|
||||
"basepath", "relpath", "fullpath", or "allpaths". Receive details in
|
||||
same buffer.
|
||||
- IOCTL_GC: Triggers a thorough garbage collection of excess
|
||||
memory. Same as SIGUSR2.
|
||||
- IOCTL_GC1: Triggers a simple garbage collection of excess
|
||||
memory. Same as what happens every 15 minutes normally.
|
||||
- IOCTL_INVALIDATE_ALL_NODES: Same as SIGUSR1. Send invalidation
|
||||
notifications to the kernel for all files causing unused files to be
|
||||
released from memory.
|
||||
@@ -0,0 +1,67 @@
|
||||
# Build
|
||||
|
||||
**NOTE:** Prebuilt packages can be found at and recommended for most
|
||||
users: https://github.com/trapexit/mergerfs/releases
|
||||
|
||||
**NOTE:** Only tagged releases are supported. `master` and other
|
||||
branches should be considered works in progress.
|
||||
|
||||
First, get the code from [github](https://github.com/trapexit/mergerfs).
|
||||
|
||||
```
|
||||
$ git clone https://github.com/trapexit/mergerfs.git
|
||||
$ # or
|
||||
$ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.tar.gz
|
||||
```
|
||||
|
||||
## Debian / Ubuntu
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
$ sudo tools/install-build-pkgs
|
||||
$ make deb
|
||||
$ sudo dpkg -i ../mergerfs_<version>_<arch>.deb
|
||||
```
|
||||
|
||||
## RHEL / CentOS / Rocky / Fedora
|
||||
|
||||
```
|
||||
$ su -
|
||||
# cd mergerfs
|
||||
# tools/install-build-pkgs
|
||||
# make rpm
|
||||
# rpm -i rpmbuild/RPMS/<arch>/mergerfs-<version>.<arch>.rpm
|
||||
```
|
||||
|
||||
## Generic Linux
|
||||
|
||||
Have git, g++ or clang, make, python installed.
|
||||
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
## FreeBSD
|
||||
|
||||
Have git, g++ or clang, gmake, python installed.
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
$ gmake
|
||||
$ gmake install # as root
|
||||
```
|
||||
|
||||
|
||||
## Build options
|
||||
|
||||
```
|
||||
$ make help
|
||||
usage: make
|
||||
|
||||
make USE_XATTR=0 - build program without xattrs functionality
|
||||
make STATIC=1 - build static binary
|
||||
make LTO=1 - build with link time optimization
|
||||
```
|
||||
@@ -0,0 +1,97 @@
|
||||
# Installation
|
||||
|
||||
If you are using a non-rolling release Linux distro such as Debian or
|
||||
Ubuntu then you are almost certainly going to have an old version of
|
||||
mergerfs installed if you use the "official" package. For that reason
|
||||
we provide packages for major stable released distros.
|
||||
|
||||
Before reporting issues or bugs please be sure to upgrade to the
|
||||
latest release to confirm they still exist.
|
||||
|
||||
All provided packages can be found at [https://github.com/trapexit/mergerfs/releases](https://github.com/trapexit/mergerfs/releases)
|
||||
|
||||
## ArchLinux
|
||||
|
||||
1. Setup AUR
|
||||
2. `pacman -S mergerfs`
|
||||
|
||||
## CentOS / Rocky
|
||||
|
||||
Get the RPM from the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.el<rel>.<arch>.rpm
|
||||
sudo rpm -i mergerfs-<ver>.el<rel>.<arch>.rpm
|
||||
```
|
||||
|
||||
## Debian based OS
|
||||
|
||||
Debian/Ubuntu/Raspberry Pi
|
||||
|
||||
Most Debian based OS installs are of a stable branch and therefore do not have
|
||||
the most up to date software. While mergerfs is available via `apt` it
|
||||
is suggested that users install the most recent version available from
|
||||
the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
### prebuilt deb
|
||||
|
||||
#### Debian
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs_<ver>.debian-<rel>_<arch>.deb
|
||||
sudo dpkg -i mergerfs_<ver>.debian-<rel>_<arch>.deb
|
||||
```
|
||||
|
||||
#### Ubuntu
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<version>/mergerfs_<ver>.ubuntu-<rel>_<arch>.deb
|
||||
sudo dpkg -i mergerfs_<ver>.ubuntu-<rel>_<arch>.deb
|
||||
```
|
||||
|
||||
### apt
|
||||
|
||||
```
|
||||
sudo apt install -y mergerfs
|
||||
```
|
||||
|
||||
## Fedora
|
||||
|
||||
Get the RPM from the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.fc<rel>.<arch>.rpm
|
||||
sudo rpm -i mergerfs-<ver>.fc<rel>.<arch>.rpm
|
||||
```
|
||||
|
||||
## FreeBSD
|
||||
|
||||
[https://www.freshports.org/filesystems/mergerfs](https://www.freshports.org/filesystems/mergerfs)
|
||||
|
||||
```
|
||||
pkg install filesystems/mergerfs
|
||||
```
|
||||
|
||||
## NixOS
|
||||
|
||||
[search.nixos.org](https://search.nixos.org/packages?channel=unstable&show=mergerfs&from=0&size=50&sort=relevance&type=packages&query=mergerfs)
|
||||
|
||||
```
|
||||
nix-env -iA nixos.mergerfs
|
||||
```
|
||||
|
||||
## Other Linux Distros
|
||||
|
||||
[Check your distro.](../related_projects.md#distributions-including-mergerfs)
|
||||
|
||||
## Static Linux Binaries
|
||||
|
||||
If your distro does not package mergerfs there are static binaries
|
||||
provided.
|
||||
|
||||
Get the tarball from the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-static-linux_<arch>.tar.gz
|
||||
sudo tar xvf mergerfs-static-linux_<arch>.tar.gz -C /
|
||||
```
|
||||
@@ -0,0 +1,29 @@
|
||||
# Upgrade
|
||||
|
||||
mergerfs can be upgraded live by mounting on top of the previous
|
||||
instance. Simply install the new version of mergerfs and follow the
|
||||
instructions below.
|
||||
|
||||
Run mergerfs again or if using `/etc/fstab` (or systemd mount file)
|
||||
call for it to mount again. Existing open files and directories will
|
||||
continue to work fine though they won't see any differences that the
|
||||
new version would provide since it is still using the previous
|
||||
instance. If you plan on changing settings with the new mount you
|
||||
should / could apply those before mounting the new version.
|
||||
|
||||
```
|
||||
$ sudo mount /mnt/mergerfs
|
||||
$ mount | grep mergerfs
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
```
|
||||
|
||||
A problem with this approach is that the underlying instance will
|
||||
continue to run even if the software using it stop or are
|
||||
restarted. To work around this you can use a "lazy umount". Before
|
||||
mounting over top the mount point with the new instance of mergerfs
|
||||
issue: `umount -l <mergerfs_mountpoint>`. Or you can let mergerfs do
|
||||
it by setting the option `lazy-umount-mountpoint=true`.
|
||||
|
||||
If the intent is to change settings at runtime then the [runtime
|
||||
interface](../runtime_interfaces.md) should be used.
|
||||
@@ -0,0 +1,17 @@
|
||||
# Sponsorship and Donations
|
||||
|
||||
[https://github.com/trapexit/support](https://github.com/trapexit/support)
|
||||
|
||||
Development and support of a project like mergerfs requires a
|
||||
significant amount of time and effort. The software is released under
|
||||
the very liberal [ISC](https://opensource.org/license/isc-license-txt)
|
||||
license and is therefore free to use for personal or commercial uses.
|
||||
|
||||
If you are a non-commercial user and find mergerfs and its support valuable
|
||||
and would like to support the project financially it would be very
|
||||
much appreciated.
|
||||
|
||||
If you are using mergerfs commercially please consider sponsoring the
|
||||
project to ensure it continues to be maintained and receive
|
||||
updates. If custom features are needed feel free to [contact me
|
||||
directly](mailto:support@spawn.link).
|
||||
@@ -0,0 +1,45 @@
|
||||
# Support
|
||||
|
||||
Filesystems are complex, as are the interactions software have with
|
||||
them, and therefore difficult to debug. When reporting on a suspected
|
||||
issue **please** include as much of the below information as possible
|
||||
otherwise it will be difficult or impossible to diagnose. Also please
|
||||
read the documentation as it provides details on many previously
|
||||
encountered questions/issues.
|
||||
|
||||
**Please make sure you are using the [latest
|
||||
release](https://github.com/trapexit/mergerfs/releases) or have tried
|
||||
it in comparison. Old versions, which are often included in distros
|
||||
like Debian and Ubuntu, are not ever going to be updated and the issue
|
||||
you are encountering may have been addressed already.**
|
||||
|
||||
**For commercial support or feature requests please [contact me
|
||||
directly.](mailto:support@spawn.link)**
|
||||
|
||||
### Information to include in bug reports
|
||||
|
||||
* [Information about the broader problem along with any attempted
|
||||
solutions.](https://xyproblem.info)
|
||||
* Solution already ruled out and why.
|
||||
* Version of mergerfs: `mergerfs --version`
|
||||
* mergerfs settings / arguments: from fstab, systemd unit, command
|
||||
line, OMV plugin, etc.
|
||||
* Version of the OS: `uname -a` and `lsb_release -a`
|
||||
* List of branches, their filesystem types, sizes (before and after issue): `df -h`
|
||||
* **All** information about the relevant paths and files: permissions, ownership, etc.
|
||||
* **All** information about the client app making the requests: version, uid/gid
|
||||
* Runtime environment:
|
||||
* Is mergerfs running within a container?
|
||||
* Are the client apps using mergerfs running in a container?
|
||||
* A `strace` of the app having problems:
|
||||
* `strace -fvTtt -s 256 -o /tmp/app.strace.txt <cmd>`
|
||||
* A `strace` of mergerfs while the program is trying to do whatever it is failing to do:
|
||||
* `strace -fvTtt -s 256 -p <mergerfsPID> -o /tmp/mergerfs.strace.txt`
|
||||
* **Precise** directions on replicating the issue. Do not leave **anything** out.
|
||||
* Try to recreate the problem in the simplest way using standard programs: `ln`, `mv`, `cp`, `ls`, `dd`, etc.
|
||||
|
||||
### Contact / Issue submission
|
||||
|
||||
* github.com: [https://github.com/trapexit/mergerfs/issues](https://github.com/trapexit/mergerfs/issues)
|
||||
* discord: [https://discord.gg/MpAr69V](https://discord.gg/MpAr69V)
|
||||
* reddit: [https://www.reddit.com/r/mergerfs](https://www.reddit.com/r/mergerfs)
|
||||
@@ -0,0 +1,33 @@
|
||||
# Terminology
|
||||
|
||||
* `disk`, `drive`, `disk drive`: A [physical data storage
|
||||
device](https://en.wikipedia.org/wiki/Disk_storage). Such as a hard
|
||||
drive or solid-state drive. Usually requires the use of a filesystem
|
||||
to be useful. mergerfs does not deal with disks.
|
||||
* `filesystem`: Lowlevel software which provides a way to organize data
|
||||
and provide access to said data in a standard way. A filesystem is a
|
||||
higher level abstraction that may or may not be stored on a
|
||||
disk. mergerfs deals exclusively with filesystems.
|
||||
* `path`: A location within a filesystem. mergerfs can work with any
|
||||
path within a filesystem and not simply the root.
|
||||
* `branch`: A base path used in a mergerfs pool. mergerfs can
|
||||
accommodate multiple paths pointing to the same filesystem.
|
||||
* `pool`: The mergerfs mount. The union of the branches. The instance
|
||||
of mergerfs. You can mount multiple mergerfs pools. Even with the
|
||||
same branches.
|
||||
* `relative path`: The path in the pool relative to the branch and
|
||||
mount. `foo/bar` is the relative path of mergerfs mount
|
||||
`/mnt/mergerfs/foo/bar`.
|
||||
* `function`: A filesystem call such as `open`, `unlink`, `create`,
|
||||
`getattr`, `rmdir`, etc. The requests your software make to the
|
||||
filesystem.
|
||||
* `category`: A collection of functions based on basic behavior
|
||||
(action, create, search).
|
||||
* `policy`: The algorithm used to select a file or files when
|
||||
performing a function.
|
||||
* `path preservation`: Aspect of some policies which includes checking
|
||||
the path for which a file would be created.
|
||||
* `out-of-band`:
|
||||
[out-of-band](https://en.wikipedia.org/wiki/Out-of-band) in our
|
||||
context refers to interacting with the underlying filesystem
|
||||
directly instead of going through mergerfs (or NFS or Samba).
|
||||
@@ -0,0 +1,47 @@
|
||||
# Tips and Notes
|
||||
|
||||
* The documentation is explicit, literal, and reasonably thorough. If
|
||||
a suspected feature is not mentioned it does not exist. Do not read
|
||||
into the wording. What is described is how it functions. If you feel
|
||||
like something is not explained sufficiently please [file a
|
||||
ticket.](https://github.com/trapexit/mergerfs/issues)
|
||||
* If a `libfuse` argument is not listed it probably shouldn't be used
|
||||
and are unsupported.
|
||||
* Ensure you're using the latest version. Especially before submitting
|
||||
bug reports.
|
||||
* Run mergerfs as `root`. mergerfs is designed and intended to be run
|
||||
as `root` and may exhibit incorrect behavior if run otherwise.
|
||||
* If you do not see some directories and files you expect, policies
|
||||
seem to skip branches, you get strange permission errors, etc. be
|
||||
sure the underlying filesystems' permissions are all the same. Use
|
||||
`mergerfs.fsck` to audit the filesystem for out of sync permissions.
|
||||
* If you still have permission issues be sure you are using POSIX ACL
|
||||
compliant filesystems. mergerfs doesn't generally make exceptions
|
||||
for FAT, NTFS, or other non-POSIX filesystem.
|
||||
* Unless using Linux v6.6 or above do **not** use `cache.files=off` if
|
||||
you expect applications (such as rtorrent) to use
|
||||
[mmap](http://linux.die.net/man/2/mmap). Enabling `dropcacheonclose`
|
||||
is recommended when `cache.files=auto-full`.
|
||||
* [Kodi](http://kodi.tv), [Plex](http://plex.tv),
|
||||
[Subsonic](http://subsonic.org), etc. can use directory
|
||||
[mtime](http://linux.die.net/man/2/stat) to more efficiently
|
||||
determine whether to scan for new content rather than simply
|
||||
performing a full scan. If using the default `getattr` policy of
|
||||
`ff` it's possible those programs will miss an update on account of
|
||||
it returning the first directory found's `stat` info and it is a
|
||||
later directory on another mount which had the `mtime` recently
|
||||
updated. To fix this you will want to set
|
||||
`func.getattr=newest`. Remember though that this is just `stat`. If
|
||||
the file is later `open`'ed or `unlink`'ed and the policy is
|
||||
different for those then a completely different file or directory
|
||||
could be acted on.
|
||||
* Some policies mixed with some functions may result in strange
|
||||
behaviors. Not that some of these behaviors and race conditions
|
||||
couldn't happen outside mergerfs but that they are far more
|
||||
likely to occur on account of the attempt to merge multiple sources
|
||||
of data which could be out of sync due to the different policies.
|
||||
* For consistency it's generally best to set `category` wide policies
|
||||
rather than individual `func`'s. This will help limit the
|
||||
confusion of tools such as
|
||||
[rsync](http://linux.die.net/man/1/rsync). However, the flexibility
|
||||
is there if needed.
|
||||
@@ -0,0 +1,117 @@
|
||||
# Tooling
|
||||
|
||||
## preload.so
|
||||
|
||||
EXPERIMENTAL
|
||||
|
||||
For some time there has been work to enable passthrough IO in
|
||||
FUSE. Passthrough IO would allow for near native performance with
|
||||
regards to reads and writes (at the expense of certain mergerfs
|
||||
features.) In Linux v6.9 that feature made its way into the kernel
|
||||
however in a somewhat limited form which is incompatible with aspects
|
||||
of how mergerfs currently functions. While work will continue to
|
||||
support passthrough IO in mergerfs this library was created to offer
|
||||
similar functionality in a more limited way.
|
||||
|
||||
`/usr/lib/mergerfs/preload.so`
|
||||
|
||||
This [preloadable
|
||||
library](https://man7.org/linux/man-pages/man8/ld.so.8.html#ENVIRONMENT)
|
||||
overrides the creation and opening of files in order to simulate
|
||||
passthrough file IO. It catches the open/creat/fopen calls, has
|
||||
mergerfs do the call, queries mergerfs for the branch the file exists
|
||||
on, reopens the file on the underlying filesystem and returns that
|
||||
instead. Meaning that you will get native read/write performance
|
||||
because mergerfs is no longer part of the workflow. Keep in mind that
|
||||
this also means certain mergerfs features that work by interrupting
|
||||
the read/write workflow, such as `moveonenospc`, will no longer work.
|
||||
|
||||
Also, understand that this will only work on dynamically linked
|
||||
software. Anything statically compiled will not work. Many GoLang and
|
||||
Rust apps are statically compiled.
|
||||
|
||||
The library will not interfere with non-mergerfs filesystems. The
|
||||
library is written to always fallback to returning the mergerfs opened
|
||||
file on error.
|
||||
|
||||
While the library was written to account for a number of edgecases
|
||||
there could be some yet accounted for so please report any oddities.
|
||||
|
||||
Thank you to
|
||||
[nohajc](https://github.com/nohajc/mergerfs-io-passthrough) for
|
||||
prototyping the idea.
|
||||
|
||||
### casual usage
|
||||
|
||||
```sh
|
||||
LD_PRELOAD=/usr/lib/mergerfs/preload.so touch /mnt/mergerfs/filename
|
||||
```
|
||||
|
||||
Or run `export LD_PRELOAD=/usr/lib/mergerfs/preload.so` in your shell
|
||||
or place it in your shell config file to have it be picked up by all
|
||||
software ran from your shell.
|
||||
|
||||
|
||||
### Docker and Podman usage
|
||||
|
||||
Assume `/mnt/fs0` and `/mnt/fs1` are pooled with mergerfs at `/media`.
|
||||
|
||||
All mergerfs branch paths _must_ be bind mounted into the container at
|
||||
the same path as found on the host so the preload library can see
|
||||
them.
|
||||
|
||||
**NOTE:** Since a container can have its own OS setup there is no
|
||||
guarentee that `preload.so` from the host install will be compatible
|
||||
with the loader found in the container. If that is true it simply
|
||||
won't work and shouldn't cause any issues.
|
||||
|
||||
|
||||
```sh
|
||||
docker run \
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
|
||||
-v /media:/media \
|
||||
-v /mnt:/mnt \
|
||||
ubuntu:latest \
|
||||
bash
|
||||
```
|
||||
|
||||
or more explicitly
|
||||
|
||||
```sh
|
||||
docker run \
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
|
||||
-v /media:/media \
|
||||
-v /mnt/fs0:/mnt/fs0 \
|
||||
-v /mnt/fs1:/mnt/fs1 \
|
||||
ubuntu:latest \
|
||||
bash
|
||||
```
|
||||
|
||||
|
||||
### systemd unit
|
||||
|
||||
Use the `Environment` option to set the LD_PRELOAD variable.
|
||||
|
||||
* [https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines)
|
||||
* [https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service](https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service)
|
||||
|
||||
```
|
||||
[Service]
|
||||
Environment=LD_PRELOAD=/usr/lib/mergerfs/preload.so
|
||||
```
|
||||
|
||||
## Misc
|
||||
|
||||
- https://github.com/trapexit/mergerfs-tools
|
||||
- mergerfs.ctl: A tool to make it easier to query and configure mergerfs at runtime
|
||||
- mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
|
||||
- mergerfs.dedup: Will help identify and optionally remove duplicate files
|
||||
- mergerfs.dup: Ensure there are at least N copies of a file across the pool
|
||||
- mergerfs.balance: Rebalance files across filesystems by moving them from the most filled to the least filled
|
||||
- mergerfs.consolidate: move files within a single mergerfs directory to the filesystem with most free space
|
||||
- https://github.com/trapexit/scorch
|
||||
- scorch: A tool to help discover silent corruption of files and keep track of files
|
||||
- https://github.com/trapexit/bbf
|
||||
- bbf (bad block finder): a tool to scan for and 'fix' hard drive bad blocks and find the files using those blocks
|
||||
@@ -0,0 +1,119 @@
|
||||
# Usage Patterns
|
||||
|
||||
## tiered cache
|
||||
|
||||
Some storage technologies support what is called "tiered" caching. The
|
||||
placing of smaller, faster storage as a transparent cache to larger,
|
||||
slower storage. NVMe, SSD, Optane in front of traditional HDDs for
|
||||
instance.
|
||||
|
||||
mergerfs does not natively support any sort of tiered caching. Most
|
||||
users have no use for such a feature and its inclusion would
|
||||
complicate the code as it exists today. However, there are a few
|
||||
situations where a cache filesystem could help with a typical mergerfs
|
||||
setup.
|
||||
|
||||
1. Fast network, slow filesystems, many readers: You've a 10+Gbps
|
||||
network with many readers and your regular filesystems can't keep
|
||||
up.
|
||||
2. Fast network, slow filesystems, small'ish bursty writes: You have
|
||||
a 10+Gbps network and wish to transfer amounts of data less than
|
||||
your cache filesystem but wish to do so quickly and the time
|
||||
between bursts is long enough to migrate data.
|
||||
|
||||
With #1 it's arguable if you should be using mergerfs at all. A RAID
|
||||
level that can aggregate performance or using higher performance
|
||||
storage would probably be the better solution. If you're going to use
|
||||
mergerfs there are other tactics that may help: spreading the data
|
||||
across filesystems (see the mergerfs.dup tool) and setting
|
||||
`func.open=rand`, using `symlinkify`, or using dm-cache or a similar
|
||||
technology to add tiered cache to the underlying device itself.
|
||||
|
||||
With #2 one could use a block cache solution as available via LVM and
|
||||
dm-cache but there is another solution which requires only mergerfs, a
|
||||
script to move files around, and a cron job to run said script.
|
||||
|
||||
* Create two mergerfs pools. One which includes just the **slow**
|
||||
branches and one which has both the **fast** branches
|
||||
(SSD,NVME,etc.) and **slow** branches. The **base** pool and the
|
||||
**cache** pool.
|
||||
* The **cache** pool should have the cache branches listed first in
|
||||
the branch list in order to to make it easier to prioritize them.
|
||||
* The best `create` policies to use for the **cache** pool would
|
||||
probably be `ff`, `lus`, or `lfs`. The latter two under the
|
||||
assumption that the cache filesystem(s) are far smaller than the
|
||||
backing filesystems.
|
||||
* You can also set the **slow** filesystems mode to `NC` which would
|
||||
give you the ability to use other `create` policies though that'd
|
||||
mean if the cache filesystems fill you'd get "out of space"
|
||||
errors. This however may be good as it would indicate the script
|
||||
moving files around is not configured properly.
|
||||
* Set your programs to use the **cache** pool.
|
||||
* Configure the **base** pool with the `create` policy you would like
|
||||
to lay out files as you like.
|
||||
* Save one of the below scripts or create your own. The script's
|
||||
responsibility is to move files from the **cache** branches (not
|
||||
pool) to the **base** pool.
|
||||
* Use `cron` (as root) to schedule the command at whatever frequency
|
||||
is appropriate for your workflow.
|
||||
|
||||
|
||||
### time based expiring
|
||||
|
||||
Move files from cache filesystem to base pool which have an access
|
||||
time older than the supplied number of days. Replace `-atime` with
|
||||
`-amin` in the script if you want minutes rather than days.
|
||||
|
||||
**NOTE:** The arguments to these scripts include the cache
|
||||
**filesystem** itself. Not the pool with the cache filesystem. You
|
||||
could have data loss if the source is the cache pool.
|
||||
|
||||
[mergerfs.time-based-mover](https://github.com/trapexit/mergerfs/blob/latest-release/tools/mergerfs.time-based-mover?raw=1)
|
||||
|
||||
Download:
|
||||
```
|
||||
curl -o /usr/local/bin/mergerfs.time-based-mover https://raw.githubusercontent.com/trapexit/mergerfs/refs/heads/latest-release/tools/mergerfs.time-based-mover
|
||||
```
|
||||
|
||||
crontab entry:
|
||||
```
|
||||
# m h dom mon dow command
|
||||
0 * * * * /usr/local/bin/mergerfs.time-based-mover /mnt/ssd/cache00 /mnt/base-pool 1
|
||||
```
|
||||
|
||||
If you have more than one cache filesystem then simply add a cron
|
||||
entry for each.
|
||||
|
||||
If you want to only move files from a subdirectory then use the
|
||||
subdirectories. `/mnt/ssd/cache00/foo` and `/mnt/base-pool/foo`
|
||||
respectively.
|
||||
|
||||
|
||||
### percentage full expiring
|
||||
|
||||
While the cache filesystem's percentage full is above the provided
|
||||
value move the oldest file from the cache filesystem to the base pool.
|
||||
|
||||
**NOTE:** The arguments to these scripts include the cache
|
||||
**filesystem** itself. Not the pool with the cache filesystem. You
|
||||
could have data loss if the source is the cache pool.
|
||||
|
||||
[mergerfs.percent-full-mover](https://github.com/trapexit/mergerfs/blob/latest-release/tools/mergerfs.percent-full-mover?raw=1)
|
||||
|
||||
Download:
|
||||
```
|
||||
curl -o /usr/local/bin/mergerfs.percent-full-mover https://raw.githubusercontent.com/trapexit/mergerfs/refs/heads/latest-release/tools/mergerfs.percent-full-mover
|
||||
```
|
||||
|
||||
crontab entry:
|
||||
```
|
||||
# m h dom mon dow command
|
||||
0 * * * * /usr/local/bin/mergerfs.percent-full-mover /mnt/ssd/cache00 /mnt/base-pool 80
|
||||
```
|
||||
|
||||
If you have more than one cache filesystem then simply add a cron
|
||||
entry for each.
|
||||
|
||||
If you want to only move files from a subdirectory then use the
|
||||
subdirectories. `/mnt/ssd/cache00/foo` and `/mnt/base-pool/foo`
|
||||
respectively.
|
||||
@@ -0,0 +1,107 @@
|
||||
site_name: mergerfs
|
||||
site_description: mergerfs - a featureful union filesystem
|
||||
site_url: https://trapexit.github.io/mergerfs/
|
||||
repo_name: mergerfs
|
||||
repo_url: https://github.com/trapexit/mergerfs
|
||||
edit_uri: edit/master/mkdocs/docs/
|
||||
docs_dir: docs
|
||||
theme:
|
||||
name: material
|
||||
logo: logo.jpeg
|
||||
features:
|
||||
- content.action.edit
|
||||
- content.action.view
|
||||
- content.code.copy
|
||||
- content.code.select
|
||||
- navigation.footer
|
||||
- navigation.instant
|
||||
- navigation.instant.prefetch
|
||||
- navigation.path
|
||||
- navigation.top
|
||||
- navigation.tracking
|
||||
- optimize
|
||||
- search.share
|
||||
- search.suggest
|
||||
- toc.follow
|
||||
palette:
|
||||
- media: "(prefers-color-scheme)"
|
||||
toggle:
|
||||
icon: material/brightness-auto
|
||||
name: Switch to light mode
|
||||
- media: "(prefers-color-scheme: light)"
|
||||
scheme: default
|
||||
toggle:
|
||||
icon: material/brightness-7
|
||||
name: Switch to dark mode
|
||||
- media: "(prefers-color-scheme: dark)"
|
||||
scheme: slate
|
||||
toggle:
|
||||
icon: material/brightness-4
|
||||
name: Switch to system preference
|
||||
markdown_extensions:
|
||||
- footnotes
|
||||
- pymdownx.highlight:
|
||||
auto_title: false
|
||||
linenums_style: pymdownx-inline
|
||||
anchor_linenums: true
|
||||
line_spans: __span
|
||||
pygments_lang_class: true
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.snippets
|
||||
- pymdownx.superfences
|
||||
nav:
|
||||
- Home: index.md
|
||||
- QuickStart: quickstart.md
|
||||
- Installation:
|
||||
- setup/installation.md
|
||||
- setup/upgrade.md
|
||||
- setup/build.md
|
||||
- terminology.md
|
||||
- intro_to_filesystems.md
|
||||
- Config:
|
||||
- config/options.md
|
||||
- config/deprecated_options.md
|
||||
- config/branches.md
|
||||
- config/functions_categories_policies.md
|
||||
- config/func_readdir.md
|
||||
- config/rename_and_link.md
|
||||
- config/cache.md
|
||||
- config/readahead.md
|
||||
- config/inodecalc.md
|
||||
- config/threads.md
|
||||
- config/pin-threads.md
|
||||
- config/link_cow.md
|
||||
- config/fuse_msg_size.md
|
||||
- config/follow-symlinks.md
|
||||
- config/link-exdev.md
|
||||
- config/rename-exdev.md
|
||||
- config/symlinkify.md
|
||||
- config/nullrw.md
|
||||
- config/xattr.md
|
||||
- config/nfsopenhack.md
|
||||
- config/statfs.md
|
||||
- config/flush-on-close.md
|
||||
- config/export-support.md
|
||||
- error_handling_and_logging.md
|
||||
- runtime_interfaces.md
|
||||
- remote_filesystems.md
|
||||
- tips_notes.md
|
||||
- known_issues_bugs.md
|
||||
- project_comparisons.md
|
||||
- performance.md
|
||||
- benchmarking.md
|
||||
- tooling.md
|
||||
- usage_patterns.md
|
||||
- FAQ:
|
||||
- faq/why_isnt_it_working.md
|
||||
- faq/reliability_and_scalability.md
|
||||
- faq/usage_and_functionality.md
|
||||
- faq/configuration_and_policies.md
|
||||
- faq/compatibility_and_integration.md
|
||||
- faq/recommendations_and_warnings.md
|
||||
- faq/technical_behavior_and_limitations.md
|
||||
- faq/limit_drive_spinup.md
|
||||
- related_projects.md
|
||||
- media_and_publicity.md
|
||||
- support.md
|
||||
- sponsorship_and_donations.md
|
||||
+7
-1
@@ -58,6 +58,8 @@ namespace l
|
||||
IFERT("branches-mount-timeout");
|
||||
IFERT("cache.symlinks");
|
||||
IFERT("cache.writeback");
|
||||
IFERT("direct-io-allow-mmap");
|
||||
IFERT("export-support");
|
||||
IFERT("fsname");
|
||||
IFERT("fuse_msg_size");
|
||||
IFERT("mount");
|
||||
@@ -93,12 +95,14 @@ Config::Config()
|
||||
cache_symlinks(false),
|
||||
category(func),
|
||||
direct_io(false),
|
||||
direct_io_allow_mmap(true),
|
||||
dropcacheonclose(false),
|
||||
export_support(true),
|
||||
flushonclose(FlushOnClose::ENUM::OPENED_FOR_WRITE),
|
||||
follow_symlinks(FollowSymlinks::ENUM::NEVER),
|
||||
fsname(),
|
||||
func(),
|
||||
fuse_msg_size(FUSE_MAX_MAX_PAGES),
|
||||
fuse_msg_size("1M"),
|
||||
ignorepponrename(false),
|
||||
inodecalc("hybrid-hash"),
|
||||
lazy_umount_mountpoint(false),
|
||||
@@ -148,7 +152,9 @@ Config::Config()
|
||||
_map["category.create"] = &category.create;
|
||||
_map["category.search"] = &category.search;
|
||||
_map["direct_io"] = &direct_io;
|
||||
_map["direct-io-allow-mmap"] = &direct_io_allow_mmap;
|
||||
_map["dropcacheonclose"] = &dropcacheonclose;
|
||||
_map["export-support"] = &export_support;
|
||||
_map["flush-on-close"] = &flushonclose;
|
||||
_map["follow-symlinks"] = &follow_symlinks;
|
||||
_map["fsname"] = &fsname;
|
||||
|
||||
+5
-2
@@ -21,12 +21,13 @@
|
||||
#include "config_cachefiles.hpp"
|
||||
#include "config_flushonclose.hpp"
|
||||
#include "config_follow_symlinks.hpp"
|
||||
#include "config_pid.hpp"
|
||||
#include "config_inodecalc.hpp"
|
||||
#include "config_link_exdev.hpp"
|
||||
#include "config_log_metrics.hpp"
|
||||
#include "config_moveonenospc.hpp"
|
||||
#include "config_nfsopenhack.hpp"
|
||||
#include "config_pagesize.hpp"
|
||||
#include "config_pid.hpp"
|
||||
#include "config_rename_exdev.hpp"
|
||||
#include "config_set.hpp"
|
||||
#include "config_statfs.hpp"
|
||||
@@ -117,12 +118,14 @@ public:
|
||||
ConfigBOOL cache_symlinks;
|
||||
Categories category;
|
||||
ConfigBOOL direct_io;
|
||||
ConfigBOOL direct_io_allow_mmap;
|
||||
ConfigBOOL dropcacheonclose;
|
||||
ConfigBOOL export_support;
|
||||
FlushOnClose flushonclose;
|
||||
FollowSymlinks follow_symlinks;
|
||||
ConfigSTR fsname;
|
||||
Funcs func;
|
||||
ConfigUINT64 fuse_msg_size;
|
||||
ConfigPageSize fuse_msg_size;
|
||||
ConfigBOOL ignorepponrename;
|
||||
InodeCalc inodecalc;
|
||||
ConfigBOOL kernel_cache;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2025, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config_pagesize.hpp"
|
||||
|
||||
#include "from_string.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
ConfigPageSize::ConfigPageSize(const uint64_t v_)
|
||||
: _v(v_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ConfigPageSize::ConfigPageSize(const std::string &s_)
|
||||
{
|
||||
from_string(s_);
|
||||
}
|
||||
|
||||
std::string
|
||||
ConfigPageSize::to_string(void) const
|
||||
{
|
||||
return std::to_string(_v);
|
||||
}
|
||||
|
||||
int
|
||||
ConfigPageSize::from_string(const std::string &s_)
|
||||
{
|
||||
uint64_t v;
|
||||
uint64_t pagesize;
|
||||
|
||||
pagesize = sysconf(_SC_PAGESIZE);
|
||||
|
||||
str::from(s_,&v);
|
||||
if(!std::isalpha(s_.back()))
|
||||
v *= pagesize;
|
||||
|
||||
_v = ((v + pagesize - 1) / pagesize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2025, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "tofrom_string.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class ConfigPageSize : public ToFromString
|
||||
{
|
||||
private:
|
||||
uint64_t _v;
|
||||
|
||||
public:
|
||||
ConfigPageSize(const uint64_t);
|
||||
ConfigPageSize(const std::string &);
|
||||
|
||||
public:
|
||||
std::string to_string(void) const final;
|
||||
int from_string(const std::string &) final;
|
||||
|
||||
public:
|
||||
ConfigPageSize&
|
||||
operator=(const uint64_t v_)
|
||||
{
|
||||
_v = v_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator const uint64_t() const
|
||||
{
|
||||
return _v;
|
||||
}
|
||||
};
|
||||
+7
-6
@@ -1,4 +1,4 @@
|
||||
// Formatting library for C++ - dynamic format arguments
|
||||
// Formatting library for C++ - dynamic argument lists
|
||||
//
|
||||
// Copyright (c) 2012 - present, Victor Zverovich
|
||||
// All rights reserved.
|
||||
@@ -22,8 +22,9 @@ template <typename T> struct is_reference_wrapper : std::false_type {};
|
||||
template <typename T>
|
||||
struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};
|
||||
|
||||
template <typename T> const T& unwrap(const T& v) { return v; }
|
||||
template <typename T> const T& unwrap(const std::reference_wrapper<T>& v) {
|
||||
template <typename T> auto unwrap(const T& v) -> const T& { return v; }
|
||||
template <typename T>
|
||||
auto unwrap(const std::reference_wrapper<T>& v) -> const T& {
|
||||
return static_cast<const T&>(v);
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ class dynamic_arg_list {
|
||||
std::unique_ptr<node<>> head_;
|
||||
|
||||
public:
|
||||
template <typename T, typename Arg> const T& push(const Arg& arg) {
|
||||
template <typename T, typename Arg> auto push(const Arg& arg) -> const T& {
|
||||
auto new_node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
|
||||
auto& value = new_node->value;
|
||||
new_node->next = std::move(head_);
|
||||
@@ -110,14 +111,14 @@ class dynamic_format_arg_store
|
||||
|
||||
friend class basic_format_args<Context>;
|
||||
|
||||
unsigned long long get_types() const {
|
||||
auto get_types() const -> unsigned long long {
|
||||
return detail::is_unpacked_bit | data_.size() |
|
||||
(named_info_.empty()
|
||||
? 0ULL
|
||||
: static_cast<unsigned long long>(detail::has_named_args_bit));
|
||||
}
|
||||
|
||||
const basic_format_arg<Context>* data() const {
|
||||
auto data() const -> const basic_format_arg<Context>* {
|
||||
return named_info_.empty() ? data_.data() : data_.data() + 1;
|
||||
}
|
||||
|
||||
|
||||
+230
-257
@@ -18,7 +18,7 @@
|
||||
#include <ostream>
|
||||
#include <type_traits>
|
||||
|
||||
#include "format.h"
|
||||
#include "ostream.h" // formatbuf
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
@@ -72,7 +72,8 @@ template <typename To, typename From,
|
||||
FMT_ENABLE_IF(!std::is_same<From, To>::value &&
|
||||
std::numeric_limits<From>::is_signed ==
|
||||
std::numeric_limits<To>::is_signed)>
|
||||
FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
|
||||
FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
|
||||
-> To {
|
||||
ec = 0;
|
||||
using F = std::numeric_limits<From>;
|
||||
using T = std::numeric_limits<To>;
|
||||
@@ -101,7 +102,8 @@ template <typename To, typename From,
|
||||
FMT_ENABLE_IF(!std::is_same<From, To>::value &&
|
||||
std::numeric_limits<From>::is_signed !=
|
||||
std::numeric_limits<To>::is_signed)>
|
||||
FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
|
||||
FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
|
||||
-> To {
|
||||
ec = 0;
|
||||
using F = std::numeric_limits<From>;
|
||||
using T = std::numeric_limits<To>;
|
||||
@@ -133,7 +135,8 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
|
||||
|
||||
template <typename To, typename From,
|
||||
FMT_ENABLE_IF(std::is_same<From, To>::value)>
|
||||
FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
|
||||
FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
|
||||
-> To {
|
||||
ec = 0;
|
||||
return from;
|
||||
} // function
|
||||
@@ -154,7 +157,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
|
||||
// clang-format on
|
||||
template <typename To, typename From,
|
||||
FMT_ENABLE_IF(!std::is_same<From, To>::value)>
|
||||
FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
|
||||
FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To {
|
||||
ec = 0;
|
||||
using T = std::numeric_limits<To>;
|
||||
static_assert(std::is_floating_point<From>::value, "From must be floating");
|
||||
@@ -176,7 +179,7 @@ FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
|
||||
|
||||
template <typename To, typename From,
|
||||
FMT_ENABLE_IF(std::is_same<From, To>::value)>
|
||||
FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
|
||||
FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To {
|
||||
ec = 0;
|
||||
static_assert(std::is_floating_point<From>::value, "From must be floating");
|
||||
return from;
|
||||
@@ -188,8 +191,8 @@ FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
|
||||
template <typename To, typename FromRep, typename FromPeriod,
|
||||
FMT_ENABLE_IF(std::is_integral<FromRep>::value),
|
||||
FMT_ENABLE_IF(std::is_integral<typename To::rep>::value)>
|
||||
To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
|
||||
int& ec) {
|
||||
auto safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
|
||||
int& ec) -> To {
|
||||
using From = std::chrono::duration<FromRep, FromPeriod>;
|
||||
ec = 0;
|
||||
// the basic idea is that we need to convert from count() in the from type
|
||||
@@ -240,8 +243,8 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
|
||||
template <typename To, typename FromRep, typename FromPeriod,
|
||||
FMT_ENABLE_IF(std::is_floating_point<FromRep>::value),
|
||||
FMT_ENABLE_IF(std::is_floating_point<typename To::rep>::value)>
|
||||
To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
|
||||
int& ec) {
|
||||
auto safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
|
||||
int& ec) -> To {
|
||||
using From = std::chrono::duration<FromRep, FromPeriod>;
|
||||
ec = 0;
|
||||
if (std::isnan(from.count())) {
|
||||
@@ -321,12 +324,12 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
|
||||
|
||||
namespace detail {
|
||||
template <typename T = void> struct null {};
|
||||
inline null<> localtime_r FMT_NOMACRO(...) { return null<>(); }
|
||||
inline null<> localtime_s(...) { return null<>(); }
|
||||
inline null<> gmtime_r(...) { return null<>(); }
|
||||
inline null<> gmtime_s(...) { return null<>(); }
|
||||
inline auto localtime_r FMT_NOMACRO(...) -> null<> { return null<>(); }
|
||||
inline auto localtime_s(...) -> null<> { return null<>(); }
|
||||
inline auto gmtime_r(...) -> null<> { return null<>(); }
|
||||
inline auto gmtime_s(...) -> null<> { return null<>(); }
|
||||
|
||||
inline const std::locale& get_classic_locale() {
|
||||
inline auto get_classic_locale() -> const std::locale& {
|
||||
static const auto& locale = std::locale::classic();
|
||||
return locale;
|
||||
}
|
||||
@@ -336,8 +339,6 @@ template <typename CodeUnit> struct codecvt_result {
|
||||
CodeUnit buf[max_size];
|
||||
CodeUnit* end;
|
||||
};
|
||||
template <typename CodeUnit>
|
||||
constexpr const size_t codecvt_result<CodeUnit>::max_size;
|
||||
|
||||
template <typename CodeUnit>
|
||||
void write_codecvt(codecvt_result<CodeUnit>& out, string_view in_buf,
|
||||
@@ -377,8 +378,8 @@ auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale& loc)
|
||||
unit_t unit;
|
||||
write_codecvt(unit, in, loc);
|
||||
// In UTF-8 is used one to four one-byte code units.
|
||||
unicode_to_utf8<code_unit, basic_memory_buffer<char, unit_t::max_size * 4>>
|
||||
u;
|
||||
auto u =
|
||||
to_utf8<code_unit, basic_memory_buffer<char, unit_t::max_size * 4>>();
|
||||
if (!u.convert({unit.buf, to_unsigned(unit.end - unit.buf)}))
|
||||
FMT_THROW(format_error("failed to format time"));
|
||||
return copy_str<char>(u.c_str(), u.c_str() + u.size(), out);
|
||||
@@ -408,8 +409,7 @@ inline void do_write(buffer<Char>& buf, const std::tm& time,
|
||||
auto&& format_buf = formatbuf<std::basic_streambuf<Char>>(buf);
|
||||
auto&& os = std::basic_ostream<Char>(&format_buf);
|
||||
os.imbue(loc);
|
||||
using iterator = std::ostreambuf_iterator<Char>;
|
||||
const auto& facet = std::use_facet<std::time_put<Char, iterator>>(loc);
|
||||
const auto& facet = std::use_facet<std::time_put<Char>>(loc);
|
||||
auto end = facet.put(os, os, Char(' '), &time, format, modifier);
|
||||
if (end.failed()) FMT_THROW(format_error("failed to format time"));
|
||||
}
|
||||
@@ -432,6 +432,51 @@ auto write(OutputIt out, const std::tm& time, const std::locale& loc,
|
||||
return write_encoded_tm_str(out, string_view(buf.data(), buf.size()), loc);
|
||||
}
|
||||
|
||||
template <typename Rep1, typename Rep2>
|
||||
struct is_same_arithmetic_type
|
||||
: public std::integral_constant<bool,
|
||||
(std::is_integral<Rep1>::value &&
|
||||
std::is_integral<Rep2>::value) ||
|
||||
(std::is_floating_point<Rep1>::value &&
|
||||
std::is_floating_point<Rep2>::value)> {
|
||||
};
|
||||
|
||||
template <
|
||||
typename To, typename FromRep, typename FromPeriod,
|
||||
FMT_ENABLE_IF(is_same_arithmetic_type<FromRep, typename To::rep>::value)>
|
||||
auto fmt_duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
|
||||
#if FMT_SAFE_DURATION_CAST
|
||||
// Throwing version of safe_duration_cast is only available for
|
||||
// integer to integer or float to float casts.
|
||||
int ec;
|
||||
To to = safe_duration_cast::safe_duration_cast<To>(from, ec);
|
||||
if (ec) FMT_THROW(format_error("cannot format duration"));
|
||||
return to;
|
||||
#else
|
||||
// Standard duration cast, may overflow.
|
||||
return std::chrono::duration_cast<To>(from);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <
|
||||
typename To, typename FromRep, typename FromPeriod,
|
||||
FMT_ENABLE_IF(!is_same_arithmetic_type<FromRep, typename To::rep>::value)>
|
||||
auto fmt_duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
|
||||
// Mixed integer <-> float cast is not supported by safe_duration_cast.
|
||||
return std::chrono::duration_cast<To>(from);
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
auto to_time_t(
|
||||
std::chrono::time_point<std::chrono::system_clock, Duration> time_point)
|
||||
-> std::time_t {
|
||||
// Cannot use std::chrono::system_clock::to_time_t since this would first
|
||||
// require a cast to std::chrono::system_clock::time_point, which could
|
||||
// overflow.
|
||||
return fmt_duration_cast<std::chrono::duration<std::time_t>>(
|
||||
time_point.time_since_epoch())
|
||||
.count();
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
FMT_BEGIN_EXPORT
|
||||
@@ -441,29 +486,29 @@ FMT_BEGIN_EXPORT
|
||||
expressed in local time. Unlike ``std::localtime``, this function is
|
||||
thread-safe on most platforms.
|
||||
*/
|
||||
inline std::tm localtime(std::time_t time) {
|
||||
inline auto localtime(std::time_t time) -> std::tm {
|
||||
struct dispatcher {
|
||||
std::time_t time_;
|
||||
std::tm tm_;
|
||||
|
||||
dispatcher(std::time_t t) : time_(t) {}
|
||||
|
||||
bool run() {
|
||||
auto run() -> bool {
|
||||
using namespace fmt::detail;
|
||||
return handle(localtime_r(&time_, &tm_));
|
||||
}
|
||||
|
||||
bool handle(std::tm* tm) { return tm != nullptr; }
|
||||
auto handle(std::tm* tm) -> bool { return tm != nullptr; }
|
||||
|
||||
bool handle(detail::null<>) {
|
||||
auto handle(detail::null<>) -> bool {
|
||||
using namespace fmt::detail;
|
||||
return fallback(localtime_s(&tm_, &time_));
|
||||
}
|
||||
|
||||
bool fallback(int res) { return res == 0; }
|
||||
auto fallback(int res) -> bool { return res == 0; }
|
||||
|
||||
#if !FMT_MSC_VERSION
|
||||
bool fallback(detail::null<>) {
|
||||
auto fallback(detail::null<>) -> bool {
|
||||
using namespace fmt::detail;
|
||||
std::tm* tm = std::localtime(&time_);
|
||||
if (tm) tm_ = *tm;
|
||||
@@ -480,8 +525,8 @@ inline std::tm localtime(std::time_t time) {
|
||||
#if FMT_USE_LOCAL_TIME
|
||||
template <typename Duration>
|
||||
inline auto localtime(std::chrono::local_time<Duration> time) -> std::tm {
|
||||
return localtime(std::chrono::system_clock::to_time_t(
|
||||
std::chrono::current_zone()->to_sys(time)));
|
||||
return localtime(
|
||||
detail::to_time_t(std::chrono::current_zone()->to_sys(time)));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -490,90 +535,49 @@ inline auto localtime(std::chrono::local_time<Duration> time) -> std::tm {
|
||||
expressed in Coordinated Universal Time (UTC). Unlike ``std::gmtime``, this
|
||||
function is thread-safe on most platforms.
|
||||
*/
|
||||
inline std::tm gmtime(std::time_t time) {
|
||||
inline auto gmtime(std::time_t time) -> std::tm {
|
||||
struct dispatcher {
|
||||
std::time_t time_;
|
||||
std::tm tm_;
|
||||
|
||||
dispatcher(std::time_t t) : time_(t) {}
|
||||
|
||||
bool run() {
|
||||
auto run() -> bool {
|
||||
using namespace fmt::detail;
|
||||
return handle(gmtime_r(&time_, &tm_));
|
||||
}
|
||||
|
||||
bool handle(std::tm* tm) { return tm != nullptr; }
|
||||
auto handle(std::tm* tm) -> bool { return tm != nullptr; }
|
||||
|
||||
bool handle(detail::null<>) {
|
||||
auto handle(detail::null<>) -> bool {
|
||||
using namespace fmt::detail;
|
||||
return fallback(gmtime_s(&tm_, &time_));
|
||||
}
|
||||
|
||||
bool fallback(int res) { return res == 0; }
|
||||
auto fallback(int res) -> bool { return res == 0; }
|
||||
|
||||
#if !FMT_MSC_VERSION
|
||||
bool fallback(detail::null<>) {
|
||||
auto fallback(detail::null<>) -> bool {
|
||||
std::tm* tm = std::gmtime(&time_);
|
||||
if (tm) tm_ = *tm;
|
||||
return tm != nullptr;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
dispatcher gt(time);
|
||||
auto gt = dispatcher(time);
|
||||
// Too big time values may be unsupported.
|
||||
if (!gt.run()) FMT_THROW(format_error("time_t value out of range"));
|
||||
return gt.tm_;
|
||||
}
|
||||
|
||||
inline std::tm gmtime(
|
||||
std::chrono::time_point<std::chrono::system_clock> time_point) {
|
||||
return gmtime(std::chrono::system_clock::to_time_t(time_point));
|
||||
template <typename Duration>
|
||||
inline auto gmtime(
|
||||
std::chrono::time_point<std::chrono::system_clock, Duration> time_point)
|
||||
-> std::tm {
|
||||
return gmtime(detail::to_time_t(time_point));
|
||||
}
|
||||
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
|
||||
// DEPRECATED!
|
||||
template <typename Char>
|
||||
FMT_CONSTEXPR auto parse_align(const Char* begin, const Char* end,
|
||||
format_specs<Char>& specs) -> const Char* {
|
||||
FMT_ASSERT(begin != end, "");
|
||||
auto align = align::none;
|
||||
auto p = begin + code_point_length(begin);
|
||||
if (end - p <= 0) p = begin;
|
||||
for (;;) {
|
||||
switch (to_ascii(*p)) {
|
||||
case '<':
|
||||
align = align::left;
|
||||
break;
|
||||
case '>':
|
||||
align = align::right;
|
||||
break;
|
||||
case '^':
|
||||
align = align::center;
|
||||
break;
|
||||
}
|
||||
if (align != align::none) {
|
||||
if (p != begin) {
|
||||
auto c = *begin;
|
||||
if (c == '}') return begin;
|
||||
if (c == '{') {
|
||||
throw_format_error("invalid fill character '{'");
|
||||
return begin;
|
||||
}
|
||||
specs.fill = {begin, to_unsigned(p - begin)};
|
||||
begin = p + 1;
|
||||
} else {
|
||||
++begin;
|
||||
}
|
||||
break;
|
||||
} else if (p == begin) {
|
||||
break;
|
||||
}
|
||||
p = begin;
|
||||
}
|
||||
specs.align = align;
|
||||
return begin;
|
||||
}
|
||||
namespace detail {
|
||||
|
||||
// Writes two-digit numbers a, b and c separated by sep to buf.
|
||||
// The method by Pavel Novikov based on
|
||||
@@ -609,7 +613,8 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Period> FMT_CONSTEXPR inline const char* get_units() {
|
||||
template <typename Period>
|
||||
FMT_CONSTEXPR inline auto get_units() -> const char* {
|
||||
if (std::is_same<Period, std::atto>::value) return "as";
|
||||
if (std::is_same<Period, std::femto>::value) return "fs";
|
||||
if (std::is_same<Period, std::pico>::value) return "ps";
|
||||
@@ -627,8 +632,9 @@ template <typename Period> FMT_CONSTEXPR inline const char* get_units() {
|
||||
if (std::is_same<Period, std::tera>::value) return "Ts";
|
||||
if (std::is_same<Period, std::peta>::value) return "Ps";
|
||||
if (std::is_same<Period, std::exa>::value) return "Es";
|
||||
if (std::is_same<Period, std::ratio<60>>::value) return "m";
|
||||
if (std::is_same<Period, std::ratio<60>>::value) return "min";
|
||||
if (std::is_same<Period, std::ratio<3600>>::value) return "h";
|
||||
if (std::is_same<Period, std::ratio<86400>>::value) return "d";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -664,9 +670,8 @@ auto write_padding(OutputIt out, pad_type pad) -> OutputIt {
|
||||
|
||||
// Parses a put_time-like format string and invokes handler actions.
|
||||
template <typename Char, typename Handler>
|
||||
FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
|
||||
const Char* end,
|
||||
Handler&& handler) {
|
||||
FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
|
||||
Handler&& handler) -> const Char* {
|
||||
if (begin == end || *begin == '}') return begin;
|
||||
if (*begin != '%') FMT_THROW(format_error("invalid format"));
|
||||
auto ptr = begin;
|
||||
@@ -997,25 +1002,25 @@ struct tm_format_checker : null_chrono_spec_handler<tm_format_checker> {
|
||||
FMT_CONSTEXPR void on_tz_name() {}
|
||||
};
|
||||
|
||||
inline const char* tm_wday_full_name(int wday) {
|
||||
inline auto tm_wday_full_name(int wday) -> const char* {
|
||||
static constexpr const char* full_name_list[] = {
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday",
|
||||
"Thursday", "Friday", "Saturday"};
|
||||
return wday >= 0 && wday <= 6 ? full_name_list[wday] : "?";
|
||||
}
|
||||
inline const char* tm_wday_short_name(int wday) {
|
||||
inline auto tm_wday_short_name(int wday) -> const char* {
|
||||
static constexpr const char* short_name_list[] = {"Sun", "Mon", "Tue", "Wed",
|
||||
"Thu", "Fri", "Sat"};
|
||||
return wday >= 0 && wday <= 6 ? short_name_list[wday] : "???";
|
||||
}
|
||||
|
||||
inline const char* tm_mon_full_name(int mon) {
|
||||
inline auto tm_mon_full_name(int mon) -> const char* {
|
||||
static constexpr const char* full_name_list[] = {
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"};
|
||||
return mon >= 0 && mon <= 11 ? full_name_list[mon] : "?";
|
||||
}
|
||||
inline const char* tm_mon_short_name(int mon) {
|
||||
inline auto tm_mon_short_name(int mon) -> const char* {
|
||||
static constexpr const char* short_name_list[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
||||
@@ -1047,21 +1052,21 @@ inline void tzset_once() {
|
||||
|
||||
// Converts value to Int and checks that it's in the range [0, upper).
|
||||
template <typename T, typename Int, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
inline Int to_nonnegative_int(T value, Int upper) {
|
||||
FMT_ASSERT(std::is_unsigned<Int>::value ||
|
||||
(value >= 0 && to_unsigned(value) <= to_unsigned(upper)),
|
||||
"invalid value");
|
||||
(void)upper;
|
||||
inline auto to_nonnegative_int(T value, Int upper) -> Int {
|
||||
if (!std::is_unsigned<Int>::value &&
|
||||
(value < 0 || to_unsigned(value) > to_unsigned(upper))) {
|
||||
FMT_THROW(fmt::format_error("chrono value is out of range"));
|
||||
}
|
||||
return static_cast<Int>(value);
|
||||
}
|
||||
template <typename T, typename Int, FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
||||
inline Int to_nonnegative_int(T value, Int upper) {
|
||||
inline auto to_nonnegative_int(T value, Int upper) -> Int {
|
||||
if (value < 0 || value > static_cast<T>(upper))
|
||||
FMT_THROW(format_error("invalid value"));
|
||||
return static_cast<Int>(value);
|
||||
}
|
||||
|
||||
constexpr long long pow10(std::uint32_t n) {
|
||||
constexpr auto pow10(std::uint32_t n) -> long long {
|
||||
return n == 0 ? 1 : 10 * pow10(n - 1);
|
||||
}
|
||||
|
||||
@@ -1095,13 +1100,12 @@ void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) {
|
||||
std::chrono::seconds::rep>::type,
|
||||
std::ratio<1, detail::pow10(num_fractional_digits)>>;
|
||||
|
||||
const auto fractional =
|
||||
d - std::chrono::duration_cast<std::chrono::seconds>(d);
|
||||
const auto fractional = d - fmt_duration_cast<std::chrono::seconds>(d);
|
||||
const auto subseconds =
|
||||
std::chrono::treat_as_floating_point<
|
||||
typename subsecond_precision::rep>::value
|
||||
? fractional.count()
|
||||
: std::chrono::duration_cast<subsecond_precision>(fractional).count();
|
||||
: fmt_duration_cast<subsecond_precision>(fractional).count();
|
||||
auto n = static_cast<uint32_or_64_or_128_t<long long>>(subseconds);
|
||||
const int num_digits = detail::count_digits(n);
|
||||
|
||||
@@ -1152,11 +1156,11 @@ void write_floating_seconds(memory_buffer& buf, Duration duration,
|
||||
num_fractional_digits = 6;
|
||||
}
|
||||
|
||||
format_to(std::back_inserter(buf), FMT_STRING("{:.{}f}"),
|
||||
std::fmod(val * static_cast<rep>(Duration::period::num) /
|
||||
static_cast<rep>(Duration::period::den),
|
||||
static_cast<rep>(60)),
|
||||
num_fractional_digits);
|
||||
fmt::format_to(std::back_inserter(buf), FMT_STRING("{:.{}f}"),
|
||||
std::fmod(val * static_cast<rep>(Duration::period::num) /
|
||||
static_cast<rep>(Duration::period::den),
|
||||
static_cast<rep>(60)),
|
||||
num_fractional_digits);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Char,
|
||||
@@ -1217,8 +1221,7 @@ class tm_writer {
|
||||
return static_cast<int>(l);
|
||||
}
|
||||
|
||||
// Algorithm:
|
||||
// https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_from_a_month_and_day_of_the_month_or_ordinal_date
|
||||
// Algorithm: https://en.wikipedia.org/wiki/ISO_week_date.
|
||||
auto iso_year_weeks(long long curr_year) const noexcept -> int {
|
||||
const auto prev_year = curr_year - 1;
|
||||
const auto curr_p =
|
||||
@@ -1358,7 +1361,7 @@ class tm_writer {
|
||||
subsecs_(subsecs),
|
||||
tm_(tm) {}
|
||||
|
||||
OutputIt out() const { return out_; }
|
||||
auto out() const -> OutputIt { return out_; }
|
||||
|
||||
FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) {
|
||||
out_ = copy_str<Char>(begin, end, out_);
|
||||
@@ -1622,6 +1625,7 @@ struct chrono_format_checker : null_chrono_spec_handler<chrono_format_checker> {
|
||||
|
||||
template <typename Char>
|
||||
FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
|
||||
FMT_CONSTEXPR void on_day_of_year() {}
|
||||
FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {}
|
||||
FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {}
|
||||
FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {}
|
||||
@@ -1640,16 +1644,16 @@ struct chrono_format_checker : null_chrono_spec_handler<chrono_format_checker> {
|
||||
|
||||
template <typename T,
|
||||
FMT_ENABLE_IF(std::is_integral<T>::value&& has_isfinite<T>::value)>
|
||||
inline bool isfinite(T) {
|
||||
inline auto isfinite(T) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
inline T mod(T x, int y) {
|
||||
inline auto mod(T x, int y) -> T {
|
||||
return x % static_cast<T>(y);
|
||||
}
|
||||
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
||||
inline T mod(T x, int y) {
|
||||
inline auto mod(T x, int y) -> T {
|
||||
return std::fmod(x, static_cast<T>(y));
|
||||
}
|
||||
|
||||
@@ -1664,49 +1668,38 @@ template <typename T> struct make_unsigned_or_unchanged<T, true> {
|
||||
using type = typename std::make_unsigned<T>::type;
|
||||
};
|
||||
|
||||
#if FMT_SAFE_DURATION_CAST
|
||||
// throwing version of safe_duration_cast
|
||||
template <typename To, typename FromRep, typename FromPeriod>
|
||||
To fmt_safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from) {
|
||||
int ec;
|
||||
To to = safe_duration_cast::safe_duration_cast<To>(from, ec);
|
||||
if (ec) FMT_THROW(format_error("cannot format duration"));
|
||||
return to;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename Rep, typename Period,
|
||||
FMT_ENABLE_IF(std::is_integral<Rep>::value)>
|
||||
inline std::chrono::duration<Rep, std::milli> get_milliseconds(
|
||||
std::chrono::duration<Rep, Period> d) {
|
||||
inline auto get_milliseconds(std::chrono::duration<Rep, Period> d)
|
||||
-> std::chrono::duration<Rep, std::milli> {
|
||||
// this may overflow and/or the result may not fit in the
|
||||
// target type.
|
||||
#if FMT_SAFE_DURATION_CAST
|
||||
using CommonSecondsType =
|
||||
typename std::common_type<decltype(d), std::chrono::seconds>::type;
|
||||
const auto d_as_common = fmt_safe_duration_cast<CommonSecondsType>(d);
|
||||
const auto d_as_common = fmt_duration_cast<CommonSecondsType>(d);
|
||||
const auto d_as_whole_seconds =
|
||||
fmt_safe_duration_cast<std::chrono::seconds>(d_as_common);
|
||||
fmt_duration_cast<std::chrono::seconds>(d_as_common);
|
||||
// this conversion should be nonproblematic
|
||||
const auto diff = d_as_common - d_as_whole_seconds;
|
||||
const auto ms =
|
||||
fmt_safe_duration_cast<std::chrono::duration<Rep, std::milli>>(diff);
|
||||
fmt_duration_cast<std::chrono::duration<Rep, std::milli>>(diff);
|
||||
return ms;
|
||||
#else
|
||||
auto s = std::chrono::duration_cast<std::chrono::seconds>(d);
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(d - s);
|
||||
auto s = fmt_duration_cast<std::chrono::seconds>(d);
|
||||
return fmt_duration_cast<std::chrono::milliseconds>(d - s);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename Char, typename Rep, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_integral<Rep>::value)>
|
||||
OutputIt format_duration_value(OutputIt out, Rep val, int) {
|
||||
auto format_duration_value(OutputIt out, Rep val, int) -> OutputIt {
|
||||
return write<Char>(out, val);
|
||||
}
|
||||
|
||||
template <typename Char, typename Rep, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_floating_point<Rep>::value)>
|
||||
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
|
||||
auto format_duration_value(OutputIt out, Rep val, int precision) -> OutputIt {
|
||||
auto specs = format_specs<Char>();
|
||||
specs.precision = precision;
|
||||
specs.type = precision >= 0 ? presentation_type::fixed_lower
|
||||
@@ -1715,12 +1708,12 @@ OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
|
||||
}
|
||||
|
||||
template <typename Char, typename OutputIt>
|
||||
OutputIt copy_unit(string_view unit, OutputIt out, Char) {
|
||||
auto copy_unit(string_view unit, OutputIt out, Char) -> OutputIt {
|
||||
return std::copy(unit.begin(), unit.end(), out);
|
||||
}
|
||||
|
||||
template <typename OutputIt>
|
||||
OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) {
|
||||
auto copy_unit(string_view unit, OutputIt out, wchar_t) -> OutputIt {
|
||||
// This works when wchar_t is UTF-32 because units only contain characters
|
||||
// that have the same representation in UTF-16 and UTF-32.
|
||||
utf8_to_utf16 u(unit);
|
||||
@@ -1728,7 +1721,7 @@ OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) {
|
||||
}
|
||||
|
||||
template <typename Char, typename Period, typename OutputIt>
|
||||
OutputIt format_duration_unit(OutputIt out) {
|
||||
auto format_duration_unit(OutputIt out) -> OutputIt {
|
||||
if (const char* unit = get_units<Period>())
|
||||
return copy_unit(string_view(unit), out, Char());
|
||||
*out++ = '[';
|
||||
@@ -1795,18 +1788,12 @@ struct chrono_formatter {
|
||||
|
||||
// this may overflow and/or the result may not fit in the
|
||||
// target type.
|
||||
#if FMT_SAFE_DURATION_CAST
|
||||
// might need checked conversion (rep!=Rep)
|
||||
auto tmpval = std::chrono::duration<rep, Period>(val);
|
||||
s = fmt_safe_duration_cast<seconds>(tmpval);
|
||||
#else
|
||||
s = std::chrono::duration_cast<seconds>(
|
||||
std::chrono::duration<rep, Period>(val));
|
||||
#endif
|
||||
s = fmt_duration_cast<seconds>(std::chrono::duration<rep, Period>(val));
|
||||
}
|
||||
|
||||
// returns true if nan or inf, writes to out.
|
||||
bool handle_nan_inf() {
|
||||
auto handle_nan_inf() -> bool {
|
||||
if (isfinite(val)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1823,17 +1810,22 @@ struct chrono_formatter {
|
||||
return true;
|
||||
}
|
||||
|
||||
Rep hour() const { return static_cast<Rep>(mod((s.count() / 3600), 24)); }
|
||||
auto days() const -> Rep { return static_cast<Rep>(s.count() / 86400); }
|
||||
auto hour() const -> Rep {
|
||||
return static_cast<Rep>(mod((s.count() / 3600), 24));
|
||||
}
|
||||
|
||||
Rep hour12() const {
|
||||
auto hour12() const -> Rep {
|
||||
Rep hour = static_cast<Rep>(mod((s.count() / 3600), 12));
|
||||
return hour <= 0 ? 12 : hour;
|
||||
}
|
||||
|
||||
Rep minute() const { return static_cast<Rep>(mod((s.count() / 60), 60)); }
|
||||
Rep second() const { return static_cast<Rep>(mod(s.count(), 60)); }
|
||||
auto minute() const -> Rep {
|
||||
return static_cast<Rep>(mod((s.count() / 60), 60));
|
||||
}
|
||||
auto second() const -> Rep { return static_cast<Rep>(mod(s.count(), 60)); }
|
||||
|
||||
std::tm time() const {
|
||||
auto time() const -> std::tm {
|
||||
auto time = std::tm();
|
||||
time.tm_hour = to_nonnegative_int(hour(), 24);
|
||||
time.tm_min = to_nonnegative_int(minute(), 60);
|
||||
@@ -1901,10 +1893,14 @@ struct chrono_formatter {
|
||||
void on_dec0_week_of_year(numeric_system) {}
|
||||
void on_dec1_week_of_year(numeric_system) {}
|
||||
void on_iso_week_of_year(numeric_system) {}
|
||||
void on_day_of_year() {}
|
||||
void on_day_of_month(numeric_system) {}
|
||||
void on_day_of_month_space(numeric_system) {}
|
||||
|
||||
void on_day_of_year() {
|
||||
if (handle_nan_inf()) return;
|
||||
write(days(), 0);
|
||||
}
|
||||
|
||||
void on_24_hour(numeric_system ns, pad_type pad) {
|
||||
if (handle_nan_inf()) return;
|
||||
|
||||
@@ -1997,7 +1993,7 @@ struct chrono_formatter {
|
||||
}
|
||||
};
|
||||
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
} // namespace detail
|
||||
|
||||
#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907
|
||||
using weekday = std::chrono::weekday;
|
||||
@@ -2011,7 +2007,7 @@ class weekday {
|
||||
weekday() = default;
|
||||
explicit constexpr weekday(unsigned wd) noexcept
|
||||
: value(static_cast<unsigned char>(wd != 7 ? wd : 0)) {}
|
||||
constexpr unsigned c_encoding() const noexcept { return value; }
|
||||
constexpr auto c_encoding() const noexcept -> unsigned { return value; }
|
||||
};
|
||||
|
||||
class year_month_day {};
|
||||
@@ -2047,80 +2043,67 @@ template <typename Char> struct formatter<weekday, Char> {
|
||||
template <typename Rep, typename Period, typename Char>
|
||||
struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
||||
private:
|
||||
format_specs<Char> specs;
|
||||
int precision = -1;
|
||||
using arg_ref_type = detail::arg_ref<Char>;
|
||||
arg_ref_type width_ref;
|
||||
arg_ref_type precision_ref;
|
||||
bool localized = false;
|
||||
basic_string_view<Char> format_str;
|
||||
using duration = std::chrono::duration<Rep, Period>;
|
||||
|
||||
using iterator = typename basic_format_parse_context<Char>::iterator;
|
||||
struct parse_range {
|
||||
iterator begin;
|
||||
iterator end;
|
||||
};
|
||||
|
||||
FMT_CONSTEXPR parse_range do_parse(basic_format_parse_context<Char>& ctx) {
|
||||
auto begin = ctx.begin(), end = ctx.end();
|
||||
if (begin == end || *begin == '}') return {begin, begin};
|
||||
|
||||
begin = detail::parse_align(begin, end, specs);
|
||||
if (begin == end) return {begin, begin};
|
||||
|
||||
begin = detail::parse_dynamic_spec(begin, end, specs.width, width_ref, ctx);
|
||||
if (begin == end) return {begin, begin};
|
||||
|
||||
auto checker = detail::chrono_format_checker();
|
||||
if (*begin == '.') {
|
||||
checker.has_precision_integral = !std::is_floating_point<Rep>::value;
|
||||
begin =
|
||||
detail::parse_precision(begin, end, precision, precision_ref, ctx);
|
||||
}
|
||||
if (begin != end && *begin == 'L') {
|
||||
++begin;
|
||||
localized = true;
|
||||
}
|
||||
end = detail::parse_chrono_format(begin, end, checker);
|
||||
return {begin, end};
|
||||
}
|
||||
format_specs<Char> specs_;
|
||||
detail::arg_ref<Char> width_ref_;
|
||||
detail::arg_ref<Char> precision_ref_;
|
||||
bool localized_ = false;
|
||||
basic_string_view<Char> format_str_;
|
||||
|
||||
public:
|
||||
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
|
||||
-> decltype(ctx.begin()) {
|
||||
auto range = do_parse(ctx);
|
||||
format_str = basic_string_view<Char>(
|
||||
&*range.begin, detail::to_unsigned(range.end - range.begin));
|
||||
return range.end;
|
||||
auto it = ctx.begin(), end = ctx.end();
|
||||
if (it == end || *it == '}') return it;
|
||||
|
||||
it = detail::parse_align(it, end, specs_);
|
||||
if (it == end) return it;
|
||||
|
||||
it = detail::parse_dynamic_spec(it, end, specs_.width, width_ref_, ctx);
|
||||
if (it == end) return it;
|
||||
|
||||
auto checker = detail::chrono_format_checker();
|
||||
if (*it == '.') {
|
||||
checker.has_precision_integral = !std::is_floating_point<Rep>::value;
|
||||
it = detail::parse_precision(it, end, specs_.precision, precision_ref_,
|
||||
ctx);
|
||||
}
|
||||
if (it != end && *it == 'L') {
|
||||
localized_ = true;
|
||||
++it;
|
||||
}
|
||||
end = detail::parse_chrono_format(it, end, checker);
|
||||
format_str_ = {it, detail::to_unsigned(end - it)};
|
||||
return end;
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const duration& d, FormatContext& ctx) const
|
||||
auto format(std::chrono::duration<Rep, Period> d, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
auto specs_copy = specs;
|
||||
auto precision_copy = precision;
|
||||
auto begin = format_str.begin(), end = format_str.end();
|
||||
auto specs = specs_;
|
||||
auto precision = specs.precision;
|
||||
specs.precision = -1;
|
||||
auto begin = format_str_.begin(), end = format_str_.end();
|
||||
// As a possible future optimization, we could avoid extra copying if width
|
||||
// is not specified.
|
||||
basic_memory_buffer<Char> buf;
|
||||
auto buf = basic_memory_buffer<Char>();
|
||||
auto out = std::back_inserter(buf);
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs_copy.width,
|
||||
width_ref, ctx);
|
||||
detail::handle_dynamic_spec<detail::precision_checker>(precision_copy,
|
||||
precision_ref, ctx);
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_,
|
||||
ctx);
|
||||
detail::handle_dynamic_spec<detail::precision_checker>(precision,
|
||||
precision_ref_, ctx);
|
||||
if (begin == end || *begin == '}') {
|
||||
out = detail::format_duration_value<Char>(out, d.count(), precision_copy);
|
||||
out = detail::format_duration_value<Char>(out, d.count(), precision);
|
||||
detail::format_duration_unit<Char, Period>(out);
|
||||
} else {
|
||||
detail::chrono_formatter<FormatContext, decltype(out), Rep, Period> f(
|
||||
ctx, out, d);
|
||||
f.precision = precision_copy;
|
||||
f.localized = localized;
|
||||
using chrono_formatter =
|
||||
detail::chrono_formatter<FormatContext, decltype(out), Rep, Period>;
|
||||
auto f = chrono_formatter(ctx, out, d);
|
||||
f.precision = precision;
|
||||
f.localized = localized_;
|
||||
detail::parse_chrono_format(begin, end, f);
|
||||
}
|
||||
return detail::write(
|
||||
ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs_copy);
|
||||
ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2128,34 +2111,33 @@ template <typename Char, typename Duration>
|
||||
struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
||||
Char> : formatter<std::tm, Char> {
|
||||
FMT_CONSTEXPR formatter() {
|
||||
this->format_str = detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>{};
|
||||
this->format_str_ = detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>{};
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(std::chrono::time_point<std::chrono::system_clock, Duration> val,
|
||||
FormatContext& ctx) const -> decltype(ctx.out()) {
|
||||
using period = typename Duration::period;
|
||||
if (period::num != 1 || period::den != 1 ||
|
||||
std::is_floating_point<typename Duration::rep>::value) {
|
||||
if (detail::const_check(
|
||||
period::num != 1 || period::den != 1 ||
|
||||
std::is_floating_point<typename Duration::rep>::value)) {
|
||||
const auto epoch = val.time_since_epoch();
|
||||
auto subsecs = std::chrono::duration_cast<Duration>(
|
||||
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
|
||||
auto subsecs = detail::fmt_duration_cast<Duration>(
|
||||
epoch - detail::fmt_duration_cast<std::chrono::seconds>(epoch));
|
||||
|
||||
if (subsecs.count() < 0) {
|
||||
auto second = std::chrono::seconds(1);
|
||||
auto second =
|
||||
detail::fmt_duration_cast<Duration>(std::chrono::seconds(1));
|
||||
if (epoch.count() < ((Duration::min)() + second).count())
|
||||
FMT_THROW(format_error("duration is too small"));
|
||||
subsecs += second;
|
||||
val -= second;
|
||||
}
|
||||
|
||||
return formatter<std::tm, Char>::do_format(
|
||||
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx,
|
||||
&subsecs);
|
||||
return formatter<std::tm, Char>::do_format(gmtime(val), ctx, &subsecs);
|
||||
}
|
||||
|
||||
return formatter<std::tm, Char>::format(
|
||||
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx);
|
||||
return formatter<std::tm, Char>::format(gmtime(val), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2164,7 +2146,7 @@ template <typename Char, typename Duration>
|
||||
struct formatter<std::chrono::local_time<Duration>, Char>
|
||||
: formatter<std::tm, Char> {
|
||||
FMT_CONSTEXPR formatter() {
|
||||
this->format_str = detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>{};
|
||||
this->format_str_ = detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>{};
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
@@ -2174,17 +2156,13 @@ struct formatter<std::chrono::local_time<Duration>, Char>
|
||||
if (period::num != 1 || period::den != 1 ||
|
||||
std::is_floating_point<typename Duration::rep>::value) {
|
||||
const auto epoch = val.time_since_epoch();
|
||||
const auto subsecs = std::chrono::duration_cast<Duration>(
|
||||
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
|
||||
const auto subsecs = detail::fmt_duration_cast<Duration>(
|
||||
epoch - detail::fmt_duration_cast<std::chrono::seconds>(epoch));
|
||||
|
||||
return formatter<std::tm, Char>::do_format(
|
||||
localtime(std::chrono::time_point_cast<std::chrono::seconds>(val)),
|
||||
ctx, &subsecs);
|
||||
return formatter<std::tm, Char>::do_format(localtime(val), ctx, &subsecs);
|
||||
}
|
||||
|
||||
return formatter<std::tm, Char>::format(
|
||||
localtime(std::chrono::time_point_cast<std::chrono::seconds>(val)),
|
||||
ctx);
|
||||
return formatter<std::tm, Char>::format(localtime(val), ctx);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
@@ -2207,51 +2185,46 @@ struct formatter<std::chrono::time_point<std::chrono::utc_clock, Duration>,
|
||||
|
||||
template <typename Char> struct formatter<std::tm, Char> {
|
||||
private:
|
||||
format_specs<Char> specs;
|
||||
detail::arg_ref<Char> width_ref;
|
||||
format_specs<Char> specs_;
|
||||
detail::arg_ref<Char> width_ref_;
|
||||
|
||||
protected:
|
||||
basic_string_view<Char> format_str;
|
||||
|
||||
FMT_CONSTEXPR auto do_parse(basic_format_parse_context<Char>& ctx)
|
||||
-> decltype(ctx.begin()) {
|
||||
auto begin = ctx.begin(), end = ctx.end();
|
||||
if (begin == end || *begin == '}') return begin;
|
||||
|
||||
begin = detail::parse_align(begin, end, specs);
|
||||
if (begin == end) return end;
|
||||
|
||||
begin = detail::parse_dynamic_spec(begin, end, specs.width, width_ref, ctx);
|
||||
if (begin == end) return end;
|
||||
|
||||
end = detail::parse_chrono_format(begin, end, detail::tm_format_checker());
|
||||
// Replace default format_str only if the new spec is not empty.
|
||||
if (end != begin) format_str = {begin, detail::to_unsigned(end - begin)};
|
||||
return end;
|
||||
}
|
||||
basic_string_view<Char> format_str_;
|
||||
|
||||
template <typename FormatContext, typename Duration>
|
||||
auto do_format(const std::tm& tm, FormatContext& ctx,
|
||||
const Duration* subsecs) const -> decltype(ctx.out()) {
|
||||
auto specs_copy = specs;
|
||||
basic_memory_buffer<Char> buf;
|
||||
auto specs = specs_;
|
||||
auto buf = basic_memory_buffer<Char>();
|
||||
auto out = std::back_inserter(buf);
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs_copy.width,
|
||||
width_ref, ctx);
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_,
|
||||
ctx);
|
||||
|
||||
const auto loc_ref = ctx.locale();
|
||||
auto loc_ref = ctx.locale();
|
||||
detail::get_locale loc(static_cast<bool>(loc_ref), loc_ref);
|
||||
auto w =
|
||||
detail::tm_writer<decltype(out), Char, Duration>(loc, out, tm, subsecs);
|
||||
detail::parse_chrono_format(format_str.begin(), format_str.end(), w);
|
||||
detail::parse_chrono_format(format_str_.begin(), format_str_.end(), w);
|
||||
return detail::write(
|
||||
ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs_copy);
|
||||
ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
|
||||
}
|
||||
|
||||
public:
|
||||
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
|
||||
-> decltype(ctx.begin()) {
|
||||
return this->do_parse(ctx);
|
||||
auto it = ctx.begin(), end = ctx.end();
|
||||
if (it == end || *it == '}') return it;
|
||||
|
||||
it = detail::parse_align(it, end, specs_);
|
||||
if (it == end) return it;
|
||||
|
||||
it = detail::parse_dynamic_spec(it, end, specs_.width, width_ref_, ctx);
|
||||
if (it == end) return it;
|
||||
|
||||
end = detail::parse_chrono_format(it, end, detail::tm_format_checker());
|
||||
// Replace the default format_str only if the new spec is not empty.
|
||||
if (end != it) format_str_ = {it, detail::to_unsigned(end - it)};
|
||||
return end;
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
|
||||
+48
-38
@@ -203,7 +203,7 @@ struct rgb {
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
// color is a struct of either a rgb color or a terminal color.
|
||||
struct color_type {
|
||||
@@ -225,8 +225,7 @@ struct color_type {
|
||||
uint32_t rgb_color;
|
||||
} value;
|
||||
};
|
||||
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
} // namespace detail
|
||||
|
||||
/** A text style consisting of foreground and background colors and emphasis. */
|
||||
class text_style {
|
||||
@@ -234,7 +233,7 @@ class text_style {
|
||||
FMT_CONSTEXPR text_style(emphasis em = emphasis()) noexcept
|
||||
: set_foreground_color(), set_background_color(), ems(em) {}
|
||||
|
||||
FMT_CONSTEXPR text_style& operator|=(const text_style& rhs) {
|
||||
FMT_CONSTEXPR auto operator|=(const text_style& rhs) -> text_style& {
|
||||
if (!set_foreground_color) {
|
||||
set_foreground_color = rhs.set_foreground_color;
|
||||
foreground_color = rhs.foreground_color;
|
||||
@@ -258,29 +257,29 @@ class text_style {
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend FMT_CONSTEXPR text_style operator|(text_style lhs,
|
||||
const text_style& rhs) {
|
||||
friend FMT_CONSTEXPR auto operator|(text_style lhs, const text_style& rhs)
|
||||
-> text_style {
|
||||
return lhs |= rhs;
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR bool has_foreground() const noexcept {
|
||||
FMT_CONSTEXPR auto has_foreground() const noexcept -> bool {
|
||||
return set_foreground_color;
|
||||
}
|
||||
FMT_CONSTEXPR bool has_background() const noexcept {
|
||||
FMT_CONSTEXPR auto has_background() const noexcept -> bool {
|
||||
return set_background_color;
|
||||
}
|
||||
FMT_CONSTEXPR bool has_emphasis() const noexcept {
|
||||
FMT_CONSTEXPR auto has_emphasis() const noexcept -> bool {
|
||||
return static_cast<uint8_t>(ems) != 0;
|
||||
}
|
||||
FMT_CONSTEXPR detail::color_type get_foreground() const noexcept {
|
||||
FMT_CONSTEXPR auto get_foreground() const noexcept -> detail::color_type {
|
||||
FMT_ASSERT(has_foreground(), "no foreground specified for this style");
|
||||
return foreground_color;
|
||||
}
|
||||
FMT_CONSTEXPR detail::color_type get_background() const noexcept {
|
||||
FMT_CONSTEXPR auto get_background() const noexcept -> detail::color_type {
|
||||
FMT_ASSERT(has_background(), "no background specified for this style");
|
||||
return background_color;
|
||||
}
|
||||
FMT_CONSTEXPR emphasis get_emphasis() const noexcept {
|
||||
FMT_CONSTEXPR auto get_emphasis() const noexcept -> emphasis {
|
||||
FMT_ASSERT(has_emphasis(), "no emphasis specified for this style");
|
||||
return ems;
|
||||
}
|
||||
@@ -298,9 +297,11 @@ class text_style {
|
||||
}
|
||||
}
|
||||
|
||||
friend FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept;
|
||||
friend FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept
|
||||
-> text_style;
|
||||
|
||||
friend FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept;
|
||||
friend FMT_CONSTEXPR auto bg(detail::color_type background) noexcept
|
||||
-> text_style;
|
||||
|
||||
detail::color_type foreground_color;
|
||||
detail::color_type background_color;
|
||||
@@ -310,20 +311,23 @@ class text_style {
|
||||
};
|
||||
|
||||
/** Creates a text style from the foreground (text) color. */
|
||||
FMT_CONSTEXPR inline text_style fg(detail::color_type foreground) noexcept {
|
||||
FMT_CONSTEXPR inline auto fg(detail::color_type foreground) noexcept
|
||||
-> text_style {
|
||||
return text_style(true, foreground);
|
||||
}
|
||||
|
||||
/** Creates a text style from the background color. */
|
||||
FMT_CONSTEXPR inline text_style bg(detail::color_type background) noexcept {
|
||||
FMT_CONSTEXPR inline auto bg(detail::color_type background) noexcept
|
||||
-> text_style {
|
||||
return text_style(false, background);
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR inline text_style operator|(emphasis lhs, emphasis rhs) noexcept {
|
||||
FMT_CONSTEXPR inline auto operator|(emphasis lhs, emphasis rhs) noexcept
|
||||
-> text_style {
|
||||
return text_style(lhs) | rhs;
|
||||
}
|
||||
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
template <typename Char> struct ansi_color_escape {
|
||||
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color,
|
||||
@@ -385,8 +389,8 @@ template <typename Char> struct ansi_color_escape {
|
||||
}
|
||||
FMT_CONSTEXPR operator const Char*() const noexcept { return buffer; }
|
||||
|
||||
FMT_CONSTEXPR const Char* begin() const noexcept { return buffer; }
|
||||
FMT_CONSTEXPR_CHAR_TRAITS const Char* end() const noexcept {
|
||||
FMT_CONSTEXPR auto begin() const noexcept -> const Char* { return buffer; }
|
||||
FMT_CONSTEXPR_CHAR_TRAITS auto end() const noexcept -> const Char* {
|
||||
return buffer + std::char_traits<Char>::length(buffer);
|
||||
}
|
||||
|
||||
@@ -401,25 +405,27 @@ template <typename Char> struct ansi_color_escape {
|
||||
out[2] = static_cast<Char>('0' + c % 10);
|
||||
out[3] = static_cast<Char>(delimiter);
|
||||
}
|
||||
static FMT_CONSTEXPR bool has_emphasis(emphasis em, emphasis mask) noexcept {
|
||||
static FMT_CONSTEXPR auto has_emphasis(emphasis em, emphasis mask) noexcept
|
||||
-> bool {
|
||||
return static_cast<uint8_t>(em) & static_cast<uint8_t>(mask);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
FMT_CONSTEXPR ansi_color_escape<Char> make_foreground_color(
|
||||
detail::color_type foreground) noexcept {
|
||||
FMT_CONSTEXPR auto make_foreground_color(detail::color_type foreground) noexcept
|
||||
-> ansi_color_escape<Char> {
|
||||
return ansi_color_escape<Char>(foreground, "\x1b[38;2;");
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
FMT_CONSTEXPR ansi_color_escape<Char> make_background_color(
|
||||
detail::color_type background) noexcept {
|
||||
FMT_CONSTEXPR auto make_background_color(detail::color_type background) noexcept
|
||||
-> ansi_color_escape<Char> {
|
||||
return ansi_color_escape<Char>(background, "\x1b[48;2;");
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
FMT_CONSTEXPR ansi_color_escape<Char> make_emphasis(emphasis em) noexcept {
|
||||
FMT_CONSTEXPR auto make_emphasis(emphasis em) noexcept
|
||||
-> ansi_color_escape<Char> {
|
||||
return ansi_color_escape<Char>(em);
|
||||
}
|
||||
|
||||
@@ -428,9 +434,10 @@ template <typename Char> inline void reset_color(buffer<Char>& buffer) {
|
||||
buffer.append(reset_color.begin(), reset_color.end());
|
||||
}
|
||||
|
||||
template <typename T> struct styled_arg {
|
||||
template <typename T> struct styled_arg : detail::view {
|
||||
const T& value;
|
||||
text_style style;
|
||||
styled_arg(const T& v, text_style s) : value(v), style(s) {}
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
@@ -457,7 +464,7 @@ void vformat_to(buffer<Char>& buf, const text_style& ts,
|
||||
if (has_style) detail::reset_color<Char>(buf);
|
||||
}
|
||||
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
} // namespace detail
|
||||
|
||||
inline void vprint(std::FILE* f, const text_style& ts, string_view fmt,
|
||||
format_args args) {
|
||||
@@ -511,9 +518,10 @@ void print(const text_style& ts, const S& format_str, const Args&... args) {
|
||||
}
|
||||
|
||||
template <typename S, typename Char = char_t<S>>
|
||||
inline std::basic_string<Char> vformat(
|
||||
inline auto vformat(
|
||||
const text_style& ts, const S& format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args)
|
||||
-> std::basic_string<Char> {
|
||||
basic_memory_buffer<Char> buf;
|
||||
detail::vformat_to(buf, ts, detail::to_string_view(format_str), args);
|
||||
return fmt::to_string(buf);
|
||||
@@ -532,8 +540,8 @@ inline std::basic_string<Char> vformat(
|
||||
\endrst
|
||||
*/
|
||||
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||
inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
|
||||
const Args&... args) {
|
||||
inline auto format(const text_style& ts, const S& format_str,
|
||||
const Args&... args) -> std::basic_string<Char> {
|
||||
return fmt::vformat(ts, detail::to_string_view(format_str),
|
||||
fmt::make_format_args<buffer_context<Char>>(args...));
|
||||
}
|
||||
@@ -543,9 +551,10 @@ inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
|
||||
*/
|
||||
template <typename OutputIt, typename Char,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
|
||||
OutputIt vformat_to(
|
||||
OutputIt out, const text_style& ts, basic_string_view<Char> format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||
auto vformat_to(OutputIt out, const text_style& ts,
|
||||
basic_string_view<Char> format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args)
|
||||
-> OutputIt {
|
||||
auto&& buf = detail::get_buffer<Char>(out);
|
||||
detail::vformat_to(buf, ts, format_str, args);
|
||||
return detail::get_iterator(buf, out);
|
||||
@@ -563,9 +572,10 @@ OutputIt vformat_to(
|
||||
fmt::emphasis::bold | fg(fmt::color::red), "{}", 42);
|
||||
\endrst
|
||||
*/
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value&&
|
||||
detail::is_string<S>::value>
|
||||
template <
|
||||
typename OutputIt, typename S, typename... Args,
|
||||
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value &&
|
||||
detail::is_string<S>::value>
|
||||
inline auto format_to(OutputIt out, const text_style& ts, const S& format_str,
|
||||
Args&&... args) ->
|
||||
typename std::enable_if<enable, OutputIt>::type {
|
||||
|
||||
+27
-99
@@ -14,89 +14,11 @@ FMT_BEGIN_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
template <typename Char, typename InputIt>
|
||||
FMT_CONSTEXPR inline counting_iterator copy_str(InputIt begin, InputIt end,
|
||||
counting_iterator it) {
|
||||
FMT_CONSTEXPR inline auto copy_str(InputIt begin, InputIt end,
|
||||
counting_iterator it) -> counting_iterator {
|
||||
return it + (end - begin);
|
||||
}
|
||||
|
||||
template <typename OutputIt> class truncating_iterator_base {
|
||||
protected:
|
||||
OutputIt out_;
|
||||
size_t limit_;
|
||||
size_t count_ = 0;
|
||||
|
||||
truncating_iterator_base() : out_(), limit_(0) {}
|
||||
|
||||
truncating_iterator_base(OutputIt out, size_t limit)
|
||||
: out_(out), limit_(limit) {}
|
||||
|
||||
public:
|
||||
using iterator_category = std::output_iterator_tag;
|
||||
using value_type = typename std::iterator_traits<OutputIt>::value_type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = void;
|
||||
using reference = void;
|
||||
FMT_UNCHECKED_ITERATOR(truncating_iterator_base);
|
||||
|
||||
OutputIt base() const { return out_; }
|
||||
size_t count() const { return count_; }
|
||||
};
|
||||
|
||||
// An output iterator that truncates the output and counts the number of objects
|
||||
// written to it.
|
||||
template <typename OutputIt,
|
||||
typename Enable = typename std::is_void<
|
||||
typename std::iterator_traits<OutputIt>::value_type>::type>
|
||||
class truncating_iterator;
|
||||
|
||||
template <typename OutputIt>
|
||||
class truncating_iterator<OutputIt, std::false_type>
|
||||
: public truncating_iterator_base<OutputIt> {
|
||||
mutable typename truncating_iterator_base<OutputIt>::value_type blackhole_;
|
||||
|
||||
public:
|
||||
using value_type = typename truncating_iterator_base<OutputIt>::value_type;
|
||||
|
||||
truncating_iterator() = default;
|
||||
|
||||
truncating_iterator(OutputIt out, size_t limit)
|
||||
: truncating_iterator_base<OutputIt>(out, limit) {}
|
||||
|
||||
truncating_iterator& operator++() {
|
||||
if (this->count_++ < this->limit_) ++this->out_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
truncating_iterator operator++(int) {
|
||||
auto it = *this;
|
||||
++*this;
|
||||
return it;
|
||||
}
|
||||
|
||||
value_type& operator*() const {
|
||||
return this->count_ < this->limit_ ? *this->out_ : blackhole_;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename OutputIt>
|
||||
class truncating_iterator<OutputIt, std::true_type>
|
||||
: public truncating_iterator_base<OutputIt> {
|
||||
public:
|
||||
truncating_iterator() = default;
|
||||
|
||||
truncating_iterator(OutputIt out, size_t limit)
|
||||
: truncating_iterator_base<OutputIt>(out, limit) {}
|
||||
|
||||
template <typename T> truncating_iterator& operator=(T val) {
|
||||
if (this->count_++ < this->limit_) *this->out_++ = val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
truncating_iterator& operator++() { return *this; }
|
||||
truncating_iterator& operator++(int) { return *this; }
|
||||
truncating_iterator& operator*() { return *this; }
|
||||
};
|
||||
|
||||
// A compile-time string which is compiled into fast formatting code.
|
||||
class compiled_string {};
|
||||
|
||||
@@ -135,7 +57,7 @@ struct udl_compiled_string : compiled_string {
|
||||
#endif
|
||||
|
||||
template <typename T, typename... Tail>
|
||||
const T& first(const T& value, const Tail&...) {
|
||||
auto first(const T& value, const Tail&...) -> const T& {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -196,7 +118,8 @@ template <typename Char> struct code_unit {
|
||||
|
||||
template <typename OutputIt, typename... Args>
|
||||
constexpr OutputIt format(OutputIt out, const Args&...) const {
|
||||
return write<Char>(out, value);
|
||||
*out++ = value;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -220,7 +143,12 @@ template <typename Char, typename T, int N> struct field {
|
||||
|
||||
template <typename OutputIt, typename... Args>
|
||||
constexpr OutputIt format(OutputIt out, const Args&... args) const {
|
||||
return write<Char>(out, get_arg_checked<T, N>(args...));
|
||||
const T& arg = get_arg_checked<T, N>(args...);
|
||||
if constexpr (std::is_convertible_v<T, basic_string_view<Char>>) {
|
||||
auto s = basic_string_view<Char>(arg);
|
||||
return copy_str<Char>(s.begin(), s.end(), out);
|
||||
}
|
||||
return write<Char>(out, arg);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -448,20 +376,18 @@ constexpr auto compile_format_string(S format_str) {
|
||||
} else if constexpr (arg_id_result.arg_id.kind == arg_id_kind::name) {
|
||||
constexpr auto arg_index =
|
||||
get_arg_index_by_name(arg_id_result.arg_id.val.name, Args{});
|
||||
if constexpr (arg_index != invalid_arg_index) {
|
||||
if constexpr (arg_index >= 0) {
|
||||
constexpr auto next_id =
|
||||
ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
|
||||
return parse_replacement_field_then_tail<
|
||||
decltype(get_type<arg_index, Args>::value), Args, arg_id_end_pos,
|
||||
arg_index, next_id>(format_str);
|
||||
} else {
|
||||
if constexpr (c == '}') {
|
||||
return parse_tail<Args, arg_id_end_pos + 1, ID>(
|
||||
runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
|
||||
format_str);
|
||||
} else if constexpr (c == ':') {
|
||||
return unknown_format(); // no type info for specs parsing
|
||||
}
|
||||
} else if constexpr (c == '}') {
|
||||
return parse_tail<Args, arg_id_end_pos + 1, ID>(
|
||||
runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
|
||||
format_str);
|
||||
} else if constexpr (c == ':') {
|
||||
return unknown_format(); // no type info for specs parsing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -562,17 +488,19 @@ FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
|
||||
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
|
||||
const S& format_str, Args&&... args) {
|
||||
auto it = fmt::format_to(detail::truncating_iterator<OutputIt>(out, n),
|
||||
format_str, std::forward<Args>(args)...);
|
||||
return {it.base(), it.count()};
|
||||
auto format_to_n(OutputIt out, size_t n, const S& format_str, Args&&... args)
|
||||
-> format_to_n_result<OutputIt> {
|
||||
using traits = detail::fixed_buffer_traits;
|
||||
auto buf = detail::iterator_buffer<OutputIt, char, traits>(out, n);
|
||||
fmt::format_to(std::back_inserter(buf), format_str,
|
||||
std::forward<Args>(args)...);
|
||||
return {buf.out(), buf.count()};
|
||||
}
|
||||
|
||||
template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
FMT_CONSTEXPR20 size_t formatted_size(const S& format_str,
|
||||
const Args&... args) {
|
||||
FMT_CONSTEXPR20 auto formatted_size(const S& format_str, const Args&... args)
|
||||
-> size_t {
|
||||
return fmt::format_to(detail::counting_iterator(), format_str, args...)
|
||||
.count();
|
||||
}
|
||||
|
||||
+328
-310
File diff suppressed because it is too large
Load Diff
+93
-96
@@ -18,7 +18,7 @@
|
||||
# include <locale>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32) && !defined(FMT_WINDOWS_NO_WCHAR)
|
||||
# include <io.h> // _isatty
|
||||
#endif
|
||||
|
||||
@@ -58,8 +58,8 @@ FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
|
||||
error_code_size += detail::to_unsigned(detail::count_digits(abs_value));
|
||||
auto it = buffer_appender<char>(out);
|
||||
if (message.size() <= inline_buffer_size - error_code_size)
|
||||
format_to(it, FMT_STRING("{}{}"), message, SEP);
|
||||
format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code);
|
||||
fmt::format_to(it, FMT_STRING("{}{}"), message, SEP);
|
||||
fmt::format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code);
|
||||
FMT_ASSERT(out.size() <= inline_buffer_size, "");
|
||||
}
|
||||
|
||||
@@ -73,9 +73,8 @@ FMT_FUNC void report_error(format_func func, int error_code,
|
||||
}
|
||||
|
||||
// A wrapper around fwrite that throws on error.
|
||||
inline void fwrite_fully(const void* ptr, size_t size, size_t count,
|
||||
FILE* stream) {
|
||||
size_t written = std::fwrite(ptr, size, count, stream);
|
||||
inline void fwrite_fully(const void* ptr, size_t count, FILE* stream) {
|
||||
size_t written = std::fwrite(ptr, 1, count, stream);
|
||||
if (written < count)
|
||||
FMT_THROW(system_error(errno, FMT_STRING("cannot write to file")));
|
||||
}
|
||||
@@ -86,7 +85,7 @@ locale_ref::locale_ref(const Locale& loc) : locale_(&loc) {
|
||||
static_assert(std::is_same<Locale, std::locale>::value, "");
|
||||
}
|
||||
|
||||
template <typename Locale> Locale locale_ref::get() const {
|
||||
template <typename Locale> auto locale_ref::get() const -> Locale {
|
||||
static_assert(std::is_same<Locale, std::locale>::value, "");
|
||||
return locale_ ? *static_cast<const std::locale*>(locale_) : std::locale();
|
||||
}
|
||||
@@ -98,7 +97,8 @@ FMT_FUNC auto thousands_sep_impl(locale_ref loc) -> thousands_sep_result<Char> {
|
||||
auto thousands_sep = grouping.empty() ? Char() : facet.thousands_sep();
|
||||
return {std::move(grouping), thousands_sep};
|
||||
}
|
||||
template <typename Char> FMT_FUNC Char decimal_point_impl(locale_ref loc) {
|
||||
template <typename Char>
|
||||
FMT_FUNC auto decimal_point_impl(locale_ref loc) -> Char {
|
||||
return std::use_facet<std::numpunct<Char>>(loc.get<std::locale>())
|
||||
.decimal_point();
|
||||
}
|
||||
@@ -144,24 +144,25 @@ FMT_API FMT_FUNC auto format_facet<std::locale>::do_put(
|
||||
}
|
||||
#endif
|
||||
|
||||
FMT_FUNC std::system_error vsystem_error(int error_code, string_view fmt,
|
||||
format_args args) {
|
||||
FMT_FUNC auto vsystem_error(int error_code, string_view fmt, format_args args)
|
||||
-> std::system_error {
|
||||
auto ec = std::error_code(error_code, std::generic_category());
|
||||
return std::system_error(ec, vformat(fmt, args));
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename F> inline bool operator==(basic_fp<F> x, basic_fp<F> y) {
|
||||
template <typename F>
|
||||
inline auto operator==(basic_fp<F> x, basic_fp<F> y) -> bool {
|
||||
return x.f == y.f && x.e == y.e;
|
||||
}
|
||||
|
||||
// Compilers should be able to optimize this into the ror instruction.
|
||||
FMT_CONSTEXPR inline uint32_t rotr(uint32_t n, uint32_t r) noexcept {
|
||||
FMT_CONSTEXPR inline auto rotr(uint32_t n, uint32_t r) noexcept -> uint32_t {
|
||||
r &= 31;
|
||||
return (n >> r) | (n << (32 - r));
|
||||
}
|
||||
FMT_CONSTEXPR inline uint64_t rotr(uint64_t n, uint32_t r) noexcept {
|
||||
FMT_CONSTEXPR inline auto rotr(uint64_t n, uint32_t r) noexcept -> uint64_t {
|
||||
r &= 63;
|
||||
return (n >> r) | (n << (64 - r));
|
||||
}
|
||||
@@ -170,14 +171,14 @@ FMT_CONSTEXPR inline uint64_t rotr(uint64_t n, uint32_t r) noexcept {
|
||||
namespace dragonbox {
|
||||
// Computes upper 64 bits of multiplication of a 32-bit unsigned integer and a
|
||||
// 64-bit unsigned integer.
|
||||
inline uint64_t umul96_upper64(uint32_t x, uint64_t y) noexcept {
|
||||
inline auto umul96_upper64(uint32_t x, uint64_t y) noexcept -> uint64_t {
|
||||
return umul128_upper64(static_cast<uint64_t>(x) << 32, y);
|
||||
}
|
||||
|
||||
// Computes lower 128 bits of multiplication of a 64-bit unsigned integer and a
|
||||
// 128-bit unsigned integer.
|
||||
inline uint128_fallback umul192_lower128(uint64_t x,
|
||||
uint128_fallback y) noexcept {
|
||||
inline auto umul192_lower128(uint64_t x, uint128_fallback y) noexcept
|
||||
-> uint128_fallback {
|
||||
uint64_t high = x * y.high();
|
||||
uint128_fallback high_low = umul128(x, y.low());
|
||||
return {high + high_low.high(), high_low.low()};
|
||||
@@ -185,12 +186,12 @@ inline uint128_fallback umul192_lower128(uint64_t x,
|
||||
|
||||
// Computes lower 64 bits of multiplication of a 32-bit unsigned integer and a
|
||||
// 64-bit unsigned integer.
|
||||
inline uint64_t umul96_lower64(uint32_t x, uint64_t y) noexcept {
|
||||
inline auto umul96_lower64(uint32_t x, uint64_t y) noexcept -> uint64_t {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
// Various fast log computations.
|
||||
inline int floor_log10_pow2_minus_log10_4_over_3(int e) noexcept {
|
||||
inline auto floor_log10_pow2_minus_log10_4_over_3(int e) noexcept -> int {
|
||||
FMT_ASSERT(e <= 2936 && e >= -2985, "too large exponent");
|
||||
return (e * 631305 - 261663) >> 21;
|
||||
}
|
||||
@@ -204,7 +205,7 @@ FMT_INLINE_VARIABLE constexpr struct {
|
||||
// divisible by pow(10, N).
|
||||
// Precondition: n <= pow(10, N + 1).
|
||||
template <int N>
|
||||
bool check_divisibility_and_divide_by_pow10(uint32_t& n) noexcept {
|
||||
auto check_divisibility_and_divide_by_pow10(uint32_t& n) noexcept -> bool {
|
||||
// The numbers below are chosen such that:
|
||||
// 1. floor(n/d) = floor(nm / 2^k) where d=10 or d=100,
|
||||
// 2. nm mod 2^k < m if and only if n is divisible by d,
|
||||
@@ -229,7 +230,7 @@ bool check_divisibility_and_divide_by_pow10(uint32_t& n) noexcept {
|
||||
|
||||
// Computes floor(n / pow(10, N)) for small n and N.
|
||||
// Precondition: n <= pow(10, N + 1).
|
||||
template <int N> uint32_t small_division_by_pow10(uint32_t n) noexcept {
|
||||
template <int N> auto small_division_by_pow10(uint32_t n) noexcept -> uint32_t {
|
||||
constexpr auto info = div_small_pow10_infos[N - 1];
|
||||
FMT_ASSERT(n <= info.divisor * 10, "n is too large");
|
||||
constexpr uint32_t magic_number =
|
||||
@@ -238,12 +239,12 @@ template <int N> uint32_t small_division_by_pow10(uint32_t n) noexcept {
|
||||
}
|
||||
|
||||
// Computes floor(n / 10^(kappa + 1)) (float)
|
||||
inline uint32_t divide_by_10_to_kappa_plus_1(uint32_t n) noexcept {
|
||||
inline auto divide_by_10_to_kappa_plus_1(uint32_t n) noexcept -> uint32_t {
|
||||
// 1374389535 = ceil(2^37/100)
|
||||
return static_cast<uint32_t>((static_cast<uint64_t>(n) * 1374389535) >> 37);
|
||||
}
|
||||
// Computes floor(n / 10^(kappa + 1)) (double)
|
||||
inline uint64_t divide_by_10_to_kappa_plus_1(uint64_t n) noexcept {
|
||||
inline auto divide_by_10_to_kappa_plus_1(uint64_t n) noexcept -> uint64_t {
|
||||
// 2361183241434822607 = ceil(2^(64+7)/1000)
|
||||
return umul128_upper64(n, 2361183241434822607ull) >> 7;
|
||||
}
|
||||
@@ -255,7 +256,7 @@ template <> struct cache_accessor<float> {
|
||||
using carrier_uint = float_info<float>::carrier_uint;
|
||||
using cache_entry_type = uint64_t;
|
||||
|
||||
static uint64_t get_cached_power(int k) noexcept {
|
||||
static auto get_cached_power(int k) noexcept -> uint64_t {
|
||||
FMT_ASSERT(k >= float_info<float>::min_k && k <= float_info<float>::max_k,
|
||||
"k is out of range");
|
||||
static constexpr const uint64_t pow10_significands[] = {
|
||||
@@ -297,20 +298,23 @@ template <> struct cache_accessor<float> {
|
||||
bool is_integer;
|
||||
};
|
||||
|
||||
static compute_mul_result compute_mul(
|
||||
carrier_uint u, const cache_entry_type& cache) noexcept {
|
||||
static auto compute_mul(carrier_uint u,
|
||||
const cache_entry_type& cache) noexcept
|
||||
-> compute_mul_result {
|
||||
auto r = umul96_upper64(u, cache);
|
||||
return {static_cast<carrier_uint>(r >> 32),
|
||||
static_cast<carrier_uint>(r) == 0};
|
||||
}
|
||||
|
||||
static uint32_t compute_delta(const cache_entry_type& cache,
|
||||
int beta) noexcept {
|
||||
static auto compute_delta(const cache_entry_type& cache, int beta) noexcept
|
||||
-> uint32_t {
|
||||
return static_cast<uint32_t>(cache >> (64 - 1 - beta));
|
||||
}
|
||||
|
||||
static compute_mul_parity_result compute_mul_parity(
|
||||
carrier_uint two_f, const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_mul_parity(carrier_uint two_f,
|
||||
const cache_entry_type& cache,
|
||||
int beta) noexcept
|
||||
-> compute_mul_parity_result {
|
||||
FMT_ASSERT(beta >= 1, "");
|
||||
FMT_ASSERT(beta < 64, "");
|
||||
|
||||
@@ -319,22 +323,22 @@ template <> struct cache_accessor<float> {
|
||||
static_cast<uint32_t>(r >> (32 - beta)) == 0};
|
||||
}
|
||||
|
||||
static carrier_uint compute_left_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_left_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept -> carrier_uint {
|
||||
return static_cast<carrier_uint>(
|
||||
(cache - (cache >> (num_significand_bits<float>() + 2))) >>
|
||||
(64 - num_significand_bits<float>() - 1 - beta));
|
||||
}
|
||||
|
||||
static carrier_uint compute_right_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_right_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept -> carrier_uint {
|
||||
return static_cast<carrier_uint>(
|
||||
(cache + (cache >> (num_significand_bits<float>() + 1))) >>
|
||||
(64 - num_significand_bits<float>() - 1 - beta));
|
||||
}
|
||||
|
||||
static carrier_uint compute_round_up_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_round_up_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept -> carrier_uint {
|
||||
return (static_cast<carrier_uint>(
|
||||
cache >> (64 - num_significand_bits<float>() - 2 - beta)) +
|
||||
1) /
|
||||
@@ -346,7 +350,7 @@ template <> struct cache_accessor<double> {
|
||||
using carrier_uint = float_info<double>::carrier_uint;
|
||||
using cache_entry_type = uint128_fallback;
|
||||
|
||||
static uint128_fallback get_cached_power(int k) noexcept {
|
||||
static auto get_cached_power(int k) noexcept -> uint128_fallback {
|
||||
FMT_ASSERT(k >= float_info<double>::min_k && k <= float_info<double>::max_k,
|
||||
"k is out of range");
|
||||
|
||||
@@ -985,8 +989,7 @@ template <> struct cache_accessor<double> {
|
||||
{0xe0accfa875af45a7, 0x93eb1b80a33b8606},
|
||||
{0x8c6c01c9498d8b88, 0xbc72f130660533c4},
|
||||
{0xaf87023b9bf0ee6a, 0xeb8fad7c7f8680b5},
|
||||
{ 0xdb68c2ca82ed2a05,
|
||||
0xa67398db9f6820e2 }
|
||||
{0xdb68c2ca82ed2a05, 0xa67398db9f6820e2},
|
||||
#else
|
||||
{0xff77b1fcbebcdc4f, 0x25e8e89c13bb0f7b},
|
||||
{0xce5d73ff402d98e3, 0xfb0a3d212dc81290},
|
||||
@@ -1071,19 +1074,22 @@ template <> struct cache_accessor<double> {
|
||||
bool is_integer;
|
||||
};
|
||||
|
||||
static compute_mul_result compute_mul(
|
||||
carrier_uint u, const cache_entry_type& cache) noexcept {
|
||||
static auto compute_mul(carrier_uint u,
|
||||
const cache_entry_type& cache) noexcept
|
||||
-> compute_mul_result {
|
||||
auto r = umul192_upper128(u, cache);
|
||||
return {r.high(), r.low() == 0};
|
||||
}
|
||||
|
||||
static uint32_t compute_delta(cache_entry_type const& cache,
|
||||
int beta) noexcept {
|
||||
static auto compute_delta(cache_entry_type const& cache, int beta) noexcept
|
||||
-> uint32_t {
|
||||
return static_cast<uint32_t>(cache.high() >> (64 - 1 - beta));
|
||||
}
|
||||
|
||||
static compute_mul_parity_result compute_mul_parity(
|
||||
carrier_uint two_f, const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_mul_parity(carrier_uint two_f,
|
||||
const cache_entry_type& cache,
|
||||
int beta) noexcept
|
||||
-> compute_mul_parity_result {
|
||||
FMT_ASSERT(beta >= 1, "");
|
||||
FMT_ASSERT(beta < 64, "");
|
||||
|
||||
@@ -1092,35 +1098,35 @@ template <> struct cache_accessor<double> {
|
||||
((r.high() << beta) | (r.low() >> (64 - beta))) == 0};
|
||||
}
|
||||
|
||||
static carrier_uint compute_left_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_left_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept -> carrier_uint {
|
||||
return (cache.high() -
|
||||
(cache.high() >> (num_significand_bits<double>() + 2))) >>
|
||||
(64 - num_significand_bits<double>() - 1 - beta);
|
||||
}
|
||||
|
||||
static carrier_uint compute_right_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_right_endpoint_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept -> carrier_uint {
|
||||
return (cache.high() +
|
||||
(cache.high() >> (num_significand_bits<double>() + 1))) >>
|
||||
(64 - num_significand_bits<double>() - 1 - beta);
|
||||
}
|
||||
|
||||
static carrier_uint compute_round_up_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept {
|
||||
static auto compute_round_up_for_shorter_interval_case(
|
||||
const cache_entry_type& cache, int beta) noexcept -> carrier_uint {
|
||||
return ((cache.high() >> (64 - num_significand_bits<double>() - 2 - beta)) +
|
||||
1) /
|
||||
2;
|
||||
}
|
||||
};
|
||||
|
||||
FMT_FUNC uint128_fallback get_cached_power(int k) noexcept {
|
||||
FMT_FUNC auto get_cached_power(int k) noexcept -> uint128_fallback {
|
||||
return cache_accessor<double>::get_cached_power(k);
|
||||
}
|
||||
|
||||
// Various integer checks
|
||||
template <typename T>
|
||||
bool is_left_endpoint_integer_shorter_interval(int exponent) noexcept {
|
||||
auto is_left_endpoint_integer_shorter_interval(int exponent) noexcept -> bool {
|
||||
const int case_shorter_interval_left_endpoint_lower_threshold = 2;
|
||||
const int case_shorter_interval_left_endpoint_upper_threshold = 3;
|
||||
return exponent >= case_shorter_interval_left_endpoint_lower_threshold &&
|
||||
@@ -1128,16 +1134,12 @@ bool is_left_endpoint_integer_shorter_interval(int exponent) noexcept {
|
||||
}
|
||||
|
||||
// Remove trailing zeros from n and return the number of zeros removed (float)
|
||||
FMT_INLINE int remove_trailing_zeros(uint32_t& n) noexcept {
|
||||
FMT_INLINE int remove_trailing_zeros(uint32_t& n, int s = 0) noexcept {
|
||||
FMT_ASSERT(n != 0, "");
|
||||
// Modular inverse of 5 (mod 2^32): (mod_inv_5 * 5) mod 2^32 = 1.
|
||||
// See https://github.com/fmtlib/fmt/issues/3163 for more details.
|
||||
const uint32_t mod_inv_5 = 0xcccccccd;
|
||||
// Casts are needed to workaround a bug in MSVC 19.22 and older.
|
||||
const uint32_t mod_inv_25 =
|
||||
static_cast<uint32_t>(uint64_t(mod_inv_5) * mod_inv_5);
|
||||
constexpr uint32_t mod_inv_5 = 0xcccccccd;
|
||||
constexpr uint32_t mod_inv_25 = 0xc28f5c29; // = mod_inv_5 * mod_inv_5
|
||||
|
||||
int s = 0;
|
||||
while (true) {
|
||||
auto q = rotr(n * mod_inv_25, 2);
|
||||
if (q > max_value<uint32_t>() / 100) break;
|
||||
@@ -1162,32 +1164,17 @@ FMT_INLINE int remove_trailing_zeros(uint64_t& n) noexcept {
|
||||
|
||||
// Is n is divisible by 10^8?
|
||||
if ((nm.high() & ((1ull << (90 - 64)) - 1)) == 0 && nm.low() < magic_number) {
|
||||
// If yes, work with the quotient.
|
||||
// If yes, work with the quotient...
|
||||
auto n32 = static_cast<uint32_t>(nm.high() >> (90 - 64));
|
||||
|
||||
const uint32_t mod_inv_5 = 0xcccccccd;
|
||||
const uint32_t mod_inv_25 = mod_inv_5 * mod_inv_5;
|
||||
|
||||
int s = 8;
|
||||
while (true) {
|
||||
auto q = rotr(n32 * mod_inv_25, 2);
|
||||
if (q > max_value<uint32_t>() / 100) break;
|
||||
n32 = q;
|
||||
s += 2;
|
||||
}
|
||||
auto q = rotr(n32 * mod_inv_5, 1);
|
||||
if (q <= max_value<uint32_t>() / 10) {
|
||||
n32 = q;
|
||||
s |= 1;
|
||||
}
|
||||
|
||||
// ... and use the 32 bit variant of the function
|
||||
int s = remove_trailing_zeros(n32, 8);
|
||||
n = n32;
|
||||
return s;
|
||||
}
|
||||
|
||||
// If n is not divisible by 10^8, work with n itself.
|
||||
const uint64_t mod_inv_5 = 0xcccccccccccccccd;
|
||||
const uint64_t mod_inv_25 = mod_inv_5 * mod_inv_5;
|
||||
constexpr uint64_t mod_inv_5 = 0xcccccccccccccccd;
|
||||
constexpr uint64_t mod_inv_25 = 0x8f5c28f5c28f5c29; // mod_inv_5 * mod_inv_5
|
||||
|
||||
int s = 0;
|
||||
while (true) {
|
||||
@@ -1253,7 +1240,7 @@ FMT_INLINE decimal_fp<T> shorter_interval_case(int exponent) noexcept {
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
template <typename T> decimal_fp<T> to_decimal(T x) noexcept {
|
||||
template <typename T> auto to_decimal(T x) noexcept -> decimal_fp<T> {
|
||||
// Step 1: integer promotion & Schubfach multiplier calculation.
|
||||
|
||||
using carrier_uint = typename float_info<T>::carrier_uint;
|
||||
@@ -1392,15 +1379,15 @@ template <> struct formatter<detail::bigint> {
|
||||
for (auto i = n.bigits_.size(); i > 0; --i) {
|
||||
auto value = n.bigits_[i - 1u];
|
||||
if (first) {
|
||||
out = format_to(out, FMT_STRING("{:x}"), value);
|
||||
out = fmt::format_to(out, FMT_STRING("{:x}"), value);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
out = format_to(out, FMT_STRING("{:08x}"), value);
|
||||
out = fmt::format_to(out, FMT_STRING("{:08x}"), value);
|
||||
}
|
||||
if (n.exp_ > 0)
|
||||
out = format_to(out, FMT_STRING("p{}"),
|
||||
n.exp_ * detail::bigint::bigit_bits);
|
||||
out = fmt::format_to(out, FMT_STRING("p{}"),
|
||||
n.exp_ * detail::bigint::bigit_bits);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
@@ -1436,7 +1423,7 @@ FMT_FUNC void report_system_error(int error_code,
|
||||
report_error(format_system_error, error_code, message);
|
||||
}
|
||||
|
||||
FMT_FUNC std::string vformat(string_view fmt, format_args args) {
|
||||
FMT_FUNC auto vformat(string_view fmt, format_args args) -> std::string {
|
||||
// Don't optimize the "{}" case to keep the binary size small and because it
|
||||
// can be better optimized in fmt::format anyway.
|
||||
auto buffer = memory_buffer();
|
||||
@@ -1445,33 +1432,43 @@ FMT_FUNC std::string vformat(string_view fmt, format_args args) {
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
#ifndef _WIN32
|
||||
FMT_FUNC bool write_console(std::FILE*, string_view) { return false; }
|
||||
#if !defined(_WIN32) || defined(FMT_WINDOWS_NO_WCHAR)
|
||||
FMT_FUNC auto write_console(int, string_view) -> bool { return false; }
|
||||
FMT_FUNC auto write_console(std::FILE*, string_view) -> bool { return false; }
|
||||
#else
|
||||
using dword = conditional_t<sizeof(long) == 4, unsigned long, unsigned>;
|
||||
extern "C" __declspec(dllimport) int __stdcall WriteConsoleW( //
|
||||
void*, const void*, dword, dword*, void*);
|
||||
|
||||
FMT_FUNC bool write_console(std::FILE* f, string_view text) {
|
||||
auto fd = _fileno(f);
|
||||
if (!_isatty(fd)) return false;
|
||||
FMT_FUNC bool write_console(int fd, string_view text) {
|
||||
auto u16 = utf8_to_utf16(text);
|
||||
auto written = dword();
|
||||
return WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)), u16.c_str(),
|
||||
static_cast<uint32_t>(u16.size()), &written, nullptr);
|
||||
static_cast<dword>(u16.size()), nullptr, nullptr) != 0;
|
||||
}
|
||||
|
||||
FMT_FUNC auto write_console(std::FILE* f, string_view text) -> bool {
|
||||
return write_console(_fileno(f), text);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// Print assuming legacy (non-Unicode) encoding.
|
||||
FMT_FUNC void vprint_mojibake(std::FILE* f, string_view fmt, format_args args) {
|
||||
auto buffer = memory_buffer();
|
||||
detail::vformat_to(buffer, fmt,
|
||||
basic_format_args<buffer_context<char>>(args));
|
||||
fwrite_fully(buffer.data(), 1, buffer.size(), f);
|
||||
detail::vformat_to(buffer, fmt, args);
|
||||
fwrite_fully(buffer.data(), buffer.size(), f);
|
||||
}
|
||||
#endif
|
||||
|
||||
FMT_FUNC void print(std::FILE* f, string_view text) {
|
||||
if (!write_console(f, text)) fwrite_fully(text.data(), 1, text.size(), f);
|
||||
#ifdef _WIN32
|
||||
int fd = _fileno(f);
|
||||
if (_isatty(fd)) {
|
||||
std::fflush(f);
|
||||
if (write_console(fd, text)) return;
|
||||
}
|
||||
#endif
|
||||
fwrite_fully(text.data(), text.size(), f);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
|
||||
+424
-624
File diff suppressed because it is too large
Load Diff
+29
-25
@@ -13,12 +13,14 @@
|
||||
#include <cstdio>
|
||||
#include <system_error> // std::system_error
|
||||
|
||||
#if defined __APPLE__ || defined(__FreeBSD__)
|
||||
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
|
||||
#endif
|
||||
|
||||
#include "format.h"
|
||||
|
||||
#if defined __APPLE__ || defined(__FreeBSD__)
|
||||
# if FMT_HAS_INCLUDE(<xlocale.h>)
|
||||
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef FMT_USE_FCNTL
|
||||
// UWP doesn't provide _pipe.
|
||||
# if FMT_HAS_INCLUDE("winapifamily.h")
|
||||
@@ -46,6 +48,7 @@
|
||||
|
||||
// Calls to system functions are wrapped in FMT_SYSTEM for testability.
|
||||
#ifdef FMT_SYSTEM
|
||||
# define FMT_HAS_SYSTEM
|
||||
# define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
|
||||
#else
|
||||
# define FMT_SYSTEM(call) ::call
|
||||
@@ -114,7 +117,7 @@ template <typename Char> class basic_cstring_view {
|
||||
basic_cstring_view(const std::basic_string<Char>& s) : data_(s.c_str()) {}
|
||||
|
||||
/** Returns the pointer to a C string. */
|
||||
const Char* c_str() const { return data_; }
|
||||
auto c_str() const -> const Char* { return data_; }
|
||||
};
|
||||
|
||||
using cstring_view = basic_cstring_view<char>;
|
||||
@@ -123,10 +126,10 @@ using wcstring_view = basic_cstring_view<wchar_t>;
|
||||
#ifdef _WIN32
|
||||
FMT_API const std::error_category& system_category() noexcept;
|
||||
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
namespace detail {
|
||||
FMT_API void format_windows_error(buffer<char>& out, int error_code,
|
||||
const char* message) noexcept;
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
}
|
||||
|
||||
FMT_API std::system_error vwindows_error(int error_code, string_view format_str,
|
||||
format_args args);
|
||||
@@ -169,7 +172,7 @@ std::system_error windows_error(int error_code, string_view message,
|
||||
// Can be used to report errors from destructors.
|
||||
FMT_API void report_windows_error(int error_code, const char* message) noexcept;
|
||||
#else
|
||||
inline const std::error_category& system_category() noexcept {
|
||||
inline auto system_category() noexcept -> const std::error_category& {
|
||||
return std::system_category();
|
||||
}
|
||||
#endif // _WIN32
|
||||
@@ -206,7 +209,7 @@ class buffered_file {
|
||||
other.file_ = nullptr;
|
||||
}
|
||||
|
||||
buffered_file& operator=(buffered_file&& other) {
|
||||
auto operator=(buffered_file&& other) -> buffered_file& {
|
||||
close();
|
||||
file_ = other.file_;
|
||||
other.file_ = nullptr;
|
||||
@@ -220,9 +223,9 @@ class buffered_file {
|
||||
FMT_API void close();
|
||||
|
||||
// Returns the pointer to a FILE object representing this file.
|
||||
FILE* get() const noexcept { return file_; }
|
||||
auto get() const noexcept -> FILE* { return file_; }
|
||||
|
||||
FMT_API int descriptor() const;
|
||||
FMT_API auto descriptor() const -> int;
|
||||
|
||||
void vprint(string_view format_str, format_args args) {
|
||||
fmt::vprint(file_, format_str, args);
|
||||
@@ -272,7 +275,7 @@ class FMT_API file {
|
||||
file(file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; }
|
||||
|
||||
// Move assignment is not noexcept because close may throw.
|
||||
file& operator=(file&& other) {
|
||||
auto operator=(file&& other) -> file& {
|
||||
close();
|
||||
fd_ = other.fd_;
|
||||
other.fd_ = -1;
|
||||
@@ -283,24 +286,24 @@ class FMT_API file {
|
||||
~file() noexcept;
|
||||
|
||||
// Returns the file descriptor.
|
||||
int descriptor() const noexcept { return fd_; }
|
||||
auto descriptor() const noexcept -> int { return fd_; }
|
||||
|
||||
// Closes the file.
|
||||
void close();
|
||||
|
||||
// Returns the file size. The size has signed type for consistency with
|
||||
// stat::st_size.
|
||||
long long size() const;
|
||||
auto size() const -> long long;
|
||||
|
||||
// Attempts to read count bytes from the file into the specified buffer.
|
||||
size_t read(void* buffer, size_t count);
|
||||
auto read(void* buffer, size_t count) -> size_t;
|
||||
|
||||
// Attempts to write count bytes from the specified buffer to the file.
|
||||
size_t write(const void* buffer, size_t count);
|
||||
auto write(const void* buffer, size_t count) -> size_t;
|
||||
|
||||
// Duplicates a file descriptor with the dup function and returns
|
||||
// the duplicate as a file object.
|
||||
static file dup(int fd);
|
||||
static auto dup(int fd) -> file;
|
||||
|
||||
// Makes fd be the copy of this file descriptor, closing fd first if
|
||||
// necessary.
|
||||
@@ -312,11 +315,12 @@ class FMT_API file {
|
||||
|
||||
// Creates a pipe setting up read_end and write_end file objects for reading
|
||||
// and writing respectively.
|
||||
// DEPRECATED! Taking files as out parameters is deprecated.
|
||||
static void pipe(file& read_end, file& write_end);
|
||||
|
||||
// Creates a buffered_file object associated with this file and detaches
|
||||
// this file object from the file.
|
||||
buffered_file fdopen(const char* mode);
|
||||
auto fdopen(const char* mode) -> buffered_file;
|
||||
|
||||
# if defined(_WIN32) && !defined(__MINGW32__)
|
||||
// Opens a file and constructs a file object representing this file by
|
||||
@@ -326,14 +330,14 @@ class FMT_API file {
|
||||
};
|
||||
|
||||
// Returns the memory page size.
|
||||
long getpagesize();
|
||||
auto getpagesize() -> long;
|
||||
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
struct buffer_size {
|
||||
buffer_size() = default;
|
||||
size_t value = 0;
|
||||
buffer_size operator=(size_t val) const {
|
||||
auto operator=(size_t val) const -> buffer_size {
|
||||
auto bs = buffer_size();
|
||||
bs.value = val;
|
||||
return bs;
|
||||
@@ -387,7 +391,7 @@ class file_buffer final : public buffer<char> {
|
||||
}
|
||||
};
|
||||
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
} // namespace detail
|
||||
|
||||
// Added {} below to work around default constructor error known to
|
||||
// occur in Xcode versions 7.2.1 and 8.2.1.
|
||||
@@ -410,7 +414,7 @@ class FMT_API ostream {
|
||||
void flush() { buffer_.flush(); }
|
||||
|
||||
template <typename... T>
|
||||
friend ostream output_file(cstring_view path, T... params);
|
||||
friend auto output_file(cstring_view path, T... params) -> ostream;
|
||||
|
||||
void close() { buffer_.close(); }
|
||||
|
||||
@@ -419,7 +423,7 @@ class FMT_API ostream {
|
||||
output to the file.
|
||||
*/
|
||||
template <typename... T> void print(format_string<T...> fmt, T&&... args) {
|
||||
vformat_to(detail::buffer_appender<char>(buffer_), fmt,
|
||||
vformat_to(std::back_inserter(buffer_), fmt,
|
||||
fmt::make_format_args(args...));
|
||||
}
|
||||
};
|
||||
@@ -440,7 +444,7 @@ class FMT_API ostream {
|
||||
\endrst
|
||||
*/
|
||||
template <typename... T>
|
||||
inline ostream output_file(cstring_view path, T... params) {
|
||||
inline auto output_file(cstring_view path, T... params) -> ostream {
|
||||
return {path, detail::ostream_params(params...)};
|
||||
}
|
||||
#endif // FMT_USE_FCNTL
|
||||
|
||||
+69
-33
@@ -10,19 +10,50 @@
|
||||
|
||||
#include <fstream> // std::filebuf
|
||||
|
||||
#if defined(_WIN32) && defined(__GLIBCXX__)
|
||||
# include <ext/stdio_filebuf.h>
|
||||
# include <ext/stdio_sync_filebuf.h>
|
||||
#elif defined(_WIN32) && defined(_LIBCPP_VERSION)
|
||||
# include <__std_stream>
|
||||
#ifdef _WIN32
|
||||
# ifdef __GLIBCXX__
|
||||
# include <ext/stdio_filebuf.h>
|
||||
# include <ext/stdio_sync_filebuf.h>
|
||||
# endif
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#include "format.h"
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Streambuf> class formatbuf : public Streambuf {
|
||||
private:
|
||||
using char_type = typename Streambuf::char_type;
|
||||
using streamsize = decltype(std::declval<Streambuf>().sputn(nullptr, 0));
|
||||
using int_type = typename Streambuf::int_type;
|
||||
using traits_type = typename Streambuf::traits_type;
|
||||
|
||||
buffer<char_type>& buffer_;
|
||||
|
||||
public:
|
||||
explicit formatbuf(buffer<char_type>& buf) : buffer_(buf) {}
|
||||
|
||||
protected:
|
||||
// The put area is always empty. This makes the implementation simpler and has
|
||||
// the advantage that the streambuf and the buffer are always in sync and
|
||||
// sputc never writes into uninitialized memory. A disadvantage is that each
|
||||
// call to sputc always results in a (virtual) call to overflow. There is no
|
||||
// disadvantage here for sputn since this always results in a call to xsputn.
|
||||
|
||||
auto overflow(int_type ch) -> int_type override {
|
||||
if (!traits_type::eq_int_type(ch, traits_type::eof()))
|
||||
buffer_.push_back(static_cast<char_type>(ch));
|
||||
return ch;
|
||||
}
|
||||
|
||||
auto xsputn(const char_type* s, streamsize count) -> streamsize override {
|
||||
buffer_.append(s, s + count);
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
// Generate a unique explicit instantion in every translation unit using a tag
|
||||
// type in an anonymous namespace.
|
||||
namespace {
|
||||
@@ -37,36 +68,40 @@ class file_access {
|
||||
template class file_access<file_access_tag, std::filebuf,
|
||||
&std::filebuf::_Myfile>;
|
||||
auto get_file(std::filebuf&) -> FILE*;
|
||||
#elif defined(_WIN32) && defined(_LIBCPP_VERSION)
|
||||
template class file_access<file_access_tag, std::__stdoutbuf<char>,
|
||||
&std::__stdoutbuf<char>::__file_>;
|
||||
auto get_file(std::__stdoutbuf<char>&) -> FILE*;
|
||||
#endif
|
||||
|
||||
inline bool write_ostream_unicode(std::ostream& os, fmt::string_view data) {
|
||||
inline auto write_ostream_unicode(std::ostream& os, fmt::string_view data)
|
||||
-> bool {
|
||||
FILE* f = nullptr;
|
||||
#if FMT_MSC_VERSION
|
||||
if (auto* buf = dynamic_cast<std::filebuf*>(os.rdbuf()))
|
||||
if (FILE* f = get_file(*buf)) return write_console(f, data);
|
||||
f = get_file(*buf);
|
||||
else
|
||||
return false;
|
||||
#elif defined(_WIN32) && defined(__GLIBCXX__)
|
||||
auto* rdbuf = os.rdbuf();
|
||||
FILE* c_file;
|
||||
if (auto* sfbuf = dynamic_cast<__gnu_cxx::stdio_sync_filebuf<char>*>(rdbuf))
|
||||
c_file = sfbuf->file();
|
||||
f = sfbuf->file();
|
||||
else if (auto* fbuf = dynamic_cast<__gnu_cxx::stdio_filebuf<char>*>(rdbuf))
|
||||
c_file = fbuf->file();
|
||||
f = fbuf->file();
|
||||
else
|
||||
return false;
|
||||
if (c_file) return write_console(c_file, data);
|
||||
#elif defined(_WIN32) && defined(_LIBCPP_VERSION)
|
||||
if (auto* buf = dynamic_cast<std::__stdoutbuf<char>*>(os.rdbuf()))
|
||||
if (FILE* f = get_file(*buf)) return write_console(f, data);
|
||||
#else
|
||||
ignore_unused(os, data);
|
||||
ignore_unused(os, data, f);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
if (f) {
|
||||
int fd = _fileno(f);
|
||||
if (_isatty(fd)) {
|
||||
os.flush();
|
||||
return write_console(fd, data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
inline bool write_ostream_unicode(std::wostream&,
|
||||
fmt::basic_string_view<wchar_t>) {
|
||||
inline auto write_ostream_unicode(std::wostream&,
|
||||
fmt::basic_string_view<wchar_t>) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -87,18 +122,19 @@ void write_buffer(std::basic_ostream<Char>& os, buffer<Char>& buf) {
|
||||
}
|
||||
|
||||
template <typename Char, typename T>
|
||||
void format_value(buffer<Char>& buf, const T& value,
|
||||
locale_ref loc = locale_ref()) {
|
||||
void format_value(buffer<Char>& buf, const T& value) {
|
||||
auto&& format_buf = formatbuf<std::basic_streambuf<Char>>(buf);
|
||||
auto&& output = std::basic_ostream<Char>(&format_buf);
|
||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
if (loc) output.imbue(loc.get<std::locale>());
|
||||
output.imbue(std::locale::classic()); // The default is always unlocalized.
|
||||
#endif
|
||||
output << value;
|
||||
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||
}
|
||||
|
||||
template <typename T> struct streamed_view { const T& value; };
|
||||
template <typename T> struct streamed_view {
|
||||
const T& value;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -111,7 +147,7 @@ struct basic_ostream_formatter : formatter<basic_string_view<Char>, Char> {
|
||||
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx) const
|
||||
-> OutputIt {
|
||||
auto buffer = basic_memory_buffer<Char>();
|
||||
detail::format_value(buffer, value, ctx.locale());
|
||||
detail::format_value(buffer, value);
|
||||
return formatter<basic_string_view<Char>, Char>::format(
|
||||
{buffer.data(), buffer.size()}, ctx);
|
||||
}
|
||||
@@ -140,7 +176,7 @@ struct formatter<detail::streamed_view<T>, Char>
|
||||
\endrst
|
||||
*/
|
||||
template <typename T>
|
||||
auto streamed(const T& value) -> detail::streamed_view<T> {
|
||||
constexpr auto streamed(const T& value) -> detail::streamed_view<T> {
|
||||
return {value};
|
||||
}
|
||||
|
||||
@@ -155,7 +191,7 @@ inline void vprint_directly(std::ostream& os, string_view format_str,
|
||||
|
||||
} // namespace detail
|
||||
|
||||
FMT_MODULE_EXPORT template <typename Char>
|
||||
FMT_EXPORT template <typename Char>
|
||||
void vprint(std::basic_ostream<Char>& os,
|
||||
basic_string_view<type_identity_t<Char>> format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||
@@ -174,7 +210,7 @@ void vprint(std::basic_ostream<Char>& os,
|
||||
fmt::print(cerr, "Don't {}!", "panic");
|
||||
\endrst
|
||||
*/
|
||||
FMT_MODULE_EXPORT template <typename... T>
|
||||
FMT_EXPORT template <typename... T>
|
||||
void print(std::ostream& os, format_string<T...> fmt, T&&... args) {
|
||||
const auto& vargs = fmt::make_format_args(args...);
|
||||
if (detail::is_utf8())
|
||||
@@ -183,7 +219,7 @@ void print(std::ostream& os, format_string<T...> fmt, T&&... args) {
|
||||
detail::vprint_directly(os, fmt, vargs);
|
||||
}
|
||||
|
||||
FMT_MODULE_EXPORT
|
||||
FMT_EXPORT
|
||||
template <typename... Args>
|
||||
void print(std::wostream& os,
|
||||
basic_format_string<wchar_t, type_identity_t<Args>...> fmt,
|
||||
@@ -191,12 +227,12 @@ void print(std::wostream& os,
|
||||
vprint(os, fmt, fmt::make_format_args<buffer_context<wchar_t>>(args...));
|
||||
}
|
||||
|
||||
FMT_MODULE_EXPORT template <typename... T>
|
||||
FMT_EXPORT template <typename... T>
|
||||
void println(std::ostream& os, format_string<T...> fmt, T&&... args) {
|
||||
fmt::print(os, "{}\n", fmt::format(fmt, std::forward<T>(args)...));
|
||||
}
|
||||
|
||||
FMT_MODULE_EXPORT
|
||||
FMT_EXPORT
|
||||
template <typename... Args>
|
||||
void println(std::wostream& os,
|
||||
basic_format_string<wchar_t, type_identity_t<Args>...> fmt,
|
||||
|
||||
+131
-135
@@ -16,22 +16,22 @@
|
||||
FMT_BEGIN_NAMESPACE
|
||||
FMT_BEGIN_EXPORT
|
||||
|
||||
template <typename T> struct printf_formatter { printf_formatter() = delete; };
|
||||
|
||||
template <typename Char>
|
||||
class basic_printf_parse_context : public basic_format_parse_context<Char> {
|
||||
using basic_format_parse_context<Char>::basic_format_parse_context;
|
||||
template <typename T> struct printf_formatter {
|
||||
printf_formatter() = delete;
|
||||
};
|
||||
|
||||
template <typename OutputIt, typename Char> class basic_printf_context {
|
||||
template <typename Char> class basic_printf_context {
|
||||
private:
|
||||
OutputIt out_;
|
||||
detail::buffer_appender<Char> out_;
|
||||
basic_format_args<basic_printf_context> args_;
|
||||
|
||||
static_assert(std::is_same<Char, char>::value ||
|
||||
std::is_same<Char, wchar_t>::value,
|
||||
"Unsupported code unit type.");
|
||||
|
||||
public:
|
||||
using char_type = Char;
|
||||
using format_arg = basic_format_arg<basic_printf_context>;
|
||||
using parse_context_type = basic_printf_parse_context<Char>;
|
||||
using parse_context_type = basic_format_parse_context<Char>;
|
||||
template <typename T> using formatter_type = printf_formatter<T>;
|
||||
|
||||
/**
|
||||
@@ -40,75 +40,77 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
||||
stored in the context object so make sure they have appropriate lifetimes.
|
||||
\endrst
|
||||
*/
|
||||
basic_printf_context(OutputIt out,
|
||||
basic_printf_context(detail::buffer_appender<Char> out,
|
||||
basic_format_args<basic_printf_context> args)
|
||||
: out_(out), args_(args) {}
|
||||
|
||||
OutputIt out() { return out_; }
|
||||
void advance_to(OutputIt it) { out_ = it; }
|
||||
auto out() -> detail::buffer_appender<Char> { return out_; }
|
||||
void advance_to(detail::buffer_appender<Char>) {}
|
||||
|
||||
detail::locale_ref locale() { return {}; }
|
||||
auto locale() -> detail::locale_ref { return {}; }
|
||||
|
||||
format_arg arg(int id) const { return args_.get(id); }
|
||||
auto arg(int id) const -> basic_format_arg<basic_printf_context> {
|
||||
return args_.get(id);
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR void on_error(const char* message) {
|
||||
detail::error_handler().on_error(message);
|
||||
}
|
||||
};
|
||||
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
// Checks if a value fits in int - used to avoid warnings about comparing
|
||||
// signed and unsigned integers.
|
||||
template <bool IsSigned> struct int_checker {
|
||||
template <typename T> static bool fits_in_int(T value) {
|
||||
template <typename T> static auto fits_in_int(T value) -> bool {
|
||||
unsigned max = max_value<int>();
|
||||
return value <= max;
|
||||
}
|
||||
static bool fits_in_int(bool) { return true; }
|
||||
static auto fits_in_int(bool) -> bool { return true; }
|
||||
};
|
||||
|
||||
template <> struct int_checker<true> {
|
||||
template <typename T> static bool fits_in_int(T value) {
|
||||
template <typename T> static auto fits_in_int(T value) -> bool {
|
||||
return value >= (std::numeric_limits<int>::min)() &&
|
||||
value <= max_value<int>();
|
||||
}
|
||||
static bool fits_in_int(int) { return true; }
|
||||
static auto fits_in_int(int) -> bool { return true; }
|
||||
};
|
||||
|
||||
class printf_precision_handler {
|
||||
public:
|
||||
struct printf_precision_handler {
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
int operator()(T value) {
|
||||
auto operator()(T value) -> int {
|
||||
if (!int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
|
||||
throw_format_error("number is too big");
|
||||
return (std::max)(static_cast<int>(value), 0);
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
||||
int operator()(T) {
|
||||
auto operator()(T) -> int {
|
||||
throw_format_error("precision is not integer");
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// An argument visitor that returns true iff arg is a zero integer.
|
||||
class is_zero_int {
|
||||
public:
|
||||
struct is_zero_int {
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
bool operator()(T value) {
|
||||
auto operator()(T value) -> bool {
|
||||
return value == 0;
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
||||
bool operator()(T) {
|
||||
auto operator()(T) -> bool {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct make_unsigned_or_bool : std::make_unsigned<T> {};
|
||||
|
||||
template <> struct make_unsigned_or_bool<bool> { using type = bool; };
|
||||
template <> struct make_unsigned_or_bool<bool> {
|
||||
using type = bool;
|
||||
};
|
||||
|
||||
template <typename T, typename Context> class arg_converter {
|
||||
private:
|
||||
@@ -132,22 +134,23 @@ template <typename T, typename Context> class arg_converter {
|
||||
if (const_check(sizeof(target_type) <= sizeof(int))) {
|
||||
// Extra casts are used to silence warnings.
|
||||
if (is_signed) {
|
||||
arg_ = detail::make_arg<Context>(
|
||||
static_cast<int>(static_cast<target_type>(value)));
|
||||
auto n = static_cast<int>(static_cast<target_type>(value));
|
||||
arg_ = detail::make_arg<Context>(n);
|
||||
} else {
|
||||
using unsigned_type = typename make_unsigned_or_bool<target_type>::type;
|
||||
arg_ = detail::make_arg<Context>(
|
||||
static_cast<unsigned>(static_cast<unsigned_type>(value)));
|
||||
auto n = static_cast<unsigned>(static_cast<unsigned_type>(value));
|
||||
arg_ = detail::make_arg<Context>(n);
|
||||
}
|
||||
} else {
|
||||
if (is_signed) {
|
||||
// glibc's printf doesn't sign extend arguments of smaller types:
|
||||
// std::printf("%lld", -42); // prints "4294967254"
|
||||
// but we don't have to do the same because it's a UB.
|
||||
arg_ = detail::make_arg<Context>(static_cast<long long>(value));
|
||||
auto n = static_cast<long long>(value);
|
||||
arg_ = detail::make_arg<Context>(n);
|
||||
} else {
|
||||
arg_ = detail::make_arg<Context>(
|
||||
static_cast<typename make_unsigned_or_bool<U>::type>(value));
|
||||
auto n = static_cast<typename make_unsigned_or_bool<U>::type>(value);
|
||||
arg_ = detail::make_arg<Context>(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,8 +178,8 @@ template <typename Context> class char_converter {
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
void operator()(T value) {
|
||||
arg_ = detail::make_arg<Context>(
|
||||
static_cast<typename Context::char_type>(value));
|
||||
auto c = static_cast<typename Context::char_type>(value);
|
||||
arg_ = detail::make_arg<Context>(c);
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
||||
@@ -186,8 +189,8 @@ template <typename Context> class char_converter {
|
||||
// An argument visitor that return a pointer to a C string if argument is a
|
||||
// string or null otherwise.
|
||||
template <typename Char> struct get_cstring {
|
||||
template <typename T> const Char* operator()(T) { return nullptr; }
|
||||
const Char* operator()(const Char* s) { return s; }
|
||||
template <typename T> auto operator()(T) -> const Char* { return nullptr; }
|
||||
auto operator()(const Char* s) -> const Char* { return s; }
|
||||
};
|
||||
|
||||
// Checks if an argument is a valid printf width specifier and sets
|
||||
@@ -200,7 +203,7 @@ template <typename Char> class printf_width_handler {
|
||||
explicit printf_width_handler(format_specs<Char>& specs) : specs_(specs) {}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
unsigned operator()(T value) {
|
||||
auto operator()(T value) -> unsigned {
|
||||
auto width = static_cast<uint32_or_64_or_128_t<T>>(value);
|
||||
if (detail::is_negative(value)) {
|
||||
specs_.align = align::left;
|
||||
@@ -212,7 +215,7 @@ template <typename Char> class printf_width_handler {
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
||||
unsigned operator()(T) {
|
||||
auto operator()(T) -> unsigned {
|
||||
throw_format_error("width is not integer");
|
||||
return 0;
|
||||
}
|
||||
@@ -227,80 +230,85 @@ auto make_arg_formatter(buffer_appender<Char> iter, format_specs<Char>& s)
|
||||
}
|
||||
|
||||
// The ``printf`` argument formatter.
|
||||
template <typename OutputIt, typename Char>
|
||||
template <typename Char>
|
||||
class printf_arg_formatter : public arg_formatter<Char> {
|
||||
private:
|
||||
using base = arg_formatter<Char>;
|
||||
using context_type = basic_printf_context<OutputIt, Char>;
|
||||
using context_type = basic_printf_context<Char>;
|
||||
|
||||
context_type& context_;
|
||||
|
||||
OutputIt write_null_pointer(bool is_string = false) {
|
||||
void write_null_pointer(bool is_string = false) {
|
||||
auto s = this->specs;
|
||||
s.type = presentation_type::none;
|
||||
return write_bytes(this->out, is_string ? "(null)" : "(nil)", s);
|
||||
write_bytes(this->out, is_string ? "(null)" : "(nil)", s);
|
||||
}
|
||||
|
||||
public:
|
||||
printf_arg_formatter(OutputIt iter, format_specs<Char>& s, context_type& ctx)
|
||||
printf_arg_formatter(buffer_appender<Char> iter, format_specs<Char>& s,
|
||||
context_type& ctx)
|
||||
: base(make_arg_formatter(iter, s)), context_(ctx) {}
|
||||
|
||||
OutputIt operator()(monostate value) { return base::operator()(value); }
|
||||
void operator()(monostate value) { base::operator()(value); }
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(detail::is_integral<T>::value)>
|
||||
OutputIt operator()(T value) {
|
||||
void operator()(T value) {
|
||||
// MSVC2013 fails to compile separate overloads for bool and Char so use
|
||||
// std::is_same instead.
|
||||
if (std::is_same<T, Char>::value) {
|
||||
format_specs<Char> fmt_specs = this->specs;
|
||||
if (fmt_specs.type != presentation_type::none &&
|
||||
fmt_specs.type != presentation_type::chr) {
|
||||
return (*this)(static_cast<int>(value));
|
||||
}
|
||||
fmt_specs.sign = sign::none;
|
||||
fmt_specs.alt = false;
|
||||
fmt_specs.fill[0] = ' '; // Ignore '0' flag for char types.
|
||||
// align::numeric needs to be overwritten here since the '0' flag is
|
||||
// ignored for non-numeric types
|
||||
if (fmt_specs.align == align::none || fmt_specs.align == align::numeric)
|
||||
fmt_specs.align = align::right;
|
||||
return write<Char>(this->out, static_cast<Char>(value), fmt_specs);
|
||||
if (!std::is_same<T, Char>::value) {
|
||||
base::operator()(value);
|
||||
return;
|
||||
}
|
||||
return base::operator()(value);
|
||||
format_specs<Char> fmt_specs = this->specs;
|
||||
if (fmt_specs.type != presentation_type::none &&
|
||||
fmt_specs.type != presentation_type::chr) {
|
||||
return (*this)(static_cast<int>(value));
|
||||
}
|
||||
fmt_specs.sign = sign::none;
|
||||
fmt_specs.alt = false;
|
||||
fmt_specs.fill[0] = ' '; // Ignore '0' flag for char types.
|
||||
// align::numeric needs to be overwritten here since the '0' flag is
|
||||
// ignored for non-numeric types
|
||||
if (fmt_specs.align == align::none || fmt_specs.align == align::numeric)
|
||||
fmt_specs.align = align::right;
|
||||
write<Char>(this->out, static_cast<Char>(value), fmt_specs);
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
||||
OutputIt operator()(T value) {
|
||||
return base::operator()(value);
|
||||
void operator()(T value) {
|
||||
base::operator()(value);
|
||||
}
|
||||
|
||||
/** Formats a null-terminated C string. */
|
||||
OutputIt operator()(const char* value) {
|
||||
if (value) return base::operator()(value);
|
||||
return write_null_pointer(this->specs.type != presentation_type::pointer);
|
||||
void operator()(const char* value) {
|
||||
if (value)
|
||||
base::operator()(value);
|
||||
else
|
||||
write_null_pointer(this->specs.type != presentation_type::pointer);
|
||||
}
|
||||
|
||||
/** Formats a null-terminated wide C string. */
|
||||
OutputIt operator()(const wchar_t* value) {
|
||||
if (value) return base::operator()(value);
|
||||
return write_null_pointer(this->specs.type != presentation_type::pointer);
|
||||
void operator()(const wchar_t* value) {
|
||||
if (value)
|
||||
base::operator()(value);
|
||||
else
|
||||
write_null_pointer(this->specs.type != presentation_type::pointer);
|
||||
}
|
||||
|
||||
OutputIt operator()(basic_string_view<Char> value) {
|
||||
return base::operator()(value);
|
||||
}
|
||||
void operator()(basic_string_view<Char> value) { base::operator()(value); }
|
||||
|
||||
/** Formats a pointer. */
|
||||
OutputIt operator()(const void* value) {
|
||||
return value ? base::operator()(value) : write_null_pointer();
|
||||
void operator()(const void* value) {
|
||||
if (value)
|
||||
base::operator()(value);
|
||||
else
|
||||
write_null_pointer();
|
||||
}
|
||||
|
||||
/** Formats an argument of a custom (user-defined) type. */
|
||||
OutputIt operator()(typename basic_format_arg<context_type>::handle handle) {
|
||||
auto parse_ctx =
|
||||
basic_printf_parse_context<Char>(basic_string_view<Char>());
|
||||
void operator()(typename basic_format_arg<context_type>::handle handle) {
|
||||
auto parse_ctx = basic_format_parse_context<Char>({});
|
||||
handle.format(parse_ctx, context_);
|
||||
return this->out;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -318,9 +326,7 @@ void parse_flags(format_specs<Char>& specs, const Char*& it, const Char* end) {
|
||||
specs.fill[0] = '0';
|
||||
break;
|
||||
case ' ':
|
||||
if (specs.sign != sign::plus) {
|
||||
specs.sign = sign::space;
|
||||
}
|
||||
if (specs.sign != sign::plus) specs.sign = sign::space;
|
||||
break;
|
||||
case '#':
|
||||
specs.alt = true;
|
||||
@@ -332,8 +338,8 @@ void parse_flags(format_specs<Char>& specs, const Char*& it, const Char* end) {
|
||||
}
|
||||
|
||||
template <typename Char, typename GetArg>
|
||||
int parse_header(const Char*& it, const Char* end, format_specs<Char>& specs,
|
||||
GetArg get_arg) {
|
||||
auto parse_header(const Char*& it, const Char* end, format_specs<Char>& specs,
|
||||
GetArg get_arg) -> int {
|
||||
int arg_index = -1;
|
||||
Char c = *it;
|
||||
if (c >= '0' && c <= '9') {
|
||||
@@ -414,8 +420,8 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
||||
basic_format_args<Context> args) {
|
||||
using iterator = buffer_appender<Char>;
|
||||
auto out = iterator(buf);
|
||||
auto context = basic_printf_context<iterator, Char>(out, args);
|
||||
auto parse_ctx = basic_printf_parse_context<Char>(format);
|
||||
auto context = basic_printf_context<Char>(out, args);
|
||||
auto parse_ctx = basic_format_parse_context<Char>(format);
|
||||
|
||||
// Returns the argument with specified index or, if arg_index is -1, the next
|
||||
// argument.
|
||||
@@ -437,12 +443,11 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
||||
}
|
||||
Char c = *it++;
|
||||
if (it != end && *it == c) {
|
||||
out = write(out, basic_string_view<Char>(start, to_unsigned(it - start)));
|
||||
write(out, basic_string_view<Char>(start, to_unsigned(it - start)));
|
||||
start = ++it;
|
||||
continue;
|
||||
}
|
||||
out =
|
||||
write(out, basic_string_view<Char>(start, to_unsigned(it - 1 - start)));
|
||||
write(out, basic_string_view<Char>(start, to_unsigned(it - 1 - start)));
|
||||
|
||||
auto specs = format_specs<Char>();
|
||||
specs.align = align::right;
|
||||
@@ -469,16 +474,17 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
||||
auto arg = get_arg(arg_index);
|
||||
// For d, i, o, u, x, and X conversion specifiers, if a precision is
|
||||
// specified, the '0' flag is ignored
|
||||
if (specs.precision >= 0 && arg.is_integral())
|
||||
specs.fill[0] =
|
||||
' '; // Ignore '0' flag for non-numeric types or if '-' present.
|
||||
if (specs.precision >= 0 && arg.is_integral()) {
|
||||
// Ignore '0' for non-numeric types or if '-' present.
|
||||
specs.fill[0] = ' ';
|
||||
}
|
||||
if (specs.precision >= 0 && arg.type() == type::cstring_type) {
|
||||
auto str = visit_format_arg(get_cstring<Char>(), arg);
|
||||
auto str_end = str + specs.precision;
|
||||
auto nul = std::find(str, str_end, Char());
|
||||
arg = make_arg<basic_printf_context<iterator, Char>>(
|
||||
basic_string_view<Char>(
|
||||
str, to_unsigned(nul != str_end ? nul - str : specs.precision)));
|
||||
auto sv = basic_string_view<Char>(
|
||||
str, to_unsigned(nul != str_end ? nul - str : specs.precision));
|
||||
arg = make_arg<basic_printf_context<Char>>(sv);
|
||||
}
|
||||
if (specs.alt && visit_format_arg(is_zero_int(), arg)) specs.alt = false;
|
||||
if (specs.fill[0] == '0') {
|
||||
@@ -540,8 +546,7 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
||||
type = 'd';
|
||||
break;
|
||||
case 'c':
|
||||
visit_format_arg(
|
||||
char_converter<basic_printf_context<iterator, Char>>(arg), arg);
|
||||
visit_format_arg(char_converter<basic_printf_context<Char>>(arg), arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -552,19 +557,14 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
||||
start = it;
|
||||
|
||||
// Format argument.
|
||||
out = visit_format_arg(
|
||||
printf_arg_formatter<iterator, Char>(out, specs, context), arg);
|
||||
visit_format_arg(printf_arg_formatter<Char>(out, specs, context), arg);
|
||||
}
|
||||
write(out, basic_string_view<Char>(start, to_unsigned(it - start)));
|
||||
}
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
} // namespace detail
|
||||
|
||||
template <typename Char>
|
||||
using basic_printf_context_t =
|
||||
basic_printf_context<detail::buffer_appender<Char>, Char>;
|
||||
|
||||
using printf_context = basic_printf_context_t<char>;
|
||||
using wprintf_context = basic_printf_context_t<wchar_t>;
|
||||
using printf_context = basic_printf_context<char>;
|
||||
using wprintf_context = basic_printf_context<wchar_t>;
|
||||
|
||||
using printf_args = basic_format_args<printf_context>;
|
||||
using wprintf_args = basic_format_args<wprintf_context>;
|
||||
@@ -581,25 +581,20 @@ inline auto make_printf_args(const T&... args)
|
||||
return {args...};
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Constructs an `~fmt::format_arg_store` object that contains references to
|
||||
arguments and can be implicitly converted to `~fmt::wprintf_args`.
|
||||
\endrst
|
||||
*/
|
||||
// DEPRECATED!
|
||||
template <typename... T>
|
||||
inline auto make_wprintf_args(const T&... args)
|
||||
-> format_arg_store<wprintf_context, T...> {
|
||||
return {args...};
|
||||
}
|
||||
|
||||
template <typename S, typename Char = char_t<S>>
|
||||
template <typename Char>
|
||||
inline auto vsprintf(
|
||||
const S& fmt,
|
||||
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
|
||||
basic_string_view<Char> fmt,
|
||||
basic_format_args<basic_printf_context<type_identity_t<Char>>> args)
|
||||
-> std::basic_string<Char> {
|
||||
auto buf = basic_memory_buffer<Char>();
|
||||
detail::vprintf(buf, detail::to_string_view(fmt), args);
|
||||
detail::vprintf(buf, fmt, args);
|
||||
return to_string(buf);
|
||||
}
|
||||
|
||||
@@ -615,18 +610,17 @@ inline auto vsprintf(
|
||||
template <typename S, typename... T,
|
||||
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
|
||||
inline auto sprintf(const S& fmt, const T&... args) -> std::basic_string<Char> {
|
||||
using context = basic_printf_context_t<Char>;
|
||||
return vsprintf(detail::to_string_view(fmt),
|
||||
fmt::make_format_args<context>(args...));
|
||||
fmt::make_format_args<basic_printf_context<Char>>(args...));
|
||||
}
|
||||
|
||||
template <typename S, typename Char = char_t<S>>
|
||||
template <typename Char>
|
||||
inline auto vfprintf(
|
||||
std::FILE* f, const S& fmt,
|
||||
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
|
||||
std::FILE* f, basic_string_view<Char> fmt,
|
||||
basic_format_args<basic_printf_context<type_identity_t<Char>>> args)
|
||||
-> int {
|
||||
auto buf = basic_memory_buffer<Char>();
|
||||
detail::vprintf(buf, detail::to_string_view(fmt), args);
|
||||
detail::vprintf(buf, fmt, args);
|
||||
size_t size = buf.size();
|
||||
return std::fwrite(buf.data(), sizeof(Char), size, f) < size
|
||||
? -1
|
||||
@@ -644,17 +638,16 @@ inline auto vfprintf(
|
||||
*/
|
||||
template <typename S, typename... T, typename Char = char_t<S>>
|
||||
inline auto fprintf(std::FILE* f, const S& fmt, const T&... args) -> int {
|
||||
using context = basic_printf_context_t<Char>;
|
||||
return vfprintf(f, detail::to_string_view(fmt),
|
||||
fmt::make_format_args<context>(args...));
|
||||
fmt::make_format_args<basic_printf_context<Char>>(args...));
|
||||
}
|
||||
|
||||
template <typename S, typename Char = char_t<S>>
|
||||
inline auto vprintf(
|
||||
const S& fmt,
|
||||
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
|
||||
template <typename Char>
|
||||
FMT_DEPRECATED inline auto vprintf(
|
||||
basic_string_view<Char> fmt,
|
||||
basic_format_args<basic_printf_context<type_identity_t<Char>>> args)
|
||||
-> int {
|
||||
return vfprintf(stdout, detail::to_string_view(fmt), args);
|
||||
return vfprintf(stdout, fmt, args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -666,11 +659,14 @@ inline auto vprintf(
|
||||
fmt::printf("Elapsed time: %.2f seconds", 1.23);
|
||||
\endrst
|
||||
*/
|
||||
template <typename S, typename... T, FMT_ENABLE_IF(detail::is_string<S>::value)>
|
||||
inline auto printf(const S& fmt, const T&... args) -> int {
|
||||
return vprintf(
|
||||
detail::to_string_view(fmt),
|
||||
fmt::make_format_args<basic_printf_context_t<char_t<S>>>(args...));
|
||||
template <typename... T>
|
||||
inline auto printf(string_view fmt, const T&... args) -> int {
|
||||
return vfprintf(stdout, fmt, make_printf_args(args...));
|
||||
}
|
||||
template <typename... T>
|
||||
FMT_DEPRECATED inline auto printf(basic_string_view<wchar_t> fmt,
|
||||
const T&... args) -> int {
|
||||
return vfprintf(stdout, fmt, make_wprintf_args(args...));
|
||||
}
|
||||
|
||||
FMT_END_EXPORT
|
||||
|
||||
+23
-17
@@ -1,13 +1,9 @@
|
||||
// Formatting library for C++ - experimental range support
|
||||
// Formatting library for C++ - range and tuple support
|
||||
//
|
||||
// Copyright (c) 2012 - present, Victor Zverovich
|
||||
// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
//
|
||||
// Copyright (c) 2018 - present, Remotion (Igor Schulz)
|
||||
// All Rights Reserved
|
||||
// {fmt} support for ranges, containers and types tuple interface.
|
||||
|
||||
#ifndef FMT_RANGES_H_
|
||||
#define FMT_RANGES_H_
|
||||
@@ -187,7 +183,7 @@ template <size_t N> using make_index_sequence = std::make_index_sequence<N>;
|
||||
template <typename T, T... N> struct integer_sequence {
|
||||
using value_type = T;
|
||||
|
||||
static FMT_CONSTEXPR size_t size() { return sizeof...(N); }
|
||||
static FMT_CONSTEXPR auto size() -> size_t { return sizeof...(N); }
|
||||
};
|
||||
|
||||
template <size_t... N> using index_sequence = integer_sequence<size_t, N...>;
|
||||
@@ -211,15 +207,15 @@ class is_tuple_formattable_ {
|
||||
};
|
||||
template <typename T, typename C> class is_tuple_formattable_<T, C, true> {
|
||||
template <std::size_t... Is>
|
||||
static std::true_type check2(index_sequence<Is...>,
|
||||
integer_sequence<bool, (Is == Is)...>);
|
||||
static std::false_type check2(...);
|
||||
static auto check2(index_sequence<Is...>,
|
||||
integer_sequence<bool, (Is == Is)...>) -> std::true_type;
|
||||
static auto check2(...) -> std::false_type;
|
||||
template <std::size_t... Is>
|
||||
static decltype(check2(
|
||||
static auto check(index_sequence<Is...>) -> decltype(check2(
|
||||
index_sequence<Is...>{},
|
||||
integer_sequence<
|
||||
bool, (is_formattable<typename std::tuple_element<Is, T>::type,
|
||||
C>::value)...>{})) check(index_sequence<Is...>);
|
||||
integer_sequence<bool,
|
||||
(is_formattable<typename std::tuple_element<Is, T>::type,
|
||||
C>::value)...>{}));
|
||||
|
||||
public:
|
||||
static constexpr const bool value =
|
||||
@@ -421,6 +417,12 @@ struct is_formattable_delayed
|
||||
#endif
|
||||
} // namespace detail
|
||||
|
||||
template <typename...> struct conjunction : std::true_type {};
|
||||
template <typename P> struct conjunction<P> : P {};
|
||||
template <typename P1, typename... Pn>
|
||||
struct conjunction<P1, Pn...>
|
||||
: conditional_t<bool(P1::value), conjunction<Pn...>, P1> {};
|
||||
|
||||
template <typename T, typename Char, typename Enable = void>
|
||||
struct range_formatter;
|
||||
|
||||
@@ -486,7 +488,8 @@ struct range_formatter<
|
||||
for (; it != end; ++it) {
|
||||
if (i > 0) out = detail::copy_str<Char>(separator_, out);
|
||||
ctx.advance_to(out);
|
||||
out = underlying_.format(mapper.map(*it), ctx);
|
||||
auto&& item = *it;
|
||||
out = underlying_.format(mapper.map(item), ctx);
|
||||
++i;
|
||||
}
|
||||
out = detail::copy_str<Char>(closing_bracket_, out);
|
||||
@@ -668,8 +671,11 @@ template <typename Container> struct all {
|
||||
} // namespace detail
|
||||
|
||||
template <typename T, typename Char>
|
||||
struct formatter<T, Char,
|
||||
enable_if_t<detail::is_container_adaptor_like<T>::value>>
|
||||
struct formatter<
|
||||
T, Char,
|
||||
enable_if_t<conjunction<detail::is_container_adaptor_like<T>,
|
||||
bool_constant<range_format_kind<T, Char>::value ==
|
||||
range_format::disabled>>::value>>
|
||||
: formatter<detail::all<typename T::container_type>, Char> {
|
||||
using all = detail::all<typename T::container_type>;
|
||||
template <typename FormatContext>
|
||||
|
||||
+251
-63
@@ -8,6 +8,8 @@
|
||||
#ifndef FMT_STD_H_
|
||||
#define FMT_STD_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <bitset>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
@@ -15,7 +17,9 @@
|
||||
#include <type_traits>
|
||||
#include <typeinfo>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "format.h"
|
||||
#include "ostream.h"
|
||||
|
||||
#if FMT_HAS_INCLUDE(<version>)
|
||||
@@ -34,6 +38,10 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>)
|
||||
# include <source_location>
|
||||
#endif
|
||||
|
||||
// GCC 4 does not support FMT_HAS_INCLUDE.
|
||||
#if FMT_HAS_INCLUDE(<cxxabi.h>) || defined(__GLIBCXX__)
|
||||
# include <cxxabi.h>
|
||||
@@ -44,67 +52,155 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cpp_lib_filesystem
|
||||
// Check if typeid is available.
|
||||
#ifndef FMT_USE_TYPEID
|
||||
// __RTTI is for EDG compilers. In MSVC typeid is available without RTTI.
|
||||
# if defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || FMT_MSC_VERSION || \
|
||||
defined(__INTEL_RTTI__) || defined(__RTTI)
|
||||
# define FMT_USE_TYPEID 1
|
||||
# else
|
||||
# define FMT_USE_TYPEID 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// For older Xcode versions, __cpp_lib_xxx flags are inaccurately defined.
|
||||
#ifndef FMT_CPP_LIB_FILESYSTEM
|
||||
# ifdef __cpp_lib_filesystem
|
||||
# define FMT_CPP_LIB_FILESYSTEM __cpp_lib_filesystem
|
||||
# else
|
||||
# define FMT_CPP_LIB_FILESYSTEM 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef FMT_CPP_LIB_VARIANT
|
||||
# ifdef __cpp_lib_variant
|
||||
# define FMT_CPP_LIB_VARIANT __cpp_lib_variant
|
||||
# else
|
||||
# define FMT_CPP_LIB_VARIANT 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if FMT_CPP_LIB_FILESYSTEM
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Char>
|
||||
template <typename Char, typename PathChar>
|
||||
auto get_path_string(const std::filesystem::path& p,
|
||||
const std::basic_string<PathChar>& native) {
|
||||
if constexpr (std::is_same_v<Char, char> && std::is_same_v<PathChar, wchar_t>)
|
||||
return to_utf8<wchar_t>(native, to_utf8_error_policy::replace);
|
||||
else
|
||||
return p.string<Char>();
|
||||
}
|
||||
|
||||
template <typename Char, typename PathChar>
|
||||
void write_escaped_path(basic_memory_buffer<Char>& quoted,
|
||||
const std::filesystem::path& p) {
|
||||
write_escaped_string<Char>(std::back_inserter(quoted), p.string<Char>());
|
||||
}
|
||||
# ifdef _WIN32
|
||||
template <>
|
||||
inline void write_escaped_path<char>(memory_buffer& quoted,
|
||||
const std::filesystem::path& p) {
|
||||
auto buf = basic_memory_buffer<wchar_t>();
|
||||
write_escaped_string<wchar_t>(std::back_inserter(buf), p.native());
|
||||
// Convert UTF-16 to UTF-8.
|
||||
if (!unicode_to_utf8<wchar_t>::convert(quoted, {buf.data(), buf.size()}))
|
||||
FMT_THROW(std::runtime_error("invalid utf16"));
|
||||
}
|
||||
# endif
|
||||
template <>
|
||||
inline void write_escaped_path<std::filesystem::path::value_type>(
|
||||
basic_memory_buffer<std::filesystem::path::value_type>& quoted,
|
||||
const std::filesystem::path& p) {
|
||||
write_escaped_string<std::filesystem::path::value_type>(
|
||||
std::back_inserter(quoted), p.native());
|
||||
const std::filesystem::path& p,
|
||||
const std::basic_string<PathChar>& native) {
|
||||
if constexpr (std::is_same_v<Char, char> &&
|
||||
std::is_same_v<PathChar, wchar_t>) {
|
||||
auto buf = basic_memory_buffer<wchar_t>();
|
||||
write_escaped_string<wchar_t>(std::back_inserter(buf), native);
|
||||
bool valid = to_utf8<wchar_t>::convert(quoted, {buf.data(), buf.size()});
|
||||
FMT_ASSERT(valid, "invalid utf16");
|
||||
} else if constexpr (std::is_same_v<Char, PathChar>) {
|
||||
write_escaped_string<std::filesystem::path::value_type>(
|
||||
std::back_inserter(quoted), native);
|
||||
} else {
|
||||
write_escaped_string<Char>(std::back_inserter(quoted), p.string<Char>());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
FMT_MODULE_EXPORT
|
||||
template <typename Char>
|
||||
struct formatter<std::filesystem::path, Char>
|
||||
: formatter<basic_string_view<Char>> {
|
||||
FMT_EXPORT
|
||||
template <typename Char> struct formatter<std::filesystem::path, Char> {
|
||||
private:
|
||||
format_specs<Char> specs_;
|
||||
detail::arg_ref<Char> width_ref_;
|
||||
bool debug_ = false;
|
||||
char path_type_ = 0;
|
||||
|
||||
public:
|
||||
FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; }
|
||||
|
||||
template <typename ParseContext> FMT_CONSTEXPR auto parse(ParseContext& ctx) {
|
||||
auto out = formatter<basic_string_view<Char>>::parse(ctx);
|
||||
this->set_debug_format(false);
|
||||
return out;
|
||||
auto it = ctx.begin(), end = ctx.end();
|
||||
if (it == end) return it;
|
||||
|
||||
it = detail::parse_align(it, end, specs_);
|
||||
if (it == end) return it;
|
||||
|
||||
it = detail::parse_dynamic_spec(it, end, specs_.width, width_ref_, ctx);
|
||||
if (it != end && *it == '?') {
|
||||
debug_ = true;
|
||||
++it;
|
||||
}
|
||||
if (it != end && (*it == 'g')) path_type_ = *it++;
|
||||
return it;
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
|
||||
typename FormatContext::iterator {
|
||||
auto format(const std::filesystem::path& p, FormatContext& ctx) const {
|
||||
auto specs = specs_;
|
||||
# ifdef _WIN32
|
||||
auto path_string = !path_type_ ? p.native() : p.generic_wstring();
|
||||
# else
|
||||
auto path_string = !path_type_ ? p.native() : p.generic_string();
|
||||
# endif
|
||||
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_,
|
||||
ctx);
|
||||
if (!debug_) {
|
||||
auto s = detail::get_path_string<Char>(p, path_string);
|
||||
return detail::write(ctx.out(), basic_string_view<Char>(s), specs);
|
||||
}
|
||||
auto quoted = basic_memory_buffer<Char>();
|
||||
detail::write_escaped_path(quoted, p);
|
||||
return formatter<basic_string_view<Char>>::format(
|
||||
basic_string_view<Char>(quoted.data(), quoted.size()), ctx);
|
||||
detail::write_escaped_path(quoted, p, path_string);
|
||||
return detail::write(ctx.out(),
|
||||
basic_string_view<Char>(quoted.data(), quoted.size()),
|
||||
specs);
|
||||
}
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
#endif
|
||||
#endif // FMT_CPP_LIB_FILESYSTEM
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
FMT_MODULE_EXPORT
|
||||
FMT_EXPORT
|
||||
template <std::size_t N, typename Char>
|
||||
struct formatter<std::bitset<N>, Char> : nested_formatter<string_view> {
|
||||
private:
|
||||
// Functor because C++11 doesn't support generic lambdas.
|
||||
struct writer {
|
||||
const std::bitset<N>& bs;
|
||||
|
||||
template <typename OutputIt>
|
||||
FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt {
|
||||
for (auto pos = N; pos > 0; --pos) {
|
||||
out = detail::write<Char>(out, bs[pos - 1] ? Char('1') : Char('0'));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
template <typename FormatContext>
|
||||
auto format(const std::bitset<N>& bs, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return write_padded(ctx, writer{bs});
|
||||
}
|
||||
};
|
||||
|
||||
FMT_EXPORT
|
||||
template <typename Char>
|
||||
struct formatter<std::thread::id, Char> : basic_ostream_formatter<Char> {};
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#ifdef __cpp_lib_optional
|
||||
FMT_BEGIN_NAMESPACE
|
||||
FMT_MODULE_EXPORT
|
||||
FMT_EXPORT
|
||||
template <typename T, typename Char>
|
||||
struct formatter<std::optional<T>, Char,
|
||||
std::enable_if_t<is_formattable<T, Char>::value>> {
|
||||
@@ -132,7 +228,7 @@ struct formatter<std::optional<T>, Char,
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(std::optional<T> const& opt, FormatContext& ctx) const
|
||||
auto format(const std::optional<T>& opt, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
if (!opt) return detail::write<Char>(ctx.out(), none);
|
||||
|
||||
@@ -146,24 +242,33 @@ struct formatter<std::optional<T>, Char,
|
||||
FMT_END_NAMESPACE
|
||||
#endif // __cpp_lib_optional
|
||||
|
||||
#ifdef __cpp_lib_variant
|
||||
#ifdef __cpp_lib_source_location
|
||||
FMT_BEGIN_NAMESPACE
|
||||
FMT_MODULE_EXPORT
|
||||
template <typename Char> struct formatter<std::monostate, Char> {
|
||||
template <typename ParseContext>
|
||||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||
FMT_EXPORT
|
||||
template <> struct formatter<std::source_location> {
|
||||
template <typename ParseContext> FMT_CONSTEXPR auto parse(ParseContext& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const std::monostate&, FormatContext& ctx) const
|
||||
auto format(const std::source_location& loc, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
auto out = ctx.out();
|
||||
out = detail::write<Char>(out, "monostate");
|
||||
out = detail::write(out, loc.file_name());
|
||||
out = detail::write(out, ':');
|
||||
out = detail::write<char>(out, loc.line());
|
||||
out = detail::write(out, ':');
|
||||
out = detail::write<char>(out, loc.column());
|
||||
out = detail::write(out, ": ");
|
||||
out = detail::write(out, loc.function_name());
|
||||
return out;
|
||||
}
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
#if FMT_CPP_LIB_VARIANT
|
||||
FMT_BEGIN_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
@@ -197,6 +302,7 @@ auto write_variant_alternative(OutputIt out, const T& v) -> OutputIt {
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T> struct is_variant_like {
|
||||
static constexpr const bool value = detail::is_variant_like_<T>::value;
|
||||
};
|
||||
@@ -206,7 +312,21 @@ template <typename T, typename C> struct is_variant_formattable {
|
||||
detail::is_variant_formattable_<T, C>::value;
|
||||
};
|
||||
|
||||
FMT_MODULE_EXPORT
|
||||
FMT_EXPORT
|
||||
template <typename Char> struct formatter<std::monostate, Char> {
|
||||
template <typename ParseContext>
|
||||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const std::monostate&, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return detail::write<Char>(ctx.out(), "monostate");
|
||||
}
|
||||
};
|
||||
|
||||
FMT_EXPORT
|
||||
template <typename Variant, typename Char>
|
||||
struct formatter<
|
||||
Variant, Char,
|
||||
@@ -223,13 +343,14 @@ struct formatter<
|
||||
auto out = ctx.out();
|
||||
|
||||
out = detail::write<Char>(out, "variant(");
|
||||
try {
|
||||
FMT_TRY {
|
||||
std::visit(
|
||||
[&](const auto& v) {
|
||||
out = detail::write_variant_alternative<Char>(out, v);
|
||||
},
|
||||
value);
|
||||
} catch (const std::bad_variant_access&) {
|
||||
}
|
||||
FMT_CATCH(const std::bad_variant_access&) {
|
||||
detail::write<Char>(out, "valueless by exception");
|
||||
}
|
||||
*out++ = ')';
|
||||
@@ -237,10 +358,10 @@ struct formatter<
|
||||
}
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
#endif // __cpp_lib_variant
|
||||
#endif // FMT_CPP_LIB_VARIANT
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
FMT_MODULE_EXPORT
|
||||
FMT_EXPORT
|
||||
template <typename Char> struct formatter<std::error_code, Char> {
|
||||
template <typename ParseContext>
|
||||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||
@@ -258,10 +379,10 @@ template <typename Char> struct formatter<std::error_code, Char> {
|
||||
}
|
||||
};
|
||||
|
||||
FMT_MODULE_EXPORT
|
||||
FMT_EXPORT
|
||||
template <typename T, typename Char>
|
||||
struct formatter<
|
||||
T, Char,
|
||||
T, Char, // DEPRECATED! Mixing code unit types.
|
||||
typename std::enable_if<std::is_base_of<std::exception, T>::value>::type> {
|
||||
private:
|
||||
bool with_typename_ = false;
|
||||
@@ -274,7 +395,7 @@ struct formatter<
|
||||
if (it == end || *it == '}') return it;
|
||||
if (*it == 't') {
|
||||
++it;
|
||||
with_typename_ = true;
|
||||
with_typename_ = FMT_USE_TYPEID != 0;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
@@ -287,11 +408,12 @@ struct formatter<
|
||||
if (!with_typename_)
|
||||
return detail::write_bytes(out, string_view(ex.what()), spec);
|
||||
|
||||
#if FMT_USE_TYPEID
|
||||
const std::type_info& ti = typeid(ex);
|
||||
#ifdef FMT_HAS_ABI_CXA_DEMANGLE
|
||||
# ifdef FMT_HAS_ABI_CXA_DEMANGLE
|
||||
int status = 0;
|
||||
std::size_t size = 0;
|
||||
std::unique_ptr<char, decltype(&std::free)> demangled_name_ptr(
|
||||
std::unique_ptr<char, void (*)(void*)> demangled_name_ptr(
|
||||
abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &std::free);
|
||||
|
||||
string_view demangled_name_view;
|
||||
@@ -327,23 +449,89 @@ struct formatter<
|
||||
demangled_name_view = string_view(ti.name());
|
||||
}
|
||||
out = detail::write_bytes(out, demangled_name_view, spec);
|
||||
#elif FMT_MSC_VERSION
|
||||
# elif FMT_MSC_VERSION
|
||||
string_view demangled_name_view(ti.name());
|
||||
if (demangled_name_view.starts_with("class "))
|
||||
demangled_name_view.remove_prefix(6);
|
||||
else if (demangled_name_view.starts_with("struct "))
|
||||
demangled_name_view.remove_prefix(7);
|
||||
out = detail::write_bytes(out, demangled_name_view, spec);
|
||||
#else
|
||||
# else
|
||||
out = detail::write_bytes(out, string_view(ti.name()), spec);
|
||||
# endif
|
||||
*out++ = ':';
|
||||
*out++ = ' ';
|
||||
return detail::write_bytes(out, string_view(ex.what()), spec);
|
||||
#endif
|
||||
out = detail::write<Char>(out, Char(':'));
|
||||
out = detail::write<Char>(out, Char(' '));
|
||||
out = detail::write_bytes(out, string_view(ex.what()), spec);
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct has_flip : std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct has_flip<T, void_t<decltype(std::declval<T>().flip())>>
|
||||
: std::true_type {};
|
||||
|
||||
template <typename T> struct is_bit_reference_like {
|
||||
static constexpr const bool value =
|
||||
std::is_convertible<T, bool>::value &&
|
||||
std::is_nothrow_assignable<T, bool>::value && has_flip<T>::value;
|
||||
};
|
||||
|
||||
#ifdef _LIBCPP_VERSION
|
||||
|
||||
// Workaround for libc++ incompatibility with C++ standard.
|
||||
// According to the Standard, `bitset::operator[] const` returns bool.
|
||||
template <typename C>
|
||||
struct is_bit_reference_like<std::__bit_const_reference<C>> {
|
||||
static constexpr const bool value = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// We can't use std::vector<bool, Allocator>::reference and
|
||||
// std::bitset<N>::reference because the compiler can't deduce Allocator and N
|
||||
// in partial specialization.
|
||||
FMT_EXPORT
|
||||
template <typename BitRef, typename Char>
|
||||
struct formatter<BitRef, Char,
|
||||
enable_if_t<detail::is_bit_reference_like<BitRef>::value>>
|
||||
: formatter<bool, Char> {
|
||||
template <typename FormatContext>
|
||||
FMT_CONSTEXPR auto format(const BitRef& v, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return formatter<bool, Char>::format(v, ctx);
|
||||
}
|
||||
};
|
||||
|
||||
FMT_EXPORT
|
||||
template <typename T, typename Char>
|
||||
struct formatter<std::atomic<T>, Char,
|
||||
enable_if_t<is_formattable<T, Char>::value>>
|
||||
: formatter<T, Char> {
|
||||
template <typename FormatContext>
|
||||
auto format(const std::atomic<T>& v, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return formatter<T, Char>::format(v.load(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __cpp_lib_atomic_flag_test
|
||||
FMT_EXPORT
|
||||
template <typename Char>
|
||||
struct formatter<std::atomic_flag, Char> : formatter<bool, Char> {
|
||||
template <typename FormatContext>
|
||||
auto format(const std::atomic_flag& v, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return formatter<bool, Char>::format(v.test(), ctx);
|
||||
}
|
||||
};
|
||||
#endif // __cpp_lib_atomic_flag_test
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
#endif // FMT_STD_H_
|
||||
|
||||
+32
-32
@@ -62,15 +62,16 @@ template <> struct is_char<detail::char8_type> : std::true_type {};
|
||||
template <> struct is_char<char16_t> : std::true_type {};
|
||||
template <> struct is_char<char32_t> : std::true_type {};
|
||||
|
||||
template <typename... Args>
|
||||
constexpr format_arg_store<wformat_context, Args...> make_wformat_args(
|
||||
const Args&... args) {
|
||||
template <typename... T>
|
||||
constexpr auto make_wformat_args(const T&... args)
|
||||
-> format_arg_store<wformat_context, T...> {
|
||||
return {args...};
|
||||
}
|
||||
|
||||
inline namespace literals {
|
||||
#if FMT_USE_USER_DEFINED_LITERALS && !FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
constexpr detail::udl_arg<wchar_t> operator"" _a(const wchar_t* s, size_t) {
|
||||
constexpr auto operator""_a(const wchar_t* s, size_t)
|
||||
-> detail::udl_arg<wchar_t> {
|
||||
return {s};
|
||||
}
|
||||
#endif
|
||||
@@ -99,9 +100,9 @@ template <typename Char, FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
|
||||
auto vformat(basic_string_view<Char> format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args)
|
||||
-> std::basic_string<Char> {
|
||||
basic_memory_buffer<Char> buffer;
|
||||
detail::vformat_to(buffer, format_str, args);
|
||||
return to_string(buffer);
|
||||
auto buf = basic_memory_buffer<Char>();
|
||||
detail::vformat_to(buf, format_str, args);
|
||||
return to_string(buf);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
@@ -111,10 +112,10 @@ auto format(wformat_string<T...> fmt, T&&... args) -> std::wstring {
|
||||
|
||||
// Pass char_t as a default template parameter instead of using
|
||||
// std::basic_string<char_t<S>> to reduce the symbol size.
|
||||
template <typename S, typename... Args, typename Char = char_t<S>,
|
||||
template <typename S, typename... T, typename Char = char_t<S>,
|
||||
FMT_ENABLE_IF(!std::is_same<Char, char>::value &&
|
||||
!std::is_same<Char, wchar_t>::value)>
|
||||
auto format(const S& format_str, Args&&... args) -> std::basic_string<Char> {
|
||||
auto format(const S& format_str, T&&... args) -> std::basic_string<Char> {
|
||||
return vformat(detail::to_string_view(format_str),
|
||||
fmt::make_format_args<buffer_context<Char>>(args...));
|
||||
}
|
||||
@@ -129,11 +130,10 @@ inline auto vformat(
|
||||
return detail::vformat(loc, detail::to_string_view(format_str), args);
|
||||
}
|
||||
|
||||
template <typename Locale, typename S, typename... Args,
|
||||
typename Char = char_t<S>,
|
||||
template <typename Locale, typename S, typename... T, typename Char = char_t<S>,
|
||||
FMT_ENABLE_IF(detail::is_locale<Locale>::value&&
|
||||
detail::is_exotic_char<Char>::value)>
|
||||
inline auto format(const Locale& loc, const S& format_str, Args&&... args)
|
||||
inline auto format(const Locale& loc, const S& format_str, T&&... args)
|
||||
-> std::basic_string<Char> {
|
||||
return detail::vformat(loc, detail::to_string_view(format_str),
|
||||
fmt::make_format_args<buffer_context<Char>>(args...));
|
||||
@@ -150,11 +150,11 @@ auto vformat_to(OutputIt out, const S& format_str,
|
||||
return detail::get_iterator(buf, out);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
template <typename OutputIt, typename S, typename... T,
|
||||
typename Char = char_t<S>,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value&&
|
||||
detail::is_exotic_char<Char>::value)>
|
||||
inline auto format_to(OutputIt out, const S& fmt, Args&&... args) -> OutputIt {
|
||||
inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt {
|
||||
return vformat_to(out, detail::to_string_view(fmt),
|
||||
fmt::make_format_args<buffer_context<Char>>(args...));
|
||||
}
|
||||
@@ -173,13 +173,13 @@ inline auto vformat_to(
|
||||
return detail::get_iterator(buf, out);
|
||||
}
|
||||
|
||||
template <
|
||||
typename OutputIt, typename Locale, typename S, typename... Args,
|
||||
typename Char = char_t<S>,
|
||||
bool enable = detail::is_output_iterator<OutputIt, Char>::value&&
|
||||
detail::is_locale<Locale>::value&& detail::is_exotic_char<Char>::value>
|
||||
template <typename OutputIt, typename Locale, typename S, typename... T,
|
||||
typename Char = char_t<S>,
|
||||
bool enable = detail::is_output_iterator<OutputIt, Char>::value &&
|
||||
detail::is_locale<Locale>::value &&
|
||||
detail::is_exotic_char<Char>::value>
|
||||
inline auto format_to(OutputIt out, const Locale& loc, const S& format_str,
|
||||
Args&&... args) ->
|
||||
T&&... args) ->
|
||||
typename std::enable_if<enable, OutputIt>::type {
|
||||
return vformat_to(out, loc, detail::to_string_view(format_str),
|
||||
fmt::make_format_args<buffer_context<Char>>(args...));
|
||||
@@ -192,36 +192,36 @@ inline auto vformat_to_n(
|
||||
OutputIt out, size_t n, basic_string_view<Char> format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args)
|
||||
-> format_to_n_result<OutputIt> {
|
||||
detail::iterator_buffer<OutputIt, Char, detail::fixed_buffer_traits> buf(out,
|
||||
n);
|
||||
using traits = detail::fixed_buffer_traits;
|
||||
auto buf = detail::iterator_buffer<OutputIt, Char, traits>(out, n);
|
||||
detail::vformat_to(buf, format_str, args);
|
||||
return {buf.out(), buf.count()};
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
template <typename OutputIt, typename S, typename... T,
|
||||
typename Char = char_t<S>,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value&&
|
||||
detail::is_exotic_char<Char>::value)>
|
||||
inline auto format_to_n(OutputIt out, size_t n, const S& fmt,
|
||||
const Args&... args) -> format_to_n_result<OutputIt> {
|
||||
inline auto format_to_n(OutputIt out, size_t n, const S& fmt, T&&... args)
|
||||
-> format_to_n_result<OutputIt> {
|
||||
return vformat_to_n(out, n, detail::to_string_view(fmt),
|
||||
fmt::make_format_args<buffer_context<Char>>(args...));
|
||||
}
|
||||
|
||||
template <typename S, typename... Args, typename Char = char_t<S>,
|
||||
template <typename S, typename... T, typename Char = char_t<S>,
|
||||
FMT_ENABLE_IF(detail::is_exotic_char<Char>::value)>
|
||||
inline auto formatted_size(const S& fmt, Args&&... args) -> size_t {
|
||||
detail::counting_buffer<Char> buf;
|
||||
inline auto formatted_size(const S& fmt, T&&... args) -> size_t {
|
||||
auto buf = detail::counting_buffer<Char>();
|
||||
detail::vformat_to(buf, detail::to_string_view(fmt),
|
||||
fmt::make_format_args<buffer_context<Char>>(args...));
|
||||
return buf.count();
|
||||
}
|
||||
|
||||
inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) {
|
||||
wmemory_buffer buffer;
|
||||
detail::vformat_to(buffer, fmt, args);
|
||||
buffer.push_back(L'\0');
|
||||
if (std::fputws(buffer.data(), f) == -1)
|
||||
auto buf = wmemory_buffer();
|
||||
detail::vformat_to(buf, fmt, args);
|
||||
buf.push_back(L'\0');
|
||||
if (std::fputws(buf.data(), f) == -1)
|
||||
FMT_THROW(system_error(errno, FMT_STRING("cannot write to file")));
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace str
|
||||
tmp = ::strtoll(value_.c_str(),&endptr,10);
|
||||
switch(*endptr)
|
||||
{
|
||||
case 'b':
|
||||
case 'B':
|
||||
tmp *= 1ULL;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
case 'K':
|
||||
tmp *= 1024ULL;
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
#ifdef __FreeBSD__
|
||||
# include <sys/types.h>
|
||||
#else
|
||||
# include <sys/sysmacros.h>
|
||||
#endif
|
||||
|
||||
namespace l
|
||||
{
|
||||
|
||||
+9
-1
@@ -18,8 +18,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
# include <sys/param.h>
|
||||
# include <sys/mount.h>
|
||||
# define umount2(target,flags) unmount(target,flags)
|
||||
# define MNT_DETACH 0
|
||||
#else
|
||||
# include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
+59
-2
@@ -23,7 +23,10 @@
|
||||
|
||||
#include "fuse.h"
|
||||
|
||||
#include "ghc/filesystem.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace l
|
||||
@@ -68,15 +71,67 @@ namespace l
|
||||
*want_ = false;
|
||||
}
|
||||
|
||||
#define MAX_FUSE_MSG_SIZE 65535
|
||||
static const char MAX_PAGES_LIMIT_FILEPATH[] = "/proc/sys/fs/fuse/max_pages_limit";
|
||||
|
||||
static
|
||||
void
|
||||
want_if_capable_max_pages(fuse_conn_info *conn_,
|
||||
Config::Write &cfg_)
|
||||
{
|
||||
std::fstream f;
|
||||
uint64_t max_pages_limit;
|
||||
|
||||
if(ghc::filesystem::exists(MAX_PAGES_LIMIT_FILEPATH))
|
||||
{
|
||||
if(cfg_->fuse_msg_size > MAX_FUSE_MSG_SIZE)
|
||||
syslog_info("fuse_msg_size > %u: setting it to %u",
|
||||
MAX_FUSE_MSG_SIZE,
|
||||
MAX_FUSE_MSG_SIZE);
|
||||
cfg_->fuse_msg_size = std::min((uint64_t)cfg_->fuse_msg_size,
|
||||
(uint64_t)MAX_FUSE_MSG_SIZE);
|
||||
|
||||
f.open(MAX_PAGES_LIMIT_FILEPATH,f.in|f.out);
|
||||
if(f.is_open())
|
||||
{
|
||||
f >> max_pages_limit;
|
||||
syslog_info("%s currently set to %u",
|
||||
MAX_PAGES_LIMIT_FILEPATH,
|
||||
(uint64_t)max_pages_limit);
|
||||
if(cfg_->fuse_msg_size > max_pages_limit)
|
||||
{
|
||||
f.seekp(0);
|
||||
f << (uint64_t)cfg_->fuse_msg_size;
|
||||
f.flush();
|
||||
syslog_info("%s changed to %u",
|
||||
MAX_PAGES_LIMIT_FILEPATH,
|
||||
(uint64_t)cfg_->fuse_msg_size);
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cfg_->fuse_msg_size != FUSE_DEFAULT_MAX_MAX_PAGES)
|
||||
syslog_info("unable to open %s",MAX_PAGES_LIMIT_FILEPATH);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cfg_->fuse_msg_size > FUSE_DEFAULT_MAX_MAX_PAGES)
|
||||
syslog_info("fuse_msg_size request %u > %u: setting it to %u",
|
||||
(uint64_t)cfg_->fuse_msg_size,
|
||||
FUSE_DEFAULT_MAX_MAX_PAGES,
|
||||
FUSE_DEFAULT_MAX_MAX_PAGES);
|
||||
cfg_->fuse_msg_size = std::min((uint64_t)cfg_->fuse_msg_size,
|
||||
(uint64_t)FUSE_DEFAULT_MAX_MAX_PAGES);
|
||||
}
|
||||
|
||||
if(l::capable(conn_,FUSE_CAP_MAX_PAGES))
|
||||
{
|
||||
l::want(conn_,FUSE_CAP_MAX_PAGES);
|
||||
conn_->max_pages = cfg_->fuse_msg_size;
|
||||
syslog_info("requesting max pages size of %u",
|
||||
(uint64_t)cfg_->fuse_msg_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -144,13 +199,15 @@ namespace FUSE
|
||||
l::want_if_capable(conn_,FUSE_CAP_ATOMIC_O_TRUNC);
|
||||
l::want_if_capable(conn_,FUSE_CAP_BIG_WRITES);
|
||||
l::want_if_capable(conn_,FUSE_CAP_CACHE_SYMLINKS,&cfg->cache_symlinks);
|
||||
l::want_if_capable(conn_,FUSE_CAP_DIRECT_IO_ALLOW_MMAP,&cfg->direct_io_allow_mmap);
|
||||
l::want_if_capable(conn_,FUSE_CAP_DONT_MASK);
|
||||
l::want_if_capable(conn_,FUSE_CAP_EXPORT_SUPPORT,&cfg->export_support);
|
||||
l::want_if_capable(conn_,FUSE_CAP_IOCTL_DIR);
|
||||
l::want_if_capable(conn_,FUSE_CAP_PARALLEL_DIROPS);
|
||||
l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS,&cfg->readdirplus);
|
||||
//l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS_AUTO);
|
||||
l::want_if_capable(conn_,FUSE_CAP_POSIX_ACL,&cfg->posix_acl);
|
||||
l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS,&cfg->readdirplus);
|
||||
l::want_if_capable(conn_,FUSE_CAP_WRITEBACK_CACHE,&cfg->writeback_cache);
|
||||
// l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS_AUTO);
|
||||
l::want_if_capable_max_pages(conn_,cfg);
|
||||
conn_->want &= ~FUSE_CAP_POSIX_LOCKS;
|
||||
conn_->want &= ~FUSE_CAP_FLOCK_LOCKS;
|
||||
|
||||
+20
-31
@@ -25,23 +25,6 @@
|
||||
// SOFTWARE.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
//
|
||||
// To dynamically select std::filesystem where available on most platforms,
|
||||
// you could use:
|
||||
//
|
||||
// #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
|
||||
// #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
|
||||
// #define GHC_USE_STD_FS
|
||||
// #include <filesystem>
|
||||
// namespace fs = std::filesystem;
|
||||
// #endif
|
||||
// #endif
|
||||
// #ifndef GHC_USE_STD_FS
|
||||
// #include <ghc/filesystem.hpp>
|
||||
// namespace fs = ghc::filesystem;
|
||||
// #endif
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
#ifndef GHC_FILESYSTEM_H
|
||||
#define GHC_FILESYSTEM_H
|
||||
|
||||
@@ -53,7 +36,7 @@
|
||||
|
||||
#ifndef GHC_OS_DETECTED
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define GHC_OS_MACOS
|
||||
#define GHC_OS_APPLE
|
||||
#elif defined(__linux__)
|
||||
#define GHC_OS_LINUX
|
||||
#if defined(__ANDROID__)
|
||||
@@ -181,7 +164,7 @@
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
#endif
|
||||
#ifdef GHC_OS_MACOS
|
||||
#ifdef GHC_OS_APPLE
|
||||
#include <Availability.h>
|
||||
#endif
|
||||
|
||||
@@ -308,7 +291,7 @@
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch)
|
||||
#define GHC_FILESYSTEM_VERSION 10514L
|
||||
#define GHC_FILESYSTEM_VERSION 10515L
|
||||
|
||||
#if !defined(GHC_WITH_EXCEPTIONS) && (defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND))
|
||||
#define GHC_WITH_EXCEPTIONS
|
||||
@@ -1159,6 +1142,10 @@ GHC_FS_API void create_hard_link(const path& to, const path& new_hard_link, std:
|
||||
GHC_FS_API uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept;
|
||||
#endif
|
||||
|
||||
#if defined(GHC_OS_WINDOWS) && (!defined(__GLIBCXX__) || (defined(_GLIBCXX_HAVE__WFOPEN) && defined(_GLIBCXX_USE_WCHAR_T)))
|
||||
#define GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
|
||||
#endif
|
||||
|
||||
// Non-C++17 add-on std::fstream wrappers with path
|
||||
template <class charT, class traits = std::char_traits<charT>>
|
||||
class basic_filebuf : public std::basic_filebuf<charT, traits>
|
||||
@@ -1170,7 +1157,7 @@ public:
|
||||
const basic_filebuf& operator=(const basic_filebuf&) = delete;
|
||||
basic_filebuf<charT, traits>* open(const path& p, std::ios_base::openmode mode)
|
||||
{
|
||||
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
|
||||
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
|
||||
return std::basic_filebuf<charT, traits>::open(p.wstring().c_str(), mode) ? this : 0;
|
||||
#else
|
||||
return std::basic_filebuf<charT, traits>::open(p.string().c_str(), mode) ? this : 0;
|
||||
@@ -1183,7 +1170,7 @@ class basic_ifstream : public std::basic_ifstream<charT, traits>
|
||||
{
|
||||
public:
|
||||
basic_ifstream() {}
|
||||
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
|
||||
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
|
||||
explicit basic_ifstream(const path& p, std::ios_base::openmode mode = std::ios_base::in)
|
||||
: std::basic_ifstream<charT, traits>(p.wstring().c_str(), mode)
|
||||
{
|
||||
@@ -1206,7 +1193,7 @@ class basic_ofstream : public std::basic_ofstream<charT, traits>
|
||||
{
|
||||
public:
|
||||
basic_ofstream() {}
|
||||
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
|
||||
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
|
||||
explicit basic_ofstream(const path& p, std::ios_base::openmode mode = std::ios_base::out)
|
||||
: std::basic_ofstream<charT, traits>(p.wstring().c_str(), mode)
|
||||
{
|
||||
@@ -1229,7 +1216,7 @@ class basic_fstream : public std::basic_fstream<charT, traits>
|
||||
{
|
||||
public:
|
||||
basic_fstream() {}
|
||||
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
|
||||
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
|
||||
explicit basic_fstream(const path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
|
||||
: std::basic_fstream<charT, traits>(p.wstring().c_str(), mode)
|
||||
{
|
||||
@@ -3170,7 +3157,7 @@ GHC_INLINE path path::extension() const
|
||||
auto iter = end();
|
||||
const auto& fn = *--iter;
|
||||
impl_string_type::size_type pos = fn._path.rfind('.');
|
||||
if (pos != std::string::npos && pos > 0) {
|
||||
if (pos != std::string::npos && pos > 0 && fn._path != "..") {
|
||||
return path(fn._path.substr(pos), native_format);
|
||||
}
|
||||
}
|
||||
@@ -3987,7 +3974,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options
|
||||
}
|
||||
ssize_t br, bw;
|
||||
while (true) {
|
||||
do { br = ::read(in, buffer.data(), buffer.size()); } while(errno == EINTR);
|
||||
do { br = ::read(in, buffer.data(), buffer.size()); } while(errno == EINTR && !br);
|
||||
if(!br) {
|
||||
break;
|
||||
}
|
||||
@@ -4650,9 +4637,11 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err
|
||||
if (!::SetFileTime(file.get(), 0, 0, &ft)) {
|
||||
ec = detail::make_system_error();
|
||||
}
|
||||
#elif defined(GHC_OS_MACOS) && \
|
||||
(__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_13) || (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_11_0) || \
|
||||
(__TV_OS_VERSION_MIN_REQUIRED < __TVOS_11_0) || (__WATCH_OS_VERSION_MIN_REQUIRED < __WATCHOS_4_0)
|
||||
#elif defined(GHC_OS_APPLE) && \
|
||||
(__MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300 \
|
||||
|| __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000 \
|
||||
|| __TV_OS_VERSION_MIN_REQUIRED && __TVOS_VERSION_MIN_REQUIRED < 110000 \
|
||||
|| __WATCH_OS_VERSION_MIN_REQUIRED && __WATCHOS_VERSION_MIN_REQUIRED < 40000)
|
||||
struct ::stat fs;
|
||||
if (::stat(p.c_str(), &fs) == 0) {
|
||||
struct ::timeval tv[2];
|
||||
@@ -5704,7 +5693,7 @@ public:
|
||||
, _entry(nullptr)
|
||||
{
|
||||
if (!path.empty()) {
|
||||
do { _dir = ::opendir(path.native().c_str()); } while(errno == EINTR);
|
||||
do { _dir = ::opendir(path.native().c_str()); } while(errno == EINTR && !_dir);
|
||||
if (!_dir) {
|
||||
auto error = errno;
|
||||
_base = filesystem::path();
|
||||
@@ -5731,7 +5720,7 @@ public:
|
||||
do {
|
||||
skip = false;
|
||||
errno = 0;
|
||||
do { _entry = ::readdir(_dir); } while(errno == EINTR);
|
||||
do { _entry = ::readdir(_dir); } while(errno == EINTR && !_entry);
|
||||
if (_entry) {
|
||||
_dir_entry._path = _base;
|
||||
_dir_entry._path.append_name(_entry->d_name);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define NONSTD_OPTIONAL_LITE_HPP
|
||||
|
||||
#define optional_lite_MAJOR 3
|
||||
#define optional_lite_MINOR 5
|
||||
#define optional_lite_MINOR 6
|
||||
#define optional_lite_PATCH 0
|
||||
|
||||
#define optional_lite_VERSION optional_STRINGIFY(optional_lite_MAJOR) "." optional_STRINGIFY(optional_lite_MINOR) "." optional_STRINGIFY(optional_lite_PATCH)
|
||||
@@ -1555,7 +1555,7 @@ private:
|
||||
void initialize( V && value )
|
||||
{
|
||||
assert( ! has_value() );
|
||||
contained.construct_value( std::move( value ) );
|
||||
contained.construct_value( std::forward<V>( value ) );
|
||||
has_value_ = true;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user