/* * Hard codes the following directory structure: * root * foo1 50 (Directory block 0) - NOTE: no actual directory file created * foo2 60,70 (Directory block 1) * bar1 80 (Directory block 1_1) * hello.txt 100 (File block 1) */ void test_file_operations_setup() { size_of_disk = dev_open(); if (size_of_disk != 250000) { printf("\ntest_file_operations_setup FAIL. Size of disk must be 250,000 blocks.\n"); } my_mkfs(); // Zero out buffers char buffer[BLOCKSIZE]; char *buffer_ptr = buffer; char name[MAX_FILE_NAME_LENGTH]; /** ROOT BLOCK **/ unsigned short bytes_allocated = HEADER_SIZE + 2 * FILE_NUM_PAIRINGS_SIZE; populate_file_header(buffer, ROOT_BLOCK, bytes_allocated, 'd'); // Set directory one name and block number memset(name, 0, MAX_FILE_NAME_LENGTH); strcpy(name, "foo1"); buffer_ptr += HEADER_SIZE; memcpy(buffer_ptr, name, MAX_FILE_NAME_LENGTH); unsigned int block_num = DIRECTORY_BLOCK_0; buffer_ptr += MAX_FILE_NAME_LENGTH; memcpy(buffer_ptr, &block_num, BYTES_IN_INT); // Set directory two name and block number memset(name, 0, MAX_FILE_NAME_LENGTH); buffer_ptr += BYTES_IN_INT; strcpy(name, "foo2"); memcpy(buffer_ptr, name, MAX_FILE_NAME_LENGTH); block_num = DIRECTORY_BLOCK_1; buffer_ptr += MAX_FILE_NAME_LENGTH; memcpy(buffer_ptr, &block_num, BYTES_IN_INT); write_block(ROOT_BLOCK, buffer); setBlockInBitmapToStatus (1, ROOT_BLOCK); /** DIRECTORY 1 **/ bytes_allocated = HEADER_SIZE + 1 * FILE_NUM_PAIRINGS_SIZE; populate_file_header(buffer, DIRECTORY_BLOCK_1_NEXT_BLOCK, bytes_allocated, 'd'); // Set directory one name and block number memset(name, 0, MAX_FILE_NAME_LENGTH); strcpy(name, "bar1"); buffer_ptr = buffer; buffer_ptr += HEADER_SIZE; memcpy(buffer_ptr, name, MAX_FILE_NAME_LENGTH); block_num = DIRECTORY_BLOCK_1_1; buffer_ptr += MAX_FILE_NAME_LENGTH; memcpy(buffer_ptr, &block_num, BYTES_IN_INT); write_block(DIRECTORY_BLOCK_1, buffer); setBlockInBitmapToStatus (1, DIRECTORY_BLOCK_1); /** DIRECTORY 1_NEXT_BLOCK **/ bytes_allocated = HEADER_SIZE + 1 * FILE_NUM_PAIRINGS_SIZE; populate_file_header(buffer, ROOT_BLOCK, bytes_allocated, 'd'); // Set directory one name and block number memset(name, 0, MAX_FILE_NAME_LENGTH); strcpy(name, "hello.txt"); buffer_ptr = buffer; buffer_ptr += HEADER_SIZE; memcpy(buffer_ptr, name, MAX_FILE_NAME_LENGTH); block_num = FILE_BLOCK_1; buffer_ptr += MAX_FILE_NAME_LENGTH; memcpy(buffer_ptr, &block_num, BYTES_IN_INT); write_block(DIRECTORY_BLOCK_1_NEXT_BLOCK, buffer); setBlockInBitmapToStatus (1, DIRECTORY_BLOCK_1_NEXT_BLOCK); /** DIRECTORY 1_1 **/ bytes_allocated = HEADER_SIZE; populate_file_header(buffer, ROOT_BLOCK, bytes_allocated, 'd'); // Set directory one name and block number write_block(DIRECTORY_BLOCK_1_1, buffer); setBlockInBitmapToStatus (1, DIRECTORY_BLOCK_1_1); }
int main (int argc, char ** argv) { set_time(0xaaaaaaaa); my_mkfs (); }