From b0cc7f237d6ccd11cd14e1ef6dbd2b75599761aa Mon Sep 17 00:00:00 2001 From: w-mj Date: Sat, 22 Jun 2019 15:05:04 +0800 Subject: [PATCH] ls -l --- fs/test_fs.cpp | 19 +++++++++++++++++-- include/stat.h | 9 +++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/test_fs.cpp b/fs/test_fs.cpp index f98df36..cba989a 100644 --- a/fs/test_fs.cpp +++ b/fs/test_fs.cpp @@ -6,6 +6,7 @@ #include "dev/block_dev.h" #include "dev/mock_disk.h" #include "delog/delog.h" +#include "stat.h" std::vector split(const std::string& s, char sp) { int i = 0, l = 0; @@ -32,8 +33,22 @@ VFS::DEntry *ls(VFS::DEntry *cwd, const std::vector& cmdd) { using namespace std; cwd->load_children(); for (auto& x: cwd->children) { - if (cmdd.size() == 2 && cmdd[1] == "l") - cout << x->name << " " << x->inode_n << endl; + if (cmdd.size() == 2 && cmdd[1] == "-l") { + x->inflate(); + switch (x->type) { + case VFS::Directory: + cout << "d"; + break; + case VFS::RegularFile: + cout << "-"; + break; + default: + cout << "?"; + break; + } + cout << previlege_to_str(x->inode->mode) << " " << x->inode->uid << " " << x->inode->gid; + cout << " " << x->inode->size << " " << x->inode->ctime << " " << x->name << endl; + } else cout << "(" << x->inode_n <<")"<< x->name << " "; } diff --git a/include/stat.h b/include/stat.h index 527b14e..088254c 100644 --- a/include/stat.h +++ b/include/stat.h @@ -51,5 +51,14 @@ static inline std::string mode_to_str(_u16 mode) { ans += std::to_string((mode & S_IRWXG) >> 3); ans += std::to_string((mode & S_IRWXO) >> 0); + return ans; +} +#include "bits.h" +static inline std::string previlege_to_str(_u16 mode) { + std::string ans = "rwxrwxrwx"; + for (_u16 i = 0; i < 9; i++) { + if (_chk_bit(mode, 8 - i) == 0) + ans[i] = '-'; + } return ans; } \ No newline at end of file