disk

package
v0.0.0-...-45a7bdf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GPTSize          = 92
	GPTPartitionSize = 128
	GPTVersion210    = 0x00010000
	GPTSignature     = 0x5452415020494645
)
View Source
const (
	MBRSize          = 512
	MBRPartitionSize = 16
	MBRSignature     = 0xAA55
)
View Source
const (
	MBRPartTypeLinux         = 0x83
	MBRPartTypeFAT32LBA      = 0x0C
	MBRPartTypeGPTProtective = 0xEE
)
View Source
const BlockSize = 512

Variables

View Source
var (
	GPTTypeMicrosoftBasicData = uuid.MustParse("EBD0A0A2-B9E5-4433-87C0-68B6B72699C7")
	GPTTypeLinuxFileSystem    = uuid.MustParse("0FC63DAF-8483-4772-8E79-3D69D8477DE4")
)
View Source
var (
	ErrGPTNotPresent  = errors.New("GPT signature not detected")
	ErrGPTUnsupported = errors.New("GPT version unsupported")
)
View Source
var CHSInvalid = CHSAddr{
	Head:     0xFF,
	Sector:   0xFF,
	Cylinder: 0xFF,
}

Functions

func NewGPT

func NewGPT(diskBlocks uint64) (*GPT, *GPT, error)

func WriteGPTPartitions

func WriteGPTPartitions(writer io.WriterAt, start uint64, size uint32, parts []GPTPartition) (uint32, error)

Types

type CHSAddr

type CHSAddr struct {
	Head     byte
	Sector   byte
	Cylinder byte
}

func (CHSAddr) String

func (a CHSAddr) String() string

type Disk

type Disk struct {
	// contains filtered or unexported fields
}

func Create

func Create(dev string, size int64) (*Disk, error)

func Open

func Open(dev string) (*Disk, error)

func (*Disk) Close

func (d *Disk) Close() error

func (*Disk) ReadGPT

func (d *Disk) ReadGPT(lba uint64) (*GPT, error)

func (*Disk) ReadGPTPartitions

func (d *Disk) ReadGPTPartitions(start uint64, size uint32, count uint32) ([]GPTPartition, uint32, error)

func (*Disk) ReadMBR

func (d *Disk) ReadMBR() (*MBR, error)

func (*Disk) WriteGPT

func (d *Disk) WriteGPT(lba uint64, gpt *GPT) error

func (*Disk) WriteGPTPartitions

func (d *Disk) WriteGPTPartitions(start uint64, size uint32, parts []GPTPartition) (uint32, error)

func (*Disk) WriteMBR

func (d *Disk) WriteMBR(mbr *MBR) error

type GPT

type GPT struct {
	Signature      uint64
	Revision       uint32
	Size           uint32
	Checksum       uint32
	Reserved       uint32
	ThisLBA        uint64
	AlternativeLBA uint64
	DataFirst      uint64
	DataLast       uint64
	GUID           uuid.UUID
	PartitionsLBA  uint64
	PartitionCount uint32
	EntrySize      uint32
	PartitionsCRC  uint32
}

func ParseGPT

func ParseGPT(data []byte) (*GPT, error)

func (*GPT) CalculateChecksum

func (t *GPT) CalculateChecksum() uint32

func (*GPT) FillBytes

func (t *GPT) FillBytes(data []byte)

func (*GPT) String

func (t *GPT) String() string

type GPTPartition

type GPTPartition struct {
	Type       uuid.UUID
	ID         uuid.UUID
	StartLBA   uint64
	EndLBA     uint64
	Attributes uint64
	Name       string
}

func NewGPTPartition

func NewGPTPartition(ty uuid.UUID, start uint64, end uint64, name string) (GPTPartition, error)

func ParseGPTPartitions

func ParseGPTPartitions(reader io.ReaderAt, start uint64, size uint32, count uint32) ([]GPTPartition, uint32, error)

type MBR

type MBR struct {
	Bootstrap [440]byte
	DiskID    uint32
	Reserved  uint16
	Part1     MBRPartition
	Part2     MBRPartition
	Part3     MBRPartition
	Part4     MBRPartition
	Signature uint16
}

func NewMBR

func NewMBR() *MBR

func ParseMBR

func ParseMBR(data []byte) *MBR

func (*MBR) FillBytes

func (m *MBR) FillBytes(data []byte)

func (*MBR) String

func (m *MBR) String() string

type MBRPartType

type MBRPartType byte

func (MBRPartType) String

func (t MBRPartType) String() string

type MBRPartition

type MBRPartition struct {
	Attrs    byte
	CHSStart CHSAddr
	Type     MBRPartType
	CHSLast  CHSAddr
	LBAStart uint32
	LBASize  uint32
}

func NewMBRPartition

func NewMBRPartition(ty MBRPartType, start uint32, size uint32) MBRPartition

func ParseMBRPartition

func ParseMBRPartition(data []byte) MBRPartition

func (MBRPartition) FillBytes

func (p MBRPartition) FillBytes(data []byte)

func (MBRPartition) String

func (p MBRPartition) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL