blob: 0bf15913bc36ae83c6913b017de9e902b7fb30a8 [file] [log] [blame]
Gao Xiang70b83292021-11-22 22:46:43 +08001/*
2 * Copyright (C) 2020 Gao Xiang
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License
6 */
7#include <stddef.h>
8#include <string.h>
9
10#include "superblocks.h"
11
12#define EROFS_SUPER_OFFSET 1024
13#define EROFS_SB_KBOFF (EROFS_SUPER_OFFSET >> 10)
14
15#define EROFS_SUPER_MAGIC_V1 "\xe2\xe1\xf5\xe0"
16#define EROFS_MAGIC_OFF 0
17
18/* All in little-endian */
19struct erofs_super_block {
20 uint32_t magic;
21 uint32_t checksum;
22 uint32_t feature_compat;
23 uint8_t blkszbits;
24 uint8_t reserved;
25
26 uint16_t root_nid;
27 uint64_t inos;
28
29 uint64_t build_time;
30 uint32_t build_time_nsec;
31 uint32_t blocks;
32 uint32_t meta_blkaddr;
33 uint32_t xattr_blkaddr;
34 uint8_t uuid[16];
35 uint8_t volume_name[16];
36 uint32_t feature_incompat;
37 uint8_t reserved2[44];
38};
39
40static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
41{
42 struct erofs_super_block *sb;
43
44 sb = blkid_probe_get_sb(pr, mag, struct erofs_super_block);
45 if (!sb)
46 return errno ? -errno : BLKID_PROBE_NONE;
47
48 if (sb->volume_name[0])
49 blkid_probe_set_label(pr, (unsigned char *)sb->volume_name,
50 sizeof(sb->volume_name));
51
52 blkid_probe_set_uuid(pr, sb->uuid);
53
54 return BLKID_PROBE_OK;
55}
56
57const struct blkid_idinfo erofs_idinfo =
58{
59 .name = "erofs",
60 .usage = BLKID_USAGE_FILESYSTEM,
61 .probefunc = probe_erofs,
62 .magics =
63 {
64 {
65 .magic = EROFS_SUPER_MAGIC_V1,
66 .len = 4,
67 .kboff = EROFS_SB_KBOFF,
68 .sboff = EROFS_MAGIC_OFF,
69 }, { NULL }
70 }
71};