2 * modified for EXT2FS support in Lites 1.1
4 * Aug 1995, Godmar Back (gback@cs.utah.edu)
5 * University of Utah, Department of Computer Science
8 * Copyright (c) 1982, 1986, 1989, 1993
9 * The Regents of the University of California. All rights reserved.
10 * (c) UNIX System Laboratories, Inc.
11 * All or some portions of this file are derived from material licensed
12 * to the University of California by American Telephone and Telegraph
13 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
14 * the permission of UNIX System Laboratories, Inc.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * @(#)ufs_vnops.c 8.7 (Berkeley) 2/3/94
45 * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
49 #include "opt_suiddir.h"
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/resourcevar.h>
54 #include <sys/kernel.h>
55 #include <sys/fcntl.h>
60 #include <sys/mount.h>
61 #include <sys/unistd.h>
63 #include <sys/vnode.h>
64 #include <sys/namei.h>
65 #include <sys/lockf.h>
66 #include <sys/event.h>
71 #include <vm/vm_extern.h>
72 #include <vm/vnode_pager.h>
74 #include <fs/fifofs/fifo.h>
76 #include <sys/signalvar.h>
77 #include <ufs/ufs/dir.h>
79 #include <gnu/ext2fs/inode.h>
80 #include <gnu/ext2fs/ext2_mount.h>
81 #include <gnu/ext2fs/ext2_fs_sb.h>
82 #include <gnu/ext2fs/fs.h>
83 #include <gnu/ext2fs/ext2_extern.h>
84 #include <gnu/ext2fs/ext2_fs.h>
86 static int ext2_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
88 static int ext2_access(struct vop_access_args *);
89 static int ext2_advlock(struct vop_advlock_args *);
90 static int ext2_chmod(struct vnode *, int, struct ucred *, struct thread *);
91 static int ext2_chown(struct vnode *, uid_t, gid_t, struct ucred *,
93 static int ext2_close(struct vop_close_args *);
94 static int ext2_create(struct vop_create_args *);
95 static int ext2_fsync(struct vop_fsync_args *);
96 static int ext2_getattr(struct vop_getattr_args *);
97 static int ext2_kqfilter(struct vop_kqfilter_args *ap);
98 static int ext2_link(struct vop_link_args *);
99 static int ext2_mkdir(struct vop_mkdir_args *);
100 static int ext2_mknod(struct vop_mknod_args *);
101 static int ext2_open(struct vop_open_args *);
102 static int ext2_pathconf(struct vop_pathconf_args *);
103 static int ext2_print(struct vop_print_args *);
104 static int ext2_read(struct vop_read_args *);
105 static int ext2_readlink(struct vop_readlink_args *);
106 static int ext2_remove(struct vop_remove_args *);
107 static int ext2_rename(struct vop_rename_args *);
108 static int ext2_rmdir(struct vop_rmdir_args *);
109 static int ext2_setattr(struct vop_setattr_args *);
110 static int ext2_strategy(struct vop_strategy_args *);
111 static int ext2_symlink(struct vop_symlink_args *);
112 static int ext2_write(struct vop_write_args *);
113 static int ext2fifo_close(struct vop_close_args *);
114 static int ext2fifo_kqfilter(struct vop_kqfilter_args *);
115 static int ext2fifo_read(struct vop_read_args *);
116 static int ext2fifo_write(struct vop_write_args *);
117 static int ext2spec_close(struct vop_close_args *);
118 static int ext2spec_read(struct vop_read_args *);
119 static int ext2spec_write(struct vop_write_args *);
120 static int filt_ext2read(struct knote *kn, long hint);
121 static int filt_ext2write(struct knote *kn, long hint);
122 static int filt_ext2vnode(struct knote *kn, long hint);
123 static void filt_ext2detach(struct knote *kn);
125 /* Global vfs data structures for ext2. */
126 vop_t **ext2_vnodeop_p;
127 static struct vnodeopv_entry_desc ext2_vnodeop_entries[] = {
128 { &vop_default_desc, (vop_t *) vop_defaultop },
129 { &vop_access_desc, (vop_t *) ext2_access },
130 { &vop_advlock_desc, (vop_t *) ext2_advlock },
131 { &vop_bmap_desc, (vop_t *) ext2_bmap },
132 { &vop_cachedlookup_desc, (vop_t *) ext2_lookup },
133 { &vop_close_desc, (vop_t *) ext2_close },
134 { &vop_create_desc, (vop_t *) ext2_create },
135 { &vop_fsync_desc, (vop_t *) ext2_fsync },
136 { &vop_getattr_desc, (vop_t *) ext2_getattr },
137 { &vop_getwritemount_desc, (vop_t *) vop_stdgetwritemount },
138 { &vop_inactive_desc, (vop_t *) ext2_inactive },
139 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
140 { &vop_link_desc, (vop_t *) ext2_link },
141 { &vop_lock_desc, (vop_t *) vop_stdlock },
142 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
143 { &vop_mkdir_desc, (vop_t *) ext2_mkdir },
144 { &vop_mknod_desc, (vop_t *) ext2_mknod },
145 { &vop_open_desc, (vop_t *) ext2_open },
146 { &vop_pathconf_desc, (vop_t *) ext2_pathconf },
147 { &vop_poll_desc, (vop_t *) vop_stdpoll },
148 { &vop_kqfilter_desc, (vop_t *) ext2_kqfilter },
149 { &vop_print_desc, (vop_t *) ext2_print },
150 { &vop_read_desc, (vop_t *) ext2_read },
151 { &vop_readdir_desc, (vop_t *) ext2_readdir },
152 { &vop_readlink_desc, (vop_t *) ext2_readlink },
153 { &vop_reallocblks_desc, (vop_t *) ext2_reallocblks },
154 { &vop_reclaim_desc, (vop_t *) ext2_reclaim },
155 { &vop_remove_desc, (vop_t *) ext2_remove },
156 { &vop_rename_desc, (vop_t *) ext2_rename },
157 { &vop_rmdir_desc, (vop_t *) ext2_rmdir },
158 { &vop_setattr_desc, (vop_t *) ext2_setattr },
159 { &vop_strategy_desc, (vop_t *) ext2_strategy },
160 { &vop_symlink_desc, (vop_t *) ext2_symlink },
161 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
162 { &vop_write_desc, (vop_t *) ext2_write },
165 static struct vnodeopv_desc ext2fs_vnodeop_opv_desc =
166 { &ext2_vnodeop_p, ext2_vnodeop_entries };
168 vop_t **ext2_specop_p;
169 static struct vnodeopv_entry_desc ext2_specop_entries[] = {
170 { &vop_default_desc, (vop_t *) spec_vnoperate },
171 { &vop_access_desc, (vop_t *) ext2_access },
172 { &vop_close_desc, (vop_t *) ext2spec_close },
173 { &vop_fsync_desc, (vop_t *) ext2_fsync },
174 { &vop_getattr_desc, (vop_t *) ext2_getattr },
175 { &vop_inactive_desc, (vop_t *) ext2_inactive },
176 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
177 { &vop_lock_desc, (vop_t *) vop_stdlock },
178 { &vop_print_desc, (vop_t *) ext2_print },
179 { &vop_read_desc, (vop_t *) ext2spec_read },
180 { &vop_reclaim_desc, (vop_t *) ext2_reclaim },
181 { &vop_setattr_desc, (vop_t *) ext2_setattr },
182 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
183 { &vop_write_desc, (vop_t *) ext2spec_write },
186 static struct vnodeopv_desc ext2fs_specop_opv_desc =
187 { &ext2_specop_p, ext2_specop_entries };
189 vop_t **ext2_fifoop_p;
190 static struct vnodeopv_entry_desc ext2_fifoop_entries[] = {
191 { &vop_default_desc, (vop_t *) fifo_vnoperate },
192 { &vop_access_desc, (vop_t *) ext2_access },
193 { &vop_close_desc, (vop_t *) ext2fifo_close },
194 { &vop_fsync_desc, (vop_t *) ext2_fsync },
195 { &vop_getattr_desc, (vop_t *) ext2_getattr },
196 { &vop_inactive_desc, (vop_t *) ext2_inactive },
197 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
198 { &vop_kqfilter_desc, (vop_t *) ext2fifo_kqfilter },
199 { &vop_lock_desc, (vop_t *) vop_stdlock },
200 { &vop_print_desc, (vop_t *) ext2_print },
201 { &vop_read_desc, (vop_t *) ext2fifo_read },
202 { &vop_reclaim_desc, (vop_t *) ext2_reclaim },
203 { &vop_setattr_desc, (vop_t *) ext2_setattr },
204 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
205 { &vop_write_desc, (vop_t *) ext2fifo_write },
208 static struct vnodeopv_desc ext2fs_fifoop_opv_desc =
209 { &ext2_fifoop_p, ext2_fifoop_entries };
211 VNODEOP_SET(ext2fs_vnodeop_opv_desc);
212 VNODEOP_SET(ext2fs_specop_opv_desc);
213 VNODEOP_SET(ext2fs_fifoop_opv_desc);
215 #include <gnu/ext2fs/ext2_readwrite.c>
221 #define SETHIGH(q, h) { \
224 tmp.val[_QUAD_HIGHWORD] = (h); \
227 #define SETLOW(q, l) { \
230 tmp.val[_QUAD_LOWWORD] = (l); \
235 * A virgin directory (no blushing please).
236 * Note that the type and namlen fields are reversed relative to ext2.
237 * Also, we don't use `struct odirtemplate', since it would just cause
238 * endianness problems.
240 static struct dirtemplate mastertemplate = {
241 0, 12, 1, EXT2_FT_DIR, ".",
242 0, DIRBLKSIZ - 12, 2, EXT2_FT_DIR, ".."
244 static struct dirtemplate omastertemplate = {
245 0, 12, 1, EXT2_FT_UNKNOWN, ".",
246 0, DIRBLKSIZ - 12, 2, EXT2_FT_UNKNOWN, ".."
257 if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
259 if ((vp->v_type == VBLK || vp->v_type == VCHR))
260 ip->i_flag |= IN_LAZYMOD;
262 ip->i_flag |= IN_MODIFIED;
263 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
265 if (ip->i_flag & IN_ACCESS) {
266 ip->i_atime = ts.tv_sec;
267 ip->i_atimensec = ts.tv_nsec;
269 if (ip->i_flag & IN_UPDATE) {
270 ip->i_mtime = ts.tv_sec;
271 ip->i_mtimensec = ts.tv_nsec;
274 if (ip->i_flag & IN_CHANGE) {
275 ip->i_ctime = ts.tv_sec;
276 ip->i_ctimensec = ts.tv_nsec;
279 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
283 * Create a regular file
287 struct vop_create_args /* {
289 struct vnode **a_vpp;
290 struct componentname *a_cnp;
297 ext2_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
298 ap->a_dvp, ap->a_vpp, ap->a_cnp);
311 struct vop_open_args /* {
314 struct ucred *a_cred;
320 * Files marked append-only must be opened for appending.
322 if ((VTOI(ap->a_vp)->i_flags & APPEND) &&
323 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
331 * Update the times on the inode.
335 struct vop_close_args /* {
338 struct ucred *a_cred;
342 struct vnode *vp = ap->a_vp;
345 mtx_lock(&vp->v_interlock);
346 if (vp->v_usecount > 1) {
348 mtx_unlock(&vp->v_interlock);
350 mtx_unlock(&vp->v_interlock);
352 * If we are closing the last reference to an unlinked
353 * file, then it will be freed by the inactive routine.
354 * Because the freeing causes a the filesystem to be
355 * modified, it must be held up during periods when the
356 * filesystem is suspended.
358 * XXX - EAGAIN is returned to prevent vn_close from
359 * repeating the vrele operation.
361 if (vp->v_type == VREG && VTOI(vp)->i_nlink == 0) {
362 (void) vn_start_write(vp, &mp, V_WAIT);
364 vn_finished_write(mp);
373 struct vop_access_args /* {
376 struct ucred *a_cred;
380 struct vnode *vp = ap->a_vp;
381 struct inode *ip = VTOI(vp);
382 mode_t mode = ap->a_mode;
386 * Disallow write attempts on read-only file systems;
387 * unless the file is a socket, fifo, or a block or
388 * character device resident on the file system.
391 switch (vp->v_type) {
395 if (vp->v_mount->mnt_flag & MNT_RDONLY)
403 /* If immutable bit set, nobody gets to write it. */
404 if ((mode & VWRITE) && (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
407 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
408 ap->a_mode, ap->a_cred, NULL);
414 struct vop_getattr_args /* {
417 struct ucred *a_cred;
421 struct vnode *vp = ap->a_vp;
422 struct inode *ip = VTOI(vp);
423 struct vattr *vap = ap->a_vap;
427 * Copy from inode table
429 vap->va_fsid = dev2udev(ip->i_dev);
430 vap->va_fileid = ip->i_number;
431 vap->va_mode = ip->i_mode & ~IFMT;
432 vap->va_nlink = ip->i_nlink;
433 vap->va_uid = ip->i_uid;
434 vap->va_gid = ip->i_gid;
435 vap->va_rdev = ip->i_rdev;
436 vap->va_size = ip->i_size;
437 vap->va_atime.tv_sec = ip->i_atime;
438 vap->va_atime.tv_nsec = ip->i_atimensec;
439 vap->va_mtime.tv_sec = ip->i_mtime;
440 vap->va_mtime.tv_nsec = ip->i_mtimensec;
441 vap->va_ctime.tv_sec = ip->i_ctime;
442 vap->va_ctime.tv_nsec = ip->i_ctimensec;
443 vap->va_flags = ip->i_flags;
444 vap->va_gen = ip->i_gen;
445 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
446 vap->va_bytes = dbtob((u_quad_t)ip->i_blocks);
447 vap->va_type = IFTOVT(ip->i_mode);
448 vap->va_filerev = ip->i_modrev;
453 * Set attribute vnode op. called from several syscalls
457 struct vop_setattr_args /* {
460 struct ucred *a_cred;
464 struct vattr *vap = ap->a_vap;
465 struct vnode *vp = ap->a_vp;
466 struct inode *ip = VTOI(vp);
467 struct ucred *cred = ap->a_cred;
468 struct thread *td = ap->a_td;
472 * Check for unsettable attributes.
474 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
475 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
476 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
477 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
480 if (vap->va_flags != VNOVAL) {
481 if (vp->v_mount->mnt_flag & MNT_RDONLY)
484 * Callers may only modify the file flags on objects they
485 * have VADMIN rights for.
487 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
490 * Unprivileged processes and privileged processes in
491 * jail() are not permitted to unset system flags, or
492 * modify flags if any system flags are set.
493 * Privileged non-jail processes may not modify system flags
494 * if securelevel > 0 and any existing system flags are set.
496 if (!suser_cred(cred, PRISON_ROOT)) {
498 & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
499 error = securelevel_gt(cred, 0);
503 ip->i_flags = vap->va_flags;
506 & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
507 (vap->va_flags & UF_SETTABLE) != vap->va_flags)
509 ip->i_flags &= SF_SETTABLE;
510 ip->i_flags |= (vap->va_flags & UF_SETTABLE);
512 ip->i_flag |= IN_CHANGE;
513 if (vap->va_flags & (IMMUTABLE | APPEND))
516 if (ip->i_flags & (IMMUTABLE | APPEND))
519 * Go through the fields and update iff not VNOVAL.
521 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
522 if (vp->v_mount->mnt_flag & MNT_RDONLY)
524 if ((error = ext2_chown(vp, vap->va_uid, vap->va_gid, cred,
528 if (vap->va_size != VNOVAL) {
530 * Disallow write attempts on read-only file systems;
531 * unless the file is a socket, fifo, or a block or
532 * character device resident on the file system.
534 switch (vp->v_type) {
539 if (vp->v_mount->mnt_flag & MNT_RDONLY)
545 if ((error = ext2_truncate(vp, vap->va_size, 0, cred, td)) != 0)
548 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
549 if (vp->v_mount->mnt_flag & MNT_RDONLY)
553 * If times is NULL, ... The caller must be the owner of
554 * the file, have permission to write the file, or be the
556 * If times is non-NULL, ... The caller must be the owner of
557 * the file or be the super-user.
559 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)) &&
560 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
561 (error = VOP_ACCESS(vp, VWRITE, cred, td))))
563 if (vap->va_atime.tv_sec != VNOVAL)
564 ip->i_flag |= IN_ACCESS;
565 if (vap->va_mtime.tv_sec != VNOVAL)
566 ip->i_flag |= IN_CHANGE | IN_UPDATE;
568 if (vap->va_atime.tv_sec != VNOVAL) {
569 ip->i_atime = vap->va_atime.tv_sec;
570 ip->i_atimensec = vap->va_atime.tv_nsec;
572 if (vap->va_mtime.tv_sec != VNOVAL) {
573 ip->i_mtime = vap->va_mtime.tv_sec;
574 ip->i_mtimensec = vap->va_mtime.tv_nsec;
576 error = ext2_update(vp, 0);
581 if (vap->va_mode != (mode_t)VNOVAL) {
582 if (vp->v_mount->mnt_flag & MNT_RDONLY)
584 error = ext2_chmod(vp, (int)vap->va_mode, cred, td);
586 VN_KNOTE(vp, NOTE_ATTRIB);
591 * Change the mode on a file.
592 * Inode must be locked before calling.
595 ext2_chmod(vp, mode, cred, td)
601 struct inode *ip = VTOI(vp);
605 * To modify the permissions on a file, must possess VADMIN
608 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
611 * Privileged processes may set the sticky bit on non-directories,
612 * as well as set the setgid bit on a file with a group that the
613 * process is not a member of.
615 if (suser_cred(cred, PRISON_ROOT)) {
616 if (vp->v_type != VDIR && (mode & S_ISTXT))
618 if (!groupmember(ip->i_gid, cred) && (mode & ISGID))
621 ip->i_mode &= ~ALLPERMS;
622 ip->i_mode |= (mode & ALLPERMS);
623 ip->i_flag |= IN_CHANGE;
628 * Perform chown operation on inode ip;
629 * inode must be locked prior to call.
632 ext2_chown(vp, uid, gid, cred, td)
639 struct inode *ip = VTOI(vp);
644 if (uid == (uid_t)VNOVAL)
646 if (gid == (gid_t)VNOVAL)
649 * To modify the ownership of a file, must possess VADMIN
652 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
655 * To change the owner of a file, or change the group of a file
656 * to a group of which we are not a member, the caller must
659 if ((uid != ip->i_uid ||
660 (gid != ip->i_gid && !groupmember(gid, cred))) &&
661 (error = suser_cred(cred, PRISON_ROOT)))
667 ip->i_flag |= IN_CHANGE;
668 if (suser_cred(cred, PRISON_ROOT) && (ouid != uid || ogid != gid))
669 ip->i_mode &= ~(ISUID | ISGID);
674 * Synch an open file.
679 struct vop_fsync_args /* {
681 struct ucred *a_cred;
686 struct vnode *vp = ap->a_vp;
692 * XXX why is all this fs specific?
696 * Flush all dirty buffers associated with a vnode.
698 ext2_discard_prealloc(VTOI(vp));
702 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
703 nbp = TAILQ_NEXT(bp, b_vnbufs);
704 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT))
706 if ((bp->b_flags & B_DELWRI) == 0)
707 panic("ext2_fsync: not dirty");
711 * Wait for I/O associated with indirect blocks to complete,
712 * since there is no way to quickly wait for them below.
714 if (bp->b_vp == vp || ap->a_waitfor == MNT_NOWAIT)
720 if (ap->a_waitfor == MNT_WAIT) {
722 while (vp->v_numoutput) {
723 vp->v_iflag |= VI_BWAIT;
724 msleep(&vp->v_numoutput, VI_MTX(vp),
725 PRIBIO + 1, "e2fsyn", 0);
729 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
730 vprint("ext2_fsync: dirty", vp);
736 return (ext2_update(ap->a_vp, ap->a_waitfor == MNT_WAIT));
745 struct vop_mknod_args /* {
747 struct vnode **a_vpp;
748 struct componentname *a_cnp;
752 struct vattr *vap = ap->a_vap;
753 struct vnode **vpp = ap->a_vpp;
758 error = ext2_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
759 ap->a_dvp, vpp, ap->a_cnp);
763 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
764 if (vap->va_rdev != VNOVAL) {
766 * Want to be able to use this to make badblock
767 * inodes, so don't truncate the dev number.
769 ip->i_rdev = vap->va_rdev;
772 * Remove inode, then reload it through VFS_VGET so it is
773 * checked to see if it is an alias of an existing entry in
777 (*vpp)->v_type = VNON;
778 ino = ip->i_number; /* Save this before vgone() invalidates ip. */
780 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
790 struct vop_remove_args /* {
793 struct componentname *a_cnp;
797 struct vnode *vp = ap->a_vp;
798 struct vnode *dvp = ap->a_dvp;
802 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
803 (VTOI(dvp)->i_flags & APPEND)) {
807 error = ext2_dirremove(dvp, ap->a_cnp);
810 ip->i_flag |= IN_CHANGE;
821 struct vop_link_args /* {
822 struct vnode *a_tdvp;
824 struct componentname *a_cnp;
827 struct vnode *vp = ap->a_vp;
828 struct vnode *tdvp = ap->a_tdvp;
829 struct componentname *cnp = ap->a_cnp;
830 struct thread *td = cnp->cn_thread;
835 if ((cnp->cn_flags & HASBUF) == 0)
836 panic("ext2_link: no name");
838 if (tdvp->v_mount != vp->v_mount) {
842 if (tdvp != vp && (error = vn_lock(vp, LK_EXCLUSIVE, td))) {
846 if ((nlink_t)ip->i_nlink >= LINK_MAX) {
850 if (ip->i_flags & (IMMUTABLE | APPEND)) {
855 ip->i_flag |= IN_CHANGE;
856 error = ext2_update(vp, 1);
858 error = ext2_direnter(ip, tdvp, cnp);
861 ip->i_flag |= IN_CHANGE;
865 VOP_UNLOCK(vp, 0, td);
871 * Rename system call.
872 * See comments in sys/ufs/ufs/ufs_vnops.c
876 struct vop_rename_args /* {
877 struct vnode *a_fdvp;
879 struct componentname *a_fcnp;
880 struct vnode *a_tdvp;
882 struct componentname *a_tcnp;
885 struct vnode *tvp = ap->a_tvp;
886 struct vnode *tdvp = ap->a_tdvp;
887 struct vnode *fvp = ap->a_fvp;
888 struct vnode *fdvp = ap->a_fdvp;
889 struct componentname *tcnp = ap->a_tcnp;
890 struct componentname *fcnp = ap->a_fcnp;
891 struct thread *td = fcnp->cn_thread;
892 struct inode *ip, *xp, *dp;
893 struct dirtemplate dirbuf;
894 int doingdirectory = 0, oldparent = 0, newparent = 0;
899 if ((tcnp->cn_flags & HASBUF) == 0 ||
900 (fcnp->cn_flags & HASBUF) == 0)
901 panic("ext2_rename: no name");
904 * Check for cross-device rename.
906 if ((fvp->v_mount != tdvp->v_mount) ||
907 (tvp && (fvp->v_mount != tvp->v_mount))) {
921 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
922 (VTOI(tdvp)->i_flags & APPEND))) {
928 * Renaming a file to itself has no effect. The upper layers should
929 * not call us in that case. Temporarily just warn if they do.
932 printf("ext2_rename: fvp == tvp (can't happen)\n");
937 if ((error = vn_lock(fvp, LK_EXCLUSIVE, td)) != 0)
941 if (ip->i_nlink >= LINK_MAX) {
942 VOP_UNLOCK(fvp, 0, td);
946 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
947 || (dp->i_flags & APPEND)) {
948 VOP_UNLOCK(fvp, 0, td);
952 if ((ip->i_mode & IFMT) == IFDIR) {
954 * Avoid ".", "..", and aliases of "." for obvious reasons.
956 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
957 dp == ip || (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT ||
958 (ip->i_flag & IN_RENAME)) {
959 VOP_UNLOCK(fvp, 0, td);
963 ip->i_flag |= IN_RENAME;
964 oldparent = dp->i_number;
970 * When the target exists, both the directory
971 * and target vnodes are returned locked.
979 * 1) Bump link count while we're moving stuff
980 * around. If we crash somewhere before
981 * completing our work, the link count
982 * may be wrong, but correctable.
985 ip->i_flag |= IN_CHANGE;
986 if ((error = ext2_update(fvp, 1)) != 0) {
987 VOP_UNLOCK(fvp, 0, td);
992 * If ".." must be changed (ie the directory gets a new
993 * parent) then the source directory must not be in the
994 * directory heirarchy above the target, as this would
995 * orphan everything below the source directory. Also
996 * the user must have write permission in the source so
997 * as to be able to change "..". We must repeat the call
998 * to namei, as the parent directory is unlocked by the
999 * call to checkpath().
1001 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1002 VOP_UNLOCK(fvp, 0, td);
1003 if (oldparent != dp->i_number)
1004 newparent = dp->i_number;
1005 if (doingdirectory && newparent) {
1006 if (error) /* write access check above */
1010 error = ext2_checkpath(ip, dp, tcnp->cn_cred);
1014 error = relookup(tdvp, &tvp, tcnp);
1024 * 2) If target doesn't exist, link the target
1025 * to the source and unlink the source.
1026 * Otherwise, rewrite the target directory
1027 * entry to reference the source inode and
1028 * expunge the original entry's existence.
1031 if (dp->i_dev != ip->i_dev)
1032 panic("ext2_rename: EXDEV");
1034 * Account for ".." in new directory.
1035 * When source and destination have the same
1036 * parent we don't fool with the link count.
1038 if (doingdirectory && newparent) {
1039 if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1044 dp->i_flag |= IN_CHANGE;
1045 error = ext2_update(tdvp, 1);
1049 error = ext2_direnter(ip, tdvp, tcnp);
1051 if (doingdirectory && newparent) {
1053 dp->i_flag |= IN_CHANGE;
1054 (void)ext2_update(tdvp, 1);
1060 if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev)
1061 panic("ext2_rename: EXDEV");
1063 * Short circuit rename(foo, foo).
1065 if (xp->i_number == ip->i_number)
1066 panic("ext2_rename: same file");
1068 * If the parent directory is "sticky", then the user must
1069 * own the parent directory, or the destination of the rename,
1070 * otherwise the destination may not be changed (except by
1071 * root). This implements append-only directories.
1073 if ((dp->i_mode & S_ISTXT) && tcnp->cn_cred->cr_uid != 0 &&
1074 tcnp->cn_cred->cr_uid != dp->i_uid &&
1075 xp->i_uid != tcnp->cn_cred->cr_uid) {
1080 * Target must be empty if a directory and have no links
1081 * to it. Also, ensure source and target are compatible
1082 * (both directories, or both not directories).
1084 if ((xp->i_mode&IFMT) == IFDIR) {
1085 if (! ext2_dirempty(xp, dp->i_number, tcnp->cn_cred) ||
1090 if (!doingdirectory) {
1095 } else if (doingdirectory) {
1099 error = ext2_dirrewrite(dp, ip, tcnp);
1103 * If the target directory is in the same
1104 * directory as the source directory,
1105 * decrement the link count on the parent
1106 * of the target directory.
1108 if (doingdirectory && !newparent) {
1110 dp->i_flag |= IN_CHANGE;
1114 * Adjust the link count of the target to
1115 * reflect the dirrewrite above. If this is
1116 * a directory it is empty and there are
1117 * no links to it, so we can squash the inode and
1118 * any space associated with it. We disallowed
1119 * renaming over top of a directory with links to
1120 * it above, as the remaining link would point to
1121 * a directory without "." or ".." entries.
1124 if (doingdirectory) {
1125 if (--xp->i_nlink != 0)
1126 panic("ext2_rename: linked directory");
1127 error = ext2_truncate(tvp, (off_t)0, IO_SYNC,
1128 tcnp->cn_cred, tcnp->cn_thread);
1130 xp->i_flag |= IN_CHANGE;
1136 * 3) Unlink the source.
1138 fcnp->cn_flags &= ~MODMASK;
1139 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1141 error = relookup(fdvp, &fvp, fcnp);
1149 * From name has disappeared.
1152 panic("ext2_rename: lost dir entry");
1157 * Ensure that the directory entry still exists and has not
1158 * changed while the new name has been entered. If the source is
1159 * a file then the entry may have been unlinked or renamed. In
1160 * either case there is no further work to be done. If the source
1161 * is a directory then it cannot have been rmdir'ed; its link
1162 * count of three would cause a rmdir to fail with ENOTEMPTY.
1163 * The IN_RENAME flag ensures that it cannot be moved by another
1168 panic("ext2_rename: lost dir entry");
1171 * If the source is a directory with a
1172 * new parent, the link count of the old
1173 * parent directory must be decremented
1174 * and ".." set to point to the new parent.
1176 if (doingdirectory && newparent) {
1178 dp->i_flag |= IN_CHANGE;
1179 error = vn_rdwr(UIO_READ, fvp, (caddr_t)&dirbuf,
1180 sizeof (struct dirtemplate), (off_t)0,
1181 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
1182 tcnp->cn_cred, NOCRED, (int *)0,
1183 (struct thread *)0);
1185 /* Like ufs little-endian: */
1186 namlen = dirbuf.dotdot_type;
1188 dirbuf.dotdot_name[0] != '.' ||
1189 dirbuf.dotdot_name[1] != '.') {
1190 ext2_dirbad(xp, (doff_t)12,
1191 "rename: mangled dir");
1193 dirbuf.dotdot_ino = newparent;
1194 (void) vn_rdwr(UIO_WRITE, fvp,
1196 sizeof (struct dirtemplate),
1197 (off_t)0, UIO_SYSSPACE,
1198 IO_NODELOCKED | IO_SYNC |
1199 IO_NOMACCHECK, tcnp->cn_cred,
1201 (struct thread *)0);
1206 error = ext2_dirremove(fdvp, fcnp);
1209 xp->i_flag |= IN_CHANGE;
1211 xp->i_flag &= ~IN_RENAME;
1226 ip->i_flag &= ~IN_RENAME;
1227 if (vn_lock(fvp, LK_EXCLUSIVE, td) == 0) {
1229 ip->i_flag |= IN_CHANGE;
1230 ip->i_flag &= ~IN_RENAME;
1242 struct vop_mkdir_args /* {
1243 struct vnode *a_dvp;
1244 struct vnode **a_vpp;
1245 struct componentname *a_cnp;
1246 struct vattr *a_vap;
1249 struct vnode *dvp = ap->a_dvp;
1250 struct vattr *vap = ap->a_vap;
1251 struct componentname *cnp = ap->a_cnp;
1252 struct inode *ip, *dp;
1254 struct dirtemplate dirtemplate, *dtp;
1258 if ((cnp->cn_flags & HASBUF) == 0)
1259 panic("ext2_mkdir: no name");
1262 if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1266 dmode = vap->va_mode & 0777;
1269 * Must simulate part of ext2_makeinode here to acquire the inode,
1270 * but not have it entered in the parent directory. The entry is
1271 * made later after writing "." and ".." entries.
1273 error = ext2_valloc(dvp, dmode, cnp->cn_cred, &tvp);
1277 ip->i_gid = dp->i_gid;
1281 * if we are hacking owners here, (only do this where told to)
1282 * and we are not giving it TOO root, (would subvert quotas)
1283 * then go ahead and give it to the other user.
1284 * The new directory also inherits the SUID bit.
1285 * If user's UID and dir UID are the same,
1286 * 'give it away' so that the SUID is still forced on.
1288 if ( (dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1289 (dp->i_mode & ISUID) && dp->i_uid) {
1291 ip->i_uid = dp->i_uid;
1293 ip->i_uid = cnp->cn_cred->cr_uid;
1297 ip->i_uid = cnp->cn_cred->cr_uid;
1299 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1301 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1303 if (cnp->cn_flags & ISWHITEOUT)
1304 ip->i_flags |= UF_OPAQUE;
1305 error = ext2_update(tvp, 1);
1308 * Bump link count in parent directory
1309 * to reflect work done below. Should
1310 * be done before reference is created
1311 * so reparation is possible if we crash.
1314 dp->i_flag |= IN_CHANGE;
1315 error = ext2_update(dvp, 1);
1319 /* Initialize directory with "." and ".." from static template. */
1320 if (EXT2_HAS_INCOMPAT_FEATURE(ip->i_e2fs->s_es,
1321 EXT2_FEATURE_INCOMPAT_FILETYPE))
1322 dtp = &mastertemplate;
1324 dtp = &omastertemplate;
1326 dirtemplate.dot_ino = ip->i_number;
1327 dirtemplate.dotdot_ino = dp->i_number;
1328 /* note that in ext2 DIRBLKSIZ == blocksize, not DEV_BSIZE
1329 * so let's just redefine it - for this function only
1332 #define DIRBLKSIZ VTOI(dvp)->i_e2fs->s_blocksize
1333 dirtemplate.dotdot_reclen = DIRBLKSIZ - 12;
1334 error = vn_rdwr(UIO_WRITE, tvp, (caddr_t)&dirtemplate,
1335 sizeof (dirtemplate), (off_t)0, UIO_SYSSPACE,
1336 IO_NODELOCKED | IO_SYNC | IO_NOMACCHECK, cnp->cn_cred, NOCRED,
1337 (int *)0, (struct thread *)0);
1340 dp->i_flag |= IN_CHANGE;
1343 if (DIRBLKSIZ > VFSTOEXT2(dvp->v_mount)->um_mountp->mnt_stat.f_bsize)
1344 /* XXX should grow with balloc() */
1345 panic("ext2_mkdir: blksize");
1347 ip->i_size = DIRBLKSIZ;
1348 ip->i_flag |= IN_CHANGE;
1351 /* Directory set up, now install its entry in the parent directory. */
1352 error = ext2_direnter(ip, dvp, cnp);
1355 dp->i_flag |= IN_CHANGE;
1359 * No need to do an explicit VOP_TRUNCATE here, vrele will do this
1360 * for us because we set the link count to 0.
1364 ip->i_flag |= IN_CHANGE;
1371 #define DIRBLKSIZ DEV_BSIZE
1375 * Rmdir system call.
1379 struct vop_rmdir_args /* {
1380 struct vnode *a_dvp;
1382 struct componentname *a_cnp;
1385 struct vnode *vp = ap->a_vp;
1386 struct vnode *dvp = ap->a_dvp;
1387 struct componentname *cnp = ap->a_cnp;
1388 struct thread *td = cnp->cn_thread;
1389 struct inode *ip, *dp;
1396 * Verify the directory is empty (and valid).
1397 * (Rmdir ".." won't be valid since
1398 * ".." will contain a reference to
1399 * the current directory and thus be
1403 if (ip->i_nlink != 2 || !ext2_dirempty(ip, dp->i_number, cnp->cn_cred)) {
1407 if ((dp->i_flags & APPEND)
1408 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
1413 * Delete reference to directory before purging
1414 * inode. If we crash in between, the directory
1415 * will be reattached to lost+found,
1417 error = ext2_dirremove(dvp, cnp);
1421 dp->i_flag |= IN_CHANGE;
1423 VOP_UNLOCK(dvp, 0, td);
1425 * Truncate inode. The only stuff left
1426 * in the directory is "." and "..". The
1427 * "." reference is inconsequential since
1428 * we're quashing it. The ".." reference
1429 * has already been adjusted above. We've
1430 * removed the "." reference and the reference
1431 * in the parent directory, but there may be
1432 * other hard links so decrement by 2 and
1433 * worry about them later.
1436 error = ext2_truncate(vp, (off_t)0, IO_SYNC, cnp->cn_cred, td);
1437 cache_purge(ITOV(ip));
1438 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
1444 * symlink -- make a symbolic link
1448 struct vop_symlink_args /* {
1449 struct vnode *a_dvp;
1450 struct vnode **a_vpp;
1451 struct componentname *a_cnp;
1452 struct vattr *a_vap;
1456 struct vnode *vp, **vpp = ap->a_vpp;
1460 error = ext2_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
1465 len = strlen(ap->a_target);
1466 if (len < vp->v_mount->mnt_maxsymlinklen) {
1468 bcopy(ap->a_target, (char *)ip->i_shortlink, len);
1470 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1472 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
1473 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
1474 ap->a_cnp->cn_cred, NOCRED, (int *)0, (struct thread *)0);
1481 * Return target name of a symbolic link
1485 struct vop_readlink_args /* {
1488 struct ucred *a_cred;
1491 struct vnode *vp = ap->a_vp;
1492 struct inode *ip = VTOI(vp);
1496 if (isize < vp->v_mount->mnt_maxsymlinklen) {
1497 uiomove((char *)ip->i_shortlink, isize, ap->a_uio);
1500 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
1504 * Calculate the logical to physical mapping if not done already,
1505 * then call the device strategy routine.
1507 * In order to be able to swap to a file, the ext2_bmaparray() operation may not
1508 * deadlock on memory. See ext2_bmap() for details.
1512 struct vop_strategy_args /* {
1517 struct buf *bp = ap->a_bp;
1518 struct vnode *vp = ap->a_vp;
1524 if (vp->v_type == VBLK || vp->v_type == VCHR)
1525 panic("ext2_strategy: spec");
1526 if (bp->b_blkno == bp->b_lblkno) {
1527 error = ext2_bmaparray(vp, bp->b_lblkno, &blkno, NULL, NULL);
1528 bp->b_blkno = blkno;
1530 bp->b_error = error;
1531 bp->b_ioflags |= BIO_ERROR;
1535 if ((long)bp->b_blkno == -1)
1538 if ((long)bp->b_blkno == -1) {
1543 bp->b_dev = vp->v_rdev;
1544 VOP_STRATEGY(vp, bp);
1549 * Print out the contents of an inode.
1553 struct vop_print_args /* {
1557 struct vnode *vp = ap->a_vp;
1558 struct inode *ip = VTOI(vp);
1560 printf("tag VT_UFS, ino %lu, on dev %s (%d, %d)",
1561 (u_long)ip->i_number, devtoname(ip->i_dev), major(ip->i_dev),
1563 if (vp->v_type == VFIFO)
1565 lockmgr_printinfo(&vp->v_lock);
1571 * Read wrapper for special devices.
1575 struct vop_read_args /* {
1579 struct ucred *a_cred;
1587 resid = uio->uio_resid;
1588 error = VOCALL(spec_vnodeop_p, VOFFSET(vop_read), ap);
1590 * The inode may have been revoked during the call, so it must not
1591 * be accessed blindly here or in the other wrapper functions.
1593 ip = VTOI(ap->a_vp);
1594 if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
1595 ip->i_flag |= IN_ACCESS;
1600 * Write wrapper for special devices.
1604 struct vop_write_args /* {
1608 struct ucred *a_cred;
1616 resid = uio->uio_resid;
1617 error = VOCALL(spec_vnodeop_p, VOFFSET(vop_write), ap);
1618 ip = VTOI(ap->a_vp);
1619 if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
1620 VTOI(ap->a_vp)->i_flag |= IN_CHANGE | IN_UPDATE;
1625 * Close wrapper for special devices.
1627 * Update the times on the inode then do device close.
1631 struct vop_close_args /* {
1634 struct ucred *a_cred;
1635 struct thread *a_td;
1638 struct vnode *vp = ap->a_vp;
1640 mtx_lock(&vp->v_interlock);
1641 if (vp->v_usecount > 1)
1643 mtx_unlock(&vp->v_interlock);
1644 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_close), ap));
1648 * Read wrapper for fifos.
1652 struct vop_read_args /* {
1656 struct ucred *a_cred;
1664 resid = uio->uio_resid;
1665 error = VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), ap);
1666 ip = VTOI(ap->a_vp);
1667 if ((ap->a_vp->v_mount->mnt_flag & MNT_NOATIME) == 0 && ip != NULL &&
1668 (uio->uio_resid != resid || (error == 0 && resid != 0)))
1669 VTOI(ap->a_vp)->i_flag |= IN_ACCESS;
1674 * Write wrapper for fifos.
1678 struct vop_write_args /* {
1682 struct ucred *a_cred;
1690 resid = uio->uio_resid;
1691 error = VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), ap);
1692 ip = VTOI(ap->a_vp);
1693 if (ip != NULL && (uio->uio_resid != resid || (error == 0 && resid != 0)))
1694 VTOI(ap->a_vp)->i_flag |= IN_CHANGE | IN_UPDATE;
1699 * Close wrapper for fifos.
1701 * Update the times on the inode then do device close.
1705 struct vop_close_args /* {
1708 struct ucred *a_cred;
1709 struct thread *a_td;
1712 struct vnode *vp = ap->a_vp;
1714 mtx_lock(&vp->v_interlock);
1715 if (vp->v_usecount > 1)
1717 mtx_unlock(&vp->v_interlock);
1718 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), ap));
1722 * Kqfilter wrapper for fifos.
1724 * Fall through to ext2 kqfilter routines if needed
1727 ext2fifo_kqfilter(ap)
1728 struct vop_kqfilter_args *ap;
1732 error = VOCALL(fifo_vnodeop_p, VOFFSET(vop_kqfilter), ap);
1734 error = ext2_kqfilter(ap);
1739 * Return POSIX pathconf information applicable to ext2 filesystems.
1743 struct vop_pathconf_args /* {
1750 switch (ap->a_name) {
1752 *ap->a_retval = LINK_MAX;
1755 *ap->a_retval = NAME_MAX;
1758 *ap->a_retval = PATH_MAX;
1761 *ap->a_retval = PIPE_BUF;
1763 case _PC_CHOWN_RESTRICTED:
1776 * Advisory record locking support
1780 struct vop_advlock_args /* {
1788 struct inode *ip = VTOI(ap->a_vp);
1790 return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
1794 * Initialize the vnode associated with a new inode, handle aliased
1798 ext2_vinit(mntp, specops, fifoops, vpp)
1810 switch(vp->v_type = IFTOVT(ip->i_mode)) {
1814 vp = addaliasu(vp, ip->i_rdev);
1824 if (ip->i_number == ROOTINO)
1825 vp->v_vflag |= VV_ROOT;
1827 * Initialize modrev times
1829 getmicrouptime(&tv);
1830 SETHIGH(ip->i_modrev, tv.tv_sec);
1831 SETLOW(ip->i_modrev, tv.tv_usec * 4294);
1837 * Allocate a new inode.
1840 ext2_makeinode(mode, dvp, vpp, cnp)
1844 struct componentname *cnp;
1846 struct inode *ip, *pdir;
1852 if ((cnp->cn_flags & HASBUF) == 0)
1853 panic("ext2_makeinode: no name");
1856 if ((mode & IFMT) == 0)
1859 error = ext2_valloc(dvp, mode, cnp->cn_cred, &tvp);
1864 ip->i_gid = pdir->i_gid;
1869 * not the owner of the directory,
1870 * and we are hacking owners here, (only do this where told to)
1871 * and we are not giving it TOO root, (would subvert quotas)
1872 * then go ahead and give it to the other user.
1873 * Note that this drops off the execute bits for security.
1875 if ( (dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1876 (pdir->i_mode & ISUID) &&
1877 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
1878 ip->i_uid = pdir->i_uid;
1881 ip->i_uid = cnp->cn_cred->cr_uid;
1885 ip->i_uid = cnp->cn_cred->cr_uid;
1887 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1889 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
1891 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
1892 suser_cred(cnp->cn_cred, PRISON_ROOT))
1893 ip->i_mode &= ~ISGID;
1895 if (cnp->cn_flags & ISWHITEOUT)
1896 ip->i_flags |= UF_OPAQUE;
1899 * Make sure inode goes to disk before directory entry.
1901 error = ext2_update(tvp, 1);
1904 error = ext2_direnter(ip, dvp, cnp);
1913 * Write error occurred trying to update the inode
1914 * or the directory so must deallocate the inode.
1917 ip->i_flag |= IN_CHANGE;
1922 static struct filterops ext2read_filtops =
1923 { 1, NULL, filt_ext2detach, filt_ext2read };
1924 static struct filterops ext2write_filtops =
1925 { 1, NULL, filt_ext2detach, filt_ext2write };
1926 static struct filterops ext2vnode_filtops =
1927 { 1, NULL, filt_ext2detach, filt_ext2vnode };
1931 struct vop_kqfilter_args /* {
1936 struct vnode *vp = ap->a_vp;
1937 struct knote *kn = ap->a_kn;
1939 switch (kn->kn_filter) {
1941 kn->kn_fop = &ext2read_filtops;
1944 kn->kn_fop = &ext2write_filtops;
1947 kn->kn_fop = &ext2vnode_filtops;
1953 kn->kn_hook = (caddr_t)vp;
1955 if (vp->v_pollinfo == NULL)
1957 mtx_lock(&vp->v_pollinfo->vpi_lock);
1958 SLIST_INSERT_HEAD(&vp->v_pollinfo->vpi_selinfo.si_note, kn, kn_selnext);
1959 mtx_unlock(&vp->v_pollinfo->vpi_lock);
1965 filt_ext2detach(struct knote *kn)
1967 struct vnode *vp = (struct vnode *)kn->kn_hook;
1969 KASSERT(vp->v_pollinfo != NULL, ("Mising v_pollinfo"));
1970 mtx_lock(&vp->v_pollinfo->vpi_lock);
1971 SLIST_REMOVE(&vp->v_pollinfo->vpi_selinfo.si_note,
1972 kn, knote, kn_selnext);
1973 mtx_unlock(&vp->v_pollinfo->vpi_lock);
1978 filt_ext2read(struct knote *kn, long hint)
1980 struct vnode *vp = (struct vnode *)kn->kn_hook;
1981 struct inode *ip = VTOI(vp);
1984 * filesystem is gone, so set the EOF flag and schedule
1985 * the knote for deletion.
1987 if (hint == NOTE_REVOKE) {
1988 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
1992 kn->kn_data = ip->i_size - kn->kn_fp->f_offset;
1993 return (kn->kn_data != 0);
1998 filt_ext2write(struct knote *kn, long hint)
2002 * filesystem is gone, so set the EOF flag and schedule
2003 * the knote for deletion.
2005 if (hint == NOTE_REVOKE)
2006 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
2013 filt_ext2vnode(struct knote *kn, long hint)
2016 if (kn->kn_sfflags & hint)
2017 kn->kn_fflags |= hint;
2018 if (hint == NOTE_REVOKE) {
2019 kn->kn_flags |= EV_EOF;
2022 return (kn->kn_fflags != 0);