diff --git a/kernel/src/arch/x86_64/disk/ATA.cpp b/kernel/src/arch/x86_64/disk/ATA.cpp index fc177efa..6bb63220 100644 --- a/kernel/src/arch/x86_64/disk/ATA.cpp +++ b/kernel/src/arch/x86_64/disk/ATA.cpp @@ -748,6 +748,8 @@ Result ATADevice::read(u8* buf, usize offset, usize size) const auto block_size = m_drive->block_size(); + ScopedKMutexLock<100>(m_drive->channel()->lock()); + auto* temp = TRY(make_array(block_size)); auto guard = make_scope_guard([temp] { delete[] temp; }); diff --git a/kernel/src/arch/x86_64/disk/ATA.h b/kernel/src/arch/x86_64/disk/ATA.h index 53207b0a..fb8c9122 100644 --- a/kernel/src/arch/x86_64/disk/ATA.h +++ b/kernel/src/arch/x86_64/disk/ATA.h @@ -157,6 +157,11 @@ namespace ATA return m_block_count * m_block_size; } + Channel* channel() const + { + return m_channel; + } + Result read_lba(u64 lba, void* out, usize nblocks); static Result create_drive_name(SharedPtr drive); @@ -233,11 +238,16 @@ namespace ATA bool wait_for_irq_or_timeout(u64 timeout); void irq_handler(Registers*); - u8 irq_line() + u8 irq_line() const { return m_interrupt_line; } + KMutex<100>& lock() + { + return m_lock; + } + void select(u8 drive); bool initialize();