xref: /csrg-svn/sys/ufs/lfs/lfs_vfsops.c (revision 52221)
123400Smckusick /*
250264Skarels  * Copyright (c) 1989, 1991 The Regents of the University of California.
337737Smckusick  * All rights reserved.
423400Smckusick  *
544539Sbostic  * %sccs.include.redist.c%
637737Smckusick  *
7*52221Sbostic  *	@(#)lfs_vfsops.c	7.72 (Berkeley) 01/18/92
823400Smckusick  */
912795Ssam 
1051483Sbostic #include <sys/param.h>
1151483Sbostic #include <sys/systm.h>
1251483Sbostic #include <sys/namei.h>
1351483Sbostic #include <sys/proc.h>
1451483Sbostic #include <sys/kernel.h>
1551483Sbostic #include <sys/vnode.h>
1651483Sbostic #include <sys/specdev.h>
1751483Sbostic #include <sys/mount.h>
1851483Sbostic #include <sys/buf.h>
1951483Sbostic #include <sys/file.h>
2051483Sbostic #include <sys/disklabel.h>
2151483Sbostic #include <sys/ioctl.h>
2251483Sbostic #include <sys/errno.h>
2351483Sbostic #include <sys/malloc.h>
2412795Ssam 
2551501Sbostic #include <ufs/ufs/quota.h>
2651501Sbostic #include <ufs/ufs/inode.h>
2751501Sbostic #include <ufs/ufs/ufsmount.h>
2851501Sbostic #include <ufs/ufs/ufs_extern.h>
2947571Skarels 
3051501Sbostic #include <ufs/lfs/lfs.h>
3151501Sbostic #include <ufs/lfs/lfs_extern.h>
3251155Sbostic 
3351991Sbostic int lfs_mountfs __P((struct vnode *, struct mount *, struct proc *));
3451215Sbostic 
3551155Sbostic struct vfsops lfs_vfsops = {
3651155Sbostic 	lfs_mount,
3739043Smckusick 	ufs_start,
3851155Sbostic 	lfs_unmount,
3951559Smckusick 	lfs_root,
4041314Smckusick 	ufs_quotactl,
4151155Sbostic 	lfs_statfs,
4251155Sbostic 	lfs_sync,
4351559Smckusick 	lfs_fhtovp,
4451559Smckusick 	lfs_vptofh,
4551483Sbostic 	lfs_init,
4637737Smckusick };
4737737Smckusick 
4851483Sbostic int
4951155Sbostic lfs_mountroot()
5012795Ssam {
5151483Sbostic 	panic("lfs_mountroot");		/* XXX -- implement */
5237737Smckusick }
5337737Smckusick 
5437737Smckusick /*
5537737Smckusick  * VFS Operations.
5637737Smckusick  *
5737737Smckusick  * mount system call
5837737Smckusick  */
5951155Sbostic lfs_mount(mp, path, data, ndp, p)
6040346Smckusick 	register struct mount *mp;
6137737Smckusick 	char *path;
6237737Smckusick 	caddr_t data;
6337737Smckusick 	struct nameidata *ndp;
6448036Smckusick 	struct proc *p;
6537737Smckusick {
6637737Smckusick 	struct vnode *devvp;
6737737Smckusick 	struct ufs_args args;
6837737Smckusick 	struct ufsmount *ump;
6951501Sbostic 	register struct lfs *fs;				/* LFS */
7037737Smckusick 	u_int size;
7137737Smckusick 	int error;
7237737Smckusick 
7337737Smckusick 	if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
7437737Smckusick 		return (error);
7551483Sbostic 
7651483Sbostic 	/* Until LFS can do NFS right.		XXX */
7751483Sbostic 	if (args.exflags & MNT_EXPORTED)
7851483Sbostic 		return (EINVAL);
7940371Smckusick 	/*
8050264Skarels 	 * If updating, check whether changing from read-only to
8150264Skarels 	 * read/write; if there is no device name, that's all we do.
8250264Skarels 	 */
8350264Skarels 	if (mp->mnt_flag & MNT_UPDATE) {
8439336Smckusick 		ump = VFSTOUFS(mp);
8551155Sbostic #ifdef NOTLFS							/* LFS */
8639336Smckusick 		fs = ump->um_fs;
8741397Smckusick 		if (fs->fs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
8839336Smckusick 			fs->fs_ronly = 0;
8951155Sbostic #else
9051155Sbostic 		fs = ump->um_lfs;
9151155Sbostic 		if (fs->lfs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
9251155Sbostic 			fs->lfs_ronly = 0;
9351155Sbostic #endif
9452175Smckusick 		if (args.fspec == 0) {
9552175Smckusick 			/*
9652175Smckusick 			 * Process export requests.
9752175Smckusick 			 */
9852175Smckusick 			if (args.exflags & MNT_EXPORTED) {
9952175Smckusick 				if (error = hang_addrlist(mp, &args))
10052175Smckusick 					return (error);
10152175Smckusick 				mp->mnt_flag |= MNT_EXPORTED;
10252175Smckusick 			}
10352175Smckusick 			if (args.exflags & MNT_DELEXPORT) {
10452175Smckusick 				free_addrlist(ump);
10552175Smckusick 				mp->mnt_flag &=
10652175Smckusick 				    ~(MNT_EXPORTED | MNT_DEFEXPORTED);
10752175Smckusick 			}
10840371Smckusick 			return (0);
10952175Smckusick 		}
11050264Skarels 	}
11150264Skarels 	/*
11250264Skarels 	 * Not an update, or updating the name: look up the name
11350264Skarels 	 * and verify that it refers to a sensible block device.
11450264Skarels 	 */
11550264Skarels 	ndp->ni_nameiop = LOOKUP | FOLLOW;
11650264Skarels 	ndp->ni_segflg = UIO_USERSPACE;
11750264Skarels 	ndp->ni_dirp = args.fspec;
11850264Skarels 	if (error = namei(ndp, p))
11950264Skarels 		return (error);
12050264Skarels 	devvp = ndp->ni_vp;
12150264Skarels 	if (devvp->v_type != VBLK) {
12250264Skarels 		vrele(devvp);
12350264Skarels 		return (ENOTBLK);
12450264Skarels 	}
12550264Skarels 	if (major(devvp->v_rdev) >= nblkdev) {
12650264Skarels 		vrele(devvp);
12750264Skarels 		return (ENXIO);
12850264Skarels 	}
12950264Skarels 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
13051155Sbostic 		error = lfs_mountfs(devvp, mp, p);		/* LFS */
13150264Skarels 	else {
13239336Smckusick 		if (devvp != ump->um_devvp)
13339336Smckusick 			error = EINVAL;	/* needs translation */
13442858Smckusick 		else
13542858Smckusick 			vrele(devvp);
13639336Smckusick 	}
13737737Smckusick 	if (error) {
13837737Smckusick 		vrele(devvp);
13937737Smckusick 		return (error);
14032721Smckusick 	}
14137737Smckusick 	ump = VFSTOUFS(mp);
14251155Sbostic 	fs = ump->um_lfs;					/* LFS */
14351155Sbostic #ifdef NOTLFS							/* LFS */
14437737Smckusick 	(void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size);
14537737Smckusick 	bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size);
14641397Smckusick 	bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
14741397Smckusick 	    MNAMELEN);
14851991Sbostic 	(void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
14941397Smckusick 	    &size);
15041397Smckusick 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
15148036Smckusick 	(void) ufs_statfs(mp, &mp->mnt_stat, p);
15251155Sbostic #else
15351155Sbostic 	(void)copyinstr(path, fs->lfs_fsmnt, sizeof(fs->lfs_fsmnt) - 1, &size);
15451155Sbostic 	bzero(fs->lfs_fsmnt + size, sizeof(fs->lfs_fsmnt) - size);
15551155Sbostic 	bcopy((caddr_t)fs->lfs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
15651155Sbostic 	    MNAMELEN);
15751991Sbostic 	(void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
15851155Sbostic 	    &size);
15951155Sbostic 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
16051155Sbostic 	(void) lfs_statfs(mp, &mp->mnt_stat, p);
16151155Sbostic #endif
16237737Smckusick 	return (0);
16312795Ssam }
16412795Ssam 
16537737Smckusick /*
16637737Smckusick  * Common code for mount and mountroot
16751155Sbostic  * LFS specific
16837737Smckusick  */
16951991Sbostic int
17051155Sbostic lfs_mountfs(devvp, mp, p)
17140376Smckusick 	register struct vnode *devvp;
17237737Smckusick 	struct mount *mp;
17348036Smckusick 	struct proc *p;
17412795Ssam {
17551155Sbostic 	extern struct vnode *rootvp;
17651501Sbostic 	register struct lfs *fs;
17751155Sbostic 	register struct ufsmount *ump;
17851155Sbostic 	struct vnode *vp;
17951155Sbostic 	struct buf *bp;
18030749Skarels 	struct partinfo dpart;
18151155Sbostic 	dev_t dev;
18251155Sbostic 	int error, i, ronly, size;
18312795Ssam 
18440376Smckusick 	/*
18540376Smckusick 	 * Disallow multiple mounts of the same device.
18645652Smckusick 	 * Disallow mounting of a device that is currently in use
18745652Smckusick 	 * (except for root, which might share swap device for miniroot).
18840376Smckusick 	 * Flush out any old buffers remaining from a previous use.
18940376Smckusick 	 */
19051483Sbostic 	if (error = ufs_mountedon(devvp))
19140376Smckusick 		return (error);
19245652Smckusick 	if (vcount(devvp) > 1 && devvp != rootvp)
19340376Smckusick 		return (EBUSY);
19440376Smckusick 	vinvalbuf(devvp, 1);
19551155Sbostic 
19651155Sbostic 	ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
19748036Smckusick 	if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p))
19837737Smckusick 		return (error);
19951155Sbostic 
20048036Smckusick 	if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0)
20137737Smckusick 		size = DEV_BSIZE;
20248036Smckusick 	else {
20330749Skarels 		size = dpart.disklab->d_secsize;
20451155Sbostic #ifdef NEVER_USED
20551155Sbostic 		dpart.part->p_fstype = FS_LFS;
20651155Sbostic 		dpart.part->p_fsize = fs->lfs_fsize;	/* frag size */
20751155Sbostic 		dpart.part->p_frag = fs->lfs_frag;	/* frags per block */
20851155Sbostic 		dpart.part->p_cpg = fs->lfs_segshift;	/* segment shift */
20951155Sbostic #endif
21037737Smckusick 	}
21151155Sbostic 
21251155Sbostic 	/* Don't free random space on error. */
21351155Sbostic 	bp = NULL;
21451155Sbostic 	ump = NULL;
21551155Sbostic 
21651155Sbostic 	/* Read in the superblock. */
21751155Sbostic 	if (error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, NOCRED, &bp))
21812795Ssam 		goto out;
21951155Sbostic 	fs = bp->b_un.b_lfs;
22051155Sbostic 
22151155Sbostic 	/* Check the basics. */
22251155Sbostic 	if (fs->lfs_magic != LFS_MAGIC || fs->lfs_bsize > MAXBSIZE ||
22351501Sbostic 	    fs->lfs_bsize < sizeof(struct lfs)) {
22441314Smckusick 		error = EINVAL;		/* XXX needs translation */
22516639Skarels 		goto out;
22616639Skarels 	}
22751155Sbostic #ifdef DEBUG
22851483Sbostic 	lfs_dump_super(fs);
22951155Sbostic #endif
23051155Sbostic 
23151155Sbostic 	/* Allocate the mount structure, copy the superblock into it. */
23241314Smckusick 	ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
23351989Smckusick 	ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK);
23451501Sbostic 	bcopy(bp->b_un.b_addr, ump->um_lfs, sizeof(struct lfs));
23551501Sbostic 	if (sizeof(struct lfs) < LFS_SBPAD)			/* XXX why? */
23639675Smckusick 		bp->b_flags |= B_INVAL;
23734421Skarels 	brelse(bp);
23834421Skarels 	bp = NULL;
23951155Sbostic 
24051183Sbostic 	/* Set up the I/O information */
24151183Sbostic 	fs->lfs_iocount = 0;
24251183Sbostic 
24351155Sbostic 	/* Set the file system readonly/modify bits. */
24451155Sbostic 	fs = ump->um_lfs;
24551155Sbostic 	fs->lfs_ronly = ronly;
24612795Ssam 	if (ronly == 0)
24751155Sbostic 		fs->lfs_fmod = 1;
24851155Sbostic 
24951155Sbostic 	/* Initialize the mount structure. */
25051155Sbostic 	dev = devvp->v_rdev;
25141397Smckusick 	mp->mnt_data = (qaddr_t)ump;
25241397Smckusick 	mp->mnt_stat.f_fsid.val[0] = (long)dev;
25351991Sbostic 	mp->mnt_stat.f_fsid.val[1] = MOUNT_LFS;
25441397Smckusick 	mp->mnt_flag |= MNT_LOCAL;
25537737Smckusick 	ump->um_mountp = mp;
25637737Smckusick 	ump->um_dev = dev;
25737737Smckusick 	ump->um_devvp = devvp;
25841314Smckusick 	for (i = 0; i < MAXQUOTAS; i++)
25941314Smckusick 		ump->um_quotas[i] = NULLVP;
260*52221Sbostic 	devvp->v_specflags |= SI_MOUNTEDON;
26151155Sbostic 
262*52221Sbostic 	/*
263*52221Sbostic 	 * We use the ifile vnode for almost every operation.  Instead of
264*52221Sbostic 	 * retrieving it from the hash table each time we retrieve it here,
265*52221Sbostic 	 * artificially increment the reference count and keep a pointer
266*52221Sbostic 	 * to it in the incore copy of the superblock.
267*52221Sbostic 	 */
268*52221Sbostic 	if (error = lfs_vget(mp, LFS_IFILE_INUM, &vp))
26951155Sbostic 		goto out;
27051155Sbostic 	fs->lfs_ivnode = vp;
271*52221Sbostic 	VREF(vp);
272*52221Sbostic 	vput(vp);
27351155Sbostic 
27437737Smckusick 	return (0);
27512795Ssam out:
27640872Smckusick 	if (bp)
27740872Smckusick 		brelse(bp);
27851155Sbostic 	(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
27941314Smckusick 	if (ump) {
28051989Smckusick 		free(ump->um_lfs, M_UFSMNT);
28151501Sbostic 		free(ump, M_UFSMNT);
28241397Smckusick 		mp->mnt_data = (qaddr_t)0;
28332721Smckusick 	}
28437737Smckusick 	return (error);
28512795Ssam }
28612795Ssam 
28739043Smckusick /*
28837737Smckusick  * unmount system call
28937737Smckusick  */
29051155Sbostic lfs_unmount(mp, mntflags, p)
29137737Smckusick 	struct mount *mp;
29241314Smckusick 	int mntflags;
29348036Smckusick 	struct proc *p;
29412795Ssam {
29551501Sbostic 	extern int doforce;
29637737Smckusick 	register struct ufsmount *ump;
29751501Sbostic 	register struct lfs *fs;				/* LFS */
29841314Smckusick 	int i, error, ronly, flags = 0;
29951215Sbostic 	int ndirty;						/* LFS */
30012795Ssam 
30151853Sbostic #ifdef VERBOSE
30251853Sbostic 	printf("lfs_unmount\n");
30351853Sbostic #endif
30448065Smckusick 	if (mntflags & MNT_FORCE) {
30548359Smckusick 		if (!doforce || mp == rootfs)
30648065Smckusick 			return (EINVAL);
30741314Smckusick 		flags |= FORCECLOSE;
30848065Smckusick 	}
30951215Sbostic 	if (error = lfs_segwrite(mp, 1))
31051215Sbostic 		return(error);
31151215Sbostic 
31251215Sbostic ndirty = lfs_umountdebug(mp);
31351215Sbostic printf("lfs_umountdebug: returned %d dirty\n", ndirty);
31451215Sbostic return(0);
31539675Smckusick 	if (mntinvalbuf(mp))
31639675Smckusick 		return (EBUSY);
31737737Smckusick 	ump = VFSTOUFS(mp);
31812795Ssam #ifdef QUOTA
31941397Smckusick 	if (mp->mnt_flag & MNT_QUOTA) {
32041314Smckusick 		if (error = vflush(mp, NULLVP, SKIPSYSTEM|flags))
32139898Smckusick 			return (error);
32241314Smckusick 		for (i = 0; i < MAXQUOTAS; i++) {
32341314Smckusick 			if (ump->um_quotas[i] == NULLVP)
32441314Smckusick 				continue;
32550114Smckusick 			quotaoff(p, mp, i);
32641314Smckusick 		}
32739898Smckusick 		/*
32841314Smckusick 		 * Here we fall through to vflush again to ensure
32941314Smckusick 		 * that we have gotten rid of all the system vnodes.
33039898Smckusick 		 */
33141314Smckusick 	}
33212795Ssam #endif
33341314Smckusick 	if (error = vflush(mp, NULLVP, flags))
33439898Smckusick 		return (error);
33551155Sbostic 	fs = ump->um_lfs;
33651155Sbostic 	ronly = !fs->lfs_ronly;
337*52221Sbostic 	vrele(fs->lfs_ivnode);
33840653Smckusick 	ump->um_devvp->v_specflags &= ~SI_MOUNTEDON;
33948036Smckusick 	error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD|FWRITE,
34048036Smckusick 		NOCRED, p);
34137737Smckusick 	vrele(ump->um_devvp);
34251989Smckusick 	free(fs, M_UFSMNT);
34351501Sbostic 	free(ump, M_UFSMNT);
34441397Smckusick 	mp->mnt_data = (qaddr_t)0;
34541397Smckusick 	mp->mnt_flag &= ~MNT_LOCAL;
34630749Skarels 	return (error);
34712795Ssam }
34812795Ssam 
34937737Smckusick /*
35051559Smckusick  * Return root of a filesystem
35151559Smckusick  */
35251559Smckusick int
35351559Smckusick lfs_root(mp, vpp)
35451559Smckusick 	struct mount *mp;
35551559Smckusick 	struct vnode **vpp;
35651559Smckusick {
35751559Smckusick 	struct vnode *nvp;
35851559Smckusick 	int error;
35951559Smckusick 
36051853Sbostic #ifdef VERBOSE
36151853Sbostic 	printf("lfs_root\n");
36251853Sbostic #endif
36351559Smckusick 	if (error = lfs_vget(mp, (ino_t)ROOTINO, &nvp))
36451559Smckusick 		return (error);
36551559Smckusick 	*vpp = nvp;
36651559Smckusick 	return (0);
36751559Smckusick }
36851559Smckusick 
36951559Smckusick /*
37037737Smckusick  * Get file system statistics.
37137737Smckusick  */
37251155Sbostic lfs_statfs(mp, sbp, p)
37337737Smckusick 	struct mount *mp;
37437737Smckusick 	register struct statfs *sbp;
37548036Smckusick 	struct proc *p;
37637737Smckusick {
37751501Sbostic 	register struct lfs *fs;
37837737Smckusick 	register struct ufsmount *ump;
37937737Smckusick 
38037737Smckusick 	ump = VFSTOUFS(mp);
38151155Sbostic 	fs = ump->um_lfs;
38251155Sbostic 	if (fs->lfs_magic != LFS_MAGIC)
38351155Sbostic 		panic("lfs_statfs: magic");
38451155Sbostic 	sbp->f_type = MOUNT_LFS;
38551155Sbostic 	sbp->f_bsize = fs->lfs_bsize;
38651943Smckusick 	sbp->f_iosize = fs->lfs_bsize;
38751155Sbostic 	sbp->f_blocks = fs->lfs_dsize;
38851155Sbostic 	sbp->f_bfree = fs->lfs_bfree;
38951155Sbostic 	sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
39051155Sbostic 		(fs->lfs_dsize - sbp->f_bfree);
39151155Sbostic 	sbp->f_files = fs->lfs_nfiles;
39251155Sbostic 	sbp->f_ffree = fs->lfs_bfree * INOPB(fs);
39341397Smckusick 	if (sbp != &mp->mnt_stat) {
39441397Smckusick 		bcopy((caddr_t)mp->mnt_stat.f_mntonname,
39540346Smckusick 			(caddr_t)&sbp->f_mntonname[0], MNAMELEN);
39641397Smckusick 		bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
39740346Smckusick 			(caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
39840346Smckusick 	}
39937737Smckusick 	return (0);
40037737Smckusick }
40137737Smckusick 
40237737Smckusick /*
40337737Smckusick  * Go through the disk queues to initiate sandbagged IO;
40437737Smckusick  * go through the inodes to write those that have been modified;
40537737Smckusick  * initiate the writing of the super block if it has been modified.
40641314Smckusick  *
40741314Smckusick  * Note: we are always called with the filesystem marked `MPBUSY'.
40837737Smckusick  */
40951155Sbostic lfs_sync(mp, waitfor)
41037737Smckusick 	struct mount *mp;
41137737Smckusick 	int waitfor;
41237737Smckusick {
41351914Sbostic 	extern int crashandburn, syncprt;
41451215Sbostic 	int error;
41537737Smckusick 
41651853Sbostic #ifdef VERBOSE
41751853Sbostic 	printf("lfs_sync\n");
41851853Sbostic #endif
41951215Sbostic 
42051914Sbostic #ifdef DIAGNOSTIC
42151914Sbostic 	if (crashandburn)
42251914Sbostic 		return (0);
42351914Sbostic #endif
42437737Smckusick 	if (syncprt)
42551483Sbostic 		ufs_bufstats();
42651310Sbostic 
42751310Sbostic 	/* All syncs must be checkpoints until roll-forward is implemented. */
42851991Sbostic 	error = lfs_segwrite(mp, 1);
42941314Smckusick #ifdef QUOTA
43041314Smckusick 	qsync(mp);
43141314Smckusick #endif
43251215Sbostic 	return (error);
43337737Smckusick }
43451559Smckusick 
43551559Smckusick /*
43651559Smckusick  * File handle to vnode
43751559Smckusick  *
43851559Smckusick  * Have to be really careful about stale file handles:
43951559Smckusick  * - check that the inode number is valid
44051559Smckusick  * - call lfs_vget() to get the locked inode
44151559Smckusick  * - check for an unallocated inode (i_mode == 0)
44251559Smckusick  * - check that the generation number matches
44351559Smckusick  *
44451559Smckusick  * XXX
44551559Smckusick  * use ifile to see if inode is allocated instead of reading off disk
44651559Smckusick  * what is the relationship between my generational number and the NFS
44751559Smckusick  * generational number.
44851559Smckusick  */
44951559Smckusick int
45052175Smckusick lfs_fhtovp(mp, fhp, setgen, vpp)
45151559Smckusick 	register struct mount *mp;
45251559Smckusick 	struct fid *fhp;
45352175Smckusick 	int setgen;
45451559Smckusick 	struct vnode **vpp;
45551559Smckusick {
45651559Smckusick 	register struct inode *ip;
45751559Smckusick 	register struct ufid *ufhp;
45851559Smckusick 	struct vnode *nvp;
45951559Smckusick 	int error;
46051559Smckusick 
46151559Smckusick 	ufhp = (struct ufid *)fhp;
46251559Smckusick 	if (ufhp->ufid_ino < ROOTINO)
46351559Smckusick 		return (EINVAL);
46451559Smckusick 	if (error = lfs_vget(mp, ufhp->ufid_ino, &nvp)) {
46551559Smckusick 		*vpp = NULLVP;
46651559Smckusick 		return (error);
46751559Smckusick 	}
46851559Smckusick 	ip = VTOI(nvp);
46951559Smckusick 	if (ip->i_mode == 0) {
47051559Smckusick 		ufs_iput(ip);
47151559Smckusick 		*vpp = NULLVP;
47251559Smckusick 		return (EINVAL);
47351559Smckusick 	}
47451559Smckusick 	if (ip->i_gen != ufhp->ufid_gen) {
47552175Smckusick 		if (setgen)
47652175Smckusick 			ufhp->ufid_gen = ip->i_gen;
47752175Smckusick 		else {
47852175Smckusick 			ufs_iput(ip);
47952175Smckusick 			*vpp = NULLVP;
48052175Smckusick 			return (EINVAL);
48152175Smckusick 		}
48251559Smckusick 	}
48351559Smckusick 	*vpp = nvp;
48451559Smckusick 	return (0);
48551559Smckusick }
48651559Smckusick 
48751559Smckusick /*
48851559Smckusick  * Vnode pointer to File handle
48951559Smckusick  */
49051559Smckusick /* ARGSUSED */
49151559Smckusick lfs_vptofh(vp, fhp)
49251559Smckusick 	struct vnode *vp;
49351559Smckusick 	struct fid *fhp;
49451559Smckusick {
49551559Smckusick 	register struct inode *ip;
49651559Smckusick 	register struct ufid *ufhp;
49751559Smckusick 
49851559Smckusick 	ip = VTOI(vp);
49951559Smckusick 	ufhp = (struct ufid *)fhp;
50051559Smckusick 	ufhp->ufid_len = sizeof(struct ufid);
50151559Smckusick 	ufhp->ufid_ino = ip->i_number;
50251559Smckusick 	ufhp->ufid_gen = ip->i_gen;
50351559Smckusick 	return (0);
50451559Smckusick }
505