Update to Disk Manager Utility, issues with directory inside directory
This commit is contained in:
1 parent
cc12b2e449
commit
0e95c59bf7
6 files changed
+90
-76
No files matched your search
BIN
Binary file not shown.
+34
-36
@@ -133,30 +133,36 @@ int dmu_create_file_system(char* disk_name) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int dmu_load_file_system(char* disk_name) {
|
int dmu_load_file_system(char* disk_name) {
|
||||||
disk = fopen ( disk_name , "r+b" );
|
disk = fopen ( disk_name , "r+b" );
|
||||||
p_control.fsci = malloc(sizeof(FSCI));
|
lsfs_disk_load_disk();
|
||||||
p_control.mtt_tags = malloc(sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE);
|
|
||||||
lsfs_disk_load_disk(disk, &p_control);
|
|
||||||
disk_is_loaded = 1;
|
disk_is_loaded = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dmu_print_mtt() {
|
int dmu_print_mtt(char *path) {
|
||||||
printf("\n|---------------------Master Tag Table----------------------|Control_bits|\n");
|
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) {
|
printf("\n|------------------------ Directory ------------------------|Control_bits|\n");
|
||||||
if (p_control.mtt_tags[i].tag_table_index == 0) {
|
|
||||||
break;
|
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("|%-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");
|
printf("|-----------------------------------------------------------|------------|\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
|
||||||
int dmu_print_tag_table(lsfs_tag_id TagID) {
|
int dmu_print_tag_table(lsfs_tag_id TagID) {
|
||||||
tag_record* tag_table = calloc(1, SECTOR_SIZE);
|
tag_record* tag_table = calloc(1, SECTOR_SIZE);
|
||||||
@@ -200,18 +206,28 @@ int main (int argc, char *argv[])
|
|||||||
scanf("%s", loaded_disk_name);
|
scanf("%s", loaded_disk_name);
|
||||||
dmu_create_file_system(loaded_disk_name);
|
dmu_create_file_system(loaded_disk_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
else if(strcmp(chose, "l") == 0) {
|
else if(strcmp(chose, "l") == 0) {
|
||||||
printf("\nLoad disk\nEnter filename:\n");
|
printf("\nLoad disk\nEnter filename:\n");
|
||||||
scanf("%s", loaded_disk_name);
|
scanf("%s", loaded_disk_name);
|
||||||
dmu_load_file_system(loaded_disk_name);
|
dmu_load_file_system(loaded_disk_name);
|
||||||
}
|
}
|
||||||
else if(strcmp(chose, "1") == 0) {
|
else if(strcmp(chose, "1") == 0) {
|
||||||
// Print Master Tag Table
|
// Print Directory:
|
||||||
dmu_print_mtt();
|
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) {
|
else if(strcmp(chose, "2") == 0) {
|
||||||
// Print Master Tag Table
|
// Print Master Tag Table
|
||||||
printf("Enter Tag ID:\n");
|
printf("Enter Tag ID:\n");
|
||||||
@@ -232,31 +248,13 @@ int main (int argc, char *argv[])
|
|||||||
scanf("%s", input_buffer);
|
scanf("%s", input_buffer);
|
||||||
lsfs_disk_create_tag(input_buffer, false);
|
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");
|
printf("Write data:\n");
|
||||||
char* new_file_data_d = calloc(1, 4096);
|
char* new_file_data_d = calloc(1, 4096);
|
||||||
scanf("%s", new_file_data_d);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
if(disk_is_loaded) {
|
if(disk_is_loaded) {
|
||||||
|
|||||||
+56
-40
@@ -188,14 +188,17 @@ Directory_Table* lsfs_find_directory(const char *path, bool drop_filename)
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < DEFAULT_TABLE_SIZE; ++j)
|
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)
|
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)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
// Alocate space, we refuse this further on
|
// Alocate space, we refuse this further on
|
||||||
dir_table = malloc(sizeof(Directory_Table));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,9 +367,9 @@ int get_free_sectors_table() {
|
|||||||
}
|
}
|
||||||
p_control.fsci.next_free_sector += DEFAULT_TABLE_SIZE;
|
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);
|
fwrite(&p_control.fsci, 1, SECTOR_SIZE, disk);
|
||||||
|
printf("Table has got assigned Sector: %d\n", return_index);
|
||||||
return 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)
|
int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
|
||||||
{
|
{
|
||||||
|
|
||||||
lsfs_string_array split_path = lsfs_string_split_c(path, '/', false);
|
// First check if file exist:
|
||||||
lsfs_string filename = split_path.strings[split_path.length-1];
|
lsfs_file *file;
|
||||||
|
if (lsfs_disk_getattr(file, path))
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
// Start from the master table
|
// Start from the master table
|
||||||
int free_index = -1; // -1 is no index found.
|
int free_index = -1; // -1 is no index found.
|
||||||
Directory_Table *dir_table = &p_control.master_table;
|
Directory_Table *dir_table = &p_control.master_table;
|
||||||
lsfs_sector_offset table_disk_position = p_control.fsci.master_table_index;
|
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)
|
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.
|
// We have found the next directory to traverse.
|
||||||
if (dir_table->entries[j].entry_kind == ENTRY_EMPTY)
|
printf("Get next dir at sector: ");
|
||||||
|
table_disk_position = dir_table->entries[j].data_pointer[0];
|
||||||
|
if (i == 0)
|
||||||
{
|
{
|
||||||
// Set the free index, continue to see if the filename exist.
|
// Alocate space, we refuse this further on
|
||||||
// if not -1, we have found a better index.
|
dir_table = malloc(sizeof(Directory_Table));
|
||||||
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)
|
|
||||||
{
|
|
||||||
// Abort mission, we have a file with the same name.
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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("%d\n", table_disk_position);
|
||||||
|
read_data_from_disk(table_disk_position, DEFAULT_TABLE_SIZE, dir_table);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
if (free_index == -1)
|
||||||
{
|
{
|
||||||
// The table is full, and we cannot create an entry
|
// 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
|
// We assign one data pointer consiting of DEFAULT_FILE_SIZE sectors
|
||||||
dir_table->entries[free_index].file_size = 0;
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -573,7 +589,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
|
|||||||
time_t current_time;
|
time_t current_time;
|
||||||
time ( ¤t_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]);
|
write_data_to_disk(table_disk_position, 1, &dir_table->entries[free_index]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in new issue
Block a user