1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

Replace most returns with CHECK_ASSERTION

Also fix some Seek methods return types being unsigned, while returning
negative errors.

Added the CHECK_ASSERTION macro checks in a couple more places.

Simplified CHECK_ASSERTION macro usage.
This commit is contained in:
Raul Tambre 2015-11-08 13:42:41 +02:00
parent 9c2f48cd1d
commit 5d5a4f804b
14 changed files with 159 additions and 394 deletions

View File

@ -327,13 +327,7 @@ int OSCopyFile(const char* source, const char* destination, bool overwrite)
//sendfile will work with non-socket output (i.e. regular file) on Linux 2.6.33+ //sendfile will work with non-socket output (i.e. regular file) on Linux 2.6.33+
off_t bytesCopied = 0; off_t bytesCopied = 0;
struct stat fileinfo = { 0 }; struct stat fileinfo = { 0 };
fstat(input, &fileinfo);
s32 ret = fstat(input, &fileinfo);
if (ret < 0)
{
return -1;
}
int result = sendfile(output, input, &bytesCopied, fileinfo.st_size) == -1 ? -1 : 0; int result = sendfile(output, input, &bytesCopied, fileinfo.st_size) == -1 ? -1 : 0;
#endif #endif

View File

@ -17,55 +17,29 @@ namespace memory_helper
{ {
#ifdef _WIN32 #ifdef _WIN32
void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS); void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
if (ret == NULL) CHECK_ASSERTION(ret != NULL);
{
LOG_ERROR(HLE, "reserve_memory VirtualAlloc failed.");
return (void*)VM_FAILURE;
}
#else #else
void* ret = mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); void* ret = mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (ret == (void*)VM_FAILURE) CHECK_ASSERTION(ret != 0);
{
LOG_ERROR(HLE, "reserve_memory mmap failed.");
}
#endif #endif
return ret; return ret;
} }
s32 commit_page_memory(void* pointer, size_t page_size) void commit_page_memory(void* pointer, size_t page_size)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE) == NULL) CHECK_ASSERTION(VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE) != NULL);
{
LOG_ERROR(HLE, "commit_page_memory VirtualAlloc failed.");
return VM_FAILURE;
}
#else #else
s32 ret = mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE); CHECK_ASSERTION(mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE) != -1);
if (ret < VM_SUCCESS)
{
LOG_ERROR(HLE, "commit_page_memory mprotect failed. (%d)", ret);
return VM_FAILURE;
}
#endif #endif
return VM_SUCCESS;
} }
s32 free_reserved_memory(void* pointer, size_t size) void free_reserved_memory(void* pointer, size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (VirtualFree(pointer, 0, MEM_RELEASE) == 0) CHECK_ASSERTION(VirtualFree(pointer, 0, MEM_RELEASE) != 0);
{
LOG_ERROR(HLE, "free_reserved_memory VirtualFree failed.");
return VM_FAILURE;
}
#else #else
if (munmap(pointer, size) != VM_SUCCESS) CHECK_ASSERTION(munmap(pointer, size) == 0);
{
LOG_ERROR(HLE, "free_reserved_memory munmap failed.");
return VM_FAILURE;
}
#endif #endif
return VM_SUCCESS;
} }
} }

View File

@ -1,20 +1,10 @@
#pragma once #pragma once
// Failure codes for the functions
enum
{
VM_SUCCESS = 0,
VM_FAILURE = -1,
};
namespace memory_helper namespace memory_helper
{ {
/** /**
* Reserve size bytes of virtual memory and returns it. * Reserve size bytes of virtual memory and returns it.
* The memory should be commited before usage. * The memory should be commited before usage.
*
* Returns the base address of the allocated region of pages, if successful.
* Returns (void*)VM_FAILURE, if unsuccessful.
*/ */
void* reserve_memory(size_t size); void* reserve_memory(size_t size);
@ -22,17 +12,11 @@ namespace memory_helper
* Commit page_size bytes of virtual memory starting at pointer. * Commit page_size bytes of virtual memory starting at pointer.
* That is, bake reserved memory with physical memory. * That is, bake reserved memory with physical memory.
* pointer should belong to a range of reserved memory. * pointer should belong to a range of reserved memory.
*
* Returns VM_SUCCESS, if successful.
* Returns VM_FAILURE, if unsuccessful.
*/ */
s32 commit_page_memory(void* pointer, size_t page_size); void commit_page_memory(void* pointer, size_t page_size);
/** /**
* Free memory alloced via reserve_memory. * Free memory alloced via reserve_memory.
*
* Returns VM_SUCCESS, if successful.
* Returns VM_FAILURE, if unsuccessful.
*/ */
s32 free_reserved_memory(void* pointer, size_t size); void free_reserved_memory(void* pointer, size_t size);
} }

View File

@ -10,6 +10,7 @@
#ifndef _WIN32 #ifndef _WIN32
#include <dirent.h> #include <dirent.h>
#include <errno.h>
#endif #endif
#include "rPlatform.h" #include "rPlatform.h"
@ -57,14 +58,9 @@ std::string rPlatform::getConfigDir()
dir = "./config"; dir = "./config";
dir = dir + "/rpcs3/"; dir = dir + "/rpcs3/";
s32 ret = mkdir(dir.c_str(), 0777); if (mkdir(dir.c_str(), 0777) == -1)
if (ret == EEXIST)
{ {
LOG_WARNING(HLE, "Configuration directory already exists. (%s)", dir); printf("An error occured during the creation of the configuration directory. (%d)", errno);
}
else if (ret < 0)
{
LOG_ERROR(HLE, "An error occured during the creation of the configuration directory. (%d)", ret);
} }
#endif #endif
} }

View File

@ -172,12 +172,8 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
{ {
metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size; metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size;
if (in->seek(metadata_sec_offset) < 0) CHECK_ASSERTION(in->seek(metadata_sec_offset) != -1);
{
LOG_ERROR(LOADER, "EDAT: Seeking medata section offset at %u failed.", metadata_sec_offset);
return 1;
}
unsigned char metadata[0x20]; unsigned char metadata[0x20];
memset(metadata, 0, 0x20); memset(metadata, 0, 0x20);
in->read(metadata, 0x20); in->read(metadata, 0x20);
@ -205,7 +201,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
{ {
// If FLAG 0x20, the metadata precedes each data block. // If FLAG 0x20, the metadata precedes each data block.
metadata_sec_offset = metadata_offset + (unsigned long long) i * (metadata_section_size + length); metadata_sec_offset = metadata_offset + (unsigned long long) i * (metadata_section_size + length);
in->seek(metadata_sec_offset); CHECK_ASSERTION(in->seek(metadata_sec_offset) != -1);
unsigned char metadata[0x20]; unsigned char metadata[0x20];
memset(metadata, 0, 0x20); memset(metadata, 0, 0x20);
@ -226,7 +222,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
else else
{ {
metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size; metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size;
in->seek(metadata_sec_offset); CHECK_ASSERTION(in->seek(metadata_sec_offset) != -1);
in->read(hash_result, 0x10); in->read(hash_result, 0x10);
offset = metadata_offset + (unsigned long long) i * edat->block_size + (unsigned long long) block_num * metadata_section_size; offset = metadata_offset + (unsigned long long) i * edat->block_size + (unsigned long long) block_num * metadata_section_size;
@ -248,11 +244,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
memset(hash, 0, 0x10); memset(hash, 0, 0x10);
memset(key_result, 0, 0x10); memset(key_result, 0, 0x10);
if (in->seek(offset) < 0) CHECK_ASSERTION(in->seek(offset) != -1);
{
LOG_ERROR(LOADER, "EDAT: Seeking offset at %u failed.", offset);
return 1;
}
in->read(enc_data, length); in->read(enc_data, length);
@ -357,7 +349,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs::file* f, bool verbose) int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs::file* f, bool verbose)
{ {
f->seek(0); CHECK_ASSERTION(f->seek(0) != -1);
unsigned char header[0xA0]; unsigned char header[0xA0];
unsigned char empty_header[0xA0]; unsigned char empty_header[0xA0];
unsigned char header_hash[0x10]; unsigned char header_hash[0x10];
@ -402,10 +394,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
f->read(header, 0xA0); f->read(header, 0xA0);
// Read in the header and metadata section hashes. // Read in the header and metadata section hashes.
if (f->seek(0x90) < 0) CHECK_ASSERTION(f->seek(0x90) != -1);
{
LOG_ERROR(LOADER, "EDAT: Seeking header at 0x90 failed.");
}
f->read(metadata_hash, 0x10); f->read(metadata_hash, 0x10);
f->read(header_hash, 0x10); f->read(header_hash, 0x10);
@ -462,10 +451,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
while (bytes_to_read > 0) while (bytes_to_read > 0)
{ {
// Locate the metadata blocks. // Locate the metadata blocks.
if (f->seek(metadata_section_offset) < 0) CHECK_ASSERTION(f->seek(metadata_section_offset) != -1);
{
LOG_ERROR(LOADER, "EDAT: Seeking metadata blocks at %u failed.", metadata_section_offset);
}
// Read in the metadata. // Read in the metadata.
f->read(metadata + bytes_read, metadata_section_size); f->read(metadata + bytes_read, metadata_section_size);
@ -512,9 +498,9 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
// Read in the metadata and header signatures. // Read in the metadata and header signatures.
f->seek(0xB0); CHECK_ASSERTION(f->seek(0xB0) != -1);
f->read(metadata_signature, 0x28); f->read(metadata_signature, 0x28);
f->seek(0xD8); CHECK_ASSERTION(f->seek(0xD8) != -1);
f->read(header_signature, 0x28); f->read(header_signature, 0x28);
// Checking metadata signature. // Checking metadata signature.
@ -530,7 +516,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
{ {
int metadata_buf_size = block_num * 0x10; int metadata_buf_size = block_num * 0x10;
unsigned char *metadata_buf = new unsigned char[metadata_buf_size]; unsigned char *metadata_buf = new unsigned char[metadata_buf_size];
f->seek(metadata_offset); CHECK_ASSERTION(f->seek(metadata_offset) != -1);
f->read(metadata_buf, metadata_buf_size); f->read(metadata_buf, metadata_buf_size);
sha1(metadata_buf, metadata_buf_size, signature_hash); sha1(metadata_buf, metadata_buf_size, signature_hash);
delete[] metadata_buf; delete[] metadata_buf;
@ -563,7 +549,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
// Setup header signature hash. // Setup header signature hash.
memset(signature_hash, 0, 20); memset(signature_hash, 0, 20);
unsigned char *header_buf = new unsigned char[0xD8]; unsigned char *header_buf = new unsigned char[0xD8];
f->seek(0x00); CHECK_ASSERTION(f->seek(0x00) != -1);
f->read(header_buf, 0xD8); f->read(header_buf, 0xD8);
sha1(header_buf, 0xD8, signature_hash ); sha1(header_buf, 0xD8, signature_hash );
delete[] header_buf; delete[] header_buf;

View File

@ -86,11 +86,7 @@ bool UnpackPKG(const fs::file& pkg_f, const std::string& dir, volatile f64& prog
// Define decryption subfunction (`psp` arg selects the key for specific block) // Define decryption subfunction (`psp` arg selects the key for specific block)
auto decrypt = [&](u64 offset, u64 size, bool psp) -> u64 auto decrypt = [&](u64 offset, u64 size, bool psp) -> u64
{ {
if (pkg_f.seek(start_offset + header.data_offset + offset) < 0) CHECK_ASSERTION(pkg_f.seek(start_offset + header.data_offset + offset) != -1);
{
LOG_ERROR(LOADER, "PKG: Package file seek to %u failed.", start_offset + header.data_offset + offset);
return -1;
}
// Read the data and set available size // Read the data and set available size
const u64 read = pkg_f.read(buf.get(), size); const u64 read = pkg_f.read(buf.get(), size);

View File

@ -698,7 +698,7 @@ SELFDecrypter::SELFDecrypter(vfsStream& s)
bool SELFDecrypter::LoadHeaders(bool isElf32) bool SELFDecrypter::LoadHeaders(bool isElf32)
{ {
// Read SCE header. // Read SCE header.
self_f.Seek(0); CHECK_ASSERTION(self_f.Seek(0) != -1);
sce_hdr.Load(self_f); sce_hdr.Load(self_f);
// Check SCE magic. // Check SCE magic.
@ -712,11 +712,12 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
self_hdr.Load(self_f); self_hdr.Load(self_f);
// Read the APP INFO. // Read the APP INFO.
self_f.Seek(self_hdr.se_appinfooff); CHECK_ASSERTION(self_f.Seek(self_hdr.se_appinfooff) != -1);
app_info.Load(self_f); app_info.Load(self_f);
// Read ELF header. // Read ELF header.
self_f.Seek(self_hdr.se_elfoff); CHECK_ASSERTION(self_f.Seek(self_hdr.se_elfoff) != -1);
if (isElf32) if (isElf32)
elf32_hdr.Load(self_f); elf32_hdr.Load(self_f);
else else
@ -741,13 +742,16 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
else else
{ {
phdr64_arr.clear(); phdr64_arr.clear();
if(elf64_hdr.e_phoff == 0 && elf64_hdr.e_phnum)
if (elf64_hdr.e_phoff == 0 && elf64_hdr.e_phnum)
{ {
LOG_ERROR(LOADER, "SELF: ELF program header offset is null!"); LOG_ERROR(LOADER, "SELF: ELF program header offset is null!");
return false; return false;
} }
self_f.Seek(self_hdr.se_phdroff);
for(u32 i = 0; i < elf64_hdr.e_phnum; ++i) CHECK_ASSERTION(self_f.Seek(self_hdr.se_phdroff) != -1);
for (u32 i = 0; i < elf64_hdr.e_phnum; ++i)
{ {
phdr64_arr.emplace_back(); phdr64_arr.emplace_back();
phdr64_arr.back().Load(self_f); phdr64_arr.back().Load(self_f);
@ -757,7 +761,7 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
// Read section info. // Read section info.
secinfo_arr.clear(); secinfo_arr.clear();
self_f.Seek(self_hdr.se_secinfoff); CHECK_ASSERTION(self_f.Seek(self_hdr.se_secinfoff) != -1);
for(u32 i = 0; i < ((isElf32) ? elf32_hdr.e_phnum : elf64_hdr.e_phnum); ++i) for(u32 i = 0; i < ((isElf32) ? elf32_hdr.e_phnum : elf64_hdr.e_phnum); ++i)
{ {
@ -766,12 +770,12 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
} }
// Read SCE version info. // Read SCE version info.
self_f.Seek(self_hdr.se_sceveroff); CHECK_ASSERTION(self_f.Seek(self_hdr.se_sceveroff) != -1);
scev_info.Load(self_f); scev_info.Load(self_f);
// Read control info. // Read control info.
ctrlinfo_arr.clear(); ctrlinfo_arr.clear();
self_f.Seek(self_hdr.se_controloff); CHECK_ASSERTION(self_f.Seek(self_hdr.se_controloff) != -1);
u32 i = 0; u32 i = 0;
while(i < self_hdr.se_controlsize) while(i < self_hdr.se_controlsize)
@ -786,12 +790,15 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
if (isElf32) if (isElf32)
{ {
shdr32_arr.clear(); shdr32_arr.clear();
if(elf32_hdr.e_shoff == 0 && elf32_hdr.e_shnum)
if (elf32_hdr.e_shoff == 0 && elf32_hdr.e_shnum)
{ {
LOG_WARNING(LOADER, "SELF: ELF section header offset is null!"); LOG_WARNING(LOADER, "SELF: ELF section header offset is null!");
return true; return true;
} }
self_f.Seek(self_hdr.se_shdroff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_shdroff) != -1);
for(u32 i = 0; i < elf32_hdr.e_shnum; ++i) for(u32 i = 0; i < elf32_hdr.e_shnum; ++i)
{ {
shdr32_arr.emplace_back(); shdr32_arr.emplace_back();
@ -801,12 +808,14 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
else else
{ {
shdr64_arr.clear(); shdr64_arr.clear();
if(elf64_hdr.e_shoff == 0 && elf64_hdr.e_shnum) if (elf64_hdr.e_shoff == 0 && elf64_hdr.e_shnum)
{ {
LOG_WARNING(LOADER, "SELF: ELF section header offset is null!"); LOG_WARNING(LOADER, "SELF: ELF section header offset is null!");
return true; return true;
} }
self_f.Seek(self_hdr.se_shdroff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_shdroff) != -1);
for(u32 i = 0; i < elf64_hdr.e_shnum; ++i) for(u32 i = 0; i < elf64_hdr.e_shnum; ++i)
{ {
shdr64_arr.emplace_back(); shdr64_arr.emplace_back();
@ -890,9 +899,8 @@ bool SELFDecrypter::DecryptNPDRM(u8 *metadata, u32 metadata_size)
memcpy(klicensee_key, key_v.GetKlicenseeKey(), 0x10); memcpy(klicensee_key, key_v.GetKlicenseeKey(), 0x10);
// Use klicensee if available. // Use klicensee if available.
// FIXME: Check is always false. if (klicensee_key != NULL)
/*if (klicensee_key != NULL) memcpy(npdrm_key, klicensee_key, 0x10);
memcpy(npdrm_key, klicensee_key, 0x10);*/
if (ctrl->npdrm.license == 1) // Network license. if (ctrl->npdrm.license == 1) // Network license.
{ {
@ -942,11 +950,11 @@ bool SELFDecrypter::LoadMetadata()
u8 *metadata_headers = (u8 *)malloc(metadata_headers_size); u8 *metadata_headers = (u8 *)malloc(metadata_headers_size);
// Locate and read the encrypted metadata info. // Locate and read the encrypted metadata info.
self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr)); CHECK_ASSERTION(self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr)) != -1);
self_f.Read(metadata_info, metadata_info_size); self_f.Read(metadata_info, metadata_info_size);
// Locate and read the encrypted metadata header and section header. // Locate and read the encrypted metadata header and section header.
self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr) + metadata_info_size); CHECK_ASSERTION(self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr) + metadata_info_size) != -1);
self_f.Read(metadata_headers, metadata_headers_size); self_f.Read(metadata_headers, metadata_headers_size);
// Find the right keyset from the key vault. // Find the right keyset from the key vault.
@ -1049,7 +1057,7 @@ bool SELFDecrypter::DecryptData()
u8 *buf = (u8 *)malloc(meta_shdr[i].data_size); u8 *buf = (u8 *)malloc(meta_shdr[i].data_size);
// Seek to the section data offset and read the encrypted data. // Seek to the section data offset and read the encrypted data.
self_f.Seek(meta_shdr[i].data_offset); CHECK_ASSERTION(self_f.Seek(meta_shdr[i].data_offset) != -1);
self_f.Read(buf, meta_shdr[i].data_size); self_f.Read(buf, meta_shdr[i].data_size);
// Zero out our ctr nonce. // Zero out our ctr nonce.
@ -1104,11 +1112,7 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
if (meta_shdr[i].type == 2) if (meta_shdr[i].type == 2)
{ {
// Seek to the program header data offset and write the data. // Seek to the program header data offset and write the data.
if (e.seek(phdr32_arr[meta_shdr[i].program_idx].p_offset) < 0) CHECK_ASSERTION(e.seek(phdr32_arr[meta_shdr[i].program_idx].p_offset) != -1);
{
LOG_ERROR(LOADER, "MakeElf program header data seek to %u failed.", phdr32_arr[meta_shdr[i].program_idx].p_offset);
return false;
}
e.write(data_buf + data_buf_offset, meta_shdr[i].data_size); e.write(data_buf + data_buf_offset, meta_shdr[i].data_size);
@ -1120,11 +1124,7 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
// Write section headers. // Write section headers.
if (self_hdr.se_shdroff != 0) if (self_hdr.se_shdroff != 0)
{ {
if (e.seek(elf32_hdr.e_shoff) < 0) CHECK_ASSERTION(e.seek(elf32_hdr.e_shoff) != -1);
{
LOG_ERROR(LOADER, "MakeElf section header seek to %u failed.", elf32_hdr.e_shoff);
return false;
}
for (u32 i = 0; i < elf32_hdr.e_shnum; ++i) for (u32 i = 0; i < elf32_hdr.e_shnum; ++i)
{ {
@ -1168,11 +1168,8 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
decomp_stream_out.CopyTo(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz); decomp_stream_out.CopyTo(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz);
// Seek to the program header data offset and write the data. // Seek to the program header data offset and write the data.
if (e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset) < 0)
{ CHECK_ASSERTION(e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset) != -1);
LOG_ERROR(LOADER, "MakeElf program header data seek to %u failed.", phdr64_arr[meta_shdr[i].program_idx].p_offset);
return false;
}
e.write(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz); e.write(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz);
@ -1182,11 +1179,7 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
else else
{ {
// Seek to the program header data offset and write the data. // Seek to the program header data offset and write the data.
if (e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset) < 0) CHECK_ASSERTION(e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset) != -1);
{
LOG_ERROR(LOADER, "MakeElf program header data seek to %u failed.", phdr64_arr[meta_shdr[i].program_idx].p_offset);
return false;
}
e.write(data_buf + data_buf_offset, meta_shdr[i].data_size); e.write(data_buf + data_buf_offset, meta_shdr[i].data_size);
} }
@ -1199,11 +1192,7 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
// Write section headers. // Write section headers.
if (self_hdr.se_shdroff != 0) if (self_hdr.se_shdroff != 0)
{ {
if (e.seek(elf64_hdr.e_shoff) < 0) CHECK_ASSERTION(e.seek(elf64_hdr.e_shoff) != -1);
{
LOG_ERROR(LOADER, "MakeElf section header seek to %u failed.", elf64_hdr.e_shoff);
return false;
}
for (u32 i = 0; i < elf64_hdr.e_shnum; ++i) for (u32 i = 0; i < elf64_hdr.e_shnum; ++i)
{ {
@ -1279,11 +1268,7 @@ bool IsSelfElf32(const std::string& path)
// Locate the class byte and check it. // Locate the class byte and check it.
u8 elf_class[0x8]; u8 elf_class[0x8];
if (f.Seek(sh.se_elfoff) < 0) CHECK_ASSERTION(f.Seek(sh.se_elfoff) != -1);
{
LOG_ERROR(LOADER, "IsSelfElf32 seek to %u failed.", sh.se_elfoff);
return false;
}
f.Read(elf_class, 0x8); f.Read(elf_class, 0x8);
@ -1302,11 +1287,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf)
} }
// Get the key version. // Get the key version.
if (s.seek(0x08) < 0) CHECK_ASSERTION(s.seek(0x08) != -1);
{
LOG_ERROR(LOADER, "Seeking debug (S)ELF at 0x08 failed.");
return false;
}
u16 key_version; u16 key_version;
s.read(&key_version, sizeof(key_version)); s.read(&key_version, sizeof(key_version));
@ -1317,11 +1298,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf)
LOG_WARNING(LOADER, "Debug SELF detected! Removing fake header..."); LOG_WARNING(LOADER, "Debug SELF detected! Removing fake header...");
// Get the real elf offset. // Get the real elf offset.
if (s.seek(0x10) < 0) CHECK_ASSERTION(s.seek(0x10) != -1);
{
LOG_ERROR(LOADER, "Seeking debug (S)ELF at 0x10 failed.");
return false;
}
u64 elf_offset; u64 elf_offset;
s.read(&elf_offset, sizeof(elf_offset)); s.read(&elf_offset, sizeof(elf_offset));
@ -1329,11 +1306,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf)
// Start at the real elf offset. // Start at the real elf offset.
elf_offset = swap64(elf_offset); elf_offset = swap64(elf_offset);
if (s.seek(elf_offset) < 0) CHECK_ASSERTION(s.seek(elf_offset) != -1);
{
LOG_ERROR(LOADER, "Seeking debug (S)ELF at %u failed.", elf_offset);
return false;
}
// Write the real ELF file back. // Write the real ELF file back.
fs::file e(elf, fom::write | fom::create | fom::trunc); fs::file e(elf, fom::write | fom::create | fom::trunc);

View File

@ -19,7 +19,7 @@ void vfsHDDManager::CreateEntry(vfsHDD_Entry& entry)
CreateBlock(entry); CreateBlock(entry);
} }
s32 vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size) void vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size)
{ {
fs::file f(path, fom::write | fom::create | fom::trunc); fs::file f(path, fom::write | fom::create | fom::trunc);
@ -48,15 +48,9 @@ s32 vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size)
u8 null = 0; u8 null = 0;
if (f.seek(hdr.block_count * hdr.block_size - sizeof(null)) < HDD_OK) CHECK_ASSERTION(f.seek(hdr.block_count * hdr.block_size - sizeof(null)) != -1);
{
LOG_ERROR(HLE, "CreateHDD seek to %u failed.", hdr.block_count * hdr.block_size - sizeof(null));
return HDD_SEEK_FAILURE;
}
f.write(&null, sizeof(null)); f.write(&null, sizeof(null));
return HDD_OK;
} }
void vfsHDDManager::Format() void vfsHDDManager::Format()
@ -76,11 +70,7 @@ bool vfsHDDFile::goto_block(u64 n)
return false; return false;
} }
if (m_hdd.Seek(m_info.data_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(m_info.data_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "goto_block seek to %u failed.", m_info.data_block * m_hdd_info.block_size);
return false;
}
block_info.next_block = m_info.data_block; block_info.next_block = m_info.data_block;
@ -91,11 +81,7 @@ bool vfsHDDFile::goto_block(u64 n)
return false; return false;
} }
if (m_hdd.Seek(block_info.next_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block_info.next_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "goto_block seek to %u failed.", block_info.next_block * m_hdd_info.block_size);
return false;
}
m_hdd.Read(&block_info, sizeof(vfsHDD_Block)); m_hdd.Read(&block_info, sizeof(vfsHDD_Block));
} }
@ -117,99 +103,57 @@ void vfsHDDFile::RemoveBlocks(u64 start_block)
} }
} }
s32 vfsHDDFile::WriteBlock(u64 block, const vfsHDD_Block& data) void vfsHDDFile::WriteBlock(u64 block, const vfsHDD_Block& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "WriteBlock seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Write(&data, sizeof(vfsHDD_Block)); m_hdd.Write(&data, sizeof(vfsHDD_Block));
return HDD_OK;
} }
s32 vfsHDDFile::ReadBlock(u64 block, vfsHDD_Block& data) void vfsHDDFile::ReadBlock(u64 block, vfsHDD_Block& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "ReadBlock seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(&data, sizeof(vfsHDD_Block)); m_hdd.Read(&data, sizeof(vfsHDD_Block));
return HDD_OK;
} }
s32 vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data) void vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Write(&data, sizeof(vfsHDD_Entry)); m_hdd.Write(&data, sizeof(vfsHDD_Entry));
return HDD_OK;
} }
s32 vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data) void vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(&data, sizeof(vfsHDD_Entry)); m_hdd.Read(&data, sizeof(vfsHDD_Entry));
return HDD_OK;
} }
s32 vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name) void vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(&data, sizeof(vfsHDD_Entry)); m_hdd.Read(&data, sizeof(vfsHDD_Entry));
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd.Read(&name.front(), GetMaxNameLen()); m_hdd.Read(&name.front(), GetMaxNameLen());
return HDD_OK;
} }
s32 vfsHDDFile::ReadEntry(u64 block, std::string& name) void vfsHDDFile::ReadEntry(u64 block, std::string& name)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) != -1);
{
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size + sizeof(vfsHDD_Entry));
return HDD_SEEK_FAILURE;
}
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd.Read(&name.front(), GetMaxNameLen()); m_hdd.Read(&name.front(), GetMaxNameLen());
return HDD_OK;
} }
s32 vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name) void vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Write(&data, sizeof(vfsHDD_Entry)); m_hdd.Write(&data, sizeof(vfsHDD_Entry));
m_hdd.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1)); m_hdd.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1));
return HDD_OK;
} }
void vfsHDDFile::Open(u64 info_block) void vfsHDDFile::Open(u64 info_block)
@ -248,19 +192,13 @@ bool vfsHDDFile::Seek(u64 pos)
return true; return true;
} }
s32 vfsHDDFile::SaveInfo() void vfsHDDFile::SaveInfo()
{ {
m_hdd.Seek(m_info_block * m_hdd_info.block_size); CHECK_ASSERTION(m_hdd.Seek(m_info_block * m_hdd_info.block_size) != -1);
if (m_hdd.Seek(m_info_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(m_info_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "SaveInfo seek to %u failed.", m_info_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Write(&m_info, sizeof(vfsHDD_Entry)); m_hdd.Write(&m_info, sizeof(vfsHDD_Entry));
return HDD_OK;
} }
u64 vfsHDDFile::Read(void* dst, u64 size) u64 vfsHDDFile::Read(void* dst, u64 size)
@ -275,19 +213,11 @@ u64 vfsHDDFile::Read(void* dst, u64 size)
vfsHDD_Block cur_block_info; vfsHDD_Block cur_block_info;
if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "Read seek to %u failed.", m_cur_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block)); m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block));
if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) != -1);
{
LOG_ERROR(HLE, "Read seek to %u failed.", m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(dst, rsize); m_hdd.Read(dst, rsize);
size -= rsize; size -= rsize;
@ -309,11 +239,7 @@ u64 vfsHDDFile::Read(void* dst, u64 size)
m_cur_block = cur_block_info.next_block; m_cur_block = cur_block_info.next_block;
rsize = std::min<u64>(block_size, size); rsize = std::min<u64>(block_size, size);
if (m_hdd.Seek(cur_block_info.next_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(cur_block_info.next_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "Read seek to %u failed.", cur_block_info.next_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block)); m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block));
@ -365,11 +291,7 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
if (wsize) if (wsize)
{ {
if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) != -1);
{
LOG_ERROR(HLE, "Write seek to %u failed.", m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position);
return HDD_SEEK_FAILURE;
}
m_hdd.Write(src, wsize); m_hdd.Write(src, wsize);
size -= wsize; size -= wsize;
@ -401,11 +323,7 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
block_info.next_block = m_cur_block; block_info.next_block = m_cur_block;
if (m_hdd.Seek(last_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(last_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "Write seek to %u failed.", last_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block)) if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block))
{ {
@ -416,11 +334,7 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
block_info.next_block = 0; block_info.next_block = 0;
if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "Write seek to %u failed.", m_cur_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block)) if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block))
{ {
@ -473,11 +387,7 @@ vfsHDD::vfsHDD(vfsDevice* device, const std::string& hdd_path)
m_hdd_info.block_size = 2048; m_hdd_info.block_size = 2048;
} }
if (m_hdd_file.Seek(m_cur_dir_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(m_cur_dir_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "vfsHDD initialization seek to %u failed.", m_cur_dir_block * m_hdd_info.block_size);
return;
}
m_hdd_file.Read(&m_cur_dir, sizeof(vfsHDD_Entry)); m_hdd_file.Read(&m_cur_dir, sizeof(vfsHDD_Entry));
} }
@ -513,27 +423,26 @@ s32 vfsHDD::OpenDir(const std::string& name)
{ {
LOG_WARNING(HLE, "OpenDir(%s)", name.c_str()); LOG_WARNING(HLE, "OpenDir(%s)", name.c_str());
u64 entry_block; u64 entry_block;
if (!SearchEntry(name, entry_block)) if (!SearchEntry(name, entry_block))
{ {
LOG_ERROR(HLE, "OpenDir could not find the entry. (%s)", name); return -1;
return HDD_ENTRY_NOT_FOUND;
} }
if (m_hdd_file.Seek(entry_block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(entry_block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "OpenDir seek to %u failed.", entry_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
vfsHDD_Entry entry; vfsHDD_Entry entry;
m_hdd_file.Read(&entry, sizeof(vfsHDD_Entry)); m_hdd_file.Read(&entry, sizeof(vfsHDD_Entry));
if (entry.type == vfsHDD_Entry_File) if (entry.type == vfsHDD_Entry_File)
{
return 1; return 1;
}
m_cur_dir_block = entry.data_block; m_cur_dir_block = entry.data_block;
ReadEntry(m_cur_dir_block, m_cur_dir); ReadEntry(m_cur_dir_block, m_cur_dir);
return HDD_OK; return 0;
} }
bool vfsHDD::Rename(const std::string& from, const std::string& to) bool vfsHDD::Rename(const std::string& from, const std::string& to)
@ -568,99 +477,57 @@ u64 vfsHDD::FindFreeBlock()
return 0; return 0;
} }
s32 vfsHDD::WriteBlock(u64 block, const vfsHDD_Block& data) void vfsHDD::WriteBlock(u64 block, const vfsHDD_Block& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "WriteBlock seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd_file.Write(&data, sizeof(vfsHDD_Block)); m_hdd_file.Write(&data, sizeof(vfsHDD_Block));
return HDD_OK;
} }
s32 vfsHDD::ReadBlock(u64 block, vfsHDD_Block& data) void vfsHDD::ReadBlock(u64 block, vfsHDD_Block& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "ReadBlock seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd_file.Read(&data, sizeof(vfsHDD_Block)); m_hdd_file.Read(&data, sizeof(vfsHDD_Block));
return HDD_OK;
} }
s32 vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data) void vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd_file.Write(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Write(&data, sizeof(vfsHDD_Entry));
return HDD_OK;
} }
s32 vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data) void vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd_file.Read(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Read(&data, sizeof(vfsHDD_Entry));
return HDD_OK;
} }
s32 vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name) void vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd_file.Read(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Read(&data, sizeof(vfsHDD_Entry));
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd_file.Read(&name.front(), GetMaxNameLen()); m_hdd_file.Read(&name.front(), GetMaxNameLen());
return HDD_OK;
} }
s32 vfsHDD::ReadEntry(u64 block, std::string& name) void vfsHDD::ReadEntry(u64 block, std::string& name)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) != -1);
{
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size + sizeof(vfsHDD_Entry));
return HDD_SEEK_FAILURE;
}
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd_file.Read(&name.front(), GetMaxNameLen()); m_hdd_file.Read(&name.front(), GetMaxNameLen());
return HDD_OK;
} }
s32 vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name) void vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK) CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
{
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd_file.Write(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Write(&data, sizeof(vfsHDD_Entry));
m_hdd_file.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1)); m_hdd_file.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1));
return HDD_OK;
} }
bool vfsHDD::Create(vfsHDD_EntryType type, const std::string& name) bool vfsHDD::Create(vfsHDD_EntryType type, const std::string& name)
@ -793,13 +660,13 @@ bool vfsHDD::Open(const std::string& path, u32 mode)
{ {
if (pos - from > 1) if (pos - from > 1)
{ {
int res = OpenDir(std::string(s + from, pos)); s32 res = OpenDir(std::string(s + from, pos));
if (res == -1) if (res == -1)
{ {
return false; return false;
} }
else if (res == 1)
if (res == 1)
{ {
file_pos = from; file_pos = from;
} }

View File

@ -5,14 +5,6 @@
static const u64 g_hdd_magic = *(u64*)"PS3eHDD\0"; static const u64 g_hdd_magic = *(u64*)"PS3eHDD\0";
static const u16 g_hdd_version = 0x0001; static const u16 g_hdd_version = 0x0001;
// Return codes
enum
{
HDD_OK = 0,
HDD_SEEK_FAILURE = 0x400,
HDD_ENTRY_NOT_FOUND = 0x401,
};
struct vfsHDD_Block struct vfsHDD_Block
{ {
struct struct
@ -55,7 +47,7 @@ public:
static void CreateEntry(vfsHDD_Entry& entry); static void CreateEntry(vfsHDD_Entry& entry);
static s32 CreateHDD(const std::string& path, u64 size, u64 block_size); static void CreateHDD(const std::string& path, u64 size, u64 block_size);
void Format(); void Format();
@ -76,19 +68,19 @@ class vfsHDDFile
void RemoveBlocks(u64 start_block); void RemoveBlocks(u64 start_block);
s32 WriteBlock(u64 block, const vfsHDD_Block& data); void WriteBlock(u64 block, const vfsHDD_Block& data);
s32 ReadBlock(u64 block, vfsHDD_Block& data); void ReadBlock(u64 block, vfsHDD_Block& data);
s32 WriteEntry(u64 block, const vfsHDD_Entry& data); void WriteEntry(u64 block, const vfsHDD_Entry& data);
s32 ReadEntry(u64 block, vfsHDD_Entry& data); void ReadEntry(u64 block, vfsHDD_Entry& data);
s32 ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name); void ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name);
s32 ReadEntry(u64 block, std::string& name); void ReadEntry(u64 block, std::string& name);
s32 WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name); void WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name);
force_inline u32 GetMaxNameLen() const force_inline u32 GetMaxNameLen() const
{ {
@ -122,7 +114,7 @@ public:
return m_cur_block * m_hdd_info.block_size + m_position; // ??? return m_cur_block * m_hdd_info.block_size + m_position; // ???
} }
s32 SaveInfo(); void SaveInfo();
u64 Read(void* dst, u64 size); u64 Read(void* dst, u64 size);
@ -170,19 +162,19 @@ public:
u64 FindFreeBlock(); u64 FindFreeBlock();
s32 WriteBlock(u64 block, const vfsHDD_Block& data); void WriteBlock(u64 block, const vfsHDD_Block& data);
s32 ReadBlock(u64 block, vfsHDD_Block& data); void ReadBlock(u64 block, vfsHDD_Block& data);
s32 WriteEntry(u64 block, const vfsHDD_Entry& data); void WriteEntry(u64 block, const vfsHDD_Entry& data);
s32 ReadEntry(u64 block, vfsHDD_Entry& data); void ReadEntry(u64 block, vfsHDD_Entry& data);
s32 ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name); void ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name);
s32 ReadEntry(u64 block, std::string& name); void ReadEntry(u64 block, std::string& name);
s32 WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name); void WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name);
bool Create(vfsHDD_EntryType type, const std::string& name); bool Create(vfsHDD_EntryType type, const std::string& name);

View File

@ -87,7 +87,7 @@ public:
if (!getRealAddr(addr, realAddr)) if (!getRealAddr(addr, realAddr))
{ {
LOG_ERROR(HLE, "Getting the real address failed. (addr=%u)", addr); LOG_ERROR(HLE, "Getting the real address failed. (addr=0x%x)", addr);
return 0; return 0;
} }

View File

@ -265,11 +265,11 @@ s32 cellFsReadWithOffset(u32 fd, u64 offset, vm::ptr<void> buf, u64 buffer_size,
const auto old_position = file->file->Tell(); const auto old_position = file->file->Tell();
file->file->Seek(offset); CHECK_ASSERTION(file->file->Seek(offset) != -1);
const auto read = file->file->Read(buf.get_ptr(), buffer_size); const auto read = file->file->Read(buf.get_ptr(), buffer_size);
file->file->Seek(old_position); CHECK_ASSERTION(file->file->Seek(old_position) != -1);
if (nread) if (nread)
{ {
@ -296,11 +296,11 @@ s32 cellFsWriteWithOffset(u32 fd, u64 offset, vm::cptr<void> buf, u64 data_size,
const auto old_position = file->file->Tell(); const auto old_position = file->file->Tell();
file->file->Seek(offset); CHECK_ASSERTION(file->file->Seek(offset) != -1);
const auto written = file->file->Write(buf.get_ptr(), data_size); const auto written = file->file->Write(buf.get_ptr(), data_size);
file->file->Seek(old_position); CHECK_ASSERTION(file->file->Seek(old_position) != -1);
if (nwrite) if (nwrite)
{ {
@ -508,9 +508,9 @@ s32 cellFsStReadStart(u32 fd, u64 offset, u64 size)
// read data // read data
auto old = file->file->Tell(); auto old = file->file->Tell();
file->file->Seek(offset + file->st_total_read); CHECK_ASSERTION(file->file->Seek(offset + file->st_total_read) != -1);
auto res = file->file->Read(vm::base(position), file->st_block_size); auto res = file->file->Read(vm::base(position), file->st_block_size);
file->file->Seek(old); CHECK_ASSERTION(file->file->Seek(old) != -1);
// notify // notify
file->st_total_read += res; file->st_total_read += res;
@ -803,17 +803,27 @@ s32 sdata_unpack(const std::string& packed_file, const std::string& unpacked_fil
} }
if (flags & 0x20) if (flags & 0x20)
packed_stream->Seek(0x100); {
CHECK_ASSERTION(packed_stream->Seek(0x100) != -1);
}
else else
packed_stream->Seek(startOffset); {
CHECK_ASSERTION(packed_stream->Seek(startOffset) != -1);
}
for (u32 i = 0; i < blockCount; i++) for (u32 i = 0; i < blockCount; i++)
{ {
if (flags & 0x20) if (flags & 0x20)
packed_stream->Seek(packed_stream->Tell() + t1); {
s64 cur;
CHECK_ASSERTION((cur = packed_stream->Tell()) != -1);
CHECK_ASSERTION(packed_stream->Seek(cur + t1) != -1);
}
if (!(blockCount - i - 1)) if (!(blockCount - i - 1))
{
blockSize = (u32)(filesizeOutput - i * blockSize); blockSize = (u32)(filesizeOutput - i * blockSize);
}
packed_stream->Read(buffer + 256, blockSize); packed_stream->Read(buffer + 256, blockSize);
unpacked_stream->Write(buffer + 256, blockSize); unpacked_stream->Write(buffer + 256, blockSize);
@ -883,11 +893,11 @@ void fsAio(vm::ptr<CellFsAio> aio, bool write, s32 xid, fs_aio_cb_t func)
const auto old_position = file->file->Tell(); const auto old_position = file->file->Tell();
file->file->Seek(aio->offset); CHECK_ASSERTION(file->file->Seek(aio->offset) != -1);
result = write ? file->file->Write(aio->buf.get_ptr(), aio->size) : file->file->Read(aio->buf.get_ptr(), aio->size); result = write ? file->file->Write(aio->buf.get_ptr(), aio->size) : file->file->Read(aio->buf.get_ptr(), aio->size);
file->file->Seek(old_position); CHECK_ASSERTION(file->file->Seek(old_position) != -1);
} }
// should be executed directly by FS AIO thread // should be executed directly by FS AIO thread

View File

@ -344,17 +344,14 @@ s32 CalculateSurfaceByteSize(u32 mode, CellRescDsts *dsts)
s32 CalculateMaxColorBuffersSize() s32 CalculateMaxColorBuffersSize()
{ {
s32 index, oneBufSize, bufNum, totalBufSize, maxBufSize; s32 oneBufSize, bufNum, totalBufSize, maxBufSize;
maxBufSize = 0; maxBufSize = 0;
for (u32 bufMode = CELL_RESC_720x480; bufMode <= CELL_RESC_1920x1080; bufMode <<= 1) for (u32 bufMode = CELL_RESC_720x480; bufMode <= CELL_RESC_1920x1080; bufMode <<= 1)
{ {
if (s_rescInternalInstance->m_initConfig.supportModes & bufMode) if (s_rescInternalInstance->m_initConfig.supportModes & bufMode)
{ {
if ((index = GetRescDestsIndex(bufMode)) != 0) oneBufSize = CalculateSurfaceByteSize(bufMode, &(s_rescInternalInstance->m_rescDsts[GetRescDestsIndex(bufMode)]));
{
oneBufSize = CalculateSurfaceByteSize(bufMode, &(s_rescInternalInstance->m_rescDsts[index]));
}
bufNum = cellRescGetNumColorBuffers(bufMode, s_rescInternalInstance->m_initConfig.palTemporalMode, 0); bufNum = cellRescGetNumColorBuffers(bufMode, s_rescInternalInstance->m_initConfig.palTemporalMode, 0);
totalBufSize = oneBufSize * bufNum; totalBufSize = oneBufSize * bufNum;
maxBufSize = (maxBufSize > totalBufSize) ? maxBufSize : totalBufSize; maxBufSize = (maxBufSize > totalBufSize) ? maxBufSize : totalBufSize;

View File

@ -79,7 +79,7 @@ void AutoPauseManagerDialog::LoadEntries(void)
u32 num; u32 num;
size_t fmax = list.size(); size_t fmax = list.size();
size_t fcur = 0; size_t fcur = 0;
list.seek(0); CHECK_ASSERTION(list.seek(0) != -1);
while (fcur <= fmax - sizeof(u32)) while (fcur <= fmax - sizeof(u32))
{ {
list.read(&num, sizeof(u32)); list.read(&num, sizeof(u32));
@ -99,7 +99,7 @@ void AutoPauseManagerDialog::SaveEntries(void)
fs::file list("pause.bin", fom::write | fom::create | fom::trunc); fs::file list("pause.bin", fom::write | fom::create | fom::trunc);
//System calls ID and Function calls ID are all u32 iirc. //System calls ID and Function calls ID are all u32 iirc.
u32 num = 0; u32 num = 0;
list.seek(0); CHECK_ASSERTION(list.seek(0) != -1);
for (size_t i = 0; i < m_entries.size(); ++i) for (size_t i = 0; i < m_entries.size(); ++i)
{ {
if (num == 0xFFFFFFFF) continue; if (num == 0xFFFFFFFF) continue;

View File

@ -263,11 +263,7 @@ void MainFrame::InstallPkg(wxCommandEvent& WXUNUSED(event))
// Fetch title ID from the header // Fetch title ID from the header
char title_id[10] = "?????????"; char title_id[10] = "?????????";
if (!pkg_f.seek(55)) CHECK_ASSERTION(pkg_f.seek(55) != -1);
{
LOG_ERROR(LOADER, "PKG: Failed to seek offset 55.");
return;
}
pkg_f.read(title_id, 9); pkg_f.read(title_id, 9);
pkg_f.seek(0); pkg_f.seek(0);