hanwen / go-fuse

FUSE bindings for Go
Other
1.97k stars 313 forks source link

How to create custom xattr with v2/fs #482

Closed dymart closed 6 months ago

dymart commented 10 months ago

Really appreciate the project.

I'm wondering if there are any examples, tests, or any more information about how to create custom xattr functions for example getxattr with v2/fs, which do not use the gatxattr syscall but sets a custom value. There were some for fuse/nodefs and fuse/pathfs.

https://github.com/hanwen/go-fuse/blob/0b3e1fde6eb5eeb1600388535913ee66f23bdc5b/fs/api.go#L246 // Getxattr should read data for the given attribute into // dest and return the number of bytes. If dest is too // small, it should return ERANGE and the size of the attribute. // If not defined, Getxattr will return ENOATTR.

The comments aren't clear how to read data for the given attribute into dest. Any hints or quick examples would be greatly appreciated. Even a simple explanation about how this should be approached would be very welcome.

Any help or guidance on this would be appreciated. If I missed a test, example or something else that clearly explains this let me know and feel free to close the issue.

Thank you

hanwen commented 10 months ago

have a look at https://github.com/hanwen/go-fuse/blob/master/fs/loopback_linux.go#L21

Does that help?

hanwen commented 10 months ago

I mean: if you don't want to use the syscall, you could do something like

  val := "hello"
  copy(dest, []byte(val))
  return len(val), 0
dymart commented 6 months ago

Hey, sorry for the slow response. Your answers were great! Really appreciate it :)