Skip to main content

FileOps

Trait FileOps 

Source
pub trait FileOps:
    Send
    + Sync
    + AsAny
    + 'static {
Show 23 methods // Required methods fn is_seekable(&self) -> bool; fn read( &self, file: &FileObject, current_task: &CurrentTask, offset: usize, data: &mut dyn OutputBuffer, ) -> Result<usize, Errno>; fn write( &self, file: &FileObject, current_task: &CurrentTask, offset: usize, data: &mut dyn InputBuffer, ) -> Result<usize, Errno>; fn seek( &self, file: &FileObject, current_task: &CurrentTask, current_offset: off_t, target: SeekTarget, ) -> Result<off_t, Errno>; // Provided methods fn open( &self, _file: &FileObject, _current_task: &CurrentTask, ) -> Result<(), Errno> { ... } fn close( self: Box<Self>, _file: &FileObjectState, _current_task: &CurrentTask, ) { ... } fn flush(&self, _file: &FileObject, _current_task: &CurrentTask) { ... } fn has_persistent_offsets(&self) -> bool { ... } fn writes_update_seek_offset(&self) -> bool { ... } fn sync( &self, file: &FileObject, current_task: &CurrentTask, ) -> Result<(), Errno> { ... } fn data_sync( &self, file: &FileObject, current_task: &CurrentTask, ) -> Result<(), Errno> { ... } fn get_memory( &self, _file: &FileObject, _current_task: &CurrentTask, _length: Option<usize>, _prot: ProtectionFlags, ) -> Result<Arc<MemoryObject>, Errno> { ... } fn mmap( &self, file: &FileObject, current_task: &CurrentTask, addr: DesiredAddress, memory_offset: u64, length: usize, prot_flags: ProtectionFlags, options: MappingOptions, filename: NamespaceNode, ) -> Result<UserAddress, Errno> { ... } fn readdir( &self, _file: &FileObject, _current_task: &CurrentTask, _sink: &mut dyn DirentSink, ) -> Result<(), Errno> { ... } fn wait_async( &self, _file: &FileObject, _current_task: &CurrentTask, _waiter: &Waiter, _events: FdEvents, _handler: EventHandler, ) -> Option<WaitCanceler> { ... } fn query_events( &self, _file: &FileObject, _current_task: &CurrentTask, ) -> Result<FdEvents, Errno> { ... } fn ioctl( &self, _file: &FileObject, _current_task: &CurrentTask, _request: u32, _arg: SyscallArg, ) -> Result<SyscallResult, Errno> { ... } fn fcntl( &self, _file: &FileObject, _current_task: &CurrentTask, cmd: u32, _arg: u64, ) -> Result<SyscallResult, Errno> { ... } fn to_handle( &self, file: &FileObject, current_task: &CurrentTask, ) -> Result<Option<NullableHandle>, Errno> { ... } fn get_handles( &self, _file: &FileObject, _current_task: &CurrentTask, ) -> Result<Vec<NullableHandle>, Errno> { ... } fn as_thread_group_key( &self, _file: &FileObject, ) -> Result<ThreadGroupKey, Errno> { ... } fn readahead( &self, _file: &FileObject, _current_task: &CurrentTask, _offset: usize, _length: usize, ) -> Result<(), Errno> { ... } fn extra_fdinfo( &self, _file: &FileHandle, _current_task: &CurrentTask, ) -> Option<FsString> { ... }
}
Expand description

Corresponds to struct file_operations in Linux, plus any filesystem-specific data.

Required Methods§

Source

fn is_seekable(&self) -> bool

Returns whether the file is seekable.

Source

fn read( &self, file: &FileObject, current_task: &CurrentTask, offset: usize, data: &mut dyn OutputBuffer, ) -> Result<usize, Errno>

Read from the file at an offset. If the file does not have persistent offsets (either directly, or because it is not seekable), offset will be 0 and can be ignored. Returns the number of bytes read.

Source

fn write( &self, file: &FileObject, current_task: &CurrentTask, offset: usize, data: &mut dyn InputBuffer, ) -> Result<usize, Errno>

Write to the file with an offset. If the file does not have persistent offsets (either directly, or because it is not seekable), offset will be 0 and can be ignored. Returns the number of bytes written.

Source

fn seek( &self, file: &FileObject, current_task: &CurrentTask, current_offset: off_t, target: SeekTarget, ) -> Result<off_t, Errno>

Adjust the current_offset if the file is seekable.

Provided Methods§

Source

fn open( &self, _file: &FileObject, _current_task: &CurrentTask, ) -> Result<(), Errno>

Called when the FileObject is opened/created

Source

fn close(self: Box<Self>, _file: &FileObjectState, _current_task: &CurrentTask)

Called when the FileObject is destroyed.

Source

fn flush(&self, _file: &FileObject, _current_task: &CurrentTask)

Called every time close() is called on this file, even if the file is not ready to be released.

Source

fn has_persistent_offsets(&self) -> bool

Returns whether the file has meaningful seek offsets. Returning false is only optimization and will makes FileObject never hold the offset lock when calling read and write.

Source

fn writes_update_seek_offset(&self) -> bool

Returns true if write() operations on the file will update the seek offset.

Source

fn sync( &self, file: &FileObject, current_task: &CurrentTask, ) -> Result<(), Errno>

Syncs cached state associated with the file descriptor to persistent storage.

The method blocks until the synchronization is complete.

Source

fn data_sync( &self, file: &FileObject, current_task: &CurrentTask, ) -> Result<(), Errno>

Syncs cached data, and only enough metadata to retrieve said data, to persistent storage.

The method blocks until the synchronization is complete.

Source

fn get_memory( &self, _file: &FileObject, _current_task: &CurrentTask, _length: Option<usize>, _prot: ProtectionFlags, ) -> Result<Arc<MemoryObject>, Errno>

Returns a VMO representing this file. At least the requested protection flags must be set on the VMO. Reading or writing the VMO must read or write the file. If this is not possible given the requested protection, an error must be returned. The length is a hint for the desired size of the VMO. The returned VMO may be larger or smaller than the requested length. This method is typically called by Self::mmap.

Source

fn mmap( &self, file: &FileObject, current_task: &CurrentTask, addr: DesiredAddress, memory_offset: u64, length: usize, prot_flags: ProtectionFlags, options: MappingOptions, filename: NamespaceNode, ) -> Result<UserAddress, Errno>

Responds to an mmap call. The default implementation calls Self::get_memory to get a VMO and then maps it with [crate::mm::MemoryManager::map]. Only implement this trait method if your file needs to control mapping, or record where a VMO gets mapped.

Source

fn readdir( &self, _file: &FileObject, _current_task: &CurrentTask, _sink: &mut dyn DirentSink, ) -> Result<(), Errno>

Respond to a getdents or getdents64 calls.

The file.offset lock will be held while entering this method. The implementation must look at sink.offset() to read the current offset into the file.

Source

fn wait_async( &self, _file: &FileObject, _current_task: &CurrentTask, _waiter: &Waiter, _events: FdEvents, _handler: EventHandler, ) -> Option<WaitCanceler>

Establish a one-shot, edge-triggered, asynchronous wait for the given FdEvents for the given file and task. Returns None if this file does not support blocking waits.

Active events are not considered. This is similar to the semantics of the ZX_WAIT_ASYNC_EDGE flag on zx_wait_async. To avoid missing events, the caller must call query_events after calling this.

If your file does not support blocking waits, leave this as the default implementation.

Source

fn query_events( &self, _file: &FileObject, _current_task: &CurrentTask, ) -> Result<FdEvents, Errno>

The events currently active on this file.

If this function returns POLLIN or POLLOUT, then FileObject will add POLLRDNORM and POLLWRNORM, respective, which are equivalent in the Linux UAPI.

See https://linux.die.net/man/2/poll

Source

fn ioctl( &self, _file: &FileObject, _current_task: &CurrentTask, _request: u32, _arg: SyscallArg, ) -> Result<SyscallResult, Errno>

Source

fn fcntl( &self, _file: &FileObject, _current_task: &CurrentTask, cmd: u32, _arg: u64, ) -> Result<SyscallResult, Errno>

Source

fn to_handle( &self, file: &FileObject, current_task: &CurrentTask, ) -> Result<Option<NullableHandle>, Errno>

Return a handle that allows access to this file descritor through the zxio protocols.

If None is returned, the file will act as if it was a fd to /dev/null.

Source

fn get_handles( &self, _file: &FileObject, _current_task: &CurrentTask, ) -> Result<Vec<NullableHandle>, Errno>

Source

fn as_thread_group_key( &self, _file: &FileObject, ) -> Result<ThreadGroupKey, Errno>

Returns the associated pid_t.

Used by pidfd and /proc/<pid>. Unlikely to be used by other files.

Source

fn readahead( &self, _file: &FileObject, _current_task: &CurrentTask, _offset: usize, _length: usize, ) -> Result<(), Errno>

Source

fn extra_fdinfo( &self, _file: &FileHandle, _current_task: &CurrentTask, ) -> Option<FsString>

Extra information that is included in the /proc//fdfino/ entry.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§