550W Document
550W, a high-end OS
|
#include <asm/pgtable.h>
#include <asm/sbi.h>
#include <arch/riscv/include/asm/io.h>
#include <drivers/screen/screen.h>
#include <drivers/virtio/virtio.h>
#include <fs/fat32.h>
#include <fs/file.h>
#include <fs/fs.h>
#include <lib/stdio.h>
#include <lib/string.h>
#include <os/mm.h>
#include <os/pcb.h>
#include <os/sync.h>
#include <os/time.h>
#include <user/user_programs.h>
类 | |
struct | fd_mbox |
宏定义 | |
#define | END_OF_DIR 0x00 |
#define | EMPTY_ENTRY 0xE5 |
类型定义 | |
typedef struct fd_mbox | fd_mbox_t |
函数 | |
uint32_t | fat32_fcluster2size (uint32_t first) |
void * | read_whole_dir (uint32_t first, uint32_t size) |
read whle file by first cluster 更多... | |
int | write_whole_dir (uint32_t first, void *data, uint32_t write) |
write whole file by first cluster 更多... | |
uint32_t | alloc_cluster (uint32_t first) |
alloc a nea cluster for a file/dir 更多... | |
void | filename2path (char *path, char *name, const char *filename) |
divede filename into path and name 更多... | |
char * | path2name (char *path, char *name) |
int | is_end_of_dir (dentry_t *entry) |
int | is_empty_entry (dentry_t *entry) |
int | ldentry2name (dentry_t *entry, char *name) |
get name from ldentry, return offset of these lentry 更多... | |
int | sdentry2name (dentry_t *entry, char *name) |
get name from sdentry, return offset(1) of this entry 更多... | |
int | dentry2name (dentry_t *entry, char *name) |
get name from dentry, return offset of this whole entry 更多... | |
int | fat32_name2offset (char *name, dentry_t *entry) |
int | fat32_name2dir (char *name, dir_info_t *now) |
search file in dir, fail then return 0, other means hit 更多... | |
int | fat32_new_dentry (dentry_t *entry, uint32_t flags, int len, char *name) |
set new dentry 更多... | |
int | alloc_dentry (dentry_t **dtable, char *name, mode_t flags, mode_t mode, dir_info_t *now) |
create a new dentry in dtable, return sdentry offest of new entry, -1 means fail 更多... | |
int | destroy_dentry (dentry_t *dtable, int offset) |
destroy an dir entry, include LFN and sn 更多... | |
int | fat32_path2dir (char *path, dir_info_t *new, dir_info_t now) |
fail return 0 更多... | |
int | fat32_dentry2fd (dentry_t *entry, fd_t *file, mode_t flags, mode_t mode, char *name) |
int | fs_init () |
long | sys_getcwd (char *buf, size_t size) |
int | sys_pipe2 (int *fd, mode_t flags) |
allocate pipe to fd[2]. 更多... | |
int | sys_dup (int old) |
copy a fd and return the new one 更多... | |
int | sys_dup3 (int old, int new, mode_t flags) |
copy a fd and return the new one 更多... | |
int | sys_mkdirat (int dirfd, const char *path_0, mode_t mode) |
mk dir at patch, success 0 fail -1 更多... | |
int | sys_chdir (char *path) |
change dir by patch, fail return -1 更多... | |
int | sys_getdents64 (int fd, dirent64_t *dirent, size_t len) |
int | sys_openat (int dirfd, const char *filename, mode_t flags, mode_t mode) |
open a file with path/cwd+path/dirfd+path 更多... | |
int | sys_close (int fd) |
int | sys_linkat (int old, const char *oldname, int newd, const char *newname, mode_t flags) |
int | sys_unlinkat (int dirfd, const char *path_0, mode_t flags) |
rm file directed by path, 0 success -1 fail 更多... | |
int | sys_mount (const char *special, const char *dir, const char *type, mode_t flags, void *data) |
int | sys_umount2 (const char *special, mode_t flags) |
ssize_t | sys_read (int fd, char *buf, size_t count) |
read count bytes to buf of fd file 更多... | |
ssize_t | sys_write (int fd, const char *buf, size_t count) |
int | sys_fstat (int fd, kstat_t *statbuf) |
int | fs_load_file (const char *name, uint8_t **bin, int *len) |
load elf file in root dir, 0 success, -1 fail 更多... | |
void * | sys_mmap (void *addr, size_t length, int prot, int flags, int fd, off_t offset) |
int | sys_munmap (void *addr, size_t length) |
bool | fs_check_file_existence (const char *name) |
变量 | |
fat32_t | fat |
dir_info_t | root_dir = {.name = "/\0"} |
dir_info_t | cur_dir = {.name = "/\0"} |
fd_mbox_t | fd_mbox_map [MAX_FD] |
#define EMPTY_ENTRY 0xE5 |
#define END_OF_DIR 0x00 |
uint32_t alloc_cluster | ( | uint32_t | first | ) |
alloc a nea cluster for a file/dir
first | id of first cluster |
int alloc_dentry | ( | dentry_t ** | dtable, |
char * | name, | ||
mode_t | flags, | ||
mode_t | mode, | ||
dir_info_t * | now | ||
) |
create a new dentry in dtable, return sdentry offest of new entry, -1 means fail
dtable | whole table of dir |
name | file name |
now | now dir info |
flags | create file(RW) or dir by O_DIRECTORY |
int dentry2name | ( | dentry_t * | entry, |
char * | name | ||
) |
get name from dentry, return offset of this whole entry
name | file name |
entry | first entry of file |
int destroy_dentry | ( | dentry_t * | dtable, |
int | offset | ||
) |
destroy an dir entry, include LFN and sn
dtable | whole table of dir |
offset | offset for sn |
uint32_t fat32_fcluster2size | ( | uint32_t | first | ) |
int fat32_name2dir | ( | char * | name, |
dir_info_t * | now | ||
) |
search file in dir, fail then return 0, other means hit
name | file name |
now | now dir info |
int fat32_name2offset | ( | char * | name, |
dentry_t * | entry | ||
) |
int fat32_new_dentry | ( | dentry_t * | entry, |
uint32_t | flags, | ||
int | len, | ||
char * | name | ||
) |
set new dentry
name | file name |
flags | file flags |
len | length of LFN |
int fat32_path2dir | ( | char * | path, |
dir_info_t * | new, | ||
dir_info_t | now | ||
) |
fail return 0
path | buffer for dir path |
new | target dir info |
now | now dir info |
void filename2path | ( | char * | path, |
char * | name, | ||
const char * | filename | ||
) |
divede filename into path and name
path | buffer for dir path |
name | buffer file name |
filename | filename with path |
bool fs_check_file_existence | ( | const char * | name | ) |
int fs_init | ( | ) |
int fs_load_file | ( | const char * | name, |
uint8_t ** | bin, | ||
int * | len | ||
) |
load elf file in root dir, 0 success, -1 fail
name | elf file should be loaded |
int is_empty_entry | ( | dentry_t * | entry | ) |
int is_end_of_dir | ( | dentry_t * | entry | ) |
int ldentry2name | ( | dentry_t * | entry, |
char * | name | ||
) |
get name from ldentry, return offset of these lentry
name | file name |
entry | first entry of LFN entry |
char* path2name | ( | char * | path, |
char * | name | ||
) |
path | buffer for dir path |
name | file in now dir |
len | name len |
void* read_whole_dir | ( | uint32_t | first, |
uint32_t | size | ||
) |
read whle file by first cluster
first | id of first cluster |
int sdentry2name | ( | dentry_t * | entry, |
char * | name | ||
) |
get name from sdentry, return offset(1) of this entry
name | file name |
entry | first entry of file |
int sys_chdir | ( | char * | path | ) |
change dir by patch, fail return -1
path | buffer for dir path |
int sys_close | ( | int | fd | ) |
int sys_dup | ( | int | old | ) |
copy a fd and return the new one
old | old fd |
int sys_dup3 | ( | int | old, |
int | new, | ||
mode_t | flags | ||
) |
copy a fd and return the new one
old | old fd |
new | new fd |
int sys_fstat | ( | int | fd, |
kstat_t * | statbuf | ||
) |
long sys_getcwd | ( | char * | buf, |
size_t | size | ||
) |
buf | buffer for cur_dir path |
size | bytes of buf |
int sys_getdents64 | ( | int | fd, |
dirent64_t * | dirent, | ||
size_t | len | ||
) |
int sys_linkat | ( | int | old, |
const char * | oldname, | ||
int | newd, | ||
const char * | newname, | ||
mode_t | flags | ||
) |
int sys_mkdirat | ( | int | dirfd, |
const char * | path_0, | ||
mode_t | mode | ||
) |
mk dir at patch, success 0 fail -1
dir_fd | mkdir at this dir |
flag | AT_FDCWD means mkdir at cwd |
path | path if from '/', other just means dir name |
int sys_mount | ( | const char * | special, |
const char * | dir, | ||
const char * | type, | ||
mode_t | flags, | ||
void * | data | ||
) |
int sys_munmap | ( | void * | addr, |
size_t | length | ||
) |
open a file with path/cwd+path/dirfd+path
fd | file descripter |
buf | bytes buf |
count | read len |
int sys_pipe2 | ( | int * | fd, |
mode_t | flags | ||
) |
allocate pipe to fd[2].
fd | target fd array. |
-1 | failed 0: succeed |
read count bytes to buf of fd file
fd | file descripter |
buf | bytes buf |
count | read len |
int sys_umount2 | ( | const char * | special, |
mode_t | flags | ||
) |
int sys_unlinkat | ( | int | dirfd, |
const char * | path_0, | ||
mode_t | flags | ||
) |
rm file directed by path, 0 success -1 fail
dirfd | file descripter |
path | dile path |
count | 0 or AT_REMOVEDIR |
int write_whole_dir | ( | uint32_t | first, |
void * | data, | ||
uint32_t | write | ||
) |
write whole file by first cluster
first | id of first cluster |
write | write or not |
data | data size need to be size from first cluster? |
dir_info_t cur_dir = {.name = "/\0"} |
fat32_t fat |
dir_info_t root_dir = {.name = "/\0"} |