mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-29 23:32:23 +00:00
fusee_cpp: improve/fix file-based emummc
This commit is contained in:
parent
2247f97cdc
commit
320f0bbcfd
2 changed files with 21 additions and 16 deletions
|
@ -23,7 +23,7 @@ namespace ams::fs {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr size_t MaxFiles = 8;
|
constexpr size_t MaxFiles = 8 + 64;
|
||||||
constexpr size_t MaxDirectories = 2;
|
constexpr size_t MaxDirectories = 2;
|
||||||
|
|
||||||
constinit bool g_is_sd_mounted = false;
|
constinit bool g_is_sd_mounted = false;
|
||||||
|
|
|
@ -99,33 +99,38 @@ namespace ams::nxboot {
|
||||||
class EmummcFileStorage : public fs::IStorage {
|
class EmummcFileStorage : public fs::IStorage {
|
||||||
private:
|
private:
|
||||||
s64 m_file_size;
|
s64 m_file_size;
|
||||||
fs::FileHandle m_handle;
|
fs::FileHandle m_handles[64];
|
||||||
int m_id;
|
bool m_open[64];
|
||||||
int m_file_path_ofs;
|
int m_file_path_ofs;
|
||||||
private:
|
private:
|
||||||
void SwitchFile(int id) {
|
void EnsureFile(int id) {
|
||||||
if (m_id != id) {
|
if (!m_open[id]) {
|
||||||
fs::CloseFile(m_handle);
|
|
||||||
|
|
||||||
/* Update path. */
|
/* Update path. */
|
||||||
g_emummc_path[m_file_path_ofs + 1] = '0' + (id % 10);
|
g_emummc_path[m_file_path_ofs + 1] = '0' + (id % 10);
|
||||||
g_emummc_path[m_file_path_ofs + 0] = '0' + (id / 10);
|
g_emummc_path[m_file_path_ofs + 0] = '0' + (id / 10);
|
||||||
|
|
||||||
/* Open new file. */
|
/* Open new file. */
|
||||||
const Result result = fs::OpenFile(std::addressof(m_handle), g_emummc_path, fs::OpenMode_Read);
|
const Result result = fs::OpenFile(m_handles + id, g_emummc_path, fs::OpenMode_Read);
|
||||||
if (R_FAILED(result)) {
|
if (R_FAILED(result)) {
|
||||||
ShowFatalError("Failed to open emummc user %02d file: 0x%08" PRIx32 "!\n", id, result.GetValue());
|
ShowFatalError("Failed to open emummc user %02d file: 0x%08" PRIx32 "!\n", id, result.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_id = id;
|
m_open[id] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
EmummcFileStorage(fs::FileHandle user00, int ofs) : m_handle(user00), m_id(0), m_file_path_ofs(ofs) {
|
EmummcFileStorage(fs::FileHandle user00, int ofs) : m_file_path_ofs(ofs) {
|
||||||
const Result result = fs::GetFileSize(std::addressof(m_file_size), m_handle);
|
const Result result = fs::GetFileSize(std::addressof(m_file_size), user00);
|
||||||
if (R_FAILED(result)) {
|
if (R_FAILED(result)) {
|
||||||
ShowFatalError("Failed to get emummc file size: 0x%08" PRIx32 "!\n", result.GetValue());
|
ShowFatalError("Failed to get emummc file size: 0x%08" PRIx32 "!\n", result.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < util::size(m_handles); ++i) {
|
||||||
|
m_open[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_handles[0] = user00;
|
||||||
|
m_open[0] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||||
|
@ -135,12 +140,12 @@ namespace ams::nxboot {
|
||||||
u8 *cur_dst = static_cast<u8 *>(buffer);
|
u8 *cur_dst = static_cast<u8 *>(buffer);
|
||||||
|
|
||||||
for (/* ... */; size > 0; ++file) {
|
for (/* ... */; size > 0; ++file) {
|
||||||
/* Switch to the current file. */
|
/* Ensure the current file is open. */
|
||||||
SwitchFile(file);
|
EnsureFile(file);
|
||||||
|
|
||||||
/* Perform the current read. */
|
/* Perform the current read. */
|
||||||
const size_t cur_size = std::min<size_t>(m_file_size - subofs, size);
|
const size_t cur_size = std::min<size_t>(m_file_size - subofs, size);
|
||||||
R_TRY(fs::ReadFile(m_handle, subofs, cur_dst, cur_size));
|
R_TRY(fs::ReadFile(m_handles[file], subofs, cur_dst, cur_size));
|
||||||
|
|
||||||
/* Advance. */
|
/* Advance. */
|
||||||
cur_dst += cur_size;
|
cur_dst += cur_size;
|
||||||
|
@ -152,7 +157,7 @@ namespace ams::nxboot {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Result Flush() override {
|
virtual Result Flush() override {
|
||||||
return fs::FlushFile(m_handle);
|
return fs::ResultUnsupportedOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Result GetSize(s64 *out) override {
|
virtual Result GetSize(s64 *out) override {
|
||||||
|
@ -360,7 +365,7 @@ namespace ams::nxboot {
|
||||||
|
|
||||||
/* Append emmc. */
|
/* Append emmc. */
|
||||||
std::memcpy(g_emummc_path + len, "/eMMC", 6);
|
std::memcpy(g_emummc_path + len, "/eMMC", 6);
|
||||||
len += 6;
|
len += 5;
|
||||||
|
|
||||||
/* Open boot0. */
|
/* Open boot0. */
|
||||||
fs::FileHandle boot0_file;
|
fs::FileHandle boot0_file;
|
||||||
|
|
Loading…
Reference in a new issue