libgocryptfs/internal/fusefrontend/file_setattr.go

86 lines
1.6 KiB
Go
Raw Normal View History

2020-07-05 20:05:07 +02:00
package fusefrontend
import (
"context"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
2020-07-12 13:13:24 +02:00
"github.com/rfjakob/gocryptfs/internal/tlog"
2020-07-05 20:05:07 +02:00
)
func (f *File) Setattr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno) {
2020-07-05 20:05:07 +02:00
errno = f.setAttr(ctx, in)
if errno != 0 {
return errno
}
return f.Getattr(ctx, out)
}
func (f *File) setAttr(ctx context.Context, in *fuse.SetAttrIn) (errno syscall.Errno) {
2020-07-05 20:05:07 +02:00
f.fdLock.RLock()
defer f.fdLock.RUnlock()
if f.released {
2020-07-12 13:13:24 +02:00
tlog.Warn.Printf("ino%d fh%d: Truncate on released file", f.qIno.Ino, f.intFd())
2020-07-05 20:05:07 +02:00
return syscall.EBADF
}
f.fileTableEntry.ContentLock.Lock()
defer f.fileTableEntry.ContentLock.Unlock()
v2api: properly implement Node.Setattr We used to always open a *File2 and letting the *File2 handle Setattr. This does not work it we cannot open the file! Before: $ go test 2020/07/12 20:14:57 writer: Write/Writev failed, err: 2=no such file or directory. opcode: INTERRUPT 2020/07/12 20:14:57 writer: Write/Writev failed, err: 2=no such file or directory. opcode: INTERRUPT --- FAIL: TestLchown (0.00s) matrix_test.go:634: lchown /tmp/gocryptfs-test-parent-1026/014500839/default-plain/symlink: too many levels of symbolic links touch: setting times of '/tmp/gocryptfs-test-parent-1026/014500839/default-plain/utimesnano_symlink': Too many levels of symbolic links --- FAIL: TestUtimesNanoSymlink (0.00s) matrix_test.go:655: exit status 1 --- FAIL: TestMkfifo (0.00s) matrix_test.go:755: file exists --- FAIL: TestMagicNames (0.00s) matrix_test.go:773: Testing n="gocryptfs.longname.QhUr5d9FHerwEs--muUs6_80cy6JRp89c1otLwp92Cs" matrix_test.go:773: Testing n="gocryptfs.diriv" matrix_test.go:815: open /tmp/gocryptfs-test-parent-1026/014500839/default-plain/linktarget: permission denied --- FAIL: TestChmod (0.00s) matrix_test.go:840: chmod 444 -> 000 failed: permission denied matrix_test.go:840: chmod 444 -> 111 failed: permission denied matrix_test.go:840: chmod 444 -> 123 failed: permission denied matrix_test.go:840: chmod 444 -> 321 failed: permission denied FAIL exit status 1 FAIL github.com/rfjakob/gocryptfs/tests/matrix 0.790s After: $ go test --- FAIL: TestMkfifo (0.00s) matrix_test.go:755: file exists --- FAIL: TestMagicNames (0.00s) matrix_test.go:773: Testing n="gocryptfs.longname.QhUr5d9FHerwEs--muUs6_80cy6JRp89c1otLwp92Cs" matrix_test.go:773: Testing n="gocryptfs.diriv" matrix_test.go:815: open /tmp/gocryptfs-test-parent-1026/501766059/default-plain/linktarget: permission denied --- FAIL: TestChmod (0.00s) matrix_test.go:849: modeHave 0644 != modeWant 0 FAIL exit status 1 FAIL github.com/rfjakob/gocryptfs/tests/matrix 0.787s
2020-07-12 20:17:15 +02:00
// fchmod(2)
2020-07-05 20:05:07 +02:00
if mode, ok := in.GetMode(); ok {
errno = fs.ToErrno(syscall.Fchmod(f.intFd(), mode))
if errno != 0 {
return errno
}
}
v2api: properly implement Node.Setattr We used to always open a *File2 and letting the *File2 handle Setattr. This does not work it we cannot open the file! Before: $ go test 2020/07/12 20:14:57 writer: Write/Writev failed, err: 2=no such file or directory. opcode: INTERRUPT 2020/07/12 20:14:57 writer: Write/Writev failed, err: 2=no such file or directory. opcode: INTERRUPT --- FAIL: TestLchown (0.00s) matrix_test.go:634: lchown /tmp/gocryptfs-test-parent-1026/014500839/default-plain/symlink: too many levels of symbolic links touch: setting times of '/tmp/gocryptfs-test-parent-1026/014500839/default-plain/utimesnano_symlink': Too many levels of symbolic links --- FAIL: TestUtimesNanoSymlink (0.00s) matrix_test.go:655: exit status 1 --- FAIL: TestMkfifo (0.00s) matrix_test.go:755: file exists --- FAIL: TestMagicNames (0.00s) matrix_test.go:773: Testing n="gocryptfs.longname.QhUr5d9FHerwEs--muUs6_80cy6JRp89c1otLwp92Cs" matrix_test.go:773: Testing n="gocryptfs.diriv" matrix_test.go:815: open /tmp/gocryptfs-test-parent-1026/014500839/default-plain/linktarget: permission denied --- FAIL: TestChmod (0.00s) matrix_test.go:840: chmod 444 -> 000 failed: permission denied matrix_test.go:840: chmod 444 -> 111 failed: permission denied matrix_test.go:840: chmod 444 -> 123 failed: permission denied matrix_test.go:840: chmod 444 -> 321 failed: permission denied FAIL exit status 1 FAIL github.com/rfjakob/gocryptfs/tests/matrix 0.790s After: $ go test --- FAIL: TestMkfifo (0.00s) matrix_test.go:755: file exists --- FAIL: TestMagicNames (0.00s) matrix_test.go:773: Testing n="gocryptfs.longname.QhUr5d9FHerwEs--muUs6_80cy6JRp89c1otLwp92Cs" matrix_test.go:773: Testing n="gocryptfs.diriv" matrix_test.go:815: open /tmp/gocryptfs-test-parent-1026/501766059/default-plain/linktarget: permission denied --- FAIL: TestChmod (0.00s) matrix_test.go:849: modeHave 0644 != modeWant 0 FAIL exit status 1 FAIL github.com/rfjakob/gocryptfs/tests/matrix 0.787s
2020-07-12 20:17:15 +02:00
// fchown(2)
2020-07-05 20:05:07 +02:00
uid32, uOk := in.GetUID()
gid32, gOk := in.GetGID()
if uOk || gOk {
uid := -1
gid := -1
if uOk {
uid = int(uid32)
}
if gOk {
gid = int(gid32)
}
errno = fs.ToErrno(syscall.Fchown(f.intFd(), uid, gid))
if errno != 0 {
return errno
}
}
// utimens(2)
mtime, mok := in.GetMTime()
atime, aok := in.GetATime()
if mok || aok {
ap := &atime
mp := &mtime
if !aok {
ap = nil
}
if !mok {
mp = nil
}
errno = fs.ToErrno(syscallcompat.FutimesNano(f.intFd(), ap, mp))
if errno != 0 {
return errno
}
}
// truncate(2)
if sz, ok := in.GetSize(); ok {
errno = syscall.Errno(f.truncate(sz))
if errno != 0 {
return errno
}
}
return 0
}