From: Rafał Miłecki Date: Mon, 7 Aug 2017 09:20:09 +0000 (+0200) Subject: libblkid-tiny: add support for UBI superblock X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=98fd5b40a70dc18e56134b0b48d224698228943e;p=oweals%2Ffstools.git libblkid-tiny: add support for UBI superblock 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. This patch adds simple code reading UBI version and unique number and setting it in the blkid_probe. Signed-off-by: Rafał Miłecki --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 826a852..8752612 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ ADD_LIBRARY(blkid-tiny SHARED libblkid-tiny/vfat.c libblkid-tiny/hfs.c libblkid-tiny/swap.c + libblkid-tiny/ubi.c libblkid-tiny/ubifs.c libblkid-tiny/squashfs.c libblkid-tiny/btrfs.c diff --git a/libblkid-tiny/libblkid-tiny.c b/libblkid-tiny/libblkid-tiny.c index d718a1e..352d1f6 100644 --- a/libblkid-tiny/libblkid-tiny.c +++ b/libblkid-tiny/libblkid-tiny.c @@ -163,6 +163,7 @@ static const struct blkid_idinfo *idinfos[] = &ext2_idinfo, &jbd_idinfo, &squashfs_idinfo, + &ubi_idinfo, &ubifs_idinfo, &jffs2_idinfo, &hfsplus_idinfo, diff --git a/libblkid-tiny/superblocks.h b/libblkid-tiny/superblocks.h index d2b242f..cde8a40 100644 --- a/libblkid-tiny/superblocks.h +++ b/libblkid-tiny/superblocks.h @@ -62,6 +62,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-tiny/ubi.c b/libblkid-tiny/ubi.c new file mode 100644 index 0000000..0739c32 --- /dev/null +++ b/libblkid-tiny/ubi.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2017 Rafał Miłecki + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ +#include +#include +#include +#include +#include + +#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_RAID, + .probefunc = probe_ubi, + .magics = + { + { .magic = "UBI#", .len = 4 }, + { NULL } + } +};