* [PATCH 0/4] Add FSLASTBLOCK tag and blkid with btrfs test
@ 2022-04-27 17:05 Andrey Albershteyn
2022-04-27 17:05 ` [PATCH 1/4] libblkid: add FSLASTBLOCK field interface showing area occupied by fs Andrey Albershteyn
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-27 17:05 UTC (permalink / raw)
To: util-linux; +Cc: Andrey Albershteyn
As discussed in [1] it would be useful to have FSLASTBLOCK tag
(size of the area occupied by filesystem). These few patches:
- add interface to set FSLASTBLOCK
- implement FSLASTBLOCK for ext2/3/4/jbd, xfs and btrfs
- add BTRFS image for blkid test
- update expected output for blkid tests to check FSLASTBLOCK
The BTRFS image is default 'mkfs.btrfs btrfs.img' (115M in size;
looks to be minimum required size)
[1]: https://bugzilla.redhat.com/show_bug.cgi?id=2064810
Andrey Albershteyn (4):
libblkid: add FSLASTBLOCK field interface showing area occupied by fs
libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs
blkid: add image for btrfs testing
blkid: add tests for FSLASTBLOCK tag
libblkid/samples/superblocks.c | 3 ++-
libblkid/src/blkid.h.in | 23 ++++++++++++-----------
libblkid/src/superblocks/btrfs.c | 5 +++++
libblkid/src/superblocks/ext.c | 5 +++++
libblkid/src/superblocks/superblocks.c | 13 +++++++++++++
libblkid/src/superblocks/superblocks.h | 1 +
libblkid/src/superblocks/xfs.c | 1 +
misc-utils/blkid.c | 2 +-
tests/expected/blkid/low-probe-btrfs | 8 ++++++++
tests/expected/blkid/low-probe-ext2 | 1 +
tests/expected/blkid/low-probe-ext3 | 1 +
tests/expected/blkid/low-probe-jbd | 1 +
tests/expected/blkid/low-probe-xfs | 1 +
tests/expected/blkid/low-probe-xfs-v5 | 1 +
tests/ts/blkid/images-fs/btrfs.img | Bin 0 -> 120586240 bytes
15 files changed, 53 insertions(+), 13 deletions(-)
create mode 100644 tests/expected/blkid/low-probe-btrfs
create mode 100644 tests/ts/blkid/images-fs/btrfs.img
--
2.27.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] libblkid: add FSLASTBLOCK field interface showing area occupied by fs
2022-04-27 17:05 [PATCH 0/4] Add FSLASTBLOCK tag and blkid with btrfs test Andrey Albershteyn
@ 2022-04-27 17:05 ` Andrey Albershteyn
2022-04-27 17:05 ` [PATCH 2/4] libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs Andrey Albershteyn
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-27 17:05 UTC (permalink / raw)
To: util-linux; +Cc: Andrey Albershteyn
Add interface to let filesystem set FSLASTBLOCK which is basically
total number of fsblocks (area occupied by fs). Enable that field in
the 'superblocks' sample.
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
libblkid/samples/superblocks.c | 3 ++-
libblkid/src/blkid.h.in | 23 ++++++++++++-----------
libblkid/src/superblocks/superblocks.c | 13 +++++++++++++
libblkid/src/superblocks/superblocks.h | 1 +
4 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/libblkid/samples/superblocks.c b/libblkid/samples/superblocks.c
index 38903ecee..b7f94ec14 100644
--- a/libblkid/samples/superblocks.c
+++ b/libblkid/samples/superblocks.c
@@ -44,7 +44,8 @@ int main(int argc, char *argv[])
BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
- BLKID_SUBLKS_MAGIC | BLKID_SUBLKS_FSSIZE);
+ BLKID_SUBLKS_MAGIC | BLKID_SUBLKS_FSSIZE |
+ BLKID_SUBLKS_FSLASTBLOCK);
rc = blkid_do_safeprobe(pr);
if (rc == -1)
diff --git a/libblkid/src/blkid.h.in b/libblkid/src/blkid.h.in
index ad4becf0a..56e64f9ab 100644
--- a/libblkid/src/blkid.h.in
+++ b/libblkid/src/blkid.h.in
@@ -271,17 +271,18 @@ extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage)
extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable)
__ul_attribute__((nonnull));
-#define BLKID_SUBLKS_LABEL (1 << 1) /* read LABEL from superblock */
-#define BLKID_SUBLKS_LABELRAW (1 << 2) /* read and define LABEL_RAW result value*/
-#define BLKID_SUBLKS_UUID (1 << 3) /* read UUID from superblock */
-#define BLKID_SUBLKS_UUIDRAW (1 << 4) /* read and define UUID_RAW result value */
-#define BLKID_SUBLKS_TYPE (1 << 5) /* define TYPE result value */
-#define BLKID_SUBLKS_SECTYPE (1 << 6) /* define compatible fs type (second type) */
-#define BLKID_SUBLKS_USAGE (1 << 7) /* define USAGE result value */
-#define BLKID_SUBLKS_VERSION (1 << 8) /* read FS type from superblock */
-#define BLKID_SUBLKS_MAGIC (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
-#define BLKID_SUBLKS_BADCSUM (1 << 10) /* allow a bad checksum */
-#define BLKID_SUBLKS_FSSIZE (1 << 11) /* read and define FSSIZE from superblock */
+#define BLKID_SUBLKS_LABEL (1 << 1) /* read LABEL from superblock */
+#define BLKID_SUBLKS_LABELRAW (1 << 2) /* read and define LABEL_RAW result value*/
+#define BLKID_SUBLKS_UUID (1 << 3) /* read UUID from superblock */
+#define BLKID_SUBLKS_UUIDRAW (1 << 4) /* read and define UUID_RAW result value */
+#define BLKID_SUBLKS_TYPE (1 << 5) /* define TYPE result value */
+#define BLKID_SUBLKS_SECTYPE (1 << 6) /* define compatible fs type (second type) */
+#define BLKID_SUBLKS_USAGE (1 << 7) /* define USAGE result value */
+#define BLKID_SUBLKS_VERSION (1 << 8) /* read FS type from superblock */
+#define BLKID_SUBLKS_MAGIC (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
+#define BLKID_SUBLKS_BADCSUM (1 << 10) /* allow a bad checksum */
+#define BLKID_SUBLKS_FSSIZE (1 << 11) /* read and define FSSIZE from superblock */
+#define BLKID_SUBLKS_FSLASTBLOCK (1 << 12) /* read and define FSLASTBLOCK from superblock */
#define BLKID_SUBLKS_DEFAULT (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index adf4ee025..5b899a830 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -68,6 +68,8 @@
*
* @FSSIZE: size of filesystem (implemented for XFS only)
*
+ * @FSLASTBLOCK: last fsblock/total number of fsblocks
+ *
* @SYSTEM_ID: ISO9660 system identifier
*
* @PUBLISHER_ID: ISO9660 publisher identifier
@@ -595,6 +597,17 @@ int blkid_probe_set_fssize(blkid_probe pr, uint64_t size)
return blkid_probe_sprintf_value(pr, "FSSIZE", "%" PRIu64, size);
}
+int blkid_probe_set_fslastblock(blkid_probe pr, uint64_t lastblock)
+{
+ struct blkid_chain *chn = blkid_probe_get_chain(pr);
+
+ if (!(chn->flags & BLKID_SUBLKS_FSLASTBLOCK))
+ return 0;
+
+ return blkid_probe_sprintf_value(pr, "FSLASTBLOCK", "%" PRIu64,
+ lastblock);
+}
+
int blkid_probe_set_id_label(blkid_probe pr, const char *name,
const unsigned char *data, size_t len)
{
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
index 67803679f..251e2e386 100644
--- a/libblkid/src/superblocks/superblocks.h
+++ b/libblkid/src/superblocks/superblocks.h
@@ -112,6 +112,7 @@ extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
int blkid_probe_set_block_size(blkid_probe pr, unsigned block_size);
int blkid_probe_set_fssize(blkid_probe pr, uint64_t size);
+int blkid_probe_set_fslastblock(blkid_probe pr, uint64_t lastblock);
extern int blkid_probe_is_bitlocker(blkid_probe pr);
extern int blkid_probe_is_ntfs(blkid_probe pr);
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs
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
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
3 siblings, 0 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-27 17:05 UTC (permalink / raw)
To: util-linux; +Cc: Andrey Albershteyn
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] blkid: add tests for FSLASTBLOCK tag
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 ` [PATCH 2/4] libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs Andrey Albershteyn
@ 2022-04-27 17:05 ` Andrey Albershteyn
2022-04-27 17:30 ` [PATCH 0/4] Add FSLASTBLOCK tag and blkid with btrfs test Andrey Albershteyn
3 siblings, 0 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-27 17:05 UTC (permalink / raw)
To: util-linux; +Cc: Andrey Albershteyn
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
misc-utils/blkid.c | 2 +-
tests/expected/blkid/low-probe-btrfs | 1 +
tests/expected/blkid/low-probe-ext2 | 1 +
tests/expected/blkid/low-probe-ext3 | 1 +
tests/expected/blkid/low-probe-jbd | 1 +
tests/expected/blkid/low-probe-xfs | 1 +
tests/expected/blkid/low-probe-xfs-v5 | 1 +
7 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 2edcd2b41..5a3e43624 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -922,7 +922,7 @@ int main(int argc, char **argv)
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
- BLKID_SUBLKS_FSSIZE);
+ BLKID_SUBLKS_FSSIZE | BLKID_SUBLKS_FSLASTBLOCK);
if (fltr_usage &&
diff --git a/tests/expected/blkid/low-probe-btrfs b/tests/expected/blkid/low-probe-btrfs
index 509fac378..48649389a 100644
--- a/tests/expected/blkid/low-probe-btrfs
+++ b/tests/expected/blkid/low-probe-btrfs
@@ -1,4 +1,5 @@
ID_FS_BLOCK_SIZE=4096
+ID_FS_FSLASTBLOCK=29440
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 087da97a4..e236c6e8a 100644
--- a/tests/expected/blkid/low-probe-ext2
+++ b/tests/expected/blkid/low-probe-ext2
@@ -1,4 +1,5 @@
ID_FS_BLOCK_SIZE=1024
+ID_FS_FSLASTBLOCK=100
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 8684884c1..164fefb7b 100644
--- a/tests/expected/blkid/low-probe-ext3
+++ b/tests/expected/blkid/low-probe-ext3
@@ -1,4 +1,5 @@
ID_FS_BLOCK_SIZE=1024
+ID_FS_FSLASTBLOCK=2048
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 c9f9f6b79..f5462a2a3 100644
--- a/tests/expected/blkid/low-probe-jbd
+++ b/tests/expected/blkid/low-probe-jbd
@@ -1,4 +1,5 @@
ID_FS_BLOCK_SIZE=1024
+ID_FS_FSLASTBLOCK=1024
ID_FS_LOGUUID=0d7a07df-7b06-4829-bce7-3b9c3ece570c
ID_FS_TYPE=jbd
ID_FS_USAGE=other
diff --git a/tests/expected/blkid/low-probe-xfs b/tests/expected/blkid/low-probe-xfs
index a91e92bcc..be9c4194a 100644
--- a/tests/expected/blkid/low-probe-xfs
+++ b/tests/expected/blkid/low-probe-xfs
@@ -1,4 +1,5 @@
ID_FS_BLOCK_SIZE=512
+ID_FS_FSLASTBLOCK=4096
ID_FS_FSSIZE=11862016
ID_FS_LABEL=test-xfs
ID_FS_LABEL_ENC=test-xfs
diff --git a/tests/expected/blkid/low-probe-xfs-v5 b/tests/expected/blkid/low-probe-xfs-v5
index 129b41f26..fd2cba933 100644
--- a/tests/expected/blkid/low-probe-xfs-v5
+++ b/tests/expected/blkid/low-probe-xfs-v5
@@ -1,4 +1,5 @@
ID_FS_BLOCK_SIZE=512
+ID_FS_FSLASTBLOCK=5120
ID_FS_FSSIZE=17469440
ID_FS_LABEL=test-xfs-v5
ID_FS_LABEL_ENC=test-xfs-v5
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/4] Add FSLASTBLOCK tag and blkid with btrfs test
2022-04-27 17:05 [PATCH 0/4] Add FSLASTBLOCK tag and blkid with btrfs test Andrey Albershteyn
` (2 preceding siblings ...)
2022-04-27 17:05 ` [PATCH 4/4] blkid: add tests for FSLASTBLOCK tag Andrey Albershteyn
@ 2022-04-27 17:30 ` Andrey Albershteyn
3 siblings, 0 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-27 17:30 UTC (permalink / raw)
To: util-linux
Oh well the 3rd patch haven't passed message length check (as it
contains binary image for BTRFS - too long message). I will create
GitHub pull request for that.
--
- Andrey
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-27 17:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/4] libblkid: add FSLASTBLOCK implementation for xfs, ext and btrfs Andrey Albershteyn
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
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).