summaryrefslogtreecommitdiffstats
path: root/src/sys/vfs/vfs_main.C
blob: 322768fc995757008e74455dae61ff45fc7409aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <string.h>

#include <sys/msg.h>
#include <sys/vfs.h>
#include <sys/task.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/";

void vfs_module_init();

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)
{
    // Create message queue, register with kernel.
    msg_q_t vfsMsgQ = msg_q_create();
    msg_q_register(vfsMsgQ, VFS_ROOT);

    printk("done.\n");
    // TODO... barrier with init.

    // Initalize modules.
    vfs_module_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 %p 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;

	    case VFS_MSG_EXEC:
		{
		    printk("VFS: Got exec request of %s\n",
		           (const char*)msg->data[0]);
		    VfsSystemModule* module = &VFS_MODULES[0];
		    tid_t child = -1;
		    while ('\0' != module->module[0])
		    {
			if (0 == strcmp((const char*) msg->data[0],
					module->module))
			{
			    if ( module->start == NULL)
			    {
			        //  module has no _start() routine,
			        //  return child = -1
			        break;
			    }
			    child = task_create(module->start,
					        (void*) msg->data[1]);
			    break;
			}
                        module++;
		    }
		    msg->data[0] = child;
		    msg_respond(vfsMsgQ, msg);
		}
		break;

	    default:
		msg_free(msg);
		break;
	}
    }   // end while(1)
}
OpenPOWER on IntegriCloud