This repository was archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathlib.rs
More file actions
47 lines (39 loc) · 1.32 KB
/
lib.rs
File metadata and controls
47 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![no_std]
#![feature(const_str_as_bytes)]
use linux_kernel_module;
struct CycleFile;
impl linux_kernel_module::chrdev::FileOperations for CycleFile {
const VTABLE: linux_kernel_module::chrdev::FileOperationsVtable =
linux_kernel_module::chrdev::FileOperationsVtable::new::<Self>();
fn open() -> linux_kernel_module::KernelResult<Self> {
return Ok(CycleFile);
}
fn read(
&self,
buf: &mut linux_kernel_module::user_ptr::UserSlicePtrWriter,
) -> linux_kernel_module::KernelResult<()> {
for c in b"123456789".iter().cycle().take(buf.len()) {
buf.write(&[*c])?;
}
return Ok(());
}
}
struct ChrdevTestModule {
_chrdev_registration: linux_kernel_module::chrdev::Registration,
}
impl linux_kernel_module::KernelModule for ChrdevTestModule {
fn init() -> linux_kernel_module::KernelResult<Self> {
let chrdev_registration = linux_kernel_module::chrdev::builder("chrdev-tests\x00")?
.register_device::<CycleFile>()
.build()?;
Ok(ChrdevTestModule {
_chrdev_registration: chrdev_registration,
})
}
}
linux_kernel_module::kernel_module!(
ChrdevTestModule,
author: "Alex Gaynor and Geoffrey Thomas",
description: "A module for testing character devices",
license: "GPL"
);