summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Lange2020-07-13 17:22:27 +0200
committerDenys Vlasenko2020-11-18 19:19:23 +0100
commitc20e42e320edcd3612cfdb71c8bea5277ebf9be2 (patch)
treeca42b51e19a840cee8b88c542370ffffbd7cd992
parentbd46f64dcb2cf4f37c2cbfeb808f4e380d9d5931 (diff)
downloadbusybox-c20e42e320edcd3612cfdb71c8bea5277ebf9be2.zip
busybox-c20e42e320edcd3612cfdb71c8bea5277ebf9be2.tar.gz
util-linux: support erofs filesystem
Add erofs to the known volume_ids. function old new delta volume_id_probe_erofs - 89 +89 fs1 24 28 +4 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 1/0 up/down: 93/0) Total: 93 bytes Signed-off-by: Norbert Lange <nolange79@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/volume_id/erofs.c67
-rw-r--r--util-linux/volume_id/volume_id.c3
-rw-r--r--util-linux/volume_id/volume_id_internal.h2
3 files changed, 72 insertions, 0 deletions
diff --git a/util-linux/volume_id/erofs.c b/util-linux/volume_id/erofs.c
new file mode 100644
index 0000000..a163a35
--- /dev/null
+++ b/util-linux/volume_id/erofs.c
@@ -0,0 +1,67 @@
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) 2020 Norbert Lange <nolange79@gmail.com>
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+//config:config FEATURE_VOLUMEID_EROFS
+//config: bool "erofs filesystem"
+//config: default y
+//config: depends on VOLUMEID
+//config: help
+//config: Erofs is a compressed readonly filesystem for Linux.
+
+//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_EROFS) += erofs.o
+
+#include "volume_id_internal.h"
+
+#define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2
+#define EROFS_SUPER_OFFSET 1024
+#define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001
+
+/* 128-byte erofs on-disk super block */
+struct erofs_super_block {
+ uint32_t magic; /* file system magic number */
+ uint32_t checksum; /* crc32c(super_block) */
+ uint32_t feature_compat;
+ uint8_t blkszbits; /* support block_size == PAGE_SIZE only */
+ uint8_t reserved;
+
+ uint16_t root_nid; /* nid of root directory */
+ uint64_t inos; /* total valid ino # (== f_files - f_favail) */
+
+ uint64_t build_time; /* inode v1 time derivation */
+ uint32_t build_time_nsec; /* inode v1 time derivation in nano scale */
+ uint32_t blocks; /* used for statfs */
+ uint32_t meta_blkaddr; /* start block address of metadata area */
+ uint32_t xattr_blkaddr; /* start block address of shared xattr area */
+ uint8_t uuid[16]; /* 128-bit uuid for volume */
+ uint8_t volume_name[16]; /* volume name */
+ uint32_t feature_incompat;
+ uint8_t reserved2[44];
+} PACKED;
+
+int FAST_FUNC volume_id_probe_erofs(struct volume_id *id /*,uint64_t off*/)
+{
+ struct erofs_super_block *sb;
+
+ BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
+
+ dbg("erofs: probing at offset 0x%llx", EROFS_SUPER_OFFSET);
+ sb = volume_id_get_buffer(id, EROFS_SUPER_OFFSET, sizeof(*sb));
+ if (!sb)
+ return -1;
+
+ if (sb->magic != cpu_to_le32(EROFS_SUPER_MAGIC_V1))
+ return -1;
+
+ IF_FEATURE_BLKID_TYPE(id->type = "erofs");
+
+ volume_id_set_label_string(id, sb->volume_name,
+ MIN(sizeof(sb->volume_name), VOLUME_ID_LABEL_SIZE));
+
+ volume_id_set_uuid(id, sb->uuid, UUID_DCE);
+
+ return 0;
+}
diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c
index c3f07a7..99150a5 100644
--- a/util-linux/volume_id/volume_id.c
+++ b/util-linux/volume_id/volume_id.c
@@ -106,6 +106,9 @@ static const probe_fptr fs1[] = {
#if ENABLE_FEATURE_VOLUMEID_SQUASHFS
volume_id_probe_squashfs,
#endif
+#if ENABLE_FEATURE_VOLUMEID_EROFS
+ volume_id_probe_erofs,
+#endif
#if ENABLE_FEATURE_VOLUMEID_XFS
volume_id_probe_xfs,
#endif
diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h
index ada1833..609beb8 100644
--- a/util-linux/volume_id/volume_id_internal.h
+++ b/util-linux/volume_id/volume_id_internal.h
@@ -215,6 +215,8 @@ int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/);
int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/);
+int FAST_FUNC volume_id_probe_erofs(struct volume_id *id /*,uint64_t off*/);
+
int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/);
int FAST_FUNC volume_id_probe_udf(struct volume_id *id /*,uint64_t off*/);