Signed-off-by: Alexander Hajnal <trinitydesktop@alephnull.net>feat/tdeio-xattr-support
parent
8d96e85f7d
commit
c383a347ea
@ -0,0 +1,86 @@
|
|||||||
|
This is a small patch adding user extended attribute support[1] for local files
|
||||||
|
to tdeio. With the patch in place user xattrs are preserved when copying or
|
||||||
|
moving files on the local system[2]. It relies on libattr[3] to do the heavy
|
||||||
|
lifting.
|
||||||
|
|
||||||
|
The code adds a call to attr_copy_file in libattr that copies the user xattrs
|
||||||
|
from the source file to the destination file. The call is made after the
|
||||||
|
source file has been closed and immediately before the source file is deleted
|
||||||
|
(in the case that a move is being done). This code is based on the sample
|
||||||
|
code[4] provided with libattr (examples/copyattr.c).
|
||||||
|
|
||||||
|
This code has been in daily use by the author of this patch for just over five
|
||||||
|
years without any issues. What's missing though is the addition of tests for
|
||||||
|
xattr and libattr support at configuration/compile time. The code I've added
|
||||||
|
is enclosed by '#ifdef USE_XATTR' statements so a test should be added that
|
||||||
|
sets this macro[5] if configure-time tests show that xattrs/libattr are working.
|
||||||
|
I don't know how to go about adding such tests though so I've simply included a
|
||||||
|
'#define USE_XATTR 1' statement to the top of the code. This should obviously
|
||||||
|
be fixed before general release.
|
||||||
|
|
||||||
|
This code has been tested on select Ubuntu Linux releases (natty, precise,
|
||||||
|
xenial, and jammy) using x86_64 Linux kernels 3.14.1, 4.18.3, and 5.15.0.
|
||||||
|
Tested filesystems are ext4 and squashfs.
|
||||||
|
|
||||||
|
As far as cross-platform availability goes this code is only known to work on
|
||||||
|
Linux[6][7]. That said, this code adds functionality that (as far as I'm aware)
|
||||||
|
isn't currently present in TDE on any of the platforms it runs on. In other
|
||||||
|
words, even if it only runs on Linux in its current state there is no loss of
|
||||||
|
functionality on any other platforms (just a lack of a gaining a feature). In
|
||||||
|
addition, determining the proper location to insert the library call was the
|
||||||
|
hard part with the actual implementation being quite straightforward. Adding
|
||||||
|
additional backends for other platforms should be pretty easy.
|
||||||
|
|
||||||
|
To test the code build and install it[8] then run the following from the
|
||||||
|
commandline in e.g. Konsole:
|
||||||
|
|
||||||
|
$ cd PATH_SUPPORTING_USER_XATTRS_AT_THE_FILESYSTEM_LEVEL
|
||||||
|
$ touch test
|
||||||
|
$ setfattr -n "user.AttributeName" -v "Attribute value" attr_test
|
||||||
|
$ kfmclient copy attr_test attr_test.copy
|
||||||
|
$ getfattr -d attr_test*
|
||||||
|
|
||||||
|
The final command should output (minus the indents):
|
||||||
|
|
||||||
|
# file: attr_test
|
||||||
|
user.AttributeName="Attribute value"
|
||||||
|
|
||||||
|
# file: attr_test.copy
|
||||||
|
user.AttributeName="Attribute value"
|
||||||
|
|
||||||
|
Enjoy!
|
||||||
|
|
||||||
|
|
||||||
|
- Alex Kent Hajnal (AKH) 2022-12-21
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[1] This includeds all attributes residing (on Linux) in the "user" namespace.
|
||||||
|
ACLs, etc. are not copied.
|
||||||
|
|
||||||
|
See the xattr(7) and e.g. the getfattr(1) manpages for more info.
|
||||||
|
|
||||||
|
[2] The underlying filesytems must, of course, have xattr support enabled.
|
||||||
|
This should be the case by default on modern systems that support xattrs.
|
||||||
|
|
||||||
|
[3] This is libattr1 and libattr1-dev on Ubuntu.
|
||||||
|
|
||||||
|
See http://savannah.nongnu.org/projects/attr for more info.
|
||||||
|
See also https://github.com/philips/attr
|
||||||
|
|
||||||
|
[4] The code that this patch is based on is licensed GPL v2 (or later).
|
||||||
|
|
||||||
|
[5] One has to use '#define USE_XATTR 1'; specifying '#define USE_XATTR'
|
||||||
|
doesn't enable the code (at least on my system).
|
||||||
|
|
||||||
|
[6] I'm not sure which non-Linux platforms (if any) libattr runs on.
|
||||||
|
|
||||||
|
|
||||||
|
[7] Another known issue is namespaces. Linux, FreeBSD, and NetBSD support
|
||||||
|
xattrs using the 'user' namespace. Solaris and OSX support user xattrs
|
||||||
|
but do not support namespaces.
|
||||||
|
(source: File::ExtAttr(3pm), personal testing)
|
||||||
|
|
||||||
|
[8] Instead of doing a full install one can simply copy the updated library:
|
||||||
|
|
||||||
|
cp -va "BUILD_DIR/tdeio/libtdeio.so.14.0.0" /opt/trinity/lib/ && ldconfig
|
Loading…
Reference in new issue