aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/node_xattr_linux.go
blob: 226ace44559437fb249d84ca7a1e8852a4f65abe (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
30
31
32
33
34
35
36
37
38
39
40
41
package fusefrontend_reverse

import (
	"fmt"
	"syscall"

	"github.com/hanwen/go-fuse/v2/fs"
	"golang.org/x/sys/unix"

	"github.com/rfjakob/gocryptfs/v2/internal/syscallcompat"
)

// On Linux, ENODATA is returned when an attribute is not found.
const noSuchAttributeError = syscall.ENODATA

func (n *Node) getXAttr(cAttr string) (out []byte, errno syscall.Errno) {
	d, errno := n.prepareAtSyscall("")
	if errno != 0 {
		return
	}
	defer syscall.Close(d.dirfd)

	procPath := fmt.Sprintf("/proc/self/fd/%d/%s", d.dirfd, d.pName)
	pData, err := syscallcompat.Lgetxattr(procPath, cAttr)
	if err != nil {
		return nil, fs.ToErrno(err)
	}
	return pData, 0
}

func (n *Node) listXAttr(buf []byte) (sz int, errno syscall.Errno) {
	d, errno := n.prepareAtSyscall("")
	if errno != 0 {
		return
	}
	defer syscall.Close(d.dirfd)

	procPath := fmt.Sprintf("/proc/self/fd/%d/%s", d.dirfd, d.pName)
	sz, err := unix.Llistxattr(procPath, buf)
	return sz, fs.ToErrno(err)
}