blob: 407885bf9924279c821c67fc52b04bd033b32b23 [file] [log] [blame]
adamdunkels23c20c72004-08-09 21:36:49 +00001#include "contiki.h"
2
3#include "log.h"
4#include "cfs.h"
5#include "cfs-service.h"
6
7#include <cbm.h>
8#include <string.h>
9
10static int s_open(const char *n, int f);
11static void s_close(int f);
12static int s_read(int f, char *b, unsigned int l);
13static int s_write(int f, char *b, unsigned int l);
14static int s_opendir(struct cfs_dir *p, const char *n);
15static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e);
16static int s_closedir(struct cfs_dir *p);
17
18static const struct cfs_service_interface interface =
19 {
20 CFS_SERVICE_VERSION,
21 s_open,
22 s_close,
23 s_read,
24 s_write,
25 s_opendir,
26 s_readdir,
27 s_closedir
28 };
29
30EK_EVENTHANDLER(eventhandler, ev, data);
31EK_PROCESS(proc, CFS_SERVICE_NAME ": KERNAL", EK_PRIO_NORMAL,
32 eventhandler, NULL, (void *)&interface);
33
34/*---------------------------------------------------------------------------*/
35LOADER_INIT_FUNC(cfs_cbm_init, arg)
36{
37 arg_free(arg);
38 ek_service_start(CFS_SERVICE_NAME, &proc);
39}
40/*---------------------------------------------------------------------------*/
41EK_EVENTHANDLER(eventhandler, ev, data)
42{
43 switch(ev) {
44 case EK_EVENT_INIT:
45 case EK_EVENT_REPLACE:
46 log_message("Starting KERNAL CFS", "");
47 break;
48 case EK_EVENT_REQUEST_REPLACE:
49 ek_replace((struct ek_proc *)data, &interface);
50 break;
51 case EK_EVENT_REQUEST_EXIT:
52 ek_exit();
53 break;
54 }
55}
56/*---------------------------------------------------------------------------*/
57static int
58s_open(const char *n, int f)
59{
60 if(cbm_open(2, 8, CBM_READ, n) == 0) {
61 return 2;
62 }
63 return -1;
64}
65/*---------------------------------------------------------------------------*/
66static void
67s_close(int f)
68{
69 cbm_close(f);
70}
71/*---------------------------------------------------------------------------*/
72static int
73s_read(int f, char *b, unsigned int l)
74{
75 return cbm_read(f, b, l);
76}
77/*---------------------------------------------------------------------------*/
78static int
79s_write(int f, char *b, unsigned int l)
80{
81 return cbm_write(f, b, l);
82}
83/*---------------------------------------------------------------------------*/
84static int
85s_opendir(struct cfs_dir *p, const char *n)
86{
87 return cbm_opendir(4, 8);
88}
89/*---------------------------------------------------------------------------*/
90static int
91s_readdir(struct cfs_dir *p, struct cfs_dirent *e)
92{
93 struct cbm_dirent ce;
94 int ret;
95 ret = cbm_readdir(4, &ce);
96 strncpy(e->name, ce.name, sizeof(ce.name));
97 e->size = ce.size;
98 return ret;
99}
100/*---------------------------------------------------------------------------*/
101static int
102s_closedir(struct cfs_dir *p)
103{
104 cbm_closedir(4);
105 return 1;
106}
107/*---------------------------------------------------------------------------*/