From f019daae0e8d3c5ceee57c2b136878afb96b6c08 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 26 Jun 2020 02:24:52 -0700 Subject: [PATCH] sysupdater: implement content meta mounting --- libstratosphere/include/stratosphere/fs.hpp | 1 + .../fs/fs_shared_filesystem_holder.hpp | 54 +++++++++++++++++++ .../include/vapours/results/fs_results.hpp | 2 + .../include/vapours/util/util_string_util.hpp | 48 +++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 libstratosphere/include/stratosphere/fs/fs_shared_filesystem_holder.hpp diff --git a/libstratosphere/include/stratosphere/fs.hpp b/libstratosphere/include/stratosphere/fs.hpp index 96093da5..faa1f851 100644 --- a/libstratosphere/include/stratosphere/fs.hpp +++ b/libstratosphere/include/stratosphere/fs.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/libstratosphere/include/stratosphere/fs/fs_shared_filesystem_holder.hpp b/libstratosphere/include/stratosphere/fs/fs_shared_filesystem_holder.hpp new file mode 100644 index 00000000..9a4c5931 --- /dev/null +++ b/libstratosphere/include/stratosphere/fs/fs_shared_filesystem_holder.hpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include +#include +#include +#include + +namespace ams::fs { + + class SharedFileSystemHolder : public fsa::IFileSystem, public impl::Newable { + NON_COPYABLE(SharedFileSystemHolder); + NON_MOVEABLE(SharedFileSystemHolder); + private: + std::shared_ptr fs; + public: + SharedFileSystemHolder(std::shared_ptr f) : fs(std::move(f)) { /* ... */ } + public: + virtual Result CreateFileImpl(const char *path, s64 size, int flags) override { return this->fs->CreateFile(path, size, flags); } + virtual Result DeleteFileImpl(const char *path) override { return this->fs->DeleteFile(path); } + virtual Result CreateDirectoryImpl(const char *path) override { return this->fs->CreateDirectory(path); } + virtual Result DeleteDirectoryImpl(const char *path) override { return this->fs->DeleteDirectory(path); } + virtual Result DeleteDirectoryRecursivelyImpl(const char *path) override { return this->fs->DeleteDirectoryRecursively(path); } + virtual Result RenameFileImpl(const char *old_path, const char *new_path) override { return this->fs->RenameFile(old_path, new_path); } + virtual Result RenameDirectoryImpl(const char *old_path, const char *new_path) override { return this->fs->RenameDirectory(old_path, new_path); } + virtual Result GetEntryTypeImpl(fs::DirectoryEntryType *out, const char *path) override { return this->fs->GetEntryType(out, path); } + virtual Result OpenFileImpl(std::unique_ptr *out_file, const char *path, fs::OpenMode mode) override { return this->fs->OpenFile(out_file, path, mode); } + virtual Result OpenDirectoryImpl(std::unique_ptr *out_dir, const char *path, fs::OpenDirectoryMode mode) override { return this->fs->OpenDirectory(out_dir, path, mode); } + virtual Result CommitImpl() override { return this->fs->Commit(); } + virtual Result GetFreeSpaceSizeImpl(s64 *out, const char *path) override { return this->fs->GetFreeSpaceSize(out, path); } + virtual Result GetTotalSpaceSizeImpl(s64 *out, const char *path) override { return this->fs->GetTotalSpaceSize(out, path); } + virtual Result CleanDirectoryRecursivelyImpl(const char *path) override { return this->fs->CleanDirectoryRecursively(path); } + + /* These aren't accessible as commands. */ + virtual Result CommitProvisionallyImpl(s64 counter) override { return this->fs->CommitProvisionally(counter); } + virtual Result RollbackImpl() override { return this->fs->Rollback(); } + virtual Result FlushImpl() override { return this->fs->Flush(); } + }; + +} diff --git a/libvapours/include/vapours/results/fs_results.hpp b/libvapours/include/vapours/results/fs_results.hpp index 0eeb9ada..88987e73 100644 --- a/libvapours/include/vapours/results/fs_results.hpp +++ b/libvapours/include/vapours/results/fs_results.hpp @@ -78,6 +78,8 @@ namespace ams::fs { R_DEFINE_ERROR_RESULT(AllocationFailureInRomFsFileSystemA, 3247); R_DEFINE_ERROR_RESULT(AllocationFailureInRomFsFileSystemB, 3248); R_DEFINE_ERROR_RESULT(AllocationFailureInRomFsFileSystemC, 3249); + R_DEFINE_ERROR_RESULT(AllocationFailureInFileSystemProxyCoreImplD, 3256); + R_DEFINE_ERROR_RESULT(AllocationFailureInFileSystemProxyCoreImplE, 3257); R_DEFINE_ERROR_RESULT(AllocationFailureInPartitionFileSystemCreatorA, 3280); R_DEFINE_ERROR_RESULT(AllocationFailureInRomFileSystemCreatorA, 3281); R_DEFINE_ERROR_RESULT(AllocationFailureInStorageOnNcaCreatorA, 3288); diff --git a/libvapours/include/vapours/util/util_string_util.hpp b/libvapours/include/vapours/util/util_string_util.hpp index a1536769..d06d96a7 100644 --- a/libvapours/include/vapours/util/util_string_util.hpp +++ b/libvapours/include/vapours/util/util_string_util.hpp @@ -20,6 +20,54 @@ namespace ams::util { + template + constexpr T ToLower(T c) { + return ('A' <= c && c <= 'Z') ? (c - 'A' + 'a') : c; + } + + template + constexpr T ToUpper(T c) { + return ('a' <= c && c <= 'z') ? (c - 'a' + 'A') : c; + } + + template + int Strncmp(const T *lhs, const T *rhs, int count) { + AMS_ASSERT(lhs != nullptr); + AMS_ASSERT(rhs != nullptr); + AMS_ABORT_UNLESS(count >= 0); + + if (count == 0) { + return 0; + } + + T l, r; + do { + l = *(lhs++); + r = *(rhs++); + } while (l && (l == r) && (--count)); + + return l - r; + } + + template + int Strnicmp(const T *lhs, const T *rhs, int count) { + AMS_ASSERT(lhs != nullptr); + AMS_ASSERT(rhs != nullptr); + AMS_ABORT_UNLESS(count >= 0); + + if (count == 0) { + return 0; + } + + T l, r; + do { + l = ::ams::util::ToLower(*(lhs++)); + r = ::ams::util::ToLower(*(rhs++)); + } while (l && (l == r) && (--count)); + + return l - r; + } + template constexpr int Strlcpy(T *dst, const T *src, int count) { AMS_ASSERT(dst != nullptr);