store num_inode_blocks in superblock, choose this value adaptively according to disk size when mkfs
This commit is contained in:
parent
bc9a7d0b3c
commit
26b44b20ba
@ -12,7 +12,7 @@ class DatablockOperation;
|
||||
|
||||
class Fs {
|
||||
public:
|
||||
Fs(RawDisk *disk);
|
||||
Fs(RawDisk *disk, bool load = false);
|
||||
~Fs();
|
||||
|
||||
ssize_t read(INode_Data *inode_data, char buf[], size_t count, size_t offset);
|
||||
|
@ -15,6 +15,7 @@ class SuperBlock_Data {
|
||||
public:
|
||||
u_int64_t free_list_head;
|
||||
u_int64_t inode_list_head;
|
||||
u_int64_t num_inode_blocks;
|
||||
SuperBlock_Data();
|
||||
void serialize(char buf[]);
|
||||
void deserialize(char buf[]);
|
||||
|
@ -227,7 +227,11 @@ int fischl(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
options.fs = new Fs(options.H);
|
||||
if(!options.load){
|
||||
if(options.load){
|
||||
options.fs = new Fs(options.H, true);
|
||||
}
|
||||
else{
|
||||
options.fs = new Fs(options.H);
|
||||
printf("FORMAT %d\n", options.fs->format());
|
||||
}
|
||||
options.fsop = new FilesOperation(*options.H, options.fs);
|
||||
|
@ -1,13 +1,22 @@
|
||||
#include "fs.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
Fs::Fs(RawDisk *disk) : disk(disk) {
|
||||
assert((disk->diskSize / IO_BLOCK_SIZE) >
|
||||
2 + NUM_INODE_BLOCKS + DATABLOCKS_PER_BITMAP_BLOCK);
|
||||
Fs::Fs(RawDisk *disk, bool load) : disk(disk) {
|
||||
superblock = SuperBlock_Data();
|
||||
inode_manager = new INode_Manager_Freelist(this, 1, 1 + NUM_INODE_BLOCKS);
|
||||
// Determine the num inode blocks
|
||||
uint64_t num_inode_blocks = 0; // The superblock is not loaded from disk here; it is done in FilesOperation::initialize called by fischl_init
|
||||
if(load) {
|
||||
load_superblock();
|
||||
num_inode_blocks = superblock.num_inode_blocks;
|
||||
} else {
|
||||
num_inode_blocks = (disk->diskSize / IO_BLOCK_SIZE) / 8; // adaptive size
|
||||
superblock.num_inode_blocks = num_inode_blocks;
|
||||
}
|
||||
assert((disk->diskSize / IO_BLOCK_SIZE) >
|
||||
2 + num_inode_blocks + DATABLOCKS_PER_BITMAP_BLOCK);
|
||||
inode_manager = new INode_Manager_Freelist(this, 1, 1 + num_inode_blocks);
|
||||
datablock_manager = new DataBlock_Manager_Bitmap(
|
||||
this, 1 + NUM_INODE_BLOCKS, disk->diskSize / IO_BLOCK_SIZE);
|
||||
this, 1 + num_inode_blocks, disk->diskSize / IO_BLOCK_SIZE);
|
||||
};
|
||||
|
||||
Fs::~Fs() {
|
||||
|
@ -36,18 +36,21 @@ size_t read_u32(u_int32_t *num, char buf[]) {
|
||||
SuperBlock_Data::SuperBlock_Data() {
|
||||
free_list_head = 0;
|
||||
inode_list_head = 0;
|
||||
num_inode_blocks = 0;
|
||||
}
|
||||
|
||||
void SuperBlock_Data::serialize(char buf[]) {
|
||||
size_t i = 0;
|
||||
i += write_u64(free_list_head, &buf[i]);
|
||||
i += write_u64(inode_list_head, &buf[i]);
|
||||
i += write_u64(num_inode_blocks, &buf[i]);
|
||||
}
|
||||
|
||||
void SuperBlock_Data::deserialize(char buf[]) {
|
||||
size_t i = 0;
|
||||
i += read_u64(&free_list_head, &buf[i]);
|
||||
i += read_u64(&inode_list_head, &buf[i]);
|
||||
i += read_u64(&num_inode_blocks, &buf[i]);
|
||||
}
|
||||
|
||||
INode_Data::INode_Data(u_int64_t inode_num) : inode_num(inode_num) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user