From: Andrey Albershteyn <aalbersh@redhat.com>
To: util-linux@vger.kernel.org
Cc: Andrey Albershteyn <aalbersh@redhat.com>
Subject: [PATCH 2/4] libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs
Date: Wed, 27 Apr 2022 19:05:12 +0200 [thread overview]
Message-ID: <20220427170514.317720-3-aalbersh@redhat.com> (raw)
In-Reply-To: <20220427170514.317720-1-aalbersh@redhat.com>
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 | 5 +++++
libblkid/src/superblocks/ext.c | 5 +++++
libblkid/src/superblocks/xfs.c | 1 +
3 files changed, 11 insertions(+)
diff --git a/libblkid/src/superblocks/btrfs.c b/libblkid/src/superblocks/btrfs.c
index 78d767d26..0ead1f591 100644
--- a/libblkid/src/superblocks/btrfs.c
+++ b/libblkid/src/superblocks/btrfs.c
@@ -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;
}
diff --git a/libblkid/src/superblocks/ext.c b/libblkid/src/superblocks/ext.c
index 3870522fa..105bdfcf3 100644
--- a/libblkid/src/superblocks/ext.c
+++ b/libblkid/src/superblocks/ext.c
@@ -190,6 +190,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 = es->s_blocks_count |
+ ((es->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ?
+ (uint64_t) es->s_blocks_count_hi << 32 : 0);
+ blkid_probe_set_fslastblock(pr, fslastblock);
}
diff --git a/libblkid/src/superblocks/xfs.c b/libblkid/src/superblocks/xfs.c
index 444050f55..1f2e92cac 100644
--- a/libblkid/src/superblocks/xfs.c
+++ b/libblkid/src/superblocks/xfs.c
@@ -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;
}
--
2.27.0
next prev parent reply other threads:[~2022-04-27 17:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-27 17:05 [PATCH 0/4] Add FSLASTBLOCK tag and blkid with btrfs test Andrey Albershteyn
2022-04-27 17:05 ` [PATCH 1/4] libblkid: add FSLASTBLOCK field interface showing area occupied by fs Andrey Albershteyn
2022-04-27 17:05 ` Andrey Albershteyn [this message]
2022-04-27 17:05 ` [PATCH 4/4] blkid: add tests for FSLASTBLOCK tag Andrey Albershteyn
2022-04-27 17:30 ` [PATCH 0/4] Add FSLASTBLOCK tag and blkid with btrfs test Andrey Albershteyn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220427170514.317720-3-aalbersh@redhat.com \
--to=aalbersh@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).