2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 #include "../../hfs.h"
25 #include "../../hfs_format.h"
26 #include "../../hfs_endian.h"
28 #include "../headers/FileMgrInternal.h"
29 #include "../headers/BTreesInternal.h"
31 #include <sys/malloc.h>
34 ============================================================
35 Public (Exported) Routines:
36 ============================================================
38 ExtendFileC Allocate more space to a given file.
41 Compare two extents file keys (a search key and a trial
42 key). Used by the BTree manager when searching for,
43 adding, or deleting keys in the extents file of an HFS
47 Compare two extents file keys (a search key and a trial
48 key). Used by the BTree manager when searching for,
49 adding, or deleting keys in the extents file of an HFS+
52 MapFileBlockC Convert (map) an offset within a given file into a
53 physical disk address.
55 TruncateFileC Truncates the disk space allocated to a file. The file
56 space is truncated to a specified new physical EOF, rounded
57 up to the next allocation block boundry. There is an option
58 to truncate to the end of the extent containing the new EOF.
61 Flush the extents file for a given volume.
66 ============================================================
68 ============================================================
70 Search the extents BTree for a particular extent record.
72 Search the FCB and extents file for an extent record that
73 contains a given file position (in bytes).
75 Search a given extent record to see if it contains a given
76 file position (in bytes). Used by SearchExtentFile.
78 Deallocate all allocation blocks in all extents of an extent
81 Deallocate blocks and delete extent records for all allocation
82 blocks beyond a certain point in a file. The starting point
83 must be the first file allocation block for some extent record
86 Deallocate all allocation blocks belonging to a given fork.
88 If the extent record came from the extents file, write out
89 the updated record; otherwise, copy the updated record into
90 the FCB resident extent record. If the record has no extents,
91 and was in the extents file, then delete the record instead.
94 static const SInt64 kTwoGigabytes
= 0x80000000LL
;
99 kResourceForkType
= 0xFF,
105 static OSErr
HFSPlusToHFSExtents(
106 const HFSPlusExtentRecord oldExtents
,
107 HFSExtentRecord newExtents
);
109 static OSErr
FindExtentRecord(
110 const ExtendedVCB
*vcb
,
114 Boolean allowPrevious
,
115 HFSPlusExtentKey
*foundKey
,
116 HFSPlusExtentRecord foundData
,
119 static OSErr
DeleteExtentRecord(
120 const ExtendedVCB
*vcb
,
125 static OSErr
CreateExtentRecord(
127 HFSPlusExtentKey
*key
,
128 HFSPlusExtentRecord extents
,
132 static OSErr
GetFCBExtentRecord(
134 HFSPlusExtentRecord extents
);
136 static OSErr
SearchExtentFile(
140 HFSPlusExtentKey
*foundExtentKey
,
141 HFSPlusExtentRecord foundExtentData
,
142 UInt32
*foundExtentDataIndex
,
143 UInt32
*extentBTreeHint
,
144 UInt32
*endingFABNPlusOne
);
146 static OSErr
SearchExtentRecord(
149 const HFSPlusExtentRecord extentData
,
150 UInt32 extentDataStartFABN
,
151 UInt32
*foundExtentDataOffset
,
152 UInt32
*endingFABNPlusOne
,
153 Boolean
*noMoreExtents
);
155 static OSErr
ReleaseExtents(
157 const HFSPlusExtentRecord extentRecord
,
158 UInt32
*numReleasedAllocationBlocks
,
159 Boolean
*releasedLastExtent
);
161 static OSErr
DeallocateFork(
163 HFSCatalogNodeID fileID
,
165 HFSPlusExtentRecord catalogExtents
,
166 Boolean
* recordDeleted
);
168 static OSErr
TruncateExtents(
173 Boolean
* recordDeleted
);
175 static OSErr
UpdateExtentRecord (
178 const HFSPlusExtentKey
*extentFileKey
,
179 const HFSPlusExtentRecord extentData
,
180 UInt32 extentBTreeHint
);
182 static Boolean
ExtentsAreIntegral(
183 const HFSPlusExtentRecord extentRecord
,
185 UInt32
*blocksChecked
,
186 Boolean
*checkedLastExtent
);
188 //_________________________________________________________________________________
190 // Routine: FindExtentRecord
192 // Purpose: Search the extents BTree for an extent record matching the given
193 // FileID, fork, and starting file allocation block number.
196 // vcb Volume to search
197 // forkType 0 = data fork, -1 = resource fork
198 // fileID File's FileID (CatalogNodeID)
199 // startBlock Starting file allocation block number
200 // allowPrevious If the desired record isn't found and this flag is set,
201 // then see if the previous record belongs to the same fork.
202 // If so, then return it.
205 // foundKey The key data for the record actually found
206 // foundData The extent record actually found (NOTE: on an HFS volume, the
207 // fourth entry will be zeroes.
208 // foundHint The BTree hint to find the node again
209 //_________________________________________________________________________________
210 static OSErr
FindExtentRecord(
211 const ExtendedVCB
*vcb
,
215 Boolean allowPrevious
,
216 HFSPlusExtentKey
*foundKey
,
217 HFSPlusExtentRecord foundData
,
221 BTreeIterator
*btIterator
;
222 FSBufferDescriptor btRecord
;
229 fcb
= GetFileControlBlock(vcb
->extentsRefNum
);
231 MALLOC(btIterator
, BTreeIterator
*, sizeof(*btIterator
), M_TEMP
, M_WAITOK
);
232 bzero(btIterator
, sizeof(*btIterator
));
234 if (vcb
->vcbSigWord
== kHFSSigWord
) {
235 HFSExtentKey
* extentKeyPtr
;
236 HFSExtentRecord extentData
;
238 extentKeyPtr
= (HFSExtentKey
*) &btIterator
->key
;
239 extentKeyPtr
->keyLength
= kHFSExtentKeyMaximumLength
;
240 extentKeyPtr
->forkType
= forkType
;
241 extentKeyPtr
->fileID
= fileID
;
242 extentKeyPtr
->startBlock
= startBlock
;
244 btRecord
.bufferAddress
= &extentData
;
245 btRecord
.itemSize
= sizeof(HFSExtentRecord
);
246 btRecord
.itemCount
= 1;
248 err
= BTSearchRecord(fcb
, btIterator
, &btRecord
, &btRecordSize
, btIterator
);
250 if (err
== btNotFound
&& allowPrevious
) {
251 err
= BTIterateRecord(fcb
, kBTreePrevRecord
, btIterator
, &btRecord
, &btRecordSize
);
253 // A previous record may not exist, so just return btNotFound (like we would if
254 // it was for the wrong file/fork).
255 if (err
== (OSErr
) fsBTStartOfIterationErr
) //¥¥ fsBTStartOfIterationErr is type unsigned long
259 // Found a previous record. Does it belong to the same fork of the same file?
260 if (extentKeyPtr
->fileID
!= fileID
|| extentKeyPtr
->forkType
!= forkType
)
268 // Copy the found key back for the caller
270 foundKey
->keyLength
= kHFSPlusExtentKeyMaximumLength
;
271 foundKey
->forkType
= extentKeyPtr
->forkType
;
273 foundKey
->fileID
= extentKeyPtr
->fileID
;
274 foundKey
->startBlock
= extentKeyPtr
->startBlock
;
276 // Copy the found data back for the caller
277 foundData
[0].startBlock
= extentData
[0].startBlock
;
278 foundData
[0].blockCount
= extentData
[0].blockCount
;
279 foundData
[1].startBlock
= extentData
[1].startBlock
;
280 foundData
[1].blockCount
= extentData
[1].blockCount
;
281 foundData
[2].startBlock
= extentData
[2].startBlock
;
282 foundData
[2].blockCount
= extentData
[2].blockCount
;
284 for (i
= 3; i
< kHFSPlusExtentDensity
; ++i
)
286 foundData
[i
].startBlock
= 0;
287 foundData
[i
].blockCount
= 0;
291 else { // HFS Plus volume
292 HFSPlusExtentKey
* extentKeyPtr
;
293 HFSPlusExtentRecord extentData
;
295 extentKeyPtr
= (HFSPlusExtentKey
*) &btIterator
->key
;
296 extentKeyPtr
->keyLength
= kHFSPlusExtentKeyMaximumLength
;
297 extentKeyPtr
->forkType
= forkType
;
298 extentKeyPtr
->pad
= 0;
299 extentKeyPtr
->fileID
= fileID
;
300 extentKeyPtr
->startBlock
= startBlock
;
302 btRecord
.bufferAddress
= &extentData
;
303 btRecord
.itemSize
= sizeof(HFSPlusExtentRecord
);
304 btRecord
.itemCount
= 1;
306 err
= BTSearchRecord(fcb
, btIterator
, &btRecord
, &btRecordSize
, btIterator
);
308 if (err
== btNotFound
&& allowPrevious
) {
309 err
= BTIterateRecord(fcb
, kBTreePrevRecord
, btIterator
, &btRecord
, &btRecordSize
);
311 // A previous record may not exist, so just return btNotFound (like we would if
312 // it was for the wrong file/fork).
313 if (err
== (OSErr
) fsBTStartOfIterationErr
) //¥¥ fsBTStartOfIterationErr is type unsigned long
317 // Found a previous record. Does it belong to the same fork of the same file?
318 if (extentKeyPtr
->fileID
!= fileID
|| extentKeyPtr
->forkType
!= forkType
)
324 // Copy the found key back for the caller
326 BlockMoveData(extentKeyPtr
, foundKey
, sizeof(HFSPlusExtentKey
));
327 // Copy the found data back for the caller
328 BlockMoveData(&extentData
, foundData
, sizeof(HFSPlusExtentRecord
));
333 *foundHint
= btIterator
->hint
.nodeNum
;
334 FREE(btIterator
, M_TEMP
);
340 static OSErr
CreateExtentRecord(
342 HFSPlusExtentKey
*key
,
343 HFSPlusExtentRecord extents
,
346 BTreeIterator
* btIterator
;
347 FSBufferDescriptor btRecord
;
355 MALLOC(btIterator
, BTreeIterator
*, sizeof(*btIterator
), M_TEMP
, M_WAITOK
);
356 bzero(btIterator
, sizeof(*btIterator
));
359 * The lock taken by callers of ExtendFileC is speculative and
360 * only occurs when the file already has overflow extents. So
361 * We need to make sure we have the lock here. The extents
362 * btree lock can be nested (its recursive) so we always take
365 lockflags
= hfs_systemfile_lock(vcb
, SFL_EXTENTS
, HFS_EXCLUSIVE_LOCK
);
367 if (vcb
->vcbSigWord
== kHFSSigWord
) {
368 HFSExtentKey
* keyPtr
;
369 HFSExtentRecord data
;
371 btRecordSize
= sizeof(HFSExtentRecord
);
372 btRecord
.bufferAddress
= &data
;
373 btRecord
.itemSize
= btRecordSize
;
374 btRecord
.itemCount
= 1;
376 keyPtr
= (HFSExtentKey
*) &btIterator
->key
;
377 keyPtr
->keyLength
= kHFSExtentKeyMaximumLength
;
378 keyPtr
->forkType
= key
->forkType
;
379 keyPtr
->fileID
= key
->fileID
;
380 keyPtr
->startBlock
= key
->startBlock
;
382 err
= HFSPlusToHFSExtents(extents
, data
);
384 else { // HFS Plus volume
385 btRecordSize
= sizeof(HFSPlusExtentRecord
);
386 btRecord
.bufferAddress
= extents
;
387 btRecord
.itemSize
= btRecordSize
;
388 btRecord
.itemCount
= 1;
390 BlockMoveData(key
, &btIterator
->key
, sizeof(HFSPlusExtentKey
));
394 err
= BTInsertRecord(GetFileControlBlock(vcb
->extentsRefNum
), btIterator
, &btRecord
, btRecordSize
);
397 *hint
= btIterator
->hint
.nodeNum
;
399 (void) BTFlushPath(GetFileControlBlock(vcb
->extentsRefNum
));
401 hfs_systemfile_unlock(vcb
, lockflags
);
403 FREE(btIterator
, M_TEMP
);
408 static OSErr
DeleteExtentRecord(
409 const ExtendedVCB
*vcb
,
414 BTreeIterator
* btIterator
;
419 MALLOC(btIterator
, BTreeIterator
*, sizeof(*btIterator
), M_TEMP
, M_WAITOK
);
420 bzero(btIterator
, sizeof(*btIterator
));
422 if (vcb
->vcbSigWord
== kHFSSigWord
) {
423 HFSExtentKey
* keyPtr
;
425 keyPtr
= (HFSExtentKey
*) &btIterator
->key
;
426 keyPtr
->keyLength
= kHFSExtentKeyMaximumLength
;
427 keyPtr
->forkType
= forkType
;
428 keyPtr
->fileID
= fileID
;
429 keyPtr
->startBlock
= startBlock
;
431 else { // HFS Plus volume
432 HFSPlusExtentKey
* keyPtr
;
434 keyPtr
= (HFSPlusExtentKey
*) &btIterator
->key
;
435 keyPtr
->keyLength
= kHFSPlusExtentKeyMaximumLength
;
436 keyPtr
->forkType
= forkType
;
438 keyPtr
->fileID
= fileID
;
439 keyPtr
->startBlock
= startBlock
;
442 err
= BTDeleteRecord(GetFileControlBlock(vcb
->extentsRefNum
), btIterator
);
443 (void) BTFlushPath(GetFileControlBlock(vcb
->extentsRefNum
));
445 FREE(btIterator
, M_TEMP
);
451 //_________________________________________________________________________________
453 // Routine: MapFileBlock
455 // Function: Maps a file position into a physical disk address.
457 //_________________________________________________________________________________
460 OSErr
MapFileBlockC (
461 ExtendedVCB
*vcb
, // volume that file resides on
462 FCB
*fcb
, // FCB of file
463 size_t numberOfBytes
, // number of contiguous bytes desired
464 off_t offset
, // starting offset within file (in bytes)
465 daddr64_t
*startSector
, // first sector (NOT an allocation block)
466 size_t *availableBytes
) // number of contiguous bytes (up to numberOfBytes)
469 UInt32 allocBlockSize
; // Size of the volume's allocation block
471 HFSPlusExtentKey foundKey
;
472 HFSPlusExtentRecord foundData
;
475 UInt32 firstFABN
; // file allocation block of first block in found extent
476 UInt32 nextFABN
; // file allocation block of block after end of found extent
477 off_t dataEnd
; // (offset) end of range that is contiguous
478 UInt32 sectorsPerBlock
; // Number of sectors per allocation block
479 UInt32 startBlock
; // volume allocation block corresponding to firstFABN
483 allocBlockSize
= vcb
->blockSize
;
484 sectorSize
= VCBTOHFS(vcb
)->hfs_phys_block_size
;
486 err
= SearchExtentFile(vcb
, fcb
, offset
, &foundKey
, foundData
, &foundIndex
, &hint
, &nextFABN
);
488 startBlock
= foundData
[foundIndex
].startBlock
;
489 firstFABN
= nextFABN
- foundData
[foundIndex
].blockCount
;
498 // Determine the end of the available space. It will either be the end of the extent,
499 // or the file's PEOF, whichever is smaller.
501 dataEnd
= (off_t
)((off_t
)(nextFABN
) * (off_t
)(allocBlockSize
)); // Assume valid data through end of this extent
502 if (((off_t
)fcb
->ff_blocks
* (off_t
)allocBlockSize
) < dataEnd
) // Is PEOF shorter?
503 dataEnd
= (off_t
)fcb
->ff_blocks
* (off_t
)allocBlockSize
; // Yes, so only map up to PEOF
505 // Compute the number of sectors in an allocation block
506 sectorsPerBlock
= allocBlockSize
/ sectorSize
; // sectors per allocation block
509 // Compute the absolute sector number that contains the offset of the given file
510 // offset in sectors from start of the extent +
511 // offset in sectors from start of allocation block space
513 temp
= (daddr64_t
)((offset
- (off_t
)((off_t
)(firstFABN
) * (off_t
)(allocBlockSize
)))/sectorSize
);
514 temp
+= startBlock
* sectorsPerBlock
;
516 /* Add in any volume offsets */
517 if (vcb
->vcbSigWord
== kHFSPlusSigWord
)
518 temp
+= vcb
->hfsPlusIOPosOffset
/ sectorSize
;
520 temp
+= vcb
->vcbAlBlSt
;
522 // Return the desired sector for file position "offset"
526 // Determine the number of contiguous bytes until the end of the extent
527 // (or the amount they asked for, whichever comes first).
531 tmpOff
= dataEnd
- offset
;
532 if (tmpOff
> (off_t
)(numberOfBytes
))
533 *availableBytes
= numberOfBytes
; // more there than they asked for, so pin the output
535 *availableBytes
= tmpOff
;
542 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
543 // Routine: ReleaseExtents
545 // Function: Release the extents of a single extent data record.
546 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
548 static OSErr
ReleaseExtents(
550 const HFSPlusExtentRecord extentRecord
,
551 UInt32
*numReleasedAllocationBlocks
,
552 Boolean
*releasedLastExtent
)
555 UInt32 numberOfExtents
;
558 *numReleasedAllocationBlocks
= 0;
559 *releasedLastExtent
= false;
561 if (vcb
->vcbSigWord
== kHFSPlusSigWord
)
562 numberOfExtents
= kHFSPlusExtentDensity
;
564 numberOfExtents
= kHFSExtentDensity
;
566 for( extentIndex
= 0; extentIndex
< numberOfExtents
; extentIndex
++)
568 UInt32 numAllocationBlocks
;
570 // Loop over the extent record and release the blocks associated with each extent.
572 numAllocationBlocks
= extentRecord
[extentIndex
].blockCount
;
573 if ( numAllocationBlocks
== 0 )
575 *releasedLastExtent
= true;
579 err
= BlockDeallocate( vcb
, extentRecord
[extentIndex
].startBlock
, numAllocationBlocks
);
583 *numReleasedAllocationBlocks
+= numAllocationBlocks
; // bump FABN to beg of next extent
591 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
592 // Routine: TruncateExtents
594 // Purpose: Delete extent records whose starting file allocation block number
595 // is greater than or equal to a given starting block number. The
596 // allocation blocks represented by the extents are deallocated.
599 // vcb Volume to operate on
600 // fileID Which file to operate on
601 // startBlock Starting file allocation block number for first extent
603 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
605 static OSErr
TruncateExtents(
610 Boolean
* recordDeleted
)
613 UInt32 numberExtentsReleased
;
614 Boolean releasedLastExtent
;
616 HFSPlusExtentKey key
;
617 HFSPlusExtentRecord extents
;
621 * The lock taken by callers of TruncateFileC is speculative and
622 * only occurs when the file already has overflow extents. So
623 * We need to make sure we have the lock here. The extents
624 * btree lock can be nested (its recursive) so we always take
627 lockflags
= hfs_systemfile_lock(vcb
, SFL_EXTENTS
, HFS_EXCLUSIVE_LOCK
);
630 err
= FindExtentRecord(vcb
, forkType
, fileID
, startBlock
, false, &key
, extents
, &hint
);
632 if (err
== btNotFound
)
637 err
= ReleaseExtents( vcb
, extents
, &numberExtentsReleased
, &releasedLastExtent
);
638 if (err
!= noErr
) break;
640 err
= DeleteExtentRecord(vcb
, forkType
, fileID
, startBlock
);
641 if (err
!= noErr
) break;
643 *recordDeleted
= true;
644 startBlock
+= numberExtentsReleased
;
646 hfs_systemfile_unlock(vcb
, lockflags
);
653 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
654 // Routine: DeallocateFork
656 // Function: De-allocates all disk space allocated to a specified fork.
657 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
659 static OSErr
DeallocateFork(
661 HFSCatalogNodeID fileID
,
663 HFSPlusExtentRecord catalogExtents
,
664 Boolean
* recordDeleted
) /* true if a record was deleted */
667 UInt32 numReleasedAllocationBlocks
;
668 Boolean releasedLastExtent
;
670 // Release the catalog extents
671 err
= ReleaseExtents( vcb
, catalogExtents
, &numReleasedAllocationBlocks
, &releasedLastExtent
);
672 // Release the extra extents, if present
673 if (err
== noErr
&& !releasedLastExtent
)
674 err
= TruncateExtents(vcb
, forkType
, fileID
, numReleasedAllocationBlocks
, recordDeleted
);
679 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
680 // Routine: FlushExtentFile
682 // Function: Flushes the extent file for a specified volume
683 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
686 OSErr
FlushExtentFile( ExtendedVCB
*vcb
)
692 fcb
= GetFileControlBlock(vcb
->extentsRefNum
);
694 lockflags
= hfs_systemfile_lock(vcb
, SFL_EXTENTS
, HFS_EXCLUSIVE_LOCK
);
695 err
= BTFlushPath(fcb
);
696 hfs_systemfile_unlock(vcb
, lockflags
);
700 // If the FCB for the extent "file" is dirty, mark the VCB as dirty.
702 if (FTOC(fcb
)->c_flag
& C_MODIFIED
)
705 // err = FlushVolumeControlBlock( vcb );
713 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
714 // Routine: CompareExtentKeys
716 // Function: Compares two extent file keys (a search key and a trial key) for
718 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
721 SInt32
CompareExtentKeys( const HFSExtentKey
*searchKey
, const HFSExtentKey
*trialKey
)
723 SInt32 result
; // ± 1
726 if (searchKey
->keyLength
!= kHFSExtentKeyMaximumLength
)
727 DebugStr("\pHFS: search Key is wrong length");
728 if (trialKey
->keyLength
!= kHFSExtentKeyMaximumLength
)
729 DebugStr("\pHFS: trial Key is wrong length");
732 result
= -1; // assume searchKey < trialKey
734 if (searchKey
->fileID
== trialKey
->fileID
) {
736 // FileNum's are equal; compare fork types
738 if (searchKey
->forkType
== trialKey
->forkType
) {
740 // Fork types are equal; compare allocation block number
742 if (searchKey
->startBlock
== trialKey
->startBlock
) {
744 // Everything is equal
750 // Allocation block numbers differ; determine sign
752 if (searchKey
->startBlock
> trialKey
->startBlock
)
758 // Fork types differ; determine sign
760 if (searchKey
->forkType
> trialKey
->forkType
)
766 // FileNums differ; determine sign
768 if (searchKey
->fileID
> trialKey
->fileID
)
777 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
778 // Routine: CompareExtentKeysPlus
780 // Function: Compares two extent file keys (a search key and a trial key) for
782 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
785 SInt32
CompareExtentKeysPlus( const HFSPlusExtentKey
*searchKey
, const HFSPlusExtentKey
*trialKey
)
787 SInt32 result
; // ± 1
790 if (searchKey
->keyLength
!= kHFSPlusExtentKeyMaximumLength
)
791 DebugStr("\pHFS: search Key is wrong length");
792 if (trialKey
->keyLength
!= kHFSPlusExtentKeyMaximumLength
)
793 DebugStr("\pHFS: trial Key is wrong length");
796 result
= -1; // assume searchKey < trialKey
798 if (searchKey
->fileID
== trialKey
->fileID
) {
800 // FileNum's are equal; compare fork types
802 if (searchKey
->forkType
== trialKey
->forkType
) {
804 // Fork types are equal; compare allocation block number
806 if (searchKey
->startBlock
== trialKey
->startBlock
) {
808 // Everything is equal
814 // Allocation block numbers differ; determine sign
816 if (searchKey
->startBlock
> trialKey
->startBlock
)
822 // Fork types differ; determine sign
824 if (searchKey
->forkType
> trialKey
->forkType
)
830 // FileNums differ; determine sign
832 if (searchKey
->fileID
> trialKey
->fileID
)
840 * Add a file extent to a file.
842 * Used by hfs_extendfs to extend the volume allocation bitmap file.
847 AddFileExtent(ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 startBlock
, UInt32 blockCount
)
849 HFSPlusExtentKey foundKey
;
850 HFSPlusExtentRecord foundData
;
858 peof
= (SInt64
)(fcb
->ff_blocks
+ blockCount
) * (SInt64
)vcb
->blockSize
;
860 error
= SearchExtentFile(vcb
, fcb
, peof
-1, &foundKey
, foundData
, &foundIndex
, &hint
, &nextBlock
);
861 if (error
!= fxRangeErr
)
865 * Add new extent. See if there is room in the current record.
867 if (foundData
[foundIndex
].blockCount
!= 0)
869 if (foundIndex
== kHFSPlusExtentDensity
) {
871 * Existing record is full so create a new one.
873 foundKey
.keyLength
= kHFSPlusExtentKeyMaximumLength
;
874 foundKey
.forkType
= kDataForkType
;
876 foundKey
.fileID
= FTOC(fcb
)->c_fileid
;
877 foundKey
.startBlock
= nextBlock
;
879 foundData
[0].startBlock
= startBlock
;
880 foundData
[0].blockCount
= blockCount
;
882 /* zero out remaining extents. */
883 for (i
= 1; i
< kHFSPlusExtentDensity
; ++i
) {
884 foundData
[i
].startBlock
= 0;
885 foundData
[i
].blockCount
= 0;
890 error
= CreateExtentRecord(vcb
, &foundKey
, foundData
, &hint
);
891 if (error
== fxOvFlErr
)
895 * Add a new extent into existing record.
897 foundData
[foundIndex
].startBlock
= startBlock
;
898 foundData
[foundIndex
].blockCount
= blockCount
;
899 error
= UpdateExtentRecord(vcb
, fcb
, &foundKey
, foundData
, hint
);
901 (void) FlushExtentFile(vcb
);
907 //_________________________________________________________________________________
909 // Routine: Extendfile
911 // Function: Extends the disk space allocated to a file.
913 //_________________________________________________________________________________
917 ExtendedVCB
*vcb
, // volume that file resides on
918 FCB
*fcb
, // FCB of file to truncate
919 SInt64 bytesToAdd
, // number of bytes to allocate
920 UInt32 blockHint
, // desired starting allocation block
921 UInt32 flags
, // EFContig and/or EFAll
922 SInt64
*actualBytesAdded
) // number of bytes actually allocated
925 UInt32 volumeBlockSize
;
927 SInt64 bytesThisExtent
;
928 HFSPlusExtentKey foundKey
;
929 HFSPlusExtentRecord foundData
;
934 Boolean allOrNothing
;
939 UInt32 actualStartBlock
;
940 UInt32 actualNumBlocks
;
941 UInt32 numExtentsPerRecord
;
948 *actualBytesAdded
= 0;
949 volumeBlockSize
= vcb
->blockSize
;
950 allOrNothing
= ((flags
& kEFAllMask
) != 0);
951 forceContig
= ((flags
& kEFContigMask
) != 0);
952 prevblocks
= fcb
->ff_blocks
;
954 if (vcb
->vcbSigWord
== kHFSPlusSigWord
)
955 numExtentsPerRecord
= kHFSPlusExtentDensity
;
957 numExtentsPerRecord
= kHFSExtentDensity
;
960 // Make sure the request and new PEOF are less than 2GB if HFS.
962 if (vcb
->vcbSigWord
== kHFSSigWord
) {
963 if (bytesToAdd
>= kTwoGigabytes
)
965 if ((((SInt64
)fcb
->ff_blocks
* (SInt64
)volumeBlockSize
) + bytesToAdd
) >= kTwoGigabytes
)
969 // Determine how many blocks need to be allocated.
970 // Round up the number of desired bytes to add.
972 blocksToAdd
= howmany(bytesToAdd
, volumeBlockSize
);
973 bytesToAdd
= (SInt64
)((SInt64
)blocksToAdd
* (SInt64
)volumeBlockSize
);
976 * For deferred allocations just reserve the blocks.
978 if ((flags
& kEFDeferMask
)
979 && (vcb
->vcbSigWord
== kHFSPlusSigWord
)
980 && (bytesToAdd
< (SInt64
)HFS_MAX_DEFERED_ALLOC
)
981 && (blocksToAdd
< hfs_freeblks(VCBTOHFS(vcb
), 1))) {
982 HFS_MOUNT_LOCK(vcb
, TRUE
);
983 vcb
->loanedBlocks
+= blocksToAdd
;
984 HFS_MOUNT_UNLOCK(vcb
, TRUE
);
986 fcb
->ff_unallocblocks
+= blocksToAdd
;
987 FTOC(fcb
)->c_blocks
+= blocksToAdd
;
988 fcb
->ff_blocks
+= blocksToAdd
;
990 FTOC(fcb
)->c_flag
|= C_MODIFIED
| C_FORCEUPDATE
;
991 *actualBytesAdded
= bytesToAdd
;
995 * Give back any unallocated blocks before doing real allocations.
997 if (fcb
->ff_unallocblocks
> 0) {
998 u_int32_t loanedBlocks
;
1000 loanedBlocks
= fcb
->ff_unallocblocks
;
1001 blocksToAdd
+= loanedBlocks
;
1002 bytesToAdd
= (SInt64
)blocksToAdd
* (SInt64
)volumeBlockSize
;
1003 FTOC(fcb
)->c_blocks
-= loanedBlocks
;
1004 fcb
->ff_blocks
-= loanedBlocks
;
1005 fcb
->ff_unallocblocks
= 0;
1007 HFS_MOUNT_LOCK(vcb
, TRUE
);
1008 vcb
->loanedBlocks
-= loanedBlocks
;
1009 HFS_MOUNT_UNLOCK(vcb
, TRUE
);
1013 // If the file's clump size is larger than the allocation block size,
1014 // then set the maximum number of bytes to the requested number of bytes
1015 // rounded up to a multiple of the clump size.
1017 if ((vcb
->vcbClpSiz
> (int32_t)volumeBlockSize
)
1018 && (bytesToAdd
< (SInt64
)HFS_MAX_DEFERED_ALLOC
)
1019 && (flags
& kEFNoClumpMask
) == 0) {
1020 maximumBytes
= (SInt64
)howmany(bytesToAdd
, vcb
->vcbClpSiz
);
1021 maximumBytes
*= vcb
->vcbClpSiz
;
1023 maximumBytes
= bytesToAdd
;
1027 // Compute new physical EOF, rounded up to a multiple of a block.
1029 if ( (vcb
->vcbSigWord
== kHFSSigWord
) && // Too big?
1030 ((((SInt64
)fcb
->ff_blocks
* (SInt64
)volumeBlockSize
) + bytesToAdd
) >= kTwoGigabytes
) ) {
1031 if (allOrNothing
) // Yes, must they have it all?
1032 goto Overflow
; // Yes, can't have it
1034 --blocksToAdd
; // No, give give 'em one block less
1035 bytesToAdd
-= volumeBlockSize
;
1040 // If allocation is all-or-nothing, make sure there are
1041 // enough free blocks on the volume (quick test).
1044 (blocksToAdd
> hfs_freeblks(VCBTOHFS(vcb
), flags
& kEFReserveMask
))) {
1050 // See if there are already enough blocks allocated to the file.
1052 peof
= ((SInt64
)fcb
->ff_blocks
* (SInt64
)volumeBlockSize
) + bytesToAdd
; // potential new PEOF
1053 err
= SearchExtentFile(vcb
, fcb
, peof
-1, &foundKey
, foundData
, &foundIndex
, &hint
, &nextBlock
);
1055 // Enough blocks are already allocated. Just update the FCB to reflect the new length.
1056 fcb
->ff_blocks
= peof
/ volumeBlockSize
;
1057 FTOC(fcb
)->c_blocks
+= (bytesToAdd
/ volumeBlockSize
);
1058 FTOC(fcb
)->c_flag
|= C_MODIFIED
| C_FORCEUPDATE
;
1061 if (err
!= fxRangeErr
) // Any real error?
1062 goto ErrorExit
; // Yes, so exit immediately
1065 // Adjust the PEOF to the end of the last extent.
1067 peof
= (SInt64
)((SInt64
)nextBlock
* (SInt64
)volumeBlockSize
); // currently allocated PEOF
1068 bytesThisExtent
= (SInt64
)(nextBlock
- fcb
->ff_blocks
) * (SInt64
)volumeBlockSize
;
1069 if (bytesThisExtent
!= 0) {
1070 fcb
->ff_blocks
= nextBlock
;
1071 FTOC(fcb
)->c_blocks
+= (bytesThisExtent
/ volumeBlockSize
);
1072 FTOC(fcb
)->c_flag
|= C_MODIFIED
;
1073 bytesToAdd
-= bytesThisExtent
;
1077 // Allocate some more space.
1079 // First try a contiguous allocation (of the whole amount).
1080 // If that fails, get whatever we can.
1081 // If forceContig, then take whatever we got
1082 // else, keep getting bits and pieces (non-contig)
1085 useMetaZone
= flags
& kEFMetadataMask
;
1086 vcb
->vcbFreeExtCnt
= 0; /* For now, force rebuild of free extent list */
1089 startBlock
= blockHint
;
1091 startBlock
= foundData
[foundIndex
].startBlock
+ foundData
[foundIndex
].blockCount
;
1093 /* Force reserve checking if requested. */
1094 if (flags
& kEFReserveMask
) {
1097 actualNumBlocks
= 0;
1098 actualStartBlock
= 0;
1100 availbytes
= (SInt64
)hfs_freeblks(VCBTOHFS(vcb
), 1) *
1101 (SInt64
)volumeBlockSize
;
1102 if (availbytes
<= 0) {
1105 if (wantContig
&& (availbytes
< bytesToAdd
))
1108 err
= BlockAllocate(
1111 howmany(MIN(bytesToAdd
, availbytes
), volumeBlockSize
),
1112 howmany(MIN(maximumBytes
, availbytes
), volumeBlockSize
),
1120 err
= BlockAllocate(vcb
, startBlock
, howmany(bytesToAdd
, volumeBlockSize
),
1121 howmany(maximumBytes
, volumeBlockSize
), wantContig
, useMetaZone
,
1122 &actualStartBlock
, &actualNumBlocks
);
1124 if (err
== dskFulErr
) {
1126 break; // AllocContig failed because not enough contiguous space
1128 // Couldn't get one big chunk, so get whatever we can.
1133 if (actualNumBlocks
!= 0)
1135 if (useMetaZone
== 0) {
1136 /* Couldn't get anything so dip into metadat zone */
1143 if (actualNumBlocks
!= 0) {
1144 // this catalog entry *must* get forced to disk when
1145 // hfs_update() is called
1146 FTOC(fcb
)->c_flag
|= C_FORCEUPDATE
;
1149 // Add the new extent to the existing extent record, or create a new one.
1150 if ((actualStartBlock
== startBlock
) && (blockHint
== 0)) {
1151 // We grew the file's last extent, so just adjust the number of blocks.
1152 foundData
[foundIndex
].blockCount
+= actualNumBlocks
;
1153 err
= UpdateExtentRecord(vcb
, fcb
, &foundKey
, foundData
, hint
);
1154 if (err
!= noErr
) break;
1159 // Need to add a new extent. See if there is room in the current record.
1160 if (foundData
[foundIndex
].blockCount
!= 0) // Is current extent free to use?
1161 ++foundIndex
; // No, so use the next one.
1162 if (foundIndex
== numExtentsPerRecord
) {
1163 // This record is full. Need to create a new one.
1164 if (FTOC(fcb
)->c_fileid
== kHFSExtentsFileID
) {
1165 (void) BlockDeallocate(vcb
, actualStartBlock
, actualNumBlocks
);
1166 err
= dskFulErr
; // Oops. Can't extend extents file past first record.
1170 foundKey
.keyLength
= kHFSPlusExtentKeyMaximumLength
;
1171 if (FORK_IS_RSRC(fcb
))
1172 foundKey
.forkType
= kResourceForkType
;
1174 foundKey
.forkType
= kDataForkType
;
1176 foundKey
.fileID
= FTOC(fcb
)->c_fileid
;
1177 foundKey
.startBlock
= nextBlock
;
1179 foundData
[0].startBlock
= actualStartBlock
;
1180 foundData
[0].blockCount
= actualNumBlocks
;
1182 // zero out remaining extents...
1183 for (i
= 1; i
< kHFSPlusExtentDensity
; ++i
)
1185 foundData
[i
].startBlock
= 0;
1186 foundData
[i
].blockCount
= 0;
1191 err
= CreateExtentRecord(vcb
, &foundKey
, foundData
, &hint
);
1192 if (err
== fxOvFlErr
) {
1193 // We couldn't create an extent record because extents B-tree
1194 // couldn't grow. Dellocate the extent just allocated and
1195 // return a disk full error.
1196 (void) BlockDeallocate(vcb
, actualStartBlock
, actualNumBlocks
);
1199 if (err
!= noErr
) break;
1201 needsFlush
= true; // We need to update the B-tree header
1204 // Add a new extent into this record and update.
1205 foundData
[foundIndex
].startBlock
= actualStartBlock
;
1206 foundData
[foundIndex
].blockCount
= actualNumBlocks
;
1207 err
= UpdateExtentRecord(vcb
, fcb
, &foundKey
, foundData
, hint
);
1208 if (err
!= noErr
) break;
1212 // Figure out how many bytes were actually allocated.
1213 // NOTE: BlockAllocate could have allocated more than we asked for.
1214 // Don't set the PEOF beyond what our client asked for.
1215 nextBlock
+= actualNumBlocks
;
1216 bytesThisExtent
= (SInt64
)((SInt64
)actualNumBlocks
* (SInt64
)volumeBlockSize
);
1217 if (bytesThisExtent
> bytesToAdd
) {
1221 bytesToAdd
-= bytesThisExtent
;
1222 maximumBytes
-= bytesThisExtent
;
1224 fcb
->ff_blocks
+= (bytesThisExtent
/ volumeBlockSize
);
1225 FTOC(fcb
)->c_blocks
+= (bytesThisExtent
/ volumeBlockSize
);
1226 FTOC(fcb
)->c_flag
|= C_MODIFIED
| C_FORCEUPDATE
;
1228 // If contiguous allocation was requested, then we've already got one contiguous
1229 // chunk. If we didn't get all we wanted, then adjust the error to disk full.
1231 if (bytesToAdd
!= 0)
1233 break; // We've already got everything that's contiguous
1236 } while (err
== noErr
&& bytesToAdd
);
1240 if (VCBTOHFS(vcb
)->hfs_flags
& HFS_METADATA_ZONE
) {
1241 /* Keep the roving allocator out of the metadata zone. */
1242 if (vcb
->nextAllocation
>= VCBTOHFS(vcb
)->hfs_metazone_start
&&
1243 vcb
->nextAllocation
<= VCBTOHFS(vcb
)->hfs_metazone_end
) {
1244 HFS_MOUNT_LOCK(vcb
, TRUE
);
1245 vcb
->nextAllocation
= VCBTOHFS(vcb
)->hfs_metazone_end
+ 1;
1246 vcb
->vcbFlags
|= 0xFF00;
1247 HFS_MOUNT_UNLOCK(vcb
, TRUE
);
1250 if (prevblocks
< fcb
->ff_blocks
) {
1251 *actualBytesAdded
= (SInt64
)(fcb
->ff_blocks
- prevblocks
) * (SInt64
)volumeBlockSize
;
1253 *actualBytesAdded
= 0;
1257 (void) FlushExtentFile(vcb
);
1262 err
= fileBoundsErr
;
1268 //_________________________________________________________________________________
1270 // Routine: TruncateFileC
1272 // Function: Truncates the disk space allocated to a file. The file space is
1273 // truncated to a specified new PEOF rounded up to the next allocation
1274 // block boundry. If the 'TFTrunExt' option is specified, the file is
1275 // truncated to the end of the extent containing the new PEOF.
1277 //_________________________________________________________________________________
1280 OSErr
TruncateFileC (
1281 ExtendedVCB
*vcb
, // volume that file resides on
1282 FCB
*fcb
, // FCB of file to truncate
1283 SInt64 peof
, // new physical size for file
1284 Boolean truncateToExtent
) // if true, truncate to end of extent containing newPEOF
1287 UInt32 nextBlock
; // next file allocation block to consider
1288 UInt32 startBlock
; // Physical (volume) allocation block number of start of a range
1289 UInt32 physNumBlocks
; // Number of allocation blocks in file (according to PEOF)
1291 HFSPlusExtentKey key
; // key for current extent record; key->keyLength == 0 if FCB's extent record
1292 UInt32 hint
; // BTree hint corresponding to key
1293 HFSPlusExtentRecord extentRecord
;
1295 UInt32 extentNextBlock
;
1296 UInt32 numExtentsPerRecord
;
1299 Boolean extentChanged
; // true if we actually changed an extent
1300 Boolean recordDeleted
; // true if an extent record got deleted
1302 recordDeleted
= false;
1304 if (vcb
->vcbSigWord
== kHFSPlusSigWord
)
1305 numExtentsPerRecord
= kHFSPlusExtentDensity
;
1307 numExtentsPerRecord
= kHFSExtentDensity
;
1309 if (FORK_IS_RSRC(fcb
))
1310 forkType
= kResourceForkType
;
1312 forkType
= kDataForkType
;
1314 temp64
= fcb
->ff_blocks
;
1315 physNumBlocks
= (UInt32
)temp64
;
1318 // Round newPEOF up to a multiple of the allocation block size. If new size is
1319 // two gigabytes or more, then round down by one allocation block (??? really?
1320 // shouldn't that be an error?).
1322 nextBlock
= howmany(peof
, vcb
->blockSize
); // number of allocation blocks to remain in file
1323 peof
= (SInt64
)((SInt64
)nextBlock
* (SInt64
)vcb
->blockSize
); // number of bytes in those blocks
1324 if ((vcb
->vcbSigWord
== kHFSSigWord
) && (peof
>= kTwoGigabytes
)) {
1326 DebugStr("\pHFS: Trying to truncate a file to 2GB or more");
1328 err
= fileBoundsErr
;
1333 // Update FCB's length
1336 * XXX Any errors could cause ff_blocks and c_blocks to get out of sync...
1338 numBlocks
= peof
/ vcb
->blockSize
;
1339 FTOC(fcb
)->c_blocks
-= (fcb
->ff_blocks
- numBlocks
);
1340 fcb
->ff_blocks
= numBlocks
;
1342 // this catalog entry is modified and *must* get forced
1343 // to disk when hfs_update() is called
1344 FTOC(fcb
)->c_flag
|= C_MODIFIED
| C_FORCEUPDATE
;
1347 // If the new PEOF is 0, then truncateToExtent has no meaning (we should always deallocate
1353 // Deallocate all the extents for this fork
1354 err
= DeallocateFork(vcb
, FTOC(fcb
)->c_fileid
, forkType
, fcb
->fcbExtents
, &recordDeleted
);
1355 if (err
!= noErr
) goto ErrorExit
; // got some error, so return it
1357 // Update the catalog extent record (making sure it's zeroed out)
1359 for (i
=0; i
< kHFSPlusExtentDensity
; i
++) {
1360 fcb
->fcbExtents
[i
].startBlock
= 0;
1361 fcb
->fcbExtents
[i
].blockCount
= 0;
1368 // Find the extent containing byte (peof-1). This is the last extent we'll keep.
1369 // (If truncateToExtent is true, we'll keep the whole extent; otherwise, we'll only
1370 // keep up through peof). The search will tell us how many allocation blocks exist
1371 // in the found extent plus all previous extents.
1373 err
= SearchExtentFile(vcb
, fcb
, peof
-1, &key
, extentRecord
, &extentIndex
, &hint
, &extentNextBlock
);
1374 if (err
!= noErr
) goto ErrorExit
;
1376 extentChanged
= false; // haven't changed the extent yet
1378 if (!truncateToExtent
) {
1380 // Shorten this extent. It may be the case that the entire extent gets
1383 numBlocks
= extentNextBlock
- nextBlock
; // How many blocks in this extent to free up
1384 if (numBlocks
!= 0) {
1385 // Compute first volume allocation block to free
1386 startBlock
= extentRecord
[extentIndex
].startBlock
+ extentRecord
[extentIndex
].blockCount
- numBlocks
;
1387 // Free the blocks in bitmap
1388 err
= BlockDeallocate(vcb
, startBlock
, numBlocks
);
1389 if (err
!= noErr
) goto ErrorExit
;
1390 // Adjust length of this extent
1391 extentRecord
[extentIndex
].blockCount
-= numBlocks
;
1392 // If extent is empty, set start block to 0
1393 if (extentRecord
[extentIndex
].blockCount
== 0)
1394 extentRecord
[extentIndex
].startBlock
= 0;
1395 // Remember that we changed the extent record
1396 extentChanged
= true;
1401 // Now move to the next extent in the record, and set up the file allocation block number
1403 nextBlock
= extentNextBlock
; // Next file allocation block to free
1404 ++extentIndex
; // Its index within the extent record
1407 // Release all following extents in this extent record. Update the record.
1409 while (extentIndex
< numExtentsPerRecord
&& extentRecord
[extentIndex
].blockCount
!= 0) {
1410 numBlocks
= extentRecord
[extentIndex
].blockCount
;
1411 // Deallocate this extent
1412 err
= BlockDeallocate(vcb
, extentRecord
[extentIndex
].startBlock
, numBlocks
);
1413 if (err
!= noErr
) goto ErrorExit
;
1414 // Update next file allocation block number
1415 nextBlock
+= numBlocks
;
1416 // Zero out start and length of this extent to delete it from record
1417 extentRecord
[extentIndex
].startBlock
= 0;
1418 extentRecord
[extentIndex
].blockCount
= 0;
1419 // Remember that we changed an extent
1420 extentChanged
= true;
1421 // Move to next extent in record
1426 // If any of the extents in the current record were changed, then update that
1427 // record (in the FCB, or extents file).
1429 if (extentChanged
) {
1430 err
= UpdateExtentRecord(vcb
, fcb
, &key
, extentRecord
, hint
);
1431 if (err
!= noErr
) goto ErrorExit
;
1435 // If there are any following allocation blocks, then we need
1436 // to seach for their extent records and delete those allocation
1439 if (nextBlock
< physNumBlocks
)
1440 err
= TruncateExtents(vcb
, forkType
, FTOC(fcb
)->c_fileid
, nextBlock
, &recordDeleted
);
1445 (void) FlushExtentFile(vcb
);
1456 OSErr
HeadTruncateFile (
1461 HFSPlusExtentRecord extents
;
1462 HFSPlusExtentRecord tailExtents
;
1463 HFSCatalogNodeID fileID
;
1473 if (vcb
->vcbSigWord
!= kHFSPlusSigWord
)
1476 forkType
= FORK_IS_RSRC(fcb
) ? kResourceForkType
: kDataForkType
;
1477 fileID
= FTOC(fcb
)->c_fileid
;
1478 bzero(tailExtents
, sizeof(tailExtents
));
1484 * Process catalog resident extents
1486 for (i
= 0, j
= 0; i
< kHFSPlusExtentDensity
; ++i
) {
1487 blkcnt
= fcb
->fcbExtents
[i
].blockCount
;
1489 break; /* end of extents */
1491 if (blksfreed
< headblks
) {
1492 error
= BlockDeallocate(vcb
, fcb
->fcbExtents
[i
].startBlock
, blkcnt
);
1494 * Any errors after the first BlockDeallocate
1495 * must be ignored so we can put the file in
1500 goto ErrorExit
; /* uh oh */
1503 printf("HeadTruncateFile: problems deallocating %s (%d)\n",
1504 FTOC(fcb
)->c_desc
.cd_nameptr
? FTOC(fcb
)->c_desc
.cd_nameptr
: "", error
);
1508 blksfreed
+= blkcnt
;
1509 fcb
->fcbExtents
[i
].startBlock
= 0;
1510 fcb
->fcbExtents
[i
].blockCount
= 0;
1512 tailExtents
[j
].startBlock
= fcb
->fcbExtents
[i
].startBlock
;
1513 tailExtents
[j
].blockCount
= blkcnt
;
1522 lockflags
= hfs_systemfile_lock(vcb
, SFL_EXTENTS
, HFS_EXCLUSIVE_LOCK
);
1525 * Process overflow extents
1530 error
= FindExtentRecord(vcb
, forkType
, fileID
, startblk
, false, NULL
, extents
, NULL
);
1533 * Any errors after the first BlockDeallocate
1534 * must be ignored so we can put the file in
1537 if (error
!= btNotFound
)
1538 printf("HeadTruncateFile: problems finding extents %s (%d)\n",
1539 FTOC(fcb
)->c_desc
.cd_nameptr
? FTOC(fcb
)->c_desc
.cd_nameptr
: "", error
);
1544 for(i
= 0, extblks
= 0; i
< kHFSPlusExtentDensity
; ++i
) {
1545 blkcnt
= extents
[i
].blockCount
;
1547 break; /* end of extents */
1549 if (blksfreed
< headblks
) {
1550 error
= BlockDeallocate(vcb
, extents
[i
].startBlock
, blkcnt
);
1552 printf("HeadTruncateFile: problems deallocating %s (%d)\n",
1553 FTOC(fcb
)->c_desc
.cd_nameptr
? FTOC(fcb
)->c_desc
.cd_nameptr
: "", error
);
1556 blksfreed
+= blkcnt
;
1558 tailExtents
[j
].startBlock
= extents
[i
].startBlock
;
1559 tailExtents
[j
].blockCount
= blkcnt
;
1565 error
= DeleteExtentRecord(vcb
, forkType
, fileID
, startblk
);
1567 printf("HeadTruncateFile: problems deallocating %s (%d)\n",
1568 FTOC(fcb
)->c_desc
.cd_nameptr
? FTOC(fcb
)->c_desc
.cd_nameptr
: "", error
);
1573 break; /* all done */
1575 startblk
+= extblks
;
1577 hfs_systemfile_unlock(vcb
, lockflags
);
1581 bcopy(tailExtents
, fcb
->fcbExtents
, sizeof(tailExtents
));
1582 blkcnt
= fcb
->ff_blocks
- headblks
;
1583 FTOC(fcb
)->c_blocks
-= blkcnt
;
1584 fcb
->ff_blocks
= blkcnt
;
1586 FTOC(fcb
)->c_flag
|= C_FORCEUPDATE
;
1587 FTOC(fcb
)->c_touch_chgtime
= TRUE
;
1589 (void) FlushExtentFile(vcb
);
1593 return MacToVFSError(error
);
1598 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
1599 // Routine: SearchExtentRecord (was XRSearch)
1601 // Function: Searches extent record for the extent mapping a given file
1602 // allocation block number (FABN).
1604 // Input: searchFABN - desired FABN
1605 // extentData - pointer to extent data record (xdr)
1606 // extentDataStartFABN - beginning FABN for extent record
1608 // Output: foundExtentDataOffset - offset to extent entry within xdr
1609 // result = noErr, offset to extent mapping desired FABN
1610 // result = FXRangeErr, offset to last extent in record
1611 // endingFABNPlusOne - ending FABN +1
1612 // noMoreExtents - True if the extent was not found, and the
1613 // extent record was not full (so don't bother
1614 // looking in subsequent records); false otherwise.
1616 // Result: noErr = ok
1617 // FXRangeErr = desired FABN > last mapped FABN in record
1618 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
1620 static OSErr
SearchExtentRecord(
1623 const HFSPlusExtentRecord extentData
,
1624 UInt32 extentDataStartFABN
,
1625 UInt32
*foundExtentIndex
,
1626 UInt32
*endingFABNPlusOne
,
1627 Boolean
*noMoreExtents
)
1631 UInt32 numberOfExtents
;
1632 UInt32 numAllocationBlocks
;
1633 Boolean foundExtent
;
1635 *endingFABNPlusOne
= extentDataStartFABN
;
1636 *noMoreExtents
= false;
1637 foundExtent
= false;
1639 if (vcb
->vcbSigWord
== kHFSPlusSigWord
)
1640 numberOfExtents
= kHFSPlusExtentDensity
;
1642 numberOfExtents
= kHFSExtentDensity
;
1644 for( extentIndex
= 0; extentIndex
< numberOfExtents
; ++extentIndex
)
1647 // Loop over the extent record and find the search FABN.
1649 numAllocationBlocks
= extentData
[extentIndex
].blockCount
;
1650 if ( numAllocationBlocks
== 0 )
1655 *endingFABNPlusOne
+= numAllocationBlocks
;
1657 if( searchFABN
< *endingFABNPlusOne
)
1659 // Found the extent.
1667 // Found the extent. Note the extent offset
1668 *foundExtentIndex
= extentIndex
;
1672 // Did not find the extent. Set foundExtentDataOffset accordingly
1673 if( extentIndex
> 0 )
1675 *foundExtentIndex
= extentIndex
- 1;
1679 *foundExtentIndex
= 0;
1682 // If we found an empty extent, then set noMoreExtents.
1683 if (extentIndex
< numberOfExtents
)
1684 *noMoreExtents
= true;
1686 // Finally, return an error to the caller
1693 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
1694 // Routine: SearchExtentFile (was XFSearch)
1696 // Function: Searches extent file (including the FCB resident extent record)
1697 // for the extent mapping a given file position.
1699 // Input: vcb - VCB pointer
1700 // fcb - FCB pointer
1701 // filePosition - file position (byte address)
1703 // Output: foundExtentKey - extent key record (xkr)
1704 // If extent was found in the FCB's resident extent record,
1705 // then foundExtentKey->keyLength will be set to 0.
1706 // foundExtentData - extent data record(xdr)
1707 // foundExtentIndex - index to extent entry in xdr
1708 // result = 0, offset to extent mapping desired FABN
1709 // result = FXRangeErr, offset to last extent in record
1710 // (i.e., kNumExtentsPerRecord-1)
1711 // extentBTreeHint - BTree hint for extent record
1712 // kNoHint = Resident extent record
1713 // endingFABNPlusOne - ending FABN +1
1716 // noErr Found an extent that contains the given file position
1717 // FXRangeErr Given position is beyond the last allocated extent
1718 // (other) (some other internal I/O error)
1719 //\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b\8b
1721 static OSErr
SearchExtentFile(
1724 SInt64 filePosition
,
1725 HFSPlusExtentKey
*foundExtentKey
,
1726 HFSPlusExtentRecord foundExtentData
,
1727 UInt32
*foundExtentIndex
,
1728 UInt32
*extentBTreeHint
,
1729 UInt32
*endingFABNPlusOne
)
1732 UInt32 filePositionBlock
;
1734 Boolean noMoreExtents
;
1737 temp64
= filePosition
/ (SInt64
)vcb
->blockSize
;
1738 filePositionBlock
= (UInt32
)temp64
;
1740 bcopy ( fcb
->fcbExtents
, foundExtentData
, sizeof(HFSPlusExtentRecord
));
1742 // Search the resident FCB first.
1743 err
= SearchExtentRecord( vcb
, filePositionBlock
, foundExtentData
, 0,
1744 foundExtentIndex
, endingFABNPlusOne
, &noMoreExtents
);
1746 if( err
== noErr
) {
1747 // Found the extent. Set results accordingly
1748 *extentBTreeHint
= kNoHint
; // no hint, because not in the BTree
1749 foundExtentKey
->keyLength
= 0; // 0 = the FCB itself
1754 // Didn't find extent in FCB. If FCB's extent record wasn't full, there's no point
1755 // in searching the extents file. Note that SearchExtentRecord left us pointing at
1756 // the last valid extent (or the first one, if none were valid). This means we need
1757 // to fill in the hint and key outputs, just like the "if" statement above.
1758 if ( noMoreExtents
) {
1759 *extentBTreeHint
= kNoHint
; // no hint, because not in the BTree
1760 foundExtentKey
->keyLength
= 0; // 0 = the FCB itself
1761 err
= fxRangeErr
; // There are no more extents, so must be beyond PEOF
1766 // Find the desired record, or the previous record if it is the same fork
1768 lockflags
= hfs_systemfile_lock(vcb
, SFL_EXTENTS
, HFS_EXCLUSIVE_LOCK
);
1770 err
= FindExtentRecord(vcb
, FORK_IS_RSRC(fcb
) ? kResourceForkType
: kDataForkType
,
1771 FTOC(fcb
)->c_fileid
, filePositionBlock
, true, foundExtentKey
, foundExtentData
, extentBTreeHint
);
1772 hfs_systemfile_unlock(vcb
, lockflags
);
1774 if (err
== btNotFound
) {
1776 // If we get here, the desired position is beyond the extents in the FCB, and there are no extents
1777 // in the extents file. Return the FCB's extents and a range error.
1779 *extentBTreeHint
= kNoHint
;
1780 foundExtentKey
->keyLength
= 0;
1781 err
= GetFCBExtentRecord(fcb
, foundExtentData
);
1782 // Note: foundExtentIndex and endingFABNPlusOne have already been set as a result of the very
1783 // first SearchExtentRecord call in this function (when searching in the FCB's extents, and
1784 // we got a range error).
1790 // If we get here, there was either a BTree error, or we found an appropriate record.
1791 // If we found a record, then search it for the correct index into the extents.
1794 // Find appropriate index into extent record
1795 err
= SearchExtentRecord(vcb
, filePositionBlock
, foundExtentData
, foundExtentKey
->startBlock
,
1796 foundExtentIndex
, endingFABNPlusOne
, &noMoreExtents
);
1805 //============================================================================
1806 // Routine: UpdateExtentRecord
1808 // Function: Write new extent data to an existing extent record with a given key.
1809 // If all of the extents are empty, and the extent record is in the
1810 // extents file, then the record is deleted.
1812 // Input: vcb - the volume containing the extents
1813 // fcb - the file that owns the extents
1814 // extentFileKey - pointer to extent key record (xkr)
1815 // If the key length is 0, then the extents are actually part
1816 // of the catalog record, stored in the FCB.
1817 // extentData - pointer to extent data record (xdr)
1818 // extentBTreeHint - hint for given key, or kNoHint
1820 // Result: noErr = ok
1821 // (other) = error from BTree
1822 //============================================================================
1824 static OSErr
UpdateExtentRecord (
1827 const HFSPlusExtentKey
*extentFileKey
,
1828 const HFSPlusExtentRecord extentData
,
1829 UInt32 extentBTreeHint
)
1833 if (extentFileKey
->keyLength
== 0) { // keyLength == 0 means the FCB's extent record
1834 BlockMoveData(extentData
, fcb
->fcbExtents
, sizeof(HFSPlusExtentRecord
));
1835 FTOC(fcb
)->c_flag
|= C_MODIFIED
;
1838 BTreeIterator
* btIterator
;
1839 FSBufferDescriptor btRecord
;
1840 UInt16 btRecordSize
;
1845 // Need to find and change a record in Extents BTree
1847 btFCB
= GetFileControlBlock(vcb
->extentsRefNum
);
1849 MALLOC(btIterator
, BTreeIterator
*, sizeof(*btIterator
), M_TEMP
, M_WAITOK
);
1850 bzero(btIterator
, sizeof(*btIterator
));
1853 * The lock taken by callers of ExtendFileC/TruncateFileC is
1854 * speculative and only occurs when the file already has
1855 * overflow extents. So we need to make sure we have the lock
1856 * here. The extents btree lock can be nested (its recursive)
1857 * so we always take it here.
1859 lockflags
= hfs_systemfile_lock(vcb
, SFL_EXTENTS
, HFS_EXCLUSIVE_LOCK
);
1861 if (vcb
->vcbSigWord
== kHFSSigWord
) {
1862 HFSExtentKey
* key
; // Actual extent key used on disk in HFS
1863 HFSExtentRecord foundData
; // The extent data actually found
1865 key
= (HFSExtentKey
*) &btIterator
->key
;
1866 key
->keyLength
= kHFSExtentKeyMaximumLength
;
1867 key
->forkType
= extentFileKey
->forkType
;
1868 key
->fileID
= extentFileKey
->fileID
;
1869 key
->startBlock
= extentFileKey
->startBlock
;
1871 btIterator
->hint
.index
= 0;
1872 btIterator
->hint
.nodeNum
= extentBTreeHint
;
1874 btRecord
.bufferAddress
= &foundData
;
1875 btRecord
.itemSize
= sizeof(HFSExtentRecord
);
1876 btRecord
.itemCount
= 1;
1878 err
= BTSearchRecord(btFCB
, btIterator
, &btRecord
, &btRecordSize
, btIterator
);
1881 err
= HFSPlusToHFSExtents(extentData
, (HFSExtentDescriptor
*)&foundData
);
1884 err
= BTReplaceRecord(btFCB
, btIterator
, &btRecord
, btRecordSize
);
1885 (void) BTFlushPath(btFCB
);
1887 else { // HFS Plus volume
1888 HFSPlusExtentRecord foundData
; // The extent data actually found
1890 BlockMoveData(extentFileKey
, &btIterator
->key
, sizeof(HFSPlusExtentKey
));
1892 btIterator
->hint
.index
= 0;
1893 btIterator
->hint
.nodeNum
= extentBTreeHint
;
1895 btRecord
.bufferAddress
= &foundData
;
1896 btRecord
.itemSize
= sizeof(HFSPlusExtentRecord
);
1897 btRecord
.itemCount
= 1;
1899 err
= BTSearchRecord(btFCB
, btIterator
, &btRecord
, &btRecordSize
, btIterator
);
1902 BlockMoveData(extentData
, &foundData
, sizeof(HFSPlusExtentRecord
));
1903 err
= BTReplaceRecord(btFCB
, btIterator
, &btRecord
, btRecordSize
);
1905 (void) BTFlushPath(btFCB
);
1907 hfs_systemfile_unlock(vcb
, lockflags
);
1908 FREE(btIterator
, M_TEMP
);
1917 static OSErr
HFSPlusToHFSExtents(
1918 const HFSPlusExtentRecord oldExtents
,
1919 HFSExtentRecord newExtents
)
1925 // copy the first 3 extents
1926 newExtents
[0].startBlock
= oldExtents
[0].startBlock
;
1927 newExtents
[0].blockCount
= oldExtents
[0].blockCount
;
1928 newExtents
[1].startBlock
= oldExtents
[1].startBlock
;
1929 newExtents
[1].blockCount
= oldExtents
[1].blockCount
;
1930 newExtents
[2].startBlock
= oldExtents
[2].startBlock
;
1931 newExtents
[2].blockCount
= oldExtents
[2].blockCount
;
1934 if (oldExtents
[3].startBlock
|| oldExtents
[3].blockCount
) {
1935 DebugStr("\pExtentRecord with > 3 extents is invalid for HFS");
1946 static OSErr
GetFCBExtentRecord(
1948 HFSPlusExtentRecord extents
)
1951 BlockMoveData(fcb
->fcbExtents
, extents
, sizeof(HFSPlusExtentRecord
));
1957 //_________________________________________________________________________________
1959 // Routine: ExtentsAreIntegral
1961 // Purpose: Ensure that each extent can hold an integral number of nodes
1962 // Called by the NodesAreContiguous function
1963 //_________________________________________________________________________________
1965 static Boolean
ExtentsAreIntegral(
1966 const HFSPlusExtentRecord extentRecord
,
1968 UInt32
*blocksChecked
,
1969 Boolean
*checkedLastExtent
)
1975 *checkedLastExtent
= false;
1977 for(extentIndex
= 0; extentIndex
< kHFSPlusExtentDensity
; extentIndex
++)
1979 blocks
= extentRecord
[extentIndex
].blockCount
;
1983 *checkedLastExtent
= true;
1987 *blocksChecked
+= blocks
;
1997 //_________________________________________________________________________________
1999 // Routine: NodesAreContiguous
2001 // Purpose: Ensure that all b-tree nodes are contiguous on disk
2002 // Called by BTOpenPath during volume mount
2003 //_________________________________________________________________________________
2006 Boolean
NodesAreContiguous(
2013 UInt32 blocksChecked
;
2015 HFSPlusExtentKey key
;
2016 HFSPlusExtentRecord extents
;
2018 Boolean lastExtentReached
;
2022 if (vcb
->blockSize
>= nodeSize
)
2025 mask
= (nodeSize
/ vcb
->blockSize
) - 1;
2027 // check the local extents
2028 (void) GetFCBExtentRecord(fcb
, extents
);
2029 if ( !ExtentsAreIntegral(extents
, mask
, &blocksChecked
, &lastExtentReached
) )
2032 if ( lastExtentReached
||
2033 (SInt64
)((SInt64
)blocksChecked
* (SInt64
)vcb
->blockSize
) >= (SInt64
)fcb
->ff_size
)
2036 startBlock
= blocksChecked
;
2038 lockflags
= hfs_systemfile_lock(vcb
, SFL_EXTENTS
, HFS_EXCLUSIVE_LOCK
);
2040 // check the overflow extents (if any)
2041 while ( !lastExtentReached
)
2043 result
= FindExtentRecord(vcb
, kDataForkType
, fcb
->ff_cp
->c_fileid
, startBlock
, FALSE
, &key
, extents
, &hint
);
2046 if ( !ExtentsAreIntegral(extents
, mask
, &blocksChecked
, &lastExtentReached
) ) {
2047 hfs_systemfile_unlock(vcb
, lockflags
);
2050 startBlock
+= blocksChecked
;
2052 hfs_systemfile_unlock(vcb
, lockflags
);