From 92e7a3ca08b68f0a54608b05bf460200ad8db62b Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 18 Mar 2020 20:05:39 -0700 Subject: [PATCH] fs: add MountDeviceSaveData --- .../include/stratosphere/fs.hpp | 3 +- .../stratosphere/fs/fs_device_save_data.hpp | 25 +++++++++ .../source/fs/fs_device_save_data.cpp | 51 +++++++++++++++++++ .../include/vapours/results/fs_results.hpp | 1 + 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 libraries/libstratosphere/include/stratosphere/fs/fs_device_save_data.hpp create mode 100644 libraries/libstratosphere/source/fs/fs_device_save_data.cpp diff --git a/libraries/libstratosphere/include/stratosphere/fs.hpp b/libraries/libstratosphere/include/stratosphere/fs.hpp index d66b690c2..f9df48d3e 100644 --- a/libraries/libstratosphere/include/stratosphere/fs.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs.hpp @@ -45,7 +45,8 @@ #include #include #include +#include +#include #include #include #include -#include diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_device_save_data.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_device_save_data.hpp new file mode 100644 index 000000000..b70170382 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_device_save_data.hpp @@ -0,0 +1,25 @@ +/* + * 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 "fs_save_data_types.hpp" + +namespace ams::fs { + + Result MountDeviceSaveData(const char *name); + Result MountDeviceSaveData(const char *name, const ncm::ApplicationId application_id); + +} diff --git a/libraries/libstratosphere/source/fs/fs_device_save_data.cpp b/libraries/libstratosphere/source/fs/fs_device_save_data.cpp new file mode 100644 index 000000000..3e7a8e83e --- /dev/null +++ b/libraries/libstratosphere/source/fs/fs_device_save_data.cpp @@ -0,0 +1,51 @@ +/* + * 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 { + + namespace { + + constexpr inline SaveDataSpaceId DeviceSaveDataSpaceId = SaveDataSpaceId::User; + + Result MountDeviceSaveDataImpl(const char *name, const SaveDataAttribute &attribute) { + /* Validate the mount name. */ + R_TRY(impl::CheckMountName(name)); + + /* Open the filesystem, use libnx bindings. */ + ::FsFileSystem fs; + R_TRY(fsOpenSaveDataFileSystem(std::addressof(fs), static_cast<::FsSaveDataSpaceId>(DeviceSaveDataSpaceId), reinterpret_cast(std::addressof(attribute)))); + + /* Allocate a new filesystem wrapper. */ + auto fsa = std::make_unique(fs); + R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInDeviceSaveDataA()); + + /* Register. */ + return fsa::Register(name, std::move(fsa)); + } + + } + + Result MountDeviceSaveData(const char *name) { + return MountDeviceSaveDataImpl(name, SaveDataAttribute::Make(ncm::InvalidProgramId, SaveDataType::Device, InvalidUserId, InvalidSystemSaveDataId)); + } + + Result MountDeviceSaveData(const char *name, const ncm::ApplicationId application_id) { + return MountDeviceSaveDataImpl(name, SaveDataAttribute::Make(application_id, SaveDataType::Device, InvalidUserId, InvalidSystemSaveDataId)); + } + +} diff --git a/libraries/libvapours/include/vapours/results/fs_results.hpp b/libraries/libvapours/include/vapours/results/fs_results.hpp index 6566b85ac..2f5d74fd6 100644 --- a/libraries/libvapours/include/vapours/results/fs_results.hpp +++ b/libraries/libvapours/include/vapours/results/fs_results.hpp @@ -63,6 +63,7 @@ namespace ams::fs { R_DEFINE_ERROR_RESULT(AllocationFailureInContentStorageB, 3221); R_DEFINE_ERROR_RESULT(AllocationFailureInDataA, 3222); R_DEFINE_ERROR_RESULT(AllocationFailureInDataB, 3223); + R_DEFINE_ERROR_RESULT(AllocationFailureInDeviceSaveDataA, 3224); R_DEFINE_ERROR_RESULT(AllocationFailureInGameCardA, 3225); R_DEFINE_ERROR_RESULT(AllocationFailureInGameCardB, 3226); R_DEFINE_ERROR_RESULT(AllocationFailureInGameCardC, 3227);