2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _IOPOLLEDINTERFACE_H_
30 #define _IOPOLLEDINTERFACE_H_
33 kIOPolledPreflightState
= 1,
34 kIOPolledBeforeSleepState
= 2,
35 kIOPolledAfterSleepState
= 3,
36 kIOPolledPostflightState
= 4,
38 kIOPolledPreflightCoreDumpState
= 5,
39 kIOPolledPostflightCoreDumpState
= 6,
41 kIOPolledBeforeSleepStateAborted
= 7,
44 #if defined(__cplusplus)
46 #include <libkern/c++/OSObject.h>
47 #include <libkern/c++/OSPtr.h>
48 #include <IOKit/IOMemoryDescriptor.h>
50 #define kIOPolledInterfaceSupportKey "IOPolledInterface"
51 #define kIOPolledInterfaceActiveKey "IOPolledInterfaceActive"
52 #define kIOPolledInterfaceStackKey "IOPolledInterfaceStack"
60 typedef void (*IOPolledCompletionAction
)( void * target
,
63 uint64_t actualByteCount
);
64 struct IOPolledCompletion
{
66 IOPolledCompletionAction action
;
70 class IOPolledInterface
: public OSObject
72 OSDeclareAbstractStructors(IOPolledInterface
);
75 struct ExpansionData
{ };
76 ExpansionData
* reserved
;
79 virtual IOReturn
probe(IOService
* target
) = 0;
81 virtual IOReturn
open( IOOptionBits state
, IOMemoryDescriptor
* buffer
) = 0;
82 virtual IOReturn
close(IOOptionBits state
) = 0;
84 virtual IOReturn
startIO(uint32_t operation
,
85 uint32_t bufferOffset
,
86 uint64_t deviceOffset
,
88 IOPolledCompletion completion
) = 0;
90 virtual IOReturn
checkForWork(void) = 0;
92 virtual IOReturn
setEncryptionKey(const uint8_t * key
, size_t keySize
);
94 OSMetaClassDeclareReservedUsedX86(IOPolledInterface
, 0);
95 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 1);
96 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 2);
97 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 3);
98 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 4);
99 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 5);
100 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 6);
101 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 7);
102 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 8);
103 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 9);
104 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 10);
105 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 11);
106 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 12);
107 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 13);
108 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 14);
109 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 15);
112 #endif /* defined(__cplusplus) */
114 #ifdef XNU_KERNEL_PRIVATE
116 #include <libkern/crypto/aes.h>
117 #include <IOKit/IOTypes.h>
118 #include <IOKit/IOHibernatePrivate.h>
120 // kern_open_file_for_direct_io() flags
122 kIOPolledFileCreate
= 0x00000001,
123 kIOPolledFileHibernate
= 0x00000002,
126 // kern_open_file_for_direct_io() oflags
128 kIOPolledFileSSD
= 0x00000001
131 #if !defined(__cplusplus)
132 typedef struct IORegistryEntry IORegistryEntry
;
133 typedef struct OSData OSData
;
134 typedef struct OSArray OSArray
;
135 typedef struct IOMemoryDescriptor IOMemoryDescriptor
;
136 typedef struct IOPolledFilePollers IOPolledFilePollers
;
138 class IOPolledFilePollers
;
141 struct IOPolledFileIOVars
{
142 IOPolledFilePollers
* pollers
;
143 struct kern_direct_file_io_ref_t
* fileRef
;
144 OSData
* fileExtents
;
148 uint32_t bufferLimit
;
151 uint32_t bufferOffset
;
153 uint64_t extentRemaining
;
159 uint64_t extentPosition
;
160 uint64_t encryptStart
;
163 AbsoluteTime cryptTime
;
164 IOPolledFileExtent
* extentMap
;
165 IOPolledFileExtent
* currentExtent
;
169 typedef struct IOPolledFileIOVars IOPolledFileIOVars
;
171 struct IOPolledFileCryptVars
{
172 uint8_t aes_iv
[AES_BLOCK_SIZE
];
175 typedef struct IOPolledFileCryptVars IOPolledFileCryptVars
;
177 #if defined(__cplusplus)
179 IOReturn
IOPolledFileOpen(const char * filename
,
181 uint64_t setFileSize
, uint64_t fsFreeSize
,
182 void * write_file_addr
, size_t write_file_len
,
183 IOPolledFileIOVars
** fileVars
,
184 LIBKERN_RETURNS_RETAINED OSData
** imagePath
,
185 uint8_t * volumeCryptKey
, size_t * keySize
);
187 IOReturn
IOPolledFileOpen(const char * filename
,
189 uint64_t setFileSize
, uint64_t fsFreeSize
,
190 void * write_file_addr
, size_t write_file_len
,
191 IOPolledFileIOVars
** fileVars
,
192 OSSharedPtr
<OSData
>& imagePath
,
193 uint8_t * volumeCryptKey
, size_t * keySize
);
195 IOReturn
IOPolledFileClose(IOPolledFileIOVars
** pVars
,
196 off_t write_offset
, void * addr
, size_t write_length
,
197 off_t discard_offset
, off_t discard_end
);
199 IOReturn
IOPolledFilePollersSetup(IOPolledFileIOVars
* vars
, uint32_t openState
);
201 LIBKERN_RETURNS_NOT_RETAINED IOMemoryDescriptor
* IOPolledFileGetIOBuffer(IOPolledFileIOVars
* vars
);
203 #endif /* defined(__cplusplus) */
205 #if defined(__cplusplus)
211 extern __C IOReturn
IOPolledFileSeek(IOPolledFileIOVars
* vars
, uint64_t position
);
213 extern __C IOReturn
IOPolledFileWrite(IOPolledFileIOVars
* vars
,
214 const uint8_t * bytes
, IOByteCount size
,
215 IOPolledFileCryptVars
* cryptvars
);
216 extern __C IOReturn
IOPolledFileRead(IOPolledFileIOVars
* vars
,
217 uint8_t * bytes
, IOByteCount size
,
218 IOPolledFileCryptVars
* cryptvars
);
220 extern __C IOReturn
IOPolledFileFlush(IOPolledFileIOVars
* vars
);
222 extern __C IOReturn
IOPolledFilePollersOpen(IOPolledFileIOVars
* vars
, uint32_t state
, bool abortable
);
224 extern __C IOReturn
IOPolledFilePollersClose(IOPolledFileIOVars
* vars
, uint32_t state
);
226 extern __C IOReturn
IOPolledFilePollersSetEncryptionKey(IOPolledFileIOVars
* vars
,
227 const uint8_t * key
, size_t keySize
);
229 extern __C IOPolledFileIOVars
* gCoreFileVars
;
235 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
237 struct kern_direct_file_io_ref_t
*
238 kern_open_file_for_direct_io(const char * name
,
240 kern_get_file_extents_callback_t callback
,
244 off_t write_file_offset
,
245 void * write_file_addr
,
246 size_t write_file_len
,
247 dev_t
* partition_device_result
,
248 dev_t
* image_device_result
,
249 uint64_t * partitionbase_result
,
250 uint64_t * maxiocount_result
,
253 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
,
254 off_t write_offset
, void * addr
, size_t write_length
,
255 off_t discard_offset
, off_t discard_end
);
257 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
259 kern_read_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
262 kern_file_mount(struct kern_direct_file_io_ref_t
* ref
);
265 kIOPolledFileMountChangeMount
= 0x00000101,
266 kIOPolledFileMountChangeUnmount
= 0x00000102,
267 kIOPolledFileMountChangeWillResize
= 0x00000201,
268 kIOPolledFileMountChangeDidResize
= 0x00000202,
270 extern void IOPolledFileMountChange(struct mount
* mp
, uint32_t op
);
274 #endif /* _SYS_CONF_H_ */
276 #endif /* XNU_KERNEL_PRIVATE */
278 #endif /* _IOPOLLEDINTERFACE_H_ */