aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/befs/befs.h2
-rw-r--r--fs/befs/btree.c33
2 files changed, 16 insertions, 19 deletions
diff --git a/fs/befs/befs.h b/fs/befs/befs.h
index c5c6cd13709c..a8ca7fcf0795 100644
--- a/fs/befs/befs.h
+++ b/fs/befs/befs.h
@@ -79,7 +79,7 @@ enum befs_err {
79 BEFS_BT_END, 79 BEFS_BT_END,
80 BEFS_BT_EMPTY, 80 BEFS_BT_EMPTY,
81 BEFS_BT_MATCH, 81 BEFS_BT_MATCH,
82 BEFS_BT_PARMATCH, 82 BEFS_BT_OVERFLOW,
83 BEFS_BT_NOT_FOUND 83 BEFS_BT_NOT_FOUND
84}; 84};
85 85
diff --git a/fs/befs/btree.c b/fs/befs/btree.c
index 3f1a39166d89..5670d845b2ef 100644
--- a/fs/befs/btree.c
+++ b/fs/befs/btree.c
@@ -281,9 +281,9 @@ befs_btree_find(struct super_block *sb, const befs_data_stream *ds,
281 281
282 while (!befs_leafnode(this_node)) { 282 while (!befs_leafnode(this_node)) {
283 res = befs_find_key(sb, this_node, key, &node_off); 283 res = befs_find_key(sb, this_node, key, &node_off);
284 if (res == BEFS_BT_NOT_FOUND) 284 /* if no key set, try the overflow node */
285 if (res == BEFS_BT_OVERFLOW)
285 node_off = this_node->head.overflow; 286 node_off = this_node->head.overflow;
286 /* if no match, go to overflow node */
287 if (befs_bt_read_node(sb, ds, this_node, node_off) != BEFS_OK) { 287 if (befs_bt_read_node(sb, ds, this_node, node_off) != BEFS_OK) {
288 befs_error(sb, "befs_btree_find() failed to read " 288 befs_error(sb, "befs_btree_find() failed to read "
289 "node at %llu", node_off); 289 "node at %llu", node_off);
@@ -291,8 +291,7 @@ befs_btree_find(struct super_block *sb, const befs_data_stream *ds,
291 } 291 }
292 } 292 }
293 293
294 /* at the correct leaf node now */ 294 /* at a leaf node now, check if it is correct */
295
296 res = befs_find_key(sb, this_node, key, value); 295 res = befs_find_key(sb, this_node, key, value);
297 296
298 brelse(this_node->bh); 297 brelse(this_node->bh);
@@ -323,16 +322,12 @@ befs_btree_find(struct super_block *sb, const befs_data_stream *ds,
323 * @findkey: Keystring to search for 322 * @findkey: Keystring to search for
324 * @value: If key is found, the value stored with the key is put here 323 * @value: If key is found, the value stored with the key is put here
325 * 324 *
326 * finds exact match if one exists, and returns BEFS_BT_MATCH 325 * Finds exact match if one exists, and returns BEFS_BT_MATCH.
327 * If no exact match, finds first key in node that is greater 326 * If there is no match and node's value array is too small for key, return
328 * (alphabetically) than the search key and returns BEFS_BT_PARMATCH 327 * BEFS_BT_OVERFLOW.
329 * (for partial match, I guess). Can you think of something better to 328 * If no match and node should countain this key, return BEFS_BT_NOT_FOUND.
330 * call it?
331 *
332 * If no key was a match or greater than the search key, return
333 * BEFS_BT_NOT_FOUND.
334 * 329 *
335 * Use binary search instead of a linear. 330 * Uses binary search instead of a linear.
336 */ 331 */
337static int 332static int
338befs_find_key(struct super_block *sb, struct befs_btree_node *node, 333befs_find_key(struct super_block *sb, struct befs_btree_node *node,
@@ -355,9 +350,8 @@ befs_find_key(struct super_block *sb, struct befs_btree_node *node,
355 350
356 eq = befs_compare_strings(thiskey, keylen, findkey, findkey_len); 351 eq = befs_compare_strings(thiskey, keylen, findkey, findkey_len);
357 if (eq < 0) { 352 if (eq < 0) {
358 befs_error(sb, "<--- %s %s not found", __func__, findkey); 353 befs_debug(sb, "<--- node can't contain %s", findkey);
359 befs_debug(sb, "<--- %s ERROR", __func__); 354 return BEFS_BT_OVERFLOW;
360 return BEFS_BT_NOT_FOUND;
361 } 355 }
362 356
363 valarray = befs_bt_valarray(node); 357 valarray = befs_bt_valarray(node);
@@ -385,12 +379,15 @@ befs_find_key(struct super_block *sb, struct befs_btree_node *node,
385 else 379 else
386 first = mid + 1; 380 first = mid + 1;
387 } 381 }
382
383 /* return an existing value so caller can arrive to a leaf node */
388 if (eq < 0) 384 if (eq < 0)
389 *value = fs64_to_cpu(sb, valarray[mid + 1]); 385 *value = fs64_to_cpu(sb, valarray[mid + 1]);
390 else 386 else
391 *value = fs64_to_cpu(sb, valarray[mid]); 387 *value = fs64_to_cpu(sb, valarray[mid]);
392 befs_debug(sb, "<--- %s found %s at %d", __func__, thiskey, mid); 388 befs_error(sb, "<--- %s %s not found", __func__, findkey);
393 return BEFS_BT_PARMATCH; 389 befs_debug(sb, "<--- %s ERROR", __func__);
390 return BEFS_BT_NOT_FOUND;
394} 391}
395 392
396/** 393/**