Improved scheme protocol.
This commit is contained in:
committed by
Jeremy Soller
parent
e9ba024aaa
commit
bf0fc66ac1
+28
-3
@@ -7,18 +7,43 @@ use crate::{
|
||||
};
|
||||
use alloc::sync::Arc;
|
||||
use spin::RwLock;
|
||||
use syscall::{schemev2::NewFdFlags, RwFlags, O_APPEND, O_NONBLOCK};
|
||||
|
||||
/// A file description
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct FileDescription {
|
||||
/// The namespace the file was opened from (used for debugging)
|
||||
pub namespace: SchemeNamespace,
|
||||
/// The current file offset (seek)
|
||||
pub offset: u64,
|
||||
/// The scheme that this file refers to
|
||||
pub scheme: SchemeId,
|
||||
/// The number the scheme uses to refer to this file
|
||||
pub number: usize,
|
||||
/// The flags passed to open or fcntl(SETFL)
|
||||
pub flags: usize,
|
||||
pub flags: u32,
|
||||
pub internal_flags: InternalFlags,
|
||||
}
|
||||
bitflags! {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct InternalFlags: u32 {
|
||||
const POSITIONED = 1;
|
||||
}
|
||||
}
|
||||
impl FileDescription {
|
||||
pub fn rw_flags(&self, rw: RwFlags) -> u32 {
|
||||
let mut ret = self.flags & !(O_NONBLOCK | O_APPEND) as u32;
|
||||
if rw.contains(RwFlags::APPEND) {
|
||||
ret |= O_APPEND as u32;
|
||||
}
|
||||
if rw.contains(RwFlags::NONBLOCK) {
|
||||
ret |= O_NONBLOCK as u32;
|
||||
}
|
||||
ret
|
||||
}
|
||||
}
|
||||
impl InternalFlags {
|
||||
pub fn from_extra0(fl: u8) -> Option<Self> {
|
||||
Some(NewFdFlags::from_bits(fl)?.iter().map(|fd| if fd == NewFdFlags::POSITIONED { Self::POSITIONED } else { Self::empty() }).collect())
|
||||
}
|
||||
}
|
||||
|
||||
/// A file descriptor
|
||||
|
||||
Reference in New Issue
Block a user