Skip to content
btrfs.rs 3.35 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 crate::config::errors;
use crate::config::trgt;
#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub enum Checksum {
    Crc32c,
    Xxhash,
    Sha256,
    Blake2,
}

#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub enum Profile {
    Raid0,
    Raid1,
    Raid1c3,
    Raid1c4,
    Raid5,
    Raid6,
    Raid10,
    Single,
    Dup,
}

#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub enum HasFeature {
    Enabled(Feature),
    Disable(Feature),
}

#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub enum Feature {
    MixedBg,
    Extrer,
    Raid56,
    SkinnyMetadata,
    NoHole,
    Raid1c34,
    Zoned,
}

#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub enum HasRuntimeFeature {
    Enabled(Feature),
    Disable(Feature),
}
#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub enum RuntimeFeatures {
    Quota,
    FreeSpaceTree,
}

#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub enum Options {
    ByteCount(u64),
    CheckSum(Checksum),
    Data(Profile),
    Metadata(Profile),
    Mixed,
    NodeSize(u16),
    SectorSize(u64),
    NoDiscard,
    RootDir(::std::path::PathBuf),
    Shrink,
    Features(Vec<HasFeature>),
    RuntimeFeatures(Vec<HasRuntimeFeature>),
    Force,
    Custom(String),
}

#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
Luker's avatar
Luker committed
#[allow(non_snake_case)]
Luker's avatar
Luker committed
pub struct BTRFS {
    id: String,
    label: Option<String>,
    UUID: Option<::uuid::Uuid>,
Luker's avatar
Luker committed
    #[serde(default)]
Luker's avatar
Luker committed
    options: Vec<Options>,
}

impl trgt::TargetCommon for BTRFS {
Luker's avatar
Luker committed
    fn id(&self) -> &str {
        self.id.as_str()
    }
Luker's avatar
Luker committed
    fn targets(&self) -> Vec<String> {
        Vec::new()
    }
Luker's avatar
Luker committed
}

impl super::FSTrait for BTRFS {
Luker's avatar
Luker committed
    fn create(&self) -> Result<(), ::std::io::Error> {
        Ok(())
    }
}

impl crate::config::CfgVerify for BTRFS {
    fn standardize(&mut self) {}
    fn check_consistency(
        &self,
        logger: &slog::Logger,
    ) -> Result<(), errors::ConfigError> {
        Ok(())
    }
}
Luker's avatar
Luker committed

impl PartialEq<BTRFS> for BTRFS {
    fn eq(&self, other: &Self) -> bool {
        match &self.label {
            Some(self_label) => match &other.label {
                Some(other_label) => {
                    if self_label != other_label {
                        return false;
                    }
                }
                _ => {}
            },
            _ => {}
        }
        // FIXME
        true
    }
}