Ejemplo n.º 1
0
func convertPartitionDimension(in string) (types.PartitionDimension, error) {
	if in == "" {
		return 0, nil
	}

	b, err := units.ParseBase2Bytes(in)
	if err != nil {
		return 0, err
	}
	if b < 0 {
		return 0, fmt.Errorf("invalid dimension (negative): %q", in)
	}

	// Translate bytes into sectors
	sectors := (b / BYTES_PER_SECTOR)
	if b%BYTES_PER_SECTOR != 0 {
		sectors++
	}
	return types.PartitionDimension(uint64(sectors)), nil
}
Ejemplo n.º 2
0
func (n *PartitionDimension) UnmarshalYAML(unmarshal func(interface{}) error) error {
	// In YAML we allow human-readable dimensions like GiB/TiB etc.
	var str string
	if err := unmarshal(&str); err != nil {
		return err
	}

	b2b, err := units.ParseBase2Bytes(str) // TODO(vc): replace the units package
	if err != nil {
		return err
	}
	if b2b < 0 {
		return fmt.Errorf("negative value inappropriate: %q", str)
	}

	// Translate bytes into sectors
	sectors := (b2b / 512)
	if b2b%512 != 0 {
		sectors++
	}
	*n = PartitionDimension(uint64(sectors))
	return nil
}
Ejemplo n.º 3
0
func (d *bytesValue) Set(s string) error {
	v, err := units.ParseBase2Bytes(s)
	*d = bytesValue(v)
	return err
}