fix check for LINK_MAX in ufs_link;
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 4 Feb 1991 14:32:50 +0000 (06:32 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 4 Feb 1991 14:32:50 +0000 (06:32 -0800)
add check for LINK_MAX in ufs_mkdir and ufs_rename

SCCS-vsn: sys/ufs/ffs/ffs_vnops.c 7.52
SCCS-vsn: sys/ufs/ffs/ufs_vnops.c 7.52
SCCS-vsn: sys/ufs/lfs/lfs_vnops.c 7.52
SCCS-vsn: sys/ufs/ufs/ufs_vnops.c 7.52

usr/src/sys/ufs/ffs/ffs_vnops.c
usr/src/sys/ufs/ffs/ufs_vnops.c
usr/src/sys/ufs/lfs/lfs_vnops.c
usr/src/sys/ufs/ufs/ufs_vnops.c

index 0d32449..ea2552e 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ffs_vnops.c 7.51 (Berkeley) %G%
+ *     @(#)ffs_vnops.c 7.52 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -849,18 +849,15 @@ ufs_link(vp, ndp)
        register struct inode *ip = VTOI(vp);
        int error;
 
        register struct inode *ip = VTOI(vp);
        int error;
 
+       if ((unsigned short)ip->i_nlink >= LINK_MAX)
+               return (EMLINK);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
-       if (ip->i_nlink == LINK_MAX - 1) {
-               error = EMLINK;
-               goto out;
-       }
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
-out:
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
@@ -995,9 +992,14 @@ ufs_rename(fndp, tndp)
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
+                       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+                               error = EMLINK;
+                               goto bad;
+                       }
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
-                       error = iupdat(dp, &time, &time, 1);
+                       if (error = iupdat(dp, &time, &time, 1))
+                               goto bad;
                }
                if (error = direnter(ip, tndp))
                        goto out;
                }
                if (error = direnter(ip, tndp))
                        goto out;
@@ -1187,6 +1189,10 @@ ufs_mkdir(ndp, vap)
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
+       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+               iput(dp);
+               return (EMLINK);
+       }
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*
index 87abfe7..99f804b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ufs_vnops.c 7.51 (Berkeley) %G%
+ *     @(#)ufs_vnops.c 7.52 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -849,18 +849,15 @@ ufs_link(vp, ndp)
        register struct inode *ip = VTOI(vp);
        int error;
 
        register struct inode *ip = VTOI(vp);
        int error;
 
+       if ((unsigned short)ip->i_nlink >= LINK_MAX)
+               return (EMLINK);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
-       if (ip->i_nlink == LINK_MAX - 1) {
-               error = EMLINK;
-               goto out;
-       }
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
-out:
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
@@ -995,9 +992,14 @@ ufs_rename(fndp, tndp)
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
+                       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+                               error = EMLINK;
+                               goto bad;
+                       }
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
-                       error = iupdat(dp, &time, &time, 1);
+                       if (error = iupdat(dp, &time, &time, 1))
+                               goto bad;
                }
                if (error = direnter(ip, tndp))
                        goto out;
                }
                if (error = direnter(ip, tndp))
                        goto out;
@@ -1187,6 +1189,10 @@ ufs_mkdir(ndp, vap)
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
+       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+               iput(dp);
+               return (EMLINK);
+       }
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*
index 9d4d4c2..3fbf2b4 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_vnops.c 7.51 (Berkeley) %G%
+ *     @(#)lfs_vnops.c 7.52 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -849,18 +849,15 @@ ufs_link(vp, ndp)
        register struct inode *ip = VTOI(vp);
        int error;
 
        register struct inode *ip = VTOI(vp);
        int error;
 
+       if ((unsigned short)ip->i_nlink >= LINK_MAX)
+               return (EMLINK);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
-       if (ip->i_nlink == LINK_MAX - 1) {
-               error = EMLINK;
-               goto out;
-       }
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
-out:
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
@@ -995,9 +992,14 @@ ufs_rename(fndp, tndp)
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
+                       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+                               error = EMLINK;
+                               goto bad;
+                       }
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
-                       error = iupdat(dp, &time, &time, 1);
+                       if (error = iupdat(dp, &time, &time, 1))
+                               goto bad;
                }
                if (error = direnter(ip, tndp))
                        goto out;
                }
                if (error = direnter(ip, tndp))
                        goto out;
@@ -1187,6 +1189,10 @@ ufs_mkdir(ndp, vap)
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
+       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+               iput(dp);
+               return (EMLINK);
+       }
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*
index 87abfe7..99f804b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ufs_vnops.c 7.51 (Berkeley) %G%
+ *     @(#)ufs_vnops.c 7.52 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -849,18 +849,15 @@ ufs_link(vp, ndp)
        register struct inode *ip = VTOI(vp);
        int error;
 
        register struct inode *ip = VTOI(vp);
        int error;
 
+       if ((unsigned short)ip->i_nlink >= LINK_MAX)
+               return (EMLINK);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
        if (ndp->ni_dvp != vp)
                ILOCK(ip);
-       if (ip->i_nlink == LINK_MAX - 1) {
-               error = EMLINK;
-               goto out;
-       }
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        error = iupdat(ip, &time, &time, 1);
        if (!error)
                error = direnter(ip, ndp);
-out:
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        if (error) {
@@ -995,9 +992,14 @@ ufs_rename(fndp, tndp)
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
+                       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+                               error = EMLINK;
+                               goto bad;
+                       }
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;
-                       error = iupdat(dp, &time, &time, 1);
+                       if (error = iupdat(dp, &time, &time, 1))
+                               goto bad;
                }
                if (error = direnter(ip, tndp))
                        goto out;
                }
                if (error = direnter(ip, tndp))
                        goto out;
@@ -1187,6 +1189,10 @@ ufs_mkdir(ndp, vap)
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
 
        dvp = ndp->ni_dvp;
        dp = VTOI(dvp);
+       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+               iput(dp);
+               return (EMLINK);
+       }
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*
        dmode = vap->va_mode&0777;
        dmode |= IFDIR;
        /*