MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / getDiskSizeMB

Function getDiskSizeMB

src/cmd/linuxkit/util.go:165–182  ·  view source on GitHub ↗

This function parses the "size" parameter of a disk specification and returns the size in MB. The "size" parameter defaults to GB, but the unit can be explicitly set with either a G (for GB) or M (for MB). It returns the disk size in MB.

(s string)

Source from the content-addressed store, hash-verified

163// the unit can be explicitly set with either a G (for GB) or M (for
164// MB). It returns the disk size in MB.
165func getDiskSizeMB(s string) (int, error) {
166 if s == "" {
167 return 0, nil
168 }
169 sz := len(s)
170 if strings.HasSuffix(s, "M") {
171 return strconv.Atoi(s[:sz-1])
172 }
173 if strings.HasSuffix(s, "G") {
174 s = s[:sz-1]
175 }
176
177 i, err := strconv.Atoi(s)
178 if err != nil {
179 return 0, err
180 }
181 return 1024 * i, nil
182}
183
184func convertMBtoGB(i int) int {
185 if i < 1024 {

Callers 3

runVCenterCmdFunction · 0.85
buildCmdFunction · 0.85
SetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected