pub struct ReOpenFile { /* private fields */ }Expand description
An owned, marshalable parameter set for ReOpenFile.
§Example
A read-only handle to a file that was opened for writing, the same file through a new handle that says what it wants anew:
use std::fs;
use std::os::windows::io::AsHandle;
use windows_namespace_request_sys::reopen::ReOpenFile;
use windows_namespace_request_sys::CapturedHandle;
use windows_sys::Win32::Storage::FileSystem::{
FILE_GENERIC_READ, FILE_SHARE_DELETE, FILE_SHARE_READ, FILE_SHARE_WRITE,
};
let path = std::env::temp_dir().join(format!("wnrs-reopen-{}.tmp", std::process::id()));
fs::write(&path, b"example")?;
let original = fs::OpenOptions::new().read(true).write(true).open(&path)?;
let request = ReOpenFile::new(CapturedHandle::capture(original.as_handle())?)
.with_desired_access(FILE_GENERIC_READ)
.with_share_mode(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE);
let reopened = fs::File::from(request.perform()?);
assert_eq!(reopened.metadata()?.len(), b"example".len() as u64);Implementations§
Source§impl ReOpenFile
impl ReOpenFile
Sourcepub fn new(original: CapturedHandle) -> Self
pub fn new(original: CapturedHandle) -> Self
Begins a request to reopen the file, directory or volume original names.
The remaining parameters start at “the caller said nothing” and are set explicitly.
Sourcepub fn with_desired_access(self, desired_access: u32) -> Self
pub fn with_desired_access(self, desired_access: u32) -> Self
Sets dwDesiredAccess.
Sets dwShareMode.
Sourcepub fn with_flags_and_attributes(
self,
flags_and_attributes: FILE_FLAGS_AND_ATTRIBUTES,
) -> Self
pub fn with_flags_and_attributes( self, flags_and_attributes: FILE_FLAGS_AND_ATTRIBUTES, ) -> Self
Sets dwFlagsAndAttributes, carried verbatim as in crate::open::OpenFile.
Sourcepub fn original(&self) -> &CapturedHandle
pub fn original(&self) -> &CapturedHandle
The owned duplicate of the handle being reopened.
Sourcepub fn desired_access(&self) -> u32
pub fn desired_access(&self) -> u32
The requested access mask.
The requested share mode.
Sourcepub fn flags_and_attributes(&self) -> FILE_FLAGS_AND_ATTRIBUTES
pub fn flags_and_attributes(&self) -> FILE_FLAGS_AND_ATTRIBUTES
The requested flags and attributes.
Sourcepub fn try_clone(&self) -> Result<Self, HandleCaptureError>
pub fn try_clone(&self) -> Result<Self, HandleCaptureError>
Copies the request, duplicating the handle.
Not Clone, because this request always owns a handle and duplicating one is fallible.
§Errors
Returns the handle-capture failure when the handle cannot be duplicated.
Sourcepub fn perform(&self) -> Outcome<OwnedHandle>
pub fn perform(&self) -> Outcome<OwnedHandle>
Performs the reopen on the calling thread.
The handle comes back owned and is a new handle each time, however often the request is performed.
§Errors
Returns the raw Win32 code, unaltered. An access or sharing that conflicts with a previous open still open is a sharing violation, which is the kernel’s error and passes through.