-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfatfsWrapper.c
1087 lines (895 loc) · 24 KB
/
fatfsWrapper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file fatfsWrapper.c
* @author Matthias Blaicher
*
*/
#include "ff.h"
#include "ffconf.h"
#include "fatfsWrapperConfig.h"
/*
* Defines for which functions need to be included in the wrapper.
*/
#define HAS_MOUNT (FATFS_WRP_ENABLE_MOUNT)
#define HAS_OPEN (FATFS_WRP_ENABLE_OPEN)
#define HAS_READ (FATFS_WRP_ENABLE_READ)
#define HAS_CLOSE (FATFS_WRP_ENABLE_CLOSE)
#define HAS_WRITE (FATFS_WRP_ENABLE_WRITE && !_FS_READONLY)
#define HAS_SYNC (FATFS_WRP_ENABLE_SYNC && !_FS_READONLY)
#define HAS_CHDRIVE (FATFS_WRP_ENABLE_CHDRIVE && (_FS_RPATH >= 1))
#define HAS_CHDIR (FATFS_WRP_ENABLE_CHDIR && (_FS_RPATH >= 1))
#define HAS_GETCWD (FATFS_WRP_ENABLE_GETCWD && (_FS_RPATH >= 2))
#define HAS_LSEEK (FATFS_WRP_ENABLE_LSEEK && (_FS_MINIMIZE <= 2))
#define HAS_OPENDIR (FATFS_WRP_ENABLE_OPENDIR && (_FS_MINIMIZE <= 1))
#define HAS_READDIR (FATFS_WRP_ENABLE_READDIR && (_FS_MINIMIZE <= 1))
#define HAS_STAT (FATFS_WRP_ENABLE_STAT && (_FS_MINIMIZE == 0))
#define HAS_GETFREE (FATFS_WRP_ENABLE_GETFREE && (_FS_MINIMIZE == 0) && !_FS_READONLY)
#define HAS_TRUNCATE (FATFS_WRP_ENABLE_TRUNKATE && (_FS_MINIMIZE == 0) && !_FS_READONLY)
#define HAS_UNLINK (FATFS_WRP_ENABLE_UNLINK && (_FS_MINIMIZE == 0) && !_FS_READONLY)
#define HAS_MKDIR (FATFS_WRP_ENABLE_MKDIR && (_FS_MINIMIZE == 0) && !_FS_READONLY)
#define HAS_CHMOD (FATFS_WRP_ENABLE_CHMOD && (_FS_MINIMIZE == 0) && !_FS_READONLY)
#define HAS_UTIME (FATFS_WRP_ENABLE_UTIME && (_FS_MINIMIZE == 0) && !_FS_READONLY)
#define HAS_RENAME (FATFS_WRP_ENABLE_RENAME && (_FS_MINIMIZE == 0) && !_FS_READONLY)
#define HAS_FORWARD (FATFS_WRP_ENABLE_FORWARD && _USE_FORWARD && _FS_TINY)
#define HAS_MKFS (FATFS_WRP_ENABLE_MKFS && _USE_MKFS && !_FS_READONLY)
#define HAS_FDISK (FATFS_WRP_ENABLE_FDISK && _USE_MKFS && !_FS_READONLY && (_MULTI_PARTITION == 2))
#define HAS_GETS (FATFS_WRP_ENABLE_GETS && _USE_STRFUNC)
#define HAS_PUTC (FATFS_WRP_ENABLE_PUTC && _USE_STRFUNC && !_FS_READONLY)
#define HAS_PUTS (FATFS_WRP_ENABLE_PUTS && _USE_STRFUNC && !_FS_READONLY)
#define HAS_PRINTF (FATFS_WRP_ENABLE_PRINTF && _USE_STRFUNC && !_FS_READONLY)
/**
* @brief Enumeration of all possible actions depending on activated functions.
*/
enum wrapper_action {
eTERMINATE,
#if HAS_MOUNT
eFMOUNT,
#endif
#if HAS_OPEN
eFOPEN,
#endif
#if HAS_READ
eFREAD,
#endif
#if HAS_WRITE
eFWRITE,
#endif
#if HAS_SYNC
eFSYNC,
#endif
#if HAS_CHDRIVE
eFCHDRIVE,
#endif
#if HAS_CHDIR
eFCHDIR,
#endif
#if HAS_GETCWD
eFGETCWD,
#endif
#if HAS_LSEEK
eFLSEEK,
#endif
#if HAS_CLOSE
eFCLOSE,
#endif
#if HAS_OPENDIR
eFOPENDIR,
#endif
#if HAS_READDIR
eFREADDIR,
#endif
#if HAS_STAT
eFSTAT,
#endif
#if HAS_GETFREE
eFGETFREE,
#endif
#if HAS_TRUNCATE
eFTRUNCATE,
#endif
#if HAS_UNLINK
eFUNLINK,
#endif
#if HAS_MKDIR
eFMKDIR,
#endif
#if HAS_CHMOD
eFCHMOD,
#endif
#if HAS_UTIME
eFUTIME,
#endif
#if HAS_RENAME
eFRENAME,
#endif
#if HAS_MKFS
eFMKFS,
#endif
#if HAS_FDISK
eFFDISK,
#endif
#if HAS_GETS
eFGETS,
#endif
#if HAS_PUTC
eFPUTC,
#endif
#if HAS_PUTS
eFPUTS,
#endif
};
#define _wrapper_msg_base \
enum wrapper_action action; \
FRESULT result;
struct wrapper_msg_base {
_wrapper_msg_base
};
struct wrapper_msg_pFATFSpTCHARvBYTE {
_wrapper_msg_base
FATFS* fatfsp;
TCHAR* string;
BYTE byte;
};
struct wrapper_msg_vBYTEpFATFS {
_wrapper_msg_base
BYTE byte;
FATFS* fatfsp;
};
struct wrapper_msg_pFILpTCHARvBYTE {
_wrapper_msg_base
FIL* filep;
TCHAR* string;
BYTE byte;
};
struct wrapper_msg_pFILpVOIDvUINTpUINT {
_wrapper_msg_base
FIL* filep;
void* voidp;
UINT uint;
UINT* uintp;
};
struct wrapper_msg_pFILvDWORD {
_wrapper_msg_base
FIL* filep;
DWORD dword;
};
struct wrapper_msg_pFIL {
_wrapper_msg_base
FIL* filep;
};
struct wrapper_msg_pDIRpTCHAR {
_wrapper_msg_base
DIR* dirp;
TCHAR* string;
};
struct wrapper_msg_pDIRpFILINFO {
_wrapper_msg_base
DIR* dirp;
FILINFO* filinfop;
};
struct wrapper_msg_pTCHARpFILINFO {
_wrapper_msg_base
TCHAR* string;
FILINFO* filinfop;
};
struct wrapper_msg_pTCHARpDWORDppFATFS {
_wrapper_msg_base
TCHAR* string;
DWORD* dwordp;
FATFS** fatfspp;
};
struct wrapper_msg_pTCHAR {
_wrapper_msg_base
TCHAR* string;
};
struct wrapper_msg_pTCHARvBYTEvBYTE {
_wrapper_msg_base
TCHAR* string;
BYTE byte1;
BYTE byte2;
};
struct wrapper_msg_pTCHARpTCHAR {
_wrapper_msg_base
TCHAR* string1;
TCHAR* string2;
};
struct wrapper_msg_vBYTE {
_wrapper_msg_base
BYTE byte;
};
struct wrapper_msg_pTCHARvUINT {
_wrapper_msg_base
TCHAR* string;
UINT uint;
};
struct wrapper_msg_vBYTEvBYTEvUINT {
_wrapper_msg_base
BYTE byte1;
BYTE byte2;
UINT uint;
};
struct wrapper_msg_vBYTEpDWORDpVOID {
_wrapper_msg_base
BYTE byte;
DWORD* dwordp;
void* voidp;
};
struct wrapper_msg_vTCHARpFIL {
_wrapper_msg_base
TCHAR tchar;
FIL* filep;
};
struct wrapper_msg_pTCHARpFIL {
_wrapper_msg_base
TCHAR* string;
FIL* filep;
};
struct wrapper_msg_pTCHARvINTpFILpTCHAR {
_wrapper_msg_base
TCHAR* string;
int n;
FIL* filep;
TCHAR* string2;
};
/**
* @brief Pointer to worker thread for synchronous communication.
*/
static thread_t* workerThread = NULL;
static bool running = FALSE;
static THD_WORKING_AREA(waFatFSWorkerThread, FATFS_WRP_WORKER_SIZE);
static void ThreadFatFSWorker(void *arg) {
(void)arg;
running = TRUE;
thread_t* p;
chRegSetThreadName("fatfsWorker");
while (!chThdShouldTerminateX()) {
/* Wait for msg with work to do. */
p = chMsgWait();
struct wrapper_msg_base* msg = (struct wrapper_msg_base*) chMsgGet(p);
msg->result = FR_INVALID_PARAMETER;
switch(msg->action) {
case eTERMINATE: {
break;
}
#if HAS_MOUNT
case eFMOUNT: {
const struct wrapper_msg_pFATFSpTCHARvBYTE* exmsg = \
(const struct wrapper_msg_pFATFSpTCHARvBYTE*) msg;
msg->result = f_mount(exmsg->fatfsp, exmsg->string, exmsg->byte);
break;
}
#endif /* HAS_MOUNT */
#if HAS_OPEN
case eFOPEN: {
const struct wrapper_msg_pFILpTCHARvBYTE* exmsg = \
(const struct wrapper_msg_pFILpTCHARvBYTE*) msg;
msg->result = f_open(exmsg->filep, exmsg->string, exmsg->byte);
break;
}
#endif /* HAS_OPEN */
#if HAS_READ
case eFREAD: {
const struct wrapper_msg_pFILpVOIDvUINTpUINT* exmsg = \
(const struct wrapper_msg_pFILpVOIDvUINTpUINT*) msg;
msg->result = f_read(exmsg->filep, exmsg->voidp, exmsg->uint,
exmsg->uintp);
break;
}
#endif /* HAS_READ */
#if HAS_WRITE
case eFWRITE: {
const struct wrapper_msg_pFILpVOIDvUINTpUINT* exmsg = \
(const struct wrapper_msg_pFILpVOIDvUINTpUINT*) msg;
msg->result = f_write(exmsg->filep, exmsg->voidp, exmsg->uint,
exmsg->uintp);
break;
}
#endif /* HAD_WRITE */
#if HAS_SYNC
case eFSYNC: {
const struct wrapper_msg_pFIL* exmsg = \
(const struct wrapper_msg_pFIL*) msg;
msg->result = f_sync(exmsg->filep);
break;
}
#endif /* HAS_SYNC */
#if HAS_CHDRIVE
case eFCHDRIVE: {
const struct wrapper_msg_vBYTE* exmsg = \
(const struct wrapper_msg_vBYTE*) msg;
msg->result = f_chdrive(exmsg->byte);
break;
}
#endif
#if HAS_CHDIR
case eFCHDIR: {
const struct wrapper_msg_pTCHAR* exmsg = \
(const struct wrapper_msg_pTCHAR*) msg;
msg->result = f_chdir(exmsg->string);
break;
}
#endif /* HAS_CHDIR */
#if HAS_GETCWD
case eFGETCWD: {
const struct wrapper_msg_pTCHARvUINT* exmsg = \
(const struct wrapper_msg_pTCHARvUINT*) msg;
msg->result = f_getcwd(exmsg->string, exmsg->uint);
break;
}
#endif
#if HAS_LSEEK
case eFLSEEK: {
const struct wrapper_msg_pFILvDWORD* exmsg = \
(const struct wrapper_msg_pFILvDWORD*) msg;
msg->result = f_lseek(exmsg->filep, exmsg->dword);
break;
}
#endif /* HAS_LSEEK */
#if HAS_CLOSE
case eFCLOSE: {
const struct wrapper_msg_pFIL* exmsg = \
(const struct wrapper_msg_pFIL*) msg;
msg->result = f_close(exmsg->filep);
break;
}
#endif /* HAS_CLOSE */
#if HAS_OPENDIR
case eFOPENDIR: {
const struct wrapper_msg_pDIRpTCHAR* exmsg = \
(const struct wrapper_msg_pDIRpTCHAR*) msg;
msg->result = f_opendir(exmsg->dirp, exmsg->string);
break;
}
#endif /* HAD_OPENDIR */
#if HAS_READDIR
case eFREADDIR: {
const struct wrapper_msg_pDIRpFILINFO* exmsg = \
(const struct wrapper_msg_pDIRpFILINFO*) msg;
msg->result = f_readdir(exmsg->dirp, exmsg->filinfop);
break;
}
#endif /* HAS_READDIR */
#if HAS_STAT
case eFSTAT: {
const struct wrapper_msg_pTCHARpFILINFO* exmsg = \
(const struct wrapper_msg_pTCHARpFILINFO*) msg;
msg->result = f_stat(exmsg->string, exmsg->filinfop);
break;
}
#endif /* HAS_STAT */
#if HAS_GETFREE
case eFGETFREE: {
const struct wrapper_msg_pTCHARpDWORDppFATFS* exmsg = \
(const struct wrapper_msg_pTCHARpDWORDppFATFS*) msg;
msg->result = f_getfree(exmsg->string, exmsg->dwordp, exmsg->fatfspp);
break;
}
#endif /* HAS_GETFREE */
#if HAS_TRUNCATE
case eFTRUNCATE: {
const struct wrapper_msg_pFIL* exmsg = \
(const struct wrapper_msg_pFIL*) msg;
msg->result = f_truncate(exmsg->filep);
break;
}
#endif /* HAS_TRUNCATE */
#if HAS_UNLINK
case eFUNLINK: {
const struct wrapper_msg_pTCHAR* exmsg = \
(const struct wrapper_msg_pTCHAR*) msg;
msg->result = f_unlink(exmsg->string);
break;
}
#endif /* HAS_UNLINK */
#if HAS_MKDIR
case eFMKDIR: {
const struct wrapper_msg_pTCHAR* exmsg = \
(const struct wrapper_msg_pTCHAR*) msg;
msg->result = f_mkdir(exmsg->string);
break;
}
#endif /* HAS_MKDIR */
#if HAS_CHMOD
case eFCHMOD: {
const struct wrapper_msg_pTCHARvBYTEvBYTE* exmsg = \
(const struct wrapper_msg_pTCHARvBYTEvBYTE*) msg;
msg->result = f_chmod(exmsg->string, exmsg->byte1, exmsg->byte2);
break;
}
#endif /* HAS_CHMOD */
#if HAS_UTIME
case eFUTIME: {
const struct wrapper_msg_pTCHARpFILINFO* exmsg = \
(const struct wrapper_msg_pTCHARpFILINFO*) msg;
msg->result = f_utime(exmsg->string, exmsg->filinfop);
break;
}
#endif /* HAD_UTIME */
#if HAS_RENAME
case eFRENAME: {
const struct wrapper_msg_pTCHARpTCHAR* exmsg = \
(const struct wrapper_msg_pTCHARpTCHAR*) msg;
msg->result = f_rename(exmsg->string1, exmsg->string2);
break;
}
#endif /* HAS_RENAME */
#if HAS_MKFS
case eFMKFS: {
const struct wrapper_msg_vBYTEvBYTEvUINT* exmsg = \
(const struct wrapper_msg_vBYTEvBYTEvUINT*) msg;
msg->result = f_mkfs(exmsg->byte1, exmsg->byte2, exmsg->uint);
break;
}
#endif /* HAS_MKFS */
#if HAS_FDISK
case eFFDISK: {
const struct wrapper_msg_vBYTEpDWORDpVOID* exmsg = \
(const struct wrapper_msg_vBYTEpDWORDpVOID*) msg;
msg->result = f_fdisk(exmsg->byte, exmsg->dwordp, exmsg->voidp);
break;
}
#endif /* HAS_FDISK */
#if HAS_GETS
case eFGETS: {
struct wrapper_msg_pTCHARvINTpFILpTCHAR* exmsg = \
(struct wrapper_msg_pTCHARvINTpFILpTCHAR*) msg;
exmsg->string2 = f_gets(exmsg->string, exmsg->n, exmsg->filep);
break;
}
#endif /* HAS_GETS */
#if HAS_PUTC
case eFPUTC: {
const struct wrapper_msg_vTCHARpFIL* exmsg = \
(const struct wrapper_msg_vTCHARpFIL*) msg;
msg->result = f_putc(exmsg->tchar, exmsg->filep);
break;
}
#endif /* HAS_PUTC */
#if HAS_PUTS
case eFPUTS: {
const struct wrapper_msg_pTCHARpFIL* exmsg = \
(const struct wrapper_msg_pTCHARpFIL*) msg;
msg->result = f_puts(exmsg->string, exmsg->filep);
break;
}
#endif /* HAS_PUTS */
}
/* Done, release msg again. */
chMsgRelease(p, 0);
}
running = FALSE;
}
thread_t* wf_init (tprio_t priority) {
workerThread = chThdCreateStatic(waFatFSWorkerThread,
sizeof(waFatFSWorkerThread),
priority, ThreadFatFSWorker, NULL);
return workerThread;
}
void wf_terminate (void) {
struct wrapper_msg_base msg;
if (workerThread) {
msg.action = eTERMINATE;
chThdTerminate(workerThread);
chMsgSend(workerThread, (msg_t) &msg);
}
return;
}
#if HAS_MOUNT || defined(__DOXYGEN__)
/**
* @brief Mount/Unmount a logical Drive
* @param vol Logical drive number to be mounted/unmounted.
* @param fs Pointer to new file system object (NULL for unmount).
* @return
*/
FRESULT wf_mount (FATFS* fs, const TCHAR* path, BYTE opt) {
struct wrapper_msg_pFATFSpTCHARvBYTE msg;
msg.action = eFMOUNT;
msg.fatfsp = fs;
msg.string = (TCHAR*) path;
msg.byte = opt;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_MOUNT */
#if HAS_OPEN || defined(__DOXYGEN__)
/**
* @brief Open or Create a File.
*
* @param fp Pointer to the blank file object.
* @param path Pointer to the file name.
* @param mode Access mode and file open mode flags.
* @return
*/
FRESULT wf_open (FIL* fp, const TCHAR* path, BYTE mode) {
struct wrapper_msg_pFILpTCHARvBYTE msg;
msg.action = eFOPEN;
msg.filep = fp;
msg.string = (TCHAR*) path;
msg.byte = mode;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_OPEN */
#if HAS_READ || defined(__DOXYGEN__)
/**
* @brief Read File
*
* @param fp Pointer to the file object.
* @param buff Pointer to data buffer.
* @param btr Number of bytes to read.
* @param br Pointer to number of bytes read.
* @return
*/
FRESULT wf_read (FIL* fp, void* buff, UINT btr, UINT* br) {
struct wrapper_msg_pFILpVOIDvUINTpUINT msg;
msg.action = eFREAD;
msg.filep = fp;
msg.voidp = buff;
msg.uint = btr;
msg.uintp = br;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_READ */
#if HAS_WRITE || defined(__DOXYGEN__)
/**
* @brief Write File.
*
* @param fp Pointer to the file object.
* @param buff Pointer to the data to be written.
* @param btw Number of bytes to write.
* @param bw Pointer to number of bytes written.
* @return
*/
FRESULT wf_write (FIL* fp, const void* buff, UINT btw, UINT* bw) {
struct wrapper_msg_pFILpVOIDvUINTpUINT msg;
msg.action = eFWRITE;
msg.filep = fp;
msg.voidp = (void*) buff;
msg.uint = btw;
msg.uintp = bw;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_WRITE */
#if HAS_SYNC || defined(__DOXYGEN__)
/**
* @brief Synchronize the File Object
*
* @param fp Pointer to the file object.
* @return
*/
FRESULT wf_sync (FIL* fp) {
struct wrapper_msg_pFIL msg;
msg.action = eFSYNC;
msg.filep = fp;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_SYNC */
#if HAS_CHDRIVE || defined(__DOXYGEN__)
/**
* @brief Change current drive.
* @param drv Drive number.
* @return
*/
FRESULT wf_chdrive (BYTE drv) {
struct wrapper_msg_vBYTE msg;
msg.action = eFCHDRIVE;
msg.byte = drv;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_CHDRIVE */
#if HAS_CHDIR || defined(__DOXYGEN__)
/**
* @brief Change current path.
* @param path Pointer to the directory path.
* @return
*/
FRESULT wf_chdir (const TCHAR* path) {
struct wrapper_msg_pTCHAR msg;
msg.action = eFCHDIR;
msg.string = (TCHAR*) path;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_CHDIR */
#if HAS_GETCWD || defined(__DOXYGEN__)
/**
* @brief Get current working directory.
* @param path Pointer to the directory path.
* @param sz_path Size of path.
* @return
*/
FRESULT wf_getcwd (TCHAR* path, UINT sz_path) {
struct wrapper_msg_pTCHARvUINT msg;
msg.action = eFGETCWD;
msg.string = (TCHAR*) path;
msg.uint = sz_path;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_GETCWD */
#if HAS_LSEEK || defined(__DOXYGEN__)
/**
* @brief Seek File R/W Pointer.
*
* @param fp Pointer to the file object.
* @param ofs File pointer from top of file.
* @return
*/
FRESULT wf_lseek (FIL* fp, DWORD ofs) {
struct wrapper_msg_pFILvDWORD msg;
msg.action = eFLSEEK;
msg.filep = fp;
msg.dword = ofs;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_LSEEK */
#if HAS_CLOSE || defined(__DOXYGEN__)
/**
* @brief Close File.
*
* @param fp Pointer to the file object to be closed.
* @return
*/
FRESULT wf_close (FIL* fp) {
struct wrapper_msg_pFIL msg;
msg.action = eFCLOSE;
msg.filep = fp;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_CLOSE */
#if HAS_OPENDIR || defined(__DOXYGEN__)
/**
* @brief Create a Directory Object
*
* @param dj Pointer to directory object to create.
* @param path Pointer to the directory path.
* @return
*/
FRESULT wf_opendir (DIR* dj, const TCHAR* path) {
struct wrapper_msg_pDIRpTCHAR msg;
msg.action = eFOPENDIR;
msg.dirp = dj;
msg.string = (TCHAR*) path;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_OPENDIR */
#if HAS_READDIR || defined(__DOXYGEN__)
/**
* @brief Read Directory Entry in Sequence
* @param dj Pointer to the open directory object.
* @param fno Pointer to file information to return.
* @return
*/
FRESULT wf_readdir (DIR* dj, FILINFO* fno) {
struct wrapper_msg_pDIRpFILINFO msg;
msg.action = eFREADDIR;
msg.dirp = dj;
msg.filinfop = fno;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_READDIR */
#if HAS_STAT || defined(__DOXYGEN__)
/**
* @brief Get File Status.
*
* @param path Pointer to the file path.
* @param fno Pointer to file information to return.
* @return
*/
FRESULT wf_stat (const TCHAR* path, FILINFO* fno) {
struct wrapper_msg_pTCHARpFILINFO msg;
msg.action = eFSTAT;
msg.string = (TCHAR*) path;
msg.filinfop = fno;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_STAT */
#if HAS_GETFREE || defined(__DOXYGEN__)
/**
* @brief Get Number of Free Clusters.
*
* @param path Pointer to the logical drive number (root dir).
* @param nclst Pointer to the variable to return number of free clusters,
* @param fatfs Pointer to pointer to corresponding file system object to
* return.
* @return
*/
FRESULT wf_getfree (const TCHAR* path, DWORD*nclst, FATFS** fatfs) {
struct wrapper_msg_pTCHARpDWORDppFATFS msg;
msg.action = eFGETFREE;
msg.string = (TCHAR*) path;
msg.dwordp = nclst;
msg.fatfspp = fatfs;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_GETFREE */
#if HAS_TRUNCATE || defined(__DOXYGEN__)
/**
* @brief Truncate File.
*
* @param fp Pointer to the file object.
* @return
*/
FRESULT wf_truncate (FIL* fp){
struct wrapper_msg_pFIL msg;
msg.action = eFTRUNCATE;
msg.filep = fp;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_TRUNCATE */
#if HAS_UNLINK || defined(__DOXYGEN__)
/**
* @brief Delete a File or Directory.
* @param path Pointer to the file or directory path.
* @return
*/
FRESULT wf_unlink (const TCHAR* path) {
struct wrapper_msg_pTCHAR msg;
msg.action = eFUNLINK;
msg.string = (TCHAR*) path;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_UNLINK */
#if HAS_MKDIR || defined(__DOXYGEN__)
/**
* @brief Create a Directory.
* @param path Pointer to the directory path.
* @return
*/
FRESULT wf_mkdir (const TCHAR* path) {
struct wrapper_msg_pTCHAR msg;
msg.action = eFMKDIR;
msg.string = (TCHAR*) path;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_MKDIR */
#if HAS_CHMOD || defined(__DOXYGEN__)
/**
* @brief Change Attribute.
*
* @param path Pointer to the file path.
* @param value Attribute bits.
* @param mask Attribute mask to change.
* @return
*/
FRESULT wf_chmod (const TCHAR* path, BYTE value, BYTE mask) {
struct wrapper_msg_pTCHARvBYTEvBYTE msg;
msg.action = eFCHMOD;
msg.string = (TCHAR*) path;
msg.byte1 = value;
msg.byte2 = mask;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_CHMOD */
#if HAS_UTIME || defined(__DOXYGEN__)
/**
* @brief Change Timestamp.
*
* @param path Pointer to the file/directory name.
* @param fno Pointer to the time stamp to be set.
* @return
*/
FRESULT wf_utime (const TCHAR* path, const FILINFO* fno) {
struct wrapper_msg_pTCHARpFILINFO msg;
msg.action = eFUTIME;
msg.string = (TCHAR*) path;
msg.filinfop = (FILINFO*) fno;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_UTIME */
#if HAS_RENAME || defined(__DOXYGEN__)
/**
* @brief Rename File/Directory.
* @param path_old Pointer to the old name.
* @param path_new Pointer to the new name
* @return
*/
FRESULT wf_rename (const TCHAR* path_old, const TCHAR* path_new) {
struct wrapper_msg_pTCHARpTCHAR msg;
msg.action = eFRENAME;
msg.string1 = (TCHAR*) path_old;
msg.string2 = (TCHAR*) path_new;
chMsgSend(workerThread, (msg_t) &msg);
return msg.result;
}
#endif /* HAS_RENAME */
#if HAS_MKFS || defined(__DOXYGEN__)
/**
* @brief Create File System on the Drive.
* @param drv Logical drive number.
* @param sfd Partitioning rule 0:FDISK, 1:SFD.
* @param au Allocation unit size [bytes].
* @return
*/
FRESULT wf_mkfs (BYTE drv, BYTE sfd, UINT au) {
struct wrapper_msg_vBYTEvBYTEvUINT msg;
msg.action = eFMKFS;
msg.byte1 = drv;
msg.byte2 = sfd;