]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: add FSLASTBLOCK field interface showing area occupied by fs
authorAndrey Albershteyn <aalbersh@redhat.com>
Wed, 27 Apr 2022 11:24:56 +0000 (13:24 +0200)
committerAndrey Albershteyn <aalbersh@redhat.com>
Wed, 27 Apr 2022 17:00:06 +0000 (19:00 +0200)
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
libblkid/src/blkid.h.in
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h

index 38903ecee21bc5099b17dc2bd0a8d54b68ca8e4f..b7f94ec1431dd2bc7f7aabbe4d89431d466841d5 100644 (file)
@@ -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)
index ad4becf0ad3be5c4071d8a9c1587286f1b126fa9..56e64f9aba64b02199e48438b5e3520dcc845564 100644 (file)
@@ -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)
index adf4ee025a915c67ae095d97d848f290ecaa1d68..5b899a8309165e89cd49ec444e5c431c30d42db5 100644 (file)
@@ -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)
 {
index 67803679f3c6875656e5bdb14d05e67fc1d24c54..251e2e3861821a7d3aaf64453972770550a8b03a 100644 (file)
@@ -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);