This repository has been archived on 2022-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Luma3DS-3GX/source/fs.c

61 lines
1.0 KiB
C
Raw Normal View History

2015-08-05 03:57:37 +02:00
/*
* fs.c
*/
#include "fs.h"
#include "fatfs/ff.h"
static FATFS fs;
2016-03-06 03:41:07 +01:00
u8 mountSD(void){
2016-03-05 23:27:02 +01:00
if(f_mount(&fs, "0:", 1) != FR_OK) return 0;
return 1;
2015-08-05 03:57:37 +02:00
}
2016-03-06 03:41:07 +01:00
u8 fileRead(u8 *dest, const char *path, u32 size){
2015-08-05 03:57:37 +02:00
FRESULT fr;
FIL fp;
2016-02-08 03:37:03 +01:00
unsigned int br = 0;
2015-08-05 03:57:37 +02:00
fr = f_open(&fp, path, FA_READ);
2016-03-05 23:27:02 +01:00
if(fr == FR_OK){
if(!size) size = f_size(&fp);
fr = f_read(&fp, dest, size, &br);
2015-08-05 03:57:37 +02:00
}
f_close(&fp);
2016-03-05 23:27:02 +01:00
return fr ? 0 : 1;
2015-08-05 03:57:37 +02:00
}
2016-03-06 03:41:07 +01:00
u8 fileWrite(const u8 *buffer, const char *path, u32 size){
2016-03-05 23:27:02 +01:00
FRESULT fr;
2015-08-05 03:57:37 +02:00
FIL fp;
2016-02-08 03:37:03 +01:00
unsigned int br = 0;
2015-08-05 03:57:37 +02:00
2016-03-05 23:27:02 +01:00
fr = f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS);
if(fr == FR_OK) fr = f_write(&fp, buffer, size, &br);
f_close(&fp);
return fr ? 0 : 1;
}
2016-03-06 03:41:07 +01:00
u32 fileSize(const char* path){
FIL fp;
2016-03-06 03:41:07 +01:00
u32 size = 0;
2016-03-05 23:27:02 +01:00
if(f_open(&fp, path, FA_READ) == FR_OK)
size = f_size(&fp);
f_close(&fp);
return size;
}
2016-03-06 03:41:07 +01:00
u8 fileExists(const char* path){
FIL fp;
2016-03-06 03:41:07 +01:00
u8 exists = 0;
2016-03-05 23:27:02 +01:00
if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1;
f_close(&fp);
return exists;
2015-08-05 03:57:37 +02:00
}