vm: fix a null dereference on out-of-memory
[minix.git] / servers / vfs / proto.h
blob74b4b8ab89326f5383c1bbaf573773cbaf73cf08
1 #ifndef __VFS_PROTO_H__
2 #define __VFS_PROTO_H__
4 /* Function prototypes. */
6 #include "timers.h"
7 #include "request.h"
8 #include "tll.h"
9 #include "threads.h"
10 #include <minix/rs.h>
12 /* Structs used in prototypes must be declared as such first. */
13 struct filp;
14 struct fproc;
15 struct vmnt;
16 struct vnode;
17 struct lookup;
18 struct worker_thread;
19 struct job;
21 typedef struct filp * filp_id_t;
23 /* comm.c */
24 int drv_sendrec(endpoint_t drv_e, message *reqm);
25 void fs_cancel(struct vmnt *vmp);
26 int fs_sendrec(endpoint_t fs_e, message *reqm);
27 void fs_sendmore(struct vmnt *vmp);
28 void send_work(void);
30 /* device.c */
31 int dev_open(dev_t dev, endpoint_t proc_e, int flags);
32 int dev_reopen(dev_t dev, int filp_no, int flags);
33 void dev_reply(struct dmap *dp);
34 int dev_close(dev_t dev, int filp_no);
35 int bdev_open(dev_t dev, int access);
36 int bdev_close(dev_t dev);
37 int dev_io(int op, dev_t dev, endpoint_t proc_e, void *buf, u64_t pos,
38 size_t bytes, int flags, int suspend_reopen);
39 int gen_opcl(int op, dev_t dev, endpoint_t task_nr, int flags);
40 int gen_io(endpoint_t driver_e, message *mess_ptr);
41 int asyn_io(endpoint_t drv_e, message *mess_ptr);
42 int no_dev(int op, dev_t dev, int proc, int flags);
43 int no_dev_io(int, message *);
44 int tty_opcl(int op, dev_t dev, endpoint_t proc, int flags);
45 int ctty_opcl(int op, dev_t dev, endpoint_t proc, int flags);
46 int clone_opcl(int op, dev_t dev, int proc, int flags);
47 int ctty_io(int task_nr, message *mess_ptr);
48 int do_ioctl(void);
49 void pm_setsid(endpoint_t proc_e);
50 void dev_status(endpoint_t drv_e);
51 void bdev_up(int major);
52 void cdev_up(int major);
53 endpoint_t find_suspended_ep(endpoint_t driver, cp_grant_id_t g);
54 void reopen_reply(void);
55 void open_reply(void);
57 /* dmap.c */
58 void lock_dmap(struct dmap *dp);
59 void unlock_dmap(struct dmap *dp);
60 int do_mapdriver(void);
61 void init_dmap(void);
62 void init_dmap_locks(void);
63 int dmap_driver_match(endpoint_t proc, int major);
64 void dmap_endpt_up(int proc_nr, int is_blk);
65 void dmap_unmap_by_endpt(int proc_nr);
66 struct dmap *get_dmap(endpoint_t proc_e);
67 struct dmap *get_dmap_by_major(int major);
68 int do_mapdriver(void);
69 int map_service(struct rprocpub *rpub);
70 void dmap_unmap_by_endpt(int proc_nr);
71 int map_driver(const char *label, int major, endpoint_t proc_nr, int
72 dev_style, int flags);
73 int map_service(struct rprocpub *rpub);
75 /* elf_core_dump.c */
76 void write_elf_core_file(struct filp *f, int csig, char *exe_name);
78 /* exec.c */
79 int pm_exec(endpoint_t proc_e, vir_bytes path, size_t path_len, vir_bytes frame,
80 size_t frame_len, vir_bytes *pc, vir_bytes *newsp, int flags);
82 /* filedes.c */
83 void *do_filp_gc(void *arg);
84 void check_filp_locks(void);
85 void check_filp_locks_by_me(void);
86 void init_filps(void);
87 struct filp *find_filp(struct vnode *vp, mode_t bits);
88 int get_fd(int start, mode_t bits, int *k, struct filp **fpt);
89 struct filp *get_filp(int fild, tll_access_t locktype);
90 struct filp *get_filp2(struct fproc *rfp, int fild, tll_access_t
91 locktype);
92 void lock_filp(struct filp *filp, tll_access_t locktype);
93 void unlock_filp(struct filp *filp);
94 void unlock_filps(struct filp *filp1, struct filp *filp2);
95 int invalidate_filp(struct filp *);
96 void invalidate_filp_by_endpt(endpoint_t proc_e);
97 void invalidate_filp_by_char_major(int major);
98 int do_verify_fd(void);
99 int set_filp(filp_id_t sfilp);
100 int do_set_filp(void);
101 int copy_filp(endpoint_t to_ep, filp_id_t cfilp);
102 int do_copy_filp(void);
103 int put_filp(filp_id_t pfilp);
104 int do_put_filp(void);
105 int cancel_fd(endpoint_t ep, int fd);
106 int do_cancel_fd(void);
107 void close_filp(struct filp *fp);
109 /* fscall.c */
110 void nested_fs_call(message *m);
112 /* link.c */
113 int do_link(void);
114 int do_unlink(void);
115 int do_rename(void);
116 int do_truncate(void);
117 int do_ftruncate(void);
118 int truncate_vnode(struct vnode *vp, off_t newsize);
119 int rdlink_direct(char *orig_path, char *link_path, struct fproc *rfp);
121 /* lock.c */
122 int lock_op(struct filp *f, int req);
123 void lock_revive(void);
125 /* main.c */
126 int main(void);
127 void lock_proc(struct fproc *rfp, int force_lock);
128 void reply(endpoint_t whom, int result);
129 void thread_cleanup(struct fproc *rfp);
130 void unlock_proc(struct fproc *rfp);
132 /* misc.c */
133 int do_dup(void);
134 void pm_exit(int proc);
135 int do_fcntl(void);
136 void pm_fork(int pproc, int cproc, int cpid);
137 void pm_setgid(int proc_e, int egid, int rgid);
138 void pm_setuid(int proc_e, int euid, int ruid);
139 void pm_setgroups(int proc_e, int ngroups, gid_t *addr);
140 int do_sync(void);
141 int do_fsync(void);
142 void pm_reboot(void);
143 int do_svrctl(void);
144 int do_getsysinfo(void);
145 int pm_dumpcore(endpoint_t proc_e, int sig, vir_bytes exe_name);
146 void * ds_event(void *arg);
148 /* mount.c */
149 int do_fsready(void);
150 int do_mount(void);
151 int do_umount(void);
152 int is_nonedev(dev_t dev);
153 void mount_pfs(void);
154 int mount_fs(dev_t dev, char fullpath[PATH_MAX+1], endpoint_t fs_e, int
155 rdonly, char mount_label[LABEL_MAX]);
156 int unmount(dev_t dev, char label[LABEL_MAX]);
157 void unmount_all(void);
159 /* open.c */
160 int do_close(void);
161 int close_fd(struct fproc *rfp, int fd_nr);
162 void close_reply(void);
163 int common_open(char path[PATH_MAX], int oflags, mode_t omode);
164 int do_creat(void);
165 int do_lseek(void);
166 int do_llseek(void);
167 int do_mknod(void);
168 int do_mkdir(void);
169 int do_open(void);
170 int do_slink(void);
171 int do_vm_open(void);
172 int do_vm_close(void);
174 /* path.c */
175 struct vnode *advance(struct vnode *dirp, struct lookup *resolve, struct
176 fproc *rfp);
177 struct vnode *eat_path(struct lookup *resolve, struct fproc *rfp);
178 struct vnode *last_dir(struct lookup *resolve, struct fproc *rfp);
179 void lookup_init(struct lookup *resolve, char *path, int flags, struct
180 vmnt **vmp, struct vnode **vp);
181 int get_name(struct vnode *dirp, struct vnode *entry, char *_name);
182 int canonical_path(char *orig_path, struct fproc *rfp);
183 int do_check_perms(void);
185 /* pipe.c */
186 int do_pipe(void);
187 int map_vnode(struct vnode *vp, endpoint_t fs_e);
188 void unpause(endpoint_t proc_e);
189 int pipe_check(struct vnode *vp, int rw_flag, int oflags, int bytes,
190 u64_t position, int notouch);
191 void release(struct vnode *vp, int op, int count);
192 void revive(endpoint_t proc_e, int returned);
193 void suspend(int why);
194 void pipe_suspend(struct filp *rfilp, char *buf, size_t size);
195 void unsuspend_by_endpt(endpoint_t proc_e);
196 void wait_for(endpoint_t proc_e);
198 /* protect.c */
199 int do_access(void);
200 int do_chmod(void);
201 int do_chown(void);
202 int do_umask(void);
203 int forbidden(struct fproc *rfp, struct vnode *vp, mode_t
204 access_desired);
205 int read_only(struct vnode *vp);
207 /* read.c */
208 int do_read(void);
209 int do_getdents(void);
210 void lock_bsf(void);
211 void unlock_bsf(void);
212 void check_bsf_lock(void);
213 int do_read_write(int rw_flag);
214 int read_write(int rw_flag, struct filp *f, char *buffer, size_t nbytes,
215 endpoint_t for_e);
216 int rw_pipe(int rw_flag, endpoint_t usr, struct filp *f, char *buf,
217 size_t req_size);
219 /* request.c */
220 int req_breadwrite(endpoint_t fs_e, endpoint_t user_e, dev_t dev, u64_t pos,
221 unsigned int num_of_bytes, char *user_addr, int rw_flag,
222 u64_t *new_posp, unsigned int *cum_iop);
223 int req_chmod(int fs_e, ino_t inode_nr, mode_t rmode, mode_t *new_modep);
224 int req_chown(endpoint_t fs_e, ino_t inode_nr, uid_t newuid, gid_t newgid,
225 mode_t *new_modep);
226 int req_create(int fs_e, ino_t inode_nr, int omode, uid_t uid, gid_t gid,
227 char *path, node_details_t *res);
228 int req_flush(endpoint_t fs_e, dev_t dev);
229 int req_fstatfs(endpoint_t fs_e, endpoint_t proc_e, vir_bytes buf);
230 int req_statvfs(endpoint_t fs_e, endpoint_t proc_e, vir_bytes buf);
231 int req_ftrunc(endpoint_t fs_e, ino_t inode_nr, off_t start, off_t end);
232 int req_getdents(endpoint_t fs_e, ino_t inode_nr, u64_t pos, char *buf,
233 size_t size, u64_t *new_pos, int direct);
234 int req_inhibread(endpoint_t fs_e, ino_t inode_nr);
235 int req_link(endpoint_t fs_e, ino_t link_parent, char *lastc,
236 ino_t linked_file);
237 int req_lookup(endpoint_t fs_e, ino_t dir_ino, ino_t root_ino, uid_t uid,
238 gid_t gid, struct lookup *resolve, lookup_res_t *res,
239 struct fproc *rfp);
240 int req_mkdir(endpoint_t fs_e, ino_t inode_nr, char *lastc, uid_t uid,
241 gid_t gid, mode_t dmode);
242 int req_mknod(endpoint_t fs_e, ino_t inode_nr, char *lastc, uid_t uid,
243 gid_t gid, mode_t dmode, dev_t dev);
244 int req_mountpoint(endpoint_t fs_e, ino_t inode_nr);
245 int req_newnode(endpoint_t fs_e, uid_t uid, gid_t gid, mode_t dmode, dev_t dev,
246 struct node_details *res);
247 int req_putnode(int fs_e, ino_t inode_nr, int count);
248 int req_rdlink(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e,
249 vir_bytes buf, size_t len, int direct);
250 int req_readsuper(endpoint_t fs_e, char *driver_name, dev_t dev, int readonly,
251 int isroot, struct node_details *res_nodep, int *con_reqs);
252 int req_readwrite(endpoint_t fs_e, ino_t inode_nr, u64_t pos, int rw_flag,
253 endpoint_t user_e, char *user_addr, unsigned int num_of_bytes,
254 u64_t *new_posp, unsigned int *cum_iop);
255 int req_rename(endpoint_t fs_e, ino_t old_dir, char *old_name, ino_t new_dir,
256 char *new_name);
257 int req_rmdir(endpoint_t fs_e, ino_t inode_nr, char *lastc);
258 int req_slink(endpoint_t fs_e, ino_t inode_nr, char *lastc, endpoint_t proc_e,
259 vir_bytes path_addr, size_t path_length, uid_t uid, gid_t gid);
260 int req_stat(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e, vir_bytes buf,
261 int old_stat);
262 int req_sync(endpoint_t fs_e);
263 int req_unlink(endpoint_t fs_e, ino_t inode_nr, char *lastc);
264 int req_unmount(endpoint_t fs_e);
265 int req_utime(endpoint_t fs_e, ino_t inode_nr, time_t actime, time_t modtime);
266 int req_newdriver(endpoint_t fs_e, dev_t dev, char *label);
268 /* stadir.c */
269 int do_chdir(void);
270 int do_fchdir(void);
271 int do_chroot(void);
272 int do_fstat(void);
273 int do_stat(void);
274 int do_fstatfs(void);
275 int do_statvfs(void);
276 int do_fstatvfs(void);
277 int do_rdlink(void);
278 int do_lstat(void);
280 /* time.c */
281 int do_utime(void);
283 /* tll.c */
284 void tll_downgrade(tll_t *tllp);
285 int tll_haspendinglock(tll_t *tllp);
286 void tll_init(tll_t *tllp);
287 int tll_islocked(tll_t *tllp);
288 int tll_lock(tll_t *tllp, tll_access_t locktype);
289 int tll_locked_by_me(tll_t *tllp);
290 void tll_lockstat(tll_t *tllp);
291 int tll_unlock(tll_t *tllp);
292 void tll_upgrade(tll_t *tllp);
294 /* utility.c */
295 time_t clock_time(void);
296 unsigned conv2(int norm, int w);
297 long conv4(int norm, long x);
298 int copy_name(size_t len, char *dest);
299 int fetch_name(vir_bytes path, size_t len, char *dest);
300 int no_sys(void);
301 int isokendpt_f(char *f, int l, endpoint_t e, int *p, int ft);
302 int in_group(struct fproc *rfp, gid_t grp);
304 #define okendpt(e, p) isokendpt_f(__FILE__, __LINE__, (e), (p), 1)
305 #define isokendpt(e, p) isokendpt_f(__FILE__, __LINE__, (e), (p), 0)
307 /* vmnt.c */
308 void check_vmnt_locks(void);
309 void check_vmnt_locks_by_me(struct fproc *rfp);
310 void mark_vmnt_free(struct vmnt *vmp);
311 struct vmnt *get_free_vmnt(void);
312 struct vmnt *find_vmnt(endpoint_t fs_e);
313 struct vmnt *get_locked_vmnt(struct fproc *rfp);
314 void init_vmnts(void);
315 int lock_vmnt(struct vmnt *vp, tll_access_t locktype);
316 void unlock_vmnt(struct vmnt *vp);
317 void vmnt_unmap_by_endpt(endpoint_t proc_e);
319 /* vnode.c */
320 void check_vnode_locks(void);
321 void check_vnode_locks_by_me(struct fproc *rfp);
322 struct vnode *get_free_vnode(void);
323 struct vnode *find_vnode(int fs_e, ino_t inode);
324 void init_vnodes(void);
325 int is_vnode_locked(struct vnode *vp);
326 int lock_vnode(struct vnode *vp, tll_access_t locktype);
327 void unlock_vnode(struct vnode *vp);
328 void dup_vnode(struct vnode *vp);
329 void put_vnode(struct vnode *vp);
330 void vnode_clean_refs(struct vnode *vp);
332 /* write.c */
333 int do_write(void);
335 /* gcov.c */
336 int do_gcov_flush(void);
337 #if ! USE_COVERAGE
338 #define do_gcov_flush no_sys
339 #endif
341 /* select.c */
342 int do_select(void);
343 void init_select(void);
344 void select_callback(struct filp *, int ops);
345 void select_forget(endpoint_t proc_e);
346 void select_reply1(endpoint_t driver_e, int minor, int status);
347 void select_reply2(endpoint_t driver_e, int minor, int status);
348 void select_timeout_check(timer_t *);
349 void select_unsuspend_by_endpt(endpoint_t proc);
351 /* worker.c */
352 int worker_available(void);
353 struct worker_thread *worker_get(thread_t worker_tid);
354 struct job *worker_getjob(thread_t worker_tid);
355 void worker_init(struct worker_thread *worker);
356 void worker_signal(struct worker_thread *worker);
357 void worker_start(void *(*func)(void *arg));
358 void worker_stop(struct worker_thread *worker);
359 void worker_stop_by_endpt(endpoint_t proc_e);
360 void worker_wait(void);
361 void sys_worker_start(void *(*func)(void *arg));
362 void dl_worker_start(void *(*func)(void *arg));
363 #endif