My Project
Loading...
Searching...
No Matches
vfs.c File Reference
#include "vfs.h"
#include "../../drivers/ahci/ahci.h"
#include "../fat32/fat32.h"
#include "../../includes/macros.h"

Go to the source code of this file.

Data Structures

struct  MOUNTED_FS

Macros

#define MAX_MOUNTS   4
#define MAIN_FS_DEVICE   0

Typedefs

typedef struct MOUNTED_FS MOUNTED_FS

Functions

MTSTATUS vfs_init (void)
 Initialize the Virtual File System (initializes other filesystem needed services as well)
MTSTATUS vfs_read (const char *filename, uint32_t *file_size_out, void **buffer_out)
 Reads the file into a buffer.
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.
MTSTATUS vfs_delete (const char *path)
 This function deletes the file given to the function from the system.
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.
MTSTATUS vfs_rmdir (const char *path)
 This function deletes the directory given to the function from the system along with its file (marks as deleted).
bool vfs_is_dir_empty (const char *path)
 This function returns if the directory given to the function is empty (e.g, has only '.' and '..' entries / is nonexistent / is deleted)
void vfs_listrootdir (void)
 This function will list the root directory of the main mount device.

Variables

FS_DRIVER fat32_driver

Macro Definition Documentation

◆ MAIN_FS_DEVICE

#define MAIN_FS_DEVICE   0

Definition at line 23 of file vfs.c.

◆ MAX_MOUNTS

#define MAX_MOUNTS   4

Definition at line 19 of file vfs.c.

Typedef Documentation

◆ MOUNTED_FS

typedef struct MOUNTED_FS MOUNTED_FS

Function Documentation

◆ vfs_delete()

MTSTATUS vfs_delete ( const char * path)

This function deletes the file given to the function from the system.

Parameters
pathFull path to delete file.
Returns
MTSTATUS Status code.

Definition at line 101 of file vfs.c.

◆ vfs_init()

MTSTATUS vfs_init ( void )

Initialize the Virtual File System (initializes other filesystem needed services as well)

Returns
MTSTATUS Status Code

Definition at line 42 of file vfs.c.

◆ vfs_is_dir_empty()

bool vfs_is_dir_empty ( const char * path)

This function returns if the directory given to the function is empty (e.g, has only '.' and '..' entries / is nonexistent / is deleted)

Parameters
pathFull path to dir
Returns
True or false based if empty or not.

Definition at line 129 of file vfs.c.

◆ vfs_listdir()

MTSTATUS vfs_listdir ( const char * path,
char * listings,
size_t max_len )

Lists the directory given.

Parameters
pathPath to directory, e.g "mydir/"
listings[OUT] Pointer to directory listing. (each seperated with a newline character)
max_len[IN] Max size of listings buffer.
Returns
MTSTATUS Status code.

Definition at line 108 of file vfs.c.

◆ vfs_listrootdir()

void vfs_listrootdir ( void )

This function will list the root directory of the main mount device.

Definition at line 136 of file vfs.c.

◆ vfs_mkdir()

MTSTATUS vfs_mkdir ( const char * path)

Creates a new directory.

Parameters
pathThe full path to the new directory
Returns
MTSTATUS Status code.

Definition at line 115 of file vfs.c.

◆ vfs_read()

MTSTATUS vfs_read ( const char * filename,
uint32_t * file_size_out,
void ** buffer_out )

Reads the file into a buffer.

Parameters
filenameThe Filename to read, e.g "file.txt" or "tmp/folder/myfile.txt"
file_size_outA pointer to put the file size in bytes
bufferOutA pointer to put the file buffer in (doesn't need to be dynamically allocated)
Returns
MTSTATUS Status Code.

Definition at line 87 of file vfs.c.

◆ vfs_rmdir()

MTSTATUS vfs_rmdir ( const char * path)

This function deletes the directory given to the function from the system along with its file (marks as deleted).

Parameters
pathFull path to delete directory.
Returns
MTSTATUS Status code.

Definition at line 122 of file vfs.c.

◆ vfs_write()

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.

Parameters
pathThe full path of the file to create
dataA pointer to the data to write.
sizeThe number of bytes to write
write_modeWhether to APPEND or CREATE/REPLACE the file. (in FS_WRITE_MODES enum)
Returns
MTSTATUS Status Code

Definition at line 94 of file vfs.c.

Variable Documentation

◆ fat32_driver

FS_DRIVER fat32_driver
Initial value:
= {
.init = fat32_fs_init,
.read = fat32_read_file,
.write = fat32_write_file,
.delete = fat32_delete_file,
.is_dir_empty = fat32_directory_is_empty,
.listrootdir = fat32_list_root,
}
MTSTATUS fat32_create_directory(const char *path)
Creates a new directory (/testdir/ or /testdir are both allowed to create 'testdir' inside of 'root')
Definition fat32.c:1047
MTSTATUS fat32_list_directory(const char *path, char *listings, size_t max_len)
Lists the directory given.
Definition fat32.c:1579
MTSTATUS fat32_delete_directory(const char *path)
This function deletes the directory given to the function from the system.
Definition fat32.c:1922
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.
Definition fat32.c:921
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.
Definition fat32.c:1275
MTSTATUS fat32_delete_file(const char *path)
This function deletes the file given to the function from the system.
Definition fat32.c:1954
void fat32_list_root(void)
Definition fat32.c:769
bool fat32_directory_is_empty(const char *path)
This function returns if the directory given to the function is empty (e.g, has only '....
Definition fat32.c:1663

Definition at line 30 of file vfs.c.