Skip to content
enums.rs 5.92 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/>.
 */

use strum_macros::Display;

#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Display)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
#[strum(serialize_all = "snake_case")]
pub enum Subsystem {
    // welp, I'm no kernel developer, but it looks like a subsystem is
    // something in '/sys/class' so here are them all on my system
    // nobody is probably going to use 99% of these, and we also have the
    // "custom" filter. It's just for future proofing
    AtaDevice,
    AtaLink,
    AtaPort,
    Backlight,
    Bdi,
    Block,
    Bluetooth,
    Bsg,
    CpuId,
    Dax,
    DevCoreDump,
    DevFreq,
    DevFreqEvent,
    DevLink,
    Dma,
    DmaHeap,
    Dmi,
    Drm,
    DrmDPAuxDev,
    Extcon,
    Graphics,
    HIDRaw,
    HwMon,
    I2CAdapter,
    I2CDev,
    Ieee80211,
    Input,
    IntelScuIpc,
    IOmmu,
    Leds,
    Lirc,
    Mei,
    Mem,
    Misc,
    Msr,
    Nd,
    Net,
    Nvme,
    NvmeGeneric,
    NvmeSubsystem,
    PciBus,
    Phy,
    PowerSupply,
    PowerCap,
    Pps,
    Ptp,
    Pwm,
    Rc,
    Regulator,
    RemoteProc,
    Rfkill,
    Rtc,
    ScsiDevice,
    ScsiDisk,
    ScsiGeneric,
    ScsiHost,
    Sound,
    SpiMaster,
    SpiSlave,
    Tee,
    Thermal,
    Tpm,
    TpmRm,
    Tty,
    UsbMisc,
    Vc,
    Video4Linux,
    VtConsole,
    WakeUp,
    Watchdog,
    WmiBus,
    Wwan,
    Custom(String),
}

impl Subsystem {
    pub fn to_str(&self) -> &str {
        match self {
            Subsystem::AtaDevice => "ata_device",
            Subsystem::AtaLink => "ata_link",
            Subsystem::AtaPort => "ata_port",
            Subsystem::Backlight => "backlight",
            Subsystem::Bdi => "bdi",
            Subsystem::Block => "block",
            Subsystem::Bluetooth => "bluetooth",
            Subsystem::Bsg => "bsg",
            Subsystem::CpuId => "cpuid",
            Subsystem::Dax => "dax",
            Subsystem::DevCoreDump => "devcoredump",
            Subsystem::DevFreq => "devfreq",
            Subsystem::DevFreqEvent => "devfreq-event",
            Subsystem::DevLink => "devLink",
            Subsystem::Dma => "dma",
            Subsystem::DmaHeap => "dma_heap",
            Subsystem::Dmi => "dmi",
            Subsystem::Drm => "drm",
            Subsystem::DrmDPAuxDev => "drm_dp_aux_dev",
            Subsystem::Extcon => "extcon",
            Subsystem::Graphics => "graphics",
            Subsystem::HIDRaw => "hidraw",
            Subsystem::HwMon => "hwmon",
            Subsystem::I2CAdapter => "i2x-adapter",
            Subsystem::I2CDev => "i2c-dev",
            Subsystem::Ieee80211 => "ieee80211",
            Subsystem::Input => "input",
            Subsystem::IntelScuIpc => "intel_scu_ipc",
            Subsystem::IOmmu => "iommu",
            Subsystem::Leds => "leds",
            Subsystem::Lirc => "lirc",
            Subsystem::Mei => "mei",
            Subsystem::Mem => "mem",
            Subsystem::Misc => "misc",
            Subsystem::Msr => "msr",
            Subsystem::Nd => "nd",
            Subsystem::Net => "net",
            Subsystem::Nvme => "nvme",
            Subsystem::NvmeGeneric => "nvme-generic",
            Subsystem::NvmeSubsystem => "nvme-subsystem",
            Subsystem::PciBus => "pci_bus",
            Subsystem::Phy => "phy",
            Subsystem::PowerSupply => "power_supply",
            Subsystem::PowerCap => "powercap",
            Subsystem::Pps => "pps",
            Subsystem::Ptp => "ptp",
            Subsystem::Pwm => "pwm",
            Subsystem::Rc => "rc",
            Subsystem::Regulator => "regulator",
            Subsystem::RemoteProc => "remoteproc",
            Subsystem::Rfkill => "rfkill",
            Subsystem::Rtc => "rtc",
            Subsystem::ScsiDevice => "scsidevice",
            Subsystem::ScsiDisk => "scsidisk",
            Subsystem::ScsiGeneric => "scsigeneric",
            Subsystem::ScsiHost => "scsihost",
            Subsystem::Sound => "sound",
            Subsystem::SpiMaster => "spi_master",
            Subsystem::SpiSlave => "spi_slave",
            Subsystem::Tee => "tee",
            Subsystem::Thermal => "thermal",
            Subsystem::Tpm => "tpm",
            Subsystem::TpmRm => "tpmrm",
            Subsystem::Tty => "tty",
            Subsystem::UsbMisc => "usbmisc",
            Subsystem::Vc => "vc",
            Subsystem::Video4Linux => "video4linux",
            Subsystem::VtConsole => "vtconsole",
            Subsystem::WakeUp => "wakeUp",
            Subsystem::Watchdog => "watchdog",
            Subsystem::WmiBus => "wmi_bus",
            Subsystem::Wwan => "wwan",
            Subsystem::Custom(s) => &s,
        }
    }
}
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Display)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
#[strum(serialize_all = "snake_case")]
pub enum DevType {
    // I have no idea where to get other possible values.
    // These are just some examples of what can be found taken from systemd
    // comments
    Disk,
    Partition,
    UsbDevice,
    ScsiDevice,
    Custom(String),
}

impl DevType {
    pub fn to_str(&self) -> &str {
        match self {
            DevType::Disk => "disk",
            DevType::Partition => "partition",
            DevType::UsbDevice => "usb_device",
            DevType::ScsiDevice => "scsi_device",
            DevType::Custom(s) => &s,
        }
    }
}