Compare commits

...

38 Commits

Author SHA1 Message Date
Michael Scire
f7f83b4742 git subrepo push libraries
subrepo:
  subdir:   "libraries"
  merged:   "cf765c094"
upstream:
  origin:   "https://github.com/Atmosphere-NX/Atmosphere-libs"
  branch:   "master"
  commit:   "cf765c094"
git-subrepo:
  version:  "0.4.1"
  origin:   "???"
  commit:   "???"
2021-10-15 23:55:53 -07:00
Michael Scire
8634ea0f7c docs: add changelog for 1.2.0 2021-10-15 23:54:25 -07:00
Michael Scire
2541f6dd71 tipc: implement special-case templating used by 13.0.0 pgl 2021-10-15 21:23:55 -07:00
Michael Scire
ff5f376c33 tipc: enable named-thread dispatch 2021-10-15 19:59:29 -07:00
Michael Scire
d1bc1a5c57 boot: update for 13.0.0/aula parameter changes (closes #1477) 2021-10-15 19:03:11 -07:00
Michael Scire
990daec3a2 powctl: integrate 13.0.0 changes (aula params not done yet) 2021-10-15 16:30:27 -07:00
Michael Scire
c04a262d49 boot: update display logic for 13.0.0 changes 2021-10-14 19:48:13 -07:00
Michael Scire
7e536f74ae strat: fix some mitm server management logic 2021-10-14 00:40:43 -07:00
Michael Scire
891fa32bf1 tipc/sm: update more fully for 13.0.0 changes 2021-10-13 23:50:57 -07:00
Michael Scire
ca25a884b5 tipc: add additional logic from 13.0.0 2021-10-12 00:57:54 -07:00
Michael Scire
0189c5f1e6 sm/tipc: minor cleanup 2021-10-12 00:20:21 -07:00
Michael Scire
124a1a1ea0 sm: update for 13.0.0, optimize layout to reduce storage size. 2021-10-11 22:16:37 -07:00
Michael Scire
82d07e04aa strat: don't force fs globals to link into every process 2021-10-11 22:16:12 -07:00
Michael Scire
bd1bcdf52b sf: prevent emitting mitm/defer code unless server in process supports it 2021-10-11 19:01:27 -07:00
Michael Scire
d27fe8a229 util: fix consteval CountTrailingZeroes impl 2021-10-11 13:15:11 -07:00
Michael Scire
1c5edaf4fb fatal: use align up for width calc 2021-10-11 12:41:43 -07:00
Michael Scire
3cd8ec509c boot: probably should have done this a few months ago huh 2021-10-11 01:01:31 -07:00
Michael Scire
3bee3e77ca ams: bump api verrsion pre-emptively to 1.2.0 2021-10-11 01:00:07 -07:00
Michael Scire
5708bb1557 ams: allow bootloader to merely approximate correct target firmware 2021-10-11 00:54:17 -07:00
Michael Scire
d41de21753 fusee: fix loader stub 2021-10-11 00:19:47 -07:00
Michael Scire
06f68a8159 loader: refactor to remove fake namespaces 2021-10-10 21:37:29 -07:00
Michael Scire
d9dc04318d loader: refactor ro manager/improve accuracy 2021-10-10 18:22:32 -07:00
Michael Scire
d8a36e39f2 spl: refactor for accuracy/move into libstrat 2021-10-10 12:57:36 -07:00
ndeadly
4758dfa933 docs: add hactool to list of build dependencies (#1662)
Co-authored-by: ndeadly <24677491+ndeadly@users.noreply.github.com>
2021-10-10 04:50:57 -07:00
Michael Scire
bc96ebb74c os: add FlushDataCache 2021-10-10 00:33:52 -07:00
Michael Scire
a595c232b9 strat: use m_ for member variables 2021-10-10 00:14:06 -07:00
Michael Scire
ce28591ab2 svc: use m_ for member variables 2021-10-09 16:14:00 -07:00
Michael Scire
00116450c3 sdmmc: use m_ for member variables 2021-10-09 15:59:59 -07:00
Michael Scire
179d91a563 kern: fix some lingering non-m_ member variables 2021-10-09 15:46:04 -07:00
Michael Scire
67a45c97ef exo/vapours: refactor member variables to m_ over this-> 2021-10-09 15:40:06 -07:00
Michael Scire
5a38311ebf libstrat: remove lingering debugging edits 2021-10-09 14:51:44 -07:00
Michael Scire
1ab0bd1765 ams: replace most remaining operator & with std::addressof 2021-10-09 14:49:53 -07:00
Michael Scire
ce8aacef21 settings: fix correctness issue in LazyFileAccessor 2021-10-09 14:20:37 -07:00
Michael Scire
ec65c39d17 strat: refactor address taking of form &var[...] 2021-10-09 12:45:31 -07:00
Michael Scire
b0e520112b strat: always use explicit result namespacing 2021-10-09 10:36:21 -07:00
Adubbz
303c6eb5f9 settings: implement KeyValueStore (#1659)
* settings: implement KeyValueStore and dependencies

* settings: update KeyValueStore for recent refactoring

* settings: address feedback
2021-10-09 09:16:40 -07:00
Michael Scire
14c8801259 sm: remove apm:p compatibility hack
Homebrew which would hang when doing this were compiled with libnx < 3.0.0.

Homebrew which is compiled with < 3.0.0 cannot send messages to sm, because
of the incorrect serialization problem (which required homebrew recompile when
12.0.0 released).

Thus, there is no case where this makes a difference.
2021-10-08 15:25:52 -07:00
Michael Scire
960ba52a43 kern: put rela in bss
NOTE: This saves ~0x4000 of space at the cost of crimes against the linker script.
2021-10-08 12:48:53 -07:00
701 changed files with 18996 additions and 15434 deletions

View File

@@ -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) + [Python 2](https://www.python.org) (Python 3 may work as well, but this is not guaranteed)
+ [LZ4](https://pypi.org/project/lz4) + [LZ4](https://pypi.org/project/lz4)
+ [PyCryptodome](https://pypi.org/project/pycryptodome) (optional) + [PyCryptodome](https://pypi.org/project/pycryptodome) (optional)
+ [hactool](https://github.com/SciresM/hactool)
## Instructions ## 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. 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` + `switch-libjpeg-turbo`
+ `devkitARM` + `devkitARM`
+ `devkitarm-rules` + `devkitarm-rules`
+ `hactool`
3. Install the following library via python's package manager `pip`, required by [exosphere](components/exosphere.md): 3. Install the following library via python's package manager `pip`, required by [exosphere](components/exosphere.md):
+ `lz4` + `lz4`

View File

@@ -1,4 +1,38 @@
# Changelog # 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 ## 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. + 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. + General system stability improvements to enhance the user's experience.

View File

@@ -22,14 +22,14 @@ namespace ams::secmon::loader {
class Lz4Uncompressor { class Lz4Uncompressor {
private: private:
const u8 *src; const u8 *m_src;
size_t src_size; size_t m_src_size;
size_t src_offset; size_t m_src_offset;
u8 *dst; u8 *m_dst;
size_t dst_size; size_t m_dst_size;
size_t dst_offset; size_t m_dst_offset;
public: 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)); this->Copy(this->GetCopySize(control >> 4));
/* If we've exceeded size, we're done. */ /* If we've exceeded size, we're done. */
if (this->src_offset >= this->src_size) { if (m_src_offset >= m_src_size) {
break; break;
} }
@@ -55,21 +55,21 @@ namespace ams::secmon::loader {
const size_t wide_copy_size = this->GetCopySize(control & 0xF); const size_t wide_copy_size = this->GetCopySize(control & 0xF);
/* Copy bytes. */ /* Copy bytes. */
const size_t end_offset = this->dst_offset + wide_copy_size + 4; const size_t end_offset = m_dst_offset + wide_copy_size + 4;
for (size_t cur_offset = this->dst_offset; cur_offset < end_offset; this->dst_offset = (++cur_offset)) { for (size_t cur_offset = m_dst_offset; cur_offset < end_offset; m_dst_offset = (++cur_offset)) {
AMS_ABORT_UNLESS(wide_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: private:
u8 ReadByte() { u8 ReadByte() {
return this->src[this->src_offset++]; return m_src[m_src_offset++];
} }
bool CanRead() const { bool CanRead() const {
return this->src_offset < this->src_size; return m_src_offset < m_src_size;
} }
size_t GetCopySize(u8 control) { size_t GetCopySize(u8 control) {
@@ -87,9 +87,9 @@ namespace ams::secmon::loader {
} }
void Copy(size_t size) { void Copy(size_t size) {
__builtin_memcpy(this->dst + this->dst_offset, this->src + this->src_offset, size); __builtin_memcpy(m_dst + m_dst_offset, m_src + m_src_offset, size);
this->dst_offset += size; m_dst_offset += size;
this->src_offset += size; m_src_offset += size;
} }
}; };

View File

@@ -76,10 +76,10 @@ namespace ams::secmon::fatal {
Bit_Readable = 31, Bit_Readable = 31,
}; };
private: private:
u32 value; u32 m_value;
protected: protected:
constexpr ALWAYS_INLINE u32 SelectBit(Bit n) const { 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 { constexpr ALWAYS_INLINE bool GetBit(Bit n) const {
@@ -97,7 +97,7 @@ namespace ams::secmon::fatal {
ALWAYS_INLINE void SetValue(u32 v) { ALWAYS_INLINE void SetValue(u32 v) {
/* Prevent re-ordering around entry modifications. */ /* Prevent re-ordering around entry modifications. */
__asm__ __volatile__("" ::: "memory"); __asm__ __volatile__("" ::: "memory");
this->value = v; m_value = v;
__asm__ __volatile__("" ::: "memory"); __asm__ __volatile__("" ::: "memory");
} }
public: 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 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); } ALWAYS_INLINE void Invalidate() { this->SetValue(0); }
}; };

View File

@@ -221,7 +221,7 @@ namespace ams::secmon::fatal {
const int prefix_len = std::strlen(automatic_backups_prefix); const int prefix_len = std::strlen(automatic_backups_prefix);
for (size_t i = 0; i + prefix_len < f_ctx->stack_dump_size; ++i) { 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" 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"; "Please try running an archive bit fixer tool (for example, the one in Hekate).\n";
break; break;

View File

@@ -28,7 +28,7 @@ namespace ams::fs {
}; };
struct ReadOption { struct ReadOption {
u32 value; u32 _value;
static const ReadOption None; static const ReadOption None;
}; };
@@ -36,7 +36,7 @@ namespace ams::fs {
inline constexpr const ReadOption ReadOption::None = {0}; inline constexpr const ReadOption ReadOption::None = {0};
inline constexpr bool operator==(const ReadOption &lhs, const ReadOption &rhs) { 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) { 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)); static_assert(util::is_pod<ReadOption>::value && sizeof(ReadOption) == sizeof(u32));
struct WriteOption { struct WriteOption {
u32 value; u32 _value;
constexpr inline bool HasFlushFlag() const { constexpr inline bool HasFlushFlag() const {
return this->value & 1; return _value & 1;
} }
static const WriteOption None; static const WriteOption None;
@@ -60,7 +60,7 @@ namespace ams::fs {
inline constexpr const WriteOption WriteOption::Flush = {1}; inline constexpr const WriteOption WriteOption::Flush = {1};
inline constexpr bool operator==(const WriteOption &lhs, const WriteOption &rhs) { 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) { inline constexpr bool operator!=(const WriteOption &lhs, const WriteOption &rhs) {

View File

@@ -23,16 +23,16 @@ namespace ams::secmon {
void *PageMapperImpl::GetPointerTo(uintptr_t phys, size_t size) const { void *PageMapperImpl::GetPointerTo(uintptr_t phys, size_t size) const {
/* Ensure we stay within the page. */ /* 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; return nullptr;
} }
if (size != 0) { 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 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 { bool PageMapperImpl::CopyToMapping(uintptr_t dst_phys, const void *src, size_t size) const {

View File

@@ -22,10 +22,10 @@ namespace ams::secmon {
class PageMapperImpl { class PageMapperImpl {
private: private:
uintptr_t physical_address; uintptr_t m_physical_address;
uintptr_t virtual_address; uintptr_t m_virtual_address;
public: 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; void *GetPointerTo(uintptr_t phys, size_t size) const;
@@ -37,14 +37,14 @@ namespace ams::secmon {
template<auto F> template<auto F>
bool MapImpl() { bool MapImpl() {
this->virtual_address = F(this->physical_address); m_virtual_address = F(m_physical_address);
return this->virtual_address != 0; return m_virtual_address != 0;
} }
template<auto F> template<auto F>
void UnmapImpl() { void UnmapImpl() {
F(); F();
this->virtual_address = 0; m_virtual_address = 0;
} }
}; };

View File

@@ -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_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_Ctr: se::ComputeAes128CtrAsync(output_address, slot, input_address, size, iv, sizeof(iv), SecurityEngineDoneHandler); break;
case CipherMode_Cmac: case CipherMode_Cmac:
return SmcResult::NotImplemented; return SmcResult::NotSupported;
default: default:
return SmcResult::InvalidArgument; return SmcResult::InvalidArgument;
} }
@@ -765,8 +765,8 @@ namespace ams::secmon::smc {
const auto which = static_cast<SecureData>(args.r[1]); const auto which = static_cast<SecureData>(args.r[1]);
/* Validate arguments/conditions. */ /* Validate arguments/conditions. */
SMC_R_UNLESS(fuse::GetPatchVersion() < fuse::PatchVersion_Odnx02A2, NotImplemented); SMC_R_UNLESS(fuse::GetPatchVersion() < fuse::PatchVersion_Odnx02A2, NotSupported);
SMC_R_UNLESS(which < SecureData_Count, NotImplemented); SMC_R_UNLESS(which < SecureData_Count, NotSupported);
/* Use a temporary buffer. */ /* Use a temporary buffer. */
u8 secure_data[AesKeySize]; u8 secure_data[AesKeySize];

View File

@@ -20,7 +20,7 @@ namespace ams::secmon::smc {
enum class SmcResult : u32 { enum class SmcResult : u32 {
Success = 0, Success = 0,
NotImplemented = 1, NotSupported = 1,
InvalidArgument = 2, InvalidArgument = 2,
Busy = 3, Busy = 3,
NoAsyncOperation = 4, NoAsyncOperation = 4,

View File

@@ -164,6 +164,7 @@ namespace ams::secmon::smc {
} }
constinit u64 g_payload_address = 0; constinit u64 g_payload_address = 0;
constinit bool g_set_true_target_firmware = false;
SmcResult GetConfig(SmcArguments &args, bool kern) { SmcResult GetConfig(SmcArguments &args, bool kern) {
switch (static_cast<ConfigItem>(args.r[1])) { switch (static_cast<ConfigItem>(args.r[1])) {
@@ -213,8 +214,8 @@ namespace ams::secmon::smc {
case ConfigItem::IsChargerHiZModeEnabled: case ConfigItem::IsChargerHiZModeEnabled:
args.r[1] = IsChargerHiZModeEnabled(); args.r[1] = IsChargerHiZModeEnabled();
break; break;
case ConfigItem::QuestState: case ConfigItem::RetailInteractiveDisplayState:
args.r[1] = fuse::GetQuestState(); args.r[1] = fuse::GetRetailInteractiveDisplayState();
break; break;
case ConfigItem::RegulatorType: case ConfigItem::RegulatorType:
args.r[1] = fuse::GetRegulator(); args.r[1] = fuse::GetRegulator();
@@ -240,11 +241,15 @@ namespace ams::secmon::smc {
break; break;
case ConfigItem::ExosphereApiVersion: case ConfigItem::ExosphereApiVersion:
/* Get information about the current exosphere version. */ /* Get information about the current exosphere version. */
args.r[1] = (static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MAJOR & 0xFF) << 56) | if (kern || g_set_true_target_firmware) {
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MINOR & 0xFF) << 48) | args.r[1] = (static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MAJOR & 0xFF) << 56) |
(static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MICRO & 0xFF) << 40) | (static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MINOR & 0xFF) << 48) |
(static_cast<u64>(GetKeyGeneration()) << 32) | (static_cast<u64>(ATMOSPHERE_RELEASE_VERSION_MICRO & 0xFF) << 40) |
(static_cast<u64>(GetTargetFirmware()) << 0); (static_cast<u64>(GetKeyGeneration()) << 32) |
(static_cast<u64>(GetTargetFirmware()) << 0);
} else {
return SmcResult::NotInitialized;
}
break; break;
case ConfigItem::ExosphereNeedsReboot: case ConfigItem::ExosphereNeedsReboot:
/* We are executing, so we aren't in the process of rebooting. */ /* 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_MINOR & 0xFF) << 16) |
(static_cast<u64>(ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO & 0xFF) << 8); (static_cast<u64>(ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO & 0xFF) << 8);
break; 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: default:
return SmcResult::InvalidArgument; return SmcResult::InvalidArgument;
} }
@@ -312,6 +329,14 @@ namespace ams::secmon::smc {
/* Configure the HiZ mode. */ /* Configure the HiZ mode. */
SetChargerHiZModeEnabled(static_cast<bool>(args.r[3])); SetChargerHiZModeEnabled(static_cast<bool>(args.r[3]));
break; 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: case ConfigItem::ExosphereNeedsReboot:
if (soc_type == fuse::SocType_Erista) { if (soc_type == fuse::SocType_Erista) {
switch (static_cast<UserRebootType>(args.r[3])) { switch (static_cast<UserRebootType>(args.r[3])) {
@@ -345,7 +370,7 @@ namespace ams::secmon::smc {
PerformUserShutDown(); PerformUserShutDown();
} }
} else /* if (soc_type == fuse::SocType_Mariko) */ { } else /* if (soc_type == fuse::SocType_Mariko) */ {
return SmcResult::NotImplemented; return SmcResult::NotSupported;
} }
break; break;
case ConfigItem::ExospherePayloadAddress: case ConfigItem::ExospherePayloadAddress:
@@ -389,7 +414,7 @@ namespace ams::secmon::smc {
/* Validate arguments. */ /* Validate arguments. */
/* NOTE: In the future, configuration for non-NAND storage may be implemented. */ /* 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); SMC_R_UNLESS(user_offset + 2 * sizeof(EmummcFilePath) <= 4_KB, InvalidArgument);
/* Get the emummc config. */ /* Get the emummc config. */

View File

@@ -34,24 +34,25 @@ namespace ams::secmon::smc {
IsDevelopmentFunctionEnabled = 11, IsDevelopmentFunctionEnabled = 11,
KernelConfiguration = 12, KernelConfiguration = 12,
IsChargerHiZModeEnabled = 13, IsChargerHiZModeEnabled = 13,
QuestState = 14, RetailInteractiveDisplayState = 14,
RegulatorType = 15, RegulatorType = 15,
DeviceUniqueKeyGeneration = 16, DeviceUniqueKeyGeneration = 16,
Package2Hash = 17, Package2Hash = 17,
/* Extension config items for exosphere. */ /* Extension config items for exosphere. */
ExosphereApiVersion = 65000, ExosphereApiVersion = 65000,
ExosphereNeedsReboot = 65001, ExosphereNeedsReboot = 65001,
ExosphereNeedsShutdown = 65002, ExosphereNeedsShutdown = 65002,
ExosphereGitCommitHash = 65003, ExosphereGitCommitHash = 65003,
ExosphereHasRcmBugPatch = 65004, ExosphereHasRcmBugPatch = 65004,
ExosphereBlankProdInfo = 65005, ExosphereBlankProdInfo = 65005,
ExosphereAllowCalWrites = 65006, ExosphereAllowCalWrites = 65006,
ExosphereEmummcType = 65007, ExosphereEmummcType = 65007,
ExospherePayloadAddress = 65008, ExospherePayloadAddress = 65008,
ExosphereLogConfiguration = 65009, ExosphereLogConfiguration = 65009,
ExosphereForceEnableUsb30 = 65010, ExosphereForceEnableUsb30 = 65010,
ExosphereSupportedHosVersion = 65011, ExosphereSupportedHosVersion = 65011,
ExosphereApproximateApiVersion = 65012,
}; };
SmcResult SmcGetConfigUser(SmcArguments &args); SmcResult SmcGetConfigUser(SmcArguments &args);

View File

@@ -70,7 +70,7 @@ namespace ams::secmon::smc {
SmcResult SmcWriteAddress(SmcArguments &args) { SmcResult SmcWriteAddress(SmcArguments &args) {
/* NOTE: This smc was deprecated in Atmosphère 0.13.0. */ /* NOTE: This smc was deprecated in Atmosphère 0.13.0. */
AMS_UNUSED(args); AMS_UNUSED(args);
return SmcResult::NotImplemented; return SmcResult::NotSupported;
} }
} }

View File

@@ -55,31 +55,31 @@ namespace ams::secmon::smc {
class PrepareEsDeviceUniqueKeyAsyncArguments { class PrepareEsDeviceUniqueKeyAsyncArguments {
private: private:
int generation; int m_generation;
EsCommonKeyType type; EsCommonKeyType m_type;
u8 label_digest[crypto::Sha256Generator::HashSize]; u8 m_label_digest[crypto::Sha256Generator::HashSize];
public: public:
void Set(int gen, EsCommonKeyType t, const u8 ld[crypto::Sha256Generator::HashSize]) { void Set(int gen, EsCommonKeyType t, const u8 ld[crypto::Sha256Generator::HashSize]) {
this->generation = gen; m_generation = gen;
this->type = t; m_type = t;
std::memcpy(this->label_digest, ld, sizeof(this->label_digest)); std::memcpy(m_label_digest, ld, sizeof(m_label_digest));
} }
int GetKeyGeneration() const { return this->generation; } int GetKeyGeneration() const { return m_generation; }
EsCommonKeyType GetCommonKeyType() const { return this->type; } EsCommonKeyType GetCommonKeyType() const { return m_type; }
void GetLabelDigest(u8 dst[crypto::Sha256Generator::HashSize]) const { std::memcpy(dst, this->label_digest, sizeof(this->label_digest)); } void GetLabelDigest(u8 dst[crypto::Sha256Generator::HashSize]) const { std::memcpy(dst, m_label_digest, sizeof(m_label_digest)); }
}; };
class ModularExponentiateByStorageKeyAsyncArguments { class ModularExponentiateByStorageKeyAsyncArguments {
private: private:
u8 msg[se::RsaSize]; u8 m_msg[se::RsaSize];
public: public:
void Set(const void *m, size_t m_size) { void Set(const void *m, size_t m_size) {
AMS_UNUSED(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; constinit SmcResult g_exp_mod_result = SmcResult::Success;

View File

@@ -73,6 +73,7 @@ SECTIONS
fusee_loader_main.o(.text*) fusee_loader_main.o(.text*)
fusee_loader_uncompress.o(.text*) fusee_loader_uncompress.o(.text*)
fusee_loader_error.o(.text*) fusee_loader_error.o(.text*)
*(.text.memcpy)
fusee_loader_main.o(.rodata*) fusee_loader_main.o(.rodata*)
fusee_loader_uncompress.o(.rodata*) fusee_loader_uncompress.o(.rodata*)
fusee_loader_error.o(.rodata*) fusee_loader_error.o(.rodata*)

View File

@@ -22,14 +22,14 @@ namespace ams::nxboot::loader {
class Lz4Uncompressor { class Lz4Uncompressor {
private: private:
const u8 *src; const u8 *m_src;
size_t src_size; size_t m_src_size;
size_t src_offset; size_t m_src_offset;
u8 *dst; u8 *m_dst;
size_t dst_size; size_t m_dst_size;
size_t dst_offset; size_t m_dst_offset;
public: 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)); this->Copy(this->GetCopySize(control >> 4));
/* If we've exceeded size, we're done. */ /* If we've exceeded size, we're done. */
if (this->src_offset >= this->src_size) { if (m_src_offset >= m_src_size) {
break; break;
} }
@@ -55,21 +55,21 @@ namespace ams::nxboot::loader {
const size_t wide_copy_size = this->GetCopySize(control & 0xF); const size_t wide_copy_size = this->GetCopySize(control & 0xF);
/* Copy bytes. */ /* Copy bytes. */
const size_t end_offset = this->dst_offset + wide_copy_size + 4; const size_t end_offset = m_dst_offset + wide_copy_size + 4;
for (size_t cur_offset = this->dst_offset; cur_offset < end_offset; this->dst_offset = (++cur_offset)) { for (size_t cur_offset = m_dst_offset; cur_offset < end_offset; m_dst_offset = (++cur_offset)) {
AMS_ABORT_UNLESS(wide_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: private:
u8 ReadByte() { u8 ReadByte() {
return this->src[this->src_offset++]; return m_src[m_src_offset++];
} }
bool CanRead() const { bool CanRead() const {
return this->src_offset < this->src_size; return m_src_offset < m_src_size;
} }
size_t GetCopySize(u8 control) { size_t GetCopySize(u8 control) {
@@ -87,11 +87,9 @@ namespace ams::nxboot::loader {
} }
void Copy(size_t size) { void Copy(size_t size) {
for (size_t i = 0; i < size; ++i) { __builtin_memcpy(m_dst + m_dst_offset, m_src + m_src_offset, size);
this->dst[this->dst_offset + i] = this->src[this->src_offset + i]; m_dst_offset += size;
} m_src_offset += size;
this->dst_offset += size;
this->src_offset += size;
} }
}; };

View File

@@ -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) { 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) { bool diskio_write_system(size_t sector_index, size_t sector_count, const void *src, size_t size) {

View File

@@ -27,10 +27,8 @@ namespace ams::fs {
constexpr size_t MaxDirectories = 2; constexpr size_t MaxDirectories = 2;
constinit bool g_is_sd_mounted = false; 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_sd_fs = {};
alignas(0x10) constinit FATFS g_sys_fs = {};
alignas(0x10) constinit FIL g_files[MaxFiles] = {}; alignas(0x10) constinit FIL g_files[MaxFiles] = {};
alignas(0x10) constinit DIR g_dirs[MaxDirectories] = {}; alignas(0x10) constinit DIR g_dirs[MaxDirectories] = {};
@@ -131,18 +129,6 @@ namespace ams::fs {
g_is_sd_mounted = false; 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) { Result GetEntryType(DirectoryEntryType *out_entry_type, bool *out_archive, const char *path) {
/* Get the file info. */ /* Get the file info. */
FILINFO info; FILINFO info;

View File

@@ -28,7 +28,7 @@ namespace ams::fs {
}; };
struct ReadOption { struct ReadOption {
u32 value; u32 _value;
static const ReadOption None; static const ReadOption None;
}; };
@@ -36,7 +36,7 @@ namespace ams::fs {
inline constexpr const ReadOption ReadOption::None = {0}; inline constexpr const ReadOption ReadOption::None = {0};
inline constexpr bool operator==(const ReadOption &lhs, const ReadOption &rhs) { 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) { 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)); static_assert(util::is_pod<ReadOption>::value && sizeof(ReadOption) == sizeof(u32));
struct WriteOption { struct WriteOption {
u32 value; u32 _value;
constexpr inline bool HasFlushFlag() const { constexpr inline bool HasFlushFlag() const {
return this->value & 1; return _value & 1;
} }
static const WriteOption None; static const WriteOption None;
@@ -60,7 +60,7 @@ namespace ams::fs {
inline constexpr const WriteOption WriteOption::Flush = {1}; inline constexpr const WriteOption WriteOption::Flush = {1};
inline constexpr bool operator==(const WriteOption &lhs, const WriteOption &rhs) { 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) { inline constexpr bool operator!=(const WriteOption &lhs, const WriteOption &rhs) {
@@ -98,9 +98,6 @@ namespace ams::fs {
bool MountSdCard(); bool MountSdCard();
void UnmountSdCard(); void UnmountSdCard();
bool MountSystem();
void UnmountSystem();
Result GetEntryType(DirectoryEntryType *out_entry_type, bool *out_archive, const char *path); Result GetEntryType(DirectoryEntryType *out_entry_type, bool *out_archive, const char *path);
Result CreateFile(const char *path, s64 size); Result CreateFile(const char *path, s64 size);

View File

@@ -181,112 +181,6 @@ namespace ams::nxboot {
constinit fs::IStorage *g_boot0_storage = nullptr; constinit fs::IStorage *g_boot0_storage = nullptr;
constinit fs::IStorage *g_user_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; constinit fs::SubStorage *g_package2_storage = nullptr;
struct Guid { struct Guid {
@@ -333,10 +227,6 @@ namespace ams::nxboot {
}; };
static_assert(sizeof(Gpt) == 16_KB + 0x200); static_assert(sizeof(Gpt) == 16_KB + 0x200);
constexpr const u16 SystemPartitionName[] = {
'S', 'Y', 'S', 'T', 'E', 'M', 0
};
constexpr const u16 Package2PartitionName[] = { constexpr const u16 Package2PartitionName[] = {
'B', 'C', 'P', 'K', 'G', '2', '-', '1', '-', 'N', 'o', 'r', 'm', 'a', 'l', '-', 'M', 'a', 'i', 'n', 0 '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 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); 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) { if (std::memcmp(gpt->entries[i].partition_name, Package2PartitionName, sizeof(Package2PartitionName)) == 0) {
g_system_storage = AllocateObject<SystemPartitionStorage>(offset, size);
} else if (std::memcmp(gpt->entries[i].partition_name, Package2PartitionName, sizeof(Package2PartitionName)) == 0) {
g_package2_storage = AllocateObject<fs::SubStorage>(*g_user_storage, offset, size); 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. */ /* Check that we created package2 storage. */
if (g_package2_storage == nullptr) { if (g_package2_storage == nullptr) {
ShowFatalError("Failed to initialize Package2\n"); 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) { Result ReadBoot0(s64 offset, void *dst, size_t size) {
@@ -478,8 +356,4 @@ namespace ams::nxboot {
return g_package2_storage->Read(offset, dst, size); 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);
}
} }

View File

@@ -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; 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; fs::DirectoryEntryType entry_type;
bool archive; bool archive;
return R_SUCCEEDED(fs::GetEntryType(std::addressof(entry_type), std::addressof(archive), path)) && entry_type == fs::DirectoryEntryType_File; 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() { bool ConfigureEmummc() {
/* Set magic. */ /* Set magic. */
g_emummc_cfg.base_cfg.magic = secmon::EmummcBaseConfiguration::Magic; g_emummc_cfg.base_cfg.magic = secmon::EmummcBaseConfiguration::Magic;
@@ -220,143 +206,56 @@ namespace ams::nxboot {
return package1; return package1;
} }
ams::TargetFirmware GetTargetFirmware(const u8 *package1) { ams::TargetFirmware GetApproximateTargetFirmware(const u8 *package1) {
/* Get first an approximation of the target firmware. */ /* Get an approximation of the target firmware. */
ams::TargetFirmware target_firmware = ams::TargetFirmware_Current;
switch (package1[0x1F]) { switch (package1[0x1F]) {
case 0x01: case 0x01:
target_firmware = ams::TargetFirmware_1_0_0; return ams::TargetFirmware_1_0_0;
break;
case 0x02: case 0x02:
target_firmware = ams::TargetFirmware_2_0_0; return ams::TargetFirmware_2_0_0;
break;
case 0x04: case 0x04:
target_firmware = ams::TargetFirmware_3_0_0; return ams::TargetFirmware_3_0_0;
break;
case 0x07: case 0x07:
target_firmware = ams::TargetFirmware_4_0_0; return ams::TargetFirmware_4_0_0;
break;
case 0x0B: case 0x0B:
target_firmware = ams::TargetFirmware_5_0_0; return ams::TargetFirmware_5_0_0;
break;
case 0x0E: case 0x0E:
if (std::memcmp(package1 + 0x10, "20180802", 8) == 0) { 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) { } else if (std::memcmp(package1 + 0x10, "20181107", 8) == 0) {
target_firmware = ams::TargetFirmware_6_2_0; return ams::TargetFirmware_6_2_0;
} else {
ShowFatalError("Unable to identify package1!\n");
} }
break; break;
case 0x0F: case 0x0F:
target_firmware = ams::TargetFirmware_7_0_0; return ams::TargetFirmware_7_0_0;
break;
case 0x10: case 0x10:
if (std::memcmp(package1 + 0x10, "20190314", 8) == 0) { 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) { } 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) { } 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) { } 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) { } 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) { } 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) { } 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) { } 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) { } 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) { } else if (std::memcmp(package1 + 0x10, "20210805", 8) == 0) {
target_firmware = ams::TargetFirmware_13_0_0; return ams::TargetFirmware_13_0_0;
} else {
ShowFatalError("Unable to identify package1!\n");
} }
break; break;
default: default:
ShowFatalError("Unable to identify package1!\n");
break; break;
} }
#define CHECK_NCA(NCA_ID, VERSION) do { if (IsNcaExist(NCA_ID)) { return ams::TargetFirmware_##VERSION; } } while(0) ShowFatalError("Unable to identify package1!\n");
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;
} }
u8 *LoadBootConfigAndPackage2() { u8 *LoadBootConfigAndPackage2() {
@@ -825,7 +724,7 @@ namespace ams::nxboot {
const u8 * const package1 = LoadPackage1(soc_type); const u8 * const package1 = LoadPackage1(soc_type);
/* Get target firmware. */ /* Get target firmware. */
const auto target_firmware = GetTargetFirmware(package1); const auto target_firmware = GetApproximateTargetFirmware(package1);
/* Read/decrypt package2. */ /* Read/decrypt package2. */
u8 * const package2 = LoadBootConfigAndPackage2(); u8 * const package2 = LoadBootConfigAndPackage2();

View File

@@ -22,14 +22,14 @@ namespace ams::nxboot {
class Lz4Uncompressor { class Lz4Uncompressor {
private: private:
const u8 *src; const u8 *m_src;
size_t src_size; size_t m_src_size;
size_t src_offset; size_t m_src_offset;
u8 *dst; u8 *m_dst;
size_t dst_size; size_t m_dst_size;
size_t dst_offset; size_t m_dst_offset;
public: 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)); this->Copy(this->GetCopySize(control >> 4));
/* If we've exceeded size, we're done. */ /* If we've exceeded size, we're done. */
if (this->src_offset >= this->src_size) { if (m_src_offset >= m_src_size) {
break; break;
} }
@@ -55,21 +55,21 @@ namespace ams::nxboot {
const size_t wide_copy_size = this->GetCopySize(control & 0xF); const size_t wide_copy_size = this->GetCopySize(control & 0xF);
/* Copy bytes. */ /* Copy bytes. */
const size_t end_offset = this->dst_offset + wide_copy_size + 4; const size_t end_offset = m_dst_offset + wide_copy_size + 4;
for (size_t cur_offset = this->dst_offset; cur_offset < end_offset; this->dst_offset = (++cur_offset)) { for (size_t cur_offset = m_dst_offset; cur_offset < end_offset; m_dst_offset = (++cur_offset)) {
AMS_ABORT_UNLESS(wide_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: private:
u8 ReadByte() { u8 ReadByte() {
return this->src[this->src_offset++]; return m_src[m_src_offset++];
} }
bool CanRead() const { bool CanRead() const {
return this->src_offset < this->src_size; return m_src_offset < m_src_size;
} }
size_t GetCopySize(u8 control) { size_t GetCopySize(u8 control) {
@@ -87,9 +87,9 @@ namespace ams::nxboot {
} }
void Copy(size_t size) { void Copy(size_t size) {
__builtin_memcpy(this->dst + this->dst_offset, this->src + this->src_offset, size); __builtin_memcpy(m_dst + m_dst_offset, m_src + m_src_offset, size);
this->dst_offset += size; m_dst_offset += size;
this->src_offset += size; m_src_offset += size;
} }
}; };

View File

@@ -6,7 +6,7 @@
[subrepo] [subrepo]
remote = https://github.com/Atmosphere-NX/Atmosphere-libs remote = https://github.com/Atmosphere-NX/Atmosphere-libs
branch = master branch = master
commit = 0a4c2759a1f73cb5581ed2e87c20e05440a2c037 commit = cf765c0946cc5c828364ae6bfccddc4041304f28
parent = d14290e3572c52f4dd9ed2a16f698ba12e9eea67 parent = 8634ea0f7c4f0e68adf2dfaaddc6ae1e225c4fc2
method = merge method = merge
cmdver = 0.4.1 cmdver = 0.4.1

View File

@@ -81,9 +81,9 @@ namespace ams::fuse {
DramId_Count, DramId_Count,
}; };
enum QuestState { enum RetailInteractiveDisplayState {
QuestState_Disabled = 0, RetailInteractiveDisplayState_Disabled = 0,
QuestState_Enabled = 1, RetailInteractiveDisplayState_Enabled = 1,
}; };
void SetRegisterAddress(uintptr_t address); void SetRegisterAddress(uintptr_t address);
@@ -102,19 +102,19 @@ namespace ams::fuse {
bool GetSecureBootKey(void *dst); bool GetSecureBootKey(void *dst);
void GetEcid(br::BootEcid *out); void GetEcid(br::BootEcid *out);
HardwareType GetHardwareType(); HardwareType GetHardwareType();
HardwareState GetHardwareState(); HardwareState GetHardwareState();
u64 GetDeviceId(); u64 GetDeviceId();
PatchVersion GetPatchVersion(); PatchVersion GetPatchVersion();
QuestState GetQuestState(); RetailInteractiveDisplayState GetRetailInteractiveDisplayState();
pmic::Regulator GetRegulator(); pmic::Regulator GetRegulator();
int GetDeviceUniqueKeyGeneration(); int GetDeviceUniqueKeyGeneration();
SocType GetSocType(); SocType GetSocType();
int GetExpectedFuseVersion(TargetFirmware target_fw); int GetExpectedFuseVersion(TargetFirmware target_fw);
int GetFuseVersion(); int GetFuseVersion();
bool HasRcmVulnerabilityPatch(); bool HasRcmVulnerabilityPatch();
bool IsOdmProductionMode(); bool IsOdmProductionMode();
void ConfigureFuseBypass(); void ConfigureFuseBypass();

View File

@@ -70,6 +70,10 @@ namespace ams::secmon {
GetConfigurationContext().secmon_cfg.key_generation = generation; 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() { ALWAYS_INLINE pkg1::BootConfig *GetBootConfigStorage() {
return std::addressof(GetConfigurationContext().boot_config); return std::addressof(GetConfigurationContext().boot_config);
} }

View File

@@ -22,52 +22,53 @@ namespace ams::secmon {
using Address = u64; using Address = u64;
struct MemoryRegion { struct MemoryRegion {
Address start_address; private:
Address end_address; Address m_start_address;
Address m_end_address;
constexpr MemoryRegion(Address address, size_t size) : start_address(address), end_address(address + size) { public:
if (end_address < start_address) { consteval MemoryRegion(Address address, size_t size) : m_start_address(address), m_end_address(address + size) {
__builtin_unreachable(); if (m_end_address < m_start_address) {
__builtin_unreachable();
}
} }
}
constexpr Address GetStartAddress() const { constexpr Address GetStartAddress() const {
return this->start_address; return m_start_address;
} }
constexpr Address GetAddress() const { constexpr Address GetAddress() const {
return this->GetStartAddress(); return this->GetStartAddress();
} }
constexpr Address GetEndAddress() const { constexpr Address GetEndAddress() const {
return this->end_address; return m_end_address;
} }
constexpr Address GetLastAddress() const { constexpr Address GetLastAddress() const {
return this->end_address - 1; return m_end_address - 1;
} }
constexpr size_t GetSize() const { constexpr size_t GetSize() const {
return this->end_address - this->start_address; return m_end_address - m_start_address;
} }
constexpr bool Contains(Address address, size_t size) const { constexpr bool Contains(Address address, size_t size) const {
return this->start_address <= address && (address + size - 1) <= this->GetLastAddress(); return m_start_address <= address && (address + size - 1) <= this->GetLastAddress();
} }
constexpr bool Contains(const MemoryRegion &rhs) const { constexpr bool Contains(const MemoryRegion &rhs) const {
return this->Contains(rhs.GetStartAddress(), rhs.GetSize()); return this->Contains(rhs.GetStartAddress(), rhs.GetSize());
} }
template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value) template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value)
ALWAYS_INLINE T *GetPointer() const { ALWAYS_INLINE T *GetPointer() const {
return reinterpret_cast<T *>(this->GetAddress()); return reinterpret_cast<T *>(this->GetAddress());
} }
template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value) template<typename T = void> requires (std::is_same<T, void>::value || util::is_pod<T>::value)
ALWAYS_INLINE T *GetEndPointer() const { ALWAYS_INLINE T *GetEndPointer() const {
return reinterpret_cast<T *>(this->GetEndAddress()); return reinterpret_cast<T *>(this->GetEndAddress());
} }
}; };
constexpr inline const MemoryRegion MemoryRegionVirtual = MemoryRegion(UINT64_C(0x1F0000000), 2_MB); constexpr inline const MemoryRegion MemoryRegionVirtual = MemoryRegion(UINT64_C(0x1F0000000), 2_MB);

View File

@@ -37,7 +37,7 @@ namespace ams::crypto::impl {
AMS_UNUSED(key_size, is_encrypt); AMS_UNUSED(key_size, is_encrypt);
/* Set the security engine keyslot. */ /* Set the security engine keyslot. */
this->slot = *static_cast<const int *>(key); m_slot = *static_cast<const int *>(key);
} }
template<size_t KeySize> template<size_t KeySize>
@@ -48,14 +48,14 @@ namespace ams::crypto::impl {
if constexpr (KeySize == 16) { if constexpr (KeySize == 16) {
/* Aes 128. */ /* 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) { } else if constexpr (KeySize == 24) {
/* Aes 192. */ /* 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); AMS_UNUSED(dst, dst_size, src, src_size);
} else if constexpr (KeySize == 32) { } else if constexpr (KeySize == 32) {
/* Aes 256. */ /* 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); AMS_UNUSED(dst, dst_size, src, src_size);
} else { } else {
/* Invalid key size. */ /* Invalid key size. */
@@ -71,14 +71,14 @@ namespace ams::crypto::impl {
if constexpr (KeySize == 16) { if constexpr (KeySize == 16) {
/* Aes 128. */ /* 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) { } else if constexpr (KeySize == 24) {
/* Aes 192. */ /* 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); AMS_UNUSED(dst, dst_size, src, src_size);
} else if constexpr (KeySize == 32) { } else if constexpr (KeySize == 32) {
/* Aes 256. */ /* 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); AMS_UNUSED(dst, dst_size, src, src_size);
} else { } else {
/* Invalid key size. */ /* Invalid key size. */

View File

@@ -37,15 +37,15 @@ namespace ams::fuse {
}; };
struct OdmWord4 { struct OdmWord4 {
using HardwareState1 = util::BitPack32::Field<0, 2, int>; using HardwareState1 = util::BitPack32::Field<0, 2, int>;
using HardwareType1 = util::BitPack32::Field<HardwareState1::Next, 1, int>; using HardwareType1 = util::BitPack32::Field<HardwareState1::Next, 1, int>;
using DramId = util::BitPack32::Field<HardwareType1::Next, 5, int>; using DramId = util::BitPack32::Field<HardwareType1::Next, 5, int>;
using HardwareType2 = util::BitPack32::Field<DramId::Next, 1, int>; using HardwareType2 = util::BitPack32::Field<DramId::Next, 1, int>;
using HardwareState2 = util::BitPack32::Field<HardwareType2::Next, 1, int>; using HardwareState2 = util::BitPack32::Field<HardwareType2::Next, 1, int>;
using QuestState = util::BitPack32::Field<HardwareState2::Next, 1, int>; using RetailInteractiveDisplayState = util::BitPack32::Field<HardwareState2::Next, 1, int>;
using FormatVersion = util::BitPack32::Field<QuestState::Next, 1, int>; using FormatVersion = util::BitPack32::Field<RetailInteractiveDisplayState::Next, 1, int>;
using Reserved = util::BitPack32::Field<FormatVersion::Next, 4, int>; using Reserved = util::BitPack32::Field<FormatVersion::Next, 4, int>;
using HardwareType3 = util::BitPack32::Field<Reserved::Next, 4, int>; using HardwareType3 = util::BitPack32::Field<Reserved::Next, 4, int>;
}; };
struct OdmWord28 { struct OdmWord28 {
@@ -343,8 +343,8 @@ namespace ams::fuse {
return static_cast<PatchVersion>(static_cast<int>(GetSocType() << 12) | patch_version); return static_cast<PatchVersion>(static_cast<int>(GetSocType() << 12) | patch_version);
} }
QuestState GetQuestState() { RetailInteractiveDisplayState GetRetailInteractiveDisplayState() {
return static_cast<QuestState>(util::BitPack32{GetCommonOdmWord(4)}.Get<OdmWord4::QuestState>()); return static_cast<RetailInteractiveDisplayState>(util::BitPack32{GetCommonOdmWord(4)}.Get<OdmWord4::RetailInteractiveDisplayState>());
} }
pmic::Regulator GetRegulator() { pmic::Regulator GetRegulator() {

View File

@@ -54,63 +54,63 @@ namespace ams::kern::init::Elf::Elf64 {
class Dyn { class Dyn {
private: private:
SXword tag; SXword m_tag;
union { union {
Xword value; Xword m_value;
Addr ptr; Addr m_ptr;
}; };
public: public:
constexpr ALWAYS_INLINE SXword GetTag() const { constexpr ALWAYS_INLINE SXword GetTag() const {
return this->tag; return m_tag;
} }
constexpr ALWAYS_INLINE Xword GetValue() const { constexpr ALWAYS_INLINE Xword GetValue() const {
return this->value; return m_value;
} }
constexpr ALWAYS_INLINE Addr GetPtr() const { constexpr ALWAYS_INLINE Addr GetPtr() const {
return this->ptr; return m_ptr;
} }
}; };
class Rel { class Rel {
private: private:
Addr offset; Addr m_offset;
Xword info; Xword m_info;
public: public:
constexpr ALWAYS_INLINE Addr GetOffset() const { constexpr ALWAYS_INLINE Addr GetOffset() const {
return this->offset; return m_offset;
} }
constexpr ALWAYS_INLINE Xword GetSym() const { constexpr ALWAYS_INLINE Xword GetSym() const {
return this->info >> 32; return m_info >> 32;
} }
constexpr ALWAYS_INLINE Xword GetType() const { constexpr ALWAYS_INLINE Xword GetType() const {
return this->info & 0xFFFFFFFF; return m_info & 0xFFFFFFFF;
} }
}; };
class Rela { class Rela {
private: private:
Addr offset; Addr m_offset;
Xword info; Xword m_info;
SXword addend; SXword m_addend;
public: public:
constexpr ALWAYS_INLINE Addr GetOffset() const { constexpr ALWAYS_INLINE Addr GetOffset() const {
return this->offset; return m_offset;
} }
constexpr ALWAYS_INLINE Xword GetSym() const { constexpr ALWAYS_INLINE Xword GetSym() const {
return this->info >> 32; return m_info >> 32;
} }
constexpr ALWAYS_INLINE Xword GetType() const { constexpr ALWAYS_INLINE Xword GetType() const {
return this->info & 0xFFFFFFFF; return m_info & 0xFFFFFFFF;
} }
constexpr ALWAYS_INLINE SXword GetAddend() const { constexpr ALWAYS_INLINE SXword GetAddend() const {
return this->addend; return m_addend;
} }
}; };

View File

@@ -140,21 +140,21 @@ namespace ams::kern::svc {
using CT = const char; using CT = const char;
using T = char; using T = char;
private: private:
const char *ptr; const char *m_ptr;
protected: protected:
ALWAYS_INLINE Result CopyStringTo(char *dst, size_t size) const { ALWAYS_INLINE Result CopyStringTo(char *dst, size_t size) const {
static_assert(sizeof(char) == 1); 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(); return ResultSuccess();
} }
ALWAYS_INLINE Result CopyArrayElementTo(char *dst, size_t index) const { 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; }
}; };
} }

View File

@@ -186,7 +186,7 @@ namespace ams::kern::board::nintendo::nx::smc {
MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success)); MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success));
/* Copy output. */ /* 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) { 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)); MESOSPHERE_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success));
/* Copy output. */ /* Copy output. */
std::memcpy(dst, &args.x[1], size); std::memcpy(dst, std::addressof(args.x[1]), size);
} }
void NORETURN Panic(u32 color) { void NORETURN Panic(u32 color) {

View File

@@ -25,18 +25,18 @@ namespace ams::kern {
public: public:
static constexpr size_t MaxMemoryRegions = 200; static constexpr size_t MaxMemoryRegions = 200;
private: private:
KMemoryRegion region_heap[MaxMemoryRegions]; KMemoryRegion m_region_heap[MaxMemoryRegions];
size_t num_regions; size_t m_num_regions;
public: public:
constexpr ALWAYS_INLINE KMemoryRegionAllocator() : region_heap(), num_regions() { /* ... */ } constexpr ALWAYS_INLINE KMemoryRegionAllocator() : m_region_heap(), m_num_regions() { /* ... */ }
public: public:
template<typename... Args> template<typename... Args>
ALWAYS_INLINE KMemoryRegion *Allocate(Args&&... args) { ALWAYS_INLINE KMemoryRegion *Allocate(Args&&... args) {
/* Ensure we stay within the bounds of our heap. */ /* 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. */ /* 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)...); std::construct_at(region, std::forward<Args>(args)...);
return region; return region;

View File

@@ -182,7 +182,7 @@ namespace ams::kern {
if (m_current_hints[which] + value <= m_limit_values[which] && (timeout < 0 || KHardwareTimer::GetTick() < timeout)) { if (m_current_hints[which] + value <= m_limit_values[which] && (timeout < 0 || KHardwareTimer::GetTick() < timeout)) {
m_waiter_count++; m_waiter_count++;
m_cond_var.Wait(&m_lock, timeout, false); m_cond_var.Wait(std::addressof(m_lock), timeout, false);
m_waiter_count--; m_waiter_count--;
if (GetCurrentThread().IsTerminationRequested()) { if (GetCurrentThread().IsTerminationRequested()) {

View File

@@ -39,7 +39,7 @@ namespace ams::kern {
const uintptr_t stack_bottom = stack_top - PageSize; const uintptr_t stack_bottom = stack_top - PageSize;
KPhysicalAddress stack_paddr = Null<KPhysicalAddress>; 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)); MESOSPHERE_R_ABORT_UNLESS(Kernel::GetKernelPageTable().UnmapPages(stack_bottom, 1, KMemoryState_Kernel));

View File

@@ -41,7 +41,7 @@ namespace ams::kern {
/* Get the physical address of the page. */ /* Get the physical address of the page. */
KPhysicalAddress phys_addr = Null<KPhysicalAddress>; 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. */ /* Unmap the page. */
R_TRY(m_owner->GetPageTable().UnmapPages(this->GetAddress(), 1, KMemoryState_ThreadLocal)); R_TRY(m_owner->GetPageTable().UnmapPages(this->GetAddress(), 1, KMemoryState_ThreadLocal));

View File

@@ -28,6 +28,7 @@ namespace ams::impl {
/* sm. */ /* sm. */
AMS_DEFINE_SYSTEM_THREAD(-1, sm, Main); AMS_DEFINE_SYSTEM_THREAD(-1, sm, Main);
AMS_DEFINE_SYSTEM_THREAD(-1, sm, DispatcherThread);
/* spl. */ /* spl. */
AMS_DEFINE_SYSTEM_THREAD(-1, spl, Main); AMS_DEFINE_SYSTEM_THREAD(-1, spl, Main);
@@ -114,6 +115,7 @@ namespace ams::impl {
/* settings. */ /* settings. */
AMS_DEFINE_SYSTEM_THREAD(21, settings, Main); AMS_DEFINE_SYSTEM_THREAD(21, settings, Main);
AMS_DEFINE_SYSTEM_THREAD(21, settings, IpcServer); AMS_DEFINE_SYSTEM_THREAD(21, settings, IpcServer);
AMS_DEFINE_SYSTEM_THREAD(21, settings, LazyWriter);
/* erpt. */ /* erpt. */
AMS_DEFINE_SYSTEM_THREAD(21, erpt, Main); 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_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_NAME(__AMS_MODULE__, __AMS_THREAD_NAME__) ( ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__ ).name

View File

@@ -20,10 +20,6 @@
namespace ams::cfg { namespace ams::cfg {
/* Privileged Process configuration. */
bool IsInitialProcess();
void GetInitialProcessRange(os::ProcessId *out_min, os::ProcessId *out_max);
/* SD card configuration. */ /* SD card configuration. */
bool IsSdCardRequiredServicesReady(); bool IsSdCardRequiredServicesReady();
void WaitSdCardRequiredServicesReady(); void WaitSdCardRequiredServicesReady();

View File

@@ -63,7 +63,7 @@ namespace ams::cfg {
static_assert(util::is_pod<OverrideStatus>::value, "util::is_pod<OverrideStatus>::value"); static_assert(util::is_pod<OverrideStatus>::value, "util::is_pod<OverrideStatus>::value");
constexpr inline bool operator==(const OverrideStatus &lhs, const OverrideStatus &rhs) { 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) { constexpr inline bool operator!=(const OverrideStatus &lhs, const OverrideStatus &rhs) {

View File

@@ -24,23 +24,23 @@ namespace ams::ddsf {
NON_COPYABLE(DeviceCodeEntry); NON_COPYABLE(DeviceCodeEntry);
NON_MOVEABLE(DeviceCodeEntry); NON_MOVEABLE(DeviceCodeEntry);
private: private:
ams::DeviceCode device_code = ams::InvalidDeviceCode; ams::DeviceCode m_device_code = ams::InvalidDeviceCode;
IDevice *device = nullptr; IDevice *m_device = nullptr;
public: 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); AMS_ASSERT(dev != nullptr);
} }
constexpr ams::DeviceCode GetDeviceCode() const { constexpr ams::DeviceCode GetDeviceCode() const {
return this->device_code; return m_device_code;
} }
constexpr IDevice &GetDevice() { constexpr IDevice &GetDevice() {
return *this->device; return *m_device;
} }
constexpr const IDevice &GetDevice() const { constexpr const IDevice &GetDevice() const {
return *this->device; return *m_device;
} }
}; };
@@ -48,15 +48,15 @@ namespace ams::ddsf {
NON_COPYABLE(DeviceCodeEntryHolder); NON_COPYABLE(DeviceCodeEntryHolder);
NON_MOVEABLE(DeviceCodeEntryHolder); NON_MOVEABLE(DeviceCodeEntryHolder);
private: private:
util::IntrusiveListNode list_node; util::IntrusiveListNode m_list_node;
util::TypedStorage<DeviceCodeEntry> entry_storage; util::TypedStorage<DeviceCodeEntry> m_entry_storage;
bool is_constructed; bool m_is_constructed;
public: public:
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::list_node>; using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::m_list_node>;
using List = typename ListTraits::ListType; 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: 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 { bool IsLinkedToList() const {
return this->list_node.IsLinked(); return m_list_node.IsLinked();
} }
DeviceCodeEntry &Construct(DeviceCode dc, IDevice *dev) { DeviceCodeEntry &Construct(DeviceCode dc, IDevice *dev) {
AMS_ASSERT(!this->IsConstructed()); AMS_ASSERT(!this->IsConstructed());
DeviceCodeEntry *entry = util::ConstructAt(this->entry_storage, dc, dev); DeviceCodeEntry *entry = util::ConstructAt(m_entry_storage, dc, dev);
this->is_constructed = true; m_is_constructed = true;
return *entry; return *entry;
} }
bool IsConstructed() const { bool IsConstructed() const {
return this->is_constructed; return m_is_constructed;
} }
void Destroy() { void Destroy() {
AMS_ASSERT(this->IsConstructed()); AMS_ASSERT(this->IsConstructed());
util::DestroyAt(this->entry_storage); util::DestroyAt(m_entry_storage);
this->is_constructed = false; m_is_constructed = false;
} }
DeviceCodeEntry &Get() { DeviceCodeEntry &Get() {
AMS_ASSERT(this->IsConstructed()); AMS_ASSERT(this->IsConstructed());
return GetReference(this->entry_storage); return GetReference(m_entry_storage);
} }
const DeviceCodeEntry &Get() const { const DeviceCodeEntry &Get() const {
AMS_ASSERT(this->IsConstructed()); AMS_ASSERT(this->IsConstructed());
return GetReference(this->entry_storage); return GetReference(m_entry_storage);
} }
}; };
static_assert(DeviceCodeEntryHolder::ListTraits::IsValid()); static_assert(DeviceCodeEntryHolder::ListTraits::IsValid());

View File

@@ -25,33 +25,33 @@ namespace ams::ddsf {
class DeviceCodeEntryManager { class DeviceCodeEntryManager {
private: private:
ams::MemoryResource *memory_resource; ams::MemoryResource *m_memory_resource;
ddsf::DeviceCodeEntryHolder::List entry_list; ddsf::DeviceCodeEntryHolder::List m_entry_list;
mutable os::SdkMutex entry_list_lock; mutable os::SdkMutex m_entry_list_lock;
private: private:
void DestroyAllEntries() { void DestroyAllEntries() {
auto it = this->entry_list.begin(); auto it = m_entry_list.begin();
while (it != this->entry_list.end()) { while (it != m_entry_list.end()) {
ddsf::DeviceCodeEntryHolder *entry = std::addressof(*it); ddsf::DeviceCodeEntryHolder *entry = std::addressof(*it);
it = this->entry_list.erase(it); it = m_entry_list.erase(it);
AMS_ASSERT(entry->IsConstructed()); AMS_ASSERT(entry->IsConstructed());
if (entry->IsConstructed()) { if (entry->IsConstructed()) {
entry->Destroy(); entry->Destroy();
} }
this->memory_resource->Deallocate(entry, sizeof(*entry)); m_memory_resource->Deallocate(entry, sizeof(*entry));
} }
} }
public: 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() { ~DeviceCodeEntryManager() {
this->DestroyAllEntries(); this->DestroyAllEntries();
} }
void Reset() { void Reset() {
std::scoped_lock lk(this->entry_list_lock); std::scoped_lock lk(m_entry_list_lock);
this->DestroyAllEntries(); this->DestroyAllEntries();
} }
@@ -66,7 +66,7 @@ namespace ams::ddsf {
template<typename F> template<typename F>
int ForEachEntry(F 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()); AMS_ASSERT(holder.IsConstructed());
return f(holder.Get()); return f(holder.Get());
}); });
@@ -74,7 +74,7 @@ namespace ams::ddsf {
template<typename F> template<typename F>
int ForEachEntry(F f) const { 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()); AMS_ASSERT(holder.IsConstructed());
return f(holder.Get()); return f(holder.Get());
}); });

View File

@@ -28,41 +28,41 @@ namespace ams::ddsf {
private: private:
struct LoopControlCommandParameters; struct LoopControlCommandParameters;
private: private:
bool is_initialized; bool m_is_initialized;
bool is_looping; bool m_is_looping;
os::SdkConditionVariable is_looping_cv; os::SdkConditionVariable m_is_looping_cv;
os::MultiWaitType multi_wait; os::MultiWaitType m_multi_wait;
os::ThreadType *loop_thread; os::ThreadType *m_loop_thread;
os::Event loop_control_event; os::Event m_loop_control_event;
os::MultiWaitHolderType loop_control_event_holder; os::MultiWaitHolderType m_loop_control_event_holder;
LoopControlCommandParameters *loop_control_command_params; LoopControlCommandParameters *m_loop_control_command_params;
os::LightEvent loop_control_command_done_event; os::LightEvent m_loop_control_command_done_event;
os::SdkMutex loop_control_lock; os::SdkMutex m_loop_control_lock;
private: private:
void ProcessControlCommand(LoopControlCommandParameters *params); void ProcessControlCommand(LoopControlCommandParameters *params);
void ProcessControlCommandImpl(LoopControlCommandParameters *params); void ProcessControlCommandImpl(LoopControlCommandParameters *params);
public: public:
EventHandlerManager() EventHandlerManager()
: is_initialized(false), is_looping(false), is_looping_cv(), multi_wait(), : m_is_initialized(false), m_is_looping(false), m_is_looping_cv(), m_multi_wait(),
loop_thread(), loop_control_event(os::EventClearMode_AutoClear), loop_control_event_holder(), m_loop_thread(), m_loop_control_event(os::EventClearMode_AutoClear), m_loop_control_event_holder(),
loop_control_command_params(), loop_control_command_done_event(os::EventClearMode_AutoClear), m_loop_control_command_params(), m_loop_control_command_done_event(os::EventClearMode_AutoClear),
loop_control_lock() m_loop_control_lock()
{ {
this->Initialize(); this->Initialize();
} }
~EventHandlerManager() { ~EventHandlerManager() {
if (this->is_looping) { if (m_is_looping) {
AMS_ASSERT(!this->IsRunningOnLoopThread()); AMS_ASSERT(!this->IsRunningOnLoopThread());
this->RequestStop(); this->RequestStop();
} }
if (this->is_initialized) { if (m_is_initialized) {
this->Finalize(); this->Finalize();
} }
} }
bool IsRunningOnLoopThread() const { return this->loop_thread == os::GetCurrentThread(); } bool IsRunningOnLoopThread() const { return m_loop_thread == os::GetCurrentThread(); }
bool IsLooping() const { return this->is_looping; } bool IsLooping() const { return m_is_looping; }
void Initialize(); void Initialize();
void Finalize(); void Finalize();

View File

@@ -32,57 +32,57 @@ namespace ams::ddsf {
public: public:
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice); AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice);
private: private:
util::IntrusiveListNode list_node; util::IntrusiveListNode m_list_node;
IDriver *driver; IDriver *m_driver;
ISession::List session_list; ISession::List m_session_list;
mutable os::SdkMutex session_list_lock; mutable os::SdkMutex m_session_list_lock;
bool is_exclusive_write; bool m_is_exclusive_write;
public: public:
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDevice::list_node>; using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDevice::m_list_node>;
using List = typename ListTraits::ListType; 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: private:
Result AttachSession(ISession *session) { Result AttachSession(ISession *session) {
AMS_ASSERT(session != nullptr); 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. */ /* Check if we're allowed to attach the session. */
if (this->is_exclusive_write && session->CheckExclusiveWrite()) { if (m_is_exclusive_write && session->CheckExclusiveWrite()) {
for (const auto &attached : this->session_list) { for (const auto &attached : m_session_list) {
R_UNLESS(!attached.CheckAccess(AccessMode_Write), ddsf::ResultAccessModeDenied()); R_UNLESS(!attached.CheckAccess(AccessMode_Write), ddsf::ResultAccessModeDenied());
} }
} }
/* Attach the session. */ /* Attach the session. */
this->session_list.push_back(*session); m_session_list.push_back(*session);
return ResultSuccess(); return ResultSuccess();
} }
void DetachSession(ISession *session) { void DetachSession(ISession *session) {
AMS_ASSERT(session != nullptr); AMS_ASSERT(session != nullptr);
std::scoped_lock lk(this->session_list_lock); std::scoped_lock lk(m_session_list_lock);
this->session_list.erase(this->session_list.iterator_to(*session)); m_session_list.erase(m_session_list.iterator_to(*session));
} }
void AttachDriver(IDriver *drv) { void AttachDriver(IDriver *drv) {
AMS_ASSERT(drv != nullptr); AMS_ASSERT(drv != nullptr);
AMS_ASSERT(!this->IsDriverAttached()); AMS_ASSERT(!this->IsDriverAttached());
this->driver = drv; m_driver = drv;
AMS_ASSERT(this->IsDriverAttached()); AMS_ASSERT(this->IsDriverAttached());
} }
void DetachDriver() { void DetachDriver() {
AMS_ASSERT(this->IsDriverAttached()); AMS_ASSERT(this->IsDriverAttached());
this->driver = nullptr; m_driver = nullptr;
AMS_ASSERT(!this->IsDriverAttached()); AMS_ASSERT(!this->IsDriverAttached());
} }
public: public:
IDevice(bool exclusive_write) : list_node(), driver(nullptr), session_list(), session_list_lock(), is_exclusive_write(exclusive_write) { IDevice(bool exclusive_write) : m_list_node(), m_driver(nullptr), m_session_list(), m_session_list_lock(), m_is_exclusive_write(exclusive_write) {
this->session_list.clear(); m_session_list.clear();
} }
protected: protected:
~IDevice() { ~IDevice() {
this->session_list.clear(); m_session_list.clear();
} }
public: public:
void AddTo(List &list) { void AddTo(List &list) {
@@ -94,45 +94,45 @@ namespace ams::ddsf {
} }
bool IsLinkedToList() const { bool IsLinkedToList() const {
return this->list_node.IsLinked(); return m_list_node.IsLinked();
} }
IDriver &GetDriver() { IDriver &GetDriver() {
AMS_ASSERT(this->IsDriverAttached()); AMS_ASSERT(this->IsDriverAttached());
return *this->driver; return *m_driver;
} }
const IDriver &GetDriver() const { const IDriver &GetDriver() const {
AMS_ASSERT(this->IsDriverAttached()); AMS_ASSERT(this->IsDriverAttached());
return *this->driver; return *m_driver;
} }
bool IsDriverAttached() const { bool IsDriverAttached() const {
return this->driver != nullptr; return m_driver != nullptr;
} }
template<typename F> template<typename F>
Result ForEachSession(F f, bool return_on_fail) { 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> template<typename F>
Result ForEachSession(F f, bool return_on_fail) const { 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> template<typename F>
int ForEachSession(F 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> template<typename F>
int ForEachSession(F f) const { 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 { bool HasAnyOpenSession() const {
return !this->session_list.empty(); return !m_session_list.empty();
} }
}; };
static_assert(IDevice::ListTraits::IsValid()); static_assert(IDevice::ListTraits::IsValid());

View File

@@ -27,21 +27,21 @@ namespace ams::ddsf {
public: public:
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDriver); AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDriver);
private: private:
util::IntrusiveListNode list_node; util::IntrusiveListNode m_list_node;
IDevice::List device_list; IDevice::List m_device_list;
mutable os::SdkMutex device_list_lock; mutable os::SdkMutex m_device_list_lock;
public: public:
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDriver::list_node>; using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&IDriver::m_list_node>;
using List = typename ListTraits::ListType; 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: private:
public: public:
IDriver() : list_node(), device_list(), device_list_lock() { IDriver() : m_list_node(), m_device_list(), m_device_list_lock() {
this->device_list.clear(); m_device_list.clear();
} }
protected: protected:
~IDriver() { ~IDriver() {
this->device_list.clear(); m_device_list.clear();
} }
public: public:
void AddTo(List &list) { void AddTo(List &list) {
@@ -53,45 +53,45 @@ namespace ams::ddsf {
} }
bool IsLinkedToList() const { bool IsLinkedToList() const {
return this->list_node.IsLinked(); return m_list_node.IsLinked();
} }
bool HasAnyDevice() const { bool HasAnyDevice() const {
return !this->device_list.empty(); return !m_device_list.empty();
} }
void RegisterDevice(IDevice *dev) { void RegisterDevice(IDevice *dev) {
AMS_ASSERT(dev != nullptr); AMS_ASSERT(dev != nullptr);
std::scoped_lock lk(this->device_list_lock); std::scoped_lock lk(m_device_list_lock);
dev->AttachDriver(this); dev->AttachDriver(this);
this->device_list.push_back(*dev); m_device_list.push_back(*dev);
} }
void UnregisterDevice(IDevice *dev) { void UnregisterDevice(IDevice *dev) {
AMS_ASSERT(dev != nullptr); AMS_ASSERT(dev != nullptr);
std::scoped_lock lk(this->device_list_lock); std::scoped_lock lk(m_device_list_lock);
this->device_list.erase(this->device_list.iterator_to(*dev)); m_device_list.erase(m_device_list.iterator_to(*dev));
dev->DetachDriver(); dev->DetachDriver();
} }
template<typename F> template<typename F>
Result ForEachDevice(F f, bool return_on_fail) { 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> template<typename F>
Result ForEachDevice(F f, bool return_on_fail) const { 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> template<typename F>
int ForEachDevice(F 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> template<typename F>
int ForEachDevice(F f) const { 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()); static_assert(IDriver::ListTraits::IsValid());

View File

@@ -26,22 +26,22 @@ namespace ams::ddsf {
NON_MOVEABLE(IEventHandler); NON_MOVEABLE(IEventHandler);
friend class EventHandlerManager; friend class EventHandlerManager;
private: private:
os::MultiWaitHolderType holder; os::MultiWaitHolderType m_holder;
uintptr_t user_data; uintptr_t m_user_data;
bool is_initialized; bool m_is_initialized;
bool is_registered; bool m_is_registered;
private: private:
void Link(os::MultiWaitType *multi_wait) { void Link(os::MultiWaitType *multi_wait) {
AMS_ASSERT(this->IsInitialized()); AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(!this->IsRegistered()); AMS_ASSERT(!this->IsRegistered());
AMS_ASSERT(multi_wait != nullptr); AMS_ASSERT(multi_wait != nullptr);
os::LinkMultiWaitHolder(multi_wait, std::addressof(this->holder)); os::LinkMultiWaitHolder(multi_wait, std::addressof(m_holder));
} }
void Unlink() { void Unlink() {
AMS_ASSERT(this->IsInitialized()); AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(this->IsRegistered()); AMS_ASSERT(this->IsRegistered());
os::UnlinkMultiWaitHolder(std::addressof(this->holder)); os::UnlinkMultiWaitHolder(std::addressof(m_holder));
} }
static IEventHandler &ToEventHandler(os::MultiWaitHolderType *holder) { static IEventHandler &ToEventHandler(os::MultiWaitHolderType *holder) {
@@ -51,7 +51,7 @@ namespace ams::ddsf {
return event_handler; return event_handler;
} }
public: 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() { ~IEventHandler() {
if (this->IsRegistered()) { if (this->IsRegistered()) {
@@ -62,28 +62,28 @@ namespace ams::ddsf {
} }
} }
bool IsInitialized() const { return this->is_initialized; } bool IsInitialized() const { return m_is_initialized; }
bool IsRegistered() const { return this->is_registered; } bool IsRegistered() const { return m_is_registered; }
uintptr_t GetUserData() const { return this->user_data; } uintptr_t GetUserData() const { return m_user_data; }
void SetUserData(uintptr_t d) { this->user_data = d; } void SetUserData(uintptr_t d) { m_user_data = d; }
template<typename T> template<typename T>
void Initialize(T *object) { void Initialize(T *object) {
AMS_ASSERT(object != nullptr); AMS_ASSERT(object != nullptr);
AMS_ASSERT(!this->IsInitialized()); AMS_ASSERT(!this->IsInitialized());
os::InitializeMultiWaitHolder(std::addressof(this->holder), object); os::InitializeMultiWaitHolder(std::addressof(m_holder), object);
os::SetMultiWaitHolderUserData(std::addressof(this->holder), reinterpret_cast<uintptr_t>(this)); os::SetMultiWaitHolderUserData(std::addressof(m_holder), reinterpret_cast<uintptr_t>(this));
this->is_initialized = true; m_is_initialized = true;
this->is_registered = false; m_is_registered = false;
} }
void Finalize() { void Finalize() {
AMS_ASSERT(this->IsInitialized()); AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(!this->IsRegistered()); AMS_ASSERT(!this->IsRegistered());
os::FinalizeMultiWaitHolder(std::addressof(this->holder)); os::FinalizeMultiWaitHolder(std::addressof(m_holder));
this->is_initialized = false; m_is_initialized = false;
this->is_registered = false; m_is_registered = false;
} }
protected: protected:
virtual void HandleEvent() = 0; virtual void HandleEvent() = 0;

View File

@@ -33,30 +33,30 @@ namespace ams::ddsf {
public: public:
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice); AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice);
private: private:
util::IntrusiveListNode list_node; util::IntrusiveListNode m_list_node;
IDevice *device; IDevice *m_device;
AccessMode access_mode; AccessMode m_access_mode;
public: public:
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&ISession::list_node>; using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&ISession::m_list_node>;
using List = typename ListTraits::ListType; 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: private:
void AttachDevice(IDevice *dev, AccessMode mode) { void AttachDevice(IDevice *dev, AccessMode mode) {
AMS_ASSERT(dev != nullptr); AMS_ASSERT(dev != nullptr);
AMS_ASSERT(!this->IsOpen()); AMS_ASSERT(!this->IsOpen());
this->device = dev; m_device = dev;
this->access_mode = mode; m_access_mode = mode;
AMS_ASSERT(this->IsOpen()); AMS_ASSERT(this->IsOpen());
} }
void DetachDevice() { void DetachDevice() {
AMS_ASSERT(this->IsOpen()); AMS_ASSERT(this->IsOpen());
this->device = nullptr; m_device = nullptr;
this->access_mode = AccessMode_None; m_access_mode = AccessMode_None;
AMS_ASSERT(!this->IsOpen()); AMS_ASSERT(!this->IsOpen());
} }
public: public:
ISession() : list_node(), device(nullptr), access_mode() { /* ... */ } ISession() : m_list_node(), m_device(nullptr), m_access_mode() { /* ... */ }
protected: protected:
~ISession() { this->DetachDevice(); AMS_ASSERT(!this->IsOpen()); } ~ISession() { this->DetachDevice(); AMS_ASSERT(!this->IsOpen()); }
public: public:
@@ -69,26 +69,26 @@ namespace ams::ddsf {
} }
bool IsLinkedToList() const { bool IsLinkedToList() const {
return this->list_node.IsLinked(); return m_list_node.IsLinked();
} }
IDevice &GetDevice() { IDevice &GetDevice() {
AMS_ASSERT(this->IsOpen()); AMS_ASSERT(this->IsOpen());
return *this->device; return *m_device;
} }
const IDevice &GetDevice() const { const IDevice &GetDevice() const {
AMS_ASSERT(this->IsOpen()); AMS_ASSERT(this->IsOpen());
return *this->device; return *m_device;
} }
bool IsOpen() const { bool IsOpen() const {
return this->device != nullptr; return m_device != nullptr;
} }
bool CheckAccess(AccessMode mode) const { bool CheckAccess(AccessMode mode) const {
AMS_ASSERT(this->IsOpen()); AMS_ASSERT(this->IsOpen());
return ((~this->access_mode) & mode) == 0; return ((~m_access_mode) & mode) == 0;
} }
bool CheckExclusiveWrite() const { bool CheckExclusiveWrite() const {

View File

@@ -37,21 +37,21 @@ namespace ams::ddsf::impl {
class TypeTag { class TypeTag {
private: private:
const char * const class_name; const char * const m_class_name;
const TypeTag * const base; const TypeTag * const m_base;
public: public:
#if !(defined(AMS_BUILD_FOR_DEBUGGING) || defined(AMS_BUILD_FOR_AUDITING)) #if !(defined(AMS_BUILD_FOR_DEBUGGING) || defined(AMS_BUILD_FOR_AUDITING))
constexpr TypeTag() : class_name(nullptr), base(nullptr) { /* ... */} constexpr TypeTag() : m_class_name(nullptr), m_base(nullptr) { /* ... */}
constexpr TypeTag(const TypeTag &b) : class_name(nullptr), base(std::addressof(b)) { AMS_ASSERT(this != this->base); } 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) : m_class_name(nullptr), m_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, const TypeTag &b) : m_class_name(nullptr), m_base(std::addressof(b)) { AMS_UNUSED(c); AMS_ASSERT(this != m_base); }
#else #else
constexpr TypeTag(const char *c) : class_name(c), base(nullptr) { /* ... */ } constexpr TypeTag(const char *c) : m_class_name(c), m_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, const TypeTag &b) : m_class_name(c), m_base(std::addressof(b)) { AMS_ASSERT(this != m_base); }
#endif #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); } 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)) { if (cur == std::addressof(rhs)) {
return true; return true;
} }
cur = cur->base; cur = cur->m_base;
} }
return false; return false;
} }

View File

@@ -33,7 +33,7 @@ namespace ams::dmnt::cheat {
MemoryRegionExtents heap_extents; MemoryRegionExtents heap_extents;
MemoryRegionExtents alias_extents; MemoryRegionExtents alias_extents;
MemoryRegionExtents aslr_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!"); static_assert(util::is_pod<CheatProcessMetadata>::value && sizeof(CheatProcessMetadata) == 0x70, "CheatProcessMetadata definition!");

View File

@@ -135,8 +135,8 @@ namespace ams::fs {
using DirectoryEntryMapTable = EntryMapTable<RomEntryKey, EntryKey, RomDirectoryEntry>; using DirectoryEntryMapTable = EntryMapTable<RomEntryKey, EntryKey, RomDirectoryEntry>;
using FileEntryMapTable = EntryMapTable<RomEntryKey, EntryKey, RomFileEntry>; using FileEntryMapTable = EntryMapTable<RomEntryKey, EntryKey, RomFileEntry>;
private: private:
DirectoryEntryMapTable dir_table; DirectoryEntryMapTable m_dir_table;
FileEntryMapTable file_table; FileEntryMapTable m_file_table;
public: public:
static s64 QueryDirectoryEntryBucketStorageSize(s64 count); static s64 QueryDirectoryEntryBucketStorageSize(s64 count);
static size_t QueryDirectoryEntrySize(size_t aux_size); static size_t QueryDirectoryEntrySize(size_t aux_size);
@@ -148,11 +148,11 @@ namespace ams::fs {
HierarchicalRomFileTable(); HierarchicalRomFileTable();
constexpr u32 GetDirectoryEntryCount() const { constexpr u32 GetDirectoryEntryCount() const {
return this->dir_table.GetEntryCount(); return m_dir_table.GetEntryCount();
} }
constexpr u32 GetFileEntryCount() const { 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); Result Initialize(SubStorage dir_bucket, SubStorage dir_entry, SubStorage file_bucket, SubStorage file_entry);

View File

@@ -43,11 +43,11 @@ namespace ams::fs {
}; };
static_assert(util::is_pod<Element>::value); static_assert(util::is_pod<Element>::value);
private: private:
s64 bucket_count; s64 m_bucket_count;
SubStorage bucket_storage; SubStorage m_bucket_storage;
SubStorage kv_storage; SubStorage m_kv_storage;
s64 total_entry_size; s64 m_total_entry_size;
u32 entry_count; u32 m_entry_count;
public: public:
static constexpr s64 QueryBucketStorageSize(s64 num) { static constexpr s64 QueryBucketStorageSize(s64 num) {
return num * sizeof(Position); return num * sizeof(Position);
@@ -69,42 +69,42 @@ namespace ams::fs {
return ResultSuccess(); return ResultSuccess();
} }
public: 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) { Result Initialize(const SubStorage &bucket, s64 count, const SubStorage &kv) {
AMS_ASSERT(count > 0); AMS_ASSERT(count > 0);
this->bucket_storage = bucket; m_bucket_storage = bucket;
this->bucket_count = count; m_bucket_count = count;
this->kv_storage = kv; m_kv_storage = kv;
return ResultSuccess(); return ResultSuccess();
} }
void Finalize() { void Finalize() {
this->bucket_storage = SubStorage(); m_bucket_storage = SubStorage();
this->kv_storage = SubStorage(); m_kv_storage = SubStorage();
this->bucket_count = 0; m_bucket_count = 0;
} }
s64 GetTotalEntrySize() const { s64 GetTotalEntrySize() const {
return this->total_entry_size; return m_total_entry_size;
} }
Result GetFreeSize(s64 *out) { Result GetFreeSize(s64 *out) {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
s64 kv_size = 0; s64 kv_size = 0;
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size))); R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
*out = kv_size - this->total_entry_size; *out = kv_size - m_total_entry_size;
return ResultSuccess(); return ResultSuccess();
} }
constexpr u32 GetEntryCount() const { constexpr u32 GetEntryCount() const {
return this->entry_count; return m_entry_count;
} }
protected: protected:
Result AddInternal(Position *out, const Key &key, u32 hash_key, const void *aux, size_t aux_size, const Value &value) { 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(out != nullptr);
AMS_ASSERT(aux != nullptr || aux_size == 0); AMS_ASSERT(aux != nullptr || aux_size == 0);
AMS_ASSERT(this->bucket_count > 0); AMS_ASSERT(m_bucket_count > 0);
{ {
Position pos, prev_pos; Position pos, prev_pos;
@@ -125,7 +125,7 @@ namespace ams::fs {
R_TRY(this->WriteKeyValue(std::addressof(elem), pos, aux, aux_size)); R_TRY(this->WriteKeyValue(std::addressof(elem), pos, aux, aux_size));
*out = pos; *out = pos;
this->entry_count++; m_entry_count++;
return ResultSuccess(); return ResultSuccess();
} }
@@ -178,7 +178,7 @@ namespace ams::fs {
} }
private: private:
BucketIndex HashToBucket(u32 hash_key) const { 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) { 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_prev != nullptr);
AMS_ASSERT(out_elem != nullptr); AMS_ASSERT(out_elem != nullptr);
AMS_ASSERT(aux != nullptr || aux_size == 0); AMS_ASSERT(aux != nullptr || aux_size == 0);
AMS_ASSERT(this->bucket_count > 0); AMS_ASSERT(m_bucket_count > 0);
*out_pos = 0; *out_pos = 0;
*out_prev = 0; *out_prev = 0;
@@ -197,7 +197,7 @@ namespace ams::fs {
R_TRY(this->ReadBucket(std::addressof(cur), ind)); R_TRY(this->ReadBucket(std::addressof(cur), ind));
s64 kv_size; 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); AMS_ASSERT(cur == InvalidPosition || cur < kv_size);
R_UNLESS(cur != InvalidPosition, fs::ResultDbmKeyNotFound()); R_UNLESS(cur != InvalidPosition, fs::ResultDbmKeyNotFound());
@@ -225,13 +225,13 @@ namespace ams::fs {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
s64 kv_size; s64 kv_size;
R_TRY(this->kv_storage.GetSize(std::addressof(kv_size))); R_TRY(m_kv_storage.GetSize(std::addressof(kv_size)));
const size_t end_pos = this->total_entry_size + sizeof(Element) + aux_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()); 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(); return ResultSuccess();
} }
@@ -244,7 +244,7 @@ namespace ams::fs {
R_TRY(this->ReadBucket(std::addressof(next), ind)); R_TRY(this->ReadBucket(std::addressof(next), ind));
s64 kv_size; 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); AMS_ASSERT(next == InvalidPosition || next < kv_size);
R_TRY(this->WriteBucket(pos, ind)); R_TRY(this->WriteBucket(pos, ind));
@@ -255,27 +255,27 @@ namespace ams::fs {
Result ReadBucket(Position *out, BucketIndex ind) { Result ReadBucket(Position *out, BucketIndex ind) {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
AMS_ASSERT(ind < this->bucket_count); AMS_ASSERT(ind < m_bucket_count);
const s64 offset = ind * sizeof(Position); 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) { Result WriteBucket(Position pos, BucketIndex ind) {
AMS_ASSERT(ind < this->bucket_count); AMS_ASSERT(ind < m_bucket_count);
const s64 offset = ind * sizeof(Position); 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) { Result ReadKeyValue(Element *out, Position pos) {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
s64 kv_size; 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); 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) { 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; *out_aux_size = out->size;
if (out->size > 0) { 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(); return ResultSuccess();
@@ -298,13 +298,13 @@ namespace ams::fs {
AMS_ASSERT(aux != nullptr); AMS_ASSERT(aux != nullptr);
s64 kv_size; 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); 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) { 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(); return ResultSuccess();

View File

@@ -81,12 +81,12 @@ namespace ams::fs::RomPathTool {
class PathParser { class PathParser {
private: private:
const RomPathChar *prev_path_start; const RomPathChar *m_prev_path_start;
const RomPathChar *prev_path_end; const RomPathChar *m_prev_path_end;
const RomPathChar *next_path; const RomPathChar *m_next_path;
bool finished; bool m_finished;
public: 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); Result Initialize(const RomPathChar *path);
void Finalize(); void Finalize();

View File

@@ -28,42 +28,42 @@ namespace ams::fs {
private: private:
static constexpr s64 InvalidSize = -1; static constexpr s64 InvalidSize = -1;
private: private:
std::unique_ptr<fsa::IFile> unique_file; std::unique_ptr<fsa::IFile> m_unique_file;
std::shared_ptr<fsa::IFile> shared_file; std::shared_ptr<fsa::IFile> m_shared_file;
fsa::IFile *base_file; fsa::IFile *m_base_file;
s64 size; s64 m_size;
public: public:
FileStorage(fsa::IFile *f) : unique_file(f), size(InvalidSize) { FileStorage(fsa::IFile *f) : m_unique_file(f), m_size(InvalidSize) {
this->base_file = this->unique_file.get(); m_base_file = m_unique_file.get();
} }
FileStorage(std::unique_ptr<fsa::IFile> f) : unique_file(std::move(f)), size(InvalidSize) { FileStorage(std::unique_ptr<fsa::IFile> f) : m_unique_file(std::move(f)), m_size(InvalidSize) {
this->base_file = this->unique_file.get(); m_base_file = m_unique_file.get();
} }
FileStorage(std::shared_ptr<fsa::IFile> f) : shared_file(f), size(InvalidSize) { FileStorage(std::shared_ptr<fsa::IFile> f) : m_shared_file(f), m_size(InvalidSize) {
this->base_file = this->shared_file.get(); m_base_file = m_shared_file.get();
} }
virtual ~FileStorage() { /* ... */ } virtual ~FileStorage() { /* ... */ }
private: private:
Result UpdateSize(); Result UpdateSize();
protected: 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) { void SetFile(fs::fsa::IFile *file) {
AMS_ASSERT(file != nullptr); AMS_ASSERT(file != nullptr);
AMS_ASSERT(this->base_file == nullptr); AMS_ASSERT(m_base_file == nullptr);
this->base_file = file; m_base_file = file;
} }
void SetFile(std::unique_ptr<fs::fsa::IFile> &&file) { void SetFile(std::unique_ptr<fs::fsa::IFile> &&file) {
AMS_ASSERT(file != nullptr); AMS_ASSERT(file != nullptr);
AMS_ASSERT(this->base_file == nullptr); AMS_ASSERT(m_base_file == nullptr);
AMS_ASSERT(this->unique_file == nullptr); AMS_ASSERT(m_unique_file == nullptr);
this->unique_file = std::move(file); m_unique_file = std::move(file);
this->base_file = this->unique_file.get(); m_base_file = m_unique_file.get();
} }
public: public:
virtual Result Read(s64 offset, void *buffer, size_t size) override; virtual Result Read(s64 offset, void *buffer, size_t size) override;
@@ -78,9 +78,9 @@ namespace ams::fs {
NON_COPYABLE(FileStorageBasedFileSystem); NON_COPYABLE(FileStorageBasedFileSystem);
NON_MOVEABLE(FileStorageBasedFileSystem); NON_MOVEABLE(FileStorageBasedFileSystem);
private: private:
std::shared_ptr<fs::fsa::IFileSystem> base_file_system; std::shared_ptr<fs::fsa::IFileSystem> m_base_file_system;
public: 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); 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: private:
static constexpr s64 InvalidSize = -1; static constexpr s64 InvalidSize = -1;
private: private:
FileHandle handle; FileHandle m_handle;
bool close_file; bool m_close_file;
s64 size; s64 m_size;
os::SdkMutex mutex; os::SdkMutex m_mutex;
public: 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) { /* ... */ } constexpr explicit FileHandleStorage(FileHandle handle) : FileHandleStorage(handle, false) { /* ... */ }
virtual ~FileHandleStorage() override { virtual ~FileHandleStorage() override {
if (this->close_file) { if (m_close_file) {
CloseFile(this->handle); CloseFile(m_handle);
} }
} }
protected: protected:

View File

@@ -28,13 +28,13 @@ namespace ams::fs {
class FsContext { class FsContext {
private: private:
ResultHandler handler; ResultHandler m_handler;
public: 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); void SetDefaultFsContextResultHandler(const ResultHandler handler);
@@ -44,24 +44,24 @@ namespace ams::fs {
class ScopedFsContext { class ScopedFsContext {
private: private:
const FsContext * const prev_context; const FsContext * const m_prev_context;
public: public:
ALWAYS_INLINE ScopedFsContext(const FsContext &ctx) : prev_context(GetCurrentThreadFsContext()) { ALWAYS_INLINE ScopedFsContext(const FsContext &ctx) : m_prev_context(GetCurrentThreadFsContext()) {
SetCurrentThreadFsContext(std::addressof(ctx)); SetCurrentThreadFsContext(std::addressof(ctx));
} }
ALWAYS_INLINE ~ScopedFsContext() { ALWAYS_INLINE ~ScopedFsContext() {
SetCurrentThreadFsContext(this->prev_context); SetCurrentThreadFsContext(m_prev_context);
} }
}; };
class ScopedAutoAbortDisabler { class ScopedAutoAbortDisabler {
private: private:
const FsContext * const prev_context; const FsContext * const m_prev_context;
public: public:
ScopedAutoAbortDisabler(); ScopedAutoAbortDisabler();
ALWAYS_INLINE ~ScopedAutoAbortDisabler() { ALWAYS_INLINE ~ScopedAutoAbortDisabler() {
SetCurrentThreadFsContext(this->prev_context); SetCurrentThreadFsContext(m_prev_context);
} }
}; };

View File

@@ -19,7 +19,7 @@
namespace ams::fs { namespace ams::fs {
struct ReadOption { struct ReadOption {
u32 value; u32 _value;
static const ReadOption None; static const ReadOption None;
}; };
@@ -27,7 +27,7 @@ namespace ams::fs {
inline constexpr const ReadOption ReadOption::None = {FsReadOption_None}; inline constexpr const ReadOption ReadOption::None = {FsReadOption_None};
inline constexpr bool operator==(const ReadOption &lhs, const ReadOption &rhs) { 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) { 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)); static_assert(util::is_pod<ReadOption>::value && sizeof(ReadOption) == sizeof(u32));
struct WriteOption { struct WriteOption {
u32 value; u32 _value;
constexpr inline bool HasFlushFlag() const { constexpr inline bool HasFlushFlag() const {
return this->value & FsWriteOption_Flush; return _value & FsWriteOption_Flush;
} }
static const WriteOption None; static const WriteOption None;
@@ -51,7 +51,7 @@ namespace ams::fs {
inline constexpr const WriteOption WriteOption::Flush = {FsWriteOption_Flush}; inline constexpr const WriteOption WriteOption::Flush = {FsWriteOption_Flush};
inline constexpr bool operator==(const WriteOption &lhs, const WriteOption &rhs) { 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) { inline constexpr bool operator!=(const WriteOption &lhs, const WriteOption &rhs) {

View File

@@ -64,36 +64,36 @@ namespace ams::fs {
class ReadOnlyStorageAdapter : public IStorage { class ReadOnlyStorageAdapter : public IStorage {
private: private:
std::shared_ptr<IStorage> shared_storage; std::shared_ptr<IStorage> m_shared_storage;
std::unique_ptr<IStorage> unique_storage; std::unique_ptr<IStorage> m_unique_storage;
IStorage *storage; IStorage *m_storage;
public: public:
ReadOnlyStorageAdapter(IStorage *s) : unique_storage(s) { ReadOnlyStorageAdapter(IStorage *s) : m_unique_storage(s) {
this->storage = this->unique_storage.get(); m_storage = m_unique_storage.get();
} }
ReadOnlyStorageAdapter(std::shared_ptr<IStorage> s) : shared_storage(s) { ReadOnlyStorageAdapter(std::shared_ptr<IStorage> s) : m_shared_storage(s) {
this->storage = this->shared_storage.get(); m_storage = m_shared_storage.get();
} }
ReadOnlyStorageAdapter(std::unique_ptr<IStorage> s) : unique_storage(std::move(s)) { ReadOnlyStorageAdapter(std::unique_ptr<IStorage> s) : m_unique_storage(std::move(s)) {
this->storage = this->unique_storage.get(); m_storage = m_unique_storage.get();
} }
virtual ~ReadOnlyStorageAdapter() { /* ... */ } virtual ~ReadOnlyStorageAdapter() { /* ... */ }
public: public:
virtual Result Read(s64 offset, void *buffer, size_t size) override { 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 { virtual Result Flush() override {
return this->storage->Flush(); return m_storage->Flush();
} }
virtual Result GetSize(s64 *out) override { 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 { 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 { virtual Result Write(s64 offset, const void *buffer, size_t size) override {

View File

@@ -30,13 +30,13 @@ namespace ams::fs {
class Deleter { class Deleter {
private: private:
size_t size; size_t m_size;
public: public:
Deleter() : size() { /* ... */ } Deleter() : m_size() { /* ... */ }
explicit Deleter(size_t sz) : size(sz) { /* ... */ } explicit Deleter(size_t sz) : m_size(sz) { /* ... */ }
void operator()(void *ptr) const { void operator()(void *ptr) const {
::ams::fs::impl::Deallocate(ptr, this->size); ::ams::fs::impl::Deallocate(ptr, m_size);
} }
}; };

View File

@@ -22,21 +22,21 @@ namespace ams::fs {
class MemoryStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable { class MemoryStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
private: private:
u8 * const buf; u8 * const m_buf;
const s64 size; const s64 m_size;
public: 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: public:
virtual Result Read(s64 offset, void *buffer, size_t size) override { virtual Result Read(s64 offset, void *buffer, size_t size) override {
/* Succeed immediately on zero-sized read. */ /* Succeed immediately on zero-sized read. */
R_SUCCEED_IF(size == 0); R_SUCCEED_IF(size == 0);
/* Validate arguments. */ /* Validate arguments. */
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
/* Copy from memory. */ /* Copy from memory. */
std::memcpy(buffer, this->buf + offset, size); std::memcpy(buffer, m_buf + offset, size);
return ResultSuccess(); return ResultSuccess();
} }
@@ -45,11 +45,11 @@ namespace ams::fs {
R_SUCCEED_IF(size == 0); R_SUCCEED_IF(size == 0);
/* Validate arguments. */ /* Validate arguments. */
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
/* Copy to memory. */ /* Copy to memory. */
std::memcpy(this->buf + offset, buffer, size); std::memcpy(m_buf + offset, buffer, size);
return ResultSuccess(); return ResultSuccess();
} }
@@ -58,7 +58,7 @@ namespace ams::fs {
} }
virtual Result GetSize(s64 *out) override { virtual Result GetSize(s64 *out) override {
*out = this->size; *out = m_size;
return ResultSuccess(); return ResultSuccess();
} }

View File

@@ -28,17 +28,17 @@ namespace ams::fs {
NON_COPYABLE(ReadOnlyFile); NON_COPYABLE(ReadOnlyFile);
NON_MOVEABLE(ReadOnlyFile); NON_MOVEABLE(ReadOnlyFile);
private: private:
std::unique_ptr<fsa::IFile> base_file; std::unique_ptr<fsa::IFile> m_base_file;
public: 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() { /* ... */ } virtual ~ReadOnlyFile() { /* ... */ }
private: private:
virtual Result DoRead(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override final { 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 { virtual Result DoGetSize(s64 *out) override final {
return this->base_file->GetSize(out); return m_base_file->GetSize(out);
} }
virtual Result DoFlush() override final { virtual Result DoFlush() override final {
@@ -59,14 +59,14 @@ namespace ams::fs {
switch (op_id) { switch (op_id) {
case OperationId::Invalidate: case OperationId::Invalidate:
case OperationId::QueryRange: 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: default:
return fs::ResultUnsupportedOperationInReadOnlyFileB(); return fs::ResultUnsupportedOperationInReadOnlyFileB();
} }
} }
public: public:
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override { 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_COPYABLE(ReadOnlyFileSystemTemplate);
NON_MOVEABLE(ReadOnlyFileSystemTemplate); NON_MOVEABLE(ReadOnlyFileSystemTemplate);
private: private:
T base_fs; T m_base_fs;
public: public:
explicit ReadOnlyFileSystemTemplate(T &&fs) : base_fs(std::move(fs)) { /* ... */ } explicit ReadOnlyFileSystemTemplate(T &&fs) : m_base_fs(std::move(fs)) { /* ... */ }
virtual ~ReadOnlyFileSystemTemplate() { /* ... */ } virtual ~ReadOnlyFileSystemTemplate() { /* ... */ }
private: private:
virtual Result DoOpenFile(std::unique_ptr<fsa::IFile> *out_file, const char *path, OpenMode mode) override final { 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()); R_UNLESS((mode & fs::OpenMode_All) == fs::OpenMode_Read, fs::ResultInvalidOpenMode());
std::unique_ptr<fsa::IFile> base_file; 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)); auto read_only_file = std::make_unique<ReadOnlyFile>(std::move(base_file));
R_UNLESS(read_only_file != nullptr, fs::ResultAllocationFailureInReadOnlyFileSystemA()); 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 { 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 { 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 { virtual Result DoCommit() override final {

View File

@@ -26,30 +26,30 @@ namespace ams::fs {
class RemoteFile : public fsa::IFile, public impl::Newable { class RemoteFile : public fsa::IFile, public impl::Newable {
private: private:
::FsFile base_file; ::FsFile m_base_file;
public: 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: public:
virtual Result DoRead(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override final { 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 { 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 { 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 { 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 { 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 { 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(op_id == OperationId::QueryRange, fs::ResultUnsupportedOperationInFileServiceObjectAdapterA());
R_UNLESS(dst_size == sizeof(FileQueryRangeInfo), fs::ResultInvalidSize()); 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: public:
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override { 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 { class RemoteDirectory : public fsa::IDirectory, public impl::Newable {
private: private:
::FsDir base_dir; ::FsDir m_base_dir;
public: 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: public:
virtual Result DoRead(s64 *out_count, DirectoryEntry *out_entries, s64 max_entries) override final { 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 { virtual Result DoGetEntryCount(s64 *out) override final {
return fsDirGetEntryCount(std::addressof(this->base_dir), out); return fsDirGetEntryCount(std::addressof(m_base_dir), out);
} }
public: public:
virtual sf::cmif::DomainObjectId GetDomainObjectId() const override { 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 { class RemoteFileSystem : public fsa::IFileSystem, public impl::Newable {
private: private:
::FsFileSystem base_fs; ::FsFileSystem m_base_fs;
public: 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: private:
Result GetPathForServiceObject(fssrv::sf::Path *out_path, const char *path) { Result GetPathForServiceObject(fssrv::sf::Path *out_path, const char *path) {
/* Copy and null terminate. */ /* Copy and null terminate. */
@@ -113,31 +113,31 @@ namespace ams::fs {
virtual Result DoCreateFile(const char *path, s64 size, int flags) override final { virtual Result DoCreateFile(const char *path, s64 size, int flags) override final {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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 { virtual Result DoDeleteFile(const char *path) override final {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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 { virtual Result DoCreateDirectory(const char *path) override final {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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 { virtual Result DoDeleteDirectory(const char *path) override final {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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 { virtual Result DoDeleteDirectoryRecursively(const char *path) override final {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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 { 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; fssrv::sf::Path new_sf_path;
R_TRY(GetPathForServiceObject(std::addressof(old_sf_path), old_path)); R_TRY(GetPathForServiceObject(std::addressof(old_sf_path), old_path));
R_TRY(GetPathForServiceObject(std::addressof(new_sf_path), new_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 { 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; fssrv::sf::Path new_sf_path;
R_TRY(GetPathForServiceObject(std::addressof(old_sf_path), old_path)); R_TRY(GetPathForServiceObject(std::addressof(old_sf_path), old_path));
R_TRY(GetPathForServiceObject(std::addressof(new_sf_path), new_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 { 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)); R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
static_assert(sizeof(::FsDirEntryType) == sizeof(DirectoryEntryType)); 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 { 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)); R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
FsFile f; 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); auto file = std::make_unique<RemoteFile>(f);
R_UNLESS(file != nullptr, fs::ResultAllocationFailureInNew()); R_UNLESS(file != nullptr, fs::ResultAllocationFailureInNew());
@@ -183,7 +183,7 @@ namespace ams::fs {
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path)); R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
FsDir d; 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); auto dir = std::make_unique<RemoteDirectory>(d);
R_UNLESS(dir != nullptr, fs::ResultAllocationFailureInNew()); R_UNLESS(dir != nullptr, fs::ResultAllocationFailureInNew());
@@ -193,39 +193,39 @@ namespace ams::fs {
} }
virtual Result DoCommit() override final { 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) { virtual Result DoGetFreeSpaceSize(s64 *out, const char *path) {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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) { virtual Result DoGetTotalSpaceSize(s64 *out, const char *path) {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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) { virtual Result DoCleanDirectoryRecursively(const char *path) {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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) { virtual Result DoGetFileTimeStampRaw(FileTimeStampRaw *out, const char *path) {
fssrv::sf::Path sf_path; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path)); R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
static_assert(sizeof(FileTimeStampRaw) == sizeof(::FsTimeStampRaw)); 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) { 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; fssrv::sf::Path sf_path;
R_TRY(GetPathForServiceObject(std::addressof(sf_path), 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));
} }
}; };

View File

@@ -22,33 +22,33 @@ namespace ams::fs {
class RemoteStorage : public IStorage, public impl::Newable { class RemoteStorage : public IStorage, public impl::Newable {
private: private:
std::unique_ptr<::FsStorage, impl::Deleter> base_storage; std::unique_ptr<::FsStorage, impl::Deleter> m_base_storage;
public: public:
RemoteStorage(::FsStorage &s) { RemoteStorage(::FsStorage &s) {
this->base_storage = impl::MakeUnique<::FsStorage>(); m_base_storage = impl::MakeUnique<::FsStorage>();
*this->base_storage = s; *m_base_storage = s;
} }
virtual ~RemoteStorage() { fsStorageClose(this->base_storage.get()); } virtual ~RemoteStorage() { fsStorageClose(m_base_storage.get()); }
public: public:
virtual Result Read(s64 offset, void *buffer, size_t size) override { 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 { 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 { virtual Result Flush() override {
return fsStorageFlush(this->base_storage.get()); return fsStorageFlush(m_base_storage.get());
}; };
virtual Result GetSize(s64 *out_size) override { 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 { 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 { virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {

View File

@@ -28,14 +28,14 @@ namespace ams::fs {
public: public:
using RomFileTable = HierarchicalRomFileTable; using RomFileTable = HierarchicalRomFileTable;
private: private:
RomFileTable rom_file_table; RomFileTable m_rom_file_table;
IStorage *base_storage; IStorage *m_base_storage;
std::unique_ptr<IStorage> unique_storage; std::unique_ptr<IStorage> m_unique_storage;
std::unique_ptr<IStorage> dir_bucket_storage; std::unique_ptr<IStorage> m_dir_bucket_storage;
std::unique_ptr<IStorage> dir_entry_storage; std::unique_ptr<IStorage> m_dir_entry_storage;
std::unique_ptr<IStorage> file_bucket_storage; std::unique_ptr<IStorage> m_file_bucket_storage;
std::unique_ptr<IStorage> file_entry_storage; std::unique_ptr<IStorage> m_file_entry_storage;
s64 entry_size; s64 m_entry_size;
private: private:
Result GetFileInfo(RomFileTable::FileInfo *out, const char *path); Result GetFileInfo(RomFileTable::FileInfo *out, const char *path);
public: public:

View File

@@ -26,29 +26,29 @@ namespace ams::fs {
NON_COPYABLE(SharedFileSystemHolder); NON_COPYABLE(SharedFileSystemHolder);
NON_MOVEABLE(SharedFileSystemHolder); NON_MOVEABLE(SharedFileSystemHolder);
private: private:
std::shared_ptr<fsa::IFileSystem> fs; std::shared_ptr<fsa::IFileSystem> m_fs;
public: 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: public:
virtual Result DoCreateFile(const char *path, s64 size, int flags) override { return this->fs->CreateFile(path, size, flags); } 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 this->fs->DeleteFile(path); } virtual Result DoDeleteFile(const char *path) override { return m_fs->DeleteFile(path); }
virtual Result DoCreateDirectory(const char *path) override { return this->fs->CreateDirectory(path); } virtual Result DoCreateDirectory(const char *path) override { return m_fs->CreateDirectory(path); }
virtual Result DoDeleteDirectory(const char *path) override { return this->fs->DeleteDirectory(path); } virtual Result DoDeleteDirectory(const char *path) override { return m_fs->DeleteDirectory(path); }
virtual Result DoDeleteDirectoryRecursively(const char *path) override { return this->fs->DeleteDirectoryRecursively(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 this->fs->RenameFile(old_path, new_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 this->fs->RenameDirectory(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 this->fs->GetEntryType(out, 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 this->fs->OpenFile(out_file, path, mode); } 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 this->fs->OpenDirectory(out_dir, 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 this->fs->Commit(); } virtual Result DoCommit() override { return m_fs->Commit(); }
virtual Result DoGetFreeSpaceSize(s64 *out, const char *path) override { return this->fs->GetFreeSpaceSize(out, path); } 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 this->fs->GetTotalSpaceSize(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 this->fs->CleanDirectoryRecursively(path); } virtual Result DoCleanDirectoryRecursively(const char *path) override { return m_fs->CleanDirectoryRecursively(path); }
/* These aren't accessible as commands. */ /* These aren't accessible as commands. */
virtual Result DoCommitProvisionally(s64 counter) override { return this->fs->CommitProvisionally(counter); } virtual Result DoCommitProvisionally(s64 counter) override { return m_fs->CommitProvisionally(counter); }
virtual Result DoRollback() override { return this->fs->Rollback(); } virtual Result DoRollback() override { return m_fs->Rollback(); }
virtual Result DoFlush() override { return this->fs->Flush(); } virtual Result DoFlush() override { return m_fs->Flush(); }
}; };
} }

View File

@@ -21,51 +21,51 @@ namespace ams::fs {
class SubStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable { class SubStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
private: private:
std::shared_ptr<IStorage> shared_base_storage; std::shared_ptr<IStorage> m_shared_base_storage;
fs::IStorage *base_storage; fs::IStorage *m_base_storage;
s64 offset; s64 m_offset;
s64 size; s64 m_size;
bool resizable; bool m_resizable;
private: private:
constexpr bool IsValid() const { constexpr bool IsValid() const {
return this->base_storage != nullptr; return m_base_storage != nullptr;
} }
public: 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) { SubStorage &operator=(const SubStorage &rhs) {
if (this != std::addressof(rhs)) { if (this != std::addressof(rhs)) {
this->base_storage = rhs.base_storage; m_base_storage = rhs.m_base_storage;
this->offset = rhs.offset; m_offset = rhs.m_offset;
this->size = rhs.size; m_size = rhs.m_size;
this->resizable = rhs.resizable; m_resizable = rhs.m_resizable;
} }
return *this; 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->IsValid());
AMS_ABORT_UNLESS(this->offset >= 0); AMS_ABORT_UNLESS(m_offset >= 0);
AMS_ABORT_UNLESS(this->size >= 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->IsValid());
AMS_ABORT_UNLESS(this->offset >= 0); AMS_ABORT_UNLESS(m_offset >= 0);
AMS_ABORT_UNLESS(this->size >= 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->IsValid());
AMS_ABORT_UNLESS(this->offset >= 0); AMS_ABORT_UNLESS(m_offset >= 0);
AMS_ABORT_UNLESS(this->size >= 0); AMS_ABORT_UNLESS(m_size >= 0);
AMS_ABORT_UNLESS(sub->size >= o + sz); AMS_ABORT_UNLESS(sub->m_size >= o + sz);
} }
public: public:
void SetResizable(bool rsz) { void SetResizable(bool rsz) {
this->resizable = rsz; m_resizable = rsz;
} }
public: public:
virtual Result Read(s64 offset, void *buffer, size_t size) override { virtual Result Read(s64 offset, void *buffer, size_t size) override {
@@ -77,9 +77,9 @@ namespace ams::fs {
/* Validate arguments and read. */ /* Validate arguments and read. */
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
return this->base_storage->Read(this->offset + offset, buffer, size); return m_base_storage->Read(m_offset + offset, buffer, size);
} }
virtual Result Write(s64 offset, const void *buffer, size_t size) override{ virtual Result Write(s64 offset, const void *buffer, size_t size) override{
@@ -90,31 +90,31 @@ namespace ams::fs {
R_SUCCEED_IF(size == 0); R_SUCCEED_IF(size == 0);
/* Validate arguments and write. */ /* Validate arguments and write. */
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); R_UNLESS(IStorage::CheckAccessRange(offset, size, m_size), fs::ResultOutOfRange());
return this->base_storage->Write(this->offset + offset, buffer, size); return m_base_storage->Write(m_offset + offset, buffer, size);
} }
virtual Result Flush() override { virtual Result Flush() override {
R_UNLESS(this->IsValid(), fs::ResultNotInitialized()); R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
return this->base_storage->Flush(); return m_base_storage->Flush();
} }
virtual Result SetSize(s64 size) override { virtual Result SetSize(s64 size) override {
/* Ensure we're initialized and validate arguments. */ /* Ensure we're initialized and validate arguments. */
R_UNLESS(this->IsValid(), fs::ResultNotInitialized()); R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
R_UNLESS(this->resizable, fs::ResultUnsupportedOperationInSubStorageA()); R_UNLESS(m_resizable, fs::ResultUnsupportedOperationInSubStorageA());
R_UNLESS(IStorage::CheckOffsetAndSize(this->offset, size), fs::ResultInvalidSize()); R_UNLESS(IStorage::CheckOffsetAndSize(m_offset, size), fs::ResultInvalidSize());
/* Ensure that we're allowed to set size. */ /* Ensure that we're allowed to set size. */
s64 cur_size; s64 cur_size;
R_TRY(this->base_storage->GetSize(std::addressof(cur_size))); R_TRY(m_base_storage->GetSize(std::addressof(cur_size)));
R_UNLESS(cur_size == this->offset + this->size, fs::ResultUnsupportedOperationInSubStorageB()); R_UNLESS(cur_size == m_offset + m_size, fs::ResultUnsupportedOperationInSubStorageB());
/* Set the size. */ /* 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(); return ResultSuccess();
} }
@@ -122,7 +122,7 @@ namespace ams::fs {
/* Ensure we're initialized. */ /* Ensure we're initialized. */
R_UNLESS(this->IsValid(), fs::ResultNotInitialized()); R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
*out = this->size; *out = m_size;
return ResultSuccess(); return ResultSuccess();
} }
@@ -135,7 +135,7 @@ namespace ams::fs {
/* Validate arguments and operate. */ /* Validate arguments and operate. */
R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange()); R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange());
return this->base_storage->OperateRange(dst, dst_size, op_id, this->offset + offset, size, src, src_size); return m_base_storage->OperateRange(dst, dst_size, op_id, m_offset + offset, size, src, src_size);
} }
using IStorage::OperateRange; using IStorage::OperateRange;

View File

@@ -66,7 +66,7 @@ namespace ams::fs::impl {
class IdString { class IdString {
private: private:
char buffer[0x20]; char m_buffer[0x20];
private: private:
const char *ToValueString(int id); const char *ToValueString(int id);
public: public:

View File

@@ -23,9 +23,9 @@ namespace ams::fssrv::fscreator {
NON_COPYABLE(RomFileSystemCreator); NON_COPYABLE(RomFileSystemCreator);
NON_MOVEABLE(RomFileSystemCreator); NON_MOVEABLE(RomFileSystemCreator);
private: private:
MemoryResource *allocator; MemoryResource *m_allocator;
public: 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; virtual Result Create(std::shared_ptr<fs::fsa::IFileSystem> *out, std::shared_ptr<fs::IStorage> storage) override;
}; };

View File

@@ -30,15 +30,15 @@ namespace ams::fssrv::fscreator {
NON_COPYABLE(StorageOnNcaCreator); NON_COPYABLE(StorageOnNcaCreator);
NON_MOVEABLE(StorageOnNcaCreator); NON_MOVEABLE(StorageOnNcaCreator);
private: private:
MemoryResource *allocator; MemoryResource *m_allocator;
fssystem::IBufferManager * const buffer_manager; fssystem::IBufferManager * const m_buffer_manager;
const fssystem::NcaCryptoConfiguration &nca_crypto_cfg; const fssystem::NcaCryptoConfiguration &m_nca_crypto_cfg;
bool is_prod; bool m_is_prod;
bool is_enabled_program_verification; bool m_is_enabled_program_verification;
private: private:
Result VerifyNcaHeaderSign2(fssystem::NcaReader *nca_reader, fs::IStorage *storage); Result VerifyNcaHeaderSign2(fssystem::NcaReader *nca_reader, fs::IStorage *storage);
public: 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) {
/* ... */ /* ... */
} }

View File

@@ -22,17 +22,17 @@ namespace ams::fssrv {
class MemoryResourceFromExpHeap : public ams::MemoryResource { class MemoryResourceFromExpHeap : public ams::MemoryResource {
private: private:
lmem::HeapHandle heap_handle; lmem::HeapHandle m_heap_handle;
public: public:
constexpr explicit MemoryResourceFromExpHeap(lmem::HeapHandle handle) : heap_handle(handle) { /* ... */ } constexpr explicit MemoryResourceFromExpHeap(lmem::HeapHandle handle) : m_heap_handle(handle) { /* ... */ }
protected: protected:
virtual void *AllocateImpl(size_t size, size_t align) override { 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 { virtual void DeallocateImpl(void *p, size_t size, size_t align) override {
AMS_UNUSED(size, align); 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 { virtual bool IsEqualImpl(const MemoryResource &rhs) const override {
@@ -43,24 +43,24 @@ namespace ams::fssrv {
class PeakCheckableMemoryResourceFromExpHeap : public ams::MemoryResource { class PeakCheckableMemoryResourceFromExpHeap : public ams::MemoryResource {
private: private:
lmem::HeapHandle heap_handle; lmem::HeapHandle m_heap_handle;
os::SdkMutex mutex; os::SdkMutex m_mutex;
size_t peak_free_size; size_t m_peak_free_size;
size_t current_free_size; size_t m_current_free_size;
public: 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) { void SetHeapHandle(lmem::HeapHandle handle) {
this->heap_handle = handle; m_heap_handle = handle;
} }
size_t GetPeakFreeSize() const { return this->peak_free_size; } size_t GetPeakFreeSize() const { return m_peak_free_size; }
size_t GetCurrentFreeSize() const { return this->current_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() { 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); void OnAllocate(void *p, size_t size);

View File

@@ -27,17 +27,17 @@ namespace ams::fssrv {
class MemoryResourceFromStandardAllocator : public ams::MemoryResource { class MemoryResourceFromStandardAllocator : public ams::MemoryResource {
private: private:
mem::StandardAllocator *allocator; mem::StandardAllocator *m_allocator;
os::SdkMutex mutex; os::SdkMutex m_mutex;
size_t peak_free_size; size_t m_peak_free_size;
size_t current_free_size; size_t m_current_free_size;
size_t peak_allocated_size; size_t m_peak_allocated_size;
public: public:
explicit MemoryResourceFromStandardAllocator(mem::StandardAllocator *allocator); explicit MemoryResourceFromStandardAllocator(mem::StandardAllocator *allocator);
public: public:
size_t GetPeakFreeSize() const { return this->peak_free_size; } size_t GetPeakFreeSize() const { return m_peak_free_size; }
size_t GetCurrentFreeSize() const { return this->current_free_size; } size_t GetCurrentFreeSize() const { return m_current_free_size; }
size_t GetPeakAllocatedSize() const { return this->peak_allocated_size; } size_t GetPeakAllocatedSize() const { return m_peak_allocated_size; }
void ClearPeak(); void ClearPeak();
protected: protected:

View File

@@ -33,34 +33,34 @@ namespace ams::fssrv {
private: private:
using Buffer = std::unique_ptr<char[], fs::impl::Deleter>; using Buffer = std::unique_ptr<char[], fs::impl::Deleter>;
private: private:
Buffer buffer; Buffer m_buffer;
const char *path; const char *m_path;
Result result; Result m_result;
private: 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); 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: public:
/* TODO: Remove non-option constructor. */ /* TODO: Remove non-option constructor. */
explicit PathNormalizer(const char *p) : buffer(), path(nullptr), result(ResultSuccess()) { explicit PathNormalizer(const char *p) : m_buffer(), m_path(nullptr), m_result(ResultSuccess()) {
this->result = Normalize(std::addressof(this->path), std::addressof(this->buffer), p, false, false, false); 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') { if ((option & Option_AcceptEmpty) && p[0] == '\x00') {
this->path = path; m_path = p;
} else { } else {
const bool preserve_unc = (option & Option_PreserveUnc); const bool preserve_unc = (option & Option_PreserveUnc);
const bool preserve_tail_sep = (option & Option_PreserveTailSeparator); const bool preserve_tail_sep = (option & Option_PreserveTailSeparator);
const bool has_mount_name = (option & Option_HasMountName); 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 { Result GetResult() const {
return this->result; return m_result;
} }
const char *GetPath() const { const char *GetPath() const {
return this->path; return m_path;
} }
}; };

View File

@@ -40,9 +40,9 @@ namespace ams::fssrv::impl {
class FileInterfaceAdapter { class FileInterfaceAdapter {
NON_COPYABLE(FileInterfaceAdapter); NON_COPYABLE(FileInterfaceAdapter);
private: private:
ams::sf::SharedPointer<FileSystemInterfaceAdapter> parent_filesystem; ams::sf::SharedPointer<FileSystemInterfaceAdapter> m_parent_filesystem;
std::unique_ptr<fs::fsa::IFile> base_file; std::unique_ptr<fs::fsa::IFile> m_base_file;
util::unique_lock<fssystem::SemaphoreAdapter> open_count_semaphore; util::unique_lock<fssystem::SemaphoreAdapter> m_open_count_semaphore;
public: public:
FileInterfaceAdapter(std::unique_ptr<fs::fsa::IFile> &&file, FileSystemInterfaceAdapter *parent, util::unique_lock<fssystem::SemaphoreAdapter> &&sema); FileInterfaceAdapter(std::unique_ptr<fs::fsa::IFile> &&file, FileSystemInterfaceAdapter *parent, util::unique_lock<fssystem::SemaphoreAdapter> &&sema);
~FileInterfaceAdapter(); ~FileInterfaceAdapter();
@@ -63,9 +63,9 @@ namespace ams::fssrv::impl {
class DirectoryInterfaceAdapter { class DirectoryInterfaceAdapter {
NON_COPYABLE(DirectoryInterfaceAdapter); NON_COPYABLE(DirectoryInterfaceAdapter);
private: private:
ams::sf::SharedPointer<FileSystemInterfaceAdapter> parent_filesystem; ams::sf::SharedPointer<FileSystemInterfaceAdapter> m_parent_filesystem;
std::unique_ptr<fs::fsa::IDirectory> base_dir; std::unique_ptr<fs::fsa::IDirectory> m_base_dir;
util::unique_lock<fssystem::SemaphoreAdapter> open_count_semaphore; util::unique_lock<fssystem::SemaphoreAdapter> m_open_count_semaphore;
public: public:
DirectoryInterfaceAdapter(std::unique_ptr<fs::fsa::IDirectory> &&dir, FileSystemInterfaceAdapter *parent, util::unique_lock<fssystem::SemaphoreAdapter> &&sema); DirectoryInterfaceAdapter(std::unique_ptr<fs::fsa::IDirectory> &&dir, FileSystemInterfaceAdapter *parent, util::unique_lock<fssystem::SemaphoreAdapter> &&sema);
~DirectoryInterfaceAdapter(); ~DirectoryInterfaceAdapter();
@@ -79,11 +79,11 @@ namespace ams::fssrv::impl {
class FileSystemInterfaceAdapter : public ams::sf::ISharedObject { class FileSystemInterfaceAdapter : public ams::sf::ISharedObject {
NON_COPYABLE(FileSystemInterfaceAdapter); NON_COPYABLE(FileSystemInterfaceAdapter);
private: private:
std::shared_ptr<fs::fsa::IFileSystem> base_fs; std::shared_ptr<fs::fsa::IFileSystem> m_base_fs;
util::unique_lock<fssystem::SemaphoreAdapter> mount_count_semaphore; util::unique_lock<fssystem::SemaphoreAdapter> m_mount_count_semaphore;
os::ReaderWriterLock invalidation_lock; os::ReaderWriterLock m_invalidation_lock;
bool open_count_limited; bool m_open_count_limited;
bool deep_retry_enabled = false; bool m_deep_retry_enabled = false;
public: public:
FileSystemInterfaceAdapter(std::shared_ptr<fs::fsa::IFileSystem> &&fs, bool open_limited); FileSystemInterfaceAdapter(std::shared_ptr<fs::fsa::IFileSystem> &&fs, bool open_limited);
/* TODO: Other constructors. */ /* TODO: Other constructors. */

View File

@@ -31,11 +31,11 @@ namespace ams::fssrv::impl {
NON_COPYABLE(StorageInterfaceAdapter); NON_COPYABLE(StorageInterfaceAdapter);
private: private:
/* TODO: Nintendo uses fssystem::AsynchronousAccessStorage here. */ /* TODO: Nintendo uses fssystem::AsynchronousAccessStorage here. */
std::shared_ptr<fs::IStorage> base_storage; std::shared_ptr<fs::IStorage> m_base_storage;
util::unique_lock<fssystem::SemaphoreAdapter> open_count_semaphore; util::unique_lock<fssystem::SemaphoreAdapter> m_open_count_semaphore;
os::ReaderWriterLock invalidation_lock; os::ReaderWriterLock m_invalidation_lock;
/* TODO: DataStorageContext. */ /* TODO: DataStorageContext. */
bool deep_retry_enabled = false; bool m_deep_retry_enabled = false;
public: public:
StorageInterfaceAdapter(fs::IStorage *storage); StorageInterfaceAdapter(fs::IStorage *storage);
StorageInterfaceAdapter(std::unique_ptr<fs::IStorage> storage); StorageInterfaceAdapter(std::unique_ptr<fs::IStorage> storage);

View File

@@ -56,13 +56,13 @@ namespace ams::fssystem::buffers {
class BufferManagerContext { class BufferManagerContext {
private: private:
bool needs_blocking; bool m_needs_blocking;
public: public:
constexpr BufferManagerContext() : needs_blocking(false) { /* ... */ } constexpr BufferManagerContext() : m_needs_blocking(false) { /* ... */ }
public: 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); void RegisterBufferManagerContext(const BufferManagerContext *context);
@@ -71,19 +71,19 @@ namespace ams::fssystem::buffers {
class ScopedBufferManagerContextRegistration { class ScopedBufferManagerContextRegistration {
private: private:
BufferManagerContext cur_context; BufferManagerContext m_cur_context;
const BufferManagerContext *old_context; const BufferManagerContext *m_old_context;
public: public:
ALWAYS_INLINE explicit ScopedBufferManagerContextRegistration() { ALWAYS_INLINE explicit ScopedBufferManagerContextRegistration() {
this->old_context = GetBufferManagerContext(); m_old_context = GetBufferManagerContext();
if (this->old_context != nullptr) { if (m_old_context != nullptr) {
this->cur_context = *this->old_context; m_cur_context = *m_old_context;
} }
RegisterBufferManagerContext(std::addressof(this->cur_context)); RegisterBufferManagerContext(std::addressof(m_cur_context));
} }
ALWAYS_INLINE ~ScopedBufferManagerContextRegistration() { ALWAYS_INLINE ~ScopedBufferManagerContextRegistration() {
RegisterBufferManagerContext(this->old_context); RegisterBufferManagerContext(m_old_context);
} }
}; };

View File

@@ -37,31 +37,31 @@ namespace ams::fssystem {
NON_COPYABLE(PageList); NON_COPYABLE(PageList);
NON_MOVEABLE(PageList); NON_MOVEABLE(PageList);
private: private:
PageEntry *first_page_entry; PageEntry *m_first_page_entry;
PageEntry *last_page_entry; PageEntry *m_last_page_entry;
s32 entry_count; s32 m_entry_count;
public: 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 bool IsEmpty() const { return m_entry_count == 0; }
constexpr s32 GetSize() const { return this->entry_count; } 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: public:
PageEntry *PopFront(); PageEntry *PopFront();
void PushBack(PageEntry *page_entry); void PushBack(PageEntry *page_entry);
bool Remove(PageEntry *page_entry); bool Remove(PageEntry *page_entry);
}; };
private: private:
size_t block_size; size_t m_block_size;
s32 order_max; s32 m_order_max;
uintptr_t heap_start; uintptr_t m_heap_start;
size_t heap_size; size_t m_heap_size;
PageList *free_lists; PageList *m_free_lists;
size_t total_free_size; size_t m_total_free_size;
PageList *external_free_lists; PageList *m_external_free_lists;
std::unique_ptr<PageList[]> internal_free_lists; std::unique_ptr<PageList[]> m_internal_free_lists;
public: public:
static constexpr s32 GetBlockCountFromOrder(s32 order) { static constexpr s32 GetBlockCountFromOrder(s32 order) {
AMS_ASSERT(0 <= order); AMS_ASSERT(0 <= order);
@@ -87,7 +87,7 @@ namespace ams::fssystem {
} }
public: 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); 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); AMS_UNUSED(work_size);
const auto aligned_work = util::AlignUp(reinterpret_cast<uintptr_t>(work), alignof(PageList)); 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); return this->Initialize(address, size, block_size, order_max);
} }
@@ -118,34 +118,34 @@ namespace ams::fssystem {
void Dump() const; void Dump() const;
s32 GetOrderFromBytes(size_t size) 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)); return this->GetOrderFromBlockCount(this->GetBlockCountFromSize(size));
} }
size_t GetBytesFromOrder(s32 order) const { size_t GetBytesFromOrder(s32 order) const {
AMS_ASSERT(this->free_lists != nullptr); AMS_ASSERT(m_free_lists != nullptr);
AMS_ASSERT(0 <= order); AMS_ASSERT(0 <= order);
AMS_ASSERT(order < this->GetOrderMax()); AMS_ASSERT(order < this->GetOrderMax());
return (this->GetBlockSize() << order); return (this->GetBlockSize() << order);
} }
s32 GetOrderMax() const { s32 GetOrderMax() const {
AMS_ASSERT(this->free_lists != nullptr); AMS_ASSERT(m_free_lists != nullptr);
return this->order_max; return m_order_max;
} }
size_t GetBlockSize() const { size_t GetBlockSize() const {
AMS_ASSERT(this->free_lists != nullptr); AMS_ASSERT(m_free_lists != nullptr);
return this->block_size; return m_block_size;
} }
s32 GetPageBlockCountMax() const { s32 GetPageBlockCountMax() const {
AMS_ASSERT(this->free_lists != nullptr); AMS_ASSERT(m_free_lists != nullptr);
return 1 << this->GetOrderMax(); return 1 << this->GetOrderMax();
} }
size_t GetPageSizeMax() const { size_t GetPageSizeMax() const {
AMS_ASSERT(this->free_lists != nullptr); AMS_ASSERT(m_free_lists != nullptr);
return this->GetPageBlockCountMax() * this->GetBlockSize(); return this->GetPageBlockCountMax() * this->GetBlockSize();
} }
private: private:
@@ -163,24 +163,24 @@ namespace ams::fssystem {
uintptr_t GetAddressFromPageEntry(const PageEntry &page_entry) const { uintptr_t GetAddressFromPageEntry(const PageEntry &page_entry) const {
const uintptr_t address = reinterpret_cast<uintptr_t>(std::addressof(page_entry)); const uintptr_t address = reinterpret_cast<uintptr_t>(std::addressof(page_entry));
AMS_ASSERT(this->heap_start <= address); AMS_ASSERT(m_heap_start <= address);
AMS_ASSERT(address < this->heap_start + this->heap_size); AMS_ASSERT(address < m_heap_start + m_heap_size);
AMS_ASSERT(util::IsAligned(address - this->heap_start, this->GetBlockSize())); AMS_ASSERT(util::IsAligned(address - m_heap_start, this->GetBlockSize()));
return address; return address;
} }
PageEntry *GetPageEntryFromAddress(uintptr_t address) const { PageEntry *GetPageEntryFromAddress(uintptr_t address) const {
AMS_ASSERT(this->heap_start <= address); AMS_ASSERT(m_heap_start <= address);
AMS_ASSERT(address < this->heap_start + this->heap_size); AMS_ASSERT(address < m_heap_start + m_heap_size);
return reinterpret_cast<PageEntry *>(this->heap_start + util::AlignDown(address - this->heap_start, this->GetBlockSize())); return reinterpret_cast<PageEntry *>(m_heap_start + util::AlignDown(address - m_heap_start, this->GetBlockSize()));
} }
s32 GetIndexFromPageEntry(const PageEntry &page_entry) const { s32 GetIndexFromPageEntry(const PageEntry &page_entry) const {
const uintptr_t address = reinterpret_cast<uintptr_t>(std::addressof(page_entry)); const uintptr_t address = reinterpret_cast<uintptr_t>(std::addressof(page_entry));
AMS_ASSERT(this->heap_start <= address); AMS_ASSERT(m_heap_start <= address);
AMS_ASSERT(address < this->heap_start + this->heap_size); AMS_ASSERT(address < m_heap_start + m_heap_size);
AMS_ASSERT(util::IsAligned(address - this->heap_start, this->GetBlockSize())); AMS_ASSERT(util::IsAligned(address - m_heap_start, this->GetBlockSize()));
return static_cast<s32>((address - this->heap_start) / this->GetBlockSize()); return static_cast<s32>((address - m_heap_start) / this->GetBlockSize());
} }
bool IsAlignedToOrder(const PageEntry *page_entry, s32 order) const { bool IsAlignedToOrder(const PageEntry *page_entry, s32 order) const {

View File

@@ -34,32 +34,32 @@ namespace ams::fssystem {
private: private:
class Entry { class Entry {
private: private:
CacheHandle handle; CacheHandle m_handle;
uintptr_t address; uintptr_t m_address;
size_t size; size_t m_size;
BufferAttribute attr; BufferAttribute m_attr;
public: public:
constexpr void Initialize(CacheHandle h, uintptr_t a, size_t sz, BufferAttribute t) { constexpr void Initialize(CacheHandle h, uintptr_t a, size_t sz, BufferAttribute t) {
this->handle = h; m_handle = h;
this->address = a; m_address = a;
this->size = sz; m_size = sz;
this->attr = t; m_attr = t;
} }
constexpr CacheHandle GetHandle() const { constexpr CacheHandle GetHandle() const {
return this->handle; return m_handle;
} }
constexpr uintptr_t GetAddress() const { constexpr uintptr_t GetAddress() const {
return this->address; return m_address;
} }
constexpr size_t GetSize() const { constexpr size_t GetSize() const {
return this->size; return m_size;
} }
constexpr BufferAttribute GetBufferAttribute() const { constexpr BufferAttribute GetBufferAttribute() const {
return this->attr; return m_attr;
} }
}; };
@@ -67,41 +67,41 @@ namespace ams::fssystem {
NON_COPYABLE(AttrInfo); NON_COPYABLE(AttrInfo);
NON_MOVEABLE(AttrInfo); NON_MOVEABLE(AttrInfo);
private: private:
s32 level; s32 m_level;
s32 cache_count; s32 m_cache_count;
size_t cache_size; size_t m_cache_size;
public: 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 { constexpr s32 GetLevel() const {
return this->level; return m_level;
} }
constexpr s32 GetCacheCount() const { constexpr s32 GetCacheCount() const {
return this->cache_count; return m_cache_count;
} }
constexpr void IncrementCacheCount() { constexpr void IncrementCacheCount() {
++this->cache_count; ++m_cache_count;
} }
constexpr void DecrementCacheCount() { constexpr void DecrementCacheCount() {
--this->cache_count; --m_cache_count;
} }
constexpr size_t GetCacheSize() const { constexpr size_t GetCacheSize() const {
return this->cache_size; return m_cache_size;
} }
constexpr void AddCacheSize(size_t diff) { constexpr void AddCacheSize(size_t diff) {
this->cache_size += diff; m_cache_size += diff;
} }
constexpr void SubtractCacheSize(size_t diff) { constexpr void SubtractCacheSize(size_t diff) {
AMS_ASSERT(this->cache_size >= diff); AMS_ASSERT(m_cache_size >= diff);
this->cache_size -= diff; m_cache_size -= diff;
} }
using Newable::operator new; using Newable::operator new;
@@ -114,19 +114,19 @@ namespace ams::fssystem {
using AttrListTraits = util::IntrusiveListBaseTraits<AttrInfo>; using AttrListTraits = util::IntrusiveListBaseTraits<AttrInfo>;
using AttrList = typename AttrListTraits::ListType; using AttrList = typename AttrListTraits::ListType;
private: private:
std::unique_ptr<char[], ::ams::fs::impl::Deleter> internal_entry_buffer; std::unique_ptr<char[], ::ams::fs::impl::Deleter> m_internal_entry_buffer;
char *external_entry_buffer; char *m_external_entry_buffer;
size_t entry_buffer_size; size_t m_entry_buffer_size;
Entry *entries; Entry *m_entries;
s32 entry_count; s32 m_entry_count;
s32 entry_count_max; s32 m_entry_count_max;
AttrList attr_list; AttrList m_attr_list;
char *external_attr_info_buffer; char *m_external_attr_info_buffer;
s32 external_attr_info_count; s32 m_external_attr_info_count;
s32 cache_count_min; s32 m_cache_count_min;
size_t cache_size_min; size_t m_cache_size_min;
size_t total_cache_size; size_t m_total_cache_size;
CacheHandle current_handle; CacheHandle m_current_handle;
public: public:
static constexpr size_t QueryWorkBufferSize(s32 max_cache_count) { static constexpr size_t QueryWorkBufferSize(s32 max_cache_count) {
AMS_ASSERT(max_cache_count > 0); 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); return util::AlignUp(entry_size + attr_list_size + alignof(Entry) + alignof(AttrInfo), 8);
} }
public: 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);
Result Initialize(s32 max_cache_count, void *work, size_t work_size) { 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)); const auto aligned_entry_buf = util::AlignUp(reinterpret_cast<uintptr_t>(work), alignof(Entry));
this->external_entry_buffer = reinterpret_cast<char *>(aligned_entry_buf); m_external_entry_buffer = reinterpret_cast<char *>(aligned_entry_buf);
this->entry_buffer_size = sizeof(Entry) * max_cache_count; 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; const auto work_end = reinterpret_cast<uintptr_t>(work) + work_size;
this->external_attr_info_buffer = reinterpret_cast<char *>(aligned_attr_info_buf); m_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_count = static_cast<s32>((work_end - aligned_attr_info_buf) / sizeof(AttrInfo));
return ResultSuccess(); return ResultSuccess();
} }
@@ -179,22 +179,22 @@ namespace ams::fssystem {
s32 GetCacheCountMin(const BufferAttribute &attr) { s32 GetCacheCountMin(const BufferAttribute &attr) {
AMS_UNUSED(attr); AMS_UNUSED(attr);
return this->cache_count_min; return m_cache_count_min;
} }
size_t GetCacheSizeMin(const BufferAttribute &attr) { size_t GetCacheSizeMin(const BufferAttribute &attr) {
AMS_UNUSED(attr); AMS_UNUSED(attr);
return this->cache_size_min; return m_cache_size_min;
} }
}; };
private: private:
BuddyHeap buddy_heap; BuddyHeap m_buddy_heap;
CacheHandleTable cache_handle_table; CacheHandleTable m_cache_handle_table;
size_t total_size; size_t m_total_size;
size_t peak_free_size; size_t m_peak_free_size;
size_t peak_total_allocatable_size; size_t m_peak_total_allocatable_size;
size_t retried_count; size_t m_retried_count;
mutable os::SdkRecursiveMutex mutex; mutable os::SdkRecursiveMutex m_mutex;
public: public:
static constexpr size_t QueryWorkBufferSize(s32 max_cache_count, s32 max_order) { static constexpr size_t QueryWorkBufferSize(s32 max_cache_count, s32 max_order) {
const auto buddy_size = FileSystemBuddyHeap::QueryWorkBufferSize(max_order); const auto buddy_size = FileSystemBuddyHeap::QueryWorkBufferSize(max_order);
@@ -202,30 +202,30 @@ namespace ams::fssystem {
return buddy_size + table_size; return buddy_size + table_size;
} }
public: 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() { /* ... */ } virtual ~FileSystemBufferManager() { /* ... */ }
Result Initialize(s32 max_cache_count, uintptr_t address, size_t buffer_size, size_t block_size) { Result Initialize(s32 max_cache_count, uintptr_t address, size_t buffer_size, size_t block_size) {
AMS_ASSERT(buffer_size > 0); AMS_ASSERT(buffer_size > 0);
R_TRY(this->cache_handle_table.Initialize(max_cache_count)); R_TRY(m_cache_handle_table.Initialize(max_cache_count));
R_TRY(this->buddy_heap.Initialize(address, buffer_size, block_size)); R_TRY(m_buddy_heap.Initialize(address, buffer_size, block_size));
this->total_size = this->buddy_heap.GetTotalFreeSize(); m_total_size = m_buddy_heap.GetTotalFreeSize();
this->peak_free_size = this->total_size; m_peak_free_size = m_total_size;
this->peak_total_allocatable_size = this->total_size; m_peak_total_allocatable_size = m_total_size;
return ResultSuccess(); return ResultSuccess();
} }
Result Initialize(s32 max_cache_count, uintptr_t address, size_t buffer_size, size_t block_size, s32 max_order) { 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); AMS_ASSERT(buffer_size > 0);
R_TRY(this->cache_handle_table.Initialize(max_cache_count)); R_TRY(m_cache_handle_table.Initialize(max_cache_count));
R_TRY(this->buddy_heap.Initialize(address, buffer_size, block_size, max_order)); R_TRY(m_buddy_heap.Initialize(address, buffer_size, block_size, max_order));
this->total_size = this->buddy_heap.GetTotalFreeSize(); m_total_size = m_buddy_heap.GetTotalFreeSize();
this->peak_free_size = this->total_size; m_peak_free_size = m_total_size;
this->peak_total_allocatable_size = this->total_size; m_peak_total_allocatable_size = m_total_size;
return ResultSuccess(); return ResultSuccess();
} }
@@ -237,12 +237,12 @@ namespace ams::fssystem {
const auto table_buffer = static_cast<char *>(work); const auto table_buffer = static_cast<char *>(work);
const auto buddy_buffer = table_buffer + table_size; const auto buddy_buffer = table_buffer + table_size;
R_TRY(this->cache_handle_table.Initialize(max_cache_count, table_buffer, table_size)); R_TRY(m_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_buddy_heap.Initialize(address, buffer_size, block_size, buddy_buffer, buddy_size));
this->total_size = this->buddy_heap.GetTotalFreeSize(); m_total_size = m_buddy_heap.GetTotalFreeSize();
this->peak_free_size = this->total_size; m_peak_free_size = m_total_size;
this->peak_total_allocatable_size = this->total_size; m_peak_total_allocatable_size = m_total_size;
return ResultSuccess(); return ResultSuccess();
} }
@@ -254,19 +254,19 @@ namespace ams::fssystem {
const auto table_buffer = static_cast<char *>(work); const auto table_buffer = static_cast<char *>(work);
const auto buddy_buffer = table_buffer + table_size; const auto buddy_buffer = table_buffer + table_size;
R_TRY(this->cache_handle_table.Initialize(max_cache_count, table_buffer, table_size)); R_TRY(m_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_buddy_heap.Initialize(address, buffer_size, block_size, max_order, buddy_buffer, buddy_size));
this->total_size = this->buddy_heap.GetTotalFreeSize(); m_total_size = m_buddy_heap.GetTotalFreeSize();
this->peak_free_size = this->total_size; m_peak_free_size = m_total_size;
this->peak_total_allocatable_size = this->total_size; m_peak_total_allocatable_size = m_total_size;
return ResultSuccess(); return ResultSuccess();
} }
void Finalize() { void Finalize() {
this->buddy_heap.Finalize(); m_buddy_heap.Finalize();
this->cache_handle_table.Finalize(); m_cache_handle_table.Finalize();
} }
private: private:
virtual const std::pair<uintptr_t, size_t> AllocateBufferImpl(size_t size, const BufferAttribute &attr) override; virtual const std::pair<uintptr_t, size_t> AllocateBufferImpl(size_t size, const BufferAttribute &attr) override;

View File

@@ -22,12 +22,12 @@ namespace ams::fssystem {
public: public:
class BufferAttribute { class BufferAttribute {
private: private:
s32 level; s32 m_level;
public: public:
constexpr BufferAttribute() : level(0) { /* ... */ } constexpr BufferAttribute() : m_level(0) { /* ... */ }
constexpr explicit BufferAttribute(s32 l) : level(l) { /* ... */ } 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; using CacheHandle = s64;

View File

@@ -74,27 +74,27 @@ namespace ams::fssystem {
static Result CreateExternalDecryptor(std::unique_ptr<IDecryptor> *out, DecryptFunction func, s32 key_index); static Result CreateExternalDecryptor(std::unique_ptr<IDecryptor> *out, DecryptFunction func, s32 key_index);
static Result CreateSoftwareDecryptor(std::unique_ptr<IDecryptor> *out); static Result CreateSoftwareDecryptor(std::unique_ptr<IDecryptor> *out);
private: private:
BucketTree table; BucketTree m_table;
fs::SubStorage data_storage; fs::SubStorage m_data_storage;
u8 key[KeySize]; u8 m_key[KeySize];
u32 secure_value; u32 m_secure_value;
s64 counter_offset; s64 m_counter_offset;
std::unique_ptr<IDecryptor> decryptor; std::unique_ptr<IDecryptor> m_decryptor;
public: 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(); } 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); 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(); 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 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 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 { virtual Result GetSize(s64 *out) override {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
*out = this->table.GetSize(); *out = m_table.GetSize();
return ResultSuccess(); return ResultSuccess();
} }

View File

@@ -28,9 +28,9 @@ namespace ams::fssystem {
static constexpr size_t KeySize = crypto::Aes128CtrEncryptor::KeySize; static constexpr size_t KeySize = crypto::Aes128CtrEncryptor::KeySize;
static constexpr size_t IvSize = crypto::Aes128CtrEncryptor::IvSize; static constexpr size_t IvSize = crypto::Aes128CtrEncryptor::IvSize;
private: private:
IStorage * const base_storage; IStorage * const m_base_storage;
char key[KeySize]; char m_key[KeySize];
char iv[IvSize]; char m_iv[IvSize];
public: public:
static void MakeIv(void *dst, size_t dst_size, u64 upper, s64 offset); static void MakeIv(void *dst, size_t dst_size, u64 upper, s64 offset);
public: public:

View File

@@ -29,11 +29,11 @@ namespace ams::fssystem {
static constexpr size_t KeySize = crypto::Aes128XtsEncryptor::KeySize; static constexpr size_t KeySize = crypto::Aes128XtsEncryptor::KeySize;
static constexpr size_t IvSize = crypto::Aes128XtsEncryptor::IvSize; static constexpr size_t IvSize = crypto::Aes128XtsEncryptor::IvSize;
private: private:
IStorage * const base_storage; IStorage * const m_base_storage;
char key[2][KeySize]; char m_key[2][KeySize];
char iv[IvSize]; char m_iv[IvSize];
const size_t block_size; const size_t m_block_size;
os::SdkMutex mutex; os::SdkMutex m_mutex;
public: 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); AesXtsStorage(IStorage *base, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, size_t block_size);

View File

@@ -35,16 +35,16 @@ namespace ams::fssystem {
static_assert(util::IsPowerOfTwo(DataAlign)); static_assert(util::IsPowerOfTwo(DataAlign));
static_assert(util::IsPowerOfTwo(BufferAlign)); static_assert(util::IsPowerOfTwo(BufferAlign));
private: private:
std::shared_ptr<fs::IStorage> shared_base_storage; std::shared_ptr<fs::IStorage> m_shared_base_storage;
fs::IStorage * const base_storage; fs::IStorage * const m_base_storage;
s64 base_storage_size; s64 m_base_storage_size;
bool is_base_storage_size_dirty; bool m_is_base_storage_size_dirty;
public: 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_TRY(this->GetSize(std::addressof(bs_size)));
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
return AlignmentMatchingStorageImpl::Read(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<char *>(buffer), size); return AlignmentMatchingStorageImpl::Read(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 { 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_TRY(this->GetSize(std::addressof(bs_size)));
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
return AlignmentMatchingStorageImpl::Write(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<const char *>(buffer), size); return AlignmentMatchingStorageImpl::Write(m_base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast<const char *>(buffer), size);
} }
virtual Result Flush() override { virtual Result Flush() override {
return this->base_storage->Flush(); return m_base_storage->Flush();
} }
virtual Result SetSize(s64 size) override { virtual Result SetSize(s64 size) override {
ON_SCOPE_EXIT { this->is_base_storage_size_dirty = true; }; ON_SCOPE_EXIT { m_is_base_storage_size_dirty = true; };
return this->base_storage->SetSize(util::AlignUp(size, DataAlign)); return m_base_storage->SetSize(util::AlignUp(size, DataAlign));
} }
virtual Result GetSize(s64 *out) override { virtual Result GetSize(s64 *out) override {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
if (this->is_base_storage_size_dirty) { if (m_is_base_storage_size_dirty) {
s64 size; 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;
this->is_base_storage_size_dirty = false; m_is_base_storage_size_dirty = false;
} }
*out = this->base_storage_size; *out = m_base_storage_size;
return ResultSuccess(); return ResultSuccess();
} }
@@ -123,7 +123,7 @@ namespace ams::fssystem {
const auto aligned_offset_end = util::AlignUp(offset + valid_size, DataAlign); const auto aligned_offset_end = util::AlignUp(offset + valid_size, DataAlign);
const auto aligned_size = aligned_offset_end - aligned_offset; 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)); static_assert(util::IsPowerOfTwo(BufferAlign));
private: private:
fs::IStorage * const base_storage; fs::IStorage * const m_base_storage;
s64 base_storage_size; s64 m_base_storage_size;
size_t data_align; size_t m_data_align;
bool is_base_storage_size_dirty; bool m_is_base_storage_size_dirty;
public: 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)); AMS_ASSERT(util::IsPowerOfTwo(da));
} }
@@ -158,9 +158,9 @@ namespace ams::fssystem {
/* Allocate a pooled buffer. */ /* Allocate a pooled buffer. */
PooledBuffer 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 { virtual Result Write(s64 offset, const void *buffer, size_t size) override {
@@ -176,32 +176,32 @@ namespace ams::fssystem {
/* Allocate a pooled buffer. */ /* Allocate a pooled buffer. */
PooledBuffer 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 { virtual Result Flush() override {
return this->base_storage->Flush(); return m_base_storage->Flush();
} }
virtual Result SetSize(s64 size) override { virtual Result SetSize(s64 size) override {
ON_SCOPE_EXIT { this->is_base_storage_size_dirty = true; }; ON_SCOPE_EXIT { m_is_base_storage_size_dirty = true; };
return this->base_storage->SetSize(util::AlignUp(size, this->data_align)); return m_base_storage->SetSize(util::AlignUp(size, m_data_align));
} }
virtual Result GetSize(s64 *out) override { virtual Result GetSize(s64 *out) override {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
if (this->is_base_storage_size_dirty) { if (m_is_base_storage_size_dirty) {
s64 size; 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;
this->is_base_storage_size_dirty = false; m_is_base_storage_size_dirty = false;
} }
*out = this->base_storage_size; *out = m_base_storage_size;
return ResultSuccess(); return ResultSuccess();
} }
@@ -216,11 +216,11 @@ namespace ams::fssystem {
/* Operate on the base storage. */ /* Operate on the base storage. */
const auto valid_size = std::min(size, bs_size - offset); const auto valid_size = std::min(size, bs_size - offset);
const auto aligned_offset = util::AlignDown(offset, this->data_align); const auto aligned_offset = util::AlignDown(offset, m_data_align);
const auto aligned_offset_end = util::AlignUp(offset + valid_size, this->data_align); const auto aligned_offset_end = util::AlignUp(offset + valid_size, m_data_align);
const auto aligned_size = aligned_offset_end - aligned_offset; 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)); static_assert(util::IsPowerOfTwo(BufferAlign));
private: private:
std::shared_ptr<fs::IStorage> shared_base_storage; std::shared_ptr<fs::IStorage> m_shared_base_storage;
fs::IStorage * const base_storage; fs::IStorage * const m_base_storage;
s64 base_storage_size; s64 m_base_storage_size;
size_t data_align; size_t m_data_align;
public: public:
explicit AlignmentMatchingStorageInBulkRead(fs::IStorage *bs, size_t da) : shared_base_storage(), base_storage(bs), base_storage_size(-1), data_align(da) { 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(this->data_align)); 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)); AMS_ASSERT(util::IsPowerOfTwo(da));
} }
@@ -260,30 +260,30 @@ namespace ams::fssystem {
R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange());
/* Allocate a pooled buffer. */ /* Allocate a pooled buffer. */
PooledBuffer pooled_buffer(this->data_align, this->data_align); PooledBuffer pooled_buffer(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 { virtual Result Flush() override {
return this->base_storage->Flush(); return m_base_storage->Flush();
} }
virtual Result SetSize(s64 size) override { virtual Result SetSize(s64 size) override {
ON_SCOPE_EXIT { this->base_storage_size = -1; }; ON_SCOPE_EXIT { m_base_storage_size = -1; };
return this->base_storage->SetSize(util::AlignUp(size, this->data_align)); return m_base_storage->SetSize(util::AlignUp(size, m_data_align));
} }
virtual Result GetSize(s64 *out) override { virtual Result GetSize(s64 *out) override {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
if (this->base_storage_size < 0) { if (m_base_storage_size < 0) {
s64 size; 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(); return ResultSuccess();
} }
@@ -298,11 +298,11 @@ namespace ams::fssystem {
/* Operate on the base storage. */ /* Operate on the base storage. */
const auto valid_size = std::min(size, bs_size - offset); const auto valid_size = std::min(size, bs_size - offset);
const auto aligned_offset = util::AlignDown(offset, this->data_align); const auto aligned_offset = util::AlignDown(offset, m_data_align);
const auto aligned_offset_end = util::AlignUp(offset + valid_size, this->data_align); const auto aligned_offset_end = util::AlignUp(offset + valid_size, m_data_align);
const auto aligned_size = aligned_offset_end - aligned_offset; 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);
} }
}; };

View File

@@ -55,24 +55,24 @@ namespace ams::fssystem {
class ContinuousReadingInfo { class ContinuousReadingInfo {
private: private:
size_t read_size; size_t m_read_size;
s32 skip_count; s32 m_skip_count;
bool done; bool m_done;
public: 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 void SetSkipCount(s32 count) { AMS_ASSERT(count >= 0); m_skip_count = count; }
constexpr s32 GetSkipCount() const { return this->skip_count; } constexpr s32 GetSkipCount() const { return m_skip_count; }
constexpr bool CheckNeedScan() { return (--this->skip_count) <= 0; } constexpr bool CheckNeedScan() { return (--m_skip_count) <= 0; }
constexpr void Done() { this->read_size = 0; this->done = true; } constexpr void Done() { m_read_size = 0; m_done = true; }
constexpr bool IsDone() const { return this->done; } constexpr bool IsDone() const { return m_done; }
constexpr void SetReadSize(size_t size) { this->read_size = size; } constexpr void SetReadSize(size_t size) { m_read_size = size; }
constexpr size_t GetReadSize() const { return this->read_size; } constexpr size_t GetReadSize() const { return m_read_size; }
constexpr bool CanDo() const { return this->read_size > 0; } constexpr bool CanDo() const { return m_read_size > 0; }
}; };
using IAllocator = MemoryResource; using IAllocator = MemoryResource;
@@ -80,60 +80,60 @@ namespace ams::fssystem {
class NodeBuffer { class NodeBuffer {
NON_COPYABLE(NodeBuffer); NON_COPYABLE(NodeBuffer);
private: private:
IAllocator *allocator; IAllocator *m_allocator;
void *header; void *m_header;
public: public:
NodeBuffer() : allocator(), header() { /* ... */ } NodeBuffer() : m_allocator(), m_header() { /* ... */ }
~NodeBuffer() { ~NodeBuffer() {
AMS_ASSERT(this->header == nullptr); AMS_ASSERT(m_header == nullptr);
} }
NodeBuffer(NodeBuffer &&rhs) : allocator(rhs.allocator), header(rhs.allocator) { NodeBuffer(NodeBuffer &&rhs) : m_allocator(rhs.m_allocator), m_header(rhs.m_allocator) {
rhs.allocator = nullptr; rhs.m_allocator = nullptr;
rhs.header = nullptr; rhs.m_header = nullptr;
} }
NodeBuffer &operator=(NodeBuffer &&rhs) { NodeBuffer &operator=(NodeBuffer &&rhs) {
if (this != std::addressof(rhs)) { if (this != std::addressof(rhs)) {
AMS_ASSERT(this->header == nullptr); AMS_ASSERT(m_header == nullptr);
this->allocator = rhs.allocator; m_allocator = rhs.m_allocator;
this->header = rhs.header; m_header = rhs.m_header;
rhs.allocator = nullptr; rhs.m_allocator = nullptr;
rhs.header = nullptr; rhs.m_header = nullptr;
} }
return *this; return *this;
} }
bool Allocate(IAllocator *allocator, size_t node_size) { bool Allocate(IAllocator *allocator, size_t node_size) {
AMS_ASSERT(this->header == nullptr); AMS_ASSERT(m_header == nullptr);
this->allocator = allocator; m_allocator = allocator;
this->header = allocator->Allocate(node_size, sizeof(s64)); 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) { void Free(size_t node_size) {
if (this->header) { if (m_header) {
this->allocator->Deallocate(this->header, node_size); m_allocator->Deallocate(m_header, node_size);
this->header = nullptr; m_header = nullptr;
} }
this->allocator = nullptr; m_allocator = nullptr;
} }
void FillZero(size_t node_size) const { void FillZero(size_t node_size) const {
if (this->header) { if (m_header) {
std::memset(this->header, 0, node_size); std::memset(m_header, 0, node_size);
} }
} }
NodeHeader *Get() const { NodeHeader *Get() const {
return reinterpret_cast<NodeHeader *>(this->header); return reinterpret_cast<NodeHeader *>(m_header);
} }
NodeHeader *operator->() const { return this->Get(); } NodeHeader *operator->() const { return this->Get(); }
@@ -142,11 +142,11 @@ namespace ams::fssystem {
T *Get() const { T *Get() const {
static_assert(util::is_pod<T>::value); static_assert(util::is_pod<T>::value);
static_assert(sizeof(T) == sizeof(NodeHeader)); static_assert(sizeof(T) == sizeof(NodeHeader));
return reinterpret_cast<T *>(this->header); return reinterpret_cast<T *>(m_header);
} }
IAllocator *GetAllocator() const { IAllocator *GetAllocator() const {
return this->allocator; return m_allocator;
} }
}; };
private: private:
@@ -205,43 +205,43 @@ namespace ams::fssystem {
return GetEntrySetCount(node_size, entry_size, entry_count) * static_cast<s64>(node_size); return GetEntrySetCount(node_size, entry_size, entry_count) * static_cast<s64>(node_size);
} }
private: private:
mutable fs::SubStorage node_storage; mutable fs::SubStorage m_node_storage;
mutable fs::SubStorage entry_storage; mutable fs::SubStorage m_entry_storage;
NodeBuffer node_l1; NodeBuffer m_node_l1;
size_t node_size; size_t m_node_size;
size_t entry_size; size_t m_entry_size;
s32 entry_count; s32 m_entry_count;
s32 offset_count; s32 m_offset_count;
s32 entry_set_count; s32 m_entry_set_count;
s64 start_offset; s64 m_start_offset;
s64 end_offset; s64 m_end_offset;
public: 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(); } ~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); 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 Initialize(size_t node_size, s64 end_offset);
void Finalize(); void Finalize();
bool IsInitialized() const { return this->node_size > 0; } bool IsInitialized() const { return m_node_size > 0; }
bool IsEmpty() const { return this->entry_size == 0; } bool IsEmpty() const { return m_entry_size == 0; }
Result Find(Visitor *visitor, s64 virtual_address) const; Result Find(Visitor *visitor, s64 virtual_address) const;
Result InvalidateCache(); Result InvalidateCache();
s32 GetEntryCount() const { return this->entry_count; } s32 GetEntryCount() const { return m_entry_count; }
IAllocator *GetAllocator() const { return this->node_l1.GetAllocator(); } IAllocator *GetAllocator() const { return m_node_l1.GetAllocator(); }
s64 GetStart() const { return this->start_offset; } s64 GetStart() const { return m_start_offset; }
s64 GetEnd() const { return this->end_offset; } s64 GetEnd() const { return m_end_offset; }
s64 GetSize() const { return this->end_offset - this->start_offset; } s64 GetSize() const { return m_end_offset - m_start_offset; }
bool Includes(s64 offset) const { 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 { 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: private:
template<typename EntryType> template<typename EntryType>
@@ -256,11 +256,11 @@ namespace ams::fssystem {
template<typename EntryType> template<typename EntryType>
Result ScanContinuousReading(ContinuousReadingInfo *out_info, const ContinuousReadingParam<EntryType> &param) const; Result ScanContinuousReading(ContinuousReadingInfo *out_info, const ContinuousReadingParam<EntryType> &param) const;
bool IsExistL2() const { return this->offset_count < this->entry_set_count; } bool IsExistL2() const { return m_offset_count < m_entry_set_count; }
bool IsExistOffsetL2OnL1() const { return this->IsExistL2() && this->node_l1->count < this->offset_count; } bool IsExistOffsetL2OnL1() const { return this->IsExistL2() && m_node_l1->count < m_offset_count; }
s64 GetEntrySetIndex(s32 node_index, s32 offset_index) const { 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); static_assert(util::is_pod<EntrySetHeader>::value);
private: private:
const BucketTree *tree; const BucketTree *m_tree;
void *entry; void *m_entry;
s32 entry_index; s32 m_entry_index;
s32 entry_set_count; s32 m_entry_set_count;
EntrySetHeader entry_set; EntrySetHeader m_entry_set;
public: 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() { ~Visitor() {
if (this->entry != nullptr) { if (m_entry != nullptr) {
this->tree->GetAllocator()->Deallocate(this->entry, this->tree->entry_size); m_tree->GetAllocator()->Deallocate(m_entry, m_tree->m_entry_size);
this->tree = nullptr; m_tree = nullptr;
this->entry = nullptr; m_entry = nullptr;
} }
} }
bool IsValid() const { return this->entry_index >= 0; } bool IsValid() const { return m_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 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() && (this->entry_index > 0 || this->entry_set.info.index > 0); } bool CanMovePrevious() const { return this->IsValid() && (m_entry_index > 0 || m_entry_set.info.index > 0); }
Result MoveNext(); Result MoveNext();
Result MovePrevious(); Result MovePrevious();
@@ -307,12 +307,12 @@ namespace ams::fssystem {
template<typename EntryType> template<typename EntryType>
Result ScanContinuousReading(ContinuousReadingInfo *out_info, s64 offset, size_t size) const; 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> 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: private:
Result Initialize(const BucketTree *tree); Result Initialize(const BucketTree *tree);

View File

@@ -27,7 +27,7 @@ namespace ams::fssystem {
/* Validate our preconditions. */ /* Validate our preconditions. */
AMS_ASSERT(this->IsInitialized()); AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(out_info != nullptr); AMS_ASSERT(out_info != nullptr);
AMS_ASSERT(this->entry_size == sizeof(EntryType)); AMS_ASSERT(m_entry_size == sizeof(EntryType));
/* Reset the output. */ /* Reset the output. */
out_info->Reset(); out_info->Reset();
@@ -44,14 +44,14 @@ namespace ams::fssystem {
R_UNLESS(entry.GetVirtualOffset() <= cur_offset, fs::ResultOutOfRange()); R_UNLESS(entry.GetVirtualOffset() <= cur_offset, fs::ResultOutOfRange());
/* Create a pooled buffer for our scan. */ /* Create a pooled buffer for our scan. */
PooledBuffer pool(this->node_size, 1); PooledBuffer pool(m_node_size, 1);
char *buffer = nullptr; char *buffer = nullptr;
/* Read the node. */ /* Read the node. */
if (this->node_size <= pool.GetSize()) { if (m_node_size <= pool.GetSize()) {
buffer = pool.GetBuffer(); buffer = pool.GetBuffer();
const auto ofs = param.entry_set.index * static_cast<s64>(this->node_size); const auto ofs = param.entry_set.index * static_cast<s64>(m_node_size);
R_TRY(this->entry_storage.Read(ofs, buffer, this->node_size)); R_TRY(m_entry_storage.Read(ofs, buffer, m_node_size));
} }
/* Calculate extents. */ /* Calculate extents. */
@@ -81,11 +81,11 @@ namespace ams::fssystem {
if (entry_index + 1 < entry_count) { if (entry_index + 1 < entry_count) {
if (buffer != nullptr) { if (buffer != nullptr) {
const auto ofs = impl::GetBucketTreeEntryOffset(0, this->entry_size, entry_index + 1); const auto ofs = impl::GetBucketTreeEntryOffset(0, m_entry_size, entry_index + 1);
std::memcpy(std::addressof(next_entry), buffer + ofs, this->entry_size); std::memcpy(std::addressof(next_entry), buffer + ofs, m_entry_size);
} else { } else {
const auto ofs = impl::GetBucketTreeEntryOffset(param.entry_set.index, this->node_size, this->entry_size, entry_index + 1); const auto ofs = impl::GetBucketTreeEntryOffset(param.entry_set.index, m_node_size, m_entry_size, entry_index + 1);
R_TRY(this->entry_storage.Read(ofs, std::addressof(next_entry), this->entry_size)); R_TRY(m_entry_storage.Read(ofs, std::addressof(next_entry), m_entry_size));
} }
next_entry_offset = next_entry.GetVirtualOffset(); next_entry_offset = next_entry.GetVirtualOffset();
@@ -154,12 +154,12 @@ namespace ams::fssystem {
/* Create our parameters. */ /* Create our parameters. */
ContinuousReadingParam<EntryType> param = { 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. */ /* Scan. */
return this->tree->ScanContinuousReading<EntryType>(out_info, param); return m_tree->ScanContinuousReading<EntryType>(out_info, param);
} }
} }

View File

@@ -24,10 +24,10 @@ namespace ams::fssystem {
using PathResolutionFileSystem = impl::IPathResolutionFileSystem<DirectoryRedirectionFileSystem>; using PathResolutionFileSystem = impl::IPathResolutionFileSystem<DirectoryRedirectionFileSystem>;
friend class impl::IPathResolutionFileSystem<DirectoryRedirectionFileSystem>; friend class impl::IPathResolutionFileSystem<DirectoryRedirectionFileSystem>;
private: private:
char *before_dir; char *m_before_dir;
size_t before_dir_len; size_t m_before_dir_len;
char *after_dir; char *m_after_dir;
size_t after_dir_len; size_t m_after_dir_len;
public: public:
DirectoryRedirectionFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs, const char *before, const char *after, bool unc = false); 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); DirectoryRedirectionFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, const char *before, const char *after, bool unc = false);

View File

@@ -24,8 +24,8 @@ namespace ams::fssystem {
using PathResolutionFileSystem = impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>; using PathResolutionFileSystem = impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>;
friend class impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>; friend class impl::IPathResolutionFileSystem<DirectorySaveDataFileSystem>;
private: private:
os::SdkMutex accessor_mutex; os::SdkMutex m_accessor_mutex;
s32 open_writable_files; s32 m_open_writable_files;
public: public:
DirectorySaveDataFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs); DirectorySaveDataFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs);
DirectorySaveDataFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs); DirectorySaveDataFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs);
@@ -35,7 +35,7 @@ namespace ams::fssystem {
protected: protected:
inline util::optional<std::scoped_lock<os::SdkMutex>> GetAccessorLock() { inline util::optional<std::scoped_lock<os::SdkMutex>> GetAccessorLock() {
/* We have a real accessor lock that we want to use. */ /* 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: private:
Result AllocateWorkBuffer(std::unique_ptr<u8[]> *out, size_t *out_size, size_t ideal_size); Result AllocateWorkBuffer(std::unique_ptr<u8[]> *out, size_t *out_size, size_t ideal_size);

View File

@@ -100,30 +100,30 @@ namespace ams::fssystem {
return BucketTree::QueryEntryStorageSize(NodeSize, sizeof(Entry), entry_count); return BucketTree::QueryEntryStorageSize(NodeSize, sizeof(Entry), entry_count);
} }
private: private:
BucketTree table; BucketTree m_table;
fs::SubStorage data_storage[StorageCount]; fs::SubStorage m_data_storage[StorageCount];
public: public:
IndirectStorage() : table(), data_storage() { /* ... */ } IndirectStorage() : m_table(), m_data_storage() { /* ... */ }
virtual ~IndirectStorage() { this->Finalize(); } virtual ~IndirectStorage() { this->Finalize(); }
Result Initialize(IAllocator *allocator, fs::SubStorage table_storage); Result Initialize(IAllocator *allocator, fs::SubStorage table_storage);
void Finalize(); 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) { 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) { void SetStorage(s32 idx, fs::SubStorage storage) {
AMS_ASSERT(0 <= idx && idx < StorageCount); AMS_ASSERT(0 <= idx && idx < StorageCount);
this->data_storage[idx] = storage; m_data_storage[idx] = storage;
} }
template<typename T> template<typename T>
void SetStorage(s32 idx, T storage, s64 offset, s64 size) { void SetStorage(s32 idx, T storage, s64 offset, s64 size) {
AMS_ASSERT(0 <= idx && idx < StorageCount); 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); 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 { virtual Result GetSize(s64 *out) override {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
*out = this->table.GetEnd(); *out = m_table.GetEnd();
return ResultSuccess(); return ResultSuccess();
} }
@@ -151,11 +151,11 @@ namespace ams::fssystem {
return fs::ResultUnsupportedOperationInIndirectStorageB(); return fs::ResultUnsupportedOperationInIndirectStorageB();
} }
protected: protected:
BucketTree &GetEntryTable() { return this->table; } BucketTree &GetEntryTable() { return m_table; }
fs::SubStorage &GetDataStorage(s32 index) { fs::SubStorage &GetDataStorage(s32 index) {
AMS_ASSERT(0 <= index && index < StorageCount); AMS_ASSERT(0 <= index && index < StorageCount);
return this->data_storage[index]; return m_data_storage[index];
} }
template<bool ContinuousCheck, typename F> template<bool ContinuousCheck, typename F>

View File

@@ -29,14 +29,14 @@ namespace ams::fssystem {
R_SUCCEED_IF(size == 0); R_SUCCEED_IF(size == 0);
/* Validate arguments. */ /* 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. */ /* Find the offset in our tree. */
BucketTree::Visitor visitor; 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(); 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. */ /* Prepare to operate in chunks. */
@@ -69,7 +69,7 @@ namespace ams::fssystem {
/* Get the current data storage's size. */ /* Get the current data storage's size. */
s64 cur_data_storage_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. */ /* Ensure that we remain within range. */
const auto data_offset = cur_offset - cur_entry_offset; 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()); R_UNLESS(cur_entry_phys_offset + data_offset + cur_size <= cur_data_storage_size, fs::ResultInvalidIndirectStorageSize());
/* Operate. */ /* 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. */ /* Mark as done. */
cr_info.Done(); cr_info.Done();
@@ -91,9 +91,9 @@ namespace ams::fssystem {
if (visitor.CanMoveNext()) { if (visitor.CanMoveNext()) {
R_TRY(visitor.MoveNext()); R_TRY(visitor.MoveNext());
next_entry_offset = visitor.Get<Entry>()->GetVirtualOffset(); 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 { } else {
next_entry_offset = this->table.GetEnd(); next_entry_offset = m_table.GetEnd();
} }
R_UNLESS(cur_offset < next_entry_offset, fs::ResultInvalidIndirectEntryOffset()); R_UNLESS(cur_offset < next_entry_offset, fs::ResultInvalidIndirectEntryOffset());
@@ -118,14 +118,14 @@ namespace ams::fssystem {
if (needs_operate) { if (needs_operate) {
/* Get the current data storage's size. */ /* Get the current data storage's size. */
s64 cur_data_storage_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. */ /* Ensure that we remain within range. */
const auto cur_entry_phys_offset = cur_entry.GetPhysicalOffset(); 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(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_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; cur_offset += cur_size;

View File

@@ -28,46 +28,46 @@ namespace ams::fssystem {
class IntegrityRomFsStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable { class IntegrityRomFsStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
private: private:
save::HierarchicalIntegrityVerificationStorage integrity_storage; save::HierarchicalIntegrityVerificationStorage m_integrity_storage;
save::FileSystemBufferManagerSet buffers; save::FileSystemBufferManagerSet m_buffers;
os::SdkRecursiveMutex mutex; os::SdkRecursiveMutex m_mutex;
Hash master_hash; Hash m_master_hash;
std::unique_ptr<fs::MemoryStorage> master_hash_storage; std::unique_ptr<fs::MemoryStorage> m_master_hash_storage;
public: public:
IntegrityRomFsStorage() : mutex() { /* ... */ } IntegrityRomFsStorage() : m_mutex() { /* ... */ }
virtual ~IntegrityRomFsStorage() override { this->Finalize(); } virtual ~IntegrityRomFsStorage() override { this->Finalize(); }
Result Initialize(save::HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, save::HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, IBufferManager *bm); Result Initialize(save::HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, save::HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, IBufferManager *bm);
void Finalize(); void Finalize();
virtual Result Read(s64 offset, void *buffer, size_t size) override { 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 { 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 SetSize(s64 size) override { AMS_UNUSED(size); return fs::ResultUnsupportedOperationInIntegrityRomFsStorageA(); }
virtual Result GetSize(s64 *out) override { virtual Result GetSize(s64 *out) override {
return this->integrity_storage.GetSize(out); return m_integrity_storage.GetSize(out);
} }
virtual Result Flush() override { 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 { 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() { Result Commit() {
return this->integrity_storage.Commit(); return m_integrity_storage.Commit();
} }
save::FileSystemBufferManagerSet *GetBuffers() { save::FileSystemBufferManagerSet *GetBuffers() {
return this->integrity_storage.GetBuffers(); return m_integrity_storage.GetBuffers();
} }
}; };

View File

@@ -85,16 +85,16 @@ namespace ams::fssystem {
NON_COPYABLE(NcaReader); NON_COPYABLE(NcaReader);
NON_MOVEABLE(NcaReader); NON_MOVEABLE(NcaReader);
private: private:
NcaHeader header; NcaHeader m_header;
u8 decryption_keys[NcaHeader::DecryptionKey_Count][NcaCryptoConfiguration::Aes128KeySize]; u8 m_decryption_keys[NcaHeader::DecryptionKey_Count][NcaCryptoConfiguration::Aes128KeySize];
std::shared_ptr<fs::IStorage> shared_base_storage; std::shared_ptr<fs::IStorage> m_shared_base_storage;
std::unique_ptr<fs::IStorage> header_storage; std::unique_ptr<fs::IStorage> m_header_storage;
fs::IStorage *body_storage; fs::IStorage *m_body_storage;
u8 external_decryption_key[NcaCryptoConfiguration::Aes128KeySize]; u8 m_external_decryption_key[NcaCryptoConfiguration::Aes128KeySize];
DecryptAesCtrFunction decrypt_aes_ctr; DecryptAesCtrFunction m_decrypt_aes_ctr;
DecryptAesCtrFunction decrypt_aes_ctr_external; DecryptAesCtrFunction m_decrypt_aes_ctr_external;
bool is_software_aes_prioritized; bool m_is_software_aes_prioritized;
NcaHeader::EncryptionType header_encryption_type; NcaHeader::EncryptionType m_header_encryption_type;
public: public:
NcaReader(); NcaReader();
~NcaReader(); ~NcaReader();
@@ -143,18 +143,18 @@ namespace ams::fssystem {
NON_COPYABLE(NcaFsHeaderReader); NON_COPYABLE(NcaFsHeaderReader);
NON_MOVEABLE(NcaFsHeaderReader); NON_MOVEABLE(NcaFsHeaderReader);
private: private:
NcaFsHeader data; NcaFsHeader m_data;
s32 fs_index; s32 m_fs_index;
public: public:
NcaFsHeaderReader() : fs_index(-1) { NcaFsHeaderReader() : m_fs_index(-1) {
std::memset(std::addressof(this->data), 0, sizeof(this->data)); std::memset(std::addressof(m_data), 0, sizeof(m_data));
} }
Result Initialize(const NcaReader &reader, s32 index); 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; } NcaFsHeader &GetData() { return m_data; }
const NcaFsHeader &GetData() const { return this->data; } const NcaFsHeader &GetData() const { return m_data; }
void GetRawData(void *dst, size_t dst_size) const; void GetRawData(void *dst, size_t dst_size) const;
NcaFsHeader::HashData &GetHashData(); NcaFsHeader::HashData &GetHashData();
@@ -179,19 +179,19 @@ namespace ams::fssystem {
class StorageOption; class StorageOption;
class StorageOptionWithHeaderReader; class StorageOptionWithHeaderReader;
private: private:
std::shared_ptr<NcaReader> original_reader; std::shared_ptr<NcaReader> m_original_reader;
std::shared_ptr<NcaReader> reader; std::shared_ptr<NcaReader> m_reader;
MemoryResource * const allocator; MemoryResource * const m_allocator;
fssystem::IBufferManager * const buffer_manager; fssystem::IBufferManager * const m_buffer_manager;
public: public:
static Result SetupFsHeaderReader(NcaFsHeaderReader *out, const NcaReader &reader, s32 fs_index); static Result SetupFsHeaderReader(NcaFsHeaderReader *out, const NcaReader &reader, s32 fs_index);
public: public:
NcaFileSystemDriver(std::shared_ptr<NcaReader> reader, MemoryResource *allocator, IBufferManager *buffer_manager) : original_reader(), reader(reader), allocator(allocator), buffer_manager(buffer_manager) { 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(this->reader != nullptr); 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) { 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(this->reader != nullptr); AMS_ASSERT(m_reader != nullptr);
} }
Result OpenRawStorage(std::shared_ptr<fs::IStorage> *out, s32 fs_index); Result OpenRawStorage(std::shared_ptr<fs::IStorage> *out, s32 fs_index);

View File

@@ -24,126 +24,126 @@ namespace ams::fssystem {
private: private:
friend class NcaFileSystemDriver; friend class NcaFileSystemDriver;
private: private:
const s32 fs_index; const s32 m_fs_index;
NcaFsHeaderReader * const header_reader; NcaFsHeaderReader * const m_header_reader;
fs::IStorage *data_storage; fs::IStorage *m_data_storage;
s64 data_storage_size; s64 m_data_storage_size;
fs::IStorage *aes_ctr_ex_table_storage; fs::IStorage *m_aes_ctr_ex_table_storage;
AesCtrCounterExtendedStorage *aes_ctr_ex_storage_raw; AesCtrCounterExtendedStorage *m_aes_ctr_ex_storage_raw;
fs::IStorage *aes_ctr_ex_storage; fs::IStorage *m_aes_ctr_ex_storage;
IndirectStorage *indirect_storage; IndirectStorage *m_indirect_storage;
SparseStorage *sparse_storage; SparseStorage *m_sparse_storage;
public: 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() { 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(this->header_reader != nullptr); 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() { 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(this->header_reader != nullptr); AMS_ASSERT(m_header_reader != nullptr);
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax); AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
} }
s32 GetFsIndex() const { return this->fs_index; } s32 GetFsIndex() const { return m_fs_index; }
NcaFsHeaderReader &GetHeaderReader() { return *this->header_reader; } NcaFsHeaderReader &GetHeaderReader() { return *m_header_reader; }
const NcaFsHeaderReader &GetHeaderReader() const { return *this->header_reader; } const NcaFsHeaderReader &GetHeaderReader() const { return *m_header_reader; }
fs::SubStorage GetDataStorage() const { return fs::SubStorage(this->data_storage, 0, this->data_storage_size); } fs::SubStorage GetDataStorage() const { return fs::SubStorage(m_data_storage, 0, m_data_storage_size); }
fs::IStorage *GetAesCtrExTableStorage() const { return this->aes_ctr_ex_table_storage; } fs::IStorage *GetAesCtrExTableStorage() const { return m_aes_ctr_ex_table_storage; }
fs::IStorage *GetAesCtrExStorage() const { return this->aes_ctr_ex_storage; } fs::IStorage *GetAesCtrExStorage() const { return m_aes_ctr_ex_storage; }
AesCtrCounterExtendedStorage *GetAesCtrExStorageRaw() const { return this->aes_ctr_ex_storage_raw; } AesCtrCounterExtendedStorage *GetAesCtrExStorageRaw() const { return m_aes_ctr_ex_storage_raw; }
IndirectStorage *GetIndirectStorage() const { return this->indirect_storage; } IndirectStorage *GetIndirectStorage() const { return m_indirect_storage; }
SparseStorage *GetSparseStorage() const { return this->sparse_storage; } SparseStorage *GetSparseStorage() const { return m_sparse_storage; }
private: private:
void SetDataStorage(fs::IStorage *storage, s64 size) { void SetDataStorage(fs::IStorage *storage, s64 size) {
AMS_ASSERT(storage != nullptr); AMS_ASSERT(storage != nullptr);
AMS_ASSERT(size >= 0); AMS_ASSERT(size >= 0);
this->data_storage = storage; m_data_storage = storage;
this->data_storage_size = size; m_data_storage_size = size;
} }
void SetAesCtrExTableStorage(fs::IStorage *storage) { AMS_ASSERT(storage != nullptr); this->aes_ctr_ex_table_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); this->aes_ctr_ex_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); this->aes_ctr_ex_storage_raw = storage; } void SetAesCtrExStorageRaw(AesCtrCounterExtendedStorage *storage) { AMS_ASSERT(storage != nullptr); m_aes_ctr_ex_storage_raw = storage; }
void SetIndirectStorage(IndirectStorage *storage) { AMS_ASSERT(storage != nullptr); this->indirect_storage = storage; } void SetIndirectStorage(IndirectStorage *storage) { AMS_ASSERT(storage != nullptr); m_indirect_storage = storage; }
void SetSparseStorage(SparseStorage *storage) { AMS_ASSERT(storage != nullptr); this->sparse_storage = storage; } void SetSparseStorage(SparseStorage *storage) { AMS_ASSERT(storage != nullptr); m_sparse_storage = storage; }
}; };
class NcaFileSystemDriver::StorageOptionWithHeaderReader : public NcaFileSystemDriver::StorageOption { class NcaFileSystemDriver::StorageOptionWithHeaderReader : public NcaFileSystemDriver::StorageOption {
private: private:
NcaFsHeaderReader header_reader_data; NcaFsHeaderReader m_header_reader_data;
public: 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 { class NcaFileSystemDriver::BaseStorage {
private: private:
std::unique_ptr<fs::IStorage> storage; std::unique_ptr<fs::IStorage> m_storage;
fs::SubStorage sub_storage; fs::SubStorage m_sub_storage;
s64 storage_offset; s64 m_storage_offset;
NcaAesCtrUpperIv aes_ctr_upper_iv; NcaAesCtrUpperIv m_aes_ctr_upper_iv;
public: public:
BaseStorage() : storage(), sub_storage(), storage_offset(0) { BaseStorage() : m_storage(), m_sub_storage(), m_storage_offset(0) {
this->aes_ctr_upper_iv.value = 0; m_aes_ctr_upper_iv.value = 0;
} }
explicit BaseStorage(const fs::SubStorage &ss) : storage(), sub_storage(ss), storage_offset(0) { explicit BaseStorage(const fs::SubStorage &ss) : m_storage(), m_sub_storage(ss), m_storage_offset(0) {
this->aes_ctr_upper_iv.value = 0; m_aes_ctr_upper_iv.value = 0;
} }
template<typename T> template<typename T>
BaseStorage(T s, s64 offset, s64 size) : storage(), sub_storage(s, offset, size), storage_offset(0) { BaseStorage(T s, s64 offset, s64 size) : m_storage(), m_sub_storage(s, offset, size), m_storage_offset(0) {
this->aes_ctr_upper_iv.value = 0; m_aes_ctr_upper_iv.value = 0;
} }
void SetStorage(std::unique_ptr<fs::IStorage> &&storage) { void SetStorage(std::unique_ptr<fs::IStorage> &&storage) {
this->storage = std::move(storage); m_storage = std::move(storage);
} }
template<typename T> template<typename T>
void SetStorage(T storage, s64 offset, s64 size) { 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() { std::unique_ptr<fs::IStorage> MakeStorage() {
if (this->storage != nullptr) { if (m_storage != nullptr) {
return std::move(this->storage); 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() { 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) { Result GetSubStorage(fs::SubStorage *out, s64 offset, s64 size) {
s64 storage_size = 0; s64 storage_size = 0;
if (this->storage != nullptr) { if (m_storage != nullptr) {
R_TRY(this->storage->GetSize(std::addressof(storage_size))); R_TRY(m_storage->GetSize(std::addressof(storage_size)));
R_UNLESS(offset + size <= storage_size, fs::ResultNcaBaseStorageOutOfRangeA()); 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 { } 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()); 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(); return ResultSuccess();
} }
void SetStorageOffset(s64 offset) { void SetStorageOffset(s64 offset) {
this->storage_offset = offset; m_storage_offset = offset;
} }
s64 GetStorageOffset() const { s64 GetStorageOffset() const {
return this->storage_offset; return m_storage_offset;
} }
void SetAesCtrUpperIv(NcaAesCtrUpperIv v) { void SetAesCtrUpperIv(NcaAesCtrUpperIv v) {
this->aes_ctr_upper_iv = v; m_aes_ctr_upper_iv = v;
} }
const NcaAesCtrUpperIv GetAesCtrUpperIv() const { const NcaAesCtrUpperIv GetAesCtrUpperIv() const {
return this->aes_ctr_upper_iv; return m_aes_ctr_upper_iv;
} }
}; };

View File

@@ -29,12 +29,12 @@ namespace ams::fssystem {
class PartitionFile; class PartitionFile;
class PartitionDirectory; class PartitionDirectory;
private: private:
fs::IStorage *base_storage; fs::IStorage *m_base_storage;
MetaType *meta_data; MetaType *m_meta_data;
bool initialized; bool m_initialized;
size_t meta_data_size; size_t m_meta_data_size;
std::unique_ptr<MetaType> unique_meta_data; std::unique_ptr<MetaType> m_unique_meta_data;
std::shared_ptr<fs::IStorage> shared_storage; std::shared_ptr<fs::IStorage> m_shared_storage;
private: private:
Result Initialize(fs::IStorage *base_storage, MemoryResource *allocator); Result Initialize(fs::IStorage *base_storage, MemoryResource *allocator);
public: public:

View File

@@ -76,15 +76,15 @@ namespace ams::fssystem {
using PartitionEntry = typename Format::PartitionEntry; using PartitionEntry = typename Format::PartitionEntry;
protected: protected:
bool initialized; bool m_initialized;
PartitionFileSystemHeader *header; PartitionFileSystemHeader *m_header;
PartitionEntry *entries; PartitionEntry *m_entries;
char *name_table; char *m_name_table;
size_t meta_data_size; size_t m_meta_data_size;
MemoryResource *allocator; MemoryResource *m_allocator;
char *buffer; char *m_buffer;
public: public:
PartitionFileSystemMetaCore() : initialized(false), allocator(nullptr), buffer(nullptr) { /* ... */ } PartitionFileSystemMetaCore() : m_initialized(false), m_allocator(nullptr), m_buffer(nullptr) { /* ... */ }
~PartitionFileSystemMetaCore(); ~PartitionFileSystemMetaCore();
Result Initialize(fs::IStorage *storage, MemoryResource *allocator); Result Initialize(fs::IStorage *storage, MemoryResource *allocator);

View File

@@ -25,8 +25,8 @@ namespace ams::fssystem {
class PooledBuffer { class PooledBuffer {
NON_COPYABLE(PooledBuffer); NON_COPYABLE(PooledBuffer);
private: private:
char *buffer; char *m_buffer;
size_t size; size_t m_size;
private: private:
static size_t GetAllocatableSizeMaxCore(bool large); static size_t GetAllocatableSizeMaxCore(bool large);
public: public:
@@ -34,14 +34,14 @@ namespace ams::fssystem {
static size_t GetAllocatableParticularlyLargeSizeMax() { return GetAllocatableSizeMaxCore(true); } static size_t GetAllocatableParticularlyLargeSizeMax() { return GetAllocatableSizeMaxCore(true); }
private: private:
void Swap(PooledBuffer &rhs) { void Swap(PooledBuffer &rhs) {
std::swap(this->buffer, rhs.buffer); std::swap(m_buffer, rhs.m_buffer);
std::swap(this->size, rhs.size); std::swap(m_size, rhs.m_size);
} }
public: public:
/* Constructor/Destructor. */ /* 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); this->Allocate(ideal_size, required_size);
} }
@@ -50,9 +50,9 @@ namespace ams::fssystem {
} }
/* Move and assignment. */ /* Move and assignment. */
explicit PooledBuffer(PooledBuffer &&rhs) : buffer(rhs.buffer), size(rhs.size) { explicit PooledBuffer(PooledBuffer &&rhs) : m_buffer(rhs.m_buffer), m_size(rhs.m_size) {
rhs.buffer = nullptr; rhs.m_buffer = nullptr;
rhs.size = 0; rhs.m_size = 0;
} }
PooledBuffer &operator=(PooledBuffer &&rhs) { PooledBuffer &operator=(PooledBuffer &&rhs) {
@@ -74,17 +74,17 @@ namespace ams::fssystem {
void Deallocate() { void Deallocate() {
/* Shrink the buffer to empty. */ /* Shrink the buffer to empty. */
this->Shrink(0); this->Shrink(0);
AMS_ASSERT(this->buffer == nullptr); AMS_ASSERT(m_buffer == nullptr);
} }
char *GetBuffer() const { char *GetBuffer() const {
AMS_ASSERT(this->buffer != nullptr); AMS_ASSERT(m_buffer != nullptr);
return this->buffer; return m_buffer;
} }
size_t GetSize() const { size_t GetSize() const {
AMS_ASSERT(this->buffer != nullptr); AMS_ASSERT(m_buffer != nullptr);
return this->size; return m_size;
} }
private: private:
void AllocateCore(size_t ideal_size, size_t required_size, bool large); void AllocateCore(size_t ideal_size, size_t required_size, bool large);

View File

@@ -27,14 +27,14 @@ namespace ams::fssystem {
public: public:
using RomFileTable = fs::HierarchicalRomFileTable; using RomFileTable = fs::HierarchicalRomFileTable;
private: private:
RomFileTable rom_file_table; RomFileTable m_rom_file_table;
fs::IStorage *base_storage; fs::IStorage *m_base_storage;
std::shared_ptr<fs::IStorage> shared_storage; std::shared_ptr<fs::IStorage> m_shared_storage;
std::unique_ptr<fs::IStorage> dir_bucket_storage; std::unique_ptr<fs::IStorage> m_dir_bucket_storage;
std::unique_ptr<fs::IStorage> dir_entry_storage; std::unique_ptr<fs::IStorage> m_dir_entry_storage;
std::unique_ptr<fs::IStorage> file_bucket_storage; std::unique_ptr<fs::IStorage> m_file_bucket_storage;
std::unique_ptr<fs::IStorage> file_entry_storage; std::unique_ptr<fs::IStorage> m_file_entry_storage;
s64 entry_size; s64 m_entry_size;
private: private:
Result GetFileInfo(RomFileTable::FileInfo *out, const char *path); Result GetFileInfo(RomFileTable::FileInfo *out, const char *path);
public: public:

View File

@@ -65,9 +65,9 @@ namespace ams::fssystem {
} }
}; };
private: private:
ZeroStorage zero_storage; ZeroStorage m_zero_storage;
public: public:
SparseStorage() : IndirectStorage(), zero_storage() { /* ... */ } SparseStorage() : IndirectStorage(), m_zero_storage() { /* ... */ }
virtual ~SparseStorage() { /* ... */ } virtual ~SparseStorage() { /* ... */ }
using IndirectStorage::Initialize; using IndirectStorage::Initialize;
@@ -95,7 +95,7 @@ namespace ams::fssystem {
virtual Result Read(s64 offset, void *buffer, size_t size) override; virtual Result Read(s64 offset, void *buffer, size_t size) override;
private: private:
void SetZeroStorage() { 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());
} }
}; };

View File

@@ -24,8 +24,8 @@ namespace ams::fssystem {
using PathResolutionFileSystem = impl::IPathResolutionFileSystem<SubDirectoryFileSystem>; using PathResolutionFileSystem = impl::IPathResolutionFileSystem<SubDirectoryFileSystem>;
friend class impl::IPathResolutionFileSystem<SubDirectoryFileSystem>; friend class impl::IPathResolutionFileSystem<SubDirectoryFileSystem>;
private: private:
char *base_path; char *m_base_path;
size_t base_path_len; size_t m_base_path_len;
public: public:
SubDirectoryFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs, const char *bp, bool unc = false); 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); SubDirectoryFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, const char *bp, bool unc = false);

View File

@@ -48,9 +48,9 @@ namespace ams::fssystem {
private: private:
static s32 GetThreadPriorityByAccessPriority(AccessMode mode); static s32 GetThreadPriorityByAccessPriority(AccessMode mode);
private: private:
ScopedThreadPriorityChanger scoped_changer; ScopedThreadPriorityChanger m_scoped_changer;
public: 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) {
/* ... */ /* ... */
} }
}; };

View File

@@ -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) { 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. */ /* Open the directory. */
std::unique_ptr<fs::fsa::IDirectory> dir; 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); const size_t parent_len = strnlen(work_path, work_path_size - 1);
@@ -37,7 +37,7 @@ namespace ams::fssystem {
while (true) { while (true) {
/* Read a single entry. */ /* Read a single entry. */
s64 read_count = 0; 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 we're out of entries, we're done. */
if (read_count == 0) { 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) { 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 = {}; fs::DirectoryEntry dir_entry = {};
char work_path[fs::EntryNameLengthMax + 1] = {}; 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> template<typename OnEnterDir, typename OnExitDir, typename OnFile>

View File

@@ -26,24 +26,24 @@ namespace ams::fssystem::impl {
class IPathResolutionFileSystem : public fs::fsa::IFileSystem, public fs::impl::Newable { class IPathResolutionFileSystem : public fs::fsa::IFileSystem, public fs::impl::Newable {
NON_COPYABLE(IPathResolutionFileSystem); NON_COPYABLE(IPathResolutionFileSystem);
private: private:
std::shared_ptr<fs::fsa::IFileSystem> shared_fs; std::shared_ptr<fs::fsa::IFileSystem> m_shared_fs;
std::unique_ptr<fs::fsa::IFileSystem> unique_fs; std::unique_ptr<fs::fsa::IFileSystem> m_unique_fs;
bool unc_preserved; bool m_unc_preserved;
protected: protected:
fs::fsa::IFileSystem * const base_fs; fs::fsa::IFileSystem * const m_base_fs;
public: 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() { /* ... */ } virtual ~IPathResolutionFileSystem() { /* ... */ }
protected: protected:
constexpr inline bool IsUncPreserved() const { constexpr inline bool IsUncPreserved() const {
return this->unc_preserved; return m_unc_preserved;
} }
public: public:
virtual Result DoCreateFile(const char *path, s64 size, int option) override { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); 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(); 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 { 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)); 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(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { virtual Result DoCommit() override {
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { 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)); R_TRY(static_cast<Impl*>(this)->ResolveFullPath(full_path, sizeof(full_path), path));
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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. */ /* These aren't accessible as commands. */
virtual Result DoCommitProvisionally(s64 counter) override { virtual Result DoCommitProvisionally(s64 counter) override {
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); 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 { virtual Result DoRollback() override {
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
return this->base_fs->Rollback(); return m_base_fs->Rollback();
} }
virtual Result DoFlush() override { virtual Result DoFlush() override {
util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock(); util::optional optional_lock = static_cast<Impl*>(this)->GetAccessorLock();
return this->base_fs->Flush(); return m_base_fs->Flush();
} }
}; };

View File

@@ -61,19 +61,19 @@ namespace ams::fssystem::save {
Flag_RealData = (1 << 10), Flag_RealData = (1 << 10),
}; };
private: private:
IBufferManager *buffer_manager; IBufferManager *m_buffer_manager;
os::SdkRecursiveMutex *mutex; os::SdkRecursiveMutex *m_mutex;
std::unique_ptr<CacheEntry[], ::ams::fs::impl::Deleter> entries; std::unique_ptr<CacheEntry[], ::ams::fs::impl::Deleter> m_entries;
IStorage *data_storage; IStorage *m_data_storage;
Result last_result; Result m_last_result;
s64 data_size; s64 m_data_size;
size_t verification_block_size; size_t m_verification_block_size;
size_t verification_block_shift; size_t m_verification_block_shift;
CacheIndex invalidate_index; CacheIndex m_invalidate_index;
s32 max_cache_entry_count; s32 m_max_cache_entry_count;
s32 flags; s32 m_flags;
s32 buffer_level; s32 m_buffer_level;
fs::StorageType storage_type; fs::StorageType m_storage_type;
public: public:
BlockCacheBufferedStorage(); BlockCacheBufferedStorage();
virtual ~BlockCacheBufferedStorage() override; virtual ~BlockCacheBufferedStorage() override;
@@ -96,31 +96,31 @@ namespace ams::fssystem::save {
Result OnRollback(); Result OnRollback();
bool IsEnabledKeepBurstMode() const { bool IsEnabledKeepBurstMode() const {
return (this->flags & Flag_KeepBurstMode) != 0; return (m_flags & Flag_KeepBurstMode) != 0;
} }
bool IsRealDataCache() const { bool IsRealDataCache() const {
return (this->flags & Flag_RealData) != 0; return (m_flags & Flag_RealData) != 0;
} }
void SetKeepBurstMode(bool en) { void SetKeepBurstMode(bool en) {
if (en) { if (en) {
this->flags |= Flag_KeepBurstMode; m_flags |= Flag_KeepBurstMode;
} else { } else {
this->flags &= ~Flag_KeepBurstMode; m_flags &= ~Flag_KeepBurstMode;
} }
} }
void SetRealDataCache(bool en) { void SetRealDataCache(bool en) {
if (en) { if (en) {
this->flags |= Flag_RealData; m_flags |= Flag_RealData;
} else { } else {
this->flags &= ~Flag_RealData; m_flags &= ~Flag_RealData;
} }
} }
private: private:
s32 GetMaxCacheEntryCount() const { s32 GetMaxCacheEntryCount() const {
return this->max_cache_entry_count; return m_max_cache_entry_count;
} }
Result ClearImpl(s64 offset, s64 size); Result ClearImpl(s64 offset, s64 size);

View File

@@ -30,16 +30,16 @@ namespace ams::fssystem::save {
class UniqueCache; class UniqueCache;
class SharedCache; class SharedCache;
private: private:
fs::SubStorage base_storage; fs::SubStorage m_base_storage;
IBufferManager *buffer_manager; IBufferManager *m_buffer_manager;
size_t block_size; size_t m_block_size;
s64 base_storage_size; s64 m_base_storage_size;
std::unique_ptr<Cache[]> caches; std::unique_ptr<Cache[]> m_caches;
s32 cache_count; s32 m_cache_count;
Cache *next_acquire_cache; Cache *m_next_acquire_cache;
Cache *next_fetch_cache; Cache *m_next_fetch_cache;
os::SdkMutex mutex; os::SdkMutex m_mutex;
bool bulk_read_enabled; bool m_bulk_read_enabled;
public: public:
BufferedStorage(); BufferedStorage();
virtual ~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); Result Initialize(fs::SubStorage base_storage, IBufferManager *buffer_manager, size_t block_size, s32 buffer_count);
void Finalize(); 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 Read(s64 offset, void *buffer, size_t size) override;
virtual Result Write(s64 offset, const 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(); 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: private:
Result PrepareAllocation(); Result PrepareAllocation();
Result ControlDirtiness(); Result ControlDirtiness();

View File

@@ -82,8 +82,8 @@ namespace ams::fssystem::save {
}; };
static_assert(util::is_pod<InputParam>::value); static_assert(util::is_pod<InputParam>::value);
private: private:
fs::SubStorage storage; fs::SubStorage m_storage;
HierarchicalIntegrityVerificationMetaInformation meta; HierarchicalIntegrityVerificationMetaInformation m_meta;
public: public:
static Result QuerySize(HierarchicalIntegrityVerificationSizeSet *out, const InputParam &input_param, s32 layer_count, s64 data_size); static Result QuerySize(HierarchicalIntegrityVerificationSizeSet *out, const InputParam &input_param, s32 layer_count, s64 data_size);
/* TODO Format */ /* TODO Format */
@@ -94,10 +94,10 @@ namespace ams::fssystem::save {
Result Initialize(fs::SubStorage meta_storage); Result Initialize(fs::SubStorage meta_storage);
void Finalize(); void Finalize();
u32 GetMasterHashSize() const { return this->meta.master_hash_size; } u32 GetMasterHashSize() const { return m_meta.master_hash_size; }
void GetLevelHashInfo(HierarchicalIntegrityVerificationInformation *out) { void GetLevelHashInfo(HierarchicalIntegrityVerificationInformation *out) {
AMS_ASSERT(out != nullptr); 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, DataStorage = 6,
}; };
private: private:
fs::SubStorage storages[DataStorage + 1]; fs::SubStorage m_storages[DataStorage + 1];
public: public:
void SetMasterHashStorage(fs::SubStorage s) { this->storages[MasterStorage] = s; } void SetMasterHashStorage(fs::SubStorage s) { m_storages[MasterStorage] = s; }
void SetLayer1HashStorage(fs::SubStorage s) { this->storages[Layer1Storage] = s; } void SetLayer1HashStorage(fs::SubStorage s) { m_storages[Layer1Storage] = s; }
void SetLayer2HashStorage(fs::SubStorage s) { this->storages[Layer2Storage] = s; } void SetLayer2HashStorage(fs::SubStorage s) { m_storages[Layer2Storage] = s; }
void SetLayer3HashStorage(fs::SubStorage s) { this->storages[Layer3Storage] = s; } void SetLayer3HashStorage(fs::SubStorage s) { m_storages[Layer3Storage] = s; }
void SetLayer4HashStorage(fs::SubStorage s) { this->storages[Layer4Storage] = s; } void SetLayer4HashStorage(fs::SubStorage s) { m_storages[Layer4Storage] = s; }
void SetLayer5HashStorage(fs::SubStorage s) { this->storages[Layer5Storage] = s; } void SetLayer5HashStorage(fs::SubStorage s) { m_storages[Layer5Storage] = s; }
void SetDataStorage(fs::SubStorage s) { this->storages[DataStorage] = s; } void SetDataStorage(fs::SubStorage s) { m_storages[DataStorage] = s; }
fs::SubStorage &operator[](s32 index) { fs::SubStorage &operator[](s32 index) {
AMS_ASSERT(MasterStorage <= index && index <= DataStorage); AMS_ASSERT(MasterStorage <= index && index <= DataStorage);
return this->storages[index]; return m_storages[index];
} }
}; };
private: private:
@@ -146,15 +146,15 @@ namespace ams::fssystem::save {
s_generate_random = func; s_generate_random = func;
} }
private: private:
FileSystemBufferManagerSet *buffers; FileSystemBufferManagerSet *m_buffers;
os::SdkRecursiveMutex *mutex; os::SdkRecursiveMutex *m_mutex;
IntegrityVerificationStorage verify_storages[MaxLayers - 1]; IntegrityVerificationStorage m_verify_storages[MaxLayers - 1];
BlockCacheBufferedStorage buffer_storages[MaxLayers - 1]; BlockCacheBufferedStorage m_buffer_storages[MaxLayers - 1];
s64 data_size; s64 m_data_size;
s32 max_layers; s32 m_max_layers;
bool is_written_for_rollback; bool m_is_written_for_rollback;
public: 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(); } virtual ~HierarchicalIntegrityVerificationStorage() override { this->Finalize(); }
Result Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::SdkRecursiveMutex *mtx, fs::StorageType storage_type); 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(); Result OnRollback();
bool IsInitialized() const { bool IsInitialized() const {
return this->data_size >= 0; return m_data_size >= 0;
} }
bool IsWrittenForRollback() const { bool IsWrittenForRollback() const {
return this->is_written_for_rollback; return m_is_written_for_rollback;
} }
FileSystemBufferManagerSet *GetBuffers() { FileSystemBufferManagerSet *GetBuffers() {
return this->buffers; return m_buffers;
} }
void GetParameters(HierarchicalIntegrityVerificationStorageControlArea::InputParam *out) const { void GetParameters(HierarchicalIntegrityVerificationStorageControlArea::InputParam *out) const {
AMS_ASSERT(out != nullptr); AMS_ASSERT(out != nullptr);
for (auto level = 0; level <= this->max_layers - 2; ++level) { for (auto level = 0; level <= m_max_layers - 2; ++level) {
out->level_block_size[level] = static_cast<size_t>(this->verify_storages[level].GetBlockSize()); out->level_block_size[level] = static_cast<size_t>(m_verify_storages[level].GetBlockSize());
} }
} }
s64 GetL1HashVerificationBlockSize() const { s64 GetL1HashVerificationBlockSize() const {
return this->verify_storages[this->max_layers - 2].GetBlockSize(); return m_verify_storages[m_max_layers - 2].GetBlockSize();
} }
fs::SubStorage GetL1HashStorage() { 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()));
} }
}; };

View File

@@ -37,18 +37,18 @@ namespace ams::fssystem::save {
}; };
static_assert(util::is_pod<BlockHash>::value); static_assert(util::is_pod<BlockHash>::value);
private: private:
fs::SubStorage hash_storage; fs::SubStorage m_hash_storage;
fs::SubStorage data_storage; fs::SubStorage m_data_storage;
s64 verification_block_size; s64 m_verification_block_size;
s64 verification_block_order; s64 m_verification_block_order;
s64 upper_layer_verification_block_size; s64 m_upper_layer_verification_block_size;
s64 upper_layer_verification_block_order; s64 m_upper_layer_verification_block_order;
IBufferManager *buffer_manager; IBufferManager *m_buffer_manager;
fs::HashSalt salt; fs::HashSalt m_salt;
bool is_real_data; bool m_is_real_data;
fs::StorageType storage_type; fs::StorageType m_storage_type;
public: 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(); } 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); 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; void CalcBlockHash(BlockHash *out, const void *buffer, size_t block_size) const;
s64 GetBlockSize() const { s64 GetBlockSize() const {
return this->verification_block_size; return m_verification_block_size;
} }
private: private:
Result ReadBlockSignature(void *dst, size_t dst_size, s64 offset, size_t size); 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); Result VerifyHash(const void *buf, BlockHash *hash);
void CalcBlockHash(BlockHash *out, const void *buffer) const { 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); Result IsCleared(bool *is_cleared, const BlockHash &hash);

Some files were not shown because too many files have changed in this diff Show More