usbloadergx/source/usbloader/wbfs/wbfs_rw.cpp
e.bovendeur e8f5ab07bd * Changed WBFS stuff to C++ classes
* Fixed bug in http.c (where realloc *might* choose another address, thanks Dr. Clipper)
* Added support to /wbfs/Game Title [GAMEID].wbfs files (thanks oggzee)
* Fixed bug in cfg_cleanup when switching partitions
* Added BGM class again (for playing background music, requested by dimok)
* Added settings for background music again
* Fixed bug in MEM2 class (returning an invalid handle when no memory could be allocated, thanks to dimok)
* Updated DIP module to OpenDIP (report bugs with this one if you've found them, but report them here: http://github.com/spacemanspiff/odip-plugin)
* Added initial code for cios 222 rev5 (THIS DOES NOT WORK YET! DON'T FILE BUGS ON THIS ONE!)
* Added fatffs module by Hermes and Waninkoko (THIS DOES NOT WORK YET! DON'T FILE BUGS ON THIS ONE!)
* Fixed bug in Settings, which resulted in a crash when the partition was changed.
* Added caching for gamelist entries, so switching between different screens/sort options/display modes should be faster
* Changed defines in ehc_module, in order to prevent clashes with new defines in rev5
2010-02-14 23:22:52 +00:00

160 lines
3.5 KiB
C++

#include <ogcsys.h>
#include <malloc.h>
#include "usbloader/sdhc.h"
#include "usbloader/usbstorage.h"
#include "usbloader/wdvd.h"
#include "wbfs_base.h"
/* Constants */
#define MAX_NB_SECTORS 32
s32 Wbfs::__ReadDVD(void *fp, u32 lba, u32 len, void *iobuf) {
void *buffer = NULL;
u64 offset;
u32 mod, size;
s32 ret;
/* Calculate offset */
offset = ((u64)lba) << 2;
/* Calcualte sizes */
mod = len % 32;
size = len - mod;
/* Read aligned data */
if (size) {
ret = WDVD_UnencryptedRead(iobuf, size, offset);
if (ret < 0)
goto out;
}
/* Read non-aligned data */
if (mod) {
/* Allocate memory */
buffer = memalign(32, 0x20);
if (!buffer)
return -1;
/* Read data */
ret = WDVD_UnencryptedRead(buffer, 0x20, offset + size);
if (ret < 0)
goto out;
/* Copy data */
void *ptr = ((u8 *) iobuf) + size;
memcpy(ptr, buffer, mod);
}
/* Success */
ret = 0;
out:
/* Free memory */
if (buffer)
free(buffer);
return ret;
}
s32 Wbfs::__ReadUSB(void *fp, u32 lba, u32 count, void *iobuf) {
u32 cnt = 0;
s32 ret;
/* Do reads */
while (cnt < count) {
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
u32 sectors = (count - cnt);
/* Read sectors is too big */
if (sectors > MAX_NB_SECTORS)
sectors = MAX_NB_SECTORS;
/* USB read */
ret = USBStorage_ReadSectors(lba + cnt, sectors, ptr);
if (ret < 0)
return ret;
/* Increment counter */
cnt += sectors;
}
return 0;
}
s32 Wbfs::__WriteUSB(void *fp, u32 lba, u32 count, void *iobuf) {
u32 cnt = 0;
s32 ret;
/* Do writes */
while (cnt < count) {
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
u32 sectors = (count - cnt);
/* Write sectors is too big */
if (sectors > MAX_NB_SECTORS)
sectors = MAX_NB_SECTORS;
/* USB write */
ret = USBStorage_WriteSectors(lba + cnt, sectors, ptr);
if (ret < 0)
return ret;
/* Increment counter */
cnt += sectors;
}
return 0;
}
s32 Wbfs::__ReadSDHC(void *fp, u32 lba, u32 count, void *iobuf) {
u32 cnt = 0;
s32 ret;
/* Do reads */
while (cnt < count) {
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
u32 sectors = (count - cnt);
/* Read sectors is too big */
if (sectors > MAX_NB_SECTORS)
sectors = MAX_NB_SECTORS;
/* SDHC read */
ret = SDHC_ReadSectors(lba + cnt, sectors, ptr);
if (!ret)
return -1;
/* Increment counter */
cnt += sectors;
}
return 0;
}
s32 Wbfs::__WriteSDHC(void *fp, u32 lba, u32 count, void *iobuf) {
u32 cnt = 0;
s32 ret;
/* Do writes */
while (cnt < count) {
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
u32 sectors = (count - cnt);
/* Write sectors is too big */
if (sectors > MAX_NB_SECTORS)
sectors = MAX_NB_SECTORS;
/* SDHC write */
ret = SDHC_WriteSectors(lba + cnt, sectors, ptr);
if (!ret)
return -1;
/* Increment counter */
cnt += sectors;
}
return 0;
}