-/*
- * Allocate a new inode.
- *
- * Put it onto its hash chain and lock it so that other requests for
- * this inode will block if they arrive while we are sleeping waiting
- * for old data structures to be purged or for the contents of the disk
- * portion of this inode to be read.
- */
-getnewino(dev, ino, mp, ipp)
- dev_t dev;
- ino_t ino;
- struct mount *mp;
- struct inode **ipp;
-{
- union ihead *ih;
- register struct inode *ip;
- struct vnode *vp;
- int error;
-
- if (error = getnewvnode(VT_UFS, mp, &ufs_vnodeops, &vp))
- return (error);
- ip = VTOI(vp);
- ip->i_vnode = vp;
- ip->i_flag = 0;
- ip->i_devvp = 0;
- ip->i_lastr = 0;
- ip->i_mode = 0;
-#ifdef QUOTA
- ip->i_dquot = NODQUOT;
-#endif
- /*
- * Put the inode on the chain for its new (ino, dev) pair.
- */
- ip->i_dev = dev;
- ip->i_number = ino;
- if (dev != NODEV) {
- ih = &ihead[INOHASH(dev, ino)];
- insque(ip, ih);
- } else {
- ip->i_forw = ip;
- ip->i_back = ip;
- }
- ILOCK(ip);
- *ipp = ip;
- return (0);
-}
-
-/*
- * Convert a pointer to an inode into a reference to an inode.
- *
- * This is basically the internal piece of iget (after the
- * inode pointer is located) but without the test for mounted
- * filesystems. It is caller's responsibility to check that
- * the inode pointer is valid.
- */
-igrab(ip)
- register struct inode *ip;
-{
- register struct vnode *vp = ITOV(ip);
-
- while ((ip->i_flag&ILOCKED) != 0) {
- ip->i_flag |= IWANT;
- sleep((caddr_t)ip, PINOD);
- }
- if (vp->v_count == 0) /* ino on free list */
- vget(vp);
- else
- VREF(vp);
- ILOCK(ip);
-}
-
-/*
- * Create a vnode for a block device.
- * Used for root filesystem, argdev, and swap areas.
- */
-bdevvp(dev, vpp)
- dev_t dev;
- struct vnode **vpp;
-{
- register struct inode *ip;
- register struct vnode *vp;
- struct inode *nip;
- int error;
-
- /*
- * Check for the existence of an existing vnode.
- */
-again:
- for (ip = bdevlisth; ip; ip = ip->i_devlst) {
- vp = ITOV(ip);
- if (dev != vp->v_rdev)
- continue;
- igrab(ip);
- if (dev != vp->v_rdev) {
- iput(ip);
- goto again;
- }
- IUNLOCK(ip);
- *vpp = vp;
- return (0);
- }
- if (error = getnewino(NODEV, (ino_t)0, (struct mount *)0, &nip)) {
- *vpp = 0;
- return (error);
- }
- ip = nip;
- ip->i_fs = 0;
- ip->i_devlst = bdevlisth;
- bdevlisth = ip;
- vp = ITOV(ip);
- vp->v_type = VBLK;
- vp->v_op = &blk_vnodeops;
- vp->v_rdev = dev;
- IUNLOCK(ip);
- *vpp = vp;
- return (0);
-}
-