-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
schoettner
committed
Sep 15, 2024
1 parent
0b86bc7
commit d9248e8
Showing
23 changed files
with
841 additions
and
853 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
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
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,30 @@ | ||
## How to add a new system call | ||
|
||
### Work to be done in User Mode | ||
|
||
1. | ||
You need to add an entry for your new syscall in: `os/library/syscall` | ||
In `enum SysCall`. Insert your new system call name before `LastEntryMarker`. | ||
|
||
2. | ||
For using your new System call, see examples in `os/library`. A system call is typically used within a runtime library function, not directly within an application. | ||
|
||
*Important: Check params before firing a syscall and abort if they are not valid.* | ||
|
||
3. | ||
Return values for system calls are defined in `return_vals.rs`. This file is used by user and kernel mode parts. | ||
|
||
|
||
### Work to be done in Kernel Mode | ||
|
||
1. | ||
You need to add the counterpart implementation for your user mode system call in a file in `os/kernel/syscall`, e.g. `sys_naming.rs`. All syscall function names should start with the prefix `sys_`. | ||
|
||
*Important: It is of upmost important to have the correct signature and check params.* | ||
|
||
2. | ||
Add your system call to the `SyscallTable` in `kernel/syscall/syscall_dispatcher.rs`. | ||
|
||
3. | ||
The return value is `isize` and created by calling `convert_syscall_result_to_ret_code` which expects a `SyscallResult`, defined in `return_vals.rs` (see above). So kernel counterparts should use `SyscallResult` which is converted to `isize` when returning to user mode. | ||
|
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 |
---|---|---|
|
@@ -2,13 +2,13 @@ cargo-features = ["edition2024"] | |
|
||
[package] | ||
edition = "2024" | ||
name = "mkentry" | ||
name = "mkdir" | ||
version = "0.1.0" | ||
authors = ["Michael Schöttner <[email protected]>, Fabian Ruhland <[email protected]>"] | ||
|
||
[lib] | ||
crate-type = ["staticlib"] | ||
path = "src/mkentry.rs" | ||
path = "src/mkdir.rs" | ||
|
||
[dependencies] | ||
# Local dependencies | ||
|
File renamed without changes.
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
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
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,145 @@ | ||
/* ╔═════════════════════════════════════════════════════════════════════════╗ | ||
║ Module: api ║ | ||
╟─────────────────────────────────────────────────────────────────────────╢ | ||
║ Descr.: Public interface of the name service (ns): ║ | ||
║ - mkdir: create a directory with all sub directories ║ | ||
║ - open: open a named object ║ | ||
║ - read: read bytes from an open object ║ | ||
║ - write: write bytes into an open object ║ | ||
║ - seek: set file pointer (for files) ║ | ||
║ - init: init ns, called once ║ | ||
║ - dump: print all entries on the screen (for debugging) ║ | ||
╟─────────────────────────────────────────────────────────────────────────╢ | ||
║ Author: Michael Schoettner, Univ. Duesseldorf, 9.9.2024 ║ | ||
╚═════════════════════════════════════════════════════════════════════════╝ | ||
*/ | ||
|
||
|
||
use alloc::string::String; | ||
use syscall::return_vals::{OpenOptions, SeekOrigin, convert_syscall_result_to_ret_code}; | ||
|
||
use crate::naming::main; | ||
use crate::naming::main::ns_get; | ||
use crate::naming::open_objects::ns_get_oot; | ||
|
||
|
||
/// | ||
/// Description: | ||
/// Init function of NS. Must be called once before using it. | ||
/// | ||
pub fn init() { | ||
main::init(); | ||
} | ||
|
||
/// | ||
/// Description: Create a directory (including sub directories) for the given path | ||
/// | ||
/// Parameters: `path` The path | ||
/// | ||
/// Return: `SyscallResult` | ||
/// | ||
pub fn mkdir(path: &String) -> isize { | ||
let result = ns_get().mkdir(path); | ||
let sysret; | ||
match result { | ||
Ok(()) => sysret = Ok(0), // Convert the success case to a meaningful u64, e.g., 0 | ||
Err(e) => sysret = Err(e), // Forward the error directly | ||
} | ||
return convert_syscall_result_to_ret_code(sysret); | ||
} | ||
|
||
/// | ||
/// Description: Open/create a named object | ||
/// | ||
/// Parameters: \ | ||
/// `path` must be an absolute path \ | ||
/// `flags` see below | ||
/// | ||
/// Return: `SyscallResult` | ||
/// | ||
pub fn open(path: &String, flags: OpenOptions) -> isize { | ||
let res = ns_get().open(path, flags); | ||
let sysret; | ||
match res { | ||
Ok(fptr) => { | ||
sysret = ns_get_oot().lock().create_new_handle_for_filepointer(fptr); | ||
}, | ||
Err(e) => sysret = Err(e), | ||
} | ||
return convert_syscall_result_to_ret_code(sysret); | ||
|
||
/* match res { | ||
Ok(fptr) => ns_get_oot().lock().create_new_handle_for_filepointer(fptr), | ||
Err(e) => Err(e), | ||
} | ||
*/ | ||
} | ||
|
||
/// | ||
/// Description: \ | ||
/// Write bytes from the given buffer into the file (at the current position). \ | ||
/// The number of bytes to be written is determined by the buffer size | ||
/// | ||
/// Parameters: \ | ||
/// `fh` file handle \ | ||
/// `buf` buffer from which bytes are copied into the file \ | ||
/// | ||
/// Return: `Ok(#bytes written)` or `Err(Errno)` | ||
/// | ||
pub fn write(fh: usize, buf: &[u8]) -> isize { | ||
let sysret; | ||
match ns_get_oot().lock().get(fh) { | ||
Ok(fptr) => sysret = fptr.write(buf), | ||
Err(e) => sysret = Err(e), | ||
} | ||
return convert_syscall_result_to_ret_code(sysret); | ||
} | ||
|
||
/// | ||
/// Description: Set file pointer. | ||
/// | ||
/// Parameters: \ | ||
/// `fh` file handle \ | ||
/// `offset` offset in bytes \ | ||
/// `origin` point of origin | ||
/// | ||
/// Return: `Ok(size in bytes)` or `Err(errno)` | ||
/// | ||
pub fn seek(fh: usize, offset: usize, origin: SeekOrigin) -> isize { | ||
let sysret; | ||
match ns_get_oot().lock().get(fh) { | ||
Ok(fptr) => sysret = fptr.seek(offset, origin), | ||
Err(e) => sysret = Err(e), | ||
} | ||
return convert_syscall_result_to_ret_code(sysret); | ||
} | ||
|
||
/// | ||
/// Description: \ | ||
/// Read bytes from the file (from current position) into the given buffer. \ | ||
/// The number of bytes to be read is determined by the buffer size | ||
/// | ||
/// Parameters: \ | ||
/// `fh` file handle \ | ||
/// `buf` buffer to copy file bytes into \ | ||
/// | ||
/// Return: `Ok(#bytes read)` or `Err(errno)` | ||
/// | ||
pub fn read(fh: usize, buf: &mut [u8]) -> isize { | ||
let sysret; | ||
match ns_get_oot().lock().get(fh) { | ||
Ok(fptr) => sysret = fptr.read(buf), | ||
Err(e) => sysret = Err(e), | ||
} | ||
return convert_syscall_result_to_ret_code(sysret); | ||
} | ||
|
||
/// | ||
/// Description: Dump all named objects on the screen (for debugging) | ||
/// | ||
/// Return: `Ok(0)` or `Err(errno)` | ||
/// | ||
pub fn dump() -> i64 { | ||
ns_get().dump(); | ||
return 0; | ||
} |
Oops, something went wrong.