strat: use m_ for member variables
This commit is contained in:
@@ -50,18 +50,18 @@ namespace ams::fs {
|
||||
Result HierarchicalRomFileTable::Initialize(SubStorage dir_bucket, SubStorage dir_entry, SubStorage file_bucket, SubStorage file_entry) {
|
||||
s64 dir_bucket_size;
|
||||
R_TRY(dir_bucket.GetSize(std::addressof(dir_bucket_size)));
|
||||
R_TRY(this->dir_table.Initialize(dir_bucket, DirectoryEntryMapTable::QueryBucketCount(dir_bucket_size), dir_entry));
|
||||
R_TRY(m_dir_table.Initialize(dir_bucket, DirectoryEntryMapTable::QueryBucketCount(dir_bucket_size), dir_entry));
|
||||
|
||||
s64 file_bucket_size;
|
||||
R_TRY(file_bucket.GetSize(std::addressof(file_bucket_size)));
|
||||
R_TRY(this->file_table.Initialize(file_bucket, FileEntryMapTable::QueryBucketCount(file_bucket_size), file_entry));
|
||||
R_TRY(m_file_table.Initialize(file_bucket, FileEntryMapTable::QueryBucketCount(file_bucket_size), file_entry));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void HierarchicalRomFileTable::Finalize() {
|
||||
this->dir_table.Finalize();
|
||||
this->file_table.Finalize();
|
||||
m_dir_table.Finalize();
|
||||
m_file_table.Finalize();
|
||||
}
|
||||
|
||||
Result HierarchicalRomFileTable::CreateRootDirectory() {
|
||||
@@ -74,7 +74,7 @@ namespace ams::fs {
|
||||
.dir = InvalidPosition,
|
||||
.file = InvalidPosition,
|
||||
};
|
||||
return this->dir_table.Add(std::addressof(root_pos), root_key, root_entry);
|
||||
return m_dir_table.Add(std::addressof(root_pos), root_key, root_entry);
|
||||
}
|
||||
|
||||
Result HierarchicalRomFileTable::CreateDirectory(RomDirectoryId *out, const RomPathChar *path, const DirectoryInfo &info) {
|
||||
@@ -95,7 +95,7 @@ namespace ams::fs {
|
||||
AMS_UNUSED(info);
|
||||
|
||||
Position new_pos = 0;
|
||||
R_TRY_CATCH(this->dir_table.Add(std::addressof(new_pos), new_key, new_entry)) {
|
||||
R_TRY_CATCH(m_dir_table.Add(std::addressof(new_pos), new_key, new_entry)) {
|
||||
R_CONVERT(fs::ResultDbmKeyFull, fs::ResultDbmDirectoryEntryFull())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
@@ -104,18 +104,18 @@ namespace ams::fs {
|
||||
if (parent_entry.dir == InvalidPosition) {
|
||||
parent_entry.dir = new_pos;
|
||||
|
||||
R_TRY(this->dir_table.SetByPosition(new_key.key.parent, parent_entry));
|
||||
R_TRY(m_dir_table.SetByPosition(new_key.key.parent, parent_entry));
|
||||
} else {
|
||||
Position cur_pos = parent_entry.dir;
|
||||
while (true) {
|
||||
RomEntryKey cur_key = {};
|
||||
RomDirectoryEntry cur_entry = {};
|
||||
R_TRY(this->dir_table.GetByPosition(std::addressof(cur_key), std::addressof(cur_entry), cur_pos));
|
||||
R_TRY(m_dir_table.GetByPosition(std::addressof(cur_key), std::addressof(cur_entry), cur_pos));
|
||||
|
||||
if (cur_entry.next == InvalidPosition) {
|
||||
cur_entry.next = new_pos;
|
||||
|
||||
R_TRY(this->dir_table.SetByPosition(cur_pos, cur_entry));
|
||||
R_TRY(m_dir_table.SetByPosition(cur_pos, cur_entry));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace ams::fs {
|
||||
};
|
||||
|
||||
Position new_pos = 0;
|
||||
R_TRY_CATCH(this->file_table.Add(std::addressof(new_pos), new_key, new_entry)) {
|
||||
R_TRY_CATCH(m_file_table.Add(std::addressof(new_pos), new_key, new_entry)) {
|
||||
R_CONVERT(fs::ResultDbmKeyFull, fs::ResultDbmFileEntryFull())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
@@ -151,18 +151,18 @@ namespace ams::fs {
|
||||
if (parent_entry.file == InvalidPosition) {
|
||||
parent_entry.file = new_pos;
|
||||
|
||||
R_TRY(this->dir_table.SetByPosition(new_key.key.parent, parent_entry));
|
||||
R_TRY(m_dir_table.SetByPosition(new_key.key.parent, parent_entry));
|
||||
} else {
|
||||
Position cur_pos = parent_entry.file;
|
||||
while (true) {
|
||||
RomEntryKey cur_key = {};
|
||||
RomFileEntry cur_entry = {};
|
||||
R_TRY(this->file_table.GetByPosition(std::addressof(cur_key), std::addressof(cur_entry), cur_pos));
|
||||
R_TRY(m_file_table.GetByPosition(std::addressof(cur_key), std::addressof(cur_entry), cur_pos));
|
||||
|
||||
if (cur_entry.next == InvalidPosition) {
|
||||
cur_entry.next = new_pos;
|
||||
|
||||
R_TRY(this->file_table.SetByPosition(cur_pos, cur_entry));
|
||||
R_TRY(m_file_table.SetByPosition(cur_pos, cur_entry));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace ams::fs {
|
||||
RomEntryKey key = {};
|
||||
RomDirectoryEntry entry = {};
|
||||
size_t aux_size = 0;
|
||||
R_TRY(this->dir_table.GetByPosition(std::addressof(key), std::addressof(entry), out, std::addressof(aux_size), find->next_dir));
|
||||
R_TRY(m_dir_table.GetByPosition(std::addressof(key), std::addressof(entry), out, std::addressof(aux_size), find->next_dir));
|
||||
AMS_ASSERT(aux_size / sizeof(RomPathChar) <= RomPathTool::MaxPathLength);
|
||||
|
||||
out[aux_size / sizeof(RomPathChar)] = RomStringTraits::NullTerminator;
|
||||
@@ -305,7 +305,7 @@ namespace ams::fs {
|
||||
RomEntryKey key = {};
|
||||
RomFileEntry entry = {};
|
||||
size_t aux_size = 0;
|
||||
R_TRY(this->file_table.GetByPosition(std::addressof(key), std::addressof(entry), out, std::addressof(aux_size), find->next_file));
|
||||
R_TRY(m_file_table.GetByPosition(std::addressof(key), std::addressof(entry), out, std::addressof(aux_size), find->next_file));
|
||||
AMS_ASSERT(aux_size / sizeof(RomPathChar) <= RomPathTool::MaxPathLength);
|
||||
|
||||
out[aux_size / sizeof(RomPathChar)] = RomStringTraits::NullTerminator;
|
||||
@@ -318,8 +318,8 @@ namespace ams::fs {
|
||||
AMS_ASSERT(out_dir_entry_size != nullptr);
|
||||
AMS_ASSERT(out_file_entry_size != nullptr);
|
||||
|
||||
*out_dir_entry_size = this->dir_table.GetTotalEntrySize();
|
||||
*out_file_entry_size = this->file_table.GetTotalEntrySize();
|
||||
*out_dir_entry_size = m_dir_table.GetTotalEntrySize();
|
||||
*out_file_entry_size = m_file_table.GetTotalEntrySize();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace ams::fs {
|
||||
|
||||
RomEntryKey gp_key = {};
|
||||
RomDirectoryEntry gp_entry = {};
|
||||
R_TRY(this->dir_table.GetByPosition(std::addressof(gp_key), std::addressof(gp_entry), pos));
|
||||
R_TRY(m_dir_table.GetByPosition(std::addressof(gp_key), std::addressof(gp_entry), pos));
|
||||
out_dir_key->key.parent = gp_key.parent;
|
||||
|
||||
R_TRY(RomPathTool::GetParentDirectoryName(std::addressof(out_dir_key->name), name, path));
|
||||
@@ -458,7 +458,7 @@ namespace ams::fs {
|
||||
{
|
||||
Position pos = InvalidPosition;
|
||||
RomDirectoryEntry entry = {};
|
||||
const Result get_res = this->dir_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
const Result get_res = m_dir_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
if (!fs::ResultDbmKeyNotFound::Includes(get_res)) {
|
||||
R_TRY(get_res);
|
||||
return if_exists;
|
||||
@@ -469,7 +469,7 @@ namespace ams::fs {
|
||||
{
|
||||
Position pos = InvalidPosition;
|
||||
RomFileEntry entry = {};
|
||||
const Result get_res = this->file_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
const Result get_res = m_file_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
if (!fs::ResultDbmKeyNotFound::Includes(get_res)) {
|
||||
R_TRY(get_res);
|
||||
return if_exists;
|
||||
@@ -482,13 +482,13 @@ namespace ams::fs {
|
||||
AMS_ASSERT(out_pos != nullptr);
|
||||
AMS_ASSERT(out_entry != nullptr);
|
||||
|
||||
const Result dir_res = this->dir_table.Get(out_pos, out_entry, key);
|
||||
const Result dir_res = m_dir_table.Get(out_pos, out_entry, key);
|
||||
R_UNLESS(R_FAILED(dir_res), dir_res);
|
||||
R_UNLESS(fs::ResultDbmKeyNotFound::Includes(dir_res), dir_res);
|
||||
|
||||
Position pos = 0;
|
||||
RomFileEntry entry = {};
|
||||
const Result file_res = this->file_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
const Result file_res = m_file_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
R_UNLESS(R_FAILED(file_res), fs::ResultDbmInvalidOperation());
|
||||
R_UNLESS(!fs::ResultDbmKeyNotFound::Includes(file_res), fs::ResultDbmDirectoryNotFound());
|
||||
return file_res;
|
||||
@@ -499,12 +499,12 @@ namespace ams::fs {
|
||||
Position pos = DirectoryIdToPosition(id);
|
||||
|
||||
RomEntryKey key = {};
|
||||
const Result dir_res = this->dir_table.GetByPosition(std::addressof(key), out_entry, pos);
|
||||
const Result dir_res = m_dir_table.GetByPosition(std::addressof(key), out_entry, pos);
|
||||
R_UNLESS(R_FAILED(dir_res), dir_res);
|
||||
R_UNLESS(fs::ResultDbmKeyNotFound::Includes(dir_res), dir_res);
|
||||
|
||||
RomFileEntry entry = {};
|
||||
const Result file_res = this->file_table.GetByPosition(std::addressof(key), std::addressof(entry), pos);
|
||||
const Result file_res = m_file_table.GetByPosition(std::addressof(key), std::addressof(entry), pos);
|
||||
R_UNLESS(R_FAILED(file_res), fs::ResultDbmInvalidOperation());
|
||||
R_UNLESS(!fs::ResultDbmKeyNotFound::Includes(file_res), fs::ResultDbmDirectoryNotFound());
|
||||
return file_res;
|
||||
@@ -514,13 +514,13 @@ namespace ams::fs {
|
||||
AMS_ASSERT(out_pos != nullptr);
|
||||
AMS_ASSERT(out_entry != nullptr);
|
||||
|
||||
const Result file_res = this->file_table.Get(out_pos, out_entry, key);
|
||||
const Result file_res = m_file_table.Get(out_pos, out_entry, key);
|
||||
R_UNLESS(R_FAILED(file_res), file_res);
|
||||
R_UNLESS(fs::ResultDbmKeyNotFound::Includes(file_res), file_res);
|
||||
|
||||
Position pos = 0;
|
||||
RomDirectoryEntry entry = {};
|
||||
const Result dir_res = this->dir_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
const Result dir_res = m_dir_table.Get(std::addressof(pos), std::addressof(entry), key);
|
||||
R_UNLESS(R_FAILED(dir_res), fs::ResultDbmInvalidOperation());
|
||||
R_UNLESS(!fs::ResultDbmKeyNotFound::Includes(dir_res), fs::ResultDbmFileNotFound());
|
||||
return dir_res;
|
||||
@@ -531,12 +531,12 @@ namespace ams::fs {
|
||||
Position pos = FileIdToPosition(id);
|
||||
|
||||
RomEntryKey key = {};
|
||||
const Result file_res = this->file_table.GetByPosition(std::addressof(key), out_entry, pos);
|
||||
const Result file_res = m_file_table.GetByPosition(std::addressof(key), out_entry, pos);
|
||||
R_UNLESS(R_FAILED(file_res), file_res);
|
||||
R_UNLESS(fs::ResultDbmKeyNotFound::Includes(file_res), file_res);
|
||||
|
||||
RomDirectoryEntry entry = {};
|
||||
const Result dir_res = this->dir_table.GetByPosition(std::addressof(key), std::addressof(entry), pos);
|
||||
const Result dir_res = m_dir_table.GetByPosition(std::addressof(key), std::addressof(entry), pos);
|
||||
R_UNLESS(R_FAILED(dir_res), fs::ResultDbmInvalidOperation());
|
||||
R_UNLESS(!fs::ResultDbmKeyNotFound::Includes(dir_res), fs::ResultDbmFileNotFound());
|
||||
return dir_res;
|
||||
|
||||
@@ -26,9 +26,9 @@ namespace ams::fs::RomPathTool {
|
||||
path++;
|
||||
}
|
||||
|
||||
this->prev_path_start = path;
|
||||
this->prev_path_end = path;
|
||||
for (this->next_path = path + 1; IsSeparator(this->next_path[0]); ++this->next_path) {
|
||||
m_prev_path_start = path;
|
||||
m_prev_path_end = path;
|
||||
for (m_next_path = path + 1; IsSeparator(m_next_path[0]); ++m_next_path) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -36,63 +36,63 @@ namespace ams::fs::RomPathTool {
|
||||
}
|
||||
|
||||
void PathParser::Finalize() {
|
||||
this->prev_path_start = nullptr;
|
||||
this->prev_path_end = nullptr;
|
||||
this->next_path = nullptr;
|
||||
this->finished = false;
|
||||
m_prev_path_start = nullptr;
|
||||
m_prev_path_end = nullptr;
|
||||
m_next_path = nullptr;
|
||||
m_finished = false;
|
||||
}
|
||||
|
||||
bool PathParser::IsParseFinished() const {
|
||||
return this->finished;
|
||||
return m_finished;
|
||||
}
|
||||
|
||||
bool PathParser::IsDirectoryPath() const {
|
||||
AMS_ASSERT(this->next_path != nullptr);
|
||||
AMS_ASSERT(m_next_path != nullptr);
|
||||
|
||||
if (IsNullTerminator(this->next_path[0]) && IsSeparator(this->next_path[-1])) {
|
||||
if (IsNullTerminator(m_next_path[0]) && IsSeparator(m_next_path[-1])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsCurrentDirectory(this->next_path)) {
|
||||
if (IsCurrentDirectory(m_next_path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return IsParentDirectory(this->next_path);
|
||||
return IsParentDirectory(m_next_path);
|
||||
}
|
||||
|
||||
Result PathParser::GetNextDirectoryName(RomEntryName *out) {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
AMS_ASSERT(this->prev_path_start != nullptr);
|
||||
AMS_ASSERT(this->prev_path_end != nullptr);
|
||||
AMS_ASSERT(this->next_path != nullptr);
|
||||
AMS_ASSERT(m_prev_path_start != nullptr);
|
||||
AMS_ASSERT(m_prev_path_end != nullptr);
|
||||
AMS_ASSERT(m_next_path != nullptr);
|
||||
|
||||
/* Set the current path to output. */
|
||||
out->length = this->prev_path_end - this->prev_path_start;
|
||||
out->path = this->prev_path_start;
|
||||
out->length = m_prev_path_end - m_prev_path_start;
|
||||
out->path = m_prev_path_start;
|
||||
|
||||
/* Parse the next path. */
|
||||
this->prev_path_start = this->next_path;
|
||||
const RomPathChar *cur = this->next_path;
|
||||
m_prev_path_start = m_next_path;
|
||||
const RomPathChar *cur = m_next_path;
|
||||
for (size_t name_len = 0; true; name_len++) {
|
||||
if (IsSeparator(cur[name_len])) {
|
||||
R_UNLESS(name_len < MaxPathLength, fs::ResultDbmDirectoryNameTooLong());
|
||||
|
||||
this->prev_path_end = cur + name_len;
|
||||
this->next_path = this->prev_path_end + 1;
|
||||
m_prev_path_end = cur + name_len;
|
||||
m_next_path = m_prev_path_end + 1;
|
||||
|
||||
while (IsSeparator(this->next_path[0])) {
|
||||
++this->next_path;
|
||||
while (IsSeparator(m_next_path[0])) {
|
||||
++m_next_path;
|
||||
}
|
||||
if (IsNullTerminator(this->next_path[0])) {
|
||||
this->finished = true;
|
||||
if (IsNullTerminator(m_next_path[0])) {
|
||||
m_finished = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (IsNullTerminator(cur[name_len])) {
|
||||
this->finished = true;
|
||||
this->next_path = cur + name_len;
|
||||
this->prev_path_end = cur + name_len;
|
||||
m_finished = true;
|
||||
m_next_path = cur + name_len;
|
||||
m_prev_path_end = cur + name_len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -102,29 +102,29 @@ namespace ams::fs::RomPathTool {
|
||||
|
||||
Result PathParser::GetAsDirectoryName(RomEntryName *out) const {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
AMS_ASSERT(this->prev_path_start != nullptr);
|
||||
AMS_ASSERT(this->prev_path_end != nullptr);
|
||||
AMS_ASSERT(this->next_path != nullptr);
|
||||
AMS_ASSERT(m_prev_path_start != nullptr);
|
||||
AMS_ASSERT(m_prev_path_end != nullptr);
|
||||
AMS_ASSERT(m_next_path != nullptr);
|
||||
|
||||
const size_t len = this->prev_path_end - this->prev_path_start;
|
||||
const size_t len = m_prev_path_end - m_prev_path_start;
|
||||
R_UNLESS(len <= MaxPathLength, fs::ResultDbmDirectoryNameTooLong());
|
||||
|
||||
out->length = len;
|
||||
out->path = this->prev_path_start;
|
||||
out->path = m_prev_path_start;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result PathParser::GetAsFileName(RomEntryName *out) const {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
AMS_ASSERT(this->prev_path_start != nullptr);
|
||||
AMS_ASSERT(this->prev_path_end != nullptr);
|
||||
AMS_ASSERT(this->next_path != nullptr);
|
||||
AMS_ASSERT(m_prev_path_start != nullptr);
|
||||
AMS_ASSERT(m_prev_path_end != nullptr);
|
||||
AMS_ASSERT(m_next_path != nullptr);
|
||||
|
||||
const size_t len = this->prev_path_end - this->prev_path_start;
|
||||
const size_t len = m_prev_path_end - m_prev_path_start;
|
||||
R_UNLESS(len <= MaxPathLength, fs::ResultDbmFileNameTooLong());
|
||||
|
||||
out->length = len;
|
||||
out->path = this->prev_path_start;
|
||||
out->path = m_prev_path_start;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
namespace ams::fs {
|
||||
|
||||
Result FileStorage::UpdateSize() {
|
||||
R_SUCCEED_IF(this->size != InvalidSize);
|
||||
return this->base_file->GetSize(std::addressof(this->size));
|
||||
R_SUCCEED_IF(m_size != InvalidSize);
|
||||
return m_base_file->GetSize(std::addressof(m_size));
|
||||
}
|
||||
|
||||
Result FileStorage::Read(s64 offset, void *buffer, size_t size) {
|
||||
@@ -33,10 +33,10 @@ namespace ams::fs {
|
||||
R_TRY(this->UpdateSize());
|
||||
|
||||
/* Ensure our access is valid. */
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
|
||||
size_t read_size;
|
||||
return this->base_file->Read(std::addressof(read_size), offset, buffer, size);
|
||||
return m_base_file->Read(std::addressof(read_size), offset, buffer, size);
|
||||
}
|
||||
|
||||
Result FileStorage::Write(s64 offset, const void *buffer, size_t size) {
|
||||
@@ -50,24 +50,24 @@ namespace ams::fs {
|
||||
R_TRY(this->UpdateSize());
|
||||
|
||||
/* Ensure our access is valid. */
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
|
||||
return this->base_file->Write(offset, buffer, size, fs::WriteOption());
|
||||
return m_base_file->Write(offset, buffer, size, fs::WriteOption());
|
||||
}
|
||||
|
||||
Result FileStorage::Flush() {
|
||||
return this->base_file->Flush();
|
||||
return m_base_file->Flush();
|
||||
}
|
||||
|
||||
Result FileStorage::GetSize(s64 *out_size) {
|
||||
R_TRY(this->UpdateSize());
|
||||
*out_size = this->size;
|
||||
*out_size = m_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileStorage::SetSize(s64 size) {
|
||||
this->size = InvalidSize;
|
||||
return this->base_file->SetSize(size);
|
||||
m_size = InvalidSize;
|
||||
return m_base_file->SetSize(size);
|
||||
}
|
||||
|
||||
Result FileStorage::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
|
||||
@@ -84,7 +84,7 @@ namespace ams::fs {
|
||||
}
|
||||
R_TRY(this->UpdateSize());
|
||||
R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange());
|
||||
return this->base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||
return m_base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||
default:
|
||||
return fs::ResultUnsupportedOperationInFileStorageA();
|
||||
}
|
||||
@@ -97,19 +97,19 @@ namespace ams::fs {
|
||||
|
||||
/* Set the file. */
|
||||
this->SetFile(std::move(base_file));
|
||||
this->base_file_system = std::move(base_file_system);
|
||||
m_base_file_system = std::move(base_file_system);
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileHandleStorage::UpdateSize() {
|
||||
R_SUCCEED_IF(this->size != InvalidSize);
|
||||
return GetFileSize(std::addressof(this->size), this->handle);
|
||||
R_SUCCEED_IF(m_size != InvalidSize);
|
||||
return GetFileSize(std::addressof(m_size), m_handle);
|
||||
}
|
||||
|
||||
Result FileHandleStorage::Read(s64 offset, void *buffer, size_t size) {
|
||||
/* Lock the mutex. */
|
||||
std::scoped_lock lk(this->mutex);
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Immediately succeed if there's nothing to read. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
@@ -121,14 +121,14 @@ namespace ams::fs {
|
||||
R_TRY(this->UpdateSize());
|
||||
|
||||
/* Ensure our access is valid. */
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
|
||||
return ReadFile(this->handle, offset, buffer, size, fs::ReadOption());
|
||||
return ReadFile(m_handle, offset, buffer, size, fs::ReadOption());
|
||||
}
|
||||
|
||||
Result FileHandleStorage::Write(s64 offset, const void *buffer, size_t size) {
|
||||
/* Lock the mutex. */
|
||||
std::scoped_lock lk(this->mutex);
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Immediately succeed if there's nothing to write. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
@@ -140,24 +140,24 @@ namespace ams::fs {
|
||||
R_TRY(this->UpdateSize());
|
||||
|
||||
/* Ensure our access is valid. */
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
|
||||
return WriteFile(this->handle, offset, buffer, size, fs::WriteOption());
|
||||
return WriteFile(m_handle, offset, buffer, size, fs::WriteOption());
|
||||
}
|
||||
|
||||
Result FileHandleStorage::Flush() {
|
||||
return FlushFile(this->handle);
|
||||
return FlushFile(m_handle);
|
||||
}
|
||||
|
||||
Result FileHandleStorage::GetSize(s64 *out_size) {
|
||||
R_TRY(this->UpdateSize());
|
||||
*out_size = this->size;
|
||||
*out_size = m_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileHandleStorage::SetSize(s64 size) {
|
||||
this->size = InvalidSize;
|
||||
return SetFileSize(this->handle, size);
|
||||
m_size = InvalidSize;
|
||||
return SetFileSize(m_handle, size);
|
||||
}
|
||||
|
||||
Result FileHandleStorage::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
|
||||
@@ -169,7 +169,7 @@ namespace ams::fs {
|
||||
R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(dst_size == sizeof(QueryRangeInfo), fs::ResultInvalidSize());
|
||||
|
||||
return QueryRange(static_cast<QueryRangeInfo *>(dst), this->handle, offset, size);
|
||||
return QueryRange(static_cast<QueryRangeInfo *>(dst), m_handle, offset, size);
|
||||
default:
|
||||
return fs::ResultUnsupportedOperationInFileStorageB();
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ namespace ams::fs {
|
||||
namespace ams::fs::impl {
|
||||
|
||||
const char *IdString::ToValueString(int id) {
|
||||
const int len = util::SNPrintf(this->buffer, sizeof(this->buffer), "%d", id);
|
||||
AMS_ASSERT(static_cast<size_t>(len) < sizeof(this->buffer));
|
||||
const int len = util::SNPrintf(m_buffer, sizeof(m_buffer), "%d", id);
|
||||
AMS_ASSERT(static_cast<size_t>(len) < sizeof(m_buffer));
|
||||
AMS_UNUSED(len);
|
||||
return this->buffer;
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
template<> const char *IdString::ToString<fs::Priority>(fs::Priority id) {
|
||||
@@ -171,20 +171,20 @@ namespace ams::fs::impl {
|
||||
|
||||
class AccessLogPrinterCallbackManager {
|
||||
private:
|
||||
AccessLogPrinterCallback callback;
|
||||
AccessLogPrinterCallback m_callback;
|
||||
public:
|
||||
constexpr AccessLogPrinterCallbackManager() : callback(nullptr) { /* ... */ }
|
||||
constexpr AccessLogPrinterCallbackManager() : m_callback(nullptr) { /* ... */ }
|
||||
|
||||
constexpr bool IsRegisteredCallback() const { return this->callback != nullptr; }
|
||||
constexpr bool IsRegisteredCallback() const { return m_callback != nullptr; }
|
||||
|
||||
constexpr void RegisterCallback(AccessLogPrinterCallback c) {
|
||||
AMS_ASSERT(this->callback == nullptr);
|
||||
this->callback = c;
|
||||
AMS_ASSERT(m_callback == nullptr);
|
||||
m_callback = c;
|
||||
}
|
||||
|
||||
constexpr int InvokeCallback(char *buf, size_t size) const {
|
||||
AMS_ASSERT(this->callback != nullptr);
|
||||
return this->callback(buf, size);
|
||||
AMS_ASSERT(m_callback != nullptr);
|
||||
return m_callback(buf, size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@ namespace ams::fs {
|
||||
|
||||
class BisCommonMountNameGenerator : public fsa::ICommonMountNameGenerator, public impl::Newable {
|
||||
private:
|
||||
const BisPartitionId id;
|
||||
const BisPartitionId m_id;
|
||||
public:
|
||||
explicit BisCommonMountNameGenerator(BisPartitionId i) : id(i) { /* ... */ }
|
||||
explicit BisCommonMountNameGenerator(BisPartitionId i) : m_id(i) { /* ... */ }
|
||||
|
||||
virtual Result GenerateCommonMountName(char *dst, size_t dst_size) override {
|
||||
/* Determine how much space we need. */
|
||||
const char *bis_mount_name = GetBisMountName(this->id);
|
||||
const char *bis_mount_name = GetBisMountName(m_id);
|
||||
const size_t needed_size = util::Strnlen(bis_mount_name, MountNameLengthMax) + 2;
|
||||
AMS_ABORT_UNLESS(dst_size >= needed_size);
|
||||
|
||||
|
||||
@@ -251,11 +251,11 @@ namespace ams::fs {
|
||||
|
||||
class SdCardRedirectionCodeFileSystem : public OpenFileOnlyFileSystem {
|
||||
private:
|
||||
util::optional<ReadOnlyFileSystem> sd_content_fs;
|
||||
ReadOnlyFileSystem code_fs;
|
||||
bool is_redirect;
|
||||
util::optional<ReadOnlyFileSystem> m_sd_content_fs;
|
||||
ReadOnlyFileSystem m_code_fs;
|
||||
bool m_is_redirect;
|
||||
public:
|
||||
SdCardRedirectionCodeFileSystem(std::unique_ptr<fsa::IFileSystem> &&code, ncm::ProgramId program_id, bool redirect) : code_fs(std::move(code)), is_redirect(redirect) {
|
||||
SdCardRedirectionCodeFileSystem(std::unique_ptr<fsa::IFileSystem> &&code, ncm::ProgramId program_id, bool redirect) : m_code_fs(std::move(code)), m_is_redirect(redirect) {
|
||||
if (!cfg::IsSdCardInitialized()) {
|
||||
return;
|
||||
}
|
||||
@@ -275,12 +275,12 @@ namespace ams::fs {
|
||||
return;
|
||||
}
|
||||
|
||||
sd_content_fs.emplace(std::move(subdir_fs));
|
||||
m_sd_content_fs.emplace(std::move(subdir_fs));
|
||||
}
|
||||
private:
|
||||
bool IsFileStubbed(const char *path) {
|
||||
/* If we don't have an sd content fs, nothing is stubbed. */
|
||||
if (!this->sd_content_fs) {
|
||||
if (!m_sd_content_fs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ namespace ams::fs {
|
||||
|
||||
/* Query whether we have the file. */
|
||||
bool has_file;
|
||||
if (R_FAILED(fssystem::HasFile(std::addressof(has_file), std::addressof(*this->sd_content_fs), stub_path))) {
|
||||
if (R_FAILED(fssystem::HasFile(std::addressof(has_file), std::addressof(*m_sd_content_fs), stub_path))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -302,70 +302,70 @@ namespace ams::fs {
|
||||
R_UNLESS((mode & fs::OpenMode_All) == fs::OpenMode_Read, fs::ResultInvalidOpenMode());
|
||||
|
||||
/* If we support redirection, we'd like to prefer a file from the sd card. */
|
||||
if (this->is_redirect) {
|
||||
R_SUCCEED_IF(R_SUCCEEDED(this->sd_content_fs->OpenFile(out_file, path, mode)));
|
||||
if (m_is_redirect) {
|
||||
R_SUCCEED_IF(R_SUCCEEDED(m_sd_content_fs->OpenFile(out_file, path, mode)));
|
||||
}
|
||||
|
||||
/* Otherwise, check if the file is stubbed. */
|
||||
R_UNLESS(!this->IsFileStubbed(path), fs::ResultPathNotFound());
|
||||
|
||||
/* Open a file from the base code fs. */
|
||||
return this->code_fs.OpenFile(out_file, path, mode);
|
||||
return m_code_fs.OpenFile(out_file, path, mode);
|
||||
}
|
||||
};
|
||||
|
||||
class AtmosphereCodeFileSystem : public OpenFileOnlyFileSystem {
|
||||
private:
|
||||
util::optional<SdCardRedirectionCodeFileSystem> code_fs;
|
||||
util::optional<ReadOnlyFileSystem> hbl_fs;
|
||||
ncm::ProgramId program_id;
|
||||
bool initialized;
|
||||
util::optional<SdCardRedirectionCodeFileSystem> m_code_fs;
|
||||
util::optional<ReadOnlyFileSystem> m_hbl_fs;
|
||||
ncm::ProgramId m_program_id;
|
||||
bool m_initialized;
|
||||
public:
|
||||
AtmosphereCodeFileSystem() : initialized(false) { /* ... */ }
|
||||
AtmosphereCodeFileSystem() : m_initialized(false) { /* ... */ }
|
||||
|
||||
Result Initialize(CodeVerificationData *out_verification_data, const char *path, ncm::ProgramId program_id, bool is_hbl, bool is_specific) {
|
||||
AMS_ABORT_UNLESS(!this->initialized);
|
||||
AMS_ABORT_UNLESS(!m_initialized);
|
||||
|
||||
/* If we're hbl, we need to open a hbl fs. */
|
||||
if (is_hbl) {
|
||||
std::unique_ptr<fsa::IFileSystem> fsa;
|
||||
R_TRY(OpenHblCodeFileSystemImpl(std::addressof(fsa)));
|
||||
this->hbl_fs.emplace(std::move(fsa));
|
||||
m_hbl_fs.emplace(std::move(fsa));
|
||||
}
|
||||
|
||||
/* Open the code filesystem. */
|
||||
std::unique_ptr<fsa::IFileSystem> fsa;
|
||||
R_TRY(OpenSdCardCodeOrStratosphereCodeOrCodeFileSystemImpl(out_verification_data, std::addressof(fsa), path, program_id));
|
||||
this->code_fs.emplace(std::move(fsa), program_id, is_specific);
|
||||
m_code_fs.emplace(std::move(fsa), program_id, is_specific);
|
||||
|
||||
this->program_id = program_id;
|
||||
this->initialized = true;
|
||||
m_program_id = program_id;
|
||||
m_initialized = true;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
private:
|
||||
virtual Result DoOpenFile(std::unique_ptr<fsa::IFile> *out_file, const char *path, OpenMode mode) override final {
|
||||
/* Ensure that we're initialized. */
|
||||
R_UNLESS(this->initialized, fs::ResultNotInitialized());
|
||||
R_UNLESS(m_initialized, fs::ResultNotInitialized());
|
||||
|
||||
/* Only allow opening files with mode = read. */
|
||||
R_UNLESS((mode & fs::OpenMode_All) == fs::OpenMode_Read, fs::ResultInvalidOpenMode());
|
||||
|
||||
/* First, check if there's an external code. */
|
||||
{
|
||||
fsa::IFileSystem *ecs = fssystem::GetExternalCodeFileSystem(this->program_id);
|
||||
fsa::IFileSystem *ecs = fssystem::GetExternalCodeFileSystem(m_program_id);
|
||||
if (ecs != nullptr) {
|
||||
return ecs->OpenFile(out_file, path, mode);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're hbl, open from the hbl fs. */
|
||||
if (this->hbl_fs) {
|
||||
return this->hbl_fs->OpenFile(out_file, path, mode);
|
||||
if (m_hbl_fs) {
|
||||
return m_hbl_fs->OpenFile(out_file, path, mode);
|
||||
}
|
||||
|
||||
/* If we're not hbl, fall back to our code filesystem. */
|
||||
return this->code_fs->OpenFile(out_file, path, mode);
|
||||
return m_code_fs->OpenFile(out_file, path, mode);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace ams::fs {
|
||||
g_context_tls.SetValue(reinterpret_cast<uintptr_t>(context));
|
||||
}
|
||||
|
||||
ScopedAutoAbortDisabler::ScopedAutoAbortDisabler() : prev_context(GetCurrentThreadFsContext()) {
|
||||
ScopedAutoAbortDisabler::ScopedAutoAbortDisabler() : m_prev_context(GetCurrentThreadFsContext()) {
|
||||
SetCurrentThreadFsContext(std::addressof(g_always_return_context));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,18 +31,18 @@ namespace ams::fs {
|
||||
|
||||
class GameCardCommonMountNameGenerator : public fsa::ICommonMountNameGenerator, public impl::Newable {
|
||||
private:
|
||||
const GameCardHandle handle;
|
||||
const GameCardPartition partition;
|
||||
const GameCardHandle m_handle;
|
||||
const GameCardPartition m_partition;
|
||||
public:
|
||||
explicit GameCardCommonMountNameGenerator(GameCardHandle h, GameCardPartition p) : handle(h), partition(p) { /* ... */ }
|
||||
explicit GameCardCommonMountNameGenerator(GameCardHandle h, GameCardPartition p) : m_handle(h), m_partition(p) { /* ... */ }
|
||||
|
||||
virtual Result GenerateCommonMountName(char *dst, size_t dst_size) override {
|
||||
/* Determine how much space we need. */
|
||||
const size_t needed_size = strnlen(impl::GameCardFileSystemMountName, MountNameLengthMax) + strnlen(GetGameCardMountNameSuffix(this->partition), MountNameLengthMax) + sizeof(GameCardHandle) * 2 + 2;
|
||||
const size_t needed_size = strnlen(impl::GameCardFileSystemMountName, MountNameLengthMax) + strnlen(GetGameCardMountNameSuffix(m_partition), MountNameLengthMax) + sizeof(GameCardHandle) * 2 + 2;
|
||||
AMS_ABORT_UNLESS(dst_size >= needed_size);
|
||||
|
||||
/* Generate the name. */
|
||||
const auto size = util::SNPrintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(this->partition), this->handle);
|
||||
const auto size = util::SNPrintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(m_partition), m_handle);
|
||||
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
|
||||
AMS_UNUSED(size);
|
||||
|
||||
|
||||
@@ -21,14 +21,14 @@ namespace ams::fs {
|
||||
|
||||
class PathVerifier {
|
||||
private:
|
||||
u32 invalid_chars[6];
|
||||
u32 separators[2];
|
||||
u32 m_invalid_chars[6];
|
||||
u32 m_separators[2];
|
||||
public:
|
||||
PathVerifier() {
|
||||
/* Convert all invalid characters. */
|
||||
u32 *dst_invalid = this->invalid_chars;
|
||||
u32 *dst_invalid = m_invalid_chars;
|
||||
for (const char *cur = ":*?<>|"; *cur != '\x00'; ++cur) {
|
||||
AMS_ASSERT(dst_invalid < std::end(this->invalid_chars));
|
||||
AMS_ASSERT(dst_invalid < std::end(m_invalid_chars));
|
||||
|
||||
const auto result = util::ConvertCharacterUtf8ToUtf32(dst_invalid, cur);
|
||||
AMS_ASSERT(result == util::CharacterEncodingResult_Success);
|
||||
@@ -36,12 +36,12 @@ namespace ams::fs {
|
||||
|
||||
++dst_invalid;
|
||||
}
|
||||
AMS_ASSERT(dst_invalid == std::end(this->invalid_chars));
|
||||
AMS_ASSERT(dst_invalid == std::end(m_invalid_chars));
|
||||
|
||||
/* Convert all separators. */
|
||||
u32 *dst_sep = this->separators;
|
||||
u32 *dst_sep = m_separators;
|
||||
for (const char *cur = "/\\"; *cur != '\x00'; ++cur) {
|
||||
AMS_ASSERT(dst_sep < std::end(this->separators));
|
||||
AMS_ASSERT(dst_sep < std::end(m_separators));
|
||||
|
||||
const auto result = util::ConvertCharacterUtf8ToUtf32(dst_sep, cur);
|
||||
AMS_ASSERT(result == util::CharacterEncodingResult_Success);
|
||||
@@ -49,7 +49,7 @@ namespace ams::fs {
|
||||
|
||||
++dst_sep;
|
||||
}
|
||||
AMS_ASSERT(dst_sep == std::end(this->separators));
|
||||
AMS_ASSERT(dst_sep == std::end(m_separators));
|
||||
}
|
||||
|
||||
Result Verify(const char *path, int max_path_len, int max_name_len) const {
|
||||
@@ -74,7 +74,7 @@ namespace ams::fs {
|
||||
R_UNLESS(result == util::CharacterEncodingResult_Success, fs::ResultInvalidCharacter());
|
||||
|
||||
/* Check if the character is invalid. */
|
||||
for (const auto invalid : this->invalid_chars) {
|
||||
for (const auto invalid : m_invalid_chars) {
|
||||
R_UNLESS(path_char != invalid, fs::ResultInvalidCharacter());
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace ams::fs {
|
||||
++name_len;
|
||||
|
||||
/* Check for separator. */
|
||||
for (const auto sep : this->separators) {
|
||||
for (const auto sep : m_separators) {
|
||||
if (path_char == sep) {
|
||||
name_len = 0;
|
||||
break;
|
||||
|
||||
@@ -166,11 +166,11 @@ namespace ams::fs {
|
||||
|
||||
class RomFsFile : public fsa::IFile, public impl::Newable {
|
||||
private:
|
||||
RomFsFileSystem *parent;
|
||||
s64 start;
|
||||
s64 end;
|
||||
RomFsFileSystem *m_parent;
|
||||
s64 m_start;
|
||||
s64 m_end;
|
||||
public:
|
||||
RomFsFile(RomFsFileSystem *p, s64 s, s64 e) : parent(p), start(s), end(e) { /* ... */ }
|
||||
RomFsFile(RomFsFileSystem *p, s64 s, s64 e) : m_parent(p), m_start(s), m_end(e) { /* ... */ }
|
||||
virtual ~RomFsFile() { /* ... */ }
|
||||
|
||||
Result VerifyArguments(size_t *out, s64 offset, void *buf, size_t size, const fs::ReadOption &option) {
|
||||
@@ -189,22 +189,22 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
s64 GetOffset() const {
|
||||
return this->start;
|
||||
return m_start;
|
||||
}
|
||||
|
||||
s64 GetSize() const {
|
||||
return this->end - this->start;
|
||||
return m_end - m_start;
|
||||
}
|
||||
|
||||
IStorage *GetStorage() {
|
||||
return this->parent->GetBaseStorage();
|
||||
return m_parent->GetBaseStorage();
|
||||
}
|
||||
public:
|
||||
virtual Result DoRead(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override {
|
||||
size_t read_size = 0;
|
||||
R_TRY(this->VerifyArguments(std::addressof(read_size), offset, buffer, size, option));
|
||||
|
||||
R_TRY(this->ConvertResult(this->GetStorage()->Read(offset + this->start, buffer, size)));
|
||||
R_TRY(this->ConvertResult(this->GetStorage()->Read(offset + m_start, buffer, size)));
|
||||
*out = read_size;
|
||||
|
||||
return ResultSuccess();
|
||||
@@ -242,7 +242,7 @@ namespace ams::fs {
|
||||
operate_size = this->GetSize() - offset;
|
||||
}
|
||||
|
||||
return this->GetStorage()->OperateRange(dst, dst_size, op_id, this->start + offset, operate_size, src, src_size);
|
||||
return this->GetStorage()->OperateRange(dst, dst_size, op_id, m_start + offset, operate_size, src, src_size);
|
||||
}
|
||||
default:
|
||||
return fs::ResultUnsupportedOperationInRomFsFileB();
|
||||
@@ -258,20 +258,20 @@ namespace ams::fs {
|
||||
private:
|
||||
using FindPosition = RomFsFileSystem::RomFileTable::FindPosition;
|
||||
private:
|
||||
RomFsFileSystem *parent;
|
||||
FindPosition current_find;
|
||||
FindPosition first_find;
|
||||
fs::OpenDirectoryMode mode;
|
||||
RomFsFileSystem *m_parent;
|
||||
FindPosition m_current_find;
|
||||
FindPosition m_first_find;
|
||||
fs::OpenDirectoryMode m_mode;
|
||||
public:
|
||||
RomFsDirectory(RomFsFileSystem *p, const FindPosition &f, fs::OpenDirectoryMode m) : parent(p), current_find(f), first_find(f), mode(m) { /* ... */ }
|
||||
RomFsDirectory(RomFsFileSystem *p, const FindPosition &f, fs::OpenDirectoryMode m) : m_parent(p), m_current_find(f), m_first_find(f), m_mode(m) { /* ... */ }
|
||||
virtual ~RomFsDirectory() override { /* ... */ }
|
||||
public:
|
||||
virtual Result DoRead(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries) {
|
||||
return this->ReadInternal(out_count, std::addressof(this->current_find), out_entries, max_entries);
|
||||
return this->ReadInternal(out_count, std::addressof(m_current_find), out_entries, max_entries);
|
||||
}
|
||||
|
||||
virtual Result DoGetEntryCount(s64 *out) {
|
||||
FindPosition find = this->first_find;
|
||||
FindPosition find = m_first_find;
|
||||
return this->ReadInternal(out, std::addressof(find), nullptr, 0);
|
||||
}
|
||||
private:
|
||||
@@ -286,9 +286,9 @@ namespace ams::fs {
|
||||
|
||||
s32 i = 0;
|
||||
|
||||
if (this->mode & fs::OpenDirectoryMode_Directory) {
|
||||
if (m_mode & fs::OpenDirectoryMode_Directory) {
|
||||
while (i < max_entries || out_entries == nullptr) {
|
||||
R_TRY_CATCH(this->parent->GetRomFileTable()->FindNextDirectory(name_buf, find, NameBufferSize)) {
|
||||
R_TRY_CATCH(m_parent->GetRomFileTable()->FindNextDirectory(name_buf, find, NameBufferSize)) {
|
||||
R_CATCH(fs::ResultDbmFindFinished) { break; }
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
@@ -304,11 +304,11 @@ namespace ams::fs {
|
||||
}
|
||||
}
|
||||
|
||||
if (this->mode & fs::OpenDirectoryMode_File) {
|
||||
if (m_mode & fs::OpenDirectoryMode_File) {
|
||||
while (i < max_entries || out_entries == nullptr) {
|
||||
auto file_pos = find->next_file;
|
||||
|
||||
R_TRY_CATCH(this->parent->GetRomFileTable()->FindNextFile(name_buf, find, NameBufferSize)) {
|
||||
R_TRY_CATCH(m_parent->GetRomFileTable()->FindNextFile(name_buf, find, NameBufferSize)) {
|
||||
R_CATCH(fs::ResultDbmFindFinished) { break; }
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace ams::fs {
|
||||
out_entries[i].type = fs::DirectoryEntryType_File;
|
||||
|
||||
RomFsFileSystem::RomFileTable::FileInfo file_info;
|
||||
R_TRY(this->parent->GetRomFileTable()->OpenFile(std::addressof(file_info), this->parent->GetRomFileTable()->PositionToFileId(file_pos)));
|
||||
R_TRY(m_parent->GetRomFileTable()->OpenFile(std::addressof(file_info), m_parent->GetRomFileTable()->PositionToFileId(file_pos)));
|
||||
out_entries[i].file_size = file_info.size.Get();
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
|
||||
RomFsFileSystem::RomFsFileSystem() : base_storage() {
|
||||
RomFsFileSystem::RomFsFileSystem() : m_base_storage() {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -379,46 +379,46 @@ namespace ams::fs {
|
||||
R_TRY(ReadFile(base, header.file_bucket_offset, file_bucket_buf, header.file_bucket_size));
|
||||
R_TRY(ReadFile(base, header.file_entry_offset, file_entry_buf, header.file_entry_size));
|
||||
|
||||
this->dir_bucket_storage.reset(new MemoryStorage(dir_bucket_buf, header.directory_bucket_size));
|
||||
this->dir_entry_storage.reset(new MemoryStorage(dir_entry_buf, header.directory_entry_size));
|
||||
this->file_bucket_storage.reset(new MemoryStorage(file_bucket_buf, header.file_bucket_size));
|
||||
this->file_entry_storage.reset(new MemoryStorage(file_entry_buf, header.file_entry_size));
|
||||
m_dir_bucket_storage.reset(new MemoryStorage(dir_bucket_buf, header.directory_bucket_size));
|
||||
m_dir_entry_storage.reset(new MemoryStorage(dir_entry_buf, header.directory_entry_size));
|
||||
m_file_bucket_storage.reset(new MemoryStorage(file_bucket_buf, header.file_bucket_size));
|
||||
m_file_entry_storage.reset(new MemoryStorage(file_entry_buf, header.file_entry_size));
|
||||
} else {
|
||||
this->dir_bucket_storage.reset(new SubStorage(base, header.directory_bucket_offset, header.directory_bucket_size));
|
||||
this->dir_entry_storage.reset(new SubStorage(base, header.directory_entry_offset, header.directory_entry_size));
|
||||
this->file_bucket_storage.reset(new SubStorage(base, header.file_bucket_offset, header.file_bucket_size));
|
||||
this->file_entry_storage.reset(new SubStorage(base, header.file_entry_offset, header.file_entry_size));
|
||||
m_dir_bucket_storage.reset(new SubStorage(base, header.directory_bucket_offset, header.directory_bucket_size));
|
||||
m_dir_entry_storage.reset(new SubStorage(base, header.directory_entry_offset, header.directory_entry_size));
|
||||
m_file_bucket_storage.reset(new SubStorage(base, header.file_bucket_offset, header.file_bucket_size));
|
||||
m_file_entry_storage.reset(new SubStorage(base, header.file_entry_offset, header.file_entry_size));
|
||||
}
|
||||
|
||||
/* Ensure we allocated storages successfully. */
|
||||
R_UNLESS(this->dir_bucket_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
R_UNLESS(this->dir_entry_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
R_UNLESS(this->file_bucket_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
R_UNLESS(this->file_entry_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
R_UNLESS(m_dir_bucket_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
R_UNLESS(m_dir_entry_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
R_UNLESS(m_file_bucket_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
R_UNLESS(m_file_entry_storage != nullptr, fs::ResultAllocationFailureInRomFsFileSystemA());
|
||||
|
||||
/* Initialize the rom table. */
|
||||
{
|
||||
|
||||
SubStorage db(this->dir_bucket_storage.get(), 0, header.directory_bucket_size);
|
||||
SubStorage de(this->dir_entry_storage.get(), 0, header.directory_entry_size);
|
||||
SubStorage fb(this->file_bucket_storage.get(), 0, header.file_bucket_size);
|
||||
SubStorage fe(this->file_entry_storage.get(), 0, header.file_entry_size);
|
||||
R_TRY(this->rom_file_table.Initialize(db, de, fb, fe));
|
||||
SubStorage db(m_dir_bucket_storage.get(), 0, header.directory_bucket_size);
|
||||
SubStorage de(m_dir_entry_storage.get(), 0, header.directory_entry_size);
|
||||
SubStorage fb(m_file_bucket_storage.get(), 0, header.file_bucket_size);
|
||||
SubStorage fe(m_file_entry_storage.get(), 0, header.file_entry_size);
|
||||
R_TRY(m_rom_file_table.Initialize(db, de, fb, fe));
|
||||
}
|
||||
|
||||
/* Set members. */
|
||||
this->entry_size = header.body_offset;
|
||||
this->base_storage = base;
|
||||
m_entry_size = header.body_offset;
|
||||
m_base_storage = base;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RomFsFileSystem::Initialize(std::unique_ptr<IStorage>&& base, void *work, size_t work_size, bool use_cache) {
|
||||
this->unique_storage = std::move(base);
|
||||
return this->Initialize(this->unique_storage.get(), work, work_size, use_cache);
|
||||
m_unique_storage = std::move(base);
|
||||
return this->Initialize(m_unique_storage.get(), work, work_size, use_cache);
|
||||
}
|
||||
|
||||
Result RomFsFileSystem::GetFileInfo(RomFileTable::FileInfo *out, const char *path) {
|
||||
R_TRY_CATCH(this->rom_file_table.OpenFile(out, path)) {
|
||||
R_TRY_CATCH(m_rom_file_table.OpenFile(out, path)) {
|
||||
R_CONVERT(fs::ResultDbmNotFound, fs::ResultPathNotFound());
|
||||
R_CONVERT(fs::ResultDbmInvalidOperation, fs::ResultPathNotFound());
|
||||
} R_END_TRY_CATCH;
|
||||
@@ -426,11 +426,11 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
IStorage *RomFsFileSystem::GetBaseStorage() {
|
||||
return this->base_storage;
|
||||
return m_base_storage;
|
||||
}
|
||||
|
||||
RomFsFileSystem::RomFileTable *RomFsFileSystem::GetRomFileTable() {
|
||||
return std::addressof(this->rom_file_table);
|
||||
return std::addressof(m_rom_file_table);
|
||||
}
|
||||
|
||||
Result RomFsFileSystem::GetFileBaseOffset(s64 *out, const char *path) {
|
||||
@@ -439,7 +439,7 @@ namespace ams::fs {
|
||||
|
||||
RomFileTable::FileInfo info;
|
||||
R_TRY(this->GetFileInfo(std::addressof(info), path));
|
||||
*out = this->entry_size + info.offset.Get();
|
||||
*out = m_entry_size + info.offset.Get();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ namespace ams::fs {
|
||||
|
||||
Result RomFsFileSystem::DoGetEntryType(fs::DirectoryEntryType *out, const char *path) {
|
||||
RomDirectoryInfo dir_info;
|
||||
R_TRY_CATCH(this->rom_file_table.GetDirectoryInformation(std::addressof(dir_info), path)) {
|
||||
R_TRY_CATCH(m_rom_file_table.GetDirectoryInformation(std::addressof(dir_info), path)) {
|
||||
R_CONVERT(fs::ResultDbmNotFound, fs::ResultPathNotFound())
|
||||
R_CATCH(fs::ResultDbmInvalidOperation) {
|
||||
RomFileTable::FileInfo file_info;
|
||||
@@ -503,7 +503,7 @@ namespace ams::fs {
|
||||
RomFileTable::FileInfo file_info;
|
||||
R_TRY(this->GetFileInfo(std::addressof(file_info), path));
|
||||
|
||||
auto file = std::make_unique<RomFsFile>(this, this->entry_size + file_info.offset.Get(), this->entry_size + file_info.offset.Get() + file_info.size.Get());
|
||||
auto file = std::make_unique<RomFsFile>(this, m_entry_size + file_info.offset.Get(), m_entry_size + file_info.offset.Get() + file_info.size.Get());
|
||||
R_UNLESS(file != nullptr, fs::ResultAllocationFailureInRomFsFileSystemB());
|
||||
|
||||
*out_file = std::move(file);
|
||||
@@ -515,7 +515,7 @@ namespace ams::fs {
|
||||
AMS_ASSERT(path != nullptr);
|
||||
|
||||
RomFileTable::FindPosition find;
|
||||
R_TRY_CATCH(this->rom_file_table.FindOpen(std::addressof(find), path)) {
|
||||
R_TRY_CATCH(m_rom_file_table.FindOpen(std::addressof(find), path)) {
|
||||
R_CONVERT(fs::ResultDbmNotFound, fs::ResultPathNotFound())
|
||||
R_CONVERT(fs::ResultDbmInvalidOperation, fs::ResultPathNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
@@ -22,33 +22,33 @@ namespace ams::fs {
|
||||
class ScopedSetter {
|
||||
NON_COPYABLE(ScopedSetter);
|
||||
private:
|
||||
T *ptr;
|
||||
T value;
|
||||
T *m_ptr;
|
||||
T m_value;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE ScopedSetter(T &p, T v) : ptr(std::addressof(p)), value(v) { /* ... */ }
|
||||
constexpr ALWAYS_INLINE ScopedSetter(T &p, T v) : m_ptr(std::addressof(p)), m_value(v) { /* ... */ }
|
||||
ALWAYS_INLINE ~ScopedSetter() {
|
||||
if (this->ptr) {
|
||||
*this->ptr = this->value;
|
||||
if (m_ptr) {
|
||||
*m_ptr = m_value;
|
||||
}
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ScopedSetter(ScopedSetter &&rhs) {
|
||||
this->ptr = rhs.ptr;
|
||||
this->value = rhs.value;
|
||||
m_ptr = rhs.ptr;
|
||||
m_value = rhs.value;
|
||||
rhs.Reset();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ScopedSetter &operator=(ScopedSetter &&rhs) {
|
||||
this->ptr = rhs.ptr;
|
||||
this->value = rhs.value;
|
||||
m_ptr = rhs.ptr;
|
||||
m_value = rhs.value;
|
||||
rhs.Reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Set(T v) { this->value = v; }
|
||||
ALWAYS_INLINE void Set(T v) { m_value = v; }
|
||||
private:
|
||||
ALWAYS_INLINE void Reset() {
|
||||
this->ptr = nullptr;
|
||||
m_ptr = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,21 +19,21 @@
|
||||
|
||||
namespace ams::fs::impl {
|
||||
|
||||
DirectoryAccessor::DirectoryAccessor(std::unique_ptr<fsa::IDirectory>&& d, FileSystemAccessor &p) : impl(std::move(d)), parent(p) {
|
||||
DirectoryAccessor::DirectoryAccessor(std::unique_ptr<fsa::IDirectory>&& d, FileSystemAccessor &p) : m_impl(std::move(d)), m_parent(p) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
DirectoryAccessor::~DirectoryAccessor() {
|
||||
this->impl.reset();
|
||||
this->parent.NotifyCloseDirectory(this);
|
||||
m_impl.reset();
|
||||
m_parent.NotifyCloseDirectory(this);
|
||||
}
|
||||
|
||||
Result DirectoryAccessor::Read(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries) {
|
||||
return this->impl->Read(out_count, out_entries, max_entries);
|
||||
return m_impl->Read(out_count, out_entries, max_entries);
|
||||
}
|
||||
|
||||
Result DirectoryAccessor::GetEntryCount(s64 *out) {
|
||||
return this->impl->GetEntryCount(out);
|
||||
return m_impl->GetEntryCount(out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace ams::fs::impl {
|
||||
class DirectoryAccessor : public util::IntrusiveListBaseNode<DirectoryAccessor>, public Newable {
|
||||
NON_COPYABLE(DirectoryAccessor);
|
||||
private:
|
||||
std::unique_ptr<fsa::IDirectory> impl;
|
||||
FileSystemAccessor &parent;
|
||||
std::unique_ptr<fsa::IDirectory> m_impl;
|
||||
FileSystemAccessor &m_parent;
|
||||
public:
|
||||
DirectoryAccessor(std::unique_ptr<fsa::IDirectory>&& d, FileSystemAccessor &p);
|
||||
~DirectoryAccessor();
|
||||
@@ -32,7 +32,7 @@ namespace ams::fs::impl {
|
||||
Result Read(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries);
|
||||
Result GetEntryCount(s64 *out);
|
||||
|
||||
FileSystemAccessor *GetParent() const { return std::addressof(this->parent); }
|
||||
FileSystemAccessor *GetParent() const { return std::addressof(m_parent); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,20 +22,20 @@
|
||||
namespace ams::fs::impl {
|
||||
|
||||
FileAccessor::FileAccessor(std::unique_ptr<fsa::IFile>&& f, FileSystemAccessor *p, OpenMode mode)
|
||||
: impl(std::move(f)), parent(p), write_state(WriteState::None), write_result(ResultSuccess()), open_mode(mode)
|
||||
: m_impl(std::move(f)), m_parent(p), m_write_state(WriteState::None), m_write_result(ResultSuccess()), m_open_mode(mode)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
FileAccessor::~FileAccessor() {
|
||||
/* Ensure that all files are flushed. */
|
||||
if (R_SUCCEEDED(this->write_result)) {
|
||||
AMS_FS_ABORT_UNLESS_WITH_RESULT(this->write_state != WriteState::NeedsFlush, fs::ResultNeedFlush());
|
||||
if (R_SUCCEEDED(m_write_result)) {
|
||||
AMS_FS_ABORT_UNLESS_WITH_RESULT(m_write_state != WriteState::NeedsFlush, fs::ResultNeedFlush());
|
||||
}
|
||||
this->impl.reset();
|
||||
m_impl.reset();
|
||||
|
||||
if (this->parent != nullptr) {
|
||||
this->parent->NotifyCloseFile(this);
|
||||
if (m_parent != nullptr) {
|
||||
m_parent->NotifyCloseFile(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace ams::fs::impl {
|
||||
}
|
||||
|
||||
Result FileAccessor::ReadWithoutCacheAccessLog(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option) {
|
||||
return this->impl->Read(out, offset, buf, size, option);
|
||||
return m_impl->Read(out, offset, buf, size, option);
|
||||
}
|
||||
|
||||
Result FileAccessor::Read(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option) {
|
||||
@@ -54,11 +54,11 @@ namespace ams::fs::impl {
|
||||
FileHandle handle = { this };
|
||||
|
||||
/* Fail after a write fails. */
|
||||
R_UNLESS(R_SUCCEEDED(this->write_result), AMS_FS_IMPL_ACCESS_LOG_WITH_NAME(this->write_result, handle, "ReadFile", AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_FILE(out, offset, size)));
|
||||
R_UNLESS(R_SUCCEEDED(m_write_result), AMS_FS_IMPL_ACCESS_LOG_WITH_NAME(m_write_result, handle, "ReadFile", AMS_FS_IMPL_ACCESS_LOG_FORMAT_READ_FILE(out, offset, size)));
|
||||
|
||||
/* TODO: Support cache. */
|
||||
const bool use_path_cache = this->parent != nullptr && this->file_path_hash != nullptr;
|
||||
const bool use_data_cache = /* TODO */false && this->parent != nullptr && this->parent->IsFileDataCacheAttachable();
|
||||
const bool use_path_cache = m_parent != nullptr && m_file_path_hash != nullptr;
|
||||
const bool use_data_cache = /* TODO */false && m_parent != nullptr && m_parent->IsFileDataCacheAttachable();
|
||||
|
||||
if (use_path_cache && use_data_cache && false) {
|
||||
/* TODO */
|
||||
@@ -70,14 +70,14 @@ namespace ams::fs::impl {
|
||||
|
||||
Result FileAccessor::Write(s64 offset, const void *buf, size_t size, const WriteOption &option) {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(this->write_result);
|
||||
R_TRY(m_write_result);
|
||||
|
||||
auto setter = MakeScopedSetter(this->write_state, WriteState::Failed);
|
||||
if (this->file_path_hash != nullptr && /* TODO */ false) {
|
||||
auto setter = MakeScopedSetter(m_write_state, WriteState::Failed);
|
||||
if (m_file_path_hash != nullptr && /* TODO */ false) {
|
||||
/* TODO */
|
||||
AMS_ABORT();
|
||||
} else {
|
||||
R_TRY(this->UpdateLastResult(this->impl->Write(offset, buf, size, option)));
|
||||
R_TRY(this->UpdateLastResult(m_impl->Write(offset, buf, size, option)));
|
||||
}
|
||||
|
||||
setter.Set(option.HasFlushFlag() ? WriteState::None : WriteState::NeedsFlush);
|
||||
@@ -87,10 +87,10 @@ namespace ams::fs::impl {
|
||||
|
||||
Result FileAccessor::Flush() {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(this->write_result);
|
||||
R_TRY(m_write_result);
|
||||
|
||||
auto setter = MakeScopedSetter(this->write_state, WriteState::Failed);
|
||||
R_TRY(this->UpdateLastResult(this->impl->Flush()));
|
||||
auto setter = MakeScopedSetter(m_write_state, WriteState::Failed);
|
||||
R_TRY(this->UpdateLastResult(m_impl->Flush()));
|
||||
setter.Set(WriteState::None);
|
||||
|
||||
return ResultSuccess();
|
||||
@@ -98,14 +98,14 @@ namespace ams::fs::impl {
|
||||
|
||||
Result FileAccessor::SetSize(s64 size) {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(this->write_result);
|
||||
R_TRY(m_write_result);
|
||||
|
||||
const WriteState old_write_state = this->write_state;
|
||||
auto setter = MakeScopedSetter(this->write_state, WriteState::Failed);
|
||||
const WriteState old_write_state = m_write_state;
|
||||
auto setter = MakeScopedSetter(m_write_state, WriteState::Failed);
|
||||
|
||||
R_TRY(this->UpdateLastResult(this->impl->SetSize(size)));
|
||||
R_TRY(this->UpdateLastResult(m_impl->SetSize(size)));
|
||||
|
||||
if (this->file_path_hash != nullptr) {
|
||||
if (m_file_path_hash != nullptr) {
|
||||
/* TODO: invalidate path cache */
|
||||
}
|
||||
|
||||
@@ -115,13 +115,13 @@ namespace ams::fs::impl {
|
||||
|
||||
Result FileAccessor::GetSize(s64 *out) {
|
||||
/* Fail after a write fails. */
|
||||
R_TRY(this->write_result);
|
||||
R_TRY(m_write_result);
|
||||
|
||||
return this->impl->GetSize(out);
|
||||
return m_impl->GetSize(out);
|
||||
}
|
||||
|
||||
Result FileAccessor::OperateRange(void *dst, size_t dst_size, OperationId operation, s64 offset, s64 size, const void *src, size_t src_size) {
|
||||
return this->impl->OperateRange(dst, dst_size, operation, offset, size, src, src_size);
|
||||
return m_impl->OperateRange(dst, dst_size, operation, offset, size, src, src_size);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,13 +30,13 @@ namespace ams::fs::impl {
|
||||
class FileAccessor : public util::IntrusiveListBaseNode<FileAccessor>, public Newable {
|
||||
NON_COPYABLE(FileAccessor);
|
||||
private:
|
||||
std::unique_ptr<fsa::IFile> impl;
|
||||
FileSystemAccessor * const parent;
|
||||
WriteState write_state;
|
||||
Result write_result;
|
||||
const OpenMode open_mode;
|
||||
std::unique_ptr<FilePathHash> file_path_hash;
|
||||
s32 path_hash_index;
|
||||
std::unique_ptr<fsa::IFile> m_impl;
|
||||
FileSystemAccessor * const m_parent;
|
||||
WriteState m_write_state;
|
||||
Result m_write_result;
|
||||
const OpenMode m_open_mode;
|
||||
std::unique_ptr<FilePathHash> m_file_path_hash;
|
||||
s32 m_path_hash_index;
|
||||
public:
|
||||
FileAccessor(std::unique_ptr<fsa::IFile>&& f, FileSystemAccessor *p, OpenMode mode);
|
||||
~FileAccessor();
|
||||
@@ -48,9 +48,9 @@ namespace ams::fs::impl {
|
||||
Result GetSize(s64 *out);
|
||||
Result OperateRange(void *dst, size_t dst_size, OperationId operation, s64 offset, s64 size, const void *src, size_t src_size);
|
||||
|
||||
OpenMode GetOpenMode() const { return this->open_mode; }
|
||||
WriteState GetWriteState() const { return this->write_state; }
|
||||
FileSystemAccessor *GetParent() const { return this->parent; }
|
||||
OpenMode GetOpenMode() const { return m_open_mode; }
|
||||
WriteState GetWriteState() const { return m_write_state; }
|
||||
FileSystemAccessor *GetParent() const { return m_parent; }
|
||||
|
||||
void SetFilePathHash(std::unique_ptr<FilePathHash>&& file_path_hash, s32 index);
|
||||
Result ReadWithoutCacheAccessLog(size_t *out, s64 offset, void *buf, size_t size, const ReadOption &option);
|
||||
@@ -59,7 +59,7 @@ namespace ams::fs::impl {
|
||||
|
||||
ALWAYS_INLINE Result UpdateLastResult(Result r) {
|
||||
if (!fs::ResultNotEnoughFreeSpace::Includes(r)) {
|
||||
this->write_result = r;
|
||||
m_write_result = r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -60,34 +60,34 @@ namespace ams::fs::impl {
|
||||
}
|
||||
|
||||
FileSystemAccessor::FileSystemAccessor(const char *n, std::unique_ptr<fsa::IFileSystem> &&fs, std::unique_ptr<fsa::ICommonMountNameGenerator> &&generator)
|
||||
: impl(std::move(fs)), open_list_lock(), mount_name_generator(std::move(generator)),
|
||||
access_log_enabled(false), data_cache_attachable(false), path_cache_attachable(false), path_cache_attached(false), multi_commit_supported(false)
|
||||
: m_impl(std::move(fs)), m_open_list_lock(), m_mount_name_generator(std::move(generator)),
|
||||
m_access_log_enabled(false), m_data_cache_attachable(false), m_path_cache_attachable(false), m_path_cache_attached(false), m_multi_commit_supported(false)
|
||||
{
|
||||
R_ABORT_UNLESS(ValidateMountName(n));
|
||||
std::strncpy(this->name.str, n, MountNameLengthMax);
|
||||
this->name.str[MountNameLengthMax] = 0;
|
||||
std::strncpy(m_name.str, n, MountNameLengthMax);
|
||||
m_name.str[MountNameLengthMax] = 0;
|
||||
}
|
||||
|
||||
FileSystemAccessor::~FileSystemAccessor() {
|
||||
std::scoped_lock lk(this->open_list_lock);
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
|
||||
/* TODO: Iterate over list entries. */
|
||||
|
||||
if (!this->open_file_list.empty()) { R_ABORT_UNLESS(fs::ResultFileNotClosed()); }
|
||||
if (!this->open_dir_list.empty()) { R_ABORT_UNLESS(fs::ResultDirectoryNotClosed()); }
|
||||
if (!m_open_file_list.empty()) { R_ABORT_UNLESS(fs::ResultFileNotClosed()); }
|
||||
if (!m_open_dir_list.empty()) { R_ABORT_UNLESS(fs::ResultDirectoryNotClosed()); }
|
||||
|
||||
if (this->path_cache_attached) {
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Invalidate path cache */
|
||||
}
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetCommonMountName(char *dst, size_t dst_size) const {
|
||||
R_UNLESS(this->mount_name_generator != nullptr, fs::ResultPreconditionViolation());
|
||||
return this->mount_name_generator->GenerateCommonMountName(dst, dst_size);
|
||||
R_UNLESS(m_mount_name_generator != nullptr, fs::ResultPreconditionViolation());
|
||||
return m_mount_name_generator->GenerateCommonMountName(dst, dst_size);
|
||||
}
|
||||
|
||||
std::shared_ptr<fssrv::impl::FileSystemInterfaceAdapter> FileSystemAccessor::GetMultiCommitTarget() {
|
||||
if (this->multi_commit_supported) {
|
||||
if (m_multi_commit_supported) {
|
||||
/* TODO: Support multi commit. */
|
||||
AMS_ABORT();
|
||||
}
|
||||
@@ -95,90 +95,90 @@ namespace ams::fs::impl {
|
||||
}
|
||||
|
||||
void FileSystemAccessor::NotifyCloseFile(FileAccessor *f) {
|
||||
std::scoped_lock lk(this->open_list_lock);
|
||||
Remove(this->open_file_list, f);
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
Remove(m_open_file_list, f);
|
||||
}
|
||||
|
||||
void FileSystemAccessor::NotifyCloseDirectory(DirectoryAccessor *d) {
|
||||
std::scoped_lock lk(this->open_list_lock);
|
||||
Remove(this->open_dir_list, d);
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
Remove(m_open_dir_list, d);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::CreateFile(const char *path, s64 size, int option) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
if (this->path_cache_attached) {
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Path cache */
|
||||
R_TRY(this->impl->CreateFile(path, size, option));
|
||||
R_TRY(m_impl->CreateFile(path, size, option));
|
||||
} else {
|
||||
R_TRY(this->impl->CreateFile(path, size, option));
|
||||
R_TRY(m_impl->CreateFile(path, size, option));
|
||||
}
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::DeleteFile(const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->DeleteFile(path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->DeleteFile(path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::CreateDirectory(const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->CreateDirectory(path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->CreateDirectory(path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::DeleteDirectory(const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->DeleteDirectory(path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->DeleteDirectory(path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::DeleteDirectoryRecursively(const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->DeleteDirectoryRecursively(path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->DeleteDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::RenameFile(const char *old_path, const char *new_path) {
|
||||
R_TRY(ValidatePath(this->name.str, old_path));
|
||||
R_TRY(ValidatePath(this->name.str, new_path));
|
||||
if (this->path_cache_attached) {
|
||||
R_TRY(ValidatePath(m_name.str, old_path));
|
||||
R_TRY(ValidatePath(m_name.str, new_path));
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Path cache */
|
||||
R_TRY(this->impl->RenameFile(old_path, new_path));
|
||||
R_TRY(m_impl->RenameFile(old_path, new_path));
|
||||
} else {
|
||||
R_TRY(this->impl->RenameFile(old_path, new_path));
|
||||
R_TRY(m_impl->RenameFile(old_path, new_path));
|
||||
}
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::RenameDirectory(const char *old_path, const char *new_path) {
|
||||
R_TRY(ValidatePath(this->name.str, old_path));
|
||||
R_TRY(ValidatePath(this->name.str, new_path));
|
||||
if (this->path_cache_attached) {
|
||||
R_TRY(ValidatePath(m_name.str, old_path));
|
||||
R_TRY(ValidatePath(m_name.str, new_path));
|
||||
if (m_path_cache_attached) {
|
||||
/* TODO: Path cache */
|
||||
R_TRY(this->impl->RenameDirectory(old_path, new_path));
|
||||
R_TRY(m_impl->RenameDirectory(old_path, new_path));
|
||||
} else {
|
||||
R_TRY(this->impl->RenameDirectory(old_path, new_path));
|
||||
R_TRY(m_impl->RenameDirectory(old_path, new_path));
|
||||
}
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetEntryType(DirectoryEntryType *out, const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->GetEntryType(out, path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->GetEntryType(out, path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::OpenFile(std::unique_ptr<FileAccessor> *out_file, const char *path, OpenMode mode) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
|
||||
std::unique_ptr<fsa::IFile> file;
|
||||
R_TRY(this->impl->OpenFile(std::addressof(file), path, mode));
|
||||
R_TRY(m_impl->OpenFile(std::addressof(file), path, mode));
|
||||
|
||||
auto accessor = new FileAccessor(std::move(file), this, mode);
|
||||
R_UNLESS(accessor != nullptr, fs::ResultAllocationFailureInFileSystemAccessorA());
|
||||
|
||||
{
|
||||
std::scoped_lock lk(this->open_list_lock);
|
||||
this->open_file_list.push_back(*accessor);
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
m_open_file_list.push_back(*accessor);
|
||||
}
|
||||
|
||||
if (this->path_cache_attached) {
|
||||
if (m_path_cache_attached) {
|
||||
if (mode & OpenMode_AllowAppend) {
|
||||
/* TODO: Append Path cache */
|
||||
} else {
|
||||
@@ -191,17 +191,17 @@ namespace ams::fs::impl {
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::OpenDirectory(std::unique_ptr<DirectoryAccessor> *out_dir, const char *path, OpenDirectoryMode mode) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
|
||||
std::unique_ptr<fsa::IDirectory> dir;
|
||||
R_TRY(this->impl->OpenDirectory(std::addressof(dir), path, mode));
|
||||
R_TRY(m_impl->OpenDirectory(std::addressof(dir), path, mode));
|
||||
|
||||
auto accessor = new DirectoryAccessor(std::move(dir), *this);
|
||||
R_UNLESS(accessor != nullptr, fs::ResultAllocationFailureInFileSystemAccessorB());
|
||||
|
||||
{
|
||||
std::scoped_lock lk(this->open_list_lock);
|
||||
this->open_dir_list.push_back(*accessor);
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
m_open_dir_list.push_back(*accessor);
|
||||
}
|
||||
|
||||
out_dir->reset(accessor);
|
||||
@@ -210,33 +210,33 @@ namespace ams::fs::impl {
|
||||
|
||||
Result FileSystemAccessor::Commit() {
|
||||
{
|
||||
std::scoped_lock lk(this->open_list_lock);
|
||||
R_ABORT_UNLESS(ValidateNoOpenWriteModeFiles(this->open_file_list));
|
||||
std::scoped_lock lk(m_open_list_lock);
|
||||
R_ABORT_UNLESS(ValidateNoOpenWriteModeFiles(m_open_file_list));
|
||||
}
|
||||
return this->impl->Commit();
|
||||
return m_impl->Commit();
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetFreeSpaceSize(s64 *out, const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->GetFreeSpaceSize(out, path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->GetFreeSpaceSize(out, path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetTotalSpaceSize(s64 *out, const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->GetTotalSpaceSize(out, path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->GetTotalSpaceSize(out, path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::CleanDirectoryRecursively(const char *path) {
|
||||
R_TRY(ValidatePath(this->name.str, path));
|
||||
return this->impl->CleanDirectoryRecursively(path);
|
||||
R_TRY(ValidatePath(m_name.str, path));
|
||||
return m_impl->CleanDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::GetFileTimeStampRaw(FileTimeStampRaw *out, const char *path) {
|
||||
return this->impl->GetFileTimeStampRaw(out, path);
|
||||
return m_impl->GetFileTimeStampRaw(out, path);
|
||||
}
|
||||
|
||||
Result FileSystemAccessor::QueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fsa::QueryId query, const char *path) {
|
||||
return this->impl->QueryEntry(dst, dst_size, src, src_size, query, path);
|
||||
return m_impl->QueryEntry(dst, dst_size, src, src_size, query, path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,17 +31,17 @@ namespace ams::fs::impl {
|
||||
using FileList = util::IntrusiveListBaseTraits<FileAccessor>::ListType;
|
||||
using DirList = util::IntrusiveListBaseTraits<DirectoryAccessor>::ListType;
|
||||
private:
|
||||
MountName name;
|
||||
std::unique_ptr<fsa::IFileSystem> impl;
|
||||
FileList open_file_list;
|
||||
DirList open_dir_list;
|
||||
os::SdkMutex open_list_lock;
|
||||
std::unique_ptr<fsa::ICommonMountNameGenerator> mount_name_generator;
|
||||
bool access_log_enabled;
|
||||
bool data_cache_attachable;
|
||||
bool path_cache_attachable;
|
||||
bool path_cache_attached;
|
||||
bool multi_commit_supported;
|
||||
MountName m_name;
|
||||
std::unique_ptr<fsa::IFileSystem> m_impl;
|
||||
FileList m_open_file_list;
|
||||
DirList m_open_dir_list;
|
||||
os::SdkMutex m_open_list_lock;
|
||||
std::unique_ptr<fsa::ICommonMountNameGenerator> m_mount_name_generator;
|
||||
bool m_access_log_enabled;
|
||||
bool m_data_cache_attachable;
|
||||
bool m_path_cache_attachable;
|
||||
bool m_path_cache_attached;
|
||||
bool m_multi_commit_supported;
|
||||
public:
|
||||
FileSystemAccessor(const char *name, std::unique_ptr<fsa::IFileSystem> &&fs, std::unique_ptr<fsa::ICommonMountNameGenerator> &&generator = nullptr);
|
||||
virtual ~FileSystemAccessor();
|
||||
@@ -63,32 +63,32 @@ namespace ams::fs::impl {
|
||||
Result GetFileTimeStampRaw(FileTimeStampRaw *out, const char *path);
|
||||
Result QueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fsa::QueryId query, const char *path);
|
||||
|
||||
const char *GetName() const { return this->name.str; }
|
||||
const char *GetName() const { return m_name.str; }
|
||||
Result GetCommonMountName(char *dst, size_t dst_size) const;
|
||||
|
||||
void SetAccessLogEnabled(bool en) { this->access_log_enabled = en; }
|
||||
void SetFileDataCacheAttachable(bool en) { this->data_cache_attachable = en; }
|
||||
void SetPathBasedFileDataCacheAttachable(bool en) { this->path_cache_attachable = en; }
|
||||
void SetMultiCommitSupported(bool en) { this->multi_commit_supported = en; }
|
||||
void SetAccessLogEnabled(bool en) { m_access_log_enabled = en; }
|
||||
void SetFileDataCacheAttachable(bool en) { m_data_cache_attachable = en; }
|
||||
void SetPathBasedFileDataCacheAttachable(bool en) { m_path_cache_attachable = en; }
|
||||
void SetMultiCommitSupported(bool en) { m_multi_commit_supported = en; }
|
||||
|
||||
bool IsEnabledAccessLog() const { return this->access_log_enabled; }
|
||||
bool IsFileDataCacheAttachable() const { return this->data_cache_attachable; }
|
||||
bool IsPathBasedFileDataCacheAttachable() const { return this->path_cache_attachable; }
|
||||
bool IsEnabledAccessLog() const { return m_access_log_enabled; }
|
||||
bool IsFileDataCacheAttachable() const { return m_data_cache_attachable; }
|
||||
bool IsPathBasedFileDataCacheAttachable() const { return m_path_cache_attachable; }
|
||||
|
||||
void AttachPathBasedFileDataCache() {
|
||||
if (this->IsPathBasedFileDataCacheAttachable()) {
|
||||
this->path_cache_attached = true;
|
||||
m_path_cache_attached = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DetachPathBasedFileDataCache() {
|
||||
this->path_cache_attached = false;
|
||||
m_path_cache_attached = false;
|
||||
}
|
||||
|
||||
std::shared_ptr<fssrv::impl::FileSystemInterfaceAdapter> GetMultiCommitTarget();
|
||||
|
||||
fsa::IFileSystem *GetRawFileSystemUnsafe() {
|
||||
return this->impl.get();
|
||||
return m_impl.get();
|
||||
}
|
||||
private:
|
||||
void NotifyCloseFile(FileAccessor *f);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ams::fs::impl {
|
||||
}
|
||||
|
||||
bool MountTable::CanAcceptMountName(const char *name) {
|
||||
for (const auto &fs : this->fs_list) {
|
||||
for (const auto &fs : m_fs_list) {
|
||||
if (MatchesName(fs, name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -36,18 +36,18 @@ namespace ams::fs::impl {
|
||||
}
|
||||
|
||||
Result MountTable::Mount(std::unique_ptr<FileSystemAccessor> &&fs) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
R_UNLESS(this->CanAcceptMountName(fs->GetName()), fs::ResultMountNameAlreadyExists());
|
||||
|
||||
this->fs_list.push_back(*fs.release());
|
||||
m_fs_list.push_back(*fs.release());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result MountTable::Find(FileSystemAccessor **out, const char *name) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
for (auto &fs : this->fs_list) {
|
||||
for (auto &fs : m_fs_list) {
|
||||
if (MatchesName(fs, name)) {
|
||||
*out = std::addressof(fs);
|
||||
return ResultSuccess();
|
||||
@@ -58,12 +58,12 @@ namespace ams::fs::impl {
|
||||
}
|
||||
|
||||
void MountTable::Unmount(const char *name) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
for (auto it = this->fs_list.cbegin(); it != this->fs_list.cend(); it++) {
|
||||
for (auto it = m_fs_list.cbegin(); it != m_fs_list.cend(); it++) {
|
||||
if (MatchesName(*it, name)) {
|
||||
auto p = std::addressof(*it);
|
||||
this->fs_list.erase(it);
|
||||
m_fs_list.erase(it);
|
||||
delete p;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace ams::fs::impl {
|
||||
private:
|
||||
using FileSystemList = util::IntrusiveListBaseTraits<FileSystemAccessor>::ListType;
|
||||
private:
|
||||
FileSystemList fs_list;
|
||||
os::SdkMutex mutex;
|
||||
FileSystemList m_fs_list;
|
||||
os::SdkMutex m_mutex;
|
||||
public:
|
||||
constexpr MountTable() : fs_list(), mutex() { /* ... */ }
|
||||
constexpr MountTable() : m_fs_list(), m_mutex() { /* ... */ }
|
||||
private:
|
||||
bool CanAcceptMountName(const char *name);
|
||||
public:
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace ams::fs::impl {
|
||||
|
||||
namespace {
|
||||
|
||||
MountTable g_mount_table;
|
||||
constinit MountTable g_mount_table;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user