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; }
bool Device_WriteSectors(u32 device, u32 sector, u32 count, void *buffer) { s32 ret; /* Read from specified device */ switch (device) { case WBFS_DEVICE_USB: ret = USBStorage_WriteSectors(sector, count, buffer); if (ret < 0) return false; return true; case WBFS_DEVICE_SDHC: return SDHC_WriteSectors(sector, count, buffer); } return false; }