xref: /csrg-svn/sys/ufs/lfs/lfs_vnops.c (revision 57067)
123405Smckusick /*
251502Sbostic  * Copyright (c) 1986, 1989, 1991 Regents of the University of California.
337737Smckusick  * All rights reserved.
423405Smckusick  *
544539Sbostic  * %sccs.include.redist.c%
637737Smckusick  *
7*57067Smargo  *	@(#)lfs_vnops.c	7.97 (Berkeley) 12/10/92
823405Smckusick  */
937Sbill 
1051482Sbostic #include <sys/param.h>
1151482Sbostic #include <sys/systm.h>
1251482Sbostic #include <sys/namei.h>
1351482Sbostic #include <sys/resourcevar.h>
1451482Sbostic #include <sys/kernel.h>
1551482Sbostic #include <sys/file.h>
1651482Sbostic #include <sys/stat.h>
1751482Sbostic #include <sys/buf.h>
1851482Sbostic #include <sys/proc.h>
1951482Sbostic #include <sys/conf.h>
2051482Sbostic #include <sys/mount.h>
2151482Sbostic #include <sys/vnode.h>
2251482Sbostic #include <sys/malloc.h>
2337Sbill 
2453321Smckusick #include <vm/vm.h>
2553321Smckusick 
2655460Sbostic #include <miscfs/specfs/specdev.h>
2755460Sbostic #include <miscfs/fifofs/fifo.h>
2855460Sbostic 
2951502Sbostic #include <ufs/ufs/quota.h>
3051502Sbostic #include <ufs/ufs/inode.h>
3151502Sbostic #include <ufs/ufs/dir.h>
3255936Sbostic #include <ufs/ufs/ufsmount.h>
3351502Sbostic #include <ufs/ufs/ufs_extern.h>
3447571Skarels 
3551502Sbostic #include <ufs/lfs/lfs.h>
3651502Sbostic #include <ufs/lfs/lfs_extern.h>
3751134Sbostic 
3851482Sbostic /* Global vfs data structures for lfs. */
3953533Sheideman int (**lfs_vnodeop_p)();
4053533Sheideman struct vnodeopv_entry_desc lfs_vnodeop_entries[] = {
4153533Sheideman 	{ &vop_default_desc, vn_default_error },
4253533Sheideman 	{ &vop_lookup_desc, ufs_lookup },		/* lookup */
43*57067Smargo 	{ &vop_create_desc, ufs_create },		/* create */
44*57067Smargo 	{ &vop_mknod_desc, ufs_mknod },			/* mknod */
4554030Smckusick 	{ &vop_open_desc, ufs_open },			/* open */
4656053Sbostic 	{ &vop_close_desc, lfs_close },			/* close */
4753533Sheideman 	{ &vop_access_desc, ufs_access },		/* access */
4855936Sbostic 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
4953533Sheideman 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
5054030Smckusick 	{ &vop_read_desc, lfs_read },			/* read */
5154030Smckusick 	{ &vop_write_desc, lfs_write },			/* write */
5254030Smckusick 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
5353533Sheideman 	{ &vop_select_desc, ufs_select },		/* select */
5454030Smckusick 	{ &vop_mmap_desc, ufs_mmap },			/* mmap */
5554030Smckusick 	{ &vop_fsync_desc, lfs_fsync },			/* fsync */
5654030Smckusick 	{ &vop_seek_desc, ufs_seek },			/* seek */
57*57067Smargo 	{ &vop_remove_desc, ufs_remove },		/* remove */
58*57067Smargo 	{ &vop_link_desc, ufs_link },			/* link */
59*57067Smargo 	{ &vop_rename_desc, ufs_rename },		/* rename */
60*57067Smargo 	{ &vop_mkdir_desc, ufs_mkdir },			/* mkdir */
61*57067Smargo 	{ &vop_rmdir_desc, ufs_rmdir },			/* rmdir */
62*57067Smargo 	{ &vop_symlink_desc, ufs_symlink },		/* symlink */
6353533Sheideman 	{ &vop_readdir_desc, ufs_readdir },		/* readdir */
6453533Sheideman 	{ &vop_readlink_desc, ufs_readlink },		/* readlink */
6553533Sheideman 	{ &vop_abortop_desc, ufs_abortop },		/* abortop */
66*57067Smargo 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
6753533Sheideman 	{ &vop_reclaim_desc, ufs_reclaim },		/* reclaim */
6854030Smckusick 	{ &vop_lock_desc, ufs_lock },			/* lock */
6953533Sheideman 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
7056474Smargo 	{ &vop_bmap_desc, ufs_bmap },			/* bmap */
7153533Sheideman 	{ &vop_strategy_desc, ufs_strategy },		/* strategy */
7254030Smckusick 	{ &vop_print_desc, ufs_print },			/* print */
7353533Sheideman 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
7453533Sheideman 	{ &vop_advlock_desc, ufs_advlock },		/* advlock */
7553533Sheideman 	{ &vop_blkatoff_desc, lfs_blkatoff },		/* blkatoff */
7653533Sheideman 	{ &vop_valloc_desc, lfs_valloc },		/* valloc */
7754030Smckusick 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
7853533Sheideman 	{ &vop_truncate_desc, lfs_truncate },		/* truncate */
7953533Sheideman 	{ &vop_update_desc, lfs_update },		/* update */
8053533Sheideman 	{ &vop_bwrite_desc, lfs_bwrite },		/* bwrite */
8153533Sheideman 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
8251482Sbostic };
8353533Sheideman struct vnodeopv_desc lfs_vnodeop_opv_desc =
8453533Sheideman 	{ &lfs_vnodeop_p, lfs_vnodeop_entries };
856254Sroot 
8653533Sheideman int (**lfs_specop_p)();
8753533Sheideman struct vnodeopv_entry_desc lfs_specop_entries[] = {
8853533Sheideman 	{ &vop_default_desc, vn_default_error },
8953533Sheideman 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
9053533Sheideman 	{ &vop_create_desc, spec_create },		/* create */
9153533Sheideman 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
9254030Smckusick 	{ &vop_open_desc, spec_open },			/* open */
9353533Sheideman 	{ &vop_close_desc, ufsspec_close },		/* close */
9453533Sheideman 	{ &vop_access_desc, ufs_access },		/* access */
9555936Sbostic 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
9653533Sheideman 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
9753533Sheideman 	{ &vop_read_desc, ufsspec_read },		/* read */
9853533Sheideman 	{ &vop_write_desc, ufsspec_write },		/* write */
9953533Sheideman 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
10053533Sheideman 	{ &vop_select_desc, spec_select },		/* select */
10154030Smckusick 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
10253533Sheideman 	{ &vop_fsync_desc, spec_fsync },		/* fsync */
10354030Smckusick 	{ &vop_seek_desc, spec_seek },			/* seek */
10453533Sheideman 	{ &vop_remove_desc, spec_remove },		/* remove */
10554030Smckusick 	{ &vop_link_desc, spec_link },			/* link */
10653533Sheideman 	{ &vop_rename_desc, spec_rename },		/* rename */
10753533Sheideman 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
10853533Sheideman 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
10953533Sheideman 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
11053533Sheideman 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
11153533Sheideman 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
11253533Sheideman 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
113*57067Smargo 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
11453533Sheideman 	{ &vop_reclaim_desc, ufs_reclaim },		/* reclaim */
11554030Smckusick 	{ &vop_lock_desc, ufs_lock },			/* lock */
11653533Sheideman 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
11754030Smckusick 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
11853533Sheideman 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
11954030Smckusick 	{ &vop_print_desc, ufs_print },			/* print */
12053533Sheideman 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
12153533Sheideman 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
12253533Sheideman 	{ &vop_blkatoff_desc, spec_blkatoff },		/* blkatoff */
12353533Sheideman 	{ &vop_valloc_desc, spec_valloc },		/* valloc */
12454030Smckusick 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
12553533Sheideman 	{ &vop_truncate_desc, spec_truncate },		/* truncate */
12653533Sheideman 	{ &vop_update_desc, lfs_update },		/* update */
12753533Sheideman 	{ &vop_bwrite_desc, lfs_bwrite },		/* bwrite */
12853533Sheideman 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
12951558Smckusick };
13053533Sheideman struct vnodeopv_desc lfs_specop_opv_desc =
13153533Sheideman 	{ &lfs_specop_p, lfs_specop_entries };
13251558Smckusick 
13351558Smckusick #ifdef FIFO
13453533Sheideman int (**lfs_fifoop_p)();
13553533Sheideman struct vnodeopv_entry_desc lfs_fifoop_entries[] = {
13653533Sheideman 	{ &vop_default_desc, vn_default_error },
13753533Sheideman 	{ &vop_lookup_desc, fifo_lookup },		/* lookup */
13853533Sheideman 	{ &vop_create_desc, fifo_create },		/* create */
13953533Sheideman 	{ &vop_mknod_desc, fifo_mknod },		/* mknod */
14054030Smckusick 	{ &vop_open_desc, fifo_open },			/* open */
14153533Sheideman 	{ &vop_close_desc, ufsfifo_close },		/* close */
14253533Sheideman 	{ &vop_access_desc, ufs_access },		/* access */
14355936Sbostic 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
14453533Sheideman 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
14553533Sheideman 	{ &vop_read_desc, ufsfifo_read },		/* read */
14653533Sheideman 	{ &vop_write_desc, ufsfifo_write },		/* write */
14753533Sheideman 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
14853533Sheideman 	{ &vop_select_desc, fifo_select },		/* select */
14954030Smckusick 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
15053533Sheideman 	{ &vop_fsync_desc, fifo_fsync },		/* fsync */
15154030Smckusick 	{ &vop_seek_desc, fifo_seek },			/* seek */
15253533Sheideman 	{ &vop_remove_desc, fifo_remove },		/* remove */
15354030Smckusick 	{ &vop_link_desc, fifo_link },			/* link */
15453533Sheideman 	{ &vop_rename_desc, fifo_rename },		/* rename */
15553533Sheideman 	{ &vop_mkdir_desc, fifo_mkdir },		/* mkdir */
15653533Sheideman 	{ &vop_rmdir_desc, fifo_rmdir },		/* rmdir */
15753533Sheideman 	{ &vop_symlink_desc, fifo_symlink },		/* symlink */
15853533Sheideman 	{ &vop_readdir_desc, fifo_readdir },		/* readdir */
15953533Sheideman 	{ &vop_readlink_desc, fifo_readlink },		/* readlink */
16053533Sheideman 	{ &vop_abortop_desc, fifo_abortop },		/* abortop */
161*57067Smargo 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
16253533Sheideman 	{ &vop_reclaim_desc, ufs_reclaim },		/* reclaim */
16354030Smckusick 	{ &vop_lock_desc, ufs_lock },			/* lock */
16453533Sheideman 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
16554030Smckusick 	{ &vop_bmap_desc, fifo_bmap },			/* bmap */
16653533Sheideman 	{ &vop_strategy_desc, fifo_strategy },		/* strategy */
16754030Smckusick 	{ &vop_print_desc, ufs_print },			/* print */
16853533Sheideman 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
16953533Sheideman 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
17053533Sheideman 	{ &vop_blkatoff_desc, fifo_blkatoff },		/* blkatoff */
17153533Sheideman 	{ &vop_valloc_desc, fifo_valloc },		/* valloc */
17254030Smckusick 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
17353533Sheideman 	{ &vop_truncate_desc, fifo_truncate },		/* truncate */
17453533Sheideman 	{ &vop_update_desc, lfs_update },		/* update */
17553533Sheideman 	{ &vop_bwrite_desc, lfs_bwrite },		/* bwrite */
17653533Sheideman 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
17751558Smckusick };
17853533Sheideman struct vnodeopv_desc lfs_fifoop_opv_desc =
17953533Sheideman 	{ &lfs_fifoop_p, lfs_fifoop_entries };
18051558Smckusick #endif /* FIFO */
18151558Smckusick 
18237Sbill /*
18339608Smckusick  * Vnode op for reading.
18439608Smckusick  */
18537737Smckusick /* ARGSUSED */
18654030Smckusick lfs_read(ap)
18754692Sbostic 	struct vop_read_args /* {
18854692Sbostic 		struct vnode *a_vp;
18954692Sbostic 		struct uio *a_uio;
19054692Sbostic 		int a_ioflag;
19154692Sbostic 		struct ucred *a_cred;
19254692Sbostic 	} */ *ap;
19339608Smckusick {
19455460Sbostic 	register struct vnode *vp = ap->a_vp;
19555460Sbostic 	register struct inode *ip = VTOI(vp);
19653867Sheideman 	register struct uio *uio = ap->a_uio;
19755460Sbostic 	register struct lfs *fs;
198*57067Smargo 	struct buf *bp;
19939608Smckusick 	daddr_t lbn, bn, rablock;
20053233Smckusick 	off_t diff;
201*57067Smargo 	int type, error = 0, size;
20255460Sbostic 	long n, on;
20339608Smckusick 
20456677Sbostic 	type = ip->i_mode & IFMT;
20548039Smckusick #ifdef DIAGNOSTIC
20653867Sheideman 	if (uio->uio_rw != UIO_READ)
20755460Sbostic 		panic("lfs_read mode");
20839608Smckusick 	if (type != IFDIR && type != IFREG && type != IFLNK)
20955460Sbostic 		panic("lfs_read type");
21055460Sbostic 	if (type == IFLNK && (int)ip->i_size < vp->v_mount->mnt_maxsymlinklen)
21155460Sbostic 		panic("read short symlink");
21248039Smckusick #endif
21353867Sheideman 	if (uio->uio_resid == 0)
21439608Smckusick 		return (0);
21555460Sbostic 	fs = ip->i_lfs;
21655460Sbostic 	if (uio->uio_offset < 0 ||
21755460Sbostic 	    (u_quad_t)uio->uio_offset + uio->uio_resid > fs->lfs_maxfilesize)
21855460Sbostic 		return (EFBIG);
21939608Smckusick 	ip->i_flag |= IACC;
22039608Smckusick 	do {
22153867Sheideman 		lbn = lblkno(fs, uio->uio_offset);
22253867Sheideman 		on = blkoff(fs, uio->uio_offset);
22355460Sbostic 		n = min((unsigned)(fs->lfs_bsize - on), uio->uio_resid);
22453867Sheideman 		diff = ip->i_size - uio->uio_offset;
22539608Smckusick 		if (diff <= 0)
22656068Sbostic 			break;
22739608Smckusick 		if (diff < n)
22839608Smckusick 			n = diff;
22955460Sbostic 		size = blksize(fs);
23056474Smargo 		lfs_check(vp, lbn);
231*57067Smargo 		error = cluster_read(vp, ip->i_size, lbn, size, NOCRED, &bp);
23255460Sbostic 		vp->v_lastr = lbn;
233*57067Smargo 		n = min(n, size - bp->b_resid);
23456068Sbostic 		if (error)
23556068Sbostic 			break;
236*57067Smargo 		error = uiomove(bp->b_un.b_addr + on, (int)n, uio);
23756677Sbostic 		if (type == IFREG &&
23856677Sbostic 		    n + on == fs->lfs_bsize || uio->uio_offset == ip->i_size)
239*57067Smargo 			bp->b_flags |= B_AGE;
240*57067Smargo 		brelse(bp);
24153867Sheideman 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
24239608Smckusick 	return (error);
24339608Smckusick }
24439608Smckusick 
24539608Smckusick /*
24639608Smckusick  * Vnode op for writing.
24739608Smckusick  */
24854030Smckusick lfs_write(ap)
24954692Sbostic 	struct vop_write_args /* {
25054692Sbostic 		struct vnode *a_vp;
25154692Sbostic 		struct uio *a_uio;
25254692Sbostic 		int a_ioflag;
25354692Sbostic 		struct ucred *a_cred;
25454692Sbostic 	} */ *ap;
25539608Smckusick {
25653867Sheideman 	register struct vnode *vp = ap->a_vp;
25754030Smckusick 	register struct uio *uio = ap->a_uio;
25854030Smckusick 	struct proc *p = uio->uio_procp;
25953867Sheideman 	register struct inode *ip = VTOI(vp);
26052091Sbostic 	register struct lfs *fs;
26154030Smckusick 	register ioflag = ap->a_ioflag;
26254765Smckusick 	struct timeval tv;
263*57067Smargo 	struct buf *bp;
26452091Sbostic 	daddr_t lbn;
26553233Smckusick 	off_t osize;
26652091Sbostic 	int n, on, flags, newblock;
26745722Smckusick 	int size, resid, error = 0;
26839608Smckusick 
26948039Smckusick #ifdef DIAGNOSTIC
27054030Smckusick 	if (uio->uio_rw != UIO_WRITE)
27152091Sbostic 		panic("lfs_write mode");
27248039Smckusick #endif
27353867Sheideman 	switch (vp->v_type) {
27439608Smckusick 	case VREG:
27554030Smckusick 		if (ioflag & IO_APPEND)
27654030Smckusick 			uio->uio_offset = ip->i_size;
27739608Smckusick 		/* fall through */
27839608Smckusick 	case VLNK:
27939608Smckusick 		break;
28039608Smckusick 
28139608Smckusick 	case VDIR:
28252091Sbostic 		/* XXX This may not be correct for LFS. */
28354030Smckusick 		if ((ioflag & IO_SYNC) == 0)
28452091Sbostic 			panic("lfs_write nonsync dir write");
28539608Smckusick 		break;
28639608Smckusick 
28739608Smckusick 	default:
28852091Sbostic 		panic("lfs_write type");
28939608Smckusick 	}
29054030Smckusick 	if (uio->uio_offset < 0)
29139608Smckusick 		return (EINVAL);
29254030Smckusick 	if (uio->uio_resid == 0)
29339608Smckusick 		return (0);
29439608Smckusick 	/*
29539608Smckusick 	 * Maybe this should be above the vnode op call, but so long as
29639608Smckusick 	 * file servers have no limits, i don't think it matters
29739608Smckusick 	 */
29853867Sheideman 	if (vp->v_type == VREG && p &&
29954030Smckusick 	    uio->uio_offset + uio->uio_resid >
30047571Skarels 	      p->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
30147571Skarels 		psignal(p, SIGXFSZ);
30239608Smckusick 		return (EFBIG);
30339608Smckusick 	}
30454030Smckusick 	resid = uio->uio_resid;
30539608Smckusick 	osize = ip->i_size;
30651183Sbostic 	fs = ip->i_lfs;						/* LFS */
30755460Sbostic 	if (uio->uio_offset < 0 ||
30855460Sbostic 	    (u_quad_t)uio->uio_offset + uio->uio_resid > fs->lfs_maxfilesize)
30955460Sbostic 		return (EFBIG);
31056068Sbostic 
31139608Smckusick 	do {
31254030Smckusick 		lbn = lblkno(fs, uio->uio_offset);
31354030Smckusick 		on = blkoff(fs, uio->uio_offset);
31455460Sbostic 		n = min((unsigned)(fs->lfs_bsize - on), uio->uio_resid);
31555936Sbostic 		lfs_check(vp, lbn);
316*57067Smargo 		if (error = lfs_balloc(vp, n, lbn, &bp))
31739608Smckusick 			break;
31854030Smckusick 		if (uio->uio_offset + n > ip->i_size) {
31954030Smckusick 			ip->i_size = uio->uio_offset + n;
32053867Sheideman 			vnode_pager_setsize(vp, (u_long)ip->i_size);
32145722Smckusick 		}
32251183Sbostic 		size = blksize(fs);
32353867Sheideman 		(void) vnode_pager_uncache(vp);
324*57067Smargo 		n = min(n, size - bp->b_resid);
325*57067Smargo 		error = uiomove(bp->b_un.b_addr + on, n, uio);
326*57067Smargo 		error = VOP_BWRITE(bp);
32756068Sbostic 		/* XXX Why is this in the loop? */
328*57067Smargo 		if (ap->a_cred && ap->a_cred->cr_uid != 0)
32939608Smckusick 			ip->i_mode &= ~(ISUID|ISGID);
33054030Smckusick 	} while (error == 0 && uio->uio_resid > 0 && n != 0);
33156068Sbostic 
33255936Sbostic 	if (error) {
33355936Sbostic 		if (ioflag & IO_UNIT) {
33455936Sbostic 			(void)VOP_TRUNCATE(vp, osize, ioflag & IO_SYNC,
33555936Sbostic 			    ap->a_cred, uio->uio_procp);
33655936Sbostic 			uio->uio_offset -= resid - uio->uio_resid;
33755936Sbostic 			uio->uio_resid = resid;
33855936Sbostic 		}
33956068Sbostic 	}
34056068Sbostic 
341*57067Smargo 	/* TURN OFF SYNC FOR NOW
34254765Smckusick 	if (!error && (ioflag & IO_SYNC)) {
34354765Smckusick 		tv = time;
34455936Sbostic 		if (!(error = VOP_UPDATE(vp, &tv, &tv, 1)))
34555936Sbostic 			error = VOP_FSYNC(vp, ap->a_cred, MNT_WAIT,
34655936Sbostic 			    uio->uio_procp);
34754765Smckusick 	}
348*57067Smargo 	*/
34939608Smckusick 	return (error);
35039608Smckusick }
35139608Smckusick 
3529167Ssam /*
35337737Smckusick  * Synch an open file.
3549167Ssam  */
35537737Smckusick /* ARGSUSED */
35654030Smckusick lfs_fsync(ap)
35754692Sbostic 	struct vop_fsync_args /* {
35854692Sbostic 		struct vnode *a_vp;
35954692Sbostic 		struct ucred *a_cred;
36054692Sbostic 		int a_waitfor;
36154692Sbostic 		struct proc *a_p;
36254692Sbostic 	} */ *ap;
3637701Ssam {
36454765Smckusick 	struct timeval tv;
3657701Ssam 
36654765Smckusick 	tv = time;
36755547Sbostic 	return (VOP_UPDATE(ap->a_vp, &tv, &tv,
36855547Sbostic 	    ap->a_waitfor == MNT_WAIT ? LFS_SYNC : 0));
36937737Smckusick }
37051558Smckusick 
37151558Smckusick /*
37254264Sbostic  * These macros are used to bracket UFS directory ops, so that we can
37354264Sbostic  * identify all the pages touched during directory ops which need to
37454264Sbostic  * be ordered and flushed atomically, so that they may be recovered.
37554264Sbostic  */
37654264Sbostic #define	SET_DIROP(fs) {							\
37754264Sbostic 	if ((fs)->lfs_writer)						\
37855547Sbostic 		tsleep(&(fs)->lfs_dirops, PRIBIO + 1, "lfs_dirop", 0);	\
37954264Sbostic 	++(fs)->lfs_dirops;						\
38054264Sbostic 	(fs)->lfs_doifile = 1;						\
38154264Sbostic }
38254264Sbostic 
38354264Sbostic #define	SET_ENDOP(fs) {							\
38454264Sbostic 	--(fs)->lfs_dirops;						\
38554264Sbostic 	if (!(fs)->lfs_dirops)						\
38654264Sbostic 		wakeup(&(fs)->lfs_writer);				\
38754264Sbostic }
38854264Sbostic 
38954264Sbostic #define	MARK_VNODE(dvp)	(dvp)->v_flag |= VDIROP
39054264Sbostic 
39154264Sbostic int
39254264Sbostic lfs_symlink(ap)
39354692Sbostic 	struct vop_symlink_args /* {
39454692Sbostic 		struct vnode *a_dvp;
39554692Sbostic 		struct vnode **a_vpp;
39654692Sbostic 		struct componentname *a_cnp;
39754692Sbostic 		struct vattr *a_vap;
39854692Sbostic 		char *a_target;
39954692Sbostic 	} */ *ap;
40054264Sbostic {
40154264Sbostic 	int ret;
40254264Sbostic 
40354264Sbostic 	SET_DIROP(VTOI(ap->a_dvp)->i_lfs);
40454264Sbostic 	MARK_VNODE(ap->a_dvp);
40554264Sbostic 	ret = ufs_symlink(ap);
40654264Sbostic 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs);
40754264Sbostic 	return (ret);
40854264Sbostic }
40954264Sbostic 
41054264Sbostic int
41154264Sbostic lfs_mknod(ap)
41254692Sbostic 	struct vop_mknod_args /* {
41354692Sbostic 		struct vnode *a_dvp;
41454692Sbostic 		struct vnode **a_vpp;
41554692Sbostic 		struct componentname *a_cnp;
41654692Sbostic 		struct vattr *a_vap;
41754692Sbostic 	} */ *ap;
41854264Sbostic {
41954264Sbostic 	int ret;
42054264Sbostic 
42154264Sbostic 	SET_DIROP(VTOI(ap->a_dvp)->i_lfs);
42254264Sbostic 	MARK_VNODE(ap->a_dvp);
42354264Sbostic 	ret = ufs_mknod(ap);
42454264Sbostic 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs);
42554264Sbostic 	return (ret);
42654264Sbostic }
42754264Sbostic 
42854264Sbostic int
42954264Sbostic lfs_create(ap)
43054692Sbostic 	struct vop_create_args /* {
43154692Sbostic 		struct vnode *a_dvp;
43254692Sbostic 		struct vnode **a_vpp;
43354692Sbostic 		struct componentname *a_cnp;
43454692Sbostic 		struct vattr *a_vap;
43554692Sbostic 	} */ *ap;
43654264Sbostic {
43754264Sbostic 	int ret;
43854264Sbostic 
43954264Sbostic 	SET_DIROP(VTOI(ap->a_dvp)->i_lfs);
44054264Sbostic 	MARK_VNODE(ap->a_dvp);
44154264Sbostic 	ret = ufs_create(ap);
44254264Sbostic 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs);
44354264Sbostic 	return (ret);
44454264Sbostic }
44554264Sbostic 
44654264Sbostic int
44754264Sbostic lfs_mkdir(ap)
44854692Sbostic 	struct vop_mkdir_args /* {
44954692Sbostic 		struct vnode *a_dvp;
45054692Sbostic 		struct vnode **a_vpp;
45154692Sbostic 		struct componentname *a_cnp;
45254692Sbostic 		struct vattr *a_vap;
45354692Sbostic 	} */ *ap;
45454264Sbostic {
45554264Sbostic 	int ret;
45654264Sbostic 
45754264Sbostic 	SET_DIROP(VTOI(ap->a_dvp)->i_lfs);
45854264Sbostic 	MARK_VNODE(ap->a_dvp);
45954264Sbostic 	ret = ufs_mkdir(ap);
46054264Sbostic 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs);
46154264Sbostic 	return (ret);
46254264Sbostic }
46354264Sbostic 
46454264Sbostic int
46554264Sbostic lfs_remove(ap)
46654692Sbostic 	struct vop_remove_args /* {
46754692Sbostic 		struct vnode *a_dvp;
46854692Sbostic 		struct vnode *a_vp;
46954692Sbostic 		struct componentname *a_cnp;
47054692Sbostic 	} */ *ap;
47154264Sbostic {
47254264Sbostic 	int ret;
47354264Sbostic 
47454264Sbostic 	SET_DIROP(VTOI(ap->a_dvp)->i_lfs);
47554264Sbostic 	MARK_VNODE(ap->a_dvp);
47654264Sbostic 	MARK_VNODE(ap->a_vp);
47754264Sbostic 	ret = ufs_remove(ap);
47854264Sbostic 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs);
47954264Sbostic 	return (ret);
48054264Sbostic }
48154264Sbostic 
48254264Sbostic int
48354264Sbostic lfs_rmdir(ap)
48454692Sbostic 	struct vop_rmdir_args /* {
48554692Sbostic 		struct vnodeop_desc *a_desc;
48654692Sbostic 		struct vnode *a_dvp;
48754692Sbostic 		struct vnode *a_vp;
48854692Sbostic 		struct componentname *a_cnp;
48954692Sbostic 	} */ *ap;
49054264Sbostic {
49154264Sbostic 	int ret;
49254264Sbostic 
49354264Sbostic 	SET_DIROP(VTOI(ap->a_dvp)->i_lfs);
49454264Sbostic 	MARK_VNODE(ap->a_dvp);
49554264Sbostic 	MARK_VNODE(ap->a_vp);
49654264Sbostic 	ret = ufs_rmdir(ap);
49754264Sbostic 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs);
49854264Sbostic 	return (ret);
49954264Sbostic }
50054264Sbostic 
50154264Sbostic int
50254264Sbostic lfs_link(ap)
50354692Sbostic 	struct vop_link_args /* {
50454692Sbostic 		struct vnode *a_vp;
50554692Sbostic 		struct vnode *a_tdvp;
50654692Sbostic 		struct componentname *a_cnp;
50754692Sbostic 	} */ *ap;
50854264Sbostic {
50954264Sbostic 	int ret;
51054264Sbostic 
51154264Sbostic 	SET_DIROP(VTOI(ap->a_vp)->i_lfs);
51254264Sbostic 	MARK_VNODE(ap->a_vp);
51354264Sbostic 	ret = ufs_link(ap);
51454264Sbostic 	SET_ENDOP(VTOI(ap->a_vp)->i_lfs);
51554264Sbostic 	return (ret);
51654264Sbostic }
51754264Sbostic 
51854264Sbostic int
51954264Sbostic lfs_rename(ap)
52054692Sbostic 	struct vop_rename_args  /* {
52154692Sbostic 		struct vnode *a_fdvp;
52254692Sbostic 		struct vnode *a_fvp;
52354692Sbostic 		struct componentname *a_fcnp;
52454692Sbostic 		struct vnode *a_tdvp;
52554692Sbostic 		struct vnode *a_tvp;
52654692Sbostic 		struct componentname *a_tcnp;
52754692Sbostic 	} */ *ap;
52854264Sbostic {
52954264Sbostic 	int ret;
53054264Sbostic 
53154264Sbostic 	SET_DIROP(VTOI(ap->a_fdvp)->i_lfs);
53254264Sbostic 	MARK_VNODE(ap->a_fdvp);
53354264Sbostic 	MARK_VNODE(ap->a_tdvp);
53454264Sbostic 	ret = ufs_rename(ap);
53554264Sbostic 	SET_ENDOP(VTOI(ap->a_fdvp)->i_lfs);
53654264Sbostic 	return (ret);
53754264Sbostic }
53855936Sbostic /* XXX hack to avoid calling ITIMES in getattr */
53955936Sbostic int
54055936Sbostic lfs_getattr(ap)
54155936Sbostic 	struct vop_getattr_args /* {
54255936Sbostic 		struct vnode *a_vp;
54355936Sbostic 		struct vattr *a_vap;
54455936Sbostic 		struct ucred *a_cred;
54555936Sbostic 		struct proc *a_p;
54655936Sbostic 	} */ *ap;
54755936Sbostic {
54855936Sbostic 	register struct vnode *vp = ap->a_vp;
54955936Sbostic 	register struct inode *ip = VTOI(vp);
55055936Sbostic 	register struct vattr *vap = ap->a_vap;
55155936Sbostic 	/*
55255936Sbostic 	 * Copy from inode table
55355936Sbostic 	 */
55455936Sbostic 	vap->va_fsid = ip->i_dev;
55555936Sbostic 	vap->va_fileid = ip->i_number;
55655936Sbostic 	vap->va_mode = ip->i_mode & ~IFMT;
55755936Sbostic 	vap->va_nlink = ip->i_nlink;
55855936Sbostic 	vap->va_uid = ip->i_uid;
55955936Sbostic 	vap->va_gid = ip->i_gid;
56055936Sbostic 	vap->va_rdev = (dev_t)ip->i_rdev;
56155936Sbostic 	vap->va_size = ip->i_din.di_size;
56255936Sbostic 	vap->va_atime = ip->i_atime;
56355936Sbostic 	vap->va_mtime = ip->i_mtime;
56455936Sbostic 	vap->va_ctime = ip->i_ctime;
56555936Sbostic 	vap->va_flags = ip->i_flags;
56655936Sbostic 	vap->va_gen = ip->i_gen;
56755936Sbostic 	/* this doesn't belong here */
56855936Sbostic 	if (vp->v_type == VBLK)
56955936Sbostic 		vap->va_blocksize = BLKDEV_IOSIZE;
57055936Sbostic 	else if (vp->v_type == VCHR)
57155936Sbostic 		vap->va_blocksize = MAXBSIZE;
57255936Sbostic 	else
57355936Sbostic 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
57455936Sbostic 	vap->va_bytes = dbtob(ip->i_blocks);
57555936Sbostic 	vap->va_type = vp->v_type;
57655936Sbostic 	vap->va_filerev = ip->i_modrev;
57755936Sbostic 	return (0);
57855936Sbostic }
57956053Sbostic /*
58056053Sbostic  * Close called
58156053Sbostic  *
58256053Sbostic  * XXX -- we were using ufs_close, but since it updates the
58356053Sbostic  * times on the inode, we might need to bump the uinodes
58456053Sbostic  * count.
58556053Sbostic  */
58656053Sbostic /* ARGSUSED */
58756053Sbostic int
58856053Sbostic lfs_close(ap)
58956053Sbostic 	struct vop_close_args /* {
59056053Sbostic 		struct vnode *a_vp;
59156053Sbostic 		int  a_fflag;
59256053Sbostic 		struct ucred *a_cred;
59356053Sbostic 		struct proc *a_p;
59456053Sbostic 	} */ *ap;
59556053Sbostic {
59656053Sbostic 	register struct vnode *vp = ap->a_vp;
59756053Sbostic 	register struct inode *ip = VTOI(vp);
59856053Sbostic 	int mod;
59956053Sbostic 
60056053Sbostic 	if (vp->v_usecount > 1 && !(ip->i_flag & ILOCKED)) {
60156053Sbostic 		mod = ip->i_flag & IMOD;
60256053Sbostic 		ITIMES(ip, &time, &time);
60356053Sbostic 		if (!mod && ip->i_flag & IMOD)
60456053Sbostic 			ip->i_lfs->lfs_uinodes++;
60556053Sbostic 	}
60656053Sbostic 	return (0);
60756053Sbostic }
60856053Sbostic 
609