|
|
@ -34,7 +34,7 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys |
|
|
|
int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind); |
|
|
|
Directory_Table* lsfs_find_directory(const char* path, bool drop_filename); |
|
|
|
int lsfs_disk_getattr(lsfs_file* find_file, const char *path); |
|
|
|
int lsfs_disk_delete_file(lsfs_file *file); |
|
|
|
int lsfs_disk_delete_entry(lsfs_file *file); |
|
|
|
int get_free_sectors_table(); |
|
|
|
int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array); |
|
|
|
int lsfs_disk_read_data_from_file(lsfs_file *file, int data_length, char *data, size_t offset_to_next_entry); |
|
|
@ -53,8 +53,7 @@ int save_modified_file_information(lsfs_file* file); |
|
|
|
#define DEFAULT_ENTRY_SIZE 1 // Sectors
|
|
|
|
#define SECTOR_SIZE 512 // BYTES
|
|
|
|
#define NUMBER_OF_MBR_PARTITIONS 4 |
|
|
|
#define DEFAULT_FILE_SIZE 4 // This is in sectors
|
|
|
|
#define DEFAULT_DATA_POINTER_SIZE 4 // This is in sectors
|
|
|
|
#define DEFAULT_DATA_POINTER_SIZE 8 // This is in sectors
|
|
|
|
#define DEFAULT_TABLE_SIZE 16 |
|
|
|
#define NUM_DATA_POINTERS 27 |
|
|
|
|
|
|
@ -241,14 +240,21 @@ int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data, |
|
|
|
int amount_read = 0; |
|
|
|
int amount_to_read = 0; |
|
|
|
int remaining_offset = offset_to_next_entry; |
|
|
|
//printf("READ: buffer_size: %d\n", buffer_size);
|
|
|
|
//printf("READ: Data length: %d\n", data_length);
|
|
|
|
//printf("READ: Offset length: %d\n", offset_to_next_entry);
|
|
|
|
printf("READ: buffer_size: %d\n", buffer_size); |
|
|
|
printf("READ: Data length: %d\n", data_length); |
|
|
|
printf("READ: Offset length: %d\n", offset_to_next_entry); |
|
|
|
|
|
|
|
|
|
|
|
int data_pointer_index = 0; // start at first data pointer.
|
|
|
|
|
|
|
|
if (data_length > buffer_size) |
|
|
|
{ |
|
|
|
data_length = buffer_size; |
|
|
|
} |
|
|
|
|
|
|
|
while(data_length > 0) // We have more to write
|
|
|
|
{ |
|
|
|
printf("READ: Remaing Data length: %d\n", data_length); |
|
|
|
if (remaining_offset == 0) |
|
|
|
{ |
|
|
|
char *tmp_buffer = calloc(DEFAULT_DATA_POINTER_SIZE, SECTOR_SIZE); |
|
|
@ -434,7 +440,14 @@ int lsfs_disk_rename_file(const char* old_filename, const char* new_filename) { |
|
|
|
lsfs_file *new_file = calloc(1, sizeof(lsfs_file)); |
|
|
|
|
|
|
|
lsfs_disk_getattr(old_file, old_filename); |
|
|
|
lsfs_disk_create_entry(new_filename, ENTRY_FILE); |
|
|
|
if (old_file->entry_kind == ENTRY_FILE) |
|
|
|
{ |
|
|
|
lsfs_disk_create_entry(new_filename, ENTRY_FILE); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
lsfs_disk_create_entry(new_filename, ENTRY_DIRECTORY); |
|
|
|
} |
|
|
|
lsfs_disk_getattr(new_file, new_filename); |
|
|
|
|
|
|
|
new_file->file_id = old_file->file_id; |
|
|
@ -442,12 +455,12 @@ int lsfs_disk_rename_file(const char* old_filename, const char* new_filename) { |
|
|
|
// TODO(Jørn) The data pointer assignt to the new file should be released.
|
|
|
|
memcpy(new_file->data_pointer, old_file->data_pointer, NUM_DATA_POINTERS * 8); |
|
|
|
save_modified_file_information(new_file); |
|
|
|
lsfs_disk_delete_file(old_file); |
|
|
|
lsfs_disk_delete_entry(old_file); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int lsfs_disk_delete_file(lsfs_file *file) { |
|
|
|
int lsfs_disk_delete_entry(lsfs_file *file) { |
|
|
|
//printf("file: %s - has been deleted \n", file->filename);
|
|
|
|
Table_Entry *zero_buffer = calloc(1, (DEFAULT_ENTRY_SIZE * SECTOR_SIZE)); |
|
|
|
//read_data_from_disk(file_id, 1, mif_record);
|
|
|
@ -530,7 +543,7 @@ int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) { |
|
|
|
{ |
|
|
|
// If free we can assign:
|
|
|
|
output_array[i] = p_control.fsci.next_free_sector; |
|
|
|
p_control.fsci.next_free_sector += DEFAULT_FILE_SIZE; |
|
|
|
p_control.fsci.next_free_sector += DEFAULT_DATA_POINTER_SIZE; |
|
|
|
num_sectors_needed--; |
|
|
|
} |
|
|
|
i++; |
|
|
@ -754,7 +767,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind) |
|
|
|
} |
|
|
|
else if (entry_kind == ENTRY_FILE) |
|
|
|
{ |
|
|
|
// We assign one data pointer consiting of DEFAULT_FILE_SIZE sectors
|
|
|
|
// We assign one data pointer consiting of DEFAULT_DATA_POINTER_SIZE sectors
|
|
|
|
dir_table->entries[free_index].file_size = 0; |
|
|
|
get_free_sectors(1, dir_table->entries[free_index].data_pointer); |
|
|
|
} |
|
|
|