Get mount working and register_fs now takes a mailbox number.

This commit is contained in:
pjht 2019-08-25 13:53:44 -05:00
parent d12421a7c8
commit 45fd13c5bb
4 changed files with 87 additions and 21 deletions

View File

@ -8,14 +8,14 @@
#include <vfs.h>
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;

View File

@ -4,6 +4,7 @@
#include <ipc/vfs.h>
#include <stdio.h>
#include <tasking.h>
#include <dbg.h>
#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);

View File

@ -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

View File

@ -3,6 +3,7 @@
#include <mailboxes.h>
#include <stdlib.h>
#include <string.h>
#include <dbg.h>
#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;i<num_drvs;i++) {
if (strcmp(type,drv_names[i])==0) {
found=1;
break;
}
}
if (!found) {
vfs_msg->flags=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;