util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libblkid: add erofs filesystem support
@ 2020-12-05  7:44 Gao Xiang
  2020-12-08 10:09 ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Gao Xiang @ 2020-12-05  7:44 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Gao Xiang

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] libblkid: add erofs filesystem support
  2020-12-05  7:44 [PATCH] libblkid: add erofs filesystem support Gao Xiang
@ 2020-12-08 10:09 ` Karel Zak
  2020-12-08 10:19   ` Gao Xiang
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2020-12-08 10:09 UTC (permalink / raw)
  To: Gao Xiang; +Cc: util-linux

On Sat, Dec 05, 2020 at 03:44:10PM +0800, Gao Xiang wrote:
> This patch adds support for detecting EROFS filesystem to libblkid.

Applied, thanks!

I have also added simple regression test to tests/ts/blkid/images-fs/erofs.img.xz. 

Note that it seems the current mkfs.erofs cannot set volume_name (aka LABEL)
although the filesystem superblock support it.
 

A small nitpick to mkfs.erofs, see https://github.com/hsiangkao/erofs-utils/blob/dev/mkfs/main.c#L27

The subdirectory in 

    #include <uuid/uuid.h> 

is unnecessary (or wrong), if you use 

    PKG_CHECK_MODULES([libuuid], [uuid])

than it returns the subdirectory as -I, see

    $ pkg-config --cflags uuid
    -I/usr/include/uuid 

so the correct way is

     #include <uuid.h>

with the proper PKG_CHECK_MODULES(), btw you have it without
subdirectory in configure.ac test.

The problem is that your code reads the default include file from
/usr/include/uuid/ rather the one specified by your build system.


    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libblkid: add erofs filesystem support
  2020-12-08 10:09 ` Karel Zak
@ 2020-12-08 10:19   ` Gao Xiang
  0 siblings, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2020-12-08 10:19 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

Hi Karel,

On Tue, Dec 08, 2020 at 11:09:10AM +0100, Karel Zak wrote:
> On Sat, Dec 05, 2020 at 03:44:10PM +0800, Gao Xiang wrote:
> > This patch adds support for detecting EROFS filesystem to libblkid.
> 
> Applied, thanks!

Thanks for taking time on this and the image/testcase!

> 
> I have also added simple regression test to tests/ts/blkid/images-fs/erofs.img.xz. 
> 
> Note that it seems the current mkfs.erofs cannot set volume_name (aka LABEL)
> although the filesystem superblock support it.

Yeah, since it has little use-case for now (but leave such field for later use),
I will add this feature if needed later :) Thanks for kind reminder!

>  
> 
> A small nitpick to mkfs.erofs, see https://github.com/hsiangkao/erofs-utils/blob/dev/mkfs/main.c#L27
> 
> The subdirectory in 
> 
>     #include <uuid/uuid.h> 
> 
> is unnecessary (or wrong), if you use 
> 
>     PKG_CHECK_MODULES([libuuid], [uuid])
> 
> than it returns the subdirectory as -I, see
> 
>     $ pkg-config --cflags uuid
>     -I/usr/include/uuid 
> 
> so the correct way is
> 
>      #include <uuid.h>
> 
> with the proper PKG_CHECK_MODULES(), btw you have it without
> subdirectory in configure.ac test.
> 
> The problem is that your code reads the default include file from
> /usr/include/uuid/ rather the one specified by your build system.

Yay, many thanks for catching this! will fix it soon!

Thanks,
Gao Xiang

> 
> 
>     Karel
> 
> -- 
>  Karel Zak  <kzak@redhat.com>
>  http://karelzak.blogspot.com
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-08 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-05  7:44 [PATCH] libblkid: add erofs filesystem support Gao Xiang
2020-12-08 10:09 ` Karel Zak
2020-12-08 10:19   ` Gao Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).