FreeCalypso > hg > tcs211-l1-reconst
comparison g23m/condat/com/src/driver/ffs_coat.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Modul : ffs_coat | |
4 +----------------------------------------------------------------------------- | |
5 | Copyright 2002 Texas Instruments Berlin, AG | |
6 | All rights reserved. | |
7 | | |
8 | This file is confidential and a trade secret of Texas | |
9 | Instruments Berlin, AG | |
10 | The receipt of or possession of this file does not convey | |
11 | any rights to reproduce or disclose its contents or to | |
12 | manufacture, use, or sell anything it may describe, in | |
13 | whole, or in part, without the specific written consent of | |
14 | Texas Instruments Berlin, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose : Encapsulate the FFS API. | |
17 +----------------------------------------------------------------------------- | |
18 */ | |
19 | |
20 #ifndef __FFS_COAT_C__ | |
21 #define __FFS_COAT_C__ | |
22 | |
23 /*==== INCLUDES ===================================================*/ | |
24 #define SAP_ACI | |
25 | |
26 #include "typedefs.h" | |
27 #include "pconst.cdg" | |
28 #include "prim.h" | |
29 #include "vsi.h" | |
30 #include "ffs/ffs.h" | |
31 #include "ffs_coat.h" | |
32 | |
33 | |
34 /*==== CONSTANTS ==================================================*/ | |
35 | |
36 /*==== TYPES ======================================================*/ | |
37 | |
38 /*==== CONSTANTS ==================================================*/ | |
39 //#define FFS_STATE_CHECK | |
40 #define FFS_PAR_CHECK | |
41 #define FFS_ERR_CHECK | |
42 | |
43 /*==== EXTERNALS ==================================================*/ | |
44 | |
45 /*==== VARIABLES ==================================================*/ | |
46 | |
47 /*==== MACROS =====================================================*/ | |
48 #if defined(FFS_STATE_CHECK) | |
49 #define _STATE_CHECK(ffs_ret)\ | |
50 {ffs_ret=_FFS_StateCheck (_FFS_FCT_NAME,hMMI,file,line);\ | |
51 if (ffs_ret NEQ EFFS_OK)return ffs_ret;} | |
52 #else /* FFS_PAR_CHECK */ | |
53 #define _STATE_CHECK(ffs_ret) | |
54 #endif /* FFS_PAR_CHECK */ | |
55 | |
56 #if defined(FFS_PAR_CHECK) | |
57 #define _PAR_CHECK_NULL(parname,parnumber,ret)\ | |
58 if (!parname){\ | |
59 _FFS_ParCheck ("NULL", _FFS_FCT_NAME, parnumber, hMMI,file, line);\ | |
60 return ret;} | |
61 | |
62 #define _PAR_CHECK_LESSZERO(parname,parnumber,ret)\ | |
63 if (parname < 0){\ | |
64 _FFS_ParCheck ("<0", _FFS_FCT_NAME, parnumber, hMMI,file, line);\ | |
65 return ret;} | |
66 #else /* FFS_PAR_CHECK */ | |
67 #define _PAR_CHECK_NULL(parname,parnumber,ret) | |
68 #define _PAR_CHECK_LESSZERO(parname,parnumber,ret) | |
69 #endif /* FFS_PAR_CHECK */ | |
70 | |
71 | |
72 #if defined(FFS_ERR_CHECK) | |
73 #define _ERROR_CHECK(ffs_ret)\ | |
74 if (ffs_ret < 0)_FFS_ErrorMsg(NULL, _FFS_FCT_NAME, ffs_ret, hMMI,file, line) | |
75 #else /* FFS_ERR_CHECK */ | |
76 #define _ERROR_CHECK(ffs_ret) | |
77 #endif /* FFS_ERR_CHECK */ | |
78 | |
79 /*==== FUNCTIONS ==================================================*/ | |
80 #if defined(FFS_COAT_ENABLED) | |
81 static void _FFS_ParCheck (const char * const errmsg, const char * const fct, | |
82 int parameter, | |
83 T_HANDLE hMMI, const char * const file, int line); | |
84 | |
85 static void _FFS_ErrorMsg (const char * const errmsg, const char * const fct, | |
86 int ffs_ret, | |
87 T_HANDLE hMMI, const char * const file, int line); | |
88 | |
89 /* FFS functions whose positive return value has a meaning */ | |
90 T_FFS_FD _FFS_open(const char *name, T_FFS_OPEN_FLAGS option, | |
91 T_HANDLE hMMI, const char * const file, int line) | |
92 { | |
93 #define _FFS_FCT_NAME "ffs_open" | |
94 T_FFS_FD ffs_ret; | |
95 | |
96 _STATE_CHECK (ffs_ret); | |
97 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
98 | |
99 ffs_ret = ffs_open (name, option); | |
100 _ERROR_CHECK (ffs_ret); | |
101 | |
102 return ffs_ret; | |
103 #undef _FFS_FCT_NAME | |
104 } | |
105 | |
106 T_FFS_SIZE _FFS_write(T_FFS_FD fdi, void *src, T_FFS_SIZE amount, | |
107 T_HANDLE hMMI, const char * const file, int line) | |
108 { | |
109 #define _FFS_FCT_NAME "ffs_write" | |
110 T_FFS_SIZE ffs_ret; | |
111 | |
112 _STATE_CHECK (ffs_ret); | |
113 _PAR_CHECK_NULL (src, 2, EFFS_BADOP); | |
114 | |
115 ffs_ret = ffs_write (fdi, src, amount); | |
116 _ERROR_CHECK (ffs_ret); | |
117 | |
118 return ffs_ret; | |
119 #undef _FFS_FCT_NAME | |
120 } | |
121 | |
122 | |
123 T_FFS_SIZE _FFS_read(T_FFS_FD fdi, void *src, T_FFS_SIZE size, | |
124 T_HANDLE hMMI, const char * const file, int line) | |
125 { | |
126 #define _FFS_FCT_NAME "ffs_read" | |
127 T_FFS_SIZE ffs_ret; | |
128 | |
129 _STATE_CHECK (ffs_ret); | |
130 _PAR_CHECK_NULL (src, 2, EFFS_BADOP); | |
131 | |
132 ffs_ret = ffs_read (fdi, src, size); | |
133 _ERROR_CHECK (ffs_ret); | |
134 | |
135 return ffs_ret; | |
136 #undef _FFS_FCT_NAME | |
137 } | |
138 | |
139 | |
140 T_FFS_SIZE _FFS_seek(T_FFS_FD fdi, T_FFS_SIZE offset, T_FFS_WHENCE whence, | |
141 T_HANDLE hMMI, const char * const file, int line) | |
142 { | |
143 #define _FFS_FCT_NAME "ffs_seek" | |
144 T_FFS_SIZE ffs_ret; | |
145 | |
146 _STATE_CHECK (ffs_ret); | |
147 _PAR_CHECK_LESSZERO (offset, 2, EFFS_BADOP); | |
148 | |
149 ffs_ret = ffs_seek (fdi, offset, whence); | |
150 _ERROR_CHECK (ffs_ret); | |
151 | |
152 return ffs_ret; | |
153 #undef _FFS_FCT_NAME | |
154 } | |
155 | |
156 | |
157 T_FFS_SIZE _FFS_opendir(const char *name, T_FFS_DIR *dir, | |
158 T_HANDLE hMMI, const char * const file, int line) | |
159 { | |
160 #define _FFS_FCT_NAME "ffs_opendir" | |
161 T_FFS_SIZE ffs_ret; | |
162 | |
163 _STATE_CHECK (ffs_ret); | |
164 _PAR_CHECK_NULL (name, 1, EFFS_NOTADIR); | |
165 _PAR_CHECK_NULL (dir, 2, EFFS_NOTADIR); | |
166 | |
167 ffs_ret = ffs_opendir (name, dir); | |
168 _ERROR_CHECK (ffs_ret); | |
169 | |
170 return ffs_ret; | |
171 #undef _FFS_FCT_NAME | |
172 } | |
173 | |
174 | |
175 T_FFS_SIZE _FFS_readdir (T_FFS_DIR *dir, char *name, T_FFS_SIZE size, | |
176 T_HANDLE hMMI, const char * const file, int line) | |
177 { | |
178 #define _FFS_FCT_NAME "ffs_readdir" | |
179 T_FFS_SIZE ffs_ret; | |
180 | |
181 _STATE_CHECK (ffs_ret); | |
182 _PAR_CHECK_NULL (dir, 1, EFFS_NOTADIR); | |
183 _PAR_CHECK_NULL (name, 2, EFFS_NOTADIR); | |
184 _PAR_CHECK_LESSZERO (size, 3, EFFS_NOTADIR); | |
185 | |
186 ffs_ret = ffs_readdir (dir, name, size); | |
187 _ERROR_CHECK (ffs_ret); | |
188 | |
189 return ffs_ret; | |
190 #undef _FFS_FCT_NAME | |
191 } | |
192 | |
193 | |
194 T_FFS_SIZE _FFS_readlink(const char *name, char *addr, T_FFS_SIZE size, | |
195 T_HANDLE hMMI, const char * const file, int line) | |
196 { | |
197 #define _FFS_FCT_NAME "ffs_readlink" | |
198 T_FFS_SIZE ffs_ret; | |
199 | |
200 _STATE_CHECK (ffs_ret); | |
201 _PAR_CHECK_NULL (name, 1, EFFS_NOTAFILE); | |
202 _PAR_CHECK_NULL (addr, 2, EFFS_NOTAFILE); | |
203 _PAR_CHECK_LESSZERO (size, 3, EFFS_FILETOOBIG); | |
204 | |
205 ffs_ret = ffs_readlink (name, addr, size); | |
206 _ERROR_CHECK (ffs_ret); | |
207 | |
208 return ffs_ret; | |
209 #undef _FFS_FCT_NAME | |
210 } | |
211 | |
212 | |
213 T_FFS_SIZE _FFS_file_read(const char *name, void *addr, T_FFS_SIZE size, | |
214 T_HANDLE hMMI, const char * const file, int line) | |
215 { | |
216 #define _FFS_FCT_NAME "ffs_file_read" | |
217 T_FFS_SIZE ffs_ret; | |
218 | |
219 _STATE_CHECK (ffs_ret); | |
220 _PAR_CHECK_NULL (name, 1, EFFS_NOTAFILE); | |
221 _PAR_CHECK_NULL (addr, 2, EFFS_NOTAFILE); | |
222 _PAR_CHECK_LESSZERO (size, 3, EFFS_FILETOOBIG); | |
223 | |
224 ffs_ret = ffs_file_read (name, addr, size); | |
225 _ERROR_CHECK (ffs_ret); | |
226 | |
227 return ffs_ret; | |
228 #undef _FFS_FCT_NAME | |
229 } | |
230 | |
231 | |
232 T_FFS_SIZE _FFS_fread(const char *name, void *addr, T_FFS_SIZE size, | |
233 T_HANDLE hMMI, const char * const file, int line) | |
234 { | |
235 #define _FFS_FCT_NAME "ffs_fread" | |
236 T_FFS_SIZE ffs_ret; | |
237 | |
238 _STATE_CHECK (ffs_ret); | |
239 _PAR_CHECK_NULL (name, 1, EFFS_NOTAFILE); | |
240 _PAR_CHECK_NULL (addr, 2, EFFS_NOTAFILE); | |
241 _PAR_CHECK_LESSZERO (size, 3, EFFS_FILETOOBIG); | |
242 | |
243 /* ffs_fread is deprecated, use ffs_file_read instead */ | |
244 ffs_ret = ffs_file_read (name, addr, size); | |
245 _ERROR_CHECK (ffs_ret); | |
246 | |
247 return ffs_ret; | |
248 #undef _FFS_FCT_NAME | |
249 } | |
250 | |
251 | |
252 | |
253 /* FFS functions which return a value EFFS_OK if OK */ | |
254 T_FFS_RET _FFS_preformat(UINT16 magic, | |
255 T_HANDLE hMMI, const char * const file, int line) | |
256 { | |
257 #define _FFS_FCT_NAME "ffs_preformat" | |
258 T_FFS_SIZE ffs_ret; | |
259 | |
260 ffs_ret = ffs_preformat (magic); | |
261 _ERROR_CHECK (ffs_ret); | |
262 | |
263 return ffs_ret; | |
264 #undef _FFS_FCT_NAME | |
265 } | |
266 | |
267 | |
268 T_FFS_RET _FFS_format(const char *name, UINT16 magic, | |
269 T_HANDLE hMMI, const char * const file, int line) | |
270 { | |
271 #define _FFS_FCT_NAME "ffs_format" | |
272 T_FFS_SIZE ffs_ret; | |
273 | |
274 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
275 | |
276 ffs_ret = ffs_format (name, magic); | |
277 _ERROR_CHECK (ffs_ret); | |
278 | |
279 return ffs_ret; | |
280 #undef _FFS_FCT_NAME | |
281 } | |
282 | |
283 | |
284 T_FFS_RET _FFS_close(T_FFS_FD fdi, | |
285 T_HANDLE hMMI, const char * const file, int line) | |
286 { | |
287 #define _FFS_FCT_NAME "ffs_close" | |
288 T_FFS_SIZE ffs_ret; | |
289 | |
290 _STATE_CHECK (ffs_ret); | |
291 | |
292 ffs_ret = ffs_close (fdi); | |
293 _ERROR_CHECK (ffs_ret); | |
294 | |
295 return ffs_ret; | |
296 #undef _FFS_FCT_NAME | |
297 } | |
298 | |
299 | |
300 T_FFS_RET _FFS_truncate(const char *path, T_FFS_OFFSET length, | |
301 T_HANDLE hMMI, const char * const file, int line) | |
302 { | |
303 #define _FFS_FCT_NAME "ffs_truncate" | |
304 T_FFS_SIZE ffs_ret; | |
305 | |
306 _STATE_CHECK (ffs_ret); | |
307 _PAR_CHECK_NULL (path, 1, EFFS_NOTFOUND); | |
308 _PAR_CHECK_LESSZERO (length, 2, EFFS_NOTFOUND); | |
309 | |
310 ffs_ret = ffs_truncate (path, length); | |
311 _ERROR_CHECK (ffs_ret); | |
312 | |
313 return ffs_ret; | |
314 #undef _FFS_FCT_NAME | |
315 } | |
316 | |
317 | |
318 T_FFS_RET _FFS_ftruncate(T_FFS_FD fdi, T_FFS_OFFSET length, | |
319 T_HANDLE hMMI, const char * const file, int line) | |
320 { | |
321 #define _FFS_FCT_NAME "ffs_ftruncate" | |
322 T_FFS_SIZE ffs_ret; | |
323 | |
324 _STATE_CHECK (ffs_ret); | |
325 _PAR_CHECK_NULL (fdi, 1, EFFS_BADFD); | |
326 _PAR_CHECK_LESSZERO (length, 2, EFFS_NOTFOUND); | |
327 | |
328 ffs_ret = ffs_ftruncate (fdi, length); | |
329 _ERROR_CHECK (ffs_ret); | |
330 | |
331 return ffs_ret; | |
332 #undef _FFS_FCT_NAME | |
333 } | |
334 | |
335 | |
336 T_FFS_RET _FFS_fdatasync(T_FFS_FD fdi, | |
337 T_HANDLE hMMI, const char * const file, int line) | |
338 { | |
339 #define _FFS_FCT_NAME "ffs_fdatasync" | |
340 T_FFS_SIZE ffs_ret; | |
341 | |
342 _STATE_CHECK (ffs_ret); | |
343 _PAR_CHECK_NULL (fdi, 1, EFFS_BADFD); | |
344 | |
345 ffs_ret = ffs_fdatasync (fdi); | |
346 _ERROR_CHECK (ffs_ret); | |
347 | |
348 return ffs_ret; | |
349 #undef _FFS_FCT_NAME | |
350 } | |
351 | |
352 | |
353 T_FFS_RET _FFS_stat(const char *name, T_FFS_STAT *stat, | |
354 T_HANDLE hMMI, const char * const file, int line) | |
355 { | |
356 #define _FFS_FCT_NAME "ffs_stat" | |
357 T_FFS_SIZE ffs_ret; | |
358 | |
359 _STATE_CHECK (ffs_ret); | |
360 _PAR_CHECK_NULL (name, 1, EFFS_NOTFOUND); | |
361 _PAR_CHECK_NULL (stat, 2, EFFS_NOTFOUND); | |
362 | |
363 ffs_ret = ffs_stat (name, stat); | |
364 _ERROR_CHECK (ffs_ret); | |
365 | |
366 return ffs_ret; | |
367 #undef _FFS_FCT_NAME | |
368 } | |
369 | |
370 | |
371 T_FFS_RET _FFS_fstat(T_FFS_FD fdi, T_FFS_STAT *stat, | |
372 T_HANDLE hMMI, const char * const file, int line) | |
373 { | |
374 #define _FFS_FCT_NAME "ffs_fstat" | |
375 T_FFS_SIZE ffs_ret; | |
376 | |
377 _STATE_CHECK (ffs_ret); | |
378 _PAR_CHECK_NULL (fdi, 1, EFFS_BADFD); | |
379 _PAR_CHECK_NULL (stat, 2, EFFS_NOTFOUND); | |
380 | |
381 ffs_ret = ffs_fstat (fdi, stat); | |
382 _ERROR_CHECK (ffs_ret); | |
383 | |
384 return ffs_ret; | |
385 #undef _FFS_FCT_NAME | |
386 } | |
387 | |
388 | |
389 T_FFS_RET _FFS_lstat(const char *name, T_FFS_STAT *stat, | |
390 T_HANDLE hMMI, const char * const file, int line) | |
391 { | |
392 #define _FFS_FCT_NAME "ffs_lstat" | |
393 T_FFS_SIZE ffs_ret; | |
394 | |
395 _STATE_CHECK (ffs_ret); | |
396 _PAR_CHECK_NULL (name, 1, EFFS_NOTFOUND); | |
397 _PAR_CHECK_NULL (stat, 2, EFFS_NOTFOUND); | |
398 | |
399 ffs_ret = ffs_lstat (name, stat); | |
400 _ERROR_CHECK (ffs_ret); | |
401 | |
402 return ffs_ret; | |
403 #undef _FFS_FCT_NAME | |
404 } | |
405 | |
406 | |
407 T_FFS_RET _FFS_xlstat(const char *name, T_FFS_XSTAT *stat, | |
408 T_HANDLE hMMI, const char * const file, int line) | |
409 { | |
410 #define _FFS_FCT_NAME "ffs_xlstat" | |
411 T_FFS_SIZE ffs_ret; | |
412 | |
413 _STATE_CHECK (ffs_ret); | |
414 _PAR_CHECK_NULL (name, 1, EFFS_NOTFOUND); | |
415 _PAR_CHECK_NULL (stat, 2, EFFS_NOTFOUND); | |
416 | |
417 ffs_ret = ffs_xlstat (name, stat); | |
418 _ERROR_CHECK (ffs_ret); | |
419 | |
420 return ffs_ret; | |
421 #undef _FFS_FCT_NAME | |
422 } | |
423 | |
424 | |
425 T_FFS_RET _FFS_linkstat(const char *name, T_FFS_STAT *stat, | |
426 T_HANDLE hMMI, const char * const file, int line) | |
427 { | |
428 #define _FFS_FCT_NAME "ffs_linkstat" | |
429 T_FFS_SIZE ffs_ret; | |
430 | |
431 _STATE_CHECK (ffs_ret); | |
432 _PAR_CHECK_NULL (name, 1, EFFS_NOTFOUND); | |
433 _PAR_CHECK_NULL (stat, 2, EFFS_NOTFOUND); | |
434 | |
435 /* ffs_linkstat is deprecated, use ffs_lstat instead */ | |
436 ffs_ret = ffs_lstat (name, stat); | |
437 _ERROR_CHECK (ffs_ret); | |
438 | |
439 return ffs_ret; | |
440 #undef _FFS_FCT_NAME | |
441 } | |
442 | |
443 | |
444 T_FFS_RET _FFS_remove(const char *name, | |
445 T_HANDLE hMMI, const char * const file, int line) | |
446 { | |
447 #define _FFS_FCT_NAME "ffs_remove" | |
448 T_FFS_SIZE ffs_ret; | |
449 | |
450 _STATE_CHECK (ffs_ret); | |
451 _PAR_CHECK_NULL (name, 1, EFFS_NOTFOUND); | |
452 | |
453 ffs_ret = ffs_remove (name); | |
454 _ERROR_CHECK (ffs_ret); | |
455 | |
456 return ffs_ret; | |
457 #undef _FFS_FCT_NAME | |
458 } | |
459 | |
460 | |
461 T_FFS_RET _FFS_mkdir(const char *name, | |
462 T_HANDLE hMMI, const char * const file, int line) | |
463 { | |
464 #define _FFS_FCT_NAME "ffs_mkdir" | |
465 T_FFS_SIZE ffs_ret; | |
466 | |
467 _STATE_CHECK (ffs_ret); | |
468 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
469 | |
470 ffs_ret = ffs_mkdir (name); | |
471 _ERROR_CHECK (ffs_ret); | |
472 | |
473 return ffs_ret; | |
474 #undef _FFS_FCT_NAME | |
475 } | |
476 | |
477 | |
478 T_FFS_RET _FFS_symlink(const char *name, const char *actualpath, | |
479 T_HANDLE hMMI, const char * const file, int line) | |
480 { | |
481 #define _FFS_FCT_NAME "ffs_symlink" | |
482 T_FFS_SIZE ffs_ret; | |
483 | |
484 _STATE_CHECK (ffs_ret); | |
485 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
486 _PAR_CHECK_NULL (actualpath, 2, EFFS_BADNAME); | |
487 | |
488 ffs_ret = ffs_symlink (name, actualpath); | |
489 _ERROR_CHECK (ffs_ret); | |
490 | |
491 return ffs_ret; | |
492 #undef _FFS_FCT_NAME | |
493 } | |
494 | |
495 | |
496 T_FFS_RET _FFS_rename(const char *oldname, const char *newname, | |
497 T_HANDLE hMMI, const char * const file, int line) | |
498 { | |
499 #define _FFS_FCT_NAME "ffs_rename" | |
500 T_FFS_SIZE ffs_ret; | |
501 | |
502 _STATE_CHECK (ffs_ret); | |
503 _PAR_CHECK_NULL (oldname, 1, EFFS_BADNAME); | |
504 _PAR_CHECK_NULL (newname, 2, EFFS_BADNAME); | |
505 | |
506 ffs_ret = ffs_rename (oldname, newname); | |
507 _ERROR_CHECK (ffs_ret); | |
508 | |
509 return ffs_ret; | |
510 #undef _FFS_FCT_NAME | |
511 } | |
512 | |
513 | |
514 T_FFS_RET _FFS_file_write(const char *name, void *addr, T_FFS_SIZE size, | |
515 T_FFS_OPEN_FLAGS flags, | |
516 T_HANDLE hMMI, const char * const file, int line) | |
517 { | |
518 #define _FFS_FCT_NAME "ffs_file_write" | |
519 T_FFS_SIZE ffs_ret; | |
520 | |
521 _STATE_CHECK (ffs_ret); | |
522 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
523 _PAR_CHECK_NULL (addr, 2, EFFS_NOTAFILE); | |
524 _PAR_CHECK_LESSZERO (size, 2, EFFS_FILETOOBIG); | |
525 | |
526 ffs_ret = ffs_file_write (name, addr, size, flags); | |
527 _ERROR_CHECK (ffs_ret); | |
528 | |
529 return ffs_ret; | |
530 #undef _FFS_FCT_NAME | |
531 } | |
532 | |
533 | |
534 T_FFS_RET _FFS_fcreate(const char *name, void *addr, T_FFS_SIZE size, | |
535 T_HANDLE hMMI, const char * const file, int line) | |
536 { | |
537 #define _FFS_FCT_NAME "ffs_fcreate" | |
538 T_FFS_SIZE ffs_ret; | |
539 | |
540 _STATE_CHECK (ffs_ret); | |
541 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
542 _PAR_CHECK_NULL (addr, 2, EFFS_NOTAFILE); | |
543 _PAR_CHECK_LESSZERO (size, 2, EFFS_FILETOOBIG); | |
544 | |
545 /* ffs_fcreate is deprecated, use ffs_file_write instead */ | |
546 ffs_ret = ffs_file_write (name, addr, size, FFS_O_CREATE|FFS_O_EXCL); | |
547 _ERROR_CHECK (ffs_ret); | |
548 | |
549 return ffs_ret; | |
550 #undef _FFS_FCT_NAME | |
551 } | |
552 | |
553 | |
554 T_FFS_RET _FFS_fupdate(const char *name, void *addr, T_FFS_SIZE size, | |
555 T_HANDLE hMMI, const char * const file, int line) | |
556 { | |
557 #define _FFS_FCT_NAME "ffs_fupdate" | |
558 T_FFS_SIZE ffs_ret; | |
559 | |
560 _STATE_CHECK (ffs_ret); | |
561 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
562 _PAR_CHECK_NULL (addr, 2, EFFS_NOTAFILE); | |
563 _PAR_CHECK_LESSZERO (size, 2, EFFS_FILETOOBIG); | |
564 | |
565 /* ffs_fupdate is deprecated, use ffs_file_write instead */ | |
566 ffs_ret = ffs_file_write (name, addr, size, FFS_O_TRUNC); | |
567 _ERROR_CHECK (ffs_ret); | |
568 | |
569 return ffs_ret; | |
570 #undef _FFS_FCT_NAME | |
571 } | |
572 | |
573 | |
574 T_FFS_RET _FFS_fwrite(const char *name, void *addr, T_FFS_SIZE size, | |
575 T_HANDLE hMMI, const char * const file, int line) | |
576 { | |
577 #define _FFS_FCT_NAME "ffs_fwrite" | |
578 T_FFS_SIZE ffs_ret; | |
579 | |
580 _STATE_CHECK (ffs_ret); | |
581 _PAR_CHECK_NULL (name, 1, EFFS_BADNAME); | |
582 _PAR_CHECK_NULL (addr, 2, EFFS_NOTAFILE); | |
583 _PAR_CHECK_LESSZERO (size, 2, EFFS_FILETOOBIG); | |
584 | |
585 /* ffs_fwrite is deprecated, use ffs_file_write instead */ | |
586 ffs_ret = ffs_file_write (name, addr, size, FFS_O_CREATE|FFS_O_TRUNC); | |
587 _ERROR_CHECK (ffs_ret); | |
588 | |
589 return ffs_ret; | |
590 #undef _FFS_FCT_NAME | |
591 } | |
592 | |
593 | |
594 T_FFS_RET _FFS_fcontrol(const char *pathname, INT8 action, int param, | |
595 T_HANDLE hMMI, const char * const file, int line) | |
596 { | |
597 #define _FFS_FCT_NAME "ffs_fcontrol" | |
598 T_FFS_SIZE ffs_ret; | |
599 | |
600 _STATE_CHECK (ffs_ret); | |
601 _PAR_CHECK_NULL (pathname, 1, EFFS_BADNAME); | |
602 | |
603 ffs_ret = ffs_fcontrol (pathname, action, param); | |
604 _ERROR_CHECK (ffs_ret); | |
605 | |
606 return ffs_ret; | |
607 #undef _FFS_FCT_NAME | |
608 } | |
609 | |
610 | |
611 T_FFS_RET _FFS_query(INT8 query, void *p, | |
612 T_HANDLE hMMI, const char * const file, int line) | |
613 { | |
614 #define _FFS_FCT_NAME "ffs_query" | |
615 T_FFS_SIZE ffs_ret; | |
616 | |
617 _PAR_CHECK_NULL (p, 2, EFFS_BADNAME); | |
618 | |
619 ffs_ret = ffs_query (query, p); | |
620 _ERROR_CHECK (ffs_ret); | |
621 | |
622 return ffs_ret; | |
623 #undef _FFS_FCT_NAME | |
624 } | |
625 | |
626 #if defined(FFS_PAR_CHECK) | |
627 static void _FFS_ParCheck (const char * const errmsg, const char * const fct, | |
628 int parameter, | |
629 T_HANDLE hMMI, const char * const file, int line) | |
630 { | |
631 char *f; | |
632 int l; | |
633 | |
634 l = strlen (file); | |
635 if (l <= 20) | |
636 f = (char *)file; | |
637 else | |
638 f = (char *)file + l - 20; | |
639 | |
640 TRACE_EVENT_P5 ("FFS PAR ERR:par %u of %s is %s (%s#%u)", | |
641 parameter, | |
642 fct ? fct : "", | |
643 errmsg ? errmsg : "", | |
644 f, | |
645 line); | |
646 } | |
647 #endif /* FFS_PAR_CHECK */ | |
648 | |
649 char *ffs_strerror(effs_t error) | |
650 { | |
651 switch (error) { | |
652 case EFFS_OK: return "ok"; /* 0 */ | |
653 case EFFS_NODEVICE: return "flash device unknown"; /* -1 */ | |
654 case EFFS_CORRUPTED: return "filesystem corrupted!?"; /* -2 */ | |
655 case EFFS_NOPREFORMAT: return "ffs not preformatted"; /* -3 */ | |
656 case EFFS_NOFORMAT: return "ffs not formatted"; /* -4 */ | |
657 case EFFS_BADFORMAT: return "incompatible ffs version"; /* -5 */ | |
658 case EFFS_MAGIC: return "bad magic"; /* -6 */ | |
659 case EFFS_AGAIN: return "not ready, try again later"; /* -7 */ | |
660 case EFFS_NOSYS: return "function not implemented"; /* -8 */ | |
661 case EFFS_DRIVER: return "ffs device driver error"; /* -9 */ | |
662 case EFFS_NOSPACE: return "out of data space"; /* -10 */ | |
663 case EFFS_FSFULL: return "file system full, no free inodes"; /* -11 */ | |
664 case EFFS_BADNAME: return "bad filename"; /* -12 */ | |
665 case EFFS_NOTFOUND: return "object not found"; /* -13 */ | |
666 case EFFS_EXISTS: return "object exists"; /* -14 */ | |
667 case EFFS_ACCESS: return "access permission violation"; /* -15 */ | |
668 case EFFS_NAMETOOLONG: return "filename too long"; /* -16 */ | |
669 case EFFS_INVALID: return "invalid argument"; /* -17 */ | |
670 case EFFS_DIRNOTEMPTY: return "directory not empty"; /* -18 */ | |
671 case EFFS_NOTADIR: return "object is not a directory"; /* -19 */ | |
672 case EFFS_SPARE: return "SPARE"; /* -20 */ | |
673 case EFFS_FILETOOBIG: return "file too big"; /* -21 */ | |
674 case EFFS_NOTAFILE: return "object is not a file"; /* -22 */ | |
675 case EFFS_PATHTOODEEP: return "path too deep"; /* -23 */ | |
676 case EFFS_NUMFD: return "Max number of open files reached"; /* -24 */ | |
677 case EFFS_BADFD: return "Bad file descriptor"; /* -25 */ | |
678 case EFFS_BADOP: return "Bad operation"; /* -26 */ | |
679 case EFFS_LOCKED: return "The file is locked"; /* -27 */ | |
680 case EFFS_TOOBIG: return "too big (tmffs buffer overflow)"; /* -30 */ | |
681 case EFFS_MEMORY: return "out of memory"; /* -31 */ | |
682 case EFFS_MSGSEND: return "message send failed"; /* -32 */ | |
683 case EFFS_SIBLINGLOOP: return "directory sibling loop"; /* -40 */ | |
684 case EFFS_NOBLOCKS: return "No more blocks!?"; /* -41 */ | |
685 default: return "unknown ffs error code!"; | |
686 } | |
687 } | |
688 | |
689 static void _FFS_ErrorMsg (const char * const errmsg, const char * const fct, | |
690 int ffs_ret, | |
691 T_HANDLE hMMI, const char * const file, int line) | |
692 { | |
693 char *f; | |
694 int l; | |
695 | |
696 l = strlen (file); | |
697 if (l <= 20) | |
698 f = (char *)file; | |
699 else | |
700 f = (char *)file + l - 20; | |
701 | |
702 TRACE_EVENT_P5 ("FFS ERR on %s: %d %s (%s#%u)", | |
703 fct ? fct : "", | |
704 ffs_ret, | |
705 ffs_strerror (ffs_ret), | |
706 f, | |
707 line); | |
708 } | |
709 | |
710 #endif /* FFS_COAT_ENABLED */ | |
711 | |
712 #if 1 | |
713 GLOBAL T_FFS_RET _FFS_StateCheck (const char * const fct, | |
714 T_HANDLE hMMI, const char * const file, int line) | |
715 { | |
716 int query_result; | |
717 int bytes_free, bytes_used, bytes_max, bytes_lost; | |
718 T_FFS_RET ffs_ret; | |
719 | |
720 SYST_TRACE ("_FFS_StateCheck()"); | |
721 | |
722 bytes_free = bytes_used = bytes_max = bytes_lost = 0; | |
723 | |
724 ffs_ret = ffs_query (Q_BYTES_FREE, &query_result); | |
725 if (ffs_ret EQ EFFS_OK) | |
726 { | |
727 bytes_free = query_result; | |
728 ffs_ret = ffs_query (Q_BYTES_USED, &query_result); | |
729 if (ffs_ret EQ EFFS_OK) | |
730 { | |
731 bytes_used = query_result; | |
732 ffs_ret = ffs_query (Q_BYTES_LOST, &query_result); | |
733 if (ffs_ret EQ EFFS_OK) | |
734 { | |
735 bytes_lost = query_result; | |
736 ffs_ret = ffs_query (Q_BYTES_MAX, &query_result); | |
737 if (ffs_ret EQ EFFS_OK) | |
738 { | |
739 bytes_max = query_result; | |
740 } | |
741 } | |
742 } | |
743 } | |
744 | |
745 #if 0 | |
746 { | |
747 char *f; | |
748 int l; | |
749 | |
750 PALLOC (trc_ind, ACI_TRC_IND); /* T_ACI_TRC_IND */ | |
751 trc_ind->cmd_src = 1; /* CMD_SRC_ATI_1 */ | |
752 | |
753 l = strlen (file); | |
754 if (l <= 20) | |
755 f = (char *)file; | |
756 else | |
757 f = (char *)file + l - 20; | |
758 | |
759 sprintf (trc_ind->trc_buf, "STATE before %s (%s#%u)", fct?fct:"", f, line); | |
760 trc_ind->trc_len = strlen (trc_ind->trc_buf); | |
761 | |
762 PSEND (hMMI, trc_ind); | |
763 } | |
764 #endif /* 0|1 */ | |
765 { | |
766 TRACE_EVENT_P4 ("FFS free=%5u used=%5u lost=%5u max=%6u", | |
767 bytes_free, | |
768 bytes_used, | |
769 bytes_lost, | |
770 bytes_max); | |
771 } | |
772 | |
773 return EFFS_OK; | |
774 } | |
775 #else /* 1|0 */ | |
776 GLOBAL T_FFS_RET _FFS_StateCheck (const char * const fct, | |
777 T_HANDLE hMMI, const char * const file, int line) | |
778 { | |
779 USHORT query_result; | |
780 int objects_free, objects_used, objects_max, objects_lost; | |
781 T_FFS_RET ffs_ret; | |
782 | |
783 SYST_TRACE ("_FFS_StateCheck()"); | |
784 | |
785 ffs_ret = ffs_query (Q_OBJECTS_FREE, &query_result); | |
786 if (ffs_ret NEQ EFFS_OK) | |
787 return ffs_ret; | |
788 else | |
789 objects_free = query_result; | |
790 | |
791 ffs_ret = ffs_query (Q_INODES_USED, &query_result); | |
792 if (ffs_ret NEQ EFFS_OK) | |
793 return ffs_ret; | |
794 else | |
795 objects_used = query_result; | |
796 | |
797 ffs_ret = ffs_query (Q_INODES_LOST, &query_result); | |
798 if (ffs_ret NEQ EFFS_OK) | |
799 return ffs_ret; | |
800 else | |
801 objects_lost = query_result; | |
802 | |
803 ffs_ret = ffs_query (Q_OBJECTS_MAX, &query_result); | |
804 if (ffs_ret NEQ EFFS_OK) | |
805 return ffs_ret; | |
806 else | |
807 objects_max = query_result; | |
808 | |
809 #if 0 | |
810 { | |
811 char *f; | |
812 int l; | |
813 | |
814 PALLOC (trc_ind, ACI_TRC_IND); /* T_ACI_TRC_IND */ | |
815 trc_ind->cmd_src = 1; /* CMD_SRC_ATI_1 */ | |
816 | |
817 l = strlen (file); | |
818 if (l <= 20) | |
819 f = (char *)file; | |
820 else | |
821 f = (char *)file + l - 20; | |
822 | |
823 sprintf (trc_ind->trc_buf, "STATE before %s (%s#%u)", fct?fct:"", f, line); | |
824 trc_ind->trc_len = strlen (trc_ind->trc_buf); | |
825 | |
826 PSEND (hMMI, trc_ind); | |
827 } | |
828 #endif /* 0|1 */ | |
829 { | |
830 PALLOC (trc_ind, ACI_TRC_IND); /* T_ACI_TRC_IND */ | |
831 trc_ind->cmd_src = 1; /* CMD_SRC_ATI_1 */ | |
832 | |
833 sprintf (trc_ind->trc_buf, "FFS objs: free=%3u used=%3u lost=%3u max=%3u", | |
834 objects_free, objects_used, objects_lost, objects_max); | |
835 trc_ind->trc_len = strlen (trc_ind->trc_buf); | |
836 | |
837 SYST_TRACE ((char *)trc_ind->trc_buf); | |
838 | |
839 PSEND (hMMI, trc_ind); | |
840 } | |
841 | |
842 return EFFS_OK; | |
843 } | |
844 #endif /* 1|0 */ | |
845 | |
846 #endif | |
847 |