pub struct OpenFileByIdentifier { /* private fields */ }Expand description
An owned, marshalable parameter set for OpenFileById.
§Example
use std::fs;
use std::os::windows::io::AsHandle;
use windows_namespace_request_sys::open_by_id::{FileIdentifier, OpenFileByIdentifier};
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-byid-{}.tmp", std::process::id()));
fs::write(&path, b"example")?;
let file = fs::File::open(&path)?;
// Any still-open handle on the same volume will do as the hint; it is never
// the object being reopened.
let hint = CapturedHandle::capture(file.as_handle())?;
let request = OpenFileByIdentifier::new(hint, FileIdentifier::FileId(0))
.with_desired_access(FILE_GENERIC_READ)
.with_share_mode(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE);
assert_eq!(request.identifier(), FileIdentifier::FileId(0));Implementations§
Source§impl OpenFileByIdentifier
impl OpenFileByIdentifier
Sourcepub fn new(volume_hint: CapturedHandle, identifier: FileIdentifier) -> Self
pub fn new(volume_hint: CapturedHandle, identifier: FileIdentifier) -> Self
Begins a request to reopen identifier, using volume_hint to name the
volume it lives on.
As with crate::open::OpenFile, the remaining parameters start at
“the caller said nothing” and are set explicitly. There is no creation
disposition to set: OpenFileById has none, which is one of the reasons
this is a separate entry rather than a variant.
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_security(self, security: Option<SecurityAttributes>) -> Self
pub fn with_security(self, security: Option<SecurityAttributes>) -> Self
Sets lpSecurityAttributes from an already-captured value.
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 volume_hint(&self) -> &CapturedHandle
pub fn volume_hint(&self) -> &CapturedHandle
The owned duplicate of the volume-hint handle.
Sourcepub fn identifier(&self) -> FileIdentifier
pub fn identifier(&self) -> FileIdentifier
The identifier this request will reopen.
Sourcepub fn desired_access(&self) -> u32
pub fn desired_access(&self) -> u32
The requested access mask.
The requested share mode.
Sourcepub fn security(&self) -> Option<&SecurityAttributes>
pub fn security(&self) -> Option<&SecurityAttributes>
The captured security attributes, if any were supplied.
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 volume-hint handle.
Not Clone, for the same reason crate::open::OpenFile::try_clone is
not: this request always owns a handle, and duplicating one is fallible.
§Errors
Returns the handle-capture failure when the hint cannot be duplicated.
Sourcepub fn perform(&self) -> Outcome<OwnedHandle>
pub fn perform(&self) -> Outcome<OwnedHandle>
Performs the open on the calling thread.
The handle comes back plain and unassociated, as with every other handle-producing entry.
§Errors
Returns the raw Win32 code, unaltered. ERROR_INVALID_PARAMETER here
most often means the identified object no longer exists, but nothing in
this crate infers that on the caller’s behalf.