Skip to main content

ReOpenFile

Struct ReOpenFile 

Source
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

Source

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.

Source

pub fn with_desired_access(self, desired_access: u32) -> Self

Sets dwDesiredAccess.

Source

pub fn with_share_mode(self, share_mode: FILE_SHARE_MODE) -> Self

Sets dwShareMode.

Source

pub fn with_flags_and_attributes( self, flags_and_attributes: FILE_FLAGS_AND_ATTRIBUTES, ) -> Self

Sets dwFlagsAndAttributes, carried verbatim as in crate::open::OpenFile.

Source

pub fn original(&self) -> &CapturedHandle

The owned duplicate of the handle being reopened.

Source

pub fn desired_access(&self) -> u32

The requested access mask.

Source

pub fn share_mode(&self) -> FILE_SHARE_MODE

The requested share mode.

Source

pub fn flags_and_attributes(&self) -> FILE_FLAGS_AND_ATTRIBUTES

The requested flags and attributes.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for ReOpenFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Request for ReOpenFile

Source§

type Error = Win32Error

How performing it can fail. Read more
Source§

type Output = OwnedHandle

What performing the request produces.
Source§

fn perform(&self) -> Outcome<OwnedHandle>

Performs the request on the calling thread. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.