aboutsummaryrefslogtreecommitdiff
path: root/test/fuse_integration/xattr_darwin.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2025-08-31 12:25:41 -0700
committerchrislu <chris.lu@gmail.com>2025-08-31 12:25:41 -0700
commitd7dc9a47d59c44b8ec0e2bd3923b42d10ac37506 (patch)
tree5bbfff429be6bf6f6b318a0740498f793a724b15 /test/fuse_integration/xattr_darwin.go
parentfd1149e5b26c6a762980f2e36c44a19ab081ee8e (diff)
downloadseaweedfs-d7dc9a47d59c44b8ec0e2bd3923b42d10ac37506.tar.xz
seaweedfs-d7dc9a47d59c44b8ec0e2bd3923b42d10ac37506.zip
add more posix tests
Diffstat (limited to 'test/fuse_integration/xattr_darwin.go')
-rw-r--r--test/fuse_integration/xattr_darwin.go125
1 files changed, 125 insertions, 0 deletions
diff --git a/test/fuse_integration/xattr_darwin.go b/test/fuse_integration/xattr_darwin.go
new file mode 100644
index 000000000..6bd6f2a90
--- /dev/null
+++ b/test/fuse_integration/xattr_darwin.go
@@ -0,0 +1,125 @@
+//go:build darwin
+
+package fuse
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+// Extended attributes support for macOS
+
+const (
+ // macOS-specific flags
+ XATTR_NOFOLLOW = 0x0001
+ XATTR_CREATE = 0x0002
+ XATTR_REPLACE = 0x0004
+)
+
+func setXattr(path, name string, value []byte, flags int) error {
+ pathBytes, err := syscall.BytePtrFromString(path)
+ if err != nil {
+ return err
+ }
+ nameBytes, err := syscall.BytePtrFromString(name)
+ if err != nil {
+ return err
+ }
+
+ var valuePtr unsafe.Pointer
+ if len(value) > 0 {
+ valuePtr = unsafe.Pointer(&value[0])
+ }
+
+ _, _, errno := syscall.Syscall6(syscall.SYS_SETXATTR,
+ uintptr(unsafe.Pointer(pathBytes)),
+ uintptr(unsafe.Pointer(nameBytes)),
+ uintptr(valuePtr),
+ uintptr(len(value)),
+ uintptr(0), // position (not used for regular files)
+ uintptr(flags))
+
+ if errno != 0 {
+ return errno
+ }
+ return nil
+}
+
+func getXattr(path, name string, value []byte) (int, error) {
+ pathBytes, err := syscall.BytePtrFromString(path)
+ if err != nil {
+ return 0, err
+ }
+ nameBytes, err := syscall.BytePtrFromString(name)
+ if err != nil {
+ return 0, err
+ }
+
+ var valuePtr unsafe.Pointer
+ if len(value) > 0 {
+ valuePtr = unsafe.Pointer(&value[0])
+ }
+
+ size, _, errno := syscall.Syscall6(syscall.SYS_GETXATTR,
+ uintptr(unsafe.Pointer(pathBytes)),
+ uintptr(unsafe.Pointer(nameBytes)),
+ uintptr(valuePtr),
+ uintptr(len(value)),
+ uintptr(0), // position
+ uintptr(0)) // options
+
+ if errno != 0 {
+ return 0, errno
+ }
+ return int(size), nil
+}
+
+func listXattr(path string, list []byte) (int, error) {
+ pathBytes, err := syscall.BytePtrFromString(path)
+ if err != nil {
+ return 0, err
+ }
+
+ var listPtr unsafe.Pointer
+ if len(list) > 0 {
+ listPtr = unsafe.Pointer(&list[0])
+ }
+
+ size, _, errno := syscall.Syscall6(syscall.SYS_LISTXATTR,
+ uintptr(unsafe.Pointer(pathBytes)),
+ uintptr(listPtr),
+ uintptr(len(list)),
+ uintptr(0), // options
+ 0, 0)
+
+ if errno != 0 {
+ return 0, errno
+ }
+ return int(size), nil
+}
+
+func removeXattr(path, name string) error {
+ pathBytes, err := syscall.BytePtrFromString(path)
+ if err != nil {
+ return err
+ }
+ nameBytes, err := syscall.BytePtrFromString(name)
+ if err != nil {
+ return err
+ }
+
+ _, _, errno := syscall.Syscall6(syscall.SYS_REMOVEXATTR,
+ uintptr(unsafe.Pointer(pathBytes)),
+ uintptr(unsafe.Pointer(nameBytes)),
+ uintptr(0), // options
+ 0, 0, 0)
+
+ if errno != 0 {
+ return errno
+ }
+ return nil
+}
+
+func isXattrSupported() bool {
+ return true
+}