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 windows_namespace_request_sys::reopen::ReOpenFile;
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(original)
.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: impl Into<SharedHandle>) -> Self
pub fn new(original: impl Into<SharedHandle>) -> Self
Begins a request to reopen the file, directory or volume original names.
The request holds original as one more holder of it. 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) -> &SharedHandle
pub fn original(&self) -> &SharedHandle
The handle being reopened, shared with its other holders.
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 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.