kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of the Institute nor the names of its contributors |
| 14 | * may be used to endorse or promote products derived from this software |
| 15 | * without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | * |
| 29 | * This file is part of the Contiki operating system. |
| 30 | * |
| 31 | * Author: Adam Dunkels <adam@sics.se> |
| 32 | * |
| 33 | * $Id: cfs-cbm.c,v 1.1 2006/04/17 15:11:57 kthacker Exp $ |
| 34 | */ |
| 35 | #include "contiki.h" |
| 36 | |
| 37 | #include "log.h" |
| 38 | #include "cfs.h" |
| 39 | #include "cfs-service.h" |
| 40 | |
| 41 | #include <cbm.h> |
| 42 | #include <string.h> |
| 43 | |
| 44 | static int s_open(const char *n, int f); |
| 45 | static void s_close(int f); |
| 46 | static int s_read(int f, char *b, unsigned int l); |
| 47 | static int s_write(int f, char *b, unsigned int l); |
| 48 | static int s_opendir(struct cfs_dir *p, const char *n); |
| 49 | static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e); |
| 50 | static int s_closedir(struct cfs_dir *p); |
| 51 | |
| 52 | static const struct cfs_service_interface interface = |
| 53 | { |
| 54 | CFS_SERVICE_VERSION, |
| 55 | s_open, |
| 56 | s_close, |
| 57 | s_read, |
| 58 | s_write, |
| 59 | s_opendir, |
| 60 | s_readdir, |
| 61 | s_closedir |
| 62 | }; |
| 63 | |
| 64 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 65 | EK_PROCESS(proc, CFS_SERVICE_NAME ": KERNAL", EK_PRIO_NORMAL, |
| 66 | eventhandler, NULL, (void *)&interface); |
| 67 | |
| 68 | /*---------------------------------------------------------------------------*/ |
| 69 | LOADER_INIT_FUNC(cfs_cbm_init, arg) |
| 70 | { |
| 71 | arg_free(arg); |
| 72 | ek_service_start(CFS_SERVICE_NAME, &proc); |
| 73 | } |
| 74 | /*---------------------------------------------------------------------------*/ |
| 75 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 76 | { |
| 77 | switch(ev) { |
| 78 | case EK_EVENT_INIT: |
| 79 | case EK_EVENT_REPLACE: |
| 80 | log_message("Starting KERNAL CFS", ""); |
| 81 | break; |
| 82 | case EK_EVENT_REQUEST_REPLACE: |
| 83 | ek_replace((struct ek_proc *)data, &interface); |
| 84 | break; |
| 85 | case EK_EVENT_REQUEST_EXIT: |
| 86 | ek_exit(); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | /*---------------------------------------------------------------------------*/ |
| 91 | static int |
| 92 | s_open(const char *n, int f) |
| 93 | { |
| 94 | if(cbm_open(2, 8, f, n) == 0) { |
| 95 | return 2; |
| 96 | } |
| 97 | return -1; |
| 98 | } |
| 99 | /*---------------------------------------------------------------------------*/ |
| 100 | static void |
| 101 | s_close(int f) |
| 102 | { |
| 103 | cbm_close(f); |
| 104 | } |
| 105 | /*---------------------------------------------------------------------------*/ |
| 106 | static int |
| 107 | s_read(int f, char *b, unsigned int l) |
| 108 | { |
| 109 | return cbm_read(f, b, l); |
| 110 | } |
| 111 | /*---------------------------------------------------------------------------*/ |
| 112 | static int |
| 113 | s_write(int f, char *b, unsigned int l) |
| 114 | { |
| 115 | return cbm_write(f, b, l); |
| 116 | } |
| 117 | /*---------------------------------------------------------------------------*/ |
| 118 | static int |
| 119 | s_opendir(struct cfs_dir *p, const char *n) |
| 120 | { |
| 121 | return cbm_opendir(4, 8); |
| 122 | } |
| 123 | /*---------------------------------------------------------------------------*/ |
| 124 | static int |
| 125 | s_readdir(struct cfs_dir *p, struct cfs_dirent *e) |
| 126 | { |
| 127 | struct cbm_dirent ce; |
| 128 | int ret; |
| 129 | ret = cbm_readdir(4, &ce); |
| 130 | strncpy(e->name, ce.name, sizeof(ce.name)); |
| 131 | e->size = ce.size; |
| 132 | return ret; |
| 133 | } |
| 134 | /*---------------------------------------------------------------------------*/ |
| 135 | static int |
| 136 | s_closedir(struct cfs_dir *p) |
| 137 | { |
| 138 | cbm_closedir(4); |
| 139 | return 1; |
| 140 | } |
| 141 | /*---------------------------------------------------------------------------*/ |