mirror of https://github.com/vinc/moros.git
Refactor code (#330)
* Update changelog * Update rust version * Make changes suggested by Clippy
This commit is contained in:
parent
0ed6579f49
commit
4d90d2da75
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Improve FUSE driver with write and delete (#292)
|
||||
- Fix device reading (#329)
|
||||
- Add a reboot command (#328)
|
||||
- Fix issues with process alloc (#327)
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2022-04-04"
|
||||
channel = "nightly-2022-04-15"
|
||||
components = ["rust-src", "llvm-tools-preview"]
|
||||
|
|
|
@ -95,8 +95,8 @@ pub fn create_device(path: &str, kind: DeviceType) -> Option<usize> {
|
|||
}
|
||||
|
||||
pub fn read(path: &str, buf: &mut [u8]) -> Result<usize, ()> {
|
||||
if let Some(info) = syscall::info(&path) {
|
||||
let res = if info.is_device() { open_device(&path) } else { open_file(&path) };
|
||||
if let Some(info) = syscall::info(path) {
|
||||
let res = if info.is_device() { open_device(path) } else { open_file(path) };
|
||||
if let Some(handle) = res {
|
||||
if let Some(bytes) = syscall::read(handle, buf) {
|
||||
syscall::close(handle);
|
||||
|
@ -113,13 +113,13 @@ pub fn read_to_string(path: &str) -> Result<String, ()> {
|
|||
}
|
||||
|
||||
pub fn read_to_bytes(path: &str) -> Result<Vec<u8>, ()> {
|
||||
if let Some(info) = syscall::info(&path) {
|
||||
if let Some(info) = syscall::info(path) {
|
||||
let f = if info.is_device() {
|
||||
open_device(&path)
|
||||
open_device(path)
|
||||
} else if info.is_dir() {
|
||||
open_dir(&path)
|
||||
open_dir(path)
|
||||
} else {
|
||||
open_file(&path)
|
||||
open_file(path)
|
||||
};
|
||||
if let Some(handle) = f {
|
||||
let n = info.size() as usize;
|
||||
|
@ -135,7 +135,7 @@ pub fn read_to_bytes(path: &str) -> Result<Vec<u8>, ()> {
|
|||
}
|
||||
|
||||
pub fn write(path: &str, buf: &[u8]) -> Result<usize, ()> {
|
||||
if let Some(handle) = create_file(&path) {
|
||||
if let Some(handle) = create_file(path) {
|
||||
if let Some(bytes) = syscall::write(handle, buf) {
|
||||
syscall::close(handle);
|
||||
return Ok(bytes);
|
||||
|
@ -145,14 +145,14 @@ pub fn write(path: &str, buf: &[u8]) -> Result<usize, ()> {
|
|||
}
|
||||
|
||||
pub fn reopen(path: &str, handle: usize) -> Result<usize, ()> {
|
||||
let res = if let Some(info) = syscall::info(&path) {
|
||||
let res = if let Some(info) = syscall::info(path) {
|
||||
if info.is_device() {
|
||||
open_device(&path)
|
||||
open_device(path)
|
||||
} else {
|
||||
open_file(&path)
|
||||
open_file(path)
|
||||
}
|
||||
} else {
|
||||
create_file(&path)
|
||||
create_file(path)
|
||||
};
|
||||
if let Some(old_handle) = res {
|
||||
syscall::dup(old_handle, handle);
|
||||
|
@ -163,7 +163,7 @@ pub fn reopen(path: &str, handle: usize) -> Result<usize, ()> {
|
|||
}
|
||||
|
||||
pub fn read_dir(path: &str) -> Result<Vec<FileInfo>, ()> {
|
||||
if let Some(info) = syscall::info(&path) {
|
||||
if let Some(info) = syscall::info(path) {
|
||||
if info.is_dir() {
|
||||
if let Ok(buf) = read_to_bytes(path) {
|
||||
let mut res = Vec::new();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::api::syscall;
|
||||
|
||||
pub fn spawn(path: &str) -> Result<(), ()> {
|
||||
if syscall::info(&path).is_some() {
|
||||
syscall::spawn(&path);
|
||||
if syscall::info(path).is_some() {
|
||||
syscall::spawn(path);
|
||||
return Ok(());
|
||||
}
|
||||
Err(())
|
||||
|
|
|
@ -169,7 +169,7 @@ extern "sysv64" fn syscall_handler(stack_frame: &mut InterruptStackFrame, regs:
|
|||
let arg3 = regs.rdx;
|
||||
|
||||
if n == sys::syscall::number::SPAWN { // Backup CPU context
|
||||
sys::process::set_stack_frame(stack_frame.clone());
|
||||
sys::process::set_stack_frame(**stack_frame);
|
||||
sys::process::set_registers(*regs);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,6 @@ unsafe impl FrameAllocator<Size4KiB> for BootInfoFrameAllocator {
|
|||
|
||||
// FIXME: creating an iterator for each allocation is very slow if
|
||||
// the heap is larger than a few megabytes.
|
||||
let frame = self.usable_frames().nth(next);
|
||||
frame
|
||||
self.usable_frames().nth(next)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ pub fn set_registers(regs: Registers) {
|
|||
pub fn stack_frame() -> InterruptStackFrameValue {
|
||||
let table = PROCESS_TABLE.read();
|
||||
let proc = &table[id()];
|
||||
proc.stack_frame.clone()
|
||||
proc.stack_frame
|
||||
}
|
||||
|
||||
pub fn set_stack_frame(stack_frame: InterruptStackFrameValue) {
|
||||
|
@ -289,7 +289,7 @@ impl Process {
|
|||
|
||||
let data = parent.data.clone();
|
||||
let registers = parent.registers;
|
||||
let stack_frame = parent.stack_frame.clone();
|
||||
let stack_frame = parent.stack_frame;
|
||||
|
||||
let id = MAX_PID.fetch_add(1, Ordering::SeqCst);
|
||||
let proc = Process { id, code_addr, code_size, entry_point, data, stack_frame, registers };
|
||||
|
|
|
@ -124,7 +124,7 @@ impl Message {
|
|||
|
||||
fn dns_address() -> Option<IpAddress> {
|
||||
if let Some(servers) = usr::net::get_config("dns") {
|
||||
if let Some((server, _)) = servers.split_once(",") {
|
||||
if let Some((server, _)) = servers.split_once(',') {
|
||||
if let Ok(addr) = IpAddress::from_str(server) {
|
||||
return Some(addr);
|
||||
}
|
||||
|
|
|
@ -461,7 +461,7 @@ fn eval_mapcar_args(args: &[Exp], env: &mut Env) -> Result<Exp, Err> {
|
|||
fn eval_progn_args(args: &[Exp], env: &mut Env) -> Result<Exp, Err> {
|
||||
let mut res = Ok(Exp::List(vec![]));
|
||||
for arg in args {
|
||||
res = Ok(eval(&arg, env)?);
|
||||
res = Ok(eval(arg, env)?);
|
||||
}
|
||||
res
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ pub fn get_config(attribute: &str) -> Option<String> {
|
|||
}
|
||||
"ip" => {
|
||||
if let Some(ref mut iface) = *sys::net::IFACE.lock() {
|
||||
for ip_cidr in iface.ip_addrs() {
|
||||
if let Some(ip_cidr) = iface.ip_addrs().iter().next() {
|
||||
return Some(format!("{}/{}", ip_cidr.address(), ip_cidr.prefix_len()));
|
||||
}
|
||||
} else {
|
||||
|
@ -155,9 +155,8 @@ pub fn get_config(attribute: &str) -> Option<String> {
|
|||
let mut res = None;
|
||||
if let Some(ref mut iface) = *sys::net::IFACE.lock() {
|
||||
iface.routes_mut().update(|storage| {
|
||||
for (_, route) in storage.iter() {
|
||||
if let Some((_, route)) = storage.iter().next() {
|
||||
res = Some(route.via_router.to_string());
|
||||
break;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -168,7 +167,7 @@ pub fn get_config(attribute: &str) -> Option<String> {
|
|||
"dns" => {
|
||||
if let Ok(value) = fs::read_to_string(DNS_FILE) {
|
||||
let servers = value.trim();
|
||||
if servers.split(",").all(|s| Ipv4Address::from_str(s).is_ok()) {
|
||||
if servers.split(',').all(|s| Ipv4Address::from_str(s).is_ok()) {
|
||||
Some(servers.to_string())
|
||||
} else {
|
||||
error!("Could not parse '{}'", servers);
|
||||
|
@ -230,7 +229,7 @@ pub fn set_config(attribute: &str, value: &str) {
|
|||
}
|
||||
"dns" => {
|
||||
let servers = value.trim();
|
||||
if servers.split(",").all(|s| Ipv4Address::from_str(s).is_ok()) {
|
||||
if servers.split(',').all(|s| Ipv4Address::from_str(s).is_ok()) {
|
||||
if fs::write(DNS_FILE, format!("{}\n", servers).as_bytes()).is_err() {
|
||||
error!("Could not write to '{}'", DNS_FILE);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ fn shell_completer(line: &str) -> Vec<String> {
|
|||
|
||||
let args = split_args(line);
|
||||
let i = args.len() - 1;
|
||||
if args.len() == 1 && !args[0].starts_with("/") { // Autocomplete command
|
||||
if args.len() == 1 && !args[0].starts_with('/') { // Autocomplete command
|
||||
for &cmd in &AUTOCOMPLETE_COMMANDS {
|
||||
if let Some(entry) = cmd.strip_prefix(args[i]) {
|
||||
entries.push(entry.into());
|
||||
|
|
Loading…
Reference in New Issue