2d69c2bf378587cd054635b6c20755873fa897eb
[project/ubox.git] / libblkid-tiny / ubifs.c
1 /*
2 * Copyright (C) 2009 Corentin Chary <corentincj@iksaif.net>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <stdint.h>
12
13 #include "superblocks.h"
14
15 /*
16 * struct ubifs_ch - common header node.
17 * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC)
18 * @crc: CRC-32 checksum of the node header
19 * @sqnum: sequence number
20 * @len: full node length
21 * @node_type: node type
22 * @group_type: node group type
23 * @padding: reserved for future, zeroes
24 *
25 * Every UBIFS node starts with this common part. If the node has a key, the
26 * key always goes next.
27 */
28 struct ubifs_ch {
29 uint32_t magic;
30 uint32_t crc;
31 uint64_t sqnum;
32 uint32_t len;
33 uint8_t node_type;
34 uint8_t group_type;
35 uint8_t padding[2];
36 } __attribute__ ((packed));
37
38 /*
39 * struct ubifs_sb_node - superblock node.
40 * @ch: common header
41 * @padding: reserved for future, zeroes
42 * @key_hash: type of hash function used in keys
43 * @key_fmt: format of the key
44 * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)
45 * @min_io_size: minimal input/output unit size
46 * @leb_size: logical eraseblock size in bytes
47 * @leb_cnt: count of LEBs used by file-system
48 * @max_leb_cnt: maximum count of LEBs used by file-system
49 * @max_bud_bytes: maximum amount of data stored in buds
50 * @log_lebs: log size in logical eraseblocks
51 * @lpt_lebs: number of LEBs used for lprops table
52 * @orph_lebs: number of LEBs used for recording orphans
53 * @jhead_cnt: count of journal heads
54 * @fanout: tree fanout (max. number of links per indexing node)
55 * @lsave_cnt: number of LEB numbers in LPT's save table
56 * @fmt_version: UBIFS on-flash format version
57 * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
58 * @padding1: reserved for future, zeroes
59 * @rp_uid: reserve pool UID
60 * @rp_gid: reserve pool GID
61 * @rp_size: size of the reserved pool in bytes
62 * @padding2: reserved for future, zeroes
63 * @time_gran: time granularity in nanoseconds
64 * @uuid: UUID generated when the file system image was created
65 * @ro_compat_version: UBIFS R/O compatibility version
66 */
67 struct ubifs_sb_node {
68 struct ubifs_ch ch;
69 uint8_t padding[2];
70 uint8_t key_hash;
71 uint8_t key_fmt;
72 uint32_t flags;
73 uint32_t min_io_size;
74 uint32_t leb_size;
75 uint32_t leb_cnt;
76 uint32_t max_leb_cnt;
77 uint64_t max_bud_bytes;
78 uint32_t log_lebs;
79 uint32_t lpt_lebs;
80 uint32_t orph_lebs;
81 uint32_t jhead_cnt;
82 uint32_t fanout;
83 uint32_t lsave_cnt;
84 uint32_t fmt_version;
85 uint16_t default_compr;
86 uint8_t padding1[2];
87 uint32_t rp_uid;
88 uint32_t rp_gid;
89 uint64_t rp_size;
90 uint32_t time_gran;
91 uint8_t uuid[16];
92 uint32_t ro_compat_version;
93 uint8_t padding2[3968];
94 } __attribute__ ((packed));
95
96 static int probe_ubifs(blkid_probe pr, const struct blkid_idmag *mag)
97 {
98 struct ubifs_sb_node *sb;
99
100 sb = blkid_probe_get_sb(pr, mag, struct ubifs_sb_node);
101 if (!sb)
102 return -1;
103
104 blkid_probe_set_uuid(pr, sb->uuid);
105 blkid_probe_sprintf_version(pr, "w%dr%d",
106 sb->fmt_version, sb->ro_compat_version);
107 return 0;
108 }
109
110 const struct blkid_idinfo ubifs_idinfo =
111 {
112 .name = "ubifs",
113 .usage = BLKID_USAGE_FILESYSTEM,
114 .probefunc = probe_ubifs,
115 .magics =
116 {
117 { .magic = "\x31\x18\x10\x06", .len = 4 },
118 { NULL }
119 }
120 };