summaryrefslogtreecommitdiffstats
path: root/libblkid/src/superblocks/erofs.c
blob: 0e7b4223dda58692730eaf76760a35af3b7173ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 }
	}
};