-
Notifications
You must be signed in to change notification settings - Fork 0
[Lower Layer] Block
Dividing a file to several parts.
In EXT2 file system, block size can be 1KB, 2KB, or 4KB. We may choose 1KB(1024B) to be our block size.
This function can create blocks. It means that this function can create a space for our file system. This function should be only executed once.
int create_filesystem(const char *path, const int size)
-
const char *path
: where user will like to place the whole file system. -
const int size
: The size of the whole file system.
- return value > 0, it means that
create_block
works fine. Return value is also equal to how many blocks you created. - return value = -1, it means that
create_block
fails to request a space on disk. - return value = -2, it means that
create_block
get a bad file system.
This function can load blocks from existing file system. Either load block or create block should be called only once.
int load_filesystem(const char *path)
-
const char *path
: the path of existing file system.
- return value = 0: it means that
load_block
works fine. - return value = -1, file system does not exist.
- return value = -2, file system fails to load because of some reason.
- return value = -3, file system fails to read.
- return value = -4, bad header, invalid file.
- to be continued.......
This function can let other functions write something to a specific block. Function will find a proper block to put data. The main purpose of this function is assign a block for user and write data to block at same time.
int write_block(const int *block_ID, void *block, int block_input_length)
-
const int *block_ID
: Block's ID. This number is a special number only for a block. Because this parameter is a pointer type, it can bring block ID to the function which calledwrite_block
. -
void *block
: the message which is going to write to block. -
int block_input_length
: the length ofblock
- return value >= 0: write successfully, return value is also same as how many bytes does function write.
- return value = -1: no file system exit.
- return value = -2: block_ID is larger that the number of blocks.
- return value = -3: fail move to the blockID.
- return value = -4: fails to write
- to be continue......
This function can let other functions modify super block. The main purpose of this function is modify data in a block.
int modify_super_block(void *block, int block_input_length)
-
void *block
: the message which is going to write to block. -
int block_input_length
: the length ofblock
- return value >= 0: write successfully, return value is also same as how many bytes does function write.
- return value = -1: no file system exit.
- return value = -3: fail move to super block.
- return value = -4: fails to write
- to be continue......
This function can let other functions read super block.
int read_block(void *block, int block_output_length)
-
void *block
: To get the message read from block. -
int block_output_length
: How many bytes does user wants to read from super block
- return value >= 0: works fine, return value is also same as how many bytes does function read.
- return value = -1: Filesystem does not exist.
- return value = -3: fail to move to super block.
- return value = -4: fail to read.
- to be continue......
This function can let other functions modify something to a specific block.
int modify_block(const int *block_ID, void *block, int block_input_length)
-
const int *block_ID
: Block's ID. This number is a special number only for a block. -
void *block
: the message which is going to write to block. -
int block_input_length
: the length ofblock
- return value >= 0: write successfully, return value is also same as how many bytes does function write.
- return value = -1: no file system exit.
- return value = -2: block_ID is larger that the number of blocks.
- return value = -3: fail move to the blockID.
- return value = -4: fails to write
- to be continue......
This function can let other functions read the specific block.
int read_block(const int block_ID, void *block)
-
const int block_ID
: Block's ID. This number is a special number only for a block. -
void *block
: To get the message read from block.
- return value >= 0: works fine, return value is also same as how many bytes does function read.
- return value = -1: Filesystem doest not exist.
- return value = -2: block_ID is larger that the number of blocks.
- return value = -3: fail to move to blockID.
- return value = -4: fail to read.
- to be continue......
This function can let other functions delete the whole message which is stored in a specific block.
int delete_block(const int *block_ID)
-
const int *block_ID
: Block's ID. This number is a special number only for a block.
- return value = 0: delete successfully.
- to be continue......
Super block will be located at block[0]. Because of block map and identify header, there are 502 empty bytes.
The upper layer of block is inode, The blocks which are number from 1 to 512 are reservered for inodes(512 * 1024 = 524288 bytes, 524288 / 128(size of one inode) = 4096).