diff --git a/SingOS.img b/SingOS.img new file mode 100644 index 0000000..9566a05 Binary files /dev/null and b/SingOS.img differ diff --git a/a.out b/a.out index c66b55b..706becf 100755 Binary files a/a.out and b/a.out differ diff --git a/lsfs_disk_controller.h b/lsfs_disk_controller.h index 19edb5b..e98fd36 100644 --- a/lsfs_disk_controller.h +++ b/lsfs_disk_controller.h @@ -46,9 +46,9 @@ int read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void int write_data_to_disk_off(lsfs_sector_offset index, void* data_to_write, int offset); int save_modified_file_information(lsfs_file* file); -#define SPACE_MBR_RECORD 2048; // Sectors -#define SPACE_VBR_RECORD 2048; // Sectors -#define SIZE_FSCI_RECORD 1; // Sectors +#define SPACE_MBR_RECORD 2048 // Sectors +#define SPACE_VBR_RECORD 2048 // Sectors +#define SIZE_FSCI_RECORD 1 // Sectors #define SECTOR_SIZE 512 // BYTES #define NUMBER_OF_MBR_PARTITIONS 4 #define DEFAULT_FILE_SIZE 4 // This is in sectors @@ -78,7 +78,7 @@ typedef struct Master_Boot_record { uint8_t offset_on_disk[446]; // The code for the bootloader Partition_Entry partitions[4]; - uint8_t master_tag_records[2]; // Signature + uint16_t mbr_signature; // Signature } __attribute__((packed)) Master_Boot_record; typedef struct struct_table_entry @@ -111,7 +111,7 @@ typedef struct File_System_Control_Information uint64_t next_sector_reuse_pointer; uint64_t last_sector_index_on_partition; uint64_t maximum_sectors_on_disk; - uint64_t sectors_size_on_disk; + uint64_t sector_size_on_disk; uint64_t not_used[24]; } __attribute__((packed)) FSCI; @@ -396,8 +396,7 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys // to master tag tables // Second and forward is the pointers to the master Tag Tables // we need the first number to allocate memory at one go. - int* zero_buffer; - FSCI fsci; + FSCI *fsci = calloc(1, sizeof(FSCI)); if (hdd_or_partition[0] == '1') { // This is the create hdd case @@ -408,13 +407,15 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys { // This is just a single partition // And then the file system is the only thing in the system. - fsci.filesystem_information = "LSFS v0.2.0-exp\n(LessSimpelFileSystem)(Generated by the disk_manager_utility.c)\nDeveloped to SingOS\nby Jorn Guldberg\n"; - fsci.this_partition_offset_on_disk = SPACE_VBR_RECORD; - fsci.master_table_index = fsci.this_partition_offset_on_disk + SIZE_FSCI_RECORD; - fsci.next_free_sector = fsci.master_table_index + DEFAULT_TABLE_SIZE; - fsci.next_uniqe_id = 1; - fsci.next_sector_reuse_pointer = 0; - fsci.last_sector_index_on_partition = filesystem_size_in_MB * 2048; // Todo, this is the ssectors pr MB, this should not be hardcoded. + sprintf(fsci->filesystem_information, "LSFS v0.2.0-exp\n(LessSimpelFileSystem)(Generated by the disk_manager_utility.c)\nDeveloped to SingOS\nby Jorn Guldberg\n"); + fsci->this_partition_offset_on_disk = SPACE_VBR_RECORD; + fsci->master_table_index = fsci->this_partition_offset_on_disk + SIZE_FSCI_RECORD; + fsci->next_free_sector = fsci->master_table_index + DEFAULT_TABLE_SIZE; + fsci->next_uniqe_id = 1; + fsci->next_sector_reuse_pointer = 0; + fsci->last_sector_index_on_partition = filesystem_size_in_MB * 2048; // Todo, this is the ssectors pr MB, this should not be hardcoded. + fsci->maximum_sectors_on_disk = 0; //TODO(Jørn) Not in use yet + fsci->sector_size_on_disk = SECTOR_SIZE; } else { @@ -422,28 +423,15 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys assert(NULL); } - - //fsci.maximum_sectors_on_partition = 1048576; // Max 4GiB - fsci.next_free_sector = 257; - // Create disk on host system: disk = fopen ( disk_name , "wb" ); - // Start writing data to the disk - fseek ( disk , 0, SEEK_SET ); - fwrite(&fsci, 1, sizeof(fsci), disk); - zero_buffer = calloc(1, (4096 - sizeof(fsci))); - fwrite(zero_buffer, 1, (4096 - sizeof(fsci)), disk); - free(zero_buffer); - /* MASTER TAG TABLE */ - - table_entry master_table[DEFAULT_TABLE_SIZE]; - memset(master_table, 0, (DEFAULT_TABLE_SIZE * sizeof(table_entry))); + write_data_to_disk(fsci->this_partition_offset_on_disk, 1, fsci); - fwrite(&master_table, 1, sizeof(master_table), disk); - zero_buffer = calloc(1, 16); - fwrite(zero_buffer, 1, 16, disk); + char* zero_buffer = calloc(1, (DEFAULT_TABLE_SIZE * SECTOR_SIZE)); + write_data_to_disk(fsci->master_table_index, DEFAULT_TABLE_SIZE, zero_buffer); free(zero_buffer); + return 0; } @@ -454,25 +442,40 @@ int lsfs_disk_load_disk() { Master_Boot_record mbr; fseek( disk , 0 * SECTOR_SIZE, SEEK_SET ); fread(&mbr, 1, sizeof(mbr), disk); - - for (int i = 0; i < NUMBER_OF_MBR_PARTITIONS; ++i) + if (mbr.mbr_signature != 0xaa55 ) { - // TODO (Jørn) We maybe wnat to optimize, such that we can detect if we have more than one partition opn the system. - if (mbr.partitions[i].partition_type == 0x18) + // Means that it is a sigle partition we try to mount + fseek(disk, (SPACE_VBR_RECORD * SECTOR_SIZE), SEEK_SET ); + fread(&p_control.fsci, 1, SECTOR_SIZE , disk); + //printf("next free sector: %d\n", p_control.fsci.next_free_sector); + //printf("next free ID: %d\n", p_control.fsci.next_uniqe_id); + + // next we find the Mater Table. + fseek (disk, (p_control.fsci.master_table_index * SECTOR_SIZE), SEEK_SET ); + fread(&p_control.master_table, 1, DEFAULT_TABLE_SIZE * SECTOR_SIZE , disk); + return 1; + } + else + { + for (int i = 0; i < NUMBER_OF_MBR_PARTITIONS; ++i) { - printf("%d\n", mbr.partitions[i].LBA_abs_first_sector); + // TODO (Jørn) We maybe wnat to optimize, such that we can detect if we have more than one partition opn the system. + if (mbr.partitions[i].partition_type == 0x18) + { + printf("%d\n", mbr.partitions[i].LBA_abs_first_sector); - // First we find the File system control information. - fseek ( disk , mbr.partitions[i].LBA_abs_first_sector * SECTOR_SIZE, SEEK_SET ); - fread(&p_control.fsci, 1, SECTOR_SIZE , disk); - //printf("next free sector: %d\n", p_control.fsci.next_free_sector); - //printf("next free ID: %d\n", p_control.fsci.next_uniqe_id); + // First we find the File system control information. + fseek(disk , mbr.partitions[i].LBA_abs_first_sector * SECTOR_SIZE, SEEK_SET ); + fread(&p_control.fsci, 1, SECTOR_SIZE , disk); + //printf("next free sector: %d\n", p_control.fsci.next_free_sector); + //printf("next free ID: %d\n", p_control.fsci.next_uniqe_id); - // next we find the Mater Table. - fseek ( disk , (mbr.partitions[i].LBA_abs_first_sector + 1) * SECTOR_SIZE, SEEK_SET ); - fread(&p_control.master_table, 1, DEFAULT_TABLE_SIZE * SECTOR_SIZE , disk); + // next we find the Mater Table. + fseek (disk, p_control.fsci.master_table_index * SECTOR_SIZE, SEEK_SET ); + fread(&p_control.master_table, 1, DEFAULT_TABLE_SIZE * SECTOR_SIZE , disk); - return 1; + return 1; + } } } return 0; diff --git a/lsfs_fuse b/lsfs_fuse index 9611d5b..3fc2f9b 100755 Binary files a/lsfs_fuse and b/lsfs_fuse differ diff --git a/lsfs_fuse.c b/lsfs_fuse.c index cb93b7d..952cec0 100644 --- a/lsfs_fuse.c +++ b/lsfs_fuse.c @@ -217,7 +217,8 @@ int lsfs_mknod(const char *path, mode_t mode, dev_t device) { int main( int argc, char *argv[] ) { // "/home/rhodez-x/Documents/github/SingOS/SingOS.img" - disk = fopen ("/home/rhodezx/Documents/github/SingOS/SingOS.img", "r+b"); + //disk = fopen ("/home/rhodezx/Documents/github/SingOS/SingOS.img", "r+b"); + disk = fopen ("SingOS.img", "r+b"); if (lsfs_disk_load_disk()) { return fuse_main( argc, argv, &lsfs_oper ); diff --git a/lsfs_fuse.o b/lsfs_fuse.o index 644b793..0510362 100644 Binary files a/lsfs_fuse.o and b/lsfs_fuse.o differ