Skip to content

Commit

Permalink
disk: define PartitionTableType enum for partition table types
Browse files Browse the repository at this point in the history
Add a new enum, PartitionTableType, for referring to the two partition
table types, "dos" and "gpt".
This is currently not used but will be part of the new custom partition
table generator.
  • Loading branch information
achilleas-k committed Nov 5, 2024
1 parent b829532 commit 366b203
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,41 @@ func NewFSType(s string) (FSType, error) {
}
}

// PartitionTableType is the partition table type enum.
type PartitionTableType uint64

const (
PT_NONE PartitionTableType = iota
PT_DOS
PT_GPT
)

func (t PartitionTableType) String() string {
switch t {
case PT_NONE:
return ""
case PT_DOS:
return "dos"
case PT_GPT:
return "gpt"
default:
panic(fmt.Sprintf("unknown or unsupported partition table type with enum value %d", t))
}
}

func NewPartitionTableType(s string) (PartitionTableType, error) {
switch s {
case "":
return PT_NONE, nil
case "dos":
return PT_DOS, nil
case "gpt":
return PT_GPT, nil
default:
return PT_NONE, fmt.Errorf("unknown or unsupported partition table type name: %s", s)
}
}

// Entity is the base interface for all disk-related entities.
type Entity interface {
// Clone returns a deep copy of the entity.
Expand Down

0 comments on commit 366b203

Please sign in to comment.