]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | /* |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
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. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
91447636 A |
27 | */ |
28 | ||
2d21ac55 A |
29 | #ifndef _IOPOLLEDINTERFACE_H_ |
30 | #define _IOPOLLEDINTERFACE_H_ | |
31 | ||
0a7de745 A |
32 | enum{ |
33 | kIOPolledPreflightState = 1, | |
34 | kIOPolledBeforeSleepState = 2, | |
35 | kIOPolledAfterSleepState = 3, | |
36 | kIOPolledPostflightState = 4, | |
3e170ce0 | 37 | |
0a7de745 A |
38 | kIOPolledPreflightCoreDumpState = 5, |
39 | kIOPolledPostflightCoreDumpState = 6, | |
ecc0ceb4 | 40 | |
0a7de745 | 41 | kIOPolledBeforeSleepStateAborted = 7, |
91447636 A |
42 | }; |
43 | ||
3e170ce0 A |
44 | #if defined(__cplusplus) |
45 | ||
46 | #include <libkern/c++/OSObject.h> | |
47 | #include <IOKit/IOMemoryDescriptor.h> | |
48 | ||
49 | #define kIOPolledInterfaceSupportKey "IOPolledInterface" | |
50 | #define kIOPolledInterfaceActiveKey "IOPolledInterfaceActive" | |
51 | #define kIOPolledInterfaceStackKey "IOPolledInterfaceStack" | |
52 | ||
0a7de745 A |
53 | enum{ |
54 | kIOPolledWrite = 1, | |
55 | kIOPolledRead = 2, | |
56 | kIOPolledFlush = 3 | |
91447636 A |
57 | }; |
58 | ||
59 | typedef void (*IOPolledCompletionAction)( void * target, | |
0a7de745 A |
60 | void * parameter, |
61 | IOReturn status, | |
62 | uint64_t actualByteCount); | |
63 | struct IOPolledCompletion { | |
64 | void * target; | |
65 | IOPolledCompletionAction action; | |
66 | void * parameter; | |
91447636 A |
67 | }; |
68 | ||
69 | class IOPolledInterface : public OSObject | |
70 | { | |
0a7de745 | 71 | OSDeclareAbstractStructors(IOPolledInterface); |
91447636 A |
72 | |
73 | protected: | |
0a7de745 A |
74 | struct ExpansionData { }; |
75 | ExpansionData * reserved; | |
91447636 A |
76 | |
77 | public: | |
0a7de745 A |
78 | virtual IOReturn probe(IOService * target) = 0; |
79 | ||
80 | virtual IOReturn open( IOOptionBits state, IOMemoryDescriptor * buffer) = 0; | |
81 | virtual IOReturn close(IOOptionBits state) = 0; | |
82 | ||
83 | virtual IOReturn startIO(uint32_t operation, | |
84 | uint32_t bufferOffset, | |
85 | uint64_t deviceOffset, | |
86 | uint64_t length, | |
87 | IOPolledCompletion completion) = 0; | |
88 | ||
89 | virtual IOReturn checkForWork(void) = 0; | |
90 | ||
91 | virtual IOReturn setEncryptionKey(const uint8_t * key, size_t keySize); | |
92 | ||
93 | OSMetaClassDeclareReservedUsed(IOPolledInterface, 0); | |
94 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 1); | |
95 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 2); | |
96 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 3); | |
97 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 4); | |
98 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 5); | |
99 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 6); | |
100 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 7); | |
101 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 8); | |
102 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 9); | |
103 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 10); | |
104 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 11); | |
105 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 12); | |
106 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 13); | |
107 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 14); | |
108 | OSMetaClassDeclareReservedUnused(IOPolledInterface, 15); | |
91447636 A |
109 | }; |
110 | ||
3e170ce0 A |
111 | #endif /* defined(__cplusplus) */ |
112 | ||
113 | #ifdef XNU_KERNEL_PRIVATE | |
114 | ||
115 | #include <libkern/crypto/aes.h> | |
116 | #include <IOKit/IOTypes.h> | |
117 | #include <IOKit/IOHibernatePrivate.h> | |
118 | ||
d9a64523 | 119 | // kern_open_file_for_direct_io() flags |
0a7de745 A |
120 | enum{ |
121 | kIOPolledFileCreate = 0x00000001, | |
122 | kIOPolledFileHibernate = 0x00000002, | |
d9a64523 A |
123 | }; |
124 | ||
125 | // kern_open_file_for_direct_io() oflags | |
0a7de745 A |
126 | enum{ |
127 | kIOPolledFileSSD = 0x00000001 | |
3e170ce0 A |
128 | }; |
129 | ||
130 | #if !defined(__cplusplus) | |
131 | typedef struct IORegistryEntry IORegistryEntry; | |
132 | typedef struct OSData OSData; | |
133 | typedef struct OSArray OSArray; | |
134 | typedef struct IOMemoryDescriptor IOMemoryDescriptor; | |
135 | typedef struct IOPolledFilePollers IOPolledFilePollers; | |
136 | #else | |
137 | class IOPolledFilePollers; | |
138 | #endif | |
139 | ||
0a7de745 A |
140 | struct IOPolledFileIOVars { |
141 | IOPolledFilePollers * pollers; | |
142 | struct kern_direct_file_io_ref_t * fileRef; | |
143 | OSData * fileExtents; | |
144 | uint64_t block0; | |
145 | IOByteCount blockSize; | |
146 | uint64_t maxiobytes; | |
147 | IOByteCount bufferLimit; | |
148 | uint8_t * buffer; | |
149 | IOByteCount bufferSize; | |
150 | IOByteCount bufferOffset; | |
151 | IOByteCount bufferHalf; | |
152 | IOByteCount extentRemaining; | |
153 | IOByteCount lastRead; | |
154 | IOByteCount readEnd; | |
155 | uint32_t flags; | |
156 | uint64_t fileSize; | |
157 | uint64_t position; | |
158 | uint64_t extentPosition; | |
159 | uint64_t encryptStart; | |
160 | uint64_t encryptEnd; | |
161 | uint64_t cryptBytes; | |
162 | AbsoluteTime cryptTime; | |
163 | IOPolledFileExtent * extentMap; | |
164 | IOPolledFileExtent * currentExtent; | |
165 | bool allocated; | |
3e170ce0 A |
166 | }; |
167 | ||
168 | typedef struct IOPolledFileIOVars IOPolledFileIOVars; | |
169 | ||
0a7de745 A |
170 | struct IOPolledFileCryptVars { |
171 | uint8_t aes_iv[AES_BLOCK_SIZE]; | |
172 | aes_ctx ctx; | |
3e170ce0 A |
173 | }; |
174 | typedef struct IOPolledFileCryptVars IOPolledFileCryptVars; | |
175 | ||
176 | #if defined(__cplusplus) | |
177 | ||
d9a64523 | 178 | IOReturn IOPolledFileOpen(const char * filename, |
0a7de745 A |
179 | uint32_t flags, |
180 | uint64_t setFileSize, uint64_t fsFreeSize, | |
181 | void * write_file_addr, size_t write_file_len, | |
182 | IOPolledFileIOVars ** fileVars, | |
cb323159 | 183 | LIBKERN_RETURNS_RETAINED OSData ** imagePath, |
0a7de745 | 184 | uint8_t * volumeCryptKey, size_t * keySize); |
3e170ce0 A |
185 | |
186 | IOReturn IOPolledFileClose(IOPolledFileIOVars ** pVars, | |
0a7de745 A |
187 | off_t write_offset, void * addr, size_t write_length, |
188 | off_t discard_offset, off_t discard_end); | |
3e170ce0 A |
189 | |
190 | IOReturn IOPolledFilePollersSetup(IOPolledFileIOVars * vars, uint32_t openState); | |
191 | ||
0a7de745 | 192 | LIBKERN_RETURNS_NOT_RETAINED IOMemoryDescriptor * IOPolledFileGetIOBuffer(IOPolledFileIOVars * vars); |
3e170ce0 A |
193 | |
194 | #endif /* defined(__cplusplus) */ | |
195 | ||
196 | #if defined(__cplusplus) | |
0a7de745 | 197 | #define __C "C" |
3e170ce0 A |
198 | #else |
199 | #define __C | |
200 | #endif | |
201 | ||
202 | extern __C IOReturn IOPolledFileSeek(IOPolledFileIOVars * vars, uint64_t position); | |
203 | ||
204 | extern __C IOReturn IOPolledFileWrite(IOPolledFileIOVars * vars, | |
0a7de745 A |
205 | const uint8_t * bytes, IOByteCount size, |
206 | IOPolledFileCryptVars * cryptvars); | |
3e170ce0 | 207 | extern __C IOReturn IOPolledFileRead(IOPolledFileIOVars * vars, |
0a7de745 A |
208 | uint8_t * bytes, IOByteCount size, |
209 | IOPolledFileCryptVars * cryptvars); | |
3e170ce0 | 210 | |
5ba3f43e A |
211 | extern __C IOReturn IOPolledFileFlush(IOPolledFileIOVars * vars); |
212 | ||
3e170ce0 A |
213 | extern __C IOReturn IOPolledFilePollersOpen(IOPolledFileIOVars * vars, uint32_t state, bool abortable); |
214 | ||
215 | extern __C IOReturn IOPolledFilePollersClose(IOPolledFileIOVars * vars, uint32_t state); | |
216 | ||
a39ff7e2 | 217 | extern __C IOReturn IOPolledFilePollersSetEncryptionKey(IOPolledFileIOVars * vars, |
0a7de745 | 218 | const uint8_t * key, size_t keySize); |
a39ff7e2 | 219 | |
3e170ce0 A |
220 | extern __C IOPolledFileIOVars * gCoreFileVars; |
221 | ||
222 | #ifdef _SYS_CONF_H_ | |
223 | ||
224 | __BEGIN_DECLS | |
225 | ||
226 | typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size); | |
227 | ||
228 | struct kern_direct_file_io_ref_t * | |
d9a64523 | 229 | kern_open_file_for_direct_io(const char * name, |
0a7de745 A |
230 | uint32_t flags, |
231 | kern_get_file_extents_callback_t callback, | |
232 | void * callback_ref, | |
233 | off_t set_file_size, | |
234 | off_t fs_free_size, | |
235 | off_t write_file_offset, | |
236 | void * write_file_addr, | |
237 | size_t write_file_len, | |
238 | dev_t * partition_device_result, | |
239 | dev_t * image_device_result, | |
240 | uint64_t * partitionbase_result, | |
241 | uint64_t * maxiocount_result, | |
242 | uint32_t * oflags); | |
3e170ce0 A |
243 | void |
244 | kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref, | |
0a7de745 A |
245 | off_t write_offset, void * addr, size_t write_length, |
246 | off_t discard_offset, off_t discard_end); | |
3e170ce0 A |
247 | int |
248 | kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, void * addr, size_t len, int ioflag); | |
249 | int | |
250 | kern_read_file(struct kern_direct_file_io_ref_t * ref, off_t offset, void * addr, size_t len, int ioflag); | |
251 | ||
252 | struct mount * | |
253 | kern_file_mount(struct kern_direct_file_io_ref_t * ref); | |
254 | ||
0a7de745 A |
255 | enum{ |
256 | kIOPolledFileMountChangeMount = 0x00000101, | |
257 | kIOPolledFileMountChangeUnmount = 0x00000102, | |
258 | kIOPolledFileMountChangeWillResize = 0x00000201, | |
259 | kIOPolledFileMountChangeDidResize = 0x00000202, | |
3e170ce0 A |
260 | }; |
261 | extern void IOPolledFileMountChange(struct mount * mp, uint32_t op); | |
262 | ||
263 | __END_DECLS | |
264 | ||
265 | #endif /* _SYS_CONF_H_ */ | |
266 | ||
267 | #endif /* XNU_KERNEL_PRIVATE */ | |
268 | ||
2d21ac55 | 269 | #endif /* _IOPOLLEDINTERFACE_H_ */ |