Message ID | 20231018122518.128049-4-wedsonaf@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Rust abstractions for VFS | expand |
On 10/18/23 14:25, Wedson Almeida Filho wrote:> +kernel::module_fs! { > + type: RoFs, > + name: "rust_rofs", > + author: "Rust for Linux Contributors", > + description: "Rust read-only file system sample", > + license: "GPL", > +} > + > +struct RoFs; > +impl fs::FileSystem for RoFs { > + const NAME: &'static CStr = c_str!("rust-fs"); > +} Why use two different names here? Alice
On Sat, 28 Oct 2023 at 13:17, Alice Ryhl <alice@ryhl.io> wrote: > > On 10/18/23 14:25, Wedson Almeida Filho wrote:> +kernel::module_fs! { > > + type: RoFs, > > + name: "rust_rofs", > > + author: "Rust for Linux Contributors", > > + description: "Rust read-only file system sample", > > + license: "GPL", > > +} > > + > > +struct RoFs; > > +impl fs::FileSystem for RoFs { > > + const NAME: &'static CStr = c_str!("rust-fs"); > > +} > > Why use two different names here? I actually wanted the same name, but the string in the module macros don't accept dashes (they need to be identifiers). I discussed this with Miguel a couple of years ago but we decided to wait and see before doing anything. Since then I noticed that Rust automatically converts dashes to underscores in crate names so that they can be used as identifiers in the language. So I guess there's a precedent if we decide to do something similar. For now I'll change rust-fs to rust_rofs as the fs name.
diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index 59f44a8b6958..2f26c5c52813 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -41,6 +41,16 @@ config SAMPLE_RUST_PRINT If unsure, say N. +config SAMPLE_RUST_ROFS + tristate "Read-only file system" + help + This option builds the Rust read-only file system sample. + + To compile this as a module, choose M here: + the module will be called rust_rofs. + + If unsure, say N. + config SAMPLE_RUST_HOSTPROGS bool "Host programs" help diff --git a/samples/rust/Makefile b/samples/rust/Makefile index 791fc18180e9..df1e4341ae95 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -3,5 +3,6 @@ obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o obj-$(CONFIG_SAMPLE_RUST_INPLACE) += rust_inplace.o obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o +obj-$(CONFIG_SAMPLE_RUST_ROFS) += rust_rofs.o subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs diff --git a/samples/rust/rust_rofs.rs b/samples/rust/rust_rofs.rs new file mode 100644 index 000000000000..1c00b1da8b94 --- /dev/null +++ b/samples/rust/rust_rofs.rs @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust read-only file system sample. + +use kernel::prelude::*; +use kernel::{c_str, fs}; + +kernel::module_fs! { + type: RoFs, + name: "rust_rofs", + author: "Rust for Linux Contributors", + description: "Rust read-only file system sample", + license: "GPL", +} + +struct RoFs; +impl fs::FileSystem for RoFs { + const NAME: &'static CStr = c_str!("rust-fs"); +}