Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBFS v3 (no nuking repo this time) #13

Merged
merged 7 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/kern16.bin
Binary file not shown.
Binary file modified disk.img
Binary file not shown.
Binary file modified diskB.img
Binary file not shown.
1 change: 1 addition & 0 deletions kern/bbfs.err
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 47 additions & 0 deletions kern/filesystem/bbfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 13 additions & 0 deletions kern/filesystem/bbfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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],
Expand All @@ -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);
17 changes: 16 additions & 1 deletion kern/kern16.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 0 additions & 8 deletions kern/kern16.err

This file was deleted.

26 changes: 26 additions & 0 deletions kern/libc/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions kern/libc/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);