wiiu-nanddumper-payload/ios_fs/source/sd_fat.c

41 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
#include "types.h"
#include "imports.h"
#include "devices.h"
#include "sdio.h"
#include "text.h"
#include "sd_fat.h"
unsigned char sd_io_buffer[0x40000] __attribute__((aligned(0x40))) __attribute__((section(".io_buffer")));
int sd_fat_read(unsigned long sector, unsigned char *buffer, unsigned long sector_count)
{
2017-03-27 22:04:19 +02:00
// It seems that sdcard_readwrite overwrite more bytes than requested with 0xff.... So I use io_buffer to read it.
if (sector_count * SDIO_BYTES_PER_SECTOR > sizeof(sd_io_buffer)) return 0;
int result = sdcard_readwrite(SDIO_READ, sd_io_buffer, sector_count, SDIO_BYTES_PER_SECTOR, sector, NULL, DEVICE_ID_SDCARD_PATCHED);
2017-03-27 22:04:19 +02:00
if (result) return 0;
memcpy(buffer, sd_io_buffer, sector_count * SDIO_BYTES_PER_SECTOR);
return 1;
}
int sd_fat_write(unsigned long sector, unsigned char *buffer, unsigned long sector_count)
{
2017-03-27 22:04:19 +02:00
if (sector_count * SDIO_BYTES_PER_SECTOR > sizeof(sd_io_buffer)) return 0;
int result = sdcard_readwrite(SDIO_WRITE, buffer, sector_count, SDIO_BYTES_PER_SECTOR, sector, NULL, DEVICE_ID_SDCARD_PATCHED);
2017-03-27 22:04:19 +02:00
return result ? 0 : 1;
}
int InitSDCardFAT32()
{
2017-03-27 22:04:19 +02:00
fl_init();
int result = fl_attach_media(sd_fat_read, sd_fat_write);
2017-03-27 22:04:19 +02:00
if (result != FAT_INIT_OK)
{
_printf(20, 40, "FAT32 attach failed %d", result);
2017-03-27 22:04:19 +02:00
return result;
}
return 0;
}