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
impl File
pub fn new(handle: ResourceHandle, end_of_file: u64) -> Self
Sourcepub fn access(&self) -> FileAccessMask
pub fn access(&self) -> FileAccessMask
Returns the access mask of the file, when the file was opened.
Sourcepub async fn read_block(
&self,
buf: &mut [u8],
pos: u64,
channel: Option<u32>,
unbuffered: bool,
) -> Result<usize>
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 ofbuf.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().
Sourcepub async fn write_block(
&self,
buf: &[u8],
pos: u64,
channel: Option<u32>,
) -> Result<usize>
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.
Methods from Deref<Target = ResourceHandle>§
Sourcepub fn created(&self) -> PrimitiveDateTime
pub fn created(&self) -> PrimitiveDateTime
Returns the creation time of the resource.
Sourcepub fn modified(&self) -> PrimitiveDateTime
pub fn modified(&self) -> PrimitiveDateTime
Returns the last modified time of the resource.
Returns the current share type of the resource. See ShareType for more details.
Sourcepub fn handle(&self) -> &ResourceHandle
pub fn handle(&self) -> &ResourceHandle
Returns the handle of the resource.
Sourcepub async fn query_info<T>(&self) -> Result<T>where
T: QueryFileInfoValue,
pub async fn query_info<T>(&self) -> Result<T>where
T: QueryFileInfoValue,
Queries the file for information.
§Type Parameters
T- The type of information to query. Must implement the QueryFileInfoValue trait.
§Returns
A Result containing the requested information.
§Notes
- use
ResourceHandle::query_full_ea_infoto query extended attributes information.
Sourcepub async fn query_full_ea_info(
&self,
names: Vec<&str>,
) -> Result<QueryFileFullEaInformation>
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.
Sourcepub async fn query_full_ea_info_with_options(
&self,
names: Vec<&str>,
output_buffer_length: Option<usize>,
) -> Result<QueryFileFullEaInformation>
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.
Sourcepub async fn query_info_with_options<T: QueryFileInfoValue>(
&self,
flags: QueryInfoFlags,
output_buffer_length: Option<usize>,
) -> Result<T>
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
T- The type of information to query. Must implement the QueryFileInfoValue trait.
§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. IfNone, the default transaction size will be used (seeConnectionConfig::default_transaction_size).
§Returns
A Result containing the requested information.
§Notes
- use ResourceHandle::query_full_ea_info to query extended attributes information.
Sourcepub async fn query_security_info(
&self,
additional_info: AdditionalInfo,
) -> Result<SecurityDescriptor>
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.
Sourcepub async fn query_security_info_with_options(
&self,
additional_info: AdditionalInfo,
output_buffer_length: Option<usize>,
) -> Result<SecurityDescriptor>
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. IfNone, the default transaction size will be used (seeConnectionConfig::default_transaction_size).
§Returns
A Result containing the requested information, of type SecurityDescriptor.
Sourcepub async fn fsctl<T: FsctlRequest>(&self, request: T) -> Result<T::Response>
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 theFsctlRequesttrait.
§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.
Sourcepub async fn fsctl_with_options<T: FsctlRequest>(
&self,
request: T,
max_output_response: u32,
) -> Result<T::Response>
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 theFsctlRequesttrait.
§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.
Sourcepub async fn ioctl(
&self,
ctl_code: u32,
request: Vec<u8>,
max_output_response: u32,
) -> Result<Vec<u8>>
pub async fn ioctl( &self, ctl_code: u32, request: Vec<u8>, max_output_response: u32, ) -> Result<Vec<u8>>
Sourcepub async fn query_fs_info<T>(&self) -> Result<T>where
T: QueryFileSystemInfoValue,
pub async fn query_fs_info<T>(&self) -> Result<T>where
T: QueryFileSystemInfoValue,
Queries the file system information for the current file.
§Type Parameters
T- The type of information to query. Must implement the QueryFileSystemInfoValue trait.
§Returns
A Result containing the requested information.
Sourcepub async fn query_fs_info_with_options<T>(
&self,
output_buffer_length: Option<usize>,
) -> Result<T>where
T: QueryFileSystemInfoValue,
pub async fn query_fs_info_with_options<T>(
&self,
output_buffer_length: Option<usize>,
) -> Result<T>where
T: QueryFileSystemInfoValue,
Queries the file system information for the current file.
§Type Parameters
T- The type of information to query. Must implement the QueryFileSystemInfoValue trait.
§Returns
A Result containing the requested information.
Sourcepub async fn set_info<T>(&self, info: T) -> Result<()>where
T: SetFileInfoValue,
pub async fn set_info<T>(&self, info: T) -> Result<()>where
T: SetFileInfoValue,
Sets the file information for the current file.
§Type Parameters
T- The type of information to set. Must implement the SetFileInfoValue trait.
Sourcepub async fn set_filesystem_info<T>(&self, info: T) -> Result<()>where
T: SetFileSystemInfoValue,
pub async fn set_filesystem_info<T>(&self, info: T) -> Result<()>where
T: SetFileSystemInfoValue,
Sets the file system information for the current file.
§Type Parameters
T- The type of information to set. Must implement the SetFileSystemInfoValue trait.
Sourcepub async fn set_security_info(
&self,
info: SecurityDescriptor,
additional_info: AdditionalInfo,
) -> Result<()>
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.
Sourcepub async fn close(&self) -> Result<()>
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.
pub async fn send_cancel( &self, msg_ids: &AsyncMessageIds, ) -> Result<SendMessageResult>
Sourcepub fn same_tree(&self, other: &Self) -> bool
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!