diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index b5df994240..ce78ad8694 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -44,6 +44,38 @@ BlockDevice *constructBlockDevice(const char *filename) { return new FileBlockDevice(f); } + +// Android NDK does not support 64-bit file I/O using C streams +// so we fall back onto syscalls + +#ifdef ANDROID + +FileBlockDevice::FileBlockDevice(FILE *file) +: f(file) +{ + fd = fileno(file); + + off64_t off = lseek64(fd, 0, SEEK_END); + filesize = off; + lseek64(fd, 0, SEEK_SET); +} + +FileBlockDevice::~FileBlockDevice() +{ + fclose(f); +} + +bool FileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr) +{ + lseek64(fd, (u64)blockNumber * (u64)GetBlockSize(), SEEK_SET); + if (read(fd, outPtr, 2048) != 2048) { + ERROR_LOG(FILESYS, "Could not read() 2048 bytes from block"); + } + return true; +} + +#else + FileBlockDevice::FileBlockDevice(FILE *file) : f(file) { @@ -59,13 +91,15 @@ FileBlockDevice::~FileBlockDevice() bool FileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr) { - fseeko(f, (u64)blockNumber * (u64)GetBlockSize(), SEEK_SET); + fseek(f, (u64)blockNumber * (u64)GetBlockSize(), SEEK_SET); if (fread(outPtr, 1, 2048, f) != 2048) DEBUG_LOG(FILESYS, "Could not read 2048 bytes from block"); return true; } +#endif + // .CSO format // compressed ISO(9660) header format diff --git a/Core/FileSystems/BlockDevices.h b/Core/FileSystems/BlockDevices.h index 8ec3955c47..bdd24d42b2 100644 --- a/Core/FileSystems/BlockDevices.h +++ b/Core/FileSystems/BlockDevices.h @@ -62,6 +62,9 @@ public: u32 GetNumBlocks() {return (u32)(filesize / GetBlockSize());} private: +#ifdef ANDROID + int fd; +#endif FILE *f; u64 filesize; };