Trait kernel::file::Operations
source · [−]pub trait Operations {
type Data: ForeignOwnable + Send + Sync = ();
type OpenData: Sync = ();
Show 11 associated constants and 10 methods
const USE_VTABLE_ATTR: ();
const HAS_OPEN: bool = false;
const HAS_RELEASE: bool = false;
const HAS_READ: bool = false;
const HAS_WRITE: bool = false;
const HAS_SEEK: bool = false;
const HAS_IOCTL: bool = false;
const HAS_COMPAT_IOCTL: bool = false;
const HAS_FSYNC: bool = false;
const HAS_MMAP: bool = false;
const HAS_POLL: bool = false;
fn open(context: &Self::OpenData, file: &File) -> Result<Self::Data>;
fn release(_data: Self::Data, _file: &File) { ... }
fn read(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_writer: &mut impl IoBufferWriter,
_offset: u64
) -> Result<usize> { ... }
fn write(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_reader: &mut impl IoBufferReader,
_offset: u64
) -> Result<usize> { ... }
fn seek(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_offset: SeekFrom
) -> Result<u64> { ... }
fn ioctl(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand
) -> Result<i32> { ... }
fn compat_ioctl(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand
) -> Result<i32> { ... }
fn fsync(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_start: u64,
_end: u64,
_datasync: bool
) -> Result<u32> { ... }
fn mmap(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_vma: &mut Area
) -> Result { ... }
fn poll(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_table: &PollTable
) -> Result<u32> { ... }
}
Expand description
Corresponds to the kernel’s struct file_operations
.
You implement this trait whenever you would create a struct file_operations
.
File descriptors may be used from multiple threads/processes concurrently, so your type must be
Sync
. It must also be Send
because Operations::release
will be called from the
thread that decrements that associated file’s refcount to zero.
Provided Associated Types
sourcetype Data: ForeignOwnable + Send + Sync = ()
type Data: ForeignOwnable + Send + Sync = ()
The type of the context data returned by Operations::open
and made available to
other methods.
sourcetype OpenData: Sync = ()
type OpenData: Sync = ()
The type of the context data passed to Operations::open
.
Required Associated Constants
sourceconst USE_VTABLE_ATTR: ()
const USE_VTABLE_ATTR: ()
A marker to prevent implementors from forgetting to use #[vtable]
attribute when implementing this trait.
Provided Associated Constants
sourceconst HAS_RELEASE: bool = false
const HAS_RELEASE: bool = false
Indicates if the release
method is overridden by the implementor.
sourceconst HAS_COMPAT_IOCTL: bool = false
const HAS_COMPAT_IOCTL: bool = false
Indicates if the compat_ioctl
method is overridden by the implementor.
Required Methods
Provided Methods
sourcefn release(_data: Self::Data, _file: &File)
fn release(_data: Self::Data, _file: &File)
Cleans up after the last reference to the file goes away.
Note that context data is moved, so it will be freed automatically unless the implementation moves it elsewhere.
Corresponds to the release
function pointer in struct file_operations
.
sourcefn read(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_writer: &mut impl IoBufferWriter,
_offset: u64
) -> Result<usize>
fn read(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_writer: &mut impl IoBufferWriter,
_offset: u64
) -> Result<usize>
Reads data from this file to the caller’s buffer.
Corresponds to the read
and read_iter
function pointers in struct file_operations
.
sourcefn write(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_reader: &mut impl IoBufferReader,
_offset: u64
) -> Result<usize>
fn write(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_reader: &mut impl IoBufferReader,
_offset: u64
) -> Result<usize>
Writes data from the caller’s buffer to this file.
Corresponds to the write
and write_iter
function pointers in struct file_operations
.
sourcefn seek(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_offset: SeekFrom
) -> Result<u64>
fn seek(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_offset: SeekFrom
) -> Result<u64>
Changes the position of the file.
Corresponds to the llseek
function pointer in struct file_operations
.
sourcefn ioctl(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand
) -> Result<i32>
fn ioctl(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand
) -> Result<i32>
Performs IO control operations that are specific to the file.
Corresponds to the unlocked_ioctl
function pointer in struct file_operations
.
sourcefn compat_ioctl(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand
) -> Result<i32>
fn compat_ioctl(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_cmd: &mut IoctlCommand
) -> Result<i32>
Performs 32-bit IO control operations on that are specific to the file on 64-bit kernels.
Corresponds to the compat_ioctl
function pointer in struct file_operations
.
sourcefn fsync(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_start: u64,
_end: u64,
_datasync: bool
) -> Result<u32>
fn fsync(
_data: <Self::Data as ForeignOwnable>::Borrowed<'_>,
_file: &File,
_start: u64,
_end: u64,
_datasync: bool
) -> Result<u32>
Syncs pending changes to this file.
Corresponds to the fsync
function pointer in struct file_operations
.