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*51989Smckusick * @(#)lfs_vfsops.c 7.68 (Berkeley) 12/16/91 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 3351483Sbostic static 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 /* 8040371Smckusick * Process export requests. 8140371Smckusick */ 8241397Smckusick if ((args.exflags & MNT_EXPORTED) || (mp->mnt_flag & MNT_EXPORTED)) { 8341397Smckusick if (args.exflags & MNT_EXPORTED) 8441397Smckusick mp->mnt_flag |= MNT_EXPORTED; 8540371Smckusick else 8641397Smckusick mp->mnt_flag &= ~MNT_EXPORTED; 8741397Smckusick if (args.exflags & MNT_EXRDONLY) 8841397Smckusick mp->mnt_flag |= MNT_EXRDONLY; 8940371Smckusick else 9041397Smckusick mp->mnt_flag &= ~MNT_EXRDONLY; 9141397Smckusick mp->mnt_exroot = args.exroot; 9240371Smckusick } 9350264Skarels /* 9450264Skarels * If updating, check whether changing from read-only to 9550264Skarels * read/write; if there is no device name, that's all we do. 9650264Skarels */ 9750264Skarels if (mp->mnt_flag & MNT_UPDATE) { 9839336Smckusick ump = VFSTOUFS(mp); 9951155Sbostic #ifdef NOTLFS /* LFS */ 10039336Smckusick fs = ump->um_fs; 10141397Smckusick if (fs->fs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0) 10239336Smckusick fs->fs_ronly = 0; 10351155Sbostic #else 10451155Sbostic fs = ump->um_lfs; 10551155Sbostic if (fs->lfs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0) 10651155Sbostic fs->lfs_ronly = 0; 10751155Sbostic #endif 10840371Smckusick if (args.fspec == 0) 10940371Smckusick return (0); 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); 14841397Smckusick (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); 15751155Sbostic (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 */ 16951155Sbostic static 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 inode *ip; 17951155Sbostic struct vnode *vp; 18051155Sbostic struct buf *bp; 18130749Skarels struct partinfo dpart; 18251155Sbostic daddr_t seg_addr; 18351155Sbostic dev_t dev; 18451155Sbostic int error, i, ronly, size; 18512795Ssam 18640376Smckusick /* 18740376Smckusick * Disallow multiple mounts of the same device. 18845652Smckusick * Disallow mounting of a device that is currently in use 18945652Smckusick * (except for root, which might share swap device for miniroot). 19040376Smckusick * Flush out any old buffers remaining from a previous use. 19140376Smckusick */ 19251483Sbostic if (error = ufs_mountedon(devvp)) 19340376Smckusick return (error); 19445652Smckusick if (vcount(devvp) > 1 && devvp != rootvp) 19540376Smckusick return (EBUSY); 19640376Smckusick vinvalbuf(devvp, 1); 19751155Sbostic 19851155Sbostic ronly = (mp->mnt_flag & MNT_RDONLY) != 0; 19948036Smckusick if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p)) 20037737Smckusick return (error); 20151155Sbostic 20248036Smckusick if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0) 20337737Smckusick size = DEV_BSIZE; 20448036Smckusick else { 20530749Skarels size = dpart.disklab->d_secsize; 20651155Sbostic #ifdef NEVER_USED 20751155Sbostic dpart.part->p_fstype = FS_LFS; 20851155Sbostic dpart.part->p_fsize = fs->lfs_fsize; /* frag size */ 20951155Sbostic dpart.part->p_frag = fs->lfs_frag; /* frags per block */ 21051155Sbostic dpart.part->p_cpg = fs->lfs_segshift; /* segment shift */ 21151155Sbostic #endif 21237737Smckusick } 21351155Sbostic 21451155Sbostic /* Don't free random space on error. */ 21551155Sbostic bp = NULL; 21651155Sbostic ump = NULL; 21751155Sbostic 21851155Sbostic /* Read in the superblock. */ 21951155Sbostic if (error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, NOCRED, &bp)) 22012795Ssam goto out; 22151155Sbostic fs = bp->b_un.b_lfs; 22251155Sbostic 22351155Sbostic /* Check the basics. */ 22451155Sbostic if (fs->lfs_magic != LFS_MAGIC || fs->lfs_bsize > MAXBSIZE || 22551501Sbostic fs->lfs_bsize < sizeof(struct lfs)) { 22641314Smckusick error = EINVAL; /* XXX needs translation */ 22716639Skarels goto out; 22816639Skarels } 22951155Sbostic #ifdef DEBUG 23051483Sbostic lfs_dump_super(fs); 23151155Sbostic #endif 23251155Sbostic 23351155Sbostic /* Allocate the mount structure, copy the superblock into it. */ 23441314Smckusick ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK); 235*51989Smckusick ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK); 23651501Sbostic bcopy(bp->b_un.b_addr, ump->um_lfs, sizeof(struct lfs)); 23751501Sbostic if (sizeof(struct lfs) < LFS_SBPAD) /* XXX why? */ 23839675Smckusick bp->b_flags |= B_INVAL; 23934421Skarels brelse(bp); 24034421Skarels bp = NULL; 24151155Sbostic 24251183Sbostic /* Set up the I/O information */ 24351183Sbostic fs->lfs_iocount = 0; 24451853Sbostic /* XXX NOTUSED: fs->lfs_seglist = NULL; */ 24551183Sbostic 24651155Sbostic /* Set the file system readonly/modify bits. */ 24751155Sbostic fs = ump->um_lfs; 24851155Sbostic fs->lfs_ronly = ronly; 24912795Ssam if (ronly == 0) 25051155Sbostic fs->lfs_fmod = 1; 25151155Sbostic 25251155Sbostic /* Initialize the mount structure. */ 25351155Sbostic dev = devvp->v_rdev; 25441397Smckusick mp->mnt_data = (qaddr_t)ump; 25541397Smckusick mp->mnt_stat.f_fsid.val[0] = (long)dev; 25651155Sbostic mp->mnt_stat.f_fsid.val[1] = MOUNT_LFS; 25741397Smckusick mp->mnt_flag |= MNT_LOCAL; 25837737Smckusick ump->um_mountp = mp; 25937737Smckusick ump->um_dev = dev; 26037737Smckusick ump->um_devvp = devvp; 26141314Smckusick for (i = 0; i < MAXQUOTAS; i++) 26241314Smckusick ump->um_quotas[i] = NULLVP; 26351155Sbostic 26451155Sbostic /* Read the ifile disk inode and store it in a vnode. */ 26551559Smckusick if (error = bread(devvp, fs->lfs_idaddr, fs->lfs_bsize, NOCRED, &bp)) 26651155Sbostic goto out; 26751559Smckusick if (error = lfs_vcreate(mp, LFS_IFILE_INUM, &vp)) 26851155Sbostic goto out; 26951155Sbostic ip = VTOI(vp); 27051559Smckusick VREF(ip->i_devvp); 27151155Sbostic 27251155Sbostic /* The ifile inode is stored in the superblock. */ 27351155Sbostic fs->lfs_ivnode = vp; 27451155Sbostic 27551155Sbostic /* Copy the on-disk inode into place. */ 27651155Sbostic ip->i_din = *lfs_ifind(fs, LFS_IFILE_INUM, bp->b_un.b_dino); 27751155Sbostic brelse(bp); 27851155Sbostic 27951155Sbostic /* Initialize the associated vnode */ 28051155Sbostic vp->v_type = IFTOVT(ip->i_mode); 28151155Sbostic 28240653Smckusick devvp->v_specflags |= SI_MOUNTEDON; 28351155Sbostic VREF(ip->i_devvp); 28437737Smckusick return (0); 28512795Ssam out: 28640872Smckusick if (bp) 28740872Smckusick brelse(bp); 28851155Sbostic (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p); 28941314Smckusick if (ump) { 290*51989Smckusick free(ump->um_lfs, M_UFSMNT); 29151501Sbostic free(ump, M_UFSMNT); 29241397Smckusick mp->mnt_data = (qaddr_t)0; 29332721Smckusick } 29437737Smckusick return (error); 29512795Ssam } 29612795Ssam 29739043Smckusick /* 29837737Smckusick * unmount system call 29937737Smckusick */ 30051155Sbostic lfs_unmount(mp, mntflags, p) 30137737Smckusick struct mount *mp; 30241314Smckusick int mntflags; 30348036Smckusick struct proc *p; 30412795Ssam { 30551501Sbostic extern int doforce; 30637737Smckusick register struct ufsmount *ump; 30751501Sbostic register struct lfs *fs; /* LFS */ 30841314Smckusick int i, error, ronly, flags = 0; 30951215Sbostic int ndirty; /* LFS */ 31012795Ssam 31151853Sbostic #ifdef VERBOSE 31251853Sbostic printf("lfs_unmount\n"); 31351853Sbostic #endif 31448065Smckusick if (mntflags & MNT_FORCE) { 31548359Smckusick if (!doforce || mp == rootfs) 31648065Smckusick return (EINVAL); 31741314Smckusick flags |= FORCECLOSE; 31848065Smckusick } 31951215Sbostic if (error = lfs_segwrite(mp, 1)) 32051215Sbostic return(error); 32151215Sbostic 32251215Sbostic ndirty = lfs_umountdebug(mp); 32351215Sbostic printf("lfs_umountdebug: returned %d dirty\n", ndirty); 32451215Sbostic return(0); 32539675Smckusick if (mntinvalbuf(mp)) 32639675Smckusick return (EBUSY); 32737737Smckusick ump = VFSTOUFS(mp); 32812795Ssam #ifdef QUOTA 32941397Smckusick if (mp->mnt_flag & MNT_QUOTA) { 33041314Smckusick if (error = vflush(mp, NULLVP, SKIPSYSTEM|flags)) 33139898Smckusick return (error); 33241314Smckusick for (i = 0; i < MAXQUOTAS; i++) { 33341314Smckusick if (ump->um_quotas[i] == NULLVP) 33441314Smckusick continue; 33550114Smckusick quotaoff(p, mp, i); 33641314Smckusick } 33739898Smckusick /* 33841314Smckusick * Here we fall through to vflush again to ensure 33941314Smckusick * that we have gotten rid of all the system vnodes. 34039898Smckusick */ 34141314Smckusick } 34212795Ssam #endif 34341314Smckusick if (error = vflush(mp, NULLVP, flags)) 34439898Smckusick return (error); 34551155Sbostic #ifdef NOTLFS /* LFS */ 34637737Smckusick fs = ump->um_fs; 34737737Smckusick ronly = !fs->fs_ronly; 34851155Sbostic #else 34951155Sbostic fs = ump->um_lfs; 35051155Sbostic ronly = !fs->lfs_ronly; 35151155Sbostic #endif 35240653Smckusick ump->um_devvp->v_specflags &= ~SI_MOUNTEDON; 35348036Smckusick error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD|FWRITE, 35448036Smckusick NOCRED, p); 35537737Smckusick vrele(ump->um_devvp); 35651155Sbostic #ifdef NOTLFS /* LFS */ 357*51989Smckusick free((caddr_t)fs->fs_csp[0], M_UFSMNT); 35851155Sbostic #else 35951155Sbostic iput(VTOI(fs->lfs_ivnode)); 36051155Sbostic #endif 361*51989Smckusick free(fs, M_UFSMNT); 36251501Sbostic free(ump, M_UFSMNT); 36341397Smckusick mp->mnt_data = (qaddr_t)0; 36441397Smckusick mp->mnt_flag &= ~MNT_LOCAL; 36530749Skarels return (error); 36612795Ssam } 36712795Ssam 36837737Smckusick /* 36951559Smckusick * Return root of a filesystem 37051559Smckusick */ 37151559Smckusick int 37251559Smckusick lfs_root(mp, vpp) 37351559Smckusick struct mount *mp; 37451559Smckusick struct vnode **vpp; 37551559Smckusick { 37651559Smckusick struct vnode *nvp; 37751559Smckusick int error; 37851559Smckusick 37951853Sbostic #ifdef VERBOSE 38051853Sbostic printf("lfs_root\n"); 38151853Sbostic #endif 38251559Smckusick if (error = lfs_vget(mp, (ino_t)ROOTINO, &nvp)) 38351559Smckusick return (error); 38451559Smckusick *vpp = nvp; 38551559Smckusick return (0); 38651559Smckusick } 38751559Smckusick 38851559Smckusick /* 38937737Smckusick * Get file system statistics. 39037737Smckusick */ 39151155Sbostic lfs_statfs(mp, sbp, p) 39237737Smckusick struct mount *mp; 39337737Smckusick register struct statfs *sbp; 39448036Smckusick struct proc *p; 39537737Smckusick { 39651501Sbostic register struct lfs *fs; 39737737Smckusick register struct ufsmount *ump; 39837737Smckusick 39937737Smckusick ump = VFSTOUFS(mp); 40051155Sbostic fs = ump->um_lfs; 40151155Sbostic if (fs->lfs_magic != LFS_MAGIC) 40251155Sbostic panic("lfs_statfs: magic"); 40351155Sbostic sbp->f_type = MOUNT_LFS; 40451155Sbostic sbp->f_bsize = fs->lfs_bsize; 40551943Smckusick sbp->f_iosize = fs->lfs_bsize; 40651155Sbostic sbp->f_blocks = fs->lfs_dsize; 40751155Sbostic sbp->f_bfree = fs->lfs_bfree; 40851155Sbostic sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) - 40951155Sbostic (fs->lfs_dsize - sbp->f_bfree); 41051155Sbostic sbp->f_files = fs->lfs_nfiles; 41151155Sbostic sbp->f_ffree = fs->lfs_bfree * INOPB(fs); 41241397Smckusick if (sbp != &mp->mnt_stat) { 41341397Smckusick bcopy((caddr_t)mp->mnt_stat.f_mntonname, 41440346Smckusick (caddr_t)&sbp->f_mntonname[0], MNAMELEN); 41541397Smckusick bcopy((caddr_t)mp->mnt_stat.f_mntfromname, 41640346Smckusick (caddr_t)&sbp->f_mntfromname[0], MNAMELEN); 41740346Smckusick } 41837737Smckusick return (0); 41937737Smckusick } 42037737Smckusick 42137737Smckusick /* 42237737Smckusick * Go through the disk queues to initiate sandbagged IO; 42337737Smckusick * go through the inodes to write those that have been modified; 42437737Smckusick * initiate the writing of the super block if it has been modified. 42541314Smckusick * 42641314Smckusick * Note: we are always called with the filesystem marked `MPBUSY'. 42737737Smckusick */ 42851155Sbostic lfs_sync(mp, waitfor) 42937737Smckusick struct mount *mp; 43037737Smckusick int waitfor; 43137737Smckusick { 43251914Sbostic extern int crashandburn, syncprt; 43351310Sbostic static int sync_lock, sync_want; 43451215Sbostic int error; 43537737Smckusick 43651853Sbostic #ifdef VERBOSE 43751853Sbostic printf("lfs_sync\n"); 43851853Sbostic #endif 43951215Sbostic 44051914Sbostic #ifdef DIAGNOSTIC 44151914Sbostic if (crashandburn) 44251914Sbostic return (0); 44351914Sbostic #endif 44451215Sbostic /* 44551310Sbostic * Meta data blocks are only marked dirty, not busy, so LFS syncs 44651310Sbostic * must be single threaded. 44751215Sbostic */ 44851310Sbostic while (sync_lock) { 44951310Sbostic sync_want = 1; 45051310Sbostic if (error = tsleep(&sync_lock, PLOCK | PCATCH, "lfs sync", 0)) 45151310Sbostic return (error); 45251310Sbostic } 45351310Sbostic sync_lock = 1; 45451215Sbostic 45537737Smckusick if (syncprt) 45651483Sbostic ufs_bufstats(); 45751310Sbostic 45851310Sbostic /* All syncs must be checkpoints until roll-forward is implemented. */ 45951215Sbostic error = lfs_segwrite(mp, 1); 46041314Smckusick #ifdef QUOTA 46141314Smckusick qsync(mp); 46241314Smckusick #endif 46351310Sbostic sync_lock = 0; 46451310Sbostic if (sync_want) { 46551310Sbostic sync_want = 0; 46651310Sbostic wakeup(&sync_lock); 46751310Sbostic } 46851215Sbostic return (error); 46937737Smckusick } 47051559Smckusick 47151559Smckusick /* 47251559Smckusick * File handle to vnode 47351559Smckusick * 47451559Smckusick * Have to be really careful about stale file handles: 47551559Smckusick * - check that the inode number is valid 47651559Smckusick * - call lfs_vget() to get the locked inode 47751559Smckusick * - check for an unallocated inode (i_mode == 0) 47851559Smckusick * - check that the generation number matches 47951559Smckusick * 48051559Smckusick * XXX 48151559Smckusick * use ifile to see if inode is allocated instead of reading off disk 48251559Smckusick * what is the relationship between my generational number and the NFS 48351559Smckusick * generational number. 48451559Smckusick */ 48551559Smckusick int 48651559Smckusick lfs_fhtovp(mp, fhp, vpp) 48751559Smckusick register struct mount *mp; 48851559Smckusick struct fid *fhp; 48951559Smckusick struct vnode **vpp; 49051559Smckusick { 49151559Smckusick register struct inode *ip; 49251559Smckusick register struct ufid *ufhp; 49351559Smckusick struct vnode *nvp; 49451559Smckusick int error; 49551559Smckusick 49651559Smckusick ufhp = (struct ufid *)fhp; 49751559Smckusick if (ufhp->ufid_ino < ROOTINO) 49851559Smckusick return (EINVAL); 49951559Smckusick if (error = lfs_vget(mp, ufhp->ufid_ino, &nvp)) { 50051559Smckusick *vpp = NULLVP; 50151559Smckusick return (error); 50251559Smckusick } 50351559Smckusick ip = VTOI(nvp); 50451559Smckusick if (ip->i_mode == 0) { 50551559Smckusick ufs_iput(ip); 50651559Smckusick *vpp = NULLVP; 50751559Smckusick return (EINVAL); 50851559Smckusick } 50951559Smckusick if (ip->i_gen != ufhp->ufid_gen) { 51051559Smckusick ufs_iput(ip); 51151559Smckusick *vpp = NULLVP; 51251559Smckusick return (EINVAL); 51351559Smckusick } 51451559Smckusick *vpp = nvp; 51551559Smckusick return (0); 51651559Smckusick } 51751559Smckusick 51851559Smckusick /* 51951559Smckusick * Vnode pointer to File handle 52051559Smckusick */ 52151559Smckusick /* ARGSUSED */ 52251559Smckusick lfs_vptofh(vp, fhp) 52351559Smckusick struct vnode *vp; 52451559Smckusick struct fid *fhp; 52551559Smckusick { 52651559Smckusick register struct inode *ip; 52751559Smckusick register struct ufid *ufhp; 52851559Smckusick 52951559Smckusick ip = VTOI(vp); 53051559Smckusick ufhp = (struct ufid *)fhp; 53151559Smckusick ufhp->ufid_len = sizeof(struct ufid); 53251559Smckusick ufhp->ufid_ino = ip->i_number; 53351559Smckusick ufhp->ufid_gen = ip->i_gen; 53451559Smckusick return (0); 53551559Smckusick } 536