kernel/file.h (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#ifndef FILE_H
#define FILE_H
#include <stdint.h>
#include "mm/paging.h"
typedef uint32_t fpos_t;
typedef int32_t off_t;
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
struct file;
struct file_operations;
typedef struct file file_t;
typedef struct file_operations file_operations_t;
struct file {
file_operations_t *fops;
uint32_t stdio_id;
uint32_t fat_cluster;
fpos_t pos;
size_t size;
};
struct file_operations {
int (*open)(const char *pathname, int flags);
int (*openat)(file_t *root, file_t *handle, const char *fname, int flags);
ssize_t (*read)(file_t *file, char *buffer, size_t size);
ssize_t (*write)(file_t *file, const char *buffer, size_t size);
int (*dir_next)(file_t *file, int index, char *fname_buffer);
off_t (*lseek)(file_t *file, off_t offset, int whence);
off_t (*tell)(file_t *file);
};
int file_init();
int file_open(const char *pathname, int flags);
int file_openat(int fd, const char *fname, int flags);
ssize_t file_read(int fd, char *buffer, size_t size);
ssize_t file_write(int fd, char *buffer, size_t size);
int file_dir_next(int fd, int index, char *fname_buffer);
off_t file_lseek(int fd, off_t offset, int whence);
off_t file_tell(int fd);
#endif