This repository was archived by the owner on Jul 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmkdir.rs
More file actions
88 lines (75 loc) · 2.61 KB
/
mkdir.rs
File metadata and controls
88 lines (75 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright © 2021 University of Colorado. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
use alloc::string::String;
use core::fmt::Debug;
use abomonation::{decode, encode, unsafe_abomonate, Abomonation};
use core2::io::Result as IOResult;
use core2::io::Write;
use kpi::io::FileModes;
use rpc::rpc::*;
use super::super::fileops::get_str_from_payload;
use super::super::kernelrpc::*;
use super::super::CLIENT_STATE;
use super::FileIO;
use crate::error::{KError, KResult};
use crate::fallible_string::TryString;
use crate::fs::cnrfs;
#[derive(Debug)]
pub(crate) struct MkDirReq {
pub pid: usize,
pub modes: FileModes,
}
unsafe_abomonate!(MkDirReq: pid, modes);
pub(crate) fn rpc_mkdir<P: AsRef<[u8]> + Debug>(
pid: usize,
pathname: P,
modes: FileModes,
) -> KResult<(u64, u64)> {
log::debug!("MkDir({:?})", pathname);
// Construct request data
let req = MkDirReq { pid, modes };
let mut req_data = [0u8; core::mem::size_of::<MkDirReq>()];
unsafe { encode(&req, &mut (&mut req_data).as_mut()) }.expect("Failed to encode mkdir request");
// Create result buffer
let mut res_data = [0u8; core::mem::size_of::<KResult<(u64, u64)>>()];
// Call RPC
CLIENT_STATE.rpc_clients[kpi::system::mtid_from_gtid(*crate::environment::CORE_ID)]
.lock()
.call(
KernelRpc::MkDir as RPCType,
&[&req_data, pathname.as_ref()],
&mut [&mut res_data],
)?;
// Parse and return result
if let Some((res, remaining)) = unsafe { decode::<KResult<(u64, u64)>>(&mut res_data) } {
if remaining.len() > 0 {
Err(KError::from(RPCError::ExtraData))
} else {
log::debug!("MkDir() {:?}", res);
*res
}
} else {
Err(KError::from(RPCError::MalformedResponse))
}
}
// RPC Handler function for close() RPCs in the controller
pub(crate) fn handle_mkdir(hdr: &mut RPCHeader, payload: &mut [u8]) -> Result<(), RPCError> {
// Parse request
let (pid, modes) = match unsafe { decode::<MkDirReq>(payload) } {
Some((req, _)) => (req.pid, req.modes),
None => {
log::error!("Invalid payload for request: {:?}", hdr);
construct_error_ret(hdr, payload, KError::from(RPCError::MalformedRequest));
return Ok(());
}
};
let ret = get_str_from_payload(
payload,
core::mem::size_of::<MkDirReq>(),
hdr.msg_len as usize,
)
.and_then(|path_string| cnrfs::MlnrKernelNode::mkdir(pid, path_string, modes));
// Call mkdir function and send result
construct_ret(hdr, payload, ret);
Ok(())
}