Sync with cat.c from netbsd-8
[minix3.git] / minix / servers / vfs / proto.h
blob17f593c1a9e48679d7171e0d8f7b77f6c2bedd35
1 #ifndef __VFS_PROTO_H__
2 #define __VFS_PROTO_H__
4 /* Function prototypes. */
6 #include <minix/rs.h>
7 #include <minix/timers.h>
9 #include "request.h"
10 #include "threads.h"
11 #include "tll.h"
12 #include "type.h"
14 /* Structs used in prototypes must be declared as such first. */
15 struct filp;
16 struct fproc;
17 struct timespec;
18 struct vmnt;
19 struct vnode;
20 struct lookup;
21 struct worker_thread;
22 struct job;
24 /* bdev.c */
25 int bdev_open(dev_t dev, int access);
26 int bdev_close(dev_t dev);
27 int bdev_ioctl(dev_t dev, endpoint_t proc_e, unsigned long req, vir_bytes buf);
28 void bdev_reply(void);
29 void bdev_up(devmajor_t major);
31 /* cdev.c */
32 dev_t cdev_map(dev_t dev, struct fproc *rfp);
33 int cdev_open(int fd, dev_t dev, int flags);
34 int cdev_close(dev_t dev);
35 int cdev_io(int op, dev_t dev, endpoint_t proc_e, vir_bytes buf, off_t pos,
36 unsigned long bytes, int flags);
37 int cdev_select(dev_t dev, int ops);
38 int cdev_cancel(dev_t dev, endpoint_t endpt, cp_grant_id_t grant);
39 void cdev_reply(void);
41 /* comm.c */
42 int drv_sendrec(endpoint_t drv_e, message *reqm);
43 void fs_cancel(struct vmnt *vmp);
44 int fs_sendrec(endpoint_t fs_e, message *reqm);
45 int vm_sendrec(message *reqm);
46 void fs_sendmore(struct vmnt *vmp);
47 void send_work(void);
48 int vm_vfs_procctl_handlemem(endpoint_t ep, vir_bytes mem, vir_bytes len, int flags);
50 /* device.c */
51 int do_ioctl(void);
52 cp_grant_id_t make_ioctl_grant(endpoint_t driver_e, endpoint_t user_e,
53 vir_bytes buf, unsigned long request);
55 /* dmap.c */
56 void lock_dmap(struct dmap *dp);
57 void unlock_dmap(struct dmap *dp);
58 int do_mapdriver(void);
59 void init_dmap(void);
60 int dmap_driver_match(endpoint_t proc, devmajor_t major);
61 void dmap_endpt_up(endpoint_t proc_nr, int is_blk);
62 struct dmap *get_dmap_by_endpt(endpoint_t proc_e);
63 struct dmap *get_dmap_by_major(devmajor_t major);
64 void dmap_unmap_by_endpt(endpoint_t proc_nr);
65 int map_service(struct rprocpub *rpub);
67 /* elf_core_dump.c */
68 void write_elf_core_file(struct filp *f, int csig, char *exe_name);
70 /* exec.c */
71 int pm_exec(vir_bytes path, size_t path_len, vir_bytes frame, size_t frame_len,
72 vir_bytes *pc, vir_bytes *newsp, vir_bytes *ps_str);
74 /* filedes.c */
75 void check_filp_locks(void);
76 void check_filp_locks_by_me(void);
77 void init_filps(void);
78 struct filp *find_filp(struct vnode *vp, mode_t bits);
79 struct filp *find_filp_by_sock_dev(dev_t dev);
80 int check_fds(struct fproc *rfp, int nfds);
81 int get_fd(struct fproc *rfp, int start, mode_t bits, int *k,
82 struct filp **fpt);
83 struct filp *get_filp(int fild, tll_access_t locktype);
84 struct filp *get_filp2(struct fproc *rfp, int fild, tll_access_t locktype);
85 void lock_filp(struct filp *filp, tll_access_t locktype);
86 void unlock_filp(struct filp *filp);
87 void unlock_filps(struct filp *filp1, struct filp *filp2);
88 void invalidate_filp(struct filp *);
89 void invalidate_filp_by_endpt(endpoint_t proc_e);
90 void invalidate_filp_by_char_major(devmajor_t major);
91 void invalidate_filp_by_sock_drv(unsigned int num);
92 int close_filp(struct filp *fp, int may_suspend);
93 int do_copyfd(void);
95 /* fscall.c */
96 void nested_fs_call(message *m);
98 /* link.c */
99 int do_link(void);
100 int do_unlink(void);
101 int do_rename(void);
102 int do_truncate(void);
103 int do_ftruncate(void);
104 int truncate_vnode(struct vnode *vp, off_t newsize);
105 int rdlink_direct(char *orig_path, char *link_path, struct fproc *rfp);
107 /* lock.c */
108 int lock_op(int fd, int req, vir_bytes arg);
109 void lock_revive(void);
111 /* main.c */
112 int main(void);
113 void lock_proc(struct fproc *rfp);
114 void unlock_proc(struct fproc *rfp);
115 void reply(message *m_out, endpoint_t whom, int result);
116 void replycode(endpoint_t whom, int result);
117 void service_pm_postponed(void);
118 void thread_cleanup(void);
120 /* misc.c */
121 void pm_exit(void);
122 int do_fcntl(void);
123 void pm_fork(endpoint_t pproc, endpoint_t cproc, pid_t cpid);
124 void pm_setgid(endpoint_t proc_e, int egid, int rgid);
125 void pm_setuid(endpoint_t proc_e, int euid, int ruid);
126 void pm_setgroups(endpoint_t proc_e, int ngroups, gid_t *addr);
127 void pm_setsid(endpoint_t proc_e);
128 int do_sync(void);
129 int do_fsync(void);
130 void pm_reboot(void);
131 int do_svrctl(void);
132 int do_getsysinfo(void);
133 int do_vm_call(void);
134 int pm_dumpcore(int sig, vir_bytes exe_name);
135 void ds_event(void);
136 int dupvm(struct fproc *fp, int pfd, int *vmfd, struct filp **f);
137 int do_getrusage(void);
139 /* mount.c */
140 int do_mount(void);
141 int do_umount(void);
142 int is_nonedev(dev_t dev);
143 void mount_pfs(void);
144 int mount_fs(dev_t dev, char mount_dev[PATH_MAX], char mount_path[PATH_MAX],
145 endpoint_t fs_e, int rdonly, char mount_type[FSTYPE_MAX],
146 char mount_label[LABEL_MAX]);
147 int unmount(dev_t dev, char label[LABEL_MAX]);
148 void unmount_all(int force);
150 /* open.c */
151 int do_close(void);
152 int close_fd(struct fproc *rfp, int fd_nr, int may_suspend);
153 int common_open(char path[PATH_MAX], int oflags, mode_t omode, int for_exec);
154 int do_creat(void);
155 int do_lseek(void);
156 int do_mknod(void);
157 int do_mkdir(void);
158 int do_open(void);
159 int do_creat(void);
160 int do_slink(void);
161 int actual_lseek(struct fproc *rfp, int seekfd, int seekwhence, off_t offset,
162 off_t *newposp);
164 /* path.c */
165 struct vnode *advance(struct vnode *dirp, struct lookup *resolve, struct
166 fproc *rfp);
167 struct vnode *eat_path(struct lookup *resolve, struct fproc *rfp);
168 struct vnode *last_dir(struct lookup *resolve, struct fproc *rfp);
169 void lookup_init(struct lookup *resolve, char *path, int flags, struct
170 vmnt **vmp, struct vnode **vp);
171 int get_name(struct vnode *dirp, struct vnode *entry, char *_name);
172 int canonical_path(char *orig_path, struct fproc *rfp);
173 int do_socketpath(void);
175 /* pipe.c */
176 int do_pipe2(void);
177 int map_vnode(struct vnode *vp, endpoint_t fs_e);
178 void unpause(void);
179 int pipe_check(struct filp *filp, int rw_flag, int oflags, int bytes,
180 int notouch);
181 void release(struct vnode *vp, int op, int count);
182 void revive(endpoint_t proc_e, int returned);
183 void suspend(int why);
184 void pipe_suspend(int callnr, int fd, vir_bytes buf, size_t size,
185 size_t cum_io);
186 void unsuspend_by_endpt(endpoint_t proc_e);
188 /* protect.c */
189 int do_access(void);
190 int do_chmod(void);
191 int do_chown(void);
192 int do_umask(void);
193 int forbidden(struct fproc *rfp, struct vnode *vp, mode_t
194 access_desired);
195 int read_only(struct vnode *vp);
197 /* read.c */
198 int do_read(void);
199 int do_getdents(void);
200 void lock_bsf(void);
201 void unlock_bsf(void);
202 void check_bsf_lock(void);
203 int do_read_write_peek(int rw_flag, int fd, vir_bytes buf, size_t bytes);
204 int actual_read_write_peek(struct fproc *rfp, int rw_flag, int fd,
205 vir_bytes buf, size_t bytes);
206 int read_write(struct fproc *rfp, int rw_flag, int fd, struct filp *f,
207 vir_bytes buffer, size_t nbytes, endpoint_t for_e);
208 int rw_pipe(int rw_flag, endpoint_t usr, struct filp *f, int callnr, int fd,
209 vir_bytes buf, size_t nbytes, size_t cum_io);
211 /* request.c */
212 int req_breadwrite(endpoint_t fs_e, endpoint_t user_e, dev_t dev, off_t pos,
213 unsigned int num_of_bytes, vir_bytes user_addr, int rw_flag,
214 off_t *new_posp, size_t *cum_iop);
215 int req_chmod(endpoint_t fs_e, ino_t inode_nr, mode_t rmode,
216 mode_t *new_modep);
217 int req_chown(endpoint_t fs_e, ino_t inode_nr, uid_t newuid, gid_t newgid,
218 mode_t *new_modep);
219 int req_create(endpoint_t fs_e, ino_t inode_nr, int omode, uid_t uid,
220 gid_t gid, char *path, node_details_t *res);
221 int req_flush(endpoint_t fs_e, dev_t dev);
222 int req_statvfs(endpoint_t fs_e, struct statvfs *buf);
223 int req_ftrunc(endpoint_t fs_e, ino_t inode_nr, off_t start, off_t end);
224 int req_getdents(endpoint_t fs_e, ino_t inode_nr, off_t pos, vir_bytes buf,
225 size_t size, off_t *new_pos, int direct);
226 int req_inhibread(endpoint_t fs_e, ino_t inode_nr);
227 int req_link(endpoint_t fs_e, ino_t link_parent, char *lastc,
228 ino_t linked_file);
229 int req_lookup(endpoint_t fs_e, ino_t dir_ino, ino_t root_ino, uid_t uid,
230 gid_t gid, struct lookup *resolve, lookup_res_t *res,
231 struct fproc *rfp);
232 int req_mkdir(endpoint_t fs_e, ino_t inode_nr, char *lastc, uid_t uid,
233 gid_t gid, mode_t dmode);
234 int req_mknod(endpoint_t fs_e, ino_t inode_nr, char *lastc, uid_t uid,
235 gid_t gid, mode_t dmode, dev_t dev);
236 int req_mountpoint(endpoint_t fs_e, ino_t inode_nr);
237 int req_newnode(endpoint_t fs_e, uid_t uid, gid_t gid, mode_t dmode,
238 dev_t dev, struct node_details *res);
239 int req_putnode(int fs_e, ino_t inode_nr, int count);
240 int req_rdlink(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e,
241 vir_bytes buf, size_t len, int direct);
242 int req_readsuper(struct vmnt *vmp, char *driver_name, dev_t dev, int readonly,
243 int isroot, struct node_details *res_nodep, unsigned int *fs_flags);
244 int req_readwrite(endpoint_t fs_e, ino_t inode_nr, off_t pos, int rw_flag,
245 endpoint_t user_e, vir_bytes user_addr, unsigned int num_of_bytes,
246 off_t *new_posp, size_t *cum_iop);
247 int req_bpeek(endpoint_t fs_e, dev_t dev, off_t pos, unsigned int num_of_bytes);
248 int req_peek(endpoint_t fs_e, ino_t inode_nr, off_t pos, unsigned int bytes);
249 int req_rename(endpoint_t fs_e, ino_t old_dir, char *old_name, ino_t new_dir,
250 char *new_name);
251 int req_rmdir(endpoint_t fs_e, ino_t inode_nr, char *lastc);
252 int req_slink(endpoint_t fs_e, ino_t inode_nr, char *lastc, endpoint_t proc_e,
253 vir_bytes path_addr, size_t path_length, uid_t uid, gid_t gid);
254 int req_stat(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e, vir_bytes buf);
255 int req_sync(endpoint_t fs_e);
256 int req_unlink(endpoint_t fs_e, ino_t inode_nr, char *lastc);
257 int req_unmount(endpoint_t fs_e);
258 int req_utime(endpoint_t fs_e, ino_t inode_nr, struct timespec * actv,
259 struct timespec * modtv);
260 int req_newdriver(endpoint_t fs_e, dev_t dev, char *label);
262 /* sdev.c */
263 int sdev_socket(int domain, int type, int protocol, dev_t *dev, int pair);
264 int sdev_bind(dev_t dev, vir_bytes addr, unsigned int addr_len,
265 int filp_flags);
266 int sdev_connect(dev_t dev, vir_bytes addr, unsigned int addr_len,
267 int filp_flags);
268 int sdev_listen(dev_t dev, int backlog);
269 int sdev_accept(dev_t dev, vir_bytes addr, unsigned int addr_len,
270 int filp_flags, int fd);
271 int sdev_readwrite(dev_t dev, vir_bytes data_buf, size_t data_len,
272 vir_bytes ctl_buf, unsigned int ctl_len, vir_bytes addr_buf,
273 unsigned int addr_len, int flags, int rw_flag, int filp_flags,
274 vir_bytes user_buf);
275 int sdev_ioctl(dev_t dev, unsigned long request, vir_bytes buf,
276 int filp_flags);
277 int sdev_setsockopt(dev_t dev, int level, int name, vir_bytes addr,
278 unsigned int len);
279 int sdev_getsockopt(dev_t dev, int level, int name, vir_bytes addr,
280 unsigned int *len);
281 int sdev_getsockname(dev_t dev, vir_bytes addr, unsigned int *addr_len);
282 int sdev_getpeername(dev_t dev, vir_bytes addr, unsigned int *addr_len);
283 int sdev_shutdown(dev_t dev, int how);
284 int sdev_close(dev_t dev, int may_suspend);
285 int sdev_select(dev_t dev, int ops);
286 void sdev_stop(struct fproc *rfp);
287 void sdev_cancel(void);
288 void sdev_reply(void);
290 /* smap.c */
291 void init_smap(void);
292 int smap_map(const char *label, endpoint_t endpt, const int *domains,
293 unsigned int ndomains);
294 void smap_unmap_by_endpt(endpoint_t endpt);
295 void smap_endpt_up(endpoint_t endpt);
296 dev_t make_smap_dev(struct smap *sp, sockid_t sockid);
297 struct smap *get_smap_by_endpt(endpoint_t endpt);
298 struct smap *get_smap_by_domain(int domain);
299 struct smap *get_smap_by_dev(dev_t dev, sockid_t * sockidp);
301 /* socket.c */
302 int do_socket(void);
303 int do_socketpair(void);
304 int do_bind(void);
305 int do_connect(void);
306 int do_listen(void);
307 int do_accept(void);
308 void resume_accept(struct fproc *rfp, int status, dev_t dev,
309 unsigned int addr_len, int listen_fd);
310 int do_sendto(void);
311 int do_recvfrom(void);
312 void resume_recvfrom(struct fproc *rfp, int status, unsigned int addr_len);
313 int do_sockmsg(void);
314 void resume_recvmsg(struct fproc *rfp, int status, unsigned int ctl_len,
315 unsigned int addr_len, int flags, vir_bytes msg_buf);
316 int do_setsockopt(void);
317 int do_getsockopt(void);
318 int do_getsockname(void);
319 int do_getpeername(void);
320 int do_shutdown(void);
322 /* stadir.c */
323 int do_chdir(void);
324 int do_fchdir(void);
325 int do_chroot(void);
326 int do_fstat(void);
327 int do_stat(void);
328 int do_statvfs(void);
329 int do_fstatvfs(void);
330 int do_getvfsstat(void);
331 int do_rdlink(void);
332 int do_lstat(void);
333 int update_statvfs(struct vmnt *vmp, struct statvfs *buf);
335 /* time.c */
336 int do_utimens(void);
338 /* tll.c */
339 void tll_downgrade(tll_t *tllp);
340 int tll_haspendinglock(tll_t *tllp);
341 void tll_init(tll_t *tllp);
342 int tll_islocked(tll_t *tllp);
343 int tll_lock(tll_t *tllp, tll_access_t locktype);
344 int tll_locked_by_me(tll_t *tllp);
345 void tll_lockstat(tll_t *tllp);
346 int tll_unlock(tll_t *tllp);
347 void tll_upgrade(tll_t *tllp);
349 /* utility.c */
350 int copy_path(char *dest, size_t size);
351 int fetch_name(vir_bytes path, size_t len, char *dest);
352 int isokendpt_f(const char *f, int l, endpoint_t e, int *p, int ft);
353 int in_group(struct fproc *rfp, gid_t grp);
354 int sys_datacopy_wrapper(endpoint_t src, vir_bytes srcv, endpoint_t dst,
355 vir_bytes dstv, size_t len);
357 #define okendpt(e, p) isokendpt_f(__FILE__, __LINE__, (e), (p), 1)
358 #define isokendpt(e, p) isokendpt_f(__FILE__, __LINE__, (e), (p), 0)
360 /* vmnt.c */
361 void check_vmnt_locks(void);
362 void check_vmnt_locks_by_me(struct fproc *rfp);
363 void mark_vmnt_free(struct vmnt *vmp);
364 struct vmnt *get_free_vmnt(void);
365 struct vmnt *find_vmnt(endpoint_t fs_e);
366 struct vmnt *get_locked_vmnt(struct fproc *rfp);
367 void init_vmnts(void);
368 int lock_vmnt(struct vmnt *vp, tll_access_t locktype);
369 void unlock_vmnt(struct vmnt *vp);
370 void vmnt_unmap_by_endpt(endpoint_t proc_e);
371 void fetch_vmnt_paths(void);
372 void upgrade_vmnt_lock(struct vmnt *vmp);
373 void downgrade_vmnt_lock(struct vmnt *vmp);
375 /* vnode.c */
376 void check_vnode_locks(void);
377 void check_vnode_locks_by_me(struct fproc *rfp);
378 struct vnode *get_free_vnode(void);
379 struct vnode *find_vnode(int fs_e, ino_t inode);
380 void init_vnodes(void);
381 int is_vnode_locked(struct vnode *vp);
382 int lock_vnode(struct vnode *vp, tll_access_t locktype);
383 void unlock_vnode(struct vnode *vp);
384 void dup_vnode(struct vnode *vp);
385 void put_vnode(struct vnode *vp);
386 void vnode_clean_refs(struct vnode *vp);
387 void upgrade_vnode_lock(struct vnode *vp);
389 /* write.c */
390 int do_write(void);
392 /* gcov.c */
393 int do_gcov_flush(void);
394 #if ! USE_COVERAGE
395 #define do_gcov_flush NULL
396 #endif
398 /* select.c */
399 int do_select(void);
400 void init_select(void);
401 void select_callback(struct filp *, int ops);
402 void select_forget(void);
403 void select_cdev_reply1(endpoint_t driver_e, devminor_t minor, int status);
404 void select_cdev_reply2(endpoint_t driver_e, devminor_t minor, int status);
405 void select_sdev_reply1(dev_t dev, int status);
406 void select_sdev_reply2(dev_t dev, int status);
407 void select_unsuspend_by_endpt(endpoint_t proc);
408 void select_dump(void);
410 /* worker.c */
411 void worker_init(void);
412 void worker_cleanup(void);
413 int worker_idle(void);
414 int worker_available(void);
415 void worker_allow(int allow);
416 struct worker_thread *worker_get(thread_t worker_tid);
417 void worker_signal(struct worker_thread *worker);
418 int worker_can_start(struct fproc *rfp);
419 void worker_start(struct fproc *rfp, void (*func)(void), message *m_ptr,
420 int use_spare);
421 void worker_stop(struct worker_thread *worker);
422 void worker_stop_by_endpt(endpoint_t proc_e);
423 void worker_yield(void);
424 void worker_wait(void);
425 struct worker_thread *worker_suspend(void);
426 void worker_resume(struct worker_thread *org_self);
427 void worker_set_proc(struct fproc *rfp);
428 #endif