Reformat code.

master
WangRunji 6 years ago
parent 075ea8469f
commit 3f71a36c66

@ -18,7 +18,7 @@ fn main() -> Result<()> {
_ => {
println!("USAGE: <zip|unzip> <PATH> <IMG>");
panic!("Invalid command: {}", cmd);
},
}
}
}

@ -32,6 +32,7 @@ trait DeviceExt: Device {
s
}
}
impl DeviceExt for Device {}
type Ptr<T> = Rc<RefCell<T>>;

@ -58,6 +58,7 @@ pub struct DiskEntry {
#[repr(C)]
pub struct Str256(pub [u8; 256]);
#[repr(C)]
pub struct Str32(pub [u8; 32]);
@ -67,22 +68,26 @@ impl AsRef<str> for Str256 {
str::from_utf8(&self.0[0..len]).unwrap()
}
}
impl AsRef<str> for Str32 {
fn as_ref(&self) -> &str {
let len = self.0.iter().enumerate().find(|(_, &b)| b == 0).unwrap().0;
str::from_utf8(&self.0[0..len]).unwrap()
}
}
impl Debug for Str256 {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "{}", self.as_ref())
}
}
impl Debug for Str32 {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "{}", self.as_ref())
}
}
impl<'a> From<&'a str> for Str256 {
fn from(s: &'a str) -> Self {
let mut ret = [0u8; 256];
@ -90,6 +95,7 @@ impl<'a> From<&'a str> for Str256 {
Str256(ret)
}
}
impl<'a> From<&'a str> for Str32 {
fn from(s: &'a str) -> Self {
let mut ret = [0u8; 32];
@ -140,8 +146,11 @@ pub trait AsBuf {
}
impl AsBuf for SuperBlock {}
impl AsBuf for DiskINode {}
impl AsBuf for DiskEntry {}
impl AsBuf for u32 {}
/*
@ -184,7 +193,10 @@ pub const DIRENT_SIZE: usize = MAX_FNAME_LEN + 1;
#[repr(u16)]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum FileType {
Invalid = 0, File = 1, Dir = 2, Link = 3,
Invalid = 0,
File = 1,
Dir = 2,
Link = 3,
}
const_assert!(o1; size_of::<SuperBlock>() <= BLKSIZE);

@ -58,19 +58,25 @@ impl INode{
}).collect())
}
pub fn lookup(&self, path: &str) -> Result<INodePtr> {
if(self.info().unwrap().type_ != FileType::Dir){
return Err(())
if self.info().unwrap().type_ != FileType::Dir {
return Err(());
}
let mut result = self.find(".").unwrap();
let mut rest_path = path;
while rest_path != "" {
if(result.borrow().info().unwrap().type_ != FileType::Dir){
return Err(())
if result.borrow().info().unwrap().type_ != FileType::Dir {
return Err(());
}
let mut name;
match rest_path.find('/') {
None => {name=rest_path; rest_path=""},
Some(pos) => {name=&rest_path[0..pos]; rest_path=&rest_path[pos + 1..]},
None => {
name = rest_path;
rest_path = ""
}
Some(pos) => {
name = &rest_path[0..pos];
rest_path = &rest_path[pos + 1..]
}
};
let found = result.borrow().find(name);
match found {
@ -97,7 +103,8 @@ pub struct FileInfo {
#[derive(Debug, Eq, PartialEq)]
pub enum FileType {
File, Dir,
File,
Dir,
}
#[derive(Debug)]

Loading…
Cancel
Save