Major update, both design and implementation
This commit is contained in:
1 parent
e5d9d51870
commit
4b7e97339d
2 files changed
+51
-2
No files matched your search
@@ -31,6 +31,7 @@ static partition_control p_control;
|
|||||||
|
|
||||||
int create_file_system();
|
int create_file_system();
|
||||||
int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind);
|
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_getattr(lsfs_file* find_file, const char *path);
|
||||||
int lsfs_disk_delete_file(lsfs_file_id file_id);
|
int lsfs_disk_delete_file(lsfs_file_id file_id);
|
||||||
int get_free_sectors_table();
|
int get_free_sectors_table();
|
||||||
@@ -165,6 +166,52 @@ typedef struct lsfs_file {
|
|||||||
} 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 lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|||||||
+4
-2
@@ -151,11 +151,13 @@ 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, "..", NULL, 0);
|
filler(buf, "..", NULL, 0);
|
||||||
|
|
||||||
|
Directory_Table *directory_table = lsfs_find_directory(path);
|
||||||
|
|
||||||
for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i)
|
for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i)
|
||||||
{
|
{
|
||||||
if (strcmp( "", p_control.master_table.entries[i].filename ) != 0)
|
if (strcmp( "", directory_table.entries[i].filename ) != 0)
|
||||||
{
|
{
|
||||||
filler(buf, p_control.master_table.entries[i].filename, NULL, 0);
|
filler(buf, directory_table.entries[i].filename, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in new issue
Block a user