mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 17:26:31 +00:00
部分函数从返回值为Result<<>,i32>修改为Result<<>,SystemError> (#210)
* 将Result<<>,i32>替换为Result<<>,SystemError> * bugfix: 显示双缓冲区初始化的时候,连续注册了两次Video Softirq的问题。 Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
use super::{_port, hba::HbaCmdTable, virt_2_phys};
|
||||
use crate::driver::disk::ahci::HBA_PxIS_TFES;
|
||||
use crate::filesystem::mbr::MbrDiskPartionTable;
|
||||
use crate::include::bindings::bindings::{E2BIG, EIO};
|
||||
use crate::io::{device::BlockDevice, disk_info::Partition, SeekFrom};
|
||||
|
||||
use crate::libs::{spinlock::SpinLock, vec_cursor::VecCursor};
|
||||
use crate::mm::phys_2_virt;
|
||||
use crate::syscall::SystemError;
|
||||
use crate::{
|
||||
driver::disk::ahci::hba::{
|
||||
FisRegH2D, FisType, HbaCmdHeader, ATA_CMD_READ_DMA_EXT, ATA_CMD_WRITE_DMA_EXT,
|
||||
@ -54,13 +54,13 @@ impl AhciDisk {
|
||||
lba_id_start: crate::io::device::BlockId, // 起始lba编号
|
||||
count: usize, // 读取lba的数量
|
||||
buf: &mut [u8],
|
||||
) -> Result<usize, i32> {
|
||||
) -> Result<usize, SystemError> {
|
||||
compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
let check_length = ((count - 1) >> 4) + 1; // prdt length
|
||||
if count * 512 > buf.len() || check_length > u16::MAX as usize {
|
||||
kerror!("ahci read: e2big");
|
||||
// 不可能的操作
|
||||
return Err(-(E2BIG as i32));
|
||||
return Err(SystemError::E2BIG);
|
||||
} else if count == 0 {
|
||||
return Ok(0);
|
||||
}
|
||||
@ -71,7 +71,7 @@ impl AhciDisk {
|
||||
let slot = port.find_cmdslot().unwrap_or(u32::MAX);
|
||||
|
||||
if slot == u32::MAX {
|
||||
return Err(-(EIO as i32));
|
||||
return Err(SystemError::EIO);
|
||||
}
|
||||
|
||||
#[allow(unused_unsafe)]
|
||||
@ -161,7 +161,7 @@ impl AhciDisk {
|
||||
|
||||
if spin_count == SPIN_LIMIT {
|
||||
kerror!("Port is hung");
|
||||
return Err(-(EIO as i32));
|
||||
return Err(SystemError::EIO);
|
||||
}
|
||||
|
||||
volatile_set_bit!(port.ci, 1 << slot, true); // Issue command
|
||||
@ -173,7 +173,7 @@ impl AhciDisk {
|
||||
}
|
||||
if (volatile_read!(port.is) & HBA_PxIS_TFES) > 0 {
|
||||
kerror!("Read disk error");
|
||||
return Err(-(EIO as i32));
|
||||
return Err(SystemError::EIO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,12 +187,12 @@ impl AhciDisk {
|
||||
lba_id_start: crate::io::device::BlockId,
|
||||
count: usize,
|
||||
buf: &[u8],
|
||||
) -> Result<usize, i32> {
|
||||
) -> Result<usize, SystemError> {
|
||||
compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
let check_length = ((count - 1) >> 4) + 1; // prdt length
|
||||
if count * 512 > buf.len() || check_length > u16::MAX as usize {
|
||||
// 不可能的操作
|
||||
return Err(-(E2BIG as i32));
|
||||
return Err(SystemError::E2BIG);
|
||||
} else if count == 0 {
|
||||
return Ok(0);
|
||||
}
|
||||
@ -204,7 +204,7 @@ impl AhciDisk {
|
||||
let slot = port.find_cmdslot().unwrap_or(u32::MAX);
|
||||
|
||||
if slot == u32::MAX {
|
||||
return Err(-(EIO as i32));
|
||||
return Err(SystemError::EIO);
|
||||
}
|
||||
|
||||
compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
@ -295,7 +295,7 @@ impl AhciDisk {
|
||||
}
|
||||
if (volatile_read!(port.is) & HBA_PxIS_TFES) > 0 {
|
||||
kerror!("Write disk error");
|
||||
return Err(-(EIO as i32));
|
||||
return Err(SystemError::EIO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ impl AhciDisk {
|
||||
return Ok(count * 512);
|
||||
}
|
||||
|
||||
fn sync(&self) -> Result<(), i32> {
|
||||
fn sync(&self) -> Result<(), SystemError> {
|
||||
// 由于目前没有block cache, 因此sync返回成功即可
|
||||
return Ok(());
|
||||
}
|
||||
@ -316,7 +316,7 @@ impl LockedAhciDisk {
|
||||
flags: u16,
|
||||
ctrl_num: u8,
|
||||
port_num: u8,
|
||||
) -> Result<Arc<LockedAhciDisk>, i32> {
|
||||
) -> Result<Arc<LockedAhciDisk>, SystemError> {
|
||||
let mut part_s: Vec<Arc<Partition>> = Vec::new();
|
||||
|
||||
// 构建磁盘结构体
|
||||
@ -351,7 +351,7 @@ impl LockedAhciDisk {
|
||||
}
|
||||
|
||||
/// @brief: 从磁盘中读取 MBR 分区表结构体 TODO: Cursor
|
||||
pub fn read_mbr_table(&self) -> Result<MbrDiskPartionTable, i32> {
|
||||
pub fn read_mbr_table(&self) -> Result<MbrDiskPartionTable, SystemError> {
|
||||
let mut table: MbrDiskPartionTable = Default::default();
|
||||
|
||||
// 数据缓冲区
|
||||
@ -404,7 +404,7 @@ impl BlockDevice for LockedAhciDisk {
|
||||
lba_id_start: crate::io::device::BlockId,
|
||||
count: usize,
|
||||
buf: &mut [u8],
|
||||
) -> Result<usize, i32> {
|
||||
) -> Result<usize, SystemError> {
|
||||
// kdebug!(
|
||||
// "ahci read at {lba_id_start}, count={count}, lock={:?}",
|
||||
// self.0
|
||||
@ -418,11 +418,11 @@ impl BlockDevice for LockedAhciDisk {
|
||||
lba_id_start: crate::io::device::BlockId,
|
||||
count: usize,
|
||||
buf: &[u8],
|
||||
) -> Result<usize, i32> {
|
||||
) -> Result<usize, SystemError> {
|
||||
self.0.lock().write_at(lba_id_start, count, buf)
|
||||
}
|
||||
|
||||
fn sync(&self) -> Result<(), i32> {
|
||||
fn sync(&self) -> Result<(), SystemError> {
|
||||
return self.0.lock().sync();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user