diff --git a/SingOS.img b/SingOS.img index 9566a05..ff92620 100644 Binary files a/SingOS.img and b/SingOS.img differ diff --git a/a.out b/a.out index 706becf..466bfbe 100755 Binary files a/a.out and b/a.out differ diff --git a/disk_manager_utility.c b/disk_manager_utility.c index 145cc30..9b8e72a 100644 --- a/disk_manager_utility.c +++ b/disk_manager_utility.c @@ -133,30 +133,36 @@ int dmu_create_file_system(char* disk_name) { return 1; } -#if 0 int dmu_load_file_system(char* disk_name) { disk = fopen ( disk_name , "r+b" ); - p_control.fsci = malloc(sizeof(FSCI)); - p_control.mtt_tags = malloc(sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE); - lsfs_disk_load_disk(disk, &p_control); + lsfs_disk_load_disk(); disk_is_loaded = 1; return 1; } -int dmu_print_mtt() { - printf("\n|---------------------Master Tag Table----------------------|Control_bits|\n"); +int dmu_print_mtt(char *path) { + Directory_Table *directory_table; + if (strcmp(path, "/") != 0) + { + directory_table = lsfs_find_directory(path, false); + } + else + { + directory_table = &p_control.master_table; + } - for (int i = 0; i < MAX_MASTER_TAGS; ++i) { - if (p_control.mtt_tags[i].tag_table_index == 0) { - break; - } - printf("|%-28s|%-30lu|%-12d| \n", p_control.mtt_tags[i].tagname, p_control.mtt_tags[i].tag_table_index, p_control.mtt_tags[i].control_bits.is_filename); + printf("\n|------------------------ Directory ------------------------|Control_bits|\n"); + + for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i) { + printf("|%-28s|%-30lu|%-12d| \n", directory_table->entries[i].filename, directory_table->entries[i].file_id, directory_table->entries[i].file_id); printf("|-----------------------------------------------------------|------------|\n"); } printf("\n\n\n"); return 1; } +#if 0 + int dmu_print_tag_table(lsfs_tag_id TagID) { tag_record* tag_table = calloc(1, SECTOR_SIZE); @@ -200,18 +206,28 @@ int main (int argc, char *argv[]) scanf("%s", loaded_disk_name); dmu_create_file_system(loaded_disk_name); } - - - #if 0 else if(strcmp(chose, "l") == 0) { printf("\nLoad disk\nEnter filename:\n"); scanf("%s", loaded_disk_name); dmu_load_file_system(loaded_disk_name); } else if(strcmp(chose, "1") == 0) { - // Print Master Tag Table - dmu_print_mtt(); + // Print Directory: + printf("Enter Directory:\n"); + scanf("%s", input_buffer); + dmu_print_mtt(input_buffer); } + else if(strcmp(chose, "5") == 0) { + printf("Enter Directory:\n"); + scanf("%s", input_buffer); + + int new_id = lsfs_disk_create_entry(input_buffer, ENTRY_DIRECTORY ); + //lsfs_disk_write_data_to_file(new_id, strlen(new_file_data_d), new_file_data_d); + + } + + + #if 0 else if(strcmp(chose, "2") == 0) { // Print Master Tag Table printf("Enter Tag ID:\n"); @@ -232,31 +248,13 @@ int main (int argc, char *argv[]) scanf("%s", input_buffer); lsfs_disk_create_tag(input_buffer, false); } - else if(strcmp(chose, "5") == 0) { - // Print Master Tag Table - printf("Enter Filename:\n"); - scanf("%s", input_buffer); - + + printf("Write data:\n"); char* new_file_data_d = calloc(1, 4096); scanf("%s", new_file_data_d); - printf("Enter Tag ID:\n"); - char* tags_number = calloc(16, sizeof(char)); - lsfs_sector_offset* tags = calloc(2, sizeof(lsfs_sector_offset)); - - scanf("%s", tags_number); - - int filename_tag = lsfs_disk_create_tag(input_buffer, true); - - tags[0] = filename_tag; - tags[1] = atoi(tags_number); - - - int new_id = lsfs_disk_create_file(input_buffer, tags, new_file_data_d ); - lsfs_disk_write_data_to_file(new_id, strlen(new_file_data_d), new_file_data_d); - } #endif } if(disk_is_loaded) { diff --git a/lsfs_disk_controller.h b/lsfs_disk_controller.h index e98fd36..06f35e1 100644 --- a/lsfs_disk_controller.h +++ b/lsfs_disk_controller.h @@ -188,14 +188,17 @@ Directory_Table* lsfs_find_directory(const char *path, bool drop_filename) { for (int j = 0; j < DEFAULT_TABLE_SIZE; ++j) { + printf("find dir: %s == %s\n", dir_table->entries[j].filename, split_path.strings[i].chars); if (strcmp(dir_table->entries[j].filename, split_path.strings[i].chars) == 0) { + printf("Latterlig data pointer: %d\n", dir_table->entries[j].data_pointer[0]); + int index_sector = dir_table->entries[j].data_pointer[0]; if (i == 0) { // Alocate space, we refuse this further on dir_table = malloc(sizeof(Directory_Table)); } - read_data_from_disk(dir_table->entries[j].data_pointer[0], DEFAULT_TABLE_SIZE, dir_table); + read_data_from_disk(index_sector, DEFAULT_TABLE_SIZE, dir_table); break; } } @@ -364,9 +367,9 @@ int get_free_sectors_table() { } p_control.fsci.next_free_sector += DEFAULT_TABLE_SIZE; - fseek ( disk , (p_control.fsci.this_partition_offset_on_disk) * SECTOR_SIZE, SEEK_SET ); + fseek ( disk , ((p_control.fsci.this_partition_offset_on_disk) * SECTOR_SIZE), SEEK_SET ); fwrite(&p_control.fsci, 1, SECTOR_SIZE, disk); - + printf("Table has got assigned Sector: %d\n", return_index); return return_index; } @@ -485,56 +488,69 @@ int lsfs_disk_load_disk() { int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind) { - lsfs_string_array split_path = lsfs_string_split_c(path, '/', false); - lsfs_string filename = split_path.strings[split_path.length-1]; + // First check if file exist: + lsfs_file *file; + if (lsfs_disk_getattr(file, path)) + { + return -EINVAL; + } // Start from the master table int free_index = -1; // -1 is no index found. Directory_Table *dir_table = &p_control.master_table; lsfs_sector_offset table_disk_position = p_control.fsci.master_table_index; - for (int i = 0; i < split_path.length; ++i) + + + lsfs_string_array split_path = lsfs_string_split_c(path, '/', false); + lsfs_string filename = split_path.strings[split_path.length-1]; + + printf("spilt length: %d\n", split_path.length); + + for (int i = 0; i < split_path.length -1; ++i) { for (int j = 0; j < DEFAULT_TABLE_SIZE; ++j) { - if (i == (split_path.length - 1)) + if (strcmp(dir_table->entries[j].filename, split_path.strings[i].chars) == 0) { - // Find free index and be sure that there dosent exist a file with the same name. - if (dir_table->entries[j].entry_kind == ENTRY_EMPTY) - { - // Set the free index, continue to see if the filename exist. - // if not -1, we have found a better index. - if (free_index == -1) - { - printf("Index found for file: %d\n", j); - table_disk_position += j; // Abselout index in file system - free_index = j; - } - } - else if (strcmp(dir_table->entries[j].filename, split_path.strings[i].chars) == 0) + // We have found the next directory to traverse. + printf("Get next dir at sector: "); + table_disk_position = dir_table->entries[j].data_pointer[0]; + if (i == 0) { - // Abort mission, we have a file with the same name. - return -EINVAL; + // Alocate space, we refuse this further on + dir_table = malloc(sizeof(Directory_Table)); } + printf("%d\n", table_disk_position); + read_data_from_disk(table_disk_position, DEFAULT_TABLE_SIZE, dir_table); + break; } - else + } + } + + + for (int table_index = 0; table_index < DEFAULT_TABLE_SIZE; ++table_index) + { + // Find free index. + if (dir_table->entries[table_index].entry_kind == ENTRY_EMPTY) + { + // Set the free index, continue to see if the filename exist. + // if not -1, we have found a better index. + if (free_index == -1) { - if (strcmp(dir_table->entries[j].filename, split_path.strings[i].chars) == 0) - { - // We have found the next directory to traverse. - if (i == 0) - { - // Alocate space, we refuse this further on - dir_table = malloc(sizeof(Directory_Table)); - } - printf("Get next dir\n"); - table_disk_position = dir_table->entries[j].data_pointer[0]; - read_data_from_disk(table_disk_position, DEFAULT_TABLE_SIZE, dir_table); - break; - } + printf("Index found for file: %d\n", table_index); + table_disk_position += table_index; // Abselout index in file system + free_index = table_index; } } } + + + + + + + if (free_index == -1) { // The table is full, and we cannot create an entry @@ -556,7 +572,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind) { // We assign one data pointer consiting of DEFAULT_FILE_SIZE sectors dir_table->entries[free_index].file_size = 0; - get_free_sectors_table(1, dir_table->entries[free_index].data_pointer); + get_free_sectors(1, dir_table->entries[free_index].data_pointer); } else { @@ -573,7 +589,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind) time_t current_time; time ( ¤t_time ); */ - + printf("File is written to sector: %d\n", table_disk_position); write_data_to_disk(table_disk_position, 1, &dir_table->entries[free_index]); return 0; } diff --git a/lsfs_fuse b/lsfs_fuse index 3fc2f9b..683a28f 100755 Binary files a/lsfs_fuse and b/lsfs_fuse differ diff --git a/lsfs_fuse.o b/lsfs_fuse.o index 0510362..b774a3f 100644 Binary files a/lsfs_fuse.o and b/lsfs_fuse.o differ