|
1 | 1 | use std::collections::HashMap;
|
2 | 2 | use std::env;
|
3 |
| -use std::fs::File; |
4 |
| -use std::os::unix::io::AsRawFd; |
5 | 3 | use std::path::Path;
|
6 | 4 | use std::process::Command;
|
7 | 5 | use std::sync::OnceLock;
|
8 | 6 |
|
9 | 7 | use anyhow::{anyhow, Context, Result};
|
10 | 8 | use camino::{Utf8Path, Utf8PathBuf};
|
11 | 9 | use fn_error_context::context;
|
12 |
| -use nix::errno::Errno; |
13 | 10 | use regex::Regex;
|
14 | 11 | use serde::Deserialize;
|
15 | 12 |
|
@@ -270,30 +267,6 @@ pub(crate) fn udev_settle() -> Result<()> {
|
270 | 267 | Ok(())
|
271 | 268 | }
|
272 | 269 |
|
273 |
| -#[allow(unsafe_code)] |
274 |
| -pub(crate) fn reread_partition_table(file: &mut File, retry: bool) -> Result<()> { |
275 |
| - let fd = file.as_raw_fd(); |
276 |
| - // Reread sometimes fails inexplicably. Retry several times before |
277 |
| - // giving up. |
278 |
| - let max_tries = if retry { 20 } else { 1 }; |
279 |
| - for retries in (0..max_tries).rev() { |
280 |
| - let result = unsafe { ioctl::blkrrpart(fd) }; |
281 |
| - match result { |
282 |
| - Ok(_) => break, |
283 |
| - Err(err) if retries == 0 && err == Errno::EINVAL => { |
284 |
| - return Err(err) |
285 |
| - .context("couldn't reread partition table: device may not support partitions") |
286 |
| - } |
287 |
| - Err(err) if retries == 0 && err == Errno::EBUSY => { |
288 |
| - return Err(err).context("couldn't reread partition table: device is in use") |
289 |
| - } |
290 |
| - Err(err) if retries == 0 => return Err(err).context("couldn't reread partition table"), |
291 |
| - Err(_) => std::thread::sleep(std::time::Duration::from_millis(100)), |
292 |
| - } |
293 |
| - } |
294 |
| - Ok(()) |
295 |
| -} |
296 |
| - |
297 | 270 | /// Parse key-value pairs from lsblk --pairs.
|
298 | 271 | /// Newer versions of lsblk support JSON but the one in CentOS 7 doesn't.
|
299 | 272 | fn split_lsblk_line(line: &str) -> HashMap<String, String> {
|
@@ -340,16 +313,6 @@ pub(crate) fn find_parent_devices(device: &str) -> Result<Vec<String>> {
|
340 | 313 | Ok(parents)
|
341 | 314 | }
|
342 | 315 |
|
343 |
| -// create unsafe ioctl wrappers |
344 |
| -#[allow(clippy::missing_safety_doc)] |
345 |
| -mod ioctl { |
346 |
| - use libc::c_int; |
347 |
| - use nix::{ioctl_none, ioctl_read, ioctl_read_bad, libc, request_code_none}; |
348 |
| - ioctl_none!(blkrrpart, 0x12, 95); |
349 |
| - ioctl_read_bad!(blksszget, request_code_none!(0x12, 104), c_int); |
350 |
| - ioctl_read!(blkgetsize64, 0x12, 114, libc::size_t); |
351 |
| -} |
352 |
| - |
353 | 316 | /// Parse a string into mibibytes
|
354 | 317 | pub(crate) fn parse_size_mib(mut s: &str) -> Result<u64> {
|
355 | 318 | let suffixes = [
|
|
0 commit comments