use std::fs;
use crate::{murmur_hash2, Error, Result, Udev};
pub(crate) const LINE_SIZE: usize = 16384;
mod device_nodes;
pub use device_nodes::*;
impl Udev {
pub(crate) fn get_sys_core_link_value(slink: &str, syspath: &str) -> Result<String> {
let path = format!("{syspath}/{slink}");
let link = fs::read_link(path)?;
Ok(link
.components()
.next_back()
.ok_or(Error::io_other("empty sys core link value"))?
.as_os_str()
.to_str()
.ok_or(Error::io_other(
"sys core link OS string contains non-Unicode bytes",
))?
.to_owned())
}
}
pub fn string_hash32(s: &str) -> u32 {
murmur_hash2(s.as_bytes(), 0)
}
pub fn string_bloom64(s: &str) -> u64 {
let hash = string_hash32(s);
(1u64 << (hash & 63))
| (1u64 << ((hash >> 6) & 63))
| (1u64 << ((hash >> 12) & 63))
| (1u64 << ((hash >> 18) & 63))
}
pub fn major(dev: libc::dev_t) -> u16 {
(((dev >> 31 >> 1) & 0xfffff000) | ((dev >> 8) & 0x00000fff)) as u16
}
pub fn minor(dev: libc::dev_t) -> u16 {
(((dev >> 12) & 0xffffff00) | (dev & 0x000000ff)) as u16
}
pub fn encode_string(arg: &str) -> Result<String> {
encode_devnode_name(arg)
}