disk: add bytes ↔ sectors conversion helper

Add simple helper methods that convert between bytes and sectors. This
is a method of `PartitionTable`, since the sector size can in theory
be per partition table and this prepares for that case.
This commit is contained in:
Christian Kellner 2021-12-20 15:36:57 +01:00 committed by Tom Gundersen
parent 115c864f93
commit f5592bd14a

View file

@ -53,6 +53,16 @@ type Filesystem struct {
FSTabPassNo uint64
}
// Convert the given bytes to the number of sectors.
func (pt *PartitionTable) BytesToSectors(size uint64) uint64 {
return size / DefaultSectorSize
}
// Convert the given number of sectors to bytes.
func (pt *PartitionTable) SectorsToBytes(size uint64) uint64 {
return size * DefaultSectorSize
}
// Clone the partition table (deep copy).
func (pt *PartitionTable) Clone() *PartitionTable {
if pt == nil {