LCOV - code coverage report
Current view: top level - libubifs - debug.c (source / functions) Hit Total Coverage
Test: a simple test Lines: 341 446 76.5 %
Date: 2024-06-05 20:10:43 Functions: 15 20 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0-only
       2             : /*
       3             :  * This file is part of UBIFS.
       4             :  *
       5             :  * Copyright (C) 2006-2008 Nokia Corporation
       6             :  *
       7             :  * Authors: Artem Bityutskiy (Битюцкий Артём)
       8             :  *          Adrian Hunter
       9             :  */
      10             : 
      11             : /*
      12             :  * This file implements most of the debugging stuff which is compiled in only
      13             :  * when it is enabled. But some debugging check functions are implemented in
      14             :  * corresponding subsystem, just because they are closely related and utilize
      15             :  * various local functions of those subsystems.
      16             :  */
      17             : 
      18             : #include <stdio.h>
      19             : #include <unistd.h>
      20             : 
      21             : #include "linux_err.h"
      22             : #include "bitops.h"
      23             : #include "kmem.h"
      24             : #include "ubifs.h"
      25             : #include "defs.h"
      26             : #include "debug.h"
      27             : #include "key.h"
      28             : #include "misc.h"
      29             : 
      30             : static DEFINE_SPINLOCK(dbg_lock);
      31             : 
      32             : static const char *get_key_fmt(int fmt)
      33             : {
      34          36 :         switch (fmt) {
      35             :         case UBIFS_SIMPLE_KEY_FMT:
      36             :                 return "simple";
      37           0 :         default:
      38             :                 return "unknown/invalid format";
      39             :         }
      40             : }
      41             : 
      42             : static const char *get_key_hash(int hash)
      43             : {
      44          36 :         switch (hash) {
      45             :         case UBIFS_KEY_HASH_R5:
      46             :                 return "R5";
      47           0 :         case UBIFS_KEY_HASH_TEST:
      48             :                 return "test";
      49           0 :         default:
      50             :                 return "unknown/invalid name hash";
      51             :         }
      52             : }
      53             : 
      54     6364080 : const char *ubifs_get_key_name(int type)
      55             : {
      56             :         switch (type) {
      57             :         case UBIFS_INO_KEY:
      58             :                 return "inode";
      59             :         case UBIFS_DENT_KEY:
      60             :                 return "direntry";
      61             :         case UBIFS_XENT_KEY:
      62             :                 return "xentry";
      63             :         case UBIFS_DATA_KEY:
      64             :                 return "data";
      65             :         case UBIFS_TRUN_KEY:
      66             :                 return "truncate";
      67             :         default:
      68             :                 return "unknown/invalid key";
      69             :         }
      70             : }
      71             : 
      72      130049 : const char *ubifs_get_type_name(int type)
      73             : {
      74             :         switch (type) {
      75             :         case UBIFS_ITYPE_REG:
      76             :                 return "file";
      77             :         case UBIFS_ITYPE_DIR:
      78             :                 return "dir";
      79             :         case UBIFS_ITYPE_LNK:
      80             :                 return "symlink";
      81             :         case UBIFS_ITYPE_BLK:
      82             :                 return "blkdev";
      83             :         case UBIFS_ITYPE_CHR:
      84             :                 return "char dev";
      85             :         case UBIFS_ITYPE_FIFO:
      86             :                 return "fifo";
      87             :         case UBIFS_ITYPE_SOCK:
      88             :                 return "socket";
      89             :         default:
      90             :                 return "unknown/invalid type";
      91             :         }
      92             : }
      93             : 
      94     5815610 : const char *dbg_snprintf_key(const struct ubifs_info *c,
      95             :                              const union ubifs_key *key, char *buffer, int len)
      96             : {
      97     5815610 :         char *p = buffer;
      98    11631220 :         int type = key_type(c, key);
      99             : 
     100     5815610 :         if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) {
     101     5815610 :                 switch (type) {
     102      530280 :                 case UBIFS_INO_KEY:
     103     1060560 :                         len -= snprintf(p, len, "(%lu, %s)",
     104     1060560 :                                         (unsigned long)key_inum(c, key),
     105             :                                         ubifs_get_key_name(type));
     106      530280 :                         break;
     107      155194 :                 case UBIFS_DENT_KEY:
     108             :                 case UBIFS_XENT_KEY:
     109      465582 :                         len -= snprintf(p, len, "(%lu, %s, %#08x)",
     110      310388 :                                         (unsigned long)key_inum(c, key),
     111             :                                         ubifs_get_key_name(type),
     112             :                                         key_hash(c, key));
     113      155194 :                         break;
     114     5123786 :                 case UBIFS_DATA_KEY:
     115    15371358 :                         len -= snprintf(p, len, "(%lu, %s, %u)",
     116    10247572 :                                         (unsigned long)key_inum(c, key),
     117             :                                         ubifs_get_key_name(type),
     118             :                                         key_block(c, key));
     119     5123786 :                         break;
     120        5552 :                 case UBIFS_TRUN_KEY:
     121       11104 :                         len -= snprintf(p, len, "(%lu, %s)",
     122       11104 :                                         (unsigned long)key_inum(c, key),
     123             :                                         ubifs_get_key_name(type));
     124        5552 :                         break;
     125         798 :                 default:
     126         798 :                         len -= snprintf(p, len, "(bad key type: %#08x, %#08x)",
     127             :                                         key->u32[0], key->u32[1]);
     128             :                 }
     129             :         } else
     130           0 :                 len -= snprintf(p, len, "bad key format %d", c->key_fmt);
     131     5815610 :         ubifs_assert(c, len > 0);
     132     5815610 :         return p;
     133             : }
     134             : 
     135    30691136 : const char *dbg_ntype(int type)
     136             : {
     137             :         switch (type) {
     138             :         case UBIFS_PAD_NODE:
     139             :                 return "padding node";
     140             :         case UBIFS_SB_NODE:
     141             :                 return "superblock node";
     142             :         case UBIFS_MST_NODE:
     143             :                 return "master node";
     144             :         case UBIFS_REF_NODE:
     145             :                 return "reference node";
     146             :         case UBIFS_INO_NODE:
     147             :                 return "inode node";
     148             :         case UBIFS_DENT_NODE:
     149             :                 return "direntry node";
     150             :         case UBIFS_XENT_NODE:
     151             :                 return "xentry node";
     152             :         case UBIFS_DATA_NODE:
     153             :                 return "data node";
     154             :         case UBIFS_TRUN_NODE:
     155             :                 return "truncate node";
     156             :         case UBIFS_IDX_NODE:
     157             :                 return "indexing node";
     158             :         case UBIFS_CS_NODE:
     159             :                 return "commit start node";
     160             :         case UBIFS_ORPH_NODE:
     161             :                 return "orphan node";
     162             :         case UBIFS_AUTH_NODE:
     163             :                 return "auth node";
     164             :         default:
     165             :                 return "unknown node";
     166             :         }
     167             : }
     168             : 
     169             : static const char *dbg_gtype(int type)
     170             : {
     171             :         switch (type) {
     172             :         case UBIFS_NO_NODE_GROUP:
     173             :                 return "no node group";
     174             :         case UBIFS_IN_NODE_GROUP:
     175             :                 return "in node group";
     176             :         case UBIFS_LAST_OF_NODE_GROUP:
     177             :                 return "last of node group";
     178             :         default:
     179             :                 return "unknown";
     180             :         }
     181             : }
     182             : 
     183           0 : const char *dbg_cstate(int cmt_state)
     184             : {
     185             :         switch (cmt_state) {
     186             :         case COMMIT_RESTING:
     187             :                 return "commit resting";
     188             :         case COMMIT_BACKGROUND:
     189             :                 return "background commit requested";
     190             :         case COMMIT_REQUIRED:
     191             :                 return "commit required";
     192             :         case COMMIT_RUNNING_BACKGROUND:
     193             :                 return "BACKGROUND commit running";
     194             :         case COMMIT_RUNNING_REQUIRED:
     195             :                 return "commit running and required";
     196             :         case COMMIT_BROKEN:
     197             :                 return "broken commit";
     198             :         default:
     199             :                 return "unknown commit state";
     200             :         }
     201             : }
     202             : 
     203       16936 : const char *dbg_jhead(int jhead)
     204             : {
     205             :         switch (jhead) {
     206             :         case GCHD:
     207             :                 return "0 (GC)";
     208             :         case BASEHD:
     209             :                 return "1 (base)";
     210             :         case DATAHD:
     211             :                 return "2 (data)";
     212             :         default:
     213             :                 return "unknown journal head";
     214             :         }
     215             : }
     216             : 
     217        2079 : static void dump_ch(const struct ubifs_ch *ch)
     218             : {
     219        2079 :         pr_err("\tmagic          %#x\n", le32_to_cpu(ch->magic));
     220        2079 :         pr_err("\tcrc            %#x\n", le32_to_cpu(ch->crc));
     221        2079 :         pr_err("\tnode_type      %d (%s)\n", ch->node_type,
     222             :                dbg_ntype(ch->node_type));
     223        2079 :         pr_err("\tgroup_type     %d (%s)\n", ch->group_type,
     224             :                dbg_gtype(ch->group_type));
     225        2079 :         pr_err("\tsqnum          %llu\n",
     226             :                (unsigned long long)le64_to_cpu(ch->sqnum));
     227        2079 :         pr_err("\tlen            %u\n", le32_to_cpu(ch->len));
     228        2079 : }
     229             : 
     230      187500 : void ubifs_dump_node(const struct ubifs_info *c, const void *node, int node_len)
     231             : {
     232             :         int i, n, type, safe_len, max_node_len, min_node_len;
     233             :         union ubifs_key key;
     234      187500 :         const struct ubifs_ch *ch = node;
     235             :         char key_buf[DBG_KEY_BUF_LEN];
     236             : 
     237             :         /* If the magic is incorrect, just hexdump the first bytes */
     238      187500 :         if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) {
     239      185178 :                 pr_err("Not a node, first %zu bytes:", UBIFS_CH_SZ);
     240      185178 :                 print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
     241             :                                (void *)node, UBIFS_CH_SZ, 1);
     242      185178 :                 return;
     243             :         }
     244             : 
     245             :         /* Skip dumping unknown type node */
     246        2322 :         type = ch->node_type;
     247        2322 :         if (type < 0 || type >= UBIFS_NODE_TYPES_CNT) {
     248         243 :                 pr_err("node type %d was not recognized\n", type);
     249             :                 return;
     250             :         }
     251             : 
     252        2079 :         spin_lock(&dbg_lock);
     253        2079 :         dump_ch(node);
     254             : 
     255        2079 :         if (c->ranges[type].max_len == 0) {
     256         123 :                 max_node_len = min_node_len = c->ranges[type].len;
     257             :         } else {
     258        1956 :                 max_node_len = c->ranges[type].max_len;
     259        1956 :                 min_node_len = c->ranges[type].min_len;
     260             :         }
     261        2079 :         safe_len = le32_to_cpu(ch->len);
     262        2079 :         safe_len = safe_len > 0 ? safe_len : 0;
     263        2079 :         safe_len = min3(safe_len, max_node_len, node_len);
     264        2079 :         if (safe_len < min_node_len) {
     265          20 :                 pr_err("node len(%d) is too short for %s, left %d bytes:\n",
     266             :                        safe_len, dbg_ntype(type),
     267             :                        safe_len > UBIFS_CH_SZ ?
     268             :                        safe_len - (int)UBIFS_CH_SZ : 0);
     269          20 :                 if (safe_len > UBIFS_CH_SZ)
     270           2 :                         print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 1,
     271             :                                        (void *)node + UBIFS_CH_SZ,
     272             :                                        safe_len - UBIFS_CH_SZ, 0);
     273             :                 goto out_unlock;
     274             :         }
     275        2059 :         if (safe_len != le32_to_cpu(ch->len))
     276          16 :                 pr_err("\ttruncated node length      %d\n", safe_len);
     277             : 
     278        2059 :         switch (type) {
     279          55 :         case UBIFS_PAD_NODE:
     280             :         {
     281          55 :                 const struct ubifs_pad_node *pad = node;
     282             : 
     283          55 :                 pr_err("\tpad_len        %u\n", le32_to_cpu(pad->pad_len));
     284             :                 break;
     285             :         }
     286          36 :         case UBIFS_SB_NODE:
     287             :         {
     288          36 :                 const struct ubifs_sb_node *sup = node;
     289          36 :                 unsigned int sup_flags = le32_to_cpu(sup->flags);
     290             : 
     291          72 :                 pr_err("\tkey_hash       %d (%s)\n",
     292             :                        (int)sup->key_hash, get_key_hash(sup->key_hash));
     293          72 :                 pr_err("\tkey_fmt        %d (%s)\n",
     294             :                        (int)sup->key_fmt, get_key_fmt(sup->key_fmt));
     295          36 :                 pr_err("\tflags          %#x\n", sup_flags);
     296          36 :                 pr_err("\tbig_lpt        %u\n",
     297             :                        !!(sup_flags & UBIFS_FLG_BIGLPT));
     298          36 :                 pr_err("\tspace_fixup    %u\n",
     299             :                        !!(sup_flags & UBIFS_FLG_SPACE_FIXUP));
     300          36 :                 pr_err("\tmin_io_size    %u\n", le32_to_cpu(sup->min_io_size));
     301          36 :                 pr_err("\tleb_size       %u\n", le32_to_cpu(sup->leb_size));
     302          36 :                 pr_err("\tleb_cnt        %u\n", le32_to_cpu(sup->leb_cnt));
     303          36 :                 pr_err("\tmax_leb_cnt    %u\n", le32_to_cpu(sup->max_leb_cnt));
     304          36 :                 pr_err("\tmax_bud_bytes  %llu\n",
     305             :                        (unsigned long long)le64_to_cpu(sup->max_bud_bytes));
     306          36 :                 pr_err("\tlog_lebs       %u\n", le32_to_cpu(sup->log_lebs));
     307          36 :                 pr_err("\tlpt_lebs       %u\n", le32_to_cpu(sup->lpt_lebs));
     308          36 :                 pr_err("\torph_lebs      %u\n", le32_to_cpu(sup->orph_lebs));
     309          36 :                 pr_err("\tjhead_cnt      %u\n", le32_to_cpu(sup->jhead_cnt));
     310          36 :                 pr_err("\tfanout         %u\n", le32_to_cpu(sup->fanout));
     311          36 :                 pr_err("\tlsave_cnt      %u\n", le32_to_cpu(sup->lsave_cnt));
     312          36 :                 pr_err("\tdefault_compr  %u\n",
     313             :                        (int)le16_to_cpu(sup->default_compr));
     314          36 :                 pr_err("\trp_size        %llu\n",
     315             :                        (unsigned long long)le64_to_cpu(sup->rp_size));
     316          36 :                 pr_err("\trp_uid         %u\n", le32_to_cpu(sup->rp_uid));
     317          36 :                 pr_err("\trp_gid         %u\n", le32_to_cpu(sup->rp_gid));
     318          36 :                 pr_err("\tfmt_version    %u\n", le32_to_cpu(sup->fmt_version));
     319          36 :                 pr_err("\ttime_gran      %u\n", le32_to_cpu(sup->time_gran));
     320          36 :                 pr_err("\tUUID           %pUB\n", sup->uuid);
     321             :                 break;
     322             :         }
     323          30 :         case UBIFS_MST_NODE:
     324             :         {
     325          30 :                 const struct ubifs_mst_node *mst = node;
     326             : 
     327          30 :                 pr_err("\thighest_inum   %llu\n",
     328             :                        (unsigned long long)le64_to_cpu(mst->highest_inum));
     329          30 :                 pr_err("\tcommit number  %llu\n",
     330             :                        (unsigned long long)le64_to_cpu(mst->cmt_no));
     331          30 :                 pr_err("\tflags          %#x\n", le32_to_cpu(mst->flags));
     332          30 :                 pr_err("\tlog_lnum       %u\n", le32_to_cpu(mst->log_lnum));
     333          30 :                 pr_err("\troot_lnum      %u\n", le32_to_cpu(mst->root_lnum));
     334          30 :                 pr_err("\troot_offs      %u\n", le32_to_cpu(mst->root_offs));
     335          30 :                 pr_err("\troot_len       %u\n", le32_to_cpu(mst->root_len));
     336          30 :                 pr_err("\tgc_lnum        %u\n", le32_to_cpu(mst->gc_lnum));
     337          30 :                 pr_err("\tihead_lnum     %u\n", le32_to_cpu(mst->ihead_lnum));
     338          30 :                 pr_err("\tihead_offs     %u\n", le32_to_cpu(mst->ihead_offs));
     339          30 :                 pr_err("\tindex_size     %llu\n",
     340             :                        (unsigned long long)le64_to_cpu(mst->index_size));
     341          30 :                 pr_err("\tlpt_lnum       %u\n", le32_to_cpu(mst->lpt_lnum));
     342          30 :                 pr_err("\tlpt_offs       %u\n", le32_to_cpu(mst->lpt_offs));
     343          30 :                 pr_err("\tnhead_lnum     %u\n", le32_to_cpu(mst->nhead_lnum));
     344          30 :                 pr_err("\tnhead_offs     %u\n", le32_to_cpu(mst->nhead_offs));
     345          30 :                 pr_err("\tltab_lnum      %u\n", le32_to_cpu(mst->ltab_lnum));
     346          30 :                 pr_err("\tltab_offs      %u\n", le32_to_cpu(mst->ltab_offs));
     347          30 :                 pr_err("\tlsave_lnum     %u\n", le32_to_cpu(mst->lsave_lnum));
     348          30 :                 pr_err("\tlsave_offs     %u\n", le32_to_cpu(mst->lsave_offs));
     349          30 :                 pr_err("\tlscan_lnum     %u\n", le32_to_cpu(mst->lscan_lnum));
     350          30 :                 pr_err("\tleb_cnt        %u\n", le32_to_cpu(mst->leb_cnt));
     351          30 :                 pr_err("\tempty_lebs     %u\n", le32_to_cpu(mst->empty_lebs));
     352          30 :                 pr_err("\tidx_lebs       %u\n", le32_to_cpu(mst->idx_lebs));
     353          30 :                 pr_err("\ttotal_free     %llu\n",
     354             :                        (unsigned long long)le64_to_cpu(mst->total_free));
     355          30 :                 pr_err("\ttotal_dirty    %llu\n",
     356             :                        (unsigned long long)le64_to_cpu(mst->total_dirty));
     357          30 :                 pr_err("\ttotal_used     %llu\n",
     358             :                        (unsigned long long)le64_to_cpu(mst->total_used));
     359          30 :                 pr_err("\ttotal_dead     %llu\n",
     360             :                        (unsigned long long)le64_to_cpu(mst->total_dead));
     361          30 :                 pr_err("\ttotal_dark     %llu\n",
     362             :                        (unsigned long long)le64_to_cpu(mst->total_dark));
     363             :                 break;
     364             :         }
     365           0 :         case UBIFS_REF_NODE:
     366             :         {
     367           0 :                 const struct ubifs_ref_node *ref = node;
     368             : 
     369           0 :                 pr_err("\tlnum           %u\n", le32_to_cpu(ref->lnum));
     370           0 :                 pr_err("\toffs           %u\n", le32_to_cpu(ref->offs));
     371           0 :                 pr_err("\tjhead          %u\n", le32_to_cpu(ref->jhead));
     372             :                 break;
     373             :         }
     374         718 :         case UBIFS_INO_NODE:
     375             :         {
     376         718 :                 const struct ubifs_ino_node *ino = node;
     377             : 
     378        1436 :                 key_read(c, &ino->key, &key);
     379         718 :                 pr_err("\tkey            %s\n",
     380             :                        dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
     381         718 :                 pr_err("\tcreat_sqnum    %llu\n",
     382             :                        (unsigned long long)le64_to_cpu(ino->creat_sqnum));
     383         718 :                 pr_err("\tsize           %llu\n",
     384             :                        (unsigned long long)le64_to_cpu(ino->size));
     385         718 :                 pr_err("\tnlink          %u\n", le32_to_cpu(ino->nlink));
     386         718 :                 pr_err("\tatime          %lld.%u\n",
     387             :                        (long long)le64_to_cpu(ino->atime_sec),
     388             :                        le32_to_cpu(ino->atime_nsec));
     389         718 :                 pr_err("\tmtime          %lld.%u\n",
     390             :                        (long long)le64_to_cpu(ino->mtime_sec),
     391             :                        le32_to_cpu(ino->mtime_nsec));
     392         718 :                 pr_err("\tctime          %lld.%u\n",
     393             :                        (long long)le64_to_cpu(ino->ctime_sec),
     394             :                        le32_to_cpu(ino->ctime_nsec));
     395         718 :                 pr_err("\tuid            %u\n", le32_to_cpu(ino->uid));
     396         718 :                 pr_err("\tgid            %u\n", le32_to_cpu(ino->gid));
     397         718 :                 pr_err("\tmode           %u\n", le32_to_cpu(ino->mode));
     398         718 :                 pr_err("\tflags          %#x\n", le32_to_cpu(ino->flags));
     399         718 :                 pr_err("\txattr_cnt      %u\n", le32_to_cpu(ino->xattr_cnt));
     400         718 :                 pr_err("\txattr_size     %u\n", le32_to_cpu(ino->xattr_size));
     401         718 :                 pr_err("\txattr_names    %u\n", le32_to_cpu(ino->xattr_names));
     402         718 :                 pr_err("\tcompr_type     %#x\n",
     403             :                        (int)le16_to_cpu(ino->compr_type));
     404         718 :                 pr_err("\tdata len       %u\n", le32_to_cpu(ino->data_len));
     405             :                 break;
     406             :         }
     407         108 :         case UBIFS_DENT_NODE:
     408             :         case UBIFS_XENT_NODE:
     409             :         {
     410         108 :                 const struct ubifs_dent_node *dent = node;
     411         108 :                 int nlen = le16_to_cpu(dent->nlen);
     412             : 
     413         216 :                 key_read(c, &dent->key, &key);
     414         108 :                 pr_err("\tkey            %s\n",
     415             :                        dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
     416         108 :                 pr_err("\tinum           %llu\n",
     417             :                        (unsigned long long)le64_to_cpu(dent->inum));
     418         108 :                 pr_err("\ttype           %d\n", (int)dent->type);
     419         108 :                 pr_err("\tnlen           %d\n", nlen);
     420         108 :                 pr_err("\tname           ");
     421             : 
     422         215 :                 if (nlen > UBIFS_MAX_NLEN ||
     423         107 :                     nlen > safe_len - UBIFS_DENT_NODE_SZ)
     424           1 :                         pr_err("(bad name length, not printing, bad or corrupted node)");
     425             :                 else {
     426        3179 :                         for (i = 0; i < nlen && dent->name[i]; i++)
     427        3179 :                                 pr_cont("%c", isprint(dent->name[i]) ?
     428             :                                         dent->name[i] : '?');
     429             :                 }
     430         108 :                 pr_cont("\n");
     431             : 
     432             :                 break;
     433             :         }
     434         286 :         case UBIFS_DATA_NODE:
     435             :         {
     436         286 :                 const struct ubifs_data_node *dn = node;
     437             : 
     438         572 :                 key_read(c, &dn->key, &key);
     439         286 :                 pr_err("\tkey            %s\n",
     440             :                        dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
     441         286 :                 pr_err("\tsize           %u\n", le32_to_cpu(dn->size));
     442         286 :                 pr_err("\tcompr_typ      %d\n",
     443             :                        (int)le16_to_cpu(dn->compr_type));
     444         286 :                 pr_err("\tdata size      %u\n",
     445             :                        le32_to_cpu(ch->len) - (unsigned int)UBIFS_DATA_NODE_SZ);
     446         286 :                 pr_err("\tdata (length = %d):\n",
     447             :                        safe_len - (int)UBIFS_DATA_NODE_SZ);
     448         572 :                 print_hex_dump("\t", DUMP_PREFIX_OFFSET, 32, 1,
     449         286 :                                (void *)&dn->data,
     450         286 :                                safe_len - (int)UBIFS_DATA_NODE_SZ, 0);
     451         286 :                 break;
     452             :         }
     453           2 :         case UBIFS_TRUN_NODE:
     454             :         {
     455           2 :                 const struct ubifs_trun_node *trun = node;
     456             : 
     457           2 :                 pr_err("\tinum           %u\n", le32_to_cpu(trun->inum));
     458           2 :                 pr_err("\told_size       %llu\n",
     459             :                        (unsigned long long)le64_to_cpu(trun->old_size));
     460           2 :                 pr_err("\tnew_size       %llu\n",
     461             :                        (unsigned long long)le64_to_cpu(trun->new_size));
     462             :                 break;
     463             :         }
     464         824 :         case UBIFS_IDX_NODE:
     465             :         {
     466         824 :                 const struct ubifs_idx_node *idx = node;
     467        1648 :                 int max_child_cnt = (safe_len - UBIFS_IDX_NODE_SZ) /
     468         824 :                                     (ubifs_idx_node_sz(c, 1) -
     469             :                                     UBIFS_IDX_NODE_SZ);
     470             : 
     471         824 :                 n = min_t(int, le16_to_cpu(idx->child_cnt), max_child_cnt);
     472         824 :                 pr_err("\tchild_cnt      %d\n", (int)le16_to_cpu(idx->child_cnt));
     473         824 :                 pr_err("\tlevel          %d\n", (int)le16_to_cpu(idx->level));
     474         824 :                 pr_err("\tBranches:\n");
     475             : 
     476        4834 :                 for (i = 0; i < n && i < c->fanout; i++) {
     477             :                         const struct ubifs_branch *br;
     478             : 
     479        4834 :                         br = ubifs_idx_branch(c, idx, i);
     480        9668 :                         key_read(c, &br->key, &key);
     481        4834 :                         pr_err("\t%d: LEB %d:%d len %d key %s\n",
     482             :                                i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs),
     483             :                                le32_to_cpu(br->len),
     484             :                                dbg_snprintf_key(c, &key, key_buf,
     485             :                                                 DBG_KEY_BUF_LEN));
     486             :                 }
     487             :                 break;
     488             :         }
     489             :         case UBIFS_CS_NODE:
     490             :                 break;
     491           0 :         case UBIFS_ORPH_NODE:
     492             :         {
     493           0 :                 const struct ubifs_orph_node *orph = node;
     494             : 
     495           0 :                 pr_err("\tcommit number  %llu\n",
     496             :                        (unsigned long long)
     497             :                                 le64_to_cpu(orph->cmt_no) & LLONG_MAX);
     498           0 :                 pr_err("\tlast node flag %llu\n",
     499             :                        (unsigned long long)(le64_to_cpu(orph->cmt_no)) >> 63);
     500           0 :                 n = (safe_len - UBIFS_ORPH_NODE_SZ) >> 3;
     501           0 :                 pr_err("\t%d orphan inode numbers:\n", n);
     502           0 :                 for (i = 0; i < n; i++)
     503           0 :                         pr_err("\t  ino %llu\n",
     504             :                                (unsigned long long)le64_to_cpu(orph->inos[i]));
     505             :                 break;
     506             :         }
     507             :         case UBIFS_AUTH_NODE:
     508             :         {
     509             :                 break;
     510             :         }
     511           0 :         default:
     512           0 :                 pr_err("node type %d was not recognized\n", type);
     513             :         }
     514             : 
     515        2079 : out_unlock:
     516        2079 :         spin_unlock(&dbg_lock);
     517             : }
     518             : 
     519           1 : void ubifs_dump_lstats(const struct ubifs_lp_stats *lst)
     520             : {
     521           1 :         spin_lock(&dbg_lock);
     522           1 :         pr_err("(pid %d) Lprops statistics: empty_lebs %d, idx_lebs  %d\n",
     523             :                getpid(), lst->empty_lebs, lst->idx_lebs);
     524           1 :         pr_err("\ttaken_empty_lebs %d, total_free %lld, total_dirty %lld\n",
     525             :                lst->taken_empty_lebs, lst->total_free, lst->total_dirty);
     526           1 :         pr_err("\ttotal_used %lld, total_dark %lld, total_dead %lld\n",
     527             :                lst->total_used, lst->total_dark, lst->total_dead);
     528           1 :         spin_unlock(&dbg_lock);
     529           1 : }
     530             : 
     531           1 : void ubifs_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi)
     532             : {
     533             :         int i;
     534             :         struct rb_node *rb;
     535             :         struct ubifs_bud *bud;
     536             :         struct ubifs_gced_idx_leb *idx_gc;
     537             :         long long available, outstanding, free;
     538             : 
     539           1 :         spin_lock(&c->space_lock);
     540           1 :         spin_lock(&dbg_lock);
     541           1 :         pr_err("(pid %d) Budgeting info: data budget sum %lld, total budget sum %lld\n",
     542             :                getpid(), bi->data_growth + bi->dd_growth,
     543             :                bi->data_growth + bi->dd_growth + bi->idx_growth);
     544           1 :         pr_err("\tbudg_data_growth %lld, budg_dd_growth %lld, budg_idx_growth %lld\n",
     545             :                bi->data_growth, bi->dd_growth, bi->idx_growth);
     546           1 :         pr_err("\tmin_idx_lebs %d, old_idx_sz %llu, uncommitted_idx %lld\n",
     547             :                bi->min_idx_lebs, bi->old_idx_sz, bi->uncommitted_idx);
     548           1 :         pr_err("\tpage_budget %d, inode_budget %d, dent_budget %d\n",
     549             :                bi->page_budget, bi->inode_budget, bi->dent_budget);
     550           1 :         pr_err("\tnospace %u, nospace_rp %u\n", bi->nospace, bi->nospace_rp);
     551           1 :         pr_err("\tdark_wm %d, dead_wm %d, max_idx_node_sz %d\n",
     552             :                c->dark_wm, c->dead_wm, c->max_idx_node_sz);
     553             : 
     554           1 :         if (bi != &c->bi)
     555             :                 /*
     556             :                  * If we are dumping saved budgeting data, do not print
     557             :                  * additional information which is about the current state, not
     558             :                  * the old one which corresponded to the saved budgeting data.
     559             :                  */
     560             :                 goto out_unlock;
     561             : 
     562           1 :         pr_err("\tfreeable_cnt %d, calc_idx_sz %lld, idx_gc_cnt %d\n",
     563             :                c->freeable_cnt, c->calc_idx_sz, c->idx_gc_cnt);
     564           1 :         pr_err("\tdirty_pg_cnt %ld, dirty_zn_cnt %ld, clean_zn_cnt %ld\n",
     565             :                atomic_long_read(&c->dirty_pg_cnt),
     566             :                atomic_long_read(&c->dirty_zn_cnt),
     567             :                atomic_long_read(&c->clean_zn_cnt));
     568           1 :         pr_err("\tgc_lnum %d, ihead_lnum %d\n", c->gc_lnum, c->ihead_lnum);
     569             : 
     570             :         /* If we are in R/O mode, journal heads do not exist */
     571           1 :         if (c->jheads)
     572           3 :                 for (i = 0; i < c->jhead_cnt; i++)
     573           3 :                         pr_err("\tjhead %s\t LEB %d\n",
     574             :                                dbg_jhead(c->jheads[i].wbuf.jhead),
     575             :                                c->jheads[i].wbuf.lnum);
     576           1 :         for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) {
     577           0 :                 bud = rb_entry(rb, struct ubifs_bud, rb);
     578           0 :                 pr_err("\tbud LEB %d\n", bud->lnum);
     579             :         }
     580           1 :         list_for_each_entry(bud, &c->old_buds, list)
     581           0 :                 pr_err("\told bud LEB %d\n", bud->lnum);
     582           1 :         list_for_each_entry(idx_gc, &c->idx_gc, list)
     583           0 :                 pr_err("\tGC'ed idx LEB %d unmap %d\n",
     584             :                        idx_gc->lnum, idx_gc->unmap);
     585           1 :         pr_err("\tcommit state %d\n", c->cmt_state);
     586             : 
     587             :         /* Print budgeting predictions */
     588           1 :         available = ubifs_calc_available(c, c->bi.min_idx_lebs);
     589           1 :         outstanding = c->bi.data_growth + c->bi.dd_growth;
     590           1 :         free = ubifs_get_free_space_nolock(c);
     591           1 :         pr_err("Budgeting predictions:\n");
     592           2 :         pr_err("\tavailable: %lld, outstanding %lld, free %lld\n",
     593             :                available, outstanding, free);
     594           1 : out_unlock:
     595           1 :         spin_unlock(&dbg_lock);
     596           1 :         spin_unlock(&c->space_lock);
     597           1 : }
     598             : 
     599        2032 : void ubifs_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp)
     600             : {
     601        2032 :         int i, spc, dark = 0, dead = 0;
     602             :         struct rb_node *rb;
     603             :         struct ubifs_bud *bud;
     604             : 
     605        2032 :         spc = lp->free + lp->dirty;
     606        2032 :         if (spc < c->dead_wm)
     607             :                 dead = spc;
     608             :         else
     609        2032 :                 dark = ubifs_calc_dark(c, spc);
     610             : 
     611        2032 :         if (lp->flags & LPROPS_INDEX)
     612         101 :                 pr_err("LEB %-7d free %-8d dirty %-8d used %-8d free + dirty %-8d flags %#x (",
     613             :                        lp->lnum, lp->free, lp->dirty, c->leb_size - spc, spc,
     614             :                        lp->flags);
     615             :         else
     616        1931 :                 pr_err("LEB %-7d free %-8d dirty %-8d used %-8d free + dirty %-8d dark %-4d dead %-4d nodes fit %-3d flags %#-4x (",
     617             :                        lp->lnum, lp->free, lp->dirty, c->leb_size - spc, spc,
     618             :                        dark, dead, (int)(spc / UBIFS_MAX_NODE_SZ), lp->flags);
     619             : 
     620        2032 :         if (lp->flags & LPROPS_TAKEN) {
     621           3 :                 if (lp->flags & LPROPS_INDEX)
     622           1 :                         pr_cont("index, taken");
     623             :                 else
     624           2 :                         pr_cont("taken");
     625             :         } else {
     626             :                 const char *s;
     627             : 
     628        2029 :                 if (lp->flags & LPROPS_INDEX) {
     629         100 :                         switch (lp->flags & LPROPS_CAT_MASK) {
     630             :                         case LPROPS_DIRTY_IDX:
     631             :                                 s = "dirty index";
     632             :                                 break;
     633           0 :                         case LPROPS_FRDI_IDX:
     634           0 :                                 s = "freeable index";
     635           0 :                                 break;
     636           0 :                         default:
     637           0 :                                 s = "index";
     638             :                         }
     639             :                 } else {
     640        1929 :                         switch (lp->flags & LPROPS_CAT_MASK) {
     641             :                         case LPROPS_UNCAT:
     642             :                                 s = "not categorized";
     643             :                                 break;
     644             :                         case LPROPS_DIRTY:
     645             :                                 s = "dirty";
     646             :                                 break;
     647             :                         case LPROPS_FREE:
     648             :                                 s = "free";
     649             :                                 break;
     650             :                         case LPROPS_EMPTY:
     651             :                                 s = "empty";
     652             :                                 break;
     653             :                         case LPROPS_FREEABLE:
     654             :                                 s = "freeable";
     655             :                                 break;
     656             :                         default:
     657             :                                 s = NULL;
     658             :                                 break;
     659             :                         }
     660             :                 }
     661        2029 :                 pr_cont("%s", s);
     662             :         }
     663             : 
     664        2032 :         for (rb = rb_first((struct rb_root *)&c->buds); rb; rb = rb_next(rb)) {
     665           0 :                 bud = rb_entry(rb, struct ubifs_bud, rb);
     666           0 :                 if (bud->lnum == lp->lnum) {
     667             :                         int head = 0;
     668           0 :                         for (i = 0; i < c->jhead_cnt; i++) {
     669             :                                 /*
     670             :                                  * Note, if we are in R/O mode or in the middle
     671             :                                  * of mounting/re-mounting, the write-buffers do
     672             :                                  * not exist.
     673             :                                  */
     674           0 :                                 if (c->jheads &&
     675           0 :                                     lp->lnum == c->jheads[i].wbuf.lnum) {
     676           0 :                                         pr_cont(", jhead %s", dbg_jhead(i));
     677             :                                         head = 1;
     678             :                                 }
     679             :                         }
     680           0 :                         if (!head)
     681           0 :                                 pr_cont(", bud of jhead %s",
     682             :                                        dbg_jhead(bud->jhead));
     683             :                 }
     684             :         }
     685        2032 :         if (lp->lnum == c->gc_lnum)
     686           0 :                 pr_cont(", GC LEB");
     687        2032 :         pr_cont(")\n");
     688        2032 : }
     689             : 
     690           1 : void ubifs_dump_lprops(struct ubifs_info *c)
     691             : {
     692             :         int lnum, err;
     693             :         struct ubifs_lprops lp;
     694             :         struct ubifs_lp_stats lst;
     695             : 
     696           1 :         pr_err("(pid %d) start dumping LEB properties\n", getpid());
     697           1 :         ubifs_get_lp_stats(c, &lst);
     698           1 :         ubifs_dump_lstats(&lst);
     699             : 
     700        2033 :         for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) {
     701        2032 :                 err = ubifs_read_one_lp(c, lnum, &lp);
     702        2032 :                 if (err) {
     703           0 :                         ubifs_err(c, "cannot read lprops for LEB %d", lnum);
     704           0 :                         continue;
     705             :                 }
     706             : 
     707        2032 :                 ubifs_dump_lprop(c, &lp);
     708             :         }
     709           1 :         pr_err("(pid %d) finish dumping LEB properties\n", getpid());
     710           1 : }
     711             : 
     712           0 : void ubifs_dump_lpt_info(struct ubifs_info *c)
     713             : {
     714             :         int i;
     715             : 
     716           0 :         spin_lock(&dbg_lock);
     717           0 :         pr_err("(pid %d) dumping LPT information\n", getpid());
     718           0 :         pr_err("\tlpt_sz:        %lld\n", c->lpt_sz);
     719           0 :         pr_err("\tpnode_sz:      %d\n", c->pnode_sz);
     720           0 :         pr_err("\tnnode_sz:      %d\n", c->nnode_sz);
     721           0 :         pr_err("\tltab_sz:       %d\n", c->ltab_sz);
     722           0 :         pr_err("\tlsave_sz:      %d\n", c->lsave_sz);
     723           0 :         pr_err("\tbig_lpt:       %u\n", c->big_lpt);
     724           0 :         pr_err("\tlpt_hght:      %d\n", c->lpt_hght);
     725           0 :         pr_err("\tpnode_cnt:     %d\n", c->pnode_cnt);
     726           0 :         pr_err("\tnnode_cnt:     %d\n", c->nnode_cnt);
     727           0 :         pr_err("\tdirty_pn_cnt:  %d\n", c->dirty_pn_cnt);
     728           0 :         pr_err("\tdirty_nn_cnt:  %d\n", c->dirty_nn_cnt);
     729           0 :         pr_err("\tlsave_cnt:     %d\n", c->lsave_cnt);
     730           0 :         pr_err("\tspace_bits:    %d\n", c->space_bits);
     731           0 :         pr_err("\tlpt_lnum_bits: %d\n", c->lpt_lnum_bits);
     732           0 :         pr_err("\tlpt_offs_bits: %d\n", c->lpt_offs_bits);
     733           0 :         pr_err("\tlpt_spc_bits:  %d\n", c->lpt_spc_bits);
     734           0 :         pr_err("\tpcnt_bits:     %d\n", c->pcnt_bits);
     735           0 :         pr_err("\tlnum_bits:     %d\n", c->lnum_bits);
     736           0 :         pr_err("\tLPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs);
     737           0 :         pr_err("\tLPT head is at %d:%d\n",
     738             :                c->nhead_lnum, c->nhead_offs);
     739           0 :         pr_err("\tLPT ltab is at %d:%d\n", c->ltab_lnum, c->ltab_offs);
     740           0 :         if (c->big_lpt)
     741           0 :                 pr_err("\tLPT lsave is at %d:%d\n",
     742             :                        c->lsave_lnum, c->lsave_offs);
     743           0 :         for (i = 0; i < c->lpt_lebs; i++)
     744           0 :                 pr_err("\tLPT LEB %d free %d dirty %d tgc %d cmt %d\n",
     745             :                        i + c->lpt_first, c->ltab[i].free, c->ltab[i].dirty,
     746             :                        c->ltab[i].tgc, c->ltab[i].cmt);
     747           0 :         spin_unlock(&dbg_lock);
     748           0 : }
     749             : 
     750           0 : void ubifs_dump_leb(const struct ubifs_info *c, int lnum)
     751             : {
     752             :         struct ubifs_scan_leb *sleb;
     753             :         struct ubifs_scan_node *snod;
     754             :         void *buf;
     755             : 
     756           0 :         pr_err("(pid %d) start dumping LEB %d\n", getpid(), lnum);
     757             : 
     758           0 :         buf = __vmalloc(c->leb_size, GFP_NOFS);
     759           0 :         if (!buf) {
     760           0 :                 ubifs_err(c, "cannot allocate memory for dumping LEB %d", lnum);
     761             :                 return;
     762             :         }
     763             : 
     764           0 :         sleb = ubifs_scan(c, lnum, 0, buf, 0);
     765           0 :         if (IS_ERR(sleb)) {
     766           0 :                 ubifs_err(c, "scan error %d", (int)PTR_ERR(sleb));
     767             :                 goto out;
     768             :         }
     769             : 
     770           0 :         pr_err("LEB %d has %d nodes ending at %d\n", lnum,
     771             :                sleb->nodes_cnt, sleb->endpt);
     772             : 
     773           0 :         list_for_each_entry(snod, &sleb->nodes, list) {
     774             :                 cond_resched();
     775           0 :                 pr_err("Dumping node at LEB %d:%d len %d\n", lnum,
     776             :                        snod->offs, snod->len);
     777           0 :                 ubifs_dump_node(c, snod->node, c->leb_size - snod->offs);
     778             :         }
     779             : 
     780           0 :         pr_err("(pid %d) finish dumping LEB %d\n", getpid(), lnum);
     781           0 :         ubifs_scan_destroy(sleb);
     782             : 
     783           0 : out:
     784           0 :         vfree(buf);
     785           0 :         return;
     786             : }
     787             : 
     788         244 : void ubifs_dump_znode(const struct ubifs_info *c,
     789             :                       const struct ubifs_znode *znode)
     790             : {
     791             :         int n;
     792             :         const struct ubifs_zbranch *zbr;
     793             :         char key_buf[DBG_KEY_BUF_LEN];
     794             : 
     795         244 :         spin_lock(&dbg_lock);
     796         244 :         if (znode->parent)
     797         244 :                 zbr = &znode->parent->zbranch[znode->iip];
     798             :         else
     799           0 :                 zbr = &c->zroot;
     800             : 
     801         244 :         pr_err("znode %p, LEB %d:%d len %d parent %p iip %d level %d child_cnt %d flags %lx\n",
     802             :                znode, zbr->lnum, zbr->offs, zbr->len, znode->parent, znode->iip,
     803             :                znode->level, znode->child_cnt, znode->flags);
     804             : 
     805         244 :         if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) {
     806           0 :                 spin_unlock(&dbg_lock);
     807           0 :                 return;
     808             :         }
     809             : 
     810         244 :         pr_err("zbranches:\n");
     811        1078 :         for (n = 0; n < znode->child_cnt; n++) {
     812        1078 :                 zbr = &znode->zbranch[n];
     813        1078 :                 if (znode->level > 0)
     814          20 :                         pr_err("\t%d: znode %p LEB %d:%d len %d key %s\n",
     815             :                                n, zbr->znode, zbr->lnum, zbr->offs, zbr->len,
     816             :                                dbg_snprintf_key(c, &zbr->key, key_buf,
     817             :                                                 DBG_KEY_BUF_LEN));
     818             :                 else
     819        1058 :                         pr_err("\t%d: LNC %p LEB %d:%d len %d key %s\n",
     820             :                                n, zbr->znode, zbr->lnum, zbr->offs, zbr->len,
     821             :                                dbg_snprintf_key(c, &zbr->key, key_buf,
     822             :                                                 DBG_KEY_BUF_LEN));
     823             :         }
     824         244 :         spin_unlock(&dbg_lock);
     825             : }
     826             : 
     827           0 : void ubifs_dump_heap(__unused struct ubifs_info *c, struct ubifs_lpt_heap *heap,
     828             :                      int cat)
     829             : {
     830             :         int i;
     831             : 
     832           0 :         pr_err("(pid %d) start dumping heap cat %d (%d elements)\n",
     833             :                getpid(), cat, heap->cnt);
     834           0 :         for (i = 0; i < heap->cnt; i++) {
     835           0 :                 struct ubifs_lprops *lprops = heap->arr[i];
     836             : 
     837           0 :                 pr_err("\t%d. LEB %d hpos %d free %d dirty %d flags %d\n",
     838             :                        i, lprops->lnum, lprops->hpos, lprops->free,
     839             :                        lprops->dirty, lprops->flags);
     840             :         }
     841           0 :         pr_err("(pid %d) finish dumping heap\n", getpid());
     842           0 : }
     843             : 
     844          18 : void ubifs_dump_pnode(__unused struct ubifs_info *c, struct ubifs_pnode *pnode,
     845             :                       struct ubifs_nnode *parent, int iip)
     846             : {
     847             :         int i;
     848             : 
     849          18 :         pr_err("(pid %d) dumping pnode:\n", getpid());
     850          18 :         pr_err("\taddress %zx parent %zx cnext %zx\n",
     851             :                (size_t)pnode, (size_t)parent, (size_t)pnode->cnext);
     852          18 :         pr_err("\tflags %lu iip %d level %d num %d\n",
     853             :                pnode->flags, iip, pnode->level, pnode->num);
     854          72 :         for (i = 0; i < UBIFS_LPT_FANOUT; i++) {
     855          72 :                 struct ubifs_lprops *lp = &pnode->lprops[i];
     856             : 
     857          72 :                 pr_err("\t%d: free %d dirty %d flags %d lnum %d\n",
     858             :                        i, lp->free, lp->dirty, lp->flags, lp->lnum);
     859             :         }
     860          18 : }
     861             : 
     862             : /**
     863             :  * dbg_walk_index - walk the on-flash index.
     864             :  * @c: UBIFS file-system description object
     865             :  * @leaf_cb: called for each leaf node
     866             :  * @znode_cb: called for each indexing node
     867             :  * @priv: private data which is passed to callbacks
     868             :  *
     869             :  * This function walks the UBIFS index and calls the @leaf_cb for each leaf
     870             :  * node and @znode_cb for each indexing node. Returns zero in case of success
     871             :  * and a negative error code in case of failure.
     872             :  *
     873             :  * It would be better if this function removed every znode it pulled to into
     874             :  * the TNC, so that the behavior more closely matched the non-debugging
     875             :  * behavior.
     876             :  */
     877        3693 : int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
     878             :                    dbg_znode_callback znode_cb, void *priv)
     879             : {
     880             :         int err;
     881             :         struct ubifs_zbranch *zbr;
     882             :         struct ubifs_znode *znode, *child;
     883             : 
     884        3693 :         mutex_lock(&c->tnc_mutex);
     885             :         /* If the root indexing node is not in TNC - pull it */
     886        3693 :         if (!c->zroot.znode) {
     887        1688 :                 c->zroot.znode = ubifs_load_znode(c, &c->zroot, NULL, 0);
     888        3376 :                 if (IS_ERR(c->zroot.znode)) {
     889          74 :                         err = PTR_ERR(c->zroot.znode);
     890          37 :                         c->zroot.znode = NULL;
     891          37 :                         goto out_unlock;
     892             :                 }
     893             :         }
     894             : 
     895             :         /*
     896             :          * We are going to traverse the indexing tree in the postorder manner.
     897             :          * Go down and find the leftmost indexing node where we are going to
     898             :          * start from.
     899             :          */
     900        3656 :         znode = c->zroot.znode;
     901       28308 :         while (znode->level > 0) {
     902       20999 :                 zbr = &znode->zbranch[0];
     903       20999 :                 child = zbr->znode;
     904       20999 :                 if (!child) {
     905       11215 :                         child = ubifs_load_znode(c, zbr, znode, 0);
     906       11215 :                         if (IS_ERR(child)) {
     907           3 :                                 err = PTR_ERR(child);
     908           3 :                                 goto out_unlock;
     909             :                         }
     910             :                 }
     911             : 
     912             :                 znode = child;
     913             :         }
     914             : 
     915             :         /* Iterate over all indexing nodes */
     916             :         while (1) {
     917             :                 int idx;
     918             : 
     919             :                 cond_resched();
     920             : 
     921  1132467422 :                 if (znode_cb) {
     922  1132467422 :                         err = znode_cb(c, znode, priv);
     923  1132467422 :                         if (err) {
     924         122 :                                 ubifs_err(c, "znode checking function returned error %d",
     925             :                                           err);
     926         122 :                                 ubifs_dump_znode(c, znode);
     927         122 :                                 goto out_dump;
     928             :                         }
     929             :                 }
     930  1132467300 :                 if (leaf_cb && znode->level == 0) {
     931  2491571090 :                         for (idx = 0; idx < znode->child_cnt; idx++) {
     932  2491571234 :                                 zbr = &znode->zbranch[idx];
     933  2491571234 :                                 err = leaf_cb(c, zbr, priv);
     934  2491571090 :                                 if (err) {
     935           0 :                                         ubifs_err(c, "leaf checking function returned error %d, for leaf at LEB %d:%d",
     936             :                                                   err, zbr->lnum, zbr->offs);
     937             :                                         goto out_dump;
     938             :                                 }
     939             :                         }
     940             :                 }
     941             : 
     942  1132467156 :                 if (!znode->parent)
     943             :                         break;
     944             : 
     945  1132464081 :                 idx = znode->iip + 1;
     946  1132464081 :                 znode = znode->parent;
     947  1132464081 :                 if (idx < znode->child_cnt) {
     948             :                         /* Switch to the next index in the parent */
     949   909277044 :                         zbr = &znode->zbranch[idx];
     950   909277044 :                         child = zbr->znode;
     951   909277044 :                         if (!child) {
     952   453925106 :                                 child = ubifs_load_znode(c, zbr, znode, idx);
     953   453925106 :                                 if (IS_ERR(child)) {
     954         227 :                                         err = PTR_ERR(child);
     955         227 :                                         goto out_unlock;
     956             :                                 }
     957   453924879 :                                 zbr->znode = child;
     958             :                         }
     959             :                         znode = child;
     960             :                 } else
     961             :                         /*
     962             :                          * This is the last child, switch to the parent and
     963             :                          * continue.
     964             :                          */
     965   223187037 :                         continue;
     966             : 
     967             :                 /* Go to the lowest leftmost znode in the new sub-tree */
     968  1132446039 :                 while (znode->level > 0) {
     969   223169307 :                         zbr = &znode->zbranch[0];
     970   223169307 :                         child = zbr->znode;
     971   223169307 :                         if (!child) {
     972   111349485 :                                 child = ubifs_load_znode(c, zbr, znode, 0);
     973   111349485 :                                 if (IS_ERR(child)) {
     974          85 :                                         err = PTR_ERR(child);
     975          85 :                                         goto out_unlock;
     976             :                                 }
     977   111349400 :                                 zbr->znode = child;
     978             :                         }
     979             :                         znode = child;
     980             :                 }
     981             :         }
     982             : 
     983        3075 :         mutex_unlock(&c->tnc_mutex);
     984        3075 :         return 0;
     985             : 
     986         122 : out_dump:
     987         122 :         if (znode->parent)
     988         122 :                 zbr = &znode->parent->zbranch[znode->iip];
     989             :         else
     990           0 :                 zbr = &c->zroot;
     991         122 :         ubifs_msg(c, "dump of znode at LEB %d:%d", zbr->lnum, zbr->offs);
     992         122 :         ubifs_dump_znode(c, znode);
     993         474 : out_unlock:
     994         474 :         mutex_unlock(&c->tnc_mutex);
     995         474 :         return err;
     996             : }
     997             : 
     998             : /**
     999             :  * add_size - add znode size to partially calculated index size.
    1000             :  * @c: UBIFS file-system description object
    1001             :  * @znode: znode to add size for
    1002             :  * @priv: partially calculated index size
    1003             :  *
    1004             :  * This is a helper function for 'dbg_check_idx_size()' which is called for
    1005             :  * every indexing node and adds its size to the 'long long' variable pointed to
    1006             :  * by @priv.
    1007             :  */
    1008   564947880 : int add_size(struct ubifs_info *c, struct ubifs_znode *znode, void *priv)
    1009             : {
    1010   564947880 :         long long *idx_size = priv;
    1011             :         int add;
    1012             : 
    1013  1129895760 :         add = ubifs_idx_node_sz(c, znode->child_cnt);
    1014   564947880 :         add = ALIGN(add, 8);
    1015   564947880 :         *idx_size += add;
    1016   564947880 :         return 0;
    1017             : }
    1018             : 
    1019           0 : void ubifs_assert_failed(struct ubifs_info *c, const char *expr,
    1020             :                          const char *file, int line)
    1021             : {
    1022           0 :         ubifs_err(c, "UBIFS assert failed: %s, in %s:%u", expr, file, line);
    1023             : 
    1024             :         /*
    1025             :          * Different from linux kernel.
    1026             :          * Invoke callback function if there is one, otherwise make filesystem
    1027             :          * readonly when assertion is failed.
    1028             :          */
    1029           0 :         if (c->assert_failed_cb)
    1030           0 :                 c->assert_failed_cb(c);
    1031             :         else
    1032           0 :                 ubifs_ro_mode(c, -EINVAL);
    1033           0 : }

Generated by: LCOV version 1.13