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_
34 kIOPolledPreflightState
= 1,
35 kIOPolledBeforeSleepState
= 2,
36 kIOPolledAfterSleepState
= 3,
37 kIOPolledPostflightState
= 4,
39 kIOPolledPreflightCoreDumpState
= 5,
40 kIOPolledPostflightCoreDumpState
= 6,
42 kIOPolledBeforeSleepStateAborted
= 7,
45 #if defined(__cplusplus)
47 #include <libkern/c++/OSObject.h>
48 #include <IOKit/IOMemoryDescriptor.h>
50 #define kIOPolledInterfaceSupportKey "IOPolledInterface"
51 #define kIOPolledInterfaceActiveKey "IOPolledInterfaceActive"
52 #define kIOPolledInterfaceStackKey "IOPolledInterfaceStack"
61 typedef void (*IOPolledCompletionAction
)( void * target
,
64 uint64_t actualByteCount
);
65 struct IOPolledCompletion
68 IOPolledCompletionAction action
;
72 class IOPolledInterface
: public OSObject
74 OSDeclareAbstractStructors(IOPolledInterface
);
77 struct ExpansionData
{ };
78 ExpansionData
* reserved
;
81 virtual IOReturn
probe(IOService
* target
) = 0;
83 virtual IOReturn
open( IOOptionBits state
, IOMemoryDescriptor
* buffer
) = 0;
84 virtual IOReturn
close(IOOptionBits state
) = 0;
86 virtual IOReturn
startIO(uint32_t operation
,
87 uint32_t bufferOffset
,
88 uint64_t deviceOffset
,
90 IOPolledCompletion completion
) = 0;
92 virtual IOReturn
checkForWork(void) = 0;
94 virtual IOReturn
setEncryptionKey(const uint8_t * key
, size_t keySize
);
96 OSMetaClassDeclareReservedUsed(IOPolledInterface
, 0);
97 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 1);
98 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 2);
99 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 3);
100 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 4);
101 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 5);
102 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 6);
103 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 7);
104 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 8);
105 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 9);
106 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 10);
107 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 11);
108 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 12);
109 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 13);
110 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 14);
111 OSMetaClassDeclareReservedUnused(IOPolledInterface
, 15);
114 #endif /* defined(__cplusplus) */
116 #ifdef XNU_KERNEL_PRIVATE
118 #include <libkern/crypto/aes.h>
119 #include <IOKit/IOTypes.h>
120 #include <IOKit/IOHibernatePrivate.h>
122 // kern_open_file_for_direct_io() flags
125 kIOPolledFileCreate
= 0x00000001,
126 kIOPolledFileHibernate
= 0x00000002,
129 // kern_open_file_for_direct_io() oflags
132 kIOPolledFileSSD
= 0x00000001
135 #if !defined(__cplusplus)
136 typedef struct IORegistryEntry IORegistryEntry
;
137 typedef struct OSData OSData
;
138 typedef struct OSArray OSArray
;
139 typedef struct IOMemoryDescriptor IOMemoryDescriptor
;
140 typedef struct IOPolledFilePollers IOPolledFilePollers
;
142 class IOPolledFilePollers
;
145 struct IOPolledFileIOVars
147 IOPolledFilePollers
* pollers
;
148 struct kern_direct_file_io_ref_t
* fileRef
;
149 OSData
* fileExtents
;
151 IOByteCount blockSize
;
153 IOByteCount bufferLimit
;
155 IOByteCount bufferSize
;
156 IOByteCount bufferOffset
;
157 IOByteCount bufferHalf
;
158 IOByteCount extentRemaining
;
159 IOByteCount lastRead
;
164 uint64_t extentPosition
;
165 uint64_t encryptStart
;
168 AbsoluteTime cryptTime
;
169 IOPolledFileExtent
* extentMap
;
170 IOPolledFileExtent
* currentExtent
;
174 typedef struct IOPolledFileIOVars IOPolledFileIOVars
;
176 struct IOPolledFileCryptVars
178 uint8_t aes_iv
[AES_BLOCK_SIZE
];
181 typedef struct IOPolledFileCryptVars IOPolledFileCryptVars
;
183 #if defined(__cplusplus)
185 IOReturn
IOPolledFileOpen(const char * filename
,
187 uint64_t setFileSize
, uint64_t fsFreeSize
,
188 void * write_file_addr
, size_t write_file_len
,
189 IOPolledFileIOVars
** fileVars
,
191 uint8_t * volumeCryptKey
, size_t * keySize
);
193 IOReturn
IOPolledFileClose(IOPolledFileIOVars
** pVars
,
194 off_t write_offset
, void * addr
, size_t write_length
,
195 off_t discard_offset
, off_t discard_end
);
197 IOReturn
IOPolledFilePollersSetup(IOPolledFileIOVars
* vars
, uint32_t openState
);
199 IOMemoryDescriptor
* IOPolledFileGetIOBuffer(IOPolledFileIOVars
* vars
);
201 #endif /* defined(__cplusplus) */
203 #if defined(__cplusplus)
209 extern __C IOReturn
IOPolledFileSeek(IOPolledFileIOVars
* vars
, uint64_t position
);
211 extern __C IOReturn
IOPolledFileWrite(IOPolledFileIOVars
* vars
,
212 const uint8_t * bytes
, IOByteCount size
,
213 IOPolledFileCryptVars
* cryptvars
);
214 extern __C IOReturn
IOPolledFileRead(IOPolledFileIOVars
* vars
,
215 uint8_t * bytes
, IOByteCount size
,
216 IOPolledFileCryptVars
* cryptvars
);
218 extern __C IOReturn
IOPolledFileFlush(IOPolledFileIOVars
* vars
);
220 extern __C IOReturn
IOPolledFilePollersOpen(IOPolledFileIOVars
* vars
, uint32_t state
, bool abortable
);
222 extern __C IOReturn
IOPolledFilePollersClose(IOPolledFileIOVars
* vars
, uint32_t state
);
224 extern __C IOReturn
IOPolledFilePollersSetEncryptionKey(IOPolledFileIOVars
* vars
,
225 const uint8_t * key
, size_t keySize
);
227 extern __C IOPolledFileIOVars
* gCoreFileVars
;
233 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
235 struct kern_direct_file_io_ref_t
*
236 kern_open_file_for_direct_io(const char * name
,
238 kern_get_file_extents_callback_t callback
,
242 off_t write_file_offset
,
243 void * write_file_addr
,
244 size_t write_file_len
,
245 dev_t
* partition_device_result
,
246 dev_t
* image_device_result
,
247 uint64_t * partitionbase_result
,
248 uint64_t * maxiocount_result
,
251 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
,
252 off_t write_offset
, void * addr
, size_t write_length
,
253 off_t discard_offset
, off_t discard_end
);
255 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
257 kern_read_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
260 kern_file_mount(struct kern_direct_file_io_ref_t
* ref
);
264 kIOPolledFileMountChangeMount
= 0x00000101,
265 kIOPolledFileMountChangeUnmount
= 0x00000102,
266 kIOPolledFileMountChangeWillResize
= 0x00000201,
267 kIOPolledFileMountChangeDidResize
= 0x00000202,
269 extern void IOPolledFileMountChange(struct mount
* mp
, uint32_t op
);
273 #endif /* _SYS_CONF_H_ */
275 #endif /* XNU_KERNEL_PRIVATE */
277 #endif /* _IOPOLLEDINTERFACE_H_ */