From c4f93dbed2309a7aa9c483c4337470905a2c1f1d Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 7 Mar 2020 21:07:23 -0800 Subject: [PATCH] fs: implement MountCode --- .../include/stratosphere/fs.hpp | 1 + .../include/stratosphere/fs/fs_code.hpp | 24 ++++++++++ .../libstratosphere/source/fs/fs_code.cpp | 44 +++++++++++++++++++ stratosphere/boot/source/boot_main.cpp | 1 - 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 libraries/libstratosphere/include/stratosphere/fs/fs_code.hpp create mode 100644 libraries/libstratosphere/source/fs/fs_code.cpp diff --git a/libraries/libstratosphere/include/stratosphere/fs.hpp b/libraries/libstratosphere/include/stratosphere/fs.hpp index ec4975eb8..1ed062124 100644 --- a/libraries/libstratosphere/include/stratosphere/fs.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs.hpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_code.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_code.hpp new file mode 100644 index 000000000..e151f94ba --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_code.hpp @@ -0,0 +1,24 @@ +/* + * 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 "fs_common.hpp" +#include + +namespace ams::fs { + + Result MountCode(const char *name, const char *path, ncm::ProgramId program_id); + +} diff --git a/libraries/libstratosphere/source/fs/fs_code.cpp b/libraries/libstratosphere/source/fs/fs_code.cpp new file mode 100644 index 000000000..51cb20b72 --- /dev/null +++ b/libraries/libstratosphere/source/fs/fs_code.cpp @@ -0,0 +1,44 @@ +/* + * 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 . + */ +#include +#include "fsa/fs_mount_utils.hpp" + +namespace ams::fs { + + Result MountCode(const char *name, const char *path, ncm::ProgramId program_id) { + /* Validate the mount name. */ + R_TRY(impl::CheckMountName(name)); + + /* Validate the path isn't null. */ + R_UNLESS(path != nullptr, fs::ResultInvalidPath()); + + /* Print a path suitable for the remove service. */ + fssrv::sf::Path sf_path; + R_TRY(FspPathPrintf(std::addressof(sf_path), "%s", path)); + + /* Open the filesystem using libnx bindings. */ + ::FsFileSystem fs; + R_TRY(fsldrOpenCodeFileSystem(program_id.value, sf_path.str, std::addressof(fs))); + + /* Allocate a new filesystem wrapper. */ + std::unique_ptr fsa(new RemoteFileSystem(fs)); + R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInCodeA()); + + /* Register. */ + return fsa::Register(name, std::move(fsa)); + } + +} diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index a46c4097a..857da11b1 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -100,7 +100,6 @@ void __appInit(void) { void __appExit(void) { /* Cleanup services. */ - fsdevUnmountAll(); pmshellExit(); splExit(); fsExit();