12using namespace MaxOS::filesystem;
13using namespace MaxOS::processes;
14using namespace MaxOS::common;
15using namespace syscore::filesystem;
31FileResource::~FileResource() =
default;
50 case FileFlags::DEFAULT:{
57 case FileFlags::READ_SIZE:{
61 case FileFlags::READ_OFFSET:{
88 case FileFlags::DEFAULT:{
95 case FileFlags::WRITE_SEEK_SET:
99 case FileFlags::WRITE_SEEK_CUR:
100 file->
seek(SeekType::CURRENT, size);
103 case FileFlags::WRITE_SEEK_END:
107 case FileFlags::WRITE_NAME:{
141DirectoryResource::~DirectoryResource() =
default;
149void DirectoryResource::write_entries(
void const* buffer,
size_t size)
const {
167 entry->is_file = is_file;
168 entry->size = entry_size;
171 entry->name[
name.length()] =
'\0';
184 for (
const auto& file :
directory->files()) {
203size_t DirectoryResource::entries_size()
const {
208 for (
const auto& file :
directory->files()) {
237 case DirectoryFlags::READ_ENTRIES:{
238 write_entries(buffer, size);
242 case DirectoryFlags::READ_ENTRIES_SIZE:{
243 return entries_size();
272 case DirectoryFlags::WRITE_NAME : {
284 case DirectoryFlags::WRITE_NEW_FILE:{
292 case DirectoryFlags::WRITE_NEW_DIR:{
299 case DirectoryFlags::WRITE_REMOVE_FILE:{
305 case DirectoryFlags::WRITE_REMOVE_DIR:{
331VFSResourceRegistry::~VFSResourceRegistry() =
default;
340Resource* VFSResourceRegistry::open_as_resource(
const string& name,
Directory* directory) {
361Resource* VFSResourceRegistry::open_as_resource(
string const& name,
File* file) {
Wrapper class for a region of bytes in memor in an attempt to add some memory safety....
Stores the left, top, width and height of a rectangle.
A wrapper for a Directory which exposes Directory operations as Resource operations.
DirectoryResource(const string &name, size_t flags, processes::resource_type_t type)
Construct a new Directory Resource object.
int read(void *buffer, size_t size, size_t flags) final
read from a directory resource
int write(const void *buffer, size_t size, size_t flags) final
write to a directory resource
Directory * directory
The directory that this resource handles & exposes.
Handles a group of files (directory)
virtual Directory * create_subdirectory(const string &name)
Create a directory in the directory.
virtual void remove_subdirectory(const string &name)
Try to remove a directory in the directory.
virtual void remove_file(const string &name)
Delete a file in the directory.
virtual File * create_file(const string &name)
Create a file in the directory.
A wrapper for a File which exposes File operations as Resource operations.
int write(const void *buffer, size_t size, size_t flags) final
write to a file resource
FileResource(const string &name, size_t flags, processes::resource_type_t type)
Construct a new File Resource object.
File * file
The file that this resource handles & exposes.
int read(void *buffer, size_t size, size_t flags) final
read from a file resource
Handles file operations and information.
virtual void read(common::buffer_t *data, size_t size)
read data from the file
size_t size() const
Get the size of the file.
void seek(SeekType seek_type, size_t offset)
Seek to a position in the file.
uint32_t position() const
Get where the file is currently at (amount read/write/seeked)
virtual void write(common::buffer_t *data, size_t size)
write data to the file
static string parent_directory(const string &path)
Get the parent directory of the path.
static bool is_file(const string &path)
Check if a path is a file.
static string join_path(const string &base, const string &extended)
Joins two paths together.
static string absolute_path(const string &path)
Calculates path with out any "../" or "./".
processes::Resource * get_resource(const string &name) final
Gets a resource from the registry by name.
processes::Resource * create_resource(const string &name, size_t flags) final
Try to create a new resource with the specified name, will fail if the name is in use.
VFSResourceRegistry(VirtualFileSystem *vfs)
Construct a new VFS Resource Registry object.
Combines all the filesystems across the partitions on each disk into a single filesystems and exposes...
Directory * open_directory(const string &path)
Try to open a directory on the virtual file system and read it's contents.
File * open_file(const string &path, size_t offset=0)
Try to open a file on the virtual file system with a given offset.
Directory * create_directory(string path)
Attempts to open the parent directory and creates the sub directory at the end of the path.
File * create_file(const string &path)
Attempts to open the parent directory and create the file at the end of the path.
Manages the creation, retention and destruction of resources of a certain type. Should be subclassed ...
virtual Resource * get_resource(const string &name)
Gets a resource from the registry by name.
virtual bool register_resource(Resource *resource)
Registers a resource in the registry.
static BaseResourceRegistry * get_registry(resource_type_t type)
Gets a registry of a type.
static Process * current_process()
Gets the process on the currently executing core.
Represents a generic resource that can be opened, closed, read from and written to.
string name()
Gets the name of this resource.
void * memcpy(void *destination, const void *source, uint64_t num)
Copies a block of memory from one location to another.
::syscore::ResourceType resource_type_t
Alias to make the libsyscore ResourceType accessible here.
class MaxOS::String string
Typedef for String.
Defines VFSResource classes for wrapping File and Directory objects as Resources in the Virtual File ...