2 * This file is part of UBIFS.
4 * Copyright (C) 2006-2008 Nokia Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Adrian Hunter
20 * Artem Bityutskiy (Битюцкий Артём)
24 * This file implements the LEB properties tree (LPT) area. The LPT area
25 * contains the LEB properties tree, a table of LPT area eraseblocks (ltab), and
26 * (for the "big" model) a table of saved LEB numbers (lsave). The LPT area sits
27 * between the log and the orphan area.
29 * The LPT area is like a miniature self-contained file system. It is required
30 * that it never runs out of space, is fast to access and update, and scales
31 * logarithmically. The LEB properties tree is implemented as a wandering tree
32 * much like the TNC, and the LPT area has its own garbage collection.
34 * The LPT has two slightly different forms called the "small model" and the
35 * "big model". The small model is used when the entire LEB properties table
36 * can be written into a single eraseblock. In that case, garbage collection
37 * consists of just writing the whole table, which therefore makes all other
38 * eraseblocks reusable. In the case of the big model, dirty eraseblocks are
39 * selected for garbage collection, which consists of marking the clean nodes in
40 * that LEB as dirty, and then only the dirty nodes are written out. Also, in
41 * the case of the big model, a table of LEB numbers is saved so that the entire
42 * LPT does not to be scanned looking for empty eraseblocks when UBIFS is first
47 #include <linux/crc16.h>
48 #include <linux/math64.h>
51 * do_calc_lpt_geom - calculate sizes for the LPT area.
52 * @c: the UBIFS file-system description object
54 * Calculate the sizes of LPT bit fields, nodes, and tree, based on the
55 * properties of the flash and whether LPT is "big" (c->big_lpt).
57 static void do_calc_lpt_geom(struct ubifs_info
*c
)
59 int i
, n
, bits
, per_leb_wastage
, max_pnode_cnt
;
60 long long sz
, tot_wastage
;
62 n
= c
->main_lebs
+ c
->max_leb_cnt
- c
->leb_cnt
;
63 max_pnode_cnt
= DIV_ROUND_UP(n
, UBIFS_LPT_FANOUT
);
67 while (n
< max_pnode_cnt
) {
69 n
<<= UBIFS_LPT_FANOUT_SHIFT
;
72 c
->pnode_cnt
= DIV_ROUND_UP(c
->main_lebs
, UBIFS_LPT_FANOUT
);
74 n
= DIV_ROUND_UP(c
->pnode_cnt
, UBIFS_LPT_FANOUT
);
76 for (i
= 1; i
< c
->lpt_hght
; i
++) {
77 n
= DIV_ROUND_UP(n
, UBIFS_LPT_FANOUT
);
81 c
->space_bits
= fls(c
->leb_size
) - 3;
82 c
->lpt_lnum_bits
= fls(c
->lpt_lebs
);
83 c
->lpt_offs_bits
= fls(c
->leb_size
- 1);
84 c
->lpt_spc_bits
= fls(c
->leb_size
);
86 n
= DIV_ROUND_UP(c
->max_leb_cnt
, UBIFS_LPT_FANOUT
);
87 c
->pcnt_bits
= fls(n
- 1);
89 c
->lnum_bits
= fls(c
->max_leb_cnt
- 1);
91 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
92 (c
->big_lpt
? c
->pcnt_bits
: 0) +
93 (c
->space_bits
* 2 + 1) * UBIFS_LPT_FANOUT
;
94 c
->pnode_sz
= (bits
+ 7) / 8;
96 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
97 (c
->big_lpt
? c
->pcnt_bits
: 0) +
98 (c
->lpt_lnum_bits
+ c
->lpt_offs_bits
) * UBIFS_LPT_FANOUT
;
99 c
->nnode_sz
= (bits
+ 7) / 8;
101 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
102 c
->lpt_lebs
* c
->lpt_spc_bits
* 2;
103 c
->ltab_sz
= (bits
+ 7) / 8;
105 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
106 c
->lnum_bits
* c
->lsave_cnt
;
107 c
->lsave_sz
= (bits
+ 7) / 8;
109 /* Calculate the minimum LPT size */
110 c
->lpt_sz
= (long long)c
->pnode_cnt
* c
->pnode_sz
;
111 c
->lpt_sz
+= (long long)c
->nnode_cnt
* c
->nnode_sz
;
112 c
->lpt_sz
+= c
->ltab_sz
;
114 c
->lpt_sz
+= c
->lsave_sz
;
118 per_leb_wastage
= max_t(int, c
->pnode_sz
, c
->nnode_sz
);
119 sz
+= per_leb_wastage
;
120 tot_wastage
= per_leb_wastage
;
121 while (sz
> c
->leb_size
) {
122 sz
+= per_leb_wastage
;
124 tot_wastage
+= per_leb_wastage
;
126 tot_wastage
+= ALIGN(sz
, c
->min_io_size
) - sz
;
127 c
->lpt_sz
+= tot_wastage
;
131 * ubifs_calc_lpt_geom - calculate and check sizes for the LPT area.
132 * @c: the UBIFS file-system description object
134 * This function returns %0 on success and a negative error code on failure.
136 int ubifs_calc_lpt_geom(struct ubifs_info
*c
)
143 /* Verify that lpt_lebs is big enough */
144 sz
= c
->lpt_sz
* 2; /* Must have at least 2 times the size */
145 lebs_needed
= div_u64(sz
+ c
->leb_size
- 1, c
->leb_size
);
146 if (lebs_needed
> c
->lpt_lebs
) {
147 ubifs_err("too few LPT LEBs");
151 /* Verify that ltab fits in a single LEB (since ltab is a single node */
152 if (c
->ltab_sz
> c
->leb_size
) {
153 ubifs_err("LPT ltab too big");
157 c
->check_lpt_free
= c
->big_lpt
;
162 * calc_dflt_lpt_geom - calculate default LPT geometry.
163 * @c: the UBIFS file-system description object
164 * @main_lebs: number of main area LEBs is passed and returned here
165 * @big_lpt: whether the LPT area is "big" is returned here
167 * The size of the LPT area depends on parameters that themselves are dependent
168 * on the size of the LPT area. This function, successively recalculates the LPT
169 * area geometry until the parameters and resultant geometry are consistent.
171 * This function returns %0 on success and a negative error code on failure.
173 static int calc_dflt_lpt_geom(struct ubifs_info
*c
, int *main_lebs
,
179 /* Start by assuming the minimum number of LPT LEBs */
180 c
->lpt_lebs
= UBIFS_MIN_LPT_LEBS
;
181 c
->main_lebs
= *main_lebs
- c
->lpt_lebs
;
182 if (c
->main_lebs
<= 0)
185 /* And assume we will use the small LPT model */
189 * Calculate the geometry based on assumptions above and then see if it
194 /* Small LPT model must have lpt_sz < leb_size */
195 if (c
->lpt_sz
> c
->leb_size
) {
196 /* Nope, so try again using big LPT model */
201 /* Now check there are enough LPT LEBs */
202 for (i
= 0; i
< 64 ; i
++) {
203 sz
= c
->lpt_sz
* 4; /* Allow 4 times the size */
204 lebs_needed
= div_u64(sz
+ c
->leb_size
- 1, c
->leb_size
);
205 if (lebs_needed
> c
->lpt_lebs
) {
206 /* Not enough LPT LEBs so try again with more */
207 c
->lpt_lebs
= lebs_needed
;
208 c
->main_lebs
= *main_lebs
- c
->lpt_lebs
;
209 if (c
->main_lebs
<= 0)
214 if (c
->ltab_sz
> c
->leb_size
) {
215 ubifs_err("LPT ltab too big");
218 *main_lebs
= c
->main_lebs
;
219 *big_lpt
= c
->big_lpt
;
226 * pack_bits - pack bit fields end-to-end.
227 * @addr: address at which to pack (passed and next address returned)
228 * @pos: bit position at which to pack (passed and next position returned)
229 * @val: value to pack
230 * @nrbits: number of bits of value to pack (1-32)
232 static void pack_bits(uint8_t **addr
, int *pos
, uint32_t val
, int nrbits
)
237 ubifs_assert(nrbits
> 0);
238 ubifs_assert(nrbits
<= 32);
239 ubifs_assert(*pos
>= 0);
240 ubifs_assert(*pos
< 8);
241 ubifs_assert((val
>> nrbits
) == 0 || nrbits
== 32);
243 *p
|= ((uint8_t)val
) << b
;
246 *++p
= (uint8_t)(val
>>= (8 - b
));
248 *++p
= (uint8_t)(val
>>= 8);
250 *++p
= (uint8_t)(val
>>= 8);
252 *++p
= (uint8_t)(val
>>= 8);
259 *++p
= (uint8_t)(val
>>= 8);
261 *++p
= (uint8_t)(val
>>= 8);
263 *++p
= (uint8_t)(val
>>= 8);
275 * ubifs_unpack_bits - unpack bit fields.
276 * @addr: address at which to unpack (passed and next address returned)
277 * @pos: bit position at which to unpack (passed and next position returned)
278 * @nrbits: number of bits of value to unpack (1-32)
280 * This functions returns the value unpacked.
282 uint32_t ubifs_unpack_bits(uint8_t **addr
, int *pos
, int nrbits
)
284 const int k
= 32 - nrbits
;
287 uint32_t uninitialized_var(val
);
288 const int bytes
= (nrbits
+ b
+ 7) >> 3;
290 ubifs_assert(nrbits
> 0);
291 ubifs_assert(nrbits
<= 32);
292 ubifs_assert(*pos
>= 0);
293 ubifs_assert(*pos
< 8);
300 val
= p
[1] | ((uint32_t)p
[2] << 8);
303 val
= p
[1] | ((uint32_t)p
[2] << 8) |
304 ((uint32_t)p
[3] << 16);
307 val
= p
[1] | ((uint32_t)p
[2] << 8) |
308 ((uint32_t)p
[3] << 16) |
309 ((uint32_t)p
[4] << 24);
320 val
= p
[0] | ((uint32_t)p
[1] << 8);
323 val
= p
[0] | ((uint32_t)p
[1] << 8) |
324 ((uint32_t)p
[2] << 16);
327 val
= p
[0] | ((uint32_t)p
[1] << 8) |
328 ((uint32_t)p
[2] << 16) |
329 ((uint32_t)p
[3] << 24);
339 ubifs_assert((val
>> nrbits
) == 0 || nrbits
- b
== 32);
344 * ubifs_pack_pnode - pack all the bit fields of a pnode.
345 * @c: UBIFS file-system description object
346 * @buf: buffer into which to pack
347 * @pnode: pnode to pack
349 void ubifs_pack_pnode(struct ubifs_info
*c
, void *buf
,
350 struct ubifs_pnode
*pnode
)
352 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
356 pack_bits(&addr
, &pos
, UBIFS_LPT_PNODE
, UBIFS_LPT_TYPE_BITS
);
358 pack_bits(&addr
, &pos
, pnode
->num
, c
->pcnt_bits
);
359 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
360 pack_bits(&addr
, &pos
, pnode
->lprops
[i
].free
>> 3,
362 pack_bits(&addr
, &pos
, pnode
->lprops
[i
].dirty
>> 3,
364 if (pnode
->lprops
[i
].flags
& LPROPS_INDEX
)
365 pack_bits(&addr
, &pos
, 1, 1);
367 pack_bits(&addr
, &pos
, 0, 1);
369 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
370 c
->pnode_sz
- UBIFS_LPT_CRC_BYTES
);
373 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
377 * ubifs_pack_nnode - pack all the bit fields of a nnode.
378 * @c: UBIFS file-system description object
379 * @buf: buffer into which to pack
380 * @nnode: nnode to pack
382 void ubifs_pack_nnode(struct ubifs_info
*c
, void *buf
,
383 struct ubifs_nnode
*nnode
)
385 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
389 pack_bits(&addr
, &pos
, UBIFS_LPT_NNODE
, UBIFS_LPT_TYPE_BITS
);
391 pack_bits(&addr
, &pos
, nnode
->num
, c
->pcnt_bits
);
392 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
393 int lnum
= nnode
->nbranch
[i
].lnum
;
396 lnum
= c
->lpt_last
+ 1;
397 pack_bits(&addr
, &pos
, lnum
- c
->lpt_first
, c
->lpt_lnum_bits
);
398 pack_bits(&addr
, &pos
, nnode
->nbranch
[i
].offs
,
401 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
402 c
->nnode_sz
- UBIFS_LPT_CRC_BYTES
);
405 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
409 * ubifs_pack_ltab - pack the LPT's own lprops table.
410 * @c: UBIFS file-system description object
411 * @buf: buffer into which to pack
412 * @ltab: LPT's own lprops table to pack
414 void ubifs_pack_ltab(struct ubifs_info
*c
, void *buf
,
415 struct ubifs_lpt_lprops
*ltab
)
417 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
421 pack_bits(&addr
, &pos
, UBIFS_LPT_LTAB
, UBIFS_LPT_TYPE_BITS
);
422 for (i
= 0; i
< c
->lpt_lebs
; i
++) {
423 pack_bits(&addr
, &pos
, ltab
[i
].free
, c
->lpt_spc_bits
);
424 pack_bits(&addr
, &pos
, ltab
[i
].dirty
, c
->lpt_spc_bits
);
426 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
427 c
->ltab_sz
- UBIFS_LPT_CRC_BYTES
);
430 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
434 * ubifs_pack_lsave - pack the LPT's save table.
435 * @c: UBIFS file-system description object
436 * @buf: buffer into which to pack
437 * @lsave: LPT's save table to pack
439 void ubifs_pack_lsave(struct ubifs_info
*c
, void *buf
, int *lsave
)
441 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
445 pack_bits(&addr
, &pos
, UBIFS_LPT_LSAVE
, UBIFS_LPT_TYPE_BITS
);
446 for (i
= 0; i
< c
->lsave_cnt
; i
++)
447 pack_bits(&addr
, &pos
, lsave
[i
], c
->lnum_bits
);
448 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
449 c
->lsave_sz
- UBIFS_LPT_CRC_BYTES
);
452 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
456 * ubifs_add_lpt_dirt - add dirty space to LPT LEB properties.
457 * @c: UBIFS file-system description object
458 * @lnum: LEB number to which to add dirty space
459 * @dirty: amount of dirty space to add
461 void ubifs_add_lpt_dirt(struct ubifs_info
*c
, int lnum
, int dirty
)
465 dbg_lp("LEB %d add %d to %d",
466 lnum
, dirty
, c
->ltab
[lnum
- c
->lpt_first
].dirty
);
467 ubifs_assert(lnum
>= c
->lpt_first
&& lnum
<= c
->lpt_last
);
468 c
->ltab
[lnum
- c
->lpt_first
].dirty
+= dirty
;
472 * set_ltab - set LPT LEB properties.
473 * @c: UBIFS file-system description object
475 * @free: amount of free space
476 * @dirty: amount of dirty space
478 static void set_ltab(struct ubifs_info
*c
, int lnum
, int free
, int dirty
)
480 dbg_lp("LEB %d free %d dirty %d to %d %d",
481 lnum
, c
->ltab
[lnum
- c
->lpt_first
].free
,
482 c
->ltab
[lnum
- c
->lpt_first
].dirty
, free
, dirty
);
483 ubifs_assert(lnum
>= c
->lpt_first
&& lnum
<= c
->lpt_last
);
484 c
->ltab
[lnum
- c
->lpt_first
].free
= free
;
485 c
->ltab
[lnum
- c
->lpt_first
].dirty
= dirty
;
489 * ubifs_add_nnode_dirt - add dirty space to LPT LEB properties.
490 * @c: UBIFS file-system description object
491 * @nnode: nnode for which to add dirt
493 void ubifs_add_nnode_dirt(struct ubifs_info
*c
, struct ubifs_nnode
*nnode
)
495 struct ubifs_nnode
*np
= nnode
->parent
;
498 ubifs_add_lpt_dirt(c
, np
->nbranch
[nnode
->iip
].lnum
,
501 ubifs_add_lpt_dirt(c
, c
->lpt_lnum
, c
->nnode_sz
);
502 if (!(c
->lpt_drty_flgs
& LTAB_DIRTY
)) {
503 c
->lpt_drty_flgs
|= LTAB_DIRTY
;
504 ubifs_add_lpt_dirt(c
, c
->ltab_lnum
, c
->ltab_sz
);
510 * add_pnode_dirt - add dirty space to LPT LEB properties.
511 * @c: UBIFS file-system description object
512 * @pnode: pnode for which to add dirt
514 static void add_pnode_dirt(struct ubifs_info
*c
, struct ubifs_pnode
*pnode
)
516 ubifs_add_lpt_dirt(c
, pnode
->parent
->nbranch
[pnode
->iip
].lnum
,
521 * calc_nnode_num - calculate nnode number.
522 * @row: the row in the tree (root is zero)
523 * @col: the column in the row (leftmost is zero)
525 * The nnode number is a number that uniquely identifies a nnode and can be used
526 * easily to traverse the tree from the root to that nnode.
528 * This function calculates and returns the nnode number for the nnode at @row
531 static int calc_nnode_num(int row
, int col
)
537 bits
= (col
& (UBIFS_LPT_FANOUT
- 1));
538 col
>>= UBIFS_LPT_FANOUT_SHIFT
;
539 num
<<= UBIFS_LPT_FANOUT_SHIFT
;
546 * calc_nnode_num_from_parent - calculate nnode number.
547 * @c: UBIFS file-system description object
548 * @parent: parent nnode
549 * @iip: index in parent
551 * The nnode number is a number that uniquely identifies a nnode and can be used
552 * easily to traverse the tree from the root to that nnode.
554 * This function calculates and returns the nnode number based on the parent's
555 * nnode number and the index in parent.
557 static int calc_nnode_num_from_parent(const struct ubifs_info
*c
,
558 struct ubifs_nnode
*parent
, int iip
)
564 shft
= (c
->lpt_hght
- parent
->level
) * UBIFS_LPT_FANOUT_SHIFT
;
565 num
= parent
->num
^ (1 << shft
);
566 num
|= (UBIFS_LPT_FANOUT
+ iip
) << shft
;
571 * calc_pnode_num_from_parent - calculate pnode number.
572 * @c: UBIFS file-system description object
573 * @parent: parent nnode
574 * @iip: index in parent
576 * The pnode number is a number that uniquely identifies a pnode and can be used
577 * easily to traverse the tree from the root to that pnode.
579 * This function calculates and returns the pnode number based on the parent's
580 * nnode number and the index in parent.
582 static int calc_pnode_num_from_parent(const struct ubifs_info
*c
,
583 struct ubifs_nnode
*parent
, int iip
)
585 int i
, n
= c
->lpt_hght
- 1, pnum
= parent
->num
, num
= 0;
587 for (i
= 0; i
< n
; i
++) {
588 num
<<= UBIFS_LPT_FANOUT_SHIFT
;
589 num
|= pnum
& (UBIFS_LPT_FANOUT
- 1);
590 pnum
>>= UBIFS_LPT_FANOUT_SHIFT
;
592 num
<<= UBIFS_LPT_FANOUT_SHIFT
;
598 * ubifs_create_dflt_lpt - create default LPT.
599 * @c: UBIFS file-system description object
600 * @main_lebs: number of main area LEBs is passed and returned here
601 * @lpt_first: LEB number of first LPT LEB
602 * @lpt_lebs: number of LEBs for LPT is passed and returned here
603 * @big_lpt: use big LPT model is passed and returned here
605 * This function returns %0 on success and a negative error code on failure.
607 int ubifs_create_dflt_lpt(struct ubifs_info
*c
, int *main_lebs
, int lpt_first
,
608 int *lpt_lebs
, int *big_lpt
)
610 int lnum
, err
= 0, node_sz
, iopos
, i
, j
, cnt
, len
, alen
, row
;
611 int blnum
, boffs
, bsz
, bcnt
;
612 struct ubifs_pnode
*pnode
= NULL
;
613 struct ubifs_nnode
*nnode
= NULL
;
614 void *buf
= NULL
, *p
;
615 struct ubifs_lpt_lprops
*ltab
= NULL
;
618 err
= calc_dflt_lpt_geom(c
, main_lebs
, big_lpt
);
621 *lpt_lebs
= c
->lpt_lebs
;
623 /* Needed by 'ubifs_pack_nnode()' and 'set_ltab()' */
624 c
->lpt_first
= lpt_first
;
625 /* Needed by 'set_ltab()' */
626 c
->lpt_last
= lpt_first
+ c
->lpt_lebs
- 1;
627 /* Needed by 'ubifs_pack_lsave()' */
628 c
->main_first
= c
->leb_cnt
- *main_lebs
;
630 lsave
= kmalloc(sizeof(int) * c
->lsave_cnt
, GFP_KERNEL
);
631 pnode
= kzalloc(sizeof(struct ubifs_pnode
), GFP_KERNEL
);
632 nnode
= kzalloc(sizeof(struct ubifs_nnode
), GFP_KERNEL
);
633 buf
= vmalloc(c
->leb_size
);
634 ltab
= vmalloc(sizeof(struct ubifs_lpt_lprops
) * c
->lpt_lebs
);
635 if (!pnode
|| !nnode
|| !buf
|| !ltab
|| !lsave
) {
640 ubifs_assert(!c
->ltab
);
641 c
->ltab
= ltab
; /* Needed by set_ltab */
643 /* Initialize LPT's own lprops */
644 for (i
= 0; i
< c
->lpt_lebs
; i
++) {
645 ltab
[i
].free
= c
->leb_size
;
653 /* Number of leaf nodes (pnodes) */
657 * The first pnode contains the LEB properties for the LEBs that contain
658 * the root inode node and the root index node of the index tree.
660 node_sz
= ALIGN(ubifs_idx_node_sz(c
, 1), 8);
661 iopos
= ALIGN(node_sz
, c
->min_io_size
);
662 pnode
->lprops
[0].free
= c
->leb_size
- iopos
;
663 pnode
->lprops
[0].dirty
= iopos
- node_sz
;
664 pnode
->lprops
[0].flags
= LPROPS_INDEX
;
666 node_sz
= UBIFS_INO_NODE_SZ
;
667 iopos
= ALIGN(node_sz
, c
->min_io_size
);
668 pnode
->lprops
[1].free
= c
->leb_size
- iopos
;
669 pnode
->lprops
[1].dirty
= iopos
- node_sz
;
671 for (i
= 2; i
< UBIFS_LPT_FANOUT
; i
++)
672 pnode
->lprops
[i
].free
= c
->leb_size
;
674 /* Add first pnode */
675 ubifs_pack_pnode(c
, p
, pnode
);
680 /* Reset pnode values for remaining pnodes */
681 pnode
->lprops
[0].free
= c
->leb_size
;
682 pnode
->lprops
[0].dirty
= 0;
683 pnode
->lprops
[0].flags
= 0;
685 pnode
->lprops
[1].free
= c
->leb_size
;
686 pnode
->lprops
[1].dirty
= 0;
689 * To calculate the internal node branches, we keep information about
692 blnum
= lnum
; /* LEB number of level below */
693 boffs
= 0; /* Offset of level below */
694 bcnt
= cnt
; /* Number of nodes in level below */
695 bsz
= c
->pnode_sz
; /* Size of nodes in level below */
697 /* Add all remaining pnodes */
698 for (i
= 1; i
< cnt
; i
++) {
699 if (len
+ c
->pnode_sz
> c
->leb_size
) {
700 alen
= ALIGN(len
, c
->min_io_size
);
701 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
702 memset(p
, 0xff, alen
- len
);
703 err
= ubi_leb_change(c
->ubi
, lnum
++, buf
, alen
,
710 ubifs_pack_pnode(c
, p
, pnode
);
714 * pnodes are simply numbered left to right starting at zero,
715 * which means the pnode number can be used easily to traverse
716 * down the tree to the corresponding pnode.
722 for (i
= UBIFS_LPT_FANOUT
; cnt
> i
; i
<<= UBIFS_LPT_FANOUT_SHIFT
)
724 /* Add all nnodes, one level at a time */
726 /* Number of internal nodes (nnodes) at next level */
727 cnt
= DIV_ROUND_UP(cnt
, UBIFS_LPT_FANOUT
);
728 for (i
= 0; i
< cnt
; i
++) {
729 if (len
+ c
->nnode_sz
> c
->leb_size
) {
730 alen
= ALIGN(len
, c
->min_io_size
);
731 set_ltab(c
, lnum
, c
->leb_size
- alen
,
733 memset(p
, 0xff, alen
- len
);
734 err
= ubi_leb_change(c
->ubi
, lnum
++, buf
, alen
,
741 /* Only 1 nnode at this level, so it is the root */
746 /* Set branches to the level below */
747 for (j
= 0; j
< UBIFS_LPT_FANOUT
; j
++) {
749 if (boffs
+ bsz
> c
->leb_size
) {
753 nnode
->nbranch
[j
].lnum
= blnum
;
754 nnode
->nbranch
[j
].offs
= boffs
;
758 nnode
->nbranch
[j
].lnum
= 0;
759 nnode
->nbranch
[j
].offs
= 0;
762 nnode
->num
= calc_nnode_num(row
, i
);
763 ubifs_pack_nnode(c
, p
, nnode
);
767 /* Only 1 nnode at this level, so it is the root */
770 /* Update the information about the level below */
777 /* Need to add LPT's save table */
778 if (len
+ c
->lsave_sz
> c
->leb_size
) {
779 alen
= ALIGN(len
, c
->min_io_size
);
780 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
781 memset(p
, 0xff, alen
- len
);
782 err
= ubi_leb_change(c
->ubi
, lnum
++, buf
, alen
,
790 c
->lsave_lnum
= lnum
;
793 for (i
= 0; i
< c
->lsave_cnt
&& i
< *main_lebs
; i
++)
794 lsave
[i
] = c
->main_first
+ i
;
795 for (; i
< c
->lsave_cnt
; i
++)
796 lsave
[i
] = c
->main_first
;
798 ubifs_pack_lsave(c
, p
, lsave
);
803 /* Need to add LPT's own LEB properties table */
804 if (len
+ c
->ltab_sz
> c
->leb_size
) {
805 alen
= ALIGN(len
, c
->min_io_size
);
806 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
807 memset(p
, 0xff, alen
- len
);
808 err
= ubi_leb_change(c
->ubi
, lnum
++, buf
, alen
, UBI_SHORTTERM
);
818 /* Update ltab before packing it */
820 alen
= ALIGN(len
, c
->min_io_size
);
821 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
823 ubifs_pack_ltab(c
, p
, ltab
);
826 /* Write remaining buffer */
827 memset(p
, 0xff, alen
- len
);
828 err
= ubi_leb_change(c
->ubi
, lnum
, buf
, alen
, UBI_SHORTTERM
);
832 c
->nhead_lnum
= lnum
;
833 c
->nhead_offs
= ALIGN(len
, c
->min_io_size
);
835 dbg_lp("space_bits %d", c
->space_bits
);
836 dbg_lp("lpt_lnum_bits %d", c
->lpt_lnum_bits
);
837 dbg_lp("lpt_offs_bits %d", c
->lpt_offs_bits
);
838 dbg_lp("lpt_spc_bits %d", c
->lpt_spc_bits
);
839 dbg_lp("pcnt_bits %d", c
->pcnt_bits
);
840 dbg_lp("lnum_bits %d", c
->lnum_bits
);
841 dbg_lp("pnode_sz %d", c
->pnode_sz
);
842 dbg_lp("nnode_sz %d", c
->nnode_sz
);
843 dbg_lp("ltab_sz %d", c
->ltab_sz
);
844 dbg_lp("lsave_sz %d", c
->lsave_sz
);
845 dbg_lp("lsave_cnt %d", c
->lsave_cnt
);
846 dbg_lp("lpt_hght %d", c
->lpt_hght
);
847 dbg_lp("big_lpt %d", c
->big_lpt
);
848 dbg_lp("LPT root is at %d:%d", c
->lpt_lnum
, c
->lpt_offs
);
849 dbg_lp("LPT head is at %d:%d", c
->nhead_lnum
, c
->nhead_offs
);
850 dbg_lp("LPT ltab is at %d:%d", c
->ltab_lnum
, c
->ltab_offs
);
852 dbg_lp("LPT lsave is at %d:%d", c
->lsave_lnum
, c
->lsave_offs
);
864 * update_cats - add LEB properties of a pnode to LEB category lists and heaps.
865 * @c: UBIFS file-system description object
868 * When a pnode is loaded into memory, the LEB properties it contains are added,
869 * by this function, to the LEB category lists and heaps.
871 static void update_cats(struct ubifs_info
*c
, struct ubifs_pnode
*pnode
)
875 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
876 int cat
= pnode
->lprops
[i
].flags
& LPROPS_CAT_MASK
;
877 int lnum
= pnode
->lprops
[i
].lnum
;
881 ubifs_add_to_cat(c
, &pnode
->lprops
[i
], cat
);
886 * replace_cats - add LEB properties of a pnode to LEB category lists and heaps.
887 * @c: UBIFS file-system description object
888 * @old_pnode: pnode copied
889 * @new_pnode: pnode copy
891 * During commit it is sometimes necessary to copy a pnode
892 * (see dirty_cow_pnode). When that happens, references in
893 * category lists and heaps must be replaced. This function does that.
895 static void replace_cats(struct ubifs_info
*c
, struct ubifs_pnode
*old_pnode
,
896 struct ubifs_pnode
*new_pnode
)
900 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
901 if (!new_pnode
->lprops
[i
].lnum
)
903 ubifs_replace_cat(c
, &old_pnode
->lprops
[i
],
904 &new_pnode
->lprops
[i
]);
909 * check_lpt_crc - check LPT node crc is correct.
910 * @c: UBIFS file-system description object
911 * @buf: buffer containing node
912 * @len: length of node
914 * This function returns %0 on success and a negative error code on failure.
916 static int check_lpt_crc(void *buf
, int len
)
920 uint16_t crc
, calc_crc
;
922 crc
= ubifs_unpack_bits(&addr
, &pos
, UBIFS_LPT_CRC_BITS
);
923 calc_crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
924 len
- UBIFS_LPT_CRC_BYTES
);
925 if (crc
!= calc_crc
) {
926 ubifs_err("invalid crc in LPT node: crc %hx calc %hx", crc
,
935 * check_lpt_type - check LPT node type is correct.
936 * @c: UBIFS file-system description object
937 * @addr: address of type bit field is passed and returned updated here
938 * @pos: position of type bit field is passed and returned updated here
939 * @type: expected type
941 * This function returns %0 on success and a negative error code on failure.
943 static int check_lpt_type(uint8_t **addr
, int *pos
, int type
)
947 node_type
= ubifs_unpack_bits(addr
, pos
, UBIFS_LPT_TYPE_BITS
);
948 if (node_type
!= type
) {
949 ubifs_err("invalid type (%d) in LPT node type %d", node_type
,
958 * unpack_pnode - unpack a pnode.
959 * @c: UBIFS file-system description object
960 * @buf: buffer containing packed pnode to unpack
961 * @pnode: pnode structure to fill
963 * This function returns %0 on success and a negative error code on failure.
965 static int unpack_pnode(const struct ubifs_info
*c
, void *buf
,
966 struct ubifs_pnode
*pnode
)
968 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
971 err
= check_lpt_type(&addr
, &pos
, UBIFS_LPT_PNODE
);
975 pnode
->num
= ubifs_unpack_bits(&addr
, &pos
, c
->pcnt_bits
);
976 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
977 struct ubifs_lprops
* const lprops
= &pnode
->lprops
[i
];
979 lprops
->free
= ubifs_unpack_bits(&addr
, &pos
, c
->space_bits
);
981 lprops
->dirty
= ubifs_unpack_bits(&addr
, &pos
, c
->space_bits
);
984 if (ubifs_unpack_bits(&addr
, &pos
, 1))
985 lprops
->flags
= LPROPS_INDEX
;
988 lprops
->flags
|= ubifs_categorize_lprops(c
, lprops
);
990 err
= check_lpt_crc(buf
, c
->pnode_sz
);
995 * ubifs_unpack_nnode - unpack a nnode.
996 * @c: UBIFS file-system description object
997 * @buf: buffer containing packed nnode to unpack
998 * @nnode: nnode structure to fill
1000 * This function returns %0 on success and a negative error code on failure.
1002 int ubifs_unpack_nnode(const struct ubifs_info
*c
, void *buf
,
1003 struct ubifs_nnode
*nnode
)
1005 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
1006 int i
, pos
= 0, err
;
1008 err
= check_lpt_type(&addr
, &pos
, UBIFS_LPT_NNODE
);
1012 nnode
->num
= ubifs_unpack_bits(&addr
, &pos
, c
->pcnt_bits
);
1013 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1016 lnum
= ubifs_unpack_bits(&addr
, &pos
, c
->lpt_lnum_bits
) +
1018 if (lnum
== c
->lpt_last
+ 1)
1020 nnode
->nbranch
[i
].lnum
= lnum
;
1021 nnode
->nbranch
[i
].offs
= ubifs_unpack_bits(&addr
, &pos
,
1024 err
= check_lpt_crc(buf
, c
->nnode_sz
);
1029 * unpack_ltab - unpack the LPT's own lprops table.
1030 * @c: UBIFS file-system description object
1031 * @buf: buffer from which to unpack
1033 * This function returns %0 on success and a negative error code on failure.
1035 static int unpack_ltab(const struct ubifs_info
*c
, void *buf
)
1037 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
1038 int i
, pos
= 0, err
;
1040 err
= check_lpt_type(&addr
, &pos
, UBIFS_LPT_LTAB
);
1043 for (i
= 0; i
< c
->lpt_lebs
; i
++) {
1044 int free
= ubifs_unpack_bits(&addr
, &pos
, c
->lpt_spc_bits
);
1045 int dirty
= ubifs_unpack_bits(&addr
, &pos
, c
->lpt_spc_bits
);
1047 if (free
< 0 || free
> c
->leb_size
|| dirty
< 0 ||
1048 dirty
> c
->leb_size
|| free
+ dirty
> c
->leb_size
)
1051 c
->ltab
[i
].free
= free
;
1052 c
->ltab
[i
].dirty
= dirty
;
1056 err
= check_lpt_crc(buf
, c
->ltab_sz
);
1061 * unpack_lsave - unpack the LPT's save table.
1062 * @c: UBIFS file-system description object
1063 * @buf: buffer from which to unpack
1065 * This function returns %0 on success and a negative error code on failure.
1067 static int unpack_lsave(const struct ubifs_info
*c
, void *buf
)
1069 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
1070 int i
, pos
= 0, err
;
1072 err
= check_lpt_type(&addr
, &pos
, UBIFS_LPT_LSAVE
);
1075 for (i
= 0; i
< c
->lsave_cnt
; i
++) {
1076 int lnum
= ubifs_unpack_bits(&addr
, &pos
, c
->lnum_bits
);
1078 if (lnum
< c
->main_first
|| lnum
>= c
->leb_cnt
)
1082 err
= check_lpt_crc(buf
, c
->lsave_sz
);
1087 * validate_nnode - validate a nnode.
1088 * @c: UBIFS file-system description object
1089 * @nnode: nnode to validate
1090 * @parent: parent nnode (or NULL for the root nnode)
1091 * @iip: index in parent
1093 * This function returns %0 on success and a negative error code on failure.
1095 static int validate_nnode(const struct ubifs_info
*c
, struct ubifs_nnode
*nnode
,
1096 struct ubifs_nnode
*parent
, int iip
)
1098 int i
, lvl
, max_offs
;
1101 int num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1103 if (nnode
->num
!= num
)
1106 lvl
= parent
? parent
->level
- 1 : c
->lpt_hght
;
1110 max_offs
= c
->leb_size
- c
->pnode_sz
;
1112 max_offs
= c
->leb_size
- c
->nnode_sz
;
1113 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1114 int lnum
= nnode
->nbranch
[i
].lnum
;
1115 int offs
= nnode
->nbranch
[i
].offs
;
1122 if (lnum
< c
->lpt_first
|| lnum
> c
->lpt_last
)
1124 if (offs
< 0 || offs
> max_offs
)
1131 * validate_pnode - validate a pnode.
1132 * @c: UBIFS file-system description object
1133 * @pnode: pnode to validate
1134 * @parent: parent nnode
1135 * @iip: index in parent
1137 * This function returns %0 on success and a negative error code on failure.
1139 static int validate_pnode(const struct ubifs_info
*c
, struct ubifs_pnode
*pnode
,
1140 struct ubifs_nnode
*parent
, int iip
)
1145 int num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1147 if (pnode
->num
!= num
)
1150 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1151 int free
= pnode
->lprops
[i
].free
;
1152 int dirty
= pnode
->lprops
[i
].dirty
;
1154 if (free
< 0 || free
> c
->leb_size
|| free
% c
->min_io_size
||
1157 if (dirty
< 0 || dirty
> c
->leb_size
|| (dirty
& 7))
1159 if (dirty
+ free
> c
->leb_size
)
1166 * set_pnode_lnum - set LEB numbers on a pnode.
1167 * @c: UBIFS file-system description object
1168 * @pnode: pnode to update
1170 * This function calculates the LEB numbers for the LEB properties it contains
1171 * based on the pnode number.
1173 static void set_pnode_lnum(const struct ubifs_info
*c
,
1174 struct ubifs_pnode
*pnode
)
1178 lnum
= (pnode
->num
<< UBIFS_LPT_FANOUT_SHIFT
) + c
->main_first
;
1179 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1180 if (lnum
>= c
->leb_cnt
)
1182 pnode
->lprops
[i
].lnum
= lnum
++;
1187 * ubifs_read_nnode - read a nnode from flash and link it to the tree in memory.
1188 * @c: UBIFS file-system description object
1189 * @parent: parent nnode (or NULL for the root)
1190 * @iip: index in parent
1192 * This function returns %0 on success and a negative error code on failure.
1194 int ubifs_read_nnode(struct ubifs_info
*c
, struct ubifs_nnode
*parent
, int iip
)
1196 struct ubifs_nbranch
*branch
= NULL
;
1197 struct ubifs_nnode
*nnode
= NULL
;
1198 void *buf
= c
->lpt_nod_buf
;
1199 int err
, lnum
, offs
;
1202 branch
= &parent
->nbranch
[iip
];
1203 lnum
= branch
->lnum
;
1204 offs
= branch
->offs
;
1209 nnode
= kzalloc(sizeof(struct ubifs_nnode
), GFP_NOFS
);
1216 * This nnode was not written which just means that the LEB
1217 * properties in the subtree below it describe empty LEBs. We
1218 * make the nnode as though we had read it, which in fact means
1219 * doing almost nothing.
1222 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1224 err
= ubi_read(c
->ubi
, lnum
, buf
, offs
, c
->nnode_sz
);
1227 err
= ubifs_unpack_nnode(c
, buf
, nnode
);
1231 err
= validate_nnode(c
, nnode
, parent
, iip
);
1235 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1237 branch
->nnode
= nnode
;
1238 nnode
->level
= parent
->level
- 1;
1241 nnode
->level
= c
->lpt_hght
;
1243 nnode
->parent
= parent
;
1248 ubifs_err("error %d reading nnode at %d:%d", err
, lnum
, offs
);
1254 * read_pnode - read a pnode from flash and link it to the tree in memory.
1255 * @c: UBIFS file-system description object
1256 * @parent: parent nnode
1257 * @iip: index in parent
1259 * This function returns %0 on success and a negative error code on failure.
1261 static int read_pnode(struct ubifs_info
*c
, struct ubifs_nnode
*parent
, int iip
)
1263 struct ubifs_nbranch
*branch
;
1264 struct ubifs_pnode
*pnode
= NULL
;
1265 void *buf
= c
->lpt_nod_buf
;
1266 int err
, lnum
, offs
;
1268 branch
= &parent
->nbranch
[iip
];
1269 lnum
= branch
->lnum
;
1270 offs
= branch
->offs
;
1271 pnode
= kzalloc(sizeof(struct ubifs_pnode
), GFP_NOFS
);
1277 * This pnode was not written which just means that the LEB
1278 * properties in it describe empty LEBs. We make the pnode as
1279 * though we had read it.
1284 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1285 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1286 struct ubifs_lprops
* const lprops
= &pnode
->lprops
[i
];
1288 lprops
->free
= c
->leb_size
;
1289 lprops
->flags
= ubifs_categorize_lprops(c
, lprops
);
1292 err
= ubi_read(c
->ubi
, lnum
, buf
, offs
, c
->pnode_sz
);
1295 err
= unpack_pnode(c
, buf
, pnode
);
1299 err
= validate_pnode(c
, pnode
, parent
, iip
);
1303 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1304 branch
->pnode
= pnode
;
1305 pnode
->parent
= parent
;
1307 set_pnode_lnum(c
, pnode
);
1308 c
->pnodes_have
+= 1;
1312 ubifs_err("error %d reading pnode at %d:%d", err
, lnum
, offs
);
1313 dbg_dump_pnode(c
, pnode
, parent
, iip
);
1314 dbg_msg("calc num: %d", calc_pnode_num_from_parent(c
, parent
, iip
));
1320 * read_ltab - read LPT's own lprops table.
1321 * @c: UBIFS file-system description object
1323 * This function returns %0 on success and a negative error code on failure.
1325 static int read_ltab(struct ubifs_info
*c
)
1330 buf
= vmalloc(c
->ltab_sz
);
1333 err
= ubi_read(c
->ubi
, c
->ltab_lnum
, buf
, c
->ltab_offs
, c
->ltab_sz
);
1336 err
= unpack_ltab(c
, buf
);
1343 * read_lsave - read LPT's save table.
1344 * @c: UBIFS file-system description object
1346 * This function returns %0 on success and a negative error code on failure.
1348 static int read_lsave(struct ubifs_info
*c
)
1353 buf
= vmalloc(c
->lsave_sz
);
1356 err
= ubi_read(c
->ubi
, c
->lsave_lnum
, buf
, c
->lsave_offs
, c
->lsave_sz
);
1359 err
= unpack_lsave(c
, buf
);
1362 for (i
= 0; i
< c
->lsave_cnt
; i
++) {
1363 int lnum
= c
->lsave
[i
];
1366 * Due to automatic resizing, the values in the lsave table
1367 * could be beyond the volume size - just ignore them.
1369 if (lnum
>= c
->leb_cnt
)
1371 ubifs_lpt_lookup(c
, lnum
);
1379 * ubifs_get_nnode - get a nnode.
1380 * @c: UBIFS file-system description object
1381 * @parent: parent nnode (or NULL for the root)
1382 * @iip: index in parent
1384 * This function returns a pointer to the nnode on success or a negative error
1387 struct ubifs_nnode
*ubifs_get_nnode(struct ubifs_info
*c
,
1388 struct ubifs_nnode
*parent
, int iip
)
1390 struct ubifs_nbranch
*branch
;
1391 struct ubifs_nnode
*nnode
;
1394 branch
= &parent
->nbranch
[iip
];
1395 nnode
= branch
->nnode
;
1398 err
= ubifs_read_nnode(c
, parent
, iip
);
1400 return ERR_PTR(err
);
1401 return branch
->nnode
;
1405 * ubifs_get_pnode - get a pnode.
1406 * @c: UBIFS file-system description object
1407 * @parent: parent nnode
1408 * @iip: index in parent
1410 * This function returns a pointer to the pnode on success or a negative error
1413 struct ubifs_pnode
*ubifs_get_pnode(struct ubifs_info
*c
,
1414 struct ubifs_nnode
*parent
, int iip
)
1416 struct ubifs_nbranch
*branch
;
1417 struct ubifs_pnode
*pnode
;
1420 branch
= &parent
->nbranch
[iip
];
1421 pnode
= branch
->pnode
;
1424 err
= read_pnode(c
, parent
, iip
);
1426 return ERR_PTR(err
);
1427 update_cats(c
, branch
->pnode
);
1428 return branch
->pnode
;
1432 * ubifs_lpt_lookup - lookup LEB properties in the LPT.
1433 * @c: UBIFS file-system description object
1434 * @lnum: LEB number to lookup
1436 * This function returns a pointer to the LEB properties on success or a
1437 * negative error code on failure.
1439 struct ubifs_lprops
*ubifs_lpt_lookup(struct ubifs_info
*c
, int lnum
)
1441 int err
, i
, h
, iip
, shft
;
1442 struct ubifs_nnode
*nnode
;
1443 struct ubifs_pnode
*pnode
;
1446 err
= ubifs_read_nnode(c
, NULL
, 0);
1448 return ERR_PTR(err
);
1451 i
= lnum
- c
->main_first
;
1452 shft
= c
->lpt_hght
* UBIFS_LPT_FANOUT_SHIFT
;
1453 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1454 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1455 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1456 nnode
= ubifs_get_nnode(c
, nnode
, iip
);
1458 return ERR_PTR(PTR_ERR(nnode
));
1460 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1461 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1462 pnode
= ubifs_get_pnode(c
, nnode
, iip
);
1464 return ERR_PTR(PTR_ERR(pnode
));
1465 iip
= (i
& (UBIFS_LPT_FANOUT
- 1));
1466 dbg_lp("LEB %d, free %d, dirty %d, flags %d", lnum
,
1467 pnode
->lprops
[iip
].free
, pnode
->lprops
[iip
].dirty
,
1468 pnode
->lprops
[iip
].flags
);
1469 return &pnode
->lprops
[iip
];
1473 * dirty_cow_nnode - ensure a nnode is not being committed.
1474 * @c: UBIFS file-system description object
1475 * @nnode: nnode to check
1477 * Returns dirtied nnode on success or negative error code on failure.
1479 static struct ubifs_nnode
*dirty_cow_nnode(struct ubifs_info
*c
,
1480 struct ubifs_nnode
*nnode
)
1482 struct ubifs_nnode
*n
;
1485 if (!test_bit(COW_CNODE
, &nnode
->flags
)) {
1486 /* nnode is not being committed */
1487 if (!test_and_set_bit(DIRTY_CNODE
, &nnode
->flags
)) {
1488 c
->dirty_nn_cnt
+= 1;
1489 ubifs_add_nnode_dirt(c
, nnode
);
1494 /* nnode is being committed, so copy it */
1495 n
= kmalloc(sizeof(struct ubifs_nnode
), GFP_NOFS
);
1497 return ERR_PTR(-ENOMEM
);
1499 memcpy(n
, nnode
, sizeof(struct ubifs_nnode
));
1501 __set_bit(DIRTY_CNODE
, &n
->flags
);
1502 __clear_bit(COW_CNODE
, &n
->flags
);
1504 /* The children now have new parent */
1505 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1506 struct ubifs_nbranch
*branch
= &n
->nbranch
[i
];
1509 branch
->cnode
->parent
= n
;
1512 ubifs_assert(!test_bit(OBSOLETE_CNODE
, &nnode
->flags
));
1513 __set_bit(OBSOLETE_CNODE
, &nnode
->flags
);
1515 c
->dirty_nn_cnt
+= 1;
1516 ubifs_add_nnode_dirt(c
, nnode
);
1518 nnode
->parent
->nbranch
[n
->iip
].nnode
= n
;
1525 * dirty_cow_pnode - ensure a pnode is not being committed.
1526 * @c: UBIFS file-system description object
1527 * @pnode: pnode to check
1529 * Returns dirtied pnode on success or negative error code on failure.
1531 static struct ubifs_pnode
*dirty_cow_pnode(struct ubifs_info
*c
,
1532 struct ubifs_pnode
*pnode
)
1534 struct ubifs_pnode
*p
;
1536 if (!test_bit(COW_CNODE
, &pnode
->flags
)) {
1537 /* pnode is not being committed */
1538 if (!test_and_set_bit(DIRTY_CNODE
, &pnode
->flags
)) {
1539 c
->dirty_pn_cnt
+= 1;
1540 add_pnode_dirt(c
, pnode
);
1545 /* pnode is being committed, so copy it */
1546 p
= kmalloc(sizeof(struct ubifs_pnode
), GFP_NOFS
);
1548 return ERR_PTR(-ENOMEM
);
1550 memcpy(p
, pnode
, sizeof(struct ubifs_pnode
));
1552 __set_bit(DIRTY_CNODE
, &p
->flags
);
1553 __clear_bit(COW_CNODE
, &p
->flags
);
1554 replace_cats(c
, pnode
, p
);
1556 ubifs_assert(!test_bit(OBSOLETE_CNODE
, &pnode
->flags
));
1557 __set_bit(OBSOLETE_CNODE
, &pnode
->flags
);
1559 c
->dirty_pn_cnt
+= 1;
1560 add_pnode_dirt(c
, pnode
);
1561 pnode
->parent
->nbranch
[p
->iip
].pnode
= p
;
1566 * ubifs_lpt_lookup_dirty - lookup LEB properties in the LPT.
1567 * @c: UBIFS file-system description object
1568 * @lnum: LEB number to lookup
1570 * This function returns a pointer to the LEB properties on success or a
1571 * negative error code on failure.
1573 struct ubifs_lprops
*ubifs_lpt_lookup_dirty(struct ubifs_info
*c
, int lnum
)
1575 int err
, i
, h
, iip
, shft
;
1576 struct ubifs_nnode
*nnode
;
1577 struct ubifs_pnode
*pnode
;
1580 err
= ubifs_read_nnode(c
, NULL
, 0);
1582 return ERR_PTR(err
);
1585 nnode
= dirty_cow_nnode(c
, nnode
);
1587 return ERR_PTR(PTR_ERR(nnode
));
1588 i
= lnum
- c
->main_first
;
1589 shft
= c
->lpt_hght
* UBIFS_LPT_FANOUT_SHIFT
;
1590 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1591 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1592 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1593 nnode
= ubifs_get_nnode(c
, nnode
, iip
);
1595 return ERR_PTR(PTR_ERR(nnode
));
1596 nnode
= dirty_cow_nnode(c
, nnode
);
1598 return ERR_PTR(PTR_ERR(nnode
));
1600 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1601 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1602 pnode
= ubifs_get_pnode(c
, nnode
, iip
);
1604 return ERR_PTR(PTR_ERR(pnode
));
1605 pnode
= dirty_cow_pnode(c
, pnode
);
1607 return ERR_PTR(PTR_ERR(pnode
));
1608 iip
= (i
& (UBIFS_LPT_FANOUT
- 1));
1609 dbg_lp("LEB %d, free %d, dirty %d, flags %d", lnum
,
1610 pnode
->lprops
[iip
].free
, pnode
->lprops
[iip
].dirty
,
1611 pnode
->lprops
[iip
].flags
);
1612 ubifs_assert(test_bit(DIRTY_CNODE
, &pnode
->flags
));
1613 return &pnode
->lprops
[iip
];
1617 * lpt_init_rd - initialize the LPT for reading.
1618 * @c: UBIFS file-system description object
1620 * This function returns %0 on success and a negative error code on failure.
1622 static int lpt_init_rd(struct ubifs_info
*c
)
1626 c
->ltab
= vmalloc(sizeof(struct ubifs_lpt_lprops
) * c
->lpt_lebs
);
1630 i
= max_t(int, c
->nnode_sz
, c
->pnode_sz
);
1631 c
->lpt_nod_buf
= kmalloc(i
, GFP_KERNEL
);
1632 if (!c
->lpt_nod_buf
)
1635 for (i
= 0; i
< LPROPS_HEAP_CNT
; i
++) {
1636 c
->lpt_heap
[i
].arr
= kmalloc(sizeof(void *) * LPT_HEAP_SZ
,
1638 if (!c
->lpt_heap
[i
].arr
)
1640 c
->lpt_heap
[i
].cnt
= 0;
1641 c
->lpt_heap
[i
].max_cnt
= LPT_HEAP_SZ
;
1644 c
->dirty_idx
.arr
= kmalloc(sizeof(void *) * LPT_HEAP_SZ
, GFP_KERNEL
);
1645 if (!c
->dirty_idx
.arr
)
1647 c
->dirty_idx
.cnt
= 0;
1648 c
->dirty_idx
.max_cnt
= LPT_HEAP_SZ
;
1654 dbg_lp("space_bits %d", c
->space_bits
);
1655 dbg_lp("lpt_lnum_bits %d", c
->lpt_lnum_bits
);
1656 dbg_lp("lpt_offs_bits %d", c
->lpt_offs_bits
);
1657 dbg_lp("lpt_spc_bits %d", c
->lpt_spc_bits
);
1658 dbg_lp("pcnt_bits %d", c
->pcnt_bits
);
1659 dbg_lp("lnum_bits %d", c
->lnum_bits
);
1660 dbg_lp("pnode_sz %d", c
->pnode_sz
);
1661 dbg_lp("nnode_sz %d", c
->nnode_sz
);
1662 dbg_lp("ltab_sz %d", c
->ltab_sz
);
1663 dbg_lp("lsave_sz %d", c
->lsave_sz
);
1664 dbg_lp("lsave_cnt %d", c
->lsave_cnt
);
1665 dbg_lp("lpt_hght %d", c
->lpt_hght
);
1666 dbg_lp("big_lpt %d", c
->big_lpt
);
1667 dbg_lp("LPT root is at %d:%d", c
->lpt_lnum
, c
->lpt_offs
);
1668 dbg_lp("LPT head is at %d:%d", c
->nhead_lnum
, c
->nhead_offs
);
1669 dbg_lp("LPT ltab is at %d:%d", c
->ltab_lnum
, c
->ltab_offs
);
1671 dbg_lp("LPT lsave is at %d:%d", c
->lsave_lnum
, c
->lsave_offs
);
1677 * lpt_init_wr - initialize the LPT for writing.
1678 * @c: UBIFS file-system description object
1680 * 'lpt_init_rd()' must have been called already.
1682 * This function returns %0 on success and a negative error code on failure.
1684 static int lpt_init_wr(struct ubifs_info
*c
)
1688 c
->ltab_cmt
= vmalloc(sizeof(struct ubifs_lpt_lprops
) * c
->lpt_lebs
);
1692 c
->lpt_buf
= vmalloc(c
->leb_size
);
1697 c
->lsave
= kmalloc(sizeof(int) * c
->lsave_cnt
, GFP_NOFS
);
1700 err
= read_lsave(c
);
1705 for (i
= 0; i
< c
->lpt_lebs
; i
++)
1706 if (c
->ltab
[i
].free
== c
->leb_size
) {
1707 err
= ubifs_leb_unmap(c
, i
+ c
->lpt_first
);
1716 * ubifs_lpt_init - initialize the LPT.
1717 * @c: UBIFS file-system description object
1718 * @rd: whether to initialize lpt for reading
1719 * @wr: whether to initialize lpt for writing
1721 * For mounting 'rw', @rd and @wr are both true. For mounting 'ro', @rd is true
1722 * and @wr is false. For mounting from 'ro' to 'rw', @rd is false and @wr is
1725 * This function returns %0 on success and a negative error code on failure.
1727 int ubifs_lpt_init(struct ubifs_info
*c
, int rd
, int wr
)
1732 err
= lpt_init_rd(c
);
1738 err
= lpt_init_wr(c
);
1747 * struct lpt_scan_node - somewhere to put nodes while we scan LPT.
1748 * @nnode: where to keep a nnode
1749 * @pnode: where to keep a pnode
1750 * @cnode: where to keep a cnode
1751 * @in_tree: is the node in the tree in memory
1752 * @ptr.nnode: pointer to the nnode (if it is an nnode) which may be here or in
1754 * @ptr.pnode: ditto for pnode
1755 * @ptr.cnode: ditto for cnode
1757 struct lpt_scan_node
{
1759 struct ubifs_nnode nnode
;
1760 struct ubifs_pnode pnode
;
1761 struct ubifs_cnode cnode
;
1765 struct ubifs_nnode
*nnode
;
1766 struct ubifs_pnode
*pnode
;
1767 struct ubifs_cnode
*cnode
;
1772 * scan_get_nnode - for the scan, get a nnode from either the tree or flash.
1773 * @c: the UBIFS file-system description object
1774 * @path: where to put the nnode
1775 * @parent: parent of the nnode
1776 * @iip: index in parent of the nnode
1778 * This function returns a pointer to the nnode on success or a negative error
1781 static struct ubifs_nnode
*scan_get_nnode(struct ubifs_info
*c
,
1782 struct lpt_scan_node
*path
,
1783 struct ubifs_nnode
*parent
, int iip
)
1785 struct ubifs_nbranch
*branch
;
1786 struct ubifs_nnode
*nnode
;
1787 void *buf
= c
->lpt_nod_buf
;
1790 branch
= &parent
->nbranch
[iip
];
1791 nnode
= branch
->nnode
;
1794 path
->ptr
.nnode
= nnode
;
1797 nnode
= &path
->nnode
;
1799 path
->ptr
.nnode
= nnode
;
1800 memset(nnode
, 0, sizeof(struct ubifs_nnode
));
1801 if (branch
->lnum
== 0) {
1803 * This nnode was not written which just means that the LEB
1804 * properties in the subtree below it describe empty LEBs. We
1805 * make the nnode as though we had read it, which in fact means
1806 * doing almost nothing.
1809 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1811 err
= ubi_read(c
->ubi
, branch
->lnum
, buf
, branch
->offs
,
1814 return ERR_PTR(err
);
1815 err
= ubifs_unpack_nnode(c
, buf
, nnode
);
1817 return ERR_PTR(err
);
1819 err
= validate_nnode(c
, nnode
, parent
, iip
);
1821 return ERR_PTR(err
);
1823 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1824 nnode
->level
= parent
->level
- 1;
1825 nnode
->parent
= parent
;
1831 * scan_get_pnode - for the scan, get a pnode from either the tree or flash.
1832 * @c: the UBIFS file-system description object
1833 * @path: where to put the pnode
1834 * @parent: parent of the pnode
1835 * @iip: index in parent of the pnode
1837 * This function returns a pointer to the pnode on success or a negative error
1840 static struct ubifs_pnode
*scan_get_pnode(struct ubifs_info
*c
,
1841 struct lpt_scan_node
*path
,
1842 struct ubifs_nnode
*parent
, int iip
)
1844 struct ubifs_nbranch
*branch
;
1845 struct ubifs_pnode
*pnode
;
1846 void *buf
= c
->lpt_nod_buf
;
1849 branch
= &parent
->nbranch
[iip
];
1850 pnode
= branch
->pnode
;
1853 path
->ptr
.pnode
= pnode
;
1856 pnode
= &path
->pnode
;
1858 path
->ptr
.pnode
= pnode
;
1859 memset(pnode
, 0, sizeof(struct ubifs_pnode
));
1860 if (branch
->lnum
== 0) {
1862 * This pnode was not written which just means that the LEB
1863 * properties in it describe empty LEBs. We make the pnode as
1864 * though we had read it.
1869 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1870 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1871 struct ubifs_lprops
* const lprops
= &pnode
->lprops
[i
];
1873 lprops
->free
= c
->leb_size
;
1874 lprops
->flags
= ubifs_categorize_lprops(c
, lprops
);
1877 ubifs_assert(branch
->lnum
>= c
->lpt_first
&&
1878 branch
->lnum
<= c
->lpt_last
);
1879 ubifs_assert(branch
->offs
>= 0 && branch
->offs
< c
->leb_size
);
1880 err
= ubi_read(c
->ubi
, branch
->lnum
, buf
, branch
->offs
,
1883 return ERR_PTR(err
);
1884 err
= unpack_pnode(c
, buf
, pnode
);
1886 return ERR_PTR(err
);
1888 err
= validate_pnode(c
, pnode
, parent
, iip
);
1890 return ERR_PTR(err
);
1892 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1893 pnode
->parent
= parent
;
1895 set_pnode_lnum(c
, pnode
);
1900 * ubifs_lpt_scan_nolock - scan the LPT.
1901 * @c: the UBIFS file-system description object
1902 * @start_lnum: LEB number from which to start scanning
1903 * @end_lnum: LEB number at which to stop scanning
1904 * @scan_cb: callback function called for each lprops
1905 * @data: data to be passed to the callback function
1907 * This function returns %0 on success and a negative error code on failure.
1909 int ubifs_lpt_scan_nolock(struct ubifs_info
*c
, int start_lnum
, int end_lnum
,
1910 ubifs_lpt_scan_callback scan_cb
, void *data
)
1912 int err
= 0, i
, h
, iip
, shft
;
1913 struct ubifs_nnode
*nnode
;
1914 struct ubifs_pnode
*pnode
;
1915 struct lpt_scan_node
*path
;
1917 if (start_lnum
== -1) {
1918 start_lnum
= end_lnum
+ 1;
1919 if (start_lnum
>= c
->leb_cnt
)
1920 start_lnum
= c
->main_first
;
1923 ubifs_assert(start_lnum
>= c
->main_first
&& start_lnum
< c
->leb_cnt
);
1924 ubifs_assert(end_lnum
>= c
->main_first
&& end_lnum
< c
->leb_cnt
);
1927 err
= ubifs_read_nnode(c
, NULL
, 0);
1932 path
= kmalloc(sizeof(struct lpt_scan_node
) * (c
->lpt_hght
+ 1),
1937 path
[0].ptr
.nnode
= c
->nroot
;
1938 path
[0].in_tree
= 1;
1940 /* Descend to the pnode containing start_lnum */
1942 i
= start_lnum
- c
->main_first
;
1943 shft
= c
->lpt_hght
* UBIFS_LPT_FANOUT_SHIFT
;
1944 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1945 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1946 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1947 nnode
= scan_get_nnode(c
, path
+ h
, nnode
, iip
);
1948 if (IS_ERR(nnode
)) {
1949 err
= PTR_ERR(nnode
);
1953 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1954 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1955 pnode
= scan_get_pnode(c
, path
+ h
, nnode
, iip
);
1956 if (IS_ERR(pnode
)) {
1957 err
= PTR_ERR(pnode
);
1960 iip
= (i
& (UBIFS_LPT_FANOUT
- 1));
1962 /* Loop for each lprops */
1964 struct ubifs_lprops
*lprops
= &pnode
->lprops
[iip
];
1965 int ret
, lnum
= lprops
->lnum
;
1967 ret
= scan_cb(c
, lprops
, path
[h
].in_tree
, data
);
1972 if (ret
& LPT_SCAN_ADD
) {
1973 /* Add all the nodes in path to the tree in memory */
1974 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1975 const size_t sz
= sizeof(struct ubifs_nnode
);
1976 struct ubifs_nnode
*parent
;
1978 if (path
[h
].in_tree
)
1980 nnode
= kmalloc(sz
, GFP_NOFS
);
1985 memcpy(nnode
, &path
[h
].nnode
, sz
);
1986 parent
= nnode
->parent
;
1987 parent
->nbranch
[nnode
->iip
].nnode
= nnode
;
1988 path
[h
].ptr
.nnode
= nnode
;
1989 path
[h
].in_tree
= 1;
1990 path
[h
+ 1].cnode
.parent
= nnode
;
1992 if (path
[h
].in_tree
)
1993 ubifs_ensure_cat(c
, lprops
);
1995 const size_t sz
= sizeof(struct ubifs_pnode
);
1996 struct ubifs_nnode
*parent
;
1998 pnode
= kmalloc(sz
, GFP_NOFS
);
2003 memcpy(pnode
, &path
[h
].pnode
, sz
);
2004 parent
= pnode
->parent
;
2005 parent
->nbranch
[pnode
->iip
].pnode
= pnode
;
2006 path
[h
].ptr
.pnode
= pnode
;
2007 path
[h
].in_tree
= 1;
2008 update_cats(c
, pnode
);
2009 c
->pnodes_have
+= 1;
2011 err
= dbg_check_lpt_nodes(c
, (struct ubifs_cnode
*)
2015 err
= dbg_check_cats(c
);
2019 if (ret
& LPT_SCAN_STOP
) {
2023 /* Get the next lprops */
2024 if (lnum
== end_lnum
) {
2026 * We got to the end without finding what we were
2032 if (lnum
+ 1 >= c
->leb_cnt
) {
2033 /* Wrap-around to the beginning */
2034 start_lnum
= c
->main_first
;
2037 if (iip
+ 1 < UBIFS_LPT_FANOUT
) {
2038 /* Next lprops is in the same pnode */
2042 /* We need to get the next pnode. Go up until we can go right */
2046 ubifs_assert(h
>= 0);
2047 nnode
= path
[h
].ptr
.nnode
;
2048 if (iip
+ 1 < UBIFS_LPT_FANOUT
)
2054 /* Descend to the pnode */
2056 for (; h
< c
->lpt_hght
; h
++) {
2057 nnode
= scan_get_nnode(c
, path
+ h
, nnode
, iip
);
2058 if (IS_ERR(nnode
)) {
2059 err
= PTR_ERR(nnode
);
2064 pnode
= scan_get_pnode(c
, path
+ h
, nnode
, iip
);
2065 if (IS_ERR(pnode
)) {
2066 err
= PTR_ERR(pnode
);
2076 #ifdef CONFIG_UBIFS_FS_DEBUG
2079 * dbg_chk_pnode - check a pnode.
2080 * @c: the UBIFS file-system description object
2081 * @pnode: pnode to check
2082 * @col: pnode column
2084 * This function returns %0 on success and a negative error code on failure.
2086 static int dbg_chk_pnode(struct ubifs_info
*c
, struct ubifs_pnode
*pnode
,
2091 if (pnode
->num
!= col
) {
2092 dbg_err("pnode num %d expected %d parent num %d iip %d",
2093 pnode
->num
, col
, pnode
->parent
->num
, pnode
->iip
);
2096 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
2097 struct ubifs_lprops
*lp
, *lprops
= &pnode
->lprops
[i
];
2098 int lnum
= (pnode
->num
<< UBIFS_LPT_FANOUT_SHIFT
) + i
+
2100 int found
, cat
= lprops
->flags
& LPROPS_CAT_MASK
;
2101 struct ubifs_lpt_heap
*heap
;
2102 struct list_head
*list
= NULL
;
2104 if (lnum
>= c
->leb_cnt
)
2106 if (lprops
->lnum
!= lnum
) {
2107 dbg_err("bad LEB number %d expected %d",
2108 lprops
->lnum
, lnum
);
2111 if (lprops
->flags
& LPROPS_TAKEN
) {
2112 if (cat
!= LPROPS_UNCAT
) {
2113 dbg_err("LEB %d taken but not uncat %d",
2119 if (lprops
->flags
& LPROPS_INDEX
) {
2122 case LPROPS_DIRTY_IDX
:
2123 case LPROPS_FRDI_IDX
:
2126 dbg_err("LEB %d index but cat %d",
2136 case LPROPS_FREEABLE
:
2139 dbg_err("LEB %d not index but cat %d",
2146 list
= &c
->uncat_list
;
2149 list
= &c
->empty_list
;
2151 case LPROPS_FREEABLE
:
2152 list
= &c
->freeable_list
;
2154 case LPROPS_FRDI_IDX
:
2155 list
= &c
->frdi_idx_list
;
2161 case LPROPS_DIRTY_IDX
:
2163 heap
= &c
->lpt_heap
[cat
- 1];
2164 if (lprops
->hpos
< heap
->cnt
&&
2165 heap
->arr
[lprops
->hpos
] == lprops
)
2170 case LPROPS_FREEABLE
:
2171 case LPROPS_FRDI_IDX
:
2172 list_for_each_entry(lp
, list
, list
)
2180 dbg_err("LEB %d cat %d not found in cat heap/list",
2186 if (lprops
->free
!= c
->leb_size
) {
2187 dbg_err("LEB %d cat %d free %d dirty %d",
2188 lprops
->lnum
, cat
, lprops
->free
,
2192 case LPROPS_FREEABLE
:
2193 case LPROPS_FRDI_IDX
:
2194 if (lprops
->free
+ lprops
->dirty
!= c
->leb_size
) {
2195 dbg_err("LEB %d cat %d free %d dirty %d",
2196 lprops
->lnum
, cat
, lprops
->free
,
2206 * dbg_check_lpt_nodes - check nnodes and pnodes.
2207 * @c: the UBIFS file-system description object
2208 * @cnode: next cnode (nnode or pnode) to check
2209 * @row: row of cnode (root is zero)
2210 * @col: column of cnode (leftmost is zero)
2212 * This function returns %0 on success and a negative error code on failure.
2214 int dbg_check_lpt_nodes(struct ubifs_info
*c
, struct ubifs_cnode
*cnode
,
2217 struct ubifs_nnode
*nnode
, *nn
;
2218 struct ubifs_cnode
*cn
;
2219 int num
, iip
= 0, err
;
2221 if (!(ubifs_chk_flags
& UBIFS_CHK_LPROPS
))
2225 ubifs_assert(row
>= 0);
2226 nnode
= cnode
->parent
;
2228 /* cnode is a nnode */
2229 num
= calc_nnode_num(row
, col
);
2230 if (cnode
->num
!= num
) {
2231 dbg_err("nnode num %d expected %d "
2232 "parent num %d iip %d", cnode
->num
, num
,
2233 (nnode
? nnode
->num
: 0), cnode
->iip
);
2236 nn
= (struct ubifs_nnode
*)cnode
;
2237 while (iip
< UBIFS_LPT_FANOUT
) {
2238 cn
= nn
->nbranch
[iip
].cnode
;
2242 col
<<= UBIFS_LPT_FANOUT_SHIFT
;
2251 if (iip
< UBIFS_LPT_FANOUT
)
2254 struct ubifs_pnode
*pnode
;
2256 /* cnode is a pnode */
2257 pnode
= (struct ubifs_pnode
*)cnode
;
2258 err
= dbg_chk_pnode(c
, pnode
, col
);
2262 /* Go up and to the right */
2264 col
>>= UBIFS_LPT_FANOUT_SHIFT
;
2265 iip
= cnode
->iip
+ 1;
2266 cnode
= (struct ubifs_cnode
*)nnode
;
2271 #endif /* CONFIG_UBIFS_FS_DEBUG */