Skip to content
part_type.rs 30 KiB
Newer Older
Luker's avatar
Luker committed
/*
 * Copyright (c) 2021, Luca Fulchir <luker@fenrirproject.org>
 *
 * This file is part of dfim.
 *
 * dfim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dfim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dfim.  If not, see <https://www.gnu.org/licenses/>.
 */

macro_rules! partition_ids {
    (
        $(
            ($gptfdisk:expr, $uuid:expr, $desc:expr, $name:ident)$(,)*
        )+
    )
    => {
Luker's avatar
Luker committed
        #[derive(::serde::Deserialize, ::serde::Serialize, Clone, Copy, Debug,PartialEq)]
        #[serde(deny_unknown_fields)]
        pub enum PartType {
            $($name,)+
        }
        impl PartType {
            pub fn default_label(&self) -> String {
                match self {
                    $(PartType::$name => $desc.to_owned(),)+
                }
Luker's avatar
Luker committed
            }
        }
        impl From<PartType> for ::uuid::Uuid {
            fn from(p: PartType) -> ::uuid::Uuid {
                match p {
Luker's avatar
Luker committed
                    $(PartType::$name => ::uuid::Uuid::parse_str($uuid).unwrap(),)+
Luker's avatar
Luker committed
            }
        }
        impl TryFrom<u16> for PartType {
            type Error = &'static str;
            fn try_from(value: u16) -> Result<Self, Self::Error> {
                match value {
                    $($gptfdisk => Ok(PartType::$name),)+
                    _ => Err("can't translate gptfdisk hex to uuid"),
                }
            }
Luker's avatar
Luker committed
        }
Luker's avatar
Luker committed
}
/* These partition IDs/UUIDs are taken from
 * GPTFDISK source. report bugs there if you find them
 * here.
 * do not add new partitions if not supported from gptfdisk
 */
partition_ids!(
    (
        0x0000,
        "00000000-0000-0000-0000-000000000000",
        "Unused entry",
        Unused
    ),
    (
        0x0100,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft Basic Data",
        MicrosoftBasicData
    ),
    (
        0x0400,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        Fat16Less32M
    ),
    (
        0x0600,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        FAT16
    ),
    (
        0x0700,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        NTFSorHPFS
    ),
    (
        0x0701,
        "558D43C5-A1AC-43C0-AAC8-D1472B2923D1",
        "Microsoft Storage Replica",
        MicrosoftStorageReplica
    ),
    (
        0x0702,
        "90B6FF38-B98F-4358-A21F-48F35B4A8AD3",
        "ArcaOS Type 1",
        ArcaOSType1
    ),
    (
        0x0b00,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        Fat32
    ),
    (
        0x0c00,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        Fat32LBA
    ),
    (
        0x0c01,
        "E3C9E316-0B5C-4DB8-817D-F92DF00215AE",
        "Microsoft reserved",
        MicrosoftReserved
    ),
    (
        0x0e00,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        Fat16LBA
    ),
    (
        0x1100,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        HiddenFAT12
    ),
    (
        0x1400,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        HiddenFAT16less32M
    ),
    (
        0x1600,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        HiddenFAT16
    ),
    (
        0x1700,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        HiddenNTFSorHPFS
    ),
    (
        0x1b00,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        HiddenFAT32
    ),
    (
        0x1c00,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        HiddenFAT32LBA
    ),
    (
        0x1e00,
        "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
        "Microsoft basic data",
        HiddenFAT16LBA
    ),
    (
        0x2700,
        "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC",
        "Windows RE",
        WindowsRe
    ),
    (
        0x3000,
        "7412F7D5-A156-4B13-81DC-867174929325",
        "ONIE boot",
        OnieBoot
    ),
    (
        0x3001,
        "D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149",
        "ONIE config",
        OnieConfig
    ),
    (
        0x3900,
        "C91818F9-8025-47AF-89D2-F030D7000C2C",
        "Plan 9",
        Plan9
    ),
    (
        0x4100,
        "9E1A2D38-C612-4316-AA26-8B49521E5A8B",
        "PowerPC PReP boot",
        PowerPcPRePBoot
    ),
Loading full blame...