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