mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-18 16:30:05 +00:00
Merge pull request #1208 from archshift/free-bytes
Implement FS_User::GetFreeBytes
This commit is contained in:
commit
af26b7a0bc
@ -131,6 +131,12 @@ public:
|
|||||||
* @return Opened directory, or nullptr
|
* @return Opened directory, or nullptr
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const = 0;
|
virtual std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the free space
|
||||||
|
* @return The number of free bytes in the archive
|
||||||
|
*/
|
||||||
|
virtual u64 GetFreeBytes() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArchiveFactory : NonCopyable {
|
class ArchiveFactory : NonCopyable {
|
||||||
|
@ -74,6 +74,11 @@ std::unique_ptr<DirectoryBackend> DiskArchive::OpenDirectory(const Path& path) c
|
|||||||
return std::move(directory);
|
return std::move(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 DiskArchive::GetFreeBytes() const {
|
||||||
|
// TODO: Stubbed to return 1GiB
|
||||||
|
return 1024 * 1024 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
DiskFile::DiskFile(const DiskArchive& archive, const Path& path, const Mode mode) {
|
DiskFile::DiskFile(const DiskArchive& archive, const Path& path, const Mode mode) {
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
bool CreateDirectory(const Path& path) const override;
|
bool CreateDirectory(const Path& path) const override;
|
||||||
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
||||||
|
u64 GetFreeBytes() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class DiskFile;
|
friend class DiskFile;
|
||||||
|
@ -59,6 +59,11 @@ std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) c
|
|||||||
return Common::make_unique<IVFCDirectory>();
|
return Common::make_unique<IVFCDirectory>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 IVFCArchive::GetFreeBytes() const {
|
||||||
|
LOG_WARNING(Service_FS, "Attempted to get the free space in an IVFC archive");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
|
size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
bool CreateDirectory(const Path& path) const override;
|
bool CreateDirectory(const Path& path) const override;
|
||||||
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
||||||
|
u64 GetFreeBytes() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<FileUtil::IOFile> romfs_file;
|
std::shared_ptr<FileUtil::IOFile> romfs_file;
|
||||||
|
@ -403,6 +403,13 @@ ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle a
|
|||||||
return MakeResult<Kernel::SharedPtr<Directory>>(std::move(directory));
|
return MakeResult<Kernel::SharedPtr<Directory>>(std::move(directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle) {
|
||||||
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
|
if (archive == nullptr)
|
||||||
|
return ERR_INVALID_HANDLE;
|
||||||
|
return MakeResult<u64>(archive->GetFreeBytes());
|
||||||
|
}
|
||||||
|
|
||||||
ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path) {
|
ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path) {
|
||||||
auto archive_itr = id_code_map.find(id_code);
|
auto archive_itr = id_code_map.find(id_code);
|
||||||
if (archive_itr == id_code_map.end()) {
|
if (archive_itr == id_code_map.end()) {
|
||||||
|
@ -166,6 +166,13 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons
|
|||||||
ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
||||||
const FileSys::Path& path);
|
const FileSys::Path& path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the free space in an Archive
|
||||||
|
* @param archive_handle Handle to an open Archive object
|
||||||
|
* @return The number of free bytes in the archive
|
||||||
|
*/
|
||||||
|
ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erases the contents of the physical folder that contains the archive
|
* Erases the contents of the physical folder that contains the archive
|
||||||
* identified by the specified id code and path
|
* identified by the specified id code and path
|
||||||
|
@ -496,6 +496,33 @@ static void FormatThisUserSaveData(Service::Interface* self) {
|
|||||||
cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData).raw;
|
cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData).raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FS_User::GetFreeBytes service function
|
||||||
|
* Inputs:
|
||||||
|
* 0: 0x08120080
|
||||||
|
* 1: Archive handle low word
|
||||||
|
* 2: Archive handle high word
|
||||||
|
* Outputs:
|
||||||
|
* 1: Result of function, 0 on success, otherwise error code
|
||||||
|
* 2: Free byte count low word
|
||||||
|
* 3: Free byte count high word
|
||||||
|
*/
|
||||||
|
static void GetFreeBytes(Service::Interface* self) {
|
||||||
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||||
|
|
||||||
|
ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[1], cmd_buff[2]);
|
||||||
|
ResultVal<u64> bytes_res = GetFreeBytesInArchive(archive_handle);
|
||||||
|
|
||||||
|
cmd_buff[1] = bytes_res.Code().raw;
|
||||||
|
if (bytes_res.Succeeded()) {
|
||||||
|
cmd_buff[2] = (u32)*bytes_res;
|
||||||
|
cmd_buff[3] = *bytes_res >> 32;
|
||||||
|
} else {
|
||||||
|
cmd_buff[2] = 0;
|
||||||
|
cmd_buff[3] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FS_User::CreateExtSaveData service function
|
* FS_User::CreateExtSaveData service function
|
||||||
* Inputs:
|
* Inputs:
|
||||||
@ -700,7 +727,7 @@ const Interface::FunctionInfo FunctionTable[] = {
|
|||||||
{0x080F0180, FormatThisUserSaveData,"FormatThisUserSaveData"},
|
{0x080F0180, FormatThisUserSaveData,"FormatThisUserSaveData"},
|
||||||
{0x08100200, nullptr, "CreateSystemSaveData"},
|
{0x08100200, nullptr, "CreateSystemSaveData"},
|
||||||
{0x08110040, nullptr, "DeleteSystemSaveData"},
|
{0x08110040, nullptr, "DeleteSystemSaveData"},
|
||||||
{0x08120080, nullptr, "GetFreeBytes"},
|
{0x08120080, GetFreeBytes, "GetFreeBytes"},
|
||||||
{0x08130000, nullptr, "GetCardType"},
|
{0x08130000, nullptr, "GetCardType"},
|
||||||
{0x08140000, nullptr, "GetSdmcArchiveResource"},
|
{0x08140000, nullptr, "GetSdmcArchiveResource"},
|
||||||
{0x08150000, nullptr, "GetNandArchiveResource"},
|
{0x08150000, nullptr, "GetNandArchiveResource"},
|
||||||
|
Loading…
Reference in New Issue
Block a user