diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2018-12-06 15:39:31 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-05 20:08:26 -0800 |
commit | 6d47e1b0056d5175a4ae67bf4469ed5c83081c84 (patch) | |
tree | cb054cc570d5f0e4ecb35b6eb147cb7e31ededdd | |
parent | d1eceeca7bfd12d4d1236346d7cdcc89b5e949e2 (diff) | |
download | crosvm-6d47e1b0056d5175a4ae67bf4469ed5c83081c84.tar crosvm-6d47e1b0056d5175a4ae67bf4469ed5c83081c84.tar.gz crosvm-6d47e1b0056d5175a4ae67bf4469ed5c83081c84.tar.bz2 crosvm-6d47e1b0056d5175a4ae67bf4469ed5c83081c84.tar.lz crosvm-6d47e1b0056d5175a4ae67bf4469ed5c83081c84.tar.xz crosvm-6d47e1b0056d5175a4ae67bf4469ed5c83081c84.tar.zst crosvm-6d47e1b0056d5175a4ae67bf4469ed5c83081c84.zip |
sys_util: add set_len() trait
Generalize file_sync into file_traits so that we can add another wrapper, this time for the set_len() method implemented directly on File. This will also be implemented on QcowFile. BUG=chromium:858815 TEST=build_test Change-Id: I43fbd1968a844c8cac359973a63babcc26942204 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1394148 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
-rw-r--r-- | sys_util/src/file_traits.rs (renamed from sys_util/src/file_sync.rs) | 16 | ||||
-rw-r--r-- | sys_util/src/lib.rs | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/sys_util/src/file_sync.rs b/sys_util/src/file_traits.rs index a67be05..2dfc28d 100644 --- a/sys_util/src/file_sync.rs +++ b/sys_util/src/file_traits.rs @@ -19,3 +19,19 @@ impl FileSync for File { self.sync_all() } } + +/// A trait for setting the size of a file. +/// This is equivalent to File's `set_len` method, but +/// wrapped in a trait so that it can be implemented for +/// other types. +pub trait FileSetLen { + // Set the size of this file. + // This is the moral equivalent of `ftruncate()`. + fn set_len(&self, _len: u64) -> Result<()>; +} + +impl FileSetLen for File { + fn set_len(&self, len: u64) -> Result<()> { + File::set_len(self, len) + } +} diff --git a/sys_util/src/lib.rs b/sys_util/src/lib.rs index 38fa81f..185489c 100644 --- a/sys_util/src/lib.rs +++ b/sys_util/src/lib.rs @@ -21,7 +21,7 @@ pub mod syslog; mod errno; mod eventfd; mod file_flags; -mod file_sync; +mod file_traits; mod fork; mod guest_address; mod guest_memory; @@ -62,7 +62,7 @@ pub use tempdir::*; pub use terminal::*; pub use timerfd::*; -pub use file_sync::FileSync; +pub use file_traits::{FileSetLen, FileSync}; pub use guest_memory::Error as GuestMemoryError; pub use mmap::Error as MmapError; pub use seek_hole::SeekHole; |