Home | History | Annotate | Line # | Download | only in lfs
lfs_vfsops.c revision 1.18
      1 /*	$NetBSD: lfs_vfsops.c,v 1.18 1998/03/18 15:57:28 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1989, 1991, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)lfs_vfsops.c	8.20 (Berkeley) 6/10/95
     36  */
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/namei.h>
     41 #include <sys/proc.h>
     42 #include <sys/kernel.h>
     43 #include <sys/vnode.h>
     44 #include <sys/mount.h>
     45 #include <sys/buf.h>
     46 #include <sys/mbuf.h>
     47 #include <sys/file.h>
     48 #include <sys/disklabel.h>
     49 #include <sys/ioctl.h>
     50 #include <sys/errno.h>
     51 #include <sys/malloc.h>
     52 #include <sys/socket.h>
     53 
     54 #include <miscfs/specfs/specdev.h>
     55 
     56 #include <ufs/ufs/quota.h>
     57 #include <ufs/ufs/inode.h>
     58 #include <ufs/ufs/ufsmount.h>
     59 #include <ufs/ufs/ufs_extern.h>
     60 
     61 #include <ufs/lfs/lfs.h>
     62 #include <ufs/lfs/lfs_extern.h>
     63 
     64 int lfs_mountfs __P((struct vnode *, struct mount *, struct proc *));
     65 
     66 extern struct vnodeopv_desc lfs_vnodeop_opv_desc;
     67 extern struct vnodeopv_desc lfs_specop_opv_desc;
     68 #ifdef FIFO
     69 extern struct vnodeopv_desc lfs_fifoop_opv_desc;
     70 #endif
     71 
     72 struct vnodeopv_desc *lfs_vnodeopv_descs[] = {
     73 	&lfs_vnodeop_opv_desc,
     74 	&lfs_specop_opv_desc,
     75 #ifdef FIFO
     76 	&lfs_fifoop_opv_desc,
     77 #endif
     78 	NULL,
     79 };
     80 
     81 struct vfsops lfs_vfsops = {
     82 	MOUNT_LFS,
     83 	lfs_mount,
     84 	ufs_start,
     85 	lfs_unmount,
     86 	ufs_root,
     87 	ufs_quotactl,
     88 	lfs_statfs,
     89 	lfs_sync,
     90 	lfs_vget,
     91 	lfs_fhtovp,
     92 	lfs_vptofh,
     93 	lfs_init,
     94 	lfs_sysctl,
     95 	NULL,
     96 	lfs_vnodeopv_descs,
     97 };
     98 
     99 /*
    100  * Initialize the filesystem, most work done by ufs_init.
    101  */
    102 void
    103 lfs_init()
    104 {
    105 	ufs_init();
    106 }
    107 
    108 /*
    109  * Called by main() when ufs is going to be mounted as root.
    110  */
    111 int
    112 lfs_mountroot()
    113 {
    114 	extern struct vnode *rootvp;
    115 	struct mount *mp;
    116 	struct proc *p = curproc;	/* XXX */
    117 	int error;
    118 
    119 	/*
    120 	 * Get vnodes for swapdev and rootdev.
    121 	 */
    122 	if ((error = bdevvp(rootdev, &rootvp))) {
    123 		printf("lfs_mountroot: can't setup bdevvp's");
    124 		return (error);
    125 	}
    126 	if ((error = vfs_rootmountalloc(MOUNT_LFS, "root_device", &mp)))
    127 		return (error);
    128 	if ((error = lfs_mountfs(rootvp, mp, p))) {
    129 		mp->mnt_op->vfs_refcount--;
    130 		vfs_unbusy(mp);
    131 		free(mp, M_MOUNT);
    132 		return (error);
    133 	}
    134 	simple_lock(&mountlist_slock);
    135 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    136 	simple_unlock(&mountlist_slock);
    137 	(void)lfs_statfs(mp, &mp->mnt_stat, p);
    138 	vfs_unbusy(mp);
    139 	return (0);
    140 }
    141 
    142 /*
    143  * VFS Operations.
    144  *
    145  * mount system call
    146  */
    147 int
    148 lfs_mount(mp, path, data, ndp, p)
    149 	register struct mount *mp;
    150 	const char *path;
    151 	void *data;
    152 	struct nameidata *ndp;
    153 	struct proc *p;
    154 {
    155 	struct vnode *devvp;
    156 	struct ufs_args args;
    157 	struct ufsmount *ump = NULL;
    158 	register struct lfs *fs = NULL;				/* LFS */
    159 	size_t size;
    160 	int error;
    161 	mode_t accessmode;
    162 
    163 	error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args));
    164 	if (error)
    165 		return (error);
    166 
    167 	/* Until LFS can do NFS right.		XXX */
    168 	if (args.export.ex_flags & MNT_EXPORTED)
    169 		return (EINVAL);
    170 
    171 	/*
    172 	 * If updating, check whether changing from read-only to
    173 	 * read/write; if there is no device name, that's all we do.
    174 	 */
    175 	if (mp->mnt_flag & MNT_UPDATE) {
    176 		ump = VFSTOUFS(mp);
    177 		if (fs->lfs_ronly && (mp->mnt_flag & MNT_WANTRDWR)) {
    178 			/*
    179 			 * If upgrade to read-write by non-root, then verify
    180 			 * that user has necessary permissions on the device.
    181 			 */
    182 			if (p->p_ucred->cr_uid != 0) {
    183 				vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
    184 				error = VOP_ACCESS(ump->um_devvp, VREAD|VWRITE,
    185 						   p->p_ucred, p);
    186 				VOP_UNLOCK(ump->um_devvp, 0);
    187 				if (error)
    188 					return (error);
    189 			}
    190 			fs->lfs_ronly = 0;
    191 		}
    192 		if (args.fspec == 0) {
    193 			/*
    194 			 * Process export requests.
    195 			 */
    196 			return (vfs_export(mp, &ump->um_export, &args.export));
    197 		}
    198 	}
    199 	/*
    200 	 * Not an update, or updating the name: look up the name
    201 	 * and verify that it refers to a sensible block device.
    202 	 */
    203 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
    204 	if ((error = namei(ndp)) != 0)
    205 		return (error);
    206 	devvp = ndp->ni_vp;
    207 	if (devvp->v_type != VBLK) {
    208 		vrele(devvp);
    209 		return (ENOTBLK);
    210 	}
    211 	if (major(devvp->v_rdev) >= nblkdev) {
    212 		vrele(devvp);
    213 		return (ENXIO);
    214 	}
    215 	/*
    216 	 * If mount by non-root, then verify that user has necessary
    217 	 * permissions on the device.
    218 	 */
    219 	if (p->p_ucred->cr_uid != 0) {
    220 		accessmode = VREAD;
    221 		if ((mp->mnt_flag & MNT_RDONLY) == 0)
    222 			accessmode |= VWRITE;
    223 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    224 		error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p);
    225 		if (error) {
    226 			vput(devvp);
    227 			return (error);
    228 		}
    229 		VOP_UNLOCK(devvp, 0);
    230 	}
    231 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
    232 		error = lfs_mountfs(devvp, mp, p);		/* LFS */
    233 	else {
    234 		if (devvp != ump->um_devvp)
    235 			error = EINVAL;	/* needs translation */
    236 		else
    237 			vrele(devvp);
    238 	}
    239 	if (error) {
    240 		vrele(devvp);
    241 		return (error);
    242 	}
    243 	ump = VFSTOUFS(mp);
    244 	fs = ump->um_lfs;					/* LFS */
    245 #ifdef NOTLFS							/* LFS */
    246 	(void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size);
    247 	bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size);
    248 	bcopy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, MNAMELEN);
    249 #else
    250 	(void)copyinstr(path, fs->lfs_fsmnt, sizeof(fs->lfs_fsmnt) - 1, &size);
    251 	bzero(fs->lfs_fsmnt + size, sizeof(fs->lfs_fsmnt) - size);
    252 	bcopy(fs->lfs_fsmnt, mp->mnt_stat.f_mntonname, MNAMELEN);
    253 #endif
    254 	(void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
    255 	    &size);
    256 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
    257 	return (0);
    258 }
    259 
    260 /*
    261  * Common code for mount and mountroot
    262  * LFS specific
    263  */
    264 int
    265 lfs_mountfs(devvp, mp, p)
    266 	register struct vnode *devvp;
    267 	struct mount *mp;
    268 	struct proc *p;
    269 {
    270 	extern struct vnode *rootvp;
    271 	register struct lfs *fs;
    272 	register struct ufsmount *ump;
    273 	struct vnode *vp;
    274 	struct buf *bp;
    275 	struct partinfo dpart;
    276 	dev_t dev;
    277 	int error, i, ronly, size;
    278 	struct ucred *cred;
    279 
    280 	cred = p ? p->p_ucred : NOCRED;
    281 	/*
    282 	 * Disallow multiple mounts of the same device.
    283 	 * Disallow mounting of a device that is currently in use
    284 	 * (except for root, which might share swap device for miniroot).
    285 	 * Flush out any old buffers remaining from a previous use.
    286 	 */
    287 	if ((error = vfs_mountedon(devvp)) != 0)
    288 		return (error);
    289 	if (vcount(devvp) > 1 && devvp != rootvp)
    290 		return (EBUSY);
    291 	if ((error = vinvalbuf(devvp, V_SAVE, cred, p, 0, 0)) != 0)
    292 		return (error);
    293 
    294 	ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
    295 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
    296 	if (error)
    297 		return (error);
    298 
    299 	if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, cred, p) != 0)
    300 		size = DEV_BSIZE;
    301 	else {
    302 		size = dpart.disklab->d_secsize;
    303 #ifdef NEVER_USED
    304 		dpart.part->p_fstype = FS_LFS;
    305 		dpart.part->p_fsize = fs->lfs_fsize;	/* frag size */
    306 		dpart.part->p_frag = fs->lfs_frag;	/* frags per block */
    307 		dpart.part->p_cpg = fs->lfs_segshift;	/* segment shift */
    308 #endif
    309 	}
    310 
    311 	/* Don't free random space on error. */
    312 	bp = NULL;
    313 	ump = NULL;
    314 
    315 	/* Read in the superblock. */
    316 	error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, cred, &bp);
    317 	if (error)
    318 		goto out;
    319 	fs = (struct lfs *)bp->b_data;
    320 
    321 	/* Check the basics. */
    322 	if (fs->lfs_magic != LFS_MAGIC || fs->lfs_bsize > MAXBSIZE ||
    323 	    fs->lfs_bsize < sizeof(struct lfs)) {
    324 		error = EINVAL;		/* XXX needs translation */
    325 		goto out;
    326 	}
    327 
    328 	/* Allocate the mount structure, copy the superblock into it. */
    329 	ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
    330 	fs = ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK);
    331 	bcopy(bp->b_data, fs, sizeof(struct lfs));
    332 	if (sizeof(struct lfs) < LFS_SBPAD)			/* XXX why? */
    333 		bp->b_flags |= B_INVAL;
    334 	brelse(bp);
    335 	bp = NULL;
    336 
    337 	/* Set up the I/O information */
    338 	fs->lfs_iocount = 0;
    339 
    340 	/* Set up the ifile and lock aflags */
    341 	fs->lfs_doifile = 0;
    342 	fs->lfs_writer = 0;
    343 	fs->lfs_dirops = 0;
    344 	fs->lfs_seglock = 0;
    345 
    346 	/* Set the file system readonly/modify bits. */
    347 	fs->lfs_ronly = ronly;
    348 	if (ronly == 0)
    349 		fs->lfs_fmod = 1;
    350 
    351 	/* Initialize the mount structure. */
    352 	dev = devvp->v_rdev;
    353 	mp->mnt_data = (qaddr_t)ump;
    354 	mp->mnt_stat.f_fsid.val[0] = (long)dev;
    355 	mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_LFS);
    356 	mp->mnt_maxsymlinklen = fs->lfs_maxsymlinklen;
    357 	mp->mnt_flag |= MNT_LOCAL;
    358 	ump->um_flags = 0;
    359 	ump->um_mountp = mp;
    360 	ump->um_dev = dev;
    361 	ump->um_devvp = devvp;
    362 	ump->um_bptrtodb = 0;
    363 	ump->um_seqinc = 1 << fs->lfs_fsbtodb;
    364 	ump->um_nindir = fs->lfs_nindir;
    365 	for (i = 0; i < MAXQUOTAS; i++)
    366 		ump->um_quotas[i] = NULLVP;
    367 	devvp->v_specflags |= SI_MOUNTEDON;
    368 
    369 	/*
    370 	 * We use the ifile vnode for almost every operation.  Instead of
    371 	 * retrieving it from the hash table each time we retrieve it here,
    372 	 * artificially increment the reference count and keep a pointer
    373 	 * to it in the incore copy of the superblock.
    374 	 */
    375 	if ((error = VFS_VGET(mp, LFS_IFILE_INUM, &vp)) != 0)
    376 		goto out;
    377 	fs->lfs_ivnode = vp;
    378 	VREF(vp);
    379 	vput(vp);
    380 
    381 	return (0);
    382 out:
    383 	if (bp)
    384 		brelse(bp);
    385 	(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, cred, p);
    386 	if (ump) {
    387 		free(ump->um_lfs, M_UFSMNT);
    388 		free(ump, M_UFSMNT);
    389 		mp->mnt_data = (qaddr_t)0;
    390 	}
    391 	return (error);
    392 }
    393 
    394 /*
    395  * unmount system call
    396  */
    397 int
    398 lfs_unmount(mp, mntflags, p)
    399 	struct mount *mp;
    400 	int mntflags;
    401 	struct proc *p;
    402 {
    403 	register struct ufsmount *ump;
    404 	register struct lfs *fs;
    405 	int error, flags, ronly;
    406 
    407 	flags = 0;
    408 	if (mntflags & MNT_FORCE)
    409 		flags |= FORCECLOSE;
    410 
    411 	ump = VFSTOUFS(mp);
    412 	fs = ump->um_lfs;
    413 #ifdef QUOTA
    414 	if (mp->mnt_flag & MNT_QUOTA) {
    415 		int i;
    416 		error = vflush(mp, fs->lfs_ivnode, SKIPSYSTEM|flags);
    417 		if (error)
    418 			return (error);
    419 		for (i = 0; i < MAXQUOTAS; i++) {
    420 			if (ump->um_quotas[i] == NULLVP)
    421 				continue;
    422 			quotaoff(p, mp, i);
    423 		}
    424 		/*
    425 		 * Here we fall through to vflush again to ensure
    426 		 * that we have gotten rid of all the system vnodes.
    427 		 */
    428 	}
    429 #endif
    430 	if ((error = vflush(mp, fs->lfs_ivnode, flags)) != 0)
    431 		return (error);
    432 	fs->lfs_clean = 1;
    433 	if ((error = VFS_SYNC(mp, 1, p->p_ucred, p)) != 0)
    434 		return (error);
    435 	if (fs->lfs_ivnode->v_dirtyblkhd.lh_first)
    436 		panic("lfs_unmount: still dirty blocks on ifile vnode\n");
    437 	vrele(fs->lfs_ivnode);
    438 	vgone(fs->lfs_ivnode);
    439 
    440 	ronly = !fs->lfs_ronly;
    441 	ump->um_devvp->v_specflags &= ~SI_MOUNTEDON;
    442 	error = VOP_CLOSE(ump->um_devvp,
    443 	    ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
    444 	vrele(ump->um_devvp);
    445 	free(fs, M_UFSMNT);
    446 	free(ump, M_UFSMNT);
    447 	mp->mnt_data = (qaddr_t)0;
    448 	mp->mnt_flag &= ~MNT_LOCAL;
    449 	return (error);
    450 }
    451 
    452 /*
    453  * Get file system statistics.
    454  */
    455 int
    456 lfs_statfs(mp, sbp, p)
    457 	struct mount *mp;
    458 	register struct statfs *sbp;
    459 	struct proc *p;
    460 {
    461 	register struct lfs *fs;
    462 	register struct ufsmount *ump;
    463 
    464 	ump = VFSTOUFS(mp);
    465 	fs = ump->um_lfs;
    466 	if (fs->lfs_magic != LFS_MAGIC)
    467 		panic("lfs_statfs: magic");
    468 	sbp->f_type = 0;
    469 	sbp->f_bsize = fs->lfs_bsize;
    470 	sbp->f_iosize = fs->lfs_bsize;
    471 	sbp->f_blocks = dbtofrags(fs, fs->lfs_dsize);
    472 	sbp->f_bfree = dbtofrags(fs, fs->lfs_bfree);
    473 	/*
    474 	 * To compute the available space.  Subtract the minimum free
    475 	 * from the total number of blocks in the file system.  Set avail
    476 	 * to the smaller of this number and fs->lfs_bfree.
    477 	 */
    478         sbp->f_bavail = (long) ((u_int64_t) fs->lfs_dsize * (u_int64_t)
    479 		(100 - fs->lfs_minfree) / (u_int64_t) 100);
    480 	sbp->f_bavail =
    481 	    sbp->f_bavail > fs->lfs_bfree ? fs->lfs_bfree : sbp->f_bavail;
    482 	sbp->f_bavail = dbtofrags(fs, sbp->f_bavail);
    483 	sbp->f_files = fs->lfs_nfiles;
    484 	sbp->f_ffree = sbp->f_bfree * INOPB(fs);
    485 	if (sbp != &mp->mnt_stat) {
    486 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
    487 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
    488 	}
    489 	strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
    490 	return (0);
    491 }
    492 
    493 /*
    494  * Go through the disk queues to initiate sandbagged IO;
    495  * go through the inodes to write those that have been modified;
    496  * initiate the writing of the super block if it has been modified.
    497  *
    498  * Note: we are always called with the filesystem marked `MPBUSY'.
    499  */
    500 int
    501 lfs_sync(mp, waitfor, cred, p)
    502 	struct mount *mp;
    503 	int waitfor;
    504 	struct ucred *cred;
    505 	struct proc *p;
    506 {
    507 	int error;
    508 
    509 	/* All syncs must be checkpoints until roll-forward is implemented. */
    510 	error = lfs_segwrite(mp, SEGM_CKP | (waitfor ? SEGM_SYNC : 0));
    511 #ifdef QUOTA
    512 	qsync(mp);
    513 #endif
    514 	return (error);
    515 }
    516 
    517 /*
    518  * Look up an LFS dinode number to find its incore vnode.  If not already
    519  * in core, read it in from the specified device.  Return the inode locked.
    520  * Detection and handling of mount points must be done by the calling routine.
    521  */
    522 int
    523 lfs_vget(mp, ino, vpp)
    524 	struct mount *mp;
    525 	ino_t ino;
    526 	struct vnode **vpp;
    527 {
    528 	register struct lfs *fs;
    529 	register struct inode *ip;
    530 	struct buf *bp;
    531 	struct ifile *ifp;
    532 	struct vnode *vp;
    533 	struct ufsmount *ump;
    534 	ufs_daddr_t daddr;
    535 	dev_t dev;
    536 	int error;
    537 
    538 	ump = VFSTOUFS(mp);
    539 	dev = ump->um_dev;
    540 	if ((*vpp = ufs_ihashget(dev, ino)) != NULL)
    541 		return (0);
    542 
    543 	/* Translate the inode number to a disk address. */
    544 	fs = ump->um_lfs;
    545 	if (ino == LFS_IFILE_INUM)
    546 		daddr = fs->lfs_idaddr;
    547 	else {
    548 		LFS_IENTRY(ifp, fs, ino, bp);
    549 		daddr = ifp->if_daddr;
    550 		brelse(bp);
    551 		if (daddr == LFS_UNUSED_DADDR)
    552 			return (ENOENT);
    553 	}
    554 
    555 	/* Allocate new vnode/inode. */
    556 	if ((error = lfs_vcreate(mp, ino, &vp)) != 0) {
    557 		*vpp = NULL;
    558 		return (error);
    559 	}
    560 
    561 	/*
    562 	 * Put it onto its hash chain and lock it so that other requests for
    563 	 * this inode will block if they arrive while we are sleeping waiting
    564 	 * for old data structures to be purged or for the contents of the
    565 	 * disk portion of this inode to be read.
    566 	 */
    567 	ip = VTOI(vp);
    568 	ufs_ihashins(ip);
    569 
    570 	/*
    571 	 * XXX
    572 	 * This may not need to be here, logically it should go down with
    573 	 * the i_devvp initialization.
    574 	 * Ask Kirk.
    575 	 */
    576 	ip->i_lfs = ump->um_lfs;
    577 
    578 	/* Read in the disk contents for the inode, copy into the inode. */
    579 	error = bread(ump->um_devvp, daddr, (int)fs->lfs_bsize, NOCRED, &bp);
    580 	if (error) {
    581 		/*
    582 		 * The inode does not contain anything useful, so it would
    583 		 * be misleading to leave it on its hash chain. With mode
    584 		 * still zero, it will be unlinked and returned to the free
    585 		 * list by vput().
    586 		 */
    587 		vput(vp);
    588 		brelse(bp);
    589 		*vpp = NULL;
    590 		return (error);
    591 	}
    592 	ip->i_din.ffs_din = *lfs_ifind(fs, ino, (struct dinode *)bp->b_data);
    593 	brelse(bp);
    594 
    595 	/*
    596 	 * Initialize the vnode from the inode, check for aliases.  In all
    597 	 * cases re-init ip, the underlying vnode/inode may have changed.
    598 	 */
    599 	error = ufs_vinit(mp, lfs_specop_p, LFS_FIFOOPS, &vp);
    600 	if (error) {
    601 		vput(vp);
    602 		*vpp = NULL;
    603 		return (error);
    604 	}
    605 	/*
    606 	 * Finish inode initialization now that aliasing has been resolved.
    607 	 */
    608 	ip->i_devvp = ump->um_devvp;
    609 	VREF(ip->i_devvp);
    610 	*vpp = vp;
    611 	return (0);
    612 }
    613 
    614 /*
    615  * File handle to vnode
    616  *
    617  * Have to be really careful about stale file handles:
    618  * - check that the inode number is valid
    619  * - call lfs_vget() to get the locked inode
    620  * - check for an unallocated inode (i_mode == 0)
    621  * - check that the given client host has export rights and return
    622  *   those rights via. exflagsp and credanonp
    623  *
    624  * XXX
    625  * use ifile to see if inode is allocated instead of reading off disk
    626  * what is the relationship between my generational number and the NFS
    627  * generational number.
    628  */
    629 int
    630 lfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
    631 	register struct mount *mp;
    632 	struct fid *fhp;
    633 	struct mbuf *nam;
    634 	struct vnode **vpp;
    635 	int *exflagsp;
    636 	struct ucred **credanonp;
    637 {
    638 	register struct ufid *ufhp;
    639 
    640 	ufhp = (struct ufid *)fhp;
    641 	if (ufhp->ufid_ino < ROOTINO)
    642 		return (ESTALE);
    643 	return (ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp));
    644 }
    645 
    646 /*
    647  * Vnode pointer to File handle
    648  */
    649 /* ARGSUSED */
    650 int
    651 lfs_vptofh(vp, fhp)
    652 	struct vnode *vp;
    653 	struct fid *fhp;
    654 {
    655 	register struct inode *ip;
    656 	register struct ufid *ufhp;
    657 
    658 	ip = VTOI(vp);
    659 	ufhp = (struct ufid *)fhp;
    660 	ufhp->ufid_len = sizeof(struct ufid);
    661 	ufhp->ufid_ino = ip->i_number;
    662 	ufhp->ufid_gen = ip->i_ffs_gen;
    663 	return (0);
    664 }
    665 
    666 int
    667 lfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    668 	int *name;
    669 	u_int namelen;
    670 	void *oldp;
    671 	size_t *oldlenp;
    672 	void *newp;
    673 	size_t newlen;
    674 	struct proc *p;
    675 {
    676 	return (EOPNOTSUPP);
    677 }
    678