os/devfs/main.c

77 lines
1.9 KiB
C
Raw Normal View History

#include <tasking.h>
2019-07-13 10:40:23 -05:00
#include <stdlib.h>
#include <mailboxes.h>
#include <ipc/vfs.h>
#include <memory.h>
2019-07-31 19:46:01 -05:00
#include <grub/text_fb_info.h>
#include "vga.h"
2019-08-03 15:50:23 -05:00
#include <vfs.h>
int main() {
2019-07-31 19:46:01 -05:00
text_fb_info info;
info.address=map_phys((void*)0xB8000,10);
info.width=80;
info.height=25;
vga_init(info);
2019-07-13 10:40:23 -05:00
uint32_t box=mailbox_new(16);
register_fs("devfs",box);
2019-07-13 10:40:23 -05:00
for (;;) {
yield();
2019-07-13 10:40:23 -05:00
Message msg;
msg.msg=malloc(sizeof(vfs_message));
mailbox_get_msg(box,&msg,sizeof(vfs_message));
if (msg.from==0) {
yield();
2019-07-13 10:40:23 -05:00
} else {
vfs_message* vfs_msg=(vfs_message*)msg.msg;
2019-08-28 20:32:14 -05:00
switch (vfs_msg->type) {
case VFS_OPEN:
vfs_msg->flags=0;
break;
case VFS_PUTS: {
char* data=malloc(sizeof(char)*vfs_msg->data);
Message msg;
msg.msg=data;
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) {
serial_print("Could not recieve fputs data from the VFS\n");
vfs_msg->flags=2;
break;
}
vga_write_string(data);
vfs_msg->flags=0;
break;
}
2019-08-31 10:42:20 -05:00
case VFS_MOUNT: {
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) {
serial_print("Could not recieve disk file path from the VFS\n");
vfs_msg->flags=2;
break;
}
free(disk_file);
vfs_msg->flags=0;
break;
}
2019-08-28 20:32:14 -05:00
default:
vfs_msg->flags=1;
}
2019-07-13 10:40:23 -05:00
msg.to=msg.from;
msg.from=box;
mailbox_send_msg(&msg);
}
free(msg.msg);
}
}