we do not want to shift by the block size, which is much larger than
[dragonfly.git] / sys / kern / vfs_vopops.c
blob3b33cb32e8bf3d131123b43cdeddeeaed60a3ded
1 /*
2 *
3 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
4 *
5 * This code is derived from software contributed to The DragonFly Project
6 * by Matthew Dillon <dillon@backplane.com>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
35 * $DragonFly: src/sys/kern/vfs_vopops.c,v 1.33 2006/10/27 04:56:31 dillon Exp $
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/buf.h>
41 #include <sys/conf.h>
42 #include <sys/dirent.h>
43 #include <sys/domain.h>
44 #include <sys/eventhandler.h>
45 #include <sys/fcntl.h>
46 #include <sys/kernel.h>
47 #include <sys/kthread.h>
48 #include <sys/malloc.h>
49 #include <sys/mbuf.h>
50 #include <sys/mount.h>
51 #include <sys/proc.h>
52 #include <sys/namei.h>
53 #include <sys/reboot.h>
54 #include <sys/socket.h>
55 #include <sys/stat.h>
56 #include <sys/sysctl.h>
57 #include <sys/syslog.h>
58 #include <sys/vmmeter.h>
59 #include <sys/vnode.h>
60 #include <sys/vfsops.h>
62 #include <machine/limits.h>
64 #include <vm/vm.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_extern.h>
67 #include <vm/vm_kern.h>
68 #include <vm/pmap.h>
69 #include <vm/vm_map.h>
70 #include <vm/vm_page.h>
71 #include <vm/vm_pager.h>
72 #include <vm/vnode_pager.h>
73 #include <vm/vm_zone.h>
75 #include <sys/buf2.h>
76 #include <sys/thread2.h>
78 #define VDESCNAME(name) __CONCAT(__CONCAT(vop_,name),_desc)
80 #define VNODEOP_DESC_INIT(name) \
81 struct syslink_desc VDESCNAME(name) = { \
82 __offsetof(struct vop_ops, __CONCAT(vop_, name)), \
83 #name }
85 VNODEOP_DESC_INIT(default);
86 VNODEOP_DESC_INIT(old_lookup);
87 VNODEOP_DESC_INIT(old_create);
88 VNODEOP_DESC_INIT(old_whiteout);
89 VNODEOP_DESC_INIT(old_mknod);
90 VNODEOP_DESC_INIT(open);
91 VNODEOP_DESC_INIT(close);
92 VNODEOP_DESC_INIT(access);
93 VNODEOP_DESC_INIT(getattr);
94 VNODEOP_DESC_INIT(setattr);
95 VNODEOP_DESC_INIT(read);
96 VNODEOP_DESC_INIT(write);
97 VNODEOP_DESC_INIT(ioctl);
98 VNODEOP_DESC_INIT(poll);
99 VNODEOP_DESC_INIT(kqfilter);
100 VNODEOP_DESC_INIT(revoke);
101 VNODEOP_DESC_INIT(mmap);
102 VNODEOP_DESC_INIT(fsync);
103 VNODEOP_DESC_INIT(old_remove);
104 VNODEOP_DESC_INIT(old_link);
105 VNODEOP_DESC_INIT(old_rename);
107 VNODEOP_DESC_INIT(old_mkdir);
108 VNODEOP_DESC_INIT(old_rmdir);
109 VNODEOP_DESC_INIT(old_symlink);
110 VNODEOP_DESC_INIT(readdir);
111 VNODEOP_DESC_INIT(readlink);
112 VNODEOP_DESC_INIT(inactive);
113 VNODEOP_DESC_INIT(reclaim);
114 VNODEOP_DESC_INIT(bmap);
115 VNODEOP_DESC_INIT(strategy);
116 VNODEOP_DESC_INIT(print);
117 VNODEOP_DESC_INIT(pathconf);
118 VNODEOP_DESC_INIT(advlock);
119 VNODEOP_DESC_INIT(balloc);
120 VNODEOP_DESC_INIT(reallocblks);
121 VNODEOP_DESC_INIT(getpages);
122 VNODEOP_DESC_INIT(putpages);
123 VNODEOP_DESC_INIT(freeblks);
124 VNODEOP_DESC_INIT(getacl);
125 VNODEOP_DESC_INIT(setacl);
126 VNODEOP_DESC_INIT(aclcheck);
127 VNODEOP_DESC_INIT(getextattr);
128 VNODEOP_DESC_INIT(setextattr);
129 VNODEOP_DESC_INIT(mountctl);
131 VNODEOP_DESC_INIT(nresolve);
132 VNODEOP_DESC_INIT(nlookupdotdot);
133 VNODEOP_DESC_INIT(ncreate);
134 VNODEOP_DESC_INIT(nmkdir);
135 VNODEOP_DESC_INIT(nmknod);
136 VNODEOP_DESC_INIT(nlink);
137 VNODEOP_DESC_INIT(nsymlink);
138 VNODEOP_DESC_INIT(nwhiteout);
139 VNODEOP_DESC_INIT(nremove);
140 VNODEOP_DESC_INIT(nrmdir);
141 VNODEOP_DESC_INIT(nrename);
143 #define DO_OPS(ops, error, ap, vop_field) \
144 error = ops->vop_field(ap);
146 /************************************************************************
147 * PRIMARY HIGH LEVEL VNODE OPERATIONS CALLS *
148 ************************************************************************
150 * These procedures are called directly from the kernel and/or fileops
151 * code to perform file/device operations on the system.
153 * NOTE: The old namespace api functions such as vop_rename() are no longer
154 * available for general use and have been renamed to vop_old_*(). Only
155 * the code in vfs_default.c is allowed to call those ops.
159 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
160 struct vnode **vpp, struct componentname *cnp)
162 struct vop_old_lookup_args ap;
163 int error;
165 ap.a_head.a_desc = &vop_old_lookup_desc;
166 ap.a_head.a_ops = ops;
167 ap.a_dvp = dvp;
168 ap.a_vpp = vpp;
169 ap.a_cnp = cnp;
171 DO_OPS(ops, error, &ap, vop_old_lookup);
172 return(error);
176 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
177 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
179 struct vop_old_create_args ap;
180 int error;
182 ap.a_head.a_desc = &vop_old_create_desc;
183 ap.a_head.a_ops = ops;
184 ap.a_dvp = dvp;
185 ap.a_vpp = vpp;
186 ap.a_cnp = cnp;
187 ap.a_vap = vap;
189 DO_OPS(ops, error, &ap, vop_old_create);
190 return(error);
194 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
195 struct componentname *cnp, int flags)
197 struct vop_old_whiteout_args ap;
198 int error;
200 ap.a_head.a_desc = &vop_old_whiteout_desc;
201 ap.a_head.a_ops = ops;
202 ap.a_dvp = dvp;
203 ap.a_cnp = cnp;
204 ap.a_flags = flags;
206 DO_OPS(ops, error, &ap, vop_old_whiteout);
207 return(error);
211 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
212 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
214 struct vop_old_mknod_args ap;
215 int error;
217 ap.a_head.a_desc = &vop_old_mknod_desc;
218 ap.a_head.a_ops = ops;
219 ap.a_dvp = dvp;
220 ap.a_vpp = vpp;
221 ap.a_cnp = cnp;
222 ap.a_vap = vap;
224 DO_OPS(ops, error, &ap, vop_old_mknod);
225 return(error);
229 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
230 struct file *fp)
232 struct vop_open_args ap;
233 int error;
235 ap.a_head.a_desc = &vop_open_desc;
236 ap.a_head.a_ops = ops;
237 ap.a_vp = vp;
238 ap.a_fp = fp;
239 ap.a_mode = mode;
240 ap.a_cred = cred;
242 DO_OPS(ops, error, &ap, vop_open);
243 return(error);
247 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag)
249 struct vop_close_args ap;
250 int error;
252 ap.a_head.a_desc = &vop_close_desc;
253 ap.a_head.a_ops = ops;
254 ap.a_vp = vp;
255 ap.a_fflag = fflag;
257 DO_OPS(ops, error, &ap, vop_close);
258 return(error);
262 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred)
264 struct vop_access_args ap;
265 int error;
267 ap.a_head.a_desc = &vop_access_desc;
268 ap.a_head.a_ops = ops;
269 ap.a_vp = vp;
270 ap.a_mode = mode;
271 ap.a_cred = cred;
273 DO_OPS(ops, error, &ap, vop_access);
274 return(error);
278 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
280 struct vop_getattr_args ap;
281 int error;
283 ap.a_head.a_desc = &vop_getattr_desc;
284 ap.a_head.a_ops = ops;
285 ap.a_vp = vp;
286 ap.a_vap = vap;
288 DO_OPS(ops, error, &ap, vop_getattr);
291 * mount pointer may be NULL if vnode is dead.
293 if (ops->head.vv_mount &&
294 (ops->head.vv_mount->mnt_kern_flag & MNTK_FSMID) == 0) {
295 vap->va_fsmid = cache_sync_fsmid_vp(vp);
297 return(error);
301 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
302 struct ucred *cred)
304 struct vop_setattr_args ap;
305 int error;
307 ap.a_head.a_desc = &vop_setattr_desc;
308 ap.a_head.a_ops = ops;
309 ap.a_vp = vp;
310 ap.a_vap = vap;
311 ap.a_cred = cred;
313 DO_OPS(ops, error, &ap, vop_setattr);
314 if (error == 0)
315 cache_update_fsmid_vp(vp);
316 return(error);
320 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
321 struct ucred *cred)
323 struct vop_read_args ap;
324 int error;
326 ap.a_head.a_desc = &vop_read_desc;
327 ap.a_head.a_ops = ops;
328 ap.a_vp = vp;
329 ap.a_uio = uio;
330 ap.a_ioflag = ioflag;
331 ap.a_cred = cred;
333 DO_OPS(ops, error, &ap, vop_read);
334 return(error);
338 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
339 struct ucred *cred)
341 struct vop_write_args ap;
342 int error;
344 ap.a_head.a_desc = &vop_write_desc;
345 ap.a_head.a_ops = ops;
346 ap.a_vp = vp;
347 ap.a_uio = uio;
348 ap.a_ioflag = ioflag;
349 ap.a_cred = cred;
351 DO_OPS(ops, error, &ap, vop_write);
352 if (error == 0)
353 cache_update_fsmid_vp(vp);
354 return(error);
358 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
359 int fflag, struct ucred *cred)
361 struct vop_ioctl_args ap;
362 int error;
364 ap.a_head.a_desc = &vop_ioctl_desc;
365 ap.a_head.a_ops = ops;
366 ap.a_vp = vp;
367 ap.a_command = command;
368 ap.a_data = data;
369 ap.a_fflag = fflag;
370 ap.a_cred = cred;
372 DO_OPS(ops, error, &ap, vop_ioctl);
373 return(error);
377 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
379 struct vop_poll_args ap;
380 int error;
382 ap.a_head.a_desc = &vop_poll_desc;
383 ap.a_head.a_ops = ops;
384 ap.a_vp = vp;
385 ap.a_events = events;
386 ap.a_cred = cred;
388 DO_OPS(ops, error, &ap, vop_poll);
389 return(error);
393 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
395 struct vop_kqfilter_args ap;
396 int error;
398 ap.a_head.a_desc = &vop_kqfilter_desc;
399 ap.a_head.a_ops = ops;
400 ap.a_vp = vp;
401 ap.a_kn = kn;
403 DO_OPS(ops, error, &ap, vop_kqfilter);
404 return(error);
408 vop_revoke(struct vop_ops *ops, struct vnode *vp, int flags)
410 struct vop_revoke_args ap;
411 int error;
413 ap.a_head.a_desc = &vop_revoke_desc;
414 ap.a_head.a_ops = ops;
415 ap.a_vp = vp;
416 ap.a_flags = flags;
418 DO_OPS(ops, error, &ap, vop_revoke);
419 return(error);
423 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
425 struct vop_mmap_args ap;
426 int error;
428 ap.a_head.a_desc = &vop_mmap_desc;
429 ap.a_head.a_ops = ops;
430 ap.a_vp = vp;
431 ap.a_fflags = fflags;
432 ap.a_cred = cred;
434 DO_OPS(ops, error, &ap, vop_mmap);
435 return(error);
439 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor)
441 struct vop_fsync_args ap;
442 int error;
444 ap.a_head.a_desc = &vop_fsync_desc;
445 ap.a_head.a_ops = ops;
446 ap.a_vp = vp;
447 ap.a_waitfor = waitfor;
449 DO_OPS(ops, error, &ap, vop_fsync);
450 return(error);
454 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
455 struct vnode *vp, struct componentname *cnp)
457 struct vop_old_remove_args ap;
458 int error;
460 ap.a_head.a_desc = &vop_old_remove_desc;
461 ap.a_head.a_ops = ops;
462 ap.a_dvp = dvp;
463 ap.a_vp = vp;
464 ap.a_cnp = cnp;
466 DO_OPS(ops, error, &ap, vop_old_remove);
467 return(error);
471 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
472 struct vnode *vp, struct componentname *cnp)
474 struct vop_old_link_args ap;
475 int error;
477 ap.a_head.a_desc = &vop_old_link_desc;
478 ap.a_head.a_ops = ops;
479 ap.a_tdvp = tdvp;
480 ap.a_vp = vp;
481 ap.a_cnp = cnp;
483 DO_OPS(ops, error, &ap, vop_old_link);
484 return(error);
488 vop_old_rename(struct vop_ops *ops,
489 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
490 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
492 struct vop_old_rename_args ap;
493 int error;
495 ap.a_head.a_desc = &vop_old_rename_desc;
496 ap.a_head.a_ops = ops;
497 ap.a_fdvp = fdvp;
498 ap.a_fvp = fvp;
499 ap.a_fcnp = fcnp;
500 ap.a_tdvp = tdvp;
501 ap.a_tvp = tvp;
502 ap.a_tcnp = tcnp;
504 DO_OPS(ops, error, &ap, vop_old_rename);
505 return(error);
509 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
510 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
512 struct vop_old_mkdir_args ap;
513 int error;
515 ap.a_head.a_desc = &vop_old_mkdir_desc;
516 ap.a_head.a_ops = ops;
517 ap.a_dvp = dvp;
518 ap.a_vpp = vpp;
519 ap.a_cnp = cnp;
520 ap.a_vap = vap;
522 DO_OPS(ops, error, &ap, vop_old_mkdir);
523 return(error);
527 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
528 struct vnode *vp, struct componentname *cnp)
530 struct vop_old_rmdir_args ap;
531 int error;
533 ap.a_head.a_desc = &vop_old_rmdir_desc;
534 ap.a_head.a_ops = ops;
535 ap.a_dvp = dvp;
536 ap.a_vp = vp;
537 ap.a_cnp = cnp;
539 DO_OPS(ops, error, &ap, vop_old_rmdir);
540 return(error);
544 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
545 struct vnode **vpp, struct componentname *cnp,
546 struct vattr *vap, char *target)
548 struct vop_old_symlink_args ap;
549 int error;
551 ap.a_head.a_desc = &vop_old_symlink_desc;
552 ap.a_head.a_ops = ops;
553 ap.a_dvp = dvp;
554 ap.a_vpp = vpp;
555 ap.a_cnp = cnp;
556 ap.a_vap = vap;
557 ap.a_target = target;
559 DO_OPS(ops, error, &ap, vop_old_symlink);
560 return(error);
564 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
565 struct ucred *cred, int *eofflag, int *ncookies, u_long **cookies)
567 struct vop_readdir_args ap;
568 int error;
570 ap.a_head.a_desc = &vop_readdir_desc;
571 ap.a_head.a_ops = ops;
572 ap.a_vp = vp;
573 ap.a_uio = uio;
574 ap.a_cred = cred;
575 ap.a_eofflag = eofflag;
576 ap.a_ncookies = ncookies;
577 ap.a_cookies = cookies;
579 DO_OPS(ops, error, &ap, vop_readdir);
580 return(error);
584 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
585 struct ucred *cred)
587 struct vop_readlink_args ap;
588 int error;
590 ap.a_head.a_desc = &vop_readlink_desc;
591 ap.a_head.a_ops = ops;
592 ap.a_vp = vp;
593 ap.a_uio = uio;
594 ap.a_cred = cred;
596 DO_OPS(ops, error, &ap, vop_readlink);
597 return(error);
601 vop_inactive(struct vop_ops *ops, struct vnode *vp)
603 struct vop_inactive_args ap;
604 int error;
606 ap.a_head.a_desc = &vop_inactive_desc;
607 ap.a_head.a_ops = ops;
608 ap.a_vp = vp;
610 DO_OPS(ops, error, &ap, vop_inactive);
611 return(error);
615 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
617 struct vop_reclaim_args ap;
618 int error;
620 ap.a_head.a_desc = &vop_reclaim_desc;
621 ap.a_head.a_ops = ops;
622 ap.a_vp = vp;
624 DO_OPS(ops, error, &ap, vop_reclaim);
625 return(error);
629 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
630 struct vnode **vpp, off_t *doffsetp, int *runp, int *runb)
632 struct vop_bmap_args ap;
633 int error;
635 ap.a_head.a_desc = &vop_bmap_desc;
636 ap.a_head.a_ops = ops;
637 ap.a_vp = vp;
638 ap.a_loffset = loffset;
639 ap.a_vpp = vpp;
640 ap.a_doffsetp = doffsetp;
641 ap.a_runp = runp;
642 ap.a_runb = runb;
644 DO_OPS(ops, error, &ap, vop_bmap);
645 return(error);
649 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
651 struct vop_strategy_args ap;
652 int error;
654 ap.a_head.a_desc = &vop_strategy_desc;
655 ap.a_head.a_ops = ops;
656 ap.a_vp = vp;
657 ap.a_bio = bio;
659 DO_OPS(ops, error, &ap, vop_strategy);
660 if (error == 0 && bio->bio_buf->b_cmd != BUF_CMD_READ)
661 cache_update_fsmid_vp(vp);
662 return(error);
666 vop_print(struct vop_ops *ops, struct vnode *vp)
668 struct vop_print_args ap;
669 int error;
671 ap.a_head.a_desc = &vop_print_desc;
672 ap.a_head.a_ops = ops;
673 ap.a_vp = vp;
675 DO_OPS(ops, error, &ap, vop_print);
676 return(error);
680 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
681 register_t *retval)
683 struct vop_pathconf_args ap;
684 int error;
686 ap.a_head.a_desc = &vop_pathconf_desc;
687 ap.a_head.a_ops = ops;
688 ap.a_vp = vp;
689 ap.a_name = name;
690 ap.a_retval = retval;
692 DO_OPS(ops, error, &ap, vop_pathconf);
693 return(error);
697 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
698 struct flock *fl, int flags)
700 struct vop_advlock_args ap;
701 int error;
703 ap.a_head.a_desc = &vop_advlock_desc;
704 ap.a_head.a_ops = ops;
705 ap.a_vp = vp;
706 ap.a_id = id;
707 ap.a_op = op;
708 ap.a_fl = fl;
709 ap.a_flags = flags;
711 DO_OPS(ops, error, &ap, vop_advlock);
712 return(error);
716 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
717 int size, struct ucred *cred, int flags,
718 struct buf **bpp)
720 struct vop_balloc_args ap;
721 int error;
723 ap.a_head.a_desc = &vop_balloc_desc;
724 ap.a_head.a_ops = ops;
725 ap.a_vp = vp;
726 ap.a_startoffset = startoffset;
727 ap.a_size = size;
728 ap.a_cred = cred;
729 ap.a_flags = flags;
730 ap.a_bpp = bpp;
732 DO_OPS(ops, error, &ap, vop_balloc);
733 return(error);
737 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
738 struct cluster_save *buflist)
740 struct vop_reallocblks_args ap;
741 int error;
743 ap.a_head.a_desc = &vop_reallocblks_desc;
744 ap.a_head.a_ops = ops;
745 ap.a_vp = vp;
746 ap.a_buflist = buflist;
748 DO_OPS(ops, error, &ap, vop_reallocblks);
749 return(error);
753 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
754 int reqpage, vm_ooffset_t offset)
756 struct vop_getpages_args ap;
757 int error;
759 ap.a_head.a_desc = &vop_getpages_desc;
760 ap.a_head.a_ops = ops;
761 ap.a_vp = vp;
762 ap.a_m = m;
763 ap.a_count = count;
764 ap.a_reqpage = reqpage;
765 ap.a_offset = offset;
767 DO_OPS(ops, error, &ap, vop_getpages);
768 return(error);
772 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
773 int sync, int *rtvals, vm_ooffset_t offset)
775 struct vop_putpages_args ap;
776 int error;
778 ap.a_head.a_desc = &vop_putpages_desc;
779 ap.a_head.a_ops = ops;
780 ap.a_vp = vp;
781 ap.a_m = m;
782 ap.a_count = count;
783 ap.a_sync = sync;
784 ap.a_rtvals = rtvals;
785 ap.a_offset = offset;
787 DO_OPS(ops, error, &ap, vop_putpages);
788 if (error == 0)
789 cache_update_fsmid_vp(vp);
790 return(error);
794 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
796 struct vop_freeblks_args ap;
797 int error;
799 ap.a_head.a_desc = &vop_freeblks_desc;
800 ap.a_head.a_ops = ops;
801 ap.a_vp = vp;
802 ap.a_offset = offset;
803 ap.a_length = length;
805 DO_OPS(ops, error, &ap, vop_freeblks);
806 return(error);
810 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
811 struct acl *aclp, struct ucred *cred)
813 struct vop_getacl_args ap;
814 int error;
816 ap.a_head.a_desc = &vop_getacl_desc;
817 ap.a_head.a_ops = ops;
818 ap.a_vp = vp;
819 ap.a_type = type;
820 ap.a_aclp = aclp;
821 ap.a_cred = cred;
823 DO_OPS(ops, error, &ap, vop_getacl);
824 return(error);
828 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
829 struct acl *aclp, struct ucred *cred)
831 struct vop_setacl_args ap;
832 int error;
834 ap.a_head.a_desc = &vop_setacl_desc;
835 ap.a_head.a_ops = ops;
836 ap.a_vp = vp;
837 ap.a_type = type;
838 ap.a_aclp = aclp;
839 ap.a_cred = cred;
841 DO_OPS(ops, error, &ap, vop_setacl);
842 if (error == 0)
843 cache_update_fsmid_vp(vp);
844 return(error);
848 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
849 struct acl *aclp, struct ucred *cred)
851 struct vop_aclcheck_args ap;
852 int error;
854 ap.a_head.a_desc = &vop_aclcheck_desc;
855 ap.a_head.a_ops = ops;
856 ap.a_vp = vp;
857 ap.a_type = type;
858 ap.a_aclp = aclp;
859 ap.a_cred = cred;
861 DO_OPS(ops, error, &ap, vop_aclcheck);
862 return(error);
866 vop_getextattr(struct vop_ops *ops, struct vnode *vp, char *name,
867 struct uio *uio, struct ucred *cred)
869 struct vop_getextattr_args ap;
870 int error;
872 ap.a_head.a_desc = &vop_getextattr_desc;
873 ap.a_head.a_ops = ops;
874 ap.a_vp = vp;
875 ap.a_name = name;
876 ap.a_uio = uio;
877 ap.a_cred = cred;
879 DO_OPS(ops, error, &ap, vop_getextattr);
880 return(error);
884 vop_setextattr(struct vop_ops *ops, struct vnode *vp, char *name,
885 struct uio *uio, struct ucred *cred)
887 struct vop_setextattr_args ap;
888 int error;
890 ap.a_head.a_desc = &vop_setextattr_desc;
891 ap.a_head.a_ops = ops;
892 ap.a_vp = vp;
893 ap.a_name = name;
894 ap.a_uio = uio;
895 ap.a_cred = cred;
897 DO_OPS(ops, error, &ap, vop_setextattr);
898 if (error == 0)
899 cache_update_fsmid_vp(vp);
900 return(error);
904 vop_mountctl(struct vop_ops *ops, int op, struct file *fp,
905 const void *ctl, int ctllen, void *buf, int buflen, int *res)
907 struct vop_mountctl_args ap;
908 int error;
910 ap.a_head.a_desc = &vop_mountctl_desc;
911 ap.a_head.a_ops = ops;
912 ap.a_op = op;
913 ap.a_ctl = ctl;
914 ap.a_fp = fp;
915 ap.a_ctllen = ctllen;
916 ap.a_buf = buf;
917 ap.a_buflen = buflen;
918 ap.a_res = res;
920 DO_OPS(ops, error, &ap, vop_mountctl);
921 return(error);
925 * NEW API FUNCTIONS
927 * nresolve takes a locked ncp and a cred and resolves the ncp into a
928 * positive or negative hit.
930 * The namecache is automatically adjusted by this function. The ncp
931 * is left locked on return.
934 vop_nresolve(struct vop_ops *ops, struct nchandle *nch, struct ucred *cred)
936 struct vop_nresolve_args ap;
937 int error;
939 ap.a_head.a_desc = &vop_nresolve_desc;
940 ap.a_head.a_ops = ops;
941 ap.a_nch = nch;
942 ap.a_cred = cred;
944 DO_OPS(ops, error, &ap, vop_nresolve);
945 return(error);
949 * nlookupdotdot takes an unlocked directory, dvp, and looks up "..", returning
950 * a locked parent directory in *vpp. If an error occurs *vpp will be NULL.
953 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
954 struct vnode **vpp, struct ucred *cred)
956 struct vop_nlookupdotdot_args ap;
957 int error;
959 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
960 ap.a_head.a_ops = ops;
961 ap.a_dvp = dvp;
962 ap.a_vpp = vpp;
963 ap.a_cred = cred;
965 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
966 return(error);
970 * ncreate takes a locked, resolved ncp that typically represents a negative
971 * cache hit and creates the file or node specified by the ncp, cred, and
972 * vattr. If no error occurs a locked vnode is returned in *vpp.
974 * The namecache is automatically adjusted by this function. The ncp
975 * is left locked on return.
978 vop_ncreate(struct vop_ops *ops, struct nchandle *nch,
979 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
981 struct vop_ncreate_args ap;
982 int error;
984 ap.a_head.a_desc = &vop_ncreate_desc;
985 ap.a_head.a_ops = ops;
986 ap.a_nch = nch;
987 ap.a_vpp = vpp;
988 ap.a_cred = cred;
989 ap.a_vap = vap;
991 DO_OPS(ops, error, &ap, vop_ncreate);
992 if (error == 0 && *vpp)
993 cache_update_fsmid_vp(*vpp);
994 return(error);
998 * nmkdir takes a locked, resolved ncp that typically represents a negative
999 * cache hit and creates the directory specified by the ncp, cred, and
1000 * vattr. If no error occurs a locked vnode is returned in *vpp.
1002 * The namecache is automatically adjusted by this function. The ncp
1003 * is left locked on return.
1006 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch,
1007 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1009 struct vop_nmkdir_args ap;
1010 int error;
1012 ap.a_head.a_desc = &vop_nmkdir_desc;
1013 ap.a_head.a_ops = ops;
1014 ap.a_nch = nch;
1015 ap.a_vpp = vpp;
1016 ap.a_cred = cred;
1017 ap.a_vap = vap;
1019 DO_OPS(ops, error, &ap, vop_nmkdir);
1020 if (error == 0 && *vpp)
1021 cache_update_fsmid_vp(*vpp);
1022 return(error);
1026 * nmknod takes a locked, resolved ncp that typically represents a negative
1027 * cache hit and creates the node specified by the ncp, cred, and
1028 * vattr. If no error occurs a locked vnode is returned in *vpp.
1030 * The namecache is automatically adjusted by this function. The ncp
1031 * is left locked on return.
1034 vop_nmknod(struct vop_ops *ops, struct nchandle *nch,
1035 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1037 struct vop_nmknod_args ap;
1038 int error;
1040 ap.a_head.a_desc = &vop_nmknod_desc;
1041 ap.a_head.a_ops = ops;
1042 ap.a_nch = nch;
1043 ap.a_vpp = vpp;
1044 ap.a_cred = cred;
1045 ap.a_vap = vap;
1047 DO_OPS(ops, error, &ap, vop_nmknod);
1048 if (error == 0 && *vpp)
1049 cache_update_fsmid_vp(*vpp);
1050 return(error);
1054 * nlink takes a locked, resolved ncp that typically represents a negative
1055 * cache hit and creates the node specified by the ncp, cred, and
1056 * existing vnode. The passed vp must be locked and will remain locked
1057 * on return, as does the ncp, whether an error occurs or not.
1059 * The namecache is automatically adjusted by this function. The ncp
1060 * is left locked on return.
1063 vop_nlink(struct vop_ops *ops, struct nchandle *nch,
1064 struct vnode *vp, struct ucred *cred)
1066 struct vop_nlink_args ap;
1067 int error;
1069 ap.a_head.a_desc = &vop_nlink_desc;
1070 ap.a_head.a_ops = ops;
1071 ap.a_nch = nch;
1072 ap.a_vp = vp;
1073 ap.a_cred = cred;
1075 DO_OPS(ops, error, &ap, vop_nlink);
1076 if (error == 0)
1077 cache_update_fsmid(nch);
1078 return(error);
1082 * nsymlink takes a locked, resolved ncp that typically represents a negative
1083 * cache hit and creates a symbolic link based on cred, vap, and target (the
1084 * contents of the link). If no error occurs a locked vnode is returned in
1085 * *vpp.
1087 * The namecache is automatically adjusted by this function. The ncp
1088 * is left locked on return.
1091 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch,
1092 struct vnode **vpp, struct ucred *cred,
1093 struct vattr *vap, char *target)
1095 struct vop_nsymlink_args ap;
1096 int error;
1098 ap.a_head.a_desc = &vop_nsymlink_desc;
1099 ap.a_head.a_ops = ops;
1100 ap.a_nch = nch;
1101 ap.a_vpp = vpp;
1102 ap.a_cred = cred;
1103 ap.a_vap = vap;
1104 ap.a_target = target;
1106 DO_OPS(ops, error, &ap, vop_nsymlink);
1107 if (error == 0)
1108 cache_update_fsmid(nch);
1109 return(error);
1113 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1114 * negative hit and executes the whiteout function specified in flags.
1116 * The namecache is automatically adjusted by this function. The ncp
1117 * is left locked on return.
1120 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch,
1121 struct ucred *cred, int flags)
1123 struct vop_nwhiteout_args ap;
1124 int error;
1126 ap.a_head.a_desc = &vop_nwhiteout_desc;
1127 ap.a_head.a_ops = ops;
1128 ap.a_nch = nch;
1129 ap.a_cred = cred;
1130 ap.a_flags = flags;
1132 DO_OPS(ops, error, &ap, vop_nwhiteout);
1133 if (error == 0)
1134 cache_update_fsmid(nch);
1135 return(error);
1139 * nremove takes a locked, resolved ncp that generally represents a
1140 * positive hit and removes the file.
1142 * The namecache is automatically adjusted by this function. The ncp
1143 * is left locked on return.
1146 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct ucred *cred)
1148 struct vop_nremove_args ap;
1149 int error;
1151 ap.a_head.a_desc = &vop_nremove_desc;
1152 ap.a_head.a_ops = ops;
1153 ap.a_nch = nch;
1154 ap.a_cred = cred;
1156 DO_OPS(ops, error, &ap, vop_nremove);
1157 if (error == 0)
1158 cache_update_fsmid(nch);
1159 return(error);
1163 * nrmdir takes a locked, resolved ncp that generally represents a
1164 * directory and removes the directory.
1166 * The namecache is automatically adjusted by this function. The ncp
1167 * is left locked on return.
1170 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct ucred *cred)
1172 struct vop_nrmdir_args ap;
1173 int error;
1175 ap.a_head.a_desc = &vop_nrmdir_desc;
1176 ap.a_head.a_ops = ops;
1177 ap.a_nch = nch;
1178 ap.a_cred = cred;
1180 DO_OPS(ops, error, &ap, vop_nrmdir);
1181 if (error == 0)
1182 cache_update_fsmid(nch);
1183 return(error);
1187 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1188 * and renames the source ncp to the target ncp. The target ncp may
1189 * represent a positive or negative hit.
1191 * The namecache is automatically adjusted by this function. The ncp
1192 * is left locked on return. The source ncp is typically changed to
1193 * a negative cache hit and the target ncp typically takes on the
1194 * source ncp's underlying file.
1197 vop_nrename(struct vop_ops *ops, struct nchandle *fnch,
1198 struct nchandle *tnch, struct ucred *cred)
1200 struct vop_nrename_args ap;
1201 int error;
1203 ap.a_head.a_desc = &vop_nrename_desc;
1204 ap.a_head.a_ops = ops;
1205 ap.a_fnch = fnch;
1206 ap.a_tnch = tnch;
1207 ap.a_cred = cred;
1209 DO_OPS(ops, error, &ap, vop_nrename);
1210 if (error == 0) {
1211 cache_update_fsmid(fnch);
1212 cache_update_fsmid(tnch);
1214 return(error);
1217 /************************************************************************
1218 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1219 ************************************************************************
1221 * These procedures are called from VFSs such as unionfs and nullfs
1222 * when they wish to forward an operation on one VFS to another. The
1223 * argument structure/message is modified and then directly passed to the
1224 * appropriate routine. This routines may also be called by initiators
1225 * who have an argument structure in hand rather then discreet arguments.
1228 vop_vnoperate_ap(struct vop_generic_args *ap)
1230 struct vop_ops *ops;
1231 int error;
1233 ops = ap->a_ops;
1234 error = VOCALL(ops, ap);
1236 return (error);
1240 * This routine is called by the cache coherency layer to execute the actual
1241 * VFS operation. If a journaling layer is present we call though it, else
1242 * we call the native VOP functions.
1245 vop_cache_operate_ap(struct vop_generic_args *ap)
1247 struct vop_ops *ops;
1248 int error;
1250 ops = ap->a_ops;
1251 if (ops->head.vv_mount->mnt_vn_journal_ops)
1252 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1253 else
1254 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1255 return (error);
1260 * This routine is called by the journaling layer to execute the actual
1261 * VFS operation.
1264 vop_journal_operate_ap(struct vop_generic_args *ap)
1266 struct vop_ops *ops;
1267 int error;
1269 ops = ap->a_ops;
1270 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1272 return (error);
1276 vop_open_ap(struct vop_open_args *ap)
1278 int error;
1280 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1281 return(error);
1285 vop_close_ap(struct vop_close_args *ap)
1287 int error;
1289 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1290 return(error);
1294 vop_access_ap(struct vop_access_args *ap)
1296 int error;
1298 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1299 return(error);
1303 vop_getattr_ap(struct vop_getattr_args *ap)
1305 int error;
1307 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1308 return(error);
1312 vop_setattr_ap(struct vop_setattr_args *ap)
1314 int error;
1316 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1317 return(error);
1321 vop_read_ap(struct vop_read_args *ap)
1323 int error;
1325 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1326 return(error);
1330 vop_write_ap(struct vop_write_args *ap)
1332 int error;
1334 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1335 return(error);
1339 vop_ioctl_ap(struct vop_ioctl_args *ap)
1341 int error;
1343 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1344 return(error);
1348 vop_poll_ap(struct vop_poll_args *ap)
1350 int error;
1352 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1353 return(error);
1357 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1359 int error;
1361 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1362 return(error);
1366 vop_revoke_ap(struct vop_revoke_args *ap)
1368 int error;
1370 DO_OPS(ap->a_head.a_ops, error, ap, vop_revoke);
1371 return(error);
1375 vop_mmap_ap(struct vop_mmap_args *ap)
1377 int error;
1379 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1380 return(error);
1384 vop_fsync_ap(struct vop_fsync_args *ap)
1386 int error;
1388 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1389 return(error);
1393 vop_readdir_ap(struct vop_readdir_args *ap)
1395 int error;
1397 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1398 return(error);
1402 vop_readlink_ap(struct vop_readlink_args *ap)
1404 int error;
1406 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1407 return(error);
1411 vop_inactive_ap(struct vop_inactive_args *ap)
1413 int error;
1415 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1416 return(error);
1420 vop_reclaim_ap(struct vop_reclaim_args *ap)
1422 int error;
1424 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1425 return(error);
1429 vop_bmap_ap(struct vop_bmap_args *ap)
1431 int error;
1433 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1434 return(error);
1438 vop_strategy_ap(struct vop_strategy_args *ap)
1440 int error;
1442 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1443 return(error);
1447 vop_print_ap(struct vop_print_args *ap)
1449 int error;
1451 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1452 return(error);
1456 vop_pathconf_ap(struct vop_pathconf_args *ap)
1458 int error;
1460 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1461 return(error);
1465 vop_advlock_ap(struct vop_advlock_args *ap)
1467 int error;
1469 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1470 return(error);
1474 vop_balloc_ap(struct vop_balloc_args *ap)
1476 int error;
1478 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1479 return(error);
1483 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1485 int error;
1487 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1488 return(error);
1492 vop_getpages_ap(struct vop_getpages_args *ap)
1494 int error;
1496 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1497 return(error);
1501 vop_putpages_ap(struct vop_putpages_args *ap)
1503 int error;
1505 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1506 return(error);
1510 vop_freeblks_ap(struct vop_freeblks_args *ap)
1512 int error;
1514 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1515 return(error);
1519 vop_getacl_ap(struct vop_getacl_args *ap)
1521 int error;
1523 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1524 return(error);
1528 vop_setacl_ap(struct vop_setacl_args *ap)
1530 int error;
1532 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1533 return(error);
1537 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1539 int error;
1541 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1542 return(error);
1546 vop_getextattr_ap(struct vop_getextattr_args *ap)
1548 int error;
1550 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1551 return(error);
1555 vop_setextattr_ap(struct vop_setextattr_args *ap)
1557 int error;
1559 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1560 return(error);
1564 vop_mountctl_ap(struct vop_mountctl_args *ap)
1566 int error;
1568 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1569 return(error);
1573 vop_nresolve_ap(struct vop_nresolve_args *ap)
1575 int error;
1577 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1578 return(error);
1582 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1584 int error;
1586 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1587 return(error);
1591 vop_ncreate_ap(struct vop_ncreate_args *ap)
1593 int error;
1595 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1596 return(error);
1600 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1602 int error;
1604 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1605 return(error);
1609 vop_nmknod_ap(struct vop_nmknod_args *ap)
1611 int error;
1613 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
1614 return(error);
1618 vop_nlink_ap(struct vop_nlink_args *ap)
1620 int error;
1622 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
1623 return(error);
1627 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
1629 int error;
1631 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
1632 return(error);
1636 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
1638 int error;
1640 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
1641 return(error);
1645 vop_nremove_ap(struct vop_nremove_args *ap)
1647 int error;
1649 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
1650 return(error);
1654 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
1656 int error;
1658 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
1659 return(error);
1663 vop_nrename_ap(struct vop_nrename_args *ap)
1665 int error;
1667 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);
1668 return(error);