objc2_virtualization/generated/VZDiskBlockDeviceStorageDeviceAttachment.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5use objc2_foundation::*;
6
7use crate::*;
8
9extern_class!(
10 /// Storage device attachment using a disk block device to store data.
11 ///
12 /// The disk block device implements a storage attachment by using an actual disk rather than a disk image on a file system.
13 ///
14 /// For example, a disk block device on the disk at `/dev/rdisk42` would execute the I/O operations directly on that disk
15 /// rather than through a file system.
16 ///
17 /// Note that if the disk has a file system formatted on it, the guest is able to destroy data in a way that is not recoverable.
18 /// The disk passed to this attachment needs to be handled with caution.
19 ///
20 /// An example use of this API is:
21 /// ```text
22 /// NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:
23 /// "
24 /// /dev/rdisk42"];
25 /// if (!fileHandle) {
26 /// // Handle errors.
27 /// }
28 ///
29 /// NSError *error;
30 /// VZDiskBlockDeviceStorageDeviceAttachment *attachment =
31 /// [[VZDiskBlockDeviceStorageDeviceAttachment alloc] initWithFileHandle:fileHandle
32 /// readOnly:YES
33 /// synchronizationMode:VZDiskSynchronizationModeFull
34 /// error:error];
35 /// if (!attachment) {
36 /// // Handle errors.
37 /// }
38 /// ```
39 ///
40 /// Disk file handles are typically only accessible by the `root` user unless permission is explicitly granted.
41 /// Running virtual machines as root is not recommended. If `root` access is required to open the file descriptor, it is recommended to do that operation
42 /// in a separate process then pass the file descriptor to a less privileged process running Virtualization framework.
43 ///
44 ///
45 /// See: VZDiskImageStorageDeviceAttachment
46 ///
47 /// See: VZNVMExpressControllerDeviceConfiguration
48 ///
49 /// See: VZUSBMassStorageDeviceConfiguration
50 ///
51 /// See: VZVirtioBlockDeviceConfiguration
52 ///
53 /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vzdiskblockdevicestoragedeviceattachment?language=objc)
54 #[unsafe(super(VZStorageDeviceAttachment, NSObject))]
55 #[derive(Debug, PartialEq, Eq, Hash)]
56 #[cfg(feature = "VZStorageDeviceAttachment")]
57 pub struct VZDiskBlockDeviceStorageDeviceAttachment;
58);
59
60#[cfg(feature = "VZStorageDeviceAttachment")]
61unsafe impl NSObjectProtocol for VZDiskBlockDeviceStorageDeviceAttachment {}
62
63#[cfg(feature = "VZStorageDeviceAttachment")]
64impl VZDiskBlockDeviceStorageDeviceAttachment {
65 extern_methods!(
66 #[cfg(feature = "VZDiskSynchronizationMode")]
67 /// Initialize the disk attachment from a file handle.
68 ///
69 /// Parameter `fileHandle`: File handle to a block device.
70 ///
71 /// Parameter `readOnly`: If YES, the disk attachment is read only, otherwise, if the file handle allows writes, the device can write data into it.
72 ///
73 /// Parameter `synchronizationMode`: Defines how the disk synchronizes with the underlying storage when the guest operating system flushes data.
74 ///
75 /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
76 ///
77 /// Returns: An initialized `VZDiskBlockDeviceStorageDeviceAttachment` or nil if there was an error.
78 ///
79 /// The file handle is retained by the disk attachment.
80 /// The handle must be open when the virtual machine starts.
81 ///
82 /// The `readOnly` parameter affects how the disk is exposed to the guest operating system
83 /// by the storage controller. If the disk is intended to be used read-only, it is also recommended
84 /// to open the file handle as read-only.
85 #[unsafe(method(initWithFileHandle:readOnly:synchronizationMode:error:_))]
86 #[unsafe(method_family = init)]
87 pub unsafe fn initWithFileHandle_readOnly_synchronizationMode_error(
88 this: Allocated<Self>,
89 file_handle: &NSFileHandle,
90 read_only: bool,
91 synchronization_mode: VZDiskSynchronizationMode,
92 ) -> Result<Retained<Self>, Retained<NSError>>;
93
94 /// File handle to the underlying disk used for storage by the attachment.
95 #[unsafe(method(fileHandle))]
96 #[unsafe(method_family = none)]
97 pub unsafe fn fileHandle(&self) -> Retained<NSFileHandle>;
98
99 /// Whether the underlying disk attachment is read-only.
100 #[unsafe(method(isReadOnly))]
101 #[unsafe(method_family = none)]
102 pub unsafe fn isReadOnly(&self) -> bool;
103
104 #[cfg(feature = "VZDiskSynchronizationMode")]
105 /// The mode in which the disk image synchronizes data with the underlying storage device.
106 #[unsafe(method(synchronizationMode))]
107 #[unsafe(method_family = none)]
108 pub unsafe fn synchronizationMode(&self) -> VZDiskSynchronizationMode;
109 );
110}
111
112/// Methods declared on superclass `VZStorageDeviceAttachment`.
113#[cfg(feature = "VZStorageDeviceAttachment")]
114impl VZDiskBlockDeviceStorageDeviceAttachment {
115 extern_methods!(
116 #[unsafe(method(new))]
117 #[unsafe(method_family = new)]
118 pub unsafe fn new() -> Retained<Self>;
119
120 #[unsafe(method(init))]
121 #[unsafe(method_family = init)]
122 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
123 );
124}