start proxmox-sys module
This commit is contained in:
parent
3dd6cd3fe0
commit
71f2d48c2e
@ -3,5 +3,6 @@ members = [
|
||||
"proxmox-tools",
|
||||
"proxmox-api",
|
||||
"proxmox-api-macro",
|
||||
"proxmox-sys",
|
||||
"proxmox",
|
||||
]
|
||||
|
18
proxmox-sys/Cargo.toml
Normal file
18
proxmox-sys/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "proxmox-sys"
|
||||
edition = "2018"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Dietmar Maurer <dietmar@proxmox.com>",
|
||||
"Wolfgang Bumiller <w.bumiller@proxmox.com>",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
failure = "0.1"
|
||||
libc = "0.2"
|
||||
nix = "0.13"
|
||||
proxmox-tools = { path = "../proxmox-tools" }
|
||||
|
||||
# Docs should be able to reference the proxmox crate.
|
||||
[dev-dependencies]
|
||||
proxmox = { path = "../proxmox" }
|
4
proxmox-sys/src/lib.rs
Normal file
4
proxmox-sys/src/lib.rs
Normal file
@ -0,0 +1,4 @@
|
||||
//! This is a system utility crate used by all our rust projects.
|
||||
|
||||
|
||||
pub mod linux;
|
38
proxmox-sys/src/linux.rs
Normal file
38
proxmox-sys/src/linux.rs
Normal file
@ -0,0 +1,38 @@
|
||||
//! Linux specific helpers and syscall wrapper
|
||||
|
||||
use failure::*;
|
||||
use proxmox_tools as tools;
|
||||
|
||||
/// Get pseudo random data (/dev/urandom)
|
||||
pub fn random_data(size: usize) -> Result<Vec<u8>, Error> {
|
||||
|
||||
let mut buffer = tools::vec::undefined(size);
|
||||
fill_with_random_data(&mut buffer)?;
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
/// Fill buffer with pseudo random data (/dev/urandom)
|
||||
///
|
||||
/// This code uses the Linux syscall getrandom() - see "man 2 getrandom".
|
||||
pub fn fill_with_random_data(buffer: &mut [u8]) -> Result<(), Error> {
|
||||
|
||||
let res = unsafe {
|
||||
libc::syscall(
|
||||
libc::SYS_getrandom,
|
||||
buffer.as_mut_ptr(),
|
||||
buffer.len() as libc::size_t,
|
||||
0 as libc::c_uint,
|
||||
)
|
||||
};
|
||||
|
||||
if res == -1 {
|
||||
return Err(std::io::Error::last_os_error().into());
|
||||
}
|
||||
|
||||
if res as usize != buffer.len() { // should not happen
|
||||
bail!("short getrandom read");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -11,3 +11,4 @@ authors = [
|
||||
proxmox-api = { path = "../proxmox-api" }
|
||||
proxmox-api-macro = { path = "../proxmox-api-macro" }
|
||||
proxmox-tools = { path = "../proxmox-tools" }
|
||||
proxmox-sys = { path = "../proxmox-sys" }
|
||||
|
@ -1,4 +1,5 @@
|
||||
pub use proxmox_tools as tools;
|
||||
pub use proxmox_sys as sys;
|
||||
|
||||
// Both `proxmox_api` and the 2 macros from `proxmox_api_macro` should be
|
||||
// exposed via `proxmox::api`.
|
||||
|
Loading…
Reference in New Issue
Block a user