]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/hfs/hfs_vnops.c
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_vnops.c
index 59c278f109475b27909707c3cb8d18f292bb6c1c..726dee5e0ff0e378e3dbb3fb0d83c83dee92dd57 100644 (file)
@@ -289,7 +289,7 @@ hfs_vnop_getattr(struct vnop_getattr_args *ap)
                        if (vnode_isvroot(vp)) {
                                if (hfsmp->hfs_privdir_desc.cd_cnid != 0)
                                        --entries;     /* hide private dir */
                        if (vnode_isvroot(vp)) {
                                if (hfsmp->hfs_privdir_desc.cd_cnid != 0)
                                        --entries;     /* hide private dir */
-                               if (hfsmp->jnl)
+                               if (hfsmp->jnl || ((HFSTOVCB(hfsmp)->vcbAtrb & kHFSVolumeJournaledMask) && (hfsmp->hfs_flags & HFS_READ_ONLY)))
                                        entries -= 2;  /* hide the journal files */
                        }
                        VATTR_RETURN(vap, va_nlink, (uint64_t)entries);
                                        entries -= 2;  /* hide the journal files */
                        }
                        VATTR_RETURN(vap, va_nlink, (uint64_t)entries);
@@ -1565,18 +1565,17 @@ hfs_removefile(struct vnode *dvp, struct vnode *vp, struct componentname *cnp,
        if ((cp->c_flag & C_HARDLINK) == 0 &&
            (!dataforkbusy || !rsrcforkbusy)) {
                /*
        if ((cp->c_flag & C_HARDLINK) == 0 &&
            (!dataforkbusy || !rsrcforkbusy)) {
                /*
-                * A ubc_setsize can cause a pagein here 
-                * so we need to the drop cnode lock. Note
-                * that we still hold the truncate lock.
+                * A ubc_setsize can cause a pagein so defer it
+                * until after the cnode lock is dropped.  The
+                * cnode lock cannot be dropped/reacquired here
+                * since we might already hold the journal lock.
                 */
                 */
-               hfs_unlock(cp);
                if (!dataforkbusy && cp->c_datafork->ff_blocks && !isbigfile) {
                if (!dataforkbusy && cp->c_datafork->ff_blocks && !isbigfile) {
-                       ubc_setsize(vp, 0);
+                       cp->c_flag |= C_NEED_DATA_SETSIZE;
                }
                if (!rsrcforkbusy && rvp) {
                }
                if (!rsrcforkbusy && rvp) {
-                       ubc_setsize(rvp, 0);
+                       cp->c_flag |= C_NEED_RSRC_SETSIZE;
                }
                }
-               hfs_lock(cp, HFS_FORCE_LOCK);
        } else {
            struct cat_desc cndesc;
 
        } else {
            struct cat_desc cndesc;
 
@@ -1890,6 +1889,10 @@ out:
 __private_extern__ void
 replace_desc(struct cnode *cp, struct cat_desc *cdp)
 {
 __private_extern__ void
 replace_desc(struct cnode *cp, struct cat_desc *cdp)
 {
+       if (&cp->c_desc == cdp) {
+               return;
+       }
+
        /* First release allocated name buffer */
        if (cp->c_desc.cd_flags & CD_HASBUF && cp->c_desc.cd_nameptr != 0) {
                char *name = cp->c_desc.cd_nameptr;
        /* First release allocated name buffer */
        if (cp->c_desc.cd_flags & CD_HASBUF && cp->c_desc.cd_nameptr != 0) {
                char *name = cp->c_desc.cd_nameptr;
@@ -2825,7 +2828,7 @@ hfs_update(struct vnode *vp, __unused int waitfor)
         * we have to do the update.
         */
        if (ISSET(cp->c_flag, C_FORCEUPDATE) == 0 &&
         * we have to do the update.
         */
        if (ISSET(cp->c_flag, C_FORCEUPDATE) == 0 &&
-           (ISSET(cp->c_flag, C_DELETED) || 
+           (ISSET(cp->c_flag, C_DELETED) ||
            (dataforkp && cp->c_datafork->ff_unallocblocks) ||
            (rsrcforkp && cp->c_rsrcfork->ff_unallocblocks))) {
        //      cp->c_flag &= ~(C_ACCESS | C_CHANGE | C_UPDATE);
            (dataforkp && cp->c_datafork->ff_unallocblocks) ||
            (rsrcforkp && cp->c_rsrcfork->ff_unallocblocks))) {
        //      cp->c_flag &= ~(C_ACCESS | C_CHANGE | C_UPDATE);
@@ -3167,6 +3170,22 @@ hfs_vgetrsrc(struct hfsmount *hfsmp, struct vnode *vp, struct vnode **rvpp, __un
                struct componentname cn;
                int lockflags;
 
                struct componentname cn;
                int lockflags;
 
+               /*
+                * Make sure cnode lock is exclusive, if not upgrade it.
+                *
+                * We assume that we were called from a read-only VNOP (getattr)
+                * and that its safe to have the cnode lock dropped and reacquired.
+                */
+               if (cp->c_lockowner != current_thread()) {
+                       /*
+                        * If the upgrade fails we loose the lock and
+                        * have to take the exclusive lock on our own.
+                        */
+                       if (lck_rw_lock_shared_to_exclusive(&cp->c_rwlock) != 0)
+                               lck_rw_lock_exclusive(&cp->c_rwlock);
+                       cp->c_lockowner = current_thread();
+               }
+
                lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK);
 
                /* Get resource fork data */
                lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK);
 
                /* Get resource fork data */
@@ -3693,7 +3712,6 @@ struct vnodeopv_entry_desc hfs_specop_entries[] = {
        { &vnop_pathconf_desc, (VOPFUNC)spec_pathconf },                /* pathconf */
        { &vnop_advlock_desc, (VOPFUNC)err_advlock },           /* advlock */
        { &vnop_bwrite_desc, (VOPFUNC)hfs_vnop_bwrite },
        { &vnop_pathconf_desc, (VOPFUNC)spec_pathconf },                /* pathconf */
        { &vnop_advlock_desc, (VOPFUNC)err_advlock },           /* advlock */
        { &vnop_bwrite_desc, (VOPFUNC)hfs_vnop_bwrite },
-       { &vnop_devblocksize_desc, (VOPFUNC)spec_devblocksize }, /* devblocksize */
        { &vnop_pagein_desc, (VOPFUNC)hfs_vnop_pagein },                /* Pagein */
        { &vnop_pageout_desc, (VOPFUNC)hfs_vnop_pageout },      /* Pageout */
         { &vnop_copyfile_desc, (VOPFUNC)err_copyfile },                /* copyfile */
        { &vnop_pagein_desc, (VOPFUNC)hfs_vnop_pagein },                /* Pagein */
        { &vnop_pageout_desc, (VOPFUNC)hfs_vnop_pageout },      /* Pageout */
         { &vnop_copyfile_desc, (VOPFUNC)err_copyfile },                /* copyfile */