objc2_fs_kit/generated/
FSVolumeExtent.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// A unique identifier for an operation.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/fskit/fsoperationid?language=objc)
13// NS_TYPED_EXTENSIBLE_ENUM
14pub type FSOperationID = NSUInteger;
15
16extern "C" {
17    /// [Apple's documentation](https://developer.apple.com/documentation/fskit/fsoperationidunspecified?language=objc)
18    pub static FSOperationIDUnspecified: FSOperationID;
19}
20
21/// Flags that describe the behavior of a blockmap operation.
22///
23/// This type is an option set in Swift.
24/// In Objective-C, you use the cases of this enumeration to create a bit field.
25///
26/// See also [Apple's documentation](https://developer.apple.com/documentation/fskit/fsblockmapflags?language=objc)
27// NS_OPTIONS
28#[repr(transparent)]
29#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
30pub struct FSBlockmapFlags(pub NSUInteger);
31bitflags::bitflags! {
32    impl FSBlockmapFlags: NSUInteger {
33/// A flag that describes a read operation.
34        #[doc(alias = "FSBlockmapFlagsRead")]
35        const Read = 0x000100;
36/// A flag that describes a write operation.
37        #[doc(alias = "FSBlockmapFlagsWrite")]
38        const Write = 0x000200;
39    }
40}
41
42unsafe impl Encode for FSBlockmapFlags {
43    const ENCODING: Encoding = NSUInteger::ENCODING;
44}
45
46unsafe impl RefEncode for FSBlockmapFlags {
47    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
48}
49
50/// Flags that describe the behavior of an I/O completion operation.
51///
52/// This type is an option set in Swift.
53/// In Objective-C, the cases of this enumeration combine to create a bit field.
54///
55/// See also [Apple's documentation](https://developer.apple.com/documentation/fskit/fscompleteioflags?language=objc)
56// NS_OPTIONS
57#[repr(transparent)]
58#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
59pub struct FSCompleteIOFlags(pub NSUInteger);
60bitflags::bitflags! {
61    impl FSCompleteIOFlags: NSUInteger {
62/// A flag that describes a read operation.
63        #[doc(alias = "FSCompleteIOFlagsRead")]
64        const Read = FSBlockmapFlags::Read.0;
65/// A flag that describes a write operation.
66        #[doc(alias = "FSCompleteIOFlagsWrite")]
67        const Write = FSBlockmapFlags::Write.0;
68/// A flag that requests that the file system module flush metadata I/O asynchronously.
69        #[doc(alias = "FSCompleteIOFlagsAsync")]
70        const Async = 0x000400;
71    }
72}
73
74unsafe impl Encode for FSCompleteIOFlags {
75    const ENCODING: Encoding = NSUInteger::ENCODING;
76}
77
78unsafe impl RefEncode for FSCompleteIOFlags {
79    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
80}
81
82/// An enumeration of types of extents.
83///
84/// See also [Apple's documentation](https://developer.apple.com/documentation/fskit/fsextenttype?language=objc)
85// NS_ENUM
86#[repr(transparent)]
87#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
88pub struct FSExtentType(pub NSInteger);
89impl FSExtentType {
90    /// An extent type to indicate valid data.
91    ///
92    /// Use this type for all extents on a file system that doesn't support sparse files.
93    ///
94    /// > Tip: The kernel keeps track of the end of file, so it knows a range of `[EOF, allocated space]` is uninitialized. Because of this behavior, it's valid to pass the data extent type for such a range.
95    #[doc(alias = "FSExtentTypeData")]
96    pub const Data: Self = Self(0);
97    /// An extent type to indicate uninitialized data.
98    ///
99    /// Only use this extent type in file systems that support sparse files, and only then to represent ranges in the file that aren't allocated yet.
100    #[doc(alias = "FSExtentTypeZeroFill")]
101    pub const ZeroFill: Self = Self(1);
102}
103
104unsafe impl Encode for FSExtentType {
105    const ENCODING: Encoding = NSInteger::ENCODING;
106}
107
108unsafe impl RefEncode for FSExtentType {
109    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
110}
111
112extern_class!(
113    /// A type that directs the kernel to map space on disk to a specific file managed by this file system.
114    ///
115    /// _Extents_ provide the kernel the logical-to-physical mapping of a given file.
116    /// An extent describes a physical offset on disk, and a length and a logical offset within the file.
117    /// Rather than working with extents directly, you use this type's methods to provide or "pack" extent information, which FSKit then passes to the kernel.
118    ///
119    /// See also [Apple's documentation](https://developer.apple.com/documentation/fskit/fsextentpacker?language=objc)
120    #[unsafe(super(NSObject))]
121    #[derive(Debug, PartialEq, Eq, Hash)]
122    pub struct FSExtentPacker;
123);
124
125extern_conformance!(
126    unsafe impl NSObjectProtocol for FSExtentPacker {}
127);
128
129impl FSExtentPacker {
130    extern_methods!(
131        #[unsafe(method(init))]
132        #[unsafe(method_family = init)]
133        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
134
135        #[cfg(all(feature = "FSResource", feature = "libc"))]
136        /// Packs a single extent to send to the kernel.
137        ///
138        /// - Parameters:
139        /// - resource: The resource on which to perform I/O.
140        /// - type: The type of extent, indicating whether it contains valid data.
141        /// - logicalOffset: The extent offset within the file, in bytes.
142        /// - physicalOffset: The extent offset on disk, in bytes.
143        /// - length: The extent length, in bytes.
144        /// - Returns: A Boolean value that indicates whether the packer can pack more extents.
145        #[unsafe(method(packExtentWithResource:type:logicalOffset:physicalOffset:length:))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn packExtentWithResource_type_logicalOffset_physicalOffset_length(
148            &self,
149            resource: &FSBlockDeviceResource,
150            r#type: FSExtentType,
151            logical_offset: libc::off_t,
152            physical_offset: libc::off_t,
153            length: usize,
154        ) -> bool;
155    );
156}
157
158/// Methods declared on superclass `NSObject`.
159impl FSExtentPacker {
160    extern_methods!(
161        #[unsafe(method(new))]
162        #[unsafe(method_family = new)]
163        pub unsafe fn new() -> Retained<Self>;
164    );
165}
166
167extern_protocol!(
168    /// Methods and properties implemented by volumes that use kernel-offloaded I/O to achieve higher file transfer performance.
169    ///
170    /// A volume that conforms to this protocol supplies file extent mappings to FSKit, which allows file transfers to take place in the kernel.
171    /// This approach provides higher-performance file transfer than transferring data between the module and kernel, while still allowing the file system to run in user space.
172    ///
173    /// This protocol uses _extents_ to provide the kernel the logical-to-physical mapping of a given file.
174    /// An extent describes a physical offset on disk, and a length and a logical offset within the file.
175    /// You don't manage extents directly.
176    /// Instead, FSKit provides you with an ``FSExtentPacker`` to define and pack the extents in your implementations of this protocol's methods.
177    ///
178    /// Most volumes conform to either this protocol or ``FSVolumeReadWriteOperations``.
179    /// You can conform to both if you need to provide kernel-offloaded I/O only for certain files.
180    /// In that case, files with the ``FSItem/Attribute/inhibitKernelOffloadedIO`` attribute set use ``FSVolumeReadWriteOperations``, and those without it use this protocol.
181    /// A volume that doesn't conform to either protocol can't support any I/O operation.
182    ///
183    /// See also [Apple's documentation](https://developer.apple.com/documentation/fskit/fsvolumekerneloffloadediooperations?language=objc)
184    pub unsafe trait FSVolumeKernelOffloadedIOOperations: NSObjectProtocol {
185        #[cfg(all(feature = "FSItem", feature = "block2", feature = "libc"))]
186        /// Maps a file's disk space into extents, allowing the kernel to perform I/O with that space.
187        ///
188        /// FSKit calls this method when the kernel needs to get a mapping of logical-to-physical offsets of the file's data.
189        /// This call may occur as part of an I/O operation on the file, or just to get the mapping as part of a `fcntl(F_LOG2PHYS)` system call.
190        /// In the case of an I/O operation on the file, `operationID` has a nonzero value; a future call to ``completeIO(for:offset:length:status:flags:operationID:replyHandler:)`` uses the same `operationID` to indicate which operation it completes.
191        /// In the case of a `fcntl(F_LOG2PHYS)` system call, the `operationID` parameter is `0` (Objective-C) or ``FSOperationID/unspecified`` (Swift).
192        /// In both cases the kernel retains the mapping, and it may perform I/O to this range (or a part of it) at any time.
193        ///
194        /// If satisfying a blockmap request requires more extents than `packer` can handle, FSKit makes additional calls to this method with the same operation ID to collect the remainder.
195        ///
196        /// - Parameters:
197        /// - file: The file for which to map disk space.
198        /// - offset: The starting logical offset of the range to be mapped (in bytes).
199        /// - length: The length of the range to be mapped (in bytes).
200        /// - flags: Flags that affect the behavior of the blockmap operation.
201        /// - operationID: A unique identifier of the blockmap call. Any value other than `0` (Objective-C) or ``FSOperationID/unspecified`` (Swift) indicates the beginning of an I/O operation. A value of `0` or ``FSOperationID/unspecified`` indicates the kernel maps the file without performing I/O. In this case, FSKit doesn't perform a corresponding call to ``completeIO(for:offset:length:status:flags:operationID:replyHandler:)``.
202        /// - packer: An extent packer you use to pack the requested range of the file's allocated disk space. FSKit sends all of the packed extents to the kernel when it invokes `reply`.
203        /// - reply: A block or closure to indicate success or failure. If mapping fails, pass an error as the one parameter to the reply handler. If mapping succeeds, pass `nil`. For an `async` Swift implementation, there's no reply handler; simply throw an error or return normally.
204        #[unsafe(method(blockmapFile:offset:length:flags:operationID:packer:replyHandler:))]
205        #[unsafe(method_family = none)]
206        unsafe fn blockmapFile_offset_length_flags_operationID_packer_replyHandler(
207            &self,
208            file: &FSItem,
209            offset: libc::off_t,
210            length: usize,
211            flags: FSBlockmapFlags,
212            operation_id: FSOperationID,
213            packer: &FSExtentPacker,
214            reply: &block2::DynBlock<dyn Fn(*mut NSError)>,
215        );
216
217        #[cfg(all(feature = "FSItem", feature = "block2", feature = "libc"))]
218        /// Completes an I/O operation for a given file.
219        ///
220        /// Implement this method by updating a file's metadata, such as its size and modification time.
221        ///
222        /// FSKit may call this method without an earlier call to ``blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:)``.
223        /// In this case, the `operationID` is `0` (Objective-C) or ``FSOperationID/unspecified`` (Swift).
224        ///
225        /// - Parameters:
226        /// - file: The file for which the I/O operation completed.
227        /// - offset: The starting logical offset at which I/O started.
228        /// - length: The length of the I/O range (in bytes).
229        /// - status: Any error that occurred during the operation. If no error occurred, this parameter is `nil`.
230        /// - flags: Flags that affect the behavior of the complete I/O operation.
231        /// - operationID: A unique identifier of the blockmap call. Any value other than `0` (Objective-C) or ``FSOperationID/unspecified`` (Swift) corresponds to a previous call to ``blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:)`` with the same `operationID`.
232        /// - reply: A block or closure to indicate success or failure. If completing I/O fails, pass an error as the one parameter to the reply handler. If completing I/O succeeds, pass `nil`. For an `async` Swift implementation, there's no reply handler; simply throw an error or return normally.
233        #[unsafe(method(completeIOForFile:offset:length:status:flags:operationID:replyHandler:))]
234        #[unsafe(method_family = none)]
235        unsafe fn completeIOForFile_offset_length_status_flags_operationID_replyHandler(
236            &self,
237            file: &FSItem,
238            offset: libc::off_t,
239            length: usize,
240            status: &NSError,
241            flags: FSCompleteIOFlags,
242            operation_id: FSOperationID,
243            reply: &block2::DynBlock<dyn Fn(*mut NSError)>,
244        );
245
246        #[cfg(all(feature = "FSFileName", feature = "FSItem", feature = "block2"))]
247        /// Creates a new file item and map its disk space.
248        ///
249        /// This method allows the module to opportunistically supply extents, avoiding future calls to ``blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:)``.
250        /// Only perform this technique opportunistically.
251        /// In particular, don't perform additional I/O to fetch extent data.
252        ///
253        /// Packing extents in this method requires that `attributes` defines a size greater than 0.
254        ///
255        /// An implementation that doesn't supply the extents can ignore the packer and call the corresponding method in the ``FSVolume/Operations`` protocol, ``FSVolume/Operations/createItem(named:type:inDirectory:attributes:replyHandler:)``.
256        ///
257        /// - Parameters:
258        /// - name: The new file's name.
259        /// - directory: The directory in which to create the file.
260        /// - attributes: Attributes to apply to the new file.
261        /// - packer: An extent packer you use to pack the file's allocated disk space.
262        /// - reply: A block or closure to indicate success or failure. If creation succeeds, pass the newly created ``FSItem`` and its ``FSFileName``, along with a `nil` error. If creation fails, pass the relevant error as the third parameter; FSKit ignores any ``FSItem`` or ``FSFileName`` in this case. For an `async` Swift implementation, there's no reply handler; instead, return a tuple of the ``FSItem`` and its ``FSFileName`` or throw an error.
263        #[unsafe(method(createFileNamed:inDirectory:attributes:packer:replyHandler:))]
264        #[unsafe(method_family = none)]
265        unsafe fn createFileNamed_inDirectory_attributes_packer_replyHandler(
266            &self,
267            name: &FSFileName,
268            directory: &FSItem,
269            attributes: &FSItemSetAttributesRequest,
270            packer: &FSExtentPacker,
271            reply: &block2::DynBlock<dyn Fn(*mut FSItem, *mut FSFileName, *mut NSError)>,
272        );
273
274        #[cfg(all(feature = "FSFileName", feature = "FSItem", feature = "block2"))]
275        /// Looks up an item within a directory and maps its disk space.
276        ///
277        /// This method allows the module to opportunistically supply extents, avoiding future calls to ``blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:)``.
278        /// Only perform this technique opportunistically.
279        /// In particular, don't perform additional I/O to fetch extent data.
280        ///
281        /// - Parameters:
282        /// - name: The name of the file to look up.
283        /// - directory: The directory in which to look up the file.
284        /// - packer: An extent packer you use to pack the file's allocated disk space.
285        /// - reply: A block or closure to indicate success or failure. If lookup succeeds, pass the found ``FSItem`` and its ``FSFileName``, along with a `nil` error. If lookup fails, pass the relevant error as the third parameter; FSKit ignores any ``FSItem`` or ``FSFileName`` in this case. For an `async` Swift implementation, there's no reply handler; instead, return a tuple of the ``FSItem`` and its ``FSFileName`` or throw an error.
286        #[unsafe(method(lookupItemNamed:inDirectory:packer:replyHandler:))]
287        #[unsafe(method_family = none)]
288        unsafe fn lookupItemNamed_inDirectory_packer_replyHandler(
289            &self,
290            name: &FSFileName,
291            directory: &FSItem,
292            packer: &FSExtentPacker,
293            reply: &block2::DynBlock<dyn Fn(*mut FSItem, *mut FSFileName, *mut NSError)>,
294        );
295
296        #[cfg(all(
297            feature = "FSItem",
298            feature = "FSVolume",
299            feature = "block2",
300            feature = "libc"
301        ))]
302        /// Preallocates and maps disk space for the given file.
303        ///
304        /// This method allows the module to opportunistically supply extents, avoiding future calls to ``blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:)``.
305        ///
306        /// > Important: Only implement this method if your file system conforms to ``FSVolume/PreallocateOperations``.
307        ///
308        /// - Parameters:
309        /// - file: The item for which to preallocate space.
310        /// - offset: The offset from which to allocate.
311        /// - length: The length of the space in bytes.
312        /// - flags: Flags that affect the preallocation behavior.
313        /// - packer: An extent packer you use to pack the file's preallocated disk space.
314        /// - reply: A block or closure to indicate success or failure. If preallocation succeeds, pass the amount of bytes allocated and a nil error. If preallocation fails, pass the relevant error as the second parameter; FSKit ignores any byte count in this case. For an `async` Swift implementation, there’s no reply handler; simply return the allocated byte count or throw an error.
315        #[optional]
316        #[unsafe(method(preallocateSpaceForFile:atOffset:length:flags:packer:replyHandler:))]
317        #[unsafe(method_family = none)]
318        unsafe fn preallocateSpaceForFile_atOffset_length_flags_packer_replyHandler(
319            &self,
320            file: &FSItem,
321            offset: libc::off_t,
322            length: usize,
323            flags: FSPreallocateFlags,
324            packer: &FSExtentPacker,
325            reply: &block2::DynBlock<dyn Fn(usize, *mut NSError)>,
326        );
327    }
328);