From 54ec5691212c1e140fb52ebacb8e0fce1b13b562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Guldberg?= Date: Sun, 12 Jul 2020 23:13:19 +0200 Subject: [PATCH] Fixed compile warnings, improved CLI interface --- build.sh | 2 ++ disk_manager | Bin 0 -> 27952 bytes disk_manager_utility.c | 18 ++++++---- lsfs_disk_controller.h | 75 +++++++++++++++++++++++++---------------- lsfs_string.h | 20 +++++------ lsfs_vbr/build.sh | 6 ++++ 6 files changed, 75 insertions(+), 46 deletions(-) create mode 100755 disk_manager create mode 100644 lsfs_vbr/build.sh diff --git a/build.sh b/build.sh index e69de29..8afdb57 100644 --- a/build.sh +++ b/build.sh @@ -0,0 +1,2 @@ +gcc -Wall -Wextra -Wpedantic disk_manager_utility.c -o disk_manager + diff --git a/disk_manager b/disk_manager new file mode 100755 index 0000000000000000000000000000000000000000..539d6dcbd30dcdb81a8982ce82515e464c5301b0 GIT binary patch literal 27952 zcmeHw4|r77weQZKkq{sg6*N^_jtUi2Vn9GZqe)=k#3mRev9|u1Op*zt=3g^22$o>z z5XcE?@Wm)QG`*yN&u9IC1MIb zKP@g0XCR-=I7u&&095&`%S?tj3ZDf?ayu106<(nDG}IOnB)N1?{uD{kP~^)z$+;-0 z@~QB~xsp#qO}EP{k#xIaDqlNQ;x%;2k#C}vk{-Q18Rn1!@NBqBLM=z`Ah|ImH>Tt? z99E9dQ2Ud7LVpL8KU3if(CE>Scn^bw} z{8FIo*H9HNu4rzmTfFd!=7xFAO|78~^END5Ja6&B!a!T$0n`|I`#6u79tKt|>G+iFi|0B<9U^;68#xtSFm;k>Z z4gZcb_|7!=x-|G}(%>U$@D#oi+5f3DcnZsj_?yz;`_tfWO@r@CgP)hipX<}`Q@5JP z&Tpo{{~-;2YZ`oe8vNO5@Q)BSnl%3TQ5yayfxifU;~w<0dg@k- zMWDT-sWsRr8r$0at)em55o)dX1^vS7Z3?v2FJ0;l)caZ+MSCb15W%JvA_RiI`a8Y# z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PRUhda9CwE&~h5S2ZB?6 zxK?rwD|u~as=Uts4GGev?br7eqe{MZq2`p(NY086k*D&DQt(>-tQ0))(&L0W_9R7q z=G-XZc6AX={TM%^8rT0P183VVMfmgK+ht}AO%9Gnm#a~9eKL{!NQ30aN)brOihlfilename); printf("File size: %lu\n", file->size); printf("Entry kind: %d\n", file->entry_kind); - printf("Index in directory table: %d\n", file->table_entry_pointer); + printf("Index in directory table: %lu\n", file->table_entry_pointer); printf("Sector index on disk: %lu\n", file->table_entry_sector_index); printf("\nData pointers:\n"); for (int i = 0; i < NUM_DATA_POINTERS; ++i) @@ -109,12 +109,12 @@ 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; // 1: is harddisk, 2: is partition + char hdd_or_partition = 0; // 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("%c", hdd_or_partition); + scanf("%c", &hdd_or_partition); } while ((hdd_or_partition != '1') && (hdd_or_partition != '2')); @@ -137,8 +137,7 @@ int dmu_create_file_system(char* disk_name) { int dmu_load_file_system(char* disk_name) { - disk = fopen ( disk_name , "r+b" ); - lsfs_disk_load_disk(); + lsfs_disk_load_disk(disk_name); disk_is_loaded = 1; return 1; } @@ -162,7 +161,7 @@ int dmu_print_mtt(char *path) { printf("\n|--------Filename------------|Not used----------------------|Entry ID----|\n"); for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i) { - printf("|%-28s|%-30lu|%-12d| \n", directory_table->entries[i].filename, directory_table->entries[i].file_id, directory_table->entries[i].file_id); + printf("|%-28s|%-30lu|%-12lu| \n", directory_table->entries[i].filename, directory_table->entries[i].file_id, directory_table->entries[i].file_id); printf("|----------------------------|------------------------------|------------|\n"); } @@ -274,6 +273,11 @@ int main (int argc, char *argv[]) { lsfs_disk_install_bootloader(settings->install_bootloader_path); } + sleep(1); + if (settings->install_vbr_path != NULL) + { + lsfs_disk_install_vbr(settings->install_vbr_path); + } } @@ -339,7 +343,7 @@ int main (int argc, char *argv[]) printf("Enter Directory:\n"); scanf("%s", input_buffer); - int new_id = lsfs_disk_create_entry(input_buffer, ENTRY_DIRECTORY ); + lsfs_disk_create_entry(input_buffer, ENTRY_DIRECTORY ); //lsfs_disk_write_data_to_file(new_id, strlen(new_file_data_d), new_file_data_d); } diff --git a/lsfs_disk_controller.h b/lsfs_disk_controller.h index 252b0e4..9b99ecc 100644 --- a/lsfs_disk_controller.h +++ b/lsfs_disk_controller.h @@ -20,13 +20,20 @@ typedef struct File_System_Control_Information FSCI; typedef struct meta_information_format mif; typedef struct tag_record tag_record; typedef struct lsfs_file lsfs_file; -typedef enum Table_Entry_Kind Table_Entry_Kind; typedef uint64_t lsfs_sector_offset; typedef lsfs_sector_offset lsfs_file_id; +typedef enum +{ + // These are specific values since, is has to corrospond to the implementation in assembly + ENTRY_EMPTY = 0, + ENTRY_FILE = 1, + ENTRY_DIRECTORY = 2, +} Table_Entry_Kind; + //typedef uint64_t sector_index; -static FILE* disk; +static FILE* disk = NULL; static partition_control p_control; static time_t timestamp_loading; @@ -36,11 +43,11 @@ 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_delete_entry(lsfs_file *file); int get_free_sectors_table(); -int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array); -int lsfs_disk_read_data_from_file(lsfs_file *file, int data_length, char *data, size_t offset_to_next_entry); -int lsfs_disk_write_data_to_file(lsfs_file* file, int data_length, char *data, size_t offset_to_next_entry); +int get_free_sectors(int num_sectors_needed, struct_table_entry* table_entry); +int lsfs_disk_read_data_from_file(lsfs_file *file, int data_length, char *data, int64_t offset_to_next_entry); +int lsfs_disk_write_data_to_file(lsfs_file* file, int data_length, char *data, int64_t offset_to_next_entry); int lsfs_disk_rename_file(const char* old_filename_, const char* new_filename); -int lsfs_disk_load_disk(); +int lsfs_disk_load_disk(char* diskname); int write_data_to_disk(lsfs_sector_offset at_sector, uint32_t number_sectors, void* data_to_write); int write_data_to_disk_off(lsfs_sector_offset index, uint32_t number_sectors, void* data_to_write, int offset); int read_data_from_disk(lsfs_sector_offset index, uint32_t number_sectors, void* data_buffer); @@ -57,14 +64,6 @@ int save_modified_file_information(lsfs_file* file); #define DEFAULT_TABLE_SIZE 8 // 16 #define NUM_DATA_POINTERS 27 -typedef enum Table_Entry_Kind -{ - // These are specific values since, is has to corrospond to the implementation in assembly - ENTRY_EMPTY = 0, - ENTRY_FILE = 1, - ENTRY_DIRECTORY = 2, -} Table_Entry_Kind; - typedef struct Partition_Entry { uint8_t active_falg; // This has value 0x80 if it is a bootable partition / it is an active partition. @@ -171,6 +170,7 @@ typedef struct tag_record { typedef struct lsfs_file { lsfs_file_id file_id; lsfs_sector_offset table_entry_pointer; + struct_table_entry* table_backpointer; Table_Entry_Kind entry_kind; char* filename; uint32_t owner_id; @@ -188,7 +188,7 @@ Directory_Table* lsfs_find_directory(const char *path, bool drop_filename) { Directory_Table *dir_table = calloc(1, sizeof(Directory_Table)); - printf("Table index: %lu \n",p_control.fsci.master_table_index ); + // printf("Table index: %lu \n",p_control.fsci.master_table_index ); read_data_from_disk(p_control.fsci.master_table_index, DEFAULT_TABLE_SIZE, dir_table); lsfs_string_array split_path = lsfs_string_split_c(path, '/', false); @@ -207,7 +207,7 @@ Directory_Table* lsfs_find_directory(const char *path, bool drop_filename) if (strcmp(dir_table->entries[j].filename, split_path.strings[i].chars) == 0) { int index_sector = dir_table->entries[j].data_pointer[0]; - printf("Table index: %lu \n",index_sector ); + // printf("Table index: %lu \n",index_sector ); read_data_from_disk(index_sector, DEFAULT_TABLE_SIZE, dir_table); break; } @@ -225,7 +225,9 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char* path) { for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i) { - if(strcmp( filename.chars, dir_table->entries[i].filename ) == 0) { + if(strcmp( filename.chars, dir_table->entries[i].filename ) == 0) + { + find_file->table_backpointer = &(dir_table->entries[i]); find_file->file_id = dir_table->entries[i].file_id; find_file->entry_kind = dir_table->entries[i].entry_kind; find_file->table_entry_pointer = i; @@ -246,7 +248,7 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char* path) { -int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data, size_t offset_to_next_entry) +int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data, int64_t offset_to_next_entry) { int data_length = file->size - offset_to_next_entry; int amount_read = 0; @@ -339,7 +341,7 @@ static inline time_t lsfs_disk_update_timestamps(lsfs_file *file) { #define lsfs_num_sectors_for_size(x) (((x)+SECTOR_SIZE-1)&~(SECTOR_SIZE-1)) -int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, size_t offset_to_next_entry) +int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, int64_t offset_to_next_entry) { int new_filesize = data_length + offset_to_next_entry; int amount_written = 0; @@ -353,7 +355,7 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s while (file->data_pointer[data_pointer_index] == 0) { // we have to assign a free sector - if (get_free_sectors(1, file->data_pointer)) + if (get_free_sectors(1, file->table_backpointer)) { // This is a fail case, we cannot assign a new sector: return amount_written; @@ -535,7 +537,7 @@ int get_free_sectors_table() { return return_index; } -int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) { +int get_free_sectors(int num_sectors_needed, struct_table_entry* table_entry) { if ((p_control.fsci.next_free_sector + num_sectors_needed) > p_control.fsci.last_sector_index_on_partition ) { @@ -551,10 +553,10 @@ int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) { return -EINVAL; // We don't have any more data pointers. } - if (output_array[i] == 0) + if (table_entry->data_pointer[i] == 0) { // If free we can assign: - output_array[i] = p_control.fsci.next_free_sector; + table_entry->data_pointer[i] = p_control.fsci.next_free_sector; p_control.fsci.next_free_sector += DEFAULT_DATA_POINTER_SIZE; num_sectors_needed--; } @@ -597,7 +599,7 @@ int create_file_system(char* disk_name, char hdd_or_partition, uint64_t filesyst { // 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"); + sprintf(fsci->filesystem_information, "LSFS v1.0.0-a4\r\n(LessSimpelFileSystem)(Generated by the disk_manager_utility.c)\r\nDeveloped to SingOS and QuasiOS\r\nby Jorn Guldberg\r\n"); if (hdd_or_partition == '1') { @@ -624,6 +626,7 @@ int create_file_system(char* disk_name, char hdd_or_partition, uint64_t filesyst write_data_to_disk(fsci->this_partition_offset_on_disk, 1, fsci); + lsfs_disk_load_disk(NULL); // Reload disk return 0; } @@ -639,6 +642,9 @@ int lsfs_disk_install_bootloader(char *bootloader_name) fread(mbr, 1, SECTOR_SIZE, disk); memcpy(mbr->code, bootloader_mbr->code, 446); write_data_to_disk(0, 1, mbr); // Write this to the first sector of the disk. + + lsfs_disk_load_disk(NULL); // Reload disk + return 0; } @@ -662,9 +668,9 @@ int lsfs_disk_install_vbr(char *vbr_path) vbr_first_sector->vbr_LBA_FSCI_position = p_control.fsci.this_partition_offset_on_disk; 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); + printf("VBR size: %lu\n", vbr_first_sector->vbr_size_in_bytes); + printf("VBR lba address: %lu\n", vbr_first_sector->vbr_LBA_address); + printf("VBR FSCI: %lu\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. @@ -688,10 +694,21 @@ int lsfs_disk_install_vbr(char *vbr_path) } -int lsfs_disk_load_disk() { +int lsfs_disk_load_disk(char* diskname) +{ // Find the partition talbe: // This makes is BIOS dependent. // UEFI is not supported. + if (diskname != NULL) + { + disk = fopen ( diskname , "r+b" ); + + } + else if (disk == NULL ) + { + return -1; + } + time(×tamp_loading); Master_Boot_record mbr; @@ -811,7 +828,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind) { // We assign one data pointer consiting of DEFAULT_DATA_POINTER_SIZE sectors dir_table->entries[free_index].file_size = 0; - get_free_sectors(1, dir_table->entries[free_index].data_pointer); + get_free_sectors(1, &(dir_table->entries[free_index])); } else { diff --git a/lsfs_string.h b/lsfs_string.h index d7eef4f..6695bc5 100644 --- a/lsfs_string.h +++ b/lsfs_string.h @@ -5,12 +5,12 @@ typedef struct lsfs_string { bool dynamic; - unsigned int length; + int length; char *chars; } lsfs_string; typedef struct lsfs_string_array { - unsigned int length; + int length; lsfs_string *strings; } lsfs_string_array; @@ -33,7 +33,7 @@ static inline lsfs_string lsfs_create_id_string(uint64_t id) { }; } -static inline lsfs_string lsfs_make_string(unsigned int length, const char *chars) { +static inline lsfs_string lsfs_make_string(int length, const char *chars) { return (lsfs_string){ .dynamic = false, .length = length, @@ -45,7 +45,7 @@ static inline lsfs_string lsfs_make_string_c(const char *cstring) { return lsfs_make_string(strlen(cstring), cstring); } -static inline lsfs_string lsfs_create_string(unsigned int length, const char *chars) { +static inline lsfs_string lsfs_create_string(int length, const char *chars) { char *copy = malloc(length + 1); // Space for null terminator memcpy(copy, chars, length); @@ -79,7 +79,7 @@ lsfs_string_array lsfs_create_string_array(size_t array_size) { } static inline void lsfs_destroy_string_array(lsfs_string_array array) { - for (unsigned int i = 0; i < array.length; ++i) { + for (int i = 0; i < array.length; ++i) { lsfs_destroy_string(array.strings[i]); } free(array.strings); @@ -87,10 +87,10 @@ static inline void lsfs_destroy_string_array(lsfs_string_array array) { lsfs_string_array lsfs_string_split(lsfs_string string, char delim, bool keep_delim) { - unsigned int i; - unsigned int last; + int i; + int last; - unsigned int count = 0; + int count = 0; i = 0; last = 0; @@ -109,7 +109,7 @@ lsfs_string_array lsfs_string_split(lsfs_string string, char delim, bool keep_de lsfs_string_array result = lsfs_create_string_array(count); - unsigned int insert_index = 0; + int insert_index = 0; int k = keep_delim ? 0 : 1; i = 0; @@ -141,7 +141,7 @@ char *dbg_strarr(lsfs_string_array strings) { int where = 0; where += sprintf(temp+where, "{"); - for (unsigned int i = 0; i < strings.length; ++i) { + for (int i = 0; i < strings.length; ++i) { where += sprintf(temp+where, "<'%.*s'>", strings.strings[i].length, strings.strings[i].chars); } where += sprintf(temp+where, "}"); diff --git a/lsfs_vbr/build.sh b/lsfs_vbr/build.sh new file mode 100644 index 0000000..f9f185b --- /dev/null +++ b/lsfs_vbr/build.sh @@ -0,0 +1,6 @@ +# First build the 16-bit LSFS implementation which is include in the VBR +cd lsfs_16-bit +bash build.sh +mv disk.out ../disk.out +cd .. +nasm -f bin vbr_lsfs.nasm -o vbr.bin \ No newline at end of file