pxattr 2.1
|
Extended attributes are arbitrarily named pieces of data associated with a file and managed by the file system.
The names and the values for the attributes are freely chosen by applications and/or users, with very few restrictions. Many recent systems and filesystems support extended attributes, but the interfaces used to manage them are far from identical.
Linux, FreeBSD and Mac OS X all provide similar extended attributes functionality.
The pxattr package provides a portable programming interface for managing file extended attributes on all three systems. It consists in a single C++ module (one source and one include file), which is to be included in the application source code (being too trivial to justify a library).
Calls are provided to read, modify or delete extended attributes. Check the Namespaces above for more detail.
Linux note: on Linux, user attributes are distinguished by having a "user." prefix in their name. On Mac OS X and FreeBSD, the user and other name spaces are distinguished by argument to the library calls. pxattr hides the "user." prefix on Linux, so that you should not specify it when reading or setting a value.
The C++ file can also be compiled into program which provides a handy way to manage attributes from the command line.
Especially, the pxattr command can produce a dump of the extended attributes for a directory tree. This dump can then be restored if the tree has been copied elsewhere. This works across the three platforms and can provide a workaround for the current lack of common extended attributes archiving commands. Method:
cd /just/above/my/treedir/.. pxattr -lR treedir > treedir/extattr_archive.txt # or whatever... tar cf /tmp/myarchive.tar treedir
On the target:
tar xf myarchive.tar pxattr -S treedir/extattr_archive.txt
Notice that I took care to preserve the relative paths when doing the backup and the restore. In a pinch, the dump could be edited to fix the paths (use sed or emacs), the dump format is line-oriented but as binary as the extended attributes contents, with just a few escaped characters.
Mac OS note: the Mac OS finder uses a number of extended attributes, two of which are of special interest: "com.apple.metadata:_kMDItemUserTags" for storing tags (colors or custom values), and "com.apple.metadata:kMDItemFinderComment" for storing a comment. The values are stored in the rather obscure Mac OS "plist" format. The main "pxattr" program will decode the values when they are explicitely requested by key. All com.apple.* tags will otherwise be skipped when listing tags (because of the opaque formats).