Use bitflags to repr Stat::mode

master
WangRunji 7 years ago
parent b24530870e
commit 203130d2b0

@ -189,7 +189,7 @@ struct IoBuf {
#[derive(Debug)] #[derive(Debug)]
struct Stat { struct Stat {
/// protection mode and file type /// protection mode and file type
mode: u32, mode: Mode,
/// number of hard links /// number of hard links
nlinks: u32, nlinks: u32,
/// number of blocks file is using /// number of blocks file is using
@ -198,18 +198,29 @@ struct Stat {
size: u32, size: u32,
} }
/// mask for type of file bitflags! {
const S_IFMT: u32 = 0o70000; struct Mode: u32 {
/// ordinary regular file /// ordinary regular file
const S_IFREG: u32 = 0o10000; const File = 0o10000;
/// directory /// directory
const S_IFDIR: u32 = 0o20000; const Dir = 0o20000;
/// symbolic link /// symbolic link
const S_IFLNK: u32 = 0o30000; const Link = 0o30000;
/// character device /// character device
const S_IFCHR: u32 = 0o40000; const Char = 0o40000;
/// block device /// block device
const S_IFBLK: u32 = 0o50000; const Block = 0o50000;
}
}
impl From<vfs::FileType> for Mode {
fn from(type_: vfs::FileType) -> Self {
match type_ {
vfs::FileType::File => Mode::File,
vfs::FileType::Dir => Mode::Dir,
}
}
}
/// Abstract operations on a inode. /// Abstract operations on a inode.
/// ///
@ -410,10 +421,7 @@ impl INode {
impl From<vfs::FileInfo> for Stat { impl From<vfs::FileInfo> for Stat {
fn from(info: vfs::FileInfo) -> Self { fn from(info: vfs::FileInfo) -> Self {
Stat { Stat {
mode: info.mode | match info.type_ { mode: Mode::from(info.type_),
vfs::FileType::File => S_IFREG,
vfs::FileType::Dir => S_IFDIR,
},
nlinks: 0, nlinks: 0,
blocks: info.blocks as u32, blocks: info.blocks as u32,
size: info.size as u32, size: info.size as u32,
@ -491,10 +499,7 @@ static INODE_OPS: INodeOps = {
println!("inode.gettype: {:?}", inode.borrow()); println!("inode.gettype: {:?}", inode.borrow());
let info = inode.borrow().info().unwrap(); let info = inode.borrow().info().unwrap();
// Inconsistent docs in ucore ! // Inconsistent docs in ucore !
*type_store = match info.type_ { *type_store = Mode::from(info.type_).bits();
vfs::FileType::File => S_IFREG,
vfs::FileType::Dir => S_IFDIR,
};
ErrorCode::Ok ErrorCode::Ok
} }
extern fn tryseek(inode: &mut INode, pos: i32) -> ErrorCode { extern fn tryseek(inode: &mut INode, pos: i32) -> ErrorCode {

Loading…
Cancel
Save