Changes to LSFS it self
This commit is contained in:
1 parent
91d1e1d0f2
commit
ea6451e625
4 files changed
+63
-51
No files matched your search
+61
-47
@@ -10,8 +10,9 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
typedef struct Directory_Table Directory_Table;
|
||||||
|
typedef struct struct_table_entry struct_table_entry;
|
||||||
typedef struct struct_partition_control partition_control;
|
typedef struct struct_partition_control partition_control;
|
||||||
typedef struct struct_table_entry table_entry;
|
|
||||||
typedef struct struct_partition_control partition_control;
|
typedef struct struct_partition_control partition_control;
|
||||||
typedef struct File_System_Control_Information FSCI;
|
typedef struct File_System_Control_Information FSCI;
|
||||||
typedef struct meta_information_format mif;
|
typedef struct meta_information_format mif;
|
||||||
@@ -58,10 +59,6 @@ int save_modified_file_information(lsfs_file* file);
|
|||||||
//#define MAX_NUM_TWO_LEVEL_DATA 94 // First Mib of a file.
|
//#define MAX_NUM_TWO_LEVEL_DATA 94 // First Mib of a file.
|
||||||
//#define MAX_NUM_THREE_LEVEL_DATA 94 // First Mib of a file.
|
//#define MAX_NUM_THREE_LEVEL_DATA 94 // First Mib of a file.
|
||||||
|
|
||||||
typedef struct struct_partition_control{
|
|
||||||
FSCI* fsci;
|
|
||||||
table_entry* master_table;
|
|
||||||
} __attribute__((packed)) partition_control;
|
|
||||||
|
|
||||||
typedef struct Partition_Entry
|
typedef struct Partition_Entry
|
||||||
{
|
{
|
||||||
@@ -74,13 +71,35 @@ typedef struct Partition_Entry
|
|||||||
|
|
||||||
} __attribute__((packed)) Partition_Entry;
|
} __attribute__((packed)) Partition_Entry;
|
||||||
|
|
||||||
typedef struct Master_Boot_record {
|
typedef struct Master_Boot_record
|
||||||
|
{
|
||||||
uint8_t offset_on_disk[446]; // The code for the bootloader
|
uint8_t offset_on_disk[446]; // The code for the bootloader
|
||||||
Partition_Entry partitions[4];
|
Partition_Entry partitions[4];
|
||||||
uint8_t master_tag_records[2]; // Signature
|
uint8_t master_tag_records[2]; // Signature
|
||||||
} __attribute__((packed)) Master_Boot_record;
|
} __attribute__((packed)) Master_Boot_record;
|
||||||
|
|
||||||
typedef struct File_System_Control_Information {
|
typedef struct struct_table_entry
|
||||||
|
{
|
||||||
|
char filename[256];
|
||||||
|
lsfs_file_id file_id;
|
||||||
|
uint64_t file_size;
|
||||||
|
mif* ext_file_data;
|
||||||
|
uint32_t file_block_size; // This tells how many block there are allocated for the specific file. eg. we read this amount of bloks for the file.
|
||||||
|
uint8_t entry_kind;
|
||||||
|
uint8_t extra_control_bits1;
|
||||||
|
uint8_t extra_control_bits2;
|
||||||
|
uint8_t extra_control_bits3;
|
||||||
|
lsfs_sector_offset data_pointer[NUM_DATA_POINTERS]; // if it is a directory, the first pointer will be to the next table.
|
||||||
|
} __attribute__((packed)) table_entry;
|
||||||
|
|
||||||
|
typedef struct Directory_Table
|
||||||
|
{
|
||||||
|
struct_table_entry entries[10];
|
||||||
|
|
||||||
|
} __attribute__((packed)) Directory_Table;
|
||||||
|
|
||||||
|
typedef struct File_System_Control_Information
|
||||||
|
{
|
||||||
uint64_t offset_on_disk;
|
uint64_t offset_on_disk;
|
||||||
uint64_t next_partition;
|
uint64_t next_partition;
|
||||||
uint64_t maximum_sectors_on_partition;
|
uint64_t maximum_sectors_on_partition;
|
||||||
@@ -91,17 +110,12 @@ typedef struct File_System_Control_Information {
|
|||||||
uint64_t master_tag_records[16];
|
uint64_t master_tag_records[16];
|
||||||
} __attribute__((packed)) FSCI;
|
} __attribute__((packed)) FSCI;
|
||||||
|
|
||||||
typedef struct struct_table_entry {
|
typedef struct struct_partition_control
|
||||||
char filename[256];
|
{
|
||||||
lsfs_file_id file_id;
|
FSCI fsci;
|
||||||
uint64_t file_size;
|
Directory_Table master_table;
|
||||||
mif* ext_file_data;
|
} __attribute__((packed)) partition_control;
|
||||||
uint32_t file_block_size; // This tells how many block there are allocated for the specific file. eg. we read this amount of bloks for the file.
|
|
||||||
struct {
|
|
||||||
uint32_t is_filename : 1;
|
|
||||||
} control_bits;
|
|
||||||
lsfs_sector_offset data_pointer[NUM_DATA_POINTERS];
|
|
||||||
} __attribute__((packed)) table_entry;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct meta_information_format {
|
typedef struct meta_information_format {
|
||||||
@@ -152,20 +166,20 @@ typedef struct lsfs_file {
|
|||||||
int lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
|
int lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
while((p_control.master_table[i].filename[0]) != 0 && !found) {
|
while((p_control.master_table.entries[i].filename[0]) != 0 && !found) {
|
||||||
if(strcmp( (path + 1 ), p_control.master_table[i].filename ) == 0) {
|
if(strcmp( (path + 1 ), p_control.master_table.entries[i].filename ) == 0) {
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
time ( ¤t_time );
|
time ( ¤t_time );
|
||||||
|
|
||||||
find_file->file_id = p_control.master_table[i].file_id;
|
find_file->file_id = p_control.master_table.entries[i].file_id;
|
||||||
find_file->table_entry_pointer = i;
|
find_file->table_entry_pointer = i;
|
||||||
find_file->filename = p_control.master_table[i].filename;
|
find_file->filename = p_control.master_table.entries[i].filename;
|
||||||
find_file->owner_id = getuid();
|
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->size = p_control.master_table.entries[i].file_size; // p_control.master_table.entries[i].data_pointer[0]; //;
|
||||||
find_file->creation_date = (uint64_t) current_time;
|
find_file->creation_date = (uint64_t) current_time;
|
||||||
find_file->access_time = (uint64_t) current_time;
|
find_file->access_time = (uint64_t) current_time;
|
||||||
find_file->modification_time = (uint64_t) current_time;
|
find_file->modification_time = (uint64_t) current_time;
|
||||||
find_file->data = p_control.master_table[i].data_pointer;
|
find_file->data = p_control.master_table.entries[i].data_pointer;
|
||||||
find_file->file_block_size = 1; // TODO: should be loaded from disk.
|
find_file->file_block_size = 1; // TODO: should be loaded from disk.
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
@@ -224,7 +238,7 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data) {
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
assert(current_sector <= NUM_DATA_POINTERS);
|
assert(current_sector <= NUM_DATA_POINTERS);
|
||||||
written = written + write_data_to_disk(p_control.master_table[file->file_id].data_pointer[current_sector], 4, tmp_buffer);
|
written = written + write_data_to_disk(p_control.master_table.entries[file->file_id].data_pointer[current_sector], 4, tmp_buffer);
|
||||||
if (data_length <= 0) break;
|
if (data_length <= 0) break;
|
||||||
|
|
||||||
data += SECTOR_SIZE;
|
data += SECTOR_SIZE;
|
||||||
@@ -255,7 +269,7 @@ time_t lsfs_disk_truncate_file(lsfs_file *file, off_t offset) {
|
|||||||
//read_data_from_disk(file_id, &file_mif);
|
//read_data_from_disk(file_id, &file_mif);
|
||||||
|
|
||||||
time_t result = lsfs_disk_update_timestamps(file);
|
time_t result = lsfs_disk_update_timestamps(file);
|
||||||
file->size = (int) offset; // p_control.master_table[i].data_pointer[0]; //;
|
file->size = (int) offset; // p_control.master_table.entries[i].data_pointer[0]; //;
|
||||||
|
|
||||||
save_modified_file_information(file);
|
save_modified_file_information(file);
|
||||||
//write_data_to_disk(file->file_id, 4, NULL);
|
//write_data_to_disk(file->file_id, 4, NULL);
|
||||||
@@ -265,16 +279,16 @@ time_t lsfs_disk_truncate_file(lsfs_file *file, off_t offset) {
|
|||||||
// int lsfs_disk_rename_tag(lsfs_file_id file_id, char* new_filename) {
|
// int lsfs_disk_rename_tag(lsfs_file_id file_id, char* new_filename) {
|
||||||
// for (int i = 0; i < MAX_MASTER_TAGS; ++i)
|
// for (int i = 0; i < MAX_MASTER_TAGS; ++i)
|
||||||
// {
|
// {
|
||||||
// if(p_control.master_table[i].file_id == file_id) {
|
// if(p_control.master_table.entries[i].file_id == file_id) {
|
||||||
// memset(p_control.master_table[i].filename, 0, sizeof(p_control.master_table[i].filename));
|
// memset(p_control.master_table.entries[i].filename, 0, sizeof(p_control.master_table.entries[i].filename));
|
||||||
// sprintf(p_control.master_table[i].filename, "%s", new_filename);
|
// sprintf(p_control.master_table.entries[i].filename, "%s", new_filename);
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// // free the sectors including the tag table
|
// // free the sectors including the tag table
|
||||||
|
|
||||||
// // Save the changes to disk
|
// // Save the changes to disk
|
||||||
// fseek ( disk , (p_control.fsci->master_tag_records[0] * SECTOR_SIZE) , SEEK_SET );
|
// fseek ( disk , (p_control.fsci.master_tag_records[0] * SECTOR_SIZE) , SEEK_SET );
|
||||||
// fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk);
|
// fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk);
|
||||||
// return 1;
|
// return 1;
|
||||||
// }
|
// }
|
||||||
@@ -330,13 +344,13 @@ int lsfs_disk_delete_file(lsfs_file_id file_id) {
|
|||||||
|
|
||||||
for (int i = 0; i < MAX_MASTER_TAGS; ++i)
|
for (int i = 0; i < MAX_MASTER_TAGS; ++i)
|
||||||
{
|
{
|
||||||
if(p_control.master_table[i].file_id == file_id) {
|
if(p_control.master_table.entries[i].file_id == file_id) {
|
||||||
p_control.master_table[i] = p_control.master_table[i+1];
|
p_control.master_table.entries[i] = p_control.master_table[i+1];
|
||||||
truncate_table = 1;
|
truncate_table = 1;
|
||||||
printf("Tag deleted from master table - TagID: %lu\n", file_id);
|
printf("Tag deleted from master table - TagID: %lu\n", file_id);
|
||||||
}
|
}
|
||||||
else if (truncate_table) {
|
else if (truncate_table) {
|
||||||
p_control.master_table[i] = p_control.master_table[i+1];
|
p_control.master_table.entries[i] = p_control.master_table[i+1];
|
||||||
if (p_control.master_table[i+1].file_id == 0) {
|
if (p_control.master_table[i+1].file_id == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -345,7 +359,7 @@ int lsfs_disk_delete_file(lsfs_file_id file_id) {
|
|||||||
// free the sectors including the tag table
|
// free the sectors including the tag table
|
||||||
|
|
||||||
// Save the changes to disk
|
// Save the changes to disk
|
||||||
fseek ( disk , (p_control.fsci->master_tag_records[0] * SECTOR_SIZE) , SEEK_SET );
|
fseek ( disk , (p_control.fsci.master_tag_records[0] * SECTOR_SIZE) , SEEK_SET );
|
||||||
fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk);
|
fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk);
|
||||||
free(tag_table);
|
free(tag_table);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -460,7 +474,7 @@ int lsfs_disk_delete_file(lsfs_file_id file_id) {
|
|||||||
//printf("Sector number: %lu, is assignt to you \n", (*free_sectors));
|
//printf("Sector number: %lu, is assignt to you \n", (*free_sectors));
|
||||||
//char* data = "red_file_1\nred_file_2\n";
|
//char* data = "red_file_1\nred_file_2\n";
|
||||||
//char* sector_to_write = write_mechanism_new_buffer(data);
|
//char* sector_to_write = write_mechanism_new_buffer(data);
|
||||||
fseek ( disk , (p_control.fsci->master_tag_records[0] * SECTOR_SIZE) , SEEK_SET );
|
fseek ( disk , (p_control.fsci.master_tag_records[0] * SECTOR_SIZE) , SEEK_SET );
|
||||||
fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk);
|
fwrite(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE, disk);
|
||||||
|
|
||||||
fseek ( disk , ((*free_sectors) * SECTOR_SIZE) , SEEK_SET );
|
fseek ( disk , ((*free_sectors) * SECTOR_SIZE) , SEEK_SET );
|
||||||
@@ -485,17 +499,17 @@ int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) {
|
|||||||
if (num_sectors_needed > 1) {
|
if (num_sectors_needed > 1) {
|
||||||
for (int i = 0; i < num_sectors_needed; ++i)
|
for (int i = 0; i < num_sectors_needed; ++i)
|
||||||
{
|
{
|
||||||
output_array[i] = p_control.fsci->next_free_sector;
|
output_array[i] = p_control.fsci.next_free_sector;
|
||||||
p_control.fsci->next_free_sector++;
|
p_control.fsci.next_free_sector++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
output_array[0] = p_control.fsci->next_free_sector;
|
output_array[0] = p_control.fsci.next_free_sector;
|
||||||
p_control.fsci->next_free_sector++;
|
p_control.fsci.next_free_sector++;
|
||||||
}
|
}
|
||||||
printf("Sector %lu is assignt\n", output_array[0]);
|
printf("Sector %lu is assignt\n", output_array[0]);
|
||||||
write_data_to_disk(0, 4, p_control.fsci);
|
write_data_to_disk(0, 4, &p_control.fsci);
|
||||||
return p_control.fsci->next_free_sector;
|
return p_control.fsci.next_free_sector;
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_file_system() {
|
int create_file_system() {
|
||||||
@@ -547,7 +561,7 @@ int lsfs_disk_load_disk() {
|
|||||||
printf("%d\n", mbr.partitions[i].LBA_abs_first_sector);
|
printf("%d\n", mbr.partitions[i].LBA_abs_first_sector);
|
||||||
// First we find the Mater Table.
|
// First we find the Mater Table.
|
||||||
fseek ( disk , mbr.partitions[i].LBA_abs_first_sector * SECTOR_SIZE, SEEK_SET );
|
fseek ( disk , mbr.partitions[i].LBA_abs_first_sector * SECTOR_SIZE, SEEK_SET );
|
||||||
fread(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE , disk);
|
fread(&p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE , disk);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -616,12 +630,12 @@ lsfs_file_id lsfs_disk_create_file(char* filename, lsfs_file_id* tags, void* fil
|
|||||||
int save_modified_file_information(lsfs_file* file) {
|
int save_modified_file_information(lsfs_file* file) {
|
||||||
// Write the file struct into the table_entry, such that we can save the data correct.
|
// Write the file struct into the table_entry, such that we can save the data correct.
|
||||||
|
|
||||||
p_control.master_table[file->table_entry_pointer].file_id = file->file_id;
|
p_control.master_table.entries[file->table_entry_pointer].file_id = file->file_id;
|
||||||
memcpy(p_control.master_table[file->table_entry_pointer].filename, file->filename, 256);
|
memcpy(p_control.master_table.entries[file->table_entry_pointer].filename, file->filename, 256);
|
||||||
p_control.master_table[file->table_entry_pointer].file_size = file->size; // p_control.master_table[i].data_pointer[0]; //;
|
p_control.master_table.entries[file->table_entry_pointer].file_size = file->size; // p_control.master_table.entries[i].data_pointer[0]; //;
|
||||||
//p_control.master_table[i].data_pointer = find_file->data;
|
//p_control.master_table.entries[i].data_pointer = find_file->data;
|
||||||
|
|
||||||
write_data_to_disk(file->table_entry_pointer, file->file_block_size, &p_control.master_table[file->table_entry_pointer]);
|
write_data_to_disk(file->table_entry_pointer, file->file_block_size, &p_control.master_table.entries[file->table_entry_pointer]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -217,8 +217,8 @@ int lsfs_readdir( const char *path, void *buf, fuse_fill_dir_t filler, off_t off
|
|||||||
filler(buf, "..", NULL, 0);
|
filler(buf, "..", NULL, 0);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(strcmp( "", p_control.master_table[i].filename ) != 0) {
|
while(strcmp( "", p_control.master_table.entries[i].filename ) != 0) {
|
||||||
filler(buf, p_control.master_table[i].filename, NULL, 0);
|
filler(buf, p_control.master_table.entries[i].filename, NULL, 0);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,8 +311,6 @@ end:
|
|||||||
int main( int argc, char *argv[] ) {
|
int main( int argc, char *argv[] ) {
|
||||||
// "/home/rhodez-x/Documents/github/SingOS/SingOS.img"
|
// "/home/rhodez-x/Documents/github/SingOS/SingOS.img"
|
||||||
disk = fopen ("/home/rhodez-x/Documents/github/SingOS/SingOS.img", "r+b");
|
disk = fopen ("/home/rhodez-x/Documents/github/SingOS/SingOS.img", "r+b");
|
||||||
p_control.fsci = malloc(sizeof(FSCI));
|
|
||||||
p_control.master_table = malloc(sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE);
|
|
||||||
if (lsfs_disk_load_disk())
|
if (lsfs_disk_load_disk())
|
||||||
{
|
{
|
||||||
return fuse_main( argc, argv, &lsfs_oper );
|
return fuse_main( argc, argv, &lsfs_oper );
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in new issue
Block a user