Documentation
¶
Overview ¶
Package diskgen builds synthetic partition-table images for tests and fuzz seeds. Every builder produces a fully valid structure by default; defect injection is the caller's job, via the Mutate hook or by editing the result.
Index ¶
- Constants
- func APM(o APMOpts) []byte
- func BSD(o BSDOpts) []byte
- func GPT(o GPTOpts) []byte
- func GUIDBytes(s string) []byte
- func MBR(o MBROpts) []byte
- func MBRExtended(o MBRExtendedOpts) []byte
- func MBRPlusBSD(size int) []byte
- func MBRPlusSun(size int) []byte
- func NestedBSD(o NestedBSDOpts) []byte
- func NestedIn(sliceType byte, sliceStart, sliceSize uint32, blockSize int, inner []byte) []byte
- func SetGPTCRCs(disk []byte, bs, headerLBA int)
- func SunI386(o SunOpts) []byte
- func SunSparc(o SunOpts) []byte
- func WriteBSDLabel(sector []byte, o BSDOpts)
- type APMEntry
- type APMOpts
- type BSDOpts
- type BSDPart
- type GPTEntry
- type GPTOpts
- type MBREntry
- type MBRExtendedOpts
- type MBROpts
- type NestedBSDOpts
- type SunOpts
- type SunPart
Constants ¶
const ( GUIDLinuxFS = "0fc63daf-8483-4772-8e79-3d69d8477de4" GUIDLinuxSwap = "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f" GUIDEFISystem = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" GUIDAppleHFS = "48465300-0000-11aa-aa11-00306543ecac" GUIDMSReserved = "e3c9e316-0b5c-4db8-817d-f92df00215ae" GUIDMSBasicData = "ebd0a0a2-b9e5-4433-87c0-68b6b72699c7" )
Well-known GPT type GUIDs, in the textual form libtable reports.
const DefaultSize = 8 << 20
DefaultSize is the image size used when an Opts leaves Size at zero.
Variables ¶
This section is empty.
Functions ¶
func GUIDBytes ¶
GUIDBytes encodes a GUID string into the mixed-endian on-disk layout GPT uses: the first three groups are little-endian, the last two big-endian.
func MBRExtended ¶
func MBRExtended(o MBRExtendedOpts) []byte
MBRExtended builds an MBR whose first slot is an extended container holding a chain of Depth EBRs, each with one logical partition.
func MBRPlusBSD ¶
MBRPlusBSD builds media on which both an MBR and a BSD disklabel parse cleanly, for exercising ambiguity resolution. A size of 0 uses DefaultSize.
func MBRPlusSun ¶
MBRPlusSun builds media on which both an MBR and a Sun label parse cleanly. The Sun label shares sector 0 with the MBR.
func NestedBSD ¶
func NestedBSD(o NestedBSDOpts) []byte
NestedBSD builds an MBR whose slice contains a BSD disklabel.
func NestedIn ¶
NestedIn builds an MBR whose single slice of sliceType contains inner, an image in its own right, rebased so inner's LBA 0 is the first sector of the slice. Use it to place any scheme inside an MBR container.
func SetGPTCRCs ¶
SetGPTCRCs recomputes the header and entry-table checksums for the header at headerLBA. Call it after mutating a GPT image to keep it internally valid.
func WriteBSDLabel ¶
WriteBSDLabel writes a disklabel at the start of sector.
Types ¶
type APMEntry ¶
type APMEntry struct {
StartLBA uint32
SizeLBA uint32
Name string
Type string
// Status of 0 marks the partition unallocated.
Status uint32
}
APMEntry describes one Apple Partition Map record.
type GPTEntry ¶
type GPTEntry struct {
TypeGUID string
UniqueGUID string
StartLBA uint64
EndLBA uint64
Attributes uint64
Name string
}
GPTEntry describes one GPT partition entry.
type GPTOpts ¶
type GPTOpts struct {
Size int
BlockSize int
// EntryCount is the value written to the header. Zero means 128.
EntryCount uint32
// EntrySize is the value written to the header. Zero means 128.
EntrySize uint32
Entries []GPTEntry
// ProtectiveSlot places the 0xEE record in a slot other than 0.
ProtectiveSlot int
// HybridEntries are additional real MBR records written alongside the
// protective entry, producing a hybrid MBR.
HybridEntries []MBREntry
// NoProtectiveMBR omits the 0xEE record entirely.
NoProtectiveMBR bool
// CorruptPrimary invalidates the primary header so only the backup parses.
CorruptPrimary bool
// NoBackup omits the secondary GPT at the end of the disk. Real tools always
// write one, so it is written by default and this opts out -- which is what
// a truncated image or a wiped tail looks like.
NoBackup bool
// DiskGUID is written to both copies. Zero means an all-zero GUID.
DiskGUID string
// SkipCRC leaves the CRC fields zero.
SkipCRC bool
Mutate func(disk []byte, blockSize int)
}
type MBRExtendedOpts ¶
type NestedBSDOpts ¶
type NestedBSDOpts struct {
Size int
BlockSize int
// SliceStart and SliceSize describe the MBR container.
SliceStart uint32
SliceSize uint32
// SliceType is the MBR type byte; 0xA5 is FreeBSD.
SliceType byte
// Relative writes disklabel addresses relative to the slice. When false the
// addresses are disk-absolute, as some real BSD installers write them.
Relative bool
Parts []BSDPart
}