2019-06-22 11:11:12 -05:00
|
|
|
#include <tasking.h>
|
2019-06-22 16:11:44 -05:00
|
|
|
#include <ipc/vfs.h>
|
2019-06-27 17:00:23 -05:00
|
|
|
#include <mailboxes.h>
|
2019-06-29 09:04:34 -05:00
|
|
|
#include <stdlib.h>
|
2019-06-22 11:11:12 -05:00
|
|
|
|
2019-06-29 09:55:02 -05:00
|
|
|
#define PROC_FD_LIMIT 1024
|
|
|
|
|
2019-06-29 09:27:41 -05:00
|
|
|
typedef struct _vfs_mapping_struct {
|
|
|
|
char* mntpnt;
|
|
|
|
uint32_t type;
|
|
|
|
struct _vfs_mapping_struct* next;
|
|
|
|
} vfs_mapping;
|
|
|
|
|
2019-06-29 09:55:02 -05:00
|
|
|
typedef struct {
|
|
|
|
char* mntpnt;
|
|
|
|
char* path;
|
|
|
|
uint32_t pos;
|
|
|
|
char error;
|
|
|
|
} vfs_file;
|
|
|
|
|
2019-06-29 09:27:41 -05:00
|
|
|
static const char** drv_names;
|
|
|
|
static uint32_t* drvs;
|
|
|
|
static uint32_t max_drvs;
|
|
|
|
static uint32_t next_drv_indx;
|
|
|
|
static vfs_mapping* head_mapping;
|
|
|
|
static vfs_mapping* tail_mapping;
|
2019-06-29 09:55:02 -05:00
|
|
|
uint32_t* fd_tables[32768];
|
|
|
|
uint16_t open_fds[32768];
|
2019-06-29 09:27:41 -05:00
|
|
|
|
2019-06-29 09:14:59 -05:00
|
|
|
vfs_message* get_message(Message* msg,uint32_t box) {
|
|
|
|
msg->msg=malloc(sizeof(vfs_message));
|
|
|
|
mailbox_get_msg(box,msg,sizeof(vfs_message));
|
|
|
|
vfs_message* vfs_msg=(vfs_message*)msg->msg;
|
|
|
|
msg->to=msg->from;
|
|
|
|
msg->from=box;
|
|
|
|
return vfs_msg;
|
|
|
|
}
|
|
|
|
|
2019-06-29 09:27:41 -05:00
|
|
|
static int vfsstrcmp(const char* s1,const char* s2) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; s1[i] == s2[i]; i++) {
|
|
|
|
if (s1[i] == '\0') return 0;
|
|
|
|
}
|
|
|
|
if (s1[i] == '\0') return 0;
|
|
|
|
return s1[i] - s2[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_vfs() {
|
|
|
|
drvs=malloc(sizeof(uint32_t)*32);
|
|
|
|
drv_names=malloc(sizeof(const char**)*32);
|
|
|
|
max_drvs=32;
|
|
|
|
next_drv_indx=0;
|
|
|
|
head_mapping=NULL;
|
|
|
|
tail_mapping=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t register_fs(uint32_t drv,const char* type) {
|
|
|
|
if (next_drv_indx==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;
|
|
|
|
}
|
|
|
|
|
2019-06-29 09:55:02 -05:00
|
|
|
char fopen(vfs_message* vfs_msg,uint32_t from) {
|
|
|
|
if (fd_tables[from]==NULL) {
|
|
|
|
fd_tables[from]=malloc(PROC_FD_LIMIT*sizeof(vfs_file));
|
|
|
|
open_fds[from]=0;
|
|
|
|
} else {
|
|
|
|
if (open_fds[from]==PROC_FD_LIMIT) {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint16_t fd=open_fds[from];
|
|
|
|
open_fds[from]++;
|
|
|
|
vfs_msg->fd=fd;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-24 11:52:13 -05:00
|
|
|
int main() {
|
2019-06-29 09:27:41 -05:00
|
|
|
init_vfs();
|
2019-06-27 17:00:23 -05:00
|
|
|
uint32_t box=mailbox_new(16);
|
|
|
|
yield();
|
2019-06-29 09:55:02 -05:00
|
|
|
while (1) {
|
|
|
|
Message msg;
|
|
|
|
vfs_message* vfs_msg=get_message(&msg,box);
|
|
|
|
switch (vfs_msg->type) {
|
|
|
|
case VFS_OPEN:
|
|
|
|
vfs_msg->flags=fopen(vfs_msg,msg.from);
|
|
|
|
break;
|
|
|
|
case VFS_PUTC:
|
|
|
|
vfs_msg->flags=1;
|
|
|
|
break;
|
|
|
|
case VFS_GETC:
|
|
|
|
vfs_msg->flags=1;
|
|
|
|
break;
|
|
|
|
case VFS_CLOSE:
|
|
|
|
vfs_msg->flags=1;
|
|
|
|
break;
|
|
|
|
case VFS_MOUNT:
|
|
|
|
vfs_msg->flags=1;
|
|
|
|
break;
|
|
|
|
case VFS_UMOUNT:
|
|
|
|
vfs_msg->flags=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vfs_msg->flags=2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mailbox_send_msg(&msg);
|
|
|
|
yield();
|
2019-06-29 09:21:08 -05:00
|
|
|
}
|
2019-05-24 11:52:13 -05:00
|
|
|
for (;;);
|
|
|
|
}
|