summaryrefslogtreecommitdiffstats
path: root/libblkid
diff options
context:
space:
mode:
authorRafał Miłecki2017-08-02 14:14:18 +0200
committerKarel Zak2017-08-03 14:11:21 +0200
commita6b1ec864a3eb1d27a8781fe99d65e4e6ac05e5b (patch)
tree941624a9a450b729ddf8ad4265dd50cabf6d78bc /libblkid
parentbuild-sys: support ncursesw without headers in ncursesw/ directory (diff)
downloadkernel-qcow2-util-linux-a6b1ec864a3eb1d27a8781fe99d65e4e6ac05e5b.tar.gz
kernel-qcow2-util-linux-a6b1ec864a3eb1d27a8781fe99d65e4e6ac05e5b.tar.xz
kernel-qcow2-util-linux-a6b1ec864a3eb1d27a8781fe99d65e4e6ac05e5b.zip
libblkid: add support for UBI superblock
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>
Diffstat (limited to 'libblkid')
-rw-r--r--libblkid/src/Makemodule.am1
-rw-r--r--libblkid/src/superblocks/superblocks.c1
-rw-r--r--libblkid/src/superblocks/superblocks.h1
-rw-r--r--libblkid/src/superblocks/ubi.c51
4 files changed, 54 insertions, 0 deletions
diff --git a/libblkid/src/Makemodule.am b/libblkid/src/Makemodule.am
index 2b70742bc..8dfe892ff 100644
--- a/libblkid/src/Makemodule.am
+++ b/libblkid/src/Makemodule.am
@@ -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 \
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index 88578c8db..cb887f8f1 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -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,
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
index ea875d768..695c3b783 100644
--- a/libblkid/src/superblocks/superblocks.h
+++ b/libblkid/src/superblocks/superblocks.h
@@ -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
index 000000000..ee2644792
--- /dev/null
+++ b/libblkid/src/superblocks/ubi.c
@@ -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 }
+ }
+};