add drive to access an area on emmc/sd as disk
This commit is contained in:
42
nyx/nyx_gui/storage/sfd.c
Normal file
42
nyx/nyx_gui/storage/sfd.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "sfd.h"
|
||||
#include <storage/emmc.h>
|
||||
#include <storage/sdmmc.h>
|
||||
|
||||
static sdmmc_storage_t *_storage;
|
||||
static u32 _offset;
|
||||
static u32 _size;
|
||||
|
||||
static void ensure_partition(){
|
||||
if(_storage == &emmc_storage){
|
||||
emmc_set_partition(EMMC_GPP);
|
||||
}
|
||||
}
|
||||
|
||||
int sfd_read(u32 sector, u32 count, void *buff){
|
||||
if(sector + _offset + count > _offset + _size){
|
||||
return 0;
|
||||
}
|
||||
ensure_partition();
|
||||
return sdmmc_storage_read(_storage, sector + _offset, count, buff);
|
||||
}
|
||||
|
||||
int sfd_write(u32 sector, u32 count, void *buff){
|
||||
if(sector + _offset + count > _offset + _size){
|
||||
return 0;
|
||||
}
|
||||
ensure_partition();
|
||||
return sdmmc_storage_write(_storage, sector + _offset, count, buff);
|
||||
}
|
||||
|
||||
bool sfd_init(sdmmc_storage_t *storage, u32 offset, u32 size){
|
||||
_storage = storage;
|
||||
_offset = offset;
|
||||
_size = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
void sfd_end(){
|
||||
_storage = NULL;
|
||||
_offset = 0;
|
||||
_size = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user