Skip to content

Commit 2589b91

Browse files
committed
pr feedback regenerate code
Signed-off-by: Maksim An <maksiman@microsoft.com>
1 parent 24844ed commit 2589b91

9 files changed

Lines changed: 98 additions & 85 deletions

File tree

internal/winapi/cimfs.go

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import (
1010
"github.com/Microsoft/hcsshim/internal/winapi/types"
1111
)
1212

13-
type g = guid.GUID
13+
// pickSupported makes sure we use appropriate syscalls depending on which DLLs are present.
14+
func pickSupported[F any](cimWriterFunc, cimfsFunc F) F {
15+
if cimwriter.Supported() {
16+
return cimWriterFunc
17+
}
18+
return cimfsFunc
19+
}
1420

1521
func CimMountImage(imagePath string, fsName string, flags uint32, volumeID *guid.GUID) error {
1622
return cimfs.CimMountImage(imagePath, fsName, flags, volumeID)
@@ -21,112 +27,112 @@ func CimDismountImage(volumeID *guid.GUID) error {
2127
}
2228

2329
func CimCreateImage(imagePath string, oldFSName *uint16, newFSName *uint16, cimFSHandle *types.FsHandle) error {
24-
if cimwriter.CimWriterSupported() {
25-
return cimwriter.CimCreateImage(imagePath, oldFSName, newFSName, cimFSHandle)
26-
}
27-
return cimfs.CimCreateImage(imagePath, oldFSName, newFSName, cimFSHandle)
30+
return pickSupported(
31+
cimwriter.CimCreateImage,
32+
cimfs.CimCreateImage,
33+
)(imagePath, oldFSName, newFSName, cimFSHandle)
2834
}
2935

3036
func CimCreateImage2(imagePath string, flags uint32, oldFSName *uint16, newFSName *uint16, cimFSHandle *types.FsHandle) error {
31-
if cimwriter.CimWriterSupported() {
32-
return cimwriter.CimCreateImage2(imagePath, flags, oldFSName, newFSName, cimFSHandle)
33-
}
34-
return cimfs.CimCreateImage2(imagePath, flags, oldFSName, newFSName, cimFSHandle)
37+
return pickSupported(
38+
cimwriter.CimCreateImage2,
39+
cimfs.CimCreateImage2,
40+
)(imagePath, flags, oldFSName, newFSName, cimFSHandle)
3541
}
3642

3743
func CimCloseImage(cimFSHandle types.FsHandle) error {
38-
if cimwriter.CimWriterSupported() {
39-
return cimwriter.CimCloseImage(cimFSHandle)
40-
}
41-
return cimfs.CimCloseImage(cimFSHandle)
44+
return pickSupported(
45+
cimwriter.CimCloseImage,
46+
cimfs.CimCloseImage,
47+
)(cimFSHandle)
4248
}
4349

4450
func CimCommitImage(cimFSHandle types.FsHandle) error {
45-
if cimwriter.CimWriterSupported() {
46-
return cimwriter.CimCommitImage(cimFSHandle)
47-
}
48-
return cimfs.CimCommitImage(cimFSHandle)
51+
return pickSupported(
52+
cimwriter.CimCommitImage,
53+
cimfs.CimCommitImage,
54+
)(cimFSHandle)
4955
}
5056

5157
func CimCreateFile(cimFSHandle types.FsHandle, path string, file *types.CimFsFileMetadata, cimStreamHandle *types.StreamHandle) error {
52-
if cimwriter.CimWriterSupported() {
53-
return cimwriter.CimCreateFile(cimFSHandle, path, file, cimStreamHandle)
54-
}
55-
return cimfs.CimCreateFile(cimFSHandle, path, file, cimStreamHandle)
58+
return pickSupported(
59+
cimwriter.CimCreateFile,
60+
cimfs.CimCreateFile,
61+
)(cimFSHandle, path, file, cimStreamHandle)
5662
}
5763

5864
func CimCloseStream(cimStreamHandle types.StreamHandle) error {
59-
if cimwriter.CimWriterSupported() {
60-
return cimwriter.CimCloseStream(cimStreamHandle)
61-
}
62-
return cimfs.CimCloseStream(cimStreamHandle)
65+
return pickSupported(
66+
cimwriter.CimCloseStream,
67+
cimfs.CimCloseStream,
68+
)(cimStreamHandle)
6369
}
6470

6571
func CimWriteStream(cimStreamHandle types.StreamHandle, buffer uintptr, bufferSize uint32) error {
66-
if cimwriter.CimWriterSupported() {
67-
return cimwriter.CimWriteStream(cimStreamHandle, buffer, bufferSize)
68-
}
69-
return cimfs.CimWriteStream(cimStreamHandle, buffer, bufferSize)
72+
return pickSupported(
73+
cimwriter.CimWriteStream,
74+
cimfs.CimWriteStream,
75+
)(cimStreamHandle, buffer, bufferSize)
7076
}
7177

7278
func CimDeletePath(cimFSHandle types.FsHandle, path string) error {
73-
if cimwriter.CimWriterSupported() {
74-
return cimwriter.CimDeletePath(cimFSHandle, path)
75-
}
76-
return cimfs.CimDeletePath(cimFSHandle, path)
79+
return pickSupported(
80+
cimwriter.CimDeletePath,
81+
cimfs.CimDeletePath,
82+
)(cimFSHandle, path)
7783
}
7884

7985
func CimCreateHardLink(cimFSHandle types.FsHandle, newPath string, oldPath string) error {
80-
if cimwriter.CimWriterSupported() {
81-
return cimwriter.CimCreateHardLink(cimFSHandle, newPath, oldPath)
82-
}
83-
return cimfs.CimCreateHardLink(cimFSHandle, newPath, oldPath)
86+
return pickSupported(
87+
cimwriter.CimCreateHardLink,
88+
cimfs.CimCreateHardLink,
89+
)(cimFSHandle, newPath, oldPath)
8490
}
8591

8692
func CimCreateAlternateStream(cimFSHandle types.FsHandle, path string, size uint64, cimStreamHandle *types.StreamHandle) error {
87-
if cimwriter.CimWriterSupported() {
88-
return cimwriter.CimCreateAlternateStream(cimFSHandle, path, size, cimStreamHandle)
89-
}
90-
return cimfs.CimCreateAlternateStream(cimFSHandle, path, size, cimStreamHandle)
93+
return pickSupported(
94+
cimwriter.CimCreateAlternateStream,
95+
cimfs.CimCreateAlternateStream,
96+
)(cimFSHandle, path, size, cimStreamHandle)
9197
}
9298

9399
func CimAddFsToMergedImage(cimFSHandle types.FsHandle, path string) error {
94-
if cimwriter.CimWriterSupported() {
95-
return cimwriter.CimAddFsToMergedImage(cimFSHandle, path)
96-
}
97-
return cimfs.CimAddFsToMergedImage(cimFSHandle, path)
100+
return pickSupported(
101+
cimwriter.CimAddFsToMergedImage,
102+
cimfs.CimAddFsToMergedImage,
103+
)(cimFSHandle, path)
98104
}
99105

100106
func CimAddFsToMergedImage2(cimFSHandle types.FsHandle, path string, flags uint32) error {
101-
if cimwriter.CimWriterSupported() {
102-
return cimwriter.CimAddFsToMergedImage2(cimFSHandle, path, flags)
103-
}
104-
return cimfs.CimAddFsToMergedImage2(cimFSHandle, path, flags)
107+
return pickSupported(
108+
cimwriter.CimAddFsToMergedImage2,
109+
cimfs.CimAddFsToMergedImage2,
110+
)(cimFSHandle, path, flags)
105111
}
106112

107113
func CimMergeMountImage(numCimPaths uint32, backingImagePaths *types.CimFsImagePath, flags uint32, volumeID *guid.GUID) error {
108114
return cimfs.CimMergeMountImage(numCimPaths, backingImagePaths, flags, volumeID)
109115
}
110116

111117
func CimTombstoneFile(cimFSHandle types.FsHandle, path string) error {
112-
if cimwriter.CimWriterSupported() {
113-
return cimwriter.CimTombstoneFile(cimFSHandle, path)
114-
}
115-
return cimfs.CimTombstoneFile(cimFSHandle, path)
118+
return pickSupported(
119+
cimwriter.CimTombstoneFile,
120+
cimfs.CimTombstoneFile,
121+
)(cimFSHandle, path)
116122
}
117123

118124
func CimCreateMergeLink(cimFSHandle types.FsHandle, newPath string, oldPath string) (hr error) {
119-
if cimwriter.CimWriterSupported() {
120-
return cimwriter.CimCreateMergeLink(cimFSHandle, newPath, oldPath)
121-
}
122-
return cimfs.CimCreateMergeLink(cimFSHandle, newPath, oldPath)
125+
return pickSupported(
126+
cimwriter.CimCreateMergeLink,
127+
cimfs.CimCreateMergeLink,
128+
)(cimFSHandle, newPath, oldPath)
123129
}
124130

125131
func CimSealImage(blockCimPath string, hashSize *uint64, fixedHeaderSize *uint64, hash *byte) (hr error) {
126-
if cimwriter.CimWriterSupported() {
127-
return cimwriter.CimSealImage(blockCimPath, hashSize, fixedHeaderSize, hash)
128-
}
129-
return cimfs.CimSealImage(blockCimPath, hashSize, fixedHeaderSize, hash)
132+
return pickSupported(
133+
cimwriter.CimSealImage,
134+
cimfs.CimSealImage,
135+
)(blockCimPath, hashSize, fixedHeaderSize, hash)
130136
}
131137

132138
func CimGetVerificationInformation(blockCimPath string, isSealed *uint32, hashSize *uint64, signatureSize *uint64, fixedHeaderSize *uint64, hash *byte, signature *byte) (hr error) {

internal/winapi/cimfs/cimfs.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
)
1010

1111
// Type aliases
12-
type g = guid.GUID
12+
13+
type GUID = guid.GUID
1314
type FsHandle = types.FsHandle
1415
type StreamHandle = types.StreamHandle
1516
type FileMetadata = types.CimFsFileMetadata
1617
type ImagePath = types.CimFsImagePath
1718

18-
//sys CimMountImage(imagePath string, fsName string, flags uint32, volumeID *g) (hr error) = cimfs.CimMountImage?
19-
//sys CimDismountImage(volumeID *g) (hr error) = cimfs.CimDismountImage?
19+
//sys CimMountImage(imagePath string, fsName string, flags uint32, volumeID *GUID) (hr error) = cimfs.CimMountImage?
20+
//sys CimDismountImage(volumeID *GUID) (hr error) = cimfs.CimDismountImage?
2021

2122
//sys CimCreateImage(imagePath string, oldFSName *uint16, newFSName *uint16, cimFSHandle *FsHandle) (hr error) = cimfs.CimCreateImage?
2223
//sys CimCreateImage2(imagePath string, flags uint32, oldFSName *uint16, newFSName *uint16, cimFSHandle *FsHandle) (hr error) = cimfs.CimCreateImage2?
@@ -31,15 +32,15 @@ type ImagePath = types.CimFsImagePath
3132
//sys CimCreateAlternateStream(cimFSHandle FsHandle, path string, size uint64, cimStreamHandle *StreamHandle) (hr error) = cimfs.CimCreateAlternateStream?
3233
//sys CimAddFsToMergedImage(cimFSHandle FsHandle, path string) (hr error) = cimfs.CimAddFsToMergedImage?
3334
//sys CimAddFsToMergedImage2(cimFSHandle FsHandle, path string, flags uint32) (hr error) = cimfs.CimAddFsToMergedImage2?
34-
//sys CimMergeMountImage(numCimPaths uint32, backingImagePaths *ImagePath, flags uint32, volumeID *g) (hr error) = cimfs.CimMergeMountImage?
35+
//sys CimMergeMountImage(numCimPaths uint32, backingImagePaths *ImagePath, flags uint32, volumeID *GUID) (hr error) = cimfs.CimMergeMountImage?
3536
//sys CimTombstoneFile(cimFSHandle FsHandle, path string) (hr error) = cimfs.CimTombstoneFile?
3637
//sys CimCreateMergeLink(cimFSHandle FsHandle, newPath string, oldPath string) (hr error) = cimfs.CimCreateMergeLink?
3738
//sys CimSealImage(blockCimPath string, hashSize *uint64, fixedHeaderSize *uint64, hash *byte) (hr error) = cimfs.CimSealImage?
3839
//sys CimGetVerificationInformation(blockCimPath string, isSealed *uint32, hashSize *uint64, signatureSize *uint64, fixedHeaderSize *uint64, hash *byte, signature *byte) (hr error) = cimfs.CimGetVerificationInformation?
39-
//sys CimMountVerifiedImage(imagePath string, fsName string, flags uint32, volumeID *g, hashSize uint16, hash *byte) (hr error) = cimfs.CimMountVerifiedImage?
40-
//sys CimMergeMountVerifiedImage(numCimPaths uint32, backingImagePaths *ImagePath, flags uint32, volumeID *g, hashSize uint16, hash *byte) (hr error) = cimfs.CimMergeMountVerifiedImage
40+
//sys CimMountVerifiedImage(imagePath string, fsName string, flags uint32, volumeID *GUID, hashSize uint16, hash *byte) (hr error) = cimfs.CimMountVerifiedImage?
41+
//sys CimMergeMountVerifiedImage(numCimPaths uint32, backingImagePaths *ImagePath, flags uint32, volumeID *GUID, hashSize uint16, hash *byte) (hr error) = cimfs.CimMergeMountVerifiedImage?
4142

42-
// CimFsSupported checks if cimfs.dll is present on the system.
43-
func CimFsSupported() bool {
43+
// Supported checks if cimfs.dll is present on the system.
44+
func Supported() bool {
4445
return modcimfs.Load() == nil
4546
}

internal/winapi/cimfs/syscall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package cimfs
22

3-
//go:generate go run github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go ./*.go
3+
//go:generate go tool github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go ./*.go

internal/winapi/cimfs/zsyscall_windows.go

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/winapi/cimwriter/cimwriter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type ImagePath = types.CimFsImagePath
2929
//sys CimCreateMergeLink(cimFSHandle FsHandle, newPath string, oldPath string) (hr error) = cimwriter.CimCreateMergeLink?
3030
//sys CimSealImage(blockCimPath string, hashSize *uint64, fixedHeaderSize *uint64, hash *byte) (hr error) = cimwriter.CimSealImage?
3131

32-
// CimWriterSupported checks if cimwriter.dll is present on the system.
33-
func CimWriterSupported() bool {
32+
// Supported checks if cimwriter.dll is present on the system.
33+
func Supported() bool {
3434
return modcimwriter.Load() == nil
3535
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package cimwriter
22

3-
//go:generate go run github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go ./*.go
3+
//go:generate go tool github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go ./*.go

internal/winapi/devices.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ package winapi
44

55
import "github.com/Microsoft/go-winio/pkg/guid"
66

7-
//sys CMGetDeviceInterfaceListSize(listlen *uint32, classGUID *g, deviceID *uint16, ulFlags uint32) (hr error) = cfgmgr32.CM_Get_Device_Interface_List_SizeW
8-
//sys CMGetDeviceInterfaceList(classGUID *g, deviceID *uint16, buffer *uint16, bufLen uint32, ulFlags uint32) (hr error) = cfgmgr32.CM_Get_Device_Interface_ListW
7+
//sys CMGetDeviceInterfaceListSize(listlen *uint32, classGUID *GUID, deviceID *uint16, ulFlags uint32) (hr error) = cfgmgr32.CM_Get_Device_Interface_List_SizeW
8+
//sys CMGetDeviceInterfaceList(classGUID *GUID, deviceID *uint16, buffer *uint16, bufLen uint32, ulFlags uint32) (hr error) = cfgmgr32.CM_Get_Device_Interface_ListW
99
//sys CMGetDeviceIDListSize(pulLen *uint32, pszFilter *byte, uFlags uint32) (hr error) = cfgmgr32.CM_Get_Device_ID_List_SizeA
1010
//sys CMGetDeviceIDList(pszFilter *byte, buffer *byte, bufferLen uint32, uFlags uint32) (hr error)= cfgmgr32.CM_Get_Device_ID_ListA
1111
//sys CMLocateDevNode(pdnDevInst *uint32, pDeviceID string, uFlags uint32) (hr error) = cfgmgr32.CM_Locate_DevNodeW
1212
//sys CMGetDevNodeProperty(dnDevInst uint32, propertyKey *DevPropKey, propertyType *uint32, propertyBuffer *uint16, propertyBufferSize *uint32, uFlags uint32) (hr error) = cfgmgr32.CM_Get_DevNode_PropertyW
1313

14+
type GUID = guid.GUID
15+
1416
type DevPropKey struct {
1517
Fmtid guid.GUID
1618
Pid uint32

internal/winapi/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ func ParseUtf16LE(b []byte) string {
8686

8787
// CimFsSupported checks if CIM FS dll is present on the system.
8888
func CimFsSupported() bool {
89-
return cimfs.CimFsSupported()
89+
return cimfs.Supported()
9090
}

internal/winapi/zsyscall_windows.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)