GitOS
Loading...
Searching...
No Matches
file.h File Reference
#include <stdint.h>
#include "Path.hpp"
#include "drivers/disk/disk.h"

Go to the source code of this file.

Data Structures

struct  file_descriptor
struct  file_stat
struct  filesystem
struct  mounted_file

Macros

#define MAX_FILESYSTEMS   12
#define MAX_FILEDESCRIPTORS   1024
#define MAX_FILESYSTEM_NAME   20
#define MAX_MOUNTED   16384

Typedefs

typedef unsigned int FILE_SEEK_MODE
typedef unsigned int FILE_MODE
typedef unsigned int FILE_STAT_FLAGS
typedef int(* FS_RESOLVE_FUNCTION) (struct disk *disk)
typedef void *(* FS_OPEN_FUNCTION) (void *private_fs, struct path_part *path, FILE_MODE mode)
typedef int(* FS_READ_FUNCTION) (void *private_fs, void *descriptor, uint32_t size, uint32_t nmemb, char *out)
typedef int(* FS_SEEK_FUNCTION) (void *private_fs, uint32_t offset, FILE_SEEK_MODE seek_mode)
typedef int(* FS_STAT_FUNCTION) (void *private_fs, struct file_stat *stat)
typedef int(* FS_CLOSE_FUNCTION) (void *private_fs)
typedef int(* FS_WRITE_FUNCTION) (void *private_fs, void *descriptor, uint32_t size, uint32_t nmemb, char *in)

Enumerations

enum  FILE_SEEK_MODES { SEEK_SET , SEEK_CUR , SEEK_END }
enum  FILE_OPEN_MODES { FILE_MODE_READ , FILE_MODE_WRITE , FILE_MODE_APPEND , FILE_MODE_INVALID }
enum  FILE_STAT_FLAGS_ENUM { FILE_STAT_READ_ONLY = 0b00000001 , FILE_STAT_FOLDER = 0b00000010 }

Functions

void fs_init ()
 Initializes internal filesystem arrays.
void fs_insert_filesystem (struct filesystem *filesystem)
 Inserts filesystem struct into internal array.
struct filesystemfs_resolve (struct disk *disk)
 Resolves filesystem for given disk.
int fopen (const char *filename, const char *mode)
 Opens file.
int fread (void *ptr, uint32_t size, uint32_t nmemb, int fd)
 Reads from file.
int fwrite (void *ptr, uint32_t size, uint32_t nmemb, int fd)
 Writes to file.
int fseek (int fd, int offset, FILE_SEEK_MODE whence)
 Seeks into file.
int fstat (int fd, struct file_stat *stat)
 Returns file status.
int fclose (int fd)
 Closes file descriptor.
void mount (const char *filename, struct filesystem *fs, void *data)

Macro Definition Documentation

◆ MAX_FILEDESCRIPTORS

#define MAX_FILEDESCRIPTORS   1024

◆ MAX_FILESYSTEM_NAME

#define MAX_FILESYSTEM_NAME   20

◆ MAX_FILESYSTEMS

#define MAX_FILESYSTEMS   12

◆ MAX_MOUNTED

#define MAX_MOUNTED   16384

Typedef Documentation

◆ FILE_MODE

typedef unsigned int FILE_MODE

◆ FILE_SEEK_MODE

typedef unsigned int FILE_SEEK_MODE

◆ FILE_STAT_FLAGS

typedef unsigned int FILE_STAT_FLAGS

◆ FS_CLOSE_FUNCTION

typedef int(* FS_CLOSE_FUNCTION) (void *private_fs)

◆ FS_OPEN_FUNCTION

typedef void *(* FS_OPEN_FUNCTION) (void *private_fs, struct path_part *path, FILE_MODE mode)

◆ FS_READ_FUNCTION

typedef int(* FS_READ_FUNCTION) (void *private_fs, void *descriptor, uint32_t size, uint32_t nmemb, char *out)

◆ FS_RESOLVE_FUNCTION

typedef int(* FS_RESOLVE_FUNCTION) (struct disk *disk)

◆ FS_SEEK_FUNCTION

typedef int(* FS_SEEK_FUNCTION) (void *private_fs, uint32_t offset, FILE_SEEK_MODE seek_mode)

◆ FS_STAT_FUNCTION

typedef int(* FS_STAT_FUNCTION) (void *private_fs, struct file_stat *stat)

◆ FS_WRITE_FUNCTION

typedef int(* FS_WRITE_FUNCTION) (void *private_fs, void *descriptor, uint32_t size, uint32_t nmemb, char *in)

Enumeration Type Documentation

◆ FILE_OPEN_MODES

Enumerator
FILE_MODE_READ 
FILE_MODE_WRITE 
FILE_MODE_APPEND 
FILE_MODE_INVALID 

◆ FILE_SEEK_MODES

Enumerator
SEEK_SET 

Absolute position from 0.

SEEK_CUR 

Relative position.

SEEK_END 

Absolute position from the end of file.

◆ FILE_STAT_FLAGS_ENUM

Enumerator
FILE_STAT_READ_ONLY 
FILE_STAT_FOLDER 

Function Documentation

◆ fclose()

int fclose ( int fd)

Closes file descriptor.

Parameters
fdFile descriptor
Returns
int Status

◆ fopen()

int fopen ( const char * filename,
const char * str_mode )

Opens file.

Parameters
filenameFile to open
str_modeOpen mode
Returns
int Status

◆ fread()

int fread ( void * ptr,
uint32_t size,
uint32_t nmemb,
int fd )

Reads from file.

Parameters
ptrOutput buffer
sizeSize in bytes of block
nmembNumber of blocks to read
fdFile descriptor
Returns
int Status

◆ fs_init()

void fs_init ( )

Initializes internal filesystem arrays.

References file_descriptors, filesystems, kzalloc(), MAX_MOUNTED, memset(), and mounted.

◆ fs_insert_filesystem()

void fs_insert_filesystem ( struct filesystem * filesystem)

Inserts filesystem struct into internal array.

Parameters
filesystem

References fs, kernel_panic(), kprintf(), and filesystem::name.

◆ fs_resolve()

struct filesystem * fs_resolve ( struct disk * disk)

Resolves filesystem for given disk.

Parameters
diskDisk to resolve
Returns
struct filesystem* Resolved filesystem, 0 if not resolved

References ALL_OK, filesystems, disk::fs_private, disk::id, kprintf(), MAX_FILESYSTEMS, mount(), and filesystem::resolve.

◆ fseek()

int fseek ( int fd,
int offset,
FILE_SEEK_MODE whence )

Seeks into file.

Parameters
fdFile descriptor
offsetSeek offset
whenceFile seek mode (SEEK_SET for absolute, SEEK_CUR for relative)
Returns
int Status

◆ fstat()

int fstat ( int fd,
struct file_stat * stat )

Returns file status.

Parameters
fdFile descriptor
statOutput file status struct
Returns
int Status

◆ fwrite()

int fwrite ( void * ptr,
uint32_t size,
uint32_t nmemb,
int fd )

Writes to file.

Parameters
ptrInput buffer
sizeSize in bytes of block
nmembNumber of blocks to read
fdFile descriptor
Returns
int Status

◆ mount()

void mount ( const char * filename,
struct filesystem * fs,
void * data )