mirror of
https://github.com/rcore-os/rCore.git
synced 2025-01-19 01:07:05 +04:00
shm
This commit is contained in:
parent
6253d80e1d
commit
5c7b637c97
38
kernel/Cargo.lock
generated
38
kernel/Cargo.lock
generated
@ -358,11 +358,11 @@ dependencies = [
|
||||
"raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rboot 0.1.2",
|
||||
"rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"rcore-memory 0.1.0",
|
||||
"rcore-thread 0.1.0 (git+https://github.com/function2-llx/rcore-thread?rev=8c1022d)",
|
||||
"riscv 0.5.0 (git+https://github.com/rcore-os/riscv)",
|
||||
@ -388,7 +388,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rcore-fs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=84a01ef#84a01ef24a4bbcabdeca271335b8eb57f75912c4"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
dependencies = [
|
||||
"filetime 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -398,42 +398,42 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rcore-fs-devfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=84a01ef#84a01ef24a4bbcabdeca271335b8eb57f75912c4"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
dependencies = [
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rcore-fs-mountfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=84a01ef#84a01ef24a4bbcabdeca271335b8eb57f75912c4"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
dependencies = [
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rcore-fs-ramfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=84a01ef#84a01ef24a4bbcabdeca271335b8eb57f75912c4"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
dependencies = [
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rcore-fs-sfs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=84a01ef#84a01ef24a4bbcabdeca271335b8eb57f75912c4"
|
||||
source = "git+https://github.com/function2-llx/rcore-fs?rev=d386ad7#d386ad7e304a912d943a218b4d5b777fe13f2ade"
|
||||
dependencies = [
|
||||
"bitvec 0.17.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)",
|
||||
"rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -743,11 +743,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d"
|
||||
"checksum raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf"
|
||||
"checksum rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)" = "<none>"
|
||||
"checksum rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)" = "<none>"
|
||||
"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)" = "<none>"
|
||||
"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)" = "<none>"
|
||||
"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)" = "<none>"
|
||||
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=84a01ef)" = "<none>"
|
||||
"checksum rcore-fs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/function2-llx/rcore-fs?rev=d386ad7)" = "<none>"
|
||||
"checksum rcore-thread 0.1.0 (git+https://github.com/function2-llx/rcore-thread?rev=8c1022d)" = "<none>"
|
||||
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
||||
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"
|
||||
|
@ -66,11 +66,11 @@ bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" }
|
||||
rcore-console = { git = "https://github.com/rcore-os/rcore-console", rev = "b7bacf9", default-features = false }
|
||||
rcore-memory = { path = "../crate/memory" }
|
||||
rcore-thread = { git = "https://github.com/function2-llx/rcore-thread", rev = "8c1022d" }
|
||||
rcore-fs = { git = "https://github.com/function2-llx/rcore-fs", rev = "84a01ef" }
|
||||
rcore-fs-sfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "84a01ef" }
|
||||
rcore-fs-ramfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "84a01ef" }
|
||||
rcore-fs-mountfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "84a01ef" }
|
||||
rcore-fs-devfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "84a01ef" }
|
||||
rcore-fs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-sfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-ramfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-mountfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
rcore-fs-devfs = { git = "https://github.com/function2-llx/rcore-fs", rev = "d386ad7" }
|
||||
compression = { version = "0.1.4", default-features = false, features = ["gzip"] }
|
||||
|
||||
|
||||
|
@ -4,8 +4,10 @@ mod fbdev;
|
||||
mod random;
|
||||
mod stdio;
|
||||
mod tty;
|
||||
mod shm;
|
||||
|
||||
pub use fbdev::*;
|
||||
pub use random::*;
|
||||
pub use stdio::*;
|
||||
pub use tty::*;
|
||||
pub use shm::*;
|
||||
|
56
kernel/src/fs/devfs/shm.rs
Normal file
56
kernel/src/fs/devfs/shm.rs
Normal file
@ -0,0 +1,56 @@
|
||||
use core::any::Any;
|
||||
use rcore_fs::vfs::*;
|
||||
|
||||
pub use super::{STDIN, STDOUT};
|
||||
use rcore_fs::vfs::FsError::NotSupported;
|
||||
|
||||
// try to create directory under /dev
|
||||
// do not have enough time to come up with a better way.
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ShmINode;
|
||||
|
||||
impl INode for ShmINode {
|
||||
/// Read bytes at `offset` into `buf`, return the number of bytes read.
|
||||
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
Err(NotSupported)
|
||||
}
|
||||
|
||||
/// Write bytes at `offset` from `buf`, return the number of bytes written.
|
||||
fn write_at(&self, offset: usize, buf: &[u8]) -> Result<usize> {
|
||||
Err(NotSupported)
|
||||
}
|
||||
|
||||
/// Poll the events, return a bitmap of events.
|
||||
fn poll(&self) -> Result<PollStatus> {
|
||||
Ok(PollStatus {
|
||||
read: false,
|
||||
write: false,
|
||||
error: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get metadata of the INode
|
||||
fn metadata(&self) -> Result<Metadata> {
|
||||
Ok(Metadata {
|
||||
dev: 1,
|
||||
inode: 2,
|
||||
size: 0,
|
||||
blk_size: 0,
|
||||
blocks: 0,
|
||||
atime: Timespec { sec: 0, nsec: 0 },
|
||||
mtime: Timespec { sec: 0, nsec: 0 },
|
||||
ctime: Timespec { sec: 0, nsec: 0 },
|
||||
type_: FileType::Dir,
|
||||
mode: 0o666,
|
||||
nlinks: 1,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdev: make_rdev(0, 40),
|
||||
})
|
||||
}
|
||||
|
||||
fn as_any_ref(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ impl INode for TtyINode {
|
||||
fn metadata(&self) -> Result<Metadata> {
|
||||
Ok(Metadata {
|
||||
dev: 1,
|
||||
inode: 1,
|
||||
inode: 13,
|
||||
size: 0,
|
||||
blk_size: 0,
|
||||
blocks: 0,
|
||||
|
@ -7,11 +7,11 @@ use rcore_fs_devfs::{
|
||||
};
|
||||
use rcore_fs_mountfs::MountFS;
|
||||
use rcore_fs_ramfs::RamFS;
|
||||
use rcore_fs_sfs::SimpleFileSystem;
|
||||
use rcore_fs_sfs::{SimpleFileSystem, INodeImpl};
|
||||
|
||||
use self::devfs::{Fbdev, RandomINode};
|
||||
|
||||
pub use self::devfs::{TtyINode, STDIN, STDOUT};
|
||||
pub use self::devfs::{TtyINode, STDIN, STDOUT, ShmINode};
|
||||
pub use self::file::*;
|
||||
pub use self::file_like::*;
|
||||
pub use self::pipe::Pipe;
|
||||
@ -89,12 +89,18 @@ lazy_static! {
|
||||
devfs.add("urandom", Arc::new(RandomINode::new(true))).expect("failed to mknod /dev/urandom");
|
||||
devfs.add("tty", Arc::new(TtyINode::default())).expect("failed to mknod /dev/tty");
|
||||
devfs.add("fb0", Arc::new(Fbdev::default())).expect("failed to mknod /dev/fb0");
|
||||
devfs.add("shm", Arc::new(ShmINode::default())).expect("failed to mkdir shm");
|
||||
|
||||
// mount DevFS at /dev
|
||||
let dev = root.find(true, "dev").unwrap_or_else(|_| {
|
||||
root.create("dev", FileType::Dir, 0o666).expect("failed to mkdir /dev")
|
||||
});
|
||||
dev.mount(devfs).expect("failed to mount DevFS");
|
||||
let devfs = dev.mount(devfs).expect("failed to mount DevFS");
|
||||
|
||||
let shm = devfs.root_inode().find(true, "shm").expect("cannot find shm");
|
||||
// mount RamFS at /dev/shm
|
||||
let shmfs = RamFS::new();
|
||||
shm.mount(shmfs).expect("failed to mount /dev/shm");
|
||||
|
||||
// mount RamFS at /tmp
|
||||
let ramfs = RamFS::new();
|
||||
@ -115,6 +121,7 @@ pub trait INodeExt {
|
||||
|
||||
impl INodeExt for dyn INode {
|
||||
fn read_as_vec(&self) -> Result<Vec<u8>> {
|
||||
|
||||
let size = self.metadata()?.size;
|
||||
let mut buf = Vec::with_capacity(size);
|
||||
unsafe {
|
||||
|
@ -11,8 +11,10 @@ use alloc::boxed::Box;
|
||||
use core::cmp::min;
|
||||
use rcore_fs::vfs::FsError::Again;
|
||||
use rcore_thread::std_thread::{park, yield_now};
|
||||
use alloc::collections::BTreeSet;
|
||||
use crate::syscall::SysError::EAGAIN;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum PipeEnd {
|
||||
Read,
|
||||
Write,
|
||||
@ -91,14 +93,18 @@ impl INode for Pipe {
|
||||
if let PipeEnd::Read = self.direction {
|
||||
// TODO: release on process lock? Or maybe remove the condvar
|
||||
let mut data = self.data.lock();
|
||||
while data.buf.len() == 0 && data.end_cnt == 2 {
|
||||
data = data.new_data.clone().wait(data);
|
||||
// while data.buf.len() == 0 && data.end_cnt == 2 {
|
||||
// data = data.new_data.clone().wait(data);
|
||||
// }
|
||||
if data.buf.len() == 0 && data.end_cnt == 2 {
|
||||
Err(Again)
|
||||
} else {
|
||||
let len = min(buf.len(), data.buf.len());
|
||||
for i in 0..len {
|
||||
buf[i] = data.buf.pop_front().unwrap();
|
||||
}
|
||||
Ok(len)
|
||||
}
|
||||
let len = min(buf.len(), data.buf.len());
|
||||
for i in 0..len {
|
||||
buf[i] = data.buf.pop_front().unwrap();
|
||||
}
|
||||
Ok(len)
|
||||
} else {
|
||||
Ok(0)
|
||||
}
|
||||
|
@ -34,9 +34,7 @@ impl Syscall<'_> {
|
||||
let slice = unsafe { self.vm().check_write_array(base, len)? };
|
||||
let file_like = proc.get_file_like(fd)?;
|
||||
let len = file_like.read(slice)?;
|
||||
if len == 1 && !proc.pid.is_init() {
|
||||
println!("write content: {}", slice[0] as char);
|
||||
}
|
||||
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
@ -49,9 +47,9 @@ impl Syscall<'_> {
|
||||
let slice = unsafe { self.vm().check_read_array(base, len)? };
|
||||
let file_like = proc.get_file_like(fd)?;
|
||||
let len = file_like.write(slice)?;
|
||||
if len == 1 && !proc.pid.is_init() {
|
||||
println!("write content: {}", slice[0] as char);
|
||||
}
|
||||
// if len == 1 && !proc.pid.is_init() {
|
||||
// println!("write content: {}", slice[0] as char);
|
||||
// }
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
|
2
user
2
user
@ -1 +1 @@
|
||||
Subproject commit 708b97007204fa47ee8ac7c5a771436558e0554e
|
||||
Subproject commit c17bb8c9ddd73b52fc4a260f5b5abd77f9427c98
|
Loading…
Reference in New Issue
Block a user