comparison gsm-fw/services/ffs/ffs.h @ 209:6f4a12b4582f

gsm-fw FFS: starting to integrate C code
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 26 Dec 2013 03:59:59 +0000
parents
children
comparison
equal deleted inserted replaced
208:2abe6ade042d 209:6f4a12b4582f
1 /******************************************************************************
2 * Flash File System (ffs)
3 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com
4 *
5 * FFS Types and globals
6 *
7 * $Id: ffs.h 1.19.1.45.1.26 Mon, 28 Apr 2003 11:27:14 +0200 cm $
8 *
9 ******************************************************************************/
10
11 #ifndef _FFS_H_
12 #define _FFS_H_
13
14 #ifndef TARGET
15 #define TARGET 1
16 #define _RVF 1
17 #endif
18
19 #ifdef _RVF
20 #include "../../riviera/rvf/rvf_api.h"
21 #include "../../riviera/rvm/rvm_use_id_list.h"
22 #endif
23
24 /******************************************************************************
25 * Types
26 ******************************************************************************/
27
28 #ifndef BASIC_TYPES
29 #define BASIC_TYPES
30 typedef signed char int8;
31 typedef unsigned char uint8;
32 typedef signed short int16;
33 typedef unsigned short uint16;
34 typedef signed int int32;
35 typedef unsigned int uint32;
36 #endif
37
38 #if (TARGET == 1)
39 // Unique message offset returned in the header of each mail (msg_id).
40 #define FFS_MESSAGE_OFFSET BUILD_MESSAGE_OFFSET(FFS_USE_ID)
41 #endif
42
43 typedef int8 effs_t; // error type
44 //typedef int effs_t;
45 typedef int32 req_id_t; // request id
46 typedef int32 offset_t; // offset from first address of ffs.
47 typedef uint32 location_t; // object location offset
48 typedef int32 blocksize_t; // can hold size of a block
49 typedef uint8 objflags_t; // object flags
50 typedef uint8 objtype_t; // object type
51
52 typedef int16 iref_t; // inode reference
53 typedef int8 bref_t; // block reference
54
55 typedef int32 fd_t; // file descriptor
56 typedef uint16 ffs_options_t; // option flags to open() and file_write()
57
58 // For directory operations
59 struct dir_s {
60 iref_t this; // iref of dir that was opened
61 iref_t index; // last inode returned by ffs_readdir()
62 };
63
64 // File stat structure
65 struct stat_s {
66 objtype_t type;
67 objflags_t flags;
68 iref_t inode;
69 int size; // size of data space occupied by object
70 };
71
72 // File xstat structure
73 struct xstat_s {
74 objtype_t type;
75 objflags_t flags;
76 iref_t inode;
77 int size; // size of data space occupied by object
78 int space; // size of physical data space occupied by object
79 location_t location;
80 uint8 reserved; // only for debug
81 bref_t block; // only for debug
82 uint16 sequence; // only for debug
83 uint16 updates; // only for debug
84 };
85
86 #if (TARGET == 0)
87 // Only use to run on PC and not in target. Must be syncron with the typedef
88 // from rv_general.h
89 typedef void (*CALLBACK_FUNC)(void *);
90
91 typedef uint16 T_RVF_ADDR_ID;
92
93 /* define return_path */
94 typedef struct
95 {
96 T_RVF_ADDR_ID addr_id;
97 void (*callback_func)(void *);
98 } T_RV_RETURN;
99
100 /* Define the header of each message used in Riviera. */
101 typedef struct {
102 uint32 msg_id;
103 void (*callback_func)(void *);
104 T_RVF_ADDR_ID src_addr_id;
105 T_RVF_ADDR_ID dest_addr_id;
106 } T_RV_HDR;
107
108 // Used riviera types
109 typedef uint16 UINT16;
110 typedef int8 INT8;
111
112 #endif
113
114 // Confirm mail sent from FFS task to caller (application)
115 struct ffs_file_cnf_s {
116 T_RV_HDR header;
117 int error; // error code of FFS operation
118 req_id_t request_id; // Unique id number
119 char *path; // path name of object operation was performed on
120 };
121
122 struct ffs_stream_cnf_s {
123 T_RV_HDR header;
124 int error; // error code of FFS operation
125 req_id_t request_id; // Unique id number
126 fd_t fdi; // file descriptor
127 };
128
129 /******************************************************************************
130 * RVF Types
131 ******************************************************************************/
132
133 typedef ffs_options_t T_FFS_OPEN_FLAGS;
134 typedef int T_FFS_SIZE;
135 typedef offset_t T_FFS_OFFSET;
136 typedef effs_t T_FFS_RET;
137 typedef req_id_t T_FFS_REQ_ID;
138 typedef int T_FFS_WHENCE;
139 typedef fd_t T_FFS_FD;
140 typedef objtype_t T_FFS_OBJECT_TYPE;
141 typedef objflags_t T_FFS_FLAGS;
142 typedef struct stat_s T_FFS_STAT;
143 typedef struct xstat_s T_FFS_XSTAT;
144 typedef struct dir_s T_FFS_DIR;
145 typedef struct ffs_file_cnf_s T_FFS_FILE_CNF;
146 typedef struct ffs_stream_cnf_s T_FFS_STREAM_CNF;
147
148 /******************************************************************************
149 * Errors
150 ******************************************************************************/
151
152 enum FFS_ERRORS {
153 EFFS_OK = 0, /* ok */
154 EFFS_NODEVICE = -1, /* flash device unknown */
155 EFFS_CORRUPTED = -2, /* filesystem corrupted!? */
156 EFFS_NOPREFORMAT = -3, /* ffs not preformatted */
157 EFFS_NOFORMAT = -4, /* ffs not formatted */
158 EFFS_BADFORMAT = -5, /* incompatible ffs version, re-format needed */
159 EFFS_MAGIC = -6, /* bad magic */
160 EFFS_AGAIN = -7, /* not ready, try again later */
161 EFFS_NOSYS = -8, /* function not implemented */
162 EFFS_DRIVER = -9, /* ffs device driver error */
163
164 EFFS_NOSPACE = -10, /* out of data space */
165 EFFS_FSFULL = -11, /* file system full, no free inodes */
166 EFFS_BADNAME = -12, /* bad filename */
167 EFFS_NOTFOUND = -13, /* object not found */
168 EFFS_EXISTS = -14, /* object exists */
169 EFFS_ACCESS = -15, /* access permission violation */
170 EFFS_NAMETOOLONG = -16, /* filename too long */
171 EFFS_INVALID = -17, /* invalid argument */
172 EFFS_DIRNOTEMPTY = -18, /* directory not empty */
173 EFFS_NOTADIR = -19, /* object is not a directory */
174 EFFS_SPARE = -20, /* SPARE */
175 EFFS_FILETOOBIG = -21, /* file too big */
176 EFFS_NOTAFILE = -22, /* object is not a file */
177 EFFS_PATHTOODEEP = -23, /* path too deep */
178
179 EFFS_NUMFD = -24, /* Max number of open files reached */
180 EFFS_BADFD = -25, /* Bad file descriptor */
181 EFFS_BADOP = -26, /* Bad operation */
182 EFFS_LOCKED = -27, /* The file is locked */
183
184 EFFS_TOOBIG = -30, /* too big (tmffs buffer overflow) */
185 EFFS_MEMORY = -31, /* out of memory */
186 EFFS_MSGSEND = -32, /* message send failed */
187
188 /* debug errors */
189
190 EFFS_SIBLINGLOOP = -40, /* directory sibling loop */
191 EFFS_NOBLOCKS = -41, /* No more blocks!? */
192 EFFS_DBR = -42, /* Data reclaim did not finish!? */
193 EFFS_RECLAIMLOOP = -43 /* Data reclaim loop */
194 };
195
196
197 /******************************************************************************
198 * Enumerations
199 ******************************************************************************/
200
201 enum FFS_OBJECT_CONTROL_ACTION {
202 OC_FLAGS = 1
203 };
204
205 enum FFS_OBJECT_TYPE {
206 OT_FILE = 1,
207 OT_DIR = 2,
208 OT_LINK = 3,
209 OT_SEGMENT = 4
210 };
211
212 enum FFS_OBJECT_FLAGS {
213 OF_READONLY = 1<<4 // object cannot be modified
214 };
215
216 enum FFS_OPEN {
217 FFS_O_EMPTY = 0x00, // Okay?
218 FFS_O_CREATE = 0x01,
219 FFS_O_APPEND = 0x02,
220 FFS_O_EXCL = 0x04,
221 FFS_O_TRUNC = 0x08,
222 FFS_O_RDONLY = 0x10,
223 FFS_O_WRONLY = 0x20,
224 FFS_O_RDWR = FFS_O_RDONLY | FFS_O_WRONLY
225 };
226
227 enum FFS_SEEK {
228 FFS_SEEK_SET = 0,
229 FFS_SEEK_CUR = 1,
230 FFS_SEEK_END = 2
231 };
232
233 // FIXME: debug indices to go into core.h
234 enum FFS_QUERY { // data size, description
235 Q_BYTES_FREE = 1, // 4, number of free bytes in FFS
236 Q_BYTES_USED = 2, // 4, number of used bytes in FFS
237 Q_BYTES_LOST = 3, // 4, number of lost bytes in FFS
238 Q_BYTES_MAX = 4, // 4, number of max available bytes in FFS
239 Q_BYTES_FREE_RAW = 5, // 4, number of free raw bytes in FFS (used internal)
240
241 Q_FD_BUF_SIZE = 10, // 4, size of buffer used by stream functions
242
243 Q_TM_BUFADDR = 11, // 4, testmode buffer addr
244 Q_TM_BUFSIZE = 12, // 4, testmode ffs buffer size
245 Q_DEV_BASE = 13, // 4, FFS device base address
246 Q_CHUNK_SIZE_MAX = 14, // 4, max size of chunks made by non stream fkt.
247
248 // FFS versions
249 Q_FFS_API_VERSION = 16, // 2, FFS API Version
250 Q_FFS_DRV_VERSION = 17, // 2, FFS Driver Version
251 Q_FFS_REVISION = 18, // 2, FFS Revision (from PRCS)
252 Q_FFS_FORMAT_READ = 19, // 2, FFS version as read from ffs
253 Q_FFS_LASTERROR = 20, // 2, FFS last error (from init)
254 Q_FFS_FORMAT_WRITE = 21, // 2, FFS version as written to ffs on format
255 Q_FFS_TM_VERSION = 22, // 2, FFS Testmode version
256
257 // File system queries
258 Q_FILENAME_MAX = 24, // 2, max filename length
259 Q_PATH_DEPTH_MAX = 25, // 2, max path/directory nesting depth
260 Q_FD_MAX = 26, // 2, max numbers of simultaneous open files
261
262 Q_OBJECTS_FREE = 32, // 2, number of objects that can be created
263 Q_INODES_USED = 33, // 2, number of inodes used
264 Q_INODES_LOST = 34, // 2, number of inodes lost
265 Q_OBJECTS_USED = 33, // 2, DEPRECATED: old name for Q_INODES_USED
266 Q_OBJECTS_LOST = 34, // 2, DEPRECATED: old name for Q_INODES_LOST
267 Q_OBJECTS_MAX = 35, // 2, max number of valid objects allowed
268 Q_INODES_MAX = 36, // 2, physical total max number of inodes
269 Q_INODES_HIGH = 37, // 2, watermark for when inodes will be reclaimed
270 Q_LOST_HIGH = 38, // 2, watermark for when data block will be reclaimed
271
272 // Device queries
273 Q_DEV_MANUFACTURER = 48, // 2, flash manufacturer ID
274 Q_DEV_DEVICE = 49, // 2, flash device ID
275 Q_DEV_BLOCKS = 50, // 2, number of FFS blocks in device
276 Q_DEV_ATOMSIZE = 51, // 2, atomsize used by FFS for this device
277 Q_DEV_DRIVER = 52, // 2, flash device driver
278
279 // All queries below here are for debug purpose only, are unsupported
280 // and can change at any time without notice!
281
282 // Miscellaneous/Internal
283 Q_BLOCKS_FREE_MIN = 64, // 2, Number of spare blocks (0 or 1)
284
285 Q_BLOCKS_FREE = 70, // 2, number of free blocks
286
287 // Debug queries
288 Q_FS_FLAGS = 80,
289 Q_FS_INODES = 81,
290 Q_FS_ROOT = 82,
291
292 Q_OBJECTS_TOTAL = 90, // 2, Accumulated number of valid objects
293 Q_TOTAL_OBJECTS = 90, // 2, DEPRECATED: old name for Q_OBJECTS_TOTAL
294
295 Q_STATS_FIRST = 100,
296 Q_STATS_DRECLAIMS = 100,
297 Q_STATS_IRECLAIMS = 101,
298 Q_STATS_BRECLAIMS = 102,
299 Q_STATS_DATA_RECLAIMED = 103,
300 Q_STATS_INODES_RECLAIMED = 104,
301 Q_STATS_DATA_ALLOCATED = 105,
302
303 Q_REQUEST_ID_LAST = 110,
304
305 Q_DEBUG_FIRST = 120,
306 Q_DEBUG_0 = 120,
307 Q_DEBUG_1 = 121,
308 Q_DEBUG_2 = 122,
309 Q_DEBUG_3 = 123,
310 Q_DEBUG_LAST = 127,
311
312 // individual lines of the bstat array can be returned by the following
313 // id plus the bstat index of the line wanted.
314 Q_BSTAT = -128
315 };
316
317
318 /******************************************************************************
319 * Function prototypes
320 ******************************************************************************/
321
322 // Call-back function prototypes
323 T_FFS_REQ_ID ffs_fcreate_nb(const char *name, void *addr, T_FFS_SIZE size,
324 T_RV_RETURN *cp);
325 T_FFS_REQ_ID ffs_fupdate_nb(const char *name, void *addr, T_FFS_SIZE size,
326 T_RV_RETURN *cp);
327 T_FFS_REQ_ID ffs_fwrite_nb(const char *name, void *addr, T_FFS_SIZE size,
328 T_RV_RETURN *cp);
329 T_FFS_REQ_ID ffs_file_write_nb(const char *name, void *addr, T_FFS_SIZE size,
330 T_FFS_OPEN_FLAGS flags, T_RV_RETURN *cp);
331
332 T_FFS_REQ_ID ffs_mkdir_nb(const char *name, T_RV_RETURN *cp);
333 T_FFS_REQ_ID ffs_symlink_nb(const char *name, const char *actualpath,
334 T_RV_RETURN *cp);
335
336 T_FFS_REQ_ID ffs_remove_nb(const char *namestruct, T_RV_RETURN *cp);
337 T_FFS_REQ_ID ffs_fcontrol_nb(const char *pathname, INT8 action, int param,
338 T_RV_RETURN *cp);
339
340 T_FFS_REQ_ID ffs_rename_nb(const char *oldname, const char *newname,
341 T_RV_RETURN *cp);
342 T_FFS_REQ_ID ffs_preformat_nb(UINT16 magic, T_RV_RETURN *cp);
343 T_FFS_REQ_ID ffs_format_nb(const char *name, UINT16 magic, T_RV_RETURN *cp);
344
345 T_FFS_REQ_ID ffs_open_nb(const char *name, T_FFS_OPEN_FLAGS option,
346 T_RV_RETURN *cp);
347 T_FFS_REQ_ID ffs_close_nb(T_FFS_FD fdi, T_RV_RETURN *cp);
348 T_FFS_REQ_ID ffs_write_nb(T_FFS_FD fdi, void *src, T_FFS_SIZE size,
349 T_RV_RETURN *cp);
350 T_FFS_REQ_ID ffs_seek_nb(T_FFS_FD fdi, T_FFS_SIZE offset, T_FFS_WHENCE whence
351 , T_RV_RETURN *cp);
352 T_FFS_REQ_ID ffs_truncate_nb(const char *path, T_FFS_OFFSET length,
353 T_RV_RETURN *cp);
354 T_FFS_REQ_ID ffs_ftruncate_nb(T_FFS_FD fdi, T_FFS_OFFSET length,
355 T_RV_RETURN *cp);
356 T_FFS_REQ_ID ffs_fdatasync_nb(T_FFS_FD fdi, T_RV_RETURN *cp);
357
358 // No-call-back function prototypes
359 T_FFS_RET ffs_fcreate(const char *name, void *addr, T_FFS_SIZE size);
360 T_FFS_RET ffs_fupdate(const char *name, void *addr, T_FFS_SIZE size);
361 T_FFS_RET ffs_fwrite(const char *name, void *addr, T_FFS_SIZE size);
362 T_FFS_RET ffs_file_write(const char *name, void *addr, T_FFS_SIZE size,
363 T_FFS_OPEN_FLAGS flags);
364 T_FFS_SIZE ffs_fread(const char *name, void *addr, T_FFS_SIZE size);
365 T_FFS_SIZE ffs_file_read(const char *name, void *addr, T_FFS_SIZE size);
366
367 T_FFS_RET ffs_mkdir(const char *name);
368 T_FFS_SIZE ffs_opendir(const char *name, T_FFS_DIR *dir);
369 T_FFS_SIZE ffs_readdir (T_FFS_DIR *dir, char *name, T_FFS_SIZE size);
370
371 T_FFS_RET ffs_symlink(const char *name, const char *actualpath);
372 T_FFS_SIZE ffs_readlink(const char *name, char *addr, T_FFS_SIZE size);
373
374 T_FFS_RET ffs_stat(const char *name, T_FFS_STAT *stat);
375 T_FFS_RET ffs_linkstat(const char *name, T_FFS_STAT *stat);
376 T_FFS_RET ffs_lstat(const char *name, T_FFS_STAT *stat);
377 T_FFS_RET ffs_xlstat(const char *name, T_FFS_XSTAT *stat);
378 T_FFS_RET ffs_fstat(T_FFS_FD fdi, T_FFS_STAT *stat);
379
380 T_FFS_RET ffs_remove(const char *name);
381 T_FFS_RET ffs_fcontrol(const char *pathname, INT8 action, int param);
382
383
384 T_FFS_RET ffs_rename(const char *oldname, const char *newname);
385
386 T_FFS_RET ffs_query(INT8 query, void *p);
387
388 T_FFS_RET ffs_preformat(UINT16 magic);
389 T_FFS_RET ffs_format(const char *name, UINT16 magic);
390
391 T_FFS_FD ffs_open(const char *name, T_FFS_OPEN_FLAGS option);
392 T_FFS_RET ffs_close(T_FFS_FD fdi);
393 T_FFS_SIZE ffs_write(T_FFS_FD fdi, void *src, T_FFS_SIZE amount);
394 T_FFS_SIZE ffs_seek(T_FFS_FD fdi, T_FFS_SIZE offset, T_FFS_WHENCE whence);
395 T_FFS_SIZE ffs_read(T_FFS_FD fdi, void *src, T_FFS_SIZE size);
396
397 T_FFS_RET ffs_truncate(const char *path, T_FFS_OFFSET length);
398
399 T_FFS_RET ffs_ftruncate(T_FFS_FD fdi, T_FFS_OFFSET length);
400
401 T_FFS_RET ffs_fdatasync(T_FFS_FD fdi);
402
403 // This function is to be implemented by user. It is defined in cfgffs.c.
404 extern T_FFS_RET ffs_is_modifiable(const char *name);
405
406 #endif //_FFS_H_