pythonoperating-systemxattr

Why must a 'user.' be prepended to the name when setting a file's xattr with os.setxattr()?


I am saving data that I guess could be deemed metadata on a JSON serialized file:

os.setxattr('/var/tmp/test.json', 'user.keyname', b'value')

and I can get the bytes value back via:

os.getxattr('/var/tmp/test.json', 'user.keyname')

The only way I can get this to work is by putting user. in front of the key/name that I want to use. Why is this?


Solution

  • https://jp-andre.pagesperso-orange.fr/extend-attr.html

    On Linux, specifically, four categories of extended attributes have been defined :

    • trusted: to record properties which should only be accessed by the kernel,
    • security: to record security properties of a file,
    • system: to record other system related properties on which the file owner has some control,
    • user: to record properties defined by applications.

    The names of the extended attributes must be prefixed by the name of the category and a dot, hence these categories are generally qualified as name spaces.