]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: add support for UBI superblock
authorRafał Miłecki <rafal@milecki.pl>
Wed, 2 Aug 2017 12:14:18 +0000 (14:14 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Aug 2017 12:11:21 +0000 (14:11 +0200)
UBI is a volume management system that can be used on a raw flash
partition for providing multiple logical volumes. Detecting UBI
superblock may be useful for tools wanting to simplify or automate
attaching UBI.

Please note it's not directly related to the ubifs support which is just
a filesystem working on top of UBI volume.

In other words: UBI can be used on MTD partition (e.g. /dev/mtdblock0)
while ubifs can be used on UBI volume (e.g. /dev/ubi0_0).

This patch adds simple code reading UBI version and unique number and
setting it in the blkid_probe.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
libblkid/src/Makemodule.am
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h
libblkid/src/superblocks/ubi.c [new file with mode: 0644]
tests/expected/blkid/low-probe-ubi [new file with mode: 0644]
tests/ts/blkid/images-fs/ubi.img.xz [new file with mode: 0644]

index 2b70742bcbcc8d66ed3faffbea14186740d9601a..8dfe892ff6aca4315caea4488e8e0891cb590844 100644 (file)
@@ -85,6 +85,7 @@ libblkid_la_SOURCES = \
        libblkid/src/superblocks/superblocks.h \
        libblkid/src/superblocks/swap.c \
        libblkid/src/superblocks/sysv.c \
+       libblkid/src/superblocks/ubi.c \
        libblkid/src/superblocks/ubifs.c \
        libblkid/src/superblocks/udf.c \
        libblkid/src/superblocks/ufs.c \
index 88578c8db878a73c0ab833124a3f1943ff93dec5..cb887f8f1726ef8d46c3dc3677d409286e8bb69a 100644 (file)
@@ -152,6 +152,7 @@ static const struct blkid_idinfo *idinfos[] =
        &squashfs3_idinfo,
        &netware_idinfo,
        &btrfs_idinfo,
+       &ubi_idinfo,
        &ubifs_idinfo,
        &bfs_idinfo,
        &vmfs_fs_idinfo,
index ea875d76802e98481c4b747d20452be7e165e3ab..695c3b783d59b7a8fa5f2fdecbaebc12928a586a 100644 (file)
@@ -64,6 +64,7 @@ extern const struct blkid_idinfo netware_idinfo;
 extern const struct blkid_idinfo sysv_idinfo;
 extern const struct blkid_idinfo xenix_idinfo;
 extern const struct blkid_idinfo btrfs_idinfo;
+extern const struct blkid_idinfo ubi_idinfo;
 extern const struct blkid_idinfo ubifs_idinfo;
 extern const struct blkid_idinfo zfs_idinfo;
 extern const struct blkid_idinfo bfs_idinfo;
diff --git a/libblkid/src/superblocks/ubi.c b/libblkid/src/superblocks/ubi.c
new file mode 100644 (file)
index 0000000..ee26447
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 Rafał Miłecki <rafal@milecki.pl>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "superblocks.h"
+
+struct ubi_ec_hdr {
+       uint32_t        magic;
+       uint8_t         version;
+       uint8_t         padding1[3];
+       uint64_t        ec;
+       uint32_t        vid_hdr_offset;
+       uint32_t        data_offset;
+       uint32_t        image_seq;
+       uint8_t         padding2[32];
+       uint32_t        hdr_crc;
+} __attribute__((packed));
+
+static int probe_ubi(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct ubi_ec_hdr *hdr;
+
+       hdr = blkid_probe_get_sb(pr, mag, struct ubi_ec_hdr);
+       if (!hdr)
+               return -1;
+
+       blkid_probe_sprintf_version(pr, "%u", hdr->version);
+       blkid_probe_sprintf_uuid(pr, (unsigned char *)&hdr->image_seq, 4, "%u",
+                                be32_to_cpu(hdr->image_seq));
+       return 0;
+}
+
+const struct blkid_idinfo ubi_idinfo =
+{
+       .name           = "ubi",
+       .usage          = BLKID_USAGE_FILESYSTEM,
+       .probefunc      = probe_ubi,
+       .magics         =
+       {
+               { .magic = "UBI#", .len = 4 },
+               { NULL }
+       }
+};
diff --git a/tests/expected/blkid/low-probe-ubi b/tests/expected/blkid/low-probe-ubi
new file mode 100644 (file)
index 0000000..318a351
--- /dev/null
@@ -0,0 +1,5 @@
+ID_FS_TYPE=ubi
+ID_FS_USAGE=filesystem
+ID_FS_UUID=1329411831
+ID_FS_UUID_ENC=1329411831
+ID_FS_VERSION=1
diff --git a/tests/ts/blkid/images-fs/ubi.img.xz b/tests/ts/blkid/images-fs/ubi.img.xz
new file mode 100644 (file)
index 0000000..ed3b3f4
Binary files /dev/null and b/tests/ts/blkid/images-fs/ubi.img.xz differ