Skip to content

Support binary Disk IDs #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions internal/os/disk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package disk

import (
"encoding/hex"
"encoding/json"
"fmt"
"os/exec"
Expand Down Expand Up @@ -179,12 +180,17 @@ func (APIImplementor) DiskHasPage83ID(disk syscall.Handle, matchID string) (bool
page83ID := []byte{}
byteSize := unsafe.Sizeof(byte(0))
for n = 0; n < devIDDesc.NumberOfIdentifiers; n++ {
if pID.CodeSet == StorageIDCodeSetASCII && pID.Association == StorageIDAssocDevice {
if pID.Association == StorageIDAssocDevice && (pID.CodeSet == StorageIDCodeSetBinary || pID.CodeSet == StorageIDCodeSetASCII) {
for m = 0; m < pID.IdentifierSize; m++ {
page83ID = append(page83ID, *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pID.Identifier[0])) + byteSize*uintptr(m))))
}

page83IDString := string(page83ID)
var page83IDString string
if pID.CodeSet == StorageIDCodeSetASCII {
page83IDString = string(page83ID)
} else if pID.CodeSet == StorageIDCodeSetBinary {
page83IDString = hex.EncodeToString(page83ID)
}
if strings.Contains(page83IDString, matchID) {
return true, nil
}
Expand Down Expand Up @@ -220,12 +226,16 @@ func (APIImplementor) GetDiskPage83ID(disk syscall.Handle) (string, error) {
page83ID := []byte{}
byteSize := unsafe.Sizeof(byte(0))
for n = 0; n < devIDDesc.NumberOfIdentifiers; n++ {
if pID.CodeSet == StorageIDCodeSetASCII && pID.Association == StorageIDAssocDevice {
if pID.Association == StorageIDAssocDevice {
for m = 0; m < pID.IdentifierSize; m++ {
page83ID = append(page83ID, *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pID.Identifier[0])) + byteSize*uintptr(m))))
}

return string(page83ID), nil
if pID.CodeSet == StorageIDCodeSetASCII {
return string(page83ID), nil
} else if pID.CodeSet == StorageIDCodeSetBinary {
return hex.EncodeToString(page83ID), nil
}
}
pID = (*StorageIdentifier)(unsafe.Pointer(uintptr(unsafe.Pointer(pID)) + byteSize*uintptr(pID.NextOffset)))
}
Expand Down