33
44#include "simplefs.h"
55
6- /* Search for the extent containing the target block.
6+ /* Search for the extent containing the target block. Binary search is used
7+ * for efficiency.
8+ *
79 * Returns the first unused file index if not found.
810 * Returns -1 if the target block is out of range.
9- * Binary search is used for efficiency.
1011 */
1112uint32_t simplefs_ext_search (struct simplefs_file_ei_block * index ,
1213 uint32_t iblock )
1314{
14- /* first , find the first unused file index with binary search.
15- * It'll be our right boundary for actual binary search
16- * and return value when file index is not found.
15+ /* First , find the first unused file index with binary search.
16+ * It will be our right boundary for actual binary search and the return
17+ * value when the file index is not found.
1718 */
1819 uint32_t start = 0 ;
1920 uint32_t end = SIMPLEFS_MAX_EXTENTS - 1 ;
@@ -62,13 +63,13 @@ uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
6263
6364 /* return 'end' if it directs to valid block
6465 * return 'boundary' if index is not found
65- * and eiblock has remaining space */
66+ * and eiblock has remaining space
67+ */
6668 end_block = index -> extents [end ].ee_block ;
6769 end_len = index -> extents [end ].ee_len ;
68- if (iblock >= end_block && iblock < end_len ) {
70+ if (iblock >= end_block && iblock < end_len )
6971 return end ;
70- } else if (boundary < SIMPLEFS_MAX_EXTENTS ) {
72+ if (boundary < SIMPLEFS_MAX_EXTENTS )
7173 return boundary ;
72- }
7374 return boundary ;
74- }
75+ }
0 commit comments