Skip to content

Commit

Permalink
2: module working
Browse files Browse the repository at this point in the history
  • Loading branch information
jackos committed Jul 30, 2022
1 parent ee51d53 commit 7551eb5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions samples/rust/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ menuconfig SAMPLES_RUST

if SAMPLES_RUST

config SAMPLE_RUST_VDEV
tristate "Virtual Device"
help
This option builds the Rust virtual device module sample.

To compile this as a module, choose M here:
the module will be called rust_vdev.

If unsure, say N.

config SAMPLE_RUST_MINIMAL
tristate "Minimal"
help
Expand Down
1 change: 1 addition & 0 deletions samples/rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ obj-$(CONFIG_SAMPLE_RUST_NETFILTER) += rust_netfilter.o
obj-$(CONFIG_SAMPLE_RUST_ECHO_SERVER) += rust_echo_server.o
obj-$(CONFIG_SAMPLE_RUST_FS) += rust_fs.o
obj-$(CONFIG_SAMPLE_RUST_SELFTESTS) += rust_selftests.o
obj-$(CONFIG_SAMPLE_RUST_VDEV) += rust_vdev.o

subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs
20 changes: 20 additions & 0 deletions samples/rust/rust_vdev.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Virtual Device Module
use kernel::prelude::*;

module! {
type: VDev,
name: b"vdev",
license: b"GPL",
}

struct VDev;

impl kernel::Module for VDev {
fn init(_name: &'static CStr, _module: &'static ThisModule) -> Result<Self> {
// Print a banner to make sure our moudle is working
pr_info!("------------------------\n");
pr_info!("starting virtual device!\n");
pr_info!("------------------------\n");
Ok(VDev)
}
}

0 comments on commit 7551eb5

Please sign in to comment.