macro_rules! module_fs {
    (type: $type:ty, $($f:tt)*) => { ... };
}
Expand description

Declares a kernel module that exposes a single file system.

The type argument must be a type which implements the Type trait. Also accepts various forms of kernel metadata.

Examples

use kernel::prelude::*;
use kernel::{c_str, fs};

module_fs! {
    type: MyFs,
    name: "my_fs_kernel_module",
    author: "Rust for Linux Contributors",
    description: "My very own file system kernel module!",
    license: "GPL",
}

struct MyFs;

#[vtable]
impl fs::Context<Self> for MyFs {
    type Data = ();
    fn try_new() -> Result {
        Ok(())
    }
}

impl fs::Type for MyFs {
    type Context = Self;
    const SUPER_TYPE: fs::Super = fs::Super::Independent;
    const NAME: &'static CStr = c_str!("example");
    const FLAGS: i32 = 0;

    fn fill_super(_data: (), sb: fs::NewSuperBlock<'_, Self>) -> Result<&fs::SuperBlock<Self>> {
        let sb = sb.init(
            (),
            &fs::SuperParams {
                magic: 0x6578616d,
                ..fs::SuperParams::DEFAULT
            },
        )?;
        let sb = sb.init_root()?;
        Ok(sb)
    }
}