瀏覽代碼

CLI interface starting to be implemented

master
Jørn Guldberg 3 年之前
父節點
當前提交
e7b27de2ce
共有 5 個檔案被更改,包括 116 行新增11 行删除
  1. +3
    -0
      .gitmodules
  2. +0
    -0
      build.sh
  3. +107
    -6
      disk_manager_utility.c
  4. +5
    -5
      lsfs_disk_controller.h
  5. +1
    -0
      lsfs_vbr/lsfs_16-bit

+ 3
- 0
.gitmodules 查看文件

@ -0,0 +1,3 @@
[submodule "lsfs_vbr/lsfs_16-bit"]
path = lsfs_vbr/lsfs_16-bit
url = git@git.imada.sdu.dk:Sandsized/lsfs_16-bit.git

+ 0
- 0
build.sh 查看文件


+ 107
- 6
disk_manager_utility.c 查看文件

@ -109,14 +109,14 @@ int dmu_install_SingOS(char* disk_name) {
int dmu_create_file_system(char* disk_name) { int dmu_create_file_system(char* disk_name) {
uint64_t filesystem_size_in_MB = 0; uint64_t filesystem_size_in_MB = 0;
char hdd_or_partition[8]; // 1: is harddisk, 2: is partition
char hdd_or_partition; // 1: is harddisk, 2: is partition
char input_size_file_system[64]; // in MB char input_size_file_system[64]; // in MB
do { do {
printf("Create as 1: harddrive or 2: as a single partition (enter 1 or 2): \n"); printf("Create as 1: harddrive or 2: as a single partition (enter 1 or 2): \n");
scanf("%s", hdd_or_partition);
scanf("%c", hdd_or_partition);
} while ((hdd_or_partition[0] != '1') && (hdd_or_partition[0] != '2'));
} while ((hdd_or_partition != '1') && (hdd_or_partition != '2'));
printf("Enter size of file system in MB (as an integer number): \n"); printf("Enter size of file system in MB (as an integer number): \n");
scanf("%s", input_size_file_system); scanf("%s", input_size_file_system);
@ -126,7 +126,7 @@ int dmu_create_file_system(char* disk_name) {
printf("Create new disk img\n"); printf("Create new disk img\n");
create_file_system(disk_name, hdd_or_partition, filesystem_size_in_MB); create_file_system(disk_name, hdd_or_partition, filesystem_size_in_MB);
printf("Disk is created as: %s\n", disk_name); printf("Disk is created as: %s\n", disk_name);
fclose (disk); fclose (disk);
// TODO: Do you want to install SingOS: // TODO: Do you want to install SingOS:
@ -135,14 +135,16 @@ int dmu_create_file_system(char* disk_name) {
return 1; return 1;
} }
int dmu_load_file_system(char* disk_name) {
int dmu_load_file_system(char* disk_name)
{
disk = fopen ( disk_name , "r+b" ); disk = fopen ( disk_name , "r+b" );
lsfs_disk_load_disk(); lsfs_disk_load_disk();
disk_is_loaded = 1; disk_is_loaded = 1;
return 1; return 1;
} }
int dmu_install_bootloader(char* disk_name) {
int dmu_install_bootloader(char* disk_name)
{
lsfs_disk_install_bootloader(disk_name); lsfs_disk_install_bootloader(disk_name);
return 1; return 1;
} }
@ -169,12 +171,111 @@ int dmu_print_mtt(char *path) {
} }
typedef struct Arguments_Settings
{
char* load_diskname;
char* new_diskname;
int new_disk_size_mb;
char* install_vbr_path;
char* install_bootloader_path;
char* copy_new_kernel;
} Arguments_Settings;
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
if (argc > 1) if (argc > 1)
{ {
Arguments_Settings* settings = calloc(1, sizeof(Arguments_Settings));
for (int i = 1; i < argc; i++)
{
// Parse parameters for cmd usage
switch(argv[i][1])
{
case 'n':
{
// Create new disk
i++; // Go to next parameter which is the path/filename for the new disk
if (i > argc)
{
// Go to loop condition to exit
continue;
}
settings->new_diskname = argv[i];
printf("Creating new disk: %s \n", settings->new_diskname);
} break;
case 's':
{
// Specify size of new disk
i++; // Go to next parameter which is the disk size
if (i > argc)
{
// Go to loop condition to exit
continue;
}
settings->new_disk_size_mb = atoi(argv[i]);
} break;
case 'v':
{
// Update Volume boot record
i++; // Go to next parameter which is the path for the VBR
if (i > argc)
{
// Go to loop condition to exit
continue;
}
settings->install_vbr_path = argv[i];
} break;
case 'b':
{
// Update bootloader
i++; // Go to next parameter which is the path for the VBR
if (i > argc)
{
// Go to loop condition to exit
continue;
}
settings->install_bootloader_path = argv[i];
} break;
}
}
// Now execute the commands.
// First check if we should create a new disk
if (settings->new_diskname != NULL)
{
// TODO(only harddisk is supported yet)
char hdd_or_partition = '1'; // 1 is harddrive
if (settings->new_disk_size_mb <= 0)
{
settings->new_disk_size_mb = 20; // 20MB is default size
}
create_file_system(settings->new_diskname, hdd_or_partition, settings->new_disk_size_mb);
settings->load_diskname = settings->new_diskname;
}
// Load the disk to complete the following instructions
if (settings->load_diskname != NULL)
{
dmu_load_file_system(settings->load_diskname);
if (settings->install_bootloader_path != NULL)
{
lsfs_disk_install_bootloader(settings->install_bootloader_path);
}
}
} }
else else

+ 5
- 5
lsfs_disk_controller.h 查看文件

@ -30,7 +30,7 @@ static FILE* disk;
static partition_control p_control; static partition_control p_control;
static time_t timestamp_loading; static time_t timestamp_loading;
int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesystem_size_in_MB);
int create_file_system(char* disk_name, char hdd_or_partition, uint64_t filesystem_size_in_MB);
int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind); int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind);
Directory_Table* lsfs_find_directory(const char* path, bool drop_filename); Directory_Table* lsfs_find_directory(const char* path, bool drop_filename);
int lsfs_disk_getattr(lsfs_file* find_file, const char *path); int lsfs_disk_getattr(lsfs_file* find_file, const char *path);
@ -567,7 +567,7 @@ int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) {
return 0; return 0;
} }
int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesystem_size_in_MB) {
int create_file_system(char* disk_name, char hdd_or_partition, uint64_t filesystem_size_in_MB) {
//char* sector_to_write; //char* sector_to_write;
// make default File System Control information (FSCI) // make default File System Control information (FSCI)
// first integer says how many pointers we got // first integer says how many pointers we got
@ -580,7 +580,7 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
disk = fopen ( disk_name , "wb" ); disk = fopen ( disk_name , "wb" );
ftruncate(fileno(disk), (filesystem_size_in_MB * 2048 * 512)); ftruncate(fileno(disk), (filesystem_size_in_MB * 2048 * 512));
if (hdd_or_partition[0] == '1')
if (hdd_or_partition == '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.
@ -593,13 +593,13 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
} }
if ((hdd_or_partition[0] == '1') || (hdd_or_partition[0] == '2'))
if ((hdd_or_partition == '1') || (hdd_or_partition == '2'))
{ {
// 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 v1.0.0-a1\r\n(LessSimpelFileSystem)(Generated by the disk_manager_utility.c)\r\nDeveloped to SingOS\r\nby Jorn Guldberg\r\n"); sprintf(fsci->filesystem_information, "LSFS v1.0.0-a1\r\n(LessSimpelFileSystem)(Generated by the disk_manager_utility.c)\r\nDeveloped to SingOS\r\nby Jorn Guldberg\r\n");
if (hdd_or_partition[0] == '1')
if (hdd_or_partition == '1')
{ {
fsci->this_partition_offset_on_disk = SPACE_MBR_RECORD + SPACE_VBR_RECORD; fsci->this_partition_offset_on_disk = SPACE_MBR_RECORD + SPACE_VBR_RECORD;
} }

+ 1
- 0
lsfs_vbr/lsfs_16-bit

@ -0,0 +1 @@
Subproject commit 73498055ec46bfa2290684b3a2129aebf1ee4f4a

Loading…
取消
儲存