-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git subrepo clone --branch=main [email protected]:Starry-OS/axstd.git ul…
…ib/axstd subrepo: subdir: "ulib/axstd" merged: "0b0595b" upstream: origin: "[email protected]:Starry-OS/axstd.git" branch: "main" commit: "0b0595b" git-subrepo: version: "0.4.9" origin: "https://github.com/ingydotnet/git-subrepo" commit: "ea10886"
- Loading branch information
1 parent
6a1bde0
commit d672410
Showing
22 changed files
with
1,840 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,14 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb |
This file contains 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,12 @@ | ||
; DO NOT EDIT (unless you know what you are doing) | ||
; | ||
; This subdirectory is a git "subrepo", and this file is maintained by the | ||
; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme | ||
; | ||
[subrepo] | ||
remote = [email protected]:Starry-OS/axstd.git | ||
branch = main | ||
commit = 0b0595b3f24a68009a47d120e5991b89a6c9f2d3 | ||
parent = 6a1bde0f765aa3141594efc162f66973c814cbea | ||
method = merge | ||
cmdver = 0.4.9 |
This file contains 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,80 @@ | ||
[package] | ||
name = "axstd" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = [ | ||
"Yuekai Jia <[email protected]>", | ||
"yanjuguang <[email protected]>", | ||
"wudashuai <[email protected]>", | ||
"yfblock <[email protected]>", | ||
"scPointer <[email protected]>", | ||
"Shiping Yuan <[email protected]>", | ||
] | ||
description = "ArceOS user library with an interface similar to rust std" | ||
license = "GPL-3.0-or-later OR Apache-2.0" | ||
homepage = "https://github.com/rcore-os/arceos" | ||
repository = "https://github.com/rcore-os/arceos/tree/main/ulib/axstd" | ||
documentation = "https://rcore-os.github.io/arceos/axstd/index.html" | ||
keywords = ["Starry"] | ||
|
||
[features] | ||
default = [] | ||
|
||
# Multicore | ||
smp = ["axfeat/smp", "spinlock/smp", "arch_boot/smp"] | ||
|
||
# Floating point/SIMD | ||
fp_simd = ["axfeat/fp_simd", "arch_boot/fp_simd"] | ||
|
||
# Interrupts | ||
irq = ["arceos_api/irq", "axfeat/irq", "arch_boot/irq"] | ||
|
||
# Memory | ||
alloc = ["arceos_api/alloc", "axfeat/alloc", "axio/alloc"] | ||
alloc-tlsf = ["axfeat/alloc-tlsf"] | ||
alloc-slab = ["axfeat/alloc-slab"] | ||
alloc-buddy = ["axfeat/alloc-buddy"] | ||
paging = ["axfeat/paging"] | ||
tls = ["axfeat/tls"] | ||
|
||
# Multi-threading and scheduler | ||
multitask = ["arceos_api/multitask", "axfeat/multitask"] | ||
sched_fifo = ["axfeat/sched_fifo"] | ||
sched_rr = ["axfeat/sched_rr", "arch_boot/preempt"] | ||
sched_cfs = ["axfeat/sched_cfs", "arch_boot/preempt"] | ||
|
||
# File system | ||
fs = ["arceos_api/fs", "axfeat/fs"] | ||
myfs = ["arceos_api/myfs", "axfeat/myfs"] | ||
fatfs = ["axfeat/fatfs"] | ||
lwext4_rust = ["axfeat/lwext4_rust", "fs"] | ||
|
||
# Networking | ||
net = ["arceos_api/net", "axfeat/net"] | ||
dns = [] | ||
|
||
# Display | ||
display = ["arceos_api/display", "axfeat/display"] | ||
|
||
# Device drivers | ||
bus-mmio = ["axfeat/bus-mmio"] | ||
bus-pci = ["axfeat/bus-pci"] | ||
driver-ramdisk = ["axfeat/driver-ramdisk"] | ||
driver-ixgbe = ["axfeat/driver-ixgbe"] | ||
driver-bcm2835-sdhci = ["axfeat/driver-bcm2835-sdhci"] | ||
|
||
# Logging | ||
log-level-off = ["axfeat/log-level-off"] | ||
log-level-error = ["axfeat/log-level-error"] | ||
log-level-warn = ["axfeat/log-level-warn"] | ||
log-level-info = ["axfeat/log-level-info"] | ||
log-level-debug = ["axfeat/log-level-debug"] | ||
log-level-trace = ["axfeat/log-level-trace"] | ||
|
||
[dependencies] | ||
axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } | ||
arceos_api = { git = "https://github.com/Starry-OS/arceos_api.git" } | ||
axio = { git = "https://github.com/Starry-OS/axio.git" } | ||
axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } | ||
spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } | ||
arch_boot = { git = "https://github.com/Starry-OS/arch_boot.git" } |
This file contains 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,19 @@ | ||
//! Inspection and manipulation of the process’s environment. | ||
|
||
#[cfg(feature = "fs")] | ||
extern crate alloc; | ||
|
||
#[cfg(feature = "fs")] | ||
use {crate::io, alloc::string::String}; | ||
|
||
/// Returns the current working directory as a [`String`]. | ||
#[cfg(feature = "fs")] | ||
pub fn current_dir() -> io::Result<String> { | ||
arceos_api::fs::ax_current_dir() | ||
} | ||
|
||
/// Changes the current working directory to the specified path. | ||
#[cfg(feature = "fs")] | ||
pub fn set_current_dir(path: &str) -> io::Result<()> { | ||
arceos_api::fs::ax_set_current_dir(path) | ||
} |
This file contains 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,154 @@ | ||
extern crate alloc; | ||
|
||
use alloc::string::String; | ||
use core::fmt; | ||
|
||
use super::FileType; | ||
use crate::io::Result; | ||
|
||
use arceos_api::fs as api; | ||
|
||
/// Iterator over the entries in a directory. | ||
pub struct ReadDir<'a> { | ||
path: &'a str, | ||
inner: api::AxDirHandle, | ||
buf_pos: usize, | ||
buf_end: usize, | ||
end_of_stream: bool, | ||
dirent_buf: [api::AxDirEntry; 31], | ||
} | ||
|
||
/// Entries returned by the [`ReadDir`] iterator. | ||
pub struct DirEntry<'a> { | ||
dir_path: &'a str, | ||
entry_name: String, | ||
entry_type: FileType, | ||
} | ||
|
||
/// A builder used to create directories in various manners. | ||
#[derive(Default, Debug)] | ||
pub struct DirBuilder { | ||
recursive: bool, | ||
} | ||
|
||
impl<'a> ReadDir<'a> { | ||
pub(super) fn new(path: &'a str) -> Result<Self> { | ||
let mut opts = api::AxOpenOptions::new(); | ||
opts.read(true); | ||
let inner = api::ax_open_dir(path, &opts)?; | ||
|
||
const EMPTY: api::AxDirEntry = api::AxDirEntry::default(); | ||
let dirent_buf = [EMPTY; 31]; | ||
Ok(ReadDir { | ||
path, | ||
inner, | ||
end_of_stream: false, | ||
buf_pos: 0, | ||
buf_end: 0, | ||
dirent_buf, | ||
}) | ||
} | ||
} | ||
|
||
impl<'a> Iterator for ReadDir<'a> { | ||
type Item = Result<DirEntry<'a>>; | ||
|
||
fn next(&mut self) -> Option<Result<DirEntry<'a>>> { | ||
if self.end_of_stream { | ||
return None; | ||
} | ||
|
||
loop { | ||
if self.buf_pos >= self.buf_end { | ||
match api::ax_read_dir(&mut self.inner, &mut self.dirent_buf) { | ||
Ok(n) => { | ||
if n == 0 { | ||
self.end_of_stream = true; | ||
return None; | ||
} | ||
self.buf_pos = 0; | ||
self.buf_end = n; | ||
} | ||
Err(e) => { | ||
self.end_of_stream = true; | ||
return Some(Err(e)); | ||
} | ||
} | ||
} | ||
let entry = &self.dirent_buf[self.buf_pos]; | ||
self.buf_pos += 1; | ||
let name_bytes = entry.name_as_bytes(); | ||
if name_bytes == b"." || name_bytes == b".." { | ||
continue; | ||
} | ||
let entry_name = unsafe { core::str::from_utf8_unchecked(name_bytes).into() }; | ||
let entry_type = entry.entry_type(); | ||
|
||
return Some(Ok(DirEntry { | ||
dir_path: self.path, | ||
entry_name, | ||
entry_type, | ||
})); | ||
} | ||
} | ||
} | ||
|
||
impl<'a> DirEntry<'a> { | ||
/// Returns the full path to the file that this entry represents. | ||
/// | ||
/// The full path is created by joining the original path to `read_dir` | ||
/// with the filename of this entry. | ||
pub fn path(&self) -> String { | ||
String::from(self.dir_path.trim_end_matches('/')) + "/" + &self.entry_name | ||
} | ||
|
||
/// Returns the bare file name of this directory entry without any other | ||
/// leading path component. | ||
pub fn file_name(&self) -> String { | ||
self.entry_name.clone() | ||
} | ||
|
||
/// Returns the file type for the file that this entry points at. | ||
pub fn file_type(&self) -> FileType { | ||
self.entry_type | ||
} | ||
} | ||
|
||
impl fmt::Debug for DirEntry<'_> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_tuple("DirEntry").field(&self.path()).finish() | ||
} | ||
} | ||
|
||
impl DirBuilder { | ||
/// Creates a new set of options with default mode/security settings for all | ||
/// platforms and also non-recursive. | ||
pub fn new() -> Self { | ||
Self { recursive: false } | ||
} | ||
|
||
/// Indicates that directories should be created recursively, creating all | ||
/// parent directories. Parents that do not exist are created with the same | ||
/// security and permissions settings. | ||
pub fn recursive(&mut self, recursive: bool) -> &mut Self { | ||
self.recursive = recursive; | ||
self | ||
} | ||
|
||
/// Creates the specified directory with the options configured in this | ||
/// builder. | ||
pub fn create(&self, path: &str) -> Result<()> { | ||
if self.recursive { | ||
self.create_dir_all(path) | ||
} else { | ||
api::ax_create_dir(path) | ||
} | ||
} | ||
|
||
fn create_dir_all(&self, _path: &str) -> Result<()> { | ||
axerrno::ax_err!( | ||
Unsupported, | ||
"Recursive directory creation is not supported yet" | ||
) | ||
} | ||
} |
Oops, something went wrong.