mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-22 10:22:08 +00:00
IStorage: rename access check helpers
This commit is contained in:
parent
bf55776241
commit
7548940efa
7 changed files with 36 additions and 36 deletions
|
@ -40,25 +40,25 @@ namespace ams::fs {
|
||||||
return this->OperateRange(nullptr, 0, op_id, offset, size, nullptr, 0);
|
return this->OperateRange(nullptr, 0, op_id, offset, size, nullptr, 0);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
static inline bool IsRangeValid(s64 offset, s64 size, s64 total_size) {
|
static inline bool CheckAccessRange(s64 offset, s64 size, s64 total_size) {
|
||||||
return offset >= 0 &&
|
return offset >= 0 &&
|
||||||
size >= 0 &&
|
size >= 0 &&
|
||||||
size <= total_size &&
|
size <= total_size &&
|
||||||
offset <= (total_size - size);
|
offset <= (total_size - size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool IsRangeValid(s64 offset, size_t size, s64 total_size) {
|
static inline bool CheckAccessRange(s64 offset, size_t size, s64 total_size) {
|
||||||
return IsRangeValid(offset, static_cast<s64>(size), total_size);
|
return CheckAccessRange(offset, static_cast<s64>(size), total_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool IsOffsetAndSizeValid(s64 offset, s64 size) {
|
static inline bool CheckOffsetAndSize(s64 offset, s64 size) {
|
||||||
return offset >= 0 &&
|
return offset >= 0 &&
|
||||||
size >= 0 &&
|
size >= 0 &&
|
||||||
offset <= (offset + size);
|
offset <= (offset + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool IsOffsetAndSizeValid(s64 offset, size_t size) {
|
static inline bool CheckOffsetAndSize(s64 offset, size_t size) {
|
||||||
return IsOffsetAndSizeValid(offset, static_cast<s64>(size));
|
return CheckOffsetAndSize(offset, static_cast<s64>(size));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace ams::fs {
|
||||||
|
|
||||||
/* Validate arguments. */
|
/* Validate arguments. */
|
||||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Copy from memory. */
|
/* Copy from memory. */
|
||||||
std::memcpy(buffer, this->buf + offset, size);
|
std::memcpy(buffer, this->buf + offset, size);
|
||||||
|
@ -46,7 +46,7 @@ namespace ams::fs {
|
||||||
|
|
||||||
/* Validate arguments. */
|
/* Validate arguments. */
|
||||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Copy to memory. */
|
/* Copy to memory. */
|
||||||
std::memcpy(this->buf + offset, buffer, size);
|
std::memcpy(this->buf + offset, buffer, size);
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace ams::fs {
|
||||||
|
|
||||||
/* Validate arguments and read. */
|
/* Validate arguments and read. */
|
||||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
return this->base_storage->Read(this->offset + offset, buffer, size);
|
return this->base_storage->Read(this->offset + offset, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ namespace ams::fs {
|
||||||
|
|
||||||
/* Validate arguments and write. */
|
/* Validate arguments and write. */
|
||||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
return this->base_storage->Write(this->offset + offset, buffer, size);
|
return this->base_storage->Write(this->offset + offset, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ namespace ams::fs {
|
||||||
/* Ensure we're initialized and validate arguments. */
|
/* Ensure we're initialized and validate arguments. */
|
||||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||||
R_UNLESS(this->resizable, fs::ResultUnsupportedOperationInSubStorageA());
|
R_UNLESS(this->resizable, fs::ResultUnsupportedOperationInSubStorageA());
|
||||||
R_UNLESS(IStorage::IsOffsetAndSizeValid(this->offset, size), fs::ResultInvalidSize());
|
R_UNLESS(IStorage::CheckOffsetAndSize(this->offset, size), fs::ResultInvalidSize());
|
||||||
|
|
||||||
/* Ensure that we're allowed to set size. */
|
/* Ensure that we're allowed to set size. */
|
||||||
s64 cur_size;
|
s64 cur_size;
|
||||||
|
@ -134,7 +134,7 @@ namespace ams::fs {
|
||||||
R_SUCCEED_IF(size == 0);
|
R_SUCCEED_IF(size == 0);
|
||||||
|
|
||||||
/* Validate arguments and operate. */
|
/* Validate arguments and operate. */
|
||||||
R_UNLESS(IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange());
|
||||||
return this->base_storage->OperateRange(dst, dst_size, op_id, this->offset + offset, size, src, src_size);
|
return this->base_storage->OperateRange(dst, dst_size, op_id, this->offset + offset, size, src, src_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace ams::fssystem {
|
||||||
|
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
return AlignmentMatchingStorageImpl::Read(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<char *>(buffer), size);
|
return AlignmentMatchingStorageImpl::Read(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<char *>(buffer), size);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ namespace ams::fssystem {
|
||||||
|
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
return AlignmentMatchingStorageImpl::Write(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<const char *>(buffer), size);
|
return AlignmentMatchingStorageImpl::Write(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<const char *>(buffer), size);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ namespace ams::fssystem {
|
||||||
/* Get the base storage size. */
|
/* Get the base storage size. */
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Operate on the base storage. */
|
/* Operate on the base storage. */
|
||||||
const auto valid_size = std::min(size, bs_size - offset);
|
const auto valid_size = std::min(size, bs_size - offset);
|
||||||
|
@ -154,7 +154,7 @@ namespace ams::fssystem {
|
||||||
|
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Allocate a pooled buffer. */
|
/* Allocate a pooled buffer. */
|
||||||
PooledBuffer pooled_buffer;
|
PooledBuffer pooled_buffer;
|
||||||
|
@ -172,7 +172,7 @@ namespace ams::fssystem {
|
||||||
|
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Allocate a pooled buffer. */
|
/* Allocate a pooled buffer. */
|
||||||
PooledBuffer pooled_buffer;
|
PooledBuffer pooled_buffer;
|
||||||
|
@ -212,7 +212,7 @@ namespace ams::fssystem {
|
||||||
/* Get the base storage size. */
|
/* Get the base storage size. */
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Operate on the base storage. */
|
/* Operate on the base storage. */
|
||||||
const auto valid_size = std::min(size, bs_size - offset);
|
const auto valid_size = std::min(size, bs_size - offset);
|
||||||
|
@ -257,7 +257,7 @@ namespace ams::fssystem {
|
||||||
|
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Allocate a pooled buffer. */
|
/* Allocate a pooled buffer. */
|
||||||
PooledBuffer pooled_buffer(this->data_align, this->data_align);
|
PooledBuffer pooled_buffer(this->data_align, this->data_align);
|
||||||
|
@ -294,7 +294,7 @@ namespace ams::fssystem {
|
||||||
/* Get the base storage size. */
|
/* Get the base storage size. */
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Operate on the base storage. */
|
/* Operate on the base storage. */
|
||||||
const auto valid_size = std::min(size, bs_size - offset);
|
const auto valid_size = std::min(size, bs_size - offset);
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace ams::fs {
|
||||||
R_TRY(this->UpdateSize());
|
R_TRY(this->UpdateSize());
|
||||||
|
|
||||||
/* Ensure our access is valid. */
|
/* Ensure our access is valid. */
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
size_t read_size;
|
size_t read_size;
|
||||||
return this->base_file->Read(&read_size, offset, buffer, size);
|
return this->base_file->Read(&read_size, offset, buffer, size);
|
||||||
|
@ -50,7 +50,7 @@ namespace ams::fs {
|
||||||
R_TRY(this->UpdateSize());
|
R_TRY(this->UpdateSize());
|
||||||
|
|
||||||
/* Ensure our access is valid. */
|
/* Ensure our access is valid. */
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
return this->base_file->Write(offset, buffer, size, fs::WriteOption());
|
return this->base_file->Write(offset, buffer, size, fs::WriteOption());
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ namespace ams::fs {
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
R_TRY(this->UpdateSize());
|
R_TRY(this->UpdateSize());
|
||||||
R_UNLESS(IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange());
|
||||||
return this->base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
return this->base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||||
default:
|
default:
|
||||||
return fs::ResultUnsupportedOperationInFileStorageA();
|
return fs::ResultUnsupportedOperationInFileStorageA();
|
||||||
|
@ -121,7 +121,7 @@ namespace ams::fs {
|
||||||
R_TRY(this->UpdateSize());
|
R_TRY(this->UpdateSize());
|
||||||
|
|
||||||
/* Ensure our access is valid. */
|
/* Ensure our access is valid. */
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
return ReadFile(this->handle, offset, buffer, size, fs::ReadOption());
|
return ReadFile(this->handle, offset, buffer, size, fs::ReadOption());
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ namespace ams::fs {
|
||||||
R_TRY(this->UpdateSize());
|
R_TRY(this->UpdateSize());
|
||||||
|
|
||||||
/* Ensure our access is valid. */
|
/* Ensure our access is valid. */
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
return WriteFile(this->handle, offset, buffer, size, fs::WriteOption());
|
return WriteFile(this->handle, offset, buffer, size, fs::WriteOption());
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ namespace ams::fssystem {
|
||||||
|
|
||||||
s64 bs_size = 0;
|
s64 bs_size = 0;
|
||||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||||
R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange());
|
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Determine extents. */
|
/* Determine extents. */
|
||||||
const auto offset_end = offset + static_cast<s64>(size);
|
const auto offset_end = offset + static_cast<s64>(size);
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace ams::fssystem::save {
|
||||||
R_UNLESS(offset <= data_size, fs::ResultInvalidOffset());
|
R_UNLESS(offset <= data_size, fs::ResultInvalidOffset());
|
||||||
|
|
||||||
/* Validate the access range. */
|
/* Validate the access range. */
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, util::AlignUp(data_size, static_cast<size_t>(this->verification_block_size))), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast<size_t>(this->verification_block_size))), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Determine the read extents. */
|
/* Determine the read extents. */
|
||||||
size_t read_size = size;
|
size_t read_size = size;
|
||||||
|
@ -165,7 +165,7 @@ namespace ams::fssystem::save {
|
||||||
|
|
||||||
/* Validate arguments. */
|
/* Validate arguments. */
|
||||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||||
R_UNLESS(IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultInvalidOffset());
|
R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultInvalidOffset());
|
||||||
|
|
||||||
/* Validate the offset. */
|
/* Validate the offset. */
|
||||||
s64 data_size;
|
s64 data_size;
|
||||||
|
@ -173,7 +173,7 @@ namespace ams::fssystem::save {
|
||||||
R_UNLESS(offset < data_size, fs::ResultInvalidOffset());
|
R_UNLESS(offset < data_size, fs::ResultInvalidOffset());
|
||||||
|
|
||||||
/* Validate the access range. */
|
/* Validate the access range. */
|
||||||
R_UNLESS(IStorage::IsRangeValid(offset, size, util::AlignUp(data_size, static_cast<size_t>(this->verification_block_size))), fs::ResultOutOfRange());
|
R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast<size_t>(this->verification_block_size))), fs::ResultOutOfRange());
|
||||||
|
|
||||||
/* Validate preconditions. */
|
/* Validate preconditions. */
|
||||||
AMS_ASSERT(util::IsAligned(offset, this->verification_block_size));
|
AMS_ASSERT(util::IsAligned(offset, this->verification_block_size));
|
||||||
|
|
Loading…
Reference in a new issue