Skip to content

Commit 7a11820

Browse files
committed
fix: recorrect wrong fstat data layout for riscv and aarch64
1 parent bbf0afd commit 7a11820

5 files changed

Lines changed: 65 additions & 53 deletions

File tree

api/ruxos_posix_api/src/imp/fd_ops.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl From<ctypes::timespec> for RuxTimeSpec {
2626
}
2727

2828
impl From<ctypes::stat> for RuxStat {
29-
#[cfg(target_arch = "aarch64")]
29+
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
3030
fn from(cstat: ctypes::stat) -> Self {
3131
RuxStat {
3232
st_dev: cstat.st_dev,
@@ -48,7 +48,7 @@ impl From<ctypes::stat> for RuxStat {
4848
}
4949
}
5050

51-
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
51+
#[cfg(target_arch = "x86_64")]
5252
fn from(cstat: ctypes::stat) -> Self {
5353
RuxStat {
5454
st_dev: cstat.st_dev,
@@ -80,7 +80,7 @@ impl From<RuxTimeSpec> for ctypes::timespec {
8080
}
8181

8282
impl From<RuxStat> for ctypes::stat {
83-
#[cfg(target_arch = "aarch64")]
83+
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
8484
fn from(rstat: RuxStat) -> Self {
8585
ctypes::stat {
8686
st_dev: rstat.st_dev,
@@ -102,7 +102,7 @@ impl From<RuxStat> for ctypes::stat {
102102
}
103103
}
104104

105-
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
105+
#[cfg(target_arch = "x86_64")]
106106
fn from(rstat: RuxStat) -> Self {
107107
ctypes::stat {
108108
st_dev: rstat.st_dev,

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub struct RuxTimeSpec {
178178
}
179179

180180
///Rust version for struct stat in ctypes. Represents file status information.
181-
#[cfg(target_arch = "aarch64")]
181+
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
182182
#[derive(Default)]
183183
pub struct RuxStat {
184184
/// Device identifier.
@@ -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,7 @@ 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 = "x86_64")]
220220
#[derive(Default)]
221221
pub struct RuxStat {
222222
/// Device identifier.
@@ -251,7 +251,7 @@ pub struct RuxStat {
251251
pub __unused: [core::ffi::c_long; 3usize],
252252
}
253253

254-
#[cfg(target_arch = "aarch64")]
254+
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
255255
impl From<VfsNodeAttr> for RuxStat {
256256
fn from(attr: VfsNodeAttr) -> Self {
257257
Self {
@@ -284,7 +284,7 @@ impl From<VfsNodeAttr> for RuxStat {
284284
}
285285
}
286286

287-
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
287+
#[cfg(target_arch = "x86_64")]
288288
impl From<VfsNodeAttr> for RuxStat {
289289
fn from(attr: VfsNodeAttr) -> Self {
290290
Self {

ulib/include/sys/stat.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <sys/time.h>
1515
#include <sys/types.h>
1616

17-
#if defined(__aarch64__)
17+
#if defined(__aarch64__) || defined(__riscv__) || defined(__riscv)
1818
struct stat {
1919
dev_t st_dev;
2020
ino_t st_ino;
@@ -55,50 +55,50 @@ struct stat {
5555
};
5656
#endif
5757

58-
#if defined(__aarch64__)
58+
#if defined(__aarch64__) || defined(__riscv__) || defined(__riscv)
5959
struct kstat {
60-
dev_t st_dev;
61-
ino_t st_ino;
62-
mode_t st_mode;
63-
nlink_t st_nlink;
64-
uid_t st_uid;
65-
gid_t st_gid;
66-
dev_t st_rdev;
67-
unsigned long __pad;
68-
off_t st_size;
69-
blksize_t st_blksize;
70-
int __pad2;
71-
blkcnt_t st_blocks;
72-
long st_atime_sec;
73-
long st_atime_nsec;
74-
long st_mtime_sec;
75-
long st_mtime_nsec;
76-
long st_ctime_sec;
77-
long st_ctime_nsec;
78-
unsigned __unused[2];
60+
dev_t st_dev;
61+
ino_t st_ino;
62+
mode_t st_mode;
63+
nlink_t st_nlink;
64+
uid_t st_uid;
65+
gid_t st_gid;
66+
dev_t st_rdev;
67+
unsigned long __pad;
68+
off_t st_size;
69+
blksize_t st_blksize;
70+
int __pad2;
71+
blkcnt_t st_blocks;
72+
long st_atime_sec;
73+
long st_atime_nsec;
74+
long st_mtime_sec;
75+
long st_mtime_nsec;
76+
long st_ctime_sec;
77+
long st_ctime_nsec;
78+
unsigned __unused[2];
7979
};
80-
#else
80+
#elif defined(__x86_64__)
8181
struct kstat {
82-
dev_t st_dev;
83-
ino_t st_ino;
84-
nlink_t st_nlink;
85-
86-
mode_t st_mode;
87-
uid_t st_uid;
88-
gid_t st_gid;
89-
unsigned int __pad0;
90-
dev_t st_rdev;
91-
off_t st_size;
92-
blksize_t st_blksize;
93-
blkcnt_t st_blocks;
94-
95-
long st_atime_sec;
96-
long st_atime_nsec;
97-
long st_mtime_sec;
98-
long st_mtime_nsec;
99-
long st_ctime_sec;
100-
long st_ctime_nsec;
101-
long __unused[3];
82+
dev_t st_dev;
83+
ino_t st_ino;
84+
nlink_t st_nlink;
85+
86+
mode_t st_mode;
87+
uid_t st_uid;
88+
gid_t st_gid;
89+
unsigned int __pad0;
90+
dev_t st_rdev;
91+
off_t st_size;
92+
blksize_t st_blksize;
93+
blkcnt_t st_blocks;
94+
95+
long st_atime_sec;
96+
long st_atime_nsec;
97+
long st_mtime_sec;
98+
long st_mtime_nsec;
99+
long st_ctime_sec;
100+
long st_ctime_nsec;
101+
long __unused[3];
102102
};
103103
#endif
104104

ulib/include/sys/types.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@ typedef unsigned long u_long, ulong;
2121

2222
typedef unsigned mode_t;
2323

24-
#if defined(__aarch64__)
24+
#if defined(__aarch64__) || defined(__riscv__) || defined(__riscv)
2525
typedef uint32_t nlink_t;
2626
#else
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)