summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/kernel/src/chrdev.rs4
-rw-r--r--rust/kernel/src/filesystem.rs84
-rw-r--r--rust/kernel/src/lib.rs3
-rw-r--r--rust/kernel/src/sysctl.rs4
-rw-r--r--rust/kernel/src/types.rs14
5 files changed, 12 insertions, 97 deletions
diff --git a/rust/kernel/src/chrdev.rs b/rust/kernel/src/chrdev.rs
index 4606a7bd5a73..d32b9a0d584a 100644
--- a/rust/kernel/src/chrdev.rs
+++ b/rust/kernel/src/chrdev.rs
@@ -14,7 +14,7 @@ use crate::error::{Error, KernelResult};
use crate::file_operations;
use crate::types::CStr;
-pub fn builder(name: &'static CStr, minors: Range<u16>) -> KernelResult<Builder> {
+pub fn builder(name: CStr<'static>, minors: Range<u16>) -> KernelResult<Builder> {
Ok(Builder {
name,
minors,
@@ -23,7 +23,7 @@ pub fn builder(name: &'static CStr, minors: Range<u16>) -> KernelResult<Builder>
}
pub struct Builder {
- name: &'static CStr,
+ name: CStr<'static>,
minors: Range<u16>,
file_ops: Vec<&'static bindings::file_operations>,
}
diff --git a/rust/kernel/src/filesystem.rs b/rust/kernel/src/filesystem.rs
deleted file mode 100644
index a5b7774292f1..000000000000
--- a/rust/kernel/src/filesystem.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-// TODO: `filesystem` is really incomplete -- deletion to be considered
-
-use alloc::boxed::Box;
-use core::default::Default;
-use core::marker;
-
-use crate::bindings;
-use crate::c_types;
-use crate::error;
-use crate::types::CStr;
-
-pub struct Registration<T: FileSystem> {
- _phantom: marker::PhantomData<T>,
- ptr: Box<bindings::file_system_type>,
-}
-
-// This is safe because Registration doesn't actually expose any methods.
-unsafe impl<T> Sync for Registration<T> where T: FileSystem {}
-
-impl<T: FileSystem> Drop for Registration<T> {
- fn drop(&mut self) {
- unsafe { bindings::unregister_filesystem(&mut *self.ptr) };
- }
-}
-
-pub trait FileSystem: Sync {
- const NAME: &'static CStr;
- const FLAGS: FileSystemFlags;
-}
-
-bitflags::bitflags! {
- pub struct FileSystemFlags: c_types::c_int {
- const REQUIRES_DEV = bindings::FS_REQUIRES_DEV as c_types::c_int;
- const BINARY_MOUNTDATA = bindings::FS_BINARY_MOUNTDATA as c_types::c_int;
- const HAS_SUBTYPE = bindings::FS_HAS_SUBTYPE as c_types::c_int;
- const USERNS_MOUNT = bindings::FS_USERNS_MOUNT as c_types::c_int;
- const RENAME_DOES_D_MOVE = bindings::FS_RENAME_DOES_D_MOVE as c_types::c_int;
- }
-}
-
-extern "C" fn fill_super_callback<T: FileSystem>(
- _sb: *mut bindings::super_block,
- _data: *mut c_types::c_void,
- _silent: c_types::c_int,
-) -> c_types::c_int {
- // T::fill_super(...)
- // This should actually create an object that gets dropped by
- // file_system_registration::kill_sb. You can point to it with
- // sb->s_fs_info.
- unimplemented!();
-}
-
-extern "C" fn mount_callback<T: FileSystem>(
- fs_type: *mut bindings::file_system_type,
- flags: c_types::c_int,
- _dev_name: *const c_types::c_char,
- data: *mut c_types::c_void,
-) -> *mut bindings::dentry {
- unsafe { bindings::mount_nodev(fs_type, flags, data, Some(fill_super_callback::<T>)) }
-}
-
-pub fn register<T: FileSystem>() -> error::KernelResult<Registration<T>> {
- let mut fs_registration = Registration {
- ptr: Box::new(bindings::file_system_type {
- name: T::NAME.as_ptr() as *const i8,
- // TODO: proper `THIS_MODULE` handling
- owner: core::ptr::null_mut(),
- fs_flags: T::FLAGS.bits(),
- mount: Some(mount_callback::<T>),
- kill_sb: Some(bindings::kill_litter_super),
-
- ..Default::default()
- }),
- _phantom: marker::PhantomData,
- };
- let result = unsafe { bindings::register_filesystem(&mut *fs_registration.ptr) };
- if result != 0 {
- return Err(error::Error::from_kernel_errno(result));
- }
-
- Ok(fs_registration)
-}
diff --git a/rust/kernel/src/lib.rs b/rust/kernel/src/lib.rs
index d8d40ff06137..7880928de74d 100644
--- a/rust/kernel/src/lib.rs
+++ b/rust/kernel/src/lib.rs
@@ -3,7 +3,7 @@
//! The `kernel` crate
#![no_std]
-#![feature(allocator_api, alloc_error_handler, const_raw_ptr_deref)]
+#![feature(allocator_api, alloc_error_handler)]
extern crate alloc;
@@ -15,7 +15,6 @@ pub mod c_types;
pub mod chrdev;
mod error;
pub mod file_operations;
-pub mod filesystem;
pub mod prelude;
pub mod printk;
pub mod random;
diff --git a/rust/kernel/src/sysctl.rs b/rust/kernel/src/sysctl.rs
index 654b7122ba3b..b94cdbc939cc 100644
--- a/rust/kernel/src/sysctl.rs
+++ b/rust/kernel/src/sysctl.rs
@@ -120,8 +120,8 @@ unsafe extern "C" fn proc_handler<T: SysctlStorage>(
impl<T: SysctlStorage> Sysctl<T> {
pub fn register(
- path: &'static types::CStr,
- name: &'static types::CStr,
+ path: types::CStr<'static>,
+ name: types::CStr<'static>,
storage: T,
mode: types::Mode,
) -> error::KernelResult<Sysctl<T>> {
diff --git a/rust/kernel/src/types.rs b/rust/kernel/src/types.rs
index ea5f8d7c2ebb..e9b4d13d4f8c 100644
--- a/rust/kernel/src/types.rs
+++ b/rust/kernel/src/types.rs
@@ -19,31 +19,31 @@ impl Mode {
/// A string that is guaranteed to have exactly one NUL byte, which is at the
/// end. Used for interoperability with kernel APIs that take C strings.
#[repr(transparent)]
-pub struct CStr(str);
+pub struct CStr<'a>(&'a str);
-impl CStr {
+impl CStr<'_> {
/// Creates a new CStr from a str without performing any additional checks.
/// # Safety
///
/// `data` _must_ end with a NUL byte, and should only have only a single
/// NUL byte, or the string will be truncated.
- pub const unsafe fn new_unchecked(data: &str) -> &CStr {
- &*(data as *const str as *const CStr)
+ pub const unsafe fn new_unchecked(data: &str) -> CStr {
+ CStr(data)
}
}
-impl Deref for CStr {
+impl Deref for CStr<'_> {
type Target = str;
fn deref(&self) -> &str {
- &self.0
+ self.0
}
}
/// Creates a new `CStr` from a string literal. The string literal should not contain any NUL
/// bytes. Example usage:
/// ```
-/// const MY_CSTR: &CStr = cstr!("My awesome CStr!");
+/// const MY_CSTR: CStr<'static> = cstr!("My awesome CStr!");
/// ```
#[macro_export]
macro_rules! cstr {