Skip to content

Commit 4da0b13

Browse files
committed
vfs: Make FileSystem::get_name return a &str
1 parent 8b54788 commit 4da0b13

6 files changed

Lines changed: 17 additions & 27 deletions

File tree

drivers/fs/ext2/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use zinnia::{
2828
pub struct Ext2Fs;
2929

3030
impl FileSystem for Ext2Fs {
31-
fn get_name(&self) -> &[u8] {
32-
b"ext2"
31+
fn get_name(&self) -> &'static str {
32+
"ext2"
3333
}
3434

3535
fn mount(&self, flags: MountFlags, arg: UserPtr<()>) -> EResult<Arc<Mount>> {

kernel/src/syscall/vfs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,9 @@ pub fn mount(
15381538
data_ptr: VirtAddr,
15391539
) -> EResult<usize> {
15401540
let fs_type = UserCStr::new(type_ptr)
1541-
.as_vec(PATH_MAX)
1541+
.as_cstring(PATH_MAX)
15421542
.ok_or(Errno::EFAULT)?;
1543+
let fs_type = fs_type.to_str().map_err(|_| Errno::EINVAL)?;
15431544
let dir = UserCStr::new(dir_ptr)
15441545
.as_vec(PATH_MAX)
15451546
.ok_or(Errno::EFAULT)?;

kernel/src/vfs/fs/devtmpfs.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ static DEV_MOUNT: Once<Arc<Mount>> = Once::new();
1212
struct DevTmpFs;
1313

1414
impl FileSystem for DevTmpFs {
15-
fn get_name(&self) -> &'static [u8] {
16-
b"devtmpfs"
15+
fn get_name(&self) -> &str {
16+
"devtmpfs"
1717
}
1818

1919
fn mount(&self, flags: MountFlags, _: UserPtr<()>) -> EResult<Arc<Mount>> {
@@ -31,12 +31,8 @@ pub fn DEVTMPFS_STAGE() {
3131
super::register(&DevTmpFs);
3232

3333
// Ask for a singleton-like tmpfs.
34-
let tmpfs = super::mount(
35-
b"tmpfs",
36-
MountFlags::empty(),
37-
UserPtr::new(VirtAddr::null()),
38-
)
39-
.expect("Unable to create devtmpfs from tmpfs");
34+
let tmpfs = super::mount("tmpfs", MountFlags::empty(), UserPtr::new(VirtAddr::null()))
35+
.expect("Unable to create devtmpfs from tmpfs");
4036

4137
unsafe { DEV_MOUNT.init(tmpfs) };
4238
}

kernel/src/vfs/fs/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bitflags::bitflags! {
4646

4747
pub trait FileSystem: Sync + Send {
4848
/// Returns an identifier which can be used to determine this file system.
49-
fn get_name(&self) -> &[u8];
49+
fn get_name(&self) -> &str;
5050

5151
/// Mounts an instance of this file system from a `source`.
5252
/// Returns a reference to the mount point with an instance of this file system.
@@ -65,17 +65,14 @@ pub trait SuperBlock: Sync + Send + Any {
6565
}
6666

6767
/// A map of all known and registered file systems.
68-
static FS_TABLE: SpinMutex<BTreeMap<&'static [u8], &'static dyn FileSystem>> =
68+
static FS_TABLE: SpinMutex<BTreeMap<&'static str, &'static dyn FileSystem>> =
6969
SpinMutex::new(BTreeMap::new());
7070

7171
/// Registers a new file system.
7272
pub fn register(fs: &'static dyn FileSystem) {
7373
let name = fs.get_name();
7474
FS_TABLE.lock().insert(name, fs);
75-
log!(
76-
"Registered new file system \"{}\"",
77-
String::from_utf8_lossy(name)
78-
);
75+
log!("Registered new file system \"{name}\"");
7976
}
8077

8178
static MOUNTED_SUPERS: SpinMutex<Vec<Arc<dyn SuperBlock>>> = SpinMutex::new(Vec::new());
@@ -92,7 +89,7 @@ pub fn sync_all() -> EResult<()> {
9289
}
9390

9491
/// Mounts a file system at path `source` on `target`.
95-
pub fn mount(fs_name: &[u8], flags: MountFlags, arg: UserPtr<()>) -> EResult<Arc<Mount>> {
92+
pub fn mount(fs_name: &str, flags: MountFlags, arg: UserPtr<()>) -> EResult<Arc<Mount>> {
9693
let fs = {
9794
let table = FS_TABLE.lock();
9895
*table.get(fs_name).ok_or(Errno::ENODEV)?

kernel/src/vfs/fs/tmpfs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use core::{
2727
struct TmpFs;
2828

2929
impl FileSystem for TmpFs {
30-
fn get_name(&self) -> &'static [u8] {
31-
b"tmpfs"
30+
fn get_name(&self) -> &str {
31+
"tmpfs"
3232
}
3333

3434
fn mount(&self, flags: MountFlags, _: UserPtr<()>) -> EResult<Arc<Mount>> {

kernel/src/vfs/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,8 @@ pub fn get_dir_entries(
292292
)]
293293
pub fn VFS_STAGE() {
294294
// Mount a tmpfs as root.
295-
let tmpfs = fs::mount(
296-
b"tmpfs",
297-
MountFlags::empty(),
298-
UserPtr::new(VirtAddr::null()),
299-
)
300-
.expect("Unable to mount the root tmpfs");
295+
let tmpfs = fs::mount("tmpfs", MountFlags::empty(), UserPtr::new(VirtAddr::null()))
296+
.expect("Unable to mount the root tmpfs");
301297

302298
let root_path = PathNode {
303299
entry: tmpfs.root.clone(),
@@ -314,7 +310,7 @@ pub fn VFS_STAGE() {
314310
pub fn VFS_DEV_MOUNT_STAGE() {
315311
// Mount the devtmpfs on `/dev`.
316312
let devtmpfs = fs::mount(
317-
b"devtmpfs",
313+
"devtmpfs",
318314
MountFlags::empty(),
319315
UserPtr::new(VirtAddr::null()),
320316
)

0 commit comments

Comments
 (0)