summaryrefslogtreecommitdiffstats
path: root/libblkid/src/superblocks/erofs.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 14:30:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 14:30:35 +0000
commit378c18e5f024ac5a8aef4cb40d7c9aa9633d144c (patch)
tree44dfb6ca500d32cabd450649b322a42e70a30683 /libblkid/src/superblocks/erofs.c
parentInitial commit. (diff)
downloadutil-linux-378c18e5f024ac5a8aef4cb40d7c9aa9633d144c.tar.xz
util-linux-378c18e5f024ac5a8aef4cb40d7c9aa9633d144c.zip
Adding upstream version 2.38.1.upstream/2.38.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libblkid/src/superblocks/erofs.c')
-rw-r--r--libblkid/src/superblocks/erofs.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/libblkid/src/superblocks/erofs.c b/libblkid/src/superblocks/erofs.c
new file mode 100644
index 0000000..0e7b422
--- /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 }
+ }
+};