Skip to content

Commit

Permalink
Syscall interface updated towards Result'
Browse files Browse the repository at this point in the history
  • Loading branch information
schoettner committed Aug 29, 2024
1 parent b3737e4 commit 7651660
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 140 deletions.
4 changes: 2 additions & 2 deletions os/application/mkentry/src/mkentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use naming::mkentry;
#[unsafe(no_mangle)]
pub fn main() {

let (r1,r2) = mkentry("/home/schoettner", "test.txt", 1);
let res = mkentry("/home/schoettner", "test.txt", 1);

println!("mkentry: 0x{:x}, 0x{:x}", r1,r2);
println!("app: mkentry {:?}", res);
}
3 changes: 2 additions & 1 deletion os/kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tar-no-std = "0.3.2"
pci_types = "0.10.0"
bitflags = "2.6.0"
smoltcp = { version = "0.11.0", default-features = false, features = ["alloc", "log", "medium-ethernet", "proto-ipv4", "socket-udp"] }
num_enum = { version = "0.7", default-features = false }

[build-dependencies]
built = { version = "0.7.4", features = ["chrono", "git2"] }
built = { version = "0.7.4", features = ["chrono", "git2"] }
1 change: 0 additions & 1 deletion os/kernel/src/naming/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod result;
pub mod stat;
pub mod name_service;
mod name_service_internal;
Expand Down
25 changes: 23 additions & 2 deletions os/kernel/src/naming/name_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,34 @@
*/
use alloc::sync::Arc;
use alloc::vec::Vec;
//use core::result::Result;
use syscall::consts::Errno;
use syscall::consts::Result;

use ::log::info;

use crate::naming::name_service_internal;
use crate::naming::name_service_internal::get_root_dir;
use crate::naming::result::Result;
use crate::naming::stat::Stat;


///
/// Description:
/// Add an entry (with or without data)
///
/// Parameters: \
/// `path` path (must exist) \
/// `name` name for the new entry \
/// `content` data bytes
///
pub fn mkentry_new(path: &str, name: &str, content: Vec<u8>) -> ::core::result::Result<usize,Errno> {
let r = get_root_dir().mkentry(path, name, content);

info!("mkentry: res = {:?}", r);
return Ok(0)
}


///
/// Description:
/// Add an entry (with or without data)
Expand All @@ -28,7 +49,7 @@ pub fn mkentry(path: &str, name: &str, content: Vec<u8>) -> Result<()> {
let r = get_root_dir().mkentry(path, name, content);

info!("mkentry: res = {:?}", r);
return r;
r
}

///
Expand Down
42 changes: 21 additions & 21 deletions os/kernel/src/naming/name_service_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
╟─────────────────────────────────────────────────────────────────────────╢
║ Descr.: Internal implementation of name service. ║
╟─────────────────────────────────────────────────────────────────────────╢
║ Author: Michael Schoettner, 1.8.2024, HHU
║ Author: Michael Schoettner, 29.8.2024, HHU ║
╚═════════════════════════════════════════════════════════════════════════╝
*/
use crate::naming::result::Result;
use crate::naming::result::{Errno, Error};
use syscall::consts::Result;
use syscall::consts::Errno;
use crate::naming::stat;
use crate::naming::stat::Mode;
use crate::naming::stat::Stat;
Expand Down Expand Up @@ -103,13 +103,13 @@ impl Directory {
// entry found, continue recursively, if more to do
if let EntryType::Directory(ref dir) = entry.entry_type {
if remaining_parts.is_empty() {
return Err(Error::new(Errno::EEXIST)); // we are done, dir already exists
return Err(Errno::EEXIST); // we are done, dir already exists
} else {
return dir.mkdir_in_dir(remaining_parts); // continue recursively
}
} else {
// found file with same name, abort
return Err(Error::new(Errno::ENOTDIR));
return Err(Errno::ENOTDIR);
}
}
}
Expand All @@ -127,7 +127,7 @@ impl Directory {
if let EntryType::Directory(ref mut new_dir) = dir.entries.last_mut().unwrap().entry_type {
return new_dir.mkdir_in_dir(remaining_parts);
} else {
return Err(Error::new(Errno::EEXIST)); // This should not happen
return Err(Errno::EEXIST); // This should not happen
}
}

Expand All @@ -153,7 +153,7 @@ impl Directory {
if parts.is_empty() {
for entry in &dir.entries {
if entry.stat.name == new_entry.stat.name {
return Err(Error::new(Errno::EEXIST)); // file already exists
return Err(Errno::EEXIST); // file already exists
}
}
dir.entries.push(new_entry);
Expand All @@ -168,11 +168,11 @@ impl Directory {
if let EntryType::Directory(ref directory) = entry.entry_type {
return directory.mkentry_in_dir(remaining_parts, new_entry);
} else {
return Err(Error::new(Errno::ENOENT)); // sub directory not found
return Err(Errno::ENOENT); // sub directory not found
}
}
}
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}

///
Expand All @@ -199,7 +199,7 @@ impl Directory {
return Ok(entry.content.clone());
} else {
// no, error
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}
}
Err(e) => Err(e),
Expand All @@ -223,7 +223,7 @@ impl Directory {
return Ok(ret);
} else {
// no, error
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}
}
Err(e) => Err(e),
Expand All @@ -236,7 +236,7 @@ impl Directory {

// If no more path parts, we did not find the file
if parts.is_empty() {
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}

// Recusively navigate to the right sub directory
Expand All @@ -249,11 +249,11 @@ impl Directory {
} else if let EntryType::Directory(ref directory) = entry.entry_type {
return directory.get_dentry(remaining_parts);
} else {
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}
}
}
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}

/// Rename given entry (any type)
Expand All @@ -268,7 +268,7 @@ impl Directory {

// If no more path parts, we did not find the file
if parts.is_empty() {
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}

// Recusively navigate to the right sub directory
Expand All @@ -282,11 +282,11 @@ impl Directory {
} else if let EntryType::Directory(ref directory) = entry.entry_type {
return directory.rename_internal(remaining_parts, new_name);
} else {
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}
}
}
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}

/// Delete given entry (any type)
Expand All @@ -302,7 +302,7 @@ impl Directory {
}
// If we found a dire which is not empty, return an error
else {
return Err(Error::new(Errno::ENOTEMPTY));
return Err(Errno::ENOTEMPTY);
}
}
// No dir found?, we continue below
Expand All @@ -316,7 +316,7 @@ impl Directory {
}
// No dir found?, we continue below
Err(_e) => {
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}
}
}
Expand All @@ -341,13 +341,13 @@ impl Directory {
if let EntryType::Directory(ref directory) = entry.entry_type {
return directory.del_internal(remaining_parts);
} else {
return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}
}
}
}

return Err(Error::new(Errno::ENOENT));
return Err(Errno::ENOENT);
}

///
Expand Down
10 changes: 5 additions & 5 deletions os/kernel/src/naming/name_service_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use alloc::vec;
use ::log::info;

use crate::naming::name_service::{cont, del, dir, mkdir, mkentry, rename, stat};
use crate::naming::result::{Errno, Error};
use syscall::consts::Errno;

///
/// Description:
Expand Down Expand Up @@ -50,7 +50,7 @@ fn test_mkdir() {
// Create same directory & subdirectory -> should fail
let r = mkdir("/home/schoettner");
assert!(
r == Err(Error::new(Errno::EEXIST)),
r == Err(Errno::EEXIST),
"mkdir(\"{}\") -> {:?}",
path,
r
Expand All @@ -59,7 +59,7 @@ fn test_mkdir() {
// Create same parent directory -> should fail
let r = mkdir("/home");
assert!(
r == Err(Error::new(Errno::EEXIST)),
r == Err(Errno::EEXIST),
"mkdir(\"{}\") -> {:?}",
path,
r
Expand Down Expand Up @@ -92,7 +92,7 @@ fn test_mkentry() {
let name = "brief.txt";
let r = mkentry(path, name, vec![1, 1, 1, 1, 1]);
assert!(
r == Err(Error::new(Errno::ENOENT)),
r == Err(Errno::ENOENT),
"mkdir(\"{}\", \"{}\") -> {:?}",
path,
name,
Expand All @@ -104,7 +104,7 @@ fn test_mkentry() {
let name = "brief.txt";
let r = mkentry(path, name, vec![1, 1, 1, 1, 1]);
assert!(
r == Err(Error::new(Errno::EEXIST)),
r == Err(Errno::EEXIST),
"mkdir(\"{}\", \"{}\") -> {:?}",
path,
name,
Expand Down
70 changes: 0 additions & 70 deletions os/kernel/src/naming/result.rs

This file was deleted.

Loading

0 comments on commit 7651660

Please sign in to comment.