2020-09-09 11:17:19 +02:00
|
|
|
package fusefrontend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
|
|
|
|
"github.com/hanwen/go-fuse/v2/fs"
|
2021-06-02 19:10:36 +02:00
|
|
|
"github.com/hanwen/go-fuse/v2/fuse"
|
2020-09-09 11:17:19 +02:00
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
|
|
|
)
|
|
|
|
|
|
|
|
// On Darwin we have to unset XATTR_NOSECURITY 0x0008
|
|
|
|
func filterXattrSetFlags(flags int) int {
|
|
|
|
// See https://opensource.apple.com/source/xnu/xnu-1504.15.3/bsd/sys/xattr.h.auto.html
|
|
|
|
const XATTR_NOSECURITY = 0x0008
|
|
|
|
|
|
|
|
return flags &^ XATTR_NOSECURITY
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) getXAttr(cAttr string) (out []byte, errno syscall.Errno) {
|
fusefrontend: implement recursive diriv caching
The new contrib/maxlen.bash showed that we have exponential
runtime with respect to directory depth.
The new recursive diriv caching is a lot smarter as it caches
intermediate lookups. maxlen.bash now completes in a few seconds.
xfstests results same as
https://github.com/rfjakob/fuse-xfstests/blob/2d158e4c82be85c15269af77498e353f928f4fab/screenlog.0 :
Failures: generic/035 generic/062 generic/080 generic/093 generic/099 generic/215 generic/285 generic/319 generic/426 generic/444 generic/467 generic/477 generic/523
Failed 13 of 580 tests
benchmark.bash results are identical:
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.BdQ: gocryptfs v2.0.1-17-g6b09bc0; go-fuse v2.1.1-0.20210611132105-24a1dfe6b4f8; 2021-06-25 go1.16.5 linux/amd64
/tmp/benchmark.bash.BdQ.mnt is a mountpoint
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 0,4821 s, 544 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0,266061 s, 985 MB/s
UNTAR: 8,280
MD5: 4,564
LS: 1,745
RM: 2,244
2021-06-25 11:33:18 +02:00
|
|
|
dirfd, cName, errno := n.prepareAtSyscallMyself()
|
2020-09-09 11:17:19 +02:00
|
|
|
if errno != 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer syscall.Close(dirfd)
|
|
|
|
|
|
|
|
// O_NONBLOCK to not block on FIFOs.
|
|
|
|
fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
defer syscall.Close(fd)
|
|
|
|
|
|
|
|
cData, err := syscallcompat.Fgetxattr(fd, cAttr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cData, 0
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:10:36 +02:00
|
|
|
func (n *Node) setXAttr(context *fuse.Context, cAttr string, cData []byte, flags uint32) (errno syscall.Errno) {
|
fusefrontend: implement recursive diriv caching
The new contrib/maxlen.bash showed that we have exponential
runtime with respect to directory depth.
The new recursive diriv caching is a lot smarter as it caches
intermediate lookups. maxlen.bash now completes in a few seconds.
xfstests results same as
https://github.com/rfjakob/fuse-xfstests/blob/2d158e4c82be85c15269af77498e353f928f4fab/screenlog.0 :
Failures: generic/035 generic/062 generic/080 generic/093 generic/099 generic/215 generic/285 generic/319 generic/426 generic/444 generic/467 generic/477 generic/523
Failed 13 of 580 tests
benchmark.bash results are identical:
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.BdQ: gocryptfs v2.0.1-17-g6b09bc0; go-fuse v2.1.1-0.20210611132105-24a1dfe6b4f8; 2021-06-25 go1.16.5 linux/amd64
/tmp/benchmark.bash.BdQ.mnt is a mountpoint
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 0,4821 s, 544 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0,266061 s, 985 MB/s
UNTAR: 8,280
MD5: 4,564
LS: 1,745
RM: 2,244
2021-06-25 11:33:18 +02:00
|
|
|
dirfd, cName, errno := n.prepareAtSyscallMyself()
|
2020-09-09 11:17:19 +02:00
|
|
|
if errno != 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer syscall.Close(dirfd)
|
|
|
|
|
|
|
|
// O_NONBLOCK to not block on FIFOs.
|
|
|
|
fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
|
|
|
|
// Directories cannot be opened read-write. Retry.
|
|
|
|
if err == syscall.EISDIR {
|
|
|
|
fd, err = syscallcompat.Openat(dirfd, cName, syscall.O_RDONLY|syscall.O_DIRECTORY|syscall.O_NONBLOCK, 0)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
defer syscall.Close(fd)
|
|
|
|
|
|
|
|
err = unix.Fsetxattr(fd, cAttr, cData, int(flags))
|
|
|
|
return fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) removeXAttr(cAttr string) (errno syscall.Errno) {
|
fusefrontend: implement recursive diriv caching
The new contrib/maxlen.bash showed that we have exponential
runtime with respect to directory depth.
The new recursive diriv caching is a lot smarter as it caches
intermediate lookups. maxlen.bash now completes in a few seconds.
xfstests results same as
https://github.com/rfjakob/fuse-xfstests/blob/2d158e4c82be85c15269af77498e353f928f4fab/screenlog.0 :
Failures: generic/035 generic/062 generic/080 generic/093 generic/099 generic/215 generic/285 generic/319 generic/426 generic/444 generic/467 generic/477 generic/523
Failed 13 of 580 tests
benchmark.bash results are identical:
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.BdQ: gocryptfs v2.0.1-17-g6b09bc0; go-fuse v2.1.1-0.20210611132105-24a1dfe6b4f8; 2021-06-25 go1.16.5 linux/amd64
/tmp/benchmark.bash.BdQ.mnt is a mountpoint
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 0,4821 s, 544 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0,266061 s, 985 MB/s
UNTAR: 8,280
MD5: 4,564
LS: 1,745
RM: 2,244
2021-06-25 11:33:18 +02:00
|
|
|
dirfd, cName, errno := n.prepareAtSyscallMyself()
|
2020-09-09 11:17:19 +02:00
|
|
|
if errno != 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer syscall.Close(dirfd)
|
|
|
|
|
|
|
|
// O_NONBLOCK to not block on FIFOs.
|
|
|
|
fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
|
|
|
|
// Directories cannot be opened read-write. Retry.
|
|
|
|
if err == syscall.EISDIR {
|
|
|
|
fd, err = syscallcompat.Openat(dirfd, cName, syscall.O_RDONLY|syscall.O_DIRECTORY|syscall.O_NONBLOCK, 0)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
defer syscall.Close(fd)
|
|
|
|
|
|
|
|
err = unix.Fremovexattr(fd, cAttr)
|
|
|
|
return fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) listXAttr() (out []string, errno syscall.Errno) {
|
fusefrontend: implement recursive diriv caching
The new contrib/maxlen.bash showed that we have exponential
runtime with respect to directory depth.
The new recursive diriv caching is a lot smarter as it caches
intermediate lookups. maxlen.bash now completes in a few seconds.
xfstests results same as
https://github.com/rfjakob/fuse-xfstests/blob/2d158e4c82be85c15269af77498e353f928f4fab/screenlog.0 :
Failures: generic/035 generic/062 generic/080 generic/093 generic/099 generic/215 generic/285 generic/319 generic/426 generic/444 generic/467 generic/477 generic/523
Failed 13 of 580 tests
benchmark.bash results are identical:
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.BdQ: gocryptfs v2.0.1-17-g6b09bc0; go-fuse v2.1.1-0.20210611132105-24a1dfe6b4f8; 2021-06-25 go1.16.5 linux/amd64
/tmp/benchmark.bash.BdQ.mnt is a mountpoint
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 0,4821 s, 544 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0,266061 s, 985 MB/s
UNTAR: 8,280
MD5: 4,564
LS: 1,745
RM: 2,244
2021-06-25 11:33:18 +02:00
|
|
|
dirfd, cName, errno := n.prepareAtSyscallMyself()
|
2020-09-09 11:17:19 +02:00
|
|
|
if errno != 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer syscall.Close(dirfd)
|
|
|
|
|
|
|
|
// O_NONBLOCK to not block on FIFOs.
|
|
|
|
fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
defer syscall.Close(fd)
|
|
|
|
|
|
|
|
cNames, err := syscallcompat.Flistxattr(fd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fs.ToErrno(err)
|
|
|
|
}
|
|
|
|
return cNames, 0
|
|
|
|
}
|