diff options
Diffstat (limited to 'rsnix/src/ahci.rs')
| -rw-r--r-- | rsnix/src/ahci.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/rsnix/src/ahci.rs b/rsnix/src/ahci.rs index 72da07d..a77b341 100644 --- a/rsnix/src/ahci.rs +++ b/rsnix/src/ahci.rs | |||
| @@ -510,22 +510,24 @@ fn active() -> Option<&'static Disk> { | |||
| 510 | disks().get(unsafe { ACTIVE }).and_then(|d| d.as_ref()) | 510 | disks().get(unsafe { ACTIVE }).and_then(|d| d.as_ref()) |
| 511 | } | 511 | } |
| 512 | 512 | ||
| 513 | /// DMA `count` sectors starting at `lba` into the selected disk's buffer. | 513 | /// Bounds-checked DMA of `count` sectors starting at `lba` into/out of the |
| 514 | pub fn read_sectors(lba: u64, count: u32) -> Result<(), ()> { | 514 | /// selected disk's buffer (single code path for both directions). |
| 515 | fn dma_sectors(lba: u64, count: u32, cmd: u8, write: bool) -> Result<(), ()> { | ||
| 515 | let d = active().ok_or(())?; | 516 | let d = active().ok_or(())?; |
| 516 | if lba + count as u64 > d.sectors { | 517 | if lba + count as u64 > d.sectors { |
| 517 | return Err(()); | 518 | return Err(()); |
| 518 | } | 519 | } |
| 519 | issue(d, ATA_READ_DMA_EXT, lba, count, false) | 520 | issue(d, cmd, lba, count, write) |
| 521 | } | ||
| 522 | |||
| 523 | /// DMA `count` sectors starting at `lba` into the selected disk's buffer. | ||
| 524 | pub fn read_sectors(lba: u64, count: u32) -> Result<(), ()> { | ||
| 525 | dma_sectors(lba, count, ATA_READ_DMA_EXT, false) | ||
| 520 | } | 526 | } |
| 521 | 527 | ||
| 522 | /// DMA `count` sectors starting at `lba` out of the selected disk's buffer. | 528 | /// DMA `count` sectors starting at `lba` out of the selected disk's buffer. |
| 523 | pub fn write_sectors(lba: u64, count: u32) -> Result<(), ()> { | 529 | pub fn write_sectors(lba: u64, count: u32) -> Result<(), ()> { |
| 524 | let d = active().ok_or(())?; | 530 | dma_sectors(lba, count, ATA_WRITE_DMA_EXT, true) |
| 525 | if lba + count as u64 > d.sectors { | ||
| 526 | return Err(()); | ||
| 527 | } | ||
| 528 | issue(d, ATA_WRITE_DMA_EXT, lba, count, true) | ||
| 529 | } | 531 | } |
| 530 | 532 | ||
| 531 | /// Pointer to the selected disk's 4 KiB DMA buffer. | 533 | /// Pointer to the selected disk's 4 KiB DMA buffer. |
