mirror of
				https://github.com/edera-dev/krata.git
				synced 2025-11-04 07:39:39 +00:00 
			
		
		
		
	hypha: move libraries to libs/
This commit is contained in:
		
							
								
								
									
										109
									
								
								libs/xen/xenstore/src/bus.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								libs/xen/xenstore/src/bus.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,109 @@
 | 
			
		||||
use crate::error::{Error, Result};
 | 
			
		||||
use crate::sys::{XsdMessageHeader, XSD_ERROR};
 | 
			
		||||
use std::ffi::CString;
 | 
			
		||||
use std::fs::metadata;
 | 
			
		||||
use std::io::{Read, Write};
 | 
			
		||||
use std::mem::size_of;
 | 
			
		||||
use std::net::Shutdown;
 | 
			
		||||
use std::os::unix::net::UnixStream;
 | 
			
		||||
 | 
			
		||||
const XEN_BUS_PATHS: &[&str] = &["/var/run/xenstored/socket"];
 | 
			
		||||
 | 
			
		||||
fn find_bus_path() -> Option<String> {
 | 
			
		||||
    for path in XEN_BUS_PATHS {
 | 
			
		||||
        match metadata(path) {
 | 
			
		||||
            Ok(_) => return Some(String::from(*path)),
 | 
			
		||||
            Err(_) => continue,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    None
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct XsdSocket {
 | 
			
		||||
    handle: UnixStream,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
pub struct XsdResponse {
 | 
			
		||||
    pub header: XsdMessageHeader,
 | 
			
		||||
    pub payload: Vec<u8>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XsdResponse {
 | 
			
		||||
    pub fn parse_string(&self) -> Result<String> {
 | 
			
		||||
        Ok(CString::from_vec_with_nul(self.payload.clone())?.into_string()?)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn parse_string_vec(&self) -> Result<Vec<String>> {
 | 
			
		||||
        let mut strings: Vec<String> = Vec::new();
 | 
			
		||||
        let mut buffer: Vec<u8> = Vec::new();
 | 
			
		||||
        for b in &self.payload {
 | 
			
		||||
            if *b == 0 {
 | 
			
		||||
                let string = String::from_utf8(buffer.clone())?;
 | 
			
		||||
                strings.push(string);
 | 
			
		||||
                buffer.clear();
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            buffer.push(*b);
 | 
			
		||||
        }
 | 
			
		||||
        Ok(strings)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn parse_bool(&self) -> Result<bool> {
 | 
			
		||||
        Ok(true)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XsdSocket {
 | 
			
		||||
    pub fn dial() -> Result<XsdSocket> {
 | 
			
		||||
        let path = match find_bus_path() {
 | 
			
		||||
            Some(path) => path,
 | 
			
		||||
            None => return Err(Error::BusNotFound),
 | 
			
		||||
        };
 | 
			
		||||
        let stream = UnixStream::connect(path)?;
 | 
			
		||||
        Ok(XsdSocket { handle: stream })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn send(&mut self, tx: u32, typ: u32, buf: &[u8]) -> Result<XsdResponse> {
 | 
			
		||||
        let header = XsdMessageHeader {
 | 
			
		||||
            typ,
 | 
			
		||||
            req: 0,
 | 
			
		||||
            tx,
 | 
			
		||||
            len: buf.len() as u32,
 | 
			
		||||
        };
 | 
			
		||||
        self.handle.write_all(bytemuck::bytes_of(&header))?;
 | 
			
		||||
        self.handle.write_all(buf)?;
 | 
			
		||||
        let mut result_buf = vec![0u8; size_of::<XsdMessageHeader>()];
 | 
			
		||||
        self.handle.read_exact(result_buf.as_mut_slice())?;
 | 
			
		||||
        let result_header = bytemuck::from_bytes::<XsdMessageHeader>(&result_buf);
 | 
			
		||||
        let mut payload = vec![0u8; result_header.len as usize];
 | 
			
		||||
        self.handle.read_exact(payload.as_mut_slice())?;
 | 
			
		||||
        if result_header.typ == XSD_ERROR {
 | 
			
		||||
            let error = CString::from_vec_with_nul(payload)?;
 | 
			
		||||
            return Err(Error::ResponseError(error.into_string()?));
 | 
			
		||||
        }
 | 
			
		||||
        let response = XsdResponse { header, payload };
 | 
			
		||||
        Ok(response)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn send_single(&mut self, tx: u32, typ: u32, string: &str) -> Result<XsdResponse> {
 | 
			
		||||
        let text = CString::new(string)?;
 | 
			
		||||
        let buf = text.as_bytes_with_nul();
 | 
			
		||||
        self.send(tx, typ, buf)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn send_multiple(&mut self, tx: u32, typ: u32, array: &[&str]) -> Result<XsdResponse> {
 | 
			
		||||
        let mut buf: Vec<u8> = Vec::new();
 | 
			
		||||
        for item in array {
 | 
			
		||||
            buf.extend_from_slice(item.as_bytes());
 | 
			
		||||
            buf.push(0);
 | 
			
		||||
        }
 | 
			
		||||
        self.send(tx, typ, buf.as_slice())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Drop for XsdSocket {
 | 
			
		||||
    fn drop(&mut self) {
 | 
			
		||||
        self.handle.shutdown(Shutdown::Both).unwrap()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										259
									
								
								libs/xen/xenstore/src/client.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										259
									
								
								libs/xen/xenstore/src/client.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,259 @@
 | 
			
		||||
use crate::bus::XsdSocket;
 | 
			
		||||
use crate::error::{Error, Result};
 | 
			
		||||
use crate::sys::{
 | 
			
		||||
    XSD_DIRECTORY, XSD_GET_DOMAIN_PATH, XSD_INTRODUCE, XSD_MKDIR, XSD_READ, XSD_RM, XSD_SET_PERMS,
 | 
			
		||||
    XSD_TRANSACTION_END, XSD_TRANSACTION_START, XSD_WRITE,
 | 
			
		||||
};
 | 
			
		||||
use log::trace;
 | 
			
		||||
use std::ffi::CString;
 | 
			
		||||
 | 
			
		||||
pub const XS_PERM_NONE: u32 = 0x00;
 | 
			
		||||
pub const XS_PERM_READ: u32 = 0x01;
 | 
			
		||||
pub const XS_PERM_WRITE: u32 = 0x02;
 | 
			
		||||
pub const XS_PERM_READ_WRITE: u32 = XS_PERM_READ | XS_PERM_WRITE;
 | 
			
		||||
 | 
			
		||||
pub struct XsdClient {
 | 
			
		||||
    pub socket: XsdSocket,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Copy, Clone)]
 | 
			
		||||
pub struct XsPermission {
 | 
			
		||||
    pub id: u32,
 | 
			
		||||
    pub perms: u32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XsPermission {
 | 
			
		||||
    pub fn encode(&self) -> Result<String> {
 | 
			
		||||
        let c = match self.perms {
 | 
			
		||||
            XS_PERM_READ_WRITE => 'b',
 | 
			
		||||
            XS_PERM_WRITE => 'w',
 | 
			
		||||
            XS_PERM_READ => 'r',
 | 
			
		||||
            XS_PERM_NONE => 'n',
 | 
			
		||||
            _ => return Err(Error::InvalidPermissions),
 | 
			
		||||
        };
 | 
			
		||||
        Ok(format!("{}{}", c, self.id))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub trait XsdInterface {
 | 
			
		||||
    fn list(&mut self, path: &str) -> Result<Vec<String>>;
 | 
			
		||||
    fn read(&mut self, path: &str) -> Result<Vec<u8>>;
 | 
			
		||||
    fn read_string(&mut self, path: &str) -> Result<String>;
 | 
			
		||||
    fn write(&mut self, path: &str, data: Vec<u8>) -> Result<bool>;
 | 
			
		||||
    fn write_string(&mut self, path: &str, data: &str) -> Result<bool>;
 | 
			
		||||
    fn mkdir(&mut self, path: &str) -> Result<bool>;
 | 
			
		||||
    fn rm(&mut self, path: &str) -> Result<bool>;
 | 
			
		||||
    fn set_perms(&mut self, path: &str, perms: &[XsPermission]) -> Result<bool>;
 | 
			
		||||
 | 
			
		||||
    fn mknod(&mut self, path: &str, perms: &[XsPermission]) -> Result<bool> {
 | 
			
		||||
        let result1 = self.write_string(path, "")?;
 | 
			
		||||
        let result2 = self.set_perms(path, perms)?;
 | 
			
		||||
        Ok(result1 && result2)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read_string_optional(&mut self, path: &str) -> Result<Option<String>> {
 | 
			
		||||
        Ok(match self.read_string(path) {
 | 
			
		||||
            Ok(value) => Some(value),
 | 
			
		||||
            Err(error) => {
 | 
			
		||||
                if error.is_noent_response() {
 | 
			
		||||
                    None
 | 
			
		||||
                } else {
 | 
			
		||||
                    return Err(error);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn list_any(&mut self, path: &str) -> Result<Vec<String>> {
 | 
			
		||||
        Ok(match self.list(path) {
 | 
			
		||||
            Ok(value) => value,
 | 
			
		||||
            Err(error) => {
 | 
			
		||||
                if error.is_noent_response() {
 | 
			
		||||
                    Vec::new()
 | 
			
		||||
                } else {
 | 
			
		||||
                    return Err(error);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XsdClient {
 | 
			
		||||
    pub fn open() -> Result<XsdClient> {
 | 
			
		||||
        let socket = XsdSocket::dial()?;
 | 
			
		||||
        Ok(XsdClient { socket })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn list(&mut self, tx: u32, path: &str) -> Result<Vec<String>> {
 | 
			
		||||
        trace!("list tx={tx} path={path}");
 | 
			
		||||
        let response = self.socket.send_single(tx, XSD_DIRECTORY, path)?;
 | 
			
		||||
        response.parse_string_vec()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read(&mut self, tx: u32, path: &str) -> Result<Vec<u8>> {
 | 
			
		||||
        trace!("read tx={tx} path={path}");
 | 
			
		||||
        let response = self.socket.send_single(tx, XSD_READ, path)?;
 | 
			
		||||
        Ok(response.payload)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn write(&mut self, tx: u32, path: &str, data: Vec<u8>) -> Result<bool> {
 | 
			
		||||
        trace!("write tx={tx} path={path} data={:?}", data);
 | 
			
		||||
        let mut buffer = Vec::new();
 | 
			
		||||
        let path = CString::new(path)?;
 | 
			
		||||
        buffer.extend_from_slice(path.as_bytes_with_nul());
 | 
			
		||||
        buffer.extend_from_slice(data.as_slice());
 | 
			
		||||
        let response = self.socket.send(tx, XSD_WRITE, buffer.as_slice())?;
 | 
			
		||||
        response.parse_bool()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn mkdir(&mut self, tx: u32, path: &str) -> Result<bool> {
 | 
			
		||||
        trace!("mkdir tx={tx} path={path}");
 | 
			
		||||
        self.socket.send_single(tx, XSD_MKDIR, path)?.parse_bool()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn rm(&mut self, tx: u32, path: &str) -> Result<bool> {
 | 
			
		||||
        trace!("rm tx={tx} path={path}");
 | 
			
		||||
        let result = self.socket.send_single(tx, XSD_RM, path);
 | 
			
		||||
        if let Err(error) = result {
 | 
			
		||||
            if error.is_noent_response() {
 | 
			
		||||
                return Ok(true);
 | 
			
		||||
            }
 | 
			
		||||
            return Err(error);
 | 
			
		||||
        }
 | 
			
		||||
        result.unwrap().parse_bool()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn set_perms(&mut self, tx: u32, path: &str, perms: &[XsPermission]) -> Result<bool> {
 | 
			
		||||
        trace!("set_perms tx={tx} path={path} perms={:?}", perms);
 | 
			
		||||
        let mut items: Vec<String> = Vec::new();
 | 
			
		||||
        items.push(path.to_string());
 | 
			
		||||
        for perm in perms {
 | 
			
		||||
            items.push(perm.encode()?);
 | 
			
		||||
        }
 | 
			
		||||
        let items_str: Vec<&str> = items.iter().map(|x| x.as_str()).collect();
 | 
			
		||||
        let response = self.socket.send_multiple(tx, XSD_SET_PERMS, &items_str)?;
 | 
			
		||||
        response.parse_bool()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn transaction(&mut self) -> Result<XsdTransaction> {
 | 
			
		||||
        trace!("transaction start");
 | 
			
		||||
        let response = self.socket.send_single(0, XSD_TRANSACTION_START, "")?;
 | 
			
		||||
        let str = response.parse_string()?;
 | 
			
		||||
        let tx = str.parse::<u32>()?;
 | 
			
		||||
        Ok(XsdTransaction { client: self, tx })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_domain_path(&mut self, domid: u32) -> Result<String> {
 | 
			
		||||
        let response =
 | 
			
		||||
            self.socket
 | 
			
		||||
                .send_single(0, XSD_GET_DOMAIN_PATH, domid.to_string().as_str())?;
 | 
			
		||||
        response.parse_string()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn introduce_domain(&mut self, domid: u32, mfn: u64, evtchn: u32) -> Result<bool> {
 | 
			
		||||
        trace!("introduce domain domid={domid} mfn={mfn} evtchn={evtchn}");
 | 
			
		||||
        let response = self.socket.send_multiple(
 | 
			
		||||
            0,
 | 
			
		||||
            XSD_INTRODUCE,
 | 
			
		||||
            &[
 | 
			
		||||
                domid.to_string().as_str(),
 | 
			
		||||
                mfn.to_string().as_str(),
 | 
			
		||||
                evtchn.to_string().as_str(),
 | 
			
		||||
            ],
 | 
			
		||||
        )?;
 | 
			
		||||
        response.parse_bool()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct XsdTransaction<'a> {
 | 
			
		||||
    client: &'a mut XsdClient,
 | 
			
		||||
    tx: u32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XsdInterface for XsdClient {
 | 
			
		||||
    fn list(&mut self, path: &str) -> Result<Vec<String>> {
 | 
			
		||||
        self.list(0, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read(&mut self, path: &str) -> Result<Vec<u8>> {
 | 
			
		||||
        self.read(0, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read_string(&mut self, path: &str) -> Result<String> {
 | 
			
		||||
        Ok(String::from_utf8(self.read(0, path)?)?)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn write(&mut self, path: &str, data: Vec<u8>) -> Result<bool> {
 | 
			
		||||
        self.write(0, path, data)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn write_string(&mut self, path: &str, data: &str) -> Result<bool> {
 | 
			
		||||
        self.write(0, path, data.as_bytes().to_vec())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn mkdir(&mut self, path: &str) -> Result<bool> {
 | 
			
		||||
        self.mkdir(0, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn rm(&mut self, path: &str) -> Result<bool> {
 | 
			
		||||
        self.rm(0, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn set_perms(&mut self, path: &str, perms: &[XsPermission]) -> Result<bool> {
 | 
			
		||||
        self.set_perms(0, path, perms)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XsdInterface for XsdTransaction<'_> {
 | 
			
		||||
    fn list(&mut self, path: &str) -> Result<Vec<String>> {
 | 
			
		||||
        self.client.list(self.tx, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read(&mut self, path: &str) -> Result<Vec<u8>> {
 | 
			
		||||
        self.client.read(self.tx, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read_string(&mut self, path: &str) -> Result<String> {
 | 
			
		||||
        Ok(String::from_utf8(self.client.read(self.tx, path)?)?)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn write(&mut self, path: &str, data: Vec<u8>) -> Result<bool> {
 | 
			
		||||
        self.client.write(self.tx, path, data)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn write_string(&mut self, path: &str, data: &str) -> Result<bool> {
 | 
			
		||||
        self.client.write(self.tx, path, data.as_bytes().to_vec())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn mkdir(&mut self, path: &str) -> Result<bool> {
 | 
			
		||||
        self.client.mkdir(self.tx, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn rm(&mut self, path: &str) -> Result<bool> {
 | 
			
		||||
        self.client.rm(self.tx, path)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn set_perms(&mut self, path: &str, perms: &[XsPermission]) -> Result<bool> {
 | 
			
		||||
        self.client.set_perms(self.tx, path, perms)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XsdTransaction<'_> {
 | 
			
		||||
    pub fn end(&mut self, abort: bool) -> Result<bool> {
 | 
			
		||||
        let abort_str = if abort { "F" } else { "T" };
 | 
			
		||||
 | 
			
		||||
        trace!("transaction end abort={}", abort);
 | 
			
		||||
        self.client
 | 
			
		||||
            .socket
 | 
			
		||||
            .send_single(self.tx, XSD_TRANSACTION_END, abort_str)?
 | 
			
		||||
            .parse_bool()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn commit(&mut self) -> Result<bool> {
 | 
			
		||||
        self.end(false)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn abort(&mut self) -> Result<bool> {
 | 
			
		||||
        self.end(true)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										40
									
								
								libs/xen/xenstore/src/error.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								libs/xen/xenstore/src/error.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,40 @@
 | 
			
		||||
use std::ffi::{FromVecWithNulError, IntoStringError, NulError};
 | 
			
		||||
use std::io;
 | 
			
		||||
use std::num::ParseIntError;
 | 
			
		||||
use std::str::Utf8Error;
 | 
			
		||||
use std::string::FromUtf8Error;
 | 
			
		||||
 | 
			
		||||
#[derive(thiserror::Error, Debug)]
 | 
			
		||||
pub enum Error {
 | 
			
		||||
    #[error("io issue encountered")]
 | 
			
		||||
    Io(#[from] io::Error),
 | 
			
		||||
    #[error("utf8 string decode failed")]
 | 
			
		||||
    Utf8DecodeString(#[from] FromUtf8Error),
 | 
			
		||||
    #[error("utf8 str decode failed")]
 | 
			
		||||
    Utf8DecodeStr(#[from] Utf8Error),
 | 
			
		||||
    #[error("unable to decode cstring as utf8")]
 | 
			
		||||
    Utf8DecodeCstring(#[from] IntoStringError),
 | 
			
		||||
    #[error("nul byte found in string")]
 | 
			
		||||
    NulByteFoundString(#[from] NulError),
 | 
			
		||||
    #[error("unable to find nul byte in vec")]
 | 
			
		||||
    VecNulByteNotFound(#[from] FromVecWithNulError),
 | 
			
		||||
    #[error("unable to parse integer")]
 | 
			
		||||
    ParseInt(#[from] ParseIntError),
 | 
			
		||||
    #[error("bus was not found on any available path")]
 | 
			
		||||
    BusNotFound,
 | 
			
		||||
    #[error("store responded with error: `{0}`")]
 | 
			
		||||
    ResponseError(String),
 | 
			
		||||
    #[error("invalid permissions provided")]
 | 
			
		||||
    InvalidPermissions,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Error {
 | 
			
		||||
    pub fn is_noent_response(&self) -> bool {
 | 
			
		||||
        match self {
 | 
			
		||||
            Error::ResponseError(message) => message == "ENOENT",
 | 
			
		||||
            _ => false,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub type Result<T> = std::result::Result<T, Error>;
 | 
			
		||||
							
								
								
									
										4
									
								
								libs/xen/xenstore/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								libs/xen/xenstore/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
pub mod bus;
 | 
			
		||||
pub mod client;
 | 
			
		||||
pub mod error;
 | 
			
		||||
pub mod sys;
 | 
			
		||||
							
								
								
									
										141
									
								
								libs/xen/xenstore/src/sys.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								libs/xen/xenstore/src/sys.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,141 @@
 | 
			
		||||
/// Handwritten protocol definitions for XenStore.
 | 
			
		||||
/// Used xen/include/public/io/xs_wire.h as a reference.
 | 
			
		||||
use bytemuck::{Pod, Zeroable};
 | 
			
		||||
use libc;
 | 
			
		||||
 | 
			
		||||
#[derive(Copy, Clone, Pod, Zeroable, Debug)]
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct XsdMessageHeader {
 | 
			
		||||
    pub typ: u32,
 | 
			
		||||
    pub req: u32,
 | 
			
		||||
    pub tx: u32,
 | 
			
		||||
    pub len: u32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub const XSD_CONTROL: u32 = 0;
 | 
			
		||||
pub const XSD_DIRECTORY: u32 = 1;
 | 
			
		||||
pub const XSD_READ: u32 = 2;
 | 
			
		||||
pub const XSD_GET_PERMS: u32 = 3;
 | 
			
		||||
pub const XSD_WATCH: u32 = 4;
 | 
			
		||||
pub const XSD_UNWATCH: u32 = 5;
 | 
			
		||||
pub const XSD_TRANSACTION_START: u32 = 6;
 | 
			
		||||
pub const XSD_TRANSACTION_END: u32 = 7;
 | 
			
		||||
pub const XSD_INTRODUCE: u32 = 8;
 | 
			
		||||
pub const XSD_RELEASE: u32 = 9;
 | 
			
		||||
pub const XSD_GET_DOMAIN_PATH: u32 = 10;
 | 
			
		||||
pub const XSD_WRITE: u32 = 11;
 | 
			
		||||
pub const XSD_MKDIR: u32 = 12;
 | 
			
		||||
pub const XSD_RM: u32 = 13;
 | 
			
		||||
pub const XSD_SET_PERMS: u32 = 14;
 | 
			
		||||
pub const XSD_WATCH_EVENT: u32 = 15;
 | 
			
		||||
pub const XSD_ERROR: u32 = 16;
 | 
			
		||||
pub const XSD_IS_DOMAIN_INTRODUCED: u32 = 17;
 | 
			
		||||
pub const XSD_RESUME: u32 = 18;
 | 
			
		||||
pub const XSD_SET_TARGET: u32 = 19;
 | 
			
		||||
pub const XSD_RESET_WATCHES: u32 = XSD_SET_TARGET + 2;
 | 
			
		||||
pub const XSD_DIRECTORY_PART: u32 = 20;
 | 
			
		||||
pub const XSD_TYPE_COUNT: u32 = 21;
 | 
			
		||||
pub const XSD_INVALID: u32 = 0xffff;
 | 
			
		||||
 | 
			
		||||
pub const XSD_WRITE_NONE: &str = "NONE";
 | 
			
		||||
pub const XSD_WRITE_CREATE: &str = "CREATE";
 | 
			
		||||
pub const XSD_WRITE_CREATE_EXCL: &str = "CREATE|EXCL";
 | 
			
		||||
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct XsdError<'a> {
 | 
			
		||||
    pub num: i32,
 | 
			
		||||
    pub error: &'a str,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub const XSD_ERROR_EINVAL: XsdError = XsdError {
 | 
			
		||||
    num: libc::EINVAL,
 | 
			
		||||
    error: "EINVAL",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EACCES: XsdError = XsdError {
 | 
			
		||||
    num: libc::EACCES,
 | 
			
		||||
    error: "EACCES",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EEXIST: XsdError = XsdError {
 | 
			
		||||
    num: libc::EEXIST,
 | 
			
		||||
    error: "EEXIST",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EISDIR: XsdError = XsdError {
 | 
			
		||||
    num: libc::EISDIR,
 | 
			
		||||
    error: "EISDIR",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_ENOENT: XsdError = XsdError {
 | 
			
		||||
    num: libc::ENOENT,
 | 
			
		||||
    error: "ENOENT",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_ENOMEM: XsdError = XsdError {
 | 
			
		||||
    num: libc::ENOMEM,
 | 
			
		||||
    error: "ENOMEM",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_ENOSPC: XsdError = XsdError {
 | 
			
		||||
    num: libc::ENOSPC,
 | 
			
		||||
    error: "ENOSPC",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EIO: XsdError = XsdError {
 | 
			
		||||
    num: libc::EIO,
 | 
			
		||||
    error: "EIO",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_ENOTEMPTY: XsdError = XsdError {
 | 
			
		||||
    num: libc::ENOTEMPTY,
 | 
			
		||||
    error: "ENOTEMPTY",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_ENOSYS: XsdError = XsdError {
 | 
			
		||||
    num: libc::ENOSYS,
 | 
			
		||||
    error: "ENOSYS",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EROFS: XsdError = XsdError {
 | 
			
		||||
    num: libc::EROFS,
 | 
			
		||||
    error: "EROFS",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EBUSY: XsdError = XsdError {
 | 
			
		||||
    num: libc::EBUSY,
 | 
			
		||||
    error: "EBUSY",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EAGAIN: XsdError = XsdError {
 | 
			
		||||
    num: libc::EAGAIN,
 | 
			
		||||
    error: "EAGAIN",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EISCONN: XsdError = XsdError {
 | 
			
		||||
    num: libc::EISCONN,
 | 
			
		||||
    error: "EISCONN",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_E2BIG: XsdError = XsdError {
 | 
			
		||||
    num: libc::E2BIG,
 | 
			
		||||
    error: "E2BIG",
 | 
			
		||||
};
 | 
			
		||||
pub const XSD_ERROR_EPERM: XsdError = XsdError {
 | 
			
		||||
    num: libc::EPERM,
 | 
			
		||||
    error: "EPERM",
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub const XSD_WATCH_PATH: u32 = 0;
 | 
			
		||||
pub const XSD_WATCH_TOKEN: u32 = 1;
 | 
			
		||||
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct XenDomainInterface {
 | 
			
		||||
    req: [i8; 1024],
 | 
			
		||||
    rsp: [i8; 1024],
 | 
			
		||||
    req_cons: u32,
 | 
			
		||||
    req_prod: u32,
 | 
			
		||||
    rsp_cons: u32,
 | 
			
		||||
    rsp_prod: u32,
 | 
			
		||||
    server_features: u32,
 | 
			
		||||
    connection: u32,
 | 
			
		||||
    error: u32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub const XS_PAYLOAD_MAX: u32 = 4096;
 | 
			
		||||
pub const XS_ABS_PATH_MAX: u32 = 3072;
 | 
			
		||||
pub const XS_REL_PATH_MAX: u32 = 2048;
 | 
			
		||||
pub const XS_SERVER_FEATURE_RECONNECTION: u32 = 1;
 | 
			
		||||
pub const XS_SERVER_FEATURE_ERROR: u32 = 2;
 | 
			
		||||
pub const XS_CONNECTED: u32 = 0;
 | 
			
		||||
pub const XS_RECONNECT: u32 = 1;
 | 
			
		||||
pub const XS_ERROR_NONE: u32 = 0;
 | 
			
		||||
pub const XS_ERROR_COMM: u32 = 1;
 | 
			
		||||
pub const XS_ERROR_RINGIDX: u32 = 2;
 | 
			
		||||
pub const XS_ERROR_PROTO: u32 = 3;
 | 
			
		||||
		Reference in New Issue
	
	Block a user