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