Skip to content

Commit 7551eb5

Browse files
committed
2: module working
1 parent ee51d53 commit 7551eb5

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

samples/rust/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ menuconfig SAMPLES_RUST
1010

1111
if SAMPLES_RUST
1212

13+
config SAMPLE_RUST_VDEV
14+
tristate "Virtual Device"
15+
help
16+
This option builds the Rust virtual device module sample.
17+
18+
To compile this as a module, choose M here:
19+
the module will be called rust_vdev.
20+
21+
If unsure, say N.
22+
1323
config SAMPLE_RUST_MINIMAL
1424
tristate "Minimal"
1525
help

samples/rust/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ obj-$(CONFIG_SAMPLE_RUST_NETFILTER) += rust_netfilter.o
1515
obj-$(CONFIG_SAMPLE_RUST_ECHO_SERVER) += rust_echo_server.o
1616
obj-$(CONFIG_SAMPLE_RUST_FS) += rust_fs.o
1717
obj-$(CONFIG_SAMPLE_RUST_SELFTESTS) += rust_selftests.o
18+
obj-$(CONFIG_SAMPLE_RUST_VDEV) += rust_vdev.o
1819

1920
subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs

samples/rust/rust_vdev.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Virtual Device Module
2+
use kernel::prelude::*;
3+
4+
module! {
5+
type: VDev,
6+
name: b"vdev",
7+
license: b"GPL",
8+
}
9+
10+
struct VDev;
11+
12+
impl kernel::Module for VDev {
13+
fn init(_name: &'static CStr, _module: &'static ThisModule) -> Result<Self> {
14+
// Print a banner to make sure our moudle is working
15+
pr_info!("------------------------\n");
16+
pr_info!("starting virtual device!\n");
17+
pr_info!("------------------------\n");
18+
Ok(VDev)
19+
}
20+
}

0 commit comments

Comments
 (0)