Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit fa9ee7e

Browse files
authored
Refs #150 -- document FileOperations
1 parent a5a85f5 commit fa9ee7e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/chrdev.rs

+17
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,30 @@ impl FileOperationsVtable {
238238
}
239239
}
240240

241+
/// `FileOperations` corresponds to the kernel's `struct file_operations`. You
242+
/// implement this trait whenever you'd create a `struct file_operations`. File
243+
/// descriptors may be used from multiple threads (or processes) concurrently,
244+
/// so your type must be `Sync`.
241245
pub trait FileOperations: Sync + Sized {
246+
/// A container for the actual `file_operations` value. This will always be:
247+
/// ```
248+
/// const VTABLE: linux_kernel_module::chrdev::FileOperationsVtable =
249+
/// linux_kernel_module::chrdev::FileOperationsVtable::new::<Self>();
250+
/// ```
242251
const VTABLE: FileOperationsVtable;
243252

253+
/// Creates a new instance of this file. Corresponds to the `open` function
254+
/// pointer in `struct file_operations`.
244255
fn open() -> KernelResult<Self>;
256+
257+
/// Reads data from this file to userspace. Corresponds to the `read`
258+
/// function pointer in `struct file_operations`.
245259
fn read(&self, _buf: &mut UserSlicePtrWriter, _offset: u64) -> KernelResult<()> {
246260
Err(Error::EINVAL)
247261
}
262+
263+
/// Changes the position of the file. Corresponds to the `llseek` function
264+
/// pointer in `struct file_operations`.
248265
fn seek(&self, _file: &File, _offset: SeekFrom) -> KernelResult<u64> {
249266
Err(Error::ESPIPE)
250267
}

0 commit comments

Comments
 (0)