[PATCH 03/12] common/encrypt: add btrfs to get_ciphertext_filename

Daniel Vacek <[email protected]> Fri, 24 Jul 2026 15:33:19 +0200
Newsgroups org.kernel.vger.linux-fscrypt,net.sourceforge.lists.linux-f2fs-devel,org.kernel.vger.fstests,org.kernel.vger.linux-btrfs,org.kernel.vger.linux-ext4,org.kernel.vger.linux-xfs
Message-ID <[email protected]>
From: Sweet Tea Dorminy <[email protected]>

Add the relevant call to get an encrypted filename from btrfs.

v1:
 * fix reading of the encrypted name
   - use simple sed substitutions and consume escapes using printf

Signed-off-by: Sweet Tea Dorminy <[email protected]>
Signed-off-by: Daniel Vacek <[email protected]>
---
 common/encrypt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/common/encrypt b/common/encrypt
index 29293ea4..8a0aaf1a 100644
--- a/common/encrypt
+++ b/common/encrypt
@@ -713,6 +713,20 @@ _get_ciphertext_filename()
 				print STDERR "Invalid base64-encoded string!\n";
 			}'
 		;;
+	btrfs)
+		# Extract the filename from the inode_ref object, similar to:
+		#
+		#	item 20 key (258 INODE_REF 257) itemoff 15121 itemsize 26
+		#		index 2 namelen 16 name: v\354\301\231\214\341+\335A\002\216\3405eFz
+		#
+		$BTRFS_UTIL_PROG inspect-internal dump-tree $device | \
+			sed -n "/ key ($inode INODE_REF $dir_inode) / { n
+				s/.*name: //
+				s/%/%%/g
+				s/\\\\ / /g
+				p; q }" | tr -d \\n | \
+			xargs -0 printf
+		;;
 	*)
 		_fail "_get_ciphertext_filename() isn't implemented on $FSTYP"
 		;;
@@ -767,6 +781,9 @@ _require_get_ciphertext_filename_support()
 			_notrun "dump.f2fs (f2fs-tools) is too old; doesn't support showing unambiguous on-disk filenames"
 		fi
 		;;
+	btrfs)
+		_require_command "$BTRFS_UTIL_PROG" btrfs
+		;;
 	*)
 		_notrun "_get_ciphertext_filename() isn't implemented on $FSTYP"
 		;;
-- 
2.53.0