@ -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
// we need the first number to allocate memory at one go.
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 ' )
{
// This is the create hdd case
// 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
// 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) \n Developed to SingOS \n by Jorn Guldberg \n " ) ;
fsci - > this_partition_offset_on_disk = SPACE_VBR_RECORD ;
sprintf ( fsci - > filesystem_information , " LSFS v1.0.0-a1 \n (LessSimpelFileSystem)(Generated by the disk_manager_utility.c) \n Developed to SingOS \n by Jorn Guldberg \n " ) ;
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 - > 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 - > maximum_sectors_on_disk = filesystem_size_in_MB * 2 048 ; //TODO(Jørn) Not in use yet
fsci - > sector_size_on_disk = SECTOR_SIZE ;
}
else
@ -442,17 +464,9 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
// This is an error case, and we should not hit this case.
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 ) ;
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 ;
}
@ -488,13 +502,13 @@ int lsfs_disk_load_disk() {
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 ) ;
fseek ( disk , ( ( mbr . partitions [ i ] . LBA_abs_first_sector + 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);
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 ) ;
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 ;