Skip to content

Commit 5807543

Browse files
committed
fix: recorrect data structre for fstat for aarch64
1 parent bbf0afd commit 5807543

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

api/ruxos_posix_api/src/imp/fs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ pub unsafe fn sys_newfstatat(
257257
}
258258
let node = fops::lookup(&path)?;
259259
let st = RuxStat::from(node.get_attr()?);
260+
261+
// TODO: remove this initialization when fields are fully implemented
262+
unsafe {
263+
core::ptr::write_bytes(kst, 0, 1);
264+
}
265+
260266
unsafe {
261267
(*kst).st_dev = st.st_dev;
262268
(*kst).st_ino = st.st_ino;

modules/ruxfdtable/src/lib.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub struct RuxStat {
200200
/// Total size, in bytes.
201201
pub st_size: i64,
202202
/// Block size for filesystem I/O.
203-
pub st_blksize: core::ffi::c_long,
203+
pub st_blksize: core::ffi::c_int,
204204
/// Padding to maintain alignment.
205205
pub __pad2: core::ffi::c_int,
206206
/// Number of 512B blocks allocated.
@@ -216,7 +216,43 @@ pub struct RuxStat {
216216
}
217217

218218
///Rust version for struct stat in ctypes. Represents file status information.
219-
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
219+
#[cfg(target_arch = "riscv64")]
220+
#[derive(Default)]
221+
pub struct RuxStat {
222+
/// Device identifier.
223+
pub st_dev: u64,
224+
/// Inode number.
225+
pub st_ino: u64,
226+
/// Number of hard links.
227+
pub st_nlink: u64,
228+
/// File mode and permissions.
229+
pub st_mode: core::ffi::c_uint,
230+
/// User ID of owner.
231+
pub st_uid: core::ffi::c_uint,
232+
/// Group ID of owner.
233+
pub st_gid: core::ffi::c_uint,
234+
/// Padding to maintain alignment.
235+
pub __pad0: core::ffi::c_uint,
236+
/// Device ID (if special file).
237+
pub st_rdev: u64,
238+
/// Total size, in bytes.
239+
pub st_size: i64,
240+
/// Block size for filesystem I/O.
241+
pub st_blksize: core::ffi::c_int,
242+
/// Number of 512B blocks allocated.
243+
pub st_blocks: i64,
244+
/// Time of last access.
245+
pub st_atime: RuxTimeSpec,
246+
/// Time of last modification.
247+
pub st_mtime: RuxTimeSpec,
248+
/// Time of last status change.
249+
pub st_ctime: RuxTimeSpec,
250+
/// Unused space, reserved for future use.
251+
pub __unused: [core::ffi::c_long; 3usize],
252+
}
253+
254+
///Rust version for struct stat in ctypes. Represents file status information.
255+
#[cfg(target_arch = "x86_64")]
220256
#[derive(Default)]
221257
pub struct RuxStat {
222258
/// Device identifier.

ulib/include/sys/types.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ typedef uint32_t nlink_t;
2727
typedef uint64_t nlink_t;
2828
#endif
2929

30+
// reference: /ulib/ruxmusl/musl-1.2.3/arch/aarch64/bits/alltypes.h.in
31+
#if defined(__aarch64__) || defined(__riscv__) || defined(__riscv)
32+
typedef int blksize_t;
33+
#else
34+
typedef long blksize_t;
35+
#endif
36+
3037
typedef int64_t off_t;
3138
typedef uint64_t ino_t;
3239
typedef uint64_t dev_t;
33-
typedef long blksize_t;
3440
typedef int64_t blkcnt_t;
3541

3642
typedef unsigned id_t;

0 commit comments

Comments
 (0)