Skip to content

Commit

Permalink
Corner cases fixed mentioned in pr
Browse files Browse the repository at this point in the history
  • Loading branch information
baekrang256 committed Apr 24, 2024
1 parent 0f9f20c commit b4897f3
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions extent.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
*/
uint32_t start = 0;
uint32_t end = SIMPLEFS_MAX_EXTENTS - 1;
uint32_t boundary = -1;
uint32_t boundary;
uint32_t end_block;
uint32_t end_len;

Expand All @@ -30,8 +30,16 @@ uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
}
}

if (end != SIMPLEFS_MAX_EXTENTS - 1 || index->extents[end].ee_start == 0) {
if (index->extents[end].ee_start == 0) {
boundary = end;
} else {
/* File index full */
boundary = end + 1;
}

if (boundary == 0) {
/* No used file index */
return boundary;
}

/* try finding target block using binary search */
Expand All @@ -52,12 +60,16 @@ uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
}
}

/* check that end directs to valid block. */
/* return 'end' if it directs to valid block
* return 'boundary' if index is not found
* and eiblock has remaining space */
end_block = index->extents[end].ee_block;
end_len = index->extents[end].ee_len;

if (iblock >= end_block && iblock < end_len) {
return end;
} else if (boundary < SIMPLEFS_MAX_EXTENTS) {
return boundary;
}
return boundary;

return -1;
}

0 comments on commit b4897f3

Please sign in to comment.