Skip to content

Commit 655c1f1

Browse files
author
Jiajie Chen
committed
Move impl_inode default impl to rcore-fs crate
1 parent 9b4e0e8 commit 655c1f1

File tree

6 files changed

+64
-120
lines changed

6 files changed

+64
-120
lines changed

kernel/Cargo.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kernel/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ smoltcp = { git = "https://github.com/rcore-os/smoltcp", default-features = fals
6565
bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" }
6666
rcore-memory = { path = "../crate/memory" }
6767
rcore-thread = { git = "https://github.com/rcore-os/rcore-thread" }
68-
rcore-fs = { git = "https://github.com/rcore-os/rcore-fs", rev = "b7f7d9e" }
69-
rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "b7f7d9e" }
70-
rcore-fs-ramfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "b7f7d9e" }
71-
rcore-fs-mountfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "b7f7d9e" }
72-
rcore-fs-devfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "b7f7d9e" }
68+
rcore-fs = { git = "https://github.com/rcore-os/rcore-fs", rev = "33f86c47" }
69+
rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "33f86c47" }
70+
rcore-fs-ramfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "33f86c47" }
71+
rcore-fs-mountfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "33f86c47" }
72+
rcore-fs-devfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "33f86c47" }
7373
compression = { version = "0.1.4", default-features = false, features = ["gzip"] }
7474

7575

kernel/src/fs/pipe.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,6 @@ impl Pipe {
6666
}
6767
}
6868

69-
// TODO: better way to provide default impl?
70-
macro_rules! impl_inode {
71-
() => {
72-
fn metadata(&self) -> Result<Metadata> { Err(FsError::NotSupported) }
73-
fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) }
74-
fn sync_all(&self) -> Result<()> { Ok(()) }
75-
fn sync_data(&self) -> Result<()> { Ok(()) }
76-
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) }
77-
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
78-
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
79-
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
80-
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
81-
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
82-
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
83-
fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
84-
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
85-
fn as_any_ref(&self) -> &dyn Any { self }
86-
};
87-
}
88-
8969
impl INode for Pipe {
9070
fn read_at(&self, _offset: usize, buf: &mut [u8]) -> Result<usize> {
9171
if let PipeEnd::Read = self.direction {
@@ -123,5 +103,6 @@ impl INode for Pipe {
123103
error: false,
124104
})
125105
}
126-
impl_inode!();
106+
107+
fn as_any_ref(&self) -> &dyn Any { self }
127108
}

kernel/src/fs/pseudo.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,6 @@ impl Pseudo {
1919
}
2020
}
2121

22-
// TODO: better way to provide default impl?
23-
macro_rules! impl_inode {
24-
() => {
25-
fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) }
26-
fn sync_all(&self) -> Result<()> { Ok(()) }
27-
fn sync_data(&self) -> Result<()> { Ok(()) }
28-
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) }
29-
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
30-
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
31-
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
32-
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
33-
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
34-
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
35-
fn io_control(&self, cmd: u32, data: usize) -> Result<()> { Err(FsError::NotSupported) }
36-
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
37-
fn as_any_ref(&self) -> &dyn Any { self }
38-
};
39-
}
40-
4122
impl INode for Pseudo {
4223
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
4324
if offset >= self.content.len() {
@@ -75,5 +56,5 @@ impl INode for Pseudo {
7556
rdev: 0,
7657
})
7758
}
78-
impl_inode!();
59+
fn as_any_ref(&self) -> &dyn Any { self }
7960
}

kernel/src/fs/stdio.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,6 @@ lazy_static! {
5353
pub static ref STDOUT: Arc<Stdout> = Arc::new(Stdout::default());
5454
}
5555

56-
// TODO: better way to provide default impl?
57-
macro_rules! impl_inode {
58-
() => {
59-
fn metadata(&self) -> Result<Metadata> { Err(FsError::NotSupported) }
60-
fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) }
61-
fn sync_all(&self) -> Result<()> { Ok(()) }
62-
fn sync_data(&self) -> Result<()> { Ok(()) }
63-
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) }
64-
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
65-
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
66-
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
67-
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
68-
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
69-
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
70-
fn io_control(&self, cmd: u32, data: usize) -> Result<()> {
71-
match cmd as usize {
72-
TCGETS | TIOCGWINSZ | TIOCSPGRP => {
73-
// pretend to be tty
74-
Ok(())
75-
},
76-
TIOCGPGRP => {
77-
// pretend to be have a tty process group
78-
// TODO: verify pointer
79-
unsafe {
80-
*(data as *mut u32) = 0
81-
};
82-
Ok(())
83-
}
84-
_ => Err(FsError::NotSupported)
85-
}
86-
}
87-
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
88-
fn as_any_ref(&self) -> &dyn Any { self }
89-
};
90-
}
9156

9257
impl INode for Stdin {
9358
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
@@ -108,7 +73,24 @@ impl INode for Stdin {
10873
error: false,
10974
})
11075
}
111-
impl_inode!();
76+
fn io_control(&self, cmd: u32, data: usize) -> Result<()> {
77+
match cmd as usize {
78+
TCGETS | TIOCGWINSZ | TIOCSPGRP => {
79+
// pretend to be tty
80+
Ok(())
81+
},
82+
TIOCGPGRP => {
83+
// pretend to be have a tty process group
84+
// TODO: verify pointer
85+
unsafe {
86+
*(data as *mut u32) = 0
87+
};
88+
Ok(())
89+
}
90+
_ => Err(FsError::NotSupported)
91+
}
92+
}
93+
fn as_any_ref(&self) -> &dyn Any { self }
11294
}
11395

11496
impl INode for Stdout {
@@ -129,5 +111,22 @@ impl INode for Stdout {
129111
error: false,
130112
})
131113
}
132-
impl_inode!();
114+
fn io_control(&self, cmd: u32, data: usize) -> Result<()> {
115+
match cmd as usize {
116+
TCGETS | TIOCGWINSZ | TIOCSPGRP => {
117+
// pretend to be tty
118+
Ok(())
119+
},
120+
TIOCGPGRP => {
121+
// pretend to be have a tty process group
122+
// TODO: verify pointer
123+
unsafe {
124+
*(data as *mut u32) = 0
125+
};
126+
Ok(())
127+
}
128+
_ => Err(FsError::NotSupported)
129+
}
130+
}
131+
fn as_any_ref(&self) -> &dyn Any { self }
133132
}

kernel/src/fs/vga.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ use core::any::Any;
88
#[derive(Default)]
99
pub struct Vga;
1010

11-
macro_rules! impl_inode {
12-
() => {
13-
fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) }
14-
fn sync_all(&self) -> Result<()> { Ok(()) }
15-
fn sync_data(&self) -> Result<()> { Ok(()) }
16-
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) }
17-
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
18-
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
19-
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
20-
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
21-
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
22-
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
23-
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
24-
fn as_any_ref(&self) -> &dyn Any { self }
25-
};
26-
}
27-
2811
impl INode for Vga {
2912
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
3013
Err(FsError::NotSupported)
@@ -97,7 +80,7 @@ impl INode for Vga {
9780
//let fb_fix_info = unsafe{ &mut *(data as *mut fb_fix_screeninfo) };
9881
//Ok(())
9982
}
100-
impl_inode!();
83+
fn as_any_ref(&self) -> &dyn Any { self }
10184
}
10285

10386
const FBIOGET_FSCREENINFO: u32 = 0x4602;

0 commit comments

Comments
 (0)