1
2
3
4
5 package wclayer
6
7 import (
8 "syscall"
9 "unsafe"
10
11 "golang.org/x/sys/windows"
12 )
13
14 var _ unsafe.Pointer
15
16
17
18 const (
19 errnoERROR_IO_PENDING = 997
20 )
21
22 var (
23 errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
24 errERROR_EINVAL error = syscall.EINVAL
25 )
26
27
28
29 func errnoErr(e syscall.Errno) error {
30 switch e {
31 case 0:
32 return errERROR_EINVAL
33 case errnoERROR_IO_PENDING:
34 return errERROR_IO_PENDING
35 }
36
37
38
39 return e
40 }
41
42 var (
43 modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
44 modvirtdisk = windows.NewLazySystemDLL("virtdisk.dll")
45 modvmcompute = windows.NewLazySystemDLL("vmcompute.dll")
46
47 procGetDiskFreeSpaceExW = modkernel32.NewProc("GetDiskFreeSpaceExW")
48 procAttachVirtualDisk = modvirtdisk.NewProc("AttachVirtualDisk")
49 procOpenVirtualDisk = modvirtdisk.NewProc("OpenVirtualDisk")
50 procActivateLayer = modvmcompute.NewProc("ActivateLayer")
51 procCopyLayer = modvmcompute.NewProc("CopyLayer")
52 procCreateLayer = modvmcompute.NewProc("CreateLayer")
53 procCreateSandboxLayer = modvmcompute.NewProc("CreateSandboxLayer")
54 procDeactivateLayer = modvmcompute.NewProc("DeactivateLayer")
55 procDestroyLayer = modvmcompute.NewProc("DestroyLayer")
56 procExpandSandboxSize = modvmcompute.NewProc("ExpandSandboxSize")
57 procExportLayer = modvmcompute.NewProc("ExportLayer")
58 procGetBaseImages = modvmcompute.NewProc("GetBaseImages")
59 procGetLayerMountPath = modvmcompute.NewProc("GetLayerMountPath")
60 procGrantVmAccess = modvmcompute.NewProc("GrantVmAccess")
61 procImportLayer = modvmcompute.NewProc("ImportLayer")
62 procLayerExists = modvmcompute.NewProc("LayerExists")
63 procNameToGuid = modvmcompute.NewProc("NameToGuid")
64 procPrepareLayer = modvmcompute.NewProc("PrepareLayer")
65 procProcessBaseImage = modvmcompute.NewProc("ProcessBaseImage")
66 procProcessUtilityImage = modvmcompute.NewProc("ProcessUtilityImage")
67 procUnprepareLayer = modvmcompute.NewProc("UnprepareLayer")
68 )
69
70 func getDiskFreeSpaceEx(directoryName string, freeBytesAvailableToCaller *int64, totalNumberOfBytes *int64, totalNumberOfFreeBytes *int64) (err error) {
71 var _p0 *uint16
72 _p0, err = syscall.UTF16PtrFromString(directoryName)
73 if err != nil {
74 return
75 }
76 return _getDiskFreeSpaceEx(_p0, freeBytesAvailableToCaller, totalNumberOfBytes, totalNumberOfFreeBytes)
77 }
78
79 func _getDiskFreeSpaceEx(directoryName *uint16, freeBytesAvailableToCaller *int64, totalNumberOfBytes *int64, totalNumberOfFreeBytes *int64) (err error) {
80 r1, _, e1 := syscall.Syscall6(procGetDiskFreeSpaceExW.Addr(), 4, uintptr(unsafe.Pointer(directoryName)), uintptr(unsafe.Pointer(freeBytesAvailableToCaller)), uintptr(unsafe.Pointer(totalNumberOfBytes)), uintptr(unsafe.Pointer(totalNumberOfFreeBytes)), 0, 0)
81 if r1 == 0 {
82 err = errnoErr(e1)
83 }
84 return
85 }
86
87 func attachVirtualDisk(handle syscall.Handle, sd uintptr, flags uint32, providerFlags uint32, params uintptr, overlapped uintptr) (err error) {
88 r1, _, e1 := syscall.Syscall6(procAttachVirtualDisk.Addr(), 6, uintptr(handle), uintptr(sd), uintptr(flags), uintptr(providerFlags), uintptr(params), uintptr(overlapped))
89 if r1 != 0 {
90 err = errnoErr(e1)
91 }
92 return
93 }
94
95 func openVirtualDisk(virtualStorageType *virtualStorageType, path string, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) {
96 var _p0 *uint16
97 _p0, err = syscall.UTF16PtrFromString(path)
98 if err != nil {
99 return
100 }
101 return _openVirtualDisk(virtualStorageType, _p0, virtualDiskAccessMask, flags, parameters, handle)
102 }
103
104 func _openVirtualDisk(virtualStorageType *virtualStorageType, path *uint16, virtualDiskAccessMask uint32, flags uint32, parameters *openVirtualDiskParameters, handle *syscall.Handle) (err error) {
105 r1, _, e1 := syscall.Syscall6(procOpenVirtualDisk.Addr(), 6, uintptr(unsafe.Pointer(virtualStorageType)), uintptr(unsafe.Pointer(path)), uintptr(virtualDiskAccessMask), uintptr(flags), uintptr(unsafe.Pointer(parameters)), uintptr(unsafe.Pointer(handle)))
106 if r1 != 0 {
107 err = errnoErr(e1)
108 }
109 return
110 }
111
112 func activateLayer(info *driverInfo, id string) (hr error) {
113 var _p0 *uint16
114 _p0, hr = syscall.UTF16PtrFromString(id)
115 if hr != nil {
116 return
117 }
118 return _activateLayer(info, _p0)
119 }
120
121 func _activateLayer(info *driverInfo, id *uint16) (hr error) {
122 hr = procActivateLayer.Find()
123 if hr != nil {
124 return
125 }
126 r0, _, _ := syscall.Syscall(procActivateLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
127 if int32(r0) < 0 {
128 if r0&0x1fff0000 == 0x00070000 {
129 r0 &= 0xffff
130 }
131 hr = syscall.Errno(r0)
132 }
133 return
134 }
135
136 func copyLayer(info *driverInfo, srcId string, dstId string, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
137 var _p0 *uint16
138 _p0, hr = syscall.UTF16PtrFromString(srcId)
139 if hr != nil {
140 return
141 }
142 var _p1 *uint16
143 _p1, hr = syscall.UTF16PtrFromString(dstId)
144 if hr != nil {
145 return
146 }
147 return _copyLayer(info, _p0, _p1, descriptors)
148 }
149
150 func _copyLayer(info *driverInfo, srcId *uint16, dstId *uint16, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
151 hr = procCopyLayer.Find()
152 if hr != nil {
153 return
154 }
155 var _p2 *WC_LAYER_DESCRIPTOR
156 if len(descriptors) > 0 {
157 _p2 = &descriptors[0]
158 }
159 r0, _, _ := syscall.Syscall6(procCopyLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(srcId)), uintptr(unsafe.Pointer(dstId)), uintptr(unsafe.Pointer(_p2)), uintptr(len(descriptors)), 0)
160 if int32(r0) < 0 {
161 if r0&0x1fff0000 == 0x00070000 {
162 r0 &= 0xffff
163 }
164 hr = syscall.Errno(r0)
165 }
166 return
167 }
168
169 func createLayer(info *driverInfo, id string, parent string) (hr error) {
170 var _p0 *uint16
171 _p0, hr = syscall.UTF16PtrFromString(id)
172 if hr != nil {
173 return
174 }
175 var _p1 *uint16
176 _p1, hr = syscall.UTF16PtrFromString(parent)
177 if hr != nil {
178 return
179 }
180 return _createLayer(info, _p0, _p1)
181 }
182
183 func _createLayer(info *driverInfo, id *uint16, parent *uint16) (hr error) {
184 hr = procCreateLayer.Find()
185 if hr != nil {
186 return
187 }
188 r0, _, _ := syscall.Syscall(procCreateLayer.Addr(), 3, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(parent)))
189 if int32(r0) < 0 {
190 if r0&0x1fff0000 == 0x00070000 {
191 r0 &= 0xffff
192 }
193 hr = syscall.Errno(r0)
194 }
195 return
196 }
197
198 func createSandboxLayer(info *driverInfo, id string, parent uintptr, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
199 var _p0 *uint16
200 _p0, hr = syscall.UTF16PtrFromString(id)
201 if hr != nil {
202 return
203 }
204 return _createSandboxLayer(info, _p0, parent, descriptors)
205 }
206
207 func _createSandboxLayer(info *driverInfo, id *uint16, parent uintptr, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
208 hr = procCreateSandboxLayer.Find()
209 if hr != nil {
210 return
211 }
212 var _p1 *WC_LAYER_DESCRIPTOR
213 if len(descriptors) > 0 {
214 _p1 = &descriptors[0]
215 }
216 r0, _, _ := syscall.Syscall6(procCreateSandboxLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(parent), uintptr(unsafe.Pointer(_p1)), uintptr(len(descriptors)), 0)
217 if int32(r0) < 0 {
218 if r0&0x1fff0000 == 0x00070000 {
219 r0 &= 0xffff
220 }
221 hr = syscall.Errno(r0)
222 }
223 return
224 }
225
226 func deactivateLayer(info *driverInfo, id string) (hr error) {
227 var _p0 *uint16
228 _p0, hr = syscall.UTF16PtrFromString(id)
229 if hr != nil {
230 return
231 }
232 return _deactivateLayer(info, _p0)
233 }
234
235 func _deactivateLayer(info *driverInfo, id *uint16) (hr error) {
236 hr = procDeactivateLayer.Find()
237 if hr != nil {
238 return
239 }
240 r0, _, _ := syscall.Syscall(procDeactivateLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
241 if int32(r0) < 0 {
242 if r0&0x1fff0000 == 0x00070000 {
243 r0 &= 0xffff
244 }
245 hr = syscall.Errno(r0)
246 }
247 return
248 }
249
250 func destroyLayer(info *driverInfo, id string) (hr error) {
251 var _p0 *uint16
252 _p0, hr = syscall.UTF16PtrFromString(id)
253 if hr != nil {
254 return
255 }
256 return _destroyLayer(info, _p0)
257 }
258
259 func _destroyLayer(info *driverInfo, id *uint16) (hr error) {
260 hr = procDestroyLayer.Find()
261 if hr != nil {
262 return
263 }
264 r0, _, _ := syscall.Syscall(procDestroyLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
265 if int32(r0) < 0 {
266 if r0&0x1fff0000 == 0x00070000 {
267 r0 &= 0xffff
268 }
269 hr = syscall.Errno(r0)
270 }
271 return
272 }
273
274 func expandSandboxSize(info *driverInfo, id string, size uint64) (hr error) {
275 var _p0 *uint16
276 _p0, hr = syscall.UTF16PtrFromString(id)
277 if hr != nil {
278 return
279 }
280 return _expandSandboxSize(info, _p0, size)
281 }
282
283 func _expandSandboxSize(info *driverInfo, id *uint16, size uint64) (hr error) {
284 hr = procExpandSandboxSize.Find()
285 if hr != nil {
286 return
287 }
288 r0, _, _ := syscall.Syscall(procExpandSandboxSize.Addr(), 3, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(size))
289 if int32(r0) < 0 {
290 if r0&0x1fff0000 == 0x00070000 {
291 r0 &= 0xffff
292 }
293 hr = syscall.Errno(r0)
294 }
295 return
296 }
297
298 func exportLayer(info *driverInfo, id string, path string, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
299 var _p0 *uint16
300 _p0, hr = syscall.UTF16PtrFromString(id)
301 if hr != nil {
302 return
303 }
304 var _p1 *uint16
305 _p1, hr = syscall.UTF16PtrFromString(path)
306 if hr != nil {
307 return
308 }
309 return _exportLayer(info, _p0, _p1, descriptors)
310 }
311
312 func _exportLayer(info *driverInfo, id *uint16, path *uint16, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
313 hr = procExportLayer.Find()
314 if hr != nil {
315 return
316 }
317 var _p2 *WC_LAYER_DESCRIPTOR
318 if len(descriptors) > 0 {
319 _p2 = &descriptors[0]
320 }
321 r0, _, _ := syscall.Syscall6(procExportLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(_p2)), uintptr(len(descriptors)), 0)
322 if int32(r0) < 0 {
323 if r0&0x1fff0000 == 0x00070000 {
324 r0 &= 0xffff
325 }
326 hr = syscall.Errno(r0)
327 }
328 return
329 }
330
331 func getBaseImages(buffer **uint16) (hr error) {
332 hr = procGetBaseImages.Find()
333 if hr != nil {
334 return
335 }
336 r0, _, _ := syscall.Syscall(procGetBaseImages.Addr(), 1, uintptr(unsafe.Pointer(buffer)), 0, 0)
337 if int32(r0) < 0 {
338 if r0&0x1fff0000 == 0x00070000 {
339 r0 &= 0xffff
340 }
341 hr = syscall.Errno(r0)
342 }
343 return
344 }
345
346 func getLayerMountPath(info *driverInfo, id string, length *uintptr, buffer *uint16) (hr error) {
347 var _p0 *uint16
348 _p0, hr = syscall.UTF16PtrFromString(id)
349 if hr != nil {
350 return
351 }
352 return _getLayerMountPath(info, _p0, length, buffer)
353 }
354
355 func _getLayerMountPath(info *driverInfo, id *uint16, length *uintptr, buffer *uint16) (hr error) {
356 hr = procGetLayerMountPath.Find()
357 if hr != nil {
358 return
359 }
360 r0, _, _ := syscall.Syscall6(procGetLayerMountPath.Addr(), 4, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(length)), uintptr(unsafe.Pointer(buffer)), 0, 0)
361 if int32(r0) < 0 {
362 if r0&0x1fff0000 == 0x00070000 {
363 r0 &= 0xffff
364 }
365 hr = syscall.Errno(r0)
366 }
367 return
368 }
369
370 func grantVmAccess(vmid string, filepath string) (hr error) {
371 var _p0 *uint16
372 _p0, hr = syscall.UTF16PtrFromString(vmid)
373 if hr != nil {
374 return
375 }
376 var _p1 *uint16
377 _p1, hr = syscall.UTF16PtrFromString(filepath)
378 if hr != nil {
379 return
380 }
381 return _grantVmAccess(_p0, _p1)
382 }
383
384 func _grantVmAccess(vmid *uint16, filepath *uint16) (hr error) {
385 hr = procGrantVmAccess.Find()
386 if hr != nil {
387 return
388 }
389 r0, _, _ := syscall.Syscall(procGrantVmAccess.Addr(), 2, uintptr(unsafe.Pointer(vmid)), uintptr(unsafe.Pointer(filepath)), 0)
390 if int32(r0) < 0 {
391 if r0&0x1fff0000 == 0x00070000 {
392 r0 &= 0xffff
393 }
394 hr = syscall.Errno(r0)
395 }
396 return
397 }
398
399 func importLayer(info *driverInfo, id string, path string, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
400 var _p0 *uint16
401 _p0, hr = syscall.UTF16PtrFromString(id)
402 if hr != nil {
403 return
404 }
405 var _p1 *uint16
406 _p1, hr = syscall.UTF16PtrFromString(path)
407 if hr != nil {
408 return
409 }
410 return _importLayer(info, _p0, _p1, descriptors)
411 }
412
413 func _importLayer(info *driverInfo, id *uint16, path *uint16, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
414 hr = procImportLayer.Find()
415 if hr != nil {
416 return
417 }
418 var _p2 *WC_LAYER_DESCRIPTOR
419 if len(descriptors) > 0 {
420 _p2 = &descriptors[0]
421 }
422 r0, _, _ := syscall.Syscall6(procImportLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(_p2)), uintptr(len(descriptors)), 0)
423 if int32(r0) < 0 {
424 if r0&0x1fff0000 == 0x00070000 {
425 r0 &= 0xffff
426 }
427 hr = syscall.Errno(r0)
428 }
429 return
430 }
431
432 func layerExists(info *driverInfo, id string, exists *uint32) (hr error) {
433 var _p0 *uint16
434 _p0, hr = syscall.UTF16PtrFromString(id)
435 if hr != nil {
436 return
437 }
438 return _layerExists(info, _p0, exists)
439 }
440
441 func _layerExists(info *driverInfo, id *uint16, exists *uint32) (hr error) {
442 hr = procLayerExists.Find()
443 if hr != nil {
444 return
445 }
446 r0, _, _ := syscall.Syscall(procLayerExists.Addr(), 3, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(exists)))
447 if int32(r0) < 0 {
448 if r0&0x1fff0000 == 0x00070000 {
449 r0 &= 0xffff
450 }
451 hr = syscall.Errno(r0)
452 }
453 return
454 }
455
456 func nameToGuid(name string, guid *_guid) (hr error) {
457 var _p0 *uint16
458 _p0, hr = syscall.UTF16PtrFromString(name)
459 if hr != nil {
460 return
461 }
462 return _nameToGuid(_p0, guid)
463 }
464
465 func _nameToGuid(name *uint16, guid *_guid) (hr error) {
466 hr = procNameToGuid.Find()
467 if hr != nil {
468 return
469 }
470 r0, _, _ := syscall.Syscall(procNameToGuid.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(guid)), 0)
471 if int32(r0) < 0 {
472 if r0&0x1fff0000 == 0x00070000 {
473 r0 &= 0xffff
474 }
475 hr = syscall.Errno(r0)
476 }
477 return
478 }
479
480 func prepareLayer(info *driverInfo, id string, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
481 var _p0 *uint16
482 _p0, hr = syscall.UTF16PtrFromString(id)
483 if hr != nil {
484 return
485 }
486 return _prepareLayer(info, _p0, descriptors)
487 }
488
489 func _prepareLayer(info *driverInfo, id *uint16, descriptors []WC_LAYER_DESCRIPTOR) (hr error) {
490 hr = procPrepareLayer.Find()
491 if hr != nil {
492 return
493 }
494 var _p1 *WC_LAYER_DESCRIPTOR
495 if len(descriptors) > 0 {
496 _p1 = &descriptors[0]
497 }
498 r0, _, _ := syscall.Syscall6(procPrepareLayer.Addr(), 4, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(_p1)), uintptr(len(descriptors)), 0, 0)
499 if int32(r0) < 0 {
500 if r0&0x1fff0000 == 0x00070000 {
501 r0 &= 0xffff
502 }
503 hr = syscall.Errno(r0)
504 }
505 return
506 }
507
508 func processBaseImage(path string) (hr error) {
509 var _p0 *uint16
510 _p0, hr = syscall.UTF16PtrFromString(path)
511 if hr != nil {
512 return
513 }
514 return _processBaseImage(_p0)
515 }
516
517 func _processBaseImage(path *uint16) (hr error) {
518 hr = procProcessBaseImage.Find()
519 if hr != nil {
520 return
521 }
522 r0, _, _ := syscall.Syscall(procProcessBaseImage.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
523 if int32(r0) < 0 {
524 if r0&0x1fff0000 == 0x00070000 {
525 r0 &= 0xffff
526 }
527 hr = syscall.Errno(r0)
528 }
529 return
530 }
531
532 func processUtilityImage(path string) (hr error) {
533 var _p0 *uint16
534 _p0, hr = syscall.UTF16PtrFromString(path)
535 if hr != nil {
536 return
537 }
538 return _processUtilityImage(_p0)
539 }
540
541 func _processUtilityImage(path *uint16) (hr error) {
542 hr = procProcessUtilityImage.Find()
543 if hr != nil {
544 return
545 }
546 r0, _, _ := syscall.Syscall(procProcessUtilityImage.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
547 if int32(r0) < 0 {
548 if r0&0x1fff0000 == 0x00070000 {
549 r0 &= 0xffff
550 }
551 hr = syscall.Errno(r0)
552 }
553 return
554 }
555
556 func unprepareLayer(info *driverInfo, id string) (hr error) {
557 var _p0 *uint16
558 _p0, hr = syscall.UTF16PtrFromString(id)
559 if hr != nil {
560 return
561 }
562 return _unprepareLayer(info, _p0)
563 }
564
565 func _unprepareLayer(info *driverInfo, id *uint16) (hr error) {
566 hr = procUnprepareLayer.Find()
567 if hr != nil {
568 return
569 }
570 r0, _, _ := syscall.Syscall(procUnprepareLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
571 if int32(r0) < 0 {
572 if r0&0x1fff0000 == 0x00070000 {
573 r0 &= 0xffff
574 }
575 hr = syscall.Errno(r0)
576 }
577 return
578 }
579
View as plain text