X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=src%2Ffs.h;fp=src%2Ffs.h;h=f05f29a6ea4ce411fd718c17ec650aa5f3cbcf4a;hp=0000000000000000000000000000000000000000;hb=137aca58851528e77004dc3909826f24bbdbde87;hpb=81c11bdd80190ec319a82b0402173cfb65fcbf72 diff --git a/src/fs.h b/src/fs.h new file mode 100644 index 0000000..f05f29a --- /dev/null +++ b/src/fs.h @@ -0,0 +1,125 @@ +/* +pcboot - bootable PC demo/game kernel +Copyright (C) 2018-2019 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY, without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#ifndef FS_H_ +#define FS_H_ + +#include + +/* device ids for virtual filesystems */ +enum { + DEV_FLOPPY0 = 0, + DEV_FLOPPY1 = 1, + DEV_HDD0 = 0x80, + DEV_HDD1 = 0x81, + DEV_MEMDISK = 0x10000 +}; + +enum { + FSTYPE_MEM, + FSTYPE_FAT, + + NUM_FSTYPES +}; + +enum { FSNODE_FILE, FSNODE_DIR }; + +enum { FSSEEK_SET, FSSEEK_CUR, FSSEEK_END }; + +enum { + FSO_CREATE = 1, + FSO_DIR = 2, + FSO_EXCL = 4 +}; + +struct filesys; +struct fs_node; +struct fs_dirent; + +struct fs_operations { + void (*destroy)(struct filesys *fs); + + struct fs_node *(*open)(struct filesys *fs, const char *path, unsigned int flags); + void (*close)(struct fs_node *node); + + long (*fsize)(struct fs_node *node); + int (*seek)(struct fs_node *node, int offs, int whence); + long (*tell)(struct fs_node *node); + int (*read)(struct fs_node *node, void *buf, int sz); + int (*write)(struct fs_node *node, void *buf, int sz); + + int (*rewinddir)(struct fs_node *node); + struct fs_dirent *(*readdir)(struct fs_node *node); + + int (*rename)(struct fs_node *node, const char *name); + int (*remove)(struct fs_node *node); +}; + +struct filesys { + int type; + char *name; + struct fs_operations *fsop; + void *data; +}; + +struct fs_node { + struct filesys *fs; + int type; + void *data; + + struct filesys *mnt; +}; + +struct fs_dirent { + char *name; + void *data; + int type; + long fsize; +}; + +struct filesys *rootfs; +struct fs_node *cwdnode; /* current working directory node */ + +struct filesys *fs_mount(int dev, uint64_t start, uint64_t size, struct fs_node *parent); + +int fs_chdir(const char *path); +char *fs_getcwd(void); + +struct fs_node *fs_open(const char *path, unsigned int flags); +int fs_close(struct fs_node *node); + +int fs_rename(struct fs_node *node, const char *name); +int fs_remove(struct fs_node *node); + +long fs_filesize(struct fs_node *node); +int fs_seek(struct fs_node *node, int offs, int whence); +long fs_tell(struct fs_node *node); +int fs_read(struct fs_node *node, void *buf, int sz); +int fs_write(struct fs_node *node, void *buf, int sz); + +int fs_rewinddir(struct fs_node *node); +struct fs_dirent *fs_readdir(struct fs_node *node); + +/* fs utility functions */ +char *fs_path_skipsep(char *s); + +/* copies the current name into the namebuf, and returns a pointer to the + * start of the next path component. + */ +char *fs_path_next(char *s, char *namebuf, int bufsz); + +#endif /* FS_H_ */