|
|
@ -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; |
|
|
|
} |
|
|
|