Contiki 2.5
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
core
cfs
cfs.h
Go to the documentation of this file.
1
/**
2
* \addtogroup sys
3
* @{
4
*/
5
6
/**
7
* \defgroup cfs The Contiki file system interface
8
*
9
* The Contiki file system interface (CFS) defines an abstract API for
10
* reading directories and for reading and writing files. The CFS API
11
* is intentionally simple. The CFS API is modeled after the POSIX
12
* file API, and slightly simplified.
13
*
14
* @{
15
*/
16
17
/**
18
* \file
19
* CFS header file.
20
* \author
21
* Adam Dunkels <adam@sics.se>
22
*
23
*/
24
25
/*
26
* Copyright (c) 2004, Swedish Institute of Computer Science.
27
* All rights reserved.
28
*
29
* Redistribution and use in source and binary forms, with or without
30
* modification, are permitted provided that the following conditions
31
* are met:
32
* 1. Redistributions of source code must retain the above copyright
33
* notice, this list of conditions and the following disclaimer.
34
* 2. Redistributions in binary form must reproduce the above copyright
35
* notice, this list of conditions and the following disclaimer in the
36
* documentation and/or other materials provided with the distribution.
37
* 3. Neither the name of the Institute nor the names of its contributors
38
* may be used to endorse or promote products derived from this software
39
* without specific prior written permission.
40
*
41
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
42
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
45
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51
* SUCH DAMAGE.
52
*
53
* This file is part of the Contiki operating system.
54
*
55
* Author: Adam Dunkels <adam@sics.se>
56
*
57
* $Id: cfs.h,v 1.18 2009/03/01 12:28:39 oliverschmidt Exp $
58
*/
59
#ifndef __CFS_H__
60
#define __CFS_H__
61
62
#include "contiki.h"
63
#include "cfs-coffee-arch.h"
64
65
#ifndef CFS_CONF_OFFSET_TYPE
66
typedef
int
cfs_offset_t;
67
#else
68
typedef
CFS_CONF_OFFSET_TYPE cfs_offset_t;
69
#endif
70
71
struct
cfs_dir {
72
char
dummy_space[32];
73
};
74
75
struct
cfs_dirent {
76
char
name[32];
77
cfs_offset_t size;
78
};
79
80
/**
81
* Specify that cfs_open() should open a file for reading.
82
*
83
* This constant indicates to cfs_open() that a file should be opened
84
* for reading. CFS_WRITE should be used if the file is opened for
85
* writing, and CFS_READ + CFS_WRITE indicates that the file is opened
86
* for both reading and writing.
87
*
88
* \sa cfs_open()
89
*/
90
#ifndef CFS_READ
91
#define CFS_READ 1
92
#endif
93
94
/**
95
* Specify that cfs_open() should open a file for writing.
96
*
97
* This constant indicates to cfs_open() that a file should be opened
98
* for writing. CFS_READ should be used if the file is opened for
99
* reading, and CFS_READ + CFS_WRITE indicates that the file is opened
100
* for both reading and writing.
101
*
102
* \sa cfs_open()
103
*/
104
#ifndef CFS_WRITE
105
#define CFS_WRITE 2
106
#endif
107
108
/**
109
* Specify that cfs_open() should append written data to the file rather than overwriting it.
110
*
111
* This constant indicates to cfs_open() that a file that should be
112
* opened for writing gets written data appended to the end of the
113
* file. The default behaviour (without CFS_APPEND) is that the file
114
* is overwritten with the new data.
115
*
116
* \sa cfs_open()
117
*/
118
#ifndef CFS_APPEND
119
#define CFS_APPEND 4
120
#endif
121
122
/**
123
* Specify that cfs_seek() should compute the offset from the beginning of the file.
124
*
125
* \sa cfs_seek()
126
*/
127
#ifndef CFS_SEEK_SET
128
#define CFS_SEEK_SET 0
129
#endif
130
131
/**
132
* Specify that cfs_seek() should compute the offset from the current position of the file pointer.
133
*
134
* \sa cfs_seek()
135
*/
136
#ifndef CFS_SEEK_CUR
137
#define CFS_SEEK_CUR 1
138
#endif
139
140
/**
141
* Specify that cfs_seek() should compute the offset from the end of the file.
142
*
143
* \sa cfs_seek()
144
*/
145
#ifndef CFS_SEEK_END
146
#define CFS_SEEK_END 2
147
#endif
148
149
/**
150
* \brief Open a file.
151
* \param name The name of the file.
152
* \param flags CFS_READ, or CFS_WRITE/CFS_APPEND, or both.
153
* \return A file descriptor, if the file could be opened, or -1 if
154
* the file could not be opened.
155
*
156
* This function opens a file and returns a file
157
* descriptor for the opened file. If the file could not
158
* be opened, the function returns -1. The function can
159
* open a file for reading or writing, or both.
160
*
161
* An opened file must be closed with cfs_close().
162
*
163
* \sa CFS_READ
164
* \sa CFS_WRITE
165
* \sa cfs_close()
166
*/
167
#ifndef cfs_open
168
CCIF
int
cfs_open
(
const
char
*name,
int
flags
);
169
#endif
170
171
/**
172
* \brief Close an open file.
173
* \param fd The file descriptor of the open file.
174
*
175
* This function closes a file that has previously been
176
* opened with cfs_open().
177
*/
178
#ifndef cfs_close
179
CCIF
void
cfs_close
(
int
fd);
180
#endif
181
182
/**
183
* \brief Read data from an open file.
184
* \param fd The file descriptor of the open file.
185
* \param buf The buffer in which data should be read from the file.
186
* \param len The number of bytes that should be read.
187
* \return The number of bytes that was actually read from the file.
188
*
189
* This function reads data from an open file into a
190
* buffer. The file must have first been opened with
191
* cfs_open() and the CFS_READ flag.
192
*/
193
#ifndef cfs_read
194
CCIF
int
cfs_read(
int
fd,
void
*buf,
unsigned
int
len);
195
#endif
196
197
/**
198
* \brief Write data to an open file.
199
* \param fd The file descriptor of the open file.
200
* \param buf The buffer from which data should be written to the file.
201
* \param len The number of bytes that should be written.
202
* \return The number of bytes that was actually written to the file.
203
*
204
* This function reads writes data from a memory buffer to
205
* an open file. The file must have been opened with
206
* cfs_open() and the CFS_WRITE flag.
207
*/
208
#ifndef cfs_write
209
CCIF
int
cfs_write(
int
fd,
const
void
*buf,
unsigned
int
len);
210
#endif
211
212
/**
213
* \brief Seek to a specified position in an open file.
214
* \param fd The file descriptor of the open file.
215
* \param offset A position, either relative or absolute, in the file.
216
* \param whence Determines how to interpret the offset parameter.
217
* \return The new position in the file, or (cfs_offset_t)-1 if the seek failed.
218
*
219
* This function moves the file position to the specified
220
* position in the file. The next byte that is read from
221
* or written to the file will be at the position given
222
* determined by the combination of the offset parameter
223
* and the whence parameter.
224
*
225
* \sa CFS_SEEK_CUR
226
* \sa CFS_SEEK_END
227
* \sa CFS_SEEK_SET
228
*/
229
#ifndef cfs_seek
230
CCIF cfs_offset_t
cfs_seek
(
int
fd, cfs_offset_t offset,
int
whence);
231
#endif
232
233
/**
234
* \brief Remove a file.
235
* \param name The name of the file.
236
* \retval 0 If the file was removed.
237
* \return -1 If the file could not be removed or if it doesn't exist.
238
*/
239
#ifndef cfs_remove
240
CCIF
int
cfs_remove
(
const
char
*name);
241
#endif
242
243
/**
244
* \brief Open a directory for reading directory entries.
245
* \param dirp A pointer to a struct cfs_dir that is filled in by the function.
246
* \param name The name of the directory.
247
* \return 0 or -1 if the directory could not be opened.
248
*
249
* \sa cfs_readdir()
250
* \sa cfs_closedir()
251
*/
252
#ifndef cfs_opendir
253
CCIF
int
cfs_opendir
(
struct
cfs_dir *dirp,
const
char
*name);
254
#endif
255
256
/**
257
* \brief Read a directory entry
258
* \param dirp A pointer to a struct cfs_dir that has been opened with cfs_opendir().
259
* \param dirent A pointer to a struct cfs_dirent that is filled in by cfs_readdir()
260
* \retval 0 If a directory entry was read.
261
* \retval -1 If no more directory entries can be read.
262
*
263
* \sa cfs_opendir()
264
* \sa cfs_closedir()
265
*/
266
#ifndef cfs_readdir
267
CCIF
int
cfs_readdir
(
struct
cfs_dir *dirp,
struct
cfs_dirent *dirent);
268
#endif
269
270
/**
271
* \brief Close a directory opened with cfs_opendir().
272
* \param dirp A pointer to a struct cfs_dir that has been opened with cfs_opendir().
273
*
274
* \sa cfs_opendir()
275
* \sa cfs_readdir()
276
*/
277
#ifndef cfs_closedir
278
CCIF
void
cfs_closedir
(
struct
cfs_dir *dirp);
279
#endif
280
281
#endif
/* __CFS_H__ */
282
283
/** @} */
284
/** @} */
Generated on Fri Aug 30 2013 12:34:04 for Contiki 2.5 by
1.8.3.1