Fix reading extended attributes values from metadata file.
commit489d586702839d3c5629823796226c8f1338a769
authorPrzemyslaw Pawelczyk <przemoc@gmail.com>
Sun, 6 Sep 2015 16:26:26 +0000 (6 18:26 +0200)
committerPrzemyslaw Pawelczyk <przemoc@gmail.com>
Sun, 6 Sep 2015 16:26:26 +0000 (6 18:26 +0200)
tree6605a36e5462d5527994b4c00f8f8aa8dea8f9dd
parent8bea7c6955d3c6b39cb28403be38e6f278113606
Fix reading extended attributes values from metadata file.

During implementation and tests of new dump action, I've noticed that
while non-textual values in extended attributes were properly stored in
.metadata file, retrieving them from it was simply broken, i.e.
anything beyond first null byte was zeroed.

Small quantum of solace is the fact that apparently metastore users
rarely use extended attributes or at least rarely with non-textual
values, because otherwise they would surely report such crucial bug.

Let's perform simple test to show the problem:

    $ mkdir -p ~/testxattr/ && cd ~/testxattr/ && touch test
    $ setfattr -n user.txt -v "tekst" test
    $ setfattr -n user.bin -v 0x020100ff00 test
    $ getfattr -d -e hex test
    # file: test
    user.bin=0x020100ff00
    user.txt=0x74656b7374

    $ metastore -s test
    $ OFFSET=$(($(grep -abo user.bin .metadata | sed 's/:.*//')+8+1+4))
    $ xxd -p -l5 -s $OFFSET .metadata
    020100ff00

So far everything seems fine, i.e. user.bin xattr is properly stored.

    $ metastore -c test
    ./test: xattr

Apparently on-disk test xattrs differ from those in metadata file,
even though they should not!
Let's apply those from metadata file and show how they look on-disk.

    $ metastore -a test
    ./test: changing metadata
    ./test: removing xattr user.bin
    ./test: adding xattr user.bin
    $ getfattr -d -e hex test
    # file: test
    user.bin=0x0201000000
    user.txt=0x74656b7374

Oh no! Extended attribute with non-textual data has been corrupted now.
But no more, because this commit fixes it!

As long as you haven't stored corrupted xattrs in metadata file, you can
still recover on-disk ones by applying them from metadata file using
fixed version of metastore.
utils.c