21static uint8_t mount_count = 0;
23#define MAIN_FS_DEVICE 0
26static MTSTATUS fat32_fs_init(uint8_t device_id) {
31 .init = fat32_fs_init,
62static MOUNTED_FS* vfs_find_fs_for_path(
const char* path) {
63 if (!path)
return NULL;
64 for (uint8_t i = 0; i < mount_count; i++) {
65 const char* mount = mounted_fs[i].mount_point;
67 if (mount[0] ==
'/' && mount[1] ==
'\0')
return &mounted_fs[i];
71 while (mount[mount_len]) mount_len++;
75 while (path[path_len]) path_len++;
76 if (path_len < mount_len)
continue;
79 for (
size_t j = 0; j < mount_len; j++) {
80 if (path[j] != mount[j]) { match =
false;
break; }
82 if (match)
return &mounted_fs[i];
88 MOUNTED_FS* fs = vfs_find_fs_for_path(filename);
91 return fs->driver->read(filename, file_size_out, buffer_out);
98 return fs->driver->write(path, data, size, (uint32_t)write_mode);
105 return fs->driver->delete(path);
112 return fs->driver->listdir(path, listings, max_len);
119 return fs->driver->mkdir(path);
126 return fs->driver->rmdir(path);
131 if (!fs || !fs->driver || !fs->driver->is_dir_empty)
return false;
133 return fs->driver->is_dir_empty(path);
138 if (!fs || !fs->driver || !fs->driver->listrootdir)
return;
140 fs->driver->listrootdir();
MTSTATUS ahci_init(void)
define AHCI_DEBUG_PRINT
MTSTATUS fat32_init(int disk_index)
MTSTATUS fat32_create_directory(const char *path)
Creates a new directory (/testdir/ or /testdir are both allowed to create 'testdir' inside of 'root')
MTSTATUS fat32_list_directory(const char *path, char *listings, size_t max_len)
Lists the directory given.
MTSTATUS fat32_delete_directory(const char *path)
This function deletes the directory given to the function from the system.
MTSTATUS fat32_read_file(const char *filename, uint32_t *file_size_out, void **buffer_out)
A FAT32 Function that reads the file requested into a dynamically allocated buffer.
MTSTATUS fat32_write_file(const char *path, const void *data, uint32_t size, uint32_t mode)
Creates a new file and writes data to it.
MTSTATUS fat32_delete_file(const char *path)
This function deletes the file given to the function from the system.
void fat32_list_root(void)
bool fat32_directory_is_empty(const char *path)
This function returns if the directory given to the function is empty (e.g, has only '....
void gop_printf(uint32_t color, const char *fmt,...)
#define COLOR_RED
Colors definitions for easier access.
#define MT_NOT_IMPLEMENTED
#define MT_FAILURE(Status)
MTSTATUS vfs_read(const char *filename, uint32_t *file_size_out, void **buffer_out)
Reads the file into a buffer.
MTSTATUS vfs_rmdir(const char *path)
This function deletes the directory given to the function from the system along with its file (marks ...
void vfs_listrootdir(void)
This function will list the root directory of the main mount device.
MTSTATUS vfs_listdir(const char *path, char *listings, size_t max_len)
Lists the directory given.
MTSTATUS vfs_mkdir(const char *path)
Creates a new directory.
bool vfs_is_dir_empty(const char *path)
This function returns if the directory given to the function is empty (e.g, has only '....
MTSTATUS vfs_delete(const char *path)
This function deletes the file given to the function from the system.
MTSTATUS vfs_init(void)
Initialize the Virtual File System (initializes other filesystem needed services as well)
MTSTATUS vfs_write(const char *path, const void *data, uint32_t size, FS_WRITE_MODES write_mode)
Creates a new file (or opens existing) and writes data to it.
enum _FS_WRITE_MODES FS_WRITE_MODES