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")]
61extern_conformance!(
62    unsafe impl NSObjectProtocol for VZDiskBlockDeviceStorageDeviceAttachment {}
63);
64
65#[cfg(feature = "VZStorageDeviceAttachment")]
66impl VZDiskBlockDeviceStorageDeviceAttachment {
67    extern_methods!(
68        #[cfg(feature = "VZDiskSynchronizationMode")]
69        /// Initialize the disk attachment from a file handle.
70        ///
71        /// Parameter `fileHandle`: File handle to a block device.
72        ///
73        /// Parameter `readOnly`: If YES, the disk attachment is read only, otherwise, if the file handle allows writes, the device can write data into it.
74        ///
75        /// Parameter `synchronizationMode`: Defines how the disk synchronizes with the underlying storage when the guest operating system flushes data.
76        ///
77        /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
78        ///
79        /// Returns: An initialized `VZDiskBlockDeviceStorageDeviceAttachment` or nil if there was an error.
80        ///
81        /// The file handle is retained by the disk attachment.
82        /// The handle must be open when the virtual machine starts.
83        ///
84        /// The `readOnly` parameter affects how the disk is exposed to the guest operating system
85        /// by the storage controller. If the disk is intended to be used read-only, it is also recommended
86        /// to open the file handle as read-only.
87        #[unsafe(method(initWithFileHandle:readOnly:synchronizationMode:error:_))]
88        #[unsafe(method_family = init)]
89        pub unsafe fn initWithFileHandle_readOnly_synchronizationMode_error(
90            this: Allocated<Self>,
91            file_handle: &NSFileHandle,
92            read_only: bool,
93            synchronization_mode: VZDiskSynchronizationMode,
94        ) -> Result<Retained<Self>, Retained<NSError>>;
95
96        /// File handle to the underlying disk used for storage by the attachment.
97        #[unsafe(method(fileHandle))]
98        #[unsafe(method_family = none)]
99        pub unsafe fn fileHandle(&self) -> Retained<NSFileHandle>;
100
101        /// Whether the underlying disk attachment is read-only.
102        #[unsafe(method(isReadOnly))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn isReadOnly(&self) -> bool;
105
106        #[cfg(feature = "VZDiskSynchronizationMode")]
107        /// The mode in which the disk image synchronizes data with the underlying storage device.
108        #[unsafe(method(synchronizationMode))]
109        #[unsafe(method_family = none)]
110        pub unsafe fn synchronizationMode(&self) -> VZDiskSynchronizationMode;
111    );
112}
113
114/// Methods declared on superclass `VZStorageDeviceAttachment`.
115#[cfg(feature = "VZStorageDeviceAttachment")]
116impl VZDiskBlockDeviceStorageDeviceAttachment {
117    extern_methods!(
118        #[unsafe(method(new))]
119        #[unsafe(method_family = new)]
120        pub unsafe fn new() -> Retained<Self>;
121
122        #[unsafe(method(init))]
123        #[unsafe(method_family = init)]
124        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
125    );
126}