Skip to content

Commit 8f5df10

Browse files
author
N3xoX1
committed
Loader: Add VirtualDirectoryPtr::CreateSubdirectory
1 parent e7aa37d commit 8f5df10

8 files changed

Lines changed: 52 additions & 7 deletions

File tree

src/nxemu-loader/core/file_sys/vfs/vfs_types.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ VirtualDirectoryPtr::~VirtualDirectoryPtr()
1111
{
1212
}
1313

14+
IVirtualDirectory * VirtualDirectoryPtr::CreateSubdirectory(const char * path) const
15+
{
16+
if (m_directory.get() == nullptr)
17+
{
18+
return nullptr;
19+
}
20+
FileSys::VirtualDir dir = m_directory->CreateSubdirectory(path);
21+
if (dir.get() == nullptr)
22+
{
23+
return nullptr;
24+
}
25+
return std::make_unique<VirtualDirectoryPtr>(dir).release();
26+
}
27+
1428
IVirtualDirectory * VirtualDirectoryPtr::GetDirectoryRelative(const char * path) const
1529
{
1630
if (m_directory.get() == nullptr)

src/nxemu-loader/core/file_sys/vfs/vfs_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class VirtualDirectoryPtr :
4545
operator bool() const;
4646

4747
// IVirtualDirectory
48+
IVirtualDirectory * CreateSubdirectory(const char * path) const override;
4849
IVirtualDirectory * GetDirectoryRelative(const char * path) const override;
4950
IVirtualDirectory * GetSubdirectory(const char * name) const override;
5051
IVirtualFile * CreateFile(const char * name) const override;

src/nxemu-module-spec/base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
enum
1818
{
19-
MODULE_LOADER_SPECS_VERSION = 0x0109,
19+
MODULE_LOADER_SPECS_VERSION = 0x010A,
2020
MODULE_VIDEO_SPECS_VERSION = 0x010C,
2121
MODULE_CPU_SPECS_VERSION = 0x0105,
2222
MODULE_OPERATING_SYSTEM_SPECS_VERSION = 0x010A,

src/nxemu-module-spec/system_loader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ __interface IVirtualFile;
155155

156156
__interface IVirtualDirectory
157157
{
158+
IVirtualDirectory * CreateSubdirectory(const char* path) const = 0;
158159
IVirtualDirectory * GetDirectoryRelative(const char * path) const = 0;
159160
IVirtualDirectory * GetSubdirectory(const char* name) const = 0;
160161
IVirtualFile * CreateFile(const char* name) const = 0;

src/nxemu-os/core/file_sys/fsa/fs_i_filesystem.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class IFileSystem {
6161
R_RETURN(this->DoRenameDirectory(old_path, new_path));
6262
}
6363

64+
Result GetEntryType(DirectoryEntryType* out, const Path& path) {
65+
R_RETURN(this->DoGetEntryType(out, path));
66+
}
67+
6468
Result OpenFile(IVirtualFile ** out_file, const Path& path, VirtualFileOpenMode mode) {
6569
R_UNLESS(out_file != nullptr, ResultNullptrArgument);
6670
R_UNLESS(((uint32_t)mode & (uint32_t)VirtualFileOpenMode::ReadWrite) != 0, ResultInvalidOpenMode);
@@ -118,8 +122,7 @@ class IFileSystem {
118122
}
119123

120124
Result DoCreateDirectory(const Path& path) {
121-
UNIMPLEMENTED();
122-
R_SUCCEED();
125+
R_RETURN(backend.CreateDirectory(path.GetString()));
123126
}
124127

125128
Result DoDeleteDirectory(const Path& path) {
@@ -142,6 +145,10 @@ class IFileSystem {
142145
R_SUCCEED();
143146
}
144147

148+
Result DoGetEntryType(DirectoryEntryType* out, const Path& path) {
149+
R_RETURN(backend.GetEntryType(out, path.GetString()));
150+
}
151+
145152
Result DoOpenFile(IVirtualFile ** out_file, const Path& path, VirtualFileOpenMode mode) {
146153
R_RETURN(backend.OpenFile(out_file, path.GetString(), mode));
147154
}

src/nxemu-os/core/hle/service/filesystem/filesystem.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ Result VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size
6161
return ResultSuccess;
6262
}
6363

64+
Result VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const {
65+
std::string path(Common::FS::SanitizePath(path_));
66+
67+
// NOTE: This is inaccurate behavior. CreateDirectory is not recursive.
68+
// CreateDirectory should return PathNotFound if the parent directory does not exist.
69+
// This is here temporarily in order to have UMM "work" in the meantime.
70+
// TODO (Morph): Remove this when a hardware test verifies the correct behavior.
71+
const auto components = Common::FS::SplitPathComponents(path);
72+
std::string relative_path;
73+
for (const auto& component : components) {
74+
relative_path = Common::FS::SanitizePath(fmt::format("{}/{}", relative_path, component));
75+
auto new_dir = backing->CreateSubdirectory(relative_path.c_str());
76+
if (new_dir == nullptr) {
77+
// TODO(DarkLordZach): Find a better error code for this
78+
return ResultUnknown;
79+
}
80+
}
81+
return ResultSuccess;
82+
}
83+
6484
Result VfsDirectoryServiceWrapper::OpenFile(IVirtualFile** out_file,
6585
const std::string& path_,
6686
VirtualFileOpenMode mode) const {

src/nxemu-os/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ Result IFileSystem::CreateDirectory(
5454
const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
5555
LOG_DEBUG(Service_FS, "called. directory={}", path->str);
5656

57-
UNIMPLEMENTED();
58-
R_SUCCEED();
57+
R_RETURN(backend->CreateDirectory(FileSys::Path(path->str)));
5958
}
6059

6160
Result IFileSystem::DeleteDirectory(
@@ -116,7 +115,10 @@ Result IFileSystem::GetEntryType(
116115
Out<u32> out_type, const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
117116
LOG_DEBUG(Service_FS, "called. file={}", path->str);
118117

119-
UNIMPLEMENTED();
118+
FileSys::DirectoryEntryType vfs_entry_type{};
119+
R_TRY(backend->GetEntryType(&vfs_entry_type, FileSys::Path(path->str)));
120+
121+
*out_type = static_cast<u32>(vfs_entry_type);
120122
R_SUCCEED();
121123
}
122124

src/nxemu-os/core/hle/service/filesystem/fsp/fsp_srv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Result FSP_SRV::OpenSdCardFileSystem(OutInterface<IFileSystem> out_interface) {
218218
{
219219
R_RETURN(FileSys::ResultPortSdCardNoDevice);
220220
}
221-
UNIMPLEMENTED();
221+
*out_interface = std::make_shared<IFileSystem>(system, std::move(sdmc_dir), SizeGetter::FromStorageId(fsc, StorageId::SdCard));
222222
R_SUCCEED();
223223
}
224224

0 commit comments

Comments
 (0)