From 45fd13c5bbe3affed28aa166ce37d6c7f797bcd8 Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 25 Aug 2019 13:53:44 -0500 Subject: [PATCH] Get mount working and register_fs now takes a mailbox number. --- fsdrv/main.c | 4 +-- libc/stdio.c | 33 +++++++++++++------ sysroot/usr/include/vfs.h | 3 +- vfs/main.c | 68 +++++++++++++++++++++++++++++++++------ 4 files changed, 87 insertions(+), 21 deletions(-) diff --git a/fsdrv/main.c b/fsdrv/main.c index 2cd9c64..cb2b767 100644 --- a/fsdrv/main.c +++ b/fsdrv/main.c @@ -8,14 +8,14 @@ #include int main() { - register_fs("devfs"); - // mount("devfs","","/dev"); text_fb_info info; info.address=map_phys((void*)0xB8000,10); info.width=80; info.height=25; vga_init(info); uint32_t box=mailbox_new(16); + register_fs("devfs",box); + mount("","devfs","/dev"); for (;;) { yield(); Message msg; diff --git a/libc/stdio.c b/libc/stdio.c index 685180c..534fcc7 100644 --- a/libc/stdio.c +++ b/libc/stdio.c @@ -4,6 +4,7 @@ #include #include #include +#include #define VFS_MBOX 3 #define VFS_PID 2 @@ -42,9 +43,6 @@ FILE* fopen(char* filename,char* mode) { msg.msg=msg_data; msg.size=sizeof(vfs_message); mailbox_send_msg(&msg); - free(msg.msg); - yieldToPID(VFS_PID); - msg.msg=malloc(sizeof(vfs_message)); yieldToPID(VFS_PID); mailbox_get_msg(box,&msg,sizeof(vfs_message)); while (msg.from==0) { @@ -71,9 +69,6 @@ int fputc(int c, FILE* stream) { msg.msg=msg_data; msg.size=sizeof(vfs_message); mailbox_send_msg(&msg); - free(msg.msg); - yieldToPID(VFS_PID); - msg.msg=malloc(sizeof(vfs_message)); yieldToPID(VFS_PID); mailbox_get_msg(box,&msg,sizeof(vfs_message)); while (msg.from==0) { @@ -99,8 +94,8 @@ int fputs(const char* s, FILE* stream) { return 0; } -void register_fs(const char* name) { - vfs_message* msg_data=make_msg(VFS_REGISTER_FS,name,NULL,0,0); +void register_fs(const char* name,uint32_t mbox) { + vfs_message* msg_data=make_msg(VFS_REGISTER_FS,name,NULL,mbox,0); Message msg; msg.from=box; msg.to=VFS_MBOX; @@ -110,7 +105,27 @@ void register_fs(const char* name) { free(msg.msg); yieldToPID(VFS_PID); msg.msg=malloc(sizeof(vfs_message)); - yieldToPID(VFS_PID); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + while (msg.from==0) { + yieldToPID(VFS_PID); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + } + free(msg.msg); +} + +void mount(char* file,char* type,char* path) { + vfs_message* msg_data=make_msg(VFS_MOUNT,type,path,0,strlen(file)+1); + Message msg; + msg.from=box; + msg.to=VFS_MBOX; + msg.msg=msg_data; + msg.size=sizeof(vfs_message); + mailbox_send_msg(&msg); + msg.msg=file; + msg.size=strlen(file)+1; + mailbox_send_msg(&msg); + yieldToPID(VFS_PID); + msg.msg=msg_data; mailbox_get_msg(box,&msg,sizeof(vfs_message)); while (msg.from==0) { yieldToPID(VFS_PID); diff --git a/sysroot/usr/include/vfs.h b/sysroot/usr/include/vfs.h index 158584d..e7c45d7 100644 --- a/sysroot/usr/include/vfs.h +++ b/sysroot/usr/include/vfs.h @@ -1,6 +1,7 @@ #ifndef VFS_H #define VFS_H -void register_fs(const char* name); +void register_fs(const char* name,uint32_t mbox); +void mount(char* file,char* type,char* path); #endif diff --git a/vfs/main.c b/vfs/main.c index 22bc018..25fb38a 100644 --- a/vfs/main.c +++ b/vfs/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #define PROC_FD_LIMIT 1024 @@ -23,7 +24,7 @@ typedef struct { static const char** drv_names; static uint32_t* drvs; static uint32_t max_drvs; -static uint32_t next_drv_indx; +static uint32_t num_drvs; static vfs_mapping* head_mapping; static vfs_mapping* tail_mapping; vfs_file* fd_tables[32768]; @@ -53,21 +54,21 @@ void init_vfs() { drv_names=malloc(sizeof(const char**)*32); drvs=malloc(sizeof(uint32_t)*32); max_drvs=32; - next_drv_indx=0; + num_drvs=0; head_mapping=NULL; tail_mapping=NULL; } uint32_t register_fs_intern(uint32_t drv,const char* type) { - if (next_drv_indx==max_drvs) { + if (num_drvs==max_drvs) { drvs=realloc(drvs,sizeof(uint32_t)*(max_drvs+32)); drv_names=realloc(drv_names,sizeof(char*)*(max_drvs+32)); max_drvs+=32; } - drvs[next_drv_indx]=drv; - drv_names[next_drv_indx]=type; - next_drv_indx++; - return next_drv_indx-1; + drvs[num_drvs]=drv; + drv_names[num_drvs]=type; + num_drvs++; + return num_drvs-1; } void vfs_fopen(vfs_message* vfs_msg,uint32_t from) { @@ -152,10 +153,59 @@ void vfs_register_fs(vfs_message* vfs_msg, uint32_t from) { char* name=malloc(sizeof(char)*(strlen(vfs_msg->mode)+1)); name[0]='\0'; strcpy(name,&vfs_msg->mode[0]); - register_fs_intern(from,name); + register_fs_intern(vfs_msg->fd,name); vfs_msg->flags=0; } +void vfs_mount(vfs_message* vfs_msg, uint32_t from) { + char* path=malloc(sizeof(char)*(strlen(vfs_msg->path)+1)); + path[0]='\0'; + strcpy(path,&vfs_msg->path[0]); + char* type=malloc(sizeof(char)*(strlen(vfs_msg->mode)+1)); + type[0]='\0'; + strcpy(type,&vfs_msg->mode[0]); + char* disk_file=malloc(sizeof(char)*(vfs_msg->data)); + Message msg; + msg.msg=disk_file; + mailbox_get_msg(box,&msg,vfs_msg->data); + while (msg.from==0 && msg.size==0) { + yield(); + mailbox_get_msg(box,&msg,sizeof(vfs_message)); + } + if (msg.from==0) { + vfs_msg->flags=4; + return; + } + char found=0; + uint32_t i; + for (i=0;iflags=4; + return; + } + if (head_mapping==NULL) { + vfs_mapping* mapping=malloc(sizeof(vfs_mapping)); + mapping->mntpnt=malloc(sizeof(char)*(strlen(path)+1)); + strcpy(mapping->mntpnt,path); + mapping->type=i; + mapping->next=NULL; + head_mapping=mapping; + tail_mapping=mapping; + } else { + vfs_mapping* mapping=malloc(sizeof(vfs_mapping)); + mapping->mntpnt=malloc(sizeof(char)*(strlen(path)+1)); + strcpy(mapping->mntpnt,path); + mapping->type=i; + mapping->next=NULL; + tail_mapping->next=mapping; + } +} + int main() { init_vfs(); box=mailbox_new(16); @@ -178,7 +228,7 @@ int main() { vfs_msg->flags=1; break; case VFS_MOUNT: - vfs_msg->flags=1; + vfs_mount(vfs_msg,msg.from); break; case VFS_UMOUNT: vfs_msg->flags=1;