rename, delete works, new default table size = 16 entries
This commit is contained in:
1 parent
3a93537cbd
commit
5db0a51db0
6 files changed
+42
-63
No files matched your search
BIN
Binary file not shown.
+40
-50
@@ -29,6 +29,7 @@ typedef lsfs_sector_offset lsfs_file_id;
|
|||||||
//typedef uint64_t sector_index;
|
//typedef uint64_t sector_index;
|
||||||
static FILE* disk;
|
static FILE* disk;
|
||||||
static partition_control p_control;
|
static partition_control p_control;
|
||||||
|
static time_t timestamp_loading;
|
||||||
|
|
||||||
int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesystem_size_in_MB);
|
int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesystem_size_in_MB);
|
||||||
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);
|
||||||
@@ -39,7 +40,7 @@ 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 buffer_size, void* buffer_for_data);
|
int lsfs_disk_read_data_from_file(lsfs_file* file, int buffer_size, void* buffer_for_data);
|
||||||
int lsfs_disk_write_data_to_file(lsfs_file* file, int data_length, char *data, size_t offset_to_next_entry);
|
int lsfs_disk_write_data_to_file(lsfs_file* file, int data_length, char *data, size_t offset_to_next_entry);
|
||||||
int lsfs_disk_rename_file(lsfs_file* file, const char* new_filename);
|
int lsfs_disk_rename_file(const char* old_filename_, const char* new_filename);
|
||||||
int lsfs_disk_load_disk();
|
int lsfs_disk_load_disk();
|
||||||
int write_data_to_disk(lsfs_sector_offset at_sector, uint32_t file_block_size, void* data_to_write);
|
int write_data_to_disk(lsfs_sector_offset at_sector, uint32_t file_block_size, void* data_to_write);
|
||||||
int read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void* data_buffer);
|
int read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void* data_buffer);
|
||||||
@@ -54,7 +55,7 @@ int save_modified_file_information(lsfs_file* file);
|
|||||||
#define NUMBER_OF_MBR_PARTITIONS 4
|
#define NUMBER_OF_MBR_PARTITIONS 4
|
||||||
#define DEFAULT_FILE_SIZE 4 // This is in sectors
|
#define DEFAULT_FILE_SIZE 4 // This is in sectors
|
||||||
#define DEFAULT_DATA_POINTER_SIZE 4 // This is in sectors
|
#define DEFAULT_DATA_POINTER_SIZE 4 // This is in sectors
|
||||||
#define DEFAULT_TABLE_SIZE 10
|
#define DEFAULT_TABLE_SIZE 16
|
||||||
#define NUM_DATA_POINTERS 27
|
#define NUM_DATA_POINTERS 27
|
||||||
|
|
||||||
typedef enum Table_Entry_Kind
|
typedef enum Table_Entry_Kind
|
||||||
@@ -100,22 +101,22 @@ typedef struct struct_table_entry
|
|||||||
|
|
||||||
typedef struct Directory_Table
|
typedef struct Directory_Table
|
||||||
{
|
{
|
||||||
struct_table_entry entries[10];
|
struct_table_entry entries[DEFAULT_TABLE_SIZE];
|
||||||
|
|
||||||
} __attribute__((packed)) Directory_Table;
|
} __attribute__((packed)) Directory_Table;
|
||||||
|
|
||||||
typedef struct File_System_Control_Information
|
typedef struct File_System_Control_Information
|
||||||
{
|
{
|
||||||
char filesystem_information[256];
|
char filesystem_information[256];
|
||||||
uint64_t master_table_index;
|
lsfs_sector_offset master_table_index;
|
||||||
uint64_t this_partition_offset_on_disk;
|
lsfs_sector_offset this_partition_offset_on_disk;
|
||||||
uint64_t next_free_sector;
|
lsfs_sector_offset next_free_sector;
|
||||||
uint64_t next_uniqe_id; // both files and directories gets this.
|
uint64_t next_uniqe_id; // both files and directories gets this.
|
||||||
uint64_t next_sector_reuse_pointer;
|
lsfs_sector_offset next_sector_reuse_pointer;
|
||||||
uint64_t last_sector_index_on_partition;
|
lsfs_sector_offset last_sector_index_on_partition;
|
||||||
uint64_t maximum_sectors_on_disk;
|
lsfs_sector_offset maximum_sectors_on_disk;
|
||||||
uint64_t sector_size_on_disk;
|
lsfs_sector_offset sector_size_on_disk;
|
||||||
uint64_t not_used[24];
|
uint64_t not_used[24];
|
||||||
|
|
||||||
} __attribute__((packed)) FSCI;
|
} __attribute__((packed)) FSCI;
|
||||||
|
|
||||||
@@ -177,7 +178,8 @@ typedef struct lsfs_file {
|
|||||||
Directory_Table* lsfs_find_directory(const char *path, bool drop_filename)
|
Directory_Table* lsfs_find_directory(const char *path, bool drop_filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
Directory_Table *dir_table = &p_control.master_table;
|
Directory_Table *dir_table = calloc(1, sizeof(Directory_Table));
|
||||||
|
read_data_from_disk(p_control.fsci.master_table_index, DEFAULT_TABLE_SIZE, dir_table);
|
||||||
lsfs_string_array split_path = lsfs_string_split_c(path, '/', false);
|
lsfs_string_array split_path = lsfs_string_split_c(path, '/', false);
|
||||||
|
|
||||||
int number_of_traversal = split_path.length;
|
int number_of_traversal = split_path.length;
|
||||||
@@ -195,16 +197,6 @@ Directory_Table* lsfs_find_directory(const char *path, bool drop_filename)
|
|||||||
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)
|
||||||
{
|
{
|
||||||
int index_sector = dir_table->entries[j].data_pointer[0];
|
int index_sector = dir_table->entries[j].data_pointer[0];
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
// Alocate space, we refuse this further on
|
|
||||||
dir_table = calloc(1, sizeof(Directory_Table));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
free(dir_table);
|
|
||||||
dir_table = calloc(1, sizeof(Directory_Table));
|
|
||||||
}
|
|
||||||
read_data_from_disk(index_sector, DEFAULT_TABLE_SIZE, dir_table);
|
read_data_from_disk(index_sector, DEFAULT_TABLE_SIZE, dir_table);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -223,9 +215,6 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
|
|||||||
for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i)
|
for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i)
|
||||||
{
|
{
|
||||||
if(strcmp( filename.chars, dir_table->entries[i].filename ) == 0) {
|
if(strcmp( filename.chars, dir_table->entries[i].filename ) == 0) {
|
||||||
time_t current_time;
|
|
||||||
time ( ¤t_time );
|
|
||||||
|
|
||||||
find_file->file_id = dir_table->entries[i].file_id;
|
find_file->file_id = dir_table->entries[i].file_id;
|
||||||
find_file->entry_kind = dir_table->entries[i].entry_kind;
|
find_file->entry_kind = dir_table->entries[i].entry_kind;
|
||||||
find_file->table_entry_pointer = i;
|
find_file->table_entry_pointer = i;
|
||||||
@@ -233,10 +222,10 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
|
|||||||
find_file->table_entry_sector_index = dir_table->entries[i].table_entry_sector_index;
|
find_file->table_entry_sector_index = dir_table->entries[i].table_entry_sector_index;
|
||||||
find_file->owner_id = getuid();
|
find_file->owner_id = getuid();
|
||||||
find_file->size = dir_table->entries[i].file_size; // dir_table->entries[i].data_pointer[0]; //;
|
find_file->size = dir_table->entries[i].file_size; // dir_table->entries[i].data_pointer[0]; //;
|
||||||
find_file->creation_date = (uint64_t) current_time;
|
find_file->creation_date = (uint64_t) timestamp_loading;
|
||||||
find_file->access_time = (uint64_t) current_time;
|
find_file->access_time = (uint64_t) timestamp_loading;
|
||||||
find_file->modification_time = (uint64_t) current_time;
|
find_file->modification_time = (uint64_t) timestamp_loading;
|
||||||
memcpy(find_file->data_pointer, dir_table->entries[i].data_pointer, DEFAULT_DATA_POINTER_SIZE * 8);
|
memcpy(find_file->data_pointer, dir_table->entries[i].data_pointer, NUM_DATA_POINTERS * 8);
|
||||||
find_file->file_block_size = 1; // TODO: should be loaded from disk.
|
find_file->file_block_size = 1; // TODO: should be loaded from disk.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -352,18 +341,21 @@ time_t lsfs_disk_truncate_file(lsfs_file *file, off_t offset) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lsfs_disk_rename_file(lsfs_file* file, const char* new_filename) {
|
int lsfs_disk_rename_file(const char* old_filename, const char* new_filename) {
|
||||||
|
|
||||||
memset(file->filename, 0, 256);
|
lsfs_file *old_file = calloc(1, sizeof(lsfs_file));
|
||||||
sprintf(file->filename, "%s", new_filename);
|
lsfs_file *new_file = calloc(1, sizeof(lsfs_file));
|
||||||
|
|
||||||
time_t current_time;
|
lsfs_disk_getattr(old_file, old_filename);
|
||||||
time ( ¤t_time );
|
lsfs_disk_create_entry(new_filename, ENTRY_FILE);
|
||||||
|
lsfs_disk_getattr(new_file, new_filename);
|
||||||
|
|
||||||
file->access_time = (uint64_t) current_time;
|
new_file->file_id = old_file->file_id;
|
||||||
file->modification_time = (uint64_t) current_time;
|
new_file->size = old_file->size;
|
||||||
|
// TODO(Jørn) The data pointer assignt to the new file should be released.
|
||||||
save_modified_file_information(file);
|
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);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -371,7 +363,7 @@ int lsfs_disk_rename_file(lsfs_file* file, const char* new_filename) {
|
|||||||
int lsfs_disk_delete_file(lsfs_file *file) {
|
int lsfs_disk_delete_file(lsfs_file *file) {
|
||||||
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);
|
||||||
write_data_to_disk(file->table_entry_sector_index, DEFAULT_TABLE_SIZE, zero_buffer);
|
write_data_to_disk(file->table_entry_sector_index, DEFAULT_ENTRY_SIZE, zero_buffer);
|
||||||
|
|
||||||
free(zero_buffer);
|
free(zero_buffer);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -453,6 +445,7 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
|
|||||||
|
|
||||||
// Create disk on host system:
|
// Create disk on host system:
|
||||||
disk = fopen ( disk_name , "wb" );
|
disk = fopen ( disk_name , "wb" );
|
||||||
|
ftruncate(fileno(disk), SECTOR_SIZE * fsci->last_sector_index_on_partition);
|
||||||
|
|
||||||
write_data_to_disk(fsci->this_partition_offset_on_disk, 1, fsci);
|
write_data_to_disk(fsci->this_partition_offset_on_disk, 1, fsci);
|
||||||
|
|
||||||
@@ -467,6 +460,8 @@ int lsfs_disk_load_disk() {
|
|||||||
// Find the partition talbe:
|
// Find the partition talbe:
|
||||||
// This makes is BIOS dependent.
|
// This makes is BIOS dependent.
|
||||||
// UEFI is not supported.
|
// UEFI is not supported.
|
||||||
|
time(×tamp_loading);
|
||||||
|
|
||||||
Master_Boot_record mbr;
|
Master_Boot_record mbr;
|
||||||
fseek( disk , 0 * SECTOR_SIZE, SEEK_SET );
|
fseek( disk , 0 * SECTOR_SIZE, SEEK_SET );
|
||||||
fread(&mbr, 1, sizeof(mbr), disk);
|
fread(&mbr, 1, sizeof(mbr), disk);
|
||||||
@@ -523,7 +518,8 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
|
|||||||
|
|
||||||
// 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 = calloc(1, sizeof(Directory_Table));
|
||||||
|
read_data_from_disk(p_control.fsci.master_table_index, DEFAULT_TABLE_SIZE, dir_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;
|
||||||
|
|
||||||
|
|
||||||
@@ -541,11 +537,6 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
|
|||||||
// We have found the next directory to traverse.
|
// We have found the next directory to traverse.
|
||||||
//printf("Get next dir at sector: ");
|
//printf("Get next dir at sector: ");
|
||||||
table_disk_position = dir_table->entries[j].data_pointer[0];
|
table_disk_position = dir_table->entries[j].data_pointer[0];
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
// Alocate space, we refuse this further on
|
|
||||||
dir_table = malloc(sizeof(Directory_Table));
|
|
||||||
}
|
|
||||||
//printf("%d\n", table_disk_position);
|
//printf("%d\n", table_disk_position);
|
||||||
read_data_from_disk(table_disk_position, DEFAULT_TABLE_SIZE, dir_table);
|
read_data_from_disk(table_disk_position, DEFAULT_TABLE_SIZE, dir_table);
|
||||||
break;
|
break;
|
||||||
@@ -610,7 +601,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
|
|||||||
time ( ¤t_time );
|
time ( ¤t_time );
|
||||||
*/
|
*/
|
||||||
//printf("File is written to sector: %d\n", table_disk_position);
|
//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, DEFAULT_ENTRY_SIZE, &dir_table->entries[free_index]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,9 +614,8 @@ int save_modified_file_information(lsfs_file* file) {
|
|||||||
|
|
||||||
//entry.file_id = file->file_id;
|
//entry.file_id = file->file_id;
|
||||||
memcpy(entry->filename, file->filename, 256);
|
memcpy(entry->filename, file->filename, 256);
|
||||||
printf("Filse size: %d\n", file->size);
|
|
||||||
entry->file_size = file->size; // p_control.master_table.entries[i].data_pointer[0]; //;
|
entry->file_size = file->size; // p_control.master_table.entries[i].data_pointer[0]; //;
|
||||||
//p_control.master_table.entries[i].data_pointer = find_file->data;
|
memcpy(entry->data_pointer, file->data_pointer, NUM_DATA_POINTERS * 8);
|
||||||
|
|
||||||
write_data_to_disk(file->table_entry_sector_index, DEFAULT_ENTRY_SIZE, entry);
|
write_data_to_disk(file->table_entry_sector_index, DEFAULT_ENTRY_SIZE, entry);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+2
-13
@@ -82,12 +82,8 @@ int lsfs_truncate(const char *path, off_t offset) {
|
|||||||
|
|
||||||
|
|
||||||
int lsfs_rename(const char *path, const char *to) {
|
int lsfs_rename(const char *path, const char *to) {
|
||||||
(void)path;
|
|
||||||
(void)to;
|
|
||||||
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
|
|
||||||
|
|
||||||
lsfs_disk_getattr(found_file, path);
|
return lsfs_disk_rename_file(path, to);
|
||||||
return lsfs_disk_rename_file(found_file, to);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int lsfs_getattr( const char *path, struct stat *stbuf ) {
|
int lsfs_getattr( const char *path, struct stat *stbuf ) {
|
||||||
@@ -149,14 +145,7 @@ int lsfs_readdir( const char *path, void *buf, fuse_fill_dir_t filler, off_t off
|
|||||||
filler(buf, "..", NULL, 0);
|
filler(buf, "..", NULL, 0);
|
||||||
|
|
||||||
Directory_Table *directory_table;
|
Directory_Table *directory_table;
|
||||||
if (strcmp(path, "/") != 0)
|
directory_table = lsfs_find_directory(path, false);
|
||||||
{
|
|
||||||
directory_table = lsfs_find_directory(path, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
directory_table = &p_control.master_table;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (directory_table != NULL)
|
if (directory_table != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in new issue
Block a user