mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-04 23:35:12 +01:00
Implement backing modes
These are used to determine the capabilities of a backing.
This commit is contained in:
parent
b94248cec0
commit
26025d9adf
@ -11,12 +11,27 @@ namespace skyline::vfs {
|
||||
*/
|
||||
class Backing {
|
||||
public:
|
||||
/**
|
||||
* @brief This describes the modes that a backing is capable of
|
||||
*/
|
||||
union Mode {
|
||||
struct {
|
||||
bool read : 1; //!< The backing is readable
|
||||
bool write : 1; //!< The backing is writable
|
||||
bool append : 1; //!< The backing can be appended
|
||||
};
|
||||
u32 raw; //!< The raw value of the mode
|
||||
};
|
||||
static_assert(sizeof(Mode) == 0x4);
|
||||
|
||||
Mode mode; //!< The mode of the backing
|
||||
size_t size; //!< The size of the backing in bytes
|
||||
|
||||
/**
|
||||
* @param mode The mode to use for the backing
|
||||
* @param size The initial size of the backing
|
||||
*/
|
||||
Backing(size_t size = 0) : size(size) {}
|
||||
Backing(Mode mode = {true, false, false}, size_t size = 0) : mode(mode), size(size) {}
|
||||
|
||||
/* Delete the move constructor to prevent multiple instances of the same backing */
|
||||
Backing(const Backing &) = delete;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "os_backing.h"
|
||||
|
||||
namespace skyline::vfs {
|
||||
OsBacking::OsBacking(int fd) : fd(fd) {
|
||||
OsBacking::OsBacking(int fd) : Backing(), fd(fd) {
|
||||
struct stat fileInfo;
|
||||
|
||||
if (fstat(fd, &fileInfo))
|
||||
@ -17,6 +17,9 @@ namespace skyline::vfs {
|
||||
}
|
||||
|
||||
size_t OsBacking::Read(u8 *output, size_t offset, size_t size) {
|
||||
if (!mode.read)
|
||||
throw exception("Attempting to read a backing that is not readable");
|
||||
|
||||
auto ret = pread64(fd, output, size, offset);
|
||||
|
||||
if (ret < 0)
|
||||
|
@ -20,9 +20,12 @@ namespace skyline::vfs {
|
||||
* @param offset The offset of the region start within the parent backing
|
||||
* @param size The size of the region in the parent backing
|
||||
*/
|
||||
RegionBacking(const std::shared_ptr<vfs::Backing> &backing, size_t offset, size_t size) : Backing(size), backing(backing), offset(offset) {};
|
||||
RegionBacking(const std::shared_ptr<vfs::Backing> &backing, size_t offset, size_t size, Mode mode = {true, false, false}) : Backing(mode, size), backing(backing), offset(offset) {};
|
||||
|
||||
inline size_t Read(u8 *output, size_t offset, size_t size) {
|
||||
if (!mode.read)
|
||||
throw exception("Attempting to read a backing that is not readable");
|
||||
|
||||
size = std::min(offset + size, this->size) - offset;
|
||||
|
||||
return backing->Read(output, this->offset + offset, size);
|
||||
|
Loading…
Reference in New Issue
Block a user