xref: /minix/minix/servers/vfs/proto.h (revision 0a6a1f1d)
1 #ifndef __VFS_PROTO_H__
2 #define __VFS_PROTO_H__
3 
4 /* Function prototypes. */
5 
6 #include <minix/rs.h>
7 #include <minix/timers.h>
8 
9 #include "request.h"
10 #include "threads.h"
11 #include "tll.h"
12 
13 /* Structs used in prototypes must be declared as such first. */
14 struct filp;
15 struct fproc;
16 struct timespec;
17 struct vmnt;
18 struct vnode;
19 struct lookup;
20 struct worker_thread;
21 struct job;
22 
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 int vm_sendrec(message *reqm);
28 void fs_sendmore(struct vmnt *vmp);
29 void send_work(void);
30 int vm_vfs_procctl_handlemem(endpoint_t ep, vir_bytes mem, vir_bytes len, int flags);
31 
32 /* device.c */
33 int cdev_open(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 dev_t cdev_map(dev_t dev, struct fproc *rfp);
38 int cdev_select(dev_t dev, int ops);
39 int cdev_cancel(dev_t dev);
40 void cdev_reply(void);
41 int bdev_open(dev_t dev, int access);
42 int bdev_close(dev_t dev);
43 void bdev_reply(void);
44 void bdev_up(devmajor_t major);
45 int do_ioctl(void);
46 
47 /* dmap.c */
48 void lock_dmap(struct dmap *dp);
49 void unlock_dmap(struct dmap *dp);
50 int do_mapdriver(void);
51 void init_dmap(void);
52 int dmap_driver_match(endpoint_t proc, devmajor_t major);
53 void dmap_endpt_up(endpoint_t proc_nr, int is_blk);
54 struct dmap *get_dmap(endpoint_t proc_e);
55 struct dmap *get_dmap_by_major(devmajor_t major);
56 void dmap_unmap_by_endpt(endpoint_t proc_nr);
57 int map_service(struct rprocpub *rpub);
58 
59 /* elf_core_dump.c */
60 void write_elf_core_file(struct filp *f, int csig, char *exe_name);
61 
62 /* exec.c */
63 int pm_exec(vir_bytes path, size_t path_len, vir_bytes frame, size_t frame_len,
64 	vir_bytes *pc, vir_bytes *newsp, vir_bytes *ps_str);
65 
66 /* filedes.c */
67 void check_filp_locks(void);
68 void check_filp_locks_by_me(void);
69 void init_filps(void);
70 struct filp *find_filp(struct vnode *vp, mode_t bits);
71 int get_fd(struct fproc *rfp, int start, mode_t bits, int *k,
72 	struct filp **fpt);
73 struct filp *get_filp(int fild, tll_access_t locktype);
74 struct filp *get_filp2(struct fproc *rfp, int fild, tll_access_t locktype);
75 void lock_filp(struct filp *filp, tll_access_t locktype);
76 void unlock_filp(struct filp *filp);
77 void unlock_filps(struct filp *filp1, struct filp *filp2);
78 void invalidate_filp(struct filp *);
79 void invalidate_filp_by_endpt(endpoint_t proc_e);
80 void invalidate_filp_by_char_major(devmajor_t major);
81 void close_filp(struct filp *fp);
82 int do_copyfd(void);
83 
84 /* fscall.c */
85 void nested_fs_call(message *m);
86 
87 /* link.c */
88 int do_link(void);
89 int do_unlink(void);
90 int do_rename(void);
91 int do_truncate(void);
92 int do_ftruncate(void);
93 int truncate_vnode(struct vnode *vp, off_t newsize);
94 int rdlink_direct(char *orig_path, char *link_path, struct fproc *rfp);
95 
96 /* lock.c */
97 int lock_op(struct filp *f, int req);
98 void lock_revive(void);
99 
100 /* main.c */
101 int main(void);
102 void lock_proc(struct fproc *rfp);
103 void unlock_proc(struct fproc *rfp);
104 void replycode(endpoint_t whom, int result);
105 void service_pm_postponed(void);
106 void thread_cleanup(void);
107 
108 /* misc.c */
109 void pm_exit(void);
110 int do_fcntl(void);
111 void pm_fork(endpoint_t pproc, endpoint_t cproc, pid_t cpid);
112 void pm_setgid(endpoint_t proc_e, int egid, int rgid);
113 void pm_setuid(endpoint_t proc_e, int euid, int ruid);
114 void pm_setgroups(endpoint_t proc_e, int ngroups, gid_t *addr);
115 void pm_setsid(endpoint_t proc_e);
116 int do_sync(void);
117 int do_fsync(void);
118 void pm_reboot(void);
119 int do_svrctl(void);
120 int do_getsysinfo(void);
121 int do_vm_call(void);
122 int pm_dumpcore(int sig, vir_bytes exe_name);
123 void ds_event(void);
124 int dupvm(struct fproc *fp, int pfd, int *vmfd, struct filp **f);
125 int do_getrusage(void);
126 
127 /* mount.c */
128 int do_mount(void);
129 int do_umount(void);
130 int is_nonedev(dev_t dev);
131 void mount_pfs(void);
132 int mount_fs(dev_t dev, char mount_dev[PATH_MAX], char mount_path[PATH_MAX],
133 	endpoint_t fs_e, int rdonly, char mount_type[FSTYPE_MAX],
134 	char mount_label[LABEL_MAX]);
135 int unmount(dev_t dev, char label[LABEL_MAX]);
136 void unmount_all(int force);
137 
138 /* open.c */
139 int do_close(void);
140 int close_fd(struct fproc *rfp, int fd_nr);
141 int common_open(char path[PATH_MAX], int oflags, mode_t omode, int for_exec);
142 int do_creat(void);
143 int do_lseek(void);
144 int do_mknod(void);
145 int do_mkdir(void);
146 int do_open(void);
147 int do_creat(void);
148 int do_slink(void);
149 int actual_lseek(struct fproc *rfp, int seekfd, int seekwhence, off_t offset,
150 	off_t *newposp);
151 
152 /* path.c */
153 struct vnode *advance(struct vnode *dirp, struct lookup *resolve, struct
154 	fproc *rfp);
155 struct vnode *eat_path(struct lookup *resolve, struct fproc *rfp);
156 struct vnode *last_dir(struct lookup *resolve, struct fproc *rfp);
157 void lookup_init(struct lookup *resolve, char *path, int flags, struct
158 	vmnt **vmp, struct vnode **vp);
159 int get_name(struct vnode *dirp, struct vnode *entry, char *_name);
160 int canonical_path(char *orig_path, struct fproc *rfp);
161 int do_checkperms(void);
162 
163 /* pipe.c */
164 int do_pipe2(void);
165 int map_vnode(struct vnode *vp, endpoint_t fs_e);
166 void unpause(void);
167 int pipe_check(struct filp *filp, int rw_flag, int oflags, int bytes,
168 	int notouch);
169 void release(struct vnode *vp, int op, int count);
170 void revive(endpoint_t proc_e, int returned);
171 void suspend(int why);
172 void pipe_suspend(struct filp *rfilp, vir_bytes buf, size_t size);
173 void unsuspend_by_endpt(endpoint_t proc_e);
174 void wait_for(endpoint_t proc_e);
175 
176 /* protect.c */
177 int do_access(void);
178 int do_chmod(void);
179 int do_chown(void);
180 int do_umask(void);
181 int forbidden(struct fproc *rfp, struct vnode *vp, mode_t
182 	access_desired);
183 int read_only(struct vnode *vp);
184 
185 /* read.c */
186 int do_read(void);
187 int do_getdents(void);
188 void lock_bsf(void);
189 void unlock_bsf(void);
190 void check_bsf_lock(void);
191 int do_read_write_peek(int rw_flag, int fd, vir_bytes buf, size_t bytes);
192 int actual_read_write_peek(struct fproc *rfp, int rw_flag, int fd, vir_bytes buf,
193 	size_t bytes);
194 int read_write(struct fproc *rfp, int rw_flag, struct filp *f, vir_bytes buffer,
195 	size_t nbytes, endpoint_t for_e);
196 int rw_pipe(int rw_flag, endpoint_t usr, struct filp *f, vir_bytes buf,
197 	size_t req_size);
198 
199 /* request.c */
200 int req_breadwrite(endpoint_t fs_e, endpoint_t user_e, dev_t dev, off_t pos,
201 	unsigned int num_of_bytes, vir_bytes user_addr, int rw_flag,
202 	off_t *new_posp, size_t *cum_iop);
203 int req_chmod(endpoint_t fs_e, ino_t inode_nr, mode_t rmode,
204 	mode_t *new_modep);
205 int req_chown(endpoint_t fs_e, ino_t inode_nr, uid_t newuid, gid_t newgid,
206 	mode_t *new_modep);
207 int req_create(endpoint_t fs_e, ino_t inode_nr, int omode, uid_t uid,
208 	gid_t gid, char *path, node_details_t *res);
209 int req_flush(endpoint_t fs_e, dev_t dev);
210 int req_statvfs(endpoint_t fs_e, struct statvfs *buf);
211 int req_ftrunc(endpoint_t fs_e, ino_t inode_nr, off_t start, off_t end);
212 int req_getdents(endpoint_t fs_e, ino_t inode_nr, off_t pos, vir_bytes buf,
213 	size_t size, off_t *new_pos, int direct);
214 int req_inhibread(endpoint_t fs_e, ino_t inode_nr);
215 int req_link(endpoint_t fs_e, ino_t link_parent, char *lastc,
216 	ino_t linked_file);
217 int req_lookup(endpoint_t fs_e, ino_t dir_ino, ino_t root_ino, uid_t uid,
218 	gid_t gid, struct lookup *resolve, lookup_res_t *res,
219 	struct fproc *rfp);
220 int req_mkdir(endpoint_t fs_e, ino_t inode_nr, char *lastc, uid_t uid,
221 	gid_t gid, mode_t dmode);
222 int req_mknod(endpoint_t fs_e, ino_t inode_nr, char *lastc, uid_t uid,
223 	gid_t gid, mode_t dmode, dev_t dev);
224 int req_mountpoint(endpoint_t fs_e, ino_t inode_nr);
225 int req_newnode(endpoint_t fs_e, uid_t uid, gid_t gid, mode_t dmode,
226 	dev_t dev, struct node_details *res);
227 int req_putnode(int fs_e, ino_t inode_nr, int count);
228 int req_rdlink(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e,
229 	vir_bytes buf, size_t len, int direct);
230 int req_readsuper(struct vmnt *vmp, char *driver_name, dev_t dev, int readonly,
231 	int isroot, struct node_details *res_nodep, unsigned int *fs_flags);
232 int req_readwrite(endpoint_t fs_e, ino_t inode_nr, off_t pos, int rw_flag,
233 	endpoint_t user_e, vir_bytes user_addr, unsigned int num_of_bytes,
234 	off_t *new_posp, size_t *cum_iop);
235 int req_bpeek(endpoint_t fs_e, dev_t dev, off_t pos, unsigned int num_of_bytes);
236 int req_peek(endpoint_t fs_e, ino_t inode_nr, off_t pos, unsigned int bytes);
237 int req_rename(endpoint_t fs_e, ino_t old_dir, char *old_name, ino_t new_dir,
238 	char *new_name);
239 int req_rmdir(endpoint_t fs_e, ino_t inode_nr, char *lastc);
240 int req_slink(endpoint_t fs_e, ino_t inode_nr, char *lastc, endpoint_t proc_e,
241 	vir_bytes path_addr, size_t path_length, uid_t uid, gid_t gid);
242 int req_stat(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e, vir_bytes buf);
243 int req_sync(endpoint_t fs_e);
244 int req_unlink(endpoint_t fs_e, ino_t inode_nr, char *lastc);
245 int req_unmount(endpoint_t fs_e);
246 int req_utime(endpoint_t fs_e, ino_t inode_nr, struct timespec * actv,
247 	struct timespec * modtv);
248 int req_newdriver(endpoint_t fs_e, dev_t dev, char *label);
249 
250 /* stadir.c */
251 int do_chdir(void);
252 int do_fchdir(void);
253 int do_chroot(void);
254 int do_fstat(void);
255 int do_stat(void);
256 int do_statvfs(void);
257 int do_fstatvfs(void);
258 int do_getvfsstat(void);
259 int do_rdlink(void);
260 int do_lstat(void);
261 int update_statvfs(struct vmnt *vmp, struct statvfs *buf);
262 
263 /* time.c */
264 int do_utimens(void);
265 
266 /* tll.c */
267 void tll_downgrade(tll_t *tllp);
268 int tll_haspendinglock(tll_t *tllp);
269 void tll_init(tll_t *tllp);
270 int tll_islocked(tll_t *tllp);
271 int tll_lock(tll_t *tllp, tll_access_t locktype);
272 int tll_locked_by_me(tll_t *tllp);
273 void tll_lockstat(tll_t *tllp);
274 int tll_unlock(tll_t *tllp);
275 void tll_upgrade(tll_t *tllp);
276 
277 /* utility.c */
278 int copy_path(char *dest, size_t size);
279 int fetch_name(vir_bytes path, size_t len, char *dest);
280 int isokendpt_f(const char *f, int l, endpoint_t e, int *p, int ft);
281 int in_group(struct fproc *rfp, gid_t grp);
282 int sys_datacopy_wrapper(endpoint_t src, vir_bytes srcv, endpoint_t dst, vir_bytes dstv,
283 	size_t len);
284 
285 #define okendpt(e, p) isokendpt_f(__FILE__, __LINE__, (e), (p), 1)
286 #define isokendpt(e, p) isokendpt_f(__FILE__, __LINE__, (e), (p), 0)
287 
288 /* vmnt.c */
289 void check_vmnt_locks(void);
290 void check_vmnt_locks_by_me(struct fproc *rfp);
291 void mark_vmnt_free(struct vmnt *vmp);
292 struct vmnt *get_free_vmnt(void);
293 struct vmnt *find_vmnt(endpoint_t fs_e);
294 struct vmnt *get_locked_vmnt(struct fproc *rfp);
295 void init_vmnts(void);
296 int lock_vmnt(struct vmnt *vp, tll_access_t locktype);
297 void unlock_vmnt(struct vmnt *vp);
298 void vmnt_unmap_by_endpt(endpoint_t proc_e);
299 void fetch_vmnt_paths(void);
300 void upgrade_vmnt_lock(struct vmnt *vmp);
301 void downgrade_vmnt_lock(struct vmnt *vmp);
302 
303 /* vnode.c */
304 void check_vnode_locks(void);
305 void check_vnode_locks_by_me(struct fproc *rfp);
306 struct vnode *get_free_vnode(void);
307 struct vnode *find_vnode(int fs_e, ino_t inode);
308 void init_vnodes(void);
309 int is_vnode_locked(struct vnode *vp);
310 int lock_vnode(struct vnode *vp, tll_access_t locktype);
311 void unlock_vnode(struct vnode *vp);
312 void dup_vnode(struct vnode *vp);
313 void put_vnode(struct vnode *vp);
314 void vnode_clean_refs(struct vnode *vp);
315 void upgrade_vnode_lock(struct vnode *vp);
316 
317 /* write.c */
318 int do_write(void);
319 
320 /* gcov.c */
321 int do_gcov_flush(void);
322 #if ! USE_COVERAGE
323 #define do_gcov_flush NULL
324 #endif
325 
326 /* select.c */
327 int do_select(void);
328 void init_select(void);
329 void select_callback(struct filp *, int ops);
330 void select_forget(void);
331 void select_reply1(endpoint_t driver_e, devminor_t minor, int status);
332 void select_reply2(endpoint_t driver_e, devminor_t minor, int status);
333 void select_timeout_check(minix_timer_t *);
334 void select_unsuspend_by_endpt(endpoint_t proc);
335 
336 /* worker.c */
337 void worker_init(void);
338 void worker_cleanup(void);
339 int worker_idle(void);
340 int worker_available(void);
341 void worker_allow(int allow);
342 struct worker_thread *worker_get(thread_t worker_tid);
343 void worker_signal(struct worker_thread *worker);
344 int worker_can_start(struct fproc *rfp);
345 void worker_start(struct fproc *rfp, void (*func)(void), message *m_ptr,
346 	int use_spare);
347 void worker_stop(struct worker_thread *worker);
348 void worker_stop_by_endpt(endpoint_t proc_e);
349 void worker_yield(void);
350 void worker_wait(void);
351 struct worker_thread *worker_suspend(void);
352 void worker_resume(struct worker_thread *org_self);
353 void worker_set_proc(struct fproc *rfp);
354 #endif
355