diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index a7d8246b84..54560b6759 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -1790,7 +1790,7 @@ BlockAllocator::CheckInode(Inode* inode, check_control* control) if (status != B_OK) return status; - int32 runsPerBlock = runs_per_block(fVolume); + int32 runsPerBlock = runs_per_block(fVolume->BlockSize()); int32 runsPerArray = runsPerBlock * data->double_indirect.Length(); CachedBlock cachedDirect(fVolume); diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index 1f6d5a0196..748dbb1414 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -1327,8 +1327,8 @@ Inode::AllocatedSize() const if (data.MaxDoubleIndirectRange() != 0) { off_t doubleIndirectSize = data.MaxDoubleIndirectRange() - data.MaxIndirectRange(); - int32 indirectSize = double_indirect_max_indirect_size(fVolume, - data.double_indirect.Length()); + int32 indirectSize = double_indirect_max_indirect_size( + data.double_indirect.Length(), fVolume->BlockSize()); size += (2 * data.double_indirect.Length() + doubleIndirectSize / indirectSize) @@ -1372,8 +1372,8 @@ Inode::FindBlockRun(off_t pos, block_run& run, off_t& offset) int32 runsPerBlock; int32 directSize; int32 indirectSize; - get_double_indirect_sizes(fVolume, data->double_indirect.Length(), - runsPerBlock, directSize, indirectSize); + get_double_indirect_sizes(data->double_indirect.Length(), + fVolume->BlockSize(), runsPerBlock, directSize, indirectSize); off_t start = pos - data->MaxIndirectRange(); int32 index = start / indirectSize; @@ -1855,8 +1855,8 @@ Inode::_GrowStream(Transaction& transaction, off_t size) int32 runsPerBlock; int32 directSize; int32 indirectSize; - get_double_indirect_sizes(fVolume, data->double_indirect.Length(), - runsPerBlock, directSize, indirectSize); + get_double_indirect_sizes(data->double_indirect.Length(), + fVolume->BlockSize(), runsPerBlock, directSize, indirectSize); off_t start = data->MaxDoubleIndirectRange() - data->MaxIndirectRange(); @@ -1957,10 +1957,13 @@ Inode::_FreeStaticStreamArray(Transaction& transaction, int32 level, block_run run, off_t size, off_t offset, off_t& max) { int32 indirectSize; - if (level == 0) - indirectSize = double_indirect_max_indirect_size(fVolume, run.Length()); - else - indirectSize = double_indirect_max_direct_size(fVolume, run.Length()); + if (level == 0) { + indirectSize = double_indirect_max_indirect_size(run.Length(), + fVolume->BlockSize()); + } else { + indirectSize = double_indirect_max_direct_size(run.Length(), + fVolume->BlockSize()); + } off_t start; if (size > offset) diff --git a/src/add-ons/kernel/file_systems/bfs/Utility.h b/src/add-ons/kernel/file_systems/bfs/Utility.h index 1c3270acaa..e1bc780dcd 100644 --- a/src/add-ons/kernel/file_systems/bfs/Utility.h +++ b/src/add-ons/kernel/file_systems/bfs/Utility.h @@ -8,7 +8,7 @@ #include "system_dependencies.h" -#include "Volume.h" +#include "bfs.h" enum inode_type { @@ -96,33 +96,37 @@ get_shift(uint64 i) inline int32 -runs_per_block(Volume* volume) +runs_per_block(uint32 blockSize) { - return volume->BlockSize() / sizeof(block_run); +#ifdef _BOOT_MODE + using namespace BFS; +#endif + + return blockSize / sizeof(struct block_run); } inline int32 -double_indirect_max_direct_size(Volume* volume, uint32 baseLength) +double_indirect_max_direct_size(uint32 baseLength, uint32 blockSize) { - return baseLength << volume->BlockShift(); + return baseLength * blockSize; } inline int32 -double_indirect_max_indirect_size(Volume* volume, uint32 baseLength) +double_indirect_max_indirect_size(uint32 baseLength, uint32 blockSize) { - return baseLength * double_indirect_max_direct_size(volume, baseLength) - * runs_per_block(volume); + return baseLength * double_indirect_max_direct_size(baseLength, blockSize) + * runs_per_block(blockSize); } inline void -get_double_indirect_sizes(Volume* volume, uint32 baseLength, +get_double_indirect_sizes(uint32 baseLength, uint32 blockSize, int32& runsPerBlock, int32& directSize, int32& indirectSize) { - runsPerBlock = runs_per_block(volume); - directSize = double_indirect_max_direct_size(volume, baseLength); + runsPerBlock = runs_per_block(blockSize); + directSize = double_indirect_max_direct_size(baseLength, blockSize); indirectSize = baseLength * directSize * runsPerBlock; } diff --git a/src/system/boot/loader/file_systems/bfs/Stream.cpp b/src/system/boot/loader/file_systems/bfs/Stream.cpp index 4f302a9f0f..35e3607ffd 100644 --- a/src/system/boot/loader/file_systems/bfs/Stream.cpp +++ b/src/system/boot/loader/file_systems/bfs/Stream.cpp @@ -1,8 +1,10 @@ -/* Stream - inode stream access functions -** -** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ +/* + * Copyright 2003-2009, Axel Dörfler, axeld@pinc-software.de. + * This file may be used under the terms of the MIT License. + */ + + +//! Inode stream access functions #include "Stream.h" @@ -200,15 +202,17 @@ Stream::FindBlockRun(off_t pos, block_run &run, off_t &offset) CachedBlock cached(fVolume); + int32 runsPerBlock; + int32 directSize; + int32 indirectSize; + get_double_indirect_sizes(data.double_indirect.Length(), + cached.BlockSize(), runsPerBlock, directSize, indirectSize); + off_t start = pos - data.MaxIndirectRange(); - int32 indirectSize = (1L << (INDIRECT_BLOCKS_SHIFT + cached.BlockShift())) - * (fVolume.BlockSize() / sizeof(block_run)); - int32 directSize = NUM_ARRAY_BLOCKS << cached.BlockShift(); int32 index = start / indirectSize; - int32 runsPerBlock = cached.BlockSize() / sizeof(block_run); block_run *indirect = (block_run *)cached.SetTo( - fVolume.ToBlock(data.double_indirect) + index / runsPerBlock); + fVolume.ToBlock(data.double_indirect) + index / runsPerBlock); if (indirect == NULL) return B_ERROR;