]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/hfs/hfs_btreeio.c
xnu-1699.32.7.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_btreeio.c
index 7e592c9828e68ca3f61282688d55e0e5a05f948f..f69c780c08ac76292e0ec23c8f2624dacfafcd3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -53,8 +53,30 @@ extern int bdwrite_internal(struct buf *, int);
 static int ClearBTNodes(struct vnode *vp, long blksize, off_t offset, off_t amount);
 static int btree_journal_modify_block_end(struct hfsmount *hfsmp, struct buf *bp);
 
+void btree_swap_node(struct buf *bp, __unused void *arg);
+
+/* 
+ * Return btree node size for given vnode.
+ *
+ * Returns: 
+ *     For btree vnode, returns btree node size. 
+ *     For non-btree vnodes, returns 0.
+ */
+u_int16_t get_btree_nodesize(struct vnode *vp)
+{
+       BTreeControlBlockPtr btree;
+       u_int16_t node_size = 0; 
+
+       if (vnode_issystem(vp)) {
+               btree = (BTreeControlBlockPtr) VTOF(vp)->fcbBTCBPtr;
+               if (btree) {
+                       node_size = btree->nodeSize;
+               }
+       }
+
+       return node_size;
+}
 
-__private_extern__
 OSStatus SetBTreeBlockSize(FileReference vp, ByteCount blockSize, __unused ItemCount minBlockCount)
 {
        BTreeControlBlockPtr    bTreePtr;
@@ -71,7 +93,6 @@ OSStatus SetBTreeBlockSize(FileReference vp, ByteCount blockSize, __unused ItemC
 }
 
 
-__private_extern__
 OSStatus GetBTreeBlock(FileReference vp, u_int32_t blockNum, GetBlockOptions options, BlockDescriptor *block)
 {
     OSStatus    retval = E_NONE;
@@ -165,7 +186,6 @@ OSStatus GetBTreeBlock(FileReference vp, u_int32_t blockNum, GetBlockOptions opt
 }
 
 
-__private_extern__
 void ModifyBlockStart(FileReference vp, BlockDescPtr blockPtr)
 {
        struct hfsmount *hfsmp = VTOHFS(vp);
@@ -185,7 +205,7 @@ void ModifyBlockStart(FileReference vp, BlockDescPtr blockPtr)
        blockPtr->isModified = 1;
 }
 
-static void
+void
 btree_swap_node(struct buf *bp, __unused void *arg)
 {
     // struct hfsmount *hfsmp = (struct hfsmount *)arg;
@@ -218,7 +238,6 @@ btree_journal_modify_block_end(struct hfsmount *hfsmp, struct buf *bp)
 }
 
 
-__private_extern__
 OSStatus ReleaseBTreeBlock(FileReference vp, BlockDescPtr blockPtr, ReleaseBlockOptions options)
 {
     struct hfsmount    *hfsmp = VTOHFS(vp);
@@ -240,6 +259,10 @@ OSStatus ReleaseBTreeBlock(FileReference vp, BlockDescPtr blockPtr, ReleaseBlock
                } else {
                        buf_brelse(bp); /* note: B-tree code will clear blockPtr->blockHeader and blockPtr->buffer */
                }
+               
+               /* Don't let anyone else try to use this bp, it's been consumed */
+               blockPtr->blockHeader = NULL;
+               
     } else {
         if (options & kForceWriteBlock) {
                        if (hfsmp->jnl) {
@@ -252,6 +275,10 @@ OSStatus ReleaseBTreeBlock(FileReference vp, BlockDescPtr blockPtr, ReleaseBlock
                        } else {
                                retval = VNOP_BWRITE(bp);
                        }
+                       
+                       /* Don't let anyone else try to use this bp, it's been consumed */
+                       blockPtr->blockHeader = NULL;
+                       
         } else if (options & kMarkBlockDirty) {
                        struct timeval tv;
                        microuptime(&tv);
@@ -292,6 +319,10 @@ OSStatus ReleaseBTreeBlock(FileReference vp, BlockDescPtr blockPtr, ReleaseBlock
                 buf_clearflags(bp, B_LOCKED);
                 buf_bawrite(bp);
             }
+            
+            /* Don't let anyone else try to use this bp, it's been consumed */
+                       blockPtr->blockHeader = NULL;
+                       
         } else {
                        // check if we had previously called journal_modify_block_start() 
                        // on this block and if so, abort it (which will call buf_brelse()).
@@ -308,15 +339,17 @@ OSStatus ReleaseBTreeBlock(FileReference vp, BlockDescPtr blockPtr, ReleaseBlock
                        } else {
                                buf_brelse(bp); /* note: B-tree code will clear blockPtr->blockHeader and blockPtr->buffer */
                        }
-        };
-    };
+                       
+                       /* Don't let anyone else try to use this bp, it's been consumed */
+                       blockPtr->blockHeader = NULL;
+        }
+    }
 
 exit:
     return (retval);
 }
 
 
-__private_extern__
 OSStatus ExtendBTreeFile(FileReference vp, FSSize minEOF, FSSize maxEOF)
 {
 #pragma unused (maxEOF)
@@ -452,7 +485,7 @@ OSStatus ExtendBTreeFile(FileReference vp, FSSize minEOF, FSSize maxEOF)
                        trim = ((filePtr->fcbEOF - origSize) % btInfo.nodeSize);
                }
 
-               ret = TruncateFileC(vcb, filePtr, filePtr->fcbEOF - trim, 0);
+               ret = TruncateFileC(vcb, filePtr, filePtr->fcbEOF - trim, 0, 0, FTOC(filePtr)->c_fileid, 0);
                filePtr->fcbEOF = (u_int64_t)filePtr->ff_blocks * (u_int64_t)vcb->blockSize;
 
                // XXXdbg - panic if the file didn't get trimmed back properly
@@ -596,6 +629,8 @@ hfs_create_attr_btree(struct hfsmount *hfsmp, u_int32_t nodesize, u_int32_t node
        u_int16_t  offset;
        int intrans = 0;
        int result;
+       int newvnode_flags = 0;
+       
 again:
        /*
         * Serialize creation using HFS_CREATING_BTREE flag.
@@ -639,7 +674,8 @@ again:
        bzero(&cfork, sizeof(cfork));
        cfork.cf_clump = nodesize * nodecnt;
 
-       result = hfs_getnewvnode(hfsmp, NULL, NULL, &cndesc, 0, &cnattr, &cfork, &vp);
+       result = hfs_getnewvnode(hfsmp, NULL, NULL, &cndesc, 0, &cnattr, 
+                                                        &cfork, &vp, &newvnode_flags);
        if (result) {
                goto exit;
        }