Make special devices go to the FileIo fast path

This commit is contained in:
Shaowei Song 2024-09-03 03:38:19 +00:00 committed by Tate, Hongliang Tian
parent 1b9b76d27c
commit 7ddb69f4db
5 changed files with 19 additions and 2 deletions

View File

@ -16,6 +16,10 @@ impl Device for Null {
// Same value with Linux // Same value with Linux
DeviceId::new(1, 3) DeviceId::new(1, 3)
} }
fn open(&self) -> Result<Option<Arc<dyn FileIo>>> {
Ok(Some(Arc::new(Null)))
}
} }
impl FileIo for Null { impl FileIo for Null {

View File

@ -31,6 +31,10 @@ impl Device for Random {
// The same value as Linux // The same value as Linux
DeviceId::new(1, 8) DeviceId::new(1, 8)
} }
fn open(&self) -> Result<Option<Arc<dyn FileIo>>> {
Ok(Some(Arc::new(Random)))
}
} }
impl FileIo for Random { impl FileIo for Random {

View File

@ -31,6 +31,10 @@ impl Device for Urandom {
// The same value as Linux // The same value as Linux
DeviceId::new(1, 9) DeviceId::new(1, 9)
} }
fn open(&self) -> Result<Option<Arc<dyn FileIo>>> {
Ok(Some(Arc::new(Urandom)))
}
} }
impl FileIo for Urandom { impl FileIo for Urandom {

View File

@ -16,6 +16,10 @@ impl Device for Zero {
// Same value with Linux // Same value with Linux
DeviceId::new(1, 5) DeviceId::new(1, 5)
} }
fn open(&self) -> Result<Option<Arc<dyn FileIo>>> {
Ok(Some(Arc::new(Zero)))
}
} }
impl FileIo for Zero { impl FileIo for Zero {

View File

@ -98,12 +98,13 @@ impl InodeHandle_ {
todo!("support write_at for FileIo"); todo!("support write_at for FileIo");
} }
if self.status_flags().contains(StatusFlags::O_APPEND) { let status_flags = self.status_flags();
if status_flags.contains(StatusFlags::O_APPEND) {
// If the file has the O_APPEND flag, the offset is ignored // If the file has the O_APPEND flag, the offset is ignored
offset = self.dentry.size(); offset = self.dentry.size();
} }
if self.status_flags().contains(StatusFlags::O_DIRECT) { if status_flags.contains(StatusFlags::O_DIRECT) {
self.dentry.inode().write_direct_at(offset, reader) self.dentry.inode().write_direct_at(offset, reader)
} else { } else {
self.dentry.inode().write_at(offset, reader) self.dentry.inode().write_at(offset, reader)