GitOS
Operating system exercise
|
#include "file.h"
#include <stdint.h>
#include <common/assert.h>
#include "kernel.h"
#include "common/string.h"
#include "common/status.h"
#include "memory/memory.h"
#include "memory/heap/kheap.h"
#include "Path.hpp"
Functions | |
void | fs_insert_filesystem (struct filesystem *filesystem) |
Inserts filesystem struct into internal array. | |
void | fs_init () |
Initializes internal filesystem arrays. | |
struct filesystem * | fs_resolve (struct disk *disk) |
Resolves filesystem for given disk. | |
int | fopen (const char *filename, const char *str_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) |
Variables | |
struct filesystem * | filesystems [MAX_FILESYSTEMS] |
Array holding all registered filesystems. | |
struct file_descriptor * | file_descriptors [MAX_FILEDESCRIPTORS] |
Array holding all open file descriptors. | |
struct mounted_file ** | mounted |
Array holding all mounted files. | |
int fclose | ( | int | fd | ) |
Closes file descriptor.
fd | File descriptor |
References filesystem::close, EIO, file_descriptor::filesystem, and file_descriptor::private_fs_descriptor.
int fopen | ( | const char * | filename, |
const char * | str_mode | ||
) |
Opens file.
filename | File to open |
str_mode | Open mode |
References assert, mounted_file::data, data, EINVARG, FILE_MODE_INVALID, filename, file_descriptor::filesystem, mounted_file::fs, file_descriptor::index, kfree(), kzalloc(), MAX_MOUNTED, MAX_PATH, memset(), mounted, path_part::next, filesystem::open, path_part::part, pathparser_free(), pathparser_parse(), file_descriptor::private_fs, file_descriptor::private_fs_descriptor, strcmp(), strcpy(), and strlen().
int fread | ( | void * | ptr, |
uint32_t | size, | ||
uint32_t | nmemb, | ||
int | fd | ||
) |
Reads from file.
ptr | Output buffer |
size | Size in bytes of block |
nmemb | Number of blocks to read |
fd | File descriptor |
References EINVARG, file_descriptor::filesystem, file_descriptor::private_fs, file_descriptor::private_fs_descriptor, filesystem::read, and size.
void fs_init | ( | ) |
Initializes internal filesystem arrays.
References file_descriptors, filesystems, kzalloc(), MAX_MOUNTED, memset(), and mounted.
void fs_insert_filesystem | ( | struct filesystem * | filesystem | ) |
Inserts filesystem struct into internal array.
filesystem |
References fs, kernel_panic(), kprintf(), and filesystem::name.
struct filesystem * fs_resolve | ( | struct disk * | disk | ) |
Resolves filesystem for given disk.
disk | Disk to resolve |
References ALL_OK, filesystems, disk::fs_private, disk::id, kprintf(), MAX_FILESYSTEMS, mount(), filesystem::name, and filesystem::resolve.
int fseek | ( | int | fd, |
int | offset, | ||
FILE_SEEK_MODE | whence | ||
) |
Seeks into file.
fd | File descriptor |
offset | Seek offset |
whence | File seek mode (SEEK_SET for absolute, SEEK_CUR for relative) |
References EIO, file_descriptor::filesystem, offset, file_descriptor::private_fs_descriptor, and filesystem::seek.
int fstat | ( | int | fd, |
struct file_stat * | stat | ||
) |
Returns file status.
fd | File descriptor |
stat | Output file status struct |
References EIO, file_descriptor::filesystem, file_descriptor::private_fs_descriptor, and filesystem::stat.
int fwrite | ( | void * | ptr, |
uint32_t | size, | ||
uint32_t | nmemb, | ||
int | fd | ||
) |
Writes to file.
ptr | Input buffer |
size | Size in bytes of block |
nmemb | Number of blocks to read |
fd | File descriptor |
References EINVARG, file_descriptor::filesystem, file_descriptor::private_fs, file_descriptor::private_fs_descriptor, size, and filesystem::write.
void mount | ( | const char * | filename, |
struct filesystem * | fs, | ||
void * | data | ||
) |
References mounted_file::data, data, filename, mounted_file::filename, mounted_file::fs, fs, kdebug, kernel_panic(), kzalloc(), MAX_MOUNTED, and mounted.
struct file_descriptor* file_descriptors[MAX_FILEDESCRIPTORS] |
Array holding all open file descriptors.
struct filesystem* filesystems[MAX_FILESYSTEMS] |
Array holding all registered filesystems.
struct mounted_file** mounted |
Array holding all mounted files.