]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: add FSSIZE implementation for btrfs and ext
authorAndrey Albershteyn <aalbersh@redhat.com>
Fri, 27 May 2022 11:57:14 +0000 (13:57 +0200)
committerAndrey Albershteyn <aalbersh@redhat.com>
Thu, 2 Jun 2022 09:31:08 +0000 (11:31 +0200)
The implementation does not take into account complete metadata
overhead. The BTRFS one doesn't consider redundant data in RAID
configuration. The ext one doesn't take into account file system
overhead.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
libblkid/src/superblocks/btrfs.c
libblkid/src/superblocks/ext.c
libblkid/src/superblocks/superblocks.c
tests/expected/blkid/low-probe-btrfs
tests/expected/blkid/low-probe-ext2
tests/expected/blkid/low-probe-ext3
tests/expected/blkid/low-probe-jbd

index 34fe0f07cce0deed1174d70a84f4c146c84b6a1c..f286c0e64d240b6cd7e022aced14d87d6d8afb2f 100644 (file)
@@ -241,6 +241,12 @@ static int probe_btrfs(blkid_probe pr, const struct blkid_idmag *mag)
                __builtin_clz(le32_to_cpu(bfs->sectorsize));
        blkid_probe_set_fslastblock(pr,
                        le64_to_cpu(bfs->total_bytes) >> sectorsize_log);
+       // The size is calculated without the RAID factor. It could not be
+       // obtained from the superblock as it is property of device tree.
+       // Without the factor we would show fs size with the redundant data. The
+       // acquisition of the factor will require additional parsing of btrfs
+       // tree.
+       blkid_probe_set_fssize(pr, le64_to_cpu(bfs->total_bytes));
 
        return 0;
 }
index cbbe8eb969d3f31f0e6ce12f92986c2019675324..96bb31e49abfb1c9e37ab615e6588ab4484aa735 100644 (file)
@@ -189,15 +189,23 @@ static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
                le32_to_cpu(es->s_rev_level),
                le16_to_cpu(es->s_minor_rev_level));
 
+       uint32_t block_size = 1024U << le32_to_cpu(es->s_log_block_size);
        if (le32_to_cpu(es->s_log_block_size) < 32){
-               blkid_probe_set_fsblocksize(pr, 1024U << le32_to_cpu(es->s_log_block_size));
-               blkid_probe_set_block_size(pr, 1024U << le32_to_cpu(es->s_log_block_size));
+               blkid_probe_set_fsblocksize(pr, block_size);
+               blkid_probe_set_block_size(pr, 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);
+       // The total number of blocks is taken without substraction of overhead
+       // (journal, metadata). The ext4 has non-trivial overhead calculation
+       // viz. ext4_calculate_overhead(). Thefore, the FSSIZE would show number
+       // slightly higher than the real value (for example, calculated via
+       // statfs()).
+       uint64_t fssize = (uint64_t)block_size*le32_to_cpu(es->s_blocks_count);
+       blkid_probe_set_fssize(pr, fssize);
 }
 
 
index 9c32bc9d527aea91135df0206ea11aab76910755..06b191a2f446cd28d5c9d69741b392e5d907ccd1 100644 (file)
@@ -66,7 +66,7 @@
  *
  * @SBMAGIC_OFFSET: offset of SBMAGIC
  *
- * @FSSIZE: size of filesystem (implemented for XFS only)
+ * @FSSIZE: size of filesystem (implemented for XFS/BTRFS/Ext only)
  *
  * @FSLASTBLOCK: last fsblock/total number of fsblocks
  *
index a626bc1f6e6629ecb9cb43aa02fabc77d0024039..c99088d221838160a1f5e87e32ef12c78ef2983e 100644 (file)
@@ -1,6 +1,7 @@
 ID_FS_BLOCK_SIZE=4096
 ID_FS_FSBLOCKSIZE=4096
 ID_FS_FSLASTBLOCK=29440
+ID_FS_FSSIZE=120586240
 ID_FS_TYPE=btrfs
 ID_FS_USAGE=filesystem
 ID_FS_UUID=d4a78b72-55e4-4811-86a6-09af936d43f9
index fa284a949e95a28fdf2d1523378ce2153f6700e4..d60d2270dcb30ebac0fd4d6089f7e68d564423d0 100644 (file)
@@ -1,6 +1,7 @@
 ID_FS_BLOCK_SIZE=1024
 ID_FS_FSBLOCKSIZE=1024
 ID_FS_FSLASTBLOCK=100
+ID_FS_FSSIZE=102400
 ID_FS_LABEL=test-ext2
 ID_FS_LABEL_ENC=test-ext2
 ID_FS_TYPE=ext2
index 422d4fef3d3d23154811bf9ea95a500f5b7fe240..6a3a61b81fca0e610bba1ee881de3390bf821ccd 100644 (file)
@@ -1,6 +1,7 @@
 ID_FS_BLOCK_SIZE=1024
 ID_FS_FSBLOCKSIZE=1024
 ID_FS_FSLASTBLOCK=2048
+ID_FS_FSSIZE=2097152
 ID_FS_LABEL=test-ext3
 ID_FS_LABEL_ENC=test-ext3
 ID_FS_SEC_TYPE=ext2
index 36c7d4062e3c1d57acc576bc9e29d10724a769b4..def505d7f3a24b3839ac89cb4b871879f229c75b 100644 (file)
@@ -1,6 +1,7 @@
 ID_FS_BLOCK_SIZE=1024
 ID_FS_FSBLOCKSIZE=1024
 ID_FS_FSLASTBLOCK=1024
+ID_FS_FSSIZE=1048576
 ID_FS_LOGUUID=0d7a07df-7b06-4829-bce7-3b9c3ece570c
 ID_FS_TYPE=jbd
 ID_FS_USAGE=other