half of tests added

This commit is contained in:
Connor 2023-11-17 01:33:19 -08:00
parent b921cadf92
commit 9ed5936762
11 changed files with 614 additions and 544 deletions

View File

@ -21,5 +21,5 @@ add_executable(fischl
)
#enable_testing()
#add_subdirectory(test)
enable_testing()
add_subdirectory(test)

View File

@ -12,8 +12,8 @@ public:
Fs(RawDisk *disk);
~Fs();
int allocate_datablock(INode_Data *inode_data);
int deallocate_datablock(INode_Data *inode_data);
int allocate_datablock(INode_Data *inode_data, u_int64_t *datablock_num);
int deallocate_datablock(INode_Data *inode_data, u_int64_t *datablock_num);
int format();
@ -29,8 +29,8 @@ public:
int save_free_list_head(u_int64_t new_free_list_head);
int save_inode_list_head(u_int64_t new_inode_list_head);
int allocate_indirect(u_int64_t *storage, int n);
int deallocate_indirect(u_int64_t *storage, int n);
int allocate_indirect(u_int64_t *storage, int n, u_int64_t *datablock_num);
int deallocate_indirect(u_int64_t *storage, int n, u_int64_t *datablock_num);
};
#endif

View File

@ -1,25 +1,27 @@
#include "fs.hpp"
int Fs::allocate_datablock(INode_Data *inode_data) {
int Fs::allocate_datablock(INode_Data *inode_data, u_int64_t *datablock_num) {
int result;
for (size_t i = 0; i < NUMBER_OF_DIRECT_BLOCKS; ++i)
if (inode_data->direct_blocks[i] == 0) {
if ((result = datablock_manager->new_datablock(
&(inode_data->direct_blocks[i]))) < 0)
for (size_t i = 0; i < NUMBER_OF_DIRECT_BLOCKS; ++i) {
result =
allocate_indirect(&(inode_data->direct_blocks[i]), 0, datablock_num);
if (result <= 0)
return result;
return 0;
}
result = allocate_indirect(&(inode_data->single_indirect_block), 1);
result =
allocate_indirect(&(inode_data->single_indirect_block), 1, datablock_num);
if (result <= 0)
return result;
result = allocate_indirect(&(inode_data->double_indirect_block), 2);
result =
allocate_indirect(&(inode_data->double_indirect_block), 2, datablock_num);
if (result <= 0)
return result;
result = allocate_indirect(&(inode_data->triple_indirect_block), 3);
result =
allocate_indirect(&(inode_data->triple_indirect_block), 3, datablock_num);
if (result <= 0)
return result;
@ -28,16 +30,18 @@ int Fs::allocate_datablock(INode_Data *inode_data) {
// This can simply be made non recursive by copy pasting - it is just written
// this way as a proof of concept
int Fs::allocate_indirect(u_int64_t *storage, int n) {
int Fs::allocate_indirect(u_int64_t *storage, int n, u_int64_t *datablock_num) {
char buf[IO_BLOCK_SIZE];
int result;
if ((*storage) == 0) {
if ((result = datablock_manager->new_datablock(storage)) < 0)
return result;
if (n == 0)
if (n == 0) {
(*datablock_num) = (*storage);
return 0;
}
}
if (n == 0)
return 1;
@ -49,7 +53,7 @@ int Fs::allocate_indirect(u_int64_t *storage, int n) {
for (size_t i = 0; i < IO_BLOCK_SIZE; i += sizeof(u_int64_t)) {
read_u64(&temp, &buf[i]);
result = allocate_indirect(&temp, n - 1);
result = allocate_indirect(&temp, n - 1, datablock_num);
if (result < 0)
return result;
if (result == 0) {
@ -63,34 +67,36 @@ int Fs::allocate_indirect(u_int64_t *storage, int n) {
return 1;
}
int Fs::deallocate_datablock(INode_Data *inode_data) {
int Fs::deallocate_datablock(INode_Data *inode_data, u_int64_t *datablock_num) {
int result;
result = deallocate_indirect(&(inode_data->triple_indirect_block), 3);
result = deallocate_indirect(&(inode_data->triple_indirect_block), 3,
datablock_num);
if (result <= 0)
return result;
result = deallocate_indirect(&(inode_data->double_indirect_block), 2);
result = deallocate_indirect(&(inode_data->double_indirect_block), 2,
datablock_num);
if (result <= 0)
return result;
result = deallocate_indirect(&(inode_data->single_indirect_block), 1);
result = deallocate_indirect(&(inode_data->single_indirect_block), 1,
datablock_num);
if (result <= 0)
return result;
for (size_t i = NUMBER_OF_DIRECT_BLOCKS - 1; i >= 0; --i)
if (inode_data->direct_blocks[i] != 0) {
if ((result = datablock_manager->free_datablock(
inode_data->direct_blocks[i])) < 0)
for (size_t i = NUMBER_OF_DIRECT_BLOCKS - 1; i >= 0; --i) {
result =
deallocate_indirect(&(inode_data->direct_blocks[i]), 0, datablock_num);
if (result <= 0)
return result;
inode_data->direct_blocks[i] = 0;
return 0;
}
return -1;
}
int Fs::deallocate_indirect(u_int64_t *storage, int n) {
int Fs::deallocate_indirect(u_int64_t *storage, int n,
u_int64_t *datablock_num) {
char buf[IO_BLOCK_SIZE];
int result;
@ -98,8 +104,10 @@ int Fs::deallocate_indirect(u_int64_t *storage, int n) {
return 1;
if (n == 0) {
u_int64_t temp_datablock_num = (*storage);
if ((result = datablock_manager->free_datablock(*storage)) < 0)
return result;
(*datablock_num) = temp_datablock_num;
(*storage) = 0;
return 0;
}
@ -112,7 +120,7 @@ int Fs::deallocate_indirect(u_int64_t *storage, int n) {
for (size_t i = IO_BLOCK_SIZE - sizeof(u_int64_t); i >= 0;
i -= sizeof(u_int64_t)) {
read_u64(&temp, &buf[i]);
result = deallocate_indirect(&temp, n - 1);
result = deallocate_indirect(&temp, n - 1, datablock_num);
if (result < 0)
return result;
if (result == 0) {

View File

@ -8,13 +8,14 @@ INode_Manager::INode_Manager(Fs *fs, u_int64_t block_segment_start,
}
u_int64_t INode_Manager::get_block_num(u_int64_t inode_num) {
u_int64_t block_num = block_segment_start + (inode_num / INODES_PER_BLOCK);
if (block_num >= block_segment_end)
if (inode_num > max_num_inodes || inode_num == 0)
return 0;
u_int64_t block_num =
block_segment_start + ((inode_num - 1) / INODES_PER_BLOCK);
return block_num;
}
u_int64_t INode_Manager::get_block_offset(u_int64_t inode_num) {
return (inode_num % INODES_PER_BLOCK) * INODE_SIZE;
return ((inode_num - 1) % INODES_PER_BLOCK) * INODE_SIZE;
}
int INode_Manager::load_inode(INode_Data *inode_data) {
@ -117,16 +118,17 @@ int INode_Manager_Freelist::free_inode(INode_Data *inode_data) {
int INode_Manager_Freelist::format() {
char buf[IO_BLOCK_SIZE];
int err;
u_int64_t next_inode_num = 1;
u_int64_t next_inode_num = 2;
for (u_int64_t i = block_segment_start; i < block_segment_end; ++i) {
for (int j = 0; j < INODES_PER_BLOCK; ++next_inode_num, ++j)
for (int j = 0; j < INODES_PER_BLOCK; ++next_inode_num, ++j) {
if (next_inode_num > max_num_inodes)
next_inode_num = 0;
write_u64(next_inode_num, &buf[j * INODE_SIZE]);
}
if ((err = fs->disk->write_block(i, buf)) < 0)
return err;
}
if ((err = fs->save_inode_list_head(0)) < 0)
if ((err = fs->save_inode_list_head(1)) < 0)
return err;
return 0;
}

View File

@ -15,11 +15,12 @@ int main() {
INode_Data inode_data = INode_Data();
fs->inode_manager->new_inode(1, 2, 3, &inode_data);
int err;
u_int64_t block_num = 0;
for (int i = 0; i < 56 + 512 + 4; ++i)
err = fs->allocate_datablock(&inode_data);
err = fs->allocate_datablock(&inode_data, &block_num);
for (int i = 0; i < 5; ++i)
printf("%d\n", err = fs->deallocate_datablock(&inode_data));
printf("%d\n", err = fs->deallocate_datablock(&inode_data, &block_num));
fs->inode_manager->save_inode(&inode_data);

View File

@ -12,7 +12,9 @@ void RawDisk::print_block(u_int64_t block_number) {
printf("\nBlock %llu:\n", block_number);
for (int i = 0; i < IO_BLOCK_SIZE; i += sizeof(u_int64_t)) {
read_u64(&num, &buf[i]);
num = 0;
for (int j = 0; j < 8; j++)
num |= ((u_int64_t)(unsigned char)buf[i + j]) << (8 * j);
printf("%llu ", num);
if ((i / sizeof(u_int64_t)) % nums_per_line == nums_per_line - 1)
printf("\n");

View File

@ -1,23 +1,34 @@
set(TARGET_LAYER0 test_layer0)
set(TARGET_LAYER1_API test_layer1_API)
set(TARGET_LAYER1_TEST1 test_layer1_test1)
# set(TARGET_LAYER1_TEST1 test_layer1_test1)
set(DIR_PLACE /dev/vdb)
# add test sources here ...
add_executable(${TARGET_LAYER0}
# add need lib and source code here
layer0.cpp
../lib/rawdisk.cpp
)
add_executable(${TARGET_LAYER1_API}
# add need lib and source code here
layer1_API.cpp
../lib/fischl.cpp
../lib/rawdisk.cpp
../lib/fs/datablock_manager.cpp
../lib/fs/fs_data_types.cpp
../lib/fs/fs_resize.cpp
../lib/fs/fs.cpp
../lib/fs/inode_manager.cpp
)
add_executable(${TARGET_LAYER1_TEST1}
# add need lib and source code here
layer1_test1.cpp
)
# add_executable(${TARGET_LAYER1_TEST1}
# # add need lib and source code here
# layer1_test1.cpp
# )
# add test to activate ctest -VV
add_test(NAME ${TARGET_LAYER0} COMMAND sudo ./${TARGET_LAYER0} ${DIR_PLACE})
add_test(NAME ${TARGET_LAYER1_API} COMMAND sudo ./${TARGET_LAYER1_API} ${DIR_PLACE})
add_test(NAME ${TARGET_LAYER1_TEST1} COMMAND sudo ./${TARGET_LAYER1_TEST1} ${DIR_PLACE})
# add_test(NAME ${TARGET_LAYER1_TEST1} COMMAND sudo ./${TARGET_LAYER1_TEST1} ${DIR_PLACE})

View File

@ -1,25 +1,28 @@
#include "rawdisk.hpp"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "rawdisk.h"
int main(int argc, char *argv[]) {
const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
const char *d = (argc < 2) ? "/dev/vdc" : argv[1];
RawDisk *H = new RawDisk(d);
RawDisk *H = new RealRawDisk(d);
char *buf = "iloveosdfjlseirfnerig";
char readBuffer[512] = {0}; // Initialize to zeros
char readBuffer[IO_BLOCK_SIZE] = {0}; // Initialize to zeros
//printf("dir %s, numSectors %lld, diskSize %lld \n", H->dir, H->numSectors, H->diskSize);
// printf("dir %s, numSectors %lld, diskSize %lld \n", H->dir, H->numSectors,
// H->diskSize);
//use number to substitute H->getnumSector(), getnumSectors() are not yest implemented
for(u_int64_t i = 0; i < 10; i++) {
H->rawdisk_write(i*512, buf, strlen(buf));//Change write_API
// use number to substitute H->getnumSector(), getnumSectors() are not yest
// implemented
for (u_int64_t i = 0; i < 10; i++) {
H->write_block(i, buf); // Change write_API
}
//use number to substitute H->getnumSector(), getnumSectors() are not yest implemented
for(u_int64_t i = 0; i < 10; i++) {
H->rawdisk_read(i*512, readBuffer, sizeof(readBuffer));//Change read_API
// use number to substitute H->getnumSector(), getnumSectors() are not yest
// implemented
for (u_int64_t i = 0; i < 10; i++) {
H->read_block(i, readBuffer); // Change read_API
assert(strncmp(readBuffer, buf, strlen(buf)) == 0);
}

View File

@ -1,117 +1,143 @@
#include "fs.hpp"
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "fs.h"
#include <inttypes.h>
int main(int argc, char *argv[]) {
const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
// const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
RawDisk *H = new RawDisk(d);
RawDisk *H = new FakeRawDisk(2048);
Fs *fs = new Fs(H);
printf("test inode\n");
INodeOperation inop;
inop.initialize(*H);//for inode initialization and datablock initialization
char buffer[8] = {0};
/**************************test inode Initialization***************************/
//test the begining of inode 1th
H->rawdisk_read((1) * SECTOR_SIZE, buffer, sizeof(buffer));
fs->format();
char buffer[IO_BLOCK_SIZE] = {0};
/**************************test inode
* Initialization***************************/
// test the begining of inode 1th
H->read_block(1, buffer);
u_int64_t t = 0;
for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == 2);//the first 1th unused inode will store the next unused inode 2th
//test the number before end of inode 524286th
H->rawdisk_read((MAX_INODE - 2) * SECTOR_SIZE, buffer, sizeof(buffer));
assert(t ==
2); // the first 1th unused inode will store the next unused inode 2th
assert(IO_BLOCK_SIZE == 4096);
assert(INODE_SIZE == 512);
// test the number before end of inode
H->read_block(NUM_INODE_BLOCKS, buffer);
t = 0;
for (int j = 0; j < 8; j++)
t |=
((u_int64_t)(unsigned char)buffer[j + IO_BLOCK_SIZE - (INODE_SIZE * 2)])
<< (8 * j);
assert(t == NUM_INODE_BLOCKS *
(IO_BLOCK_SIZE / INODE_SIZE)); // store the maximun th inode
// test the end of inode
t = 0;
for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j + IO_BLOCK_SIZE - INODE_SIZE])
<< (8 * j);
assert(
t ==
0); // the end of inode(524287th inode) do not have the next inode address
/**************************test datablock
* Initialization***************************/
// 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->read_block(NUM_INODE_BLOCKS + 1,
buffer); // the begining of free datablock will store
// from address (MAX_INODE) * SECTOR_SIZE
t = 0;
for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == MAX_INODE - 1);//store the maximun th inode
//test the end of inode 524287th
H->rawdisk_read((MAX_INODE - 1) * SECTOR_SIZE, buffer, sizeof(buffer));
assert(t == NUM_INODE_BLOCKS + 1 + DATABLOCKS_PER_BITMAP_BLOCK +
1); // 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
H->read_block(NUM_BLOCKS - DATABLOCKS_PER_BITMAP_BLOCK - 1, buffer);
t = 0;
for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == 0);//the end of inode(524287th inode) do not have the next inode address
/**************************test datablock Initialization***************************/
//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;
for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == NUM_BLOCKS - DATABLOCKS_PER_BITMAP_BLOCK - 1);
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
H->rawdisk_read((MAX_BLOCKNUM - 2048*8) * SECTOR_SIZE, buffer, sizeof(buffer));
t = 0;
for (int j = 0; j < 8; j++)
t |= ((u_int64_t)(unsigned char)buffer[j]) << (8 * j);
assert(t == (MAX_BLOCKNUM)*SECTOR_SIZE);
/***************************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 record_free[10] = {0};//should do a pop up structure to record the free inode
/***************************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
INode_Data inode_list[20];
u_int64_t 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++){
inode_list[i] = inop.inode_allocate(*H);
assert(inode_list[i] == i+1);
//printf(" %d", inode_list[i]);
// printf("Allocate 20 inode num:{");
for (int i = 0; i < 20; i++) {
fs->inode_manager->new_inode(0, 0, 0, &inode_list[i]);
assert(inode_list[i].inode_num == i + 1);
// printf(" %d", inode_list[i].inode_num);
}
//printf("}\n");
for(int i=10;i<20;i++){
inop.inode_free(*H,inode_list[i]);//free the 10 element from inode_list[10]
record_free[i-10] = inode_list[i];
// printf("}\n");
for (int i = 10; i < 20; i++) {
record_free[i - 10] = inode_list[i].inode_num;
fs->inode_manager->free_inode(
&inode_list[i]); // free the 10 element from inode_list[10]
}
//allocate again the last 10
// allocate again the last 10
printf("Allocate again: inode num:{");
for(int i=10;i<20;i++){
inode_list[i] = inop.inode_allocate(*H);
//printf("inode %d, rec_f %d\n,", inode_list[i],record_free[rec]);
assert(inode_list[i] == record_free[rec]);
for (int i = 10; i < 20; i++) {
fs->inode_manager->new_inode(0, 0, 0, &inode_list[i]);
// printf("inode %d, rec_f %d\n,", inode_list[i],record_free[rec]);
assert(inode_list[i].inode_num == record_free[rec]);
rec--;
}
printf("}\n");
/***************************test direct blocks[48] de/allocation**********************************/
//after free the datablock, the program will find the first smallest address of datablock to give to the inode
//should test random resize each node, but should use datablock_free data structure to record
INode inode_inside[10];
u_int64_t rec_datablock_free[10][3] = {0};//array version
for(int i=0;i<10;i++){
inode_inside[i].inode_construct(inode_list[i],*H);
//printf("%dth data block starting addres: ", i);
for(int j=0;j<6;j++){
inode_inside[i].datablock_allocate(*H);
//printf("%d," ,inode_inside[i].datablock_allocate(*H));
/***************************test direct blocks[48]
* de/allocation**********************************/
// after free the datablock, the program will find the first smallest address
// of datablock to give to the inode should test random resize each node, but
// should use datablock_free data structure to record
u_int64_t rec_datablock_free[10][3] = {0}; // array version
u_int64_t temp_block_num = 0;
for (int i = 0; i < 10; i++) {
// printf("%dth data block starting addres: ", i);
for (int j = 0; j < 6; j++) {
fs->allocate_datablock(&inode_list[i], &temp_block_num);
// printf("%d," ,inode_inside[i].datablock_allocate(*H));
}
//printf("\n");
// printf("\n");
}
for(int i=0;i<10;i++){
//printf("%dth data block free addres: ", i);
for(int j = 2;j >=0;j--){
rec_datablock_free[i][j] = inode_inside[i].datablock_deallocate(*H);
//printf("", rec_datablock_free[i][j]);
for (int i = 0; i < 10; i++) {
// printf("%dth data block free addres: ", i);
for (int j = 2; j >= 0; j--) {
fs->deallocate_datablock(&inode_list[i], &(rec_datablock_free[i][j]));
// 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++){
assert(inode_inside[i].datablock_allocate(*H) == rec_datablock_free[i][j]);
//printf("%d," ,inode_inside[i].datablock_allocate(*H));
for (int i = 0; i < 10; i++) {
// printf("%dth data block allocate again addres: ", i);
for (int j = 0; j < 3; j++) {
fs->allocate_datablock(&inode_list[i], &temp_block_num);
assert(temp_block_num == rec_datablock_free[i][j]);
// printf("%d," ,inode_inside[i].datablock_allocate(*H));
}
//printf("\n");
// printf("\n");
}
//printf("}\n");
// printf("}\n");
delete H; // Delete the RawDisk object
return 0;

View File

@ -1,113 +1,130 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "fs.h"
#include <inttypes.h>
// #include "fs.h"
// #include <assert.h>
// #include <inttypes.h>
// #include <stdio.h>
// #include <string.h>
// in fs.h:
// #define MAX_INODE 2048
// #define MAX_BLOCKNUM 51200
// 51200 Sectors = 2048 * 25 Sectors = 25MB
// Free List Heads: 2048*512, 2048*9*512, 2048*17*512
// Available INodes: 2047 (-1 because superblock)
// Available DataBlocks (including Indirect Blocks): 2047 * 3 = 6141
// // in fs.h:
// // #define MAX_INODE 2048
// // #define MAX_BLOCKNUM 51200
// // 51200 Sectors = 2048 * 25 Sectors = 25MB
// // Free List Heads: 2048*512, 2048*9*512, 2048*17*512
// // Available INodes: 2047 (-1 because superblock)
// // Available DataBlocks (including Indirect Blocks): 2047 * 3 = 6141
int main(int argc, char *argv[]) {
const char* d = (argc < 2) ? "/dev/vdc" : argv[1];
// int main(int argc, char *argv[]) {
// const char *d = (argc < 2) ? "/dev/vdc" : argv[1];
RawDisk *H = new RawDisk(d);
// RawDisk *H = new FakeRawDisk(d);
printf("=== INode Alloc/Dealloc Test ===\n");
INodeOperation inop;
inop.initialize(*H);
// printf("=== INode Alloc/Dealloc Test ===\n");
// INodeOperation inop;
// inop.initialize(*H);
// Test INode alloc and dealloc
int inode_list[2046] = {0}; // if we allocate 2047 inodes head will be 0 (faulty)
printf("freeInodeHead: %d \n", SuperBlock::getFreeINodeHead(*H)); // this impl should give 1
for(int i=0;i<2046;i++){
inode_list[i] = inop.inode_allocate(*H);
if (SuperBlock::getFreeINodeHead(*H) == 0) {
printf("%d\n",i);
assert(false);
}
}
printf("freeInodeHead: %d \n", SuperBlock::getFreeINodeHead(*H)); // this impl should give 2047
for(int i=0;i<1024;i++){
inop.inode_free(*H,inode_list[i]);
}
for(int i=0;i<1022;i++){
inode_list[i] = inop.inode_allocate(*H);
assert(SuperBlock::getFreeINodeHead(*H) != 0);
}
printf("freeInodeHead: %d \n", SuperBlock::getFreeINodeHead(*H)); // this impl should give 2
inode_list[1022] = inop.inode_allocate(*H);
printf("freeInodeHead: %d \n", SuperBlock::getFreeINodeHead(*H)); // this impl should give 1
inode_list[1023] = inop.inode_allocate(*H);
printf("freeInodeHead: %d \n", SuperBlock::getFreeINodeHead(*H)); // this impl should give 2047
// // Test INode alloc and dealloc
// int inode_list[2046] = {
// 0}; // if we allocate 2047 inodes head will be 0 (faulty)
// printf("freeInodeHead: %d \n",
// SuperBlock::getFreeINodeHead(*H)); // this impl should give 1
// for (int i = 0; i < 2046; i++) {
// inode_list[i] = inop.inode_allocate(*H);
// if (SuperBlock::getFreeINodeHead(*H) == 0) {
// printf("%d\n", i);
// assert(false);
// }
// }
// printf("freeInodeHead: %d \n",
// SuperBlock::getFreeINodeHead(*H)); // this impl should give 2047
// for (int i = 0; i < 1024; i++) {
// inop.inode_free(*H, inode_list[i]);
// }
// for (int i = 0; i < 1022; i++) {
// inode_list[i] = inop.inode_allocate(*H);
// assert(SuperBlock::getFreeINodeHead(*H) != 0);
// }
// printf("freeInodeHead: %d \n",
// SuperBlock::getFreeINodeHead(*H)); // this impl should give 2
// inode_list[1022] = inop.inode_allocate(*H);
// printf("freeInodeHead: %d \n",
// SuperBlock::getFreeINodeHead(*H)); // this impl should give 1
// inode_list[1023] = inop.inode_allocate(*H);
// printf("freeInodeHead: %d \n",
// SuperBlock::getFreeINodeHead(*H)); // this impl should give 2047
// Test Many Files
printf("=== Many Files Test ===\n");
INode inode_inside[100];
for(int i=0;i<100;i++){
inode_inside[i].inode_construct(inode_list[i],*H);
for(int j=0;j<60;j++) { // Note that 1 indirect block is used for each file
u_int64_t allcBlockNum = inode_inside[i].datablock_allocate(*H);
if (SuperBlock::getFreeListHead(*H) >= (u_int64_t) 51200*512) {
printf("Bad FreeListHead: %d, %d, %llu\n", i, j, SuperBlock::getFreeListHead(*H));
assert(false);
}
if (allcBlockNum % 2048 != 0 || allcBlockNum < 2048*512 || allcBlockNum >= 25*2048*512) {
printf("Bad Allocated Block Number: %d, %d, %llu\n", i, j, allcBlockNum);
assert(false);
}
}
}
printf("Finished Allocating\n");
// in this impl should give 17*2048*512 = 17825792
printf("freeListHead: %llu \n", SuperBlock::getFreeListHead(*H)); // if all 6141 blocks allocated, would give 51200*512 (faulty)
for(int i=0;i<100;i++){
for(int j=0;j<59;j++){
u_int64_t freedBlkNum = inode_inside[i].datablock_deallocate(*H);
u_int64_t fh = SuperBlock::getFreeListHead(*H);
if (freedBlkNum % 2048 != 0 || freedBlkNum < 2048*512 || freedBlkNum >= 25*2048*512 || fh >= 51200*512) {
printf("%d, %d, Freed Block Number: %llu\n", i, j, freedBlkNum);
printf("FreeListHead is %llu\n", fh);
assert(false);
}
}
}
printf("Finished Deallocating\n");
printf("freeListHead: %d \n", SuperBlock::getFreeListHead(*H));
// // Test Many Files
// printf("=== Many Files Test ===\n");
// INode inode_inside[100];
// for (int i = 0; i < 100; i++) {
// inode_inside[i].inode_construct(inode_list[i], *H);
// for (int j = 0; j < 60;
// j++) { // Note that 1 indirect block is used for each file
// u_int64_t allcBlockNum = inode_inside[i].datablock_allocate(*H);
// if (SuperBlock::getFreeListHead(*H) >= (u_int64_t)51200 * 512) {
// printf("Bad FreeListHead: %d, %d, %llu\n", i, j,
// SuperBlock::getFreeListHead(*H));
// assert(false);
// }
// if (allcBlockNum % 2048 != 0 || allcBlockNum < 2048 * 512 ||
// allcBlockNum >= 25 * 2048 * 512) {
// printf("Bad Allocated Block Number: %d, %d, %llu\n", i, j,
// allcBlockNum);
// assert(false);
// }
// }
// }
// printf("Finished Allocating\n");
// // in this impl should give 17*2048*512 = 17825792
// printf(
// "freeListHead: %llu \n",
// SuperBlock::getFreeListHead(
// *H)); // if all 6141 blocks allocated, would give 51200*512
// (faulty)
// for (int i = 0; i < 100; i++) {
// for (int j = 0; j < 59; j++) {
// u_int64_t freedBlkNum = inode_inside[i].datablock_deallocate(*H);
// u_int64_t fh = SuperBlock::getFreeListHead(*H);
// if (freedBlkNum % 2048 != 0 || freedBlkNum < 2048 * 512 ||
// freedBlkNum >= 25 * 2048 * 512 || fh >= 51200 * 512) {
// printf("%d, %d, Freed Block Number: %llu\n", i, j, freedBlkNum);
// printf("FreeListHead is %llu\n", fh);
// assert(false);
// }
// }
// }
// printf("Finished Deallocating\n");
// printf("freeListHead: %d \n", SuperBlock::getFreeListHead(*H));
// Test Big File (Use direct, single indirect, double indirect)
printf("=== Big File Test ===\n");
u_int64_t lastAllc = 0;
for(int j=0;j<5000;j++){
u_int64_t allcBlockNum = inode_inside[0].datablock_allocate(*H);
lastAllc = allcBlockNum;
u_int64_t fh = SuperBlock::getFreeListHead(*H);
if (allcBlockNum % 2048 != 0 || allcBlockNum < 2048*512 || allcBlockNum >= 25*2048*512 || fh >= 51200*512) {
printf("%d, Alloc Block Number: %llu\n", j, allcBlockNum);
printf("FreeListHead is %llu\n", fh);
assert(false);
}
}
printf("last allocate for big file: %llu\n", lastAllc);
printf("Finished Allocating\n");
printf("freeListHead: %d \n", SuperBlock::getFreeListHead(*H));
for(int j=0;j<5000;j++){
u_int64_t freedBlkNum = inode_inside[0].datablock_deallocate(*H);
u_int64_t fh = SuperBlock::getFreeListHead(*H);
if (freedBlkNum % 2048 != 0 || freedBlkNum < 2048*512 || freedBlkNum >= 25*2048*512 || fh >= 51200*512) {
printf("%d, Freed Block Number: %llu\n", j, freedBlkNum);
printf("FreeListHead is %llu\n", fh);
assert(false);
}
}
printf("Finished Deallocating\n");
printf("freeListHead: %d \n", SuperBlock::getFreeListHead(*H));
// // Test Big File (Use direct, single indirect, double indirect)
// printf("=== Big File Test ===\n");
// u_int64_t lastAllc = 0;
// for (int j = 0; j < 5000; j++) {
// u_int64_t allcBlockNum = inode_inside[0].datablock_allocate(*H);
// lastAllc = allcBlockNum;
// u_int64_t fh = SuperBlock::getFreeListHead(*H);
// if (allcBlockNum % 2048 != 0 || allcBlockNum < 2048 * 512 ||
// allcBlockNum >= 25 * 2048 * 512 || fh >= 51200 * 512) {
// printf("%d, Alloc Block Number: %llu\n", j, allcBlockNum);
// printf("FreeListHead is %llu\n", fh);
// assert(false);
// }
// }
// printf("last allocate for big file: %llu\n", lastAllc);
// printf("Finished Allocating\n");
// printf("freeListHead: %d \n", SuperBlock::getFreeListHead(*H));
// for (int j = 0; j < 5000; j++) {
// u_int64_t freedBlkNum = inode_inside[0].datablock_deallocate(*H);
// u_int64_t fh = SuperBlock::getFreeListHead(*H);
// if (freedBlkNum % 2048 != 0 || freedBlkNum < 2048 * 512 ||
// freedBlkNum >= 25 * 2048 * 512 || fh >= 51200 * 512) {
// printf("%d, Freed Block Number: %llu\n", j, freedBlkNum);
// printf("FreeListHead is %llu\n", fh);
// assert(false);
// }
// }
// printf("Finished Deallocating\n");
// printf("freeListHead: %d \n", SuperBlock::getFreeListHead(*H));
delete H; // Delete the RawDisk object
// delete H; // Delete the RawDisk object
return 0;
}
// return 0;
// }