Skip to content

Commit

Permalink
chore: Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Mar 2, 2021
1 parent 9cfacd4 commit 05d9649
Show file tree
Hide file tree
Showing 34 changed files with 2,628 additions and 756 deletions.
1,489 changes: 772 additions & 717 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ edition = "2018"
[workspace]
members = [
"cli",
"ffi",
"crates/bootloader",
"crates/chroot",
"crates/disks",
"crates/disk-ops",
"crates/disk-types",
"crates/external",
"crates/fstab-generate",
"crates/hardware",
"crates/locales",
"crates/os-detect",
"crates/squashfs",
"crates/timezones",
"crates/utils",
"ffi",
]

[lib]
Expand All @@ -37,9 +40,9 @@ crate-type = ["lib"]
pbr = "1.0.2"

[dependencies]
cascade = "0.1.4"
dirs = "2.0.2"
disk-types = "=0.1.2"
cascade = "1.0"
dirs = "3.0"
disk-types = { path = "crates/disk-types"}
distinst-bootloader = { path = "crates/bootloader" }
distinst-chroot = { path = "crates/chroot" }
distinst-disks = { path = "crates/disks" }
Expand All @@ -51,22 +54,22 @@ distinst-timezones = { path = "crates/timezones" }
distinst-utils = { path = "crates/utils" }
envfile = "0.2.1"
fern = "0.6.0"
fstab-generate = "0.1.2"
fstab-generate = { path = "crates/fstab-generate" }
hostname-validator = "1.0.0"
itertools = "0.9.0"
itertools = "0.10.0"
libc = "0.2.68"
libparted = "0.1.4"
log = "0.4.8"
logind-dbus = "0.1.1"
os-detect = "0.2.2"
os-detect = { path = "crates/os-detect" }
os-release = "0.1.0"
partition-identity = "0.2.8"
proc-mounts = "0.2.4"
rayon = "1.3.0"
sys-mount = "1.2.1"
tempdir = "0.3.7"
bitflags = "1.2.1"
err-derive = "0.2.4"
err-derive = "0.3"
apt-cli-wrappers = { git = "https://github.com/pop-os/apt-cli-wrappers" }
systemd-boot-conf = "0.2.1"
derive_more = "0.99.5"
Expand Down
2 changes: 1 addition & 1 deletion crates/chroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ edition = "2018"

[dependencies]
sys-mount = "1.2.1"
cascade = "0.1.4"
cascade = "1.0"
log = "0.4.8"
libc = "0.2.68"
2 changes: 1 addition & 1 deletion crates/disk-ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2018"
[dependencies]
distinst-bootloader = { path = "../bootloader" }
derive-new = "0.5.8"
disk-types = "=0.1.2"
disk-types = { path = "../disk-types" }
distinst-external-commands = { path = "../external" }
log = "0.4.8"
tempdir = "0.3.7"
Expand Down
19 changes: 19 additions & 0 deletions crates/disk-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "disk-types"
version = "0.1.5"
authors = ["Jeremy Soller <[email protected]>", "Michael Aaron Murphy <[email protected]>"]
description = "Common traits and types for handling block devices, partitions, file systems, etc."
repository = "https://github.com/pop-os/disk-types"
readme = "README.md"
license = "MIT"
keywords = ["disk", "partition"]
categories = ["filesystem", "os"]
edition = "2018"

[dependencies]
sys-mount = "1.2.1"
tempdir = "0.3.7"
os-detect = { path = "../os-detect" }
sysfs-class = "0.1.2"
libparted = "0.1.4"
err-derive = "0.3"
44 changes: 44 additions & 0 deletions crates/disk-types/src/bootloader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Detect whether a Linux system is in EFI or BIOS mode.
//!
//! ```rust,no_run
//! use distinst_bootloader::Bootloader;
//!
//! match Bootloader::detect() {
//! Bootloader::Efi => println!("System is in EFI mode"),
//! Bootloader::Bios => println!("System is in BIOS mode")
//! }
//! ```
use std::path::Path;
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};

/// Force the installation to perform either a BIOS or EFI installation.
pub static FORCE_BOOTLOADER: AtomicUsize = ATOMIC_USIZE_INIT;

/// Bootloader type
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Bootloader {
Bios,
Efi,
}

impl Bootloader {
/// Detects whether the system is running from EFI.
pub fn detect() -> Bootloader {
match FORCE_BOOTLOADER.load(Ordering::SeqCst) {
1 => {
return Bootloader::Bios;
}
2 => {
return Bootloader::Efi;
}
_ => ()
}

if Path::new("/sys/firmware/efi").is_dir() {
Bootloader::Efi
} else {
Bootloader::Bios
}
}
}
16 changes: 16 additions & 0 deletions crates/disk-types/src/checker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::fs::FileSystem;
use std::io;
use std::path::Path;
use std::process::{Command, ExitStatus, Stdio};

pub trait Fscker {
fn fsck(path: &Path, fs: FileSystem) -> Result<(), FsckError>;
}

#[derive(Debug, Error)]
pub enum FsckError {
#[error(display = "fsck I/O error: {:?}", _0)]
Io(io::Error),
#[error(display = "command failed with exit status: {}", _0)]
BadStatus(ExitStatus),
}
116 changes: 116 additions & 0 deletions crates/disk-types/src/device.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use std::{
cell::RefCell,
fmt::Debug,
fs::File,
io::{self, Read},
path::{Path, PathBuf},
str::FromStr,
};
use sysfs_class::{Block, SysClass};

/// Methods that all block devices share, whether they are partitions or disks.
///
/// This trait is required to implement other disk traits.
pub trait BlockDeviceExt {
/// The sys path of the block device.
fn sys_block_path(&self) -> PathBuf { sys_block_path(self.get_device_name(), "") }

fn is_partition(&self) -> bool {
sys_block_path(self.get_device_name(), "partition").exists()
}

/// Checks if the device is a read-only device.
fn is_read_only(&self) -> bool {
Block::from_path(&self.sys_block_path())
.ok()
.map_or(false, |block| block.ro().ok() == Some(1))
}

/// Checks if the device is a removable device.
///
/// # Notes
/// This is only applicable for disk devices.
fn is_removable(&self) -> bool {
Block::from_path(&self.sys_block_path())
.ok()
.map_or(false, |block| block.removable().ok() == Some(1))
}

/// Checks if the device is a rotational device.
///
/// # Notes
/// This is only applicable for disk devices.
fn is_rotational(&self) -> bool {
Block::from_path(&self.sys_block_path())
.ok()
.map_or(false, |block| block.queue_rotational().ok() == Some(1))
}

/// The path to the block device, such as `/dev/sda1`, or `/dev/data/root`.
fn get_device_path(&self) -> &Path;

/// The mount point of this block device, if it is mounted.
fn get_mount_point(&self) -> Option<&Path> { None }

/// The name of the device, such as `sda1`.
fn get_device_name(&self) -> &str {
self.get_device_path()
.file_name()
.expect("BlockDeviceExt::get_device_path missing file_name")
.to_str()
.expect("BlockDeviceExt::get_device_path invalid file_name")
}

/// The combined total number of sectors on the disk.
fn get_sectors(&self) -> u64 {
let size_file = sys_block_path(self.get_device_name(), "/size");
read_file::<u64>(&size_file).expect("no sector count found")
}

/// The size of each logical sector, in bytes.
fn get_logical_block_size(&self) -> u64 {
eprintln!("get block size for {:?}", self.sys_block_path());

let block = Block::from_path(&self.sys_block_path())
.expect("device lacks block");

match block.queue_logical_block_size() {
Ok(size) => return size,
Err(_) => {
return Block::from_path(&self.sys_block_path())
.expect("partition does not have a block device")
.parent_device()
.expect("partition lacks parent block device")
.queue_logical_block_size()
.expect("parent of partition lacks logical block size");
}
}
}

/// The size of each logical sector, in bytes.
fn get_physical_block_size(&self) -> u64 {
let path = sys_block_path(self.get_device_name(), "/queue/physical_block_size");
read_file::<u64>(&path).expect("physical block size not found")
}
}

fn sys_block_path(name: &str, ppath: &str) -> PathBuf {
PathBuf::from(["/sys/class/block/", name, ppath].concat())
}

thread_local! {
static BUFFER: RefCell<String> = String::with_capacity(256).into();
}

fn read_file<T: FromStr>(path: &Path) -> io::Result<T>
where
<T as FromStr>::Err: Debug,
{
BUFFER.with(|buffer| {
let mut buffer = buffer.borrow_mut();
File::open(path)?.read_to_string(&mut buffer)?;
let value = buffer.trim().parse::<T>();
buffer.clear();
value.map_err(|why| io::Error::new(io::ErrorKind::Other, format!("{:?}", why)))
})
}
Loading

0 comments on commit 05d9649

Please sign in to comment.