Skip to content

Commit 2ccfeab

Browse files
committed
support both cimfs and cimwriter dlls
The PR introducing cimwriter.dll was a breaking change, which is fixed in this PR. Add both cimfs.dll and cimwriter.dll syscalls and only use cimwriter.dll when present. Signed-off-by: Maksim An <[email protected]>
1 parent 73fdc96 commit 2ccfeab

File tree

12 files changed

+1169
-537
lines changed

12 files changed

+1169
-537
lines changed

internal/winapi/cimfs.go

Lines changed: 133 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,140 @@
33
package winapi
44

55
import (
6-
"unsafe"
7-
86
"github.com/Microsoft/go-winio/pkg/guid"
9-
"golang.org/x/sys/windows"
7+
8+
"github.com/Microsoft/hcsshim/internal/winapi/cimfs"
9+
"github.com/Microsoft/hcsshim/internal/winapi/cimwriter"
10+
"github.com/Microsoft/hcsshim/internal/winapi/types"
1011
)
1112

1213
type g = guid.GUID
13-
type FsHandle uintptr
14-
type StreamHandle uintptr
15-
16-
type CimFsFileMetadata struct {
17-
Attributes uint32
18-
FileSize int64
19-
20-
CreationTime windows.Filetime
21-
LastWriteTime windows.Filetime
22-
ChangeTime windows.Filetime
23-
LastAccessTime windows.Filetime
24-
25-
SecurityDescriptorBuffer unsafe.Pointer
26-
SecurityDescriptorSize uint32
27-
28-
ReparseDataBuffer unsafe.Pointer
29-
ReparseDataSize uint32
30-
31-
ExtendedAttributes unsafe.Pointer
32-
EACount uint32
33-
}
34-
35-
type CimFsImagePath struct {
36-
ImageDir *uint16
37-
ImageName *uint16
38-
}
39-
40-
//sys CimMountImage(imagePath string, fsName string, flags uint32, volumeID *g) (hr error) = cimfs.CimMountImage?
41-
//sys CimDismountImage(volumeID *g) (hr error) = cimfs.CimDismountImage?
42-
43-
//sys CimCreateImage(imagePath string, oldFSName *uint16, newFSName *uint16, cimFSHandle *FsHandle) (hr error) = cimwriter.CimCreateImage?
44-
//sys CimCreateImage2(imagePath string, flags uint32, oldFSName *uint16, newFSName *uint16, cimFSHandle *FsHandle) (hr error) = cimwriter.CimCreateImage2?
45-
//sys CimCloseImage(cimFSHandle FsHandle) = cimwriter.CimCloseImage?
46-
//sys CimCommitImage(cimFSHandle FsHandle) (hr error) = cimwriter.CimCommitImage?
47-
48-
//sys CimCreateFile(cimFSHandle FsHandle, path string, file *CimFsFileMetadata, cimStreamHandle *StreamHandle) (hr error) = cimwriter.CimCreateFile?
49-
//sys CimCloseStream(cimStreamHandle StreamHandle) (hr error) = cimwriter.CimCloseStream?
50-
//sys CimWriteStream(cimStreamHandle StreamHandle, buffer uintptr, bufferSize uint32) (hr error) = cimwriter.CimWriteStream?
51-
//sys CimDeletePath(cimFSHandle FsHandle, path string) (hr error) = cimwriter.CimDeletePath?
52-
//sys CimCreateHardLink(cimFSHandle FsHandle, newPath string, oldPath string) (hr error) = cimwriter.CimCreateHardLink?
53-
//sys CimCreateAlternateStream(cimFSHandle FsHandle, path string, size uint64, cimStreamHandle *StreamHandle) (hr error) = cimwriter.CimCreateAlternateStream?
54-
//sys CimAddFsToMergedImage(cimFSHandle FsHandle, path string) (hr error) = cimwriter.CimAddFsToMergedImage?
55-
//sys CimAddFsToMergedImage2(cimFSHandle FsHandle, path string, flags uint32) (hr error) = cimwriter.CimAddFsToMergedImage2?
56-
//sys CimMergeMountImage(numCimPaths uint32, backingImagePaths *CimFsImagePath, flags uint32, volumeID *g) (hr error) = cimfs.CimMergeMountImage?
57-
//sys CimTombstoneFile(cimFSHandle FsHandle, path string) (hr error) = cimwriter.CimTombstoneFile?
58-
//sys CimCreateMergeLink(cimFSHandle FsHandle, newPath string, oldPath string) (hr error) = cimwriter.CimCreateMergeLink?
59-
//sys CimSealImage(blockCimPath string, hashSize *uint64, fixedHeaderSize *uint64, hash *byte) (hr error) = cimwriter.CimSealImage?
60-
//sys CimGetVerificationInformation(blockCimPath string, isSealed *uint32, hashSize *uint64, signatureSize *uint64, fixedHeaderSize *uint64, hash *byte, signature *byte) (hr error) = cimfs.CimGetVerificationInformation?
61-
//sys CimMountVerifiedImage(imagePath string, fsName string, flags uint32, volumeID *g, hashSize uint16, hash *byte) (hr error) = cimfs.CimMountVerifiedImage?
62-
//sys CimMergeMountVerifiedImage(numCimPaths uint32, backingImagePaths *CimFsImagePath, flags uint32, volumeID *g, hashSize uint16, hash *byte) (hr error) = cimfs.CimMergeMountVerifiedImage
14+
15+
func CimMountImage(imagePath string, fsName string, flags uint32, volumeID *guid.GUID) error {
16+
return cimfs.CimMountImage(imagePath, fsName, flags, volumeID)
17+
}
18+
19+
func CimDismountImage(volumeID *guid.GUID) error {
20+
return cimfs.CimDismountImage(volumeID)
21+
}
22+
23+
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)
28+
}
29+
30+
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)
35+
}
36+
37+
func CimCloseImage(cimFSHandle types.FsHandle) error {
38+
if cimwriter.CimWriterSupported() {
39+
return cimwriter.CimCloseImage(cimFSHandle)
40+
}
41+
return cimfs.CimCloseImage(cimFSHandle)
42+
}
43+
44+
func CimCommitImage(cimFSHandle types.FsHandle) error {
45+
if cimwriter.CimWriterSupported() {
46+
return cimwriter.CimCommitImage(cimFSHandle)
47+
}
48+
return cimfs.CimCommitImage(cimFSHandle)
49+
}
50+
51+
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)
56+
}
57+
58+
func CimCloseStream(cimStreamHandle types.StreamHandle) error {
59+
if cimwriter.CimWriterSupported() {
60+
return cimwriter.CimCloseStream(cimStreamHandle)
61+
}
62+
return cimfs.CimCloseStream(cimStreamHandle)
63+
}
64+
65+
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)
70+
}
71+
72+
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)
77+
}
78+
79+
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)
84+
}
85+
86+
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)
91+
}
92+
93+
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)
98+
}
99+
100+
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)
105+
}
106+
107+
func CimMergeMountImage(numCimPaths uint32, backingImagePaths *types.CimFsImagePath, flags uint32, volumeID *guid.GUID) error {
108+
return cimfs.CimMergeMountImage(numCimPaths, backingImagePaths, flags, volumeID)
109+
}
110+
111+
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)
116+
}
117+
118+
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)
123+
}
124+
125+
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)
130+
}
131+
132+
func CimGetVerificationInformation(blockCimPath string, isSealed *uint32, hashSize *uint64, signatureSize *uint64, fixedHeaderSize *uint64, hash *byte, signature *byte) (hr error) {
133+
return cimfs.CimGetVerificationInformation(blockCimPath, isSealed, hashSize, signatureSize, fixedHeaderSize, hash, signature)
134+
}
135+
136+
func CimMountVerifiedImage(imagePath string, fsName string, flags uint32, volumeID *guid.GUID, hashSize uint16, hash *byte) error {
137+
return cimfs.CimMountVerifiedImage(imagePath, fsName, flags, volumeID, hashSize, hash)
138+
}
139+
140+
func CimMergeMountVerifiedImage(numCimPaths uint32, backingImagePaths *types.CimFsImagePath, flags uint32, volumeID *guid.GUID, hashSize uint16, hash *byte) error {
141+
return cimfs.CimMergeMountVerifiedImage(numCimPaths, backingImagePaths, flags, volumeID, hashSize, hash)
142+
}

internal/winapi/cimfs/cimfs.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//go:build windows
2+
3+
package cimfs
4+
5+
import (
6+
"github.com/Microsoft/go-winio/pkg/guid"
7+
8+
"github.com/Microsoft/hcsshim/internal/winapi/types"
9+
)
10+
11+
// Type aliases
12+
type g = guid.GUID
13+
type FsHandle = types.FsHandle
14+
type StreamHandle = types.StreamHandle
15+
type FileMetadata = types.CimFsFileMetadata
16+
type ImagePath = types.CimFsImagePath
17+
18+
//sys CimMountImage(imagePath string, fsName string, flags uint32, volumeID *g) (hr error) = cimfs.CimMountImage?
19+
//sys CimDismountImage(volumeID *g) (hr error) = cimfs.CimDismountImage?
20+
21+
//sys CimCreateImage(imagePath string, oldFSName *uint16, newFSName *uint16, cimFSHandle *FsHandle) (hr error) = cimfs.CimCreateImage?
22+
//sys CimCreateImage2(imagePath string, flags uint32, oldFSName *uint16, newFSName *uint16, cimFSHandle *FsHandle) (hr error) = cimfs.CimCreateImage2?
23+
//sys CimCloseImage(cimFSHandle FsHandle) = cimfs.CimCloseImage?
24+
//sys CimCommitImage(cimFSHandle FsHandle) (hr error) = cimfs.CimCommitImage?
25+
26+
//sys CimCreateFile(cimFSHandle FsHandle, path string, file *FileMetadata, cimStreamHandle *StreamHandle) (hr error) = cimfs.CimCreateFile?
27+
//sys CimCloseStream(cimStreamHandle StreamHandle) (hr error) = cimfs.CimCloseStream?
28+
//sys CimWriteStream(cimStreamHandle StreamHandle, buffer uintptr, bufferSize uint32) (hr error) = cimfs.CimWriteStream?
29+
//sys CimDeletePath(cimFSHandle FsHandle, path string) (hr error) = cimfs.CimDeletePath?
30+
//sys CimCreateHardLink(cimFSHandle FsHandle, newPath string, oldPath string) (hr error) = cimfs.CimCreateHardLink?
31+
//sys CimCreateAlternateStream(cimFSHandle FsHandle, path string, size uint64, cimStreamHandle *StreamHandle) (hr error) = cimfs.CimCreateAlternateStream?
32+
//sys CimAddFsToMergedImage(cimFSHandle FsHandle, path string) (hr error) = cimfs.CimAddFsToMergedImage?
33+
//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 CimTombstoneFile(cimFSHandle FsHandle, path string) (hr error) = cimfs.CimTombstoneFile?
36+
//sys CimCreateMergeLink(cimFSHandle FsHandle, newPath string, oldPath string) (hr error) = cimfs.CimCreateMergeLink?
37+
//sys CimSealImage(blockCimPath string, hashSize *uint64, fixedHeaderSize *uint64, hash *byte) (hr error) = cimfs.CimSealImage?
38+
//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
41+
42+
// CimFsSupported checks if cimfs.dll is present on the system.
43+
func CimFsSupported() bool {
44+
return modcimfs.Load() == nil
45+
}

internal/winapi/cimfs/syscall.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package cimfs
2+
3+
//go:generate go run github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go ./*.go

0 commit comments

Comments
 (0)