|
|
@ -31,6 +31,7 @@ static partition_control p_control; |
|
|
|
|
|
|
|
int create_file_system(); |
|
|
|
int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind); |
|
|
|
Directory_Table* lsfs_find_directory(const char path); |
|
|
|
int lsfs_disk_getattr(lsfs_file* find_file, const char *path); |
|
|
|
int lsfs_disk_delete_file(lsfs_file_id file_id); |
|
|
|
int get_free_sectors_table(); |
|
|
@ -165,6 +166,52 @@ typedef struct lsfs_file { |
|
|
|
} lsfs_file; |
|
|
|
|
|
|
|
|
|
|
|
Directory_Table* lsfs_find_directory(const char path) |
|
|
|
{ |
|
|
|
|
|
|
|
lsfs_string_array split_path = lsfs_string_split_c(path, '/', false); |
|
|
|
lsfs_string filename = split_path.strings[split_path.length-1]; |
|
|
|
|
|
|
|
// 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) |
|
|
|
{ |
|
|
|
for (int j = 0; j < DEFAULT_TABLE_SIZE; ++j) |
|
|
|
{ |
|
|
|
if (i == (split_path.length - 1)) |
|
|
|
{ |
|
|
|
// 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); |
|
|
|
free_index = j; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (strcmp(dir_table->entries[j].filename, split_path.strings[0].chars) == 0) |
|
|
|
{ |
|
|
|
// Abort mission, we have a file with the same name.
|
|
|
|
return -EINVAL; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (strcmp(dir_table->entries[j].filename, split_path.strings[0].chars) == 0) |
|
|
|
{ |
|
|
|
// We have found the next directory to traverse.
|
|
|
|
; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int lsfs_disk_getattr(lsfs_file* find_file, const char* path) { |
|
|
|
int i = 0; |
|
|
|
int found = 0; |
|
|
|