Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors raised by missing-prototypes #45

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 60 additions & 10 deletions extent.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,69 @@
/* Search for the extent containing the target block.
* Returns the first unused file index if not found.
* Returns -1 if the target block is out of range.
* TODO: Implement binary search for efficiency.
* Binary search is used for efficiency.
*/
uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
uint32_t iblock)
{
uint32_t i;
for (i = 0; i < SIMPLEFS_MAX_EXTENTS; i++) {
uint32_t block = index->extents[i].ee_block;
uint32_t len = index->extents[i].ee_len;
if (index->extents[i].ee_start == 0 ||
(iblock >= block && iblock < block + len))
return i;
/* first, find the first unused file index with binary search.
* It'll be our right boundary for actual binary search
* and return value when file index is not found.
*/
uint32_t start = 0;
uint32_t end = SIMPLEFS_MAX_EXTENTS - 1;
uint32_t boundary;
uint32_t end_block;
uint32_t end_len;

while (start < end) {
uint32_t mid = start + (end - start) / 2;
if (index->extents[mid].ee_start == 0) {
end = mid;
} else {
start = mid + 1;
}
}

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 */
start = 0;
end = boundary - 1;
while (start < end) {
uint32_t mid = start + (end - start) / 2;
uint32_t block = index->extents[mid].ee_block;
uint32_t len = index->extents[mid].ee_len;
if (iblock >= block && iblock < block + len) {
/* found before search finished */
return mid;
}
if (iblock < block) {
end = mid;
} else {
start = mid + 1;
}
}

return -1;
}
/* 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;
}
9 changes: 8 additions & 1 deletion simplefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ struct simplefs_dir_block {

/* superblock functions */
int simplefs_fill_super(struct super_block *sb, void *data, int silent);
void simplefs_kill_sb(struct super_block *sb);

/* inode functions */
int simplefs_init_inode_cache(void);
void simplefs_destroy_inode_cache(void);
struct inode *simplefs_iget(struct super_block *sb, unsigned long ino);

/* dentry function */
struct dentry *simplefs_mount(struct file_system_type *fs_type,
int flags,
const char *dev_name,
void *data);

/* file functions */
extern const struct file_operations simplefs_file_ops;
extern const struct file_operations simplefs_dir_ops;
Expand All @@ -123,7 +130,7 @@ extern const struct address_space_operations simplefs_aops;
extern uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
uint32_t iblock);

/* Getters for superbock and inode */
/* Getters for superblock and inode */
#define SIMPLEFS_SB(sb) (sb->s_fs_info)
#define SIMPLEFS_INODE(inode) \
(container_of(inode, struct simplefs_inode_info, vfs_inode))
Expand Down