Compare commits
38 Commits
kern_rela_
...
1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7f83b4742 | ||
|
|
8634ea0f7c | ||
|
|
2541f6dd71 | ||
|
|
ff5f376c33 | ||
|
|
d1bc1a5c57 | ||
|
|
990daec3a2 | ||
|
|
c04a262d49 | ||
|
|
7e536f74ae | ||
|
|
891fa32bf1 | ||
|
|
ca25a884b5 | ||
|
|
0189c5f1e6 | ||
|
|
124a1a1ea0 | ||
|
|
82d07e04aa | ||
|
|
bd1bcdf52b | ||
|
|
d27fe8a229 | ||
|
|
1c5edaf4fb | ||
|
|
3cd8ec509c | ||
|
|
3bee3e77ca | ||
|
|
5708bb1557 | ||
|
|
d41de21753 | ||
|
|
06f68a8159 | ||
|
|
d9dc04318d | ||
|
|
d8a36e39f2 | ||
|
|
4758dfa933 | ||
|
|
bc96ebb74c | ||
|
|
a595c232b9 | ||
|
|
ce28591ab2 | ||
|
|
00116450c3 | ||
|
|
179d91a563 | ||
|
|
67a45c97ef | ||
|
|
5a38311ebf | ||
|
|
1ab0bd1765 | ||
|
|
ce8aacef21 | ||
|
|
ec65c39d17 | ||
|
|
b0e520112b | ||
|
|
303c6eb5f9 | ||
|
|
14c8801259 | ||
|
|
960ba52a43 |
@@ -7,6 +7,7 @@ Building Atmosphère is a very straightforward process that relies almost exclus
|
||||
+ [Python 2](https://www.python.org) (Python 3 may work as well, but this is not guaranteed)
|
||||
+ [LZ4](https://pypi.org/project/lz4)
|
||||
+ [PyCryptodome](https://pypi.org/project/pycryptodome) (optional)
|
||||
+ [hactool](https://github.com/SciresM/hactool)
|
||||
|
||||
## Instructions
|
||||
1. Follow the guide located [here](https://devkitpro.org/wiki/Getting_Started) to install and configure all the tools necessary for the build process.
|
||||
@@ -17,6 +18,7 @@ Building Atmosphère is a very straightforward process that relies almost exclus
|
||||
+ `switch-libjpeg-turbo`
|
||||
+ `devkitARM`
|
||||
+ `devkitarm-rules`
|
||||
+ `hactool`
|
||||
|
||||
3. Install the following library via python's package manager `pip`, required by [exosphere](components/exosphere.md):
|
||||
+ `lz4`
|
||||
|
||||
@@ -1,4 +1,38 @@
|
||||
# Changelog
|
||||
## 1.2.0
|
||||
+ `boot` was updated to reflect the latest official behavior for display/battery management.
|
||||
+ This should fix any issues that might result from running older releases on the OLED model, if you're somehow in a position to do so.
|
||||
+ The "target firmware" system was changed to allow the bootloader to specify an approximation, rather than the true target firmware.
|
||||
+ Previously we expected compliant bootloaders to inspect SYSTEM:/ to determine the specific target firmware.
|
||||
+ Now, we only require an approximate version, with major version == true major version and approximate version <= true version.
|
||||
+ This greatly simplifies bootloader requirements, and correspondingly all code for accessing SYSTEM has been removed from fusee.
|
||||
+ This should result in a substantial speedup when booting emummc with fusee, as SYSTEM accesses were the most expensive thing done previously.
|
||||
+ This should resolve any inconsistency in firmware detection when booting via fusee vs hekate.
|
||||
+ This should also improve our compatibility with micro firmware releases, making it more likely that atmosphere "just works" if nothing important has changed.
|
||||
+ Dynamic resource limit determination logic was implemented in `pm` to match latest official behavior.
|
||||
+ This greatly simplifies/makes consistent the resource limits on older firmwares, as well.
|
||||
+ An enormous amount of refactoring was performed under the hood, including:
|
||||
+ **Please Note**: If you are a developer who uses Atmosphere-libs, a number of changes here are breaking.
|
||||
+ Feel free to contact SciresM#0524 for help updating your program.
|
||||
+ The OS namespace had many primitives implemented/made more accurate.
|
||||
+ Since mesosphere is now always-on, os::LightEvent (which required newer SVCs) is now globally usable (and used by stratosphere where relevant).
|
||||
+ Assertions are now true no-ops when building for release.
|
||||
+ Stratosphere is now built with -Wextra/-Werror.
|
||||
+ Most "common" logic in system module main.cpp files was moved into libstratosphere.
|
||||
+ **Please Note**: main.cpp files for prior atmosphere-libs will no longer work, for a really large number of reasons.
|
||||
+ A number of longstanding code style issues were corrected.
|
||||
+ Mesosphere now uses util::BitFlagSet for SVC permissions.
|
||||
+ Mesosphere now puts its relocation table inside .bss, which allows that memory to be reclaimed after relocations are performed.
|
||||
+ These changes save ~16KB of memory in the kernel, all said and done.
|
||||
+ A number of locations in stratosphere where memory could be saved were spotted and taken advantage of, leading to ~150-200KB of saved memory.
|
||||
+ The `spl` and `loader` system module was refactored to better reflect official logic.
|
||||
+ `sf` ipc server code was updated to only emit mitm/defer logic when that logic is actually required somewhere in process.
|
||||
+ `tipc` ipc server code was updated to reflect changes to official logic made in 13.0.0.
|
||||
+ Many, many other minor changes, please talk to SciresM#0524 or read the relevant commits if you want to know more.
|
||||
+ A number of minor issues were fixed, including:
|
||||
+ Mesosphere's handling of SVC permissions on thread pin/unpin was updated to reflect official kernel behavior.
|
||||
+ util::CountTrailingZeroes() was fixed to calculate the correct value when used at compile-time.
|
||||
+ General system stability improvements to enhance the user's experience.
|
||||
## 1.1.1
|
||||
+ A bug was fixed which caused some memory to leak when launching a game with mods enabled, eventually causing a crash after enough game launches without rebooting.
|
||||
+ General system stability improvements to enhance the user's experience.
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace ams::secmon::loader {
|
||||
|
||||
class Lz4Uncompressor {
|
||||
private:
|
||||
const u8 *src;
|
||||
size_t src_size;
|
||||
size_t src_offset;
|
||||
u8 *dst;
|
||||
size_t dst_size;
|
||||
size_t dst_offset;
|
||||
const u8 *m_src;
|
||||
size_t m_src_size;
|
||||
size_t m_src_offset;
|
||||
u8 *m_dst;
|
||||
size_t m_dst_size;
|
||||
size_t m_dst_offset;
|
||||
public:
|
||||
Lz4Uncompressor(void *dst, size_t dst_size, const void *src, size_t src_size) : src(static_cast<const u8 *>(src)), src_size(src_size), src_offset(0), dst(static_cast<u8 *>(dst)), dst_size(dst_size), dst_offset(0) {
|
||||
Lz4Uncompressor(void *dst, size_t dst_size, const void *src, size_t src_size) : m_src(static_cast<const u8 *>(src)), m_src_size(src_size), m_src_offset(0), m_dst(static_cast<u8 *>(dst)), m_dst_size(dst_size), m_dst_offset(0) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ams::secmon::loader {
|
||||
this->Copy(this->GetCopySize(control >> 4));
|
||||
|
||||
/* If we've exceeded size, we're done. */
|
||||
if (this->src_offset >= this->src_size) {
|
||||
if (m_src_offset >= m_src_size) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -55,21 +55,21 @@ namespace ams::secmon::loader {
|
||||
const size_t wide_copy_size = this->GetCopySize(control & 0xF);
|
||||
|
||||
/* Copy bytes. */
|
||||
const size_t end_offset = this->dst_offset + wide_copy_size + 4;
|
||||
for (size_t cur_offset = this->dst_offset; cur_offset < end_offset; this->dst_offset = (++cur_offset)) {
|
||||
const size_t end_offset = m_dst_offset + wide_copy_size + 4;
|
||||
for (size_t cur_offset = m_dst_offset; cur_offset < end_offset; m_dst_offset = (++cur_offset)) {
|
||||
AMS_ABORT_UNLESS(wide_offset <= cur_offset);
|
||||
|
||||
this->dst[cur_offset] = this->dst[cur_offset - wide_offset];
|
||||
m_dst[cur_offset] = m_dst[cur_offset - wide_offset];
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
u8 ReadByte() {
|
||||
return this->src[this->src_offset++];
|
||||
return m_src[m_src_offset++];
|
||||
}
|
||||
|
||||
bool CanRead() const {
|
||||
return this->src_offset < this->src_size;
|
||||
return m_src_offset < m_src_size;
|
||||
}
|
||||
|
||||
size_t GetCopySize(u8 control) {
|
||||
@@ -87,9 +87,9 @@ namespace ams::secmon::loader {
|
||||
}
|
||||
|
||||
void Copy(size_t size) {
|
||||
__builtin_memcpy(this->dst + this->dst_offset, this->src + this->src_offset, size);
|
||||
this->dst_offset += size;
|
||||
this->src_offset += size;
|
||||
__builtin_memcpy(m_dst + m_dst_offset, m_src + m_src_offset, size);
|
||||
m_dst_offset += size;
|
||||
m_src_offset += size;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -76,10 +76,10 @@ namespace ams::secmon::fatal {
|
||||
Bit_Readable = 31,
|
||||
};
|
||||
private:
|
||||
u32 value;
|
||||
u32 m_value;
|
||||
protected:
|
||||
constexpr ALWAYS_INLINE u32 SelectBit(Bit n) const {
|
||||
return (this->value & (1u << n));
|
||||
return (m_value & (1u << n));
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool GetBit(Bit n) const {
|
||||
@@ -97,7 +97,7 @@ namespace ams::secmon::fatal {
|
||||
ALWAYS_INLINE void SetValue(u32 v) {
|
||||
/* Prevent re-ordering around entry modifications. */
|
||||
__asm__ __volatile__("" ::: "memory");
|
||||
this->value = v;
|
||||
m_value = v;
|
||||
__asm__ __volatile__("" ::: "memory");
|
||||
}
|
||||
public:
|
||||
@@ -112,7 +112,7 @@ namespace ams::secmon::fatal {
|
||||
|
||||
constexpr ALWAYS_INLINE u32 GetAttributes() const { return this->SelectBit(Bit_NonSecure) | this->SelectBit(Bit_Writeable) | this->SelectBit(Bit_Readable); }
|
||||
|
||||
constexpr ALWAYS_INLINE dd::PhysicalAddress GetPhysicalAddress() const { return (static_cast<u64>(this->value) << DevicePageBits) & PhysicalAddressMask; }
|
||||
constexpr ALWAYS_INLINE dd::PhysicalAddress GetPhysicalAddress() const { return (static_cast<u64>(m_value) << DevicePageBits) & PhysicalAddressMask; }
|
||||
|
||||
ALWAYS_INLINE void Invalidate() { this->SetValue(0); }
|
||||
};
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace ams::secmon::fatal {
|
||||
const int prefix_len = std::strlen(automatic_backups_prefix);
|
||||
|
||||
for (size_t i = 0; i + prefix_len < f_ctx->stack_dump_size; ++i) {
|
||||
if (std::memcmp(&f_ctx->stack_dump[i], automatic_backups_prefix, prefix_len) == 0) {
|
||||
if (std::memcmp(f_ctx->stack_dump + i, automatic_backups_prefix, prefix_len) == 0) {
|
||||
suggestion = "The atmosphere directory may improperly have archive bits set.\n"
|
||||
"Please try running an archive bit fixer tool (for example, the one in Hekate).\n";
|
||||
break;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ams::fs {
|
||||
};
|
||||
|
||||
struct ReadOption {
|
||||
u32 value;
|
||||
u32 _value;
|
||||
|
||||
static const ReadOption None;
|
||||
};
|
||||
@@ -36,7 +36,7 @@ namespace ams::fs {
|
||||
inline constexpr const ReadOption ReadOption::None = {0};
|
||||
|
||||
inline constexpr bool operator==(const ReadOption &lhs, const ReadOption &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
return lhs._value == rhs._value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const ReadOption &lhs, const ReadOption &rhs) {
|
||||
@@ -46,10 +46,10 @@ namespace ams::fs {
|
||||
static_assert(util::is_pod<ReadOption>::value && sizeof(ReadOption) == sizeof(u32));
|
||||
|
||||
struct WriteOption {
|
||||
u32 value;
|
||||
u32 _value;
|
||||
|
||||
constexpr inline bool HasFlushFlag() const {
|
||||
return this->value & 1;
|
||||
return _value & 1;
|
||||
}
|
||||
|
||||
static const WriteOption None;
|
||||
@@ -60,7 +60,7 @@ namespace ams::fs {
|
||||
inline constexpr const WriteOption WriteOption::Flush = {1};
|
||||
|
||||
inline constexpr bool operator==(const WriteOption &lhs, const WriteOption &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
return lhs._value == rhs._value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const WriteOption &lhs, const WriteOption &rhs) {
|
||||
|
||||
@@ -23,16 +23,16 @@ namespace ams::secmon {
|
||||
|
||||
void *PageMapperImpl::GetPointerTo(uintptr_t phys, size_t size) const {
|
||||
/* Ensure we stay within the page. */
|
||||
if (util::AlignDown(phys, 4_KB) != this->physical_address) {
|
||||
if (util::AlignDown(phys, 4_KB) != m_physical_address) {
|
||||
return nullptr;
|
||||
}
|
||||
if (size != 0) {
|
||||
if (util::AlignDown(phys + size - 1, 4_KB) != this->physical_address) {
|
||||
if (util::AlignDown(phys + size - 1, 4_KB) != m_physical_address) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return reinterpret_cast<void *>(phys + (this->virtual_address - this->physical_address));
|
||||
return reinterpret_cast<void *>(phys + (m_virtual_address - m_physical_address));
|
||||
}
|
||||
|
||||
bool PageMapperImpl::CopyToMapping(uintptr_t dst_phys, const void *src, size_t size) const {
|
||||
|
||||
@@ -22,10 +22,10 @@ namespace ams::secmon {
|
||||
|
||||
class PageMapperImpl {
|
||||
private:
|
||||
uintptr_t physical_address;
|
||||
uintptr_t virtual_address;
|
||||
uintptr_t m_physical_address;
|
||||
uintptr_t m_virtual_address;
|
||||
public:
|
||||
constexpr PageMapperImpl(uintptr_t phys) : physical_address(util::AlignDown(phys, 4_KB)), virtual_address() { /* ... */ }
|
||||
constexpr PageMapperImpl(uintptr_t phys) : m_physical_address(util::AlignDown(phys, 4_KB)), m_virtual_address() { /* ... */ }
|
||||
|
||||
void *GetPointerTo(uintptr_t phys, size_t size) const;
|
||||
|
||||
@@ -37,14 +37,14 @@ namespace ams::secmon {
|
||||
|
||||
template<auto F>
|
||||
bool MapImpl() {
|
||||
this->virtual_address = F(this->physical_address);
|
||||
return this->virtual_address != 0;
|
||||
m_virtual_address = F(m_physical_address);
|
||||
return m_virtual_address != 0;
|
||||
}
|
||||
|
||||
template<auto F>
|
||||
void UnmapImpl() {
|
||||
F();
|
||||
this->virtual_address = 0;
|
||||
m_virtual_address = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@ namespace ams::secmon::smc {
|
||||
case CipherMode_CbcDecryption: se::DecryptAes128CbcAsync(output_address, slot, input_address, size, iv, sizeof(iv), SecurityEngineDoneHandler); break;
|
||||
case CipherMode_Ctr: se::ComputeAes128CtrAsync(output_address, slot, input_address, size, iv, sizeof(iv), SecurityEngineDoneHandler); break;
|
||||
case CipherMode_Cmac:
|
||||
return SmcResult::NotImplemented;
|
||||
return SmcResult::NotSupported;
|
||||
default:
|
||||
return SmcResult::InvalidArgument;
|
||||
}
|
||||
@@ -765,8 +765,8 @@ namespace ams::secmon::smc {
|
||||
const auto which = static_cast<SecureData>(args.r[1]);
|
||||
|
||||
/* Validate arguments/conditions. */
|
||||
SMC_R_UNLESS(fuse::GetPatchVersion() < fuse::PatchVersion_Odnx02A2, NotImplemented);
|
||||
SMC_R_UNLESS(which < SecureData_Count, NotImplemented);
|
||||
SMC_R_UNLESS(fuse::GetPatchVersion() < fuse::PatchVersion_Odnx02A2, NotSupported);
|
||||
SMC_R_UNLESS(which < SecureData_Count, NotSupported);
|
||||
|
||||
/* Use a temporary buffer. */
|
||||
u8 secure_data[AesKeySize];
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace ams::secmon::smc {
|
||||
|
||||
enum class SmcResult : u32 {
|
||||
Success = 0,
|
||||
NotImplemented = 1,
|
||||
NotSupported = 1,
|
||||
InvalidArgument = 2,
|
||||
Busy = 3,
|
||||
NoAsyncOperation = 4,
|
||||
|
||||
@@ -164,6 +164,7 @@ namespace ams::secmon::smc {
|
||||
}
|
||||
|
||||
constinit u64 g_payload_address = 0;
|
||||
constinit bool g_set_true_target_firmware = false;
|
||||
|
||||
SmcResult GetConfig(SmcArguments &args, bool kern) {
|
||||
switch (static_cast<ConfigItem>(args.r[1])) {
|
||||
@@ -213,8 +214,8 @@ namespace ams::secmon::smc {
|
||||
case ConfigItem::IsChargerHiZModeEnabled:
|
||||
args.r[1] = IsChargerHiZModeEnabled();
|
||||
break;
|
||||
case ConfigItem::QuestState:
|
||||
args.r[1] = fuse::GetQuestState();
|
||||
case ConfigItem::RetailInteractiveDisplayState:
|
||||
args.r[1] = fuse::GetRetailInteractiveDisplayState();
|
||||
break;
|
||||
case ConfigItem::RegulatorType:
|
||||
args.r[1] = fuse::GetRegulator();
|
||||
@@ -240,11 +241,15 @@ namespace ams::secmon::smc {
|
||||
break;
|
||||
case ConfigItem::ExosphereApiVersion:
|
||||
/* Get information about the current exosphere version. */
|
||||
args.r[1] = (static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MAJOR & 0xFF) << 56) |
|
||||
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MINOR & 0xFF) << 48) |
|
||||
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MICRO & 0xFF) << 40) |
|
||||
(static_cast<u64>(GetKeyGeneration()) << 32) |
|
||||
(static_cast<u64>(GetTargetFirmware()) << 0);
|
||||
if (kern || g_set_true_target_firmware) {
|
||||
args.r[1] = (static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MAJOR & 0xFF) << 56) |
|
||||
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MINOR & 0xFF) << 48) |
|
||||
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MICRO & 0xFF) << 40) |
|
||||
(static_cast<u64>(GetKeyGeneration()) << 32) |
|
||||
(static_cast<u64>(GetTargetFirmware()) << 0);
|
||||
} else {
|
||||
return SmcResult::NotInitialized;
|
||||
}
|
||||
break;
|
||||
case ConfigItem::ExosphereNeedsReboot:
|
||||
/* We are executing, so we aren't in the process of rebooting. */
|
||||
@@ -297,6 +302,18 @@ namespace ams::secmon::smc {
|
||||
(static_cast<u64>(ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR & 0xFF) << 16) |
|
||||
(static_cast<u64>(ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO & 0xFF) << 8);
|
||||
break;
|
||||
case ConfigItem::ExosphereApproximateApiVersion:
|
||||
/* Get information about the current exosphere version. */
|
||||
if (!g_set_true_target_firmware) {
|
||||
args.r[1] = (static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MAJOR & 0xFF) << 56) |
|
||||
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MINOR & 0xFF) << 48) |
|
||||
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MICRO & 0xFF) << 40) |
|
||||
(static_cast<u64>(GetKeyGeneration()) << 32) |
|
||||
(static_cast<u64>(GetTargetFirmware()) << 0);
|
||||
} else {
|
||||
return SmcResult::Busy;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return SmcResult::InvalidArgument;
|
||||
}
|
||||
@@ -312,6 +329,14 @@ namespace ams::secmon::smc {
|
||||
/* Configure the HiZ mode. */
|
||||
SetChargerHiZModeEnabled(static_cast<bool>(args.r[3]));
|
||||
break;
|
||||
case ConfigItem::ExosphereApiVersion:
|
||||
if (!g_set_true_target_firmware) {
|
||||
::ams::secmon::impl::SetTargetFirmware(static_cast<ams::TargetFirmware>(args.r[3] & 0xFFFFFFFF));
|
||||
g_set_true_target_firmware = true;
|
||||
} else {
|
||||
return SmcResult::Busy;
|
||||
}
|
||||
break;
|
||||
case ConfigItem::ExosphereNeedsReboot:
|
||||
if (soc_type == fuse::SocType_Erista) {
|
||||
switch (static_cast<UserRebootType>(args.r[3])) {
|
||||
@@ -345,7 +370,7 @@ namespace ams::secmon::smc {
|
||||
PerformUserShutDown();
|
||||
}
|
||||
} else /* if (soc_type == fuse::SocType_Mariko) */ {
|
||||
return SmcResult::NotImplemented;
|
||||
return SmcResult::NotSupported;
|
||||
}
|
||||
break;
|
||||
case ConfigItem::ExospherePayloadAddress:
|
||||
@@ -389,7 +414,7 @@ namespace ams::secmon::smc {
|
||||
|
||||
/* Validate arguments. */
|
||||
/* NOTE: In the future, configuration for non-NAND storage may be implemented. */
|
||||
SMC_R_UNLESS(mmc == EmummcMmc_Nand, NotImplemented);
|
||||
SMC_R_UNLESS(mmc == EmummcMmc_Nand, NotSupported);
|
||||
SMC_R_UNLESS(user_offset + 2 * sizeof(EmummcFilePath) <= 4_KB, InvalidArgument);
|
||||
|
||||
/* Get the emummc config. */
|
||||
|
||||
@@ -34,24 +34,25 @@ namespace ams::secmon::smc {
|
||||
IsDevelopmentFunctionEnabled = 11,
|
||||
KernelConfiguration = 12,
|
||||
IsChargerHiZModeEnabled = 13,
|
||||
QuestState = 14,
|
||||
RetailInteractiveDisplayState = 14,
|
||||
RegulatorType = 15,
|
||||
DeviceUniqueKeyGeneration = 16,
|
||||
Package2Hash = 17,
|
||||
|
||||
/* Extension config items for exosphere. */
|
||||
ExosphereApiVersion = 65000,
|
||||
ExosphereNeedsReboot = 65001,
|
||||
ExosphereNeedsShutdown = 65002,
|
||||
ExosphereGitCommitHash = 65003,
|
||||
ExosphereHasRcmBugPatch = 65004,
|
||||
ExosphereBlankProdInfo = 65005,
|
||||
ExosphereAllowCalWrites = 65006,
|
||||
ExosphereEmummcType = 65007,
|
||||
ExospherePayloadAddress = 65008,
|
||||
ExosphereLogConfiguration = 65009,
|
||||
ExosphereForceEnableUsb30 = 65010,
|
||||
ExosphereSupportedHosVersion = 65011,
|
||||
ExosphereApiVersion = 65000,
|
||||
ExosphereNeedsReboot = 65001,
|
||||
ExosphereNeedsShutdown = 65002,
|
||||
ExosphereGitCommitHash = 65003,
|
||||
ExosphereHasRcmBugPatch = 65004,
|
||||
ExosphereBlankProdInfo = 65005,
|
||||
ExosphereAllowCalWrites = 65006,
|
||||
ExosphereEmummcType = 65007,
|
||||
ExospherePayloadAddress = 65008,
|
||||
ExosphereLogConfiguration = 65009,
|
||||
ExosphereForceEnableUsb30 = 65010,
|
||||
ExosphereSupportedHosVersion = 65011,
|
||||
ExosphereApproximateApiVersion = 65012,
|
||||
};
|
||||
|
||||
SmcResult SmcGetConfigUser(SmcArguments &args);
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace ams::secmon::smc {
|
||||
SmcResult SmcWriteAddress(SmcArguments &args) {
|
||||
/* NOTE: This smc was deprecated in Atmosphère 0.13.0. */
|
||||
AMS_UNUSED(args);
|
||||
return SmcResult::NotImplemented;
|
||||
return SmcResult::NotSupported;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,31 +55,31 @@ namespace ams::secmon::smc {
|
||||
|
||||
class PrepareEsDeviceUniqueKeyAsyncArguments {
|
||||
private:
|
||||
int generation;
|
||||
EsCommonKeyType type;
|
||||
u8 label_digest[crypto::Sha256Generator::HashSize];
|
||||
int m_generation;
|
||||
EsCommonKeyType m_type;
|
||||
u8 m_label_digest[crypto::Sha256Generator::HashSize];
|
||||
public:
|
||||
void Set(int gen, EsCommonKeyType t, const u8 ld[crypto::Sha256Generator::HashSize]) {
|
||||
this->generation = gen;
|
||||
this->type = t;
|
||||
std::memcpy(this->label_digest, ld, sizeof(this->label_digest));
|
||||
m_generation = gen;
|
||||
m_type = t;
|
||||
std::memcpy(m_label_digest, ld, sizeof(m_label_digest));
|
||||
}
|
||||
|
||||
int GetKeyGeneration() const { return this->generation; }
|
||||
EsCommonKeyType GetCommonKeyType() const { return this->type; }
|
||||
void GetLabelDigest(u8 dst[crypto::Sha256Generator::HashSize]) const { std::memcpy(dst, this->label_digest, sizeof(this->label_digest)); }
|
||||
int GetKeyGeneration() const { return m_generation; }
|
||||
EsCommonKeyType GetCommonKeyType() const { return m_type; }
|
||||
void GetLabelDigest(u8 dst[crypto::Sha256Generator::HashSize]) const { std::memcpy(dst, m_label_digest, sizeof(m_label_digest)); }
|
||||
};
|
||||
|
||||
class ModularExponentiateByStorageKeyAsyncArguments {
|
||||
private:
|
||||
u8 msg[se::RsaSize];
|
||||
u8 m_msg[se::RsaSize];
|
||||
public:
|
||||
void Set(const void *m, size_t m_size) {
|
||||
AMS_UNUSED(m_size);
|
||||
std::memcpy(this->msg, m, sizeof(this->msg));
|
||||
std::memcpy(m_msg, m, sizeof(m_msg));
|
||||
}
|
||||
|
||||
const u8 *GetMessage() const { return this->msg; }
|
||||
const u8 *GetMessage() const { return m_msg; }
|
||||
};
|
||||
|
||||
constinit SmcResult g_exp_mod_result = SmcResult::Success;
|
||||
|
||||
@@ -73,6 +73,7 @@ SECTIONS
|
||||
fusee_loader_main.o(.text*)
|
||||
fusee_loader_uncompress.o(.text*)
|
||||
fusee_loader_error.o(.text*)
|
||||
*(.text.memcpy)
|
||||
fusee_loader_main.o(.rodata*)
|
||||
fusee_loader_uncompress.o(.rodata*)
|
||||
fusee_loader_error.o(.rodata*)
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace ams::nxboot::loader {
|
||||
|
||||
class Lz4Uncompressor {
|
||||
private:
|
||||
const u8 *src;
|
||||
size_t src_size;
|
||||
size_t src_offset;
|
||||
u8 *dst;
|
||||
size_t dst_size;
|
||||
size_t dst_offset;
|
||||
const u8 *m_src;
|
||||
size_t m_src_size;
|
||||
size_t m_src_offset;
|
||||
u8 *m_dst;
|
||||
size_t m_dst_size;
|
||||
size_t m_dst_offset;
|
||||
public:
|
||||
Lz4Uncompressor(void *dst, size_t dst_size, const void *src, size_t src_size) : src(static_cast<const u8 *>(src)), src_size(src_size), src_offset(0), dst(static_cast<u8 *>(dst)), dst_size(dst_size), dst_offset(0) {
|
||||
Lz4Uncompressor(void *dst, size_t dst_size, const void *src, size_t src_size) : m_src(static_cast<const u8 *>(src)), m_src_size(src_size), m_src_offset(0), m_dst(static_cast<u8 *>(dst)), m_dst_size(dst_size), m_dst_offset(0) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ams::nxboot::loader {
|
||||
this->Copy(this->GetCopySize(control >> 4));
|
||||
|
||||
/* If we've exceeded size, we're done. */
|
||||
if (this->src_offset >= this->src_size) {
|
||||
if (m_src_offset >= m_src_size) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -55,21 +55,21 @@ namespace ams::nxboot::loader {
|
||||
const size_t wide_copy_size = this->GetCopySize(control & 0xF);
|
||||
|
||||
/* Copy bytes. */
|
||||
const size_t end_offset = this->dst_offset + wide_copy_size + 4;
|
||||
for (size_t cur_offset = this->dst_offset; cur_offset < end_offset; this->dst_offset = (++cur_offset)) {
|
||||
const size_t end_offset = m_dst_offset + wide_copy_size + 4;
|
||||
for (size_t cur_offset = m_dst_offset; cur_offset < end_offset; m_dst_offset = (++cur_offset)) {
|
||||
AMS_ABORT_UNLESS(wide_offset <= cur_offset);
|
||||
|
||||
this->dst[cur_offset] = this->dst[cur_offset - wide_offset];
|
||||
m_dst[cur_offset] = m_dst[cur_offset - wide_offset];
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
u8 ReadByte() {
|
||||
return this->src[this->src_offset++];
|
||||
return m_src[m_src_offset++];
|
||||
}
|
||||
|
||||
bool CanRead() const {
|
||||
return this->src_offset < this->src_size;
|
||||
return m_src_offset < m_src_size;
|
||||
}
|
||||
|
||||
size_t GetCopySize(u8 control) {
|
||||
@@ -87,11 +87,9 @@ namespace ams::nxboot::loader {
|
||||
}
|
||||
|
||||
void Copy(size_t size) {
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
this->dst[this->dst_offset + i] = this->src[this->src_offset + i];
|
||||
}
|
||||
this->dst_offset += size;
|
||||
this->src_offset += size;
|
||||
__builtin_memcpy(m_dst + m_dst_offset, m_src + m_src_offset, size);
|
||||
m_dst_offset += size;
|
||||
m_src_offset += size;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
2
fusee/program/source/fatfs/fusee_diskio.cpp
vendored
2
fusee/program/source/fatfs/fusee_diskio.cpp
vendored
@@ -27,7 +27,7 @@ bool diskio_write_sd_card(size_t sector_index, size_t sector_count, const void *
|
||||
}
|
||||
|
||||
bool diskio_read_system(void *dst, size_t size, size_t sector_index, size_t sector_count) {
|
||||
return R_SUCCEEDED(::ams::nxboot::ReadSystem(sector_index * 0x200, dst, size));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool diskio_write_system(size_t sector_index, size_t sector_count, const void *src, size_t size) {
|
||||
|
||||
@@ -27,10 +27,8 @@ namespace ams::fs {
|
||||
constexpr size_t MaxDirectories = 2;
|
||||
|
||||
constinit bool g_is_sd_mounted = false;
|
||||
constinit bool g_is_sys_mounted = false;
|
||||
|
||||
alignas(0x10) constinit FATFS g_sd_fs = {};
|
||||
alignas(0x10) constinit FATFS g_sys_fs = {};
|
||||
|
||||
alignas(0x10) constinit FIL g_files[MaxFiles] = {};
|
||||
alignas(0x10) constinit DIR g_dirs[MaxDirectories] = {};
|
||||
@@ -131,18 +129,6 @@ namespace ams::fs {
|
||||
g_is_sd_mounted = false;
|
||||
}
|
||||
|
||||
bool MountSystem() {
|
||||
AMS_ASSERT(!g_is_sys_mounted);
|
||||
g_is_sys_mounted = f_mount(std::addressof(g_sys_fs), "sys:", 1) == FR_OK;
|
||||
return g_is_sys_mounted;
|
||||
}
|
||||
|
||||
void UnmountSystem() {
|
||||
AMS_ASSERT(g_is_sys_mounted);
|
||||
f_unmount("sys:");
|
||||
g_is_sys_mounted = false;
|
||||
}
|
||||
|
||||
Result GetEntryType(DirectoryEntryType *out_entry_type, bool *out_archive, const char *path) {
|
||||
/* Get the file info. */
|
||||
FILINFO info;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ams::fs {
|
||||
};
|
||||
|
||||
struct ReadOption {
|
||||
u32 value;
|
||||
u32 _value;
|
||||
|
||||
static const ReadOption None;
|
||||
};
|
||||
@@ -36,7 +36,7 @@ namespace ams::fs {
|
||||
inline constexpr const ReadOption ReadOption::None = {0};
|
||||
|
||||
inline constexpr bool operator==(const ReadOption &lhs, const ReadOption &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
return lhs._value == rhs._value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const ReadOption &lhs, const ReadOption &rhs) {
|
||||
@@ -46,10 +46,10 @@ namespace ams::fs {
|
||||
static_assert(util::is_pod<ReadOption>::value && sizeof(ReadOption) == sizeof(u32));
|
||||
|
||||
struct WriteOption {
|
||||
u32 value;
|
||||
u32 _value;
|
||||
|
||||
constexpr inline bool HasFlushFlag() const {
|
||||
return this->value & 1;
|
||||
return _value & 1;
|
||||
}
|
||||
|
||||
static const WriteOption None;
|
||||
@@ -60,7 +60,7 @@ namespace ams::fs {
|
||||
inline constexpr const WriteOption WriteOption::Flush = {1};
|
||||
|
||||
inline constexpr bool operator==(const WriteOption &lhs, const WriteOption &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
return lhs._value == rhs._value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const WriteOption &lhs, const WriteOption &rhs) {
|
||||
@@ -98,9 +98,6 @@ namespace ams::fs {
|
||||
bool MountSdCard();
|
||||
void UnmountSdCard();
|
||||
|
||||
bool MountSystem();
|
||||
void UnmountSystem();
|
||||
|
||||
Result GetEntryType(DirectoryEntryType *out_entry_type, bool *out_archive, const char *path);
|
||||
|
||||
Result CreateFile(const char *path, s64 size);
|
||||
|
||||
@@ -181,112 +181,6 @@ namespace ams::nxboot {
|
||||
constinit fs::IStorage *g_boot0_storage = nullptr;
|
||||
constinit fs::IStorage *g_user_storage = nullptr;
|
||||
|
||||
class SystemPartitionStorage : public fs::IStorage {
|
||||
private:
|
||||
static constexpr size_t CacheEntries = BITSIZEOF(u32);
|
||||
static constexpr size_t SectorSize = 0x4000;
|
||||
private:
|
||||
fs::SubStorage m_storage;
|
||||
u8 *m_sector_cache;
|
||||
u32 *m_sector_ids;
|
||||
u32 m_sector_flags;
|
||||
u32 m_next_idx;
|
||||
private:
|
||||
Result LoadSector(u8 *sector, u32 sector_id) {
|
||||
/* Read the sector data. */
|
||||
R_TRY(m_storage.Read(static_cast<s64>(sector_id) * SectorSize, sector, SectorSize));
|
||||
|
||||
/* Decrypt the sector. */
|
||||
se::DecryptAes128Xts(sector, SectorSize, pkg1::AesKeySlot_BootloaderSystem0, pkg1::AesKeySlot_BootloaderSystem1, sector, SectorSize, sector_id);
|
||||
|
||||
/* Mark the sector as freshly loaded. */
|
||||
m_sector_flags &= ~(1u << (sector_id % CacheEntries));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetSector(u8 **out_sector, u32 sector_id) {
|
||||
/* Try to find in the cache. */
|
||||
for (size_t i = 0; i < CacheEntries; ++i) {
|
||||
if (m_sector_ids[i] == sector_id) {
|
||||
m_sector_flags &= ~(1u << i);
|
||||
*out_sector = m_sector_cache + SectorSize * i;
|
||||
return ResultSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
/* Find a sector to evict. */
|
||||
while ((m_sector_flags & (1u << m_next_idx)) == 0) {
|
||||
m_sector_flags |= (1u << m_next_idx);
|
||||
m_next_idx = (m_next_idx + 1) % CacheEntries;
|
||||
}
|
||||
|
||||
/* Get the chosen sector. */
|
||||
*out_sector = m_sector_cache + SectorSize * m_next_idx;
|
||||
m_next_idx = (m_next_idx + 1) % CacheEntries;
|
||||
|
||||
/* Load the sector. */
|
||||
return this->LoadSector(*out_sector, sector_id);
|
||||
}
|
||||
public:
|
||||
SystemPartitionStorage(s64 ofs, s64 size) : m_storage(*g_user_storage, ofs, size) {
|
||||
/* Allocate sector cache. */
|
||||
m_sector_cache = static_cast<u8 *>(AllocateAligned(CacheEntries * SectorSize, SectorSize));
|
||||
|
||||
/* Allocate sector ids. */
|
||||
m_sector_ids = static_cast<u32 *>(AllocateAligned(CacheEntries * sizeof(u32), alignof(u32)));
|
||||
for (size_t i = 0; i < CacheEntries; ++i) {
|
||||
m_sector_ids[i] = std::numeric_limits<u32>::max();
|
||||
}
|
||||
|
||||
/* All sectors are dirty. */
|
||||
m_sector_flags = ~0u;
|
||||
|
||||
/* Next sector is 0. */
|
||||
m_next_idx = 0;
|
||||
}
|
||||
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
u32 sector_id = offset / SectorSize;
|
||||
s64 subofs = offset % SectorSize;
|
||||
|
||||
u8 *cur_dst = static_cast<u8 *>(buffer);
|
||||
while (size > 0) {
|
||||
/* Get the current sector. */
|
||||
u8 *sector;
|
||||
R_TRY(this->GetSector(std::addressof(sector), sector_id++));
|
||||
|
||||
/* Copy the data. */
|
||||
const size_t cur_size = std::min<size_t>(SectorSize - subofs, size);
|
||||
std::memcpy(cur_dst, sector + subofs, cur_size);
|
||||
|
||||
/* Advance. */
|
||||
cur_dst += cur_size;
|
||||
size -= cur_size;
|
||||
subofs = 0;
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
virtual Result Flush() override {
|
||||
return m_storage.Flush();
|
||||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
return m_storage.GetSize(out);
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
};
|
||||
|
||||
constinit SystemPartitionStorage *g_system_storage = nullptr;
|
||||
constinit fs::SubStorage *g_package2_storage = nullptr;
|
||||
|
||||
struct Guid {
|
||||
@@ -333,10 +227,6 @@ namespace ams::nxboot {
|
||||
};
|
||||
static_assert(sizeof(Gpt) == 16_KB + 0x200);
|
||||
|
||||
constexpr const u16 SystemPartitionName[] = {
|
||||
'S', 'Y', 'S', 'T', 'E', 'M', 0
|
||||
};
|
||||
|
||||
constexpr const u16 Package2PartitionName[] = {
|
||||
'B', 'C', 'P', 'K', 'G', '2', '-', '1', '-', 'N', 'o', 'r', 'm', 'a', 'l', '-', 'M', 'a', 'i', 'n', 0
|
||||
};
|
||||
@@ -447,27 +337,15 @@ namespace ams::nxboot {
|
||||
const s64 offset = INT64_C(0x200) * gpt->entries[i].starting_lba;
|
||||
const u64 size = UINT64_C(0x200) * (gpt->entries[i].ending_lba + 1 - gpt->entries[i].starting_lba);
|
||||
|
||||
if (std::memcmp(gpt->entries[i].partition_name, SystemPartitionName, sizeof(SystemPartitionName)) == 0) {
|
||||
g_system_storage = AllocateObject<SystemPartitionStorage>(offset, size);
|
||||
} else if (std::memcmp(gpt->entries[i].partition_name, Package2PartitionName, sizeof(Package2PartitionName)) == 0) {
|
||||
if (std::memcmp(gpt->entries[i].partition_name, Package2PartitionName, sizeof(Package2PartitionName)) == 0) {
|
||||
g_package2_storage = AllocateObject<fs::SubStorage>(*g_user_storage, offset, size);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that we created system storage. */
|
||||
if (g_system_storage == nullptr) {
|
||||
ShowFatalError("Failed to initialize SYSTEM\n");
|
||||
}
|
||||
|
||||
/* Check that we created package2 storage. */
|
||||
if (g_package2_storage == nullptr) {
|
||||
ShowFatalError("Failed to initialize Package2\n");
|
||||
}
|
||||
|
||||
/* Mount system. */
|
||||
if (!fs::MountSystem()) {
|
||||
ShowFatalError("Failed to mount SYSTEM\n");
|
||||
}
|
||||
}
|
||||
|
||||
Result ReadBoot0(s64 offset, void *dst, size_t size) {
|
||||
@@ -478,8 +356,4 @@ namespace ams::nxboot {
|
||||
return g_package2_storage->Read(offset, dst, size);
|
||||
}
|
||||
|
||||
Result ReadSystem(s64 offset, void *dst, size_t size) {
|
||||
return g_system_storage->Read(offset, dst, size);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,26 +118,12 @@ namespace ams::nxboot {
|
||||
return R_SUCCEEDED(fs::GetEntryType(std::addressof(entry_type), std::addressof(archive), path)) && entry_type == fs::DirectoryEntryType_Directory;
|
||||
}
|
||||
|
||||
[[maybe_unused]] bool IsFileExist(const char *path) {
|
||||
bool IsFileExist(const char *path) {
|
||||
fs::DirectoryEntryType entry_type;
|
||||
bool archive;
|
||||
return R_SUCCEEDED(fs::GetEntryType(std::addressof(entry_type), std::addressof(archive), path)) && entry_type == fs::DirectoryEntryType_File;
|
||||
}
|
||||
|
||||
bool IsConcatenationFileExist(const char *path) {
|
||||
fs::DirectoryEntryType entry_type;
|
||||
bool archive;
|
||||
return R_SUCCEEDED(fs::GetEntryType(std::addressof(entry_type), std::addressof(archive), path)) && ((entry_type == fs::DirectoryEntryType_File) || (entry_type == fs::DirectoryEntryType_Directory && archive));
|
||||
}
|
||||
|
||||
constinit char g_nca_path[0x40] = "sys:/contents/registered/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.nca";
|
||||
|
||||
bool IsNcaExist(const char *nca_name) {
|
||||
std::memcpy(g_nca_path + 0x19, nca_name, 0x20);
|
||||
|
||||
return IsConcatenationFileExist(g_nca_path);
|
||||
}
|
||||
|
||||
bool ConfigureEmummc() {
|
||||
/* Set magic. */
|
||||
g_emummc_cfg.base_cfg.magic = secmon::EmummcBaseConfiguration::Magic;
|
||||
@@ -220,143 +206,56 @@ namespace ams::nxboot {
|
||||
return package1;
|
||||
}
|
||||
|
||||
ams::TargetFirmware GetTargetFirmware(const u8 *package1) {
|
||||
/* Get first an approximation of the target firmware. */
|
||||
ams::TargetFirmware target_firmware = ams::TargetFirmware_Current;
|
||||
ams::TargetFirmware GetApproximateTargetFirmware(const u8 *package1) {
|
||||
/* Get an approximation of the target firmware. */
|
||||
switch (package1[0x1F]) {
|
||||
case 0x01:
|
||||
target_firmware = ams::TargetFirmware_1_0_0;
|
||||
break;
|
||||
return ams::TargetFirmware_1_0_0;
|
||||
case 0x02:
|
||||
target_firmware = ams::TargetFirmware_2_0_0;
|
||||
break;
|
||||
return ams::TargetFirmware_2_0_0;
|
||||
case 0x04:
|
||||
target_firmware = ams::TargetFirmware_3_0_0;
|
||||
break;
|
||||
return ams::TargetFirmware_3_0_0;
|
||||
case 0x07:
|
||||
target_firmware = ams::TargetFirmware_4_0_0;
|
||||
break;
|
||||
return ams::TargetFirmware_4_0_0;
|
||||
case 0x0B:
|
||||
target_firmware = ams::TargetFirmware_5_0_0;
|
||||
break;
|
||||
return ams::TargetFirmware_5_0_0;
|
||||
case 0x0E:
|
||||
if (std::memcmp(package1 + 0x10, "20180802", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_6_0_0;
|
||||
return ams::TargetFirmware_6_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20181107", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_6_2_0;
|
||||
} else {
|
||||
ShowFatalError("Unable to identify package1!\n");
|
||||
return ams::TargetFirmware_6_2_0;
|
||||
}
|
||||
break;
|
||||
case 0x0F:
|
||||
target_firmware = ams::TargetFirmware_7_0_0;
|
||||
break;
|
||||
return ams::TargetFirmware_7_0_0;
|
||||
case 0x10:
|
||||
if (std::memcmp(package1 + 0x10, "20190314", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_8_0_0;
|
||||
return ams::TargetFirmware_8_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20190531", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_8_1_0;
|
||||
return ams::TargetFirmware_8_1_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20190809", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_9_0_0;
|
||||
return ams::TargetFirmware_9_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20191021", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_9_1_0;
|
||||
return ams::TargetFirmware_9_1_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20200303", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_10_0_0;
|
||||
return ams::TargetFirmware_10_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20201030", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_11_0_0;
|
||||
return ams::TargetFirmware_11_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20210129", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_12_0_0;
|
||||
return ams::TargetFirmware_12_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20210422", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_12_0_2;
|
||||
return ams::TargetFirmware_12_0_2;
|
||||
} else if (std::memcmp(package1 + 0x10, "20210607", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_12_1_0;
|
||||
return ams::TargetFirmware_12_1_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20210805", 8) == 0) {
|
||||
target_firmware = ams::TargetFirmware_13_0_0;
|
||||
} else {
|
||||
ShowFatalError("Unable to identify package1!\n");
|
||||
return ams::TargetFirmware_13_0_0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ShowFatalError("Unable to identify package1!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
#define CHECK_NCA(NCA_ID, VERSION) do { if (IsNcaExist(NCA_ID)) { return ams::TargetFirmware_##VERSION; } } while(0)
|
||||
|
||||
if (target_firmware >= ams::TargetFirmware_13_0_0) {
|
||||
CHECK_NCA("bf2337ee88bd9f963a33b3ecbbc3732a", 13_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_12_1_0) {
|
||||
CHECK_NCA("9d9d83d68d9517f245f3e8cd7f93c416", 12_1_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_12_0_2) {
|
||||
CHECK_NCA("a1863a5c0e1cedd442f5e60b0422dc15", 12_0_3);
|
||||
CHECK_NCA("63d928b5a3016fe8cc0e76d2f06f4e98", 12_0_2);
|
||||
} else if (target_firmware >= ams::TargetFirmware_12_0_0) {
|
||||
CHECK_NCA("e65114b456f9d0b566a80e53bade2d89", 12_0_1);
|
||||
CHECK_NCA("bd4185843550fbba125b20787005d1d2", 12_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_11_0_0) {
|
||||
CHECK_NCA("56211c7a5ed20a5332f5cdda67121e37", 11_0_1);
|
||||
CHECK_NCA("594c90bcdbcccad6b062eadba0cd0e7e", 11_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_10_0_0) {
|
||||
CHECK_NCA("26325de4db3909e0ef2379787c7e671d", 10_2_0);
|
||||
CHECK_NCA("5077973537f6735b564dd7475b779f87", 10_1_1); /* Exclusive to China. */
|
||||
CHECK_NCA("fd1faed0ca750700d254c0915b93d506", 10_1_0);
|
||||
CHECK_NCA("34728c771299443420820d8ae490ea41", 10_0_4);
|
||||
CHECK_NCA("5b1df84f88c3334335bbb45d8522cbb4", 10_0_3);
|
||||
CHECK_NCA("e951bc9dedcd54f65ffd83d4d050f9e0", 10_0_2);
|
||||
CHECK_NCA("36ab1acf0c10a2beb9f7d472685f9a89", 10_0_1);
|
||||
CHECK_NCA("5625cdc21d5f1ca52f6c36ba261505b9", 10_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_9_1_0) {
|
||||
CHECK_NCA("09ef4d92bb47b33861e695ba524a2c17", 9_2_0);
|
||||
CHECK_NCA("c5fbb49f2e3648c8cfca758020c53ecb", 9_1_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_9_0_0) {
|
||||
CHECK_NCA("fd1ffb82dc1da76346343de22edbc97c", 9_0_1);
|
||||
CHECK_NCA("a6af05b33f8f903aab90c8b0fcbcc6a4", 9_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_8_1_0) {
|
||||
CHECK_NCA("724d9b432929ea43e787ad81bf09ae65", 8_1_1); /* 8.1.1-100 from Lite */
|
||||
CHECK_NCA("e9bb0602e939270a9348bddd9b78827b", 8_1_1); /* 8.1.1-12 from chinese gamecard */
|
||||
CHECK_NCA("7eedb7006ad855ec567114be601b2a9d", 8_1_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_8_0_0) {
|
||||
CHECK_NCA("6c5426d27c40288302ad616307867eba", 8_0_1);
|
||||
CHECK_NCA("4fe7b4abcea4a0bcc50975c1a926efcb", 8_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_7_0_0) {
|
||||
CHECK_NCA("e6b22c40bb4fa66a151f1dc8db5a7b5c", 7_0_1);
|
||||
CHECK_NCA("c613bd9660478de69bc8d0e2e7ea9949", 7_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_6_2_0) {
|
||||
CHECK_NCA("6dfaaf1a3cebda6307aa770d9303d9b6", 6_2_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_6_0_0) {
|
||||
CHECK_NCA("1d21680af5a034d626693674faf81b02", 6_1_0);
|
||||
CHECK_NCA("663e74e45ffc86fbbaeb98045feea315", 6_0_1);
|
||||
CHECK_NCA("258c1786b0f6844250f34d9c6f66095b", 6_0_0); /* Release 6.0.0-5.0 */
|
||||
CHECK_NCA("286e30bafd7e4197df6551ad802dd815", 6_0_0); /* Pre-Release 6.0.0-4.0 */
|
||||
} else if (target_firmware >= ams::TargetFirmware_5_0_0) {
|
||||
CHECK_NCA("fce3b0ea366f9c95fe6498b69274b0e7", 5_1_0);
|
||||
CHECK_NCA("c5758b0cb8c6512e8967e38842d35016", 5_0_2);
|
||||
CHECK_NCA("53eb605d4620e8fd50064b24fd57783a", 5_0_1);
|
||||
CHECK_NCA("09a2f9c16ce1c121ae6d231b35d17515", 5_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_4_0_0) {
|
||||
CHECK_NCA("77e1ae7661ad8a718b9b13b70304aeea", 4_1_0);
|
||||
CHECK_NCA("d0e5d20e3260f3083bcc067483b71274", 4_0_1);
|
||||
CHECK_NCA("483a24ee3fd7149f9112d1931166a678", 4_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_3_0_0) {
|
||||
CHECK_NCA("704129fc89e1fcb85c37b3112e51b0fc", 3_0_2);
|
||||
CHECK_NCA("1fb00543307337d523ccefa9923e0c50", 3_0_1);
|
||||
CHECK_NCA("6ebd3447473bade18badbeb5032af87d", 3_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_2_0_0) {
|
||||
CHECK_NCA("d1c991c53a8a9038f8c3157a553d876d", 2_3_0);
|
||||
CHECK_NCA("7f90353dff2d7ce69e19e07ebc0d5489", 2_2_0);
|
||||
CHECK_NCA("e9b3e75fce00e52fe646156634d229b4", 2_1_0);
|
||||
CHECK_NCA("7a1f79f8184d4b9bae1755090278f52c", 2_0_0);
|
||||
} else if (target_firmware >= ams::TargetFirmware_1_0_0) {
|
||||
CHECK_NCA("a1b287e07f8455e8192f13d0e45a2aaf", 1_0_0); /* 1.0.0 from Factory */
|
||||
CHECK_NCA("117f7b9c7da3e8cef02340596af206b3", 1_0_0); /* 1.0.0 from Gamecard */
|
||||
} else {
|
||||
ShowFatalError("Unable to determine target firmware!\n");
|
||||
}
|
||||
|
||||
#undef CHECK_NCA
|
||||
|
||||
/* If we didn't find a more specific firmware, return our package1 approximation. */
|
||||
return target_firmware;
|
||||
ShowFatalError("Unable to identify package1!\n");
|
||||
}
|
||||
|
||||
u8 *LoadBootConfigAndPackage2() {
|
||||
@@ -825,7 +724,7 @@ namespace ams::nxboot {
|
||||
const u8 * const package1 = LoadPackage1(soc_type);
|
||||
|
||||
/* Get target firmware. */
|
||||
const auto target_firmware = GetTargetFirmware(package1);
|
||||
const auto target_firmware = GetApproximateTargetFirmware(package1);
|
||||
|
||||
/* Read/decrypt package2. */
|
||||
u8 * const package2 = LoadBootConfigAndPackage2();
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace ams::nxboot {
|
||||
|
||||
class Lz4Uncompressor {
|
||||
private:
|
||||
const u8 *src;
|
||||
size_t src_size;
|
||||
size_t src_offset;
|
||||
u8 *dst;
|
||||
size_t dst_size;
|
||||
size_t dst_offset;
|
||||
const u8 *m_src;
|
||||
size_t m_src_size;
|
||||
size_t m_src_offset;
|
||||
u8 *m_dst;
|
||||
size_t m_dst_size;
|
||||
size_t m_dst_offset;
|
||||
public:
|
||||
Lz4Uncompressor(void *dst, size_t dst_size, const void *src, size_t src_size) : src(static_cast<const u8 *>(src)), src_size(src_size), src_offset(0), dst(static_cast<u8 *>(dst)), dst_size(dst_size), dst_offset(0) {
|
||||
Lz4Uncompressor(void *dst, size_t dst_size, const void *src, size_t src_size) : m_src(static_cast<const u8 *>(src)), m_src_size(src_size), m_src_offset(0), m_dst(static_cast<u8 *>(dst)), m_dst_size(dst_size), m_dst_offset(0) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ams::nxboot {
|
||||
this->Copy(this->GetCopySize(control >> 4));
|
||||
|
||||
/* If we've exceeded size, we're done. */
|
||||
if (this->src_offset >= this->src_size) {
|
||||
if (m_src_offset >= m_src_size) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -55,21 +55,21 @@ namespace ams::nxboot {
|
||||
const size_t wide_copy_size = this->GetCopySize(control & 0xF);
|
||||
|
||||
/* Copy bytes. */
|
||||
const size_t end_offset = this->dst_offset + wide_copy_size + 4;
|
||||
for (size_t cur_offset = this->dst_offset; cur_offset < end_offset; this->dst_offset = (++cur_offset)) {
|
||||
const size_t end_offset = m_dst_offset + wide_copy_size + 4;
|
||||
for (size_t cur_offset = m_dst_offset; cur_offset < end_offset; m_dst_offset = (++cur_offset)) {
|
||||
AMS_ABORT_UNLESS(wide_offset <= cur_offset);
|
||||
|
||||
this->dst[cur_offset] = this->dst[cur_offset - wide_offset];
|
||||
m_dst[cur_offset] = m_dst[cur_offset - wide_offset];
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
u8 ReadByte() {
|
||||
return this->src[this->src_offset++];
|
||||
return m_src[m_src_offset++];
|
||||
}
|
||||
|
||||
bool CanRead() const {
|
||||
return this->src_offset < this->src_size;
|
||||
return m_src_offset < m_src_size;
|
||||
}
|
||||
|
||||
size_t GetCopySize(u8 control) {
|
||||
@@ -87,9 +87,9 @@ namespace ams::nxboot {
|
||||
}
|
||||
|
||||
void Copy(size_t size) {
|
||||
__builtin_memcpy(this->dst + this->dst_offset, this->src + this->src_offset, size);
|
||||
this->dst_offset += size;
|
||||
this->src_offset += size;
|
||||
__builtin_memcpy(m_dst + m_dst_offset, m_src + m_src_offset, size);
|
||||
m_dst_offset += size;
|
||||
m_src_offset += size;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[subrepo]
|
||||
remote = https://github.com/Atmosphere-NX/Atmosphere-libs
|
||||
branch = master
|
||||
commit = 0a4c2759a1f73cb5581ed2e87c20e05440a2c037
|
||||
parent = d14290e3572c52f4dd9ed2a16f698ba12e9eea67
|
||||
commit = cf765c0946cc5c828364ae6bfccddc4041304f28
|
||||
parent = 8634ea0f7c4f0e68adf2dfaaddc6ae1e225c4fc2
|
||||
method = merge
|
||||
cmdver = 0.4.1
|
||||
|
||||
@@ -81,9 +81,9 @@ namespace ams::fuse {
|
||||
DramId_Count,
|
||||
};
|
||||
|
||||
enum QuestState {
|
||||
QuestState_Disabled = 0,
|
||||
QuestState_Enabled = 1,
|
||||
enum RetailInteractiveDisplayState {
|
||||
RetailInteractiveDisplayState_Disabled = 0,
|
||||
RetailInteractiveDisplayState_Enabled = 1,
|
||||
};
|
||||
|
||||
void SetRegisterAddress(uintptr_t address);
|
||||
@@ -102,19 +102,19 @@ namespace ams::fuse {
|
||||
|
||||
bool GetSecureBootKey(void *dst);
|
||||
|
||||
void GetEcid(br::BootEcid *out);
|
||||
HardwareType GetHardwareType();
|
||||
HardwareState GetHardwareState();
|
||||
u64 GetDeviceId();
|
||||
PatchVersion GetPatchVersion();
|
||||
QuestState GetQuestState();
|
||||
pmic::Regulator GetRegulator();
|
||||
int GetDeviceUniqueKeyGeneration();
|
||||
void GetEcid(br::BootEcid *out);
|
||||
HardwareType GetHardwareType();
|
||||
HardwareState GetHardwareState();
|
||||
u64 GetDeviceId();
|
||||
PatchVersion GetPatchVersion();
|
||||
RetailInteractiveDisplayState GetRetailInteractiveDisplayState();
|
||||
pmic::Regulator GetRegulator();
|
||||
int GetDeviceUniqueKeyGeneration();
|
||||
|
||||
SocType GetSocType();
|
||||
int GetExpectedFuseVersion(TargetFirmware target_fw);
|
||||
int GetFuseVersion();
|
||||
bool HasRcmVulnerabilityPatch();
|
||||
SocType GetSocType();
|
||||
int GetExpectedFuseVersion(TargetFirmware target_fw);
|
||||
int GetFuseVersion();
|
||||
bool HasRcmVulnerabilityPatch();
|
||||
|
||||
bool IsOdmProductionMode();
|
||||
void ConfigureFuseBypass();
|
||||
|
||||
@@ -70,6 +70,10 @@ namespace ams::secmon {
|
||||
GetConfigurationContext().secmon_cfg.key_generation = generation;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void SetTargetFirmware(ams::TargetFirmware target_firmware) {
|
||||
GetConfigurationContext().secmon_cfg.target_firmware = target_firmware;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE pkg1::BootConfig *GetBootConfigStorage() {
|
||||
return std::addressof(GetConfigurationContext().boot_config);
|
||||
}
|
||||
|
||||
@@ -22,52 +22,53 @@ namespace ams::secmon {
|
||||
using Address = u64;
|
||||
|
||||
struct MemoryRegion {
|
||||
Address start_address;
|
||||
Address end_address;
|
||||
|
||||
constexpr MemoryRegion(Address address, size_t size) : start_address(address), end_address(address + size) {
|
||||
if (end_address < start_address) {
|
||||
__builtin_unreachable();
|
||||
private:
|
||||
Address m_start_address;
|
||||
Address m_end_address;
|
||||
public:
|
||||
consteval MemoryRegion(Address address, size_t size) : m_start_address(address), m_end_address(address + size) {
|
||||
if (m_end_address < m_start_address) {
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Address GetStartAddress() const {
|
||||
return this->start_address;
|
||||
}
|
||||
constexpr Address GetStartAddress() const {
|
||||
return m_start_address;
|
||||
}
|
||||
|
||||
constexpr Address GetAddress() const {
|
||||
return this->GetStartAddress();
|
||||
}
|
||||
constexpr Address GetAddress() const {
|
||||
return this->GetStartAddress();
|
||||
}
|
||||
|
||||
constexpr Address GetEndAddress() const {
|
||||
return this->end_address;
|
||||
}
|
||||
constexpr Address GetEndAddress() const {
|
||||
return m_end_address;
|
||||
}
|
||||
|
||||
constexpr Address GetLastAddress() const {
|
||||
return this->end_address - 1;
|
||||
}
|
||||
constexpr Address GetLastAddress() const {
|
||||
return m_end_address - 1;
|
||||
}
|
||||
|
||||
constexpr size_t GetSize() const {
|
||||
return this->end_address - this->start_address;
|
||||
}
|
||||
constexpr size_t GetSize() const {
|
||||
return m_end_address - m_start_address;
|
||||
}
|
||||
|
||||
constexpr bool Contains(Address address, size_t size) const {
|
||||
return this->start_address <= address && (address + size - 1) <= this->GetLastAddress();
|
||||
}
|
||||
constexpr bool Contains(Address address, size_t size) const {
|
||||
return m_start_address <= address && (address + size - 1) <= this->GetLastAddress();
|
||||
}
|
||||
|
||||
constexpr bool Contains(const MemoryRegion &rhs) const {
|
||||
return this->Contains(rhs.GetStartAddress(), rhs.GetSize());
|
||||
}
|
||||
constexpr bool Contains(const MemoryRegion &rhs) const {
|
||||
return this->Contains(rhs.GetStartAddress(), rhs.GetSize());
|
||||
}
|
||||
|
||||
template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value)
|
||||
ALWAYS_INLINE T *GetPointer() const {
|
||||
return reinterpret_cast<T *>(this->GetAddress());
|
||||
}
|
||||
template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value)
|
||||
ALWAYS_INLINE T *GetPointer() const {
|
||||
return reinterpret_cast<T *>(this->GetAddress());
|
||||
}
|
||||
|
||||
template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value)
|
||||
ALWAYS_INLINE T *GetEndPointer() const {
|
||||
return reinterpret_cast<T *>(this->GetEndAddress());
|
||||
}
|
||||
template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value)
|
||||
ALWAYS_INLINE T *GetEndPointer() const {
|
||||
return reinterpret_cast<T *>(this->GetEndAddress());
|
||||
}
|
||||
};
|
||||
|
||||
constexpr inline const MemoryRegion MemoryRegionVirtual = MemoryRegion(UINT64_C(0x1F0000000), 2_MB);
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ams::crypto::impl {
|
||||
AMS_UNUSED(key_size, is_encrypt);
|
||||
|
||||
/* Set the security engine keyslot. */
|
||||
this->slot = *static_cast<const int *>(key);
|
||||
m_slot = *static_cast<const int *>(key);
|
||||
}
|
||||
|
||||
template<size_t KeySize>
|
||||
@@ -48,14 +48,14 @@ namespace ams::crypto::impl {
|
||||
|
||||
if constexpr (KeySize == 16) {
|
||||
/* Aes 128. */
|
||||
se::EncryptAes128(dst, dst_size, this->slot, src, src_size);
|
||||
se::EncryptAes128(dst, dst_size, m_slot, src, src_size);
|
||||
} else if constexpr (KeySize == 24) {
|
||||
/* Aes 192. */
|
||||
/* TODO: se::EncryptAes192(dst, dst_size, this->slot, src, src_size); */
|
||||
/* TODO: se::EncryptAes192(dst, dst_size, m_slot, src, src_size); */
|
||||
AMS_UNUSED(dst, dst_size, src, src_size);
|
||||
} else if constexpr (KeySize == 32) {
|
||||
/* Aes 256. */
|
||||
/* TODO: se::EncryptAes256(dst, dst_size, this->slot, src, src_size); */
|
||||
/* TODO: se::EncryptAes256(dst, dst_size, m_slot, src, src_size); */
|
||||
AMS_UNUSED(dst, dst_size, src, src_size);
|
||||
} else {
|
||||
/* Invalid key size. */
|
||||
@@ -71,14 +71,14 @@ namespace ams::crypto::impl {
|
||||
|
||||
if constexpr (KeySize == 16) {
|
||||
/* Aes 128. */
|
||||
se::DecryptAes128(dst, dst_size, this->slot, src, src_size);
|
||||
se::DecryptAes128(dst, dst_size, m_slot, src, src_size);
|
||||
} else if constexpr (KeySize == 24) {
|
||||
/* Aes 192. */
|
||||
/* TODO: se::DecryptAes192(dst, dst_size, this->slot, src, src_size); */
|
||||
/* TODO: se::DecryptAes192(dst, dst_size, m_slot, src, src_size); */
|
||||
AMS_UNUSED(dst, dst_size, src, src_size);
|
||||
} else if constexpr (KeySize == 32) {
|
||||
/* Aes 256. */
|
||||
/* TODO: se::DecryptAes256(dst, dst_size, this->slot, src, src_size); */
|
||||
/* TODO: se::DecryptAes256(dst, dst_size, m_slot, src, src_size); */
|
||||
AMS_UNUSED(dst, dst_size, src, src_size);
|
||||
} else {
|
||||
/* Invalid key size. */
|
||||
|
||||
@@ -37,15 +37,15 @@ namespace ams::fuse {
|
||||
};
|
||||
|
||||
struct OdmWord4 {
|
||||
using HardwareState1 = util::BitPack32::Field<0, 2, int>;
|
||||
using HardwareType1 = util::BitPack32::Field<HardwareState1::Next, 1, int>;
|
||||
using DramId = util::BitPack32::Field<HardwareType1::Next, 5, int>;
|
||||
using HardwareType2 = util::BitPack32::Field<DramId::Next, 1, int>;
|
||||
using HardwareState2 = util::BitPack32::Field<HardwareType2::Next, 1, int>;
|
||||
using QuestState = util::BitPack32::Field<HardwareState2::Next, 1, int>;
|
||||
using FormatVersion = util::BitPack32::Field<QuestState::Next, 1, int>;
|
||||
using Reserved = util::BitPack32::Field<FormatVersion::Next, 4, int>;
|
||||
using HardwareType3 = util::BitPack32::Field<Reserved::Next, 4, int>;
|
||||
using HardwareState1 = util::BitPack32::Field<0, 2, int>;
|
||||
using HardwareType1 = util::BitPack32::Field<HardwareState1::Next, 1, int>;
|
||||
using DramId = util::BitPack32::Field<HardwareType1::Next, 5, int>;
|
||||
using HardwareType2 = util::BitPack32::Field<DramId::Next, 1, int>;
|
||||
using HardwareState2 = util::BitPack32::Field<HardwareType2::Next, 1, int>;
|
||||
using RetailInteractiveDisplayState = util::BitPack32::Field<HardwareState2::Next, 1, int>;
|
||||
using FormatVersion = util::BitPack32::Field<RetailInteractiveDisplayState::Next, 1, int>;
|
||||
using Reserved = util::BitPack32::Field<FormatVersion::Next, 4, int>;
|
||||
using HardwareType3 = util::BitPack32::Field<Reserved::Next, 4, int>;
|
||||
};
|
||||
|
||||
struct OdmWord28 {
|
||||
@@ -343,8 +343,8 @@ namespace ams::fuse {
|
||||
return static_cast<PatchVersion>(static_cast<int>(GetSocType() << 12) | patch_version);
|
||||
}
|
||||
|
||||
QuestState GetQuestState() {
|
||||
return static_cast<QuestState>(util::BitPack32{GetCommonOdmWord(4)}.Get<OdmWord4::QuestState>());
|
||||
RetailInteractiveDisplayState GetRetailInteractiveDisplayState() {
|
||||
return static_cast<RetailInteractiveDisplayState>(util::BitPack32{GetCommonOdmWord(4)}.Get<OdmWord4::RetailInteractiveDisplayState>());
|
||||
}
|
||||
|
||||
pmic::Regulator GetRegulator() {
|
||||
|
||||
@@ -54,63 +54,63 @@ namespace ams::kern::init::Elf::Elf64 {
|
||||
|
||||
class Dyn {
|
||||
private:
|
||||
SXword tag;
|
||||
SXword m_tag;
|
||||
union {
|
||||
Xword value;
|
||||
Addr ptr;
|
||||
Xword m_value;
|
||||
Addr m_ptr;
|
||||
};
|
||||
public:
|
||||
constexpr ALWAYS_INLINE SXword GetTag() const {
|
||||
return this->tag;
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE Xword GetValue() const {
|
||||
return this->value;
|
||||
return m_value;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE Addr GetPtr() const {
|
||||
return this->ptr;
|
||||
return m_ptr;
|
||||
}
|
||||
};
|
||||
|
||||
class Rel {
|
||||
private:
|
||||
Addr offset;
|
||||
Xword info;
|
||||
Addr m_offset;
|
||||
Xword m_info;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE Addr GetOffset() const {
|
||||
return this->offset;
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE Xword GetSym() const {
|
||||
return this->info >> 32;
|
||||
return m_info >> 32;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE Xword GetType() const {
|
||||
return this->info & 0xFFFFFFFF;
|
||||
return m_info & 0xFFFFFFFF;
|
||||
}
|
||||
};
|
||||
|
||||
class Rela {
|
||||
private:
|
||||
Addr offset;
|
||||
Xword info;
|
||||
SXword addend;
|
||||
Addr m_offset;
|
||||
Xword m_info;
|
||||
SXword m_addend;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE Addr GetOffset() const {
|
||||
return this->offset;
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE Xword GetSym() const {
|
||||
return this->info >> 32;
|
||||
return m_info >> 32;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE Xword GetType() const {
|
||||
return this->info & 0xFFFFFFFF;
|
||||
return m_info & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE SXword GetAddend() const {
|
||||
return this->addend;
|
||||
return m_addend;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -140,21 +140,21 @@ namespace ams::kern::svc {
|
||||
using CT = const char;
|
||||
using T = char;
|
||||
private:
|
||||
const char *ptr;
|
||||
const char *m_ptr;
|
||||
protected:
|
||||
ALWAYS_INLINE Result CopyStringTo(char *dst, size_t size) const {
|
||||
static_assert(sizeof(char) == 1);
|
||||
R_UNLESS(UserspaceAccess::CopyStringFromUser(dst, this->ptr, size) > 0, svc::ResultInvalidPointer());
|
||||
R_UNLESS(UserspaceAccess::CopyStringFromUser(dst, m_ptr, size) > 0, svc::ResultInvalidPointer());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Result CopyArrayElementTo(char *dst, size_t index) const {
|
||||
return Traits::CopyFromUserspace(dst, this->ptr + index, sizeof(*dst));
|
||||
return Traits::CopyFromUserspace(dst, m_ptr + index, sizeof(*dst));
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsNull() const { return this->ptr == nullptr; }
|
||||
constexpr ALWAYS_INLINE bool IsNull() const { return m_ptr == nullptr; }
|
||||
|
||||
constexpr ALWAYS_INLINE const char *GetUnsafePointer() const { return this->ptr; }
|
||||
constexpr ALWAYS_INLINE const char *GetUnsafePointer() const { return m_ptr; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success));
|
||||
|
||||
/* Copy output. */
|
||||
std::memcpy(dst, &args.x[1], size);
|
||||
std::memcpy(dst, std::addressof(args.x[1]), size);
|
||||
}
|
||||
|
||||
bool ReadWriteRegister(u32 *out, u64 address, u32 mask, u32 value) {
|
||||
@@ -255,7 +255,7 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||
MESOSPHERE_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success));
|
||||
|
||||
/* Copy output. */
|
||||
std::memcpy(dst, &args.x[1], size);
|
||||
std::memcpy(dst, std::addressof(args.x[1]), size);
|
||||
}
|
||||
|
||||
void NORETURN Panic(u32 color) {
|
||||
|
||||
@@ -25,18 +25,18 @@ namespace ams::kern {
|
||||
public:
|
||||
static constexpr size_t MaxMemoryRegions = 200;
|
||||
private:
|
||||
KMemoryRegion region_heap[MaxMemoryRegions];
|
||||
size_t num_regions;
|
||||
KMemoryRegion m_region_heap[MaxMemoryRegions];
|
||||
size_t m_num_regions;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE KMemoryRegionAllocator() : region_heap(), num_regions() { /* ... */ }
|
||||
constexpr ALWAYS_INLINE KMemoryRegionAllocator() : m_region_heap(), m_num_regions() { /* ... */ }
|
||||
public:
|
||||
template<typename... Args>
|
||||
ALWAYS_INLINE KMemoryRegion *Allocate(Args&&... args) {
|
||||
/* Ensure we stay within the bounds of our heap. */
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(this->num_regions < MaxMemoryRegions);
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(m_num_regions < MaxMemoryRegions);
|
||||
|
||||
/* Create the new region. */
|
||||
KMemoryRegion *region = std::addressof(this->region_heap[this->num_regions++]);
|
||||
KMemoryRegion *region = std::addressof(m_region_heap[m_num_regions++]);
|
||||
std::construct_at(region, std::forward<Args>(args)...);
|
||||
|
||||
return region;
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace ams::kern {
|
||||
|
||||
if (m_current_hints[which] + value <= m_limit_values[which] && (timeout < 0 || KHardwareTimer::GetTick() < timeout)) {
|
||||
m_waiter_count++;
|
||||
m_cond_var.Wait(&m_lock, timeout, false);
|
||||
m_cond_var.Wait(std::addressof(m_lock), timeout, false);
|
||||
m_waiter_count--;
|
||||
|
||||
if (GetCurrentThread().IsTerminationRequested()) {
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace ams::kern {
|
||||
const uintptr_t stack_bottom = stack_top - PageSize;
|
||||
|
||||
KPhysicalAddress stack_paddr = Null<KPhysicalAddress>;
|
||||
MESOSPHERE_ABORT_UNLESS(Kernel::GetKernelPageTable().GetPhysicalAddress(&stack_paddr, stack_bottom));
|
||||
MESOSPHERE_ABORT_UNLESS(Kernel::GetKernelPageTable().GetPhysicalAddress(std::addressof(stack_paddr), stack_bottom));
|
||||
|
||||
MESOSPHERE_R_ABORT_UNLESS(Kernel::GetKernelPageTable().UnmapPages(stack_bottom, 1, KMemoryState_Kernel));
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace ams::kern {
|
||||
|
||||
/* Get the physical address of the page. */
|
||||
KPhysicalAddress phys_addr = Null<KPhysicalAddress>;
|
||||
MESOSPHERE_ABORT_UNLESS(m_owner->GetPageTable().GetPhysicalAddress(&phys_addr, this->GetAddress()));
|
||||
MESOSPHERE_ABORT_UNLESS(m_owner->GetPageTable().GetPhysicalAddress(std::addressof(phys_addr), this->GetAddress()));
|
||||
|
||||
/* Unmap the page. */
|
||||
R_TRY(m_owner->GetPageTable().UnmapPages(this->GetAddress(), 1, KMemoryState_ThreadLocal));
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace ams::impl {
|
||||
|
||||
/* sm. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(-1, sm, Main);
|
||||
AMS_DEFINE_SYSTEM_THREAD(-1, sm, DispatcherThread);
|
||||
|
||||
/* spl. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(-1, spl, Main);
|
||||
@@ -114,6 +115,7 @@ namespace ams::impl {
|
||||
/* settings. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, settings, Main);
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, settings, IpcServer);
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, settings, LazyWriter);
|
||||
|
||||
/* erpt. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(21, erpt, Main);
|
||||
@@ -176,5 +178,5 @@ namespace ams::impl {
|
||||
|
||||
}
|
||||
|
||||
#define AMS_GET_SYSTEM_THREAD_PRIORITY(__AMS_MODULE__, __AMS_THREAD_NAME__) ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__.priority
|
||||
#define AMS_GET_SYSTEM_THREAD_NAME(__AMS_MODULE__, __AMS_THREAD_NAME__) ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__.name
|
||||
#define AMS_GET_SYSTEM_THREAD_PRIORITY(__AMS_MODULE__, __AMS_THREAD_NAME__) ( ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__ ).priority
|
||||
#define AMS_GET_SYSTEM_THREAD_NAME(__AMS_MODULE__, __AMS_THREAD_NAME__) ( ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__ ).name
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
|
||||
namespace ams::cfg {
|
||||
|
||||
/* Privileged Process configuration. */
|
||||
bool IsInitialProcess();
|
||||
void GetInitialProcessRange(os::ProcessId *out_min, os::ProcessId *out_max);
|
||||
|
||||
/* SD card configuration. */
|
||||
bool IsSdCardRequiredServicesReady();
|
||||
void WaitSdCardRequiredServicesReady();
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace ams::cfg {
|
||||
static_assert(util::is_pod<OverrideStatus>::value, "util::is_pod<OverrideStatus>::value");
|
||||
|
||||
constexpr inline bool operator==(const OverrideStatus &lhs, const OverrideStatus &rhs) {
|
||||
return std::memcmp(&lhs, &rhs, sizeof(lhs)) == 0;
|
||||
return std::memcmp(std::addressof(lhs), std::addressof(rhs), sizeof(lhs)) == 0;
|
||||
}
|
||||
|
||||
constexpr inline bool operator!=(const OverrideStatus &lhs, const OverrideStatus &rhs) {
|
||||
|
||||
@@ -24,23 +24,23 @@ namespace ams::ddsf {
|
||||
NON_COPYABLE(DeviceCodeEntry);
|
||||
NON_MOVEABLE(DeviceCodeEntry);
|
||||
private:
|
||||
ams::DeviceCode device_code = ams::InvalidDeviceCode;
|
||||
IDevice *device = nullptr;
|
||||
ams::DeviceCode m_device_code = ams::InvalidDeviceCode;
|
||||
IDevice *m_device = nullptr;
|
||||
public:
|
||||
constexpr DeviceCodeEntry(ams::DeviceCode dc, IDevice *dev) : device_code(dc), device(dev) {
|
||||
constexpr DeviceCodeEntry(ams::DeviceCode dc, IDevice *dev) : m_device_code(dc), m_device(dev) {
|
||||
AMS_ASSERT(dev != nullptr);
|
||||
}
|
||||
|
||||
constexpr ams::DeviceCode GetDeviceCode() const {
|
||||
return this->device_code;
|
||||
return m_device_code;
|
||||
}
|
||||
|
||||
constexpr IDevice &GetDevice() {
|
||||
return *this->device;
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
constexpr const IDevice &GetDevice() const {
|
||||
return *this->device;
|
||||
return *m_device;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -48,15 +48,15 @@ namespace ams::ddsf {
|
||||
NON_COPYABLE(DeviceCodeEntryHolder);
|
||||
NON_MOVEABLE(DeviceCodeEntryHolder);
|
||||
private:
|
||||
util::IntrusiveListNode list_node;
|
||||
util::TypedStorage<DeviceCodeEntry> entry_storage;
|
||||
bool is_constructed;
|
||||
util::IntrusiveListNode m_list_node;
|
||||
util::TypedStorage<DeviceCodeEntry> m_entry_storage;
|
||||
bool m_is_constructed;
|
||||
public:
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::list_node>;
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::m_list_node>;
|
||||
using List = typename ListTraits::ListType;
|
||||
friend class util::IntrusiveList<DeviceCodeEntryHolder, util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::list_node>>;
|
||||
friend class util::IntrusiveList<DeviceCodeEntryHolder, util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::m_list_node>>;
|
||||
public:
|
||||
DeviceCodeEntryHolder() : list_node(), entry_storage(), is_constructed(false) {
|
||||
DeviceCodeEntryHolder() : m_list_node(), m_entry_storage(), m_is_constructed(false) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -75,34 +75,34 @@ namespace ams::ddsf {
|
||||
}
|
||||
|
||||
bool IsLinkedToList() const {
|
||||
return this->list_node.IsLinked();
|
||||
return m_list_node.IsLinked();
|
||||
}
|
||||
|
||||
DeviceCodeEntry &Construct(DeviceCode dc, IDevice *dev) {
|
||||
AMS_ASSERT(!this->IsConstructed());
|
||||
DeviceCodeEntry *entry = util::ConstructAt(this->entry_storage, dc, dev);
|
||||
this->is_constructed = true;
|
||||
DeviceCodeEntry *entry = util::ConstructAt(m_entry_storage, dc, dev);
|
||||
m_is_constructed = true;
|
||||
return *entry;
|
||||
}
|
||||
|
||||
bool IsConstructed() const {
|
||||
return this->is_constructed;
|
||||
return m_is_constructed;
|
||||
}
|
||||
|
||||
void Destroy() {
|
||||
AMS_ASSERT(this->IsConstructed());
|
||||
util::DestroyAt(this->entry_storage);
|
||||
this->is_constructed = false;
|
||||
util::DestroyAt(m_entry_storage);
|
||||
m_is_constructed = false;
|
||||
}
|
||||
|
||||
DeviceCodeEntry &Get() {
|
||||
AMS_ASSERT(this->IsConstructed());
|
||||
return GetReference(this->entry_storage);
|
||||
return GetReference(m_entry_storage);
|
||||
}
|
||||
|
||||
const DeviceCodeEntry &Get() const {
|
||||
AMS_ASSERT(this->IsConstructed());
|
||||
return GetReference(this->entry_storage);
|
||||
return GetReference(m_entry_storage);
|
||||
}
|
||||
};
|
||||
static_assert(DeviceCodeEntryHolder::ListTraits::IsValid());
|
||||
|
||||
@@ -25,33 +25,33 @@ namespace ams::ddsf {
|
||||
|
||||
class DeviceCodeEntryManager {
|
||||
private:
|
||||
ams::MemoryResource *memory_resource;
|
||||
ddsf::DeviceCodeEntryHolder::List entry_list;
|
||||
mutable os::SdkMutex entry_list_lock;
|
||||
ams::MemoryResource *m_memory_resource;
|
||||
ddsf::DeviceCodeEntryHolder::List m_entry_list;
|
||||
mutable os::SdkMutex m_entry_list_lock;
|
||||
private:
|
||||
void DestroyAllEntries() {
|
||||
auto it = this->entry_list.begin();
|
||||
while (it != this->entry_list.end()) {
|
||||
auto it = m_entry_list.begin();
|
||||
while (it != m_entry_list.end()) {
|
||||
ddsf::DeviceCodeEntryHolder *entry = std::addressof(*it);
|
||||
it = this->entry_list.erase(it);
|
||||
it = m_entry_list.erase(it);
|
||||
|
||||
AMS_ASSERT(entry->IsConstructed());
|
||||
if (entry->IsConstructed()) {
|
||||
entry->Destroy();
|
||||
}
|
||||
|
||||
this->memory_resource->Deallocate(entry, sizeof(*entry));
|
||||
m_memory_resource->Deallocate(entry, sizeof(*entry));
|
||||
}
|
||||
}
|
||||
public:
|
||||
DeviceCodeEntryManager(ams::MemoryResource *mr) : memory_resource(mr), entry_list(), entry_list_lock() { /* ... */ }
|
||||
DeviceCodeEntryManager(ams::MemoryResource *mr) : m_memory_resource(mr), m_entry_list(), m_entry_list_lock() { /* ... */ }
|
||||
|
||||
~DeviceCodeEntryManager() {
|
||||
this->DestroyAllEntries();
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
std::scoped_lock lk(this->entry_list_lock);
|
||||
std::scoped_lock lk(m_entry_list_lock);
|
||||
this->DestroyAllEntries();
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace ams::ddsf {
|
||||
|
||||
template<typename F>
|
||||
int ForEachEntry(F f) {
|
||||
return impl::ForEach(this->entry_list_lock, this->entry_list, [&](DeviceCodeEntryHolder &holder) -> bool {
|
||||
return impl::ForEach(m_entry_list_lock, m_entry_list, [&](DeviceCodeEntryHolder &holder) -> bool {
|
||||
AMS_ASSERT(holder.IsConstructed());
|
||||
return f(holder.Get());
|
||||
});
|
||||
@@ -74,7 +74,7 @@ namespace ams::ddsf {
|
||||
|
||||
template<typename F>
|
||||
int ForEachEntry(F f) const {
|
||||
return impl::ForEach(this->entry_list_lock, this->entry_list, [&](const DeviceCodeEntryHolder &holder) -> bool {
|
||||
return impl::ForEach(m_entry_list_lock, m_entry_list, [&](const DeviceCodeEntryHolder &holder) -> bool {
|
||||
AMS_ASSERT(holder.IsConstructed());
|
||||
return f(holder.Get());
|
||||
});
|
||||
|
||||
@@ -28,41 +28,41 @@ namespace ams::ddsf {
|
||||
private:
|
||||
struct LoopControlCommandParameters;
|
||||
private:
|
||||
bool is_initialized;
|
||||
bool is_looping;
|
||||
os::SdkConditionVariable is_looping_cv;
|
||||
os::MultiWaitType multi_wait;
|
||||
os::ThreadType *loop_thread;
|
||||
os::Event loop_control_event;
|
||||
os::MultiWaitHolderType loop_control_event_holder;
|
||||
LoopControlCommandParameters *loop_control_command_params;
|
||||
os::LightEvent loop_control_command_done_event;
|
||||
os::SdkMutex loop_control_lock;
|
||||
bool m_is_initialized;
|
||||
bool m_is_looping;
|
||||
os::SdkConditionVariable m_is_looping_cv;
|
||||
os::MultiWaitType m_multi_wait;
|
||||
os::ThreadType *m_loop_thread;
|
||||
os::Event m_loop_control_event;
|
||||
os::MultiWaitHolderType m_loop_control_event_holder;
|
||||
LoopControlCommandParameters *m_loop_control_command_params;
|
||||
os::LightEvent m_loop_control_command_done_event;
|
||||
os::SdkMutex m_loop_control_lock;
|
||||
private:
|
||||
void ProcessControlCommand(LoopControlCommandParameters *params);
|
||||
void ProcessControlCommandImpl(LoopControlCommandParameters *params);
|
||||
public:
|
||||
EventHandlerManager()
|
||||
: is_initialized(false), is_looping(false), is_looping_cv(), multi_wait(),
|
||||
loop_thread(), loop_control_event(os::EventClearMode_AutoClear), loop_control_event_holder(),
|
||||
loop_control_command_params(), loop_control_command_done_event(os::EventClearMode_AutoClear),
|
||||
loop_control_lock()
|
||||
: m_is_initialized(false), m_is_looping(false), m_is_looping_cv(), m_multi_wait(),
|
||||
m_loop_thread(), m_loop_control_event(os::EventClearMode_AutoClear), m_loop_control_event_holder(),
|
||||
m_loop_control_command_params(), m_loop_control_command_done_event(os::EventClearMode_AutoClear),
|
||||
m_loop_control_lock()
|
||||
{
|
||||
this->Initialize();
|
||||
}
|
||||
|
||||
~EventHandlerManager() {
|
||||
if (this->is_looping) {
|
||||
if (m_is_looping) {
|
||||
AMS_ASSERT(!this->IsRunningOnLoopThread());
|
||||
this->RequestStop();
|
||||
}
|
||||
if (this->is_initialized) {
|
||||
if (m_is_initialized) {
|
||||
this->Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsRunningOnLoopThread() const { return this->loop_thread == os::GetCurrentThread(); }
|
||||
bool IsLooping() const { return this->is_looping; }
|
||||
bool IsRunningOnLoopThread() const { return m_loop_thread == os::GetCurrentThread(); }
|
||||
bool IsLooping() const { return m_is_looping; }
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
@@ -32,57 +32,57 @@ namespace ams::ddsf {
|
||||
public:
|
||||
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice);
|
||||
private:
|
||||
util::IntrusiveListNode list_node;
|
||||
IDriver *driver;
|
||||
ISession::List session_list;
|
||||
mutable os::SdkMutex session_list_lock;
|
||||
bool is_exclusive_write;
|
||||
util::IntrusiveListNode m_list_node;
|
||||
IDriver *m_driver;
|
||||
ISession::List m_session_list;
|
||||
mutable os::SdkMutex m_session_list_lock;
|
||||
bool m_is_exclusive_write;
|
||||
public:
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDevice::list_node>;
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDevice::m_list_node>;
|
||||
using List = typename ListTraits::ListType;
|
||||
friend class util::IntrusiveList<IDevice, util::IntrusiveListMemberTraitsDeferredAssert<&IDevice::list_node>>;
|
||||
friend class util::IntrusiveList<IDevice, util::IntrusiveListMemberTraitsDeferredAssert<&IDevice::m_list_node>>;
|
||||
private:
|
||||
Result AttachSession(ISession *session) {
|
||||
AMS_ASSERT(session != nullptr);
|
||||
std::scoped_lock lk(this->session_list_lock);
|
||||
std::scoped_lock lk(m_session_list_lock);
|
||||
|
||||
/* Check if we're allowed to attach the session. */
|
||||
if (this->is_exclusive_write && session->CheckExclusiveWrite()) {
|
||||
for (const auto &attached : this->session_list) {
|
||||
if (m_is_exclusive_write && session->CheckExclusiveWrite()) {
|
||||
for (const auto &attached : m_session_list) {
|
||||
R_UNLESS(!attached.CheckAccess(AccessMode_Write), ddsf::ResultAccessModeDenied());
|
||||
}
|
||||
}
|
||||
|
||||
/* Attach the session. */
|
||||
this->session_list.push_back(*session);
|
||||
m_session_list.push_back(*session);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void DetachSession(ISession *session) {
|
||||
AMS_ASSERT(session != nullptr);
|
||||
std::scoped_lock lk(this->session_list_lock);
|
||||
this->session_list.erase(this->session_list.iterator_to(*session));
|
||||
std::scoped_lock lk(m_session_list_lock);
|
||||
m_session_list.erase(m_session_list.iterator_to(*session));
|
||||
}
|
||||
|
||||
void AttachDriver(IDriver *drv) {
|
||||
AMS_ASSERT(drv != nullptr);
|
||||
AMS_ASSERT(!this->IsDriverAttached());
|
||||
this->driver = drv;
|
||||
m_driver = drv;
|
||||
AMS_ASSERT(this->IsDriverAttached());
|
||||
}
|
||||
|
||||
void DetachDriver() {
|
||||
AMS_ASSERT(this->IsDriverAttached());
|
||||
this->driver = nullptr;
|
||||
m_driver = nullptr;
|
||||
AMS_ASSERT(!this->IsDriverAttached());
|
||||
}
|
||||
public:
|
||||
IDevice(bool exclusive_write) : list_node(), driver(nullptr), session_list(), session_list_lock(), is_exclusive_write(exclusive_write) {
|
||||
this->session_list.clear();
|
||||
IDevice(bool exclusive_write) : m_list_node(), m_driver(nullptr), m_session_list(), m_session_list_lock(), m_is_exclusive_write(exclusive_write) {
|
||||
m_session_list.clear();
|
||||
}
|
||||
protected:
|
||||
~IDevice() {
|
||||
this->session_list.clear();
|
||||
m_session_list.clear();
|
||||
}
|
||||
public:
|
||||
void AddTo(List &list) {
|
||||
@@ -94,45 +94,45 @@ namespace ams::ddsf {
|
||||
}
|
||||
|
||||
bool IsLinkedToList() const {
|
||||
return this->list_node.IsLinked();
|
||||
return m_list_node.IsLinked();
|
||||
}
|
||||
|
||||
IDriver &GetDriver() {
|
||||
AMS_ASSERT(this->IsDriverAttached());
|
||||
return *this->driver;
|
||||
return *m_driver;
|
||||
}
|
||||
|
||||
const IDriver &GetDriver() const {
|
||||
AMS_ASSERT(this->IsDriverAttached());
|
||||
return *this->driver;
|
||||
return *m_driver;
|
||||
}
|
||||
|
||||
bool IsDriverAttached() const {
|
||||
return this->driver != nullptr;
|
||||
return m_driver != nullptr;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
Result ForEachSession(F f, bool return_on_fail) {
|
||||
return impl::ForEach(this->session_list_lock, this->session_list, f, return_on_fail);
|
||||
return impl::ForEach(m_session_list_lock, m_session_list, f, return_on_fail);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
Result ForEachSession(F f, bool return_on_fail) const {
|
||||
return impl::ForEach(this->session_list_lock, this->session_list, f, return_on_fail);
|
||||
return impl::ForEach(m_session_list_lock, m_session_list, f, return_on_fail);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
int ForEachSession(F f) {
|
||||
return impl::ForEach(this->session_list_lock, this->session_list, f);
|
||||
return impl::ForEach(m_session_list_lock, m_session_list, f);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
int ForEachSession(F f) const {
|
||||
return impl::ForEach(this->session_list_lock, this->session_list, f);
|
||||
return impl::ForEach(m_session_list_lock, m_session_list, f);
|
||||
}
|
||||
|
||||
bool HasAnyOpenSession() const {
|
||||
return !this->session_list.empty();
|
||||
return !m_session_list.empty();
|
||||
}
|
||||
};
|
||||
static_assert(IDevice::ListTraits::IsValid());
|
||||
|
||||
@@ -27,21 +27,21 @@ namespace ams::ddsf {
|
||||
public:
|
||||
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDriver);
|
||||
private:
|
||||
util::IntrusiveListNode list_node;
|
||||
IDevice::List device_list;
|
||||
mutable os::SdkMutex device_list_lock;
|
||||
util::IntrusiveListNode m_list_node;
|
||||
IDevice::List m_device_list;
|
||||
mutable os::SdkMutex m_device_list_lock;
|
||||
public:
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDriver::list_node>;
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDriver::m_list_node>;
|
||||
using List = typename ListTraits::ListType;
|
||||
friend class util::IntrusiveList<IDriver, util::IntrusiveListMemberTraitsDeferredAssert<&IDriver::list_node>>;
|
||||
friend class util::IntrusiveList<IDriver, util::IntrusiveListMemberTraitsDeferredAssert<&IDriver::m_list_node>>;
|
||||
private:
|
||||
public:
|
||||
IDriver() : list_node(), device_list(), device_list_lock() {
|
||||
this->device_list.clear();
|
||||
IDriver() : m_list_node(), m_device_list(), m_device_list_lock() {
|
||||
m_device_list.clear();
|
||||
}
|
||||
protected:
|
||||
~IDriver() {
|
||||
this->device_list.clear();
|
||||
m_device_list.clear();
|
||||
}
|
||||
public:
|
||||
void AddTo(List &list) {
|
||||
@@ -53,45 +53,45 @@ namespace ams::ddsf {
|
||||
}
|
||||
|
||||
bool IsLinkedToList() const {
|
||||
return this->list_node.IsLinked();
|
||||
return m_list_node.IsLinked();
|
||||
}
|
||||
|
||||
bool HasAnyDevice() const {
|
||||
return !this->device_list.empty();
|
||||
return !m_device_list.empty();
|
||||
}
|
||||
|
||||
void RegisterDevice(IDevice *dev) {
|
||||
AMS_ASSERT(dev != nullptr);
|
||||
std::scoped_lock lk(this->device_list_lock);
|
||||
std::scoped_lock lk(m_device_list_lock);
|
||||
dev->AttachDriver(this);
|
||||
this->device_list.push_back(*dev);
|
||||
m_device_list.push_back(*dev);
|
||||
}
|
||||
|
||||
void UnregisterDevice(IDevice *dev) {
|
||||
AMS_ASSERT(dev != nullptr);
|
||||
std::scoped_lock lk(this->device_list_lock);
|
||||
this->device_list.erase(this->device_list.iterator_to(*dev));
|
||||
std::scoped_lock lk(m_device_list_lock);
|
||||
m_device_list.erase(m_device_list.iterator_to(*dev));
|
||||
dev->DetachDriver();
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
Result ForEachDevice(F f, bool return_on_fail) {
|
||||
return impl::ForEach(this->device_list_lock, this->device_list, f, return_on_fail);
|
||||
return impl::ForEach(m_device_list_lock, m_device_list, f, return_on_fail);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
Result ForEachDevice(F f, bool return_on_fail) const {
|
||||
return impl::ForEach(this->device_list_lock, this->device_list, f, return_on_fail);
|
||||
return impl::ForEach(m_device_list_lock, m_device_list, f, return_on_fail);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
int ForEachDevice(F f) {
|
||||
return impl::ForEach(this->device_list_lock, this->device_list, f);
|
||||
return impl::ForEach(m_device_list_lock, m_device_list, f);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
int ForEachDevice(F f) const {
|
||||
return impl::ForEach(this->device_list_lock, this->device_list, f);
|
||||
return impl::ForEach(m_device_list_lock, m_device_list, f);
|
||||
}
|
||||
};
|
||||
static_assert(IDriver::ListTraits::IsValid());
|
||||
|
||||
@@ -26,22 +26,22 @@ namespace ams::ddsf {
|
||||
NON_MOVEABLE(IEventHandler);
|
||||
friend class EventHandlerManager;
|
||||
private:
|
||||
os::MultiWaitHolderType holder;
|
||||
uintptr_t user_data;
|
||||
bool is_initialized;
|
||||
bool is_registered;
|
||||
os::MultiWaitHolderType m_holder;
|
||||
uintptr_t m_user_data;
|
||||
bool m_is_initialized;
|
||||
bool m_is_registered;
|
||||
private:
|
||||
void Link(os::MultiWaitType *multi_wait) {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
AMS_ASSERT(!this->IsRegistered());
|
||||
AMS_ASSERT(multi_wait != nullptr);
|
||||
os::LinkMultiWaitHolder(multi_wait, std::addressof(this->holder));
|
||||
os::LinkMultiWaitHolder(multi_wait, std::addressof(m_holder));
|
||||
}
|
||||
|
||||
void Unlink() {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
AMS_ASSERT(this->IsRegistered());
|
||||
os::UnlinkMultiWaitHolder(std::addressof(this->holder));
|
||||
os::UnlinkMultiWaitHolder(std::addressof(m_holder));
|
||||
}
|
||||
|
||||
static IEventHandler &ToEventHandler(os::MultiWaitHolderType *holder) {
|
||||
@@ -51,7 +51,7 @@ namespace ams::ddsf {
|
||||
return event_handler;
|
||||
}
|
||||
public:
|
||||
IEventHandler() : holder(), user_data(0), is_initialized(false), is_registered(false) { /* ... */ }
|
||||
IEventHandler() : m_holder(), m_user_data(0), m_is_initialized(false), m_is_registered(false) { /* ... */ }
|
||||
|
||||
~IEventHandler() {
|
||||
if (this->IsRegistered()) {
|
||||
@@ -62,28 +62,28 @@ namespace ams::ddsf {
|
||||
}
|
||||
}
|
||||
|
||||
bool IsInitialized() const { return this->is_initialized; }
|
||||
bool IsRegistered() const { return this->is_registered; }
|
||||
bool IsInitialized() const { return m_is_initialized; }
|
||||
bool IsRegistered() const { return m_is_registered; }
|
||||
|
||||
uintptr_t GetUserData() const { return this->user_data; }
|
||||
void SetUserData(uintptr_t d) { this->user_data = d; }
|
||||
uintptr_t GetUserData() const { return m_user_data; }
|
||||
void SetUserData(uintptr_t d) { m_user_data = d; }
|
||||
|
||||
template<typename T>
|
||||
void Initialize(T *object) {
|
||||
AMS_ASSERT(object != nullptr);
|
||||
AMS_ASSERT(!this->IsInitialized());
|
||||
os::InitializeMultiWaitHolder(std::addressof(this->holder), object);
|
||||
os::SetMultiWaitHolderUserData(std::addressof(this->holder), reinterpret_cast<uintptr_t>(this));
|
||||
this->is_initialized = true;
|
||||
this->is_registered = false;
|
||||
os::InitializeMultiWaitHolder(std::addressof(m_holder), object);
|
||||
os::SetMultiWaitHolderUserData(std::addressof(m_holder), reinterpret_cast<uintptr_t>(this));
|
||||
m_is_initialized = true;
|
||||
m_is_registered = false;
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
AMS_ASSERT(!this->IsRegistered());
|
||||
os::FinalizeMultiWaitHolder(std::addressof(this->holder));
|
||||
this->is_initialized = false;
|
||||
this->is_registered = false;
|
||||
os::FinalizeMultiWaitHolder(std::addressof(m_holder));
|
||||
m_is_initialized = false;
|
||||
m_is_registered = false;
|
||||
}
|
||||
protected:
|
||||
virtual void HandleEvent() = 0;
|
||||
|
||||
@@ -33,30 +33,30 @@ namespace ams::ddsf {
|
||||
public:
|
||||
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice);
|
||||
private:
|
||||
util::IntrusiveListNode list_node;
|
||||
IDevice *device;
|
||||
AccessMode access_mode;
|
||||
util::IntrusiveListNode m_list_node;
|
||||
IDevice *m_device;
|
||||
AccessMode m_access_mode;
|
||||
public:
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&ISession::list_node>;
|
||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&ISession::m_list_node>;
|
||||
using List = typename ListTraits::ListType;
|
||||
friend class util::IntrusiveList<ISession, util::IntrusiveListMemberTraitsDeferredAssert<&ISession::list_node>>;
|
||||
friend class util::IntrusiveList<ISession, util::IntrusiveListMemberTraitsDeferredAssert<&ISession::m_list_node>>;
|
||||
private:
|
||||
void AttachDevice(IDevice *dev, AccessMode mode) {
|
||||
AMS_ASSERT(dev != nullptr);
|
||||
AMS_ASSERT(!this->IsOpen());
|
||||
this->device = dev;
|
||||
this->access_mode = mode;
|
||||
m_device = dev;
|
||||
m_access_mode = mode;
|
||||
AMS_ASSERT(this->IsOpen());
|
||||
}
|
||||
|
||||
void DetachDevice() {
|
||||
AMS_ASSERT(this->IsOpen());
|
||||
this->device = nullptr;
|
||||
this->access_mode = AccessMode_None;
|
||||
m_device = nullptr;
|
||||
m_access_mode = AccessMode_None;
|
||||
AMS_ASSERT(!this->IsOpen());
|
||||
}
|
||||
public:
|
||||
ISession() : list_node(), device(nullptr), access_mode() { /* ... */ }
|
||||
ISession() : m_list_node(), m_device(nullptr), m_access_mode() { /* ... */ }
|
||||
protected:
|
||||
~ISession() { this->DetachDevice(); AMS_ASSERT(!this->IsOpen()); }
|
||||
public:
|
||||
@@ -69,26 +69,26 @@ namespace ams::ddsf {
|
||||
}
|
||||
|
||||
bool IsLinkedToList() const {
|
||||
return this->list_node.IsLinked();
|
||||
return m_list_node.IsLinked();
|
||||
}
|
||||
|
||||
IDevice &GetDevice() {
|
||||
AMS_ASSERT(this->IsOpen());
|
||||
return *this->device;
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
const IDevice &GetDevice() const {
|
||||
AMS_ASSERT(this->IsOpen());
|
||||
return *this->device;
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
bool IsOpen() const {
|
||||
return this->device != nullptr;
|
||||
return m_device != nullptr;
|
||||
}
|
||||
|
||||
bool CheckAccess(AccessMode mode) const {
|
||||
AMS_ASSERT(this->IsOpen());
|
||||
return ((~this->access_mode) & mode) == 0;
|
||||
return ((~m_access_mode) & mode) == 0;
|
||||
}
|
||||
|
||||
bool CheckExclusiveWrite() const {
|
||||
|
||||
@@ -37,21 +37,21 @@ namespace ams::ddsf::impl {
|
||||
|
||||
class TypeTag {
|
||||
private:
|
||||
const char * const class_name;
|
||||
const TypeTag * const base;
|
||||
const char * const m_class_name;
|
||||
const TypeTag * const m_base;
|
||||
public:
|
||||
#if !(defined(AMS_BUILD_FOR_DEBUGGING) || defined(AMS_BUILD_FOR_AUDITING))
|
||||
constexpr TypeTag() : class_name(nullptr), base(nullptr) { /* ... */}
|
||||
constexpr TypeTag(const TypeTag &b) : class_name(nullptr), base(std::addressof(b)) { AMS_ASSERT(this != this->base); }
|
||||
constexpr TypeTag() : m_class_name(nullptr), m_base(nullptr) { /* ... */}
|
||||
constexpr TypeTag(const TypeTag &b) : m_class_name(nullptr), m_base(std::addressof(b)) { AMS_ASSERT(this != m_base); }
|
||||
|
||||
constexpr TypeTag(const char *c) : class_name(nullptr), base(nullptr) { AMS_UNUSED(c); }
|
||||
constexpr TypeTag(const char *c, const TypeTag &b) : class_name(nullptr), base(std::addressof(b)) { AMS_UNUSED(c); AMS_ASSERT(this != this->base); }
|
||||
constexpr TypeTag(const char *c) : m_class_name(nullptr), m_base(nullptr) { AMS_UNUSED(c); }
|
||||
constexpr TypeTag(const char *c, const TypeTag &b) : m_class_name(nullptr), m_base(std::addressof(b)) { AMS_UNUSED(c); AMS_ASSERT(this != m_base); }
|
||||
#else
|
||||
constexpr TypeTag(const char *c) : class_name(c), base(nullptr) { /* ... */ }
|
||||
constexpr TypeTag(const char *c, const TypeTag &b) : class_name(c), base(std::addressof(b)) { AMS_ASSERT(this != this->base); }
|
||||
constexpr TypeTag(const char *c) : m_class_name(c), m_base(nullptr) { /* ... */ }
|
||||
constexpr TypeTag(const char *c, const TypeTag &b) : m_class_name(c), m_base(std::addressof(b)) { AMS_ASSERT(this != m_base); }
|
||||
#endif
|
||||
|
||||
constexpr const char * GetClassName() const { return this->class_name; }
|
||||
constexpr const char * GetClassName() const { return m_class_name; }
|
||||
|
||||
constexpr bool Is(const TypeTag &rhs) const { return this == std::addressof(rhs); }
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace ams::ddsf::impl {
|
||||
if (cur == std::addressof(rhs)) {
|
||||
return true;
|
||||
}
|
||||
cur = cur->base;
|
||||
cur = cur->m_base;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ams::dmnt::cheat {
|
||||
MemoryRegionExtents heap_extents;
|
||||
MemoryRegionExtents alias_extents;
|
||||
MemoryRegionExtents aslr_extents;
|
||||
u8 main_nso_build_id[0x20];
|
||||
u8 main_nso_module_id[0x20];
|
||||
};
|
||||
|
||||
static_assert(util::is_pod<CheatProcessMetadata>::value && sizeof(CheatProcessMetadata) == 0x70, "CheatProcessMetadata definition!");
|
||||
|
||||
@@ -135,8 +135,8 @@ namespace ams::fs {
|
||||
using DirectoryEntryMapTable = EntryMapTable<RomEntryKey, EntryKey, RomDirectoryEntry>;
|
||||
using FileEntryMapTable = EntryMapTable<RomEntryKey, EntryKey, RomFileEntry>;
|
||||
private:
|
||||
DirectoryEntryMapTable dir_table;
|
||||
FileEntryMapTable file_table;
|
||||
DirectoryEntryMapTable m_dir_table;
|
||||
FileEntryMapTable m_file_table;
|
||||
public:
|
||||
static s64 QueryDirectoryEntryBucketStorageSize(s64 count);
|
||||
static size_t QueryDirectoryEntrySize(size_t aux_size);
|
||||
@@ -148,11 +148,11 @@ namespace ams::fs {
|
||||
HierarchicalRomFileTable();
|
||||
|
||||
constexpr u32 GetDirectoryEntryCount() const {
|
||||
return this->dir_table.GetEntryCount();
|
||||
return m_dir_table.GetEntryCount();
|
||||
}
|
||||
|
||||
constexpr u32 GetFileEntryCount() const {
|
||||
return this->file_table.GetEntryCount();
|
||||
return m_file_table.GetEntryCount();
|
||||
}
|
||||
|
||||
Result Initialize(SubStorage dir_bucket, SubStorage dir_entry, SubStorage file_bucket, SubStorage file_entry);
|
||||
|
||||
@@ -43,11 +43,11 @@ namespace ams::fs {
|
||||
};
|
||||
static_assert(util::is_pod<Element>::value);
|
||||
private:
|
||||
s64 bucket_count;
|
||||
SubStorage bucket_storage;
|
||||
SubStorage kv_storage;
|
||||
s64 total_entry_size;
|
||||
u32 entry_count;
|
||||
s64 m_bucket_count;
|
||||
SubStorage m_bucket_storage;
|
||||
SubStorage m_kv_storage;
|
||||
s64 m_total_entry_size;
|
||||
u32 m_entry_count;
|
||||
public:
|
||||
static constexpr s64 QueryBucketStorageSize(s64 num) {
|
||||
return num * sizeof(Position);
|
||||
@@ -69,42 +69,42 @@ namespace ams::fs {
|
||||
return ResultSuccess();
|
||||
}
|
||||
public:
|
||||
KeyValueRomStorageTemplate() : bucket_count(), bucket_storage(), kv_storage(), total_entry_size(), entry_count() { /* ... */ }
|
||||
KeyValueRomStorageTemplate() : m_bucket_count(), m_bucket_storage(), m_kv_storage(), m_total_entry_size(), m_entry_count() { /* ... */ }
|
||||
|
||||
Result Initialize(const SubStorage &bucket, s64 count, const SubStorage &kv) {
|
||||
AMS_ASSERT(count > 0);
|
||||
this->bucket_storage = bucket;
|
||||
this->bucket_count = count;
|
||||
this->kv_storage = kv;
|
||||
m_bucket_storage = bucket;
|
||||
m_bucket_count = count;
|
||||
m_kv_storage = kv;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
this->bucket_storage = SubStorage();
|
||||
this->kv_storage = SubStorage();
|
||||
this->bucket_count = 0;
|
||||
m_bucket_storage = SubStorage();
|
||||
m_kv_storage = SubStorage();
|
||||
m_bucket_count = 0;
|
||||
}
|
||||
|
||||
s64 GetTotalEntrySize() const {
|
||||
return this->total_entry_size;
|
||||
return m_total_entry_size;
|
||||
}
|
||||
|
||||
Result GetFreeSize(s64 *out) {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
s64 kv_size = 0;
|
||||
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size)));
|
||||
*out = kv_size - this->total_entry_size;
|
||||
R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
|
||||
*out = kv_size - m_total_entry_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
constexpr u32 GetEntryCount() const {
|
||||
return this->entry_count;
|
||||
return m_entry_count;
|
||||
}
|
||||
protected:
|
||||
Result AddInternal(Position *out, const Key &key, u32 hash_key, const void *aux, size_t aux_size, const Value &value) {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
AMS_ASSERT(aux != nullptr || aux_size == 0);
|
||||
AMS_ASSERT(this->bucket_count > 0);
|
||||
AMS_ASSERT(m_bucket_count > 0);
|
||||
|
||||
{
|
||||
Position pos, prev_pos;
|
||||
@@ -125,7 +125,7 @@ namespace ams::fs {
|
||||
R_TRY(this->WriteKeyValue(std::addressof(elem), pos, aux, aux_size));
|
||||
|
||||
*out = pos;
|
||||
this->entry_count++;
|
||||
m_entry_count++;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
@@ -178,7 +178,7 @@ namespace ams::fs {
|
||||
}
|
||||
private:
|
||||
BucketIndex HashToBucket(u32 hash_key) const {
|
||||
return hash_key % this->bucket_count;
|
||||
return hash_key % m_bucket_count;
|
||||
}
|
||||
|
||||
Result FindInternal(Position *out_pos, Position *out_prev, Element *out_elem, const Key &key, u32 hash_key, const void *aux, size_t aux_size) {
|
||||
@@ -186,7 +186,7 @@ namespace ams::fs {
|
||||
AMS_ASSERT(out_prev != nullptr);
|
||||
AMS_ASSERT(out_elem != nullptr);
|
||||
AMS_ASSERT(aux != nullptr || aux_size == 0);
|
||||
AMS_ASSERT(this->bucket_count > 0);
|
||||
AMS_ASSERT(m_bucket_count > 0);
|
||||
|
||||
*out_pos = 0;
|
||||
*out_prev = 0;
|
||||
@@ -197,7 +197,7 @@ namespace ams::fs {
|
||||
R_TRY(this->ReadBucket(std::addressof(cur), ind));
|
||||
|
||||
s64 kv_size;
|
||||
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size)));
|
||||
R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
|
||||
AMS_ASSERT(cur == InvalidPosition || cur < kv_size);
|
||||
|
||||
R_UNLESS(cur != InvalidPosition, fs::ResultDbmKeyNotFound());
|
||||
@@ -225,13 +225,13 @@ namespace ams::fs {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
|
||||
s64 kv_size;
|
||||
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size)));
|
||||
const size_t end_pos = this->total_entry_size + sizeof(Element) + aux_size;
|
||||
R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
|
||||
const size_t end_pos = m_total_entry_size + sizeof(Element) + aux_size;
|
||||
R_UNLESS(end_pos <= static_cast<size_t>(kv_size), fs::ResultDbmKeyFull());
|
||||
|
||||
*out = static_cast<Position>(this->total_entry_size);
|
||||
*out = static_cast<Position>(m_total_entry_size);
|
||||
|
||||
this->total_entry_size = util::AlignUp(static_cast<s64>(end_pos), alignof(Position));
|
||||
m_total_entry_size = util::AlignUp(static_cast<s64>(end_pos), alignof(Position));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace ams::fs {
|
||||
R_TRY(this->ReadBucket(std::addressof(next), ind));
|
||||
|
||||
s64 kv_size;
|
||||
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size)));
|
||||
R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
|
||||
AMS_ASSERT(next == InvalidPosition || next < kv_size);
|
||||
|
||||
R_TRY(this->WriteBucket(pos, ind));
|
||||
@@ -255,27 +255,27 @@ namespace ams::fs {
|
||||
|
||||
Result ReadBucket(Position *out, BucketIndex ind) {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
AMS_ASSERT(ind < this->bucket_count);
|
||||
AMS_ASSERT(ind < m_bucket_count);
|
||||
|
||||
const s64 offset = ind * sizeof(Position);
|
||||
return this->bucket_storage.Read(offset, out, sizeof(*out));
|
||||
return m_bucket_storage.Read(offset, out, sizeof(*out));
|
||||
}
|
||||
|
||||
Result WriteBucket(Position pos, BucketIndex ind) {
|
||||
AMS_ASSERT(ind < this->bucket_count);
|
||||
AMS_ASSERT(ind < m_bucket_count);
|
||||
|
||||
const s64 offset = ind * sizeof(Position);
|
||||
return this->bucket_storage.Write(offset, std::addressof(pos), sizeof(pos));
|
||||
return m_bucket_storage.Write(offset, std::addressof(pos), sizeof(pos));
|
||||
}
|
||||
|
||||
Result ReadKeyValue(Element *out, Position pos) {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
|
||||
s64 kv_size;
|
||||
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size)));
|
||||
R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
|
||||
AMS_ASSERT(pos < kv_size);
|
||||
|
||||
return this->kv_storage.Read(pos, out, sizeof(*out));
|
||||
return m_kv_storage.Read(pos, out, sizeof(*out));
|
||||
}
|
||||
|
||||
Result ReadKeyValue(Element *out, void *out_aux, size_t *out_aux_size, Position pos) {
|
||||
@@ -287,7 +287,7 @@ namespace ams::fs {
|
||||
|
||||
*out_aux_size = out->size;
|
||||
if (out->size > 0) {
|
||||
R_TRY(this->kv_storage.Read(pos + sizeof(*out), out_aux, out->size));
|
||||
R_TRY(m_kv_storage.Read(pos + sizeof(*out), out_aux, out->size));
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
@@ -298,13 +298,13 @@ namespace ams::fs {
|
||||
AMS_ASSERT(aux != nullptr);
|
||||
|
||||
s64 kv_size;
|
||||
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size)));
|
||||
R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
|
||||
AMS_ASSERT(pos < kv_size);
|
||||
|
||||
R_TRY(this->kv_storage.Write(pos, elem, sizeof(*elem)));
|
||||
R_TRY(m_kv_storage.Write(pos, elem, sizeof(*elem)));
|
||||
|
||||
if (aux != nullptr && aux_size > 0) {
|
||||
R_TRY(this->kv_storage.Write(pos + sizeof(*elem), aux, aux_size));
|
||||
R_TRY(m_kv_storage.Write(pos + sizeof(*elem), aux, aux_size));
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
|
||||
@@ -81,12 +81,12 @@ namespace ams::fs::RomPathTool {
|
||||
|
||||
class PathParser {
|
||||
private:
|
||||
const RomPathChar *prev_path_start;
|
||||
const RomPathChar *prev_path_end;
|
||||
const RomPathChar *next_path;
|
||||
bool finished;
|
||||
const RomPathChar *m_prev_path_start;
|
||||
const RomPathChar *m_prev_path_end;
|
||||
const RomPathChar *m_next_path;
|
||||
bool m_finished;
|
||||
public:
|
||||
constexpr PathParser() : prev_path_start(), prev_path_end(), next_path(), finished() { /* ... */ }
|
||||
constexpr PathParser() : m_prev_path_start(), m_prev_path_end(), m_next_path(), m_finished() { /* ... */ }
|
||||
|
||||
Result Initialize(const RomPathChar *path);
|
||||
void Finalize();
|
||||
|
||||
@@ -28,42 +28,42 @@ namespace ams::fs {
|
||||
private:
|
||||
static constexpr s64 InvalidSize = -1;
|
||||
private:
|
||||
std::unique_ptr<fsa::IFile> unique_file;
|
||||
std::shared_ptr<fsa::IFile> shared_file;
|
||||
fsa::IFile *base_file;
|
||||
s64 size;
|
||||
std::unique_ptr<fsa::IFile> m_unique_file;
|
||||
std::shared_ptr<fsa::IFile> m_shared_file;
|
||||
fsa::IFile *m_base_file;
|
||||
s64 m_size;
|
||||
public:
|
||||
FileStorage(fsa::IFile *f) : unique_file(f), size(InvalidSize) {
|
||||
this->base_file = this->unique_file.get();
|
||||
FileStorage(fsa::IFile *f) : m_unique_file(f), m_size(InvalidSize) {
|
||||
m_base_file = m_unique_file.get();
|
||||
}
|
||||
|
||||
FileStorage(std::unique_ptr<fsa::IFile> f) : unique_file(std::move(f)), size(InvalidSize) {
|
||||
this->base_file = this->unique_file.get();
|
||||
FileStorage(std::unique_ptr<fsa::IFile> f) : m_unique_file(std::move(f)), m_size(InvalidSize) {
|
||||
m_base_file = m_unique_file.get();
|
||||
}
|
||||
|
||||
FileStorage(std::shared_ptr<fsa::IFile> f) : shared_file(f), size(InvalidSize) {
|
||||
this->base_file = this->shared_file.get();
|
||||
FileStorage(std::shared_ptr<fsa::IFile> f) : m_shared_file(f), m_size(InvalidSize) {
|
||||
m_base_file = m_shared_file.get();
|
||||
}
|
||||
|
||||
virtual ~FileStorage() { /* ... */ }
|
||||
private:
|
||||
Result UpdateSize();
|
||||
protected:
|
||||
constexpr FileStorage() : unique_file(), shared_file(), base_file(nullptr), size(InvalidSize) { /* ... */ }
|
||||
constexpr FileStorage() : m_unique_file(), m_shared_file(), m_base_file(nullptr), m_size(InvalidSize) { /* ... */ }
|
||||
|
||||
void SetFile(fs::fsa::IFile *file) {
|
||||
AMS_ASSERT(file != nullptr);
|
||||
AMS_ASSERT(this->base_file == nullptr);
|
||||
this->base_file = file;
|
||||
AMS_ASSERT(m_base_file == nullptr);
|
||||
m_base_file = file;
|
||||
}
|
||||
|
||||
void SetFile(std::unique_ptr<fs::fsa::IFile> &&file) {
|
||||
AMS_ASSERT(file != nullptr);
|
||||
AMS_ASSERT(this->base_file == nullptr);
|
||||
AMS_ASSERT(this->unique_file == nullptr);
|
||||
AMS_ASSERT(m_base_file == nullptr);
|
||||
AMS_ASSERT(m_unique_file == nullptr);
|
||||
|
||||
this->unique_file = std::move(file);
|
||||
this->base_file = this->unique_file.get();
|
||||
m_unique_file = std::move(file);
|
||||
m_base_file = m_unique_file.get();
|
||||
}
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
||||
@@ -78,9 +78,9 @@ namespace ams::fs {
|
||||
NON_COPYABLE(FileStorageBasedFileSystem);
|
||||
NON_MOVEABLE(FileStorageBasedFileSystem);
|
||||
private:
|
||||
std::shared_ptr<fs::fsa::IFileSystem> base_file_system;
|
||||
std::shared_ptr<fs::fsa::IFileSystem> m_base_file_system;
|
||||
public:
|
||||
constexpr FileStorageBasedFileSystem() : FileStorage(), base_file_system(nullptr) { /* ... */ }
|
||||
constexpr FileStorageBasedFileSystem() : FileStorage(), m_base_file_system(nullptr) { /* ... */ }
|
||||
|
||||
Result Initialize(std::shared_ptr<fs::fsa::IFileSystem> base_file_system, const char *path, fs::OpenMode mode);
|
||||
};
|
||||
@@ -89,17 +89,17 @@ namespace ams::fs {
|
||||
private:
|
||||
static constexpr s64 InvalidSize = -1;
|
||||
private:
|
||||
FileHandle handle;
|
||||
bool close_file;
|
||||
s64 size;
|
||||
os::SdkMutex mutex;
|
||||
FileHandle m_handle;
|
||||
bool m_close_file;
|
||||
s64 m_size;
|
||||
os::SdkMutex m_mutex;
|
||||
public:
|
||||
constexpr explicit FileHandleStorage(FileHandle handle, bool close_file) : handle(handle), close_file(close_file), size(InvalidSize), mutex() { /* ... */ }
|
||||
constexpr explicit FileHandleStorage(FileHandle handle, bool close_file) : m_handle(handle), m_close_file(close_file), m_size(InvalidSize), m_mutex() { /* ... */ }
|
||||
constexpr explicit FileHandleStorage(FileHandle handle) : FileHandleStorage(handle, false) { /* ... */ }
|
||||
|
||||
virtual ~FileHandleStorage() override {
|
||||
if (this->close_file) {
|
||||
CloseFile(this->handle);
|
||||
if (m_close_file) {
|
||||
CloseFile(m_handle);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
|
||||
@@ -28,13 +28,13 @@ namespace ams::fs {
|
||||
|
||||
class FsContext {
|
||||
private:
|
||||
ResultHandler handler;
|
||||
ResultHandler m_handler;
|
||||
public:
|
||||
constexpr explicit FsContext(ResultHandler h) : handler(h) { /* ... */ }
|
||||
constexpr explicit FsContext(ResultHandler h) : m_handler(h) { /* ... */ }
|
||||
|
||||
constexpr void SetHandler(ResultHandler h) { this->handler = h; }
|
||||
constexpr void SetHandler(ResultHandler h) { m_handler = h; }
|
||||
|
||||
constexpr AbortSpecifier HandleResult(Result result) const { return this->handler(result); }
|
||||
constexpr AbortSpecifier HandleResult(Result result) const { return m_handler(result); }
|
||||
};
|
||||
|
||||
void SetDefaultFsContextResultHandler(const ResultHandler handler);
|
||||
@@ -44,24 +44,24 @@ namespace ams::fs {
|
||||
|
||||
class ScopedFsContext {
|
||||
private:
|
||||
const FsContext * const prev_context;
|
||||
const FsContext * const m_prev_context;
|
||||
public:
|
||||
ALWAYS_INLINE ScopedFsContext(const FsContext &ctx) : prev_context(GetCurrentThreadFsContext()) {
|
||||
ALWAYS_INLINE ScopedFsContext(const FsContext &ctx) : m_prev_context(GetCurrentThreadFsContext()) {
|
||||
SetCurrentThreadFsContext(std::addressof(ctx));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ~ScopedFsContext() {
|
||||
SetCurrentThreadFsContext(this->prev_context);
|
||||
SetCurrentThreadFsContext(m_prev_context);
|
||||
}
|
||||
};
|
||||
|
||||
class ScopedAutoAbortDisabler {
|
||||
private:
|
||||
const FsContext * const prev_context;
|
||||
const FsContext * const m_prev_context;
|
||||
public:
|
||||
ScopedAutoAbortDisabler();
|
||||
ALWAYS_INLINE ~ScopedAutoAbortDisabler() {
|
||||
SetCurrentThreadFsContext(this->prev_context);
|
||||
SetCurrentThreadFsContext(m_prev_context);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
namespace ams::fs {
|
||||
|
||||
struct ReadOption {
|
||||
u32 value;
|
||||
u32 _value;
|
||||
|
||||
static const ReadOption None;
|
||||
};
|
||||
@@ -27,7 +27,7 @@ namespace ams::fs {
|
||||
inline constexpr const ReadOption ReadOption::None = {FsReadOption_None};
|
||||
|
||||
inline constexpr bool operator==(const ReadOption &lhs, const ReadOption &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
return lhs._value == rhs._value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const ReadOption &lhs, const ReadOption &rhs) {
|
||||
@@ -37,10 +37,10 @@ namespace ams::fs {
|
||||
static_assert(util::is_pod<ReadOption>::value && sizeof(ReadOption) == sizeof(u32));
|
||||
|
||||
struct WriteOption {
|
||||
u32 value;
|
||||
u32 _value;
|
||||
|
||||
constexpr inline bool HasFlushFlag() const {
|
||||
return this->value & FsWriteOption_Flush;
|
||||
return _value & FsWriteOption_Flush;
|
||||
}
|
||||
|
||||
static const WriteOption None;
|
||||
@@ -51,7 +51,7 @@ namespace ams::fs {
|
||||
inline constexpr const WriteOption WriteOption::Flush = {FsWriteOption_Flush};
|
||||
|
||||
inline constexpr bool operator==(const WriteOption &lhs, const WriteOption &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
return lhs._value == rhs._value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const WriteOption &lhs, const WriteOption &rhs) {
|
||||
|
||||
@@ -64,36 +64,36 @@ namespace ams::fs {
|
||||
|
||||
class ReadOnlyStorageAdapter : public IStorage {
|
||||
private:
|
||||
std::shared_ptr<IStorage> shared_storage;
|
||||
std::unique_ptr<IStorage> unique_storage;
|
||||
IStorage *storage;
|
||||
std::shared_ptr<IStorage> m_shared_storage;
|
||||
std::unique_ptr<IStorage> m_unique_storage;
|
||||
IStorage *m_storage;
|
||||
public:
|
||||
ReadOnlyStorageAdapter(IStorage *s) : unique_storage(s) {
|
||||
this->storage = this->unique_storage.get();
|
||||
ReadOnlyStorageAdapter(IStorage *s) : m_unique_storage(s) {
|
||||
m_storage = m_unique_storage.get();
|
||||
}
|
||||
ReadOnlyStorageAdapter(std::shared_ptr<IStorage> s) : shared_storage(s) {
|
||||
this->storage = this->shared_storage.get();
|
||||
ReadOnlyStorageAdapter(std::shared_ptr<IStorage> s) : m_shared_storage(s) {
|
||||
m_storage = m_shared_storage.get();
|
||||
}
|
||||
ReadOnlyStorageAdapter(std::unique_ptr<IStorage> s) : unique_storage(std::move(s)) {
|
||||
this->storage = this->unique_storage.get();
|
||||
ReadOnlyStorageAdapter(std::unique_ptr<IStorage> s) : m_unique_storage(std::move(s)) {
|
||||
m_storage = m_unique_storage.get();
|
||||
}
|
||||
|
||||
virtual ~ReadOnlyStorageAdapter() { /* ... */ }
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
return this->storage->Read(offset, buffer, size);
|
||||
return m_storage->Read(offset, buffer, size);
|
||||
}
|
||||
|
||||
virtual Result Flush() override {
|
||||
return this->storage->Flush();
|
||||
return m_storage->Flush();
|
||||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
return this->storage->GetSize(out);
|
||||
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 this->storage->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||
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 {
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace ams::fs {
|
||||
|
||||
class Deleter {
|
||||
private:
|
||||
size_t size;
|
||||
size_t m_size;
|
||||
public:
|
||||
Deleter() : size() { /* ... */ }
|
||||
explicit Deleter(size_t sz) : size(sz) { /* ... */ }
|
||||
Deleter() : m_size() { /* ... */ }
|
||||
explicit Deleter(size_t sz) : m_size(sz) { /* ... */ }
|
||||
|
||||
void operator()(void *ptr) const {
|
||||
::ams::fs::impl::Deallocate(ptr, this->size);
|
||||
::ams::fs::impl::Deallocate(ptr, m_size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,21 +22,21 @@ namespace ams::fs {
|
||||
|
||||
class MemoryStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
|
||||
private:
|
||||
u8 * const buf;
|
||||
const s64 size;
|
||||
u8 * const m_buf;
|
||||
const s64 m_size;
|
||||
public:
|
||||
MemoryStorage(void *b, s64 sz) : buf(static_cast<u8 *>(b)), size(sz) { /* .. */ }
|
||||
MemoryStorage(void *b, s64 sz) : m_buf(static_cast<u8 *>(b)), m_size(sz) { /* .. */ }
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
/* Succeed immediately on zero-sized read. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
|
||||
/* Copy from memory. */
|
||||
std::memcpy(buffer, this->buf + offset, size);
|
||||
std::memcpy(buffer, m_buf + offset, size);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ namespace ams::fs {
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
|
||||
/* Copy to memory. */
|
||||
std::memcpy(this->buf + offset, buffer, size);
|
||||
std::memcpy(m_buf + offset, buffer, size);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
*out = this->size;
|
||||
*out = m_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,17 +28,17 @@ namespace ams::fs {
|
||||
NON_COPYABLE(ReadOnlyFile);
|
||||
NON_MOVEABLE(ReadOnlyFile);
|
||||
private:
|
||||
std::unique_ptr<fsa::IFile> base_file;
|
||||
std::unique_ptr<fsa::IFile> m_base_file;
|
||||
public:
|
||||
explicit ReadOnlyFile(std::unique_ptr<fsa::IFile> &&f) : base_file(std::move(f)) { /* ... */ }
|
||||
explicit ReadOnlyFile(std::unique_ptr<fsa::IFile> &&f) : m_base_file(std::move(f)) { /* ... */ }
|
||||
virtual ~ReadOnlyFile() { /* ... */ }
|
||||
private:
|
||||
virtual Result DoRead(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override final {
|
||||
return this->base_file->Read(out, offset, buffer, size, option);
|
||||
return m_base_file->Read(out, offset, buffer, size, option);
|
||||
}
|
||||
|
||||
virtual Result DoGetSize(s64 *out) override final {
|
||||
return this->base_file->GetSize(out);
|
||||
return m_base_file->GetSize(out);
|
||||
}
|
||||
|
||||
virtual Result DoFlush() override final {
|
||||
@@ -59,14 +59,14 @@ namespace ams::fs {
|
||||
switch (op_id) {
|
||||
case OperationId::Invalidate:
|
||||
case OperationId::QueryRange:
|
||||
return this->base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||
return m_base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||
default:
|
||||
return fs::ResultUnsupportedOperationInReadOnlyFileB();
|
||||
}
|
||||
}
|
||||
public:
|
||||
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override {
|
||||
return this->base_file->GetDomainObjectId();
|
||||
return m_base_file->GetDomainObjectId();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,9 +77,9 @@ namespace ams::fs {
|
||||
NON_COPYABLE(ReadOnlyFileSystemTemplate);
|
||||
NON_MOVEABLE(ReadOnlyFileSystemTemplate);
|
||||
private:
|
||||
T base_fs;
|
||||
T m_base_fs;
|
||||
public:
|
||||
explicit ReadOnlyFileSystemTemplate(T &&fs) : base_fs(std::move(fs)) { /* ... */ }
|
||||
explicit ReadOnlyFileSystemTemplate(T &&fs) : m_base_fs(std::move(fs)) { /* ... */ }
|
||||
virtual ~ReadOnlyFileSystemTemplate() { /* ... */ }
|
||||
private:
|
||||
virtual Result DoOpenFile(std::unique_ptr<fsa::IFile> *out_file, const char *path, OpenMode mode) override final {
|
||||
@@ -87,7 +87,7 @@ namespace ams::fs {
|
||||
R_UNLESS((mode & fs::OpenMode_All) == fs::OpenMode_Read, fs::ResultInvalidOpenMode());
|
||||
|
||||
std::unique_ptr<fsa::IFile> base_file;
|
||||
R_TRY(this->base_fs->OpenFile(std::addressof(base_file), path, mode));
|
||||
R_TRY(m_base_fs->OpenFile(std::addressof(base_file), path, mode));
|
||||
|
||||
auto read_only_file = std::make_unique<ReadOnlyFile>(std::move(base_file));
|
||||
R_UNLESS(read_only_file != nullptr, fs::ResultAllocationFailureInReadOnlyFileSystemA());
|
||||
@@ -97,11 +97,11 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
virtual Result DoOpenDirectory(std::unique_ptr<fsa::IDirectory> *out_dir, const char *path, OpenDirectoryMode mode) override final {
|
||||
return this->base_fs->OpenDirectory(out_dir, path, mode);
|
||||
return m_base_fs->OpenDirectory(out_dir, path, mode);
|
||||
}
|
||||
|
||||
virtual Result DoGetEntryType(DirectoryEntryType *out, const char *path) override final {
|
||||
return this->base_fs->GetEntryType(out, path);
|
||||
return m_base_fs->GetEntryType(out, path);
|
||||
}
|
||||
|
||||
virtual Result DoCommit() override final {
|
||||
|
||||
@@ -26,30 +26,30 @@ namespace ams::fs {
|
||||
|
||||
class RemoteFile : public fsa::IFile, public impl::Newable {
|
||||
private:
|
||||
::FsFile base_file;
|
||||
::FsFile m_base_file;
|
||||
public:
|
||||
RemoteFile(const ::FsFile &f) : base_file(f) { /* ... */ }
|
||||
RemoteFile(const ::FsFile &f) : m_base_file(f) { /* ... */ }
|
||||
|
||||
virtual ~RemoteFile() { fsFileClose(std::addressof(this->base_file)); }
|
||||
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(this->base_file), offset, buffer, size, option.value, out);
|
||||
return fsFileRead(std::addressof(m_base_file), offset, buffer, size, option._value, out);
|
||||
}
|
||||
|
||||
virtual Result DoGetSize(s64 *out) override final {
|
||||
return fsFileGetSize(std::addressof(this->base_file), out);
|
||||
return fsFileGetSize(std::addressof(m_base_file), out);
|
||||
}
|
||||
|
||||
virtual Result DoFlush() override final {
|
||||
return fsFileFlush(std::addressof(this->base_file));
|
||||
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(this->base_file), offset, buffer, size, option.value);
|
||||
return fsFileWrite(std::addressof(m_base_file), offset, buffer, size, option._value);
|
||||
}
|
||||
|
||||
virtual Result DoSetSize(s64 size) override final {
|
||||
return fsFileSetSize(std::addressof(this->base_file), size);
|
||||
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 {
|
||||
@@ -58,42 +58,42 @@ namespace ams::fs {
|
||||
R_UNLESS(op_id == OperationId::QueryRange, fs::ResultUnsupportedOperationInFileServiceObjectAdapterA());
|
||||
R_UNLESS(dst_size == sizeof(FileQueryRangeInfo), fs::ResultInvalidSize());
|
||||
|
||||
return fsFileOperateRange(std::addressof(this->base_file), static_cast<::FsOperationId>(op_id), offset, size, reinterpret_cast<::FsRangeInfo *>(dst));
|
||||
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 {
|
||||
return sf::cmif::DomainObjectId{serviceGetObjectId(const_cast<::Service *>(std::addressof(this->base_file.s)))};
|
||||
return sf::cmif::DomainObjectId{serviceGetObjectId(const_cast<::Service *>(std::addressof(m_base_file.s)))};
|
||||
}
|
||||
};
|
||||
|
||||
class RemoteDirectory : public fsa::IDirectory, public impl::Newable {
|
||||
private:
|
||||
::FsDir base_dir;
|
||||
::FsDir m_base_dir;
|
||||
public:
|
||||
RemoteDirectory(const ::FsDir &d) : base_dir(d) { /* ... */ }
|
||||
RemoteDirectory(const ::FsDir &d) : m_base_dir(d) { /* ... */ }
|
||||
|
||||
virtual ~RemoteDirectory() { fsDirClose(std::addressof(this->base_dir)); }
|
||||
virtual ~RemoteDirectory() { fsDirClose(std::addressof(m_base_dir)); }
|
||||
public:
|
||||
virtual Result DoRead(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries) override final {
|
||||
return fsDirRead(std::addressof(this->base_dir), out_count, max_entries, out_entries);
|
||||
return fsDirRead(std::addressof(m_base_dir), out_count, max_entries, out_entries);
|
||||
}
|
||||
|
||||
virtual Result DoGetEntryCount(s64 *out) override final {
|
||||
return fsDirGetEntryCount(std::addressof(this->base_dir), out);
|
||||
return fsDirGetEntryCount(std::addressof(m_base_dir), out);
|
||||
}
|
||||
public:
|
||||
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override {
|
||||
return sf::cmif::DomainObjectId{serviceGetObjectId(const_cast<::Service *>(std::addressof(this->base_dir.s)))};
|
||||
return sf::cmif::DomainObjectId{serviceGetObjectId(const_cast<::Service *>(std::addressof(m_base_dir.s)))};
|
||||
}
|
||||
};
|
||||
|
||||
class RemoteFileSystem : public fsa::IFileSystem, public impl::Newable {
|
||||
private:
|
||||
::FsFileSystem base_fs;
|
||||
::FsFileSystem m_base_fs;
|
||||
public:
|
||||
RemoteFileSystem(const ::FsFileSystem &fs) : base_fs(fs) { /* ... */ }
|
||||
RemoteFileSystem(const ::FsFileSystem &fs) : m_base_fs(fs) { /* ... */ }
|
||||
|
||||
virtual ~RemoteFileSystem() { fsFsClose(std::addressof(this->base_fs)); }
|
||||
virtual ~RemoteFileSystem() { fsFsClose(std::addressof(m_base_fs)); }
|
||||
private:
|
||||
Result GetPathForServiceObject(fssrv::sf::Path *out_path, const char *path) {
|
||||
/* Copy and null terminate. */
|
||||
@@ -113,31 +113,31 @@ namespace ams::fs {
|
||||
virtual Result DoCreateFile(const char *path, s64 size, int flags) override final {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsCreateFile(std::addressof(this->base_fs), sf_path.str, size, flags);
|
||||
return fsFsCreateFile(std::addressof(m_base_fs), sf_path.str, size, flags);
|
||||
}
|
||||
|
||||
virtual Result DoDeleteFile(const char *path) override final {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsDeleteFile(std::addressof(this->base_fs), sf_path.str);
|
||||
return fsFsDeleteFile(std::addressof(m_base_fs), sf_path.str);
|
||||
}
|
||||
|
||||
virtual Result DoCreateDirectory(const char *path) override final {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsCreateDirectory(std::addressof(this->base_fs), sf_path.str);
|
||||
return fsFsCreateDirectory(std::addressof(m_base_fs), sf_path.str);
|
||||
}
|
||||
|
||||
virtual Result DoDeleteDirectory(const char *path) override final {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsDeleteDirectory(std::addressof(this->base_fs), sf_path.str);
|
||||
return fsFsDeleteDirectory(std::addressof(m_base_fs), sf_path.str);
|
||||
}
|
||||
|
||||
virtual Result DoDeleteDirectoryRecursively(const char *path) override final {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsDeleteDirectoryRecursively(std::addressof(this->base_fs), sf_path.str);
|
||||
return fsFsDeleteDirectoryRecursively(std::addressof(m_base_fs), sf_path.str);
|
||||
}
|
||||
|
||||
virtual Result DoRenameFile(const char *old_path, const char *new_path) override final {
|
||||
@@ -145,7 +145,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(this->base_fs), old_sf_path.str, new_sf_path.str);
|
||||
return fsFsRenameFile(std::addressof(m_base_fs), old_sf_path.str, new_sf_path.str);
|
||||
}
|
||||
|
||||
virtual Result DoRenameDirectory(const char *old_path, const char *new_path) override final {
|
||||
@@ -153,7 +153,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(this->base_fs), old_sf_path.str, new_sf_path.str);
|
||||
return fsFsRenameDirectory(std::addressof(m_base_fs), old_sf_path.str, new_sf_path.str);
|
||||
}
|
||||
|
||||
virtual Result DoGetEntryType(DirectoryEntryType *out, const char *path) override final {
|
||||
@@ -161,7 +161,7 @@ namespace ams::fs {
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
|
||||
static_assert(sizeof(::FsDirEntryType) == sizeof(DirectoryEntryType));
|
||||
return fsFsGetEntryType(std::addressof(this->base_fs), sf_path.str, reinterpret_cast<::FsDirEntryType *>(out));
|
||||
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 char *path, OpenMode mode) override final {
|
||||
@@ -169,7 +169,7 @@ namespace ams::fs {
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
|
||||
FsFile f;
|
||||
R_TRY(fsFsOpenFile(std::addressof(this->base_fs), sf_path.str, mode, &f));
|
||||
R_TRY(fsFsOpenFile(std::addressof(m_base_fs), sf_path.str, mode, std::addressof(f)));
|
||||
|
||||
auto file = std::make_unique<RemoteFile>(f);
|
||||
R_UNLESS(file != nullptr, fs::ResultAllocationFailureInNew());
|
||||
@@ -183,7 +183,7 @@ namespace ams::fs {
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
|
||||
FsDir d;
|
||||
R_TRY(fsFsOpenDirectory(std::addressof(this->base_fs), sf_path.str, mode, &d));
|
||||
R_TRY(fsFsOpenDirectory(std::addressof(m_base_fs), sf_path.str, mode, std::addressof(d)));
|
||||
|
||||
auto dir = std::make_unique<RemoteDirectory>(d);
|
||||
R_UNLESS(dir != nullptr, fs::ResultAllocationFailureInNew());
|
||||
@@ -193,39 +193,39 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
virtual Result DoCommit() override final {
|
||||
return fsFsCommit(std::addressof(this->base_fs));
|
||||
return fsFsCommit(std::addressof(m_base_fs));
|
||||
}
|
||||
|
||||
|
||||
virtual Result DoGetFreeSpaceSize(s64 *out, const char *path) {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsGetFreeSpace(std::addressof(this->base_fs), sf_path.str, out);
|
||||
return fsFsGetFreeSpace(std::addressof(m_base_fs), sf_path.str, out);
|
||||
}
|
||||
|
||||
virtual Result DoGetTotalSpaceSize(s64 *out, const char *path) {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsGetTotalSpace(std::addressof(this->base_fs), sf_path.str, out);
|
||||
return fsFsGetTotalSpace(std::addressof(m_base_fs), sf_path.str, out);
|
||||
}
|
||||
|
||||
virtual Result DoCleanDirectoryRecursively(const char *path) {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsCleanDirectoryRecursively(std::addressof(this->base_fs), sf_path.str);
|
||||
return fsFsCleanDirectoryRecursively(std::addressof(m_base_fs), sf_path.str);
|
||||
}
|
||||
|
||||
virtual Result DoGetFileTimeStampRaw(FileTimeStampRaw *out, const char *path) {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
static_assert(sizeof(FileTimeStampRaw) == sizeof(::FsTimeStampRaw));
|
||||
return fsFsGetFileTimeStampRaw(std::addressof(this->base_fs), sf_path.str, reinterpret_cast<::FsTimeStampRaw *>(out));
|
||||
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 char *path) {
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
|
||||
return fsFsQueryEntry(std::addressof(this->base_fs), dst, dst_size, src, src_size, sf_path.str, static_cast<FsFileSystemQueryId>(query));
|
||||
return fsFsQueryEntry(std::addressof(m_base_fs), dst, dst_size, src, src_size, sf_path.str, static_cast<FsFileSystemQueryId>(query));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,33 +22,33 @@ namespace ams::fs {
|
||||
|
||||
class RemoteStorage : public IStorage, public impl::Newable {
|
||||
private:
|
||||
std::unique_ptr<::FsStorage, impl::Deleter> base_storage;
|
||||
std::unique_ptr<::FsStorage, impl::Deleter> m_base_storage;
|
||||
public:
|
||||
RemoteStorage(::FsStorage &s) {
|
||||
this->base_storage = impl::MakeUnique<::FsStorage>();
|
||||
*this->base_storage = s;
|
||||
m_base_storage = impl::MakeUnique<::FsStorage>();
|
||||
*m_base_storage = s;
|
||||
}
|
||||
|
||||
virtual ~RemoteStorage() { fsStorageClose(this->base_storage.get()); }
|
||||
virtual ~RemoteStorage() { fsStorageClose(m_base_storage.get()); }
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
return fsStorageRead(this->base_storage.get(), offset, buffer, size);
|
||||
return fsStorageRead(m_base_storage.get(), offset, buffer, size);
|
||||
};
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
|
||||
return fsStorageWrite(this->base_storage.get(), offset, buffer, size);
|
||||
return fsStorageWrite(m_base_storage.get(), offset, buffer, size);
|
||||
};
|
||||
|
||||
virtual Result Flush() override {
|
||||
return fsStorageFlush(this->base_storage.get());
|
||||
return fsStorageFlush(m_base_storage.get());
|
||||
};
|
||||
|
||||
virtual Result GetSize(s64 *out_size) override {
|
||||
return fsStorageGetSize(this->base_storage.get(), out_size);
|
||||
return fsStorageGetSize(m_base_storage.get(), out_size);
|
||||
};
|
||||
|
||||
virtual Result SetSize(s64 size) override {
|
||||
return fsStorageSetSize(this->base_storage.get(), size);
|
||||
return fsStorageSetSize(m_base_storage.get(), 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 {
|
||||
|
||||
@@ -28,14 +28,14 @@ namespace ams::fs {
|
||||
public:
|
||||
using RomFileTable = HierarchicalRomFileTable;
|
||||
private:
|
||||
RomFileTable rom_file_table;
|
||||
IStorage *base_storage;
|
||||
std::unique_ptr<IStorage> unique_storage;
|
||||
std::unique_ptr<IStorage> dir_bucket_storage;
|
||||
std::unique_ptr<IStorage> dir_entry_storage;
|
||||
std::unique_ptr<IStorage> file_bucket_storage;
|
||||
std::unique_ptr<IStorage> file_entry_storage;
|
||||
s64 entry_size;
|
||||
RomFileTable m_rom_file_table;
|
||||
IStorage *m_base_storage;
|
||||
std::unique_ptr<IStorage> m_unique_storage;
|
||||
std::unique_ptr<IStorage> m_dir_bucket_storage;
|
||||
std::unique_ptr<IStorage> m_dir_entry_storage;
|
||||
std::unique_ptr<IStorage> m_file_bucket_storage;
|
||||
std::unique_ptr<IStorage> m_file_entry_storage;
|
||||
s64 m_entry_size;
|
||||
private:
|
||||
Result GetFileInfo(RomFileTable::FileInfo *out, const char *path);
|
||||
public:
|
||||
|
||||
@@ -26,29 +26,29 @@ namespace ams::fs {
|
||||
NON_COPYABLE(SharedFileSystemHolder);
|
||||
NON_MOVEABLE(SharedFileSystemHolder);
|
||||
private:
|
||||
std::shared_ptr<fsa::IFileSystem> fs;
|
||||
std::shared_ptr<fsa::IFileSystem> m_fs;
|
||||
public:
|
||||
SharedFileSystemHolder(std::shared_ptr<fsa::IFileSystem> f) : fs(std::move(f)) { /* ... */ }
|
||||
SharedFileSystemHolder(std::shared_ptr<fsa::IFileSystem> f) : m_fs(std::move(f)) { /* ... */ }
|
||||
public:
|
||||
virtual Result DoCreateFile(const char *path, s64 size, int flags) override { return this->fs->CreateFile(path, size, flags); }
|
||||
virtual Result DoDeleteFile(const char *path) override { return this->fs->DeleteFile(path); }
|
||||
virtual Result DoCreateDirectory(const char *path) override { return this->fs->CreateDirectory(path); }
|
||||
virtual Result DoDeleteDirectory(const char *path) override { return this->fs->DeleteDirectory(path); }
|
||||
virtual Result DoDeleteDirectoryRecursively(const char *path) override { return this->fs->DeleteDirectoryRecursively(path); }
|
||||
virtual Result DoRenameFile(const char *old_path, const char *new_path) override { return this->fs->RenameFile(old_path, new_path); }
|
||||
virtual Result DoRenameDirectory(const char *old_path, const char *new_path) override { return this->fs->RenameDirectory(old_path, new_path); }
|
||||
virtual Result DoGetEntryType(fs::DirectoryEntryType *out, const char *path) override { return this->fs->GetEntryType(out, path); }
|
||||
virtual Result DoOpenFile(std::unique_ptr<fs::fsa::IFile> *out_file, const char *path, fs::OpenMode mode) override { return this->fs->OpenFile(out_file, path, mode); }
|
||||
virtual Result DoOpenDirectory(std::unique_ptr<fs::fsa::IDirectory> *out_dir, const char *path, fs::OpenDirectoryMode mode) override { return this->fs->OpenDirectory(out_dir, path, mode); }
|
||||
virtual Result DoCommit() override { return this->fs->Commit(); }
|
||||
virtual Result DoGetFreeSpaceSize(s64 *out, const char *path) override { return this->fs->GetFreeSpaceSize(out, path); }
|
||||
virtual Result DoGetTotalSpaceSize(s64 *out, const char *path) override { return this->fs->GetTotalSpaceSize(out, path); }
|
||||
virtual Result DoCleanDirectoryRecursively(const char *path) override { return this->fs->CleanDirectoryRecursively(path); }
|
||||
virtual Result DoCreateFile(const char *path, s64 size, int flags) override { return m_fs->CreateFile(path, size, flags); }
|
||||
virtual Result DoDeleteFile(const char *path) override { return m_fs->DeleteFile(path); }
|
||||
virtual Result DoCreateDirectory(const char *path) override { return m_fs->CreateDirectory(path); }
|
||||
virtual Result DoDeleteDirectory(const char *path) override { return m_fs->DeleteDirectory(path); }
|
||||
virtual Result DoDeleteDirectoryRecursively(const char *path) override { return m_fs->DeleteDirectoryRecursively(path); }
|
||||
virtual Result DoRenameFile(const char *old_path, const char *new_path) override { return m_fs->RenameFile(old_path, new_path); }
|
||||
virtual Result DoRenameDirectory(const char *old_path, const char *new_path) override { return m_fs->RenameDirectory(old_path, new_path); }
|
||||
virtual Result DoGetEntryType(fs::DirectoryEntryType *out, const char *path) override { return m_fs->GetEntryType(out, path); }
|
||||
virtual Result DoOpenFile(std::unique_ptr<fs::fsa::IFile> *out_file, const char *path, fs::OpenMode mode) override { return m_fs->OpenFile(out_file, path, mode); }
|
||||
virtual Result DoOpenDirectory(std::unique_ptr<fs::fsa::IDirectory> *out_dir, const char *path, fs::OpenDirectoryMode mode) override { return m_fs->OpenDirectory(out_dir, path, mode); }
|
||||
virtual Result DoCommit() override { return m_fs->Commit(); }
|
||||
virtual Result DoGetFreeSpaceSize(s64 *out, const char *path) override { return m_fs->GetFreeSpaceSize(out, path); }
|
||||
virtual Result DoGetTotalSpaceSize(s64 *out, const char *path) override { return m_fs->GetTotalSpaceSize(out, path); }
|
||||
virtual Result DoCleanDirectoryRecursively(const char *path) override { return m_fs->CleanDirectoryRecursively(path); }
|
||||
|
||||
/* These aren't accessible as commands. */
|
||||
virtual Result DoCommitProvisionally(s64 counter) override { return this->fs->CommitProvisionally(counter); }
|
||||
virtual Result DoRollback() override { return this->fs->Rollback(); }
|
||||
virtual Result DoFlush() override { return this->fs->Flush(); }
|
||||
virtual Result DoCommitProvisionally(s64 counter) override { return m_fs->CommitProvisionally(counter); }
|
||||
virtual Result DoRollback() override { return m_fs->Rollback(); }
|
||||
virtual Result DoFlush() override { return m_fs->Flush(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -21,51 +21,51 @@ namespace ams::fs {
|
||||
|
||||
class SubStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
|
||||
private:
|
||||
std::shared_ptr<IStorage> shared_base_storage;
|
||||
fs::IStorage *base_storage;
|
||||
s64 offset;
|
||||
s64 size;
|
||||
bool resizable;
|
||||
std::shared_ptr<IStorage> m_shared_base_storage;
|
||||
fs::IStorage *m_base_storage;
|
||||
s64 m_offset;
|
||||
s64 m_size;
|
||||
bool m_resizable;
|
||||
private:
|
||||
constexpr bool IsValid() const {
|
||||
return this->base_storage != nullptr;
|
||||
return m_base_storage != nullptr;
|
||||
}
|
||||
public:
|
||||
SubStorage() : shared_base_storage(), base_storage(nullptr), offset(0), size(0), resizable(false) { /* ... */ }
|
||||
SubStorage() : m_shared_base_storage(), m_base_storage(nullptr), m_offset(0), m_size(0), m_resizable(false) { /* ... */ }
|
||||
|
||||
SubStorage(const SubStorage &rhs) : shared_base_storage(), base_storage(rhs.base_storage), offset(rhs.offset), size(rhs.size), resizable(rhs.resizable) { /* ... */}
|
||||
SubStorage(const SubStorage &rhs) : m_shared_base_storage(), m_base_storage(rhs.m_base_storage), m_offset(rhs.m_offset), m_size(rhs.m_size), m_resizable(rhs.m_resizable) { /* ... */}
|
||||
SubStorage &operator=(const SubStorage &rhs) {
|
||||
if (this != std::addressof(rhs)) {
|
||||
this->base_storage = rhs.base_storage;
|
||||
this->offset = rhs.offset;
|
||||
this->size = rhs.size;
|
||||
this->resizable = rhs.resizable;
|
||||
m_base_storage = rhs.m_base_storage;
|
||||
m_offset = rhs.m_offset;
|
||||
m_size = rhs.m_size;
|
||||
m_resizable = rhs.m_resizable;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SubStorage(IStorage *storage, s64 o, s64 sz) : shared_base_storage(), base_storage(storage), offset(o), size(sz), resizable(false) {
|
||||
SubStorage(IStorage *storage, s64 o, s64 sz) : m_shared_base_storage(), m_base_storage(storage), m_offset(o), m_size(sz), m_resizable(false) {
|
||||
AMS_ABORT_UNLESS(this->IsValid());
|
||||
AMS_ABORT_UNLESS(this->offset >= 0);
|
||||
AMS_ABORT_UNLESS(this->size >= 0);
|
||||
AMS_ABORT_UNLESS(m_offset >= 0);
|
||||
AMS_ABORT_UNLESS(m_size >= 0);
|
||||
}
|
||||
|
||||
SubStorage(std::shared_ptr<IStorage> storage, s64 o, s64 sz) : shared_base_storage(storage), base_storage(storage.get()), offset(o), size(sz), resizable(false) {
|
||||
SubStorage(std::shared_ptr<IStorage> storage, s64 o, s64 sz) : m_shared_base_storage(storage), m_base_storage(storage.get()), m_offset(o), m_size(sz), m_resizable(false) {
|
||||
AMS_ABORT_UNLESS(this->IsValid());
|
||||
AMS_ABORT_UNLESS(this->offset >= 0);
|
||||
AMS_ABORT_UNLESS(this->size >= 0);
|
||||
AMS_ABORT_UNLESS(m_offset >= 0);
|
||||
AMS_ABORT_UNLESS(m_size >= 0);
|
||||
}
|
||||
|
||||
SubStorage(SubStorage *sub, s64 o, s64 sz) : shared_base_storage(), base_storage(sub->base_storage), offset(o + sub->offset), size(sz), resizable(false) {
|
||||
SubStorage(SubStorage *sub, s64 o, s64 sz) : m_shared_base_storage(), m_base_storage(sub->m_base_storage), m_offset(o + sub->m_offset), m_size(sz), m_resizable(false) {
|
||||
AMS_ABORT_UNLESS(this->IsValid());
|
||||
AMS_ABORT_UNLESS(this->offset >= 0);
|
||||
AMS_ABORT_UNLESS(this->size >= 0);
|
||||
AMS_ABORT_UNLESS(sub->size >= o + sz);
|
||||
AMS_ABORT_UNLESS(m_offset >= 0);
|
||||
AMS_ABORT_UNLESS(m_size >= 0);
|
||||
AMS_ABORT_UNLESS(sub->m_size >= o + sz);
|
||||
}
|
||||
|
||||
public:
|
||||
void SetResizable(bool rsz) {
|
||||
this->resizable = rsz;
|
||||
m_resizable = rsz;
|
||||
}
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
@@ -77,9 +77,9 @@ namespace ams::fs {
|
||||
|
||||
|
||||
/* Validate arguments and read. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
return this->base_storage->Read(this->offset + offset, buffer, size);
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
return m_base_storage->Read(m_offset + offset, buffer, size);
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override{
|
||||
@@ -90,31 +90,31 @@ namespace ams::fs {
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments and write. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange());
|
||||
return this->base_storage->Write(this->offset + offset, buffer, size);
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
|
||||
return m_base_storage->Write(m_offset + offset, buffer, size);
|
||||
}
|
||||
|
||||
virtual Result Flush() override {
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
return this->base_storage->Flush();
|
||||
return m_base_storage->Flush();
|
||||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override {
|
||||
/* Ensure we're initialized and validate arguments. */
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
R_UNLESS(this->resizable, fs::ResultUnsupportedOperationInSubStorageA());
|
||||
R_UNLESS(IStorage::CheckOffsetAndSize(this->offset, size), fs::ResultInvalidSize());
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
R_UNLESS(m_resizable, fs::ResultUnsupportedOperationInSubStorageA());
|
||||
R_UNLESS(IStorage::CheckOffsetAndSize(m_offset, size), fs::ResultInvalidSize());
|
||||
|
||||
/* Ensure that we're allowed to set size. */
|
||||
s64 cur_size;
|
||||
R_TRY(this->base_storage->GetSize(std::addressof(cur_size)));
|
||||
R_UNLESS(cur_size == this->offset + this->size, fs::ResultUnsupportedOperationInSubStorageB());
|
||||
R_TRY(m_base_storage->GetSize(std::addressof(cur_size)));
|
||||
R_UNLESS(cur_size == m_offset + m_size, fs::ResultUnsupportedOperationInSubStorageB());
|
||||
|
||||
/* Set the size. */
|
||||
R_TRY(this->base_storage->SetSize(this->offset + size));
|
||||
R_TRY(m_base_storage->SetSize(m_offset + size));
|
||||
|
||||
this->size = size;
|
||||
m_size = size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace ams::fs {
|
||||
/* Ensure we're initialized. */
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
|
||||
*out = this->size;
|
||||
*out = m_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace ams::fs {
|
||||
|
||||
/* Validate arguments and operate. */
|
||||
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 m_base_storage->OperateRange(dst, dst_size, op_id, m_offset + offset, size, src, src_size);
|
||||
}
|
||||
|
||||
using IStorage::OperateRange;
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace ams::fs::impl {
|
||||
|
||||
class IdString {
|
||||
private:
|
||||
char buffer[0x20];
|
||||
char m_buffer[0x20];
|
||||
private:
|
||||
const char *ToValueString(int id);
|
||||
public:
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace ams::fssrv::fscreator {
|
||||
NON_COPYABLE(RomFileSystemCreator);
|
||||
NON_MOVEABLE(RomFileSystemCreator);
|
||||
private:
|
||||
MemoryResource *allocator;
|
||||
MemoryResource *m_allocator;
|
||||
public:
|
||||
explicit RomFileSystemCreator(MemoryResource *mr) : allocator(mr) { /* ... */ }
|
||||
explicit RomFileSystemCreator(MemoryResource *mr) : m_allocator(mr) { /* ... */ }
|
||||
|
||||
virtual Result Create(std::shared_ptr<fs::fsa::IFileSystem> *out, std::shared_ptr<fs::IStorage> storage) override;
|
||||
};
|
||||
|
||||
@@ -30,15 +30,15 @@ namespace ams::fssrv::fscreator {
|
||||
NON_COPYABLE(StorageOnNcaCreator);
|
||||
NON_MOVEABLE(StorageOnNcaCreator);
|
||||
private:
|
||||
MemoryResource *allocator;
|
||||
fssystem::IBufferManager * const buffer_manager;
|
||||
const fssystem::NcaCryptoConfiguration &nca_crypto_cfg;
|
||||
bool is_prod;
|
||||
bool is_enabled_program_verification;
|
||||
MemoryResource *m_allocator;
|
||||
fssystem::IBufferManager * const m_buffer_manager;
|
||||
const fssystem::NcaCryptoConfiguration &m_nca_crypto_cfg;
|
||||
bool m_is_prod;
|
||||
bool m_is_enabled_program_verification;
|
||||
private:
|
||||
Result VerifyNcaHeaderSign2(fssystem::NcaReader *nca_reader, fs::IStorage *storage);
|
||||
public:
|
||||
explicit StorageOnNcaCreator(MemoryResource *mr, const fssystem::NcaCryptoConfiguration &cfg, bool prod, fssystem::IBufferManager *bm) : allocator(mr), buffer_manager(bm), nca_crypto_cfg(cfg), is_prod(prod), is_enabled_program_verification(true) {
|
||||
explicit StorageOnNcaCreator(MemoryResource *mr, const fssystem::NcaCryptoConfiguration &cfg, bool prod, fssystem::IBufferManager *bm) : m_allocator(mr), m_buffer_manager(bm), m_nca_crypto_cfg(cfg), m_is_prod(prod), m_is_enabled_program_verification(true) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,17 @@ namespace ams::fssrv {
|
||||
|
||||
class MemoryResourceFromExpHeap : public ams::MemoryResource {
|
||||
private:
|
||||
lmem::HeapHandle heap_handle;
|
||||
lmem::HeapHandle m_heap_handle;
|
||||
public:
|
||||
constexpr explicit MemoryResourceFromExpHeap(lmem::HeapHandle handle) : heap_handle(handle) { /* ... */ }
|
||||
constexpr explicit MemoryResourceFromExpHeap(lmem::HeapHandle handle) : m_heap_handle(handle) { /* ... */ }
|
||||
protected:
|
||||
virtual void *AllocateImpl(size_t size, size_t align) override {
|
||||
return lmem::AllocateFromExpHeap(this->heap_handle, size, static_cast<s32>(align));
|
||||
return lmem::AllocateFromExpHeap(m_heap_handle, size, static_cast<s32>(align));
|
||||
}
|
||||
|
||||
virtual void DeallocateImpl(void *p, size_t size, size_t align) override {
|
||||
AMS_UNUSED(size, align);
|
||||
return lmem::FreeToExpHeap(this->heap_handle, p);
|
||||
return lmem::FreeToExpHeap(m_heap_handle, p);
|
||||
}
|
||||
|
||||
virtual bool IsEqualImpl(const MemoryResource &rhs) const override {
|
||||
@@ -43,24 +43,24 @@ namespace ams::fssrv {
|
||||
|
||||
class PeakCheckableMemoryResourceFromExpHeap : public ams::MemoryResource {
|
||||
private:
|
||||
lmem::HeapHandle heap_handle;
|
||||
os::SdkMutex mutex;
|
||||
size_t peak_free_size;
|
||||
size_t current_free_size;
|
||||
lmem::HeapHandle m_heap_handle;
|
||||
os::SdkMutex m_mutex;
|
||||
size_t m_peak_free_size;
|
||||
size_t m_current_free_size;
|
||||
public:
|
||||
constexpr explicit PeakCheckableMemoryResourceFromExpHeap(size_t heap_size) : heap_handle(nullptr), mutex(), peak_free_size(heap_size), current_free_size(heap_size) { /* ... */ }
|
||||
constexpr explicit PeakCheckableMemoryResourceFromExpHeap(size_t heap_size) : m_heap_handle(nullptr), m_mutex(), m_peak_free_size(heap_size), m_current_free_size(heap_size) { /* ... */ }
|
||||
|
||||
void SetHeapHandle(lmem::HeapHandle handle) {
|
||||
this->heap_handle = handle;
|
||||
m_heap_handle = handle;
|
||||
}
|
||||
|
||||
size_t GetPeakFreeSize() const { return this->peak_free_size; }
|
||||
size_t GetCurrentFreeSize() const { return this->current_free_size; }
|
||||
size_t GetPeakFreeSize() const { return m_peak_free_size; }
|
||||
size_t GetCurrentFreeSize() const { return m_current_free_size; }
|
||||
|
||||
void ClearPeak() { this->peak_free_size = this->current_free_size; }
|
||||
void ClearPeak() { m_peak_free_size = m_current_free_size; }
|
||||
|
||||
std::scoped_lock<os::SdkMutex> GetScopedLock() {
|
||||
return std::scoped_lock(this->mutex);
|
||||
return std::scoped_lock(m_mutex);
|
||||
}
|
||||
|
||||
void OnAllocate(void *p, size_t size);
|
||||
|
||||
@@ -27,17 +27,17 @@ namespace ams::fssrv {
|
||||
|
||||
class MemoryResourceFromStandardAllocator : public ams::MemoryResource {
|
||||
private:
|
||||
mem::StandardAllocator *allocator;
|
||||
os::SdkMutex mutex;
|
||||
size_t peak_free_size;
|
||||
size_t current_free_size;
|
||||
size_t peak_allocated_size;
|
||||
mem::StandardAllocator *m_allocator;
|
||||
os::SdkMutex m_mutex;
|
||||
size_t m_peak_free_size;
|
||||
size_t m_current_free_size;
|
||||
size_t m_peak_allocated_size;
|
||||
public:
|
||||
explicit MemoryResourceFromStandardAllocator(mem::StandardAllocator *allocator);
|
||||
public:
|
||||
size_t GetPeakFreeSize() const { return this->peak_free_size; }
|
||||
size_t GetCurrentFreeSize() const { return this->current_free_size; }
|
||||
size_t GetPeakAllocatedSize() const { return this->peak_allocated_size; }
|
||||
size_t GetPeakFreeSize() const { return m_peak_free_size; }
|
||||
size_t GetCurrentFreeSize() const { return m_current_free_size; }
|
||||
size_t GetPeakAllocatedSize() const { return m_peak_allocated_size; }
|
||||
|
||||
void ClearPeak();
|
||||
protected:
|
||||
|
||||
@@ -33,34 +33,34 @@ namespace ams::fssrv {
|
||||
private:
|
||||
using Buffer = std::unique_ptr<char[], fs::impl::Deleter>;
|
||||
private:
|
||||
Buffer buffer;
|
||||
const char *path;
|
||||
Result result;
|
||||
Buffer m_buffer;
|
||||
const char *m_path;
|
||||
Result m_result;
|
||||
private:
|
||||
static Result Normalize(const char **out_path, Buffer *out_buf, const char *path, bool preserve_unc, bool preserve_tail_sep, bool has_mount_name);
|
||||
public:
|
||||
/* TODO: Remove non-option constructor. */
|
||||
explicit PathNormalizer(const char *p) : buffer(), path(nullptr), result(ResultSuccess()) {
|
||||
this->result = Normalize(std::addressof(this->path), std::addressof(this->buffer), p, false, false, false);
|
||||
explicit PathNormalizer(const char *p) : m_buffer(), m_path(nullptr), m_result(ResultSuccess()) {
|
||||
m_result = Normalize(std::addressof(m_path), std::addressof(m_buffer), p, false, false, false);
|
||||
}
|
||||
|
||||
PathNormalizer(const char *p, u32 option) : buffer(), path(nullptr), result(ResultSuccess()) {
|
||||
PathNormalizer(const char *p, u32 option) : m_buffer(), m_path(nullptr), m_result(ResultSuccess()) {
|
||||
if ((option & Option_AcceptEmpty) && p[0] == '\x00') {
|
||||
this->path = path;
|
||||
m_path = p;
|
||||
} else {
|
||||
const bool preserve_unc = (option & Option_PreserveUnc);
|
||||
const bool preserve_tail_sep = (option & Option_PreserveTailSeparator);
|
||||
const bool has_mount_name = (option & Option_HasMountName);
|
||||
this->result = Normalize(std::addressof(this->path), std::addressof(this->buffer), p, preserve_unc, preserve_tail_sep, has_mount_name);
|
||||
m_result = Normalize(std::addressof(m_path), std::addressof(m_buffer), p, preserve_unc, preserve_tail_sep, has_mount_name);
|
||||
}
|
||||
}
|
||||
|
||||
Result GetResult() const {
|
||||
return this->result;
|
||||
return m_result;
|
||||
}
|
||||
|
||||
const char *GetPath() const {
|
||||
return this->path;
|
||||
return m_path;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ namespace ams::fssrv::impl {
|
||||
class FileInterfaceAdapter {
|
||||
NON_COPYABLE(FileInterfaceAdapter);
|
||||
private:
|
||||
ams::sf::SharedPointer<FileSystemInterfaceAdapter> parent_filesystem;
|
||||
std::unique_ptr<fs::fsa::IFile> base_file;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> open_count_semaphore;
|
||||
ams::sf::SharedPointer<FileSystemInterfaceAdapter> m_parent_filesystem;
|
||||
std::unique_ptr<fs::fsa::IFile> m_base_file;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> m_open_count_semaphore;
|
||||
public:
|
||||
FileInterfaceAdapter(std::unique_ptr<fs::fsa::IFile> &&file, FileSystemInterfaceAdapter *parent, util::unique_lock<fssystem::SemaphoreAdapter> &&sema);
|
||||
~FileInterfaceAdapter();
|
||||
@@ -63,9 +63,9 @@ namespace ams::fssrv::impl {
|
||||
class DirectoryInterfaceAdapter {
|
||||
NON_COPYABLE(DirectoryInterfaceAdapter);
|
||||
private:
|
||||
ams::sf::SharedPointer<FileSystemInterfaceAdapter> parent_filesystem;
|
||||
std::unique_ptr<fs::fsa::IDirectory> base_dir;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> open_count_semaphore;
|
||||
ams::sf::SharedPointer<FileSystemInterfaceAdapter> m_parent_filesystem;
|
||||
std::unique_ptr<fs::fsa::IDirectory> m_base_dir;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> m_open_count_semaphore;
|
||||
public:
|
||||
DirectoryInterfaceAdapter(std::unique_ptr<fs::fsa::IDirectory> &&dir, FileSystemInterfaceAdapter *parent, util::unique_lock<fssystem::SemaphoreAdapter> &&sema);
|
||||
~DirectoryInterfaceAdapter();
|
||||
@@ -79,11 +79,11 @@ namespace ams::fssrv::impl {
|
||||
class FileSystemInterfaceAdapter : public ams::sf::ISharedObject {
|
||||
NON_COPYABLE(FileSystemInterfaceAdapter);
|
||||
private:
|
||||
std::shared_ptr<fs::fsa::IFileSystem> base_fs;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> mount_count_semaphore;
|
||||
os::ReaderWriterLock invalidation_lock;
|
||||
bool open_count_limited;
|
||||
bool deep_retry_enabled = false;
|
||||
std::shared_ptr<fs::fsa::IFileSystem> m_base_fs;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> m_mount_count_semaphore;
|
||||
os::ReaderWriterLock m_invalidation_lock;
|
||||
bool m_open_count_limited;
|
||||
bool m_deep_retry_enabled = false;
|
||||
public:
|
||||
FileSystemInterfaceAdapter(std::shared_ptr<fs::fsa::IFileSystem> &&fs, bool open_limited);
|
||||
/* TODO: Other constructors. */
|
||||
|
||||
@@ -31,11 +31,11 @@ namespace ams::fssrv::impl {
|
||||
NON_COPYABLE(StorageInterfaceAdapter);
|
||||
private:
|
||||
/* TODO: Nintendo uses fssystem::AsynchronousAccessStorage here. */
|
||||
std::shared_ptr<fs::IStorage> base_storage;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> open_count_semaphore;
|
||||
os::ReaderWriterLock invalidation_lock;
|
||||
std::shared_ptr<fs::IStorage> m_base_storage;
|
||||
util::unique_lock<fssystem::SemaphoreAdapter> m_open_count_semaphore;
|
||||
os::ReaderWriterLock m_invalidation_lock;
|
||||
/* TODO: DataStorageContext. */
|
||||
bool deep_retry_enabled = false;
|
||||
bool m_deep_retry_enabled = false;
|
||||
public:
|
||||
StorageInterfaceAdapter(fs::IStorage *storage);
|
||||
StorageInterfaceAdapter(std::unique_ptr<fs::IStorage> storage);
|
||||
|
||||
@@ -56,13 +56,13 @@ namespace ams::fssystem::buffers {
|
||||
|
||||
class BufferManagerContext {
|
||||
private:
|
||||
bool needs_blocking;
|
||||
bool m_needs_blocking;
|
||||
public:
|
||||
constexpr BufferManagerContext() : needs_blocking(false) { /* ... */ }
|
||||
constexpr BufferManagerContext() : m_needs_blocking(false) { /* ... */ }
|
||||
public:
|
||||
bool IsNeedBlocking() const { return this->needs_blocking; }
|
||||
bool IsNeedBlocking() const { return m_needs_blocking; }
|
||||
|
||||
void SetNeedBlocking(bool need) { this->needs_blocking = need; }
|
||||
void SetNeedBlocking(bool need) { m_needs_blocking = need; }
|
||||
};
|
||||
|
||||
void RegisterBufferManagerContext(const BufferManagerContext *context);
|
||||
@@ -71,19 +71,19 @@ namespace ams::fssystem::buffers {
|
||||
|
||||
class ScopedBufferManagerContextRegistration {
|
||||
private:
|
||||
BufferManagerContext cur_context;
|
||||
const BufferManagerContext *old_context;
|
||||
BufferManagerContext m_cur_context;
|
||||
const BufferManagerContext *m_old_context;
|
||||
public:
|
||||
ALWAYS_INLINE explicit ScopedBufferManagerContextRegistration() {
|
||||
this->old_context = GetBufferManagerContext();
|
||||
if (this->old_context != nullptr) {
|
||||
this->cur_context = *this->old_context;
|
||||
m_old_context = GetBufferManagerContext();
|
||||
if (m_old_context != nullptr) {
|
||||
m_cur_context = *m_old_context;
|
||||
}
|
||||
RegisterBufferManagerContext(std::addressof(this->cur_context));
|
||||
RegisterBufferManagerContext(std::addressof(m_cur_context));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ~ScopedBufferManagerContextRegistration() {
|
||||
RegisterBufferManagerContext(this->old_context);
|
||||
RegisterBufferManagerContext(m_old_context);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -37,31 +37,31 @@ namespace ams::fssystem {
|
||||
NON_COPYABLE(PageList);
|
||||
NON_MOVEABLE(PageList);
|
||||
private:
|
||||
PageEntry *first_page_entry;
|
||||
PageEntry *last_page_entry;
|
||||
s32 entry_count;
|
||||
PageEntry *m_first_page_entry;
|
||||
PageEntry *m_last_page_entry;
|
||||
s32 m_entry_count;
|
||||
public:
|
||||
constexpr PageList() : first_page_entry(), last_page_entry(), entry_count() { /* ... */ }
|
||||
constexpr PageList() : m_first_page_entry(), m_last_page_entry(), m_entry_count() { /* ... */ }
|
||||
|
||||
constexpr bool IsEmpty() const { return this->entry_count == 0; }
|
||||
constexpr s32 GetSize() const { return this->entry_count; }
|
||||
constexpr bool IsEmpty() const { return m_entry_count == 0; }
|
||||
constexpr s32 GetSize() const { return m_entry_count; }
|
||||
|
||||
constexpr const PageEntry *GetFront() const { return this->first_page_entry; }
|
||||
constexpr const PageEntry *GetFront() const { return m_first_page_entry; }
|
||||
public:
|
||||
PageEntry *PopFront();
|
||||
void PushBack(PageEntry *page_entry);
|
||||
bool Remove(PageEntry *page_entry);
|
||||
};
|
||||
private:
|
||||
size_t block_size;
|
||||
s32 order_max;
|
||||
uintptr_t heap_start;
|
||||
size_t heap_size;
|
||||
size_t m_block_size;
|
||||
s32 m_order_max;
|
||||
uintptr_t m_heap_start;
|
||||
size_t m_heap_size;
|
||||
|
||||
PageList *free_lists;
|
||||
size_t total_free_size;
|
||||
PageList *external_free_lists;
|
||||
std::unique_ptr<PageList[]> internal_free_lists;
|
||||
PageList *m_free_lists;
|
||||
size_t m_total_free_size;
|
||||
PageList *m_external_free_lists;
|
||||
std::unique_ptr<PageList[]> m_internal_free_lists;
|
||||
public:
|
||||
static constexpr s32 GetBlockCountFromOrder(s32 order) {
|
||||
AMS_ASSERT(0 <= order);
|
||||
@@ -87,7 +87,7 @@ namespace ams::fssystem {
|
||||
}
|
||||
|
||||
public:
|
||||
constexpr FileSystemBuddyHeap() : block_size(), order_max(), heap_start(), heap_size(), free_lists(), total_free_size(), external_free_lists(), internal_free_lists() { /* ... */ }
|
||||
constexpr FileSystemBuddyHeap() : m_block_size(), m_order_max(), m_heap_start(), m_heap_size(), m_free_lists(), m_total_free_size(), m_external_free_lists(), m_internal_free_lists() { /* ... */ }
|
||||
|
||||
Result Initialize(uintptr_t address, size_t size, size_t block_size, s32 order_max);
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace ams::fssystem {
|
||||
AMS_UNUSED(work_size);
|
||||
|
||||
const auto aligned_work = util::AlignUp(reinterpret_cast<uintptr_t>(work), alignof(PageList));
|
||||
this->external_free_lists = reinterpret_cast<PageList *>(aligned_work);
|
||||
m_external_free_lists = reinterpret_cast<PageList *>(aligned_work);
|
||||
return this->Initialize(address, size, block_size, order_max);
|
||||
}
|
||||
|
||||
@@ -118,34 +118,34 @@ namespace ams::fssystem {
|
||||
void Dump() const;
|
||||
|
||||
s32 GetOrderFromBytes(size_t size) const {
|
||||
AMS_ASSERT(this->free_lists != nullptr);
|
||||
AMS_ASSERT(m_free_lists != nullptr);
|
||||
return this->GetOrderFromBlockCount(this->GetBlockCountFromSize(size));
|
||||
}
|
||||
|
||||
size_t GetBytesFromOrder(s32 order) const {
|
||||
AMS_ASSERT(this->free_lists != nullptr);
|
||||
AMS_ASSERT(m_free_lists != nullptr);
|
||||
AMS_ASSERT(0 <= order);
|
||||
AMS_ASSERT(order < this->GetOrderMax());
|
||||
return (this->GetBlockSize() << order);
|
||||
}
|
||||
|
||||
s32 GetOrderMax() const {
|
||||
AMS_ASSERT(this->free_lists != nullptr);
|
||||
return this->order_max;
|
||||
AMS_ASSERT(m_free_lists != nullptr);
|
||||
return m_order_max;
|
||||
}
|
||||
|
||||
size_t GetBlockSize() const {
|
||||
AMS_ASSERT(this->free_lists != nullptr);
|
||||
return this->block_size;
|
||||
AMS_ASSERT(m_free_lists != nullptr);
|
||||
return m_block_size;
|
||||
}
|
||||
|
||||
s32 GetPageBlockCountMax() const {
|
||||
AMS_ASSERT(this->free_lists != nullptr);
|
||||
AMS_ASSERT(m_free_lists != nullptr);
|
||||
return 1 << this->GetOrderMax();
|
||||
}
|
||||
|
||||
size_t GetPageSizeMax() const {
|
||||
AMS_ASSERT(this->free_lists != nullptr);
|
||||
AMS_ASSERT(m_free_lists != nullptr);
|
||||
return this->GetPageBlockCountMax() * this->GetBlockSize();
|
||||
}
|
||||
private:
|
||||
@@ -163,24 +163,24 @@ namespace ams::fssystem {
|
||||
|
||||
uintptr_t GetAddressFromPageEntry(const PageEntry &page_entry) const {
|
||||
const uintptr_t address = reinterpret_cast<uintptr_t>(std::addressof(page_entry));
|
||||
AMS_ASSERT(this->heap_start <= address);
|
||||
AMS_ASSERT(address < this->heap_start + this->heap_size);
|
||||
AMS_ASSERT(util::IsAligned(address - this->heap_start, this->GetBlockSize()));
|
||||
AMS_ASSERT(m_heap_start <= address);
|
||||
AMS_ASSERT(address < m_heap_start + m_heap_size);
|
||||
AMS_ASSERT(util::IsAligned(address - m_heap_start, this->GetBlockSize()));
|
||||
return address;
|
||||
}
|
||||
|
||||
PageEntry *GetPageEntryFromAddress(uintptr_t address) const {
|
||||
AMS_ASSERT(this->heap_start <= address);
|
||||
AMS_ASSERT(address < this->heap_start + this->heap_size);
|
||||
return reinterpret_cast<PageEntry *>(this->heap_start + util::AlignDown(address - this->heap_start, this->GetBlockSize()));
|
||||
AMS_ASSERT(m_heap_start <= address);
|
||||
AMS_ASSERT(address < m_heap_start + m_heap_size);
|
||||
return reinterpret_cast<PageEntry *>(m_heap_start + util::AlignDown(address - m_heap_start, this->GetBlockSize()));
|
||||
}
|
||||
|
||||
s32 GetIndexFromPageEntry(const PageEntry &page_entry) const {
|
||||
const uintptr_t address = reinterpret_cast<uintptr_t>(std::addressof(page_entry));
|
||||
AMS_ASSERT(this->heap_start <= address);
|
||||
AMS_ASSERT(address < this->heap_start + this->heap_size);
|
||||
AMS_ASSERT(util::IsAligned(address - this->heap_start, this->GetBlockSize()));
|
||||
return static_cast<s32>((address - this->heap_start) / this->GetBlockSize());
|
||||
AMS_ASSERT(m_heap_start <= address);
|
||||
AMS_ASSERT(address < m_heap_start + m_heap_size);
|
||||
AMS_ASSERT(util::IsAligned(address - m_heap_start, this->GetBlockSize()));
|
||||
return static_cast<s32>((address - m_heap_start) / this->GetBlockSize());
|
||||
}
|
||||
|
||||
bool IsAlignedToOrder(const PageEntry *page_entry, s32 order) const {
|
||||
|
||||
@@ -34,32 +34,32 @@ namespace ams::fssystem {
|
||||
private:
|
||||
class Entry {
|
||||
private:
|
||||
CacheHandle handle;
|
||||
uintptr_t address;
|
||||
size_t size;
|
||||
BufferAttribute attr;
|
||||
CacheHandle m_handle;
|
||||
uintptr_t m_address;
|
||||
size_t m_size;
|
||||
BufferAttribute m_attr;
|
||||
public:
|
||||
constexpr void Initialize(CacheHandle h, uintptr_t a, size_t sz, BufferAttribute t) {
|
||||
this->handle = h;
|
||||
this->address = a;
|
||||
this->size = sz;
|
||||
this->attr = t;
|
||||
m_handle = h;
|
||||
m_address = a;
|
||||
m_size = sz;
|
||||
m_attr = t;
|
||||
}
|
||||
|
||||
constexpr CacheHandle GetHandle() const {
|
||||
return this->handle;
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
constexpr uintptr_t GetAddress() const {
|
||||
return this->address;
|
||||
return m_address;
|
||||
}
|
||||
|
||||
constexpr size_t GetSize() const {
|
||||
return this->size;
|
||||
return m_size;
|
||||
}
|
||||
|
||||
constexpr BufferAttribute GetBufferAttribute() const {
|
||||
return this->attr;
|
||||
return m_attr;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -67,41 +67,41 @@ namespace ams::fssystem {
|
||||
NON_COPYABLE(AttrInfo);
|
||||
NON_MOVEABLE(AttrInfo);
|
||||
private:
|
||||
s32 level;
|
||||
s32 cache_count;
|
||||
size_t cache_size;
|
||||
s32 m_level;
|
||||
s32 m_cache_count;
|
||||
size_t m_cache_size;
|
||||
public:
|
||||
constexpr AttrInfo(s32 l, s32 cc, size_t cs) : level(l), cache_count(cc), cache_size(cs) {
|
||||
constexpr AttrInfo(s32 l, s32 cc, size_t cs) : m_level(l), m_cache_count(cc), m_cache_size(cs) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
constexpr s32 GetLevel() const {
|
||||
return this->level;
|
||||
return m_level;
|
||||
}
|
||||
|
||||
constexpr s32 GetCacheCount() const {
|
||||
return this->cache_count;
|
||||
return m_cache_count;
|
||||
}
|
||||
|
||||
constexpr void IncrementCacheCount() {
|
||||
++this->cache_count;
|
||||
++m_cache_count;
|
||||
}
|
||||
|
||||
constexpr void DecrementCacheCount() {
|
||||
--this->cache_count;
|
||||
--m_cache_count;
|
||||
}
|
||||
|
||||
constexpr size_t GetCacheSize() const {
|
||||
return this->cache_size;
|
||||
return m_cache_size;
|
||||
}
|
||||
|
||||
constexpr void AddCacheSize(size_t diff) {
|
||||
this->cache_size += diff;
|
||||
m_cache_size += diff;
|
||||
}
|
||||
|
||||
constexpr void SubtractCacheSize(size_t diff) {
|
||||
AMS_ASSERT(this->cache_size >= diff);
|
||||
this->cache_size -= diff;
|
||||
AMS_ASSERT(m_cache_size >= diff);
|
||||
m_cache_size -= diff;
|
||||
}
|
||||
|
||||
using Newable::operator new;
|
||||
@@ -114,19 +114,19 @@ namespace ams::fssystem {
|
||||
using AttrListTraits = util::IntrusiveListBaseTraits<AttrInfo>;
|
||||
using AttrList = typename AttrListTraits::ListType;
|
||||
private:
|
||||
std::unique_ptr<char[], ::ams::fs::impl::Deleter> internal_entry_buffer;
|
||||
char *external_entry_buffer;
|
||||
size_t entry_buffer_size;
|
||||
Entry *entries;
|
||||
s32 entry_count;
|
||||
s32 entry_count_max;
|
||||
AttrList attr_list;
|
||||
char *external_attr_info_buffer;
|
||||
s32 external_attr_info_count;
|
||||
s32 cache_count_min;
|
||||
size_t cache_size_min;
|
||||
size_t total_cache_size;
|
||||
CacheHandle current_handle;
|
||||
std::unique_ptr<char[], ::ams::fs::impl::Deleter> m_internal_entry_buffer;
|
||||
char *m_external_entry_buffer;
|
||||
size_t m_entry_buffer_size;
|
||||
Entry *m_entries;
|
||||
s32 m_entry_count;
|
||||
s32 m_entry_count_max;
|
||||
AttrList m_attr_list;
|
||||
char *m_external_attr_info_buffer;
|
||||
s32 m_external_attr_info_count;
|
||||
s32 m_cache_count_min;
|
||||
size_t m_cache_size_min;
|
||||
size_t m_total_cache_size;
|
||||
CacheHandle m_current_handle;
|
||||
public:
|
||||
static constexpr size_t QueryWorkBufferSize(s32 max_cache_count) {
|
||||
AMS_ASSERT(max_cache_count > 0);
|
||||
@@ -135,7 +135,7 @@ namespace ams::fssystem {
|
||||
return util::AlignUp(entry_size + attr_list_size + alignof(Entry) + alignof(AttrInfo), 8);
|
||||
}
|
||||
public:
|
||||
CacheHandleTable() : internal_entry_buffer(), external_entry_buffer(), entry_buffer_size(), entries(), entry_count(), entry_count_max(), attr_list(), external_attr_info_buffer(), external_attr_info_count(), cache_count_min(), cache_size_min(), total_cache_size(), current_handle() {
|
||||
CacheHandleTable() : m_internal_entry_buffer(), m_external_entry_buffer(), m_entry_buffer_size(), m_entries(), m_entry_count(), m_entry_count_max(), m_attr_list(), m_external_attr_info_buffer(), m_external_attr_info_count(), m_cache_count_min(), m_cache_size_min(), m_total_cache_size(), m_current_handle() {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -146,13 +146,13 @@ namespace ams::fssystem {
|
||||
Result Initialize(s32 max_cache_count);
|
||||
Result Initialize(s32 max_cache_count, void *work, size_t work_size) {
|
||||
const auto aligned_entry_buf = util::AlignUp(reinterpret_cast<uintptr_t>(work), alignof(Entry));
|
||||
this->external_entry_buffer = reinterpret_cast<char *>(aligned_entry_buf);
|
||||
this->entry_buffer_size = sizeof(Entry) * max_cache_count;
|
||||
m_external_entry_buffer = reinterpret_cast<char *>(aligned_entry_buf);
|
||||
m_entry_buffer_size = sizeof(Entry) * max_cache_count;
|
||||
|
||||
const auto aligned_attr_info_buf = util::AlignUp(reinterpret_cast<uintptr_t>(this->external_entry_buffer + this->entry_buffer_size), alignof(AttrInfo));
|
||||
const auto aligned_attr_info_buf = util::AlignUp(reinterpret_cast<uintptr_t>(m_external_entry_buffer + m_entry_buffer_size), alignof(AttrInfo));
|
||||
const auto work_end = reinterpret_cast<uintptr_t>(work) + work_size;
|
||||
this->external_attr_info_buffer = reinterpret_cast<char *>(aligned_attr_info_buf);
|
||||
this->external_attr_info_count = static_cast<s32>((work_end - aligned_attr_info_buf) / sizeof(AttrInfo));
|
||||
m_external_attr_info_buffer = reinterpret_cast<char *>(aligned_attr_info_buf);
|
||||
m_external_attr_info_count = static_cast<s32>((work_end - aligned_attr_info_buf) / sizeof(AttrInfo));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
@@ -179,22 +179,22 @@ namespace ams::fssystem {
|
||||
|
||||
s32 GetCacheCountMin(const BufferAttribute &attr) {
|
||||
AMS_UNUSED(attr);
|
||||
return this->cache_count_min;
|
||||
return m_cache_count_min;
|
||||
}
|
||||
|
||||
size_t GetCacheSizeMin(const BufferAttribute &attr) {
|
||||
AMS_UNUSED(attr);
|
||||
return this->cache_size_min;
|
||||
return m_cache_size_min;
|
||||
}
|
||||
};
|
||||
private:
|
||||
BuddyHeap buddy_heap;
|
||||
CacheHandleTable cache_handle_table;
|
||||
size_t total_size;
|
||||
size_t peak_free_size;
|
||||
size_t peak_total_allocatable_size;
|
||||
size_t retried_count;
|
||||
mutable os::SdkRecursiveMutex mutex;
|
||||
BuddyHeap m_buddy_heap;
|
||||
CacheHandleTable m_cache_handle_table;
|
||||
size_t m_total_size;
|
||||
size_t m_peak_free_size;
|
||||
size_t m_peak_total_allocatable_size;
|
||||
size_t m_retried_count;
|
||||
mutable os::SdkRecursiveMutex m_mutex;
|
||||
public:
|
||||
static constexpr size_t QueryWorkBufferSize(s32 max_cache_count, s32 max_order) {
|
||||
const auto buddy_size = FileSystemBuddyHeap::QueryWorkBufferSize(max_order);
|
||||
@@ -202,30 +202,30 @@ namespace ams::fssystem {
|
||||
return buddy_size + table_size;
|
||||
}
|
||||
public:
|
||||
FileSystemBufferManager() : total_size(), peak_free_size(), peak_total_allocatable_size(), retried_count(), mutex() { /* ... */ }
|
||||
FileSystemBufferManager() : m_total_size(), m_peak_free_size(), m_peak_total_allocatable_size(), m_retried_count(), m_mutex() { /* ... */ }
|
||||
|
||||
virtual ~FileSystemBufferManager() { /* ... */ }
|
||||
|
||||
Result Initialize(s32 max_cache_count, uintptr_t address, size_t buffer_size, size_t block_size) {
|
||||
AMS_ASSERT(buffer_size > 0);
|
||||
R_TRY(this->cache_handle_table.Initialize(max_cache_count));
|
||||
R_TRY(this->buddy_heap.Initialize(address, buffer_size, block_size));
|
||||
R_TRY(m_cache_handle_table.Initialize(max_cache_count));
|
||||
R_TRY(m_buddy_heap.Initialize(address, buffer_size, block_size));
|
||||
|
||||
this->total_size = this->buddy_heap.GetTotalFreeSize();
|
||||
this->peak_free_size = this->total_size;
|
||||
this->peak_total_allocatable_size = this->total_size;
|
||||
m_total_size = m_buddy_heap.GetTotalFreeSize();
|
||||
m_peak_free_size = m_total_size;
|
||||
m_peak_total_allocatable_size = m_total_size;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result Initialize(s32 max_cache_count, uintptr_t address, size_t buffer_size, size_t block_size, s32 max_order) {
|
||||
AMS_ASSERT(buffer_size > 0);
|
||||
R_TRY(this->cache_handle_table.Initialize(max_cache_count));
|
||||
R_TRY(this->buddy_heap.Initialize(address, buffer_size, block_size, max_order));
|
||||
R_TRY(m_cache_handle_table.Initialize(max_cache_count));
|
||||
R_TRY(m_buddy_heap.Initialize(address, buffer_size, block_size, max_order));
|
||||
|
||||
this->total_size = this->buddy_heap.GetTotalFreeSize();
|
||||
this->peak_free_size = this->total_size;
|
||||
this->peak_total_allocatable_size = this->total_size;
|
||||
m_total_size = m_buddy_heap.GetTotalFreeSize();
|
||||
m_peak_free_size = m_total_size;
|
||||
m_peak_total_allocatable_size = m_total_size;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
@@ -237,12 +237,12 @@ namespace ams::fssystem {
|
||||
const auto table_buffer = static_cast<char *>(work);
|
||||
const auto buddy_buffer = table_buffer + table_size;
|
||||
|
||||
R_TRY(this->cache_handle_table.Initialize(max_cache_count, table_buffer, table_size));
|
||||
R_TRY(this->buddy_heap.Initialize(address, buffer_size, block_size, buddy_buffer, buddy_size));
|
||||
R_TRY(m_cache_handle_table.Initialize(max_cache_count, table_buffer, table_size));
|
||||
R_TRY(m_buddy_heap.Initialize(address, buffer_size, block_size, buddy_buffer, buddy_size));
|
||||
|
||||
this->total_size = this->buddy_heap.GetTotalFreeSize();
|
||||
this->peak_free_size = this->total_size;
|
||||
this->peak_total_allocatable_size = this->total_size;
|
||||
m_total_size = m_buddy_heap.GetTotalFreeSize();
|
||||
m_peak_free_size = m_total_size;
|
||||
m_peak_total_allocatable_size = m_total_size;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
@@ -254,19 +254,19 @@ namespace ams::fssystem {
|
||||
const auto table_buffer = static_cast<char *>(work);
|
||||
const auto buddy_buffer = table_buffer + table_size;
|
||||
|
||||
R_TRY(this->cache_handle_table.Initialize(max_cache_count, table_buffer, table_size));
|
||||
R_TRY(this->buddy_heap.Initialize(address, buffer_size, block_size, max_order, buddy_buffer, buddy_size));
|
||||
R_TRY(m_cache_handle_table.Initialize(max_cache_count, table_buffer, table_size));
|
||||
R_TRY(m_buddy_heap.Initialize(address, buffer_size, block_size, max_order, buddy_buffer, buddy_size));
|
||||
|
||||
this->total_size = this->buddy_heap.GetTotalFreeSize();
|
||||
this->peak_free_size = this->total_size;
|
||||
this->peak_total_allocatable_size = this->total_size;
|
||||
m_total_size = m_buddy_heap.GetTotalFreeSize();
|
||||
m_peak_free_size = m_total_size;
|
||||
m_peak_total_allocatable_size = m_total_size;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
this->buddy_heap.Finalize();
|
||||
this->cache_handle_table.Finalize();
|
||||
m_buddy_heap.Finalize();
|
||||
m_cache_handle_table.Finalize();
|
||||
}
|
||||
private:
|
||||
virtual const std::pair<uintptr_t, size_t> AllocateBufferImpl(size_t size, const BufferAttribute &attr) override;
|
||||
|
||||
@@ -22,12 +22,12 @@ namespace ams::fssystem {
|
||||
public:
|
||||
class BufferAttribute {
|
||||
private:
|
||||
s32 level;
|
||||
s32 m_level;
|
||||
public:
|
||||
constexpr BufferAttribute() : level(0) { /* ... */ }
|
||||
constexpr explicit BufferAttribute(s32 l) : level(l) { /* ... */ }
|
||||
constexpr BufferAttribute() : m_level(0) { /* ... */ }
|
||||
constexpr explicit BufferAttribute(s32 l) : m_level(l) { /* ... */ }
|
||||
|
||||
constexpr s32 GetLevel() const { return this->level; }
|
||||
constexpr s32 GetLevel() const { return m_level; }
|
||||
};
|
||||
|
||||
using CacheHandle = s64;
|
||||
|
||||
@@ -74,27 +74,27 @@ namespace ams::fssystem {
|
||||
static Result CreateExternalDecryptor(std::unique_ptr<IDecryptor> *out, DecryptFunction func, s32 key_index);
|
||||
static Result CreateSoftwareDecryptor(std::unique_ptr<IDecryptor> *out);
|
||||
private:
|
||||
BucketTree table;
|
||||
fs::SubStorage data_storage;
|
||||
u8 key[KeySize];
|
||||
u32 secure_value;
|
||||
s64 counter_offset;
|
||||
std::unique_ptr<IDecryptor> decryptor;
|
||||
BucketTree m_table;
|
||||
fs::SubStorage m_data_storage;
|
||||
u8 m_key[KeySize];
|
||||
u32 m_secure_value;
|
||||
s64 m_counter_offset;
|
||||
std::unique_ptr<IDecryptor> m_decryptor;
|
||||
public:
|
||||
AesCtrCounterExtendedStorage() : table(), data_storage(), secure_value(), counter_offset(), decryptor() { /* ... */ }
|
||||
AesCtrCounterExtendedStorage() : m_table(), m_data_storage(), m_secure_value(), m_counter_offset(), m_decryptor() { /* ... */ }
|
||||
virtual ~AesCtrCounterExtendedStorage() { this->Finalize(); }
|
||||
|
||||
Result Initialize(IAllocator *allocator, const void *key, size_t key_size, u32 secure_value, s64 counter_offset, fs::SubStorage data_storage, fs::SubStorage node_storage, fs::SubStorage entry_storage, s32 entry_count, std::unique_ptr<IDecryptor> &&decryptor);
|
||||
void Finalize();
|
||||
|
||||
bool IsInitialized() const { return this->table.IsInitialized(); }
|
||||
bool IsInitialized() const { return m_table.IsInitialized(); }
|
||||
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
||||
virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override;
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
*out = this->table.GetSize();
|
||||
*out = m_table.GetSize();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace ams::fssystem {
|
||||
static constexpr size_t KeySize = crypto::Aes128CtrEncryptor::KeySize;
|
||||
static constexpr size_t IvSize = crypto::Aes128CtrEncryptor::IvSize;
|
||||
private:
|
||||
IStorage * const base_storage;
|
||||
char key[KeySize];
|
||||
char iv[IvSize];
|
||||
IStorage * const m_base_storage;
|
||||
char m_key[KeySize];
|
||||
char m_iv[IvSize];
|
||||
public:
|
||||
static void MakeIv(void *dst, size_t dst_size, u64 upper, s64 offset);
|
||||
public:
|
||||
|
||||
@@ -29,11 +29,11 @@ namespace ams::fssystem {
|
||||
static constexpr size_t KeySize = crypto::Aes128XtsEncryptor::KeySize;
|
||||
static constexpr size_t IvSize = crypto::Aes128XtsEncryptor::IvSize;
|
||||
private:
|
||||
IStorage * const base_storage;
|
||||
char key[2][KeySize];
|
||||
char iv[IvSize];
|
||||
const size_t block_size;
|
||||
os::SdkMutex mutex;
|
||||
IStorage * const m_base_storage;
|
||||
char m_key[2][KeySize];
|
||||
char m_iv[IvSize];
|
||||
const size_t m_block_size;
|
||||
os::SdkMutex m_mutex;
|
||||
public:
|
||||
AesXtsStorage(IStorage *base, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, size_t block_size);
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ namespace ams::fssystem {
|
||||
static_assert(util::IsPowerOfTwo(DataAlign));
|
||||
static_assert(util::IsPowerOfTwo(BufferAlign));
|
||||
private:
|
||||
std::shared_ptr<fs::IStorage> shared_base_storage;
|
||||
fs::IStorage * const base_storage;
|
||||
s64 base_storage_size;
|
||||
bool is_base_storage_size_dirty;
|
||||
std::shared_ptr<fs::IStorage> m_shared_base_storage;
|
||||
fs::IStorage * const m_base_storage;
|
||||
s64 m_base_storage_size;
|
||||
bool m_is_base_storage_size_dirty;
|
||||
public:
|
||||
explicit AlignmentMatchingStorage(fs::IStorage *bs) : base_storage(bs), is_base_storage_size_dirty(true) {
|
||||
explicit AlignmentMatchingStorage(fs::IStorage *bs) : m_base_storage(bs), m_is_base_storage_size_dirty(true) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
explicit AlignmentMatchingStorage(std::shared_ptr<fs::IStorage> bs) : shared_base_storage(bs), base_storage(shared_base_storage.get()), is_base_storage_size_dirty(true) {
|
||||
explicit AlignmentMatchingStorage(std::shared_ptr<fs::IStorage> bs) : m_shared_base_storage(bs), m_base_storage(m_shared_base_storage.get()), m_is_base_storage_size_dirty(true) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace ams::fssystem {
|
||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||
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(m_base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<char *>(buffer), size);
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
|
||||
@@ -81,30 +81,30 @@ namespace ams::fssystem {
|
||||
R_TRY(this->GetSize(std::addressof(bs_size)));
|
||||
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(m_base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<const char *>(buffer), size);
|
||||
}
|
||||
|
||||
virtual Result Flush() override {
|
||||
return this->base_storage->Flush();
|
||||
return m_base_storage->Flush();
|
||||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override {
|
||||
ON_SCOPE_EXIT { this->is_base_storage_size_dirty = true; };
|
||||
return this->base_storage->SetSize(util::AlignUp(size, DataAlign));
|
||||
ON_SCOPE_EXIT { m_is_base_storage_size_dirty = true; };
|
||||
return m_base_storage->SetSize(util::AlignUp(size, DataAlign));
|
||||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
|
||||
if (this->is_base_storage_size_dirty) {
|
||||
if (m_is_base_storage_size_dirty) {
|
||||
s64 size;
|
||||
R_TRY(this->base_storage->GetSize(std::addressof(size)));
|
||||
R_TRY(m_base_storage->GetSize(std::addressof(size)));
|
||||
|
||||
this->base_storage_size = size;
|
||||
this->is_base_storage_size_dirty = false;
|
||||
m_base_storage_size = size;
|
||||
m_is_base_storage_size_dirty = false;
|
||||
}
|
||||
|
||||
*out = this->base_storage_size;
|
||||
*out = m_base_storage_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace ams::fssystem {
|
||||
const auto aligned_offset_end = util::AlignUp(offset + valid_size, DataAlign);
|
||||
const auto aligned_size = aligned_offset_end - aligned_offset;
|
||||
|
||||
return this->base_storage->OperateRange(dst, dst_size, op_id, aligned_offset, aligned_size, src, src_size);
|
||||
return m_base_storage->OperateRange(dst, dst_size, op_id, aligned_offset, aligned_size, src, src_size);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -136,12 +136,12 @@ namespace ams::fssystem {
|
||||
|
||||
static_assert(util::IsPowerOfTwo(BufferAlign));
|
||||
private:
|
||||
fs::IStorage * const base_storage;
|
||||
s64 base_storage_size;
|
||||
size_t data_align;
|
||||
bool is_base_storage_size_dirty;
|
||||
fs::IStorage * const m_base_storage;
|
||||
s64 m_base_storage_size;
|
||||
size_t m_data_align;
|
||||
bool m_is_base_storage_size_dirty;
|
||||
public:
|
||||
explicit AlignmentMatchingStoragePooledBuffer(fs::IStorage *bs, size_t da) : base_storage(bs), data_align(da), is_base_storage_size_dirty(true) {
|
||||
explicit AlignmentMatchingStoragePooledBuffer(fs::IStorage *bs, size_t da) : m_base_storage(bs), m_data_align(da), m_is_base_storage_size_dirty(true) {
|
||||
AMS_ASSERT(util::IsPowerOfTwo(da));
|
||||
}
|
||||
|
||||
@@ -158,9 +158,9 @@ namespace ams::fssystem {
|
||||
|
||||
/* Allocate a pooled buffer. */
|
||||
PooledBuffer pooled_buffer;
|
||||
pooled_buffer.AllocateParticularlyLarge(this->data_align, this->data_align);
|
||||
pooled_buffer.AllocateParticularlyLarge(m_data_align, m_data_align);
|
||||
|
||||
return AlignmentMatchingStorageImpl::Read(this->base_storage, pooled_buffer.GetBuffer(), pooled_buffer.GetSize(), this->data_align, BufferAlign, offset, static_cast<char *>(buffer), size);
|
||||
return AlignmentMatchingStorageImpl::Read(m_base_storage, pooled_buffer.GetBuffer(), pooled_buffer.GetSize(), m_data_align, BufferAlign, offset, static_cast<char *>(buffer), size);
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
|
||||
@@ -176,32 +176,32 @@ namespace ams::fssystem {
|
||||
|
||||
/* Allocate a pooled buffer. */
|
||||
PooledBuffer pooled_buffer;
|
||||
pooled_buffer.AllocateParticularlyLarge(this->data_align, this->data_align);
|
||||
pooled_buffer.AllocateParticularlyLarge(m_data_align, m_data_align);
|
||||
|
||||
return AlignmentMatchingStorageImpl::Write(this->base_storage, pooled_buffer.GetBuffer(), pooled_buffer.GetSize(), this->data_align, BufferAlign, offset, static_cast<const char *>(buffer), size);
|
||||
return AlignmentMatchingStorageImpl::Write(m_base_storage, pooled_buffer.GetBuffer(), pooled_buffer.GetSize(), m_data_align, BufferAlign, offset, static_cast<const char *>(buffer), size);
|
||||
}
|
||||
|
||||
virtual Result Flush() override {
|
||||
return this->base_storage->Flush();
|
||||
return m_base_storage->Flush();
|
||||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override {
|
||||
ON_SCOPE_EXIT { this->is_base_storage_size_dirty = true; };
|
||||
return this->base_storage->SetSize(util::AlignUp(size, this->data_align));
|
||||
ON_SCOPE_EXIT { m_is_base_storage_size_dirty = true; };
|
||||
return m_base_storage->SetSize(util::AlignUp(size, m_data_align));
|
||||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
|
||||
if (this->is_base_storage_size_dirty) {
|
||||
if (m_is_base_storage_size_dirty) {
|
||||
s64 size;
|
||||
R_TRY(this->base_storage->GetSize(std::addressof(size)));
|
||||
R_TRY(m_base_storage->GetSize(std::addressof(size)));
|
||||
|
||||
this->base_storage_size = size;
|
||||
this->is_base_storage_size_dirty = false;
|
||||
m_base_storage_size = size;
|
||||
m_is_base_storage_size_dirty = false;
|
||||
}
|
||||
|
||||
*out = this->base_storage_size;
|
||||
*out = m_base_storage_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -216,11 +216,11 @@ namespace ams::fssystem {
|
||||
|
||||
/* Operate on the base storage. */
|
||||
const auto valid_size = std::min(size, bs_size - offset);
|
||||
const auto aligned_offset = util::AlignDown(offset, this->data_align);
|
||||
const auto aligned_offset_end = util::AlignUp(offset + valid_size, this->data_align);
|
||||
const auto aligned_offset = util::AlignDown(offset, m_data_align);
|
||||
const auto aligned_offset_end = util::AlignUp(offset + valid_size, m_data_align);
|
||||
const auto aligned_size = aligned_offset_end - aligned_offset;
|
||||
|
||||
return this->base_storage->OperateRange(dst, dst_size, op_id, aligned_offset, aligned_size, src, src_size);
|
||||
return m_base_storage->OperateRange(dst, dst_size, op_id, aligned_offset, aligned_size, src, src_size);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -233,16 +233,16 @@ namespace ams::fssystem {
|
||||
|
||||
static_assert(util::IsPowerOfTwo(BufferAlign));
|
||||
private:
|
||||
std::shared_ptr<fs::IStorage> shared_base_storage;
|
||||
fs::IStorage * const base_storage;
|
||||
s64 base_storage_size;
|
||||
size_t data_align;
|
||||
std::shared_ptr<fs::IStorage> m_shared_base_storage;
|
||||
fs::IStorage * const m_base_storage;
|
||||
s64 m_base_storage_size;
|
||||
size_t m_data_align;
|
||||
public:
|
||||
explicit AlignmentMatchingStorageInBulkRead(fs::IStorage *bs, size_t da) : shared_base_storage(), base_storage(bs), base_storage_size(-1), data_align(da) {
|
||||
AMS_ASSERT(util::IsPowerOfTwo(this->data_align));
|
||||
explicit AlignmentMatchingStorageInBulkRead(fs::IStorage *bs, size_t da) : m_shared_base_storage(), m_base_storage(bs), m_base_storage_size(-1), m_data_align(da) {
|
||||
AMS_ASSERT(util::IsPowerOfTwo(m_data_align));
|
||||
}
|
||||
|
||||
explicit AlignmentMatchingStorageInBulkRead(std::shared_ptr<fs::IStorage> bs, size_t da) : shared_base_storage(bs), base_storage(shared_base_storage.get()), base_storage_size(-1), data_align(da) {
|
||||
explicit AlignmentMatchingStorageInBulkRead(std::shared_ptr<fs::IStorage> bs, size_t da) : m_shared_base_storage(bs), m_base_storage(m_shared_base_storage.get()), m_base_storage_size(-1), m_data_align(da) {
|
||||
AMS_ASSERT(util::IsPowerOfTwo(da));
|
||||
}
|
||||
|
||||
@@ -260,30 +260,30 @@ namespace ams::fssystem {
|
||||
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
|
||||
|
||||
/* Allocate a pooled buffer. */
|
||||
PooledBuffer pooled_buffer(this->data_align, this->data_align);
|
||||
return AlignmentMatchingStorageImpl::Write(this->base_storage, pooled_buffer.GetBuffer(), pooled_buffer.GetSize(), this->data_align, BufferAlign, offset, static_cast<const char *>(buffer), size);
|
||||
PooledBuffer pooled_buffer(m_data_align, m_data_align);
|
||||
return AlignmentMatchingStorageImpl::Write(m_base_storage, pooled_buffer.GetBuffer(), pooled_buffer.GetSize(), m_data_align, BufferAlign, offset, static_cast<const char *>(buffer), size);
|
||||
}
|
||||
|
||||
virtual Result Flush() override {
|
||||
return this->base_storage->Flush();
|
||||
return m_base_storage->Flush();
|
||||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override {
|
||||
ON_SCOPE_EXIT { this->base_storage_size = -1; };
|
||||
return this->base_storage->SetSize(util::AlignUp(size, this->data_align));
|
||||
ON_SCOPE_EXIT { m_base_storage_size = -1; };
|
||||
return m_base_storage->SetSize(util::AlignUp(size, m_data_align));
|
||||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
|
||||
if (this->base_storage_size < 0) {
|
||||
if (m_base_storage_size < 0) {
|
||||
s64 size;
|
||||
R_TRY(this->base_storage->GetSize(std::addressof(size)));
|
||||
R_TRY(m_base_storage->GetSize(std::addressof(size)));
|
||||
|
||||
this->base_storage_size = size;
|
||||
m_base_storage_size = size;
|
||||
}
|
||||
|
||||
*out = this->base_storage_size;
|
||||
*out = m_base_storage_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -298,11 +298,11 @@ namespace ams::fssystem {
|
||||
|
||||
/* Operate on the base storage. */
|
||||
const auto valid_size = std::min(size, bs_size - offset);
|
||||
const auto aligned_offset = util::AlignDown(offset, this->data_align);
|
||||
const auto aligned_offset_end = util::AlignUp(offset + valid_size, this->data_align);
|
||||
const auto aligned_offset = util::AlignDown(offset, m_data_align);
|
||||
const auto aligned_offset_end = util::AlignUp(offset + valid_size, m_data_align);
|
||||
const auto aligned_size = aligned_offset_end - aligned_offset;
|
||||
|
||||
return this->base_storage->OperateRange(dst, dst_size, op_id, aligned_offset, aligned_size, src, src_size);
|
||||
return m_base_storage->OperateRange(dst, dst_size, op_id, aligned_offset, aligned_size, src, src_size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -55,24 +55,24 @@ namespace ams::fssystem {
|
||||
|
||||
class ContinuousReadingInfo {
|
||||
private:
|
||||
size_t read_size;
|
||||
s32 skip_count;
|
||||
bool done;
|
||||
size_t m_read_size;
|
||||
s32 m_skip_count;
|
||||
bool m_done;
|
||||
public:
|
||||
constexpr ContinuousReadingInfo() : read_size(), skip_count(), done() { /* ... */ }
|
||||
constexpr ContinuousReadingInfo() : m_read_size(), m_skip_count(), m_done() { /* ... */ }
|
||||
|
||||
constexpr void Reset() { this->read_size = 0; this->skip_count = 0; this->done = false; }
|
||||
constexpr void Reset() { m_read_size = 0; m_skip_count = 0; m_done = false; }
|
||||
|
||||
constexpr void SetSkipCount(s32 count) { AMS_ASSERT(count >= 0); this->skip_count = count; }
|
||||
constexpr s32 GetSkipCount() const { return this->skip_count; }
|
||||
constexpr bool CheckNeedScan() { return (--this->skip_count) <= 0; }
|
||||
constexpr void SetSkipCount(s32 count) { AMS_ASSERT(count >= 0); m_skip_count = count; }
|
||||
constexpr s32 GetSkipCount() const { return m_skip_count; }
|
||||
constexpr bool CheckNeedScan() { return (--m_skip_count) <= 0; }
|
||||
|
||||
constexpr void Done() { this->read_size = 0; this->done = true; }
|
||||
constexpr bool IsDone() const { return this->done; }
|
||||
constexpr void Done() { m_read_size = 0; m_done = true; }
|
||||
constexpr bool IsDone() const { return m_done; }
|
||||
|
||||
constexpr void SetReadSize(size_t size) { this->read_size = size; }
|
||||
constexpr size_t GetReadSize() const { return this->read_size; }
|
||||
constexpr bool CanDo() const { return this->read_size > 0; }
|
||||
constexpr void SetReadSize(size_t size) { m_read_size = size; }
|
||||
constexpr size_t GetReadSize() const { return m_read_size; }
|
||||
constexpr bool CanDo() const { return m_read_size > 0; }
|
||||
};
|
||||
|
||||
using IAllocator = MemoryResource;
|
||||
@@ -80,60 +80,60 @@ namespace ams::fssystem {
|
||||
class NodeBuffer {
|
||||
NON_COPYABLE(NodeBuffer);
|
||||
private:
|
||||
IAllocator *allocator;
|
||||
void *header;
|
||||
IAllocator *m_allocator;
|
||||
void *m_header;
|
||||
public:
|
||||
NodeBuffer() : allocator(), header() { /* ... */ }
|
||||
NodeBuffer() : m_allocator(), m_header() { /* ... */ }
|
||||
|
||||
~NodeBuffer() {
|
||||
AMS_ASSERT(this->header == nullptr);
|
||||
AMS_ASSERT(m_header == nullptr);
|
||||
}
|
||||
|
||||
NodeBuffer(NodeBuffer &&rhs) : allocator(rhs.allocator), header(rhs.allocator) {
|
||||
rhs.allocator = nullptr;
|
||||
rhs.header = nullptr;
|
||||
NodeBuffer(NodeBuffer &&rhs) : m_allocator(rhs.m_allocator), m_header(rhs.m_allocator) {
|
||||
rhs.m_allocator = nullptr;
|
||||
rhs.m_header = nullptr;
|
||||
}
|
||||
|
||||
NodeBuffer &operator=(NodeBuffer &&rhs) {
|
||||
if (this != std::addressof(rhs)) {
|
||||
AMS_ASSERT(this->header == nullptr);
|
||||
AMS_ASSERT(m_header == nullptr);
|
||||
|
||||
this->allocator = rhs.allocator;
|
||||
this->header = rhs.header;
|
||||
m_allocator = rhs.m_allocator;
|
||||
m_header = rhs.m_header;
|
||||
|
||||
rhs.allocator = nullptr;
|
||||
rhs.header = nullptr;
|
||||
rhs.m_allocator = nullptr;
|
||||
rhs.m_header = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Allocate(IAllocator *allocator, size_t node_size) {
|
||||
AMS_ASSERT(this->header == nullptr);
|
||||
AMS_ASSERT(m_header == nullptr);
|
||||
|
||||
this->allocator = allocator;
|
||||
this->header = allocator->Allocate(node_size, sizeof(s64));
|
||||
m_allocator = allocator;
|
||||
m_header = allocator->Allocate(node_size, sizeof(s64));
|
||||
|
||||
AMS_ASSERT(util::IsAligned(this->header, sizeof(s64)));
|
||||
AMS_ASSERT(util::IsAligned(m_header, sizeof(s64)));
|
||||
|
||||
return this->header != nullptr;
|
||||
return m_header != nullptr;
|
||||
}
|
||||
|
||||
void Free(size_t node_size) {
|
||||
if (this->header) {
|
||||
this->allocator->Deallocate(this->header, node_size);
|
||||
this->header = nullptr;
|
||||
if (m_header) {
|
||||
m_allocator->Deallocate(m_header, node_size);
|
||||
m_header = nullptr;
|
||||
}
|
||||
this->allocator = nullptr;
|
||||
m_allocator = nullptr;
|
||||
}
|
||||
|
||||
void FillZero(size_t node_size) const {
|
||||
if (this->header) {
|
||||
std::memset(this->header, 0, node_size);
|
||||
if (m_header) {
|
||||
std::memset(m_header, 0, node_size);
|
||||
}
|
||||
}
|
||||
|
||||
NodeHeader *Get() const {
|
||||
return reinterpret_cast<NodeHeader *>(this->header);
|
||||
return reinterpret_cast<NodeHeader *>(m_header);
|
||||
}
|
||||
|
||||
NodeHeader *operator->() const { return this->Get(); }
|
||||
@@ -142,11 +142,11 @@ namespace ams::fssystem {
|
||||
T *Get() const {
|
||||
static_assert(util::is_pod<T>::value);
|
||||
static_assert(sizeof(T) == sizeof(NodeHeader));
|
||||
return reinterpret_cast<T *>(this->header);
|
||||
return reinterpret_cast<T *>(m_header);
|
||||
}
|
||||
|
||||
IAllocator *GetAllocator() const {
|
||||
return this->allocator;
|
||||
return m_allocator;
|
||||
}
|
||||
};
|
||||
private:
|
||||
@@ -205,43 +205,43 @@ namespace ams::fssystem {
|
||||
return GetEntrySetCount(node_size, entry_size, entry_count) * static_cast<s64>(node_size);
|
||||
}
|
||||
private:
|
||||
mutable fs::SubStorage node_storage;
|
||||
mutable fs::SubStorage entry_storage;
|
||||
NodeBuffer node_l1;
|
||||
size_t node_size;
|
||||
size_t entry_size;
|
||||
s32 entry_count;
|
||||
s32 offset_count;
|
||||
s32 entry_set_count;
|
||||
s64 start_offset;
|
||||
s64 end_offset;
|
||||
mutable fs::SubStorage m_node_storage;
|
||||
mutable fs::SubStorage m_entry_storage;
|
||||
NodeBuffer m_node_l1;
|
||||
size_t m_node_size;
|
||||
size_t m_entry_size;
|
||||
s32 m_entry_count;
|
||||
s32 m_offset_count;
|
||||
s32 m_entry_set_count;
|
||||
s64 m_start_offset;
|
||||
s64 m_end_offset;
|
||||
public:
|
||||
BucketTree() : node_storage(), entry_storage(), node_l1(), node_size(), entry_size(), entry_count(), offset_count(), entry_set_count(), start_offset(), end_offset() { /* ... */ }
|
||||
BucketTree() : m_node_storage(), m_entry_storage(), m_node_l1(), m_node_size(), m_entry_size(), m_entry_count(), m_offset_count(), m_entry_set_count(), m_start_offset(), m_end_offset() { /* ... */ }
|
||||
~BucketTree() { this->Finalize(); }
|
||||
|
||||
Result Initialize(IAllocator *allocator, fs::SubStorage node_storage, fs::SubStorage entry_storage, size_t node_size, size_t entry_size, s32 entry_count);
|
||||
void Initialize(size_t node_size, s64 end_offset);
|
||||
void Finalize();
|
||||
|
||||
bool IsInitialized() const { return this->node_size > 0; }
|
||||
bool IsEmpty() const { return this->entry_size == 0; }
|
||||
bool IsInitialized() const { return m_node_size > 0; }
|
||||
bool IsEmpty() const { return m_entry_size == 0; }
|
||||
|
||||
Result Find(Visitor *visitor, s64 virtual_address) const;
|
||||
Result InvalidateCache();
|
||||
|
||||
s32 GetEntryCount() const { return this->entry_count; }
|
||||
IAllocator *GetAllocator() const { return this->node_l1.GetAllocator(); }
|
||||
s32 GetEntryCount() const { return m_entry_count; }
|
||||
IAllocator *GetAllocator() const { return m_node_l1.GetAllocator(); }
|
||||
|
||||
s64 GetStart() const { return this->start_offset; }
|
||||
s64 GetEnd() const { return this->end_offset; }
|
||||
s64 GetSize() const { return this->end_offset - this->start_offset; }
|
||||
s64 GetStart() const { return m_start_offset; }
|
||||
s64 GetEnd() const { return m_end_offset; }
|
||||
s64 GetSize() const { return m_end_offset - m_start_offset; }
|
||||
|
||||
bool Includes(s64 offset) const {
|
||||
return this->start_offset <= offset && offset < this->end_offset;
|
||||
return m_start_offset <= offset && offset < m_end_offset;
|
||||
}
|
||||
|
||||
bool Includes(s64 offset, s64 size) const {
|
||||
return size > 0 && this->start_offset <= offset && size <= this->end_offset - offset;
|
||||
return size > 0 && m_start_offset <= offset && size <= m_end_offset - offset;
|
||||
}
|
||||
private:
|
||||
template<typename EntryType>
|
||||
@@ -256,11 +256,11 @@ namespace ams::fssystem {
|
||||
template<typename EntryType>
|
||||
Result ScanContinuousReading(ContinuousReadingInfo *out_info, const ContinuousReadingParam<EntryType> ¶m) const;
|
||||
|
||||
bool IsExistL2() const { return this->offset_count < this->entry_set_count; }
|
||||
bool IsExistOffsetL2OnL1() const { return this->IsExistL2() && this->node_l1->count < this->offset_count; }
|
||||
bool IsExistL2() const { return m_offset_count < m_entry_set_count; }
|
||||
bool IsExistOffsetL2OnL1() const { return this->IsExistL2() && m_node_l1->count < m_offset_count; }
|
||||
|
||||
s64 GetEntrySetIndex(s32 node_index, s32 offset_index) const {
|
||||
return (this->offset_count - this->node_l1->count) + (this->offset_count * node_index) + offset_index;
|
||||
return (m_offset_count - m_node_l1->count) + (m_offset_count * node_index) + offset_index;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -282,24 +282,24 @@ namespace ams::fssystem {
|
||||
};
|
||||
static_assert(util::is_pod<EntrySetHeader>::value);
|
||||
private:
|
||||
const BucketTree *tree;
|
||||
void *entry;
|
||||
s32 entry_index;
|
||||
s32 entry_set_count;
|
||||
EntrySetHeader entry_set;
|
||||
const BucketTree *m_tree;
|
||||
void *m_entry;
|
||||
s32 m_entry_index;
|
||||
s32 m_entry_set_count;
|
||||
EntrySetHeader m_entry_set;
|
||||
public:
|
||||
constexpr Visitor() : tree(), entry(), entry_index(-1), entry_set_count(), entry_set{} { /* ... */ }
|
||||
constexpr Visitor() : m_tree(), m_entry(), m_entry_index(-1), m_entry_set_count(), m_entry_set{} { /* ... */ }
|
||||
~Visitor() {
|
||||
if (this->entry != nullptr) {
|
||||
this->tree->GetAllocator()->Deallocate(this->entry, this->tree->entry_size);
|
||||
this->tree = nullptr;
|
||||
this->entry = nullptr;
|
||||
if (m_entry != nullptr) {
|
||||
m_tree->GetAllocator()->Deallocate(m_entry, m_tree->m_entry_size);
|
||||
m_tree = nullptr;
|
||||
m_entry = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValid() const { return this->entry_index >= 0; }
|
||||
bool CanMoveNext() const { return this->IsValid() && (this->entry_index + 1 < this->entry_set.info.count || this->entry_set.info.index + 1 < this->entry_set_count); }
|
||||
bool CanMovePrevious() const { return this->IsValid() && (this->entry_index > 0 || this->entry_set.info.index > 0); }
|
||||
bool IsValid() const { return m_entry_index >= 0; }
|
||||
bool CanMoveNext() const { return this->IsValid() && (m_entry_index + 1 < m_entry_set.info.count || m_entry_set.info.index + 1 < m_entry_set_count); }
|
||||
bool CanMovePrevious() const { return this->IsValid() && (m_entry_index > 0 || m_entry_set.info.index > 0); }
|
||||
|
||||
Result MoveNext();
|
||||
Result MovePrevious();
|
||||
@@ -307,12 +307,12 @@ namespace ams::fssystem {
|
||||
template<typename EntryType>
|
||||
Result ScanContinuousReading(ContinuousReadingInfo *out_info, s64 offset, size_t size) const;
|
||||
|
||||
const void *Get() const { AMS_ASSERT(this->IsValid()); return this->entry; }
|
||||
const void *Get() const { AMS_ASSERT(this->IsValid()); return m_entry; }
|
||||
|
||||
template<typename T>
|
||||
const T *Get() const { AMS_ASSERT(this->IsValid()); return reinterpret_cast<const T *>(this->entry); }
|
||||
const T *Get() const { AMS_ASSERT(this->IsValid()); return reinterpret_cast<const T *>(m_entry); }
|
||||
|
||||
const BucketTree *GetTree() const { return this->tree; }
|
||||
const BucketTree *GetTree() const { return m_tree; }
|
||||
private:
|
||||
Result Initialize(const BucketTree *tree);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ams::fssystem {
|
||||
/* Validate our preconditions. */
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
AMS_ASSERT(out_info != nullptr);
|
||||
AMS_ASSERT(this->entry_size == sizeof(EntryType));
|
||||
AMS_ASSERT(m_entry_size == sizeof(EntryType));
|
||||
|
||||
/* Reset the output. */
|
||||
out_info->Reset();
|
||||
@@ -44,14 +44,14 @@ namespace ams::fssystem {
|
||||
R_UNLESS(entry.GetVirtualOffset() <= cur_offset, fs::ResultOutOfRange());
|
||||
|
||||
/* Create a pooled buffer for our scan. */
|
||||
PooledBuffer pool(this->node_size, 1);
|
||||
PooledBuffer pool(m_node_size, 1);
|
||||
char *buffer = nullptr;
|
||||
|
||||
/* Read the node. */
|
||||
if (this->node_size <= pool.GetSize()) {
|
||||
if (m_node_size <= pool.GetSize()) {
|
||||
buffer = pool.GetBuffer();
|
||||
const auto ofs = param.entry_set.index * static_cast<s64>(this->node_size);
|
||||
R_TRY(this->entry_storage.Read(ofs, buffer, this->node_size));
|
||||
const auto ofs = param.entry_set.index * static_cast<s64>(m_node_size);
|
||||
R_TRY(m_entry_storage.Read(ofs, buffer, m_node_size));
|
||||
}
|
||||
|
||||
/* Calculate extents. */
|
||||
@@ -81,11 +81,11 @@ namespace ams::fssystem {
|
||||
|
||||
if (entry_index + 1 < entry_count) {
|
||||
if (buffer != nullptr) {
|
||||
const auto ofs = impl::GetBucketTreeEntryOffset(0, this->entry_size, entry_index + 1);
|
||||
std::memcpy(std::addressof(next_entry), buffer + ofs, this->entry_size);
|
||||
const auto ofs = impl::GetBucketTreeEntryOffset(0, m_entry_size, entry_index + 1);
|
||||
std::memcpy(std::addressof(next_entry), buffer + ofs, m_entry_size);
|
||||
} else {
|
||||
const auto ofs = impl::GetBucketTreeEntryOffset(param.entry_set.index, this->node_size, this->entry_size, entry_index + 1);
|
||||
R_TRY(this->entry_storage.Read(ofs, std::addressof(next_entry), this->entry_size));
|
||||
const auto ofs = impl::GetBucketTreeEntryOffset(param.entry_set.index, m_node_size, m_entry_size, entry_index + 1);
|
||||
R_TRY(m_entry_storage.Read(ofs, std::addressof(next_entry), m_entry_size));
|
||||
}
|
||||
|
||||
next_entry_offset = next_entry.GetVirtualOffset();
|
||||
@@ -154,12 +154,12 @@ namespace ams::fssystem {
|
||||
|
||||
/* Create our parameters. */
|
||||
ContinuousReadingParam<EntryType> param = {
|
||||
offset, size, this->entry_set.header, this->entry_index
|
||||
offset, size, m_entry_set.header, m_entry_index
|
||||
};
|
||||
std::memcpy(std::addressof(param.entry), this->entry, sizeof(EntryType));
|
||||
std::memcpy(std::addressof(param.entry), m_entry, sizeof(EntryType));
|
||||
|
||||
/* Scan. */
|
||||
return this->tree->ScanContinuousReading<EntryType>(out_info, param);
|
||||
return m_tree->ScanContinuousReading<EntryType>(out_info, param);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ namespace ams::fssystem {
|
||||
using PathResolutionFileSystem = impl::IPathResolutionFileSystem<DirectoryRedirectionFileSystem>;
|
||||
friend class impl::IPathResolutionFileSystem<DirectoryRedirectionFileSystem>;
|
||||
private:
|
||||
char *before_dir;
|
||||
size_t before_dir_len;
|
||||
char *after_dir;
|
||||
size_t after_dir_len;
|
||||
char *m_before_dir;
|
||||
size_t m_before_dir_len;
|
||||
char *m_after_dir;
|
||||
size_t m_after_dir_len;
|
||||
public:
|
||||
DirectoryRedirectionFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs, const char *before, const char *after, bool unc = false);
|
||||
DirectoryRedirectionFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, const char *before, const char *after, bool unc = false);
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace ams::fssystem {
|
||||
using PathResolutionFileSystem = impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>;
|
||||
friend class impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>;
|
||||
private:
|
||||
os::SdkMutex accessor_mutex;
|
||||
s32 open_writable_files;
|
||||
os::SdkMutex m_accessor_mutex;
|
||||
s32 m_open_writable_files;
|
||||
public:
|
||||
DirectorySaveDataFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs);
|
||||
DirectorySaveDataFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs);
|
||||
@@ -35,7 +35,7 @@ namespace ams::fssystem {
|
||||
protected:
|
||||
inline util::optional<std::scoped_lock<os::SdkMutex>> GetAccessorLock() {
|
||||
/* We have a real accessor lock that we want to use. */
|
||||
return util::make_optional<std::scoped_lock<os::SdkMutex>>(this->accessor_mutex);
|
||||
return util::make_optional<std::scoped_lock<os::SdkMutex>>(m_accessor_mutex);
|
||||
}
|
||||
private:
|
||||
Result AllocateWorkBuffer(std::unique_ptr<u8[]> *out, size_t *out_size, size_t ideal_size);
|
||||
|
||||
@@ -100,30 +100,30 @@ namespace ams::fssystem {
|
||||
return BucketTree::QueryEntryStorageSize(NodeSize, sizeof(Entry), entry_count);
|
||||
}
|
||||
private:
|
||||
BucketTree table;
|
||||
fs::SubStorage data_storage[StorageCount];
|
||||
BucketTree m_table;
|
||||
fs::SubStorage m_data_storage[StorageCount];
|
||||
public:
|
||||
IndirectStorage() : table(), data_storage() { /* ... */ }
|
||||
IndirectStorage() : m_table(), m_data_storage() { /* ... */ }
|
||||
virtual ~IndirectStorage() { this->Finalize(); }
|
||||
|
||||
Result Initialize(IAllocator *allocator, fs::SubStorage table_storage);
|
||||
void Finalize();
|
||||
|
||||
bool IsInitialized() const { return this->table.IsInitialized(); }
|
||||
bool IsInitialized() const { return m_table.IsInitialized(); }
|
||||
|
||||
Result Initialize(IAllocator *allocator, fs::SubStorage node_storage, fs::SubStorage entry_storage, s32 entry_count) {
|
||||
return this->table.Initialize(allocator, node_storage, entry_storage, NodeSize, sizeof(Entry), entry_count);
|
||||
return m_table.Initialize(allocator, node_storage, entry_storage, NodeSize, sizeof(Entry), entry_count);
|
||||
}
|
||||
|
||||
void SetStorage(s32 idx, fs::SubStorage storage) {
|
||||
AMS_ASSERT(0 <= idx && idx < StorageCount);
|
||||
this->data_storage[idx] = storage;
|
||||
m_data_storage[idx] = storage;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SetStorage(s32 idx, T storage, s64 offset, s64 size) {
|
||||
AMS_ASSERT(0 <= idx && idx < StorageCount);
|
||||
this->data_storage[idx] = fs::SubStorage(storage, offset, size);
|
||||
m_data_storage[idx] = fs::SubStorage(storage, offset, size);
|
||||
}
|
||||
|
||||
Result GetEntryList(Entry *out_entries, s32 *out_entry_count, s32 entry_count, s64 offset, s64 size);
|
||||
@@ -133,7 +133,7 @@ namespace ams::fssystem {
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
*out = this->table.GetEnd();
|
||||
*out = m_table.GetEnd();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -151,11 +151,11 @@ namespace ams::fssystem {
|
||||
return fs::ResultUnsupportedOperationInIndirectStorageB();
|
||||
}
|
||||
protected:
|
||||
BucketTree &GetEntryTable() { return this->table; }
|
||||
BucketTree &GetEntryTable() { return m_table; }
|
||||
|
||||
fs::SubStorage &GetDataStorage(s32 index) {
|
||||
AMS_ASSERT(0 <= index && index < StorageCount);
|
||||
return this->data_storage[index];
|
||||
return m_data_storage[index];
|
||||
}
|
||||
|
||||
template<bool ContinuousCheck, typename F>
|
||||
|
||||
@@ -29,14 +29,14 @@ namespace ams::fssystem {
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments. */
|
||||
R_UNLESS(this->table.Includes(offset, size), fs::ResultOutOfRange());
|
||||
R_UNLESS(m_table.Includes(offset, size), fs::ResultOutOfRange());
|
||||
|
||||
/* Find the offset in our tree. */
|
||||
BucketTree::Visitor visitor;
|
||||
R_TRY(this->table.Find(std::addressof(visitor), offset));
|
||||
R_TRY(m_table.Find(std::addressof(visitor), offset));
|
||||
{
|
||||
const auto entry_offset = visitor.Get<Entry>()->GetVirtualOffset();
|
||||
R_UNLESS(0 <= entry_offset && this->table.Includes(entry_offset), fs::ResultInvalidIndirectEntryOffset());
|
||||
R_UNLESS(0 <= entry_offset && m_table.Includes(entry_offset), fs::ResultInvalidIndirectEntryOffset());
|
||||
}
|
||||
|
||||
/* Prepare to operate in chunks. */
|
||||
@@ -69,7 +69,7 @@ namespace ams::fssystem {
|
||||
|
||||
/* Get the current data storage's size. */
|
||||
s64 cur_data_storage_size;
|
||||
R_TRY(this->data_storage[0].GetSize(std::addressof(cur_data_storage_size)));
|
||||
R_TRY(m_data_storage[0].GetSize(std::addressof(cur_data_storage_size)));
|
||||
|
||||
/* Ensure that we remain within range. */
|
||||
const auto data_offset = cur_offset - cur_entry_offset;
|
||||
@@ -79,7 +79,7 @@ namespace ams::fssystem {
|
||||
R_UNLESS(cur_entry_phys_offset + data_offset + cur_size <= cur_data_storage_size, fs::ResultInvalidIndirectStorageSize());
|
||||
|
||||
/* Operate. */
|
||||
R_TRY(func(std::addressof(this->data_storage[0]), cur_entry_phys_offset + data_offset, cur_offset, cur_size));
|
||||
R_TRY(func(std::addressof(m_data_storage[0]), cur_entry_phys_offset + data_offset, cur_offset, cur_size));
|
||||
|
||||
/* Mark as done. */
|
||||
cr_info.Done();
|
||||
@@ -91,9 +91,9 @@ namespace ams::fssystem {
|
||||
if (visitor.CanMoveNext()) {
|
||||
R_TRY(visitor.MoveNext());
|
||||
next_entry_offset = visitor.Get<Entry>()->GetVirtualOffset();
|
||||
R_UNLESS(this->table.Includes(next_entry_offset), fs::ResultInvalidIndirectEntryOffset());
|
||||
R_UNLESS(m_table.Includes(next_entry_offset), fs::ResultInvalidIndirectEntryOffset());
|
||||
} else {
|
||||
next_entry_offset = this->table.GetEnd();
|
||||
next_entry_offset = m_table.GetEnd();
|
||||
}
|
||||
R_UNLESS(cur_offset < next_entry_offset, fs::ResultInvalidIndirectEntryOffset());
|
||||
|
||||
@@ -118,14 +118,14 @@ namespace ams::fssystem {
|
||||
if (needs_operate) {
|
||||
/* Get the current data storage's size. */
|
||||
s64 cur_data_storage_size;
|
||||
R_TRY(this->data_storage[cur_entry.storage_index].GetSize(std::addressof(cur_data_storage_size)));
|
||||
R_TRY(m_data_storage[cur_entry.storage_index].GetSize(std::addressof(cur_data_storage_size)));
|
||||
|
||||
/* Ensure that we remain within range. */
|
||||
const auto cur_entry_phys_offset = cur_entry.GetPhysicalOffset();
|
||||
R_UNLESS(0 <= cur_entry_phys_offset && cur_entry_phys_offset <= cur_data_storage_size, fs::ResultIndirectStorageCorrupted());
|
||||
R_UNLESS(cur_entry_phys_offset + data_offset + cur_size <= cur_data_storage_size, fs::ResultIndirectStorageCorrupted());
|
||||
|
||||
R_TRY(func(std::addressof(this->data_storage[cur_entry.storage_index]), cur_entry_phys_offset + data_offset, cur_offset, cur_size));
|
||||
R_TRY(func(std::addressof(m_data_storage[cur_entry.storage_index]), cur_entry_phys_offset + data_offset, cur_offset, cur_size));
|
||||
}
|
||||
|
||||
cur_offset += cur_size;
|
||||
|
||||
@@ -28,46 +28,46 @@ namespace ams::fssystem {
|
||||
|
||||
class IntegrityRomFsStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
|
||||
private:
|
||||
save::HierarchicalIntegrityVerificationStorage integrity_storage;
|
||||
save::FileSystemBufferManagerSet buffers;
|
||||
os::SdkRecursiveMutex mutex;
|
||||
Hash master_hash;
|
||||
std::unique_ptr<fs::MemoryStorage> master_hash_storage;
|
||||
save::HierarchicalIntegrityVerificationStorage m_integrity_storage;
|
||||
save::FileSystemBufferManagerSet m_buffers;
|
||||
os::SdkRecursiveMutex m_mutex;
|
||||
Hash m_master_hash;
|
||||
std::unique_ptr<fs::MemoryStorage> m_master_hash_storage;
|
||||
public:
|
||||
IntegrityRomFsStorage() : mutex() { /* ... */ }
|
||||
IntegrityRomFsStorage() : m_mutex() { /* ... */ }
|
||||
virtual ~IntegrityRomFsStorage() override { this->Finalize(); }
|
||||
|
||||
Result Initialize(save::HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, save::HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, IBufferManager *bm);
|
||||
void Finalize();
|
||||
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
return this->integrity_storage.Read(offset, buffer, size);
|
||||
return m_integrity_storage.Read(offset, buffer, size);
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
|
||||
return this->integrity_storage.Write(offset, buffer, size);
|
||||
return m_integrity_storage.Write(offset, buffer, size);
|
||||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override { AMS_UNUSED(size); return fs::ResultUnsupportedOperationInIntegrityRomFsStorageA(); }
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
return this->integrity_storage.GetSize(out);
|
||||
return m_integrity_storage.GetSize(out);
|
||||
}
|
||||
|
||||
virtual Result Flush() override {
|
||||
return this->integrity_storage.Flush();
|
||||
return m_integrity_storage.Flush();
|
||||
}
|
||||
|
||||
virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
|
||||
return this->integrity_storage.OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||
return m_integrity_storage.OperateRange(dst, dst_size, op_id, offset, size, src, src_size);
|
||||
}
|
||||
|
||||
Result Commit() {
|
||||
return this->integrity_storage.Commit();
|
||||
return m_integrity_storage.Commit();
|
||||
}
|
||||
|
||||
save::FileSystemBufferManagerSet *GetBuffers() {
|
||||
return this->integrity_storage.GetBuffers();
|
||||
return m_integrity_storage.GetBuffers();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -85,16 +85,16 @@ namespace ams::fssystem {
|
||||
NON_COPYABLE(NcaReader);
|
||||
NON_MOVEABLE(NcaReader);
|
||||
private:
|
||||
NcaHeader header;
|
||||
u8 decryption_keys[NcaHeader::DecryptionKey_Count][NcaCryptoConfiguration::Aes128KeySize];
|
||||
std::shared_ptr<fs::IStorage> shared_base_storage;
|
||||
std::unique_ptr<fs::IStorage> header_storage;
|
||||
fs::IStorage *body_storage;
|
||||
u8 external_decryption_key[NcaCryptoConfiguration::Aes128KeySize];
|
||||
DecryptAesCtrFunction decrypt_aes_ctr;
|
||||
DecryptAesCtrFunction decrypt_aes_ctr_external;
|
||||
bool is_software_aes_prioritized;
|
||||
NcaHeader::EncryptionType header_encryption_type;
|
||||
NcaHeader m_header;
|
||||
u8 m_decryption_keys[NcaHeader::DecryptionKey_Count][NcaCryptoConfiguration::Aes128KeySize];
|
||||
std::shared_ptr<fs::IStorage> m_shared_base_storage;
|
||||
std::unique_ptr<fs::IStorage> m_header_storage;
|
||||
fs::IStorage *m_body_storage;
|
||||
u8 m_external_decryption_key[NcaCryptoConfiguration::Aes128KeySize];
|
||||
DecryptAesCtrFunction m_decrypt_aes_ctr;
|
||||
DecryptAesCtrFunction m_decrypt_aes_ctr_external;
|
||||
bool m_is_software_aes_prioritized;
|
||||
NcaHeader::EncryptionType m_header_encryption_type;
|
||||
public:
|
||||
NcaReader();
|
||||
~NcaReader();
|
||||
@@ -143,18 +143,18 @@ namespace ams::fssystem {
|
||||
NON_COPYABLE(NcaFsHeaderReader);
|
||||
NON_MOVEABLE(NcaFsHeaderReader);
|
||||
private:
|
||||
NcaFsHeader data;
|
||||
s32 fs_index;
|
||||
NcaFsHeader m_data;
|
||||
s32 m_fs_index;
|
||||
public:
|
||||
NcaFsHeaderReader() : fs_index(-1) {
|
||||
std::memset(std::addressof(this->data), 0, sizeof(this->data));
|
||||
NcaFsHeaderReader() : m_fs_index(-1) {
|
||||
std::memset(std::addressof(m_data), 0, sizeof(m_data));
|
||||
}
|
||||
|
||||
Result Initialize(const NcaReader &reader, s32 index);
|
||||
bool IsInitialized() const { return this->fs_index >= 0; }
|
||||
bool IsInitialized() const { return m_fs_index >= 0; }
|
||||
|
||||
NcaFsHeader &GetData() { return this->data; }
|
||||
const NcaFsHeader &GetData() const { return this->data; }
|
||||
NcaFsHeader &GetData() { return m_data; }
|
||||
const NcaFsHeader &GetData() const { return m_data; }
|
||||
void GetRawData(void *dst, size_t dst_size) const;
|
||||
|
||||
NcaFsHeader::HashData &GetHashData();
|
||||
@@ -179,19 +179,19 @@ namespace ams::fssystem {
|
||||
class StorageOption;
|
||||
class StorageOptionWithHeaderReader;
|
||||
private:
|
||||
std::shared_ptr<NcaReader> original_reader;
|
||||
std::shared_ptr<NcaReader> reader;
|
||||
MemoryResource * const allocator;
|
||||
fssystem::IBufferManager * const buffer_manager;
|
||||
std::shared_ptr<NcaReader> m_original_reader;
|
||||
std::shared_ptr<NcaReader> m_reader;
|
||||
MemoryResource * const m_allocator;
|
||||
fssystem::IBufferManager * const m_buffer_manager;
|
||||
public:
|
||||
static Result SetupFsHeaderReader(NcaFsHeaderReader *out, const NcaReader &reader, s32 fs_index);
|
||||
public:
|
||||
NcaFileSystemDriver(std::shared_ptr<NcaReader> reader, MemoryResource *allocator, IBufferManager *buffer_manager) : original_reader(), reader(reader), allocator(allocator), buffer_manager(buffer_manager) {
|
||||
AMS_ASSERT(this->reader != nullptr);
|
||||
NcaFileSystemDriver(std::shared_ptr<NcaReader> reader, MemoryResource *allocator, IBufferManager *buffer_manager) : m_original_reader(), m_reader(reader), m_allocator(allocator), m_buffer_manager(buffer_manager) {
|
||||
AMS_ASSERT(m_reader != nullptr);
|
||||
}
|
||||
|
||||
NcaFileSystemDriver(std::shared_ptr<NcaReader> original_reader, std::shared_ptr<NcaReader> reader, MemoryResource *allocator, IBufferManager *buffer_manager) : original_reader(original_reader), reader(reader), allocator(allocator), buffer_manager(buffer_manager) {
|
||||
AMS_ASSERT(this->reader != nullptr);
|
||||
NcaFileSystemDriver(std::shared_ptr<NcaReader> original_reader, std::shared_ptr<NcaReader> reader, MemoryResource *allocator, IBufferManager *buffer_manager) : m_original_reader(original_reader), m_reader(reader), m_allocator(allocator), m_buffer_manager(buffer_manager) {
|
||||
AMS_ASSERT(m_reader != nullptr);
|
||||
}
|
||||
|
||||
Result OpenRawStorage(std::shared_ptr<fs::IStorage> *out, s32 fs_index);
|
||||
|
||||
@@ -24,126 +24,126 @@ namespace ams::fssystem {
|
||||
private:
|
||||
friend class NcaFileSystemDriver;
|
||||
private:
|
||||
const s32 fs_index;
|
||||
NcaFsHeaderReader * const header_reader;
|
||||
fs::IStorage *data_storage;
|
||||
s64 data_storage_size;
|
||||
fs::IStorage *aes_ctr_ex_table_storage;
|
||||
AesCtrCounterExtendedStorage *aes_ctr_ex_storage_raw;
|
||||
fs::IStorage *aes_ctr_ex_storage;
|
||||
IndirectStorage *indirect_storage;
|
||||
SparseStorage *sparse_storage;
|
||||
const s32 m_fs_index;
|
||||
NcaFsHeaderReader * const m_header_reader;
|
||||
fs::IStorage *m_data_storage;
|
||||
s64 m_data_storage_size;
|
||||
fs::IStorage *m_aes_ctr_ex_table_storage;
|
||||
AesCtrCounterExtendedStorage *m_aes_ctr_ex_storage_raw;
|
||||
fs::IStorage *m_aes_ctr_ex_storage;
|
||||
IndirectStorage *m_indirect_storage;
|
||||
SparseStorage *m_sparse_storage;
|
||||
public:
|
||||
explicit StorageOption(NcaFsHeaderReader *reader) : fs_index(reader->GetFsIndex()), header_reader(reader), data_storage(), data_storage_size(), aes_ctr_ex_table_storage(), aes_ctr_ex_storage_raw(), aes_ctr_ex_storage(), indirect_storage(), sparse_storage() {
|
||||
AMS_ASSERT(this->header_reader != nullptr);
|
||||
explicit StorageOption(NcaFsHeaderReader *reader) : m_fs_index(reader->GetFsIndex()), m_header_reader(reader), m_data_storage(), m_data_storage_size(), m_aes_ctr_ex_table_storage(), m_aes_ctr_ex_storage_raw(), m_aes_ctr_ex_storage(), m_indirect_storage(), m_sparse_storage() {
|
||||
AMS_ASSERT(m_header_reader != nullptr);
|
||||
}
|
||||
|
||||
StorageOption(NcaFsHeaderReader *reader, s32 index) : fs_index(index), header_reader(reader), data_storage(), data_storage_size(), aes_ctr_ex_table_storage(), aes_ctr_ex_storage_raw(), aes_ctr_ex_storage(), indirect_storage(), sparse_storage() {
|
||||
AMS_ASSERT(this->header_reader != nullptr);
|
||||
StorageOption(NcaFsHeaderReader *reader, s32 index) : m_fs_index(index), m_header_reader(reader), m_data_storage(), m_data_storage_size(), m_aes_ctr_ex_table_storage(), m_aes_ctr_ex_storage_raw(), m_aes_ctr_ex_storage(), m_indirect_storage(), m_sparse_storage() {
|
||||
AMS_ASSERT(m_header_reader != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
}
|
||||
|
||||
s32 GetFsIndex() const { return this->fs_index; }
|
||||
NcaFsHeaderReader &GetHeaderReader() { return *this->header_reader; }
|
||||
const NcaFsHeaderReader &GetHeaderReader() const { return *this->header_reader; }
|
||||
fs::SubStorage GetDataStorage() const { return fs::SubStorage(this->data_storage, 0, this->data_storage_size); }
|
||||
fs::IStorage *GetAesCtrExTableStorage() const { return this->aes_ctr_ex_table_storage; }
|
||||
fs::IStorage *GetAesCtrExStorage() const { return this->aes_ctr_ex_storage; }
|
||||
AesCtrCounterExtendedStorage *GetAesCtrExStorageRaw() const { return this->aes_ctr_ex_storage_raw; }
|
||||
IndirectStorage *GetIndirectStorage() const { return this->indirect_storage; }
|
||||
SparseStorage *GetSparseStorage() const { return this->sparse_storage; }
|
||||
s32 GetFsIndex() const { return m_fs_index; }
|
||||
NcaFsHeaderReader &GetHeaderReader() { return *m_header_reader; }
|
||||
const NcaFsHeaderReader &GetHeaderReader() const { return *m_header_reader; }
|
||||
fs::SubStorage GetDataStorage() const { return fs::SubStorage(m_data_storage, 0, m_data_storage_size); }
|
||||
fs::IStorage *GetAesCtrExTableStorage() const { return m_aes_ctr_ex_table_storage; }
|
||||
fs::IStorage *GetAesCtrExStorage() const { return m_aes_ctr_ex_storage; }
|
||||
AesCtrCounterExtendedStorage *GetAesCtrExStorageRaw() const { return m_aes_ctr_ex_storage_raw; }
|
||||
IndirectStorage *GetIndirectStorage() const { return m_indirect_storage; }
|
||||
SparseStorage *GetSparseStorage() const { return m_sparse_storage; }
|
||||
private:
|
||||
void SetDataStorage(fs::IStorage *storage, s64 size) {
|
||||
AMS_ASSERT(storage != nullptr);
|
||||
AMS_ASSERT(size >= 0);
|
||||
this->data_storage = storage;
|
||||
this->data_storage_size = size;
|
||||
m_data_storage = storage;
|
||||
m_data_storage_size = size;
|
||||
}
|
||||
|
||||
void SetAesCtrExTableStorage(fs::IStorage *storage) { AMS_ASSERT(storage != nullptr); this->aes_ctr_ex_table_storage = storage; }
|
||||
void SetAesCtrExStorage(fs::IStorage *storage) { AMS_ASSERT(storage != nullptr); this->aes_ctr_ex_storage = storage; }
|
||||
void SetAesCtrExStorageRaw(AesCtrCounterExtendedStorage *storage) { AMS_ASSERT(storage != nullptr); this->aes_ctr_ex_storage_raw = storage; }
|
||||
void SetIndirectStorage(IndirectStorage *storage) { AMS_ASSERT(storage != nullptr); this->indirect_storage = storage; }
|
||||
void SetSparseStorage(SparseStorage *storage) { AMS_ASSERT(storage != nullptr); this->sparse_storage = storage; }
|
||||
void SetAesCtrExTableStorage(fs::IStorage *storage) { AMS_ASSERT(storage != nullptr); m_aes_ctr_ex_table_storage = storage; }
|
||||
void SetAesCtrExStorage(fs::IStorage *storage) { AMS_ASSERT(storage != nullptr); m_aes_ctr_ex_storage = storage; }
|
||||
void SetAesCtrExStorageRaw(AesCtrCounterExtendedStorage *storage) { AMS_ASSERT(storage != nullptr); m_aes_ctr_ex_storage_raw = storage; }
|
||||
void SetIndirectStorage(IndirectStorage *storage) { AMS_ASSERT(storage != nullptr); m_indirect_storage = storage; }
|
||||
void SetSparseStorage(SparseStorage *storage) { AMS_ASSERT(storage != nullptr); m_sparse_storage = storage; }
|
||||
};
|
||||
|
||||
class NcaFileSystemDriver::StorageOptionWithHeaderReader : public NcaFileSystemDriver::StorageOption {
|
||||
private:
|
||||
NcaFsHeaderReader header_reader_data;
|
||||
NcaFsHeaderReader m_header_reader_data;
|
||||
public:
|
||||
explicit StorageOptionWithHeaderReader(s32 index) : StorageOption(std::addressof(header_reader_data), index) { /* ... */ }
|
||||
explicit StorageOptionWithHeaderReader(s32 index) : StorageOption(std::addressof(m_header_reader_data), index) { /* ... */ }
|
||||
};
|
||||
|
||||
class NcaFileSystemDriver::BaseStorage {
|
||||
private:
|
||||
std::unique_ptr<fs::IStorage> storage;
|
||||
fs::SubStorage sub_storage;
|
||||
s64 storage_offset;
|
||||
NcaAesCtrUpperIv aes_ctr_upper_iv;
|
||||
std::unique_ptr<fs::IStorage> m_storage;
|
||||
fs::SubStorage m_sub_storage;
|
||||
s64 m_storage_offset;
|
||||
NcaAesCtrUpperIv m_aes_ctr_upper_iv;
|
||||
public:
|
||||
BaseStorage() : storage(), sub_storage(), storage_offset(0) {
|
||||
this->aes_ctr_upper_iv.value = 0;
|
||||
BaseStorage() : m_storage(), m_sub_storage(), m_storage_offset(0) {
|
||||
m_aes_ctr_upper_iv.value = 0;
|
||||
}
|
||||
|
||||
explicit BaseStorage(const fs::SubStorage &ss) : storage(), sub_storage(ss), storage_offset(0) {
|
||||
this->aes_ctr_upper_iv.value = 0;
|
||||
explicit BaseStorage(const fs::SubStorage &ss) : m_storage(), m_sub_storage(ss), m_storage_offset(0) {
|
||||
m_aes_ctr_upper_iv.value = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
BaseStorage(T s, s64 offset, s64 size) : storage(), sub_storage(s, offset, size), storage_offset(0) {
|
||||
this->aes_ctr_upper_iv.value = 0;
|
||||
BaseStorage(T s, s64 offset, s64 size) : m_storage(), m_sub_storage(s, offset, size), m_storage_offset(0) {
|
||||
m_aes_ctr_upper_iv.value = 0;
|
||||
}
|
||||
|
||||
void SetStorage(std::unique_ptr<fs::IStorage> &&storage) {
|
||||
this->storage = std::move(storage);
|
||||
m_storage = std::move(storage);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SetStorage(T storage, s64 offset, s64 size) {
|
||||
this->sub_storage = fs::SubStorage(storage, offset, size);
|
||||
m_sub_storage = fs::SubStorage(storage, offset, size);
|
||||
}
|
||||
|
||||
std::unique_ptr<fs::IStorage> MakeStorage() {
|
||||
if (this->storage != nullptr) {
|
||||
return std::move(this->storage);
|
||||
if (m_storage != nullptr) {
|
||||
return std::move(m_storage);
|
||||
}
|
||||
return std::make_unique<fs::SubStorage>(this->sub_storage);
|
||||
return std::make_unique<fs::SubStorage>(m_sub_storage);
|
||||
}
|
||||
|
||||
std::unique_ptr<fs::IStorage> GetStorage() {
|
||||
return std::move(this->storage);
|
||||
return std::move(m_storage);
|
||||
}
|
||||
|
||||
Result GetSubStorage(fs::SubStorage *out, s64 offset, s64 size) {
|
||||
s64 storage_size = 0;
|
||||
|
||||
if (this->storage != nullptr) {
|
||||
R_TRY(this->storage->GetSize(std::addressof(storage_size)));
|
||||
if (m_storage != nullptr) {
|
||||
R_TRY(m_storage->GetSize(std::addressof(storage_size)));
|
||||
R_UNLESS(offset + size <= storage_size, fs::ResultNcaBaseStorageOutOfRangeA());
|
||||
*out = fs::SubStorage(this->storage.get(), offset, size);
|
||||
*out = fs::SubStorage(m_storage.get(), offset, size);
|
||||
} else {
|
||||
R_TRY(this->sub_storage.GetSize(std::addressof(storage_size)));
|
||||
R_TRY(m_sub_storage.GetSize(std::addressof(storage_size)));
|
||||
R_UNLESS(offset + size <= storage_size, fs::ResultNcaBaseStorageOutOfRangeA());
|
||||
*out = fs::SubStorage(std::addressof(this->sub_storage), offset, size);
|
||||
*out = fs::SubStorage(std::addressof(m_sub_storage), offset, size);
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void SetStorageOffset(s64 offset) {
|
||||
this->storage_offset = offset;
|
||||
m_storage_offset = offset;
|
||||
}
|
||||
|
||||
s64 GetStorageOffset() const {
|
||||
return this->storage_offset;
|
||||
return m_storage_offset;
|
||||
}
|
||||
|
||||
void SetAesCtrUpperIv(NcaAesCtrUpperIv v) {
|
||||
this->aes_ctr_upper_iv = v;
|
||||
m_aes_ctr_upper_iv = v;
|
||||
}
|
||||
|
||||
const NcaAesCtrUpperIv GetAesCtrUpperIv() const {
|
||||
return this->aes_ctr_upper_iv;
|
||||
return m_aes_ctr_upper_iv;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ namespace ams::fssystem {
|
||||
class PartitionFile;
|
||||
class PartitionDirectory;
|
||||
private:
|
||||
fs::IStorage *base_storage;
|
||||
MetaType *meta_data;
|
||||
bool initialized;
|
||||
size_t meta_data_size;
|
||||
std::unique_ptr<MetaType> unique_meta_data;
|
||||
std::shared_ptr<fs::IStorage> shared_storage;
|
||||
fs::IStorage *m_base_storage;
|
||||
MetaType *m_meta_data;
|
||||
bool m_initialized;
|
||||
size_t m_meta_data_size;
|
||||
std::unique_ptr<MetaType> m_unique_meta_data;
|
||||
std::shared_ptr<fs::IStorage> m_shared_storage;
|
||||
private:
|
||||
Result Initialize(fs::IStorage *base_storage, MemoryResource *allocator);
|
||||
public:
|
||||
|
||||
@@ -76,15 +76,15 @@ namespace ams::fssystem {
|
||||
|
||||
using PartitionEntry = typename Format::PartitionEntry;
|
||||
protected:
|
||||
bool initialized;
|
||||
PartitionFileSystemHeader *header;
|
||||
PartitionEntry *entries;
|
||||
char *name_table;
|
||||
size_t meta_data_size;
|
||||
MemoryResource *allocator;
|
||||
char *buffer;
|
||||
bool m_initialized;
|
||||
PartitionFileSystemHeader *m_header;
|
||||
PartitionEntry *m_entries;
|
||||
char *m_name_table;
|
||||
size_t m_meta_data_size;
|
||||
MemoryResource *m_allocator;
|
||||
char *m_buffer;
|
||||
public:
|
||||
PartitionFileSystemMetaCore() : initialized(false), allocator(nullptr), buffer(nullptr) { /* ... */ }
|
||||
PartitionFileSystemMetaCore() : m_initialized(false), m_allocator(nullptr), m_buffer(nullptr) { /* ... */ }
|
||||
~PartitionFileSystemMetaCore();
|
||||
|
||||
Result Initialize(fs::IStorage *storage, MemoryResource *allocator);
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace ams::fssystem {
|
||||
class PooledBuffer {
|
||||
NON_COPYABLE(PooledBuffer);
|
||||
private:
|
||||
char *buffer;
|
||||
size_t size;
|
||||
char *m_buffer;
|
||||
size_t m_size;
|
||||
private:
|
||||
static size_t GetAllocatableSizeMaxCore(bool large);
|
||||
public:
|
||||
@@ -34,14 +34,14 @@ namespace ams::fssystem {
|
||||
static size_t GetAllocatableParticularlyLargeSizeMax() { return GetAllocatableSizeMaxCore(true); }
|
||||
private:
|
||||
void Swap(PooledBuffer &rhs) {
|
||||
std::swap(this->buffer, rhs.buffer);
|
||||
std::swap(this->size, rhs.size);
|
||||
std::swap(m_buffer, rhs.m_buffer);
|
||||
std::swap(m_size, rhs.m_size);
|
||||
}
|
||||
public:
|
||||
/* Constructor/Destructor. */
|
||||
constexpr PooledBuffer() : buffer(), size() { /* ... */ }
|
||||
constexpr PooledBuffer() : m_buffer(), m_size() { /* ... */ }
|
||||
|
||||
PooledBuffer(size_t ideal_size, size_t required_size) : buffer(), size() {
|
||||
PooledBuffer(size_t ideal_size, size_t required_size) : m_buffer(), m_size() {
|
||||
this->Allocate(ideal_size, required_size);
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ namespace ams::fssystem {
|
||||
}
|
||||
|
||||
/* Move and assignment. */
|
||||
explicit PooledBuffer(PooledBuffer &&rhs) : buffer(rhs.buffer), size(rhs.size) {
|
||||
rhs.buffer = nullptr;
|
||||
rhs.size = 0;
|
||||
explicit PooledBuffer(PooledBuffer &&rhs) : m_buffer(rhs.m_buffer), m_size(rhs.m_size) {
|
||||
rhs.m_buffer = nullptr;
|
||||
rhs.m_size = 0;
|
||||
}
|
||||
|
||||
PooledBuffer &operator=(PooledBuffer &&rhs) {
|
||||
@@ -74,17 +74,17 @@ namespace ams::fssystem {
|
||||
void Deallocate() {
|
||||
/* Shrink the buffer to empty. */
|
||||
this->Shrink(0);
|
||||
AMS_ASSERT(this->buffer == nullptr);
|
||||
AMS_ASSERT(m_buffer == nullptr);
|
||||
}
|
||||
|
||||
char *GetBuffer() const {
|
||||
AMS_ASSERT(this->buffer != nullptr);
|
||||
return this->buffer;
|
||||
AMS_ASSERT(m_buffer != nullptr);
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
size_t GetSize() const {
|
||||
AMS_ASSERT(this->buffer != nullptr);
|
||||
return this->size;
|
||||
AMS_ASSERT(m_buffer != nullptr);
|
||||
return m_size;
|
||||
}
|
||||
private:
|
||||
void AllocateCore(size_t ideal_size, size_t required_size, bool large);
|
||||
|
||||
@@ -27,14 +27,14 @@ namespace ams::fssystem {
|
||||
public:
|
||||
using RomFileTable = fs::HierarchicalRomFileTable;
|
||||
private:
|
||||
RomFileTable rom_file_table;
|
||||
fs::IStorage *base_storage;
|
||||
std::shared_ptr<fs::IStorage> shared_storage;
|
||||
std::unique_ptr<fs::IStorage> dir_bucket_storage;
|
||||
std::unique_ptr<fs::IStorage> dir_entry_storage;
|
||||
std::unique_ptr<fs::IStorage> file_bucket_storage;
|
||||
std::unique_ptr<fs::IStorage> file_entry_storage;
|
||||
s64 entry_size;
|
||||
RomFileTable m_rom_file_table;
|
||||
fs::IStorage *m_base_storage;
|
||||
std::shared_ptr<fs::IStorage> m_shared_storage;
|
||||
std::unique_ptr<fs::IStorage> m_dir_bucket_storage;
|
||||
std::unique_ptr<fs::IStorage> m_dir_entry_storage;
|
||||
std::unique_ptr<fs::IStorage> m_file_bucket_storage;
|
||||
std::unique_ptr<fs::IStorage> m_file_entry_storage;
|
||||
s64 m_entry_size;
|
||||
private:
|
||||
Result GetFileInfo(RomFileTable::FileInfo *out, const char *path);
|
||||
public:
|
||||
|
||||
@@ -65,9 +65,9 @@ namespace ams::fssystem {
|
||||
}
|
||||
};
|
||||
private:
|
||||
ZeroStorage zero_storage;
|
||||
ZeroStorage m_zero_storage;
|
||||
public:
|
||||
SparseStorage() : IndirectStorage(), zero_storage() { /* ... */ }
|
||||
SparseStorage() : IndirectStorage(), m_zero_storage() { /* ... */ }
|
||||
virtual ~SparseStorage() { /* ... */ }
|
||||
|
||||
using IndirectStorage::Initialize;
|
||||
@@ -95,7 +95,7 @@ namespace ams::fssystem {
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
||||
private:
|
||||
void SetZeroStorage() {
|
||||
return this->SetStorage(1, std::addressof(this->zero_storage), 0, std::numeric_limits<s64>::max());
|
||||
return this->SetStorage(1, std::addressof(m_zero_storage), 0, std::numeric_limits<s64>::max());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace ams::fssystem {
|
||||
using PathResolutionFileSystem = impl::IPathResolutionFileSystem<SubDirectoryFileSystem>;
|
||||
friend class impl::IPathResolutionFileSystem<SubDirectoryFileSystem>;
|
||||
private:
|
||||
char *base_path;
|
||||
size_t base_path_len;
|
||||
char *m_base_path;
|
||||
size_t m_base_path_len;
|
||||
public:
|
||||
SubDirectoryFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs, const char *bp, bool unc = false);
|
||||
SubDirectoryFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, const char *bp, bool unc = false);
|
||||
|
||||
@@ -48,9 +48,9 @@ namespace ams::fssystem {
|
||||
private:
|
||||
static s32 GetThreadPriorityByAccessPriority(AccessMode mode);
|
||||
private:
|
||||
ScopedThreadPriorityChanger scoped_changer;
|
||||
ScopedThreadPriorityChanger m_scoped_changer;
|
||||
public:
|
||||
ALWAYS_INLINE explicit ScopedThreadPriorityChangerByAccessPriority(AccessMode mode) : scoped_changer(GetThreadPriorityByAccessPriority(mode), ScopedThreadPriorityChanger::Mode::Absolute) {
|
||||
ALWAYS_INLINE explicit ScopedThreadPriorityChangerByAccessPriority(AccessMode mode) : m_scoped_changer(GetThreadPriorityByAccessPriority(mode), ScopedThreadPriorityChanger::Mode::Absolute) {
|
||||
/* ... */
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ams::fssystem {
|
||||
Result IterateDirectoryRecursivelyImpl(fs::fsa::IFileSystem *fs, char *work_path, size_t work_path_size, fs::DirectoryEntry *dir_ent, OnEnterDir on_enter_dir, OnExitDir on_exit_dir, OnFile on_file) {
|
||||
/* Open the directory. */
|
||||
std::unique_ptr<fs::fsa::IDirectory> dir;
|
||||
R_TRY(fs->OpenDirectory(&dir, work_path, fs::OpenDirectoryMode_All));
|
||||
R_TRY(fs->OpenDirectory(std::addressof(dir), work_path, fs::OpenDirectoryMode_All));
|
||||
|
||||
const size_t parent_len = strnlen(work_path, work_path_size - 1);
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ams::fssystem {
|
||||
while (true) {
|
||||
/* Read a single entry. */
|
||||
s64 read_count = 0;
|
||||
R_TRY(dir->Read(&read_count, dir_ent, 1));
|
||||
R_TRY(dir->Read(std::addressof(read_count), dir_ent, 1));
|
||||
|
||||
/* If we're out of entries, we're done. */
|
||||
if (read_count == 0) {
|
||||
@@ -106,7 +106,7 @@ namespace ams::fssystem {
|
||||
Result IterateDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *root_path, OnEnterDir on_enter_dir, OnExitDir on_exit_dir, OnFile on_file) {
|
||||
fs::DirectoryEntry dir_entry = {};
|
||||
char work_path[fs::EntryNameLengthMax + 1] = {};
|
||||
return IterateDirectoryRecursively(fs, root_path, work_path, sizeof(work_path), &dir_entry, on_enter_dir, on_exit_dir, on_file);
|
||||
return IterateDirectoryRecursively(fs, root_path, work_path, sizeof(work_path), std::addressof(dir_entry), on_enter_dir, on_exit_dir, on_file);
|
||||
}
|
||||
|
||||
template<typename OnEnterDir, typename OnExitDir, typename OnFile>
|
||||
|
||||
@@ -26,24 +26,24 @@ namespace ams::fssystem::impl {
|
||||
class IPathResolutionFileSystem : public fs::fsa::IFileSystem, public fs::impl::Newable {
|
||||
NON_COPYABLE(IPathResolutionFileSystem);
|
||||
private:
|
||||
std::shared_ptr<fs::fsa::IFileSystem> shared_fs;
|
||||
std::unique_ptr<fs::fsa::IFileSystem> unique_fs;
|
||||
bool unc_preserved;
|
||||
std::shared_ptr<fs::fsa::IFileSystem> m_shared_fs;
|
||||
std::unique_ptr<fs::fsa::IFileSystem> m_unique_fs;
|
||||
bool m_unc_preserved;
|
||||
protected:
|
||||
fs::fsa::IFileSystem * const base_fs;
|
||||
fs::fsa::IFileSystem * const m_base_fs;
|
||||
public:
|
||||
IPathResolutionFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs, bool unc = false) : shared_fs(std::move(fs)), unc_preserved(unc), base_fs(shared_fs.get()) {
|
||||
IPathResolutionFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs, bool unc = false) : m_shared_fs(std::move(fs)), m_unc_preserved(unc), m_base_fs(m_shared_fs.get()) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
IPathResolutionFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, bool unc = false) : unique_fs(std::move(fs)), unc_preserved(unc), base_fs(unique_fs.get()) {
|
||||
IPathResolutionFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, bool unc = false) : m_unique_fs(std::move(fs)), m_unc_preserved(unc), m_base_fs(m_unique_fs.get()) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
virtual ~IPathResolutionFileSystem() { /* ... */ }
|
||||
protected:
|
||||
constexpr inline bool IsUncPreserved() const {
|
||||
return this->unc_preserved;
|
||||
return m_unc_preserved;
|
||||
}
|
||||
public:
|
||||
virtual Result DoCreateFile(const char *path, s64 size, int option) override {
|
||||
@@ -51,7 +51,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->CreateFile(full_path, size, option);
|
||||
return m_base_fs->CreateFile(full_path, size, option);
|
||||
}
|
||||
|
||||
virtual Result DoDeleteFile(const char *path) override {
|
||||
@@ -59,7 +59,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->DeleteFile(full_path);
|
||||
return m_base_fs->DeleteFile(full_path);
|
||||
}
|
||||
|
||||
virtual Result DoCreateDirectory(const char *path) override {
|
||||
@@ -67,7 +67,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->CreateDirectory(full_path);
|
||||
return m_base_fs->CreateDirectory(full_path);
|
||||
}
|
||||
|
||||
virtual Result DoDeleteDirectory(const char *path) override {
|
||||
@@ -75,7 +75,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->DeleteDirectory(full_path);
|
||||
return m_base_fs->DeleteDirectory(full_path);
|
||||
}
|
||||
|
||||
virtual Result DoDeleteDirectoryRecursively(const char *path) override {
|
||||
@@ -83,7 +83,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->DeleteDirectoryRecursively(full_path);
|
||||
return m_base_fs->DeleteDirectoryRecursively(full_path);
|
||||
}
|
||||
|
||||
virtual Result DoRenameFile(const char *old_path, const char *new_path) override {
|
||||
@@ -93,7 +93,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(new_full_path, sizeof(new_full_path), new_path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->RenameFile(old_full_path, new_full_path);
|
||||
return m_base_fs->RenameFile(old_full_path, new_full_path);
|
||||
}
|
||||
|
||||
virtual Result DoRenameDirectory(const char *old_path, const char *new_path) override {
|
||||
@@ -103,7 +103,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(new_full_path, sizeof(new_full_path), new_path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->RenameDirectory(old_full_path, new_full_path);
|
||||
return m_base_fs->RenameDirectory(old_full_path, new_full_path);
|
||||
}
|
||||
|
||||
virtual Result DoGetEntryType(fs::DirectoryEntryType *out, const char *path) override {
|
||||
@@ -111,7 +111,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->GetEntryType(out, full_path);
|
||||
return m_base_fs->GetEntryType(out, full_path);
|
||||
}
|
||||
|
||||
virtual Result DoOpenFile(std::unique_ptr<fs::fsa::IFile> *out_file, const char *path, fs::OpenMode mode) override {
|
||||
@@ -119,7 +119,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->OpenFile(out_file, full_path, mode);
|
||||
return m_base_fs->OpenFile(out_file, full_path, mode);
|
||||
}
|
||||
|
||||
virtual Result DoOpenDirectory(std::unique_ptr<fs::fsa::IDirectory> *out_dir, const char *path, fs::OpenDirectoryMode mode) override {
|
||||
@@ -127,12 +127,12 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->OpenDirectory(out_dir, full_path, mode);
|
||||
return m_base_fs->OpenDirectory(out_dir, full_path, mode);
|
||||
}
|
||||
|
||||
virtual Result DoCommit() override {
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->Commit();
|
||||
return m_base_fs->Commit();
|
||||
}
|
||||
|
||||
virtual Result DoGetFreeSpaceSize(s64 *out, const char *path) override {
|
||||
@@ -140,7 +140,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->GetFreeSpaceSize(out, full_path);
|
||||
return m_base_fs->GetFreeSpaceSize(out, full_path);
|
||||
}
|
||||
|
||||
virtual Result DoGetTotalSpaceSize(s64 *out, const char *path) override {
|
||||
@@ -148,7 +148,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->GetTotalSpaceSize(out, full_path);
|
||||
return m_base_fs->GetTotalSpaceSize(out, full_path);
|
||||
}
|
||||
|
||||
virtual Result DoCleanDirectoryRecursively(const char *path) override {
|
||||
@@ -156,7 +156,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->CleanDirectoryRecursively(full_path);
|
||||
return m_base_fs->CleanDirectoryRecursively(full_path);
|
||||
}
|
||||
|
||||
virtual Result DoGetFileTimeStampRaw(fs::FileTimeStampRaw *out, const char *path) override {
|
||||
@@ -164,7 +164,7 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->GetFileTimeStampRaw(out, full_path);
|
||||
return m_base_fs->GetFileTimeStampRaw(out, full_path);
|
||||
}
|
||||
|
||||
virtual Result DoQueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fs::fsa::QueryId query, const char *path) override {
|
||||
@@ -172,23 +172,23 @@ namespace ams::fssystem::impl {
|
||||
R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
|
||||
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->QueryEntry(dst, dst_size, src, src_size, query, full_path);
|
||||
return m_base_fs->QueryEntry(dst, dst_size, src, src_size, query, full_path);
|
||||
}
|
||||
|
||||
/* These aren't accessible as commands. */
|
||||
virtual Result DoCommitProvisionally(s64 counter) override {
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->CommitProvisionally(counter);
|
||||
return m_base_fs->CommitProvisionally(counter);
|
||||
}
|
||||
|
||||
virtual Result DoRollback() override {
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->Rollback();
|
||||
return m_base_fs->Rollback();
|
||||
}
|
||||
|
||||
virtual Result DoFlush() override {
|
||||
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
|
||||
return this->base_fs->Flush();
|
||||
return m_base_fs->Flush();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -61,19 +61,19 @@ namespace ams::fssystem::save {
|
||||
Flag_RealData = (1 << 10),
|
||||
};
|
||||
private:
|
||||
IBufferManager *buffer_manager;
|
||||
os::SdkRecursiveMutex *mutex;
|
||||
std::unique_ptr<CacheEntry[], ::ams::fs::impl::Deleter> entries;
|
||||
IStorage *data_storage;
|
||||
Result last_result;
|
||||
s64 data_size;
|
||||
size_t verification_block_size;
|
||||
size_t verification_block_shift;
|
||||
CacheIndex invalidate_index;
|
||||
s32 max_cache_entry_count;
|
||||
s32 flags;
|
||||
s32 buffer_level;
|
||||
fs::StorageType storage_type;
|
||||
IBufferManager *m_buffer_manager;
|
||||
os::SdkRecursiveMutex *m_mutex;
|
||||
std::unique_ptr<CacheEntry[], ::ams::fs::impl::Deleter> m_entries;
|
||||
IStorage *m_data_storage;
|
||||
Result m_last_result;
|
||||
s64 m_data_size;
|
||||
size_t m_verification_block_size;
|
||||
size_t m_verification_block_shift;
|
||||
CacheIndex m_invalidate_index;
|
||||
s32 m_max_cache_entry_count;
|
||||
s32 m_flags;
|
||||
s32 m_buffer_level;
|
||||
fs::StorageType m_storage_type;
|
||||
public:
|
||||
BlockCacheBufferedStorage();
|
||||
virtual ~BlockCacheBufferedStorage() override;
|
||||
@@ -96,31 +96,31 @@ namespace ams::fssystem::save {
|
||||
Result OnRollback();
|
||||
|
||||
bool IsEnabledKeepBurstMode() const {
|
||||
return (this->flags & Flag_KeepBurstMode) != 0;
|
||||
return (m_flags & Flag_KeepBurstMode) != 0;
|
||||
}
|
||||
|
||||
bool IsRealDataCache() const {
|
||||
return (this->flags & Flag_RealData) != 0;
|
||||
return (m_flags & Flag_RealData) != 0;
|
||||
}
|
||||
|
||||
void SetKeepBurstMode(bool en) {
|
||||
if (en) {
|
||||
this->flags |= Flag_KeepBurstMode;
|
||||
m_flags |= Flag_KeepBurstMode;
|
||||
} else {
|
||||
this->flags &= ~Flag_KeepBurstMode;
|
||||
m_flags &= ~Flag_KeepBurstMode;
|
||||
}
|
||||
}
|
||||
|
||||
void SetRealDataCache(bool en) {
|
||||
if (en) {
|
||||
this->flags |= Flag_RealData;
|
||||
m_flags |= Flag_RealData;
|
||||
} else {
|
||||
this->flags &= ~Flag_RealData;
|
||||
m_flags &= ~Flag_RealData;
|
||||
}
|
||||
}
|
||||
private:
|
||||
s32 GetMaxCacheEntryCount() const {
|
||||
return this->max_cache_entry_count;
|
||||
return m_max_cache_entry_count;
|
||||
}
|
||||
|
||||
Result ClearImpl(s64 offset, s64 size);
|
||||
|
||||
@@ -30,16 +30,16 @@ namespace ams::fssystem::save {
|
||||
class UniqueCache;
|
||||
class SharedCache;
|
||||
private:
|
||||
fs::SubStorage base_storage;
|
||||
IBufferManager *buffer_manager;
|
||||
size_t block_size;
|
||||
s64 base_storage_size;
|
||||
std::unique_ptr<Cache[]> caches;
|
||||
s32 cache_count;
|
||||
Cache *next_acquire_cache;
|
||||
Cache *next_fetch_cache;
|
||||
os::SdkMutex mutex;
|
||||
bool bulk_read_enabled;
|
||||
fs::SubStorage m_base_storage;
|
||||
IBufferManager *m_buffer_manager;
|
||||
size_t m_block_size;
|
||||
s64 m_base_storage_size;
|
||||
std::unique_ptr<Cache[]> m_caches;
|
||||
s32 m_cache_count;
|
||||
Cache *m_next_acquire_cache;
|
||||
Cache *m_next_fetch_cache;
|
||||
os::SdkMutex m_mutex;
|
||||
bool m_bulk_read_enabled;
|
||||
public:
|
||||
BufferedStorage();
|
||||
virtual ~BufferedStorage();
|
||||
@@ -47,7 +47,7 @@ namespace ams::fssystem::save {
|
||||
Result Initialize(fs::SubStorage base_storage, IBufferManager *buffer_manager, size_t block_size, s32 buffer_count);
|
||||
void Finalize();
|
||||
|
||||
bool IsInitialized() const { return this->caches != nullptr; }
|
||||
bool IsInitialized() const { return m_caches != nullptr; }
|
||||
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override;
|
||||
@@ -61,9 +61,9 @@ namespace ams::fssystem::save {
|
||||
|
||||
void InvalidateCaches();
|
||||
|
||||
IBufferManager *GetBufferManager() const { return this->buffer_manager; }
|
||||
IBufferManager *GetBufferManager() const { return m_buffer_manager; }
|
||||
|
||||
void EnableBulkRead() { this->bulk_read_enabled = true; }
|
||||
void EnableBulkRead() { m_bulk_read_enabled = true; }
|
||||
private:
|
||||
Result PrepareAllocation();
|
||||
Result ControlDirtiness();
|
||||
|
||||
@@ -82,8 +82,8 @@ namespace ams::fssystem::save {
|
||||
};
|
||||
static_assert(util::is_pod<InputParam>::value);
|
||||
private:
|
||||
fs::SubStorage storage;
|
||||
HierarchicalIntegrityVerificationMetaInformation meta;
|
||||
fs::SubStorage m_storage;
|
||||
HierarchicalIntegrityVerificationMetaInformation m_meta;
|
||||
public:
|
||||
static Result QuerySize(HierarchicalIntegrityVerificationSizeSet *out, const InputParam &input_param, s32 layer_count, s64 data_size);
|
||||
/* TODO Format */
|
||||
@@ -94,10 +94,10 @@ namespace ams::fssystem::save {
|
||||
Result Initialize(fs::SubStorage meta_storage);
|
||||
void Finalize();
|
||||
|
||||
u32 GetMasterHashSize() const { return this->meta.master_hash_size; }
|
||||
u32 GetMasterHashSize() const { return m_meta.master_hash_size; }
|
||||
void GetLevelHashInfo(HierarchicalIntegrityVerificationInformation *out) {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
*out = this->meta.level_hash_info;
|
||||
*out = m_meta.level_hash_info;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,19 +124,19 @@ namespace ams::fssystem::save {
|
||||
DataStorage = 6,
|
||||
};
|
||||
private:
|
||||
fs::SubStorage storages[DataStorage + 1];
|
||||
fs::SubStorage m_storages[DataStorage + 1];
|
||||
public:
|
||||
void SetMasterHashStorage(fs::SubStorage s) { this->storages[MasterStorage] = s; }
|
||||
void SetLayer1HashStorage(fs::SubStorage s) { this->storages[Layer1Storage] = s; }
|
||||
void SetLayer2HashStorage(fs::SubStorage s) { this->storages[Layer2Storage] = s; }
|
||||
void SetLayer3HashStorage(fs::SubStorage s) { this->storages[Layer3Storage] = s; }
|
||||
void SetLayer4HashStorage(fs::SubStorage s) { this->storages[Layer4Storage] = s; }
|
||||
void SetLayer5HashStorage(fs::SubStorage s) { this->storages[Layer5Storage] = s; }
|
||||
void SetDataStorage(fs::SubStorage s) { this->storages[DataStorage] = s; }
|
||||
void SetMasterHashStorage(fs::SubStorage s) { m_storages[MasterStorage] = s; }
|
||||
void SetLayer1HashStorage(fs::SubStorage s) { m_storages[Layer1Storage] = s; }
|
||||
void SetLayer2HashStorage(fs::SubStorage s) { m_storages[Layer2Storage] = s; }
|
||||
void SetLayer3HashStorage(fs::SubStorage s) { m_storages[Layer3Storage] = s; }
|
||||
void SetLayer4HashStorage(fs::SubStorage s) { m_storages[Layer4Storage] = s; }
|
||||
void SetLayer5HashStorage(fs::SubStorage s) { m_storages[Layer5Storage] = s; }
|
||||
void SetDataStorage(fs::SubStorage s) { m_storages[DataStorage] = s; }
|
||||
|
||||
fs::SubStorage &operator[](s32 index) {
|
||||
AMS_ASSERT(MasterStorage <= index && index <= DataStorage);
|
||||
return this->storages[index];
|
||||
return m_storages[index];
|
||||
}
|
||||
};
|
||||
private:
|
||||
@@ -146,15 +146,15 @@ namespace ams::fssystem::save {
|
||||
s_generate_random = func;
|
||||
}
|
||||
private:
|
||||
FileSystemBufferManagerSet *buffers;
|
||||
os::SdkRecursiveMutex *mutex;
|
||||
IntegrityVerificationStorage verify_storages[MaxLayers - 1];
|
||||
BlockCacheBufferedStorage buffer_storages[MaxLayers - 1];
|
||||
s64 data_size;
|
||||
s32 max_layers;
|
||||
bool is_written_for_rollback;
|
||||
FileSystemBufferManagerSet *m_buffers;
|
||||
os::SdkRecursiveMutex *m_mutex;
|
||||
IntegrityVerificationStorage m_verify_storages[MaxLayers - 1];
|
||||
BlockCacheBufferedStorage m_buffer_storages[MaxLayers - 1];
|
||||
s64 m_data_size;
|
||||
s32 m_max_layers;
|
||||
bool m_is_written_for_rollback;
|
||||
public:
|
||||
HierarchicalIntegrityVerificationStorage() : buffers(nullptr), mutex(nullptr), data_size(-1), is_written_for_rollback(false) { /* ... */ }
|
||||
HierarchicalIntegrityVerificationStorage() : m_buffers(nullptr), m_mutex(nullptr), m_data_size(-1), m_is_written_for_rollback(false) { /* ... */ }
|
||||
virtual ~HierarchicalIntegrityVerificationStorage() override { this->Finalize(); }
|
||||
|
||||
Result Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::SdkRecursiveMutex *mtx, fs::StorageType storage_type);
|
||||
@@ -175,30 +175,30 @@ namespace ams::fssystem::save {
|
||||
Result OnRollback();
|
||||
|
||||
bool IsInitialized() const {
|
||||
return this->data_size >= 0;
|
||||
return m_data_size >= 0;
|
||||
}
|
||||
|
||||
bool IsWrittenForRollback() const {
|
||||
return this->is_written_for_rollback;
|
||||
return m_is_written_for_rollback;
|
||||
}
|
||||
|
||||
FileSystemBufferManagerSet *GetBuffers() {
|
||||
return this->buffers;
|
||||
return m_buffers;
|
||||
}
|
||||
|
||||
void GetParameters(HierarchicalIntegrityVerificationStorageControlArea::InputParam *out) const {
|
||||
AMS_ASSERT(out != nullptr);
|
||||
for (auto level = 0; level <= this->max_layers - 2; ++level) {
|
||||
out->level_block_size[level] = static_cast<size_t>(this->verify_storages[level].GetBlockSize());
|
||||
for (auto level = 0; level <= m_max_layers - 2; ++level) {
|
||||
out->level_block_size[level] = static_cast<size_t>(m_verify_storages[level].GetBlockSize());
|
||||
}
|
||||
}
|
||||
|
||||
s64 GetL1HashVerificationBlockSize() const {
|
||||
return this->verify_storages[this->max_layers - 2].GetBlockSize();
|
||||
return m_verify_storages[m_max_layers - 2].GetBlockSize();
|
||||
}
|
||||
|
||||
fs::SubStorage GetL1HashStorage() {
|
||||
return fs::SubStorage(std::addressof(this->buffer_storages[this->max_layers - 3]), 0, util::DivideUp(this->data_size, this->GetL1HashVerificationBlockSize()));
|
||||
return fs::SubStorage(std::addressof(m_buffer_storages[m_max_layers - 3]), 0, util::DivideUp(m_data_size, this->GetL1HashVerificationBlockSize()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -37,18 +37,18 @@ namespace ams::fssystem::save {
|
||||
};
|
||||
static_assert(util::is_pod<BlockHash>::value);
|
||||
private:
|
||||
fs::SubStorage hash_storage;
|
||||
fs::SubStorage data_storage;
|
||||
s64 verification_block_size;
|
||||
s64 verification_block_order;
|
||||
s64 upper_layer_verification_block_size;
|
||||
s64 upper_layer_verification_block_order;
|
||||
IBufferManager *buffer_manager;
|
||||
fs::HashSalt salt;
|
||||
bool is_real_data;
|
||||
fs::StorageType storage_type;
|
||||
fs::SubStorage m_hash_storage;
|
||||
fs::SubStorage m_data_storage;
|
||||
s64 m_verification_block_size;
|
||||
s64 m_verification_block_order;
|
||||
s64 m_upper_layer_verification_block_size;
|
||||
s64 m_upper_layer_verification_block_order;
|
||||
IBufferManager *m_buffer_manager;
|
||||
fs::HashSalt m_salt;
|
||||
bool m_is_real_data;
|
||||
fs::StorageType m_storage_type;
|
||||
public:
|
||||
IntegrityVerificationStorage() : verification_block_size(0), verification_block_order(0), upper_layer_verification_block_size(0), upper_layer_verification_block_order(0), buffer_manager(nullptr) { /* ... */ }
|
||||
IntegrityVerificationStorage() : m_verification_block_size(0), m_verification_block_order(0), m_upper_layer_verification_block_size(0), m_upper_layer_verification_block_order(0), m_buffer_manager(nullptr) { /* ... */ }
|
||||
virtual ~IntegrityVerificationStorage() override { this->Finalize(); }
|
||||
|
||||
Result Initialize(fs::SubStorage hs, fs::SubStorage ds, s64 verif_block_size, s64 upper_layer_verif_block_size, IBufferManager *bm, const fs::HashSalt &salt, bool is_real_data, fs::StorageType storage_type);
|
||||
@@ -68,7 +68,7 @@ namespace ams::fssystem::save {
|
||||
void CalcBlockHash(BlockHash *out, const void *buffer, size_t block_size) const;
|
||||
|
||||
s64 GetBlockSize() const {
|
||||
return this->verification_block_size;
|
||||
return m_verification_block_size;
|
||||
}
|
||||
private:
|
||||
Result ReadBlockSignature(void *dst, size_t dst_size, s64 offset, size_t size);
|
||||
@@ -76,7 +76,7 @@ namespace ams::fssystem::save {
|
||||
Result VerifyHash(const void *buf, BlockHash *hash);
|
||||
|
||||
void CalcBlockHash(BlockHash *out, const void *buffer) const {
|
||||
return this->CalcBlockHash(out, buffer, static_cast<size_t>(this->verification_block_size));
|
||||
return this->CalcBlockHash(out, buffer, static_cast<size_t>(m_verification_block_size));
|
||||
}
|
||||
|
||||
Result IsCleared(bool *is_cleared, const BlockHash &hash);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user