pf2: implement much of Attach, structurally

This commit is contained in:
Michael Scire
2020-11-26 04:24:38 -08:00
parent 7b01d59b3b
commit ceef76c428
5 changed files with 318 additions and 5 deletions

View File

@@ -117,6 +117,34 @@ namespace ams::prfile2::pf {
HandleType partition_handle;
DriveCharacter drive_char;
u8 status;
template<size_t Ix>
constexpr ALWAYS_INLINE bool GetStatusBit() const {
constexpr u32 Mask = (1u << Ix);
return (this->status & Mask) != 0;
}
template<size_t Ix>
constexpr ALWAYS_INLINE void SetStatusBit(bool en) {
constexpr u32 Mask = (1u << Ix);
if (en) {
this->status |= Mask;
} else {
this->status &= ~Mask;
}
}
constexpr bool IsAttached() const { return this->GetStatusBit<0>(); }
constexpr void SetAttached(bool en) { this->SetStatusBit<0>(en); }
constexpr bool IsMounted() const { return this->GetStatusBit<1>(); }
constexpr void SetMounted(bool en) { this->SetStatusBit<1>(en); }
constexpr bool IsDiskInserted() const { return this->GetStatusBit<2>(); }
constexpr void SetDiskInserted(bool en) { this->SetStatusBit<2>(en); }
constexpr bool IsFlag12() const { return this->GetStatusBit<12>(); }
constexpr void SetFlag12(bool en) { this->SetStatusBit<12>(en); }
};
using TailBuf = u32;

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/>.
*/
#pragma once
#include <vapours/prfile2/prfile2_common.hpp>
namespace ams::prfile2 {
constexpr inline const auto MinimumFatBufferSize = 1;
constexpr inline const auto MaximumFatBufferSize = (1 << 16) - 1;
constexpr inline const auto MinimumDataBufferSize = 1;
constexpr inline const auto MaximumDataBufferSize = (1 << 15) - 1;
constexpr inline const auto MinimumFatPages = 1;
constexpr inline const auto MinimumDataPages = 4;
struct SectorCache {
u32 mode;
u16 num_fat_pages;
u16 num_data_pages;
pf::CachePage *current_fat;
pf::CachePage *current_data;
pf::SectorBuffer *buffers;
u32 fat_buf_size;
u32 data_buf_size;
void *signature;
};
}
namespace ams::prfile2::cache {
/* ... */
}

View File

@@ -64,7 +64,8 @@ namespace ams::prfile2 {
Error_SYSTEM = -1,
};
constexpr inline const u32 InvalidSector = std::numeric_limits<u32>::max();
constexpr inline const u32 InvalidSector = std::numeric_limits<u32>::max();
constexpr inline const u32 InvalidCluster = std::numeric_limits<u32>::max();
enum OpenMode {
OpenMode_None = 0,

View File

@@ -15,6 +15,7 @@
*/
#pragma once
#include <vapours/prfile2/prfile2_common.hpp>
#include <vapours/prfile2/prfile2_cache.hpp>
#include <vapours/prfile2/prfile2_critical_section.hpp>
#include <vapours/prfile2/prfile2_entry.hpp>
#include <vapours/prfile2/prfile2_fat.hpp>
@@ -129,6 +130,12 @@ namespace ams::prfile2 {
};
};
namespace pdm {
struct Partition;
}
struct Volume {
BiosParameterBlock bpb;
u32 num_free_clusters;
@@ -142,7 +149,7 @@ namespace ams::prfile2 {
u32 num_open_files;
u32 num_open_directories;
/* ... */
/* TODO: SectorCache cache; */
SectorCache cache;
VolumeContext *context;
u64 context_id;
DirectoryTail tail_entry;
@@ -156,13 +163,41 @@ namespace ams::prfile2 {
pf::Error last_error;
pf::Error last_driver_error;
/* ... */
void *partition;
HandleType partition_handle;
VolumeCallback callback;
const u8 *format_param;
/* ... */
/* TODO: ExtensionTable extension_table; */
/* TODO: ExtensionData ext; */
/* ... */
template<size_t Ix>
constexpr ALWAYS_INLINE bool GetFlagsBit() const {
constexpr u32 Mask = (1u << Ix);
return (this->flags & Mask) != 0;
}
template<size_t Ix>
constexpr ALWAYS_INLINE void SetFlagsBit(bool en) {
constexpr u32 Mask = (1u << Ix);
if (en) {
this->flags |= Mask;
} else {
this->flags &= ~Mask;
}
}
constexpr bool IsAttached() const { return this->GetFlagsBit<0>(); }
constexpr void SetAttached(bool en) { this->SetFlagsBit<0>(en); }
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 IsFlag12() const { return this->GetFlagsBit<12>(); }
constexpr void SetFlag12(bool en) { this->SetFlagsBit<12>(en); }
};
struct VolumeSet {