1 parent
5cf271cb28
commit
b027a29e24
6 files changed
+24
-11
No files matched your search
BIN
Binary file not shown.
+23
-10
@@ -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);
|
int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind);
|
||||||
Directory_Table* lsfs_find_directory(const char* path, bool drop_filename);
|
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_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_table();
|
||||||
int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array);
|
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);
|
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 DEFAULT_ENTRY_SIZE 1 // Sectors
|
||||||
#define SECTOR_SIZE 512 // BYTES
|
#define SECTOR_SIZE 512 // BYTES
|
||||||
#define NUMBER_OF_MBR_PARTITIONS 4
|
#define NUMBER_OF_MBR_PARTITIONS 4
|
||||||
#define DEFAULT_FILE_SIZE 4 // This is in sectors
|
#define DEFAULT_DATA_POINTER_SIZE 8 // This is in sectors
|
||||||
#define DEFAULT_DATA_POINTER_SIZE 4 // This is in sectors
|
|
||||||
#define DEFAULT_TABLE_SIZE 16
|
#define DEFAULT_TABLE_SIZE 16
|
||||||
#define NUM_DATA_POINTERS 27
|
#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_read = 0;
|
||||||
int amount_to_read = 0;
|
int amount_to_read = 0;
|
||||||
int remaining_offset = offset_to_next_entry;
|
int remaining_offset = offset_to_next_entry;
|
||||||
//printf("READ: buffer_size: %d\n", buffer_size);
|
printf("READ: buffer_size: %d\n", buffer_size);
|
||||||
//printf("READ: Data length: %d\n", data_length);
|
printf("READ: Data length: %d\n", data_length);
|
||||||
//printf("READ: Offset length: %d\n", offset_to_next_entry);
|
printf("READ: Offset length: %d\n", offset_to_next_entry);
|
||||||
|
|
||||||
|
|
||||||
int data_pointer_index = 0; // start at first data pointer.
|
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
|
while(data_length > 0) // We have more to write
|
||||||
{
|
{
|
||||||
|
printf("READ: Remaing Data length: %d\n", data_length);
|
||||||
if (remaining_offset == 0)
|
if (remaining_offset == 0)
|
||||||
{
|
{
|
||||||
char *tmp_buffer = calloc(DEFAULT_DATA_POINTER_SIZE, SECTOR_SIZE);
|
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_file *new_file = calloc(1, sizeof(lsfs_file));
|
||||||
|
|
||||||
lsfs_disk_getattr(old_file, old_filename);
|
lsfs_disk_getattr(old_file, old_filename);
|
||||||
|
if (old_file->entry_kind == ENTRY_FILE)
|
||||||
|
{
|
||||||
lsfs_disk_create_entry(new_filename, 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);
|
lsfs_disk_getattr(new_file, new_filename);
|
||||||
|
|
||||||
new_file->file_id = old_file->file_id;
|
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.
|
// 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);
|
memcpy(new_file->data_pointer, old_file->data_pointer, NUM_DATA_POINTERS * 8);
|
||||||
save_modified_file_information(new_file);
|
save_modified_file_information(new_file);
|
||||||
lsfs_disk_delete_file(old_file);
|
lsfs_disk_delete_entry(old_file);
|
||||||
|
|
||||||
return 0;
|
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);
|
//printf("file: %s - has been deleted \n", file->filename);
|
||||||
Table_Entry *zero_buffer = calloc(1, (DEFAULT_ENTRY_SIZE * SECTOR_SIZE));
|
Table_Entry *zero_buffer = calloc(1, (DEFAULT_ENTRY_SIZE * SECTOR_SIZE));
|
||||||
//read_data_from_disk(file_id, 1, mif_record);
|
//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:
|
// If free we can assign:
|
||||||
output_array[i] = p_control.fsci.next_free_sector;
|
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--;
|
num_sectors_needed--;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@@ -754,7 +767,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
|
|||||||
}
|
}
|
||||||
else if (entry_kind == ENTRY_FILE)
|
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;
|
dir_table->entries[free_index].file_size = 0;
|
||||||
get_free_sectors(1, dir_table->entries[free_index].data_pointer);
|
get_free_sectors(1, dir_table->entries[free_index].data_pointer);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ int lsfs_unlink(const char *path) {
|
|||||||
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
|
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
|
||||||
|
|
||||||
lsfs_disk_getattr(found_file, path);
|
lsfs_disk_getattr(found_file, path);
|
||||||
lsfs_disk_delete_file(found_file);
|
lsfs_disk_delete_entry(found_file);
|
||||||
free(found_file);
|
free(found_file);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in new issue
Block a user