Browse Source

Correct loading of master table from MBR

master
Jørn Guldberg 6 years ago
parent
commit
91d1e1d0f2
  1. 51
      lsfs_disk_controller.h
  2. BIN
      lsfs_fuse
  3. 20
      lsfs_fuse.c
  4. BIN
      lsfs_fuse.o

51
lsfs_disk_controller.h

@ -46,6 +46,7 @@ int save_modified_file_information(lsfs_file* file);
#define SECTOR_SIZE 512 #define SECTOR_SIZE 512
#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_MASTER_TABLE_SIZE 64 #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 ) #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; table_entry* master_table;
} __attribute__((packed)) partition_control; } __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 { typedef struct File_System_Control_Information {
uint64_t offset_on_disk; uint64_t offset_on_disk;
uint64_t next_partition; uint64_t next_partition;
@ -82,7 +100,7 @@ typedef struct struct_table_entry {
struct { struct {
uint32_t is_filename : 1; uint32_t is_filename : 1;
} control_bits; } control_bits;
lsfs_sector_offset data_pointer[NUM_DATA_POINTERS] lsfs_sector_offset data_pointer[NUM_DATA_POINTERS];
} __attribute__((packed)) table_entry; } __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); //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[i].data_pointer[0]; //;
save_modified_file_information(file); save_modified_file_information(file);
@ -515,16 +532,26 @@ int create_file_system() {
} }
int lsfs_disk_load_disk() { int lsfs_disk_load_disk() {
// Find the partition talbe:
// First we find the Mater Table. // This makes is BIOS dependent.
fseek ( disk , 24 * SECTOR_SIZE, SEEK_SET ); // UEFI is not supported.
fread(p_control.master_table, 1, sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE , disk); Master_Boot_record mbr;
fseek( disk , 0 * SECTOR_SIZE, SEEK_SET );
// Now we can finde the FSCI data fread(&mbr, 1, sizeof(mbr), disk);
//fseek ( disk , 0, SEEK_SET );
//fread(p_control.fsci, 1, sizeof(FSCI), disk); for (int i = 0; i < NUMBER_OF_MBR_PARTITIONS; ++i)
{
return 1; // 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;
} }

BIN
lsfs_fuse

Binary file not shown.

20
lsfs_fuse.c

@ -305,6 +305,7 @@ int lsfs_mknod(const char *path, mode_t mode, dev_t device) {
end: end:
lsfs_destroy_string_array(split_path); lsfs_destroy_string_array(split_path);
return res;*/ return res;*/
return 0;
} }
int main( int argc, char *argv[] ) { 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"); disk = fopen ("/home/rhodez-x/Documents/github/SingOS/SingOS.img", "r+b");
p_control.fsci = malloc(sizeof(FSCI)); p_control.fsci = malloc(sizeof(FSCI));
p_control.master_table = malloc(sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE); p_control.master_table = malloc(sizeof(table_entry) * DEFAULT_MASTER_TABLE_SIZE);
lsfs_disk_load_disk(); if (lsfs_disk_load_disk())
{
//tag_record *tag_table = calloc(1, SECTOR_SIZE); return fuse_main( argc, argv, &lsfs_oper );
//mif* mif_data = calloc(1, SECTOR_SIZE); }
else
//free(mif_data); {
//free(tag_table); printf("[ERROR] - Correct file format not found \n");
//free(seen_file_ids); return 0;
}
return fuse_main( argc, argv, &lsfs_oper );
} }

BIN
lsfs_fuse.o

Binary file not shown.
Loading…
Cancel
Save