From 480bf0d14ca13b41ae670885566abe1916f0bcbf Mon Sep 17 00:00:00 2001 From: equation314 Date: Sun, 17 Mar 2019 23:16:22 +0800 Subject: [PATCH] fix struct stat layout on non-x86 archs --- kernel/src/syscall/fs.rs | 62 ++++++++++++++++++++++++++++++++++++++++ user | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 167052f..9a21cd4 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -718,7 +718,9 @@ impl DirentBufWriter { } } +#[cfg(target_arch = "x86_64")] #[repr(C)] +#[derive(Debug)] pub struct Stat { /// ID of device containing file dev: u64, @@ -752,6 +754,44 @@ pub struct Stat { ctime: Timespec, } +#[cfg(not(target_arch = "x86_64"))] +#[repr(C)] +#[derive(Debug)] +pub struct Stat { + /// ID of device containing file + dev: u64, + /// inode number + ino: u64, + /// file type and mode + mode: StatMode, + /// number of hard links + nlink: u32, + + /// user ID of owner + uid: u32, + /// group ID of owner + gid: u32, + /// device ID (if special file) + rdev: u64, + /// padding + __pad: u64, + /// total size, in bytes + size: u64, + /// blocksize for filesystem I/O + blksize: u32, + /// padding + __pad2: u32, + /// number of 512B blocks allocated + blocks: u64, + + /// last access time + atime: Timespec, + /// last modification time + mtime: Timespec, + /// last status change time + ctime: Timespec, +} + bitflags! { pub struct StatMode: u32 { const NULL = 0; @@ -824,6 +864,7 @@ impl StatMode { } impl From for Stat { + #[cfg(target_arch = "x86_64")] fn from(info: Metadata) -> Self { Stat { dev: info.dev as u64, @@ -842,6 +883,27 @@ impl From for Stat { _pad0: 0 } } + + #[cfg(not(target_arch = "x86_64"))] + fn from(info: Metadata) -> Self { + Stat { + dev: info.dev as u64, + ino: info.inode as u64, + mode: StatMode::from_type_mode(info.type_, info.mode as u16), + nlink: info.nlinks as u32, + uid: info.uid as u32, + gid: info.gid as u32, + rdev: 0, + size: info.size as u64, + blksize: info.blk_size as u32, + blocks: info.blocks as u64, + atime: info.atime, + mtime: info.mtime, + ctime: info.ctime, + __pad: 0, + __pad2: 0 + } + } } const SEEK_SET: u8 = 1; diff --git a/user b/user index 10d4972..9484651 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit 10d49723dfbdb9015f16beb55e97c108de7e19da +Subproject commit 9484651b977e75d66a56f0f99b3865e424ea8d48