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