Disk manager utility can now create hdd format
This commit is contained in:
1 parent
3264a78cdb
commit
b172a091a7
1 file changed
+31
-17
+31
-17
@@ -417,24 +417,46 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
|
|||||||
// Second and forward is the pointers to the 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.
|
// we need the first number to allocate memory at one go.
|
||||||
FSCI *fsci = calloc(1, sizeof(FSCI));
|
FSCI *fsci = calloc(1, sizeof(FSCI));
|
||||||
|
// Create disk on host system:
|
||||||
|
|
||||||
|
disk = fopen ( disk_name , "wb" );
|
||||||
|
ftruncate(fileno(disk), (filesystem_size_in_MB * 2048 * 512));
|
||||||
|
|
||||||
if (hdd_or_partition[0] == '1')
|
if (hdd_or_partition[0] == '1')
|
||||||
{
|
{
|
||||||
// This is the create hdd case
|
// This is the create hdd case
|
||||||
// This means that we setup the partition table.
|
// This means that we setup the partition table.
|
||||||
;
|
Master_Boot_record *mbr = calloc(1, sizeof(Master_Boot_record));
|
||||||
|
mbr->partitions[0].partition_type = 0x18;
|
||||||
|
mbr->partitions[0].LBA_abs_first_sector = 2048;
|
||||||
|
mbr->partitions[0].number_of_sectors = filesystem_size_in_MB * 2048;
|
||||||
|
mbr->mbr_signature = 0xaa55;
|
||||||
|
write_data_to_disk(0, 1, mbr); // Write this to the first sector of the disk.
|
||||||
}
|
}
|
||||||
else if (hdd_or_partition[0] == '2')
|
|
||||||
|
|
||||||
|
if ((hdd_or_partition[0] == '1') || (hdd_or_partition[0] == '2'))
|
||||||
{
|
{
|
||||||
|
printf("HEY YUP\n");
|
||||||
// This is just a single partition
|
// This is just a single partition
|
||||||
// And then the file system is the only thing in the system.
|
// And then the file system is the only thing in the system.
|
||||||
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");
|
sprintf(fsci->filesystem_information, "LSFS v1.0.0-a1\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;
|
|
||||||
|
if (hdd_or_partition[0] == '1')
|
||||||
|
{
|
||||||
|
fsci->this_partition_offset_on_disk = SPACE_MBR_RECORD + SPACE_VBR_RECORD;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fsci->this_partition_offset_on_disk = SPACE_VBR_RECORD;
|
||||||
|
}
|
||||||
|
|
||||||
fsci->master_table_index = fsci->this_partition_offset_on_disk + SIZE_FSCI_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_free_sector = fsci->master_table_index + DEFAULT_TABLE_SIZE;
|
||||||
fsci->next_uniqe_id = 1;
|
fsci->next_uniqe_id = 1;
|
||||||
fsci->next_sector_reuse_pointer = 0;
|
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->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->maximum_sectors_on_disk = filesystem_size_in_MB * 2048; //TODO(Jørn) Not in use yet
|
||||||
fsci->sector_size_on_disk = SECTOR_SIZE;
|
fsci->sector_size_on_disk = SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -443,16 +465,8 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
|
|||||||
assert(NULL);
|
assert(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create disk on host system:
|
|
||||||
disk = fopen ( disk_name , "wb" );
|
|
||||||
ftruncate(fileno(disk), SECTOR_SIZE * fsci->last_sector_index_on_partition);
|
|
||||||
|
|
||||||
write_data_to_disk(fsci->this_partition_offset_on_disk, 1, fsci);
|
write_data_to_disk(fsci->this_partition_offset_on_disk, 1, fsci);
|
||||||
|
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,13 +502,13 @@ 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 File system control information.
|
// First we find the File system control information.
|
||||||
fseek(disk , mbr.partitions[i].LBA_abs_first_sector * SECTOR_SIZE, SEEK_SET );
|
fseek(disk , ((mbr.partitions[i].LBA_abs_first_sector + SPACE_VBR_RECORD) * SECTOR_SIZE), SEEK_SET );
|
||||||
fread(&p_control.fsci, 1, SECTOR_SIZE , disk);
|
fread(&p_control.fsci, 1, SECTOR_SIZE , disk);
|
||||||
//printf("next free sector: %d\n", p_control.fsci.next_free_sector);
|
printf("next free sector: %d\n", p_control.fsci.next_free_sector);
|
||||||
//printf("next free ID: %d\n", p_control.fsci.next_uniqe_id);
|
printf("next free ID: %d\n", p_control.fsci.next_uniqe_id);
|
||||||
|
|
||||||
// next we find the Mater Table.
|
// next we find the Mater Table.
|
||||||
fseek (disk, p_control.fsci.master_table_index * SECTOR_SIZE, SEEK_SET );
|
fseek (disk, (p_control.fsci.master_table_index * SECTOR_SIZE), SEEK_SET );
|
||||||
fread(&p_control.master_table, 1, DEFAULT_TABLE_SIZE * SECTOR_SIZE , disk);
|
fread(&p_control.master_table, 1, DEFAULT_TABLE_SIZE * SECTOR_SIZE , disk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in new issue
Block a user