Add context and file structs
This commit is contained in:
parent
49739d47e8
commit
4e270bb807
9 changed files with 88 additions and 14 deletions
10
kernel/context/file.rs
Normal file
10
kernel/context/file.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
//! File struct
|
||||
|
||||
/// A file
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct File {
|
||||
/// The scheme that this file refers to
|
||||
pub scheme: usize,
|
||||
/// The number the scheme uses to refer to this file
|
||||
pub number: usize,
|
||||
}
|
34
kernel/context/mod.rs
Normal file
34
kernel/context/mod.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
//! Context management
|
||||
|
||||
/// File operations
|
||||
pub mod file;
|
||||
|
||||
/// Context list
|
||||
pub static mut CONTEXT: Context = Context::new();
|
||||
|
||||
/// A context, which identifies either a process or a thread
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Context {
|
||||
/// The open files in the scheme
|
||||
pub files: [Option<file::File>; 32]
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub const fn new() -> Context {
|
||||
Context {
|
||||
files: [None; 32]
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a file to the lowest available slot.
|
||||
/// Return the file descriptor number or None if no slot was found
|
||||
pub fn add_file(&mut self, file: file::File) -> Option<usize> {
|
||||
for (i, mut file_option) in self.files.iter_mut().enumerate() {
|
||||
if file_option.is_none() {
|
||||
*file_option = Some(file);
|
||||
return Some(i);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue