Merge pull request #5270 from kzys/remove-blockdev
Use os.File#Seek() to get the size of a block device
This commit is contained in:
commit
9a9bd09756
@ -20,6 +20,8 @@ package dmsetup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -327,15 +329,18 @@ func GetFullDevicePath(deviceName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BlockDeviceSize returns size of block device in bytes
|
// BlockDeviceSize returns size of block device in bytes
|
||||||
func BlockDeviceSize(devicePath string) (uint64, error) {
|
func BlockDeviceSize(path string) (int64, error) {
|
||||||
data, err := exec.Command("blockdev", "--getsize64", "-q", devicePath).CombinedOutput()
|
f, err := os.Open(path)
|
||||||
output := string(data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrapf(err, output)
|
return 0, err
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
output = strings.TrimSuffix(output, "\n")
|
size, err := f.Seek(0, io.SeekEnd)
|
||||||
return strconv.ParseUint(output, 10, 64)
|
if err != nil {
|
||||||
|
return 0, errors.Wrapf(err, "failed to seek on %q", path)
|
||||||
|
}
|
||||||
|
return size, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dmsetup(args ...string) (string, error) {
|
func dmsetup(args ...string) (string, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user