summaryrefslogtreecommitdiffstats
path: root/tdeio/tdeio/README.xattr
blob: 0c7d32d2143ba9bd0515f04df997069ce3983fa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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 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.  For ext2/3/4 filesytems the ext_attr 
feature must be enabled and the filesystem mounted with the user_xattr option.

As far as cross-platform availability goes this code is only known to work on 
Linux[5][6].  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[7] then run the following from the 
commandline in e.g. Konsole:

  $ cd PATH_SUPPORTING_USER_XATTRS_AT_THE_FILESYSTEM_LEVEL
  $ touch attr_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] I'm not sure which non-Linux platforms (if any) runs on.  It appears that 
    Cygwin and GNU/Hurd are also supported but this has not been verified.

[6] One potential issue is namespaces.  Linux, FreeBSD, and NetBSD support 
    xattrs using the 'user' namespace.  Solaris and OSX support user xattrs 
    but do not support namespaces.  When using libattr, attributes from all 
    namespaces are copied except those whose names match the patterns listed 
    in /etc/xattr.conf; other platforms may need special handling.
    (source: File::ExtAttr(3pm), personal testing)

[7] 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