This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
forked from Code-Hex/vz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtualization_14.m
86 lines (79 loc) · 4.17 KB
/
virtualization_14.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// virtualization_14.m
//
// Created by codehex.
//
#import "virtualization_14.h"
/*!
@abstract Initialize a VZNVMExpressControllerDeviceConfiguration with a device attachment.
@param attachment The storage device attachment. This defines how the virtualized device operates on the host side.
@see VZDiskImageStorageDeviceAttachment
@see https://nvmexpress.org/wp-content/uploads/NVM-Express-1_1b-1.pdf
*/
void *newVZNVMExpressControllerDeviceConfiguration(void *attachment)
{
#ifdef INCLUDE_TARGET_OSX_14
if (@available(macOS 14, *)) {
return [[VZNVMExpressControllerDeviceConfiguration alloc] initWithAttachment:(VZStorageDeviceAttachment *)attachment];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Initialize the disk attachment from a file handle.
@param fileHandle File handle to a block device.
@param readOnly If YES, the disk attachment is read only, otherwise, if the file handle allows writes, the device can write data into it.
@param synchronizationMode Defines how the disk synchronizes with the underlying storage when the guest operating system flushes data.
@param error If not nil, assigned with the error if the initialization failed.
@return An initialized `VZDiskBlockDeviceStorageDeviceAttachment` or nil if there was an error.
@discussion
The file handle is retained by the disk attachment.
The handle must be open when the virtual machine starts.
The `readOnly` parameter affects how the disk is exposed to the guest operating system
by the storage controller. If the disk is intended to be used read-only, it is also recommended
to open the file handle as read-only.
*/
void *newVZDiskBlockDeviceStorageDeviceAttachment(int fileDescriptor, bool readOnly, int syncMode, void **error)
{
#ifdef INCLUDE_TARGET_OSX_14
if (@available(macOS 14, *)) {
NSFileHandle *fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileDescriptor];
return [[VZDiskBlockDeviceStorageDeviceAttachment alloc]
initWithFileHandle:fileHandle
readOnly:(BOOL)readOnly
synchronizationMode:(VZDiskSynchronizationMode)syncMode
error:(NSError *_Nullable *_Nullable)error];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Initialize a network block device storage attachment from an NBD URI.
@param uri The NBD’s URI represented as a URL.
@param timeout The timeout value in seconds for the connection between the client and server. When the timeout expires, an attempt to reconnect with the server takes place.
@param forcedReadOnly If YES, the framework forces the disk attachment to be read-only, regardless of whether or not the NBD server supports write requests.
@param synchronizationMode Defines how the disk synchronizes with the underlying storage when the guest operating system flushes data.
@param error If not nil, assigned with the error if the initialization failed.
@return An initialized `VZDiskBlockDeviceStorageDeviceAttachment` or nil if there was an error.
@discussion
The forcedReadOnly parameter affects how framework exposes the NBD client to the guest operating
system by the storage controller. As part of the NBD protocol, the NBD server advertises whether
or not the disk exposed by the NBD client is read-only during the handshake phase of the protocol.
Setting forcedReadOnly to YES forces the NBD client to show up as read-only to the guest
regardless of whether or not the NBD server advertises itself as read-only.
*/
void *newVZNetworkBlockDeviceStorageDeviceAttachment(const char *uri, double timeout, bool forcedReadOnly, int syncMode, void **error)
{
#ifdef INCLUDE_TARGET_OSX_14
if (@available(macOS 14, *)) {
NSURL *url = [NSURL URLWithString:[NSString stringWithUTF8String:uri]];
return [[VZNetworkBlockDeviceStorageDeviceAttachment alloc]
initWithURL:url
timeout:(NSTimeInterval)timeout
forcedReadOnly:(BOOL)forcedReadOnly
synchronizationMode:(VZDiskSynchronizationMode)syncMode
error:(NSError *_Nullable *_Nullable)error];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}