From: Andrey Albershteyn Date: Fri, 27 May 2022 11:57:14 +0000 (+0200) Subject: libblkid: add FSSIZE implementation for btrfs and ext X-Git-Tag: v2.39-rc1~639^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d9d9a709ce6f22d4fbd09986d1372b3c06374e47;p=thirdparty%2Futil-linux.git libblkid: add FSSIZE implementation for btrfs and ext 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 --- diff --git a/libblkid/src/superblocks/btrfs.c b/libblkid/src/superblocks/btrfs.c index 34fe0f07cc..f286c0e64d 100644 --- a/libblkid/src/superblocks/btrfs.c +++ b/libblkid/src/superblocks/btrfs.c @@ -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; } diff --git a/libblkid/src/superblocks/ext.c b/libblkid/src/superblocks/ext.c index cbbe8eb969..96bb31e49a 100644 --- a/libblkid/src/superblocks/ext.c +++ b/libblkid/src/superblocks/ext.c @@ -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); } diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c index 9c32bc9d52..06b191a2f4 100644 --- a/libblkid/src/superblocks/superblocks.c +++ b/libblkid/src/superblocks/superblocks.c @@ -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 * diff --git a/tests/expected/blkid/low-probe-btrfs b/tests/expected/blkid/low-probe-btrfs index a626bc1f6e..c99088d221 100644 --- a/tests/expected/blkid/low-probe-btrfs +++ b/tests/expected/blkid/low-probe-btrfs @@ -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 diff --git a/tests/expected/blkid/low-probe-ext2 b/tests/expected/blkid/low-probe-ext2 index fa284a949e..d60d2270dc 100644 --- a/tests/expected/blkid/low-probe-ext2 +++ b/tests/expected/blkid/low-probe-ext2 @@ -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 diff --git a/tests/expected/blkid/low-probe-ext3 b/tests/expected/blkid/low-probe-ext3 index 422d4fef3d..6a3a61b81f 100644 --- a/tests/expected/blkid/low-probe-ext3 +++ b/tests/expected/blkid/low-probe-ext3 @@ -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 diff --git a/tests/expected/blkid/low-probe-jbd b/tests/expected/blkid/low-probe-jbd index 36c7d4062e..def505d7f3 100644 --- a/tests/expected/blkid/low-probe-jbd +++ b/tests/expected/blkid/low-probe-jbd @@ -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