2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <sys/param.h>
30 #include <sys/systm.h>
32 #include <sys/buf_internal.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/mount.h>
36 #include <sys/vnode.h>
40 #include "hfs_cnode.h"
42 #include "hfs_endian.h"
43 #include "hfs_btreeio.h"
45 #include "hfscommon/headers/FileMgrInternal.h"
46 #include "hfscommon/headers/BTreesPrivate.h"
48 #define FORCESYNCBTREEWRITES 0
50 /* From bsd/vfs/vfs_bio.c */
51 extern int bdwrite_internal(struct buf
*, int);
53 static int ClearBTNodes(struct vnode
*vp
, long blksize
, off_t offset
, off_t amount
);
54 static int btree_journal_modify_block_end(struct hfsmount
*hfsmp
, struct buf
*bp
);
58 OSStatus
SetBTreeBlockSize(FileReference vp
, ByteCount blockSize
, __unused ItemCount minBlockCount
)
60 BTreeControlBlockPtr bTreePtr
;
62 DBG_ASSERT(vp
!= NULL
);
63 DBG_ASSERT(blockSize
>= kMinNodeSize
);
64 if (blockSize
> MAXBSIZE
)
65 return (fsBTBadNodeSize
);
67 bTreePtr
= (BTreeControlBlockPtr
)VTOF(vp
)->fcbBTCBPtr
;
68 bTreePtr
->nodeSize
= blockSize
;
75 OSStatus
GetBTreeBlock(FileReference vp
, u_int32_t blockNum
, GetBlockOptions options
, BlockDescriptor
*block
)
77 OSStatus retval
= E_NONE
;
78 struct buf
*bp
= NULL
;
80 if (options
& kGetEmptyBlock
) {
84 offset
= (daddr64_t
)blockNum
* (daddr64_t
)block
->blockSize
;
85 bp
= buf_getblk(vp
, (daddr64_t
)blockNum
, block
->blockSize
, 0, 0, BLK_META
);
87 VNOP_BLOCKMAP(vp
, offset
, block
->blockSize
, &blkno
, NULL
, NULL
, 0, NULL
) == 0) {
88 buf_setblkno(bp
, blkno
);
91 retval
= buf_meta_bread(vp
, (daddr64_t
)blockNum
, block
->blockSize
, NOCRED
, &bp
);
94 retval
= -1; //XXX need better error
96 if (retval
== E_NONE
) {
97 block
->blockHeader
= bp
;
98 block
->buffer
= (char *)buf_dataptr(bp
);
99 block
->blockNum
= buf_lblkno(bp
);
100 block
->blockReadFromDisk
= (buf_fromcache(bp
) == 0); /* not found in cache ==> came from disk */
103 block
->isModified
= 0;
105 /* Check and endian swap B-Tree node (only if it's a valid block) */
106 if (!(options
& kGetEmptyBlock
)) {
107 /* This happens when we first open the b-tree, we might not have all the node data on hand */
108 if ((((BTNodeDescriptor
*)block
->buffer
)->kind
== kBTHeaderNode
) &&
109 (((BTHeaderRec
*)((char *)block
->buffer
+ 14))->nodeSize
!= buf_count(bp
)) &&
110 (SWAP_BE16 (((BTHeaderRec
*)((char *)block
->buffer
+ 14))->nodeSize
) != buf_count(bp
))) {
113 * Don't swap the node descriptor, record offsets, or other records.
114 * This record will be invalidated and re-read with the correct node
115 * size once the B-tree control block is set up with the node size
116 * from the header record.
118 retval
= hfs_swap_BTNode (block
, vp
, kSwapBTNodeHeaderRecordOnly
);
120 } else if (block
->blockReadFromDisk
) {
122 * The node was just read from disk, so always swap/check it.
123 * This is necessary on big endian since the test below won't trigger.
125 retval
= hfs_swap_BTNode (block
, vp
, kSwapBTNodeBigToHost
);
126 } else if (*((u_int16_t
*)((char *)block
->buffer
+ (block
->blockSize
- sizeof (u_int16_t
)))) == 0x0e00) {
128 * The node was left in the cache in non-native order, so swap it.
129 * This only happens on little endian, after the node is written
132 retval
= hfs_swap_BTNode (block
, vp
, kSwapBTNodeBigToHost
);
136 * If we got an error, then the node is only partially swapped.
137 * We mark the buffer invalid so that the next attempt to get the
138 * node will read it and attempt to swap again, and will notice
139 * the error again. If we didn't do this, the next attempt to get
140 * the node might use the partially swapped node as-is.
150 block
->blockHeader
= NULL
;
151 block
->buffer
= NULL
;
159 void ModifyBlockStart(FileReference vp
, BlockDescPtr blockPtr
)
161 struct hfsmount
*hfsmp
= VTOHFS(vp
);
162 struct buf
*bp
= NULL
;
164 if (hfsmp
->jnl
== NULL
) {
168 bp
= (struct buf
*) blockPtr
->blockHeader
;
170 panic("ModifyBlockStart: null bp for blockdescptr %p?!?\n", blockPtr
);
174 journal_modify_block_start(hfsmp
->jnl
, bp
);
175 blockPtr
->isModified
= 1;
179 btree_swap_node(struct buf
*bp
, __unused
void *arg
)
181 // struct hfsmount *hfsmp = (struct hfsmount *)arg;
183 struct vnode
*vp
= buf_vnode(bp
);
184 BlockDescriptor block
;
186 /* Prepare the block pointer */
187 block
.blockHeader
= bp
;
188 block
.buffer
= (char *)buf_dataptr(bp
);
189 block
.blockNum
= buf_lblkno(bp
);
190 /* not found in cache ==> came from disk */
191 block
.blockReadFromDisk
= (buf_fromcache(bp
) == 0);
192 block
.blockSize
= buf_count(bp
);
194 // swap the data now that this node is ready to go to disk
195 retval
= hfs_swap_BTNode (&block
, vp
, kSwapBTNodeHostToBig
);
197 panic("btree_swap_node: about to write corrupt node!\n");
202 btree_journal_modify_block_end(struct hfsmount
*hfsmp
, struct buf
*bp
)
204 return journal_modify_block_end(hfsmp
->jnl
, bp
, btree_swap_node
, hfsmp
);
209 OSStatus
ReleaseBTreeBlock(FileReference vp
, BlockDescPtr blockPtr
, ReleaseBlockOptions options
)
211 struct hfsmount
*hfsmp
= VTOHFS(vp
);
212 OSStatus retval
= E_NONE
;
213 struct buf
*bp
= NULL
;
215 bp
= (struct buf
*) blockPtr
->blockHeader
;
222 if (options
& kTrashBlock
) {
225 if (hfsmp
->jnl
&& (buf_flags(bp
) & B_LOCKED
)) {
226 journal_kill_block(hfsmp
->jnl
, bp
);
228 buf_brelse(bp
); /* note: B-tree code will clear blockPtr->blockHeader and blockPtr->buffer */
231 if (options
& kForceWriteBlock
) {
233 if (blockPtr
->isModified
== 0) {
234 panic("hfs: releaseblock: modified is 0 but forcewrite set! bp %p\n", bp
);
237 retval
= btree_journal_modify_block_end(hfsmp
, bp
);
238 blockPtr
->isModified
= 0;
240 retval
= VNOP_BWRITE(bp
);
242 } else if (options
& kMarkBlockDirty
) {
245 if ((options
& kLockTransaction
) && hfsmp
->jnl
== NULL
) {
248 * Set the B_LOCKED flag and unlock the buffer, causing buf_brelse to move
249 * the buffer onto the LOCKED free list. This is necessary, otherwise
250 * getnewbuf() would try to reclaim the buffers using buf_bawrite, which
251 * isn't going to work.
254 /* Don't hog all the buffers... */
255 if (count_lock_queue() > kMaxLockedMetaBuffers
) {
256 hfs_btsync(vp
, HFS_SYNCTRANS
);
257 /* Rollback sync time to cause a sync on lock release... */
258 (void) BTSetLastSync(VTOF(vp
), tv
.tv_sec
- (kMaxSecsForFsync
+ 1));
260 buf_setflags(bp
, B_LOCKED
);
264 * Delay-write this block.
265 * If the maximum delayed buffers has been exceeded then
266 * free up some buffers and fall back to an asynchronous write.
269 if (blockPtr
->isModified
== 0) {
270 panic("hfs: releaseblock: modified is 0 but markdirty set! bp %p\n", bp
);
272 retval
= btree_journal_modify_block_end(hfsmp
, bp
);
273 blockPtr
->isModified
= 0;
274 } else if (bdwrite_internal(bp
, 1) != 0) {
276 /* Rollback sync time to cause a sync on lock release... */
277 (void) BTSetLastSync(VTOF(vp
), tv
.tv_sec
- (kMaxSecsForFsync
+ 1));
279 buf_clearflags(bp
, B_LOCKED
);
283 // check if we had previously called journal_modify_block_start()
284 // on this block and if so, abort it (which will call buf_brelse()).
285 if (hfsmp
->jnl
&& blockPtr
->isModified
) {
286 // XXXdbg - I don't want to call modify_block_abort()
287 // because I think it may be screwing up the
288 // journal and blowing away a block that has
291 // journal_modify_block_abort(hfsmp->jnl, bp);
292 //panic("hfs: releaseblock called for 0x%x but mod_block_start previously called.\n", bp);
293 btree_journal_modify_block_end(hfsmp
, bp
);
294 blockPtr
->isModified
= 0;
296 buf_brelse(bp
); /* note: B-tree code will clear blockPtr->blockHeader and blockPtr->buffer */
307 OSStatus
ExtendBTreeFile(FileReference vp
, FSSize minEOF
, FSSize maxEOF
)
309 #pragma unused (maxEOF)
311 OSStatus retval
= 0, ret
= 0;
312 int64_t actualBytesAdded
, origSize
;
313 u_int64_t bytesToAdd
;
314 u_int32_t startAllocation
;
315 u_int32_t fileblocks
;
319 struct proc
*p
= NULL
;
323 filePtr
= GetFileControlBlock(vp
);
325 if ( (off_t
)minEOF
> filePtr
->fcbEOF
)
327 bytesToAdd
= minEOF
- filePtr
->fcbEOF
;
329 if (bytesToAdd
< filePtr
->ff_clumpsize
)
330 bytesToAdd
= filePtr
->ff_clumpsize
; //XXX why not always be a mutiple of clump size?
340 * The Extents B-tree can't have overflow extents. ExtendFileC will
341 * return an error if an attempt is made to extend the Extents B-tree
342 * when the resident extents are exhausted.
345 /* Protect allocation bitmap and extents overflow file. */
346 lockflags
= SFL_BITMAP
;
347 if (VTOC(vp
)->c_fileid
!= kHFSExtentsFileID
)
348 lockflags
|= SFL_EXTENTS
;
349 lockflags
= hfs_systemfile_lock(vcb
, lockflags
, HFS_EXCLUSIVE_LOCK
);
351 (void) BTGetInformation(filePtr
, 0, &btInfo
);
355 * The b-tree code expects nodes to be contiguous. So when
356 * the allocation block size is less than the b-tree node
357 * size, we need to force disk allocations to be contiguous.
359 if (vcb
->blockSize
>= btInfo
.nodeSize
) {
362 /* Ensure that all b-tree nodes are contiguous on disk */
363 extendFlags
= kEFContigMask
;
367 origSize
= filePtr
->fcbEOF
;
368 fileblocks
= filePtr
->ff_blocks
;
369 startAllocation
= vcb
->nextAllocation
;
371 // loop trying to get a contiguous chunk that's an integer multiple
372 // of the btree node size. if we can't get a contiguous chunk that
373 // is at least the node size then we break out of the loop and let
374 // the error propagate back up.
375 while((off_t
)bytesToAdd
>= btInfo
.nodeSize
) {
377 retval
= ExtendFileC(vcb
, filePtr
, bytesToAdd
, 0,
378 kEFContigMask
| kEFMetadataMask
| kEFNoClumpMask
,
379 (int64_t *)&actualBytesAdded
);
380 if (retval
== dskFulErr
&& actualBytesAdded
== 0) {
382 if (bytesToAdd
< btInfo
.nodeSize
) {
384 } else if ((bytesToAdd
% btInfo
.nodeSize
) != 0) {
385 // make sure it's an integer multiple of the nodeSize
386 bytesToAdd
-= (bytesToAdd
% btInfo
.nodeSize
);
389 } while (retval
== dskFulErr
&& actualBytesAdded
== 0);
391 if (retval
== dskFulErr
&& actualBytesAdded
== 0 && bytesToAdd
<= btInfo
.nodeSize
) {
395 filePtr
->fcbEOF
= (u_int64_t
)filePtr
->ff_blocks
* (u_int64_t
)vcb
->blockSize
;
396 bytesToAdd
= minEOF
- filePtr
->fcbEOF
;
400 * If a new extent was added then move the roving allocator
401 * reference forward by the current b-tree file size so
402 * there's plenty of room to grow.
405 ((VCBTOHFS(vcb
)->hfs_flags
& HFS_METADATA_ZONE
) == 0) &&
406 (vcb
->nextAllocation
> startAllocation
) &&
407 ((vcb
->nextAllocation
+ fileblocks
) < vcb
->allocLimit
)) {
408 HFS_UPDATE_NEXT_ALLOCATION(vcb
, vcb
->nextAllocation
+ fileblocks
);
411 filePtr
->fcbEOF
= (u_int64_t
)filePtr
->ff_blocks
* (u_int64_t
)vcb
->blockSize
;
413 // XXXdbg ExtendFileC() could have returned an error even though
414 // it grew the file to be big enough for our needs. If this is
415 // the case, we don't care about retval so we blow it away.
417 if (filePtr
->fcbEOF
>= (off_t
)minEOF
&& retval
!= 0) {
421 // XXXdbg if the file grew but isn't large enough or isn't an
422 // even multiple of the nodeSize then trim things back. if
423 // the file isn't large enough we trim back to the original
424 // size. otherwise we trim back to be an even multiple of the
427 if ((filePtr
->fcbEOF
< (off_t
)minEOF
) || ((filePtr
->fcbEOF
- origSize
) % btInfo
.nodeSize
) != 0) {
429 if (filePtr
->fcbEOF
< (off_t
)minEOF
) {
432 if (filePtr
->fcbEOF
< origSize
) {
433 panic("hfs: btree file eof %lld less than orig size %lld!\n",
434 filePtr
->fcbEOF
, origSize
);
437 trim
= filePtr
->fcbEOF
- origSize
;
439 trim
= ((filePtr
->fcbEOF
- origSize
) % btInfo
.nodeSize
);
442 ret
= TruncateFileC(vcb
, filePtr
, filePtr
->fcbEOF
- trim
, 0);
443 filePtr
->fcbEOF
= (u_int64_t
)filePtr
->ff_blocks
* (u_int64_t
)vcb
->blockSize
;
445 // XXXdbg - panic if the file didn't get trimmed back properly
446 if ((filePtr
->fcbEOF
% btInfo
.nodeSize
) != 0) {
447 panic("hfs: truncate file didn't! fcbEOF %lld nsize %d fcb %p\n",
448 filePtr
->fcbEOF
, btInfo
.nodeSize
, filePtr
);
452 // XXXdbg - this probably doesn't need to be a panic()
453 panic("hfs: error truncating btree files (sz 0x%llx, trim %lld, ret %ld)\n",
454 filePtr
->fcbEOF
, trim
, ret
);
459 if(VTOC(vp
)->c_fileid
!= kHFSExtentsFileID
) {
461 * Get any extents overflow b-tree changes to disk ASAP!
463 (void) BTFlushPath(VTOF(vcb
->extentsRefNum
));
464 (void) hfs_fsync(vcb
->extentsRefNum
, MNT_WAIT
, 0, p
);
466 hfs_systemfile_unlock(vcb
, lockflags
);
469 if ((filePtr
->fcbEOF
% btInfo
.nodeSize
) != 0) {
470 panic("hfs: extendbtree: fcb %p has eof 0x%llx not a multiple of 0x%x (trim %llx)\n",
471 filePtr
, filePtr
->fcbEOF
, btInfo
.nodeSize
, trim
);
475 * Update the Alternate MDB or Alternate VolumeHeader
477 if ((VTOC(vp
)->c_fileid
== kHFSExtentsFileID
) ||
478 (VTOC(vp
)->c_fileid
== kHFSCatalogFileID
) ||
479 (VTOC(vp
)->c_fileid
== kHFSAttributesFileID
)
481 VTOC(vp
)->c_flag
|= C_MODIFIED
;
483 ret
= hfs_flushvolumeheader(VCBTOHFS(vcb
), MNT_WAIT
, HFS_ALTFLUSH
);
485 VTOC(vp
)->c_touch_chgtime
= TRUE
;
486 VTOC(vp
)->c_touch_modtime
= TRUE
;
487 (void) hfs_update(vp
, TRUE
);
490 ret
= ClearBTNodes(vp
, btInfo
.nodeSize
, origSize
, (filePtr
->fcbEOF
- origSize
));
496 hfs_systemfile_unlock(vcb
, lockflags
);
503 * Clear out (zero) new b-tree nodes on disk.
506 ClearBTNodes(struct vnode
*vp
, long blksize
, off_t offset
, off_t amount
)
508 struct hfsmount
*hfsmp
= VTOHFS(vp
);
509 struct buf
*bp
= NULL
;
513 blk
= offset
/ blksize
;
514 blkcnt
= amount
/ blksize
;
517 bp
= buf_getblk(vp
, blk
, blksize
, 0, 0, BLK_META
);
523 // XXXdbg -- skipping this for now since it makes a transaction
524 // become *way* too large
525 //journal_modify_block_start(hfsmp->jnl, bp);
527 bzero((char *)buf_dataptr(bp
), blksize
);
533 // XXXdbg -- skipping this for now since it makes a transaction
534 // become *way* too large
535 //journal_modify_block_end(hfsmp->jnl, bp);
537 // XXXdbg - remove this once we decide what to do with the
538 // writes to the journal
544 /* wait/yield every 32 blocks so we don't hog all the buffers */
558 extern char hfs_attrname
[];
561 * Create an HFS+ Attribute B-tree File.
563 * No global resources should be held.
566 hfs_create_attr_btree(struct hfsmount
*hfsmp
, u_int32_t nodesize
, u_int32_t nodecnt
)
568 struct vnode
* vp
= NULLVP
;
569 struct cat_desc cndesc
;
570 struct cat_attr cnattr
;
571 struct cat_fork cfork
;
572 BlockDescriptor blkdesc
;
573 BTNodeDescriptor
*ndp
;
575 BTreeControlBlockPtr btcb
= NULL
;
576 struct buf
*bp
= NULL
;
584 * Serialize creation using HFS_CREATING_BTREE flag.
586 lck_mtx_lock(&hfsmp
->hfs_mutex
);
587 if (hfsmp
->hfs_flags
& HFS_CREATING_BTREE
) {
588 /* Someone else beat us, wait for them to finish. */
589 (void) msleep(hfsmp
->hfs_attribute_cp
, &hfsmp
->hfs_mutex
,
590 PDROP
| PINOD
, "hfs_create_attr_btree", 0);
591 if (hfsmp
->hfs_attribute_vp
) {
596 hfsmp
->hfs_flags
|= HFS_CREATING_BTREE
;
597 lck_mtx_unlock(&hfsmp
->hfs_mutex
);
599 /* Check if were out of usable disk space. */
600 if ((hfs_freeblks(hfsmp
, 1) == 0)) {
606 * Set up Attribute B-tree vnode
607 * (this must be done before we start a transaction
608 * or take any system file locks)
610 bzero(&cndesc
, sizeof(cndesc
));
611 cndesc
.cd_parentcnid
= kHFSRootParentID
;
612 cndesc
.cd_flags
|= CD_ISMETA
;
613 cndesc
.cd_nameptr
= (const u_int8_t
*)hfs_attrname
;
614 cndesc
.cd_namelen
= strlen(hfs_attrname
);
615 cndesc
.cd_cnid
= kHFSAttributesFileID
;
617 bzero(&cnattr
, sizeof(cnattr
));
618 cnattr
.ca_linkcount
= 1;
619 cnattr
.ca_mode
= S_IFREG
;
620 cnattr
.ca_fileid
= cndesc
.cd_cnid
;
622 bzero(&cfork
, sizeof(cfork
));
623 cfork
.cf_clump
= nodesize
* nodecnt
;
625 result
= hfs_getnewvnode(hfsmp
, NULL
, NULL
, &cndesc
, 0, &cnattr
, &cfork
, &vp
);
630 * Set up Attribute B-tree control block
632 MALLOC(btcb
, BTreeControlBlock
*, sizeof(BTreeControlBlock
), M_TEMP
, M_WAITOK
);
633 bzero(btcb
, sizeof(BTreeControlBlock
));
635 btcb
->nodeSize
= nodesize
;
636 btcb
->maxKeyLength
= kHFSPlusAttrKeyMaximumLength
;
637 btcb
->btreeType
= 0xFF;
638 btcb
->attributes
= kBTVariableIndexKeysMask
| kBTBigKeysMask
;
639 btcb
->version
= kBTreeVersion
;
640 btcb
->writeCount
= 1;
641 btcb
->flags
= 0; /* kBTHeaderDirty */
642 btcb
->fileRefNum
= vp
;
643 btcb
->getBlockProc
= GetBTreeBlock
;
644 btcb
->releaseBlockProc
= ReleaseBTreeBlock
;
645 btcb
->setEndOfForkProc
= ExtendBTreeFile
;
646 btcb
->keyCompareProc
= (KeyCompareProcPtr
)hfs_attrkeycompare
;
647 VTOF(vp
)->fcbBTCBPtr
= btcb
;
650 * Allocate some space
652 if (hfs_start_transaction(hfsmp
) != 0) {
658 /* Note ExtendBTreeFile will acquire the necessary system file locks. */
659 result
= ExtendBTreeFile(vp
, nodesize
, cfork
.cf_clump
);
663 btcb
->totalNodes
= VTOF(vp
)->ff_size
/ nodesize
;
664 btcb
->freeNodes
= btcb
->totalNodes
- 1;
667 * Initialize the b-tree header on disk
669 bp
= buf_getblk(vp
, 0, nodesize
, 0, 0, BLK_META
);
675 buffer
= (void *)buf_dataptr(bp
);
676 blkdesc
.buffer
= buffer
;
677 blkdesc
.blockHeader
= (void *)bp
;
678 blkdesc
.blockReadFromDisk
= 0;
679 blkdesc
.isModified
= 0;
681 ModifyBlockStart(vp
, &blkdesc
);
683 if (buf_size(bp
) != nodesize
)
684 panic("hfs_create_attr_btree: bad buffer size (%d)\n", buf_size(bp
));
686 bzero(buffer
, nodesize
);
687 index
= (u_int16_t
*)buffer
;
689 /* FILL IN THE NODE DESCRIPTOR: */
690 ndp
= (BTNodeDescriptor
*)buffer
;
691 ndp
->kind
= kBTHeaderNode
;
693 offset
= sizeof(BTNodeDescriptor
);
694 index
[(nodesize
/ 2) - 1] = offset
;
696 /* FILL IN THE HEADER RECORD: */
697 bthp
= (BTHeaderRec
*)((u_int8_t
*)buffer
+ offset
);
698 bthp
->nodeSize
= nodesize
;
699 bthp
->totalNodes
= btcb
->totalNodes
;
700 bthp
->freeNodes
= btcb
->freeNodes
;
701 bthp
->clumpSize
= cfork
.cf_clump
;
702 bthp
->btreeType
= 0xFF;
703 bthp
->attributes
= kBTVariableIndexKeysMask
| kBTBigKeysMask
;
704 bthp
->maxKeyLength
= kHFSPlusAttrKeyMaximumLength
;
705 bthp
->keyCompareType
= kHFSBinaryCompare
;
706 offset
+= sizeof(BTHeaderRec
);
707 index
[(nodesize
/ 2) - 2] = offset
;
709 /* FILL IN THE USER RECORD: */
710 offset
+= kBTreeHeaderUserBytes
;
711 index
[(nodesize
/ 2) - 3] = offset
;
713 /* FILL IN THE MAP RECORD (only one node in use). */
714 *((u_int8_t
*)buffer
+ offset
) = 0x80;
715 offset
+= nodesize
- sizeof(BTNodeDescriptor
) - sizeof(BTHeaderRec
)
716 - kBTreeHeaderUserBytes
- (4 * sizeof(int16_t));
717 index
[(nodesize
/ 2) - 4] = offset
;
720 result
= btree_journal_modify_block_end(hfsmp
, bp
);
722 result
= VNOP_BWRITE(bp
);
727 /* Update vp/cp for attribute btree */
728 lck_mtx_lock(&hfsmp
->hfs_mutex
);
729 hfsmp
->hfs_attribute_cp
= VTOC(vp
);
730 hfsmp
->hfs_attribute_vp
= vp
;
731 lck_mtx_unlock(&hfsmp
->hfs_mutex
);
733 (void) hfs_flushvolumeheader(hfsmp
, MNT_WAIT
, HFS_ALTFLUSH
);
736 hfs_unlock(VTOC(vp
));
745 /* XXX need to give back blocks ? */
748 hfs_end_transaction(hfsmp
);
752 * All done, clear HFS_CREATING_BTREE, and wake up any sleepers.
754 lck_mtx_lock(&hfsmp
->hfs_mutex
);
755 hfsmp
->hfs_flags
&= ~HFS_CREATING_BTREE
;
756 wakeup((caddr_t
)hfsmp
->hfs_attribute_cp
);
757 lck_mtx_unlock(&hfsmp
->hfs_mutex
);