diff --git a/SingOS.img b/SingOS.img index bad421b..615ddcc 100644 Binary files a/SingOS.img and b/SingOS.img differ diff --git a/a.out b/a.out index 80285b3..d9b6291 100755 Binary files a/a.out and b/a.out differ diff --git a/lsfs_disk_controller.h b/lsfs_disk_controller.h index a50473b..b3108e9 100644 --- a/lsfs_disk_controller.h +++ b/lsfs_disk_controller.h @@ -83,6 +83,16 @@ typedef struct Master_Boot_record uint16_t mbr_signature; // Signature } __attribute__((packed)) Master_Boot_record; +typedef struct Volume_Boot_record +{ + uint8_t code[446]; // The code for the bootloader + uint64_t vbr_size_in_bytes; // Signature + uint64_t vbr_LBA_address; + uint64_t vbr_LBA_FSCI_position; + uint64_t not_used[5]; + uint16_t vbr_signature; // Signature +} __attribute__((packed)) Volume_Boot_record; + typedef struct struct_table_entry { char filename[256]; @@ -240,9 +250,9 @@ int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data, int amount_read = 0; int amount_to_read = 0; int remaining_offset = offset_to_next_entry; - printf("READ: buffer_size: %d\n", buffer_size); - printf("READ: Data length: %d\n", data_length); - printf("READ: Offset length: %d\n", offset_to_next_entry); + //printf("READ: buffer_size: %d\n", buffer_size); + //printf("READ: Data length: %d\n", data_length); + //printf("READ: Offset length: %d\n", offset_to_next_entry); int data_pointer_index = 0; // start at first data pointer. @@ -254,7 +264,7 @@ int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data, while(data_length > 0) // We have more to write { - printf("READ: Remaing Data length: %d\n", data_length); + //printf("READ: Remaing Data length: %d\n", data_length); if (remaining_offset == 0) { char *tmp_buffer = calloc(DEFAULT_DATA_POINTER_SIZE, SECTOR_SIZE); @@ -418,7 +428,7 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s //write_data_to_disk(file->file_id, 4, &p_control.master_table[file->file_id]); // Should return the total new file size - printf("We Think that we have written: %d \n", amount_written); + //printf("We Think that we have written: %d \n", amount_written); return amount_written; } @@ -635,13 +645,43 @@ int lsfs_disk_install_vbr(char *vbr_path) struct stat st; stat(vbr_path, &st); FILE *vbr = fopen ( vbr_path , "r+b" ); - void *vbr_buffer = calloc(1, (SPACE_VBR_RECORD * SECTOR_SIZE)); + Volume_Boot_record *vbr_first_sector = calloc(1, SECTOR_SIZE); + void *vbr_buffer_rest = calloc(1, (SPACE_VBR_RECORD * SECTOR_SIZE - 1)); - + // First load first sector fseek(vbr, 0, SEEK_SET); - fread(vbr_buffer, 1, st.st_size, vbr); - printf("Sector index for vbr: %d - %d\n", (p_control.fsci.this_partition_offset_on_disk - SPACE_VBR_RECORD), st.st_size); - write_data_to_disk((p_control.fsci.this_partition_offset_on_disk - SPACE_VBR_RECORD), SPACE_VBR_RECORD, vbr_buffer); // Write this to the first sector of the disk. + fread(vbr_first_sector, 1, SECTOR_SIZE, vbr); + + fseek(vbr, SECTOR_SIZE, SEEK_SET); + fread(vbr_buffer_rest, 1, (st.st_size - SECTOR_SIZE), vbr); + + vbr_first_sector->vbr_size_in_bytes = st.st_size; + vbr_first_sector->vbr_LBA_address = p_control.fsci.this_partition_offset_on_disk; + vbr_first_sector->vbr_LBA_FSCI_position = p_control.fsci.this_partition_offset_on_disk + SPACE_VBR_RECORD; + vbr_first_sector->vbr_signature = 0x1818; + + printf("VBR size: %d\n", vbr_first_sector->vbr_size_in_bytes); + printf("VBR lba address: %d\n", vbr_first_sector->vbr_LBA_address); + printf("VBR FSCI: %d\n", vbr_first_sector->vbr_LBA_FSCI_position); + + write_data_to_disk((p_control.fsci.this_partition_offset_on_disk - SPACE_VBR_RECORD), 1, vbr_first_sector); // Write this to the first sector of the disk. + write_data_to_disk((p_control.fsci.this_partition_offset_on_disk - SPACE_VBR_RECORD + 1), (SPACE_VBR_RECORD - 1), vbr_buffer_rest); // Write this to the first sector of the disk. + + Master_Boot_record mbr; + fseek( disk , 0 * SECTOR_SIZE, SEEK_SET ); + fread(&mbr, 1, sizeof(mbr), disk); + + + if (mbr.mbr_signature == 0xaa55 ) + { + mbr.partitions[0].active_falg = 0x80; // TODO(Jørn) Hardcoded partition. + write_data_to_disk(0, 1, &mbr); + } + else + { + return -EINVAL; + } + return 0; } diff --git a/lsfs_fuse b/lsfs_fuse index 5b3c1b0..39f5eb4 100755 Binary files a/lsfs_fuse and b/lsfs_fuse differ diff --git a/lsfs_fuse.o b/lsfs_fuse.o index 1c01761..2afd71e 100644 Binary files a/lsfs_fuse.o and b/lsfs_fuse.o differ