file_systems: Remove now-redundant bounds checks before file_cache_read().
Change-Id: Iafb7d188c7e7cb4406d924eb3354a7ede40c6641 Reviewed-on: https://review.haiku-os.org/c/1421 Reviewed-by: waddlesplash <waddlesplash@gmail.com> Reviewed-by: Michael Lotz <mmlr@mlotz.ch>
This commit is contained in:
parent
728b515e1c
commit
097bbc7fd2
@ -1556,21 +1556,6 @@ Inode::FindBlockRun(off_t pos, block_run& run, off_t& offset)
|
||||
status_t
|
||||
Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)
|
||||
{
|
||||
size_t length = *_length;
|
||||
|
||||
// set/check boundaries for pos/length
|
||||
if (pos < 0)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
InodeReadLocker locker(this);
|
||||
|
||||
if (pos >= Size() || length == 0) {
|
||||
*_length = 0;
|
||||
return B_NO_ERROR;
|
||||
}
|
||||
|
||||
locker.Unlock();
|
||||
|
||||
return file_cache_read(FileCache(), NULL, pos, buffer, _length);
|
||||
}
|
||||
|
||||
|
@ -173,22 +173,6 @@ Inode::FindBlock(off_t pos, off_t& physical, off_t *_length)
|
||||
status_t
|
||||
Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)
|
||||
{
|
||||
size_t length = *_length;
|
||||
|
||||
// set/check boundaries for pos/length
|
||||
if (pos < 0) {
|
||||
ERROR("inode %" B_PRIdINO ": ReadAt failed(pos %" B_PRIdOFF", length %"
|
||||
B_PRIuSIZE ")\n", ID(), pos, length);
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
if (pos >= Size() || length == 0) {
|
||||
TRACE("inode %" B_PRIdINO ": ReadAt 0 (pos %" B_PRIdOFF", length %"
|
||||
B_PRIuSIZE ")\n", ID(), pos, length);
|
||||
*_length = 0;
|
||||
return B_NO_ERROR;
|
||||
}
|
||||
|
||||
return file_cache_read(FileCache(), NULL, pos, buffer, _length);
|
||||
}
|
||||
|
||||
|
@ -206,22 +206,6 @@ Inode::FindBlock(off_t offset, fsblock_t& block, uint32 *_count)
|
||||
status_t
|
||||
Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)
|
||||
{
|
||||
size_t length = *_length;
|
||||
|
||||
// set/check boundaries for pos/length
|
||||
if (pos < 0) {
|
||||
ERROR("inode %" B_PRIdINO ": ReadAt failed(pos %" B_PRIdOFF
|
||||
", length %" B_PRIuSIZE ")\n", ID(), pos, length);
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
if (pos >= Size() || length == 0) {
|
||||
TRACE("inode %" B_PRIdINO ": ReadAt 0 (pos %" B_PRIdOFF ", length %"
|
||||
B_PRIuSIZE ")\n", ID(), pos, length);
|
||||
*_length = 0;
|
||||
return B_NO_ERROR;
|
||||
}
|
||||
|
||||
return file_cache_read(FileCache(), NULL, pos, buffer, _length);
|
||||
}
|
||||
|
||||
|
@ -370,20 +370,8 @@ dosfs_read(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t pos,
|
||||
DPRINTF(0, ("dosfs_read called %" B_PRIuSIZE " bytes at %" B_PRIdOFF
|
||||
" (vnode id %" B_PRIdINO ")\n", *len, pos, node->vnid));
|
||||
|
||||
if (pos < 0) pos = 0;
|
||||
|
||||
if ((node->st_size == 0) || (*len == 0) || (pos >= node->st_size)) {
|
||||
*len = 0;
|
||||
goto bi;
|
||||
}
|
||||
|
||||
// truncate bytes to read to file size
|
||||
if (pos + *len >= node->st_size)
|
||||
*len = node->st_size - pos;
|
||||
|
||||
result = file_cache_read(node->cache, cookie, pos, buf, len);
|
||||
|
||||
bi:
|
||||
if (result != B_OK) {
|
||||
DPRINTF(0, ("dosfs_read (%s)\n", strerror(result)));
|
||||
} else {
|
||||
|
@ -528,16 +528,6 @@ fs_read(fs_volume* _volume, fs_vnode* _node, void* cookie, off_t pos,
|
||||
if ((node->flags & ISO_IS_DIR) != 0)
|
||||
return EISDIR;
|
||||
|
||||
uint32 fileSize = node->dataLen[FS_DATA_FORMAT];
|
||||
|
||||
// set/check boundaries for pos/length
|
||||
if (pos < 0)
|
||||
return B_BAD_VALUE;
|
||||
if (pos >= fileSize) {
|
||||
*_length = 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
return file_cache_read(node->cache, NULL, pos, buffer, _length);
|
||||
}
|
||||
|
||||
|
@ -83,12 +83,6 @@ struct PackageFile::DataAccessor {
|
||||
|
||||
status_t ReadData(off_t offset, void* buffer, size_t* bufferSize)
|
||||
{
|
||||
if (offset < 0 || (uint64)offset > fData->UncompressedSize())
|
||||
return B_BAD_VALUE;
|
||||
|
||||
*bufferSize = std::min((uint64)*bufferSize,
|
||||
fData->UncompressedSize() - offset);
|
||||
|
||||
return file_cache_read(fFileCache, NULL, offset, buffer, bufferSize);
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ Icb::FindBlock(uint32 logicalBlock, off_t &block, bool &recorded)
|
||||
long_address extent;
|
||||
bool isEmpty = false;
|
||||
recorded = false;
|
||||
|
||||
|
||||
switch (_IcbTag().descriptor_flags()) {
|
||||
case ICB_DESCRIPTOR_TYPE_SHORT:
|
||||
{
|
||||
@ -299,6 +299,11 @@ Icb::Read(off_t pos, void *buffer, size_t *length, uint32 *block)
|
||||
TRACE(("Icb::Read: pos = %" B_PRIdOFF ", buffer = %p, length = (%p)->%ld\n",
|
||||
pos, buffer, length, (length ? *length : 0)));
|
||||
|
||||
DEBUG_INIT_ETC("Icb", ("pos: %lld, length: %ld", pos, *length));
|
||||
|
||||
if (fFileCache != NULL)
|
||||
return file_cache_read(fFileCache, NULL, pos, buffer, length);
|
||||
|
||||
if (!buffer || !length || pos < 0)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
@ -307,11 +312,6 @@ Icb::Read(off_t pos, void *buffer, size_t *length, uint32 *block)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
DEBUG_INIT_ETC("Icb", ("pos: %lld, length: %ld", pos, *length));
|
||||
|
||||
if (fFileCache != NULL)
|
||||
return file_cache_read(fFileCache, NULL, pos, buffer, length);
|
||||
|
||||
switch (_IcbTag().descriptor_flags()) {
|
||||
case ICB_DESCRIPTOR_TYPE_SHORT:
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user