All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@redhat.com>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org, Gao Xiang <hsiangkao@redhat.com>
Subject: [PATCH] libblkid: add erofs filesystem support
Date: Sat,  5 Dec 2020 15:44:10 +0800	[thread overview]
Message-ID: <20201205074410.2317033-1-hsiangkao@redhat.com> (raw)

Enhanced Read-Only File System (EROFS) has been included in Linux
kernel, many Linux distributions, buildroot and Android AOSP for
a while. Plus, nowadays, it's known that EROFS has been commercially
used by several Android vendors for their system partitions.
util-linux in busybox can also detect it recently.

This patch adds support for detecting EROFS filesystem to libblkid.

Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
---
 libblkid/src/Makemodule.am             |  1 +
 libblkid/src/superblocks/erofs.c       | 73 ++++++++++++++++++++++++++
 libblkid/src/superblocks/superblocks.c |  3 +-
 libblkid/src/superblocks/superblocks.h |  1 +
 4 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 libblkid/src/superblocks/erofs.c

diff --git a/libblkid/src/Makemodule.am b/libblkid/src/Makemodule.am
index 1aa6dfcef..16a0a2826 100644
--- a/libblkid/src/Makemodule.am
+++ b/libblkid/src/Makemodule.am
@@ -101,6 +101,7 @@ libblkid_la_SOURCES = \
 	libblkid/src/superblocks/xfs.c \
 	libblkid/src/superblocks/zfs.c \
 	libblkid/src/superblocks/zonefs.c \
+	libblkid/src/superblocks/erofs.c \
 	\
 	libblkid/src/topology/topology.c \
 	libblkid/src/topology/topology.h
diff --git a/libblkid/src/superblocks/erofs.c b/libblkid/src/superblocks/erofs.c
new file mode 100644
index 000000000..0e7b4223d
--- /dev/null
+++ b/libblkid/src/superblocks/erofs.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2020 Gao Xiang
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License
+ */
+#include <stddef.h>
+#include <string.h>
+
+#include "superblocks.h"
+
+#define EROFS_SUPER_OFFSET      1024
+#define EROFS_SB_KBOFF		(EROFS_SUPER_OFFSET >> 10)
+
+#define EROFS_SUPER_MAGIC_V1	"\xe2\xe1\xf5\xe0"
+#define EROFS_MAGIC_OFF		0
+
+/* All in little-endian */
+struct erofs_super_block {
+	uint32_t	magic;
+	uint32_t	checksum;
+	uint32_t	feature_compat;
+	uint8_t		blkszbits;
+	uint8_t		reserved;
+
+	uint16_t	root_nid;
+	uint64_t	inos;
+
+	uint64_t	build_time;
+	uint32_t	build_time_nsec;
+	uint32_t	blocks;
+	uint32_t	meta_blkaddr;
+	uint32_t	xattr_blkaddr;
+	uint8_t		uuid[16];
+	uint8_t		volume_name[16];
+	uint32_t	feature_incompat;
+	uint8_t		reserved2[44];
+};
+
+static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
+{
+	struct erofs_super_block *sb;
+
+	sb = blkid_probe_get_sb(pr, mag, struct erofs_super_block);
+	if (!sb)
+		return errno ? -errno : BLKID_PROBE_NONE;
+
+	if (sb->volume_name[0])
+		blkid_probe_set_label(pr, (unsigned char *)sb->volume_name,
+				      sizeof(sb->volume_name));
+
+	blkid_probe_set_uuid(pr, sb->uuid);
+
+	if (sb->blkszbits < 32)
+		blkid_probe_set_block_size(pr, 1U << sb->blkszbits);
+	return BLKID_PROBE_OK;
+}
+
+const struct blkid_idinfo erofs_idinfo =
+{
+	.name           = "erofs",
+	.usage          = BLKID_USAGE_FILESYSTEM,
+	.probefunc      = probe_erofs,
+	.magics         =
+        {
+		{
+			.magic = EROFS_SUPER_MAGIC_V1,
+			.len = 4,
+			.kboff = EROFS_SB_KBOFF,
+			.sboff = EROFS_MAGIC_OFF,
+		}, { NULL }
+	}
+};
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index 7b0f5eed0..f21365538 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -168,7 +168,8 @@ static const struct blkid_idinfo *idinfos[] =
 	&f2fs_idinfo,
 	&mpool_idinfo,
 	&apfs_idinfo,
-	&zonefs_idinfo
+	&zonefs_idinfo,
+	&erofs_idinfo
 };
 
 /*
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
index 5ebe6bc43..9c489c438 100644
--- a/libblkid/src/superblocks/superblocks.h
+++ b/libblkid/src/superblocks/superblocks.h
@@ -85,6 +85,7 @@ 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;
+extern const struct blkid_idinfo erofs_idinfo;
 
 /*
  * superblock functions
-- 
2.18.4


             reply	other threads:[~2020-12-05  7:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-05  7:44 Gao Xiang [this message]
2020-12-08 10:09 ` [PATCH] libblkid: add erofs filesystem support Karel Zak
2020-12-08 10:19   ` Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201205074410.2317033-1-hsiangkao@redhat.com \
    --to=hsiangkao@redhat.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.