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