/*
- * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
//
// If the disk is already full, don't bother.
//
- if (vcb->freeBlocks == 0) {
+ if (hfs_freeblks(VCBTOHFS(vcb), 0) == 0) {
err = dskFulErr;
goto Exit;
}
- if (forceContiguous && vcb->freeBlocks < minBlocks) {
+ if (forceContiguous && hfs_freeblks(VCBTOHFS(vcb), 0) < minBlocks) {
err = dskFulErr;
goto Exit;
}
//
if (forceContiguous) {
err = BlockAllocateContig(vcb, startingBlock, minBlocks, maxBlocks, actualStartBlock, actualNumBlocks);
+ /*
+ * If we allocated from a new position then
+ * also update the roving allocatior.
+ */
+ if ((err == noErr) && (*actualStartBlock > startingBlock))
+ vcb->nextAllocation = *actualStartBlock;
} else {
/*
* Scan the bitmap once, gather the N largest free extents, then
//
VCB_LOCK(vcb);
vcb->freeBlocks += numBlocks;
+ if (vcb->nextAllocation == (firstBlock + numBlocks))
+ vcb->nextAllocation -= numBlocks;
VCB_UNLOCK(vcb);
MarkVCBDirty(vcb);
if (bp) {
if (dirty) {
- bp->b_flags |= B_DIRTY;
- bdwrite(bp);
+ // XXXdbg
+ struct hfsmount *hfsmp = VCBTOHFS(vcb);
+
+ if (hfsmp->jnl) {
+ journal_modify_block_end(hfsmp->jnl, bp);
+ } else {
+ bdwrite(bp);
+ }
} else {
brelse(bp);
}
return err;
}
-extern OSErr LookupBufferMapping(caddr_t bufferAddress, struct buf **bpp, int *mappingIndexPtr);
-
/*
_______________________________________________________________________
UInt32 bitsPerBlock;
UInt32 wordsPerBlock;
Boolean dirty = false;
+ struct hfsmount *hfsmp = VCBTOHFS(vcb);
// Since this routine doesn't wrap around
if (maxBlocks > (endingBlock - startingBlock)) {
endingBlock = block + maxBlocks; // if we get this far, we've found enough
}
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
//
// Allocate all of the consecutive blocks
//
if (err != noErr) goto Exit;
buffer = currCache;
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
wordsLeft = wordsPerBlock;
}
UInt32 blockRef;
UInt32 bitsPerBlock;
UInt32 wordsPerBlock;
+ // XXXdbg
+ struct hfsmount *hfsmp = VCBTOHFS(vcb);
//
// Pre-read the bitmap block containing the first word of allocation
wordsLeft = wordsPerBlock - wordIndexInBlock;
}
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
//
// If the first block to allocate doesn't start on a word
// boundary in the bitmap, then treat that first word
err = ReadBitmapBlock(vcb, startingBlock, &buffer, &blockRef);
if (err != noErr) goto Exit;
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
// Readjust currentWord and wordsLeft
currentWord = buffer;
wordsLeft = wordsPerBlock;
err = ReadBitmapBlock(vcb, startingBlock, &buffer, &blockRef);
if (err != noErr) goto Exit;
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
// Readjust currentWord and wordsLeft
currentWord = buffer;
wordsLeft = wordsPerBlock;
UInt32 blockRef;
UInt32 bitsPerBlock;
UInt32 wordsPerBlock;
+ // XXXdbg
+ struct hfsmount *hfsmp = VCBTOHFS(vcb);
//
// Pre-read the bitmap block containing the first word of allocation
err = ReadBitmapBlock(vcb, startingBlock, &buffer, &blockRef);
if (err != noErr) goto Exit;
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
//
// Initialize currentWord, and wordsLeft.
//
err = ReadBitmapBlock(vcb, startingBlock, &buffer, &blockRef);
if (err != noErr) goto Exit;
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
// Readjust currentWord and wordsLeft
currentWord = buffer;
wordsLeft = wordsPerBlock;
err = ReadBitmapBlock(vcb, startingBlock, &buffer, &blockRef);
if (err != noErr) goto Exit;
+ // XXXdbg
+ if (hfsmp->jnl) {
+ journal_modify_block_start(hfsmp->jnl, (struct buf *)blockRef);
+ }
+
// Readjust currentWord and wordsLeft
currentWord = buffer;
wordsLeft = wordsPerBlock;
stopBlock = endingBlock - minBlocks + 1;
currentBlock = startingBlock;
+ firstBlock = 0;
//
// Pre-read the first bitmap block.
bitMask = currentBlock & kBitsWithinWordMask;
if (bitMask)
{
- tempWord = *currentWord; // Fetch the current word only once
+ tempWord = SWAP_BE32(*currentWord); // Fetch the current word only once
bitMask = kHighBitInWordMask >> bitMask;
while (tempWord & bitMask)
{
}
// See if any of the bits are clear
- if ((tempWord=*currentWord) + 1) // non-zero if any bits were clear
+ if ((tempWord = SWAP_BE32(*currentWord)) + 1) // non-zero if any bits were clear
{
// Figure out which bit is clear
bitMask = kHighBitInWordMask;
bitMask = currentBlock & kBitsWithinWordMask;
if (bitMask)
{
- tempWord = *currentWord; // Fetch the current word only once
+ tempWord = SWAP_BE32(*currentWord); // Fetch the current word only once
bitMask = kHighBitInWordMask >> bitMask;
while (bitMask && !(tempWord & bitMask))
{
}
// See if any of the bits are set
- if ((tempWord=*currentWord) != 0)
+ if ((tempWord = SWAP_BE32(*currentWord)) != 0)
{
// Figure out which bit is set
bitMask = kHighBitInWordMask;