2019-07-13 10:18:41 -05:00
|
|
|
#include <tasking.h>
|
2019-07-13 10:40:23 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <mailboxes.h>
|
|
|
|
#include <ipc/vfs.h>
|
2019-07-13 10:18:41 -05:00
|
|
|
#include <memory.h>
|
2019-07-31 19:46:01 -05:00
|
|
|
#include <grub/text_fb_info.h>
|
2019-08-03 15:50:23 -05:00
|
|
|
#include <vfs.h>
|
2019-08-31 16:46:52 -05:00
|
|
|
#include <ipc/devfs.h>
|
|
|
|
#include <string.h>
|
2019-08-31 16:48:11 -05:00
|
|
|
#include <dbg.h>
|
2019-08-31 16:46:52 -05:00
|
|
|
|
|
|
|
uint32_t vfs_box;
|
2019-09-10 19:13:34 -05:00
|
|
|
uint32_t devfs_vfs_box;
|
2019-09-05 14:12:04 -05:00
|
|
|
uint32_t devfs_reg_box;
|
|
|
|
uint32_t devfs_drv_box;
|
2019-08-31 16:46:52 -05:00
|
|
|
int num_devs;
|
|
|
|
int max_devs;
|
|
|
|
char** dev_names;
|
|
|
|
uint32_t* dev_mboxes;
|
|
|
|
int* dev_types;
|
|
|
|
|
2019-09-01 14:15:01 -05:00
|
|
|
#define VFS_PID 2
|
|
|
|
|
2019-09-05 14:12:04 -05:00
|
|
|
char devfs_open(vfs_message* vfs_msg) {
|
|
|
|
int i;
|
|
|
|
char found=0;
|
|
|
|
for (i=0;i<num_devs;i++) {
|
|
|
|
if (strcmp(dev_names[i],&vfs_msg->path[0])==0) {
|
|
|
|
found=1;
|
2019-08-31 16:46:52 -05:00
|
|
|
break;
|
|
|
|
}
|
2019-09-05 14:12:04 -05:00
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
vfs_msg->flags=2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (dev_types[i]==1) {
|
|
|
|
uint32_t* data=malloc(sizeof(uint32_t));
|
|
|
|
*data=dev_mboxes[i];
|
|
|
|
vfs_msg->fs_data=data;
|
2019-08-31 16:46:52 -05:00
|
|
|
Message msg;
|
2019-09-05 14:12:04 -05:00
|
|
|
msg.from=devfs_drv_box;
|
|
|
|
msg.to=dev_mboxes[i];
|
2019-08-31 16:46:52 -05:00
|
|
|
msg.size=sizeof(vfs_message);
|
|
|
|
msg.msg=vfs_msg;
|
|
|
|
mailbox_send_msg(&msg);
|
2019-09-05 14:12:04 -05:00
|
|
|
} else {
|
|
|
|
vfs_msg->flags=0;
|
|
|
|
uint32_t* data=malloc(sizeof(uint32_t));
|
|
|
|
*data=dev_mboxes[i];
|
|
|
|
vfs_msg->fs_data=data;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
vfs_msg->flags=2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char devfs_puts(vfs_message* vfs_msg) {
|
|
|
|
char* data=malloc(sizeof(char)*vfs_msg->data);
|
|
|
|
Message msg;
|
|
|
|
msg.msg=data;
|
2019-09-10 19:13:34 -05:00
|
|
|
mailbox_get_msg(devfs_vfs_box,&msg,vfs_msg->data);
|
2019-09-05 14:12:04 -05:00
|
|
|
while (msg.from==0 && msg.size==0) {
|
2019-08-31 16:46:52 -05:00
|
|
|
yield();
|
2019-09-10 19:13:34 -05:00
|
|
|
mailbox_get_msg(devfs_vfs_box,&msg,sizeof(vfs_message));
|
2019-09-05 14:12:04 -05:00
|
|
|
}
|
|
|
|
if (msg.from==0) {
|
|
|
|
serial_print("Could not recieve fputs data from the VFS\n");
|
|
|
|
vfs_msg->flags=2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
msg.from=devfs_drv_box;
|
|
|
|
msg.to=*((uint32_t*)vfs_msg->fs_data);
|
|
|
|
msg.size=sizeof(vfs_message);
|
|
|
|
msg.msg=vfs_msg;
|
|
|
|
mailbox_send_msg(&msg);
|
|
|
|
msg.size=vfs_msg->data;
|
|
|
|
msg.msg=data;
|
|
|
|
mailbox_send_msg(&msg);
|
2019-10-20 09:44:33 -05:00
|
|
|
free(data);
|
2019-09-05 14:12:04 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char devfs_gets(vfs_message* vfs_msg) {
|
|
|
|
Message msg;
|
|
|
|
msg.from=devfs_drv_box;
|
|
|
|
msg.to=*((uint32_t*)vfs_msg->fs_data);
|
|
|
|
msg.size=sizeof(vfs_message);
|
|
|
|
msg.msg=vfs_msg;
|
|
|
|
mailbox_send_msg(&msg);
|
|
|
|
vfs_msg->flags=0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* devfs_gets_finish(vfs_message* vfs_msg) {
|
2019-10-20 09:44:33 -05:00
|
|
|
char str[256];
|
|
|
|
int_to_ascii(vfs_msg->data,str);
|
|
|
|
serial_print("gets_finish: Driver wants ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print(" bytes of gets data\n");
|
2020-07-09 11:28:57 -05:00
|
|
|
int_to_ascii(vfs_msg->type,str);
|
|
|
|
serial_print("gets_finish: Driver has message type ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
if (vfs_msg->flags) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-07-12 13:47:17 -05:00
|
|
|
char* gets_data=malloc(sizeof(uint8_t)*vfs_msg->data);
|
2019-09-05 14:12:04 -05:00
|
|
|
Message msg;
|
|
|
|
msg.msg=gets_data;
|
2019-10-20 09:44:33 -05:00
|
|
|
int_to_ascii(vfs_msg->data,str);
|
|
|
|
serial_print("gets_finish: Driver now wants ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print(" bytes of gets data\n");
|
2020-07-09 11:28:57 -05:00
|
|
|
msg.msg=gets_data;
|
|
|
|
int_to_ascii(vfs_msg->type,str);
|
|
|
|
serial_print("gets_finish: Driver now has message type ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
|
|
|
|
|
|
|
// int_to_ascii(devfs_drv_box,str);
|
|
|
|
// serial_print("mailbox_get_msg(");
|
|
|
|
// serial_print(str);
|
|
|
|
// serial_print(",");
|
|
|
|
// hex_to_ascii(msg,str);
|
|
|
|
// serial_print(str);
|
|
|
|
// serial_print(",");
|
|
|
|
// int_to_ascii((uint32_t)vfs_msg->data,str);
|
|
|
|
// serial_print(str);
|
|
|
|
// serial_print(");\n");
|
|
|
|
vfs_message temp_msg;
|
|
|
|
memcpy(&temp_msg, vfs_msg, sizeof(vfs_message));
|
2019-10-20 09:44:33 -05:00
|
|
|
mailbox_get_msg(devfs_drv_box,&msg,(uint32_t)vfs_msg->data);
|
|
|
|
// while (msg.from==0 && msg.size==0) {
|
|
|
|
// serial_print("Yielding to wait for data msg\n");
|
|
|
|
// yield();
|
|
|
|
// mailbox_get_msg(devfs_drv_box,&msg,(uint32_t)vfs_msg->data);
|
|
|
|
// }
|
2020-07-09 11:28:57 -05:00
|
|
|
memcpy(vfs_msg, &temp_msg, sizeof(vfs_message));
|
2019-10-20 09:44:33 -05:00
|
|
|
int_to_ascii(vfs_msg->data,str);
|
|
|
|
serial_print("gets_finish: Again, driver now wants ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print(" bytes of gets data\n");
|
2020-07-09 11:28:57 -05:00
|
|
|
int_to_ascii(vfs_msg->type,str);
|
|
|
|
serial_print("gets_finish: Again, driver now has message type ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
vfs_msg->flags=0;
|
2019-10-20 09:44:33 -05:00
|
|
|
int_to_ascii(vfs_msg->data,str);
|
|
|
|
serial_print("gets_finish: Sending ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print(" bytes of gets data\n");
|
2020-07-09 11:28:57 -05:00
|
|
|
int_to_ascii(vfs_msg->type,str);
|
|
|
|
serial_print("gets_finish: Sending message type ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
return gets_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
char devfs_mount(vfs_message* vfs_msg) {
|
|
|
|
char* disk_file=malloc(sizeof(char)*vfs_msg->data);
|
|
|
|
Message msg;
|
|
|
|
msg.msg=disk_file;
|
2019-09-10 19:13:34 -05:00
|
|
|
mailbox_get_msg(devfs_vfs_box,&msg,vfs_msg->data);
|
2019-09-05 14:12:04 -05:00
|
|
|
while (msg.from==0 && msg.size==0) {
|
|
|
|
yield();
|
2019-09-10 19:13:34 -05:00
|
|
|
mailbox_get_msg(devfs_vfs_box,&msg,sizeof(vfs_message));
|
2019-09-05 14:12:04 -05:00
|
|
|
}
|
|
|
|
if (msg.from==0) {
|
|
|
|
serial_print("Could not recieve disk file path from the VFS\n");
|
|
|
|
vfs_msg->flags=2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
free(disk_file);
|
|
|
|
vfs_msg->flags=0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void process_vfs_msg(vfs_message* vfs_msg, uint32_t from) {
|
2019-10-20 09:44:33 -05:00
|
|
|
char str[256];
|
|
|
|
int_to_ascii(vfs_msg->data,str);
|
|
|
|
serial_print("vfs_msg->data=");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
|
|
|
if (from!=vfs_box) {
|
2019-09-05 14:12:04 -05:00
|
|
|
if (vfs_msg->flags) {
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("vfs_msg->flags=");
|
|
|
|
char str[256];
|
|
|
|
int_to_ascii(vfs_msg->flags,str);
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
if (vfs_msg->type==VFS_OPEN) {
|
|
|
|
free((void*)vfs_msg->data);
|
|
|
|
}
|
2019-09-01 14:15:01 -05:00
|
|
|
Message msg;
|
2019-09-10 19:13:34 -05:00
|
|
|
msg.to=vfs_box;
|
|
|
|
msg.from=devfs_vfs_box;
|
2019-09-01 14:15:01 -05:00
|
|
|
msg.size=sizeof(vfs_message);
|
|
|
|
msg.msg=vfs_msg;
|
|
|
|
mailbox_send_msg(&msg);
|
2019-09-05 14:12:04 -05:00
|
|
|
} else {
|
|
|
|
char* gets_data=NULL;
|
2020-07-09 11:28:57 -05:00
|
|
|
serial_print("GOT FINISH TYPE ");
|
|
|
|
char str[256];
|
|
|
|
int_to_ascii(vfs_msg->type,str);
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
switch (vfs_msg->type) {
|
|
|
|
case VFS_OPEN:
|
|
|
|
vfs_msg->flags=0;
|
|
|
|
break;
|
|
|
|
case VFS_PUTS:
|
|
|
|
vfs_msg->flags=0;
|
2019-09-01 14:15:01 -05:00
|
|
|
break;
|
2019-09-05 14:12:04 -05:00
|
|
|
case VFS_GETS:
|
2019-10-20 09:44:33 -05:00
|
|
|
int_to_ascii(vfs_msg->data,str);
|
|
|
|
serial_print("process_vfs_msg: Driver sending ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print(" bytes of gets data\n");
|
|
|
|
serial_print("GETS_FINISH\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
gets_data=devfs_gets_finish(vfs_msg);
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("GETS_FINISH DONE\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
break;
|
|
|
|
case VFS_MOUNT:
|
|
|
|
vfs_msg->flags=0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vfs_msg->flags=1;
|
2019-09-01 14:15:01 -05:00
|
|
|
}
|
2019-09-05 14:12:04 -05:00
|
|
|
Message msg;
|
2019-09-10 19:13:34 -05:00
|
|
|
msg.to=vfs_box;
|
|
|
|
msg.from=devfs_vfs_box;
|
2019-09-05 14:12:04 -05:00
|
|
|
msg.size=sizeof(vfs_message);
|
|
|
|
msg.msg=vfs_msg;
|
2020-07-09 11:28:57 -05:00
|
|
|
serial_print("SENDING FINISH TYPE ");
|
|
|
|
int_to_ascii(vfs_msg->type,str);
|
|
|
|
serial_print(str);
|
|
|
|
serial_print("\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
mailbox_send_msg(&msg);
|
|
|
|
if (gets_data) {
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("Gets data\n");
|
|
|
|
char str[256];
|
|
|
|
int_to_ascii(vfs_msg->data,str);
|
|
|
|
serial_print("Sending ");
|
|
|
|
serial_print(str);
|
|
|
|
serial_print(" bytes of gets data\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
msg.size=vfs_msg->data;
|
|
|
|
msg.msg=gets_data;
|
|
|
|
mailbox_send_msg(&msg);
|
2019-10-20 09:44:33 -05:00
|
|
|
free(gets_data);
|
|
|
|
} else {
|
|
|
|
serial_print("No gets data\n");
|
2019-09-01 14:15:01 -05:00
|
|
|
}
|
2019-09-05 14:12:04 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char send_msg;
|
|
|
|
switch (vfs_msg->type) {
|
|
|
|
case VFS_OPEN:
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("OPEN\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
send_msg=devfs_open(vfs_msg);
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("OPEN DONE\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
break;
|
|
|
|
case VFS_PUTS:
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("PUTS\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
send_msg=devfs_puts(vfs_msg);
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("PUTS DONE\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
break;
|
|
|
|
case VFS_GETS:
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("GETS\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
send_msg=devfs_gets(vfs_msg);
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("GETS DONE\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
break;
|
|
|
|
case VFS_MOUNT:
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("MOUNT\n");
|
2019-09-05 14:12:04 -05:00
|
|
|
send_msg=devfs_mount(vfs_msg);
|
2019-10-20 09:44:33 -05:00
|
|
|
serial_print("MOUNT DONE\n");
|
2019-09-01 14:15:01 -05:00
|
|
|
break;
|
2019-09-05 14:12:04 -05:00
|
|
|
default:
|
|
|
|
vfs_msg->flags=1;
|
2019-09-01 14:15:01 -05:00
|
|
|
}
|
2019-09-05 14:12:04 -05:00
|
|
|
if (send_msg) {
|
|
|
|
serial_print("Send message prep\n");
|
2019-08-31 16:46:52 -05:00
|
|
|
Message msg;
|
2019-09-10 19:13:34 -05:00
|
|
|
msg.to=vfs_box;
|
|
|
|
msg.from=devfs_vfs_box;
|
2019-09-05 14:12:04 -05:00
|
|
|
msg.size=sizeof(vfs_message);
|
|
|
|
msg.msg=vfs_msg;
|
|
|
|
serial_print("Send message\n");
|
|
|
|
mailbox_send_msg(&msg);
|
|
|
|
serial_print("Done\n");
|
2019-08-31 16:46:52 -05:00
|
|
|
}
|
|
|
|
}
|
2019-09-05 14:12:04 -05:00
|
|
|
free(vfs_msg);
|
|
|
|
yieldToPID(VFS_PID);
|
2019-08-31 16:46:52 -05:00
|
|
|
}
|
|
|
|
|
2019-07-13 10:18:41 -05:00
|
|
|
|
|
|
|
int main() {
|
2019-09-10 19:13:34 -05:00
|
|
|
vfs_box=mailbox_find_by_name("vfs");
|
|
|
|
devfs_vfs_box=mailbox_new(16,"devfs_vfs");
|
2019-09-05 14:12:04 -05:00
|
|
|
devfs_reg_box=mailbox_new(16,"devfs_register");
|
|
|
|
devfs_drv_box=mailbox_new(16,"devfs_driver");
|
2019-09-10 19:13:34 -05:00
|
|
|
register_fs("devfs",devfs_vfs_box);
|
2019-08-31 16:46:52 -05:00
|
|
|
dev_names=malloc(sizeof(char*)*32);
|
|
|
|
dev_mboxes=malloc(sizeof(uint32_t)*32);
|
|
|
|
dev_types=malloc(sizeof(int)*32);
|
2019-07-13 10:40:23 -05:00
|
|
|
for (;;) {
|
|
|
|
Message msg;
|
|
|
|
msg.msg=malloc(sizeof(vfs_message));
|
2019-09-10 19:13:34 -05:00
|
|
|
mailbox_get_msg(devfs_vfs_box,&msg,sizeof(vfs_message));
|
2019-07-13 10:40:23 -05:00
|
|
|
if (msg.from==0) {
|
2019-09-01 14:15:01 -05:00
|
|
|
free(msg.msg);
|
2019-07-13 10:40:23 -05:00
|
|
|
} else {
|
|
|
|
vfs_message* vfs_msg=(vfs_message*)msg.msg;
|
2019-09-05 14:12:04 -05:00
|
|
|
process_vfs_msg(vfs_msg,msg.from);
|
2019-10-20 09:44:33 -05:00
|
|
|
free(msg.msg);
|
2019-09-05 14:12:04 -05:00
|
|
|
}
|
|
|
|
mailbox_get_msg(devfs_drv_box,&msg,sizeof(vfs_message));
|
|
|
|
if (msg.from==0) {
|
2019-09-01 14:15:01 -05:00
|
|
|
free(msg.msg);
|
2019-09-05 14:12:04 -05:00
|
|
|
} else {
|
|
|
|
vfs_message* vfs_msg=(vfs_message*)msg.msg;
|
|
|
|
process_vfs_msg(vfs_msg,msg.from);
|
2019-10-20 09:44:33 -05:00
|
|
|
free(msg.msg);
|
2019-07-13 10:40:23 -05:00
|
|
|
}
|
2019-08-31 16:46:52 -05:00
|
|
|
msg.msg=malloc(sizeof(devfs_message));
|
2019-09-05 14:12:04 -05:00
|
|
|
mailbox_get_msg(devfs_reg_box,&msg,sizeof(devfs_message));
|
2019-10-20 09:44:33 -05:00
|
|
|
if (msg.from==0) {
|
|
|
|
free(msg.msg);
|
|
|
|
} else {
|
2019-08-31 16:46:52 -05:00
|
|
|
devfs_message* devfs_msg=(devfs_message*)msg.msg;
|
|
|
|
if (num_devs==max_devs) {
|
|
|
|
max_devs+=32;
|
|
|
|
dev_names=realloc(dev_names,sizeof(char*)*max_devs);
|
|
|
|
dev_mboxes=realloc(dev_mboxes,sizeof(uint32_t)*max_devs);
|
|
|
|
dev_types=realloc(dev_types,sizeof(int)*max_devs);
|
|
|
|
}
|
|
|
|
dev_names[num_devs]=malloc(sizeof(char)*strlen(&devfs_msg->name[0]));
|
|
|
|
strcpy(dev_names[num_devs],&devfs_msg->name[0]);
|
|
|
|
dev_mboxes[num_devs]=devfs_msg->mbox;
|
|
|
|
dev_types[num_devs]=devfs_msg->dev_type;
|
|
|
|
num_devs++;
|
2019-10-20 09:44:33 -05:00
|
|
|
free(msg.msg);
|
2019-08-31 16:46:52 -05:00
|
|
|
}
|
2019-09-01 14:15:01 -05:00
|
|
|
yield();
|
2019-07-13 10:18:41 -05:00
|
|
|
}
|
|
|
|
}
|