From 102e1e0e743bdd3cecc762ce939e9db5c9aeb0b7 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 26 Nov 2020 10:38:26 -0800 Subject: [PATCH] pf2: add drv::Initialize(Volume *) --- .../libvapours/include/vapours/prfile2.hpp | 1 + .../pdm/prfile2_pdm_upper_layer_api.hpp | 29 ++++++++++++ .../include/vapours/prfile2/prfile2_drv.hpp | 29 ++++++++++++ .../vapours/prfile2/prfile2_volume.hpp | 11 ++++- .../pdm/prfile2_pdm_upper_layer_part_api.cpp | 47 +++++++++++++++++++ .../libvapours/source/prfile2/prfile2_drv.cpp | 45 ++++++++++++++++++ .../source/prfile2/prfile2_volume.cpp | 4 +- 7 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 libraries/libvapours/include/vapours/prfile2/pdm/prfile2_pdm_upper_layer_api.hpp create mode 100644 libraries/libvapours/include/vapours/prfile2/prfile2_drv.hpp create mode 100644 libraries/libvapours/source/prfile2/pdm/prfile2_pdm_upper_layer_part_api.cpp create mode 100644 libraries/libvapours/source/prfile2/prfile2_drv.cpp diff --git a/libraries/libvapours/include/vapours/prfile2.hpp b/libraries/libvapours/include/vapours/prfile2.hpp index 45a147200..80844e8ab 100644 --- a/libraries/libvapours/include/vapours/prfile2.hpp +++ b/libraries/libvapours/include/vapours/prfile2.hpp @@ -25,5 +25,6 @@ #include #include #include +#include #include #include diff --git a/libraries/libvapours/include/vapours/prfile2/pdm/prfile2_pdm_upper_layer_api.hpp b/libraries/libvapours/include/vapours/prfile2/pdm/prfile2_pdm_upper_layer_api.hpp new file mode 100644 index 000000000..c2056aad9 --- /dev/null +++ b/libraries/libvapours/include/vapours/prfile2/pdm/prfile2_pdm_upper_layer_api.hpp @@ -0,0 +1,29 @@ +/* + * 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 + +namespace ams::prfile2::pdm { + + namespace part { + + pdm::Error CheckDataEraseRequest(HandleType part_handle, bool *out); + + } + +} diff --git a/libraries/libvapours/include/vapours/prfile2/prfile2_drv.hpp b/libraries/libvapours/include/vapours/prfile2/prfile2_drv.hpp new file mode 100644 index 000000000..c093ae653 --- /dev/null +++ b/libraries/libvapours/include/vapours/prfile2/prfile2_drv.hpp @@ -0,0 +1,29 @@ +/* + * 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 + +namespace ams::prfile2 { + + struct Volume; + +} + +namespace ams::prfile2::drv { + + pf::Error Initialize(Volume *volume); + +} diff --git a/libraries/libvapours/include/vapours/prfile2/prfile2_volume.hpp b/libraries/libvapours/include/vapours/prfile2/prfile2_volume.hpp index db972b798..0e9005068 100644 --- a/libraries/libvapours/include/vapours/prfile2/prfile2_volume.hpp +++ b/libraries/libvapours/include/vapours/prfile2/prfile2_volume.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -193,8 +194,14 @@ namespace ams::prfile2 { constexpr bool IsMounted() const { return this->GetFlagsBit<1>(); } constexpr void SetMounted(bool en) { this->SetFlagsBit<1>(en); } - constexpr bool IsDiskInserted() const { return this->GetFlagsBit<2>(); } - constexpr void SetDiskInserted(bool en) { this->SetFlagsBit<2>(en); } + constexpr bool IsFormatAfterMountRequested() const { return this->GetFlagsBit<4>(); } + constexpr void SetFormatAfterMountRequested(bool en) { this->SetFlagsBit<4>(en); } + + constexpr bool IsNoFormattingByFatFsLayer() const { return this->GetFlagsBit<5>(); } + constexpr void SetNoFormattingByFatFsLayer(bool en) { this->SetFlagsBit<5>(en); } + + constexpr bool IsDataEraseRequested() const { return this->GetFlagsBit<6>(); } + constexpr void SetDataEraseRequested(bool en) { this->SetFlagsBit<6>(en); } constexpr bool IsFlag12() const { return this->GetFlagsBit<12>(); } constexpr void SetFlag12(bool en) { this->SetFlagsBit<12>(en); } diff --git a/libraries/libvapours/source/prfile2/pdm/prfile2_pdm_upper_layer_part_api.cpp b/libraries/libvapours/source/prfile2/pdm/prfile2_pdm_upper_layer_part_api.cpp new file mode 100644 index 000000000..212c87e33 --- /dev/null +++ b/libraries/libvapours/source/prfile2/pdm/prfile2_pdm_upper_layer_part_api.cpp @@ -0,0 +1,47 @@ +/* + * 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 . + */ +#if defined(ATMOSPHERE_IS_STRATOSPHERE) +#include +#elif defined(ATMOSPHERE_IS_MESOSPHERE) +#include +#elif defined(ATMOSPHERE_IS_EXOSPHERE) +#include +#else +#include +#endif +#include "prfile2_pdm_disk_set.hpp" + +namespace ams::prfile2::pdm::part { + + pdm::Error CheckDataEraseRequest(HandleType part_handle, bool *out) { + /* Check parameters. */ + Partition *part = GetPartition(part_handle); + if (out == nullptr || part == nullptr) { + return pdm::Error_InvalidParameter; + } + + /* Get the disk. */ + Disk *disk = GetDisk(part->disk_handle); + if (disk == nullptr) { + return pdm::Error_InvalidParameter; + } + + /* Check for data erase function. */ + *out = disk->erase_callback != nullptr; + return pdm::Error_Ok; + } + +} diff --git a/libraries/libvapours/source/prfile2/prfile2_drv.cpp b/libraries/libvapours/source/prfile2/prfile2_drv.cpp new file mode 100644 index 000000000..ddfd79611 --- /dev/null +++ b/libraries/libvapours/source/prfile2/prfile2_drv.cpp @@ -0,0 +1,45 @@ +/* + * 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 . + */ +#if defined(ATMOSPHERE_IS_STRATOSPHERE) +#include +#elif defined(ATMOSPHERE_IS_MESOSPHERE) +#include +#elif defined(ATMOSPHERE_IS_EXOSPHERE) +#include +#else +#include +#endif + +namespace ams::prfile2::drv { + + pf::Error Initialize(Volume *volume) { + /* Check the volume. */ + if (volume == nullptr) { + return pf::Error_InvalidParameter; + } + + /* Check the data erase request. */ + bool data_erase; + if (auto pdm_err = pdm::part::CheckDataEraseRequest(volume->partition_handle, std::addressof(data_erase)); pdm_err != pdm::Error_Ok) { + return pf::Error_Generic; + } + + /* Set the data erase request flag. */ + volume->SetDataEraseRequested(data_erase); + return pf::Error_Ok; + } + +} diff --git a/libraries/libvapours/source/prfile2/prfile2_volume.cpp b/libraries/libvapours/source/prfile2/prfile2_volume.cpp index 68d653c47..5034bab20 100644 --- a/libraries/libvapours/source/prfile2/prfile2_volume.cpp +++ b/libraries/libvapours/source/prfile2/prfile2_volume.cpp @@ -273,7 +273,9 @@ namespace ams::prfile2::vol { vol->tail_entry.tracker_bits = vol->tail_entry.tracker_buf; /* Initialize driver for volume. */ - /* TODO: drv::Initialize(vol); + error checking */ + if (auto err = drv::Initialize(vol); err != pf::Error_Ok) { + return SetLastErrorAndReturn(err); + } /* Setup the cache. */ /* TODO: cache::SetCache(vol, drive_table->cache->pages, drive_table->cache->buffers, drive_table->cache->num_fat_pages, drive_table->cache->num_data_pages); */