Canonicalize paths in open

This commit is contained in:
Jeremy Soller 2016-09-18 12:54:10 -06:00
parent cfbaccf4d2
commit 1b056395bb
2 changed files with 12 additions and 5 deletions

View file

@ -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<usize> {
pub fn add_file(&self, file: File) -> Option<usize> {
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<File> {
pub fn remove_file(&self, i: usize) -> Option<File> {
let mut files = self.files.lock();
if i < files.len() {
files[i].take()

View file

@ -61,7 +61,14 @@ pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
/// Open syscall
pub fn open(path: &[u8], flags: usize) -> Result<usize> {
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<usize> {
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<usize> {
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
};