Max OS 0.3
Loading...
Searching...
No Matches
filesystem.h
Go to the documentation of this file.
1
9#ifndef MAXOS_FILESYSTEM_FILESYSTEM_H
10#define MAXOS_FILESYSTEM_FILESYSTEM_H
11
12#include <cstdint>
13#include <cstddef>
14#include <common/string.h>
15#include <common/vector.h>
16#include <common/buffer.h>
17#include <filesystem/path.h>
18#include <syscore/include/filesystem/file.h>
19
20
21namespace MaxOS::filesystem {
22
23
24 typedef uint32_t lba_t;
25 typedef syscore::filesystem::SeekType SeekType;
26
31 class File {
32
33 protected:
34 uint32_t m_offset = 0;
35 string m_name;
36 size_t m_size = 0;
37
38 public:
39 File();
40 virtual ~File();
41
42 virtual void write(common::buffer_t* data, size_t size);
43 virtual void read(common::buffer_t* data, size_t size);
44 virtual void flush();
45
46 void seek(SeekType seek_type, size_t offset);
47 [[nodiscard]] uint32_t position() const;
48
49 [[nodiscard]] size_t size() const;
50 string name();
51 };
52
57 class Directory {
58 protected:
61
62 string m_name;
63
64 public:
65 Directory();
66 virtual ~Directory();
67
68 virtual void read_from_disk();
69
72
73 File* open_file(const string& name);
74 Directory* open_subdirectory(const string& name);
75
76 virtual File* create_file(const string& name);
77 virtual void remove_file(const string& name);
78
79 void rename_file(File* file, const string& new_name);
80 virtual void rename_file(const string& old_name, const string& new_name);
81
82 void rename_subdirectory(Directory* directory, const string& new_name);
83 virtual void rename_subdirectory(const string& old_name, const string& new_name);
84
85 virtual Directory* create_subdirectory(const string& name);
86 virtual void remove_subdirectory(const string& name);
87
88 string name();
89 size_t size();
90 };
91
96 class FileSystem {
97 protected:
99
100 public:
101 FileSystem();
102 virtual ~FileSystem();
103
105 Directory* get_directory(const string& path);
106
107 bool exists(const string& path);
108 };
109
110}
111
112
113#endif //MAXOS_FILESYSTEM_FILESYSTEM_H
Defines a Buffer class for safe memory operations.
Wrapper class for a region of bytes in memor in an attempt to add some memory safety....
Definition buffer.h:25
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Handles a group of files (directory)
Definition filesystem.h:57
common::Vector< Directory * > m_subdirectories
The subdirectories in this directory.
Definition filesystem.h:60
void rename_file(File *file, const string &new_name)
Rename a file in the directory.
string m_name
The name of this directory.
Definition filesystem.h:62
Directory * open_subdirectory(const string &name)
Open a directory in the directory.
virtual Directory * create_subdirectory(const string &name)
Create a directory in the directory.
File * open_file(const string &name)
Open a file in the directory.
virtual void remove_subdirectory(const string &name)
Try to remove a directory in the directory.
size_t size()
Get the size of the directory.
void rename_subdirectory(Directory *directory, const string &new_name)
Rename a subdirectory in the directory.
common::Vector< File * > m_files
The files in this directory.
Definition filesystem.h:59
common::Vector< Directory * > subdirectories()
Get the subdirectories in the directory.
virtual void remove_file(const string &name)
Delete a file in the directory.
common::Vector< File * > files()
Get the files in the directory.
virtual void read_from_disk()
read the directory from the disk
string name()
Get the name of the directory.
virtual File * create_file(const string &name)
Create a file in the directory.
virtual ~Directory()
Destructor for Directory, frees all files and subdirectories.
Handles the disk operations and file system information.
Definition filesystem.h:96
Directory * get_directory(const string &path)
Get the directory at a given path.
bool exists(const string &path)
Check if a path exists on the filesystem.
Directory * m_root_directory
The fist directory in the file system (not be confused with the system root)
Definition filesystem.h:98
virtual ~FileSystem()
Destructor for FileSystem, frees the root directory (Which in turn frees all files and subdirectories...
Directory * root_directory()
Get the directory at "/".
Handles file operations and information.
Definition filesystem.h:31
size_t m_size
The size of the file.
Definition filesystem.h:36
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.
string m_name
The name of the file.
Definition filesystem.h:35
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
uint32_t m_offset
The current offset in the file.
Definition filesystem.h:34
string name()
Get the name of the file.
virtual void flush()
Flush the file to the disk.
syscore::filesystem::SeekType SeekType
Seek type for file operations.
Definition filesystem.h:25
uint32_t lba_t
Logical Block Addressing type.
Definition filesystem.h:24
Provides utilities for handling file and directory paths.
Defines a String class for dynamically sized strings with various operations.
Defines a Vector class for dynamically storing an array of elements.