File

Struct File 

Source
pub struct File { /* private fields */ }
Expand description

An opened file on the server.

§std::io Support

The File struct also supports the Read and Write traits. Note that both of these traits are blocking, and will block the current thread until the operation is complete. Use File::read_block and File::write_block for non-blocking operations. The File struct also implements the Seek trait. This allows you to seek to a specific position in the file, combined with the Read and Write traits. Using any of the implemented std::io traits mentioned above should have no effect on calling the other, non-blocking methods. Since we would NOT like to call a tokio task from a blocking context, these traits are NOT implemented in the async context!

You may not directly create this struct. Instead, use the Tree::create method to gain a proper handle against the server in the shape of a Resource, that can be then converted to a File.

Implementations§

Source§

impl File

Source

pub fn new(handle: ResourceHandle, end_of_file: u64) -> Self

Source

pub fn access(&self) -> FileAccessMask

Returns the access mask of the file, when the file was opened.

Source

pub async fn read_block( &self, buf: &mut [u8], pos: u64, channel: Option<u32>, unbuffered: bool, ) -> Result<usize>

Read a block of data from an opened file.

§Arguments
  • buf - The buffer to read the data into. A maximum of buf.len() bytes will be read.
  • pos - The offset in the file to read from.
  • unbuffered - Whether to try using unbuffered I/O (if supported by the server).
§Returns

The number of bytes read, up to buf.len().

Source

pub async fn write_block( &self, buf: &[u8], pos: u64, channel: Option<u32>, ) -> Result<usize>

Write a block of data to an opened file.

§Arguments
  • buf - The data to write.
  • pos - The offset in the file to write to.
§Returns

The number of bytes written.

§Note

this method copies the data from buf into an internal buffer, which is then sent to the server. If you want to avoid this copy, use File::write_block_zc instead.

Source

pub async fn write_block_zc( &self, buf: Arc<[u8]>, pos: u64, channel: Option<u32>, ) -> Result<usize>

Write a block of data to an opened file, without copying the data.

§Arguments
  • buf - The data to write.
  • pos - The offset in the file to write to.
§Returns

The number of bytes written.

Source

pub async fn flush(&self) -> Result<()>

Sends a flush request to the server to flush the file.

Source

pub async fn srv_copy(&self, from: &File) -> Result<()>

Performs a server-side copy from another file on the same server.

§Arguments
  • from - The file to copy from.
§Notes
  • This copy must be performed against a file from the same share (tree) as this file.

Methods from Deref<Target = ResourceHandle>§

Source

pub fn name(&self) -> &str

Returns the name of the resource.

Source

pub fn created(&self) -> PrimitiveDateTime

Returns the creation time of the resource.

Source

pub fn modified(&self) -> PrimitiveDateTime

Returns the last modified time of the resource.

Source

pub fn share_type(&self) -> ShareType

Returns the current share type of the resource. See ShareType for more details.

Source

pub fn handle(&self) -> &ResourceHandle

Returns the handle of the resource.

Source

pub async fn query_info<T>(&self) -> Result<T>

Queries the file for information.

§Type Parameters
§Returns

A Result containing the requested information.

§Notes
Source

pub async fn query_full_ea_info( &self, names: Vec<&str>, ) -> Result<QueryFileFullEaInformation>

Queries the file for extended attributes information.

§Arguments
  • names - A list of extended attribute names to query.
§Returns

A Result containing the requested information, of type QueryFileFullEaInformation. See ResourceHandle::query_info for more information.

Source

pub async fn query_full_ea_info_with_options( &self, names: Vec<&str>, output_buffer_length: Option<usize>, ) -> Result<QueryFileFullEaInformation>

Queries the file for extended attributes information.

The output_buffer_length should usually be the returned value from a prior FileEaInformation query, as it indicates the total size of all EAs.

§Arguments
  • names - A list of extended attribute names to query.
§Returns

A Result containing the requested information, of type QueryFileFullEaInformation. See ResourceHandle::query_info for more information.

Source

pub async fn query_info_with_options<T: QueryFileInfoValue>( &self, flags: QueryInfoFlags, output_buffer_length: Option<usize>, ) -> Result<T>

Queries the file for information with additional arguments.

§Type Parameters
§Arguments
  • flags - The QueryInfoFlags for the query request.
  • output_buffer_length - An optional maximum output buffer to use. This should be less than or equal to the negotiated max transaction size. If None, the default transaction size will be used (see ConnectionConfig::default_transaction_size).
§Returns

A Result containing the requested information.

§Notes
Source

pub async fn query_security_info( &self, additional_info: AdditionalInfo, ) -> Result<SecurityDescriptor>

Queries the file for it’s security descriptor.

§Arguments
  • additional_info - The information to request on the security descriptor.
§Returns

A Result containing the requested information, of type SecurityDescriptor.

Source

pub async fn query_security_info_with_options( &self, additional_info: AdditionalInfo, output_buffer_length: Option<usize>, ) -> Result<SecurityDescriptor>

Queries the file for it’s security descriptor.

§Arguments
  • additional_info - The information to request on the security descriptor.
  • output_buffer_length - An optional maximum output buffer to use. This should be less than or equal to the negotiated max transaction size. If None, the default transaction size will be used (see ConnectionConfig::default_transaction_size).
§Returns

A Result containing the requested information, of type SecurityDescriptor.

Source

pub async fn fsctl<T: FsctlRequest>(&self, request: T) -> Result<T::Response>

Sends an FSCTL message for the current resource (file).

§Type Parameters
  • T - The type of the request to send. Must implement the FsctlRequest trait.
§Arguments
  • request - The request to send, which has an associated FSCTL code and data.
§Returns

A Result containing the requested information, as bound to FsctlRequest::Response.

Source

pub async fn fsctl_with_options<T: FsctlRequest>( &self, request: T, max_output_response: u32, ) -> Result<T::Response>

Sends an FSCTL message for the current resource (file) with additional options.

§Type Parameters
  • T - The type of the request to send. Must implement the FsctlRequest trait.
§Arguments
  • request - The request to send, which has an associated FSCTL code and data.
  • max_input_response - The maximum input response size.
  • max_output_response - The maximum output response size.
§Returns

A Result containing the requested information, as bound to FsctlRequest::Response.

Source

pub async fn ioctl( &self, ctl_code: u32, request: Vec<u8>, max_output_response: u32, ) -> Result<Vec<u8>>

Sends an IOCTL message for the current resource (file).

§Arguments
  • ctl_code - The control code for the IOCTL request.
  • request - The request data to send.
  • max_output_response - The maximum output response size.
§Returns

A Result containing the response data as a vector of bytes.

Source

pub async fn query_fs_info<T>(&self) -> Result<T>

Queries the file system information for the current file.

§Type Parameters
§Returns

A Result containing the requested information.

Source

pub async fn query_fs_info_with_options<T>( &self, output_buffer_length: Option<usize>, ) -> Result<T>

Queries the file system information for the current file.

§Type Parameters
§Returns

A Result containing the requested information.

Source

pub async fn set_info<T>(&self, info: T) -> Result<()>

Sets the file information for the current file.

§Type Parameters
  • T - The type of information to set. Must implement the SetFileInfoValue trait.
Source

pub async fn set_filesystem_info<T>(&self, info: T) -> Result<()>

Sets the file system information for the current file.

§Type Parameters
Source

pub async fn set_security_info( &self, info: SecurityDescriptor, additional_info: AdditionalInfo, ) -> Result<()>

Sets the file system information for the current file.

§Arguments
  • info - The information to set - a SecurityDescriptor.
  • additional_info - The information that is set on the security descriptor.
Source

pub async fn close(&self) -> Result<()>

Closes the resource. The resource may not be used after calling this method.

§Returns

A Result indicating success or failure.

Source

pub async fn send_cancel( &self, msg_ids: &AsyncMessageIds, ) -> Result<SendMessageResult>

Source

pub fn same_tree(&self, other: &Self) -> bool

Returns whether current resource is opened from the same tree as the other resource. This is useful to check if two resources are opened from the same share instance.

§Note
  • Even if a resource is positioned in the same tree, if the tree was accessed using different share connections, this will return false!

Trait Implementations§

Source§

impl Deref for File

Source§

type Target = ResourceHandle

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for File

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl GetLen for File

Source§

async fn get_len(&self) -> Result<u64>

Source§

impl ReadAtChannel for File

Source§

async fn read_at_channel( &self, buf: &mut [u8], offset: u64, channel: Option<u32>, ) -> Result<usize>

Source§

impl SetLen for File

Source§

async fn set_len(&self, len: u64) -> Result<()>

Source§

impl TryInto<File> for Resource

Source§

type Error = (Error, Resource)

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

fn try_into(self) -> Result<File, Self::Error>

Performs the conversion.
Source§

impl WriteAtChannel for File

Source§

async fn write_at_channel( &self, buf: &[u8], offset: u64, channel: Option<u32>, ) -> Result<usize>

Auto Trait Implementations§

§

impl !Freeze for File

§

impl !RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl !UnwindSafe for File

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ReadAt for T
where T: ReadAtChannel + ?Sized,

Source§

fn read_at( &self, buf: &mut [u8], offset: u64, ) -> impl Future<Output = Result<usize, Error>> + Send

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WriteAt for T
where T: WriteAtChannel + ?Sized,

Source§

fn write_at( &self, buf: &[u8], offset: u64, ) -> impl Future<Output = Result<usize, Error>> + Send