]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs
authorAndrey Albershteyn <aalbersh@redhat.com>
Wed, 27 Apr 2022 12:46:33 +0000 (14:46 +0200)
committerAndrey Albershteyn <aalbersh@redhat.com>
Mon, 2 May 2022 10:11:17 +0000 (12:11 +0200)
Implementation of FSLASTBLOCK for most common filesystems. Most of
the fs store total number of reserved blocks in superblock.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
libblkid/src/superblocks/btrfs.c
libblkid/src/superblocks/ext.c
libblkid/src/superblocks/xfs.c

index 78d767d260d7ddca75472da7f803ca2630578034..0ead1f5916c3428e6f10839095e572f8b6d3aab4 100644 (file)
@@ -236,6 +236,11 @@ static int probe_btrfs(blkid_probe pr, const struct blkid_idmag *mag)
        blkid_probe_set_uuid_as(pr, bfs->dev_item.uuid, "UUID_SUB");
        blkid_probe_set_block_size(pr, le32_to_cpu(bfs->sectorsize));
 
+       uint32_t sectorsize_log = 31 -
+               __builtin_clz(le32_to_cpu(bfs->sectorsize));
+       blkid_probe_set_fslastblock(pr,
+                       le64_to_cpu(bfs->total_bytes) >> sectorsize_log);
+
        return 0;
 }
 
index 3870522fadf1ab05e472d641a5f88f4264c6c0af..0b9023734750caf3850ee27a937314c7bcf35216 100644 (file)
@@ -164,10 +164,11 @@ static struct ext2_super_block *ext_get_super(
 static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
+       uint32_t s_feature_incompat = le32_to_cpu(es->s_feature_incompat);
 
        DBG(PROBE, ul_debug("ext2_sb.compat = %08X:%08X:%08X",
                   le32_to_cpu(es->s_feature_compat),
-                  le32_to_cpu(es->s_feature_incompat),
+                  s_feature_incompat,
                   le32_to_cpu(es->s_feature_ro_compat)));
 
        if (*es->s_volume_name != '\0')
@@ -179,7 +180,7 @@ static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
                blkid_probe_set_uuid_as(pr, es->s_journal_uuid, "EXT_JOURNAL");
 
        if (ver != 2 && (chn->flags & BLKID_SUBLKS_SECTYPE) &&
-           ((le32_to_cpu(es->s_feature_incompat) & EXT2_FEATURE_INCOMPAT_UNSUPPORTED) == 0))
+           ((s_feature_incompat & EXT2_FEATURE_INCOMPAT_UNSUPPORTED) == 0))
                blkid_probe_set_value(pr, "SEC_TYPE",
                                (unsigned char *) "ext2",
                                sizeof("ext2"));
@@ -190,6 +191,11 @@ static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
 
        if (le32_to_cpu(es->s_log_block_size) < 32)
                blkid_probe_set_block_size(pr, 1024U << le32_to_cpu(es->s_log_block_size));
+
+       uint64_t fslastblock = le32_to_cpu(es->s_blocks_count) |
+               ((s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ?
+               (uint64_t) le32_to_cpu(es->s_blocks_count_hi) << 32 : 0);
+       blkid_probe_set_fslastblock(pr, fslastblock);
 }
 
 
index 444050f55bf4c6405cfa47f12f73b86e81773540..1f2e92cac52b6f5ced884b9977c97a5294290137 100644 (file)
@@ -183,6 +183,7 @@ static int probe_xfs(blkid_probe pr, const struct blkid_idmag *mag)
                                sizeof(xs->sb_fname));
        blkid_probe_set_uuid(pr, xs->sb_uuid);
        blkid_probe_set_fssize(pr, xfs_fssize(xs));
+       blkid_probe_set_fslastblock(pr, be64_to_cpu(xs->sb_dblocks));
        blkid_probe_set_block_size(pr, be16_to_cpu(xs->sb_sectsize));
        return 0;
 }