blob: 6f92cfe15195b68efcb3050d027bf56f718b3248 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package fusefrontend
import (
"golang.org/x/sys/unix"
"github.com/rfjakob/gocryptfs/v2/internal/syscallcompat"
)
// SharedStorageLock conveniently wraps F_OFD_SETLKW
// See https://man7.org/linux/man-pages/man2/fcntl.2.html -> "Open file description locks (non-POSIX)"
//
// lkType is one of:
// * unix.F_RDLCK (shared read lock)
// * unix.F_WRLCK (exclusive write lock)
// * unix.F_UNLCK (unlock)
//
// This function is a no-op if args.SharedStorage == false.
func (f *File) LockSharedStorage(lkType int16, lkStart int64, lkLen int64) error {
if !f.rootNode.args.SharedStorage {
return nil
}
lk := unix.Flock_t{
Type: lkType,
Whence: unix.SEEK_SET,
Start: lkStart,
Len: lkLen,
}
return unix.FcntlFlock(uintptr(f.intFd()), syscallcompat.F_OFD_SETLKW, &lk)
}
|