|
|
@ -16,6 +16,7 @@ typedef struct struct_partition_control partition_control; |
|
|
|
typedef struct File_System_Control_Information FSCI; |
|
|
|
typedef struct meta_information_format mif; |
|
|
|
typedef struct tag_record tag_record; |
|
|
|
typedef struct lsfs_file lsfs_file; |
|
|
|
|
|
|
|
typedef uint64_t lsfs_sector_offset; |
|
|
|
typedef lsfs_sector_offset lsfs_file_id; |
|
|
@ -27,6 +28,7 @@ static partition_control p_control; |
|
|
|
int create_file_system(); |
|
|
|
//lsfs_sector_offset lsfs_disk_create_tag(char* tag_name, bool is_filename);
|
|
|
|
lsfs_sector_offset lsfs_disk_create_file(char* filename, lsfs_file_id* tags, void* file_data); |
|
|
|
int lsfs_disk_getattr(lsfs_file* find_file, const char *path); |
|
|
|
//int lsfs_disk_untag_file(lsfs_file_id file_id, lsfs_file_id file_id);
|
|
|
|
//int lsfs_disk_tag_file(lsfs_file_id file_id, lsfs_file_id file_id);
|
|
|
|
//int lsfs_disk_delete_tag(lsfs_file_id file_id);
|
|
|
@ -72,7 +74,7 @@ typedef struct File_System_Control_Information { |
|
|
|
|
|
|
|
typedef struct struct_table_entry { |
|
|
|
char filename[256]; |
|
|
|
lsfs_file_id tag_table_index; |
|
|
|
lsfs_file_id file_id; |
|
|
|
uint64_t file_size; |
|
|
|
mif* ext_file_data; |
|
|
|
struct { |
|
|
@ -113,26 +115,61 @@ typedef struct tag_record { |
|
|
|
|
|
|
|
} __attribute__((packed)) tag_record; |
|
|
|
|
|
|
|
typedef struct lsfs_file { |
|
|
|
lsfs_file_id file_id; |
|
|
|
char* filename; |
|
|
|
uint32_t owner_id; |
|
|
|
uint64_t size; |
|
|
|
uint64_t creation_date; |
|
|
|
uint64_t access_time; |
|
|
|
uint64_t modification_time; |
|
|
|
lsfs_sector_offset *data; |
|
|
|
} lsfs_file; |
|
|
|
|
|
|
|
|
|
|
|
int lsfs_disk_getattr(lsfs_file* find_file, const char* path) { |
|
|
|
int i = 0; |
|
|
|
int found = 0; |
|
|
|
while((p_control.master_table[i].filename[0]) != 0 && !found) { |
|
|
|
if(strcmp( (path + 1 ), p_control.master_table[i].filename ) == 0) { |
|
|
|
time_t current_time; |
|
|
|
time ( ¤t_time ); |
|
|
|
|
|
|
|
//find_file = calloc(1, sizeof(lsfs_file));
|
|
|
|
find_file->file_id = p_control.master_table[i].file_id; |
|
|
|
find_file->filename = p_control.master_table[i].filename; |
|
|
|
find_file->owner_id = getuid(); |
|
|
|
find_file->size = p_control.master_table[i].file_size; // p_control.master_table[i].data_pointer[0]; //;
|
|
|
|
find_file->creation_date = (uint64_t) current_time; |
|
|
|
find_file->access_time = (uint64_t) current_time; |
|
|
|
find_file->modification_time = (uint64_t) current_time; |
|
|
|
found = 1; |
|
|
|
} |
|
|
|
i++; |
|
|
|
} |
|
|
|
return found; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int lsfs_disk_read_data_from_file(lsfs_file_id file_id, int buffer_size, void* buffer_for_data) { |
|
|
|
// TODO some offset, to tell where in the file we want to write
|
|
|
|
mif* mif_record = calloc(1, SECTOR_SIZE); |
|
|
|
read_data_from_disk(file_id, mif_record); |
|
|
|
|
|
|
|
int return_val = 0; |
|
|
|
|
|
|
|
for (int i = 0; i < NUM_DATA_POINTERS; ++i) { |
|
|
|
if(mif_record->one_level_pointer_data[i] == 0) { |
|
|
|
if(p_control.master_table[file_id].data_pointer[i] == 0) { |
|
|
|
break; |
|
|
|
} |
|
|
|
return_val += read_data_from_disk(mif_record->one_level_pointer_data[i], buffer_for_data + (SECTOR_SIZE * i)); |
|
|
|
i++; |
|
|
|
return_val += read_data_from_disk(p_control.master_table[file_id].data_pointer[i], buffer_for_data + (SECTOR_SIZE * i)); |
|
|
|
} |
|
|
|
|
|
|
|
time_t current_time; |
|
|
|
time ( ¤t_time ); |
|
|
|
//time_t current_time;
|
|
|
|
//time ( ¤t_time );
|
|
|
|
|
|
|
|
mif_record->last_access_date = (uint64_t) current_time; |
|
|
|
write_data_to_disk(file_id, mif_record); |
|
|
|
free(mif_record); |
|
|
|
//mif_record->last_access_date = (uint64_t) current_time;
|
|
|
|
//write_data_to_disk(file_id, mif_record);
|
|
|
|
//free(mif_record);
|
|
|
|
return return_val; |
|
|
|
} |
|
|
|
|
|
|
@ -165,7 +202,7 @@ int lsfs_disk_write_data_to_file(lsfs_file_id file_id, int data_length, char *da |
|
|
|
|
|
|
|
for (;;) { |
|
|
|
assert(current_sector <= NUM_DATA_POINTERS); |
|
|
|
write_data_to_disk(mif_record.one_level_pointer_data[current_sector++], tmp_buffer); |
|
|
|
write_data_to_disk(p_control.master_table[file_id].data_pointer[current_sector], tmp_buffer); |
|
|
|
if (data_length <= 0) break; |
|
|
|
|
|
|
|
data += SECTOR_SIZE; |
|
|
@ -184,10 +221,10 @@ int lsfs_disk_write_data_to_file(lsfs_file_id file_id, int data_length, char *da |
|
|
|
|
|
|
|
free(tmp_buffer); |
|
|
|
|
|
|
|
lsfs_disk_update_timestamps(&mif_record); |
|
|
|
mif_record.file_size += amount_written; // update file size
|
|
|
|
//lsfs_disk_update_timestamps(&mif_record);
|
|
|
|
p_control.master_table[file_id].file_size += amount_written; // update file size
|
|
|
|
|
|
|
|
write_data_to_disk(file_id, &mif_record); |
|
|
|
write_data_to_disk(file_id, &p_control.master_table[file_id]); |
|
|
|
return amount_written; |
|
|
|
} |
|
|
|
|
|
|
@ -203,7 +240,7 @@ time_t lsfs_disk_truncate_file(lsfs_file_id file_id) { |
|
|
|
int lsfs_disk_rename_tag(lsfs_file_id file_id, char* new_filename) { |
|
|
|
for (int i = 0; i < MAX_MASTER_TAGS; ++i) |
|
|
|
{ |
|
|
|
if(p_control.master_table[i].tag_table_index == file_id) { |
|
|
|
if(p_control.master_table[i].file_id == file_id) { |
|
|
|
memset(p_control.master_table[i].filename, 0, sizeof(p_control.master_table[i].filename)); |
|
|
|
sprintf(p_control.master_table[i].filename, "%s", new_filename); |
|
|
|
break; |
|
|
@ -270,14 +307,14 @@ int lsfs_disk_delete_file(lsfs_file_id file_id) { |
|
|
|
|
|
|
|
for (int i = 0; i < MAX_MASTER_TAGS; ++i) |
|
|
|
{ |
|
|
|
if(p_control.master_table[i].tag_table_index == file_id) { |
|
|
|
if(p_control.master_table[i].file_id == file_id) { |
|
|
|
p_control.master_table[i] = p_control.master_table[i+1]; |
|
|
|
truncate_table = 1; |
|
|
|
printf("Tag deleted from master table - TagID: %lu\n", file_id); |
|
|
|
} |
|
|
|
else if (truncate_table) { |
|
|
|
p_control.master_table[i] = p_control.master_table[i+1]; |
|
|
|
if (p_control.master_table[i+1].tag_table_index == 0) { |
|
|
|
if (p_control.master_table[i+1].file_id == 0) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -383,13 +420,13 @@ int lsfs_disk_delete_file(lsfs_file_id file_id) { |
|
|
|
|
|
|
|
// Insert tag in the master tag, table an set the pointer to the first of the tag table
|
|
|
|
int index_in_mtt = 0; |
|
|
|
while(p_control.master_table[index_in_mtt].tag_table_index != 0) { |
|
|
|
while(p_control.master_table[index_in_mtt].file_id != 0) { |
|
|
|
//TODO also have to count if we enter next data section.
|
|
|
|
index_in_mtt++; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p_control.master_table[index_in_mtt].tag_table_index = free_sectors[0]; |
|
|
|
p_control.master_table[index_in_mtt].file_id = free_sectors[0]; |
|
|
|
printf("%lu\n", free_sectors[0]); |
|
|
|
sprintf(p_control.master_table[index_in_mtt].filename, "%s", tag_name); |
|
|
|
p_control.master_table[index_in_mtt].control_bits.is_filename = is_filename; |
|
|
|