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 * Author: Adrian Hunter
25 * An orphan is an inode number whose inode node has been committed to the index
26 * with a link count of zero. That happens when an open file is deleted
27 * (unlinked) and then a commit is run. In the normal course of events the inode
28 * would be deleted when the file is closed. However in the case of an unclean
29 * unmount, orphans need to be accounted for. After an unclean unmount, the
30 * orphans' inodes must be deleted which means either scanning the entire index
31 * looking for them, or keeping a list on flash somewhere. This unit implements
32 * the latter approach.
34 * The orphan area is a fixed number of LEBs situated between the LPT area and
35 * the main area. The number of orphan area LEBs is specified when the file
36 * system is created. The minimum number is 1. The size of the orphan area
37 * should be so that it can hold the maximum number of orphans that are expected
38 * to ever exist at one time.
40 * The number of orphans that can fit in a LEB is:
42 * (c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64)
44 * For example: a 15872 byte LEB can fit 1980 orphans so 1 LEB may be enough.
46 * Orphans are accumulated in a rb-tree. When an inode's link count drops to
47 * zero, the inode number is added to the rb-tree. It is removed from the tree
48 * when the inode is deleted. Any new orphans that are in the orphan tree when
49 * the commit is run, are written to the orphan area in 1 or more orphan nodes.
50 * If the orphan area is full, it is consolidated to make space. There is
51 * always enough space because validation prevents the user from creating more
52 * than the maximum number of orphans allowed.
55 static int dbg_check_orphans(struct ubifs_info *c);
57 static struct ubifs_orphan *orphan_add(struct ubifs_info *c, ino_t inum,
58 struct ubifs_orphan *parent_orphan)
60 struct ubifs_orphan *orphan, *o;
61 struct rb_node **p, *parent = NULL;
63 orphan = kzalloc(sizeof(struct ubifs_orphan), GFP_NOFS);
65 return ERR_PTR(-ENOMEM);
68 INIT_LIST_HEAD(&orphan->child_list);
70 spin_lock(&c->orphan_lock);
71 if (c->tot_orphans >= c->max_orphans) {
72 spin_unlock(&c->orphan_lock);
74 return ERR_PTR(-ENFILE);
76 p = &c->orph_tree.rb_node;
79 o = rb_entry(parent, struct ubifs_orphan, rb);
82 else if (inum > o->inum)
85 ubifs_err(c, "orphaned twice");
86 spin_unlock(&c->orphan_lock);
88 return ERR_PTR(-EINVAL);
93 rb_link_node(&orphan->rb, parent, p);
94 rb_insert_color(&orphan->rb, &c->orph_tree);
95 list_add_tail(&orphan->list, &c->orph_list);
96 list_add_tail(&orphan->new_list, &c->orph_new);
99 list_add_tail(&orphan->child_list,
100 &parent_orphan->child_list);
103 spin_unlock(&c->orphan_lock);
104 dbg_gen("ino %lu", (unsigned long)inum);
108 static struct ubifs_orphan *lookup_orphan(struct ubifs_info *c, ino_t inum)
110 struct ubifs_orphan *o;
113 p = c->orph_tree.rb_node;
115 o = rb_entry(p, struct ubifs_orphan, rb);
118 else if (inum > o->inum)
127 static void __orphan_drop(struct ubifs_info *c, struct ubifs_orphan *o)
129 rb_erase(&o->rb, &c->orph_tree);
134 list_del(&o->new_list);
141 static void orphan_delete(struct ubifs_info *c, ino_t inum)
143 struct ubifs_orphan *orph, *child_orph, *tmp_o;
145 spin_lock(&c->orphan_lock);
147 orph = lookup_orphan(c, inum);
149 spin_unlock(&c->orphan_lock);
150 ubifs_err(c, "missing orphan ino %lu", (unsigned long)inum);
157 spin_unlock(&c->orphan_lock);
158 dbg_gen("deleted twice ino %lu",
159 (unsigned long)inum);
165 orph->dnext = c->orph_dnext;
166 c->orph_dnext = orph;
167 spin_unlock(&c->orphan_lock);
168 dbg_gen("delete later ino %lu",
169 (unsigned long)inum);
173 list_for_each_entry_safe(child_orph, tmp_o, &orph->child_list, child_list) {
174 list_del(&child_orph->child_list);
175 __orphan_drop(c, child_orph);
178 __orphan_drop(c, orph);
180 spin_unlock(&c->orphan_lock);
184 * ubifs_add_orphan - add an orphan.
185 * @c: UBIFS file-system description object
186 * @inum: orphan inode number
188 * Add an orphan. This function is called when an inodes link count drops to
191 int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
196 struct ubifs_dent_node *xent;
197 struct fscrypt_name nm = {0};
198 struct ubifs_orphan *xattr_orphan;
199 struct ubifs_orphan *orphan;
201 orphan = orphan_add(c, inum, NULL);
203 return PTR_ERR(orphan);
205 lowest_xent_key(c, &key, inum);
207 xent = ubifs_tnc_next_ent(c, &key, &nm);
215 fname_name(&nm) = xent->name;
216 fname_len(&nm) = le16_to_cpu(xent->nlen);
217 xattr_inum = le64_to_cpu(xent->inum);
219 xattr_orphan = orphan_add(c, xattr_inum, orphan);
220 if (IS_ERR(xattr_orphan))
221 return PTR_ERR(xattr_orphan);
223 key_read(c, &xent->key, &key);
230 * ubifs_delete_orphan - delete an orphan.
231 * @c: UBIFS file-system description object
232 * @inum: orphan inode number
234 * Delete an orphan. This function is called when an inode is deleted.
236 void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum)
238 orphan_delete(c, inum);
242 * ubifs_orphan_start_commit - start commit of orphans.
243 * @c: UBIFS file-system description object
245 * Start commit of orphans.
247 int ubifs_orphan_start_commit(struct ubifs_info *c)
249 struct ubifs_orphan *orphan, **last;
251 spin_lock(&c->orphan_lock);
252 last = &c->orph_cnext;
253 list_for_each_entry(orphan, &c->orph_new, new_list) {
254 ubifs_assert(c, orphan->new);
255 ubifs_assert(c, !orphan->cmt);
259 last = &orphan->cnext;
262 c->cmt_orphans = c->new_orphans;
264 dbg_cmt("%d orphans to commit", c->cmt_orphans);
265 INIT_LIST_HEAD(&c->orph_new);
266 if (c->tot_orphans == 0)
270 spin_unlock(&c->orphan_lock);
275 * avail_orphs - calculate available space.
276 * @c: UBIFS file-system description object
278 * This function returns the number of orphans that can be written in the
281 static int avail_orphs(struct ubifs_info *c)
283 int avail_lebs, avail, gap;
285 avail_lebs = c->orph_lebs - (c->ohead_lnum - c->orph_first) - 1;
287 ((c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64));
288 gap = c->leb_size - c->ohead_offs;
289 if (gap >= UBIFS_ORPH_NODE_SZ + sizeof(__le64))
290 avail += (gap - UBIFS_ORPH_NODE_SZ) / sizeof(__le64);
295 * tot_avail_orphs - calculate total space.
296 * @c: UBIFS file-system description object
298 * This function returns the number of orphans that can be written in half
299 * the total space. That leaves half the space for adding new orphans.
301 static int tot_avail_orphs(struct ubifs_info *c)
303 int avail_lebs, avail;
305 avail_lebs = c->orph_lebs;
307 ((c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64));
312 * do_write_orph_node - write a node to the orphan head.
313 * @c: UBIFS file-system description object
314 * @len: length of node
315 * @atomic: write atomically
317 * This function writes a node to the orphan head from the orphan buffer. If
318 * %atomic is not zero, then the write is done atomically. On success, %0 is
319 * returned, otherwise a negative error code is returned.
321 static int do_write_orph_node(struct ubifs_info *c, int len, int atomic)
326 ubifs_assert(c, c->ohead_offs == 0);
327 ubifs_prepare_node(c, c->orph_buf, len, 1);
328 len = ALIGN(len, c->min_io_size);
329 err = ubifs_leb_change(c, c->ohead_lnum, c->orph_buf, len);
331 if (c->ohead_offs == 0) {
332 /* Ensure LEB has been unmapped */
333 err = ubifs_leb_unmap(c, c->ohead_lnum);
337 err = ubifs_write_node(c, c->orph_buf, len, c->ohead_lnum,
344 * write_orph_node - write an orphan node.
345 * @c: UBIFS file-system description object
346 * @atomic: write atomically
348 * This function builds an orphan node from the cnext list and writes it to the
349 * orphan head. On success, %0 is returned, otherwise a negative error code
352 static int write_orph_node(struct ubifs_info *c, int atomic)
354 struct ubifs_orphan *orphan, *cnext;
355 struct ubifs_orph_node *orph;
356 int gap, err, len, cnt, i;
358 ubifs_assert(c, c->cmt_orphans > 0);
359 gap = c->leb_size - c->ohead_offs;
360 if (gap < UBIFS_ORPH_NODE_SZ + sizeof(__le64)) {
364 if (c->ohead_lnum > c->orph_last) {
366 * We limit the number of orphans so that this should
369 ubifs_err(c, "out of space in orphan area");
373 cnt = (gap - UBIFS_ORPH_NODE_SZ) / sizeof(__le64);
374 if (cnt > c->cmt_orphans)
375 cnt = c->cmt_orphans;
376 len = UBIFS_ORPH_NODE_SZ + cnt * sizeof(__le64);
377 ubifs_assert(c, c->orph_buf);
379 orph->ch.node_type = UBIFS_ORPH_NODE;
380 spin_lock(&c->orphan_lock);
381 cnext = c->orph_cnext;
382 for (i = 0; i < cnt; i++) {
384 ubifs_assert(c, orphan->cmt);
385 orph->inos[i] = cpu_to_le64(orphan->inum);
387 cnext = orphan->cnext;
388 orphan->cnext = NULL;
390 c->orph_cnext = cnext;
391 c->cmt_orphans -= cnt;
392 spin_unlock(&c->orphan_lock);
394 orph->cmt_no = cpu_to_le64(c->cmt_no);
396 /* Mark the last node of the commit */
397 orph->cmt_no = cpu_to_le64((c->cmt_no) | (1ULL << 63));
398 ubifs_assert(c, c->ohead_offs + len <= c->leb_size);
399 ubifs_assert(c, c->ohead_lnum >= c->orph_first);
400 ubifs_assert(c, c->ohead_lnum <= c->orph_last);
401 err = do_write_orph_node(c, len, atomic);
402 c->ohead_offs += ALIGN(len, c->min_io_size);
403 c->ohead_offs = ALIGN(c->ohead_offs, 8);
408 * write_orph_nodes - write orphan nodes until there are no more to commit.
409 * @c: UBIFS file-system description object
410 * @atomic: write atomically
412 * This function writes orphan nodes for all the orphans to commit. On success,
413 * %0 is returned, otherwise a negative error code is returned.
415 static int write_orph_nodes(struct ubifs_info *c, int atomic)
419 while (c->cmt_orphans > 0) {
420 err = write_orph_node(c, atomic);
427 /* Unmap any unused LEBs after consolidation */
428 for (lnum = c->ohead_lnum + 1; lnum <= c->orph_last; lnum++) {
429 err = ubifs_leb_unmap(c, lnum);
438 * consolidate - consolidate the orphan area.
439 * @c: UBIFS file-system description object
441 * This function enables consolidation by putting all the orphans into the list
442 * to commit. The list is in the order that the orphans were added, and the
443 * LEBs are written atomically in order, so at no time can orphans be lost by
444 * an unclean unmount.
446 * This function returns %0 on success and a negative error code on failure.
448 static int consolidate(struct ubifs_info *c)
450 int tot_avail = tot_avail_orphs(c), err = 0;
452 spin_lock(&c->orphan_lock);
453 dbg_cmt("there is space for %d orphans and there are %d",
454 tot_avail, c->tot_orphans);
455 if (c->tot_orphans - c->new_orphans <= tot_avail) {
456 struct ubifs_orphan *orphan, **last;
459 /* Change the cnext list to include all non-new orphans */
460 last = &c->orph_cnext;
461 list_for_each_entry(orphan, &c->orph_list, list) {
466 last = &orphan->cnext;
470 ubifs_assert(c, cnt == c->tot_orphans - c->new_orphans);
471 c->cmt_orphans = cnt;
472 c->ohead_lnum = c->orph_first;
476 * We limit the number of orphans so that this should
479 ubifs_err(c, "out of space in orphan area");
482 spin_unlock(&c->orphan_lock);
487 * commit_orphans - commit orphans.
488 * @c: UBIFS file-system description object
490 * This function commits orphans to flash. On success, %0 is returned,
491 * otherwise a negative error code is returned.
493 static int commit_orphans(struct ubifs_info *c)
495 int avail, atomic = 0, err;
497 ubifs_assert(c, c->cmt_orphans > 0);
498 avail = avail_orphs(c);
499 if (avail < c->cmt_orphans) {
500 /* Not enough space to write new orphans, so consolidate */
501 err = consolidate(c);
506 err = write_orph_nodes(c, atomic);
511 * erase_deleted - erase the orphans marked for deletion.
512 * @c: UBIFS file-system description object
514 * During commit, the orphans being committed cannot be deleted, so they are
515 * marked for deletion and deleted by this function. Also, the recovery
516 * adds killed orphans to the deletion list, and therefore they are deleted
519 static void erase_deleted(struct ubifs_info *c)
521 struct ubifs_orphan *orphan, *dnext;
523 spin_lock(&c->orphan_lock);
524 dnext = c->orph_dnext;
527 dnext = orphan->dnext;
528 ubifs_assert(c, !orphan->new);
529 ubifs_assert(c, orphan->del);
530 rb_erase(&orphan->rb, &c->orph_tree);
531 list_del(&orphan->list);
533 dbg_gen("deleting orphan ino %lu", (unsigned long)orphan->inum);
536 c->orph_dnext = NULL;
537 spin_unlock(&c->orphan_lock);
541 * ubifs_orphan_end_commit - end commit of orphans.
542 * @c: UBIFS file-system description object
544 * End commit of orphans.
546 int ubifs_orphan_end_commit(struct ubifs_info *c)
550 if (c->cmt_orphans != 0) {
551 err = commit_orphans(c);
556 err = dbg_check_orphans(c);
561 * ubifs_clear_orphans - erase all LEBs used for orphans.
562 * @c: UBIFS file-system description object
564 * If recovery is not required, then the orphans from the previous session
565 * are not needed. This function locates the LEBs used to record
566 * orphans, and un-maps them.
568 int ubifs_clear_orphans(struct ubifs_info *c)
572 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) {
573 err = ubifs_leb_unmap(c, lnum);
577 c->ohead_lnum = c->orph_first;
583 * insert_dead_orphan - insert an orphan.
584 * @c: UBIFS file-system description object
585 * @inum: orphan inode number
587 * This function is a helper to the 'do_kill_orphans()' function. The orphan
588 * must be kept until the next commit, so it is added to the rb-tree and the
591 static int insert_dead_orphan(struct ubifs_info *c, ino_t inum)
593 struct ubifs_orphan *orphan, *o;
594 struct rb_node **p, *parent = NULL;
596 orphan = kzalloc(sizeof(struct ubifs_orphan), GFP_KERNEL);
601 p = &c->orph_tree.rb_node;
604 o = rb_entry(parent, struct ubifs_orphan, rb);
607 else if (inum > o->inum)
610 /* Already added - no problem */
616 rb_link_node(&orphan->rb, parent, p);
617 rb_insert_color(&orphan->rb, &c->orph_tree);
618 list_add_tail(&orphan->list, &c->orph_list);
620 orphan->dnext = c->orph_dnext;
621 c->orph_dnext = orphan;
622 dbg_mnt("ino %lu, new %d, tot %d", (unsigned long)inum,
623 c->new_orphans, c->tot_orphans);
628 * do_kill_orphans - remove orphan inodes from the index.
629 * @c: UBIFS file-system description object
631 * @last_cmt_no: cmt_no of last orphan node read is passed and returned here
632 * @outofdate: whether the LEB is out of date is returned here
633 * @last_flagged: whether the end orphan node is encountered
635 * This function is a helper to the 'kill_orphans()' function. It goes through
636 * every orphan node in a LEB and for every inode number recorded, removes
637 * all keys for that inode from the TNC.
639 static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
640 unsigned long long *last_cmt_no, int *outofdate,
643 struct ubifs_scan_node *snod;
644 struct ubifs_orph_node *orph;
645 unsigned long long cmt_no;
647 int i, n, err, first = 1;
649 list_for_each_entry(snod, &sleb->nodes, list) {
650 if (snod->type != UBIFS_ORPH_NODE) {
651 ubifs_err(c, "invalid node type %d in orphan area at %d:%d",
652 snod->type, sleb->lnum, snod->offs);
653 ubifs_dump_node(c, snod->node);
659 /* Check commit number */
660 cmt_no = le64_to_cpu(orph->cmt_no) & LLONG_MAX;
662 * The commit number on the master node may be less, because
663 * of a failed commit. If there are several failed commits in a
664 * row, the commit number written on orphan nodes will continue
665 * to increase (because the commit number is adjusted here) even
666 * though the commit number on the master node stays the same
667 * because the master node has not been re-written.
669 if (cmt_no > c->cmt_no)
671 if (cmt_no < *last_cmt_no && *last_flagged) {
673 * The last orphan node had a higher commit number and
674 * was flagged as the last written for that commit
675 * number. That makes this orphan node, out of date.
678 ubifs_err(c, "out of order commit number %llu in orphan node at %d:%d",
679 cmt_no, sleb->lnum, snod->offs);
680 ubifs_dump_node(c, snod->node);
683 dbg_rcvry("out of date LEB %d", sleb->lnum);
691 n = (le32_to_cpu(orph->ch.len) - UBIFS_ORPH_NODE_SZ) >> 3;
692 for (i = 0; i < n; i++) {
693 union ubifs_key key1, key2;
695 inum = le64_to_cpu(orph->inos[i]);
696 dbg_rcvry("deleting orphaned inode %lu",
697 (unsigned long)inum);
699 lowest_ino_key(c, &key1, inum);
700 highest_ino_key(c, &key2, inum);
702 err = ubifs_tnc_remove_range(c, &key1, &key2);
705 err = insert_dead_orphan(c, inum);
710 *last_cmt_no = cmt_no;
711 if (le64_to_cpu(orph->cmt_no) & (1ULL << 63)) {
712 dbg_rcvry("last orph node for commit %llu at %d:%d",
713 cmt_no, sleb->lnum, snod->offs);
723 * kill_orphans - remove all orphan inodes from the index.
724 * @c: UBIFS file-system description object
726 * If recovery is required, then orphan inodes recorded during the previous
727 * session (which ended with an unclean unmount) must be deleted from the index.
728 * This is done by updating the TNC, but since the index is not updated until
729 * the next commit, the LEBs where the orphan information is recorded are not
730 * erased until the next commit.
732 static int kill_orphans(struct ubifs_info *c)
734 unsigned long long last_cmt_no = 0;
735 int lnum, err = 0, outofdate = 0, last_flagged = 0;
737 c->ohead_lnum = c->orph_first;
739 /* Check no-orphans flag and skip this if no orphans */
741 dbg_rcvry("no orphans");
745 * Orph nodes always start at c->orph_first and are written to each
746 * successive LEB in turn. Generally unused LEBs will have been unmapped
747 * but may contain out of date orphan nodes if the unmap didn't go
748 * through. In addition, the last orphan node written for each commit is
749 * marked (top bit of orph->cmt_no is set to 1). It is possible that
750 * there are orphan nodes from the next commit (i.e. the commit did not
751 * complete successfully). In that case, no orphans will have been lost
752 * due to the way that orphans are written, and any orphans added will
753 * be valid orphans anyway and so can be deleted.
755 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) {
756 struct ubifs_scan_leb *sleb;
758 dbg_rcvry("LEB %d", lnum);
759 sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1);
761 if (PTR_ERR(sleb) == -EUCLEAN)
762 sleb = ubifs_recover_leb(c, lnum, 0,
769 err = do_kill_orphans(c, sleb, &last_cmt_no, &outofdate,
771 if (err || outofdate) {
772 ubifs_scan_destroy(sleb);
776 c->ohead_lnum = lnum;
777 c->ohead_offs = sleb->endpt;
779 ubifs_scan_destroy(sleb);
785 * ubifs_mount_orphans - delete orphan inodes and erase LEBs that recorded them.
786 * @c: UBIFS file-system description object
787 * @unclean: indicates recovery from unclean unmount
788 * @read_only: indicates read only mount
790 * This function is called when mounting to erase orphans from the previous
791 * session. If UBIFS was not unmounted cleanly, then the inodes recorded as
792 * orphans are deleted.
794 int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only)
798 c->max_orphans = tot_avail_orphs(c);
801 c->orph_buf = vmalloc(c->leb_size);
807 err = kill_orphans(c);
809 err = ubifs_clear_orphans(c);
815 * Everything below is related to debugging.
818 struct check_orphan {
824 unsigned long last_ino;
825 unsigned long tot_inos;
826 unsigned long missing;
827 unsigned long long leaf_cnt;
828 struct ubifs_ino_node *node;
832 static bool dbg_find_orphan(struct ubifs_info *c, ino_t inum)
836 spin_lock(&c->orphan_lock);
837 found = !!lookup_orphan(c, inum);
838 spin_unlock(&c->orphan_lock);
843 static int dbg_ins_check_orphan(struct rb_root *root, ino_t inum)
845 struct check_orphan *orphan, *o;
846 struct rb_node **p, *parent = NULL;
848 orphan = kzalloc(sizeof(struct check_orphan), GFP_NOFS);
856 o = rb_entry(parent, struct check_orphan, rb);
859 else if (inum > o->inum)
866 rb_link_node(&orphan->rb, parent, p);
867 rb_insert_color(&orphan->rb, root);
871 static int dbg_find_check_orphan(struct rb_root *root, ino_t inum)
873 struct check_orphan *o;
878 o = rb_entry(p, struct check_orphan, rb);
881 else if (inum > o->inum)
889 static void dbg_free_check_tree(struct rb_root *root)
891 struct check_orphan *o, *n;
893 rbtree_postorder_for_each_entry_safe(o, n, root, rb)
897 static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr,
900 struct check_info *ci = priv;
904 inum = key_inum(c, &zbr->key);
905 if (inum != ci->last_ino) {
906 /* Lowest node type is the inode node, so it comes first */
907 if (key_type(c, &zbr->key) != UBIFS_INO_KEY)
908 ubifs_err(c, "found orphan node ino %lu, type %d",
909 (unsigned long)inum, key_type(c, &zbr->key));
912 err = ubifs_tnc_read_node(c, zbr, ci->node);
914 ubifs_err(c, "node read failed, error %d", err);
917 if (ci->node->nlink == 0)
918 /* Must be recorded as an orphan */
919 if (!dbg_find_check_orphan(&ci->root, inum) &&
920 !dbg_find_orphan(c, inum)) {
921 ubifs_err(c, "missing orphan, ino %lu",
922 (unsigned long)inum);
930 static int dbg_read_orphans(struct check_info *ci, struct ubifs_scan_leb *sleb)
932 struct ubifs_scan_node *snod;
933 struct ubifs_orph_node *orph;
937 list_for_each_entry(snod, &sleb->nodes, list) {
939 if (snod->type != UBIFS_ORPH_NODE)
942 n = (le32_to_cpu(orph->ch.len) - UBIFS_ORPH_NODE_SZ) >> 3;
943 for (i = 0; i < n; i++) {
944 inum = le64_to_cpu(orph->inos[i]);
945 err = dbg_ins_check_orphan(&ci->root, inum);
953 static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci)
958 /* Check no-orphans flag and skip this if no orphans */
962 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
964 ubifs_err(c, "cannot allocate memory to check orphans");
968 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) {
969 struct ubifs_scan_leb *sleb;
971 sleb = ubifs_scan(c, lnum, 0, buf, 0);
977 err = dbg_read_orphans(ci, sleb);
978 ubifs_scan_destroy(sleb);
987 static int dbg_check_orphans(struct ubifs_info *c)
989 struct check_info ci;
992 if (!dbg_is_chk_orph(c))
1000 ci.node = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
1002 ubifs_err(c, "out of memory");
1006 err = dbg_scan_orphans(c, &ci);
1010 err = dbg_walk_index(c, &dbg_orphan_check, NULL, &ci);
1012 ubifs_err(c, "cannot scan TNC, error %d", err);
1017 ubifs_err(c, "%lu missing orphan(s)", ci.missing);
1022 dbg_cmt("last inode number is %lu", ci.last_ino);
1023 dbg_cmt("total number of inodes is %lu", ci.tot_inos);
1024 dbg_cmt("total number of leaf nodes is %llu", ci.leaf_cnt);
1027 dbg_free_check_tree(&ci.root);