forked from Bananymous/banan-os
Kernel: Reads return 0 bytes read at the end of device
We used to not have any idea if we where already at the end of device. Also fixed couple of copy-paste errors from read->write
This commit is contained in:
parent
c62849a783
commit
dcde2ae6b4
|
@ -241,7 +241,7 @@ namespace Kernel
|
||||||
BAN::ErrorOr<void> ATAController::write(ATADevice* device, uint64_t lba, uint8_t sector_count, const uint8_t* buffer)
|
BAN::ErrorOr<void> ATAController::write(ATADevice* device, uint64_t lba, uint8_t sector_count, const uint8_t* buffer)
|
||||||
{
|
{
|
||||||
if (lba + sector_count > device->m_lba_count)
|
if (lba + sector_count > device->m_lba_count)
|
||||||
return BAN::Error::from_c_string("Attempted to read outside of the device boundaries");
|
return BAN::Error::from_c_string("Attempted to write outside of the device boundaries");
|
||||||
|
|
||||||
LockGuard _(m_lock);
|
LockGuard _(m_lock);
|
||||||
|
|
||||||
|
@ -377,6 +377,8 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
if (offset % sector_size() || bytes % sector_size())
|
if (offset % sector_size() || bytes % sector_size())
|
||||||
return BAN::Error::from_errno(EINVAL);
|
return BAN::Error::from_errno(EINVAL);
|
||||||
|
if (offset == total_size())
|
||||||
|
return 0;
|
||||||
TRY(read_sectors(offset / sector_size(), bytes / sector_size(), (uint8_t*)buffer));
|
TRY(read_sectors(offset / sector_size(), bytes / sector_size(), (uint8_t*)buffer));
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
const uint32_t sectors_in_partition = m_lba_end - m_lba_start;
|
const uint32_t sectors_in_partition = m_lba_end - m_lba_start;
|
||||||
if (lba + sector_count > sectors_in_partition)
|
if (lba + sector_count > sectors_in_partition)
|
||||||
return BAN::Error::from_c_string("Attempted to read outside of the partition boundaries");
|
return BAN::Error::from_c_string("Attempted to write outside of the partition boundaries");
|
||||||
TRY(m_device.write_sectors(m_lba_start + lba, sector_count, buffer));
|
TRY(m_device.write_sectors(m_lba_start + lba, sector_count, buffer));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -237,8 +237,18 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
if (offset % m_device.sector_size() || bytes % m_device.sector_size())
|
if (offset % m_device.sector_size() || bytes % m_device.sector_size())
|
||||||
return BAN::Error::from_errno(ENOTSUP);
|
return BAN::Error::from_errno(ENOTSUP);
|
||||||
TRY(read_sectors(offset / m_device.sector_size(), bytes / m_device.sector_size(), (uint8_t*)buffer));
|
|
||||||
return bytes;
|
const uint32_t sectors_in_partition = m_lba_end - m_lba_start;
|
||||||
|
uint32_t lba = offset / m_device.sector_size();
|
||||||
|
uint32_t sector_count = bytes / m_device.sector_size();
|
||||||
|
|
||||||
|
if (lba == sectors_in_partition)
|
||||||
|
return 0;
|
||||||
|
if (lba + sector_count > sectors_in_partition)
|
||||||
|
sector_count = sectors_in_partition - lba;
|
||||||
|
|
||||||
|
TRY(read_sectors(lba, sector_count, (uint8_t*)buffer));
|
||||||
|
return sector_count * m_device.sector_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue