Lines Matching full:c
5 * Copyright (C) 2006-2008 Nokia Corporation.
17 * @c: UBIFS file-system description object
24 int ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2) in ubifs_compare_master_node() argument
52 * @c: UBIFS file-system description object
64 static int mst_node_check_hash(const struct ubifs_info *c, in mst_node_check_hash() argument
71 crypto_shash_tfm_digest(c->hash_tfm, node + sizeof(struct ubifs_ch), in mst_node_check_hash()
75 if (ubifs_check_hash(c, expected, calc)) in mst_node_check_hash()
83 * @c: UBIFS file-system description object
90 static int scan_for_master(struct ubifs_info *c) in scan_for_master() argument
98 sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1); in scan_for_master()
107 memcpy(c->mst_node, snod->node, snod->len); in scan_for_master()
114 sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1); in scan_for_master()
126 if (ubifs_compare_master_node(c, c->mst_node, snod->node)) in scan_for_master()
129 c->mst_offs = offs; in scan_for_master()
132 if (!ubifs_authenticated(c)) in scan_for_master()
135 if (ubifs_hmac_zero(c, c->mst_node->hmac)) { in scan_for_master()
136 err = mst_node_check_hash(c, c->mst_node, in scan_for_master()
137 c->sup_node->hash_mst); in scan_for_master()
139 ubifs_err(c, "Failed to verify master node hash"); in scan_for_master()
141 err = ubifs_node_verify_hmac(c, c->mst_node, in scan_for_master()
145 ubifs_err(c, "Failed to verify master node HMAC"); in scan_for_master()
158 ubifs_err(c, "unexpected node type %d master LEB %d:%d", in scan_for_master()
166 * @c: UBIFS file-system description object
171 static int validate_master(const struct ubifs_info *c) in validate_master() argument
176 if (c->max_sqnum >= SQNUM_WATERMARK) { in validate_master()
181 if (c->cmt_no >= c->max_sqnum) { in validate_master()
186 if (c->highest_inum >= INUM_WATERMARK) { in validate_master()
191 if (c->lhead_lnum < UBIFS_LOG_LNUM || in validate_master()
192 c->lhead_lnum >= UBIFS_LOG_LNUM + c->log_lebs || in validate_master()
193 c->lhead_offs < 0 || c->lhead_offs >= c->leb_size || in validate_master()
194 c->lhead_offs & (c->min_io_size - 1)) { in validate_master()
199 if (c->zroot.lnum >= c->leb_cnt || c->zroot.lnum < c->main_first || in validate_master()
200 c->zroot.offs >= c->leb_size || c->zroot.offs & 7) { in validate_master()
205 if (c->zroot.len < c->ranges[UBIFS_IDX_NODE].min_len || in validate_master()
206 c->zroot.len > c->ranges[UBIFS_IDX_NODE].max_len) { in validate_master()
211 if (c->gc_lnum >= c->leb_cnt || c->gc_lnum < c->main_first) { in validate_master()
216 if (c->ihead_lnum >= c->leb_cnt || c->ihead_lnum < c->main_first || in validate_master()
217 c->ihead_offs % c->min_io_size || c->ihead_offs < 0 || in validate_master()
218 c->ihead_offs > c->leb_size || c->ihead_offs & 7) { in validate_master()
223 main_sz = (long long)c->main_lebs * c->leb_size; in validate_master()
224 if (c->bi.old_idx_sz & 7 || c->bi.old_idx_sz >= main_sz) { in validate_master()
229 if (c->lpt_lnum < c->lpt_first || c->lpt_lnum > c->lpt_last || in validate_master()
230 c->lpt_offs < 0 || c->lpt_offs + c->nnode_sz > c->leb_size) { in validate_master()
235 if (c->nhead_lnum < c->lpt_first || c->nhead_lnum > c->lpt_last || in validate_master()
236 c->nhead_offs < 0 || c->nhead_offs % c->min_io_size || in validate_master()
237 c->nhead_offs > c->leb_size) { in validate_master()
242 if (c->ltab_lnum < c->lpt_first || c->ltab_lnum > c->lpt_last || in validate_master()
243 c->ltab_offs < 0 || in validate_master()
244 c->ltab_offs + c->ltab_sz > c->leb_size) { in validate_master()
249 if (c->big_lpt && (c->lsave_lnum < c->lpt_first || in validate_master()
250 c->lsave_lnum > c->lpt_last || c->lsave_offs < 0 || in validate_master()
251 c->lsave_offs + c->lsave_sz > c->leb_size)) { in validate_master()
256 if (c->lscan_lnum < c->main_first || c->lscan_lnum >= c->leb_cnt) { in validate_master()
261 if (c->lst.empty_lebs < 0 || c->lst.empty_lebs > c->main_lebs - 2) { in validate_master()
266 if (c->lst.idx_lebs < 0 || c->lst.idx_lebs > c->main_lebs - 1) { in validate_master()
271 if (c->lst.total_free < 0 || c->lst.total_free > main_sz || in validate_master()
272 c->lst.total_free & 7) { in validate_master()
277 if (c->lst.total_dirty < 0 || (c->lst.total_dirty & 7)) { in validate_master()
282 if (c->lst.total_used < 0 || (c->lst.total_used & 7)) { in validate_master()
287 if (c->lst.total_free + c->lst.total_dirty + in validate_master()
288 c->lst.total_used > main_sz) { in validate_master()
293 if (c->lst.total_dead + c->lst.total_dark + in validate_master()
294 c->lst.total_used + c->bi.old_idx_sz > main_sz) { in validate_master()
299 if (c->lst.total_dead < 0 || in validate_master()
300 c->lst.total_dead > c->lst.total_free + c->lst.total_dirty || in validate_master()
301 c->lst.total_dead & 7) { in validate_master()
306 if (c->lst.total_dark < 0 || in validate_master()
307 c->lst.total_dark > c->lst.total_free + c->lst.total_dirty || in validate_master()
308 c->lst.total_dark & 7) { in validate_master()
316 ubifs_err(c, "bad master node at offset %d error %d", c->mst_offs, err); in validate_master()
317 ubifs_dump_node(c, c->mst_node); in validate_master()
323 * @c: UBIFS file-system description object
329 int ubifs_read_master(struct ubifs_info *c) in ubifs_read_master() argument
333 c->mst_node = kzalloc(c->mst_node_alsz, GFP_KERNEL); in ubifs_read_master()
334 if (!c->mst_node) in ubifs_read_master()
337 err = scan_for_master(c); in ubifs_read_master()
340 err = ubifs_recover_master_node(c); in ubifs_read_master()
343 * Note, we do not free 'c->mst_node' here because the in ubifs_read_master()
350 c->mst_node->flags &= cpu_to_le32(~UBIFS_MST_RCVRY); in ubifs_read_master()
352 c->max_sqnum = le64_to_cpu(c->mst_node->ch.sqnum); in ubifs_read_master()
353 c->highest_inum = le64_to_cpu(c->mst_node->highest_inum); in ubifs_read_master()
354 c->cmt_no = le64_to_cpu(c->mst_node->cmt_no); in ubifs_read_master()
355 c->zroot.lnum = le32_to_cpu(c->mst_node->root_lnum); in ubifs_read_master()
356 c->zroot.offs = le32_to_cpu(c->mst_node->root_offs); in ubifs_read_master()
357 c->zroot.len = le32_to_cpu(c->mst_node->root_len); in ubifs_read_master()
358 c->lhead_lnum = le32_to_cpu(c->mst_node->log_lnum); in ubifs_read_master()
359 c->gc_lnum = le32_to_cpu(c->mst_node->gc_lnum); in ubifs_read_master()
360 c->ihead_lnum = le32_to_cpu(c->mst_node->ihead_lnum); in ubifs_read_master()
361 c->ihead_offs = le32_to_cpu(c->mst_node->ihead_offs); in ubifs_read_master()
362 c->bi.old_idx_sz = le64_to_cpu(c->mst_node->index_size); in ubifs_read_master()
363 c->lpt_lnum = le32_to_cpu(c->mst_node->lpt_lnum); in ubifs_read_master()
364 c->lpt_offs = le32_to_cpu(c->mst_node->lpt_offs); in ubifs_read_master()
365 c->nhead_lnum = le32_to_cpu(c->mst_node->nhead_lnum); in ubifs_read_master()
366 c->nhead_offs = le32_to_cpu(c->mst_node->nhead_offs); in ubifs_read_master()
367 c->ltab_lnum = le32_to_cpu(c->mst_node->ltab_lnum); in ubifs_read_master()
368 c->ltab_offs = le32_to_cpu(c->mst_node->ltab_offs); in ubifs_read_master()
369 c->lsave_lnum = le32_to_cpu(c->mst_node->lsave_lnum); in ubifs_read_master()
370 c->lsave_offs = le32_to_cpu(c->mst_node->lsave_offs); in ubifs_read_master()
371 c->lscan_lnum = le32_to_cpu(c->mst_node->lscan_lnum); in ubifs_read_master()
372 c->lst.empty_lebs = le32_to_cpu(c->mst_node->empty_lebs); in ubifs_read_master()
373 c->lst.idx_lebs = le32_to_cpu(c->mst_node->idx_lebs); in ubifs_read_master()
374 old_leb_cnt = le32_to_cpu(c->mst_node->leb_cnt); in ubifs_read_master()
375 c->lst.total_free = le64_to_cpu(c->mst_node->total_free); in ubifs_read_master()
376 c->lst.total_dirty = le64_to_cpu(c->mst_node->total_dirty); in ubifs_read_master()
377 c->lst.total_used = le64_to_cpu(c->mst_node->total_used); in ubifs_read_master()
378 c->lst.total_dead = le64_to_cpu(c->mst_node->total_dead); in ubifs_read_master()
379 c->lst.total_dark = le64_to_cpu(c->mst_node->total_dark); in ubifs_read_master()
381 ubifs_copy_hash(c, c->mst_node->hash_root_idx, c->zroot.hash); in ubifs_read_master()
383 c->calc_idx_sz = c->bi.old_idx_sz; in ubifs_read_master()
385 if (c->mst_node->flags & cpu_to_le32(UBIFS_MST_NO_ORPHS)) in ubifs_read_master()
386 c->no_orphs = 1; in ubifs_read_master()
388 if (old_leb_cnt != c->leb_cnt) { in ubifs_read_master()
390 int growth = c->leb_cnt - old_leb_cnt; in ubifs_read_master()
392 if (c->leb_cnt < old_leb_cnt || in ubifs_read_master()
393 c->leb_cnt < UBIFS_MIN_LEB_CNT) { in ubifs_read_master()
394 ubifs_err(c, "bad leb_cnt on master node"); in ubifs_read_master()
395 ubifs_dump_node(c, c->mst_node); in ubifs_read_master()
400 old_leb_cnt, c->leb_cnt); in ubifs_read_master()
401 c->lst.empty_lebs += growth; in ubifs_read_master()
402 c->lst.total_free += growth * (long long)c->leb_size; in ubifs_read_master()
403 c->lst.total_dark += growth * (long long)c->dark_wm; in ubifs_read_master()
411 c->mst_node->leb_cnt = cpu_to_le32(c->leb_cnt); in ubifs_read_master()
412 c->mst_node->empty_lebs = cpu_to_le32(c->lst.empty_lebs); in ubifs_read_master()
413 c->mst_node->total_free = cpu_to_le64(c->lst.total_free); in ubifs_read_master()
414 c->mst_node->total_dark = cpu_to_le64(c->lst.total_dark); in ubifs_read_master()
417 err = validate_master(c); in ubifs_read_master()
421 err = dbg_old_index_check_init(c, &c->zroot); in ubifs_read_master()
428 * @c: UBIFS file-system description object
434 int ubifs_write_master(struct ubifs_info *c) in ubifs_write_master() argument
438 ubifs_assert(c, !c->ro_media && !c->ro_mount); in ubifs_write_master()
439 if (c->ro_error) in ubifs_write_master()
443 offs = c->mst_offs + c->mst_node_alsz; in ubifs_write_master()
446 if (offs + UBIFS_MST_NODE_SZ > c->leb_size) { in ubifs_write_master()
447 err = ubifs_leb_unmap(c, lnum); in ubifs_write_master()
453 c->mst_offs = offs; in ubifs_write_master()
454 c->mst_node->highest_inum = cpu_to_le64(c->highest_inum); in ubifs_write_master()
456 ubifs_copy_hash(c, c->zroot.hash, c->mst_node->hash_root_idx); in ubifs_write_master()
457 err = ubifs_write_node_hmac(c, c->mst_node, len, lnum, offs, in ubifs_write_master()
465 err = ubifs_leb_unmap(c, lnum); in ubifs_write_master()
469 err = ubifs_write_node_hmac(c, c->mst_node, len, lnum, offs, in ubifs_write_master()