comparison g23m-glue/gdi/ffs_coat.c @ 0:75a11d740a02

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