-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor parse inf driver class guid
Signed-off-by: JUN JIE NAN <[email protected]>
- Loading branch information
Showing
15 changed files
with
166 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package windows | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var ( | ||
versionRe = regexp.MustCompile(`(?i)^\[Version\][ ]*$`) | ||
classGuidRe = regexp.MustCompile(`(?i)^ClassGuid[ ]*=[ ]*(.+)$`) | ||
) | ||
|
||
func ParseDriverClassGuid(driverName, infPath string) (classGuid string, err error) { | ||
// Retrieve the ClassGuid which is needed for the Windows registry entries. | ||
file, err := os.Open(infPath) | ||
if err != nil { | ||
err = fmt.Errorf("Failed to open driver %s inf %s: %w", driverName, infPath, err) | ||
return | ||
} | ||
|
||
defer func() { | ||
file.Close() | ||
if classGuid == "" { | ||
err = fmt.Errorf("Failed to parse driver %s classGuid %s", driverName, infPath) | ||
} | ||
}() | ||
|
||
classGuid = MatchClassGuid(file) | ||
return | ||
} | ||
|
||
func MatchClassGuid(r io.Reader) (classGuid string) { | ||
scanner := bufio.NewScanner(r) | ||
versionFlag := false | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if !versionFlag { | ||
if versionRe.MatchString(line) { | ||
versionFlag = true | ||
} | ||
continue | ||
} | ||
matches := classGuidRe.FindStringSubmatch(line) | ||
if len(matches) > 1 { | ||
classGuid = strings.TrimSpace(matches[1]) | ||
if classGuid != "" { | ||
return | ||
} | ||
} | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package windows | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestMatchClassGuid(t *testing.T) { | ||
tcs := []struct { | ||
filename string | ||
want string | ||
}{ | ||
{"testdata/inf01.txt", "{4D36E97B-E325-11CE-BFC1-08002BE10318}"}, | ||
{"testdata/inf02.txt", "{4D36E97B-E325-11CE-BFC1-08002BE10318}"}, | ||
{"testdata/inf03.txt", ""}, | ||
} | ||
for _, tc := range tcs { | ||
t.Run("", func(t *testing.T) { | ||
file, err := os.Open(tc.filename) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
actual := MatchClassGuid(file) | ||
if actual != tc.want { | ||
t.Fatal(actual, tc.want) | ||
} | ||
}) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Version] | ||
Signature="$Windows NT$" | ||
Class=SCSIAdapter | ||
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318} | ||
Provider=%VENDOR% | ||
DriverVer = 02/25/2024,100.94.104.24800 | ||
CatalogFile=viostor.cat | ||
DriverPackageType = PlugAndPlay | ||
DriverPackageDisplayName = %VioStorScsi.DeviceDesc% | ||
PnpLockdown=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
;/*++ | ||
; | ||
;Copyright (c) 2008-2023 Red Hat Inc. | ||
; | ||
; | ||
;Module Name: | ||
; viostor.inf | ||
; | ||
;Abstract: | ||
; | ||
;Installation Notes: | ||
; Step by step driver installation wiki: | ||
; https://github.com/virtio-win/kvm-guest-drivers-windows/wiki/Driver-installation | ||
; | ||
;--*/ | ||
|
||
[Version] | ||
Signature="$Windows NT$" | ||
Class=SCSIAdapter | ||
;ClassGUID={4d36e97b-e325-11ce-bfc1-08002be10318} | ||
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318} | ||
Provider=%VENDOR% | ||
DriverVer = 02/25/2024,100.94.104.24800 | ||
CatalogFile=viostor.cat | ||
DriverPackageType = PlugAndPlay | ||
DriverPackageDisplayName = %VioStorScsi.DeviceDesc% | ||
PnpLockdown=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
;/*++ | ||
; | ||
;Copyright (c) 2008-2023 Red Hat Inc. | ||
; | ||
; | ||
;Module Name: | ||
; viostor.inf | ||
; | ||
;Abstract: | ||
; | ||
;Installation Notes: | ||
; Step by step driver installation wiki: | ||
; https://github.com/virtio-win/kvm-guest-drivers-windows/wiki/Driver-installation | ||
; | ||
;--*/ | ||
|
||
;[Version] | ||
Signature="$Windows NT$" | ||
Class=SCSIAdapter | ||
;ClassGUID={4d36e97b-e325-11ce-bfc1-08002be10318} | ||
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318} | ||
Provider=%VENDOR% | ||
DriverVer = 02/25/2024,100.94.104.24800 | ||
CatalogFile=viostor.cat | ||
DriverPackageType = PlugAndPlay | ||
DriverPackageDisplayName = %VioStorScsi.DeviceDesc% | ||
PnpLockdown=1 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package shared | ||
package windows | ||
|
||
import ( | ||
"bufio" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package shared | ||
package windows | ||
|
||
import ( | ||
"os" | ||
|