forked from suyu/suyu
Filesys: Move creation of Handles for File/Directory to service handlers
This commit is contained in:
parent
e1f9f9ea04
commit
5e91fc0d1a
3 changed files with 33 additions and 32 deletions
|
@ -303,7 +303,8 @@ ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, Arc
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<Handle> OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path, const FileSys::Mode mode) {
|
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle,
|
||||||
|
const FileSys::Path& path, const FileSys::Mode mode) {
|
||||||
Archive* archive = GetArchive(archive_handle);
|
Archive* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
return ERR_INVALID_HANDLE;
|
return ERR_INVALID_HANDLE;
|
||||||
|
@ -314,10 +315,8 @@ ResultVal<Handle> OpenFileFromArchive(ArchiveHandle archive_handle, const FileSy
|
||||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file = Common::make_unique<File>(std::move(backend), path);
|
auto file = Kernel::SharedPtr<File>(new File(std::move(backend), path));
|
||||||
// TOOD(yuriks): Fix error reporting
|
return MakeResult<Kernel::SharedPtr<Kernel::Session>>(std::move(file));
|
||||||
Handle handle = Kernel::g_handle_table.Create(file.release()).ValueOr(INVALID_HANDLE);
|
|
||||||
return MakeResult<Handle>(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
|
ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
|
||||||
|
@ -403,13 +402,8 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons
|
||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
||||||
* Open a Directory from an Archive
|
const FileSys::Path& path) {
|
||||||
* @param archive_handle Handle to an open Archive object
|
|
||||||
* @param path Path to the Directory inside of the Archive
|
|
||||||
* @return Opened Directory object
|
|
||||||
*/
|
|
||||||
ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
|
|
||||||
Archive* archive = GetArchive(archive_handle);
|
Archive* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
return ERR_INVALID_HANDLE;
|
return ERR_INVALID_HANDLE;
|
||||||
|
@ -420,10 +414,8 @@ ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const F
|
||||||
ErrorSummary::NotFound, ErrorLevel::Permanent);
|
ErrorSummary::NotFound, ErrorLevel::Permanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto directory = Common::make_unique<Directory>(std::move(backend), path);
|
auto directory = Kernel::SharedPtr<Directory>(new Directory(std::move(backend), path));
|
||||||
// TOOD(yuriks): Fix error reporting
|
return MakeResult<Kernel::SharedPtr<Kernel::Session>>(std::move(directory));
|
||||||
Handle handle = Kernel::g_handle_table.Create(directory.release()).ValueOr(INVALID_HANDLE);
|
|
||||||
return MakeResult<Handle>(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode FormatSaveData() {
|
ResultCode FormatSaveData() {
|
||||||
|
|
|
@ -15,6 +15,10 @@ extern const std::string SYSTEM_ID;
|
||||||
/// The scrambled SD card CID, also known as ID1
|
/// The scrambled SD card CID, also known as ID1
|
||||||
extern const std::string SDCARD_ID;
|
extern const std::string SDCARD_ID;
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class Session;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Service {
|
namespace Service {
|
||||||
namespace FS {
|
namespace FS {
|
||||||
|
|
||||||
|
@ -58,9 +62,10 @@ ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, Arc
|
||||||
* @param archive_handle Handle to an open Archive object
|
* @param archive_handle Handle to an open Archive object
|
||||||
* @param path Path to the File inside of the Archive
|
* @param path Path to the File inside of the Archive
|
||||||
* @param mode Mode under which to open the File
|
* @param mode Mode under which to open the File
|
||||||
* @return Handle to the opened File object
|
* @return The opened File object as a Session
|
||||||
*/
|
*/
|
||||||
ResultVal<Handle> OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path, const FileSys::Mode mode);
|
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle,
|
||||||
|
const FileSys::Path& path, const FileSys::Mode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a File from an Archive
|
* Delete a File from an Archive
|
||||||
|
@ -121,9 +126,10 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons
|
||||||
* Open a Directory from an Archive
|
* Open a Directory from an Archive
|
||||||
* @param archive_handle Handle to an open Archive object
|
* @param archive_handle Handle to an open Archive object
|
||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return Handle to the opened File object
|
* @return The opened Directory object as a Session
|
||||||
*/
|
*/
|
||||||
ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
|
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
||||||
|
const FileSys::Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a blank SaveData archive.
|
* Creates a blank SaveData archive.
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Namespace FS_User
|
// Namespace FS_User
|
||||||
|
|
||||||
|
using Kernel::SharedPtr;
|
||||||
|
using Kernel::Session;
|
||||||
|
|
||||||
namespace Service {
|
namespace Service {
|
||||||
namespace FS {
|
namespace FS {
|
||||||
|
|
||||||
|
@ -58,10 +61,10 @@ static void OpenFile(Service::Interface* self) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_FS, "path=%s, mode=%d attrs=%u", file_path.DebugStr().c_str(), mode.hex, attributes);
|
LOG_DEBUG(Service_FS, "path=%s, mode=%d attrs=%u", file_path.DebugStr().c_str(), mode.hex, attributes);
|
||||||
|
|
||||||
ResultVal<Handle> handle = OpenFileFromArchive(archive_handle, file_path, mode);
|
ResultVal<SharedPtr<Session>> file_res = OpenFileFromArchive(archive_handle, file_path, mode);
|
||||||
cmd_buff[1] = handle.Code().raw;
|
cmd_buff[1] = file_res.Code().raw;
|
||||||
if (handle.Succeeded()) {
|
if (file_res.Succeeded()) {
|
||||||
cmd_buff[3] = *handle;
|
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
|
||||||
} else {
|
} else {
|
||||||
cmd_buff[3] = 0;
|
cmd_buff[3] = 0;
|
||||||
LOG_ERROR(Service_FS, "failed to get a handle for file %s", file_path.DebugStr().c_str());
|
LOG_ERROR(Service_FS, "failed to get a handle for file %s", file_path.DebugStr().c_str());
|
||||||
|
@ -114,10 +117,10 @@ static void OpenFileDirectly(Service::Interface* self) {
|
||||||
}
|
}
|
||||||
SCOPE_EXIT({ CloseArchive(*archive_handle); });
|
SCOPE_EXIT({ CloseArchive(*archive_handle); });
|
||||||
|
|
||||||
ResultVal<Handle> handle = OpenFileFromArchive(*archive_handle, file_path, mode);
|
ResultVal<SharedPtr<Session>> file_res = OpenFileFromArchive(*archive_handle, file_path, mode);
|
||||||
cmd_buff[1] = handle.Code().raw;
|
cmd_buff[1] = file_res.Code().raw;
|
||||||
if (handle.Succeeded()) {
|
if (file_res.Succeeded()) {
|
||||||
cmd_buff[3] = *handle;
|
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
|
||||||
} else {
|
} else {
|
||||||
cmd_buff[3] = 0;
|
cmd_buff[3] = 0;
|
||||||
LOG_ERROR(Service_FS, "failed to get a handle for file %s", file_path.DebugStr().c_str());
|
LOG_ERROR(Service_FS, "failed to get a handle for file %s", file_path.DebugStr().c_str());
|
||||||
|
@ -334,10 +337,10 @@ static void OpenDirectory(Service::Interface* self) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
||||||
|
|
||||||
ResultVal<Handle> handle = OpenDirectoryFromArchive(archive_handle, dir_path);
|
ResultVal<SharedPtr<Session>> dir_res = OpenDirectoryFromArchive(archive_handle, dir_path);
|
||||||
cmd_buff[1] = handle.Code().raw;
|
cmd_buff[1] = dir_res.Code().raw;
|
||||||
if (handle.Succeeded()) {
|
if (dir_res.Succeeded()) {
|
||||||
cmd_buff[3] = *handle;
|
cmd_buff[3] = Kernel::g_handle_table.Create(*dir_res).MoveFrom();
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Service_FS, "failed to get a handle for directory");
|
LOG_ERROR(Service_FS, "failed to get a handle for directory");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue