Skip to content

Commit

Permalink
Merge pull request #75 from ken4647/9p_symlink
Browse files Browse the repository at this point in the history
Implement logic to open symlink in 9pfs
  • Loading branch information
coolyjg authored Mar 28, 2024
2 parents f0bc272 + 4aaffd1 commit 8c43a6a
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions modules/rux9p/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl CommonNode {
const O_RDWR: u8 = 0x02;
const O_RDONLY: u8 = 0x00;
const EISDIR: u8 = 21;
const ELOOP: u8 = 40;

let result = if *protocol == "9P2000.L" {
dev.write().l_topen(fid, O_RDWR as u32)
Expand All @@ -131,23 +132,36 @@ impl CommonNode {
Ok(())
};

if let Err(EISDIR) = result {
if *protocol == "9P2000.L" {
handle_result!(
dev.write().l_topen(fid, O_RDONLY as u32),
"9pfs l_topen failed! error code: {}"
);
} else if *protocol == "9P2000.u" {
handle_result!(
dev.write().topen(fid, O_RDONLY),
"9pfs topen failed! error code: {}"
);
} else {
error!("9pfs open failed! Unsupported protocol version");
match result {
Err(EISDIR) if *protocol == "9P2000.L" => handle_result!(
dev.write().l_topen(fid, O_RDONLY as u32),
"9pfs l_topen failed! error code: {}"
),
Err(EISDIR) if *protocol == "9P2000.u" => handle_result!(
dev.write().topen(fid, O_RDONLY),
"9pfs topen failed! error code: {}"
),
Err(ELOOP) if *protocol == "9P2000.L" => {
let try_readlink = dev.write().treadlink(fid);
if let Ok(path) = try_readlink {
debug!("read link path ==> {:}", path);
let mut splited: Vec<&str> = path
.split('/')
.filter(|&x| !x.is_empty() && (x != "."))
.collect();
splited.insert(0, "..");
let try_walk = dev.write().twalk(fid, fid, splited.len() as u16, &splited);
match try_walk {
Ok(_) => return Self::new(fid, parent, dev, protocol),
Err(ecode) => error!("9pfs twalk failed! error code: {}", ecode),
}
} else {
error!("9pfs treadlink failed! error code: {:?}", try_readlink);
}
}
} else if let Err(ecode) = result {
error!("9pfs topen failed! error code: {}", ecode);
}
Err(ecode) => error!("9pfs topen failed! error code: {}", ecode),
_ => {}
};

Arc::new_cyclic(|this| Self {
inner: dev,
Expand Down Expand Up @@ -224,7 +238,13 @@ impl CommonNode {
fn try_get(&self, path: &str) -> VfsResult<VfsNodeRef> {
let (name, rest) = split_path(path);
if name == ".." {
return self.parent().unwrap().lookup(rest.unwrap_or(""));
match self.parent() {
Some(parent) => return parent.lookup(rest.unwrap_or("")),
None => {
error!("9pfs: try_get a directory out of 9pfs boundary");
return Err(VfsError::BadState);
}
}
} else if name == "." {
return self.try_get(rest.unwrap_or(""));
}
Expand Down

0 comments on commit 8c43a6a

Please sign in to comment.