Blame 0024-libblkid-add-FSLASTBLOCK-field-interface-showing-are.patch

Karel Zak 18b0e4
From fb9ea75a8a69b06eb6a4039b841ce3ccabb76775 Mon Sep 17 00:00:00 2001
Karel Zak 18b0e4
From: Andrey Albershteyn <aalbersh@redhat.com>
Karel Zak 18b0e4
Date: Wed, 27 Apr 2022 13:24:56 +0200
Karel Zak 18b0e4
Subject: libblkid: add FSLASTBLOCK field interface showing area occupied by fs
Karel Zak 18b0e4
Karel Zak 18b0e4
Add interface to let filesystem set FSLASTBLOCK which is basically
Karel Zak 18b0e4
total number of fsblocks (area occupied by fs). Enable that field in
Karel Zak 18b0e4
the 'superblocks' sample.
Karel Zak 18b0e4
Karel Zak 18b0e4
Upstream: http://github.com/util-linux/util-linux/commit/b7cb26ec3
Karel Zak 18b0e4
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2064810
Karel Zak 18b0e4
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
Karel Zak 18b0e4
---
Karel Zak 18b0e4
 libblkid/samples/superblocks.c         |  3 ++-
Karel Zak 18b0e4
 libblkid/src/blkid.h.in                | 23 ++++++++++++-----------
Karel Zak 18b0e4
 libblkid/src/superblocks/superblocks.c | 13 +++++++++++++
Karel Zak 18b0e4
 libblkid/src/superblocks/superblocks.h |  1 +
Karel Zak 18b0e4
 4 files changed, 28 insertions(+), 12 deletions(-)
Karel Zak 18b0e4
Karel Zak 18b0e4
diff --git a/libblkid/samples/superblocks.c b/libblkid/samples/superblocks.c
Karel Zak 18b0e4
index 38903ecee..b7f94ec14 100644
Karel Zak 18b0e4
--- a/libblkid/samples/superblocks.c
Karel Zak 18b0e4
+++ b/libblkid/samples/superblocks.c
Karel Zak 18b0e4
@@ -44,7 +44,8 @@ int main(int argc, char *argv[])
Karel Zak 18b0e4
 			BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
Karel Zak 18b0e4
 			BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
Karel Zak 18b0e4
 			BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
Karel Zak 18b0e4
-			BLKID_SUBLKS_MAGIC | BLKID_SUBLKS_FSSIZE);
Karel Zak 18b0e4
+			BLKID_SUBLKS_MAGIC | BLKID_SUBLKS_FSSIZE |
Karel Zak 18b0e4
+			BLKID_SUBLKS_FSLASTBLOCK);
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 	rc = blkid_do_safeprobe(pr);
Karel Zak 18b0e4
 	if (rc == -1)
Karel Zak 18b0e4
diff --git a/libblkid/src/blkid.h.in b/libblkid/src/blkid.h.in
Karel Zak 18b0e4
index ad4becf0a..56e64f9ab 100644
Karel Zak 18b0e4
--- a/libblkid/src/blkid.h.in
Karel Zak 18b0e4
+++ b/libblkid/src/blkid.h.in
Karel Zak 18b0e4
@@ -271,17 +271,18 @@ extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage)
Karel Zak 18b0e4
 extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable)
Karel Zak 18b0e4
 			__ul_attribute__((nonnull));
Karel Zak 18b0e4
 
Karel Zak 18b0e4
-#define BLKID_SUBLKS_LABEL	(1 << 1) /* read LABEL from superblock */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_LABELRAW	(1 << 2) /* read and define LABEL_RAW result value*/
Karel Zak 18b0e4
-#define BLKID_SUBLKS_UUID	(1 << 3) /* read UUID from superblock */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_UUIDRAW	(1 << 4) /* read and define UUID_RAW result value */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_TYPE	(1 << 5) /* define TYPE result value */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_SECTYPE	(1 << 6) /* define compatible fs type (second type) */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_USAGE	(1 << 7) /* define USAGE result value */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_VERSION	(1 << 8) /* read FS type from superblock */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_MAGIC	(1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_BADCSUM	(1 << 10) /* allow a bad checksum */
Karel Zak 18b0e4
-#define BLKID_SUBLKS_FSSIZE	(1 << 11) /* read and define FSSIZE from superblock */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_LABEL		(1 << 1) /* read LABEL from superblock */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_LABELRAW		(1 << 2) /* read and define LABEL_RAW result value*/
Karel Zak 18b0e4
+#define BLKID_SUBLKS_UUID		(1 << 3) /* read UUID from superblock */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_UUIDRAW		(1 << 4) /* read and define UUID_RAW result value */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_TYPE		(1 << 5) /* define TYPE result value */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_SECTYPE		(1 << 6) /* define compatible fs type (second type) */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_USAGE		(1 << 7) /* define USAGE result value */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_VERSION		(1 << 8) /* read FS type from superblock */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_MAGIC		(1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_BADCSUM		(1 << 10) /* allow a bad checksum */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_FSSIZE		(1 << 11) /* read and define FSSIZE from superblock */
Karel Zak 18b0e4
+#define BLKID_SUBLKS_FSLASTBLOCK	(1 << 12) /* read and define FSLASTBLOCK from superblock */
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 #define BLKID_SUBLKS_DEFAULT	(BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
Karel Zak 18b0e4
 				 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
Karel Zak 18b0e4
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
Karel Zak 18b0e4
index adf4ee025..5b899a830 100644
Karel Zak 18b0e4
--- a/libblkid/src/superblocks/superblocks.c
Karel Zak 18b0e4
+++ b/libblkid/src/superblocks/superblocks.c
Karel Zak 18b0e4
@@ -68,6 +68,8 @@
Karel Zak 18b0e4
  *
Karel Zak 18b0e4
  * @FSSIZE: size of filesystem (implemented for XFS only)
Karel Zak 18b0e4
  *
Karel Zak 18b0e4
+ * @FSLASTBLOCK: last fsblock/total number of fsblocks
Karel Zak 18b0e4
+ *
Karel Zak 18b0e4
  * @SYSTEM_ID: ISO9660 system identifier
Karel Zak 18b0e4
  *
Karel Zak 18b0e4
  * @PUBLISHER_ID: ISO9660 publisher identifier
Karel Zak 18b0e4
@@ -595,6 +597,17 @@ int blkid_probe_set_fssize(blkid_probe pr, uint64_t size)
Karel Zak 18b0e4
 	return blkid_probe_sprintf_value(pr, "FSSIZE", "%" PRIu64, size);
Karel Zak 18b0e4
 }
Karel Zak 18b0e4
 
Karel Zak 18b0e4
+int blkid_probe_set_fslastblock(blkid_probe pr, uint64_t lastblock)
Karel Zak 18b0e4
+{
Karel Zak 18b0e4
+	struct blkid_chain *chn = blkid_probe_get_chain(pr);
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+	if (!(chn->flags & BLKID_SUBLKS_FSLASTBLOCK))
Karel Zak 18b0e4
+		return 0;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+	return blkid_probe_sprintf_value(pr, "FSLASTBLOCK", "%" PRIu64,
Karel Zak 18b0e4
+			lastblock);
Karel Zak 18b0e4
+}
Karel Zak 18b0e4
+
Karel Zak 18b0e4
 int blkid_probe_set_id_label(blkid_probe pr, const char *name,
Karel Zak 18b0e4
 			     const unsigned char *data, size_t len)
Karel Zak 18b0e4
 {
Karel Zak 18b0e4
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
Karel Zak 18b0e4
index 67803679f..251e2e386 100644
Karel Zak 18b0e4
--- a/libblkid/src/superblocks/superblocks.h
Karel Zak 18b0e4
+++ b/libblkid/src/superblocks/superblocks.h
Karel Zak 18b0e4
@@ -112,6 +112,7 @@ extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 int blkid_probe_set_block_size(blkid_probe pr, unsigned block_size);
Karel Zak 18b0e4
 int blkid_probe_set_fssize(blkid_probe pr, uint64_t size);
Karel Zak 18b0e4
+int blkid_probe_set_fslastblock(blkid_probe pr, uint64_t lastblock);
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 extern int blkid_probe_is_bitlocker(blkid_probe pr);
Karel Zak 18b0e4
 extern int blkid_probe_is_ntfs(blkid_probe pr);
Karel Zak 18b0e4
-- 
Karel Zak 18b0e4
2.36.1
Karel Zak 18b0e4