partly- Inspect, create, and alter MBRs.

Safe HaskellSafe-Inferred



Types for dealing with the old-fasioned and modern Master Boot Records. This does not cover things like the GUID partition table or any of the weird variations like AAP or NEWLDR.



data Timestamp Source

The so-called mystery bytes on Windows 95B, 98, 98SE, and Me -- in fact, they're a timestamp and a drive number. See http:thestarman.pcministry.comasmmbr/mystery.htm .



data CHS Source

A representation of the cylinderheadsector address in MBRs.




head :: Word8

The head number.

sector :: Word8

The sector number; this is actually a six-bit number, but Haskell doesn't have a convenient way to deal with those.

cylinder :: Word16

The cylinder number; likewise, this is actually a 10-bit number.


data PartitionEntry Source

Partition entries themselves are somewhat intricate.




status :: Word8

A bitfield describing this partition. An 0x00 here means it's inactive; having bit 7 set (i.e. > 0x80) means bootable; anything less is invalid.

chsFirst :: CHS

The CHS address of the first absolute sector of the partition.

partitionType :: Word8

A partition type; for specifics, see the following document:

chsLast :: CHS

The CHS address of the last absolute sector of the partition.

lbaFirst :: Word32

The logical block address of the first absolute sector.

sectors :: Word32

The number of sectors in the partition.

nullPartition :: PartitionEntrySource

The empty partition table entry.

bootable :: PartitionEntry -> BoolSource

Whether this partition entry is marked bootable.

data PartitionTable Source

An MBR partition table consists of (up to?) four partition entries.

nullPartitionTable :: PartitionTableSource

The empty partition table.

data BootRecord Source

The structure of a Master Boot Record is as follows...




bootloader :: ByteString

The first piece of data on a disk with a Master Boot Record is some bootloader code that gets loaded to address 0x7c00 in memory. N.B: this may include the data for the Windows timestamp, if it exists. It will also include the optional disk signature, if it exists -- thus this field is always 446 bytes long.

partitions :: PartitionTable

Four partition table entries.

bootSig :: Word16

Finally, the boot signature.

emptyBootloader :: ByteStringSource

The empty bootloader -- 446 empty bytes.

nullBootRecord :: BootRecordSource

The empty boot record.

getTimestamp :: BootRecord -> Maybe TimestampSource

Get the completely-optional, obsolete disk timestamp used by some old versions of Windows.

getDiskSignature :: BootRecord -> Maybe Word32Source

Get the optional disk signature from a Bootrecord's bootloader.