From 7b4822aa382da58b6a797fa617bb833a8edd6abc Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 5 Nov 2019 13:48:04 -0800 Subject: [PATCH] devices: fix fuse compilation on 32-bit platforms struct stat64 uses different types on 32-bit platforms like arm; cast to the types used there to allow compilation on both x86-64 and arm. In addition, a 64-bit offset was being passed to libc::ftruncate, but this API takes a 32-bit off_t on 32-bit platforms; switch to ftruncate64 to allow the full range of offsets. BUG=b:136128319 TEST=emerge-kevin crosvm TEST=emerge-nami crosvm Change-Id: I382aef8509ca723efcf5024b22e140265636dc10 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1899218 Reviewed-by: Stephen Barber Reviewed-by: Chirantan Ekbote Tested-by: kokoro --- devices/src/virtio/fs/fuse.rs | 12 ++++++------ devices/src/virtio/fs/passthrough.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/devices/src/virtio/fs/fuse.rs b/devices/src/virtio/fs/fuse.rs index 0fac6e6592..f9f97d8030 100644 --- a/devices/src/virtio/fs/fuse.rs +++ b/devices/src/virtio/fs/fuse.rs @@ -654,12 +654,12 @@ impl Into for SetattrIn { out.st_uid = self.uid; out.st_gid = self.gid; out.st_size = self.size as i64; - out.st_atime = self.atime as i64; - out.st_mtime = self.mtime as i64; - out.st_ctime = self.ctime as i64; - out.st_atime_nsec = self.atimensec as i64; - out.st_mtime_nsec = self.mtimensec as i64; - out.st_ctime_nsec = self.ctimensec as i64; + out.st_atime = self.atime as libc::time_t; + out.st_mtime = self.mtime as libc::time_t; + out.st_ctime = self.ctime as libc::time_t; + out.st_atime_nsec = self.atimensec as libc::c_long; + out.st_mtime_nsec = self.mtimensec as libc::c_long; + out.st_ctime_nsec = self.ctimensec as libc::c_long; out } diff --git a/devices/src/virtio/fs/passthrough.rs b/devices/src/virtio/fs/passthrough.rs index c42b2125d5..73e7e8b567 100644 --- a/devices/src/virtio/fs/passthrough.rs +++ b/devices/src/virtio/fs/passthrough.rs @@ -1005,11 +1005,11 @@ impl FileSystem for PassthroughFs { if valid.contains(SetattrValid::SIZE) { // Safe because this doesn't modify any memory and we check the return value. let res = match data { - Data::Handle(_, fd) => unsafe { libc::ftruncate(fd, attr.st_size) }, + Data::Handle(_, fd) => unsafe { libc::ftruncate64(fd, attr.st_size) }, _ => { // There is no `ftruncateat` so we need to get a new fd and truncate it. let f = self.open_inode(inode, libc::O_NONBLOCK | libc::O_RDWR)?; - unsafe { libc::ftruncate(f.as_raw_fd(), attr.st_size) } + unsafe { libc::ftruncate64(f.as_raw_fd(), attr.st_size) } } }; if res < 0 {