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