@@ -85,7 +85,7 @@ struct befs_btree_node {
8585};
8686
8787/* local constants */
88- static const befs_off_t befs_bt_inval = 0xffffffffffffffffULL ;
88+ static const befs_off_t BEFS_BT_INVAL = 0xffffffffffffffffULL ;
8989
9090/* local functions */
9191static 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,
156156 sup -> max_depth = fs32_to_cpu (sb , od_sup -> max_depth );
157157 sup -> data_type = fs32_to_cpu (sb , od_sup -> data_type );
158158 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 );
161159
162160 brelse (bh );
163161 if (sup -> magic != BEFS_BTREE_MAGIC ) {
@@ -183,8 +181,8 @@ befs_bt_read_super(struct super_block *sb, const befs_data_stream *ds,
183181 * Calls befs_read_datastream to read in the indicated btree node and
184182 * makes sure its header fields are in cpu byteorder, byteswapping if
185183 * 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.
188186 *
189187 * On success, returns BEFS_OK and *@node contains the btree node that
190188 * 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,
244242 * Read the superblock and rootnode of the b+tree.
245243 * Drill down through the interior nodes using befs_find_key().
246244 * 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.
248246 */
249247int
250248befs_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,
283281
284282 while (!befs_leafnode (this_node )) {
285283 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 )
287286 node_off = this_node -> head .overflow ;
288- /* if no match, go to overflow node */
289287 if (befs_bt_read_node (sb , ds , this_node , node_off ) != BEFS_OK ) {
290288 befs_error (sb , "befs_btree_find() failed to read "
291289 "node at %llu" , node_off );
292290 goto error_alloc ;
293291 }
294292 }
295293
296- /* at the correct leaf node now */
297-
294+ /* at a leaf node now, check if it is correct */
298295 res = befs_find_key (sb , this_node , key , value );
299296
300297 brelse (this_node -> bh );
301298 kfree (this_node );
302299
303300 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__ );
305303 * value = 0 ;
306304 return BEFS_BT_NOT_FOUND ;
307305 }
@@ -324,16 +322,12 @@ befs_btree_find(struct super_block *sb, const befs_data_stream *ds,
324322 * @findkey: Keystring to search for
325323 * @value: If key is found, the value stored with the key is put here
326324 *
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.
335329 *
336- * Use binary search instead of a linear.
330+ * Uses binary search instead of a linear.
337331 */
338332static int
339333befs_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,
348342
349343 befs_debug (sb , "---> %s %s" , __func__ , findkey );
350344
351- * value = 0 ;
352-
353345 findkey_len = strlen (findkey );
354346
355- /* if node can not contain key, just skeep this node */
347+ /* if node can not contain key, just skip this node */
356348 last = node -> head .all_key_count - 1 ;
357349 thiskey = befs_bt_get_key (sb , node , last , & keylen );
358350
359351 eq = befs_compare_strings (thiskey , keylen , findkey , findkey_len );
360352 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 ;
363355 }
364356
365357 valarray = befs_bt_valarray (node );
@@ -387,12 +379,15 @@ befs_find_key(struct super_block *sb, struct befs_btree_node *node,
387379 else
388380 first = mid + 1 ;
389381 }
382+
383+ /* return an existing value so caller can arrive to a leaf node */
390384 if (eq < 0 )
391385 * value = fs64_to_cpu (sb , valarray [mid + 1 ]);
392386 else
393387 * 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 ;
396391}
397392
398393/**
@@ -405,7 +400,7 @@ befs_find_key(struct super_block *sb, struct befs_btree_node *node,
405400 * @keysize: Length of the returned key
406401 * @value: Value stored with the returned key
407402 *
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
409404 * return in keybuf/value.
410405 * Bufsize is the size of keybuf (BEFS_NAME_LEN+1 is a good size). Keysize is
411406 * 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,
422417{
423418 struct befs_btree_node * this_node ;
424419 befs_btree_super bt_super ;
425- befs_off_t node_off = 0 ;
420+ befs_off_t node_off ;
426421 int cur_key ;
427422 fs64 * valarray ;
428423 char * keystart ;
@@ -467,7 +462,7 @@ befs_btree_read(struct super_block *sb, const befs_data_stream *ds,
467462 while (key_sum + this_node -> head .all_key_count <= key_no ) {
468463
469464 /* 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 ) {
471466 * keysize = 0 ;
472467 * value = 0 ;
473468 befs_debug (sb ,
@@ -541,7 +536,6 @@ befs_btree_read(struct super_block *sb, const befs_data_stream *ds,
541536 * @node_off: Pointer to offset of current node within datastream. Modified
542537 * by the function.
543538 *
544- *
545539 * Helper function for btree traverse. Moves the current position to the
546540 * start of the first leaf node.
547541 *
@@ -608,7 +602,7 @@ static int
608602befs_leafnode (struct befs_btree_node * node )
609603{
610604 /* 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 )
612606 return 1 ;
613607 else
614608 return 0 ;
@@ -715,7 +709,7 @@ befs_bt_get_key(struct super_block *sb, struct befs_btree_node *node,
715709 *
716710 * Returns 0 if @key1 and @key2 are equal.
717711 * Returns >0 if @key1 is greater.
718- * Returns <0 if @key2 is greater..
712+ * Returns <0 if @key2 is greater.
719713 */
720714static int
721715befs_compare_strings (const void * key1 , int keylen1 ,
0 commit comments