#[cfg(feature = "serde1")] use serde::{Deserialize, Serialize};
/// Device entries under `/proc/devices` #[derive(Debug, Clone)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pubstruct Devices { /// Character devices pub char_devices: Vec<CharDeviceEntry>, /// Block devices, which can be empty if the kernel doesn't support block devices (without `CONFIG_BLOCK`) pub block_devices: Vec<BlockDeviceEntry>,
}
/// A charcter device entry under `/proc/devices` #[derive(Debug, Clone)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pubstruct CharDeviceEntry { /// Device major number pub major: u32, /// Device name pub name: String,
}
/// A block device entry under `/proc/devices` #[derive(Debug, Clone)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pubstruct BlockDeviceEntry { /// Device major number pub major: i32, /// Device name pub name: String,
}
implsuper::FromBufRead for Devices { fn from_buf_read<R: BufRead>(r: R) -> ProcResult<Self> { enum State {
Char,
Block,
} letmut state = State::Char; // Always start with char devices letmut devices = Devices {
char_devices: vec![],
block_devices: vec![],
};
for line in r.lines() { let line = expect!(line);
if line.is_empty() { continue;
} elseif line.starts_with("Character devices:") {
state = State::Char; continue;
} elseif line.starts_with("Block devices:") {
state = State::Block; continue;
}
letmut s = line.split_whitespace();
match state {
State::Char => { let major = expect!(u32::from_str(expect!(s.next()))); let name = expect!(s.next()).to_string();
let char_device_entry = CharDeviceEntry { major, name };
devices.char_devices.push(char_device_entry);
}
State::Block => { let major = expect!(i32::from_str(expect!(s.next()))); let name = expect!(s.next()).to_string();
let block_device_entry = BlockDeviceEntry { major, name };
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.