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,
48 * insert_old_idx - record an index node obsoleted since the last commit start.
49 * @c: UBIFS file-system description object
53 * Returns %0 on success, and a negative error code on failure.
61 * That means that the garbage collection and the in-the-gaps method of
66 * they cannot be easily found. In those cases, an entry is added to an RB-tree.
67 * That is what this function does. The RB-tree is ordered by LEB number and
77 return -ENOMEM; in insert_old_idx()
78 old_idx->lnum = lnum; in insert_old_idx()
79 old_idx->offs = offs; in insert_old_idx()
81 p = &c->old_idx.rb_node; in insert_old_idx()
85 if (lnum < o->lnum) in insert_old_idx()
86 p = &(*p)->rb_left; in insert_old_idx()
87 else if (lnum > o->lnum) in insert_old_idx()
88 p = &(*p)->rb_right; in insert_old_idx()
89 else if (offs < o->offs) in insert_old_idx()
90 p = &(*p)->rb_left; in insert_old_idx()
91 else if (offs > o->offs) in insert_old_idx()
92 p = &(*p)->rb_right; in insert_old_idx()
99 rb_link_node(&old_idx->rb, parent, p); in insert_old_idx()
100 rb_insert_color(&old_idx->rb, &c->old_idx); in insert_old_idx()
105 * insert_old_idx_znode - record a znode obsoleted since last commit start.
106 * @c: UBIFS file-system description object
109 * Returns %0 on success, and a negative error code on failure.
113 if (znode->parent) { in insert_old_idx_znode()
116 zbr = &znode->parent->zbranch[znode->iip]; in insert_old_idx_znode()
117 if (zbr->len) in insert_old_idx_znode()
118 return insert_old_idx(c, zbr->lnum, zbr->offs); in insert_old_idx_znode()
120 if (c->zroot.len) in insert_old_idx_znode()
121 return insert_old_idx(c, c->zroot.lnum, in insert_old_idx_znode()
122 c->zroot.offs); in insert_old_idx_znode()
127 * ins_clr_old_idx_znode - record a znode obsoleted since last commit start.
128 * @c: UBIFS file-system description object
131 * Returns %0 on success, and a negative error code on failure.
138 if (znode->parent) { in ins_clr_old_idx_znode()
141 zbr = &znode->parent->zbranch[znode->iip]; in ins_clr_old_idx_znode()
142 if (zbr->len) { in ins_clr_old_idx_znode()
143 err = insert_old_idx(c, zbr->lnum, zbr->offs); in ins_clr_old_idx_znode()
146 zbr->lnum = 0; in ins_clr_old_idx_znode()
147 zbr->offs = 0; in ins_clr_old_idx_znode()
148 zbr->len = 0; in ins_clr_old_idx_znode()
151 if (c->zroot.len) { in ins_clr_old_idx_znode()
152 err = insert_old_idx(c, c->zroot.lnum, c->zroot.offs); in ins_clr_old_idx_znode()
155 c->zroot.lnum = 0; in ins_clr_old_idx_znode()
156 c->zroot.offs = 0; in ins_clr_old_idx_znode()
157 c->zroot.len = 0; in ins_clr_old_idx_znode()
163 * destroy_old_idx - destroy the old_idx RB-tree.
164 * @c: UBIFS file-system description object
166 * During start commit, the old_idx RB-tree is used to avoid overwriting index
169 * new index is successfully written. The old-idx RB-tree is used for the
170 * in-the-gaps method of writing index nodes and is destroyed every commit.
176 rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb) in destroy_old_idx()
179 c->old_idx = RB_ROOT; in destroy_old_idx()
183 * copy_znode - copy a dirty znode.
184 * @c: UBIFS file-system description object
194 zn = kmemdup(znode, c->max_znode_sz, GFP_NOFS); in copy_znode()
196 return ERR_PTR(-ENOMEM); in copy_znode()
198 zn->cnext = NULL; in copy_znode()
199 __set_bit(DIRTY_ZNODE, &zn->flags); in copy_znode()
200 __clear_bit(COW_ZNODE, &zn->flags); in copy_znode()
203 __set_bit(OBSOLETE_ZNODE, &znode->flags); in copy_znode()
205 if (znode->level != 0) { in copy_znode()
207 const int n = zn->child_cnt; in copy_znode()
211 struct ubifs_zbranch *zbr = &zn->zbranch[i]; in copy_znode()
213 if (zbr->znode) in copy_znode()
214 zbr->znode->parent = zn; in copy_znode()
218 atomic_long_inc(&c->dirty_zn_cnt); in copy_znode()
223 * add_idx_dirt - add dirt due to a dirty znode.
224 * @c: UBIFS file-system description object
232 c->calc_idx_sz -= ALIGN(dirt, 8); in add_idx_dirt()
237 * dirty_cow_znode - ensure a znode is not being committed.
238 * @c: UBIFS file-system description object
241 * Returns dirtied znode on success or negative error code on failure.
246 struct ubifs_znode *znode = zbr->znode; in dirty_cow_znode()
252 if (!test_and_set_bit(DIRTY_ZNODE, &znode->flags)) { in dirty_cow_znode()
253 atomic_long_inc(&c->dirty_zn_cnt); in dirty_cow_znode()
254 atomic_long_dec(&c->clean_zn_cnt); in dirty_cow_znode()
256 err = add_idx_dirt(c, zbr->lnum, zbr->len); in dirty_cow_znode()
267 if (zbr->len) { in dirty_cow_znode()
268 err = insert_old_idx(c, zbr->lnum, zbr->offs); in dirty_cow_znode()
271 err = add_idx_dirt(c, zbr->lnum, zbr->len); in dirty_cow_znode()
275 zbr->znode = zn; in dirty_cow_znode()
276 zbr->lnum = 0; in dirty_cow_znode()
277 zbr->offs = 0; in dirty_cow_znode()
278 zbr->len = 0; in dirty_cow_znode()
286 * lnc_add - add a leaf node to the leaf node cache.
287 * @c: UBIFS file-system description object
291 * Leaf nodes are non-index nodes directory entry nodes or data nodes. The
292 * purpose of the leaf node cache is to save re-reading the same leaf node over
302 * used with @c->tnc_mutex unlock upon return from the TNC subsystem. But LNC
312 ubifs_assert(c, !zbr->leaf); in lnc_add()
313 ubifs_assert(c, zbr->len != 0); in lnc_add()
314 ubifs_assert(c, is_hash_key(c, &zbr->key)); in lnc_add()
319 ubifs_dump_node(c, dent, zbr->len); in lnc_add()
323 lnc_node = kmemdup(node, zbr->len, GFP_NOFS); in lnc_add()
328 zbr->leaf = lnc_node; in lnc_add()
333 * lnc_add_directly - add a leaf node to the leaf-node-cache.
334 * @c: UBIFS file-system description object
346 ubifs_assert(c, !zbr->leaf); in lnc_add_directly()
347 ubifs_assert(c, zbr->len != 0); in lnc_add_directly()
352 ubifs_dump_node(c, node, zbr->len); in lnc_add_directly()
356 zbr->leaf = node; in lnc_add_directly()
361 * lnc_free - remove a leaf node from the leaf node cache.
366 if (!zbr->leaf) in lnc_free()
368 kfree(zbr->leaf); in lnc_free()
369 zbr->leaf = NULL; in lnc_free()
373 * tnc_read_hashed_node - read a "hashed" leaf node.
374 * @c: UBIFS file-system description object
375 * @zbr: key and position of the node
381 * code in case of failure.
388 ubifs_assert(c, is_hash_key(c, &zbr->key)); in tnc_read_hashed_node()
390 if (zbr->leaf) { in tnc_read_hashed_node()
392 ubifs_assert(c, zbr->len != 0); in tnc_read_hashed_node()
393 memcpy(node, zbr->leaf, zbr->len); in tnc_read_hashed_node()
397 if (c->replaying) { in tnc_read_hashed_node()
398 err = fallible_read_node(c, &zbr->key, zbr, node); in tnc_read_hashed_node()
400 * When the node was not found, return -ENOENT, 0 otherwise. in tnc_read_hashed_node()
401 * Negative return codes stay as-is. in tnc_read_hashed_node()
404 err = -ENOENT; in tnc_read_hashed_node()
419 * try_read_node - read a node if it is a node.
420 * @c: UBIFS file-system description object
427 * a node is not present. A negative error code is returned for I/O errors.
430 * the return code indicates if a node was read.
432 * Note, this function does not check CRC of data nodes if @c->no_chk_data_crc
434 * @c->mounting or @c->remounting_rw is true (we are mounting or re-mounting to
435 * R/W mode), @c->no_chk_data_crc is ignored and CRC is checked. This is
436 * because during mounting or re-mounting from R/O mode to R/W mode we may read
443 int len = zbr->len; in try_read_node()
444 int lnum = zbr->lnum; in try_read_node()
445 int offs = zbr->offs; in try_read_node()
459 if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) in try_read_node()
462 if (ch->node_type != type) in try_read_node()
465 node_len = le32_to_cpu(ch->len); in try_read_node()
469 if (type != UBIFS_DATA_NODE || !c->no_chk_data_crc || c->mounting || in try_read_node()
470 c->remounting_rw) { in try_read_node()
471 crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); in try_read_node()
472 node_crc = le32_to_cpu(ch->crc); in try_read_node()
477 err = ubifs_node_check_hash(c, buf, zbr->hash); in try_read_node()
479 ubifs_bad_hash(c, buf, zbr->hash, lnum, offs); in try_read_node()
487 * fallible_read_node - try to read a leaf node.
488 * @c: UBIFS file-system description object
489 * @key: key of node to read
494 * if the node is not present, and a negative error code in the case of error.
496 static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key, in fallible_read_node() argument
501 dbg_tnck(key, "LEB %d:%d, key ", zbr->lnum, zbr->offs); in fallible_read_node()
503 ret = try_read_node(c, node, key_type(c, key), zbr); in fallible_read_node()
508 /* All nodes have key in the same place */ in fallible_read_node()
509 key_read(c, &dent->key, &node_key); in fallible_read_node()
510 if (keys_cmp(c, key, &node_key) != 0) in fallible_read_node()
513 if (ret == 0 && c->replaying) in fallible_read_node()
514 dbg_mntk(key, "dangling branch LEB %d:%d len %d, key ", in fallible_read_node()
515 zbr->lnum, zbr->offs, zbr->len); in fallible_read_node()
520 * matches_name - determine if a direntry or xattr entry matches a given name.
521 * @c: UBIFS file-system description object
528 * of failure, a negative error code is returned.
537 if (!zbr->leaf) { in matches_name()
538 dent = kmalloc(zbr->len, GFP_NOFS); in matches_name()
540 return -ENOMEM; in matches_name()
551 dent = zbr->leaf; in matches_name()
553 nlen = le16_to_cpu(dent->nlen); in matches_name()
554 err = memcmp(dent->name, fname_name(nm), min_t(int, nlen, fname_len(nm))); in matches_name()
573 * get_znode - get a TNC znode that may not be loaded yet.
574 * @c: UBIFS file-system description object
578 * This function returns the znode or a negative error code.
585 zbr = &znode->zbranch[n]; in get_znode()
586 if (zbr->znode) in get_znode()
587 znode = zbr->znode; in get_znode()
594 * tnc_next - find next TNC entry.
595 * @c: UBIFS file-system description object
599 * This function returns %0 if the next TNC entry is found, %-ENOENT if there is
600 * no next entry, or a negative error code otherwise.
608 if (nn < znode->child_cnt) { in tnc_next()
615 zp = znode->parent; in tnc_next()
617 return -ENOENT; in tnc_next()
618 nn = znode->iip + 1; in tnc_next()
620 if (nn < znode->child_cnt) { in tnc_next()
624 while (znode->level != 0) { in tnc_next()
639 * tnc_prev - find previous TNC entry.
640 * @c: UBIFS file-system description object
644 * This function returns %0 if the previous TNC entry is found, %-ENOENT if
645 * there is no next entry, or a negative error code otherwise.
653 *n = nn - 1; in tnc_prev()
659 zp = znode->parent; in tnc_prev()
661 return -ENOENT; in tnc_prev()
662 nn = znode->iip - 1; in tnc_prev()
668 while (znode->level != 0) { in tnc_prev()
669 nn = znode->child_cnt - 1; in tnc_prev()
674 nn = znode->child_cnt - 1; in tnc_prev()
684 * resolve_collision - resolve a collision.
685 * @c: UBIFS file-system description object
686 * @key: key of a directory or extended attribute entry
691 * This function is called for "hashed" keys to make sure that the found key
696 * This means that @n may be set to %-1 if the leftmost key in @zn is the
697 * previous one. A negative error code is returned on failures.
699 static int resolve_collision(struct ubifs_info *c, const union ubifs_key *key, in resolve_collision() argument
705 err = matches_name(c, &(*zn)->zbranch[*n], nm); in resolve_collision()
715 if (err == -ENOENT) { in resolve_collision()
717 *n = -1; in resolve_collision()
722 if (keys_cmp(c, &(*zn)->zbranch[*n].key, key)) { in resolve_collision()
731 * ---------------------- in resolve_collision()
733 * ----------------------- in resolve_collision()
736 * ------------ ------------ in resolve_collision()
738 * ------------ ------------ in resolve_collision()
750 * 'tnc_insert()' would correct the parent key. in resolve_collision()
752 if (*n == (*zn)->child_cnt - 1) { in resolve_collision()
757 if (err == -ENOENT) in resolve_collision()
758 err = -EINVAL; in resolve_collision()
762 *n = -1; in resolve_collision()
766 err = matches_name(c, &(*zn)->zbranch[*n], nm); in resolve_collision()
782 if (err == -ENOENT) in resolve_collision()
786 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision()
788 err = matches_name(c, &znode->zbranch[nn], nm); in resolve_collision()
803 * fallible_matches_name - determine if a dent matches a given name.
804 * @c: UBIFS file-system description object
815 * error code is returned in case of failure.
825 if (!zbr->leaf) { in fallible_matches_name()
826 dent = kmalloc(zbr->len, GFP_NOFS); in fallible_matches_name()
828 return -ENOMEM; in fallible_matches_name()
830 err = fallible_read_node(c, &zbr->key, zbr, dent); in fallible_matches_name()
844 dent = zbr->leaf; in fallible_matches_name()
846 nlen = le16_to_cpu(dent->nlen); in fallible_matches_name()
847 err = memcmp(dent->name, fname_name(nm), min_t(int, nlen, fname_len(nm))); in fallible_matches_name()
866 * fallible_resolve_collision - resolve a collision even if nodes are missing.
867 * @c: UBIFS file-system description object
868 * @key: key
872 * @adding: indicates caller is adding a key to the TNC
877 * Garbage-collected and the commit was not done. A branch that refers to a node
885 * o a negative error code is returned in case of failure.
888 const union ubifs_key *key, in fallible_resolve_collision() argument
896 cmp = fallible_matches_name(c, &znode->zbranch[nn], nm); in fallible_resolve_collision()
907 * branch - to the left or to the right. Well, let's try left. in fallible_resolve_collision()
917 if (err == -ENOENT) { in fallible_resolve_collision()
919 *n = -1; in fallible_resolve_collision()
924 if (keys_cmp(c, &(*zn)->zbranch[*n].key, key)) { in fallible_resolve_collision()
926 if (*n == (*zn)->child_cnt - 1) { in fallible_resolve_collision()
931 if (err == -ENOENT) in fallible_resolve_collision()
932 err = -EINVAL; in fallible_resolve_collision()
936 *n = -1; in fallible_resolve_collision()
940 err = fallible_matches_name(c, &(*zn)->zbranch[*n], nm); in fallible_resolve_collision()
965 if (err == -ENOENT) in fallible_resolve_collision()
969 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in fallible_resolve_collision()
971 err = fallible_matches_name(c, &znode->zbranch[nn], nm); in fallible_resolve_collision()
991 dbg_mntk(key, "dangling match LEB %d:%d len %d key ", in fallible_resolve_collision()
992 o_znode->zbranch[o_n].lnum, o_znode->zbranch[o_n].offs, in fallible_resolve_collision()
993 o_znode->zbranch[o_n].len); in fallible_resolve_collision()
1000 * matches_position - determine if a zbranch matches a given position.
1009 if (zbr->lnum == lnum && zbr->offs == offs) in matches_position()
1016 * resolve_collision_directly - resolve a collision directly.
1017 * @c: UBIFS file-system description object
1018 * @key: key of directory entry
1030 * previous directory entry. Otherwise a negative error code is returned.
1033 const union ubifs_key *key, in resolve_collision_directly() argument
1042 if (matches_position(&znode->zbranch[nn], lnum, offs)) in resolve_collision_directly()
1048 if (err == -ENOENT) in resolve_collision_directly()
1052 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision_directly()
1054 if (matches_position(&znode->zbranch[nn], lnum, offs)) { in resolve_collision_directly()
1066 if (err == -ENOENT) in resolve_collision_directly()
1070 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision_directly()
1074 if (matches_position(&znode->zbranch[nn], lnum, offs)) in resolve_collision_directly()
1080 * dirty_cow_bottom_up - dirty a znode and its ancestors.
1081 * @c: UBIFS file-system description object
1084 * If we do not have a unique key that resides in a znode, then we cannot
1093 int *path = c->bottom_up_buf, p = 0; in dirty_cow_bottom_up()
1095 ubifs_assert(c, c->zroot.znode); in dirty_cow_bottom_up()
1097 if (c->zroot.znode->level > BOTTOM_UP_HEIGHT) { in dirty_cow_bottom_up()
1098 kfree(c->bottom_up_buf); in dirty_cow_bottom_up()
1099 c->bottom_up_buf = kmalloc_array(c->zroot.znode->level, in dirty_cow_bottom_up()
1102 if (!c->bottom_up_buf) in dirty_cow_bottom_up()
1103 return ERR_PTR(-ENOMEM); in dirty_cow_bottom_up()
1104 path = c->bottom_up_buf; in dirty_cow_bottom_up()
1106 if (c->zroot.znode->level) { in dirty_cow_bottom_up()
1111 zp = znode->parent; in dirty_cow_bottom_up()
1114 n = znode->iip; in dirty_cow_bottom_up()
1115 ubifs_assert(c, p < c->zroot.znode->level); in dirty_cow_bottom_up()
1117 if (!zp->cnext && ubifs_zn_dirty(znode)) in dirty_cow_bottom_up()
1127 zp = znode->parent; in dirty_cow_bottom_up()
1129 ubifs_assert(c, path[p - 1] >= 0); in dirty_cow_bottom_up()
1130 ubifs_assert(c, path[p - 1] < zp->child_cnt); in dirty_cow_bottom_up()
1131 zbr = &zp->zbranch[path[--p]]; in dirty_cow_bottom_up()
1134 ubifs_assert(c, znode == c->zroot.znode); in dirty_cow_bottom_up()
1135 znode = dirty_cow_znode(c, &c->zroot); in dirty_cow_bottom_up()
1139 ubifs_assert(c, path[p - 1] >= 0); in dirty_cow_bottom_up()
1140 ubifs_assert(c, path[p - 1] < znode->child_cnt); in dirty_cow_bottom_up()
1141 znode = znode->zbranch[path[p - 1]].znode; in dirty_cow_bottom_up()
1148 * ubifs_lookup_level0 - search for zero-level znode.
1149 * @c: UBIFS file-system description object
1150 * @key: key to lookup
1154 * This function looks up the TNC tree and search for zero-level znode which
1155 * refers key @key. The found zero-level znode is returned in @zn. There are 3
1157 * o exact match, i.e. the found zero-level znode contains key @key, then %1
1159 * o not exact match, which means that zero-level znode does not contain
1160 * @key, then %0 is returned and slot number of the closest branch or %-1
1162 * o @key is so small that it is even less than the lowest key of the
1163 * leftmost zero-level node, then %0 is returned and %0 is stored in @n.
1167 * case of failure, a negative error code is returned.
1169 int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key, in ubifs_lookup_level0() argument
1176 dbg_tnck(key, "search key "); in ubifs_lookup_level0()
1177 ubifs_assert(c, key_type(c, key) < UBIFS_INVALID_KEY); in ubifs_lookup_level0()
1179 znode = c->zroot.znode; in ubifs_lookup_level0()
1181 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in ubifs_lookup_level0()
1186 znode->time = time; in ubifs_lookup_level0()
1191 exact = ubifs_search_zbranch(c, znode, key, n); in ubifs_lookup_level0()
1193 if (znode->level == 0) in ubifs_lookup_level0()
1198 zbr = &znode->zbranch[*n]; in ubifs_lookup_level0()
1200 if (zbr->znode) { in ubifs_lookup_level0()
1201 znode->time = time; in ubifs_lookup_level0()
1202 znode = zbr->znode; in ubifs_lookup_level0()
1213 if (exact || !is_hash_key(c, key) || *n != -1) { in ubifs_lookup_level0()
1214 dbg_tnc("found %d, lvl %d, n %d", exact, znode->level, *n); in ubifs_lookup_level0()
1219 * Here is a tricky place. We have not found the key and this is a in ubifs_lookup_level0()
1220 * "hashed" key, which may collide. The rest of the code deals with in ubifs_lookup_level0()
1235 * In the examples, if we are looking for key "5", we may reach nodes in ubifs_lookup_level0()
1237 * left and see if there is "5" key there. If there is, we have to in ubifs_lookup_level0()
1241 * elements which are equivalent to the next key in the parent in the in ubifs_lookup_level0()
1249 * And this becomes what is at the first "picture" after key "5" marked in ubifs_lookup_level0()
1252 * removing the leftmost key, we would have to correct the key of the in ubifs_lookup_level0()
1254 * if we changed the leftmost key of the parent znode, the garbage in ubifs_lookup_level0()
1256 * indexing LEBs). Although we already have an additional RB-tree where in ubifs_lookup_level0()
1262 if (err == -ENOENT) { in ubifs_lookup_level0()
1263 dbg_tnc("found 0, lvl %d, n -1", znode->level); in ubifs_lookup_level0()
1264 *n = -1; in ubifs_lookup_level0()
1269 if (keys_cmp(c, key, &znode->zbranch[*n].key)) { in ubifs_lookup_level0()
1270 dbg_tnc("found 0, lvl %d, n -1", znode->level); in ubifs_lookup_level0()
1271 *n = -1; in ubifs_lookup_level0()
1275 dbg_tnc("found 1, lvl %d, n %d", znode->level, *n); in ubifs_lookup_level0()
1281 * lookup_level0_dirty - search for zero-level znode dirtying.
1282 * @c: UBIFS file-system description object
1283 * @key: key to lookup
1287 * This function looks up the TNC tree and search for zero-level znode which
1288 * refers key @key. The found zero-level znode is returned in @zn. There are 3
1290 * o exact match, i.e. the found zero-level znode contains key @key, then %1
1292 * o not exact match, which means that zero-level znode does not contain @key
1295 * o @key is so small that it is even less than the lowest key of the
1296 * leftmost zero-level node, then %0 is returned and %-1 is stored in @n.
1298 * Additionally all znodes in the path from the root to the located zero-level
1303 * case of failure, a negative error code is returned.
1305 static int lookup_level0_dirty(struct ubifs_info *c, const union ubifs_key *key, in lookup_level0_dirty() argument
1312 dbg_tnck(key, "search and dirty key "); in lookup_level0_dirty()
1314 znode = c->zroot.znode; in lookup_level0_dirty()
1316 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in lookup_level0_dirty()
1321 znode = dirty_cow_znode(c, &c->zroot); in lookup_level0_dirty()
1325 znode->time = time; in lookup_level0_dirty()
1330 exact = ubifs_search_zbranch(c, znode, key, n); in lookup_level0_dirty()
1332 if (znode->level == 0) in lookup_level0_dirty()
1337 zbr = &znode->zbranch[*n]; in lookup_level0_dirty()
1339 if (zbr->znode) { in lookup_level0_dirty()
1340 znode->time = time; in lookup_level0_dirty()
1357 if (exact || !is_hash_key(c, key) || *n != -1) { in lookup_level0_dirty()
1358 dbg_tnc("found %d, lvl %d, n %d", exact, znode->level, *n); in lookup_level0_dirty()
1364 * code. in lookup_level0_dirty()
1367 if (err == -ENOENT) { in lookup_level0_dirty()
1368 *n = -1; in lookup_level0_dirty()
1369 dbg_tnc("found 0, lvl %d, n -1", znode->level); in lookup_level0_dirty()
1374 if (keys_cmp(c, key, &znode->zbranch[*n].key)) { in lookup_level0_dirty()
1375 *n = -1; in lookup_level0_dirty()
1376 dbg_tnc("found 0, lvl %d, n -1", znode->level); in lookup_level0_dirty()
1380 if (znode->cnext || !ubifs_zn_dirty(znode)) { in lookup_level0_dirty()
1386 dbg_tnc("found 1, lvl %d, n %d", znode->level, *n); in lookup_level0_dirty()
1392 * maybe_leb_gced - determine if a LEB may have been garbage collected.
1393 * @c: UBIFS file-system description object
1405 gced_lnum = c->gced_lnum; in maybe_leb_gced()
1407 gc_seq2 = c->gc_seq; in maybe_leb_gced()
1419 if (gced_lnum != c->gced_lnum) in maybe_leb_gced()
1428 * ubifs_tnc_locate - look up a file-system node and return it and its location.
1429 * @c: UBIFS file-system description object
1430 * @key: node key to lookup
1435 * This function looks up and reads node with key @key. The caller has to make
1437 * of success, %-ENOENT if the node was not found, and a negative error code in
1440 int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_locate() argument
1448 mutex_lock(&c->tnc_mutex); in ubifs_tnc_locate()
1449 found = ubifs_lookup_level0(c, key, &znode, &n); in ubifs_tnc_locate()
1451 err = -ENOENT; in ubifs_tnc_locate()
1457 zt = &znode->zbranch[n]; in ubifs_tnc_locate()
1459 *lnum = zt->lnum; in ubifs_tnc_locate()
1460 *offs = zt->offs; in ubifs_tnc_locate()
1462 if (is_hash_key(c, key)) { in ubifs_tnc_locate()
1475 zbr = znode->zbranch[n]; in ubifs_tnc_locate()
1476 gc_seq1 = c->gc_seq; in ubifs_tnc_locate()
1477 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_locate()
1485 err = fallible_read_node(c, key, &zbr, node); in ubifs_tnc_locate()
1497 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_locate()
1502 * ubifs_tnc_get_bu_keys - lookup keys for bulk-read.
1503 * @c: UBIFS file-system description object
1504 * @bu: bulk-read parameters and results
1508 * and a negative error code in case of failure.
1510 * Note, if the bulk-read buffer length (@bu->buf_len) is known, this function
1511 * makes sure bulk-read nodes fit the buffer. Otherwise, this function prepares
1512 * maximum possible amount of nodes for bulk-read.
1516 int n, err = 0, lnum = -1, offs; in ubifs_tnc_get_bu_keys()
1518 unsigned int block = key_block(c, &bu->key); in ubifs_tnc_get_bu_keys()
1521 bu->cnt = 0; in ubifs_tnc_get_bu_keys()
1522 bu->blk_cnt = 0; in ubifs_tnc_get_bu_keys()
1523 bu->eof = 0; in ubifs_tnc_get_bu_keys()
1525 mutex_lock(&c->tnc_mutex); in ubifs_tnc_get_bu_keys()
1526 /* Find first key */ in ubifs_tnc_get_bu_keys()
1527 err = ubifs_lookup_level0(c, &bu->key, &znode, &n); in ubifs_tnc_get_bu_keys()
1531 /* Key found */ in ubifs_tnc_get_bu_keys()
1532 len = znode->zbranch[n].len; in ubifs_tnc_get_bu_keys()
1534 if (len > bu->buf_len) { in ubifs_tnc_get_bu_keys()
1535 err = -EINVAL; in ubifs_tnc_get_bu_keys()
1538 /* Add this key */ in ubifs_tnc_get_bu_keys()
1539 bu->zbranch[bu->cnt++] = znode->zbranch[n]; in ubifs_tnc_get_bu_keys()
1540 bu->blk_cnt += 1; in ubifs_tnc_get_bu_keys()
1541 lnum = znode->zbranch[n].lnum; in ubifs_tnc_get_bu_keys()
1542 offs = ALIGN(znode->zbranch[n].offs + len, 8); in ubifs_tnc_get_bu_keys()
1546 union ubifs_key *key; in ubifs_tnc_get_bu_keys() local
1549 /* Find next key */ in ubifs_tnc_get_bu_keys()
1553 zbr = &znode->zbranch[n]; in ubifs_tnc_get_bu_keys()
1554 key = &zbr->key; in ubifs_tnc_get_bu_keys()
1555 /* See if there is another data key for this file */ in ubifs_tnc_get_bu_keys()
1556 if (key_inum(c, key) != key_inum(c, &bu->key) || in ubifs_tnc_get_bu_keys()
1557 key_type(c, key) != UBIFS_DATA_KEY) { in ubifs_tnc_get_bu_keys()
1558 err = -ENOENT; in ubifs_tnc_get_bu_keys()
1562 /* First key found */ in ubifs_tnc_get_bu_keys()
1563 lnum = zbr->lnum; in ubifs_tnc_get_bu_keys()
1564 offs = ALIGN(zbr->offs + zbr->len, 8); in ubifs_tnc_get_bu_keys()
1565 len = zbr->len; in ubifs_tnc_get_bu_keys()
1566 if (len > bu->buf_len) { in ubifs_tnc_get_bu_keys()
1567 err = -EINVAL; in ubifs_tnc_get_bu_keys()
1575 if (zbr->lnum != lnum || zbr->offs != offs) in ubifs_tnc_get_bu_keys()
1577 offs += ALIGN(zbr->len, 8); in ubifs_tnc_get_bu_keys()
1578 len = ALIGN(len, 8) + zbr->len; in ubifs_tnc_get_bu_keys()
1580 if (len > bu->buf_len) in ubifs_tnc_get_bu_keys()
1584 next_block = key_block(c, key); in ubifs_tnc_get_bu_keys()
1585 bu->blk_cnt += (next_block - block - 1); in ubifs_tnc_get_bu_keys()
1586 if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1589 /* Add this key */ in ubifs_tnc_get_bu_keys()
1590 bu->zbranch[bu->cnt++] = *zbr; in ubifs_tnc_get_bu_keys()
1591 bu->blk_cnt += 1; in ubifs_tnc_get_bu_keys()
1593 if (bu->cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1595 if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1599 if (err == -ENOENT) { in ubifs_tnc_get_bu_keys()
1600 bu->eof = 1; in ubifs_tnc_get_bu_keys()
1603 bu->gc_seq = c->gc_seq; in ubifs_tnc_get_bu_keys()
1604 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_get_bu_keys()
1608 * An enormous hole could cause bulk-read to encompass too many in ubifs_tnc_get_bu_keys()
1611 if (bu->blk_cnt > UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1612 bu->blk_cnt = UBIFS_MAX_BULK_READ; in ubifs_tnc_get_bu_keys()
1614 * Ensure that bulk-read covers a whole number of page cache in ubifs_tnc_get_bu_keys()
1618 !(bu->blk_cnt & (UBIFS_BLOCKS_PER_PAGE - 1))) in ubifs_tnc_get_bu_keys()
1620 if (bu->eof) { in ubifs_tnc_get_bu_keys()
1622 bu->blk_cnt += UBIFS_BLOCKS_PER_PAGE - 1; in ubifs_tnc_get_bu_keys()
1626 block = key_block(c, &bu->key) + bu->blk_cnt; in ubifs_tnc_get_bu_keys()
1627 block &= ~(UBIFS_BLOCKS_PER_PAGE - 1); in ubifs_tnc_get_bu_keys()
1628 while (bu->cnt) { in ubifs_tnc_get_bu_keys()
1629 if (key_block(c, &bu->zbranch[bu->cnt - 1].key) < block) in ubifs_tnc_get_bu_keys()
1631 bu->cnt -= 1; in ubifs_tnc_get_bu_keys()
1637 * read_wbuf - bulk-read from a LEB with a wbuf.
1644 * This functions returns %0 on success or a negative error code on failure.
1649 const struct ubifs_info *c = wbuf->c; in read_wbuf()
1653 ubifs_assert(c, wbuf && lnum >= 0 && lnum < c->leb_cnt && offs >= 0); in read_wbuf()
1654 ubifs_assert(c, !(offs & 7) && offs < c->leb_size); in read_wbuf()
1655 ubifs_assert(c, offs + len <= c->leb_size); in read_wbuf()
1657 spin_lock(&wbuf->lock); in read_wbuf()
1658 overlap = (lnum == wbuf->lnum && offs + len > wbuf->offs); in read_wbuf()
1660 /* We may safely unlock the write-buffer and read the data */ in read_wbuf()
1661 spin_unlock(&wbuf->lock); in read_wbuf()
1666 rlen = wbuf->offs - offs; in read_wbuf()
1670 /* Copy the rest from the write-buffer */ in read_wbuf()
1671 memcpy(buf + rlen, wbuf->buf + offs + rlen - wbuf->offs, len - rlen); in read_wbuf()
1672 spin_unlock(&wbuf->lock); in read_wbuf()
1675 /* Read everything that goes before write-buffer */ in read_wbuf()
1682 * validate_data_node - validate data nodes for bulk-read.
1683 * @c: UBIFS file-system description object
1687 * This functions returns %0 on success or a negative error code on failure.
1696 if (ch->node_type != UBIFS_DATA_NODE) { in validate_data_node()
1698 ch->node_type, UBIFS_DATA_NODE); in validate_data_node()
1702 err = ubifs_check_node(c, buf, zbr->len, zbr->lnum, zbr->offs, 0, 0); in validate_data_node()
1708 err = ubifs_node_check_hash(c, buf, zbr->hash); in validate_data_node()
1710 ubifs_bad_hash(c, buf, zbr->hash, zbr->lnum, zbr->offs); in validate_data_node()
1714 len = le32_to_cpu(ch->len); in validate_data_node()
1715 if (len != zbr->len) { in validate_data_node()
1716 ubifs_err(c, "bad node length %d, expected %d", len, zbr->len); in validate_data_node()
1720 /* Make sure the key of the read node is correct */ in validate_data_node()
1722 if (!keys_eq(c, &zbr->key, &key1)) { in validate_data_node()
1723 ubifs_err(c, "bad key in node at LEB %d:%d", in validate_data_node()
1724 zbr->lnum, zbr->offs); in validate_data_node()
1725 dbg_tnck(&zbr->key, "looked for key "); in validate_data_node()
1726 dbg_tnck(&key1, "found node's key "); in validate_data_node()
1733 err = -EINVAL; in validate_data_node()
1735 ubifs_err(c, "bad node at LEB %d:%d", zbr->lnum, zbr->offs); in validate_data_node()
1736 ubifs_dump_node(c, buf, zbr->len); in validate_data_node()
1742 * ubifs_tnc_bulk_read - read a number of data nodes in one go.
1743 * @c: UBIFS file-system description object
1744 * @bu: bulk-read parameters and results
1748 * -EAGAIN to indicate a race with GC, or another negative error code on
1753 int lnum = bu->zbranch[0].lnum, offs = bu->zbranch[0].offs, len, err, i; in ubifs_tnc_bulk_read()
1757 len = bu->zbranch[bu->cnt - 1].offs; in ubifs_tnc_bulk_read()
1758 len += bu->zbranch[bu->cnt - 1].len - offs; in ubifs_tnc_bulk_read()
1759 if (len > bu->buf_len) { in ubifs_tnc_bulk_read()
1760 ubifs_err(c, "buffer too small %d vs %d", bu->buf_len, len); in ubifs_tnc_bulk_read()
1761 return -EINVAL; in ubifs_tnc_bulk_read()
1767 err = read_wbuf(wbuf, bu->buf, len, lnum, offs); in ubifs_tnc_bulk_read()
1769 err = ubifs_leb_read(c, lnum, bu->buf, offs, len, 0); in ubifs_tnc_bulk_read()
1772 if (maybe_leb_gced(c, lnum, bu->gc_seq)) in ubifs_tnc_bulk_read()
1773 return -EAGAIN; in ubifs_tnc_bulk_read()
1775 if (err && err != -EBADMSG) { in ubifs_tnc_bulk_read()
1779 dbg_tnck(&bu->key, "key "); in ubifs_tnc_bulk_read()
1784 buf = bu->buf; in ubifs_tnc_bulk_read()
1785 for (i = 0; i < bu->cnt; i++) { in ubifs_tnc_bulk_read()
1786 err = validate_data_node(c, buf, &bu->zbranch[i]); in ubifs_tnc_bulk_read()
1789 buf = buf + ALIGN(bu->zbranch[i].len, 8); in ubifs_tnc_bulk_read()
1796 * do_lookup_nm- look up a "hashed" node.
1797 * @c: UBIFS file-system description object
1798 * @key: node key to lookup
1802 * This function looks up and reads a node which contains name hash in the key.
1804 * key, so we have to sequentially look to all of them until the needed one is
1805 * found. This function returns zero in case of success, %-ENOENT if the node
1806 * was not found, and a negative error code in case of failure.
1808 static int do_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, in do_lookup_nm() argument
1814 dbg_tnck(key, "key "); in do_lookup_nm()
1815 mutex_lock(&c->tnc_mutex); in do_lookup_nm()
1816 found = ubifs_lookup_level0(c, key, &znode, &n); in do_lookup_nm()
1818 err = -ENOENT; in do_lookup_nm()
1827 err = resolve_collision(c, key, &znode, &n, nm); in do_lookup_nm()
1832 err = -ENOENT; in do_lookup_nm()
1836 err = tnc_read_hashed_node(c, &znode->zbranch[n], node); in do_lookup_nm()
1839 mutex_unlock(&c->tnc_mutex); in do_lookup_nm()
1844 * ubifs_tnc_lookup_nm - look up a "hashed" node.
1845 * @c: UBIFS file-system description object
1846 * @key: node key to lookup
1850 * This function looks up and reads a node which contains name hash in the key.
1852 * key, so we have to sequentially look to all of them until the needed one is
1853 * found. This function returns zero in case of success, %-ENOENT if the node
1854 * was not found, and a negative error code in case of failure.
1856 int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_lookup_nm() argument
1866 err = ubifs_tnc_lookup(c, key, node); in ubifs_tnc_lookup_nm()
1870 len = le16_to_cpu(dent->nlen); in ubifs_tnc_lookup_nm()
1871 if (fname_len(nm) == len && !memcmp(dent->name, fname_name(nm), len)) in ubifs_tnc_lookup_nm()
1879 return do_lookup_nm(c, key, node, nm); in ubifs_tnc_lookup_nm()
1882 static int search_dh_cookie(struct ubifs_info *c, const union ubifs_key *key, in search_dh_cookie() argument
1898 zbr = &znode->zbranch[*n]; in search_dh_cookie()
1899 dkey = &zbr->key; in search_dh_cookie()
1901 if (key_inum(c, dkey) != key_inum(c, key) || in search_dh_cookie()
1902 key_type(c, dkey) != key_type(c, key)) { in search_dh_cookie()
1903 return -ENOENT; in search_dh_cookie()
1910 if (key_hash(c, key) == key_hash(c, dkey) && in search_dh_cookie()
1911 le32_to_cpu(dent->cookie) == cookie) { in search_dh_cookie()
1922 static int do_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, in do_lookup_dh() argument
1929 ubifs_assert(c, is_hash_key(c, key)); in do_lookup_dh()
1931 lowest_dent_key(c, &start_key, key_inum(c, key)); in do_lookup_dh()
1933 mutex_lock(&c->tnc_mutex); in do_lookup_dh()
1938 err = search_dh_cookie(c, key, dent, cookie, &znode, &n, err); in do_lookup_dh()
1941 mutex_unlock(&c->tnc_mutex); in do_lookup_dh()
1946 * ubifs_tnc_lookup_dh - look up a "double hashed" node.
1947 * @c: UBIFS file-system description object
1948 * @key: node key to lookup
1952 * This function looks up and reads a node which contains name hash in the key.
1954 * key, so we have to sequentially look to all of them until the needed one
1956 * This function returns zero in case of success, %-ENOENT if the node
1957 * was not found, and a negative error code in case of failure.
1959 int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_lookup_dh() argument
1965 if (!c->double_hash) in ubifs_tnc_lookup_dh()
1966 return -EOPNOTSUPP; in ubifs_tnc_lookup_dh()
1972 err = ubifs_tnc_lookup(c, key, node); in ubifs_tnc_lookup_dh()
1976 if (le32_to_cpu(dent->cookie) == cookie) in ubifs_tnc_lookup_dh()
1983 return do_lookup_dh(c, key, node, cookie); in ubifs_tnc_lookup_dh()
1987 * correct_parent_keys - correct parent znodes' keys.
1988 * @c: UBIFS file-system description object
1991 * This is a helper function for 'tnc_insert()'. When the key of the leftmost
1998 union ubifs_key *key, *key1; in correct_parent_keys() local
2000 ubifs_assert(c, znode->parent); in correct_parent_keys()
2001 ubifs_assert(c, znode->iip == 0); in correct_parent_keys()
2003 key = &znode->zbranch[0].key; in correct_parent_keys()
2004 key1 = &znode->parent->zbranch[0].key; in correct_parent_keys()
2006 while (keys_cmp(c, key, key1) < 0) { in correct_parent_keys()
2007 key_copy(c, key, key1); in correct_parent_keys()
2008 znode = znode->parent; in correct_parent_keys()
2009 znode->alt = 1; in correct_parent_keys()
2010 if (!znode->parent || znode->iip) in correct_parent_keys()
2012 key1 = &znode->parent->zbranch[0].key; in correct_parent_keys()
2017 * insert_zbranch - insert a zbranch into a znode.
2018 * @c: UBIFS file-system description object
2025 * zbranch has to be inserted to the @znode->zbranches[]' array at the @n-th
2035 if (znode->level) { in insert_zbranch()
2036 for (i = znode->child_cnt; i > n; i--) { in insert_zbranch()
2037 znode->zbranch[i] = znode->zbranch[i - 1]; in insert_zbranch()
2038 if (znode->zbranch[i].znode) in insert_zbranch()
2039 znode->zbranch[i].znode->iip = i; in insert_zbranch()
2041 if (zbr->znode) in insert_zbranch()
2042 zbr->znode->iip = n; in insert_zbranch()
2044 for (i = znode->child_cnt; i > n; i--) in insert_zbranch()
2045 znode->zbranch[i] = znode->zbranch[i - 1]; in insert_zbranch()
2047 znode->zbranch[n] = *zbr; in insert_zbranch()
2048 znode->child_cnt += 1; in insert_zbranch()
2051 * After inserting at slot zero, the lower bound of the key range of in insert_zbranch()
2053 * then the upper bound of the key range may change, and furthermore in insert_zbranch()
2056 * TNC using the key from the index node on flash. That is bad because in insert_zbranch()
2065 znode->alt = 1; in insert_zbranch()
2069 * tnc_insert - insert a node into TNC.
2070 * @c: UBIFS file-system description object
2078 * error code in case of failure.
2085 union ubifs_key *key = &zbr->key, *key1; in tnc_insert() local
2087 ubifs_assert(c, n >= 0 && n <= c->fanout); in tnc_insert()
2091 zp = znode->parent; in tnc_insert()
2092 if (znode->child_cnt < c->fanout) { in tnc_insert()
2093 ubifs_assert(c, n != c->fanout); in tnc_insert()
2094 dbg_tnck(key, "inserted at %d level %d, key ", n, znode->level); in tnc_insert()
2098 /* Ensure parent's key is correct */ in tnc_insert()
2099 if (n == 0 && zp && znode->iip == 0) in tnc_insert()
2109 dbg_tnck(key, "splitting level %d, key ", znode->level); in tnc_insert()
2111 if (znode->alt) in tnc_insert()
2113 * We can no longer be sure of finding this znode by key, so we in tnc_insert()
2118 zn = kzalloc(c->max_znode_sz, GFP_NOFS); in tnc_insert()
2120 return -ENOMEM; in tnc_insert()
2121 zn->parent = zp; in tnc_insert()
2122 zn->level = znode->level; in tnc_insert()
2125 if (znode->level == 0 && key_type(c, key) == UBIFS_DATA_KEY) { in tnc_insert()
2127 if (n == c->fanout) { in tnc_insert()
2128 key1 = &znode->zbranch[n - 1].key; in tnc_insert()
2129 if (key_inum(c, key1) == key_inum(c, key) && in tnc_insert()
2134 } else if (appending && n != c->fanout) { in tnc_insert()
2138 if (n >= (c->fanout + 1) / 2) { in tnc_insert()
2139 key1 = &znode->zbranch[0].key; in tnc_insert()
2140 if (key_inum(c, key1) == key_inum(c, key) && in tnc_insert()
2142 key1 = &znode->zbranch[n].key; in tnc_insert()
2143 if (key_inum(c, key1) != key_inum(c, key) || in tnc_insert()
2146 move = c->fanout - keep; in tnc_insert()
2155 keep = c->fanout; in tnc_insert()
2158 keep = (c->fanout + 1) / 2; in tnc_insert()
2159 move = c->fanout - keep; in tnc_insert()
2171 keep -= 1; in tnc_insert()
2175 n -= keep; in tnc_insert()
2176 /* Re-parent */ in tnc_insert()
2177 if (zn->level != 0) in tnc_insert()
2178 zbr->znode->parent = zn; in tnc_insert()
2183 __set_bit(DIRTY_ZNODE, &zn->flags); in tnc_insert()
2184 atomic_long_inc(&c->dirty_zn_cnt); in tnc_insert()
2186 zn->child_cnt = move; in tnc_insert()
2187 znode->child_cnt = keep; in tnc_insert()
2193 zn->zbranch[i] = znode->zbranch[keep + i]; in tnc_insert()
2194 /* Re-parent */ in tnc_insert()
2195 if (zn->level != 0) in tnc_insert()
2196 if (zn->zbranch[i].znode) { in tnc_insert()
2197 zn->zbranch[i].znode->parent = zn; in tnc_insert()
2198 zn->zbranch[i].znode->iip = i; in tnc_insert()
2202 /* Insert new key and branch */ in tnc_insert()
2203 dbg_tnck(key, "inserting at %d level %d, key ", n, zn->level); in tnc_insert()
2209 if (n == 0 && zi == znode && znode->iip == 0) in tnc_insert()
2213 n = znode->iip + 1; in tnc_insert()
2216 zbr->key = zn->zbranch[0].key; in tnc_insert()
2217 zbr->znode = zn; in tnc_insert()
2218 zbr->lnum = 0; in tnc_insert()
2219 zbr->offs = 0; in tnc_insert()
2220 zbr->len = 0; in tnc_insert()
2227 dbg_tnc("creating new zroot at level %d", znode->level + 1); in tnc_insert()
2229 zi = kzalloc(c->max_znode_sz, GFP_NOFS); in tnc_insert()
2231 return -ENOMEM; in tnc_insert()
2233 zi->child_cnt = 2; in tnc_insert()
2234 zi->level = znode->level + 1; in tnc_insert()
2236 __set_bit(DIRTY_ZNODE, &zi->flags); in tnc_insert()
2237 atomic_long_inc(&c->dirty_zn_cnt); in tnc_insert()
2239 zi->zbranch[0].key = znode->zbranch[0].key; in tnc_insert()
2240 zi->zbranch[0].znode = znode; in tnc_insert()
2241 zi->zbranch[0].lnum = c->zroot.lnum; in tnc_insert()
2242 zi->zbranch[0].offs = c->zroot.offs; in tnc_insert()
2243 zi->zbranch[0].len = c->zroot.len; in tnc_insert()
2244 zi->zbranch[1].key = zn->zbranch[0].key; in tnc_insert()
2245 zi->zbranch[1].znode = zn; in tnc_insert()
2247 c->zroot.lnum = 0; in tnc_insert()
2248 c->zroot.offs = 0; in tnc_insert()
2249 c->zroot.len = 0; in tnc_insert()
2250 c->zroot.znode = zi; in tnc_insert()
2252 zn->parent = zi; in tnc_insert()
2253 zn->iip = 1; in tnc_insert()
2254 znode->parent = zi; in tnc_insert()
2255 znode->iip = 0; in tnc_insert()
2261 * ubifs_tnc_add - add a node to TNC.
2262 * @c: UBIFS file-system description object
2263 * @key: key to add
2269 * This function adds a node with key @key to TNC. The node may be new or it may
2270 * obsolete some existing one. Returns %0 on success or negative error code on
2273 int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum, in ubifs_tnc_add() argument
2279 mutex_lock(&c->tnc_mutex); in ubifs_tnc_add()
2280 dbg_tnck(key, "%d:%d, len %d, key ", lnum, offs, len); in ubifs_tnc_add()
2281 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_add()
2290 key_copy(c, key, &zbr.key); in ubifs_tnc_add()
2293 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_add()
2296 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_add()
2297 zbr->lnum = lnum; in ubifs_tnc_add()
2298 zbr->offs = offs; in ubifs_tnc_add()
2299 zbr->len = len; in ubifs_tnc_add()
2300 ubifs_copy_hash(c, hash, zbr->hash); in ubifs_tnc_add()
2305 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add()
2311 * ubifs_tnc_replace - replace a node in the TNC only if the old node is found.
2312 * @c: UBIFS file-system description object
2313 * @key: key to add
2320 * This function replaces a node with key @key in the TNC only if the old node
2322 * Returns %0 on success or negative error code on failure.
2324 int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_replace() argument
2330 mutex_lock(&c->tnc_mutex); in ubifs_tnc_replace()
2331 dbg_tnck(key, "old LEB %d:%d, new LEB %d:%d, len %d, key ", old_lnum, in ubifs_tnc_replace()
2333 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_replace()
2340 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_replace()
2343 if (zbr->lnum == old_lnum && zbr->offs == old_offs) { in ubifs_tnc_replace()
2345 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_replace()
2348 zbr->lnum = lnum; in ubifs_tnc_replace()
2349 zbr->offs = offs; in ubifs_tnc_replace()
2350 zbr->len = len; in ubifs_tnc_replace()
2352 } else if (is_hash_key(c, key)) { in ubifs_tnc_replace()
2353 found = resolve_collision_directly(c, key, &znode, &n, in ubifs_tnc_replace()
2364 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_replace()
2371 zbr = &znode->zbranch[n]; in ubifs_tnc_replace()
2373 err = ubifs_add_dirt(c, zbr->lnum, in ubifs_tnc_replace()
2374 zbr->len); in ubifs_tnc_replace()
2377 zbr->lnum = lnum; in ubifs_tnc_replace()
2378 zbr->offs = offs; in ubifs_tnc_replace()
2379 zbr->len = len; in ubifs_tnc_replace()
2391 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_replace()
2396 * ubifs_tnc_add_nm - add a "hashed" node to TNC.
2397 * @c: UBIFS file-system description object
2398 * @key: key to add
2408 int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_add_nm() argument
2415 mutex_lock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2416 dbg_tnck(key, "LEB %d:%d, key ", lnum, offs); in ubifs_tnc_add_nm()
2417 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_add_nm()
2424 if (c->replaying) in ubifs_tnc_add_nm()
2425 found = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_add_nm()
2428 found = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_add_nm()
2436 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_add_nm()
2445 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_add_nm()
2448 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_add_nm()
2449 zbr->lnum = lnum; in ubifs_tnc_add_nm()
2450 zbr->offs = offs; in ubifs_tnc_add_nm()
2451 zbr->len = len; in ubifs_tnc_add_nm()
2452 ubifs_copy_hash(c, hash, zbr->hash); in ubifs_tnc_add_nm()
2465 key_copy(c, key, &zbr.key); in ubifs_tnc_add_nm()
2469 if (c->replaying) { in ubifs_tnc_add_nm()
2473 * by passing 'ubifs_tnc_remove_nm()' the same key but in ubifs_tnc_add_nm()
2479 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2482 return ubifs_tnc_remove_nm(c, key, &noname); in ubifs_tnc_add_nm()
2489 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2494 * tnc_delete - delete a znode form TNC.
2495 * @c: UBIFS file-system description object
2499 * This function deletes a leaf node from @n-th slot of @znode. Returns zero in
2500 * case of success and a negative error code in case of failure.
2509 ubifs_assert(c, znode->level == 0); in tnc_delete()
2510 ubifs_assert(c, n >= 0 && n < c->fanout); in tnc_delete()
2511 dbg_tnck(&znode->zbranch[n].key, "deleting key "); in tnc_delete()
2513 zbr = &znode->zbranch[n]; in tnc_delete()
2516 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in tnc_delete()
2523 for (i = n; i < znode->child_cnt - 1; i++) in tnc_delete()
2524 znode->zbranch[i] = znode->zbranch[i + 1]; in tnc_delete()
2525 znode->child_cnt -= 1; in tnc_delete()
2527 if (znode->child_cnt > 0) in tnc_delete()
2539 zp = znode->parent; in tnc_delete()
2540 n = znode->iip; in tnc_delete()
2542 atomic_long_dec(&c->dirty_zn_cnt); in tnc_delete()
2548 if (znode->cnext) { in tnc_delete()
2549 __set_bit(OBSOLETE_ZNODE, &znode->flags); in tnc_delete()
2550 atomic_long_inc(&c->clean_zn_cnt); in tnc_delete()
2555 } while (znode->child_cnt == 1); /* while removing last child */ in tnc_delete()
2557 /* Remove from znode, entry n - 1 */ in tnc_delete()
2558 znode->child_cnt -= 1; in tnc_delete()
2559 ubifs_assert(c, znode->level != 0); in tnc_delete()
2560 for (i = n; i < znode->child_cnt; i++) { in tnc_delete()
2561 znode->zbranch[i] = znode->zbranch[i + 1]; in tnc_delete()
2562 if (znode->zbranch[i].znode) in tnc_delete()
2563 znode->zbranch[i].znode->iip = i; in tnc_delete()
2570 if (!znode->parent) { in tnc_delete()
2571 while (znode->child_cnt == 1 && znode->level != 0) { in tnc_delete()
2573 zbr = &znode->zbranch[0]; in tnc_delete()
2580 znode->parent = NULL; in tnc_delete()
2581 znode->iip = 0; in tnc_delete()
2582 if (c->zroot.len) { in tnc_delete()
2583 err = insert_old_idx(c, c->zroot.lnum, in tnc_delete()
2584 c->zroot.offs); in tnc_delete()
2588 c->zroot.lnum = zbr->lnum; in tnc_delete()
2589 c->zroot.offs = zbr->offs; in tnc_delete()
2590 c->zroot.len = zbr->len; in tnc_delete()
2591 c->zroot.znode = znode; in tnc_delete()
2594 atomic_long_dec(&c->dirty_zn_cnt); in tnc_delete()
2596 if (zp->cnext) { in tnc_delete()
2597 __set_bit(OBSOLETE_ZNODE, &zp->flags); in tnc_delete()
2598 atomic_long_inc(&c->clean_zn_cnt); in tnc_delete()
2609 * ubifs_tnc_remove - remove an index entry of a node.
2610 * @c: UBIFS file-system description object
2611 * @key: key of node
2613 * Returns %0 on success or negative error code on failure.
2615 int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key) in ubifs_tnc_remove() argument
2620 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove()
2621 dbg_tnck(key, "key "); in ubifs_tnc_remove()
2622 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove()
2633 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove()
2638 * ubifs_tnc_remove_nm - remove an index entry for a "hashed" node.
2639 * @c: UBIFS file-system description object
2640 * @key: key of node
2643 * Returns %0 on success or negative error code on failure.
2645 int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_remove_nm() argument
2651 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_nm()
2652 dbg_tnck(key, "key "); in ubifs_tnc_remove_nm()
2653 err = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove_nm()
2658 if (c->replaying) in ubifs_tnc_remove_nm()
2659 err = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_remove_nm()
2662 err = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_remove_nm()
2668 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_nm()
2682 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_nm()
2687 * ubifs_tnc_remove_dh - remove an index entry for a "double hashed" node.
2688 * @c: UBIFS file-system description object
2689 * @key: key of node
2692 * Returns %0 on success or negative error code on failure.
2694 int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_remove_dh() argument
2702 if (!c->double_hash) in ubifs_tnc_remove_dh()
2703 return -EOPNOTSUPP; in ubifs_tnc_remove_dh()
2705 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_dh()
2706 err = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove_dh()
2710 zbr = &znode->zbranch[n]; in ubifs_tnc_remove_dh()
2713 err = -ENOMEM; in ubifs_tnc_remove_dh()
2722 if (le32_to_cpu(dent->cookie) != cookie) { in ubifs_tnc_remove_dh()
2725 lowest_dent_key(c, &start_key, key_inum(c, key)); in ubifs_tnc_remove_dh()
2731 err = search_dh_cookie(c, key, dent, cookie, &znode, &n, err); in ubifs_tnc_remove_dh()
2736 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_dh()
2750 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_dh()
2755 * key_in_range - determine if a key falls within a range of keys.
2756 * @c: UBIFS file-system description object
2757 * @key: key to check
2758 * @from_key: lowest key in range
2759 * @to_key: highest key in range
2761 * This function returns %1 if the key is in range and %0 otherwise.
2763 static int key_in_range(struct ubifs_info *c, union ubifs_key *key, in key_in_range() argument
2766 if (keys_cmp(c, key, from_key) < 0) in key_in_range()
2768 if (keys_cmp(c, key, to_key) > 0) in key_in_range()
2774 * ubifs_tnc_remove_range - remove index entries in range.
2775 * @c: UBIFS file-system description object
2776 * @from_key: lowest key to remove
2777 * @to_key: highest key to remove
2781 * code in case of failure.
2788 union ubifs_key *key; in ubifs_tnc_remove_range() local
2790 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_range()
2798 key = from_key; in ubifs_tnc_remove_range()
2801 if (err == -ENOENT) { in ubifs_tnc_remove_range()
2807 key = &znode->zbranch[n].key; in ubifs_tnc_remove_range()
2808 if (!key_in_range(c, key, from_key, to_key)) { in ubifs_tnc_remove_range()
2815 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_range()
2824 for (i = n + 1, k = 0; i < znode->child_cnt; i++, k++) { in ubifs_tnc_remove_range()
2825 key = &znode->zbranch[i].key; in ubifs_tnc_remove_range()
2826 if (!key_in_range(c, key, from_key, to_key)) in ubifs_tnc_remove_range()
2828 lnc_free(&znode->zbranch[i]); in ubifs_tnc_remove_range()
2829 err = ubifs_add_dirt(c, znode->zbranch[i].lnum, in ubifs_tnc_remove_range()
2830 znode->zbranch[i].len); in ubifs_tnc_remove_range()
2835 dbg_tnck(key, "removing key "); in ubifs_tnc_remove_range()
2838 for (i = n + 1 + k; i < znode->child_cnt; i++) in ubifs_tnc_remove_range()
2839 znode->zbranch[i - k] = znode->zbranch[i]; in ubifs_tnc_remove_range()
2840 znode->child_cnt -= k; in ubifs_tnc_remove_range()
2852 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_range()
2857 * ubifs_tnc_remove_ino - remove an inode from TNC.
2858 * @c: UBIFS file-system description object
2863 * error code in case of failure.
2885 if (err == -ENOENT) in ubifs_tnc_remove_ino()
2891 xattr_inum = le64_to_cpu(xent->inum); in ubifs_tnc_remove_ino()
2892 dbg_tnc("xent '%s', ino %lu", xent->name, in ubifs_tnc_remove_ino()
2897 fname_name(&nm) = xent->name; in ubifs_tnc_remove_ino()
2898 fname_len(&nm) = le16_to_cpu(xent->nlen); in ubifs_tnc_remove_ino()
2917 key_read(c, &xent->key, &key1); in ubifs_tnc_remove_ino()
2928 * ubifs_tnc_next_ent - walk directory or extended attribute entries.
2929 * @c: UBIFS file-system description object
2930 * @key: key of last entry
2934 * after the given key (@key) if there is one. @nm is used to resolve
2937 * If the name of the current entry is not known and only the key is known,
2938 * @nm->name has to be %NULL. In this case the semantics of this function is a
2939 * little bit different and it returns the entry corresponding to this key, not
2940 * the next one. If the key was not found, the closest "right" entry is
2943 * If the fist entry has to be found, @key has to contain the lowest possible
2944 * key value for this inode and @name has to be %NULL.
2947 * in case of success, %-ENOENT is returned if no entry was found, and a
2948 * negative error code is returned in case of failure.
2951 union ubifs_key *key, in ubifs_tnc_next_ent() argument
2954 int n, err, type = key_type(c, key); in ubifs_tnc_next_ent()
2960 dbg_tnck(key, "key "); in ubifs_tnc_next_ent()
2961 ubifs_assert(c, is_hash_key(c, key)); in ubifs_tnc_next_ent()
2963 mutex_lock(&c->tnc_mutex); in ubifs_tnc_next_ent()
2964 err = ubifs_lookup_level0(c, key, &znode, &n); in ubifs_tnc_next_ent()
2971 if (c->replaying) in ubifs_tnc_next_ent()
2972 err = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_next_ent()
2975 err = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_next_ent()
2994 * However, the given key does not exist in the TNC in ubifs_tnc_next_ent()
3004 zbr = &znode->zbranch[n]; in ubifs_tnc_next_ent()
3005 dent = kmalloc(zbr->len, GFP_NOFS); in ubifs_tnc_next_ent()
3007 err = -ENOMEM; in ubifs_tnc_next_ent()
3015 dkey = &zbr->key; in ubifs_tnc_next_ent()
3016 if (key_inum(c, dkey) != key_inum(c, key) || in ubifs_tnc_next_ent()
3018 err = -ENOENT; in ubifs_tnc_next_ent()
3026 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_next_ent()
3032 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_next_ent()
3037 * tnc_destroy_cnext - destroy left-over obsolete znodes from a failed commit.
3038 * @c: UBIFS file-system description object
3040 * Destroy left-over obsolete znodes from a failed commit.
3046 if (!c->cnext) in tnc_destroy_cnext()
3048 ubifs_assert(c, c->cmt_state == COMMIT_BROKEN); in tnc_destroy_cnext()
3049 cnext = c->cnext; in tnc_destroy_cnext()
3053 cnext = cnext->cnext; in tnc_destroy_cnext()
3056 } while (cnext && cnext != c->cnext); in tnc_destroy_cnext()
3060 * ubifs_tnc_close - close TNC subsystem and free all related resources.
3061 * @c: UBIFS file-system description object
3066 if (c->zroot.znode) { in ubifs_tnc_close()
3069 n = atomic_long_read(&c->clean_zn_cnt); in ubifs_tnc_close()
3070 freed = ubifs_destroy_tnc_subtree(c, c->zroot.znode); in ubifs_tnc_close()
3074 kfree(c->gap_lebs); in ubifs_tnc_close()
3075 kfree(c->ilebs); in ubifs_tnc_close()
3080 * left_znode - get the znode to the left.
3081 * @c: UBIFS file-system description object
3085 * there is not one. A negative error code is returned on failure.
3090 int level = znode->level; in left_znode()
3093 int n = znode->iip - 1; in left_znode()
3096 znode = znode->parent; in left_znode()
3104 while (znode->level != level) { in left_znode()
3105 n = znode->child_cnt - 1; in left_znode()
3117 * right_znode - get the znode to the right.
3118 * @c: UBIFS file-system description object
3122 * if there is not one. A negative error code is returned on failure.
3127 int level = znode->level; in right_znode()
3130 int n = znode->iip + 1; in right_znode()
3133 znode = znode->parent; in right_znode()
3136 if (n < znode->child_cnt) { in right_znode()
3141 while (znode->level != level) { in right_znode()
3153 * lookup_znode - find a particular indexing node from TNC.
3154 * @c: UBIFS file-system description object
3155 * @key: index node key to lookup
3160 * This function searches an indexing node by its first key @key and its
3163 * were found on the media by scanning, for example when garbage-collecting or
3164 * when doing in-the-gaps commit. This means that the indexing node which is
3165 * looked for does not have to have exactly the same leftmost key @key, because
3166 * the leftmost key may have been changed, in which case TNC will contain a
3171 * not find it. For situations like this UBIFS has the old index RB-tree
3175 * found. A negative error code is returned on failure.
3178 union ubifs_key *key, int level, in lookup_znode() argument
3184 ubifs_assert(c, key_type(c, key) < UBIFS_INVALID_KEY); in lookup_znode()
3191 return ERR_PTR(-EINVAL); in lookup_znode()
3194 znode = c->zroot.znode; in lookup_znode()
3196 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in lookup_znode()
3201 if (c->zroot.lnum == lnum && c->zroot.offs == offs) in lookup_znode()
3204 if (level >= znode->level) in lookup_znode()
3207 ubifs_search_zbranch(c, znode, key, &n); in lookup_znode()
3210 * We reached a znode where the leftmost key is greater in lookup_znode()
3211 * than the key we are searching for. This is the same in lookup_znode()
3222 ubifs_search_zbranch(c, znode, key, &n); in lookup_znode()
3225 if (znode->level == level + 1) in lookup_znode()
3232 if (znode->zbranch[n].lnum == lnum && znode->zbranch[n].offs == offs) in lookup_znode()
3234 /* If the key is unique, there is nowhere else to look */ in lookup_znode()
3235 if (!is_hash_key(c, key)) in lookup_znode()
3238 * The key is not unique and so may be also in the znodes to either in lookup_znode()
3247 n -= 1; in lookup_znode()
3254 n = znode->child_cnt - 1; in lookup_znode()
3257 if (znode->zbranch[n].lnum == lnum && in lookup_znode()
3258 znode->zbranch[n].offs == offs) in lookup_znode()
3260 /* Stop if the key is less than the one we are looking for */ in lookup_znode()
3261 if (keys_cmp(c, &znode->zbranch[n].key, key) < 0) in lookup_znode()
3270 if (++n >= znode->child_cnt) { in lookup_znode()
3279 if (znode->zbranch[n].lnum == lnum && in lookup_znode()
3280 znode->zbranch[n].offs == offs) in lookup_znode()
3282 /* Stop if the key is greater than the one we are looking for */ in lookup_znode()
3283 if (keys_cmp(c, &znode->zbranch[n].key, key) > 0) in lookup_znode()
3290 * is_idx_node_in_tnc - determine if an index node is in the TNC.
3291 * @c: UBIFS file-system description object
3292 * @key: key of index node
3300 * znode is clean, and a negative error code in case of failure.
3302 * Note, the @key argument has to be the key of the first child. Also note,
3304 * offset for a main-area node.
3306 int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, in is_idx_node_in_tnc() argument
3311 znode = lookup_znode(c, key, level, lnum, offs); in is_idx_node_in_tnc()
3321 * is_leaf_node_in_tnc - determine if a non-indexing not is in the TNC.
3322 * @c: UBIFS file-system description object
3323 * @key: node key
3328 * not, and a negative error code in case of failure.
3331 * and offset for a main-area node.
3333 static int is_leaf_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, in is_leaf_node_in_tnc() argument
3339 const int unique = !is_hash_key(c, key); in is_leaf_node_in_tnc()
3341 found = ubifs_lookup_level0(c, key, &znode, &n); in is_leaf_node_in_tnc()
3343 return found; /* Error code */ in is_leaf_node_in_tnc()
3346 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3347 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3352 * Because the key is not unique, we have to look left in is_leaf_node_in_tnc()
3360 if (err == -ENOENT) in is_leaf_node_in_tnc()
3364 if (keys_cmp(c, key, &znode->zbranch[n].key)) in is_leaf_node_in_tnc()
3366 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3367 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3376 if (err == -ENOENT) in is_leaf_node_in_tnc()
3380 if (keys_cmp(c, key, &znode->zbranch[n].key)) in is_leaf_node_in_tnc()
3382 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3383 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3390 * ubifs_tnc_has_node - determine whether a node is in the TNC.
3391 * @c: UBIFS file-system description object
3392 * @key: node key
3396 * @is_idx: non-zero if the node is an index node
3399 * negative error code in case of failure. For index nodes, @key has to be the
3400 * key of the first child. An index node is considered to be in the TNC only if
3403 int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level, in ubifs_tnc_has_node() argument
3408 mutex_lock(&c->tnc_mutex); in ubifs_tnc_has_node()
3410 err = is_idx_node_in_tnc(c, key, level, lnum, offs); in ubifs_tnc_has_node()
3422 err = is_leaf_node_in_tnc(c, key, lnum, offs); in ubifs_tnc_has_node()
3425 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_has_node()
3430 * ubifs_dirty_idx_node - dirty an index node.
3431 * @c: UBIFS file-system description object
3432 * @key: index node key
3438 * collected. The @key argument has to be the key of the first child. This
3440 * for a main-area node. Returns %0 on success and a negative error code on
3443 int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level, in ubifs_dirty_idx_node() argument
3449 mutex_lock(&c->tnc_mutex); in ubifs_dirty_idx_node()
3450 znode = lookup_znode(c, key, level, lnum, offs); in ubifs_dirty_idx_node()
3464 mutex_unlock(&c->tnc_mutex); in ubifs_dirty_idx_node()
3469 * dbg_check_inode_size - check if inode size is correct.
3470 * @c: UBIFS file-system description object
3475 * not have any pages beyond @size. Returns zero if the inode is OK, %-EINVAL
3476 * if it has a data page beyond @size, and other negative error code in case of
3483 union ubifs_key from_key, to_key, *key; in dbg_check_inode_size() local
3487 if (!S_ISREG(inode->i_mode)) in dbg_check_inode_size()
3492 block = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT; in dbg_check_inode_size()
3493 data_key_init(c, &from_key, inode->i_ino, block); in dbg_check_inode_size()
3494 highest_data_key(c, &to_key, inode->i_ino); in dbg_check_inode_size()
3496 mutex_lock(&c->tnc_mutex); in dbg_check_inode_size()
3502 key = &from_key; in dbg_check_inode_size()
3507 if (err == -ENOENT) { in dbg_check_inode_size()
3515 key = &znode->zbranch[n].key; in dbg_check_inode_size()
3516 if (!key_in_range(c, key, &from_key, &to_key)) in dbg_check_inode_size()
3520 block = key_block(c, key); in dbg_check_inode_size()
3522 (unsigned long)inode->i_ino, size, in dbg_check_inode_size()
3524 mutex_unlock(&c->tnc_mutex); in dbg_check_inode_size()
3527 return -EINVAL; in dbg_check_inode_size()
3530 mutex_unlock(&c->tnc_mutex); in dbg_check_inode_size()