Skip to content

Commit 95f6edc

Browse files
committed
SuperBlock data modification functions
1 parent 5a780d3 commit 95f6edc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

System/TPFS/SuperBlock.hs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module System.TPFS.SuperBlock (
2+
module System.TPFS.SolidArray,
3+
SuperBlockState(..),
4+
bitsToSBStates,
5+
sbStatesToBits
6+
) where
7+
8+
import Control.Applicative
9+
import qualified Data.ByteString.Lazy as B
10+
import System.TPFS.Address
11+
import System.TPFS.Bitmap
12+
import System.TPFS.SolidArray
13+
14+
data SuperBlockState = SBEmpty
15+
| SBSpaceAvailable
16+
| SBFull
17+
deriving (Show, Read, Eq)
18+
19+
instance SolidArray SuperBlockState where
20+
arrRead h a (s,e) = bitsToSBStates <$> arrRead h a (s*2,e*2+1)
21+
arrWrite h a o = arrWrite h a (o*2) . sbStatesToBits
22+
23+
-- | Converts a list of bits into the equivalent @['SuperBlockState']@. The
24+
-- input list length must be even, and the output list length will
25+
-- always be half that of the input list.
26+
bitsToSBStates (False : False : xs) = SBEmpty : bitsToSBStates xs
27+
bitsToSBStates (True : False : xs) = SBSpaceAvailable : bitsToSBStates xs
28+
bitsToSBStates (True : True : xs) = SBFull : bitsToSBStates xs
29+
bitsToSBStates [] = []
30+
31+
-- | Converts @['SuperBlockState']@ into a list of bits. Dual of 'bitsToSBState'.
32+
sbStatesToBits (SBEmpty : xs) = False : False : sbStatesToBits xs
33+
sbStatesToBits (SBSpaceAvailable : xs) = True : False : sbStatesToBits xs
34+
sbStatesToBits (SBFull : xs) = True : True : sbStatesToBits xs
35+
sbStatesToBits [] = []

0 commit comments

Comments
 (0)