mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-19 16:16:48 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05d81dbc23 | ||
|
|
00235c15bf | ||
|
|
3c5351af93 | ||
|
|
12b9fc1750 | ||
|
|
3d2283f10f | ||
|
|
192bb9c57e | ||
|
|
157dae0d2f | ||
|
|
00c814dc58 | ||
|
|
6d6fb45a3b | ||
|
|
f954be60a4 | ||
|
|
897f20bff8 | ||
|
|
c7c5b07389 | ||
|
|
d0b6cd1f38 | ||
|
|
1ad05d7783 | ||
|
|
1dc7bff6e6 | ||
|
|
18d684cd16 | ||
|
|
8f594e17d7 | ||
|
|
77269a8bac | ||
|
|
cd90193deb | ||
|
|
35fca6364f | ||
|
|
cd71af8c5b | ||
|
|
a7f26d3769 | ||
|
|
3fb7f8919a | ||
|
|
abc4ed4d9f | ||
|
|
dfa82699b9 | ||
|
|
b8beeaceb3 | ||
|
|
d9a79062b8 | ||
|
|
a22b79c416 | ||
|
|
b1f2e94a2f | ||
|
|
2ebd386b5b | ||
|
|
a8cd9b710e | ||
|
|
12d2cf7464 | ||
|
|
7e423cd9ce | ||
|
|
fa3218cb72 | ||
|
|
0395e7c776 | ||
|
|
a575cf76c2 | ||
|
|
93923177ee | ||
|
|
51858114b2 | ||
|
|
1513c92cbc | ||
|
|
7824586f76 | ||
|
|
158dda9f23 | ||
|
|
577bc67fa7 | ||
|
|
1a698e5ef5 | ||
|
|
a0885e33dc | ||
|
|
2ee6b4f581 | ||
|
|
709dda5069 | ||
|
|
f0f8e527b4 | ||
|
|
49474f01ca | ||
|
|
9e8b309a90 | ||
|
|
f7547d7cf5 | ||
|
|
bb02ab2cba | ||
|
|
fb1432e14e | ||
|
|
34d38cb0fb | ||
|
|
192a9d54d1 | ||
|
|
40574bd138 | ||
|
|
064fd5560f | ||
|
|
073d1b6f6f | ||
|
|
45f757dc60 | ||
|
|
939b4a0fe5 | ||
|
|
0fceb8e0a3 | ||
|
|
34662da806 | ||
|
|
7634eb1440 | ||
|
|
08cd5f89ff | ||
|
|
47f184a944 | ||
|
|
920f7fd049 | ||
|
|
a93ab6c2f5 | ||
|
|
a375f33eb4 | ||
|
|
1e7b84f7fd | ||
|
|
43cbd9c670 | ||
|
|
9f36eada14 | ||
|
|
30cdfa64b8 | ||
|
|
81e9544f7d | ||
|
|
3cb2045ebb | ||
|
|
652440fd8c | ||
|
|
6dc6fde641 | ||
|
|
66fdcc4ef7 | ||
|
|
cb35a374ac | ||
|
|
68210d9252 | ||
|
|
23b8e4582e | ||
|
|
13511ea72a | ||
|
|
3a50344cb9 | ||
|
|
9f27ad448a | ||
|
|
be6341e6f0 | ||
|
|
f7d3e8bf47 | ||
|
|
e541cdb755 | ||
|
|
74ed1b09ee | ||
|
|
9987111fa4 | ||
|
|
d0414d7c78 | ||
|
|
8f6a7ba79a | ||
|
|
ef8d8f306e | ||
|
|
1de01684e0 | ||
|
|
cd15b7a66a | ||
|
|
6b88258d81 | ||
|
|
8643d35ebf | ||
|
|
b7d7ace9bf | ||
|
|
1cfe1c3715 | ||
|
|
63b02b327b | ||
|
|
dbb13ef7ad | ||
|
|
6aec6c939a | ||
|
|
90ca14afff | ||
|
|
c7328293a0 | ||
|
|
cfaf812c62 | ||
|
|
47fb6e29c6 | ||
|
|
0c6c69e02e | ||
|
|
4b6cfdc68a | ||
|
|
309cfee52b | ||
|
|
9b3c085cf3 | ||
|
|
382ca876ca | ||
|
|
93acfb015c | ||
|
|
070ed08caa | ||
|
|
5d44161e77 | ||
|
|
6492fda483 | ||
|
|
447fd8b2fb | ||
|
|
2061211894 | ||
|
|
5030d5a5b4 | ||
|
|
4928944167 |
@@ -1,4 +1,6 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
|
||||
@@ -71,7 +71,7 @@ CFLAGS = -g -Wall \
|
||||
$(OPTS) \
|
||||
-Wno-unused-result \
|
||||
$(FUSE_CFLAGS) \
|
||||
-DFUSE_USE_VERSION=26 \
|
||||
-DFUSE_USE_VERSION=29 \
|
||||
-MMD \
|
||||
-DFLAG_NOPATH=$(FLAG_NOPATH) \
|
||||
-DFALLOCATE=$(FALLOCATE) \
|
||||
@@ -134,7 +134,7 @@ obj/%.o: src/%.cpp
|
||||
clean: rpm-clean
|
||||
$(RM) -rf obj
|
||||
$(RM) -f src/version.hpp
|
||||
$(RM) -f "$(TARGET)" "$(MANPAGE)" mount.mergerfs
|
||||
$(RM) -f "$(TARGET)" mount.mergerfs
|
||||
$(FIND) . -name "*~" -delete
|
||||
|
||||
distclean: clean
|
||||
@@ -143,14 +143,16 @@ distclean: clean
|
||||
install: install-base install-mount.mergerfs install-man
|
||||
|
||||
install-base: $(TARGET)
|
||||
$(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
|
||||
$(MKDIR) -p "$(INSTALLBINDIR)"
|
||||
$(INSTALL) -v -m 0755 "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
|
||||
|
||||
install-mount.mergerfs: mount.mergerfs
|
||||
$(MKDIR) -p "$(INSTALLBINDIR)"
|
||||
$(CP) -a "$<" "$(INSTALLBINDIR)/$<"
|
||||
|
||||
install-man: $(MANPAGE)
|
||||
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
|
||||
$(MKDIR) -p "$(INSTALLMAN1DIR)"
|
||||
$(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
|
||||
|
||||
install-strip: install-base
|
||||
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
|
||||
@@ -168,9 +170,7 @@ uninstall-man:
|
||||
|
||||
$(MANPAGE): README.md
|
||||
ifneq (,$(PANDOC))
|
||||
$(PANDOC) -s -t man -o $(MANPAGE) README.md
|
||||
else
|
||||
$(CP) man/mergerfs.1 .
|
||||
$(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
|
||||
endif
|
||||
|
||||
man: $(MANPAGE)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
% mergerfs(1) mergerfs user manual
|
||||
% Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
% 2016-02-21
|
||||
% 2016-10-13
|
||||
|
||||
# NAME
|
||||
|
||||
@@ -12,7 +12,7 @@ mergerfs -o<options> <srcmounts> <mountpoint>
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
**mergerfs** is a union filesystem geared towards simplifing storage and management of files across numerous commodity storage devices. It is similar to **mhddfs**, **unionfs**, and **aufs**.
|
||||
**mergerfs** is a union filesystem geared towards simplifying storage and management of files across numerous commodity storage devices. It is similar to **mhddfs**, **unionfs**, and **aufs**.
|
||||
|
||||
# FEATURES
|
||||
|
||||
@@ -24,7 +24,7 @@ mergerfs -o<options> <srcmounts> <mountpoint>
|
||||
* Safe to run as root
|
||||
* Opportunistic credential caching
|
||||
* Works with heterogeneous filesystem types
|
||||
* Handling of writes to full drives
|
||||
* Handling of writes to full drives (transparently move file to drive with capacity)
|
||||
* Handles pool of readonly and read/write drives
|
||||
|
||||
# OPTIONS
|
||||
@@ -34,36 +34,41 @@ mergerfs -o<options> <srcmounts> <mountpoint>
|
||||
* **defaults**: a shortcut for FUSE's **atomic_o_trunc**, **auto_cache**, **big_writes**, **default_permissions**, **splice_move**, **splice_read**, and **splice_write**. These options seem to provide the best performance.
|
||||
* **direct_io**: causes FUSE to bypass an addition caching step which can increase write speeds at the detriment of read speed.
|
||||
* **minfreespace**: the minimum space value used for creation policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively. (default: 4G)
|
||||
* **moveonenospc**: when enabled (set to **true**) if a **write** fails with **ENOSPC** a scan of all drives will be done looking for the drive with most free space which is at least the size of the file plus the amount which failed to write. An attempt to move the file to that drive will occur (keeping all metadata possible) and if successful the original is unlinked and the write retried. (default: false)
|
||||
* **moveonenospc**: when enabled (set to **true**) if a **write** fails with **ENOSPC** or **EDQUOT** a scan of all drives will be done looking for the drive with most free space which is at least the size of the file plus the amount which failed to write. An attempt to move the file to that drive will occur (keeping all metadata possible) and if successful the original is unlinked and the write retried. (default: false)
|
||||
* **func.<func>=<policy>**: sets the specific FUSE function's policy. See below for the list of value types. Example: **func.getattr=newest**
|
||||
* **category.<category>=<policy>**: Sets policy of all FUSE functions in the provided category. Example: **category.create=mfs**
|
||||
* **fsname**: 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.
|
||||
|
||||
**NOTE:** Options are evaluated in the order listed so if the options are **func.rmdir=rand,category.action=ff** the **action** category setting will override the **rmdir** setting.
|
||||
|
||||
###srcmounts###
|
||||
|
||||
The source mounts argument is a colon (':') delimited list of paths. To make it simpler to include multiple source mounts without having to modify your [fstab](http://linux.die.net/man/5/fstab) we also support [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will probably expand it.**
|
||||
The srcmounts (source mounts) argument is a colon (':') delimited list of paths to be included in the pool. It does not matter if the paths are on the same or different drives nor does it matter the filesystem. Used and available space will not be duplicated for paths on the same device and any features which aren't supported by the underlying filesystem (such as file attributes or extended attributes) will return the appropriate errors.
|
||||
|
||||
To make it easier to include multiple source mounts mergerfs supports [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will expand it.**
|
||||
|
||||
```
|
||||
$ mergerfs /mnt/disk\*:/mnt/cdrom /media/drives
|
||||
$ mergerfs -o defaults,allow_other /mnt/disk\*:/mnt/cdrom /media/drives
|
||||
```
|
||||
|
||||
The above line will use all mount points in /mnt prefixed with *disk* and the directory *cdrom*.
|
||||
The above line will use all mount points in /mnt prefixed with **disk** and the **cdrom**.
|
||||
|
||||
In /etc/fstab it'd look like the following:
|
||||
To have the pool mounted at boot or otherwise accessable from related tools use **/etc/fstab**.
|
||||
|
||||
```
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other 0 0
|
||||
```
|
||||
|
||||
**NOTE:** the globbing is done at mount or xattr update time. If a new directory is added matching the glob after the fact it will not be included.
|
||||
**NOTE:** the globbing is done at mount or xattr update time (see below). If a new directory is added matching the glob after the fact it will not be automatically included.
|
||||
|
||||
**NOTE:** for mounting via **fstab** to work you must have **mount.fuse** installed. For Ubuntu/Debian it is included in the **fuse** package.
|
||||
|
||||
# FUNCTIONS / POLICIES / CATEGORIES
|
||||
|
||||
The filesystem has a number of functions. Those functions are grouped into 3 categories: **action**, **create**, **search**. These functions and categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a function or category though some are not very practical. For instance: **rand** (Random) may be useful for file creation (create) but could lead to very odd behavior if used for `chmod`.
|
||||
The POSIX filesystem API has a number of functions. **creat**, **stat**, **chown**, etc. In mergerfs these functions are grouped into 3 categories: **action**, **create**, and **search**. Functions and categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a function or category though some are not very practical. For instance: **rand** (random) may be useful for file creation (create) but could lead to very odd behavior if used for `chmod` (though only if there were more than one copy of the file).
|
||||
|
||||
All policies when used to create will ignore drives which are mounted readonly. This allows for read/write and readonly drives to be mixed together.
|
||||
Policies, when called to create, will ignore drives which are readonly or have less than **minfreespace**. This allows for read/write and readonly drives to be mixed together and keep drives which may remount as readonly on error from further affecting the pool.
|
||||
|
||||
#### Function / Category classifications ####
|
||||
|
||||
@@ -74,24 +79,29 @@ All policies when used to create will ignore drives which are mounted readonly.
|
||||
| search | access, getattr, getxattr, ioctl, listxattr, open, readlink |
|
||||
| N/A | fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, release, statfs, write |
|
||||
|
||||
Due to FUSE limitations **ioctl** behaves differently if its acting on a directory. It'll use the **getattr** policy to find and open the directory before issuing the **ioctl**. In other cases where something may be searched (to confirm a directory exists across all source mounts) then **getattr** will be used.
|
||||
Due to FUSE limitations **ioctl** behaves differently if its acting on a directory. It'll use the **getattr** policy to find and open the directory before issuing the **ioctl**. In other cases where something may be searched (to confirm a directory exists across all source mounts) **getattr** will also be used.
|
||||
|
||||
#### Policy descriptions ####
|
||||
|
||||
Most policies when called to create will filter out drives which are readonly or have less than **minfreespace**.
|
||||
|
||||
| Policy | Description |
|
||||
|--------------|-------------|
|
||||
| all | Search category: acts like **ff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** perform on all read/write drives with **minfreespace**. **create** filters the same way but acts like **ff**. |
|
||||
| eplfs (existing path, least free space) | If the path exists on multiple drives use the one with the least free space. Falls back to **lfs**. |
|
||||
| epmfs (existing path, most free space) | If the path exists on multiple drives use the one with the most free space. Falls back to **mfs**. |
|
||||
| all | Search category: acts like **ff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **ff**. It will exclude readonly drives and those with free space less than **minfreespace**. |
|
||||
| epall (existing path, all) | Search category: acts like **epff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all existing paths found. **create** works like **epff**. It will exclude readonly drives and those with free space less than **minfreespace**. |
|
||||
| epff | Given the order of the drives, as defined at mount time or when configured via the xattr interface, act on the first one found where the path already exists. For **create** category it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). Falls back to **ff**. |
|
||||
| eplfs (existing path, least free space) | If the path exists on multiple drives use the one with the least free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lfs**. |
|
||||
| eplus (existing path, least used space) | If the path exists on multiple drives use the one with the least used space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lus**. |
|
||||
| epmfs (existing path, most free space) | If the path exists on multiple drives use the one with the most free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
|
||||
| eprand (existing path, random) | Calls **epall** and then randomizes. |
|
||||
| erofs | Exclusively return **-1** with **errno** set to **EROFS**. By setting **create** functions to this you can in effect turn the filesystem readonly. |
|
||||
| ff (first found) | Given the order of the drives, as defined at mount time or when configured via xattr interface, act on the first one found. |
|
||||
| lfs (least free space) | Pick the drive with the least available free space but more than **minfreespace**. Falls back to **mfs**. |
|
||||
| mfs (most free space) | Use the drive with the most available free space. Falls back to **ff**. |
|
||||
| newest (newest file) | Pick the file / directory with the largest mtime. |
|
||||
| ff (first found) | Given the order of the drives, as defined at mount time or when configured via xattr interface, act on the first one found. For **create** category it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
|
||||
| lfs (least free space) | Pick the drive with the least available free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
|
||||
| lus (least used space) | Pick the drive with the least used space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
|
||||
| mfs (most free space) | Pick the drive with the most available free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **ff**. |
|
||||
| newest (newest file) | Pick the file / directory with the largest mtime. For **create** category it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
|
||||
| rand (random) | Calls **all** and then randomizes. |
|
||||
|
||||
**epff**, **eplfs**, **eplus**, and **epmf** are path preserving policies. As the descriptions above explain they will only consider drives where the path being accessed exists. Non-path preserving policies will clone paths as necessary.
|
||||
|
||||
#### Defaults ####
|
||||
|
||||
| Category | Policy |
|
||||
@@ -102,14 +112,14 @@ Most policies when called to create will filter out drives which are readonly or
|
||||
|
||||
#### rename & link ####
|
||||
|
||||
[rename](http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky function in a merged system. Normally if a rename can't be done atomically due to the source and destination paths existing on different mount points it will return `-1` with `errno = EXDEV`. The atomic rename is most critical for replacing files in place atomically (such as securing writing to a temp file and then replacing a target). The problem is that by merging multiple paths you can have N instances of the source and destinations on different drives. This can lead to several undesirable situtations with or without errors and it's not entirely obvious what to do when an error occurs.
|
||||
[rename](http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky function in a merged system. Normally if a rename can't be done atomically due to the source and destination paths existing on different mount points it will return **-1** with **errno = EXDEV**. The atomic rename is most critical for replacing files in place atomically (such as securing writing to a temp file and then replacing a target). The problem is that by merging multiple paths you can have N instances of the source and destinations on different drives. This can lead to several undesirable situtations with or without errors and it's not entirely obvious what to do when an error occurs.
|
||||
|
||||
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 complient with POSIX requirements. However, many applications fail to handle EXDEV at all and treat it as a normal error or they only partially support EXDEV (don't respond the same as `mv` would). 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.
|
||||
|
||||
* If using a policy which tries to preserve directories (epmfs,eplfs)
|
||||
* Using the `rename` policy get the list of files to rename
|
||||
* 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 run `create` policy
|
||||
* If failure with ENOENT run **create** policy
|
||||
* If create policy returns the same drive as currently evaluating then clone the path
|
||||
* Re-attempt rename
|
||||
* If **any** of the renames succeed the higher level rename is considered a success
|
||||
@@ -117,9 +127,9 @@ Originally mergerfs would return EXDEV whenever a rename was requested which was
|
||||
* On success:
|
||||
* Remove the target from all drives with no source file
|
||||
* Remove the source from all drives which failed to rename
|
||||
* If using a policy which does **not** try to preserve directories
|
||||
* Using the `rename` policy get the list of files to rename
|
||||
* Using the `getattr` policy get the target path
|
||||
* 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 source drive != target drive:
|
||||
* Clone target path from target drive to source drive
|
||||
@@ -132,15 +142,13 @@ Originally mergerfs would return EXDEV whenever a rename was requested which was
|
||||
|
||||
The the removals are subject to normal entitlement checks.
|
||||
|
||||
The above behavior will help minimize the likelihood of EXDEV being returned but it will still be possible. To remove the possibility all together mergerfs would need to perform the as `mv` does when it receives EXDEV normally.
|
||||
The above behavior will help minimize the likelihood of EXDEV being returned but it will still be possible. To remove the possibility all together mergerfs would need to perform the as **mv** does when it receives EXDEV normally.
|
||||
|
||||
`link` uses the same basic strategy.
|
||||
**link** uses the same basic strategy.
|
||||
|
||||
#### readdir ####
|
||||
|
||||
[readdir](http://linux.die.net/man/3/readdir) is different from all other filesystem functions. It certainly could have it's own set of policies to tweak its behavior. At this time it provides a simple **first found** merging of directories and files found. That is: only the first file or directory found for a directory is returned. Given how FUSE works though the data representing the returned entry comes from **getattr**.
|
||||
|
||||
It could be extended to offer the ability to see all files found. Perhaps concatenating **#** and a number to the name. But to really be useful you'd need to be able to access them which would complicate file lookup.
|
||||
[readdir](http://linux.die.net/man/3/readdir) is different from all other filesystem functions. While it could have it's own set of policies to tweak its behavior at this time it provides a simple union of files and directories found. Remember that any action or information queried about these files and directories come from the respective function. For instance: an **ls** is a **readdir** and for each file/directory returned **getattr** is called. Meaning the policy of **getattr** is responsible for choosing the file/directory which is the source of the metadata you see in an **ls**.
|
||||
|
||||
#### statvfs ####
|
||||
|
||||
@@ -155,7 +163,7 @@ First get the code from [github](http://github.com/trapexit/mergerfs).
|
||||
```
|
||||
$ git clone https://github.com/trapexit/mergerfs.git
|
||||
$ # or
|
||||
$ wget https://github.com/trapexit/mergerfs/archive/master.zip
|
||||
$ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.tar.gz
|
||||
```
|
||||
|
||||
#### Debian / Ubuntu
|
||||
@@ -195,38 +203,40 @@ $ sudo make install
|
||||
|
||||
There is a pseudo file available at the mount point which allows for the runtime modification of certain **mergerfs** options. The file will not show up in **readdir** but can be **stat**'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
|
||||
|
||||
Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
|
||||
Even if xattrs are disabled for mergerfs the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls against this pseudo file will still work.
|
||||
|
||||
Any changes made at runtime are **not** persisted. If you wish for values to persist they must be included as options wherever you configure the mounting of mergerfs (fstab).
|
||||
|
||||
##### Keys #####
|
||||
|
||||
Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
|
||||
Use `xattr -l /mount/point/.mergerfs` to see all supported keys. Some are informational and therefore readonly.
|
||||
|
||||
##### user.mergerfs.srcmounts #####
|
||||
###### user.mergerfs.srcmounts ######
|
||||
|
||||
For **user.mergerfs.srcmounts** there are several instructions available for manipulating the list. The value provided is just as the value used at mount time. A colon (':') delimited list of full path globs.
|
||||
Used to query or modify the list of source mounts. When modifying there are several shortcuts to easy manipulation of the list.
|
||||
|
||||
| Instruction | Description |
|
||||
| Value | Description |
|
||||
|--------------|-------------|
|
||||
| [list] | set |
|
||||
| +<[list] | prepend |
|
||||
| +>[list] | append |
|
||||
| [list] | set |
|
||||
| +<[list] | prepend |
|
||||
| +>[list] | append |
|
||||
| -[list] | remove all values provided |
|
||||
| -< | remove first in list |
|
||||
| -> | remove last in list |
|
||||
|
||||
##### minfreespace #####
|
||||
###### minfreespace ######
|
||||
|
||||
Input: interger with an optional multiplier suffix. **K**, **M**, or **G**.
|
||||
|
||||
Output: value in bytes
|
||||
|
||||
##### moveonenospc #####
|
||||
###### moveonenospc ######
|
||||
|
||||
Input: **true** and **false**
|
||||
|
||||
Ouput: **true** or **false**
|
||||
|
||||
##### categories / funcs #####
|
||||
###### categories / funcs ######
|
||||
|
||||
Input: short policy string as described elsewhere in this document
|
||||
|
||||
@@ -261,7 +271,7 @@ newest
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
```
|
||||
|
||||
#### mergerfs file xattrs ####
|
||||
#### file / directory xattrs ####
|
||||
|
||||
While they won't show up when using [listxattr](http://linux.die.net/man/2/listxattr) **mergerfs** offers a number of special xattrs to query information about the files served. To access the values you will need to issue a [getxattr](http://linux.die.net/man/2/getxattr) for one of the following:
|
||||
|
||||
@@ -286,15 +296,19 @@ A B C
|
||||
|
||||
# TOOLING
|
||||
|
||||
Find tooling to help with managing `mergerfs` at: https://github.com/trapexit/mergerfs-tools
|
||||
|
||||
* mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
|
||||
* mergerfs.mktrash: Creates FreeDesktop.org Trash specification compatible directories on a mergerfs mount
|
||||
* 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.mktrash: Creates FreeDesktop.org Trash specification compatible directories on a mergerfs mount
|
||||
* https://github.com/trapexit/scorch
|
||||
* scorch: A tool to help discover silent corruption of files
|
||||
|
||||
# TIPS / NOTES
|
||||
|
||||
* Detailed guides to setting up a backup solution using mergerfs and other technologies: https://github.com/trapexit/backup-and-recovery-howtos
|
||||
* https://github.com/trapexit/backup-and-recovery-howtos : A set of guides / howtos on creating a data storage system, backing it up, maintaining it, and recovering from failure.
|
||||
* If you don't see some directories / files you expect in a merged point be sure the user has permission to all the underlying directories. If `/drive0/a` has is owned by `root:root` with ACLs set to `0700` and `/drive1/a` is `root:root` and `0755` you'll see only `/drive1/a`. Use `mergerfs.fsck` to audit the drive for out of sync permissions.
|
||||
* Do *not* use `direct_io` if you expect applications (such as rtorrent) to [mmap](http://linux.die.net/man/2/mmap) files. It is not currently supported in FUSE w/ `direct_io` enabled.
|
||||
* Since POSIX gives you only error or success on calls its difficult to determine the proper behavior when applying the behavior to multiple targets. **mergerfs** will return an error only if all attempts of an action fail. Any success will lead to a success returned.
|
||||
* The recommended options are **defaults,allow_other**. The **allow_other** is to allow users who are not the one which executed mergerfs access to the mountpoint. **defaults** is described above and should offer the best performance. It's possible that if you're running on an older platform the **splice** features aren't available and could error. In that case simply use the other options manually.
|
||||
* If write performance is valued more than read it may be useful to enable **direct_io**. Best to benchmark with and without and choose appropriately.
|
||||
@@ -304,6 +318,14 @@ Find tooling to help with managing `mergerfs` at: https://github.com/trapexit/me
|
||||
|
||||
# KNOWN ISSUES / BUGS
|
||||
|
||||
#### rtorrent fails with ENODEV (No such device)
|
||||
|
||||
Be sure to turn off `direct_io`. rtorrent and some other applications use [mmap](http://linux.die.net/man/2/mmap) to read and write to files and offer no failback to traditional methods. FUSE does not currently support mmap while using `direct_io`. There will be a performance penalty on writes with `direct_io` off but it's the only way to get such applications to work. If the performance loss is too high for other apps you can mount mergerfs twice. Once with `direct_io` enabled and one without it.
|
||||
|
||||
#### mmap performance is really bad
|
||||
|
||||
There [is a bug](https://lkml.org/lkml/2016/3/16/260) 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/5/11/59).
|
||||
|
||||
#### 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 situtation 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.
|
||||
@@ -332,19 +354,72 @@ If suddenly the mergerfs mount point disappears and `Transport endpoint is not c
|
||||
|
||||
In order to fix this please install newer versions of libfuse. If using a Debian based distro (Debian,Ubuntu,Mint) you can likely just install newer versions of [libfuse](https://packages.debian.org/unstable/libfuse2) and [fuse](https://packages.debian.org/unstable/fuse) from the repo of a newer release.
|
||||
|
||||
#### mergerfs under heavy load and memory preasure leads to kernel panic
|
||||
|
||||
https://lkml.org/lkml/2016/9/14/527
|
||||
|
||||
```
|
||||
[25192.515454] kernel BUG at /build/linux-a2WvEb/linux-4.4.0/mm/workingset.c:346!
|
||||
[25192.517521] invalid opcode: 0000 [#1] SMP
|
||||
[25192.519602] Modules linked in: netconsole ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 configfs binfmt_misc veth bridge stp llc nf_conntrack_ipv6 nf_defrag_ipv6 xt_conntrack ip6table_filter ip6_tables xt_multiport iptable_filter ipt_MASQUERADE nf_nat_masquerade_ipv4 xt_comment xt_nat iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack xt_CHECKSUM xt_tcpudp iptable_mangle ip_tables x_tables intel_rapl x86_pkg_temp_thermal intel_powerclamp eeepc_wmi asus_wmi coretemp sparse_keymap kvm_intel ppdev kvm irqbypass mei_me 8250_fintek input_leds serio_raw parport_pc tpm_infineon mei shpchp mac_hid parport lpc_ich autofs4 drbg ansi_cprng dm_crypt algif_skcipher af_alg btrfs raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor raid6_pq libcrc32c raid0 multipath linear raid10 raid1 i915 crct10dif_pclmul crc32_pclmul aesni_intel i2c_algo_bit aes_x86_64 drm_kms_helper lrw gf128mul glue_helper ablk_helper syscopyarea cryptd sysfillrect sysimgblt fb_sys_fops drm ahci r8169 libahci mii wmi fjes video [last unloaded: netconsole]
|
||||
[25192.540910] CPU: 2 PID: 63 Comm: kswapd0 Not tainted 4.4.0-36-generic #55-Ubuntu
|
||||
[25192.543411] Hardware name: System manufacturer System Product Name/P8H67-M PRO, BIOS 3904 04/27/2013
|
||||
[25192.545840] task: ffff88040cae6040 ti: ffff880407488000 task.ti: ffff880407488000
|
||||
[25192.548277] RIP: 0010:[<ffffffff811ba501>] [<ffffffff811ba501>] shadow_lru_isolate+0x181/0x190
|
||||
[25192.550706] RSP: 0018:ffff88040748bbe0 EFLAGS: 00010002
|
||||
[25192.553127] RAX: 0000000000001c81 RBX: ffff8802f91ee928 RCX: ffff8802f91eeb38
|
||||
[25192.555544] RDX: ffff8802f91ee938 RSI: ffff8802f91ee928 RDI: ffff8804099ba2c0
|
||||
[25192.557914] RBP: ffff88040748bc08 R08: 000000000001a7b6 R09: 000000000000003f
|
||||
[25192.560237] R10: 000000000001a750 R11: 0000000000000000 R12: ffff8804099ba2c0
|
||||
[25192.562512] R13: ffff8803157e9680 R14: ffff8803157e9668 R15: ffff8804099ba2c8
|
||||
[25192.564724] FS: 0000000000000000(0000) GS:ffff88041f280000(0000) knlGS:0000000000000000
|
||||
[25192.566990] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
|
||||
[25192.569201] CR2: 00007ffabb690000 CR3: 0000000001e0a000 CR4: 00000000000406e0
|
||||
[25192.571419] Stack:
|
||||
[25192.573550] ffff8804099ba2c0 ffff88039e4f86f0 ffff8802f91ee928 ffff8804099ba2c8
|
||||
[25192.575695] ffff88040748bd08 ffff88040748bc58 ffffffff811b99bf 0000000000000052
|
||||
[25192.577814] 0000000000000000 ffffffff811ba380 000000000000008a 0000000000000080
|
||||
[25192.579947] Call Trace:
|
||||
[25192.582022] [<ffffffff811b99bf>] __list_lru_walk_one.isra.3+0x8f/0x130
|
||||
[25192.584137] [<ffffffff811ba380>] ? memcg_drain_all_list_lrus+0x190/0x190
|
||||
[25192.586165] [<ffffffff811b9a83>] list_lru_walk_one+0x23/0x30
|
||||
[25192.588145] [<ffffffff811ba544>] scan_shadow_nodes+0x34/0x50
|
||||
[25192.590074] [<ffffffff811a0e9d>] shrink_slab.part.40+0x1ed/0x3d0
|
||||
[25192.591985] [<ffffffff811a53da>] shrink_zone+0x2ca/0x2e0
|
||||
[25192.593863] [<ffffffff811a64ce>] kswapd+0x51e/0x990
|
||||
[25192.595737] [<ffffffff811a5fb0>] ? mem_cgroup_shrink_node_zone+0x1c0/0x1c0
|
||||
[25192.597613] [<ffffffff810a0808>] kthread+0xd8/0xf0
|
||||
[25192.599495] [<ffffffff810a0730>] ? kthread_create_on_node+0x1e0/0x1e0
|
||||
[25192.601335] [<ffffffff8182e34f>] ret_from_fork+0x3f/0x70
|
||||
[25192.603193] [<ffffffff810a0730>] ? kthread_create_on_node+0x1e0/0x1e0
|
||||
```
|
||||
|
||||
There is a bug in the kernel. A work around appears to be turning off `splice`. Add `no_splice_write,no_splice_move,no_splice_read` to mergerfs' options. Should be placed after `defaults` if it is used since it will turn them on.
|
||||
|
||||
# FAQ
|
||||
|
||||
#### Why use mergerfs over mhddfs?
|
||||
|
||||
mhddfs is no longer maintained and has some known stability and security issues (see below).
|
||||
mhddfs is no longer maintained and has some known stability and security issues (see below). MergerFS provides a superset of mhddfs' features and should offer the same or maybe better performance.
|
||||
|
||||
#### Why use mergerfs over aufs?
|
||||
|
||||
While aufs can offer better peak performance mergerfs offers more configurability and is generally easier to use. mergerfs however doesn't offer the overlay features which tends to result in whiteout files being left around the underlying filesystems.
|
||||
While aufs can offer better peak performance mergerfs offers more configurability and is generally easier to use. mergerfs however doesn't offer the same overlay features (which tends to result in whiteout files being left around the underlying filesystems.)
|
||||
|
||||
#### Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation / striping?
|
||||
|
||||
A single drive failure will lead to full pool failure without additional redundancy. mergerfs performs a similar behavior without the catastrophic failure and lack of recovery. Drives can fail and all other data will continue to be accessable.
|
||||
With simple JBOD / drive concatenation / stripping / RAID0 a single drive failure will lead to full pool failure. mergerfs performs a similar behavior without the catastrophic failure and general lack of recovery. Drives can fail and all other data will continue to be accessable.
|
||||
|
||||
When combined with something like [SnapRaid](http://www.snapraid.it) and/or an offsite full backup solution you can have the flexibilty of JBOD without the single point of failure.
|
||||
|
||||
#### Can drives be written to directly? Outside of mergerfs while pooled?
|
||||
|
||||
Yes. It will be represented immediately in the pool as the policies would describe.
|
||||
|
||||
#### Why do I get an "out of space" error even though the system says there's lots of space left?
|
||||
|
||||
Please reread the sections above about policies, path preserving, and the **moveonenospc** option. If the policy is path preserving and a drive is almost full and the drive the policy would pick then the writing of the file may fill the drive and receive ENOSPC errors. That is expected with those settings. If you don't want that: enable **moveonenospc** and don't use a path preserving policy.
|
||||
|
||||
|
||||
#### It's mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?
|
||||
|
||||
@@ -371,3 +446,10 @@ For non-Linux systems mergerfs uses a read-write lock and changes credentials on
|
||||
#### Support development
|
||||
* Gratipay: https://gratipay.com/~trapexit
|
||||
* BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
|
||||
# LINKS
|
||||
|
||||
* http://github.com/trapexit/mergerfs
|
||||
* http://github.com/trapexit/mergerfs-tools
|
||||
* http://github.com/trapexit/scorch
|
||||
* http://github.com/trapexit/backup-and-recovery-howtos
|
||||
|
||||
+275
-77
@@ -1,5 +1,5 @@
|
||||
.\"t
|
||||
.TH "mergerfs" "1" "2016\-02\-21" "mergerfs user manual" ""
|
||||
.TH "mergerfs" "1" "2016\-10\-13" "mergerfs user manual" ""
|
||||
.SH NAME
|
||||
.PP
|
||||
mergerfs \- another (FUSE based) union filesystem
|
||||
@@ -8,7 +8,7 @@ mergerfs \- another (FUSE based) union filesystem
|
||||
mergerfs \-o<options> <srcmounts> <mountpoint>
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
\f[B]mergerfs\f[] is a union filesystem geared towards simplifing
|
||||
\f[B]mergerfs\f[] is a union filesystem geared towards simplifying
|
||||
storage and management of files across numerous commodity storage
|
||||
devices.
|
||||
It is similar to \f[B]mhddfs\f[], \f[B]unionfs\f[], and \f[B]aufs\f[].
|
||||
@@ -30,7 +30,8 @@ Opportunistic credential caching
|
||||
.IP \[bu] 2
|
||||
Works with heterogeneous filesystem types
|
||||
.IP \[bu] 2
|
||||
Handling of writes to full drives
|
||||
Handling of writes to full drives (transparently move file to drive with
|
||||
capacity)
|
||||
.IP \[bu] 2
|
||||
Handles pool of readonly and read/write drives
|
||||
.SH OPTIONS
|
||||
@@ -51,9 +52,9 @@ kilobyte, megabyte, and gigabyte respectively.
|
||||
(default: 4G)
|
||||
.IP \[bu] 2
|
||||
\f[B]moveonenospc\f[]: when enabled (set to \f[B]true\f[]) if a
|
||||
\f[B]write\f[] fails with \f[B]ENOSPC\f[] a scan of all drives will be
|
||||
done looking for the drive with most free space which is at least the
|
||||
size of the file plus the amount which failed to write.
|
||||
\f[B]write\f[] fails with \f[B]ENOSPC\f[] or \f[B]EDQUOT\f[] a scan of
|
||||
all drives will be done looking for the drive with most free space which
|
||||
is at least the size of the file plus the amount which failed to write.
|
||||
An attempt to move the file to that drive will occur (keeping all
|
||||
metadata possible) and if successful the original is unlinked and the
|
||||
write retried.
|
||||
@@ -67,6 +68,11 @@ Example: \f[B]func.getattr=newest\f[]
|
||||
\f[B]category.<category>=<policy>\f[]: Sets policy of all FUSE functions
|
||||
in the provided category.
|
||||
Example: \f[B]category.create=mfs\f[]
|
||||
.IP \[bu] 2
|
||||
\f[B]fsname\f[]: sets the name of the filesystem as seen in
|
||||
\f[B]mount\f[], \f[B]df\f[], etc.
|
||||
Defaults to a list of the source paths concatenated together with the
|
||||
longest common prefix removed.
|
||||
.PP
|
||||
\f[B]NOTE:\f[] Options are evaluated in the order listed so if the
|
||||
options are \f[B]func.rmdir=rand,category.action=ff\f[] the
|
||||
@@ -74,24 +80,31 @@ options are \f[B]func.rmdir=rand,category.action=ff\f[] the
|
||||
setting.
|
||||
.SS srcmounts
|
||||
.PP
|
||||
The source mounts argument is a colon (\[aq]:\[aq]) delimited list of
|
||||
paths.
|
||||
To make it simpler to include multiple source mounts without having to
|
||||
modify your fstab (http://linux.die.net/man/5/fstab) we also support
|
||||
The srcmounts (source mounts) argument is a colon (\[aq]:\[aq])
|
||||
delimited list of paths to be included in the pool.
|
||||
It does not matter if the paths are on the same or different drives nor
|
||||
does it matter the filesystem.
|
||||
Used and available space will not be duplicated for paths on the same
|
||||
device and any features which aren\[aq]t supported by the underlying
|
||||
filesystem (such as file attributes or extended attributes) will return
|
||||
the appropriate errors.
|
||||
.PP
|
||||
To make it easier to include multiple source mounts mergerfs supports
|
||||
globbing (http://linux.die.net/man/7/glob).
|
||||
\f[B]The globbing tokens MUST be escaped when using via the shell else
|
||||
the shell itself will probably expand it.\f[]
|
||||
the shell itself will expand it.\f[]
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
$\ mergerfs\ /mnt/disk\\*:/mnt/cdrom\ /media/drives
|
||||
$\ mergerfs\ \-o\ defaults,allow_other\ /mnt/disk\\*:/mnt/cdrom\ /media/drives
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
The above line will use all mount points in /mnt prefixed with
|
||||
\f[I]disk\f[] and the directory \f[I]cdrom\f[].
|
||||
\f[B]disk\f[] and the \f[B]cdrom\f[].
|
||||
.PP
|
||||
In /etc/fstab it\[aq]d look like the following:
|
||||
To have the pool mounted at boot or otherwise accessable from related
|
||||
tools use \f[B]/etc/fstab\f[].
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
@@ -100,24 +113,33 @@ In /etc/fstab it\[aq]d look like the following:
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
\f[B]NOTE:\f[] the globbing is done at mount or xattr update time.
|
||||
\f[B]NOTE:\f[] the globbing is done at mount or xattr update time (see
|
||||
below).
|
||||
If a new directory is added matching the glob after the fact it will not
|
||||
be included.
|
||||
be automatically included.
|
||||
.PP
|
||||
\f[B]NOTE:\f[] for mounting via \f[B]fstab\f[] to work you must have
|
||||
\f[B]mount.fuse\f[] installed.
|
||||
For Ubuntu/Debian it is included in the \f[B]fuse\f[] package.
|
||||
.SH FUNCTIONS / POLICIES / CATEGORIES
|
||||
.PP
|
||||
The filesystem has a number of functions.
|
||||
Those functions are grouped into 3 categories: \f[B]action\f[],
|
||||
\f[B]create\f[], \f[B]search\f[].
|
||||
These functions and categories can be assigned a policy which dictates
|
||||
how \f[B]mergerfs\f[] behaves.
|
||||
The POSIX filesystem API has a number of functions.
|
||||
\f[B]creat\f[], \f[B]stat\f[], \f[B]chown\f[], etc.
|
||||
In mergerfs these functions are grouped into 3 categories:
|
||||
\f[B]action\f[], \f[B]create\f[], and \f[B]search\f[].
|
||||
Functions and categories can be assigned a policy which dictates how
|
||||
\f[B]mergerfs\f[] behaves.
|
||||
Any policy can be assigned to a function or category though some are not
|
||||
very practical.
|
||||
For instance: \f[B]rand\f[] (Random) may be useful for file creation
|
||||
(create) but could lead to very odd behavior if used for \f[C]chmod\f[].
|
||||
For instance: \f[B]rand\f[] (random) may be useful for file creation
|
||||
(create) but could lead to very odd behavior if used for \f[C]chmod\f[]
|
||||
(though only if there were more than one copy of the file).
|
||||
.PP
|
||||
All policies when used to create will ignore drives which are mounted
|
||||
readonly.
|
||||
This allows for read/write and readonly drives to be mixed together.
|
||||
Policies, when called to create, will ignore drives which are readonly
|
||||
or have less than \f[B]minfreespace\f[].
|
||||
This allows for read/write and readonly drives to be mixed together and
|
||||
keep drives which may remount as readonly on error from further
|
||||
affecting the pool.
|
||||
.SS Function / Category classifications
|
||||
.PP
|
||||
.TS
|
||||
@@ -158,12 +180,9 @@ on a directory.
|
||||
It\[aq]ll use the \f[B]getattr\f[] policy to find and open the directory
|
||||
before issuing the \f[B]ioctl\f[].
|
||||
In other cases where something may be searched (to confirm a directory
|
||||
exists across all source mounts) then \f[B]getattr\f[] will be used.
|
||||
exists across all source mounts) \f[B]getattr\f[] will also be used.
|
||||
.SS Policy descriptions
|
||||
.PP
|
||||
Most policies when called to create will filter out drives which are
|
||||
readonly or have less than \f[B]minfreespace\f[].
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
l l.
|
||||
@@ -179,25 +198,66 @@ T}@T{
|
||||
Search category: acts like \f[B]ff\f[].
|
||||
Action category: apply to all found.
|
||||
Create category: for \f[B]mkdir\f[], \f[B]mknod\f[], and
|
||||
\f[B]symlink\f[] perform on all read/write drives with
|
||||
\f[B]symlink\f[] it will apply to all found.
|
||||
\f[B]create\f[] works like \f[B]ff\f[].
|
||||
It will exclude readonly drives and those with free space less than
|
||||
\f[B]minfreespace\f[].
|
||||
\f[B]create\f[] filters the same way but acts like \f[B]ff\f[].
|
||||
T}
|
||||
T{
|
||||
epall (existing path, all)
|
||||
T}@T{
|
||||
Search category: acts like \f[B]epff\f[].
|
||||
Action category: apply to all found.
|
||||
Create category: for \f[B]mkdir\f[], \f[B]mknod\f[], and
|
||||
\f[B]symlink\f[] it will apply to all existing paths found.
|
||||
\f[B]create\f[] works like \f[B]epff\f[].
|
||||
It will exclude readonly drives and those with free space less than
|
||||
\f[B]minfreespace\f[].
|
||||
T}
|
||||
T{
|
||||
epff
|
||||
T}@T{
|
||||
Given the order of the drives, as defined at mount time or when
|
||||
configured via the xattr interface, act on the first one found where the
|
||||
path already exists.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[] (unless there is no
|
||||
other option).
|
||||
Falls back to \f[B]ff\f[].
|
||||
T}
|
||||
T{
|
||||
eplfs (existing path, least free space)
|
||||
T}@T{
|
||||
If the path exists on multiple drives use the one with the least free
|
||||
space.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]lfs\f[].
|
||||
T}
|
||||
T{
|
||||
eplus (existing path, least used space)
|
||||
T}@T{
|
||||
If the path exists on multiple drives use the one with the least used
|
||||
space.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]lus\f[].
|
||||
T}
|
||||
T{
|
||||
epmfs (existing path, most free space)
|
||||
T}@T{
|
||||
If the path exists on multiple drives use the one with the most free
|
||||
space.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]mfs\f[].
|
||||
T}
|
||||
T{
|
||||
eprand (existing path, random)
|
||||
T}@T{
|
||||
Calls \f[B]epall\f[] and then randomizes.
|
||||
T}
|
||||
T{
|
||||
erofs
|
||||
T}@T{
|
||||
Exclusively return \f[B]\-1\f[] with \f[B]errno\f[] set to
|
||||
@@ -210,24 +270,41 @@ ff (first found)
|
||||
T}@T{
|
||||
Given the order of the drives, as defined at mount time or when
|
||||
configured via xattr interface, act on the first one found.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[] (unless there is no
|
||||
other option).
|
||||
T}
|
||||
T{
|
||||
lfs (least free space)
|
||||
T}@T{
|
||||
Pick the drive with the least available free space but more than
|
||||
\f[B]minfreespace\f[].
|
||||
Pick the drive with the least available free space.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]mfs\f[].
|
||||
T}
|
||||
T{
|
||||
lus (least used space)
|
||||
T}@T{
|
||||
Pick the drive with the least used space.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]mfs\f[].
|
||||
T}
|
||||
T{
|
||||
mfs (most free space)
|
||||
T}@T{
|
||||
Use the drive with the most available free space.
|
||||
Pick the drive with the most available free space.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[].
|
||||
Falls back to \f[B]ff\f[].
|
||||
T}
|
||||
T{
|
||||
newest (newest file)
|
||||
T}@T{
|
||||
Pick the file / directory with the largest mtime.
|
||||
For \f[B]create\f[] category it will exclude readonly drives and those
|
||||
with free space less than \f[B]minfreespace\f[] (unless there is no
|
||||
other option).
|
||||
T}
|
||||
T{
|
||||
rand (random)
|
||||
@@ -235,6 +312,12 @@ T}@T{
|
||||
Calls \f[B]all\f[] and then randomizes.
|
||||
T}
|
||||
.TE
|
||||
.PP
|
||||
\f[B]epff\f[], \f[B]eplfs\f[], \f[B]eplus\f[], and \f[B]epmf\f[] are
|
||||
path preserving policies.
|
||||
As the descriptions above explain they will only consider drives where
|
||||
the path being accessed exists.
|
||||
Non\-path preserving policies will clone paths as necessary.
|
||||
.SS Defaults
|
||||
.PP
|
||||
.TS
|
||||
@@ -268,7 +351,7 @@ rename (http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky
|
||||
function in a merged system.
|
||||
Normally if a rename can\[aq]t be done atomically due to the source and
|
||||
destination paths existing on different mount points it will return
|
||||
\f[C]\-1\f[] with \f[C]errno\ =\ EXDEV\f[].
|
||||
\f[B]\-1\f[] with \f[B]errno = EXDEV\f[].
|
||||
The atomic rename is most critical for replacing files in place
|
||||
atomically (such as securing writing to a temp file and then replacing a
|
||||
target).
|
||||
@@ -287,14 +370,15 @@ same as \f[C]mv\f[] would).
|
||||
Such apps include: gvfsd\-fuse v1.20.3 and prior, Finder / CIFS/SMB
|
||||
client in Apple OSX 10.9+, NZBGet, Samba\[aq]s recycling bin feature.
|
||||
.IP \[bu] 2
|
||||
If using a policy which tries to preserve directories (epmfs,eplfs)
|
||||
If using a \f[B]create\f[] policy which tries to preserve directory
|
||||
paths (epff,eplfs,eplus,epmfs)
|
||||
.IP \[bu] 2
|
||||
Using the \f[C]rename\f[] policy get the list of files to rename
|
||||
Using the \f[B]rename\f[] policy get the list of files to rename
|
||||
.IP \[bu] 2
|
||||
For each file attempt rename:
|
||||
.RS 2
|
||||
.IP \[bu] 2
|
||||
If failure with ENOENT run \f[C]create\f[] policy
|
||||
If failure with ENOENT run \f[B]create\f[] policy
|
||||
.IP \[bu] 2
|
||||
If create policy returns the same drive as currently evaluating then
|
||||
clone the path
|
||||
@@ -316,11 +400,12 @@ Remove the target from all drives with no source file
|
||||
Remove the source from all drives which failed to rename
|
||||
.RE
|
||||
.IP \[bu] 2
|
||||
If using a policy which does \f[B]not\f[] try to preserve directories
|
||||
If using a \f[B]create\f[] policy which does \f[B]not\f[] try to
|
||||
preserve directory paths
|
||||
.IP \[bu] 2
|
||||
Using the \f[C]rename\f[] policy get the list of files to rename
|
||||
Using the \f[B]rename\f[] policy get the list of files to rename
|
||||
.IP \[bu] 2
|
||||
Using the \f[C]getattr\f[] policy get the target path
|
||||
Using the \f[B]getattr\f[] policy get the target path
|
||||
.IP \[bu] 2
|
||||
For each file attempt rename:
|
||||
.RS 2
|
||||
@@ -351,26 +436,22 @@ The the removals are subject to normal entitlement checks.
|
||||
The above behavior will help minimize the likelihood of EXDEV being
|
||||
returned but it will still be possible.
|
||||
To remove the possibility all together mergerfs would need to perform
|
||||
the as \f[C]mv\f[] does when it receives EXDEV normally.
|
||||
the as \f[B]mv\f[] does when it receives EXDEV normally.
|
||||
.PP
|
||||
\f[C]link\f[] uses the same basic strategy.
|
||||
\f[B]link\f[] uses the same basic strategy.
|
||||
.SS readdir
|
||||
.PP
|
||||
readdir (http://linux.die.net/man/3/readdir) is different from all other
|
||||
filesystem functions.
|
||||
It certainly could have it\[aq]s own set of policies to tweak its
|
||||
behavior.
|
||||
At this time it provides a simple \f[B]first found\f[] merging of
|
||||
directories and files found.
|
||||
That is: only the first file or directory found for a directory is
|
||||
returned.
|
||||
Given how FUSE works though the data representing the returned entry
|
||||
comes from \f[B]getattr\f[].
|
||||
.PP
|
||||
It could be extended to offer the ability to see all files found.
|
||||
Perhaps concatenating \f[B]#\f[] and a number to the name.
|
||||
But to really be useful you\[aq]d need to be able to access them which
|
||||
would complicate file lookup.
|
||||
While it could have it\[aq]s own set of policies to tweak its behavior
|
||||
at this time it provides a simple union of files and directories found.
|
||||
Remember that any action or information queried about these files and
|
||||
directories come from the respective function.
|
||||
For instance: an \f[B]ls\f[] is a \f[B]readdir\f[] and for each
|
||||
file/directory returned \f[B]getattr\f[] is called.
|
||||
Meaning the policy of \f[B]getattr\f[] is responsible for choosing the
|
||||
file/directory which is the source of the metadata you see in an
|
||||
\f[B]ls\f[].
|
||||
.SS statvfs
|
||||
.PP
|
||||
statvfs (http://linux.die.net/man/2/statvfs) normalizes the source
|
||||
@@ -391,7 +472,7 @@ First get the code from github (http://github.com/trapexit/mergerfs).
|
||||
\f[C]
|
||||
$\ git\ clone\ https://github.com/trapexit/mergerfs.git
|
||||
$\ #\ or
|
||||
$\ wget\ https://github.com/trapexit/mergerfs/archive/master.zip
|
||||
$\ wget\ https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs\-<ver>.tar.gz
|
||||
\f[]
|
||||
.fi
|
||||
.SS Debian / Ubuntu
|
||||
@@ -442,25 +523,29 @@ The file will not show up in \f[B]readdir\f[] but can be
|
||||
\f[B]stat\f[]\[aq]ed and manipulated via
|
||||
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls.
|
||||
.PP
|
||||
Even if xattrs are disabled the
|
||||
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls will
|
||||
still work.
|
||||
Even if xattrs are disabled for mergerfs the
|
||||
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls
|
||||
against this pseudo file will still work.
|
||||
.PP
|
||||
Any changes made at runtime are \f[B]not\f[] persisted.
|
||||
If you wish for values to persist they must be included as options
|
||||
wherever you configure the mounting of mergerfs (fstab).
|
||||
.SS Keys
|
||||
.PP
|
||||
Use \f[C]xattr\ \-l\ /mount/point/.mergerfs\f[] to see all supported
|
||||
keys.
|
||||
Some are informational and therefore readonly.
|
||||
.SS user.mergerfs.srcmounts
|
||||
.PP
|
||||
For \f[B]user.mergerfs.srcmounts\f[] there are several instructions
|
||||
available for manipulating the list.
|
||||
The value provided is just as the value used at mount time.
|
||||
A colon (\[aq]:\[aq]) delimited list of full path globs.
|
||||
Used to query or modify the list of source mounts.
|
||||
When modifying there are several shortcuts to easy manipulation of the
|
||||
list.
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
l l.
|
||||
T{
|
||||
Instruction
|
||||
Value
|
||||
T}@T{
|
||||
Description
|
||||
T}
|
||||
@@ -544,7 +629,7 @@ newest
|
||||
/tmp/a:/tmp/b:/tmp/c
|
||||
\f[]
|
||||
.fi
|
||||
.SS mergerfs file xattrs
|
||||
.SS file / directory xattrs
|
||||
.PP
|
||||
While they won\[aq]t show up when using
|
||||
listxattr (http://linux.die.net/man/2/listxattr) \f[B]mergerfs\f[]
|
||||
@@ -581,25 +666,41 @@ A\ B\ C
|
||||
\f[]
|
||||
.fi
|
||||
.SH TOOLING
|
||||
.PP
|
||||
Find tooling to help with managing \f[C]mergerfs\f[] at:
|
||||
.IP \[bu] 2
|
||||
https://github.com/trapexit/mergerfs\-tools
|
||||
.IP \[bu] 2
|
||||
fsck.mergerfs: Provides permissions and ownership auditing and the
|
||||
mergerfs.ctl: A tool to make it easier to query and configure mergerfs
|
||||
at runtime
|
||||
.IP \[bu] 2
|
||||
mergerfs.fsck: Provides permissions and ownership auditing and the
|
||||
ability to fix them
|
||||
.IP \[bu] 2
|
||||
mergerfs.dedup: Will help identify and optionally remove duplicate files
|
||||
.IP \[bu] 2
|
||||
mergerfs.mktrash: Creates FreeDesktop.org Trash specification compatible
|
||||
directories on a mergerfs mount
|
||||
.IP \[bu] 2
|
||||
https://github.com/trapexit/scorch
|
||||
.IP \[bu] 2
|
||||
scorch: A tool to help discover silent corruption of files
|
||||
.SH TIPS / NOTES
|
||||
.IP \[bu] 2
|
||||
https://github.com/trapexit/backup\-and\-recovery\-howtos : A set of
|
||||
guides / howtos on creating a data storage system, backing it up,
|
||||
maintaining it, and recovering from failure.
|
||||
.IP \[bu] 2
|
||||
If you don\[aq]t see some directories / files you expect in a merged
|
||||
point be sure the user has permission to all the underlying directories.
|
||||
If \f[C]/drive0/a\f[] has is owned by \f[C]root:root\f[] with ACLs set
|
||||
to \f[C]0700\f[] and \f[C]/drive1/a\f[] is \f[C]root:root\f[] and
|
||||
\f[C]0755\f[] you\[aq]ll see only \f[C]/drive1/a\f[].
|
||||
Use \f[C]fsck.mergerfs\f[] to audit the drive for out of sync
|
||||
Use \f[C]mergerfs.fsck\f[] to audit the drive for out of sync
|
||||
permissions.
|
||||
.IP \[bu] 2
|
||||
Do \f[I]not\f[] use \f[C]direct_io\f[] if you expect applications (such
|
||||
as rtorrent) to mmap (http://linux.die.net/man/2/mmap) files.
|
||||
It is not currently supported in FUSE w/ \f[C]direct_io\f[] enabled.
|
||||
.IP \[bu] 2
|
||||
Since POSIX gives you only error or success on calls its difficult to
|
||||
determine the proper behavior when applying the behavior to multiple
|
||||
targets.
|
||||
@@ -648,6 +749,23 @@ Due to previously mentioned issues its generally best to set
|
||||
This will help limit the confusion of tools such as
|
||||
rsync (http://linux.die.net/man/1/rsync).
|
||||
.SH KNOWN ISSUES / BUGS
|
||||
.SS rtorrent fails with ENODEV (No such device)
|
||||
.PP
|
||||
Be sure to turn off \f[C]direct_io\f[].
|
||||
rtorrent and some other applications use
|
||||
mmap (http://linux.die.net/man/2/mmap) to read and write to files and
|
||||
offer no failback to traditional methods.
|
||||
FUSE does not currently support mmap while using \f[C]direct_io\f[].
|
||||
There will be a performance penalty on writes with \f[C]direct_io\f[]
|
||||
off but it\[aq]s the only way to get such applications to work.
|
||||
If the performance loss is too high for other apps you can mount
|
||||
mergerfs twice.
|
||||
Once with \f[C]direct_io\f[] enabled and one without it.
|
||||
.SS mmap performance is really bad
|
||||
.PP
|
||||
There is a bug (https://lkml.org/lkml/2016/3/16/260) 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/5/11/59).
|
||||
.SS Trashing files occasionally fails
|
||||
.PP
|
||||
This is the same issue as with Samba.
|
||||
@@ -748,25 +866,96 @@ install newer versions of
|
||||
libfuse (https://packages.debian.org/unstable/libfuse2) and
|
||||
fuse (https://packages.debian.org/unstable/fuse) from the repo of a
|
||||
newer release.
|
||||
.SS mergerfs under heavy load and memory preasure leads to kernel panic
|
||||
.PP
|
||||
https://lkml.org/lkml/2016/9/14/527
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
[25192.515454]\ kernel\ BUG\ at\ /build/linux\-a2WvEb/linux\-4.4.0/mm/workingset.c:346!
|
||||
[25192.517521]\ invalid\ opcode:\ 0000\ [#1]\ SMP
|
||||
[25192.519602]\ Modules\ linked\ in:\ netconsole\ ip6t_REJECT\ nf_reject_ipv6\ ipt_REJECT\ nf_reject_ipv4\ configfs\ binfmt_misc\ veth\ bridge\ stp\ llc\ nf_conntrack_ipv6\ nf_defrag_ipv6\ xt_conntrack\ ip6table_filter\ ip6_tables\ xt_multiport\ iptable_filter\ ipt_MASQUERADE\ nf_nat_masquerade_ipv4\ xt_comment\ xt_nat\ iptable_nat\ nf_conntrack_ipv4\ nf_defrag_ipv4\ nf_nat_ipv4\ nf_nat\ nf_conntrack\ xt_CHECKSUM\ xt_tcpudp\ iptable_mangle\ ip_tables\ x_tables\ intel_rapl\ x86_pkg_temp_thermal\ intel_powerclamp\ eeepc_wmi\ asus_wmi\ coretemp\ sparse_keymap\ kvm_intel\ ppdev\ kvm\ irqbypass\ mei_me\ 8250_fintek\ input_leds\ serio_raw\ parport_pc\ tpm_infineon\ mei\ shpchp\ mac_hid\ parport\ lpc_ich\ autofs4\ drbg\ ansi_cprng\ dm_crypt\ algif_skcipher\ af_alg\ btrfs\ raid456\ async_raid6_recov\ async_memcpy\ async_pq\ async_xor\ async_tx\ xor\ raid6_pq\ libcrc32c\ raid0\ multipath\ linear\ raid10\ raid1\ i915\ crct10dif_pclmul\ crc32_pclmul\ aesni_intel\ i2c_algo_bit\ aes_x86_64\ drm_kms_helper\ lrw\ gf128mul\ glue_helper\ ablk_helper\ syscopyarea\ cryptd\ sysfillrect\ sysimgblt\ fb_sys_fops\ drm\ ahci\ r8169\ libahci\ mii\ wmi\ fjes\ video\ [last\ unloaded:\ netconsole]
|
||||
[25192.540910]\ CPU:\ 2\ PID:\ 63\ Comm:\ kswapd0\ Not\ tainted\ 4.4.0\-36\-generic\ #55\-Ubuntu
|
||||
[25192.543411]\ Hardware\ name:\ System\ manufacturer\ System\ Product\ Name/P8H67\-M\ PRO,\ BIOS\ 3904\ 04/27/2013
|
||||
[25192.545840]\ task:\ ffff88040cae6040\ ti:\ ffff880407488000\ task.ti:\ ffff880407488000
|
||||
[25192.548277]\ RIP:\ 0010:[<ffffffff811ba501>]\ \ [<ffffffff811ba501>]\ shadow_lru_isolate+0x181/0x190
|
||||
[25192.550706]\ RSP:\ 0018:ffff88040748bbe0\ \ EFLAGS:\ 00010002
|
||||
[25192.553127]\ RAX:\ 0000000000001c81\ RBX:\ ffff8802f91ee928\ RCX:\ ffff8802f91eeb38
|
||||
[25192.555544]\ RDX:\ ffff8802f91ee938\ RSI:\ ffff8802f91ee928\ RDI:\ ffff8804099ba2c0
|
||||
[25192.557914]\ RBP:\ ffff88040748bc08\ R08:\ 000000000001a7b6\ R09:\ 000000000000003f
|
||||
[25192.560237]\ R10:\ 000000000001a750\ R11:\ 0000000000000000\ R12:\ ffff8804099ba2c0
|
||||
[25192.562512]\ R13:\ ffff8803157e9680\ R14:\ ffff8803157e9668\ R15:\ ffff8804099ba2c8
|
||||
[25192.564724]\ FS:\ \ 0000000000000000(0000)\ GS:ffff88041f280000(0000)\ knlGS:0000000000000000
|
||||
[25192.566990]\ CS:\ \ 0010\ DS:\ 0000\ ES:\ 0000\ CR0:\ 0000000080050033
|
||||
[25192.569201]\ CR2:\ 00007ffabb690000\ CR3:\ 0000000001e0a000\ CR4:\ 00000000000406e0
|
||||
[25192.571419]\ Stack:
|
||||
[25192.573550]\ \ ffff8804099ba2c0\ ffff88039e4f86f0\ ffff8802f91ee928\ ffff8804099ba2c8
|
||||
[25192.575695]\ \ ffff88040748bd08\ ffff88040748bc58\ ffffffff811b99bf\ 0000000000000052
|
||||
[25192.577814]\ \ 0000000000000000\ ffffffff811ba380\ 000000000000008a\ 0000000000000080
|
||||
[25192.579947]\ Call\ Trace:
|
||||
[25192.582022]\ \ [<ffffffff811b99bf>]\ __list_lru_walk_one.isra.3+0x8f/0x130
|
||||
[25192.584137]\ \ [<ffffffff811ba380>]\ ?\ memcg_drain_all_list_lrus+0x190/0x190
|
||||
[25192.586165]\ \ [<ffffffff811b9a83>]\ list_lru_walk_one+0x23/0x30
|
||||
[25192.588145]\ \ [<ffffffff811ba544>]\ scan_shadow_nodes+0x34/0x50
|
||||
[25192.590074]\ \ [<ffffffff811a0e9d>]\ shrink_slab.part.40+0x1ed/0x3d0
|
||||
[25192.591985]\ \ [<ffffffff811a53da>]\ shrink_zone+0x2ca/0x2e0
|
||||
[25192.593863]\ \ [<ffffffff811a64ce>]\ kswapd+0x51e/0x990
|
||||
[25192.595737]\ \ [<ffffffff811a5fb0>]\ ?\ mem_cgroup_shrink_node_zone+0x1c0/0x1c0
|
||||
[25192.597613]\ \ [<ffffffff810a0808>]\ kthread+0xd8/0xf0
|
||||
[25192.599495]\ \ [<ffffffff810a0730>]\ ?\ kthread_create_on_node+0x1e0/0x1e0
|
||||
[25192.601335]\ \ [<ffffffff8182e34f>]\ ret_from_fork+0x3f/0x70
|
||||
[25192.603193]\ \ [<ffffffff810a0730>]\ ?\ kthread_create_on_node+0x1e0/0x1e0
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
There is a bug in the kernel.
|
||||
A work around appears to be turning off \f[C]splice\f[].
|
||||
Add \f[C]no_splice_write,no_splice_move,no_splice_read\f[] to
|
||||
mergerfs\[aq] options.
|
||||
Should be placed after \f[C]defaults\f[] if it is used since it will
|
||||
turn them on.
|
||||
.SH FAQ
|
||||
.SS Why use mergerfs over mhddfs?
|
||||
.PP
|
||||
mhddfs is no longer maintained and has some known stability and security
|
||||
issues (see below).
|
||||
MergerFS provides a superset of mhddfs\[aq] features and should offer
|
||||
the same or maybe better performance.
|
||||
.SS Why use mergerfs over aufs?
|
||||
.PP
|
||||
While aufs can offer better peak performance mergerfs offers more
|
||||
configurability and is generally easier to use.
|
||||
mergerfs however doesn\[aq]t offer the overlay features which tends to
|
||||
result in whiteout files being left around the underlying filesystems.
|
||||
mergerfs however doesn\[aq]t offer the same overlay features (which
|
||||
tends to result in whiteout files being left around the underlying
|
||||
filesystems.)
|
||||
.SS Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation /
|
||||
striping?
|
||||
.PP
|
||||
A single drive failure will lead to full pool failure without additional
|
||||
redundancy.
|
||||
With simple JBOD / drive concatenation / stripping / RAID0 a single
|
||||
drive failure will lead to full pool failure.
|
||||
mergerfs performs a similar behavior without the catastrophic failure
|
||||
and lack of recovery.
|
||||
and general lack of recovery.
|
||||
Drives can fail and all other data will continue to be accessable.
|
||||
.PP
|
||||
When combined with something like SnapRaid (http://www.snapraid.it)
|
||||
and/or an offsite full backup solution you can have the flexibilty of
|
||||
JBOD without the single point of failure.
|
||||
.SS Can drives be written to directly? Outside of mergerfs while pooled?
|
||||
.PP
|
||||
Yes.
|
||||
It will be represented immediately in the pool as the policies would
|
||||
describe.
|
||||
.SS Why do I get an "out of space" error even though the system says
|
||||
there\[aq]s lots of space left?
|
||||
.PP
|
||||
Please reread the sections above about policies, path preserving, and
|
||||
the \f[B]moveonenospc\f[] option.
|
||||
If the policy is path preserving and a drive is almost full and the
|
||||
drive the policy would pick then the writing of the file may fill the
|
||||
drive and receive ENOSPC errors.
|
||||
That is expected with those settings.
|
||||
If you don\[aq]t want that: enable \f[B]moveonenospc\f[] and don\[aq]t
|
||||
use a path preserving policy.
|
||||
.SS It\[aq]s mentioned that there are some security issues with mhddfs.
|
||||
What are they? How does mergerfs address them?
|
||||
.PP
|
||||
@@ -790,7 +979,7 @@ behavior poses a problem.
|
||||
\f[B]libfuse\f[] is multithreaded by default.
|
||||
We\[aq]d need to lock access to \f[B]seteuid\f[] and \f[B]setegid\f[]
|
||||
with a mutex so that the several threads aren\[aq]t stepping on one
|
||||
another and files end up with weird permissions and ownership.
|
||||
anofther and files end up with weird permissions and ownership.
|
||||
This however wouldn\[aq]t scale well.
|
||||
With lots of calls the contention on that mutex would be extremely high.
|
||||
Thankfully on Linux and OSX we have a better solution.
|
||||
@@ -853,5 +1042,14 @@ email: trapexit\@spawn.link
|
||||
Gratipay: https://gratipay.com/~trapexit
|
||||
.IP \[bu] 2
|
||||
BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
|
||||
.SH LINKS
|
||||
.IP \[bu] 2
|
||||
http://github.com/trapexit/mergerfs
|
||||
.IP \[bu] 2
|
||||
http://github.com/trapexit/mergerfs\-tools
|
||||
.IP \[bu] 2
|
||||
http://github.com/trapexit/scorch
|
||||
.IP \[bu] 2
|
||||
http://github.com/trapexit/backup\-and\-recovery\-howtos
|
||||
.SH AUTHORS
|
||||
Antonio SJ Musumeci <trapexit@spawn.link>.
|
||||
|
||||
+4
-5
@@ -17,10 +17,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_access.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
@@ -34,7 +33,7 @@ static
|
||||
int
|
||||
_access(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const int mask)
|
||||
{
|
||||
@@ -48,7 +47,7 @@ _access(Policy::Func::Search searchFunc,
|
||||
|
||||
fs::path::make(basepaths[0],fusepath,fullpath);
|
||||
|
||||
rv = ::eaccess(fullpath.c_str(),mask);
|
||||
rv = fs::eaccess(fullpath,mask);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
+4
-3
@@ -16,11 +16,12 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_chmod.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
@@ -42,7 +43,7 @@ _chmod_loop_core(const string *basepath,
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::chmod(fullpath.c_str(),mode);
|
||||
rv = fs::chmod(fullpath,mode);
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
}
|
||||
@@ -68,7 +69,7 @@ static
|
||||
int
|
||||
_chmod(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode)
|
||||
{
|
||||
|
||||
+4
-4
@@ -16,12 +16,12 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_chown.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
#include "rwlock.hpp"
|
||||
@@ -45,7 +45,7 @@ _chown_loop_core(const string *basepath,
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
rv = ::lchown(fullpath.c_str(),uid,gid);
|
||||
rv = fs::lchown(fullpath,uid,gid);
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ static
|
||||
int
|
||||
_chown(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const uid_t uid,
|
||||
const gid_t gid)
|
||||
|
||||
+1
-1
@@ -14,12 +14,12 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_clonefile.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
|
||||
+2
-2
@@ -19,11 +19,11 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
#define MINFREESPACE_DEFAULT (4294967295ULL)
|
||||
#define POLICYINIT(X) X(policies[FuseFunc::Enum::X])
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ namespace mergerfs
|
||||
std::string destmount;
|
||||
std::vector<std::string> srcmounts;
|
||||
mutable pthread_rwlock_t srcmountslock;
|
||||
size_t minfreespace;
|
||||
uint64_t minfreespace;
|
||||
bool moveonenospc;
|
||||
|
||||
public:
|
||||
|
||||
+5
-8
@@ -16,18 +16,15 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
@@ -57,7 +54,7 @@ _create_core(const string &existingpath,
|
||||
|
||||
fs::path::make(&createpath,fusepath,fullpath);
|
||||
|
||||
fd = ::open(fullpath.c_str(),flags,mode);
|
||||
fd = fs::open(fullpath,flags,mode);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -71,7 +68,7 @@ int
|
||||
_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode,
|
||||
const int flags,
|
||||
|
||||
+2
-1
@@ -14,9 +14,10 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(ENODATA) && !defined(ENOATTR)
|
||||
#define ENOATTR ENODATA
|
||||
#endif
|
||||
|
||||
#if defined(ENOATTR) && !defined(ENODATA)
|
||||
#define ENODATA ENOATTR
|
||||
#endif
|
||||
|
||||
#if !defined(ENOATTR) && !defined(ENODATA)
|
||||
#error "Neither ENOATTR or ENODATA defined: please contact mergerfs author with platform information"
|
||||
#endif
|
||||
+3
-19
@@ -18,10 +18,9 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_fallocate.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
@@ -32,22 +31,7 @@ _fallocate(const int fd,
|
||||
{
|
||||
int rv;
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
rv = ::fallocate(fd,mode,offset,len);
|
||||
#elif defined _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
|
||||
if(mode)
|
||||
{
|
||||
rv = -1;
|
||||
errno = EOPNOTSUPP;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = ::posix_fallocate(fd,offset,len);
|
||||
}
|
||||
#else
|
||||
rv = -1;
|
||||
errno = EOPNOTSUPP;
|
||||
#endif
|
||||
rv = fs::fallocate(fd,mode,offset,len);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
+3
-6
@@ -16,12 +16,9 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
@@ -30,7 +27,7 @@ _fgetattr(const int fd,
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::fstat(fd,&st);
|
||||
rv = fs::fstat(fd,st);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,8 +14,8 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace mergerfs
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_flock.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_flock(const int fd,
|
||||
const int operation)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::flock(fd,operation);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
flock(const char *fusepath,
|
||||
fuse_file_info *ffi,
|
||||
int op)
|
||||
{
|
||||
FileInfo* fi = reinterpret_cast<FileInfo*>(ffi->fh);
|
||||
|
||||
return _flock(fi->fd,op);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace fuse
|
||||
{
|
||||
int
|
||||
flock(const char *fusepath,
|
||||
fuse_file_info *ffi,
|
||||
int op);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -16,10 +16,10 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_dup.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
@@ -27,11 +27,11 @@ _flush(const int fd)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::dup(fd);
|
||||
rv = fs::dup(fd);
|
||||
if(rv == -1)
|
||||
errno = EIO;
|
||||
else
|
||||
rv = ::close(rv);
|
||||
rv = fs::close(rv);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
+46
-41
@@ -17,18 +17,17 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fcntl.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_base_realpath.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_statvfs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
@@ -46,7 +45,7 @@ namespace fs
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::lstat(path.c_str(),&st);
|
||||
rv = fs::lstat(path,st);
|
||||
|
||||
return LSTAT_SUCCEEDED(rv);
|
||||
}
|
||||
@@ -60,57 +59,62 @@ namespace fs
|
||||
}
|
||||
|
||||
bool
|
||||
statvfs(const string &path,
|
||||
struct statvfs &st)
|
||||
info(const string &path,
|
||||
bool &readonly,
|
||||
uint64_t &spaceavail,
|
||||
uint64_t &spaceused)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = ::statvfs(path.c_str(),&st);
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
{
|
||||
readonly = StatVFS::readonly(st);
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
}
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
info(const string &path,
|
||||
bool &readonly,
|
||||
size_t &spaceavail)
|
||||
{
|
||||
bool rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(rv)
|
||||
{
|
||||
readonly = StatVFS::readonly(st);
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
readonly(const string &path)
|
||||
{
|
||||
bool rv;
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
|
||||
return (rv && StatVFS::readonly(st));
|
||||
return (STATVFS_SUCCEEDED(rv) && StatVFS::readonly(st));
|
||||
}
|
||||
|
||||
bool
|
||||
spaceavail(const string &path,
|
||||
size_t &spaceavail)
|
||||
uint64_t &spaceavail)
|
||||
{
|
||||
bool rv;
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(rv)
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
|
||||
return rv;
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
spaceused(const string &path,
|
||||
uint64_t &spaceused)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -142,7 +146,7 @@ namespace fs
|
||||
string fullpath;
|
||||
struct stat st;
|
||||
|
||||
rv = ::fstat(fd,&st);
|
||||
rv = fs::fstat(fd,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
@@ -151,7 +155,7 @@ namespace fs
|
||||
{
|
||||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
rv = fs::lstat(fullpath,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
continue;
|
||||
|
||||
@@ -195,15 +199,16 @@ namespace fs
|
||||
realpathize(vector<string> &strs)
|
||||
{
|
||||
char *rv;
|
||||
char buf[PATH_MAX];
|
||||
|
||||
for(size_t i = 0; i < strs.size(); i++)
|
||||
{
|
||||
rv = ::realpath(strs[i].c_str(),buf);
|
||||
rv = fs::realpath(strs[i]);
|
||||
if(rv == NULL)
|
||||
continue;
|
||||
|
||||
strs[i] = buf;
|
||||
strs[i] = rv;
|
||||
|
||||
::free(rv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +220,7 @@ namespace fs
|
||||
|
||||
int
|
||||
mfs(const vector<string> &basepaths,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
string &path)
|
||||
{
|
||||
fsblkcnt_t mfs;
|
||||
@@ -225,7 +230,7 @@ namespace fs
|
||||
mfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
size_t spaceavail;
|
||||
uint64_t spaceavail;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
if(!fs::spaceavail(basepath,spaceavail))
|
||||
|
||||
+9
-7
@@ -17,12 +17,13 @@
|
||||
#ifndef __FS_HPP__
|
||||
#define __FS_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
using std::size_t;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
@@ -30,17 +31,18 @@ namespace fs
|
||||
struct stat &st);
|
||||
bool exists(const string &path);
|
||||
|
||||
bool statvfs(const string &path,
|
||||
struct statvfs &st);
|
||||
|
||||
bool info(const string &path,
|
||||
bool &readonly,
|
||||
size_t &spaceavail);
|
||||
uint64_t &spaceavail,
|
||||
uint64_t &spaceused);
|
||||
|
||||
bool readonly(const string &path);
|
||||
|
||||
bool spaceavail(const string &path,
|
||||
size_t &spaceavail);
|
||||
uint64_t &spaceavail);
|
||||
|
||||
bool spaceused(const string &path,
|
||||
uint64_t &spaceavail);
|
||||
|
||||
void findallfiles(const vector<string> &srcmounts,
|
||||
const char *fusepath,
|
||||
@@ -59,7 +61,7 @@ namespace fs
|
||||
int getfl(const int fd);
|
||||
|
||||
int mfs(const vector<string> &srcs,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
string &path);
|
||||
};
|
||||
|
||||
|
||||
+5
-111
@@ -14,114 +14,8 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace attr
|
||||
{
|
||||
static
|
||||
int
|
||||
get_fs_ioc_flags(const int fd,
|
||||
int &flags)
|
||||
{
|
||||
return ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
get_fs_ioc_flags(const string &file,
|
||||
int &flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
const int openflags = O_RDONLY|O_NONBLOCK;
|
||||
|
||||
fd = ::open(file.c_str(),openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = get_fs_ioc_flags(fd,flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ::close(fd);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
set_fs_ioc_flags(const int fd,
|
||||
const int flags)
|
||||
{
|
||||
return ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
set_fs_ioc_flags(const string &file,
|
||||
const int flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
const int openflags = O_RDONLY|O_NONBLOCK;
|
||||
|
||||
fd = ::open(file.c_str(),openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = set_fs_ioc_flags(fd,flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error = errno;
|
||||
::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ::close(fd);
|
||||
}
|
||||
|
||||
int
|
||||
copy(const int fdin,
|
||||
const int fdout)
|
||||
{
|
||||
int rv;
|
||||
int flags;
|
||||
|
||||
rv = get_fs_ioc_flags(fdin,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return set_fs_ioc_flags(fdout,flags);
|
||||
}
|
||||
|
||||
int
|
||||
copy(const string &from,
|
||||
const string &to)
|
||||
{
|
||||
int rv;
|
||||
int flags;
|
||||
|
||||
rv = get_fs_ioc_flags(from,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return set_fs_ioc_flags(to,flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef __linux__
|
||||
# include "fs_attr_linux.icpp"
|
||||
#else
|
||||
# include "fs_attr_unsupported.icpp"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_ioctl.hpp"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace attr
|
||||
{
|
||||
static
|
||||
int
|
||||
get_fs_ioc_flags(const int fd,
|
||||
int &flags)
|
||||
{
|
||||
return fs::ioctl(fd,FS_IOC_GETFLAGS,(void*)&flags);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
get_fs_ioc_flags(const string &file,
|
||||
int &flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
const int openflags = O_RDONLY|O_NONBLOCK;
|
||||
|
||||
fd = fs::open(file,openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = get_fs_ioc_flags(fd,flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error = errno;
|
||||
fs::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fs::close(fd);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
set_fs_ioc_flags(const int fd,
|
||||
const int flags)
|
||||
{
|
||||
return fs::ioctl(fd,FS_IOC_SETFLAGS,(void*)&flags);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
set_fs_ioc_flags(const string &file,
|
||||
const int flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
const int openflags = O_RDONLY|O_NONBLOCK;
|
||||
|
||||
fd = fs::open(file,openflags);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
rv = set_fs_ioc_flags(fd,flags);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error = errno;
|
||||
fs::close(fd);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fs::close(fd);
|
||||
}
|
||||
|
||||
int
|
||||
copy(const int fdin,
|
||||
const int fdout)
|
||||
{
|
||||
int rv;
|
||||
int flags;
|
||||
|
||||
rv = get_fs_ioc_flags(fdin,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return set_fs_ioc_flags(fdout,flags);
|
||||
}
|
||||
|
||||
int
|
||||
copy(const string &from,
|
||||
const string &to)
|
||||
{
|
||||
int rv;
|
||||
int flags;
|
||||
|
||||
rv = get_fs_ioc_flags(from,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return set_fs_ioc_flags(to,flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace attr
|
||||
{
|
||||
int
|
||||
copy(const int fdin,
|
||||
const int fdout)
|
||||
{
|
||||
return ENOTSUP;
|
||||
}
|
||||
|
||||
int
|
||||
copy(const std::string &from,
|
||||
const std::string &to)
|
||||
{
|
||||
return ENOTSUP;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
access(const int dirfd,
|
||||
const std::string &path,
|
||||
const int mode,
|
||||
const int flags)
|
||||
{
|
||||
return ::faccessat(dirfd,path.c_str(),mode,flags);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
access(const std::string &path,
|
||||
const int mode,
|
||||
const int flags)
|
||||
{
|
||||
return fs::access(AT_FDCWD,path,mode,flags);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
eaccess(const std::string &path,
|
||||
const int mode)
|
||||
{
|
||||
return fs::access(path,mode,AT_EACCESS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
chmod(const std::string &path,
|
||||
const mode_t mode)
|
||||
{
|
||||
return ::chmod(path.c_str(),mode);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fchmod(const int fd,
|
||||
const mode_t mode)
|
||||
{
|
||||
return ::fchmod(fd,mode);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fchmod(const int fd,
|
||||
const struct stat &st)
|
||||
{
|
||||
return ::fchmod(fd,st.st_mode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
chown(const std::string &path,
|
||||
const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
return ::chown(path.c_str(),uid,gid);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
chown(const std::string &path,
|
||||
const struct stat &st)
|
||||
{
|
||||
return fs::chown(path,st.st_uid,st.st_gid);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lchown(const std::string &path,
|
||||
const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
return ::lchown(path.c_str(),uid,gid);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fchown(const int fd,
|
||||
const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
return ::fchown(fd,uid,gid);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fchown(const int fd,
|
||||
const struct stat &st)
|
||||
{
|
||||
return fs::fchown(fd,st.st_uid,st.st_gid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
close(const int fd)
|
||||
{
|
||||
return ::close(fd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
closedir(DIR *dirp)
|
||||
{
|
||||
return ::closedir(dirp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
dup(const int fd)
|
||||
{
|
||||
return ::dup(fd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/file.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
flock(const int fd,
|
||||
const int operation)
|
||||
{
|
||||
return ::flock(fd,operation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
fsync(const int fd)
|
||||
{
|
||||
return ::fsync(fd);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fdatasync(const int fd)
|
||||
{
|
||||
#if _POSIX_SYNCHRONIZED_IO > 0
|
||||
return ::fdatasync(fd);
|
||||
#else
|
||||
return (errno=ENOSYS,-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
ftruncate(const int fd,
|
||||
const off_t size)
|
||||
{
|
||||
return ::ftruncate(fd,size);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
lgetxattr(const std::string &path,
|
||||
const char *attrname,
|
||||
void *value,
|
||||
const size_t size)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::lgetxattr(path.c_str(),attrname,value,size);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
ioctl(const int fd,
|
||||
const int request,
|
||||
void *data)
|
||||
{
|
||||
return ::ioctl(fd,request,data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
link(const std::string &oldpath,
|
||||
const std::string &newpath)
|
||||
{
|
||||
return ::link(oldpath.c_str(),newpath.c_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
llistxattr(const std::string &path,
|
||||
char *list,
|
||||
const size_t size)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::llistxattr(path.c_str(),list,size);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
off_t
|
||||
lseek(const int fd,
|
||||
const off_t offset,
|
||||
const int whence)
|
||||
{
|
||||
return ::lseek(fd,offset,whence);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
mkdir(const std::string &path,
|
||||
const mode_t mode)
|
||||
{
|
||||
return ::mkdir(path.c_str(),mode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
mknod(const std::string &path,
|
||||
const mode_t mode,
|
||||
const dev_t dev)
|
||||
{
|
||||
return ::mknod(path.c_str(),mode,dev);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
open(const std::string &path,
|
||||
const int flags)
|
||||
{
|
||||
return ::open(path.c_str(),flags);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
open(const std::string &path,
|
||||
const int flags,
|
||||
const mode_t mode)
|
||||
{
|
||||
return ::open(path.c_str(),flags,mode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
DIR *
|
||||
opendir(const std::string &name)
|
||||
{
|
||||
return ::opendir(name.c_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
read(const int fd,
|
||||
void *buf,
|
||||
const size_t count)
|
||||
{
|
||||
return ::read(fd,buf,count);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
pread(const int fd,
|
||||
void *buf,
|
||||
const size_t count,
|
||||
const off_t offset)
|
||||
{
|
||||
return ::pread(fd,buf,count,offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
struct dirent *
|
||||
readdir(DIR *dirp)
|
||||
{
|
||||
return ::readdir(dirp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
readlink(const std::string &path,
|
||||
char *buf,
|
||||
const size_t bufsiz)
|
||||
{
|
||||
return ::readlink(path.c_str(),buf,bufsiz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
char *
|
||||
realpath(const std::string &path,
|
||||
char *resolved_path)
|
||||
{
|
||||
return ::realpath(path.c_str(),resolved_path);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
char *
|
||||
realpath(const std::string &path)
|
||||
{
|
||||
return fs::realpath(path,NULL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
lremovexattr(const std::string &path,
|
||||
const char *attrname)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::lremovexattr(path.c_str(),attrname);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
rename(const std::string &oldpath,
|
||||
const std::string &newpath)
|
||||
{
|
||||
return ::rename(oldpath.c_str(),newpath.c_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
rmdir(const std::string &path)
|
||||
{
|
||||
return ::rmdir(path.c_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
lsetxattr(const std::string &path,
|
||||
const char *name,
|
||||
const void *value,
|
||||
const size_t size,
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::lsetxattr(path.c_str(),name,value,size,flags);
|
||||
#else
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
stat(const char *path,
|
||||
struct stat &st)
|
||||
{
|
||||
return ::stat(path,&st);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
stat(const std::string &path,
|
||||
struct stat &st)
|
||||
{
|
||||
return fs::stat(path.c_str(),st);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lstat(const std::string &path,
|
||||
struct stat &st)
|
||||
{
|
||||
return ::lstat(path.c_str(),&st);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fstat(const int fd,
|
||||
struct stat &st)
|
||||
{
|
||||
return ::fstat(fd,&st);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
statvfs(const char *path,
|
||||
struct statvfs &st)
|
||||
{
|
||||
return ::statvfs(path,&st);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
statvfs(const std::string &path,
|
||||
struct statvfs &st)
|
||||
{
|
||||
return fs::statvfs(path.c_str(),st);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
truncate(const std::string &path,
|
||||
const off_t length)
|
||||
{
|
||||
return ::truncate(path.c_str(),length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
unlink(const std::string &path)
|
||||
{
|
||||
return ::unlink(path.c_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
# include "fs_base_utime_utimensat.hpp"
|
||||
#elif __FreeBSD__ >= 11
|
||||
# include "fs_base_utime_utimensat.hpp"
|
||||
#else
|
||||
# include "fs_base_utime_generic.hpp"
|
||||
#endif
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
utime(const std::string &path,
|
||||
const struct stat &st)
|
||||
{
|
||||
struct timespec times[2];
|
||||
|
||||
times[0] = st.st_atim;
|
||||
times[1] = st.st_mtim;
|
||||
|
||||
return fs::utime(AT_FDCWD,path,times,0);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
utime(const int fd,
|
||||
const struct stat &st)
|
||||
{
|
||||
struct timespec times[2];
|
||||
|
||||
times[0] = st.st_atim;
|
||||
times[1] = st.st_mtim;
|
||||
|
||||
return fs::utime(fd,times);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lutime(const std::string &path,
|
||||
const struct timespec times[2])
|
||||
{
|
||||
return fs::utime(AT_FDCWD,path,times,AT_SYMLINK_NOFOLLOW);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifndef UTIME_NOW
|
||||
# define UTIME_NOW ((1l << 30) - 1l)
|
||||
#endif
|
||||
|
||||
#ifndef UTIME_OMIT
|
||||
# define UTIME_OMIT ((1l << 30) - 2l)
|
||||
#endif
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_can_call_lutimes(const int dirfd,
|
||||
const std::string &path,
|
||||
const int flags)
|
||||
{
|
||||
return ((flags == AT_SYMLINK_NOFOLLOW) &&
|
||||
((dirfd == AT_FDCWD) ||
|
||||
(path[0] == '/')));
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_should_ignore(const struct timespec ts[2])
|
||||
{
|
||||
return ((ts != NULL) &&
|
||||
(ts[0].tv_nsec == UTIME_OMIT) &&
|
||||
(ts[1].tv_nsec == UTIME_OMIT));
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_should_be_set_to_now(const struct timespec ts[2])
|
||||
{
|
||||
return ((ts == NULL) ||
|
||||
((ts[0].tv_nsec == UTIME_NOW) &&
|
||||
(ts[1].tv_nsec == UTIME_NOW)));
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_timespec_invalid(const struct timespec &ts)
|
||||
{
|
||||
return (((ts.tv_nsec < 0) ||
|
||||
(ts.tv_nsec > 999999999)) &&
|
||||
((ts.tv_nsec != UTIME_NOW) &&
|
||||
(ts.tv_nsec != UTIME_OMIT)));
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_timespec_invalid(const struct timespec ts[2])
|
||||
{
|
||||
return ((ts != NULL) &&
|
||||
(_timespec_invalid(ts[0]) ||
|
||||
_timespec_invalid(ts[1])));
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_flags_invalid(const int flags)
|
||||
{
|
||||
return ((flags & ~AT_SYMLINK_NOFOLLOW) != 0);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_any_timespec_is_utime_omit(const struct timespec ts[2])
|
||||
{
|
||||
return ((ts[0].tv_nsec == UTIME_OMIT) ||
|
||||
(ts[1].tv_nsec == UTIME_OMIT));
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
_any_timespec_is_utime_now(const struct timespec ts[2])
|
||||
{
|
||||
return ((ts[0].tv_nsec == UTIME_NOW) ||
|
||||
(ts[1].tv_nsec == UTIME_NOW));
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_set_utime_omit_to_current_value(const int dirfd,
|
||||
const std::string &path,
|
||||
const struct timespec ts[2],
|
||||
struct timeval tv[2],
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
||||
if(!_any_timespec_is_utime_omit(ts))
|
||||
return 0;
|
||||
|
||||
rv = ::fstatat(dirfd,path.c_str(),&st,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
if(ts[0].tv_nsec == UTIME_OMIT)
|
||||
TIMESPEC_TO_TIMEVAL(&tv[0],&st.st_atim);
|
||||
if(ts[1].tv_nsec == UTIME_OMIT)
|
||||
TIMESPEC_TO_TIMEVAL(&tv[1],&st.st_mtim);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_set_utime_omit_to_current_value(const int fd,
|
||||
const struct timespec ts[2],
|
||||
struct timeval tv[2])
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
||||
if(!_any_timespec_is_utime_omit(ts))
|
||||
return 0;
|
||||
|
||||
rv = ::fstat(fd,&st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
if(ts[0].tv_nsec == UTIME_OMIT)
|
||||
TIMESPEC_TO_TIMEVAL(&tv[0],&st.st_atim);
|
||||
if(ts[1].tv_nsec == UTIME_OMIT)
|
||||
TIMESPEC_TO_TIMEVAL(&tv[1],&st.st_mtim);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_set_utime_now_to_now(const struct timespec ts[2],
|
||||
struct timeval tv[2])
|
||||
{
|
||||
int rv;
|
||||
struct timeval now;
|
||||
|
||||
if(_any_timespec_is_utime_now(ts))
|
||||
return 0;
|
||||
|
||||
rv = ::gettimeofday(&now,NULL);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
if(ts[0].tv_nsec == UTIME_NOW)
|
||||
tv[0] = now;
|
||||
if(ts[1].tv_nsec == UTIME_NOW)
|
||||
tv[1] = now;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_convert_timespec_to_timeval(const int dirfd,
|
||||
const std::string &path,
|
||||
const struct timespec ts[2],
|
||||
struct timeval tv[2],
|
||||
struct timeval *&tvp,
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if(_should_be_set_to_now(ts))
|
||||
return (tvp=NULL,0);
|
||||
|
||||
TIMESPEC_TO_TIMEVAL(&tv[0],&ts[0]);
|
||||
TIMESPEC_TO_TIMEVAL(&tv[1],&ts[1]);
|
||||
|
||||
rv = _set_utime_omit_to_current_value(dirfd,path,ts,tv,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = _set_utime_now_to_now(ts,tv);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return (tvp=tv,0);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
_convert_timespec_to_timeval(const int fd,
|
||||
const struct timespec ts[2],
|
||||
struct timeval tv[2],
|
||||
struct timeval *&tvp)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if(_should_be_set_to_now(ts))
|
||||
return (tvp=NULL,0);
|
||||
|
||||
TIMESPEC_TO_TIMEVAL(&tv[0],&ts[0]);
|
||||
TIMESPEC_TO_TIMEVAL(&tv[1],&ts[1]);
|
||||
|
||||
rv = _set_utime_omit_to_current_value(fd,ts,tv);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = _set_utime_now_to_now(ts,tv);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return (tvp=tv,0);
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
utime(const int dirfd,
|
||||
const std::string &path,
|
||||
const struct timespec ts[2],
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
struct timeval tv[2];
|
||||
struct timeval *tvp;
|
||||
|
||||
if(_flags_invalid(flags))
|
||||
return (errno=EINVAL,-1);
|
||||
if(_timespec_invalid(ts))
|
||||
return (errno=EINVAL,-1);
|
||||
if(_should_ignore(ts))
|
||||
return 0;
|
||||
|
||||
rv = _convert_timespec_to_timeval(dirfd,path,ts,tv,tvp,flags);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
if((flags & AT_SYMLINK_NOFOLLOW) == 0)
|
||||
return ::futimesat(dirfd,path.c_str(),tvp);
|
||||
if(_can_call_lutimes(dirfd,path,flags))
|
||||
return ::lutimes(path.c_str(),tvp);
|
||||
|
||||
return (errno=ENOTSUP,-1);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
utime(const int fd,
|
||||
const struct timespec ts[2])
|
||||
{
|
||||
int rv;
|
||||
struct timeval tv[2];
|
||||
struct timeval *tvp;
|
||||
|
||||
if(_timespec_invalid(ts))
|
||||
return (errno=EINVAL,-1);
|
||||
if(_should_ignore(ts))
|
||||
return 0;
|
||||
|
||||
rv = _convert_timespec_to_timeval(fd,ts,tv,tvp);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return ::futimes(fd,tvp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
utime(const int dirfd,
|
||||
const std::string &path,
|
||||
const struct timespec times[2],
|
||||
const int flags)
|
||||
{
|
||||
return ::utimensat(dirfd,path.c_str(),times,flags);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
utime(const int fd,
|
||||
const struct timespec times[2])
|
||||
{
|
||||
return ::futimens(fd,times);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
write(const int fd,
|
||||
const void *buf,
|
||||
const size_t count)
|
||||
{
|
||||
return ::write(fd,buf,count);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
pwrite(const int fd,
|
||||
const void *buf,
|
||||
const size_t count,
|
||||
const off_t offset)
|
||||
{
|
||||
return ::pwrite(fd,buf,count,offset);
|
||||
}
|
||||
}
|
||||
+139
-140
@@ -14,143 +14,145 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#ifdef __linux__
|
||||
#include <sys/sendfile.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_base_chmod.hpp"
|
||||
#include "fs_base_chown.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_lseek.hpp"
|
||||
#include "fs_base_mkdir.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_read.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_utime.hpp"
|
||||
#include "fs_base_write.hpp"
|
||||
#include "fs_fadvise.hpp"
|
||||
#include "fs_fallocate.hpp"
|
||||
#include "fs_sendfile.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
|
||||
#ifndef O_LARGEFILE
|
||||
# define O_LARGEFILE 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOATIME
|
||||
# define O_NOATIME 0
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
int
|
||||
writen(const int fd,
|
||||
const char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
size_t nleft;
|
||||
ssize_t nwritten;
|
||||
|
||||
nleft = count;
|
||||
while(nleft > 0)
|
||||
{
|
||||
nwritten = fs::write(fd,buf,nleft);
|
||||
if(nwritten == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nleft -= nwritten;
|
||||
buf += nwritten;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copyfile_rw(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count,
|
||||
const size_t blocksize)
|
||||
{
|
||||
ssize_t nr;
|
||||
ssize_t nw;
|
||||
ssize_t bufsize;
|
||||
size_t totalwritten;
|
||||
vector<char> buf;
|
||||
|
||||
bufsize = (blocksize * 16);
|
||||
buf.resize(bufsize);
|
||||
|
||||
fs::lseek(fdin,0,SEEK_SET);
|
||||
|
||||
totalwritten = 0;
|
||||
while(totalwritten < count)
|
||||
{
|
||||
nr = fs::read(fdin,&buf[0],bufsize);
|
||||
if(nr == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nw = writen(fdout,&buf[0],nr);
|
||||
if(nw == -1)
|
||||
return -1;
|
||||
|
||||
totalwritten += nw;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copydata(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count,
|
||||
const size_t blocksize)
|
||||
{
|
||||
int rv;
|
||||
|
||||
fs::fadvise(fdin,0,count,POSIX_FADV_WILLNEED);
|
||||
fs::fadvise(fdin,0,count,POSIX_FADV_SEQUENTIAL);
|
||||
|
||||
fs::fallocate(fdout,0,0,count);
|
||||
|
||||
rv = fs::sendfile(fdin,fdout,count);
|
||||
if((rv == -1) && ((errno == EINVAL) || (errno == ENOSYS)))
|
||||
return ::copyfile_rw(fdin,fdout,count,blocksize);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
ignorable_error(const int err)
|
||||
{
|
||||
switch(err)
|
||||
{
|
||||
case ENOTTY:
|
||||
case ENOTSUP:
|
||||
#if ENOTSUP != EOPNOTSUPP
|
||||
case EOPNOTSUPP:
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
ssize_t
|
||||
sendfile(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count)
|
||||
{
|
||||
#if defined __linux__
|
||||
off_t offset = 0;
|
||||
return ::sendfile(fdout,fdin,&offset,count);
|
||||
#else
|
||||
return (errno=EINVAL,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
writen(const int fd,
|
||||
const char *buf,
|
||||
const size_t count)
|
||||
{
|
||||
size_t nleft;
|
||||
ssize_t nwritten;
|
||||
|
||||
nleft = count;
|
||||
while(nleft > 0)
|
||||
{
|
||||
nwritten = ::write(fd,buf,nleft);
|
||||
if(nwritten == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nleft -= nwritten;
|
||||
buf += nwritten;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copyfile_rw(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count,
|
||||
const size_t blocksize)
|
||||
{
|
||||
ssize_t nr;
|
||||
ssize_t nw;
|
||||
ssize_t bufsize;
|
||||
size_t totalwritten;
|
||||
vector<char> buf;
|
||||
|
||||
bufsize = (blocksize * 16);
|
||||
buf.resize(bufsize);
|
||||
|
||||
totalwritten = 0;
|
||||
while(totalwritten < count)
|
||||
{
|
||||
nr = ::read(fdin,&buf[0],bufsize);
|
||||
if(nr == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
nw = writen(fdout,&buf[0],nr);
|
||||
if(nw == -1)
|
||||
return -1;
|
||||
|
||||
totalwritten += nw;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
copydata(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count,
|
||||
const size_t blocksize)
|
||||
{
|
||||
int rv;
|
||||
|
||||
::posix_fadvise(fdin,0,count,POSIX_FADV_WILLNEED);
|
||||
::posix_fadvise(fdin,0,count,POSIX_FADV_SEQUENTIAL);
|
||||
|
||||
::posix_fallocate(fdout,0,count);
|
||||
|
||||
rv = fs::sendfile(fdin,fdout,count);
|
||||
if((rv == -1) && ((errno == EINVAL) || (errno == ENOSYS)))
|
||||
return fs::copyfile_rw(fdin,fdout,count,blocksize);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
ignorable_error(const int err)
|
||||
{
|
||||
switch(err)
|
||||
{
|
||||
case ENOTTY:
|
||||
case ENOTSUP:
|
||||
#if ENOTSUP != EOPNOTSUPP
|
||||
case EOPNOTSUPP:
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
clonefile(const int fdin,
|
||||
const int fdout)
|
||||
@@ -158,34 +160,31 @@ namespace fs
|
||||
int rv;
|
||||
struct stat stin;
|
||||
|
||||
rv = ::fstat(fdin,&stin);
|
||||
rv = fs::fstat(fdin,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = copydata(fdin,fdout,stin.st_size,stin.st_blksize);
|
||||
rv = ::copydata(fdin,fdout,stin.st_size,stin.st_blksize);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::attr::copy(fdin,fdout);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::xattr::copy(fdin,fdout);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = ::fchown(fdout,stin.st_uid,stin.st_gid);
|
||||
rv = fs::fchown(fdout,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
rv = ::fchmod(fdout,stin.st_mode);
|
||||
rv = fs::fchmod(fdout,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
struct timespec times[2];
|
||||
times[0] = stin.st_atim;
|
||||
times[1] = stin.st_mtim;
|
||||
rv = ::futimens(fdout,times);
|
||||
rv = fs::utime(fdout,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
@@ -201,21 +200,21 @@ namespace fs
|
||||
int fdout;
|
||||
int error;
|
||||
|
||||
fdin = ::open(in.c_str(),O_RDONLY|O_NOFOLLOW);
|
||||
fdin = fs::open(in,O_RDONLY|O_NOFOLLOW);
|
||||
if(fdin == -1)
|
||||
return -1;
|
||||
|
||||
const int flags = O_CREAT|O_LARGEFILE|O_NOATIME|O_NOFOLLOW|O_TRUNC|O_WRONLY;
|
||||
const int mode = S_IWUSR;
|
||||
fdout = ::open(out.c_str(),flags,mode);
|
||||
const int flags = O_CREAT|O_LARGEFILE|O_NOATIME|O_NOFOLLOW|O_TRUNC|O_WRONLY;
|
||||
const mode_t mode = S_IWUSR;
|
||||
fdout = fs::open(out,flags,mode);
|
||||
if(fdout == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::clonefile(fdin,fdout);
|
||||
error = errno;
|
||||
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
fs::close(fdin);
|
||||
fs::close(fdout);
|
||||
|
||||
errno = error;
|
||||
return rv;
|
||||
|
||||
+33
-35
@@ -14,38 +14,39 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "errno.h"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_base_chmod.hpp"
|
||||
#include "fs_base_chown.hpp"
|
||||
#include "fs_base_mkdir.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_utime.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
|
||||
static
|
||||
bool
|
||||
ignorable_error(const int err)
|
||||
{
|
||||
switch(err)
|
||||
{
|
||||
case ENOTTY:
|
||||
case ENOTSUP:
|
||||
#if ENOTSUP != EOPNOTSUPP
|
||||
case EOPNOTSUPP:
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
bool
|
||||
ignorable_error(const int err)
|
||||
{
|
||||
switch(err)
|
||||
{
|
||||
case ENOTTY:
|
||||
case ENOTSUP:
|
||||
#if ENOTSUP != EOPNOTSUPP
|
||||
case EOPNOTSUPP:
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
clonepath(const string &fromsrc,
|
||||
const string &tosrc,
|
||||
@@ -61,47 +62,44 @@ namespace fs
|
||||
fs::path::dirname(dirname);
|
||||
if(!dirname.empty())
|
||||
{
|
||||
rv = clonepath(fromsrc,tosrc,dirname.c_str());
|
||||
rv = fs::clonepath(fromsrc,tosrc,dirname.c_str());
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path::make(&fromsrc,relative,frompath);
|
||||
rv = ::stat(frompath.c_str(),&st);
|
||||
rv = fs::stat(frompath,st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
else if(!S_ISDIR(st.st_mode))
|
||||
return (errno = ENOTDIR,-1);
|
||||
return (errno=ENOTDIR,-1);
|
||||
|
||||
fs::path::make(&tosrc,relative,topath);
|
||||
rv = ::mkdir(topath.c_str(),st.st_mode);
|
||||
rv = fs::mkdir(topath,st.st_mode);
|
||||
if(rv == -1)
|
||||
{
|
||||
if(errno != EEXIST)
|
||||
return -1;
|
||||
|
||||
rv = ::chmod(topath.c_str(),st.st_mode);
|
||||
rv = fs::chmod(topath,st.st_mode);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// It may not support it... it's fine...
|
||||
rv = fs::attr::copy(frompath,topath);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = fs::xattr::copy(frompath,topath);
|
||||
if(rv == -1 && !ignorable_error(errno))
|
||||
if((rv == -1) && !ignorable_error(errno))
|
||||
return -1;
|
||||
|
||||
rv = ::chown(topath.c_str(),st.st_uid,st.st_gid);
|
||||
rv = fs::chown(topath,st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
struct timespec times[2];
|
||||
times[0] = st.st_atim;
|
||||
times[1] = st.st_mtim;
|
||||
rv = ::utimensat(-1,topath.c_str(),times,0);
|
||||
rv = fs::utime(topath,st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
|
||||
# include "fs_fadvise_posix.icpp"
|
||||
#else
|
||||
# include "fs_fadvise_unsupported.icpp"
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FS_FADVISE_HPP__
|
||||
#define __FS_FADVISE_HPP__
|
||||
|
||||
#ifndef POSIX_FADV_NORMAL
|
||||
# define POSIX_FADV_NORMAL 0
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_FADV_RANDOM
|
||||
# define POSIX_FADV_RANDOM 1
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_FADV_SEQUENTIAL
|
||||
# define POSIX_FADV_SEQUENTIAL 2
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_FADV_WILLNEED
|
||||
# define POSIX_FADV_WILLNEED 3
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_FADV_DONTNEED
|
||||
# define POSIX_FADV_DONTNEED 4
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_FADV_NOREUSE
|
||||
# define POSIX_FADV_NOREUSE 5
|
||||
#endif
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
fadvise(const int fd,
|
||||
const off_t offset,
|
||||
const off_t len,
|
||||
const int advice);
|
||||
}
|
||||
|
||||
#endif // __FS_FADVISE_HPP__
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
fadvise(const int fd,
|
||||
const off_t offset,
|
||||
const off_t len,
|
||||
const int advice)
|
||||
{
|
||||
return ::posix_fadvise(fd,offset,len,advice);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
fadvise(const int fd,
|
||||
const off_t offset,
|
||||
const off_t len,
|
||||
const int advice)
|
||||
{
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef __linux__
|
||||
# include "fs_fallocate_linux.icpp"
|
||||
#elif _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
|
||||
# include "fs_fallocate_posix.icpp"
|
||||
#elif __APPLE__
|
||||
# include "fs_fallocate_osx.icpp"
|
||||
#else
|
||||
# include "fs_fallocate_unsupported.icpp"
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FS_FALLOCATE_HPP__
|
||||
#define __FS_FALLOCATE_HPP__
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
fallocate(const int fd,
|
||||
const int mode,
|
||||
const off_t offset,
|
||||
const off_t len);
|
||||
}
|
||||
|
||||
#endif // __FS_FALLOCATE_HPP__
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_fallocate.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
fallocate(const int fd,
|
||||
const int mode,
|
||||
const off_t offset,
|
||||
const off_t len)
|
||||
{
|
||||
return ::fallocate(fd,mode,offset,len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_fallocate.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
int
|
||||
_fallocate_core(const int fd,
|
||||
const off_t offset,
|
||||
const off_t len)
|
||||
{
|
||||
int rv;
|
||||
fstore_t store = {F_ALLOCATECONTIG,F_PEOFPOSMODE,offset,len,0};
|
||||
|
||||
rv = ::fcntl(fd,F_PREALLOCATE,&store);
|
||||
if(rv == -1)
|
||||
{
|
||||
store.fst_flags = F_ALLOCATEALL;
|
||||
rv = ::fcntl(fd,F_PREALLOCATE,&store);
|
||||
}
|
||||
|
||||
if(rv == -1)
|
||||
return rv;
|
||||
|
||||
return ::ftruncate(fd,(offset+len));
|
||||
}
|
||||
|
||||
int
|
||||
fallocate(const int fd,
|
||||
const int mode,
|
||||
const off_t offset,
|
||||
const off_t len)
|
||||
{
|
||||
if(mode)
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
|
||||
return ::_fallocate_core(fd,offset,len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_fallocate.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
fallocate(const int fd,
|
||||
const int mode,
|
||||
const off_t offset,
|
||||
const off_t len)
|
||||
{
|
||||
return (mode ?
|
||||
(errno=EOPNOTSUPP,-1) :
|
||||
(::posix_fallocate(fd,offset,len)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_fallocate.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
fallocate(const int fd,
|
||||
const int mode,
|
||||
const off_t offset,
|
||||
const off_t len)
|
||||
{
|
||||
return (errno=EOPNOTSUPP,-1);
|
||||
}
|
||||
}
|
||||
+21
-17
@@ -14,18 +14,22 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_unlink.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_clonefile.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -49,7 +53,7 @@ namespace fs
|
||||
|
||||
fdin = origfd;
|
||||
|
||||
rv = fstat(fdin,&fdin_st);
|
||||
rv = fs::fstat(fdin,fdin_st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
@@ -73,35 +77,35 @@ namespace fs
|
||||
return -1;
|
||||
|
||||
fs::path::append(fdin_path,fusepath);
|
||||
fdin = ::open(fdin_path.c_str(),O_RDONLY);
|
||||
fdin = fs::open(fdin_path,O_RDONLY);
|
||||
if(fdin == -1)
|
||||
return -1;
|
||||
|
||||
fs::path::append(fdout_path,fusepath);
|
||||
fdout = ::open(fdout_path.c_str(),fdin_flags|O_CREAT,fdin_st.st_mode);
|
||||
fdout = fs::open(fdout_path,fdin_flags|O_CREAT,fdin_st.st_mode);
|
||||
if(fdout == -1)
|
||||
return -1;
|
||||
|
||||
rv = fs::clonefile(fdin,fdout);
|
||||
if(rv == -1)
|
||||
{
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
::unlink(fdout_path.c_str());
|
||||
fs::close(fdin);
|
||||
fs::close(fdout);
|
||||
fs::unlink(fdout_path.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ::unlink(fdin_path.c_str());
|
||||
rv = fs::unlink(fdin_path);
|
||||
if(rv == -1)
|
||||
{
|
||||
::close(fdin);
|
||||
::close(fdout);
|
||||
::unlink(fdout_path.c_str());
|
||||
fs::close(fdin);
|
||||
fs::close(fdout);
|
||||
fs::unlink(fdout_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
::close(fdin);
|
||||
::close(origfd);
|
||||
fs::close(fdin);
|
||||
fs::close(origfd);
|
||||
|
||||
origfd = fdout;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
# include "fs_sendfile_linux.icpp"
|
||||
#else
|
||||
# include "fs_sendfile_unsupported.icpp"
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __FS_SENDFILE_HPP__
|
||||
#define __FS_SENDFILE_HPP__
|
||||
|
||||
namespace fs
|
||||
{
|
||||
ssize_t
|
||||
sendfile(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count);
|
||||
}
|
||||
|
||||
#endif // __FS_SENDFILE_HPP__
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/sendfile.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
ssize_t
|
||||
sendfile(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count)
|
||||
{
|
||||
off_t offset = 0;
|
||||
|
||||
return ::sendfile(fdout,fdin,&offset,count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
ssize_t
|
||||
sendfile(const int fdin,
|
||||
const int fdout,
|
||||
const size_t count)
|
||||
{
|
||||
return (errno=EINVAL,-1);
|
||||
}
|
||||
}
|
||||
+52
-52
@@ -14,7 +14,6 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -26,6 +25,9 @@
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "str.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
@@ -44,23 +46,23 @@ namespace fs
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
ssize_t rv;
|
||||
ssize_t size;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
size = ::flistxattr(fd,NULL,0);
|
||||
attrs.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::flistxattr(fd,&attrs[0],size);
|
||||
rv = ::flistxattr(fd,NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
attrs.resize(rv);
|
||||
|
||||
rv = ::flistxattr(fd,&attrs[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -69,24 +71,24 @@ namespace fs
|
||||
vector<char> &attrs)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
ssize_t rv;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
size = ::listxattr(path.c_str(),NULL,0);
|
||||
attrs.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::listxattr(path.c_str(),&attrs[0],size);
|
||||
rv = ::llistxattr(path.c_str(),NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
attrs.resize(rv);
|
||||
|
||||
rv = ::llistxattr(path.c_str(),&attrs[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -126,7 +128,7 @@ namespace fs
|
||||
|
||||
int
|
||||
list(const int fd,
|
||||
string &attrstr)
|
||||
string &attrstr)
|
||||
{
|
||||
int rv;
|
||||
vector<char> attrs;
|
||||
@@ -158,24 +160,24 @@ namespace fs
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
ssize_t rv;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
size = ::fgetxattr(fd,attr.c_str(),NULL,0);
|
||||
value.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::fgetxattr(fd,attr.c_str(),&value[0],size);
|
||||
rv = ::fgetxattr(fd,attr.c_str(),NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
value.resize(rv);
|
||||
|
||||
rv = ::fgetxattr(fd,attr.c_str(),&value[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -185,24 +187,24 @@ namespace fs
|
||||
vector<char> &value)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
int size;
|
||||
ssize_t rv;
|
||||
|
||||
rv = -1;
|
||||
errno = ERANGE;
|
||||
while(rv == -1 && errno == ERANGE)
|
||||
while((rv == -1) && (errno == ERANGE))
|
||||
{
|
||||
size = ::getxattr(path.c_str(),attr.c_str(),NULL,0);
|
||||
value.resize(size);
|
||||
if(size == 0)
|
||||
return 0;
|
||||
rv = ::getxattr(path.c_str(),attr.c_str(),&value[0],size);
|
||||
rv = ::lgetxattr(path.c_str(),attr.c_str(),NULL,0);
|
||||
if(rv <= 0)
|
||||
return rv;
|
||||
|
||||
value.resize(rv);
|
||||
|
||||
rv = ::lgetxattr(path.c_str(),attr.c_str(),&value[0],rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -305,8 +307,7 @@ namespace fs
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -317,14 +318,13 @@ namespace fs
|
||||
const int flags)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
return ::setxattr(path.c_str(),
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
return ::lsetxattr(path.c_str(),
|
||||
key.c_str(),
|
||||
value.data(),
|
||||
value.size(),
|
||||
flags);
|
||||
#else
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
return (errno=ENOTSUP,-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -351,13 +351,13 @@ namespace fs
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = ::open(path.c_str(),O_RDONLY|O_NONBLOCK);
|
||||
fd = fs::open(path,O_RDONLY|O_NONBLOCK);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
set(fd,attrs);
|
||||
|
||||
return ::close(fd);
|
||||
return fs::close(fd);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace fs
|
||||
{
|
||||
namespace xattr
|
||||
{
|
||||
using std::size_t;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
+4
-5
@@ -23,10 +23,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_fsync.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
@@ -36,8 +35,8 @@ _fsync(const int fd,
|
||||
int rv;
|
||||
|
||||
rv = (isdatasync ?
|
||||
::fdatasync(fd) :
|
||||
::fsync(fd));
|
||||
fs::fdatasync(fd) :
|
||||
fs::fsync(fd));
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
+3
-5
@@ -16,11 +16,9 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_ftruncate.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
@@ -29,7 +27,7 @@ _ftruncate(const int fd,
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::ftruncate(fd,size);
|
||||
rv = fs::ftruncate(fd,size);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,8 +16,8 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fusefunc.hpp"
|
||||
#include "category.hpp"
|
||||
#include "buildvector.hpp"
|
||||
#include "category.hpp"
|
||||
#include "fusefunc.hpp"
|
||||
|
||||
#define FUSEFUNC(X,Y) FuseFunc(FuseFunc::Enum::X,#X,Category::Enum::Y)
|
||||
|
||||
|
||||
+4
-7
@@ -19,12 +19,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
@@ -62,7 +59,7 @@ static
|
||||
int
|
||||
_getattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
struct stat &buf)
|
||||
{
|
||||
@@ -76,7 +73,7 @@ _getattr(Policy::Func::Search searchFunc,
|
||||
|
||||
fs::path::make(basepaths[0],fusepath,fullpath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&buf);
|
||||
rv = fs::lstat(fullpath,buf);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
||||
+3
-9
@@ -21,19 +21,17 @@
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_getxattr.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "str.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "version.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -47,15 +45,11 @@ _lgetxattr(const string &path,
|
||||
void *value,
|
||||
const size_t size)
|
||||
{
|
||||
#ifndef WITHOUT_XATTR
|
||||
int rv;
|
||||
|
||||
rv = ::lgetxattr(path.c_str(),attrname,value,size);
|
||||
rv = fs::lgetxattr(path,attrname,value,size);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
|
||||
+6
-2
@@ -14,10 +14,10 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined __linux__ and UGID_USE_RWLOCK == 0
|
||||
@@ -126,7 +126,11 @@ int
|
||||
setgroups(const gid_t_rec *rec)
|
||||
{
|
||||
#if defined __linux__ and UGID_USE_RWLOCK == 0
|
||||
# if defined SYS_setgroups32
|
||||
return ::syscall(SYS_setgroups32,rec->size,rec->gids);
|
||||
# else
|
||||
return ::syscall(SYS_setgroups,rec->size,rec->gids);
|
||||
# endif
|
||||
#else
|
||||
return ::setgroups(rec->size,rec->gids);
|
||||
#endif
|
||||
|
||||
+10
-12
@@ -19,12 +19,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_ioctl.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
@@ -41,17 +43,13 @@ _ioctl(const int fd,
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::ioctl(fd,cmd,data);
|
||||
rv = fs::ioctl(fd,cmd,data);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
}
|
||||
|
||||
#ifdef FUSE_IOCTL_DIR
|
||||
|
||||
#ifndef O_DIRECTORY
|
||||
#define O_DIRECTORY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NOATIME
|
||||
#define O_NOATIME 0
|
||||
#endif
|
||||
@@ -60,7 +58,7 @@ static
|
||||
int
|
||||
_ioctl_dir_base(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const int cmd,
|
||||
void *data)
|
||||
@@ -76,14 +74,14 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,
|
||||
|
||||
fs::path::make(basepaths[0],fusepath,fullpath);
|
||||
|
||||
const int flags = O_RDWR | O_NOATIME | O_DIRECTORY;
|
||||
fd = ::open(fullpath.c_str(),flags);
|
||||
const int flags = O_RDONLY | O_NOATIME | O_NONBLOCK;
|
||||
fd = fs::open(fullpath,flags);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
rv = _ioctl(fd,cmd,data);
|
||||
|
||||
::close(fd);
|
||||
fs::close(fd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
+12
-13
@@ -19,10 +19,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_link.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
@@ -56,7 +55,7 @@ _link_create_path_core(const string &oldbasepath,
|
||||
fs::path::make(&oldbasepath,oldfusepath,oldfullpath);
|
||||
fs::path::make(&oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
rv = ::link(oldfullpath.c_str(),newfullpath.c_str());
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
}
|
||||
@@ -88,7 +87,7 @@ int
|
||||
_link_create_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
{
|
||||
@@ -117,7 +116,7 @@ int
|
||||
_clonepath_if_would_create(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
@@ -158,7 +157,7 @@ int
|
||||
_link_preserve_path_core(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const string &oldbasepath,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath,
|
||||
@@ -171,7 +170,7 @@ _link_preserve_path_core(Policy::Func::Search searchFunc,
|
||||
fs::path::make(&oldbasepath,oldfusepath,oldfullpath);
|
||||
fs::path::make(&oldbasepath,newfusepath,newfullpath);
|
||||
|
||||
rv = ::link(oldfullpath.c_str(),newfullpath.c_str());
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
if((rv == -1) && (errno == ENOENT))
|
||||
{
|
||||
rv = _clonepath_if_would_create(searchFunc,createFunc,
|
||||
@@ -179,7 +178,7 @@ _link_preserve_path_core(Policy::Func::Search searchFunc,
|
||||
oldbasepath,
|
||||
oldfusepath,newfusepath);
|
||||
if(rv != -1)
|
||||
rv = ::link(oldfullpath.c_str(),newfullpath.c_str());
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
}
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
@@ -190,7 +189,7 @@ int
|
||||
_link_preserve_path_loop(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath,
|
||||
const vector<const string*> &oldbasepaths)
|
||||
@@ -216,9 +215,9 @@ _link_preserve_path(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Action actionFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
const uint64_t minfreespace,
|
||||
const char *oldfusepath,
|
||||
const char *newfusepath)
|
||||
{
|
||||
int rv;
|
||||
vector<const string*> oldbasepaths;
|
||||
|
||||
+4
-10
@@ -19,13 +19,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "buildvector.hpp"
|
||||
#include "category.hpp"
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_listxattr.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
@@ -69,12 +69,11 @@ _listxattr_controlfile(char *list,
|
||||
return xattrs.size();
|
||||
}
|
||||
|
||||
#ifndef WITHOUT_XATTR
|
||||
static
|
||||
int
|
||||
_listxattr(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
char *list,
|
||||
const size_t size)
|
||||
@@ -89,11 +88,10 @@ _listxattr(Policy::Func::Search searchFunc,
|
||||
|
||||
fs::path::make(basepaths[0],fusepath,fullpath);
|
||||
|
||||
rv = ::llistxattr(fullpath.c_str(),list,size);
|
||||
rv = fs::llistxattr(fullpath,list,size);
|
||||
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
@@ -110,7 +108,6 @@ namespace mergerfs
|
||||
if(fusepath == config.controlfile)
|
||||
return _listxattr_controlfile(list,size);
|
||||
|
||||
#ifndef WITHOUT_XATTR
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
@@ -120,9 +117,6 @@ namespace mergerfs
|
||||
fusepath,
|
||||
list,
|
||||
size);
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -34,6 +34,7 @@
|
||||
#include "destroy.hpp"
|
||||
#include "fallocate.hpp"
|
||||
#include "fgetattr.hpp"
|
||||
#include "flock.hpp"
|
||||
#include "flush.hpp"
|
||||
#include "fsync.hpp"
|
||||
#include "ftruncate.hpp"
|
||||
@@ -95,7 +96,7 @@ namespace local
|
||||
#endif
|
||||
ops.fgetattr = mergerfs::fuse::fgetattr;
|
||||
#if FLOCK
|
||||
ops.flock = NULL;
|
||||
ops.flock = mergerfs::fuse::flock;
|
||||
#endif
|
||||
ops.flush = mergerfs::fuse::flush;
|
||||
ops.fsync = mergerfs::fuse::fsync;
|
||||
|
||||
+4
-6
@@ -16,14 +16,12 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_mkdir.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
@@ -55,7 +53,7 @@ _mkdir_loop_core(const string &existingpath,
|
||||
|
||||
fs::path::make(&createpath,fusepath,fullpath);
|
||||
|
||||
rv = ::mkdir(fullpath.c_str(),mode);
|
||||
rv = fs::mkdir(fullpath,mode);
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
}
|
||||
@@ -85,7 +83,7 @@ int
|
||||
_mkdir(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode)
|
||||
{
|
||||
|
||||
+4
-8
@@ -19,13 +19,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_mknod.hpp"
|
||||
#include "fs_clonepath.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rv.hpp"
|
||||
@@ -57,7 +53,7 @@ _mknod_loop_core(const string &existingpath,
|
||||
|
||||
fs::path::make(&createpath,fusepath,fullpath);
|
||||
|
||||
rv = ::mknod(fullpath.c_str(),mode,dev);
|
||||
rv = fs::mknod(fullpath,mode,dev);
|
||||
|
||||
return calc_error(rv,error,errno);
|
||||
}
|
||||
@@ -89,7 +85,7 @@ int
|
||||
_mknod(Policy::Func::Search searchFunc,
|
||||
Policy::Func::Create createFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const mode_t mode,
|
||||
const dev_t dev)
|
||||
|
||||
+5
-4
@@ -14,6 +14,7 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
@@ -21,11 +22,11 @@
|
||||
namespace num
|
||||
{
|
||||
int
|
||||
to_size_t(const std::string &str,
|
||||
size_t &value)
|
||||
to_uint64_t(const std::string &str,
|
||||
uint64_t &value)
|
||||
{
|
||||
size_t tmp;
|
||||
char *endptr;
|
||||
char *endptr;
|
||||
uint64_t tmp;
|
||||
|
||||
tmp = strtoll(str.c_str(),&endptr,10);
|
||||
switch(*endptr)
|
||||
|
||||
+3
-1
@@ -14,9 +14,11 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace num
|
||||
{
|
||||
int to_size_t(const std::string &str, size_t &value);
|
||||
int to_uint64_t(const std::string &str, uint64_t &value);
|
||||
}
|
||||
|
||||
+5
-5
@@ -16,15 +16,15 @@
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "fs_base_open.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "rwlock.hpp"
|
||||
#include "ugid.hpp"
|
||||
@@ -45,7 +45,7 @@ _open_core(const string *basepath,
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
fd = ::open(fullpath.c_str(),flags);
|
||||
fd = fs::open(fullpath,flags);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
@@ -58,7 +58,7 @@ static
|
||||
int
|
||||
_open(Policy::Func::Search searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
const char *fusepath,
|
||||
const int flags,
|
||||
uint64_t &fh)
|
||||
|
||||
@@ -107,11 +107,11 @@ set_default_options(fuse_args &args)
|
||||
static
|
||||
int
|
||||
parse_and_process_minfreespace(const std::string &value,
|
||||
size_t &minfreespace)
|
||||
uint64_t &minfreespace)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = num::to_size_t(value,minfreespace);
|
||||
rv = num::to_uint64_t(value,minfreespace);
|
||||
if(rv == -1)
|
||||
return 1;
|
||||
|
||||
|
||||
+12
-2
@@ -16,9 +16,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "buildvector.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
#define POLICY(X,PP) (Policy(Policy::Enum::X,#X,Policy::Func::X,PP))
|
||||
#define PRESERVES_PATH true
|
||||
@@ -30,11 +30,16 @@ namespace mergerfs
|
||||
buildvector<Policy,true>
|
||||
(POLICY(invalid,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(all,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(epall,PRESERVES_PATH))
|
||||
(POLICY(epff,PRESERVES_PATH))
|
||||
(POLICY(eplfs,PRESERVES_PATH))
|
||||
(POLICY(eplus,PRESERVES_PATH))
|
||||
(POLICY(epmfs,PRESERVES_PATH))
|
||||
(POLICY(eprand,PRESERVES_PATH))
|
||||
(POLICY(erofs,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(ff,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(lfs,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(lus,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(mfs,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(newest,DOESNT_PRESERVE_PATH))
|
||||
(POLICY(rand,DOESNT_PRESERVE_PATH));
|
||||
@@ -45,11 +50,16 @@ namespace mergerfs
|
||||
|
||||
CONST_POLICY(invalid);
|
||||
CONST_POLICY(all);
|
||||
CONST_POLICY(epall);
|
||||
CONST_POLICY(epff);
|
||||
CONST_POLICY(eplfs);
|
||||
CONST_POLICY(eplus);
|
||||
CONST_POLICY(epmfs);
|
||||
CONST_POLICY(eprand);
|
||||
CONST_POLICY(erofs);
|
||||
CONST_POLICY(ff);
|
||||
CONST_POLICY(lfs);
|
||||
CONST_POLICY(lus);
|
||||
CONST_POLICY(mfs);
|
||||
CONST_POLICY(newest);
|
||||
CONST_POLICY(rand);
|
||||
|
||||
+30
-16
@@ -43,11 +43,16 @@ namespace mergerfs
|
||||
invalid = -1,
|
||||
BEGIN = 0,
|
||||
all = BEGIN,
|
||||
epall,
|
||||
epff,
|
||||
eplfs,
|
||||
eplus,
|
||||
epmfs,
|
||||
eprand,
|
||||
erofs,
|
||||
ff,
|
||||
lfs,
|
||||
lus,
|
||||
mfs,
|
||||
newest,
|
||||
rand,
|
||||
@@ -61,15 +66,14 @@ namespace mergerfs
|
||||
struct Func
|
||||
{
|
||||
typedef std::string string;
|
||||
typedef std::size_t size_t;
|
||||
typedef std::vector<string> strvec;
|
||||
typedef std::vector<const string*> cstrptrvec;
|
||||
typedef const string cstring;
|
||||
typedef const size_t csize_t;
|
||||
typedef const uint64_t cuint64_t;
|
||||
typedef const strvec cstrvec;
|
||||
typedef const Category::Enum::Type CType;
|
||||
|
||||
typedef int (*Ptr)(CType,cstrvec &,const char *,csize_t,cstrptrvec &);
|
||||
typedef int (*Ptr)(CType,cstrvec &,const char *,cuint64_t,cstrptrvec &);
|
||||
|
||||
template <CType T>
|
||||
class Base
|
||||
@@ -80,7 +84,7 @@ namespace mergerfs
|
||||
{}
|
||||
|
||||
int
|
||||
operator()(cstrvec &b,const char *c,csize_t d,cstrptrvec &e)
|
||||
operator()(cstrvec &b,const char *c,cuint64_t d,cstrptrvec &e)
|
||||
{
|
||||
return func(T,b,c,d,e);
|
||||
}
|
||||
@@ -93,16 +97,21 @@ namespace mergerfs
|
||||
typedef Base<Category::Enum::create> Create;
|
||||
typedef Base<Category::Enum::search> Search;
|
||||
|
||||
static int invalid(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int all(CType,cstrvec&,const char*,csize_t,cstrptrvec&);
|
||||
static int eplfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int epmfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int erofs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int ff(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int lfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int mfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int newest(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int rand(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
|
||||
static int invalid(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int all(CType,cstrvec&,const char*,cuint64_t,cstrptrvec&);
|
||||
static int epall(CType,cstrvec&,const char*,cuint64_t,cstrptrvec&);
|
||||
static int epff(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eplfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eplus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int epmfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int eprand(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int erofs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int ff(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int lfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int lus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int mfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int newest(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
static int rand(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -161,16 +170,21 @@ namespace mergerfs
|
||||
static const Policy &find(const Enum::Type);
|
||||
|
||||
public:
|
||||
static const std::vector<Policy> _policies_;
|
||||
static const Policy * const policies;
|
||||
static const std::vector<Policy> _policies_;
|
||||
static const Policy * const policies;
|
||||
|
||||
static const Policy &invalid;
|
||||
static const Policy &all;
|
||||
static const Policy &epall;
|
||||
static const Policy &epff;
|
||||
static const Policy &eplfs;
|
||||
static const Policy ⩱
|
||||
static const Policy &epmfs;
|
||||
static const Policy &eprand;
|
||||
static const Policy &erofs;
|
||||
static const Policy &ff;
|
||||
static const Policy &lfs;
|
||||
static const Policy &lus;
|
||||
static const Policy &mfs;
|
||||
static const Policy &newest;
|
||||
static const Policy &rand;
|
||||
|
||||
+6
-7
@@ -14,32 +14,31 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
|
||||
static
|
||||
int
|
||||
_all_create(const vector<string> &basepaths,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
size_t spaceavail;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
if(!fs::info(*basepath,readonly,spaceavail))
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
@@ -87,7 +86,7 @@ namespace mergerfs
|
||||
Policy::Func::all(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
static
|
||||
int
|
||||
_epall_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
|
||||
if(paths.empty())
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epall_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
}
|
||||
|
||||
if(paths.empty())
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::epall(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _epall_create(basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _epall_other(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_epff_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
const string *fallback;
|
||||
|
||||
fallback = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
if(fallback == NULL)
|
||||
fallback = basepath;
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
if(fallback == NULL)
|
||||
return POLICY_FAIL_ENOENT;
|
||||
|
||||
paths.push_back(fallback);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epff_other(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
|
||||
paths.push_back(basepath);
|
||||
|
||||
return POLICY_SUCCESS;
|
||||
}
|
||||
|
||||
return POLICY_FAIL_ENOENT;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_epff(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _epff_create(basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return _epff_other(basepaths,fusepath,paths);
|
||||
}
|
||||
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::epff(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = _epff(type,basepaths,fusepath,minfreespace,paths);
|
||||
if(POLICY_FAILED(rv))
|
||||
rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
+12
-13
@@ -14,45 +14,44 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::size_t;
|
||||
using mergerfs::Category;
|
||||
|
||||
static
|
||||
int
|
||||
_eplfs_create(const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
size_t eplfs;
|
||||
uint64_t eplfs;
|
||||
const string *eplfsbasepath;
|
||||
|
||||
eplfs = std::numeric_limits<size_t>::max();
|
||||
eplfs = std::numeric_limits<uint64_t>::max();
|
||||
eplfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
bool readonly;
|
||||
size_t spaceavail;
|
||||
uint64_t spaceavail;
|
||||
uint64_t _spaceused;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
if(!fs::info(*basepath,readonly,spaceavail))
|
||||
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
|
||||
continue;
|
||||
if(readonly)
|
||||
continue;
|
||||
@@ -80,14 +79,14 @@ _eplfs_other(const vector<string> &basepaths,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
string fullpath;
|
||||
size_t eplfs;
|
||||
uint64_t eplfs;
|
||||
const string *eplfsbasepath;
|
||||
|
||||
eplfs = std::numeric_limits<size_t>::max();
|
||||
eplfs = std::numeric_limits<uint64_t>::max();
|
||||
eplfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
size_t spaceavail;
|
||||
uint64_t spaceavail;
|
||||
const string *basepath = &basepaths[i];
|
||||
|
||||
fs::path::make(basepath,fusepath,fullpath);
|
||||
@@ -116,7 +115,7 @@ int
|
||||
_eplfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
@@ -131,7 +130,7 @@ namespace mergerfs
|
||||
Policy::Func::eplfs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const char *fusepath,
|
||||
const size_t minfreespace,
|
||||
const uint64_t minfreespace,
|
||||
vector<const string*> &paths)
|
||||
{
|
||||
int rv;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user