2018-01-19 22:34:48 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2014-12-17 00:38:14 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-09-11 18:46:42 -04:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-09-27 15:41:21 -04:00
|
|
|
#include <cstddef>
|
2018-08-08 17:49:57 -04:00
|
|
|
#include <iterator>
|
|
|
|
#include <string_view>
|
2018-03-19 23:58:55 -04:00
|
|
|
#include "common/common_funcs.h"
|
2014-09-11 18:46:42 -04:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FileSys namespace
|
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
enum EntryType : u8 {
|
|
|
|
Directory = 0,
|
|
|
|
File = 1,
|
|
|
|
};
|
|
|
|
|
2018-03-19 23:58:55 -04:00
|
|
|
// Structure of a directory entry, from
|
|
|
|
// http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry
|
2014-09-11 18:46:42 -04:00
|
|
|
struct Entry {
|
2018-08-08 17:49:57 -04:00
|
|
|
Entry(std::string_view view, EntryType entry_type, u64 entry_size)
|
|
|
|
: type{entry_type}, file_size{entry_size} {
|
2018-09-15 09:21:06 -04:00
|
|
|
const std::size_t copy_size = view.copy(filename, std::size(filename) - 1);
|
2018-08-08 17:49:57 -04:00
|
|
|
filename[copy_size] = '\0';
|
|
|
|
}
|
|
|
|
|
2018-12-02 23:15:55 -05:00
|
|
|
char filename[0x301];
|
|
|
|
INSERT_PADDING_BYTES(3);
|
2018-03-19 23:58:55 -04:00
|
|
|
EntryType type;
|
|
|
|
INSERT_PADDING_BYTES(3);
|
|
|
|
u64 file_size;
|
2014-09-11 18:46:42 -04:00
|
|
|
};
|
2018-03-19 23:58:55 -04:00
|
|
|
static_assert(sizeof(Entry) == 0x310, "Directory Entry struct isn't exactly 0x310 bytes long!");
|
|
|
|
static_assert(offsetof(Entry, type) == 0x304, "Wrong offset for type in Entry.");
|
|
|
|
static_assert(offsetof(Entry, file_size) == 0x308, "Wrong offset for file_size in Entry.");
|
2014-09-11 18:46:42 -04:00
|
|
|
|
2014-12-15 01:59:29 -05:00
|
|
|
class DirectoryBackend : NonCopyable {
|
2014-09-11 18:46:42 -04:00
|
|
|
public:
|
2016-09-18 21:01:46 -04:00
|
|
|
DirectoryBackend() {}
|
|
|
|
virtual ~DirectoryBackend() {}
|
2014-09-11 18:46:42 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List files contained in the directory
|
|
|
|
* @param count Number of entries to return at once in entries
|
|
|
|
* @param entries Buffer to read data into
|
|
|
|
* @return Number of entries listed
|
|
|
|
*/
|
2018-03-19 23:58:55 -04:00
|
|
|
virtual u64 Read(const u64 count, Entry* entries) = 0;
|
|
|
|
|
|
|
|
/// Returns the number of entries still left to read.
|
|
|
|
virtual u64 GetEntryCount() const = 0;
|
2014-09-11 18:46:42 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the directory
|
|
|
|
* @return true if the directory closed correctly
|
|
|
|
*/
|
|
|
|
virtual bool Close() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FileSys
|