1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-23 20:32:10 +00:00
Atmosphere/fusee/common/fatfs/diskio.c

165 lines
5.4 KiB
C
Raw Normal View History

2019-07-01 20:12:30 +01:00
/*-----------------------------------------------------------------------*/
2020-11-11 17:18:31 +00:00
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2019 */
2019-07-01 20:12:30 +01:00
/*-----------------------------------------------------------------------*/
/* 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 <stdbool.h>
#include <string.h>
2019-07-01 20:20:34 +01:00
#include "ff.h" /* Obtains integer types */
#include "diskio.h" /* Declarations of disk functions */
2019-07-01 20:12:30 +01:00
#include "ffconf.h"
#if defined(FUSEE_STAGE1_SRC)
2020-11-30 01:30:35 +00:00
#include "../../../fusee/fusee-primary/fusee-primary-main/src/fs_utils.h"
#elif defined(FUSEE_STAGE2_SRC)
#include "../../../fusee/fusee-secondary/src/device_partition.h"
#endif
#ifdef FUSEE_STAGE2_SRC
2019-07-01 20:12:30 +01:00
/* fs_dev.c */
extern device_partition_t *g_volume_to_devparts[FF_VOLUMES];
#endif
2019-07-01 20:12:30 +01:00
2020-11-11 17:18:31 +00:00
2019-07-01 20:12:30 +01:00
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (
2019-07-01 20:20:34 +01:00
BYTE pdrv /* Physical drive nmuber to identify the drive */
2019-07-01 20:12:30 +01:00
)
{
#ifdef FUSEE_STAGE2_SRC
2019-07-01 20:20:34 +01:00
device_partition_t *devpart = g_volume_to_devparts[pdrv];
2019-07-01 20:12:30 +01:00
if (devpart)
return devpart->initialized ? RES_OK : STA_NOINIT;
else
return STA_NODISK;
#else
return RES_OK;
#endif
2019-07-01 20:12:30 +01:00
}
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
2019-07-01 20:20:34 +01:00
BYTE pdrv /* Physical drive nmuber to identify the drive */
2019-07-01 20:12:30 +01:00
)
{
#ifdef FUSEE_STAGE2_SRC
2019-07-01 20:20:34 +01:00
/* We aren't using FF_MULTI_PARTITION, so pdrv = volume id. */
device_partition_t *devpart = g_volume_to_devparts[pdrv];
if (!devpart)
return STA_NODISK;
else if (devpart->initializer)
return devpart->initializer(devpart) ? STA_NOINIT : RES_OK;
2020-11-30 01:30:35 +00:00
else
2019-07-01 20:12:30 +01:00
return RES_OK;
#else
return RES_OK;
#endif
2019-07-01 20:12:30 +01:00
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
2019-07-01 20:20:34 +01:00
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
2020-11-11 17:18:31 +00:00
LBA_t sector, /* Start sector in LBA */
2019-07-01 20:20:34 +01:00
UINT count /* Number of sectors to read */
2019-07-01 20:12:30 +01:00
)
{
#ifdef FUSEE_STAGE2_SRC
2019-07-01 20:20:34 +01:00
/* We aren't using FF_MULTI_PARTITION, so pdrv = volume id. */
device_partition_t *devpart = g_volume_to_devparts[pdrv];
if (!devpart)
return RES_PARERR;
else if (devpart->reader)
return device_partition_read_data(devpart, buff, sector, count) ? RES_ERROR : RES_OK;
else
2019-07-01 20:12:30 +01:00
return RES_ERROR;
#else
switch (pdrv) {
case 0:
return sdmmc_device_read(&g_sd_device, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
default:
return RES_PARERR;
}
#endif
2019-07-01 20:12:30 +01:00
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if FF_FS_READONLY == 0
DRESULT disk_write (
2019-07-01 20:20:34 +01:00
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
2020-11-11 17:18:31 +00:00
LBA_t sector, /* Start sector in LBA */
2019-07-01 20:20:34 +01:00
UINT count /* Number of sectors to write */
2019-07-01 20:12:30 +01:00
)
{
#ifdef FUSEE_STAGE2_SRC
2019-07-01 20:20:34 +01:00
/* We aren't using FF_MULTI_PARTITION, so pdrv = volume id. */
device_partition_t *devpart = g_volume_to_devparts[pdrv];
if (!devpart)
return RES_PARERR;
else if (devpart->writer)
return device_partition_write_data(devpart, buff, sector, count) ? RES_ERROR : RES_OK;
else
2019-07-01 20:12:30 +01:00
return RES_ERROR;
#else
switch (pdrv) {
case 0:
return sdmmc_device_write(&g_sd_device, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
default:
return RES_PARERR;
}
#endif
2019-07-01 20:12:30 +01:00
}
#endif
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
DRESULT disk_ioctl (
2019-07-01 20:20:34 +01:00
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
2019-07-01 20:12:30 +01:00
)
{
#ifdef FUSEE_STAGE2_SRC
/* We aren't using FF_MULTI_PARTITION, so pdrv = volume id. */
2019-07-01 20:20:34 +01:00
device_partition_t *devpart = g_volume_to_devparts[pdrv];
switch (cmd) {
2019-07-01 20:12:30 +01:00
case GET_SECTOR_SIZE:
*(WORD *)buff = devpart ? (WORD)devpart->sector_size : 512;
return RES_OK;
default:
return RES_OK;
}
#else
return RES_OK;
#endif
2019-07-01 20:12:30 +01:00
}