diff --git a/bin/kern16.bin b/bin/kern16.bin index 08f3c53..812daa4 100755 Binary files a/bin/kern16.bin and b/bin/kern16.bin differ diff --git a/disk.img b/disk.img index f551560..276befb 100644 Binary files a/disk.img and b/disk.img differ diff --git a/diskB.img b/diskB.img index 3525e06..2fe1b84 100644 Binary files a/diskB.img and b/diskB.img differ diff --git a/kern/bbfs.err b/kern/bbfs.err index 1831170..a33bad6 100644 --- a/kern/bbfs.err +++ b/kern/bbfs.err @@ -1,4 +1,5 @@ filesystem/bbfs.c(103): Warning! W131: No prototype found for function 'memcpy' +filesystem/bbfs.c(167): Warning! W303: Parameter 'data' has been defined, but not referenced filesystem/bbfs.c(103): Warning! W308: The function 'memcpy' without prototyped parameters called filesystem/bbfs.c(103): Note! I2002: 'memcpy' defined in: filesystem/bbfs.c(103) filesystem/bbfs.c(126): Warning! W308: The function 'memcpy' without prototyped parameters called diff --git a/kern/filesystem/bbfs.c b/kern/filesystem/bbfs.c index d8f4d92..4bf00af 100644 --- a/kern/filesystem/bbfs.c +++ b/kern/filesystem/bbfs.c @@ -128,3 +128,50 @@ void bbfs_read_block(void far* block_address_src, bbfs_read_block_end: printf("BBFS: finished.\r\n"); } + +/** + * just a bare bones function for + * writing a file. Only for BBFS v3 +*/ + +void bbfs_v3_write_file(char file_name[], char file_exst[], char data[], int file_id) { + char data_buffer[512]; + + // copy the file name + for (int x = 0; x <= 12; x++) + data_buffer[x] = file_name[x]; + + // copy the file exst. + for (int x = 13; x <= 16; x++) + data_buffer[x] = file_exst[x-13]; + + // copy data to the data_buffer + for (int x = 16; x <= 496; x++) + data_buffer[x] = data[x-16]; + + // write to disk + // TODO: fix the junk writing after the data[] is written. + printf("BBFS: writing file [%s.%s] to disk...\r\n", file_name, file_exst); + x86_Disk_Write(1, 1, 0, file_id, 0, data_buffer); + + // finished + printf("BBFS: finished writing file [%s.%s] to the disk.\r\n", file_name, file_exst); + +} + + +/** + * just a bare bones function for + * readining a file. Only for BBFS v3 +*/ +void bbfs_v3_read_file(int file_id, char data[]) +{ + char data_buffer[512]; + + printf("BBFS: reading file [%d] from disk...\r\n", file_id); + + x86_Disk_Read(1, 1, 0, file_id, 0, data_buffer); + + // finished + printf("BBFS: file [%d] read.\r\n", file_id); +} diff --git a/kern/filesystem/bbfs.h b/kern/filesystem/bbfs.h index 03d2be0..0f13c40 100644 --- a/kern/filesystem/bbfs.h +++ b/kern/filesystem/bbfs.h @@ -9,6 +9,10 @@ #define RAM_BLOCK_SIZE 512 /* maximum size of a RAM block (blck. name not counted)*/ #define REAL_BLCK_SIZE 500 /* actual size of a RAM block (-12B for blck. name)*/ +#define FILE_NAME_LENGTH 12 +#define FILE_EXST_LENGTH 4 +#define FILE_HEADER_SIZE 28 + typedef struct { char disk_label[10]; @@ -22,6 +26,12 @@ typedef struct char free_space[500]; } BBFS_v2_block_data; +typedef struct +{ + char file_name; + char file_exst; +} BBFS_v3_file_header; + bool _file_sys_not_recognized; void bbfs_get_disk_params(char disk_label[10], @@ -36,3 +46,6 @@ void bbfs_write_block(void far* block_address_dest, void bbfs_read_block(void far* block_address_src, uint8_t buffer[512], uint16_t num_bytes); + +void bbfs_v3_read_file(); +void bbfs_v3_write_file(char file_name[], char file_exst[], char data[], int file_id); diff --git a/kern/kern16.c b/kern/kern16.c index 53d6466..1e62b43 100644 --- a/kern/kern16.c +++ b/kern/kern16.c @@ -99,13 +99,28 @@ void _cdecl kstart_(uint16_t bootDrive) bbfs_write_block(44032, test_buffer, 512); bbfs_read_block(44032, test_buffer2, 512); */ +/* + char buffer_b[512]; + /* char buffer_b[512]; for (int x = 0; x < 512; x++) { buffer_b[x] = 'a'; } +*/ + + + //x86_Disk_Write(1, 1, 0, 1, 0, buffer_b); + + char test_file_name[] = "HELLO WORLD"; + char test_file_exst[] = "TXT"; + char test_data[] = "THIS IS JUST SOME RANDOM JUNK THAT WILL BE WRITTEN TO THE DISK AS [HELLO WORLD.TXT]"; + + bbfs_v3_write_file(test_file_name, test_file_exst, test_data, 1); + + char test_out_file[512]; - x86_Disk_Write(1, 1, 0, 1, 0, buffer_b); */ + bbfs_v3_read_file(1, test_out_file); get_low_memory(); get_used_memory(); diff --git a/kern/kern16.err b/kern/kern16.err deleted file mode 100644 index 05ffbea..0000000 --- a/kern/kern16.err +++ /dev/null @@ -1,8 +0,0 @@ -kern16.c(40): Warning! W101: Parameter 4: Non-portable pointer conversion -kern16.c(40): Note! I2003: source conversion type is 'int' -kern16.c(40): Note! I2004: target conversion type is 'void __far *' -kern16.c(40): Note! I2002: 'DISK_ReadSectors' defined in: filesystem/disk.h(17) -memory/allocator.h(24): Warning! W202: Symbol 'bitmap_size' has been defined, but not referenced -memory/allocator.h(23): Warning! W202: Symbol 'bitmap_pages' has been defined, but not referenced -memory/allocator.h(22): Warning! W202: Symbol 'bitmap' has been defined, but not referenced -memory/allocator.h(21): Warning! W202: Symbol 'free_memory' has been defined, but not referenced diff --git a/kern/libc/string.c b/kern/libc/string.c index 74e0f50..f092984 100644 --- a/kern/libc/string.c +++ b/kern/libc/string.c @@ -41,6 +41,32 @@ char* strcpy(char* dst, const char* src) return origDst; } +char *strncpy(char *s1, const char *s2, size_t n) +{ + unsigned int extern_iter = 0; + + unsigned int iterator = 0; + for (iterator = 0; iterator < n; iterator++) + { + if (s2[iterator] != '\0') + s1[iterator] = s2[iterator]; + else + { + s1[iterator] = s2[iterator]; + extern_iter = iterator + 1; + break; + } + } + + while (extern_iter < n) + { + s1[extern_iter] = '\0'; + extern_iter++; + } + + return s1; +} + unsigned strlen(const char* str) { unsigned len = 0; diff --git a/kern/libc/string.h b/kern/libc/string.h index 95d91cb..f4d3c67 100644 --- a/kern/libc/string.h +++ b/kern/libc/string.h @@ -5,5 +5,6 @@ const char* strchr(const char* str, char chr); char* strcpy(char* dst, const char* src); +char *strncpy(char *s1, const char *s2, size_t n); // copied from a scrapped version of PekOS unsigned strlen(const char* str); int strcmp(char *str1, char *str2);