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:
@@ -1464,7 +1464,9 @@ status_t
|
|||||||
Inode::SetFileSize(Transaction *transaction, off_t size)
|
Inode::SetFileSize(Transaction *transaction, off_t size)
|
||||||
{
|
{
|
||||||
if (size < 0
|
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)
|
|| Flags() & INODE_NO_CACHE)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ class CachedBlock {
|
|||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
fBlockNumber = block;
|
fBlockNumber = block;
|
||||||
return fBlock = empty ? (uint8 *)get_empty_block(fVolume->Device(),block,fVolume->BlockSize())
|
return fBlock = empty ? (uint8 *)get_empty_block(fVolume->Device(), block, BlockSize())
|
||||||
: (uint8 *)get_block(fVolume->Device(),block,fVolume->BlockSize());
|
: (uint8 *)get_block(fVolume->Device(), block, BlockSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 *SetTo(block_run run, bool empty = false)
|
uint8 *SetTo(block_run run, bool empty = false)
|
||||||
@@ -107,6 +107,8 @@ class CachedBlock {
|
|||||||
|
|
||||||
uint8 *Block() const { return fBlock; }
|
uint8 *Block() const { return fBlock; }
|
||||||
off_t BlockNumber() const { return fBlockNumber; }
|
off_t BlockNumber() const { return fBlockNumber; }
|
||||||
|
uint32 BlockSize() const { return fVolume->BlockSize(); }
|
||||||
|
uint32 BlockShift() const { return fVolume->BlockShift(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Volume *fVolume;
|
Volume *fVolume;
|
||||||
|
|||||||
@@ -35,11 +35,13 @@ class Uncached {
|
|||||||
|
|
||||||
uint8 *Block() const { return fBlock; }
|
uint8 *Block() const { return fBlock; }
|
||||||
off_t BlockNumber() const { return fBlockNumber; }
|
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 Read(Volume *volume, block_run run, uint8 *buffer);
|
||||||
static status_t Write(Transaction *transaction, Volume *volume, block_run run, const uint8 *buffer);
|
static status_t Write(Transaction *transaction, Volume *volume, block_run run, const uint8 *buffer);
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
Volume *fVolume;
|
Volume *fVolume;
|
||||||
off_t fBlockNumber;
|
off_t fBlockNumber;
|
||||||
uint8 *fBlock;
|
uint8 *fBlock;
|
||||||
@@ -116,9 +118,9 @@ Uncached::SetTo(off_t block, bool empty = false)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (empty)
|
if (empty)
|
||||||
memset(fBlock, 0, fVolume->BlockSize());
|
memset(fBlock, 0, BlockSize());
|
||||||
else
|
else
|
||||||
read_pos(fVolume->Device(), fBlockNumber << fVolume->BlockShift(), fBlock, fVolume->BlockSize());
|
read_pos(fVolume->Device(), fBlockNumber << BlockShift(), fBlock, BlockSize());
|
||||||
|
|
||||||
return fBlock;
|
return fBlock;
|
||||||
}
|
}
|
||||||
@@ -137,7 +139,7 @@ Uncached::WriteBack(Transaction *transaction)
|
|||||||
if (fBlock == NULL)
|
if (fBlock == NULL)
|
||||||
RETURN_ERROR(B_BAD_VALUE);
|
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>
|
template<class Cache>
|
||||||
class Stream : public Inode {
|
class Stream : public Inode {
|
||||||
public:
|
private:
|
||||||
// The constructor only exists to make the compiler happy - it
|
// The constructor only exists to make the compiler happy - it
|
||||||
// is never called in the code itself
|
// is never called in the code itself
|
||||||
Stream() : Inode(NULL, -1) {}
|
Stream() : Inode(NULL, -1) {}
|
||||||
|
|
||||||
|
public:
|
||||||
status_t FindBlockRun(off_t pos, block_run &run, off_t &offset);
|
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 ReadAt(off_t pos, uint8 *buffer, size_t *length);
|
||||||
status_t WriteAt(Transaction *transaction, off_t pos, const 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);
|
Cache cached(fVolume);
|
||||||
|
|
||||||
off_t start = pos - data->max_indirect_range;
|
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));
|
* (fVolume->BlockSize() / sizeof(block_run));
|
||||||
int32 directSize = NUM_ARRAY_BLOCKS << fVolume->BlockShift();
|
int32 directSize = NUM_ARRAY_BLOCKS << cached.BlockShift();
|
||||||
int32 index = start / indirectSize;
|
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(
|
block_run *indirect = (block_run *)cached.SetTo(
|
||||||
fVolume->ToBlock(data->double_indirect) + index / runsPerBlock);
|
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())
|
if (indirect[current].IsZero())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
runBlockEnd += indirect[current].length << fVolume->BlockShift();
|
runBlockEnd += indirect[current].length << cached.BlockShift();
|
||||||
if (runBlockEnd > pos) {
|
if (runBlockEnd > pos) {
|
||||||
run = indirect[current];
|
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("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);
|
//printf("### indirect-run[%ld] = (%ld,%d,%d), offset = %Ld\n",fCurrent,fRun.allocation_group,fRun.start,fRun.length,fRunFileOffset);
|
||||||
return fVolume->IsValidBlockRun(run);
|
return fVolume->IsValidBlockRun(run);
|
||||||
|
|||||||
Reference in New Issue
Block a user