Skip to content

Commit

Permalink
installer: Add boot + system partition differentiation
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Jun 21, 2024
1 parent fdba2bc commit fc7ebf8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
47 changes: 46 additions & 1 deletion crates/installer/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use system::{
};
use thiserror::Error;

use crate::Model;
use crate::{BootPartition, Model, SystemPartition};

#[derive(Debug, Error)]
pub enum Error {
Expand All @@ -32,20 +32,65 @@ pub struct Installer<'a> {

/// All known/useful disks
disks: Vec<Disk>,

/// Boot partitions
boot_parts: Vec<BootPartition>,

/// System partitions
system_parts: Vec<SystemPartition>,
}

impl<'a> Installer<'a> {
/// Return a newly initialised installer
pub fn new() -> Result<Self, Error> {
let locale_registry = locale::Registry::new()?;
let disks = Disk::discover()?;

let mut boot_parts = vec![];
let mut system_parts = vec![];
for disk in disks.iter() {
if let Ok(parts) = disk.partitions() {
if let Some(esp) = parts
.iter()
.find(|p| matches!(p.kind, disk::PartitionKind::ESP))
.cloned()
{
let xbootldr = parts
.iter()
.find(|p| matches!(p.kind, disk::PartitionKind::XBOOTLDR))
.cloned();
boot_parts.push(BootPartition { esp, xbootldr })
}
let others = parts
.iter()
.filter(|p| matches!(p.kind, disk::PartitionKind::Regular))
.cloned();
system_parts.extend(others.map(|p| SystemPartition {
partition: p,
mountpoint: None,
}));
}
}

Ok(Self {
locale_registry,
locales: Vec::new(),
disks,
system_parts,
boot_parts,
})
}

/// Return references to the discovered boot partitions
pub fn boot_partitions(&self) -> &[BootPartition] {
&self.boot_parts
}

/// Return references to the discovered system partitions
pub fn system_partitions(&self) -> &[SystemPartition] {
&self.system_parts
}

/// build the model into a set of install steps
pub fn compile_to_steps(&self, _model: &Model) -> Result<(), Error> {
todo!("dont know how")
Expand Down
3 changes: 3 additions & 0 deletions crates/installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ pub use account::Account;

mod engine;
pub use engine::Installer;

mod partitions;
pub use partitions::{BootPartition, SystemPartition};
10 changes: 8 additions & 2 deletions crates/installer/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

use std::collections::BTreeSet;

use crate::Account;
use crate::{Account, BootPartition, SystemPartition};

/// Core model for the installation target
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct Model {
/// All accounts in the system.
pub accounts: BTreeSet<Account>,

/// The boot partition to use
pub boot_partition: BootPartition,

/// The system partitions to use/mount
pub partitions: Vec<SystemPartition>,
}
36 changes: 36 additions & 0 deletions crates/installer/src/partitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: Copyright © 2024 Serpent OS Developers
//
// SPDX-License-Identifier: MPL-2.0

//! A higher abstraction over partitions for the purposes of
//! installer usage.
//! Quite simply we only care about the difference in a regular
//! partition, and a boot partition.
use system::disk;

/// A boot partition is an EFI System Partition which may or may
/// not be paired with an `XBOOTLDR` partition, relative to its location
/// on the same GPT disk.
/// This is a requirement per the Boot Loader Specification.
#[derive(Debug)]
pub struct BootPartition {
pub(crate) esp: disk::Partition,
pub(crate) xbootldr: Option<disk::Partition>,
}

/// A system partition is simply a regular partition with a specified mountpoint
/// within the root.
#[derive(Debug)]
pub struct SystemPartition {
pub(crate) partition: disk::Partition,

/// Where will it be mounted
pub(crate) mountpoint: Option<String>,
}

impl AsRef<disk::Partition> for SystemPartition {
fn as_ref(&self) -> &disk::Partition {
&self.partition
}
}

0 comments on commit fc7ebf8

Please sign in to comment.