2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
8 #include <kernel/kernel.h>
9 #include <boot/stage2.h>
11 #define DEFAULT_FD_TABLE_SIZE 128
12 #define MAX_FD_TABLE_SIZE 2048
27 typedef void * fs_cookie
;
28 typedef void * file_cookie
;
29 typedef void * fs_vnode
;
31 typedef struct iovec
{
36 typedef struct 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
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
);
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
);
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 for file I/O */
135 int sys_mount(const char *path
, const char *device
, const char *fs_name
, void *args
);
136 int sys_unmount(const char *path
);
138 int sys_open(const char *path
, stream_type st
, int omode
);
139 int sys_close(int fd
);
140 int sys_fsync(int fd
);
141 ssize_t
sys_read(int fd
, void *buf
, off_t pos
, ssize_t len
);
142 ssize_t
sys_write(int fd
, const void *buf
, off_t pos
, ssize_t len
);
143 int sys_seek(int fd
, off_t pos
, seek_type seek_type
);
144 int sys_ioctl(int fd
, int op
, void *buf
, size_t len
);
145 int sys_create(const char *path
, stream_type stream_type
);
146 int sys_unlink(const char *path
);
147 int sys_rename(const char *oldpath
, const char *newpath
);
148 int sys_rstat(const char *path
, struct file_stat
*stat
);
149 int sys_wstat(const char *path
, struct file_stat
*stat
, int stat_mask
);
150 char *sys_getcwd(char *buf
, size_t size
);
151 int sys_setcwd(const char* path
);
153 int sys_dup2(int ofd
, int nfd
);
155 /* calls the syscall dispatcher should use for user file I/O */
156 int user_mount(const char *path
, const char *device
, const char *fs_name
, void *args
);
157 int user_unmount(const char *path
);
159 int user_open(const char *path
, stream_type st
, int omode
);
160 int user_close(int fd
);
161 int user_fsync(int fd
);
162 ssize_t
user_read(int fd
, void *buf
, off_t pos
, ssize_t len
);
163 ssize_t
user_write(int fd
, const void *buf
, off_t pos
, ssize_t len
);
164 int user_seek(int fd
, off_t pos
, seek_type seek_type
);
165 int user_ioctl(int fd
, int op
, void *buf
, size_t len
);
166 int user_create(const char *path
, stream_type stream_type
);
167 int user_unlink(const char *path
);
168 int user_rename(const char *oldpath
, const char *newpath
);
169 int user_rstat(const char *path
, struct file_stat
*stat
);
170 int user_wstat(const char *path
, struct file_stat
*stat
, int stat_mask
);
171 int user_getcwd(char *buf
, size_t size
);
172 int user_setcwd(const char* path
);
173 int user_dup(int fd
);
174 int user_dup2(int ofd
, int nfd
);