Added a missing check of the return value of a cached write in
Inode::FillGapWithZeros(), pointed out by Mike Nordell. Note, that function is currently not used. Some smaller cleanups. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1058 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -907,14 +907,15 @@ Inode::WriteAt(Transaction *transaction,off_t pos,const uint8 *buffer,size_t *_l
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Inode::FillGapWithZeros(off_t pos,off_t newSize)
|
Inode::FillGapWithZeros(off_t pos, off_t newSize)
|
||||||
{
|
{
|
||||||
|
// ToDo: we currently do anything here, same as original BFS!
|
||||||
//if (pos >= newSize)
|
//if (pos >= newSize)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
block_run run;
|
block_run run;
|
||||||
off_t offset;
|
off_t offset;
|
||||||
if (FindBlockRun(pos,run,offset) < B_OK)
|
if (FindBlockRun(pos, run, offset) < B_OK)
|
||||||
RETURN_ERROR(B_BAD_VALUE);
|
RETURN_ERROR(B_BAD_VALUE);
|
||||||
|
|
||||||
off_t length = newSize - pos;
|
off_t length = newSize - pos;
|
||||||
@@ -939,16 +940,17 @@ Inode::FillGapWithZeros(off_t pos,off_t newSize)
|
|||||||
if (length < bytesWritten)
|
if (length < bytesWritten)
|
||||||
bytesWritten = length;
|
bytesWritten = length;
|
||||||
|
|
||||||
memset(block + (pos % blockSize),0,bytesWritten);
|
memset(block + (pos % blockSize), 0, bytesWritten);
|
||||||
fVolume->WriteBlocks(cached.BlockNumber(),block,1);
|
if (fVolume->WriteBlocks(cached.BlockNumber(), block, 1) < B_OK)
|
||||||
|
RETURN_ERROR(B_IO_ERROR);
|
||||||
|
|
||||||
pos += bytesWritten;
|
pos += bytesWritten;
|
||||||
|
|
||||||
length -= bytesWritten;
|
length -= bytesWritten;
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
if (FindBlockRun(pos,run,offset) < B_OK)
|
if (FindBlockRun(pos, run, offset) < B_OK)
|
||||||
RETURN_ERROR(B_BAD_VALUE);
|
RETURN_ERROR(B_BAD_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -959,25 +961,25 @@ Inode::FillGapWithZeros(off_t pos,off_t newSize)
|
|||||||
|
|
||||||
CachedBlock cached(fVolume);
|
CachedBlock cached(fVolume);
|
||||||
off_t blockNumber = fVolume->ToBlock(run);
|
off_t blockNumber = fVolume->ToBlock(run);
|
||||||
for (int32 i = 0;i < run.length;i++) {
|
for (int32 i = 0; i < run.length; i++) {
|
||||||
if ((block = cached.SetTo(blockNumber + i,true)) == NULL)
|
if ((block = cached.SetTo(blockNumber + i, true)) == NULL)
|
||||||
RETURN_ERROR(B_IO_ERROR);
|
RETURN_ERROR(B_IO_ERROR);
|
||||||
|
|
||||||
if (fVolume->WriteBlocks(cached.BlockNumber(),block,1) < B_OK)
|
if (fVolume->WriteBlocks(cached.BlockNumber(), block, 1) < B_OK)
|
||||||
RETURN_ERROR(B_IO_ERROR);
|
RETURN_ERROR(B_IO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 bytes = run.length << blockShift;
|
int32 bytes = run.length << blockShift;
|
||||||
length -= bytes;
|
length -= bytes;
|
||||||
bytesWritten += bytes;
|
bytesWritten += bytes;
|
||||||
|
|
||||||
// since we don't respect a last partial block, length can be lower
|
// since we don't respect a last partial block, length can be lower
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pos += bytes;
|
pos += bytes;
|
||||||
|
|
||||||
if (FindBlockRun(pos,run,offset) < B_OK)
|
if (FindBlockRun(pos, run, offset) < B_OK)
|
||||||
RETURN_ERROR(B_BAD_VALUE);
|
RETURN_ERROR(B_BAD_VALUE);
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user