1
0
mirror of https://github.com/rcore-os/rCore.git synced 2025-01-19 01:07:05 +04:00

fix getdents64: set inode id and file type properly

This commit is contained in:
function2-llx 2020-05-13 02:05:31 +08:00
parent 17b55552d1
commit 0c4d53f8d4
5 changed files with 34 additions and 60 deletions

38
kernel/Cargo.lock generated
View File

@ -358,11 +358,11 @@ dependencies = [
"raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rboot 0.1.2",
"rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"rcore-memory 0.1.0",
"rcore-thread 0.1.0 (git+https://github.com/function2-llx/rcore-thread?rev=8c1022d)",
"riscv 0.5.0 (git+https://github.com/rcore-os/riscv)",
@ -388,7 +388,7 @@ dependencies = [
[[package]]
name = "rcore-fs"
version = "0.1.0"
source = "git+https://github.com/function2-llx/rcore-fs?rev=1311a81#1311a8139d31bb5550245b08d8c0180900fc67e9"
source = "git+https://github.com/function2-llx/rcore-fs?rev=9143f80#9143f805f742f17d934bd7c5c0d9420b8a35a5e5"
dependencies = [
"filetime 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -398,42 +398,42 @@ dependencies = [
[[package]]
name = "rcore-fs-devfs"
version = "0.1.0"
source = "git+https://github.com/function2-llx/rcore-fs?rev=1311a81#1311a8139d31bb5550245b08d8c0180900fc67e9"
source = "git+https://github.com/function2-llx/rcore-fs?rev=9143f80#9143f805f742f17d934bd7c5c0d9420b8a35a5e5"
dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rcore-fs-mountfs"
version = "0.1.0"
source = "git+https://github.com/function2-llx/rcore-fs?rev=1311a81#1311a8139d31bb5550245b08d8c0180900fc67e9"
source = "git+https://github.com/function2-llx/rcore-fs?rev=9143f80#9143f805f742f17d934bd7c5c0d9420b8a35a5e5"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rcore-fs-ramfs"
version = "0.1.0"
source = "git+https://github.com/function2-llx/rcore-fs?rev=1311a81#1311a8139d31bb5550245b08d8c0180900fc67e9"
source = "git+https://github.com/function2-llx/rcore-fs?rev=9143f80#9143f805f742f17d934bd7c5c0d9420b8a35a5e5"
dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rcore-fs-sfs"
version = "0.1.0"
source = "git+https://github.com/function2-llx/rcore-fs?rev=1311a81#1311a8139d31bb5550245b08d8c0180900fc67e9"
source = "git+https://github.com/function2-llx/rcore-fs?rev=9143f80#9143f805f742f17d934bd7c5c0d9420b8a35a5e5"
dependencies = [
"bitvec 0.17.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)",
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)",
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -743,11 +743,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d"
"checksum raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf"
"checksum rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)" = "<none>"
"checksum rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)" = "<none>"
"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)" = "<none>"
"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)" = "<none>"
"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)" = "<none>"
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=1311a81)" = "<none>"
"checksum rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)" = "<none>"
"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)" = "<none>"
"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)" = "<none>"
"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)" = "<none>"
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=9143f80)" = "<none>"
"checksum rcore-thread 0.1.0 (git+https://github.com/function2-llx/rcore-thread?rev=8c1022d)" = "<none>"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"

View File

@ -66,11 +66,11 @@ bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" }
rcore-console = { git = "https://github.com/rcore-os/rcore-console", rev = "b7bacf9", default-features = false }
rcore-memory = { path = "../crate/memory" }
rcore-thread = { git = "https://github.com/function2-llx/rcore-thread", rev = "8c1022d" }
rcore-fs = { git = "https://github.com/function2-llx/rcore-fs", rev = "1311a81" }
rcore-fs-sfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "1311a81" }
rcore-fs-ramfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "1311a81" }
rcore-fs-mountfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "1311a81" }
rcore-fs-devfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "1311a81" }
rcore-fs = { git = "https://github.com/function2-llx/rcore-fs", rev = "9143f80" }
rcore-fs-sfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "9143f80" }
rcore-fs-ramfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "9143f80" }
rcore-fs-mountfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "9143f80" }
rcore-fs-devfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "9143f80" }
compression = { version = "0.1.4", default-features = false, features = ["gzip"] }

View File

@ -160,14 +160,14 @@ impl FileHandle {
self.inode.lookup_follow(path, max_follow)
}
pub fn read_entry(&mut self) -> Result<String> {
pub fn read_entry(&mut self) -> Result<(usize, FileType, String)> {
if !self.options.lock().read {
return Err(FsError::InvalidParam); // FIXME: => EBADF
}
let mut offset_inner = self.offset.lock();
let name = self.inode.get_entry(*offset_inner as usize)?;
let entry = self.inode.get_entry(*offset_inner as usize)?;
*offset_inner += 1;
Ok(name)
Ok(entry)
}
pub fn poll(&self) -> Result<PollStatus> {
@ -207,33 +207,6 @@ impl FileHandle {
pub fn inode(&self) -> Arc<dyn INode> {
self.inode.clone()
}
// pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult {
// use super::fcntl::*;
// match cmd {
// F_SETFD => {
// self.fd_cloexec = (arg & 1) as bool;
// Ok(0)
// }
// F_GETFD => {
// Ok(self.fd_cloexec as usize)
// }
// F_SETFL => {
// if arg & 0x800 > 0 {
// self.options.nonblock = true;
// }
// Ok(0)
// }
// F_DUPFD_CLOEXEC => {
// info!("dupfd_cloexec: arg: {:#x}", arg);
// let proc = self
// Ok(0)
// }
// _ => {
// Ok(0)
// }
// }
// }
}
impl fmt::Debug for FileHandle {

View File

@ -801,12 +801,11 @@ impl Syscall<'_> {
}
let mut writer = DirentBufWriter::new(buf);
loop {
let name = match file.read_entry() {
let (ino, file_type, name) = match file.read_entry() {
Err(FsError::EntryNotFound) => break,
r => r,
}?;
// TODO: get ino from dirent
let ok = writer.try_write(0, DirentType::from_type(&info.type_).bits(), &name);
let ok = writer.try_write(ino as u64, DirentType::from_type(&file_type).bits(), &name);
if !ok {
file.seek(SeekFrom::Current(-1))?;
break;
@ -1435,7 +1434,7 @@ impl OpenFlags {
pub struct LinuxDirent64 {
/// Inode number
ino: u64,
/// Offset to next structure
/// Offset to next structure, an opaque value
offset: u64,
/// Size of this dirent
reclen: u16,

View File

@ -161,6 +161,10 @@ impl TimeSpec {
inode.set_metadata(&metadata).expect("set metadata failed");
}
}
pub fn is_zero(&self) -> bool {
self.sec == 0 && self.nsec == 0
}
}
impl Into<Timespec> for TimeSpec {
@ -169,8 +173,6 @@ impl Into<Timespec> for TimeSpec {
sec: self.sec as i64,
nsec: self.nsec as i32,
}
pub fn is_zero(&self) -> bool {
self.sec == 0 && self.nsec == 0
}
}