]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/hfs/hfs_link.c
xnu-1228.12.14.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_link.c
index f6c5e8409a82dd48ffe799fdbbf3a03f217cde2e..ba47918e3f261dd7bd680a59519403d12f4db171 100644 (file)
@@ -438,6 +438,25 @@ hfs_vnop_link(struct vnop_link_args *ap)
        }
        tdcp = VTOC(tdvp);
        cp = VTOC(vp);
+       
+       /*
+        * Make sure we don't race the src or dst parent directories with rmdir.
+        * Note that we should only have a src parent directory cnode lock 
+        * if we're dealing with a directory hardlink here.
+        */
+       if (fdcp) {
+               if (fdcp->c_flag & (C_NOEXISTS | C_DELETED)) {
+                       error = ENOENT;
+                       goto out;
+               }
+       }
+       
+       if (tdcp->c_flag & (C_NOEXISTS | C_DELETED)) {
+               error = ENOENT;
+               goto out;
+       }
+       
+       /* Check src for errors: too many links, immutable, race with unlink */
        if (cp->c_linkcount >= HFS_LINK_MAX) {
                error = EMLINK;
                goto out;