On Linux read the ESRT table from the sysfs resource_version and resource_count_max are reported by sysfs, so they're defaulted to reaesonable values capsule_flags in sysfs seems to be 0 always. Not sure why.
(dir: &Path)
| 393 | /// resource_version and resource_count_max are reported by sysfs, so they're defaulted to reaesonable values |
| 394 | /// capsule_flags in sysfs seems to be 0 always. Not sure why. |
| 395 | fn esrt_from_sysfs(dir: &Path) -> io::Result<Esrt> { |
| 396 | let mut esrt_table = Esrt { |
| 397 | resource_count: 0, |
| 398 | resource_count_max: 0, |
| 399 | resource_version: ESRT_FIRMWARE_RESOURCE_VERSION, |
| 400 | entries: vec![], |
| 401 | }; |
| 402 | if dir.is_dir() { |
| 403 | for esrt_entry in fs::read_dir(dir)? { |
| 404 | let esrt_entry = esrt_entry?; |
| 405 | let path = esrt_entry.path(); |
| 406 | if path.is_dir() { |
| 407 | let fw_class = fs::read_to_string(path.join("fw_class"))?; |
| 408 | let fw_type = fs::read_to_string(path.join("fw_type"))?; |
| 409 | let fw_version = fs::read_to_string(path.join("fw_version"))?; |
| 410 | let lowest_supported_fw_version = |
| 411 | fs::read_to_string(path.join("lowest_supported_fw_version"))?; |
| 412 | let raw_capsule_flags = fs::read_to_string(path.join("capsule_flags"))?; |
| 413 | let capsule_flags = raw_capsule_flags.trim_start_matches("0x"); |
| 414 | let last_attempt_version = fs::read_to_string(path.join("last_attempt_version"))?; |
| 415 | let last_attempt_status = fs::read_to_string(path.join("last_attempt_status"))?; |
| 416 | let esrt = EsrtResourceEntry { |
| 417 | fw_class: CGuid::from( |
| 418 | GUID::parse(fw_class.trim()).expect("Kernel provided wrong value"), |
| 419 | ), |
| 420 | fw_type: fw_type |
| 421 | .trim() |
| 422 | .parse::<u32>() |
| 423 | .expect("Kernel provided wrong value"), |
| 424 | fw_version: fw_version |
| 425 | .trim() |
| 426 | .parse::<u32>() |
| 427 | .expect("Kernel provided wrong value"), |
| 428 | lowest_supported_fw_version: lowest_supported_fw_version |
| 429 | .trim() |
| 430 | .parse::<u32>() |
| 431 | .expect("Kernel provided wrong value"), |
| 432 | // TODO: Flags seem to be 0 always |
| 433 | capsule_flags: u32::from_str_radix(capsule_flags.trim(), 16) |
| 434 | .expect("Kernel provided wrong value"), |
| 435 | last_attempt_version: last_attempt_version |
| 436 | .trim() |
| 437 | .parse::<u32>() |
| 438 | .expect("Kernel provided wrong value"), // UpdateStatus |
| 439 | last_attempt_status: last_attempt_status |
| 440 | .trim() |
| 441 | .parse::<u32>() |
| 442 | .expect("Kernel provided wrong value"), |
| 443 | }; |
| 444 | esrt_table.resource_count += 1; |
| 445 | esrt_table.resource_count_max += 1; |
| 446 | esrt_table.entries.push(esrt); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | Ok(esrt_table) |
| 451 | } |
| 452 |