1 // SPDX-License-Identifier: GPL-2.0+
3 * This file is part of UBIFS.
5 * Copyright (C) 2006-2008 Nokia Corporation.
7 * Authors: Adrian Hunter
8 * Artem Bityutskiy (Битюцкий Артём)
12 * This file implements the LEB properties tree (LPT) area. The LPT area
13 * contains the LEB properties tree, a table of LPT area eraseblocks (ltab), and
14 * (for the "big" model) a table of saved LEB numbers (lsave). The LPT area sits
15 * between the log and the orphan area.
17 * The LPT area is like a miniature self-contained file system. It is required
18 * that it never runs out of space, is fast to access and update, and scales
19 * logarithmically. The LEB properties tree is implemented as a wandering tree
20 * much like the TNC, and the LPT area has its own garbage collection.
22 * The LPT has two slightly different forms called the "small model" and the
23 * "big model". The small model is used when the entire LEB properties table
24 * can be written into a single eraseblock. In that case, garbage collection
25 * consists of just writing the whole table, which therefore makes all other
26 * eraseblocks reusable. In the case of the big model, dirty eraseblocks are
27 * selected for garbage collection, which consists of marking the clean nodes in
28 * that LEB as dirty, and then only the dirty nodes are written out. Also, in
29 * the case of the big model, a table of LEB numbers is saved so that the entire
30 * LPT does not to be scanned looking for empty eraseblocks when UBIFS is first
36 #include <linux/crc16.h>
37 #include <linux/math64.h>
38 #include <linux/slab.h>
40 #include <linux/compat.h>
41 #include <linux/err.h>
42 #include <ubi_uboot.h>
47 * do_calc_lpt_geom - calculate sizes for the LPT area.
48 * @c: the UBIFS file-system description object
50 * Calculate the sizes of LPT bit fields, nodes, and tree, based on the
51 * properties of the flash and whether LPT is "big" (c->big_lpt).
53 static void do_calc_lpt_geom(struct ubifs_info
*c
)
55 int i
, n
, bits
, per_leb_wastage
, max_pnode_cnt
;
56 long long sz
, tot_wastage
;
58 n
= c
->main_lebs
+ c
->max_leb_cnt
- c
->leb_cnt
;
59 max_pnode_cnt
= DIV_ROUND_UP(n
, UBIFS_LPT_FANOUT
);
63 while (n
< max_pnode_cnt
) {
65 n
<<= UBIFS_LPT_FANOUT_SHIFT
;
68 c
->pnode_cnt
= DIV_ROUND_UP(c
->main_lebs
, UBIFS_LPT_FANOUT
);
70 n
= DIV_ROUND_UP(c
->pnode_cnt
, UBIFS_LPT_FANOUT
);
72 for (i
= 1; i
< c
->lpt_hght
; i
++) {
73 n
= DIV_ROUND_UP(n
, UBIFS_LPT_FANOUT
);
77 c
->space_bits
= fls(c
->leb_size
) - 3;
78 c
->lpt_lnum_bits
= fls(c
->lpt_lebs
);
79 c
->lpt_offs_bits
= fls(c
->leb_size
- 1);
80 c
->lpt_spc_bits
= fls(c
->leb_size
);
82 n
= DIV_ROUND_UP(c
->max_leb_cnt
, UBIFS_LPT_FANOUT
);
83 c
->pcnt_bits
= fls(n
- 1);
85 c
->lnum_bits
= fls(c
->max_leb_cnt
- 1);
87 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
88 (c
->big_lpt
? c
->pcnt_bits
: 0) +
89 (c
->space_bits
* 2 + 1) * UBIFS_LPT_FANOUT
;
90 c
->pnode_sz
= (bits
+ 7) / 8;
92 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
93 (c
->big_lpt
? c
->pcnt_bits
: 0) +
94 (c
->lpt_lnum_bits
+ c
->lpt_offs_bits
) * UBIFS_LPT_FANOUT
;
95 c
->nnode_sz
= (bits
+ 7) / 8;
97 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
98 c
->lpt_lebs
* c
->lpt_spc_bits
* 2;
99 c
->ltab_sz
= (bits
+ 7) / 8;
101 bits
= UBIFS_LPT_CRC_BITS
+ UBIFS_LPT_TYPE_BITS
+
102 c
->lnum_bits
* c
->lsave_cnt
;
103 c
->lsave_sz
= (bits
+ 7) / 8;
105 /* Calculate the minimum LPT size */
106 c
->lpt_sz
= (long long)c
->pnode_cnt
* c
->pnode_sz
;
107 c
->lpt_sz
+= (long long)c
->nnode_cnt
* c
->nnode_sz
;
108 c
->lpt_sz
+= c
->ltab_sz
;
110 c
->lpt_sz
+= c
->lsave_sz
;
114 per_leb_wastage
= max_t(int, c
->pnode_sz
, c
->nnode_sz
);
115 sz
+= per_leb_wastage
;
116 tot_wastage
= per_leb_wastage
;
117 while (sz
> c
->leb_size
) {
118 sz
+= per_leb_wastage
;
120 tot_wastage
+= per_leb_wastage
;
122 tot_wastage
+= ALIGN(sz
, c
->min_io_size
) - sz
;
123 c
->lpt_sz
+= tot_wastage
;
127 * ubifs_calc_lpt_geom - calculate and check sizes for the LPT area.
128 * @c: the UBIFS file-system description object
130 * This function returns %0 on success and a negative error code on failure.
132 int ubifs_calc_lpt_geom(struct ubifs_info
*c
)
139 /* Verify that lpt_lebs is big enough */
140 sz
= c
->lpt_sz
* 2; /* Must have at least 2 times the size */
141 lebs_needed
= div_u64(sz
+ c
->leb_size
- 1, c
->leb_size
);
142 if (lebs_needed
> c
->lpt_lebs
) {
143 ubifs_err(c
, "too few LPT LEBs");
147 /* Verify that ltab fits in a single LEB (since ltab is a single node */
148 if (c
->ltab_sz
> c
->leb_size
) {
149 ubifs_err(c
, "LPT ltab too big");
153 c
->check_lpt_free
= c
->big_lpt
;
158 * calc_dflt_lpt_geom - calculate default LPT geometry.
159 * @c: the UBIFS file-system description object
160 * @main_lebs: number of main area LEBs is passed and returned here
161 * @big_lpt: whether the LPT area is "big" is returned here
163 * The size of the LPT area depends on parameters that themselves are dependent
164 * on the size of the LPT area. This function, successively recalculates the LPT
165 * area geometry until the parameters and resultant geometry are consistent.
167 * This function returns %0 on success and a negative error code on failure.
169 static int calc_dflt_lpt_geom(struct ubifs_info
*c
, int *main_lebs
,
175 /* Start by assuming the minimum number of LPT LEBs */
176 c
->lpt_lebs
= UBIFS_MIN_LPT_LEBS
;
177 c
->main_lebs
= *main_lebs
- c
->lpt_lebs
;
178 if (c
->main_lebs
<= 0)
181 /* And assume we will use the small LPT model */
185 * Calculate the geometry based on assumptions above and then see if it
190 /* Small LPT model must have lpt_sz < leb_size */
191 if (c
->lpt_sz
> c
->leb_size
) {
192 /* Nope, so try again using big LPT model */
197 /* Now check there are enough LPT LEBs */
198 for (i
= 0; i
< 64 ; i
++) {
199 sz
= c
->lpt_sz
* 4; /* Allow 4 times the size */
200 lebs_needed
= div_u64(sz
+ c
->leb_size
- 1, c
->leb_size
);
201 if (lebs_needed
> c
->lpt_lebs
) {
202 /* Not enough LPT LEBs so try again with more */
203 c
->lpt_lebs
= lebs_needed
;
204 c
->main_lebs
= *main_lebs
- c
->lpt_lebs
;
205 if (c
->main_lebs
<= 0)
210 if (c
->ltab_sz
> c
->leb_size
) {
211 ubifs_err(c
, "LPT ltab too big");
214 *main_lebs
= c
->main_lebs
;
215 *big_lpt
= c
->big_lpt
;
222 * pack_bits - pack bit fields end-to-end.
223 * @addr: address at which to pack (passed and next address returned)
224 * @pos: bit position at which to pack (passed and next position returned)
225 * @val: value to pack
226 * @nrbits: number of bits of value to pack (1-32)
228 static void pack_bits(uint8_t **addr
, int *pos
, uint32_t val
, int nrbits
)
233 ubifs_assert(nrbits
> 0);
234 ubifs_assert(nrbits
<= 32);
235 ubifs_assert(*pos
>= 0);
236 ubifs_assert(*pos
< 8);
237 ubifs_assert((val
>> nrbits
) == 0 || nrbits
== 32);
239 *p
|= ((uint8_t)val
) << b
;
242 *++p
= (uint8_t)(val
>>= (8 - b
));
244 *++p
= (uint8_t)(val
>>= 8);
246 *++p
= (uint8_t)(val
>>= 8);
248 *++p
= (uint8_t)(val
>>= 8);
255 *++p
= (uint8_t)(val
>>= 8);
257 *++p
= (uint8_t)(val
>>= 8);
259 *++p
= (uint8_t)(val
>>= 8);
271 * ubifs_unpack_bits - unpack bit fields.
272 * @addr: address at which to unpack (passed and next address returned)
273 * @pos: bit position at which to unpack (passed and next position returned)
274 * @nrbits: number of bits of value to unpack (1-32)
276 * This functions returns the value unpacked.
278 uint32_t ubifs_unpack_bits(uint8_t **addr
, int *pos
, int nrbits
)
280 const int k
= 32 - nrbits
;
283 uint32_t uninitialized_var(val
);
284 const int bytes
= (nrbits
+ b
+ 7) >> 3;
286 ubifs_assert(nrbits
> 0);
287 ubifs_assert(nrbits
<= 32);
288 ubifs_assert(*pos
>= 0);
289 ubifs_assert(*pos
< 8);
296 val
= p
[1] | ((uint32_t)p
[2] << 8);
299 val
= p
[1] | ((uint32_t)p
[2] << 8) |
300 ((uint32_t)p
[3] << 16);
303 val
= p
[1] | ((uint32_t)p
[2] << 8) |
304 ((uint32_t)p
[3] << 16) |
305 ((uint32_t)p
[4] << 24);
316 val
= p
[0] | ((uint32_t)p
[1] << 8);
319 val
= p
[0] | ((uint32_t)p
[1] << 8) |
320 ((uint32_t)p
[2] << 16);
323 val
= p
[0] | ((uint32_t)p
[1] << 8) |
324 ((uint32_t)p
[2] << 16) |
325 ((uint32_t)p
[3] << 24);
335 ubifs_assert((val
>> nrbits
) == 0 || nrbits
- b
== 32);
340 * ubifs_pack_pnode - pack all the bit fields of a pnode.
341 * @c: UBIFS file-system description object
342 * @buf: buffer into which to pack
343 * @pnode: pnode to pack
345 void ubifs_pack_pnode(struct ubifs_info
*c
, void *buf
,
346 struct ubifs_pnode
*pnode
)
348 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
352 pack_bits(&addr
, &pos
, UBIFS_LPT_PNODE
, UBIFS_LPT_TYPE_BITS
);
354 pack_bits(&addr
, &pos
, pnode
->num
, c
->pcnt_bits
);
355 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
356 pack_bits(&addr
, &pos
, pnode
->lprops
[i
].free
>> 3,
358 pack_bits(&addr
, &pos
, pnode
->lprops
[i
].dirty
>> 3,
360 if (pnode
->lprops
[i
].flags
& LPROPS_INDEX
)
361 pack_bits(&addr
, &pos
, 1, 1);
363 pack_bits(&addr
, &pos
, 0, 1);
365 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
366 c
->pnode_sz
- UBIFS_LPT_CRC_BYTES
);
369 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
373 * ubifs_pack_nnode - pack all the bit fields of a nnode.
374 * @c: UBIFS file-system description object
375 * @buf: buffer into which to pack
376 * @nnode: nnode to pack
378 void ubifs_pack_nnode(struct ubifs_info
*c
, void *buf
,
379 struct ubifs_nnode
*nnode
)
381 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
385 pack_bits(&addr
, &pos
, UBIFS_LPT_NNODE
, UBIFS_LPT_TYPE_BITS
);
387 pack_bits(&addr
, &pos
, nnode
->num
, c
->pcnt_bits
);
388 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
389 int lnum
= nnode
->nbranch
[i
].lnum
;
392 lnum
= c
->lpt_last
+ 1;
393 pack_bits(&addr
, &pos
, lnum
- c
->lpt_first
, c
->lpt_lnum_bits
);
394 pack_bits(&addr
, &pos
, nnode
->nbranch
[i
].offs
,
397 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
398 c
->nnode_sz
- UBIFS_LPT_CRC_BYTES
);
401 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
405 * ubifs_pack_ltab - pack the LPT's own lprops table.
406 * @c: UBIFS file-system description object
407 * @buf: buffer into which to pack
408 * @ltab: LPT's own lprops table to pack
410 void ubifs_pack_ltab(struct ubifs_info
*c
, void *buf
,
411 struct ubifs_lpt_lprops
*ltab
)
413 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
417 pack_bits(&addr
, &pos
, UBIFS_LPT_LTAB
, UBIFS_LPT_TYPE_BITS
);
418 for (i
= 0; i
< c
->lpt_lebs
; i
++) {
419 pack_bits(&addr
, &pos
, ltab
[i
].free
, c
->lpt_spc_bits
);
420 pack_bits(&addr
, &pos
, ltab
[i
].dirty
, c
->lpt_spc_bits
);
422 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
423 c
->ltab_sz
- UBIFS_LPT_CRC_BYTES
);
426 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
430 * ubifs_pack_lsave - pack the LPT's save table.
431 * @c: UBIFS file-system description object
432 * @buf: buffer into which to pack
433 * @lsave: LPT's save table to pack
435 void ubifs_pack_lsave(struct ubifs_info
*c
, void *buf
, int *lsave
)
437 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
441 pack_bits(&addr
, &pos
, UBIFS_LPT_LSAVE
, UBIFS_LPT_TYPE_BITS
);
442 for (i
= 0; i
< c
->lsave_cnt
; i
++)
443 pack_bits(&addr
, &pos
, lsave
[i
], c
->lnum_bits
);
444 crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
445 c
->lsave_sz
- UBIFS_LPT_CRC_BYTES
);
448 pack_bits(&addr
, &pos
, crc
, UBIFS_LPT_CRC_BITS
);
452 * ubifs_add_lpt_dirt - add dirty space to LPT LEB properties.
453 * @c: UBIFS file-system description object
454 * @lnum: LEB number to which to add dirty space
455 * @dirty: amount of dirty space to add
457 void ubifs_add_lpt_dirt(struct ubifs_info
*c
, int lnum
, int dirty
)
461 dbg_lp("LEB %d add %d to %d",
462 lnum
, dirty
, c
->ltab
[lnum
- c
->lpt_first
].dirty
);
463 ubifs_assert(lnum
>= c
->lpt_first
&& lnum
<= c
->lpt_last
);
464 c
->ltab
[lnum
- c
->lpt_first
].dirty
+= dirty
;
468 * set_ltab - set LPT LEB properties.
469 * @c: UBIFS file-system description object
471 * @free: amount of free space
472 * @dirty: amount of dirty space
474 static void set_ltab(struct ubifs_info
*c
, int lnum
, int free
, int dirty
)
476 dbg_lp("LEB %d free %d dirty %d to %d %d",
477 lnum
, c
->ltab
[lnum
- c
->lpt_first
].free
,
478 c
->ltab
[lnum
- c
->lpt_first
].dirty
, free
, dirty
);
479 ubifs_assert(lnum
>= c
->lpt_first
&& lnum
<= c
->lpt_last
);
480 c
->ltab
[lnum
- c
->lpt_first
].free
= free
;
481 c
->ltab
[lnum
- c
->lpt_first
].dirty
= dirty
;
485 * ubifs_add_nnode_dirt - add dirty space to LPT LEB properties.
486 * @c: UBIFS file-system description object
487 * @nnode: nnode for which to add dirt
489 void ubifs_add_nnode_dirt(struct ubifs_info
*c
, struct ubifs_nnode
*nnode
)
491 struct ubifs_nnode
*np
= nnode
->parent
;
494 ubifs_add_lpt_dirt(c
, np
->nbranch
[nnode
->iip
].lnum
,
497 ubifs_add_lpt_dirt(c
, c
->lpt_lnum
, c
->nnode_sz
);
498 if (!(c
->lpt_drty_flgs
& LTAB_DIRTY
)) {
499 c
->lpt_drty_flgs
|= LTAB_DIRTY
;
500 ubifs_add_lpt_dirt(c
, c
->ltab_lnum
, c
->ltab_sz
);
506 * add_pnode_dirt - add dirty space to LPT LEB properties.
507 * @c: UBIFS file-system description object
508 * @pnode: pnode for which to add dirt
510 static void add_pnode_dirt(struct ubifs_info
*c
, struct ubifs_pnode
*pnode
)
512 ubifs_add_lpt_dirt(c
, pnode
->parent
->nbranch
[pnode
->iip
].lnum
,
517 * calc_nnode_num - calculate nnode number.
518 * @row: the row in the tree (root is zero)
519 * @col: the column in the row (leftmost is zero)
521 * The nnode number is a number that uniquely identifies a nnode and can be used
522 * easily to traverse the tree from the root to that nnode.
524 * This function calculates and returns the nnode number for the nnode at @row
527 static int calc_nnode_num(int row
, int col
)
533 bits
= (col
& (UBIFS_LPT_FANOUT
- 1));
534 col
>>= UBIFS_LPT_FANOUT_SHIFT
;
535 num
<<= UBIFS_LPT_FANOUT_SHIFT
;
542 * calc_nnode_num_from_parent - calculate nnode number.
543 * @c: UBIFS file-system description object
544 * @parent: parent nnode
545 * @iip: index in parent
547 * The nnode number is a number that uniquely identifies a nnode and can be used
548 * easily to traverse the tree from the root to that nnode.
550 * This function calculates and returns the nnode number based on the parent's
551 * nnode number and the index in parent.
553 static int calc_nnode_num_from_parent(const struct ubifs_info
*c
,
554 struct ubifs_nnode
*parent
, int iip
)
560 shft
= (c
->lpt_hght
- parent
->level
) * UBIFS_LPT_FANOUT_SHIFT
;
561 num
= parent
->num
^ (1 << shft
);
562 num
|= (UBIFS_LPT_FANOUT
+ iip
) << shft
;
567 * calc_pnode_num_from_parent - calculate pnode number.
568 * @c: UBIFS file-system description object
569 * @parent: parent nnode
570 * @iip: index in parent
572 * The pnode number is a number that uniquely identifies a pnode and can be used
573 * easily to traverse the tree from the root to that pnode.
575 * This function calculates and returns the pnode number based on the parent's
576 * nnode number and the index in parent.
578 static int calc_pnode_num_from_parent(const struct ubifs_info
*c
,
579 struct ubifs_nnode
*parent
, int iip
)
581 int i
, n
= c
->lpt_hght
- 1, pnum
= parent
->num
, num
= 0;
583 for (i
= 0; i
< n
; i
++) {
584 num
<<= UBIFS_LPT_FANOUT_SHIFT
;
585 num
|= pnum
& (UBIFS_LPT_FANOUT
- 1);
586 pnum
>>= UBIFS_LPT_FANOUT_SHIFT
;
588 num
<<= UBIFS_LPT_FANOUT_SHIFT
;
594 * ubifs_create_dflt_lpt - create default LPT.
595 * @c: UBIFS file-system description object
596 * @main_lebs: number of main area LEBs is passed and returned here
597 * @lpt_first: LEB number of first LPT LEB
598 * @lpt_lebs: number of LEBs for LPT is passed and returned here
599 * @big_lpt: use big LPT model is passed and returned here
601 * This function returns %0 on success and a negative error code on failure.
603 int ubifs_create_dflt_lpt(struct ubifs_info
*c
, int *main_lebs
, int lpt_first
,
604 int *lpt_lebs
, int *big_lpt
)
606 int lnum
, err
= 0, node_sz
, iopos
, i
, j
, cnt
, len
, alen
, row
;
607 int blnum
, boffs
, bsz
, bcnt
;
608 struct ubifs_pnode
*pnode
= NULL
;
609 struct ubifs_nnode
*nnode
= NULL
;
610 void *buf
= NULL
, *p
;
611 struct ubifs_lpt_lprops
*ltab
= NULL
;
614 err
= calc_dflt_lpt_geom(c
, main_lebs
, big_lpt
);
617 *lpt_lebs
= c
->lpt_lebs
;
619 /* Needed by 'ubifs_pack_nnode()' and 'set_ltab()' */
620 c
->lpt_first
= lpt_first
;
621 /* Needed by 'set_ltab()' */
622 c
->lpt_last
= lpt_first
+ c
->lpt_lebs
- 1;
623 /* Needed by 'ubifs_pack_lsave()' */
624 c
->main_first
= c
->leb_cnt
- *main_lebs
;
626 lsave
= kmalloc(sizeof(int) * c
->lsave_cnt
, GFP_KERNEL
);
627 pnode
= kzalloc(sizeof(struct ubifs_pnode
), GFP_KERNEL
);
628 nnode
= kzalloc(sizeof(struct ubifs_nnode
), GFP_KERNEL
);
629 buf
= vmalloc(c
->leb_size
);
630 ltab
= vmalloc(sizeof(struct ubifs_lpt_lprops
) * c
->lpt_lebs
);
631 if (!pnode
|| !nnode
|| !buf
|| !ltab
|| !lsave
) {
636 ubifs_assert(!c
->ltab
);
637 c
->ltab
= ltab
; /* Needed by set_ltab */
639 /* Initialize LPT's own lprops */
640 for (i
= 0; i
< c
->lpt_lebs
; i
++) {
641 ltab
[i
].free
= c
->leb_size
;
649 /* Number of leaf nodes (pnodes) */
653 * The first pnode contains the LEB properties for the LEBs that contain
654 * the root inode node and the root index node of the index tree.
656 node_sz
= ALIGN(ubifs_idx_node_sz(c
, 1), 8);
657 iopos
= ALIGN(node_sz
, c
->min_io_size
);
658 pnode
->lprops
[0].free
= c
->leb_size
- iopos
;
659 pnode
->lprops
[0].dirty
= iopos
- node_sz
;
660 pnode
->lprops
[0].flags
= LPROPS_INDEX
;
662 node_sz
= UBIFS_INO_NODE_SZ
;
663 iopos
= ALIGN(node_sz
, c
->min_io_size
);
664 pnode
->lprops
[1].free
= c
->leb_size
- iopos
;
665 pnode
->lprops
[1].dirty
= iopos
- node_sz
;
667 for (i
= 2; i
< UBIFS_LPT_FANOUT
; i
++)
668 pnode
->lprops
[i
].free
= c
->leb_size
;
670 /* Add first pnode */
671 ubifs_pack_pnode(c
, p
, pnode
);
676 /* Reset pnode values for remaining pnodes */
677 pnode
->lprops
[0].free
= c
->leb_size
;
678 pnode
->lprops
[0].dirty
= 0;
679 pnode
->lprops
[0].flags
= 0;
681 pnode
->lprops
[1].free
= c
->leb_size
;
682 pnode
->lprops
[1].dirty
= 0;
685 * To calculate the internal node branches, we keep information about
688 blnum
= lnum
; /* LEB number of level below */
689 boffs
= 0; /* Offset of level below */
690 bcnt
= cnt
; /* Number of nodes in level below */
691 bsz
= c
->pnode_sz
; /* Size of nodes in level below */
693 /* Add all remaining pnodes */
694 for (i
= 1; i
< cnt
; i
++) {
695 if (len
+ c
->pnode_sz
> c
->leb_size
) {
696 alen
= ALIGN(len
, c
->min_io_size
);
697 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
698 memset(p
, 0xff, alen
- len
);
699 err
= ubifs_leb_change(c
, lnum
++, buf
, alen
);
705 ubifs_pack_pnode(c
, p
, pnode
);
709 * pnodes are simply numbered left to right starting at zero,
710 * which means the pnode number can be used easily to traverse
711 * down the tree to the corresponding pnode.
717 for (i
= UBIFS_LPT_FANOUT
; cnt
> i
; i
<<= UBIFS_LPT_FANOUT_SHIFT
)
719 /* Add all nnodes, one level at a time */
721 /* Number of internal nodes (nnodes) at next level */
722 cnt
= DIV_ROUND_UP(cnt
, UBIFS_LPT_FANOUT
);
723 for (i
= 0; i
< cnt
; i
++) {
724 if (len
+ c
->nnode_sz
> c
->leb_size
) {
725 alen
= ALIGN(len
, c
->min_io_size
);
726 set_ltab(c
, lnum
, c
->leb_size
- alen
,
728 memset(p
, 0xff, alen
- len
);
729 err
= ubifs_leb_change(c
, lnum
++, buf
, alen
);
735 /* Only 1 nnode at this level, so it is the root */
740 /* Set branches to the level below */
741 for (j
= 0; j
< UBIFS_LPT_FANOUT
; j
++) {
743 if (boffs
+ bsz
> c
->leb_size
) {
747 nnode
->nbranch
[j
].lnum
= blnum
;
748 nnode
->nbranch
[j
].offs
= boffs
;
752 nnode
->nbranch
[j
].lnum
= 0;
753 nnode
->nbranch
[j
].offs
= 0;
756 nnode
->num
= calc_nnode_num(row
, i
);
757 ubifs_pack_nnode(c
, p
, nnode
);
761 /* Only 1 nnode at this level, so it is the root */
764 /* Update the information about the level below */
771 /* Need to add LPT's save table */
772 if (len
+ c
->lsave_sz
> c
->leb_size
) {
773 alen
= ALIGN(len
, c
->min_io_size
);
774 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
775 memset(p
, 0xff, alen
- len
);
776 err
= ubifs_leb_change(c
, lnum
++, buf
, alen
);
783 c
->lsave_lnum
= lnum
;
786 for (i
= 0; i
< c
->lsave_cnt
&& i
< *main_lebs
; i
++)
787 lsave
[i
] = c
->main_first
+ i
;
788 for (; i
< c
->lsave_cnt
; i
++)
789 lsave
[i
] = c
->main_first
;
791 ubifs_pack_lsave(c
, p
, lsave
);
796 /* Need to add LPT's own LEB properties table */
797 if (len
+ c
->ltab_sz
> c
->leb_size
) {
798 alen
= ALIGN(len
, c
->min_io_size
);
799 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
800 memset(p
, 0xff, alen
- len
);
801 err
= ubifs_leb_change(c
, lnum
++, buf
, alen
);
811 /* Update ltab before packing it */
813 alen
= ALIGN(len
, c
->min_io_size
);
814 set_ltab(c
, lnum
, c
->leb_size
- alen
, alen
- len
);
816 ubifs_pack_ltab(c
, p
, ltab
);
819 /* Write remaining buffer */
820 memset(p
, 0xff, alen
- len
);
821 err
= ubifs_leb_change(c
, lnum
, buf
, alen
);
825 c
->nhead_lnum
= lnum
;
826 c
->nhead_offs
= ALIGN(len
, c
->min_io_size
);
828 dbg_lp("space_bits %d", c
->space_bits
);
829 dbg_lp("lpt_lnum_bits %d", c
->lpt_lnum_bits
);
830 dbg_lp("lpt_offs_bits %d", c
->lpt_offs_bits
);
831 dbg_lp("lpt_spc_bits %d", c
->lpt_spc_bits
);
832 dbg_lp("pcnt_bits %d", c
->pcnt_bits
);
833 dbg_lp("lnum_bits %d", c
->lnum_bits
);
834 dbg_lp("pnode_sz %d", c
->pnode_sz
);
835 dbg_lp("nnode_sz %d", c
->nnode_sz
);
836 dbg_lp("ltab_sz %d", c
->ltab_sz
);
837 dbg_lp("lsave_sz %d", c
->lsave_sz
);
838 dbg_lp("lsave_cnt %d", c
->lsave_cnt
);
839 dbg_lp("lpt_hght %d", c
->lpt_hght
);
840 dbg_lp("big_lpt %d", c
->big_lpt
);
841 dbg_lp("LPT root is at %d:%d", c
->lpt_lnum
, c
->lpt_offs
);
842 dbg_lp("LPT head is at %d:%d", c
->nhead_lnum
, c
->nhead_offs
);
843 dbg_lp("LPT ltab is at %d:%d", c
->ltab_lnum
, c
->ltab_offs
);
845 dbg_lp("LPT lsave is at %d:%d", c
->lsave_lnum
, c
->lsave_offs
);
857 * update_cats - add LEB properties of a pnode to LEB category lists and heaps.
858 * @c: UBIFS file-system description object
861 * When a pnode is loaded into memory, the LEB properties it contains are added,
862 * by this function, to the LEB category lists and heaps.
864 static void update_cats(struct ubifs_info
*c
, struct ubifs_pnode
*pnode
)
868 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
869 int cat
= pnode
->lprops
[i
].flags
& LPROPS_CAT_MASK
;
870 int lnum
= pnode
->lprops
[i
].lnum
;
874 ubifs_add_to_cat(c
, &pnode
->lprops
[i
], cat
);
879 * replace_cats - add LEB properties of a pnode to LEB category lists and heaps.
880 * @c: UBIFS file-system description object
881 * @old_pnode: pnode copied
882 * @new_pnode: pnode copy
884 * During commit it is sometimes necessary to copy a pnode
885 * (see dirty_cow_pnode). When that happens, references in
886 * category lists and heaps must be replaced. This function does that.
888 static void replace_cats(struct ubifs_info
*c
, struct ubifs_pnode
*old_pnode
,
889 struct ubifs_pnode
*new_pnode
)
893 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
894 if (!new_pnode
->lprops
[i
].lnum
)
896 ubifs_replace_cat(c
, &old_pnode
->lprops
[i
],
897 &new_pnode
->lprops
[i
]);
902 * check_lpt_crc - check LPT node crc is correct.
903 * @c: UBIFS file-system description object
904 * @buf: buffer containing node
905 * @len: length of node
907 * This function returns %0 on success and a negative error code on failure.
909 static int check_lpt_crc(const struct ubifs_info
*c
, void *buf
, int len
)
913 uint16_t crc
, calc_crc
;
915 crc
= ubifs_unpack_bits(&addr
, &pos
, UBIFS_LPT_CRC_BITS
);
916 calc_crc
= crc16(-1, buf
+ UBIFS_LPT_CRC_BYTES
,
917 len
- UBIFS_LPT_CRC_BYTES
);
918 if (crc
!= calc_crc
) {
919 ubifs_err(c
, "invalid crc in LPT node: crc %hx calc %hx",
928 * check_lpt_type - check LPT node type is correct.
929 * @c: UBIFS file-system description object
930 * @addr: address of type bit field is passed and returned updated here
931 * @pos: position of type bit field is passed and returned updated here
932 * @type: expected type
934 * This function returns %0 on success and a negative error code on failure.
936 static int check_lpt_type(const struct ubifs_info
*c
, uint8_t **addr
,
941 node_type
= ubifs_unpack_bits(addr
, pos
, UBIFS_LPT_TYPE_BITS
);
942 if (node_type
!= type
) {
943 ubifs_err(c
, "invalid type (%d) in LPT node type %d",
952 * unpack_pnode - unpack a pnode.
953 * @c: UBIFS file-system description object
954 * @buf: buffer containing packed pnode to unpack
955 * @pnode: pnode structure to fill
957 * This function returns %0 on success and a negative error code on failure.
959 static int unpack_pnode(const struct ubifs_info
*c
, void *buf
,
960 struct ubifs_pnode
*pnode
)
962 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
965 err
= check_lpt_type(c
, &addr
, &pos
, UBIFS_LPT_PNODE
);
969 pnode
->num
= ubifs_unpack_bits(&addr
, &pos
, c
->pcnt_bits
);
970 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
971 struct ubifs_lprops
* const lprops
= &pnode
->lprops
[i
];
973 lprops
->free
= ubifs_unpack_bits(&addr
, &pos
, c
->space_bits
);
975 lprops
->dirty
= ubifs_unpack_bits(&addr
, &pos
, c
->space_bits
);
978 if (ubifs_unpack_bits(&addr
, &pos
, 1))
979 lprops
->flags
= LPROPS_INDEX
;
982 lprops
->flags
|= ubifs_categorize_lprops(c
, lprops
);
984 err
= check_lpt_crc(c
, buf
, c
->pnode_sz
);
989 * ubifs_unpack_nnode - unpack a nnode.
990 * @c: UBIFS file-system description object
991 * @buf: buffer containing packed nnode to unpack
992 * @nnode: nnode structure to fill
994 * This function returns %0 on success and a negative error code on failure.
996 int ubifs_unpack_nnode(const struct ubifs_info
*c
, void *buf
,
997 struct ubifs_nnode
*nnode
)
999 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
1000 int i
, pos
= 0, err
;
1002 err
= check_lpt_type(c
, &addr
, &pos
, UBIFS_LPT_NNODE
);
1006 nnode
->num
= ubifs_unpack_bits(&addr
, &pos
, c
->pcnt_bits
);
1007 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1010 lnum
= ubifs_unpack_bits(&addr
, &pos
, c
->lpt_lnum_bits
) +
1012 if (lnum
== c
->lpt_last
+ 1)
1014 nnode
->nbranch
[i
].lnum
= lnum
;
1015 nnode
->nbranch
[i
].offs
= ubifs_unpack_bits(&addr
, &pos
,
1018 err
= check_lpt_crc(c
, buf
, c
->nnode_sz
);
1023 * unpack_ltab - unpack the LPT's own lprops table.
1024 * @c: UBIFS file-system description object
1025 * @buf: buffer from which to unpack
1027 * This function returns %0 on success and a negative error code on failure.
1029 static int unpack_ltab(const struct ubifs_info
*c
, void *buf
)
1031 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
1032 int i
, pos
= 0, err
;
1034 err
= check_lpt_type(c
, &addr
, &pos
, UBIFS_LPT_LTAB
);
1037 for (i
= 0; i
< c
->lpt_lebs
; i
++) {
1038 int free
= ubifs_unpack_bits(&addr
, &pos
, c
->lpt_spc_bits
);
1039 int dirty
= ubifs_unpack_bits(&addr
, &pos
, c
->lpt_spc_bits
);
1041 if (free
< 0 || free
> c
->leb_size
|| dirty
< 0 ||
1042 dirty
> c
->leb_size
|| free
+ dirty
> c
->leb_size
)
1045 c
->ltab
[i
].free
= free
;
1046 c
->ltab
[i
].dirty
= dirty
;
1050 err
= check_lpt_crc(c
, buf
, c
->ltab_sz
);
1056 * unpack_lsave - unpack the LPT's save table.
1057 * @c: UBIFS file-system description object
1058 * @buf: buffer from which to unpack
1060 * This function returns %0 on success and a negative error code on failure.
1062 static int unpack_lsave(const struct ubifs_info
*c
, void *buf
)
1064 uint8_t *addr
= buf
+ UBIFS_LPT_CRC_BYTES
;
1065 int i
, pos
= 0, err
;
1067 err
= check_lpt_type(c
, &addr
, &pos
, UBIFS_LPT_LSAVE
);
1070 for (i
= 0; i
< c
->lsave_cnt
; i
++) {
1071 int lnum
= ubifs_unpack_bits(&addr
, &pos
, c
->lnum_bits
);
1073 if (lnum
< c
->main_first
|| lnum
>= c
->leb_cnt
)
1077 err
= check_lpt_crc(c
, buf
, c
->lsave_sz
);
1083 * validate_nnode - validate a nnode.
1084 * @c: UBIFS file-system description object
1085 * @nnode: nnode to validate
1086 * @parent: parent nnode (or NULL for the root nnode)
1087 * @iip: index in parent
1089 * This function returns %0 on success and a negative error code on failure.
1091 static int validate_nnode(const struct ubifs_info
*c
, struct ubifs_nnode
*nnode
,
1092 struct ubifs_nnode
*parent
, int iip
)
1094 int i
, lvl
, max_offs
;
1097 int num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1099 if (nnode
->num
!= num
)
1102 lvl
= parent
? parent
->level
- 1 : c
->lpt_hght
;
1106 max_offs
= c
->leb_size
- c
->pnode_sz
;
1108 max_offs
= c
->leb_size
- c
->nnode_sz
;
1109 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1110 int lnum
= nnode
->nbranch
[i
].lnum
;
1111 int offs
= nnode
->nbranch
[i
].offs
;
1118 if (lnum
< c
->lpt_first
|| lnum
> c
->lpt_last
)
1120 if (offs
< 0 || offs
> max_offs
)
1127 * validate_pnode - validate a pnode.
1128 * @c: UBIFS file-system description object
1129 * @pnode: pnode to validate
1130 * @parent: parent nnode
1131 * @iip: index in parent
1133 * This function returns %0 on success and a negative error code on failure.
1135 static int validate_pnode(const struct ubifs_info
*c
, struct ubifs_pnode
*pnode
,
1136 struct ubifs_nnode
*parent
, int iip
)
1141 int num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1143 if (pnode
->num
!= num
)
1146 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1147 int free
= pnode
->lprops
[i
].free
;
1148 int dirty
= pnode
->lprops
[i
].dirty
;
1150 if (free
< 0 || free
> c
->leb_size
|| free
% c
->min_io_size
||
1153 if (dirty
< 0 || dirty
> c
->leb_size
|| (dirty
& 7))
1155 if (dirty
+ free
> c
->leb_size
)
1162 * set_pnode_lnum - set LEB numbers on a pnode.
1163 * @c: UBIFS file-system description object
1164 * @pnode: pnode to update
1166 * This function calculates the LEB numbers for the LEB properties it contains
1167 * based on the pnode number.
1169 static void set_pnode_lnum(const struct ubifs_info
*c
,
1170 struct ubifs_pnode
*pnode
)
1174 lnum
= (pnode
->num
<< UBIFS_LPT_FANOUT_SHIFT
) + c
->main_first
;
1175 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1176 if (lnum
>= c
->leb_cnt
)
1178 pnode
->lprops
[i
].lnum
= lnum
++;
1183 * ubifs_read_nnode - read a nnode from flash and link it to the tree in memory.
1184 * @c: UBIFS file-system description object
1185 * @parent: parent nnode (or NULL for the root)
1186 * @iip: index in parent
1188 * This function returns %0 on success and a negative error code on failure.
1190 int ubifs_read_nnode(struct ubifs_info
*c
, struct ubifs_nnode
*parent
, int iip
)
1192 struct ubifs_nbranch
*branch
= NULL
;
1193 struct ubifs_nnode
*nnode
= NULL
;
1194 void *buf
= c
->lpt_nod_buf
;
1195 int err
, lnum
, offs
;
1198 branch
= &parent
->nbranch
[iip
];
1199 lnum
= branch
->lnum
;
1200 offs
= branch
->offs
;
1205 nnode
= kzalloc(sizeof(struct ubifs_nnode
), GFP_NOFS
);
1212 * This nnode was not written which just means that the LEB
1213 * properties in the subtree below it describe empty LEBs. We
1214 * make the nnode as though we had read it, which in fact means
1215 * doing almost nothing.
1218 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1220 err
= ubifs_leb_read(c
, lnum
, buf
, offs
, c
->nnode_sz
, 1);
1223 err
= ubifs_unpack_nnode(c
, buf
, nnode
);
1227 err
= validate_nnode(c
, nnode
, parent
, iip
);
1231 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1233 branch
->nnode
= nnode
;
1234 nnode
->level
= parent
->level
- 1;
1237 nnode
->level
= c
->lpt_hght
;
1239 nnode
->parent
= parent
;
1244 ubifs_err(c
, "error %d reading nnode at %d:%d", err
, lnum
, offs
);
1251 * read_pnode - read a pnode from flash and link it to the tree in memory.
1252 * @c: UBIFS file-system description object
1253 * @parent: parent nnode
1254 * @iip: index in parent
1256 * This function returns %0 on success and a negative error code on failure.
1258 static int read_pnode(struct ubifs_info
*c
, struct ubifs_nnode
*parent
, int iip
)
1260 struct ubifs_nbranch
*branch
;
1261 struct ubifs_pnode
*pnode
= NULL
;
1262 void *buf
= c
->lpt_nod_buf
;
1263 int err
, lnum
, offs
;
1265 branch
= &parent
->nbranch
[iip
];
1266 lnum
= branch
->lnum
;
1267 offs
= branch
->offs
;
1268 pnode
= kzalloc(sizeof(struct ubifs_pnode
), GFP_NOFS
);
1274 * This pnode was not written which just means that the LEB
1275 * properties in it describe empty LEBs. We make the pnode as
1276 * though we had read it.
1281 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1282 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1283 struct ubifs_lprops
* const lprops
= &pnode
->lprops
[i
];
1285 lprops
->free
= c
->leb_size
;
1286 lprops
->flags
= ubifs_categorize_lprops(c
, lprops
);
1289 err
= ubifs_leb_read(c
, lnum
, buf
, offs
, c
->pnode_sz
, 1);
1292 err
= unpack_pnode(c
, buf
, pnode
);
1296 err
= validate_pnode(c
, pnode
, parent
, iip
);
1300 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1301 branch
->pnode
= pnode
;
1302 pnode
->parent
= parent
;
1304 set_pnode_lnum(c
, pnode
);
1305 c
->pnodes_have
+= 1;
1309 ubifs_err(c
, "error %d reading pnode at %d:%d", err
, lnum
, offs
);
1310 ubifs_dump_pnode(c
, pnode
, parent
, iip
);
1312 ubifs_err(c
, "calc num: %d", calc_pnode_num_from_parent(c
, parent
, iip
));
1318 * read_ltab - read LPT's own lprops table.
1319 * @c: UBIFS file-system description object
1321 * This function returns %0 on success and a negative error code on failure.
1323 static int read_ltab(struct ubifs_info
*c
)
1328 buf
= vmalloc(c
->ltab_sz
);
1331 err
= ubifs_leb_read(c
, c
->ltab_lnum
, buf
, c
->ltab_offs
, c
->ltab_sz
, 1);
1334 err
= unpack_ltab(c
, buf
);
1342 * read_lsave - read LPT's save table.
1343 * @c: UBIFS file-system description object
1345 * This function returns %0 on success and a negative error code on failure.
1347 static int read_lsave(struct ubifs_info
*c
)
1352 buf
= vmalloc(c
->lsave_sz
);
1355 err
= ubifs_leb_read(c
, c
->lsave_lnum
, buf
, c
->lsave_offs
,
1359 err
= unpack_lsave(c
, buf
);
1362 for (i
= 0; i
< c
->lsave_cnt
; i
++) {
1363 int lnum
= c
->lsave
[i
];
1364 struct ubifs_lprops
*lprops
;
1367 * Due to automatic resizing, the values in the lsave table
1368 * could be beyond the volume size - just ignore them.
1370 if (lnum
>= c
->leb_cnt
)
1372 lprops
= ubifs_lpt_lookup(c
, lnum
);
1373 if (IS_ERR(lprops
)) {
1374 err
= PTR_ERR(lprops
);
1385 * ubifs_get_nnode - get a nnode.
1386 * @c: UBIFS file-system description object
1387 * @parent: parent nnode (or NULL for the root)
1388 * @iip: index in parent
1390 * This function returns a pointer to the nnode on success or a negative error
1393 struct ubifs_nnode
*ubifs_get_nnode(struct ubifs_info
*c
,
1394 struct ubifs_nnode
*parent
, int iip
)
1396 struct ubifs_nbranch
*branch
;
1397 struct ubifs_nnode
*nnode
;
1400 branch
= &parent
->nbranch
[iip
];
1401 nnode
= branch
->nnode
;
1404 err
= ubifs_read_nnode(c
, parent
, iip
);
1406 return ERR_PTR(err
);
1407 return branch
->nnode
;
1411 * ubifs_get_pnode - get a pnode.
1412 * @c: UBIFS file-system description object
1413 * @parent: parent nnode
1414 * @iip: index in parent
1416 * This function returns a pointer to the pnode on success or a negative error
1419 struct ubifs_pnode
*ubifs_get_pnode(struct ubifs_info
*c
,
1420 struct ubifs_nnode
*parent
, int iip
)
1422 struct ubifs_nbranch
*branch
;
1423 struct ubifs_pnode
*pnode
;
1426 branch
= &parent
->nbranch
[iip
];
1427 pnode
= branch
->pnode
;
1430 err
= read_pnode(c
, parent
, iip
);
1432 return ERR_PTR(err
);
1433 update_cats(c
, branch
->pnode
);
1434 return branch
->pnode
;
1438 * ubifs_lpt_lookup - lookup LEB properties in the LPT.
1439 * @c: UBIFS file-system description object
1440 * @lnum: LEB number to lookup
1442 * This function returns a pointer to the LEB properties on success or a
1443 * negative error code on failure.
1445 struct ubifs_lprops
*ubifs_lpt_lookup(struct ubifs_info
*c
, int lnum
)
1447 int err
, i
, h
, iip
, shft
;
1448 struct ubifs_nnode
*nnode
;
1449 struct ubifs_pnode
*pnode
;
1452 err
= ubifs_read_nnode(c
, NULL
, 0);
1454 return ERR_PTR(err
);
1457 i
= lnum
- c
->main_first
;
1458 shft
= c
->lpt_hght
* UBIFS_LPT_FANOUT_SHIFT
;
1459 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1460 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1461 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1462 nnode
= ubifs_get_nnode(c
, nnode
, iip
);
1464 return ERR_CAST(nnode
);
1466 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1467 pnode
= ubifs_get_pnode(c
, nnode
, iip
);
1469 return ERR_CAST(pnode
);
1470 iip
= (i
& (UBIFS_LPT_FANOUT
- 1));
1471 dbg_lp("LEB %d, free %d, dirty %d, flags %d", lnum
,
1472 pnode
->lprops
[iip
].free
, pnode
->lprops
[iip
].dirty
,
1473 pnode
->lprops
[iip
].flags
);
1474 return &pnode
->lprops
[iip
];
1478 * dirty_cow_nnode - ensure a nnode is not being committed.
1479 * @c: UBIFS file-system description object
1480 * @nnode: nnode to check
1482 * Returns dirtied nnode on success or negative error code on failure.
1484 static struct ubifs_nnode
*dirty_cow_nnode(struct ubifs_info
*c
,
1485 struct ubifs_nnode
*nnode
)
1487 struct ubifs_nnode
*n
;
1490 if (!test_bit(COW_CNODE
, &nnode
->flags
)) {
1491 /* nnode is not being committed */
1492 if (!test_and_set_bit(DIRTY_CNODE
, &nnode
->flags
)) {
1493 c
->dirty_nn_cnt
+= 1;
1494 ubifs_add_nnode_dirt(c
, nnode
);
1499 /* nnode is being committed, so copy it */
1500 n
= kmalloc(sizeof(struct ubifs_nnode
), GFP_NOFS
);
1502 return ERR_PTR(-ENOMEM
);
1504 memcpy(n
, nnode
, sizeof(struct ubifs_nnode
));
1506 __set_bit(DIRTY_CNODE
, &n
->flags
);
1507 __clear_bit(COW_CNODE
, &n
->flags
);
1509 /* The children now have new parent */
1510 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1511 struct ubifs_nbranch
*branch
= &n
->nbranch
[i
];
1514 branch
->cnode
->parent
= n
;
1517 ubifs_assert(!test_bit(OBSOLETE_CNODE
, &nnode
->flags
));
1518 __set_bit(OBSOLETE_CNODE
, &nnode
->flags
);
1520 c
->dirty_nn_cnt
+= 1;
1521 ubifs_add_nnode_dirt(c
, nnode
);
1523 nnode
->parent
->nbranch
[n
->iip
].nnode
= n
;
1530 * dirty_cow_pnode - ensure a pnode is not being committed.
1531 * @c: UBIFS file-system description object
1532 * @pnode: pnode to check
1534 * Returns dirtied pnode on success or negative error code on failure.
1536 static struct ubifs_pnode
*dirty_cow_pnode(struct ubifs_info
*c
,
1537 struct ubifs_pnode
*pnode
)
1539 struct ubifs_pnode
*p
;
1541 if (!test_bit(COW_CNODE
, &pnode
->flags
)) {
1542 /* pnode is not being committed */
1543 if (!test_and_set_bit(DIRTY_CNODE
, &pnode
->flags
)) {
1544 c
->dirty_pn_cnt
+= 1;
1545 add_pnode_dirt(c
, pnode
);
1550 /* pnode is being committed, so copy it */
1551 p
= kmalloc(sizeof(struct ubifs_pnode
), GFP_NOFS
);
1553 return ERR_PTR(-ENOMEM
);
1555 memcpy(p
, pnode
, sizeof(struct ubifs_pnode
));
1557 __set_bit(DIRTY_CNODE
, &p
->flags
);
1558 __clear_bit(COW_CNODE
, &p
->flags
);
1559 replace_cats(c
, pnode
, p
);
1561 ubifs_assert(!test_bit(OBSOLETE_CNODE
, &pnode
->flags
));
1562 __set_bit(OBSOLETE_CNODE
, &pnode
->flags
);
1564 c
->dirty_pn_cnt
+= 1;
1565 add_pnode_dirt(c
, pnode
);
1566 pnode
->parent
->nbranch
[p
->iip
].pnode
= p
;
1571 * ubifs_lpt_lookup_dirty - lookup LEB properties in the LPT.
1572 * @c: UBIFS file-system description object
1573 * @lnum: LEB number to lookup
1575 * This function returns a pointer to the LEB properties on success or a
1576 * negative error code on failure.
1578 struct ubifs_lprops
*ubifs_lpt_lookup_dirty(struct ubifs_info
*c
, int lnum
)
1580 int err
, i
, h
, iip
, shft
;
1581 struct ubifs_nnode
*nnode
;
1582 struct ubifs_pnode
*pnode
;
1585 err
= ubifs_read_nnode(c
, NULL
, 0);
1587 return ERR_PTR(err
);
1590 nnode
= dirty_cow_nnode(c
, nnode
);
1592 return ERR_CAST(nnode
);
1593 i
= lnum
- c
->main_first
;
1594 shft
= c
->lpt_hght
* UBIFS_LPT_FANOUT_SHIFT
;
1595 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1596 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1597 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1598 nnode
= ubifs_get_nnode(c
, nnode
, iip
);
1600 return ERR_CAST(nnode
);
1601 nnode
= dirty_cow_nnode(c
, nnode
);
1603 return ERR_CAST(nnode
);
1605 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1606 pnode
= ubifs_get_pnode(c
, nnode
, iip
);
1608 return ERR_CAST(pnode
);
1609 pnode
= dirty_cow_pnode(c
, pnode
);
1611 return ERR_CAST(pnode
);
1612 iip
= (i
& (UBIFS_LPT_FANOUT
- 1));
1613 dbg_lp("LEB %d, free %d, dirty %d, flags %d", lnum
,
1614 pnode
->lprops
[iip
].free
, pnode
->lprops
[iip
].dirty
,
1615 pnode
->lprops
[iip
].flags
);
1616 ubifs_assert(test_bit(DIRTY_CNODE
, &pnode
->flags
));
1617 return &pnode
->lprops
[iip
];
1621 * lpt_init_rd - initialize the LPT for reading.
1622 * @c: UBIFS file-system description object
1624 * This function returns %0 on success and a negative error code on failure.
1626 static int lpt_init_rd(struct ubifs_info
*c
)
1630 c
->ltab
= vmalloc(sizeof(struct ubifs_lpt_lprops
) * c
->lpt_lebs
);
1634 i
= max_t(int, c
->nnode_sz
, c
->pnode_sz
);
1635 c
->lpt_nod_buf
= kmalloc(i
, GFP_KERNEL
);
1636 if (!c
->lpt_nod_buf
)
1639 for (i
= 0; i
< LPROPS_HEAP_CNT
; i
++) {
1640 c
->lpt_heap
[i
].arr
= kmalloc(sizeof(void *) * LPT_HEAP_SZ
,
1642 if (!c
->lpt_heap
[i
].arr
)
1644 c
->lpt_heap
[i
].cnt
= 0;
1645 c
->lpt_heap
[i
].max_cnt
= LPT_HEAP_SZ
;
1648 c
->dirty_idx
.arr
= kmalloc(sizeof(void *) * LPT_HEAP_SZ
, GFP_KERNEL
);
1649 if (!c
->dirty_idx
.arr
)
1651 c
->dirty_idx
.cnt
= 0;
1652 c
->dirty_idx
.max_cnt
= LPT_HEAP_SZ
;
1658 dbg_lp("space_bits %d", c
->space_bits
);
1659 dbg_lp("lpt_lnum_bits %d", c
->lpt_lnum_bits
);
1660 dbg_lp("lpt_offs_bits %d", c
->lpt_offs_bits
);
1661 dbg_lp("lpt_spc_bits %d", c
->lpt_spc_bits
);
1662 dbg_lp("pcnt_bits %d", c
->pcnt_bits
);
1663 dbg_lp("lnum_bits %d", c
->lnum_bits
);
1664 dbg_lp("pnode_sz %d", c
->pnode_sz
);
1665 dbg_lp("nnode_sz %d", c
->nnode_sz
);
1666 dbg_lp("ltab_sz %d", c
->ltab_sz
);
1667 dbg_lp("lsave_sz %d", c
->lsave_sz
);
1668 dbg_lp("lsave_cnt %d", c
->lsave_cnt
);
1669 dbg_lp("lpt_hght %d", c
->lpt_hght
);
1670 dbg_lp("big_lpt %d", c
->big_lpt
);
1671 dbg_lp("LPT root is at %d:%d", c
->lpt_lnum
, c
->lpt_offs
);
1672 dbg_lp("LPT head is at %d:%d", c
->nhead_lnum
, c
->nhead_offs
);
1673 dbg_lp("LPT ltab is at %d:%d", c
->ltab_lnum
, c
->ltab_offs
);
1675 dbg_lp("LPT lsave is at %d:%d", c
->lsave_lnum
, c
->lsave_offs
);
1682 * lpt_init_wr - initialize the LPT for writing.
1683 * @c: UBIFS file-system description object
1685 * 'lpt_init_rd()' must have been called already.
1687 * This function returns %0 on success and a negative error code on failure.
1689 static int lpt_init_wr(struct ubifs_info
*c
)
1693 c
->ltab_cmt
= vmalloc(sizeof(struct ubifs_lpt_lprops
) * c
->lpt_lebs
);
1697 c
->lpt_buf
= vmalloc(c
->leb_size
);
1702 c
->lsave
= kmalloc(sizeof(int) * c
->lsave_cnt
, GFP_NOFS
);
1705 err
= read_lsave(c
);
1710 for (i
= 0; i
< c
->lpt_lebs
; i
++)
1711 if (c
->ltab
[i
].free
== c
->leb_size
) {
1712 err
= ubifs_leb_unmap(c
, i
+ c
->lpt_first
);
1722 * ubifs_lpt_init - initialize the LPT.
1723 * @c: UBIFS file-system description object
1724 * @rd: whether to initialize lpt for reading
1725 * @wr: whether to initialize lpt for writing
1727 * For mounting 'rw', @rd and @wr are both true. For mounting 'ro', @rd is true
1728 * and @wr is false. For mounting from 'ro' to 'rw', @rd is false and @wr is
1731 * This function returns %0 on success and a negative error code on failure.
1733 int ubifs_lpt_init(struct ubifs_info
*c
, int rd
, int wr
)
1738 err
= lpt_init_rd(c
);
1745 err
= lpt_init_wr(c
);
1756 ubifs_lpt_free(c
, 1);
1759 ubifs_lpt_free(c
, 0);
1764 * struct lpt_scan_node - somewhere to put nodes while we scan LPT.
1765 * @nnode: where to keep a nnode
1766 * @pnode: where to keep a pnode
1767 * @cnode: where to keep a cnode
1768 * @in_tree: is the node in the tree in memory
1769 * @ptr.nnode: pointer to the nnode (if it is an nnode) which may be here or in
1771 * @ptr.pnode: ditto for pnode
1772 * @ptr.cnode: ditto for cnode
1774 struct lpt_scan_node
{
1776 struct ubifs_nnode nnode
;
1777 struct ubifs_pnode pnode
;
1778 struct ubifs_cnode cnode
;
1782 struct ubifs_nnode
*nnode
;
1783 struct ubifs_pnode
*pnode
;
1784 struct ubifs_cnode
*cnode
;
1789 * scan_get_nnode - for the scan, get a nnode from either the tree or flash.
1790 * @c: the UBIFS file-system description object
1791 * @path: where to put the nnode
1792 * @parent: parent of the nnode
1793 * @iip: index in parent of the nnode
1795 * This function returns a pointer to the nnode on success or a negative error
1798 static struct ubifs_nnode
*scan_get_nnode(struct ubifs_info
*c
,
1799 struct lpt_scan_node
*path
,
1800 struct ubifs_nnode
*parent
, int iip
)
1802 struct ubifs_nbranch
*branch
;
1803 struct ubifs_nnode
*nnode
;
1804 void *buf
= c
->lpt_nod_buf
;
1807 branch
= &parent
->nbranch
[iip
];
1808 nnode
= branch
->nnode
;
1811 path
->ptr
.nnode
= nnode
;
1814 nnode
= &path
->nnode
;
1816 path
->ptr
.nnode
= nnode
;
1817 memset(nnode
, 0, sizeof(struct ubifs_nnode
));
1818 if (branch
->lnum
== 0) {
1820 * This nnode was not written which just means that the LEB
1821 * properties in the subtree below it describe empty LEBs. We
1822 * make the nnode as though we had read it, which in fact means
1823 * doing almost nothing.
1826 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1828 err
= ubifs_leb_read(c
, branch
->lnum
, buf
, branch
->offs
,
1831 return ERR_PTR(err
);
1832 err
= ubifs_unpack_nnode(c
, buf
, nnode
);
1834 return ERR_PTR(err
);
1836 err
= validate_nnode(c
, nnode
, parent
, iip
);
1838 return ERR_PTR(err
);
1840 nnode
->num
= calc_nnode_num_from_parent(c
, parent
, iip
);
1841 nnode
->level
= parent
->level
- 1;
1842 nnode
->parent
= parent
;
1848 * scan_get_pnode - for the scan, get a pnode from either the tree or flash.
1849 * @c: the UBIFS file-system description object
1850 * @path: where to put the pnode
1851 * @parent: parent of the pnode
1852 * @iip: index in parent of the pnode
1854 * This function returns a pointer to the pnode on success or a negative error
1857 static struct ubifs_pnode
*scan_get_pnode(struct ubifs_info
*c
,
1858 struct lpt_scan_node
*path
,
1859 struct ubifs_nnode
*parent
, int iip
)
1861 struct ubifs_nbranch
*branch
;
1862 struct ubifs_pnode
*pnode
;
1863 void *buf
= c
->lpt_nod_buf
;
1866 branch
= &parent
->nbranch
[iip
];
1867 pnode
= branch
->pnode
;
1870 path
->ptr
.pnode
= pnode
;
1873 pnode
= &path
->pnode
;
1875 path
->ptr
.pnode
= pnode
;
1876 memset(pnode
, 0, sizeof(struct ubifs_pnode
));
1877 if (branch
->lnum
== 0) {
1879 * This pnode was not written which just means that the LEB
1880 * properties in it describe empty LEBs. We make the pnode as
1881 * though we had read it.
1886 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1887 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
1888 struct ubifs_lprops
* const lprops
= &pnode
->lprops
[i
];
1890 lprops
->free
= c
->leb_size
;
1891 lprops
->flags
= ubifs_categorize_lprops(c
, lprops
);
1894 ubifs_assert(branch
->lnum
>= c
->lpt_first
&&
1895 branch
->lnum
<= c
->lpt_last
);
1896 ubifs_assert(branch
->offs
>= 0 && branch
->offs
< c
->leb_size
);
1897 err
= ubifs_leb_read(c
, branch
->lnum
, buf
, branch
->offs
,
1900 return ERR_PTR(err
);
1901 err
= unpack_pnode(c
, buf
, pnode
);
1903 return ERR_PTR(err
);
1905 err
= validate_pnode(c
, pnode
, parent
, iip
);
1907 return ERR_PTR(err
);
1909 pnode
->num
= calc_pnode_num_from_parent(c
, parent
, iip
);
1910 pnode
->parent
= parent
;
1912 set_pnode_lnum(c
, pnode
);
1917 * ubifs_lpt_scan_nolock - scan the LPT.
1918 * @c: the UBIFS file-system description object
1919 * @start_lnum: LEB number from which to start scanning
1920 * @end_lnum: LEB number at which to stop scanning
1921 * @scan_cb: callback function called for each lprops
1922 * @data: data to be passed to the callback function
1924 * This function returns %0 on success and a negative error code on failure.
1926 int ubifs_lpt_scan_nolock(struct ubifs_info
*c
, int start_lnum
, int end_lnum
,
1927 ubifs_lpt_scan_callback scan_cb
, void *data
)
1929 int err
= 0, i
, h
, iip
, shft
;
1930 struct ubifs_nnode
*nnode
;
1931 struct ubifs_pnode
*pnode
;
1932 struct lpt_scan_node
*path
;
1934 if (start_lnum
== -1) {
1935 start_lnum
= end_lnum
+ 1;
1936 if (start_lnum
>= c
->leb_cnt
)
1937 start_lnum
= c
->main_first
;
1940 ubifs_assert(start_lnum
>= c
->main_first
&& start_lnum
< c
->leb_cnt
);
1941 ubifs_assert(end_lnum
>= c
->main_first
&& end_lnum
< c
->leb_cnt
);
1944 err
= ubifs_read_nnode(c
, NULL
, 0);
1949 path
= kmalloc(sizeof(struct lpt_scan_node
) * (c
->lpt_hght
+ 1),
1954 path
[0].ptr
.nnode
= c
->nroot
;
1955 path
[0].in_tree
= 1;
1957 /* Descend to the pnode containing start_lnum */
1959 i
= start_lnum
- c
->main_first
;
1960 shft
= c
->lpt_hght
* UBIFS_LPT_FANOUT_SHIFT
;
1961 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1962 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1963 shft
-= UBIFS_LPT_FANOUT_SHIFT
;
1964 nnode
= scan_get_nnode(c
, path
+ h
, nnode
, iip
);
1965 if (IS_ERR(nnode
)) {
1966 err
= PTR_ERR(nnode
);
1970 iip
= ((i
>> shft
) & (UBIFS_LPT_FANOUT
- 1));
1971 pnode
= scan_get_pnode(c
, path
+ h
, nnode
, iip
);
1972 if (IS_ERR(pnode
)) {
1973 err
= PTR_ERR(pnode
);
1976 iip
= (i
& (UBIFS_LPT_FANOUT
- 1));
1978 /* Loop for each lprops */
1980 struct ubifs_lprops
*lprops
= &pnode
->lprops
[iip
];
1981 int ret
, lnum
= lprops
->lnum
;
1983 ret
= scan_cb(c
, lprops
, path
[h
].in_tree
, data
);
1988 if (ret
& LPT_SCAN_ADD
) {
1989 /* Add all the nodes in path to the tree in memory */
1990 for (h
= 1; h
< c
->lpt_hght
; h
++) {
1991 const size_t sz
= sizeof(struct ubifs_nnode
);
1992 struct ubifs_nnode
*parent
;
1994 if (path
[h
].in_tree
)
1996 nnode
= kmemdup(&path
[h
].nnode
, sz
, GFP_NOFS
);
2001 parent
= nnode
->parent
;
2002 parent
->nbranch
[nnode
->iip
].nnode
= nnode
;
2003 path
[h
].ptr
.nnode
= nnode
;
2004 path
[h
].in_tree
= 1;
2005 path
[h
+ 1].cnode
.parent
= nnode
;
2007 if (path
[h
].in_tree
)
2008 ubifs_ensure_cat(c
, lprops
);
2010 const size_t sz
= sizeof(struct ubifs_pnode
);
2011 struct ubifs_nnode
*parent
;
2013 pnode
= kmemdup(&path
[h
].pnode
, sz
, GFP_NOFS
);
2018 parent
= pnode
->parent
;
2019 parent
->nbranch
[pnode
->iip
].pnode
= pnode
;
2020 path
[h
].ptr
.pnode
= pnode
;
2021 path
[h
].in_tree
= 1;
2022 update_cats(c
, pnode
);
2023 c
->pnodes_have
+= 1;
2025 err
= dbg_check_lpt_nodes(c
, (struct ubifs_cnode
*)
2029 err
= dbg_check_cats(c
);
2033 if (ret
& LPT_SCAN_STOP
) {
2037 /* Get the next lprops */
2038 if (lnum
== end_lnum
) {
2040 * We got to the end without finding what we were
2046 if (lnum
+ 1 >= c
->leb_cnt
) {
2047 /* Wrap-around to the beginning */
2048 start_lnum
= c
->main_first
;
2051 if (iip
+ 1 < UBIFS_LPT_FANOUT
) {
2052 /* Next lprops is in the same pnode */
2056 /* We need to get the next pnode. Go up until we can go right */
2060 ubifs_assert(h
>= 0);
2061 nnode
= path
[h
].ptr
.nnode
;
2062 if (iip
+ 1 < UBIFS_LPT_FANOUT
)
2068 /* Descend to the pnode */
2070 for (; h
< c
->lpt_hght
; h
++) {
2071 nnode
= scan_get_nnode(c
, path
+ h
, nnode
, iip
);
2072 if (IS_ERR(nnode
)) {
2073 err
= PTR_ERR(nnode
);
2078 pnode
= scan_get_pnode(c
, path
+ h
, nnode
, iip
);
2079 if (IS_ERR(pnode
)) {
2080 err
= PTR_ERR(pnode
);
2091 * dbg_chk_pnode - check a pnode.
2092 * @c: the UBIFS file-system description object
2093 * @pnode: pnode to check
2094 * @col: pnode column
2096 * This function returns %0 on success and a negative error code on failure.
2098 static int dbg_chk_pnode(struct ubifs_info
*c
, struct ubifs_pnode
*pnode
,
2103 if (pnode
->num
!= col
) {
2104 ubifs_err(c
, "pnode num %d expected %d parent num %d iip %d",
2105 pnode
->num
, col
, pnode
->parent
->num
, pnode
->iip
);
2108 for (i
= 0; i
< UBIFS_LPT_FANOUT
; i
++) {
2109 struct ubifs_lprops
*lp
, *lprops
= &pnode
->lprops
[i
];
2110 int lnum
= (pnode
->num
<< UBIFS_LPT_FANOUT_SHIFT
) + i
+
2112 int found
, cat
= lprops
->flags
& LPROPS_CAT_MASK
;
2113 struct ubifs_lpt_heap
*heap
;
2114 struct list_head
*list
= NULL
;
2116 if (lnum
>= c
->leb_cnt
)
2118 if (lprops
->lnum
!= lnum
) {
2119 ubifs_err(c
, "bad LEB number %d expected %d",
2120 lprops
->lnum
, lnum
);
2123 if (lprops
->flags
& LPROPS_TAKEN
) {
2124 if (cat
!= LPROPS_UNCAT
) {
2125 ubifs_err(c
, "LEB %d taken but not uncat %d",
2131 if (lprops
->flags
& LPROPS_INDEX
) {
2134 case LPROPS_DIRTY_IDX
:
2135 case LPROPS_FRDI_IDX
:
2138 ubifs_err(c
, "LEB %d index but cat %d",
2148 case LPROPS_FREEABLE
:
2151 ubifs_err(c
, "LEB %d not index but cat %d",
2158 list
= &c
->uncat_list
;
2161 list
= &c
->empty_list
;
2163 case LPROPS_FREEABLE
:
2164 list
= &c
->freeable_list
;
2166 case LPROPS_FRDI_IDX
:
2167 list
= &c
->frdi_idx_list
;
2173 case LPROPS_DIRTY_IDX
:
2175 heap
= &c
->lpt_heap
[cat
- 1];
2176 if (lprops
->hpos
< heap
->cnt
&&
2177 heap
->arr
[lprops
->hpos
] == lprops
)
2182 case LPROPS_FREEABLE
:
2183 case LPROPS_FRDI_IDX
:
2184 list_for_each_entry(lp
, list
, list
)
2192 ubifs_err(c
, "LEB %d cat %d not found in cat heap/list",
2198 if (lprops
->free
!= c
->leb_size
) {
2199 ubifs_err(c
, "LEB %d cat %d free %d dirty %d",
2200 lprops
->lnum
, cat
, lprops
->free
,
2205 case LPROPS_FREEABLE
:
2206 case LPROPS_FRDI_IDX
:
2207 if (lprops
->free
+ lprops
->dirty
!= c
->leb_size
) {
2208 ubifs_err(c
, "LEB %d cat %d free %d dirty %d",
2209 lprops
->lnum
, cat
, lprops
->free
,
2220 * dbg_check_lpt_nodes - check nnodes and pnodes.
2221 * @c: the UBIFS file-system description object
2222 * @cnode: next cnode (nnode or pnode) to check
2223 * @row: row of cnode (root is zero)
2224 * @col: column of cnode (leftmost is zero)
2226 * This function returns %0 on success and a negative error code on failure.
2228 int dbg_check_lpt_nodes(struct ubifs_info
*c
, struct ubifs_cnode
*cnode
,
2231 struct ubifs_nnode
*nnode
, *nn
;
2232 struct ubifs_cnode
*cn
;
2233 int num
, iip
= 0, err
;
2235 if (!dbg_is_chk_lprops(c
))
2239 ubifs_assert(row
>= 0);
2240 nnode
= cnode
->parent
;
2242 /* cnode is a nnode */
2243 num
= calc_nnode_num(row
, col
);
2244 if (cnode
->num
!= num
) {
2245 ubifs_err(c
, "nnode num %d expected %d parent num %d iip %d",
2247 (nnode
? nnode
->num
: 0), cnode
->iip
);
2250 nn
= (struct ubifs_nnode
*)cnode
;
2251 while (iip
< UBIFS_LPT_FANOUT
) {
2252 cn
= nn
->nbranch
[iip
].cnode
;
2256 col
<<= UBIFS_LPT_FANOUT_SHIFT
;
2265 if (iip
< UBIFS_LPT_FANOUT
)
2268 struct ubifs_pnode
*pnode
;
2270 /* cnode is a pnode */
2271 pnode
= (struct ubifs_pnode
*)cnode
;
2272 err
= dbg_chk_pnode(c
, pnode
, col
);
2276 /* Go up and to the right */
2278 col
>>= UBIFS_LPT_FANOUT_SHIFT
;
2279 iip
= cnode
->iip
+ 1;
2280 cnode
= (struct ubifs_cnode
*)nnode
;