fs: update romfs types

This commit is contained in:
Michael Scire 2022-03-28 13:57:06 -07:00
parent a8b52dc123
commit 28f11a86fd
9 changed files with 156 additions and 217 deletions

View file

@ -17,19 +17,19 @@
namespace ams::fs {
s64 HierarchicalRomFileTable::QueryDirectoryEntryBucketStorageSize(s64 count) {
s64 HierarchicalRomFileTable::QueryDirectoryEntryBucketStorageSize(StorageSizeType count) {
return DirectoryEntryMapTable::QueryBucketStorageSize(count);
}
size_t HierarchicalRomFileTable::QueryDirectoryEntrySize(size_t aux_size) {
s64 HierarchicalRomFileTable::QueryDirectoryEntrySize(StorageSizeType aux_size) {
return DirectoryEntryMapTable::QueryEntrySize(aux_size);
}
s64 HierarchicalRomFileTable::QueryFileEntryBucketStorageSize(s64 count) {
s64 HierarchicalRomFileTable::QueryFileEntryBucketStorageSize(StorageSizeType count) {
return FileEntryMapTable::QueryBucketStorageSize(count);
}
size_t HierarchicalRomFileTable::QueryFileEntrySize(size_t aux_size) {
s64 HierarchicalRomFileTable::QueryFileEntrySize(StorageSizeType aux_size) {
return FileEntryMapTable::QueryEntrySize(aux_size);
}
@ -68,7 +68,6 @@ namespace ams::fs {
Position root_pos = RootPosition;
EntryKey root_key = {};
root_key.key.parent = root_pos;
RomPathTool::InitEntryName(std::addressof(root_key.name));
RomDirectoryEntry root_entry = {
.next = InvalidPosition,
.dir = InvalidPosition,
@ -77,7 +76,7 @@ namespace ams::fs {
R_RETURN(m_dir_table.Add(std::addressof(root_pos), root_key, root_entry));
}
Result HierarchicalRomFileTable::CreateDirectory(RomDirectoryId *out, const RomPathChar *path, const DirectoryInfo &info) {
Result HierarchicalRomFileTable::CreateDirectory(RomDirectoryId *out, const RomPathChar *path) {
AMS_ASSERT(out != nullptr);
AMS_ASSERT(path != nullptr);
@ -92,7 +91,6 @@ namespace ams::fs {
.dir = InvalidPosition,
.file = InvalidPosition,
};
AMS_UNUSED(info);
Position new_pos = 0;
R_TRY_CATCH(m_dir_table.Add(std::addressof(new_pos), new_key, new_entry)) {
@ -205,28 +203,6 @@ namespace ams::fs {
R_SUCCEED();
}
Result HierarchicalRomFileTable::GetDirectoryInformation(DirectoryInfo *out, const RomPathChar *path) {
AMS_ASSERT(out != nullptr);
AMS_ASSERT(path != nullptr);
RomDirectoryEntry parent_entry = {};
EntryKey key = {};
R_TRY(this->FindDirectoryRecursive(std::addressof(key), std::addressof(parent_entry), path));
R_RETURN(this->GetDirectoryInformation(out, key));
}
Result HierarchicalRomFileTable::GetDirectoryInformation(DirectoryInfo *out, RomDirectoryId id) {
AMS_ASSERT(out != nullptr);
RomDirectoryEntry entry = {};
R_TRY(this->GetDirectoryEntry(std::addressof(entry), id));
AMS_UNUSED(out);
R_SUCCEED();
}
Result HierarchicalRomFileTable::OpenFile(FileInfo *out, const RomPathChar *path) {
AMS_ASSERT(out != nullptr);
AMS_ASSERT(path != nullptr);
@ -318,22 +294,22 @@ namespace ams::fs {
AMS_ASSERT(out_dir_entry_size != nullptr);
AMS_ASSERT(out_file_entry_size != nullptr);
*out_dir_entry_size = m_dir_table.GetTotalEntrySize();
*out_dir_entry_size = m_dir_table.GetTotalEntrySize();
*out_file_entry_size = m_file_table.GetTotalEntrySize();
R_SUCCEED();
}
Result HierarchicalRomFileTable::GetGrandParent(Position *out_pos, EntryKey *out_dir_key, RomDirectoryEntry *out_dir_entry, Position pos, RomPathTool::RomEntryName name, const RomPathChar *path) {
Result HierarchicalRomFileTable::GetParent(Position *out_pos, EntryKey *out_dir_key, RomDirectoryEntry *out_dir_entry, Position pos, RomPathTool::RomEntryName name, const RomPathChar *path) {
AMS_ASSERT(out_pos != nullptr);
AMS_ASSERT(out_dir_key != nullptr);
AMS_ASSERT(out_dir_entry != nullptr);
AMS_ASSERT(path != nullptr);
RomEntryKey gp_key = {};
RomDirectoryEntry gp_entry = {};
R_TRY(m_dir_table.GetByPosition(std::addressof(gp_key), std::addressof(gp_entry), pos));
out_dir_key->key.parent = gp_key.parent;
RomEntryKey p_key = {};
RomDirectoryEntry p_entry = {};
R_TRY(m_dir_table.GetByPosition(std::addressof(p_key), std::addressof(p_entry), pos));
out_dir_key->key = p_key;
R_TRY(RomPathTool::GetParentDirectoryName(std::addressof(out_dir_key->name), name, path));
R_TRY(this->GetDirectoryEntry(out_pos, out_dir_entry, *out_dir_key));
@ -362,13 +338,13 @@ namespace ams::fs {
R_TRY(parser->GetNextDirectoryName(std::addressof(dir_key.name)));
if (RomPathTool::IsCurrentDirectory(dir_key.name)) {
if (dir_key.name.IsCurrentDirectory()) {
dir_key = old_key;
continue;
} else if (RomPathTool::IsParentDirectory(dir_key.name)) {
} else if (dir_key.name.IsParentDirectory()) {
R_UNLESS(parent_pos != RootPosition, fs::ResultDirectoryUnobtainable());
R_TRY(this->GetGrandParent(std::addressof(parent_pos), std::addressof(dir_key), std::addressof(dir_entry), dir_key.key.parent, dir_key.name, path));
R_TRY(this->GetParent(std::addressof(parent_pos), std::addressof(dir_key), std::addressof(dir_entry), dir_key.key.parent, dir_key.name, path));
} else {
dir_key.key.parent = parent_pos;
R_TRY_CATCH(this->GetDirectoryEntry(std::addressof(dir_pos), std::addressof(dir_entry), dir_key)) {
@ -401,31 +377,31 @@ namespace ams::fs {
RomPathTool::RomEntryName name = {};
R_TRY(parser.GetAsDirectoryName(std::addressof(name)));
if (RomPathTool::IsCurrentDirectory(name)) {
if (name.IsCurrentDirectory()) {
*out_key = parent_key;
if (out_key->key.parent != RootPosition) {
Position pos = 0;
R_TRY(this->GetGrandParent(std::addressof(pos), std::addressof(parent_key), out_dir_entry, out_key->key.parent, out_key->name, path));
R_TRY(this->GetParent(std::addressof(pos), std::addressof(parent_key), out_dir_entry, out_key->key.parent, out_key->name, path));
}
} else if (RomPathTool::IsParentDirectory(name)) {
} else if (name.IsParentDirectory()) {
R_UNLESS(parent_pos != RootPosition, fs::ResultDirectoryUnobtainable());
Position pos = 0;
RomDirectoryEntry cur_entry = {};
R_TRY(this->GetGrandParent(std::addressof(pos), out_key, std::addressof(cur_entry), parent_key.key.parent, parent_key.name, path));
R_TRY(this->GetParent(std::addressof(pos), out_key, std::addressof(cur_entry), parent_key.key.parent, parent_key.name, path));
if (out_key->key.parent != RootPosition) {
R_TRY(this->GetGrandParent(std::addressof(pos), std::addressof(parent_key), out_dir_entry, out_key->key.parent, out_key->name, path));
R_TRY(this->GetParent(std::addressof(pos), std::addressof(parent_key), out_dir_entry, out_key->key.parent, out_key->name, path));
}
} else {
out_key->name = name;
out_key->key.parent = (out_key->name.length > 0) ? parent_pos : RootPosition;
out_key->key.parent = out_key->name.IsRootDirectory() ? RootPosition : parent_pos;
}
} else {
{
RomPathTool::RomEntryName name = {};
R_TRY(parser.GetAsDirectoryName(std::addressof(name)));
R_UNLESS(!RomPathTool::IsParentDirectory(name) || parent_pos != RootPosition, fs::ResultDirectoryUnobtainable());
R_UNLESS(!name.IsParentDirectory() || parent_pos != RootPosition, fs::ResultDirectoryUnobtainable());
}
R_UNLESS(!parser.IsDirectoryPath(), fs::ResultDbmInvalidOperation());
@ -461,7 +437,7 @@ namespace ams::fs {
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);
R_RETURN(if_exists);
R_THROW(if_exists);
}
}
@ -472,9 +448,10 @@ namespace ams::fs {
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);
R_RETURN(if_exists);
R_THROW(if_exists);
}
}
R_SUCCEED();
}
@ -542,18 +519,6 @@ namespace ams::fs {
R_RETURN(dir_res);
}
Result HierarchicalRomFileTable::GetDirectoryInformation(DirectoryInfo *out, const EntryKey &key) {
AMS_ASSERT(out != nullptr);
Position pos = 0;
RomDirectoryEntry entry = {};
R_TRY(this->GetDirectoryEntry(std::addressof(pos), std::addressof(entry), key));
AMS_UNUSED(out);
R_SUCCEED();
}
Result HierarchicalRomFileTable::OpenFile(FileInfo *out, const EntryKey &key) {
AMS_ASSERT(out != nullptr);

View file

@ -21,16 +21,14 @@ namespace ams::fs::RomPathTool {
AMS_ASSERT(path != nullptr);
/* Require paths start with a separator, and skip repeated separators. */
R_UNLESS(IsSeparator(path[0]), fs::ResultDbmInvalidPathFormat());
while (IsSeparator(path[1])) {
path++;
R_UNLESS(RomPathTool::IsSeparator(path[0]), fs::ResultDbmInvalidPathFormat());
while (RomPathTool::IsSeparator(path[1])) {
++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) {
/* ... */
}
m_next_path = path + 1;
R_SUCCEED();
}
@ -49,52 +47,49 @@ namespace ams::fs::RomPathTool {
bool PathParser::IsDirectoryPath() const {
AMS_ASSERT(m_next_path != nullptr);
if (IsNullTerminator(m_next_path[0]) && IsSeparator(m_next_path[-1])) {
if (RomPathTool::IsNullTerminator(m_next_path[0]) && RomPathTool::IsSeparator(m_next_path[-1])) {
return true;
}
if (IsCurrentDirectory(m_next_path)) {
if (RomPathTool::IsCurrentDirectory(m_next_path)) {
return true;
}
return IsParentDirectory(m_next_path);
return RomPathTool::IsParentDirectory(m_next_path);
}
Result PathParser::GetNextDirectoryName(RomEntryName *out) {
AMS_ASSERT(out != nullptr);
AMS_ASSERT(m_prev_path_start != nullptr);
AMS_ASSERT(m_prev_path_end != nullptr);
AMS_ASSERT(m_next_path != nullptr);
AMS_ASSERT(out != nullptr);
/* Set the current path to output. */
out->length = m_prev_path_end - m_prev_path_start;
out->path = m_prev_path_start;
/* Get as directory name. */
R_TRY(this->GetAsDirectoryName(out));
/* Parse the 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());
m_prev_path_end = cur + name_len;
m_next_path = m_prev_path_end + 1;
while (IsSeparator(m_next_path[0])) {
++m_next_path;
}
if (IsNullTerminator(m_next_path[0])) {
m_finished = true;
}
break;
size_t name_len;
for (name_len = 0; !RomPathTool::IsSeparator(cur[name_len]); ++name_len) {
if (RomPathTool::IsNullTerminator(cur[name_len])) {
m_finished = true;
m_prev_path_start = m_next_path;
m_next_path = cur + name_len;
m_prev_path_end = cur + name_len;
R_SUCCEED();
}
}
if (IsNullTerminator(cur[name_len])) {
m_finished = true;
m_next_path = cur + name_len;
m_prev_path_end = cur + name_len;
break;
}
/* Advance past separators. */
m_prev_path_start = m_next_path;
m_prev_path_end = cur + name_len;
for (m_next_path = m_prev_path_end + 1; RomPathTool::IsSeparator(m_next_path[0]); ++m_next_path) {
/* ... */
}
/* Check if we're finished. */
if (RomPathTool::IsNullTerminator(m_next_path[0])) {
m_finished = true;
}
R_SUCCEED();
@ -106,11 +101,12 @@ namespace ams::fs::RomPathTool {
AMS_ASSERT(m_prev_path_end != nullptr);
AMS_ASSERT(m_next_path != nullptr);
AMS_ASSERT(m_prev_path_start <= m_prev_path_end);
const size_t len = m_prev_path_end - m_prev_path_start;
R_UNLESS(len <= MaxPathLength, fs::ResultDbmDirectoryNameTooLong());
out->length = len;
out->path = m_prev_path_start;
out->Initialize(m_prev_path_start, len);
R_SUCCEED();
}
@ -120,11 +116,12 @@ namespace ams::fs::RomPathTool {
AMS_ASSERT(m_prev_path_end != nullptr);
AMS_ASSERT(m_next_path != nullptr);
AMS_ASSERT(m_prev_path_start <= m_prev_path_end);
const size_t len = m_prev_path_end - m_prev_path_start;
R_UNLESS(len <= MaxPathLength, fs::ResultDbmFileNameTooLong());
out->length = len;
out->path = m_prev_path_start;
out->Initialize(m_prev_path_start, len);
R_SUCCEED();
}
@ -132,19 +129,18 @@ namespace ams::fs::RomPathTool {
AMS_ASSERT(out != nullptr);
AMS_ASSERT(p != nullptr);
const RomPathChar *start = cur.path;
const RomPathChar *end = cur.path + cur.length - 1;
const RomPathChar *start = cur.begin();
const RomPathChar *end = cur.end() - 1;
s32 depth = 1;
if (IsParentDirectory(cur)) {
if (cur.IsParentDirectory()) {
++depth;
}
if (cur.path > p) {
if (start > p) {
size_t len = 0;
const RomPathChar *head = cur.path - 1;
while (head >= p) {
if (IsSeparator(*head)) {
for (const RomPathChar *head = start - 1; head >= p; --head) {
if (RomPathTool::IsSeparator(*head)) {
if (IsCurrentDirectory(head + 1, len)) {
++depth;
}
@ -158,9 +154,9 @@ namespace ams::fs::RomPathTool {
break;
}
while (IsSeparator(*head)) {
do {
--head;
}
} while (head > p && RomPathTool::IsSeparator(*head));
end = head;
len = 0;
@ -168,22 +164,15 @@ namespace ams::fs::RomPathTool {
}
++len;
--head;
}
R_UNLESS(depth == 0, fs::ResultDirectoryUnobtainable());
if (head == p) {
start = p + 1;
}
}
if (end <= p) {
out->path = p;
out->length = 0;
out->Initialize(p, 0);
} else {
out->path = start;
out->length = end - start + 1;
out->Initialize(start, end - start + 1);
}
R_SUCCEED();