comparison src/cs/drivers/drv_app/ffs/ffs.h @ 0:b6a5e36de839

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