• Home
  • Raw
  • Download

Lines Matching +full:key +full:- +full:code

4  * Copyright (C) 2006-2008 Nokia Corporation.
17 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 * the UBIFS B-tree.
39 static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key,
60 * insert_old_idx - record an index node obsoleted since the last commit start.
61 * @c: UBIFS file-system description object
65 * Returns %0 on success, and a negative error code on failure.
73 * That means that the garbage collection and the in-the-gaps method of
78 * they cannot be easily found. In those cases, an entry is added to an RB-tree.
79 * That is what this function does. The RB-tree is ordered by LEB number and
89 return -ENOMEM; in insert_old_idx()
90 old_idx->lnum = lnum; in insert_old_idx()
91 old_idx->offs = offs; in insert_old_idx()
93 p = &c->old_idx.rb_node; in insert_old_idx()
97 if (lnum < o->lnum) in insert_old_idx()
98 p = &(*p)->rb_left; in insert_old_idx()
99 else if (lnum > o->lnum) in insert_old_idx()
100 p = &(*p)->rb_right; in insert_old_idx()
101 else if (offs < o->offs) in insert_old_idx()
102 p = &(*p)->rb_left; in insert_old_idx()
103 else if (offs > o->offs) in insert_old_idx()
104 p = &(*p)->rb_right; in insert_old_idx()
111 rb_link_node(&old_idx->rb, parent, p); in insert_old_idx()
112 rb_insert_color(&old_idx->rb, &c->old_idx); in insert_old_idx()
117 * insert_old_idx_znode - record a znode obsoleted since last commit start.
118 * @c: UBIFS file-system description object
121 * Returns %0 on success, and a negative error code on failure.
125 if (znode->parent) { in insert_old_idx_znode()
128 zbr = &znode->parent->zbranch[znode->iip]; in insert_old_idx_znode()
129 if (zbr->len) in insert_old_idx_znode()
130 return insert_old_idx(c, zbr->lnum, zbr->offs); in insert_old_idx_znode()
132 if (c->zroot.len) in insert_old_idx_znode()
133 return insert_old_idx(c, c->zroot.lnum, in insert_old_idx_znode()
134 c->zroot.offs); in insert_old_idx_znode()
139 * ins_clr_old_idx_znode - record a znode obsoleted since last commit start.
140 * @c: UBIFS file-system description object
143 * Returns %0 on success, and a negative error code on failure.
150 if (znode->parent) { in ins_clr_old_idx_znode()
153 zbr = &znode->parent->zbranch[znode->iip]; in ins_clr_old_idx_znode()
154 if (zbr->len) { in ins_clr_old_idx_znode()
155 err = insert_old_idx(c, zbr->lnum, zbr->offs); in ins_clr_old_idx_znode()
158 zbr->lnum = 0; in ins_clr_old_idx_znode()
159 zbr->offs = 0; in ins_clr_old_idx_znode()
160 zbr->len = 0; in ins_clr_old_idx_znode()
163 if (c->zroot.len) { in ins_clr_old_idx_znode()
164 err = insert_old_idx(c, c->zroot.lnum, c->zroot.offs); in ins_clr_old_idx_znode()
167 c->zroot.lnum = 0; in ins_clr_old_idx_znode()
168 c->zroot.offs = 0; in ins_clr_old_idx_znode()
169 c->zroot.len = 0; in ins_clr_old_idx_znode()
175 * destroy_old_idx - destroy the old_idx RB-tree.
176 * @c: UBIFS file-system description object
178 * During start commit, the old_idx RB-tree is used to avoid overwriting index
181 * new index is successfully written. The old-idx RB-tree is used for the
182 * in-the-gaps method of writing index nodes and is destroyed every commit.
188 rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb) in destroy_old_idx()
191 c->old_idx = RB_ROOT; in destroy_old_idx()
195 * copy_znode - copy a dirty znode.
196 * @c: UBIFS file-system description object
206 zn = kmemdup(znode, c->max_znode_sz, GFP_NOFS); in copy_znode()
208 return ERR_PTR(-ENOMEM); in copy_znode()
210 zn->cnext = NULL; in copy_znode()
211 __set_bit(DIRTY_ZNODE, &zn->flags); in copy_znode()
212 __clear_bit(COW_ZNODE, &zn->flags); in copy_znode()
215 __set_bit(OBSOLETE_ZNODE, &znode->flags); in copy_znode()
217 if (znode->level != 0) { in copy_znode()
219 const int n = zn->child_cnt; in copy_znode()
223 struct ubifs_zbranch *zbr = &zn->zbranch[i]; in copy_znode()
225 if (zbr->znode) in copy_znode()
226 zbr->znode->parent = zn; in copy_znode()
230 atomic_long_inc(&c->dirty_zn_cnt); in copy_znode()
235 * add_idx_dirt - add dirt due to a dirty znode.
236 * @c: UBIFS file-system description object
244 c->calc_idx_sz -= ALIGN(dirt, 8); in add_idx_dirt()
249 * dirty_cow_znode - ensure a znode is not being committed.
250 * @c: UBIFS file-system description object
253 * Returns dirtied znode on success or negative error code on failure.
258 struct ubifs_znode *znode = zbr->znode; in dirty_cow_znode()
264 if (!test_and_set_bit(DIRTY_ZNODE, &znode->flags)) { in dirty_cow_znode()
265 atomic_long_inc(&c->dirty_zn_cnt); in dirty_cow_znode()
266 atomic_long_dec(&c->clean_zn_cnt); in dirty_cow_znode()
268 err = add_idx_dirt(c, zbr->lnum, zbr->len); in dirty_cow_znode()
279 if (zbr->len) { in dirty_cow_znode()
280 err = insert_old_idx(c, zbr->lnum, zbr->offs); in dirty_cow_znode()
283 err = add_idx_dirt(c, zbr->lnum, zbr->len); in dirty_cow_znode()
287 zbr->znode = zn; in dirty_cow_znode()
288 zbr->lnum = 0; in dirty_cow_znode()
289 zbr->offs = 0; in dirty_cow_znode()
290 zbr->len = 0; in dirty_cow_znode()
298 * lnc_add - add a leaf node to the leaf node cache.
299 * @c: UBIFS file-system description object
303 * Leaf nodes are non-index nodes directory entry nodes or data nodes. The
304 * purpose of the leaf node cache is to save re-reading the same leaf node over
314 * used with @c->tnc_mutex unlock upon return from the TNC subsystem. But LNC
324 ubifs_assert(c, !zbr->leaf); in lnc_add()
325 ubifs_assert(c, zbr->len != 0); in lnc_add()
326 ubifs_assert(c, is_hash_key(c, &zbr->key)); in lnc_add()
335 lnc_node = kmemdup(node, zbr->len, GFP_NOFS); in lnc_add()
340 zbr->leaf = lnc_node; in lnc_add()
345 * lnc_add_directly - add a leaf node to the leaf-node-cache.
346 * @c: UBIFS file-system description object
358 ubifs_assert(c, !zbr->leaf); in lnc_add_directly()
359 ubifs_assert(c, zbr->len != 0); in lnc_add_directly()
368 zbr->leaf = node; in lnc_add_directly()
373 * lnc_free - remove a leaf node from the leaf node cache.
379 if (!zbr->leaf) in lnc_free()
381 kfree(zbr->leaf); in lnc_free()
382 zbr->leaf = NULL; in lnc_free()
386 * tnc_read_hashed_node - read a "hashed" leaf node.
387 * @c: UBIFS file-system description object
388 * @zbr: key and position of the node
394 * code in case of failure.
401 ubifs_assert(c, is_hash_key(c, &zbr->key)); in tnc_read_hashed_node()
403 if (zbr->leaf) { in tnc_read_hashed_node()
405 ubifs_assert(c, zbr->len != 0); in tnc_read_hashed_node()
406 memcpy(node, zbr->leaf, zbr->len); in tnc_read_hashed_node()
410 if (c->replaying) { in tnc_read_hashed_node()
411 err = fallible_read_node(c, &zbr->key, zbr, node); in tnc_read_hashed_node()
413 * When the node was not found, return -ENOENT, 0 otherwise. in tnc_read_hashed_node()
414 * Negative return codes stay as-is. in tnc_read_hashed_node()
417 err = -ENOENT; in tnc_read_hashed_node()
432 * try_read_node - read a node if it is a node.
433 * @c: UBIFS file-system description object
442 * a node is not present. A negative error code is returned for I/O errors.
445 * the return code indicates if a node was read.
447 * Note, this function does not check CRC of data nodes if @c->no_chk_data_crc
449 * @c->mounting or @c->remounting_rw is true (we are mounting or re-mounting to
450 * R/W mode), @c->no_chk_data_crc is ignored and CRC is checked. This is
451 * because during mounting or re-mounting from R/O mode to R/W mode we may read
471 if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) in try_read_node()
474 if (ch->node_type != type) in try_read_node()
477 node_len = le32_to_cpu(ch->len); in try_read_node()
481 if (type == UBIFS_DATA_NODE && c->no_chk_data_crc && !c->mounting && in try_read_node()
482 !c->remounting_rw) in try_read_node()
485 crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); in try_read_node()
486 node_crc = le32_to_cpu(ch->crc); in try_read_node()
494 * fallible_read_node - try to read a leaf node.
495 * @c: UBIFS file-system description object
496 * @key: key of node to read
501 * if the node is not present, and a negative error code in the case of error.
503 static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key, in fallible_read_node() argument
508 dbg_tnck(key, "LEB %d:%d, key ", zbr->lnum, zbr->offs); in fallible_read_node()
510 ret = try_read_node(c, node, key_type(c, key), zbr->len, zbr->lnum, in fallible_read_node()
511 zbr->offs); in fallible_read_node()
516 /* All nodes have key in the same place */ in fallible_read_node()
517 key_read(c, &dent->key, &node_key); in fallible_read_node()
518 if (keys_cmp(c, key, &node_key) != 0) in fallible_read_node()
521 if (ret == 0 && c->replaying) in fallible_read_node()
522 dbg_mntk(key, "dangling branch LEB %d:%d len %d, key ", in fallible_read_node()
523 zbr->lnum, zbr->offs, zbr->len); in fallible_read_node()
528 * matches_name - determine if a direntry or xattr entry matches a given name.
529 * @c: UBIFS file-system description object
536 * of failure, a negative error code is returned.
545 if (!zbr->leaf) { in matches_name()
546 dent = kmalloc(zbr->len, GFP_NOFS); in matches_name()
548 return -ENOMEM; in matches_name()
559 dent = zbr->leaf; in matches_name()
561 nlen = le16_to_cpu(dent->nlen); in matches_name()
562 err = memcmp(dent->name, fname_name(nm), min_t(int, nlen, fname_len(nm))); in matches_name()
581 * get_znode - get a TNC znode that may not be loaded yet.
582 * @c: UBIFS file-system description object
586 * This function returns the znode or a negative error code.
593 zbr = &znode->zbranch[n]; in get_znode()
594 if (zbr->znode) in get_znode()
595 znode = zbr->znode; in get_znode()
602 * tnc_next - find next TNC entry.
603 * @c: UBIFS file-system description object
607 * This function returns %0 if the next TNC entry is found, %-ENOENT if there is
608 * no next entry, or a negative error code otherwise.
616 if (nn < znode->child_cnt) { in tnc_next()
623 zp = znode->parent; in tnc_next()
625 return -ENOENT; in tnc_next()
626 nn = znode->iip + 1; in tnc_next()
628 if (nn < znode->child_cnt) { in tnc_next()
632 while (znode->level != 0) { in tnc_next()
647 * tnc_prev - find previous TNC entry.
648 * @c: UBIFS file-system description object
652 * This function returns %0 if the previous TNC entry is found, %-ENOENT if
653 * there is no next entry, or a negative error code otherwise.
661 *n = nn - 1; in tnc_prev()
667 zp = znode->parent; in tnc_prev()
669 return -ENOENT; in tnc_prev()
670 nn = znode->iip - 1; in tnc_prev()
676 while (znode->level != 0) { in tnc_prev()
677 nn = znode->child_cnt - 1; in tnc_prev()
682 nn = znode->child_cnt - 1; in tnc_prev()
692 * resolve_collision - resolve a collision.
693 * @c: UBIFS file-system description object
694 * @key: key of a directory or extended attribute entry
699 * This function is called for "hashed" keys to make sure that the found key
704 * This means that @n may be set to %-1 if the leftmost key in @zn is the
705 * previous one. A negative error code is returned on failures.
707 static int resolve_collision(struct ubifs_info *c, const union ubifs_key *key, in resolve_collision() argument
713 err = matches_name(c, &(*zn)->zbranch[*n], nm); in resolve_collision()
723 if (err == -ENOENT) { in resolve_collision()
725 *n = -1; in resolve_collision()
730 if (keys_cmp(c, &(*zn)->zbranch[*n].key, key)) { in resolve_collision()
739 * ---------------------- in resolve_collision()
741 * ----------------------- in resolve_collision()
744 * ------------ ------------ in resolve_collision()
746 * ------------ ------------ in resolve_collision()
758 * 'tnc_insert()' would correct the parent key. in resolve_collision()
760 if (*n == (*zn)->child_cnt - 1) { in resolve_collision()
765 if (err == -ENOENT) in resolve_collision()
766 err = -EINVAL; in resolve_collision()
770 *n = -1; in resolve_collision()
774 err = matches_name(c, &(*zn)->zbranch[*n], nm); in resolve_collision()
790 if (err == -ENOENT) in resolve_collision()
794 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision()
796 err = matches_name(c, &znode->zbranch[nn], nm); in resolve_collision()
811 * fallible_matches_name - determine if a dent matches a given name.
812 * @c: UBIFS file-system description object
823 * error code is returned in case of failure.
833 if (!zbr->leaf) { in fallible_matches_name()
834 dent = kmalloc(zbr->len, GFP_NOFS); in fallible_matches_name()
836 return -ENOMEM; in fallible_matches_name()
838 err = fallible_read_node(c, &zbr->key, zbr, dent); in fallible_matches_name()
852 dent = zbr->leaf; in fallible_matches_name()
854 nlen = le16_to_cpu(dent->nlen); in fallible_matches_name()
855 err = memcmp(dent->name, fname_name(nm), min_t(int, nlen, fname_len(nm))); in fallible_matches_name()
874 * fallible_resolve_collision - resolve a collision even if nodes are missing.
875 * @c: UBIFS file-system description object
876 * @key: key
880 * @adding: indicates caller is adding a key to the TNC
885 * Garbage-collected and the commit was not done. A branch that refers to a node
893 * o a negative error code is returned in case of failure.
896 const union ubifs_key *key, in fallible_resolve_collision() argument
904 cmp = fallible_matches_name(c, &znode->zbranch[nn], nm); in fallible_resolve_collision()
915 * branch - to the left or to the right. Well, let's try left. in fallible_resolve_collision()
925 if (err == -ENOENT) { in fallible_resolve_collision()
927 *n = -1; in fallible_resolve_collision()
932 if (keys_cmp(c, &(*zn)->zbranch[*n].key, key)) { in fallible_resolve_collision()
934 if (*n == (*zn)->child_cnt - 1) { in fallible_resolve_collision()
939 if (err == -ENOENT) in fallible_resolve_collision()
940 err = -EINVAL; in fallible_resolve_collision()
944 *n = -1; in fallible_resolve_collision()
948 err = fallible_matches_name(c, &(*zn)->zbranch[*n], nm); in fallible_resolve_collision()
973 if (err == -ENOENT) in fallible_resolve_collision()
977 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in fallible_resolve_collision()
979 err = fallible_matches_name(c, &znode->zbranch[nn], nm); in fallible_resolve_collision()
999 dbg_mntk(key, "dangling match LEB %d:%d len %d key ", in fallible_resolve_collision()
1000 o_znode->zbranch[o_n].lnum, o_znode->zbranch[o_n].offs, in fallible_resolve_collision()
1001 o_znode->zbranch[o_n].len); in fallible_resolve_collision()
1008 * matches_position - determine if a zbranch matches a given position.
1017 if (zbr->lnum == lnum && zbr->offs == offs) in matches_position()
1024 * resolve_collision_directly - resolve a collision directly.
1025 * @c: UBIFS file-system description object
1026 * @key: key of directory entry
1038 * previous directory entry. Otherwise a negative error code is returned.
1041 const union ubifs_key *key, in resolve_collision_directly() argument
1050 if (matches_position(&znode->zbranch[nn], lnum, offs)) in resolve_collision_directly()
1056 if (err == -ENOENT) in resolve_collision_directly()
1060 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision_directly()
1062 if (matches_position(&znode->zbranch[nn], lnum, offs)) { in resolve_collision_directly()
1074 if (err == -ENOENT) in resolve_collision_directly()
1078 if (keys_cmp(c, &znode->zbranch[nn].key, key)) in resolve_collision_directly()
1082 if (matches_position(&znode->zbranch[nn], lnum, offs)) in resolve_collision_directly()
1088 * dirty_cow_bottom_up - dirty a znode and its ancestors.
1089 * @c: UBIFS file-system description object
1092 * If we do not have a unique key that resides in a znode, then we cannot
1101 int *path = c->bottom_up_buf, p = 0; in dirty_cow_bottom_up()
1103 ubifs_assert(c, c->zroot.znode); in dirty_cow_bottom_up()
1105 if (c->zroot.znode->level > BOTTOM_UP_HEIGHT) { in dirty_cow_bottom_up()
1106 kfree(c->bottom_up_buf); in dirty_cow_bottom_up()
1107 c->bottom_up_buf = kmalloc_array(c->zroot.znode->level, in dirty_cow_bottom_up()
1110 if (!c->bottom_up_buf) in dirty_cow_bottom_up()
1111 return ERR_PTR(-ENOMEM); in dirty_cow_bottom_up()
1112 path = c->bottom_up_buf; in dirty_cow_bottom_up()
1114 if (c->zroot.znode->level) { in dirty_cow_bottom_up()
1119 zp = znode->parent; in dirty_cow_bottom_up()
1122 n = znode->iip; in dirty_cow_bottom_up()
1123 ubifs_assert(c, p < c->zroot.znode->level); in dirty_cow_bottom_up()
1125 if (!zp->cnext && ubifs_zn_dirty(znode)) in dirty_cow_bottom_up()
1135 zp = znode->parent; in dirty_cow_bottom_up()
1137 ubifs_assert(c, path[p - 1] >= 0); in dirty_cow_bottom_up()
1138 ubifs_assert(c, path[p - 1] < zp->child_cnt); in dirty_cow_bottom_up()
1139 zbr = &zp->zbranch[path[--p]]; in dirty_cow_bottom_up()
1142 ubifs_assert(c, znode == c->zroot.znode); in dirty_cow_bottom_up()
1143 znode = dirty_cow_znode(c, &c->zroot); in dirty_cow_bottom_up()
1147 ubifs_assert(c, path[p - 1] >= 0); in dirty_cow_bottom_up()
1148 ubifs_assert(c, path[p - 1] < znode->child_cnt); in dirty_cow_bottom_up()
1149 znode = znode->zbranch[path[p - 1]].znode; in dirty_cow_bottom_up()
1156 * ubifs_lookup_level0 - search for zero-level znode.
1157 * @c: UBIFS file-system description object
1158 * @key: key to lookup
1162 * This function looks up the TNC tree and search for zero-level znode which
1163 * refers key @key. The found zero-level znode is returned in @zn. There are 3
1165 * o exact match, i.e. the found zero-level znode contains key @key, then %1
1167 * o not exact match, which means that zero-level znode does not contain
1168 * @key, then %0 is returned and slot number of the closest branch or %-1
1170 * o @key is so small that it is even less than the lowest key of the
1171 * leftmost zero-level node, then %0 is returned and %0 is stored in @n.
1175 * case of failure, a negative error code is returned.
1177 int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key, in ubifs_lookup_level0() argument
1184 dbg_tnck(key, "search key "); in ubifs_lookup_level0()
1185 ubifs_assert(c, key_type(c, key) < UBIFS_INVALID_KEY); in ubifs_lookup_level0()
1187 znode = c->zroot.znode; in ubifs_lookup_level0()
1189 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in ubifs_lookup_level0()
1194 znode->time = time; in ubifs_lookup_level0()
1199 exact = ubifs_search_zbranch(c, znode, key, n); in ubifs_lookup_level0()
1201 if (znode->level == 0) in ubifs_lookup_level0()
1206 zbr = &znode->zbranch[*n]; in ubifs_lookup_level0()
1208 if (zbr->znode) { in ubifs_lookup_level0()
1209 znode->time = time; in ubifs_lookup_level0()
1210 znode = zbr->znode; in ubifs_lookup_level0()
1221 if (exact || !is_hash_key(c, key) || *n != -1) { in ubifs_lookup_level0()
1222 dbg_tnc("found %d, lvl %d, n %d", exact, znode->level, *n); in ubifs_lookup_level0()
1227 * Here is a tricky place. We have not found the key and this is a in ubifs_lookup_level0()
1228 * "hashed" key, which may collide. The rest of the code deals with in ubifs_lookup_level0()
1243 * In the examples, if we are looking for key "5", we may reach nodes in ubifs_lookup_level0()
1245 * left and see if there is "5" key there. If there is, we have to in ubifs_lookup_level0()
1249 * elements which are equivalent to the next key in the parent in the in ubifs_lookup_level0()
1257 * And this becomes what is at the first "picture" after key "5" marked in ubifs_lookup_level0()
1260 * removing the leftmost key, we would have to correct the key of the in ubifs_lookup_level0()
1262 * if we changed the leftmost key of the parent znode, the garbage in ubifs_lookup_level0()
1264 * indexing LEBs). Although we already have an additional RB-tree where in ubifs_lookup_level0()
1270 if (err == -ENOENT) { in ubifs_lookup_level0()
1271 dbg_tnc("found 0, lvl %d, n -1", znode->level); in ubifs_lookup_level0()
1272 *n = -1; in ubifs_lookup_level0()
1277 if (keys_cmp(c, key, &znode->zbranch[*n].key)) { in ubifs_lookup_level0()
1278 dbg_tnc("found 0, lvl %d, n -1", znode->level); in ubifs_lookup_level0()
1279 *n = -1; in ubifs_lookup_level0()
1283 dbg_tnc("found 1, lvl %d, n %d", znode->level, *n); in ubifs_lookup_level0()
1289 * lookup_level0_dirty - search for zero-level znode dirtying.
1290 * @c: UBIFS file-system description object
1291 * @key: key to lookup
1295 * This function looks up the TNC tree and search for zero-level znode which
1296 * refers key @key. The found zero-level znode is returned in @zn. There are 3
1298 * o exact match, i.e. the found zero-level znode contains key @key, then %1
1300 * o not exact match, which means that zero-level znode does not contain @key
1303 * o @key is so small that it is even less than the lowest key of the
1304 * leftmost zero-level node, then %0 is returned and %-1 is stored in @n.
1306 * Additionally all znodes in the path from the root to the located zero-level
1311 * case of failure, a negative error code is returned.
1313 static int lookup_level0_dirty(struct ubifs_info *c, const union ubifs_key *key, in lookup_level0_dirty() argument
1320 dbg_tnck(key, "search and dirty key "); in lookup_level0_dirty()
1322 znode = c->zroot.znode; in lookup_level0_dirty()
1324 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in lookup_level0_dirty()
1329 znode = dirty_cow_znode(c, &c->zroot); in lookup_level0_dirty()
1333 znode->time = time; in lookup_level0_dirty()
1338 exact = ubifs_search_zbranch(c, znode, key, n); in lookup_level0_dirty()
1340 if (znode->level == 0) in lookup_level0_dirty()
1345 zbr = &znode->zbranch[*n]; in lookup_level0_dirty()
1347 if (zbr->znode) { in lookup_level0_dirty()
1348 znode->time = time; in lookup_level0_dirty()
1365 if (exact || !is_hash_key(c, key) || *n != -1) { in lookup_level0_dirty()
1366 dbg_tnc("found %d, lvl %d, n %d", exact, znode->level, *n); in lookup_level0_dirty()
1372 * code. in lookup_level0_dirty()
1375 if (err == -ENOENT) { in lookup_level0_dirty()
1376 *n = -1; in lookup_level0_dirty()
1377 dbg_tnc("found 0, lvl %d, n -1", znode->level); in lookup_level0_dirty()
1382 if (keys_cmp(c, key, &znode->zbranch[*n].key)) { in lookup_level0_dirty()
1383 *n = -1; in lookup_level0_dirty()
1384 dbg_tnc("found 0, lvl %d, n -1", znode->level); in lookup_level0_dirty()
1388 if (znode->cnext || !ubifs_zn_dirty(znode)) { in lookup_level0_dirty()
1394 dbg_tnc("found 1, lvl %d, n %d", znode->level, *n); in lookup_level0_dirty()
1400 * maybe_leb_gced - determine if a LEB may have been garbage collected.
1401 * @c: UBIFS file-system description object
1413 gced_lnum = c->gced_lnum; in maybe_leb_gced()
1415 gc_seq2 = c->gc_seq; in maybe_leb_gced()
1427 if (gced_lnum != c->gced_lnum) in maybe_leb_gced()
1436 * ubifs_tnc_locate - look up a file-system node and return it and its location.
1437 * @c: UBIFS file-system description object
1438 * @key: node key to lookup
1443 * This function looks up and reads node with key @key. The caller has to make
1445 * of success, %-ENOENT if the node was not found, and a negative error code in
1448 int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_locate() argument
1456 mutex_lock(&c->tnc_mutex); in ubifs_tnc_locate()
1457 found = ubifs_lookup_level0(c, key, &znode, &n); in ubifs_tnc_locate()
1459 err = -ENOENT; in ubifs_tnc_locate()
1465 zt = &znode->zbranch[n]; in ubifs_tnc_locate()
1467 *lnum = zt->lnum; in ubifs_tnc_locate()
1468 *offs = zt->offs; in ubifs_tnc_locate()
1470 if (is_hash_key(c, key)) { in ubifs_tnc_locate()
1483 zbr = znode->zbranch[n]; in ubifs_tnc_locate()
1484 gc_seq1 = c->gc_seq; in ubifs_tnc_locate()
1485 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_locate()
1493 err = fallible_read_node(c, key, &zbr, node); in ubifs_tnc_locate()
1505 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_locate()
1510 * ubifs_tnc_get_bu_keys - lookup keys for bulk-read.
1511 * @c: UBIFS file-system description object
1512 * @bu: bulk-read parameters and results
1516 * and a negative error code in case of failure.
1518 * Note, if the bulk-read buffer length (@bu->buf_len) is known, this function
1519 * makes sure bulk-read nodes fit the buffer. Otherwise, this function prepares
1520 * maximum possible amount of nodes for bulk-read.
1524 int n, err = 0, lnum = -1, uninitialized_var(offs); in ubifs_tnc_get_bu_keys()
1526 unsigned int block = key_block(c, &bu->key); in ubifs_tnc_get_bu_keys()
1529 bu->cnt = 0; in ubifs_tnc_get_bu_keys()
1530 bu->blk_cnt = 0; in ubifs_tnc_get_bu_keys()
1531 bu->eof = 0; in ubifs_tnc_get_bu_keys()
1533 mutex_lock(&c->tnc_mutex); in ubifs_tnc_get_bu_keys()
1534 /* Find first key */ in ubifs_tnc_get_bu_keys()
1535 err = ubifs_lookup_level0(c, &bu->key, &znode, &n); in ubifs_tnc_get_bu_keys()
1539 /* Key found */ in ubifs_tnc_get_bu_keys()
1540 len = znode->zbranch[n].len; in ubifs_tnc_get_bu_keys()
1542 if (len > bu->buf_len) { in ubifs_tnc_get_bu_keys()
1543 err = -EINVAL; in ubifs_tnc_get_bu_keys()
1546 /* Add this key */ in ubifs_tnc_get_bu_keys()
1547 bu->zbranch[bu->cnt++] = znode->zbranch[n]; in ubifs_tnc_get_bu_keys()
1548 bu->blk_cnt += 1; in ubifs_tnc_get_bu_keys()
1549 lnum = znode->zbranch[n].lnum; in ubifs_tnc_get_bu_keys()
1550 offs = ALIGN(znode->zbranch[n].offs + len, 8); in ubifs_tnc_get_bu_keys()
1554 union ubifs_key *key; in ubifs_tnc_get_bu_keys() local
1557 /* Find next key */ in ubifs_tnc_get_bu_keys()
1561 zbr = &znode->zbranch[n]; in ubifs_tnc_get_bu_keys()
1562 key = &zbr->key; in ubifs_tnc_get_bu_keys()
1563 /* See if there is another data key for this file */ in ubifs_tnc_get_bu_keys()
1564 if (key_inum(c, key) != key_inum(c, &bu->key) || in ubifs_tnc_get_bu_keys()
1565 key_type(c, key) != UBIFS_DATA_KEY) { in ubifs_tnc_get_bu_keys()
1566 err = -ENOENT; in ubifs_tnc_get_bu_keys()
1570 /* First key found */ in ubifs_tnc_get_bu_keys()
1571 lnum = zbr->lnum; in ubifs_tnc_get_bu_keys()
1572 offs = ALIGN(zbr->offs + zbr->len, 8); in ubifs_tnc_get_bu_keys()
1573 len = zbr->len; in ubifs_tnc_get_bu_keys()
1574 if (len > bu->buf_len) { in ubifs_tnc_get_bu_keys()
1575 err = -EINVAL; in ubifs_tnc_get_bu_keys()
1583 if (zbr->lnum != lnum || zbr->offs != offs) in ubifs_tnc_get_bu_keys()
1585 offs += ALIGN(zbr->len, 8); in ubifs_tnc_get_bu_keys()
1586 len = ALIGN(len, 8) + zbr->len; in ubifs_tnc_get_bu_keys()
1588 if (len > bu->buf_len) in ubifs_tnc_get_bu_keys()
1592 next_block = key_block(c, key); in ubifs_tnc_get_bu_keys()
1593 bu->blk_cnt += (next_block - block - 1); in ubifs_tnc_get_bu_keys()
1594 if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1597 /* Add this key */ in ubifs_tnc_get_bu_keys()
1598 bu->zbranch[bu->cnt++] = *zbr; in ubifs_tnc_get_bu_keys()
1599 bu->blk_cnt += 1; in ubifs_tnc_get_bu_keys()
1601 if (bu->cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1603 if (bu->blk_cnt >= UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1607 if (err == -ENOENT) { in ubifs_tnc_get_bu_keys()
1608 bu->eof = 1; in ubifs_tnc_get_bu_keys()
1611 bu->gc_seq = c->gc_seq; in ubifs_tnc_get_bu_keys()
1612 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_get_bu_keys()
1616 * An enormous hole could cause bulk-read to encompass too many in ubifs_tnc_get_bu_keys()
1619 if (bu->blk_cnt > UBIFS_MAX_BULK_READ) in ubifs_tnc_get_bu_keys()
1620 bu->blk_cnt = UBIFS_MAX_BULK_READ; in ubifs_tnc_get_bu_keys()
1622 * Ensure that bulk-read covers a whole number of page cache in ubifs_tnc_get_bu_keys()
1626 !(bu->blk_cnt & (UBIFS_BLOCKS_PER_PAGE - 1))) in ubifs_tnc_get_bu_keys()
1628 if (bu->eof) { in ubifs_tnc_get_bu_keys()
1630 bu->blk_cnt += UBIFS_BLOCKS_PER_PAGE - 1; in ubifs_tnc_get_bu_keys()
1634 block = key_block(c, &bu->key) + bu->blk_cnt; in ubifs_tnc_get_bu_keys()
1635 block &= ~(UBIFS_BLOCKS_PER_PAGE - 1); in ubifs_tnc_get_bu_keys()
1636 while (bu->cnt) { in ubifs_tnc_get_bu_keys()
1637 if (key_block(c, &bu->zbranch[bu->cnt - 1].key) < block) in ubifs_tnc_get_bu_keys()
1639 bu->cnt -= 1; in ubifs_tnc_get_bu_keys()
1645 * read_wbuf - bulk-read from a LEB with a wbuf.
1652 * This functions returns %0 on success or a negative error code on failure.
1657 const struct ubifs_info *c = wbuf->c; in read_wbuf()
1661 ubifs_assert(c, wbuf && lnum >= 0 && lnum < c->leb_cnt && offs >= 0); in read_wbuf()
1662 ubifs_assert(c, !(offs & 7) && offs < c->leb_size); in read_wbuf()
1663 ubifs_assert(c, offs + len <= c->leb_size); in read_wbuf()
1665 spin_lock(&wbuf->lock); in read_wbuf()
1666 overlap = (lnum == wbuf->lnum && offs + len > wbuf->offs); in read_wbuf()
1668 /* We may safely unlock the write-buffer and read the data */ in read_wbuf()
1669 spin_unlock(&wbuf->lock); in read_wbuf()
1674 rlen = wbuf->offs - offs; in read_wbuf()
1678 /* Copy the rest from the write-buffer */ in read_wbuf()
1679 memcpy(buf + rlen, wbuf->buf + offs + rlen - wbuf->offs, len - rlen); in read_wbuf()
1680 spin_unlock(&wbuf->lock); in read_wbuf()
1683 /* Read everything that goes before write-buffer */ in read_wbuf()
1690 * validate_data_node - validate data nodes for bulk-read.
1691 * @c: UBIFS file-system description object
1695 * This functions returns %0 on success or a negative error code on failure.
1704 if (ch->node_type != UBIFS_DATA_NODE) { in validate_data_node()
1706 ch->node_type, UBIFS_DATA_NODE); in validate_data_node()
1710 err = ubifs_check_node(c, buf, zbr->lnum, zbr->offs, 0, 0); in validate_data_node()
1716 len = le32_to_cpu(ch->len); in validate_data_node()
1717 if (len != zbr->len) { in validate_data_node()
1718 ubifs_err(c, "bad node length %d, expected %d", len, zbr->len); in validate_data_node()
1722 /* Make sure the key of the read node is correct */ in validate_data_node()
1724 if (!keys_eq(c, &zbr->key, &key1)) { in validate_data_node()
1725 ubifs_err(c, "bad key in node at LEB %d:%d", in validate_data_node()
1726 zbr->lnum, zbr->offs); in validate_data_node()
1727 dbg_tnck(&zbr->key, "looked for key "); in validate_data_node()
1728 dbg_tnck(&key1, "found node's key "); in validate_data_node()
1735 err = -EINVAL; in validate_data_node()
1737 ubifs_err(c, "bad node at LEB %d:%d", zbr->lnum, zbr->offs); in validate_data_node()
1744 * ubifs_tnc_bulk_read - read a number of data nodes in one go.
1745 * @c: UBIFS file-system description object
1746 * @bu: bulk-read parameters and results
1750 * -EAGAIN to indicate a race with GC, or another negative error code on
1755 int lnum = bu->zbranch[0].lnum, offs = bu->zbranch[0].offs, len, err, i; in ubifs_tnc_bulk_read()
1759 len = bu->zbranch[bu->cnt - 1].offs; in ubifs_tnc_bulk_read()
1760 len += bu->zbranch[bu->cnt - 1].len - offs; in ubifs_tnc_bulk_read()
1761 if (len > bu->buf_len) { in ubifs_tnc_bulk_read()
1762 ubifs_err(c, "buffer too small %d vs %d", bu->buf_len, len); in ubifs_tnc_bulk_read()
1763 return -EINVAL; in ubifs_tnc_bulk_read()
1769 err = read_wbuf(wbuf, bu->buf, len, lnum, offs); in ubifs_tnc_bulk_read()
1771 err = ubifs_leb_read(c, lnum, bu->buf, offs, len, 0); in ubifs_tnc_bulk_read()
1774 if (maybe_leb_gced(c, lnum, bu->gc_seq)) in ubifs_tnc_bulk_read()
1775 return -EAGAIN; in ubifs_tnc_bulk_read()
1777 if (err && err != -EBADMSG) { in ubifs_tnc_bulk_read()
1781 dbg_tnck(&bu->key, "key "); in ubifs_tnc_bulk_read()
1786 buf = bu->buf; in ubifs_tnc_bulk_read()
1787 for (i = 0; i < bu->cnt; i++) { in ubifs_tnc_bulk_read()
1788 err = validate_data_node(c, buf, &bu->zbranch[i]); in ubifs_tnc_bulk_read()
1791 buf = buf + ALIGN(bu->zbranch[i].len, 8); in ubifs_tnc_bulk_read()
1798 * do_lookup_nm- look up a "hashed" node.
1799 * @c: UBIFS file-system description object
1800 * @key: node key to lookup
1804 * This function looks up and reads a node which contains name hash in the key.
1806 * key, so we have to sequentially look to all of them until the needed one is
1807 * found. This function returns zero in case of success, %-ENOENT if the node
1808 * was not found, and a negative error code in case of failure.
1810 static int do_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, in do_lookup_nm() argument
1816 dbg_tnck(key, "key "); in do_lookup_nm()
1817 mutex_lock(&c->tnc_mutex); in do_lookup_nm()
1818 found = ubifs_lookup_level0(c, key, &znode, &n); in do_lookup_nm()
1820 err = -ENOENT; in do_lookup_nm()
1829 err = resolve_collision(c, key, &znode, &n, nm); in do_lookup_nm()
1834 err = -ENOENT; in do_lookup_nm()
1838 err = tnc_read_hashed_node(c, &znode->zbranch[n], node); in do_lookup_nm()
1841 mutex_unlock(&c->tnc_mutex); in do_lookup_nm()
1846 * ubifs_tnc_lookup_nm - look up a "hashed" node.
1847 * @c: UBIFS file-system description object
1848 * @key: node key to lookup
1852 * This function looks up and reads a node which contains name hash in the key.
1854 * key, so we have to sequentially look to all of them until the needed one is
1855 * found. This function returns zero in case of success, %-ENOENT if the node
1856 * was not found, and a negative error code in case of failure.
1858 int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_lookup_nm() argument
1868 err = ubifs_tnc_lookup(c, key, node); in ubifs_tnc_lookup_nm()
1872 len = le16_to_cpu(dent->nlen); in ubifs_tnc_lookup_nm()
1873 if (fname_len(nm) == len && !memcmp(dent->name, fname_name(nm), len)) in ubifs_tnc_lookup_nm()
1881 return do_lookup_nm(c, key, node, nm); in ubifs_tnc_lookup_nm()
1884 static int search_dh_cookie(struct ubifs_info *c, const union ubifs_key *key, in search_dh_cookie() argument
1900 zbr = &znode->zbranch[*n]; in search_dh_cookie()
1901 dkey = &zbr->key; in search_dh_cookie()
1903 if (key_inum(c, dkey) != key_inum(c, key) || in search_dh_cookie()
1904 key_type(c, dkey) != key_type(c, key)) { in search_dh_cookie()
1905 return -ENOENT; in search_dh_cookie()
1912 if (key_hash(c, key) == key_hash(c, dkey) && in search_dh_cookie()
1913 le32_to_cpu(dent->cookie) == cookie) { in search_dh_cookie()
1924 static int do_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, in do_lookup_dh() argument
1931 ubifs_assert(c, is_hash_key(c, key)); in do_lookup_dh()
1933 lowest_dent_key(c, &start_key, key_inum(c, key)); in do_lookup_dh()
1935 mutex_lock(&c->tnc_mutex); in do_lookup_dh()
1940 err = search_dh_cookie(c, key, dent, cookie, &znode, &n, err); in do_lookup_dh()
1943 mutex_unlock(&c->tnc_mutex); in do_lookup_dh()
1948 * ubifs_tnc_lookup_dh - look up a "double hashed" node.
1949 * @c: UBIFS file-system description object
1950 * @key: node key to lookup
1954 * This function looks up and reads a node which contains name hash in the key.
1956 * key, so we have to sequentially look to all of them until the needed one
1958 * This function returns zero in case of success, %-ENOENT if the node
1959 * was not found, and a negative error code in case of failure.
1961 int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_lookup_dh() argument
1967 if (!c->double_hash) in ubifs_tnc_lookup_dh()
1968 return -EOPNOTSUPP; in ubifs_tnc_lookup_dh()
1974 err = ubifs_tnc_lookup(c, key, node); in ubifs_tnc_lookup_dh()
1978 if (le32_to_cpu(dent->cookie) == cookie) in ubifs_tnc_lookup_dh()
1985 return do_lookup_dh(c, key, node, cookie); in ubifs_tnc_lookup_dh()
1989 * correct_parent_keys - correct parent znodes' keys.
1990 * @c: UBIFS file-system description object
1993 * This is a helper function for 'tnc_insert()'. When the key of the leftmost
2000 union ubifs_key *key, *key1; in correct_parent_keys() local
2002 ubifs_assert(c, znode->parent); in correct_parent_keys()
2003 ubifs_assert(c, znode->iip == 0); in correct_parent_keys()
2005 key = &znode->zbranch[0].key; in correct_parent_keys()
2006 key1 = &znode->parent->zbranch[0].key; in correct_parent_keys()
2008 while (keys_cmp(c, key, key1) < 0) { in correct_parent_keys()
2009 key_copy(c, key, key1); in correct_parent_keys()
2010 znode = znode->parent; in correct_parent_keys()
2011 znode->alt = 1; in correct_parent_keys()
2012 if (!znode->parent || znode->iip) in correct_parent_keys()
2014 key1 = &znode->parent->zbranch[0].key; in correct_parent_keys()
2019 * insert_zbranch - insert a zbranch into a znode.
2020 * @c: UBIFS file-system description object
2027 * zbranch has to be inserted to the @znode->zbranches[]' array at the @n-th
2037 if (znode->level) { in insert_zbranch()
2038 for (i = znode->child_cnt; i > n; i--) { in insert_zbranch()
2039 znode->zbranch[i] = znode->zbranch[i - 1]; in insert_zbranch()
2040 if (znode->zbranch[i].znode) in insert_zbranch()
2041 znode->zbranch[i].znode->iip = i; in insert_zbranch()
2043 if (zbr->znode) in insert_zbranch()
2044 zbr->znode->iip = n; in insert_zbranch()
2046 for (i = znode->child_cnt; i > n; i--) in insert_zbranch()
2047 znode->zbranch[i] = znode->zbranch[i - 1]; in insert_zbranch()
2049 znode->zbranch[n] = *zbr; in insert_zbranch()
2050 znode->child_cnt += 1; in insert_zbranch()
2053 * After inserting at slot zero, the lower bound of the key range of in insert_zbranch()
2055 * then the upper bound of the key range may change, and furthermore in insert_zbranch()
2058 * TNC using the key from the index node on flash. That is bad because in insert_zbranch()
2067 znode->alt = 1; in insert_zbranch()
2071 * tnc_insert - insert a node into TNC.
2072 * @c: UBIFS file-system description object
2080 * error code in case of failure.
2087 union ubifs_key *key = &zbr->key, *key1; in tnc_insert() local
2089 ubifs_assert(c, n >= 0 && n <= c->fanout); in tnc_insert()
2093 zp = znode->parent; in tnc_insert()
2094 if (znode->child_cnt < c->fanout) { in tnc_insert()
2095 ubifs_assert(c, n != c->fanout); in tnc_insert()
2096 dbg_tnck(key, "inserted at %d level %d, key ", n, znode->level); in tnc_insert()
2100 /* Ensure parent's key is correct */ in tnc_insert()
2101 if (n == 0 && zp && znode->iip == 0) in tnc_insert()
2111 dbg_tnck(key, "splitting level %d, key ", znode->level); in tnc_insert()
2113 if (znode->alt) in tnc_insert()
2115 * We can no longer be sure of finding this znode by key, so we in tnc_insert()
2120 zn = kzalloc(c->max_znode_sz, GFP_NOFS); in tnc_insert()
2122 return -ENOMEM; in tnc_insert()
2123 zn->parent = zp; in tnc_insert()
2124 zn->level = znode->level; in tnc_insert()
2127 if (znode->level == 0 && key_type(c, key) == UBIFS_DATA_KEY) { in tnc_insert()
2129 if (n == c->fanout) { in tnc_insert()
2130 key1 = &znode->zbranch[n - 1].key; in tnc_insert()
2131 if (key_inum(c, key1) == key_inum(c, key) && in tnc_insert()
2136 } else if (appending && n != c->fanout) { in tnc_insert()
2140 if (n >= (c->fanout + 1) / 2) { in tnc_insert()
2141 key1 = &znode->zbranch[0].key; in tnc_insert()
2142 if (key_inum(c, key1) == key_inum(c, key) && in tnc_insert()
2144 key1 = &znode->zbranch[n].key; in tnc_insert()
2145 if (key_inum(c, key1) != key_inum(c, key) || in tnc_insert()
2148 move = c->fanout - keep; in tnc_insert()
2157 keep = c->fanout; in tnc_insert()
2160 keep = (c->fanout + 1) / 2; in tnc_insert()
2161 move = c->fanout - keep; in tnc_insert()
2173 keep -= 1; in tnc_insert()
2177 n -= keep; in tnc_insert()
2178 /* Re-parent */ in tnc_insert()
2179 if (zn->level != 0) in tnc_insert()
2180 zbr->znode->parent = zn; in tnc_insert()
2185 __set_bit(DIRTY_ZNODE, &zn->flags); in tnc_insert()
2186 atomic_long_inc(&c->dirty_zn_cnt); in tnc_insert()
2188 zn->child_cnt = move; in tnc_insert()
2189 znode->child_cnt = keep; in tnc_insert()
2195 zn->zbranch[i] = znode->zbranch[keep + i]; in tnc_insert()
2196 /* Re-parent */ in tnc_insert()
2197 if (zn->level != 0) in tnc_insert()
2198 if (zn->zbranch[i].znode) { in tnc_insert()
2199 zn->zbranch[i].znode->parent = zn; in tnc_insert()
2200 zn->zbranch[i].znode->iip = i; in tnc_insert()
2204 /* Insert new key and branch */ in tnc_insert()
2205 dbg_tnck(key, "inserting at %d level %d, key ", n, zn->level); in tnc_insert()
2211 if (n == 0 && zi == znode && znode->iip == 0) in tnc_insert()
2215 n = znode->iip + 1; in tnc_insert()
2218 zbr->key = zn->zbranch[0].key; in tnc_insert()
2219 zbr->znode = zn; in tnc_insert()
2220 zbr->lnum = 0; in tnc_insert()
2221 zbr->offs = 0; in tnc_insert()
2222 zbr->len = 0; in tnc_insert()
2229 dbg_tnc("creating new zroot at level %d", znode->level + 1); in tnc_insert()
2231 zi = kzalloc(c->max_znode_sz, GFP_NOFS); in tnc_insert()
2233 return -ENOMEM; in tnc_insert()
2235 zi->child_cnt = 2; in tnc_insert()
2236 zi->level = znode->level + 1; in tnc_insert()
2238 __set_bit(DIRTY_ZNODE, &zi->flags); in tnc_insert()
2239 atomic_long_inc(&c->dirty_zn_cnt); in tnc_insert()
2241 zi->zbranch[0].key = znode->zbranch[0].key; in tnc_insert()
2242 zi->zbranch[0].znode = znode; in tnc_insert()
2243 zi->zbranch[0].lnum = c->zroot.lnum; in tnc_insert()
2244 zi->zbranch[0].offs = c->zroot.offs; in tnc_insert()
2245 zi->zbranch[0].len = c->zroot.len; in tnc_insert()
2246 zi->zbranch[1].key = zn->zbranch[0].key; in tnc_insert()
2247 zi->zbranch[1].znode = zn; in tnc_insert()
2249 c->zroot.lnum = 0; in tnc_insert()
2250 c->zroot.offs = 0; in tnc_insert()
2251 c->zroot.len = 0; in tnc_insert()
2252 c->zroot.znode = zi; in tnc_insert()
2254 zn->parent = zi; in tnc_insert()
2255 zn->iip = 1; in tnc_insert()
2256 znode->parent = zi; in tnc_insert()
2257 znode->iip = 0; in tnc_insert()
2263 * ubifs_tnc_add - add a node to TNC.
2264 * @c: UBIFS file-system description object
2265 * @key: key to add
2270 * This function adds a node with key @key to TNC. The node may be new or it may
2271 * obsolete some existing one. Returns %0 on success or negative error code on
2274 int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum, in ubifs_tnc_add() argument
2280 mutex_lock(&c->tnc_mutex); in ubifs_tnc_add()
2281 dbg_tnck(key, "%d:%d, len %d, key ", lnum, offs, len); in ubifs_tnc_add()
2282 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()
2304 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add()
2310 * ubifs_tnc_replace - replace a node in the TNC only if the old node is found.
2311 * @c: UBIFS file-system description object
2312 * @key: key to add
2319 * This function replaces a node with key @key in the TNC only if the old node
2321 * Returns %0 on success or negative error code on failure.
2323 int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_replace() argument
2329 mutex_lock(&c->tnc_mutex); in ubifs_tnc_replace()
2330 dbg_tnck(key, "old LEB %d:%d, new LEB %d:%d, len %d, key ", old_lnum, in ubifs_tnc_replace()
2332 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_replace()
2339 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_replace()
2342 if (zbr->lnum == old_lnum && zbr->offs == old_offs) { in ubifs_tnc_replace()
2344 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_replace()
2347 zbr->lnum = lnum; in ubifs_tnc_replace()
2348 zbr->offs = offs; in ubifs_tnc_replace()
2349 zbr->len = len; in ubifs_tnc_replace()
2351 } else if (is_hash_key(c, key)) { in ubifs_tnc_replace()
2352 found = resolve_collision_directly(c, key, &znode, &n, in ubifs_tnc_replace()
2363 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_replace()
2370 zbr = &znode->zbranch[n]; in ubifs_tnc_replace()
2372 err = ubifs_add_dirt(c, zbr->lnum, in ubifs_tnc_replace()
2373 zbr->len); in ubifs_tnc_replace()
2376 zbr->lnum = lnum; in ubifs_tnc_replace()
2377 zbr->offs = offs; in ubifs_tnc_replace()
2378 zbr->len = len; in ubifs_tnc_replace()
2390 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_replace()
2395 * ubifs_tnc_add_nm - add a "hashed" node to TNC.
2396 * @c: UBIFS file-system description object
2397 * @key: key to add
2406 int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_add_nm() argument
2413 mutex_lock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2414 dbg_tnck(key, "LEB %d:%d, key ", lnum, offs); in ubifs_tnc_add_nm()
2415 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_add_nm()
2422 if (c->replaying) in ubifs_tnc_add_nm()
2423 found = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_add_nm()
2426 found = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_add_nm()
2434 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_add_nm()
2443 struct ubifs_zbranch *zbr = &znode->zbranch[n]; in ubifs_tnc_add_nm()
2446 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in ubifs_tnc_add_nm()
2447 zbr->lnum = lnum; in ubifs_tnc_add_nm()
2448 zbr->offs = offs; in ubifs_tnc_add_nm()
2449 zbr->len = len; in ubifs_tnc_add_nm()
2461 key_copy(c, key, &zbr.key); in ubifs_tnc_add_nm()
2465 if (c->replaying) { in ubifs_tnc_add_nm()
2469 * by passing 'ubifs_tnc_remove_nm()' the same key but in ubifs_tnc_add_nm()
2475 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2478 return ubifs_tnc_remove_nm(c, key, &noname); in ubifs_tnc_add_nm()
2485 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_add_nm()
2490 * tnc_delete - delete a znode form TNC.
2491 * @c: UBIFS file-system description object
2495 * This function deletes a leaf node from @n-th slot of @znode. Returns zero in
2496 * case of success and a negative error code in case of failure.
2505 ubifs_assert(c, znode->level == 0); in tnc_delete()
2506 ubifs_assert(c, n >= 0 && n < c->fanout); in tnc_delete()
2507 dbg_tnck(&znode->zbranch[n].key, "deleting key "); in tnc_delete()
2509 zbr = &znode->zbranch[n]; in tnc_delete()
2512 err = ubifs_add_dirt(c, zbr->lnum, zbr->len); in tnc_delete()
2519 for (i = n; i < znode->child_cnt - 1; i++) in tnc_delete()
2520 znode->zbranch[i] = znode->zbranch[i + 1]; in tnc_delete()
2521 znode->child_cnt -= 1; in tnc_delete()
2523 if (znode->child_cnt > 0) in tnc_delete()
2535 zp = znode->parent; in tnc_delete()
2536 n = znode->iip; in tnc_delete()
2538 atomic_long_dec(&c->dirty_zn_cnt); in tnc_delete()
2544 if (znode->cnext) { in tnc_delete()
2545 __set_bit(OBSOLETE_ZNODE, &znode->flags); in tnc_delete()
2546 atomic_long_inc(&c->clean_zn_cnt); in tnc_delete()
2551 } while (znode->child_cnt == 1); /* while removing last child */ in tnc_delete()
2553 /* Remove from znode, entry n - 1 */ in tnc_delete()
2554 znode->child_cnt -= 1; in tnc_delete()
2555 ubifs_assert(c, znode->level != 0); in tnc_delete()
2556 for (i = n; i < znode->child_cnt; i++) { in tnc_delete()
2557 znode->zbranch[i] = znode->zbranch[i + 1]; in tnc_delete()
2558 if (znode->zbranch[i].znode) in tnc_delete()
2559 znode->zbranch[i].znode->iip = i; in tnc_delete()
2566 if (!znode->parent) { in tnc_delete()
2567 while (znode->child_cnt == 1 && znode->level != 0) { in tnc_delete()
2569 zbr = &znode->zbranch[0]; in tnc_delete()
2576 znode->parent = NULL; in tnc_delete()
2577 znode->iip = 0; in tnc_delete()
2578 if (c->zroot.len) { in tnc_delete()
2579 err = insert_old_idx(c, c->zroot.lnum, in tnc_delete()
2580 c->zroot.offs); in tnc_delete()
2584 c->zroot.lnum = zbr->lnum; in tnc_delete()
2585 c->zroot.offs = zbr->offs; in tnc_delete()
2586 c->zroot.len = zbr->len; in tnc_delete()
2587 c->zroot.znode = znode; in tnc_delete()
2590 atomic_long_dec(&c->dirty_zn_cnt); in tnc_delete()
2592 if (zp->cnext) { in tnc_delete()
2593 __set_bit(OBSOLETE_ZNODE, &zp->flags); in tnc_delete()
2594 atomic_long_inc(&c->clean_zn_cnt); in tnc_delete()
2605 * ubifs_tnc_remove - remove an index entry of a node.
2606 * @c: UBIFS file-system description object
2607 * @key: key of node
2609 * Returns %0 on success or negative error code on failure.
2611 int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key) in ubifs_tnc_remove() argument
2616 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove()
2617 dbg_tnck(key, "key "); in ubifs_tnc_remove()
2618 found = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove()
2629 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove()
2634 * ubifs_tnc_remove_nm - remove an index entry for a "hashed" node.
2635 * @c: UBIFS file-system description object
2636 * @key: key of node
2639 * Returns %0 on success or negative error code on failure.
2641 int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_remove_nm() argument
2647 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_nm()
2648 dbg_tnck(key, "key "); in ubifs_tnc_remove_nm()
2649 err = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove_nm()
2654 if (c->replaying) in ubifs_tnc_remove_nm()
2655 err = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_remove_nm()
2658 err = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_remove_nm()
2664 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_nm()
2678 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_nm()
2683 * ubifs_tnc_remove_dh - remove an index entry for a "double hashed" node.
2684 * @c: UBIFS file-system description object
2685 * @key: key of node
2688 * Returns %0 on success or negative error code on failure.
2690 int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key, in ubifs_tnc_remove_dh() argument
2698 if (!c->double_hash) in ubifs_tnc_remove_dh()
2699 return -EOPNOTSUPP; in ubifs_tnc_remove_dh()
2701 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_dh()
2702 err = lookup_level0_dirty(c, key, &znode, &n); in ubifs_tnc_remove_dh()
2706 zbr = &znode->zbranch[n]; in ubifs_tnc_remove_dh()
2709 err = -ENOMEM; in ubifs_tnc_remove_dh()
2718 if (le32_to_cpu(dent->cookie) != cookie) { in ubifs_tnc_remove_dh()
2721 lowest_dent_key(c, &start_key, key_inum(c, key)); in ubifs_tnc_remove_dh()
2727 err = search_dh_cookie(c, key, dent, cookie, &znode, &n, err); in ubifs_tnc_remove_dh()
2732 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_dh()
2746 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_dh()
2751 * key_in_range - determine if a key falls within a range of keys.
2752 * @c: UBIFS file-system description object
2753 * @key: key to check
2754 * @from_key: lowest key in range
2755 * @to_key: highest key in range
2757 * This function returns %1 if the key is in range and %0 otherwise.
2759 static int key_in_range(struct ubifs_info *c, union ubifs_key *key, in key_in_range() argument
2762 if (keys_cmp(c, key, from_key) < 0) in key_in_range()
2764 if (keys_cmp(c, key, to_key) > 0) in key_in_range()
2770 * ubifs_tnc_remove_range - remove index entries in range.
2771 * @c: UBIFS file-system description object
2772 * @from_key: lowest key to remove
2773 * @to_key: highest key to remove
2777 * code in case of failure.
2784 union ubifs_key *key; in ubifs_tnc_remove_range() local
2786 mutex_lock(&c->tnc_mutex); in ubifs_tnc_remove_range()
2794 key = from_key; in ubifs_tnc_remove_range()
2797 if (err == -ENOENT) { in ubifs_tnc_remove_range()
2803 key = &znode->zbranch[n].key; in ubifs_tnc_remove_range()
2804 if (!key_in_range(c, key, from_key, to_key)) { in ubifs_tnc_remove_range()
2811 if (znode->cnext || !ubifs_zn_dirty(znode)) { in ubifs_tnc_remove_range()
2820 for (i = n + 1, k = 0; i < znode->child_cnt; i++, k++) { in ubifs_tnc_remove_range()
2821 key = &znode->zbranch[i].key; in ubifs_tnc_remove_range()
2822 if (!key_in_range(c, key, from_key, to_key)) in ubifs_tnc_remove_range()
2824 lnc_free(&znode->zbranch[i]); in ubifs_tnc_remove_range()
2825 err = ubifs_add_dirt(c, znode->zbranch[i].lnum, in ubifs_tnc_remove_range()
2826 znode->zbranch[i].len); in ubifs_tnc_remove_range()
2831 dbg_tnck(key, "removing key "); in ubifs_tnc_remove_range()
2834 for (i = n + 1 + k; i < znode->child_cnt; i++) in ubifs_tnc_remove_range()
2835 znode->zbranch[i - k] = znode->zbranch[i]; in ubifs_tnc_remove_range()
2836 znode->child_cnt -= k; in ubifs_tnc_remove_range()
2848 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_remove_range()
2853 * ubifs_tnc_remove_ino - remove an inode from TNC.
2854 * @c: UBIFS file-system description object
2859 * error code in case of failure.
2881 if (err == -ENOENT) in ubifs_tnc_remove_ino()
2886 xattr_inum = le64_to_cpu(xent->inum); in ubifs_tnc_remove_ino()
2887 dbg_tnc("xent '%s', ino %lu", xent->name, in ubifs_tnc_remove_ino()
2892 fname_name(&nm) = xent->name; in ubifs_tnc_remove_ino()
2893 fname_len(&nm) = le16_to_cpu(xent->nlen); in ubifs_tnc_remove_ino()
2910 key_read(c, &xent->key, &key1); in ubifs_tnc_remove_ino()
2921 * ubifs_tnc_next_ent - walk directory or extended attribute entries.
2922 * @c: UBIFS file-system description object
2923 * @key: key of last entry
2927 * after the given key (@key) if there is one. @nm is used to resolve
2930 * If the name of the current entry is not known and only the key is known,
2931 * @nm->name has to be %NULL. In this case the semantics of this function is a
2932 * little bit different and it returns the entry corresponding to this key, not
2933 * the next one. If the key was not found, the closest "right" entry is
2936 * If the fist entry has to be found, @key has to contain the lowest possible
2937 * key value for this inode and @name has to be %NULL.
2940 * in case of success, %-ENOENT is returned if no entry was found, and a
2941 * negative error code is returned in case of failure.
2944 union ubifs_key *key, in ubifs_tnc_next_ent() argument
2947 int n, err, type = key_type(c, key); in ubifs_tnc_next_ent()
2953 dbg_tnck(key, "key "); in ubifs_tnc_next_ent()
2954 ubifs_assert(c, is_hash_key(c, key)); in ubifs_tnc_next_ent()
2956 mutex_lock(&c->tnc_mutex); in ubifs_tnc_next_ent()
2957 err = ubifs_lookup_level0(c, key, &znode, &n); in ubifs_tnc_next_ent()
2964 if (c->replaying) in ubifs_tnc_next_ent()
2965 err = fallible_resolve_collision(c, key, &znode, &n, in ubifs_tnc_next_ent()
2968 err = resolve_collision(c, key, &znode, &n, nm); in ubifs_tnc_next_ent()
2987 * However, the given key does not exist in the TNC in ubifs_tnc_next_ent()
2997 zbr = &znode->zbranch[n]; in ubifs_tnc_next_ent()
2998 dent = kmalloc(zbr->len, GFP_NOFS); in ubifs_tnc_next_ent()
3000 err = -ENOMEM; in ubifs_tnc_next_ent()
3008 dkey = &zbr->key; in ubifs_tnc_next_ent()
3009 if (key_inum(c, dkey) != key_inum(c, key) || in ubifs_tnc_next_ent()
3011 err = -ENOENT; in ubifs_tnc_next_ent()
3019 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_next_ent()
3025 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_next_ent()
3030 * tnc_destroy_cnext - destroy left-over obsolete znodes from a failed commit.
3031 * @c: UBIFS file-system description object
3033 * Destroy left-over obsolete znodes from a failed commit.
3039 if (!c->cnext) in tnc_destroy_cnext()
3041 ubifs_assert(c, c->cmt_state == COMMIT_BROKEN); in tnc_destroy_cnext()
3042 cnext = c->cnext; in tnc_destroy_cnext()
3046 cnext = cnext->cnext; in tnc_destroy_cnext()
3049 } while (cnext && cnext != c->cnext); in tnc_destroy_cnext()
3053 * ubifs_tnc_close - close TNC subsystem and free all related resources.
3054 * @c: UBIFS file-system description object
3059 if (c->zroot.znode) { in ubifs_tnc_close()
3062 n = atomic_long_read(&c->clean_zn_cnt); in ubifs_tnc_close()
3063 freed = ubifs_destroy_tnc_subtree(c, c->zroot.znode); in ubifs_tnc_close()
3067 kfree(c->gap_lebs); in ubifs_tnc_close()
3068 kfree(c->ilebs); in ubifs_tnc_close()
3073 * left_znode - get the znode to the left.
3074 * @c: UBIFS file-system description object
3078 * there is not one. A negative error code is returned on failure.
3083 int level = znode->level; in left_znode()
3086 int n = znode->iip - 1; in left_znode()
3089 znode = znode->parent; in left_znode()
3097 while (znode->level != level) { in left_znode()
3098 n = znode->child_cnt - 1; in left_znode()
3110 * right_znode - get the znode to the right.
3111 * @c: UBIFS file-system description object
3115 * if there is not one. A negative error code is returned on failure.
3120 int level = znode->level; in right_znode()
3123 int n = znode->iip + 1; in right_znode()
3126 znode = znode->parent; in right_znode()
3129 if (n < znode->child_cnt) { in right_znode()
3134 while (znode->level != level) { in right_znode()
3146 * lookup_znode - find a particular indexing node from TNC.
3147 * @c: UBIFS file-system description object
3148 * @key: index node key to lookup
3153 * This function searches an indexing node by its first key @key and its
3156 * were found on the media by scanning, for example when garbage-collecting or
3157 * when doing in-the-gaps commit. This means that the indexing node which is
3158 * looked for does not have to have exactly the same leftmost key @key, because
3159 * the leftmost key may have been changed, in which case TNC will contain a
3164 * not find it. For situations like this UBIFS has the old index RB-tree
3168 * found. A negative error code is returned on failure.
3171 union ubifs_key *key, int level, in lookup_znode() argument
3177 ubifs_assert(c, key_type(c, key) < UBIFS_INVALID_KEY); in lookup_znode()
3184 return ERR_PTR(-EINVAL); in lookup_znode()
3187 znode = c->zroot.znode; in lookup_znode()
3189 znode = ubifs_load_znode(c, &c->zroot, NULL, 0); in lookup_znode()
3194 if (c->zroot.lnum == lnum && c->zroot.offs == offs) in lookup_znode()
3197 if (level >= znode->level) in lookup_znode()
3200 ubifs_search_zbranch(c, znode, key, &n); in lookup_znode()
3203 * We reached a znode where the leftmost key is greater in lookup_znode()
3204 * than the key we are searching for. This is the same in lookup_znode()
3215 ubifs_search_zbranch(c, znode, key, &n); in lookup_znode()
3218 if (znode->level == level + 1) in lookup_znode()
3225 if (znode->zbranch[n].lnum == lnum && znode->zbranch[n].offs == offs) in lookup_znode()
3227 /* If the key is unique, there is nowhere else to look */ in lookup_znode()
3228 if (!is_hash_key(c, key)) in lookup_znode()
3231 * The key is not unique and so may be also in the znodes to either in lookup_znode()
3240 n -= 1; in lookup_znode()
3247 n = znode->child_cnt - 1; in lookup_znode()
3250 if (znode->zbranch[n].lnum == lnum && in lookup_znode()
3251 znode->zbranch[n].offs == offs) in lookup_znode()
3253 /* Stop if the key is less than the one we are looking for */ in lookup_znode()
3254 if (keys_cmp(c, &znode->zbranch[n].key, key) < 0) in lookup_znode()
3263 if (++n >= znode->child_cnt) { in lookup_znode()
3272 if (znode->zbranch[n].lnum == lnum && in lookup_znode()
3273 znode->zbranch[n].offs == offs) in lookup_znode()
3275 /* Stop if the key is greater than the one we are looking for */ in lookup_znode()
3276 if (keys_cmp(c, &znode->zbranch[n].key, key) > 0) in lookup_znode()
3283 * is_idx_node_in_tnc - determine if an index node is in the TNC.
3284 * @c: UBIFS file-system description object
3285 * @key: key of index node
3293 * znode is clean, and a negative error code in case of failure.
3295 * Note, the @key argument has to be the key of the first child. Also note,
3297 * offset for a main-area node.
3299 int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, in is_idx_node_in_tnc() argument
3304 znode = lookup_znode(c, key, level, lnum, offs); in is_idx_node_in_tnc()
3314 * is_leaf_node_in_tnc - determine if a non-indexing not is in the TNC.
3315 * @c: UBIFS file-system description object
3316 * @key: node key
3321 * not, and a negative error code in case of failure.
3324 * and offset for a main-area node.
3326 static int is_leaf_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, in is_leaf_node_in_tnc() argument
3332 const int unique = !is_hash_key(c, key); in is_leaf_node_in_tnc()
3334 found = ubifs_lookup_level0(c, key, &znode, &n); in is_leaf_node_in_tnc()
3336 return found; /* Error code */ in is_leaf_node_in_tnc()
3339 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3340 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3345 * Because the key is not unique, we have to look left in is_leaf_node_in_tnc()
3353 if (err == -ENOENT) in is_leaf_node_in_tnc()
3357 if (keys_cmp(c, key, &znode->zbranch[n].key)) in is_leaf_node_in_tnc()
3359 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3360 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3369 if (err == -ENOENT) in is_leaf_node_in_tnc()
3373 if (keys_cmp(c, key, &znode->zbranch[n].key)) in is_leaf_node_in_tnc()
3375 zbr = &znode->zbranch[n]; in is_leaf_node_in_tnc()
3376 if (lnum == zbr->lnum && offs == zbr->offs) in is_leaf_node_in_tnc()
3383 * ubifs_tnc_has_node - determine whether a node is in the TNC.
3384 * @c: UBIFS file-system description object
3385 * @key: node key
3389 * @is_idx: non-zero if the node is an index node
3392 * negative error code in case of failure. For index nodes, @key has to be the
3393 * key of the first child. An index node is considered to be in the TNC only if
3396 int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level, in ubifs_tnc_has_node() argument
3401 mutex_lock(&c->tnc_mutex); in ubifs_tnc_has_node()
3403 err = is_idx_node_in_tnc(c, key, level, lnum, offs); in ubifs_tnc_has_node()
3415 err = is_leaf_node_in_tnc(c, key, lnum, offs); in ubifs_tnc_has_node()
3418 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_has_node()
3423 * ubifs_dirty_idx_node - dirty an index node.
3424 * @c: UBIFS file-system description object
3425 * @key: index node key
3431 * collected. The @key argument has to be the key of the first child. This
3433 * for a main-area node. Returns %0 on success and a negative error code on
3436 int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level, in ubifs_dirty_idx_node() argument
3442 mutex_lock(&c->tnc_mutex); in ubifs_dirty_idx_node()
3443 znode = lookup_znode(c, key, level, lnum, offs); in ubifs_dirty_idx_node()
3457 mutex_unlock(&c->tnc_mutex); in ubifs_dirty_idx_node()
3462 * dbg_check_inode_size - check if inode size is correct.
3463 * @c: UBIFS file-system description object
3468 * not have any pages beyond @size. Returns zero if the inode is OK, %-EINVAL
3469 * if it has a data page beyond @size, and other negative error code in case of
3476 union ubifs_key from_key, to_key, *key; in dbg_check_inode_size() local
3480 if (!S_ISREG(inode->i_mode)) in dbg_check_inode_size()
3485 block = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT; in dbg_check_inode_size()
3486 data_key_init(c, &from_key, inode->i_ino, block); in dbg_check_inode_size()
3487 highest_data_key(c, &to_key, inode->i_ino); in dbg_check_inode_size()
3489 mutex_lock(&c->tnc_mutex); in dbg_check_inode_size()
3495 key = &from_key; in dbg_check_inode_size()
3500 if (err == -ENOENT) { in dbg_check_inode_size()
3508 key = &znode->zbranch[n].key; in dbg_check_inode_size()
3509 if (!key_in_range(c, key, &from_key, &to_key)) in dbg_check_inode_size()
3513 block = key_block(c, key); in dbg_check_inode_size()
3515 (unsigned long)inode->i_ino, size, in dbg_check_inode_size()
3517 mutex_unlock(&c->tnc_mutex); in dbg_check_inode_size()
3520 return -EINVAL; in dbg_check_inode_size()
3523 mutex_unlock(&c->tnc_mutex); in dbg_check_inode_size()