syscallcompat

package
v2.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package syscallcompat wraps Linux-specific syscalls.

Index

Constants

View Source
const (
	// QuirkBrokenFalloc means the falloc is broken.
	// Preallocation on Btrfs is broken ( https://github.com/rfjakob/gocryptfs/issues/395 )
	// and slow ( https://github.com/rfjakob/gocryptfs/issues/63 ).
	QuirkBrokenFalloc = uint64(1 << iota)
	// QuirkDuplicateIno1 means that we have duplicate inode numbers.
	// On MacOS ExFAT, all empty files share inode number 1:
	// https://github.com/rfjakob/gocryptfs/issues/585
	QuirkDuplicateIno1
	// QuirkNoUserXattr means that user.* xattrs are not supported
	QuirkNoUserXattr
)
View Source
const (

	// O_DIRECT means oncached I/O on Linux. No direct equivalent on MacOS and defined
	// to zero there.
	O_DIRECT = syscall.O_DIRECT

	// O_PATH is only defined on Linux
	O_PATH = unix.O_PATH

	// Only defined on Linux
	RENAME_NOREPLACE = unix.RENAME_NOREPLACE
	RENAME_WHITEOUT  = unix.RENAME_WHITEOUT
	RENAME_EXCHANGE  = unix.RENAME_EXCHANGE
)
View Source
const PATH_MAX = 4096

PATH_MAX is the maximum allowed path length on Linux. It is not defined on Darwin, so we use the Linux value.

View Source
const XATTR_BUFSZ = XATTR_SIZE_MAX + 1024

Make the buffer 1kB bigger so we can detect overflows. Unfortunately, slices larger than 64kB are always allocated on the heap.

View Source
const XATTR_BUFSZ_SMALL = 500

We try with a small buffer first - this one can be allocated on the stack.

View Source
const XATTR_SIZE_MAX = 65536

Variables

This section is empty.

Functions

func DetectQuirks

func DetectQuirks(cipherdir string) (q uint64)

DetectQuirks decides if there are known quirks on the backing filesystem that need to be workarounded.

Tested by tests/root_test.TestBtrfsQuirks

func Dup3

func Dup3(oldfd int, newfd int, flags int) (err error)

Dup3 wraps the Dup3 syscall. We want to use Dup3 rather than Dup2 because Dup2 is not implemented on arm64.

func EnospcPrealloc

func EnospcPrealloc(fd int, off int64, len int64) (err error)

EnospcPrealloc preallocates ciphertext space without changing the file size. This guarantees that we don't run out of space while writing a ciphertext block (that would corrupt the block).

func Faccessat

func Faccessat(dirfd int, path string, mode uint32) error

Faccessat exists both in Linux and in MacOS 10.10+, but the Linux version DOES NOT support any flags. Emulate AT_SYMLINK_NOFOLLOW like glibc does.

func Fallocate

func Fallocate(fd int, mode uint32, off int64, len int64) (err error)

Fallocate wraps the Fallocate syscall.

func FchmodatNofollow

func FchmodatNofollow(dirfd int, path string, mode uint32) (err error)

FchmodatNofollow is like Fchmodat but never follows symlinks.

This should be handled by the AT_SYMLINK_NOFOLLOW flag, but Linux does not implement it, so we have to perform an elaborate dance with O_PATH and /proc/self/fd.

See also: Qemu implemented the same logic as fchmodat_nofollow(): https://git.qemu.org/?p=qemu.git;a=blob;f=hw/9pfs/9p-local.c#l335

func Fchownat

func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)

Fchownat syscall.

func Fgetxattr

func Fgetxattr(fd int, attr string) (val []byte, err error)

Fgetxattr is a wrapper around unix.Fgetxattr that handles the buffer sizing.

func Flistxattr

func Flistxattr(fd int) (attrs []string, err error)

Flistxattr is a wrapper for unix.Flistxattr that handles buffer sizing and parsing the returned blob to a string slice.

func Flush

func Flush(fd int) error

Flush is a helper for the FUSE command FLUSH. Retries on EINTR.

func Fstatat

func Fstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error)

Fstatat syscall. Retries on EINTR.

func Fstatat2

func Fstatat2(dirfd int, path string, flags int) (*syscall.Stat_t, error)

Fstatat2 is a more convenient version of Fstatat. It allocates a Stat_t for you and also handles the Unix2syscall conversion. Retries on EINTR.

func FutimesNano

func FutimesNano(fd int, a *time.Time, m *time.Time) (err error)

FutimesNano syscall.

func Getdents

func Getdents(fd int) ([]fuse.DirEntry, error)

Getdents syscall with "." and ".." filtered out.

func GetdentsSpecial

func GetdentsSpecial(fd int) (entries []fuse.DirEntry, entriesSpecial []fuse.DirEntry, err error)

GetdentsSpecial calls the Getdents syscall, with normal entries and "." / ".." split into two slices.

func IsENOSPC

func IsENOSPC(err error) bool

IsENOSPC tries to find out if "err" is a (potentially wrapped) ENOSPC error.

func Lgetxattr

func Lgetxattr(path string, attr string) (val []byte, err error)

Lgetxattr is a wrapper around unix.Lgetxattr that handles the buffer sizing.

func Llistxattr

func Llistxattr(path string) (attrs []string, err error)

Llistxattr is a wrapper for unix.Llistxattr that handles buffer sizing and parsing the returned blob to a string slice.

func LsetxattrUser

func LsetxattrUser(path string, attr string, data []byte, flags int, context *fuse.Context) (err error)

LsetxattrUser runs the Lsetxattr syscall in the context of a different user. This is useful when setting ACLs, as the result depends on the user running the operation (see fuse-xfstests generic/375).

If `context` is nil, this function behaves like ordinary Lsetxattr.

func MkdiratUser

func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error)

MkdiratUser runs the Mkdirat syscall in the context of a different user. If `context` is nil, this function behaves like ordinary Mkdirat.

See OpenatUser() for how this works.

func Mknodat

func Mknodat(dirfd int, path string, mode uint32, dev int) (err error)

Mknodat wraps the Mknodat syscall.

func MknodatUser

func MknodatUser(dirfd int, path string, mode uint32, dev int, context *fuse.Context) (err error)

MknodatUser runs the Mknodat syscall in the context of a different user. If `context` is nil, this function behaves like ordinary Mknodat.

See OpenatUser() for how this works.

func Open

func Open(path string, mode int, perm uint32) (fd int, err error)

Open wraps syscall.Open. Retries on EINTR.

func OpenDirNofollow

func OpenDirNofollow(baseDir string, relPath string) (fd int, err error)

OpenDirNofollow opens the dir at "relPath" in a way that is secure against symlink attacks. Symlinks that are part of "relPath" are never followed. This function is implemented by walking the directory tree, starting at "baseDir", using the Openat syscall with the O_NOFOLLOW flag. Symlinks that are part of the "baseDir" path are followed. Retries on EINTR.

func Openat

func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)

Openat wraps the Openat syscall. Retries on EINTR.

func OpenatUser

func OpenatUser(dirfd int, path string, flags int, mode uint32, context *fuse.Context) (fd int, err error)

OpenatUser runs the Openat syscall in the context of a different user.

It switches the current thread to the new user, performs the syscall, and switches back.

If `context` is nil, this function behaves like ordinary Openat (no user switching).

func Readlinkat

func Readlinkat(dirfd int, path string) (string, error)

Readlinkat is a convenience wrapper around unix.Readlinkat() that takes care of buffer sizing. Implemented like os.Readlink().

func Renameat

func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)

Renameat wraps the Renameat syscall. Retries on EINTR.

func Renameat2

func Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error)

Renameat2 does not exist on Darwin, so we have to wrap it here. Retries on EINTR.

func SymlinkatUser

func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.Context) (err error)

SymlinkatUser runs the Symlinkat syscall in the context of a different user. If `context` is nil, this function behaves like ordinary Symlinkat.

See OpenatUser() for how this works.

func Unix2syscall

func Unix2syscall(u unix.Stat_t) syscall.Stat_t

Unix2syscall converts a unix.Stat_t struct to a syscall.Stat_t struct. A direct cast does not work because the padding is named differently in unix.Stat_t for some reason ("X__unused" in syscall, "_" in unix).

func Unlinkat

func Unlinkat(dirfd int, path string, flags int) (err error)

Unlinkat syscall. Retries on EINTR.

func UtimesNanoAtNofollow

func UtimesNanoAtNofollow(dirfd int, path string, a *time.Time, m *time.Time) (err error)

UtimesNanoAtNofollow is like UtimesNanoAt but never follows symlinks. Retries on EINTR.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL