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