Commit 9f58d3503a1368673609db1962e4a584261b62eb
Committed by
Artem Bityutskiy
1 parent
e11602ea3e
Exists in
master
and in
7 other branches
UBIFS: add a superblock flag for free space fix-up
The 'space_fixup' flag can be set in the superblock of a new filesystem by mkfs.ubifs to indicate that any eraseblocks with free space remaining should be fixed-up the first time it's mounted (after which the flag is un-set). This means that the UBIFS image has been flashed by a "dumb" flasher and the free space has been actually programmed (writing all 0xFFs), so this free space cannot be used. UBIFS fixes the free space up by re-writing the contents of all LEBs with free space using the atomic LEB change UBI operation. Artem: improved commit message, add some more commentaries to the code. Signed-off-by: Matthew L. Creech <mlcreech@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Showing 4 changed files with 7 additions and 0 deletions Inline Diff
fs/ubifs/debug.c
1 | /* | 1 | /* |
2 | * This file is part of UBIFS. | 2 | * This file is part of UBIFS. |
3 | * | 3 | * |
4 | * Copyright (C) 2006-2008 Nokia Corporation | 4 | * Copyright (C) 2006-2008 Nokia Corporation |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 6 | * This program is free software; you can redistribute it and/or modify it |
7 | * under the terms of the GNU General Public License version 2 as published by | 7 | * under the terms of the GNU General Public License version 2 as published by |
8 | * the Free Software Foundation. | 8 | * the Free Software Foundation. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
13 | * more details. | 13 | * more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License along with | 15 | * You should have received a copy of the GNU General Public License along with |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | 16 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | * | 18 | * |
19 | * Authors: Artem Bityutskiy (Битюцкий Артём) | 19 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
20 | * Adrian Hunter | 20 | * Adrian Hunter |
21 | */ | 21 | */ |
22 | 22 | ||
23 | /* | 23 | /* |
24 | * This file implements most of the debugging stuff which is compiled in only | 24 | * This file implements most of the debugging stuff which is compiled in only |
25 | * when it is enabled. But some debugging check functions are implemented in | 25 | * when it is enabled. But some debugging check functions are implemented in |
26 | * corresponding subsystem, just because they are closely related and utilize | 26 | * corresponding subsystem, just because they are closely related and utilize |
27 | * various local functions of those subsystems. | 27 | * various local functions of those subsystems. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #define UBIFS_DBG_PRESERVE_UBI | 30 | #define UBIFS_DBG_PRESERVE_UBI |
31 | 31 | ||
32 | #include "ubifs.h" | 32 | #include "ubifs.h" |
33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
34 | #include <linux/moduleparam.h> | 34 | #include <linux/moduleparam.h> |
35 | #include <linux/debugfs.h> | 35 | #include <linux/debugfs.h> |
36 | #include <linux/math64.h> | 36 | #include <linux/math64.h> |
37 | 37 | ||
38 | #ifdef CONFIG_UBIFS_FS_DEBUG | 38 | #ifdef CONFIG_UBIFS_FS_DEBUG |
39 | 39 | ||
40 | DEFINE_SPINLOCK(dbg_lock); | 40 | DEFINE_SPINLOCK(dbg_lock); |
41 | 41 | ||
42 | static char dbg_key_buf0[128]; | 42 | static char dbg_key_buf0[128]; |
43 | static char dbg_key_buf1[128]; | 43 | static char dbg_key_buf1[128]; |
44 | 44 | ||
45 | unsigned int ubifs_msg_flags; | 45 | unsigned int ubifs_msg_flags; |
46 | unsigned int ubifs_chk_flags; | 46 | unsigned int ubifs_chk_flags; |
47 | unsigned int ubifs_tst_flags; | 47 | unsigned int ubifs_tst_flags; |
48 | 48 | ||
49 | module_param_named(debug_msgs, ubifs_msg_flags, uint, S_IRUGO | S_IWUSR); | 49 | module_param_named(debug_msgs, ubifs_msg_flags, uint, S_IRUGO | S_IWUSR); |
50 | module_param_named(debug_chks, ubifs_chk_flags, uint, S_IRUGO | S_IWUSR); | 50 | module_param_named(debug_chks, ubifs_chk_flags, uint, S_IRUGO | S_IWUSR); |
51 | module_param_named(debug_tsts, ubifs_tst_flags, uint, S_IRUGO | S_IWUSR); | 51 | module_param_named(debug_tsts, ubifs_tst_flags, uint, S_IRUGO | S_IWUSR); |
52 | 52 | ||
53 | MODULE_PARM_DESC(debug_msgs, "Debug message type flags"); | 53 | MODULE_PARM_DESC(debug_msgs, "Debug message type flags"); |
54 | MODULE_PARM_DESC(debug_chks, "Debug check flags"); | 54 | MODULE_PARM_DESC(debug_chks, "Debug check flags"); |
55 | MODULE_PARM_DESC(debug_tsts, "Debug special test flags"); | 55 | MODULE_PARM_DESC(debug_tsts, "Debug special test flags"); |
56 | 56 | ||
57 | static const char *get_key_fmt(int fmt) | 57 | static const char *get_key_fmt(int fmt) |
58 | { | 58 | { |
59 | switch (fmt) { | 59 | switch (fmt) { |
60 | case UBIFS_SIMPLE_KEY_FMT: | 60 | case UBIFS_SIMPLE_KEY_FMT: |
61 | return "simple"; | 61 | return "simple"; |
62 | default: | 62 | default: |
63 | return "unknown/invalid format"; | 63 | return "unknown/invalid format"; |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | static const char *get_key_hash(int hash) | 67 | static const char *get_key_hash(int hash) |
68 | { | 68 | { |
69 | switch (hash) { | 69 | switch (hash) { |
70 | case UBIFS_KEY_HASH_R5: | 70 | case UBIFS_KEY_HASH_R5: |
71 | return "R5"; | 71 | return "R5"; |
72 | case UBIFS_KEY_HASH_TEST: | 72 | case UBIFS_KEY_HASH_TEST: |
73 | return "test"; | 73 | return "test"; |
74 | default: | 74 | default: |
75 | return "unknown/invalid name hash"; | 75 | return "unknown/invalid name hash"; |
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | static const char *get_key_type(int type) | 79 | static const char *get_key_type(int type) |
80 | { | 80 | { |
81 | switch (type) { | 81 | switch (type) { |
82 | case UBIFS_INO_KEY: | 82 | case UBIFS_INO_KEY: |
83 | return "inode"; | 83 | return "inode"; |
84 | case UBIFS_DENT_KEY: | 84 | case UBIFS_DENT_KEY: |
85 | return "direntry"; | 85 | return "direntry"; |
86 | case UBIFS_XENT_KEY: | 86 | case UBIFS_XENT_KEY: |
87 | return "xentry"; | 87 | return "xentry"; |
88 | case UBIFS_DATA_KEY: | 88 | case UBIFS_DATA_KEY: |
89 | return "data"; | 89 | return "data"; |
90 | case UBIFS_TRUN_KEY: | 90 | case UBIFS_TRUN_KEY: |
91 | return "truncate"; | 91 | return "truncate"; |
92 | default: | 92 | default: |
93 | return "unknown/invalid key"; | 93 | return "unknown/invalid key"; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, | 97 | static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, |
98 | char *buffer) | 98 | char *buffer) |
99 | { | 99 | { |
100 | char *p = buffer; | 100 | char *p = buffer; |
101 | int type = key_type(c, key); | 101 | int type = key_type(c, key); |
102 | 102 | ||
103 | if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { | 103 | if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { |
104 | switch (type) { | 104 | switch (type) { |
105 | case UBIFS_INO_KEY: | 105 | case UBIFS_INO_KEY: |
106 | sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key), | 106 | sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key), |
107 | get_key_type(type)); | 107 | get_key_type(type)); |
108 | break; | 108 | break; |
109 | case UBIFS_DENT_KEY: | 109 | case UBIFS_DENT_KEY: |
110 | case UBIFS_XENT_KEY: | 110 | case UBIFS_XENT_KEY: |
111 | sprintf(p, "(%lu, %s, %#08x)", | 111 | sprintf(p, "(%lu, %s, %#08x)", |
112 | (unsigned long)key_inum(c, key), | 112 | (unsigned long)key_inum(c, key), |
113 | get_key_type(type), key_hash(c, key)); | 113 | get_key_type(type), key_hash(c, key)); |
114 | break; | 114 | break; |
115 | case UBIFS_DATA_KEY: | 115 | case UBIFS_DATA_KEY: |
116 | sprintf(p, "(%lu, %s, %u)", | 116 | sprintf(p, "(%lu, %s, %u)", |
117 | (unsigned long)key_inum(c, key), | 117 | (unsigned long)key_inum(c, key), |
118 | get_key_type(type), key_block(c, key)); | 118 | get_key_type(type), key_block(c, key)); |
119 | break; | 119 | break; |
120 | case UBIFS_TRUN_KEY: | 120 | case UBIFS_TRUN_KEY: |
121 | sprintf(p, "(%lu, %s)", | 121 | sprintf(p, "(%lu, %s)", |
122 | (unsigned long)key_inum(c, key), | 122 | (unsigned long)key_inum(c, key), |
123 | get_key_type(type)); | 123 | get_key_type(type)); |
124 | break; | 124 | break; |
125 | default: | 125 | default: |
126 | sprintf(p, "(bad key type: %#08x, %#08x)", | 126 | sprintf(p, "(bad key type: %#08x, %#08x)", |
127 | key->u32[0], key->u32[1]); | 127 | key->u32[0], key->u32[1]); |
128 | } | 128 | } |
129 | } else | 129 | } else |
130 | sprintf(p, "bad key format %d", c->key_fmt); | 130 | sprintf(p, "bad key format %d", c->key_fmt); |
131 | } | 131 | } |
132 | 132 | ||
133 | const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key) | 133 | const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key) |
134 | { | 134 | { |
135 | /* dbg_lock must be held */ | 135 | /* dbg_lock must be held */ |
136 | sprintf_key(c, key, dbg_key_buf0); | 136 | sprintf_key(c, key, dbg_key_buf0); |
137 | return dbg_key_buf0; | 137 | return dbg_key_buf0; |
138 | } | 138 | } |
139 | 139 | ||
140 | const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key) | 140 | const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key) |
141 | { | 141 | { |
142 | /* dbg_lock must be held */ | 142 | /* dbg_lock must be held */ |
143 | sprintf_key(c, key, dbg_key_buf1); | 143 | sprintf_key(c, key, dbg_key_buf1); |
144 | return dbg_key_buf1; | 144 | return dbg_key_buf1; |
145 | } | 145 | } |
146 | 146 | ||
147 | const char *dbg_ntype(int type) | 147 | const char *dbg_ntype(int type) |
148 | { | 148 | { |
149 | switch (type) { | 149 | switch (type) { |
150 | case UBIFS_PAD_NODE: | 150 | case UBIFS_PAD_NODE: |
151 | return "padding node"; | 151 | return "padding node"; |
152 | case UBIFS_SB_NODE: | 152 | case UBIFS_SB_NODE: |
153 | return "superblock node"; | 153 | return "superblock node"; |
154 | case UBIFS_MST_NODE: | 154 | case UBIFS_MST_NODE: |
155 | return "master node"; | 155 | return "master node"; |
156 | case UBIFS_REF_NODE: | 156 | case UBIFS_REF_NODE: |
157 | return "reference node"; | 157 | return "reference node"; |
158 | case UBIFS_INO_NODE: | 158 | case UBIFS_INO_NODE: |
159 | return "inode node"; | 159 | return "inode node"; |
160 | case UBIFS_DENT_NODE: | 160 | case UBIFS_DENT_NODE: |
161 | return "direntry node"; | 161 | return "direntry node"; |
162 | case UBIFS_XENT_NODE: | 162 | case UBIFS_XENT_NODE: |
163 | return "xentry node"; | 163 | return "xentry node"; |
164 | case UBIFS_DATA_NODE: | 164 | case UBIFS_DATA_NODE: |
165 | return "data node"; | 165 | return "data node"; |
166 | case UBIFS_TRUN_NODE: | 166 | case UBIFS_TRUN_NODE: |
167 | return "truncate node"; | 167 | return "truncate node"; |
168 | case UBIFS_IDX_NODE: | 168 | case UBIFS_IDX_NODE: |
169 | return "indexing node"; | 169 | return "indexing node"; |
170 | case UBIFS_CS_NODE: | 170 | case UBIFS_CS_NODE: |
171 | return "commit start node"; | 171 | return "commit start node"; |
172 | case UBIFS_ORPH_NODE: | 172 | case UBIFS_ORPH_NODE: |
173 | return "orphan node"; | 173 | return "orphan node"; |
174 | default: | 174 | default: |
175 | return "unknown node"; | 175 | return "unknown node"; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | static const char *dbg_gtype(int type) | 179 | static const char *dbg_gtype(int type) |
180 | { | 180 | { |
181 | switch (type) { | 181 | switch (type) { |
182 | case UBIFS_NO_NODE_GROUP: | 182 | case UBIFS_NO_NODE_GROUP: |
183 | return "no node group"; | 183 | return "no node group"; |
184 | case UBIFS_IN_NODE_GROUP: | 184 | case UBIFS_IN_NODE_GROUP: |
185 | return "in node group"; | 185 | return "in node group"; |
186 | case UBIFS_LAST_OF_NODE_GROUP: | 186 | case UBIFS_LAST_OF_NODE_GROUP: |
187 | return "last of node group"; | 187 | return "last of node group"; |
188 | default: | 188 | default: |
189 | return "unknown"; | 189 | return "unknown"; |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | const char *dbg_cstate(int cmt_state) | 193 | const char *dbg_cstate(int cmt_state) |
194 | { | 194 | { |
195 | switch (cmt_state) { | 195 | switch (cmt_state) { |
196 | case COMMIT_RESTING: | 196 | case COMMIT_RESTING: |
197 | return "commit resting"; | 197 | return "commit resting"; |
198 | case COMMIT_BACKGROUND: | 198 | case COMMIT_BACKGROUND: |
199 | return "background commit requested"; | 199 | return "background commit requested"; |
200 | case COMMIT_REQUIRED: | 200 | case COMMIT_REQUIRED: |
201 | return "commit required"; | 201 | return "commit required"; |
202 | case COMMIT_RUNNING_BACKGROUND: | 202 | case COMMIT_RUNNING_BACKGROUND: |
203 | return "BACKGROUND commit running"; | 203 | return "BACKGROUND commit running"; |
204 | case COMMIT_RUNNING_REQUIRED: | 204 | case COMMIT_RUNNING_REQUIRED: |
205 | return "commit running and required"; | 205 | return "commit running and required"; |
206 | case COMMIT_BROKEN: | 206 | case COMMIT_BROKEN: |
207 | return "broken commit"; | 207 | return "broken commit"; |
208 | default: | 208 | default: |
209 | return "unknown commit state"; | 209 | return "unknown commit state"; |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | const char *dbg_jhead(int jhead) | 213 | const char *dbg_jhead(int jhead) |
214 | { | 214 | { |
215 | switch (jhead) { | 215 | switch (jhead) { |
216 | case GCHD: | 216 | case GCHD: |
217 | return "0 (GC)"; | 217 | return "0 (GC)"; |
218 | case BASEHD: | 218 | case BASEHD: |
219 | return "1 (base)"; | 219 | return "1 (base)"; |
220 | case DATAHD: | 220 | case DATAHD: |
221 | return "2 (data)"; | 221 | return "2 (data)"; |
222 | default: | 222 | default: |
223 | return "unknown journal head"; | 223 | return "unknown journal head"; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||
227 | static void dump_ch(const struct ubifs_ch *ch) | 227 | static void dump_ch(const struct ubifs_ch *ch) |
228 | { | 228 | { |
229 | printk(KERN_DEBUG "\tmagic %#x\n", le32_to_cpu(ch->magic)); | 229 | printk(KERN_DEBUG "\tmagic %#x\n", le32_to_cpu(ch->magic)); |
230 | printk(KERN_DEBUG "\tcrc %#x\n", le32_to_cpu(ch->crc)); | 230 | printk(KERN_DEBUG "\tcrc %#x\n", le32_to_cpu(ch->crc)); |
231 | printk(KERN_DEBUG "\tnode_type %d (%s)\n", ch->node_type, | 231 | printk(KERN_DEBUG "\tnode_type %d (%s)\n", ch->node_type, |
232 | dbg_ntype(ch->node_type)); | 232 | dbg_ntype(ch->node_type)); |
233 | printk(KERN_DEBUG "\tgroup_type %d (%s)\n", ch->group_type, | 233 | printk(KERN_DEBUG "\tgroup_type %d (%s)\n", ch->group_type, |
234 | dbg_gtype(ch->group_type)); | 234 | dbg_gtype(ch->group_type)); |
235 | printk(KERN_DEBUG "\tsqnum %llu\n", | 235 | printk(KERN_DEBUG "\tsqnum %llu\n", |
236 | (unsigned long long)le64_to_cpu(ch->sqnum)); | 236 | (unsigned long long)le64_to_cpu(ch->sqnum)); |
237 | printk(KERN_DEBUG "\tlen %u\n", le32_to_cpu(ch->len)); | 237 | printk(KERN_DEBUG "\tlen %u\n", le32_to_cpu(ch->len)); |
238 | } | 238 | } |
239 | 239 | ||
240 | void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode) | 240 | void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode) |
241 | { | 241 | { |
242 | const struct ubifs_inode *ui = ubifs_inode(inode); | 242 | const struct ubifs_inode *ui = ubifs_inode(inode); |
243 | 243 | ||
244 | printk(KERN_DEBUG "Dump in-memory inode:"); | 244 | printk(KERN_DEBUG "Dump in-memory inode:"); |
245 | printk(KERN_DEBUG "\tinode %lu\n", inode->i_ino); | 245 | printk(KERN_DEBUG "\tinode %lu\n", inode->i_ino); |
246 | printk(KERN_DEBUG "\tsize %llu\n", | 246 | printk(KERN_DEBUG "\tsize %llu\n", |
247 | (unsigned long long)i_size_read(inode)); | 247 | (unsigned long long)i_size_read(inode)); |
248 | printk(KERN_DEBUG "\tnlink %u\n", inode->i_nlink); | 248 | printk(KERN_DEBUG "\tnlink %u\n", inode->i_nlink); |
249 | printk(KERN_DEBUG "\tuid %u\n", (unsigned int)inode->i_uid); | 249 | printk(KERN_DEBUG "\tuid %u\n", (unsigned int)inode->i_uid); |
250 | printk(KERN_DEBUG "\tgid %u\n", (unsigned int)inode->i_gid); | 250 | printk(KERN_DEBUG "\tgid %u\n", (unsigned int)inode->i_gid); |
251 | printk(KERN_DEBUG "\tatime %u.%u\n", | 251 | printk(KERN_DEBUG "\tatime %u.%u\n", |
252 | (unsigned int)inode->i_atime.tv_sec, | 252 | (unsigned int)inode->i_atime.tv_sec, |
253 | (unsigned int)inode->i_atime.tv_nsec); | 253 | (unsigned int)inode->i_atime.tv_nsec); |
254 | printk(KERN_DEBUG "\tmtime %u.%u\n", | 254 | printk(KERN_DEBUG "\tmtime %u.%u\n", |
255 | (unsigned int)inode->i_mtime.tv_sec, | 255 | (unsigned int)inode->i_mtime.tv_sec, |
256 | (unsigned int)inode->i_mtime.tv_nsec); | 256 | (unsigned int)inode->i_mtime.tv_nsec); |
257 | printk(KERN_DEBUG "\tctime %u.%u\n", | 257 | printk(KERN_DEBUG "\tctime %u.%u\n", |
258 | (unsigned int)inode->i_ctime.tv_sec, | 258 | (unsigned int)inode->i_ctime.tv_sec, |
259 | (unsigned int)inode->i_ctime.tv_nsec); | 259 | (unsigned int)inode->i_ctime.tv_nsec); |
260 | printk(KERN_DEBUG "\tcreat_sqnum %llu\n", ui->creat_sqnum); | 260 | printk(KERN_DEBUG "\tcreat_sqnum %llu\n", ui->creat_sqnum); |
261 | printk(KERN_DEBUG "\txattr_size %u\n", ui->xattr_size); | 261 | printk(KERN_DEBUG "\txattr_size %u\n", ui->xattr_size); |
262 | printk(KERN_DEBUG "\txattr_cnt %u\n", ui->xattr_cnt); | 262 | printk(KERN_DEBUG "\txattr_cnt %u\n", ui->xattr_cnt); |
263 | printk(KERN_DEBUG "\txattr_names %u\n", ui->xattr_names); | 263 | printk(KERN_DEBUG "\txattr_names %u\n", ui->xattr_names); |
264 | printk(KERN_DEBUG "\tdirty %u\n", ui->dirty); | 264 | printk(KERN_DEBUG "\tdirty %u\n", ui->dirty); |
265 | printk(KERN_DEBUG "\txattr %u\n", ui->xattr); | 265 | printk(KERN_DEBUG "\txattr %u\n", ui->xattr); |
266 | printk(KERN_DEBUG "\tbulk_read %u\n", ui->xattr); | 266 | printk(KERN_DEBUG "\tbulk_read %u\n", ui->xattr); |
267 | printk(KERN_DEBUG "\tsynced_i_size %llu\n", | 267 | printk(KERN_DEBUG "\tsynced_i_size %llu\n", |
268 | (unsigned long long)ui->synced_i_size); | 268 | (unsigned long long)ui->synced_i_size); |
269 | printk(KERN_DEBUG "\tui_size %llu\n", | 269 | printk(KERN_DEBUG "\tui_size %llu\n", |
270 | (unsigned long long)ui->ui_size); | 270 | (unsigned long long)ui->ui_size); |
271 | printk(KERN_DEBUG "\tflags %d\n", ui->flags); | 271 | printk(KERN_DEBUG "\tflags %d\n", ui->flags); |
272 | printk(KERN_DEBUG "\tcompr_type %d\n", ui->compr_type); | 272 | printk(KERN_DEBUG "\tcompr_type %d\n", ui->compr_type); |
273 | printk(KERN_DEBUG "\tlast_page_read %lu\n", ui->last_page_read); | 273 | printk(KERN_DEBUG "\tlast_page_read %lu\n", ui->last_page_read); |
274 | printk(KERN_DEBUG "\tread_in_a_row %lu\n", ui->read_in_a_row); | 274 | printk(KERN_DEBUG "\tread_in_a_row %lu\n", ui->read_in_a_row); |
275 | printk(KERN_DEBUG "\tdata_len %d\n", ui->data_len); | 275 | printk(KERN_DEBUG "\tdata_len %d\n", ui->data_len); |
276 | } | 276 | } |
277 | 277 | ||
278 | void dbg_dump_node(const struct ubifs_info *c, const void *node) | 278 | void dbg_dump_node(const struct ubifs_info *c, const void *node) |
279 | { | 279 | { |
280 | int i, n; | 280 | int i, n; |
281 | union ubifs_key key; | 281 | union ubifs_key key; |
282 | const struct ubifs_ch *ch = node; | 282 | const struct ubifs_ch *ch = node; |
283 | 283 | ||
284 | if (dbg_failure_mode) | 284 | if (dbg_failure_mode) |
285 | return; | 285 | return; |
286 | 286 | ||
287 | /* If the magic is incorrect, just hexdump the first bytes */ | 287 | /* If the magic is incorrect, just hexdump the first bytes */ |
288 | if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) { | 288 | if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) { |
289 | printk(KERN_DEBUG "Not a node, first %zu bytes:", UBIFS_CH_SZ); | 289 | printk(KERN_DEBUG "Not a node, first %zu bytes:", UBIFS_CH_SZ); |
290 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 290 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
291 | (void *)node, UBIFS_CH_SZ, 1); | 291 | (void *)node, UBIFS_CH_SZ, 1); |
292 | return; | 292 | return; |
293 | } | 293 | } |
294 | 294 | ||
295 | spin_lock(&dbg_lock); | 295 | spin_lock(&dbg_lock); |
296 | dump_ch(node); | 296 | dump_ch(node); |
297 | 297 | ||
298 | switch (ch->node_type) { | 298 | switch (ch->node_type) { |
299 | case UBIFS_PAD_NODE: | 299 | case UBIFS_PAD_NODE: |
300 | { | 300 | { |
301 | const struct ubifs_pad_node *pad = node; | 301 | const struct ubifs_pad_node *pad = node; |
302 | 302 | ||
303 | printk(KERN_DEBUG "\tpad_len %u\n", | 303 | printk(KERN_DEBUG "\tpad_len %u\n", |
304 | le32_to_cpu(pad->pad_len)); | 304 | le32_to_cpu(pad->pad_len)); |
305 | break; | 305 | break; |
306 | } | 306 | } |
307 | case UBIFS_SB_NODE: | 307 | case UBIFS_SB_NODE: |
308 | { | 308 | { |
309 | const struct ubifs_sb_node *sup = node; | 309 | const struct ubifs_sb_node *sup = node; |
310 | unsigned int sup_flags = le32_to_cpu(sup->flags); | 310 | unsigned int sup_flags = le32_to_cpu(sup->flags); |
311 | 311 | ||
312 | printk(KERN_DEBUG "\tkey_hash %d (%s)\n", | 312 | printk(KERN_DEBUG "\tkey_hash %d (%s)\n", |
313 | (int)sup->key_hash, get_key_hash(sup->key_hash)); | 313 | (int)sup->key_hash, get_key_hash(sup->key_hash)); |
314 | printk(KERN_DEBUG "\tkey_fmt %d (%s)\n", | 314 | printk(KERN_DEBUG "\tkey_fmt %d (%s)\n", |
315 | (int)sup->key_fmt, get_key_fmt(sup->key_fmt)); | 315 | (int)sup->key_fmt, get_key_fmt(sup->key_fmt)); |
316 | printk(KERN_DEBUG "\tflags %#x\n", sup_flags); | 316 | printk(KERN_DEBUG "\tflags %#x\n", sup_flags); |
317 | printk(KERN_DEBUG "\t big_lpt %u\n", | 317 | printk(KERN_DEBUG "\t big_lpt %u\n", |
318 | !!(sup_flags & UBIFS_FLG_BIGLPT)); | 318 | !!(sup_flags & UBIFS_FLG_BIGLPT)); |
319 | printk(KERN_DEBUG "\t space_fixup %u\n", | ||
320 | !!(sup_flags & UBIFS_FLG_SPACE_FIXUP)); | ||
319 | printk(KERN_DEBUG "\tmin_io_size %u\n", | 321 | printk(KERN_DEBUG "\tmin_io_size %u\n", |
320 | le32_to_cpu(sup->min_io_size)); | 322 | le32_to_cpu(sup->min_io_size)); |
321 | printk(KERN_DEBUG "\tleb_size %u\n", | 323 | printk(KERN_DEBUG "\tleb_size %u\n", |
322 | le32_to_cpu(sup->leb_size)); | 324 | le32_to_cpu(sup->leb_size)); |
323 | printk(KERN_DEBUG "\tleb_cnt %u\n", | 325 | printk(KERN_DEBUG "\tleb_cnt %u\n", |
324 | le32_to_cpu(sup->leb_cnt)); | 326 | le32_to_cpu(sup->leb_cnt)); |
325 | printk(KERN_DEBUG "\tmax_leb_cnt %u\n", | 327 | printk(KERN_DEBUG "\tmax_leb_cnt %u\n", |
326 | le32_to_cpu(sup->max_leb_cnt)); | 328 | le32_to_cpu(sup->max_leb_cnt)); |
327 | printk(KERN_DEBUG "\tmax_bud_bytes %llu\n", | 329 | printk(KERN_DEBUG "\tmax_bud_bytes %llu\n", |
328 | (unsigned long long)le64_to_cpu(sup->max_bud_bytes)); | 330 | (unsigned long long)le64_to_cpu(sup->max_bud_bytes)); |
329 | printk(KERN_DEBUG "\tlog_lebs %u\n", | 331 | printk(KERN_DEBUG "\tlog_lebs %u\n", |
330 | le32_to_cpu(sup->log_lebs)); | 332 | le32_to_cpu(sup->log_lebs)); |
331 | printk(KERN_DEBUG "\tlpt_lebs %u\n", | 333 | printk(KERN_DEBUG "\tlpt_lebs %u\n", |
332 | le32_to_cpu(sup->lpt_lebs)); | 334 | le32_to_cpu(sup->lpt_lebs)); |
333 | printk(KERN_DEBUG "\torph_lebs %u\n", | 335 | printk(KERN_DEBUG "\torph_lebs %u\n", |
334 | le32_to_cpu(sup->orph_lebs)); | 336 | le32_to_cpu(sup->orph_lebs)); |
335 | printk(KERN_DEBUG "\tjhead_cnt %u\n", | 337 | printk(KERN_DEBUG "\tjhead_cnt %u\n", |
336 | le32_to_cpu(sup->jhead_cnt)); | 338 | le32_to_cpu(sup->jhead_cnt)); |
337 | printk(KERN_DEBUG "\tfanout %u\n", | 339 | printk(KERN_DEBUG "\tfanout %u\n", |
338 | le32_to_cpu(sup->fanout)); | 340 | le32_to_cpu(sup->fanout)); |
339 | printk(KERN_DEBUG "\tlsave_cnt %u\n", | 341 | printk(KERN_DEBUG "\tlsave_cnt %u\n", |
340 | le32_to_cpu(sup->lsave_cnt)); | 342 | le32_to_cpu(sup->lsave_cnt)); |
341 | printk(KERN_DEBUG "\tdefault_compr %u\n", | 343 | printk(KERN_DEBUG "\tdefault_compr %u\n", |
342 | (int)le16_to_cpu(sup->default_compr)); | 344 | (int)le16_to_cpu(sup->default_compr)); |
343 | printk(KERN_DEBUG "\trp_size %llu\n", | 345 | printk(KERN_DEBUG "\trp_size %llu\n", |
344 | (unsigned long long)le64_to_cpu(sup->rp_size)); | 346 | (unsigned long long)le64_to_cpu(sup->rp_size)); |
345 | printk(KERN_DEBUG "\trp_uid %u\n", | 347 | printk(KERN_DEBUG "\trp_uid %u\n", |
346 | le32_to_cpu(sup->rp_uid)); | 348 | le32_to_cpu(sup->rp_uid)); |
347 | printk(KERN_DEBUG "\trp_gid %u\n", | 349 | printk(KERN_DEBUG "\trp_gid %u\n", |
348 | le32_to_cpu(sup->rp_gid)); | 350 | le32_to_cpu(sup->rp_gid)); |
349 | printk(KERN_DEBUG "\tfmt_version %u\n", | 351 | printk(KERN_DEBUG "\tfmt_version %u\n", |
350 | le32_to_cpu(sup->fmt_version)); | 352 | le32_to_cpu(sup->fmt_version)); |
351 | printk(KERN_DEBUG "\ttime_gran %u\n", | 353 | printk(KERN_DEBUG "\ttime_gran %u\n", |
352 | le32_to_cpu(sup->time_gran)); | 354 | le32_to_cpu(sup->time_gran)); |
353 | printk(KERN_DEBUG "\tUUID %pUB\n", | 355 | printk(KERN_DEBUG "\tUUID %pUB\n", |
354 | sup->uuid); | 356 | sup->uuid); |
355 | break; | 357 | break; |
356 | } | 358 | } |
357 | case UBIFS_MST_NODE: | 359 | case UBIFS_MST_NODE: |
358 | { | 360 | { |
359 | const struct ubifs_mst_node *mst = node; | 361 | const struct ubifs_mst_node *mst = node; |
360 | 362 | ||
361 | printk(KERN_DEBUG "\thighest_inum %llu\n", | 363 | printk(KERN_DEBUG "\thighest_inum %llu\n", |
362 | (unsigned long long)le64_to_cpu(mst->highest_inum)); | 364 | (unsigned long long)le64_to_cpu(mst->highest_inum)); |
363 | printk(KERN_DEBUG "\tcommit number %llu\n", | 365 | printk(KERN_DEBUG "\tcommit number %llu\n", |
364 | (unsigned long long)le64_to_cpu(mst->cmt_no)); | 366 | (unsigned long long)le64_to_cpu(mst->cmt_no)); |
365 | printk(KERN_DEBUG "\tflags %#x\n", | 367 | printk(KERN_DEBUG "\tflags %#x\n", |
366 | le32_to_cpu(mst->flags)); | 368 | le32_to_cpu(mst->flags)); |
367 | printk(KERN_DEBUG "\tlog_lnum %u\n", | 369 | printk(KERN_DEBUG "\tlog_lnum %u\n", |
368 | le32_to_cpu(mst->log_lnum)); | 370 | le32_to_cpu(mst->log_lnum)); |
369 | printk(KERN_DEBUG "\troot_lnum %u\n", | 371 | printk(KERN_DEBUG "\troot_lnum %u\n", |
370 | le32_to_cpu(mst->root_lnum)); | 372 | le32_to_cpu(mst->root_lnum)); |
371 | printk(KERN_DEBUG "\troot_offs %u\n", | 373 | printk(KERN_DEBUG "\troot_offs %u\n", |
372 | le32_to_cpu(mst->root_offs)); | 374 | le32_to_cpu(mst->root_offs)); |
373 | printk(KERN_DEBUG "\troot_len %u\n", | 375 | printk(KERN_DEBUG "\troot_len %u\n", |
374 | le32_to_cpu(mst->root_len)); | 376 | le32_to_cpu(mst->root_len)); |
375 | printk(KERN_DEBUG "\tgc_lnum %u\n", | 377 | printk(KERN_DEBUG "\tgc_lnum %u\n", |
376 | le32_to_cpu(mst->gc_lnum)); | 378 | le32_to_cpu(mst->gc_lnum)); |
377 | printk(KERN_DEBUG "\tihead_lnum %u\n", | 379 | printk(KERN_DEBUG "\tihead_lnum %u\n", |
378 | le32_to_cpu(mst->ihead_lnum)); | 380 | le32_to_cpu(mst->ihead_lnum)); |
379 | printk(KERN_DEBUG "\tihead_offs %u\n", | 381 | printk(KERN_DEBUG "\tihead_offs %u\n", |
380 | le32_to_cpu(mst->ihead_offs)); | 382 | le32_to_cpu(mst->ihead_offs)); |
381 | printk(KERN_DEBUG "\tindex_size %llu\n", | 383 | printk(KERN_DEBUG "\tindex_size %llu\n", |
382 | (unsigned long long)le64_to_cpu(mst->index_size)); | 384 | (unsigned long long)le64_to_cpu(mst->index_size)); |
383 | printk(KERN_DEBUG "\tlpt_lnum %u\n", | 385 | printk(KERN_DEBUG "\tlpt_lnum %u\n", |
384 | le32_to_cpu(mst->lpt_lnum)); | 386 | le32_to_cpu(mst->lpt_lnum)); |
385 | printk(KERN_DEBUG "\tlpt_offs %u\n", | 387 | printk(KERN_DEBUG "\tlpt_offs %u\n", |
386 | le32_to_cpu(mst->lpt_offs)); | 388 | le32_to_cpu(mst->lpt_offs)); |
387 | printk(KERN_DEBUG "\tnhead_lnum %u\n", | 389 | printk(KERN_DEBUG "\tnhead_lnum %u\n", |
388 | le32_to_cpu(mst->nhead_lnum)); | 390 | le32_to_cpu(mst->nhead_lnum)); |
389 | printk(KERN_DEBUG "\tnhead_offs %u\n", | 391 | printk(KERN_DEBUG "\tnhead_offs %u\n", |
390 | le32_to_cpu(mst->nhead_offs)); | 392 | le32_to_cpu(mst->nhead_offs)); |
391 | printk(KERN_DEBUG "\tltab_lnum %u\n", | 393 | printk(KERN_DEBUG "\tltab_lnum %u\n", |
392 | le32_to_cpu(mst->ltab_lnum)); | 394 | le32_to_cpu(mst->ltab_lnum)); |
393 | printk(KERN_DEBUG "\tltab_offs %u\n", | 395 | printk(KERN_DEBUG "\tltab_offs %u\n", |
394 | le32_to_cpu(mst->ltab_offs)); | 396 | le32_to_cpu(mst->ltab_offs)); |
395 | printk(KERN_DEBUG "\tlsave_lnum %u\n", | 397 | printk(KERN_DEBUG "\tlsave_lnum %u\n", |
396 | le32_to_cpu(mst->lsave_lnum)); | 398 | le32_to_cpu(mst->lsave_lnum)); |
397 | printk(KERN_DEBUG "\tlsave_offs %u\n", | 399 | printk(KERN_DEBUG "\tlsave_offs %u\n", |
398 | le32_to_cpu(mst->lsave_offs)); | 400 | le32_to_cpu(mst->lsave_offs)); |
399 | printk(KERN_DEBUG "\tlscan_lnum %u\n", | 401 | printk(KERN_DEBUG "\tlscan_lnum %u\n", |
400 | le32_to_cpu(mst->lscan_lnum)); | 402 | le32_to_cpu(mst->lscan_lnum)); |
401 | printk(KERN_DEBUG "\tleb_cnt %u\n", | 403 | printk(KERN_DEBUG "\tleb_cnt %u\n", |
402 | le32_to_cpu(mst->leb_cnt)); | 404 | le32_to_cpu(mst->leb_cnt)); |
403 | printk(KERN_DEBUG "\tempty_lebs %u\n", | 405 | printk(KERN_DEBUG "\tempty_lebs %u\n", |
404 | le32_to_cpu(mst->empty_lebs)); | 406 | le32_to_cpu(mst->empty_lebs)); |
405 | printk(KERN_DEBUG "\tidx_lebs %u\n", | 407 | printk(KERN_DEBUG "\tidx_lebs %u\n", |
406 | le32_to_cpu(mst->idx_lebs)); | 408 | le32_to_cpu(mst->idx_lebs)); |
407 | printk(KERN_DEBUG "\ttotal_free %llu\n", | 409 | printk(KERN_DEBUG "\ttotal_free %llu\n", |
408 | (unsigned long long)le64_to_cpu(mst->total_free)); | 410 | (unsigned long long)le64_to_cpu(mst->total_free)); |
409 | printk(KERN_DEBUG "\ttotal_dirty %llu\n", | 411 | printk(KERN_DEBUG "\ttotal_dirty %llu\n", |
410 | (unsigned long long)le64_to_cpu(mst->total_dirty)); | 412 | (unsigned long long)le64_to_cpu(mst->total_dirty)); |
411 | printk(KERN_DEBUG "\ttotal_used %llu\n", | 413 | printk(KERN_DEBUG "\ttotal_used %llu\n", |
412 | (unsigned long long)le64_to_cpu(mst->total_used)); | 414 | (unsigned long long)le64_to_cpu(mst->total_used)); |
413 | printk(KERN_DEBUG "\ttotal_dead %llu\n", | 415 | printk(KERN_DEBUG "\ttotal_dead %llu\n", |
414 | (unsigned long long)le64_to_cpu(mst->total_dead)); | 416 | (unsigned long long)le64_to_cpu(mst->total_dead)); |
415 | printk(KERN_DEBUG "\ttotal_dark %llu\n", | 417 | printk(KERN_DEBUG "\ttotal_dark %llu\n", |
416 | (unsigned long long)le64_to_cpu(mst->total_dark)); | 418 | (unsigned long long)le64_to_cpu(mst->total_dark)); |
417 | break; | 419 | break; |
418 | } | 420 | } |
419 | case UBIFS_REF_NODE: | 421 | case UBIFS_REF_NODE: |
420 | { | 422 | { |
421 | const struct ubifs_ref_node *ref = node; | 423 | const struct ubifs_ref_node *ref = node; |
422 | 424 | ||
423 | printk(KERN_DEBUG "\tlnum %u\n", | 425 | printk(KERN_DEBUG "\tlnum %u\n", |
424 | le32_to_cpu(ref->lnum)); | 426 | le32_to_cpu(ref->lnum)); |
425 | printk(KERN_DEBUG "\toffs %u\n", | 427 | printk(KERN_DEBUG "\toffs %u\n", |
426 | le32_to_cpu(ref->offs)); | 428 | le32_to_cpu(ref->offs)); |
427 | printk(KERN_DEBUG "\tjhead %u\n", | 429 | printk(KERN_DEBUG "\tjhead %u\n", |
428 | le32_to_cpu(ref->jhead)); | 430 | le32_to_cpu(ref->jhead)); |
429 | break; | 431 | break; |
430 | } | 432 | } |
431 | case UBIFS_INO_NODE: | 433 | case UBIFS_INO_NODE: |
432 | { | 434 | { |
433 | const struct ubifs_ino_node *ino = node; | 435 | const struct ubifs_ino_node *ino = node; |
434 | 436 | ||
435 | key_read(c, &ino->key, &key); | 437 | key_read(c, &ino->key, &key); |
436 | printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); | 438 | printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); |
437 | printk(KERN_DEBUG "\tcreat_sqnum %llu\n", | 439 | printk(KERN_DEBUG "\tcreat_sqnum %llu\n", |
438 | (unsigned long long)le64_to_cpu(ino->creat_sqnum)); | 440 | (unsigned long long)le64_to_cpu(ino->creat_sqnum)); |
439 | printk(KERN_DEBUG "\tsize %llu\n", | 441 | printk(KERN_DEBUG "\tsize %llu\n", |
440 | (unsigned long long)le64_to_cpu(ino->size)); | 442 | (unsigned long long)le64_to_cpu(ino->size)); |
441 | printk(KERN_DEBUG "\tnlink %u\n", | 443 | printk(KERN_DEBUG "\tnlink %u\n", |
442 | le32_to_cpu(ino->nlink)); | 444 | le32_to_cpu(ino->nlink)); |
443 | printk(KERN_DEBUG "\tatime %lld.%u\n", | 445 | printk(KERN_DEBUG "\tatime %lld.%u\n", |
444 | (long long)le64_to_cpu(ino->atime_sec), | 446 | (long long)le64_to_cpu(ino->atime_sec), |
445 | le32_to_cpu(ino->atime_nsec)); | 447 | le32_to_cpu(ino->atime_nsec)); |
446 | printk(KERN_DEBUG "\tmtime %lld.%u\n", | 448 | printk(KERN_DEBUG "\tmtime %lld.%u\n", |
447 | (long long)le64_to_cpu(ino->mtime_sec), | 449 | (long long)le64_to_cpu(ino->mtime_sec), |
448 | le32_to_cpu(ino->mtime_nsec)); | 450 | le32_to_cpu(ino->mtime_nsec)); |
449 | printk(KERN_DEBUG "\tctime %lld.%u\n", | 451 | printk(KERN_DEBUG "\tctime %lld.%u\n", |
450 | (long long)le64_to_cpu(ino->ctime_sec), | 452 | (long long)le64_to_cpu(ino->ctime_sec), |
451 | le32_to_cpu(ino->ctime_nsec)); | 453 | le32_to_cpu(ino->ctime_nsec)); |
452 | printk(KERN_DEBUG "\tuid %u\n", | 454 | printk(KERN_DEBUG "\tuid %u\n", |
453 | le32_to_cpu(ino->uid)); | 455 | le32_to_cpu(ino->uid)); |
454 | printk(KERN_DEBUG "\tgid %u\n", | 456 | printk(KERN_DEBUG "\tgid %u\n", |
455 | le32_to_cpu(ino->gid)); | 457 | le32_to_cpu(ino->gid)); |
456 | printk(KERN_DEBUG "\tmode %u\n", | 458 | printk(KERN_DEBUG "\tmode %u\n", |
457 | le32_to_cpu(ino->mode)); | 459 | le32_to_cpu(ino->mode)); |
458 | printk(KERN_DEBUG "\tflags %#x\n", | 460 | printk(KERN_DEBUG "\tflags %#x\n", |
459 | le32_to_cpu(ino->flags)); | 461 | le32_to_cpu(ino->flags)); |
460 | printk(KERN_DEBUG "\txattr_cnt %u\n", | 462 | printk(KERN_DEBUG "\txattr_cnt %u\n", |
461 | le32_to_cpu(ino->xattr_cnt)); | 463 | le32_to_cpu(ino->xattr_cnt)); |
462 | printk(KERN_DEBUG "\txattr_size %u\n", | 464 | printk(KERN_DEBUG "\txattr_size %u\n", |
463 | le32_to_cpu(ino->xattr_size)); | 465 | le32_to_cpu(ino->xattr_size)); |
464 | printk(KERN_DEBUG "\txattr_names %u\n", | 466 | printk(KERN_DEBUG "\txattr_names %u\n", |
465 | le32_to_cpu(ino->xattr_names)); | 467 | le32_to_cpu(ino->xattr_names)); |
466 | printk(KERN_DEBUG "\tcompr_type %#x\n", | 468 | printk(KERN_DEBUG "\tcompr_type %#x\n", |
467 | (int)le16_to_cpu(ino->compr_type)); | 469 | (int)le16_to_cpu(ino->compr_type)); |
468 | printk(KERN_DEBUG "\tdata len %u\n", | 470 | printk(KERN_DEBUG "\tdata len %u\n", |
469 | le32_to_cpu(ino->data_len)); | 471 | le32_to_cpu(ino->data_len)); |
470 | break; | 472 | break; |
471 | } | 473 | } |
472 | case UBIFS_DENT_NODE: | 474 | case UBIFS_DENT_NODE: |
473 | case UBIFS_XENT_NODE: | 475 | case UBIFS_XENT_NODE: |
474 | { | 476 | { |
475 | const struct ubifs_dent_node *dent = node; | 477 | const struct ubifs_dent_node *dent = node; |
476 | int nlen = le16_to_cpu(dent->nlen); | 478 | int nlen = le16_to_cpu(dent->nlen); |
477 | 479 | ||
478 | key_read(c, &dent->key, &key); | 480 | key_read(c, &dent->key, &key); |
479 | printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); | 481 | printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); |
480 | printk(KERN_DEBUG "\tinum %llu\n", | 482 | printk(KERN_DEBUG "\tinum %llu\n", |
481 | (unsigned long long)le64_to_cpu(dent->inum)); | 483 | (unsigned long long)le64_to_cpu(dent->inum)); |
482 | printk(KERN_DEBUG "\ttype %d\n", (int)dent->type); | 484 | printk(KERN_DEBUG "\ttype %d\n", (int)dent->type); |
483 | printk(KERN_DEBUG "\tnlen %d\n", nlen); | 485 | printk(KERN_DEBUG "\tnlen %d\n", nlen); |
484 | printk(KERN_DEBUG "\tname "); | 486 | printk(KERN_DEBUG "\tname "); |
485 | 487 | ||
486 | if (nlen > UBIFS_MAX_NLEN) | 488 | if (nlen > UBIFS_MAX_NLEN) |
487 | printk(KERN_DEBUG "(bad name length, not printing, " | 489 | printk(KERN_DEBUG "(bad name length, not printing, " |
488 | "bad or corrupted node)"); | 490 | "bad or corrupted node)"); |
489 | else { | 491 | else { |
490 | for (i = 0; i < nlen && dent->name[i]; i++) | 492 | for (i = 0; i < nlen && dent->name[i]; i++) |
491 | printk(KERN_CONT "%c", dent->name[i]); | 493 | printk(KERN_CONT "%c", dent->name[i]); |
492 | } | 494 | } |
493 | printk(KERN_CONT "\n"); | 495 | printk(KERN_CONT "\n"); |
494 | 496 | ||
495 | break; | 497 | break; |
496 | } | 498 | } |
497 | case UBIFS_DATA_NODE: | 499 | case UBIFS_DATA_NODE: |
498 | { | 500 | { |
499 | const struct ubifs_data_node *dn = node; | 501 | const struct ubifs_data_node *dn = node; |
500 | int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ; | 502 | int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ; |
501 | 503 | ||
502 | key_read(c, &dn->key, &key); | 504 | key_read(c, &dn->key, &key); |
503 | printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); | 505 | printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); |
504 | printk(KERN_DEBUG "\tsize %u\n", | 506 | printk(KERN_DEBUG "\tsize %u\n", |
505 | le32_to_cpu(dn->size)); | 507 | le32_to_cpu(dn->size)); |
506 | printk(KERN_DEBUG "\tcompr_typ %d\n", | 508 | printk(KERN_DEBUG "\tcompr_typ %d\n", |
507 | (int)le16_to_cpu(dn->compr_type)); | 509 | (int)le16_to_cpu(dn->compr_type)); |
508 | printk(KERN_DEBUG "\tdata size %d\n", | 510 | printk(KERN_DEBUG "\tdata size %d\n", |
509 | dlen); | 511 | dlen); |
510 | printk(KERN_DEBUG "\tdata:\n"); | 512 | printk(KERN_DEBUG "\tdata:\n"); |
511 | print_hex_dump(KERN_DEBUG, "\t", DUMP_PREFIX_OFFSET, 32, 1, | 513 | print_hex_dump(KERN_DEBUG, "\t", DUMP_PREFIX_OFFSET, 32, 1, |
512 | (void *)&dn->data, dlen, 0); | 514 | (void *)&dn->data, dlen, 0); |
513 | break; | 515 | break; |
514 | } | 516 | } |
515 | case UBIFS_TRUN_NODE: | 517 | case UBIFS_TRUN_NODE: |
516 | { | 518 | { |
517 | const struct ubifs_trun_node *trun = node; | 519 | const struct ubifs_trun_node *trun = node; |
518 | 520 | ||
519 | printk(KERN_DEBUG "\tinum %u\n", | 521 | printk(KERN_DEBUG "\tinum %u\n", |
520 | le32_to_cpu(trun->inum)); | 522 | le32_to_cpu(trun->inum)); |
521 | printk(KERN_DEBUG "\told_size %llu\n", | 523 | printk(KERN_DEBUG "\told_size %llu\n", |
522 | (unsigned long long)le64_to_cpu(trun->old_size)); | 524 | (unsigned long long)le64_to_cpu(trun->old_size)); |
523 | printk(KERN_DEBUG "\tnew_size %llu\n", | 525 | printk(KERN_DEBUG "\tnew_size %llu\n", |
524 | (unsigned long long)le64_to_cpu(trun->new_size)); | 526 | (unsigned long long)le64_to_cpu(trun->new_size)); |
525 | break; | 527 | break; |
526 | } | 528 | } |
527 | case UBIFS_IDX_NODE: | 529 | case UBIFS_IDX_NODE: |
528 | { | 530 | { |
529 | const struct ubifs_idx_node *idx = node; | 531 | const struct ubifs_idx_node *idx = node; |
530 | 532 | ||
531 | n = le16_to_cpu(idx->child_cnt); | 533 | n = le16_to_cpu(idx->child_cnt); |
532 | printk(KERN_DEBUG "\tchild_cnt %d\n", n); | 534 | printk(KERN_DEBUG "\tchild_cnt %d\n", n); |
533 | printk(KERN_DEBUG "\tlevel %d\n", | 535 | printk(KERN_DEBUG "\tlevel %d\n", |
534 | (int)le16_to_cpu(idx->level)); | 536 | (int)le16_to_cpu(idx->level)); |
535 | printk(KERN_DEBUG "\tBranches:\n"); | 537 | printk(KERN_DEBUG "\tBranches:\n"); |
536 | 538 | ||
537 | for (i = 0; i < n && i < c->fanout - 1; i++) { | 539 | for (i = 0; i < n && i < c->fanout - 1; i++) { |
538 | const struct ubifs_branch *br; | 540 | const struct ubifs_branch *br; |
539 | 541 | ||
540 | br = ubifs_idx_branch(c, idx, i); | 542 | br = ubifs_idx_branch(c, idx, i); |
541 | key_read(c, &br->key, &key); | 543 | key_read(c, &br->key, &key); |
542 | printk(KERN_DEBUG "\t%d: LEB %d:%d len %d key %s\n", | 544 | printk(KERN_DEBUG "\t%d: LEB %d:%d len %d key %s\n", |
543 | i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs), | 545 | i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs), |
544 | le32_to_cpu(br->len), DBGKEY(&key)); | 546 | le32_to_cpu(br->len), DBGKEY(&key)); |
545 | } | 547 | } |
546 | break; | 548 | break; |
547 | } | 549 | } |
548 | case UBIFS_CS_NODE: | 550 | case UBIFS_CS_NODE: |
549 | break; | 551 | break; |
550 | case UBIFS_ORPH_NODE: | 552 | case UBIFS_ORPH_NODE: |
551 | { | 553 | { |
552 | const struct ubifs_orph_node *orph = node; | 554 | const struct ubifs_orph_node *orph = node; |
553 | 555 | ||
554 | printk(KERN_DEBUG "\tcommit number %llu\n", | 556 | printk(KERN_DEBUG "\tcommit number %llu\n", |
555 | (unsigned long long) | 557 | (unsigned long long) |
556 | le64_to_cpu(orph->cmt_no) & LLONG_MAX); | 558 | le64_to_cpu(orph->cmt_no) & LLONG_MAX); |
557 | printk(KERN_DEBUG "\tlast node flag %llu\n", | 559 | printk(KERN_DEBUG "\tlast node flag %llu\n", |
558 | (unsigned long long)(le64_to_cpu(orph->cmt_no)) >> 63); | 560 | (unsigned long long)(le64_to_cpu(orph->cmt_no)) >> 63); |
559 | n = (le32_to_cpu(ch->len) - UBIFS_ORPH_NODE_SZ) >> 3; | 561 | n = (le32_to_cpu(ch->len) - UBIFS_ORPH_NODE_SZ) >> 3; |
560 | printk(KERN_DEBUG "\t%d orphan inode numbers:\n", n); | 562 | printk(KERN_DEBUG "\t%d orphan inode numbers:\n", n); |
561 | for (i = 0; i < n; i++) | 563 | for (i = 0; i < n; i++) |
562 | printk(KERN_DEBUG "\t ino %llu\n", | 564 | printk(KERN_DEBUG "\t ino %llu\n", |
563 | (unsigned long long)le64_to_cpu(orph->inos[i])); | 565 | (unsigned long long)le64_to_cpu(orph->inos[i])); |
564 | break; | 566 | break; |
565 | } | 567 | } |
566 | default: | 568 | default: |
567 | printk(KERN_DEBUG "node type %d was not recognized\n", | 569 | printk(KERN_DEBUG "node type %d was not recognized\n", |
568 | (int)ch->node_type); | 570 | (int)ch->node_type); |
569 | } | 571 | } |
570 | spin_unlock(&dbg_lock); | 572 | spin_unlock(&dbg_lock); |
571 | } | 573 | } |
572 | 574 | ||
573 | void dbg_dump_budget_req(const struct ubifs_budget_req *req) | 575 | void dbg_dump_budget_req(const struct ubifs_budget_req *req) |
574 | { | 576 | { |
575 | spin_lock(&dbg_lock); | 577 | spin_lock(&dbg_lock); |
576 | printk(KERN_DEBUG "Budgeting request: new_ino %d, dirtied_ino %d\n", | 578 | printk(KERN_DEBUG "Budgeting request: new_ino %d, dirtied_ino %d\n", |
577 | req->new_ino, req->dirtied_ino); | 579 | req->new_ino, req->dirtied_ino); |
578 | printk(KERN_DEBUG "\tnew_ino_d %d, dirtied_ino_d %d\n", | 580 | printk(KERN_DEBUG "\tnew_ino_d %d, dirtied_ino_d %d\n", |
579 | req->new_ino_d, req->dirtied_ino_d); | 581 | req->new_ino_d, req->dirtied_ino_d); |
580 | printk(KERN_DEBUG "\tnew_page %d, dirtied_page %d\n", | 582 | printk(KERN_DEBUG "\tnew_page %d, dirtied_page %d\n", |
581 | req->new_page, req->dirtied_page); | 583 | req->new_page, req->dirtied_page); |
582 | printk(KERN_DEBUG "\tnew_dent %d, mod_dent %d\n", | 584 | printk(KERN_DEBUG "\tnew_dent %d, mod_dent %d\n", |
583 | req->new_dent, req->mod_dent); | 585 | req->new_dent, req->mod_dent); |
584 | printk(KERN_DEBUG "\tidx_growth %d\n", req->idx_growth); | 586 | printk(KERN_DEBUG "\tidx_growth %d\n", req->idx_growth); |
585 | printk(KERN_DEBUG "\tdata_growth %d dd_growth %d\n", | 587 | printk(KERN_DEBUG "\tdata_growth %d dd_growth %d\n", |
586 | req->data_growth, req->dd_growth); | 588 | req->data_growth, req->dd_growth); |
587 | spin_unlock(&dbg_lock); | 589 | spin_unlock(&dbg_lock); |
588 | } | 590 | } |
589 | 591 | ||
590 | void dbg_dump_lstats(const struct ubifs_lp_stats *lst) | 592 | void dbg_dump_lstats(const struct ubifs_lp_stats *lst) |
591 | { | 593 | { |
592 | spin_lock(&dbg_lock); | 594 | spin_lock(&dbg_lock); |
593 | printk(KERN_DEBUG "(pid %d) Lprops statistics: empty_lebs %d, " | 595 | printk(KERN_DEBUG "(pid %d) Lprops statistics: empty_lebs %d, " |
594 | "idx_lebs %d\n", current->pid, lst->empty_lebs, lst->idx_lebs); | 596 | "idx_lebs %d\n", current->pid, lst->empty_lebs, lst->idx_lebs); |
595 | printk(KERN_DEBUG "\ttaken_empty_lebs %d, total_free %lld, " | 597 | printk(KERN_DEBUG "\ttaken_empty_lebs %d, total_free %lld, " |
596 | "total_dirty %lld\n", lst->taken_empty_lebs, lst->total_free, | 598 | "total_dirty %lld\n", lst->taken_empty_lebs, lst->total_free, |
597 | lst->total_dirty); | 599 | lst->total_dirty); |
598 | printk(KERN_DEBUG "\ttotal_used %lld, total_dark %lld, " | 600 | printk(KERN_DEBUG "\ttotal_used %lld, total_dark %lld, " |
599 | "total_dead %lld\n", lst->total_used, lst->total_dark, | 601 | "total_dead %lld\n", lst->total_used, lst->total_dark, |
600 | lst->total_dead); | 602 | lst->total_dead); |
601 | spin_unlock(&dbg_lock); | 603 | spin_unlock(&dbg_lock); |
602 | } | 604 | } |
603 | 605 | ||
604 | void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi) | 606 | void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi) |
605 | { | 607 | { |
606 | int i; | 608 | int i; |
607 | struct rb_node *rb; | 609 | struct rb_node *rb; |
608 | struct ubifs_bud *bud; | 610 | struct ubifs_bud *bud; |
609 | struct ubifs_gced_idx_leb *idx_gc; | 611 | struct ubifs_gced_idx_leb *idx_gc; |
610 | long long available, outstanding, free; | 612 | long long available, outstanding, free; |
611 | 613 | ||
612 | spin_lock(&c->space_lock); | 614 | spin_lock(&c->space_lock); |
613 | spin_lock(&dbg_lock); | 615 | spin_lock(&dbg_lock); |
614 | printk(KERN_DEBUG "(pid %d) Budgeting info: data budget sum %lld, " | 616 | printk(KERN_DEBUG "(pid %d) Budgeting info: data budget sum %lld, " |
615 | "total budget sum %lld\n", current->pid, | 617 | "total budget sum %lld\n", current->pid, |
616 | bi->data_growth + bi->dd_growth, | 618 | bi->data_growth + bi->dd_growth, |
617 | bi->data_growth + bi->dd_growth + bi->idx_growth); | 619 | bi->data_growth + bi->dd_growth + bi->idx_growth); |
618 | printk(KERN_DEBUG "\tbudg_data_growth %lld, budg_dd_growth %lld, " | 620 | printk(KERN_DEBUG "\tbudg_data_growth %lld, budg_dd_growth %lld, " |
619 | "budg_idx_growth %lld\n", bi->data_growth, bi->dd_growth, | 621 | "budg_idx_growth %lld\n", bi->data_growth, bi->dd_growth, |
620 | bi->idx_growth); | 622 | bi->idx_growth); |
621 | printk(KERN_DEBUG "\tmin_idx_lebs %d, old_idx_sz %llu, " | 623 | printk(KERN_DEBUG "\tmin_idx_lebs %d, old_idx_sz %llu, " |
622 | "uncommitted_idx %lld\n", bi->min_idx_lebs, bi->old_idx_sz, | 624 | "uncommitted_idx %lld\n", bi->min_idx_lebs, bi->old_idx_sz, |
623 | bi->uncommitted_idx); | 625 | bi->uncommitted_idx); |
624 | printk(KERN_DEBUG "\tpage_budget %d, inode_budget %d, dent_budget %d\n", | 626 | printk(KERN_DEBUG "\tpage_budget %d, inode_budget %d, dent_budget %d\n", |
625 | bi->page_budget, bi->inode_budget, bi->dent_budget); | 627 | bi->page_budget, bi->inode_budget, bi->dent_budget); |
626 | printk(KERN_DEBUG "\tnospace %u, nospace_rp %u\n", | 628 | printk(KERN_DEBUG "\tnospace %u, nospace_rp %u\n", |
627 | bi->nospace, bi->nospace_rp); | 629 | bi->nospace, bi->nospace_rp); |
628 | printk(KERN_DEBUG "\tdark_wm %d, dead_wm %d, max_idx_node_sz %d\n", | 630 | printk(KERN_DEBUG "\tdark_wm %d, dead_wm %d, max_idx_node_sz %d\n", |
629 | c->dark_wm, c->dead_wm, c->max_idx_node_sz); | 631 | c->dark_wm, c->dead_wm, c->max_idx_node_sz); |
630 | 632 | ||
631 | if (bi != &c->bi) | 633 | if (bi != &c->bi) |
632 | /* | 634 | /* |
633 | * If we are dumping saved budgeting data, do not print | 635 | * If we are dumping saved budgeting data, do not print |
634 | * additional information which is about the current state, not | 636 | * additional information which is about the current state, not |
635 | * the old one which corresponded to the saved budgeting data. | 637 | * the old one which corresponded to the saved budgeting data. |
636 | */ | 638 | */ |
637 | goto out_unlock; | 639 | goto out_unlock; |
638 | 640 | ||
639 | printk(KERN_DEBUG "\tfreeable_cnt %d, calc_idx_sz %lld, idx_gc_cnt %d\n", | 641 | printk(KERN_DEBUG "\tfreeable_cnt %d, calc_idx_sz %lld, idx_gc_cnt %d\n", |
640 | c->freeable_cnt, c->calc_idx_sz, c->idx_gc_cnt); | 642 | c->freeable_cnt, c->calc_idx_sz, c->idx_gc_cnt); |
641 | printk(KERN_DEBUG "\tdirty_pg_cnt %ld, dirty_zn_cnt %ld, " | 643 | printk(KERN_DEBUG "\tdirty_pg_cnt %ld, dirty_zn_cnt %ld, " |
642 | "clean_zn_cnt %ld\n", atomic_long_read(&c->dirty_pg_cnt), | 644 | "clean_zn_cnt %ld\n", atomic_long_read(&c->dirty_pg_cnt), |
643 | atomic_long_read(&c->dirty_zn_cnt), | 645 | atomic_long_read(&c->dirty_zn_cnt), |
644 | atomic_long_read(&c->clean_zn_cnt)); | 646 | atomic_long_read(&c->clean_zn_cnt)); |
645 | printk(KERN_DEBUG "\tgc_lnum %d, ihead_lnum %d\n", | 647 | printk(KERN_DEBUG "\tgc_lnum %d, ihead_lnum %d\n", |
646 | c->gc_lnum, c->ihead_lnum); | 648 | c->gc_lnum, c->ihead_lnum); |
647 | 649 | ||
648 | /* If we are in R/O mode, journal heads do not exist */ | 650 | /* If we are in R/O mode, journal heads do not exist */ |
649 | if (c->jheads) | 651 | if (c->jheads) |
650 | for (i = 0; i < c->jhead_cnt; i++) | 652 | for (i = 0; i < c->jhead_cnt; i++) |
651 | printk(KERN_DEBUG "\tjhead %s\t LEB %d\n", | 653 | printk(KERN_DEBUG "\tjhead %s\t LEB %d\n", |
652 | dbg_jhead(c->jheads[i].wbuf.jhead), | 654 | dbg_jhead(c->jheads[i].wbuf.jhead), |
653 | c->jheads[i].wbuf.lnum); | 655 | c->jheads[i].wbuf.lnum); |
654 | for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) { | 656 | for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) { |
655 | bud = rb_entry(rb, struct ubifs_bud, rb); | 657 | bud = rb_entry(rb, struct ubifs_bud, rb); |
656 | printk(KERN_DEBUG "\tbud LEB %d\n", bud->lnum); | 658 | printk(KERN_DEBUG "\tbud LEB %d\n", bud->lnum); |
657 | } | 659 | } |
658 | list_for_each_entry(bud, &c->old_buds, list) | 660 | list_for_each_entry(bud, &c->old_buds, list) |
659 | printk(KERN_DEBUG "\told bud LEB %d\n", bud->lnum); | 661 | printk(KERN_DEBUG "\told bud LEB %d\n", bud->lnum); |
660 | list_for_each_entry(idx_gc, &c->idx_gc, list) | 662 | list_for_each_entry(idx_gc, &c->idx_gc, list) |
661 | printk(KERN_DEBUG "\tGC'ed idx LEB %d unmap %d\n", | 663 | printk(KERN_DEBUG "\tGC'ed idx LEB %d unmap %d\n", |
662 | idx_gc->lnum, idx_gc->unmap); | 664 | idx_gc->lnum, idx_gc->unmap); |
663 | printk(KERN_DEBUG "\tcommit state %d\n", c->cmt_state); | 665 | printk(KERN_DEBUG "\tcommit state %d\n", c->cmt_state); |
664 | 666 | ||
665 | /* Print budgeting predictions */ | 667 | /* Print budgeting predictions */ |
666 | available = ubifs_calc_available(c, c->bi.min_idx_lebs); | 668 | available = ubifs_calc_available(c, c->bi.min_idx_lebs); |
667 | outstanding = c->bi.data_growth + c->bi.dd_growth; | 669 | outstanding = c->bi.data_growth + c->bi.dd_growth; |
668 | free = ubifs_get_free_space_nolock(c); | 670 | free = ubifs_get_free_space_nolock(c); |
669 | printk(KERN_DEBUG "Budgeting predictions:\n"); | 671 | printk(KERN_DEBUG "Budgeting predictions:\n"); |
670 | printk(KERN_DEBUG "\tavailable: %lld, outstanding %lld, free %lld\n", | 672 | printk(KERN_DEBUG "\tavailable: %lld, outstanding %lld, free %lld\n", |
671 | available, outstanding, free); | 673 | available, outstanding, free); |
672 | out_unlock: | 674 | out_unlock: |
673 | spin_unlock(&dbg_lock); | 675 | spin_unlock(&dbg_lock); |
674 | spin_unlock(&c->space_lock); | 676 | spin_unlock(&c->space_lock); |
675 | } | 677 | } |
676 | 678 | ||
677 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) | 679 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) |
678 | { | 680 | { |
679 | int i, spc, dark = 0, dead = 0; | 681 | int i, spc, dark = 0, dead = 0; |
680 | struct rb_node *rb; | 682 | struct rb_node *rb; |
681 | struct ubifs_bud *bud; | 683 | struct ubifs_bud *bud; |
682 | 684 | ||
683 | spc = lp->free + lp->dirty; | 685 | spc = lp->free + lp->dirty; |
684 | if (spc < c->dead_wm) | 686 | if (spc < c->dead_wm) |
685 | dead = spc; | 687 | dead = spc; |
686 | else | 688 | else |
687 | dark = ubifs_calc_dark(c, spc); | 689 | dark = ubifs_calc_dark(c, spc); |
688 | 690 | ||
689 | if (lp->flags & LPROPS_INDEX) | 691 | if (lp->flags & LPROPS_INDEX) |
690 | printk(KERN_DEBUG "LEB %-7d free %-8d dirty %-8d used %-8d " | 692 | printk(KERN_DEBUG "LEB %-7d free %-8d dirty %-8d used %-8d " |
691 | "free + dirty %-8d flags %#x (", lp->lnum, lp->free, | 693 | "free + dirty %-8d flags %#x (", lp->lnum, lp->free, |
692 | lp->dirty, c->leb_size - spc, spc, lp->flags); | 694 | lp->dirty, c->leb_size - spc, spc, lp->flags); |
693 | else | 695 | else |
694 | printk(KERN_DEBUG "LEB %-7d free %-8d dirty %-8d used %-8d " | 696 | printk(KERN_DEBUG "LEB %-7d free %-8d dirty %-8d used %-8d " |
695 | "free + dirty %-8d dark %-4d dead %-4d nodes fit %-3d " | 697 | "free + dirty %-8d dark %-4d dead %-4d nodes fit %-3d " |
696 | "flags %#-4x (", lp->lnum, lp->free, lp->dirty, | 698 | "flags %#-4x (", lp->lnum, lp->free, lp->dirty, |
697 | c->leb_size - spc, spc, dark, dead, | 699 | c->leb_size - spc, spc, dark, dead, |
698 | (int)(spc / UBIFS_MAX_NODE_SZ), lp->flags); | 700 | (int)(spc / UBIFS_MAX_NODE_SZ), lp->flags); |
699 | 701 | ||
700 | if (lp->flags & LPROPS_TAKEN) { | 702 | if (lp->flags & LPROPS_TAKEN) { |
701 | if (lp->flags & LPROPS_INDEX) | 703 | if (lp->flags & LPROPS_INDEX) |
702 | printk(KERN_CONT "index, taken"); | 704 | printk(KERN_CONT "index, taken"); |
703 | else | 705 | else |
704 | printk(KERN_CONT "taken"); | 706 | printk(KERN_CONT "taken"); |
705 | } else { | 707 | } else { |
706 | const char *s; | 708 | const char *s; |
707 | 709 | ||
708 | if (lp->flags & LPROPS_INDEX) { | 710 | if (lp->flags & LPROPS_INDEX) { |
709 | switch (lp->flags & LPROPS_CAT_MASK) { | 711 | switch (lp->flags & LPROPS_CAT_MASK) { |
710 | case LPROPS_DIRTY_IDX: | 712 | case LPROPS_DIRTY_IDX: |
711 | s = "dirty index"; | 713 | s = "dirty index"; |
712 | break; | 714 | break; |
713 | case LPROPS_FRDI_IDX: | 715 | case LPROPS_FRDI_IDX: |
714 | s = "freeable index"; | 716 | s = "freeable index"; |
715 | break; | 717 | break; |
716 | default: | 718 | default: |
717 | s = "index"; | 719 | s = "index"; |
718 | } | 720 | } |
719 | } else { | 721 | } else { |
720 | switch (lp->flags & LPROPS_CAT_MASK) { | 722 | switch (lp->flags & LPROPS_CAT_MASK) { |
721 | case LPROPS_UNCAT: | 723 | case LPROPS_UNCAT: |
722 | s = "not categorized"; | 724 | s = "not categorized"; |
723 | break; | 725 | break; |
724 | case LPROPS_DIRTY: | 726 | case LPROPS_DIRTY: |
725 | s = "dirty"; | 727 | s = "dirty"; |
726 | break; | 728 | break; |
727 | case LPROPS_FREE: | 729 | case LPROPS_FREE: |
728 | s = "free"; | 730 | s = "free"; |
729 | break; | 731 | break; |
730 | case LPROPS_EMPTY: | 732 | case LPROPS_EMPTY: |
731 | s = "empty"; | 733 | s = "empty"; |
732 | break; | 734 | break; |
733 | case LPROPS_FREEABLE: | 735 | case LPROPS_FREEABLE: |
734 | s = "freeable"; | 736 | s = "freeable"; |
735 | break; | 737 | break; |
736 | default: | 738 | default: |
737 | s = NULL; | 739 | s = NULL; |
738 | break; | 740 | break; |
739 | } | 741 | } |
740 | } | 742 | } |
741 | printk(KERN_CONT "%s", s); | 743 | printk(KERN_CONT "%s", s); |
742 | } | 744 | } |
743 | 745 | ||
744 | for (rb = rb_first((struct rb_root *)&c->buds); rb; rb = rb_next(rb)) { | 746 | for (rb = rb_first((struct rb_root *)&c->buds); rb; rb = rb_next(rb)) { |
745 | bud = rb_entry(rb, struct ubifs_bud, rb); | 747 | bud = rb_entry(rb, struct ubifs_bud, rb); |
746 | if (bud->lnum == lp->lnum) { | 748 | if (bud->lnum == lp->lnum) { |
747 | int head = 0; | 749 | int head = 0; |
748 | for (i = 0; i < c->jhead_cnt; i++) { | 750 | for (i = 0; i < c->jhead_cnt; i++) { |
749 | /* | 751 | /* |
750 | * Note, if we are in R/O mode or in the middle | 752 | * Note, if we are in R/O mode or in the middle |
751 | * of mounting/re-mounting, the write-buffers do | 753 | * of mounting/re-mounting, the write-buffers do |
752 | * not exist. | 754 | * not exist. |
753 | */ | 755 | */ |
754 | if (c->jheads && | 756 | if (c->jheads && |
755 | lp->lnum == c->jheads[i].wbuf.lnum) { | 757 | lp->lnum == c->jheads[i].wbuf.lnum) { |
756 | printk(KERN_CONT ", jhead %s", | 758 | printk(KERN_CONT ", jhead %s", |
757 | dbg_jhead(i)); | 759 | dbg_jhead(i)); |
758 | head = 1; | 760 | head = 1; |
759 | } | 761 | } |
760 | } | 762 | } |
761 | if (!head) | 763 | if (!head) |
762 | printk(KERN_CONT ", bud of jhead %s", | 764 | printk(KERN_CONT ", bud of jhead %s", |
763 | dbg_jhead(bud->jhead)); | 765 | dbg_jhead(bud->jhead)); |
764 | } | 766 | } |
765 | } | 767 | } |
766 | if (lp->lnum == c->gc_lnum) | 768 | if (lp->lnum == c->gc_lnum) |
767 | printk(KERN_CONT ", GC LEB"); | 769 | printk(KERN_CONT ", GC LEB"); |
768 | printk(KERN_CONT ")\n"); | 770 | printk(KERN_CONT ")\n"); |
769 | } | 771 | } |
770 | 772 | ||
771 | void dbg_dump_lprops(struct ubifs_info *c) | 773 | void dbg_dump_lprops(struct ubifs_info *c) |
772 | { | 774 | { |
773 | int lnum, err; | 775 | int lnum, err; |
774 | struct ubifs_lprops lp; | 776 | struct ubifs_lprops lp; |
775 | struct ubifs_lp_stats lst; | 777 | struct ubifs_lp_stats lst; |
776 | 778 | ||
777 | printk(KERN_DEBUG "(pid %d) start dumping LEB properties\n", | 779 | printk(KERN_DEBUG "(pid %d) start dumping LEB properties\n", |
778 | current->pid); | 780 | current->pid); |
779 | ubifs_get_lp_stats(c, &lst); | 781 | ubifs_get_lp_stats(c, &lst); |
780 | dbg_dump_lstats(&lst); | 782 | dbg_dump_lstats(&lst); |
781 | 783 | ||
782 | for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { | 784 | for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { |
783 | err = ubifs_read_one_lp(c, lnum, &lp); | 785 | err = ubifs_read_one_lp(c, lnum, &lp); |
784 | if (err) | 786 | if (err) |
785 | ubifs_err("cannot read lprops for LEB %d", lnum); | 787 | ubifs_err("cannot read lprops for LEB %d", lnum); |
786 | 788 | ||
787 | dbg_dump_lprop(c, &lp); | 789 | dbg_dump_lprop(c, &lp); |
788 | } | 790 | } |
789 | printk(KERN_DEBUG "(pid %d) finish dumping LEB properties\n", | 791 | printk(KERN_DEBUG "(pid %d) finish dumping LEB properties\n", |
790 | current->pid); | 792 | current->pid); |
791 | } | 793 | } |
792 | 794 | ||
793 | void dbg_dump_lpt_info(struct ubifs_info *c) | 795 | void dbg_dump_lpt_info(struct ubifs_info *c) |
794 | { | 796 | { |
795 | int i; | 797 | int i; |
796 | 798 | ||
797 | spin_lock(&dbg_lock); | 799 | spin_lock(&dbg_lock); |
798 | printk(KERN_DEBUG "(pid %d) dumping LPT information\n", current->pid); | 800 | printk(KERN_DEBUG "(pid %d) dumping LPT information\n", current->pid); |
799 | printk(KERN_DEBUG "\tlpt_sz: %lld\n", c->lpt_sz); | 801 | printk(KERN_DEBUG "\tlpt_sz: %lld\n", c->lpt_sz); |
800 | printk(KERN_DEBUG "\tpnode_sz: %d\n", c->pnode_sz); | 802 | printk(KERN_DEBUG "\tpnode_sz: %d\n", c->pnode_sz); |
801 | printk(KERN_DEBUG "\tnnode_sz: %d\n", c->nnode_sz); | 803 | printk(KERN_DEBUG "\tnnode_sz: %d\n", c->nnode_sz); |
802 | printk(KERN_DEBUG "\tltab_sz: %d\n", c->ltab_sz); | 804 | printk(KERN_DEBUG "\tltab_sz: %d\n", c->ltab_sz); |
803 | printk(KERN_DEBUG "\tlsave_sz: %d\n", c->lsave_sz); | 805 | printk(KERN_DEBUG "\tlsave_sz: %d\n", c->lsave_sz); |
804 | printk(KERN_DEBUG "\tbig_lpt: %d\n", c->big_lpt); | 806 | printk(KERN_DEBUG "\tbig_lpt: %d\n", c->big_lpt); |
805 | printk(KERN_DEBUG "\tlpt_hght: %d\n", c->lpt_hght); | 807 | printk(KERN_DEBUG "\tlpt_hght: %d\n", c->lpt_hght); |
806 | printk(KERN_DEBUG "\tpnode_cnt: %d\n", c->pnode_cnt); | 808 | printk(KERN_DEBUG "\tpnode_cnt: %d\n", c->pnode_cnt); |
807 | printk(KERN_DEBUG "\tnnode_cnt: %d\n", c->nnode_cnt); | 809 | printk(KERN_DEBUG "\tnnode_cnt: %d\n", c->nnode_cnt); |
808 | printk(KERN_DEBUG "\tdirty_pn_cnt: %d\n", c->dirty_pn_cnt); | 810 | printk(KERN_DEBUG "\tdirty_pn_cnt: %d\n", c->dirty_pn_cnt); |
809 | printk(KERN_DEBUG "\tdirty_nn_cnt: %d\n", c->dirty_nn_cnt); | 811 | printk(KERN_DEBUG "\tdirty_nn_cnt: %d\n", c->dirty_nn_cnt); |
810 | printk(KERN_DEBUG "\tlsave_cnt: %d\n", c->lsave_cnt); | 812 | printk(KERN_DEBUG "\tlsave_cnt: %d\n", c->lsave_cnt); |
811 | printk(KERN_DEBUG "\tspace_bits: %d\n", c->space_bits); | 813 | printk(KERN_DEBUG "\tspace_bits: %d\n", c->space_bits); |
812 | printk(KERN_DEBUG "\tlpt_lnum_bits: %d\n", c->lpt_lnum_bits); | 814 | printk(KERN_DEBUG "\tlpt_lnum_bits: %d\n", c->lpt_lnum_bits); |
813 | printk(KERN_DEBUG "\tlpt_offs_bits: %d\n", c->lpt_offs_bits); | 815 | printk(KERN_DEBUG "\tlpt_offs_bits: %d\n", c->lpt_offs_bits); |
814 | printk(KERN_DEBUG "\tlpt_spc_bits: %d\n", c->lpt_spc_bits); | 816 | printk(KERN_DEBUG "\tlpt_spc_bits: %d\n", c->lpt_spc_bits); |
815 | printk(KERN_DEBUG "\tpcnt_bits: %d\n", c->pcnt_bits); | 817 | printk(KERN_DEBUG "\tpcnt_bits: %d\n", c->pcnt_bits); |
816 | printk(KERN_DEBUG "\tlnum_bits: %d\n", c->lnum_bits); | 818 | printk(KERN_DEBUG "\tlnum_bits: %d\n", c->lnum_bits); |
817 | printk(KERN_DEBUG "\tLPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs); | 819 | printk(KERN_DEBUG "\tLPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs); |
818 | printk(KERN_DEBUG "\tLPT head is at %d:%d\n", | 820 | printk(KERN_DEBUG "\tLPT head is at %d:%d\n", |
819 | c->nhead_lnum, c->nhead_offs); | 821 | c->nhead_lnum, c->nhead_offs); |
820 | printk(KERN_DEBUG "\tLPT ltab is at %d:%d\n", | 822 | printk(KERN_DEBUG "\tLPT ltab is at %d:%d\n", |
821 | c->ltab_lnum, c->ltab_offs); | 823 | c->ltab_lnum, c->ltab_offs); |
822 | if (c->big_lpt) | 824 | if (c->big_lpt) |
823 | printk(KERN_DEBUG "\tLPT lsave is at %d:%d\n", | 825 | printk(KERN_DEBUG "\tLPT lsave is at %d:%d\n", |
824 | c->lsave_lnum, c->lsave_offs); | 826 | c->lsave_lnum, c->lsave_offs); |
825 | for (i = 0; i < c->lpt_lebs; i++) | 827 | for (i = 0; i < c->lpt_lebs; i++) |
826 | printk(KERN_DEBUG "\tLPT LEB %d free %d dirty %d tgc %d " | 828 | printk(KERN_DEBUG "\tLPT LEB %d free %d dirty %d tgc %d " |
827 | "cmt %d\n", i + c->lpt_first, c->ltab[i].free, | 829 | "cmt %d\n", i + c->lpt_first, c->ltab[i].free, |
828 | c->ltab[i].dirty, c->ltab[i].tgc, c->ltab[i].cmt); | 830 | c->ltab[i].dirty, c->ltab[i].tgc, c->ltab[i].cmt); |
829 | spin_unlock(&dbg_lock); | 831 | spin_unlock(&dbg_lock); |
830 | } | 832 | } |
831 | 833 | ||
832 | void dbg_dump_leb(const struct ubifs_info *c, int lnum) | 834 | void dbg_dump_leb(const struct ubifs_info *c, int lnum) |
833 | { | 835 | { |
834 | struct ubifs_scan_leb *sleb; | 836 | struct ubifs_scan_leb *sleb; |
835 | struct ubifs_scan_node *snod; | 837 | struct ubifs_scan_node *snod; |
836 | void *buf; | 838 | void *buf; |
837 | 839 | ||
838 | if (dbg_failure_mode) | 840 | if (dbg_failure_mode) |
839 | return; | 841 | return; |
840 | 842 | ||
841 | printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n", | 843 | printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n", |
842 | current->pid, lnum); | 844 | current->pid, lnum); |
843 | 845 | ||
844 | buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); | 846 | buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); |
845 | if (!buf) { | 847 | if (!buf) { |
846 | ubifs_err("cannot allocate memory for dumping LEB %d", lnum); | 848 | ubifs_err("cannot allocate memory for dumping LEB %d", lnum); |
847 | return; | 849 | return; |
848 | } | 850 | } |
849 | 851 | ||
850 | sleb = ubifs_scan(c, lnum, 0, buf, 0); | 852 | sleb = ubifs_scan(c, lnum, 0, buf, 0); |
851 | if (IS_ERR(sleb)) { | 853 | if (IS_ERR(sleb)) { |
852 | ubifs_err("scan error %d", (int)PTR_ERR(sleb)); | 854 | ubifs_err("scan error %d", (int)PTR_ERR(sleb)); |
853 | goto out; | 855 | goto out; |
854 | } | 856 | } |
855 | 857 | ||
856 | printk(KERN_DEBUG "LEB %d has %d nodes ending at %d\n", lnum, | 858 | printk(KERN_DEBUG "LEB %d has %d nodes ending at %d\n", lnum, |
857 | sleb->nodes_cnt, sleb->endpt); | 859 | sleb->nodes_cnt, sleb->endpt); |
858 | 860 | ||
859 | list_for_each_entry(snod, &sleb->nodes, list) { | 861 | list_for_each_entry(snod, &sleb->nodes, list) { |
860 | cond_resched(); | 862 | cond_resched(); |
861 | printk(KERN_DEBUG "Dumping node at LEB %d:%d len %d\n", lnum, | 863 | printk(KERN_DEBUG "Dumping node at LEB %d:%d len %d\n", lnum, |
862 | snod->offs, snod->len); | 864 | snod->offs, snod->len); |
863 | dbg_dump_node(c, snod->node); | 865 | dbg_dump_node(c, snod->node); |
864 | } | 866 | } |
865 | 867 | ||
866 | printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n", | 868 | printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n", |
867 | current->pid, lnum); | 869 | current->pid, lnum); |
868 | ubifs_scan_destroy(sleb); | 870 | ubifs_scan_destroy(sleb); |
869 | 871 | ||
870 | out: | 872 | out: |
871 | vfree(buf); | 873 | vfree(buf); |
872 | return; | 874 | return; |
873 | } | 875 | } |
874 | 876 | ||
875 | void dbg_dump_znode(const struct ubifs_info *c, | 877 | void dbg_dump_znode(const struct ubifs_info *c, |
876 | const struct ubifs_znode *znode) | 878 | const struct ubifs_znode *znode) |
877 | { | 879 | { |
878 | int n; | 880 | int n; |
879 | const struct ubifs_zbranch *zbr; | 881 | const struct ubifs_zbranch *zbr; |
880 | 882 | ||
881 | spin_lock(&dbg_lock); | 883 | spin_lock(&dbg_lock); |
882 | if (znode->parent) | 884 | if (znode->parent) |
883 | zbr = &znode->parent->zbranch[znode->iip]; | 885 | zbr = &znode->parent->zbranch[znode->iip]; |
884 | else | 886 | else |
885 | zbr = &c->zroot; | 887 | zbr = &c->zroot; |
886 | 888 | ||
887 | printk(KERN_DEBUG "znode %p, LEB %d:%d len %d parent %p iip %d level %d" | 889 | printk(KERN_DEBUG "znode %p, LEB %d:%d len %d parent %p iip %d level %d" |
888 | " child_cnt %d flags %lx\n", znode, zbr->lnum, zbr->offs, | 890 | " child_cnt %d flags %lx\n", znode, zbr->lnum, zbr->offs, |
889 | zbr->len, znode->parent, znode->iip, znode->level, | 891 | zbr->len, znode->parent, znode->iip, znode->level, |
890 | znode->child_cnt, znode->flags); | 892 | znode->child_cnt, znode->flags); |
891 | 893 | ||
892 | if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { | 894 | if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { |
893 | spin_unlock(&dbg_lock); | 895 | spin_unlock(&dbg_lock); |
894 | return; | 896 | return; |
895 | } | 897 | } |
896 | 898 | ||
897 | printk(KERN_DEBUG "zbranches:\n"); | 899 | printk(KERN_DEBUG "zbranches:\n"); |
898 | for (n = 0; n < znode->child_cnt; n++) { | 900 | for (n = 0; n < znode->child_cnt; n++) { |
899 | zbr = &znode->zbranch[n]; | 901 | zbr = &znode->zbranch[n]; |
900 | if (znode->level > 0) | 902 | if (znode->level > 0) |
901 | printk(KERN_DEBUG "\t%d: znode %p LEB %d:%d len %d key " | 903 | printk(KERN_DEBUG "\t%d: znode %p LEB %d:%d len %d key " |
902 | "%s\n", n, zbr->znode, zbr->lnum, | 904 | "%s\n", n, zbr->znode, zbr->lnum, |
903 | zbr->offs, zbr->len, | 905 | zbr->offs, zbr->len, |
904 | DBGKEY(&zbr->key)); | 906 | DBGKEY(&zbr->key)); |
905 | else | 907 | else |
906 | printk(KERN_DEBUG "\t%d: LNC %p LEB %d:%d len %d key " | 908 | printk(KERN_DEBUG "\t%d: LNC %p LEB %d:%d len %d key " |
907 | "%s\n", n, zbr->znode, zbr->lnum, | 909 | "%s\n", n, zbr->znode, zbr->lnum, |
908 | zbr->offs, zbr->len, | 910 | zbr->offs, zbr->len, |
909 | DBGKEY(&zbr->key)); | 911 | DBGKEY(&zbr->key)); |
910 | } | 912 | } |
911 | spin_unlock(&dbg_lock); | 913 | spin_unlock(&dbg_lock); |
912 | } | 914 | } |
913 | 915 | ||
914 | void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) | 916 | void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) |
915 | { | 917 | { |
916 | int i; | 918 | int i; |
917 | 919 | ||
918 | printk(KERN_DEBUG "(pid %d) start dumping heap cat %d (%d elements)\n", | 920 | printk(KERN_DEBUG "(pid %d) start dumping heap cat %d (%d elements)\n", |
919 | current->pid, cat, heap->cnt); | 921 | current->pid, cat, heap->cnt); |
920 | for (i = 0; i < heap->cnt; i++) { | 922 | for (i = 0; i < heap->cnt; i++) { |
921 | struct ubifs_lprops *lprops = heap->arr[i]; | 923 | struct ubifs_lprops *lprops = heap->arr[i]; |
922 | 924 | ||
923 | printk(KERN_DEBUG "\t%d. LEB %d hpos %d free %d dirty %d " | 925 | printk(KERN_DEBUG "\t%d. LEB %d hpos %d free %d dirty %d " |
924 | "flags %d\n", i, lprops->lnum, lprops->hpos, | 926 | "flags %d\n", i, lprops->lnum, lprops->hpos, |
925 | lprops->free, lprops->dirty, lprops->flags); | 927 | lprops->free, lprops->dirty, lprops->flags); |
926 | } | 928 | } |
927 | printk(KERN_DEBUG "(pid %d) finish dumping heap\n", current->pid); | 929 | printk(KERN_DEBUG "(pid %d) finish dumping heap\n", current->pid); |
928 | } | 930 | } |
929 | 931 | ||
930 | void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, | 932 | void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, |
931 | struct ubifs_nnode *parent, int iip) | 933 | struct ubifs_nnode *parent, int iip) |
932 | { | 934 | { |
933 | int i; | 935 | int i; |
934 | 936 | ||
935 | printk(KERN_DEBUG "(pid %d) dumping pnode:\n", current->pid); | 937 | printk(KERN_DEBUG "(pid %d) dumping pnode:\n", current->pid); |
936 | printk(KERN_DEBUG "\taddress %zx parent %zx cnext %zx\n", | 938 | printk(KERN_DEBUG "\taddress %zx parent %zx cnext %zx\n", |
937 | (size_t)pnode, (size_t)parent, (size_t)pnode->cnext); | 939 | (size_t)pnode, (size_t)parent, (size_t)pnode->cnext); |
938 | printk(KERN_DEBUG "\tflags %lu iip %d level %d num %d\n", | 940 | printk(KERN_DEBUG "\tflags %lu iip %d level %d num %d\n", |
939 | pnode->flags, iip, pnode->level, pnode->num); | 941 | pnode->flags, iip, pnode->level, pnode->num); |
940 | for (i = 0; i < UBIFS_LPT_FANOUT; i++) { | 942 | for (i = 0; i < UBIFS_LPT_FANOUT; i++) { |
941 | struct ubifs_lprops *lp = &pnode->lprops[i]; | 943 | struct ubifs_lprops *lp = &pnode->lprops[i]; |
942 | 944 | ||
943 | printk(KERN_DEBUG "\t%d: free %d dirty %d flags %d lnum %d\n", | 945 | printk(KERN_DEBUG "\t%d: free %d dirty %d flags %d lnum %d\n", |
944 | i, lp->free, lp->dirty, lp->flags, lp->lnum); | 946 | i, lp->free, lp->dirty, lp->flags, lp->lnum); |
945 | } | 947 | } |
946 | } | 948 | } |
947 | 949 | ||
948 | void dbg_dump_tnc(struct ubifs_info *c) | 950 | void dbg_dump_tnc(struct ubifs_info *c) |
949 | { | 951 | { |
950 | struct ubifs_znode *znode; | 952 | struct ubifs_znode *znode; |
951 | int level; | 953 | int level; |
952 | 954 | ||
953 | printk(KERN_DEBUG "\n"); | 955 | printk(KERN_DEBUG "\n"); |
954 | printk(KERN_DEBUG "(pid %d) start dumping TNC tree\n", current->pid); | 956 | printk(KERN_DEBUG "(pid %d) start dumping TNC tree\n", current->pid); |
955 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL); | 957 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL); |
956 | level = znode->level; | 958 | level = znode->level; |
957 | printk(KERN_DEBUG "== Level %d ==\n", level); | 959 | printk(KERN_DEBUG "== Level %d ==\n", level); |
958 | while (znode) { | 960 | while (znode) { |
959 | if (level != znode->level) { | 961 | if (level != znode->level) { |
960 | level = znode->level; | 962 | level = znode->level; |
961 | printk(KERN_DEBUG "== Level %d ==\n", level); | 963 | printk(KERN_DEBUG "== Level %d ==\n", level); |
962 | } | 964 | } |
963 | dbg_dump_znode(c, znode); | 965 | dbg_dump_znode(c, znode); |
964 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); | 966 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); |
965 | } | 967 | } |
966 | printk(KERN_DEBUG "(pid %d) finish dumping TNC tree\n", current->pid); | 968 | printk(KERN_DEBUG "(pid %d) finish dumping TNC tree\n", current->pid); |
967 | } | 969 | } |
968 | 970 | ||
969 | static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, | 971 | static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, |
970 | void *priv) | 972 | void *priv) |
971 | { | 973 | { |
972 | dbg_dump_znode(c, znode); | 974 | dbg_dump_znode(c, znode); |
973 | return 0; | 975 | return 0; |
974 | } | 976 | } |
975 | 977 | ||
976 | /** | 978 | /** |
977 | * dbg_dump_index - dump the on-flash index. | 979 | * dbg_dump_index - dump the on-flash index. |
978 | * @c: UBIFS file-system description object | 980 | * @c: UBIFS file-system description object |
979 | * | 981 | * |
980 | * This function dumps whole UBIFS indexing B-tree, unlike 'dbg_dump_tnc()' | 982 | * This function dumps whole UBIFS indexing B-tree, unlike 'dbg_dump_tnc()' |
981 | * which dumps only in-memory znodes and does not read znodes which from flash. | 983 | * which dumps only in-memory znodes and does not read znodes which from flash. |
982 | */ | 984 | */ |
983 | void dbg_dump_index(struct ubifs_info *c) | 985 | void dbg_dump_index(struct ubifs_info *c) |
984 | { | 986 | { |
985 | dbg_walk_index(c, NULL, dump_znode, NULL); | 987 | dbg_walk_index(c, NULL, dump_znode, NULL); |
986 | } | 988 | } |
987 | 989 | ||
988 | /** | 990 | /** |
989 | * dbg_save_space_info - save information about flash space. | 991 | * dbg_save_space_info - save information about flash space. |
990 | * @c: UBIFS file-system description object | 992 | * @c: UBIFS file-system description object |
991 | * | 993 | * |
992 | * This function saves information about UBIFS free space, dirty space, etc, in | 994 | * This function saves information about UBIFS free space, dirty space, etc, in |
993 | * order to check it later. | 995 | * order to check it later. |
994 | */ | 996 | */ |
995 | void dbg_save_space_info(struct ubifs_info *c) | 997 | void dbg_save_space_info(struct ubifs_info *c) |
996 | { | 998 | { |
997 | struct ubifs_debug_info *d = c->dbg; | 999 | struct ubifs_debug_info *d = c->dbg; |
998 | int freeable_cnt; | 1000 | int freeable_cnt; |
999 | 1001 | ||
1000 | spin_lock(&c->space_lock); | 1002 | spin_lock(&c->space_lock); |
1001 | memcpy(&d->saved_lst, &c->lst, sizeof(struct ubifs_lp_stats)); | 1003 | memcpy(&d->saved_lst, &c->lst, sizeof(struct ubifs_lp_stats)); |
1002 | memcpy(&d->saved_bi, &c->bi, sizeof(struct ubifs_budg_info)); | 1004 | memcpy(&d->saved_bi, &c->bi, sizeof(struct ubifs_budg_info)); |
1003 | d->saved_idx_gc_cnt = c->idx_gc_cnt; | 1005 | d->saved_idx_gc_cnt = c->idx_gc_cnt; |
1004 | 1006 | ||
1005 | /* | 1007 | /* |
1006 | * We use a dirty hack here and zero out @c->freeable_cnt, because it | 1008 | * We use a dirty hack here and zero out @c->freeable_cnt, because it |
1007 | * affects the free space calculations, and UBIFS might not know about | 1009 | * affects the free space calculations, and UBIFS might not know about |
1008 | * all freeable eraseblocks. Indeed, we know about freeable eraseblocks | 1010 | * all freeable eraseblocks. Indeed, we know about freeable eraseblocks |
1009 | * only when we read their lprops, and we do this only lazily, upon the | 1011 | * only when we read their lprops, and we do this only lazily, upon the |
1010 | * need. So at any given point of time @c->freeable_cnt might be not | 1012 | * need. So at any given point of time @c->freeable_cnt might be not |
1011 | * exactly accurate. | 1013 | * exactly accurate. |
1012 | * | 1014 | * |
1013 | * Just one example about the issue we hit when we did not zero | 1015 | * Just one example about the issue we hit when we did not zero |
1014 | * @c->freeable_cnt. | 1016 | * @c->freeable_cnt. |
1015 | * 1. The file-system is mounted R/O, c->freeable_cnt is %0. We save the | 1017 | * 1. The file-system is mounted R/O, c->freeable_cnt is %0. We save the |
1016 | * amount of free space in @d->saved_free | 1018 | * amount of free space in @d->saved_free |
1017 | * 2. We re-mount R/W, which makes UBIFS to read the "lsave" | 1019 | * 2. We re-mount R/W, which makes UBIFS to read the "lsave" |
1018 | * information from flash, where we cache LEBs from various | 1020 | * information from flash, where we cache LEBs from various |
1019 | * categories ('ubifs_remount_fs()' -> 'ubifs_lpt_init()' | 1021 | * categories ('ubifs_remount_fs()' -> 'ubifs_lpt_init()' |
1020 | * -> 'lpt_init_wr()' -> 'read_lsave()' -> 'ubifs_lpt_lookup()' | 1022 | * -> 'lpt_init_wr()' -> 'read_lsave()' -> 'ubifs_lpt_lookup()' |
1021 | * -> 'ubifs_get_pnode()' -> 'update_cats()' | 1023 | * -> 'ubifs_get_pnode()' -> 'update_cats()' |
1022 | * -> 'ubifs_add_to_cat()'). | 1024 | * -> 'ubifs_add_to_cat()'). |
1023 | * 3. Lsave contains a freeable eraseblock, and @c->freeable_cnt | 1025 | * 3. Lsave contains a freeable eraseblock, and @c->freeable_cnt |
1024 | * becomes %1. | 1026 | * becomes %1. |
1025 | * 4. We calculate the amount of free space when the re-mount is | 1027 | * 4. We calculate the amount of free space when the re-mount is |
1026 | * finished in 'dbg_check_space_info()' and it does not match | 1028 | * finished in 'dbg_check_space_info()' and it does not match |
1027 | * @d->saved_free. | 1029 | * @d->saved_free. |
1028 | */ | 1030 | */ |
1029 | freeable_cnt = c->freeable_cnt; | 1031 | freeable_cnt = c->freeable_cnt; |
1030 | c->freeable_cnt = 0; | 1032 | c->freeable_cnt = 0; |
1031 | d->saved_free = ubifs_get_free_space_nolock(c); | 1033 | d->saved_free = ubifs_get_free_space_nolock(c); |
1032 | c->freeable_cnt = freeable_cnt; | 1034 | c->freeable_cnt = freeable_cnt; |
1033 | spin_unlock(&c->space_lock); | 1035 | spin_unlock(&c->space_lock); |
1034 | } | 1036 | } |
1035 | 1037 | ||
1036 | /** | 1038 | /** |
1037 | * dbg_check_space_info - check flash space information. | 1039 | * dbg_check_space_info - check flash space information. |
1038 | * @c: UBIFS file-system description object | 1040 | * @c: UBIFS file-system description object |
1039 | * | 1041 | * |
1040 | * This function compares current flash space information with the information | 1042 | * This function compares current flash space information with the information |
1041 | * which was saved when the 'dbg_save_space_info()' function was called. | 1043 | * which was saved when the 'dbg_save_space_info()' function was called. |
1042 | * Returns zero if the information has not changed, and %-EINVAL it it has | 1044 | * Returns zero if the information has not changed, and %-EINVAL it it has |
1043 | * changed. | 1045 | * changed. |
1044 | */ | 1046 | */ |
1045 | int dbg_check_space_info(struct ubifs_info *c) | 1047 | int dbg_check_space_info(struct ubifs_info *c) |
1046 | { | 1048 | { |
1047 | struct ubifs_debug_info *d = c->dbg; | 1049 | struct ubifs_debug_info *d = c->dbg; |
1048 | struct ubifs_lp_stats lst; | 1050 | struct ubifs_lp_stats lst; |
1049 | long long free; | 1051 | long long free; |
1050 | int freeable_cnt; | 1052 | int freeable_cnt; |
1051 | 1053 | ||
1052 | spin_lock(&c->space_lock); | 1054 | spin_lock(&c->space_lock); |
1053 | freeable_cnt = c->freeable_cnt; | 1055 | freeable_cnt = c->freeable_cnt; |
1054 | c->freeable_cnt = 0; | 1056 | c->freeable_cnt = 0; |
1055 | free = ubifs_get_free_space_nolock(c); | 1057 | free = ubifs_get_free_space_nolock(c); |
1056 | c->freeable_cnt = freeable_cnt; | 1058 | c->freeable_cnt = freeable_cnt; |
1057 | spin_unlock(&c->space_lock); | 1059 | spin_unlock(&c->space_lock); |
1058 | 1060 | ||
1059 | if (free != d->saved_free) { | 1061 | if (free != d->saved_free) { |
1060 | ubifs_err("free space changed from %lld to %lld", | 1062 | ubifs_err("free space changed from %lld to %lld", |
1061 | d->saved_free, free); | 1063 | d->saved_free, free); |
1062 | goto out; | 1064 | goto out; |
1063 | } | 1065 | } |
1064 | 1066 | ||
1065 | return 0; | 1067 | return 0; |
1066 | 1068 | ||
1067 | out: | 1069 | out: |
1068 | ubifs_msg("saved lprops statistics dump"); | 1070 | ubifs_msg("saved lprops statistics dump"); |
1069 | dbg_dump_lstats(&d->saved_lst); | 1071 | dbg_dump_lstats(&d->saved_lst); |
1070 | ubifs_msg("saved budgeting info dump"); | 1072 | ubifs_msg("saved budgeting info dump"); |
1071 | dbg_dump_budg(c, &d->saved_bi); | 1073 | dbg_dump_budg(c, &d->saved_bi); |
1072 | ubifs_msg("saved idx_gc_cnt %d", d->saved_idx_gc_cnt); | 1074 | ubifs_msg("saved idx_gc_cnt %d", d->saved_idx_gc_cnt); |
1073 | ubifs_msg("current lprops statistics dump"); | 1075 | ubifs_msg("current lprops statistics dump"); |
1074 | ubifs_get_lp_stats(c, &lst); | 1076 | ubifs_get_lp_stats(c, &lst); |
1075 | dbg_dump_lstats(&lst); | 1077 | dbg_dump_lstats(&lst); |
1076 | ubifs_msg("current budgeting info dump"); | 1078 | ubifs_msg("current budgeting info dump"); |
1077 | dbg_dump_budg(c, &c->bi); | 1079 | dbg_dump_budg(c, &c->bi); |
1078 | dump_stack(); | 1080 | dump_stack(); |
1079 | return -EINVAL; | 1081 | return -EINVAL; |
1080 | } | 1082 | } |
1081 | 1083 | ||
1082 | /** | 1084 | /** |
1083 | * dbg_check_synced_i_size - check synchronized inode size. | 1085 | * dbg_check_synced_i_size - check synchronized inode size. |
1084 | * @inode: inode to check | 1086 | * @inode: inode to check |
1085 | * | 1087 | * |
1086 | * If inode is clean, synchronized inode size has to be equivalent to current | 1088 | * If inode is clean, synchronized inode size has to be equivalent to current |
1087 | * inode size. This function has to be called only for locked inodes (@i_mutex | 1089 | * inode size. This function has to be called only for locked inodes (@i_mutex |
1088 | * has to be locked). Returns %0 if synchronized inode size if correct, and | 1090 | * has to be locked). Returns %0 if synchronized inode size if correct, and |
1089 | * %-EINVAL if not. | 1091 | * %-EINVAL if not. |
1090 | */ | 1092 | */ |
1091 | int dbg_check_synced_i_size(struct inode *inode) | 1093 | int dbg_check_synced_i_size(struct inode *inode) |
1092 | { | 1094 | { |
1093 | int err = 0; | 1095 | int err = 0; |
1094 | struct ubifs_inode *ui = ubifs_inode(inode); | 1096 | struct ubifs_inode *ui = ubifs_inode(inode); |
1095 | 1097 | ||
1096 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) | 1098 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) |
1097 | return 0; | 1099 | return 0; |
1098 | if (!S_ISREG(inode->i_mode)) | 1100 | if (!S_ISREG(inode->i_mode)) |
1099 | return 0; | 1101 | return 0; |
1100 | 1102 | ||
1101 | mutex_lock(&ui->ui_mutex); | 1103 | mutex_lock(&ui->ui_mutex); |
1102 | spin_lock(&ui->ui_lock); | 1104 | spin_lock(&ui->ui_lock); |
1103 | if (ui->ui_size != ui->synced_i_size && !ui->dirty) { | 1105 | if (ui->ui_size != ui->synced_i_size && !ui->dirty) { |
1104 | ubifs_err("ui_size is %lld, synced_i_size is %lld, but inode " | 1106 | ubifs_err("ui_size is %lld, synced_i_size is %lld, but inode " |
1105 | "is clean", ui->ui_size, ui->synced_i_size); | 1107 | "is clean", ui->ui_size, ui->synced_i_size); |
1106 | ubifs_err("i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, | 1108 | ubifs_err("i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, |
1107 | inode->i_mode, i_size_read(inode)); | 1109 | inode->i_mode, i_size_read(inode)); |
1108 | dbg_dump_stack(); | 1110 | dbg_dump_stack(); |
1109 | err = -EINVAL; | 1111 | err = -EINVAL; |
1110 | } | 1112 | } |
1111 | spin_unlock(&ui->ui_lock); | 1113 | spin_unlock(&ui->ui_lock); |
1112 | mutex_unlock(&ui->ui_mutex); | 1114 | mutex_unlock(&ui->ui_mutex); |
1113 | return err; | 1115 | return err; |
1114 | } | 1116 | } |
1115 | 1117 | ||
1116 | /* | 1118 | /* |
1117 | * dbg_check_dir - check directory inode size and link count. | 1119 | * dbg_check_dir - check directory inode size and link count. |
1118 | * @c: UBIFS file-system description object | 1120 | * @c: UBIFS file-system description object |
1119 | * @dir: the directory to calculate size for | 1121 | * @dir: the directory to calculate size for |
1120 | * @size: the result is returned here | 1122 | * @size: the result is returned here |
1121 | * | 1123 | * |
1122 | * This function makes sure that directory size and link count are correct. | 1124 | * This function makes sure that directory size and link count are correct. |
1123 | * Returns zero in case of success and a negative error code in case of | 1125 | * Returns zero in case of success and a negative error code in case of |
1124 | * failure. | 1126 | * failure. |
1125 | * | 1127 | * |
1126 | * Note, it is good idea to make sure the @dir->i_mutex is locked before | 1128 | * Note, it is good idea to make sure the @dir->i_mutex is locked before |
1127 | * calling this function. | 1129 | * calling this function. |
1128 | */ | 1130 | */ |
1129 | int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir) | 1131 | int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir) |
1130 | { | 1132 | { |
1131 | unsigned int nlink = 2; | 1133 | unsigned int nlink = 2; |
1132 | union ubifs_key key; | 1134 | union ubifs_key key; |
1133 | struct ubifs_dent_node *dent, *pdent = NULL; | 1135 | struct ubifs_dent_node *dent, *pdent = NULL; |
1134 | struct qstr nm = { .name = NULL }; | 1136 | struct qstr nm = { .name = NULL }; |
1135 | loff_t size = UBIFS_INO_NODE_SZ; | 1137 | loff_t size = UBIFS_INO_NODE_SZ; |
1136 | 1138 | ||
1137 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) | 1139 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) |
1138 | return 0; | 1140 | return 0; |
1139 | 1141 | ||
1140 | if (!S_ISDIR(dir->i_mode)) | 1142 | if (!S_ISDIR(dir->i_mode)) |
1141 | return 0; | 1143 | return 0; |
1142 | 1144 | ||
1143 | lowest_dent_key(c, &key, dir->i_ino); | 1145 | lowest_dent_key(c, &key, dir->i_ino); |
1144 | while (1) { | 1146 | while (1) { |
1145 | int err; | 1147 | int err; |
1146 | 1148 | ||
1147 | dent = ubifs_tnc_next_ent(c, &key, &nm); | 1149 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
1148 | if (IS_ERR(dent)) { | 1150 | if (IS_ERR(dent)) { |
1149 | err = PTR_ERR(dent); | 1151 | err = PTR_ERR(dent); |
1150 | if (err == -ENOENT) | 1152 | if (err == -ENOENT) |
1151 | break; | 1153 | break; |
1152 | return err; | 1154 | return err; |
1153 | } | 1155 | } |
1154 | 1156 | ||
1155 | nm.name = dent->name; | 1157 | nm.name = dent->name; |
1156 | nm.len = le16_to_cpu(dent->nlen); | 1158 | nm.len = le16_to_cpu(dent->nlen); |
1157 | size += CALC_DENT_SIZE(nm.len); | 1159 | size += CALC_DENT_SIZE(nm.len); |
1158 | if (dent->type == UBIFS_ITYPE_DIR) | 1160 | if (dent->type == UBIFS_ITYPE_DIR) |
1159 | nlink += 1; | 1161 | nlink += 1; |
1160 | kfree(pdent); | 1162 | kfree(pdent); |
1161 | pdent = dent; | 1163 | pdent = dent; |
1162 | key_read(c, &dent->key, &key); | 1164 | key_read(c, &dent->key, &key); |
1163 | } | 1165 | } |
1164 | kfree(pdent); | 1166 | kfree(pdent); |
1165 | 1167 | ||
1166 | if (i_size_read(dir) != size) { | 1168 | if (i_size_read(dir) != size) { |
1167 | ubifs_err("directory inode %lu has size %llu, " | 1169 | ubifs_err("directory inode %lu has size %llu, " |
1168 | "but calculated size is %llu", dir->i_ino, | 1170 | "but calculated size is %llu", dir->i_ino, |
1169 | (unsigned long long)i_size_read(dir), | 1171 | (unsigned long long)i_size_read(dir), |
1170 | (unsigned long long)size); | 1172 | (unsigned long long)size); |
1171 | dump_stack(); | 1173 | dump_stack(); |
1172 | return -EINVAL; | 1174 | return -EINVAL; |
1173 | } | 1175 | } |
1174 | if (dir->i_nlink != nlink) { | 1176 | if (dir->i_nlink != nlink) { |
1175 | ubifs_err("directory inode %lu has nlink %u, but calculated " | 1177 | ubifs_err("directory inode %lu has nlink %u, but calculated " |
1176 | "nlink is %u", dir->i_ino, dir->i_nlink, nlink); | 1178 | "nlink is %u", dir->i_ino, dir->i_nlink, nlink); |
1177 | dump_stack(); | 1179 | dump_stack(); |
1178 | return -EINVAL; | 1180 | return -EINVAL; |
1179 | } | 1181 | } |
1180 | 1182 | ||
1181 | return 0; | 1183 | return 0; |
1182 | } | 1184 | } |
1183 | 1185 | ||
1184 | /** | 1186 | /** |
1185 | * dbg_check_key_order - make sure that colliding keys are properly ordered. | 1187 | * dbg_check_key_order - make sure that colliding keys are properly ordered. |
1186 | * @c: UBIFS file-system description object | 1188 | * @c: UBIFS file-system description object |
1187 | * @zbr1: first zbranch | 1189 | * @zbr1: first zbranch |
1188 | * @zbr2: following zbranch | 1190 | * @zbr2: following zbranch |
1189 | * | 1191 | * |
1190 | * In UBIFS indexing B-tree colliding keys has to be sorted in binary order of | 1192 | * In UBIFS indexing B-tree colliding keys has to be sorted in binary order of |
1191 | * names of the direntries/xentries which are referred by the keys. This | 1193 | * names of the direntries/xentries which are referred by the keys. This |
1192 | * function reads direntries/xentries referred by @zbr1 and @zbr2 and makes | 1194 | * function reads direntries/xentries referred by @zbr1 and @zbr2 and makes |
1193 | * sure the name of direntry/xentry referred by @zbr1 is less than | 1195 | * sure the name of direntry/xentry referred by @zbr1 is less than |
1194 | * direntry/xentry referred by @zbr2. Returns zero if this is true, %1 if not, | 1196 | * direntry/xentry referred by @zbr2. Returns zero if this is true, %1 if not, |
1195 | * and a negative error code in case of failure. | 1197 | * and a negative error code in case of failure. |
1196 | */ | 1198 | */ |
1197 | static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1, | 1199 | static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1, |
1198 | struct ubifs_zbranch *zbr2) | 1200 | struct ubifs_zbranch *zbr2) |
1199 | { | 1201 | { |
1200 | int err, nlen1, nlen2, cmp; | 1202 | int err, nlen1, nlen2, cmp; |
1201 | struct ubifs_dent_node *dent1, *dent2; | 1203 | struct ubifs_dent_node *dent1, *dent2; |
1202 | union ubifs_key key; | 1204 | union ubifs_key key; |
1203 | 1205 | ||
1204 | ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key)); | 1206 | ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key)); |
1205 | dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); | 1207 | dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); |
1206 | if (!dent1) | 1208 | if (!dent1) |
1207 | return -ENOMEM; | 1209 | return -ENOMEM; |
1208 | dent2 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); | 1210 | dent2 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); |
1209 | if (!dent2) { | 1211 | if (!dent2) { |
1210 | err = -ENOMEM; | 1212 | err = -ENOMEM; |
1211 | goto out_free; | 1213 | goto out_free; |
1212 | } | 1214 | } |
1213 | 1215 | ||
1214 | err = ubifs_tnc_read_node(c, zbr1, dent1); | 1216 | err = ubifs_tnc_read_node(c, zbr1, dent1); |
1215 | if (err) | 1217 | if (err) |
1216 | goto out_free; | 1218 | goto out_free; |
1217 | err = ubifs_validate_entry(c, dent1); | 1219 | err = ubifs_validate_entry(c, dent1); |
1218 | if (err) | 1220 | if (err) |
1219 | goto out_free; | 1221 | goto out_free; |
1220 | 1222 | ||
1221 | err = ubifs_tnc_read_node(c, zbr2, dent2); | 1223 | err = ubifs_tnc_read_node(c, zbr2, dent2); |
1222 | if (err) | 1224 | if (err) |
1223 | goto out_free; | 1225 | goto out_free; |
1224 | err = ubifs_validate_entry(c, dent2); | 1226 | err = ubifs_validate_entry(c, dent2); |
1225 | if (err) | 1227 | if (err) |
1226 | goto out_free; | 1228 | goto out_free; |
1227 | 1229 | ||
1228 | /* Make sure node keys are the same as in zbranch */ | 1230 | /* Make sure node keys are the same as in zbranch */ |
1229 | err = 1; | 1231 | err = 1; |
1230 | key_read(c, &dent1->key, &key); | 1232 | key_read(c, &dent1->key, &key); |
1231 | if (keys_cmp(c, &zbr1->key, &key)) { | 1233 | if (keys_cmp(c, &zbr1->key, &key)) { |
1232 | dbg_err("1st entry at %d:%d has key %s", zbr1->lnum, | 1234 | dbg_err("1st entry at %d:%d has key %s", zbr1->lnum, |
1233 | zbr1->offs, DBGKEY(&key)); | 1235 | zbr1->offs, DBGKEY(&key)); |
1234 | dbg_err("but it should have key %s according to tnc", | 1236 | dbg_err("but it should have key %s according to tnc", |
1235 | DBGKEY(&zbr1->key)); | 1237 | DBGKEY(&zbr1->key)); |
1236 | dbg_dump_node(c, dent1); | 1238 | dbg_dump_node(c, dent1); |
1237 | goto out_free; | 1239 | goto out_free; |
1238 | } | 1240 | } |
1239 | 1241 | ||
1240 | key_read(c, &dent2->key, &key); | 1242 | key_read(c, &dent2->key, &key); |
1241 | if (keys_cmp(c, &zbr2->key, &key)) { | 1243 | if (keys_cmp(c, &zbr2->key, &key)) { |
1242 | dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum, | 1244 | dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum, |
1243 | zbr1->offs, DBGKEY(&key)); | 1245 | zbr1->offs, DBGKEY(&key)); |
1244 | dbg_err("but it should have key %s according to tnc", | 1246 | dbg_err("but it should have key %s according to tnc", |
1245 | DBGKEY(&zbr2->key)); | 1247 | DBGKEY(&zbr2->key)); |
1246 | dbg_dump_node(c, dent2); | 1248 | dbg_dump_node(c, dent2); |
1247 | goto out_free; | 1249 | goto out_free; |
1248 | } | 1250 | } |
1249 | 1251 | ||
1250 | nlen1 = le16_to_cpu(dent1->nlen); | 1252 | nlen1 = le16_to_cpu(dent1->nlen); |
1251 | nlen2 = le16_to_cpu(dent2->nlen); | 1253 | nlen2 = le16_to_cpu(dent2->nlen); |
1252 | 1254 | ||
1253 | cmp = memcmp(dent1->name, dent2->name, min_t(int, nlen1, nlen2)); | 1255 | cmp = memcmp(dent1->name, dent2->name, min_t(int, nlen1, nlen2)); |
1254 | if (cmp < 0 || (cmp == 0 && nlen1 < nlen2)) { | 1256 | if (cmp < 0 || (cmp == 0 && nlen1 < nlen2)) { |
1255 | err = 0; | 1257 | err = 0; |
1256 | goto out_free; | 1258 | goto out_free; |
1257 | } | 1259 | } |
1258 | if (cmp == 0 && nlen1 == nlen2) | 1260 | if (cmp == 0 && nlen1 == nlen2) |
1259 | dbg_err("2 xent/dent nodes with the same name"); | 1261 | dbg_err("2 xent/dent nodes with the same name"); |
1260 | else | 1262 | else |
1261 | dbg_err("bad order of colliding key %s", | 1263 | dbg_err("bad order of colliding key %s", |
1262 | DBGKEY(&key)); | 1264 | DBGKEY(&key)); |
1263 | 1265 | ||
1264 | ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); | 1266 | ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); |
1265 | dbg_dump_node(c, dent1); | 1267 | dbg_dump_node(c, dent1); |
1266 | ubifs_msg("second node at %d:%d\n", zbr2->lnum, zbr2->offs); | 1268 | ubifs_msg("second node at %d:%d\n", zbr2->lnum, zbr2->offs); |
1267 | dbg_dump_node(c, dent2); | 1269 | dbg_dump_node(c, dent2); |
1268 | 1270 | ||
1269 | out_free: | 1271 | out_free: |
1270 | kfree(dent2); | 1272 | kfree(dent2); |
1271 | kfree(dent1); | 1273 | kfree(dent1); |
1272 | return err; | 1274 | return err; |
1273 | } | 1275 | } |
1274 | 1276 | ||
1275 | /** | 1277 | /** |
1276 | * dbg_check_znode - check if znode is all right. | 1278 | * dbg_check_znode - check if znode is all right. |
1277 | * @c: UBIFS file-system description object | 1279 | * @c: UBIFS file-system description object |
1278 | * @zbr: zbranch which points to this znode | 1280 | * @zbr: zbranch which points to this znode |
1279 | * | 1281 | * |
1280 | * This function makes sure that znode referred to by @zbr is all right. | 1282 | * This function makes sure that znode referred to by @zbr is all right. |
1281 | * Returns zero if it is, and %-EINVAL if it is not. | 1283 | * Returns zero if it is, and %-EINVAL if it is not. |
1282 | */ | 1284 | */ |
1283 | static int dbg_check_znode(struct ubifs_info *c, struct ubifs_zbranch *zbr) | 1285 | static int dbg_check_znode(struct ubifs_info *c, struct ubifs_zbranch *zbr) |
1284 | { | 1286 | { |
1285 | struct ubifs_znode *znode = zbr->znode; | 1287 | struct ubifs_znode *znode = zbr->znode; |
1286 | struct ubifs_znode *zp = znode->parent; | 1288 | struct ubifs_znode *zp = znode->parent; |
1287 | int n, err, cmp; | 1289 | int n, err, cmp; |
1288 | 1290 | ||
1289 | if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { | 1291 | if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { |
1290 | err = 1; | 1292 | err = 1; |
1291 | goto out; | 1293 | goto out; |
1292 | } | 1294 | } |
1293 | if (znode->level < 0) { | 1295 | if (znode->level < 0) { |
1294 | err = 2; | 1296 | err = 2; |
1295 | goto out; | 1297 | goto out; |
1296 | } | 1298 | } |
1297 | if (znode->iip < 0 || znode->iip >= c->fanout) { | 1299 | if (znode->iip < 0 || znode->iip >= c->fanout) { |
1298 | err = 3; | 1300 | err = 3; |
1299 | goto out; | 1301 | goto out; |
1300 | } | 1302 | } |
1301 | 1303 | ||
1302 | if (zbr->len == 0) | 1304 | if (zbr->len == 0) |
1303 | /* Only dirty zbranch may have no on-flash nodes */ | 1305 | /* Only dirty zbranch may have no on-flash nodes */ |
1304 | if (!ubifs_zn_dirty(znode)) { | 1306 | if (!ubifs_zn_dirty(znode)) { |
1305 | err = 4; | 1307 | err = 4; |
1306 | goto out; | 1308 | goto out; |
1307 | } | 1309 | } |
1308 | 1310 | ||
1309 | if (ubifs_zn_dirty(znode)) { | 1311 | if (ubifs_zn_dirty(znode)) { |
1310 | /* | 1312 | /* |
1311 | * If znode is dirty, its parent has to be dirty as well. The | 1313 | * If znode is dirty, its parent has to be dirty as well. The |
1312 | * order of the operation is important, so we have to have | 1314 | * order of the operation is important, so we have to have |
1313 | * memory barriers. | 1315 | * memory barriers. |
1314 | */ | 1316 | */ |
1315 | smp_mb(); | 1317 | smp_mb(); |
1316 | if (zp && !ubifs_zn_dirty(zp)) { | 1318 | if (zp && !ubifs_zn_dirty(zp)) { |
1317 | /* | 1319 | /* |
1318 | * The dirty flag is atomic and is cleared outside the | 1320 | * The dirty flag is atomic and is cleared outside the |
1319 | * TNC mutex, so znode's dirty flag may now have | 1321 | * TNC mutex, so znode's dirty flag may now have |
1320 | * been cleared. The child is always cleared before the | 1322 | * been cleared. The child is always cleared before the |
1321 | * parent, so we just need to check again. | 1323 | * parent, so we just need to check again. |
1322 | */ | 1324 | */ |
1323 | smp_mb(); | 1325 | smp_mb(); |
1324 | if (ubifs_zn_dirty(znode)) { | 1326 | if (ubifs_zn_dirty(znode)) { |
1325 | err = 5; | 1327 | err = 5; |
1326 | goto out; | 1328 | goto out; |
1327 | } | 1329 | } |
1328 | } | 1330 | } |
1329 | } | 1331 | } |
1330 | 1332 | ||
1331 | if (zp) { | 1333 | if (zp) { |
1332 | const union ubifs_key *min, *max; | 1334 | const union ubifs_key *min, *max; |
1333 | 1335 | ||
1334 | if (znode->level != zp->level - 1) { | 1336 | if (znode->level != zp->level - 1) { |
1335 | err = 6; | 1337 | err = 6; |
1336 | goto out; | 1338 | goto out; |
1337 | } | 1339 | } |
1338 | 1340 | ||
1339 | /* Make sure the 'parent' pointer in our znode is correct */ | 1341 | /* Make sure the 'parent' pointer in our znode is correct */ |
1340 | err = ubifs_search_zbranch(c, zp, &zbr->key, &n); | 1342 | err = ubifs_search_zbranch(c, zp, &zbr->key, &n); |
1341 | if (!err) { | 1343 | if (!err) { |
1342 | /* This zbranch does not exist in the parent */ | 1344 | /* This zbranch does not exist in the parent */ |
1343 | err = 7; | 1345 | err = 7; |
1344 | goto out; | 1346 | goto out; |
1345 | } | 1347 | } |
1346 | 1348 | ||
1347 | if (znode->iip >= zp->child_cnt) { | 1349 | if (znode->iip >= zp->child_cnt) { |
1348 | err = 8; | 1350 | err = 8; |
1349 | goto out; | 1351 | goto out; |
1350 | } | 1352 | } |
1351 | 1353 | ||
1352 | if (znode->iip != n) { | 1354 | if (znode->iip != n) { |
1353 | /* This may happen only in case of collisions */ | 1355 | /* This may happen only in case of collisions */ |
1354 | if (keys_cmp(c, &zp->zbranch[n].key, | 1356 | if (keys_cmp(c, &zp->zbranch[n].key, |
1355 | &zp->zbranch[znode->iip].key)) { | 1357 | &zp->zbranch[znode->iip].key)) { |
1356 | err = 9; | 1358 | err = 9; |
1357 | goto out; | 1359 | goto out; |
1358 | } | 1360 | } |
1359 | n = znode->iip; | 1361 | n = znode->iip; |
1360 | } | 1362 | } |
1361 | 1363 | ||
1362 | /* | 1364 | /* |
1363 | * Make sure that the first key in our znode is greater than or | 1365 | * Make sure that the first key in our znode is greater than or |
1364 | * equal to the key in the pointing zbranch. | 1366 | * equal to the key in the pointing zbranch. |
1365 | */ | 1367 | */ |
1366 | min = &zbr->key; | 1368 | min = &zbr->key; |
1367 | cmp = keys_cmp(c, min, &znode->zbranch[0].key); | 1369 | cmp = keys_cmp(c, min, &znode->zbranch[0].key); |
1368 | if (cmp == 1) { | 1370 | if (cmp == 1) { |
1369 | err = 10; | 1371 | err = 10; |
1370 | goto out; | 1372 | goto out; |
1371 | } | 1373 | } |
1372 | 1374 | ||
1373 | if (n + 1 < zp->child_cnt) { | 1375 | if (n + 1 < zp->child_cnt) { |
1374 | max = &zp->zbranch[n + 1].key; | 1376 | max = &zp->zbranch[n + 1].key; |
1375 | 1377 | ||
1376 | /* | 1378 | /* |
1377 | * Make sure the last key in our znode is less or | 1379 | * Make sure the last key in our znode is less or |
1378 | * equivalent than the key in the zbranch which goes | 1380 | * equivalent than the key in the zbranch which goes |
1379 | * after our pointing zbranch. | 1381 | * after our pointing zbranch. |
1380 | */ | 1382 | */ |
1381 | cmp = keys_cmp(c, max, | 1383 | cmp = keys_cmp(c, max, |
1382 | &znode->zbranch[znode->child_cnt - 1].key); | 1384 | &znode->zbranch[znode->child_cnt - 1].key); |
1383 | if (cmp == -1) { | 1385 | if (cmp == -1) { |
1384 | err = 11; | 1386 | err = 11; |
1385 | goto out; | 1387 | goto out; |
1386 | } | 1388 | } |
1387 | } | 1389 | } |
1388 | } else { | 1390 | } else { |
1389 | /* This may only be root znode */ | 1391 | /* This may only be root znode */ |
1390 | if (zbr != &c->zroot) { | 1392 | if (zbr != &c->zroot) { |
1391 | err = 12; | 1393 | err = 12; |
1392 | goto out; | 1394 | goto out; |
1393 | } | 1395 | } |
1394 | } | 1396 | } |
1395 | 1397 | ||
1396 | /* | 1398 | /* |
1397 | * Make sure that next key is greater or equivalent then the previous | 1399 | * Make sure that next key is greater or equivalent then the previous |
1398 | * one. | 1400 | * one. |
1399 | */ | 1401 | */ |
1400 | for (n = 1; n < znode->child_cnt; n++) { | 1402 | for (n = 1; n < znode->child_cnt; n++) { |
1401 | cmp = keys_cmp(c, &znode->zbranch[n - 1].key, | 1403 | cmp = keys_cmp(c, &znode->zbranch[n - 1].key, |
1402 | &znode->zbranch[n].key); | 1404 | &znode->zbranch[n].key); |
1403 | if (cmp > 0) { | 1405 | if (cmp > 0) { |
1404 | err = 13; | 1406 | err = 13; |
1405 | goto out; | 1407 | goto out; |
1406 | } | 1408 | } |
1407 | if (cmp == 0) { | 1409 | if (cmp == 0) { |
1408 | /* This can only be keys with colliding hash */ | 1410 | /* This can only be keys with colliding hash */ |
1409 | if (!is_hash_key(c, &znode->zbranch[n].key)) { | 1411 | if (!is_hash_key(c, &znode->zbranch[n].key)) { |
1410 | err = 14; | 1412 | err = 14; |
1411 | goto out; | 1413 | goto out; |
1412 | } | 1414 | } |
1413 | 1415 | ||
1414 | if (znode->level != 0 || c->replaying) | 1416 | if (znode->level != 0 || c->replaying) |
1415 | continue; | 1417 | continue; |
1416 | 1418 | ||
1417 | /* | 1419 | /* |
1418 | * Colliding keys should follow binary order of | 1420 | * Colliding keys should follow binary order of |
1419 | * corresponding xentry/dentry names. | 1421 | * corresponding xentry/dentry names. |
1420 | */ | 1422 | */ |
1421 | err = dbg_check_key_order(c, &znode->zbranch[n - 1], | 1423 | err = dbg_check_key_order(c, &znode->zbranch[n - 1], |
1422 | &znode->zbranch[n]); | 1424 | &znode->zbranch[n]); |
1423 | if (err < 0) | 1425 | if (err < 0) |
1424 | return err; | 1426 | return err; |
1425 | if (err) { | 1427 | if (err) { |
1426 | err = 15; | 1428 | err = 15; |
1427 | goto out; | 1429 | goto out; |
1428 | } | 1430 | } |
1429 | } | 1431 | } |
1430 | } | 1432 | } |
1431 | 1433 | ||
1432 | for (n = 0; n < znode->child_cnt; n++) { | 1434 | for (n = 0; n < znode->child_cnt; n++) { |
1433 | if (!znode->zbranch[n].znode && | 1435 | if (!znode->zbranch[n].znode && |
1434 | (znode->zbranch[n].lnum == 0 || | 1436 | (znode->zbranch[n].lnum == 0 || |
1435 | znode->zbranch[n].len == 0)) { | 1437 | znode->zbranch[n].len == 0)) { |
1436 | err = 16; | 1438 | err = 16; |
1437 | goto out; | 1439 | goto out; |
1438 | } | 1440 | } |
1439 | 1441 | ||
1440 | if (znode->zbranch[n].lnum != 0 && | 1442 | if (znode->zbranch[n].lnum != 0 && |
1441 | znode->zbranch[n].len == 0) { | 1443 | znode->zbranch[n].len == 0) { |
1442 | err = 17; | 1444 | err = 17; |
1443 | goto out; | 1445 | goto out; |
1444 | } | 1446 | } |
1445 | 1447 | ||
1446 | if (znode->zbranch[n].lnum == 0 && | 1448 | if (znode->zbranch[n].lnum == 0 && |
1447 | znode->zbranch[n].len != 0) { | 1449 | znode->zbranch[n].len != 0) { |
1448 | err = 18; | 1450 | err = 18; |
1449 | goto out; | 1451 | goto out; |
1450 | } | 1452 | } |
1451 | 1453 | ||
1452 | if (znode->zbranch[n].lnum == 0 && | 1454 | if (znode->zbranch[n].lnum == 0 && |
1453 | znode->zbranch[n].offs != 0) { | 1455 | znode->zbranch[n].offs != 0) { |
1454 | err = 19; | 1456 | err = 19; |
1455 | goto out; | 1457 | goto out; |
1456 | } | 1458 | } |
1457 | 1459 | ||
1458 | if (znode->level != 0 && znode->zbranch[n].znode) | 1460 | if (znode->level != 0 && znode->zbranch[n].znode) |
1459 | if (znode->zbranch[n].znode->parent != znode) { | 1461 | if (znode->zbranch[n].znode->parent != znode) { |
1460 | err = 20; | 1462 | err = 20; |
1461 | goto out; | 1463 | goto out; |
1462 | } | 1464 | } |
1463 | } | 1465 | } |
1464 | 1466 | ||
1465 | return 0; | 1467 | return 0; |
1466 | 1468 | ||
1467 | out: | 1469 | out: |
1468 | ubifs_err("failed, error %d", err); | 1470 | ubifs_err("failed, error %d", err); |
1469 | ubifs_msg("dump of the znode"); | 1471 | ubifs_msg("dump of the znode"); |
1470 | dbg_dump_znode(c, znode); | 1472 | dbg_dump_znode(c, znode); |
1471 | if (zp) { | 1473 | if (zp) { |
1472 | ubifs_msg("dump of the parent znode"); | 1474 | ubifs_msg("dump of the parent znode"); |
1473 | dbg_dump_znode(c, zp); | 1475 | dbg_dump_znode(c, zp); |
1474 | } | 1476 | } |
1475 | dump_stack(); | 1477 | dump_stack(); |
1476 | return -EINVAL; | 1478 | return -EINVAL; |
1477 | } | 1479 | } |
1478 | 1480 | ||
1479 | /** | 1481 | /** |
1480 | * dbg_check_tnc - check TNC tree. | 1482 | * dbg_check_tnc - check TNC tree. |
1481 | * @c: UBIFS file-system description object | 1483 | * @c: UBIFS file-system description object |
1482 | * @extra: do extra checks that are possible at start commit | 1484 | * @extra: do extra checks that are possible at start commit |
1483 | * | 1485 | * |
1484 | * This function traverses whole TNC tree and checks every znode. Returns zero | 1486 | * This function traverses whole TNC tree and checks every znode. Returns zero |
1485 | * if everything is all right and %-EINVAL if something is wrong with TNC. | 1487 | * if everything is all right and %-EINVAL if something is wrong with TNC. |
1486 | */ | 1488 | */ |
1487 | int dbg_check_tnc(struct ubifs_info *c, int extra) | 1489 | int dbg_check_tnc(struct ubifs_info *c, int extra) |
1488 | { | 1490 | { |
1489 | struct ubifs_znode *znode; | 1491 | struct ubifs_znode *znode; |
1490 | long clean_cnt = 0, dirty_cnt = 0; | 1492 | long clean_cnt = 0, dirty_cnt = 0; |
1491 | int err, last; | 1493 | int err, last; |
1492 | 1494 | ||
1493 | if (!(ubifs_chk_flags & UBIFS_CHK_TNC)) | 1495 | if (!(ubifs_chk_flags & UBIFS_CHK_TNC)) |
1494 | return 0; | 1496 | return 0; |
1495 | 1497 | ||
1496 | ubifs_assert(mutex_is_locked(&c->tnc_mutex)); | 1498 | ubifs_assert(mutex_is_locked(&c->tnc_mutex)); |
1497 | if (!c->zroot.znode) | 1499 | if (!c->zroot.znode) |
1498 | return 0; | 1500 | return 0; |
1499 | 1501 | ||
1500 | znode = ubifs_tnc_postorder_first(c->zroot.znode); | 1502 | znode = ubifs_tnc_postorder_first(c->zroot.znode); |
1501 | while (1) { | 1503 | while (1) { |
1502 | struct ubifs_znode *prev; | 1504 | struct ubifs_znode *prev; |
1503 | struct ubifs_zbranch *zbr; | 1505 | struct ubifs_zbranch *zbr; |
1504 | 1506 | ||
1505 | if (!znode->parent) | 1507 | if (!znode->parent) |
1506 | zbr = &c->zroot; | 1508 | zbr = &c->zroot; |
1507 | else | 1509 | else |
1508 | zbr = &znode->parent->zbranch[znode->iip]; | 1510 | zbr = &znode->parent->zbranch[znode->iip]; |
1509 | 1511 | ||
1510 | err = dbg_check_znode(c, zbr); | 1512 | err = dbg_check_znode(c, zbr); |
1511 | if (err) | 1513 | if (err) |
1512 | return err; | 1514 | return err; |
1513 | 1515 | ||
1514 | if (extra) { | 1516 | if (extra) { |
1515 | if (ubifs_zn_dirty(znode)) | 1517 | if (ubifs_zn_dirty(znode)) |
1516 | dirty_cnt += 1; | 1518 | dirty_cnt += 1; |
1517 | else | 1519 | else |
1518 | clean_cnt += 1; | 1520 | clean_cnt += 1; |
1519 | } | 1521 | } |
1520 | 1522 | ||
1521 | prev = znode; | 1523 | prev = znode; |
1522 | znode = ubifs_tnc_postorder_next(znode); | 1524 | znode = ubifs_tnc_postorder_next(znode); |
1523 | if (!znode) | 1525 | if (!znode) |
1524 | break; | 1526 | break; |
1525 | 1527 | ||
1526 | /* | 1528 | /* |
1527 | * If the last key of this znode is equivalent to the first key | 1529 | * If the last key of this znode is equivalent to the first key |
1528 | * of the next znode (collision), then check order of the keys. | 1530 | * of the next znode (collision), then check order of the keys. |
1529 | */ | 1531 | */ |
1530 | last = prev->child_cnt - 1; | 1532 | last = prev->child_cnt - 1; |
1531 | if (prev->level == 0 && znode->level == 0 && !c->replaying && | 1533 | if (prev->level == 0 && znode->level == 0 && !c->replaying && |
1532 | !keys_cmp(c, &prev->zbranch[last].key, | 1534 | !keys_cmp(c, &prev->zbranch[last].key, |
1533 | &znode->zbranch[0].key)) { | 1535 | &znode->zbranch[0].key)) { |
1534 | err = dbg_check_key_order(c, &prev->zbranch[last], | 1536 | err = dbg_check_key_order(c, &prev->zbranch[last], |
1535 | &znode->zbranch[0]); | 1537 | &znode->zbranch[0]); |
1536 | if (err < 0) | 1538 | if (err < 0) |
1537 | return err; | 1539 | return err; |
1538 | if (err) { | 1540 | if (err) { |
1539 | ubifs_msg("first znode"); | 1541 | ubifs_msg("first znode"); |
1540 | dbg_dump_znode(c, prev); | 1542 | dbg_dump_znode(c, prev); |
1541 | ubifs_msg("second znode"); | 1543 | ubifs_msg("second znode"); |
1542 | dbg_dump_znode(c, znode); | 1544 | dbg_dump_znode(c, znode); |
1543 | return -EINVAL; | 1545 | return -EINVAL; |
1544 | } | 1546 | } |
1545 | } | 1547 | } |
1546 | } | 1548 | } |
1547 | 1549 | ||
1548 | if (extra) { | 1550 | if (extra) { |
1549 | if (clean_cnt != atomic_long_read(&c->clean_zn_cnt)) { | 1551 | if (clean_cnt != atomic_long_read(&c->clean_zn_cnt)) { |
1550 | ubifs_err("incorrect clean_zn_cnt %ld, calculated %ld", | 1552 | ubifs_err("incorrect clean_zn_cnt %ld, calculated %ld", |
1551 | atomic_long_read(&c->clean_zn_cnt), | 1553 | atomic_long_read(&c->clean_zn_cnt), |
1552 | clean_cnt); | 1554 | clean_cnt); |
1553 | return -EINVAL; | 1555 | return -EINVAL; |
1554 | } | 1556 | } |
1555 | if (dirty_cnt != atomic_long_read(&c->dirty_zn_cnt)) { | 1557 | if (dirty_cnt != atomic_long_read(&c->dirty_zn_cnt)) { |
1556 | ubifs_err("incorrect dirty_zn_cnt %ld, calculated %ld", | 1558 | ubifs_err("incorrect dirty_zn_cnt %ld, calculated %ld", |
1557 | atomic_long_read(&c->dirty_zn_cnt), | 1559 | atomic_long_read(&c->dirty_zn_cnt), |
1558 | dirty_cnt); | 1560 | dirty_cnt); |
1559 | return -EINVAL; | 1561 | return -EINVAL; |
1560 | } | 1562 | } |
1561 | } | 1563 | } |
1562 | 1564 | ||
1563 | return 0; | 1565 | return 0; |
1564 | } | 1566 | } |
1565 | 1567 | ||
1566 | /** | 1568 | /** |
1567 | * dbg_walk_index - walk the on-flash index. | 1569 | * dbg_walk_index - walk the on-flash index. |
1568 | * @c: UBIFS file-system description object | 1570 | * @c: UBIFS file-system description object |
1569 | * @leaf_cb: called for each leaf node | 1571 | * @leaf_cb: called for each leaf node |
1570 | * @znode_cb: called for each indexing node | 1572 | * @znode_cb: called for each indexing node |
1571 | * @priv: private data which is passed to callbacks | 1573 | * @priv: private data which is passed to callbacks |
1572 | * | 1574 | * |
1573 | * This function walks the UBIFS index and calls the @leaf_cb for each leaf | 1575 | * This function walks the UBIFS index and calls the @leaf_cb for each leaf |
1574 | * node and @znode_cb for each indexing node. Returns zero in case of success | 1576 | * node and @znode_cb for each indexing node. Returns zero in case of success |
1575 | * and a negative error code in case of failure. | 1577 | * and a negative error code in case of failure. |
1576 | * | 1578 | * |
1577 | * It would be better if this function removed every znode it pulled to into | 1579 | * It would be better if this function removed every znode it pulled to into |
1578 | * the TNC, so that the behavior more closely matched the non-debugging | 1580 | * the TNC, so that the behavior more closely matched the non-debugging |
1579 | * behavior. | 1581 | * behavior. |
1580 | */ | 1582 | */ |
1581 | int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, | 1583 | int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, |
1582 | dbg_znode_callback znode_cb, void *priv) | 1584 | dbg_znode_callback znode_cb, void *priv) |
1583 | { | 1585 | { |
1584 | int err; | 1586 | int err; |
1585 | struct ubifs_zbranch *zbr; | 1587 | struct ubifs_zbranch *zbr; |
1586 | struct ubifs_znode *znode, *child; | 1588 | struct ubifs_znode *znode, *child; |
1587 | 1589 | ||
1588 | mutex_lock(&c->tnc_mutex); | 1590 | mutex_lock(&c->tnc_mutex); |
1589 | /* If the root indexing node is not in TNC - pull it */ | 1591 | /* If the root indexing node is not in TNC - pull it */ |
1590 | if (!c->zroot.znode) { | 1592 | if (!c->zroot.znode) { |
1591 | c->zroot.znode = ubifs_load_znode(c, &c->zroot, NULL, 0); | 1593 | c->zroot.znode = ubifs_load_znode(c, &c->zroot, NULL, 0); |
1592 | if (IS_ERR(c->zroot.znode)) { | 1594 | if (IS_ERR(c->zroot.znode)) { |
1593 | err = PTR_ERR(c->zroot.znode); | 1595 | err = PTR_ERR(c->zroot.znode); |
1594 | c->zroot.znode = NULL; | 1596 | c->zroot.znode = NULL; |
1595 | goto out_unlock; | 1597 | goto out_unlock; |
1596 | } | 1598 | } |
1597 | } | 1599 | } |
1598 | 1600 | ||
1599 | /* | 1601 | /* |
1600 | * We are going to traverse the indexing tree in the postorder manner. | 1602 | * We are going to traverse the indexing tree in the postorder manner. |
1601 | * Go down and find the leftmost indexing node where we are going to | 1603 | * Go down and find the leftmost indexing node where we are going to |
1602 | * start from. | 1604 | * start from. |
1603 | */ | 1605 | */ |
1604 | znode = c->zroot.znode; | 1606 | znode = c->zroot.znode; |
1605 | while (znode->level > 0) { | 1607 | while (znode->level > 0) { |
1606 | zbr = &znode->zbranch[0]; | 1608 | zbr = &znode->zbranch[0]; |
1607 | child = zbr->znode; | 1609 | child = zbr->znode; |
1608 | if (!child) { | 1610 | if (!child) { |
1609 | child = ubifs_load_znode(c, zbr, znode, 0); | 1611 | child = ubifs_load_znode(c, zbr, znode, 0); |
1610 | if (IS_ERR(child)) { | 1612 | if (IS_ERR(child)) { |
1611 | err = PTR_ERR(child); | 1613 | err = PTR_ERR(child); |
1612 | goto out_unlock; | 1614 | goto out_unlock; |
1613 | } | 1615 | } |
1614 | zbr->znode = child; | 1616 | zbr->znode = child; |
1615 | } | 1617 | } |
1616 | 1618 | ||
1617 | znode = child; | 1619 | znode = child; |
1618 | } | 1620 | } |
1619 | 1621 | ||
1620 | /* Iterate over all indexing nodes */ | 1622 | /* Iterate over all indexing nodes */ |
1621 | while (1) { | 1623 | while (1) { |
1622 | int idx; | 1624 | int idx; |
1623 | 1625 | ||
1624 | cond_resched(); | 1626 | cond_resched(); |
1625 | 1627 | ||
1626 | if (znode_cb) { | 1628 | if (znode_cb) { |
1627 | err = znode_cb(c, znode, priv); | 1629 | err = znode_cb(c, znode, priv); |
1628 | if (err) { | 1630 | if (err) { |
1629 | ubifs_err("znode checking function returned " | 1631 | ubifs_err("znode checking function returned " |
1630 | "error %d", err); | 1632 | "error %d", err); |
1631 | dbg_dump_znode(c, znode); | 1633 | dbg_dump_znode(c, znode); |
1632 | goto out_dump; | 1634 | goto out_dump; |
1633 | } | 1635 | } |
1634 | } | 1636 | } |
1635 | if (leaf_cb && znode->level == 0) { | 1637 | if (leaf_cb && znode->level == 0) { |
1636 | for (idx = 0; idx < znode->child_cnt; idx++) { | 1638 | for (idx = 0; idx < znode->child_cnt; idx++) { |
1637 | zbr = &znode->zbranch[idx]; | 1639 | zbr = &znode->zbranch[idx]; |
1638 | err = leaf_cb(c, zbr, priv); | 1640 | err = leaf_cb(c, zbr, priv); |
1639 | if (err) { | 1641 | if (err) { |
1640 | ubifs_err("leaf checking function " | 1642 | ubifs_err("leaf checking function " |
1641 | "returned error %d, for leaf " | 1643 | "returned error %d, for leaf " |
1642 | "at LEB %d:%d", | 1644 | "at LEB %d:%d", |
1643 | err, zbr->lnum, zbr->offs); | 1645 | err, zbr->lnum, zbr->offs); |
1644 | goto out_dump; | 1646 | goto out_dump; |
1645 | } | 1647 | } |
1646 | } | 1648 | } |
1647 | } | 1649 | } |
1648 | 1650 | ||
1649 | if (!znode->parent) | 1651 | if (!znode->parent) |
1650 | break; | 1652 | break; |
1651 | 1653 | ||
1652 | idx = znode->iip + 1; | 1654 | idx = znode->iip + 1; |
1653 | znode = znode->parent; | 1655 | znode = znode->parent; |
1654 | if (idx < znode->child_cnt) { | 1656 | if (idx < znode->child_cnt) { |
1655 | /* Switch to the next index in the parent */ | 1657 | /* Switch to the next index in the parent */ |
1656 | zbr = &znode->zbranch[idx]; | 1658 | zbr = &znode->zbranch[idx]; |
1657 | child = zbr->znode; | 1659 | child = zbr->znode; |
1658 | if (!child) { | 1660 | if (!child) { |
1659 | child = ubifs_load_znode(c, zbr, znode, idx); | 1661 | child = ubifs_load_znode(c, zbr, znode, idx); |
1660 | if (IS_ERR(child)) { | 1662 | if (IS_ERR(child)) { |
1661 | err = PTR_ERR(child); | 1663 | err = PTR_ERR(child); |
1662 | goto out_unlock; | 1664 | goto out_unlock; |
1663 | } | 1665 | } |
1664 | zbr->znode = child; | 1666 | zbr->znode = child; |
1665 | } | 1667 | } |
1666 | znode = child; | 1668 | znode = child; |
1667 | } else | 1669 | } else |
1668 | /* | 1670 | /* |
1669 | * This is the last child, switch to the parent and | 1671 | * This is the last child, switch to the parent and |
1670 | * continue. | 1672 | * continue. |
1671 | */ | 1673 | */ |
1672 | continue; | 1674 | continue; |
1673 | 1675 | ||
1674 | /* Go to the lowest leftmost znode in the new sub-tree */ | 1676 | /* Go to the lowest leftmost znode in the new sub-tree */ |
1675 | while (znode->level > 0) { | 1677 | while (znode->level > 0) { |
1676 | zbr = &znode->zbranch[0]; | 1678 | zbr = &znode->zbranch[0]; |
1677 | child = zbr->znode; | 1679 | child = zbr->znode; |
1678 | if (!child) { | 1680 | if (!child) { |
1679 | child = ubifs_load_znode(c, zbr, znode, 0); | 1681 | child = ubifs_load_znode(c, zbr, znode, 0); |
1680 | if (IS_ERR(child)) { | 1682 | if (IS_ERR(child)) { |
1681 | err = PTR_ERR(child); | 1683 | err = PTR_ERR(child); |
1682 | goto out_unlock; | 1684 | goto out_unlock; |
1683 | } | 1685 | } |
1684 | zbr->znode = child; | 1686 | zbr->znode = child; |
1685 | } | 1687 | } |
1686 | znode = child; | 1688 | znode = child; |
1687 | } | 1689 | } |
1688 | } | 1690 | } |
1689 | 1691 | ||
1690 | mutex_unlock(&c->tnc_mutex); | 1692 | mutex_unlock(&c->tnc_mutex); |
1691 | return 0; | 1693 | return 0; |
1692 | 1694 | ||
1693 | out_dump: | 1695 | out_dump: |
1694 | if (znode->parent) | 1696 | if (znode->parent) |
1695 | zbr = &znode->parent->zbranch[znode->iip]; | 1697 | zbr = &znode->parent->zbranch[znode->iip]; |
1696 | else | 1698 | else |
1697 | zbr = &c->zroot; | 1699 | zbr = &c->zroot; |
1698 | ubifs_msg("dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); | 1700 | ubifs_msg("dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); |
1699 | dbg_dump_znode(c, znode); | 1701 | dbg_dump_znode(c, znode); |
1700 | out_unlock: | 1702 | out_unlock: |
1701 | mutex_unlock(&c->tnc_mutex); | 1703 | mutex_unlock(&c->tnc_mutex); |
1702 | return err; | 1704 | return err; |
1703 | } | 1705 | } |
1704 | 1706 | ||
1705 | /** | 1707 | /** |
1706 | * add_size - add znode size to partially calculated index size. | 1708 | * add_size - add znode size to partially calculated index size. |
1707 | * @c: UBIFS file-system description object | 1709 | * @c: UBIFS file-system description object |
1708 | * @znode: znode to add size for | 1710 | * @znode: znode to add size for |
1709 | * @priv: partially calculated index size | 1711 | * @priv: partially calculated index size |
1710 | * | 1712 | * |
1711 | * This is a helper function for 'dbg_check_idx_size()' which is called for | 1713 | * This is a helper function for 'dbg_check_idx_size()' which is called for |
1712 | * every indexing node and adds its size to the 'long long' variable pointed to | 1714 | * every indexing node and adds its size to the 'long long' variable pointed to |
1713 | * by @priv. | 1715 | * by @priv. |
1714 | */ | 1716 | */ |
1715 | static int add_size(struct ubifs_info *c, struct ubifs_znode *znode, void *priv) | 1717 | static int add_size(struct ubifs_info *c, struct ubifs_znode *znode, void *priv) |
1716 | { | 1718 | { |
1717 | long long *idx_size = priv; | 1719 | long long *idx_size = priv; |
1718 | int add; | 1720 | int add; |
1719 | 1721 | ||
1720 | add = ubifs_idx_node_sz(c, znode->child_cnt); | 1722 | add = ubifs_idx_node_sz(c, znode->child_cnt); |
1721 | add = ALIGN(add, 8); | 1723 | add = ALIGN(add, 8); |
1722 | *idx_size += add; | 1724 | *idx_size += add; |
1723 | return 0; | 1725 | return 0; |
1724 | } | 1726 | } |
1725 | 1727 | ||
1726 | /** | 1728 | /** |
1727 | * dbg_check_idx_size - check index size. | 1729 | * dbg_check_idx_size - check index size. |
1728 | * @c: UBIFS file-system description object | 1730 | * @c: UBIFS file-system description object |
1729 | * @idx_size: size to check | 1731 | * @idx_size: size to check |
1730 | * | 1732 | * |
1731 | * This function walks the UBIFS index, calculates its size and checks that the | 1733 | * This function walks the UBIFS index, calculates its size and checks that the |
1732 | * size is equivalent to @idx_size. Returns zero in case of success and a | 1734 | * size is equivalent to @idx_size. Returns zero in case of success and a |
1733 | * negative error code in case of failure. | 1735 | * negative error code in case of failure. |
1734 | */ | 1736 | */ |
1735 | int dbg_check_idx_size(struct ubifs_info *c, long long idx_size) | 1737 | int dbg_check_idx_size(struct ubifs_info *c, long long idx_size) |
1736 | { | 1738 | { |
1737 | int err; | 1739 | int err; |
1738 | long long calc = 0; | 1740 | long long calc = 0; |
1739 | 1741 | ||
1740 | if (!(ubifs_chk_flags & UBIFS_CHK_IDX_SZ)) | 1742 | if (!(ubifs_chk_flags & UBIFS_CHK_IDX_SZ)) |
1741 | return 0; | 1743 | return 0; |
1742 | 1744 | ||
1743 | err = dbg_walk_index(c, NULL, add_size, &calc); | 1745 | err = dbg_walk_index(c, NULL, add_size, &calc); |
1744 | if (err) { | 1746 | if (err) { |
1745 | ubifs_err("error %d while walking the index", err); | 1747 | ubifs_err("error %d while walking the index", err); |
1746 | return err; | 1748 | return err; |
1747 | } | 1749 | } |
1748 | 1750 | ||
1749 | if (calc != idx_size) { | 1751 | if (calc != idx_size) { |
1750 | ubifs_err("index size check failed: calculated size is %lld, " | 1752 | ubifs_err("index size check failed: calculated size is %lld, " |
1751 | "should be %lld", calc, idx_size); | 1753 | "should be %lld", calc, idx_size); |
1752 | dump_stack(); | 1754 | dump_stack(); |
1753 | return -EINVAL; | 1755 | return -EINVAL; |
1754 | } | 1756 | } |
1755 | 1757 | ||
1756 | return 0; | 1758 | return 0; |
1757 | } | 1759 | } |
1758 | 1760 | ||
1759 | /** | 1761 | /** |
1760 | * struct fsck_inode - information about an inode used when checking the file-system. | 1762 | * struct fsck_inode - information about an inode used when checking the file-system. |
1761 | * @rb: link in the RB-tree of inodes | 1763 | * @rb: link in the RB-tree of inodes |
1762 | * @inum: inode number | 1764 | * @inum: inode number |
1763 | * @mode: inode type, permissions, etc | 1765 | * @mode: inode type, permissions, etc |
1764 | * @nlink: inode link count | 1766 | * @nlink: inode link count |
1765 | * @xattr_cnt: count of extended attributes | 1767 | * @xattr_cnt: count of extended attributes |
1766 | * @references: how many directory/xattr entries refer this inode (calculated | 1768 | * @references: how many directory/xattr entries refer this inode (calculated |
1767 | * while walking the index) | 1769 | * while walking the index) |
1768 | * @calc_cnt: for directory inode count of child directories | 1770 | * @calc_cnt: for directory inode count of child directories |
1769 | * @size: inode size (read from on-flash inode) | 1771 | * @size: inode size (read from on-flash inode) |
1770 | * @xattr_sz: summary size of all extended attributes (read from on-flash | 1772 | * @xattr_sz: summary size of all extended attributes (read from on-flash |
1771 | * inode) | 1773 | * inode) |
1772 | * @calc_sz: for directories calculated directory size | 1774 | * @calc_sz: for directories calculated directory size |
1773 | * @calc_xcnt: count of extended attributes | 1775 | * @calc_xcnt: count of extended attributes |
1774 | * @calc_xsz: calculated summary size of all extended attributes | 1776 | * @calc_xsz: calculated summary size of all extended attributes |
1775 | * @xattr_nms: sum of lengths of all extended attribute names belonging to this | 1777 | * @xattr_nms: sum of lengths of all extended attribute names belonging to this |
1776 | * inode (read from on-flash inode) | 1778 | * inode (read from on-flash inode) |
1777 | * @calc_xnms: calculated sum of lengths of all extended attribute names | 1779 | * @calc_xnms: calculated sum of lengths of all extended attribute names |
1778 | */ | 1780 | */ |
1779 | struct fsck_inode { | 1781 | struct fsck_inode { |
1780 | struct rb_node rb; | 1782 | struct rb_node rb; |
1781 | ino_t inum; | 1783 | ino_t inum; |
1782 | umode_t mode; | 1784 | umode_t mode; |
1783 | unsigned int nlink; | 1785 | unsigned int nlink; |
1784 | unsigned int xattr_cnt; | 1786 | unsigned int xattr_cnt; |
1785 | int references; | 1787 | int references; |
1786 | int calc_cnt; | 1788 | int calc_cnt; |
1787 | long long size; | 1789 | long long size; |
1788 | unsigned int xattr_sz; | 1790 | unsigned int xattr_sz; |
1789 | long long calc_sz; | 1791 | long long calc_sz; |
1790 | long long calc_xcnt; | 1792 | long long calc_xcnt; |
1791 | long long calc_xsz; | 1793 | long long calc_xsz; |
1792 | unsigned int xattr_nms; | 1794 | unsigned int xattr_nms; |
1793 | long long calc_xnms; | 1795 | long long calc_xnms; |
1794 | }; | 1796 | }; |
1795 | 1797 | ||
1796 | /** | 1798 | /** |
1797 | * struct fsck_data - private FS checking information. | 1799 | * struct fsck_data - private FS checking information. |
1798 | * @inodes: RB-tree of all inodes (contains @struct fsck_inode objects) | 1800 | * @inodes: RB-tree of all inodes (contains @struct fsck_inode objects) |
1799 | */ | 1801 | */ |
1800 | struct fsck_data { | 1802 | struct fsck_data { |
1801 | struct rb_root inodes; | 1803 | struct rb_root inodes; |
1802 | }; | 1804 | }; |
1803 | 1805 | ||
1804 | /** | 1806 | /** |
1805 | * add_inode - add inode information to RB-tree of inodes. | 1807 | * add_inode - add inode information to RB-tree of inodes. |
1806 | * @c: UBIFS file-system description object | 1808 | * @c: UBIFS file-system description object |
1807 | * @fsckd: FS checking information | 1809 | * @fsckd: FS checking information |
1808 | * @ino: raw UBIFS inode to add | 1810 | * @ino: raw UBIFS inode to add |
1809 | * | 1811 | * |
1810 | * This is a helper function for 'check_leaf()' which adds information about | 1812 | * This is a helper function for 'check_leaf()' which adds information about |
1811 | * inode @ino to the RB-tree of inodes. Returns inode information pointer in | 1813 | * inode @ino to the RB-tree of inodes. Returns inode information pointer in |
1812 | * case of success and a negative error code in case of failure. | 1814 | * case of success and a negative error code in case of failure. |
1813 | */ | 1815 | */ |
1814 | static struct fsck_inode *add_inode(struct ubifs_info *c, | 1816 | static struct fsck_inode *add_inode(struct ubifs_info *c, |
1815 | struct fsck_data *fsckd, | 1817 | struct fsck_data *fsckd, |
1816 | struct ubifs_ino_node *ino) | 1818 | struct ubifs_ino_node *ino) |
1817 | { | 1819 | { |
1818 | struct rb_node **p, *parent = NULL; | 1820 | struct rb_node **p, *parent = NULL; |
1819 | struct fsck_inode *fscki; | 1821 | struct fsck_inode *fscki; |
1820 | ino_t inum = key_inum_flash(c, &ino->key); | 1822 | ino_t inum = key_inum_flash(c, &ino->key); |
1821 | struct inode *inode; | 1823 | struct inode *inode; |
1822 | struct ubifs_inode *ui; | 1824 | struct ubifs_inode *ui; |
1823 | 1825 | ||
1824 | p = &fsckd->inodes.rb_node; | 1826 | p = &fsckd->inodes.rb_node; |
1825 | while (*p) { | 1827 | while (*p) { |
1826 | parent = *p; | 1828 | parent = *p; |
1827 | fscki = rb_entry(parent, struct fsck_inode, rb); | 1829 | fscki = rb_entry(parent, struct fsck_inode, rb); |
1828 | if (inum < fscki->inum) | 1830 | if (inum < fscki->inum) |
1829 | p = &(*p)->rb_left; | 1831 | p = &(*p)->rb_left; |
1830 | else if (inum > fscki->inum) | 1832 | else if (inum > fscki->inum) |
1831 | p = &(*p)->rb_right; | 1833 | p = &(*p)->rb_right; |
1832 | else | 1834 | else |
1833 | return fscki; | 1835 | return fscki; |
1834 | } | 1836 | } |
1835 | 1837 | ||
1836 | if (inum > c->highest_inum) { | 1838 | if (inum > c->highest_inum) { |
1837 | ubifs_err("too high inode number, max. is %lu", | 1839 | ubifs_err("too high inode number, max. is %lu", |
1838 | (unsigned long)c->highest_inum); | 1840 | (unsigned long)c->highest_inum); |
1839 | return ERR_PTR(-EINVAL); | 1841 | return ERR_PTR(-EINVAL); |
1840 | } | 1842 | } |
1841 | 1843 | ||
1842 | fscki = kzalloc(sizeof(struct fsck_inode), GFP_NOFS); | 1844 | fscki = kzalloc(sizeof(struct fsck_inode), GFP_NOFS); |
1843 | if (!fscki) | 1845 | if (!fscki) |
1844 | return ERR_PTR(-ENOMEM); | 1846 | return ERR_PTR(-ENOMEM); |
1845 | 1847 | ||
1846 | inode = ilookup(c->vfs_sb, inum); | 1848 | inode = ilookup(c->vfs_sb, inum); |
1847 | 1849 | ||
1848 | fscki->inum = inum; | 1850 | fscki->inum = inum; |
1849 | /* | 1851 | /* |
1850 | * If the inode is present in the VFS inode cache, use it instead of | 1852 | * If the inode is present in the VFS inode cache, use it instead of |
1851 | * the on-flash inode which might be out-of-date. E.g., the size might | 1853 | * the on-flash inode which might be out-of-date. E.g., the size might |
1852 | * be out-of-date. If we do not do this, the following may happen, for | 1854 | * be out-of-date. If we do not do this, the following may happen, for |
1853 | * example: | 1855 | * example: |
1854 | * 1. A power cut happens | 1856 | * 1. A power cut happens |
1855 | * 2. We mount the file-system R/O, the replay process fixes up the | 1857 | * 2. We mount the file-system R/O, the replay process fixes up the |
1856 | * inode size in the VFS cache, but on on-flash. | 1858 | * inode size in the VFS cache, but on on-flash. |
1857 | * 3. 'check_leaf()' fails because it hits a data node beyond inode | 1859 | * 3. 'check_leaf()' fails because it hits a data node beyond inode |
1858 | * size. | 1860 | * size. |
1859 | */ | 1861 | */ |
1860 | if (!inode) { | 1862 | if (!inode) { |
1861 | fscki->nlink = le32_to_cpu(ino->nlink); | 1863 | fscki->nlink = le32_to_cpu(ino->nlink); |
1862 | fscki->size = le64_to_cpu(ino->size); | 1864 | fscki->size = le64_to_cpu(ino->size); |
1863 | fscki->xattr_cnt = le32_to_cpu(ino->xattr_cnt); | 1865 | fscki->xattr_cnt = le32_to_cpu(ino->xattr_cnt); |
1864 | fscki->xattr_sz = le32_to_cpu(ino->xattr_size); | 1866 | fscki->xattr_sz = le32_to_cpu(ino->xattr_size); |
1865 | fscki->xattr_nms = le32_to_cpu(ino->xattr_names); | 1867 | fscki->xattr_nms = le32_to_cpu(ino->xattr_names); |
1866 | fscki->mode = le32_to_cpu(ino->mode); | 1868 | fscki->mode = le32_to_cpu(ino->mode); |
1867 | } else { | 1869 | } else { |
1868 | ui = ubifs_inode(inode); | 1870 | ui = ubifs_inode(inode); |
1869 | fscki->nlink = inode->i_nlink; | 1871 | fscki->nlink = inode->i_nlink; |
1870 | fscki->size = inode->i_size; | 1872 | fscki->size = inode->i_size; |
1871 | fscki->xattr_cnt = ui->xattr_cnt; | 1873 | fscki->xattr_cnt = ui->xattr_cnt; |
1872 | fscki->xattr_sz = ui->xattr_size; | 1874 | fscki->xattr_sz = ui->xattr_size; |
1873 | fscki->xattr_nms = ui->xattr_names; | 1875 | fscki->xattr_nms = ui->xattr_names; |
1874 | fscki->mode = inode->i_mode; | 1876 | fscki->mode = inode->i_mode; |
1875 | iput(inode); | 1877 | iput(inode); |
1876 | } | 1878 | } |
1877 | 1879 | ||
1878 | if (S_ISDIR(fscki->mode)) { | 1880 | if (S_ISDIR(fscki->mode)) { |
1879 | fscki->calc_sz = UBIFS_INO_NODE_SZ; | 1881 | fscki->calc_sz = UBIFS_INO_NODE_SZ; |
1880 | fscki->calc_cnt = 2; | 1882 | fscki->calc_cnt = 2; |
1881 | } | 1883 | } |
1882 | 1884 | ||
1883 | rb_link_node(&fscki->rb, parent, p); | 1885 | rb_link_node(&fscki->rb, parent, p); |
1884 | rb_insert_color(&fscki->rb, &fsckd->inodes); | 1886 | rb_insert_color(&fscki->rb, &fsckd->inodes); |
1885 | 1887 | ||
1886 | return fscki; | 1888 | return fscki; |
1887 | } | 1889 | } |
1888 | 1890 | ||
1889 | /** | 1891 | /** |
1890 | * search_inode - search inode in the RB-tree of inodes. | 1892 | * search_inode - search inode in the RB-tree of inodes. |
1891 | * @fsckd: FS checking information | 1893 | * @fsckd: FS checking information |
1892 | * @inum: inode number to search | 1894 | * @inum: inode number to search |
1893 | * | 1895 | * |
1894 | * This is a helper function for 'check_leaf()' which searches inode @inum in | 1896 | * This is a helper function for 'check_leaf()' which searches inode @inum in |
1895 | * the RB-tree of inodes and returns an inode information pointer or %NULL if | 1897 | * the RB-tree of inodes and returns an inode information pointer or %NULL if |
1896 | * the inode was not found. | 1898 | * the inode was not found. |
1897 | */ | 1899 | */ |
1898 | static struct fsck_inode *search_inode(struct fsck_data *fsckd, ino_t inum) | 1900 | static struct fsck_inode *search_inode(struct fsck_data *fsckd, ino_t inum) |
1899 | { | 1901 | { |
1900 | struct rb_node *p; | 1902 | struct rb_node *p; |
1901 | struct fsck_inode *fscki; | 1903 | struct fsck_inode *fscki; |
1902 | 1904 | ||
1903 | p = fsckd->inodes.rb_node; | 1905 | p = fsckd->inodes.rb_node; |
1904 | while (p) { | 1906 | while (p) { |
1905 | fscki = rb_entry(p, struct fsck_inode, rb); | 1907 | fscki = rb_entry(p, struct fsck_inode, rb); |
1906 | if (inum < fscki->inum) | 1908 | if (inum < fscki->inum) |
1907 | p = p->rb_left; | 1909 | p = p->rb_left; |
1908 | else if (inum > fscki->inum) | 1910 | else if (inum > fscki->inum) |
1909 | p = p->rb_right; | 1911 | p = p->rb_right; |
1910 | else | 1912 | else |
1911 | return fscki; | 1913 | return fscki; |
1912 | } | 1914 | } |
1913 | return NULL; | 1915 | return NULL; |
1914 | } | 1916 | } |
1915 | 1917 | ||
1916 | /** | 1918 | /** |
1917 | * read_add_inode - read inode node and add it to RB-tree of inodes. | 1919 | * read_add_inode - read inode node and add it to RB-tree of inodes. |
1918 | * @c: UBIFS file-system description object | 1920 | * @c: UBIFS file-system description object |
1919 | * @fsckd: FS checking information | 1921 | * @fsckd: FS checking information |
1920 | * @inum: inode number to read | 1922 | * @inum: inode number to read |
1921 | * | 1923 | * |
1922 | * This is a helper function for 'check_leaf()' which finds inode node @inum in | 1924 | * This is a helper function for 'check_leaf()' which finds inode node @inum in |
1923 | * the index, reads it, and adds it to the RB-tree of inodes. Returns inode | 1925 | * the index, reads it, and adds it to the RB-tree of inodes. Returns inode |
1924 | * information pointer in case of success and a negative error code in case of | 1926 | * information pointer in case of success and a negative error code in case of |
1925 | * failure. | 1927 | * failure. |
1926 | */ | 1928 | */ |
1927 | static struct fsck_inode *read_add_inode(struct ubifs_info *c, | 1929 | static struct fsck_inode *read_add_inode(struct ubifs_info *c, |
1928 | struct fsck_data *fsckd, ino_t inum) | 1930 | struct fsck_data *fsckd, ino_t inum) |
1929 | { | 1931 | { |
1930 | int n, err; | 1932 | int n, err; |
1931 | union ubifs_key key; | 1933 | union ubifs_key key; |
1932 | struct ubifs_znode *znode; | 1934 | struct ubifs_znode *znode; |
1933 | struct ubifs_zbranch *zbr; | 1935 | struct ubifs_zbranch *zbr; |
1934 | struct ubifs_ino_node *ino; | 1936 | struct ubifs_ino_node *ino; |
1935 | struct fsck_inode *fscki; | 1937 | struct fsck_inode *fscki; |
1936 | 1938 | ||
1937 | fscki = search_inode(fsckd, inum); | 1939 | fscki = search_inode(fsckd, inum); |
1938 | if (fscki) | 1940 | if (fscki) |
1939 | return fscki; | 1941 | return fscki; |
1940 | 1942 | ||
1941 | ino_key_init(c, &key, inum); | 1943 | ino_key_init(c, &key, inum); |
1942 | err = ubifs_lookup_level0(c, &key, &znode, &n); | 1944 | err = ubifs_lookup_level0(c, &key, &znode, &n); |
1943 | if (!err) { | 1945 | if (!err) { |
1944 | ubifs_err("inode %lu not found in index", (unsigned long)inum); | 1946 | ubifs_err("inode %lu not found in index", (unsigned long)inum); |
1945 | return ERR_PTR(-ENOENT); | 1947 | return ERR_PTR(-ENOENT); |
1946 | } else if (err < 0) { | 1948 | } else if (err < 0) { |
1947 | ubifs_err("error %d while looking up inode %lu", | 1949 | ubifs_err("error %d while looking up inode %lu", |
1948 | err, (unsigned long)inum); | 1950 | err, (unsigned long)inum); |
1949 | return ERR_PTR(err); | 1951 | return ERR_PTR(err); |
1950 | } | 1952 | } |
1951 | 1953 | ||
1952 | zbr = &znode->zbranch[n]; | 1954 | zbr = &znode->zbranch[n]; |
1953 | if (zbr->len < UBIFS_INO_NODE_SZ) { | 1955 | if (zbr->len < UBIFS_INO_NODE_SZ) { |
1954 | ubifs_err("bad node %lu node length %d", | 1956 | ubifs_err("bad node %lu node length %d", |
1955 | (unsigned long)inum, zbr->len); | 1957 | (unsigned long)inum, zbr->len); |
1956 | return ERR_PTR(-EINVAL); | 1958 | return ERR_PTR(-EINVAL); |
1957 | } | 1959 | } |
1958 | 1960 | ||
1959 | ino = kmalloc(zbr->len, GFP_NOFS); | 1961 | ino = kmalloc(zbr->len, GFP_NOFS); |
1960 | if (!ino) | 1962 | if (!ino) |
1961 | return ERR_PTR(-ENOMEM); | 1963 | return ERR_PTR(-ENOMEM); |
1962 | 1964 | ||
1963 | err = ubifs_tnc_read_node(c, zbr, ino); | 1965 | err = ubifs_tnc_read_node(c, zbr, ino); |
1964 | if (err) { | 1966 | if (err) { |
1965 | ubifs_err("cannot read inode node at LEB %d:%d, error %d", | 1967 | ubifs_err("cannot read inode node at LEB %d:%d, error %d", |
1966 | zbr->lnum, zbr->offs, err); | 1968 | zbr->lnum, zbr->offs, err); |
1967 | kfree(ino); | 1969 | kfree(ino); |
1968 | return ERR_PTR(err); | 1970 | return ERR_PTR(err); |
1969 | } | 1971 | } |
1970 | 1972 | ||
1971 | fscki = add_inode(c, fsckd, ino); | 1973 | fscki = add_inode(c, fsckd, ino); |
1972 | kfree(ino); | 1974 | kfree(ino); |
1973 | if (IS_ERR(fscki)) { | 1975 | if (IS_ERR(fscki)) { |
1974 | ubifs_err("error %ld while adding inode %lu node", | 1976 | ubifs_err("error %ld while adding inode %lu node", |
1975 | PTR_ERR(fscki), (unsigned long)inum); | 1977 | PTR_ERR(fscki), (unsigned long)inum); |
1976 | return fscki; | 1978 | return fscki; |
1977 | } | 1979 | } |
1978 | 1980 | ||
1979 | return fscki; | 1981 | return fscki; |
1980 | } | 1982 | } |
1981 | 1983 | ||
1982 | /** | 1984 | /** |
1983 | * check_leaf - check leaf node. | 1985 | * check_leaf - check leaf node. |
1984 | * @c: UBIFS file-system description object | 1986 | * @c: UBIFS file-system description object |
1985 | * @zbr: zbranch of the leaf node to check | 1987 | * @zbr: zbranch of the leaf node to check |
1986 | * @priv: FS checking information | 1988 | * @priv: FS checking information |
1987 | * | 1989 | * |
1988 | * This is a helper function for 'dbg_check_filesystem()' which is called for | 1990 | * This is a helper function for 'dbg_check_filesystem()' which is called for |
1989 | * every single leaf node while walking the indexing tree. It checks that the | 1991 | * every single leaf node while walking the indexing tree. It checks that the |
1990 | * leaf node referred from the indexing tree exists, has correct CRC, and does | 1992 | * leaf node referred from the indexing tree exists, has correct CRC, and does |
1991 | * some other basic validation. This function is also responsible for building | 1993 | * some other basic validation. This function is also responsible for building |
1992 | * an RB-tree of inodes - it adds all inodes into the RB-tree. It also | 1994 | * an RB-tree of inodes - it adds all inodes into the RB-tree. It also |
1993 | * calculates reference count, size, etc for each inode in order to later | 1995 | * calculates reference count, size, etc for each inode in order to later |
1994 | * compare them to the information stored inside the inodes and detect possible | 1996 | * compare them to the information stored inside the inodes and detect possible |
1995 | * inconsistencies. Returns zero in case of success and a negative error code | 1997 | * inconsistencies. Returns zero in case of success and a negative error code |
1996 | * in case of failure. | 1998 | * in case of failure. |
1997 | */ | 1999 | */ |
1998 | static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr, | 2000 | static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr, |
1999 | void *priv) | 2001 | void *priv) |
2000 | { | 2002 | { |
2001 | ino_t inum; | 2003 | ino_t inum; |
2002 | void *node; | 2004 | void *node; |
2003 | struct ubifs_ch *ch; | 2005 | struct ubifs_ch *ch; |
2004 | int err, type = key_type(c, &zbr->key); | 2006 | int err, type = key_type(c, &zbr->key); |
2005 | struct fsck_inode *fscki; | 2007 | struct fsck_inode *fscki; |
2006 | 2008 | ||
2007 | if (zbr->len < UBIFS_CH_SZ) { | 2009 | if (zbr->len < UBIFS_CH_SZ) { |
2008 | ubifs_err("bad leaf length %d (LEB %d:%d)", | 2010 | ubifs_err("bad leaf length %d (LEB %d:%d)", |
2009 | zbr->len, zbr->lnum, zbr->offs); | 2011 | zbr->len, zbr->lnum, zbr->offs); |
2010 | return -EINVAL; | 2012 | return -EINVAL; |
2011 | } | 2013 | } |
2012 | 2014 | ||
2013 | node = kmalloc(zbr->len, GFP_NOFS); | 2015 | node = kmalloc(zbr->len, GFP_NOFS); |
2014 | if (!node) | 2016 | if (!node) |
2015 | return -ENOMEM; | 2017 | return -ENOMEM; |
2016 | 2018 | ||
2017 | err = ubifs_tnc_read_node(c, zbr, node); | 2019 | err = ubifs_tnc_read_node(c, zbr, node); |
2018 | if (err) { | 2020 | if (err) { |
2019 | ubifs_err("cannot read leaf node at LEB %d:%d, error %d", | 2021 | ubifs_err("cannot read leaf node at LEB %d:%d, error %d", |
2020 | zbr->lnum, zbr->offs, err); | 2022 | zbr->lnum, zbr->offs, err); |
2021 | goto out_free; | 2023 | goto out_free; |
2022 | } | 2024 | } |
2023 | 2025 | ||
2024 | /* If this is an inode node, add it to RB-tree of inodes */ | 2026 | /* If this is an inode node, add it to RB-tree of inodes */ |
2025 | if (type == UBIFS_INO_KEY) { | 2027 | if (type == UBIFS_INO_KEY) { |
2026 | fscki = add_inode(c, priv, node); | 2028 | fscki = add_inode(c, priv, node); |
2027 | if (IS_ERR(fscki)) { | 2029 | if (IS_ERR(fscki)) { |
2028 | err = PTR_ERR(fscki); | 2030 | err = PTR_ERR(fscki); |
2029 | ubifs_err("error %d while adding inode node", err); | 2031 | ubifs_err("error %d while adding inode node", err); |
2030 | goto out_dump; | 2032 | goto out_dump; |
2031 | } | 2033 | } |
2032 | goto out; | 2034 | goto out; |
2033 | } | 2035 | } |
2034 | 2036 | ||
2035 | if (type != UBIFS_DENT_KEY && type != UBIFS_XENT_KEY && | 2037 | if (type != UBIFS_DENT_KEY && type != UBIFS_XENT_KEY && |
2036 | type != UBIFS_DATA_KEY) { | 2038 | type != UBIFS_DATA_KEY) { |
2037 | ubifs_err("unexpected node type %d at LEB %d:%d", | 2039 | ubifs_err("unexpected node type %d at LEB %d:%d", |
2038 | type, zbr->lnum, zbr->offs); | 2040 | type, zbr->lnum, zbr->offs); |
2039 | err = -EINVAL; | 2041 | err = -EINVAL; |
2040 | goto out_free; | 2042 | goto out_free; |
2041 | } | 2043 | } |
2042 | 2044 | ||
2043 | ch = node; | 2045 | ch = node; |
2044 | if (le64_to_cpu(ch->sqnum) > c->max_sqnum) { | 2046 | if (le64_to_cpu(ch->sqnum) > c->max_sqnum) { |
2045 | ubifs_err("too high sequence number, max. is %llu", | 2047 | ubifs_err("too high sequence number, max. is %llu", |
2046 | c->max_sqnum); | 2048 | c->max_sqnum); |
2047 | err = -EINVAL; | 2049 | err = -EINVAL; |
2048 | goto out_dump; | 2050 | goto out_dump; |
2049 | } | 2051 | } |
2050 | 2052 | ||
2051 | if (type == UBIFS_DATA_KEY) { | 2053 | if (type == UBIFS_DATA_KEY) { |
2052 | long long blk_offs; | 2054 | long long blk_offs; |
2053 | struct ubifs_data_node *dn = node; | 2055 | struct ubifs_data_node *dn = node; |
2054 | 2056 | ||
2055 | /* | 2057 | /* |
2056 | * Search the inode node this data node belongs to and insert | 2058 | * Search the inode node this data node belongs to and insert |
2057 | * it to the RB-tree of inodes. | 2059 | * it to the RB-tree of inodes. |
2058 | */ | 2060 | */ |
2059 | inum = key_inum_flash(c, &dn->key); | 2061 | inum = key_inum_flash(c, &dn->key); |
2060 | fscki = read_add_inode(c, priv, inum); | 2062 | fscki = read_add_inode(c, priv, inum); |
2061 | if (IS_ERR(fscki)) { | 2063 | if (IS_ERR(fscki)) { |
2062 | err = PTR_ERR(fscki); | 2064 | err = PTR_ERR(fscki); |
2063 | ubifs_err("error %d while processing data node and " | 2065 | ubifs_err("error %d while processing data node and " |
2064 | "trying to find inode node %lu", | 2066 | "trying to find inode node %lu", |
2065 | err, (unsigned long)inum); | 2067 | err, (unsigned long)inum); |
2066 | goto out_dump; | 2068 | goto out_dump; |
2067 | } | 2069 | } |
2068 | 2070 | ||
2069 | /* Make sure the data node is within inode size */ | 2071 | /* Make sure the data node is within inode size */ |
2070 | blk_offs = key_block_flash(c, &dn->key); | 2072 | blk_offs = key_block_flash(c, &dn->key); |
2071 | blk_offs <<= UBIFS_BLOCK_SHIFT; | 2073 | blk_offs <<= UBIFS_BLOCK_SHIFT; |
2072 | blk_offs += le32_to_cpu(dn->size); | 2074 | blk_offs += le32_to_cpu(dn->size); |
2073 | if (blk_offs > fscki->size) { | 2075 | if (blk_offs > fscki->size) { |
2074 | ubifs_err("data node at LEB %d:%d is not within inode " | 2076 | ubifs_err("data node at LEB %d:%d is not within inode " |
2075 | "size %lld", zbr->lnum, zbr->offs, | 2077 | "size %lld", zbr->lnum, zbr->offs, |
2076 | fscki->size); | 2078 | fscki->size); |
2077 | err = -EINVAL; | 2079 | err = -EINVAL; |
2078 | goto out_dump; | 2080 | goto out_dump; |
2079 | } | 2081 | } |
2080 | } else { | 2082 | } else { |
2081 | int nlen; | 2083 | int nlen; |
2082 | struct ubifs_dent_node *dent = node; | 2084 | struct ubifs_dent_node *dent = node; |
2083 | struct fsck_inode *fscki1; | 2085 | struct fsck_inode *fscki1; |
2084 | 2086 | ||
2085 | err = ubifs_validate_entry(c, dent); | 2087 | err = ubifs_validate_entry(c, dent); |
2086 | if (err) | 2088 | if (err) |
2087 | goto out_dump; | 2089 | goto out_dump; |
2088 | 2090 | ||
2089 | /* | 2091 | /* |
2090 | * Search the inode node this entry refers to and the parent | 2092 | * Search the inode node this entry refers to and the parent |
2091 | * inode node and insert them to the RB-tree of inodes. | 2093 | * inode node and insert them to the RB-tree of inodes. |
2092 | */ | 2094 | */ |
2093 | inum = le64_to_cpu(dent->inum); | 2095 | inum = le64_to_cpu(dent->inum); |
2094 | fscki = read_add_inode(c, priv, inum); | 2096 | fscki = read_add_inode(c, priv, inum); |
2095 | if (IS_ERR(fscki)) { | 2097 | if (IS_ERR(fscki)) { |
2096 | err = PTR_ERR(fscki); | 2098 | err = PTR_ERR(fscki); |
2097 | ubifs_err("error %d while processing entry node and " | 2099 | ubifs_err("error %d while processing entry node and " |
2098 | "trying to find inode node %lu", | 2100 | "trying to find inode node %lu", |
2099 | err, (unsigned long)inum); | 2101 | err, (unsigned long)inum); |
2100 | goto out_dump; | 2102 | goto out_dump; |
2101 | } | 2103 | } |
2102 | 2104 | ||
2103 | /* Count how many direntries or xentries refers this inode */ | 2105 | /* Count how many direntries or xentries refers this inode */ |
2104 | fscki->references += 1; | 2106 | fscki->references += 1; |
2105 | 2107 | ||
2106 | inum = key_inum_flash(c, &dent->key); | 2108 | inum = key_inum_flash(c, &dent->key); |
2107 | fscki1 = read_add_inode(c, priv, inum); | 2109 | fscki1 = read_add_inode(c, priv, inum); |
2108 | if (IS_ERR(fscki1)) { | 2110 | if (IS_ERR(fscki1)) { |
2109 | err = PTR_ERR(fscki1); | 2111 | err = PTR_ERR(fscki1); |
2110 | ubifs_err("error %d while processing entry node and " | 2112 | ubifs_err("error %d while processing entry node and " |
2111 | "trying to find parent inode node %lu", | 2113 | "trying to find parent inode node %lu", |
2112 | err, (unsigned long)inum); | 2114 | err, (unsigned long)inum); |
2113 | goto out_dump; | 2115 | goto out_dump; |
2114 | } | 2116 | } |
2115 | 2117 | ||
2116 | nlen = le16_to_cpu(dent->nlen); | 2118 | nlen = le16_to_cpu(dent->nlen); |
2117 | if (type == UBIFS_XENT_KEY) { | 2119 | if (type == UBIFS_XENT_KEY) { |
2118 | fscki1->calc_xcnt += 1; | 2120 | fscki1->calc_xcnt += 1; |
2119 | fscki1->calc_xsz += CALC_DENT_SIZE(nlen); | 2121 | fscki1->calc_xsz += CALC_DENT_SIZE(nlen); |
2120 | fscki1->calc_xsz += CALC_XATTR_BYTES(fscki->size); | 2122 | fscki1->calc_xsz += CALC_XATTR_BYTES(fscki->size); |
2121 | fscki1->calc_xnms += nlen; | 2123 | fscki1->calc_xnms += nlen; |
2122 | } else { | 2124 | } else { |
2123 | fscki1->calc_sz += CALC_DENT_SIZE(nlen); | 2125 | fscki1->calc_sz += CALC_DENT_SIZE(nlen); |
2124 | if (dent->type == UBIFS_ITYPE_DIR) | 2126 | if (dent->type == UBIFS_ITYPE_DIR) |
2125 | fscki1->calc_cnt += 1; | 2127 | fscki1->calc_cnt += 1; |
2126 | } | 2128 | } |
2127 | } | 2129 | } |
2128 | 2130 | ||
2129 | out: | 2131 | out: |
2130 | kfree(node); | 2132 | kfree(node); |
2131 | return 0; | 2133 | return 0; |
2132 | 2134 | ||
2133 | out_dump: | 2135 | out_dump: |
2134 | ubifs_msg("dump of node at LEB %d:%d", zbr->lnum, zbr->offs); | 2136 | ubifs_msg("dump of node at LEB %d:%d", zbr->lnum, zbr->offs); |
2135 | dbg_dump_node(c, node); | 2137 | dbg_dump_node(c, node); |
2136 | out_free: | 2138 | out_free: |
2137 | kfree(node); | 2139 | kfree(node); |
2138 | return err; | 2140 | return err; |
2139 | } | 2141 | } |
2140 | 2142 | ||
2141 | /** | 2143 | /** |
2142 | * free_inodes - free RB-tree of inodes. | 2144 | * free_inodes - free RB-tree of inodes. |
2143 | * @fsckd: FS checking information | 2145 | * @fsckd: FS checking information |
2144 | */ | 2146 | */ |
2145 | static void free_inodes(struct fsck_data *fsckd) | 2147 | static void free_inodes(struct fsck_data *fsckd) |
2146 | { | 2148 | { |
2147 | struct rb_node *this = fsckd->inodes.rb_node; | 2149 | struct rb_node *this = fsckd->inodes.rb_node; |
2148 | struct fsck_inode *fscki; | 2150 | struct fsck_inode *fscki; |
2149 | 2151 | ||
2150 | while (this) { | 2152 | while (this) { |
2151 | if (this->rb_left) | 2153 | if (this->rb_left) |
2152 | this = this->rb_left; | 2154 | this = this->rb_left; |
2153 | else if (this->rb_right) | 2155 | else if (this->rb_right) |
2154 | this = this->rb_right; | 2156 | this = this->rb_right; |
2155 | else { | 2157 | else { |
2156 | fscki = rb_entry(this, struct fsck_inode, rb); | 2158 | fscki = rb_entry(this, struct fsck_inode, rb); |
2157 | this = rb_parent(this); | 2159 | this = rb_parent(this); |
2158 | if (this) { | 2160 | if (this) { |
2159 | if (this->rb_left == &fscki->rb) | 2161 | if (this->rb_left == &fscki->rb) |
2160 | this->rb_left = NULL; | 2162 | this->rb_left = NULL; |
2161 | else | 2163 | else |
2162 | this->rb_right = NULL; | 2164 | this->rb_right = NULL; |
2163 | } | 2165 | } |
2164 | kfree(fscki); | 2166 | kfree(fscki); |
2165 | } | 2167 | } |
2166 | } | 2168 | } |
2167 | } | 2169 | } |
2168 | 2170 | ||
2169 | /** | 2171 | /** |
2170 | * check_inodes - checks all inodes. | 2172 | * check_inodes - checks all inodes. |
2171 | * @c: UBIFS file-system description object | 2173 | * @c: UBIFS file-system description object |
2172 | * @fsckd: FS checking information | 2174 | * @fsckd: FS checking information |
2173 | * | 2175 | * |
2174 | * This is a helper function for 'dbg_check_filesystem()' which walks the | 2176 | * This is a helper function for 'dbg_check_filesystem()' which walks the |
2175 | * RB-tree of inodes after the index scan has been finished, and checks that | 2177 | * RB-tree of inodes after the index scan has been finished, and checks that |
2176 | * inode nlink, size, etc are correct. Returns zero if inodes are fine, | 2178 | * inode nlink, size, etc are correct. Returns zero if inodes are fine, |
2177 | * %-EINVAL if not, and a negative error code in case of failure. | 2179 | * %-EINVAL if not, and a negative error code in case of failure. |
2178 | */ | 2180 | */ |
2179 | static int check_inodes(struct ubifs_info *c, struct fsck_data *fsckd) | 2181 | static int check_inodes(struct ubifs_info *c, struct fsck_data *fsckd) |
2180 | { | 2182 | { |
2181 | int n, err; | 2183 | int n, err; |
2182 | union ubifs_key key; | 2184 | union ubifs_key key; |
2183 | struct ubifs_znode *znode; | 2185 | struct ubifs_znode *znode; |
2184 | struct ubifs_zbranch *zbr; | 2186 | struct ubifs_zbranch *zbr; |
2185 | struct ubifs_ino_node *ino; | 2187 | struct ubifs_ino_node *ino; |
2186 | struct fsck_inode *fscki; | 2188 | struct fsck_inode *fscki; |
2187 | struct rb_node *this = rb_first(&fsckd->inodes); | 2189 | struct rb_node *this = rb_first(&fsckd->inodes); |
2188 | 2190 | ||
2189 | while (this) { | 2191 | while (this) { |
2190 | fscki = rb_entry(this, struct fsck_inode, rb); | 2192 | fscki = rb_entry(this, struct fsck_inode, rb); |
2191 | this = rb_next(this); | 2193 | this = rb_next(this); |
2192 | 2194 | ||
2193 | if (S_ISDIR(fscki->mode)) { | 2195 | if (S_ISDIR(fscki->mode)) { |
2194 | /* | 2196 | /* |
2195 | * Directories have to have exactly one reference (they | 2197 | * Directories have to have exactly one reference (they |
2196 | * cannot have hardlinks), although root inode is an | 2198 | * cannot have hardlinks), although root inode is an |
2197 | * exception. | 2199 | * exception. |
2198 | */ | 2200 | */ |
2199 | if (fscki->inum != UBIFS_ROOT_INO && | 2201 | if (fscki->inum != UBIFS_ROOT_INO && |
2200 | fscki->references != 1) { | 2202 | fscki->references != 1) { |
2201 | ubifs_err("directory inode %lu has %d " | 2203 | ubifs_err("directory inode %lu has %d " |
2202 | "direntries which refer it, but " | 2204 | "direntries which refer it, but " |
2203 | "should be 1", | 2205 | "should be 1", |
2204 | (unsigned long)fscki->inum, | 2206 | (unsigned long)fscki->inum, |
2205 | fscki->references); | 2207 | fscki->references); |
2206 | goto out_dump; | 2208 | goto out_dump; |
2207 | } | 2209 | } |
2208 | if (fscki->inum == UBIFS_ROOT_INO && | 2210 | if (fscki->inum == UBIFS_ROOT_INO && |
2209 | fscki->references != 0) { | 2211 | fscki->references != 0) { |
2210 | ubifs_err("root inode %lu has non-zero (%d) " | 2212 | ubifs_err("root inode %lu has non-zero (%d) " |
2211 | "direntries which refer it", | 2213 | "direntries which refer it", |
2212 | (unsigned long)fscki->inum, | 2214 | (unsigned long)fscki->inum, |
2213 | fscki->references); | 2215 | fscki->references); |
2214 | goto out_dump; | 2216 | goto out_dump; |
2215 | } | 2217 | } |
2216 | if (fscki->calc_sz != fscki->size) { | 2218 | if (fscki->calc_sz != fscki->size) { |
2217 | ubifs_err("directory inode %lu size is %lld, " | 2219 | ubifs_err("directory inode %lu size is %lld, " |
2218 | "but calculated size is %lld", | 2220 | "but calculated size is %lld", |
2219 | (unsigned long)fscki->inum, | 2221 | (unsigned long)fscki->inum, |
2220 | fscki->size, fscki->calc_sz); | 2222 | fscki->size, fscki->calc_sz); |
2221 | goto out_dump; | 2223 | goto out_dump; |
2222 | } | 2224 | } |
2223 | if (fscki->calc_cnt != fscki->nlink) { | 2225 | if (fscki->calc_cnt != fscki->nlink) { |
2224 | ubifs_err("directory inode %lu nlink is %d, " | 2226 | ubifs_err("directory inode %lu nlink is %d, " |
2225 | "but calculated nlink is %d", | 2227 | "but calculated nlink is %d", |
2226 | (unsigned long)fscki->inum, | 2228 | (unsigned long)fscki->inum, |
2227 | fscki->nlink, fscki->calc_cnt); | 2229 | fscki->nlink, fscki->calc_cnt); |
2228 | goto out_dump; | 2230 | goto out_dump; |
2229 | } | 2231 | } |
2230 | } else { | 2232 | } else { |
2231 | if (fscki->references != fscki->nlink) { | 2233 | if (fscki->references != fscki->nlink) { |
2232 | ubifs_err("inode %lu nlink is %d, but " | 2234 | ubifs_err("inode %lu nlink is %d, but " |
2233 | "calculated nlink is %d", | 2235 | "calculated nlink is %d", |
2234 | (unsigned long)fscki->inum, | 2236 | (unsigned long)fscki->inum, |
2235 | fscki->nlink, fscki->references); | 2237 | fscki->nlink, fscki->references); |
2236 | goto out_dump; | 2238 | goto out_dump; |
2237 | } | 2239 | } |
2238 | } | 2240 | } |
2239 | if (fscki->xattr_sz != fscki->calc_xsz) { | 2241 | if (fscki->xattr_sz != fscki->calc_xsz) { |
2240 | ubifs_err("inode %lu has xattr size %u, but " | 2242 | ubifs_err("inode %lu has xattr size %u, but " |
2241 | "calculated size is %lld", | 2243 | "calculated size is %lld", |
2242 | (unsigned long)fscki->inum, fscki->xattr_sz, | 2244 | (unsigned long)fscki->inum, fscki->xattr_sz, |
2243 | fscki->calc_xsz); | 2245 | fscki->calc_xsz); |
2244 | goto out_dump; | 2246 | goto out_dump; |
2245 | } | 2247 | } |
2246 | if (fscki->xattr_cnt != fscki->calc_xcnt) { | 2248 | if (fscki->xattr_cnt != fscki->calc_xcnt) { |
2247 | ubifs_err("inode %lu has %u xattrs, but " | 2249 | ubifs_err("inode %lu has %u xattrs, but " |
2248 | "calculated count is %lld", | 2250 | "calculated count is %lld", |
2249 | (unsigned long)fscki->inum, | 2251 | (unsigned long)fscki->inum, |
2250 | fscki->xattr_cnt, fscki->calc_xcnt); | 2252 | fscki->xattr_cnt, fscki->calc_xcnt); |
2251 | goto out_dump; | 2253 | goto out_dump; |
2252 | } | 2254 | } |
2253 | if (fscki->xattr_nms != fscki->calc_xnms) { | 2255 | if (fscki->xattr_nms != fscki->calc_xnms) { |
2254 | ubifs_err("inode %lu has xattr names' size %u, but " | 2256 | ubifs_err("inode %lu has xattr names' size %u, but " |
2255 | "calculated names' size is %lld", | 2257 | "calculated names' size is %lld", |
2256 | (unsigned long)fscki->inum, fscki->xattr_nms, | 2258 | (unsigned long)fscki->inum, fscki->xattr_nms, |
2257 | fscki->calc_xnms); | 2259 | fscki->calc_xnms); |
2258 | goto out_dump; | 2260 | goto out_dump; |
2259 | } | 2261 | } |
2260 | } | 2262 | } |
2261 | 2263 | ||
2262 | return 0; | 2264 | return 0; |
2263 | 2265 | ||
2264 | out_dump: | 2266 | out_dump: |
2265 | /* Read the bad inode and dump it */ | 2267 | /* Read the bad inode and dump it */ |
2266 | ino_key_init(c, &key, fscki->inum); | 2268 | ino_key_init(c, &key, fscki->inum); |
2267 | err = ubifs_lookup_level0(c, &key, &znode, &n); | 2269 | err = ubifs_lookup_level0(c, &key, &znode, &n); |
2268 | if (!err) { | 2270 | if (!err) { |
2269 | ubifs_err("inode %lu not found in index", | 2271 | ubifs_err("inode %lu not found in index", |
2270 | (unsigned long)fscki->inum); | 2272 | (unsigned long)fscki->inum); |
2271 | return -ENOENT; | 2273 | return -ENOENT; |
2272 | } else if (err < 0) { | 2274 | } else if (err < 0) { |
2273 | ubifs_err("error %d while looking up inode %lu", | 2275 | ubifs_err("error %d while looking up inode %lu", |
2274 | err, (unsigned long)fscki->inum); | 2276 | err, (unsigned long)fscki->inum); |
2275 | return err; | 2277 | return err; |
2276 | } | 2278 | } |
2277 | 2279 | ||
2278 | zbr = &znode->zbranch[n]; | 2280 | zbr = &znode->zbranch[n]; |
2279 | ino = kmalloc(zbr->len, GFP_NOFS); | 2281 | ino = kmalloc(zbr->len, GFP_NOFS); |
2280 | if (!ino) | 2282 | if (!ino) |
2281 | return -ENOMEM; | 2283 | return -ENOMEM; |
2282 | 2284 | ||
2283 | err = ubifs_tnc_read_node(c, zbr, ino); | 2285 | err = ubifs_tnc_read_node(c, zbr, ino); |
2284 | if (err) { | 2286 | if (err) { |
2285 | ubifs_err("cannot read inode node at LEB %d:%d, error %d", | 2287 | ubifs_err("cannot read inode node at LEB %d:%d, error %d", |
2286 | zbr->lnum, zbr->offs, err); | 2288 | zbr->lnum, zbr->offs, err); |
2287 | kfree(ino); | 2289 | kfree(ino); |
2288 | return err; | 2290 | return err; |
2289 | } | 2291 | } |
2290 | 2292 | ||
2291 | ubifs_msg("dump of the inode %lu sitting in LEB %d:%d", | 2293 | ubifs_msg("dump of the inode %lu sitting in LEB %d:%d", |
2292 | (unsigned long)fscki->inum, zbr->lnum, zbr->offs); | 2294 | (unsigned long)fscki->inum, zbr->lnum, zbr->offs); |
2293 | dbg_dump_node(c, ino); | 2295 | dbg_dump_node(c, ino); |
2294 | kfree(ino); | 2296 | kfree(ino); |
2295 | return -EINVAL; | 2297 | return -EINVAL; |
2296 | } | 2298 | } |
2297 | 2299 | ||
2298 | /** | 2300 | /** |
2299 | * dbg_check_filesystem - check the file-system. | 2301 | * dbg_check_filesystem - check the file-system. |
2300 | * @c: UBIFS file-system description object | 2302 | * @c: UBIFS file-system description object |
2301 | * | 2303 | * |
2302 | * This function checks the file system, namely: | 2304 | * This function checks the file system, namely: |
2303 | * o makes sure that all leaf nodes exist and their CRCs are correct; | 2305 | * o makes sure that all leaf nodes exist and their CRCs are correct; |
2304 | * o makes sure inode nlink, size, xattr size/count are correct (for all | 2306 | * o makes sure inode nlink, size, xattr size/count are correct (for all |
2305 | * inodes). | 2307 | * inodes). |
2306 | * | 2308 | * |
2307 | * The function reads whole indexing tree and all nodes, so it is pretty | 2309 | * The function reads whole indexing tree and all nodes, so it is pretty |
2308 | * heavy-weight. Returns zero if the file-system is consistent, %-EINVAL if | 2310 | * heavy-weight. Returns zero if the file-system is consistent, %-EINVAL if |
2309 | * not, and a negative error code in case of failure. | 2311 | * not, and a negative error code in case of failure. |
2310 | */ | 2312 | */ |
2311 | int dbg_check_filesystem(struct ubifs_info *c) | 2313 | int dbg_check_filesystem(struct ubifs_info *c) |
2312 | { | 2314 | { |
2313 | int err; | 2315 | int err; |
2314 | struct fsck_data fsckd; | 2316 | struct fsck_data fsckd; |
2315 | 2317 | ||
2316 | if (!(ubifs_chk_flags & UBIFS_CHK_FS)) | 2318 | if (!(ubifs_chk_flags & UBIFS_CHK_FS)) |
2317 | return 0; | 2319 | return 0; |
2318 | 2320 | ||
2319 | fsckd.inodes = RB_ROOT; | 2321 | fsckd.inodes = RB_ROOT; |
2320 | err = dbg_walk_index(c, check_leaf, NULL, &fsckd); | 2322 | err = dbg_walk_index(c, check_leaf, NULL, &fsckd); |
2321 | if (err) | 2323 | if (err) |
2322 | goto out_free; | 2324 | goto out_free; |
2323 | 2325 | ||
2324 | err = check_inodes(c, &fsckd); | 2326 | err = check_inodes(c, &fsckd); |
2325 | if (err) | 2327 | if (err) |
2326 | goto out_free; | 2328 | goto out_free; |
2327 | 2329 | ||
2328 | free_inodes(&fsckd); | 2330 | free_inodes(&fsckd); |
2329 | return 0; | 2331 | return 0; |
2330 | 2332 | ||
2331 | out_free: | 2333 | out_free: |
2332 | ubifs_err("file-system check failed with error %d", err); | 2334 | ubifs_err("file-system check failed with error %d", err); |
2333 | dump_stack(); | 2335 | dump_stack(); |
2334 | free_inodes(&fsckd); | 2336 | free_inodes(&fsckd); |
2335 | return err; | 2337 | return err; |
2336 | } | 2338 | } |
2337 | 2339 | ||
2338 | /** | 2340 | /** |
2339 | * dbg_check_data_nodes_order - check that list of data nodes is sorted. | 2341 | * dbg_check_data_nodes_order - check that list of data nodes is sorted. |
2340 | * @c: UBIFS file-system description object | 2342 | * @c: UBIFS file-system description object |
2341 | * @head: the list of nodes ('struct ubifs_scan_node' objects) | 2343 | * @head: the list of nodes ('struct ubifs_scan_node' objects) |
2342 | * | 2344 | * |
2343 | * This function returns zero if the list of data nodes is sorted correctly, | 2345 | * This function returns zero if the list of data nodes is sorted correctly, |
2344 | * and %-EINVAL if not. | 2346 | * and %-EINVAL if not. |
2345 | */ | 2347 | */ |
2346 | int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head) | 2348 | int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head) |
2347 | { | 2349 | { |
2348 | struct list_head *cur; | 2350 | struct list_head *cur; |
2349 | struct ubifs_scan_node *sa, *sb; | 2351 | struct ubifs_scan_node *sa, *sb; |
2350 | 2352 | ||
2351 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) | 2353 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) |
2352 | return 0; | 2354 | return 0; |
2353 | 2355 | ||
2354 | for (cur = head->next; cur->next != head; cur = cur->next) { | 2356 | for (cur = head->next; cur->next != head; cur = cur->next) { |
2355 | ino_t inuma, inumb; | 2357 | ino_t inuma, inumb; |
2356 | uint32_t blka, blkb; | 2358 | uint32_t blka, blkb; |
2357 | 2359 | ||
2358 | cond_resched(); | 2360 | cond_resched(); |
2359 | sa = container_of(cur, struct ubifs_scan_node, list); | 2361 | sa = container_of(cur, struct ubifs_scan_node, list); |
2360 | sb = container_of(cur->next, struct ubifs_scan_node, list); | 2362 | sb = container_of(cur->next, struct ubifs_scan_node, list); |
2361 | 2363 | ||
2362 | if (sa->type != UBIFS_DATA_NODE) { | 2364 | if (sa->type != UBIFS_DATA_NODE) { |
2363 | ubifs_err("bad node type %d", sa->type); | 2365 | ubifs_err("bad node type %d", sa->type); |
2364 | dbg_dump_node(c, sa->node); | 2366 | dbg_dump_node(c, sa->node); |
2365 | return -EINVAL; | 2367 | return -EINVAL; |
2366 | } | 2368 | } |
2367 | if (sb->type != UBIFS_DATA_NODE) { | 2369 | if (sb->type != UBIFS_DATA_NODE) { |
2368 | ubifs_err("bad node type %d", sb->type); | 2370 | ubifs_err("bad node type %d", sb->type); |
2369 | dbg_dump_node(c, sb->node); | 2371 | dbg_dump_node(c, sb->node); |
2370 | return -EINVAL; | 2372 | return -EINVAL; |
2371 | } | 2373 | } |
2372 | 2374 | ||
2373 | inuma = key_inum(c, &sa->key); | 2375 | inuma = key_inum(c, &sa->key); |
2374 | inumb = key_inum(c, &sb->key); | 2376 | inumb = key_inum(c, &sb->key); |
2375 | 2377 | ||
2376 | if (inuma < inumb) | 2378 | if (inuma < inumb) |
2377 | continue; | 2379 | continue; |
2378 | if (inuma > inumb) { | 2380 | if (inuma > inumb) { |
2379 | ubifs_err("larger inum %lu goes before inum %lu", | 2381 | ubifs_err("larger inum %lu goes before inum %lu", |
2380 | (unsigned long)inuma, (unsigned long)inumb); | 2382 | (unsigned long)inuma, (unsigned long)inumb); |
2381 | goto error_dump; | 2383 | goto error_dump; |
2382 | } | 2384 | } |
2383 | 2385 | ||
2384 | blka = key_block(c, &sa->key); | 2386 | blka = key_block(c, &sa->key); |
2385 | blkb = key_block(c, &sb->key); | 2387 | blkb = key_block(c, &sb->key); |
2386 | 2388 | ||
2387 | if (blka > blkb) { | 2389 | if (blka > blkb) { |
2388 | ubifs_err("larger block %u goes before %u", blka, blkb); | 2390 | ubifs_err("larger block %u goes before %u", blka, blkb); |
2389 | goto error_dump; | 2391 | goto error_dump; |
2390 | } | 2392 | } |
2391 | if (blka == blkb) { | 2393 | if (blka == blkb) { |
2392 | ubifs_err("two data nodes for the same block"); | 2394 | ubifs_err("two data nodes for the same block"); |
2393 | goto error_dump; | 2395 | goto error_dump; |
2394 | } | 2396 | } |
2395 | } | 2397 | } |
2396 | 2398 | ||
2397 | return 0; | 2399 | return 0; |
2398 | 2400 | ||
2399 | error_dump: | 2401 | error_dump: |
2400 | dbg_dump_node(c, sa->node); | 2402 | dbg_dump_node(c, sa->node); |
2401 | dbg_dump_node(c, sb->node); | 2403 | dbg_dump_node(c, sb->node); |
2402 | return -EINVAL; | 2404 | return -EINVAL; |
2403 | } | 2405 | } |
2404 | 2406 | ||
2405 | /** | 2407 | /** |
2406 | * dbg_check_nondata_nodes_order - check that list of data nodes is sorted. | 2408 | * dbg_check_nondata_nodes_order - check that list of data nodes is sorted. |
2407 | * @c: UBIFS file-system description object | 2409 | * @c: UBIFS file-system description object |
2408 | * @head: the list of nodes ('struct ubifs_scan_node' objects) | 2410 | * @head: the list of nodes ('struct ubifs_scan_node' objects) |
2409 | * | 2411 | * |
2410 | * This function returns zero if the list of non-data nodes is sorted correctly, | 2412 | * This function returns zero if the list of non-data nodes is sorted correctly, |
2411 | * and %-EINVAL if not. | 2413 | * and %-EINVAL if not. |
2412 | */ | 2414 | */ |
2413 | int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) | 2415 | int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) |
2414 | { | 2416 | { |
2415 | struct list_head *cur; | 2417 | struct list_head *cur; |
2416 | struct ubifs_scan_node *sa, *sb; | 2418 | struct ubifs_scan_node *sa, *sb; |
2417 | 2419 | ||
2418 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) | 2420 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) |
2419 | return 0; | 2421 | return 0; |
2420 | 2422 | ||
2421 | for (cur = head->next; cur->next != head; cur = cur->next) { | 2423 | for (cur = head->next; cur->next != head; cur = cur->next) { |
2422 | ino_t inuma, inumb; | 2424 | ino_t inuma, inumb; |
2423 | uint32_t hasha, hashb; | 2425 | uint32_t hasha, hashb; |
2424 | 2426 | ||
2425 | cond_resched(); | 2427 | cond_resched(); |
2426 | sa = container_of(cur, struct ubifs_scan_node, list); | 2428 | sa = container_of(cur, struct ubifs_scan_node, list); |
2427 | sb = container_of(cur->next, struct ubifs_scan_node, list); | 2429 | sb = container_of(cur->next, struct ubifs_scan_node, list); |
2428 | 2430 | ||
2429 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && | 2431 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && |
2430 | sa->type != UBIFS_XENT_NODE) { | 2432 | sa->type != UBIFS_XENT_NODE) { |
2431 | ubifs_err("bad node type %d", sa->type); | 2433 | ubifs_err("bad node type %d", sa->type); |
2432 | dbg_dump_node(c, sa->node); | 2434 | dbg_dump_node(c, sa->node); |
2433 | return -EINVAL; | 2435 | return -EINVAL; |
2434 | } | 2436 | } |
2435 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && | 2437 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && |
2436 | sa->type != UBIFS_XENT_NODE) { | 2438 | sa->type != UBIFS_XENT_NODE) { |
2437 | ubifs_err("bad node type %d", sb->type); | 2439 | ubifs_err("bad node type %d", sb->type); |
2438 | dbg_dump_node(c, sb->node); | 2440 | dbg_dump_node(c, sb->node); |
2439 | return -EINVAL; | 2441 | return -EINVAL; |
2440 | } | 2442 | } |
2441 | 2443 | ||
2442 | if (sa->type != UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { | 2444 | if (sa->type != UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { |
2443 | ubifs_err("non-inode node goes before inode node"); | 2445 | ubifs_err("non-inode node goes before inode node"); |
2444 | goto error_dump; | 2446 | goto error_dump; |
2445 | } | 2447 | } |
2446 | 2448 | ||
2447 | if (sa->type == UBIFS_INO_NODE && sb->type != UBIFS_INO_NODE) | 2449 | if (sa->type == UBIFS_INO_NODE && sb->type != UBIFS_INO_NODE) |
2448 | continue; | 2450 | continue; |
2449 | 2451 | ||
2450 | if (sa->type == UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { | 2452 | if (sa->type == UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { |
2451 | /* Inode nodes are sorted in descending size order */ | 2453 | /* Inode nodes are sorted in descending size order */ |
2452 | if (sa->len < sb->len) { | 2454 | if (sa->len < sb->len) { |
2453 | ubifs_err("smaller inode node goes first"); | 2455 | ubifs_err("smaller inode node goes first"); |
2454 | goto error_dump; | 2456 | goto error_dump; |
2455 | } | 2457 | } |
2456 | continue; | 2458 | continue; |
2457 | } | 2459 | } |
2458 | 2460 | ||
2459 | /* | 2461 | /* |
2460 | * This is either a dentry or xentry, which should be sorted in | 2462 | * This is either a dentry or xentry, which should be sorted in |
2461 | * ascending (parent ino, hash) order. | 2463 | * ascending (parent ino, hash) order. |
2462 | */ | 2464 | */ |
2463 | inuma = key_inum(c, &sa->key); | 2465 | inuma = key_inum(c, &sa->key); |
2464 | inumb = key_inum(c, &sb->key); | 2466 | inumb = key_inum(c, &sb->key); |
2465 | 2467 | ||
2466 | if (inuma < inumb) | 2468 | if (inuma < inumb) |
2467 | continue; | 2469 | continue; |
2468 | if (inuma > inumb) { | 2470 | if (inuma > inumb) { |
2469 | ubifs_err("larger inum %lu goes before inum %lu", | 2471 | ubifs_err("larger inum %lu goes before inum %lu", |
2470 | (unsigned long)inuma, (unsigned long)inumb); | 2472 | (unsigned long)inuma, (unsigned long)inumb); |
2471 | goto error_dump; | 2473 | goto error_dump; |
2472 | } | 2474 | } |
2473 | 2475 | ||
2474 | hasha = key_block(c, &sa->key); | 2476 | hasha = key_block(c, &sa->key); |
2475 | hashb = key_block(c, &sb->key); | 2477 | hashb = key_block(c, &sb->key); |
2476 | 2478 | ||
2477 | if (hasha > hashb) { | 2479 | if (hasha > hashb) { |
2478 | ubifs_err("larger hash %u goes before %u", | 2480 | ubifs_err("larger hash %u goes before %u", |
2479 | hasha, hashb); | 2481 | hasha, hashb); |
2480 | goto error_dump; | 2482 | goto error_dump; |
2481 | } | 2483 | } |
2482 | } | 2484 | } |
2483 | 2485 | ||
2484 | return 0; | 2486 | return 0; |
2485 | 2487 | ||
2486 | error_dump: | 2488 | error_dump: |
2487 | ubifs_msg("dumping first node"); | 2489 | ubifs_msg("dumping first node"); |
2488 | dbg_dump_node(c, sa->node); | 2490 | dbg_dump_node(c, sa->node); |
2489 | ubifs_msg("dumping second node"); | 2491 | ubifs_msg("dumping second node"); |
2490 | dbg_dump_node(c, sb->node); | 2492 | dbg_dump_node(c, sb->node); |
2491 | return -EINVAL; | 2493 | return -EINVAL; |
2492 | return 0; | 2494 | return 0; |
2493 | } | 2495 | } |
2494 | 2496 | ||
2495 | int dbg_force_in_the_gaps(void) | 2497 | int dbg_force_in_the_gaps(void) |
2496 | { | 2498 | { |
2497 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) | 2499 | if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) |
2498 | return 0; | 2500 | return 0; |
2499 | 2501 | ||
2500 | return !(random32() & 7); | 2502 | return !(random32() & 7); |
2501 | } | 2503 | } |
2502 | 2504 | ||
2503 | /* Failure mode for recovery testing */ | 2505 | /* Failure mode for recovery testing */ |
2504 | 2506 | ||
2505 | #define chance(n, d) (simple_rand() <= (n) * 32768LL / (d)) | 2507 | #define chance(n, d) (simple_rand() <= (n) * 32768LL / (d)) |
2506 | 2508 | ||
2507 | struct failure_mode_info { | 2509 | struct failure_mode_info { |
2508 | struct list_head list; | 2510 | struct list_head list; |
2509 | struct ubifs_info *c; | 2511 | struct ubifs_info *c; |
2510 | }; | 2512 | }; |
2511 | 2513 | ||
2512 | static LIST_HEAD(fmi_list); | 2514 | static LIST_HEAD(fmi_list); |
2513 | static DEFINE_SPINLOCK(fmi_lock); | 2515 | static DEFINE_SPINLOCK(fmi_lock); |
2514 | 2516 | ||
2515 | static unsigned int next; | 2517 | static unsigned int next; |
2516 | 2518 | ||
2517 | static int simple_rand(void) | 2519 | static int simple_rand(void) |
2518 | { | 2520 | { |
2519 | if (next == 0) | 2521 | if (next == 0) |
2520 | next = current->pid; | 2522 | next = current->pid; |
2521 | next = next * 1103515245 + 12345; | 2523 | next = next * 1103515245 + 12345; |
2522 | return (next >> 16) & 32767; | 2524 | return (next >> 16) & 32767; |
2523 | } | 2525 | } |
2524 | 2526 | ||
2525 | static void failure_mode_init(struct ubifs_info *c) | 2527 | static void failure_mode_init(struct ubifs_info *c) |
2526 | { | 2528 | { |
2527 | struct failure_mode_info *fmi; | 2529 | struct failure_mode_info *fmi; |
2528 | 2530 | ||
2529 | fmi = kmalloc(sizeof(struct failure_mode_info), GFP_NOFS); | 2531 | fmi = kmalloc(sizeof(struct failure_mode_info), GFP_NOFS); |
2530 | if (!fmi) { | 2532 | if (!fmi) { |
2531 | ubifs_err("Failed to register failure mode - no memory"); | 2533 | ubifs_err("Failed to register failure mode - no memory"); |
2532 | return; | 2534 | return; |
2533 | } | 2535 | } |
2534 | fmi->c = c; | 2536 | fmi->c = c; |
2535 | spin_lock(&fmi_lock); | 2537 | spin_lock(&fmi_lock); |
2536 | list_add_tail(&fmi->list, &fmi_list); | 2538 | list_add_tail(&fmi->list, &fmi_list); |
2537 | spin_unlock(&fmi_lock); | 2539 | spin_unlock(&fmi_lock); |
2538 | } | 2540 | } |
2539 | 2541 | ||
2540 | static void failure_mode_exit(struct ubifs_info *c) | 2542 | static void failure_mode_exit(struct ubifs_info *c) |
2541 | { | 2543 | { |
2542 | struct failure_mode_info *fmi, *tmp; | 2544 | struct failure_mode_info *fmi, *tmp; |
2543 | 2545 | ||
2544 | spin_lock(&fmi_lock); | 2546 | spin_lock(&fmi_lock); |
2545 | list_for_each_entry_safe(fmi, tmp, &fmi_list, list) | 2547 | list_for_each_entry_safe(fmi, tmp, &fmi_list, list) |
2546 | if (fmi->c == c) { | 2548 | if (fmi->c == c) { |
2547 | list_del(&fmi->list); | 2549 | list_del(&fmi->list); |
2548 | kfree(fmi); | 2550 | kfree(fmi); |
2549 | } | 2551 | } |
2550 | spin_unlock(&fmi_lock); | 2552 | spin_unlock(&fmi_lock); |
2551 | } | 2553 | } |
2552 | 2554 | ||
2553 | static struct ubifs_info *dbg_find_info(struct ubi_volume_desc *desc) | 2555 | static struct ubifs_info *dbg_find_info(struct ubi_volume_desc *desc) |
2554 | { | 2556 | { |
2555 | struct failure_mode_info *fmi; | 2557 | struct failure_mode_info *fmi; |
2556 | 2558 | ||
2557 | spin_lock(&fmi_lock); | 2559 | spin_lock(&fmi_lock); |
2558 | list_for_each_entry(fmi, &fmi_list, list) | 2560 | list_for_each_entry(fmi, &fmi_list, list) |
2559 | if (fmi->c->ubi == desc) { | 2561 | if (fmi->c->ubi == desc) { |
2560 | struct ubifs_info *c = fmi->c; | 2562 | struct ubifs_info *c = fmi->c; |
2561 | 2563 | ||
2562 | spin_unlock(&fmi_lock); | 2564 | spin_unlock(&fmi_lock); |
2563 | return c; | 2565 | return c; |
2564 | } | 2566 | } |
2565 | spin_unlock(&fmi_lock); | 2567 | spin_unlock(&fmi_lock); |
2566 | return NULL; | 2568 | return NULL; |
2567 | } | 2569 | } |
2568 | 2570 | ||
2569 | static int in_failure_mode(struct ubi_volume_desc *desc) | 2571 | static int in_failure_mode(struct ubi_volume_desc *desc) |
2570 | { | 2572 | { |
2571 | struct ubifs_info *c = dbg_find_info(desc); | 2573 | struct ubifs_info *c = dbg_find_info(desc); |
2572 | 2574 | ||
2573 | if (c && dbg_failure_mode) | 2575 | if (c && dbg_failure_mode) |
2574 | return c->dbg->failure_mode; | 2576 | return c->dbg->failure_mode; |
2575 | return 0; | 2577 | return 0; |
2576 | } | 2578 | } |
2577 | 2579 | ||
2578 | static int do_fail(struct ubi_volume_desc *desc, int lnum, int write) | 2580 | static int do_fail(struct ubi_volume_desc *desc, int lnum, int write) |
2579 | { | 2581 | { |
2580 | struct ubifs_info *c = dbg_find_info(desc); | 2582 | struct ubifs_info *c = dbg_find_info(desc); |
2581 | struct ubifs_debug_info *d; | 2583 | struct ubifs_debug_info *d; |
2582 | 2584 | ||
2583 | if (!c || !dbg_failure_mode) | 2585 | if (!c || !dbg_failure_mode) |
2584 | return 0; | 2586 | return 0; |
2585 | d = c->dbg; | 2587 | d = c->dbg; |
2586 | if (d->failure_mode) | 2588 | if (d->failure_mode) |
2587 | return 1; | 2589 | return 1; |
2588 | if (!d->fail_cnt) { | 2590 | if (!d->fail_cnt) { |
2589 | /* First call - decide delay to failure */ | 2591 | /* First call - decide delay to failure */ |
2590 | if (chance(1, 2)) { | 2592 | if (chance(1, 2)) { |
2591 | unsigned int delay = 1 << (simple_rand() >> 11); | 2593 | unsigned int delay = 1 << (simple_rand() >> 11); |
2592 | 2594 | ||
2593 | if (chance(1, 2)) { | 2595 | if (chance(1, 2)) { |
2594 | d->fail_delay = 1; | 2596 | d->fail_delay = 1; |
2595 | d->fail_timeout = jiffies + | 2597 | d->fail_timeout = jiffies + |
2596 | msecs_to_jiffies(delay); | 2598 | msecs_to_jiffies(delay); |
2597 | dbg_rcvry("failing after %ums", delay); | 2599 | dbg_rcvry("failing after %ums", delay); |
2598 | } else { | 2600 | } else { |
2599 | d->fail_delay = 2; | 2601 | d->fail_delay = 2; |
2600 | d->fail_cnt_max = delay; | 2602 | d->fail_cnt_max = delay; |
2601 | dbg_rcvry("failing after %u calls", delay); | 2603 | dbg_rcvry("failing after %u calls", delay); |
2602 | } | 2604 | } |
2603 | } | 2605 | } |
2604 | d->fail_cnt += 1; | 2606 | d->fail_cnt += 1; |
2605 | } | 2607 | } |
2606 | /* Determine if failure delay has expired */ | 2608 | /* Determine if failure delay has expired */ |
2607 | if (d->fail_delay == 1) { | 2609 | if (d->fail_delay == 1) { |
2608 | if (time_before(jiffies, d->fail_timeout)) | 2610 | if (time_before(jiffies, d->fail_timeout)) |
2609 | return 0; | 2611 | return 0; |
2610 | } else if (d->fail_delay == 2) | 2612 | } else if (d->fail_delay == 2) |
2611 | if (d->fail_cnt++ < d->fail_cnt_max) | 2613 | if (d->fail_cnt++ < d->fail_cnt_max) |
2612 | return 0; | 2614 | return 0; |
2613 | if (lnum == UBIFS_SB_LNUM) { | 2615 | if (lnum == UBIFS_SB_LNUM) { |
2614 | if (write) { | 2616 | if (write) { |
2615 | if (chance(1, 2)) | 2617 | if (chance(1, 2)) |
2616 | return 0; | 2618 | return 0; |
2617 | } else if (chance(19, 20)) | 2619 | } else if (chance(19, 20)) |
2618 | return 0; | 2620 | return 0; |
2619 | dbg_rcvry("failing in super block LEB %d", lnum); | 2621 | dbg_rcvry("failing in super block LEB %d", lnum); |
2620 | } else if (lnum == UBIFS_MST_LNUM || lnum == UBIFS_MST_LNUM + 1) { | 2622 | } else if (lnum == UBIFS_MST_LNUM || lnum == UBIFS_MST_LNUM + 1) { |
2621 | if (chance(19, 20)) | 2623 | if (chance(19, 20)) |
2622 | return 0; | 2624 | return 0; |
2623 | dbg_rcvry("failing in master LEB %d", lnum); | 2625 | dbg_rcvry("failing in master LEB %d", lnum); |
2624 | } else if (lnum >= UBIFS_LOG_LNUM && lnum <= c->log_last) { | 2626 | } else if (lnum >= UBIFS_LOG_LNUM && lnum <= c->log_last) { |
2625 | if (write) { | 2627 | if (write) { |
2626 | if (chance(99, 100)) | 2628 | if (chance(99, 100)) |
2627 | return 0; | 2629 | return 0; |
2628 | } else if (chance(399, 400)) | 2630 | } else if (chance(399, 400)) |
2629 | return 0; | 2631 | return 0; |
2630 | dbg_rcvry("failing in log LEB %d", lnum); | 2632 | dbg_rcvry("failing in log LEB %d", lnum); |
2631 | } else if (lnum >= c->lpt_first && lnum <= c->lpt_last) { | 2633 | } else if (lnum >= c->lpt_first && lnum <= c->lpt_last) { |
2632 | if (write) { | 2634 | if (write) { |
2633 | if (chance(7, 8)) | 2635 | if (chance(7, 8)) |
2634 | return 0; | 2636 | return 0; |
2635 | } else if (chance(19, 20)) | 2637 | } else if (chance(19, 20)) |
2636 | return 0; | 2638 | return 0; |
2637 | dbg_rcvry("failing in LPT LEB %d", lnum); | 2639 | dbg_rcvry("failing in LPT LEB %d", lnum); |
2638 | } else if (lnum >= c->orph_first && lnum <= c->orph_last) { | 2640 | } else if (lnum >= c->orph_first && lnum <= c->orph_last) { |
2639 | if (write) { | 2641 | if (write) { |
2640 | if (chance(1, 2)) | 2642 | if (chance(1, 2)) |
2641 | return 0; | 2643 | return 0; |
2642 | } else if (chance(9, 10)) | 2644 | } else if (chance(9, 10)) |
2643 | return 0; | 2645 | return 0; |
2644 | dbg_rcvry("failing in orphan LEB %d", lnum); | 2646 | dbg_rcvry("failing in orphan LEB %d", lnum); |
2645 | } else if (lnum == c->ihead_lnum) { | 2647 | } else if (lnum == c->ihead_lnum) { |
2646 | if (chance(99, 100)) | 2648 | if (chance(99, 100)) |
2647 | return 0; | 2649 | return 0; |
2648 | dbg_rcvry("failing in index head LEB %d", lnum); | 2650 | dbg_rcvry("failing in index head LEB %d", lnum); |
2649 | } else if (c->jheads && lnum == c->jheads[GCHD].wbuf.lnum) { | 2651 | } else if (c->jheads && lnum == c->jheads[GCHD].wbuf.lnum) { |
2650 | if (chance(9, 10)) | 2652 | if (chance(9, 10)) |
2651 | return 0; | 2653 | return 0; |
2652 | dbg_rcvry("failing in GC head LEB %d", lnum); | 2654 | dbg_rcvry("failing in GC head LEB %d", lnum); |
2653 | } else if (write && !RB_EMPTY_ROOT(&c->buds) && | 2655 | } else if (write && !RB_EMPTY_ROOT(&c->buds) && |
2654 | !ubifs_search_bud(c, lnum)) { | 2656 | !ubifs_search_bud(c, lnum)) { |
2655 | if (chance(19, 20)) | 2657 | if (chance(19, 20)) |
2656 | return 0; | 2658 | return 0; |
2657 | dbg_rcvry("failing in non-bud LEB %d", lnum); | 2659 | dbg_rcvry("failing in non-bud LEB %d", lnum); |
2658 | } else if (c->cmt_state == COMMIT_RUNNING_BACKGROUND || | 2660 | } else if (c->cmt_state == COMMIT_RUNNING_BACKGROUND || |
2659 | c->cmt_state == COMMIT_RUNNING_REQUIRED) { | 2661 | c->cmt_state == COMMIT_RUNNING_REQUIRED) { |
2660 | if (chance(999, 1000)) | 2662 | if (chance(999, 1000)) |
2661 | return 0; | 2663 | return 0; |
2662 | dbg_rcvry("failing in bud LEB %d commit running", lnum); | 2664 | dbg_rcvry("failing in bud LEB %d commit running", lnum); |
2663 | } else { | 2665 | } else { |
2664 | if (chance(9999, 10000)) | 2666 | if (chance(9999, 10000)) |
2665 | return 0; | 2667 | return 0; |
2666 | dbg_rcvry("failing in bud LEB %d commit not running", lnum); | 2668 | dbg_rcvry("failing in bud LEB %d commit not running", lnum); |
2667 | } | 2669 | } |
2668 | ubifs_err("*** SETTING FAILURE MODE ON (LEB %d) ***", lnum); | 2670 | ubifs_err("*** SETTING FAILURE MODE ON (LEB %d) ***", lnum); |
2669 | d->failure_mode = 1; | 2671 | d->failure_mode = 1; |
2670 | dump_stack(); | 2672 | dump_stack(); |
2671 | return 1; | 2673 | return 1; |
2672 | } | 2674 | } |
2673 | 2675 | ||
2674 | static void cut_data(const void *buf, int len) | 2676 | static void cut_data(const void *buf, int len) |
2675 | { | 2677 | { |
2676 | int flen, i; | 2678 | int flen, i; |
2677 | unsigned char *p = (void *)buf; | 2679 | unsigned char *p = (void *)buf; |
2678 | 2680 | ||
2679 | flen = (len * (long long)simple_rand()) >> 15; | 2681 | flen = (len * (long long)simple_rand()) >> 15; |
2680 | for (i = flen; i < len; i++) | 2682 | for (i = flen; i < len; i++) |
2681 | p[i] = 0xff; | 2683 | p[i] = 0xff; |
2682 | } | 2684 | } |
2683 | 2685 | ||
2684 | int dbg_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset, | 2686 | int dbg_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset, |
2685 | int len, int check) | 2687 | int len, int check) |
2686 | { | 2688 | { |
2687 | if (in_failure_mode(desc)) | 2689 | if (in_failure_mode(desc)) |
2688 | return -EROFS; | 2690 | return -EROFS; |
2689 | return ubi_leb_read(desc, lnum, buf, offset, len, check); | 2691 | return ubi_leb_read(desc, lnum, buf, offset, len, check); |
2690 | } | 2692 | } |
2691 | 2693 | ||
2692 | int dbg_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, | 2694 | int dbg_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, |
2693 | int offset, int len, int dtype) | 2695 | int offset, int len, int dtype) |
2694 | { | 2696 | { |
2695 | int err, failing; | 2697 | int err, failing; |
2696 | 2698 | ||
2697 | if (in_failure_mode(desc)) | 2699 | if (in_failure_mode(desc)) |
2698 | return -EROFS; | 2700 | return -EROFS; |
2699 | failing = do_fail(desc, lnum, 1); | 2701 | failing = do_fail(desc, lnum, 1); |
2700 | if (failing) | 2702 | if (failing) |
2701 | cut_data(buf, len); | 2703 | cut_data(buf, len); |
2702 | err = ubi_leb_write(desc, lnum, buf, offset, len, dtype); | 2704 | err = ubi_leb_write(desc, lnum, buf, offset, len, dtype); |
2703 | if (err) | 2705 | if (err) |
2704 | return err; | 2706 | return err; |
2705 | if (failing) | 2707 | if (failing) |
2706 | return -EROFS; | 2708 | return -EROFS; |
2707 | return 0; | 2709 | return 0; |
2708 | } | 2710 | } |
2709 | 2711 | ||
2710 | int dbg_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, | 2712 | int dbg_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, |
2711 | int len, int dtype) | 2713 | int len, int dtype) |
2712 | { | 2714 | { |
2713 | int err; | 2715 | int err; |
2714 | 2716 | ||
2715 | if (do_fail(desc, lnum, 1)) | 2717 | if (do_fail(desc, lnum, 1)) |
2716 | return -EROFS; | 2718 | return -EROFS; |
2717 | err = ubi_leb_change(desc, lnum, buf, len, dtype); | 2719 | err = ubi_leb_change(desc, lnum, buf, len, dtype); |
2718 | if (err) | 2720 | if (err) |
2719 | return err; | 2721 | return err; |
2720 | if (do_fail(desc, lnum, 1)) | 2722 | if (do_fail(desc, lnum, 1)) |
2721 | return -EROFS; | 2723 | return -EROFS; |
2722 | return 0; | 2724 | return 0; |
2723 | } | 2725 | } |
2724 | 2726 | ||
2725 | int dbg_leb_erase(struct ubi_volume_desc *desc, int lnum) | 2727 | int dbg_leb_erase(struct ubi_volume_desc *desc, int lnum) |
2726 | { | 2728 | { |
2727 | int err; | 2729 | int err; |
2728 | 2730 | ||
2729 | if (do_fail(desc, lnum, 0)) | 2731 | if (do_fail(desc, lnum, 0)) |
2730 | return -EROFS; | 2732 | return -EROFS; |
2731 | err = ubi_leb_erase(desc, lnum); | 2733 | err = ubi_leb_erase(desc, lnum); |
2732 | if (err) | 2734 | if (err) |
2733 | return err; | 2735 | return err; |
2734 | if (do_fail(desc, lnum, 0)) | 2736 | if (do_fail(desc, lnum, 0)) |
2735 | return -EROFS; | 2737 | return -EROFS; |
2736 | return 0; | 2738 | return 0; |
2737 | } | 2739 | } |
2738 | 2740 | ||
2739 | int dbg_leb_unmap(struct ubi_volume_desc *desc, int lnum) | 2741 | int dbg_leb_unmap(struct ubi_volume_desc *desc, int lnum) |
2740 | { | 2742 | { |
2741 | int err; | 2743 | int err; |
2742 | 2744 | ||
2743 | if (do_fail(desc, lnum, 0)) | 2745 | if (do_fail(desc, lnum, 0)) |
2744 | return -EROFS; | 2746 | return -EROFS; |
2745 | err = ubi_leb_unmap(desc, lnum); | 2747 | err = ubi_leb_unmap(desc, lnum); |
2746 | if (err) | 2748 | if (err) |
2747 | return err; | 2749 | return err; |
2748 | if (do_fail(desc, lnum, 0)) | 2750 | if (do_fail(desc, lnum, 0)) |
2749 | return -EROFS; | 2751 | return -EROFS; |
2750 | return 0; | 2752 | return 0; |
2751 | } | 2753 | } |
2752 | 2754 | ||
2753 | int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum) | 2755 | int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum) |
2754 | { | 2756 | { |
2755 | if (in_failure_mode(desc)) | 2757 | if (in_failure_mode(desc)) |
2756 | return -EROFS; | 2758 | return -EROFS; |
2757 | return ubi_is_mapped(desc, lnum); | 2759 | return ubi_is_mapped(desc, lnum); |
2758 | } | 2760 | } |
2759 | 2761 | ||
2760 | int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) | 2762 | int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) |
2761 | { | 2763 | { |
2762 | int err; | 2764 | int err; |
2763 | 2765 | ||
2764 | if (do_fail(desc, lnum, 0)) | 2766 | if (do_fail(desc, lnum, 0)) |
2765 | return -EROFS; | 2767 | return -EROFS; |
2766 | err = ubi_leb_map(desc, lnum, dtype); | 2768 | err = ubi_leb_map(desc, lnum, dtype); |
2767 | if (err) | 2769 | if (err) |
2768 | return err; | 2770 | return err; |
2769 | if (do_fail(desc, lnum, 0)) | 2771 | if (do_fail(desc, lnum, 0)) |
2770 | return -EROFS; | 2772 | return -EROFS; |
2771 | return 0; | 2773 | return 0; |
2772 | } | 2774 | } |
2773 | 2775 | ||
2774 | /** | 2776 | /** |
2775 | * ubifs_debugging_init - initialize UBIFS debugging. | 2777 | * ubifs_debugging_init - initialize UBIFS debugging. |
2776 | * @c: UBIFS file-system description object | 2778 | * @c: UBIFS file-system description object |
2777 | * | 2779 | * |
2778 | * This function initializes debugging-related data for the file system. | 2780 | * This function initializes debugging-related data for the file system. |
2779 | * Returns zero in case of success and a negative error code in case of | 2781 | * Returns zero in case of success and a negative error code in case of |
2780 | * failure. | 2782 | * failure. |
2781 | */ | 2783 | */ |
2782 | int ubifs_debugging_init(struct ubifs_info *c) | 2784 | int ubifs_debugging_init(struct ubifs_info *c) |
2783 | { | 2785 | { |
2784 | c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL); | 2786 | c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL); |
2785 | if (!c->dbg) | 2787 | if (!c->dbg) |
2786 | return -ENOMEM; | 2788 | return -ENOMEM; |
2787 | 2789 | ||
2788 | failure_mode_init(c); | 2790 | failure_mode_init(c); |
2789 | return 0; | 2791 | return 0; |
2790 | } | 2792 | } |
2791 | 2793 | ||
2792 | /** | 2794 | /** |
2793 | * ubifs_debugging_exit - free debugging data. | 2795 | * ubifs_debugging_exit - free debugging data. |
2794 | * @c: UBIFS file-system description object | 2796 | * @c: UBIFS file-system description object |
2795 | */ | 2797 | */ |
2796 | void ubifs_debugging_exit(struct ubifs_info *c) | 2798 | void ubifs_debugging_exit(struct ubifs_info *c) |
2797 | { | 2799 | { |
2798 | failure_mode_exit(c); | 2800 | failure_mode_exit(c); |
2799 | kfree(c->dbg); | 2801 | kfree(c->dbg); |
2800 | } | 2802 | } |
2801 | 2803 | ||
2802 | /* | 2804 | /* |
2803 | * Root directory for UBIFS stuff in debugfs. Contains sub-directories which | 2805 | * Root directory for UBIFS stuff in debugfs. Contains sub-directories which |
2804 | * contain the stuff specific to particular file-system mounts. | 2806 | * contain the stuff specific to particular file-system mounts. |
2805 | */ | 2807 | */ |
2806 | static struct dentry *dfs_rootdir; | 2808 | static struct dentry *dfs_rootdir; |
2807 | 2809 | ||
2808 | /** | 2810 | /** |
2809 | * dbg_debugfs_init - initialize debugfs file-system. | 2811 | * dbg_debugfs_init - initialize debugfs file-system. |
2810 | * | 2812 | * |
2811 | * UBIFS uses debugfs file-system to expose various debugging knobs to | 2813 | * UBIFS uses debugfs file-system to expose various debugging knobs to |
2812 | * user-space. This function creates "ubifs" directory in the debugfs | 2814 | * user-space. This function creates "ubifs" directory in the debugfs |
2813 | * file-system. Returns zero in case of success and a negative error code in | 2815 | * file-system. Returns zero in case of success and a negative error code in |
2814 | * case of failure. | 2816 | * case of failure. |
2815 | */ | 2817 | */ |
2816 | int dbg_debugfs_init(void) | 2818 | int dbg_debugfs_init(void) |
2817 | { | 2819 | { |
2818 | dfs_rootdir = debugfs_create_dir("ubifs", NULL); | 2820 | dfs_rootdir = debugfs_create_dir("ubifs", NULL); |
2819 | if (IS_ERR(dfs_rootdir)) { | 2821 | if (IS_ERR(dfs_rootdir)) { |
2820 | int err = PTR_ERR(dfs_rootdir); | 2822 | int err = PTR_ERR(dfs_rootdir); |
2821 | ubifs_err("cannot create \"ubifs\" debugfs directory, " | 2823 | ubifs_err("cannot create \"ubifs\" debugfs directory, " |
2822 | "error %d\n", err); | 2824 | "error %d\n", err); |
2823 | return err; | 2825 | return err; |
2824 | } | 2826 | } |
2825 | 2827 | ||
2826 | return 0; | 2828 | return 0; |
2827 | } | 2829 | } |
2828 | 2830 | ||
2829 | /** | 2831 | /** |
2830 | * dbg_debugfs_exit - remove the "ubifs" directory from debugfs file-system. | 2832 | * dbg_debugfs_exit - remove the "ubifs" directory from debugfs file-system. |
2831 | */ | 2833 | */ |
2832 | void dbg_debugfs_exit(void) | 2834 | void dbg_debugfs_exit(void) |
2833 | { | 2835 | { |
2834 | debugfs_remove(dfs_rootdir); | 2836 | debugfs_remove(dfs_rootdir); |
2835 | } | 2837 | } |
2836 | 2838 | ||
2837 | static int open_debugfs_file(struct inode *inode, struct file *file) | 2839 | static int open_debugfs_file(struct inode *inode, struct file *file) |
2838 | { | 2840 | { |
2839 | file->private_data = inode->i_private; | 2841 | file->private_data = inode->i_private; |
2840 | return nonseekable_open(inode, file); | 2842 | return nonseekable_open(inode, file); |
2841 | } | 2843 | } |
2842 | 2844 | ||
2843 | static ssize_t write_debugfs_file(struct file *file, const char __user *buf, | 2845 | static ssize_t write_debugfs_file(struct file *file, const char __user *buf, |
2844 | size_t count, loff_t *ppos) | 2846 | size_t count, loff_t *ppos) |
2845 | { | 2847 | { |
2846 | struct ubifs_info *c = file->private_data; | 2848 | struct ubifs_info *c = file->private_data; |
2847 | struct ubifs_debug_info *d = c->dbg; | 2849 | struct ubifs_debug_info *d = c->dbg; |
2848 | 2850 | ||
2849 | if (file->f_path.dentry == d->dfs_dump_lprops) | 2851 | if (file->f_path.dentry == d->dfs_dump_lprops) |
2850 | dbg_dump_lprops(c); | 2852 | dbg_dump_lprops(c); |
2851 | else if (file->f_path.dentry == d->dfs_dump_budg) | 2853 | else if (file->f_path.dentry == d->dfs_dump_budg) |
2852 | dbg_dump_budg(c, &c->bi); | 2854 | dbg_dump_budg(c, &c->bi); |
2853 | else if (file->f_path.dentry == d->dfs_dump_tnc) { | 2855 | else if (file->f_path.dentry == d->dfs_dump_tnc) { |
2854 | mutex_lock(&c->tnc_mutex); | 2856 | mutex_lock(&c->tnc_mutex); |
2855 | dbg_dump_tnc(c); | 2857 | dbg_dump_tnc(c); |
2856 | mutex_unlock(&c->tnc_mutex); | 2858 | mutex_unlock(&c->tnc_mutex); |
2857 | } else | 2859 | } else |
2858 | return -EINVAL; | 2860 | return -EINVAL; |
2859 | 2861 | ||
2860 | return count; | 2862 | return count; |
2861 | } | 2863 | } |
2862 | 2864 | ||
2863 | static const struct file_operations dfs_fops = { | 2865 | static const struct file_operations dfs_fops = { |
2864 | .open = open_debugfs_file, | 2866 | .open = open_debugfs_file, |
2865 | .write = write_debugfs_file, | 2867 | .write = write_debugfs_file, |
2866 | .owner = THIS_MODULE, | 2868 | .owner = THIS_MODULE, |
2867 | .llseek = no_llseek, | 2869 | .llseek = no_llseek, |
2868 | }; | 2870 | }; |
2869 | 2871 | ||
2870 | /** | 2872 | /** |
2871 | * dbg_debugfs_init_fs - initialize debugfs for UBIFS instance. | 2873 | * dbg_debugfs_init_fs - initialize debugfs for UBIFS instance. |
2872 | * @c: UBIFS file-system description object | 2874 | * @c: UBIFS file-system description object |
2873 | * | 2875 | * |
2874 | * This function creates all debugfs files for this instance of UBIFS. Returns | 2876 | * This function creates all debugfs files for this instance of UBIFS. Returns |
2875 | * zero in case of success and a negative error code in case of failure. | 2877 | * zero in case of success and a negative error code in case of failure. |
2876 | * | 2878 | * |
2877 | * Note, the only reason we have not merged this function with the | 2879 | * Note, the only reason we have not merged this function with the |
2878 | * 'ubifs_debugging_init()' function is because it is better to initialize | 2880 | * 'ubifs_debugging_init()' function is because it is better to initialize |
2879 | * debugfs interfaces at the very end of the mount process, and remove them at | 2881 | * debugfs interfaces at the very end of the mount process, and remove them at |
2880 | * the very beginning of the mount process. | 2882 | * the very beginning of the mount process. |
2881 | */ | 2883 | */ |
2882 | int dbg_debugfs_init_fs(struct ubifs_info *c) | 2884 | int dbg_debugfs_init_fs(struct ubifs_info *c) |
2883 | { | 2885 | { |
2884 | int err; | 2886 | int err; |
2885 | const char *fname; | 2887 | const char *fname; |
2886 | struct dentry *dent; | 2888 | struct dentry *dent; |
2887 | struct ubifs_debug_info *d = c->dbg; | 2889 | struct ubifs_debug_info *d = c->dbg; |
2888 | 2890 | ||
2889 | sprintf(d->dfs_dir_name, "ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); | 2891 | sprintf(d->dfs_dir_name, "ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); |
2890 | fname = d->dfs_dir_name; | 2892 | fname = d->dfs_dir_name; |
2891 | dent = debugfs_create_dir(fname, dfs_rootdir); | 2893 | dent = debugfs_create_dir(fname, dfs_rootdir); |
2892 | if (IS_ERR_OR_NULL(dent)) | 2894 | if (IS_ERR_OR_NULL(dent)) |
2893 | goto out; | 2895 | goto out; |
2894 | d->dfs_dir = dent; | 2896 | d->dfs_dir = dent; |
2895 | 2897 | ||
2896 | fname = "dump_lprops"; | 2898 | fname = "dump_lprops"; |
2897 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); | 2899 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
2898 | if (IS_ERR_OR_NULL(dent)) | 2900 | if (IS_ERR_OR_NULL(dent)) |
2899 | goto out_remove; | 2901 | goto out_remove; |
2900 | d->dfs_dump_lprops = dent; | 2902 | d->dfs_dump_lprops = dent; |
2901 | 2903 | ||
2902 | fname = "dump_budg"; | 2904 | fname = "dump_budg"; |
2903 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); | 2905 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
2904 | if (IS_ERR_OR_NULL(dent)) | 2906 | if (IS_ERR_OR_NULL(dent)) |
2905 | goto out_remove; | 2907 | goto out_remove; |
2906 | d->dfs_dump_budg = dent; | 2908 | d->dfs_dump_budg = dent; |
2907 | 2909 | ||
2908 | fname = "dump_tnc"; | 2910 | fname = "dump_tnc"; |
2909 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); | 2911 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
2910 | if (IS_ERR_OR_NULL(dent)) | 2912 | if (IS_ERR_OR_NULL(dent)) |
2911 | goto out_remove; | 2913 | goto out_remove; |
2912 | d->dfs_dump_tnc = dent; | 2914 | d->dfs_dump_tnc = dent; |
2913 | 2915 | ||
2914 | return 0; | 2916 | return 0; |
2915 | 2917 | ||
2916 | out_remove: | 2918 | out_remove: |
2917 | debugfs_remove_recursive(d->dfs_dir); | 2919 | debugfs_remove_recursive(d->dfs_dir); |
2918 | out: | 2920 | out: |
2919 | err = dent ? PTR_ERR(dent) : -ENODEV; | 2921 | err = dent ? PTR_ERR(dent) : -ENODEV; |
2920 | ubifs_err("cannot create \"%s\" debugfs directory, error %d\n", | 2922 | ubifs_err("cannot create \"%s\" debugfs directory, error %d\n", |
2921 | fname, err); | 2923 | fname, err); |
2922 | return err; | 2924 | return err; |
2923 | } | 2925 | } |
2924 | 2926 | ||
2925 | /** | 2927 | /** |
2926 | * dbg_debugfs_exit_fs - remove all debugfs files. | 2928 | * dbg_debugfs_exit_fs - remove all debugfs files. |
2927 | * @c: UBIFS file-system description object | 2929 | * @c: UBIFS file-system description object |
2928 | */ | 2930 | */ |
2929 | void dbg_debugfs_exit_fs(struct ubifs_info *c) | 2931 | void dbg_debugfs_exit_fs(struct ubifs_info *c) |
2930 | { | 2932 | { |
2931 | debugfs_remove_recursive(c->dbg->dfs_dir); | 2933 | debugfs_remove_recursive(c->dbg->dfs_dir); |
2932 | } | 2934 | } |
2933 | 2935 | ||
2934 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | 2936 | #endif /* CONFIG_UBIFS_FS_DEBUG */ |
2935 | 2937 |
fs/ubifs/sb.c
1 | /* | 1 | /* |
2 | * This file is part of UBIFS. | 2 | * This file is part of UBIFS. |
3 | * | 3 | * |
4 | * Copyright (C) 2006-2008 Nokia Corporation. | 4 | * Copyright (C) 2006-2008 Nokia Corporation. |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 6 | * This program is free software; you can redistribute it and/or modify it |
7 | * under the terms of the GNU General Public License version 2 as published by | 7 | * under the terms of the GNU General Public License version 2 as published by |
8 | * the Free Software Foundation. | 8 | * the Free Software Foundation. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
13 | * more details. | 13 | * more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License along with | 15 | * You should have received a copy of the GNU General Public License along with |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | 16 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | * | 18 | * |
19 | * Authors: Artem Bityutskiy (Битюцкий Артём) | 19 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
20 | * Adrian Hunter | 20 | * Adrian Hunter |
21 | */ | 21 | */ |
22 | 22 | ||
23 | /* | 23 | /* |
24 | * This file implements UBIFS superblock. The superblock is stored at the first | 24 | * This file implements UBIFS superblock. The superblock is stored at the first |
25 | * LEB of the volume and is never changed by UBIFS. Only user-space tools may | 25 | * LEB of the volume and is never changed by UBIFS. Only user-space tools may |
26 | * change it. The superblock node mostly contains geometry information. | 26 | * change it. The superblock node mostly contains geometry information. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "ubifs.h" | 29 | #include "ubifs.h" |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | #include <linux/random.h> | 31 | #include <linux/random.h> |
32 | #include <linux/math64.h> | 32 | #include <linux/math64.h> |
33 | 33 | ||
34 | /* | 34 | /* |
35 | * Default journal size in logical eraseblocks as a percent of total | 35 | * Default journal size in logical eraseblocks as a percent of total |
36 | * flash size. | 36 | * flash size. |
37 | */ | 37 | */ |
38 | #define DEFAULT_JNL_PERCENT 5 | 38 | #define DEFAULT_JNL_PERCENT 5 |
39 | 39 | ||
40 | /* Default maximum journal size in bytes */ | 40 | /* Default maximum journal size in bytes */ |
41 | #define DEFAULT_MAX_JNL (32*1024*1024) | 41 | #define DEFAULT_MAX_JNL (32*1024*1024) |
42 | 42 | ||
43 | /* Default indexing tree fanout */ | 43 | /* Default indexing tree fanout */ |
44 | #define DEFAULT_FANOUT 8 | 44 | #define DEFAULT_FANOUT 8 |
45 | 45 | ||
46 | /* Default number of data journal heads */ | 46 | /* Default number of data journal heads */ |
47 | #define DEFAULT_JHEADS_CNT 1 | 47 | #define DEFAULT_JHEADS_CNT 1 |
48 | 48 | ||
49 | /* Default positions of different LEBs in the main area */ | 49 | /* Default positions of different LEBs in the main area */ |
50 | #define DEFAULT_IDX_LEB 0 | 50 | #define DEFAULT_IDX_LEB 0 |
51 | #define DEFAULT_DATA_LEB 1 | 51 | #define DEFAULT_DATA_LEB 1 |
52 | #define DEFAULT_GC_LEB 2 | 52 | #define DEFAULT_GC_LEB 2 |
53 | 53 | ||
54 | /* Default number of LEB numbers in LPT's save table */ | 54 | /* Default number of LEB numbers in LPT's save table */ |
55 | #define DEFAULT_LSAVE_CNT 256 | 55 | #define DEFAULT_LSAVE_CNT 256 |
56 | 56 | ||
57 | /* Default reserved pool size as a percent of maximum free space */ | 57 | /* Default reserved pool size as a percent of maximum free space */ |
58 | #define DEFAULT_RP_PERCENT 5 | 58 | #define DEFAULT_RP_PERCENT 5 |
59 | 59 | ||
60 | /* The default maximum size of reserved pool in bytes */ | 60 | /* The default maximum size of reserved pool in bytes */ |
61 | #define DEFAULT_MAX_RP_SIZE (5*1024*1024) | 61 | #define DEFAULT_MAX_RP_SIZE (5*1024*1024) |
62 | 62 | ||
63 | /* Default time granularity in nanoseconds */ | 63 | /* Default time granularity in nanoseconds */ |
64 | #define DEFAULT_TIME_GRAN 1000000000 | 64 | #define DEFAULT_TIME_GRAN 1000000000 |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * create_default_filesystem - format empty UBI volume. | 67 | * create_default_filesystem - format empty UBI volume. |
68 | * @c: UBIFS file-system description object | 68 | * @c: UBIFS file-system description object |
69 | * | 69 | * |
70 | * This function creates default empty file-system. Returns zero in case of | 70 | * This function creates default empty file-system. Returns zero in case of |
71 | * success and a negative error code in case of failure. | 71 | * success and a negative error code in case of failure. |
72 | */ | 72 | */ |
73 | static int create_default_filesystem(struct ubifs_info *c) | 73 | static int create_default_filesystem(struct ubifs_info *c) |
74 | { | 74 | { |
75 | struct ubifs_sb_node *sup; | 75 | struct ubifs_sb_node *sup; |
76 | struct ubifs_mst_node *mst; | 76 | struct ubifs_mst_node *mst; |
77 | struct ubifs_idx_node *idx; | 77 | struct ubifs_idx_node *idx; |
78 | struct ubifs_branch *br; | 78 | struct ubifs_branch *br; |
79 | struct ubifs_ino_node *ino; | 79 | struct ubifs_ino_node *ino; |
80 | struct ubifs_cs_node *cs; | 80 | struct ubifs_cs_node *cs; |
81 | union ubifs_key key; | 81 | union ubifs_key key; |
82 | int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first; | 82 | int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first; |
83 | int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0; | 83 | int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0; |
84 | int min_leb_cnt = UBIFS_MIN_LEB_CNT; | 84 | int min_leb_cnt = UBIFS_MIN_LEB_CNT; |
85 | long long tmp64, main_bytes; | 85 | long long tmp64, main_bytes; |
86 | __le64 tmp_le64; | 86 | __le64 tmp_le64; |
87 | 87 | ||
88 | /* Some functions called from here depend on the @c->key_len filed */ | 88 | /* Some functions called from here depend on the @c->key_len filed */ |
89 | c->key_len = UBIFS_SK_LEN; | 89 | c->key_len = UBIFS_SK_LEN; |
90 | 90 | ||
91 | /* | 91 | /* |
92 | * First of all, we have to calculate default file-system geometry - | 92 | * First of all, we have to calculate default file-system geometry - |
93 | * log size, journal size, etc. | 93 | * log size, journal size, etc. |
94 | */ | 94 | */ |
95 | if (c->leb_cnt < 0x7FFFFFFF / DEFAULT_JNL_PERCENT) | 95 | if (c->leb_cnt < 0x7FFFFFFF / DEFAULT_JNL_PERCENT) |
96 | /* We can first multiply then divide and have no overflow */ | 96 | /* We can first multiply then divide and have no overflow */ |
97 | jnl_lebs = c->leb_cnt * DEFAULT_JNL_PERCENT / 100; | 97 | jnl_lebs = c->leb_cnt * DEFAULT_JNL_PERCENT / 100; |
98 | else | 98 | else |
99 | jnl_lebs = (c->leb_cnt / 100) * DEFAULT_JNL_PERCENT; | 99 | jnl_lebs = (c->leb_cnt / 100) * DEFAULT_JNL_PERCENT; |
100 | 100 | ||
101 | if (jnl_lebs < UBIFS_MIN_JNL_LEBS) | 101 | if (jnl_lebs < UBIFS_MIN_JNL_LEBS) |
102 | jnl_lebs = UBIFS_MIN_JNL_LEBS; | 102 | jnl_lebs = UBIFS_MIN_JNL_LEBS; |
103 | if (jnl_lebs * c->leb_size > DEFAULT_MAX_JNL) | 103 | if (jnl_lebs * c->leb_size > DEFAULT_MAX_JNL) |
104 | jnl_lebs = DEFAULT_MAX_JNL / c->leb_size; | 104 | jnl_lebs = DEFAULT_MAX_JNL / c->leb_size; |
105 | 105 | ||
106 | /* | 106 | /* |
107 | * The log should be large enough to fit reference nodes for all bud | 107 | * The log should be large enough to fit reference nodes for all bud |
108 | * LEBs. Because buds do not have to start from the beginning of LEBs | 108 | * LEBs. Because buds do not have to start from the beginning of LEBs |
109 | * (half of the LEB may contain committed data), the log should | 109 | * (half of the LEB may contain committed data), the log should |
110 | * generally be larger, make it twice as large. | 110 | * generally be larger, make it twice as large. |
111 | */ | 111 | */ |
112 | tmp = 2 * (c->ref_node_alsz * jnl_lebs) + c->leb_size - 1; | 112 | tmp = 2 * (c->ref_node_alsz * jnl_lebs) + c->leb_size - 1; |
113 | log_lebs = tmp / c->leb_size; | 113 | log_lebs = tmp / c->leb_size; |
114 | /* Plus one LEB reserved for commit */ | 114 | /* Plus one LEB reserved for commit */ |
115 | log_lebs += 1; | 115 | log_lebs += 1; |
116 | if (c->leb_cnt - min_leb_cnt > 8) { | 116 | if (c->leb_cnt - min_leb_cnt > 8) { |
117 | /* And some extra space to allow writes while committing */ | 117 | /* And some extra space to allow writes while committing */ |
118 | log_lebs += 1; | 118 | log_lebs += 1; |
119 | min_leb_cnt += 1; | 119 | min_leb_cnt += 1; |
120 | } | 120 | } |
121 | 121 | ||
122 | max_buds = jnl_lebs - log_lebs; | 122 | max_buds = jnl_lebs - log_lebs; |
123 | if (max_buds < UBIFS_MIN_BUD_LEBS) | 123 | if (max_buds < UBIFS_MIN_BUD_LEBS) |
124 | max_buds = UBIFS_MIN_BUD_LEBS; | 124 | max_buds = UBIFS_MIN_BUD_LEBS; |
125 | 125 | ||
126 | /* | 126 | /* |
127 | * Orphan nodes are stored in a separate area. One node can store a lot | 127 | * Orphan nodes are stored in a separate area. One node can store a lot |
128 | * of orphan inode numbers, but when new orphan comes we just add a new | 128 | * of orphan inode numbers, but when new orphan comes we just add a new |
129 | * orphan node. At some point the nodes are consolidated into one | 129 | * orphan node. At some point the nodes are consolidated into one |
130 | * orphan node. | 130 | * orphan node. |
131 | */ | 131 | */ |
132 | orph_lebs = UBIFS_MIN_ORPH_LEBS; | 132 | orph_lebs = UBIFS_MIN_ORPH_LEBS; |
133 | #ifdef CONFIG_UBIFS_FS_DEBUG | 133 | #ifdef CONFIG_UBIFS_FS_DEBUG |
134 | if (c->leb_cnt - min_leb_cnt > 1) | 134 | if (c->leb_cnt - min_leb_cnt > 1) |
135 | /* | 135 | /* |
136 | * For debugging purposes it is better to have at least 2 | 136 | * For debugging purposes it is better to have at least 2 |
137 | * orphan LEBs, because the orphan subsystem would need to do | 137 | * orphan LEBs, because the orphan subsystem would need to do |
138 | * consolidations and would be stressed more. | 138 | * consolidations and would be stressed more. |
139 | */ | 139 | */ |
140 | orph_lebs += 1; | 140 | orph_lebs += 1; |
141 | #endif | 141 | #endif |
142 | 142 | ||
143 | main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - log_lebs; | 143 | main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - log_lebs; |
144 | main_lebs -= orph_lebs; | 144 | main_lebs -= orph_lebs; |
145 | 145 | ||
146 | lpt_first = UBIFS_LOG_LNUM + log_lebs; | 146 | lpt_first = UBIFS_LOG_LNUM + log_lebs; |
147 | c->lsave_cnt = DEFAULT_LSAVE_CNT; | 147 | c->lsave_cnt = DEFAULT_LSAVE_CNT; |
148 | c->max_leb_cnt = c->leb_cnt; | 148 | c->max_leb_cnt = c->leb_cnt; |
149 | err = ubifs_create_dflt_lpt(c, &main_lebs, lpt_first, &lpt_lebs, | 149 | err = ubifs_create_dflt_lpt(c, &main_lebs, lpt_first, &lpt_lebs, |
150 | &big_lpt); | 150 | &big_lpt); |
151 | if (err) | 151 | if (err) |
152 | return err; | 152 | return err; |
153 | 153 | ||
154 | dbg_gen("LEB Properties Tree created (LEBs %d-%d)", lpt_first, | 154 | dbg_gen("LEB Properties Tree created (LEBs %d-%d)", lpt_first, |
155 | lpt_first + lpt_lebs - 1); | 155 | lpt_first + lpt_lebs - 1); |
156 | 156 | ||
157 | main_first = c->leb_cnt - main_lebs; | 157 | main_first = c->leb_cnt - main_lebs; |
158 | 158 | ||
159 | /* Create default superblock */ | 159 | /* Create default superblock */ |
160 | tmp = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size); | 160 | tmp = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size); |
161 | sup = kzalloc(tmp, GFP_KERNEL); | 161 | sup = kzalloc(tmp, GFP_KERNEL); |
162 | if (!sup) | 162 | if (!sup) |
163 | return -ENOMEM; | 163 | return -ENOMEM; |
164 | 164 | ||
165 | tmp64 = (long long)max_buds * c->leb_size; | 165 | tmp64 = (long long)max_buds * c->leb_size; |
166 | if (big_lpt) | 166 | if (big_lpt) |
167 | sup_flags |= UBIFS_FLG_BIGLPT; | 167 | sup_flags |= UBIFS_FLG_BIGLPT; |
168 | 168 | ||
169 | sup->ch.node_type = UBIFS_SB_NODE; | 169 | sup->ch.node_type = UBIFS_SB_NODE; |
170 | sup->key_hash = UBIFS_KEY_HASH_R5; | 170 | sup->key_hash = UBIFS_KEY_HASH_R5; |
171 | sup->flags = cpu_to_le32(sup_flags); | 171 | sup->flags = cpu_to_le32(sup_flags); |
172 | sup->min_io_size = cpu_to_le32(c->min_io_size); | 172 | sup->min_io_size = cpu_to_le32(c->min_io_size); |
173 | sup->leb_size = cpu_to_le32(c->leb_size); | 173 | sup->leb_size = cpu_to_le32(c->leb_size); |
174 | sup->leb_cnt = cpu_to_le32(c->leb_cnt); | 174 | sup->leb_cnt = cpu_to_le32(c->leb_cnt); |
175 | sup->max_leb_cnt = cpu_to_le32(c->max_leb_cnt); | 175 | sup->max_leb_cnt = cpu_to_le32(c->max_leb_cnt); |
176 | sup->max_bud_bytes = cpu_to_le64(tmp64); | 176 | sup->max_bud_bytes = cpu_to_le64(tmp64); |
177 | sup->log_lebs = cpu_to_le32(log_lebs); | 177 | sup->log_lebs = cpu_to_le32(log_lebs); |
178 | sup->lpt_lebs = cpu_to_le32(lpt_lebs); | 178 | sup->lpt_lebs = cpu_to_le32(lpt_lebs); |
179 | sup->orph_lebs = cpu_to_le32(orph_lebs); | 179 | sup->orph_lebs = cpu_to_le32(orph_lebs); |
180 | sup->jhead_cnt = cpu_to_le32(DEFAULT_JHEADS_CNT); | 180 | sup->jhead_cnt = cpu_to_le32(DEFAULT_JHEADS_CNT); |
181 | sup->fanout = cpu_to_le32(DEFAULT_FANOUT); | 181 | sup->fanout = cpu_to_le32(DEFAULT_FANOUT); |
182 | sup->lsave_cnt = cpu_to_le32(c->lsave_cnt); | 182 | sup->lsave_cnt = cpu_to_le32(c->lsave_cnt); |
183 | sup->fmt_version = cpu_to_le32(UBIFS_FORMAT_VERSION); | 183 | sup->fmt_version = cpu_to_le32(UBIFS_FORMAT_VERSION); |
184 | sup->time_gran = cpu_to_le32(DEFAULT_TIME_GRAN); | 184 | sup->time_gran = cpu_to_le32(DEFAULT_TIME_GRAN); |
185 | if (c->mount_opts.override_compr) | 185 | if (c->mount_opts.override_compr) |
186 | sup->default_compr = cpu_to_le16(c->mount_opts.compr_type); | 186 | sup->default_compr = cpu_to_le16(c->mount_opts.compr_type); |
187 | else | 187 | else |
188 | sup->default_compr = cpu_to_le16(UBIFS_COMPR_LZO); | 188 | sup->default_compr = cpu_to_le16(UBIFS_COMPR_LZO); |
189 | 189 | ||
190 | generate_random_uuid(sup->uuid); | 190 | generate_random_uuid(sup->uuid); |
191 | 191 | ||
192 | main_bytes = (long long)main_lebs * c->leb_size; | 192 | main_bytes = (long long)main_lebs * c->leb_size; |
193 | tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100); | 193 | tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100); |
194 | if (tmp64 > DEFAULT_MAX_RP_SIZE) | 194 | if (tmp64 > DEFAULT_MAX_RP_SIZE) |
195 | tmp64 = DEFAULT_MAX_RP_SIZE; | 195 | tmp64 = DEFAULT_MAX_RP_SIZE; |
196 | sup->rp_size = cpu_to_le64(tmp64); | 196 | sup->rp_size = cpu_to_le64(tmp64); |
197 | sup->ro_compat_version = cpu_to_le32(UBIFS_RO_COMPAT_VERSION); | 197 | sup->ro_compat_version = cpu_to_le32(UBIFS_RO_COMPAT_VERSION); |
198 | 198 | ||
199 | err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0, UBI_LONGTERM); | 199 | err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0, UBI_LONGTERM); |
200 | kfree(sup); | 200 | kfree(sup); |
201 | if (err) | 201 | if (err) |
202 | return err; | 202 | return err; |
203 | 203 | ||
204 | dbg_gen("default superblock created at LEB 0:0"); | 204 | dbg_gen("default superblock created at LEB 0:0"); |
205 | 205 | ||
206 | /* Create default master node */ | 206 | /* Create default master node */ |
207 | mst = kzalloc(c->mst_node_alsz, GFP_KERNEL); | 207 | mst = kzalloc(c->mst_node_alsz, GFP_KERNEL); |
208 | if (!mst) | 208 | if (!mst) |
209 | return -ENOMEM; | 209 | return -ENOMEM; |
210 | 210 | ||
211 | mst->ch.node_type = UBIFS_MST_NODE; | 211 | mst->ch.node_type = UBIFS_MST_NODE; |
212 | mst->log_lnum = cpu_to_le32(UBIFS_LOG_LNUM); | 212 | mst->log_lnum = cpu_to_le32(UBIFS_LOG_LNUM); |
213 | mst->highest_inum = cpu_to_le64(UBIFS_FIRST_INO); | 213 | mst->highest_inum = cpu_to_le64(UBIFS_FIRST_INO); |
214 | mst->cmt_no = 0; | 214 | mst->cmt_no = 0; |
215 | mst->root_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB); | 215 | mst->root_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB); |
216 | mst->root_offs = 0; | 216 | mst->root_offs = 0; |
217 | tmp = ubifs_idx_node_sz(c, 1); | 217 | tmp = ubifs_idx_node_sz(c, 1); |
218 | mst->root_len = cpu_to_le32(tmp); | 218 | mst->root_len = cpu_to_le32(tmp); |
219 | mst->gc_lnum = cpu_to_le32(main_first + DEFAULT_GC_LEB); | 219 | mst->gc_lnum = cpu_to_le32(main_first + DEFAULT_GC_LEB); |
220 | mst->ihead_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB); | 220 | mst->ihead_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB); |
221 | mst->ihead_offs = cpu_to_le32(ALIGN(tmp, c->min_io_size)); | 221 | mst->ihead_offs = cpu_to_le32(ALIGN(tmp, c->min_io_size)); |
222 | mst->index_size = cpu_to_le64(ALIGN(tmp, 8)); | 222 | mst->index_size = cpu_to_le64(ALIGN(tmp, 8)); |
223 | mst->lpt_lnum = cpu_to_le32(c->lpt_lnum); | 223 | mst->lpt_lnum = cpu_to_le32(c->lpt_lnum); |
224 | mst->lpt_offs = cpu_to_le32(c->lpt_offs); | 224 | mst->lpt_offs = cpu_to_le32(c->lpt_offs); |
225 | mst->nhead_lnum = cpu_to_le32(c->nhead_lnum); | 225 | mst->nhead_lnum = cpu_to_le32(c->nhead_lnum); |
226 | mst->nhead_offs = cpu_to_le32(c->nhead_offs); | 226 | mst->nhead_offs = cpu_to_le32(c->nhead_offs); |
227 | mst->ltab_lnum = cpu_to_le32(c->ltab_lnum); | 227 | mst->ltab_lnum = cpu_to_le32(c->ltab_lnum); |
228 | mst->ltab_offs = cpu_to_le32(c->ltab_offs); | 228 | mst->ltab_offs = cpu_to_le32(c->ltab_offs); |
229 | mst->lsave_lnum = cpu_to_le32(c->lsave_lnum); | 229 | mst->lsave_lnum = cpu_to_le32(c->lsave_lnum); |
230 | mst->lsave_offs = cpu_to_le32(c->lsave_offs); | 230 | mst->lsave_offs = cpu_to_le32(c->lsave_offs); |
231 | mst->lscan_lnum = cpu_to_le32(main_first); | 231 | mst->lscan_lnum = cpu_to_le32(main_first); |
232 | mst->empty_lebs = cpu_to_le32(main_lebs - 2); | 232 | mst->empty_lebs = cpu_to_le32(main_lebs - 2); |
233 | mst->idx_lebs = cpu_to_le32(1); | 233 | mst->idx_lebs = cpu_to_le32(1); |
234 | mst->leb_cnt = cpu_to_le32(c->leb_cnt); | 234 | mst->leb_cnt = cpu_to_le32(c->leb_cnt); |
235 | 235 | ||
236 | /* Calculate lprops statistics */ | 236 | /* Calculate lprops statistics */ |
237 | tmp64 = main_bytes; | 237 | tmp64 = main_bytes; |
238 | tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size); | 238 | tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size); |
239 | tmp64 -= ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size); | 239 | tmp64 -= ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size); |
240 | mst->total_free = cpu_to_le64(tmp64); | 240 | mst->total_free = cpu_to_le64(tmp64); |
241 | 241 | ||
242 | tmp64 = ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size); | 242 | tmp64 = ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size); |
243 | ino_waste = ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size) - | 243 | ino_waste = ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size) - |
244 | UBIFS_INO_NODE_SZ; | 244 | UBIFS_INO_NODE_SZ; |
245 | tmp64 += ino_waste; | 245 | tmp64 += ino_waste; |
246 | tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), 8); | 246 | tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), 8); |
247 | mst->total_dirty = cpu_to_le64(tmp64); | 247 | mst->total_dirty = cpu_to_le64(tmp64); |
248 | 248 | ||
249 | /* The indexing LEB does not contribute to dark space */ | 249 | /* The indexing LEB does not contribute to dark space */ |
250 | tmp64 = (c->main_lebs - 1) * c->dark_wm; | 250 | tmp64 = (c->main_lebs - 1) * c->dark_wm; |
251 | mst->total_dark = cpu_to_le64(tmp64); | 251 | mst->total_dark = cpu_to_le64(tmp64); |
252 | 252 | ||
253 | mst->total_used = cpu_to_le64(UBIFS_INO_NODE_SZ); | 253 | mst->total_used = cpu_to_le64(UBIFS_INO_NODE_SZ); |
254 | 254 | ||
255 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0, | 255 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0, |
256 | UBI_UNKNOWN); | 256 | UBI_UNKNOWN); |
257 | if (err) { | 257 | if (err) { |
258 | kfree(mst); | 258 | kfree(mst); |
259 | return err; | 259 | return err; |
260 | } | 260 | } |
261 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, 0, | 261 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, 0, |
262 | UBI_UNKNOWN); | 262 | UBI_UNKNOWN); |
263 | kfree(mst); | 263 | kfree(mst); |
264 | if (err) | 264 | if (err) |
265 | return err; | 265 | return err; |
266 | 266 | ||
267 | dbg_gen("default master node created at LEB %d:0", UBIFS_MST_LNUM); | 267 | dbg_gen("default master node created at LEB %d:0", UBIFS_MST_LNUM); |
268 | 268 | ||
269 | /* Create the root indexing node */ | 269 | /* Create the root indexing node */ |
270 | tmp = ubifs_idx_node_sz(c, 1); | 270 | tmp = ubifs_idx_node_sz(c, 1); |
271 | idx = kzalloc(ALIGN(tmp, c->min_io_size), GFP_KERNEL); | 271 | idx = kzalloc(ALIGN(tmp, c->min_io_size), GFP_KERNEL); |
272 | if (!idx) | 272 | if (!idx) |
273 | return -ENOMEM; | 273 | return -ENOMEM; |
274 | 274 | ||
275 | c->key_fmt = UBIFS_SIMPLE_KEY_FMT; | 275 | c->key_fmt = UBIFS_SIMPLE_KEY_FMT; |
276 | c->key_hash = key_r5_hash; | 276 | c->key_hash = key_r5_hash; |
277 | 277 | ||
278 | idx->ch.node_type = UBIFS_IDX_NODE; | 278 | idx->ch.node_type = UBIFS_IDX_NODE; |
279 | idx->child_cnt = cpu_to_le16(1); | 279 | idx->child_cnt = cpu_to_le16(1); |
280 | ino_key_init(c, &key, UBIFS_ROOT_INO); | 280 | ino_key_init(c, &key, UBIFS_ROOT_INO); |
281 | br = ubifs_idx_branch(c, idx, 0); | 281 | br = ubifs_idx_branch(c, idx, 0); |
282 | key_write_idx(c, &key, &br->key); | 282 | key_write_idx(c, &key, &br->key); |
283 | br->lnum = cpu_to_le32(main_first + DEFAULT_DATA_LEB); | 283 | br->lnum = cpu_to_le32(main_first + DEFAULT_DATA_LEB); |
284 | br->len = cpu_to_le32(UBIFS_INO_NODE_SZ); | 284 | br->len = cpu_to_le32(UBIFS_INO_NODE_SZ); |
285 | err = ubifs_write_node(c, idx, tmp, main_first + DEFAULT_IDX_LEB, 0, | 285 | err = ubifs_write_node(c, idx, tmp, main_first + DEFAULT_IDX_LEB, 0, |
286 | UBI_UNKNOWN); | 286 | UBI_UNKNOWN); |
287 | kfree(idx); | 287 | kfree(idx); |
288 | if (err) | 288 | if (err) |
289 | return err; | 289 | return err; |
290 | 290 | ||
291 | dbg_gen("default root indexing node created LEB %d:0", | 291 | dbg_gen("default root indexing node created LEB %d:0", |
292 | main_first + DEFAULT_IDX_LEB); | 292 | main_first + DEFAULT_IDX_LEB); |
293 | 293 | ||
294 | /* Create default root inode */ | 294 | /* Create default root inode */ |
295 | tmp = ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size); | 295 | tmp = ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size); |
296 | ino = kzalloc(tmp, GFP_KERNEL); | 296 | ino = kzalloc(tmp, GFP_KERNEL); |
297 | if (!ino) | 297 | if (!ino) |
298 | return -ENOMEM; | 298 | return -ENOMEM; |
299 | 299 | ||
300 | ino_key_init_flash(c, &ino->key, UBIFS_ROOT_INO); | 300 | ino_key_init_flash(c, &ino->key, UBIFS_ROOT_INO); |
301 | ino->ch.node_type = UBIFS_INO_NODE; | 301 | ino->ch.node_type = UBIFS_INO_NODE; |
302 | ino->creat_sqnum = cpu_to_le64(++c->max_sqnum); | 302 | ino->creat_sqnum = cpu_to_le64(++c->max_sqnum); |
303 | ino->nlink = cpu_to_le32(2); | 303 | ino->nlink = cpu_to_le32(2); |
304 | tmp_le64 = cpu_to_le64(CURRENT_TIME_SEC.tv_sec); | 304 | tmp_le64 = cpu_to_le64(CURRENT_TIME_SEC.tv_sec); |
305 | ino->atime_sec = tmp_le64; | 305 | ino->atime_sec = tmp_le64; |
306 | ino->ctime_sec = tmp_le64; | 306 | ino->ctime_sec = tmp_le64; |
307 | ino->mtime_sec = tmp_le64; | 307 | ino->mtime_sec = tmp_le64; |
308 | ino->atime_nsec = 0; | 308 | ino->atime_nsec = 0; |
309 | ino->ctime_nsec = 0; | 309 | ino->ctime_nsec = 0; |
310 | ino->mtime_nsec = 0; | 310 | ino->mtime_nsec = 0; |
311 | ino->mode = cpu_to_le32(S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO); | 311 | ino->mode = cpu_to_le32(S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO); |
312 | ino->size = cpu_to_le64(UBIFS_INO_NODE_SZ); | 312 | ino->size = cpu_to_le64(UBIFS_INO_NODE_SZ); |
313 | 313 | ||
314 | /* Set compression enabled by default */ | 314 | /* Set compression enabled by default */ |
315 | ino->flags = cpu_to_le32(UBIFS_COMPR_FL); | 315 | ino->flags = cpu_to_le32(UBIFS_COMPR_FL); |
316 | 316 | ||
317 | err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, | 317 | err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, |
318 | main_first + DEFAULT_DATA_LEB, 0, | 318 | main_first + DEFAULT_DATA_LEB, 0, |
319 | UBI_UNKNOWN); | 319 | UBI_UNKNOWN); |
320 | kfree(ino); | 320 | kfree(ino); |
321 | if (err) | 321 | if (err) |
322 | return err; | 322 | return err; |
323 | 323 | ||
324 | dbg_gen("root inode created at LEB %d:0", | 324 | dbg_gen("root inode created at LEB %d:0", |
325 | main_first + DEFAULT_DATA_LEB); | 325 | main_first + DEFAULT_DATA_LEB); |
326 | 326 | ||
327 | /* | 327 | /* |
328 | * The first node in the log has to be the commit start node. This is | 328 | * The first node in the log has to be the commit start node. This is |
329 | * always the case during normal file-system operation. Write a fake | 329 | * always the case during normal file-system operation. Write a fake |
330 | * commit start node to the log. | 330 | * commit start node to the log. |
331 | */ | 331 | */ |
332 | tmp = ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size); | 332 | tmp = ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size); |
333 | cs = kzalloc(tmp, GFP_KERNEL); | 333 | cs = kzalloc(tmp, GFP_KERNEL); |
334 | if (!cs) | 334 | if (!cs) |
335 | return -ENOMEM; | 335 | return -ENOMEM; |
336 | 336 | ||
337 | cs->ch.node_type = UBIFS_CS_NODE; | 337 | cs->ch.node_type = UBIFS_CS_NODE; |
338 | err = ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, | 338 | err = ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, |
339 | 0, UBI_UNKNOWN); | 339 | 0, UBI_UNKNOWN); |
340 | kfree(cs); | 340 | kfree(cs); |
341 | 341 | ||
342 | ubifs_msg("default file-system created"); | 342 | ubifs_msg("default file-system created"); |
343 | return 0; | 343 | return 0; |
344 | } | 344 | } |
345 | 345 | ||
346 | /** | 346 | /** |
347 | * validate_sb - validate superblock node. | 347 | * validate_sb - validate superblock node. |
348 | * @c: UBIFS file-system description object | 348 | * @c: UBIFS file-system description object |
349 | * @sup: superblock node | 349 | * @sup: superblock node |
350 | * | 350 | * |
351 | * This function validates superblock node @sup. Since most of data was read | 351 | * This function validates superblock node @sup. Since most of data was read |
352 | * from the superblock and stored in @c, the function validates fields in @c | 352 | * from the superblock and stored in @c, the function validates fields in @c |
353 | * instead. Returns zero in case of success and %-EINVAL in case of validation | 353 | * instead. Returns zero in case of success and %-EINVAL in case of validation |
354 | * failure. | 354 | * failure. |
355 | */ | 355 | */ |
356 | static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup) | 356 | static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup) |
357 | { | 357 | { |
358 | long long max_bytes; | 358 | long long max_bytes; |
359 | int err = 1, min_leb_cnt; | 359 | int err = 1, min_leb_cnt; |
360 | 360 | ||
361 | if (!c->key_hash) { | 361 | if (!c->key_hash) { |
362 | err = 2; | 362 | err = 2; |
363 | goto failed; | 363 | goto failed; |
364 | } | 364 | } |
365 | 365 | ||
366 | if (sup->key_fmt != UBIFS_SIMPLE_KEY_FMT) { | 366 | if (sup->key_fmt != UBIFS_SIMPLE_KEY_FMT) { |
367 | err = 3; | 367 | err = 3; |
368 | goto failed; | 368 | goto failed; |
369 | } | 369 | } |
370 | 370 | ||
371 | if (le32_to_cpu(sup->min_io_size) != c->min_io_size) { | 371 | if (le32_to_cpu(sup->min_io_size) != c->min_io_size) { |
372 | ubifs_err("min. I/O unit mismatch: %d in superblock, %d real", | 372 | ubifs_err("min. I/O unit mismatch: %d in superblock, %d real", |
373 | le32_to_cpu(sup->min_io_size), c->min_io_size); | 373 | le32_to_cpu(sup->min_io_size), c->min_io_size); |
374 | goto failed; | 374 | goto failed; |
375 | } | 375 | } |
376 | 376 | ||
377 | if (le32_to_cpu(sup->leb_size) != c->leb_size) { | 377 | if (le32_to_cpu(sup->leb_size) != c->leb_size) { |
378 | ubifs_err("LEB size mismatch: %d in superblock, %d real", | 378 | ubifs_err("LEB size mismatch: %d in superblock, %d real", |
379 | le32_to_cpu(sup->leb_size), c->leb_size); | 379 | le32_to_cpu(sup->leb_size), c->leb_size); |
380 | goto failed; | 380 | goto failed; |
381 | } | 381 | } |
382 | 382 | ||
383 | if (c->log_lebs < UBIFS_MIN_LOG_LEBS || | 383 | if (c->log_lebs < UBIFS_MIN_LOG_LEBS || |
384 | c->lpt_lebs < UBIFS_MIN_LPT_LEBS || | 384 | c->lpt_lebs < UBIFS_MIN_LPT_LEBS || |
385 | c->orph_lebs < UBIFS_MIN_ORPH_LEBS || | 385 | c->orph_lebs < UBIFS_MIN_ORPH_LEBS || |
386 | c->main_lebs < UBIFS_MIN_MAIN_LEBS) { | 386 | c->main_lebs < UBIFS_MIN_MAIN_LEBS) { |
387 | err = 4; | 387 | err = 4; |
388 | goto failed; | 388 | goto failed; |
389 | } | 389 | } |
390 | 390 | ||
391 | /* | 391 | /* |
392 | * Calculate minimum allowed amount of main area LEBs. This is very | 392 | * Calculate minimum allowed amount of main area LEBs. This is very |
393 | * similar to %UBIFS_MIN_LEB_CNT, but we take into account real what we | 393 | * similar to %UBIFS_MIN_LEB_CNT, but we take into account real what we |
394 | * have just read from the superblock. | 394 | * have just read from the superblock. |
395 | */ | 395 | */ |
396 | min_leb_cnt = UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs; | 396 | min_leb_cnt = UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs; |
397 | min_leb_cnt += c->lpt_lebs + c->orph_lebs + c->jhead_cnt + 6; | 397 | min_leb_cnt += c->lpt_lebs + c->orph_lebs + c->jhead_cnt + 6; |
398 | 398 | ||
399 | if (c->leb_cnt < min_leb_cnt || c->leb_cnt > c->vi.size) { | 399 | if (c->leb_cnt < min_leb_cnt || c->leb_cnt > c->vi.size) { |
400 | ubifs_err("bad LEB count: %d in superblock, %d on UBI volume, " | 400 | ubifs_err("bad LEB count: %d in superblock, %d on UBI volume, " |
401 | "%d minimum required", c->leb_cnt, c->vi.size, | 401 | "%d minimum required", c->leb_cnt, c->vi.size, |
402 | min_leb_cnt); | 402 | min_leb_cnt); |
403 | goto failed; | 403 | goto failed; |
404 | } | 404 | } |
405 | 405 | ||
406 | if (c->max_leb_cnt < c->leb_cnt) { | 406 | if (c->max_leb_cnt < c->leb_cnt) { |
407 | ubifs_err("max. LEB count %d less than LEB count %d", | 407 | ubifs_err("max. LEB count %d less than LEB count %d", |
408 | c->max_leb_cnt, c->leb_cnt); | 408 | c->max_leb_cnt, c->leb_cnt); |
409 | goto failed; | 409 | goto failed; |
410 | } | 410 | } |
411 | 411 | ||
412 | if (c->main_lebs < UBIFS_MIN_MAIN_LEBS) { | 412 | if (c->main_lebs < UBIFS_MIN_MAIN_LEBS) { |
413 | err = 7; | 413 | err = 7; |
414 | goto failed; | 414 | goto failed; |
415 | } | 415 | } |
416 | 416 | ||
417 | if (c->max_bud_bytes < (long long)c->leb_size * UBIFS_MIN_BUD_LEBS || | 417 | if (c->max_bud_bytes < (long long)c->leb_size * UBIFS_MIN_BUD_LEBS || |
418 | c->max_bud_bytes > (long long)c->leb_size * c->main_lebs) { | 418 | c->max_bud_bytes > (long long)c->leb_size * c->main_lebs) { |
419 | err = 8; | 419 | err = 8; |
420 | goto failed; | 420 | goto failed; |
421 | } | 421 | } |
422 | 422 | ||
423 | if (c->jhead_cnt < NONDATA_JHEADS_CNT + 1 || | 423 | if (c->jhead_cnt < NONDATA_JHEADS_CNT + 1 || |
424 | c->jhead_cnt > NONDATA_JHEADS_CNT + UBIFS_MAX_JHEADS) { | 424 | c->jhead_cnt > NONDATA_JHEADS_CNT + UBIFS_MAX_JHEADS) { |
425 | err = 9; | 425 | err = 9; |
426 | goto failed; | 426 | goto failed; |
427 | } | 427 | } |
428 | 428 | ||
429 | if (c->fanout < UBIFS_MIN_FANOUT || | 429 | if (c->fanout < UBIFS_MIN_FANOUT || |
430 | ubifs_idx_node_sz(c, c->fanout) > c->leb_size) { | 430 | ubifs_idx_node_sz(c, c->fanout) > c->leb_size) { |
431 | err = 10; | 431 | err = 10; |
432 | goto failed; | 432 | goto failed; |
433 | } | 433 | } |
434 | 434 | ||
435 | if (c->lsave_cnt < 0 || (c->lsave_cnt > DEFAULT_LSAVE_CNT && | 435 | if (c->lsave_cnt < 0 || (c->lsave_cnt > DEFAULT_LSAVE_CNT && |
436 | c->lsave_cnt > c->max_leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - | 436 | c->lsave_cnt > c->max_leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - |
437 | c->log_lebs - c->lpt_lebs - c->orph_lebs)) { | 437 | c->log_lebs - c->lpt_lebs - c->orph_lebs)) { |
438 | err = 11; | 438 | err = 11; |
439 | goto failed; | 439 | goto failed; |
440 | } | 440 | } |
441 | 441 | ||
442 | if (UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs + c->lpt_lebs + | 442 | if (UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs + c->lpt_lebs + |
443 | c->orph_lebs + c->main_lebs != c->leb_cnt) { | 443 | c->orph_lebs + c->main_lebs != c->leb_cnt) { |
444 | err = 12; | 444 | err = 12; |
445 | goto failed; | 445 | goto failed; |
446 | } | 446 | } |
447 | 447 | ||
448 | if (c->default_compr < 0 || c->default_compr >= UBIFS_COMPR_TYPES_CNT) { | 448 | if (c->default_compr < 0 || c->default_compr >= UBIFS_COMPR_TYPES_CNT) { |
449 | err = 13; | 449 | err = 13; |
450 | goto failed; | 450 | goto failed; |
451 | } | 451 | } |
452 | 452 | ||
453 | max_bytes = c->main_lebs * (long long)c->leb_size; | 453 | max_bytes = c->main_lebs * (long long)c->leb_size; |
454 | if (c->rp_size < 0 || max_bytes < c->rp_size) { | 454 | if (c->rp_size < 0 || max_bytes < c->rp_size) { |
455 | err = 14; | 455 | err = 14; |
456 | goto failed; | 456 | goto failed; |
457 | } | 457 | } |
458 | 458 | ||
459 | if (le32_to_cpu(sup->time_gran) > 1000000000 || | 459 | if (le32_to_cpu(sup->time_gran) > 1000000000 || |
460 | le32_to_cpu(sup->time_gran) < 1) { | 460 | le32_to_cpu(sup->time_gran) < 1) { |
461 | err = 15; | 461 | err = 15; |
462 | goto failed; | 462 | goto failed; |
463 | } | 463 | } |
464 | 464 | ||
465 | return 0; | 465 | return 0; |
466 | 466 | ||
467 | failed: | 467 | failed: |
468 | ubifs_err("bad superblock, error %d", err); | 468 | ubifs_err("bad superblock, error %d", err); |
469 | dbg_dump_node(c, sup); | 469 | dbg_dump_node(c, sup); |
470 | return -EINVAL; | 470 | return -EINVAL; |
471 | } | 471 | } |
472 | 472 | ||
473 | /** | 473 | /** |
474 | * ubifs_read_sb_node - read superblock node. | 474 | * ubifs_read_sb_node - read superblock node. |
475 | * @c: UBIFS file-system description object | 475 | * @c: UBIFS file-system description object |
476 | * | 476 | * |
477 | * This function returns a pointer to the superblock node or a negative error | 477 | * This function returns a pointer to the superblock node or a negative error |
478 | * code. Note, the user of this function is responsible of kfree()'ing the | 478 | * code. Note, the user of this function is responsible of kfree()'ing the |
479 | * returned superblock buffer. | 479 | * returned superblock buffer. |
480 | */ | 480 | */ |
481 | struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c) | 481 | struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c) |
482 | { | 482 | { |
483 | struct ubifs_sb_node *sup; | 483 | struct ubifs_sb_node *sup; |
484 | int err; | 484 | int err; |
485 | 485 | ||
486 | sup = kmalloc(ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size), GFP_NOFS); | 486 | sup = kmalloc(ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size), GFP_NOFS); |
487 | if (!sup) | 487 | if (!sup) |
488 | return ERR_PTR(-ENOMEM); | 488 | return ERR_PTR(-ENOMEM); |
489 | 489 | ||
490 | err = ubifs_read_node(c, sup, UBIFS_SB_NODE, UBIFS_SB_NODE_SZ, | 490 | err = ubifs_read_node(c, sup, UBIFS_SB_NODE, UBIFS_SB_NODE_SZ, |
491 | UBIFS_SB_LNUM, 0); | 491 | UBIFS_SB_LNUM, 0); |
492 | if (err) { | 492 | if (err) { |
493 | kfree(sup); | 493 | kfree(sup); |
494 | return ERR_PTR(err); | 494 | return ERR_PTR(err); |
495 | } | 495 | } |
496 | 496 | ||
497 | return sup; | 497 | return sup; |
498 | } | 498 | } |
499 | 499 | ||
500 | /** | 500 | /** |
501 | * ubifs_write_sb_node - write superblock node. | 501 | * ubifs_write_sb_node - write superblock node. |
502 | * @c: UBIFS file-system description object | 502 | * @c: UBIFS file-system description object |
503 | * @sup: superblock node read with 'ubifs_read_sb_node()' | 503 | * @sup: superblock node read with 'ubifs_read_sb_node()' |
504 | * | 504 | * |
505 | * This function returns %0 on success and a negative error code on failure. | 505 | * This function returns %0 on success and a negative error code on failure. |
506 | */ | 506 | */ |
507 | int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup) | 507 | int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup) |
508 | { | 508 | { |
509 | int len = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size); | 509 | int len = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size); |
510 | 510 | ||
511 | ubifs_prepare_node(c, sup, UBIFS_SB_NODE_SZ, 1); | 511 | ubifs_prepare_node(c, sup, UBIFS_SB_NODE_SZ, 1); |
512 | return ubifs_leb_change(c, UBIFS_SB_LNUM, sup, len, UBI_LONGTERM); | 512 | return ubifs_leb_change(c, UBIFS_SB_LNUM, sup, len, UBI_LONGTERM); |
513 | } | 513 | } |
514 | 514 | ||
515 | /** | 515 | /** |
516 | * ubifs_read_superblock - read superblock. | 516 | * ubifs_read_superblock - read superblock. |
517 | * @c: UBIFS file-system description object | 517 | * @c: UBIFS file-system description object |
518 | * | 518 | * |
519 | * This function finds, reads and checks the superblock. If an empty UBI volume | 519 | * This function finds, reads and checks the superblock. If an empty UBI volume |
520 | * is being mounted, this function creates default superblock. Returns zero in | 520 | * is being mounted, this function creates default superblock. Returns zero in |
521 | * case of success, and a negative error code in case of failure. | 521 | * case of success, and a negative error code in case of failure. |
522 | */ | 522 | */ |
523 | int ubifs_read_superblock(struct ubifs_info *c) | 523 | int ubifs_read_superblock(struct ubifs_info *c) |
524 | { | 524 | { |
525 | int err, sup_flags; | 525 | int err, sup_flags; |
526 | struct ubifs_sb_node *sup; | 526 | struct ubifs_sb_node *sup; |
527 | 527 | ||
528 | if (c->empty) { | 528 | if (c->empty) { |
529 | err = create_default_filesystem(c); | 529 | err = create_default_filesystem(c); |
530 | if (err) | 530 | if (err) |
531 | return err; | 531 | return err; |
532 | } | 532 | } |
533 | 533 | ||
534 | sup = ubifs_read_sb_node(c); | 534 | sup = ubifs_read_sb_node(c); |
535 | if (IS_ERR(sup)) | 535 | if (IS_ERR(sup)) |
536 | return PTR_ERR(sup); | 536 | return PTR_ERR(sup); |
537 | 537 | ||
538 | c->fmt_version = le32_to_cpu(sup->fmt_version); | 538 | c->fmt_version = le32_to_cpu(sup->fmt_version); |
539 | c->ro_compat_version = le32_to_cpu(sup->ro_compat_version); | 539 | c->ro_compat_version = le32_to_cpu(sup->ro_compat_version); |
540 | 540 | ||
541 | /* | 541 | /* |
542 | * The software supports all previous versions but not future versions, | 542 | * The software supports all previous versions but not future versions, |
543 | * due to the unavailability of time-travelling equipment. | 543 | * due to the unavailability of time-travelling equipment. |
544 | */ | 544 | */ |
545 | if (c->fmt_version > UBIFS_FORMAT_VERSION) { | 545 | if (c->fmt_version > UBIFS_FORMAT_VERSION) { |
546 | ubifs_assert(!c->ro_media || c->ro_mount); | 546 | ubifs_assert(!c->ro_media || c->ro_mount); |
547 | if (!c->ro_mount || | 547 | if (!c->ro_mount || |
548 | c->ro_compat_version > UBIFS_RO_COMPAT_VERSION) { | 548 | c->ro_compat_version > UBIFS_RO_COMPAT_VERSION) { |
549 | ubifs_err("on-flash format version is w%d/r%d, but " | 549 | ubifs_err("on-flash format version is w%d/r%d, but " |
550 | "software only supports up to version " | 550 | "software only supports up to version " |
551 | "w%d/r%d", c->fmt_version, | 551 | "w%d/r%d", c->fmt_version, |
552 | c->ro_compat_version, UBIFS_FORMAT_VERSION, | 552 | c->ro_compat_version, UBIFS_FORMAT_VERSION, |
553 | UBIFS_RO_COMPAT_VERSION); | 553 | UBIFS_RO_COMPAT_VERSION); |
554 | if (c->ro_compat_version <= UBIFS_RO_COMPAT_VERSION) { | 554 | if (c->ro_compat_version <= UBIFS_RO_COMPAT_VERSION) { |
555 | ubifs_msg("only R/O mounting is possible"); | 555 | ubifs_msg("only R/O mounting is possible"); |
556 | err = -EROFS; | 556 | err = -EROFS; |
557 | } else | 557 | } else |
558 | err = -EINVAL; | 558 | err = -EINVAL; |
559 | goto out; | 559 | goto out; |
560 | } | 560 | } |
561 | 561 | ||
562 | /* | 562 | /* |
563 | * The FS is mounted R/O, and the media format is | 563 | * The FS is mounted R/O, and the media format is |
564 | * R/O-compatible with the UBIFS implementation, so we can | 564 | * R/O-compatible with the UBIFS implementation, so we can |
565 | * mount. | 565 | * mount. |
566 | */ | 566 | */ |
567 | c->rw_incompat = 1; | 567 | c->rw_incompat = 1; |
568 | } | 568 | } |
569 | 569 | ||
570 | if (c->fmt_version < 3) { | 570 | if (c->fmt_version < 3) { |
571 | ubifs_err("on-flash format version %d is not supported", | 571 | ubifs_err("on-flash format version %d is not supported", |
572 | c->fmt_version); | 572 | c->fmt_version); |
573 | err = -EINVAL; | 573 | err = -EINVAL; |
574 | goto out; | 574 | goto out; |
575 | } | 575 | } |
576 | 576 | ||
577 | switch (sup->key_hash) { | 577 | switch (sup->key_hash) { |
578 | case UBIFS_KEY_HASH_R5: | 578 | case UBIFS_KEY_HASH_R5: |
579 | c->key_hash = key_r5_hash; | 579 | c->key_hash = key_r5_hash; |
580 | c->key_hash_type = UBIFS_KEY_HASH_R5; | 580 | c->key_hash_type = UBIFS_KEY_HASH_R5; |
581 | break; | 581 | break; |
582 | 582 | ||
583 | case UBIFS_KEY_HASH_TEST: | 583 | case UBIFS_KEY_HASH_TEST: |
584 | c->key_hash = key_test_hash; | 584 | c->key_hash = key_test_hash; |
585 | c->key_hash_type = UBIFS_KEY_HASH_TEST; | 585 | c->key_hash_type = UBIFS_KEY_HASH_TEST; |
586 | break; | 586 | break; |
587 | }; | 587 | }; |
588 | 588 | ||
589 | c->key_fmt = sup->key_fmt; | 589 | c->key_fmt = sup->key_fmt; |
590 | 590 | ||
591 | switch (c->key_fmt) { | 591 | switch (c->key_fmt) { |
592 | case UBIFS_SIMPLE_KEY_FMT: | 592 | case UBIFS_SIMPLE_KEY_FMT: |
593 | c->key_len = UBIFS_SK_LEN; | 593 | c->key_len = UBIFS_SK_LEN; |
594 | break; | 594 | break; |
595 | default: | 595 | default: |
596 | ubifs_err("unsupported key format"); | 596 | ubifs_err("unsupported key format"); |
597 | err = -EINVAL; | 597 | err = -EINVAL; |
598 | goto out; | 598 | goto out; |
599 | } | 599 | } |
600 | 600 | ||
601 | c->leb_cnt = le32_to_cpu(sup->leb_cnt); | 601 | c->leb_cnt = le32_to_cpu(sup->leb_cnt); |
602 | c->max_leb_cnt = le32_to_cpu(sup->max_leb_cnt); | 602 | c->max_leb_cnt = le32_to_cpu(sup->max_leb_cnt); |
603 | c->max_bud_bytes = le64_to_cpu(sup->max_bud_bytes); | 603 | c->max_bud_bytes = le64_to_cpu(sup->max_bud_bytes); |
604 | c->log_lebs = le32_to_cpu(sup->log_lebs); | 604 | c->log_lebs = le32_to_cpu(sup->log_lebs); |
605 | c->lpt_lebs = le32_to_cpu(sup->lpt_lebs); | 605 | c->lpt_lebs = le32_to_cpu(sup->lpt_lebs); |
606 | c->orph_lebs = le32_to_cpu(sup->orph_lebs); | 606 | c->orph_lebs = le32_to_cpu(sup->orph_lebs); |
607 | c->jhead_cnt = le32_to_cpu(sup->jhead_cnt) + NONDATA_JHEADS_CNT; | 607 | c->jhead_cnt = le32_to_cpu(sup->jhead_cnt) + NONDATA_JHEADS_CNT; |
608 | c->fanout = le32_to_cpu(sup->fanout); | 608 | c->fanout = le32_to_cpu(sup->fanout); |
609 | c->lsave_cnt = le32_to_cpu(sup->lsave_cnt); | 609 | c->lsave_cnt = le32_to_cpu(sup->lsave_cnt); |
610 | c->rp_size = le64_to_cpu(sup->rp_size); | 610 | c->rp_size = le64_to_cpu(sup->rp_size); |
611 | c->rp_uid = le32_to_cpu(sup->rp_uid); | 611 | c->rp_uid = le32_to_cpu(sup->rp_uid); |
612 | c->rp_gid = le32_to_cpu(sup->rp_gid); | 612 | c->rp_gid = le32_to_cpu(sup->rp_gid); |
613 | sup_flags = le32_to_cpu(sup->flags); | 613 | sup_flags = le32_to_cpu(sup->flags); |
614 | if (!c->mount_opts.override_compr) | 614 | if (!c->mount_opts.override_compr) |
615 | c->default_compr = le16_to_cpu(sup->default_compr); | 615 | c->default_compr = le16_to_cpu(sup->default_compr); |
616 | 616 | ||
617 | c->vfs_sb->s_time_gran = le32_to_cpu(sup->time_gran); | 617 | c->vfs_sb->s_time_gran = le32_to_cpu(sup->time_gran); |
618 | memcpy(&c->uuid, &sup->uuid, 16); | 618 | memcpy(&c->uuid, &sup->uuid, 16); |
619 | c->big_lpt = !!(sup_flags & UBIFS_FLG_BIGLPT); | 619 | c->big_lpt = !!(sup_flags & UBIFS_FLG_BIGLPT); |
620 | c->space_fixup = !!(sup_flags & UBIFS_FLG_SPACE_FIXUP); | ||
620 | 621 | ||
621 | /* Automatically increase file system size to the maximum size */ | 622 | /* Automatically increase file system size to the maximum size */ |
622 | c->old_leb_cnt = c->leb_cnt; | 623 | c->old_leb_cnt = c->leb_cnt; |
623 | if (c->leb_cnt < c->vi.size && c->leb_cnt < c->max_leb_cnt) { | 624 | if (c->leb_cnt < c->vi.size && c->leb_cnt < c->max_leb_cnt) { |
624 | c->leb_cnt = min_t(int, c->max_leb_cnt, c->vi.size); | 625 | c->leb_cnt = min_t(int, c->max_leb_cnt, c->vi.size); |
625 | if (c->ro_mount) | 626 | if (c->ro_mount) |
626 | dbg_mnt("Auto resizing (ro) from %d LEBs to %d LEBs", | 627 | dbg_mnt("Auto resizing (ro) from %d LEBs to %d LEBs", |
627 | c->old_leb_cnt, c->leb_cnt); | 628 | c->old_leb_cnt, c->leb_cnt); |
628 | else { | 629 | else { |
629 | dbg_mnt("Auto resizing (sb) from %d LEBs to %d LEBs", | 630 | dbg_mnt("Auto resizing (sb) from %d LEBs to %d LEBs", |
630 | c->old_leb_cnt, c->leb_cnt); | 631 | c->old_leb_cnt, c->leb_cnt); |
631 | sup->leb_cnt = cpu_to_le32(c->leb_cnt); | 632 | sup->leb_cnt = cpu_to_le32(c->leb_cnt); |
632 | err = ubifs_write_sb_node(c, sup); | 633 | err = ubifs_write_sb_node(c, sup); |
633 | if (err) | 634 | if (err) |
634 | goto out; | 635 | goto out; |
635 | c->old_leb_cnt = c->leb_cnt; | 636 | c->old_leb_cnt = c->leb_cnt; |
636 | } | 637 | } |
637 | } | 638 | } |
638 | 639 | ||
639 | c->log_bytes = (long long)c->log_lebs * c->leb_size; | 640 | c->log_bytes = (long long)c->log_lebs * c->leb_size; |
640 | c->log_last = UBIFS_LOG_LNUM + c->log_lebs - 1; | 641 | c->log_last = UBIFS_LOG_LNUM + c->log_lebs - 1; |
641 | c->lpt_first = UBIFS_LOG_LNUM + c->log_lebs; | 642 | c->lpt_first = UBIFS_LOG_LNUM + c->log_lebs; |
642 | c->lpt_last = c->lpt_first + c->lpt_lebs - 1; | 643 | c->lpt_last = c->lpt_first + c->lpt_lebs - 1; |
643 | c->orph_first = c->lpt_last + 1; | 644 | c->orph_first = c->lpt_last + 1; |
644 | c->orph_last = c->orph_first + c->orph_lebs - 1; | 645 | c->orph_last = c->orph_first + c->orph_lebs - 1; |
645 | c->main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS; | 646 | c->main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS; |
646 | c->main_lebs -= c->log_lebs + c->lpt_lebs + c->orph_lebs; | 647 | c->main_lebs -= c->log_lebs + c->lpt_lebs + c->orph_lebs; |
647 | c->main_first = c->leb_cnt - c->main_lebs; | 648 | c->main_first = c->leb_cnt - c->main_lebs; |
648 | 649 | ||
649 | err = validate_sb(c, sup); | 650 | err = validate_sb(c, sup); |
650 | out: | 651 | out: |
651 | kfree(sup); | 652 | kfree(sup); |
652 | return err; | 653 | return err; |
653 | } | 654 | } |
654 | 655 |
fs/ubifs/ubifs-media.h
1 | /* | 1 | /* |
2 | * This file is part of UBIFS. | 2 | * This file is part of UBIFS. |
3 | * | 3 | * |
4 | * Copyright (C) 2006-2008 Nokia Corporation. | 4 | * Copyright (C) 2006-2008 Nokia Corporation. |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 6 | * This program is free software; you can redistribute it and/or modify it |
7 | * under the terms of the GNU General Public License version 2 as published by | 7 | * under the terms of the GNU General Public License version 2 as published by |
8 | * the Free Software Foundation. | 8 | * the Free Software Foundation. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
13 | * more details. | 13 | * more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License along with | 15 | * You should have received a copy of the GNU General Public License along with |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | 16 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | * | 18 | * |
19 | * Authors: Artem Bityutskiy (Битюцкий Артём) | 19 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
20 | * Adrian Hunter | 20 | * Adrian Hunter |
21 | */ | 21 | */ |
22 | 22 | ||
23 | /* | 23 | /* |
24 | * This file describes UBIFS on-flash format and contains definitions of all the | 24 | * This file describes UBIFS on-flash format and contains definitions of all the |
25 | * relevant data structures and constants. | 25 | * relevant data structures and constants. |
26 | * | 26 | * |
27 | * All UBIFS on-flash objects are stored in the form of nodes. All nodes start | 27 | * All UBIFS on-flash objects are stored in the form of nodes. All nodes start |
28 | * with the UBIFS node magic number and have the same common header. Nodes | 28 | * with the UBIFS node magic number and have the same common header. Nodes |
29 | * always sit at 8-byte aligned positions on the media and node header sizes are | 29 | * always sit at 8-byte aligned positions on the media and node header sizes are |
30 | * also 8-byte aligned (except for the indexing node and the padding node). | 30 | * also 8-byte aligned (except for the indexing node and the padding node). |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #ifndef __UBIFS_MEDIA_H__ | 33 | #ifndef __UBIFS_MEDIA_H__ |
34 | #define __UBIFS_MEDIA_H__ | 34 | #define __UBIFS_MEDIA_H__ |
35 | 35 | ||
36 | /* UBIFS node magic number (must not have the padding byte first or last) */ | 36 | /* UBIFS node magic number (must not have the padding byte first or last) */ |
37 | #define UBIFS_NODE_MAGIC 0x06101831 | 37 | #define UBIFS_NODE_MAGIC 0x06101831 |
38 | 38 | ||
39 | /* | 39 | /* |
40 | * UBIFS on-flash format version. This version is increased when the on-flash | 40 | * UBIFS on-flash format version. This version is increased when the on-flash |
41 | * format is changing. If this happens, UBIFS is will support older versions as | 41 | * format is changing. If this happens, UBIFS is will support older versions as |
42 | * well. But older UBIFS code will not support newer formats. Format changes | 42 | * well. But older UBIFS code will not support newer formats. Format changes |
43 | * will be rare and only when absolutely necessary, e.g. to fix a bug or to add | 43 | * will be rare and only when absolutely necessary, e.g. to fix a bug or to add |
44 | * a new feature. | 44 | * a new feature. |
45 | * | 45 | * |
46 | * UBIFS went into mainline kernel with format version 4. The older formats | 46 | * UBIFS went into mainline kernel with format version 4. The older formats |
47 | * were development formats. | 47 | * were development formats. |
48 | */ | 48 | */ |
49 | #define UBIFS_FORMAT_VERSION 4 | 49 | #define UBIFS_FORMAT_VERSION 4 |
50 | 50 | ||
51 | /* | 51 | /* |
52 | * Read-only compatibility version. If the UBIFS format is changed, older UBIFS | 52 | * Read-only compatibility version. If the UBIFS format is changed, older UBIFS |
53 | * implementations will not be able to mount newer formats in read-write mode. | 53 | * implementations will not be able to mount newer formats in read-write mode. |
54 | * However, depending on the change, it may be possible to mount newer formats | 54 | * However, depending on the change, it may be possible to mount newer formats |
55 | * in R/O mode. This is indicated by the R/O compatibility version which is | 55 | * in R/O mode. This is indicated by the R/O compatibility version which is |
56 | * stored in the super-block. | 56 | * stored in the super-block. |
57 | * | 57 | * |
58 | * This is needed to support boot-loaders which only need R/O mounting. With | 58 | * This is needed to support boot-loaders which only need R/O mounting. With |
59 | * this flag it is possible to do UBIFS format changes without a need to update | 59 | * this flag it is possible to do UBIFS format changes without a need to update |
60 | * boot-loaders. | 60 | * boot-loaders. |
61 | */ | 61 | */ |
62 | #define UBIFS_RO_COMPAT_VERSION 0 | 62 | #define UBIFS_RO_COMPAT_VERSION 0 |
63 | 63 | ||
64 | /* Minimum logical eraseblock size in bytes */ | 64 | /* Minimum logical eraseblock size in bytes */ |
65 | #define UBIFS_MIN_LEB_SZ (15*1024) | 65 | #define UBIFS_MIN_LEB_SZ (15*1024) |
66 | 66 | ||
67 | /* Initial CRC32 value used when calculating CRC checksums */ | 67 | /* Initial CRC32 value used when calculating CRC checksums */ |
68 | #define UBIFS_CRC32_INIT 0xFFFFFFFFU | 68 | #define UBIFS_CRC32_INIT 0xFFFFFFFFU |
69 | 69 | ||
70 | /* | 70 | /* |
71 | * UBIFS does not try to compress data if its length is less than the below | 71 | * UBIFS does not try to compress data if its length is less than the below |
72 | * constant. | 72 | * constant. |
73 | */ | 73 | */ |
74 | #define UBIFS_MIN_COMPR_LEN 128 | 74 | #define UBIFS_MIN_COMPR_LEN 128 |
75 | 75 | ||
76 | /* | 76 | /* |
77 | * If compressed data length is less than %UBIFS_MIN_COMPRESS_DIFF bytes | 77 | * If compressed data length is less than %UBIFS_MIN_COMPRESS_DIFF bytes |
78 | * shorter than uncompressed data length, UBIFS prefers to leave this data | 78 | * shorter than uncompressed data length, UBIFS prefers to leave this data |
79 | * node uncompress, because it'll be read faster. | 79 | * node uncompress, because it'll be read faster. |
80 | */ | 80 | */ |
81 | #define UBIFS_MIN_COMPRESS_DIFF 64 | 81 | #define UBIFS_MIN_COMPRESS_DIFF 64 |
82 | 82 | ||
83 | /* Root inode number */ | 83 | /* Root inode number */ |
84 | #define UBIFS_ROOT_INO 1 | 84 | #define UBIFS_ROOT_INO 1 |
85 | 85 | ||
86 | /* Lowest inode number used for regular inodes (not UBIFS-only internal ones) */ | 86 | /* Lowest inode number used for regular inodes (not UBIFS-only internal ones) */ |
87 | #define UBIFS_FIRST_INO 64 | 87 | #define UBIFS_FIRST_INO 64 |
88 | 88 | ||
89 | /* | 89 | /* |
90 | * Maximum file name and extended attribute length (must be a multiple of 8, | 90 | * Maximum file name and extended attribute length (must be a multiple of 8, |
91 | * minus 1). | 91 | * minus 1). |
92 | */ | 92 | */ |
93 | #define UBIFS_MAX_NLEN 255 | 93 | #define UBIFS_MAX_NLEN 255 |
94 | 94 | ||
95 | /* Maximum number of data journal heads */ | 95 | /* Maximum number of data journal heads */ |
96 | #define UBIFS_MAX_JHEADS 1 | 96 | #define UBIFS_MAX_JHEADS 1 |
97 | 97 | ||
98 | /* | 98 | /* |
99 | * Size of UBIFS data block. Note, UBIFS is not a block oriented file-system, | 99 | * Size of UBIFS data block. Note, UBIFS is not a block oriented file-system, |
100 | * which means that it does not treat the underlying media as consisting of | 100 | * which means that it does not treat the underlying media as consisting of |
101 | * blocks like in case of hard drives. Do not be confused. UBIFS block is just | 101 | * blocks like in case of hard drives. Do not be confused. UBIFS block is just |
102 | * the maximum amount of data which one data node can have or which can be | 102 | * the maximum amount of data which one data node can have or which can be |
103 | * attached to an inode node. | 103 | * attached to an inode node. |
104 | */ | 104 | */ |
105 | #define UBIFS_BLOCK_SIZE 4096 | 105 | #define UBIFS_BLOCK_SIZE 4096 |
106 | #define UBIFS_BLOCK_SHIFT 12 | 106 | #define UBIFS_BLOCK_SHIFT 12 |
107 | 107 | ||
108 | /* UBIFS padding byte pattern (must not be first or last byte of node magic) */ | 108 | /* UBIFS padding byte pattern (must not be first or last byte of node magic) */ |
109 | #define UBIFS_PADDING_BYTE 0xCE | 109 | #define UBIFS_PADDING_BYTE 0xCE |
110 | 110 | ||
111 | /* Maximum possible key length */ | 111 | /* Maximum possible key length */ |
112 | #define UBIFS_MAX_KEY_LEN 16 | 112 | #define UBIFS_MAX_KEY_LEN 16 |
113 | 113 | ||
114 | /* Key length ("simple" format) */ | 114 | /* Key length ("simple" format) */ |
115 | #define UBIFS_SK_LEN 8 | 115 | #define UBIFS_SK_LEN 8 |
116 | 116 | ||
117 | /* Minimum index tree fanout */ | 117 | /* Minimum index tree fanout */ |
118 | #define UBIFS_MIN_FANOUT 3 | 118 | #define UBIFS_MIN_FANOUT 3 |
119 | 119 | ||
120 | /* Maximum number of levels in UBIFS indexing B-tree */ | 120 | /* Maximum number of levels in UBIFS indexing B-tree */ |
121 | #define UBIFS_MAX_LEVELS 512 | 121 | #define UBIFS_MAX_LEVELS 512 |
122 | 122 | ||
123 | /* Maximum amount of data attached to an inode in bytes */ | 123 | /* Maximum amount of data attached to an inode in bytes */ |
124 | #define UBIFS_MAX_INO_DATA UBIFS_BLOCK_SIZE | 124 | #define UBIFS_MAX_INO_DATA UBIFS_BLOCK_SIZE |
125 | 125 | ||
126 | /* LEB Properties Tree fanout (must be power of 2) and fanout shift */ | 126 | /* LEB Properties Tree fanout (must be power of 2) and fanout shift */ |
127 | #define UBIFS_LPT_FANOUT 4 | 127 | #define UBIFS_LPT_FANOUT 4 |
128 | #define UBIFS_LPT_FANOUT_SHIFT 2 | 128 | #define UBIFS_LPT_FANOUT_SHIFT 2 |
129 | 129 | ||
130 | /* LEB Properties Tree bit field sizes */ | 130 | /* LEB Properties Tree bit field sizes */ |
131 | #define UBIFS_LPT_CRC_BITS 16 | 131 | #define UBIFS_LPT_CRC_BITS 16 |
132 | #define UBIFS_LPT_CRC_BYTES 2 | 132 | #define UBIFS_LPT_CRC_BYTES 2 |
133 | #define UBIFS_LPT_TYPE_BITS 4 | 133 | #define UBIFS_LPT_TYPE_BITS 4 |
134 | 134 | ||
135 | /* The key is always at the same position in all keyed nodes */ | 135 | /* The key is always at the same position in all keyed nodes */ |
136 | #define UBIFS_KEY_OFFSET offsetof(struct ubifs_ino_node, key) | 136 | #define UBIFS_KEY_OFFSET offsetof(struct ubifs_ino_node, key) |
137 | 137 | ||
138 | /* Garbage collector journal head number */ | 138 | /* Garbage collector journal head number */ |
139 | #define UBIFS_GC_HEAD 0 | 139 | #define UBIFS_GC_HEAD 0 |
140 | /* Base journal head number */ | 140 | /* Base journal head number */ |
141 | #define UBIFS_BASE_HEAD 1 | 141 | #define UBIFS_BASE_HEAD 1 |
142 | /* Data journal head number */ | 142 | /* Data journal head number */ |
143 | #define UBIFS_DATA_HEAD 2 | 143 | #define UBIFS_DATA_HEAD 2 |
144 | 144 | ||
145 | /* | 145 | /* |
146 | * LEB Properties Tree node types. | 146 | * LEB Properties Tree node types. |
147 | * | 147 | * |
148 | * UBIFS_LPT_PNODE: LPT leaf node (contains LEB properties) | 148 | * UBIFS_LPT_PNODE: LPT leaf node (contains LEB properties) |
149 | * UBIFS_LPT_NNODE: LPT internal node | 149 | * UBIFS_LPT_NNODE: LPT internal node |
150 | * UBIFS_LPT_LTAB: LPT's own lprops table | 150 | * UBIFS_LPT_LTAB: LPT's own lprops table |
151 | * UBIFS_LPT_LSAVE: LPT's save table (big model only) | 151 | * UBIFS_LPT_LSAVE: LPT's save table (big model only) |
152 | * UBIFS_LPT_NODE_CNT: count of LPT node types | 152 | * UBIFS_LPT_NODE_CNT: count of LPT node types |
153 | * UBIFS_LPT_NOT_A_NODE: all ones (15 for 4 bits) is never a valid node type | 153 | * UBIFS_LPT_NOT_A_NODE: all ones (15 for 4 bits) is never a valid node type |
154 | */ | 154 | */ |
155 | enum { | 155 | enum { |
156 | UBIFS_LPT_PNODE, | 156 | UBIFS_LPT_PNODE, |
157 | UBIFS_LPT_NNODE, | 157 | UBIFS_LPT_NNODE, |
158 | UBIFS_LPT_LTAB, | 158 | UBIFS_LPT_LTAB, |
159 | UBIFS_LPT_LSAVE, | 159 | UBIFS_LPT_LSAVE, |
160 | UBIFS_LPT_NODE_CNT, | 160 | UBIFS_LPT_NODE_CNT, |
161 | UBIFS_LPT_NOT_A_NODE = (1 << UBIFS_LPT_TYPE_BITS) - 1, | 161 | UBIFS_LPT_NOT_A_NODE = (1 << UBIFS_LPT_TYPE_BITS) - 1, |
162 | }; | 162 | }; |
163 | 163 | ||
164 | /* | 164 | /* |
165 | * UBIFS inode types. | 165 | * UBIFS inode types. |
166 | * | 166 | * |
167 | * UBIFS_ITYPE_REG: regular file | 167 | * UBIFS_ITYPE_REG: regular file |
168 | * UBIFS_ITYPE_DIR: directory | 168 | * UBIFS_ITYPE_DIR: directory |
169 | * UBIFS_ITYPE_LNK: soft link | 169 | * UBIFS_ITYPE_LNK: soft link |
170 | * UBIFS_ITYPE_BLK: block device node | 170 | * UBIFS_ITYPE_BLK: block device node |
171 | * UBIFS_ITYPE_CHR: character device node | 171 | * UBIFS_ITYPE_CHR: character device node |
172 | * UBIFS_ITYPE_FIFO: fifo | 172 | * UBIFS_ITYPE_FIFO: fifo |
173 | * UBIFS_ITYPE_SOCK: socket | 173 | * UBIFS_ITYPE_SOCK: socket |
174 | * UBIFS_ITYPES_CNT: count of supported file types | 174 | * UBIFS_ITYPES_CNT: count of supported file types |
175 | */ | 175 | */ |
176 | enum { | 176 | enum { |
177 | UBIFS_ITYPE_REG, | 177 | UBIFS_ITYPE_REG, |
178 | UBIFS_ITYPE_DIR, | 178 | UBIFS_ITYPE_DIR, |
179 | UBIFS_ITYPE_LNK, | 179 | UBIFS_ITYPE_LNK, |
180 | UBIFS_ITYPE_BLK, | 180 | UBIFS_ITYPE_BLK, |
181 | UBIFS_ITYPE_CHR, | 181 | UBIFS_ITYPE_CHR, |
182 | UBIFS_ITYPE_FIFO, | 182 | UBIFS_ITYPE_FIFO, |
183 | UBIFS_ITYPE_SOCK, | 183 | UBIFS_ITYPE_SOCK, |
184 | UBIFS_ITYPES_CNT, | 184 | UBIFS_ITYPES_CNT, |
185 | }; | 185 | }; |
186 | 186 | ||
187 | /* | 187 | /* |
188 | * Supported key hash functions. | 188 | * Supported key hash functions. |
189 | * | 189 | * |
190 | * UBIFS_KEY_HASH_R5: R5 hash | 190 | * UBIFS_KEY_HASH_R5: R5 hash |
191 | * UBIFS_KEY_HASH_TEST: test hash which just returns first 4 bytes of the name | 191 | * UBIFS_KEY_HASH_TEST: test hash which just returns first 4 bytes of the name |
192 | */ | 192 | */ |
193 | enum { | 193 | enum { |
194 | UBIFS_KEY_HASH_R5, | 194 | UBIFS_KEY_HASH_R5, |
195 | UBIFS_KEY_HASH_TEST, | 195 | UBIFS_KEY_HASH_TEST, |
196 | }; | 196 | }; |
197 | 197 | ||
198 | /* | 198 | /* |
199 | * Supported key formats. | 199 | * Supported key formats. |
200 | * | 200 | * |
201 | * UBIFS_SIMPLE_KEY_FMT: simple key format | 201 | * UBIFS_SIMPLE_KEY_FMT: simple key format |
202 | */ | 202 | */ |
203 | enum { | 203 | enum { |
204 | UBIFS_SIMPLE_KEY_FMT, | 204 | UBIFS_SIMPLE_KEY_FMT, |
205 | }; | 205 | }; |
206 | 206 | ||
207 | /* | 207 | /* |
208 | * The simple key format uses 29 bits for storing UBIFS block number and hash | 208 | * The simple key format uses 29 bits for storing UBIFS block number and hash |
209 | * value. | 209 | * value. |
210 | */ | 210 | */ |
211 | #define UBIFS_S_KEY_BLOCK_BITS 29 | 211 | #define UBIFS_S_KEY_BLOCK_BITS 29 |
212 | #define UBIFS_S_KEY_BLOCK_MASK 0x1FFFFFFF | 212 | #define UBIFS_S_KEY_BLOCK_MASK 0x1FFFFFFF |
213 | #define UBIFS_S_KEY_HASH_BITS UBIFS_S_KEY_BLOCK_BITS | 213 | #define UBIFS_S_KEY_HASH_BITS UBIFS_S_KEY_BLOCK_BITS |
214 | #define UBIFS_S_KEY_HASH_MASK UBIFS_S_KEY_BLOCK_MASK | 214 | #define UBIFS_S_KEY_HASH_MASK UBIFS_S_KEY_BLOCK_MASK |
215 | 215 | ||
216 | /* | 216 | /* |
217 | * Key types. | 217 | * Key types. |
218 | * | 218 | * |
219 | * UBIFS_INO_KEY: inode node key | 219 | * UBIFS_INO_KEY: inode node key |
220 | * UBIFS_DATA_KEY: data node key | 220 | * UBIFS_DATA_KEY: data node key |
221 | * UBIFS_DENT_KEY: directory entry node key | 221 | * UBIFS_DENT_KEY: directory entry node key |
222 | * UBIFS_XENT_KEY: extended attribute entry key | 222 | * UBIFS_XENT_KEY: extended attribute entry key |
223 | * UBIFS_KEY_TYPES_CNT: number of supported key types | 223 | * UBIFS_KEY_TYPES_CNT: number of supported key types |
224 | */ | 224 | */ |
225 | enum { | 225 | enum { |
226 | UBIFS_INO_KEY, | 226 | UBIFS_INO_KEY, |
227 | UBIFS_DATA_KEY, | 227 | UBIFS_DATA_KEY, |
228 | UBIFS_DENT_KEY, | 228 | UBIFS_DENT_KEY, |
229 | UBIFS_XENT_KEY, | 229 | UBIFS_XENT_KEY, |
230 | UBIFS_KEY_TYPES_CNT, | 230 | UBIFS_KEY_TYPES_CNT, |
231 | }; | 231 | }; |
232 | 232 | ||
233 | /* Count of LEBs reserved for the superblock area */ | 233 | /* Count of LEBs reserved for the superblock area */ |
234 | #define UBIFS_SB_LEBS 1 | 234 | #define UBIFS_SB_LEBS 1 |
235 | /* Count of LEBs reserved for the master area */ | 235 | /* Count of LEBs reserved for the master area */ |
236 | #define UBIFS_MST_LEBS 2 | 236 | #define UBIFS_MST_LEBS 2 |
237 | 237 | ||
238 | /* First LEB of the superblock area */ | 238 | /* First LEB of the superblock area */ |
239 | #define UBIFS_SB_LNUM 0 | 239 | #define UBIFS_SB_LNUM 0 |
240 | /* First LEB of the master area */ | 240 | /* First LEB of the master area */ |
241 | #define UBIFS_MST_LNUM (UBIFS_SB_LNUM + UBIFS_SB_LEBS) | 241 | #define UBIFS_MST_LNUM (UBIFS_SB_LNUM + UBIFS_SB_LEBS) |
242 | /* First LEB of the log area */ | 242 | /* First LEB of the log area */ |
243 | #define UBIFS_LOG_LNUM (UBIFS_MST_LNUM + UBIFS_MST_LEBS) | 243 | #define UBIFS_LOG_LNUM (UBIFS_MST_LNUM + UBIFS_MST_LEBS) |
244 | 244 | ||
245 | /* | 245 | /* |
246 | * The below constants define the absolute minimum values for various UBIFS | 246 | * The below constants define the absolute minimum values for various UBIFS |
247 | * media areas. Many of them actually depend of flash geometry and the FS | 247 | * media areas. Many of them actually depend of flash geometry and the FS |
248 | * configuration (number of journal heads, orphan LEBs, etc). This means that | 248 | * configuration (number of journal heads, orphan LEBs, etc). This means that |
249 | * the smallest volume size which can be used for UBIFS cannot be pre-defined | 249 | * the smallest volume size which can be used for UBIFS cannot be pre-defined |
250 | * by these constants. The file-system that meets the below limitation will not | 250 | * by these constants. The file-system that meets the below limitation will not |
251 | * necessarily mount. UBIFS does run-time calculations and validates the FS | 251 | * necessarily mount. UBIFS does run-time calculations and validates the FS |
252 | * size. | 252 | * size. |
253 | */ | 253 | */ |
254 | 254 | ||
255 | /* Minimum number of logical eraseblocks in the log */ | 255 | /* Minimum number of logical eraseblocks in the log */ |
256 | #define UBIFS_MIN_LOG_LEBS 2 | 256 | #define UBIFS_MIN_LOG_LEBS 2 |
257 | /* Minimum number of bud logical eraseblocks (one for each head) */ | 257 | /* Minimum number of bud logical eraseblocks (one for each head) */ |
258 | #define UBIFS_MIN_BUD_LEBS 3 | 258 | #define UBIFS_MIN_BUD_LEBS 3 |
259 | /* Minimum number of journal logical eraseblocks */ | 259 | /* Minimum number of journal logical eraseblocks */ |
260 | #define UBIFS_MIN_JNL_LEBS (UBIFS_MIN_LOG_LEBS + UBIFS_MIN_BUD_LEBS) | 260 | #define UBIFS_MIN_JNL_LEBS (UBIFS_MIN_LOG_LEBS + UBIFS_MIN_BUD_LEBS) |
261 | /* Minimum number of LPT area logical eraseblocks */ | 261 | /* Minimum number of LPT area logical eraseblocks */ |
262 | #define UBIFS_MIN_LPT_LEBS 2 | 262 | #define UBIFS_MIN_LPT_LEBS 2 |
263 | /* Minimum number of orphan area logical eraseblocks */ | 263 | /* Minimum number of orphan area logical eraseblocks */ |
264 | #define UBIFS_MIN_ORPH_LEBS 1 | 264 | #define UBIFS_MIN_ORPH_LEBS 1 |
265 | /* | 265 | /* |
266 | * Minimum number of main area logical eraseblocks (buds, 3 for the index, 1 | 266 | * Minimum number of main area logical eraseblocks (buds, 3 for the index, 1 |
267 | * for GC, 1 for deletions, and at least 1 for committed data). | 267 | * for GC, 1 for deletions, and at least 1 for committed data). |
268 | */ | 268 | */ |
269 | #define UBIFS_MIN_MAIN_LEBS (UBIFS_MIN_BUD_LEBS + 6) | 269 | #define UBIFS_MIN_MAIN_LEBS (UBIFS_MIN_BUD_LEBS + 6) |
270 | 270 | ||
271 | /* Minimum number of logical eraseblocks */ | 271 | /* Minimum number of logical eraseblocks */ |
272 | #define UBIFS_MIN_LEB_CNT (UBIFS_SB_LEBS + UBIFS_MST_LEBS + \ | 272 | #define UBIFS_MIN_LEB_CNT (UBIFS_SB_LEBS + UBIFS_MST_LEBS + \ |
273 | UBIFS_MIN_LOG_LEBS + UBIFS_MIN_LPT_LEBS + \ | 273 | UBIFS_MIN_LOG_LEBS + UBIFS_MIN_LPT_LEBS + \ |
274 | UBIFS_MIN_ORPH_LEBS + UBIFS_MIN_MAIN_LEBS) | 274 | UBIFS_MIN_ORPH_LEBS + UBIFS_MIN_MAIN_LEBS) |
275 | 275 | ||
276 | /* Node sizes (N.B. these are guaranteed to be multiples of 8) */ | 276 | /* Node sizes (N.B. these are guaranteed to be multiples of 8) */ |
277 | #define UBIFS_CH_SZ sizeof(struct ubifs_ch) | 277 | #define UBIFS_CH_SZ sizeof(struct ubifs_ch) |
278 | #define UBIFS_INO_NODE_SZ sizeof(struct ubifs_ino_node) | 278 | #define UBIFS_INO_NODE_SZ sizeof(struct ubifs_ino_node) |
279 | #define UBIFS_DATA_NODE_SZ sizeof(struct ubifs_data_node) | 279 | #define UBIFS_DATA_NODE_SZ sizeof(struct ubifs_data_node) |
280 | #define UBIFS_DENT_NODE_SZ sizeof(struct ubifs_dent_node) | 280 | #define UBIFS_DENT_NODE_SZ sizeof(struct ubifs_dent_node) |
281 | #define UBIFS_TRUN_NODE_SZ sizeof(struct ubifs_trun_node) | 281 | #define UBIFS_TRUN_NODE_SZ sizeof(struct ubifs_trun_node) |
282 | #define UBIFS_PAD_NODE_SZ sizeof(struct ubifs_pad_node) | 282 | #define UBIFS_PAD_NODE_SZ sizeof(struct ubifs_pad_node) |
283 | #define UBIFS_SB_NODE_SZ sizeof(struct ubifs_sb_node) | 283 | #define UBIFS_SB_NODE_SZ sizeof(struct ubifs_sb_node) |
284 | #define UBIFS_MST_NODE_SZ sizeof(struct ubifs_mst_node) | 284 | #define UBIFS_MST_NODE_SZ sizeof(struct ubifs_mst_node) |
285 | #define UBIFS_REF_NODE_SZ sizeof(struct ubifs_ref_node) | 285 | #define UBIFS_REF_NODE_SZ sizeof(struct ubifs_ref_node) |
286 | #define UBIFS_IDX_NODE_SZ sizeof(struct ubifs_idx_node) | 286 | #define UBIFS_IDX_NODE_SZ sizeof(struct ubifs_idx_node) |
287 | #define UBIFS_CS_NODE_SZ sizeof(struct ubifs_cs_node) | 287 | #define UBIFS_CS_NODE_SZ sizeof(struct ubifs_cs_node) |
288 | #define UBIFS_ORPH_NODE_SZ sizeof(struct ubifs_orph_node) | 288 | #define UBIFS_ORPH_NODE_SZ sizeof(struct ubifs_orph_node) |
289 | /* Extended attribute entry nodes are identical to directory entry nodes */ | 289 | /* Extended attribute entry nodes are identical to directory entry nodes */ |
290 | #define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ | 290 | #define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ |
291 | /* Only this does not have to be multiple of 8 bytes */ | 291 | /* Only this does not have to be multiple of 8 bytes */ |
292 | #define UBIFS_BRANCH_SZ sizeof(struct ubifs_branch) | 292 | #define UBIFS_BRANCH_SZ sizeof(struct ubifs_branch) |
293 | 293 | ||
294 | /* Maximum node sizes (N.B. these are guaranteed to be multiples of 8) */ | 294 | /* Maximum node sizes (N.B. these are guaranteed to be multiples of 8) */ |
295 | #define UBIFS_MAX_DATA_NODE_SZ (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE) | 295 | #define UBIFS_MAX_DATA_NODE_SZ (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE) |
296 | #define UBIFS_MAX_INO_NODE_SZ (UBIFS_INO_NODE_SZ + UBIFS_MAX_INO_DATA) | 296 | #define UBIFS_MAX_INO_NODE_SZ (UBIFS_INO_NODE_SZ + UBIFS_MAX_INO_DATA) |
297 | #define UBIFS_MAX_DENT_NODE_SZ (UBIFS_DENT_NODE_SZ + UBIFS_MAX_NLEN + 1) | 297 | #define UBIFS_MAX_DENT_NODE_SZ (UBIFS_DENT_NODE_SZ + UBIFS_MAX_NLEN + 1) |
298 | #define UBIFS_MAX_XENT_NODE_SZ UBIFS_MAX_DENT_NODE_SZ | 298 | #define UBIFS_MAX_XENT_NODE_SZ UBIFS_MAX_DENT_NODE_SZ |
299 | 299 | ||
300 | /* The largest UBIFS node */ | 300 | /* The largest UBIFS node */ |
301 | #define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ | 301 | #define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ |
302 | 302 | ||
303 | /* | 303 | /* |
304 | * On-flash inode flags. | 304 | * On-flash inode flags. |
305 | * | 305 | * |
306 | * UBIFS_COMPR_FL: use compression for this inode | 306 | * UBIFS_COMPR_FL: use compression for this inode |
307 | * UBIFS_SYNC_FL: I/O on this inode has to be synchronous | 307 | * UBIFS_SYNC_FL: I/O on this inode has to be synchronous |
308 | * UBIFS_IMMUTABLE_FL: inode is immutable | 308 | * UBIFS_IMMUTABLE_FL: inode is immutable |
309 | * UBIFS_APPEND_FL: writes to the inode may only append data | 309 | * UBIFS_APPEND_FL: writes to the inode may only append data |
310 | * UBIFS_DIRSYNC_FL: I/O on this directory inode has to be synchronous | 310 | * UBIFS_DIRSYNC_FL: I/O on this directory inode has to be synchronous |
311 | * UBIFS_XATTR_FL: this inode is the inode for an extended attribute value | 311 | * UBIFS_XATTR_FL: this inode is the inode for an extended attribute value |
312 | * | 312 | * |
313 | * Note, these are on-flash flags which correspond to ioctl flags | 313 | * Note, these are on-flash flags which correspond to ioctl flags |
314 | * (@FS_COMPR_FL, etc). They have the same values now, but generally, do not | 314 | * (@FS_COMPR_FL, etc). They have the same values now, but generally, do not |
315 | * have to be the same. | 315 | * have to be the same. |
316 | */ | 316 | */ |
317 | enum { | 317 | enum { |
318 | UBIFS_COMPR_FL = 0x01, | 318 | UBIFS_COMPR_FL = 0x01, |
319 | UBIFS_SYNC_FL = 0x02, | 319 | UBIFS_SYNC_FL = 0x02, |
320 | UBIFS_IMMUTABLE_FL = 0x04, | 320 | UBIFS_IMMUTABLE_FL = 0x04, |
321 | UBIFS_APPEND_FL = 0x08, | 321 | UBIFS_APPEND_FL = 0x08, |
322 | UBIFS_DIRSYNC_FL = 0x10, | 322 | UBIFS_DIRSYNC_FL = 0x10, |
323 | UBIFS_XATTR_FL = 0x20, | 323 | UBIFS_XATTR_FL = 0x20, |
324 | }; | 324 | }; |
325 | 325 | ||
326 | /* Inode flag bits used by UBIFS */ | 326 | /* Inode flag bits used by UBIFS */ |
327 | #define UBIFS_FL_MASK 0x0000001F | 327 | #define UBIFS_FL_MASK 0x0000001F |
328 | 328 | ||
329 | /* | 329 | /* |
330 | * UBIFS compression algorithms. | 330 | * UBIFS compression algorithms. |
331 | * | 331 | * |
332 | * UBIFS_COMPR_NONE: no compression | 332 | * UBIFS_COMPR_NONE: no compression |
333 | * UBIFS_COMPR_LZO: LZO compression | 333 | * UBIFS_COMPR_LZO: LZO compression |
334 | * UBIFS_COMPR_ZLIB: ZLIB compression | 334 | * UBIFS_COMPR_ZLIB: ZLIB compression |
335 | * UBIFS_COMPR_TYPES_CNT: count of supported compression types | 335 | * UBIFS_COMPR_TYPES_CNT: count of supported compression types |
336 | */ | 336 | */ |
337 | enum { | 337 | enum { |
338 | UBIFS_COMPR_NONE, | 338 | UBIFS_COMPR_NONE, |
339 | UBIFS_COMPR_LZO, | 339 | UBIFS_COMPR_LZO, |
340 | UBIFS_COMPR_ZLIB, | 340 | UBIFS_COMPR_ZLIB, |
341 | UBIFS_COMPR_TYPES_CNT, | 341 | UBIFS_COMPR_TYPES_CNT, |
342 | }; | 342 | }; |
343 | 343 | ||
344 | /* | 344 | /* |
345 | * UBIFS node types. | 345 | * UBIFS node types. |
346 | * | 346 | * |
347 | * UBIFS_INO_NODE: inode node | 347 | * UBIFS_INO_NODE: inode node |
348 | * UBIFS_DATA_NODE: data node | 348 | * UBIFS_DATA_NODE: data node |
349 | * UBIFS_DENT_NODE: directory entry node | 349 | * UBIFS_DENT_NODE: directory entry node |
350 | * UBIFS_XENT_NODE: extended attribute node | 350 | * UBIFS_XENT_NODE: extended attribute node |
351 | * UBIFS_TRUN_NODE: truncation node | 351 | * UBIFS_TRUN_NODE: truncation node |
352 | * UBIFS_PAD_NODE: padding node | 352 | * UBIFS_PAD_NODE: padding node |
353 | * UBIFS_SB_NODE: superblock node | 353 | * UBIFS_SB_NODE: superblock node |
354 | * UBIFS_MST_NODE: master node | 354 | * UBIFS_MST_NODE: master node |
355 | * UBIFS_REF_NODE: LEB reference node | 355 | * UBIFS_REF_NODE: LEB reference node |
356 | * UBIFS_IDX_NODE: index node | 356 | * UBIFS_IDX_NODE: index node |
357 | * UBIFS_CS_NODE: commit start node | 357 | * UBIFS_CS_NODE: commit start node |
358 | * UBIFS_ORPH_NODE: orphan node | 358 | * UBIFS_ORPH_NODE: orphan node |
359 | * UBIFS_NODE_TYPES_CNT: count of supported node types | 359 | * UBIFS_NODE_TYPES_CNT: count of supported node types |
360 | * | 360 | * |
361 | * Note, we index arrays by these numbers, so keep them low and contiguous. | 361 | * Note, we index arrays by these numbers, so keep them low and contiguous. |
362 | * Node type constants for inodes, direntries and so on have to be the same as | 362 | * Node type constants for inodes, direntries and so on have to be the same as |
363 | * corresponding key type constants. | 363 | * corresponding key type constants. |
364 | */ | 364 | */ |
365 | enum { | 365 | enum { |
366 | UBIFS_INO_NODE, | 366 | UBIFS_INO_NODE, |
367 | UBIFS_DATA_NODE, | 367 | UBIFS_DATA_NODE, |
368 | UBIFS_DENT_NODE, | 368 | UBIFS_DENT_NODE, |
369 | UBIFS_XENT_NODE, | 369 | UBIFS_XENT_NODE, |
370 | UBIFS_TRUN_NODE, | 370 | UBIFS_TRUN_NODE, |
371 | UBIFS_PAD_NODE, | 371 | UBIFS_PAD_NODE, |
372 | UBIFS_SB_NODE, | 372 | UBIFS_SB_NODE, |
373 | UBIFS_MST_NODE, | 373 | UBIFS_MST_NODE, |
374 | UBIFS_REF_NODE, | 374 | UBIFS_REF_NODE, |
375 | UBIFS_IDX_NODE, | 375 | UBIFS_IDX_NODE, |
376 | UBIFS_CS_NODE, | 376 | UBIFS_CS_NODE, |
377 | UBIFS_ORPH_NODE, | 377 | UBIFS_ORPH_NODE, |
378 | UBIFS_NODE_TYPES_CNT, | 378 | UBIFS_NODE_TYPES_CNT, |
379 | }; | 379 | }; |
380 | 380 | ||
381 | /* | 381 | /* |
382 | * Master node flags. | 382 | * Master node flags. |
383 | * | 383 | * |
384 | * UBIFS_MST_DIRTY: rebooted uncleanly - master node is dirty | 384 | * UBIFS_MST_DIRTY: rebooted uncleanly - master node is dirty |
385 | * UBIFS_MST_NO_ORPHS: no orphan inodes present | 385 | * UBIFS_MST_NO_ORPHS: no orphan inodes present |
386 | * UBIFS_MST_RCVRY: written by recovery | 386 | * UBIFS_MST_RCVRY: written by recovery |
387 | */ | 387 | */ |
388 | enum { | 388 | enum { |
389 | UBIFS_MST_DIRTY = 1, | 389 | UBIFS_MST_DIRTY = 1, |
390 | UBIFS_MST_NO_ORPHS = 2, | 390 | UBIFS_MST_NO_ORPHS = 2, |
391 | UBIFS_MST_RCVRY = 4, | 391 | UBIFS_MST_RCVRY = 4, |
392 | }; | 392 | }; |
393 | 393 | ||
394 | /* | 394 | /* |
395 | * Node group type (used by recovery to recover whole group or none). | 395 | * Node group type (used by recovery to recover whole group or none). |
396 | * | 396 | * |
397 | * UBIFS_NO_NODE_GROUP: this node is not part of a group | 397 | * UBIFS_NO_NODE_GROUP: this node is not part of a group |
398 | * UBIFS_IN_NODE_GROUP: this node is a part of a group | 398 | * UBIFS_IN_NODE_GROUP: this node is a part of a group |
399 | * UBIFS_LAST_OF_NODE_GROUP: this node is the last in a group | 399 | * UBIFS_LAST_OF_NODE_GROUP: this node is the last in a group |
400 | */ | 400 | */ |
401 | enum { | 401 | enum { |
402 | UBIFS_NO_NODE_GROUP = 0, | 402 | UBIFS_NO_NODE_GROUP = 0, |
403 | UBIFS_IN_NODE_GROUP, | 403 | UBIFS_IN_NODE_GROUP, |
404 | UBIFS_LAST_OF_NODE_GROUP, | 404 | UBIFS_LAST_OF_NODE_GROUP, |
405 | }; | 405 | }; |
406 | 406 | ||
407 | /* | 407 | /* |
408 | * Superblock flags. | 408 | * Superblock flags. |
409 | * | 409 | * |
410 | * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set | 410 | * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set |
411 | * UBIFS_FLG_SPACE_FIXUP: first-mount "fixup" of free space within LEBs needed | ||
411 | */ | 412 | */ |
412 | enum { | 413 | enum { |
413 | UBIFS_FLG_BIGLPT = 0x02, | 414 | UBIFS_FLG_BIGLPT = 0x02, |
415 | UBIFS_FLG_SPACE_FIXUP = 0x04, | ||
414 | }; | 416 | }; |
415 | 417 | ||
416 | /** | 418 | /** |
417 | * struct ubifs_ch - common header node. | 419 | * struct ubifs_ch - common header node. |
418 | * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC) | 420 | * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC) |
419 | * @crc: CRC-32 checksum of the node header | 421 | * @crc: CRC-32 checksum of the node header |
420 | * @sqnum: sequence number | 422 | * @sqnum: sequence number |
421 | * @len: full node length | 423 | * @len: full node length |
422 | * @node_type: node type | 424 | * @node_type: node type |
423 | * @group_type: node group type | 425 | * @group_type: node group type |
424 | * @padding: reserved for future, zeroes | 426 | * @padding: reserved for future, zeroes |
425 | * | 427 | * |
426 | * Every UBIFS node starts with this common part. If the node has a key, the | 428 | * Every UBIFS node starts with this common part. If the node has a key, the |
427 | * key always goes next. | 429 | * key always goes next. |
428 | */ | 430 | */ |
429 | struct ubifs_ch { | 431 | struct ubifs_ch { |
430 | __le32 magic; | 432 | __le32 magic; |
431 | __le32 crc; | 433 | __le32 crc; |
432 | __le64 sqnum; | 434 | __le64 sqnum; |
433 | __le32 len; | 435 | __le32 len; |
434 | __u8 node_type; | 436 | __u8 node_type; |
435 | __u8 group_type; | 437 | __u8 group_type; |
436 | __u8 padding[2]; | 438 | __u8 padding[2]; |
437 | } __packed; | 439 | } __packed; |
438 | 440 | ||
439 | /** | 441 | /** |
440 | * union ubifs_dev_desc - device node descriptor. | 442 | * union ubifs_dev_desc - device node descriptor. |
441 | * @new: new type device descriptor | 443 | * @new: new type device descriptor |
442 | * @huge: huge type device descriptor | 444 | * @huge: huge type device descriptor |
443 | * | 445 | * |
444 | * This data structure describes major/minor numbers of a device node. In an | 446 | * This data structure describes major/minor numbers of a device node. In an |
445 | * inode is a device node then its data contains an object of this type. UBIFS | 447 | * inode is a device node then its data contains an object of this type. UBIFS |
446 | * uses standard Linux "new" and "huge" device node encodings. | 448 | * uses standard Linux "new" and "huge" device node encodings. |
447 | */ | 449 | */ |
448 | union ubifs_dev_desc { | 450 | union ubifs_dev_desc { |
449 | __le32 new; | 451 | __le32 new; |
450 | __le64 huge; | 452 | __le64 huge; |
451 | } __packed; | 453 | } __packed; |
452 | 454 | ||
453 | /** | 455 | /** |
454 | * struct ubifs_ino_node - inode node. | 456 | * struct ubifs_ino_node - inode node. |
455 | * @ch: common header | 457 | * @ch: common header |
456 | * @key: node key | 458 | * @key: node key |
457 | * @creat_sqnum: sequence number at time of creation | 459 | * @creat_sqnum: sequence number at time of creation |
458 | * @size: inode size in bytes (amount of uncompressed data) | 460 | * @size: inode size in bytes (amount of uncompressed data) |
459 | * @atime_sec: access time seconds | 461 | * @atime_sec: access time seconds |
460 | * @ctime_sec: creation time seconds | 462 | * @ctime_sec: creation time seconds |
461 | * @mtime_sec: modification time seconds | 463 | * @mtime_sec: modification time seconds |
462 | * @atime_nsec: access time nanoseconds | 464 | * @atime_nsec: access time nanoseconds |
463 | * @ctime_nsec: creation time nanoseconds | 465 | * @ctime_nsec: creation time nanoseconds |
464 | * @mtime_nsec: modification time nanoseconds | 466 | * @mtime_nsec: modification time nanoseconds |
465 | * @nlink: number of hard links | 467 | * @nlink: number of hard links |
466 | * @uid: owner ID | 468 | * @uid: owner ID |
467 | * @gid: group ID | 469 | * @gid: group ID |
468 | * @mode: access flags | 470 | * @mode: access flags |
469 | * @flags: per-inode flags (%UBIFS_COMPR_FL, %UBIFS_SYNC_FL, etc) | 471 | * @flags: per-inode flags (%UBIFS_COMPR_FL, %UBIFS_SYNC_FL, etc) |
470 | * @data_len: inode data length | 472 | * @data_len: inode data length |
471 | * @xattr_cnt: count of extended attributes this inode has | 473 | * @xattr_cnt: count of extended attributes this inode has |
472 | * @xattr_size: summarized size of all extended attributes in bytes | 474 | * @xattr_size: summarized size of all extended attributes in bytes |
473 | * @padding1: reserved for future, zeroes | 475 | * @padding1: reserved for future, zeroes |
474 | * @xattr_names: sum of lengths of all extended attribute names belonging to | 476 | * @xattr_names: sum of lengths of all extended attribute names belonging to |
475 | * this inode | 477 | * this inode |
476 | * @compr_type: compression type used for this inode | 478 | * @compr_type: compression type used for this inode |
477 | * @padding2: reserved for future, zeroes | 479 | * @padding2: reserved for future, zeroes |
478 | * @data: data attached to the inode | 480 | * @data: data attached to the inode |
479 | * | 481 | * |
480 | * Note, even though inode compression type is defined by @compr_type, some | 482 | * Note, even though inode compression type is defined by @compr_type, some |
481 | * nodes of this inode may be compressed with different compressor - this | 483 | * nodes of this inode may be compressed with different compressor - this |
482 | * happens if compression type is changed while the inode already has data | 484 | * happens if compression type is changed while the inode already has data |
483 | * nodes. But @compr_type will be use for further writes to the inode. | 485 | * nodes. But @compr_type will be use for further writes to the inode. |
484 | * | 486 | * |
485 | * Note, do not forget to amend 'zero_ino_node_unused()' function when changing | 487 | * Note, do not forget to amend 'zero_ino_node_unused()' function when changing |
486 | * the padding fields. | 488 | * the padding fields. |
487 | */ | 489 | */ |
488 | struct ubifs_ino_node { | 490 | struct ubifs_ino_node { |
489 | struct ubifs_ch ch; | 491 | struct ubifs_ch ch; |
490 | __u8 key[UBIFS_MAX_KEY_LEN]; | 492 | __u8 key[UBIFS_MAX_KEY_LEN]; |
491 | __le64 creat_sqnum; | 493 | __le64 creat_sqnum; |
492 | __le64 size; | 494 | __le64 size; |
493 | __le64 atime_sec; | 495 | __le64 atime_sec; |
494 | __le64 ctime_sec; | 496 | __le64 ctime_sec; |
495 | __le64 mtime_sec; | 497 | __le64 mtime_sec; |
496 | __le32 atime_nsec; | 498 | __le32 atime_nsec; |
497 | __le32 ctime_nsec; | 499 | __le32 ctime_nsec; |
498 | __le32 mtime_nsec; | 500 | __le32 mtime_nsec; |
499 | __le32 nlink; | 501 | __le32 nlink; |
500 | __le32 uid; | 502 | __le32 uid; |
501 | __le32 gid; | 503 | __le32 gid; |
502 | __le32 mode; | 504 | __le32 mode; |
503 | __le32 flags; | 505 | __le32 flags; |
504 | __le32 data_len; | 506 | __le32 data_len; |
505 | __le32 xattr_cnt; | 507 | __le32 xattr_cnt; |
506 | __le32 xattr_size; | 508 | __le32 xattr_size; |
507 | __u8 padding1[4]; /* Watch 'zero_ino_node_unused()' if changing! */ | 509 | __u8 padding1[4]; /* Watch 'zero_ino_node_unused()' if changing! */ |
508 | __le32 xattr_names; | 510 | __le32 xattr_names; |
509 | __le16 compr_type; | 511 | __le16 compr_type; |
510 | __u8 padding2[26]; /* Watch 'zero_ino_node_unused()' if changing! */ | 512 | __u8 padding2[26]; /* Watch 'zero_ino_node_unused()' if changing! */ |
511 | __u8 data[]; | 513 | __u8 data[]; |
512 | } __packed; | 514 | } __packed; |
513 | 515 | ||
514 | /** | 516 | /** |
515 | * struct ubifs_dent_node - directory entry node. | 517 | * struct ubifs_dent_node - directory entry node. |
516 | * @ch: common header | 518 | * @ch: common header |
517 | * @key: node key | 519 | * @key: node key |
518 | * @inum: target inode number | 520 | * @inum: target inode number |
519 | * @padding1: reserved for future, zeroes | 521 | * @padding1: reserved for future, zeroes |
520 | * @type: type of the target inode (%UBIFS_ITYPE_REG, %UBIFS_ITYPE_DIR, etc) | 522 | * @type: type of the target inode (%UBIFS_ITYPE_REG, %UBIFS_ITYPE_DIR, etc) |
521 | * @nlen: name length | 523 | * @nlen: name length |
522 | * @padding2: reserved for future, zeroes | 524 | * @padding2: reserved for future, zeroes |
523 | * @name: zero-terminated name | 525 | * @name: zero-terminated name |
524 | * | 526 | * |
525 | * Note, do not forget to amend 'zero_dent_node_unused()' function when | 527 | * Note, do not forget to amend 'zero_dent_node_unused()' function when |
526 | * changing the padding fields. | 528 | * changing the padding fields. |
527 | */ | 529 | */ |
528 | struct ubifs_dent_node { | 530 | struct ubifs_dent_node { |
529 | struct ubifs_ch ch; | 531 | struct ubifs_ch ch; |
530 | __u8 key[UBIFS_MAX_KEY_LEN]; | 532 | __u8 key[UBIFS_MAX_KEY_LEN]; |
531 | __le64 inum; | 533 | __le64 inum; |
532 | __u8 padding1; | 534 | __u8 padding1; |
533 | __u8 type; | 535 | __u8 type; |
534 | __le16 nlen; | 536 | __le16 nlen; |
535 | __u8 padding2[4]; /* Watch 'zero_dent_node_unused()' if changing! */ | 537 | __u8 padding2[4]; /* Watch 'zero_dent_node_unused()' if changing! */ |
536 | __u8 name[]; | 538 | __u8 name[]; |
537 | } __packed; | 539 | } __packed; |
538 | 540 | ||
539 | /** | 541 | /** |
540 | * struct ubifs_data_node - data node. | 542 | * struct ubifs_data_node - data node. |
541 | * @ch: common header | 543 | * @ch: common header |
542 | * @key: node key | 544 | * @key: node key |
543 | * @size: uncompressed data size in bytes | 545 | * @size: uncompressed data size in bytes |
544 | * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc) | 546 | * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc) |
545 | * @padding: reserved for future, zeroes | 547 | * @padding: reserved for future, zeroes |
546 | * @data: data | 548 | * @data: data |
547 | * | 549 | * |
548 | * Note, do not forget to amend 'zero_data_node_unused()' function when | 550 | * Note, do not forget to amend 'zero_data_node_unused()' function when |
549 | * changing the padding fields. | 551 | * changing the padding fields. |
550 | */ | 552 | */ |
551 | struct ubifs_data_node { | 553 | struct ubifs_data_node { |
552 | struct ubifs_ch ch; | 554 | struct ubifs_ch ch; |
553 | __u8 key[UBIFS_MAX_KEY_LEN]; | 555 | __u8 key[UBIFS_MAX_KEY_LEN]; |
554 | __le32 size; | 556 | __le32 size; |
555 | __le16 compr_type; | 557 | __le16 compr_type; |
556 | __u8 padding[2]; /* Watch 'zero_data_node_unused()' if changing! */ | 558 | __u8 padding[2]; /* Watch 'zero_data_node_unused()' if changing! */ |
557 | __u8 data[]; | 559 | __u8 data[]; |
558 | } __packed; | 560 | } __packed; |
559 | 561 | ||
560 | /** | 562 | /** |
561 | * struct ubifs_trun_node - truncation node. | 563 | * struct ubifs_trun_node - truncation node. |
562 | * @ch: common header | 564 | * @ch: common header |
563 | * @inum: truncated inode number | 565 | * @inum: truncated inode number |
564 | * @padding: reserved for future, zeroes | 566 | * @padding: reserved for future, zeroes |
565 | * @old_size: size before truncation | 567 | * @old_size: size before truncation |
566 | * @new_size: size after truncation | 568 | * @new_size: size after truncation |
567 | * | 569 | * |
568 | * This node exists only in the journal and never goes to the main area. Note, | 570 | * This node exists only in the journal and never goes to the main area. Note, |
569 | * do not forget to amend 'zero_trun_node_unused()' function when changing the | 571 | * do not forget to amend 'zero_trun_node_unused()' function when changing the |
570 | * padding fields. | 572 | * padding fields. |
571 | */ | 573 | */ |
572 | struct ubifs_trun_node { | 574 | struct ubifs_trun_node { |
573 | struct ubifs_ch ch; | 575 | struct ubifs_ch ch; |
574 | __le32 inum; | 576 | __le32 inum; |
575 | __u8 padding[12]; /* Watch 'zero_trun_node_unused()' if changing! */ | 577 | __u8 padding[12]; /* Watch 'zero_trun_node_unused()' if changing! */ |
576 | __le64 old_size; | 578 | __le64 old_size; |
577 | __le64 new_size; | 579 | __le64 new_size; |
578 | } __packed; | 580 | } __packed; |
579 | 581 | ||
580 | /** | 582 | /** |
581 | * struct ubifs_pad_node - padding node. | 583 | * struct ubifs_pad_node - padding node. |
582 | * @ch: common header | 584 | * @ch: common header |
583 | * @pad_len: how many bytes after this node are unused (because padded) | 585 | * @pad_len: how many bytes after this node are unused (because padded) |
584 | * @padding: reserved for future, zeroes | 586 | * @padding: reserved for future, zeroes |
585 | */ | 587 | */ |
586 | struct ubifs_pad_node { | 588 | struct ubifs_pad_node { |
587 | struct ubifs_ch ch; | 589 | struct ubifs_ch ch; |
588 | __le32 pad_len; | 590 | __le32 pad_len; |
589 | } __packed; | 591 | } __packed; |
590 | 592 | ||
591 | /** | 593 | /** |
592 | * struct ubifs_sb_node - superblock node. | 594 | * struct ubifs_sb_node - superblock node. |
593 | * @ch: common header | 595 | * @ch: common header |
594 | * @padding: reserved for future, zeroes | 596 | * @padding: reserved for future, zeroes |
595 | * @key_hash: type of hash function used in keys | 597 | * @key_hash: type of hash function used in keys |
596 | * @key_fmt: format of the key | 598 | * @key_fmt: format of the key |
597 | * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc) | 599 | * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc) |
598 | * @min_io_size: minimal input/output unit size | 600 | * @min_io_size: minimal input/output unit size |
599 | * @leb_size: logical eraseblock size in bytes | 601 | * @leb_size: logical eraseblock size in bytes |
600 | * @leb_cnt: count of LEBs used by file-system | 602 | * @leb_cnt: count of LEBs used by file-system |
601 | * @max_leb_cnt: maximum count of LEBs used by file-system | 603 | * @max_leb_cnt: maximum count of LEBs used by file-system |
602 | * @max_bud_bytes: maximum amount of data stored in buds | 604 | * @max_bud_bytes: maximum amount of data stored in buds |
603 | * @log_lebs: log size in logical eraseblocks | 605 | * @log_lebs: log size in logical eraseblocks |
604 | * @lpt_lebs: number of LEBs used for lprops table | 606 | * @lpt_lebs: number of LEBs used for lprops table |
605 | * @orph_lebs: number of LEBs used for recording orphans | 607 | * @orph_lebs: number of LEBs used for recording orphans |
606 | * @jhead_cnt: count of journal heads | 608 | * @jhead_cnt: count of journal heads |
607 | * @fanout: tree fanout (max. number of links per indexing node) | 609 | * @fanout: tree fanout (max. number of links per indexing node) |
608 | * @lsave_cnt: number of LEB numbers in LPT's save table | 610 | * @lsave_cnt: number of LEB numbers in LPT's save table |
609 | * @fmt_version: UBIFS on-flash format version | 611 | * @fmt_version: UBIFS on-flash format version |
610 | * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc) | 612 | * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc) |
611 | * @padding1: reserved for future, zeroes | 613 | * @padding1: reserved for future, zeroes |
612 | * @rp_uid: reserve pool UID | 614 | * @rp_uid: reserve pool UID |
613 | * @rp_gid: reserve pool GID | 615 | * @rp_gid: reserve pool GID |
614 | * @rp_size: size of the reserved pool in bytes | 616 | * @rp_size: size of the reserved pool in bytes |
615 | * @padding2: reserved for future, zeroes | 617 | * @padding2: reserved for future, zeroes |
616 | * @time_gran: time granularity in nanoseconds | 618 | * @time_gran: time granularity in nanoseconds |
617 | * @uuid: UUID generated when the file system image was created | 619 | * @uuid: UUID generated when the file system image was created |
618 | * @ro_compat_version: UBIFS R/O compatibility version | 620 | * @ro_compat_version: UBIFS R/O compatibility version |
619 | */ | 621 | */ |
620 | struct ubifs_sb_node { | 622 | struct ubifs_sb_node { |
621 | struct ubifs_ch ch; | 623 | struct ubifs_ch ch; |
622 | __u8 padding[2]; | 624 | __u8 padding[2]; |
623 | __u8 key_hash; | 625 | __u8 key_hash; |
624 | __u8 key_fmt; | 626 | __u8 key_fmt; |
625 | __le32 flags; | 627 | __le32 flags; |
626 | __le32 min_io_size; | 628 | __le32 min_io_size; |
627 | __le32 leb_size; | 629 | __le32 leb_size; |
628 | __le32 leb_cnt; | 630 | __le32 leb_cnt; |
629 | __le32 max_leb_cnt; | 631 | __le32 max_leb_cnt; |
630 | __le64 max_bud_bytes; | 632 | __le64 max_bud_bytes; |
631 | __le32 log_lebs; | 633 | __le32 log_lebs; |
632 | __le32 lpt_lebs; | 634 | __le32 lpt_lebs; |
633 | __le32 orph_lebs; | 635 | __le32 orph_lebs; |
634 | __le32 jhead_cnt; | 636 | __le32 jhead_cnt; |
635 | __le32 fanout; | 637 | __le32 fanout; |
636 | __le32 lsave_cnt; | 638 | __le32 lsave_cnt; |
637 | __le32 fmt_version; | 639 | __le32 fmt_version; |
638 | __le16 default_compr; | 640 | __le16 default_compr; |
639 | __u8 padding1[2]; | 641 | __u8 padding1[2]; |
640 | __le32 rp_uid; | 642 | __le32 rp_uid; |
641 | __le32 rp_gid; | 643 | __le32 rp_gid; |
642 | __le64 rp_size; | 644 | __le64 rp_size; |
643 | __le32 time_gran; | 645 | __le32 time_gran; |
644 | __u8 uuid[16]; | 646 | __u8 uuid[16]; |
645 | __le32 ro_compat_version; | 647 | __le32 ro_compat_version; |
646 | __u8 padding2[3968]; | 648 | __u8 padding2[3968]; |
647 | } __packed; | 649 | } __packed; |
648 | 650 | ||
649 | /** | 651 | /** |
650 | * struct ubifs_mst_node - master node. | 652 | * struct ubifs_mst_node - master node. |
651 | * @ch: common header | 653 | * @ch: common header |
652 | * @highest_inum: highest inode number in the committed index | 654 | * @highest_inum: highest inode number in the committed index |
653 | * @cmt_no: commit number | 655 | * @cmt_no: commit number |
654 | * @flags: various flags (%UBIFS_MST_DIRTY, etc) | 656 | * @flags: various flags (%UBIFS_MST_DIRTY, etc) |
655 | * @log_lnum: start of the log | 657 | * @log_lnum: start of the log |
656 | * @root_lnum: LEB number of the root indexing node | 658 | * @root_lnum: LEB number of the root indexing node |
657 | * @root_offs: offset within @root_lnum | 659 | * @root_offs: offset within @root_lnum |
658 | * @root_len: root indexing node length | 660 | * @root_len: root indexing node length |
659 | * @gc_lnum: LEB reserved for garbage collection (%-1 value means the LEB was | 661 | * @gc_lnum: LEB reserved for garbage collection (%-1 value means the LEB was |
660 | * not reserved and should be reserved on mount) | 662 | * not reserved and should be reserved on mount) |
661 | * @ihead_lnum: LEB number of index head | 663 | * @ihead_lnum: LEB number of index head |
662 | * @ihead_offs: offset of index head | 664 | * @ihead_offs: offset of index head |
663 | * @index_size: size of index on flash | 665 | * @index_size: size of index on flash |
664 | * @total_free: total free space in bytes | 666 | * @total_free: total free space in bytes |
665 | * @total_dirty: total dirty space in bytes | 667 | * @total_dirty: total dirty space in bytes |
666 | * @total_used: total used space in bytes (includes only data LEBs) | 668 | * @total_used: total used space in bytes (includes only data LEBs) |
667 | * @total_dead: total dead space in bytes (includes only data LEBs) | 669 | * @total_dead: total dead space in bytes (includes only data LEBs) |
668 | * @total_dark: total dark space in bytes (includes only data LEBs) | 670 | * @total_dark: total dark space in bytes (includes only data LEBs) |
669 | * @lpt_lnum: LEB number of LPT root nnode | 671 | * @lpt_lnum: LEB number of LPT root nnode |
670 | * @lpt_offs: offset of LPT root nnode | 672 | * @lpt_offs: offset of LPT root nnode |
671 | * @nhead_lnum: LEB number of LPT head | 673 | * @nhead_lnum: LEB number of LPT head |
672 | * @nhead_offs: offset of LPT head | 674 | * @nhead_offs: offset of LPT head |
673 | * @ltab_lnum: LEB number of LPT's own lprops table | 675 | * @ltab_lnum: LEB number of LPT's own lprops table |
674 | * @ltab_offs: offset of LPT's own lprops table | 676 | * @ltab_offs: offset of LPT's own lprops table |
675 | * @lsave_lnum: LEB number of LPT's save table (big model only) | 677 | * @lsave_lnum: LEB number of LPT's save table (big model only) |
676 | * @lsave_offs: offset of LPT's save table (big model only) | 678 | * @lsave_offs: offset of LPT's save table (big model only) |
677 | * @lscan_lnum: LEB number of last LPT scan | 679 | * @lscan_lnum: LEB number of last LPT scan |
678 | * @empty_lebs: number of empty logical eraseblocks | 680 | * @empty_lebs: number of empty logical eraseblocks |
679 | * @idx_lebs: number of indexing logical eraseblocks | 681 | * @idx_lebs: number of indexing logical eraseblocks |
680 | * @leb_cnt: count of LEBs used by file-system | 682 | * @leb_cnt: count of LEBs used by file-system |
681 | * @padding: reserved for future, zeroes | 683 | * @padding: reserved for future, zeroes |
682 | */ | 684 | */ |
683 | struct ubifs_mst_node { | 685 | struct ubifs_mst_node { |
684 | struct ubifs_ch ch; | 686 | struct ubifs_ch ch; |
685 | __le64 highest_inum; | 687 | __le64 highest_inum; |
686 | __le64 cmt_no; | 688 | __le64 cmt_no; |
687 | __le32 flags; | 689 | __le32 flags; |
688 | __le32 log_lnum; | 690 | __le32 log_lnum; |
689 | __le32 root_lnum; | 691 | __le32 root_lnum; |
690 | __le32 root_offs; | 692 | __le32 root_offs; |
691 | __le32 root_len; | 693 | __le32 root_len; |
692 | __le32 gc_lnum; | 694 | __le32 gc_lnum; |
693 | __le32 ihead_lnum; | 695 | __le32 ihead_lnum; |
694 | __le32 ihead_offs; | 696 | __le32 ihead_offs; |
695 | __le64 index_size; | 697 | __le64 index_size; |
696 | __le64 total_free; | 698 | __le64 total_free; |
697 | __le64 total_dirty; | 699 | __le64 total_dirty; |
698 | __le64 total_used; | 700 | __le64 total_used; |
699 | __le64 total_dead; | 701 | __le64 total_dead; |
700 | __le64 total_dark; | 702 | __le64 total_dark; |
701 | __le32 lpt_lnum; | 703 | __le32 lpt_lnum; |
702 | __le32 lpt_offs; | 704 | __le32 lpt_offs; |
703 | __le32 nhead_lnum; | 705 | __le32 nhead_lnum; |
704 | __le32 nhead_offs; | 706 | __le32 nhead_offs; |
705 | __le32 ltab_lnum; | 707 | __le32 ltab_lnum; |
706 | __le32 ltab_offs; | 708 | __le32 ltab_offs; |
707 | __le32 lsave_lnum; | 709 | __le32 lsave_lnum; |
708 | __le32 lsave_offs; | 710 | __le32 lsave_offs; |
709 | __le32 lscan_lnum; | 711 | __le32 lscan_lnum; |
710 | __le32 empty_lebs; | 712 | __le32 empty_lebs; |
711 | __le32 idx_lebs; | 713 | __le32 idx_lebs; |
712 | __le32 leb_cnt; | 714 | __le32 leb_cnt; |
713 | __u8 padding[344]; | 715 | __u8 padding[344]; |
714 | } __packed; | 716 | } __packed; |
715 | 717 | ||
716 | /** | 718 | /** |
717 | * struct ubifs_ref_node - logical eraseblock reference node. | 719 | * struct ubifs_ref_node - logical eraseblock reference node. |
718 | * @ch: common header | 720 | * @ch: common header |
719 | * @lnum: the referred logical eraseblock number | 721 | * @lnum: the referred logical eraseblock number |
720 | * @offs: start offset in the referred LEB | 722 | * @offs: start offset in the referred LEB |
721 | * @jhead: journal head number | 723 | * @jhead: journal head number |
722 | * @padding: reserved for future, zeroes | 724 | * @padding: reserved for future, zeroes |
723 | */ | 725 | */ |
724 | struct ubifs_ref_node { | 726 | struct ubifs_ref_node { |
725 | struct ubifs_ch ch; | 727 | struct ubifs_ch ch; |
726 | __le32 lnum; | 728 | __le32 lnum; |
727 | __le32 offs; | 729 | __le32 offs; |
728 | __le32 jhead; | 730 | __le32 jhead; |
729 | __u8 padding[28]; | 731 | __u8 padding[28]; |
730 | } __packed; | 732 | } __packed; |
731 | 733 | ||
732 | /** | 734 | /** |
733 | * struct ubifs_branch - key/reference/length branch | 735 | * struct ubifs_branch - key/reference/length branch |
734 | * @lnum: LEB number of the target node | 736 | * @lnum: LEB number of the target node |
735 | * @offs: offset within @lnum | 737 | * @offs: offset within @lnum |
736 | * @len: target node length | 738 | * @len: target node length |
737 | * @key: key | 739 | * @key: key |
738 | */ | 740 | */ |
739 | struct ubifs_branch { | 741 | struct ubifs_branch { |
740 | __le32 lnum; | 742 | __le32 lnum; |
741 | __le32 offs; | 743 | __le32 offs; |
742 | __le32 len; | 744 | __le32 len; |
743 | __u8 key[]; | 745 | __u8 key[]; |
744 | } __packed; | 746 | } __packed; |
745 | 747 | ||
746 | /** | 748 | /** |
747 | * struct ubifs_idx_node - indexing node. | 749 | * struct ubifs_idx_node - indexing node. |
748 | * @ch: common header | 750 | * @ch: common header |
749 | * @child_cnt: number of child index nodes | 751 | * @child_cnt: number of child index nodes |
750 | * @level: tree level | 752 | * @level: tree level |
751 | * @branches: LEB number / offset / length / key branches | 753 | * @branches: LEB number / offset / length / key branches |
752 | */ | 754 | */ |
753 | struct ubifs_idx_node { | 755 | struct ubifs_idx_node { |
754 | struct ubifs_ch ch; | 756 | struct ubifs_ch ch; |
755 | __le16 child_cnt; | 757 | __le16 child_cnt; |
756 | __le16 level; | 758 | __le16 level; |
757 | __u8 branches[]; | 759 | __u8 branches[]; |
758 | } __packed; | 760 | } __packed; |
759 | 761 | ||
760 | /** | 762 | /** |
761 | * struct ubifs_cs_node - commit start node. | 763 | * struct ubifs_cs_node - commit start node. |
762 | * @ch: common header | 764 | * @ch: common header |
763 | * @cmt_no: commit number | 765 | * @cmt_no: commit number |
764 | */ | 766 | */ |
765 | struct ubifs_cs_node { | 767 | struct ubifs_cs_node { |
766 | struct ubifs_ch ch; | 768 | struct ubifs_ch ch; |
767 | __le64 cmt_no; | 769 | __le64 cmt_no; |
768 | } __packed; | 770 | } __packed; |
769 | 771 | ||
770 | /** | 772 | /** |
771 | * struct ubifs_orph_node - orphan node. | 773 | * struct ubifs_orph_node - orphan node. |
772 | * @ch: common header | 774 | * @ch: common header |
773 | * @cmt_no: commit number (also top bit is set on the last node of the commit) | 775 | * @cmt_no: commit number (also top bit is set on the last node of the commit) |
774 | * @inos: inode numbers of orphans | 776 | * @inos: inode numbers of orphans |
775 | */ | 777 | */ |
776 | struct ubifs_orph_node { | 778 | struct ubifs_orph_node { |
777 | struct ubifs_ch ch; | 779 | struct ubifs_ch ch; |
778 | __le64 cmt_no; | 780 | __le64 cmt_no; |
779 | __le64 inos[]; | 781 | __le64 inos[]; |
780 | } __packed; | 782 | } __packed; |
781 | 783 | ||
782 | #endif /* __UBIFS_MEDIA_H__ */ | 784 | #endif /* __UBIFS_MEDIA_H__ */ |
783 | 785 |
fs/ubifs/ubifs.h
1 | /* | 1 | /* |
2 | * This file is part of UBIFS. | 2 | * This file is part of UBIFS. |
3 | * | 3 | * |
4 | * Copyright (C) 2006-2008 Nokia Corporation | 4 | * Copyright (C) 2006-2008 Nokia Corporation |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 6 | * This program is free software; you can redistribute it and/or modify it |
7 | * under the terms of the GNU General Public License version 2 as published by | 7 | * under the terms of the GNU General Public License version 2 as published by |
8 | * the Free Software Foundation. | 8 | * the Free Software Foundation. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
13 | * more details. | 13 | * more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License along with | 15 | * You should have received a copy of the GNU General Public License along with |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | 16 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | * | 18 | * |
19 | * Authors: Artem Bityutskiy (Битюцкий Артём) | 19 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
20 | * Adrian Hunter | 20 | * Adrian Hunter |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #ifndef __UBIFS_H__ | 23 | #ifndef __UBIFS_H__ |
24 | #define __UBIFS_H__ | 24 | #define __UBIFS_H__ |
25 | 25 | ||
26 | #include <asm/div64.h> | 26 | #include <asm/div64.h> |
27 | #include <linux/statfs.h> | 27 | #include <linux/statfs.h> |
28 | #include <linux/fs.h> | 28 | #include <linux/fs.h> |
29 | #include <linux/err.h> | 29 | #include <linux/err.h> |
30 | #include <linux/sched.h> | 30 | #include <linux/sched.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/vmalloc.h> | 32 | #include <linux/vmalloc.h> |
33 | #include <linux/spinlock.h> | 33 | #include <linux/spinlock.h> |
34 | #include <linux/mutex.h> | 34 | #include <linux/mutex.h> |
35 | #include <linux/rwsem.h> | 35 | #include <linux/rwsem.h> |
36 | #include <linux/mtd/ubi.h> | 36 | #include <linux/mtd/ubi.h> |
37 | #include <linux/pagemap.h> | 37 | #include <linux/pagemap.h> |
38 | #include <linux/backing-dev.h> | 38 | #include <linux/backing-dev.h> |
39 | #include "ubifs-media.h" | 39 | #include "ubifs-media.h" |
40 | 40 | ||
41 | /* Version of this UBIFS implementation */ | 41 | /* Version of this UBIFS implementation */ |
42 | #define UBIFS_VERSION 1 | 42 | #define UBIFS_VERSION 1 |
43 | 43 | ||
44 | /* Normal UBIFS messages */ | 44 | /* Normal UBIFS messages */ |
45 | #define ubifs_msg(fmt, ...) \ | 45 | #define ubifs_msg(fmt, ...) \ |
46 | printk(KERN_NOTICE "UBIFS: " fmt "\n", ##__VA_ARGS__) | 46 | printk(KERN_NOTICE "UBIFS: " fmt "\n", ##__VA_ARGS__) |
47 | /* UBIFS error messages */ | 47 | /* UBIFS error messages */ |
48 | #define ubifs_err(fmt, ...) \ | 48 | #define ubifs_err(fmt, ...) \ |
49 | printk(KERN_ERR "UBIFS error (pid %d): %s: " fmt "\n", current->pid, \ | 49 | printk(KERN_ERR "UBIFS error (pid %d): %s: " fmt "\n", current->pid, \ |
50 | __func__, ##__VA_ARGS__) | 50 | __func__, ##__VA_ARGS__) |
51 | /* UBIFS warning messages */ | 51 | /* UBIFS warning messages */ |
52 | #define ubifs_warn(fmt, ...) \ | 52 | #define ubifs_warn(fmt, ...) \ |
53 | printk(KERN_WARNING "UBIFS warning (pid %d): %s: " fmt "\n", \ | 53 | printk(KERN_WARNING "UBIFS warning (pid %d): %s: " fmt "\n", \ |
54 | current->pid, __func__, ##__VA_ARGS__) | 54 | current->pid, __func__, ##__VA_ARGS__) |
55 | 55 | ||
56 | /* UBIFS file system VFS magic number */ | 56 | /* UBIFS file system VFS magic number */ |
57 | #define UBIFS_SUPER_MAGIC 0x24051905 | 57 | #define UBIFS_SUPER_MAGIC 0x24051905 |
58 | 58 | ||
59 | /* Number of UBIFS blocks per VFS page */ | 59 | /* Number of UBIFS blocks per VFS page */ |
60 | #define UBIFS_BLOCKS_PER_PAGE (PAGE_CACHE_SIZE / UBIFS_BLOCK_SIZE) | 60 | #define UBIFS_BLOCKS_PER_PAGE (PAGE_CACHE_SIZE / UBIFS_BLOCK_SIZE) |
61 | #define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_CACHE_SHIFT - UBIFS_BLOCK_SHIFT) | 61 | #define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_CACHE_SHIFT - UBIFS_BLOCK_SHIFT) |
62 | 62 | ||
63 | /* "File system end of life" sequence number watermark */ | 63 | /* "File system end of life" sequence number watermark */ |
64 | #define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL | 64 | #define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL |
65 | #define SQNUM_WATERMARK 0xFFFFFFFFFF000000ULL | 65 | #define SQNUM_WATERMARK 0xFFFFFFFFFF000000ULL |
66 | 66 | ||
67 | /* | 67 | /* |
68 | * Minimum amount of LEBs reserved for the index. At present the index needs at | 68 | * Minimum amount of LEBs reserved for the index. At present the index needs at |
69 | * least 2 LEBs: one for the index head and one for in-the-gaps method (which | 69 | * least 2 LEBs: one for the index head and one for in-the-gaps method (which |
70 | * currently does not cater for the index head and so excludes it from | 70 | * currently does not cater for the index head and so excludes it from |
71 | * consideration). | 71 | * consideration). |
72 | */ | 72 | */ |
73 | #define MIN_INDEX_LEBS 2 | 73 | #define MIN_INDEX_LEBS 2 |
74 | 74 | ||
75 | /* Minimum amount of data UBIFS writes to the flash */ | 75 | /* Minimum amount of data UBIFS writes to the flash */ |
76 | #define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8) | 76 | #define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8) |
77 | 77 | ||
78 | /* | 78 | /* |
79 | * Currently we do not support inode number overlapping and re-using, so this | 79 | * Currently we do not support inode number overlapping and re-using, so this |
80 | * watermark defines dangerous inode number level. This should be fixed later, | 80 | * watermark defines dangerous inode number level. This should be fixed later, |
81 | * although it is difficult to exceed current limit. Another option is to use | 81 | * although it is difficult to exceed current limit. Another option is to use |
82 | * 64-bit inode numbers, but this means more overhead. | 82 | * 64-bit inode numbers, but this means more overhead. |
83 | */ | 83 | */ |
84 | #define INUM_WARN_WATERMARK 0xFFF00000 | 84 | #define INUM_WARN_WATERMARK 0xFFF00000 |
85 | #define INUM_WATERMARK 0xFFFFFF00 | 85 | #define INUM_WATERMARK 0xFFFFFF00 |
86 | 86 | ||
87 | /* Largest key size supported in this implementation */ | 87 | /* Largest key size supported in this implementation */ |
88 | #define CUR_MAX_KEY_LEN UBIFS_SK_LEN | 88 | #define CUR_MAX_KEY_LEN UBIFS_SK_LEN |
89 | 89 | ||
90 | /* Maximum number of entries in each LPT (LEB category) heap */ | 90 | /* Maximum number of entries in each LPT (LEB category) heap */ |
91 | #define LPT_HEAP_SZ 256 | 91 | #define LPT_HEAP_SZ 256 |
92 | 92 | ||
93 | /* | 93 | /* |
94 | * Background thread name pattern. The numbers are UBI device and volume | 94 | * Background thread name pattern. The numbers are UBI device and volume |
95 | * numbers. | 95 | * numbers. |
96 | */ | 96 | */ |
97 | #define BGT_NAME_PATTERN "ubifs_bgt%d_%d" | 97 | #define BGT_NAME_PATTERN "ubifs_bgt%d_%d" |
98 | 98 | ||
99 | /* Write-buffer synchronization timeout interval in seconds */ | 99 | /* Write-buffer synchronization timeout interval in seconds */ |
100 | #define WBUF_TIMEOUT_SOFTLIMIT 3 | 100 | #define WBUF_TIMEOUT_SOFTLIMIT 3 |
101 | #define WBUF_TIMEOUT_HARDLIMIT 5 | 101 | #define WBUF_TIMEOUT_HARDLIMIT 5 |
102 | 102 | ||
103 | /* Maximum possible inode number (only 32-bit inodes are supported now) */ | 103 | /* Maximum possible inode number (only 32-bit inodes are supported now) */ |
104 | #define MAX_INUM 0xFFFFFFFF | 104 | #define MAX_INUM 0xFFFFFFFF |
105 | 105 | ||
106 | /* Number of non-data journal heads */ | 106 | /* Number of non-data journal heads */ |
107 | #define NONDATA_JHEADS_CNT 2 | 107 | #define NONDATA_JHEADS_CNT 2 |
108 | 108 | ||
109 | /* Shorter names for journal head numbers for internal usage */ | 109 | /* Shorter names for journal head numbers for internal usage */ |
110 | #define GCHD UBIFS_GC_HEAD | 110 | #define GCHD UBIFS_GC_HEAD |
111 | #define BASEHD UBIFS_BASE_HEAD | 111 | #define BASEHD UBIFS_BASE_HEAD |
112 | #define DATAHD UBIFS_DATA_HEAD | 112 | #define DATAHD UBIFS_DATA_HEAD |
113 | 113 | ||
114 | /* 'No change' value for 'ubifs_change_lp()' */ | 114 | /* 'No change' value for 'ubifs_change_lp()' */ |
115 | #define LPROPS_NC 0x80000001 | 115 | #define LPROPS_NC 0x80000001 |
116 | 116 | ||
117 | /* | 117 | /* |
118 | * There is no notion of truncation key because truncation nodes do not exist | 118 | * There is no notion of truncation key because truncation nodes do not exist |
119 | * in TNC. However, when replaying, it is handy to introduce fake "truncation" | 119 | * in TNC. However, when replaying, it is handy to introduce fake "truncation" |
120 | * keys for truncation nodes because the code becomes simpler. So we define | 120 | * keys for truncation nodes because the code becomes simpler. So we define |
121 | * %UBIFS_TRUN_KEY type. | 121 | * %UBIFS_TRUN_KEY type. |
122 | * | 122 | * |
123 | * But otherwise, out of the journal reply scope, the truncation keys are | 123 | * But otherwise, out of the journal reply scope, the truncation keys are |
124 | * invalid. | 124 | * invalid. |
125 | */ | 125 | */ |
126 | #define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT | 126 | #define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT |
127 | #define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT | 127 | #define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT |
128 | 128 | ||
129 | /* | 129 | /* |
130 | * How much a directory entry/extended attribute entry adds to the parent/host | 130 | * How much a directory entry/extended attribute entry adds to the parent/host |
131 | * inode. | 131 | * inode. |
132 | */ | 132 | */ |
133 | #define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8) | 133 | #define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8) |
134 | 134 | ||
135 | /* How much an extended attribute adds to the host inode */ | 135 | /* How much an extended attribute adds to the host inode */ |
136 | #define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8) | 136 | #define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8) |
137 | 137 | ||
138 | /* | 138 | /* |
139 | * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered | 139 | * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered |
140 | * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are | 140 | * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are |
141 | * considered "young". This is used by shrinker when selecting znode to trim | 141 | * considered "young". This is used by shrinker when selecting znode to trim |
142 | * off. | 142 | * off. |
143 | */ | 143 | */ |
144 | #define OLD_ZNODE_AGE 20 | 144 | #define OLD_ZNODE_AGE 20 |
145 | #define YOUNG_ZNODE_AGE 5 | 145 | #define YOUNG_ZNODE_AGE 5 |
146 | 146 | ||
147 | /* | 147 | /* |
148 | * Some compressors, like LZO, may end up with more data then the input buffer. | 148 | * Some compressors, like LZO, may end up with more data then the input buffer. |
149 | * So UBIFS always allocates larger output buffer, to be sure the compressor | 149 | * So UBIFS always allocates larger output buffer, to be sure the compressor |
150 | * will not corrupt memory in case of worst case compression. | 150 | * will not corrupt memory in case of worst case compression. |
151 | */ | 151 | */ |
152 | #define WORST_COMPR_FACTOR 2 | 152 | #define WORST_COMPR_FACTOR 2 |
153 | 153 | ||
154 | /* | 154 | /* |
155 | * How much memory is needed for a buffer where we comress a data node. | 155 | * How much memory is needed for a buffer where we comress a data node. |
156 | */ | 156 | */ |
157 | #define COMPRESSED_DATA_NODE_BUF_SZ \ | 157 | #define COMPRESSED_DATA_NODE_BUF_SZ \ |
158 | (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR) | 158 | (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR) |
159 | 159 | ||
160 | /* Maximum expected tree height for use by bottom_up_buf */ | 160 | /* Maximum expected tree height for use by bottom_up_buf */ |
161 | #define BOTTOM_UP_HEIGHT 64 | 161 | #define BOTTOM_UP_HEIGHT 64 |
162 | 162 | ||
163 | /* Maximum number of data nodes to bulk-read */ | 163 | /* Maximum number of data nodes to bulk-read */ |
164 | #define UBIFS_MAX_BULK_READ 32 | 164 | #define UBIFS_MAX_BULK_READ 32 |
165 | 165 | ||
166 | /* | 166 | /* |
167 | * Lockdep classes for UBIFS inode @ui_mutex. | 167 | * Lockdep classes for UBIFS inode @ui_mutex. |
168 | */ | 168 | */ |
169 | enum { | 169 | enum { |
170 | WB_MUTEX_1 = 0, | 170 | WB_MUTEX_1 = 0, |
171 | WB_MUTEX_2 = 1, | 171 | WB_MUTEX_2 = 1, |
172 | WB_MUTEX_3 = 2, | 172 | WB_MUTEX_3 = 2, |
173 | }; | 173 | }; |
174 | 174 | ||
175 | /* | 175 | /* |
176 | * Znode flags (actually, bit numbers which store the flags). | 176 | * Znode flags (actually, bit numbers which store the flags). |
177 | * | 177 | * |
178 | * DIRTY_ZNODE: znode is dirty | 178 | * DIRTY_ZNODE: znode is dirty |
179 | * COW_ZNODE: znode is being committed and a new instance of this znode has to | 179 | * COW_ZNODE: znode is being committed and a new instance of this znode has to |
180 | * be created before changing this znode | 180 | * be created before changing this znode |
181 | * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is | 181 | * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is |
182 | * still in the commit list and the ongoing commit operation | 182 | * still in the commit list and the ongoing commit operation |
183 | * will commit it, and delete this znode after it is done | 183 | * will commit it, and delete this znode after it is done |
184 | */ | 184 | */ |
185 | enum { | 185 | enum { |
186 | DIRTY_ZNODE = 0, | 186 | DIRTY_ZNODE = 0, |
187 | COW_ZNODE = 1, | 187 | COW_ZNODE = 1, |
188 | OBSOLETE_ZNODE = 2, | 188 | OBSOLETE_ZNODE = 2, |
189 | }; | 189 | }; |
190 | 190 | ||
191 | /* | 191 | /* |
192 | * Commit states. | 192 | * Commit states. |
193 | * | 193 | * |
194 | * COMMIT_RESTING: commit is not wanted | 194 | * COMMIT_RESTING: commit is not wanted |
195 | * COMMIT_BACKGROUND: background commit has been requested | 195 | * COMMIT_BACKGROUND: background commit has been requested |
196 | * COMMIT_REQUIRED: commit is required | 196 | * COMMIT_REQUIRED: commit is required |
197 | * COMMIT_RUNNING_BACKGROUND: background commit is running | 197 | * COMMIT_RUNNING_BACKGROUND: background commit is running |
198 | * COMMIT_RUNNING_REQUIRED: commit is running and it is required | 198 | * COMMIT_RUNNING_REQUIRED: commit is running and it is required |
199 | * COMMIT_BROKEN: commit failed | 199 | * COMMIT_BROKEN: commit failed |
200 | */ | 200 | */ |
201 | enum { | 201 | enum { |
202 | COMMIT_RESTING = 0, | 202 | COMMIT_RESTING = 0, |
203 | COMMIT_BACKGROUND, | 203 | COMMIT_BACKGROUND, |
204 | COMMIT_REQUIRED, | 204 | COMMIT_REQUIRED, |
205 | COMMIT_RUNNING_BACKGROUND, | 205 | COMMIT_RUNNING_BACKGROUND, |
206 | COMMIT_RUNNING_REQUIRED, | 206 | COMMIT_RUNNING_REQUIRED, |
207 | COMMIT_BROKEN, | 207 | COMMIT_BROKEN, |
208 | }; | 208 | }; |
209 | 209 | ||
210 | /* | 210 | /* |
211 | * 'ubifs_scan_a_node()' return values. | 211 | * 'ubifs_scan_a_node()' return values. |
212 | * | 212 | * |
213 | * SCANNED_GARBAGE: scanned garbage | 213 | * SCANNED_GARBAGE: scanned garbage |
214 | * SCANNED_EMPTY_SPACE: scanned empty space | 214 | * SCANNED_EMPTY_SPACE: scanned empty space |
215 | * SCANNED_A_NODE: scanned a valid node | 215 | * SCANNED_A_NODE: scanned a valid node |
216 | * SCANNED_A_CORRUPT_NODE: scanned a corrupted node | 216 | * SCANNED_A_CORRUPT_NODE: scanned a corrupted node |
217 | * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length | 217 | * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length |
218 | * | 218 | * |
219 | * Greater than zero means: 'scanned that number of padding bytes' | 219 | * Greater than zero means: 'scanned that number of padding bytes' |
220 | */ | 220 | */ |
221 | enum { | 221 | enum { |
222 | SCANNED_GARBAGE = 0, | 222 | SCANNED_GARBAGE = 0, |
223 | SCANNED_EMPTY_SPACE = -1, | 223 | SCANNED_EMPTY_SPACE = -1, |
224 | SCANNED_A_NODE = -2, | 224 | SCANNED_A_NODE = -2, |
225 | SCANNED_A_CORRUPT_NODE = -3, | 225 | SCANNED_A_CORRUPT_NODE = -3, |
226 | SCANNED_A_BAD_PAD_NODE = -4, | 226 | SCANNED_A_BAD_PAD_NODE = -4, |
227 | }; | 227 | }; |
228 | 228 | ||
229 | /* | 229 | /* |
230 | * LPT cnode flag bits. | 230 | * LPT cnode flag bits. |
231 | * | 231 | * |
232 | * DIRTY_CNODE: cnode is dirty | 232 | * DIRTY_CNODE: cnode is dirty |
233 | * COW_CNODE: cnode is being committed and must be copied before writing | 233 | * COW_CNODE: cnode is being committed and must be copied before writing |
234 | * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted), | 234 | * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted), |
235 | * so it can (and must) be freed when the commit is finished | 235 | * so it can (and must) be freed when the commit is finished |
236 | */ | 236 | */ |
237 | enum { | 237 | enum { |
238 | DIRTY_CNODE = 0, | 238 | DIRTY_CNODE = 0, |
239 | COW_CNODE = 1, | 239 | COW_CNODE = 1, |
240 | OBSOLETE_CNODE = 2, | 240 | OBSOLETE_CNODE = 2, |
241 | }; | 241 | }; |
242 | 242 | ||
243 | /* | 243 | /* |
244 | * Dirty flag bits (lpt_drty_flgs) for LPT special nodes. | 244 | * Dirty flag bits (lpt_drty_flgs) for LPT special nodes. |
245 | * | 245 | * |
246 | * LTAB_DIRTY: ltab node is dirty | 246 | * LTAB_DIRTY: ltab node is dirty |
247 | * LSAVE_DIRTY: lsave node is dirty | 247 | * LSAVE_DIRTY: lsave node is dirty |
248 | */ | 248 | */ |
249 | enum { | 249 | enum { |
250 | LTAB_DIRTY = 1, | 250 | LTAB_DIRTY = 1, |
251 | LSAVE_DIRTY = 2, | 251 | LSAVE_DIRTY = 2, |
252 | }; | 252 | }; |
253 | 253 | ||
254 | /* | 254 | /* |
255 | * Return codes used by the garbage collector. | 255 | * Return codes used by the garbage collector. |
256 | * @LEB_FREED: the logical eraseblock was freed and is ready to use | 256 | * @LEB_FREED: the logical eraseblock was freed and is ready to use |
257 | * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit | 257 | * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit |
258 | * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes | 258 | * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes |
259 | */ | 259 | */ |
260 | enum { | 260 | enum { |
261 | LEB_FREED, | 261 | LEB_FREED, |
262 | LEB_FREED_IDX, | 262 | LEB_FREED_IDX, |
263 | LEB_RETAINED, | 263 | LEB_RETAINED, |
264 | }; | 264 | }; |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * struct ubifs_old_idx - index node obsoleted since last commit start. | 267 | * struct ubifs_old_idx - index node obsoleted since last commit start. |
268 | * @rb: rb-tree node | 268 | * @rb: rb-tree node |
269 | * @lnum: LEB number of obsoleted index node | 269 | * @lnum: LEB number of obsoleted index node |
270 | * @offs: offset of obsoleted index node | 270 | * @offs: offset of obsoleted index node |
271 | */ | 271 | */ |
272 | struct ubifs_old_idx { | 272 | struct ubifs_old_idx { |
273 | struct rb_node rb; | 273 | struct rb_node rb; |
274 | int lnum; | 274 | int lnum; |
275 | int offs; | 275 | int offs; |
276 | }; | 276 | }; |
277 | 277 | ||
278 | /* The below union makes it easier to deal with keys */ | 278 | /* The below union makes it easier to deal with keys */ |
279 | union ubifs_key { | 279 | union ubifs_key { |
280 | uint8_t u8[CUR_MAX_KEY_LEN]; | 280 | uint8_t u8[CUR_MAX_KEY_LEN]; |
281 | uint32_t u32[CUR_MAX_KEY_LEN/4]; | 281 | uint32_t u32[CUR_MAX_KEY_LEN/4]; |
282 | uint64_t u64[CUR_MAX_KEY_LEN/8]; | 282 | uint64_t u64[CUR_MAX_KEY_LEN/8]; |
283 | __le32 j32[CUR_MAX_KEY_LEN/4]; | 283 | __le32 j32[CUR_MAX_KEY_LEN/4]; |
284 | }; | 284 | }; |
285 | 285 | ||
286 | /** | 286 | /** |
287 | * struct ubifs_scan_node - UBIFS scanned node information. | 287 | * struct ubifs_scan_node - UBIFS scanned node information. |
288 | * @list: list of scanned nodes | 288 | * @list: list of scanned nodes |
289 | * @key: key of node scanned (if it has one) | 289 | * @key: key of node scanned (if it has one) |
290 | * @sqnum: sequence number | 290 | * @sqnum: sequence number |
291 | * @type: type of node scanned | 291 | * @type: type of node scanned |
292 | * @offs: offset with LEB of node scanned | 292 | * @offs: offset with LEB of node scanned |
293 | * @len: length of node scanned | 293 | * @len: length of node scanned |
294 | * @node: raw node | 294 | * @node: raw node |
295 | */ | 295 | */ |
296 | struct ubifs_scan_node { | 296 | struct ubifs_scan_node { |
297 | struct list_head list; | 297 | struct list_head list; |
298 | union ubifs_key key; | 298 | union ubifs_key key; |
299 | unsigned long long sqnum; | 299 | unsigned long long sqnum; |
300 | int type; | 300 | int type; |
301 | int offs; | 301 | int offs; |
302 | int len; | 302 | int len; |
303 | void *node; | 303 | void *node; |
304 | }; | 304 | }; |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * struct ubifs_scan_leb - UBIFS scanned LEB information. | 307 | * struct ubifs_scan_leb - UBIFS scanned LEB information. |
308 | * @lnum: logical eraseblock number | 308 | * @lnum: logical eraseblock number |
309 | * @nodes_cnt: number of nodes scanned | 309 | * @nodes_cnt: number of nodes scanned |
310 | * @nodes: list of struct ubifs_scan_node | 310 | * @nodes: list of struct ubifs_scan_node |
311 | * @endpt: end point (and therefore the start of empty space) | 311 | * @endpt: end point (and therefore the start of empty space) |
312 | * @ecc: read returned -EBADMSG | 312 | * @ecc: read returned -EBADMSG |
313 | * @buf: buffer containing entire LEB scanned | 313 | * @buf: buffer containing entire LEB scanned |
314 | */ | 314 | */ |
315 | struct ubifs_scan_leb { | 315 | struct ubifs_scan_leb { |
316 | int lnum; | 316 | int lnum; |
317 | int nodes_cnt; | 317 | int nodes_cnt; |
318 | struct list_head nodes; | 318 | struct list_head nodes; |
319 | int endpt; | 319 | int endpt; |
320 | int ecc; | 320 | int ecc; |
321 | void *buf; | 321 | void *buf; |
322 | }; | 322 | }; |
323 | 323 | ||
324 | /** | 324 | /** |
325 | * struct ubifs_gced_idx_leb - garbage-collected indexing LEB. | 325 | * struct ubifs_gced_idx_leb - garbage-collected indexing LEB. |
326 | * @list: list | 326 | * @list: list |
327 | * @lnum: LEB number | 327 | * @lnum: LEB number |
328 | * @unmap: OK to unmap this LEB | 328 | * @unmap: OK to unmap this LEB |
329 | * | 329 | * |
330 | * This data structure is used to temporary store garbage-collected indexing | 330 | * This data structure is used to temporary store garbage-collected indexing |
331 | * LEBs - they are not released immediately, but only after the next commit. | 331 | * LEBs - they are not released immediately, but only after the next commit. |
332 | * This is needed to guarantee recoverability. | 332 | * This is needed to guarantee recoverability. |
333 | */ | 333 | */ |
334 | struct ubifs_gced_idx_leb { | 334 | struct ubifs_gced_idx_leb { |
335 | struct list_head list; | 335 | struct list_head list; |
336 | int lnum; | 336 | int lnum; |
337 | int unmap; | 337 | int unmap; |
338 | }; | 338 | }; |
339 | 339 | ||
340 | /** | 340 | /** |
341 | * struct ubifs_inode - UBIFS in-memory inode description. | 341 | * struct ubifs_inode - UBIFS in-memory inode description. |
342 | * @vfs_inode: VFS inode description object | 342 | * @vfs_inode: VFS inode description object |
343 | * @creat_sqnum: sequence number at time of creation | 343 | * @creat_sqnum: sequence number at time of creation |
344 | * @del_cmtno: commit number corresponding to the time the inode was deleted, | 344 | * @del_cmtno: commit number corresponding to the time the inode was deleted, |
345 | * protected by @c->commit_sem; | 345 | * protected by @c->commit_sem; |
346 | * @xattr_size: summarized size of all extended attributes in bytes | 346 | * @xattr_size: summarized size of all extended attributes in bytes |
347 | * @xattr_cnt: count of extended attributes this inode has | 347 | * @xattr_cnt: count of extended attributes this inode has |
348 | * @xattr_names: sum of lengths of all extended attribute names belonging to | 348 | * @xattr_names: sum of lengths of all extended attribute names belonging to |
349 | * this inode | 349 | * this inode |
350 | * @dirty: non-zero if the inode is dirty | 350 | * @dirty: non-zero if the inode is dirty |
351 | * @xattr: non-zero if this is an extended attribute inode | 351 | * @xattr: non-zero if this is an extended attribute inode |
352 | * @bulk_read: non-zero if bulk-read should be used | 352 | * @bulk_read: non-zero if bulk-read should be used |
353 | * @ui_mutex: serializes inode write-back with the rest of VFS operations, | 353 | * @ui_mutex: serializes inode write-back with the rest of VFS operations, |
354 | * serializes "clean <-> dirty" state changes, serializes bulk-read, | 354 | * serializes "clean <-> dirty" state changes, serializes bulk-read, |
355 | * protects @dirty, @bulk_read, @ui_size, and @xattr_size | 355 | * protects @dirty, @bulk_read, @ui_size, and @xattr_size |
356 | * @ui_lock: protects @synced_i_size | 356 | * @ui_lock: protects @synced_i_size |
357 | * @synced_i_size: synchronized size of inode, i.e. the value of inode size | 357 | * @synced_i_size: synchronized size of inode, i.e. the value of inode size |
358 | * currently stored on the flash; used only for regular file | 358 | * currently stored on the flash; used only for regular file |
359 | * inodes | 359 | * inodes |
360 | * @ui_size: inode size used by UBIFS when writing to flash | 360 | * @ui_size: inode size used by UBIFS when writing to flash |
361 | * @flags: inode flags (@UBIFS_COMPR_FL, etc) | 361 | * @flags: inode flags (@UBIFS_COMPR_FL, etc) |
362 | * @compr_type: default compression type used for this inode | 362 | * @compr_type: default compression type used for this inode |
363 | * @last_page_read: page number of last page read (for bulk read) | 363 | * @last_page_read: page number of last page read (for bulk read) |
364 | * @read_in_a_row: number of consecutive pages read in a row (for bulk read) | 364 | * @read_in_a_row: number of consecutive pages read in a row (for bulk read) |
365 | * @data_len: length of the data attached to the inode | 365 | * @data_len: length of the data attached to the inode |
366 | * @data: inode's data | 366 | * @data: inode's data |
367 | * | 367 | * |
368 | * @ui_mutex exists for two main reasons. At first it prevents inodes from | 368 | * @ui_mutex exists for two main reasons. At first it prevents inodes from |
369 | * being written back while UBIFS changing them, being in the middle of an VFS | 369 | * being written back while UBIFS changing them, being in the middle of an VFS |
370 | * operation. This way UBIFS makes sure the inode fields are consistent. For | 370 | * operation. This way UBIFS makes sure the inode fields are consistent. For |
371 | * example, in 'ubifs_rename()' we change 3 inodes simultaneously, and | 371 | * example, in 'ubifs_rename()' we change 3 inodes simultaneously, and |
372 | * write-back must not write any of them before we have finished. | 372 | * write-back must not write any of them before we have finished. |
373 | * | 373 | * |
374 | * The second reason is budgeting - UBIFS has to budget all operations. If an | 374 | * The second reason is budgeting - UBIFS has to budget all operations. If an |
375 | * operation is going to mark an inode dirty, it has to allocate budget for | 375 | * operation is going to mark an inode dirty, it has to allocate budget for |
376 | * this. It cannot just mark it dirty because there is no guarantee there will | 376 | * this. It cannot just mark it dirty because there is no guarantee there will |
377 | * be enough flash space to write the inode back later. This means UBIFS has | 377 | * be enough flash space to write the inode back later. This means UBIFS has |
378 | * to have full control over inode "clean <-> dirty" transitions (and pages | 378 | * to have full control over inode "clean <-> dirty" transitions (and pages |
379 | * actually). But unfortunately, VFS marks inodes dirty in many places, and it | 379 | * actually). But unfortunately, VFS marks inodes dirty in many places, and it |
380 | * does not ask the file-system if it is allowed to do so (there is a notifier, | 380 | * does not ask the file-system if it is allowed to do so (there is a notifier, |
381 | * but it is not enough), i.e., there is no mechanism to synchronize with this. | 381 | * but it is not enough), i.e., there is no mechanism to synchronize with this. |
382 | * So UBIFS has its own inode dirty flag and its own mutex to serialize | 382 | * So UBIFS has its own inode dirty flag and its own mutex to serialize |
383 | * "clean <-> dirty" transitions. | 383 | * "clean <-> dirty" transitions. |
384 | * | 384 | * |
385 | * The @synced_i_size field is used to make sure we never write pages which are | 385 | * The @synced_i_size field is used to make sure we never write pages which are |
386 | * beyond last synchronized inode size. See 'ubifs_writepage()' for more | 386 | * beyond last synchronized inode size. See 'ubifs_writepage()' for more |
387 | * information. | 387 | * information. |
388 | * | 388 | * |
389 | * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses | 389 | * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses |
390 | * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot | 390 | * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot |
391 | * make sure @inode->i_size is always changed under @ui_mutex, because it | 391 | * make sure @inode->i_size is always changed under @ui_mutex, because it |
392 | * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would | 392 | * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would |
393 | * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields | 393 | * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields |
394 | * are changed under @ui_mutex, so they do not need "shadow" fields. Note, one | 394 | * are changed under @ui_mutex, so they do not need "shadow" fields. Note, one |
395 | * could consider to rework locking and base it on "shadow" fields. | 395 | * could consider to rework locking and base it on "shadow" fields. |
396 | */ | 396 | */ |
397 | struct ubifs_inode { | 397 | struct ubifs_inode { |
398 | struct inode vfs_inode; | 398 | struct inode vfs_inode; |
399 | unsigned long long creat_sqnum; | 399 | unsigned long long creat_sqnum; |
400 | unsigned long long del_cmtno; | 400 | unsigned long long del_cmtno; |
401 | unsigned int xattr_size; | 401 | unsigned int xattr_size; |
402 | unsigned int xattr_cnt; | 402 | unsigned int xattr_cnt; |
403 | unsigned int xattr_names; | 403 | unsigned int xattr_names; |
404 | unsigned int dirty:1; | 404 | unsigned int dirty:1; |
405 | unsigned int xattr:1; | 405 | unsigned int xattr:1; |
406 | unsigned int bulk_read:1; | 406 | unsigned int bulk_read:1; |
407 | unsigned int compr_type:2; | 407 | unsigned int compr_type:2; |
408 | struct mutex ui_mutex; | 408 | struct mutex ui_mutex; |
409 | spinlock_t ui_lock; | 409 | spinlock_t ui_lock; |
410 | loff_t synced_i_size; | 410 | loff_t synced_i_size; |
411 | loff_t ui_size; | 411 | loff_t ui_size; |
412 | int flags; | 412 | int flags; |
413 | pgoff_t last_page_read; | 413 | pgoff_t last_page_read; |
414 | pgoff_t read_in_a_row; | 414 | pgoff_t read_in_a_row; |
415 | int data_len; | 415 | int data_len; |
416 | void *data; | 416 | void *data; |
417 | }; | 417 | }; |
418 | 418 | ||
419 | /** | 419 | /** |
420 | * struct ubifs_unclean_leb - records a LEB recovered under read-only mode. | 420 | * struct ubifs_unclean_leb - records a LEB recovered under read-only mode. |
421 | * @list: list | 421 | * @list: list |
422 | * @lnum: LEB number of recovered LEB | 422 | * @lnum: LEB number of recovered LEB |
423 | * @endpt: offset where recovery ended | 423 | * @endpt: offset where recovery ended |
424 | * | 424 | * |
425 | * This structure records a LEB identified during recovery that needs to be | 425 | * This structure records a LEB identified during recovery that needs to be |
426 | * cleaned but was not because UBIFS was mounted read-only. The information | 426 | * cleaned but was not because UBIFS was mounted read-only. The information |
427 | * is used to clean the LEB when remounting to read-write mode. | 427 | * is used to clean the LEB when remounting to read-write mode. |
428 | */ | 428 | */ |
429 | struct ubifs_unclean_leb { | 429 | struct ubifs_unclean_leb { |
430 | struct list_head list; | 430 | struct list_head list; |
431 | int lnum; | 431 | int lnum; |
432 | int endpt; | 432 | int endpt; |
433 | }; | 433 | }; |
434 | 434 | ||
435 | /* | 435 | /* |
436 | * LEB properties flags. | 436 | * LEB properties flags. |
437 | * | 437 | * |
438 | * LPROPS_UNCAT: not categorized | 438 | * LPROPS_UNCAT: not categorized |
439 | * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index | 439 | * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index |
440 | * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index | 440 | * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index |
441 | * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index | 441 | * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index |
442 | * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs | 442 | * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs |
443 | * LPROPS_EMPTY: LEB is empty, not taken | 443 | * LPROPS_EMPTY: LEB is empty, not taken |
444 | * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken | 444 | * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken |
445 | * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken | 445 | * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken |
446 | * LPROPS_CAT_MASK: mask for the LEB categories above | 446 | * LPROPS_CAT_MASK: mask for the LEB categories above |
447 | * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media) | 447 | * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media) |
448 | * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash) | 448 | * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash) |
449 | */ | 449 | */ |
450 | enum { | 450 | enum { |
451 | LPROPS_UNCAT = 0, | 451 | LPROPS_UNCAT = 0, |
452 | LPROPS_DIRTY = 1, | 452 | LPROPS_DIRTY = 1, |
453 | LPROPS_DIRTY_IDX = 2, | 453 | LPROPS_DIRTY_IDX = 2, |
454 | LPROPS_FREE = 3, | 454 | LPROPS_FREE = 3, |
455 | LPROPS_HEAP_CNT = 3, | 455 | LPROPS_HEAP_CNT = 3, |
456 | LPROPS_EMPTY = 4, | 456 | LPROPS_EMPTY = 4, |
457 | LPROPS_FREEABLE = 5, | 457 | LPROPS_FREEABLE = 5, |
458 | LPROPS_FRDI_IDX = 6, | 458 | LPROPS_FRDI_IDX = 6, |
459 | LPROPS_CAT_MASK = 15, | 459 | LPROPS_CAT_MASK = 15, |
460 | LPROPS_TAKEN = 16, | 460 | LPROPS_TAKEN = 16, |
461 | LPROPS_INDEX = 32, | 461 | LPROPS_INDEX = 32, |
462 | }; | 462 | }; |
463 | 463 | ||
464 | /** | 464 | /** |
465 | * struct ubifs_lprops - logical eraseblock properties. | 465 | * struct ubifs_lprops - logical eraseblock properties. |
466 | * @free: amount of free space in bytes | 466 | * @free: amount of free space in bytes |
467 | * @dirty: amount of dirty space in bytes | 467 | * @dirty: amount of dirty space in bytes |
468 | * @flags: LEB properties flags (see above) | 468 | * @flags: LEB properties flags (see above) |
469 | * @lnum: LEB number | 469 | * @lnum: LEB number |
470 | * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE) | 470 | * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE) |
471 | * @hpos: heap position in heap of same-category lprops (other categories) | 471 | * @hpos: heap position in heap of same-category lprops (other categories) |
472 | */ | 472 | */ |
473 | struct ubifs_lprops { | 473 | struct ubifs_lprops { |
474 | int free; | 474 | int free; |
475 | int dirty; | 475 | int dirty; |
476 | int flags; | 476 | int flags; |
477 | int lnum; | 477 | int lnum; |
478 | union { | 478 | union { |
479 | struct list_head list; | 479 | struct list_head list; |
480 | int hpos; | 480 | int hpos; |
481 | }; | 481 | }; |
482 | }; | 482 | }; |
483 | 483 | ||
484 | /** | 484 | /** |
485 | * struct ubifs_lpt_lprops - LPT logical eraseblock properties. | 485 | * struct ubifs_lpt_lprops - LPT logical eraseblock properties. |
486 | * @free: amount of free space in bytes | 486 | * @free: amount of free space in bytes |
487 | * @dirty: amount of dirty space in bytes | 487 | * @dirty: amount of dirty space in bytes |
488 | * @tgc: trivial GC flag (1 => unmap after commit end) | 488 | * @tgc: trivial GC flag (1 => unmap after commit end) |
489 | * @cmt: commit flag (1 => reserved for commit) | 489 | * @cmt: commit flag (1 => reserved for commit) |
490 | */ | 490 | */ |
491 | struct ubifs_lpt_lprops { | 491 | struct ubifs_lpt_lprops { |
492 | int free; | 492 | int free; |
493 | int dirty; | 493 | int dirty; |
494 | unsigned tgc:1; | 494 | unsigned tgc:1; |
495 | unsigned cmt:1; | 495 | unsigned cmt:1; |
496 | }; | 496 | }; |
497 | 497 | ||
498 | /** | 498 | /** |
499 | * struct ubifs_lp_stats - statistics of eraseblocks in the main area. | 499 | * struct ubifs_lp_stats - statistics of eraseblocks in the main area. |
500 | * @empty_lebs: number of empty LEBs | 500 | * @empty_lebs: number of empty LEBs |
501 | * @taken_empty_lebs: number of taken LEBs | 501 | * @taken_empty_lebs: number of taken LEBs |
502 | * @idx_lebs: number of indexing LEBs | 502 | * @idx_lebs: number of indexing LEBs |
503 | * @total_free: total free space in bytes (includes all LEBs) | 503 | * @total_free: total free space in bytes (includes all LEBs) |
504 | * @total_dirty: total dirty space in bytes (includes all LEBs) | 504 | * @total_dirty: total dirty space in bytes (includes all LEBs) |
505 | * @total_used: total used space in bytes (does not include index LEBs) | 505 | * @total_used: total used space in bytes (does not include index LEBs) |
506 | * @total_dead: total dead space in bytes (does not include index LEBs) | 506 | * @total_dead: total dead space in bytes (does not include index LEBs) |
507 | * @total_dark: total dark space in bytes (does not include index LEBs) | 507 | * @total_dark: total dark space in bytes (does not include index LEBs) |
508 | * | 508 | * |
509 | * The @taken_empty_lebs field counts the LEBs that are in the transient state | 509 | * The @taken_empty_lebs field counts the LEBs that are in the transient state |
510 | * of having been "taken" for use but not yet written to. @taken_empty_lebs is | 510 | * of having been "taken" for use but not yet written to. @taken_empty_lebs is |
511 | * needed to account correctly for @gc_lnum, otherwise @empty_lebs could be | 511 | * needed to account correctly for @gc_lnum, otherwise @empty_lebs could be |
512 | * used by itself (in which case 'unused_lebs' would be a better name). In the | 512 | * used by itself (in which case 'unused_lebs' would be a better name). In the |
513 | * case of @gc_lnum, it is "taken" at mount time or whenever a LEB is retained | 513 | * case of @gc_lnum, it is "taken" at mount time or whenever a LEB is retained |
514 | * by GC, but unlike other empty LEBs that are "taken", it may not be written | 514 | * by GC, but unlike other empty LEBs that are "taken", it may not be written |
515 | * straight away (i.e. before the next commit start or unmount), so either | 515 | * straight away (i.e. before the next commit start or unmount), so either |
516 | * @gc_lnum must be specially accounted for, or the current approach followed | 516 | * @gc_lnum must be specially accounted for, or the current approach followed |
517 | * i.e. count it under @taken_empty_lebs. | 517 | * i.e. count it under @taken_empty_lebs. |
518 | * | 518 | * |
519 | * @empty_lebs includes @taken_empty_lebs. | 519 | * @empty_lebs includes @taken_empty_lebs. |
520 | * | 520 | * |
521 | * @total_used, @total_dead and @total_dark fields do not account indexing | 521 | * @total_used, @total_dead and @total_dark fields do not account indexing |
522 | * LEBs. | 522 | * LEBs. |
523 | */ | 523 | */ |
524 | struct ubifs_lp_stats { | 524 | struct ubifs_lp_stats { |
525 | int empty_lebs; | 525 | int empty_lebs; |
526 | int taken_empty_lebs; | 526 | int taken_empty_lebs; |
527 | int idx_lebs; | 527 | int idx_lebs; |
528 | long long total_free; | 528 | long long total_free; |
529 | long long total_dirty; | 529 | long long total_dirty; |
530 | long long total_used; | 530 | long long total_used; |
531 | long long total_dead; | 531 | long long total_dead; |
532 | long long total_dark; | 532 | long long total_dark; |
533 | }; | 533 | }; |
534 | 534 | ||
535 | struct ubifs_nnode; | 535 | struct ubifs_nnode; |
536 | 536 | ||
537 | /** | 537 | /** |
538 | * struct ubifs_cnode - LEB Properties Tree common node. | 538 | * struct ubifs_cnode - LEB Properties Tree common node. |
539 | * @parent: parent nnode | 539 | * @parent: parent nnode |
540 | * @cnext: next cnode to commit | 540 | * @cnext: next cnode to commit |
541 | * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) | 541 | * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) |
542 | * @iip: index in parent | 542 | * @iip: index in parent |
543 | * @level: level in the tree (zero for pnodes, greater than zero for nnodes) | 543 | * @level: level in the tree (zero for pnodes, greater than zero for nnodes) |
544 | * @num: node number | 544 | * @num: node number |
545 | */ | 545 | */ |
546 | struct ubifs_cnode { | 546 | struct ubifs_cnode { |
547 | struct ubifs_nnode *parent; | 547 | struct ubifs_nnode *parent; |
548 | struct ubifs_cnode *cnext; | 548 | struct ubifs_cnode *cnext; |
549 | unsigned long flags; | 549 | unsigned long flags; |
550 | int iip; | 550 | int iip; |
551 | int level; | 551 | int level; |
552 | int num; | 552 | int num; |
553 | }; | 553 | }; |
554 | 554 | ||
555 | /** | 555 | /** |
556 | * struct ubifs_pnode - LEB Properties Tree leaf node. | 556 | * struct ubifs_pnode - LEB Properties Tree leaf node. |
557 | * @parent: parent nnode | 557 | * @parent: parent nnode |
558 | * @cnext: next cnode to commit | 558 | * @cnext: next cnode to commit |
559 | * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) | 559 | * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) |
560 | * @iip: index in parent | 560 | * @iip: index in parent |
561 | * @level: level in the tree (always zero for pnodes) | 561 | * @level: level in the tree (always zero for pnodes) |
562 | * @num: node number | 562 | * @num: node number |
563 | * @lprops: LEB properties array | 563 | * @lprops: LEB properties array |
564 | */ | 564 | */ |
565 | struct ubifs_pnode { | 565 | struct ubifs_pnode { |
566 | struct ubifs_nnode *parent; | 566 | struct ubifs_nnode *parent; |
567 | struct ubifs_cnode *cnext; | 567 | struct ubifs_cnode *cnext; |
568 | unsigned long flags; | 568 | unsigned long flags; |
569 | int iip; | 569 | int iip; |
570 | int level; | 570 | int level; |
571 | int num; | 571 | int num; |
572 | struct ubifs_lprops lprops[UBIFS_LPT_FANOUT]; | 572 | struct ubifs_lprops lprops[UBIFS_LPT_FANOUT]; |
573 | }; | 573 | }; |
574 | 574 | ||
575 | /** | 575 | /** |
576 | * struct ubifs_nbranch - LEB Properties Tree internal node branch. | 576 | * struct ubifs_nbranch - LEB Properties Tree internal node branch. |
577 | * @lnum: LEB number of child | 577 | * @lnum: LEB number of child |
578 | * @offs: offset of child | 578 | * @offs: offset of child |
579 | * @nnode: nnode child | 579 | * @nnode: nnode child |
580 | * @pnode: pnode child | 580 | * @pnode: pnode child |
581 | * @cnode: cnode child | 581 | * @cnode: cnode child |
582 | */ | 582 | */ |
583 | struct ubifs_nbranch { | 583 | struct ubifs_nbranch { |
584 | int lnum; | 584 | int lnum; |
585 | int offs; | 585 | int offs; |
586 | union { | 586 | union { |
587 | struct ubifs_nnode *nnode; | 587 | struct ubifs_nnode *nnode; |
588 | struct ubifs_pnode *pnode; | 588 | struct ubifs_pnode *pnode; |
589 | struct ubifs_cnode *cnode; | 589 | struct ubifs_cnode *cnode; |
590 | }; | 590 | }; |
591 | }; | 591 | }; |
592 | 592 | ||
593 | /** | 593 | /** |
594 | * struct ubifs_nnode - LEB Properties Tree internal node. | 594 | * struct ubifs_nnode - LEB Properties Tree internal node. |
595 | * @parent: parent nnode | 595 | * @parent: parent nnode |
596 | * @cnext: next cnode to commit | 596 | * @cnext: next cnode to commit |
597 | * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) | 597 | * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) |
598 | * @iip: index in parent | 598 | * @iip: index in parent |
599 | * @level: level in the tree (always greater than zero for nnodes) | 599 | * @level: level in the tree (always greater than zero for nnodes) |
600 | * @num: node number | 600 | * @num: node number |
601 | * @nbranch: branches to child nodes | 601 | * @nbranch: branches to child nodes |
602 | */ | 602 | */ |
603 | struct ubifs_nnode { | 603 | struct ubifs_nnode { |
604 | struct ubifs_nnode *parent; | 604 | struct ubifs_nnode *parent; |
605 | struct ubifs_cnode *cnext; | 605 | struct ubifs_cnode *cnext; |
606 | unsigned long flags; | 606 | unsigned long flags; |
607 | int iip; | 607 | int iip; |
608 | int level; | 608 | int level; |
609 | int num; | 609 | int num; |
610 | struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT]; | 610 | struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT]; |
611 | }; | 611 | }; |
612 | 612 | ||
613 | /** | 613 | /** |
614 | * struct ubifs_lpt_heap - heap of categorized lprops. | 614 | * struct ubifs_lpt_heap - heap of categorized lprops. |
615 | * @arr: heap array | 615 | * @arr: heap array |
616 | * @cnt: number in heap | 616 | * @cnt: number in heap |
617 | * @max_cnt: maximum number allowed in heap | 617 | * @max_cnt: maximum number allowed in heap |
618 | * | 618 | * |
619 | * There are %LPROPS_HEAP_CNT heaps. | 619 | * There are %LPROPS_HEAP_CNT heaps. |
620 | */ | 620 | */ |
621 | struct ubifs_lpt_heap { | 621 | struct ubifs_lpt_heap { |
622 | struct ubifs_lprops **arr; | 622 | struct ubifs_lprops **arr; |
623 | int cnt; | 623 | int cnt; |
624 | int max_cnt; | 624 | int max_cnt; |
625 | }; | 625 | }; |
626 | 626 | ||
627 | /* | 627 | /* |
628 | * Return codes for LPT scan callback function. | 628 | * Return codes for LPT scan callback function. |
629 | * | 629 | * |
630 | * LPT_SCAN_CONTINUE: continue scanning | 630 | * LPT_SCAN_CONTINUE: continue scanning |
631 | * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory | 631 | * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory |
632 | * LPT_SCAN_STOP: stop scanning | 632 | * LPT_SCAN_STOP: stop scanning |
633 | */ | 633 | */ |
634 | enum { | 634 | enum { |
635 | LPT_SCAN_CONTINUE = 0, | 635 | LPT_SCAN_CONTINUE = 0, |
636 | LPT_SCAN_ADD = 1, | 636 | LPT_SCAN_ADD = 1, |
637 | LPT_SCAN_STOP = 2, | 637 | LPT_SCAN_STOP = 2, |
638 | }; | 638 | }; |
639 | 639 | ||
640 | struct ubifs_info; | 640 | struct ubifs_info; |
641 | 641 | ||
642 | /* Callback used by the 'ubifs_lpt_scan_nolock()' function */ | 642 | /* Callback used by the 'ubifs_lpt_scan_nolock()' function */ |
643 | typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c, | 643 | typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c, |
644 | const struct ubifs_lprops *lprops, | 644 | const struct ubifs_lprops *lprops, |
645 | int in_tree, void *data); | 645 | int in_tree, void *data); |
646 | 646 | ||
647 | /** | 647 | /** |
648 | * struct ubifs_wbuf - UBIFS write-buffer. | 648 | * struct ubifs_wbuf - UBIFS write-buffer. |
649 | * @c: UBIFS file-system description object | 649 | * @c: UBIFS file-system description object |
650 | * @buf: write-buffer (of min. flash I/O unit size) | 650 | * @buf: write-buffer (of min. flash I/O unit size) |
651 | * @lnum: logical eraseblock number the write-buffer points to | 651 | * @lnum: logical eraseblock number the write-buffer points to |
652 | * @offs: write-buffer offset in this logical eraseblock | 652 | * @offs: write-buffer offset in this logical eraseblock |
653 | * @avail: number of bytes available in the write-buffer | 653 | * @avail: number of bytes available in the write-buffer |
654 | * @used: number of used bytes in the write-buffer | 654 | * @used: number of used bytes in the write-buffer |
655 | * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range) | 655 | * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range) |
656 | * @dtype: type of data stored in this LEB (%UBI_LONGTERM, %UBI_SHORTTERM, | 656 | * @dtype: type of data stored in this LEB (%UBI_LONGTERM, %UBI_SHORTTERM, |
657 | * %UBI_UNKNOWN) | 657 | * %UBI_UNKNOWN) |
658 | * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep | 658 | * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep |
659 | * up by 'mutex_lock_nested()). | 659 | * up by 'mutex_lock_nested()). |
660 | * @sync_callback: write-buffer synchronization callback | 660 | * @sync_callback: write-buffer synchronization callback |
661 | * @io_mutex: serializes write-buffer I/O | 661 | * @io_mutex: serializes write-buffer I/O |
662 | * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes | 662 | * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes |
663 | * fields | 663 | * fields |
664 | * @softlimit: soft write-buffer timeout interval | 664 | * @softlimit: soft write-buffer timeout interval |
665 | * @delta: hard and soft timeouts delta (the timer expire inteval is @softlimit | 665 | * @delta: hard and soft timeouts delta (the timer expire inteval is @softlimit |
666 | * and @softlimit + @delta) | 666 | * and @softlimit + @delta) |
667 | * @timer: write-buffer timer | 667 | * @timer: write-buffer timer |
668 | * @no_timer: non-zero if this write-buffer does not have a timer | 668 | * @no_timer: non-zero if this write-buffer does not have a timer |
669 | * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing | 669 | * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing |
670 | * @next_ino: points to the next position of the following inode number | 670 | * @next_ino: points to the next position of the following inode number |
671 | * @inodes: stores the inode numbers of the nodes which are in wbuf | 671 | * @inodes: stores the inode numbers of the nodes which are in wbuf |
672 | * | 672 | * |
673 | * The write-buffer synchronization callback is called when the write-buffer is | 673 | * The write-buffer synchronization callback is called when the write-buffer is |
674 | * synchronized in order to notify how much space was wasted due to | 674 | * synchronized in order to notify how much space was wasted due to |
675 | * write-buffer padding and how much free space is left in the LEB. | 675 | * write-buffer padding and how much free space is left in the LEB. |
676 | * | 676 | * |
677 | * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under | 677 | * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under |
678 | * spin-lock or mutex because they are written under both mutex and spin-lock. | 678 | * spin-lock or mutex because they are written under both mutex and spin-lock. |
679 | * @buf is appended to under mutex but overwritten under both mutex and | 679 | * @buf is appended to under mutex but overwritten under both mutex and |
680 | * spin-lock. Thus the data between @buf and @buf + @used can be read under | 680 | * spin-lock. Thus the data between @buf and @buf + @used can be read under |
681 | * spinlock. | 681 | * spinlock. |
682 | */ | 682 | */ |
683 | struct ubifs_wbuf { | 683 | struct ubifs_wbuf { |
684 | struct ubifs_info *c; | 684 | struct ubifs_info *c; |
685 | void *buf; | 685 | void *buf; |
686 | int lnum; | 686 | int lnum; |
687 | int offs; | 687 | int offs; |
688 | int avail; | 688 | int avail; |
689 | int used; | 689 | int used; |
690 | int size; | 690 | int size; |
691 | int dtype; | 691 | int dtype; |
692 | int jhead; | 692 | int jhead; |
693 | int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad); | 693 | int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad); |
694 | struct mutex io_mutex; | 694 | struct mutex io_mutex; |
695 | spinlock_t lock; | 695 | spinlock_t lock; |
696 | ktime_t softlimit; | 696 | ktime_t softlimit; |
697 | unsigned long long delta; | 697 | unsigned long long delta; |
698 | struct hrtimer timer; | 698 | struct hrtimer timer; |
699 | unsigned int no_timer:1; | 699 | unsigned int no_timer:1; |
700 | unsigned int need_sync:1; | 700 | unsigned int need_sync:1; |
701 | int next_ino; | 701 | int next_ino; |
702 | ino_t *inodes; | 702 | ino_t *inodes; |
703 | }; | 703 | }; |
704 | 704 | ||
705 | /** | 705 | /** |
706 | * struct ubifs_bud - bud logical eraseblock. | 706 | * struct ubifs_bud - bud logical eraseblock. |
707 | * @lnum: logical eraseblock number | 707 | * @lnum: logical eraseblock number |
708 | * @start: where the (uncommitted) bud data starts | 708 | * @start: where the (uncommitted) bud data starts |
709 | * @jhead: journal head number this bud belongs to | 709 | * @jhead: journal head number this bud belongs to |
710 | * @list: link in the list buds belonging to the same journal head | 710 | * @list: link in the list buds belonging to the same journal head |
711 | * @rb: link in the tree of all buds | 711 | * @rb: link in the tree of all buds |
712 | */ | 712 | */ |
713 | struct ubifs_bud { | 713 | struct ubifs_bud { |
714 | int lnum; | 714 | int lnum; |
715 | int start; | 715 | int start; |
716 | int jhead; | 716 | int jhead; |
717 | struct list_head list; | 717 | struct list_head list; |
718 | struct rb_node rb; | 718 | struct rb_node rb; |
719 | }; | 719 | }; |
720 | 720 | ||
721 | /** | 721 | /** |
722 | * struct ubifs_jhead - journal head. | 722 | * struct ubifs_jhead - journal head. |
723 | * @wbuf: head's write-buffer | 723 | * @wbuf: head's write-buffer |
724 | * @buds_list: list of bud LEBs belonging to this journal head | 724 | * @buds_list: list of bud LEBs belonging to this journal head |
725 | * | 725 | * |
726 | * Note, the @buds list is protected by the @c->buds_lock. | 726 | * Note, the @buds list is protected by the @c->buds_lock. |
727 | */ | 727 | */ |
728 | struct ubifs_jhead { | 728 | struct ubifs_jhead { |
729 | struct ubifs_wbuf wbuf; | 729 | struct ubifs_wbuf wbuf; |
730 | struct list_head buds_list; | 730 | struct list_head buds_list; |
731 | }; | 731 | }; |
732 | 732 | ||
733 | /** | 733 | /** |
734 | * struct ubifs_zbranch - key/coordinate/length branch stored in znodes. | 734 | * struct ubifs_zbranch - key/coordinate/length branch stored in znodes. |
735 | * @key: key | 735 | * @key: key |
736 | * @znode: znode address in memory | 736 | * @znode: znode address in memory |
737 | * @lnum: LEB number of the target node (indexing node or data node) | 737 | * @lnum: LEB number of the target node (indexing node or data node) |
738 | * @offs: target node offset within @lnum | 738 | * @offs: target node offset within @lnum |
739 | * @len: target node length | 739 | * @len: target node length |
740 | */ | 740 | */ |
741 | struct ubifs_zbranch { | 741 | struct ubifs_zbranch { |
742 | union ubifs_key key; | 742 | union ubifs_key key; |
743 | union { | 743 | union { |
744 | struct ubifs_znode *znode; | 744 | struct ubifs_znode *znode; |
745 | void *leaf; | 745 | void *leaf; |
746 | }; | 746 | }; |
747 | int lnum; | 747 | int lnum; |
748 | int offs; | 748 | int offs; |
749 | int len; | 749 | int len; |
750 | }; | 750 | }; |
751 | 751 | ||
752 | /** | 752 | /** |
753 | * struct ubifs_znode - in-memory representation of an indexing node. | 753 | * struct ubifs_znode - in-memory representation of an indexing node. |
754 | * @parent: parent znode or NULL if it is the root | 754 | * @parent: parent znode or NULL if it is the root |
755 | * @cnext: next znode to commit | 755 | * @cnext: next znode to commit |
756 | * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE) | 756 | * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE) |
757 | * @time: last access time (seconds) | 757 | * @time: last access time (seconds) |
758 | * @level: level of the entry in the TNC tree | 758 | * @level: level of the entry in the TNC tree |
759 | * @child_cnt: count of child znodes | 759 | * @child_cnt: count of child znodes |
760 | * @iip: index in parent's zbranch array | 760 | * @iip: index in parent's zbranch array |
761 | * @alt: lower bound of key range has altered i.e. child inserted at slot 0 | 761 | * @alt: lower bound of key range has altered i.e. child inserted at slot 0 |
762 | * @lnum: LEB number of the corresponding indexing node | 762 | * @lnum: LEB number of the corresponding indexing node |
763 | * @offs: offset of the corresponding indexing node | 763 | * @offs: offset of the corresponding indexing node |
764 | * @len: length of the corresponding indexing node | 764 | * @len: length of the corresponding indexing node |
765 | * @zbranch: array of znode branches (@c->fanout elements) | 765 | * @zbranch: array of znode branches (@c->fanout elements) |
766 | */ | 766 | */ |
767 | struct ubifs_znode { | 767 | struct ubifs_znode { |
768 | struct ubifs_znode *parent; | 768 | struct ubifs_znode *parent; |
769 | struct ubifs_znode *cnext; | 769 | struct ubifs_znode *cnext; |
770 | unsigned long flags; | 770 | unsigned long flags; |
771 | unsigned long time; | 771 | unsigned long time; |
772 | int level; | 772 | int level; |
773 | int child_cnt; | 773 | int child_cnt; |
774 | int iip; | 774 | int iip; |
775 | int alt; | 775 | int alt; |
776 | #ifdef CONFIG_UBIFS_FS_DEBUG | 776 | #ifdef CONFIG_UBIFS_FS_DEBUG |
777 | int lnum, offs, len; | 777 | int lnum, offs, len; |
778 | #endif | 778 | #endif |
779 | struct ubifs_zbranch zbranch[]; | 779 | struct ubifs_zbranch zbranch[]; |
780 | }; | 780 | }; |
781 | 781 | ||
782 | /** | 782 | /** |
783 | * struct bu_info - bulk-read information. | 783 | * struct bu_info - bulk-read information. |
784 | * @key: first data node key | 784 | * @key: first data node key |
785 | * @zbranch: zbranches of data nodes to bulk read | 785 | * @zbranch: zbranches of data nodes to bulk read |
786 | * @buf: buffer to read into | 786 | * @buf: buffer to read into |
787 | * @buf_len: buffer length | 787 | * @buf_len: buffer length |
788 | * @gc_seq: GC sequence number to detect races with GC | 788 | * @gc_seq: GC sequence number to detect races with GC |
789 | * @cnt: number of data nodes for bulk read | 789 | * @cnt: number of data nodes for bulk read |
790 | * @blk_cnt: number of data blocks including holes | 790 | * @blk_cnt: number of data blocks including holes |
791 | * @oef: end of file reached | 791 | * @oef: end of file reached |
792 | */ | 792 | */ |
793 | struct bu_info { | 793 | struct bu_info { |
794 | union ubifs_key key; | 794 | union ubifs_key key; |
795 | struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ]; | 795 | struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ]; |
796 | void *buf; | 796 | void *buf; |
797 | int buf_len; | 797 | int buf_len; |
798 | int gc_seq; | 798 | int gc_seq; |
799 | int cnt; | 799 | int cnt; |
800 | int blk_cnt; | 800 | int blk_cnt; |
801 | int eof; | 801 | int eof; |
802 | }; | 802 | }; |
803 | 803 | ||
804 | /** | 804 | /** |
805 | * struct ubifs_node_range - node length range description data structure. | 805 | * struct ubifs_node_range - node length range description data structure. |
806 | * @len: fixed node length | 806 | * @len: fixed node length |
807 | * @min_len: minimum possible node length | 807 | * @min_len: minimum possible node length |
808 | * @max_len: maximum possible node length | 808 | * @max_len: maximum possible node length |
809 | * | 809 | * |
810 | * If @max_len is %0, the node has fixed length @len. | 810 | * If @max_len is %0, the node has fixed length @len. |
811 | */ | 811 | */ |
812 | struct ubifs_node_range { | 812 | struct ubifs_node_range { |
813 | union { | 813 | union { |
814 | int len; | 814 | int len; |
815 | int min_len; | 815 | int min_len; |
816 | }; | 816 | }; |
817 | int max_len; | 817 | int max_len; |
818 | }; | 818 | }; |
819 | 819 | ||
820 | /** | 820 | /** |
821 | * struct ubifs_compressor - UBIFS compressor description structure. | 821 | * struct ubifs_compressor - UBIFS compressor description structure. |
822 | * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc) | 822 | * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc) |
823 | * @cc: cryptoapi compressor handle | 823 | * @cc: cryptoapi compressor handle |
824 | * @comp_mutex: mutex used during compression | 824 | * @comp_mutex: mutex used during compression |
825 | * @decomp_mutex: mutex used during decompression | 825 | * @decomp_mutex: mutex used during decompression |
826 | * @name: compressor name | 826 | * @name: compressor name |
827 | * @capi_name: cryptoapi compressor name | 827 | * @capi_name: cryptoapi compressor name |
828 | */ | 828 | */ |
829 | struct ubifs_compressor { | 829 | struct ubifs_compressor { |
830 | int compr_type; | 830 | int compr_type; |
831 | struct crypto_comp *cc; | 831 | struct crypto_comp *cc; |
832 | struct mutex *comp_mutex; | 832 | struct mutex *comp_mutex; |
833 | struct mutex *decomp_mutex; | 833 | struct mutex *decomp_mutex; |
834 | const char *name; | 834 | const char *name; |
835 | const char *capi_name; | 835 | const char *capi_name; |
836 | }; | 836 | }; |
837 | 837 | ||
838 | /** | 838 | /** |
839 | * struct ubifs_budget_req - budget requirements of an operation. | 839 | * struct ubifs_budget_req - budget requirements of an operation. |
840 | * | 840 | * |
841 | * @fast: non-zero if the budgeting should try to acquire budget quickly and | 841 | * @fast: non-zero if the budgeting should try to acquire budget quickly and |
842 | * should not try to call write-back | 842 | * should not try to call write-back |
843 | * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields | 843 | * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields |
844 | * have to be re-calculated | 844 | * have to be re-calculated |
845 | * @new_page: non-zero if the operation adds a new page | 845 | * @new_page: non-zero if the operation adds a new page |
846 | * @dirtied_page: non-zero if the operation makes a page dirty | 846 | * @dirtied_page: non-zero if the operation makes a page dirty |
847 | * @new_dent: non-zero if the operation adds a new directory entry | 847 | * @new_dent: non-zero if the operation adds a new directory entry |
848 | * @mod_dent: non-zero if the operation removes or modifies an existing | 848 | * @mod_dent: non-zero if the operation removes or modifies an existing |
849 | * directory entry | 849 | * directory entry |
850 | * @new_ino: non-zero if the operation adds a new inode | 850 | * @new_ino: non-zero if the operation adds a new inode |
851 | * @new_ino_d: now much data newly created inode contains | 851 | * @new_ino_d: now much data newly created inode contains |
852 | * @dirtied_ino: how many inodes the operation makes dirty | 852 | * @dirtied_ino: how many inodes the operation makes dirty |
853 | * @dirtied_ino_d: now much data dirtied inode contains | 853 | * @dirtied_ino_d: now much data dirtied inode contains |
854 | * @idx_growth: how much the index will supposedly grow | 854 | * @idx_growth: how much the index will supposedly grow |
855 | * @data_growth: how much new data the operation will supposedly add | 855 | * @data_growth: how much new data the operation will supposedly add |
856 | * @dd_growth: how much data that makes other data dirty the operation will | 856 | * @dd_growth: how much data that makes other data dirty the operation will |
857 | * supposedly add | 857 | * supposedly add |
858 | * | 858 | * |
859 | * @idx_growth, @data_growth and @dd_growth are not used in budget request. The | 859 | * @idx_growth, @data_growth and @dd_growth are not used in budget request. The |
860 | * budgeting subsystem caches index and data growth values there to avoid | 860 | * budgeting subsystem caches index and data growth values there to avoid |
861 | * re-calculating them when the budget is released. However, if @idx_growth is | 861 | * re-calculating them when the budget is released. However, if @idx_growth is |
862 | * %-1, it is calculated by the release function using other fields. | 862 | * %-1, it is calculated by the release function using other fields. |
863 | * | 863 | * |
864 | * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d | 864 | * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d |
865 | * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made | 865 | * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made |
866 | * dirty by the re-name operation. | 866 | * dirty by the re-name operation. |
867 | * | 867 | * |
868 | * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to | 868 | * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to |
869 | * make sure the amount of inode data which contribute to @new_ino_d and | 869 | * make sure the amount of inode data which contribute to @new_ino_d and |
870 | * @dirtied_ino_d fields are aligned. | 870 | * @dirtied_ino_d fields are aligned. |
871 | */ | 871 | */ |
872 | struct ubifs_budget_req { | 872 | struct ubifs_budget_req { |
873 | unsigned int fast:1; | 873 | unsigned int fast:1; |
874 | unsigned int recalculate:1; | 874 | unsigned int recalculate:1; |
875 | #ifndef UBIFS_DEBUG | 875 | #ifndef UBIFS_DEBUG |
876 | unsigned int new_page:1; | 876 | unsigned int new_page:1; |
877 | unsigned int dirtied_page:1; | 877 | unsigned int dirtied_page:1; |
878 | unsigned int new_dent:1; | 878 | unsigned int new_dent:1; |
879 | unsigned int mod_dent:1; | 879 | unsigned int mod_dent:1; |
880 | unsigned int new_ino:1; | 880 | unsigned int new_ino:1; |
881 | unsigned int new_ino_d:13; | 881 | unsigned int new_ino_d:13; |
882 | unsigned int dirtied_ino:4; | 882 | unsigned int dirtied_ino:4; |
883 | unsigned int dirtied_ino_d:15; | 883 | unsigned int dirtied_ino_d:15; |
884 | #else | 884 | #else |
885 | /* Not bit-fields to check for overflows */ | 885 | /* Not bit-fields to check for overflows */ |
886 | unsigned int new_page; | 886 | unsigned int new_page; |
887 | unsigned int dirtied_page; | 887 | unsigned int dirtied_page; |
888 | unsigned int new_dent; | 888 | unsigned int new_dent; |
889 | unsigned int mod_dent; | 889 | unsigned int mod_dent; |
890 | unsigned int new_ino; | 890 | unsigned int new_ino; |
891 | unsigned int new_ino_d; | 891 | unsigned int new_ino_d; |
892 | unsigned int dirtied_ino; | 892 | unsigned int dirtied_ino; |
893 | unsigned int dirtied_ino_d; | 893 | unsigned int dirtied_ino_d; |
894 | #endif | 894 | #endif |
895 | int idx_growth; | 895 | int idx_growth; |
896 | int data_growth; | 896 | int data_growth; |
897 | int dd_growth; | 897 | int dd_growth; |
898 | }; | 898 | }; |
899 | 899 | ||
900 | /** | 900 | /** |
901 | * struct ubifs_orphan - stores the inode number of an orphan. | 901 | * struct ubifs_orphan - stores the inode number of an orphan. |
902 | * @rb: rb-tree node of rb-tree of orphans sorted by inode number | 902 | * @rb: rb-tree node of rb-tree of orphans sorted by inode number |
903 | * @list: list head of list of orphans in order added | 903 | * @list: list head of list of orphans in order added |
904 | * @new_list: list head of list of orphans added since the last commit | 904 | * @new_list: list head of list of orphans added since the last commit |
905 | * @cnext: next orphan to commit | 905 | * @cnext: next orphan to commit |
906 | * @dnext: next orphan to delete | 906 | * @dnext: next orphan to delete |
907 | * @inum: inode number | 907 | * @inum: inode number |
908 | * @new: %1 => added since the last commit, otherwise %0 | 908 | * @new: %1 => added since the last commit, otherwise %0 |
909 | */ | 909 | */ |
910 | struct ubifs_orphan { | 910 | struct ubifs_orphan { |
911 | struct rb_node rb; | 911 | struct rb_node rb; |
912 | struct list_head list; | 912 | struct list_head list; |
913 | struct list_head new_list; | 913 | struct list_head new_list; |
914 | struct ubifs_orphan *cnext; | 914 | struct ubifs_orphan *cnext; |
915 | struct ubifs_orphan *dnext; | 915 | struct ubifs_orphan *dnext; |
916 | ino_t inum; | 916 | ino_t inum; |
917 | int new; | 917 | int new; |
918 | }; | 918 | }; |
919 | 919 | ||
920 | /** | 920 | /** |
921 | * struct ubifs_mount_opts - UBIFS-specific mount options information. | 921 | * struct ubifs_mount_opts - UBIFS-specific mount options information. |
922 | * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast) | 922 | * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast) |
923 | * @bulk_read: enable/disable bulk-reads (%0 default, %1 disabe, %2 enable) | 923 | * @bulk_read: enable/disable bulk-reads (%0 default, %1 disabe, %2 enable) |
924 | * @chk_data_crc: enable/disable CRC data checking when reading data nodes | 924 | * @chk_data_crc: enable/disable CRC data checking when reading data nodes |
925 | * (%0 default, %1 disabe, %2 enable) | 925 | * (%0 default, %1 disabe, %2 enable) |
926 | * @override_compr: override default compressor (%0 - do not override and use | 926 | * @override_compr: override default compressor (%0 - do not override and use |
927 | * superblock compressor, %1 - override and use compressor | 927 | * superblock compressor, %1 - override and use compressor |
928 | * specified in @compr_type) | 928 | * specified in @compr_type) |
929 | * @compr_type: compressor type to override the superblock compressor with | 929 | * @compr_type: compressor type to override the superblock compressor with |
930 | * (%UBIFS_COMPR_NONE, etc) | 930 | * (%UBIFS_COMPR_NONE, etc) |
931 | */ | 931 | */ |
932 | struct ubifs_mount_opts { | 932 | struct ubifs_mount_opts { |
933 | unsigned int unmount_mode:2; | 933 | unsigned int unmount_mode:2; |
934 | unsigned int bulk_read:2; | 934 | unsigned int bulk_read:2; |
935 | unsigned int chk_data_crc:2; | 935 | unsigned int chk_data_crc:2; |
936 | unsigned int override_compr:1; | 936 | unsigned int override_compr:1; |
937 | unsigned int compr_type:2; | 937 | unsigned int compr_type:2; |
938 | }; | 938 | }; |
939 | 939 | ||
940 | /** | 940 | /** |
941 | * struct ubifs_budg_info - UBIFS budgeting information. | 941 | * struct ubifs_budg_info - UBIFS budgeting information. |
942 | * @idx_growth: amount of bytes budgeted for index growth | 942 | * @idx_growth: amount of bytes budgeted for index growth |
943 | * @data_growth: amount of bytes budgeted for cached data | 943 | * @data_growth: amount of bytes budgeted for cached data |
944 | * @dd_growth: amount of bytes budgeted for cached data that will make | 944 | * @dd_growth: amount of bytes budgeted for cached data that will make |
945 | * other data dirty | 945 | * other data dirty |
946 | * @uncommitted_idx: amount of bytes were budgeted for growth of the index, but | 946 | * @uncommitted_idx: amount of bytes were budgeted for growth of the index, but |
947 | * which still have to be taken into account because the index | 947 | * which still have to be taken into account because the index |
948 | * has not been committed so far | 948 | * has not been committed so far |
949 | * @old_idx_sz: size of index on flash | 949 | * @old_idx_sz: size of index on flash |
950 | * @min_idx_lebs: minimum number of LEBs required for the index | 950 | * @min_idx_lebs: minimum number of LEBs required for the index |
951 | * @nospace: non-zero if the file-system does not have flash space (used as | 951 | * @nospace: non-zero if the file-system does not have flash space (used as |
952 | * optimization) | 952 | * optimization) |
953 | * @nospace_rp: the same as @nospace, but additionally means that even reserved | 953 | * @nospace_rp: the same as @nospace, but additionally means that even reserved |
954 | * pool is full | 954 | * pool is full |
955 | * @page_budget: budget for a page (constant, nenver changed after mount) | 955 | * @page_budget: budget for a page (constant, nenver changed after mount) |
956 | * @inode_budget: budget for an inode (constant, nenver changed after mount) | 956 | * @inode_budget: budget for an inode (constant, nenver changed after mount) |
957 | * @dent_budget: budget for a directory entry (constant, nenver changed after | 957 | * @dent_budget: budget for a directory entry (constant, nenver changed after |
958 | * mount) | 958 | * mount) |
959 | */ | 959 | */ |
960 | struct ubifs_budg_info { | 960 | struct ubifs_budg_info { |
961 | long long idx_growth; | 961 | long long idx_growth; |
962 | long long data_growth; | 962 | long long data_growth; |
963 | long long dd_growth; | 963 | long long dd_growth; |
964 | long long uncommitted_idx; | 964 | long long uncommitted_idx; |
965 | unsigned long long old_idx_sz; | 965 | unsigned long long old_idx_sz; |
966 | int min_idx_lebs; | 966 | int min_idx_lebs; |
967 | unsigned int nospace:1; | 967 | unsigned int nospace:1; |
968 | unsigned int nospace_rp:1; | 968 | unsigned int nospace_rp:1; |
969 | int page_budget; | 969 | int page_budget; |
970 | int inode_budget; | 970 | int inode_budget; |
971 | int dent_budget; | 971 | int dent_budget; |
972 | }; | 972 | }; |
973 | 973 | ||
974 | struct ubifs_debug_info; | 974 | struct ubifs_debug_info; |
975 | 975 | ||
976 | /** | 976 | /** |
977 | * struct ubifs_info - UBIFS file-system description data structure | 977 | * struct ubifs_info - UBIFS file-system description data structure |
978 | * (per-superblock). | 978 | * (per-superblock). |
979 | * @vfs_sb: VFS @struct super_block object | 979 | * @vfs_sb: VFS @struct super_block object |
980 | * @bdi: backing device info object to make VFS happy and disable read-ahead | 980 | * @bdi: backing device info object to make VFS happy and disable read-ahead |
981 | * | 981 | * |
982 | * @highest_inum: highest used inode number | 982 | * @highest_inum: highest used inode number |
983 | * @max_sqnum: current global sequence number | 983 | * @max_sqnum: current global sequence number |
984 | * @cmt_no: commit number of the last successfully completed commit, protected | 984 | * @cmt_no: commit number of the last successfully completed commit, protected |
985 | * by @commit_sem | 985 | * by @commit_sem |
986 | * @cnt_lock: protects @highest_inum and @max_sqnum counters | 986 | * @cnt_lock: protects @highest_inum and @max_sqnum counters |
987 | * @fmt_version: UBIFS on-flash format version | 987 | * @fmt_version: UBIFS on-flash format version |
988 | * @ro_compat_version: R/O compatibility version | 988 | * @ro_compat_version: R/O compatibility version |
989 | * @uuid: UUID from super block | 989 | * @uuid: UUID from super block |
990 | * | 990 | * |
991 | * @lhead_lnum: log head logical eraseblock number | 991 | * @lhead_lnum: log head logical eraseblock number |
992 | * @lhead_offs: log head offset | 992 | * @lhead_offs: log head offset |
993 | * @ltail_lnum: log tail logical eraseblock number (offset is always 0) | 993 | * @ltail_lnum: log tail logical eraseblock number (offset is always 0) |
994 | * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and | 994 | * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and |
995 | * @bud_bytes | 995 | * @bud_bytes |
996 | * @min_log_bytes: minimum required number of bytes in the log | 996 | * @min_log_bytes: minimum required number of bytes in the log |
997 | * @cmt_bud_bytes: used during commit to temporarily amount of bytes in | 997 | * @cmt_bud_bytes: used during commit to temporarily amount of bytes in |
998 | * committed buds | 998 | * committed buds |
999 | * | 999 | * |
1000 | * @buds: tree of all buds indexed by bud LEB number | 1000 | * @buds: tree of all buds indexed by bud LEB number |
1001 | * @bud_bytes: how many bytes of flash is used by buds | 1001 | * @bud_bytes: how many bytes of flash is used by buds |
1002 | * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud | 1002 | * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud |
1003 | * lists | 1003 | * lists |
1004 | * @jhead_cnt: count of journal heads | 1004 | * @jhead_cnt: count of journal heads |
1005 | * @jheads: journal heads (head zero is base head) | 1005 | * @jheads: journal heads (head zero is base head) |
1006 | * @max_bud_bytes: maximum number of bytes allowed in buds | 1006 | * @max_bud_bytes: maximum number of bytes allowed in buds |
1007 | * @bg_bud_bytes: number of bud bytes when background commit is initiated | 1007 | * @bg_bud_bytes: number of bud bytes when background commit is initiated |
1008 | * @old_buds: buds to be released after commit ends | 1008 | * @old_buds: buds to be released after commit ends |
1009 | * @max_bud_cnt: maximum number of buds | 1009 | * @max_bud_cnt: maximum number of buds |
1010 | * | 1010 | * |
1011 | * @commit_sem: synchronizes committer with other processes | 1011 | * @commit_sem: synchronizes committer with other processes |
1012 | * @cmt_state: commit state | 1012 | * @cmt_state: commit state |
1013 | * @cs_lock: commit state lock | 1013 | * @cs_lock: commit state lock |
1014 | * @cmt_wq: wait queue to sleep on if the log is full and a commit is running | 1014 | * @cmt_wq: wait queue to sleep on if the log is full and a commit is running |
1015 | * | 1015 | * |
1016 | * @big_lpt: flag that LPT is too big to write whole during commit | 1016 | * @big_lpt: flag that LPT is too big to write whole during commit |
1017 | * @space_fixup: flag indicating that free space in LEBs needs to be cleaned up | ||
1017 | * @no_chk_data_crc: do not check CRCs when reading data nodes (except during | 1018 | * @no_chk_data_crc: do not check CRCs when reading data nodes (except during |
1018 | * recovery) | 1019 | * recovery) |
1019 | * @bulk_read: enable bulk-reads | 1020 | * @bulk_read: enable bulk-reads |
1020 | * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc) | 1021 | * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc) |
1021 | * @rw_incompat: the media is not R/W compatible | 1022 | * @rw_incompat: the media is not R/W compatible |
1022 | * | 1023 | * |
1023 | * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and | 1024 | * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and |
1024 | * @calc_idx_sz | 1025 | * @calc_idx_sz |
1025 | * @zroot: zbranch which points to the root index node and znode | 1026 | * @zroot: zbranch which points to the root index node and znode |
1026 | * @cnext: next znode to commit | 1027 | * @cnext: next znode to commit |
1027 | * @enext: next znode to commit to empty space | 1028 | * @enext: next znode to commit to empty space |
1028 | * @gap_lebs: array of LEBs used by the in-gaps commit method | 1029 | * @gap_lebs: array of LEBs used by the in-gaps commit method |
1029 | * @cbuf: commit buffer | 1030 | * @cbuf: commit buffer |
1030 | * @ileb_buf: buffer for commit in-the-gaps method | 1031 | * @ileb_buf: buffer for commit in-the-gaps method |
1031 | * @ileb_len: length of data in ileb_buf | 1032 | * @ileb_len: length of data in ileb_buf |
1032 | * @ihead_lnum: LEB number of index head | 1033 | * @ihead_lnum: LEB number of index head |
1033 | * @ihead_offs: offset of index head | 1034 | * @ihead_offs: offset of index head |
1034 | * @ilebs: pre-allocated index LEBs | 1035 | * @ilebs: pre-allocated index LEBs |
1035 | * @ileb_cnt: number of pre-allocated index LEBs | 1036 | * @ileb_cnt: number of pre-allocated index LEBs |
1036 | * @ileb_nxt: next pre-allocated index LEBs | 1037 | * @ileb_nxt: next pre-allocated index LEBs |
1037 | * @old_idx: tree of index nodes obsoleted since the last commit start | 1038 | * @old_idx: tree of index nodes obsoleted since the last commit start |
1038 | * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c | 1039 | * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c |
1039 | * | 1040 | * |
1040 | * @mst_node: master node | 1041 | * @mst_node: master node |
1041 | * @mst_offs: offset of valid master node | 1042 | * @mst_offs: offset of valid master node |
1042 | * @mst_mutex: protects the master node area, @mst_node, and @mst_offs | 1043 | * @mst_mutex: protects the master node area, @mst_node, and @mst_offs |
1043 | * | 1044 | * |
1044 | * @max_bu_buf_len: maximum bulk-read buffer length | 1045 | * @max_bu_buf_len: maximum bulk-read buffer length |
1045 | * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu | 1046 | * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu |
1046 | * @bu: pre-allocated bulk-read information | 1047 | * @bu: pre-allocated bulk-read information |
1047 | * | 1048 | * |
1048 | * @write_reserve_mutex: protects @write_reserve_buf | 1049 | * @write_reserve_mutex: protects @write_reserve_buf |
1049 | * @write_reserve_buf: on the write path we allocate memory, which might | 1050 | * @write_reserve_buf: on the write path we allocate memory, which might |
1050 | * sometimes be unavailable, in which case we use this | 1051 | * sometimes be unavailable, in which case we use this |
1051 | * write reserve buffer | 1052 | * write reserve buffer |
1052 | * | 1053 | * |
1053 | * @log_lebs: number of logical eraseblocks in the log | 1054 | * @log_lebs: number of logical eraseblocks in the log |
1054 | * @log_bytes: log size in bytes | 1055 | * @log_bytes: log size in bytes |
1055 | * @log_last: last LEB of the log | 1056 | * @log_last: last LEB of the log |
1056 | * @lpt_lebs: number of LEBs used for lprops table | 1057 | * @lpt_lebs: number of LEBs used for lprops table |
1057 | * @lpt_first: first LEB of the lprops table area | 1058 | * @lpt_first: first LEB of the lprops table area |
1058 | * @lpt_last: last LEB of the lprops table area | 1059 | * @lpt_last: last LEB of the lprops table area |
1059 | * @orph_lebs: number of LEBs used for the orphan area | 1060 | * @orph_lebs: number of LEBs used for the orphan area |
1060 | * @orph_first: first LEB of the orphan area | 1061 | * @orph_first: first LEB of the orphan area |
1061 | * @orph_last: last LEB of the orphan area | 1062 | * @orph_last: last LEB of the orphan area |
1062 | * @main_lebs: count of LEBs in the main area | 1063 | * @main_lebs: count of LEBs in the main area |
1063 | * @main_first: first LEB of the main area | 1064 | * @main_first: first LEB of the main area |
1064 | * @main_bytes: main area size in bytes | 1065 | * @main_bytes: main area size in bytes |
1065 | * | 1066 | * |
1066 | * @key_hash_type: type of the key hash | 1067 | * @key_hash_type: type of the key hash |
1067 | * @key_hash: direntry key hash function | 1068 | * @key_hash: direntry key hash function |
1068 | * @key_fmt: key format | 1069 | * @key_fmt: key format |
1069 | * @key_len: key length | 1070 | * @key_len: key length |
1070 | * @fanout: fanout of the index tree (number of links per indexing node) | 1071 | * @fanout: fanout of the index tree (number of links per indexing node) |
1071 | * | 1072 | * |
1072 | * @min_io_size: minimal input/output unit size | 1073 | * @min_io_size: minimal input/output unit size |
1073 | * @min_io_shift: number of bits in @min_io_size minus one | 1074 | * @min_io_shift: number of bits in @min_io_size minus one |
1074 | * @max_write_size: maximum amount of bytes the underlying flash can write at a | 1075 | * @max_write_size: maximum amount of bytes the underlying flash can write at a |
1075 | * time (MTD write buffer size) | 1076 | * time (MTD write buffer size) |
1076 | * @max_write_shift: number of bits in @max_write_size minus one | 1077 | * @max_write_shift: number of bits in @max_write_size minus one |
1077 | * @leb_size: logical eraseblock size in bytes | 1078 | * @leb_size: logical eraseblock size in bytes |
1078 | * @leb_start: starting offset of logical eraseblocks within physical | 1079 | * @leb_start: starting offset of logical eraseblocks within physical |
1079 | * eraseblocks | 1080 | * eraseblocks |
1080 | * @half_leb_size: half LEB size | 1081 | * @half_leb_size: half LEB size |
1081 | * @idx_leb_size: how many bytes of an LEB are effectively available when it is | 1082 | * @idx_leb_size: how many bytes of an LEB are effectively available when it is |
1082 | * used to store indexing nodes (@leb_size - @max_idx_node_sz) | 1083 | * used to store indexing nodes (@leb_size - @max_idx_node_sz) |
1083 | * @leb_cnt: count of logical eraseblocks | 1084 | * @leb_cnt: count of logical eraseblocks |
1084 | * @max_leb_cnt: maximum count of logical eraseblocks | 1085 | * @max_leb_cnt: maximum count of logical eraseblocks |
1085 | * @old_leb_cnt: count of logical eraseblocks before re-size | 1086 | * @old_leb_cnt: count of logical eraseblocks before re-size |
1086 | * @ro_media: the underlying UBI volume is read-only | 1087 | * @ro_media: the underlying UBI volume is read-only |
1087 | * @ro_mount: the file-system was mounted as read-only | 1088 | * @ro_mount: the file-system was mounted as read-only |
1088 | * @ro_error: UBIFS switched to R/O mode because an error happened | 1089 | * @ro_error: UBIFS switched to R/O mode because an error happened |
1089 | * | 1090 | * |
1090 | * @dirty_pg_cnt: number of dirty pages (not used) | 1091 | * @dirty_pg_cnt: number of dirty pages (not used) |
1091 | * @dirty_zn_cnt: number of dirty znodes | 1092 | * @dirty_zn_cnt: number of dirty znodes |
1092 | * @clean_zn_cnt: number of clean znodes | 1093 | * @clean_zn_cnt: number of clean znodes |
1093 | * | 1094 | * |
1094 | * @space_lock: protects @bi and @lst | 1095 | * @space_lock: protects @bi and @lst |
1095 | * @lst: lprops statistics | 1096 | * @lst: lprops statistics |
1096 | * @bi: budgeting information | 1097 | * @bi: budgeting information |
1097 | * @calc_idx_sz: temporary variable which is used to calculate new index size | 1098 | * @calc_idx_sz: temporary variable which is used to calculate new index size |
1098 | * (contains accurate new index size at end of TNC commit start) | 1099 | * (contains accurate new index size at end of TNC commit start) |
1099 | * | 1100 | * |
1100 | * @ref_node_alsz: size of the LEB reference node aligned to the min. flash | 1101 | * @ref_node_alsz: size of the LEB reference node aligned to the min. flash |
1101 | * I/O unit | 1102 | * I/O unit |
1102 | * @mst_node_alsz: master node aligned size | 1103 | * @mst_node_alsz: master node aligned size |
1103 | * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary | 1104 | * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary |
1104 | * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary | 1105 | * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary |
1105 | * @max_inode_sz: maximum possible inode size in bytes | 1106 | * @max_inode_sz: maximum possible inode size in bytes |
1106 | * @max_znode_sz: size of znode in bytes | 1107 | * @max_znode_sz: size of znode in bytes |
1107 | * | 1108 | * |
1108 | * @leb_overhead: how many bytes are wasted in an LEB when it is filled with | 1109 | * @leb_overhead: how many bytes are wasted in an LEB when it is filled with |
1109 | * data nodes of maximum size - used in free space reporting | 1110 | * data nodes of maximum size - used in free space reporting |
1110 | * @dead_wm: LEB dead space watermark | 1111 | * @dead_wm: LEB dead space watermark |
1111 | * @dark_wm: LEB dark space watermark | 1112 | * @dark_wm: LEB dark space watermark |
1112 | * @block_cnt: count of 4KiB blocks on the FS | 1113 | * @block_cnt: count of 4KiB blocks on the FS |
1113 | * | 1114 | * |
1114 | * @ranges: UBIFS node length ranges | 1115 | * @ranges: UBIFS node length ranges |
1115 | * @ubi: UBI volume descriptor | 1116 | * @ubi: UBI volume descriptor |
1116 | * @di: UBI device information | 1117 | * @di: UBI device information |
1117 | * @vi: UBI volume information | 1118 | * @vi: UBI volume information |
1118 | * | 1119 | * |
1119 | * @orph_tree: rb-tree of orphan inode numbers | 1120 | * @orph_tree: rb-tree of orphan inode numbers |
1120 | * @orph_list: list of orphan inode numbers in order added | 1121 | * @orph_list: list of orphan inode numbers in order added |
1121 | * @orph_new: list of orphan inode numbers added since last commit | 1122 | * @orph_new: list of orphan inode numbers added since last commit |
1122 | * @orph_cnext: next orphan to commit | 1123 | * @orph_cnext: next orphan to commit |
1123 | * @orph_dnext: next orphan to delete | 1124 | * @orph_dnext: next orphan to delete |
1124 | * @orphan_lock: lock for orph_tree and orph_new | 1125 | * @orphan_lock: lock for orph_tree and orph_new |
1125 | * @orph_buf: buffer for orphan nodes | 1126 | * @orph_buf: buffer for orphan nodes |
1126 | * @new_orphans: number of orphans since last commit | 1127 | * @new_orphans: number of orphans since last commit |
1127 | * @cmt_orphans: number of orphans being committed | 1128 | * @cmt_orphans: number of orphans being committed |
1128 | * @tot_orphans: number of orphans in the rb_tree | 1129 | * @tot_orphans: number of orphans in the rb_tree |
1129 | * @max_orphans: maximum number of orphans allowed | 1130 | * @max_orphans: maximum number of orphans allowed |
1130 | * @ohead_lnum: orphan head LEB number | 1131 | * @ohead_lnum: orphan head LEB number |
1131 | * @ohead_offs: orphan head offset | 1132 | * @ohead_offs: orphan head offset |
1132 | * @no_orphs: non-zero if there are no orphans | 1133 | * @no_orphs: non-zero if there are no orphans |
1133 | * | 1134 | * |
1134 | * @bgt: UBIFS background thread | 1135 | * @bgt: UBIFS background thread |
1135 | * @bgt_name: background thread name | 1136 | * @bgt_name: background thread name |
1136 | * @need_bgt: if background thread should run | 1137 | * @need_bgt: if background thread should run |
1137 | * @need_wbuf_sync: if write-buffers have to be synchronized | 1138 | * @need_wbuf_sync: if write-buffers have to be synchronized |
1138 | * | 1139 | * |
1139 | * @gc_lnum: LEB number used for garbage collection | 1140 | * @gc_lnum: LEB number used for garbage collection |
1140 | * @sbuf: a buffer of LEB size used by GC and replay for scanning | 1141 | * @sbuf: a buffer of LEB size used by GC and replay for scanning |
1141 | * @idx_gc: list of index LEBs that have been garbage collected | 1142 | * @idx_gc: list of index LEBs that have been garbage collected |
1142 | * @idx_gc_cnt: number of elements on the idx_gc list | 1143 | * @idx_gc_cnt: number of elements on the idx_gc list |
1143 | * @gc_seq: incremented for every non-index LEB garbage collected | 1144 | * @gc_seq: incremented for every non-index LEB garbage collected |
1144 | * @gced_lnum: last non-index LEB that was garbage collected | 1145 | * @gced_lnum: last non-index LEB that was garbage collected |
1145 | * | 1146 | * |
1146 | * @infos_list: links all 'ubifs_info' objects | 1147 | * @infos_list: links all 'ubifs_info' objects |
1147 | * @umount_mutex: serializes shrinker and un-mount | 1148 | * @umount_mutex: serializes shrinker and un-mount |
1148 | * @shrinker_run_no: shrinker run number | 1149 | * @shrinker_run_no: shrinker run number |
1149 | * | 1150 | * |
1150 | * @space_bits: number of bits needed to record free or dirty space | 1151 | * @space_bits: number of bits needed to record free or dirty space |
1151 | * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT | 1152 | * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT |
1152 | * @lpt_offs_bits: number of bits needed to record an offset in the LPT | 1153 | * @lpt_offs_bits: number of bits needed to record an offset in the LPT |
1153 | * @lpt_spc_bits: number of bits needed to space in the LPT | 1154 | * @lpt_spc_bits: number of bits needed to space in the LPT |
1154 | * @pcnt_bits: number of bits needed to record pnode or nnode number | 1155 | * @pcnt_bits: number of bits needed to record pnode or nnode number |
1155 | * @lnum_bits: number of bits needed to record LEB number | 1156 | * @lnum_bits: number of bits needed to record LEB number |
1156 | * @nnode_sz: size of on-flash nnode | 1157 | * @nnode_sz: size of on-flash nnode |
1157 | * @pnode_sz: size of on-flash pnode | 1158 | * @pnode_sz: size of on-flash pnode |
1158 | * @ltab_sz: size of on-flash LPT lprops table | 1159 | * @ltab_sz: size of on-flash LPT lprops table |
1159 | * @lsave_sz: size of on-flash LPT save table | 1160 | * @lsave_sz: size of on-flash LPT save table |
1160 | * @pnode_cnt: number of pnodes | 1161 | * @pnode_cnt: number of pnodes |
1161 | * @nnode_cnt: number of nnodes | 1162 | * @nnode_cnt: number of nnodes |
1162 | * @lpt_hght: height of the LPT | 1163 | * @lpt_hght: height of the LPT |
1163 | * @pnodes_have: number of pnodes in memory | 1164 | * @pnodes_have: number of pnodes in memory |
1164 | * | 1165 | * |
1165 | * @lp_mutex: protects lprops table and all the other lprops-related fields | 1166 | * @lp_mutex: protects lprops table and all the other lprops-related fields |
1166 | * @lpt_lnum: LEB number of the root nnode of the LPT | 1167 | * @lpt_lnum: LEB number of the root nnode of the LPT |
1167 | * @lpt_offs: offset of the root nnode of the LPT | 1168 | * @lpt_offs: offset of the root nnode of the LPT |
1168 | * @nhead_lnum: LEB number of LPT head | 1169 | * @nhead_lnum: LEB number of LPT head |
1169 | * @nhead_offs: offset of LPT head | 1170 | * @nhead_offs: offset of LPT head |
1170 | * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab | 1171 | * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab |
1171 | * @dirty_nn_cnt: number of dirty nnodes | 1172 | * @dirty_nn_cnt: number of dirty nnodes |
1172 | * @dirty_pn_cnt: number of dirty pnodes | 1173 | * @dirty_pn_cnt: number of dirty pnodes |
1173 | * @check_lpt_free: flag that indicates LPT GC may be needed | 1174 | * @check_lpt_free: flag that indicates LPT GC may be needed |
1174 | * @lpt_sz: LPT size | 1175 | * @lpt_sz: LPT size |
1175 | * @lpt_nod_buf: buffer for an on-flash nnode or pnode | 1176 | * @lpt_nod_buf: buffer for an on-flash nnode or pnode |
1176 | * @lpt_buf: buffer of LEB size used by LPT | 1177 | * @lpt_buf: buffer of LEB size used by LPT |
1177 | * @nroot: address in memory of the root nnode of the LPT | 1178 | * @nroot: address in memory of the root nnode of the LPT |
1178 | * @lpt_cnext: next LPT node to commit | 1179 | * @lpt_cnext: next LPT node to commit |
1179 | * @lpt_heap: array of heaps of categorized lprops | 1180 | * @lpt_heap: array of heaps of categorized lprops |
1180 | * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at | 1181 | * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at |
1181 | * previous commit start | 1182 | * previous commit start |
1182 | * @uncat_list: list of un-categorized LEBs | 1183 | * @uncat_list: list of un-categorized LEBs |
1183 | * @empty_list: list of empty LEBs | 1184 | * @empty_list: list of empty LEBs |
1184 | * @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size) | 1185 | * @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size) |
1185 | * @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size) | 1186 | * @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size) |
1186 | * @freeable_cnt: number of freeable LEBs in @freeable_list | 1187 | * @freeable_cnt: number of freeable LEBs in @freeable_list |
1187 | * | 1188 | * |
1188 | * @ltab_lnum: LEB number of LPT's own lprops table | 1189 | * @ltab_lnum: LEB number of LPT's own lprops table |
1189 | * @ltab_offs: offset of LPT's own lprops table | 1190 | * @ltab_offs: offset of LPT's own lprops table |
1190 | * @ltab: LPT's own lprops table | 1191 | * @ltab: LPT's own lprops table |
1191 | * @ltab_cmt: LPT's own lprops table (commit copy) | 1192 | * @ltab_cmt: LPT's own lprops table (commit copy) |
1192 | * @lsave_cnt: number of LEB numbers in LPT's save table | 1193 | * @lsave_cnt: number of LEB numbers in LPT's save table |
1193 | * @lsave_lnum: LEB number of LPT's save table | 1194 | * @lsave_lnum: LEB number of LPT's save table |
1194 | * @lsave_offs: offset of LPT's save table | 1195 | * @lsave_offs: offset of LPT's save table |
1195 | * @lsave: LPT's save table | 1196 | * @lsave: LPT's save table |
1196 | * @lscan_lnum: LEB number of last LPT scan | 1197 | * @lscan_lnum: LEB number of last LPT scan |
1197 | * | 1198 | * |
1198 | * @rp_size: size of the reserved pool in bytes | 1199 | * @rp_size: size of the reserved pool in bytes |
1199 | * @report_rp_size: size of the reserved pool reported to user-space | 1200 | * @report_rp_size: size of the reserved pool reported to user-space |
1200 | * @rp_uid: reserved pool user ID | 1201 | * @rp_uid: reserved pool user ID |
1201 | * @rp_gid: reserved pool group ID | 1202 | * @rp_gid: reserved pool group ID |
1202 | * | 1203 | * |
1203 | * @empty: %1 if the UBI device is empty | 1204 | * @empty: %1 if the UBI device is empty |
1204 | * @need_recovery: %1 if the file-system needs recovery | 1205 | * @need_recovery: %1 if the file-system needs recovery |
1205 | * @replaying: %1 during journal replay | 1206 | * @replaying: %1 during journal replay |
1206 | * @mounting: %1 while mounting | 1207 | * @mounting: %1 while mounting |
1207 | * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode | 1208 | * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode |
1208 | * @replay_list: temporary list used during journal replay | 1209 | * @replay_list: temporary list used during journal replay |
1209 | * @replay_buds: list of buds to replay | 1210 | * @replay_buds: list of buds to replay |
1210 | * @cs_sqnum: sequence number of first node in the log (commit start node) | 1211 | * @cs_sqnum: sequence number of first node in the log (commit start node) |
1211 | * @replay_sqnum: sequence number of node currently being replayed | 1212 | * @replay_sqnum: sequence number of node currently being replayed |
1212 | * @unclean_leb_list: LEBs to recover when re-mounting R/O mounted FS to R/W | 1213 | * @unclean_leb_list: LEBs to recover when re-mounting R/O mounted FS to R/W |
1213 | * mode | 1214 | * mode |
1214 | * @rcvrd_mst_node: recovered master node to write when re-mounting R/O mounted | 1215 | * @rcvrd_mst_node: recovered master node to write when re-mounting R/O mounted |
1215 | * FS to R/W mode | 1216 | * FS to R/W mode |
1216 | * @size_tree: inode size information for recovery | 1217 | * @size_tree: inode size information for recovery |
1217 | * @mount_opts: UBIFS-specific mount options | 1218 | * @mount_opts: UBIFS-specific mount options |
1218 | * | 1219 | * |
1219 | * @dbg: debugging-related information | 1220 | * @dbg: debugging-related information |
1220 | */ | 1221 | */ |
1221 | struct ubifs_info { | 1222 | struct ubifs_info { |
1222 | struct super_block *vfs_sb; | 1223 | struct super_block *vfs_sb; |
1223 | struct backing_dev_info bdi; | 1224 | struct backing_dev_info bdi; |
1224 | 1225 | ||
1225 | ino_t highest_inum; | 1226 | ino_t highest_inum; |
1226 | unsigned long long max_sqnum; | 1227 | unsigned long long max_sqnum; |
1227 | unsigned long long cmt_no; | 1228 | unsigned long long cmt_no; |
1228 | spinlock_t cnt_lock; | 1229 | spinlock_t cnt_lock; |
1229 | int fmt_version; | 1230 | int fmt_version; |
1230 | int ro_compat_version; | 1231 | int ro_compat_version; |
1231 | unsigned char uuid[16]; | 1232 | unsigned char uuid[16]; |
1232 | 1233 | ||
1233 | int lhead_lnum; | 1234 | int lhead_lnum; |
1234 | int lhead_offs; | 1235 | int lhead_offs; |
1235 | int ltail_lnum; | 1236 | int ltail_lnum; |
1236 | struct mutex log_mutex; | 1237 | struct mutex log_mutex; |
1237 | int min_log_bytes; | 1238 | int min_log_bytes; |
1238 | long long cmt_bud_bytes; | 1239 | long long cmt_bud_bytes; |
1239 | 1240 | ||
1240 | struct rb_root buds; | 1241 | struct rb_root buds; |
1241 | long long bud_bytes; | 1242 | long long bud_bytes; |
1242 | spinlock_t buds_lock; | 1243 | spinlock_t buds_lock; |
1243 | int jhead_cnt; | 1244 | int jhead_cnt; |
1244 | struct ubifs_jhead *jheads; | 1245 | struct ubifs_jhead *jheads; |
1245 | long long max_bud_bytes; | 1246 | long long max_bud_bytes; |
1246 | long long bg_bud_bytes; | 1247 | long long bg_bud_bytes; |
1247 | struct list_head old_buds; | 1248 | struct list_head old_buds; |
1248 | int max_bud_cnt; | 1249 | int max_bud_cnt; |
1249 | 1250 | ||
1250 | struct rw_semaphore commit_sem; | 1251 | struct rw_semaphore commit_sem; |
1251 | int cmt_state; | 1252 | int cmt_state; |
1252 | spinlock_t cs_lock; | 1253 | spinlock_t cs_lock; |
1253 | wait_queue_head_t cmt_wq; | 1254 | wait_queue_head_t cmt_wq; |
1254 | 1255 | ||
1255 | unsigned int big_lpt:1; | 1256 | unsigned int big_lpt:1; |
1257 | unsigned int space_fixup:1; | ||
1256 | unsigned int no_chk_data_crc:1; | 1258 | unsigned int no_chk_data_crc:1; |
1257 | unsigned int bulk_read:1; | 1259 | unsigned int bulk_read:1; |
1258 | unsigned int default_compr:2; | 1260 | unsigned int default_compr:2; |
1259 | unsigned int rw_incompat:1; | 1261 | unsigned int rw_incompat:1; |
1260 | 1262 | ||
1261 | struct mutex tnc_mutex; | 1263 | struct mutex tnc_mutex; |
1262 | struct ubifs_zbranch zroot; | 1264 | struct ubifs_zbranch zroot; |
1263 | struct ubifs_znode *cnext; | 1265 | struct ubifs_znode *cnext; |
1264 | struct ubifs_znode *enext; | 1266 | struct ubifs_znode *enext; |
1265 | int *gap_lebs; | 1267 | int *gap_lebs; |
1266 | void *cbuf; | 1268 | void *cbuf; |
1267 | void *ileb_buf; | 1269 | void *ileb_buf; |
1268 | int ileb_len; | 1270 | int ileb_len; |
1269 | int ihead_lnum; | 1271 | int ihead_lnum; |
1270 | int ihead_offs; | 1272 | int ihead_offs; |
1271 | int *ilebs; | 1273 | int *ilebs; |
1272 | int ileb_cnt; | 1274 | int ileb_cnt; |
1273 | int ileb_nxt; | 1275 | int ileb_nxt; |
1274 | struct rb_root old_idx; | 1276 | struct rb_root old_idx; |
1275 | int *bottom_up_buf; | 1277 | int *bottom_up_buf; |
1276 | 1278 | ||
1277 | struct ubifs_mst_node *mst_node; | 1279 | struct ubifs_mst_node *mst_node; |
1278 | int mst_offs; | 1280 | int mst_offs; |
1279 | struct mutex mst_mutex; | 1281 | struct mutex mst_mutex; |
1280 | 1282 | ||
1281 | int max_bu_buf_len; | 1283 | int max_bu_buf_len; |
1282 | struct mutex bu_mutex; | 1284 | struct mutex bu_mutex; |
1283 | struct bu_info bu; | 1285 | struct bu_info bu; |
1284 | 1286 | ||
1285 | struct mutex write_reserve_mutex; | 1287 | struct mutex write_reserve_mutex; |
1286 | void *write_reserve_buf; | 1288 | void *write_reserve_buf; |
1287 | 1289 | ||
1288 | int log_lebs; | 1290 | int log_lebs; |
1289 | long long log_bytes; | 1291 | long long log_bytes; |
1290 | int log_last; | 1292 | int log_last; |
1291 | int lpt_lebs; | 1293 | int lpt_lebs; |
1292 | int lpt_first; | 1294 | int lpt_first; |
1293 | int lpt_last; | 1295 | int lpt_last; |
1294 | int orph_lebs; | 1296 | int orph_lebs; |
1295 | int orph_first; | 1297 | int orph_first; |
1296 | int orph_last; | 1298 | int orph_last; |
1297 | int main_lebs; | 1299 | int main_lebs; |
1298 | int main_first; | 1300 | int main_first; |
1299 | long long main_bytes; | 1301 | long long main_bytes; |
1300 | 1302 | ||
1301 | uint8_t key_hash_type; | 1303 | uint8_t key_hash_type; |
1302 | uint32_t (*key_hash)(const char *str, int len); | 1304 | uint32_t (*key_hash)(const char *str, int len); |
1303 | int key_fmt; | 1305 | int key_fmt; |
1304 | int key_len; | 1306 | int key_len; |
1305 | int fanout; | 1307 | int fanout; |
1306 | 1308 | ||
1307 | int min_io_size; | 1309 | int min_io_size; |
1308 | int min_io_shift; | 1310 | int min_io_shift; |
1309 | int max_write_size; | 1311 | int max_write_size; |
1310 | int max_write_shift; | 1312 | int max_write_shift; |
1311 | int leb_size; | 1313 | int leb_size; |
1312 | int leb_start; | 1314 | int leb_start; |
1313 | int half_leb_size; | 1315 | int half_leb_size; |
1314 | int idx_leb_size; | 1316 | int idx_leb_size; |
1315 | int leb_cnt; | 1317 | int leb_cnt; |
1316 | int max_leb_cnt; | 1318 | int max_leb_cnt; |
1317 | int old_leb_cnt; | 1319 | int old_leb_cnt; |
1318 | unsigned int ro_media:1; | 1320 | unsigned int ro_media:1; |
1319 | unsigned int ro_mount:1; | 1321 | unsigned int ro_mount:1; |
1320 | unsigned int ro_error:1; | 1322 | unsigned int ro_error:1; |
1321 | 1323 | ||
1322 | atomic_long_t dirty_pg_cnt; | 1324 | atomic_long_t dirty_pg_cnt; |
1323 | atomic_long_t dirty_zn_cnt; | 1325 | atomic_long_t dirty_zn_cnt; |
1324 | atomic_long_t clean_zn_cnt; | 1326 | atomic_long_t clean_zn_cnt; |
1325 | 1327 | ||
1326 | spinlock_t space_lock; | 1328 | spinlock_t space_lock; |
1327 | struct ubifs_lp_stats lst; | 1329 | struct ubifs_lp_stats lst; |
1328 | struct ubifs_budg_info bi; | 1330 | struct ubifs_budg_info bi; |
1329 | unsigned long long calc_idx_sz; | 1331 | unsigned long long calc_idx_sz; |
1330 | 1332 | ||
1331 | int ref_node_alsz; | 1333 | int ref_node_alsz; |
1332 | int mst_node_alsz; | 1334 | int mst_node_alsz; |
1333 | int min_idx_node_sz; | 1335 | int min_idx_node_sz; |
1334 | int max_idx_node_sz; | 1336 | int max_idx_node_sz; |
1335 | long long max_inode_sz; | 1337 | long long max_inode_sz; |
1336 | int max_znode_sz; | 1338 | int max_znode_sz; |
1337 | 1339 | ||
1338 | int leb_overhead; | 1340 | int leb_overhead; |
1339 | int dead_wm; | 1341 | int dead_wm; |
1340 | int dark_wm; | 1342 | int dark_wm; |
1341 | int block_cnt; | 1343 | int block_cnt; |
1342 | 1344 | ||
1343 | struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT]; | 1345 | struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT]; |
1344 | struct ubi_volume_desc *ubi; | 1346 | struct ubi_volume_desc *ubi; |
1345 | struct ubi_device_info di; | 1347 | struct ubi_device_info di; |
1346 | struct ubi_volume_info vi; | 1348 | struct ubi_volume_info vi; |
1347 | 1349 | ||
1348 | struct rb_root orph_tree; | 1350 | struct rb_root orph_tree; |
1349 | struct list_head orph_list; | 1351 | struct list_head orph_list; |
1350 | struct list_head orph_new; | 1352 | struct list_head orph_new; |
1351 | struct ubifs_orphan *orph_cnext; | 1353 | struct ubifs_orphan *orph_cnext; |
1352 | struct ubifs_orphan *orph_dnext; | 1354 | struct ubifs_orphan *orph_dnext; |
1353 | spinlock_t orphan_lock; | 1355 | spinlock_t orphan_lock; |
1354 | void *orph_buf; | 1356 | void *orph_buf; |
1355 | int new_orphans; | 1357 | int new_orphans; |
1356 | int cmt_orphans; | 1358 | int cmt_orphans; |
1357 | int tot_orphans; | 1359 | int tot_orphans; |
1358 | int max_orphans; | 1360 | int max_orphans; |
1359 | int ohead_lnum; | 1361 | int ohead_lnum; |
1360 | int ohead_offs; | 1362 | int ohead_offs; |
1361 | int no_orphs; | 1363 | int no_orphs; |
1362 | 1364 | ||
1363 | struct task_struct *bgt; | 1365 | struct task_struct *bgt; |
1364 | char bgt_name[sizeof(BGT_NAME_PATTERN) + 9]; | 1366 | char bgt_name[sizeof(BGT_NAME_PATTERN) + 9]; |
1365 | int need_bgt; | 1367 | int need_bgt; |
1366 | int need_wbuf_sync; | 1368 | int need_wbuf_sync; |
1367 | 1369 | ||
1368 | int gc_lnum; | 1370 | int gc_lnum; |
1369 | void *sbuf; | 1371 | void *sbuf; |
1370 | struct list_head idx_gc; | 1372 | struct list_head idx_gc; |
1371 | int idx_gc_cnt; | 1373 | int idx_gc_cnt; |
1372 | int gc_seq; | 1374 | int gc_seq; |
1373 | int gced_lnum; | 1375 | int gced_lnum; |
1374 | 1376 | ||
1375 | struct list_head infos_list; | 1377 | struct list_head infos_list; |
1376 | struct mutex umount_mutex; | 1378 | struct mutex umount_mutex; |
1377 | unsigned int shrinker_run_no; | 1379 | unsigned int shrinker_run_no; |
1378 | 1380 | ||
1379 | int space_bits; | 1381 | int space_bits; |
1380 | int lpt_lnum_bits; | 1382 | int lpt_lnum_bits; |
1381 | int lpt_offs_bits; | 1383 | int lpt_offs_bits; |
1382 | int lpt_spc_bits; | 1384 | int lpt_spc_bits; |
1383 | int pcnt_bits; | 1385 | int pcnt_bits; |
1384 | int lnum_bits; | 1386 | int lnum_bits; |
1385 | int nnode_sz; | 1387 | int nnode_sz; |
1386 | int pnode_sz; | 1388 | int pnode_sz; |
1387 | int ltab_sz; | 1389 | int ltab_sz; |
1388 | int lsave_sz; | 1390 | int lsave_sz; |
1389 | int pnode_cnt; | 1391 | int pnode_cnt; |
1390 | int nnode_cnt; | 1392 | int nnode_cnt; |
1391 | int lpt_hght; | 1393 | int lpt_hght; |
1392 | int pnodes_have; | 1394 | int pnodes_have; |
1393 | 1395 | ||
1394 | struct mutex lp_mutex; | 1396 | struct mutex lp_mutex; |
1395 | int lpt_lnum; | 1397 | int lpt_lnum; |
1396 | int lpt_offs; | 1398 | int lpt_offs; |
1397 | int nhead_lnum; | 1399 | int nhead_lnum; |
1398 | int nhead_offs; | 1400 | int nhead_offs; |
1399 | int lpt_drty_flgs; | 1401 | int lpt_drty_flgs; |
1400 | int dirty_nn_cnt; | 1402 | int dirty_nn_cnt; |
1401 | int dirty_pn_cnt; | 1403 | int dirty_pn_cnt; |
1402 | int check_lpt_free; | 1404 | int check_lpt_free; |
1403 | long long lpt_sz; | 1405 | long long lpt_sz; |
1404 | void *lpt_nod_buf; | 1406 | void *lpt_nod_buf; |
1405 | void *lpt_buf; | 1407 | void *lpt_buf; |
1406 | struct ubifs_nnode *nroot; | 1408 | struct ubifs_nnode *nroot; |
1407 | struct ubifs_cnode *lpt_cnext; | 1409 | struct ubifs_cnode *lpt_cnext; |
1408 | struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT]; | 1410 | struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT]; |
1409 | struct ubifs_lpt_heap dirty_idx; | 1411 | struct ubifs_lpt_heap dirty_idx; |
1410 | struct list_head uncat_list; | 1412 | struct list_head uncat_list; |
1411 | struct list_head empty_list; | 1413 | struct list_head empty_list; |
1412 | struct list_head freeable_list; | 1414 | struct list_head freeable_list; |
1413 | struct list_head frdi_idx_list; | 1415 | struct list_head frdi_idx_list; |
1414 | int freeable_cnt; | 1416 | int freeable_cnt; |
1415 | 1417 | ||
1416 | int ltab_lnum; | 1418 | int ltab_lnum; |
1417 | int ltab_offs; | 1419 | int ltab_offs; |
1418 | struct ubifs_lpt_lprops *ltab; | 1420 | struct ubifs_lpt_lprops *ltab; |
1419 | struct ubifs_lpt_lprops *ltab_cmt; | 1421 | struct ubifs_lpt_lprops *ltab_cmt; |
1420 | int lsave_cnt; | 1422 | int lsave_cnt; |
1421 | int lsave_lnum; | 1423 | int lsave_lnum; |
1422 | int lsave_offs; | 1424 | int lsave_offs; |
1423 | int *lsave; | 1425 | int *lsave; |
1424 | int lscan_lnum; | 1426 | int lscan_lnum; |
1425 | 1427 | ||
1426 | long long rp_size; | 1428 | long long rp_size; |
1427 | long long report_rp_size; | 1429 | long long report_rp_size; |
1428 | uid_t rp_uid; | 1430 | uid_t rp_uid; |
1429 | gid_t rp_gid; | 1431 | gid_t rp_gid; |
1430 | 1432 | ||
1431 | /* The below fields are used only during mounting and re-mounting */ | 1433 | /* The below fields are used only during mounting and re-mounting */ |
1432 | unsigned int empty:1; | 1434 | unsigned int empty:1; |
1433 | unsigned int need_recovery:1; | 1435 | unsigned int need_recovery:1; |
1434 | unsigned int replaying:1; | 1436 | unsigned int replaying:1; |
1435 | unsigned int mounting:1; | 1437 | unsigned int mounting:1; |
1436 | unsigned int remounting_rw:1; | 1438 | unsigned int remounting_rw:1; |
1437 | struct list_head replay_list; | 1439 | struct list_head replay_list; |
1438 | struct list_head replay_buds; | 1440 | struct list_head replay_buds; |
1439 | unsigned long long cs_sqnum; | 1441 | unsigned long long cs_sqnum; |
1440 | unsigned long long replay_sqnum; | 1442 | unsigned long long replay_sqnum; |
1441 | struct list_head unclean_leb_list; | 1443 | struct list_head unclean_leb_list; |
1442 | struct ubifs_mst_node *rcvrd_mst_node; | 1444 | struct ubifs_mst_node *rcvrd_mst_node; |
1443 | struct rb_root size_tree; | 1445 | struct rb_root size_tree; |
1444 | struct ubifs_mount_opts mount_opts; | 1446 | struct ubifs_mount_opts mount_opts; |
1445 | 1447 | ||
1446 | #ifdef CONFIG_UBIFS_FS_DEBUG | 1448 | #ifdef CONFIG_UBIFS_FS_DEBUG |
1447 | struct ubifs_debug_info *dbg; | 1449 | struct ubifs_debug_info *dbg; |
1448 | #endif | 1450 | #endif |
1449 | }; | 1451 | }; |
1450 | 1452 | ||
1451 | extern struct list_head ubifs_infos; | 1453 | extern struct list_head ubifs_infos; |
1452 | extern spinlock_t ubifs_infos_lock; | 1454 | extern spinlock_t ubifs_infos_lock; |
1453 | extern atomic_long_t ubifs_clean_zn_cnt; | 1455 | extern atomic_long_t ubifs_clean_zn_cnt; |
1454 | extern struct kmem_cache *ubifs_inode_slab; | 1456 | extern struct kmem_cache *ubifs_inode_slab; |
1455 | extern const struct super_operations ubifs_super_operations; | 1457 | extern const struct super_operations ubifs_super_operations; |
1456 | extern const struct address_space_operations ubifs_file_address_operations; | 1458 | extern const struct address_space_operations ubifs_file_address_operations; |
1457 | extern const struct file_operations ubifs_file_operations; | 1459 | extern const struct file_operations ubifs_file_operations; |
1458 | extern const struct inode_operations ubifs_file_inode_operations; | 1460 | extern const struct inode_operations ubifs_file_inode_operations; |
1459 | extern const struct file_operations ubifs_dir_operations; | 1461 | extern const struct file_operations ubifs_dir_operations; |
1460 | extern const struct inode_operations ubifs_dir_inode_operations; | 1462 | extern const struct inode_operations ubifs_dir_inode_operations; |
1461 | extern const struct inode_operations ubifs_symlink_inode_operations; | 1463 | extern const struct inode_operations ubifs_symlink_inode_operations; |
1462 | extern struct backing_dev_info ubifs_backing_dev_info; | 1464 | extern struct backing_dev_info ubifs_backing_dev_info; |
1463 | extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; | 1465 | extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; |
1464 | 1466 | ||
1465 | /* io.c */ | 1467 | /* io.c */ |
1466 | void ubifs_ro_mode(struct ubifs_info *c, int err); | 1468 | void ubifs_ro_mode(struct ubifs_info *c, int err); |
1467 | int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len); | 1469 | int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len); |
1468 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, | 1470 | int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs, |
1469 | int dtype); | 1471 | int dtype); |
1470 | int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf); | 1472 | int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf); |
1471 | int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, | 1473 | int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, |
1472 | int lnum, int offs); | 1474 | int lnum, int offs); |
1473 | int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, | 1475 | int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, |
1474 | int lnum, int offs); | 1476 | int lnum, int offs); |
1475 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, | 1477 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, |
1476 | int offs, int dtype); | 1478 | int offs, int dtype); |
1477 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | 1479 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, |
1478 | int offs, int quiet, int must_chk_crc); | 1480 | int offs, int quiet, int must_chk_crc); |
1479 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); | 1481 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); |
1480 | void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); | 1482 | void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); |
1481 | int ubifs_io_init(struct ubifs_info *c); | 1483 | int ubifs_io_init(struct ubifs_info *c); |
1482 | void ubifs_pad(const struct ubifs_info *c, void *buf, int pad); | 1484 | void ubifs_pad(const struct ubifs_info *c, void *buf, int pad); |
1483 | int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf); | 1485 | int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf); |
1484 | int ubifs_bg_wbufs_sync(struct ubifs_info *c); | 1486 | int ubifs_bg_wbufs_sync(struct ubifs_info *c); |
1485 | void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum); | 1487 | void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum); |
1486 | int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode); | 1488 | int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode); |
1487 | 1489 | ||
1488 | /* scan.c */ | 1490 | /* scan.c */ |
1489 | struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, | 1491 | struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, |
1490 | int offs, void *sbuf, int quiet); | 1492 | int offs, void *sbuf, int quiet); |
1491 | void ubifs_scan_destroy(struct ubifs_scan_leb *sleb); | 1493 | void ubifs_scan_destroy(struct ubifs_scan_leb *sleb); |
1492 | int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, | 1494 | int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, |
1493 | int offs, int quiet); | 1495 | int offs, int quiet); |
1494 | struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum, | 1496 | struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum, |
1495 | int offs, void *sbuf); | 1497 | int offs, void *sbuf); |
1496 | void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb, | 1498 | void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb, |
1497 | int lnum, int offs); | 1499 | int lnum, int offs); |
1498 | int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb, | 1500 | int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb, |
1499 | void *buf, int offs); | 1501 | void *buf, int offs); |
1500 | void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs, | 1502 | void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs, |
1501 | void *buf); | 1503 | void *buf); |
1502 | 1504 | ||
1503 | /* log.c */ | 1505 | /* log.c */ |
1504 | void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud); | 1506 | void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud); |
1505 | void ubifs_create_buds_lists(struct ubifs_info *c); | 1507 | void ubifs_create_buds_lists(struct ubifs_info *c); |
1506 | int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs); | 1508 | int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs); |
1507 | struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum); | 1509 | struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum); |
1508 | struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum); | 1510 | struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum); |
1509 | int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum); | 1511 | int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum); |
1510 | int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum); | 1512 | int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum); |
1511 | int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum); | 1513 | int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum); |
1512 | int ubifs_consolidate_log(struct ubifs_info *c); | 1514 | int ubifs_consolidate_log(struct ubifs_info *c); |
1513 | 1515 | ||
1514 | /* journal.c */ | 1516 | /* journal.c */ |
1515 | int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, | 1517 | int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, |
1516 | const struct qstr *nm, const struct inode *inode, | 1518 | const struct qstr *nm, const struct inode *inode, |
1517 | int deletion, int xent); | 1519 | int deletion, int xent); |
1518 | int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode, | 1520 | int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode, |
1519 | const union ubifs_key *key, const void *buf, int len); | 1521 | const union ubifs_key *key, const void *buf, int len); |
1520 | int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode); | 1522 | int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode); |
1521 | int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode); | 1523 | int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode); |
1522 | int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir, | 1524 | int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir, |
1523 | const struct dentry *old_dentry, | 1525 | const struct dentry *old_dentry, |
1524 | const struct inode *new_dir, | 1526 | const struct inode *new_dir, |
1525 | const struct dentry *new_dentry, int sync); | 1527 | const struct dentry *new_dentry, int sync); |
1526 | int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode, | 1528 | int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode, |
1527 | loff_t old_size, loff_t new_size); | 1529 | loff_t old_size, loff_t new_size); |
1528 | int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host, | 1530 | int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host, |
1529 | const struct inode *inode, const struct qstr *nm); | 1531 | const struct inode *inode, const struct qstr *nm); |
1530 | int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1, | 1532 | int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1, |
1531 | const struct inode *inode2); | 1533 | const struct inode *inode2); |
1532 | 1534 | ||
1533 | /* budget.c */ | 1535 | /* budget.c */ |
1534 | int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req); | 1536 | int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req); |
1535 | void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req); | 1537 | void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req); |
1536 | void ubifs_release_dirty_inode_budget(struct ubifs_info *c, | 1538 | void ubifs_release_dirty_inode_budget(struct ubifs_info *c, |
1537 | struct ubifs_inode *ui); | 1539 | struct ubifs_inode *ui); |
1538 | int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode, | 1540 | int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode, |
1539 | struct ubifs_budget_req *req); | 1541 | struct ubifs_budget_req *req); |
1540 | void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode, | 1542 | void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode, |
1541 | struct ubifs_budget_req *req); | 1543 | struct ubifs_budget_req *req); |
1542 | void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode, | 1544 | void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode, |
1543 | struct ubifs_budget_req *req); | 1545 | struct ubifs_budget_req *req); |
1544 | long long ubifs_get_free_space(struct ubifs_info *c); | 1546 | long long ubifs_get_free_space(struct ubifs_info *c); |
1545 | long long ubifs_get_free_space_nolock(struct ubifs_info *c); | 1547 | long long ubifs_get_free_space_nolock(struct ubifs_info *c); |
1546 | int ubifs_calc_min_idx_lebs(struct ubifs_info *c); | 1548 | int ubifs_calc_min_idx_lebs(struct ubifs_info *c); |
1547 | void ubifs_convert_page_budget(struct ubifs_info *c); | 1549 | void ubifs_convert_page_budget(struct ubifs_info *c); |
1548 | long long ubifs_reported_space(const struct ubifs_info *c, long long free); | 1550 | long long ubifs_reported_space(const struct ubifs_info *c, long long free); |
1549 | long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs); | 1551 | long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs); |
1550 | 1552 | ||
1551 | /* find.c */ | 1553 | /* find.c */ |
1552 | int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs, | 1554 | int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs, |
1553 | int squeeze); | 1555 | int squeeze); |
1554 | int ubifs_find_free_leb_for_idx(struct ubifs_info *c); | 1556 | int ubifs_find_free_leb_for_idx(struct ubifs_info *c); |
1555 | int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp, | 1557 | int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp, |
1556 | int min_space, int pick_free); | 1558 | int min_space, int pick_free); |
1557 | int ubifs_find_dirty_idx_leb(struct ubifs_info *c); | 1559 | int ubifs_find_dirty_idx_leb(struct ubifs_info *c); |
1558 | int ubifs_save_dirty_idx_lnums(struct ubifs_info *c); | 1560 | int ubifs_save_dirty_idx_lnums(struct ubifs_info *c); |
1559 | 1561 | ||
1560 | /* tnc.c */ | 1562 | /* tnc.c */ |
1561 | int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key, | 1563 | int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key, |
1562 | struct ubifs_znode **zn, int *n); | 1564 | struct ubifs_znode **zn, int *n); |
1563 | int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, | 1565 | int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, |
1564 | void *node, const struct qstr *nm); | 1566 | void *node, const struct qstr *nm); |
1565 | int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key, | 1567 | int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key, |
1566 | void *node, int *lnum, int *offs); | 1568 | void *node, int *lnum, int *offs); |
1567 | int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum, | 1569 | int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum, |
1568 | int offs, int len); | 1570 | int offs, int len); |
1569 | int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key, | 1571 | int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key, |
1570 | int old_lnum, int old_offs, int lnum, int offs, int len); | 1572 | int old_lnum, int old_offs, int lnum, int offs, int len); |
1571 | int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key, | 1573 | int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key, |
1572 | int lnum, int offs, int len, const struct qstr *nm); | 1574 | int lnum, int offs, int len, const struct qstr *nm); |
1573 | int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key); | 1575 | int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key); |
1574 | int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key, | 1576 | int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key, |
1575 | const struct qstr *nm); | 1577 | const struct qstr *nm); |
1576 | int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key, | 1578 | int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key, |
1577 | union ubifs_key *to_key); | 1579 | union ubifs_key *to_key); |
1578 | int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum); | 1580 | int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum); |
1579 | struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c, | 1581 | struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c, |
1580 | union ubifs_key *key, | 1582 | union ubifs_key *key, |
1581 | const struct qstr *nm); | 1583 | const struct qstr *nm); |
1582 | void ubifs_tnc_close(struct ubifs_info *c); | 1584 | void ubifs_tnc_close(struct ubifs_info *c); |
1583 | int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level, | 1585 | int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level, |
1584 | int lnum, int offs, int is_idx); | 1586 | int lnum, int offs, int is_idx); |
1585 | int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level, | 1587 | int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level, |
1586 | int lnum, int offs); | 1588 | int lnum, int offs); |
1587 | /* Shared by tnc.c for tnc_commit.c */ | 1589 | /* Shared by tnc.c for tnc_commit.c */ |
1588 | void destroy_old_idx(struct ubifs_info *c); | 1590 | void destroy_old_idx(struct ubifs_info *c); |
1589 | int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, | 1591 | int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, |
1590 | int lnum, int offs); | 1592 | int lnum, int offs); |
1591 | int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode); | 1593 | int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode); |
1592 | int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu); | 1594 | int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu); |
1593 | int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu); | 1595 | int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu); |
1594 | 1596 | ||
1595 | /* tnc_misc.c */ | 1597 | /* tnc_misc.c */ |
1596 | struct ubifs_znode *ubifs_tnc_levelorder_next(struct ubifs_znode *zr, | 1598 | struct ubifs_znode *ubifs_tnc_levelorder_next(struct ubifs_znode *zr, |
1597 | struct ubifs_znode *znode); | 1599 | struct ubifs_znode *znode); |
1598 | int ubifs_search_zbranch(const struct ubifs_info *c, | 1600 | int ubifs_search_zbranch(const struct ubifs_info *c, |
1599 | const struct ubifs_znode *znode, | 1601 | const struct ubifs_znode *znode, |
1600 | const union ubifs_key *key, int *n); | 1602 | const union ubifs_key *key, int *n); |
1601 | struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode); | 1603 | struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode); |
1602 | struct ubifs_znode *ubifs_tnc_postorder_next(struct ubifs_znode *znode); | 1604 | struct ubifs_znode *ubifs_tnc_postorder_next(struct ubifs_znode *znode); |
1603 | long ubifs_destroy_tnc_subtree(struct ubifs_znode *zr); | 1605 | long ubifs_destroy_tnc_subtree(struct ubifs_znode *zr); |
1604 | struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c, | 1606 | struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c, |
1605 | struct ubifs_zbranch *zbr, | 1607 | struct ubifs_zbranch *zbr, |
1606 | struct ubifs_znode *parent, int iip); | 1608 | struct ubifs_znode *parent, int iip); |
1607 | int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr, | 1609 | int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr, |
1608 | void *node); | 1610 | void *node); |
1609 | 1611 | ||
1610 | /* tnc_commit.c */ | 1612 | /* tnc_commit.c */ |
1611 | int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot); | 1613 | int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot); |
1612 | int ubifs_tnc_end_commit(struct ubifs_info *c); | 1614 | int ubifs_tnc_end_commit(struct ubifs_info *c); |
1613 | 1615 | ||
1614 | /* shrinker.c */ | 1616 | /* shrinker.c */ |
1615 | int ubifs_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask); | 1617 | int ubifs_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask); |
1616 | 1618 | ||
1617 | /* commit.c */ | 1619 | /* commit.c */ |
1618 | int ubifs_bg_thread(void *info); | 1620 | int ubifs_bg_thread(void *info); |
1619 | void ubifs_commit_required(struct ubifs_info *c); | 1621 | void ubifs_commit_required(struct ubifs_info *c); |
1620 | void ubifs_request_bg_commit(struct ubifs_info *c); | 1622 | void ubifs_request_bg_commit(struct ubifs_info *c); |
1621 | int ubifs_run_commit(struct ubifs_info *c); | 1623 | int ubifs_run_commit(struct ubifs_info *c); |
1622 | void ubifs_recovery_commit(struct ubifs_info *c); | 1624 | void ubifs_recovery_commit(struct ubifs_info *c); |
1623 | int ubifs_gc_should_commit(struct ubifs_info *c); | 1625 | int ubifs_gc_should_commit(struct ubifs_info *c); |
1624 | void ubifs_wait_for_commit(struct ubifs_info *c); | 1626 | void ubifs_wait_for_commit(struct ubifs_info *c); |
1625 | 1627 | ||
1626 | /* master.c */ | 1628 | /* master.c */ |
1627 | int ubifs_read_master(struct ubifs_info *c); | 1629 | int ubifs_read_master(struct ubifs_info *c); |
1628 | int ubifs_write_master(struct ubifs_info *c); | 1630 | int ubifs_write_master(struct ubifs_info *c); |
1629 | 1631 | ||
1630 | /* sb.c */ | 1632 | /* sb.c */ |
1631 | int ubifs_read_superblock(struct ubifs_info *c); | 1633 | int ubifs_read_superblock(struct ubifs_info *c); |
1632 | struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c); | 1634 | struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c); |
1633 | int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup); | 1635 | int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup); |
1634 | 1636 | ||
1635 | /* replay.c */ | 1637 | /* replay.c */ |
1636 | int ubifs_validate_entry(struct ubifs_info *c, | 1638 | int ubifs_validate_entry(struct ubifs_info *c, |
1637 | const struct ubifs_dent_node *dent); | 1639 | const struct ubifs_dent_node *dent); |
1638 | int ubifs_replay_journal(struct ubifs_info *c); | 1640 | int ubifs_replay_journal(struct ubifs_info *c); |
1639 | 1641 | ||
1640 | /* gc.c */ | 1642 | /* gc.c */ |
1641 | int ubifs_garbage_collect(struct ubifs_info *c, int anyway); | 1643 | int ubifs_garbage_collect(struct ubifs_info *c, int anyway); |
1642 | int ubifs_gc_start_commit(struct ubifs_info *c); | 1644 | int ubifs_gc_start_commit(struct ubifs_info *c); |
1643 | int ubifs_gc_end_commit(struct ubifs_info *c); | 1645 | int ubifs_gc_end_commit(struct ubifs_info *c); |
1644 | void ubifs_destroy_idx_gc(struct ubifs_info *c); | 1646 | void ubifs_destroy_idx_gc(struct ubifs_info *c); |
1645 | int ubifs_get_idx_gc_leb(struct ubifs_info *c); | 1647 | int ubifs_get_idx_gc_leb(struct ubifs_info *c); |
1646 | int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp); | 1648 | int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp); |
1647 | 1649 | ||
1648 | /* orphan.c */ | 1650 | /* orphan.c */ |
1649 | int ubifs_add_orphan(struct ubifs_info *c, ino_t inum); | 1651 | int ubifs_add_orphan(struct ubifs_info *c, ino_t inum); |
1650 | void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum); | 1652 | void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum); |
1651 | int ubifs_orphan_start_commit(struct ubifs_info *c); | 1653 | int ubifs_orphan_start_commit(struct ubifs_info *c); |
1652 | int ubifs_orphan_end_commit(struct ubifs_info *c); | 1654 | int ubifs_orphan_end_commit(struct ubifs_info *c); |
1653 | int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only); | 1655 | int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only); |
1654 | int ubifs_clear_orphans(struct ubifs_info *c); | 1656 | int ubifs_clear_orphans(struct ubifs_info *c); |
1655 | 1657 | ||
1656 | /* lpt.c */ | 1658 | /* lpt.c */ |
1657 | int ubifs_calc_lpt_geom(struct ubifs_info *c); | 1659 | int ubifs_calc_lpt_geom(struct ubifs_info *c); |
1658 | int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, | 1660 | int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, |
1659 | int *lpt_lebs, int *big_lpt); | 1661 | int *lpt_lebs, int *big_lpt); |
1660 | int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr); | 1662 | int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr); |
1661 | struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum); | 1663 | struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum); |
1662 | struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum); | 1664 | struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum); |
1663 | int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum, | 1665 | int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum, |
1664 | ubifs_lpt_scan_callback scan_cb, void *data); | 1666 | ubifs_lpt_scan_callback scan_cb, void *data); |
1665 | 1667 | ||
1666 | /* Shared by lpt.c for lpt_commit.c */ | 1668 | /* Shared by lpt.c for lpt_commit.c */ |
1667 | void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave); | 1669 | void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave); |
1668 | void ubifs_pack_ltab(struct ubifs_info *c, void *buf, | 1670 | void ubifs_pack_ltab(struct ubifs_info *c, void *buf, |
1669 | struct ubifs_lpt_lprops *ltab); | 1671 | struct ubifs_lpt_lprops *ltab); |
1670 | void ubifs_pack_pnode(struct ubifs_info *c, void *buf, | 1672 | void ubifs_pack_pnode(struct ubifs_info *c, void *buf, |
1671 | struct ubifs_pnode *pnode); | 1673 | struct ubifs_pnode *pnode); |
1672 | void ubifs_pack_nnode(struct ubifs_info *c, void *buf, | 1674 | void ubifs_pack_nnode(struct ubifs_info *c, void *buf, |
1673 | struct ubifs_nnode *nnode); | 1675 | struct ubifs_nnode *nnode); |
1674 | struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c, | 1676 | struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c, |
1675 | struct ubifs_nnode *parent, int iip); | 1677 | struct ubifs_nnode *parent, int iip); |
1676 | struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c, | 1678 | struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c, |
1677 | struct ubifs_nnode *parent, int iip); | 1679 | struct ubifs_nnode *parent, int iip); |
1678 | int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip); | 1680 | int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip); |
1679 | void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty); | 1681 | void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty); |
1680 | void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode); | 1682 | void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode); |
1681 | uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits); | 1683 | uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits); |
1682 | struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght); | 1684 | struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght); |
1683 | /* Needed only in debugging code in lpt_commit.c */ | 1685 | /* Needed only in debugging code in lpt_commit.c */ |
1684 | int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf, | 1686 | int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf, |
1685 | struct ubifs_nnode *nnode); | 1687 | struct ubifs_nnode *nnode); |
1686 | 1688 | ||
1687 | /* lpt_commit.c */ | 1689 | /* lpt_commit.c */ |
1688 | int ubifs_lpt_start_commit(struct ubifs_info *c); | 1690 | int ubifs_lpt_start_commit(struct ubifs_info *c); |
1689 | int ubifs_lpt_end_commit(struct ubifs_info *c); | 1691 | int ubifs_lpt_end_commit(struct ubifs_info *c); |
1690 | int ubifs_lpt_post_commit(struct ubifs_info *c); | 1692 | int ubifs_lpt_post_commit(struct ubifs_info *c); |
1691 | void ubifs_lpt_free(struct ubifs_info *c, int wr_only); | 1693 | void ubifs_lpt_free(struct ubifs_info *c, int wr_only); |
1692 | 1694 | ||
1693 | /* lprops.c */ | 1695 | /* lprops.c */ |
1694 | const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, | 1696 | const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, |
1695 | const struct ubifs_lprops *lp, | 1697 | const struct ubifs_lprops *lp, |
1696 | int free, int dirty, int flags, | 1698 | int free, int dirty, int flags, |
1697 | int idx_gc_cnt); | 1699 | int idx_gc_cnt); |
1698 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst); | 1700 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst); |
1699 | void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, | 1701 | void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, |
1700 | int cat); | 1702 | int cat); |
1701 | void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops, | 1703 | void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops, |
1702 | struct ubifs_lprops *new_lprops); | 1704 | struct ubifs_lprops *new_lprops); |
1703 | void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops); | 1705 | void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops); |
1704 | int ubifs_categorize_lprops(const struct ubifs_info *c, | 1706 | int ubifs_categorize_lprops(const struct ubifs_info *c, |
1705 | const struct ubifs_lprops *lprops); | 1707 | const struct ubifs_lprops *lprops); |
1706 | int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, | 1708 | int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, |
1707 | int flags_set, int flags_clean, int idx_gc_cnt); | 1709 | int flags_set, int flags_clean, int idx_gc_cnt); |
1708 | int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, | 1710 | int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, |
1709 | int flags_set, int flags_clean); | 1711 | int flags_set, int flags_clean); |
1710 | int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp); | 1712 | int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp); |
1711 | const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c); | 1713 | const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c); |
1712 | const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c); | 1714 | const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c); |
1713 | const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c); | 1715 | const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c); |
1714 | const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c); | 1716 | const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c); |
1715 | int ubifs_calc_dark(const struct ubifs_info *c, int spc); | 1717 | int ubifs_calc_dark(const struct ubifs_info *c, int spc); |
1716 | 1718 | ||
1717 | /* file.c */ | 1719 | /* file.c */ |
1718 | int ubifs_fsync(struct file *file, int datasync); | 1720 | int ubifs_fsync(struct file *file, int datasync); |
1719 | int ubifs_setattr(struct dentry *dentry, struct iattr *attr); | 1721 | int ubifs_setattr(struct dentry *dentry, struct iattr *attr); |
1720 | 1722 | ||
1721 | /* dir.c */ | 1723 | /* dir.c */ |
1722 | struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir, | 1724 | struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir, |
1723 | int mode); | 1725 | int mode); |
1724 | int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry, | 1726 | int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
1725 | struct kstat *stat); | 1727 | struct kstat *stat); |
1726 | 1728 | ||
1727 | /* xattr.c */ | 1729 | /* xattr.c */ |
1728 | int ubifs_setxattr(struct dentry *dentry, const char *name, | 1730 | int ubifs_setxattr(struct dentry *dentry, const char *name, |
1729 | const void *value, size_t size, int flags); | 1731 | const void *value, size_t size, int flags); |
1730 | ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf, | 1732 | ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf, |
1731 | size_t size); | 1733 | size_t size); |
1732 | ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size); | 1734 | ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
1733 | int ubifs_removexattr(struct dentry *dentry, const char *name); | 1735 | int ubifs_removexattr(struct dentry *dentry, const char *name); |
1734 | 1736 | ||
1735 | /* super.c */ | 1737 | /* super.c */ |
1736 | struct inode *ubifs_iget(struct super_block *sb, unsigned long inum); | 1738 | struct inode *ubifs_iget(struct super_block *sb, unsigned long inum); |
1737 | 1739 | ||
1738 | /* recovery.c */ | 1740 | /* recovery.c */ |
1739 | int ubifs_recover_master_node(struct ubifs_info *c); | 1741 | int ubifs_recover_master_node(struct ubifs_info *c); |
1740 | int ubifs_write_rcvrd_mst_node(struct ubifs_info *c); | 1742 | int ubifs_write_rcvrd_mst_node(struct ubifs_info *c); |
1741 | struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum, | 1743 | struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum, |
1742 | int offs, void *sbuf, int grouped); | 1744 | int offs, void *sbuf, int grouped); |
1743 | struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum, | 1745 | struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum, |
1744 | int offs, void *sbuf); | 1746 | int offs, void *sbuf); |
1745 | int ubifs_recover_inl_heads(const struct ubifs_info *c, void *sbuf); | 1747 | int ubifs_recover_inl_heads(const struct ubifs_info *c, void *sbuf); |
1746 | int ubifs_clean_lebs(const struct ubifs_info *c, void *sbuf); | 1748 | int ubifs_clean_lebs(const struct ubifs_info *c, void *sbuf); |
1747 | int ubifs_rcvry_gc_commit(struct ubifs_info *c); | 1749 | int ubifs_rcvry_gc_commit(struct ubifs_info *c); |
1748 | int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key, | 1750 | int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key, |
1749 | int deletion, loff_t new_size); | 1751 | int deletion, loff_t new_size); |
1750 | int ubifs_recover_size(struct ubifs_info *c); | 1752 | int ubifs_recover_size(struct ubifs_info *c); |
1751 | void ubifs_destroy_size_tree(struct ubifs_info *c); | 1753 | void ubifs_destroy_size_tree(struct ubifs_info *c); |
1752 | 1754 | ||
1753 | /* ioctl.c */ | 1755 | /* ioctl.c */ |
1754 | long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 1756 | long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
1755 | void ubifs_set_inode_flags(struct inode *inode); | 1757 | void ubifs_set_inode_flags(struct inode *inode); |
1756 | #ifdef CONFIG_COMPAT | 1758 | #ifdef CONFIG_COMPAT |
1757 | long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 1759 | long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
1758 | #endif | 1760 | #endif |
1759 | 1761 | ||
1760 | /* compressor.c */ | 1762 | /* compressor.c */ |
1761 | int __init ubifs_compressors_init(void); | 1763 | int __init ubifs_compressors_init(void); |
1762 | void ubifs_compressors_exit(void); | 1764 | void ubifs_compressors_exit(void); |
1763 | void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len, | 1765 | void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len, |
1764 | int *compr_type); | 1766 | int *compr_type); |
1765 | int ubifs_decompress(const void *buf, int len, void *out, int *out_len, | 1767 | int ubifs_decompress(const void *buf, int len, void *out, int *out_len, |
1766 | int compr_type); | 1768 | int compr_type); |
1767 | 1769 | ||
1768 | #include "debug.h" | 1770 | #include "debug.h" |
1769 | #include "misc.h" | 1771 | #include "misc.h" |
1770 | #include "key.h" | 1772 | #include "key.h" |
1771 | 1773 | ||
1772 | #endif /* !__UBIFS_H__ */ | 1774 | #endif /* !__UBIFS_H__ */ |
1773 | 1775 |