diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2018-09-21 17:34:46 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-09-26 10:33:14 -0700 |
commit | 36d4ec520eea957564ef47bc11dbbcbcb3756460 (patch) | |
tree | cc8258480d47cf6704cf65005e2cf242129e668f /sys_util | |
parent | b43f9bcd526c534251a45165e3aa75d91450802c (diff) | |
download | crosvm-36d4ec520eea957564ef47bc11dbbcbcb3756460.tar crosvm-36d4ec520eea957564ef47bc11dbbcbcb3756460.tar.gz crosvm-36d4ec520eea957564ef47bc11dbbcbcb3756460.tar.bz2 crosvm-36d4ec520eea957564ef47bc11dbbcbcb3756460.tar.lz crosvm-36d4ec520eea957564ef47bc11dbbcbcb3756460.tar.xz crosvm-36d4ec520eea957564ef47bc11dbbcbcb3756460.tar.zst crosvm-36d4ec520eea957564ef47bc11dbbcbcb3756460.zip |
sys_util: use fallocate64 for large file support
Rust's libc crate exports the default off_t definition on 32-bit platforms, rather than the _FILE_OFFSET_BITS=64 variant, so we need to explicitly use the 64-bit API to get support for files larger than 2 GB. The Rust libc crate does not currently export fallocate64, so declare it ourselves for now. This declaration can be removed once fallocate64 is added upstream. BUG=chromium:850998 TEST=Run fstrim on Kevin (32-bit ARM) and verify it works Change-Id: Id0aa7a6e7e6080f4c53e10c3ad1d105f15ee2549 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1238850 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'sys_util')
-rw-r--r-- | sys_util/src/lib.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/sys_util/src/lib.rs b/sys_util/src/lib.rs index 55861af..511ee7e 100644 --- a/sys_util/src/lib.rs +++ b/sys_util/src/lib.rs @@ -160,6 +160,16 @@ pub enum FallocateMode { ZeroRange, } +// TODO(dverkamp): Remove this once fallocate64 is available in libc. +extern { + pub fn fallocate64( + fd: libc::c_int, + mode: libc::c_int, + offset: libc::off64_t, + len: libc::off64_t + ) -> libc::c_int; +} + /// Safe wrapper for `fallocate()`. pub fn fallocate( file: &AsRawFd, @@ -168,16 +178,16 @@ pub fn fallocate( offset: u64, len: u64 ) -> Result<()> { - let offset = if offset > libc::off_t::max_value() as u64 { + let offset = if offset > libc::off64_t::max_value() as u64 { return Err(Error::new(libc::EINVAL)); } else { - offset as libc::off_t + offset as libc::off64_t }; - let len = if len > libc::off_t::max_value() as u64 { + let len = if len > libc::off64_t::max_value() as u64 { return Err(Error::new(libc::EINVAL)); } else { - len as libc::off_t + len as libc::off64_t }; let mut mode = match mode { @@ -191,7 +201,8 @@ pub fn fallocate( // Safe since we pass in a valid fd and fallocate mode, validate offset and len, // and check the return value. - let ret = unsafe { libc::fallocate(file.as_raw_fd(), mode, offset, len) }; + // TODO(dverkamp): Replace this with libc::fallocate64 once it is available. + let ret = unsafe { fallocate64(file.as_raw_fd(), mode, offset, len) }; if ret < 0 { errno_result() } else { |