Add close, add filesystem code to main kernel for hardware testing

This commit is contained in:
Byron Lathi
2023-12-07 08:10:45 -08:00
parent 0327ab6a2b
commit 6f16ac4daf
3 changed files with 32 additions and 17 deletions

View File

@@ -20,9 +20,21 @@ size_t fat32_file_write(int8_t fd, const void* buf, size_t nbytes) {
return -1; return -1;
} }
/*
* file_close
* DESCRIPTION: close device abstracted as file
* INPUTS: fd -- file descriptor for file to be closed
* OUTPUTS: none
* RETURN VALUE: none
* SIDE EFFECTS: none
*/
int8_t fat32_file_close(int8_t fd) { int8_t fat32_file_close(int8_t fd) {
(void)fd; struct pcb* pcb;
return -1; pcb = get_pcb_ptr();
/* update pcb to remove process */
pcb->file_desc_array[fd].flags = !IN_USE;
return 0;
} }
int8_t fat32_file_open(const char* filename) { int8_t fat32_file_open(const char* filename) {
@@ -64,7 +76,6 @@ int8_t fat32_file_open(const char* filename) {
size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) { size_t fat32_file_read(int8_t fd, void* buf, size_t nbytes) {
uint16_t i; uint16_t i;
uint8_t error;
size_t offset; size_t offset;
size_t leftover_length; size_t leftover_length;
size_t bytes_read = 0; size_t bytes_read = 0;

View File

@@ -21,6 +21,9 @@ void handle_rtc_interrupt() {
char buf[128]; char buf[128];
int main() { int main() {
int8_t fd;
size_t nbytes, i;
cputs("Kernel\n"); cputs("Kernel\n");
cputs("Init Mapper\n"); cputs("Init Mapper\n");
@@ -49,17 +52,19 @@ int main() {
fat32_init(); fat32_init();
terminal_open(NULL); /* This is what is going to be part of open */
terminal_write(0, "Terminal Write\n", 15); fd = fat32_file_open("VERYLA~1TXT");
cprintf("fd: %x\n", fd);
while(1) { nbytes = fat32_file_read(fd, buf, 23);
if (terminal_read(0, buf, 128)) { for (i = 0; i < nbytes; i++) {
cprintf("Fail\n"); cprintf("%c", buf[i]);
break; }
while ((nbytes = fat32_file_read(fd, buf, 128))){
for (i = 0; i < nbytes; i++) {
cprintf("%c", buf[i]);
} }
terminal_write(0, "Got: ", 5);
terminal_write(0, buf, strlen(buf));
terminal_write(0, "\n", 1);
} }
return 0; return 0;

View File

@@ -34,11 +34,10 @@ struct pcb {
struct file_desc file_desc_array[FILE_DESC_SIZE]; struct file_desc file_desc_array[FILE_DESC_SIZE];
int32_t is_vidmapped; int32_t is_vidmapped;
uint8_t args[128]; uint8_t args[128];
uint32_t execute_return; uint16_t execute_return;
int32_t pid; uint16_t pid;
int32_t parent_pid; uint16_t parent_pid;
uint32_t parent_esp; uint16_t parent_esp;
uint32_t parent_ebp;
}; };