2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018-2019 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
23 /* device ids for virtual filesystems */
39 enum { FSNODE_FILE, FSNODE_DIR };
41 enum { FSSEEK_SET, FSSEEK_CUR, FSSEEK_END };
53 struct fs_operations {
54 void (*destroy)(struct filesys *fs);
56 struct fs_node *(*open)(struct filesys *fs, const char *path, unsigned int flags);
57 void (*close)(struct fs_node *node);
59 long (*fsize)(struct fs_node *node);
60 int (*seek)(struct fs_node *node, int offs, int whence);
61 long (*tell)(struct fs_node *node);
62 int (*read)(struct fs_node *node, void *buf, int sz);
63 int (*write)(struct fs_node *node, void *buf, int sz);
65 int (*rewinddir)(struct fs_node *node);
66 struct fs_dirent *(*readdir)(struct fs_node *node);
68 int (*rename)(struct fs_node *node, const char *name);
69 int (*remove)(struct fs_node *node);
75 struct fs_operations *fsop;
94 struct filesys *rootfs;
95 struct fs_node *cwdnode; /* current working directory node */
97 struct filesys *fs_mount(int dev, uint64_t start, uint64_t size, struct fs_node *parent);
99 int fs_chdir(const char *path);
100 char *fs_getcwd(void);
102 struct fs_node *fs_open(const char *path, unsigned int flags);
103 int fs_close(struct fs_node *node);
105 int fs_rename(struct fs_node *node, const char *name);
106 int fs_remove(struct fs_node *node);
108 long fs_filesize(struct fs_node *node);
109 int fs_seek(struct fs_node *node, int offs, int whence);
110 long fs_tell(struct fs_node *node);
111 int fs_read(struct fs_node *node, void *buf, int sz);
112 int fs_write(struct fs_node *node, void *buf, int sz);
114 int fs_rewinddir(struct fs_node *node);
115 struct fs_dirent *fs_readdir(struct fs_node *node);
117 /* fs utility functions */
118 char *fs_path_skipsep(char *s);
120 /* copies the current name into the namebuf, and returns a pointer to the
121 * start of the next path component.
123 char *fs_path_next(char *s, char *namebuf, int bufsz);