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