* Fix a number of cases where too much kernel memory might be allocated to
[dragonfly.git] / sys / vfs / ufs / ufs_vnops.c
1 /*
2  * Copyright (c) 1982, 1986, 1989, 1993, 1995
3  *      The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
39  * $FreeBSD: src/sys/ufs/ufs/ufs_vnops.c,v 1.131.2.8 2003/01/02 17:26:19 bde Exp $
40  * $DragonFly: src/sys/vfs/ufs/ufs_vnops.c,v 1.49 2006/05/26 16:56:34 dillon Exp $
41  */
42
43 #include "opt_quota.h"
44 #include "opt_suiddir.h"
45 #include "opt_ufs.h"
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
50 #include <sys/fcntl.h>
51 #include <sys/stat.h>
52 #include <sys/buf.h>
53 #include <sys/proc.h>
54 #include <sys/namei.h>
55 #include <sys/mount.h>
56 #include <sys/unistd.h>
57 #include <sys/vnode.h>
58 #include <sys/malloc.h>
59 #include <sys/dirent.h>
60 #include <sys/lockf.h>
61 #include <sys/event.h>
62 #include <sys/conf.h>
63
64 #include <sys/file.h>           /* XXX */
65 #include <sys/jail.h>
66
67 #include <vm/vm.h>
68 #include <vm/vm_extern.h>
69
70 #include <vfs/fifofs/fifo.h>
71
72 #include "quota.h"
73 #include "inode.h"
74 #include "dir.h"
75 #include "ufsmount.h"
76 #include "ufs_extern.h"
77 #ifdef UFS_DIRHASH
78 #include "dirhash.h"
79 #endif
80
81 static int ufs_access (struct vop_access_args *);
82 static int ufs_advlock (struct vop_advlock_args *);
83 static int ufs_chmod (struct vnode *, int, struct ucred *);
84 static int ufs_chown (struct vnode *, uid_t, gid_t, struct ucred *);
85 static int ufs_close (struct vop_close_args *);
86 static int ufs_create (struct vop_old_create_args *);
87 static int ufs_getattr (struct vop_getattr_args *);
88 static int ufs_link (struct vop_old_link_args *);
89 static int ufs_makeinode (int mode, struct vnode *, struct vnode **, struct componentname *);
90 static int ufs_missingop (struct vop_generic_args *ap);
91 static int ufs_mkdir (struct vop_old_mkdir_args *);
92 static int ufs_mknod (struct vop_old_mknod_args *);
93 static int ufs_mmap (struct vop_mmap_args *);
94 static int ufs_open (struct vop_open_args *);
95 static int ufs_pathconf (struct vop_pathconf_args *);
96 static int ufs_print (struct vop_print_args *);
97 static int ufs_readdir (struct vop_readdir_args *);
98 static int ufs_readlink (struct vop_readlink_args *);
99 static int ufs_remove (struct vop_old_remove_args *);
100 static int ufs_rename (struct vop_old_rename_args *);
101 static int ufs_rmdir (struct vop_old_rmdir_args *);
102 static int ufs_setattr (struct vop_setattr_args *);
103 static int ufs_strategy (struct vop_strategy_args *);
104 static int ufs_symlink (struct vop_old_symlink_args *);
105 static int ufs_whiteout (struct vop_old_whiteout_args *);
106 static int ufsfifo_close (struct vop_close_args *);
107 static int ufsfifo_kqfilter (struct vop_kqfilter_args *);
108 static int ufsfifo_read (struct vop_read_args *);
109 static int ufsfifo_write (struct vop_write_args *);
110 static int ufsspec_close (struct vop_close_args *);
111 static int ufsspec_read (struct vop_read_args *);
112 static int ufsspec_write (struct vop_write_args *);
113 static int filt_ufsread (struct knote *kn, long hint);
114 static int filt_ufswrite (struct knote *kn, long hint);
115 static int filt_ufsvnode (struct knote *kn, long hint);
116 static void filt_ufsdetach (struct knote *kn);
117 static int ufs_kqfilter (struct vop_kqfilter_args *ap);
118
119 union _qcvt {
120         int64_t qcvt;
121         int32_t val[2];
122 };
123 #define SETHIGH(q, h) { \
124         union _qcvt tmp; \
125         tmp.qcvt = (q); \
126         tmp.val[_QUAD_HIGHWORD] = (h); \
127         (q) = tmp.qcvt; \
128 }
129 #define SETLOW(q, l) { \
130         union _qcvt tmp; \
131         tmp.qcvt = (q); \
132         tmp.val[_QUAD_LOWWORD] = (l); \
133         (q) = tmp.qcvt; \
134 }
135 #define VN_KNOTE(vp, b) \
136         KNOTE(&vp->v_pollinfo.vpi_selinfo.si_note, (b))
137
138 #define OFSFMT(vp)              ((vp)->v_mount->mnt_maxsymlinklen <= 0)
139
140 /*
141  * A virgin directory (no blushing please).
142  */
143 static struct dirtemplate mastertemplate = {
144         0, 12, DT_DIR, 1, ".",
145         0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
146 };
147 static struct odirtemplate omastertemplate = {
148         0, 12, 1, ".",
149         0, DIRBLKSIZ - 12, 2, ".."
150 };
151
152 void
153 ufs_itimes(struct vnode *vp)
154 {
155         struct inode *ip;
156         struct timespec ts;
157
158         ip = VTOI(vp);
159         if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
160                 return;
161         if ((vp->v_type == VBLK || vp->v_type == VCHR) && !DOINGSOFTDEP(vp))
162                 ip->i_flag |= IN_LAZYMOD;
163         else
164                 ip->i_flag |= IN_MODIFIED;
165         if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
166                 vfs_timestamp(&ts);
167                 if (ip->i_flag & IN_ACCESS) {
168                         ip->i_atime = ts.tv_sec;
169                         ip->i_atimensec = ts.tv_nsec;
170                 }
171                 if (ip->i_flag & IN_UPDATE) {
172                         ip->i_mtime = ts.tv_sec;
173                         ip->i_mtimensec = ts.tv_nsec;
174                         ip->i_modrev++;
175                 }
176                 if (ip->i_flag & IN_CHANGE) {
177                         ip->i_ctime = ts.tv_sec;
178                         ip->i_ctimensec = ts.tv_nsec;
179                 }
180         }
181         ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
182 }
183
184 /*
185  * Create a regular file
186  *
187  * ufs_create(struct vnode *a_dvp, struct vnode **a_vpp,
188  *            struct componentname *a_cnp, struct vattr *a_vap)
189  */
190 static
191 int
192 ufs_create(struct vop_old_create_args *ap)
193 {
194         int error;
195
196         error =
197             ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
198             ap->a_dvp, ap->a_vpp, ap->a_cnp);
199         if (error)
200                 return (error);
201         VN_KNOTE(ap->a_dvp, NOTE_WRITE);
202         return (0);
203 }
204
205 /*
206  * Mknod vnode call
207  *
208  * ufs_mknod(struct vnode *a_dvp, struct vnode **a_vpp,
209  *           struct componentname *a_cnp, struct vattr *a_vap)
210  */
211 /* ARGSUSED */
212 static
213 int
214 ufs_mknod(struct vop_old_mknod_args *ap)
215 {
216         struct vattr *vap = ap->a_vap;
217         struct vnode **vpp = ap->a_vpp;
218         struct inode *ip;
219         ino_t ino;
220         int error;
221
222         error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
223             ap->a_dvp, vpp, ap->a_cnp);
224         if (error)
225                 return (error);
226         VN_KNOTE(ap->a_dvp, NOTE_WRITE);
227         ip = VTOI(*vpp);
228         ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
229         if (vap->va_rdev != VNOVAL) {
230                 /*
231                  * Want to be able to use this to make badblock
232                  * inodes, so don't truncate the dev number.
233                  */
234                 ip->i_rdev = vap->va_rdev;
235         }
236         /*
237          * Remove inode, then reload it through VFS_VGET so it is
238          * checked to see if it is an alias of an existing entry in
239          * the inode cache.
240          */
241         (*vpp)->v_type = VNON;
242         ino = ip->i_number;     /* Save this before vgone() invalidates ip. */
243         vgone(*vpp);
244         vput(*vpp);
245         error = VFS_VGET(ap->a_dvp->v_mount, ino, vpp);
246         if (error) {
247                 *vpp = NULL;
248                 return (error);
249         }
250         return (0);
251 }
252
253 /*
254  * Open called.
255  *
256  * Nothing to do.
257  *
258  * ufs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
259  *          struct thread *a_td)
260  */
261 /* ARGSUSED */
262 static
263 int
264 ufs_open(struct vop_open_args *ap)
265 {
266         struct vnode *vp = ap->a_vp;
267
268         /*
269          * Files marked append-only must be opened for appending.
270          */
271         if ((VTOI(vp)->i_flags & APPEND) &&
272             (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE) {
273                 return (EPERM);
274         }
275
276         return (vop_stdopen(ap));
277 }
278
279 /*
280  * Close called.
281  *
282  * Update the times on the inode.
283  *
284  * ufs_close(struct vnode *a_vp, int a_fflag, struct ucred *a_cred,
285  *           struct thread *a_td)
286  */
287 /* ARGSUSED */
288 static
289 int
290 ufs_close(struct vop_close_args *ap)
291 {
292         struct vnode *vp = ap->a_vp;
293
294         if (vp->v_usecount > 1)
295                 ufs_itimes(vp);
296         return (vop_stdclose(ap));
297 }
298
299 /*
300  * ufs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
301  *            struct thread *a_td)
302  */
303 static
304 int
305 ufs_access(struct vop_access_args *ap)
306 {
307         struct vnode *vp = ap->a_vp;
308         struct inode *ip = VTOI(vp);
309         struct ucred *cred = ap->a_cred;
310         mode_t mask, mode = ap->a_mode;
311         gid_t *gp;
312         int i;
313 #ifdef QUOTA
314         int error;
315 #endif
316
317         /*
318          * Disallow write attempts on read-only filesystems;
319          * unless the file is a socket, fifo, or a block or
320          * character device resident on the filesystem.
321          */
322         if (mode & VWRITE) {
323                 switch (vp->v_type) {
324                 case VDIR:
325                 case VLNK:
326                 case VREG:
327                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
328                                 return (EROFS);
329 #ifdef QUOTA
330                         if ((error = ufs_getinoquota(ip)) != 0)
331                                 return (error);
332 #endif
333                         break;
334                 default:
335                         break;
336                 }
337         }
338
339         /* If immutable bit set, nobody gets to write it. */
340         if ((mode & VWRITE) && (ip->i_flags & IMMUTABLE))
341                 return (EPERM);
342
343         /* Otherwise, user id 0 always gets access. */
344         if (cred->cr_uid == 0)
345                 return (0);
346
347         mask = 0;
348
349         /* Otherwise, check the owner. */
350         if (cred->cr_uid == ip->i_uid) {
351                 if (mode & VEXEC)
352                         mask |= S_IXUSR;
353                 if (mode & VREAD)
354                         mask |= S_IRUSR;
355                 if (mode & VWRITE)
356                         mask |= S_IWUSR;
357                 return ((ip->i_mode & mask) == mask ? 0 : EACCES);
358         }
359
360         /* Otherwise, check the groups. */
361         for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
362                 if (ip->i_gid == *gp) {
363                         if (mode & VEXEC)
364                                 mask |= S_IXGRP;
365                         if (mode & VREAD)
366                                 mask |= S_IRGRP;
367                         if (mode & VWRITE)
368                                 mask |= S_IWGRP;
369                         return ((ip->i_mode & mask) == mask ? 0 : EACCES);
370                 }
371
372         /* Otherwise, check everyone else. */
373         if (mode & VEXEC)
374                 mask |= S_IXOTH;
375         if (mode & VREAD)
376                 mask |= S_IROTH;
377         if (mode & VWRITE)
378                 mask |= S_IWOTH;
379         return ((ip->i_mode & mask) == mask ? 0 : EACCES);
380 }
381
382 /*
383  * ufs_getattr(struct vnode *a_vp, struct vattr *a_vap,
384  *              struct thread *a_td)
385  */
386 /* ARGSUSED */
387 static
388 int
389 ufs_getattr(struct vop_getattr_args *ap)
390 {
391         struct vnode *vp = ap->a_vp;
392         struct inode *ip = VTOI(vp);
393         struct vattr *vap = ap->a_vap;
394
395         /*
396          * This may cause i_fsmid to be updated even if no change (0)
397          * is returned, but we should only write out the inode if non-zero
398          * is returned and if the mount is read-write.
399          */
400         if (cache_check_fsmid_vp(vp, &ip->i_fsmid) &&
401             (vp->v_mount->mnt_flag & MNT_RDONLY) == 0
402         ) {
403                 ip->i_flag |= IN_LAZYMOD;
404         }
405
406         ufs_itimes(vp);
407         /*
408          * Copy from inode table
409          */
410         vap->va_fsid = dev2udev(ip->i_dev);
411         vap->va_fileid = ip->i_number;
412         vap->va_mode = ip->i_mode & ~IFMT;
413         vap->va_nlink = VFSTOUFS(vp->v_mount)->um_i_effnlink_valid ?
414             ip->i_effnlink : ip->i_nlink;
415         vap->va_uid = ip->i_uid;
416         vap->va_gid = ip->i_gid;
417         vap->va_rdev = ip->i_rdev;
418         vap->va_size = ip->i_din.di_size;
419         vap->va_atime.tv_sec = ip->i_atime;
420         vap->va_atime.tv_nsec = ip->i_atimensec;
421         vap->va_mtime.tv_sec = ip->i_mtime;
422         vap->va_mtime.tv_nsec = ip->i_mtimensec;
423         vap->va_ctime.tv_sec = ip->i_ctime;
424         vap->va_ctime.tv_nsec = ip->i_ctimensec;
425         vap->va_flags = ip->i_flags;
426         vap->va_gen = ip->i_gen;
427         vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
428         vap->va_bytes = dbtob((u_quad_t)ip->i_blocks);
429         vap->va_type = IFTOVT(ip->i_mode);
430         vap->va_filerev = ip->i_modrev;
431         vap->va_fsmid = ip->i_fsmid;
432         return (0);
433 }
434
435 /*
436  * Set attribute vnode op. called from several syscalls
437  *
438  * ufs_setattr(struct vnode *a_vp, struct vattr *a_vap,
439  *              struct ucred *a_cred, struct thread *a_td)
440  */
441 static
442 int
443 ufs_setattr(struct vop_setattr_args *ap)
444 {
445         struct vattr *vap = ap->a_vap;
446         struct vnode *vp = ap->a_vp;
447         struct inode *ip = VTOI(vp);
448         struct ucred *cred = ap->a_cred;
449         int error;
450
451         /*
452          * Check for unsettable attributes.
453          */
454         if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
455             (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
456             (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
457             ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
458                 return (EINVAL);
459         }
460         if (vap->va_flags != VNOVAL) {
461                 if (vp->v_mount->mnt_flag & MNT_RDONLY)
462                         return (EROFS);
463                 if (cred->cr_uid != ip->i_uid &&
464                     (error = suser_cred(cred, PRISON_ROOT)))
465                         return (error);
466                 /*
467                  * Note that a root chflags becomes a user chflags when
468                  * we are jailed, unless the jail.chflags_allowed sysctl
469                  * is set.
470                  */
471                 if (cred->cr_uid == 0 && 
472                     (!jailed(cred) || jail_chflags_allowed)) {
473                         if ((ip->i_flags
474                             & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) &&
475                             securelevel > 0)
476                                 return (EPERM);
477                         ip->i_flags = vap->va_flags;
478                 } else {
479                         if (ip->i_flags
480                             & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
481                             (vap->va_flags & UF_SETTABLE) != vap->va_flags)
482                                 return (EPERM);
483                         ip->i_flags &= SF_SETTABLE;
484                         ip->i_flags |= (vap->va_flags & UF_SETTABLE);
485                 }
486                 ip->i_flag |= IN_CHANGE;
487                 if (vap->va_flags & (IMMUTABLE | APPEND))
488                         return (0);
489         }
490         if (ip->i_flags & (IMMUTABLE | APPEND))
491                 return (EPERM);
492         /*
493          * Go through the fields and update iff not VNOVAL.
494          */
495         if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
496                 if (vp->v_mount->mnt_flag & MNT_RDONLY)
497                         return (EROFS);
498                 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred)) != 0)
499                         return (error);
500         }
501         if (vap->va_size != VNOVAL) {
502                 /*
503                  * Disallow write attempts on read-only filesystems;
504                  * unless the file is a socket, fifo, or a block or
505                  * character device resident on the filesystem.
506                  */
507                 switch (vp->v_type) {
508                 case VDIR:
509                         return (EISDIR);
510                 case VLNK:
511                 case VREG:
512                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
513                                 return (EROFS);
514                         break;
515                 default:
516                         break;
517                 }
518                 if ((error = UFS_TRUNCATE(vp, vap->va_size, 0, cred)) != 0)
519                         return (error);
520         }
521         ip = VTOI(vp);
522         if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
523                 if (vp->v_mount->mnt_flag & MNT_RDONLY)
524                         return (EROFS);
525                 if (cred->cr_uid != ip->i_uid &&
526                     (error = suser_cred(cred, PRISON_ROOT)) &&
527                     ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
528                     (error = VOP_ACCESS(vp, VWRITE, cred))))
529                         return (error);
530                 if (vap->va_atime.tv_sec != VNOVAL)
531                         ip->i_flag |= IN_ACCESS;
532                 if (vap->va_mtime.tv_sec != VNOVAL)
533                         ip->i_flag |= IN_CHANGE | IN_UPDATE;
534                 ufs_itimes(vp);
535                 if (vap->va_atime.tv_sec != VNOVAL) {
536                         ip->i_atime = vap->va_atime.tv_sec;
537                         ip->i_atimensec = vap->va_atime.tv_nsec;
538                 }
539                 if (vap->va_mtime.tv_sec != VNOVAL) {
540                         ip->i_mtime = vap->va_mtime.tv_sec;
541                         ip->i_mtimensec = vap->va_mtime.tv_nsec;
542                 }
543                 error = UFS_UPDATE(vp, 0);
544                 if (error)
545                         return (error);
546         }
547         error = 0;
548         if (vap->va_mode != (mode_t)VNOVAL) {
549                 if (vp->v_mount->mnt_flag & MNT_RDONLY)
550                         return (EROFS);
551                 error = ufs_chmod(vp, (int)vap->va_mode, cred);
552         }
553         VN_KNOTE(vp, NOTE_ATTRIB);
554         return (error);
555 }
556
557 /*
558  * Change the mode on a file.
559  * Inode must be locked before calling.
560  */
561 static int
562 ufs_chmod(struct vnode *vp, int mode, struct ucred *cred)
563 {
564         struct inode *ip = VTOI(vp);
565         int error;
566
567         if (cred->cr_uid != ip->i_uid) {
568             error = suser_cred(cred, PRISON_ROOT);
569             if (error)
570                 return (error);
571         }
572         if (cred->cr_uid) {
573                 if (vp->v_type != VDIR && (mode & S_ISTXT))
574                         return (EFTYPE);
575                 if (!groupmember(ip->i_gid, cred) && (mode & ISGID))
576                         return (EPERM);
577         }
578         ip->i_mode &= ~ALLPERMS;
579         ip->i_mode |= (mode & ALLPERMS);
580         ip->i_flag |= IN_CHANGE;
581         return (0);
582 }
583
584 /*
585  * Perform chown operation on inode ip;
586  * inode must be locked prior to call.
587  */
588 static int
589 ufs_chown(struct vnode *vp, uid_t uid, gid_t gid, struct ucred *cred)
590 {
591         struct inode *ip = VTOI(vp);
592         uid_t ouid;
593         gid_t ogid;
594         int error = 0;
595 #ifdef QUOTA
596         int i;
597         long change;
598 #endif
599
600         if (uid == (uid_t)VNOVAL)
601                 uid = ip->i_uid;
602         if (gid == (gid_t)VNOVAL)
603                 gid = ip->i_gid;
604         /*
605          * If we don't own the file, are trying to change the owner
606          * of the file, or are not a member of the target group,
607          * the caller must be superuser or the call fails.
608          */
609         if ((cred->cr_uid != ip->i_uid || uid != ip->i_uid ||
610             (gid != ip->i_gid && !(cred->cr_gid == gid ||
611             groupmember((gid_t)gid, cred)))) &&
612             (error = suser_cred(cred, PRISON_ROOT)))
613                 return (error);
614         ogid = ip->i_gid;
615         ouid = ip->i_uid;
616 #ifdef QUOTA
617         if ((error = ufs_getinoquota(ip)) != 0)
618                 return (error);
619         if (ouid == uid) {
620                 ufs_dqrele(vp, ip->i_dquot[USRQUOTA]);
621                 ip->i_dquot[USRQUOTA] = NODQUOT;
622         }
623         if (ogid == gid) {
624                 ufs_dqrele(vp, ip->i_dquot[GRPQUOTA]);
625                 ip->i_dquot[GRPQUOTA] = NODQUOT;
626         }
627         change = ip->i_blocks;
628         (void) ufs_chkdq(ip, -change, cred, CHOWN);
629         (void) ufs_chkiq(ip, -1, cred, CHOWN);
630         for (i = 0; i < MAXQUOTAS; i++) {
631                 ufs_dqrele(vp, ip->i_dquot[i]);
632                 ip->i_dquot[i] = NODQUOT;
633         }
634 #endif
635         ip->i_gid = gid;
636         ip->i_uid = uid;
637 #ifdef QUOTA
638         if ((error = ufs_getinoquota(ip)) == 0) {
639                 if (ouid == uid) {
640                         ufs_dqrele(vp, ip->i_dquot[USRQUOTA]);
641                         ip->i_dquot[USRQUOTA] = NODQUOT;
642                 }
643                 if (ogid == gid) {
644                         ufs_dqrele(vp, ip->i_dquot[GRPQUOTA]);
645                         ip->i_dquot[GRPQUOTA] = NODQUOT;
646                 }
647                 if ((error = ufs_chkdq(ip, change, cred, CHOWN)) == 0) {
648                         if ((error = ufs_chkiq(ip, 1, cred, CHOWN)) == 0)
649                                 goto good;
650                         else
651                                 (void)ufs_chkdq(ip, -change, cred, CHOWN|FORCE);
652                 }
653                 for (i = 0; i < MAXQUOTAS; i++) {
654                         ufs_dqrele(vp, ip->i_dquot[i]);
655                         ip->i_dquot[i] = NODQUOT;
656                 }
657         }
658         ip->i_gid = ogid;
659         ip->i_uid = ouid;
660         if (ufs_getinoquota(ip) == 0) {
661                 if (ouid == uid) {
662                         ufs_dqrele(vp, ip->i_dquot[USRQUOTA]);
663                         ip->i_dquot[USRQUOTA] = NODQUOT;
664                 }
665                 if (ogid == gid) {
666                         ufs_dqrele(vp, ip->i_dquot[GRPQUOTA]);
667                         ip->i_dquot[GRPQUOTA] = NODQUOT;
668                 }
669                 (void) ufs_chkdq(ip, change, cred, FORCE|CHOWN);
670                 (void) ufs_chkiq(ip, 1, cred, FORCE|CHOWN);
671                 (void) ufs_getinoquota(ip);
672         }
673         return (error);
674 good:
675         if (ufs_getinoquota(ip))
676                 panic("ufs_chown: lost quota");
677 #endif /* QUOTA */
678         ip->i_flag |= IN_CHANGE;
679         if (cred->cr_uid != 0 && (ouid != uid || ogid != gid))
680                 ip->i_mode &= ~(ISUID | ISGID);
681         return (0);
682 }
683
684 /*
685  * Mmap a file
686  *
687  * NB Currently unsupported.
688  *
689  * ufs_mmap(struct vnode *a_vp, int a_fflags, struct ucred *a_cred,
690  *          struct thread *a_td)
691  */
692 /* ARGSUSED */
693 static
694 int
695 ufs_mmap(struct vop_mmap_args *ap)
696 {
697         return (EINVAL);
698 }
699
700 /*
701  * ufs_remove(struct vnode *a_dvp, struct vnode *a_vp,
702  *            struct componentname *a_cnp)
703  */
704 static
705 int
706 ufs_remove(struct vop_old_remove_args *ap)
707 {
708         struct inode *ip;
709         struct vnode *vp = ap->a_vp;
710         struct vnode *dvp = ap->a_dvp;
711         int error;
712
713         ip = VTOI(vp);
714         if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
715             (VTOI(dvp)->i_flags & APPEND)) {
716                 error = EPERM;
717                 goto out;
718         }
719         error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
720         VN_KNOTE(vp, NOTE_DELETE);
721         VN_KNOTE(dvp, NOTE_WRITE);
722 out:
723         return (error);
724 }
725
726 /*
727  * link vnode call
728  *
729  * ufs_link(struct vnode *a_tdvp, struct vnode *a_vp,
730  *          struct componentname *a_cnp)
731  */
732 static
733 int
734 ufs_link(struct vop_old_link_args *ap)
735 {
736         struct vnode *vp = ap->a_vp;
737         struct vnode *tdvp = ap->a_tdvp;
738         struct componentname *cnp = ap->a_cnp;
739         struct inode *ip;
740         struct direct newdir;
741         int error;
742
743         if (tdvp->v_mount != vp->v_mount) {
744                 error = EXDEV;
745                 goto out2;
746         }
747         if (tdvp != vp && (error = vn_lock(vp, LK_EXCLUSIVE))) {
748                 goto out2;
749         }
750         ip = VTOI(vp);
751         if ((nlink_t)ip->i_nlink >= LINK_MAX) {
752                 error = EMLINK;
753                 goto out1;
754         }
755         if (ip->i_flags & (IMMUTABLE | APPEND)) {
756                 error = EPERM;
757                 goto out1;
758         }
759         ip->i_effnlink++;
760         ip->i_nlink++;
761         ip->i_flag |= IN_CHANGE;
762         if (DOINGSOFTDEP(vp))
763                 softdep_change_linkcnt(ip);
764         error = UFS_UPDATE(vp, !(DOINGSOFTDEP(vp) | DOINGASYNC(vp)));
765         if (!error) {
766                 ufs_makedirentry(ip, cnp, &newdir);
767                 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL);
768         }
769
770         if (error) {
771                 ip->i_effnlink--;
772                 ip->i_nlink--;
773                 ip->i_flag |= IN_CHANGE;
774                 if (DOINGSOFTDEP(vp))
775                         softdep_change_linkcnt(ip);
776         }
777 out1:
778         if (tdvp != vp)
779                 VOP_UNLOCK(vp, 0);
780 out2:
781         VN_KNOTE(vp, NOTE_LINK);
782         VN_KNOTE(tdvp, NOTE_WRITE);
783         return (error);
784 }
785
786 /*
787  * whiteout vnode call
788  *
789  * ufs_whiteout(struct vnode *a_dvp, struct componentname *a_cnp, int a_flags)
790  */
791 static
792 int
793 ufs_whiteout(struct vop_old_whiteout_args *ap)
794 {
795         struct vnode *dvp = ap->a_dvp;
796         struct componentname *cnp = ap->a_cnp;
797         struct direct newdir;
798         int error = 0;
799
800         switch (ap->a_flags) {
801         case NAMEI_LOOKUP:
802                 /* 4.4 format directories support whiteout operations */
803                 if (dvp->v_mount->mnt_maxsymlinklen > 0)
804                         return (0);
805                 return (EOPNOTSUPP);
806
807         case NAMEI_CREATE:
808                 /* create a new directory whiteout */
809 #ifdef DIAGNOSTIC
810                 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
811                         panic("ufs_whiteout: old format filesystem");
812 #endif
813
814                 newdir.d_ino = WINO;
815                 newdir.d_namlen = cnp->cn_namelen;
816                 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
817                 newdir.d_type = DT_WHT;
818                 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL);
819                 break;
820
821         case NAMEI_DELETE:
822                 /* remove an existing directory whiteout */
823 #ifdef DIAGNOSTIC
824                 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
825                         panic("ufs_whiteout: old format filesystem");
826 #endif
827
828                 cnp->cn_flags &= ~CNP_DOWHITEOUT;
829                 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
830                 break;
831         default:
832                 panic("ufs_whiteout: unknown op");
833         }
834         return (error);
835 }
836
837 /*
838  * Rename system call.
839  *      rename("foo", "bar");
840  * is essentially
841  *      unlink("bar");
842  *      link("foo", "bar");
843  *      unlink("foo");
844  * but ``atomically''.  Can't do full commit without saving state in the
845  * inode on disk which isn't feasible at this time.  Best we can do is
846  * always guarantee the target exists.
847  *
848  * Basic algorithm is:
849  *
850  * 1) Bump link count on source while we're linking it to the
851  *    target.  This also ensure the inode won't be deleted out
852  *    from underneath us while we work (it may be truncated by
853  *    a concurrent `trunc' or `open' for creation).
854  * 2) Link source to destination.  If destination already exists,
855  *    delete it first.
856  * 3) Unlink source reference to inode if still around. If a
857  *    directory was moved and the parent of the destination
858  *    is different from the source, patch the ".." entry in the
859  *    directory.
860  *
861  * ufs_rename(struct vnode *a_fdvp, struct vnode *a_fvp,
862  *            struct componentname *a_fcnp, struct vnode *a_tdvp,
863  *            struct vnode *a_tvp, struct componentname *a_tcnp)
864  */
865 static
866 int
867 ufs_rename(struct vop_old_rename_args *ap)
868 {
869         struct vnode *tvp = ap->a_tvp;
870         struct vnode *tdvp = ap->a_tdvp;
871         struct vnode *fvp = ap->a_fvp;
872         struct vnode *fdvp = ap->a_fdvp;
873         struct componentname *tcnp = ap->a_tcnp;
874         struct componentname *fcnp = ap->a_fcnp;
875         struct inode *ip, *xp, *dp;
876         struct direct newdir;
877         ino_t oldparent = 0, newparent = 0;
878         int doingdirectory = 0;
879         int error = 0, ioflag;
880
881         /*
882          * Check for cross-device rename.
883          */
884         if ((fvp->v_mount != tdvp->v_mount) ||
885             (tvp && (fvp->v_mount != tvp->v_mount))) {
886                 error = EXDEV;
887 abortit:
888                 if (tdvp == tvp)
889                         vrele(tdvp);
890                 else
891                         vput(tdvp);
892                 if (tvp)
893                         vput(tvp);
894                 vrele(fdvp);
895                 vrele(fvp);
896                 return (error);
897         }
898
899         if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
900             (VTOI(tdvp)->i_flags & APPEND))) {
901                 error = EPERM;
902                 goto abortit;
903         }
904
905         /*
906          * Renaming a file to itself has no effect.  The upper layers should
907          * not call us in that case.  Temporarily just warn if they do.
908          */
909         if (fvp == tvp) {
910                 printf("ufs_rename: fvp == tvp (can't happen)\n");
911                 error = 0;
912                 goto abortit;
913         }
914
915         if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
916                 goto abortit;
917
918         /*
919          * Note: now that fvp is locked we have to be sure to unlock it before
920          * using the 'abortit' target.
921          */
922         dp = VTOI(fdvp);
923         ip = VTOI(fvp);
924         if (ip->i_nlink >= LINK_MAX) {
925                 VOP_UNLOCK(fvp, 0);
926                 error = EMLINK;
927                 goto abortit;
928         }
929         if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
930             || (dp->i_flags & APPEND)) {
931                 VOP_UNLOCK(fvp, 0);
932                 error = EPERM;
933                 goto abortit;
934         }
935         if ((ip->i_mode & IFMT) == IFDIR) {
936                 /*
937                  * Avoid ".", "..", and aliases of "." for obvious reasons.
938                  */
939                 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
940                     dp == ip || (fcnp->cn_flags | tcnp->cn_flags) & CNP_ISDOTDOT ||
941                     (ip->i_flag & IN_RENAME)) {
942                         VOP_UNLOCK(fvp, 0);
943                         error = EINVAL;
944                         goto abortit;
945                 }
946                 ip->i_flag |= IN_RENAME;
947                 oldparent = dp->i_number;
948                 doingdirectory = 1;
949         }
950         VN_KNOTE(fdvp, NOTE_WRITE);             /* XXX right place? */
951
952         /*
953          * fvp still locked.  ip->i_flag has IN_RENAME set if doingdirectory.
954          * Cleanup fvp requirements so we can unlock it.
955          *
956          * tvp and tdvp are locked.  tvp may be NULL.  Now that dp and xp
957          * is setup we can use the 'bad' target if we unlock fvp.  We cannot
958          * use the abortit target anymore because of IN_RENAME.
959          */
960         dp = VTOI(tdvp);
961         if (tvp)
962                 xp = VTOI(tvp);
963         else
964                 xp = NULL;
965
966         /*
967          * 1) Bump link count while we're moving stuff
968          *    around.  If we crash somewhere before
969          *    completing our work, the link count
970          *    may be wrong, but correctable.
971          */
972         ip->i_effnlink++;
973         ip->i_nlink++;
974         ip->i_flag |= IN_CHANGE;
975         if (DOINGSOFTDEP(fvp))
976                 softdep_change_linkcnt(ip);
977         if ((error = UFS_UPDATE(fvp, !(DOINGSOFTDEP(fvp) |
978                                        DOINGASYNC(fvp)))) != 0) {
979                 VOP_UNLOCK(fvp, 0);
980                 goto bad;
981         }
982
983         /*
984          * If ".." must be changed (ie the directory gets a new
985          * parent) then the source directory must not be in the
986          * directory heirarchy above the target, as this would
987          * orphan everything below the source directory. Also
988          * the user must have write permission in the source so
989          * as to be able to change "..". We must repeat the call
990          * to namei, as the parent directory is unlocked by the
991          * call to checkpath().
992          */
993         error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred);
994         VOP_UNLOCK(fvp, 0);
995
996         /*
997          * We are now back to where we were in that fvp, fdvp are unlocked
998          * and tvp, tdvp are locked.  tvp may be NULL.  IN_RENAME may be
999          * set.  Only the bad target or, if we clean up tvp and tdvp, the
1000          * out target, may be used.
1001          */
1002         if (oldparent != dp->i_number)
1003                 newparent = dp->i_number;
1004         if (doingdirectory && newparent) {
1005                 if (error)      /* write access check above */
1006                         goto bad;
1007
1008                 /*
1009                  * Once we start messing with tvp and tdvp we cannot use the
1010                  * 'bad' target, only finish cleaning tdvp and tvp up and
1011                  * use the 'out' target.
1012                  *
1013                  * This cleans up tvp.
1014                  */
1015                 if (xp != NULL) {
1016                         vput(tvp);
1017                         xp = NULL;
1018                 }
1019
1020                 /*
1021                  * This is a real mess. ufs_checkpath vput's the target
1022                  * directory so retain an extra ref and note that tdvp will
1023                  * lose its lock on return.  This leaves us with one good
1024                  * ref after ufs_checkpath returns.
1025                  */
1026                 vref(tdvp);
1027                 error = ufs_checkpath(ip, dp, tcnp->cn_cred);
1028                 tcnp->cn_flags |= CNP_PDIRUNLOCK;
1029                 if (error) {
1030                         vrele(tdvp);
1031                         goto out;
1032                 }
1033
1034                 /*
1035                  * relookup no longer messes with tdvp's refs. tdvp must be
1036                  * unlocked on entry and will be locked on a successful
1037                  * return.
1038                  */
1039                 error = relookup(tdvp, &tvp, tcnp);
1040                 if (error) {
1041                         if (tcnp->cn_flags & CNP_PDIRUNLOCK)
1042                                 vrele(tdvp);
1043                         else
1044                                 vput(tdvp);
1045                         goto out;
1046                 }
1047                 KKASSERT((tcnp->cn_flags & CNP_PDIRUNLOCK) == 0);
1048                 dp = VTOI(tdvp);
1049                 if (tvp)
1050                         xp = VTOI(tvp);
1051         }
1052
1053         /*
1054          * We are back to fvp, fdvp unlocked, tvp, tdvp locked.  tvp may 
1055          * be NULL (xp will also be NULL in that case), and IN_RENAME will
1056          * be set if doingdirectory.  This means we can use the 'bad' target
1057          * again.
1058          */
1059
1060         /*
1061          * 2) If target doesn't exist, link the target
1062          *    to the source and unlink the source.
1063          *    Otherwise, rewrite the target directory
1064          *    entry to reference the source inode and
1065          *    expunge the original entry's existence.
1066          */
1067         if (xp == NULL) {
1068                 if (dp->i_dev != ip->i_dev)
1069                         panic("ufs_rename: EXDEV");
1070                 /*
1071                  * Account for ".." in new directory.
1072                  * When source and destination have the same
1073                  * parent we don't fool with the link count.
1074                  */
1075                 if (doingdirectory && newparent) {
1076                         if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1077                                 error = EMLINK;
1078                                 goto bad;
1079                         }
1080                         dp->i_effnlink++;
1081                         dp->i_nlink++;
1082                         dp->i_flag |= IN_CHANGE;
1083                         if (DOINGSOFTDEP(tdvp))
1084                                 softdep_change_linkcnt(dp);
1085                         error = UFS_UPDATE(tdvp, !(DOINGSOFTDEP(tdvp) |
1086                                                    DOINGASYNC(tdvp)));
1087                         if (error)
1088                                 goto bad;
1089                 }
1090                 ufs_makedirentry(ip, tcnp, &newdir);
1091                 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL);
1092                 if (error) {
1093                         if (doingdirectory && newparent) {
1094                                 dp->i_effnlink--;
1095                                 dp->i_nlink--;
1096                                 dp->i_flag |= IN_CHANGE;
1097                                 if (DOINGSOFTDEP(tdvp))
1098                                         softdep_change_linkcnt(dp);
1099                                 (void)UFS_UPDATE(tdvp, 1);
1100                         }
1101                         goto bad;
1102                 }
1103                 VN_KNOTE(tdvp, NOTE_WRITE);
1104                 vput(tdvp);
1105         } else {
1106                 if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev)
1107                         panic("ufs_rename: EXDEV");
1108                 /*
1109                  * Short circuit rename(foo, foo).
1110                  */
1111                 if (xp->i_number == ip->i_number)
1112                         panic("ufs_rename: same file");
1113                 /*
1114                  * If the parent directory is "sticky", then the user must
1115                  * own the parent directory, or the destination of the rename,
1116                  * otherwise the destination may not be changed (except by
1117                  * root). This implements append-only directories.
1118                  */
1119                 if ((dp->i_mode & S_ISTXT) && tcnp->cn_cred->cr_uid != 0 &&
1120                     tcnp->cn_cred->cr_uid != dp->i_uid &&
1121                     xp->i_uid != tcnp->cn_cred->cr_uid) {
1122                         error = EPERM;
1123                         goto bad;
1124                 }
1125                 /*
1126                  * Target must be empty if a directory and have no links
1127                  * to it. Also, ensure source and target are compatible
1128                  * (both directories, or both not directories).
1129                  *
1130                  * Purge the file or directory being replaced from the
1131                  * nameccache.
1132                  */
1133                 if ((xp->i_mode&IFMT) == IFDIR) {
1134                         if ((xp->i_effnlink > 2) ||
1135                             !ufs_dirempty(xp, dp->i_number, tcnp->cn_cred)) {
1136                                 error = ENOTEMPTY;
1137                                 goto bad;
1138                         }
1139                         if (!doingdirectory) {
1140                                 error = ENOTDIR;
1141                                 goto bad;
1142                         }
1143                         /* cache_purge removed - handled by VFS compat layer */
1144                 } else if (doingdirectory == 0) {
1145                         /* cache_purge removed - handled by VFS compat layer */
1146                 } else {
1147                         error = EISDIR;
1148                         goto bad;
1149                 }
1150                 /*
1151                  * note: inode passed to ufs_dirrewrite() is 0 for a 
1152                  * non-directory file rename, 1 for a directory rename
1153                  * in the same directory, and > 1 for an inode representing
1154                  * the new directory.
1155                  */
1156                 error = ufs_dirrewrite(dp, xp, ip->i_number,
1157                     IFTODT(ip->i_mode),
1158                     (doingdirectory && newparent) ?
1159                         newparent : (ino_t)doingdirectory);
1160                 if (error)
1161                         goto bad;
1162                 if (doingdirectory) {
1163                         if (!newparent) {
1164                                 dp->i_effnlink--;
1165                                 if (DOINGSOFTDEP(tdvp))
1166                                         softdep_change_linkcnt(dp);
1167                         }
1168                         xp->i_effnlink--;
1169                         if (DOINGSOFTDEP(tvp))
1170                                 softdep_change_linkcnt(xp);
1171                 }
1172                 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1173                         /*
1174                          * Truncate inode. The only stuff left in the directory
1175                          * is "." and "..". The "." reference is inconsequential
1176                          * since we are quashing it. We have removed the "."
1177                          * reference and the reference in the parent directory,
1178                          * but there may be other hard links. The soft
1179                          * dependency code will arrange to do these operations
1180                          * after the parent directory entry has been deleted on
1181                          * disk, so when running with that code we avoid doing
1182                          * them now.
1183                          */
1184                         if (!newparent) {
1185                                 dp->i_nlink--;
1186                                 dp->i_flag |= IN_CHANGE;
1187                         }
1188                         xp->i_nlink--;
1189                         xp->i_flag |= IN_CHANGE;
1190                         ioflag = DOINGASYNC(tvp) ? 0 : IO_SYNC;
1191                         error = UFS_TRUNCATE(tvp, (off_t)0, ioflag,
1192                                              tcnp->cn_cred);
1193                         if (error)
1194                                 goto bad;
1195                 }
1196                 VN_KNOTE(tdvp, NOTE_WRITE);
1197                 vput(tdvp);
1198                 VN_KNOTE(tvp, NOTE_DELETE);
1199                 vput(tvp);
1200                 xp = NULL;
1201         }
1202
1203         /*
1204          * tvp and tdvp have been cleaned up.  only fvp and fdvp (both
1205          * unlocked) remain.  We are about to overwrite fvp but we have to
1206          * keep 'ip' intact so we cannot release the old fvp, which is still
1207          * refd and accessible via ap->a_fvp.
1208          *
1209          * This means we cannot use either 'bad' or 'out' to cleanup any 
1210          * more.
1211          */
1212
1213         /*
1214          * 3) Unlink the source.
1215          */
1216         fcnp->cn_flags &= ~CNP_MODMASK;
1217         fcnp->cn_flags |= CNP_LOCKPARENT;
1218         error = relookup(fdvp, &fvp, fcnp);
1219         if (error || fvp == NULL) {
1220                 /*
1221                  * From name has disappeared.  IN_RENAME will not be set if
1222                  * we get past the panic so we don't have to clean it up.
1223                  */
1224                 if (doingdirectory)
1225                         panic("ufs_rename: lost dir entry");
1226                 vrele(ap->a_fvp);
1227                 if (fcnp->cn_flags & CNP_PDIRUNLOCK)
1228                         vrele(fdvp);
1229                 else
1230                         vput(fdvp);
1231                 return(0);
1232         }
1233         KKASSERT((fcnp->cn_flags & CNP_PDIRUNLOCK) == 0);
1234
1235         /*
1236          * fdvp and fvp are locked.
1237          */
1238         xp = VTOI(fvp);
1239         dp = VTOI(fdvp);
1240
1241         /*
1242          * Ensure that the directory entry still exists and has not
1243          * changed while the new name has been entered. If the source is
1244          * a file then the entry may have been unlinked or renamed. In
1245          * either case there is no further work to be done. If the source
1246          * is a directory then it cannot have been rmdir'ed; the IN_RENAME
1247          * flag ensures that it cannot be moved by another rename or removed
1248          * by a rmdir.  Cleanup IN_RENAME.
1249          */
1250         if (xp != ip) {
1251                 if (doingdirectory)
1252                         panic("ufs_rename: lost dir entry");
1253         } else {
1254                 /*
1255                  * If the source is a directory with a
1256                  * new parent, the link count of the old
1257                  * parent directory must be decremented
1258                  * and ".." set to point to the new parent.
1259                  */
1260                 if (doingdirectory && newparent) {
1261                         xp->i_offset = mastertemplate.dot_reclen;
1262                         ufs_dirrewrite(xp, dp, newparent, DT_DIR, 0);
1263                         /* cache_purge removed - handled by VFS compat layer */
1264                 }
1265                 error = ufs_dirremove(fdvp, xp, fcnp->cn_flags, 0);
1266                 xp->i_flag &= ~IN_RENAME;
1267         }
1268
1269         VN_KNOTE(fvp, NOTE_RENAME);
1270         vput(fdvp);
1271         vput(fvp);
1272         vrele(ap->a_fvp);
1273         return (error);
1274
1275 bad:
1276         if (xp)
1277                 vput(ITOV(xp));
1278         vput(ITOV(dp));
1279 out:
1280         if (doingdirectory)
1281                 ip->i_flag &= ~IN_RENAME;
1282         if (vn_lock(fvp, LK_EXCLUSIVE) == 0) {
1283                 ip->i_effnlink--;
1284                 ip->i_nlink--;
1285                 ip->i_flag |= IN_CHANGE;
1286                 ip->i_flag &= ~IN_RENAME;
1287                 if (DOINGSOFTDEP(fvp))
1288                         softdep_change_linkcnt(ip);
1289                 vput(fvp);
1290         } else {
1291                 vrele(fvp);
1292         }
1293         return (error);
1294 }
1295
1296 /*
1297  * Mkdir system call
1298  *
1299  * ufs_mkdir(struct vnode *a_dvp, struct vnode **a_vpp,
1300  *           struct componentname *a_cnp, struct vattr *a_vap)
1301  */
1302 static
1303 int
1304 ufs_mkdir(struct vop_old_mkdir_args *ap)
1305 {
1306         struct vnode *dvp = ap->a_dvp;
1307         struct vattr *vap = ap->a_vap;
1308         struct componentname *cnp = ap->a_cnp;
1309         struct inode *ip, *dp;
1310         struct vnode *tvp;
1311         struct buf *bp;
1312         struct dirtemplate dirtemplate, *dtp;
1313         struct direct newdir;
1314         int error, dmode;
1315         long blkoff;
1316
1317         dp = VTOI(dvp);
1318         if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1319                 error = EMLINK;
1320                 goto out;
1321         }
1322         dmode = vap->va_mode & 0777;
1323         dmode |= IFDIR;
1324         /*
1325          * Must simulate part of ufs_makeinode here to acquire the inode,
1326          * but not have it entered in the parent directory. The entry is
1327          * made later after writing "." and ".." entries.
1328          */
1329         error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1330         if (error)
1331                 goto out;
1332         ip = VTOI(tvp);
1333         ip->i_gid = dp->i_gid;
1334 #ifdef SUIDDIR
1335         {
1336 #ifdef QUOTA
1337                 struct ucred ucred, *ucp;
1338                 ucp = cnp->cn_cred;
1339 #endif
1340                 /*
1341                  * If we are hacking owners here, (only do this where told to)
1342                  * and we are not giving it TO root, (would subvert quotas)
1343                  * then go ahead and give it to the other user.
1344                  * The new directory also inherits the SUID bit.
1345                  * If user's UID and dir UID are the same,
1346                  * 'give it away' so that the SUID is still forced on.
1347                  */
1348                 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1349                     (dp->i_mode & ISUID) && dp->i_uid) {
1350                         dmode |= ISUID;
1351                         ip->i_uid = dp->i_uid;
1352 #ifdef QUOTA
1353                         if (dp->i_uid != cnp->cn_cred->cr_uid) {
1354                                 /*
1355                                  * Make sure the correct user gets charged
1356                                  * for the space.
1357                                  * Make a dummy credential for the victim.
1358                                  * XXX This seems to never be accessed out of
1359                                  * our context so a stack variable is ok.
1360                                  */
1361                                 ucred.cr_ref = 1;
1362                                 ucred.cr_uid = ip->i_uid;
1363                                 ucred.cr_ngroups = 1;
1364                                 ucred.cr_groups[0] = dp->i_gid;
1365                                 ucp = &ucred;
1366                         }
1367 #endif
1368                 } else
1369                         ip->i_uid = cnp->cn_cred->cr_uid;
1370 #ifdef QUOTA
1371                 if ((error = ufs_getinoquota(ip)) ||
1372                     (error = ufs_chkiq(ip, 1, ucp, 0))) {
1373                         UFS_VFREE(tvp, ip->i_number, dmode);
1374                         vput(tvp);
1375                         return (error);
1376                 }
1377 #endif
1378         }
1379 #else   /* !SUIDDIR */
1380         ip->i_uid = cnp->cn_cred->cr_uid;
1381 #ifdef QUOTA
1382         if ((error = ufs_getinoquota(ip)) ||
1383             (error = ufs_chkiq(ip, 1, cnp->cn_cred, 0))) {
1384                 UFS_VFREE(tvp, ip->i_number, dmode);
1385                 vput(tvp);
1386                 return (error);
1387         }
1388 #endif
1389 #endif  /* !SUIDDIR */
1390         ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1391         ip->i_mode = dmode;
1392         tvp->v_type = VDIR;     /* Rest init'd in getnewvnode(). */
1393         ip->i_effnlink = 2;
1394         ip->i_nlink = 2;
1395         if (DOINGSOFTDEP(tvp))
1396                 softdep_change_linkcnt(ip);
1397         if (cnp->cn_flags & CNP_ISWHITEOUT)
1398                 ip->i_flags |= UF_OPAQUE;
1399
1400         /*
1401          * Bump link count in parent directory to reflect work done below.
1402          * Should be done before reference is created so cleanup is
1403          * possible if we crash.
1404          */
1405         dp->i_effnlink++;
1406         dp->i_nlink++;
1407         dp->i_flag |= IN_CHANGE;
1408         if (DOINGSOFTDEP(dvp))
1409                 softdep_change_linkcnt(dp);
1410         error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(dvp) | DOINGASYNC(dvp)));
1411         if (error)
1412                 goto bad;
1413
1414         /*
1415          * The vnode must have a VM object in order to issue buffer cache
1416          * ops on it.
1417          */
1418         vinitvmio(tvp, DIRBLKSIZ);
1419
1420         /*
1421          * Initialize directory with "." and ".." from static template.
1422          */
1423         if (dvp->v_mount->mnt_maxsymlinklen > 0)
1424                 dtp = &mastertemplate;
1425         else
1426                 dtp = (struct dirtemplate *)&omastertemplate;
1427         dirtemplate = *dtp;
1428         dirtemplate.dot_ino = ip->i_number;
1429         dirtemplate.dotdot_ino = dp->i_number;
1430         vnode_pager_setsize(tvp, DIRBLKSIZ);
1431         error = VOP_BALLOC(tvp, 0LL, DIRBLKSIZ, cnp->cn_cred, B_CLRBUF, &bp);
1432         if (error)
1433                 goto bad;
1434         ip->i_size = DIRBLKSIZ;
1435         ip->i_flag |= IN_CHANGE | IN_UPDATE;
1436         bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1437         if (DOINGSOFTDEP(tvp)) {
1438                 /*
1439                  * Ensure that the entire newly allocated block is a
1440                  * valid directory so that future growth within the
1441                  * block does not have to ensure that the block is
1442                  * written before the inode.
1443                  */
1444                 blkoff = DIRBLKSIZ;
1445                 while (blkoff < bp->b_bcount) {
1446                         ((struct direct *)
1447                            (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1448                         blkoff += DIRBLKSIZ;
1449                 }
1450         }
1451         if ((error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) |
1452                                        DOINGASYNC(tvp)))) != 0) {
1453                 bwrite(bp);
1454                 goto bad;
1455         }
1456         /*
1457          * Directory set up, now install its entry in the parent directory.
1458          *
1459          * If we are not doing soft dependencies, then we must write out the
1460          * buffer containing the new directory body before entering the new 
1461          * name in the parent. If we are doing soft dependencies, then the
1462          * buffer containing the new directory body will be passed to and
1463          * released in the soft dependency code after the code has attached
1464          * an appropriate ordering dependency to the buffer which ensures that
1465          * the buffer is written before the new name is written in the parent.
1466          */
1467         if (DOINGASYNC(dvp))
1468                 bdwrite(bp);
1469         else if (!DOINGSOFTDEP(dvp) && (error = bwrite(bp)) != 0)
1470                 goto bad;
1471         ufs_makedirentry(ip, cnp, &newdir);
1472         error = ufs_direnter(dvp, tvp, &newdir, cnp, bp);
1473         
1474 bad:
1475         if (error == 0) {
1476                 VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
1477                 *ap->a_vpp = tvp;
1478         } else {
1479                 dp->i_effnlink--;
1480                 dp->i_nlink--;
1481                 dp->i_flag |= IN_CHANGE;
1482                 if (DOINGSOFTDEP(dvp))
1483                         softdep_change_linkcnt(dp);
1484                 /*
1485                  * No need to do an explicit VOP_TRUNCATE here, vrele will
1486                  * do this for us because we set the link count to 0.
1487                  */
1488                 ip->i_effnlink = 0;
1489                 ip->i_nlink = 0;
1490                 ip->i_flag |= IN_CHANGE;
1491                 if (DOINGSOFTDEP(tvp))
1492                         softdep_change_linkcnt(ip);
1493                 vput(tvp);
1494         }
1495 out:
1496         return (error);
1497 }
1498
1499 /*
1500  * Rmdir system call.
1501  *
1502  * ufs_rmdir(struct vnode *a_dvp, struct vnode *a_vp,
1503  *           struct componentname *a_cnp)
1504  */
1505 static
1506 int
1507 ufs_rmdir(struct vop_old_rmdir_args *ap)
1508 {
1509         struct vnode *vp = ap->a_vp;
1510         struct vnode *dvp = ap->a_dvp;
1511         struct componentname *cnp = ap->a_cnp;
1512         struct inode *ip, *dp;
1513         int error, ioflag;
1514
1515         ip = VTOI(vp);
1516         dp = VTOI(dvp);
1517
1518         /*
1519          * Do not remove a directory that is in the process of being renamed.
1520          * Verify the directory is empty (and valid). Rmdir ".." will not be
1521          * valid since ".." will contain a reference to the current directory
1522          * and thus be non-empty. Do not allow the removal of mounted on
1523          * directories (this can happen when an NFS exported filesystem
1524          * tries to remove a locally mounted on directory).
1525          */
1526         error = 0;
1527         if (ip->i_flag & IN_RENAME) {
1528                 error = EINVAL;
1529                 goto out;
1530         }
1531         if (ip->i_effnlink != 2 ||
1532             !ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
1533                 error = ENOTEMPTY;
1534                 goto out;
1535         }
1536         if ((dp->i_flags & APPEND)
1537             || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
1538                 error = EPERM;
1539                 goto out;
1540         }
1541         if (vp->v_mountedhere != 0) {
1542                 error = EINVAL;
1543                 goto out;
1544         }
1545         /*
1546          * Delete reference to directory before purging
1547          * inode.  If we crash in between, the directory
1548          * will be reattached to lost+found,
1549          */
1550         dp->i_effnlink--;
1551         ip->i_effnlink--;
1552         if (DOINGSOFTDEP(vp)) {
1553                 softdep_change_linkcnt(dp);
1554                 softdep_change_linkcnt(ip);
1555         }
1556         error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
1557         if (error) {
1558                 dp->i_effnlink++;
1559                 ip->i_effnlink++;
1560                 if (DOINGSOFTDEP(vp)) {
1561                         softdep_change_linkcnt(dp);
1562                         softdep_change_linkcnt(ip);
1563                 }
1564                 goto out;
1565         }
1566         VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
1567         /*
1568          * Truncate inode. The only stuff left in the directory is "." and
1569          * "..". The "." reference is inconsequential since we are quashing
1570          * it. The soft dependency code will arrange to do these operations
1571          * after the parent directory entry has been deleted on disk, so
1572          * when running with that code we avoid doing them now.
1573          */
1574         if (!DOINGSOFTDEP(vp)) {
1575                 dp->i_nlink--;
1576                 dp->i_flag |= IN_CHANGE;
1577                 ip->i_nlink--;
1578                 ip->i_flag |= IN_CHANGE;
1579                 ioflag = DOINGASYNC(vp) ? 0 : IO_SYNC;
1580                 error = UFS_TRUNCATE(vp, (off_t)0, ioflag, cnp->cn_cred);
1581         }
1582         /* cache_purge removed - handled by VFS compat layer */
1583 #ifdef UFS_DIRHASH
1584         /* Kill any active hash; i_effnlink == 0, so it will not come back. */
1585         if (ip->i_dirhash != NULL)
1586                 ufsdirhash_free(ip);
1587 #endif
1588 out:
1589         VN_KNOTE(vp, NOTE_DELETE);
1590         return (error);
1591 }
1592
1593 /*
1594  * symlink -- make a symbolic link
1595  *
1596  * ufs_symlink(struct vnode *a_dvp, struct vnode **a_vpp,
1597  *              struct componentname *a_cnp, struct vattr *a_vap,
1598  *              char *a_target)
1599  */
1600 static
1601 int
1602 ufs_symlink(struct vop_old_symlink_args *ap)
1603 {
1604         struct vnode *vp, **vpp = ap->a_vpp;
1605         struct inode *ip;
1606         int len, error;
1607
1608         error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
1609                               vpp, ap->a_cnp);
1610         if (error)
1611                 return (error);
1612         VN_KNOTE(ap->a_dvp, NOTE_WRITE);
1613         vp = *vpp;
1614         len = strlen(ap->a_target);
1615         if (len < vp->v_mount->mnt_maxsymlinklen) {
1616                 ip = VTOI(vp);
1617                 bcopy(ap->a_target, (char *)ip->i_shortlink, len);
1618                 ip->i_size = len;
1619                 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1620         } else {
1621                 /*
1622                  * Make sure we have a VM object in order to use
1623                  * the buffer cache.
1624                  */
1625                 if (vp->v_object == NULL)
1626                         vinitvmio(vp, 0);
1627                 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
1628                                 UIO_SYSSPACE, IO_NODELOCKED, 
1629                                 ap->a_cnp->cn_cred, NULL);
1630         }
1631         if (error)
1632                 vput(vp);
1633         return (error);
1634 }
1635
1636 /*
1637  * Vnode op for reading directories.
1638  *
1639  * ufs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
1640  *              int *a_eofflag, int *ncookies, u_long **a_cookies)
1641  */
1642 static
1643 int
1644 ufs_readdir(struct vop_readdir_args *ap)
1645 {
1646         struct uio *uio = ap->a_uio;
1647         struct vnode *vp = ap->a_vp;
1648         struct direct *dp;
1649         struct buf *bp;
1650         int retval;
1651         int error;
1652         int offset;     /* offset into buffer cache buffer */
1653         int eoffset;    /* end of buffer clipped to file EOF */
1654         int pickup;     /* pickup point */
1655         int ncookies;
1656         int cookie_index;
1657         u_long *cookies;
1658
1659         if (uio->uio_offset < 0)
1660                 return (EINVAL);
1661         /*
1662          * Guess the number of cookies needed.  Make sure we compute at
1663          * least 1, and no more then a reasonable limit.
1664          */
1665         if (ap->a_ncookies) {
1666                 ncookies = uio->uio_resid / 16 + 1;
1667                 if (ncookies > 1024)
1668                         ncookies = 1024;
1669                 cookies = malloc(ncookies * sizeof(u_long), M_TEMP, M_WAITOK);
1670         } else {
1671                 ncookies = -1;  /* force conditionals below */
1672                 cookies = NULL;
1673         }
1674         cookie_index = 0;
1675
1676         /*
1677          * Past or at EOF
1678          */
1679         if (uio->uio_offset >= VTOI(vp)->i_size) {
1680                 if (ap->a_eofflag)
1681                         *ap->a_eofflag = 1;
1682                 if (ap->a_ncookies) {
1683                         *ap->a_ncookies = cookie_index;
1684                         *ap->a_cookies = cookies;
1685                 }
1686                 return(0);
1687         }
1688
1689         /*
1690          * Loop until we run out of cookies, we run out of user buffer,
1691          * or we hit the directory EOF.
1692          *
1693          * Always start scans at the beginning of the buffer, don't trust
1694          * the offset supplied by userland.
1695          */
1696         while ((error = UFS_BLKATOFF(vp, uio->uio_offset, NULL, &bp)) == 0) {
1697                 pickup = (int)(uio->uio_offset - bp->b_loffset);
1698                 offset = 0;
1699                 retval = 0;
1700                 if (bp->b_loffset + bp->b_bcount > VTOI(vp)->i_size)
1701                         eoffset = (int)(VTOI(vp)->i_size - bp->b_loffset);
1702                 else
1703                         eoffset = bp->b_bcount;
1704
1705                 while (offset < eoffset) {
1706                         dp = (struct direct *)(bp->b_data + offset);
1707                         if (dp->d_reclen <= 0 || (dp->d_reclen & 3) ||
1708                             offset + dp->d_reclen > bp->b_bcount) {
1709                                 error = EIO;
1710                                 break;
1711                         }
1712                         if (offsetof(struct direct, d_name[dp->d_namlen]) >                                  dp->d_reclen) {
1713                                 error = EIO;
1714                                 break;
1715                         }
1716                         if (offset < pickup) {
1717                                 offset += dp->d_reclen;
1718                                 continue;
1719                         }
1720 #if BYTE_ORDER == LITTLE_ENDIAN
1721                         if (OFSFMT(vp)) {
1722                                 retval = vop_write_dirent(&error, uio,
1723                                     dp->d_ino, dp->d_namlen, dp->d_type,
1724                                     dp->d_name);
1725                         } else
1726 #endif
1727                         {
1728                                 retval = vop_write_dirent(&error, uio,
1729                                     dp->d_ino, dp->d_type, dp->d_namlen,
1730                                     dp->d_name);
1731                         }
1732                         if (retval)
1733                                 break;
1734                         if (cookies) {
1735                                 cookies[cookie_index] =
1736                                         (u_long)bp->b_loffset + offset;
1737                         }
1738                         ++cookie_index;
1739                         offset += dp->d_reclen;
1740                         if (cookie_index == ncookies)
1741                                 break;
1742                 }
1743
1744                 /*
1745                  * This will align the next loop to the beginning of the
1746                  * next block, and pickup will calculate to 0.
1747                  */
1748                 uio->uio_offset = bp->b_loffset + offset;
1749                 brelse(bp);
1750
1751                 if (retval || error || cookie_index == ncookies ||
1752                     uio->uio_offset >= VTOI(vp)->i_size) {
1753                         break;
1754                 }
1755         }
1756         if (ap->a_eofflag)
1757                 *ap->a_eofflag = VTOI(vp)->i_size <= uio->uio_offset;
1758
1759         /*
1760          * Report errors only if we didn't manage to read anything
1761          */
1762         if (error && cookie_index == 0) {
1763                 if (cookies) {
1764                         free(cookies, M_TEMP);
1765                         *ap->a_ncookies = 0;
1766                         *ap->a_cookies = NULL;
1767                 }
1768         } else {
1769                 error = 0;
1770                 if (cookies) {
1771                         *ap->a_ncookies = cookie_index;
1772                         *ap->a_cookies = cookies;
1773                 }
1774         }
1775         return (error);
1776 }
1777
1778 /*
1779  * Return target name of a symbolic link
1780  *
1781  * ufs_readlink(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred)
1782  */
1783 static
1784 int
1785 ufs_readlink(struct vop_readlink_args *ap)
1786 {
1787         struct vnode *vp = ap->a_vp;
1788         struct inode *ip = VTOI(vp);
1789         int isize;
1790
1791         isize = ip->i_size;
1792         if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
1793             (ip->i_din.di_blocks == 0)) {   /* XXX - for old fastlink support */
1794                 uiomove((char *)ip->i_shortlink, isize, ap->a_uio);
1795                 return (0);
1796         }
1797
1798         /*
1799          * Perform the equivalent of an OPEN on vp so we can issue a
1800          * VOP_READ.
1801          */
1802         return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
1803 }
1804
1805 /*
1806  * Calculate the logical to physical mapping if not done already,
1807  * then call the device strategy routine.
1808  *
1809  * In order to be able to swap to a file, the VOP_BMAP operation may not
1810  * deadlock on memory.  See ufs_bmap() for details.
1811  *
1812  * ufs_strategy(struct vnode *a_vp, struct bio *a_bio)
1813  */
1814 static
1815 int
1816 ufs_strategy(struct vop_strategy_args *ap)
1817 {
1818         struct bio *bio = ap->a_bio;
1819         struct bio *nbio;
1820         struct buf *bp = bio->bio_buf;
1821         struct vnode *vp = ap->a_vp;
1822         struct inode *ip;
1823         int error;
1824
1825         ip = VTOI(vp);
1826         if (vp->v_type == VBLK || vp->v_type == VCHR)
1827                 panic("ufs_strategy: spec");
1828         nbio = push_bio(bio);
1829         if (nbio->bio_offset == NOOFFSET) {
1830                 error = VOP_BMAP(vp, bio->bio_offset, NULL, &nbio->bio_offset,
1831                                  NULL, NULL);
1832                 if (error) {
1833                         bp->b_error = error;
1834                         bp->b_flags |= B_ERROR;
1835                         /* I/O was never started on nbio, must biodone(bio) */
1836                         biodone(bio);
1837                         return (error);
1838                 }
1839                 if (nbio->bio_offset == NOOFFSET)
1840                         vfs_bio_clrbuf(bp);
1841         }
1842         if (nbio->bio_offset == NOOFFSET) {
1843                 /*
1844                  * We hit a hole in the file.  The buffer has been zero-filled
1845                  * so just biodone() it.
1846                  */
1847                 biodone(bio);
1848         } else {
1849                 vn_strategy(ip->i_devvp, nbio);
1850         }
1851         return (0);
1852 }
1853
1854 /*
1855  * Print out the contents of an inode.
1856  *
1857  * ufs_print(struct vnode *a_vp)
1858  */
1859 static
1860 int
1861 ufs_print(struct vop_print_args *ap)
1862 {
1863         struct vnode *vp = ap->a_vp;
1864         struct inode *ip = VTOI(vp);
1865
1866         printf("tag VT_UFS, ino %lu, on dev %s (%d, %d)",
1867             (u_long)ip->i_number, devtoname(ip->i_dev), major(ip->i_dev),
1868             minor(ip->i_dev));
1869         if (vp->v_type == VFIFO)
1870                 fifo_printinfo(vp);
1871         lockmgr_printinfo(&vp->v_lock);
1872         printf("\n");
1873         return (0);
1874 }
1875
1876 /*
1877  * Read wrapper for special devices.
1878  *
1879  * ufsspec_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
1880  *              struct ucred *a_cred)
1881  */
1882 static
1883 int
1884 ufsspec_read(struct vop_read_args *ap)
1885 {
1886         int error, resid;
1887         struct inode *ip;
1888         struct uio *uio;
1889
1890         uio = ap->a_uio;
1891         resid = uio->uio_resid;
1892         error = VOCALL(spec_vnode_vops, &ap->a_head);
1893         /*
1894          * The inode may have been revoked during the call, so it must not
1895          * be accessed blindly here or in the other wrapper functions.
1896          */
1897         ip = VTOI(ap->a_vp);
1898         if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
1899                 ip->i_flag |= IN_ACCESS;
1900         return (error);
1901 }
1902
1903 /*
1904  * Write wrapper for special devices.
1905  *
1906  * ufsspec_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
1907  *               struct ucred *a_cred)
1908  */
1909 static
1910 int
1911 ufsspec_write(struct vop_write_args *ap)
1912 {
1913         int error, resid;
1914         struct inode *ip;
1915         struct uio *uio;
1916
1917         uio = ap->a_uio;
1918         resid = uio->uio_resid;
1919         error = VOCALL(spec_vnode_vops, &ap->a_head);
1920         ip = VTOI(ap->a_vp);
1921         if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
1922                 VTOI(ap->a_vp)->i_flag |= IN_CHANGE | IN_UPDATE;
1923         return (error);
1924 }
1925
1926 /*
1927  * Close wrapper for special devices.
1928  *
1929  * Update the times on the inode then do device close.
1930  *
1931  * ufsspec_close(struct vnode *a_vp, int a_fflag, struct ucred *a_cred,
1932  *               struct thread *a_td)
1933  */
1934 static 
1935 int
1936 ufsspec_close(struct vop_close_args *ap)
1937 {
1938         struct vnode *vp = ap->a_vp;
1939
1940         if (vp->v_usecount > 1)
1941                 ufs_itimes(vp);
1942         return (VOCALL(spec_vnode_vops, &ap->a_head));
1943 }
1944
1945 /*
1946  * Read wrapper for fifos.
1947  *
1948  * ufsfifo_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
1949  *              struct ucred *a_cred)
1950  */
1951 static
1952 int
1953 ufsfifo_read(struct vop_read_args *ap)
1954 {
1955         int error, resid;
1956         struct inode *ip;
1957         struct uio *uio;
1958
1959         uio = ap->a_uio;
1960         resid = uio->uio_resid;
1961         error = VOCALL(fifo_vnode_vops, &ap->a_head);
1962         ip = VTOI(ap->a_vp);
1963         if ((ap->a_vp->v_mount->mnt_flag & MNT_NOATIME) == 0 && ip != NULL &&
1964             (uio->uio_resid != resid || (error == 0 && resid != 0)))
1965                 VTOI(ap->a_vp)->i_flag |= IN_ACCESS;
1966         return (error);
1967 }
1968
1969 /*
1970  * Write wrapper for fifos.
1971  *
1972  * ufsfifo_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
1973  *               struct ucred *a_cred)
1974  */
1975 static
1976 int
1977 ufsfifo_write(struct vop_write_args *ap)
1978 {
1979         int error, resid;
1980         struct inode *ip;
1981         struct uio *uio;
1982
1983         uio = ap->a_uio;
1984         resid = uio->uio_resid;
1985         error = VOCALL(fifo_vnode_vops, &ap->a_head);
1986         ip = VTOI(ap->a_vp);
1987         if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
1988                 VTOI(ap->a_vp)->i_flag |= IN_CHANGE | IN_UPDATE;
1989         return (error);
1990 }
1991
1992 /*
1993  * Close wrapper for fifos.
1994  *
1995  * Update the times on the inode then do device close.
1996  *
1997  * ufsfifo_close(struct vnode *a_vp, int a_fflag, struct ucred *a_cred,
1998  *               struct thread *a_td)
1999  */
2000 static
2001 int
2002 ufsfifo_close(struct vop_close_args *ap)
2003 {
2004         struct vnode *vp = ap->a_vp;
2005
2006         if (vp->v_usecount > 1)
2007                 ufs_itimes(vp);
2008         return (VOCALL(fifo_vnode_vops, &ap->a_head));
2009 }
2010
2011 /*
2012  * Kqfilter wrapper for fifos.
2013  *
2014  * Fall through to ufs kqfilter routines if needed 
2015  */
2016 static
2017 int
2018 ufsfifo_kqfilter(struct vop_kqfilter_args *ap)
2019 {
2020         int error;
2021
2022         error = VOCALL(fifo_vnode_vops, &ap->a_head);
2023         if (error)
2024                 error = ufs_kqfilter(ap);
2025         return (error);
2026 }
2027
2028 /*
2029  * Return POSIX pathconf information applicable to ufs filesystems.
2030  *
2031  * ufs_pathconf(struct vnode *a_vp, int a_name, int *a_retval)
2032  */
2033 static
2034 int
2035 ufs_pathconf(struct vop_pathconf_args *ap)
2036 {
2037         switch (ap->a_name) {
2038         case _PC_LINK_MAX:
2039                 *ap->a_retval = LINK_MAX;
2040                 return (0);
2041         case _PC_NAME_MAX:
2042                 *ap->a_retval = NAME_MAX;
2043                 return (0);
2044         case _PC_PATH_MAX:
2045                 *ap->a_retval = PATH_MAX;
2046                 return (0);
2047         case _PC_PIPE_BUF:
2048                 *ap->a_retval = PIPE_BUF;
2049                 return (0);
2050         case _PC_CHOWN_RESTRICTED:
2051                 *ap->a_retval = 1;
2052                 return (0);
2053         case _PC_NO_TRUNC:
2054                 *ap->a_retval = 1;
2055                 return (0);
2056         default:
2057                 return (EINVAL);
2058         }
2059         /* NOTREACHED */
2060 }
2061
2062 /*
2063  * Advisory record locking support
2064  *
2065  * ufs_advlock(struct vnode *a_vp, caddr_t a_id, int a_op, struct flock *a_fl,
2066  *             int a_flags)
2067  */
2068 static
2069 int
2070 ufs_advlock(struct vop_advlock_args *ap)
2071 {
2072         struct inode *ip = VTOI(ap->a_vp);
2073
2074         return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
2075 }
2076
2077 /*
2078  * Initialize the vnode associated with a new inode, handle aliased
2079  * vnodes.
2080  *
2081  * Make sure directories have their VM object now rather then later,
2082  * saving us from having to check on all the myrid directory VOPs
2083  * that might be executed without a VOP_OPEN being performed.
2084  */
2085 int
2086 ufs_vinit(struct mount *mntp, struct vnode **vpp)
2087 {
2088         struct inode *ip;
2089         struct vnode *vp;
2090         struct timeval tv;
2091
2092         vp = *vpp;
2093         ip = VTOI(vp);
2094
2095         vp->v_type = IFTOVT(ip->i_mode);
2096
2097         switch(vp->v_type) {
2098         case VCHR:
2099         case VBLK:
2100                 vp->v_ops = &mntp->mnt_vn_spec_ops;
2101                 addaliasu(vp, ip->i_rdev);
2102                 break;
2103         case VFIFO:
2104                 vp->v_ops = &mntp->mnt_vn_fifo_ops;
2105                 break;
2106         case VDIR:
2107         case VREG:
2108                 vinitvmio(vp, ip->i_size);
2109                 break;
2110         case VLNK:
2111                 if (ip->i_size >= vp->v_mount->mnt_maxsymlinklen)
2112                         vinitvmio(vp, ip->i_size);
2113                 break;
2114         default:
2115                 break;
2116
2117         }
2118
2119         if (ip->i_number == ROOTINO)
2120                 vp->v_flag |= VROOT;
2121         /*
2122          * Initialize modrev times
2123          */
2124         getmicrouptime(&tv);
2125         SETHIGH(ip->i_modrev, tv.tv_sec);
2126         SETLOW(ip->i_modrev, tv.tv_usec * 4294);
2127         *vpp = vp;
2128         return (0);
2129 }
2130
2131 /*
2132  * Allocate a new inode.
2133  */
2134 static
2135 int
2136 ufs_makeinode(int mode, struct vnode *dvp, struct vnode **vpp,
2137               struct componentname *cnp)
2138 {
2139         struct inode *ip, *pdir;
2140         struct direct newdir;
2141         struct vnode *tvp;
2142         int error;
2143
2144         pdir = VTOI(dvp);
2145         *vpp = NULL;
2146         if ((mode & IFMT) == 0)
2147                 mode |= IFREG;
2148
2149         error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2150         if (error)
2151                 return (error);
2152         ip = VTOI(tvp);
2153         ip->i_gid = pdir->i_gid;
2154 #ifdef SUIDDIR
2155         {
2156 #ifdef QUOTA
2157                 struct ucred ucred, *ucp;
2158                 ucp = cnp->cn_cred;
2159 #endif
2160                 /*
2161                  * If we are not the owner of the directory,
2162                  * and we are hacking owners here, (only do this where told to)
2163                  * and we are not giving it TO root, (would subvert quotas)
2164                  * then go ahead and give it to the other user.
2165                  * Note that this drops off the execute bits for security.
2166                  */
2167                 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2168                     (pdir->i_mode & ISUID) &&
2169                     (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2170                         ip->i_uid = pdir->i_uid;
2171                         mode &= ~07111;
2172 #ifdef QUOTA
2173                         /*
2174                          * Make sure the correct user gets charged
2175                          * for the space.
2176                          * Quickly knock up a dummy credential for the victim.
2177                          * XXX This seems to never be accessed out of our
2178                          * context so a stack variable is ok.
2179                          */
2180                         ucred.cr_ref = 1;
2181                         ucred.cr_uid = ip->i_uid;
2182                         ucred.cr_ngroups = 1;
2183                         ucred.cr_groups[0] = pdir->i_gid;
2184                         ucp = &ucred;
2185 #endif
2186                 } else
2187                         ip->i_uid = cnp->cn_cred->cr_uid;
2188
2189 #ifdef QUOTA
2190                 if ((error = ufs_getinoquota(ip)) ||
2191                     (error = ufs_chkiq(ip, 1, ucp, 0))) {
2192                         UFS_VFREE(tvp, ip->i_number, mode);
2193                         vput(tvp);
2194                         return (error);
2195                 }
2196 #endif
2197         }
2198 #else   /* !SUIDDIR */
2199         ip->i_uid = cnp->cn_cred->cr_uid;
2200 #ifdef QUOTA
2201         if ((error = ufs_getinoquota(ip)) ||
2202             (error = ufs_chkiq(ip, 1, cnp->cn_cred, 0))) {
2203                 UFS_VFREE(tvp, ip->i_number, mode);
2204                 vput(tvp);
2205                 return (error);
2206         }
2207 #endif
2208 #endif  /* !SUIDDIR */
2209         ip->i_fsmid = cache_getnewfsmid();
2210         ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
2211         ip->i_mode = mode;
2212         tvp->v_type = IFTOVT(mode);     /* Rest init'd in getnewvnode(). */
2213         ip->i_effnlink = 1;
2214         ip->i_nlink = 1;
2215         if (DOINGSOFTDEP(tvp))
2216                 softdep_change_linkcnt(ip);
2217         if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2218             suser_cred(cnp->cn_cred, 0)) {
2219                 ip->i_mode &= ~ISGID;
2220         }
2221
2222         if (cnp->cn_flags & CNP_ISWHITEOUT)
2223                 ip->i_flags |= UF_OPAQUE;
2224
2225         /*
2226          * Regular files and directories need VM objects.  Softlinks do
2227          * not (not immediately anyway).
2228          */
2229         if (tvp->v_type == VREG || tvp->v_type == VDIR)
2230                 vinitvmio(tvp, 0);
2231
2232         /*
2233          * Make sure inode goes to disk before directory entry.
2234          */
2235         error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) | DOINGASYNC(tvp)));
2236         if (error)
2237                 goto bad;
2238         ufs_makedirentry(ip, cnp, &newdir);
2239         error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL);
2240         if (error)
2241                 goto bad;
2242         *vpp = tvp;
2243         return (0);
2244
2245 bad:
2246         /*
2247          * Write error occurred trying to update the inode
2248          * or the directory so must deallocate the inode.
2249          */
2250         ip->i_effnlink = 0;
2251         ip->i_nlink = 0;
2252         ip->i_flag |= IN_CHANGE;
2253         if (DOINGSOFTDEP(tvp))
2254                 softdep_change_linkcnt(ip);
2255         vput(tvp);
2256         return (error);
2257 }
2258
2259 static int
2260 ufs_missingop(struct vop_generic_args *ap)
2261 {
2262         panic("no vop function for %s in ufs child", ap->a_desc->vdesc_name);
2263         return (EOPNOTSUPP);
2264 }
2265
2266 static struct filterops ufsread_filtops = 
2267         { 1, NULL, filt_ufsdetach, filt_ufsread };
2268 static struct filterops ufswrite_filtops = 
2269         { 1, NULL, filt_ufsdetach, filt_ufswrite };
2270 static struct filterops ufsvnode_filtops = 
2271         { 1, NULL, filt_ufsdetach, filt_ufsvnode };
2272
2273 /*
2274  * ufs_kqfilter(struct vnode *a_vp, struct knote *a_kn)
2275  */
2276 static int
2277 ufs_kqfilter(struct vop_kqfilter_args *ap)
2278 {
2279         struct vnode *vp = ap->a_vp;
2280         struct knote *kn = ap->a_kn;
2281         lwkt_tokref ilock;
2282
2283         switch (kn->kn_filter) {
2284         case EVFILT_READ:
2285                 kn->kn_fop = &ufsread_filtops;
2286                 break;
2287         case EVFILT_WRITE:
2288                 kn->kn_fop = &ufswrite_filtops;
2289                 break;
2290         case EVFILT_VNODE:
2291                 kn->kn_fop = &ufsvnode_filtops;
2292                 break;
2293         default:
2294                 return (1);
2295         }
2296
2297         kn->kn_hook = (caddr_t)vp;
2298
2299         lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
2300         SLIST_INSERT_HEAD(&vp->v_pollinfo.vpi_selinfo.si_note, kn, kn_selnext);
2301         lwkt_reltoken(&ilock);
2302
2303         return (0);
2304 }
2305
2306 static void
2307 filt_ufsdetach(struct knote *kn)
2308 {
2309         struct vnode *vp = (struct vnode *)kn->kn_hook;
2310         lwkt_tokref ilock;
2311
2312         lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
2313         SLIST_REMOVE(&vp->v_pollinfo.vpi_selinfo.si_note,
2314             kn, knote, kn_selnext);
2315         lwkt_reltoken(&ilock);
2316 }
2317
2318 /*ARGSUSED*/
2319 static int
2320 filt_ufsread(struct knote *kn, long hint)
2321 {
2322         struct vnode *vp = (struct vnode *)kn->kn_hook;
2323         struct inode *ip = VTOI(vp);
2324
2325         /*
2326          * filesystem is gone, so set the EOF flag and schedule 
2327          * the knote for deletion.
2328          */
2329         if (hint == NOTE_REVOKE) {
2330                 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
2331                 return (1);
2332         }
2333
2334         kn->kn_data = ip->i_size - kn->kn_fp->f_offset;
2335         return (kn->kn_data != 0);
2336 }
2337
2338 /*ARGSUSED*/
2339 static int
2340 filt_ufswrite(struct knote *kn, long hint)
2341 {
2342         /*
2343          * filesystem is gone, so set the EOF flag and schedule 
2344          * the knote for deletion.
2345          */
2346         if (hint == NOTE_REVOKE)
2347                 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
2348
2349         kn->kn_data = 0;
2350         return (1);
2351 }
2352
2353 static int
2354 filt_ufsvnode(struct knote *kn, long hint)
2355 {
2356         if (kn->kn_sfflags & hint)
2357                 kn->kn_fflags |= hint;
2358         if (hint == NOTE_REVOKE) {
2359                 kn->kn_flags |= EV_EOF;
2360                 return (1);
2361         }
2362         return (kn->kn_fflags != 0);
2363 }
2364
2365 /* Global vfs data structures for ufs. */
2366 static struct vop_ops *ufs_vnode_vops;
2367 static struct vnodeopv_entry_desc ufs_vnodeop_entries[] = {
2368         { &vop_default_desc,            vop_defaultop },
2369         { &vop_fsync_desc,              (vnodeopv_entry_t) ufs_missingop },
2370         { &vop_read_desc,               (vnodeopv_entry_t) ufs_missingop },
2371         { &vop_reallocblks_desc,        (vnodeopv_entry_t) ufs_missingop },
2372         { &vop_write_desc,              (vnodeopv_entry_t) ufs_missingop },
2373         { &vop_access_desc,             (vnodeopv_entry_t) ufs_access },
2374         { &vop_advlock_desc,            (vnodeopv_entry_t) ufs_advlock },
2375         { &vop_bmap_desc,               (vnodeopv_entry_t) ufs_bmap },
2376         { &vop_old_lookup_desc,         (vnodeopv_entry_t) ufs_lookup },
2377         { &vop_close_desc,              (vnodeopv_entry_t) ufs_close },
2378         { &vop_old_create_desc,         (vnodeopv_entry_t) ufs_create },
2379         { &vop_getattr_desc,            (vnodeopv_entry_t) ufs_getattr },
2380         { &vop_inactive_desc,           (vnodeopv_entry_t) ufs_inactive },
2381         { &vop_islocked_desc,           (vnodeopv_entry_t) vop_stdislocked },
2382         { &vop_old_link_desc,           (vnodeopv_entry_t) ufs_link },
2383         { &vop_lock_desc,               (vnodeopv_entry_t) vop_stdlock },
2384         { &vop_old_mkdir_desc,          (vnodeopv_entry_t) ufs_mkdir },
2385         { &vop_old_mknod_desc,          (vnodeopv_entry_t) ufs_mknod },
2386         { &vop_mmap_desc,               (vnodeopv_entry_t) ufs_mmap },
2387         { &vop_open_desc,               (vnodeopv_entry_t) ufs_open },
2388         { &vop_pathconf_desc,           (vnodeopv_entry_t) ufs_pathconf },
2389         { &vop_poll_desc,               (vnodeopv_entry_t) vop_stdpoll },
2390         { &vop_kqfilter_desc,           (vnodeopv_entry_t) ufs_kqfilter },
2391         { &vop_print_desc,              (vnodeopv_entry_t) ufs_print },
2392         { &vop_readdir_desc,            (vnodeopv_entry_t) ufs_readdir },
2393         { &vop_readlink_desc,           (vnodeopv_entry_t) ufs_readlink },
2394         { &vop_reclaim_desc,            (vnodeopv_entry_t) ufs_reclaim },
2395         { &vop_old_remove_desc,         (vnodeopv_entry_t) ufs_remove },
2396         { &vop_old_rename_desc,         (vnodeopv_entry_t) ufs_rename },
2397         { &vop_old_rmdir_desc,          (vnodeopv_entry_t) ufs_rmdir },
2398         { &vop_setattr_desc,            (vnodeopv_entry_t) ufs_setattr },
2399         { &vop_strategy_desc,           (vnodeopv_entry_t) ufs_strategy },
2400         { &vop_old_symlink_desc,        (vnodeopv_entry_t) ufs_symlink },
2401         { &vop_unlock_desc,             (vnodeopv_entry_t) vop_stdunlock },
2402         { &vop_old_whiteout_desc,       (vnodeopv_entry_t) ufs_whiteout },
2403         { NULL, NULL }
2404 };
2405 static struct vnodeopv_desc ufs_vnodeop_opv_desc =
2406         { &ufs_vnode_vops, ufs_vnodeop_entries, VVF_SUPPORTS_FSMID };
2407
2408 static struct vop_ops *ufs_spec_vops;
2409 static struct vnodeopv_entry_desc ufs_specop_entries[] = {
2410         { &vop_default_desc,            (vnodeopv_entry_t) spec_vnoperate },
2411         { &vop_fsync_desc,              (vnodeopv_entry_t) ufs_missingop },
2412         { &vop_access_desc,             (vnodeopv_entry_t) ufs_access },
2413         { &vop_close_desc,              (vnodeopv_entry_t) ufsspec_close },
2414         { &vop_getattr_desc,            (vnodeopv_entry_t) ufs_getattr },
2415         { &vop_inactive_desc,           (vnodeopv_entry_t) ufs_inactive },
2416         { &vop_islocked_desc,           (vnodeopv_entry_t) vop_stdislocked },
2417         { &vop_lock_desc,               (vnodeopv_entry_t) vop_stdlock },
2418         { &vop_print_desc,              (vnodeopv_entry_t) ufs_print },
2419         { &vop_read_desc,               (vnodeopv_entry_t) ufsspec_read },
2420         { &vop_reclaim_desc,            (vnodeopv_entry_t) ufs_reclaim },
2421         { &vop_setattr_desc,            (vnodeopv_entry_t) ufs_setattr },
2422         { &vop_unlock_desc,             (vnodeopv_entry_t) vop_stdunlock },
2423         { &vop_write_desc,              (vnodeopv_entry_t) ufsspec_write },
2424         { NULL, NULL }
2425 };
2426 static struct vnodeopv_desc ufs_specop_opv_desc =
2427         { &ufs_spec_vops, ufs_specop_entries, VVF_SUPPORTS_FSMID };
2428
2429 static struct vop_ops *ufs_fifo_vops;
2430 static struct vnodeopv_entry_desc ufs_fifoop_entries[] = {
2431         { &vop_default_desc,            (vnodeopv_entry_t) fifo_vnoperate },
2432         { &vop_fsync_desc,              (vnodeopv_entry_t) ufs_missingop },
2433         { &vop_access_desc,             (vnodeopv_entry_t) ufs_access },
2434         { &vop_close_desc,              (vnodeopv_entry_t) ufsfifo_close },
2435         { &vop_getattr_desc,            (vnodeopv_entry_t) ufs_getattr },
2436         { &vop_inactive_desc,           (vnodeopv_entry_t) ufs_inactive },
2437         { &vop_islocked_desc,           (vnodeopv_entry_t) vop_stdislocked },
2438         { &vop_kqfilter_desc,           (vnodeopv_entry_t) ufsfifo_kqfilter },
2439         { &vop_lock_desc,               (vnodeopv_entry_t) vop_stdlock },
2440         { &vop_print_desc,              (vnodeopv_entry_t) ufs_print },
2441         { &vop_read_desc,               (vnodeopv_entry_t) ufsfifo_read },
2442         { &vop_reclaim_desc,            (vnodeopv_entry_t) ufs_reclaim },
2443         { &vop_setattr_desc,            (vnodeopv_entry_t) ufs_setattr },
2444         { &vop_unlock_desc,             (vnodeopv_entry_t) vop_stdunlock },
2445         { &vop_write_desc,              (vnodeopv_entry_t) ufsfifo_write },
2446         { NULL, NULL }
2447 };
2448 static struct vnodeopv_desc ufs_fifoop_opv_desc =
2449         { &ufs_fifo_vops, ufs_fifoop_entries, VVF_SUPPORTS_FSMID };
2450
2451 VNODEOP_SET(ufs_vnodeop_opv_desc);
2452 VNODEOP_SET(ufs_specop_opv_desc);
2453 VNODEOP_SET(ufs_fifoop_opv_desc);
2454
2455 /*
2456  * ufs_vnoperate(struct vnodeop_desc *a_desc)
2457  */
2458 int
2459 ufs_vnoperate(struct vop_generic_args *ap)
2460 {
2461         return (VOCALL(ufs_vnode_vops, ap));
2462 }
2463
2464 /*
2465  * ufs_vnoperatefifo(struct vnodeop_desc *a_desc)
2466  */
2467 int
2468 ufs_vnoperatefifo(struct vop_generic_args *ap)
2469 {
2470         return (VOCALL(ufs_fifo_vops, ap));
2471 }
2472
2473 /*
2474  * ufs_vnoperatespec(struct vnodeop_desc *a_desc)
2475  */
2476 int
2477 ufs_vnoperatespec(struct vop_generic_args *ap)
2478 {
2479         return (VOCALL(ufs_spec_vops, ap));
2480 }