diff --git a/Makefile b/Makefile index 3babbff..61cc0ed 100644 --- a/Makefile +++ b/Makefile @@ -11,12 +11,12 @@ CFLAGS = -O0 -g -Wall -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=25 LIBS := fuse LIBS := $(addprefix -l,$(LIBS)) -all: tfs +all: lsfs_fuse %.o: %.c .always_rebuilt $(GCC) $(CFLAGS) -c -o $@ $< -tfs: $(OBJS) .always_rebuilt +lsfs_fuse: $(OBJS) .always_rebuilt $(GCC) $(OBJS) $(LIBS) $(CFLAGS) -o lsfs_fuse clean: diff --git a/lsfs_disk_controller.h b/lsfs_disk_controller.h index 7fba263..cd029d8 100644 --- a/lsfs_disk_controller.h +++ b/lsfs_disk_controller.h @@ -11,7 +11,7 @@ #include typedef struct struct_partition_control partition_control; -typedef struct struct_global_tag global_tag; +typedef struct struct_table_entry table_entry; typedef struct struct_partition_control partition_control; typedef struct File_System_Control_Information FSCI; typedef struct meta_information_format mif; @@ -19,23 +19,22 @@ typedef struct tag_record tag_record; typedef uint64_t lsfs_sector_offset; typedef lsfs_sector_offset lsfs_file_id; -typedef lsfs_sector_offset lsfs_tag_id; //typedef uint64_t sector_index; static FILE* disk; -static partition_control p_control; // used for debugging +static partition_control p_control; int create_file_system(); -lsfs_sector_offset lsfs_disk_create_tag(char* tag_name, bool is_filename); -lsfs_sector_offset lsfs_disk_create_file(char* filename, lsfs_tag_id* tags, void* file_data); -int lsfs_disk_untag_file(lsfs_tag_id tag_id, lsfs_file_id file_id); -int lsfs_disk_tag_file(lsfs_tag_id tag_id, lsfs_file_id file_id); -int lsfs_disk_delete_tag(lsfs_tag_id tag_id); +//lsfs_sector_offset lsfs_disk_create_tag(char* tag_name, bool is_filename); +lsfs_sector_offset lsfs_disk_create_file(char* filename, lsfs_file_id* tags, void* file_data); +//int lsfs_disk_untag_file(lsfs_file_id file_id, lsfs_file_id file_id); +//int lsfs_disk_tag_file(lsfs_file_id file_id, lsfs_file_id file_id); +//int lsfs_disk_delete_tag(lsfs_file_id file_id); int lsfs_disk_delete_file(lsfs_file_id file_id); int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array); int lsfs_disk_read_data_from_file(lsfs_file_id file_id, int buffer_size, void* buffer_for_data); int lsfs_disk_write_data_to_file(lsfs_file_id file_id, int data_length, char *data); -int lsfs_disk_rename_tag(lsfs_file_id file_id, char* new_tagname); +//int lsfs_disk_rename_tag(lsfs_file_id file_id, char* new_filename); int lsfs_disk_rename_file(lsfs_file_id file_id, const char* new_filename); int lsfs_disk_load_disk(); int write_data_to_disk(lsfs_sector_offset at_sector, void* data_to_write); @@ -43,21 +42,21 @@ int read_data_from_disk(lsfs_sector_offset index, void* data_buffer); int write_data_to_disk_off(lsfs_sector_offset index, void* data_to_write, int offset); -#define SECTOR_SIZE 4096 -#define DEFAULT_FILE_SIZE 1 // This is in sectors -#define DEFAULT_MASTER_TAG_TABLE_SIZE 3855 // correspond to 1 MiB in sectors 3855 * 57825 +#define SECTOR_SIZE 512 +#define DEFAULT_FILE_SIZE 4 // This is in sectors +#define DEFAULT_MASTER_TABLE_SIZE 64 #define DEFAULT_TAG_TABLE_SIZE 64 // correspond to 262144 bytes in sectors - 16384 files pr. default. (minus one, the last is a pointer to a table more ) #define MAX_MASTER_TAGS 57825 #define MAX_TAGS_IN_TAG_TABLE 16384 #define MAX_TAGS_FOR_A_FILE 32 +#define NUM_DATA_POINTERS 28 -#define MAX_NUM_ONE_LEVEL_DATA 256 // First Mib of a file. -#define MAX_NUM_TWO_LEVEL_DATA 94 // First Mib of a file. -#define MAX_NUM_THREE_LEVEL_DATA 94 // First Mib of a file. +//#define MAX_NUM_TWO_LEVEL_DATA 94 // First Mib of a file. +//#define MAX_NUM_THREE_LEVEL_DATA 94 // First Mib of a file. typedef struct struct_partition_control{ FSCI* fsci; - global_tag* master_table; + table_entry* master_table; } __attribute__((packed)) partition_control; typedef struct File_System_Control_Information { @@ -71,24 +70,22 @@ typedef struct File_System_Control_Information { uint64_t master_tag_records[16]; } __attribute__((packed)) FSCI; -typedef struct struct_global_tag { - /* SizeOf this = - * tagname - * address - * control_bits - */ - char tagname[256]; - lsfs_tag_id tag_table_index; +typedef struct struct_table_entry { + char filename[256]; + lsfs_file_id tag_table_index; + uint64_t file_size; + mif* ext_file_data; struct { uint64_t is_filename : 1; } control_bits; -} __attribute__((packed)) global_tag; + lsfs_sector_offset data_pointer[NUM_DATA_POINTERS] +} __attribute__((packed)) table_entry; typedef struct meta_information_format { char filename[246]; // remeber that the 246 bytes has to be a /0 terminator.. uint32_t owner_id; - lsfs_tag_id tags[32]; + lsfs_file_id tags[32]; uint64_t file_size; uint32_t control_bits; /* not pressent - Permission key table 64 bytes sha-265 pr. key*/ @@ -100,7 +97,7 @@ typedef struct meta_information_format { * 94 next pointers is a pointer * 94 next pointers to pointers to data */ - lsfs_sector_offset one_level_pointer_data[MAX_NUM_ONE_LEVEL_DATA]; + lsfs_sector_offset one_level_pointer_data[NUM_DATA_POINTERS]; lsfs_sector_offset two_level_pointer_data[94]; lsfs_sector_offset three_level_pointer_data[94]; @@ -122,7 +119,7 @@ int lsfs_disk_read_data_from_file(lsfs_file_id file_id, int buffer_size, void* b mif* mif_record = calloc(1, SECTOR_SIZE); read_data_from_disk(file_id, mif_record); int return_val = 0; - for (int i = 0; i < MAX_NUM_ONE_LEVEL_DATA; ++i) { + for (int i = 0; i < NUM_DATA_POINTERS; ++i) { if(mif_record->one_level_pointer_data[i] == 0) { break; } @@ -167,7 +164,7 @@ int lsfs_disk_write_data_to_file(lsfs_file_id file_id, int data_length, char *da } for (;;) { - assert(current_sector <= MAX_NUM_ONE_LEVEL_DATA); + assert(current_sector <= NUM_DATA_POINTERS); write_data_to_disk(mif_record.one_level_pointer_data[current_sector++], tmp_buffer); if (data_length <= 0) break; @@ -203,12 +200,12 @@ time_t lsfs_disk_truncate_file(lsfs_file_id file_id) { return result; } -int lsfs_disk_rename_tag(lsfs_tag_id tag_id, char* new_tagname) { +int lsfs_disk_rename_tag(lsfs_file_id file_id, char* new_filename) { for (int i = 0; i < MAX_MASTER_TAGS; ++i) { - if(p_control.mtt_tags[i].tag_table_index == tag_id) { - memset(p_control.mtt_tags[i].tagname, 0, sizeof(p_control.mtt_tags[i].tagname)); - sprintf(p_control.mtt_tags[i].tagname, "%s", new_tagname); + if(p_control.master_table[i].tag_table_index == file_id) { + memset(p_control.master_table[i].filename, 0, sizeof(p_control.master_table[i].filename)); + sprintf(p_control.master_table[i].filename, "%s", new_filename); break; } } @@ -216,7 +213,7 @@ int lsfs_disk_rename_tag(lsfs_tag_id tag_id, char* new_tagname) { // Save the changes to disk fseek ( disk , (p_control.fsci->master_tag_records[0] * SECTOR_SIZE) , SEEK_SET ); - fwrite(p_control.mtt_tags, 1, sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE, disk); + fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk); return 1; } @@ -247,7 +244,7 @@ int lsfs_disk_delete_file(lsfs_file_id file_id) { if(mif_record->tags[i] == 0) { break; } - lsfs_disk_untag_file(mif_record->tags[i], file_id); + //lsfs_disk_untag_file(mif_record->tags[i], file_id); } // TODO Delete/free all data sectors. // Delete/free the mif record sector. @@ -256,16 +253,16 @@ int lsfs_disk_delete_file(lsfs_file_id file_id) { return 1; } -int lsfs_disk_delete_tag(lsfs_tag_id tag_id) { +/*int lsfs_disk_delete_tag(lsfs_file_id file_id) { tag_record* tag_table = calloc(64, SECTOR_SIZE); - read_data_from_disk(tag_id, tag_table); + read_data_from_disk(file_id, tag_table); for (int i = 0; i < MAX_TAGS_IN_TAG_TABLE; ++i) { if(tag_table[i].mif_record == 0) { break; } - lsfs_disk_untag_file(tag_id, tag_table[i].mif_record); + lsfs_disk_untag_file(file_id, tag_table[i].mif_record); } @@ -273,14 +270,14 @@ int lsfs_disk_delete_tag(lsfs_tag_id tag_id) { for (int i = 0; i < MAX_MASTER_TAGS; ++i) { - if(p_control.mtt_tags[i].tag_table_index == tag_id) { - p_control.mtt_tags[i] = p_control.mtt_tags[i+1]; + if(p_control.master_table[i].tag_table_index == file_id) { + p_control.master_table[i] = p_control.master_table[i+1]; truncate_table = 1; - printf("Tag deleted from master table - TagID: %lu\n", tag_id); + printf("Tag deleted from master table - TagID: %lu\n", file_id); } else if (truncate_table) { - p_control.mtt_tags[i] = p_control.mtt_tags[i+1]; - if (p_control.mtt_tags[i+1].tag_table_index == 0) { + p_control.master_table[i] = p_control.master_table[i+1]; + if (p_control.master_table[i+1].tag_table_index == 0) { break; } } @@ -289,19 +286,19 @@ int lsfs_disk_delete_tag(lsfs_tag_id tag_id) { // Save the changes to disk fseek ( disk , (p_control.fsci->master_tag_records[0] * SECTOR_SIZE) , SEEK_SET ); - fwrite(p_control.mtt_tags, 1, sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE, disk); + fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk); free(tag_table); return 1; -} +}*/ -int lsfs_disk_tag_file(lsfs_tag_id tag_id, lsfs_file_id file_id) { +/*int lsfs_disk_tag_file(lsfs_file_id file_id, lsfs_file_id file_id) { mif* mif_record = calloc(1, SECTOR_SIZE); read_data_from_disk(file_id, mif_record); for (int i = 0; i < MAX_TAGS_FOR_A_FILE; ++i) { if(mif_record->tags[i] == 0) { - mif_record->tags[i] = tag_id; + mif_record->tags[i] = file_id; break; } } @@ -309,7 +306,7 @@ int lsfs_disk_tag_file(lsfs_tag_id tag_id, lsfs_file_id file_id) { free(mif_record); tag_record* tag_table = calloc(64, SECTOR_SIZE); - read_data_from_disk(tag_id, tag_table); + read_data_from_disk(file_id, tag_table); for (int i = 0; i < MAX_TAGS_IN_TAG_TABLE; ++i) { @@ -319,22 +316,23 @@ int lsfs_disk_tag_file(lsfs_tag_id tag_id, lsfs_file_id file_id) { break; } } - write_data_to_disk(tag_id, tag_table); + write_data_to_disk(file_id, tag_table); free(tag_table); return 1; } +*/ -int lsfs_disk_untag_file(lsfs_tag_id tag_id, lsfs_file_id file_id) { +/*int lsfs_disk_untag_file(lsfs_file_id file_id, lsfs_file_id file_id) { mif* mif_record = calloc(1, SECTOR_SIZE); read_data_from_disk(file_id, mif_record); int truncate_table = 0; for (int i = 0; i < MAX_TAGS_FOR_A_FILE; ++i) { - if(mif_record->tags[i] == tag_id) { + if(mif_record->tags[i] == file_id) { mif_record->tags[i] = mif_record->tags[i+1]; truncate_table = 1; - printf("file untagged - TagID: %lu - FileID: %lu \n", tag_id, file_id); + printf("file untagged - TagID: %lu - FileID: %lu \n", file_id, file_id); } else if (truncate_table) { mif_record->tags[i] = mif_record->tags[i+1]; @@ -354,7 +352,7 @@ int lsfs_disk_untag_file(lsfs_tag_id tag_id, lsfs_file_id file_id) { free(mif_record); tag_record* tag_table = calloc(64, SECTOR_SIZE); - read_data_from_disk(tag_id, tag_table); + read_data_from_disk(file_id, tag_table); truncate_table = 0; for (int i = 0; i < MAX_TAGS_IN_TAG_TABLE; ++i) @@ -371,30 +369,30 @@ int lsfs_disk_untag_file(lsfs_tag_id tag_id, lsfs_file_id file_id) { } } } - write_data_to_disk(tag_id, tag_table); + write_data_to_disk(file_id, tag_table); free(tag_table); return 1; -} +}*/ -lsfs_tag_id lsfs_disk_create_tag(char* tag_name, bool is_filename) { - /* Return ID of new tag, oterwise return 0 */ - lsfs_tag_id* free_sectors; +/*lsfs_file_id lsfs_disk_create_tag(char* tag_name, bool is_filename) { + // Return ID of new tag, oterwise return 0 + lsfs_file_id* free_sectors; // Returns an array, with the sector numbers that is assignt to you - free_sectors = calloc(DEFAULT_TAG_TABLE_SIZE, sizeof(lsfs_tag_id)); + free_sectors = calloc(DEFAULT_TAG_TABLE_SIZE, sizeof(lsfs_file_id)); get_free_sectors(DEFAULT_TAG_TABLE_SIZE, free_sectors); // has to be freed // Insert tag in the master tag, table an set the pointer to the first of the tag table int index_in_mtt = 0; - while(p_control.mtt_tags[index_in_mtt].tag_table_index != 0) { + while(p_control.master_table[index_in_mtt].tag_table_index != 0) { //TODO also have to count if we enter next data section. index_in_mtt++; } - p_control.mtt_tags[index_in_mtt].tag_table_index = free_sectors[0]; + p_control.master_table[index_in_mtt].tag_table_index = free_sectors[0]; printf("%lu\n", free_sectors[0]); - sprintf(p_control.mtt_tags[index_in_mtt].tagname, "%s", tag_name); - p_control.mtt_tags[index_in_mtt].control_bits.is_filename = is_filename; + sprintf(p_control.master_table[index_in_mtt].filename, "%s", tag_name); + p_control.master_table[index_in_mtt].control_bits.is_filename = is_filename; tag_record new_tag[DEFAULT_TAG_TABLE_SIZE]; memset(new_tag, 0, (DEFAULT_TAG_TABLE_SIZE * sizeof(tag_record))); @@ -403,7 +401,7 @@ lsfs_tag_id lsfs_disk_create_tag(char* tag_name, bool is_filename) { //char* data = "red_file_1\nred_file_2\n"; //char* sector_to_write = write_mechanism_new_buffer(data); fseek ( disk , (p_control.fsci->master_tag_records[0] * SECTOR_SIZE) , SEEK_SET ); - fwrite(p_control.mtt_tags, 1, sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE, disk); + fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk); fseek ( disk , ((*free_sectors) * SECTOR_SIZE) , SEEK_SET ); fwrite(new_tag, 1, DEFAULT_TAG_TABLE_SIZE * sizeof(tag_record), disk); @@ -413,6 +411,7 @@ lsfs_tag_id lsfs_disk_create_tag(char* tag_name, bool is_filename) { free(free_sectors); return return_value; } +*/ int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) { /* @@ -462,10 +461,10 @@ int create_file_system() { free(zero_buffer); /* MASTER TAG TABLE */ - global_tag mtt_tags[DEFAULT_MASTER_TAG_TABLE_SIZE]; - memset(mtt_tags, 0, (DEFAULT_MASTER_TAG_TABLE_SIZE * sizeof(global_tag))); + table_entry master_table[DEFAULT_MASTER_TABLE_SIZE]; + memset(master_table, 0, (DEFAULT_MASTER_TABLE_SIZE * sizeof(table_entry))); - fwrite(&mtt_tags, 1, sizeof(mtt_tags), disk); + fwrite(&master_table, 1, sizeof(master_table), disk); zero_buffer = calloc(1, 16); fwrite(zero_buffer, 1, 16, disk); free(zero_buffer); @@ -475,22 +474,22 @@ int create_file_system() { int lsfs_disk_load_disk() { // First we find the Mater Table. - fseek ( disk , 1 * SECTOR_SIZE, SEEK_SET ); - fread(p_control.mtt_tags, 1, sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE , disk); + fseek ( disk , 24 * SECTOR_SIZE, SEEK_SET ); + fread(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE , disk); // Now we can finde the FSCI data - fseek ( disk , 0, SEEK_SET ); - fread(p_control.fsci, 1, sizeof(FSCI), disk); + //fseek ( disk , 0, SEEK_SET ); + //fread(p_control.fsci, 1, sizeof(FSCI), disk); return 1; } -lsfs_tag_id lsfs_disk_create_file(char* filename, lsfs_tag_id* tags, void* file_data) { +lsfs_file_id lsfs_disk_create_file(char* filename, lsfs_file_id* tags, void* file_data) { // create space for mif mif new_file_data; - lsfs_tag_id return_id; + lsfs_file_id return_id; memset(new_file_data.filename, 0, sizeof(new_file_data.filename)); @@ -499,11 +498,11 @@ lsfs_tag_id lsfs_disk_create_file(char* filename, lsfs_tag_id* tags, void* file_ printf("%s\n", new_file_data.filename); new_file_data.owner_id = getuid(); - lsfs_tag_id* index_to_mif_data; - index_to_mif_data = calloc(1, sizeof(lsfs_tag_id)); + lsfs_file_id* index_to_mif_data; + index_to_mif_data = calloc(1, sizeof(lsfs_file_id)); get_free_sectors(1, index_to_mif_data); // has to be freed - memset(new_file_data.tags, 0, (32 * sizeof(lsfs_tag_id))); + memset(new_file_data.tags, 0, (32 * sizeof(lsfs_file_id))); new_file_data.file_size = 0; @@ -532,7 +531,7 @@ lsfs_tag_id lsfs_disk_create_file(char* filename, lsfs_tag_id* tags, void* file_ if (tags != NULL) { while(tags[i] != 0) { printf("A tag is found \n"); - lsfs_disk_tag_file(tags[i], index_to_mif_data[0]); + //lsfs_disk_tag_file(tags[i], index_to_mif_data[0]); new_file_data.tags[i] = tags[i]; i++; } diff --git a/lsfs_fuse b/lsfs_fuse deleted file mode 100755 index 8e528fe..0000000 Binary files a/lsfs_fuse and /dev/null differ diff --git a/lsfs_fuse.c b/lsfs_fuse.c index d77d7b0..3327824 100644 --- a/lsfs_fuse.c +++ b/lsfs_fuse.c @@ -187,6 +187,10 @@ int lsfs_readdir( const char *path, void *buf, fuse_fill_dir_t filler, off_t off filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, "hello", NULL, 0); + filler(buf, p_control.master_table[0].filename, NULL, 0); + filler(buf, p_control.master_table[1].filename, NULL, 0); + filler(buf, p_control.master_table[2].filename, NULL, 0); + return 0; } @@ -292,10 +296,10 @@ end: int main( int argc, char *argv[] ) { - disk = fopen ( "~/Documents/github/SingOS/bin/SingOS.img" , "r+b" ); + disk = fopen ( "/home/rhodez-x/Documents/github/SingOS/bin/SingOS.img" , "r+b" ); p_control.fsci = malloc(sizeof(FSCI)); - p_control.master_table = malloc(sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE); - lsfs_disk_load_disk(disk, &p_control); + p_control.master_table = malloc(sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE); + lsfs_disk_load_disk(); //tag_record *tag_table = calloc(1, SECTOR_SIZE); //mif* mif_data = calloc(1, SECTOR_SIZE); diff --git a/lsfs_fuse.o b/lsfs_fuse.o deleted file mode 100644 index 779d9cf..0000000 Binary files a/lsfs_fuse.o and /dev/null differ