Merge branch 'guangzheliu/layer1dev' into wangziao/layer1test
This commit is contained in:
commit
3d959eeeb1
25
include/fs.h
25
include/fs.h
@ -17,7 +17,7 @@ one inode equipped with one 512 bytes block
|
|||||||
class SuperBlock{
|
class SuperBlock{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SuperBlock(const char *directory){
|
SuperBlock(){
|
||||||
|
|
||||||
}
|
}
|
||||||
~SuperBlock(){
|
~SuperBlock(){
|
||||||
@ -145,7 +145,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
char buffer[IO_BLOCK_SIZE] = {0};
|
char buffer[IO_BLOCK_SIZE] = {0};
|
||||||
u_int64_t freeBlockNum = 0;
|
u_int64_t freeBlockNum = 0;
|
||||||
disk.rawdisk_read(freeListHead, buffer, sizeof(buffer));
|
disk.rawdisk_read(freeListHea
|
||||||
|
d, buffer, sizeof(buffer));
|
||||||
for (int i = 8; i < 264; i++){
|
for (int i = 8; i < 264; i++){
|
||||||
if((i < 263 && buffer[i] != -1) || (i == 263 && buffer[i] != 127)){
|
if((i < 263 && buffer[i] != -1) || (i == 263 && buffer[i] != 127)){
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@ -181,9 +182,8 @@ public:
|
|||||||
bool allo_single_indirect(RawDisk &disk, u_int64_t &single_i, u_int64_t freeBlockNum) {
|
bool allo_single_indirect(RawDisk &disk, u_int64_t &single_i, u_int64_t freeBlockNum) {
|
||||||
if (single_i == 0){
|
if (single_i == 0){
|
||||||
single_i = datablock_allocate_in_list(disk);
|
single_i = datablock_allocate_in_list(disk);
|
||||||
char init_buffer[IO_BLOCK_SIZE] = {0};
|
char new_buffer[IO_BLOCK_SIZE] = {0};
|
||||||
disk.rawdisk_write(single_i, init_buffer, sizeof(init_buffer));
|
disk.rawdisk_write(single_i, new_buffer, sizeof(new_buffer));
|
||||||
// I think the same should be done to alloc double, triple indirect
|
|
||||||
}
|
}
|
||||||
bool inSingle = false;
|
bool inSingle = false;
|
||||||
char buffer[IO_BLOCK_SIZE] = {0};
|
char buffer[IO_BLOCK_SIZE] = {0};
|
||||||
@ -203,8 +203,8 @@ public:
|
|||||||
bool allo_double_indirect(RawDisk &disk, u_int64_t &double_i, u_int64_t freeBlockNum) {
|
bool allo_double_indirect(RawDisk &disk, u_int64_t &double_i, u_int64_t freeBlockNum) {
|
||||||
if (double_i == 0){
|
if (double_i == 0){
|
||||||
double_i = datablock_allocate_in_list(disk);
|
double_i = datablock_allocate_in_list(disk);
|
||||||
char init_buffer[IO_BLOCK_SIZE] = {0};
|
char new_buffer[IO_BLOCK_SIZE] = {0};
|
||||||
disk.rawdisk_write(double_i, init_buffer, sizeof(init_buffer));
|
disk.rawdisk_write(double_i, new_buffer, sizeof(new_buffer));
|
||||||
}
|
}
|
||||||
bool inDouble = false;
|
bool inDouble = false;
|
||||||
char buffer[IO_BLOCK_SIZE] = {0};
|
char buffer[IO_BLOCK_SIZE] = {0};
|
||||||
@ -225,8 +225,8 @@ public:
|
|||||||
bool allo_triple_indirect(RawDisk &disk, u_int64_t &triple_i, u_int64_t freeBlockNum) {
|
bool allo_triple_indirect(RawDisk &disk, u_int64_t &triple_i, u_int64_t freeBlockNum) {
|
||||||
if (triple_i == 0){
|
if (triple_i == 0){
|
||||||
triple_i = datablock_allocate_in_list(disk);
|
triple_i = datablock_allocate_in_list(disk);
|
||||||
char init_buffer[IO_BLOCK_SIZE] = {0};
|
char new_buffer[IO_BLOCK_SIZE] = {0};
|
||||||
disk.rawdisk_write(triple_i, init_buffer, sizeof(init_buffer));
|
disk.rawdisk_write(triple_i, new_buffer, sizeof(new_buffer));
|
||||||
}
|
}
|
||||||
bool inTriple = false;
|
bool inTriple = false;
|
||||||
char buffer[IO_BLOCK_SIZE] = {0};
|
char buffer[IO_BLOCK_SIZE] = {0};
|
||||||
@ -279,6 +279,7 @@ public:
|
|||||||
u_int64_t freeBlockHead = ((freeBlockNum/SECTOR_SIZE-MAX_INODE)/(8*2048)*(8*2048)+MAX_INODE)*SECTOR_SIZE;
|
u_int64_t freeBlockHead = ((freeBlockNum/SECTOR_SIZE-MAX_INODE)/(8*2048)*(8*2048)+MAX_INODE)*SECTOR_SIZE;
|
||||||
|
|
||||||
char buffer[IO_BLOCK_SIZE] = {0};
|
char buffer[IO_BLOCK_SIZE] = {0};
|
||||||
|
bool nowInList = false;
|
||||||
disk.rawdisk_read(freeBlockHead, buffer, sizeof(buffer));
|
disk.rawdisk_read(freeBlockHead, buffer, sizeof(buffer));
|
||||||
|
|
||||||
// mark it alive in its bitmap
|
// mark it alive in its bitmap
|
||||||
@ -287,13 +288,13 @@ public:
|
|||||||
|
|
||||||
bool notEmpty = false;
|
bool notEmpty = false;
|
||||||
for (int i = 8; i < 264; i++){
|
for (int i = 8; i < 264; i++){
|
||||||
if(buffer[i] != 0){
|
if((i < 263 && buffer[i] != -1) || (i == 263 && buffer[i] != 127)){
|
||||||
notEmpty = true;
|
nowInList = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if its bitmap was 0, add it back to the list head
|
// if its bitmap was 0, add it back to the list head
|
||||||
if(!notEmpty){
|
if(!nowInList){
|
||||||
u_int64_t freeListHead = SuperBlock::getFreeListHead(disk);
|
u_int64_t freeListHead = SuperBlock::getFreeListHead(disk);
|
||||||
write_byte_at(freeListHead, 0, buffer);
|
write_byte_at(freeListHead, 0, buffer);
|
||||||
printf("HEADER MOVE (Cause: Dealloc) %llu -> %llu\n", freeListHead, freeBlockHead);
|
printf("HEADER MOVE (Cause: Dealloc) %llu -> %llu\n", freeListHead, freeBlockHead);
|
||||||
|
@ -11,37 +11,40 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
printf("test inode\n");
|
printf("test inode\n");
|
||||||
INodeOperation inop;
|
INodeOperation inop;
|
||||||
inop.initialize(*H);
|
inop.initialize(*H);//for inode initialization and datablock initialization
|
||||||
char buffer[8] = {0};
|
char buffer[8] = {0};
|
||||||
//test the begining of inode 1~524287
|
/**************************test inode Initialization***************************/
|
||||||
|
//test the begining of inode 1th
|
||||||
H->rawdisk_read((1) * SECTOR_SIZE, buffer, sizeof(buffer));
|
H->rawdisk_read((1) * SECTOR_SIZE, buffer, sizeof(buffer));
|
||||||
u_int64_t t = 0;
|
u_int64_t t = 0;
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
||||||
|
|
||||||
assert(t == 2);
|
assert(t == 2);//the first 1th unused inode will store the next unused inode 2th
|
||||||
//test the number before end of inode 524286
|
//test the number before end of inode 524286th
|
||||||
H->rawdisk_read((MAX_INODE - 2) * SECTOR_SIZE, buffer, sizeof(buffer));
|
H->rawdisk_read((MAX_INODE - 2) * SECTOR_SIZE, buffer, sizeof(buffer));
|
||||||
t = 0;
|
t = 0;
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
||||||
|
|
||||||
fprintf(stderr,"[t %llu,%d]\n",t,__LINE__);
|
assert(t == MAX_INODE - 1);//store the maximun th inode
|
||||||
assert(t == MAX_INODE - 1);
|
//test the end of inode 524287th
|
||||||
//test the end of inode 1~524287
|
|
||||||
H->rawdisk_read((MAX_INODE - 1) * SECTOR_SIZE, buffer, sizeof(buffer));
|
H->rawdisk_read((MAX_INODE - 1) * SECTOR_SIZE, buffer, sizeof(buffer));
|
||||||
t = 0;
|
t = 0;
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
||||||
|
|
||||||
assert(t == 0);
|
assert(t == 0);//the end of inode(524287th inode) do not have the next inode address
|
||||||
//test the begining of datablock
|
/**************************test datablock Initialization***************************/
|
||||||
H->rawdisk_read((MAX_INODE) * SECTOR_SIZE, buffer, sizeof(buffer));
|
//we separate 2048 4kB I/O block(1+2047) as a group and the first I/O block will manage the following 2047 I/O block usage.
|
||||||
|
//the first 8 bytes(0~7) in first I/O block store the address of next first I/O block, the following 256(8~263) bytes record 2047 I/O block usage.
|
||||||
|
//test the begining of free datablock
|
||||||
|
H->rawdisk_read((MAX_INODE) * SECTOR_SIZE, buffer, sizeof(buffer));//the begining of free datablock will store from address (MAX_INODE) * SECTOR_SIZE
|
||||||
t = 0;
|
t = 0;
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
||||||
|
|
||||||
assert(t == (MAX_INODE+2048*8)*SECTOR_SIZE);
|
assert(t == (MAX_INODE+2048*8)*SECTOR_SIZE);//the first 8 bytes of 4k I/O block will store the next address(after 2048*4k I/O block)
|
||||||
//test the end of the datablock
|
//test the end of the datablock
|
||||||
H->rawdisk_read((MAX_BLOCKNUM - 2048*8) * SECTOR_SIZE, buffer, sizeof(buffer));
|
H->rawdisk_read((MAX_BLOCKNUM - 2048*8) * SECTOR_SIZE, buffer, sizeof(buffer));
|
||||||
t = 0;
|
t = 0;
|
||||||
@ -49,60 +52,66 @@ int main(int argc, char *argv[]) {
|
|||||||
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
|
||||||
|
|
||||||
assert(t == (MAX_BLOCKNUM)*SECTOR_SIZE);
|
assert(t == (MAX_BLOCKNUM)*SECTOR_SIZE);
|
||||||
//initialize
|
|
||||||
|
/***************************test inode de/allocation**********************************/
|
||||||
|
//when requesting an inode, the inode_allocation will give you the inode number, we use inode_list to store the sequence allocate inode
|
||||||
|
//arrary version
|
||||||
int inode_list[20] = {0};
|
int inode_list[20] = {0};
|
||||||
printf("Allocate 20 inode num:{");
|
int record_free[10] = {0};//should do a pop up structure to record the free inode
|
||||||
|
int rec = 9;
|
||||||
|
//printf("Allocate 20 inode num:{");
|
||||||
for(int i=0;i<20;i++){
|
for(int i=0;i<20;i++){
|
||||||
inode_list[i] = inop.inode_allocate(*H);
|
inode_list[i] = inop.inode_allocate(*H);
|
||||||
printf(" %d", inode_list[i]);
|
assert(inode_list[i] == i+1);
|
||||||
|
//printf(" %d", inode_list[i]);
|
||||||
}
|
}
|
||||||
printf("}\n");
|
//printf("}\n");
|
||||||
//free the last 10
|
|
||||||
printf("Free: inode num:{");
|
|
||||||
for(int i=10;i<20;i++){
|
for(int i=10;i<20;i++){
|
||||||
inop.inode_free(*H,inode_list[i]);
|
inop.inode_free(*H,inode_list[i]);//free the 10 element from inode_list[10]
|
||||||
printf(" %d", inode_list[i]);
|
record_free[i-10] = inode_list[i];
|
||||||
}
|
}
|
||||||
printf("}\n");
|
|
||||||
//allocate again the last 10
|
//allocate again the last 10
|
||||||
printf("Allocate again: inode num:{");
|
printf("Allocate again: inode num:{");
|
||||||
for(int i=10;i<20;i++){
|
for(int i=10;i<20;i++){
|
||||||
inode_list[i] = inop.inode_allocate(*H);
|
inode_list[i] = inop.inode_allocate(*H);
|
||||||
printf(" %d", inode_list[i]);
|
//printf("inode %d, rec_f %d\n,", inode_list[i],record_free[rec]);
|
||||||
|
assert(inode_list[i] == record_free[rec]);
|
||||||
|
rec--;
|
||||||
}
|
}
|
||||||
printf("}\n");
|
printf("}\n");
|
||||||
|
/***************************test direct blocks[48] de/allocation**********************************/
|
||||||
printf("The status 20 inode num:{");
|
//after free the datablock, the program will find the first smallest address of datablock to give to the inode
|
||||||
for(int i=0;i<20;i++){
|
//should test random resize each node, but should use datablock_free data structure to record
|
||||||
printf(" %d", inode_list[i]);
|
|
||||||
}
|
|
||||||
printf("}\n");
|
|
||||||
|
|
||||||
INode inode_inside[10];
|
INode inode_inside[10];
|
||||||
|
u_int64_t rec_datablock_free[10][3] = {0};//array version
|
||||||
for(int i=0;i<10;i++){
|
for(int i=0;i<10;i++){
|
||||||
inode_inside[i].inode_construct(inode_list[i],*H);
|
inode_inside[i].inode_construct(inode_list[i],*H);
|
||||||
printf("%dth data block starting addres: ", i);
|
//printf("%dth data block starting addres: ", i);
|
||||||
for(int j=0;j<6;j++){
|
for(int j=0;j<6;j++){
|
||||||
printf("%d," ,inode_inside[i].datablock_allocate(*H));
|
inode_inside[i].datablock_allocate(*H);
|
||||||
|
//printf("%d," ,inode_inside[i].datablock_allocate(*H));
|
||||||
}
|
}
|
||||||
printf("\n");
|
//printf("\n");
|
||||||
}
|
}
|
||||||
for(int i=0;i<10;i++){
|
for(int i=0;i<10;i++){
|
||||||
printf("%dth data block free addres: ", i);
|
//printf("%dth data block free addres: ", i);
|
||||||
for(int j=0;j<3;j++){
|
for(int j = 2;j >=0;j--){
|
||||||
printf("%d," ,inode_inside[i].datablock_deallocate(*H));
|
rec_datablock_free[i][j] = inode_inside[i].datablock_deallocate(*H);
|
||||||
|
//printf("", rec_datablock_free[i][j]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
//printf("\n");
|
||||||
}
|
|
||||||
for(int i=0;i<10;i++){
|
|
||||||
printf("%dth data block allocate again addres: ", i);
|
|
||||||
for(int j=0;j<3;j++){
|
|
||||||
printf("%d," ,inode_inside[i].datablock_allocate(*H));
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("}\n");
|
for(int i=0;i<10;i++){
|
||||||
|
//printf("%dth data block allocate again addres: ", i);
|
||||||
|
for(int j=0;j<3;j++){
|
||||||
|
assert(inode_inside[i].datablock_allocate(*H) == rec_datablock_free[i][j]);
|
||||||
|
//printf("%d," ,inode_inside[i].datablock_allocate(*H));
|
||||||
|
}
|
||||||
|
//printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("}\n");
|
||||||
delete H; // Delete the RawDisk object
|
delete H; // Delete the RawDisk object
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user