Skip to content

Commit 2306156

Browse files
committed
copy fs, kill arceos_posix_api
1 parent bd61f86 commit 2306156

35 files changed

Lines changed: 4748 additions & 714 deletions

Cargo.lock

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

Cargo.toml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,35 @@ homepage = "https://github.com/arceos-org/arceos"
1414
repository = "https://github.com/arceos-org/starry-next"
1515

1616
[workspace.dependencies]
17-
axfeat = { git = "https://github.com/oscomp/arceos.git" }
18-
arceos_posix_api = { git = "https://github.com/oscomp/arceos.git", features = [
19-
"uspace",
20-
"smp",
21-
"irq",
17+
axfeat = { git = "https://github.com/oscomp/arceos.git", features = [
2218
"fs",
19+
"irq",
2320
"multitask",
2421
"net",
25-
"pipe",
26-
"select",
27-
"epoll",
22+
"smp",
2823
] }
24+
# arceos_posix_api = { git = "https://github.com/oscomp/arceos.git", features = [
25+
# "uspace",
26+
# "smp",
27+
# "irq",
28+
# "fs",
29+
# "multitask",
30+
# "net",
31+
# "pipe",
32+
# "select",
33+
# "epoll",
34+
# ] }
2935

3036
axconfig = { git = "https://github.com/oscomp/arceos.git" }
3137
axfs = { git = "https://github.com/oscomp/arceos.git" }
3238
axhal = { git = "https://github.com/oscomp/arceos.git", features = ["uspace"] }
3339
axlog = { git = "https://github.com/oscomp/arceos.git" }
3440
axmm = { git = "https://github.com/oscomp/arceos.git" }
41+
axnet = { git = "https://github.com/oscomp/arceos.git" }
3542
axns = { git = "https://github.com/oscomp/arceos.git", features = [
3643
"thread-local",
3744
] }
45+
axruntime = { git = "https://github.com/oscomp/arceos.git" }
3846
axsync = { git = "https://github.com/oscomp/arceos.git" }
3947
axtask = { git = "https://github.com/oscomp/arceos.git" }
4048

@@ -56,6 +64,9 @@ memory_addr = "0.3"
5664
starry-core = { path = "./core" }
5765
starry-api = { path = "./api" }
5866

67+
68+
spin = "0.9"
69+
5970
[package]
6071
name = "starry"
6172
version.workspace = true
@@ -73,9 +84,11 @@ axfeat.workspace = true
7384
axfs.workspace = true
7485
axhal.workspace = true
7586
axlog.workspace = true
87+
axruntime.workspace = true
7688
axsync.workspace = true
7789
axtask.workspace = true
78-
arceos_posix_api.workspace = true
90+
axconfig.workspace = true
91+
# arceos_posix_api.workspace = true
7992

8093
axprocess.workspace = true
8194
axsignal.workspace = true

api/Cargo.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ axhal.workspace = true
1313
axlog.workspace = true
1414
axsync.workspace = true
1515
axtask.workspace = true
16-
arceos_posix_api.workspace = true
16+
arceos_posix_api = { path = "../.arceos/api/arceos_posix_api", features = ["uspace", "smp", "irq", "fs", "multitask", "net", "pipe", "select", "epoll"] }
1717

1818
axprocess.workspace = true
1919
axsignal.workspace = true
@@ -30,5 +30,14 @@ macro_rules_attribute = "0.2"
3030
num_enum = { version = "0.7", default-features = false }
3131
static_assertions = "1.1"
3232

33+
axfs_vfs = { git = "https://github.com/Ressed/axfs_crates.git" }
34+
axio = "0.1.1"
35+
flatten_objects = "0.2.3"
36+
spin.workspace = true
37+
axmm.workspace = true
38+
axnet.workspace = true
39+
axns.workspace = true
40+
ctor_bare = "0.2.1"
41+
3342
[target.'cfg(target_arch = "x86_64")'.dependencies]
34-
x86 = "0.52"
43+
x86 = "0.52"

api/src/fd/fs.rs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
use core::{any::Any, ffi::c_int};
2+
3+
use alloc::{string::String, sync::Arc};
4+
use axerrno::{LinuxError, LinuxResult};
5+
use axio::PollState;
6+
use axsync::{Mutex, MutexGuard};
7+
use linux_raw_sys::general::S_IFDIR;
8+
9+
use super::{FileLike, Kstat, get_file_like};
10+
11+
/// File wrapper for `axfs::fops::File`.
12+
pub struct File {
13+
inner: Mutex<axfs::fops::File>,
14+
path: String,
15+
}
16+
17+
impl File {
18+
pub fn new(inner: axfs::fops::File, path: String) -> Self {
19+
Self {
20+
inner: Mutex::new(inner),
21+
path,
22+
}
23+
}
24+
25+
/// Get the path of the file.
26+
pub fn path(&self) -> &str {
27+
&self.path
28+
}
29+
30+
/// Get the inner node of the file.
31+
pub fn inner(&self) -> MutexGuard<axfs::fops::File> {
32+
self.inner.lock()
33+
}
34+
}
35+
36+
impl FileLike for File {
37+
fn read(&self, buf: &mut [u8]) -> LinuxResult<usize> {
38+
Ok(self.inner().read(buf)?)
39+
}
40+
41+
fn write(&self, buf: &[u8]) -> LinuxResult<usize> {
42+
Ok(self.inner().write(buf)?)
43+
}
44+
45+
fn stat(&self) -> LinuxResult<Kstat> {
46+
let metadata = self.inner().get_attr()?;
47+
let ty = metadata.file_type() as u8;
48+
let perm = metadata.perm().bits() as u32;
49+
50+
Ok(Kstat {
51+
mode: ((ty as u32) << 12) | perm,
52+
size: metadata.size(),
53+
blocks: metadata.blocks(),
54+
blksize: 512,
55+
..Default::default()
56+
})
57+
}
58+
59+
fn into_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
60+
self
61+
}
62+
63+
fn poll(&self) -> LinuxResult<PollState> {
64+
Ok(PollState {
65+
readable: true,
66+
writable: true,
67+
})
68+
}
69+
70+
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
71+
Ok(())
72+
}
73+
}
74+
75+
/// Directory wrapper for `axfs::fops::Directory`.
76+
pub struct Directory {
77+
inner: Mutex<axfs::fops::Directory>,
78+
path: String,
79+
}
80+
81+
impl Directory {
82+
pub fn new(inner: axfs::fops::Directory, path: String) -> Self {
83+
Self {
84+
inner: Mutex::new(inner),
85+
path,
86+
}
87+
}
88+
89+
/// Get the path of the directory.
90+
pub fn path(&self) -> &str {
91+
&self.path
92+
}
93+
94+
/// Get the inner node of the directory.
95+
pub fn inner(&self) -> MutexGuard<axfs::fops::Directory> {
96+
self.inner.lock()
97+
}
98+
}
99+
100+
impl FileLike for Directory {
101+
fn read(&self, _buf: &mut [u8]) -> LinuxResult<usize> {
102+
Err(LinuxError::EBADF)
103+
}
104+
105+
fn write(&self, _buf: &[u8]) -> LinuxResult<usize> {
106+
Err(LinuxError::EBADF)
107+
}
108+
109+
fn stat(&self) -> LinuxResult<Kstat> {
110+
Ok(Kstat {
111+
mode: S_IFDIR | 0o755u32, // rwxr-xr-x
112+
..Default::default()
113+
})
114+
}
115+
116+
fn into_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
117+
self
118+
}
119+
120+
fn poll(&self) -> LinuxResult<PollState> {
121+
Ok(PollState {
122+
readable: true,
123+
writable: false,
124+
})
125+
}
126+
127+
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
128+
Ok(())
129+
}
130+
131+
fn from_fd(fd: c_int) -> LinuxResult<Arc<Self>> {
132+
get_file_like(fd)?
133+
.into_any()
134+
.downcast::<Self>()
135+
.map_err(|_| LinuxError::ENOTDIR)
136+
}
137+
}

0 commit comments

Comments
 (0)