summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/include/string.h2
-rw-r--r--src/include/sys/msg.h4
-rw-r--r--src/include/sys/vfs.h26
-rw-r--r--src/lib/string.c12
-rw-r--r--src/lib/syscall_msg.C26
-rw-r--r--src/sys/init/init_main.C8
-rw-r--r--src/sys/makefile4
-rw-r--r--src/sys/vfs/makefile10
-rw-r--r--src/sys/vfs/vfs_main.C78
9 files changed, 157 insertions, 13 deletions
diff --git a/src/include/string.h b/src/include/string.h
index a2b704067..30c878d65 100644
--- a/src/include/string.h
+++ b/src/include/string.h
@@ -9,6 +9,8 @@ extern "C"
#endif
void* memset(void* s, int c, size_t n);
+
+ char* strcpy(char* d, const char* s);
int strcmp(const char* s1, const char* s2);
#ifdef __cplusplus
diff --git a/src/include/sys/msg.h b/src/include/sys/msg.h
index ca5dab7e6..d7c42f4e3 100644
--- a/src/include/sys/msg.h
+++ b/src/include/sys/msg.h
@@ -22,8 +22,8 @@ struct msg_t
// Message queue interfaces.
msg_q_t msg_q_create();
int msg_q_destroy();
-int msg_q_register(msg_q_t q, char* name);
-msg_q_t msg_q_resolve(char* name);
+int msg_q_register(msg_q_t q, const char* name);
+msg_q_t msg_q_resolve(const char* name);
// Message interfaces.
__attribute__((always_inline))
diff --git a/src/include/sys/vfs.h b/src/include/sys/vfs.h
new file mode 100644
index 000000000..579b9ba34
--- /dev/null
+++ b/src/include/sys/vfs.h
@@ -0,0 +1,26 @@
+#ifndef __SYS_VFS_H
+#define __SYS_VFS_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+extern const char* VFS_ROOT;
+extern const char* VFS_ROOT_BIN;
+extern const char* VFS_ROOT_DATA;
+extern const char* VFS_ROOT_MSG;
+
+enum VfsMessages
+{
+ VFS_MSG_REGISTER_MSGQ,
+ VFS_MSG_RESOLVE_MSGQ,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/lib/string.c b/src/lib/string.c
index fb4d435ae..eb8fe3d1c 100644
--- a/src/lib/string.c
+++ b/src/lib/string.c
@@ -10,6 +10,18 @@ void* memset(void* s, int c, size_t n)
}
}
+char* strcpy(char* d, const char* s)
+{
+ char* d1 = d;
+
+ do
+ {
+ *d1 = *s;
+ if (*s == '\0') return d;
+ d1++; s++;
+ } while(1);
+}
+
int strcmp(const char* a, const char* b)
{
while((*a != '\0') && (*b != '\0'))
diff --git a/src/lib/syscall_msg.C b/src/lib/syscall_msg.C
index 774ddb0bb..66eaa1679 100644
--- a/src/lib/syscall_msg.C
+++ b/src/lib/syscall_msg.C
@@ -1,12 +1,11 @@
#include <sys/msg.h>
#include <sys/syscall.h>
+#include <sys/vfs.h>
#include <string.h>
using namespace Systemcalls;
-const char* VFS_ROOT = "/"; // TODO.
-
msg_q_t msg_q_create()
{
return (msg_q_t) _syscall0(MSGQ_CREATE);
@@ -17,7 +16,7 @@ int msg_q_destroy(msg_q_t q)
return (int64_t)_syscall1(MSGQ_DESTROY, q);
}
-int msg_q_register(msg_q_t q, char* name)
+int msg_q_register(msg_q_t q, const char* name)
{
if (0 == strcmp(VFS_ROOT, name))
{
@@ -25,12 +24,17 @@ int msg_q_register(msg_q_t q, char* name)
}
else
{
- // TODO.
- return -1;
+ msg_q_t vfsQ = (msg_q_t)_syscall0(MSGQ_RESOLVE_ROOT);
+ msg_t* msg = msg_allocate();
+ msg->type = VFS_MSG_REGISTER_MSGQ;
+ msg->extra_data = (void*) name;
+ int rc = msg_sendrecv(vfsQ, msg);
+ msg_free(msg);
+ return rc;
}
}
-msg_q_t msg_q_resolve(char* name)
+msg_q_t msg_q_resolve(const char* name)
{
if (0 == strcmp(VFS_ROOT, name))
{
@@ -38,8 +42,14 @@ msg_q_t msg_q_resolve(char* name)
}
else
{
- // TODO.
- return NULL;
+ msg_q_t vfsQ = (msg_q_t)_syscall0(MSGQ_RESOLVE_ROOT);
+ msg_t* msg = msg_allocate();
+ msg->type = VFS_MSG_RESOLVE_MSGQ;
+ msg->extra_data = (void*) name;
+ msg_sendrecv(vfsQ, msg);
+ msg_q_t rc = (msg_q_t) msg->data[0];
+ msg_free(msg);
+ return rc;
}
}
diff --git a/src/sys/init/init_main.C b/src/sys/init/init_main.C
index c11b4ef97..a7bc68b55 100644
--- a/src/sys/init/init_main.C
+++ b/src/sys/init/init_main.C
@@ -14,13 +14,21 @@ void init_child(void* unused)
task_end();
}
+void vfs_main(void*);
+
void init_main(void* unused)
{
printk("Starting init!\n");
+
+ printk("Bringing up VFS...");
+ task_create(&vfs_main, NULL);
+ task_yield(); // TODO... add a barrier to ensure VFS is fully up.
global_mutex = mutex_create();
msg_q_t msgq = msg_q_create();
+ msg_q_register(msgq, "/msg/init");
+
msg_t* msg = msg_allocate();
msg->type = 1; msg->data[0] = 0xDEADBEEF12345678;
msg_send(msgq, msg);
diff --git a/src/sys/makefile b/src/sys/makefile
index 5a553e1d2..0eb552a44 100644
--- a/src/sys/makefile
+++ b/src/sys/makefile
@@ -2,9 +2,7 @@ IMGDIR = ../../img
OBJDIR = ../../obj
include ../../config.mk
-SUBDIRS = init.d
-IMAGES += ${IMGDIR}/kernel.elf
-IMAGES += ${IMGDIR}/kernel.bin
+SUBDIRS = init.d vfs.d
all: ${SUBDIRS}
diff --git a/src/sys/vfs/makefile b/src/sys/vfs/makefile
new file mode 100644
index 000000000..94ca71bbf
--- /dev/null
+++ b/src/sys/vfs/makefile
@@ -0,0 +1,10 @@
+OBJDIR = ../../../obj
+include ../../../config.mk
+
+OBJS = vfs_main.o
+OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
+
+all: ${OBJECTS}
+
+clean:
+ (rm -f ${OBJECTS} )
diff --git a/src/sys/vfs/vfs_main.C b/src/sys/vfs/vfs_main.C
new file mode 100644
index 000000000..6ba561eb2
--- /dev/null
+++ b/src/sys/vfs/vfs_main.C
@@ -0,0 +1,78 @@
+#include <string.h>
+
+#include <sys/msg.h>
+#include <sys/vfs.h>
+
+#include <util/locked/list.H>
+#include <kernel/console.H> // TODO : Remove this.
+
+const char* VFS_ROOT = "/";
+const char* VFS_ROOT_BIN = "/bin/";
+const char* VFS_ROOT_DATA = "/data/";
+const char* VFS_ROOT_MSG = "/msg/";
+
+struct VfsPath
+{
+ char key[64];
+
+ bool operator!=(VfsPath& r) { return 0 != strcmp(key, r.key); };
+};
+
+struct VfsEntry
+{
+ typedef VfsPath key_type;
+ key_type key;
+ msg_q_t msg_q;
+
+ VfsEntry* next;
+ VfsEntry* prev;
+};
+
+void vfs_main(void* unused)
+{
+ msg_q_t vfsMsgQ = msg_q_create();
+ msg_q_register(vfsMsgQ, VFS_ROOT);
+
+ printk("done.\n");
+ // TODO... barrier with init.
+
+ Util::Locked::List<VfsEntry, VfsEntry::key_type> vfsContents;
+
+ while(1)
+ {
+ msg_t* msg = msg_wait(vfsMsgQ);
+
+ switch(msg->type)
+ {
+ case VFS_MSG_REGISTER_MSGQ:
+ {
+ VfsEntry* e = new VfsEntry();
+ strcpy(e->key.key, (char*) msg->extra_data);
+ e->msg_q = (msg_q_t) msg->data[0];
+ vfsContents.insert(e);
+
+ printk("VFS: Registering %llx as %s\n",
+ e->msg_q, e->key.key);
+ msg_respond(vfsMsgQ, msg);
+ }
+ break;
+
+ case VFS_MSG_RESOLVE_MSGQ:
+ {
+ VfsEntry::key_type k;
+ strcpy(k.key, (char*) msg->extra_data);
+ VfsEntry* e = vfsContents.find(k);
+ if (NULL == e)
+ msg->data[0] = (uint64_t) NULL;
+ else
+ msg->data[0] = (uint64_t) e->msg_q;
+ msg_respond(vfsMsgQ, msg);
+ }
+ break;
+
+ default:
+ msg_free(msg);
+ break;
+ }
+ }
+}
OpenPOWER on IntegriCloud