disk_arbitration_sys/
disk.rs

1use crate::prelude::*;
2
3#[repr(C)]
4#[derive(Debug, Copy, Clone)]
5pub struct __DADisk {
6    _unused: [u8; 0],
7}
8
9/// Type of a reference to DADisk instances.
10pub type DADiskRef = *mut __DADisk;
11
12/// Options for [`DADiskMount`].
13///
14/// # Constants
15///
16/// * [`kDADiskMountOptionDefault`] - Default option.
17/// * [`kDADiskMountOptionWhole`]   - Mount the volumes tied to the whole disk object.
18pub type DADiskMountOptions = c_uint;
19pub const kDADiskMountOptionDefault: DADiskMountOptions = 0;
20pub const kDADiskMountOptionWhole: DADiskMountOptions = 1;
21
22/// Options for [`DADiskRename`].
23///
24/// # Constants
25///
26/// * [`kDADiskRenameOptionDefault`] - Default option.
27pub type DADiskRenameOptions = c_uint;
28pub const kDADiskRenameOptionDefault: DADiskRenameOptions = 0;
29
30/// Options for [`DADiskUnmount`].
31///
32/// # Constants
33///
34/// * [`kDADiskUnmountOptionDefault`] - Default option.
35/// * [`kDADiskUnmountOptionForce`]   - Unmount the volume even if files are still active.
36/// * [`kDADiskUnmountOptionWhole`]   - Unmount the volumes tied to the whole disk object.
37pub type DADiskUnmountOptions = c_uint;
38pub const kDADiskUnmountOptionDefault: DADiskUnmountOptions = 0;
39pub const kDADiskUnmountOptionForce: DADiskUnmountOptions = 524288;
40pub const kDADiskUnmountOptionWhole: DADiskUnmountOptions = 1;
41
42/// Options for [`DADiskEject`].
43///
44/// # Constants
45///
46/// * [`kDADiskEjectOptionDefault`] - Default option.
47pub type DADiskEjectOptions = c_uint;
48pub const kDADiskEjectOptionDefault: DADiskEjectOptions = 0;
49
50/// Options for [`DADiskClaim`].
51///
52/// # Constants
53///
54/// * [`kDADiskClaimOptionDefault`] - Default option.
55pub type DADiskClaimOptions = c_uint;
56pub const kDADiskClaimOptionDefault: DADiskClaimOptions = 0;
57
58/// Options for [`DADiskGetOptions`] and [`DADiskSetOptions`].
59///
60/// # Constants
61///
62/// * [`kDADiskOptionDefault`] - Default option.
63pub type DADiskOptions = c_uint;
64pub const kDADiskOptionDefault: DADiskOptions = 0;
65
66extern "C" {
67    /// Returns the type identifier of all DADisk instances.
68    pub fn DADiskGetTypeID() -> CFTypeID;
69
70    /// Creates a new disk object.
71    ///
72    /// # Parameters
73    ///
74    /// * `allocator` - The allocator object to be used to allocate memory.
75    /// * `session`   - The DASession in which to contact Disk Arbitration.
76    /// * `name`      - The BSD device name.
77    ///
78    /// # Returns
79    ///
80    /// A reference to a new DADisk.
81    ///
82    /// # Discussion
83    ///
84    /// The caller of this function receives a reference to the returned object.
85    /// The caller also implicitly retains the object and is responsible for
86    /// releasing it with [`CFRelease`].
87    pub fn DADiskCreateFromBSDName(
88        allocator: CFAllocatorRef,
89        session: DASessionRef,
90        name: *const c_char,
91    ) -> DADiskRef;
92
93    /// Creates a new disk object.
94    ///
95    /// # Parameters
96    ///
97    /// * `allocator` - The allocator object to be used to allocate memory.
98    /// * `session`   - The DASession in which to contact Disk Arbitration.
99    /// * `media`     - The I/O Kit media object.
100    ///
101    /// # Returns
102    ///
103    /// A reference to a new DADisk.
104    ///
105    /// # Discussion
106    ///
107    /// The caller of this function receives a reference to the returned object. The
108    /// caller also implicitly retains the object and is responsible for releasing it
109    /// with [`CFRelease`].
110    pub fn DADiskCreateFromIOMedia(
111        allocator: CFAllocatorRef,
112        session: DASessionRef,
113        media: io_service_t,
114    ) -> DADiskRef;
115
116    /// Creates a new disk object.
117    ///
118    /// # Parameters
119    ///
120    /// * `allocator` - The allocator object to be used to allocate memory.
121    /// * `session`   - The DASession in which to contact Disk Arbitration.
122    /// * `path`      - The BSD mount point.
123    ///
124    /// # Returns
125    ///
126    /// A reference to a new DADisk.
127    ///
128    /// # Discussion
129    ///
130    /// The caller of this function receives a reference to the returned object. The
131    /// caller also implicitly retains the object and is responsible for releasing it
132    /// with [`CFRelease`].
133    pub fn DADiskCreateFromVolumePath(
134        allocator: CFAllocatorRef,
135        session: DASessionRef,
136        path: CFURLRef,
137    ) -> DADiskRef;
138
139    /// Obtains the BSD device name for the specified disk.
140    ///
141    /// # Parameters
142    ///
143    /// * `disk` - The DADisk for which to obtain the BSD device name.
144    ///
145    /// # Returns
146    ///
147    /// The disk's BSD device name.
148    ///
149    /// # Discussion
150    ///
151    /// The BSD device name can be used with opendev() to open the BSD device.
152    pub fn DADiskGetBSDName(disk: DADiskRef) -> *const ::std::os::raw::c_char;
153
154    /// Obtains the I/O Kit media object for the specified disk.
155    ///
156    /// # Parameters
157    ///
158    /// * `disk` - The DADisk for which to obtain the I/O Kit media object.
159    ///
160    /// # Returns
161    ///
162    /// The disk's I/O Kit media object.
163    ///
164    /// # Discussion
165    ///
166    /// The caller of this function receives a reference to the returned object. The
167    /// caller also implicitly retains the object and is responsible for releasing it
168    /// with [`IOObjectRelease`].
169    pub fn DADiskCopyIOMedia(disk: DADiskRef) -> io_service_t;
170
171    /// Obtains the Disk Arbitration description of the specified disk.
172    ///
173    /// # Parameters
174    ///
175    /// * `disk` - The DADisk for which to obtain the Disk Arbitration description.
176    ///
177    /// # Returns
178    ///
179    /// The disk's Disk Arbitration description.
180    ///
181    /// # Discussion
182    ///
183    /// This function will contact Disk Arbitration to acquire the latest description
184    /// of the specified disk, unless this function is called on a disk object passed
185    /// within the context of a registered callback, in which case the description is
186    /// current as of that callback event.
187    ///
188    /// The caller of this function receives a reference to the returned object. The
189    /// caller also implicitly retains the object and is responsible for releasing it
190    /// with [`CFRelease`].
191    pub fn DADiskCopyDescription(disk: DADiskRef) -> CFDictionaryRef;
192
193    /// Obtain the associated whole disk object for the specified disk.
194    ///
195    /// # Parameters
196    ///
197    /// * `disk` - The disk object.
198    ///
199    /// # Returns
200    ///
201    /// The disk's associated whole disk object.
202    ///
203    /// # Discussion
204    ///
205    /// The caller of this function receives a reference to the returned object. The
206    /// caller also implicitly retains the object and is responsible for releasing it
207    /// with [`CFRelease`].
208    pub fn DADiskCopyWholeDisk(disk: DADiskRef) -> DADiskRef;
209}
210
211extern "C" {
212    /// Mounts the volume at the specified disk object.
213    ///
214    /// # Parameters
215    ///
216    /// * `disk`     - The disk object.
217    /// * `path`     - The mount path. Pass NULL for a "standard" mount path.
218    /// * `options`  - The mount options.
219    /// * `callback` - The callback function to call once the mount completes.
220    /// * `context`  - The user-defined context parameter to pass to the callback function.
221    pub fn DADiskMount(
222        disk: DADiskRef,
223        path: CFURLRef,
224        options: DADiskMountOptions,
225        callback: DADiskMountCallback,
226        context: *mut c_void,
227    );
228
229    /// Mounts the volume at the specified disk object, with the specified mount options.
230    ///
231    /// # Parameters
232    ///
233    /// * `disk`      - The disk object.
234    /// * `path`      - The mount path. Pass NULL for a "standard" mount path.
235    /// * `options`   - The mount options.
236    /// * `callback`  - The callback function to call once the mount completes.
237    /// * `context`   - The user-defined context parameter to pass to the callback function.
238    /// * `arguments` - The null-terminated list of mount options to pass to `/sbin/mount -o`.
239    pub fn DADiskMountWithArguments(
240        disk: DADiskRef,
241        path: CFURLRef,
242        options: DADiskMountOptions,
243        callback: DADiskMountCallback,
244        context: *mut c_void,
245        arguments: *mut CFStringRef,
246    );
247
248    /// Renames the volume at the specified disk object.
249    ///
250    /// # Parameters
251    ///
252    /// * `disk`     - The disk object.
253    /// * `options`  - The rename options.
254    /// * `callback` - The callback function to call once the rename completes.
255    /// * `context`  - The user-defined context parameter to pass to the callback function.
256    pub fn DADiskRename(
257        disk: DADiskRef,
258        name: CFStringRef,
259        options: DADiskRenameOptions,
260        callback: DADiskRenameCallback,
261        context: *mut c_void,
262    );
263
264    /// Unmounts the volume at the specified disk object.
265    ///
266    /// # Parameters
267    ///
268    /// * `disk`     - The disk object.
269    /// * `options`  - The unmount options.
270    /// * `callback` - The callback function to call once the unmount completes.
271    /// * `context`  - The user-defined context parameter to pass to the callback function.
272    pub fn DADiskUnmount(
273        disk: DADiskRef,
274        options: DADiskUnmountOptions,
275        callback: DADiskUnmountCallback,
276        context: *mut c_void,
277    );
278
279    /// Claims the specified disk object for exclusive use.
280    ///
281    /// # Parameters
282    ///
283    /// * `disk`            - The disk object.
284    /// * `options`         - The claim options.
285    /// * `release`         - The callback function to call when the claim is to be released.
286    /// * `releaseContext`  - The user-defined context parameter to pass to the callback function.
287    /// * `callback`        - The callback function to call once the claim completes.
288    /// * `callbackContext` - The user-defined context parameter to pass to the callback function.
289    pub fn DADiskClaim(
290        disk: DADiskRef,
291        options: DADiskClaimOptions,
292        release: DADiskClaimReleaseCallback,
293        releaseContext: *mut c_void,
294        callback: DADiskClaimCallback,
295        callbackContext: *mut c_void,
296    );
297
298    /// Reports whether or not the disk is claimed.
299    ///
300    /// # Parameters
301    ///
302    /// * `disk` - The disk object.
303    ///
304    /// # Returns
305    ///
306    /// TRUE if the disk is claimed, otherwise FALSE.
307    pub fn DADiskIsClaimed(disk: DADiskRef) -> Boolean;
308
309    /// Unclaims the specified disk object.
310    ///
311    /// # Parameters
312    ///
313    /// * `disk` - The disk object.
314    pub fn DADiskUnclaim(disk: DADiskRef);
315
316    /// Obtains the options for the specified disk.
317    ///
318    /// # Parameters
319    ///
320    /// * `disk` - The disk object for which to obtain the options.
321    ///
322    /// # Returns
323    ///
324    /// The options.
325    pub fn DADiskGetOptions(disk: DADiskRef) -> DADiskOptions;
326
327    /// Sets the options for the specified disk.
328    ///
329    /// # Parameters
330    ///
331    /// * `disk`    - The disk object for which to set the options.
332    /// * `options` - The options to set or clear.
333    /// * `value`   - Pass TRUE to set options; otherwise pass FALSE to clear options.
334    ///
335    /// # Returns
336    ///
337    /// A result code.
338    pub fn DADiskSetOptions(disk: DADiskRef, options: DADiskOptions, value: Boolean) -> DAReturn;
339
340    /// Ejects the specified disk object.
341    ///
342    /// # Parameters
343    ///
344    /// * `disk`     - The disk object.
345    /// * `options`  - The eject options.
346    /// * `callback` - The callback function to call once the ejection completes.
347    /// * `context`  - The user-defined context parameter to pass to the callback function.
348    pub fn DADiskEject(
349        disk: DADiskRef,
350        options: DADiskEjectOptions,
351        callback: DADiskEjectCallback,
352        context: *mut c_void,
353    );
354}
355
356extern "C" {
357    pub static kDADiskDescriptionVolumeKindKey: CFStringRef;
358    pub static kDADiskDescriptionVolumeMountableKey: CFStringRef;
359    pub static kDADiskDescriptionVolumeNameKey: CFStringRef;
360    pub static kDADiskDescriptionVolumeNetworkKey: CFStringRef;
361    pub static kDADiskDescriptionVolumePathKey: CFStringRef;
362    pub static kDADiskDescriptionVolumeTypeKey: CFStringRef;
363    pub static kDADiskDescriptionVolumeUUIDKey: CFStringRef;
364
365    pub static kDADiskDescriptionMediaBSDMajorKey: CFStringRef;
366    pub static kDADiskDescriptionMediaBSDMinorKey: CFStringRef;
367    pub static kDADiskDescriptionMediaBSDNameKey: CFStringRef;
368    pub static kDADiskDescriptionMediaBSDUnitKey: CFStringRef;
369    pub static kDADiskDescriptionMediaBlockSizeKey: CFStringRef;
370    pub static kDADiskDescriptionMediaContentKey: CFStringRef;
371    pub static kDADiskDescriptionMediaEjectableKey: CFStringRef;
372    pub static kDADiskDescriptionMediaIconKey: CFStringRef;
373    pub static kDADiskDescriptionMediaKindKey: CFStringRef;
374    pub static kDADiskDescriptionMediaLeafKey: CFStringRef;
375    pub static kDADiskDescriptionMediaNameKey: CFStringRef;
376    pub static kDADiskDescriptionMediaPathKey: CFStringRef;
377    pub static kDADiskDescriptionMediaRemovableKey: CFStringRef;
378    pub static kDADiskDescriptionMediaSizeKey: CFStringRef;
379    pub static kDADiskDescriptionMediaTypeKey: CFStringRef;
380    pub static kDADiskDescriptionMediaUUIDKey: CFStringRef;
381    pub static kDADiskDescriptionMediaWholeKey: CFStringRef;
382    pub static kDADiskDescriptionMediaWritableKey: CFStringRef;
383
384    pub static kDADiskDescriptionDeviceGUIDKey: CFStringRef;
385    pub static kDADiskDescriptionDeviceInternalKey: CFStringRef;
386    pub static kDADiskDescriptionDeviceModelKey: CFStringRef;
387    pub static kDADiskDescriptionDevicePathKey: CFStringRef;
388    pub static kDADiskDescriptionDeviceProtocolKey: CFStringRef;
389    pub static kDADiskDescriptionDeviceRevisionKey: CFStringRef;
390    pub static kDADiskDescriptionDeviceUnitKey: CFStringRef;
391    pub static kDADiskDescriptionDeviceVendorKey: CFStringRef;
392
393    pub static kDADiskDescriptionBusNameKey: CFStringRef;
394    pub static kDADiskDescriptionBusPathKey: CFStringRef;
395}
396
397#[cfg(feature = "macos_10_14_4_features")]
398extern "C" {
399    pub static kDADiskDescriptionDeviceTDMLockedKey: CFStringRef;
400    pub static kDADiskDescriptionMediaEncryptedKey: CFStringRef;
401    pub static kDADiskDescriptionMediaEncryptionDetailKey: CFStringRef;
402}
403
404extern "C" {
405    /// Predefined CFDictionary object containing a set of disk description keys and values
406    /// appropriate for matching unformatted media using DARegister*Callback.
407    pub static mut kDADiskDescriptionMatchMediaUnformatted: CFDictionaryRef;
408
409    /// Predefined CFDictionary object containing a set of disk description keys and values
410    /// appropriate for matching whole media using DARegister*Callback.
411    pub static mut kDADiskDescriptionMatchMediaWhole: CFDictionaryRef;
412
413    /// Predefined CFDictionary object containing a set of disk description keys and values
414    /// appropriate for matching mountable volumes using DARegister*Callback.
415    pub static mut kDADiskDescriptionMatchVolumeMountable: CFDictionaryRef;
416
417    /// Predefined CFDictionary object containing a set of disk description keys and values
418    /// appropriate for matching unrecognized volumes using DARegister*Callback.
419    pub static mut kDADiskDescriptionMatchVolumeUnrecognized: CFDictionaryRef;
420
421    /// Predefined CFArray object containing a set of disk description keys appropriate for
422    /// watching volume name changes using DARegisterDiskDescriptionChangedCallback.
423    pub static mut kDADiskDescriptionWatchVolumeName: CFArrayRef;
424
425    /// Predefined CFArray object containing a set of disk description keys appropriate for
426    /// watching volume mount changes using DARegisterDiskDescriptionChangedCallback.
427    pub static mut kDADiskDescriptionWatchVolumePath: CFArrayRef;
428}