Home > Back-end >  Are extended attributes name and value guaranteed to be UTF-8 encoded
Are extended attributes name and value guaranteed to be UTF-8 encoded

Time:10-15

I am trying to implement Rusty wrappers for those extended attributes syscalls, if they are guaranteed to be UTF-8 encoded, then I can use the type String, or I have to use OsString.

I googled a lot, but only found these two pages:

I would like to know information on as many platforms as possible since I try to cover them all in my implementation.

CodePudding user response:

No, in Linux they are absolutely not guaranteed to be in UTF-8. Attribute values are not even guaranteed to be strings at all. They are just arrays of bytes with no constraints on them.

int setxattr(const char *path, const char *name,
             const void *value, size_t size, int flags);

const void *value, size_t size is not a good way to pass a string to a function. const char* name is, and attribute names are indeed strings, but they are null-terminated byte strings.

Freedesktop recommendations are just that, recommendations. They don't prevent anyone from creating any attribute they want.

  • Related