From a17131aaf1458daf178dee7f745be2877016d1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Valdemar=20M=C3=B8rch?= Date: Thu, 27 Feb 2025 19:57:43 +0100 Subject: [PATCH] Fix BTRFS_SEND_C_CLONE It now aligns with https://github.com/torvalds/linux/blob/dd83757f6e686a2188997cb58b5975f744bb7786/fs/btrfs/send.c#L5394 This maybe fixes #22. Without this, I got this error: Traceback (most recent call last): File "/home/peter/work/btrfs-snapshots-diff/./btrfs-snapshots-diff.py", line 653, in main() File "/home/peter/work/btrfs-snapshots-diff/./btrfs-snapshots-diff.py", line 620, in main commands, paths = stream.decode(bogus=args.bogus) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/peter/work/btrfs-snapshots-diff/./btrfs-snapshots-diff.py", line 325, in decode offset2, path = self._tlv_get_string('BTRFS_SEND_A_PATH', offset) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/peter/work/btrfs-snapshots-diff/./btrfs-snapshots-diff.py", line 105, in _tlv_get_string raise ValueError(f'Unexpected attribute {self.send_attrs[attr]}') ValueError: Unexpected attribute BTRFS_SEND_A_FILE_OFFSET And according to btrfs/send.c BTRFS_SEND_A_PATH not supposed to be sent as the first element of a BTRFS_SEND_C_CLONE, but BTRFS_SEND_A_FILE_OFFSET is. The patch to create-example.sh causes the test to fail, but I cannot fix them because of #23. --- btrfs-snapshots-diff.py | 16 +++++++++------- create-example.sh | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/btrfs-snapshots-diff.py b/btrfs-snapshots-diff.py index 8cd1ce4..8ffdd29 100755 --- a/btrfs-snapshots-diff.py +++ b/btrfs-snapshots-diff.py @@ -322,22 +322,24 @@ def decode(self, bogus=True): ) elif command == 'BTRFS_SEND_C_CLONE': - offset2, path = self._tlv_get_string('BTRFS_SEND_A_PATH', offset) offset2, file_offset = self._tlv_get_u64( - 'BTRFS_SEND_A_FILE_OFFSET', offset2 + 'BTRFS_SEND_A_FILE_OFFSET', offset ) offset2, clone_len = self._tlv_get_u64( 'BTRFS_SEND_A_CLONE_LEN', offset2 ) + offset2, path = self._tlv_get_string( + 'BTRFS_SEND_A_PATH', offset2 + ) offset2, clone_uuid = self._tlv_get_uuid( 'BTRFS_SEND_A_CLONE_UUID', offset2 ) - offset2, clone_transid = self._tlv_get_u64( - 'BTRFS_SEND_A_CLONE_TRANSID', offset2 + offset2, clone_ctransid = self._tlv_get_u64( + 'BTRFS_SEND_A_CLONE_CTRANSID', offset2 ) offset2, clone_path = self._tlv_get_string( - 'BTRFS_SEND_A_CLONE_PATH', offset - ) # BTRFS_SEND_A_CLONE8PATH + 'BTRFS_SEND_A_CLONE_PATH', offset2 + ) offset2, clone_offset = self._tlv_get_u64( 'BTRFS_SEND_A_CLONE_OFFSET', offset2 ) @@ -349,7 +351,7 @@ def decode(self, bogus=True): 'file_offset': file_offset, 'clone_len': clone_len, 'clone_uuid': clone_uuid, - 'clone_transid': clone_transid, + 'clone_transid': clone_ctransid, 'clone_path': clone_path, 'clone_offset': clone_offset, } diff --git a/create-example.sh b/create-example.sh index 8b6d03f..f50274a 100755 --- a/create-example.sh +++ b/create-example.sh @@ -32,6 +32,8 @@ mkfifo fifo ln file hardlink ln -s file symlink echo 'Hello Btrfs' > 'xxx;yyy;zzz' +dd if=/dev/zero of=source bs=1024 count=1024 > /dev/null 2>&1 +cp --reflink=always source bbbb mv file file2 cd ..