This repository was archived by the owner on Mar 7, 2021. It is now read-only.
File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -238,13 +238,30 @@ impl FileOperationsVtable {
238
238
}
239
239
}
240
240
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`.
241
245
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
+ /// ```
242
251
const VTABLE : FileOperationsVtable ;
243
252
253
+ /// Creates a new instance of this file. Corresponds to the `open` function
254
+ /// pointer in `struct file_operations`.
244
255
fn open ( ) -> KernelResult < Self > ;
256
+
257
+ /// Reads data from this file to userspace. Corresponds to the `read`
258
+ /// function pointer in `struct file_operations`.
245
259
fn read ( & self , _buf : & mut UserSlicePtrWriter , _offset : u64 ) -> KernelResult < ( ) > {
246
260
Err ( Error :: EINVAL )
247
261
}
262
+
263
+ /// Changes the position of the file. Corresponds to the `llseek` function
264
+ /// pointer in `struct file_operations`.
248
265
fn seek ( & self , _file : & File , _offset : SeekFrom ) -> KernelResult < u64 > {
249
266
Err ( Error :: ESPIPE )
250
267
}
You can’t perform that action at this time.
0 commit comments