Canonicalize paths in open
This commit is contained in:
parent
cfbaccf4d2
commit
1b056395bb
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue