| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::{AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#}; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/, fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/}; |
| 5 | |
| 6 | use craterust-analyzer cargo udevrs 0.4.0 crate/::{Errorrust-analyzer cargo udevrs 0.4.0 error/Error#, Resultrust-analyzer cargo udevrs 0.4.0 error/Result#, Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#, UdevEntryrust-analyzer cargo udevrs 0.4.0 list/UdevEntry#, UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#}; |
| 7 | |
| 8 | mod linerust-analyzer cargo udevrs 0.4.0 hwdb/line/; |
| 9 | mod trierust-analyzer cargo udevrs 0.4.0 hwdb/trie/; |
| 10 | |
| 11 | pub use linerust-analyzer cargo udevrs 0.4.0 hwdb/line/::*; |
| 12 | pub use trierust-analyzer cargo udevrs 0.4.0 hwdb/trie/::*; |
| 13 | |
| 14 | static NODE_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/NODE_SIZE.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize# = AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]new().(24); |
| 15 | static CHILD_ENTRY_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/CHILD_ENTRY_SIZE.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize# = AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]new().(16); |
| 16 | static VALUE_ENTRY_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/VALUE_ENTRY_SIZE.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize# = AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]new().(32); |
| 17 | |
| 18 | /// Gets the [Node](TrieNode) size loaded from the [TrieHeader]. |
| 19 | pub fn node_sizerust-analyzer cargo udevrs 0.4.0 hwdb/node_size().() -> usize { |
| 20 | NODE_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/NODE_SIZE..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#) |
| 21 | } |
| 22 | |
| 23 | pub(craterust-analyzer cargo udevrs 0.4.0 crate/) fn set_node_sizerust-analyzer cargo udevrs 0.4.0 hwdb/set_node_size().(val: usize) { |
| 24 | NODE_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/NODE_SIZE..storerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]store().(val, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#); |
| 25 | } |
| 26 | |
| 27 | /// Gets the [ChildEntry](TrieChildEntry) size loaded from the [TrieHeader]. |
| 28 | pub fn child_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/child_entry_size().() -> usize { |
| 29 | CHILD_ENTRY_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/CHILD_ENTRY_SIZE..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#) |
| 30 | } |
| 31 | |
| 32 | pub(craterust-analyzer cargo udevrs 0.4.0 crate/) fn set_child_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/set_child_entry_size().(val: usize) { |
| 33 | CHILD_ENTRY_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/CHILD_ENTRY_SIZE..storerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]store().(val, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#); |
| 34 | } |
| 35 | |
| 36 | /// Gets the [ValueEntry](TrieValueEntry) size loaded from the [TrieHeader]. |
| 37 | pub fn value_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/value_entry_size().() -> usize { |
| 38 | VALUE_ENTRY_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/VALUE_ENTRY_SIZE..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#) |
| 39 | } |
| 40 | |
| 41 | pub(craterust-analyzer cargo udevrs 0.4.0 crate/) fn set_value_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/set_value_entry_size().(val: usize) { |
| 42 | VALUE_ENTRY_SIZErust-analyzer cargo udevrs 0.4.0 hwdb/VALUE_ENTRY_SIZE..storerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]store().(val, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#); |
| 43 | } |
| 44 | |
| 45 | #[cfg(target_os = "linux")] |
| 46 | const UDEV_LIBEXEC_DIRrust-analyzer cargo udevrs 0.4.0 hwdb/UDEV_LIBEXEC_DIR.: &str = "/usr/lib/udev"; |
| 47 | // FIXME: add udev libexec dirs for other OSes |
| 48 | |
| 49 | fn get_hwdb_bin_pathsrust-analyzer cargo udevrs 0.4.0 hwdb/get_hwdb_bin_paths().() -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 50 | const DEFAULT_LOCATIONSrust-analyzer cargo udevrs 0.4.0 hwdb/DEFAULT_LOCATIONS.: [&str; 2] = ["/etc/udev", UDEV_LIBEXEC_DIRrust-analyzer cargo udevrs 0.4.0 hwdb/UDEV_LIBEXEC_DIR.]; |
| 51 | |
| 52 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(by_env) = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("UDEV_HWDB_BIN") { |
| 53 | DEFAULT_LOCATIONSrust-analyzer cargo udevrs 0.4.0 hwdb/DEFAULT_LOCATIONS. |
| 54 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 55 | .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]fold().(by_env, |path, loc| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{path}\0{loc}/hwdb.bin")) |
| 56 | } else { |
| 57 | DEFAULT_LOCATIONSrust-analyzer cargo udevrs 0.4.0 hwdb/DEFAULT_LOCATIONS. |
| 58 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 59 | .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]fold().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(), |path, loc| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{path}\0{loc}/hwdb.bin")) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /// Represents the on-disk hardware database. |
| 64 | /// |
| 65 | /// Retrieves properties from the hardware database. |
| 66 | #[repr(C)] |
| 67 | pub struct UdevHwdbrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb# { |
| 68 | udevrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#udev.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#>, |
| 69 | bin_pathsrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#bin_paths.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 70 | hwdb_pathrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#hwdb_path.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 71 | headrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#head.: TrieHeaderrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/TrieHeader#, |
| 72 | properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#properties_list.: UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#, |
| 73 | } |
| 74 | |
| 75 | impl UdevHwdbrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb# { |
| 76 | /// Creates a new [UdevHwdb]. |
| 77 | pub fn newrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]new().(udev: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Udevrust-analyzer cargo udevrs 0.4.0 context/Udev#>) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<Selfrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]> { |
| 78 | let mut hwdb_path = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 79 | let bin_paths = get_hwdb_bin_pathsrust-analyzer cargo udevrs 0.4.0 hwdb/get_hwdb_bin_paths().(); |
| 80 | |
| 81 | let (head, metadata) = { |
| 82 | // In the original `libudev`, they `mmap` the entire on-disk database into a `const char *` |
| 83 | // union, which leads to inherently unsafe access in Rust. |
| 84 | // |
| 85 | // Instead, we'll just parse the header for now, which advances the `File` struct's internal |
| 86 | // cursor, and delay further parsing for subsequent calls to the various node entry, and value calls. |
| 87 | // |
| 88 | // Alternatively, we could parse the properties list now, and avoid keeping the file |
| 89 | // struct, file metadata, and `TrieHeader` in the `UdevHwdb` struct. Instead, we would just |
| 90 | // keep the parsed `properties_list`. |
| 91 | // |
| 92 | // TBD. |
| 93 | |
| 94 | let mut bin_file: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 95 | |
| 96 | for path in bin_paths.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\0') { |
| 97 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(f) = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().().readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true).openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(path) { |
| 98 | bin_file = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(f); |
| 99 | path.clone_intorust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]clone_into().(&mut hwdb_path); |
| 100 | break; |
| 101 | } |
| 102 | let errno = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().(); |
| 103 | if errno.raw_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]raw_os_error().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(libcrust-analyzer cargo libc 0.2.169 crate/::ENOENTrust-analyzer cargo libc 0.2.169 unix/linux_like/linux/ENOENT.) { |
| 104 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 105 | } else { |
| 106 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::UdevHwdbrust-analyzer cargo udevrs 0.4.0 error/Error#UdevHwdb#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 107 | "error reading {path}, errno: {errno}" |
| 108 | ))) |
| 109 | }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 110 | } |
| 111 | |
| 112 | let mut file = bin_file.ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::UdevHwdbrust-analyzer cargo udevrs 0.4.0 error/Error#UdevHwdb#( |
| 113 | "unable to find hwdb.bin database file".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 114 | ))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 115 | |
| 116 | let metadata = file.metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]metadata().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 117 | let mut hwdb_head_buf = [0u8; memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<TrieHeaderrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/TrieHeader#>()]; |
| 118 | |
| 119 | file.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut hwdb_head_buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 120 | |
| 121 | (TrieHeaderrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/TrieHeader#::try_fromrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader][`TryFrom<&[u8]>`]try_from().(hwdb_head_buf.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`AsRef<[T]>`]as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., metadata) |
| 122 | }; |
| 123 | |
| 124 | let properties_list = UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#::newrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]new().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&udev)); |
| 125 | |
| 126 | set_node_sizerust-analyzer cargo udevrs 0.4.0 hwdb/set_node_size().(head.node_sizerust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]node_size().() as usize); |
| 127 | set_child_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/set_child_entry_size().(head.child_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]child_entry_size().() as usize); |
| 128 | set_value_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/set_value_entry_size().(head.value_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]value_entry_size().() as usize); |
| 129 | |
| 130 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("=== trie on-disk ==="); |
| 131 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("tool version: {}", head.tool_versionrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]tool_version().()); |
| 132 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("file size: {:8} bytes", metadata.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]len().()); |
| 133 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("header size: {:8} bytes", head.header_sizerust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]header_size().()); |
| 134 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("node size: {:8} bytes", head.node_sizerust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]node_size().()); |
| 135 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("child size: {:8} bytes", head.child_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]child_entry_size().()); |
| 136 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("value size: {:8} bytes", head.value_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]value_entry_size().()); |
| 137 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("strings: {:8} bytes", head.strings_lenrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]strings_len().()); |
| 138 | logrust-analyzer cargo log 0.4.25 crate/::debugrust-analyzer cargo log 0.4.25 macros/debug!!("nodes: {:8} bytes", head.nodes_lenrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]nodes_len().()); |
| 139 | |
| 140 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb] { |
| 141 | udevrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#udev., |
| 142 | bin_pathsrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#bin_paths., |
| 143 | hwdb_pathrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#hwdb_path., |
| 144 | headrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#head., |
| 145 | properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#properties_list., |
| 146 | }) |
| 147 | } |
| 148 | |
| 149 | /// Gets a reference to the [TrieHeader]. |
| 150 | pub const fn headerrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]header().(&self) -> &TrieHeaderrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/TrieHeader# { |
| 151 | &self.headrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#head. |
| 152 | } |
| 153 | |
| 154 | /// Looks up a matching device in the hardware database. |
| 155 | /// |
| 156 | /// Parameters: |
| 157 | /// |
| 158 | /// - `modalias`: modalias string |
| 159 | /// - `flags`: (unused), preserved for easier mapping to `libudev` C API |
| 160 | /// |
| 161 | /// From the `libudev` documentation: |
| 162 | /// |
| 163 | /// ```no_build,no_run |
| 164 | /// The lookup key is a `modalias` string, whose formats are defined for the Linux kernel modules. |
| 165 | /// Examples are: pci:v00008086d00001C2D*, usb:v04F2pB221*. The first entry |
| 166 | /// of a list of retrieved properties is returned. |
| 167 | /// ``` |
| 168 | /// |
| 169 | /// Returns: an optional reference to an [UdevEntry]. |
| 170 | pub fn get_properties_list_entryrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]get_properties_list_entry().(&mut self, modalias: &str, _flags: u32) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&UdevEntryrust-analyzer cargo udevrs 0.4.0 list/UdevEntry#> { |
| 171 | // For now, do the naive thing, and read the entire HWDB into memory (12M+!!!) |
| 172 | // |
| 173 | // Using the BufReader to jump around to all the various offsets will probably be |
| 174 | // more efficient, but harder to follow. BufReader only supports relative `Seek`ing. |
| 175 | // |
| 176 | // Nodes are also not sequential in the on-disk format, which would make parsing |
| 177 | // easier, but lose some of the structure of the HWDB. According to the man page |
| 178 | // (`man 7 hwdb`), entries later in the HWDB have higher priority, which some tools |
| 179 | // may rely on. |
| 180 | // |
| 181 | // `libudev` does not appear to track priority. |
| 182 | // |
| 183 | // Loading everything into memory at one time also avoids some other tool updating the |
| 184 | // HWDB while we are parsing it. |
| 185 | let file = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().() |
| 186 | .readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true) |
| 187 | .openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(&self.hwdb_pathrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#hwdb_path.) |
| 188 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| { |
| 189 | logrust-analyzer cargo log 0.4.25 crate/::warnrust-analyzer cargo log 0.4.25 macros/warn!!("unable to open HWDB file: {err}"); |
| 190 | }) |
| 191 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 192 | |
| 193 | let metadata = file |
| 194 | .metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]metadata().() |
| 195 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| { |
| 196 | logrust-analyzer cargo log 0.4.25 crate/::warnrust-analyzer cargo log 0.4.25 macros/warn!!("unable to get HWDB metadata: {err}"); |
| 197 | }) |
| 198 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 199 | |
| 200 | let file_len = metadata.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]len().() as usize; |
| 201 | |
| 202 | let mut reader = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(file); |
| 203 | let mut hwdb_buf = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(file_len); |
| 204 | |
| 205 | reader |
| 206 | .read_to_endrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`][Read]read_to_end().(&mut hwdb_buf) |
| 207 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| { |
| 208 | logrust-analyzer cargo log 0.4.25 crate/::warnrust-analyzer cargo log 0.4.25 macros/warn!!("error reading HWDB into memory: {err}"); |
| 209 | }) |
| 210 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 211 | |
| 212 | self.properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#properties_list..clearrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]clear().(); |
| 213 | |
| 214 | Selfrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]::trie_searchrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]trie_search().(&mut self.properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#properties_list., &self.headrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#head., &hwdb_buf, modalias) |
| 215 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| { |
| 216 | logrust-analyzer cargo log 0.4.25 crate/::warnrust-analyzer cargo log 0.4.25 macros/warn!!("error looking up property list UdevEntry: {err}"); |
| 217 | }) |
| 218 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 219 | |
| 220 | self.properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#properties_list..entryrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]entry().() |
| 221 | } |
| 222 | |
| 223 | /// Looks up a matching device modalias in the hardware database and returns the list of properties. |
| 224 | pub fn queryrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]query().(&mut self, modalias: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#> { |
| 225 | self.get_properties_list_entryrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]get_properties_list_entry().(modalias, 0)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 226 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]properties_list().()) |
| 227 | } |
| 228 | |
| 229 | /// Gets a reference to the [properties list](UdevList). |
| 230 | pub const fn properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]properties_list().(&self) -> &UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList# { |
| 231 | &self.properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#properties_list. |
| 232 | } |
| 233 | |
| 234 | /// Adds a key-value pair to the property list. |
| 235 | pub fn add_propertyrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]add_property().(&mut self, key: &str, value: &str) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<()> { |
| 236 | Selfrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]::_add_propertyrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]_add_property().(&mut self.properties_listrust-analyzer cargo udevrs 0.4.0 hwdb/UdevHwdb#properties_list., key, value) |
| 237 | } |
| 238 | |
| 239 | pub(craterust-analyzer cargo udevrs 0.4.0 crate/) fn _add_propertyrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]_add_property().(list: &mut UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#, key: &str, value: &str) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<()> { |
| 240 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(nkey) = key.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().(' ') { |
| 241 | // TODO - should check priority if existing: https://github.com/systemd/systemd/blob/main/src/libsystemd/sd-hwdb/sd-hwdb.c#L134 |
| 242 | // add_entry if UdevList.unique (default) will replace currently |
| 243 | list.add_entryrust-analyzer cargo udevrs 0.4.0 list/impl#[UdevList]add_entry().(nkey, value) |
| 244 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|_| ()) |
| 245 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::UdevHwdbrust-analyzer cargo udevrs 0.4.0 error/Error#UdevHwdb#("unable to add property".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 246 | } else { |
| 247 | // Silently ignore all properties which do not start with a |
| 248 | // space; future extensions might use additional prefixes. |
| 249 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /// Parses all [TrieEntry] nodes from an in-memory HWDB buffer. |
| 254 | pub fn parse_nodesrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]parse_nodes().<'a>( |
| 255 | head: &'a TrieHeaderrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/TrieHeader#, |
| 256 | hwdb_buf: &'a [u8], |
| 257 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = TrieEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/TrieEntry#> + 'a { |
| 258 | let nodes_len = head.nodes_lenrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]nodes_len().() as usize; |
| 259 | let node_start = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<TrieHeaderrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/TrieHeader#>(); |
| 260 | let node_end = node_start.saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_add().(nodes_len); |
| 261 | |
| 262 | let buf_len = hwdb_buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 263 | |
| 264 | let mut idx = node_start; |
| 265 | |
| 266 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/from_fn/from_fn().(move || { |
| 267 | if (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#buf_len).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`]contains().(&node_start) |
| 268 | && (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#buf_len).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`]contains().(&node_end) |
| 269 | && idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().nodes_len |
| 270 | { |
| 271 | TrieEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/TrieEntry#::try_fromrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry][`TryFrom<&[u8]>`]try_from().(&hwdb_buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 272 | .inspectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]inspect().(|entry| { |
| 273 | idx = idx.saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_add().(entry.lenrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry]len().()); |
| 274 | }) |
| 275 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| { |
| 276 | logrust-analyzer cargo log 0.4.25 crate/::errorrust-analyzer cargo log 0.4.25 macros/error!!("Error parsing TrieEntry: {err}"); |
| 277 | }) |
| 278 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 279 | } else { |
| 280 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 281 | } |
| 282 | }) |
| 283 | } |
| 284 | |
| 285 | fn trie_searchrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]trie_search().( |
| 286 | list: &mut UdevListrust-analyzer cargo udevrs 0.4.0 list/UdevList#, |
| 287 | head: &TrieHeaderrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/TrieHeader#, |
| 288 | hwdb_buf: &[u8], |
| 289 | search: &str, |
| 290 | ) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<()> { |
| 291 | let mut line_buf = LineBufrust-analyzer cargo udevrs 0.4.0 hwdb/line/LineBuf#::newrust-analyzer cargo udevrs 0.4.0 hwdb/line/impl#[LineBuf]new().(); |
| 292 | let mut i = 0usize; |
| 293 | let nodes_root_off = head.nodes_root_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/header/impl#[TrieHeader]nodes_root_off().() as usize; |
| 294 | |
| 295 | let mut node = if nodes_root_off rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().hwdb_buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 296 | TrieEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/TrieEntry#::try_fromrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry][`TryFrom<&[u8]>`]try_from().(&hwdb_buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().nodes_root_off..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 297 | } else { |
| 298 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 299 | }; |
| 300 | |
| 301 | logrust-analyzer cargo log 0.4.25 crate/::tracerust-analyzer cargo log 0.4.25 macros/trace!!("Search term: {search}"); |
| 302 | |
| 303 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) = node { |
| 304 | if n.noderust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry]node().().prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]prefix_off().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().0 { |
| 305 | let prefix_off = n.noderust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry]node().().prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]prefix_off().() as usize; |
| 306 | let ts = trie_stringrust-analyzer cargo udevrs 0.4.0 hwdb/trie/trie_string().(hwdb_buf, prefix_off)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 307 | |
| 308 | for (p, c) in ts.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 309 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'*' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'?' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'[' { |
| 310 | return line_buf.trie_fnmatchrust-analyzer cargo udevrs 0.4.0 hwdb/line/impl#[LineBuf]trie_fnmatch().(list, hwdb_buf, &n, p, &search[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().p..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 311 | } |
| 312 | |
| 313 | if search.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().p) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) { |
| 314 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | i = i.saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_add().(ts.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]count().()); |
| 319 | } |
| 320 | |
| 321 | for wildcard in [b'*', b'?', b'['] { |
| 322 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(child) = n.lookup_childrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry]lookup_child().(hwdb_buf, wildcard) { |
| 323 | line_buf.add_charrust-analyzer cargo udevrs 0.4.0 hwdb/line/impl#[LineBuf]add_char().(wildcard)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 324 | logrust-analyzer cargo log 0.4.25 crate/::tracerust-analyzer cargo log 0.4.25 macros/trace!!("wildcard ({wildcard:?}) child match: child: {child:?}"); |
| 325 | line_buf.trie_fnmatchrust-analyzer cargo udevrs 0.4.0 hwdb/line/impl#[LineBuf]trie_fnmatch().(list, hwdb_buf, &child, 0, &search[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 326 | line_buf.remove_charrust-analyzer cargo udevrs 0.4.0 hwdb/line/impl#[LineBuf]remove_char().(); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | if search.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(i) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('\0') { |
| 331 | for value in n.valuesrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry]values().().iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 332 | let key_str = trie_stringrust-analyzer cargo udevrs 0.4.0 hwdb/trie/trie_string().(hwdb_buf, value.key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]key_off().() as usize)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 333 | let val_str = trie_stringrust-analyzer cargo udevrs 0.4.0 hwdb/trie/trie_string().(hwdb_buf, value.value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]value_off().() as usize)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 334 | |
| 335 | logrust-analyzer cargo log 0.4.25 crate/::tracerust-analyzer cargo log 0.4.25 macros/trace!!("Matching property, key: {key_str}, value: {val_str}"); |
| 336 | Selfrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]::_add_propertyrust-analyzer cargo udevrs 0.4.0 hwdb/impl#[UdevHwdb]_add_property().(list, key_str, val_str)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | node = n.lookup_childrust-analyzer cargo udevrs 0.4.0 hwdb/trie/entry/impl#[TrieEntry]lookup_child().(hwdb_buf, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().search.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(i).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&0)); |
| 341 | i = i.saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_add().(1); |
| 342 | logrust-analyzer cargo log 0.4.25 crate/::tracerust-analyzer cargo log 0.4.25 macros/trace!!("No match found, searching next child[{i}]: {node:?}"); |
| 343 | } |
| 344 | |
| 345 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 346 | } |
| 347 | } |