blob: 13604ec35c8921a603d7da83b7f09e78396488d9
1 | /* |
2 | * volume_id - reads filesystem label and uuid |
3 | * |
4 | * Copyright (C) 2012 S-G Bergh <sgb@systemasis.org> |
5 | * |
6 | * Licensed under GPLv2, see file LICENSE in this source tree. |
7 | */ |
8 | |
9 | //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_UBIFS) += ubifs.o |
10 | |
11 | //config: |
12 | //config:config FEATURE_VOLUMEID_UBIFS |
13 | //config: bool "UBIFS filesystem" |
14 | //config: default y |
15 | //config: depends on VOLUMEID |
16 | //config: help |
17 | //config: UBIFS (Unsorted Block Image File System) is a file |
18 | //config: system for use with raw flash memory media. |
19 | //config: |
20 | |
21 | #include "volume_id_internal.h" |
22 | |
23 | #define UBIFS_NODE_MAGIC 0x06101831 |
24 | |
25 | /* |
26 | * struct ubifs_ch - common header node. |
27 | * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC) |
28 | * @crc: CRC-32 checksum of the node header |
29 | * @sqnum: sequence number |
30 | * @len: full node length |
31 | * @node_type: node type |
32 | * @group_type: node group type |
33 | * @padding: reserved for future, zeroes |
34 | * |
35 | * Every UBIFS node starts with this common part. If the node has a key, the |
36 | * key always goes next. |
37 | */ |
38 | struct ubifs_ch { |
39 | uint32_t magic; |
40 | uint32_t crc; |
41 | uint64_t sqnum; |
42 | uint32_t len; |
43 | uint8_t node_type; |
44 | uint8_t group_type; |
45 | uint8_t padding[2]; |
46 | } PACKED; |
47 | |
48 | /* |
49 | * struct ubifs_sb_node - superblock node. |
50 | * @ch: common header |
51 | * @padding: reserved for future, zeroes |
52 | * @key_hash: type of hash function used in keys |
53 | * @key_fmt: format of the key |
54 | * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc) |
55 | * @min_io_size: minimal input/output unit size |
56 | * @leb_size: logical eraseblock size in bytes |
57 | * @leb_cnt: count of LEBs used by file-system |
58 | * @max_leb_cnt: maximum count of LEBs used by file-system |
59 | * @max_bud_bytes: maximum amount of data stored in buds |
60 | * @log_lebs: log size in logical eraseblocks |
61 | * @lpt_lebs: number of LEBs used for lprops table |
62 | * @orph_lebs: number of LEBs used for recording orphans |
63 | * @jhead_cnt: count of journal heads |
64 | * @fanout: tree fanout (max. number of links per indexing node) |
65 | * @lsave_cnt: number of LEB numbers in LPT's save table |
66 | * @fmt_version: UBIFS on-flash format version |
67 | * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc) |
68 | * @padding1: reserved for future, zeroes |
69 | * @rp_uid: reserve pool UID |
70 | * @rp_gid: reserve pool GID |
71 | * @rp_size: size of the reserved pool in bytes |
72 | * @padding2: reserved for future, zeroes |
73 | * @time_gran: time granularity in nanoseconds |
74 | * @uuid: UUID generated when the file system image was created |
75 | * @ro_compat_version: UBIFS R/O compatibility version |
76 | */ |
77 | struct ubifs_sb_node { |
78 | struct ubifs_ch ch; |
79 | uint8_t padding[2]; |
80 | uint8_t key_hash; |
81 | uint8_t key_fmt; |
82 | uint32_t flags; |
83 | uint32_t min_io_size; |
84 | uint32_t leb_size; |
85 | uint32_t leb_cnt; |
86 | uint32_t max_leb_cnt; |
87 | uint64_t max_bud_bytes; |
88 | uint32_t log_lebs; |
89 | uint32_t lpt_lebs; |
90 | uint32_t orph_lebs; |
91 | uint32_t jhead_cnt; |
92 | uint32_t fanout; |
93 | uint32_t lsave_cnt; |
94 | uint32_t fmt_version; |
95 | uint16_t default_compr; |
96 | uint8_t padding1[2]; |
97 | uint32_t rp_uid; |
98 | uint32_t rp_gid; |
99 | uint64_t rp_size; |
100 | uint32_t time_gran; |
101 | uint8_t uuid[16]; |
102 | uint32_t ro_compat_version; |
103 | /* |
104 | uint8_t padding2[3968]; |
105 | */ |
106 | } PACKED; |
107 | |
108 | int FAST_FUNC volume_id_probe_ubifs(struct volume_id *id /*,uint64_t off*/) |
109 | { |
110 | #define off ((uint64_t)0) |
111 | struct ubifs_sb_node *sb; |
112 | |
113 | dbg("UBIFS: probing at offset 0x%llx", (unsigned long long) off); |
114 | sb = volume_id_get_buffer(id, off, sizeof(struct ubifs_sb_node)); |
115 | if (!sb) |
116 | return -1; |
117 | |
118 | if (le32_to_cpu(sb->ch.magic) != UBIFS_NODE_MAGIC) |
119 | return -1; |
120 | |
121 | IF_FEATURE_BLKID_TYPE(id->type = "ubifs";) |
122 | volume_id_set_uuid(id, sb->uuid, UUID_DCE); |
123 | |
124 | return 0; |
125 | } |
126 |