forked from Azure-stars/starry-next
-
Notifications
You must be signed in to change notification settings - Fork 36
refactor: remove arceos_posix_api #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0726ced
refactor: remove arceos_posix api
AsakuraMizu cdf1bca
cleanup syscalls
AsakuraMizu f5f23d3
feat: lseek
AsakuraMizu fc0c1c7
chore: drop syscall_instrument
AsakuraMizu 653751c
fix: writev
AsakuraMizu d092bfe
chore: time-related stuffs
AsakuraMizu b524edb
chore: changes according to review
AsakuraMizu 3d6e0fa
fix: openat path
AsakuraMizu 457c493
fix: getdents64
AsakuraMizu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.