logical_disk: Fix failed to get disk ID for dynamic volumes (#1544)
This commit is contained in:
parent
4635be8c0c
commit
6cecc735df
|
@ -28,4 +28,19 @@ jobs:
|
||||||
bug
|
bug
|
||||||
docs
|
docs
|
||||||
chore
|
chore
|
||||||
&& exit 1
|
&& exit 1
|
||||||
|
title:
|
||||||
|
name: check title prefix
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: check
|
||||||
|
run: |
|
||||||
|
PR_TITLE_PREFIX=$(echo "$PR_TITLE" | cut -d':' -f1)
|
||||||
|
if [[ ! -d "pkg/collector/$PR_TITLE_PREFIX" ]] || [[ "$PR_TITLE_PREFIX" == "chore" ]] || [[ "$PR_TITLE_PREFIX" == "*" ]]; then
|
||||||
|
echo "PR title must start with an name of an collector package"
|
||||||
|
echo "Example: 'logical_disk: description'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
|
@ -5,11 +5,13 @@ package logical_disk
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
@ -463,6 +465,9 @@ func getDriveType(driveType uint32) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// diskExtentSize Size of the DiskExtent structure in bytes.
|
||||||
|
const diskExtentSize = 24
|
||||||
|
|
||||||
// getDiskIDByVolume returns the disk ID for a given volume.
|
// getDiskIDByVolume returns the disk ID for a given volume.
|
||||||
func getDiskIDByVolume(rootDrive string) (string, error) {
|
func getDiskIDByVolume(rootDrive string) (string, error) {
|
||||||
// Open a volume handle to the Disk Root.
|
// Open a volume handle to the Disk Root.
|
||||||
|
@ -488,16 +493,24 @@ func getDiskIDByVolume(rootDrive string) (string, error) {
|
||||||
var bytesReturned uint32
|
var bytesReturned uint32
|
||||||
err = windows.DeviceIoControl(f, controlCode, nil, 0, &volumeDiskExtents[0], uint32(len(volumeDiskExtents)), &bytesReturned, nil)
|
err = windows.DeviceIoControl(f, controlCode, nil, 0, &volumeDiskExtents[0], uint32(len(volumeDiskExtents)), &bytesReturned, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", fmt.Errorf("could not identify physical drive for %s: %w", rootDrive, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if uint(binary.LittleEndian.Uint32(volumeDiskExtents)) != 1 {
|
numDiskIDs := uint(binary.LittleEndian.Uint32(volumeDiskExtents))
|
||||||
return "", fmt.Errorf("could not identify physical drive for %s", rootDrive)
|
if numDiskIDs < 1 {
|
||||||
|
return "", fmt.Errorf("could not identify physical drive for %s: no disk IDs returned", rootDrive)
|
||||||
}
|
}
|
||||||
|
|
||||||
diskId := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(volumeDiskExtents[8:])), 10)
|
diskIDs := make([]string, numDiskIDs)
|
||||||
|
|
||||||
return diskId, nil
|
for i := range numDiskIDs {
|
||||||
|
diskIDs[i] = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(volumeDiskExtents[8+i*diskExtentSize:])), 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
slices.Sort(diskIDs)
|
||||||
|
diskIDs = slices.Compact(diskIDs)
|
||||||
|
|
||||||
|
return strings.Join(diskIDs, ";"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVolumeInfo(rootDrive string) (volumeInfo, error) {
|
func getVolumeInfo(rootDrive string) (volumeInfo, error) {
|
||||||
|
|
Loading…
Reference in New Issue