xref: /minix/sys/ufs/ext2fs/ext2fs_vnops.c (revision 84d9c625)
1 /*	$NetBSD: ext2fs_vnops.c,v 1.107 2013/03/18 19:35:47 plunky Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1986, 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)ufs_vnops.c	8.14 (Berkeley) 10/26/94
37  * Modified for ext2fs by Manuel Bouyer.
38  */
39 
40 /*
41  * Copyright (c) 1997 Manuel Bouyer.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  *
63  *	@(#)ufs_vnops.c	8.14 (Berkeley) 10/26/94
64  * Modified for ext2fs by Manuel Bouyer.
65  */
66 
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: ext2fs_vnops.c,v 1.107 2013/03/18 19:35:47 plunky Exp $");
69 
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/resourcevar.h>
73 #include <sys/kernel.h>
74 #include <sys/file.h>
75 #include <sys/stat.h>
76 #include <sys/buf.h>
77 #include <sys/proc.h>
78 #include <sys/mount.h>
79 #include <sys/namei.h>
80 #include <sys/vnode.h>
81 #include <sys/lockf.h>
82 #include <sys/malloc.h>
83 #include <sys/pool.h>
84 #include <sys/signalvar.h>
85 #include <sys/kauth.h>
86 
87 #include <miscfs/fifofs/fifo.h>
88 #include <miscfs/genfs/genfs.h>
89 #include <miscfs/specfs/specdev.h>
90 
91 #include <ufs/ufs/inode.h>
92 #include <ufs/ufs/ufs_extern.h>
93 #include <ufs/ufs/ufsmount.h>
94 
95 #include <ufs/ext2fs/ext2fs.h>
96 #include <ufs/ext2fs/ext2fs_extern.h>
97 #include <ufs/ext2fs/ext2fs_dir.h>
98 
99 extern int prtactive;
100 
101 static int ext2fs_chmod(struct vnode *, int, kauth_cred_t, struct lwp *);
102 static int ext2fs_chown(struct vnode *, uid_t, gid_t, kauth_cred_t,
103 				struct lwp *);
104 
105 union _qcvt {
106 	int64_t	qcvt;
107 	int32_t val[2];
108 };
109 
110 #define SETHIGH(q, h) { \
111 	union _qcvt tmp; \
112 	tmp.qcvt = (q); \
113 	tmp.val[_QUAD_HIGHWORD] = (h); \
114 	(q) = tmp.qcvt; \
115 }
116 #define SETLOW(q, l) { \
117 	union _qcvt tmp; \
118 	tmp.qcvt = (q); \
119 	tmp.val[_QUAD_LOWWORD] = (l); \
120 	(q) = tmp.qcvt; \
121 }
122 
123 /*
124  * Create a regular file
125  */
126 int
127 ext2fs_create(void *v)
128 {
129 	struct vop_create_args /* {
130 		struct vnode *a_dvp;
131 		struct vnode **a_vpp;
132 		struct componentname *a_cnp;
133 		struct vattr *a_vap;
134 	} */ *ap = v;
135 	int	error;
136 
137 	error =
138 	    ext2fs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
139 			     ap->a_dvp, ap->a_vpp, ap->a_cnp);
140 
141 	if (error)
142 		return (error);
143 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
144 	return (0);
145 }
146 
147 /*
148  * Mknod vnode call
149  */
150 /* ARGSUSED */
151 int
152 ext2fs_mknod(void *v)
153 {
154 	struct vop_mknod_args /* {
155 		struct vnode *a_dvp;
156 		struct vnode **a_vpp;
157 		struct componentname *a_cnp;
158 		struct vattr *a_vap;
159 	} */ *ap = v;
160 	struct vattr *vap = ap->a_vap;
161 	struct vnode **vpp = ap->a_vpp;
162 	struct inode *ip;
163 	int error;
164 	struct mount	*mp;
165 	ino_t		ino;
166 
167 	if ((error = ext2fs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
168 		    ap->a_dvp, vpp, ap->a_cnp)) != 0)
169 		return (error);
170 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
171 	ip = VTOI(*vpp);
172 	mp  = (*vpp)->v_mount;
173 	ino = ip->i_number;
174 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
175 	if (vap->va_rdev != VNOVAL) {
176 		/*
177 		 * Want to be able to use this to make badblock
178 		 * inodes, so don't truncate the dev number.
179 		 */
180 		ip->i_din.e2fs_din->e2di_rdev = h2fs32(vap->va_rdev);
181 	}
182 	/*
183 	 * Remove inode so that it will be reloaded by VFS_VGET and
184 	 * checked to see if it is an alias of an existing entry in
185 	 * the inode cache.
186 	 */
187 	VOP_UNLOCK(*vpp);
188 	(*vpp)->v_type = VNON;
189 	vgone(*vpp);
190 	error = VFS_VGET(mp, ino, vpp);
191 	if (error != 0) {
192 		*vpp = NULL;
193 		return (error);
194 	}
195 	return (0);
196 }
197 
198 /*
199  * Open called.
200  *
201  * Just check the APPEND flag.
202  */
203 /* ARGSUSED */
204 int
205 ext2fs_open(void *v)
206 {
207 	struct vop_open_args /* {
208 		struct vnode *a_vp;
209 		int  a_mode;
210 		kauth_cred_t a_cred;
211 	} */ *ap = v;
212 
213 	/*
214 	 * Files marked append-only must be opened for appending.
215 	 */
216 	if ((VTOI(ap->a_vp)->i_e2fs_flags & EXT2_APPEND) &&
217 		(ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
218 		return (EPERM);
219 	return (0);
220 }
221 
222 static int
223 ext2fs_check_possible(struct vnode *vp, struct inode *ip, mode_t mode)
224 {
225 
226 	/*
227 	 * Disallow write attempts on read-only file systems;
228 	 * unless the file is a socket, fifo, or a block or
229 	 * character device resident on the file system.
230 	 */
231 	if (mode & VWRITE) {
232 		switch (vp->v_type) {
233 		case VDIR:
234 		case VLNK:
235 		case VREG:
236 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
237 				return (EROFS);
238 			break;
239 		default:
240 			break;
241 		}
242 	}
243 
244 	/* If immutable bit set, nobody gets to write it. */
245 	if ((mode & VWRITE) && (ip->i_e2fs_flags & EXT2_IMMUTABLE))
246 		return (EPERM);
247 
248 	return 0;
249 }
250 
251 static int
252 ext2fs_check_permitted(struct vnode *vp, struct inode *ip, mode_t mode,
253     kauth_cred_t cred)
254 {
255 
256 	return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(mode, vp->v_type,
257 	    ip->i_e2fs_mode & ALLPERMS), vp, NULL, genfs_can_access(vp->v_type,
258 	    ip->i_e2fs_mode & ALLPERMS, ip->i_uid, ip->i_gid, mode, cred));
259 }
260 
261 int
262 ext2fs_access(void *v)
263 {
264 	struct vop_access_args /* {
265 		struct vnode *a_vp;
266 		int  a_mode;
267 		kauth_cred_t a_cred;
268 	} */ *ap = v;
269 	struct vnode *vp = ap->a_vp;
270 	struct inode *ip = VTOI(vp);
271 	mode_t mode = ap->a_mode;
272 	int error;
273 
274 	error = ext2fs_check_possible(vp, ip, mode);
275 	if (error)
276 		return error;
277 
278 	error = ext2fs_check_permitted(vp, ip, mode, ap->a_cred);
279 
280 	return error;
281 }
282 
283 /* ARGSUSED */
284 int
285 ext2fs_getattr(void *v)
286 {
287 	struct vop_getattr_args /* {
288 		struct vnode *a_vp;
289 		struct vattr *a_vap;
290 		kauth_cred_t a_cred;
291 	} */ *ap = v;
292 	struct vnode *vp = ap->a_vp;
293 	struct inode *ip = VTOI(vp);
294 	struct vattr *vap = ap->a_vap;
295 
296 	EXT2FS_ITIMES(ip, NULL, NULL, NULL);
297 	/*
298 	 * Copy from inode table
299 	 */
300 	vap->va_fsid = ip->i_dev;
301 	vap->va_fileid = ip->i_number;
302 	vap->va_mode = ip->i_e2fs_mode & ALLPERMS;
303 	vap->va_nlink = ip->i_e2fs_nlink;
304 	vap->va_uid = ip->i_uid;
305 	vap->va_gid = ip->i_gid;
306 	vap->va_rdev = (dev_t)fs2h32(ip->i_din.e2fs_din->e2di_rdev);
307 	vap->va_size = vp->v_size;
308 	vap->va_atime.tv_sec = ip->i_e2fs_atime;
309 	vap->va_atime.tv_nsec = 0;
310 	vap->va_mtime.tv_sec = ip->i_e2fs_mtime;
311 	vap->va_mtime.tv_nsec = 0;
312 	vap->va_ctime.tv_sec = ip->i_e2fs_ctime;
313 	vap->va_ctime.tv_nsec = 0;
314 #ifdef EXT2FS_SYSTEM_FLAGS
315 	vap->va_flags = (ip->i_e2fs_flags & EXT2_APPEND) ? SF_APPEND : 0;
316 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_IMMUTABLE) ? SF_IMMUTABLE : 0;
317 #else
318 	vap->va_flags = (ip->i_e2fs_flags & EXT2_APPEND) ? UF_APPEND : 0;
319 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_IMMUTABLE) ? UF_IMMUTABLE : 0;
320 #endif
321 	vap->va_gen = ip->i_e2fs_gen;
322 	/* this doesn't belong here */
323 	if (vp->v_type == VBLK)
324 		vap->va_blocksize = BLKDEV_IOSIZE;
325 	else if (vp->v_type == VCHR)
326 		vap->va_blocksize = MAXBSIZE;
327 	else
328 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
329 	vap->va_bytes = dbtob(ext2fs_nblock(ip));
330 	vap->va_type = vp->v_type;
331 	vap->va_filerev = ip->i_modrev;
332 	return (0);
333 }
334 
335 /*
336  * Set attribute vnode op. called from several syscalls
337  */
338 int
339 ext2fs_setattr(void *v)
340 {
341 	struct vop_setattr_args /* {
342 		struct vnode *a_vp;
343 		struct vattr *a_vap;
344 		kauth_cred_t a_cred;
345 	} */ *ap = v;
346 	struct vattr *vap = ap->a_vap;
347 	struct vnode *vp = ap->a_vp;
348 	struct inode *ip = VTOI(vp);
349 	kauth_cred_t cred = ap->a_cred;
350 	struct lwp *l = curlwp;
351 	int error;
352 	kauth_action_t action = KAUTH_VNODE_WRITE_FLAGS;
353 	bool changing_sysflags = false;
354 
355 	/*
356 	 * Check for unsettable attributes.
357 	 */
358 	if ((vap->va_type != VNON) || (vap->va_nlink != (nlink_t)VNOVAL) ||
359 	    (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
360 	    (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
361 	    ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
362 		return (EINVAL);
363 	}
364 	if (vap->va_flags != VNOVAL) {
365 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
366 			return (EROFS);
367 
368 		/*
369 		 * Check if we're allowed to change the flags.
370 		 * If EXT2FS_SYSTEM_FLAGS is set, then the flags are treated
371 		 * as system flags, otherwise they're considered to be user
372 		 * flags.
373 		 */
374 #ifdef EXT2FS_SYSTEM_FLAGS
375 		/* Indicate we're changing system flags if we are. */
376 		if ((vap->va_flags & SF_APPEND) ||
377 		     (vap->va_flags & SF_IMMUTABLE)) {
378 			action |= KAUTH_VNODE_WRITE_SYSFLAGS;
379 			changing_sysflags = true;
380 		}
381 
382 		/* Indicate the node has system flags if it does. */
383 		if (ip->i_e2fs_flags & (EXT2_APPEND | EXT2_IMMUTABLE)) {
384 			action |= KAUTH_VNODE_HAS_SYSFLAGS;
385 		}
386 #endif /* EXT2FS_SYSTEM_FLAGS */
387 
388 		error = kauth_authorize_vnode(cred, action, vp, NULL,
389 		    genfs_can_chflags(cred, vp->v_type, ip->i_uid,
390 		    changing_sysflags));
391 		if (error)
392 			return (error);
393 
394 #ifdef EXT2FS_SYSTEM_FLAGS
395 		ip->i_e2fs_flags &= ~(EXT2_APPEND | EXT2_IMMUTABLE);
396 		ip->i_e2fs_flags |=
397 		    (vap->va_flags & SF_APPEND) ?  EXT2_APPEND : 0 |
398 		    (vap->va_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE : 0;
399 #else
400 		ip->i_e2fs_flags &= ~(EXT2_APPEND | EXT2_IMMUTABLE);
401 		ip->i_e2fs_flags |=
402 		    (vap->va_flags & UF_APPEND) ? EXT2_APPEND : 0 |
403 		    (vap->va_flags & UF_IMMUTABLE) ? EXT2_IMMUTABLE : 0;
404 #endif
405 		ip->i_flag |= IN_CHANGE;
406 		if (vap->va_flags & (IMMUTABLE | APPEND))
407 			return (0);
408 	}
409 	if (ip->i_e2fs_flags & (EXT2_APPEND | EXT2_IMMUTABLE))
410 		return (EPERM);
411 	/*
412 	 * Go through the fields and update iff not VNOVAL.
413 	 */
414 	if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
415 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
416 			return (EROFS);
417 		error = ext2fs_chown(vp, vap->va_uid, vap->va_gid, cred, l);
418 		if (error)
419 			return (error);
420 	}
421 	if (vap->va_size != VNOVAL) {
422 		/*
423 		 * Disallow write attempts on read-only file systems;
424 		 * unless the file is a socket, fifo, or a block or
425 		 * character device resident on the file system.
426 		 */
427 		switch (vp->v_type) {
428 		case VDIR:
429 			return (EISDIR);
430 		case VLNK:
431 		case VREG:
432 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
433 				return (EROFS);
434 		default:
435 			break;
436 		}
437 		error = ext2fs_truncate(vp, vap->va_size, 0, cred);
438 		if (error)
439 			return (error);
440 	}
441 	ip = VTOI(vp);
442 	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
443 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
444 			return (EROFS);
445 		error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
446 		    NULL, genfs_can_chtimes(vp, vap->va_vaflags, ip->i_uid,
447 		    cred));
448 		if (error)
449 			return (error);
450 		if (vap->va_atime.tv_sec != VNOVAL)
451 			if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
452 				ip->i_flag |= IN_ACCESS;
453 		if (vap->va_mtime.tv_sec != VNOVAL) {
454 			ip->i_flag |= IN_CHANGE | IN_UPDATE;
455 			if (vp->v_mount->mnt_flag & MNT_RELATIME)
456 				ip->i_flag |= IN_ACCESS;
457 		}
458 		error = ext2fs_update(vp, &vap->va_atime, &vap->va_mtime,
459 			UPDATE_WAIT);
460 		if (error)
461 			return (error);
462 	}
463 	error = 0;
464 	if (vap->va_mode != (mode_t)VNOVAL) {
465 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
466 			return (EROFS);
467 		error = ext2fs_chmod(vp, (int)vap->va_mode, cred, l);
468 	}
469 	VN_KNOTE(vp, NOTE_ATTRIB);
470 	return (error);
471 }
472 
473 /*
474  * Change the mode on a file.
475  * Inode must be locked before calling.
476  */
477 static int
478 ext2fs_chmod(struct vnode *vp, int mode, kauth_cred_t cred, struct lwp *l)
479 {
480 	struct inode *ip = VTOI(vp);
481 	int error;
482 
483 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp,
484 	    NULL, genfs_can_chmod(vp->v_type, cred, ip->i_uid, ip->i_gid,
485 	    mode));
486 	if (error)
487 		return (error);
488 
489 	ip->i_e2fs_mode &= ~ALLPERMS;
490 	ip->i_e2fs_mode |= (mode & ALLPERMS);
491 	ip->i_flag |= IN_CHANGE;
492 	return (0);
493 }
494 
495 /*
496  * Perform chown operation on inode ip;
497  * inode must be locked prior to call.
498  */
499 static int
500 ext2fs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred,
501 		struct lwp *l)
502 {
503 	struct inode *ip = VTOI(vp);
504 	uid_t ouid;
505 	gid_t ogid;
506 	int error;
507 
508 	if (uid == (uid_t)VNOVAL)
509 		uid = ip->i_uid;
510 	if (gid == (gid_t)VNOVAL)
511 		gid = ip->i_gid;
512 
513 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP, vp,
514 	    NULL, genfs_can_chown(cred, ip->i_uid, ip->i_gid, uid, gid));
515 	if (error)
516 		return (error);
517 
518 	ogid = ip->i_gid;
519 	ouid = ip->i_uid;
520 
521 	ip->i_e2fs_gid = gid & 0xffff;
522 	ip->i_e2fs_uid = uid & 0xffff;
523 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0) {
524 		ip->i_e2fs_gid_high = (gid >> 16) & 0xffff;
525 		ip->i_e2fs_uid_high = (uid >> 16) & 0xffff;
526 	} else {
527 		ip->i_e2fs_gid_high = 0;
528 		ip->i_e2fs_uid_high = 0;
529 	}
530 	if (ouid != uid || ogid != gid) {
531 		ext2fs_set_inode_guid(ip);
532 		ip->i_flag |= IN_CHANGE;
533 	}
534 	if (ouid != uid && (ip->i_e2fs_mode & ISUID) &&
535 	    kauth_authorize_vnode(cred, KAUTH_VNODE_RETAIN_SUID,
536 	    vp, NULL, EPERM) != 0)
537 		ip->i_e2fs_mode &= ~ISUID;
538 	if (ogid != gid && (ip->i_e2fs_mode & ISGID) &&
539 	    kauth_authorize_vnode(cred, KAUTH_VNODE_RETAIN_SGID,
540 	    vp, NULL, EPERM) != 0)
541 		ip->i_e2fs_mode &= ~ISGID;
542 	return (0);
543 }
544 
545 int
546 ext2fs_remove(void *v)
547 {
548 	struct vop_remove_args /* {
549 		struct vnode *a_dvp;
550 		struct vnode *a_vp;
551 		struct componentname *a_cnp;
552 	} */ *ap = v;
553 	struct inode *ip;
554 	struct vnode *vp = ap->a_vp;
555 	struct vnode *dvp = ap->a_dvp;
556 	struct ufs_lookup_results *ulr;
557 	int error;
558 
559 	/* XXX should handle this material another way */
560 	ulr = &VTOI(dvp)->i_crap;
561 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
562 
563 	ip = VTOI(vp);
564 	if (vp->v_type == VDIR ||
565 		(ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) ||
566 		(VTOI(dvp)->i_e2fs_flags & EXT2_APPEND)) {
567 		error = EPERM;
568 	} else {
569 		error = ext2fs_dirremove(dvp, ulr, ap->a_cnp);
570 		if (error == 0) {
571 			ip->i_e2fs_nlink--;
572 			ip->i_flag |= IN_CHANGE;
573 		}
574 	}
575 
576 	VN_KNOTE(vp, NOTE_DELETE);
577 	VN_KNOTE(dvp, NOTE_WRITE);
578 	if (dvp == vp)
579 		vrele(vp);
580 	else
581 		vput(vp);
582 	vput(dvp);
583 	return (error);
584 }
585 
586 /*
587  * ext2fs_link: create hard link.
588  */
589 int
590 ext2fs_link(void *v)
591 {
592 	struct vop_link_args /* {
593 		struct vnode *a_dvp;
594 		struct vnode *a_vp;
595 		struct componentname *a_cnp;
596 	} */ *ap = v;
597 	struct vnode *dvp = ap->a_dvp;
598 	struct vnode *vp = ap->a_vp;
599 	struct componentname *cnp = ap->a_cnp;
600 	struct inode *ip;
601 	int error;
602 	struct ufs_lookup_results *ulr;
603 
604 	KASSERT(dvp != vp);
605 	KASSERT(vp->v_type != VDIR);
606 	KASSERT(dvp->v_mount == vp->v_mount);
607 
608 	/* XXX should handle this material another way */
609 	ulr = &VTOI(dvp)->i_crap;
610 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
611 
612 	error = vn_lock(vp, LK_EXCLUSIVE);
613 	if (error) {
614 		VOP_ABORTOP(dvp, cnp);
615 		goto out2;
616 	}
617 	ip = VTOI(vp);
618 	if ((nlink_t)ip->i_e2fs_nlink >= LINK_MAX) {
619 		VOP_ABORTOP(dvp, cnp);
620 		error = EMLINK;
621 		goto out1;
622 	}
623 	if (ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) {
624 		VOP_ABORTOP(dvp, cnp);
625 		error = EPERM;
626 		goto out1;
627 	}
628 	ip->i_e2fs_nlink++;
629 	ip->i_flag |= IN_CHANGE;
630 	error = ext2fs_update(vp, NULL, NULL, UPDATE_WAIT);
631 	if (!error)
632 		error = ext2fs_direnter(ip, dvp, ulr, cnp);
633 	if (error) {
634 		ip->i_e2fs_nlink--;
635 		ip->i_flag |= IN_CHANGE;
636 	}
637 out1:
638 	VOP_UNLOCK(vp);
639 out2:
640 	VN_KNOTE(vp, NOTE_LINK);
641 	VN_KNOTE(dvp, NOTE_WRITE);
642 	vput(dvp);
643 	return (error);
644 }
645 
646 /*
647  * Mkdir system call
648  */
649 int
650 ext2fs_mkdir(void *v)
651 {
652 	struct vop_mkdir_args /* {
653 		struct vnode *a_dvp;
654 		struct vnode **a_vpp;
655 		struct componentname *a_cnp;
656 		struct vattr *a_vap;
657 	} */ *ap = v;
658 	struct vnode		*dvp = ap->a_dvp;
659 	struct vattr		*vap = ap->a_vap;
660 	struct componentname	*cnp = ap->a_cnp;
661 	struct inode		*ip, *dp = VTOI(dvp);
662 	struct vnode		*tvp;
663 	struct ext2fs_dirtemplate dirtemplate;
664 	int			error, dmode;
665 	struct ufs_lookup_results *ulr;
666 
667 	/* XXX should handle this material another way */
668 	ulr = &VTOI(dvp)->i_crap;
669 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
670 
671 	if ((nlink_t)dp->i_e2fs_nlink >= LINK_MAX) {
672 		error = EMLINK;
673 		goto out;
674 	}
675 	dmode = vap->va_mode & ACCESSPERMS;
676 	dmode |= IFDIR;
677 	/*
678 	 * Must simulate part of ext2fs_makeinode here to acquire the inode,
679 	 * but not have it entered in the parent directory. The entry is
680 	 * made later after writing "." and ".." entries.
681 	 */
682 	if ((error = ext2fs_valloc(dvp, dmode, cnp->cn_cred, &tvp)) != 0)
683 		goto out;
684 	ip = VTOI(tvp);
685 	ip->i_uid = kauth_cred_geteuid(cnp->cn_cred);
686 	ip->i_e2fs_uid = ip->i_uid & 0xffff;
687 	ip->i_e2fs_gid = dp->i_e2fs_gid;
688 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0) {
689 		ip->i_e2fs_uid_high = (ip->i_uid >> 16) & 0xffff;
690 		ip->i_e2fs_gid_high = dp->i_e2fs_gid_high;
691 	} else {
692 		ip->i_e2fs_uid_high = 0;
693 		ip->i_e2fs_gid_high = 0;
694 	}
695 	ip->i_gid = ip->i_e2fs_gid | (ip->i_e2fs_gid_high << 16);
696 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
697 	ip->i_e2fs_mode = dmode;
698 	tvp->v_type = VDIR;	/* Rest init'd in getnewvnode(). */
699 	ip->i_e2fs_nlink = 2;
700 
701 	/*
702 	 * Bump link count in parent directory
703 	 * to reflect work done below.  Should
704 	 * be done before reference is created
705 	 * so reparation is possible if we crash.
706 	 */
707 	dp->i_e2fs_nlink++;
708 	dp->i_flag |= IN_CHANGE;
709 	if ((error = ext2fs_update(dvp, NULL, NULL, UPDATE_DIROP)) != 0)
710 		goto bad;
711 
712 	/* Initialize directory with "." and ".." from static template. */
713 	memset(&dirtemplate, 0, sizeof(dirtemplate));
714 	dirtemplate.dot_ino = h2fs32(ip->i_number);
715 	dirtemplate.dot_reclen = h2fs16(12);
716 	dirtemplate.dot_namlen = 1;
717 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
718 	    (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {
719 		dirtemplate.dot_type = EXT2_FT_DIR;
720 	}
721 	dirtemplate.dot_name[0] = '.';
722 	dirtemplate.dotdot_ino = h2fs32(dp->i_number);
723     dirtemplate.dotdot_reclen = h2fs16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12);
724 	dirtemplate.dotdot_namlen = 2;
725 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
726 	    (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {
727 		dirtemplate.dotdot_type = EXT2_FT_DIR;
728 	}
729 	dirtemplate.dotdot_name[0] = dirtemplate.dotdot_name[1] = '.';
730 	error = vn_rdwr(UIO_WRITE, tvp, (void *)&dirtemplate,
731 	    sizeof (dirtemplate), (off_t)0, UIO_SYSSPACE,
732 	    IO_NODELOCKED|IO_SYNC, cnp->cn_cred, (size_t *)0, NULL);
733 	if (error) {
734 		dp->i_e2fs_nlink--;
735 		dp->i_flag |= IN_CHANGE;
736 		goto bad;
737 	}
738 	if (VTOI(dvp)->i_e2fs->e2fs_bsize > dvp->v_mount->mnt_stat.f_bsize)
739 		panic("ext2fs_mkdir: blksize"); /* XXX should grow with balloc() */
740 	else {
741 		error = ext2fs_setsize(ip, VTOI(dvp)->i_e2fs->e2fs_bsize);
742 		if (error) {
743 			dp->i_e2fs_nlink--;
744 			dp->i_flag |= IN_CHANGE;
745 			goto bad;
746 		}
747 		ip->i_flag |= IN_CHANGE;
748 		uvm_vnp_setsize(tvp, ext2fs_size(ip));
749 	}
750 
751 	/* Directory set up, now install it's entry in the parent directory. */
752 	error = ext2fs_direnter(ip, dvp, ulr, cnp);
753 	if (error != 0) {
754 		dp->i_e2fs_nlink--;
755 		dp->i_flag |= IN_CHANGE;
756 	}
757 bad:
758 	/*
759 	 * No need to do an explicit ext2fs_truncate here, vrele will do this
760 	 * for us because we set the link count to 0.
761 	 */
762 	if (error) {
763 		ip->i_e2fs_nlink = 0;
764 		ip->i_flag |= IN_CHANGE;
765 		vput(tvp);
766 	} else {
767 		VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
768 		*ap->a_vpp = tvp;
769 	}
770 out:
771 	vput(dvp);
772 	return (error);
773 }
774 
775 /*
776  * Rmdir system call.
777  */
778 int
779 ext2fs_rmdir(void *v)
780 {
781 	struct vop_rmdir_args /* {
782 		struct vnode *a_dvp;
783 		struct vnode *a_vp;
784 		struct componentname *a_cnp;
785 	} */ *ap = v;
786 	struct vnode *vp = ap->a_vp;
787 	struct vnode *dvp = ap->a_dvp;
788 	struct componentname *cnp = ap->a_cnp;
789 	struct inode *ip, *dp;
790 	int error;
791 	struct ufs_lookup_results *ulr;
792 
793 	ip = VTOI(vp);
794 	dp = VTOI(dvp);
795 
796 	/* XXX should handle this material another way */
797 	ulr = &dp->i_crap;
798 	UFS_CHECK_CRAPCOUNTER(dp);
799 
800 	/*
801 	 * No rmdir "." please.
802 	 */
803 	if (dp == ip) {
804 		vrele(dvp);
805 		vput(vp);
806 		return (EINVAL);
807 	}
808 	/*
809 	 * Verify the directory is empty (and valid).
810 	 * (Rmdir ".." won't be valid since
811 	 *  ".." will contain a reference to
812 	 *  the current directory and thus be
813 	 *  non-empty.)
814 	 */
815 	error = 0;
816 	if (ip->i_e2fs_nlink != 2 ||
817 	    !ext2fs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
818 		error = ENOTEMPTY;
819 		goto out;
820 	}
821 	if ((dp->i_e2fs_flags & EXT2_APPEND) ||
822 				 (ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND))) {
823 		error = EPERM;
824 		goto out;
825 	}
826 	/*
827 	 * Delete reference to directory before purging
828 	 * inode.  If we crash in between, the directory
829 	 * will be reattached to lost+found,
830 	 */
831 	error = ext2fs_dirremove(dvp, ulr, cnp);
832 	if (error != 0)
833 		goto out;
834 	dp->i_e2fs_nlink--;
835 	dp->i_flag |= IN_CHANGE;
836 	VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
837 	cache_purge(dvp);
838 	vput(dvp);
839 	dvp = NULL;
840 	/*
841 	 * Truncate inode.  The only stuff left
842 	 * in the directory is "." and "..".  The
843 	 * "." reference is inconsequential since
844 	 * we're quashing it.  The ".." reference
845 	 * has already been adjusted above.  We've
846 	 * removed the "." reference and the reference
847 	 * in the parent directory, but there may be
848 	 * other hard links so decrement by 2 and
849 	 * worry about them later.
850 	 */
851 	ip->i_e2fs_nlink -= 2;
852 	error = ext2fs_truncate(vp, (off_t)0, IO_SYNC, cnp->cn_cred);
853 	cache_purge(ITOV(ip));
854 out:
855 	VN_KNOTE(vp, NOTE_DELETE);
856 	if (dvp)
857 		vput(dvp);
858 	vput(vp);
859 	return (error);
860 }
861 
862 /*
863  * symlink -- make a symbolic link
864  */
865 int
866 ext2fs_symlink(void *v)
867 {
868 	struct vop_symlink_args /* {
869 		struct vnode *a_dvp;
870 		struct vnode **a_vpp;
871 		struct componentname *a_cnp;
872 		struct vattr *a_vap;
873 		char *a_target;
874 	} */ *ap = v;
875 	struct vnode	*vp, **vpp;
876 	struct inode	*ip;
877 	int		len, error;
878 
879 	vpp = ap->a_vpp;
880 	error = ext2fs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
881 			      vpp, ap->a_cnp);
882 	if (error)
883 		return (error);
884 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
885 	vp = *vpp;
886 	len = strlen(ap->a_target);
887 	ip = VTOI(vp);
888 	if (len < ip->i_ump->um_maxsymlinklen) {
889 		memcpy((char *)ip->i_din.e2fs_din->e2di_shortlink, ap->a_target, len);
890 		error = ext2fs_setsize(ip, len);
891 		if (error)
892 			goto bad;
893 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
894 		if (vp->v_mount->mnt_flag & MNT_RELATIME)
895 			ip->i_flag |= IN_ACCESS;
896 		uvm_vnp_setsize(vp, len);
897 	} else
898 		error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
899 		    UIO_SYSSPACE, IO_NODELOCKED, ap->a_cnp->cn_cred,
900 		    (size_t *)0, NULL);
901 bad:
902 	if (error)
903 		vput(vp);
904 	return (error);
905 }
906 
907 /*
908  * Return target name of a symbolic link
909  */
910 int
911 ext2fs_readlink(void *v)
912 {
913 	struct vop_readlink_args /* {
914 		struct vnode *a_vp;
915 		struct uio *a_uio;
916 		kauth_cred_t a_cred;
917 	} */ *ap = v;
918 	struct vnode	*vp = ap->a_vp;
919 	struct inode	*ip = VTOI(vp);
920 	struct ufsmount	*ump = ip->i_ump;
921 	int		isize;
922 
923 	isize = ext2fs_size(ip);
924 	if (isize < ump->um_maxsymlinklen ||
925 	    (ump->um_maxsymlinklen == 0 && ext2fs_nblock(ip) == 0)) {
926 		uiomove((char *)ip->i_din.e2fs_din->e2di_shortlink, isize, ap->a_uio);
927 		return (0);
928 	}
929 	return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
930 }
931 
932 /*
933  * Advisory record locking support
934  */
935 int
936 ext2fs_advlock(void *v)
937 {
938 	struct vop_advlock_args /* {
939 		struct vnode *a_vp;
940 		void * a_id;
941 		int  a_op;
942 		struct flock *a_fl;
943 		int  a_flags;
944 	} */ *ap = v;
945 	struct inode *ip = VTOI(ap->a_vp);
946 
947 	return lf_advlock(ap, &ip->i_lockf, ext2fs_size(ip));
948 }
949 
950 int
951 ext2fs_fsync(void *v)
952 {
953 	struct vop_fsync_args /* {
954 		struct vnode *a_vp;
955 		kauth_cred_t a_cred;
956 		int a_flags;
957 		off_t offlo;
958 		off_t offhi;
959 		struct proc *a_p;
960 	} */ *ap = v;
961 	struct vnode *vp = ap->a_vp;
962 	int wait;
963 	int error;
964 
965 	wait = (ap->a_flags & FSYNC_WAIT) != 0;
966 
967 	if (vp->v_type == VBLK)
968 		error = spec_fsync(v);
969 	else
970 		error = vflushbuf(vp, ap->a_flags);
971 	if (error == 0 && (ap->a_flags & FSYNC_DATAONLY) == 0)
972 		error = ext2fs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0);
973 
974 	if (error == 0 && ap->a_flags & FSYNC_CACHE) {
975 		int l = 0;
976 		error = VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
977 		    curlwp->l_cred);
978 	}
979 
980 	return error;
981 }
982 
983 /*
984  * Initialize the vnode associated with a new inode, handle aliased
985  * vnodes.
986  */
987 int
988 ext2fs_vinit(struct mount *mntp, int (**specops)(void *),
989 	int (**fifoops)(void *), struct vnode **vpp)
990 {
991 	struct timeval tv;
992 	struct inode *ip;
993 	struct vnode *vp;
994 
995 	vp = *vpp;
996 	ip = VTOI(vp);
997 	switch(vp->v_type = IFTOVT(ip->i_e2fs_mode)) {
998 	case VCHR:
999 	case VBLK:
1000 		vp->v_op = specops;
1001 		spec_node_init(vp, fs2h32(ip->i_din.e2fs_din->e2di_rdev));
1002 		break;
1003 	case VFIFO:
1004 		vp->v_op = fifoops;
1005 		break;
1006 	case VNON:
1007 	case VBAD:
1008 	case VSOCK:
1009 	case VLNK:
1010 	case VDIR:
1011 	case VREG:
1012 		break;
1013 	}
1014 	if (ip->i_number == UFS_ROOTINO)
1015                 vp->v_vflag |= VV_ROOT;
1016 	/*
1017 	 * Initialize modrev times
1018 	 */
1019 	getmicrouptime(&tv);
1020 	SETHIGH(ip->i_modrev, tv.tv_sec);
1021 	SETLOW(ip->i_modrev, tv.tv_usec * 4294);
1022 	*vpp = vp;
1023 	return (0);
1024 }
1025 
1026 /*
1027  * Allocate a new inode.
1028  */
1029 int
1030 ext2fs_makeinode(int mode, struct vnode *dvp, struct vnode **vpp,
1031 		struct componentname *cnp)
1032 {
1033 	struct inode *ip, *pdir;
1034 	struct vnode *tvp;
1035 	int error;
1036 	struct ufs_lookup_results *ulr;
1037 
1038 	pdir = VTOI(dvp);
1039 
1040 	/* XXX should handle this material another way */
1041 	ulr = &pdir->i_crap;
1042 	UFS_CHECK_CRAPCOUNTER(pdir);
1043 
1044 	*vpp = NULL;
1045 	if ((mode & IFMT) == 0)
1046 		mode |= IFREG;
1047 
1048 	if ((error = ext2fs_valloc(dvp, mode, cnp->cn_cred, &tvp)) != 0) {
1049 		vput(dvp);
1050 		return (error);
1051 	}
1052 	ip = VTOI(tvp);
1053 	ip->i_uid = kauth_cred_geteuid(cnp->cn_cred);
1054 	ip->i_e2fs_uid = ip->i_uid & 0xffff;
1055 	ip->i_e2fs_gid = pdir->i_e2fs_gid;
1056 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0) {
1057 		ip->i_e2fs_uid_high = (ip->i_uid >> 16) & 0xffff;
1058 		ip->i_e2fs_gid_high = pdir->i_e2fs_gid_high;
1059 	} else {
1060 		ip->i_e2fs_uid_high = 0;
1061 		ip->i_e2fs_gid_high = 0;
1062 	}
1063 	ip->i_gid = ip->i_e2fs_gid | (ip->i_e2fs_gid_high << 16);
1064 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1065 	ip->i_e2fs_mode = mode;
1066 	tvp->v_type = IFTOVT(mode);	/* Rest init'd in getnewvnode(). */
1067 	ip->i_e2fs_nlink = 1;
1068 
1069 	/* Authorize setting SGID if needed. */
1070 	if (ip->i_e2fs_mode & ISGID) {
1071 		error = kauth_authorize_vnode(cnp->cn_cred, KAUTH_VNODE_WRITE_SECURITY,
1072 		    tvp, NULL, genfs_can_chmod(tvp->v_type, cnp->cn_cred, ip->i_uid,
1073 		    ip->i_gid, mode));
1074 		if (error)
1075 			ip->i_e2fs_mode &= ~ISGID;
1076 	}
1077 
1078 	/*
1079 	 * Make sure inode goes to disk before directory entry.
1080 	 */
1081 	if ((error = ext2fs_update(tvp, NULL, NULL, UPDATE_WAIT)) != 0)
1082 		goto bad;
1083 	error = ext2fs_direnter(ip, dvp, ulr, cnp);
1084 	if (error != 0)
1085 		goto bad;
1086 	vput(dvp);
1087 	*vpp = tvp;
1088 	return (0);
1089 
1090 bad:
1091 	/*
1092 	 * Write error occurred trying to update the inode
1093 	 * or the directory so must deallocate the inode.
1094 	 */
1095 	tvp->v_type = VNON;	/* Stop explosion if VBLK */
1096 	ip->i_e2fs_nlink = 0;
1097 	ip->i_flag |= IN_CHANGE;
1098 	vput(tvp);
1099 	vput(dvp);
1100 	return (error);
1101 }
1102 
1103 /*
1104  * Reclaim an inode so that it can be used for other purposes.
1105  */
1106 int
1107 ext2fs_reclaim(void *v)
1108 {
1109 	struct vop_reclaim_args /* {
1110 		struct vnode *a_vp;
1111 	} */ *ap = v;
1112 	struct vnode *vp = ap->a_vp;
1113 	struct inode *ip = VTOI(vp);
1114 	int error;
1115 
1116 	/*
1117 	 * The inode must be freed and updated before being removed
1118 	 * from its hash chain.  Other threads trying to gain a hold
1119 	 * on the inode will be stalled because it is locked (VI_XLOCK).
1120 	 */
1121 	if (ip->i_omode == 1 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
1122 		ext2fs_vfree(vp, ip->i_number, ip->i_e2fs_mode);
1123 	if ((error = ufs_reclaim(vp)) != 0)
1124 		return (error);
1125 	if (ip->i_din.e2fs_din != NULL)
1126 		pool_put(&ext2fs_dinode_pool, ip->i_din.e2fs_din);
1127 	genfs_node_destroy(vp);
1128 	pool_put(&ext2fs_inode_pool, vp->v_data);
1129 	vp->v_data = NULL;
1130 	return (0);
1131 }
1132 
1133 /* Global vfs data structures for ext2fs. */
1134 int (**ext2fs_vnodeop_p)(void *);
1135 const struct vnodeopv_entry_desc ext2fs_vnodeop_entries[] = {
1136 	{ &vop_default_desc, vn_default_error },
1137 	{ &vop_lookup_desc, ext2fs_lookup },		/* lookup */
1138 	{ &vop_create_desc, ext2fs_create },		/* create */
1139 	{ &vop_mknod_desc, ext2fs_mknod },		/* mknod */
1140 	{ &vop_open_desc, ext2fs_open },		/* open */
1141 	{ &vop_close_desc, ufs_close },			/* close */
1142 	{ &vop_access_desc, ext2fs_access },		/* access */
1143 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
1144 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
1145 	{ &vop_read_desc, ext2fs_read },		/* read */
1146 	{ &vop_write_desc, ext2fs_write },		/* write */
1147 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
1148 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
1149 	{ &vop_poll_desc, ufs_poll },			/* poll */
1150 	{ &vop_kqfilter_desc, genfs_kqfilter },		/* kqfilter */
1151 	{ &vop_revoke_desc, ufs_revoke },		/* revoke */
1152 	{ &vop_mmap_desc, ufs_mmap },			/* mmap */
1153 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
1154 	{ &vop_seek_desc, ufs_seek },			/* seek */
1155 	{ &vop_remove_desc, ext2fs_remove },		/* remove */
1156 	{ &vop_link_desc, ext2fs_link },		/* link */
1157 	{ &vop_rename_desc, ext2fs_rename },		/* rename */
1158 	{ &vop_mkdir_desc, ext2fs_mkdir },		/* mkdir */
1159 	{ &vop_rmdir_desc, ext2fs_rmdir },		/* rmdir */
1160 	{ &vop_symlink_desc, ext2fs_symlink },		/* symlink */
1161 	{ &vop_readdir_desc, ext2fs_readdir },		/* readdir */
1162 	{ &vop_readlink_desc, ext2fs_readlink },	/* readlink */
1163 	{ &vop_abortop_desc, ufs_abortop },		/* abortop */
1164 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
1165 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
1166 	{ &vop_lock_desc, ufs_lock },			/* lock */
1167 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
1168 	{ &vop_bmap_desc, ext2fs_bmap },		/* bmap */
1169 	{ &vop_strategy_desc, ufs_strategy },		/* strategy */
1170 	{ &vop_print_desc, ufs_print },			/* print */
1171 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
1172 	{ &vop_pathconf_desc, ufs_pathconf },		/* pathconf */
1173 	{ &vop_advlock_desc, ext2fs_advlock },		/* advlock */
1174 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
1175 	{ &vop_getpages_desc, genfs_getpages },		/* getpages */
1176 	{ &vop_putpages_desc, genfs_putpages },		/* putpages */
1177 	{ NULL, NULL }
1178 };
1179 const struct vnodeopv_desc ext2fs_vnodeop_opv_desc =
1180 	{ &ext2fs_vnodeop_p, ext2fs_vnodeop_entries };
1181 
1182 int (**ext2fs_specop_p)(void *);
1183 const struct vnodeopv_entry_desc ext2fs_specop_entries[] = {
1184 	{ &vop_default_desc, vn_default_error },
1185 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
1186 	{ &vop_create_desc, spec_create },		/* create */
1187 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
1188 	{ &vop_open_desc, spec_open },			/* open */
1189 	{ &vop_close_desc, ufsspec_close },		/* close */
1190 	{ &vop_access_desc, ext2fs_access },		/* access */
1191 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
1192 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
1193 	{ &vop_read_desc, ufsspec_read },		/* read */
1194 	{ &vop_write_desc, ufsspec_write },		/* write */
1195 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
1196 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
1197 	{ &vop_poll_desc, spec_poll },			/* poll */
1198 	{ &vop_kqfilter_desc, spec_kqfilter },		/* kqfilter */
1199 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
1200 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
1201 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
1202 	{ &vop_seek_desc, spec_seek },			/* seek */
1203 	{ &vop_remove_desc, spec_remove },		/* remove */
1204 	{ &vop_link_desc, spec_link },			/* link */
1205 	{ &vop_rename_desc, spec_rename },		/* rename */
1206 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
1207 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
1208 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
1209 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
1210 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
1211 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
1212 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
1213 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
1214 	{ &vop_lock_desc, ufs_lock },			/* lock */
1215 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
1216 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
1217 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
1218 	{ &vop_print_desc, ufs_print },			/* print */
1219 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
1220 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
1221 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
1222 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
1223 	{ &vop_getpages_desc, spec_getpages },		/* getpages */
1224 	{ &vop_putpages_desc, spec_putpages },		/* putpages */
1225 	{ NULL, NULL }
1226 };
1227 const struct vnodeopv_desc ext2fs_specop_opv_desc =
1228 	{ &ext2fs_specop_p, ext2fs_specop_entries };
1229 
1230 int (**ext2fs_fifoop_p)(void *);
1231 const struct vnodeopv_entry_desc ext2fs_fifoop_entries[] = {
1232 	{ &vop_default_desc, vn_default_error },
1233 	{ &vop_lookup_desc, vn_fifo_bypass },		/* lookup */
1234 	{ &vop_create_desc, vn_fifo_bypass },		/* create */
1235 	{ &vop_mknod_desc, vn_fifo_bypass },		/* mknod */
1236 	{ &vop_open_desc, vn_fifo_bypass },		/* open */
1237 	{ &vop_close_desc, ufsfifo_close },		/* close */
1238 	{ &vop_access_desc, ext2fs_access },		/* access */
1239 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
1240 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
1241 	{ &vop_read_desc, ufsfifo_read },		/* read */
1242 	{ &vop_write_desc, ufsfifo_write },		/* write */
1243 	{ &vop_ioctl_desc, vn_fifo_bypass },		/* ioctl */
1244 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
1245 	{ &vop_poll_desc, vn_fifo_bypass },		/* poll */
1246 	{ &vop_kqfilter_desc, vn_fifo_bypass },		/* kqfilter */
1247 	{ &vop_revoke_desc, vn_fifo_bypass },		/* revoke */
1248 	{ &vop_mmap_desc, vn_fifo_bypass },		/* mmap */
1249 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
1250 	{ &vop_seek_desc, vn_fifo_bypass },		/* seek */
1251 	{ &vop_remove_desc, vn_fifo_bypass },		/* remove */
1252 	{ &vop_link_desc, vn_fifo_bypass },		/* link */
1253 	{ &vop_rename_desc, vn_fifo_bypass },		/* rename */
1254 	{ &vop_mkdir_desc, vn_fifo_bypass },		/* mkdir */
1255 	{ &vop_rmdir_desc, vn_fifo_bypass },		/* rmdir */
1256 	{ &vop_symlink_desc, vn_fifo_bypass },		/* symlink */
1257 	{ &vop_readdir_desc, vn_fifo_bypass },		/* readdir */
1258 	{ &vop_readlink_desc, vn_fifo_bypass },		/* readlink */
1259 	{ &vop_abortop_desc, vn_fifo_bypass },		/* abortop */
1260 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
1261 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
1262 	{ &vop_lock_desc, ufs_lock },			/* lock */
1263 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
1264 	{ &vop_bmap_desc, vn_fifo_bypass },		/* bmap */
1265 	{ &vop_strategy_desc, vn_fifo_bypass },		/* strategy */
1266 	{ &vop_print_desc, ufs_print },			/* print */
1267 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
1268 	{ &vop_pathconf_desc, vn_fifo_bypass },		/* pathconf */
1269 	{ &vop_advlock_desc, vn_fifo_bypass },		/* advlock */
1270 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
1271 	{ &vop_putpages_desc, vn_fifo_bypass },		/* putpages */
1272 	{ NULL, NULL }
1273 };
1274 const struct vnodeopv_desc ext2fs_fifoop_opv_desc =
1275 	{ &ext2fs_fifoop_p, ext2fs_fifoop_entries };
1276