]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: Add support for zonefs
authorDamien Le Moal <damien.lemoal@wdc.com>
Fri, 20 Mar 2020 04:55:43 +0000 (13:55 +0900)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Mar 2020 10:27:16 +0000 (11:27 +0100)
The zonefs filesystem was added to upstream linux kernel 5.6. This
patch add support for probing zonefs formatted zoned block devices so
that other file system formatting tool can detect its presence on a
device.

[kzak@redhat.com: - use standard integer types]

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/Makemodule.am
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h
libblkid/src/superblocks/zonefs.c [new file with mode: 0644]

index c5d9426b198f869916334180f21abcf4bbe234a5..394c2ed4362c932ec0ec3c4e15c0c2d4d2461950 100644 (file)
@@ -101,6 +101,7 @@ libblkid_la_SOURCES = \
        libblkid/src/superblocks/vxfs.c \
        libblkid/src/superblocks/xfs.c \
        libblkid/src/superblocks/zfs.c \
+       libblkid/src/superblocks/zonefs.c \
        \
        libblkid/src/topology/topology.c \
        libblkid/src/topology/topology.h
index baf35e51b575dc80d61135e54d0114181d8065f3..67172d0a0ec5092922e7c9949b360fe2e4d15f28 100644 (file)
@@ -167,7 +167,8 @@ static const struct blkid_idinfo *idinfos[] =
        &exfat_idinfo,
        &f2fs_idinfo,
        &mpool_idinfo,
-       &apfs_idinfo
+       &apfs_idinfo,
+       &zonefs_idinfo
 };
 
 /*
index 0cd0caccf8a42d651bc03031e6a82fc0c3b67369..5ebe6bc432052e6a7ac0ce07e64b0b253d9ff45d 100644 (file)
@@ -84,6 +84,7 @@ extern const struct blkid_idinfo vdo_idinfo;
 extern const struct blkid_idinfo stratis_idinfo;
 extern const struct blkid_idinfo bitlocker_idinfo;
 extern const struct blkid_idinfo apfs_idinfo;
+extern const struct blkid_idinfo zonefs_idinfo;
 
 /*
  * superblock functions
diff --git a/libblkid/src/superblocks/zonefs.c b/libblkid/src/superblocks/zonefs.c
new file mode 100644 (file)
index 0000000..84f1e32
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2020 Western Digital Corporation or its affiliates.
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License
+ */
+#include <stddef.h>
+#include <string.h>
+#include <uuid/uuid.h>
+
+#include "superblocks.h"
+
+#define ZONEFS_MAGIC           "SFOZ" /* 0x5a4f4653 'Z' 'O' 'F' 'S' */
+#define ZONEFS_MAGIC_SIZE      4
+#define ZONEFS_MAGIC_OFST      0
+#define ZONEFS_UUID_SIZE       16
+#define ZONEFS_LABEL_SIZE      32
+#define ZONEFS_SB_OFST         0
+
+#define ZONEFS_BLOCK_SIZE      4096U
+
+/* All in little-endian */
+struct zonefs_super {
+
+       /* Magic number */
+       int32_t         s_magic;
+
+       /* Checksum */
+       int32_t         s_crc;
+
+       /* Volume label */
+       char            s_label[ZONEFS_LABEL_SIZE];
+
+       /* 128-bit uuid */
+       uint8_t         s_uuid[ZONEFS_UUID_SIZE];
+
+       /* Features */
+       int64_t         s_features;
+
+       /* UID/GID to use for files */
+       int32_t         s_uid;
+       int32_t         s_gid;
+
+       /* File permissions */
+       int32_t         s_perm;
+
+       /* Padding to 4096 bytes */
+       /* uint8_t              s_reserved[4020]; */
+
+} __attribute__ ((packed));
+
+static int probe_zonefs(blkid_probe pr,
+               const struct blkid_idmag *mag  __attribute__((__unused__)))
+{
+       struct zonefs_super *sb;
+
+       sb = (struct zonefs_super *)
+               blkid_probe_get_buffer(pr, ZONEFS_SB_OFST,
+                                      sizeof(struct zonefs_super));
+       if (!sb)
+               return errno ? -errno : 1;
+
+       if (sb->s_label[0])
+               blkid_probe_set_label(pr, (unsigned char *) sb->s_label,
+                                     sizeof(sb->s_label));
+
+       blkid_probe_set_uuid(pr, sb->s_uuid);
+       blkid_probe_set_block_size(pr, ZONEFS_BLOCK_SIZE);
+
+       return 0;
+}
+
+const struct blkid_idinfo zonefs_idinfo =
+{
+       .name           = "zonefs",
+       .usage          = BLKID_USAGE_FILESYSTEM,
+       .probefunc      = probe_zonefs,
+       .magics         =
+        {
+               {
+                       .magic = (char *)ZONEFS_MAGIC,
+                       .len = ZONEFS_MAGIC_SIZE,
+                       .kboff = ZONEFS_SB_OFST,
+                       .sboff = ZONEFS_MAGIC_OFST,
+               },
+               { NULL }
+       }
+};