fs/system: deduplicate RomFs code
This commit is contained in:
@@ -17,23 +17,22 @@
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
s64 HierarchicalRomFileTable::QueryDirectoryEntryStorageSize(u32 count) {
|
||||
const size_t real_count = count + ReservedDirectoryCount;
|
||||
return DirectoryEntryMapTable::QueryKeyValueStorageSize(real_count) + real_count * (RomPathTool::MaxPathLength + 1) * sizeof(RomPathChar);
|
||||
}
|
||||
|
||||
s64 HierarchicalRomFileTable::QueryDirectoryEntryBucketStorageSize(s64 count) {
|
||||
return DirectoryEntryMapTable::QueryBucketStorageSize(count);
|
||||
}
|
||||
|
||||
s64 HierarchicalRomFileTable::QueryFileEntryStorageSize(u32 count) {
|
||||
return FileEntryMapTable::QueryKeyValueStorageSize(count) + count * (RomPathTool::MaxPathLength + 1) * sizeof(RomPathChar);
|
||||
size_t HierarchicalRomFileTable::QueryDirectoryEntrySize(size_t aux_size) {
|
||||
return DirectoryEntryMapTable::QueryEntrySize(aux_size);
|
||||
}
|
||||
|
||||
s64 HierarchicalRomFileTable::QueryFileEntryBucketStorageSize(s64 count) {
|
||||
return FileEntryMapTable::QueryBucketStorageSize(count);
|
||||
}
|
||||
|
||||
size_t HierarchicalRomFileTable::QueryFileEntrySize(size_t aux_size) {
|
||||
return FileEntryMapTable::QueryEntrySize(aux_size);
|
||||
}
|
||||
|
||||
Result HierarchicalRomFileTable::Format(SubStorage dir_bucket, SubStorage file_bucket) {
|
||||
s64 dir_bucket_size;
|
||||
R_TRY(dir_bucket.GetSize(std::addressof(dir_bucket_size)));
|
||||
@@ -69,7 +68,7 @@ namespace ams::fs {
|
||||
Position root_pos = RootPosition;
|
||||
EntryKey root_key = {};
|
||||
root_key.key.parent = root_pos;
|
||||
RomPathTool::InitializeRomEntryName(std::addressof(root_key.name));
|
||||
RomPathTool::InitEntryName(std::addressof(root_key.name));
|
||||
RomDirectoryEntry root_entry = {
|
||||
.next = InvalidPosition,
|
||||
.dir = InvalidPosition,
|
||||
@@ -99,7 +98,7 @@ namespace ams::fs {
|
||||
R_CONVERT(fs::ResultDbmKeyFull, fs::ResultDbmDirectoryEntryFull())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
*out = ConvertToDirectoryId(new_pos);
|
||||
*out = PositionToDirectoryId(new_pos);
|
||||
|
||||
if (parent_entry.dir == InvalidPosition) {
|
||||
parent_entry.dir = new_pos;
|
||||
@@ -146,7 +145,7 @@ namespace ams::fs {
|
||||
R_CONVERT(fs::ResultDbmKeyFull, fs::ResultDbmFileEntryFull())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
*out = ConvertToFileId(new_pos);
|
||||
*out = PositionToFileId(new_pos);
|
||||
|
||||
if (parent_entry.file == InvalidPosition) {
|
||||
parent_entry.file = new_pos;
|
||||
@@ -185,7 +184,7 @@ namespace ams::fs {
|
||||
RomDirectoryEntry entry = {};
|
||||
R_TRY(this->GetDirectoryEntry(std::addressof(pos), std::addressof(entry), key));
|
||||
|
||||
*out = ConvertToDirectoryId(pos);
|
||||
*out = PositionToDirectoryId(pos);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -201,7 +200,7 @@ namespace ams::fs {
|
||||
RomFileEntry entry = {};
|
||||
R_TRY(this->GetFileEntry(std::addressof(pos), std::addressof(entry), key));
|
||||
|
||||
*out = ConvertToFileId(pos);
|
||||
*out = PositionToFileId(pos);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -353,7 +352,7 @@ namespace ams::fs {
|
||||
R_TRY(this->GetDirectoryEntry(std::addressof(dir_pos), std::addressof(dir_entry), dir_key));
|
||||
|
||||
Position parent_pos = dir_pos;
|
||||
while (!parser->IsFinished()) {
|
||||
while (!parser->IsParseFinished()) {
|
||||
EntryKey old_key = dir_key;
|
||||
|
||||
R_TRY(parser->GetNextDirectoryName(std::addressof(dir_key.name)));
|
||||
@@ -492,7 +491,7 @@ namespace ams::fs {
|
||||
|
||||
Result HierarchicalRomFileTable::GetDirectoryEntry(RomDirectoryEntry *out_entry, RomDirectoryId id) {
|
||||
AMS_ASSERT(out_entry != nullptr);
|
||||
Position pos = ConvertToPosition(id);
|
||||
Position pos = DirectoryIdToPosition(id);
|
||||
|
||||
RomEntryKey key = {};
|
||||
const Result dir_res = this->dir_table.GetByPosition(std::addressof(key), out_entry, pos);
|
||||
@@ -524,7 +523,7 @@ namespace ams::fs {
|
||||
|
||||
Result HierarchicalRomFileTable::GetFileEntry(RomFileEntry *out_entry, RomFileId id) {
|
||||
AMS_ASSERT(out_entry != nullptr);
|
||||
Position pos = ConvertToPosition(id);
|
||||
Position pos = FileIdToPosition(id);
|
||||
|
||||
RomEntryKey key = {};
|
||||
const Result file_res = this->file_table.GetByPosition(std::addressof(key), out_entry, pos);
|
||||
@@ -28,9 +28,8 @@ namespace ams::fs::RomPathTool {
|
||||
|
||||
this->prev_path_start = path;
|
||||
this->prev_path_end = path;
|
||||
this->next_path = path + 1;
|
||||
while (IsSeparator(this->next_path[0])) {
|
||||
this->next_path++;
|
||||
for (this->next_path = path + 1; IsSeparator(this->next_path[0]); ++this->next_path) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
@@ -43,12 +42,13 @@ namespace ams::fs::RomPathTool {
|
||||
this->finished = false;
|
||||
}
|
||||
|
||||
bool PathParser::IsFinished() const {
|
||||
bool PathParser::IsParseFinished() const {
|
||||
return this->finished;
|
||||
}
|
||||
|
||||
bool PathParser::IsDirectoryPath() const {
|
||||
AMS_ASSERT(this->next_path != nullptr);
|
||||
|
||||
if (IsNullTerminator(this->next_path[0]) && IsSeparator(this->next_path[-1])) {
|
||||
return true;
|
||||
}
|
||||
@@ -57,11 +57,47 @@ namespace ams::fs::RomPathTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsParentDirectory(this->next_path)) {
|
||||
return true;
|
||||
return IsParentDirectory(this->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);
|
||||
|
||||
/* Set the current path to output. */
|
||||
out->length = this->prev_path_end - this->prev_path_start;
|
||||
out->path = this->prev_path_start;
|
||||
|
||||
/* Parse the next path. */
|
||||
this->prev_path_start = this->next_path;
|
||||
const RomPathChar *cur = this->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;
|
||||
|
||||
while (IsSeparator(this->next_path[0])) {
|
||||
++this->next_path;
|
||||
}
|
||||
if (IsNullTerminator(this->next_path[0])) {
|
||||
this->finished = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (IsNullTerminator(cur[name_len])) {
|
||||
this->finished = true;
|
||||
this->next_path = cur + name_len;
|
||||
this->prev_path_end = cur + name_len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result PathParser::GetAsDirectoryName(RomEntryName *out) const {
|
||||
@@ -92,45 +128,6 @@ namespace ams::fs::RomPathTool {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Set the current path to output. */
|
||||
out->length = this->prev_path_end - this->prev_path_start;
|
||||
out->path = this->prev_path_start;
|
||||
|
||||
/* Parse the next path. */
|
||||
this->prev_path_start = this->next_path;
|
||||
const RomPathChar *cur = this->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;
|
||||
|
||||
while (IsSeparator(this->next_path[0])) {
|
||||
this->next_path++;
|
||||
}
|
||||
if (IsNullTerminator(this->next_path[0])) {
|
||||
this->finished = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (IsNullTerminator(cur[name_len])) {
|
||||
this->finished = true;
|
||||
this->prev_path_end = this->next_path = cur + name_len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetParentDirectoryName(RomEntryName *out, const RomEntryName &cur, const RomPathChar *p) {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
AMS_ASSERT(p != nullptr);
|
||||
@@ -140,7 +137,7 @@ namespace ams::fs::RomPathTool {
|
||||
|
||||
s32 depth = 1;
|
||||
if (IsParentDirectory(cur)) {
|
||||
depth++;
|
||||
++depth;
|
||||
}
|
||||
|
||||
if (cur.path > p) {
|
||||
@@ -149,7 +146,7 @@ namespace ams::fs::RomPathTool {
|
||||
while (head >= p) {
|
||||
if (IsSeparator(*head)) {
|
||||
if (IsCurrentDirectory(head + 1, len)) {
|
||||
depth++;
|
||||
++depth;
|
||||
}
|
||||
|
||||
if (IsParentDirectory(head + 1, len)) {
|
||||
@@ -162,16 +159,16 @@ namespace ams::fs::RomPathTool {
|
||||
}
|
||||
|
||||
while (IsSeparator(*head)) {
|
||||
head--;
|
||||
--head;
|
||||
}
|
||||
|
||||
end = head;
|
||||
len = 0;
|
||||
depth--;
|
||||
--depth;
|
||||
}
|
||||
|
||||
len++;
|
||||
head--;
|
||||
++len;
|
||||
--head;
|
||||
}
|
||||
|
||||
R_UNLESS(depth == 0, fs::ResultDirectoryUnobtainable());
|
||||
@@ -182,10 +179,10 @@ namespace ams::fs::RomPathTool {
|
||||
}
|
||||
|
||||
if (end <= p) {
|
||||
out->path = p;
|
||||
out->path = p;
|
||||
out->length = 0;
|
||||
} else {
|
||||
out->path = start;
|
||||
out->path = start;
|
||||
out->length = end - start + 1;
|
||||
}
|
||||
|
||||
@@ -316,7 +316,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()->ConvertToFileId(file_pos)));
|
||||
R_TRY(this->parent->GetRomFileTable()->OpenFile(std::addressof(file_info), this->parent->GetRomFileTable()->PositionToFileId(file_pos)));
|
||||
out_entries[i].file_size = file_info.size.Get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user