Lines Matching +full:key +full:- +full:code
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2006-2008 Nokia Corporation.
13 * the UBIFS B-tree.
27 static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key,
53 p = &c->old_idx.rb_node; in do_insert_old_idx()
57 if (old_idx->lnum < o->lnum) in do_insert_old_idx()
58 p = &(*p)->rb_left; in do_insert_old_idx()
59 else if (old_idx->lnum > o->lnum) in do_insert_old_idx()
60 p = &(*p)->rb_right; in do_insert_old_idx()
61 else if (old_idx->offs < o->offs) in do_insert_old_idx()
62 p = &(*p)->rb_left; in do_insert_old_idx()
63 else if (old_idx->offs > o->offs) in do_insert_old_idx()
64 p = &(*p)->rb_right; in do_insert_old_idx()
70 rb_link_node(&old_idx->rb, parent, p); in do_insert_old_idx()
71 rb_insert_color(&old_idx->rb, &c->old_idx); in do_insert_old_idx()
75 * insert_old_idx - record an index node obsoleted since the last commit start.
76 * @c: UBIFS file-system description object
80 * Returns %0 on success, and a negative error code on failure.
88 * That means that the garbage collection and the in-the-gaps method of
93 * they cannot be easily found. In those cases, an entry is added to an RB-tree.
94 * That is what this function does. The RB-tree is ordered by LEB number and
103 return -ENOMEM; in insert_old_idx()
104 old_idx->lnum = lnum; in insert_old_idx()
105 old_idx->offs = offs; in insert_old_idx()
112 * insert_old_idx_znode - record a znode obsoleted since last commit start.
113 * @c: UBIFS file-system description object
116 * Returns %0 on success, and a negative error code on failure.
120 if (znode->parent) { in insert_old_idx_znode()
123 zbr = &znode->parent->zbranch[znode->iip]; in insert_old_idx_znode()
124 if (zbr->len) in insert_old_idx_znode()
125 return insert_old_idx(c, zbr->lnum, zbr->offs); in insert_old_idx_znode()
127 if (c->zroot.len) in insert_old_idx_znode()
128 return insert_old_idx(c, c->zroot.lnum, in insert_old_idx_znode()
129 c->zroot.offs); in insert_old_idx_znode()
134 * ins_clr_old_idx_znode - record a znode obsoleted since last commit start.
135 * @c: UBIFS file-system description object
138 * Returns %0 on success, and a negative error code on failure.
145 if (znode->parent) { in ins_clr_old_idx_znode()
148 zbr = &znode->parent->zbranch[znode->iip]; in ins_clr_old_idx_znode()
149 if (zbr->len) { in ins_clr_old_idx_znode()
150 err = insert_old_idx(c, zbr->lnum, zbr->offs); in ins_clr_old_idx_znode()
153 zbr->lnum = 0; in ins_clr_old_idx_znode()
154 zbr->offs = 0; in ins_clr_old_idx_znode()
155 zbr->len = 0; in ins_clr_old_idx_znode()
158 if (c->zroot.len) { in ins_clr_old_idx_znode()
159 err = insert_old_idx(c, c->zroot.lnum, c->zroot.offs); in ins_clr_old_idx_znode()
162 c->zroot.lnum = 0; in ins_clr_old_idx_znode()
163 c->zroot.offs = 0; in ins_clr_old_idx_znode()
164 c->zroot.len = 0; in ins_clr_old_idx_znode()
170 * destroy_old_idx - destroy the old_idx RB-tree.
171 * @c: UBIFS file-system description object
173 * During start commit, the old_idx RB-tree is used to avoid overwriting index
176 * new index is successfully written. The old-idx RB-tree is used for the
177 * in-the-gaps method of writing index nodes and is destroyed every commit.
183 rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb) in destroy_old_idx()
186 c->old_idx = RB_ROOT; in destroy_old_idx()
190 * copy_znode - copy a dirty znode.
191 * @c: UBIFS file-system description object
201 zn = kmemdup(znode, c->max_znode_sz, GFP_NOFS); in copy_znode()
203 return ERR_PTR(-ENOMEM); in copy_znode()
205 zn->cnext = NULL; in copy_znode()
206 __set_bit(DIRTY_ZNODE, &zn->flags); in copy_znode()
207 __clear_bit(COW_ZNODE, &zn->flags); in copy_znode()
213 * add_idx_dirt - add dirt due to a dirty znode.
214 * @c: UBIFS file-system description object
222 c->calc_idx_sz -= ALIGN(dirt, 8); in add_idx_dirt()
227 * replace_znode - replace old znode with new znode.
228 * @c: UBIFS file-system description object
239 __set_bit(OBSOLETE_ZNODE, &old_zn->flags); in replace_znode()
241 if (old_zn->level != 0) { in replace_znode()
243 const int n = new_zn->child_cnt; in replace_znode()
247 struct ubifs_zbranch *child = &new_zn->zbranch[i]; in replace_znode()
249 if (child->znode) in replace_znode()
250 child->znode->parent = new_zn; in replace_znode()
254 zbr->znode = new_zn; in replace_znode()
255 zbr->lnum = 0; in replace_znode()
256 zbr->offs = 0; in replace_znode()
257 zbr->len = 0; in replace_znode()
259 atomic_long_inc(&c->dirty_zn_cnt); in replace_znode()
263 * dirty_cow_znode - ensure a znode is not being committed.
264 * @c: UBIFS file-system description object
267 * Returns dirtied znode on success or negative error code on failure.
272 struct ubifs_znode *znode = zbr->znode; in dirty_cow_znode()
278 if (!test_and_set_bit(DIRTY_ZNODE, &znode->flags)) { in dirty_cow_znode()
279 atomic_long_inc(&c->dirty_zn_cnt); in dirty_cow_znode()
280 atomic_long_dec(&c->clean_zn_cnt); in dirty_cow_znode()
282 err = add_idx_dirt(c, zbr->lnum, zbr->len); in dirty_cow_znode()
293 if (zbr->len) { in dirty_cow_znode()
298 err = -ENOMEM; in dirty_cow_znode()
301 old_idx->lnum = zbr->lnum; in dirty_cow_znode()
302 old_idx->offs = zbr->offs; in dirty_cow_znode()
304 err = add_idx_dirt(c, zbr->lnum, zbr->len); in dirty_cow_znode()
323 * lnc_add - add a leaf node to the leaf node cache.
324 * @c: UBIFS file-system description object
328 * Leaf nodes are non-index nodes directory entry nodes or data nodes. The
329 * purpose of the leaf node cache is to save re-reading the same leaf node over
339 * used with @c->tnc_mutex unlock upon return from the TNC subsystem. But LNC
349 ubifs_assert(c, !zbr->leaf); in lnc_add()
350 ubifs_assert(c, zbr->len != 0); in lnc_add()
351 ubifs_assert(c, is_hash_key(c, &zbr->key)); in lnc_add()
356 ubifs_dump_node(c, dent, zbr->len); in lnc_add()
360 lnc_node = kmemdup(node, zbr->len, GFP_NOFS); in lnc_add()
365 zbr->leaf = lnc_node; in lnc_add()
370 * lnc_add_directly - add a leaf node to the leaf-node-cache.
371 * @c: UBIFS file-system description object
383 ubifs_assert(c, !zbr->leaf); in lnc_add_directly()
384 ubifs_assert(c, zbr->len != 0); in lnc_add_directly()
389 ubifs_dump_node(c, node, zbr->len); in lnc_add_directly()
393 zbr->leaf = node; in lnc_add_directly()
398 * lnc_free - remove a leaf node from the leaf node cache.
403 if (!zbr->leaf) in lnc_free()
405 kfree(zbr->leaf); in lnc_free()
406 zbr->leaf = NULL; in lnc_free()
410 * tnc_read_hashed_node - read a "hashed" leaf node.
411 * @c: UBIFS file-system description object
412 * @zbr: key and position of the node
418 * code in case of failure.
425 ubifs_assert(c, is_hash_key(c, &zbr->key)); in tnc_read_hashed_node()
427 if (zbr->leaf) { in tnc_read_hashed_node()
429 ubifs_assert(c, zbr->len != 0); in tnc_read_hashed_node()
430 memcpy(node, zbr->leaf, zbr->len); in tnc_read_hashed_node()
434 if (c->replaying) { in tnc_read_hashed_node()
435 err = fallible_read_node(c, &zbr->key, zbr, node); in tnc_read_hashed_node()
437 * When the node was not found, return -ENOENT, 0 otherwise. in tnc_read_hashed_node()
438 * Negative return codes stay as-is. in tnc_read_hashed_node()
441 err = -ENOENT; in tnc_read_hashed_node()
456 * try_read_node - read a node if it is a node.
457 * @c: UBIFS file-system description object
464 * a node is not present. A negative error code is returned for I/O errors.
467 * the return code indicates if a node was read.
469 * Note, this function does not check CRC of data nodes if @c->no_chk_data_crc
471 * @c->mounting or @c->remounting_rw is true (we are mounting or re-mounting to
472 * R/W mode), @c->no_chk_data_crc is ignored and CRC is checked. This is
473 * because during mounting or re-mounting from R/O mode to R/W mode we may read
480 int len = zbr->len; in try_read_node()
481 int lnum = zbr->lnum; in try_read_node()
482 int offs = zbr->offs; in try_read_node()
496 if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) in try_read_node()
499 if (ch->node_type != type) in try_read_node()
502 node_len = le32_to_cpu(ch->len); in try_read_node()
506 if (type != UBIFS_DATA_NODE || !c->no_chk_data_crc || c->mounting || in try_read_node()
507 c->remounting_rw) { in try_read_node()
508 crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); in try_read_node()
509 node_crc = le32_to_cpu(ch->crc); in try_read_node()
514 err = ubifs_node_check_hash(c, buf, zbr->hash); in try_read_node()
516 ubifs_bad_hash(c, buf, zbr->hash, lnum, offs); in try_read_node()
524 * fallible_read_node - try to read a leaf node.
525 * @c: UBIFS file-system description object
526 * @key: key of node to read
531 * if the node is not present, and a negative error code in the case of error.
533 static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key, in fallible_read_node() argument
538 dbg_tnck(key, "LEB %d:%d, key ", zbr->lnum, zbr->offs); in fallible_read_node()
540 ret = try_read_node(c, node, key_type(c, key), zbr); in fallible_read_node()
545 /* All nodes have key in the same place */ in fallible_read_node()
546 key_read(c, &dent->key, &node_key); in fallible_read_node()
547 if (keys_cmp(c, key, &node_key) != 0) in fallible_read_node()
550 if (ret == 0 && c->replaying) in fallible_read_node()
551 dbg_mntk(key, "dangling branch LEB %d:%d len %d, key ", in fallible_read_node()
552 zbr->lnum, zbr->offs, zbr->len); in fallible_read_node()
557 * matches_name - determine if a direntry or xattr entry matches a given name.
558 * @c: UBIFS file-system description object
565 * of failure, a negative error code is returned.
574 if (!zbr->leaf) { in matches_name()
575 dent = kmalloc(zbr->len, GFP_NOFS); in matches_name()
577 return -ENOMEM; in matches_name()
588 dent = zbr->leaf; in matches_name()
590 nlen = le16_to_cpu(dent->nlen); in matches_name()
591 err = memcmp(dent->name, fname_name(nm), min_t(int, nlen, fname_len(nm))); in matches_name()
610 * get_znode - get a TNC znode that may not be loaded yet.
611 * @c: UBIFS file-system description object
615 * This function returns the znode or a negative error code.
622 zbr = &znode->zbranch[n]; in get_znode()
623 if (zbr->znode) in get_znode()
624 znode = zbr->znode; in get_znode()
631 * tnc_next - find next TNC entry.
632 * @c: UBIFS file-system description object
636 * This function returns %0 if the next TNC entry is found, %-ENOENT if there is
637 * no next entry, or a negative error code otherwise.
645 if (nn < znode->child_cnt) { in tnc_next()
652 zp = znode->parent; in tnc_next()
654 return -ENOENT; in tnc_next()
655 nn = znode->iip + 1; in tnc_next()
657 if (nn < znode->child_cnt) { in tnc_next()
661 while (znode->level != 0) { in tnc_next()
676 * tnc_prev - find previous TNC entry.
677 * @c: UBIFS file-system description object
681 * This function returns %0 if the previous TNC entry is found, %-ENOENT if
682 * there is no next entry, or a negative error code otherwise.
690 *n = nn - 1; in tnc_prev()
696 zp = znode->parent; in tnc_prev()
698 return -ENOENT; in tnc_prev()
699 nn = znode->iip - 1; in tnc_prev()
705 while (znode->level != 0) { in tnc_prev()
706 nn = znode->child_cnt - 1; in tnc_prev()
711 nn = znode->child_cnt - 1; in tnc_prev()
721 * resolve_collision - resolve a collision.
722 * @c: UBIFS file-system description object
723 * @key: key of a directory or extended attribute entry
728 * This function is called for "hashed" keys to make sure that the found key
733 * This means that @n may be set to %-1 if the leftmost key in @zn is the
734 * previous one. A negative error code is returned on failures.
736 static int resolve_collision(struct ubifs_info *c, const union ubifs_key *key, in resolve_collision() argument
742 err = matches_name(c, &(*zn)->zbranch[*n], nm); in resolve_collision()
752 if (err == -ENOENT) { in resolve_collision()
754 *n = -1; in resolve_collision()
759 if (keys_cmp(c, &(*zn)->zbranch[*n].key, key)) { in resolve_collision()
768 * ---------------------- in resolve_collision()
770 * ----------------------- in resolve_collision()
773 * ------------ ------------ in resolve_collision()
775 * ------------ ------------ in resolve_collision()
787 * 'tnc_insert()' would correct the parent key. in resolve_collision()
789 if (*n == (*zn)->child_cnt - 1) { in resolve_collision()
794 if (err == -ENOENT) in resolve_collision()
795 err = -EINVAL; in resolve_collision()
799 *n = -1; in resolve_collision()
803 err = matches_name(c, &(*zn)->zbranch[*n], nm); in resolve_collision()
819 if (err == -ENOENT) in resolve_collision()
823 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision()
825 err = matches_name(c, &znode->zbranch[nn], nm); in resolve_collision()
840 * fallible_matches_name - determine if a dent matches a given name.
841 * @c: UBIFS file-system description object
852 * error code is returned in case of failure.
862 if (!zbr->leaf) { in fallible_matches_name()
863 dent = kmalloc(zbr->len, GFP_NOFS); in fallible_matches_name()
865 return -ENOMEM; in fallible_matches_name()
867 err = fallible_read_node(c, &zbr->key, zbr, dent); in fallible_matches_name()
881 dent = zbr->leaf; in fallible_matches_name()
883 nlen = le16_to_cpu(dent->nlen); in fallible_matches_name()
884 err = memcmp(dent->name, fname_name(nm), min_t(int, nlen, fname_len(nm))); in fallible_matches_name()
903 * fallible_resolve_collision - resolve a collision even if nodes are missing.
904 * @c: UBIFS file-system description object
905 * @key: key
909 * @adding: indicates caller is adding a key to the TNC
914 * Garbage-collected and the commit was not done. A branch that refers to a node
922 * o a negative error code is returned in case of failure.
925 const union ubifs_key *key, in fallible_resolve_collision() argument
933 cmp = fallible_matches_name(c, &znode->zbranch[nn], nm); in fallible_resolve_collision()
944 * branch - to the left or to the right. Well, let's try left. in fallible_resolve_collision()
954 if (err == -ENOENT) { in fallible_resolve_collision()
956 *n = -1; in fallible_resolve_collision()
961 if (keys_cmp(c, &(*zn)->zbranch[*n].key, key)) { in fallible_resolve_collision()
963 if (*n == (*zn)->child_cnt - 1) { in fallible_resolve_collision()
968 if (err == -ENOENT) in fallible_resolve_collision()
969 err = -EINVAL; in fallible_resolve_collision()
973 *n = -1; in fallible_resolve_collision()
977 err = fallible_matches_name(c, &(*zn)->zbranch[*n], nm); in fallible_resolve_collision()
1002 if (err == -ENOENT) in fallible_resolve_collision()
1006 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in fallible_resolve_collision()
1008 err = fallible_matches_name(c, &znode->zbranch[nn], nm); in fallible_resolve_collision()
1028 dbg_mntk(key, "dangling match LEB %d:%d len %d key ", in fallible_resolve_collision()
1029 o_znode->zbranch[o_n].lnum, o_znode->zbranch[o_n].offs, in fallible_resolve_collision()
1030 o_znode->zbranch[o_n].len); in fallible_resolve_collision()
1037 * matches_position - determine if a zbranch matches a given position.
1046 if (zbr->lnum == lnum && zbr->offs == offs) in matches_position()
1053 * resolve_collision_directly - resolve a collision directly.
1054 * @c: UBIFS file-system description object
1055 * @key: key of directory entry
1067 * previous directory entry. Otherwise a negative error code is returned.
1070 const union ubifs_key *key, in resolve_collision_directly() argument
1079 if (matches_position(&znode->zbranch[nn], lnum, offs)) in resolve_collision_directly()
1085 if (err == -ENOENT) in resolve_collision_directly()
1089 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision_directly()
1091 if (matches_position(&znode->zbranch[nn], lnum, offs)) { in resolve_collision_directly()
1103 if (err == -ENOENT) in resolve_collision_directly()
1107 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision_directly()
1111 if (matches_position(&znode->zbranch[nn], lnum, offs)) in resolve_collision_directly()
1117 * dirty_cow_bottom_up - dirty a znode and its ancestors.
1118 * @c: UBIFS file-system description object
1121 * If we do not have a unique key that resides in a znode, then we cannot
1130 int *path = c->bottom_up_buf, p = 0; in dirty_cow_bottom_up()
1132 ubifs_assert(c, c->zroot.znode); in dirty_cow_bottom_up()
1134 if (c->zroot.znode->level > BOTTOM_UP_HEIGHT) { in dirty_cow_bottom_up()
1135 kfree(c->bottom_up_buf); in dirty_cow_bottom_up()
1136 c->bottom_up_buf = kmalloc_array(c->zroot.znode->level, in dirty_cow_bottom_up()
1139 if (!c->bottom_up_buf) in dirty_cow_bottom_up()
1140 return ERR_PTR(-ENOMEM); in dirty_cow_bottom_up()
1141 path = c->bottom_up_buf; in dirty_cow_bottom_up()
1143 if (c->zroot.znode->level) { in dirty_cow_bottom_up()
1148 zp = znode->parent; in dirty_cow_bottom_up()
1151 n = znode->iip; in dirty_cow_bottom_up()
1152 ubifs_assert(c, p < c->zroot.znode->level); in dirty_cow_bottom_up()
1154 if (!zp->cnext && ubifs_zn_dirty(znode)) in dirty_cow_bottom_up()
1164 zp = znode->parent; in dirty_cow_bottom_up()
1166 ubifs_assert(c, path[p - 1] >= 0); in dirty_cow_bottom_up()
1167 ubifs_assert(c, path[p - 1] < zp->child_cnt); in dirty_cow_bottom_up()
1168 zbr = &zp->zbranch[path[--p]]; in dirty_cow_bottom_up()
1171 ubifs_assert(c, znode == c->zroot.znode); in dirty_cow_bottom_up()
1172 znode = dirty_cow_znode(c, &c->zroot); in dirty_cow_bottom_up()
1176 ubifs_assert(c, path[p - 1] >= 0); in dirty_cow_bottom_up()
1177 ubifs_assert(c, path[p - 1] < znode->child_cnt); in dirty_cow_bottom_up()
1178 znode = znode->zbranch[path[p - 1]].znode; in dirty_cow_bottom_up()
1185 * ubifs_lookup_level0 - search for zero-level znode.
1186 * @c: UBIFS file-system description object
1187 * @key: key to lookup
1191 * This function looks up the TNC tree and search for zero-level znode which
1192 * refers key @key. The found zero-level znode is returned in @zn. There are 3
1194 * o exact match, i.e. the found zero-level znode contains key @key, then %1
1196 * o not exact match, which means that zero-level znode does not contain
1197 * @key, then %0 is returned and slot number of the closest branch or %-1
1199 * o @key is so small that it is even less than the lowest key of the
1200 * leftmost zero-level node, then %0 is returned and %0 is stored in @n.
1204 * case of failure, a negative error code is returned.
1206 int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key, in ubifs_lookup_level0() argument
1213 dbg_tnck(key, "search key "); in ubifs_lookup_level0()
1214 ubifs_assert(c, key_type(c, key) < UBIFS_INVALID_KEY); in ubifs_lookup_level0()
1216 znode = c->zroot.znode; in ubifs_lookup_level0()
1218 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in ubifs_lookup_level0()
1223 znode->time = time; in ubifs_lookup_level0()
1228 exact = ubifs_search_zbranch(c, znode, key, n); in ubifs_lookup_level0()
1230 if (znode->level == 0) in ubifs_lookup_level0()
1235 zbr = &znode->zbranch[*n]; in ubifs_lookup_level0()
1237 if (zbr->znode) { in ubifs_lookup_level0()
1238 znode->time = time; in ubifs_lookup_level0()
1239 znode = zbr->znode; in ubifs_lookup_level0()
1250 if (exact || !is_hash_key(c, key) || *n != -1) { in ubifs_lookup_level0()
1251 dbg_tnc("found %d, lvl %d, n %d", exact, znode->level, *n); in ubifs_lookup_level0()
1256 * Here is a tricky place. We have not found the key and this is a in ubifs_lookup_level0()
1257 * "hashed" key, which may collide. The rest of the code deals with in ubifs_lookup_level0()
1272 * In the examples, if we are looking for key "5", we may reach nodes in ubifs_lookup_level0()
1274 * left and see if there is "5" key there. If there is, we have to in ubifs_lookup_level0()
1278 * elements which are equivalent to the next key in the parent in the in ubifs_lookup_level0()
1286 * And this becomes what is at the first "picture" after key "5" marked in ubifs_lookup_level0()
1289 * removing the leftmost key, we would have to correct the key of the in ubifs_lookup_level0()
1291 * if we changed the leftmost key of the parent znode, the garbage in ubifs_lookup_level0()
1293 * indexing LEBs). Although we already have an additional RB-tree where in ubifs_lookup_level0()
1299 if (err == -ENOENT) { in ubifs_lookup_level0()
1300 dbg_tnc("found 0, lvl %d, n -1", znode->level); in ubifs_lookup_level0()
1301 *n = -1; in ubifs_lookup_level0()
1306 if (keys_cmp(c, key, &znode->zbranch[*n].key)) { in ubifs_lookup_level0()
1307 dbg_tnc("found 0, lvl %d, n -1", znode->level); in ubifs_lookup_level0()
1308 *n = -1; in ubifs_lookup_level0()
1312 dbg_tnc("found 1, lvl %d, n %d", znode->level, *n); in ubifs_lookup_level0()
1318 * lookup_level0_dirty - search for zero-level znode dirtying.
1319 * @c: UBIFS file-system description object
1320 * @key: key to lookup
1324 * This function looks up the TNC tree and search for zero-level znode which
1325 * refers key @key. The found zero-level znode is returned in @zn. There are 3
1327 * o exact match, i.e. the found zero-level znode contains key @key, then %1
1329 * o not exact match, which means that zero-level znode does not contain @key
1332 * o @key is so small that it is even less than the lowest key of the
1333 * leftmost zero-level node, then %0 is returned and %-1 is stored in @n.
1335 * Additionally all znodes in the path from the root to the located zero-level
1340 * case of failure, a negative error code is returned.
1342 static int lookup_level0_dirty(struct ubifs_info *c, const union ubifs_key *key, in lookup_level0_dirty() argument
1349 dbg_tnck(key, "search and dirty key "); in lookup_level0_dirty()
1351 znode = c->zroot.znode; in lookup_level0_dirty()
1353 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in lookup_level0_dirty()
1358 znode = dirty_cow_znode(c, &c->zroot); in lookup_level0_dirty()
1362 znode->time = time; in lookup_level0_dirty()
1367 exact = ubifs_search_zbranch(c, znode, key, n); in lookup_level0_dirty()
1369 if (znode->level == 0) in lookup_level0_dirty()
1374 zbr = &znode->zbranch[*n]; in lookup_level0_dirty()
1376 if (zbr->znode) { in lookup_level0_dirty()
1377 znode->time = time; in lookup_level0_dirty()
1394 if (exact || !is_hash_key(c, key) || *n != -1) { in lookup_level0_dirty()
1395 dbg_tnc("found %d, lvl %d, n %d", exact, znode->level, *n); in lookup_level0_dirty()
1401 * code. in lookup_level0_dirty()
1404 if (err == -ENOENT) { in lookup_level0_dirty()
1405 *n = -1; in lookup_level0_dirty()
1406 dbg_tnc("found 0, lvl %d, n -1", znode->level); in lookup_level0_dirty()
1411 if (keys_cmp(c, key, &znode->zbranch[*n].key)) { in lookup_level0_dirty()
1412 *n = -1; in lookup_level0_dirty()
1413 dbg_tnc("found 0, lvl %d, n -1", znode->level); in lookup_level0_dirty()
1417 if (znode->cnext || !ubifs_zn_dirty(znode)) { in lookup_level0_dirty()
1423 dbg_tnc("found 1, lvl %d, n %d", znode->level, *n); in lookup_level0_dirty()
1429 * maybe_leb_gced - determine if a LEB may have been garbage collected.
1430 * @c: UBIFS file-system description object
1442 gced_lnum = c->gced_lnum; in maybe_leb_gced()
1444 gc_seq2 = c->gc_seq; in maybe_leb_gced()
1456 if (gced_lnum != c->gced_lnum) in maybe_leb_gced()
1465 * ubifs_tnc_locate - look up a file-system node and return it and its location.
1466 * @c: UBIFS file-system description object
1467 * @key: node key to lookup
1472 * This function looks up and reads node with key @key. The caller has to make
1474 * of success, %-ENOENT if the node was not found, and a negative error code in
1477 int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_locate() argument
1485 mutex_lock(&c->tnc_mutex); in ubifs_tnc_locate()
1486 found = ubifs_lookup_level0(c, key, &znode, &n); in ubifs_tnc_locate()
1488 err = -ENOENT; in ubifs_tnc_locate()
1494 zt = &znode->zbranch[n]; in ubifs_tnc_locate()
1496 *lnum = zt->lnum; in ubifs_tnc_locate()
1497 *offs = zt->offs; in ubifs_tnc_locate()
1499 if (is_hash_key(c, key)) { in ubifs_tnc_locate()
1512 zbr = znode->zbranch[n]; in ubifs_tnc_locate()
1513 gc_seq1 = c->gc_seq; in ubifs_tnc_locate()
1514 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_locate()
1522 err = fallible_read_node(c, key, &zbr, node); in ubifs_tnc_locate()
1534 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_locate()
1539 * ubifs_tnc_get_bu_keys - lookup keys for bulk-read.
1540 * @c: UBIFS file-system description object
1541 * @bu: bulk-read parameters and results
1545 * and a negative error code in case of failure.
1547 * Note, if the bulk-read buffer length (@bu->buf_len) is known, this function
1548 * makes sure bulk-read nodes fit the buffer. Otherwise, this function prepares
1549 * maximum possible amount of nodes for bulk-read.
1553 int n, err = 0, lnum = -1, offs; in ubifs_tnc_get_bu_keys()
1555 unsigned int block = key_block(c, &bu->key); in ubifs_tnc_get_bu_keys()
1558 bu->cnt = 0; in ubifs_tnc_get_bu_keys()
1559 bu->blk_cnt = 0; in ubifs_tnc_get_bu_keys()
1560 bu->eof = 0; in ubifs_tnc_get_bu_keys()
1562 mutex_lock(&c->tnc_mutex); in ubifs_tnc_get_bu_keys()
1563 /* Find first key */ in ubifs_tnc_get_bu_keys()
1564 err = ubifs_lookup_level0(c, &bu->key, &znode, &n); in ubifs_tnc_get_bu_keys()
1568 /* Key found */ in ubifs_tnc_get_bu_keys()
1569 len = znode->zbranch[n].len; in ubifs_tnc_get_bu_keys()
1571 if (len > bu->buf_len) { in ubifs_tnc_get_bu_keys()
1572 err = -EINVAL; in ubifs_tnc_get_bu_keys()
1575 /* Add this key */ in ubifs_tnc_get_bu_keys()
1576 bu->zbranch[bu->cnt++] = znode->zbranch[n]; in ubifs_tnc_get_bu_keys()
1577 bu->blk_cnt += 1; in ubifs_tnc_get_bu_keys()
1578 lnum = znode->zbranch[n].lnum; in ubifs_tnc_get_bu_keys()
1579 offs = ALIGN(znode->zbranch[n].offs + len, 8); in ubifs_tnc_get_bu_keys()
1583 union ubifs_key *key; in ubifs_tnc_get_bu_keys() local
1586 /* Find next key */ in ubifs_tnc_get_bu_keys()
1590 zbr = &znode->zbranch[n]; in ubifs_tnc_get_bu_keys()
1591 key = &zbr->key; in ubifs_tnc_get_bu_keys()
1592 /* See if there is another data key for this file */ in ubifs_tnc_get_bu_keys()
1593 if (key_inum(c, key) != key_inum(c, &bu->key) || in ubifs_tnc_get_bu_keys()
1594 key_type(c, key) != UBIFS_DATA_KEY) { in ubifs_tnc_get_bu_keys()
1595 err = -ENOENT; in ubifs_tnc_get_bu_keys()
1599 /* First key found */ in ubifs_tnc_get_bu_keys()
1600 lnum = zbr->lnum; in ubifs_tnc_get_bu_keys()
1601 offs = ALIGN(zbr->offs + zbr->len, 8); in ubifs_tnc_get_bu_keys()
1602 len = zbr->len; in ubifs_tnc_get_bu_keys()
1603 if (len > bu->buf_len) { in ubifs_tnc_get_bu_keys()
1604 err = -EINVAL; in ubifs_tnc_get_bu_keys()
1612 if (zbr->lnum != lnum || zbr->offs != offs) in ubifs_tnc_get_bu_keys()
1614 offs += ALIGN(zbr->len, 8); in ubifs_tnc_get_bu_keys()
1615 len = ALIGN(len, 8) + zbr->len; in ubifs_tnc_get_bu_keys()
1617 if (len > bu->buf_len) in ubifs_tnc_get_bu_keys()
1621 next_block = key_block(c, key); in ubifs_tnc_get_bu_keys()
1622 bu->blk_cnt += (next_block - block - 1); in ubifs_tnc_get_bu_keys()
1623 if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1626 /* Add this key */ in ubifs_tnc_get_bu_keys()
1627 bu->zbranch[bu->cnt++] = *zbr; in ubifs_tnc_get_bu_keys()
1628 bu->blk_cnt += 1; in ubifs_tnc_get_bu_keys()
1630 if (bu->cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1632 if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1636 if (err == -ENOENT) { in ubifs_tnc_get_bu_keys()
1637 bu->eof = 1; in ubifs_tnc_get_bu_keys()
1640 bu->gc_seq = c->gc_seq; in ubifs_tnc_get_bu_keys()
1641 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_get_bu_keys()
1645 * An enormous hole could cause bulk-read to encompass too many in ubifs_tnc_get_bu_keys()
1648 if (bu->blk_cnt > UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1649 bu->blk_cnt = UBIFS_MAX_BULK_READ; in ubifs_tnc_get_bu_keys()
1651 * Ensure that bulk-read covers a whole number of page cache in ubifs_tnc_get_bu_keys()
1655 !(bu->blk_cnt & (UBIFS_BLOCKS_PER_PAGE - 1))) in ubifs_tnc_get_bu_keys()
1657 if (bu->eof) { in ubifs_tnc_get_bu_keys()
1659 bu->blk_cnt += UBIFS_BLOCKS_PER_PAGE - 1; in ubifs_tnc_get_bu_keys()
1663 block = key_block(c, &bu->key) + bu->blk_cnt; in ubifs_tnc_get_bu_keys()
1664 block &= ~(UBIFS_BLOCKS_PER_PAGE - 1); in ubifs_tnc_get_bu_keys()
1665 while (bu->cnt) { in ubifs_tnc_get_bu_keys()
1666 if (key_block(c, &bu->zbranch[bu->cnt - 1].key) < block) in ubifs_tnc_get_bu_keys()
1668 bu->cnt -= 1; in ubifs_tnc_get_bu_keys()
1674 * read_wbuf - bulk-read from a LEB with a wbuf.
1681 * This functions returns %0 on success or a negative error code on failure.
1686 const struct ubifs_info *c = wbuf->c; in read_wbuf()
1690 ubifs_assert(c, wbuf && lnum >= 0 && lnum < c->leb_cnt && offs >= 0); in read_wbuf()
1691 ubifs_assert(c, !(offs & 7) && offs < c->leb_size); in read_wbuf()
1692 ubifs_assert(c, offs + len <= c->leb_size); in read_wbuf()
1694 spin_lock(&wbuf->lock); in read_wbuf()
1695 overlap = (lnum == wbuf->lnum && offs + len > wbuf->offs); in read_wbuf()
1697 /* We may safely unlock the write-buffer and read the data */ in read_wbuf()
1698 spin_unlock(&wbuf->lock); in read_wbuf()
1703 rlen = wbuf->offs - offs; in read_wbuf()
1707 /* Copy the rest from the write-buffer */ in read_wbuf()
1708 memcpy(buf + rlen, wbuf->buf + offs + rlen - wbuf->offs, len - rlen); in read_wbuf()
1709 spin_unlock(&wbuf->lock); in read_wbuf()
1712 /* Read everything that goes before write-buffer */ in read_wbuf()
1719 * validate_data_node - validate data nodes for bulk-read.
1720 * @c: UBIFS file-system description object
1724 * This functions returns %0 on success or a negative error code on failure.
1733 if (ch->node_type != UBIFS_DATA_NODE) { in validate_data_node()
1735 ch->node_type, UBIFS_DATA_NODE); in validate_data_node()
1739 err = ubifs_check_node(c, buf, zbr->len, zbr->lnum, zbr->offs, 0, 0); in validate_data_node()
1745 err = ubifs_node_check_hash(c, buf, zbr->hash); in validate_data_node()
1747 ubifs_bad_hash(c, buf, zbr->hash, zbr->lnum, zbr->offs); in validate_data_node()
1751 len = le32_to_cpu(ch->len); in validate_data_node()
1752 if (len != zbr->len) { in validate_data_node()
1753 ubifs_err(c, "bad node length %d, expected %d", len, zbr->len); in validate_data_node()
1757 /* Make sure the key of the read node is correct */ in validate_data_node()
1759 if (!keys_eq(c, &zbr->key, &key1)) { in validate_data_node()
1760 ubifs_err(c, "bad key in node at LEB %d:%d", in validate_data_node()
1761 zbr->lnum, zbr->offs); in validate_data_node()
1762 dbg_tnck(&zbr->key, "looked for key "); in validate_data_node()
1763 dbg_tnck(&key1, "found node's key "); in validate_data_node()
1770 err = -EINVAL; in validate_data_node()
1772 ubifs_err(c, "bad node at LEB %d:%d", zbr->lnum, zbr->offs); in validate_data_node()
1773 ubifs_dump_node(c, buf, zbr->len); in validate_data_node()
1779 * ubifs_tnc_bulk_read - read a number of data nodes in one go.
1780 * @c: UBIFS file-system description object
1781 * @bu: bulk-read parameters and results
1785 * -EAGAIN to indicate a race with GC, or another negative error code on
1790 int lnum = bu->zbranch[0].lnum, offs = bu->zbranch[0].offs, len, err, i; in ubifs_tnc_bulk_read()
1794 len = bu->zbranch[bu->cnt - 1].offs; in ubifs_tnc_bulk_read()
1795 len += bu->zbranch[bu->cnt - 1].len - offs; in ubifs_tnc_bulk_read()
1796 if (len > bu->buf_len) { in ubifs_tnc_bulk_read()
1797 ubifs_err(c, "buffer too small %d vs %d", bu->buf_len, len); in ubifs_tnc_bulk_read()
1798 return -EINVAL; in ubifs_tnc_bulk_read()
1804 err = read_wbuf(wbuf, bu->buf, len, lnum, offs); in ubifs_tnc_bulk_read()
1806 err = ubifs_leb_read(c, lnum, bu->buf, offs, len, 0); in ubifs_tnc_bulk_read()
1809 if (maybe_leb_gced(c, lnum, bu->gc_seq)) in ubifs_tnc_bulk_read()
1810 return -EAGAIN; in ubifs_tnc_bulk_read()
1812 if (err && err != -EBADMSG) { in ubifs_tnc_bulk_read()
1816 dbg_tnck(&bu->key, "key "); in ubifs_tnc_bulk_read()
1821 buf = bu->buf; in ubifs_tnc_bulk_read()
1822 for (i = 0; i < bu->cnt; i++) { in ubifs_tnc_bulk_read()
1823 err = validate_data_node(c, buf, &bu->zbranch[i]); in ubifs_tnc_bulk_read()
1826 buf = buf + ALIGN(bu->zbranch[i].len, 8); in ubifs_tnc_bulk_read()
1833 * do_lookup_nm- look up a "hashed" node.
1834 * @c: UBIFS file-system description object
1835 * @key: node key to lookup
1839 * This function looks up and reads a node which contains name hash in the key.
1841 * key, so we have to sequentially look to all of them until the needed one is
1842 * found. This function returns zero in case of success, %-ENOENT if the node
1843 * was not found, and a negative error code in case of failure.
1845 static int do_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, in do_lookup_nm() argument
1851 dbg_tnck(key, "key "); in do_lookup_nm()
1852 mutex_lock(&c->tnc_mutex); in do_lookup_nm()
1853 found = ubifs_lookup_level0(c, key, &znode, &n); in do_lookup_nm()
1855 err = -ENOENT; in do_lookup_nm()
1864 err = resolve_collision(c, key, &znode, &n, nm); in do_lookup_nm()
1869 err = -ENOENT; in do_lookup_nm()
1873 err = tnc_read_hashed_node(c, &znode->zbranch[n], node); in do_lookup_nm()
1876 mutex_unlock(&c->tnc_mutex); in do_lookup_nm()
1881 * ubifs_tnc_lookup_nm - look up a "hashed" node.
1882 * @c: UBIFS file-system description object
1883 * @key: node key to lookup
1887 * This function looks up and reads a node which contains name hash in the key.
1889 * key, so we have to sequentially look to all of them until the needed one is
1890 * found. This function returns zero in case of success, %-ENOENT if the node
1891 * was not found, and a negative error code in case of failure.
1893 int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_lookup_nm() argument
1903 err = ubifs_tnc_lookup(c, key, node); in ubifs_tnc_lookup_nm()
1907 len = le16_to_cpu(dent->nlen); in ubifs_tnc_lookup_nm()
1908 if (fname_len(nm) == len && !memcmp(dent->name, fname_name(nm), len)) in ubifs_tnc_lookup_nm()
1916 return do_lookup_nm(c, key, node, nm); in ubifs_tnc_lookup_nm()
1919 static int search_dh_cookie(struct ubifs_info *c, const union ubifs_key *key, in search_dh_cookie() argument
1935 zbr = &znode->zbranch[*n]; in search_dh_cookie()
1936 dkey = &zbr->key; in search_dh_cookie()
1938 if (key_inum(c, dkey) != key_inum(c, key) || in search_dh_cookie()
1939 key_type(c, dkey) != key_type(c, key)) { in search_dh_cookie()
1940 return -ENOENT; in search_dh_cookie()
1947 if (key_hash(c, key) == key_hash(c, dkey) && in search_dh_cookie()
1948 le32_to_cpu(dent->cookie) == cookie) { in search_dh_cookie()
1959 static int do_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, in do_lookup_dh() argument
1966 ubifs_assert(c, is_hash_key(c, key)); in do_lookup_dh()
1968 lowest_dent_key(c, &start_key, key_inum(c, key)); in do_lookup_dh()
1970 mutex_lock(&c->tnc_mutex); in do_lookup_dh()
1975 err = search_dh_cookie(c, key, dent, cookie, &znode, &n, err); in do_lookup_dh()
1978 mutex_unlock(&c->tnc_mutex); in do_lookup_dh()
1983 * ubifs_tnc_lookup_dh - look up a "double hashed" node.
1984 * @c: UBIFS file-system description object
1985 * @key: node key to lookup
1989 * This function looks up and reads a node which contains name hash in the key.
1991 * key, so we have to sequentially look to all of them until the needed one
1993 * This function returns zero in case of success, %-ENOENT if the node
1994 * was not found, and a negative error code in case of failure.
1996 int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_lookup_dh() argument
2002 if (!c->double_hash) in ubifs_tnc_lookup_dh()
2003 return -EOPNOTSUPP; in ubifs_tnc_lookup_dh()
2009 err = ubifs_tnc_lookup(c, key, node); in ubifs_tnc_lookup_dh()
2013 if (le32_to_cpu(dent->cookie) == cookie) in ubifs_tnc_lookup_dh()
2020 return do_lookup_dh(c, key, node, cookie); in ubifs_tnc_lookup_dh()
2024 * correct_parent_keys - correct parent znodes' keys.
2025 * @c: UBIFS file-system description object
2028 * This is a helper function for 'tnc_insert()'. When the key of the leftmost
2035 union ubifs_key *key, *key1; in correct_parent_keys() local
2037 ubifs_assert(c, znode->parent); in correct_parent_keys()
2038 ubifs_assert(c, znode->iip == 0); in correct_parent_keys()
2040 key = &znode->zbranch[0].key; in correct_parent_keys()
2041 key1 = &znode->parent->zbranch[0].key; in correct_parent_keys()
2043 while (keys_cmp(c, key, key1) < 0) { in correct_parent_keys()
2044 key_copy(c, key, key1); in correct_parent_keys()
2045 znode = znode->parent; in correct_parent_keys()
2046 znode->alt = 1; in correct_parent_keys()
2047 if (!znode->parent || znode->iip) in correct_parent_keys()
2049 key1 = &znode->parent->zbranch[0].key; in correct_parent_keys()
2054 * insert_zbranch - insert a zbranch into a znode.
2055 * @c: UBIFS file-system description object
2062 * zbranch has to be inserted to the @znode->zbranches[]' array at the @n-th
2072 if (znode->level) { in insert_zbranch()
2073 for (i = znode->child_cnt; i > n; i--) { in insert_zbranch()
2074 znode->zbranch[i] = znode->zbranch[i - 1]; in insert_zbranch()
2075 if (znode->zbranch[i].znode) in insert_zbranch()
2076 znode->zbranch[i].znode->iip = i; in insert_zbranch()
2078 if (zbr->znode) in insert_zbranch()
2079 zbr->znode->iip = n; in insert_zbranch()
2081 for (i = znode->child_cnt; i > n; i--) in insert_zbranch()
2082 znode->zbranch[i] = znode->zbranch[i - 1]; in insert_zbranch()
2084 znode->zbranch[n] = *zbr; in insert_zbranch()
2085 znode->child_cnt += 1; in insert_zbranch()
2088 * After inserting at slot zero, the lower bound of the key range of in insert_zbranch()
2090 * then the upper bound of the key range may change, and furthermore in insert_zbranch()
2093 * TNC using the key from the index node on flash. That is bad because in insert_zbranch()
2102 znode->alt = 1; in insert_zbranch()
2106 * tnc_insert - insert a node into TNC.
2107 * @c: UBIFS file-system description object
2115 * error code in case of failure.
2122 union ubifs_key *key = &zbr->key, *key1; in tnc_insert() local
2124 ubifs_assert(c, n >= 0 && n <= c->fanout); in tnc_insert()
2128 zp = znode->parent; in tnc_insert()
2129 if (znode->child_cnt < c->fanout) { in tnc_insert()
2130 ubifs_assert(c, n != c->fanout); in tnc_insert()
2131 dbg_tnck(key, "inserted at %d level %d, key ", n, znode->level); in tnc_insert()
2135 /* Ensure parent's key is correct */ in tnc_insert()
2136 if (n == 0 && zp && znode->iip == 0) in tnc_insert()
2146 dbg_tnck(key, "splitting level %d, key ", znode->level); in tnc_insert()
2148 if (znode->alt) in tnc_insert()
2150 * We can no longer be sure of finding this znode by key, so we in tnc_insert()
2155 zn = kzalloc(c->max_znode_sz, GFP_NOFS); in tnc_insert()
2157 return -ENOMEM; in tnc_insert()
2158 zn->parent = zp; in tnc_insert()
2159 zn->level = znode->level; in tnc_insert()
2162 if (znode->level == 0 && key_type(c, key) == UBIFS_DATA_KEY) { in tnc_insert()
2164 if (n == c->fanout) { in tnc_insert()
2165 key1 = &znode->zbranch[n - 1].key; in tnc_insert()
2166 if (key_inum(c, key1) == key_inum(c, key) && in tnc_insert()
2171 } else if (appending && n != c->fanout) { in tnc_insert()
2175 if (n >= (c->fanout + 1) / 2) { in tnc_insert()
2176 key1 = &znode->zbranch[0].key; in tnc_insert()
2177 if (key_inum(c, key1) == key_inum(c, key) && in tnc_insert()
2179 key1 = &znode->zbranch[n].key; in tnc_insert()
2180 if (key_inum(c, key1) != key_inum(c, key) || in tnc_insert()
2183 move = c->fanout - keep; in tnc_insert()
2192 keep = c->fanout; in tnc_insert()
2195 keep = (c->fanout + 1) / 2; in tnc_insert()
2196 move = c->fanout - keep; in tnc_insert()
2208 keep -= 1; in tnc_insert()
2212 n -= keep; in tnc_insert()
2213 /* Re-parent */ in tnc_insert()
2214 if (zn->level != 0) in tnc_insert()
2215 zbr->znode->parent = zn; in tnc_insert()
2220 __set_bit(DIRTY_ZNODE, &zn->flags); in tnc_insert()
2221 atomic_long_inc(&c->dirty_zn_cnt); in tnc_insert()
2223 zn->child_cnt = move; in tnc_insert()
2224 znode->child_cnt = keep; in tnc_insert()
2230 zn->zbranch[i] = znode->zbranch[keep + i]; in tnc_insert()
2231 /* Re-parent */ in tnc_insert()
2232 if (zn->level != 0) in tnc_insert()
2233 if (zn->zbranch[i].znode) { in tnc_insert()
2234 zn->zbranch[i].znode->parent = zn; in tnc_insert()
2235 zn->zbranch[i].znode->iip = i; in tnc_insert()
2239 /* Insert new key and branch */ in tnc_insert()
2240 dbg_tnck(key, "inserting at %d level %d, key ", n, zn->level); in tnc_insert()
2246 if (n == 0 && zi == znode && znode->iip == 0) in tnc_insert()
2250 n = znode->iip + 1; in tnc_insert()
2253 zbr->key = zn->zbranch[0].key; in tnc_insert()
2254 zbr->znode = zn; in tnc_insert()
2255 zbr->lnum = 0; in tnc_insert()
2256 zbr->offs = 0; in tnc_insert()
2257 zbr->len = 0; in tnc_insert()
2264 dbg_tnc("creating new zroot at level %d", znode->level + 1); in tnc_insert()
2266 zi = kzalloc(c->max_znode_sz, GFP_NOFS); in tnc_insert()
2268 return -ENOMEM; in tnc_insert()
2270 zi->child_cnt = 2; in tnc_insert()
2271 zi->level = znode->level + 1; in tnc_insert()
2273 __set_bit(DIRTY_ZNODE, &zi->flags); in tnc_insert()
2274 atomic_long_inc(&c->dirty_zn_cnt); in tnc_insert()
2276 zi->zbranch[0].key = znode->zbranch[0].key; in tnc_insert()
2277 zi->zbranch[0].znode = znode; in tnc_insert()
2278 zi->zbranch[0].lnum = c->zroot.lnum; in tnc_insert()
2279 zi->zbranch[0].offs = c->zroot.offs; in tnc_insert()
2280 zi->zbranch[0].len = c->zroot.len; in tnc_insert()
2281 zi->zbranch[1].key = zn->zbranch[0].key; in tnc_insert()
2282 zi->zbranch[1].znode = zn; in tnc_insert()
2284 c->zroot.lnum = 0; in tnc_insert()
2285 c->zroot.offs = 0; in tnc_insert()
2286 c->zroot.len = 0; in tnc_insert()
2287 c->zroot.znode = zi; in tnc_insert()
2289 zn->parent = zi; in tnc_insert()
2290 zn->iip = 1; in tnc_insert()
2291 znode->parent = zi; in tnc_insert()
2292 znode->iip = 0; in tnc_insert()
2298 * ubifs_tnc_add - add a node to TNC.
2299 * @c: UBIFS file-system description object
2300 * @key: key to add
2306 * This function adds a node with key @key to TNC. The node may be new or it may
2307 * obsolete some existing one. Returns %0 on success or negative error code on
2310 int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum, in ubifs_tnc_add() argument
2316 mutex_lock(&c->tnc_mutex); in ubifs_tnc_add()
2317 dbg_tnck(key, "%d:%d, len %d, key ", lnum, offs, len); in ubifs_tnc_add()
2318 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_add()
2327 key_copy(c, key, &zbr.key); in ubifs_tnc_add()
2330 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_add()
2333 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_add()
2334 zbr->lnum = lnum; in ubifs_tnc_add()
2335 zbr->offs = offs; in ubifs_tnc_add()
2336 zbr->len = len; in ubifs_tnc_add()
2337 ubifs_copy_hash(c, hash, zbr->hash); in ubifs_tnc_add()
2342 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add()
2348 * ubifs_tnc_replace - replace a node in the TNC only if the old node is found.
2349 * @c: UBIFS file-system description object
2350 * @key: key to add
2357 * This function replaces a node with key @key in the TNC only if the old node
2359 * Returns %0 on success or negative error code on failure.
2361 int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_replace() argument
2367 mutex_lock(&c->tnc_mutex); in ubifs_tnc_replace()
2368 dbg_tnck(key, "old LEB %d:%d, new LEB %d:%d, len %d, key ", old_lnum, in ubifs_tnc_replace()
2370 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_replace()
2377 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_replace()
2380 if (zbr->lnum == old_lnum && zbr->offs == old_offs) { in ubifs_tnc_replace()
2382 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_replace()
2385 zbr->lnum = lnum; in ubifs_tnc_replace()
2386 zbr->offs = offs; in ubifs_tnc_replace()
2387 zbr->len = len; in ubifs_tnc_replace()
2389 } else if (is_hash_key(c, key)) { in ubifs_tnc_replace()
2390 found = resolve_collision_directly(c, key, &znode, &n, in ubifs_tnc_replace()
2401 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_replace()
2408 zbr = &znode->zbranch[n]; in ubifs_tnc_replace()
2410 err = ubifs_add_dirt(c, zbr->lnum, in ubifs_tnc_replace()
2411 zbr->len); in ubifs_tnc_replace()
2414 zbr->lnum = lnum; in ubifs_tnc_replace()
2415 zbr->offs = offs; in ubifs_tnc_replace()
2416 zbr->len = len; in ubifs_tnc_replace()
2428 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_replace()
2433 * ubifs_tnc_add_nm - add a "hashed" node to TNC.
2434 * @c: UBIFS file-system description object
2435 * @key: key to add
2445 int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_add_nm() argument
2452 mutex_lock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2453 dbg_tnck(key, "LEB %d:%d, key ", lnum, offs); in ubifs_tnc_add_nm()
2454 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_add_nm()
2461 if (c->replaying) in ubifs_tnc_add_nm()
2462 found = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_add_nm()
2465 found = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_add_nm()
2473 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_add_nm()
2482 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_add_nm()
2485 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_add_nm()
2486 zbr->lnum = lnum; in ubifs_tnc_add_nm()
2487 zbr->offs = offs; in ubifs_tnc_add_nm()
2488 zbr->len = len; in ubifs_tnc_add_nm()
2489 ubifs_copy_hash(c, hash, zbr->hash); in ubifs_tnc_add_nm()
2502 key_copy(c, key, &zbr.key); in ubifs_tnc_add_nm()
2506 if (c->replaying) { in ubifs_tnc_add_nm()
2510 * by passing 'ubifs_tnc_remove_nm()' the same key but in ubifs_tnc_add_nm()
2516 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2519 return ubifs_tnc_remove_nm(c, key, &noname); in ubifs_tnc_add_nm()
2526 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2531 * tnc_delete - delete a znode form TNC.
2532 * @c: UBIFS file-system description object
2536 * This function deletes a leaf node from @n-th slot of @znode. Returns zero in
2537 * case of success and a negative error code in case of failure.
2546 ubifs_assert(c, znode->level == 0); in tnc_delete()
2547 ubifs_assert(c, n >= 0 && n < c->fanout); in tnc_delete()
2548 dbg_tnck(&znode->zbranch[n].key, "deleting key "); in tnc_delete()
2550 zbr = &znode->zbranch[n]; in tnc_delete()
2553 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in tnc_delete()
2560 for (i = n; i < znode->child_cnt - 1; i++) in tnc_delete()
2561 znode->zbranch[i] = znode->zbranch[i + 1]; in tnc_delete()
2562 znode->child_cnt -= 1; in tnc_delete()
2564 if (znode->child_cnt > 0) in tnc_delete()
2576 zp = znode->parent; in tnc_delete()
2577 n = znode->iip; in tnc_delete()
2579 atomic_long_dec(&c->dirty_zn_cnt); in tnc_delete()
2585 if (znode->cnext) { in tnc_delete()
2586 __set_bit(OBSOLETE_ZNODE, &znode->flags); in tnc_delete()
2587 atomic_long_inc(&c->clean_zn_cnt); in tnc_delete()
2592 } while (znode->child_cnt == 1); /* while removing last child */ in tnc_delete()
2594 /* Remove from znode, entry n - 1 */ in tnc_delete()
2595 znode->child_cnt -= 1; in tnc_delete()
2596 ubifs_assert(c, znode->level != 0); in tnc_delete()
2597 for (i = n; i < znode->child_cnt; i++) { in tnc_delete()
2598 znode->zbranch[i] = znode->zbranch[i + 1]; in tnc_delete()
2599 if (znode->zbranch[i].znode) in tnc_delete()
2600 znode->zbranch[i].znode->iip = i; in tnc_delete()
2607 if (!znode->parent) { in tnc_delete()
2608 while (znode->child_cnt == 1 && znode->level != 0) { in tnc_delete()
2610 zbr = &znode->zbranch[0]; in tnc_delete()
2617 znode->parent = NULL; in tnc_delete()
2618 znode->iip = 0; in tnc_delete()
2619 if (c->zroot.len) { in tnc_delete()
2620 err = insert_old_idx(c, c->zroot.lnum, in tnc_delete()
2621 c->zroot.offs); in tnc_delete()
2625 c->zroot.lnum = zbr->lnum; in tnc_delete()
2626 c->zroot.offs = zbr->offs; in tnc_delete()
2627 c->zroot.len = zbr->len; in tnc_delete()
2628 c->zroot.znode = znode; in tnc_delete()
2631 atomic_long_dec(&c->dirty_zn_cnt); in tnc_delete()
2633 if (zp->cnext) { in tnc_delete()
2634 __set_bit(OBSOLETE_ZNODE, &zp->flags); in tnc_delete()
2635 atomic_long_inc(&c->clean_zn_cnt); in tnc_delete()
2646 * ubifs_tnc_remove - remove an index entry of a node.
2647 * @c: UBIFS file-system description object
2648 * @key: key of node
2650 * Returns %0 on success or negative error code on failure.
2652 int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key) in ubifs_tnc_remove() argument
2657 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove()
2658 dbg_tnck(key, "key "); in ubifs_tnc_remove()
2659 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove()
2670 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove()
2675 * ubifs_tnc_remove_nm - remove an index entry for a "hashed" node.
2676 * @c: UBIFS file-system description object
2677 * @key: key of node
2680 * Returns %0 on success or negative error code on failure.
2682 int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_remove_nm() argument
2688 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_nm()
2689 dbg_tnck(key, "key "); in ubifs_tnc_remove_nm()
2690 err = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove_nm()
2695 if (c->replaying) in ubifs_tnc_remove_nm()
2696 err = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_remove_nm()
2699 err = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_remove_nm()
2705 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_nm()
2719 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_nm()
2724 * ubifs_tnc_remove_dh - remove an index entry for a "double hashed" node.
2725 * @c: UBIFS file-system description object
2726 * @key: key of node
2729 * Returns %0 on success or negative error code on failure.
2731 int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_remove_dh() argument
2739 if (!c->double_hash) in ubifs_tnc_remove_dh()
2740 return -EOPNOTSUPP; in ubifs_tnc_remove_dh()
2742 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_dh()
2743 err = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove_dh()
2747 zbr = &znode->zbranch[n]; in ubifs_tnc_remove_dh()
2750 err = -ENOMEM; in ubifs_tnc_remove_dh()
2759 if (le32_to_cpu(dent->cookie) != cookie) { in ubifs_tnc_remove_dh()
2762 lowest_dent_key(c, &start_key, key_inum(c, key)); in ubifs_tnc_remove_dh()
2768 err = search_dh_cookie(c, key, dent, cookie, &znode, &n, err); in ubifs_tnc_remove_dh()
2773 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_dh()
2787 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_dh()
2792 * key_in_range - determine if a key falls within a range of keys.
2793 * @c: UBIFS file-system description object
2794 * @key: key to check
2795 * @from_key: lowest key in range
2796 * @to_key: highest key in range
2798 * This function returns %1 if the key is in range and %0 otherwise.
2800 static int key_in_range(struct ubifs_info *c, union ubifs_key *key, in key_in_range() argument
2803 if (keys_cmp(c, key, from_key) < 0) in key_in_range()
2805 if (keys_cmp(c, key, to_key) > 0) in key_in_range()
2811 * ubifs_tnc_remove_range - remove index entries in range.
2812 * @c: UBIFS file-system description object
2813 * @from_key: lowest key to remove
2814 * @to_key: highest key to remove
2818 * code in case of failure.
2825 union ubifs_key *key; in ubifs_tnc_remove_range() local
2827 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_range()
2835 key = from_key; in ubifs_tnc_remove_range()
2838 if (err == -ENOENT) { in ubifs_tnc_remove_range()
2844 key = &znode->zbranch[n].key; in ubifs_tnc_remove_range()
2845 if (!key_in_range(c, key, from_key, to_key)) { in ubifs_tnc_remove_range()
2852 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_range()
2861 for (i = n + 1, k = 0; i < znode->child_cnt; i++, k++) { in ubifs_tnc_remove_range()
2862 key = &znode->zbranch[i].key; in ubifs_tnc_remove_range()
2863 if (!key_in_range(c, key, from_key, to_key)) in ubifs_tnc_remove_range()
2865 lnc_free(&znode->zbranch[i]); in ubifs_tnc_remove_range()
2866 err = ubifs_add_dirt(c, znode->zbranch[i].lnum, in ubifs_tnc_remove_range()
2867 znode->zbranch[i].len); in ubifs_tnc_remove_range()
2872 dbg_tnck(key, "removing key "); in ubifs_tnc_remove_range()
2875 for (i = n + 1 + k; i < znode->child_cnt; i++) in ubifs_tnc_remove_range()
2876 znode->zbranch[i - k] = znode->zbranch[i]; in ubifs_tnc_remove_range()
2877 znode->child_cnt -= k; in ubifs_tnc_remove_range()
2889 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_range()
2894 * ubifs_tnc_remove_ino - remove an inode from TNC.
2895 * @c: UBIFS file-system description object
2900 * error code in case of failure.
2922 if (err == -ENOENT) in ubifs_tnc_remove_ino()
2928 xattr_inum = le64_to_cpu(xent->inum); in ubifs_tnc_remove_ino()
2929 dbg_tnc("xent '%s', ino %lu", xent->name, in ubifs_tnc_remove_ino()
2934 fname_name(&nm) = xent->name; in ubifs_tnc_remove_ino()
2935 fname_len(&nm) = le16_to_cpu(xent->nlen); in ubifs_tnc_remove_ino()
2954 key_read(c, &xent->key, &key1); in ubifs_tnc_remove_ino()
2965 * ubifs_tnc_next_ent - walk directory or extended attribute entries.
2966 * @c: UBIFS file-system description object
2967 * @key: key of last entry
2971 * after the given key (@key) if there is one. @nm is used to resolve
2974 * If the name of the current entry is not known and only the key is known,
2975 * @nm->name has to be %NULL. In this case the semantics of this function is a
2976 * little bit different and it returns the entry corresponding to this key, not
2977 * the next one. If the key was not found, the closest "right" entry is
2980 * If the fist entry has to be found, @key has to contain the lowest possible
2981 * key value for this inode and @name has to be %NULL.
2984 * in case of success, %-ENOENT is returned if no entry was found, and a
2985 * negative error code is returned in case of failure.
2988 union ubifs_key *key, in ubifs_tnc_next_ent() argument
2991 int n, err, type = key_type(c, key); in ubifs_tnc_next_ent()
2997 dbg_tnck(key, "key "); in ubifs_tnc_next_ent()
2998 ubifs_assert(c, is_hash_key(c, key)); in ubifs_tnc_next_ent()
3000 mutex_lock(&c->tnc_mutex); in ubifs_tnc_next_ent()
3001 err = ubifs_lookup_level0(c, key, &znode, &n); in ubifs_tnc_next_ent()
3008 if (c->replaying) in ubifs_tnc_next_ent()
3009 err = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_next_ent()
3012 err = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_next_ent()
3031 * However, the given key does not exist in the TNC in ubifs_tnc_next_ent()
3041 zbr = &znode->zbranch[n]; in ubifs_tnc_next_ent()
3042 dent = kmalloc(zbr->len, GFP_NOFS); in ubifs_tnc_next_ent()
3044 err = -ENOMEM; in ubifs_tnc_next_ent()
3052 dkey = &zbr->key; in ubifs_tnc_next_ent()
3053 if (key_inum(c, dkey) != key_inum(c, key) || in ubifs_tnc_next_ent()
3055 err = -ENOENT; in ubifs_tnc_next_ent()
3063 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_next_ent()
3069 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_next_ent()
3074 * tnc_destroy_cnext - destroy left-over obsolete znodes from a failed commit.
3075 * @c: UBIFS file-system description object
3077 * Destroy left-over obsolete znodes from a failed commit.
3083 if (!c->cnext) in tnc_destroy_cnext()
3085 ubifs_assert(c, c->cmt_state == COMMIT_BROKEN); in tnc_destroy_cnext()
3086 cnext = c->cnext; in tnc_destroy_cnext()
3090 cnext = cnext->cnext; in tnc_destroy_cnext()
3097 * count while closing tnc. Non-obsolete znode could in tnc_destroy_cnext()
3098 * be re-dirtied during committing process, so dirty in tnc_destroy_cnext()
3105 atomic_long_inc(&c->clean_zn_cnt); in tnc_destroy_cnext()
3108 } while (cnext && cnext != c->cnext); in tnc_destroy_cnext()
3112 * ubifs_tnc_close - close TNC subsystem and free all related resources.
3113 * @c: UBIFS file-system description object
3118 if (c->zroot.znode) { in ubifs_tnc_close()
3121 n = atomic_long_read(&c->clean_zn_cnt); in ubifs_tnc_close()
3122 freed = ubifs_destroy_tnc_subtree(c, c->zroot.znode); in ubifs_tnc_close()
3126 kfree(c->gap_lebs); in ubifs_tnc_close()
3127 kfree(c->ilebs); in ubifs_tnc_close()
3132 * left_znode - get the znode to the left.
3133 * @c: UBIFS file-system description object
3137 * there is not one. A negative error code is returned on failure.
3142 int level = znode->level; in left_znode()
3145 int n = znode->iip - 1; in left_znode()
3148 znode = znode->parent; in left_znode()
3156 while (znode->level != level) { in left_znode()
3157 n = znode->child_cnt - 1; in left_znode()
3169 * right_znode - get the znode to the right.
3170 * @c: UBIFS file-system description object
3174 * if there is not one. A negative error code is returned on failure.
3179 int level = znode->level; in right_znode()
3182 int n = znode->iip + 1; in right_znode()
3185 znode = znode->parent; in right_znode()
3188 if (n < znode->child_cnt) { in right_znode()
3193 while (znode->level != level) { in right_znode()
3205 * lookup_znode - find a particular indexing node from TNC.
3206 * @c: UBIFS file-system description object
3207 * @key: index node key to lookup
3212 * This function searches an indexing node by its first key @key and its
3215 * were found on the media by scanning, for example when garbage-collecting or
3216 * when doing in-the-gaps commit. This means that the indexing node which is
3217 * looked for does not have to have exactly the same leftmost key @key, because
3218 * the leftmost key may have been changed, in which case TNC will contain a
3223 * not find it. For situations like this UBIFS has the old index RB-tree
3227 * found. A negative error code is returned on failure.
3230 union ubifs_key *key, int level, in lookup_znode() argument
3236 ubifs_assert(c, key_type(c, key) < UBIFS_INVALID_KEY); in lookup_znode()
3243 return ERR_PTR(-EINVAL); in lookup_znode()
3246 znode = c->zroot.znode; in lookup_znode()
3248 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in lookup_znode()
3253 if (c->zroot.lnum == lnum && c->zroot.offs == offs) in lookup_znode()
3256 if (level >= znode->level) in lookup_znode()
3259 ubifs_search_zbranch(c, znode, key, &n); in lookup_znode()
3262 * We reached a znode where the leftmost key is greater in lookup_znode()
3263 * than the key we are searching for. This is the same in lookup_znode()
3274 ubifs_search_zbranch(c, znode, key, &n); in lookup_znode()
3277 if (znode->level == level + 1) in lookup_znode()
3284 if (znode->zbranch[n].lnum == lnum && znode->zbranch[n].offs == offs) in lookup_znode()
3286 /* If the key is unique, there is nowhere else to look */ in lookup_znode()
3287 if (!is_hash_key(c, key)) in lookup_znode()
3290 * The key is not unique and so may be also in the znodes to either in lookup_znode()
3299 n -= 1; in lookup_znode()
3306 n = znode->child_cnt - 1; in lookup_znode()
3309 if (znode->zbranch[n].lnum == lnum && in lookup_znode()
3310 znode->zbranch[n].offs == offs) in lookup_znode()
3312 /* Stop if the key is less than the one we are looking for */ in lookup_znode()
3313 if (keys_cmp(c, &znode->zbranch[n].key, key) < 0) in lookup_znode()
3322 if (++n >= znode->child_cnt) { in lookup_znode()
3331 if (znode->zbranch[n].lnum == lnum && in lookup_znode()
3332 znode->zbranch[n].offs == offs) in lookup_znode()
3334 /* Stop if the key is greater than the one we are looking for */ in lookup_znode()
3335 if (keys_cmp(c, &znode->zbranch[n].key, key) > 0) in lookup_znode()
3342 * is_idx_node_in_tnc - determine if an index node is in the TNC.
3343 * @c: UBIFS file-system description object
3344 * @key: key of index node
3352 * znode is clean, and a negative error code in case of failure.
3354 * Note, the @key argument has to be the key of the first child. Also note,
3356 * offset for a main-area node.
3358 int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, in is_idx_node_in_tnc() argument
3363 znode = lookup_znode(c, key, level, lnum, offs); in is_idx_node_in_tnc()
3373 * is_leaf_node_in_tnc - determine if a non-indexing not is in the TNC.
3374 * @c: UBIFS file-system description object
3375 * @key: node key
3380 * not, and a negative error code in case of failure.
3383 * and offset for a main-area node.
3385 static int is_leaf_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, in is_leaf_node_in_tnc() argument
3391 const int unique = !is_hash_key(c, key); in is_leaf_node_in_tnc()
3393 found = ubifs_lookup_level0(c, key, &znode, &n); in is_leaf_node_in_tnc()
3395 return found; /* Error code */ in is_leaf_node_in_tnc()
3398 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3399 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3404 * Because the key is not unique, we have to look left in is_leaf_node_in_tnc()
3412 if (err == -ENOENT) in is_leaf_node_in_tnc()
3416 if (keys_cmp(c, key, &znode->zbranch[n].key)) in is_leaf_node_in_tnc()
3418 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3419 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3428 if (err == -ENOENT) in is_leaf_node_in_tnc()
3432 if (keys_cmp(c, key, &znode->zbranch[n].key)) in is_leaf_node_in_tnc()
3434 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3435 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3442 * ubifs_tnc_has_node - determine whether a node is in the TNC.
3443 * @c: UBIFS file-system description object
3444 * @key: node key
3448 * @is_idx: non-zero if the node is an index node
3451 * negative error code in case of failure. For index nodes, @key has to be the
3452 * key of the first child. An index node is considered to be in the TNC only if
3455 int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level, in ubifs_tnc_has_node() argument
3460 mutex_lock(&c->tnc_mutex); in ubifs_tnc_has_node()
3462 err = is_idx_node_in_tnc(c, key, level, lnum, offs); in ubifs_tnc_has_node()
3474 err = is_leaf_node_in_tnc(c, key, lnum, offs); in ubifs_tnc_has_node()
3477 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_has_node()
3482 * ubifs_dirty_idx_node - dirty an index node.
3483 * @c: UBIFS file-system description object
3484 * @key: index node key
3490 * collected. The @key argument has to be the key of the first child. This
3492 * for a main-area node. Returns %0 on success and a negative error code on
3495 int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level, in ubifs_dirty_idx_node() argument
3501 mutex_lock(&c->tnc_mutex); in ubifs_dirty_idx_node()
3502 znode = lookup_znode(c, key, level, lnum, offs); in ubifs_dirty_idx_node()
3516 mutex_unlock(&c->tnc_mutex); in ubifs_dirty_idx_node()
3521 * dbg_check_inode_size - check if inode size is correct.
3522 * @c: UBIFS file-system description object
3527 * not have any pages beyond @size. Returns zero if the inode is OK, %-EINVAL
3528 * if it has a data page beyond @size, and other negative error code in case of
3535 union ubifs_key from_key, to_key, *key; in dbg_check_inode_size() local
3539 if (!S_ISREG(inode->i_mode)) in dbg_check_inode_size()
3544 block = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT; in dbg_check_inode_size()
3545 data_key_init(c, &from_key, inode->i_ino, block); in dbg_check_inode_size()
3546 highest_data_key(c, &to_key, inode->i_ino); in dbg_check_inode_size()
3548 mutex_lock(&c->tnc_mutex); in dbg_check_inode_size()
3554 key = &from_key; in dbg_check_inode_size()
3559 if (err == -ENOENT) { in dbg_check_inode_size()
3567 key = &znode->zbranch[n].key; in dbg_check_inode_size()
3568 if (!key_in_range(c, key, &from_key, &to_key)) in dbg_check_inode_size()
3572 block = key_block(c, key); in dbg_check_inode_size()
3574 (unsigned long)inode->i_ino, size, in dbg_check_inode_size()
3576 mutex_unlock(&c->tnc_mutex); in dbg_check_inode_size()
3579 return -EINVAL; in dbg_check_inode_size()
3582 mutex_unlock(&c->tnc_mutex); in dbg_check_inode_size()