1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 08:22:04 +00:00

pf2: add drv::Initialize(Volume *)

This commit is contained in:
Michael Scire 2020-11-26 10:38:26 -08:00
parent ceef76c428
commit 102e1e0e74
7 changed files with 163 additions and 3 deletions

View file

@ -25,5 +25,6 @@
#include <vapours/prfile2/prfile2_system.hpp>
#include <vapours/prfile2/pdm/prfile2_pdm_api.hpp>
#include <vapours/prfile2/pdm/prfile2_pdm_disk_management.hpp>
#include <vapours/prfile2/pdm/prfile2_pdm_upper_layer_api.hpp>
#include <vapours/prfile2/prfile2_fatfs.hpp>
#include <vapours/prfile2/prfile2_volume.hpp>

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours/prfile2/pdm/prfile2_pdm_types.hpp>
#include <vapours/prfile2/pdm/prfile2_pdm_common.hpp>
#include <vapours/prfile2/pdm/prfile2_pdm_disk_management.hpp>
namespace ams::prfile2::pdm {
namespace part {
pdm::Error CheckDataEraseRequest(HandleType part_handle, bool *out);
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours/prfile2/prfile2_common.hpp>
namespace ams::prfile2 {
struct Volume;
}
namespace ams::prfile2::drv {
pf::Error Initialize(Volume *volume);
}

View file

@ -17,6 +17,7 @@
#include <vapours/prfile2/prfile2_common.hpp>
#include <vapours/prfile2/prfile2_cache.hpp>
#include <vapours/prfile2/prfile2_critical_section.hpp>
#include <vapours/prfile2/prfile2_drv.hpp>
#include <vapours/prfile2/prfile2_entry.hpp>
#include <vapours/prfile2/prfile2_fat.hpp>
@ -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); }

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#if defined(ATMOSPHERE_IS_STRATOSPHERE)
#include <stratosphere.hpp>
#elif defined(ATMOSPHERE_IS_MESOSPHERE)
#include <mesosphere.hpp>
#elif defined(ATMOSPHERE_IS_EXOSPHERE)
#include <exosphere.hpp>
#else
#include <vapours.hpp>
#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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#if defined(ATMOSPHERE_IS_STRATOSPHERE)
#include <stratosphere.hpp>
#elif defined(ATMOSPHERE_IS_MESOSPHERE)
#include <mesosphere.hpp>
#elif defined(ATMOSPHERE_IS_EXOSPHERE)
#include <exosphere.hpp>
#else
#include <vapours.hpp>
#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;
}
}

View file

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