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*51559Smckusick * @(#)lfs_vfsops.c 7.64 (Berkeley) 11/05/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, 39*51559Smckusick lfs_root, 4041314Smckusick ufs_quotactl, 4151155Sbostic lfs_statfs, 4251155Sbostic lfs_sync, 43*51559Smckusick lfs_fhtovp, 44*51559Smckusick 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); 23551501Sbostic ump->um_lfs = malloc(sizeof(struct lfs), M_SUPERBLK, 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; 24451183Sbostic 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. */ 265*51559Smckusick /* XXX Why not just lfs_vget?? */ 266*51559Smckusick if (error = bread(devvp, fs->lfs_idaddr, fs->lfs_bsize, NOCRED, &bp)) 26751155Sbostic goto out; 268*51559Smckusick if (error = lfs_vcreate(mp, LFS_IFILE_INUM, &vp)) 26951155Sbostic goto out; 27051155Sbostic ip = VTOI(vp); 271*51559Smckusick VREF(ip->i_devvp); 27251155Sbostic 27351155Sbostic /* The ifile inode is stored in the superblock. */ 27451155Sbostic fs->lfs_ivnode = vp; 27551155Sbostic 27651155Sbostic /* Copy the on-disk inode into place. */ 27751155Sbostic ip->i_din = *lfs_ifind(fs, LFS_IFILE_INUM, bp->b_un.b_dino); 27851155Sbostic brelse(bp); 27951155Sbostic 28051155Sbostic /* Initialize the associated vnode */ 28151155Sbostic vp->v_type = IFTOVT(ip->i_mode); 28251155Sbostic 28351155Sbostic /* 28451155Sbostic * Read in the segusage table. 28551155Sbostic * 28651155Sbostic * Since we always explicitly write the segusage table at a checkpoint, 28751155Sbostic * we're assuming that it is continguous on disk. 28851155Sbostic */ 28951155Sbostic seg_addr = ip->i_din.di_db[0]; 29051155Sbostic size = fs->lfs_segtabsz << fs->lfs_bshift; 29151155Sbostic fs->lfs_segtab = malloc(size, M_SUPERBLK, M_WAITOK); 292*51559Smckusick if (error = bread(devvp, seg_addr, size, NOCRED, &bp)) { 29351155Sbostic free(fs->lfs_segtab, M_SUPERBLK); 29451155Sbostic goto out; 29551155Sbostic } 29651155Sbostic bcopy((caddr_t)bp->b_un.b_addr, fs->lfs_segtab, size); 29751155Sbostic brelse(bp); 29840653Smckusick devvp->v_specflags |= SI_MOUNTEDON; 29951155Sbostic VREF(ip->i_devvp); 30037737Smckusick return (0); 30112795Ssam out: 30240872Smckusick if (bp) 30340872Smckusick brelse(bp); 30451155Sbostic (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p); 30541314Smckusick if (ump) { 30651501Sbostic free(ump->um_lfs, M_SUPERBLK); 30751501Sbostic free(ump, M_UFSMNT); 30841397Smckusick mp->mnt_data = (qaddr_t)0; 30932721Smckusick } 31037737Smckusick return (error); 31112795Ssam } 31212795Ssam 31339043Smckusick /* 31437737Smckusick * unmount system call 31537737Smckusick */ 31651155Sbostic lfs_unmount(mp, mntflags, p) 31737737Smckusick struct mount *mp; 31841314Smckusick int mntflags; 31948036Smckusick struct proc *p; 32012795Ssam { 32151501Sbostic extern int doforce; 32237737Smckusick register struct ufsmount *ump; 32351501Sbostic register struct lfs *fs; /* LFS */ 32441314Smckusick int i, error, ronly, flags = 0; 32551215Sbostic int ndirty; /* LFS */ 32612795Ssam 32751155Sbostic printf("lfs_unmount\n"); 32848065Smckusick if (mntflags & MNT_FORCE) { 32948359Smckusick if (!doforce || mp == rootfs) 33048065Smckusick return (EINVAL); 33141314Smckusick flags |= FORCECLOSE; 33248065Smckusick } 33351215Sbostic if (error = lfs_segwrite(mp, 1)) 33451215Sbostic return(error); 33551215Sbostic 33651215Sbostic ndirty = lfs_umountdebug(mp); 33751215Sbostic printf("lfs_umountdebug: returned %d dirty\n", ndirty); 33851215Sbostic return(0); 33939675Smckusick if (mntinvalbuf(mp)) 34039675Smckusick return (EBUSY); 34137737Smckusick ump = VFSTOUFS(mp); 34212795Ssam #ifdef QUOTA 34341397Smckusick if (mp->mnt_flag & MNT_QUOTA) { 34441314Smckusick if (error = vflush(mp, NULLVP, SKIPSYSTEM|flags)) 34539898Smckusick return (error); 34641314Smckusick for (i = 0; i < MAXQUOTAS; i++) { 34741314Smckusick if (ump->um_quotas[i] == NULLVP) 34841314Smckusick continue; 34950114Smckusick quotaoff(p, mp, i); 35041314Smckusick } 35139898Smckusick /* 35241314Smckusick * Here we fall through to vflush again to ensure 35341314Smckusick * that we have gotten rid of all the system vnodes. 35439898Smckusick */ 35541314Smckusick } 35612795Ssam #endif 35741314Smckusick if (error = vflush(mp, NULLVP, flags)) 35839898Smckusick return (error); 35951155Sbostic #ifdef NOTLFS /* LFS */ 36037737Smckusick fs = ump->um_fs; 36137737Smckusick ronly = !fs->fs_ronly; 36251155Sbostic #else 36351155Sbostic fs = ump->um_lfs; 36451155Sbostic ronly = !fs->lfs_ronly; 36551155Sbostic #endif 36640653Smckusick ump->um_devvp->v_specflags &= ~SI_MOUNTEDON; 36748036Smckusick error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD|FWRITE, 36848036Smckusick NOCRED, p); 36937737Smckusick vrele(ump->um_devvp); 37051155Sbostic #ifdef NOTLFS /* LFS */ 37141314Smckusick free((caddr_t)fs->fs_csp[0], M_SUPERBLK); 37251155Sbostic #else 37351155Sbostic free(fs->lfs_segtab, M_SUPERBLK); 37451155Sbostic iput(VTOI(fs->lfs_ivnode)); 37551155Sbostic #endif 37651501Sbostic free(fs, M_SUPERBLK); 37751501Sbostic free(ump, M_UFSMNT); 37841397Smckusick mp->mnt_data = (qaddr_t)0; 37941397Smckusick mp->mnt_flag &= ~MNT_LOCAL; 38030749Skarels return (error); 38112795Ssam } 38212795Ssam 38337737Smckusick /* 384*51559Smckusick * Return root of a filesystem 385*51559Smckusick */ 386*51559Smckusick int 387*51559Smckusick lfs_root(mp, vpp) 388*51559Smckusick struct mount *mp; 389*51559Smckusick struct vnode **vpp; 390*51559Smckusick { 391*51559Smckusick struct vnode *nvp; 392*51559Smckusick int error; 393*51559Smckusick 394*51559Smckusick if (error = lfs_vget(mp, (ino_t)ROOTINO, &nvp)) 395*51559Smckusick return (error); 396*51559Smckusick *vpp = nvp; 397*51559Smckusick return (0); 398*51559Smckusick } 399*51559Smckusick 400*51559Smckusick /* 40137737Smckusick * Get file system statistics. 40237737Smckusick */ 40351155Sbostic lfs_statfs(mp, sbp, p) 40437737Smckusick struct mount *mp; 40537737Smckusick register struct statfs *sbp; 40648036Smckusick struct proc *p; 40737737Smckusick { 40851501Sbostic register struct lfs *fs; 40937737Smckusick register struct ufsmount *ump; 41037737Smckusick 41137737Smckusick ump = VFSTOUFS(mp); 41251155Sbostic #ifdef NOTLFS /* LFS */ 41337737Smckusick fs = ump->um_fs; 41437737Smckusick if (fs->fs_magic != FS_MAGIC) 41537737Smckusick panic("ufs_statfs"); 41637737Smckusick sbp->f_type = MOUNT_UFS; 41737737Smckusick sbp->f_fsize = fs->fs_fsize; 41837737Smckusick sbp->f_bsize = fs->fs_bsize; 41937737Smckusick sbp->f_blocks = fs->fs_dsize; 42037737Smckusick sbp->f_bfree = fs->fs_cstotal.cs_nbfree * fs->fs_frag + 42137737Smckusick fs->fs_cstotal.cs_nffree; 42237737Smckusick sbp->f_bavail = (fs->fs_dsize * (100 - fs->fs_minfree) / 100) - 42337737Smckusick (fs->fs_dsize - sbp->f_bfree); 42439350Smckusick sbp->f_files = fs->fs_ncg * fs->fs_ipg - ROOTINO; 42537737Smckusick sbp->f_ffree = fs->fs_cstotal.cs_nifree; 42651155Sbostic #else 42751155Sbostic fs = ump->um_lfs; 42851155Sbostic if (fs->lfs_magic != LFS_MAGIC) 42951155Sbostic panic("lfs_statfs: magic"); 43051155Sbostic sbp->f_type = MOUNT_LFS; 43151155Sbostic sbp->f_fsize = fs->lfs_bsize; 43251155Sbostic sbp->f_bsize = fs->lfs_bsize; 43351155Sbostic sbp->f_blocks = fs->lfs_dsize; 43451155Sbostic sbp->f_bfree = fs->lfs_bfree; 43551155Sbostic sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) - 43651155Sbostic (fs->lfs_dsize - sbp->f_bfree); 43751155Sbostic sbp->f_files = fs->lfs_nfiles; 43851155Sbostic sbp->f_ffree = fs->lfs_bfree * INOPB(fs); 43951155Sbostic #endif 44041397Smckusick if (sbp != &mp->mnt_stat) { 44141397Smckusick bcopy((caddr_t)mp->mnt_stat.f_mntonname, 44240346Smckusick (caddr_t)&sbp->f_mntonname[0], MNAMELEN); 44341397Smckusick bcopy((caddr_t)mp->mnt_stat.f_mntfromname, 44440346Smckusick (caddr_t)&sbp->f_mntfromname[0], MNAMELEN); 44540346Smckusick } 44637737Smckusick return (0); 44737737Smckusick } 44837737Smckusick 44937737Smckusick /* 45037737Smckusick * Go through the disk queues to initiate sandbagged IO; 45137737Smckusick * go through the inodes to write those that have been modified; 45237737Smckusick * initiate the writing of the super block if it has been modified. 45341314Smckusick * 45441314Smckusick * Note: we are always called with the filesystem marked `MPBUSY'. 45537737Smckusick */ 45651155Sbostic lfs_sync(mp, waitfor) 45737737Smckusick struct mount *mp; 45837737Smckusick int waitfor; 45937737Smckusick { 46051483Sbostic extern int syncprt; 46151310Sbostic static int sync_lock, sync_want; 46251215Sbostic int error; 46337737Smckusick 46451155Sbostic printf("lfs_sync\n"); 46551215Sbostic 46651215Sbostic /* 46751310Sbostic * Meta data blocks are only marked dirty, not busy, so LFS syncs 46851310Sbostic * must be single threaded. 46951215Sbostic */ 47051310Sbostic while (sync_lock) { 47151310Sbostic sync_want = 1; 47251310Sbostic if (error = tsleep(&sync_lock, PLOCK | PCATCH, "lfs sync", 0)) 47351310Sbostic return (error); 47451310Sbostic } 47551310Sbostic sync_lock = 1; 47651215Sbostic 47737737Smckusick if (syncprt) 47851483Sbostic ufs_bufstats(); 47951310Sbostic 48051310Sbostic /* All syncs must be checkpoints until roll-forward is implemented. */ 48151215Sbostic error = lfs_segwrite(mp, 1); 48241314Smckusick #ifdef QUOTA 48341314Smckusick qsync(mp); 48441314Smckusick #endif 48551310Sbostic sync_lock = 0; 48651310Sbostic if (sync_want) { 48751310Sbostic sync_want = 0; 48851310Sbostic wakeup(&sync_lock); 48951310Sbostic } 49051215Sbostic return (error); 49137737Smckusick } 492*51559Smckusick 493*51559Smckusick /* 494*51559Smckusick * File handle to vnode 495*51559Smckusick * 496*51559Smckusick * Have to be really careful about stale file handles: 497*51559Smckusick * - check that the inode number is valid 498*51559Smckusick * - call lfs_vget() to get the locked inode 499*51559Smckusick * - check for an unallocated inode (i_mode == 0) 500*51559Smckusick * - check that the generation number matches 501*51559Smckusick * 502*51559Smckusick * XXX 503*51559Smckusick * use ifile to see if inode is allocated instead of reading off disk 504*51559Smckusick * what is the relationship between my generational number and the NFS 505*51559Smckusick * generational number. 506*51559Smckusick */ 507*51559Smckusick int 508*51559Smckusick lfs_fhtovp(mp, fhp, vpp) 509*51559Smckusick register struct mount *mp; 510*51559Smckusick struct fid *fhp; 511*51559Smckusick struct vnode **vpp; 512*51559Smckusick { 513*51559Smckusick register struct inode *ip; 514*51559Smckusick register struct ufid *ufhp; 515*51559Smckusick struct vnode *nvp; 516*51559Smckusick int error; 517*51559Smckusick 518*51559Smckusick ufhp = (struct ufid *)fhp; 519*51559Smckusick if (ufhp->ufid_ino < ROOTINO) 520*51559Smckusick return (EINVAL); 521*51559Smckusick if (error = lfs_vget(mp, ufhp->ufid_ino, &nvp)) { 522*51559Smckusick *vpp = NULLVP; 523*51559Smckusick return (error); 524*51559Smckusick } 525*51559Smckusick ip = VTOI(nvp); 526*51559Smckusick if (ip->i_mode == 0) { 527*51559Smckusick ufs_iput(ip); 528*51559Smckusick *vpp = NULLVP; 529*51559Smckusick return (EINVAL); 530*51559Smckusick } 531*51559Smckusick if (ip->i_gen != ufhp->ufid_gen) { 532*51559Smckusick ufs_iput(ip); 533*51559Smckusick *vpp = NULLVP; 534*51559Smckusick return (EINVAL); 535*51559Smckusick } 536*51559Smckusick *vpp = nvp; 537*51559Smckusick return (0); 538*51559Smckusick } 539*51559Smckusick 540*51559Smckusick /* 541*51559Smckusick * Vnode pointer to File handle 542*51559Smckusick */ 543*51559Smckusick /* ARGSUSED */ 544*51559Smckusick lfs_vptofh(vp, fhp) 545*51559Smckusick struct vnode *vp; 546*51559Smckusick struct fid *fhp; 547*51559Smckusick { 548*51559Smckusick register struct inode *ip; 549*51559Smckusick register struct ufid *ufhp; 550*51559Smckusick 551*51559Smckusick ip = VTOI(vp); 552*51559Smckusick ufhp = (struct ufid *)fhp; 553*51559Smckusick ufhp->ufid_len = sizeof(struct ufid); 554*51559Smckusick ufhp->ufid_ino = ip->i_number; 555*51559Smckusick ufhp->ufid_gen = ip->i_gen; 556*51559Smckusick return (0); 557*51559Smckusick } 558