mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-11 06:16:49 +00:00
Make special devices go to the FileIo
fast path
This commit is contained in:
parent
1b9b76d27c
commit
7ddb69f4db
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user