@@ -85,7 +85,7 @@ struct befs_btree_node {
85
85
};
86
86
87
87
/* local constants */
88
- static const befs_off_t befs_bt_inval = 0xffffffffffffffffULL ;
88
+ static const befs_off_t BEFS_BT_INVAL = 0xffffffffffffffffULL ;
89
89
90
90
/* local functions */
91
91
static int befs_btree_seekleaf (struct super_block * sb , const befs_data_stream * ds ,
@@ -156,8 +156,6 @@ befs_bt_read_super(struct super_block *sb, const befs_data_stream *ds,
156
156
sup -> max_depth = fs32_to_cpu (sb , od_sup -> max_depth );
157
157
sup -> data_type = fs32_to_cpu (sb , od_sup -> data_type );
158
158
sup -> root_node_ptr = fs64_to_cpu (sb , od_sup -> root_node_ptr );
159
- sup -> free_node_ptr = fs64_to_cpu (sb , od_sup -> free_node_ptr );
160
- sup -> max_size = fs64_to_cpu (sb , od_sup -> max_size );
161
159
162
160
brelse (bh );
163
161
if (sup -> magic != BEFS_BTREE_MAGIC ) {
@@ -183,8 +181,8 @@ befs_bt_read_super(struct super_block *sb, const befs_data_stream *ds,
183
181
* Calls befs_read_datastream to read in the indicated btree node and
184
182
* makes sure its header fields are in cpu byteorder, byteswapping if
185
183
* necessary.
186
- * Note: node->bh must be NULL when this function called first
187
- * time. Don't forget brelse(node->bh) after last call.
184
+ * Note: node->bh must be NULL when this function is called the first time.
185
+ * Don't forget brelse(node->bh) after last call.
188
186
*
189
187
* On success, returns BEFS_OK and *@node contains the btree node that
190
188
* starts at @node_off, with the node->head fields in cpu byte order.
@@ -244,7 +242,7 @@ befs_bt_read_node(struct super_block *sb, const befs_data_stream *ds,
244
242
* Read the superblock and rootnode of the b+tree.
245
243
* Drill down through the interior nodes using befs_find_key().
246
244
* Once at the correct leaf node, use befs_find_key() again to get the
247
- * actuall value stored with the key.
245
+ * actual value stored with the key.
248
246
*/
249
247
int
250
248
befs_btree_find (struct super_block * sb , const befs_data_stream * ds ,
@@ -283,25 +281,25 @@ befs_btree_find(struct super_block *sb, const befs_data_stream *ds,
283
281
284
282
while (!befs_leafnode (this_node )) {
285
283
res = befs_find_key (sb , this_node , key , & node_off );
286
- if (res == BEFS_BT_NOT_FOUND )
284
+ /* if no key set, try the overflow node */
285
+ if (res == BEFS_BT_OVERFLOW )
287
286
node_off = this_node -> head .overflow ;
288
- /* if no match, go to overflow node */
289
287
if (befs_bt_read_node (sb , ds , this_node , node_off ) != BEFS_OK ) {
290
288
befs_error (sb , "befs_btree_find() failed to read "
291
289
"node at %llu" , node_off );
292
290
goto error_alloc ;
293
291
}
294
292
}
295
293
296
- /* at the correct leaf node now */
297
-
294
+ /* at a leaf node now, check if it is correct */
298
295
res = befs_find_key (sb , this_node , key , value );
299
296
300
297
brelse (this_node -> bh );
301
298
kfree (this_node );
302
299
303
300
if (res != BEFS_BT_MATCH ) {
304
- befs_debug (sb , "<--- %s Key %s not found" , __func__ , key );
301
+ befs_error (sb , "<--- %s Key %s not found" , __func__ , key );
302
+ befs_debug (sb , "<--- %s ERROR" , __func__ );
305
303
* value = 0 ;
306
304
return BEFS_BT_NOT_FOUND ;
307
305
}
@@ -324,16 +322,12 @@ befs_btree_find(struct super_block *sb, const befs_data_stream *ds,
324
322
* @findkey: Keystring to search for
325
323
* @value: If key is found, the value stored with the key is put here
326
324
*
327
- * finds exact match if one exists, and returns BEFS_BT_MATCH
328
- * If no exact match, finds first key in node that is greater
329
- * (alphabetically) than the search key and returns BEFS_BT_PARMATCH
330
- * (for partial match, I guess). Can you think of something better to
331
- * call it?
332
- *
333
- * If no key was a match or greater than the search key, return
334
- * BEFS_BT_NOT_FOUND.
325
+ * Finds exact match if one exists, and returns BEFS_BT_MATCH.
326
+ * If there is no match and node's value array is too small for key, return
327
+ * BEFS_BT_OVERFLOW.
328
+ * If no match and node should countain this key, return BEFS_BT_NOT_FOUND.
335
329
*
336
- * Use binary search instead of a linear.
330
+ * Uses binary search instead of a linear.
337
331
*/
338
332
static int
339
333
befs_find_key (struct super_block * sb , struct befs_btree_node * node ,
@@ -348,18 +342,16 @@ befs_find_key(struct super_block *sb, struct befs_btree_node *node,
348
342
349
343
befs_debug (sb , "---> %s %s" , __func__ , findkey );
350
344
351
- * value = 0 ;
352
-
353
345
findkey_len = strlen (findkey );
354
346
355
- /* if node can not contain key, just skeep this node */
347
+ /* if node can not contain key, just skip this node */
356
348
last = node -> head .all_key_count - 1 ;
357
349
thiskey = befs_bt_get_key (sb , node , last , & keylen );
358
350
359
351
eq = befs_compare_strings (thiskey , keylen , findkey , findkey_len );
360
352
if (eq < 0 ) {
361
- befs_debug (sb , "<--- %s %s not found" , __func__ , findkey );
362
- return BEFS_BT_NOT_FOUND ;
353
+ befs_debug (sb , "<--- node can't contain %s" , findkey );
354
+ return BEFS_BT_OVERFLOW ;
363
355
}
364
356
365
357
valarray = befs_bt_valarray (node );
@@ -387,12 +379,15 @@ befs_find_key(struct super_block *sb, struct befs_btree_node *node,
387
379
else
388
380
first = mid + 1 ;
389
381
}
382
+
383
+ /* return an existing value so caller can arrive to a leaf node */
390
384
if (eq < 0 )
391
385
* value = fs64_to_cpu (sb , valarray [mid + 1 ]);
392
386
else
393
387
* value = fs64_to_cpu (sb , valarray [mid ]);
394
- befs_debug (sb , "<--- %s found %s at %d" , __func__ , thiskey , mid );
395
- return BEFS_BT_PARMATCH ;
388
+ befs_error (sb , "<--- %s %s not found" , __func__ , findkey );
389
+ befs_debug (sb , "<--- %s ERROR" , __func__ );
390
+ return BEFS_BT_NOT_FOUND ;
396
391
}
397
392
398
393
/**
@@ -405,7 +400,7 @@ befs_find_key(struct super_block *sb, struct befs_btree_node *node,
405
400
* @keysize: Length of the returned key
406
401
* @value: Value stored with the returned key
407
402
*
408
- * Heres how it works: Key_no is the index of the key/value pair to
403
+ * Here's how it works: Key_no is the index of the key/value pair to
409
404
* return in keybuf/value.
410
405
* Bufsize is the size of keybuf (BEFS_NAME_LEN+1 is a good size). Keysize is
411
406
* the number of characters in the key (just a convenience).
@@ -422,7 +417,7 @@ befs_btree_read(struct super_block *sb, const befs_data_stream *ds,
422
417
{
423
418
struct befs_btree_node * this_node ;
424
419
befs_btree_super bt_super ;
425
- befs_off_t node_off = 0 ;
420
+ befs_off_t node_off ;
426
421
int cur_key ;
427
422
fs64 * valarray ;
428
423
char * keystart ;
@@ -467,7 +462,7 @@ befs_btree_read(struct super_block *sb, const befs_data_stream *ds,
467
462
while (key_sum + this_node -> head .all_key_count <= key_no ) {
468
463
469
464
/* no more nodes to look in: key_no is too large */
470
- if (this_node -> head .right == befs_bt_inval ) {
465
+ if (this_node -> head .right == BEFS_BT_INVAL ) {
471
466
* keysize = 0 ;
472
467
* value = 0 ;
473
468
befs_debug (sb ,
@@ -541,7 +536,6 @@ befs_btree_read(struct super_block *sb, const befs_data_stream *ds,
541
536
* @node_off: Pointer to offset of current node within datastream. Modified
542
537
* by the function.
543
538
*
544
- *
545
539
* Helper function for btree traverse. Moves the current position to the
546
540
* start of the first leaf node.
547
541
*
@@ -608,7 +602,7 @@ static int
608
602
befs_leafnode (struct befs_btree_node * node )
609
603
{
610
604
/* all interior nodes (and only interior nodes) have an overflow node */
611
- if (node -> head .overflow == befs_bt_inval )
605
+ if (node -> head .overflow == BEFS_BT_INVAL )
612
606
return 1 ;
613
607
else
614
608
return 0 ;
@@ -715,7 +709,7 @@ befs_bt_get_key(struct super_block *sb, struct befs_btree_node *node,
715
709
*
716
710
* Returns 0 if @key1 and @key2 are equal.
717
711
* Returns >0 if @key1 is greater.
718
- * Returns <0 if @key2 is greater..
712
+ * Returns <0 if @key2 is greater.
719
713
*/
720
714
static int
721
715
befs_compare_strings (const void * key1 , int keylen1 ,
0 commit comments