-
-/*
- * Print out statistics on the current allocation of the buffer pool.
- * Can be enabled to print out on every ``sync'' by setting "syncprt"
- * above.
- */
-bufstats()
-{
- int s, i, j, count;
- register struct buf *bp, *dp;
- int counts[MAXBSIZE/CLBYTES+1];
- static char *bname[BQUEUES] = { "LOCKED", "LRU", "AGE", "EMPTY" };
-
- for (bp = bfreelist, i = 0; bp < &bfreelist[BQUEUES]; bp++, i++) {
- count = 0;
- for (j = 0; j <= MAXBSIZE/CLBYTES; j++)
- counts[j] = 0;
- s = splbio();
- for (dp = bp->av_forw; dp != bp; dp = dp->av_forw) {
- counts[dp->b_bufsize/CLBYTES]++;
- count++;
- }
- splx(s);
- printf("%s: total-%d", bname[i], count);
- for (j = 0; j <= MAXBSIZE/CLBYTES; j++)
- if (counts[j] != 0)
- printf(", %d-%d", j * CLBYTES, counts[j]);
- printf("\n");
- }
-}
-
-/*
- * File handle to vnode
- *
- * Have to be really careful about stale file handles:
- * - check that the inode number is in range
- * - call iget() to get the locked inode
- * - check for an unallocated inode (i_mode == 0)
- * - check that the generation number matches
- */
-ufs_fhtovp(mp, fhp, vpp)
- register struct mount *mp;
- struct fid *fhp;
- struct vnode **vpp;
-{
- register struct ufid *ufhp;
- register struct fs *fs;
- register struct inode *ip;
- struct inode *nip;
- struct vnode tvp;
- int error;
-
- ufhp = (struct ufid *)fhp;
- fs = VFSTOUFS(mp)->um_fs;
- if (ufhp->ufid_ino < ROOTINO ||
- ufhp->ufid_ino >= fs->fs_ncg * fs->fs_ipg) {
- *vpp = NULLVP;
- return (EINVAL);
- }
- tvp.v_mount = mp;
- ip = VTOI(&tvp);
- ip->i_vnode = &tvp;
- ip->i_dev = VFSTOUFS(mp)->um_dev;
- if (error = iget(ip, ufhp->ufid_ino, &nip)) {
- *vpp = NULLVP;
- return (error);
- }
- ip = nip;
- if (ip->i_mode == 0) {
- iput(ip);
- *vpp = NULLVP;
- return (EINVAL);
- }
- if (ip->i_gen != ufhp->ufid_gen) {
- iput(ip);
- *vpp = NULLVP;
- return (EINVAL);
- }
- *vpp = ITOV(ip);
- return (0);
-}
-
-/*
- * Vnode pointer to File handle
- */
-/* ARGSUSED */
-ufs_vptofh(vp, fhp)
- struct vnode *vp;
- struct fid *fhp;
-{
- register struct inode *ip = VTOI(vp);
- register struct ufid *ufhp;
-
- ufhp = (struct ufid *)fhp;
- ufhp->ufid_len = sizeof(struct ufid);
- ufhp->ufid_ino = ip->i_number;
- ufhp->ufid_gen = ip->i_gen;
- return (0);
-}
-
-/*
- * Common code for mount and quota.
- * Check that the user's argument is a reasonable
- * thing on which to mount, and return the device number if so.
- */
-getmdev(devvpp, fname, ndp)
- struct vnode **devvpp;
- caddr_t fname;
- register struct nameidata *ndp;
-{
- register struct vnode *vp;
- int error;
-
- ndp->ni_nameiop = LOOKUP | LOCKLEAF | FOLLOW;
- ndp->ni_segflg = UIO_USERSPACE;
- ndp->ni_dirp = fname;
- if (error = namei(ndp)) {
- if (error == ENOENT)
- return (ENODEV); /* needs translation */
- return (error);
- }
- vp = ndp->ni_vp;
- if (vp->v_type != VBLK) {
- vput(vp);
- return (ENOTBLK);
- }
- if (major(vp->v_rdev) >= nblkdev) {
- vput(vp);
- return (ENXIO);
- }
- iunlock(VTOI(vp));
- *devvpp = vp;
- return (0);
-}