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); */