Implement symlink following

master
Jiajie Chen 6 years ago
parent 0272aa1070
commit 547baa9ecd

4
kernel/Cargo.lock generated

@ -338,12 +338,12 @@ dependencies = [
[[package]]
name = "rcore-fs"
version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#47df4e1cc97f061fa6eadf66eaacf774d22bb806"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#c9322710b4ba67c086f500befb8208c6ae353493"
[[package]]
name = "rcore-fs-sfs"
version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#47df4e1cc97f061fa6eadf66eaacf774d22bb806"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#c9322710b4ba67c086f500befb8208c6ae353493"
dependencies = [
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

@ -56,6 +56,8 @@ lazy_static! {
};
}
pub const FOLLOW_MAX_DEPTH: usize = 1;
pub trait INodeExt {
fn read_as_vec(&self) -> Result<Vec<u8>>;
}

@ -6,11 +6,12 @@ use spin::{Mutex, RwLock};
use xmas_elf::{ElfFile, header, program::{Flags, Type}};
use rcore_memory::PAGE_SIZE;
use rcore_thread::Tid;
use rcore_fs::vfs::FileType;
use core::str;
use crate::arch::interrupt::{Context, TrapFrame};
use crate::memory::{ByFrame, GlobalFrameAlloc, KernelStack, MemoryAttr, MemorySet};
use crate::fs::{FileHandle, OpenOptions, INodeExt};
use crate::fs::{FileHandle, OpenOptions, INodeExt, FOLLOW_MAX_DEPTH};
use crate::sync::Condvar;
use crate::net::{SocketWrapper, SOCKETS};
@ -204,7 +205,8 @@ impl Thread {
let size = interp.file_size() as usize - 1; // skip last '\0'
if offset + size < data.len() {
if let Ok(loader_path) = str::from_utf8(&data[offset..(offset+size)]) {
if let Ok(inode) = crate::fs::ROOT_INODE.lookup(&loader_path[1..]) {
// assuming absolute path
if let Ok(inode) = crate::fs::ROOT_INODE.lookup_follow(&loader_path[1..], FOLLOW_MAX_DEPTH) {
if let Ok(buf) = inode.read_as_vec() {
debug!("using loader {}", &loader_path);
// Elf loader should not have INTERP

@ -683,12 +683,12 @@ impl Process {
if path.len() > 0 && path.as_bytes()[0] == b'/' {
// absolute path
let abs_path = path.split_at(1).1; // skip start '/'
let inode = ROOT_INODE.lookup(abs_path)?;
let inode = ROOT_INODE.lookup_follow(abs_path, FOLLOW_MAX_DEPTH)?;
Ok(inode)
} else {
// relative path
let cwd = self.cwd.split_at(1).1; // skip start '/'
let inode = ROOT_INODE.lookup(cwd)?.lookup(path)?;
let inode = ROOT_INODE.lookup(cwd)?.lookup_follow(path, FOLLOW_MAX_DEPTH)?;
Ok(inode)
}
}

@ -1,7 +1,7 @@
//! Syscalls for process
use super::*;
use crate::fs::INodeExt;
use crate::fs::{INodeExt, FOLLOW_MAX_DEPTH};
/// Fork the current process. Return the child's PID.
pub fn sys_fork(tf: &TrapFrame) -> SysResult {
@ -120,7 +120,7 @@ pub fn sys_exec(name: *const u8, argv: *const *const u8, envp: *const *const u8,
// Read program file
let path = args[0].as_str();
let inode = crate::fs::ROOT_INODE.lookup(path)?;
let inode = crate::fs::ROOT_INODE.lookup_follow(path, FOLLOW_MAX_DEPTH)?;
let buf = inode.read_as_vec()?;
// Make new Thread

Loading…
Cancel
Save