blob: 91f762da78cb2c938f4c7bd9a0e713ac5ed14b66 [file] [log] [blame]
adamdunkels38fb3502004-09-12 20:30:03 +00001/*
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-init.c,v 1.2 2004/09/12 20:30:04 adamdunkels Exp $
34 */
adamdunkels927dad62004-08-09 21:34:24 +000035#include "contiki.h"
36
37#include "cfs.h"
38#include "cfs-service.h"
39
40#include <cbm.h>
41#include <string.h>
42
43static int s_open(const char *n, int f);
44static void s_close(int f);
45static int s_read(int f, char *b, unsigned int l);
46static int s_write(int f, char *b, unsigned int l) {return -1;}
47static int s_opendir(struct cfs_dir *p, const char *n) {return -1;}
48static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e) {return -1;}
49static int s_closedir(struct cfs_dir *p) {return -1;}
50
51static const struct cfs_service_interface interface =
52 {
53 CFS_SERVICE_VERSION,
54 s_open,
55 s_close,
56 s_read,
57 s_write,
58 s_opendir,
59 s_readdir,
60 s_closedir
61 };
62
63EK_EVENTHANDLER(eventhandler, ev, data);
64EK_PROCESS(proc, CFS_SERVICE_NAME ": init", EK_PRIO_NORMAL,
65 eventhandler, NULL, (void *)&interface);
66
67/*---------------------------------------------------------------------------*/
68EK_PROCESS_INIT(cfs_init_init, arg)
69{
70 arg_free(arg);
71 ek_service_start(CFS_SERVICE_NAME, &proc);
72}
73/*---------------------------------------------------------------------------*/
74EK_EVENTHANDLER(eventhandler, ev, data)
75{
76 switch(ev) {
77 case EK_EVENT_INIT:
78 break;
79 case EK_EVENT_REQUEST_REPLACE:
80 ek_replace((struct ek_proc *)data, &interface);
81 break;
82 case EK_EVENT_REQUEST_EXIT:
83 ek_exit();
84 break;
85 }
86}
87/*---------------------------------------------------------------------------*/
88static int
89s_open(const char *n, int f)
90{
91 if(cbm_open(2, 8, CBM_READ, n) == 0) {
92 return 2;
93 }
94 return -1;
95}
96/*---------------------------------------------------------------------------*/
97static void
98s_close(int f)
99{
100 cbm_close(f);
101}
102/*---------------------------------------------------------------------------*/
103static int
104s_read(int f, char *b, unsigned int l)
105{
106 return cbm_read(f, b, l);
107}
108/*---------------------------------------------------------------------------*/