Added CachedBlock::BlockSize(), and CachedBlock::BlockShift() methods as

suggested by Mike Nordell.
Some code cleanups, added a comment in Inode::SetFileSize() to point out
that Stream<Cache>::WriteAt() denies growing the file size its own.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1060 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2002-09-16 16:03:05 +00:00
parent 850b731e4d
commit d801dfdd1c
3 changed files with 48 additions and 42 deletions
@@ -1464,7 +1464,9 @@ status_t
Inode::SetFileSize(Transaction *transaction, off_t size)
{
if (size < 0
// uncached files can't be resized
// uncached files can't be resized (Stream<Cache>::WriteAt() specifically
// denies growing uncached files because of efficiency, so it had to be
// adapted if this ever changes [which will probably happen in OpenBeOS]).
|| Flags() & INODE_NO_CACHE)
return B_BAD_VALUE;
+4 -2
View File
@@ -88,8 +88,8 @@ class CachedBlock {
{
Unset();
fBlockNumber = block;
return fBlock = empty ? (uint8 *)get_empty_block(fVolume->Device(),block,fVolume->BlockSize())
: (uint8 *)get_block(fVolume->Device(),block,fVolume->BlockSize());
return fBlock = empty ? (uint8 *)get_empty_block(fVolume->Device(), block, BlockSize())
: (uint8 *)get_block(fVolume->Device(), block, BlockSize());
}
uint8 *SetTo(block_run run, bool empty = false)
@@ -107,6 +107,8 @@ class CachedBlock {
uint8 *Block() const { return fBlock; }
off_t BlockNumber() const { return fBlockNumber; }
uint32 BlockSize() const { return fVolume->BlockSize(); }
uint32 BlockShift() const { return fVolume->BlockShift(); }
protected:
Volume *fVolume;
+13 -11
View File
@@ -35,11 +35,13 @@ class Uncached {
uint8 *Block() const { return fBlock; }
off_t BlockNumber() const { return fBlockNumber; }
uint32 BlockSize() const { return fVolume->BlockSize(); }
uint32 BlockShift() const { return fVolume->BlockShift(); }
static status_t Read(Volume *volume, block_run run, uint8 *buffer);
static status_t Write(Transaction *transaction, Volume *volume, block_run run, const uint8 *buffer);
protected:
private:
Volume *fVolume;
off_t fBlockNumber;
uint8 *fBlock;
@@ -116,9 +118,9 @@ Uncached::SetTo(off_t block, bool empty = false)
return NULL;
if (empty)
memset(fBlock, 0, fVolume->BlockSize());
memset(fBlock, 0, BlockSize());
else
read_pos(fVolume->Device(), fBlockNumber << fVolume->BlockShift(), fBlock, fVolume->BlockSize());
read_pos(fVolume->Device(), fBlockNumber << BlockShift(), fBlock, BlockSize());
return fBlock;
}
@@ -137,7 +139,7 @@ Uncached::WriteBack(Transaction *transaction)
if (fBlock == NULL)
RETURN_ERROR(B_BAD_VALUE);
return write_pos(fVolume->Device(), fBlockNumber << fVolume->BlockShift(), fBlock, fVolume->BlockSize());
return write_pos(fVolume->Device(), fBlockNumber << BlockShift(), fBlock, BlockSize());
}
@@ -247,15 +249,15 @@ Logged::Write(Transaction *transaction, Volume *volume, block_run run, const uin
template<class Cache>
class Stream : public Inode {
public:
private:
// The constructor only exists to make the compiler happy - it
// is never called in the code itself
Stream() : Inode(NULL, -1) {}
public:
status_t FindBlockRun(off_t pos, block_run &run, off_t &offset);
status_t ReadAt(off_t pos, uint8 *buffer, size_t *length);
status_t WriteAt(Transaction *transaction, off_t pos, const uint8 *buffer, size_t *length);
};
@@ -276,11 +278,11 @@ Stream<Cache>::FindBlockRun(off_t pos,block_run &run,off_t &offset)
Cache cached(fVolume);
off_t start = pos - data->max_indirect_range;
int32 indirectSize = (1L << (INDIRECT_BLOCKS_SHIFT + fVolume->BlockShift()))
int32 indirectSize = (1L << (INDIRECT_BLOCKS_SHIFT + cached.BlockShift()))
* (fVolume->BlockSize() / sizeof(block_run));
int32 directSize = NUM_ARRAY_BLOCKS << fVolume->BlockShift();
int32 directSize = NUM_ARRAY_BLOCKS << cached.BlockShift();
int32 index = start / indirectSize;
int32 runsPerBlock = fVolume->BlockSize() / sizeof(block_run);
int32 runsPerBlock = cached.BlockSize() / sizeof(block_run);
block_run *indirect = (block_run *)cached.SetTo(
fVolume->ToBlock(data->double_indirect) + index / runsPerBlock);
@@ -319,10 +321,10 @@ Stream<Cache>::FindBlockRun(off_t pos,block_run &run,off_t &offset)
if (indirect[current].IsZero())
break;
runBlockEnd += indirect[current].length << fVolume->BlockShift();
runBlockEnd += indirect[current].length << cached.BlockShift();
if (runBlockEnd > pos) {
run = indirect[current];
offset = runBlockEnd - (run.length << fVolume->BlockShift());
offset = runBlockEnd - (run.length << cached.BlockShift());
//printf("reading from indirect block: %ld,%d\n",fRun.allocation_group,fRun.start);
//printf("### indirect-run[%ld] = (%ld,%d,%d), offset = %Ld\n",fCurrent,fRun.allocation_group,fRun.start,fRun.length,fRunFileOffset);
return fVolume->IsValidBlockRun(run);