Reformat code.

master
WangRunji 7 years ago
parent 075ea8469f
commit 3f71a36c66

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

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

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

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

Loading…
Cancel
Save