pse-uisim/fatfs.c
2023-09-19 17:57:18 +02:00

54 lines
1.1 KiB
C

#include "fatfs.h"
#include <errno.h>
#include <stdio.h>
FRESULT f_open (
FIL* fp, /* Pointer to the blank file object */
const TCHAR* path, /* Pointer to the file name */
BYTE mode /* Access mode and file open mode flags */
){
FILE* f;
printf("mode %d\n", mode);
if(mode & FA_READ)
f = fopen(path, "r");
else if(mode & FA_WRITE && mode & FA_OPEN_ALWAYS)
f = fopen(path, "w+");
else
printf("Unimplemented mode");
if(f == NULL){
printf("errno %d\n",errno);
return FR_NO_FILE;
}
*fp = f;
return FR_OK;
}
FRESULT f_read (
FIL* fp, /* Pointer to the file object */
void* buff, /* Pointer to data buffer */
UINT btr, /* Number of bytes to read */
UINT* br /* Pointer to number of bytes read */
){
*br = fread(buff, 1, btr, *fp);
return FR_OK;
}
FRESULT f_close (
FIL *fp /* Pointer to the file object to be closed */
){
fclose(*fp);
return FR_OK;
}
FRESULT f_write (
FIL* fp, /* Pointer to the file object */
const void *buff, /* Pointer to the data to be written */
UINT btw, /* Number of bytes to write */
UINT* bw /* Pointer to number of bytes written */
){
*bw = fwrite(buff, 1, btw, *fp);
return FR_OK;
}