ams: globally prefer R_RETURN to return for ams::Result

This commit is contained in:
Michael Scire
2022-03-26 14:48:33 -07:00
parent dd78ede99f
commit bbf22b4c60
325 changed files with 1955 additions and 1993 deletions

View File

@@ -81,23 +81,23 @@ namespace ams::fs {
using Base = KeyValueRomStorageTemplate<ImplKeyType, ValueType, MaxKeyLength>;
public:
Result Add(Position *out, const ClientKeyType &key, const Value &value) {
return Base::AddInternal(out, key.key, key.Hash(), key.name.path, key.name.length * sizeof(RomPathChar), value);
R_RETURN(Base::AddInternal(out, key.key, key.Hash(), key.name.path, key.name.length * sizeof(RomPathChar), value));
}
Result Get(Position *out_pos, Value *out_val, const ClientKeyType &key) {
return Base::GetInternal(out_pos, out_val, key.key, key.Hash(), key.name.path, key.name.length * sizeof(RomPathChar));
R_RETURN(Base::GetInternal(out_pos, out_val, key.key, key.Hash(), key.name.path, key.name.length * sizeof(RomPathChar)));
}
Result GetByPosition(ImplKey *out_key, Value *out_val, Position pos) {
return Base::GetByPosition(out_key, out_val, pos);
R_RETURN(Base::GetByPosition(out_key, out_val, pos));
}
Result GetByPosition(ImplKey *out_key, Value *out_val, void *out_aux, size_t *out_aux_size, Position pos) {
return Base::GetByPosition(out_key, out_val, out_aux, out_aux_size, pos);
R_RETURN(Base::GetByPosition(out_key, out_val, out_aux, out_aux_size, pos));
}
Result SetByPosition(Position pos, const Value &value) {
return Base::SetByPosition(pos, value);
R_RETURN(Base::SetByPosition(pos, value));
}
};

View File

@@ -175,7 +175,7 @@ namespace ams::fs {
Element elem;
R_TRY(this->ReadKeyValue(std::addressof(elem), pos));
elem.value = value;
return this->WriteKeyValue(std::addressof(elem), pos, nullptr, 0);
R_RETURN(this->WriteKeyValue(std::addressof(elem), pos, nullptr, 0));
}
private:
BucketIndex HashToBucket(u32 hash_key) const {
@@ -259,14 +259,14 @@ namespace ams::fs {
AMS_ASSERT(ind < m_bucket_count);
const s64 offset = ind * sizeof(Position);
return m_bucket_storage.Read(offset, out, sizeof(*out));
R_RETURN(m_bucket_storage.Read(offset, out, sizeof(*out)));
}
Result WriteBucket(Position pos, BucketIndex ind) {
AMS_ASSERT(ind < m_bucket_count);
const s64 offset = ind * sizeof(Position);
return m_bucket_storage.Write(offset, std::addressof(pos), sizeof(pos));
R_RETURN(m_bucket_storage.Write(offset, std::addressof(pos), sizeof(pos)));
}
Result ReadKeyValue(Element *out, Position pos) {
@@ -276,7 +276,7 @@ namespace ams::fs {
R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
AMS_ASSERT(pos < kv_size);
return m_kv_storage.Read(pos, out, sizeof(*out));
R_RETURN(m_kv_storage.Read(pos, out, sizeof(*out)));
}
Result ReadKeyValue(Element *out, void *out_aux, size_t *out_aux_size, Position pos) {

View File

@@ -25,7 +25,7 @@ namespace ams::fs {
Result BindEvent(os::SystemEventType *out, os::EventClearMode clear_mode) {
AMS_ASSERT(out != nullptr);
return this->DoBindEvent(out, clear_mode);
R_RETURN(this->DoBindEvent(out, clear_mode));
}
private:
virtual Result DoBindEvent(os::SystemEventType *out, os::EventClearMode clear_mode) = 0;

View File

@@ -95,19 +95,19 @@ namespace ams::fs {
virtual ~ReadOnlyStorageAdapter() { /* ... */ }
public:
virtual Result Read(s64 offset, void *buffer, size_t size) override {
return m_storage->Read(offset, buffer, size);
R_RETURN(m_storage->Read(offset, buffer, size));
}
virtual Result Flush() override {
return m_storage->Flush();
R_RETURN(m_storage->Flush());
}
virtual Result GetSize(s64 *out) override {
return m_storage->GetSize(out);
R_RETURN(m_storage->GetSize(out));
}
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
return m_storage->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
R_RETURN(m_storage->OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override {

View File

@@ -205,7 +205,7 @@ namespace ams::fs {
/* Check the path is valid. */
R_UNLESS(path != nullptr, fs::ResultNullptrArgument());
return this->Initialize(path, std::strlen(path));
R_RETURN(this->Initialize(path, std::strlen(path)));
}
Result InitializeWithFormat(const char *fmt, ...) __attribute__((format (printf, 2, 3))) {

View File

@@ -619,7 +619,7 @@ namespace ams::fs {
}
static constexpr ALWAYS_INLINE Result SkipMountName(const char **out, size_t *out_len, const char *path) {
return ParseMountName(out, out_len, nullptr, 0, path);
R_RETURN(ParseMountName(out, out_len, nullptr, 0, path));
}
static constexpr Result ParseMountName(const char **out, size_t *out_len, char *out_mount_name, size_t out_mount_name_buffer_size, const char *path) {
@@ -684,7 +684,7 @@ namespace ams::fs {
}
static constexpr ALWAYS_INLINE Result SkipRelativeDotPath(const char **out, size_t *out_len, const char *path) {
return ParseRelativeDotPath(out, out_len, nullptr, 0, path);
R_RETURN(ParseRelativeDotPath(out, out_len, nullptr, 0, path));
}
static constexpr Result ParseRelativeDotPath(const char **out, size_t *out_len, char *out_relative, size_t out_relative_buffer_size, const char *path) {

View File

@@ -36,11 +36,11 @@ namespace ams::fs {
virtual ~ReadOnlyFile() { /* ... */ }
private:
virtual Result DoRead(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override final {
return m_base_file->Read(out, offset, buffer, size, option);
R_RETURN(m_base_file->Read(out, offset, buffer, size, option));
}
virtual Result DoGetSize(s64 *out) override final {
return m_base_file->GetSize(out);
R_RETURN(m_base_file->GetSize(out));
}
virtual Result DoFlush() override final {
@@ -66,7 +66,7 @@ namespace ams::fs {
switch (op_id) {
case OperationId::Invalidate:
case OperationId::QueryRange:
return m_base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
R_RETURN(m_base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
default:
R_THROW(fs::ResultUnsupportedOperateRangeForReadOnlyFile());
}
@@ -104,11 +104,11 @@ namespace ams::fs {
}
virtual Result DoOpenDirectory(std::unique_ptr<fsa::IDirectory> *out_dir, const fs::Path &path, OpenDirectoryMode mode) override final {
return m_base_fs->OpenDirectory(out_dir, path, mode);
R_RETURN(m_base_fs->OpenDirectory(out_dir, path, mode));
}
virtual Result DoGetEntryType(DirectoryEntryType *out, const fs::Path &path) override final {
return m_base_fs->GetEntryType(out, path);
R_RETURN(m_base_fs->GetEntryType(out, path));
}
virtual Result DoCommit() override final {

View File

@@ -35,23 +35,23 @@ namespace ams::fs {
virtual ~RemoteFile() { fsFileClose(std::addressof(m_base_file)); }
public:
virtual Result DoRead(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override final {
return fsFileRead(std::addressof(m_base_file), offset, buffer, size, option._value, out);
R_RETURN(fsFileRead(std::addressof(m_base_file), offset, buffer, size, option._value, out));
}
virtual Result DoGetSize(s64 *out) override final {
return fsFileGetSize(std::addressof(m_base_file), out);
R_RETURN(fsFileGetSize(std::addressof(m_base_file), out));
}
virtual Result DoFlush() override final {
return fsFileFlush(std::addressof(m_base_file));
R_RETURN(fsFileFlush(std::addressof(m_base_file)));
}
virtual Result DoWrite(s64 offset, const void *buffer, size_t size, const fs::WriteOption &option) override final {
return fsFileWrite(std::addressof(m_base_file), offset, buffer, size, option._value);
R_RETURN(fsFileWrite(std::addressof(m_base_file), offset, buffer, size, option._value));
}
virtual Result DoSetSize(s64 size) override final {
return fsFileSetSize(std::addressof(m_base_file), size);
R_RETURN(fsFileSetSize(std::addressof(m_base_file), size));
}
virtual Result DoOperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override final {
@@ -60,7 +60,7 @@ namespace ams::fs {
R_UNLESS(op_id == OperationId::QueryRange, fs::ResultUnsupportedOperateRangeForFileServiceObjectAdapter());
R_UNLESS(dst_size == sizeof(FileQueryRangeInfo), fs::ResultInvalidSize());
return fsFileOperateRange(std::addressof(m_base_file), static_cast<::FsOperationId>(op_id), offset, size, reinterpret_cast<::FsRangeInfo *>(dst));
R_RETURN(fsFileOperateRange(std::addressof(m_base_file), static_cast<::FsOperationId>(op_id), offset, size, reinterpret_cast<::FsRangeInfo *>(dst)));
}
public:
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override final {
@@ -80,11 +80,11 @@ namespace ams::fs {
public:
virtual Result DoRead(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries) override final {
static_assert(sizeof(*out_entries) == sizeof(::FsDirectoryEntry));
return fsDirRead(std::addressof(m_base_dir), out_count, max_entries, reinterpret_cast<::FsDirectoryEntry *>(out_entries));
R_RETURN(fsDirRead(std::addressof(m_base_dir), out_count, max_entries, reinterpret_cast<::FsDirectoryEntry *>(out_entries)));
}
virtual Result DoGetEntryCount(s64 *out) override final {
return fsDirGetEntryCount(std::addressof(m_base_dir), out);
R_RETURN(fsDirGetEntryCount(std::addressof(m_base_dir), out));
}
public:
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override final {
@@ -119,31 +119,31 @@ namespace ams::fs {
virtual Result DoCreateFile(const fs::Path &path, s64 size, int flags) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsCreateFile(std::addressof(m_base_fs), sf_path.str, size, flags);
R_RETURN(fsFsCreateFile(std::addressof(m_base_fs), sf_path.str, size, flags));
}
virtual Result DoDeleteFile(const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsDeleteFile(std::addressof(m_base_fs), sf_path.str);
R_RETURN(fsFsDeleteFile(std::addressof(m_base_fs), sf_path.str));
}
virtual Result DoCreateDirectory(const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsCreateDirectory(std::addressof(m_base_fs), sf_path.str);
R_RETURN(fsFsCreateDirectory(std::addressof(m_base_fs), sf_path.str));
}
virtual Result DoDeleteDirectory(const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsDeleteDirectory(std::addressof(m_base_fs), sf_path.str);
R_RETURN(fsFsDeleteDirectory(std::addressof(m_base_fs), sf_path.str));
}
virtual Result DoDeleteDirectoryRecursively(const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsDeleteDirectoryRecursively(std::addressof(m_base_fs), sf_path.str);
R_RETURN(fsFsDeleteDirectoryRecursively(std::addressof(m_base_fs), sf_path.str));
}
virtual Result DoRenameFile(const fs::Path &old_path, const fs::Path &new_path) override final {
@@ -151,7 +151,7 @@ namespace ams::fs {
fssrv::sf::Path new_sf_path;
R_TRY(GetPathForServiceObject(std::addressof(old_sf_path), old_path));
R_TRY(GetPathForServiceObject(std::addressof(new_sf_path), new_path));
return fsFsRenameFile(std::addressof(m_base_fs), old_sf_path.str, new_sf_path.str);
R_RETURN(fsFsRenameFile(std::addressof(m_base_fs), old_sf_path.str, new_sf_path.str));
}
virtual Result DoRenameDirectory(const fs::Path &old_path, const fs::Path &new_path) override final {
@@ -159,7 +159,7 @@ namespace ams::fs {
fssrv::sf::Path new_sf_path;
R_TRY(GetPathForServiceObject(std::addressof(old_sf_path), old_path));
R_TRY(GetPathForServiceObject(std::addressof(new_sf_path), new_path));
return fsFsRenameDirectory(std::addressof(m_base_fs), old_sf_path.str, new_sf_path.str);
R_RETURN(fsFsRenameDirectory(std::addressof(m_base_fs), old_sf_path.str, new_sf_path.str));
}
virtual Result DoGetEntryType(DirectoryEntryType *out, const fs::Path &path) override final {
@@ -167,7 +167,7 @@ namespace ams::fs {
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
static_assert(sizeof(::FsDirEntryType) == sizeof(DirectoryEntryType));
return fsFsGetEntryType(std::addressof(m_base_fs), sf_path.str, reinterpret_cast<::FsDirEntryType *>(out));
R_RETURN(fsFsGetEntryType(std::addressof(m_base_fs), sf_path.str, reinterpret_cast<::FsDirEntryType *>(out)));
}
virtual Result DoOpenFile(std::unique_ptr<fsa::IFile> *out_file, const fs::Path &path, OpenMode mode) override final {
@@ -199,38 +199,38 @@ namespace ams::fs {
}
virtual Result DoCommit() override final {
return fsFsCommit(std::addressof(m_base_fs));
R_RETURN(fsFsCommit(std::addressof(m_base_fs)));
}
virtual Result DoGetFreeSpaceSize(s64 *out, const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsGetFreeSpace(std::addressof(m_base_fs), sf_path.str, out);
R_RETURN(fsFsGetFreeSpace(std::addressof(m_base_fs), sf_path.str, out));
}
virtual Result DoGetTotalSpaceSize(s64 *out, const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsGetTotalSpace(std::addressof(m_base_fs), sf_path.str, out);
R_RETURN(fsFsGetTotalSpace(std::addressof(m_base_fs), sf_path.str, out));
}
virtual Result DoCleanDirectoryRecursively(const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsCleanDirectoryRecursively(std::addressof(m_base_fs), sf_path.str);
R_RETURN(fsFsCleanDirectoryRecursively(std::addressof(m_base_fs), sf_path.str));
}
virtual Result DoGetFileTimeStampRaw(FileTimeStampRaw *out, const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
static_assert(sizeof(FileTimeStampRaw) == sizeof(::FsTimeStampRaw));
return fsFsGetFileTimeStampRaw(std::addressof(m_base_fs), sf_path.str, reinterpret_cast<::FsTimeStampRaw *>(out));
R_RETURN(fsFsGetFileTimeStampRaw(std::addressof(m_base_fs), sf_path.str, reinterpret_cast<::FsTimeStampRaw *>(out)));
}
virtual Result DoQueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fsa::QueryId query, const fs::Path &path) override final {
fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
return fsFsQueryEntry(std::addressof(m_base_fs), dst, dst_size, src, src_size, sf_path.str, static_cast<FsFileSystemQueryId>(query));
R_RETURN(fsFsQueryEntry(std::addressof(m_base_fs), dst, dst_size, src, src_size, sf_path.str, static_cast<FsFileSystemQueryId>(query)));
}
};
#endif

View File

@@ -32,23 +32,23 @@ namespace ams::fs {
virtual ~RemoteStorage() { fsStorageClose(std::addressof(m_base_storage)); }
public:
virtual Result Read(s64 offset, void *buffer, size_t size) override {
return fsStorageRead(std::addressof(m_base_storage), offset, buffer, size);
R_RETURN(fsStorageRead(std::addressof(m_base_storage), offset, buffer, size));
};
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
return fsStorageWrite(std::addressof(m_base_storage), offset, buffer, size);
R_RETURN(fsStorageWrite(std::addressof(m_base_storage), offset, buffer, size));
};
virtual Result Flush() override {
return fsStorageFlush(std::addressof(m_base_storage));
R_RETURN(fsStorageFlush(std::addressof(m_base_storage)));
};
virtual Result GetSize(s64 *out_size) override {
return fsStorageGetSize(std::addressof(m_base_storage), out_size);
R_RETURN(fsStorageGetSize(std::addressof(m_base_storage), out_size));
};
virtual Result SetSize(s64 size) override {
return fsStorageSetSize(std::addressof(m_base_storage), size);
R_RETURN(fsStorageSetSize(std::addressof(m_base_storage), size));
};
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {

View File

@@ -84,7 +84,7 @@ namespace ams::fs {
/* Validate arguments and read. */
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_TRY(IStorage::CheckAccessRange(offset, size, m_size));
return m_base_storage->Read(m_offset + offset, buffer, size);
R_RETURN(m_base_storage->Read(m_offset + offset, buffer, size));
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override{
@@ -97,12 +97,12 @@ namespace ams::fs {
/* Validate arguments and write. */
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_TRY(IStorage::CheckAccessRange(offset, size, m_size));
return m_base_storage->Write(m_offset + offset, buffer, size);
R_RETURN(m_base_storage->Write(m_offset + offset, buffer, size));
}
virtual Result Flush() override {
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
return m_base_storage->Flush();
R_RETURN(m_base_storage->Flush());
}
virtual Result SetSize(s64 size) override {