bunch of work on tcp:
[newos.git] / include / kernel / vfs.h
blobc8ee3b5c9916605459ae7772073b9d73a07798f6
1 /*
2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #ifndef _KERNEL_VFS_H
6 #define _KERNEL_VFS_H
8 #include <kernel/kernel.h>
9 #include <boot/stage2.h>
11 #define DEFAULT_FD_TABLE_SIZE 128
12 #define MAX_FD_TABLE_SIZE 2048
14 typedef enum {
15 STREAM_TYPE_ANY = 0,
16 STREAM_TYPE_FILE,
17 STREAM_TYPE_DIR,
18 STREAM_TYPE_DEVICE
19 } stream_type;
21 typedef enum {
22 SEEK_SET = 0,
23 SEEK_CUR,
24 SEEK_END
25 } seek_type;
27 typedef void * fs_cookie;
28 typedef void * file_cookie;
29 typedef void * fs_vnode;
31 typedef struct iovec {
32 void *start;
33 size_t len;
34 } iovec;
36 typedef struct iovecs {
37 size_t num;
38 size_t total_len;
39 iovec vec[0];
40 } iovecs;
42 /* macro to allocate a iovec array on the stack */
43 #define IOVECS(name, size) \
44 uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \
45 iovecs *name = (iovecs *)_##name
47 struct file_stat {
48 vnode_id vnid;
49 stream_type type;
50 off_t size;
53 #if 0
54 struct fs_calls {
55 int (*fs_mount)(void **fs_cookie, void *flags, void *covered_vnode, fs_id id, void **priv_vnode_root);
56 int (*fs_unmount)(void *fs_cookie);
57 int (*fs_register_mountpoint)(void *fs_cookie, void *vnode, void *redir_vnode);
58 int (*fs_unregister_mountpoint)(void *fs_cookie, void *vnode);
59 int (*fs_dispose_vnode)(void *fs_cookie, void *vnode);
60 int (*fs_open)(void *fs_cookie, void *base_vnode, const char *path, const char *stream, stream_type stream_type, void **vnode, void **cookie, struct redir_struct *redir);
61 int (*fs_seek)(void *fs_cookie, void *vnode, void *cookie, off_t pos, seek_type seek_type);
62 int (*fs_read)(void *fs_cookie, void *vnode, void *cookie, void *buf, off_t pos, size_t *len);
63 int (*fs_write)(void *fs_cookie, void *vnode, void *cookie, const void *buf, off_t pos, size_t *len);
64 int (*fs_ioctl)(void *fs_cookie, void *vnode, void *cookie, int op, void *buf, size_t len);
65 int (*fs_close)(void *fs_cookie, void *vnode, void *cookie);
66 int (*fs_create)(void *fs_cookie, void *base_vnode, const char *path, const char *stream, stream_type stream_type, struct redir_struct *redir);
67 int (*fs_stat)(void *fs_cookie, void *base_vnode, const char *path, const char *stream, stream_type stream_type, struct vnode_stat *stat, struct redir_struct *redir);
69 #endif
71 struct fs_calls {
72 int (*fs_mount)(fs_cookie *fs, fs_id id, const char *device, void *args, vnode_id *root_vnid);
73 int (*fs_unmount)(fs_cookie fs);
74 int (*fs_sync)(fs_cookie fs);
76 int (*fs_lookup)(fs_cookie fs, fs_vnode dir, const char *name, vnode_id *id);
78 int (*fs_getvnode)(fs_cookie fs, vnode_id id, fs_vnode *v, bool r);
79 int (*fs_putvnode)(fs_cookie fs, fs_vnode v, bool r);
80 int (*fs_removevnode)(fs_cookie fs, fs_vnode v, bool r);
82 int (*fs_open)(fs_cookie fs, fs_vnode v, file_cookie *cookie, stream_type st, int oflags);
83 int (*fs_close)(fs_cookie fs, fs_vnode v, file_cookie cookie);
84 int (*fs_freecookie)(fs_cookie fs, fs_vnode v, file_cookie cookie);
85 int (*fs_fsync)(fs_cookie fs, fs_vnode v);
87 ssize_t (*fs_read)(fs_cookie fs, fs_vnode v, file_cookie cookie, void *buf, off_t pos, ssize_t len);
88 ssize_t (*fs_write)(fs_cookie fs, fs_vnode v, file_cookie cookie, const void *buf, off_t pos, ssize_t len);
89 int (*fs_seek)(fs_cookie fs, fs_vnode v, file_cookie cookie, off_t pos, seek_type st);
90 int (*fs_ioctl)(fs_cookie fs, fs_vnode v, file_cookie cookie, int op, void *buf, size_t len);
92 int (*fs_canpage)(fs_cookie fs, fs_vnode v);
93 ssize_t (*fs_readpage)(fs_cookie fs, fs_vnode v, iovecs *vecs, off_t pos);
94 ssize_t (*fs_writepage)(fs_cookie fs, fs_vnode v, iovecs *vecs, off_t pos);
96 int (*fs_create)(fs_cookie fs, fs_vnode dir, const char *name, stream_type st, void *create_args, vnode_id *new_vnid);
97 int (*fs_unlink)(fs_cookie fs, fs_vnode dir, const char *name);
98 int (*fs_rename)(fs_cookie fs, fs_vnode olddir, const char *oldname, fs_vnode newdir, const char *newname);
100 int (*fs_rstat)(fs_cookie fs, fs_vnode v, struct file_stat *stat);
101 int (*fs_wstat)(fs_cookie fs, fs_vnode v, struct file_stat *stat, int stat_mask);
104 int vfs_init(kernel_args *ka);
105 int vfs_bootstrap_all_filesystems(void);
106 int vfs_register_filesystem(const char *name, struct fs_calls *calls);
107 void *vfs_new_ioctx(void *parent_ioctx);
108 int vfs_free_ioctx(void *ioctx);
109 int vfs_test(void);
111 struct rlimit;
112 int vfs_getrlimit(int resource, struct rlimit * rlp);
113 int vfs_setrlimit(int resource, const struct rlimit * rlp);
115 image_id vfs_load_fs_module(const char *path);
117 /* calls needed by fs internals */
118 int vfs_get_vnode(fs_id fsid, vnode_id vnid, fs_vnode *v);
119 int vfs_put_vnode(fs_id fsid, vnode_id vnid);
120 int vfs_remove_vnode(fs_id fsid, vnode_id vnid);
122 /* calls needed by the VM for paging */
123 int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode);
124 int vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode);
125 int vfs_put_vnode_ptr(void *vnode);
126 void vfs_vnode_acquire_ref(void *vnode);
127 void vfs_vnode_release_ref(void *vnode);
128 ssize_t vfs_canpage(void *vnode);
129 ssize_t vfs_readpage(void *vnode, iovecs *vecs, off_t pos);
130 ssize_t vfs_writepage(void *vnode, iovecs *vecs, off_t pos);
131 void *vfs_get_cache_ptr(void *vnode);
132 int vfs_set_cache_ptr(void *vnode, void *cache);
134 /* calls kernel code should make if it's trying strange stuff */
135 int vfs_mount(char *path, const char *device, const char *fs_name, void *args, bool kernel);
136 int vfs_unmount(char *path, bool kernel);
137 int vfs_sync(void);
138 int vfs_open(char *path, stream_type st, int omode, bool kernel);
139 int vfs_seek(int fd, off_t pos, seek_type seek_type, bool kernel);
140 ssize_t vfs_read(int fd, void *buf, off_t pos, ssize_t len, bool kernel);
141 ssize_t vfs_write(int fd, const void *buf, off_t pos, ssize_t len, bool kernel);
142 int vfs_ioctl(int fd, int op, void *buf, size_t len, bool kernel);
143 int vfs_close(int fd, bool kernel);
144 int vfs_fsync(int fd, bool kernel);
145 int vfs_create(char *path, stream_type stream_type, void *args, bool kernel);
146 int vfs_unlink(char *path, bool kernel);
147 int vfs_rename(char *path, char *newpath, bool kernel);
148 int vfs_rstat(char *path, struct file_stat *stat, bool kernel);
149 int vfs_wstat(char *path, struct file_stat *stat, int stat_mask, bool kernel);
151 /* calls kernel code should make for file I/O */
152 int sys_mount(const char *path, const char *device, const char *fs_name, void *args);
153 int sys_unmount(const char *path);
154 int sys_sync(void);
155 int sys_open(const char *path, stream_type st, int omode);
156 int sys_close(int fd);
157 int sys_fsync(int fd);
158 ssize_t sys_read(int fd, void *buf, off_t pos, ssize_t len);
159 ssize_t sys_write(int fd, const void *buf, off_t pos, ssize_t len);
160 int sys_seek(int fd, off_t pos, seek_type seek_type);
161 int sys_ioctl(int fd, int op, void *buf, size_t len);
162 int sys_create(const char *path, stream_type stream_type);
163 int sys_unlink(const char *path);
164 int sys_rename(const char *oldpath, const char *newpath);
165 int sys_rstat(const char *path, struct file_stat *stat);
166 int sys_wstat(const char *path, struct file_stat *stat, int stat_mask);
167 char *sys_getcwd(char *buf, size_t size);
168 int sys_setcwd(const char* path);
169 int sys_dup(int fd);
170 int sys_dup2(int ofd, int nfd);
172 /* calls the syscall dispatcher should use for user file I/O */
173 int user_mount(const char *path, const char *device, const char *fs_name, void *args);
174 int user_unmount(const char *path);
175 int user_sync(void);
176 int user_open(const char *path, stream_type st, int omode);
177 int user_close(int fd);
178 int user_fsync(int fd);
179 ssize_t user_read(int fd, void *buf, off_t pos, ssize_t len);
180 ssize_t user_write(int fd, const void *buf, off_t pos, ssize_t len);
181 int user_seek(int fd, off_t pos, seek_type seek_type);
182 int user_ioctl(int fd, int op, void *buf, size_t len);
183 int user_create(const char *path, stream_type stream_type);
184 int user_unlink(const char *path);
185 int user_rename(const char *oldpath, const char *newpath);
186 int user_rstat(const char *path, struct file_stat *stat);
187 int user_wstat(const char *path, struct file_stat *stat, int stat_mask);
188 int user_getcwd(char *buf, size_t size);
189 int user_setcwd(const char* path);
190 int user_dup(int fd);
191 int user_dup2(int ofd, int nfd);
193 #endif