forked from sysprog21/simplefs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextent.c
More file actions
24 lines (22 loc) · 677 Bytes
/
extent.c
File metadata and controls
24 lines (22 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <linux/fs.h>
#include <linux/kernel.h>
#include "simplefs.h"
/*
* Search the extent which contain the target block.
* Retrun the first unused file index if not found.
* Return -1 if it is out of range.
* TODO: use binary search.
*/
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;
}
return -1;
}