123400Smckusick /* 266805Sbostic * Copyright (c) 1989, 1991, 1993, 1994 363375Sbostic * The Regents of the University of California. All rights reserved. 423400Smckusick * 544539Sbostic * %sccs.include.redist.c% 637737Smckusick * 7*67533Smckusick * @(#)lfs_vfsops.c 8.9 (Berkeley) 07/14/94 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/mount.h> 1751483Sbostic #include <sys/buf.h> 1854734Smckusick #include <sys/mbuf.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> 2454734Smckusick #include <sys/socket.h> 2512795Ssam 2655047Smckusick #include <miscfs/specfs/specdev.h> 2755047Smckusick 2851501Sbostic #include <ufs/ufs/quota.h> 2951501Sbostic #include <ufs/ufs/inode.h> 3051501Sbostic #include <ufs/ufs/ufsmount.h> 3151501Sbostic #include <ufs/ufs/ufs_extern.h> 3247571Skarels 3351501Sbostic #include <ufs/lfs/lfs.h> 3451501Sbostic #include <ufs/lfs/lfs_extern.h> 3551155Sbostic 3651991Sbostic int lfs_mountfs __P((struct vnode *, struct mount *, struct proc *)); 3751215Sbostic 3851155Sbostic struct vfsops lfs_vfsops = { 3951155Sbostic lfs_mount, 4039043Smckusick ufs_start, 4151155Sbostic lfs_unmount, 4266805Sbostic ufs_root, 4341314Smckusick ufs_quotactl, 4451155Sbostic lfs_statfs, 4551155Sbostic lfs_sync, 4654693Sbostic lfs_vget, 4751559Smckusick lfs_fhtovp, 4851559Smckusick lfs_vptofh, 4951483Sbostic lfs_init, 5037737Smckusick }; 5137737Smckusick 5251483Sbostic int 5351155Sbostic lfs_mountroot() 5412795Ssam { 5551483Sbostic panic("lfs_mountroot"); /* XXX -- implement */ 5637737Smckusick } 5737737Smckusick 5837737Smckusick /* 5937737Smckusick * VFS Operations. 6037737Smckusick * 6137737Smckusick * mount system call 6237737Smckusick */ 6351155Sbostic lfs_mount(mp, path, data, ndp, p) 6440346Smckusick register struct mount *mp; 6537737Smckusick char *path; 6637737Smckusick caddr_t data; 6737737Smckusick struct nameidata *ndp; 6848036Smckusick struct proc *p; 6937737Smckusick { 7037737Smckusick struct vnode *devvp; 7137737Smckusick struct ufs_args args; 7237737Smckusick struct ufsmount *ump; 7351501Sbostic register struct lfs *fs; /* LFS */ 7437737Smckusick u_int size; 7537737Smckusick int error; 76*67533Smckusick mode_t accessmode; 7737737Smckusick 7837737Smckusick if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args))) 7937737Smckusick return (error); 8051483Sbostic 8151483Sbostic /* Until LFS can do NFS right. XXX */ 8265674Shibler if (args.export.ex_flags & MNT_EXPORTED) 8351483Sbostic return (EINVAL); 8465674Shibler 8540371Smckusick /* 8650264Skarels * If updating, check whether changing from read-only to 8750264Skarels * read/write; if there is no device name, that's all we do. 8850264Skarels */ 8950264Skarels if (mp->mnt_flag & MNT_UPDATE) { 9039336Smckusick ump = VFSTOUFS(mp); 91*67533Smckusick if (fs->lfs_ronly && (mp->mnt_flag & MNT_WANTRDWR)) { 92*67533Smckusick /* 93*67533Smckusick * If upgrade to read-write by non-root, then verify 94*67533Smckusick * that user has necessary permissions on the device. 95*67533Smckusick */ 96*67533Smckusick if (p->p_ucred->cr_uid != 0) { 97*67533Smckusick VOP_LOCK(ump->um_devvp); 98*67533Smckusick if (error = VOP_ACCESS(ump->um_devvp, 99*67533Smckusick VREAD | VWRITE, p->p_ucred, p)) { 100*67533Smckusick VOP_UNLOCK(ump->um_devvp); 101*67533Smckusick return (error); 102*67533Smckusick } 103*67533Smckusick VOP_UNLOCK(ump->um_devvp); 104*67533Smckusick } 10551155Sbostic fs->lfs_ronly = 0; 106*67533Smckusick } 10752175Smckusick if (args.fspec == 0) { 10852175Smckusick /* 10952175Smckusick * Process export requests. 11052175Smckusick */ 11165674Shibler return (vfs_export(mp, &ump->um_export, &args.export)); 11252175Smckusick } 11350264Skarels } 11450264Skarels /* 11550264Skarels * Not an update, or updating the name: look up the name 11650264Skarels * and verify that it refers to a sensible block device. 11750264Skarels */ 11852333Smckusick NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p); 11952333Smckusick if (error = namei(ndp)) 12050264Skarels return (error); 12150264Skarels devvp = ndp->ni_vp; 12250264Skarels if (devvp->v_type != VBLK) { 12350264Skarels vrele(devvp); 12450264Skarels return (ENOTBLK); 12550264Skarels } 12650264Skarels if (major(devvp->v_rdev) >= nblkdev) { 12750264Skarels vrele(devvp); 12850264Skarels return (ENXIO); 12950264Skarels } 130*67533Smckusick /* 131*67533Smckusick * If mount by non-root, then verify that user has necessary 132*67533Smckusick * permissions on the device. 133*67533Smckusick */ 134*67533Smckusick if (p->p_ucred->cr_uid != 0) { 135*67533Smckusick accessmode = VREAD; 136*67533Smckusick if ((mp->mnt_flag & MNT_RDONLY) == 0) 137*67533Smckusick accessmode |= VWRITE; 138*67533Smckusick VOP_LOCK(devvp); 139*67533Smckusick if (error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) { 140*67533Smckusick vput(devvp); 141*67533Smckusick return (error); 142*67533Smckusick } 143*67533Smckusick VOP_UNLOCK(devvp); 144*67533Smckusick } 14550264Skarels if ((mp->mnt_flag & MNT_UPDATE) == 0) 14651155Sbostic error = lfs_mountfs(devvp, mp, p); /* LFS */ 14750264Skarels else { 14839336Smckusick if (devvp != ump->um_devvp) 14939336Smckusick error = EINVAL; /* needs translation */ 15042858Smckusick else 15142858Smckusick vrele(devvp); 15239336Smckusick } 15337737Smckusick if (error) { 15437737Smckusick vrele(devvp); 15537737Smckusick return (error); 15632721Smckusick } 15737737Smckusick ump = VFSTOUFS(mp); 15851155Sbostic fs = ump->um_lfs; /* LFS */ 15951155Sbostic #ifdef NOTLFS /* LFS */ 16037737Smckusick (void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size); 16137737Smckusick bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size); 16241397Smckusick bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname, 16341397Smckusick MNAMELEN); 16451991Sbostic (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, 16541397Smckusick &size); 16641397Smckusick bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 16748036Smckusick (void) ufs_statfs(mp, &mp->mnt_stat, p); 16851155Sbostic #else 16951155Sbostic (void)copyinstr(path, fs->lfs_fsmnt, sizeof(fs->lfs_fsmnt) - 1, &size); 17051155Sbostic bzero(fs->lfs_fsmnt + size, sizeof(fs->lfs_fsmnt) - size); 17151155Sbostic bcopy((caddr_t)fs->lfs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname, 17251155Sbostic MNAMELEN); 17351991Sbostic (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, 17451155Sbostic &size); 17551155Sbostic bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 17651155Sbostic (void) lfs_statfs(mp, &mp->mnt_stat, p); 17751155Sbostic #endif 17837737Smckusick return (0); 17912795Ssam } 18012795Ssam 18137737Smckusick /* 18237737Smckusick * Common code for mount and mountroot 18351155Sbostic * LFS specific 18437737Smckusick */ 18551991Sbostic int 18651155Sbostic lfs_mountfs(devvp, mp, p) 18740376Smckusick register struct vnode *devvp; 18837737Smckusick struct mount *mp; 18948036Smckusick struct proc *p; 19012795Ssam { 19151155Sbostic extern struct vnode *rootvp; 19251501Sbostic register struct lfs *fs; 19351155Sbostic register struct ufsmount *ump; 19451155Sbostic struct vnode *vp; 19551155Sbostic struct buf *bp; 19630749Skarels struct partinfo dpart; 19751155Sbostic dev_t dev; 19851155Sbostic int error, i, ronly, size; 19912795Ssam 20040376Smckusick /* 20140376Smckusick * Disallow multiple mounts of the same device. 20245652Smckusick * Disallow mounting of a device that is currently in use 20345652Smckusick * (except for root, which might share swap device for miniroot). 20440376Smckusick * Flush out any old buffers remaining from a previous use. 20540376Smckusick */ 20665674Shibler if (error = vfs_mountedon(devvp)) 20740376Smckusick return (error); 20845652Smckusick if (vcount(devvp) > 1 && devvp != rootvp) 20940376Smckusick return (EBUSY); 21066738Spendry if (error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) 21154693Sbostic return (error); 21251155Sbostic 21351155Sbostic ronly = (mp->mnt_flag & MNT_RDONLY) != 0; 21459473Smckusick if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p)) 21537737Smckusick return (error); 21651155Sbostic 21748036Smckusick if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0) 21837737Smckusick size = DEV_BSIZE; 21948036Smckusick else { 22030749Skarels size = dpart.disklab->d_secsize; 22151155Sbostic #ifdef NEVER_USED 22251155Sbostic dpart.part->p_fstype = FS_LFS; 22351155Sbostic dpart.part->p_fsize = fs->lfs_fsize; /* frag size */ 22451155Sbostic dpart.part->p_frag = fs->lfs_frag; /* frags per block */ 22551155Sbostic dpart.part->p_cpg = fs->lfs_segshift; /* segment shift */ 22651155Sbostic #endif 22737737Smckusick } 22851155Sbostic 22951155Sbostic /* Don't free random space on error. */ 23051155Sbostic bp = NULL; 23151155Sbostic ump = NULL; 23251155Sbostic 23351155Sbostic /* Read in the superblock. */ 23451155Sbostic if (error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, NOCRED, &bp)) 23512795Ssam goto out; 23664523Sbostic fs = (struct lfs *)bp->b_data; 23751155Sbostic 23851155Sbostic /* Check the basics. */ 23951155Sbostic if (fs->lfs_magic != LFS_MAGIC || fs->lfs_bsize > MAXBSIZE || 24051501Sbostic fs->lfs_bsize < sizeof(struct lfs)) { 24141314Smckusick error = EINVAL; /* XXX needs translation */ 24216639Skarels goto out; 24316639Skarels } 24451155Sbostic 24551155Sbostic /* Allocate the mount structure, copy the superblock into it. */ 24641314Smckusick ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK); 24755548Sbostic fs = ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK); 24864523Sbostic bcopy(bp->b_data, fs, sizeof(struct lfs)); 24951501Sbostic if (sizeof(struct lfs) < LFS_SBPAD) /* XXX why? */ 25039675Smckusick bp->b_flags |= B_INVAL; 25134421Skarels brelse(bp); 25234421Skarels bp = NULL; 25351155Sbostic 25451183Sbostic /* Set up the I/O information */ 25551183Sbostic fs->lfs_iocount = 0; 25651183Sbostic 25755548Sbostic /* Set up the ifile and lock aflags */ 25854264Sbostic fs->lfs_doifile = 0; 25954264Sbostic fs->lfs_writer = 0; 26054264Sbostic fs->lfs_dirops = 0; 26155548Sbostic fs->lfs_seglock = 0; 26254264Sbostic 26351155Sbostic /* Set the file system readonly/modify bits. */ 26451155Sbostic fs->lfs_ronly = ronly; 26512795Ssam if (ronly == 0) 26651155Sbostic fs->lfs_fmod = 1; 26751155Sbostic 26851155Sbostic /* Initialize the mount structure. */ 26951155Sbostic dev = devvp->v_rdev; 27041397Smckusick mp->mnt_data = (qaddr_t)ump; 27141397Smckusick mp->mnt_stat.f_fsid.val[0] = (long)dev; 27251991Sbostic mp->mnt_stat.f_fsid.val[1] = MOUNT_LFS; 27367395Smkm mp->mnt_maxsymlinklen = fs->lfs_maxsymlinklen; 27441397Smckusick mp->mnt_flag |= MNT_LOCAL; 27537737Smckusick ump->um_mountp = mp; 27637737Smckusick ump->um_dev = dev; 27737737Smckusick ump->um_devvp = devvp; 27856475Smargo ump->um_bptrtodb = 0; 27956475Smargo ump->um_seqinc = 1 << fs->lfs_fsbtodb; 28056475Smargo ump->um_nindir = fs->lfs_nindir; 28141314Smckusick for (i = 0; i < MAXQUOTAS; i++) 28241314Smckusick ump->um_quotas[i] = NULLVP; 28352221Sbostic devvp->v_specflags |= SI_MOUNTEDON; 28451155Sbostic 28552221Sbostic /* 28652221Sbostic * We use the ifile vnode for almost every operation. Instead of 28752221Sbostic * retrieving it from the hash table each time we retrieve it here, 28852221Sbostic * artificially increment the reference count and keep a pointer 28952221Sbostic * to it in the incore copy of the superblock. 29052221Sbostic */ 29154693Sbostic if (error = VFS_VGET(mp, LFS_IFILE_INUM, &vp)) 29251155Sbostic goto out; 29351155Sbostic fs->lfs_ivnode = vp; 29452221Sbostic VREF(vp); 29552221Sbostic vput(vp); 29651155Sbostic 29737737Smckusick return (0); 29812795Ssam out: 29940872Smckusick if (bp) 30040872Smckusick brelse(bp); 30151155Sbostic (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p); 30241314Smckusick if (ump) { 30351989Smckusick free(ump->um_lfs, M_UFSMNT); 30451501Sbostic free(ump, M_UFSMNT); 30541397Smckusick mp->mnt_data = (qaddr_t)0; 30632721Smckusick } 30737737Smckusick return (error); 30812795Ssam } 30912795Ssam 31039043Smckusick /* 31137737Smckusick * unmount system call 31237737Smckusick */ 31351155Sbostic lfs_unmount(mp, mntflags, p) 31437737Smckusick struct mount *mp; 31541314Smckusick int mntflags; 31648036Smckusick struct proc *p; 31712795Ssam { 31851501Sbostic extern int doforce; 31937737Smckusick register struct ufsmount *ump; 32055548Sbostic register struct lfs *fs; 32154693Sbostic int i, error, flags, ronly; 32212795Ssam 32354693Sbostic flags = 0; 32448065Smckusick if (mntflags & MNT_FORCE) { 32565240Smckusick if (!doforce || (mp->mnt_flag & MNT_ROOTFS)) 32648065Smckusick return (EINVAL); 32741314Smckusick flags |= FORCECLOSE; 32848065Smckusick } 32954264Sbostic 33054264Sbostic ump = VFSTOUFS(mp); 33154264Sbostic fs = ump->um_lfs; 33212795Ssam #ifdef QUOTA 33341397Smckusick if (mp->mnt_flag & MNT_QUOTA) { 33454264Sbostic if (error = vflush(mp, fs->lfs_ivnode, SKIPSYSTEM|flags)) 33539898Smckusick return (error); 33641314Smckusick for (i = 0; i < MAXQUOTAS; i++) { 33741314Smckusick if (ump->um_quotas[i] == NULLVP) 33841314Smckusick continue; 33950114Smckusick quotaoff(p, mp, i); 34041314Smckusick } 34139898Smckusick /* 34241314Smckusick * Here we fall through to vflush again to ensure 34341314Smckusick * that we have gotten rid of all the system vnodes. 34439898Smckusick */ 34541314Smckusick } 34612795Ssam #endif 34754693Sbostic if (error = vflush(mp, fs->lfs_ivnode, flags)) 34839898Smckusick return (error); 34955548Sbostic fs->lfs_clean = 1; 35054693Sbostic if (error = VFS_SYNC(mp, 1, p->p_ucred, p)) 35154693Sbostic return (error); 35265240Smckusick if (fs->lfs_ivnode->v_dirtyblkhd.lh_first) 35354693Sbostic panic("lfs_unmount: still dirty blocks on ifile vnode\n"); 35455806Sbostic vrele(fs->lfs_ivnode); 35554693Sbostic vgone(fs->lfs_ivnode); 35654693Sbostic 35751155Sbostic ronly = !fs->lfs_ronly; 35840653Smckusick ump->um_devvp->v_specflags &= ~SI_MOUNTEDON; 35954693Sbostic error = VOP_CLOSE(ump->um_devvp, 36054693Sbostic ronly ? FREAD : FREAD|FWRITE, NOCRED, p); 36137737Smckusick vrele(ump->um_devvp); 36251989Smckusick free(fs, M_UFSMNT); 36351501Sbostic free(ump, M_UFSMNT); 36441397Smckusick mp->mnt_data = (qaddr_t)0; 36541397Smckusick mp->mnt_flag &= ~MNT_LOCAL; 36630749Skarels return (error); 36712795Ssam } 36812795Ssam 36937737Smckusick /* 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; 38756156Smargo sbp->f_blocks = dbtofsb(fs,fs->lfs_dsize); 38855588Sbostic sbp->f_bfree = dbtofsb(fs, fs->lfs_bfree); 38951155Sbostic sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) - 39056368Smargo (fs->lfs_dsize - fs->lfs_bfree); 39156156Smargo sbp->f_bavail = dbtofsb(fs, sbp->f_bavail); 39251155Sbostic sbp->f_files = fs->lfs_nfiles; 39355588Sbostic sbp->f_ffree = sbp->f_bfree * INOPB(fs); 39441397Smckusick if (sbp != &mp->mnt_stat) { 39541397Smckusick bcopy((caddr_t)mp->mnt_stat.f_mntonname, 39640346Smckusick (caddr_t)&sbp->f_mntonname[0], MNAMELEN); 39741397Smckusick bcopy((caddr_t)mp->mnt_stat.f_mntfromname, 39840346Smckusick (caddr_t)&sbp->f_mntfromname[0], MNAMELEN); 39940346Smckusick } 40037737Smckusick return (0); 40137737Smckusick } 40237737Smckusick 40337737Smckusick /* 40437737Smckusick * Go through the disk queues to initiate sandbagged IO; 40537737Smckusick * go through the inodes to write those that have been modified; 40637737Smckusick * initiate the writing of the super block if it has been modified. 40741314Smckusick * 40841314Smckusick * Note: we are always called with the filesystem marked `MPBUSY'. 40937737Smckusick */ 41054693Sbostic lfs_sync(mp, waitfor, cred, p) 41137737Smckusick struct mount *mp; 41237737Smckusick int waitfor; 41354693Sbostic struct ucred *cred; 41454693Sbostic struct proc *p; 41537737Smckusick { 41651215Sbostic int error; 41737737Smckusick 41851310Sbostic /* All syncs must be checkpoints until roll-forward is implemented. */ 41957068Smargo error = lfs_segwrite(mp, SEGM_CKP | (waitfor ? SEGM_SYNC : 0)); 42041314Smckusick #ifdef QUOTA 42141314Smckusick qsync(mp); 42241314Smckusick #endif 42351215Sbostic return (error); 42437737Smckusick } 42551559Smckusick 42651559Smckusick /* 42754693Sbostic * Look up an LFS dinode number to find its incore vnode. If not already 42854693Sbostic * in core, read it in from the specified device. Return the inode locked. 42954693Sbostic * Detection and handling of mount points must be done by the calling routine. 43054693Sbostic */ 43154693Sbostic int 43254693Sbostic lfs_vget(mp, ino, vpp) 43354693Sbostic struct mount *mp; 43454693Sbostic ino_t ino; 43554693Sbostic struct vnode **vpp; 43654693Sbostic { 43754693Sbostic register struct lfs *fs; 43854693Sbostic register struct inode *ip; 43954693Sbostic struct buf *bp; 44054693Sbostic struct ifile *ifp; 44154693Sbostic struct vnode *vp; 44254693Sbostic struct ufsmount *ump; 44354693Sbostic daddr_t daddr; 44454693Sbostic dev_t dev; 44554693Sbostic int error; 44654693Sbostic 44754693Sbostic ump = VFSTOUFS(mp); 44854693Sbostic dev = ump->um_dev; 44954693Sbostic if ((*vpp = ufs_ihashget(dev, ino)) != NULL) 45054693Sbostic return (0); 45154693Sbostic 45254693Sbostic /* Translate the inode number to a disk address. */ 45354693Sbostic fs = ump->um_lfs; 45454693Sbostic if (ino == LFS_IFILE_INUM) 45554693Sbostic daddr = fs->lfs_idaddr; 45654693Sbostic else { 45754693Sbostic LFS_IENTRY(ifp, fs, ino, bp); 45854693Sbostic daddr = ifp->if_daddr; 45954693Sbostic brelse(bp); 46054693Sbostic if (daddr == LFS_UNUSED_DADDR) 46154693Sbostic return (ENOENT); 46254693Sbostic } 46354693Sbostic 46454693Sbostic /* Allocate new vnode/inode. */ 46554693Sbostic if (error = lfs_vcreate(mp, ino, &vp)) { 46654693Sbostic *vpp = NULL; 46754693Sbostic return (error); 46854693Sbostic } 46954693Sbostic 47054693Sbostic /* 47154693Sbostic * Put it onto its hash chain and lock it so that other requests for 47254693Sbostic * this inode will block if they arrive while we are sleeping waiting 47354693Sbostic * for old data structures to be purged or for the contents of the 47454693Sbostic * disk portion of this inode to be read. 47554693Sbostic */ 47654693Sbostic ip = VTOI(vp); 47754693Sbostic ufs_ihashins(ip); 47854693Sbostic 47954693Sbostic /* 48054693Sbostic * XXX 48154693Sbostic * This may not need to be here, logically it should go down with 48254693Sbostic * the i_devvp initialization. 48354693Sbostic * Ask Kirk. 48454693Sbostic */ 48554693Sbostic ip->i_lfs = ump->um_lfs; 48654693Sbostic 48754693Sbostic /* Read in the disk contents for the inode, copy into the inode. */ 48854693Sbostic if (error = 48954693Sbostic bread(ump->um_devvp, daddr, (int)fs->lfs_bsize, NOCRED, &bp)) { 49054693Sbostic /* 49159820Smckusick * The inode does not contain anything useful, so it would 49259820Smckusick * be misleading to leave it on its hash chain. With mode 49359820Smckusick * still zero, it will be unlinked and returned to the free 49459820Smckusick * list by vput(). 49554693Sbostic */ 49656799Smckusick vput(vp); 49754693Sbostic brelse(bp); 49854693Sbostic *vpp = NULL; 49954693Sbostic return (error); 50054693Sbostic } 50164523Sbostic ip->i_din = *lfs_ifind(fs, ino, (struct dinode *)bp->b_data); 50254693Sbostic brelse(bp); 50354693Sbostic 50454693Sbostic /* 50554693Sbostic * Initialize the vnode from the inode, check for aliases. In all 50654693Sbostic * cases re-init ip, the underlying vnode/inode may have changed. 50754693Sbostic */ 50854693Sbostic if (error = ufs_vinit(mp, lfs_specop_p, LFS_FIFOOPS, &vp)) { 50956799Smckusick vput(vp); 51054693Sbostic *vpp = NULL; 51154693Sbostic return (error); 51254693Sbostic } 51354693Sbostic /* 51454693Sbostic * Finish inode initialization now that aliasing has been resolved. 51554693Sbostic */ 51654693Sbostic ip->i_devvp = ump->um_devvp; 51754693Sbostic VREF(ip->i_devvp); 51854693Sbostic *vpp = vp; 51954693Sbostic return (0); 52054693Sbostic } 52154693Sbostic 52254693Sbostic /* 52351559Smckusick * File handle to vnode 52451559Smckusick * 52551559Smckusick * Have to be really careful about stale file handles: 52651559Smckusick * - check that the inode number is valid 52751559Smckusick * - call lfs_vget() to get the locked inode 52851559Smckusick * - check for an unallocated inode (i_mode == 0) 52955891Smckusick * - check that the given client host has export rights and return 53055891Smckusick * those rights via. exflagsp and credanonp 53151559Smckusick * 53251559Smckusick * XXX 53351559Smckusick * use ifile to see if inode is allocated instead of reading off disk 53451559Smckusick * what is the relationship between my generational number and the NFS 53551559Smckusick * generational number. 53651559Smckusick */ 53751559Smckusick int 53854734Smckusick lfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp) 53951559Smckusick register struct mount *mp; 54051559Smckusick struct fid *fhp; 54154734Smckusick struct mbuf *nam; 54251559Smckusick struct vnode **vpp; 54354734Smckusick int *exflagsp; 54454734Smckusick struct ucred **credanonp; 54551559Smckusick { 54651559Smckusick register struct ufid *ufhp; 54751559Smckusick 54851559Smckusick ufhp = (struct ufid *)fhp; 54951559Smckusick if (ufhp->ufid_ino < ROOTINO) 55054734Smckusick return (ESTALE); 55156246Smckusick return (ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp)); 55251559Smckusick } 55351559Smckusick 55451559Smckusick /* 55551559Smckusick * Vnode pointer to File handle 55651559Smckusick */ 55751559Smckusick /* ARGSUSED */ 55851559Smckusick lfs_vptofh(vp, fhp) 55951559Smckusick struct vnode *vp; 56051559Smckusick struct fid *fhp; 56151559Smckusick { 56251559Smckusick register struct inode *ip; 56351559Smckusick register struct ufid *ufhp; 56451559Smckusick 56551559Smckusick ip = VTOI(vp); 56651559Smckusick ufhp = (struct ufid *)fhp; 56751559Smckusick ufhp->ufid_len = sizeof(struct ufid); 56851559Smckusick ufhp->ufid_ino = ip->i_number; 56951559Smckusick ufhp->ufid_gen = ip->i_gen; 57051559Smckusick return (0); 57151559Smckusick } 572