From e7b27de2ce144752268750b79027f880e0c998fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Guldberg?= Date: Fri, 10 Jul 2020 22:39:32 +0200 Subject: [PATCH] CLI interface starting to be implemented --- .gitmodules | 3 ++ build.sh | 0 disk_manager_utility.c | 113 ++++++++++++++++++++++++++++++++++++++--- lsfs_disk_controller.h | 10 ++-- lsfs_vbr/lsfs_16-bit | 1 + 5 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 .gitmodules create mode 100644 build.sh create mode 160000 lsfs_vbr/lsfs_16-bit diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b007114 --- /dev/null +++ b/.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 diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..e69de29 diff --git a/disk_manager_utility.c b/disk_manager_utility.c index bb93011..f68fc67 100644 --- a/disk_manager_utility.c +++ b/disk_manager_utility.c @@ -109,14 +109,14 @@ int dmu_install_SingOS(char* disk_name) { int dmu_create_file_system(char* disk_name) { 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 do { 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"); scanf("%s", input_size_file_system); @@ -126,7 +126,7 @@ int dmu_create_file_system(char* disk_name) { printf("Create new disk img\n"); create_file_system(disk_name, hdd_or_partition, filesystem_size_in_MB); printf("Disk is created as: %s\n", disk_name); - + fclose (disk); // TODO: Do you want to install SingOS: @@ -135,14 +135,16 @@ int dmu_create_file_system(char* disk_name) { return 1; } -int dmu_load_file_system(char* disk_name) { +int dmu_load_file_system(char* disk_name) +{ disk = fopen ( disk_name , "r+b" ); lsfs_disk_load_disk(); disk_is_loaded = 1; return 1; } -int dmu_install_bootloader(char* disk_name) { +int dmu_install_bootloader(char* disk_name) +{ lsfs_disk_install_bootloader(disk_name); 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[]) { 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 diff --git a/lsfs_disk_controller.h b/lsfs_disk_controller.h index 051d096..252b0e4 100644 --- a/lsfs_disk_controller.h +++ b/lsfs_disk_controller.h @@ -30,7 +30,7 @@ static FILE* disk; static partition_control p_control; 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); Directory_Table* lsfs_find_directory(const char* path, bool drop_filename); 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; } -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; // make default File System Control information (FSCI) // 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" ); 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 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 // 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"); - if (hdd_or_partition[0] == '1') + if (hdd_or_partition == '1') { fsci->this_partition_offset_on_disk = SPACE_MBR_RECORD + SPACE_VBR_RECORD; } diff --git a/lsfs_vbr/lsfs_16-bit b/lsfs_vbr/lsfs_16-bit new file mode 160000 index 0000000..7349805 --- /dev/null +++ b/lsfs_vbr/lsfs_16-bit @@ -0,0 +1 @@ +Subproject commit 73498055ec46bfa2290684b3a2129aebf1ee4f4a