Skip to content

Commit 52573b4

Browse files
committed
Make Nsecs be 64-bit on 32-bit x86 Linux.
1 parent 28f25ad commit 52573b4

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,15 +933,23 @@ fn utimensat_old(
933933
.tv_sec
934934
.try_into()
935935
.map_err(|_| io::Errno::OVERFLOW)?,
936-
tv_nsec: times.last_access.tv_nsec,
936+
tv_nsec: times
937+
.last_access
938+
.tv_nsec
939+
.try_into()
940+
.map_err(|_| io::Errno::OVERFLOW)?,
937941
},
938942
c::timespec {
939943
tv_sec: times
940944
.last_modification
941945
.tv_sec
942946
.try_into()
943947
.map_err(|_| io::Errno::OVERFLOW)?,
944-
tv_nsec: times.last_modification.tv_nsec,
948+
tv_nsec: times
949+
.last_modification
950+
.tv_nsec
951+
.try_into()
952+
.map_err(|_| io::Errno::OVERFLOW)?,
945953
},
946954
];
947955
unsafe {
@@ -1515,15 +1523,23 @@ fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> {
15151523
.tv_sec
15161524
.try_into()
15171525
.map_err(|_| io::Errno::OVERFLOW)?,
1518-
tv_nsec: times.last_access.tv_nsec,
1526+
tv_nsec: times
1527+
.last_access
1528+
.tv_nsec
1529+
.try_into()
1530+
.map_err(|_| io::Errno::OVERFLOW)?,
15191531
},
15201532
c::timespec {
15211533
tv_sec: times
15221534
.last_modification
15231535
.tv_sec
15241536
.try_into()
15251537
.map_err(|_| io::Errno::OVERFLOW)?,
1526-
tv_nsec: times.last_modification.tv_nsec,
1538+
tv_nsec: times
1539+
.last_modification
1540+
.tv_nsec
1541+
.try_into()
1542+
.map_err(|_| io::Errno::OVERFLOW)?,
15271543
},
15281544
];
15291545

src/timespec.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! `Timespec` and related types, which are used by multiple public API
22
//! modules.
33
4+
#[cfg(not(fix_y2038))]
45
use crate::backend::c;
56

67
/// `struct timespec`
@@ -28,18 +29,22 @@ pub type Secs = c::time_t;
2829
#[cfg(fix_y2038)]
2930
pub type Secs = i64;
3031

31-
/// A type for the `tv_nsec` field of [`Timespec`].
32-
#[cfg(all(libc, target_arch = "x86_64", target_pointer_width = "32"))]
32+
/// A type for the `tv_sec` field of [`Timespec`].
33+
#[cfg(any(
34+
fix_y2038,
35+
linux_raw,
36+
all(libc, target_arch = "x86_64", target_pointer_width = "32")
37+
))]
3338
pub type Nsecs = i64;
3439

3540
/// A type for the `tv_nsec` field of [`Timespec`].
36-
#[cfg(all(libc, not(all(target_arch = "x86_64", target_pointer_width = "32"))))]
41+
#[cfg(all(
42+
not(fix_y2038),
43+
libc,
44+
not(all(target_arch = "x86_64", target_pointer_width = "32"))
45+
))]
3746
pub type Nsecs = c::c_long;
3847

39-
/// A type for the `tv_nsec` field of [`Timespec`].
40-
#[cfg(linux_raw)]
41-
pub type Nsecs = i64;
42-
4348
/// On 32-bit glibc platforms, `timespec` has anonymous padding fields, which
4449
/// Rust doesn't support yet (see `unnamed_fields`), so we define our own
4550
/// struct with explicit padding, with bidirectional `From` impls.
@@ -52,7 +57,7 @@ pub(crate) struct LibcTimespec {
5257
#[cfg(target_endian = "big")]
5358
padding: core::mem::MaybeUninit<u32>,
5459

55-
pub(crate) tv_nsec: Nsecs,
60+
pub(crate) tv_nsec: i32,
5661

5762
#[cfg(target_endian = "little")]
5863
padding: core::mem::MaybeUninit<u32>,
@@ -64,7 +69,7 @@ impl From<LibcTimespec> for Timespec {
6469
fn from(t: LibcTimespec) -> Self {
6570
Self {
6671
tv_sec: t.tv_sec,
67-
tv_nsec: t.tv_nsec,
72+
tv_nsec: t.tv_nsec as _,
6873
}
6974
}
7075
}
@@ -75,7 +80,7 @@ impl From<Timespec> for LibcTimespec {
7580
fn from(t: Timespec) -> Self {
7681
Self {
7782
tv_sec: t.tv_sec,
78-
tv_nsec: t.tv_nsec,
83+
tv_nsec: t.tv_nsec as _,
7984
padding: core::mem::MaybeUninit::uninit(),
8085
}
8186
}

0 commit comments

Comments
 (0)