[PATCH 1/4] filesystem: get device uuid in fs_get_blkid

Su Yue <[email protected]> Tue, 13 May 2025 14:14:24 +0800
Newsgroups dev.linux.lists.lvm-devel
Message-ID <[email protected]>
Add new field fs_info::uuid to record device uuid when calling
fs_get_blkid() for further use.

No functional change.

Signed-off-by: Su Yue <[email protected]>
---
 lib/device/dev-type.c   | 3 +++
 lib/device/filesystem.h | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index c4a366d0089d..08848ca0f216 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -999,6 +999,9 @@ int fs_get_blkid(const char *pathname, struct fs_info *fsi)
 	if (!blkid_probe_lookup_value(probe, "FSSIZE", &str, &len) && len)
 		fssize = strtoull(str, NULL, 0);
 
+	if (!blkid_probe_lookup_value(probe, "UUID", &str, &len) && len)
+		memcpy(fsi->uuid, str, UUID_LEN);
+
 	blkid_free_probe(probe);
 
 	if (fslastblock && fsblocksize)
diff --git a/lib/device/filesystem.h b/lib/device/filesystem.h
index 024c9974a19d..4ba6f0db99b7 100644
--- a/lib/device/filesystem.h
+++ b/lib/device/filesystem.h
@@ -19,10 +19,12 @@
 #include "lib/device/device.h"
 
 #define FSTYPE_MAX 16
+#define UUID_LEN 37
 
 struct fs_info {
 	char fstype[FSTYPE_MAX];
 	char mount_dir[PATH_MAX];
+	char uuid[UUID_LEN];
 	char fs_dev_path[PATH_MAX]; /* usually lv dev, can be crypt dev */
 	unsigned int fs_block_size_bytes; /* 512 or 4k */
 	uint64_t fs_last_byte; /* last byte on the device used by the fs */
-- 
2.48.1