adamdunkels | 23c20c7 | 2004-08-09 21:36:49 +0000 | [diff] [blame^] | 1 | #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 | |
| 10 | static int s_open(const char *n, int f); |
| 11 | static void s_close(int f); |
| 12 | static int s_read(int f, char *b, unsigned int l); |
| 13 | static int s_write(int f, char *b, unsigned int l); |
| 14 | static int s_opendir(struct cfs_dir *p, const char *n); |
| 15 | static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e); |
| 16 | static int s_closedir(struct cfs_dir *p); |
| 17 | |
| 18 | static 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 | |
| 30 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 31 | EK_PROCESS(proc, CFS_SERVICE_NAME ": KERNAL", EK_PRIO_NORMAL, |
| 32 | eventhandler, NULL, (void *)&interface); |
| 33 | |
| 34 | /*---------------------------------------------------------------------------*/ |
| 35 | LOADER_INIT_FUNC(cfs_cbm_init, arg) |
| 36 | { |
| 37 | arg_free(arg); |
| 38 | ek_service_start(CFS_SERVICE_NAME, &proc); |
| 39 | } |
| 40 | /*---------------------------------------------------------------------------*/ |
| 41 | EK_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 | /*---------------------------------------------------------------------------*/ |
| 57 | static int |
| 58 | s_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 | /*---------------------------------------------------------------------------*/ |
| 66 | static void |
| 67 | s_close(int f) |
| 68 | { |
| 69 | cbm_close(f); |
| 70 | } |
| 71 | /*---------------------------------------------------------------------------*/ |
| 72 | static int |
| 73 | s_read(int f, char *b, unsigned int l) |
| 74 | { |
| 75 | return cbm_read(f, b, l); |
| 76 | } |
| 77 | /*---------------------------------------------------------------------------*/ |
| 78 | static int |
| 79 | s_write(int f, char *b, unsigned int l) |
| 80 | { |
| 81 | return cbm_write(f, b, l); |
| 82 | } |
| 83 | /*---------------------------------------------------------------------------*/ |
| 84 | static int |
| 85 | s_opendir(struct cfs_dir *p, const char *n) |
| 86 | { |
| 87 | return cbm_opendir(4, 8); |
| 88 | } |
| 89 | /*---------------------------------------------------------------------------*/ |
| 90 | static int |
| 91 | s_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 | /*---------------------------------------------------------------------------*/ |
| 101 | static int |
| 102 | s_closedir(struct cfs_dir *p) |
| 103 | { |
| 104 | cbm_closedir(4); |
| 105 | return 1; |
| 106 | } |
| 107 | /*---------------------------------------------------------------------------*/ |