GetDeviceLogicalBlockSize Windows impl
This commit is contained in:
parent
7c435854bd
commit
540062c80d
3 changed files with 49 additions and 44 deletions
|
|
@ -89,3 +89,23 @@ func CheckRunAsRoot() (bool, error) {
|
|||
|
||||
return currentUser.Username == "root", nil
|
||||
}
|
||||
|
||||
func GetDeviceLogicalBlockSize(devPath string) (uint64, error) {
|
||||
fd, err := os.Open(devPath)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "open device")
|
||||
}
|
||||
|
||||
defer func() { _ = fd.Close() }()
|
||||
|
||||
bs, err := getDeviceLogicalBlockSizeInner(fd.Fd())
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "get block size inner")
|
||||
}
|
||||
|
||||
if bs <= 0 {
|
||||
return 0, fmt.Errorf("retrieved block size is zero (or negative): '%v'", bs)
|
||||
}
|
||||
|
||||
return uint64(bs), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue