{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-----------------------------------------------------------------------------
-- |
-- Module      : Data.EXT2.Integrity.Superblock
-- Copyright   : (C) 2015 Braden Walters,
--                   2015 Ricky Elrod
-- License     : MIT (see LICENSE file)
-- Maintainer  : Braden Walters <vc@braden-walters.info>,
--               Ricky Elrod <ricky@elrod.me>
-- Stability   : experimental
-- Portability : ghc
--
-- Functions for checking the integrity of 'Superblock's.
module Data.EXT2.Integrity.Superblock
( superblockMagicCheck
) where

import Data.EXT2.Info.Types
import Data.EXT2.Superblock

-- | Given a superblock ensure that its magic number is as-expected.
superblockMagicCheck :: Superblock -> IntegrityStatus EXT2Error
superblockMagicCheck (checkIdent -> Left e) = Inconsistent e
superblockMagicCheck _ = Consistent

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-----------------------------------------------------------------------------
-- |
-- Module      : Data.EXT2.Integrity.Superblock
-- Copyright   : (C) 2015 Braden Walters,
--                   2015 Ricky Elrod
-- License     : MIT (see LICENSE file)
-- Maintainer  : Braden Walters <vc@braden-walters.info>,
--               Ricky Elrod <ricky@elrod.me>
-- Stability   : experimental
-- Portability : ghc
--
-- Functions for checking the integrity of 'Superblock's.
module Data.EXT2.Integrity.Superblock
( superblockMagicCheck
, superblockConsistency
) where

import Data.EXT2.Info.Types
import Data.EXT2.Superblock

-- | Given a 'Superblock', ensure that its magic number is as-expected.
superblockMagicCheck :: Superblock -> IntegrityStatus EXT2Error
superblockMagicCheck (checkIdent -> Left e) = Inconsistent e
superblockMagicCheck _ = Consistent

-- | Ensure consistency of two 'Superblock's.
--
-- This is given for free by 'Superblock'\'s 'Eq' instance.
superblockConsistency :: Superblock -> Superblock -> IntegrityStatus EXT2Error
superblockConsistency x ((== x) -> True) = Consistent
superblockConsistency _ _ = Inconsistent InconsistentSuperblocks

Add a function for superblock consistency checking
Add a function for superblock consistency checking

@meoblast001 will hate my use of ViewPatterns here.

Signed-off-by: Ricky Elrod <3de8762d49a778edd8b1aa9f381ea5a9ccb62944@elrod.me>
