diff --git a/kernel/context/context.rs b/kernel/context/context.rs index 43bdc61..4b4cc3a 100644 --- a/kernel/context/context.rs +++ b/kernel/context/context.rs @@ -93,7 +93,7 @@ impl Context { /// 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) -> Option { + pub fn add_file(&self, file: File) -> Option { let mut files = self.files.lock(); for (i, mut file_option) in files.iter_mut().enumerate() { if file_option.is_none() { @@ -122,7 +122,7 @@ impl Context { /// Remove a file // TODO: adjust files vector to smaller size if possible - pub fn remove_file(&mut self, i: usize) -> Option { + pub fn remove_file(&self, i: usize) -> Option { let mut files = self.files.lock(); if i < files.len() { files[i].take() diff --git a/kernel/syscall/fs.rs b/kernel/syscall/fs.rs index acf457e..c992bba 100644 --- a/kernel/syscall/fs.rs +++ b/kernel/syscall/fs.rs @@ -61,7 +61,14 @@ pub fn write(fd: usize, buf: &[u8]) -> Result { /// Open syscall pub fn open(path: &[u8], flags: usize) -> Result { - let mut parts = path.splitn(2, |&b| b == b':'); + let path_canon = { + let contexts = context::contexts(); + let context_lock = contexts.current().ok_or(Error::NoProcess)?; + let context = context_lock.read(); + context.canonicalize(path) + }; + + let mut parts = path_canon.splitn(2, |&b| b == b':'); let namespace_opt = parts.next(); let reference_opt = parts.next(); @@ -75,7 +82,7 @@ pub fn open(path: &[u8], flags: usize) -> Result { let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::NoProcess)?; - let mut context = context_lock.write(); + let context = context_lock.read(); context.add_file(::context::file::File { scheme: scheme_id, number: file_id @@ -87,7 +94,7 @@ pub fn close(fd: usize) -> Result { let file = { let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::NoProcess)?; - let mut context = context_lock.write(); + let context = context_lock.read(); let file = context.remove_file(fd).ok_or(Error::BadFile)?; file };