@@ -40,7 +40,7 @@ static int32_t filerProcessWrite(filerFileStruct_t *f) {
4040 if (!f -> open ) {
4141 res = f_open (& f -> fp , f -> fileName , FA_CREATE_ALWAYS | FA_WRITE );
4242 if (res != FR_OK )
43- return -1 ;
43+ return FILER_STATUS_ERR_OPEN ;
4444
4545 f -> open = 1 ;
4646 }
@@ -49,14 +49,14 @@ static int32_t filerProcessWrite(filerFileStruct_t *f) {
4949 res = f_lseek (& f -> fp , f -> seek );
5050 if (res != FR_OK ) {
5151 f -> open = 0 ;
52- return -1 ;
52+ return FILER_STATUS_ERR_SEEK ;
5353 }
5454 }
5555
5656 res = f_write (& f -> fp , f -> buf , f -> length , & bytes );
5757 if (res != FR_OK ) {
5858 f -> open = 0 ;
59- return -1 ;
59+ return FILER_STATUS_ERR_WRITE ;
6060 }
6161
6262 return bytes ;
@@ -68,8 +68,12 @@ static int32_t filerProcessRead(filerFileStruct_t *f) {
6868
6969 if (!f -> open ) {
7070 res = f_open (& f -> fp , f -> fileName , FA_OPEN_EXISTING | FA_READ );
71- if (res != FR_OK )
72- return -1 ;
71+ if (res != FR_OK ) {
72+ if (res == FR_NO_FILE || res == FR_NO_PATH )
73+ return FILER_STATUS_ERR_FNF ;
74+ else
75+ return FILER_STATUS_ERR_OPEN ;
76+ }
7377
7478 f -> open = 1 ;
7579 }
@@ -78,14 +82,14 @@ static int32_t filerProcessRead(filerFileStruct_t *f) {
7882 res = f_lseek (& f -> fp , f -> seek );
7983 if (res != FR_OK ) {
8084 f -> open = 0 ;
81- return -1 ;
85+ return FILER_STATUS_ERR_SEEK ;
8286 }
8387 }
8488
8589 res = f_read (& f -> fp , f -> buf , f -> length , & bytes );
8690 if (res != FR_OK ) {
8791 f -> open = 0 ;
88- return -1 ;
92+ return FILER_STATUS_ERR_READ ;
8993 }
9094
9195 return bytes ;
@@ -95,13 +99,13 @@ static int32_t filerProcessSync(filerFileStruct_t *f) {
9599 uint32_t res ;
96100
97101 if (!f -> open ) {
98- return -1 ;
102+ return FILER_STATUS_ERR_OPEN ;
99103 }
100104
101105 res = f_sync (& f -> fp );
102106 if (res != FR_OK ) {
103107 f -> open = 0 ;
104- return -1 ;
108+ return FILER_STATUS_ERR_SYNC ;
105109 }
106110
107111 return 0 ;
@@ -116,7 +120,7 @@ static int32_t filerProcessStream(filerFileStruct_t *f, uint8_t final) {
116120 sprintf (filerData .buf , "%03d-%s.LOG" , filerData .session , f -> fileName );
117121 res = f_open (& f -> fp , filerData .buf , FA_CREATE_ALWAYS | FA_WRITE );
118122 if (res != FR_OK )
119- return -1 ;
123+ return FILER_STATUS_ERR_OPEN ;
120124
121125 f -> open = 1 ;
122126 }
@@ -132,7 +136,7 @@ static int32_t filerProcessStream(filerFileStruct_t *f, uint8_t final) {
132136 f -> tail = (f -> tail + bytes ) % f -> length ;
133137
134138 if (res != FR_OK )
135- return -1 ;
139+ return FILER_STATUS_ERR_WRITE ;
136140 }
137141
138142 return bytes ;
@@ -147,9 +151,9 @@ static int32_t filerProcessClose(filerFileStruct_t *f) {
147151 }
148152
149153 if (res != FR_OK )
150- return -1 ;
154+ return FILER_STATUS_ERR_CLOSE ;
151155 else
152- return 0 ;
156+ return FILER_STATUS_OK ;
153157}
154158
155159static void filerProcessRequest (filerFileStruct_t * f ) {
@@ -369,13 +373,13 @@ int8_t filerGetHandle(char *fileName) {
369373 }
370374
371375 // too many files open
372- return -1 ;
376+ return FILER_STATUS_ERR_ALLOC ;
373377}
374378
375379int32_t filerReadWrite (filerFileStruct_t * f , void * buf , int32_t seek , uint32_t length , uint8_t function ) {
376380 // handle allocated yet?
377381 if (!f -> allocated || !filerData .initialized )
378- return -1 ;
382+ return FILER_STATUS_ERR_INIT ;
379383
380384 f -> buf = buf ;
381385 f -> function = function ;
@@ -404,7 +408,7 @@ int32_t filerSync(int8_t handle) {
404408
405409 // handle allocated yet?
406410 if (!f -> allocated )
407- return -1 ;
411+ return FILER_STATUS_ERR_INIT ;
408412
409413 if (f -> open ) {
410414 f -> function = FILER_FUNC_SYNC ;
@@ -422,7 +426,7 @@ int32_t filerClose(int8_t handle) {
422426
423427 // handle allocated yet?
424428 if (!f -> allocated )
425- return -1 ;
429+ return FILER_STATUS_ERR_INIT ;
426430
427431 if (f -> open ) {
428432 f -> function = FILER_FUNC_CLOSE ;
@@ -450,7 +454,7 @@ int32_t filerStream(int8_t handle, void *buf, uint32_t length) {
450454
451455 // handle allocated yet?
452456 if (!f -> allocated )
453- return -1 ;
457+ return FILER_STATUS_ERR_INIT ;
454458
455459 f -> function = FILER_FUNC_STREAM ;
456460 f -> buf = buf ;
0 commit comments