Lines Matching +full:- +full:c
4 * Copyright (C) 2006-2008 Nokia Corporation
6 * SPDX-License-Identifier: GPL-2.0+
101 const char *dbg_snprintf_key(const struct ubifs_info *c, in dbg_snprintf_key() argument
105 int type = key_type(c, key); in dbg_snprintf_key()
107 if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { in dbg_snprintf_key()
110 len -= snprintf(p, len, "(%lu, %s)", in dbg_snprintf_key()
111 (unsigned long)key_inum(c, key), in dbg_snprintf_key()
116 len -= snprintf(p, len, "(%lu, %s, %#08x)", in dbg_snprintf_key()
117 (unsigned long)key_inum(c, key), in dbg_snprintf_key()
118 get_key_type(type), key_hash(c, key)); in dbg_snprintf_key()
121 len -= snprintf(p, len, "(%lu, %s, %u)", in dbg_snprintf_key()
122 (unsigned long)key_inum(c, key), in dbg_snprintf_key()
123 get_key_type(type), key_block(c, key)); in dbg_snprintf_key()
126 len -= snprintf(p, len, "(%lu, %s)", in dbg_snprintf_key()
127 (unsigned long)key_inum(c, key), in dbg_snprintf_key()
131 len -= snprintf(p, len, "(bad key type: %#08x, %#08x)", in dbg_snprintf_key()
132 key->u32[0], key->u32[1]); in dbg_snprintf_key()
135 len -= snprintf(p, len, "bad key format %d", c->key_fmt); in dbg_snprintf_key()
222 pr_err("\tmagic %#x\n", le32_to_cpu(ch->magic)); in dump_ch()
223 pr_err("\tcrc %#x\n", le32_to_cpu(ch->crc)); in dump_ch()
224 pr_err("\tnode_type %d (%s)\n", ch->node_type, in dump_ch()
225 dbg_ntype(ch->node_type)); in dump_ch()
226 pr_err("\tgroup_type %d (%s)\n", ch->group_type, in dump_ch()
227 dbg_gtype(ch->group_type)); in dump_ch()
229 (unsigned long long)le64_to_cpu(ch->sqnum)); in dump_ch()
230 pr_err("\tlen %u\n", le32_to_cpu(ch->len)); in dump_ch()
233 void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode) in ubifs_dump_inode() argument
242 pr_err("Dump in-memory inode:"); in ubifs_dump_inode()
243 pr_err("\tinode %lu\n", inode->i_ino); in ubifs_dump_inode()
246 pr_err("\tnlink %u\n", inode->i_nlink); in ubifs_dump_inode()
250 (unsigned int)inode->i_atime.tv_sec, in ubifs_dump_inode()
251 (unsigned int)inode->i_atime.tv_nsec); in ubifs_dump_inode()
253 (unsigned int)inode->i_mtime.tv_sec, in ubifs_dump_inode()
254 (unsigned int)inode->i_mtime.tv_nsec); in ubifs_dump_inode()
256 (unsigned int)inode->i_ctime.tv_sec, in ubifs_dump_inode()
257 (unsigned int)inode->i_ctime.tv_nsec); in ubifs_dump_inode()
258 pr_err("\tcreat_sqnum %llu\n", ui->creat_sqnum); in ubifs_dump_inode()
259 pr_err("\txattr_size %u\n", ui->xattr_size); in ubifs_dump_inode()
260 pr_err("\txattr_cnt %u\n", ui->xattr_cnt); in ubifs_dump_inode()
261 pr_err("\txattr_names %u\n", ui->xattr_names); in ubifs_dump_inode()
262 pr_err("\tdirty %u\n", ui->dirty); in ubifs_dump_inode()
263 pr_err("\txattr %u\n", ui->xattr); in ubifs_dump_inode()
264 pr_err("\tbulk_read %u\n", ui->xattr); in ubifs_dump_inode()
266 (unsigned long long)ui->synced_i_size); in ubifs_dump_inode()
268 (unsigned long long)ui->ui_size); in ubifs_dump_inode()
269 pr_err("\tflags %d\n", ui->flags); in ubifs_dump_inode()
270 pr_err("\tcompr_type %d\n", ui->compr_type); in ubifs_dump_inode()
271 pr_err("\tlast_page_read %lu\n", ui->last_page_read); in ubifs_dump_inode()
272 pr_err("\tread_in_a_row %lu\n", ui->read_in_a_row); in ubifs_dump_inode()
273 pr_err("\tdata_len %d\n", ui->data_len); in ubifs_dump_inode()
275 if (!S_ISDIR(inode->i_mode)) in ubifs_dump_inode()
279 ubifs_assert(!mutex_is_locked(&c->tnc_mutex)); in ubifs_dump_inode()
281 lowest_dent_key(c, &key, inode->i_ino); in ubifs_dump_inode()
283 dent = ubifs_tnc_next_ent(c, &key, &nm); in ubifs_dump_inode()
285 if (PTR_ERR(dent) != -ENOENT) in ubifs_dump_inode()
291 count++, dent->name, get_dent_type(dent->type)); in ubifs_dump_inode()
293 nm.name = dent->name; in ubifs_dump_inode()
294 nm.len = le16_to_cpu(dent->nlen); in ubifs_dump_inode()
297 key_read(c, &dent->key, &key); in ubifs_dump_inode()
303 void ubifs_dump_node(const struct ubifs_info *c, const void *node) in ubifs_dump_node() argument
311 if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) { in ubifs_dump_node()
321 switch (ch->node_type) { in ubifs_dump_node()
326 pr_err("\tpad_len %u\n", le32_to_cpu(pad->pad_len)); in ubifs_dump_node()
332 unsigned int sup_flags = le32_to_cpu(sup->flags); in ubifs_dump_node()
335 (int)sup->key_hash, get_key_hash(sup->key_hash)); in ubifs_dump_node()
337 (int)sup->key_fmt, get_key_fmt(sup->key_fmt)); in ubifs_dump_node()
343 pr_err("\tmin_io_size %u\n", le32_to_cpu(sup->min_io_size)); in ubifs_dump_node()
344 pr_err("\tleb_size %u\n", le32_to_cpu(sup->leb_size)); in ubifs_dump_node()
345 pr_err("\tleb_cnt %u\n", le32_to_cpu(sup->leb_cnt)); in ubifs_dump_node()
346 pr_err("\tmax_leb_cnt %u\n", le32_to_cpu(sup->max_leb_cnt)); in ubifs_dump_node()
348 (unsigned long long)le64_to_cpu(sup->max_bud_bytes)); in ubifs_dump_node()
349 pr_err("\tlog_lebs %u\n", le32_to_cpu(sup->log_lebs)); in ubifs_dump_node()
350 pr_err("\tlpt_lebs %u\n", le32_to_cpu(sup->lpt_lebs)); in ubifs_dump_node()
351 pr_err("\torph_lebs %u\n", le32_to_cpu(sup->orph_lebs)); in ubifs_dump_node()
352 pr_err("\tjhead_cnt %u\n", le32_to_cpu(sup->jhead_cnt)); in ubifs_dump_node()
353 pr_err("\tfanout %u\n", le32_to_cpu(sup->fanout)); in ubifs_dump_node()
354 pr_err("\tlsave_cnt %u\n", le32_to_cpu(sup->lsave_cnt)); in ubifs_dump_node()
356 (int)le16_to_cpu(sup->default_compr)); in ubifs_dump_node()
358 (unsigned long long)le64_to_cpu(sup->rp_size)); in ubifs_dump_node()
359 pr_err("\trp_uid %u\n", le32_to_cpu(sup->rp_uid)); in ubifs_dump_node()
360 pr_err("\trp_gid %u\n", le32_to_cpu(sup->rp_gid)); in ubifs_dump_node()
361 pr_err("\tfmt_version %u\n", le32_to_cpu(sup->fmt_version)); in ubifs_dump_node()
362 pr_err("\ttime_gran %u\n", le32_to_cpu(sup->time_gran)); in ubifs_dump_node()
363 pr_err("\tUUID %pUB\n", sup->uuid); in ubifs_dump_node()
371 (unsigned long long)le64_to_cpu(mst->highest_inum)); in ubifs_dump_node()
373 (unsigned long long)le64_to_cpu(mst->cmt_no)); in ubifs_dump_node()
374 pr_err("\tflags %#x\n", le32_to_cpu(mst->flags)); in ubifs_dump_node()
375 pr_err("\tlog_lnum %u\n", le32_to_cpu(mst->log_lnum)); in ubifs_dump_node()
376 pr_err("\troot_lnum %u\n", le32_to_cpu(mst->root_lnum)); in ubifs_dump_node()
377 pr_err("\troot_offs %u\n", le32_to_cpu(mst->root_offs)); in ubifs_dump_node()
378 pr_err("\troot_len %u\n", le32_to_cpu(mst->root_len)); in ubifs_dump_node()
379 pr_err("\tgc_lnum %u\n", le32_to_cpu(mst->gc_lnum)); in ubifs_dump_node()
380 pr_err("\tihead_lnum %u\n", le32_to_cpu(mst->ihead_lnum)); in ubifs_dump_node()
381 pr_err("\tihead_offs %u\n", le32_to_cpu(mst->ihead_offs)); in ubifs_dump_node()
383 (unsigned long long)le64_to_cpu(mst->index_size)); in ubifs_dump_node()
384 pr_err("\tlpt_lnum %u\n", le32_to_cpu(mst->lpt_lnum)); in ubifs_dump_node()
385 pr_err("\tlpt_offs %u\n", le32_to_cpu(mst->lpt_offs)); in ubifs_dump_node()
386 pr_err("\tnhead_lnum %u\n", le32_to_cpu(mst->nhead_lnum)); in ubifs_dump_node()
387 pr_err("\tnhead_offs %u\n", le32_to_cpu(mst->nhead_offs)); in ubifs_dump_node()
388 pr_err("\tltab_lnum %u\n", le32_to_cpu(mst->ltab_lnum)); in ubifs_dump_node()
389 pr_err("\tltab_offs %u\n", le32_to_cpu(mst->ltab_offs)); in ubifs_dump_node()
390 pr_err("\tlsave_lnum %u\n", le32_to_cpu(mst->lsave_lnum)); in ubifs_dump_node()
391 pr_err("\tlsave_offs %u\n", le32_to_cpu(mst->lsave_offs)); in ubifs_dump_node()
392 pr_err("\tlscan_lnum %u\n", le32_to_cpu(mst->lscan_lnum)); in ubifs_dump_node()
393 pr_err("\tleb_cnt %u\n", le32_to_cpu(mst->leb_cnt)); in ubifs_dump_node()
394 pr_err("\tempty_lebs %u\n", le32_to_cpu(mst->empty_lebs)); in ubifs_dump_node()
395 pr_err("\tidx_lebs %u\n", le32_to_cpu(mst->idx_lebs)); in ubifs_dump_node()
397 (unsigned long long)le64_to_cpu(mst->total_free)); in ubifs_dump_node()
399 (unsigned long long)le64_to_cpu(mst->total_dirty)); in ubifs_dump_node()
401 (unsigned long long)le64_to_cpu(mst->total_used)); in ubifs_dump_node()
403 (unsigned long long)le64_to_cpu(mst->total_dead)); in ubifs_dump_node()
405 (unsigned long long)le64_to_cpu(mst->total_dark)); in ubifs_dump_node()
412 pr_err("\tlnum %u\n", le32_to_cpu(ref->lnum)); in ubifs_dump_node()
413 pr_err("\toffs %u\n", le32_to_cpu(ref->offs)); in ubifs_dump_node()
414 pr_err("\tjhead %u\n", le32_to_cpu(ref->jhead)); in ubifs_dump_node()
421 key_read(c, &ino->key, &key); in ubifs_dump_node()
423 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); in ubifs_dump_node()
425 (unsigned long long)le64_to_cpu(ino->creat_sqnum)); in ubifs_dump_node()
427 (unsigned long long)le64_to_cpu(ino->size)); in ubifs_dump_node()
428 pr_err("\tnlink %u\n", le32_to_cpu(ino->nlink)); in ubifs_dump_node()
430 (long long)le64_to_cpu(ino->atime_sec), in ubifs_dump_node()
431 le32_to_cpu(ino->atime_nsec)); in ubifs_dump_node()
433 (long long)le64_to_cpu(ino->mtime_sec), in ubifs_dump_node()
434 le32_to_cpu(ino->mtime_nsec)); in ubifs_dump_node()
436 (long long)le64_to_cpu(ino->ctime_sec), in ubifs_dump_node()
437 le32_to_cpu(ino->ctime_nsec)); in ubifs_dump_node()
438 pr_err("\tuid %u\n", le32_to_cpu(ino->uid)); in ubifs_dump_node()
439 pr_err("\tgid %u\n", le32_to_cpu(ino->gid)); in ubifs_dump_node()
440 pr_err("\tmode %u\n", le32_to_cpu(ino->mode)); in ubifs_dump_node()
441 pr_err("\tflags %#x\n", le32_to_cpu(ino->flags)); in ubifs_dump_node()
442 pr_err("\txattr_cnt %u\n", le32_to_cpu(ino->xattr_cnt)); in ubifs_dump_node()
443 pr_err("\txattr_size %u\n", le32_to_cpu(ino->xattr_size)); in ubifs_dump_node()
444 pr_err("\txattr_names %u\n", le32_to_cpu(ino->xattr_names)); in ubifs_dump_node()
446 (int)le16_to_cpu(ino->compr_type)); in ubifs_dump_node()
447 pr_err("\tdata len %u\n", le32_to_cpu(ino->data_len)); in ubifs_dump_node()
454 int nlen = le16_to_cpu(dent->nlen); in ubifs_dump_node()
456 key_read(c, &dent->key, &key); in ubifs_dump_node()
458 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); in ubifs_dump_node()
460 (unsigned long long)le64_to_cpu(dent->inum)); in ubifs_dump_node()
461 pr_err("\ttype %d\n", (int)dent->type); in ubifs_dump_node()
468 for (i = 0; i < nlen && dent->name[i]; i++) in ubifs_dump_node()
469 pr_cont("%c", dent->name[i]); in ubifs_dump_node()
478 int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ; in ubifs_dump_node()
480 key_read(c, &dn->key, &key); in ubifs_dump_node()
482 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); in ubifs_dump_node()
483 pr_err("\tsize %u\n", le32_to_cpu(dn->size)); in ubifs_dump_node()
485 (int)le16_to_cpu(dn->compr_type)); in ubifs_dump_node()
489 (void *)&dn->data, dlen, 0); in ubifs_dump_node()
496 pr_err("\tinum %u\n", le32_to_cpu(trun->inum)); in ubifs_dump_node()
498 (unsigned long long)le64_to_cpu(trun->old_size)); in ubifs_dump_node()
500 (unsigned long long)le64_to_cpu(trun->new_size)); in ubifs_dump_node()
507 n = le16_to_cpu(idx->child_cnt); in ubifs_dump_node()
509 pr_err("\tlevel %d\n", (int)le16_to_cpu(idx->level)); in ubifs_dump_node()
512 for (i = 0; i < n && i < c->fanout - 1; i++) { in ubifs_dump_node()
515 br = ubifs_idx_branch(c, idx, i); in ubifs_dump_node()
516 key_read(c, &br->key, &key); in ubifs_dump_node()
518 i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs), in ubifs_dump_node()
519 le32_to_cpu(br->len), in ubifs_dump_node()
520 dbg_snprintf_key(c, &key, key_buf, in ubifs_dump_node()
533 le64_to_cpu(orph->cmt_no) & LLONG_MAX); in ubifs_dump_node()
535 (unsigned long long)(le64_to_cpu(orph->cmt_no)) >> 63); in ubifs_dump_node()
536 n = (le32_to_cpu(ch->len) - UBIFS_ORPH_NODE_SZ) >> 3; in ubifs_dump_node()
540 (unsigned long long)le64_to_cpu(orph->inos[i])); in ubifs_dump_node()
545 (int)ch->node_type); in ubifs_dump_node()
554 req->new_ino, req->dirtied_ino); in ubifs_dump_budget_req()
556 req->new_ino_d, req->dirtied_ino_d); in ubifs_dump_budget_req()
558 req->new_page, req->dirtied_page); in ubifs_dump_budget_req()
560 req->new_dent, req->mod_dent); in ubifs_dump_budget_req()
561 pr_err("\tidx_growth %d\n", req->idx_growth); in ubifs_dump_budget_req()
563 req->data_growth, req->dd_growth); in ubifs_dump_budget_req()
571 current->pid, lst->empty_lebs, lst->idx_lebs); in ubifs_dump_lstats()
573 lst->taken_empty_lebs, lst->total_free, lst->total_dirty); in ubifs_dump_lstats()
575 lst->total_used, lst->total_dark, lst->total_dead); in ubifs_dump_lstats()
580 void ubifs_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi) in ubifs_dump_budg() argument
588 spin_lock(&c->space_lock); in ubifs_dump_budg()
591 current->pid, bi->data_growth + bi->dd_growth, in ubifs_dump_budg()
592 bi->data_growth + bi->dd_growth + bi->idx_growth); in ubifs_dump_budg()
594 bi->data_growth, bi->dd_growth, bi->idx_growth); in ubifs_dump_budg()
596 bi->min_idx_lebs, bi->old_idx_sz, bi->uncommitted_idx); in ubifs_dump_budg()
598 bi->page_budget, bi->inode_budget, bi->dent_budget); in ubifs_dump_budg()
599 pr_err("\tnospace %u, nospace_rp %u\n", bi->nospace, bi->nospace_rp); in ubifs_dump_budg()
601 c->dark_wm, c->dead_wm, c->max_idx_node_sz); in ubifs_dump_budg()
603 if (bi != &c->bi) in ubifs_dump_budg()
612 c->freeable_cnt, c->calc_idx_sz, c->idx_gc_cnt); in ubifs_dump_budg()
614 atomic_long_read(&c->dirty_pg_cnt), in ubifs_dump_budg()
615 atomic_long_read(&c->dirty_zn_cnt), in ubifs_dump_budg()
616 atomic_long_read(&c->clean_zn_cnt)); in ubifs_dump_budg()
617 pr_err("\tgc_lnum %d, ihead_lnum %d\n", c->gc_lnum, c->ihead_lnum); in ubifs_dump_budg()
620 if (c->jheads) in ubifs_dump_budg()
621 for (i = 0; i < c->jhead_cnt; i++) in ubifs_dump_budg()
623 dbg_jhead(c->jheads[i].wbuf.jhead), in ubifs_dump_budg()
624 c->jheads[i].wbuf.lnum); in ubifs_dump_budg()
625 for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) { in ubifs_dump_budg()
627 pr_err("\tbud LEB %d\n", bud->lnum); in ubifs_dump_budg()
629 list_for_each_entry(bud, &c->old_buds, list) in ubifs_dump_budg()
630 pr_err("\told bud LEB %d\n", bud->lnum); in ubifs_dump_budg()
631 list_for_each_entry(idx_gc, &c->idx_gc, list) in ubifs_dump_budg()
633 idx_gc->lnum, idx_gc->unmap); in ubifs_dump_budg()
634 pr_err("\tcommit state %d\n", c->cmt_state); in ubifs_dump_budg()
637 available = ubifs_calc_available(c, c->bi.min_idx_lebs); in ubifs_dump_budg()
638 outstanding = c->bi.data_growth + c->bi.dd_growth; in ubifs_dump_budg()
639 free = ubifs_get_free_space_nolock(c); in ubifs_dump_budg()
645 spin_unlock(&c->space_lock); in ubifs_dump_budg()
648 void ubifs_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi) in ubifs_dump_budg() argument
653 void ubifs_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) in ubifs_dump_lprop() argument
659 spc = lp->free + lp->dirty; in ubifs_dump_lprop()
660 if (spc < c->dead_wm) in ubifs_dump_lprop()
663 dark = ubifs_calc_dark(c, spc); in ubifs_dump_lprop()
665 if (lp->flags & LPROPS_INDEX) in ubifs_dump_lprop()
666 pr_err("LEB %-7d free %-8d dirty %-8d used %-8d free + dirty %-8d flags %#x (", in ubifs_dump_lprop()
667 lp->lnum, lp->free, lp->dirty, c->leb_size - spc, spc, in ubifs_dump_lprop()
668 lp->flags); in ubifs_dump_lprop()
670 …pr_err("LEB %-7d free %-8d dirty %-8d used %-8d free + dirty %-8d dark %-4d dead %-4d nodes fit %-… in ubifs_dump_lprop()
671 lp->lnum, lp->free, lp->dirty, c->leb_size - spc, spc, in ubifs_dump_lprop()
672 dark, dead, (int)(spc / UBIFS_MAX_NODE_SZ), lp->flags); in ubifs_dump_lprop()
674 if (lp->flags & LPROPS_TAKEN) { in ubifs_dump_lprop()
675 if (lp->flags & LPROPS_INDEX) in ubifs_dump_lprop()
682 if (lp->flags & LPROPS_INDEX) { in ubifs_dump_lprop()
683 switch (lp->flags & LPROPS_CAT_MASK) { in ubifs_dump_lprop()
694 switch (lp->flags & LPROPS_CAT_MASK) { in ubifs_dump_lprop()
718 for (rb = rb_first((struct rb_root *)&c->buds); rb; rb = rb_next(rb)) { in ubifs_dump_lprop()
720 if (bud->lnum == lp->lnum) { in ubifs_dump_lprop()
722 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_dump_lprop()
725 * of mounting/re-mounting, the write-buffers do in ubifs_dump_lprop()
728 if (c->jheads && in ubifs_dump_lprop()
729 lp->lnum == c->jheads[i].wbuf.lnum) { in ubifs_dump_lprop()
736 dbg_jhead(bud->jhead)); in ubifs_dump_lprop()
739 if (lp->lnum == c->gc_lnum) in ubifs_dump_lprop()
744 void ubifs_dump_lprops(struct ubifs_info *c) in ubifs_dump_lprops() argument
750 pr_err("(pid %d) start dumping LEB properties\n", current->pid); in ubifs_dump_lprops()
751 ubifs_get_lp_stats(c, &lst); in ubifs_dump_lprops()
754 for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { in ubifs_dump_lprops()
755 err = ubifs_read_one_lp(c, lnum, &lp); in ubifs_dump_lprops()
757 ubifs_err(c, "cannot read lprops for LEB %d", lnum); in ubifs_dump_lprops()
761 ubifs_dump_lprop(c, &lp); in ubifs_dump_lprops()
763 pr_err("(pid %d) finish dumping LEB properties\n", current->pid); in ubifs_dump_lprops()
766 void ubifs_dump_lpt_info(struct ubifs_info *c) in ubifs_dump_lpt_info() argument
771 pr_err("(pid %d) dumping LPT information\n", current->pid); in ubifs_dump_lpt_info()
772 pr_err("\tlpt_sz: %lld\n", c->lpt_sz); in ubifs_dump_lpt_info()
773 pr_err("\tpnode_sz: %d\n", c->pnode_sz); in ubifs_dump_lpt_info()
774 pr_err("\tnnode_sz: %d\n", c->nnode_sz); in ubifs_dump_lpt_info()
775 pr_err("\tltab_sz: %d\n", c->ltab_sz); in ubifs_dump_lpt_info()
776 pr_err("\tlsave_sz: %d\n", c->lsave_sz); in ubifs_dump_lpt_info()
777 pr_err("\tbig_lpt: %d\n", c->big_lpt); in ubifs_dump_lpt_info()
778 pr_err("\tlpt_hght: %d\n", c->lpt_hght); in ubifs_dump_lpt_info()
779 pr_err("\tpnode_cnt: %d\n", c->pnode_cnt); in ubifs_dump_lpt_info()
780 pr_err("\tnnode_cnt: %d\n", c->nnode_cnt); in ubifs_dump_lpt_info()
781 pr_err("\tdirty_pn_cnt: %d\n", c->dirty_pn_cnt); in ubifs_dump_lpt_info()
782 pr_err("\tdirty_nn_cnt: %d\n", c->dirty_nn_cnt); in ubifs_dump_lpt_info()
783 pr_err("\tlsave_cnt: %d\n", c->lsave_cnt); in ubifs_dump_lpt_info()
784 pr_err("\tspace_bits: %d\n", c->space_bits); in ubifs_dump_lpt_info()
785 pr_err("\tlpt_lnum_bits: %d\n", c->lpt_lnum_bits); in ubifs_dump_lpt_info()
786 pr_err("\tlpt_offs_bits: %d\n", c->lpt_offs_bits); in ubifs_dump_lpt_info()
787 pr_err("\tlpt_spc_bits: %d\n", c->lpt_spc_bits); in ubifs_dump_lpt_info()
788 pr_err("\tpcnt_bits: %d\n", c->pcnt_bits); in ubifs_dump_lpt_info()
789 pr_err("\tlnum_bits: %d\n", c->lnum_bits); in ubifs_dump_lpt_info()
790 pr_err("\tLPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs); in ubifs_dump_lpt_info()
792 c->nhead_lnum, c->nhead_offs); in ubifs_dump_lpt_info()
793 pr_err("\tLPT ltab is at %d:%d\n", c->ltab_lnum, c->ltab_offs); in ubifs_dump_lpt_info()
794 if (c->big_lpt) in ubifs_dump_lpt_info()
796 c->lsave_lnum, c->lsave_offs); in ubifs_dump_lpt_info()
797 for (i = 0; i < c->lpt_lebs; i++) in ubifs_dump_lpt_info()
799 i + c->lpt_first, c->ltab[i].free, c->ltab[i].dirty, in ubifs_dump_lpt_info()
800 c->ltab[i].tgc, c->ltab[i].cmt); in ubifs_dump_lpt_info()
804 void ubifs_dump_sleb(const struct ubifs_info *c, in ubifs_dump_sleb() argument
810 current->pid, sleb->lnum, offs); in ubifs_dump_sleb()
812 list_for_each_entry(snod, &sleb->nodes, list) { in ubifs_dump_sleb()
815 sleb->lnum, snod->offs, snod->len); in ubifs_dump_sleb()
816 ubifs_dump_node(c, snod->node); in ubifs_dump_sleb()
820 void ubifs_dump_leb(const struct ubifs_info *c, int lnum) in ubifs_dump_leb() argument
826 pr_err("(pid %d) start dumping LEB %d\n", current->pid, lnum); in ubifs_dump_leb()
828 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); in ubifs_dump_leb()
830 ubifs_err(c, "cannot allocate memory for dumping LEB %d", lnum); in ubifs_dump_leb()
834 sleb = ubifs_scan(c, lnum, 0, buf, 0); in ubifs_dump_leb()
836 ubifs_err(c, "scan error %d", (int)PTR_ERR(sleb)); in ubifs_dump_leb()
841 sleb->nodes_cnt, sleb->endpt); in ubifs_dump_leb()
843 list_for_each_entry(snod, &sleb->nodes, list) { in ubifs_dump_leb()
846 snod->offs, snod->len); in ubifs_dump_leb()
847 ubifs_dump_node(c, snod->node); in ubifs_dump_leb()
850 pr_err("(pid %d) finish dumping LEB %d\n", current->pid, lnum); in ubifs_dump_leb()
858 void ubifs_dump_znode(const struct ubifs_info *c, in ubifs_dump_znode() argument
866 if (znode->parent) in ubifs_dump_znode()
867 zbr = &znode->parent->zbranch[znode->iip]; in ubifs_dump_znode()
869 zbr = &c->zroot; in ubifs_dump_znode()
872 znode, zbr->lnum, zbr->offs, zbr->len, znode->parent, znode->iip, in ubifs_dump_znode()
873 znode->level, znode->child_cnt, znode->flags); in ubifs_dump_znode()
875 if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { in ubifs_dump_znode()
881 for (n = 0; n < znode->child_cnt; n++) { in ubifs_dump_znode()
882 zbr = &znode->zbranch[n]; in ubifs_dump_znode()
883 if (znode->level > 0) in ubifs_dump_znode()
885 n, zbr->znode, zbr->lnum, zbr->offs, zbr->len, in ubifs_dump_znode()
886 dbg_snprintf_key(c, &zbr->key, key_buf, in ubifs_dump_znode()
890 n, zbr->znode, zbr->lnum, zbr->offs, zbr->len, in ubifs_dump_znode()
891 dbg_snprintf_key(c, &zbr->key, key_buf, in ubifs_dump_znode()
897 void ubifs_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) in ubifs_dump_heap() argument
902 current->pid, cat, heap->cnt); in ubifs_dump_heap()
903 for (i = 0; i < heap->cnt; i++) { in ubifs_dump_heap()
904 struct ubifs_lprops *lprops = heap->arr[i]; in ubifs_dump_heap()
907 i, lprops->lnum, lprops->hpos, lprops->free, in ubifs_dump_heap()
908 lprops->dirty, lprops->flags); in ubifs_dump_heap()
910 pr_err("(pid %d) finish dumping heap\n", current->pid); in ubifs_dump_heap()
913 void ubifs_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, in ubifs_dump_pnode() argument
918 pr_err("(pid %d) dumping pnode:\n", current->pid); in ubifs_dump_pnode()
920 (size_t)pnode, (size_t)parent, (size_t)pnode->cnext); in ubifs_dump_pnode()
922 pnode->flags, iip, pnode->level, pnode->num); in ubifs_dump_pnode()
924 struct ubifs_lprops *lp = &pnode->lprops[i]; in ubifs_dump_pnode()
927 i, lp->free, lp->dirty, lp->flags, lp->lnum); in ubifs_dump_pnode()
931 void ubifs_dump_tnc(struct ubifs_info *c) in ubifs_dump_tnc() argument
937 pr_err("(pid %d) start dumping TNC tree\n", current->pid); in ubifs_dump_tnc()
938 znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL); in ubifs_dump_tnc()
939 level = znode->level; in ubifs_dump_tnc()
942 if (level != znode->level) { in ubifs_dump_tnc()
943 level = znode->level; in ubifs_dump_tnc()
946 ubifs_dump_znode(c, znode); in ubifs_dump_tnc()
947 znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); in ubifs_dump_tnc()
949 pr_err("(pid %d) finish dumping TNC tree\n", current->pid); in ubifs_dump_tnc()
952 static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, in dump_znode() argument
955 ubifs_dump_znode(c, znode); in dump_znode()
960 * ubifs_dump_index - dump the on-flash index.
961 * @c: UBIFS file-system description object
963 * This function dumps whole UBIFS indexing B-tree, unlike 'ubifs_dump_tnc()'
964 * which dumps only in-memory znodes and does not read znodes which from flash.
966 void ubifs_dump_index(struct ubifs_info *c) in ubifs_dump_index() argument
968 dbg_walk_index(c, NULL, dump_znode, NULL); in ubifs_dump_index()
973 * dbg_save_space_info - save information about flash space.
974 * @c: UBIFS file-system description object
979 void dbg_save_space_info(struct ubifs_info *c) in dbg_save_space_info() argument
981 struct ubifs_debug_info *d = c->dbg; in dbg_save_space_info()
984 spin_lock(&c->space_lock); in dbg_save_space_info()
985 memcpy(&d->saved_lst, &c->lst, sizeof(struct ubifs_lp_stats)); in dbg_save_space_info()
986 memcpy(&d->saved_bi, &c->bi, sizeof(struct ubifs_budg_info)); in dbg_save_space_info()
987 d->saved_idx_gc_cnt = c->idx_gc_cnt; in dbg_save_space_info()
990 * We use a dirty hack here and zero out @c->freeable_cnt, because it in dbg_save_space_info()
994 * need. So at any given point of time @c->freeable_cnt might be not in dbg_save_space_info()
998 * @c->freeable_cnt. in dbg_save_space_info()
999 * 1. The file-system is mounted R/O, c->freeable_cnt is %0. We save the in dbg_save_space_info()
1000 * amount of free space in @d->saved_free in dbg_save_space_info()
1001 * 2. We re-mount R/W, which makes UBIFS to read the "lsave" in dbg_save_space_info()
1003 * categories ('ubifs_remount_fs()' -> 'ubifs_lpt_init()' in dbg_save_space_info()
1004 * -> 'lpt_init_wr()' -> 'read_lsave()' -> 'ubifs_lpt_lookup()' in dbg_save_space_info()
1005 * -> 'ubifs_get_pnode()' -> 'update_cats()' in dbg_save_space_info()
1006 * -> 'ubifs_add_to_cat()'). in dbg_save_space_info()
1007 * 3. Lsave contains a freeable eraseblock, and @c->freeable_cnt in dbg_save_space_info()
1009 * 4. We calculate the amount of free space when the re-mount is in dbg_save_space_info()
1011 * @d->saved_free. in dbg_save_space_info()
1013 freeable_cnt = c->freeable_cnt; in dbg_save_space_info()
1014 c->freeable_cnt = 0; in dbg_save_space_info()
1015 d->saved_free = ubifs_get_free_space_nolock(c); in dbg_save_space_info()
1016 c->freeable_cnt = freeable_cnt; in dbg_save_space_info()
1017 spin_unlock(&c->space_lock); in dbg_save_space_info()
1021 * dbg_check_space_info - check flash space information.
1022 * @c: UBIFS file-system description object
1026 * Returns zero if the information has not changed, and %-EINVAL it it has
1029 int dbg_check_space_info(struct ubifs_info *c) in dbg_check_space_info() argument
1031 struct ubifs_debug_info *d = c->dbg; in dbg_check_space_info()
1036 spin_lock(&c->space_lock); in dbg_check_space_info()
1037 freeable_cnt = c->freeable_cnt; in dbg_check_space_info()
1038 c->freeable_cnt = 0; in dbg_check_space_info()
1039 free = ubifs_get_free_space_nolock(c); in dbg_check_space_info()
1040 c->freeable_cnt = freeable_cnt; in dbg_check_space_info()
1041 spin_unlock(&c->space_lock); in dbg_check_space_info()
1043 if (free != d->saved_free) { in dbg_check_space_info()
1044 ubifs_err(c, "free space changed from %lld to %lld", in dbg_check_space_info()
1045 d->saved_free, free); in dbg_check_space_info()
1052 ubifs_msg(c, "saved lprops statistics dump"); in dbg_check_space_info()
1053 ubifs_dump_lstats(&d->saved_lst); in dbg_check_space_info()
1054 ubifs_msg(c, "saved budgeting info dump"); in dbg_check_space_info()
1055 ubifs_dump_budg(c, &d->saved_bi); in dbg_check_space_info()
1056 ubifs_msg(c, "saved idx_gc_cnt %d", d->saved_idx_gc_cnt); in dbg_check_space_info()
1057 ubifs_msg(c, "current lprops statistics dump"); in dbg_check_space_info()
1058 ubifs_get_lp_stats(c, &lst); in dbg_check_space_info()
1060 ubifs_msg(c, "current budgeting info dump"); in dbg_check_space_info()
1061 ubifs_dump_budg(c, &c->bi); in dbg_check_space_info()
1063 return -EINVAL; in dbg_check_space_info()
1067 * dbg_check_synced_i_size - check synchronized inode size.
1068 * @c: UBIFS file-system description object
1074 * %-EINVAL if not.
1076 int dbg_check_synced_i_size(const struct ubifs_info *c, struct inode *inode) in dbg_check_synced_i_size() argument
1081 if (!dbg_is_chk_gen(c)) in dbg_check_synced_i_size()
1083 if (!S_ISREG(inode->i_mode)) in dbg_check_synced_i_size()
1086 mutex_lock(&ui->ui_mutex); in dbg_check_synced_i_size()
1087 spin_lock(&ui->ui_lock); in dbg_check_synced_i_size()
1088 if (ui->ui_size != ui->synced_i_size && !ui->dirty) { in dbg_check_synced_i_size()
1089 ubifs_err(c, "ui_size is %lld, synced_i_size is %lld, but inode is clean", in dbg_check_synced_i_size()
1090 ui->ui_size, ui->synced_i_size); in dbg_check_synced_i_size()
1091 ubifs_err(c, "i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, in dbg_check_synced_i_size()
1092 inode->i_mode, i_size_read(inode)); in dbg_check_synced_i_size()
1094 err = -EINVAL; in dbg_check_synced_i_size()
1096 spin_unlock(&ui->ui_lock); in dbg_check_synced_i_size()
1097 mutex_unlock(&ui->ui_mutex); in dbg_check_synced_i_size()
1102 * dbg_check_dir - check directory inode size and link count.
1103 * @c: UBIFS file-system description object
1111 * Note, it is good idea to make sure the @dir->i_mutex is locked before
1114 int dbg_check_dir(struct ubifs_info *c, const struct inode *dir) in dbg_check_dir() argument
1122 if (!dbg_is_chk_gen(c)) in dbg_check_dir()
1125 if (!S_ISDIR(dir->i_mode)) in dbg_check_dir()
1128 lowest_dent_key(c, &key, dir->i_ino); in dbg_check_dir()
1132 dent = ubifs_tnc_next_ent(c, &key, &nm); in dbg_check_dir()
1135 if (err == -ENOENT) in dbg_check_dir()
1140 nm.name = dent->name; in dbg_check_dir()
1141 nm.len = le16_to_cpu(dent->nlen); in dbg_check_dir()
1143 if (dent->type == UBIFS_ITYPE_DIR) in dbg_check_dir()
1147 key_read(c, &dent->key, &key); in dbg_check_dir()
1152 ubifs_err(c, "directory inode %lu has size %llu, but calculated size is %llu", in dbg_check_dir()
1153 dir->i_ino, (unsigned long long)i_size_read(dir), in dbg_check_dir()
1155 ubifs_dump_inode(c, dir); in dbg_check_dir()
1157 return -EINVAL; in dbg_check_dir()
1159 if (dir->i_nlink != nlink) { in dbg_check_dir()
1160 ubifs_err(c, "directory inode %lu has nlink %u, but calculated nlink is %u", in dbg_check_dir()
1161 dir->i_ino, dir->i_nlink, nlink); in dbg_check_dir()
1162 ubifs_dump_inode(c, dir); in dbg_check_dir()
1164 return -EINVAL; in dbg_check_dir()
1171 * dbg_check_key_order - make sure that colliding keys are properly ordered.
1172 * @c: UBIFS file-system description object
1176 * In UBIFS indexing B-tree colliding keys has to be sorted in binary order of
1183 static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1, in dbg_check_key_order() argument
1191 ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key)); in dbg_check_key_order()
1194 return -ENOMEM; in dbg_check_key_order()
1197 err = -ENOMEM; in dbg_check_key_order()
1201 err = ubifs_tnc_read_node(c, zbr1, dent1); in dbg_check_key_order()
1204 err = ubifs_validate_entry(c, dent1); in dbg_check_key_order()
1208 err = ubifs_tnc_read_node(c, zbr2, dent2); in dbg_check_key_order()
1211 err = ubifs_validate_entry(c, dent2); in dbg_check_key_order()
1217 key_read(c, &dent1->key, &key); in dbg_check_key_order()
1218 if (keys_cmp(c, &zbr1->key, &key)) { in dbg_check_key_order()
1219 ubifs_err(c, "1st entry at %d:%d has key %s", zbr1->lnum, in dbg_check_key_order()
1220 zbr1->offs, dbg_snprintf_key(c, &key, key_buf, in dbg_check_key_order()
1222 ubifs_err(c, "but it should have key %s according to tnc", in dbg_check_key_order()
1223 dbg_snprintf_key(c, &zbr1->key, key_buf, in dbg_check_key_order()
1225 ubifs_dump_node(c, dent1); in dbg_check_key_order()
1229 key_read(c, &dent2->key, &key); in dbg_check_key_order()
1230 if (keys_cmp(c, &zbr2->key, &key)) { in dbg_check_key_order()
1231 ubifs_err(c, "2nd entry at %d:%d has key %s", zbr1->lnum, in dbg_check_key_order()
1232 zbr1->offs, dbg_snprintf_key(c, &key, key_buf, in dbg_check_key_order()
1234 ubifs_err(c, "but it should have key %s according to tnc", in dbg_check_key_order()
1235 dbg_snprintf_key(c, &zbr2->key, key_buf, in dbg_check_key_order()
1237 ubifs_dump_node(c, dent2); in dbg_check_key_order()
1241 nlen1 = le16_to_cpu(dent1->nlen); in dbg_check_key_order()
1242 nlen2 = le16_to_cpu(dent2->nlen); in dbg_check_key_order()
1244 cmp = memcmp(dent1->name, dent2->name, min_t(int, nlen1, nlen2)); in dbg_check_key_order()
1250 ubifs_err(c, "2 xent/dent nodes with the same name"); in dbg_check_key_order()
1252 ubifs_err(c, "bad order of colliding key %s", in dbg_check_key_order()
1253 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); in dbg_check_key_order()
1255 ubifs_msg(c, "first node at %d:%d\n", zbr1->lnum, zbr1->offs); in dbg_check_key_order()
1256 ubifs_dump_node(c, dent1); in dbg_check_key_order()
1257 ubifs_msg(c, "second node at %d:%d\n", zbr2->lnum, zbr2->offs); in dbg_check_key_order()
1258 ubifs_dump_node(c, dent2); in dbg_check_key_order()
1267 * dbg_check_znode - check if znode is all right.
1268 * @c: UBIFS file-system description object
1272 * Returns zero if it is, and %-EINVAL if it is not.
1274 static int dbg_check_znode(struct ubifs_info *c, struct ubifs_zbranch *zbr) in dbg_check_znode() argument
1276 struct ubifs_znode *znode = zbr->znode; in dbg_check_znode()
1277 struct ubifs_znode *zp = znode->parent; in dbg_check_znode()
1280 if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { in dbg_check_znode()
1284 if (znode->level < 0) { in dbg_check_znode()
1288 if (znode->iip < 0 || znode->iip >= c->fanout) { in dbg_check_znode()
1293 if (zbr->len == 0) in dbg_check_znode()
1294 /* Only dirty zbranch may have no on-flash nodes */ in dbg_check_znode()
1325 if (znode->level != zp->level - 1) { in dbg_check_znode()
1331 err = ubifs_search_zbranch(c, zp, &zbr->key, &n); in dbg_check_znode()
1338 if (znode->iip >= zp->child_cnt) { in dbg_check_znode()
1343 if (znode->iip != n) { in dbg_check_znode()
1345 if (keys_cmp(c, &zp->zbranch[n].key, in dbg_check_znode()
1346 &zp->zbranch[znode->iip].key)) { in dbg_check_znode()
1350 n = znode->iip; in dbg_check_znode()
1357 min = &zbr->key; in dbg_check_znode()
1358 cmp = keys_cmp(c, min, &znode->zbranch[0].key); in dbg_check_znode()
1364 if (n + 1 < zp->child_cnt) { in dbg_check_znode()
1365 max = &zp->zbranch[n + 1].key; in dbg_check_znode()
1372 cmp = keys_cmp(c, max, in dbg_check_znode()
1373 &znode->zbranch[znode->child_cnt - 1].key); in dbg_check_znode()
1374 if (cmp == -1) { in dbg_check_znode()
1381 if (zbr != &c->zroot) { in dbg_check_znode()
1391 for (n = 1; n < znode->child_cnt; n++) { in dbg_check_znode()
1392 cmp = keys_cmp(c, &znode->zbranch[n - 1].key, in dbg_check_znode()
1393 &znode->zbranch[n].key); in dbg_check_znode()
1400 if (!is_hash_key(c, &znode->zbranch[n].key)) { in dbg_check_znode()
1405 if (znode->level != 0 || c->replaying) in dbg_check_znode()
1412 err = dbg_check_key_order(c, &znode->zbranch[n - 1], in dbg_check_znode()
1413 &znode->zbranch[n]); in dbg_check_znode()
1423 for (n = 0; n < znode->child_cnt; n++) { in dbg_check_znode()
1424 if (!znode->zbranch[n].znode && in dbg_check_znode()
1425 (znode->zbranch[n].lnum == 0 || in dbg_check_znode()
1426 znode->zbranch[n].len == 0)) { in dbg_check_znode()
1431 if (znode->zbranch[n].lnum != 0 && in dbg_check_znode()
1432 znode->zbranch[n].len == 0) { in dbg_check_znode()
1437 if (znode->zbranch[n].lnum == 0 && in dbg_check_znode()
1438 znode->zbranch[n].len != 0) { in dbg_check_znode()
1443 if (znode->zbranch[n].lnum == 0 && in dbg_check_znode()
1444 znode->zbranch[n].offs != 0) { in dbg_check_znode()
1449 if (znode->level != 0 && znode->zbranch[n].znode) in dbg_check_znode()
1450 if (znode->zbranch[n].znode->parent != znode) { in dbg_check_znode()
1459 ubifs_err(c, "failed, error %d", err); in dbg_check_znode()
1460 ubifs_msg(c, "dump of the znode"); in dbg_check_znode()
1461 ubifs_dump_znode(c, znode); in dbg_check_znode()
1463 ubifs_msg(c, "dump of the parent znode"); in dbg_check_znode()
1464 ubifs_dump_znode(c, zp); in dbg_check_znode()
1467 return -EINVAL; in dbg_check_znode()
1471 int dbg_check_dir(struct ubifs_info *c, const struct inode *dir) in dbg_check_dir() argument
1476 void dbg_debugfs_exit_fs(struct ubifs_info *c) in dbg_debugfs_exit_fs() argument
1481 int ubifs_debugging_init(struct ubifs_info *c) in ubifs_debugging_init() argument
1485 void ubifs_debugging_exit(struct ubifs_info *c) in ubifs_debugging_exit() argument
1488 int dbg_check_filesystem(struct ubifs_info *c) in dbg_check_filesystem() argument
1492 int dbg_debugfs_init_fs(struct ubifs_info *c) in dbg_debugfs_init_fs() argument
1500 * dbg_check_tnc - check TNC tree.
1501 * @c: UBIFS file-system description object
1505 * if everything is all right and %-EINVAL if something is wrong with TNC.
1507 int dbg_check_tnc(struct ubifs_info *c, int extra) in dbg_check_tnc() argument
1513 if (!dbg_is_chk_index(c)) in dbg_check_tnc()
1516 ubifs_assert(mutex_is_locked(&c->tnc_mutex)); in dbg_check_tnc()
1517 if (!c->zroot.znode) in dbg_check_tnc()
1520 znode = ubifs_tnc_postorder_first(c->zroot.znode); in dbg_check_tnc()
1525 if (!znode->parent) in dbg_check_tnc()
1526 zbr = &c->zroot; in dbg_check_tnc()
1528 zbr = &znode->parent->zbranch[znode->iip]; in dbg_check_tnc()
1530 err = dbg_check_znode(c, zbr); in dbg_check_tnc()
1550 last = prev->child_cnt - 1; in dbg_check_tnc()
1551 if (prev->level == 0 && znode->level == 0 && !c->replaying && in dbg_check_tnc()
1552 !keys_cmp(c, &prev->zbranch[last].key, in dbg_check_tnc()
1553 &znode->zbranch[0].key)) { in dbg_check_tnc()
1554 err = dbg_check_key_order(c, &prev->zbranch[last], in dbg_check_tnc()
1555 &znode->zbranch[0]); in dbg_check_tnc()
1559 ubifs_msg(c, "first znode"); in dbg_check_tnc()
1560 ubifs_dump_znode(c, prev); in dbg_check_tnc()
1561 ubifs_msg(c, "second znode"); in dbg_check_tnc()
1562 ubifs_dump_znode(c, znode); in dbg_check_tnc()
1563 return -EINVAL; in dbg_check_tnc()
1569 if (clean_cnt != atomic_long_read(&c->clean_zn_cnt)) { in dbg_check_tnc()
1570 ubifs_err(c, "incorrect clean_zn_cnt %ld, calculated %ld", in dbg_check_tnc()
1571 atomic_long_read(&c->clean_zn_cnt), in dbg_check_tnc()
1573 return -EINVAL; in dbg_check_tnc()
1575 if (dirty_cnt != atomic_long_read(&c->dirty_zn_cnt)) { in dbg_check_tnc()
1576 ubifs_err(c, "incorrect dirty_zn_cnt %ld, calculated %ld", in dbg_check_tnc()
1577 atomic_long_read(&c->dirty_zn_cnt), in dbg_check_tnc()
1579 return -EINVAL; in dbg_check_tnc()
1586 int dbg_check_tnc(struct ubifs_info *c, int extra) in dbg_check_tnc() argument
1593 * dbg_walk_index - walk the on-flash index.
1594 * @c: UBIFS file-system description object
1604 * the TNC, so that the behavior more closely matched the non-debugging
1607 int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, in dbg_walk_index() argument
1614 mutex_lock(&c->tnc_mutex); in dbg_walk_index()
1615 /* If the root indexing node is not in TNC - pull it */ in dbg_walk_index()
1616 if (!c->zroot.znode) { in dbg_walk_index()
1617 c->zroot.znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in dbg_walk_index()
1618 if (IS_ERR(c->zroot.znode)) { in dbg_walk_index()
1619 err = PTR_ERR(c->zroot.znode); in dbg_walk_index()
1620 c->zroot.znode = NULL; in dbg_walk_index()
1630 znode = c->zroot.znode; in dbg_walk_index()
1631 while (znode->level > 0) { in dbg_walk_index()
1632 zbr = &znode->zbranch[0]; in dbg_walk_index()
1633 child = zbr->znode; in dbg_walk_index()
1635 child = ubifs_load_znode(c, zbr, znode, 0); in dbg_walk_index()
1640 zbr->znode = child; in dbg_walk_index()
1653 err = znode_cb(c, znode, priv); in dbg_walk_index()
1655 ubifs_err(c, "znode checking function returned error %d", in dbg_walk_index()
1657 ubifs_dump_znode(c, znode); in dbg_walk_index()
1661 if (leaf_cb && znode->level == 0) { in dbg_walk_index()
1662 for (idx = 0; idx < znode->child_cnt; idx++) { in dbg_walk_index()
1663 zbr = &znode->zbranch[idx]; in dbg_walk_index()
1664 err = leaf_cb(c, zbr, priv); in dbg_walk_index()
1666 ubifs_err(c, "leaf checking function returned error %d, for leaf at LEB %d:%d", in dbg_walk_index()
1667 err, zbr->lnum, zbr->offs); in dbg_walk_index()
1673 if (!znode->parent) in dbg_walk_index()
1676 idx = znode->iip + 1; in dbg_walk_index()
1677 znode = znode->parent; in dbg_walk_index()
1678 if (idx < znode->child_cnt) { in dbg_walk_index()
1680 zbr = &znode->zbranch[idx]; in dbg_walk_index()
1681 child = zbr->znode; in dbg_walk_index()
1683 child = ubifs_load_znode(c, zbr, znode, idx); in dbg_walk_index()
1688 zbr->znode = child; in dbg_walk_index()
1698 /* Go to the lowest leftmost znode in the new sub-tree */ in dbg_walk_index()
1699 while (znode->level > 0) { in dbg_walk_index()
1700 zbr = &znode->zbranch[0]; in dbg_walk_index()
1701 child = zbr->znode; in dbg_walk_index()
1703 child = ubifs_load_znode(c, zbr, znode, 0); in dbg_walk_index()
1708 zbr->znode = child; in dbg_walk_index()
1714 mutex_unlock(&c->tnc_mutex); in dbg_walk_index()
1718 if (znode->parent) in dbg_walk_index()
1719 zbr = &znode->parent->zbranch[znode->iip]; in dbg_walk_index()
1721 zbr = &c->zroot; in dbg_walk_index()
1722 ubifs_msg(c, "dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); in dbg_walk_index()
1723 ubifs_dump_znode(c, znode); in dbg_walk_index()
1725 mutex_unlock(&c->tnc_mutex); in dbg_walk_index()
1730 * add_size - add znode size to partially calculated index size.
1731 * @c: UBIFS file-system description object
1739 static int add_size(struct ubifs_info *c, struct ubifs_znode *znode, void *priv) in add_size() argument
1744 add = ubifs_idx_node_sz(c, znode->child_cnt); in add_size()
1751 * dbg_check_idx_size - check index size.
1752 * @c: UBIFS file-system description object
1759 int dbg_check_idx_size(struct ubifs_info *c, long long idx_size) in dbg_check_idx_size() argument
1764 if (!dbg_is_chk_index(c)) in dbg_check_idx_size()
1767 err = dbg_walk_index(c, NULL, add_size, &calc); in dbg_check_idx_size()
1769 ubifs_err(c, "error %d while walking the index", err); in dbg_check_idx_size()
1774 ubifs_err(c, "index size check failed: calculated size is %lld, should be %lld", in dbg_check_idx_size()
1777 return -EINVAL; in dbg_check_idx_size()
1785 * struct fsck_inode - information about an inode used when checking the file-system.
1786 * @rb: link in the RB-tree of inodes
1794 * @size: inode size (read from on-flash inode)
1795 * @xattr_sz: summary size of all extended attributes (read from on-flash
1801 * inode (read from on-flash inode)
1822 * struct fsck_data - private FS checking information.
1823 * @inodes: RB-tree of all inodes (contains @struct fsck_inode objects)
1830 * add_inode - add inode information to RB-tree of inodes.
1831 * @c: UBIFS file-system description object
1836 * inode @ino to the RB-tree of inodes. Returns inode information pointer in
1839 static struct fsck_inode *add_inode(struct ubifs_info *c, in add_inode() argument
1845 ino_t inum = key_inum_flash(c, &ino->key); in add_inode()
1849 p = &fsckd->inodes.rb_node; in add_inode()
1853 if (inum < fscki->inum) in add_inode()
1854 p = &(*p)->rb_left; in add_inode()
1855 else if (inum > fscki->inum) in add_inode()
1856 p = &(*p)->rb_right; in add_inode()
1861 if (inum > c->highest_inum) { in add_inode()
1862 ubifs_err(c, "too high inode number, max. is %lu", in add_inode()
1863 (unsigned long)c->highest_inum); in add_inode()
1864 return ERR_PTR(-EINVAL); in add_inode()
1869 return ERR_PTR(-ENOMEM); in add_inode()
1871 inode = ilookup(c->vfs_sb, inum); in add_inode()
1873 fscki->inum = inum; in add_inode()
1876 * the on-flash inode which might be out-of-date. E.g., the size might in add_inode()
1877 * be out-of-date. If we do not do this, the following may happen, for in add_inode()
1880 * 2. We mount the file-system R/O, the replay process fixes up the in add_inode()
1881 * inode size in the VFS cache, but on on-flash. in add_inode()
1886 fscki->nlink = le32_to_cpu(ino->nlink); in add_inode()
1887 fscki->size = le64_to_cpu(ino->size); in add_inode()
1888 fscki->xattr_cnt = le32_to_cpu(ino->xattr_cnt); in add_inode()
1889 fscki->xattr_sz = le32_to_cpu(ino->xattr_size); in add_inode()
1890 fscki->xattr_nms = le32_to_cpu(ino->xattr_names); in add_inode()
1891 fscki->mode = le32_to_cpu(ino->mode); in add_inode()
1894 fscki->nlink = inode->i_nlink; in add_inode()
1895 fscki->size = inode->i_size; in add_inode()
1896 fscki->xattr_cnt = ui->xattr_cnt; in add_inode()
1897 fscki->xattr_sz = ui->xattr_size; in add_inode()
1898 fscki->xattr_nms = ui->xattr_names; in add_inode()
1899 fscki->mode = inode->i_mode; in add_inode()
1903 if (S_ISDIR(fscki->mode)) { in add_inode()
1904 fscki->calc_sz = UBIFS_INO_NODE_SZ; in add_inode()
1905 fscki->calc_cnt = 2; in add_inode()
1908 rb_link_node(&fscki->rb, parent, p); in add_inode()
1909 rb_insert_color(&fscki->rb, &fsckd->inodes); in add_inode()
1915 * search_inode - search inode in the RB-tree of inodes.
1920 * the RB-tree of inodes and returns an inode information pointer or %NULL if
1928 p = fsckd->inodes.rb_node; in search_inode()
1931 if (inum < fscki->inum) in search_inode()
1932 p = p->rb_left; in search_inode()
1933 else if (inum > fscki->inum) in search_inode()
1934 p = p->rb_right; in search_inode()
1942 * read_add_inode - read inode node and add it to RB-tree of inodes.
1943 * @c: UBIFS file-system description object
1948 * the index, reads it, and adds it to the RB-tree of inodes. Returns inode
1952 static struct fsck_inode *read_add_inode(struct ubifs_info *c, in read_add_inode() argument
1966 ino_key_init(c, &key, inum); in read_add_inode()
1967 err = ubifs_lookup_level0(c, &key, &znode, &n); in read_add_inode()
1969 ubifs_err(c, "inode %lu not found in index", (unsigned long)inum); in read_add_inode()
1970 return ERR_PTR(-ENOENT); in read_add_inode()
1972 ubifs_err(c, "error %d while looking up inode %lu", in read_add_inode()
1977 zbr = &znode->zbranch[n]; in read_add_inode()
1978 if (zbr->len < UBIFS_INO_NODE_SZ) { in read_add_inode()
1979 ubifs_err(c, "bad node %lu node length %d", in read_add_inode()
1980 (unsigned long)inum, zbr->len); in read_add_inode()
1981 return ERR_PTR(-EINVAL); in read_add_inode()
1984 ino = kmalloc(zbr->len, GFP_NOFS); in read_add_inode()
1986 return ERR_PTR(-ENOMEM); in read_add_inode()
1988 err = ubifs_tnc_read_node(c, zbr, ino); in read_add_inode()
1990 ubifs_err(c, "cannot read inode node at LEB %d:%d, error %d", in read_add_inode()
1991 zbr->lnum, zbr->offs, err); in read_add_inode()
1996 fscki = add_inode(c, fsckd, ino); in read_add_inode()
1999 ubifs_err(c, "error %ld while adding inode %lu node", in read_add_inode()
2008 * check_leaf - check leaf node.
2009 * @c: UBIFS file-system description object
2017 * an RB-tree of inodes - it adds all inodes into the RB-tree. It also
2023 static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr, in check_leaf() argument
2029 int err, type = key_type(c, &zbr->key); in check_leaf()
2032 if (zbr->len < UBIFS_CH_SZ) { in check_leaf()
2033 ubifs_err(c, "bad leaf length %d (LEB %d:%d)", in check_leaf()
2034 zbr->len, zbr->lnum, zbr->offs); in check_leaf()
2035 return -EINVAL; in check_leaf()
2038 node = kmalloc(zbr->len, GFP_NOFS); in check_leaf()
2040 return -ENOMEM; in check_leaf()
2042 err = ubifs_tnc_read_node(c, zbr, node); in check_leaf()
2044 ubifs_err(c, "cannot read leaf node at LEB %d:%d, error %d", in check_leaf()
2045 zbr->lnum, zbr->offs, err); in check_leaf()
2049 /* If this is an inode node, add it to RB-tree of inodes */ in check_leaf()
2051 fscki = add_inode(c, priv, node); in check_leaf()
2054 ubifs_err(c, "error %d while adding inode node", err); in check_leaf()
2062 ubifs_err(c, "unexpected node type %d at LEB %d:%d", in check_leaf()
2063 type, zbr->lnum, zbr->offs); in check_leaf()
2064 err = -EINVAL; in check_leaf()
2069 if (le64_to_cpu(ch->sqnum) > c->max_sqnum) { in check_leaf()
2070 ubifs_err(c, "too high sequence number, max. is %llu", in check_leaf()
2071 c->max_sqnum); in check_leaf()
2072 err = -EINVAL; in check_leaf()
2080 ubifs_assert(zbr->len >= UBIFS_DATA_NODE_SZ); in check_leaf()
2084 * it to the RB-tree of inodes. in check_leaf()
2086 inum = key_inum_flash(c, &dn->key); in check_leaf()
2087 fscki = read_add_inode(c, priv, inum); in check_leaf()
2090 ubifs_err(c, "error %d while processing data node and trying to find inode node %lu", in check_leaf()
2096 blk_offs = key_block_flash(c, &dn->key); in check_leaf()
2098 blk_offs += le32_to_cpu(dn->size); in check_leaf()
2099 if (blk_offs > fscki->size) { in check_leaf()
2100 ubifs_err(c, "data node at LEB %d:%d is not within inode size %lld", in check_leaf()
2101 zbr->lnum, zbr->offs, fscki->size); in check_leaf()
2102 err = -EINVAL; in check_leaf()
2110 ubifs_assert(zbr->len >= UBIFS_DENT_NODE_SZ); in check_leaf()
2112 err = ubifs_validate_entry(c, dent); in check_leaf()
2118 * inode node and insert them to the RB-tree of inodes. in check_leaf()
2120 inum = le64_to_cpu(dent->inum); in check_leaf()
2121 fscki = read_add_inode(c, priv, inum); in check_leaf()
2124 ubifs_err(c, "error %d while processing entry node and trying to find inode node %lu", in check_leaf()
2130 fscki->references += 1; in check_leaf()
2132 inum = key_inum_flash(c, &dent->key); in check_leaf()
2133 fscki1 = read_add_inode(c, priv, inum); in check_leaf()
2136 ubifs_err(c, "error %d while processing entry node and trying to find parent inode node %lu", in check_leaf()
2141 nlen = le16_to_cpu(dent->nlen); in check_leaf()
2143 fscki1->calc_xcnt += 1; in check_leaf()
2144 fscki1->calc_xsz += CALC_DENT_SIZE(nlen); in check_leaf()
2145 fscki1->calc_xsz += CALC_XATTR_BYTES(fscki->size); in check_leaf()
2146 fscki1->calc_xnms += nlen; in check_leaf()
2148 fscki1->calc_sz += CALC_DENT_SIZE(nlen); in check_leaf()
2149 if (dent->type == UBIFS_ITYPE_DIR) in check_leaf()
2150 fscki1->calc_cnt += 1; in check_leaf()
2159 ubifs_msg(c, "dump of node at LEB %d:%d", zbr->lnum, zbr->offs); in check_leaf()
2160 ubifs_dump_node(c, node); in check_leaf()
2167 * free_inodes - free RB-tree of inodes.
2174 rbtree_postorder_for_each_entry_safe(fscki, n, &fsckd->inodes, rb) in free_inodes()
2179 * check_inodes - checks all inodes.
2180 * @c: UBIFS file-system description object
2184 * RB-tree of inodes after the index scan has been finished, and checks that
2186 * %-EINVAL if not, and a negative error code in case of failure.
2188 static int check_inodes(struct ubifs_info *c, struct fsck_data *fsckd) in check_inodes() argument
2196 struct rb_node *this = rb_first(&fsckd->inodes); in check_inodes()
2202 if (S_ISDIR(fscki->mode)) { in check_inodes()
2208 if (fscki->inum != UBIFS_ROOT_INO && in check_inodes()
2209 fscki->references != 1) { in check_inodes()
2210 ubifs_err(c, "directory inode %lu has %d direntries which refer it, but should be 1", in check_inodes()
2211 (unsigned long)fscki->inum, in check_inodes()
2212 fscki->references); in check_inodes()
2215 if (fscki->inum == UBIFS_ROOT_INO && in check_inodes()
2216 fscki->references != 0) { in check_inodes()
2217 ubifs_err(c, "root inode %lu has non-zero (%d) direntries which refer it", in check_inodes()
2218 (unsigned long)fscki->inum, in check_inodes()
2219 fscki->references); in check_inodes()
2222 if (fscki->calc_sz != fscki->size) { in check_inodes()
2223 ubifs_err(c, "directory inode %lu size is %lld, but calculated size is %lld", in check_inodes()
2224 (unsigned long)fscki->inum, in check_inodes()
2225 fscki->size, fscki->calc_sz); in check_inodes()
2228 if (fscki->calc_cnt != fscki->nlink) { in check_inodes()
2229 ubifs_err(c, "directory inode %lu nlink is %d, but calculated nlink is %d", in check_inodes()
2230 (unsigned long)fscki->inum, in check_inodes()
2231 fscki->nlink, fscki->calc_cnt); in check_inodes()
2235 if (fscki->references != fscki->nlink) { in check_inodes()
2236 ubifs_err(c, "inode %lu nlink is %d, but calculated nlink is %d", in check_inodes()
2237 (unsigned long)fscki->inum, in check_inodes()
2238 fscki->nlink, fscki->references); in check_inodes()
2242 if (fscki->xattr_sz != fscki->calc_xsz) { in check_inodes()
2243 ubifs_err(c, "inode %lu has xattr size %u, but calculated size is %lld", in check_inodes()
2244 (unsigned long)fscki->inum, fscki->xattr_sz, in check_inodes()
2245 fscki->calc_xsz); in check_inodes()
2248 if (fscki->xattr_cnt != fscki->calc_xcnt) { in check_inodes()
2249 ubifs_err(c, "inode %lu has %u xattrs, but calculated count is %lld", in check_inodes()
2250 (unsigned long)fscki->inum, in check_inodes()
2251 fscki->xattr_cnt, fscki->calc_xcnt); in check_inodes()
2254 if (fscki->xattr_nms != fscki->calc_xnms) { in check_inodes()
2255 ubifs_err(c, "inode %lu has xattr names' size %u, but calculated names' size is %lld", in check_inodes()
2256 (unsigned long)fscki->inum, fscki->xattr_nms, in check_inodes()
2257 fscki->calc_xnms); in check_inodes()
2266 ino_key_init(c, &key, fscki->inum); in check_inodes()
2267 err = ubifs_lookup_level0(c, &key, &znode, &n); in check_inodes()
2269 ubifs_err(c, "inode %lu not found in index", in check_inodes()
2270 (unsigned long)fscki->inum); in check_inodes()
2271 return -ENOENT; in check_inodes()
2273 ubifs_err(c, "error %d while looking up inode %lu", in check_inodes()
2274 err, (unsigned long)fscki->inum); in check_inodes()
2278 zbr = &znode->zbranch[n]; in check_inodes()
2279 ino = kmalloc(zbr->len, GFP_NOFS); in check_inodes()
2281 return -ENOMEM; in check_inodes()
2283 err = ubifs_tnc_read_node(c, zbr, ino); in check_inodes()
2285 ubifs_err(c, "cannot read inode node at LEB %d:%d, error %d", in check_inodes()
2286 zbr->lnum, zbr->offs, err); in check_inodes()
2291 ubifs_msg(c, "dump of the inode %lu sitting in LEB %d:%d", in check_inodes()
2292 (unsigned long)fscki->inum, zbr->lnum, zbr->offs); in check_inodes()
2293 ubifs_dump_node(c, ino); in check_inodes()
2295 return -EINVAL; in check_inodes()
2299 * dbg_check_filesystem - check the file-system.
2300 * @c: UBIFS file-system description object
2308 * heavy-weight. Returns zero if the file-system is consistent, %-EINVAL if
2311 int dbg_check_filesystem(struct ubifs_info *c) in dbg_check_filesystem() argument
2316 if (!dbg_is_chk_fs(c)) in dbg_check_filesystem()
2320 err = dbg_walk_index(c, check_leaf, NULL, &fsckd); in dbg_check_filesystem()
2324 err = check_inodes(c, &fsckd); in dbg_check_filesystem()
2332 ubifs_err(c, "file-system check failed with error %d", err); in dbg_check_filesystem()
2339 * dbg_check_data_nodes_order - check that list of data nodes is sorted.
2340 * @c: UBIFS file-system description object
2344 * and %-EINVAL if not.
2346 int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head) in dbg_check_data_nodes_order() argument
2351 if (!dbg_is_chk_gen(c)) in dbg_check_data_nodes_order()
2354 for (cur = head->next; cur->next != head; cur = cur->next) { in dbg_check_data_nodes_order()
2360 sb = container_of(cur->next, struct ubifs_scan_node, list); in dbg_check_data_nodes_order()
2362 if (sa->type != UBIFS_DATA_NODE) { in dbg_check_data_nodes_order()
2363 ubifs_err(c, "bad node type %d", sa->type); in dbg_check_data_nodes_order()
2364 ubifs_dump_node(c, sa->node); in dbg_check_data_nodes_order()
2365 return -EINVAL; in dbg_check_data_nodes_order()
2367 if (sb->type != UBIFS_DATA_NODE) { in dbg_check_data_nodes_order()
2368 ubifs_err(c, "bad node type %d", sb->type); in dbg_check_data_nodes_order()
2369 ubifs_dump_node(c, sb->node); in dbg_check_data_nodes_order()
2370 return -EINVAL; in dbg_check_data_nodes_order()
2373 inuma = key_inum(c, &sa->key); in dbg_check_data_nodes_order()
2374 inumb = key_inum(c, &sb->key); in dbg_check_data_nodes_order()
2379 ubifs_err(c, "larger inum %lu goes before inum %lu", in dbg_check_data_nodes_order()
2384 blka = key_block(c, &sa->key); in dbg_check_data_nodes_order()
2385 blkb = key_block(c, &sb->key); in dbg_check_data_nodes_order()
2388 ubifs_err(c, "larger block %u goes before %u", blka, blkb); in dbg_check_data_nodes_order()
2392 ubifs_err(c, "two data nodes for the same block"); in dbg_check_data_nodes_order()
2400 ubifs_dump_node(c, sa->node); in dbg_check_data_nodes_order()
2401 ubifs_dump_node(c, sb->node); in dbg_check_data_nodes_order()
2402 return -EINVAL; in dbg_check_data_nodes_order()
2406 * dbg_check_nondata_nodes_order - check that list of data nodes is sorted.
2407 * @c: UBIFS file-system description object
2410 * This function returns zero if the list of non-data nodes is sorted correctly,
2411 * and %-EINVAL if not.
2413 int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) in dbg_check_nondata_nodes_order() argument
2418 if (!dbg_is_chk_gen(c)) in dbg_check_nondata_nodes_order()
2421 for (cur = head->next; cur->next != head; cur = cur->next) { in dbg_check_nondata_nodes_order()
2427 sb = container_of(cur->next, struct ubifs_scan_node, list); in dbg_check_nondata_nodes_order()
2429 if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && in dbg_check_nondata_nodes_order()
2430 sa->type != UBIFS_XENT_NODE) { in dbg_check_nondata_nodes_order()
2431 ubifs_err(c, "bad node type %d", sa->type); in dbg_check_nondata_nodes_order()
2432 ubifs_dump_node(c, sa->node); in dbg_check_nondata_nodes_order()
2433 return -EINVAL; in dbg_check_nondata_nodes_order()
2435 if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && in dbg_check_nondata_nodes_order()
2436 sa->type != UBIFS_XENT_NODE) { in dbg_check_nondata_nodes_order()
2437 ubifs_err(c, "bad node type %d", sb->type); in dbg_check_nondata_nodes_order()
2438 ubifs_dump_node(c, sb->node); in dbg_check_nondata_nodes_order()
2439 return -EINVAL; in dbg_check_nondata_nodes_order()
2442 if (sa->type != UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { in dbg_check_nondata_nodes_order()
2443 ubifs_err(c, "non-inode node goes before inode node"); in dbg_check_nondata_nodes_order()
2447 if (sa->type == UBIFS_INO_NODE && sb->type != UBIFS_INO_NODE) in dbg_check_nondata_nodes_order()
2450 if (sa->type == UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { in dbg_check_nondata_nodes_order()
2452 if (sa->len < sb->len) { in dbg_check_nondata_nodes_order()
2453 ubifs_err(c, "smaller inode node goes first"); in dbg_check_nondata_nodes_order()
2463 inuma = key_inum(c, &sa->key); in dbg_check_nondata_nodes_order()
2464 inumb = key_inum(c, &sb->key); in dbg_check_nondata_nodes_order()
2469 ubifs_err(c, "larger inum %lu goes before inum %lu", in dbg_check_nondata_nodes_order()
2474 hasha = key_block(c, &sa->key); in dbg_check_nondata_nodes_order()
2475 hashb = key_block(c, &sb->key); in dbg_check_nondata_nodes_order()
2478 ubifs_err(c, "larger hash %u goes before %u", in dbg_check_nondata_nodes_order()
2487 ubifs_msg(c, "dumping first node"); in dbg_check_nondata_nodes_order()
2488 ubifs_dump_node(c, sa->node); in dbg_check_nondata_nodes_order()
2489 ubifs_msg(c, "dumping second node"); in dbg_check_nondata_nodes_order()
2490 ubifs_dump_node(c, sb->node); in dbg_check_nondata_nodes_order()
2491 return -EINVAL; in dbg_check_nondata_nodes_order()
2501 static int power_cut_emulated(struct ubifs_info *c, int lnum, int write) in power_cut_emulated() argument
2503 struct ubifs_debug_info *d = c->dbg; in power_cut_emulated()
2505 ubifs_assert(dbg_is_tst_rcvry(c)); in power_cut_emulated()
2507 if (!d->pc_cnt) { in power_cut_emulated()
2508 /* First call - decide delay to the power cut */ in power_cut_emulated()
2513 d->pc_delay = 1; in power_cut_emulated()
2516 d->pc_timeout = jiffies; in power_cut_emulated()
2517 d->pc_timeout += msecs_to_jiffies(delay); in power_cut_emulated()
2518 ubifs_warn(c, "failing after %lums", delay); in power_cut_emulated()
2520 d->pc_delay = 2; in power_cut_emulated()
2523 d->pc_cnt_max = delay; in power_cut_emulated()
2524 ubifs_warn(c, "failing after %lu calls", delay); in power_cut_emulated()
2528 d->pc_cnt += 1; in power_cut_emulated()
2532 if (d->pc_delay == 1 && time_before(jiffies, d->pc_timeout)) in power_cut_emulated()
2534 if (d->pc_delay == 2 && d->pc_cnt++ < d->pc_cnt_max) in power_cut_emulated()
2542 ubifs_warn(c, "failing in super block LEB %d", lnum); in power_cut_emulated()
2546 ubifs_warn(c, "failing in master LEB %d", lnum); in power_cut_emulated()
2547 } else if (lnum >= UBIFS_LOG_LNUM && lnum <= c->log_last) { in power_cut_emulated()
2552 ubifs_warn(c, "failing in log LEB %d", lnum); in power_cut_emulated()
2553 } else if (lnum >= c->lpt_first && lnum <= c->lpt_last) { in power_cut_emulated()
2558 ubifs_warn(c, "failing in LPT LEB %d", lnum); in power_cut_emulated()
2559 } else if (lnum >= c->orph_first && lnum <= c->orph_last) { in power_cut_emulated()
2564 ubifs_warn(c, "failing in orphan LEB %d", lnum); in power_cut_emulated()
2565 } else if (lnum == c->ihead_lnum) { in power_cut_emulated()
2568 ubifs_warn(c, "failing in index head LEB %d", lnum); in power_cut_emulated()
2569 } else if (c->jheads && lnum == c->jheads[GCHD].wbuf.lnum) { in power_cut_emulated()
2572 ubifs_warn(c, "failing in GC head LEB %d", lnum); in power_cut_emulated()
2573 } else if (write && !RB_EMPTY_ROOT(&c->buds) && in power_cut_emulated()
2574 !ubifs_search_bud(c, lnum)) { in power_cut_emulated()
2577 ubifs_warn(c, "failing in non-bud LEB %d", lnum); in power_cut_emulated()
2578 } else if (c->cmt_state == COMMIT_RUNNING_BACKGROUND || in power_cut_emulated()
2579 c->cmt_state == COMMIT_RUNNING_REQUIRED) { in power_cut_emulated()
2582 ubifs_warn(c, "failing in bud LEB %d commit running", lnum); in power_cut_emulated()
2586 ubifs_warn(c, "failing in bud LEB %d commit not running", lnum); in power_cut_emulated()
2589 d->pc_happened = 1; in power_cut_emulated()
2590 ubifs_warn(c, "========== Power cut emulated =========="); in power_cut_emulated()
2595 static int corrupt_data(const struct ubifs_info *c, const void *buf, in corrupt_data() argument
2603 to = min(len, ALIGN(from + 1, c->max_write_size)); in corrupt_data()
2605 ubifs_warn(c, "filled bytes %u-%u with %s", from, to - 1, in corrupt_data()
2609 memset(p + from, 0xFF, to - from); in corrupt_data()
2611 prandom_bytes(p + from, to - from); in corrupt_data()
2616 int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, in dbg_leb_write() argument
2621 if (c->dbg->pc_happened) in dbg_leb_write()
2622 return -EROFS; in dbg_leb_write()
2624 failing = power_cut_emulated(c, lnum, 1); in dbg_leb_write()
2626 len = corrupt_data(c, buf, len); in dbg_leb_write()
2627 ubifs_warn(c, "actually write %d bytes to LEB %d:%d (the buffer was corrupted)", in dbg_leb_write()
2630 err = ubi_leb_write(c->ubi, lnum, buf, offs, len); in dbg_leb_write()
2634 return -EROFS; in dbg_leb_write()
2638 int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, in dbg_leb_change() argument
2643 if (c->dbg->pc_happened) in dbg_leb_change()
2644 return -EROFS; in dbg_leb_change()
2645 if (power_cut_emulated(c, lnum, 1)) in dbg_leb_change()
2646 return -EROFS; in dbg_leb_change()
2647 err = ubi_leb_change(c->ubi, lnum, buf, len); in dbg_leb_change()
2650 if (power_cut_emulated(c, lnum, 1)) in dbg_leb_change()
2651 return -EROFS; in dbg_leb_change()
2655 int dbg_leb_unmap(struct ubifs_info *c, int lnum) in dbg_leb_unmap() argument
2659 if (c->dbg->pc_happened) in dbg_leb_unmap()
2660 return -EROFS; in dbg_leb_unmap()
2661 if (power_cut_emulated(c, lnum, 0)) in dbg_leb_unmap()
2662 return -EROFS; in dbg_leb_unmap()
2663 err = ubi_leb_unmap(c->ubi, lnum); in dbg_leb_unmap()
2666 if (power_cut_emulated(c, lnum, 0)) in dbg_leb_unmap()
2667 return -EROFS; in dbg_leb_unmap()
2671 int dbg_leb_map(struct ubifs_info *c, int lnum) in dbg_leb_map() argument
2675 if (c->dbg->pc_happened) in dbg_leb_map()
2676 return -EROFS; in dbg_leb_map()
2677 if (power_cut_emulated(c, lnum, 0)) in dbg_leb_map()
2678 return -EROFS; in dbg_leb_map()
2679 err = ubi_leb_map(c->ubi, lnum); in dbg_leb_map()
2682 if (power_cut_emulated(c, lnum, 0)) in dbg_leb_map()
2683 return -EROFS; in dbg_leb_map()
2688 * Root directory for UBIFS stuff in debugfs. Contains sub-directories which
2689 * contain the stuff specific to particular file-system mounts.
2695 file->private_data = inode->i_private; in dfs_file_open()
2700 * provide_user_output - provide output to the user reading a debugfs file.
2729 struct dentry *dent = file->f_path.dentry; in dfs_file_read()
2730 struct ubifs_info *c = file->private_data; in dfs_file_read() local
2731 struct ubifs_debug_info *d = c->dbg; in dfs_file_read()
2734 if (dent == d->dfs_chk_gen) in dfs_file_read()
2735 val = d->chk_gen; in dfs_file_read()
2736 else if (dent == d->dfs_chk_index) in dfs_file_read()
2737 val = d->chk_index; in dfs_file_read()
2738 else if (dent == d->dfs_chk_orph) in dfs_file_read()
2739 val = d->chk_orph; in dfs_file_read()
2740 else if (dent == d->dfs_chk_lprops) in dfs_file_read()
2741 val = d->chk_lprops; in dfs_file_read()
2742 else if (dent == d->dfs_chk_fs) in dfs_file_read()
2743 val = d->chk_fs; in dfs_file_read()
2744 else if (dent == d->dfs_tst_rcvry) in dfs_file_read()
2745 val = d->tst_rcvry; in dfs_file_read()
2746 else if (dent == d->dfs_ro_error) in dfs_file_read()
2747 val = c->ro_error; in dfs_file_read()
2749 return -EINVAL; in dfs_file_read()
2755 * interpret_user_input - interpret user debugfs file input.
2756 * @u: user-provided buffer with the input
2768 buf_size = min_t(size_t, count, (sizeof(buf) - 1)); in interpret_user_input()
2770 return -EFAULT; in interpret_user_input()
2777 return -EINVAL; in interpret_user_input()
2783 struct ubifs_info *c = file->private_data; in dfs_file_write() local
2784 struct ubifs_debug_info *d = c->dbg; in dfs_file_write()
2785 struct dentry *dent = file->f_path.dentry; in dfs_file_write()
2789 * TODO: this is racy - the file-system might have already been in dfs_file_write()
2792 * a debugfs opened, we rember FS's UUID in file->private_data. Then in dfs_file_write()
2798 * 'ubifs-debug' file-system instead. in dfs_file_write()
2800 if (file->f_path.dentry == d->dfs_dump_lprops) { in dfs_file_write()
2801 ubifs_dump_lprops(c); in dfs_file_write()
2804 if (file->f_path.dentry == d->dfs_dump_budg) { in dfs_file_write()
2805 ubifs_dump_budg(c, &c->bi); in dfs_file_write()
2808 if (file->f_path.dentry == d->dfs_dump_tnc) { in dfs_file_write()
2809 mutex_lock(&c->tnc_mutex); in dfs_file_write()
2810 ubifs_dump_tnc(c); in dfs_file_write()
2811 mutex_unlock(&c->tnc_mutex); in dfs_file_write()
2819 if (dent == d->dfs_chk_gen) in dfs_file_write()
2820 d->chk_gen = val; in dfs_file_write()
2821 else if (dent == d->dfs_chk_index) in dfs_file_write()
2822 d->chk_index = val; in dfs_file_write()
2823 else if (dent == d->dfs_chk_orph) in dfs_file_write()
2824 d->chk_orph = val; in dfs_file_write()
2825 else if (dent == d->dfs_chk_lprops) in dfs_file_write()
2826 d->chk_lprops = val; in dfs_file_write()
2827 else if (dent == d->dfs_chk_fs) in dfs_file_write()
2828 d->chk_fs = val; in dfs_file_write()
2829 else if (dent == d->dfs_tst_rcvry) in dfs_file_write()
2830 d->tst_rcvry = val; in dfs_file_write()
2831 else if (dent == d->dfs_ro_error) in dfs_file_write()
2832 c->ro_error = !!val; in dfs_file_write()
2834 return -EINVAL; in dfs_file_write()
2848 * dbg_debugfs_init_fs - initialize debugfs for UBIFS instance.
2849 * @c: UBIFS file-system description object
2859 int dbg_debugfs_init_fs(struct ubifs_info *c) in dbg_debugfs_init_fs() argument
2864 struct ubifs_debug_info *d = c->dbg; in dbg_debugfs_init_fs()
2869 n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME, in dbg_debugfs_init_fs()
2870 c->vi.ubi_num, c->vi.vol_id); in dbg_debugfs_init_fs()
2874 dent = ERR_PTR(-EINVAL); in dbg_debugfs_init_fs()
2878 fname = d->dfs_dir_name; in dbg_debugfs_init_fs()
2882 d->dfs_dir = dent; in dbg_debugfs_init_fs()
2885 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); in dbg_debugfs_init_fs()
2888 d->dfs_dump_lprops = dent; in dbg_debugfs_init_fs()
2891 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); in dbg_debugfs_init_fs()
2894 d->dfs_dump_budg = dent; in dbg_debugfs_init_fs()
2897 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); in dbg_debugfs_init_fs()
2900 d->dfs_dump_tnc = dent; in dbg_debugfs_init_fs()
2903 dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, in dbg_debugfs_init_fs()
2907 d->dfs_chk_gen = dent; in dbg_debugfs_init_fs()
2910 dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, in dbg_debugfs_init_fs()
2914 d->dfs_chk_index = dent; in dbg_debugfs_init_fs()
2917 dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, in dbg_debugfs_init_fs()
2921 d->dfs_chk_orph = dent; in dbg_debugfs_init_fs()
2924 dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, in dbg_debugfs_init_fs()
2928 d->dfs_chk_lprops = dent; in dbg_debugfs_init_fs()
2931 dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, in dbg_debugfs_init_fs()
2935 d->dfs_chk_fs = dent; in dbg_debugfs_init_fs()
2938 dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, in dbg_debugfs_init_fs()
2942 d->dfs_tst_rcvry = dent; in dbg_debugfs_init_fs()
2945 dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, in dbg_debugfs_init_fs()
2949 d->dfs_ro_error = dent; in dbg_debugfs_init_fs()
2954 debugfs_remove_recursive(d->dfs_dir); in dbg_debugfs_init_fs()
2956 err = dent ? PTR_ERR(dent) : -ENODEV; in dbg_debugfs_init_fs()
2957 ubifs_err(c, "cannot create \"%s\" debugfs file or directory, error %d\n", in dbg_debugfs_init_fs()
2963 * dbg_debugfs_exit_fs - remove all debugfs files.
2964 * @c: UBIFS file-system description object
2966 void dbg_debugfs_exit_fs(struct ubifs_info *c) in dbg_debugfs_exit_fs() argument
2969 debugfs_remove_recursive(c->dbg->dfs_dir); in dbg_debugfs_exit_fs()
2984 struct dentry *dent = file->f_path.dentry; in dfs_global_file_read()
3000 return -EINVAL; in dfs_global_file_read()
3008 struct dentry *dent = file->f_path.dentry; in dfs_global_file_write()
3028 return -EINVAL; in dfs_global_file_write()
3041 * dbg_debugfs_init - initialize debugfs file-system.
3043 * UBIFS uses debugfs file-system to expose various debugging knobs to
3044 * user-space. This function creates "ubifs" directory in the debugfs
3045 * file-system. Returns zero in case of success and a negative error code in
3110 err = dent ? PTR_ERR(dent) : -ENODEV; in dbg_debugfs_init()
3112 current->pid, fname, err); in dbg_debugfs_init()
3117 * dbg_debugfs_exit - remove the "ubifs" directory from debugfs file-system.
3126 * ubifs_debugging_init - initialize UBIFS debugging.
3127 * @c: UBIFS file-system description object
3129 * This function initializes debugging-related data for the file system.
3133 int ubifs_debugging_init(struct ubifs_info *c) in ubifs_debugging_init() argument
3135 c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL); in ubifs_debugging_init()
3136 if (!c->dbg) in ubifs_debugging_init()
3137 return -ENOMEM; in ubifs_debugging_init()
3143 * ubifs_debugging_exit - free debugging data.
3144 * @c: UBIFS file-system description object
3146 void ubifs_debugging_exit(struct ubifs_info *c) in ubifs_debugging_exit() argument
3148 kfree(c->dbg); in ubifs_debugging_exit()