alnyan/yggdrasil: vfs rework in the kernel

This commit is contained in:
2023-12-05 12:24:47 +02:00
parent 4883af9371
commit 6c71a2798b
7 changed files with 25 additions and 26 deletions
-1
View File
@@ -7164,7 +7164,6 @@ name = "yggdrasil-abi"
version = "0.1.0"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
]
+4 -9
View File
@@ -81,7 +81,7 @@ impl Iterator for ReadDir {
let entry = self.buffer.take();
break if let Some(entry) = entry {
if &entry.name[..2] == b".\0" || &entry.name[..3] == b"..\0" {
if entry.name == "." || entry.name == ".." {
continue;
}
@@ -101,10 +101,7 @@ impl fmt::Debug for ReadDir {
impl DirEntry {
fn from_raw(parent: PathBuf, raw: &OsDirectoryEntry) -> Self {
// TODO this is ugly
let name_nul = raw.name.iter().position(|&x| x == 0).unwrap();
let name_str = crate::str::from_utf8(&raw.name[..name_nul]).unwrap();
let filename = OsString::from_str(name_str).unwrap();
let filename = OsString::from_str(raw.name.as_ref()).unwrap();
Self { path: parent.join(filename.clone()), filename, ty: FileType(raw.ty) }
}
@@ -144,12 +141,10 @@ pub fn readdir(path: &Path) -> io::Result<ReadDir> {
pub fn rmdir(path: &Path) -> io::Result<()> {
run_with_path_str(path, |path_str| {
cvt_io(unsafe { yggdrasil_rt::sys::remove(None, path_str, false) })
cvt_io(unsafe { yggdrasil_rt::sys::remove_directory(None, path_str) })
})
}
pub fn remove_dir_all(path: &Path) -> io::Result<()> {
run_with_path_str(path, |path_str| {
cvt_io(unsafe { yggdrasil_rt::sys::remove(None, path_str, true) })
})
todo!()
}
+1 -3
View File
@@ -124,9 +124,7 @@ pub(self) fn get_metadata_inner(
}
pub fn unlink(path: &Path) -> io::Result<()> {
run_with_path_str(path, |path_str| {
cvt_io(unsafe { yggdrasil_rt::sys::remove(None, path_str, false) })
})
run_with_path_str(path, |path_str| cvt_io(unsafe { yggdrasil_rt::sys::remove(None, path_str) }))
}
pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
+14 -7
View File
@@ -115,12 +115,17 @@ where
}
pub fn hashmap_random_keys() -> (u64, u64) {
const KEY_LEN: usize = core::mem::size_of::<u64>();
let mut v = [0u8; KEY_LEN * 2];
unsafe {
yggdrasil_rt::sys::debug_trace("sys::yggdrasil::hashmap_random_keys()");
yggdrasil_rt::sys::get_random(&mut v);
}
// Bruh
(1234, 4321)
let key1 = v[0..KEY_LEN].try_into().unwrap();
let key2 = v[KEY_LEN..].try_into().unwrap();
(u64::from_ne_bytes(key1), u64::from_ne_bytes(key2))
}
pub fn abort_internal() -> ! {
@@ -150,12 +155,14 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
Ok(OsError::DirectoryNotEmpty) => ErrorKind::DirectoryNotEmpty,
Ok(OsError::Interrupted) => ErrorKind::Interrupted,
Ok(OsError::WouldBlock) => ErrorKind::WouldBlock,
Ok(OsError::ReadOnly) => ErrorKind::ReadOnlyFilesystem,
Ok(OsError::PermissionDenied) => ErrorKind::PermissionDenied,
// Memory and general
Ok(OsError::OutOfMemory) => ErrorKind::OutOfMemory,
Ok(OsError::InvalidArgument) | Ok(OsError::InvalidMemoryOperation) => {
ErrorKind::InvalidInput
}
Ok(OsError::InvalidArgument)
| Ok(OsError::InvalidMemoryOperation)
| Ok(OsError::InvalidOperation) => ErrorKind::InvalidInput,
Ok(OsError::NotImplemented) => ErrorKind::Unsupported,
// Uncategorized
@@ -199,5 +206,5 @@ pub unsafe extern "C" fn runtime_entry(program_arg: usize) -> ! {
let result = main(0, null());
yggdrasil_rt::sys::exit(OsExitCode::Exited(result));
yggdrasil_rt::sys::exit_process(OsExitCode::Exited(result));
}
+4 -4
View File
@@ -6,12 +6,12 @@ use yggdrasil_rt::path as rt_path;
#[inline]
pub fn is_sep_byte(b: u8) -> bool {
b == (rt_path::SEPARATOR as u8)
b == (rt_path::Path::SEPARATOR as u8)
}
#[inline]
pub fn is_verbatim_sep(b: u8) -> bool {
b == (rt_path::SEPARATOR as u8)
b == (rt_path::Path::SEPARATOR as u8)
}
#[inline]
@@ -19,8 +19,8 @@ pub fn parse_prefix(_: &OsStr) -> Option<Prefix<'_>> {
None
}
pub const MAIN_SEP_STR: &str = rt_path::SEPARATOR_STR;
pub const MAIN_SEP: char = rt_path::SEPARATOR;
pub const MAIN_SEP_STR: &str = rt_path::Path::SEPARATOR_STR;
pub const MAIN_SEP: char = rt_path::Path::SEPARATOR;
pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
let mut components = path.strip_prefix(".").unwrap_or(path).components();
+1 -1
View File
@@ -70,7 +70,7 @@ unsafe extern "C" fn signal_entry(data: &SignalEntryData) -> ! {
}
SignalHandler::Terminate => {
eprintln!("#{}: {:?}", pid, data.signal);
sys::exit(OsExitCode::BySignal(data.signal));
sys::exit_process(OsExitCode::BySignal(data.signal));
}
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ impl Thread {
p();
debug_trace!("Thread finish");
sys::exit(ExitCode::Exited(0));
sys::exit_thread(ExitCode::Exited(0));
}
}
}