2 * Copyright (c) 2000-2003 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@
23 File: VolumeAllocation.c
25 Contains: Routines for accessing and modifying the volume bitmap.
29 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
36 Allocate space on a volume. Can allocate space contiguously.
37 If not contiguous, then allocation may be less than what was
38 asked for. Returns the starting block number, and number of
39 blocks. (Will only do a single extent???)
41 Deallocate a contiguous run of allocation blocks.
46 Mark a contiguous range of blocks as free. The corresponding
47 bits in the volume bitmap will be cleared.
49 Mark a contiguous range of blocks as allocated. The cor-
50 responding bits in the volume bitmap are set. Also tests to see
51 if any of the blocks were previously unallocated.
53 Find a contiguous range of blocks of a given size. The caller
54 specifies where to begin the search (by block number). The
55 block number of the first block in the range is returned.
57 Find and allocate a contiguous range of blocks up to a given size. The
58 first range of contiguous free blocks found are allocated, even if there
59 are fewer blocks than requested (and even if a contiguous range of blocks
60 of the given size exists elsewhere).
62 Find and allocate a contiguous range of blocks of a given size. If
63 a contiguous range of free blocks of the given size isn't found, then
64 the allocation fails (i.e. it is "all or nothing").
67 Try to allocate space from known free space in the volume's
71 Given an allocation block number, read the bitmap block that
72 contains that allocation block into a caller-supplied buffer.
75 Release a bitmap block back into the buffer cache.
78 #include "../../hfs_macos_defs.h"
80 #include <sys/types.h>
82 #include <sys/systm.h>
84 #include "../../hfs.h"
85 #include "../../hfs_dbg.h"
86 #include "../../hfs_format.h"
87 #include "../../hfs_endian.h"
89 #include "../headers/FileMgrInternal.h"
97 kBitsWithinWordMask
= kBitsPerWord
-1
100 #define kLowBitInWordMask 0x00000001ul
101 #define kHighBitInWordMask 0x80000000ul
102 #define kAllBitsSetInWord 0xFFFFFFFFul
105 static OSErr
ReadBitmapBlock(
111 static OSErr
ReleaseBitmapBlock(
116 static OSErr
BlockAllocateAny(
118 UInt32 startingBlock
,
122 UInt32
*actualStartBlock
,
123 UInt32
*actualNumBlocks
);
125 static OSErr
BlockAllocateContig(
127 UInt32 startingBlock
,
131 UInt32
*actualStartBlock
,
132 UInt32
*actualNumBlocks
);
134 static OSErr
BlockFindContiguous(
136 UInt32 startingBlock
,
141 UInt32
*actualStartBlock
,
142 UInt32
*actualNumBlocks
);
144 static OSErr
BlockAllocateKnown(
147 UInt32
*actualStartBlock
,
148 UInt32
*actualNumBlocks
);
152 ;________________________________________________________________________________
156 ; Function: Allocate space on a volume. If contiguous allocation is requested,
157 ; at least the requested number of bytes will be allocated or an
158 ; error will be returned. If contiguous allocation is not forced,
159 ; the space will be allocated at the first free fragment following
160 ; the requested starting allocation block. If there is not enough
161 ; room there, a block of less than the requested size will be
164 ; If the requested starting block is 0 (for new file allocations),
165 ; the volume's allocation block pointer will be used as a starting
169 ; vcb - Pointer to ExtendedVCB for the volume to allocate space on
170 ; fcb - Pointer to FCB for the file for which storage is being allocated
171 ; startingBlock - Preferred starting allocation block, 0 = no preference
172 ; forceContiguous - Force contiguous flag - if bit 0 set (NE), allocation is contiguous
173 ; or an error is returned
175 ; minBlocks - Number of blocks requested. If the allocation is non-contiguous,
176 ; less than this may actually be allocated
177 ; maxBlocks - The maximum number of blocks to allocate. If there is additional free
178 ; space after bytesRequested, then up to maxBlocks bytes should really
179 ; be allocated. (Used by ExtendFileC to round up allocations to a multiple
180 ; of the file's clump size.)
183 ; (result) - Error code, zero for successful allocation
184 ; *startBlock - Actual starting allocation block
185 ; *actualBlocks - Actual number of allocation blocks allocated
188 ; The volume bitmap is read and updated; the volume bitmap cache may be changed.
189 ;________________________________________________________________________________
193 OSErr
BlockAllocate (
194 ExtendedVCB
*vcb
, /* which volume to allocate space on */
195 UInt32 startingBlock
, /* preferred starting block, or 0 for no preference */
196 UInt32 minBlocks
, /* desired number of blocks to allocate */
197 UInt32 maxBlocks
, /* maximum number of blocks to allocate */
198 Boolean forceContiguous
, /* non-zero to force contiguous allocation and to force */
199 /* minBlocks bytes to actually be allocated */
202 UInt32
*actualStartBlock
, /* actual first block of allocation */
203 UInt32
*actualNumBlocks
) /* number of blocks actually allocated; if forceContiguous */
204 /* was zero, then this may represent fewer than minBlocks */
208 Boolean updateAllocPtr
= false; // true if nextAllocation needs to be updated
211 // Initialize outputs in case we get an error
213 *actualStartBlock
= 0;
214 *actualNumBlocks
= 0;
215 freeBlocks
= hfs_freeblks(VCBTOHFS(vcb
), 0);
218 // If the disk is already full, don't bother.
220 if (freeBlocks
== 0) {
224 if (forceContiguous
&& freeBlocks
< minBlocks
) {
229 * Clip if necessary so we don't over-subscribe the free blocks.
231 if (minBlocks
> freeBlocks
) {
232 minBlocks
= freeBlocks
;
234 if (maxBlocks
> freeBlocks
) {
235 maxBlocks
= freeBlocks
;
239 // If caller didn't specify a starting block number, then use the volume's
240 // next block to allocate from.
242 if (startingBlock
== 0) {
243 HFS_MOUNT_LOCK(vcb
, TRUE
);
244 startingBlock
= vcb
->nextAllocation
;
245 HFS_MOUNT_UNLOCK(vcb
, TRUE
);
246 updateAllocPtr
= true;
248 if (startingBlock
>= vcb
->totalBlocks
) {
249 startingBlock
= 0; /* overflow so start at beginning */
253 // If the request must be contiguous, then find a sequence of free blocks
254 // that is long enough. Otherwise, find the first free block.
256 if (forceContiguous
) {
257 err
= BlockAllocateContig(vcb
, startingBlock
, minBlocks
, maxBlocks
,
258 useMetaZone
, actualStartBlock
, actualNumBlocks
);
260 * If we allocated from a new position then
261 * also update the roving allocatior.
263 if ((err
== noErr
) &&
264 (*actualStartBlock
> startingBlock
) &&
265 ((*actualStartBlock
< VCBTOHFS(vcb
)->hfs_metazone_start
) ||
266 (*actualStartBlock
> VCBTOHFS(vcb
)->hfs_metazone_end
))) {
267 HFS_MOUNT_LOCK(vcb
, TRUE
);
268 vcb
->nextAllocation
= *actualStartBlock
;
269 HFS_MOUNT_UNLOCK(vcb
, TRUE
);
273 * Scan the bitmap once, gather the N largest free extents, then
274 * allocate from these largest extents. Repeat as needed until
275 * we get all the space we needed. We could probably build up
276 * that list when the higher level caller tried (and failed) a
277 * contiguous allocation first.
279 err
= BlockAllocateKnown(vcb
, maxBlocks
, actualStartBlock
, actualNumBlocks
);
280 if (err
== dskFulErr
)
281 err
= BlockAllocateAny(vcb
, startingBlock
, vcb
->totalBlocks
,
282 maxBlocks
, useMetaZone
, actualStartBlock
,
284 if (err
== dskFulErr
)
285 err
= BlockAllocateAny(vcb
, 1, startingBlock
, maxBlocks
,
286 useMetaZone
, actualStartBlock
,
291 // if we actually allocated something then go update the
292 // various bits of state that we maintain regardless of
293 // whether there was an error (i.e. partial allocations
294 // still need to update things like the free block count).
296 if (*actualNumBlocks
!= 0) {
298 // If we used the volume's roving allocation pointer, then we need to update it.
299 // Adding in the length of the current allocation might reduce the next allocate
300 // call by avoiding a re-scan of the already allocated space. However, the clump
301 // just allocated can quite conceivably end up being truncated or released when
302 // the file is closed or its EOF changed. Leaving the allocation pointer at the
303 // start of the last allocation will avoid unnecessary fragmentation in this case.
305 HFS_MOUNT_LOCK(vcb
, TRUE
);
307 if (updateAllocPtr
&&
308 ((*actualStartBlock
< VCBTOHFS(vcb
)->hfs_metazone_start
) ||
309 (*actualStartBlock
> VCBTOHFS(vcb
)->hfs_metazone_end
))) {
310 vcb
->nextAllocation
= *actualStartBlock
;
313 // Update the number of free blocks on the volume
315 vcb
->freeBlocks
-= *actualNumBlocks
;
317 HFS_MOUNT_UNLOCK(vcb
, TRUE
);
319 hfs_generate_volume_notifications(VCBTOHFS(vcb
));
327 ;________________________________________________________________________________
329 ; Routine: BlkDealloc
331 ; Function: Update the bitmap to deallocate a run of disk allocation blocks
334 ; vcb - Pointer to ExtendedVCB for the volume to free space on
335 ; firstBlock - First allocation block to be freed
336 ; numBlocks - Number of allocation blocks to free up (must be > 0!)
339 ; (result) - Result code
342 ; The volume bitmap is read and updated; the volume bitmap cache may be changed.
343 ;________________________________________________________________________________
347 OSErr
BlockDeallocate (
348 ExtendedVCB
*vcb
, // Which volume to deallocate space on
349 UInt32 firstBlock
, // First block in range to deallocate
350 UInt32 numBlocks
) // Number of contiguous blocks to deallocate
355 // If no blocks to deallocate, then exit early
357 if (numBlocks
== 0) {
363 // Call internal routine to free the sequence of blocks
365 err
= BlockMarkFree(vcb
, firstBlock
, numBlocks
);
370 // Update the volume's free block count, and mark the VCB as dirty.
372 HFS_MOUNT_LOCK(vcb
, TRUE
);
373 vcb
->freeBlocks
+= numBlocks
;
374 if (vcb
->nextAllocation
== (firstBlock
+ numBlocks
))
375 vcb
->nextAllocation
-= numBlocks
;
377 HFS_MOUNT_UNLOCK(vcb
, TRUE
);
379 hfs_generate_volume_notifications(VCBTOHFS(vcb
));
386 UInt8 freebitcount
[16] = {
387 4, 3, 3, 2, 3, 2, 2, 1, /* 0 1 2 3 4 5 6 7 */
388 3, 2, 2, 1, 2, 1, 1, 0, /* 8 9 A B C D E F */
393 MetaZoneFreeBlocks(ExtendedVCB
*vcb
)
406 bytesleft
= freeblocks
= 0;
408 bit
= VCBTOHFS(vcb
)->hfs_metazone_start
;
412 lastbit
= VCBTOHFS(vcb
)->hfs_metazone_end
;
413 bytesperblock
= vcb
->vcbVBMIOSize
;
416 * Count all the bits from bit to lastbit.
418 while (bit
< lastbit
) {
420 * Get next bitmap block.
422 if (bytesleft
== 0) {
424 (void) ReleaseBitmapBlock(vcb
, blockRef
, false);
427 if (ReadBitmapBlock(vcb
, bit
, &currCache
, &blockRef
) != 0) {
430 buffer
= (UInt8
*)currCache
;
431 bytesleft
= bytesperblock
;
434 freeblocks
+= freebitcount
[byte
& 0x0F];
435 freeblocks
+= freebitcount
[(byte
>> 4) & 0x0F];
440 (void) ReleaseBitmapBlock(vcb
, blockRef
, false);
447 * Obtain the next allocation block (bit) that's
448 * outside the metadata allocation zone.
450 static UInt32
NextBitmapBlock(
454 struct hfsmount
*hfsmp
= VCBTOHFS(vcb
);
456 if ((hfsmp
->hfs_flags
& HFS_METADATA_ZONE
) == 0)
459 * Skip over metadata allocation zone.
461 if ((bit
>= hfsmp
->hfs_metazone_start
) &&
462 (bit
<= hfsmp
->hfs_metazone_end
)) {
463 bit
= hfsmp
->hfs_metazone_end
+ 1;
470 ;_______________________________________________________________________
472 ; Routine: ReadBitmapBlock
474 ; Function: Read in a bitmap block corresponding to a given allocation
475 ; block (bit). Return a pointer to the bitmap block.
478 ; vcb -- Pointer to ExtendedVCB
479 ; bit -- Allocation block whose bitmap block is desired
482 ; buffer -- Pointer to bitmap block corresonding to "block"
484 ;_______________________________________________________________________
486 static OSErr
ReadBitmapBlock(
493 struct buf
*bp
= NULL
;
494 struct vnode
*vp
= NULL
;
499 * volume bitmap blocks are protected by the allocation file lock
501 REQUIRE_FILE_LOCK(vcb
->hfs_allocation_vp
, false);
503 blockSize
= (UInt32
)vcb
->vcbVBMIOSize
;
504 block
= (daddr64_t
)(bit
/ (blockSize
* kBitsPerByte
));
506 if (vcb
->vcbSigWord
== kHFSPlusSigWord
) {
507 vp
= vcb
->hfs_allocation_vp
; /* use allocation file vnode */
510 vp
= VCBTOHFS(vcb
)->hfs_devvp
; /* use device I/O vnode */
511 block
+= vcb
->vcbVBMSt
; /* map to physical block */
514 err
= (int)buf_meta_bread(vp
, block
, blockSize
, NOCRED
, &bp
);
522 *blockRef
= (UInt32
)bp
;
523 *buffer
= (UInt32
*)buf_dataptr(bp
);
532 ;_______________________________________________________________________
534 ; Routine: ReleaseBitmapBlock
536 ; Function: Relase a bitmap block.
542 ;_______________________________________________________________________
544 static OSErr
ReleaseBitmapBlock(
549 struct buf
*bp
= (struct buf
*)blockRef
;
553 panic("ReleaseBitmapBlock: missing bp");
560 struct hfsmount
*hfsmp
= VCBTOHFS(vcb
);
563 journal_modify_block_end(hfsmp
->jnl
, bp
);
577 _______________________________________________________________________
579 Routine: BlockAllocateContig
581 Function: Allocate a contiguous group of allocation blocks. The
582 allocation is all-or-nothing. The caller guarantees that
583 there are enough free blocks (though they may not be
584 contiguous, in which case this call will fail).
587 vcb Pointer to volume where space is to be allocated
588 startingBlock Preferred first block for allocation
589 minBlocks Minimum number of contiguous blocks to allocate
590 maxBlocks Maximum number of contiguous blocks to allocate
594 actualStartBlock First block of range allocated, or 0 if error
595 actualNumBlocks Number of blocks allocated, or 0 if error
596 _______________________________________________________________________
598 static OSErr
BlockAllocateContig(
600 UInt32 startingBlock
,
604 UInt32
*actualStartBlock
,
605 UInt32
*actualNumBlocks
)
610 // Find a contiguous group of blocks at least minBlocks long.
611 // Determine the number of contiguous blocks available (up
616 * NOTE: If the only contiguous free extent of at least minBlocks
617 * crosses startingBlock (i.e. starts before, ends after), then we
618 * won't find it. Earlier versions *did* find this case by letting
619 * the second search look past startingBlock by minBlocks. But
620 * with the free extent cache, this can lead to duplicate entries
621 * in the cache, causing the same blocks to be allocated twice.
623 err
= BlockFindContiguous(vcb
, startingBlock
, vcb
->totalBlocks
, minBlocks
,
624 maxBlocks
, useMetaZone
, actualStartBlock
, actualNumBlocks
);
625 if (err
== dskFulErr
&& startingBlock
!= 0) {
627 * Constrain the endingBlock so we don't bother looking for ranges
628 * that would overlap those found in the previous call.
630 err
= BlockFindContiguous(vcb
, 1, startingBlock
, minBlocks
, maxBlocks
,
631 useMetaZone
, actualStartBlock
, actualNumBlocks
);
633 if (err
!= noErr
) goto Exit
;
636 if ((*actualStartBlock
+ *actualNumBlocks
) > vcb
->totalBlocks
)
637 panic("BlockAllocateContig: allocation overflow on \"%s\"", vcb
->vcbVN
);
640 // Now mark those blocks allocated.
642 err
= BlockMarkAllocated(vcb
, *actualStartBlock
, *actualNumBlocks
);
646 *actualStartBlock
= 0;
647 *actualNumBlocks
= 0;
654 _______________________________________________________________________
656 Routine: BlockAllocateAny
658 Function: Allocate one or more allocation blocks. If there are fewer
659 free blocks than requested, all free blocks will be
660 allocated. The caller guarantees that there is at least
664 vcb Pointer to volume where space is to be allocated
665 startingBlock Preferred first block for allocation
666 endingBlock Last block to check + 1
667 maxBlocks Maximum number of contiguous blocks to allocate
671 actualStartBlock First block of range allocated, or 0 if error
672 actualNumBlocks Number of blocks allocated, or 0 if error
673 _______________________________________________________________________
675 static OSErr
BlockAllocateAny(
677 UInt32 startingBlock
,
678 register UInt32 endingBlock
,
681 UInt32
*actualStartBlock
,
682 UInt32
*actualNumBlocks
)
685 register UInt32 block
; // current block number
686 register UInt32 currentWord
; // Pointer to current word within bitmap block
687 register UInt32 bitMask
; // Word with given bits already set (ready to OR in)
688 register UInt32 wordsLeft
; // Number of words left in this bitmap block
689 UInt32
*buffer
= NULL
;
690 UInt32
*currCache
= NULL
;
693 UInt32 wordsPerBlock
;
694 Boolean dirty
= false;
695 struct hfsmount
*hfsmp
= VCBTOHFS(vcb
);
697 // Since this routine doesn't wrap around
698 if (maxBlocks
> (endingBlock
- startingBlock
)) {
699 maxBlocks
= endingBlock
- startingBlock
;
703 * Skip over metadata blocks.
706 startingBlock
= NextBitmapBlock(vcb
, startingBlock
);
709 // Pre-read the first bitmap block
711 err
= ReadBitmapBlock(vcb
, startingBlock
, &currCache
, &blockRef
);
712 if (err
!= noErr
) goto Exit
;
716 // Set up the current position within the block
719 UInt32 wordIndexInBlock
;
721 bitsPerBlock
= vcb
->vcbVBMIOSize
* kBitsPerByte
;
722 wordsPerBlock
= vcb
->vcbVBMIOSize
/ kBytesPerWord
;
724 wordIndexInBlock
= (startingBlock
& (bitsPerBlock
-1)) / kBitsPerWord
;
725 buffer
+= wordIndexInBlock
;
726 wordsLeft
= wordsPerBlock
- wordIndexInBlock
;
727 currentWord
= SWAP_BE32 (*buffer
);
728 bitMask
= kHighBitInWordMask
>> (startingBlock
& kBitsWithinWordMask
);
732 // Find the first unallocated block
735 while (block
< endingBlock
) {
736 if ((currentWord
& bitMask
) == 0)
744 bitMask
= kHighBitInWordMask
;
747 if (--wordsLeft
== 0) {
749 buffer
= currCache
= NULL
;
750 err
= ReleaseBitmapBlock(vcb
, blockRef
, false);
751 if (err
!= noErr
) goto Exit
;
754 * Skip over metadata blocks.
757 block
= NextBitmapBlock(vcb
, block
);
758 if (block
>= endingBlock
) {
763 err
= ReadBitmapBlock(vcb
, block
, &currCache
, &blockRef
);
764 if (err
!= noErr
) goto Exit
;
767 wordsLeft
= wordsPerBlock
;
769 currentWord
= SWAP_BE32 (*buffer
);
773 // Did we get to the end of the bitmap before finding a free block?
774 // If so, then couldn't allocate anything.
775 if (block
>= endingBlock
) {
780 // Return the first block in the allocated range
781 *actualStartBlock
= block
;
784 // If we could get the desired number of blocks before hitting endingBlock,
785 // then adjust endingBlock so we won't keep looking. Ideally, the comparison
786 // would be (block + maxBlocks) < endingBlock, but that could overflow. The
787 // comparison below yields identical results, but without overflow.
788 if (block
< (endingBlock
-maxBlocks
)) {
789 endingBlock
= block
+ maxBlocks
; // if we get this far, we've found enough
794 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
798 // Allocate all of the consecutive blocks
800 while ((currentWord
& bitMask
) == 0) {
801 // Allocate this block
802 currentWord
|= bitMask
;
804 // Move to the next block. If no more, then exit.
806 if (block
== endingBlock
)
812 *buffer
= SWAP_BE32 (currentWord
); // update value in bitmap
815 bitMask
= kHighBitInWordMask
;
818 if (--wordsLeft
== 0) {
820 buffer
= currCache
= NULL
;
821 err
= ReleaseBitmapBlock(vcb
, blockRef
, true);
822 if (err
!= noErr
) goto Exit
;
825 * Skip over metadata blocks.
830 nextBlock
= NextBitmapBlock(vcb
, block
);
831 if (nextBlock
!= block
) {
832 goto Exit
; /* allocation gap, so stop */
836 err
= ReadBitmapBlock(vcb
, block
, &currCache
, &blockRef
);
837 if (err
!= noErr
) goto Exit
;
842 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
845 wordsLeft
= wordsPerBlock
;
848 currentWord
= SWAP_BE32 (*buffer
);
851 *buffer
= SWAP_BE32 (currentWord
); // update the last change
855 *actualNumBlocks
= block
- *actualStartBlock
;
858 if ((*actualStartBlock
+ *actualNumBlocks
) > vcb
->totalBlocks
)
859 panic("BlockAllocateAny: allocation overflow on \"%s\"", vcb
->vcbVN
);
862 *actualStartBlock
= 0;
863 *actualNumBlocks
= 0;
867 (void) ReleaseBitmapBlock(vcb
, blockRef
, dirty
);
874 _______________________________________________________________________
876 Routine: BlockAllocateKnown
878 Function: Try to allocate space from known free space in the free
882 vcb Pointer to volume where space is to be allocated
883 maxBlocks Maximum number of contiguous blocks to allocate
886 actualStartBlock First block of range allocated, or 0 if error
887 actualNumBlocks Number of blocks allocated, or 0 if error
890 dskFulErr Free extent cache is empty
891 _______________________________________________________________________
893 static OSErr
BlockAllocateKnown(
896 UInt32
*actualStartBlock
,
897 UInt32
*actualNumBlocks
)
902 UInt32 newStartBlock
, newBlockCount
;
904 if (vcb
->vcbFreeExtCnt
== 0)
907 // Just grab up to maxBlocks of the first (largest) free exent.
908 *actualStartBlock
= vcb
->vcbFreeExt
[0].startBlock
;
909 foundBlocks
= vcb
->vcbFreeExt
[0].blockCount
;
910 if (foundBlocks
> maxBlocks
)
911 foundBlocks
= maxBlocks
;
912 *actualNumBlocks
= foundBlocks
;
914 // Adjust the start and length of that extent.
915 newStartBlock
= vcb
->vcbFreeExt
[0].startBlock
+ foundBlocks
;
916 newBlockCount
= vcb
->vcbFreeExt
[0].blockCount
- foundBlocks
;
918 // The first extent might not be the largest anymore. Bubble up any
919 // (now larger) extents to the top of the list.
920 for (i
=1; i
<vcb
->vcbFreeExtCnt
; ++i
)
922 if (vcb
->vcbFreeExt
[i
].blockCount
> newBlockCount
)
924 vcb
->vcbFreeExt
[i
-1].startBlock
= vcb
->vcbFreeExt
[i
].startBlock
;
925 vcb
->vcbFreeExt
[i
-1].blockCount
= vcb
->vcbFreeExt
[i
].blockCount
;
933 // If this is now the smallest known free extent, then it might be smaller than
934 // other extents we didn't keep track of. So, just forget about this extent.
935 // After the previous loop, (i-1) is the index of the extent we just allocated from.
936 if (i
== vcb
->vcbFreeExtCnt
)
938 // It's now the smallest extent, so forget about it
939 --vcb
->vcbFreeExtCnt
;
943 // It's not the smallest, so store it in its proper place
944 vcb
->vcbFreeExt
[i
-1].startBlock
= newStartBlock
;
945 vcb
->vcbFreeExt
[i
-1].blockCount
= newBlockCount
;
949 if ((*actualStartBlock
+ *actualNumBlocks
) > vcb
->totalBlocks
)
951 printf("BlockAllocateKnown: allocation overflow on \"%s\"", vcb
->vcbVN
);
952 *actualStartBlock
= 0;
953 *actualNumBlocks
= 0;
959 // Now mark the found extent in the bitmap
961 err
= BlockMarkAllocated(vcb
, *actualStartBlock
, *actualNumBlocks
);
969 _______________________________________________________________________
971 Routine: BlockMarkAllocated
973 Function: Mark a contiguous group of blocks as allocated (set in the
974 bitmap). It assumes those bits are currently marked
975 deallocated (clear in the bitmap).
978 vcb Pointer to volume where space is to be allocated
979 startingBlock First block number to mark as allocated
980 numBlocks Number of blocks to mark as allocated
981 _______________________________________________________________________
984 OSErr
BlockMarkAllocated(
986 UInt32 startingBlock
,
987 register UInt32 numBlocks
)
990 register UInt32
*currentWord
; // Pointer to current word within bitmap block
991 register UInt32 wordsLeft
; // Number of words left in this bitmap block
992 register UInt32 bitMask
; // Word with given bits already set (ready to OR in)
993 UInt32 firstBit
; // Bit index within word of first bit to allocate
994 UInt32 numBits
; // Number of bits in word to allocate
995 UInt32
*buffer
= NULL
;
998 UInt32 wordsPerBlock
;
1000 struct hfsmount
*hfsmp
= VCBTOHFS(vcb
);
1004 // Pre-read the bitmap block containing the first word of allocation
1007 err
= ReadBitmapBlock(vcb
, startingBlock
, &buffer
, &blockRef
);
1008 if (err
!= noErr
) goto Exit
;
1010 // Initialize currentWord, and wordsLeft.
1013 UInt32 wordIndexInBlock
;
1015 bitsPerBlock
= vcb
->vcbVBMIOSize
* kBitsPerByte
;
1016 wordsPerBlock
= vcb
->vcbVBMIOSize
/ kBytesPerWord
;
1018 wordIndexInBlock
= (startingBlock
& (bitsPerBlock
-1)) / kBitsPerWord
;
1019 currentWord
= buffer
+ wordIndexInBlock
;
1020 wordsLeft
= wordsPerBlock
- wordIndexInBlock
;
1025 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
1029 // If the first block to allocate doesn't start on a word
1030 // boundary in the bitmap, then treat that first word
1034 firstBit
= startingBlock
% kBitsPerWord
;
1035 if (firstBit
!= 0) {
1036 bitMask
= kAllBitsSetInWord
>> firstBit
; // turn off all bits before firstBit
1037 numBits
= kBitsPerWord
- firstBit
; // number of remaining bits in this word
1038 if (numBits
> numBlocks
) {
1039 numBits
= numBlocks
; // entire allocation is inside this one word
1040 bitMask
&= ~(kAllBitsSetInWord
>> (firstBit
+ numBits
)); // turn off bits after last
1043 if ((*currentWord
& SWAP_BE32 (bitMask
)) != 0) {
1044 panic("BlockMarkAllocated: blocks already allocated!");
1047 *currentWord
|= SWAP_BE32 (bitMask
); // set the bits in the bitmap
1048 numBlocks
-= numBits
; // adjust number of blocks left to allocate
1050 ++currentWord
; // move to next word
1051 --wordsLeft
; // one less word left in this block
1055 // Allocate whole words (32 blocks) at a time.
1058 bitMask
= kAllBitsSetInWord
; // put this in a register for 68K
1059 while (numBlocks
>= kBitsPerWord
) {
1060 if (wordsLeft
== 0) {
1061 // Read in the next bitmap block
1062 startingBlock
+= bitsPerBlock
; // generate a block number in the next bitmap block
1065 err
= ReleaseBitmapBlock(vcb
, blockRef
, true);
1066 if (err
!= noErr
) goto Exit
;
1068 err
= ReadBitmapBlock(vcb
, startingBlock
, &buffer
, &blockRef
);
1069 if (err
!= noErr
) goto Exit
;
1073 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
1076 // Readjust currentWord and wordsLeft
1077 currentWord
= buffer
;
1078 wordsLeft
= wordsPerBlock
;
1081 if (*currentWord
!= 0) {
1082 panic("BlockMarkAllocated: blocks already allocated!");
1085 *currentWord
= SWAP_BE32 (bitMask
);
1086 numBlocks
-= kBitsPerWord
;
1088 ++currentWord
; // move to next word
1089 --wordsLeft
; // one less word left in this block
1093 // Allocate any remaining blocks.
1096 if (numBlocks
!= 0) {
1097 bitMask
= ~(kAllBitsSetInWord
>> numBlocks
); // set first numBlocks bits
1098 if (wordsLeft
== 0) {
1099 // Read in the next bitmap block
1100 startingBlock
+= bitsPerBlock
; // generate a block number in the next bitmap block
1103 err
= ReleaseBitmapBlock(vcb
, blockRef
, true);
1104 if (err
!= noErr
) goto Exit
;
1106 err
= ReadBitmapBlock(vcb
, startingBlock
, &buffer
, &blockRef
);
1107 if (err
!= noErr
) goto Exit
;
1111 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
1114 // Readjust currentWord and wordsLeft
1115 currentWord
= buffer
;
1116 wordsLeft
= wordsPerBlock
;
1119 if ((*currentWord
& SWAP_BE32 (bitMask
)) != 0) {
1120 panic("BlockMarkAllocated: blocks already allocated!");
1123 *currentWord
|= SWAP_BE32 (bitMask
); // set the bits in the bitmap
1125 // No need to update currentWord or wordsLeft
1131 (void)ReleaseBitmapBlock(vcb
, blockRef
, true);
1138 _______________________________________________________________________
1140 Routine: BlockMarkFree
1142 Function: Mark a contiguous group of blocks as free (clear in the
1143 bitmap). It assumes those bits are currently marked
1144 allocated (set in the bitmap).
1147 vcb Pointer to volume where space is to be freed
1148 startingBlock First block number to mark as freed
1149 numBlocks Number of blocks to mark as freed
1150 _______________________________________________________________________
1153 OSErr
BlockMarkFree(
1155 UInt32 startingBlock
,
1156 register UInt32 numBlocks
)
1159 register UInt32
*currentWord
; // Pointer to current word within bitmap block
1160 register UInt32 wordsLeft
; // Number of words left in this bitmap block
1161 register UInt32 bitMask
; // Word with given bits already set (ready to OR in)
1162 UInt32 firstBit
; // Bit index within word of first bit to allocate
1163 UInt32 numBits
; // Number of bits in word to allocate
1164 UInt32
*buffer
= NULL
;
1166 UInt32 bitsPerBlock
;
1167 UInt32 wordsPerBlock
;
1169 struct hfsmount
*hfsmp
= VCBTOHFS(vcb
);
1171 if (startingBlock
+ numBlocks
> vcb
->totalBlocks
) {
1172 printf("hfs: block mark free: trying to free non-existent blocks (%d %d %d)\n",
1173 startingBlock
, numBlocks
, vcb
->totalBlocks
);
1180 // Pre-read the bitmap block containing the first word of allocation
1183 err
= ReadBitmapBlock(vcb
, startingBlock
, &buffer
, &blockRef
);
1184 if (err
!= noErr
) goto Exit
;
1187 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
1191 // Initialize currentWord, and wordsLeft.
1194 UInt32 wordIndexInBlock
;
1196 bitsPerBlock
= vcb
->vcbVBMIOSize
* kBitsPerByte
;
1197 wordsPerBlock
= vcb
->vcbVBMIOSize
/ kBytesPerWord
;
1199 wordIndexInBlock
= (startingBlock
& (bitsPerBlock
-1)) / kBitsPerWord
;
1200 currentWord
= buffer
+ wordIndexInBlock
;
1201 wordsLeft
= wordsPerBlock
- wordIndexInBlock
;
1205 // If the first block to free doesn't start on a word
1206 // boundary in the bitmap, then treat that first word
1210 firstBit
= startingBlock
% kBitsPerWord
;
1211 if (firstBit
!= 0) {
1212 bitMask
= kAllBitsSetInWord
>> firstBit
; // turn off all bits before firstBit
1213 numBits
= kBitsPerWord
- firstBit
; // number of remaining bits in this word
1214 if (numBits
> numBlocks
) {
1215 numBits
= numBlocks
; // entire allocation is inside this one word
1216 bitMask
&= ~(kAllBitsSetInWord
>> (firstBit
+ numBits
)); // turn off bits after last
1218 if ((*currentWord
& SWAP_BE32 (bitMask
)) != SWAP_BE32 (bitMask
)) {
1221 *currentWord
&= SWAP_BE32 (~bitMask
); // clear the bits in the bitmap
1222 numBlocks
-= numBits
; // adjust number of blocks left to free
1224 ++currentWord
; // move to next word
1225 --wordsLeft
; // one less word left in this block
1229 // Free whole words (32 blocks) at a time.
1232 while (numBlocks
>= kBitsPerWord
) {
1233 if (wordsLeft
== 0) {
1234 // Read in the next bitmap block
1235 startingBlock
+= bitsPerBlock
; // generate a block number in the next bitmap block
1238 err
= ReleaseBitmapBlock(vcb
, blockRef
, true);
1239 if (err
!= noErr
) goto Exit
;
1241 err
= ReadBitmapBlock(vcb
, startingBlock
, &buffer
, &blockRef
);
1242 if (err
!= noErr
) goto Exit
;
1246 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
1249 // Readjust currentWord and wordsLeft
1250 currentWord
= buffer
;
1251 wordsLeft
= wordsPerBlock
;
1253 if (*currentWord
!= SWAP_BE32 (kAllBitsSetInWord
)) {
1256 *currentWord
= 0; // clear the entire word
1257 numBlocks
-= kBitsPerWord
;
1259 ++currentWord
; // move to next word
1260 --wordsLeft
; // one less word left in this block
1264 // Free any remaining blocks.
1267 if (numBlocks
!= 0) {
1268 bitMask
= ~(kAllBitsSetInWord
>> numBlocks
); // set first numBlocks bits
1269 if (wordsLeft
== 0) {
1270 // Read in the next bitmap block
1271 startingBlock
+= bitsPerBlock
; // generate a block number in the next bitmap block
1274 err
= ReleaseBitmapBlock(vcb
, blockRef
, true);
1275 if (err
!= noErr
) goto Exit
;
1277 err
= ReadBitmapBlock(vcb
, startingBlock
, &buffer
, &blockRef
);
1278 if (err
!= noErr
) goto Exit
;
1282 journal_modify_block_start(hfsmp
->jnl
, (struct buf
*)blockRef
);
1285 // Readjust currentWord and wordsLeft
1286 currentWord
= buffer
;
1287 wordsLeft
= wordsPerBlock
;
1289 if ((*currentWord
& SWAP_BE32 (bitMask
)) != SWAP_BE32 (bitMask
)) {
1292 *currentWord
&= SWAP_BE32 (~bitMask
); // clear the bits in the bitmap
1294 // No need to update currentWord or wordsLeft
1300 (void)ReleaseBitmapBlock(vcb
, blockRef
, true);
1306 panic("BlockMarkFree: blocks not allocated!");
1308 printf("hfs: WARNING - blocks on volume %s not allocated!\n", vcb
->vcbVN
);
1309 vcb
->vcbAtrb
|= kHFSVolumeInconsistentMask
;
1318 _______________________________________________________________________
1320 Routine: BlockFindContiguous
1322 Function: Find a contiguous range of blocks that are free (bits
1323 clear in the bitmap). If a contiguous range of the
1324 minimum size can't be found, an error will be returned.
1327 vcb Pointer to volume where space is to be allocated
1328 startingBlock Preferred first block of range
1329 endingBlock Last possible block in range + 1
1330 minBlocks Minimum number of blocks needed. Must be > 0.
1331 maxBlocks Maximum (ideal) number of blocks desired
1332 useMetaZone OK to dip into metadata allocation zone
1335 actualStartBlock First block of range found, or 0 if error
1336 actualNumBlocks Number of blocks found, or 0 if error
1339 noErr Found at least minBlocks contiguous
1340 dskFulErr No contiguous space found, or all less than minBlocks
1341 _______________________________________________________________________
1344 static OSErr
BlockFindContiguous(
1346 UInt32 startingBlock
,
1350 Boolean useMetaZone
,
1351 UInt32
*actualStartBlock
,
1352 UInt32
*actualNumBlocks
)
1355 register UInt32 currentBlock
; // Block we're currently looking at.
1356 UInt32 firstBlock
; // First free block in current extent.
1357 UInt32 stopBlock
; // If we get to this block, stop searching for first free block.
1358 UInt32 foundBlocks
; // Number of contiguous free blocks in current extent.
1359 UInt32
*buffer
= NULL
;
1360 register UInt32
*currentWord
;
1361 register UInt32 bitMask
;
1362 register UInt32 wordsLeft
;
1363 register UInt32 tempWord
;
1365 UInt32 wordsPerBlock
;
1368 * When we're skipping the metadata zone and the start/end
1369 * range overlaps with the metadata zone then adjust the
1370 * start to be outside of the metadata zone. If the range
1371 * is entirely inside the metadata zone then we can deny the
1372 * request (dskFulErr).
1374 if (!useMetaZone
&& (vcb
->hfs_flags
& HFS_METADATA_ZONE
)) {
1375 if (startingBlock
<= vcb
->hfs_metazone_end
) {
1376 if (endingBlock
> (vcb
->hfs_metazone_end
+ 2))
1377 startingBlock
= vcb
->hfs_metazone_end
+ 1;
1383 if ((endingBlock
- startingBlock
) < minBlocks
)
1385 // The set of blocks we're checking is smaller than the minimum number
1386 // of blocks, so we couldn't possibly find a good range.
1390 stopBlock
= endingBlock
- minBlocks
+ 1;
1391 currentBlock
= startingBlock
;
1395 * Skip over metadata blocks.
1398 currentBlock
= NextBitmapBlock(vcb
, currentBlock
);
1401 // Pre-read the first bitmap block.
1403 err
= ReadBitmapBlock(vcb
, currentBlock
, &buffer
, &blockRef
);
1404 if ( err
!= noErr
) goto ErrorExit
;
1407 // Figure out where currentBlock is within the buffer.
1409 wordsPerBlock
= vcb
->vcbVBMIOSize
/ kBytesPerWord
;
1411 wordsLeft
= (currentBlock
/ kBitsPerWord
) & (wordsPerBlock
-1); // Current index into buffer
1412 currentWord
= buffer
+ wordsLeft
;
1413 wordsLeft
= wordsPerBlock
- wordsLeft
;
1419 //============================================================
1420 // Look for a free block, skipping over allocated blocks.
1421 //============================================================
1424 // Check an initial partial word (if any)
1426 bitMask
= currentBlock
& kBitsWithinWordMask
;
1429 tempWord
= SWAP_BE32(*currentWord
); // Fetch the current word only once
1430 bitMask
= kHighBitInWordMask
>> bitMask
;
1431 while (tempWord
& bitMask
)
1437 // Did we find an unused bit (bitMask != 0), or run out of bits (bitMask == 0)?
1441 // Didn't find any unused bits, so we're done with this word.
1447 // Check whole words
1449 while (currentBlock
< stopBlock
)
1451 // See if it's time to read another block.
1455 err
= ReleaseBitmapBlock(vcb
, blockRef
, false);
1456 if (err
!= noErr
) goto ErrorExit
;
1459 * Skip over metadata blocks.
1462 currentBlock
= NextBitmapBlock(vcb
, currentBlock
);
1463 if (currentBlock
>= stopBlock
) {
1468 err
= ReadBitmapBlock(vcb
, currentBlock
, &buffer
, &blockRef
);
1469 if ( err
!= noErr
) goto ErrorExit
;
1471 currentWord
= buffer
;
1472 wordsLeft
= wordsPerBlock
;
1475 // See if any of the bits are clear
1476 if ((tempWord
= SWAP_BE32(*currentWord
)) + 1) // non-zero if any bits were clear
1478 // Figure out which bit is clear
1479 bitMask
= kHighBitInWordMask
;
1480 while (tempWord
& bitMask
)
1486 break; // Found the free bit; break out to FoundUnused.
1489 // Keep looking at the next word
1490 currentBlock
+= kBitsPerWord
;
1496 // Make sure the unused bit is early enough to use
1497 if (currentBlock
>= stopBlock
)
1502 // Remember the start of the extent
1503 firstBlock
= currentBlock
;
1505 //============================================================
1506 // Count the number of contiguous free blocks.
1507 //============================================================
1510 // Check an initial partial word (if any)
1512 bitMask
= currentBlock
& kBitsWithinWordMask
;
1515 tempWord
= SWAP_BE32(*currentWord
); // Fetch the current word only once
1516 bitMask
= kHighBitInWordMask
>> bitMask
;
1517 while (bitMask
&& !(tempWord
& bitMask
))
1523 // Did we find a used bit (bitMask != 0), or run out of bits (bitMask == 0)?
1527 // Didn't find any used bits, so we're done with this word.
1533 // Check whole words
1535 while (currentBlock
< endingBlock
)
1537 // See if it's time to read another block.
1541 err
= ReleaseBitmapBlock(vcb
, blockRef
, false);
1542 if (err
!= noErr
) goto ErrorExit
;
1545 * Skip over metadata blocks.
1550 nextBlock
= NextBitmapBlock(vcb
, currentBlock
);
1551 if (nextBlock
!= currentBlock
) {
1552 goto LoopExit
; /* allocation gap, so stop */
1556 err
= ReadBitmapBlock(vcb
, currentBlock
, &buffer
, &blockRef
);
1557 if ( err
!= noErr
) goto ErrorExit
;
1559 currentWord
= buffer
;
1560 wordsLeft
= wordsPerBlock
;
1563 // See if any of the bits are set
1564 if ((tempWord
= SWAP_BE32(*currentWord
)) != 0)
1566 // Figure out which bit is set
1567 bitMask
= kHighBitInWordMask
;
1568 while (!(tempWord
& bitMask
))
1574 break; // Found the used bit; break out to FoundUsed.
1577 // Keep looking at the next word
1578 currentBlock
+= kBitsPerWord
;
1582 // If we found at least maxBlocks, we can quit early.
1583 if ((currentBlock
- firstBlock
) >= maxBlocks
)
1588 // Make sure we didn't run out of bitmap looking for a used block.
1589 // If so, pin to the end of the bitmap.
1590 if (currentBlock
> endingBlock
)
1591 currentBlock
= endingBlock
;
1593 // Figure out how many contiguous free blocks there were.
1594 // Pin the answer to maxBlocks.
1595 foundBlocks
= currentBlock
- firstBlock
;
1596 if (foundBlocks
> maxBlocks
)
1597 foundBlocks
= maxBlocks
;
1598 if (foundBlocks
>= minBlocks
)
1599 break; // Found what we needed!
1601 // This free chunk wasn't big enough. Try inserting it into the free extent cache in case
1602 // the allocation wasn't forced contiguous.
1603 tempWord
= vcb
->vcbFreeExtCnt
;
1604 if (tempWord
== kMaxFreeExtents
&& vcb
->vcbFreeExt
[kMaxFreeExtents
-1].blockCount
< foundBlocks
)
1606 if (tempWord
< kMaxFreeExtents
)
1608 // We're going to add this extent. Bubble any smaller extents down in the list.
1609 while (tempWord
&& vcb
->vcbFreeExt
[tempWord
-1].blockCount
< foundBlocks
)
1611 vcb
->vcbFreeExt
[tempWord
] = vcb
->vcbFreeExt
[tempWord
-1];
1614 vcb
->vcbFreeExt
[tempWord
].startBlock
= firstBlock
;
1615 vcb
->vcbFreeExt
[tempWord
].blockCount
= foundBlocks
;
1617 if (vcb
->vcbFreeExtCnt
< kMaxFreeExtents
)
1618 ++vcb
->vcbFreeExtCnt
;
1620 } while (currentBlock
< stopBlock
);
1623 // Return the outputs.
1624 if (foundBlocks
< minBlocks
)
1629 *actualStartBlock
= 0;
1630 *actualNumBlocks
= 0;
1635 *actualStartBlock
= firstBlock
;
1636 *actualNumBlocks
= foundBlocks
;
1640 (void) ReleaseBitmapBlock(vcb
, blockRef
, false);
1646 * Test to see if any blocks in a range are allocated.
1648 * The journal or allocation file lock must be held.
1652 hfs_isallocated(struct hfsmount
*hfsmp
, u_long startingBlock
, u_long numBlocks
)
1654 UInt32
*currentWord
; // Pointer to current word within bitmap block
1655 UInt32 wordsLeft
; // Number of words left in this bitmap block
1656 UInt32 bitMask
; // Word with given bits already set (ready to test)
1657 UInt32 firstBit
; // Bit index within word of first bit to allocate
1658 UInt32 numBits
; // Number of bits in word to allocate
1659 UInt32
*buffer
= NULL
;
1661 UInt32 bitsPerBlock
;
1662 UInt32 wordsPerBlock
;
1667 * Pre-read the bitmap block containing the first word of allocation
1669 error
= ReadBitmapBlock(hfsmp
, startingBlock
, &buffer
, &blockRef
);
1674 * Initialize currentWord, and wordsLeft.
1677 UInt32 wordIndexInBlock
;
1679 bitsPerBlock
= hfsmp
->vcbVBMIOSize
* kBitsPerByte
;
1680 wordsPerBlock
= hfsmp
->vcbVBMIOSize
/ kBytesPerWord
;
1682 wordIndexInBlock
= (startingBlock
& (bitsPerBlock
-1)) / kBitsPerWord
;
1683 currentWord
= buffer
+ wordIndexInBlock
;
1684 wordsLeft
= wordsPerBlock
- wordIndexInBlock
;
1688 * First test any non word aligned bits.
1690 firstBit
= startingBlock
% kBitsPerWord
;
1691 if (firstBit
!= 0) {
1692 bitMask
= kAllBitsSetInWord
>> firstBit
;
1693 numBits
= kBitsPerWord
- firstBit
;
1694 if (numBits
> numBlocks
) {
1695 numBits
= numBlocks
;
1696 bitMask
&= ~(kAllBitsSetInWord
>> (firstBit
+ numBits
));
1698 if ((*currentWord
& SWAP_BE32 (bitMask
)) != 0) {
1702 numBlocks
-= numBits
;
1708 * Test whole words (32 blocks) at a time.
1710 while (numBlocks
>= kBitsPerWord
) {
1711 if (wordsLeft
== 0) {
1712 /* Read in the next bitmap block. */
1713 startingBlock
+= bitsPerBlock
;
1716 error
= ReleaseBitmapBlock(hfsmp
, blockRef
, false);
1717 if (error
) goto Exit
;
1719 error
= ReadBitmapBlock(hfsmp
, startingBlock
, &buffer
, &blockRef
);
1720 if (error
) goto Exit
;
1722 /* Readjust currentWord and wordsLeft. */
1723 currentWord
= buffer
;
1724 wordsLeft
= wordsPerBlock
;
1726 if (*currentWord
!= 0) {
1730 numBlocks
-= kBitsPerWord
;
1736 * Test any remaining blocks.
1738 if (numBlocks
!= 0) {
1739 bitMask
= ~(kAllBitsSetInWord
>> numBlocks
);
1740 if (wordsLeft
== 0) {
1741 /* Read in the next bitmap block */
1742 startingBlock
+= bitsPerBlock
;
1745 error
= ReleaseBitmapBlock(hfsmp
, blockRef
, false);
1746 if (error
) goto Exit
;
1748 error
= ReadBitmapBlock(hfsmp
, startingBlock
, &buffer
, &blockRef
);
1749 if (error
) goto Exit
;
1751 currentWord
= buffer
;
1752 wordsLeft
= wordsPerBlock
;
1754 if ((*currentWord
& SWAP_BE32 (bitMask
)) != 0) {
1761 (void)ReleaseBitmapBlock(hfsmp
, blockRef
, false);