diff --git a/lsfs_disk_controller.h b/lsfs_disk_controller.h index f42e156..edc51a9 100644 --- a/lsfs_disk_controller.h +++ b/lsfs_disk_controller.h @@ -46,6 +46,7 @@ int save_modified_file_information(lsfs_file* file); #define SECTOR_SIZE 512 +#define NUMBER_OF_MBR_PARTITIONS 4 #define DEFAULT_FILE_SIZE 4 // This is in sectors #define DEFAULT_MASTER_TABLE_SIZE 64 #define DEFAULT_TAG_TABLE_SIZE 64 // correspond to 262144 bytes in sectors - 16384 files pr. default. (minus one, the last is a pointer to a table more ) @@ -62,6 +63,23 @@ typedef struct struct_partition_control{ table_entry* master_table; } __attribute__((packed)) partition_control; +typedef struct Partition_Entry +{ + uint8_t active_falg; // This has value 0x80 if it is a bootable partition / it is an active partition. + uint8_t CHS_start_addr[3]; // [0] = H, [1] = S, [2] = C + uint8_t partition_type; // This has a value such that one can idenfity which file system the partition is. + uint8_t CHS_last_addr[3]; // [0] = H, [1] = S, [2] = C + uint32_t LBA_abs_first_sector; + uint32_t number_of_sectors; + +} __attribute__((packed)) Partition_Entry; + +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 +} __attribute__((packed)) Master_Boot_record; + typedef struct File_System_Control_Information { uint64_t offset_on_disk; uint64_t next_partition; @@ -82,7 +100,7 @@ typedef struct struct_table_entry { struct { uint32_t is_filename : 1; } control_bits; - lsfs_sector_offset data_pointer[NUM_DATA_POINTERS] + lsfs_sector_offset data_pointer[NUM_DATA_POINTERS]; } __attribute__((packed)) table_entry; @@ -237,7 +255,6 @@ time_t lsfs_disk_truncate_file(lsfs_file *file, off_t offset) { //read_data_from_disk(file_id, &file_mif); time_t result = lsfs_disk_update_timestamps(file); - file->size = (int) offset; // p_control.master_table[i].data_pointer[0]; //; save_modified_file_information(file); @@ -515,16 +532,26 @@ int create_file_system() { } int lsfs_disk_load_disk() { - - // First we find the Mater Table. - fseek ( disk , 24 * SECTOR_SIZE, SEEK_SET ); - fread(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE , disk); - - // Now we can finde the FSCI data - //fseek ( disk , 0, SEEK_SET ); - //fread(p_control.fsci, 1, sizeof(FSCI), disk); - - return 1; + // Find the partition talbe: + // This makes is BIOS dependent. + // UEFI is not supported. + 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) + { + // 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 Mater Table. + 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); + return 1; + } + } + return 0; } diff --git a/lsfs_fuse b/lsfs_fuse index f69dac4..9247428 100755 Binary files a/lsfs_fuse and b/lsfs_fuse differ diff --git a/lsfs_fuse.c b/lsfs_fuse.c index 4676cfb..5bb2a5b 100644 --- a/lsfs_fuse.c +++ b/lsfs_fuse.c @@ -305,6 +305,7 @@ int lsfs_mknod(const char *path, mode_t mode, dev_t device) { end: lsfs_destroy_string_array(split_path); return res;*/ + return 0; } int main( int argc, char *argv[] ) { @@ -312,14 +313,13 @@ int main( int argc, char *argv[] ) { 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); - lsfs_disk_load_disk(); - - //tag_record *tag_table = calloc(1, SECTOR_SIZE); - //mif* mif_data = calloc(1, SECTOR_SIZE); - - //free(mif_data); - //free(tag_table); - //free(seen_file_ids); - - return fuse_main( argc, argv, &lsfs_oper ); + if (lsfs_disk_load_disk()) + { + return fuse_main( argc, argv, &lsfs_oper ); + } + else + { + printf("[ERROR] - Correct file format not found \n"); + return 0; + } } diff --git a/lsfs_fuse.o b/lsfs_fuse.o index 0e79c22..148ceb9 100644 Binary files a/lsfs_fuse.o and b/lsfs_fuse.o differ