From 43ff80a026b285717ba5160090264dcbfed79b94 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 27 Jun 2024 16:46:19 -0700 Subject: [PATCH] base: windows: pass &File to set_sparse_file() This is only ever called with a File, so replace the AsRawDescriptor parameter to simplify it and prevent accidentally calling it with the wrong type (as mentioned by the comment, it must be a File anyway). BUG=None TEST=tools/dev_container tools/presubmit Change-Id: I08a87211f74983caeabe812448be4984e6f68cea Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5666315 Commit-Queue: Daniel Verkamp Reviewed-by: Noah Gold --- base/src/sys/windows/file_util.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/base/src/sys/windows/file_util.rs b/base/src/sys/windows/file_util.rs index f4a61b260b..786c7eddba 100644 --- a/base/src/sys/windows/file_util.rs +++ b/base/src/sys/windows/file_util.rs @@ -31,14 +31,12 @@ pub fn open_file_or_duplicate>(path: P, options: &OpenOptions) -> /// Marks the given file as sparse. Required if we want hole punching to be performant. /// (If a file is not marked as sparse, a hole punch will just write zeros.) -/// # Safety -/// handle *must* be File. We accept all AsRawDescriptors for convenience. -pub fn set_sparse_file(handle: &T) -> io::Result<()> { +pub fn set_sparse_file(file: &File) -> io::Result<()> { // SAFETY: // Safe because we check the return value and handle is guaranteed to be a // valid file handle by the caller. let result = unsafe { - super::ioctl::ioctl_with_ptr(handle, FSCTL_SET_SPARSE, std::ptr::null_mut::()) + super::ioctl::ioctl_with_ptr(file, FSCTL_SET_SPARSE, std::ptr::null_mut::()) }; if result != 0 { return Err(io::Error::from_raw_os_error(result));