From 82a559cd6b8208a479aa3a7c1579f54164c6553a Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 15 Sep 2019 22:25:02 -0400 Subject: [PATCH] Refs #150 -- document FileOperations --- src/chrdev.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/chrdev.rs b/src/chrdev.rs index ece83ee1..9398b0e3 100644 --- a/src/chrdev.rs +++ b/src/chrdev.rs @@ -238,13 +238,30 @@ impl FileOperationsVtable { } } +/// `FileOperations` corresponds to the kernel's `struct file_operations`. You +/// implement this trait whenever you'd create a `struct file_operations`. File +/// descriptors may be used from multiple threads (or processes) concurrently, +/// so your type must be `Sync`. pub trait FileOperations: Sync + Sized { + /// A container for the actual `file_operations` value. This will always be: + /// ``` + /// const VTABLE: linux_kernel_module::chrdev::FileOperationsVtable = + /// linux_kernel_module::chrdev::FileOperationsVtable::new::(); + /// ``` const VTABLE: FileOperationsVtable; + /// Creates a new instance of this file. Corresponds to the `open` function + /// pointer in `struct file_operations`. fn open() -> KernelResult; + + /// Reads data from this file to userspace. Corresponds to the `read` + /// function pointer in `struct file_operations`. fn read(&self, _buf: &mut UserSlicePtrWriter, _offset: u64) -> KernelResult<()> { Err(Error::EINVAL) } + + /// Changes the position of the file. Corresponds to the `llseek` function + /// pointer in `struct file_operations`. fn seek(&self, _file: &File, _offset: SeekFrom) -> KernelResult { Err(Error::ESPIPE) }