dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame 0025-libblkid-add-FSLASTBLOCK-implementation-for-xfs-ext-.patch

Karel Zak 18b0e4
From 9c7f3317fc66fe971a331dd71e76aff7ae091ab2 Mon Sep 17 00:00:00 2001
Karel Zak 18b0e4
From: Andrey Albershteyn <aalbersh@redhat.com>
Karel Zak 18b0e4
Date: Wed, 27 Apr 2022 14:46:33 +0200
Karel Zak 18b0e4
Subject: libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs
Karel Zak 18b0e4
Karel Zak 18b0e4
Implementation of FSLASTBLOCK for most common filesystems. Most of
Karel Zak 18b0e4
the fs store total number of reserved blocks in superblock.
Karel Zak 18b0e4
Karel Zak 18b0e4
Upstream: http://github.com/util-linux/util-linux/commit/5f995b3f1
Karel Zak 18b0e4
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2064810
Karel Zak 18b0e4
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
Karel Zak 18b0e4
---
Karel Zak 18b0e4
 libblkid/src/superblocks/btrfs.c |  5 +++++
Karel Zak 18b0e4
 libblkid/src/superblocks/ext.c   | 10 ++++++++--
Karel Zak 18b0e4
 libblkid/src/superblocks/xfs.c   |  1 +
Karel Zak 18b0e4
 3 files changed, 14 insertions(+), 2 deletions(-)
Karel Zak 18b0e4
Karel Zak 18b0e4
diff --git a/libblkid/src/superblocks/btrfs.c b/libblkid/src/superblocks/btrfs.c
Karel Zak 18b0e4
index f0fde700d..9708f2e28 100644
Karel Zak 18b0e4
--- a/libblkid/src/superblocks/btrfs.c
Karel Zak 18b0e4
+++ b/libblkid/src/superblocks/btrfs.c
Karel Zak 18b0e4
@@ -76,6 +76,11 @@ static int probe_btrfs(blkid_probe pr, const struct blkid_idmag *mag)
Karel Zak 18b0e4
 	blkid_probe_set_uuid_as(pr, bfs->dev_item.uuid, "UUID_SUB");
Karel Zak 18b0e4
 	blkid_probe_set_block_size(pr, le32_to_cpu(bfs->sectorsize));
Karel Zak 18b0e4
 
Karel Zak 18b0e4
+	uint32_t sectorsize_log = 31 -
Karel Zak 18b0e4
+		__builtin_clz(le32_to_cpu(bfs->sectorsize));
Karel Zak 18b0e4
+	blkid_probe_set_fslastblock(pr,
Karel Zak 18b0e4
+			le64_to_cpu(bfs->total_bytes) >> sectorsize_log);
Karel Zak 18b0e4
+
Karel Zak 18b0e4
 	return 0;
Karel Zak 18b0e4
 }
Karel Zak 18b0e4
 
Karel Zak 18b0e4
diff --git a/libblkid/src/superblocks/ext.c b/libblkid/src/superblocks/ext.c
Karel Zak 18b0e4
index 3870522fa..0b9023734 100644
Karel Zak 18b0e4
--- a/libblkid/src/superblocks/ext.c
Karel Zak 18b0e4
+++ b/libblkid/src/superblocks/ext.c
Karel Zak 18b0e4
@@ -164,10 +164,11 @@ static struct ext2_super_block *ext_get_super(
Karel Zak 18b0e4
 static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
Karel Zak 18b0e4
 {
Karel Zak 18b0e4
 	struct blkid_chain *chn = blkid_probe_get_chain(pr);
Karel Zak 18b0e4
+	uint32_t s_feature_incompat = le32_to_cpu(es->s_feature_incompat);
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 	DBG(PROBE, ul_debug("ext2_sb.compat = %08X:%08X:%08X",
Karel Zak 18b0e4
 		   le32_to_cpu(es->s_feature_compat),
Karel Zak 18b0e4
-		   le32_to_cpu(es->s_feature_incompat),
Karel Zak 18b0e4
+		   s_feature_incompat,
Karel Zak 18b0e4
 		   le32_to_cpu(es->s_feature_ro_compat)));
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 	if (*es->s_volume_name != '\0')
Karel Zak 18b0e4
@@ -179,7 +180,7 @@ static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
Karel Zak 18b0e4
 		blkid_probe_set_uuid_as(pr, es->s_journal_uuid, "EXT_JOURNAL");
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 	if (ver != 2 && (chn->flags & BLKID_SUBLKS_SECTYPE) &&
Karel Zak 18b0e4
-	    ((le32_to_cpu(es->s_feature_incompat) & EXT2_FEATURE_INCOMPAT_UNSUPPORTED) == 0))
Karel Zak 18b0e4
+	    ((s_feature_incompat & EXT2_FEATURE_INCOMPAT_UNSUPPORTED) == 0))
Karel Zak 18b0e4
 		blkid_probe_set_value(pr, "SEC_TYPE",
Karel Zak 18b0e4
 				(unsigned char *) "ext2",
Karel Zak 18b0e4
 				sizeof("ext2"));
Karel Zak 18b0e4
@@ -190,6 +191,11 @@ static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 	if (le32_to_cpu(es->s_log_block_size) < 32)
Karel Zak 18b0e4
 		blkid_probe_set_block_size(pr, 1024U << le32_to_cpu(es->s_log_block_size));
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+	uint64_t fslastblock = le32_to_cpu(es->s_blocks_count) |
Karel Zak 18b0e4
+		((s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ?
Karel Zak 18b0e4
+		(uint64_t) le32_to_cpu(es->s_blocks_count_hi) << 32 : 0);
Karel Zak 18b0e4
+	blkid_probe_set_fslastblock(pr, fslastblock);
Karel Zak 18b0e4
 }
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 
Karel Zak 18b0e4
diff --git a/libblkid/src/superblocks/xfs.c b/libblkid/src/superblocks/xfs.c
Karel Zak 18b0e4
index 444050f55..1f2e92cac 100644
Karel Zak 18b0e4
--- a/libblkid/src/superblocks/xfs.c
Karel Zak 18b0e4
+++ b/libblkid/src/superblocks/xfs.c
Karel Zak 18b0e4
@@ -183,6 +183,7 @@ static int probe_xfs(blkid_probe pr, const struct blkid_idmag *mag)
Karel Zak 18b0e4
 				sizeof(xs->sb_fname));
Karel Zak 18b0e4
 	blkid_probe_set_uuid(pr, xs->sb_uuid);
Karel Zak 18b0e4
 	blkid_probe_set_fssize(pr, xfs_fssize(xs));
Karel Zak 18b0e4
+	blkid_probe_set_fslastblock(pr, be64_to_cpu(xs->sb_dblocks));
Karel Zak 18b0e4
 	blkid_probe_set_block_size(pr, be16_to_cpu(xs->sb_sectsize));
Karel Zak 18b0e4
 	return 0;
Karel Zak 18b0e4
 }
Karel Zak 18b0e4
-- 
Karel Zak 18b0e4
2.36.1
Karel Zak 18b0e4