1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-10-30 07:21:46 +00:00
nxdumptool/source/core/fatfs/diskio.c
Pablo Curiel 596928a3c6 Create BIS storage interface.
Takes care of retrieving a FsStorage object for any FAT eMMC BIS partition, mounting it via FatFs and creating a virtual devoptab device that can be used to carry out FS operations. All write operations have been stubbed, disabled or ifdef'd out of the code.

Other changes include:

* cert: update code to use the new BIS storage interface.

* defines: remove BIS_SYSTEM_PARTITION_MOUNT_NAME macro.

* devoptab: slightly improve macros.
* devoptab: add operation table for FatFs devices.
* devoptab: add rodev_fstat().
* devoptab: add devoptabMountFatFsDevice().

* fatfs: update diskio code to use the new BIS storage interface.
* fatfs: update configuration.

* save: update code to use regular C I/O calls instead of FatFs calls.

* tik: update code to use the new BIS storage interface.

* utils: remove eMMC BIS System partition (un)mount code.
2024-10-28 14:31:58 +01:00

117 lines
3.9 KiB
C

/*-----------------------------------------------------------------------*/
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
/* This is an example of glue functions to attach various exsisting */
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include <core/nxdt_utils.h>
#include <core/bis_storage.h>
#include <core/fatfs/ff.h> /* Obtains integer types */
#include <core/fatfs/diskio.h> /* Declarations of disk functions */
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (
BYTE pdrv /* Physical drive number to identify the drive */
)
{
NX_IGNORE_ARG(pdrv);
return 0;
}
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive number to identify the drive */
)
{
NX_IGNORE_ARG(pdrv);
return 0;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
BYTE pdrv, /* Physical drive number to identify the drive */
BYTE *buff, /* Data buffer to store read data */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to read */
)
{
FsStorage *bis_storage = NULL;
u64 offset = 0, size = 0;
Result rc = 0;
DRESULT ret = RES_PARERR;
bisStorageControlMutex(true);
/* Get pointer to FsStorage object. */
bis_storage = bisStorageGetFsStorageByFatFsDriveNumber(pdrv);
if (!bis_storage)
{
LOG_MSG_ERROR("Failed to retrieve FsStorage object for drive number %u!", pdrv);
goto end;
}
/* Calculate data offset and size. */
offset = ((u64)FF_MAX_SS * (u64)sector);
size = ((u64)FF_MAX_SS * (u64)count);
/* Read BIS storage. */
rc = fsStorageRead(bis_storage, (s64)offset, buff, size);
ret = (R_SUCCEEDED(rc) ? RES_OK : RES_ERROR);
if (ret == RES_ERROR) LOG_MSG_ERROR("Failed to read 0x%lX-byte long block at offset 0x%lX from drive number %u!", offset, size, pdrv);
end:
bisStorageControlMutex(false);
return ret;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if FF_FS_READONLY == 0
DRESULT disk_write (
BYTE pdrv, /* Physical drive number to identify the drive */
const BYTE *buff, /* Data to be written */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to write */
)
{
NX_IGNORE_ARG(pdrv);
NX_IGNORE_ARG(buff);
NX_IGNORE_ARG(sector);
NX_IGNORE_ARG(count);
return RES_OK;
}
#endif
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
DRESULT disk_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
NX_IGNORE_ARG(pdrv);
NX_IGNORE_ARG(cmd);
NX_IGNORE_ARG(buff);
return RES_OK;
}