-
-/*
- * Remove any inodes in the inode cache belonging to dev.
- *
- * There should not be any active ones, return error if any are found
- * (nb: this is a user error, not a system err).
- */
-#ifdef QUOTA
-iflush(dev, iq)
- dev_t dev;
- struct inode *iq;
-#else
-iflush(dev)
- dev_t dev;
-#endif
-{
- register struct inode *ip;
-
- for (ip = inode; ip < inodeNINODE; ip++) {
-#ifdef QUOTA
- if (ip != iq && ip->i_dev == dev)
-#else
- if (ip->i_dev == dev)
-#endif
- if (ITOV(ip)->v_count)
- return (EBUSY);
- else {
- remque(ip);
- ip->i_forw = ip;
- ip->i_back = ip;
- /*
- * as v_count == 0, the inode was on the free
- * list already, just leave it there, it will
- * fall off the bottom eventually. We could
- * perhaps move it to the head of the free
- * list, but as umounts are done so
- * infrequently, we would gain very little,
- * while making the code bigger.
- */
-#ifdef QUOTA
- dqrele(ip->i_dquot);
- ip->i_dquot = NODQUOT;
-#endif
- if (ip->i_devvp) {
- vrele(ip->i_devvp);
- ip->i_devvp = 0;
- }
- }
- }
- return (0);
-}
-
-/*
- * Lock an inode. If its already locked, set the WANT bit and sleep.
- */
-ilock(ip)
- register struct inode *ip;
-{
-
- while (ip->i_flag & ILOCKED) {
- ip->i_flag |= IWANT;
- (void) sleep((caddr_t)ip, PINOD);
- }
- ip->i_flag |= ILOCKED;
-}
-
-/*
- * Unlock an inode. If WANT bit is on, wakeup.
- */
-iunlock(ip)
- register struct inode *ip;
-{
-
- if ((ip->i_flag & ILOCKED) == 0)
- printf("unlocking unlocked inode %d on dev 0x%x\n",
- ip->i_number, ip->i_dev);
- ip->i_flag &= ~ILOCKED;
- if (ip->i_flag&IWANT) {
- ip->i_flag &= ~IWANT;
- wakeup((caddr_t)ip);
- }
-}
-
-/*
- * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
- * The mode is shifted to select the owner/group/other fields. The
- * super user is granted all permissions.
- *
- * NB: Called from vnode op table. It seems this could all be done
- * using vattr's but...
- */
-iaccess(ip, mode, cred)
- register struct inode *ip;
- register int mode;
- struct ucred *cred;
-{
- register gid_t *gp;
- register struct vnode *vp = ITOV(ip);
- int i;
-
- /*
- * If you're the super-user,
- * you always get access.
- */
- if (cred->cr_uid == 0)
- return (0);
- /*
- * Access check is based on only one of owner, group, public.
- * If not owner, then check group. If not a member of the
- * group, then check public access.
- */
- if (cred->cr_uid != ip->i_uid) {
- mode >>= 3;
- gp = cred->cr_groups;
- for (i = 0; i < cred->cr_ngroups; i++, gp++)
- if (ip->i_gid == *gp)
- goto found;
- mode >>= 3;
-found:
- ;
- }
- if ((ip->i_mode & mode) != 0)
- return (0);
- return (EACCES);
-}