Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
282 changes: 19 additions & 263 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@ homepage = "https://github.com/arceos-org/arceos"
repository = "https://github.com/arceos-org/starry-next"

[workspace.dependencies]
axfeat = { git = "https://github.com/oscomp/arceos.git" }
arceos_posix_api = { git = "https://github.com/oscomp/arceos.git", features = [
"uspace",
"smp",
"irq",
axfeat = { git = "https://github.com/oscomp/arceos.git", features = [
"fs",
"irq",
"multitask",
"net",
"pipe",
"select",
"epoll",
"smp",
] }

axconfig = { git = "https://github.com/oscomp/arceos.git" }
axfs = { git = "https://github.com/oscomp/arceos.git" }
axhal = { git = "https://github.com/oscomp/arceos.git", features = ["uspace"] }
axlog = { git = "https://github.com/oscomp/arceos.git" }
axmm = { git = "https://github.com/oscomp/arceos.git" }
axnet = { git = "https://github.com/oscomp/arceos.git" }
axns = { git = "https://github.com/oscomp/arceos.git", features = [
"thread-local",
] }
axruntime = { git = "https://github.com/oscomp/arceos.git" }
axsync = { git = "https://github.com/oscomp/arceos.git" }
axtask = { git = "https://github.com/oscomp/arceos.git" }

Expand All @@ -43,6 +40,7 @@ axsignal = { git = "https://github.com/Starry-OS/axsignal.git", rev = "b5b6089"

axerrno = "0.1"
bitflags = "2.6"
cfg-if = "1.0"
linkme = "0.3"
linux-raw-sys = { version = "0.9.3", default-features = false, features = [
"no_std",
Expand All @@ -52,6 +50,7 @@ linux-raw-sys = { version = "0.9.3", default-features = false, features = [
"system",
] }
memory_addr = "0.3"
spin = "0.9"

starry-core = { path = "./core" }
starry-api = { path = "./api" }
Expand All @@ -73,9 +72,9 @@ axfeat.workspace = true
axfs.workspace = true
axhal.workspace = true
axlog.workspace = true
axruntime.workspace = true
axsync.workspace = true
axtask.workspace = true
arceos_posix_api.workspace = true

axprocess.workspace = true
axsignal.workspace = true
Expand Down
13 changes: 10 additions & 3 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
axfeat.workspace = true

axconfig.workspace = true
axfs.workspace = true
axhal.workspace = true
axlog.workspace = true
axmm.workspace = true
axnet.workspace = true
axns.workspace = true
axsync.workspace = true
axtask.workspace = true
arceos_posix_api.workspace = true

axprocess.workspace = true
axsignal.workspace = true

axerrno.workspace = true
bitflags.workspace = true
cfg-if.workspace = true
linkme.workspace = true
linux-raw-sys.workspace = true
memory_addr.workspace = true
spin.workspace = true

starry-core.workspace = true

macro_rules_attribute = "0.2"
axio = "0.1.1"
ctor_bare = "0.2.1"
flatten_objects = "0.2.3"
num_enum = { version = "0.7", default-features = false }
static_assertions = "1.1"

[target.'cfg(target_arch = "x86_64")'.dependencies]
x86 = "0.52"
145 changes: 145 additions & 0 deletions api/src/file/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
use core::{any::Any, ffi::c_int};

use alloc::{string::String, sync::Arc};
use axerrno::{LinuxError, LinuxResult};
use axfs::fops::DirEntry;
use axio::PollState;
use axsync::{Mutex, MutexGuard};
use linux_raw_sys::general::S_IFDIR;

use super::{FileLike, Kstat, get_file_like};

/// File wrapper for `axfs::fops::File`.
pub struct File {
inner: Mutex<axfs::fops::File>,
path: String,
}

impl File {
pub fn new(inner: axfs::fops::File, path: String) -> Self {
Self {
inner: Mutex::new(inner),
path,
}
}

/// Get the path of the file.
pub fn path(&self) -> &str {
&self.path
}

/// Get the inner node of the file.
pub fn inner(&self) -> MutexGuard<axfs::fops::File> {
self.inner.lock()
}
}

impl FileLike for File {
fn read(&self, buf: &mut [u8]) -> LinuxResult<usize> {
Ok(self.inner().read(buf)?)
}

fn write(&self, buf: &[u8]) -> LinuxResult<usize> {
Ok(self.inner().write(buf)?)
}

fn stat(&self) -> LinuxResult<Kstat> {
let metadata = self.inner().get_attr()?;
let ty = metadata.file_type() as u8;
let perm = metadata.perm().bits() as u32;

Ok(Kstat {
mode: ((ty as u32) << 12) | perm,
size: metadata.size(),
blocks: metadata.blocks(),
blksize: 512,
..Default::default()
})
}

fn into_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
self
}

fn poll(&self) -> LinuxResult<PollState> {
Ok(PollState {
readable: true,
writable: true,
})
}

fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}
}

/// Directory wrapper for `axfs::fops::Directory`.
pub struct Directory {
inner: Mutex<axfs::fops::Directory>,
path: String,
last_dirent: Mutex<Option<DirEntry>>,
}

impl Directory {
pub fn new(inner: axfs::fops::Directory, path: String) -> Self {
Self {
inner: Mutex::new(inner),
path,
last_dirent: Mutex::new(None),
}
}

/// Get the path of the directory.
pub fn path(&self) -> &str {
&self.path
}

/// Get the inner node of the directory.
pub fn inner(&self) -> MutexGuard<axfs::fops::Directory> {
self.inner.lock()
}

/// Get the last directory entry.
pub fn last_dirent(&self) -> MutexGuard<Option<DirEntry>> {
self.last_dirent.lock()
}
}

impl FileLike for Directory {
fn read(&self, _buf: &mut [u8]) -> LinuxResult<usize> {
Err(LinuxError::EBADF)
}

fn write(&self, _buf: &[u8]) -> LinuxResult<usize> {
Err(LinuxError::EBADF)
}

fn stat(&self) -> LinuxResult<Kstat> {
Ok(Kstat {
mode: S_IFDIR | 0o755u32, // rwxr-xr-x
..Default::default()
})
}

fn into_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
self
}

fn poll(&self) -> LinuxResult<PollState> {
Ok(PollState {
readable: true,
writable: false,
})
}

fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn from_fd(fd: c_int) -> LinuxResult<Arc<Self>> {
get_file_like(fd)?
.into_any()
.downcast::<Self>()
.map_err(|_| LinuxError::ENOTDIR)
}
}
Loading
Loading