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 <IOKit/IOMemoryDescriptor.h>
49 #define kIOPolledInterfaceSupportKey "IOPolledInterface"
50 #define kIOPolledInterfaceActiveKey "IOPolledInterfaceActive"
51 #define kIOPolledInterfaceStackKey "IOPolledInterfaceStack"
59 typedef void (*IOPolledCompletionAction
)( void * target
,
62 uint64_t actualByteCount
);
63 struct IOPolledCompletion
{
65 IOPolledCompletionAction action
;
69 class IOPolledInterface
: public OSObject
71 OSDeclareAbstractStructors(IOPolledInterface
);
74 struct ExpansionData
{ };
75 ExpansionData
* reserved
;
78 virtual IOReturn
probe(IOService
* target
) = 0;
80 virtual IOReturn
open( IOOptionBits state
, IOMemoryDescriptor
* buffer
) = 0;
81 virtual IOReturn
close(IOOptionBits state
) = 0;
83 virtual IOReturn
startIO(uint32_t operation
,
84 uint32_t bufferOffset
,
85 uint64_t deviceOffset
,
87 IOPolledCompletion completion
) = 0;
89 virtual IOReturn
checkForWork(void) = 0;
91 virtual IOReturn
setEncryptionKey(const uint8_t * key
, size_t keySize
);
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);
111 #endif /* defined(__cplusplus) */
113 #ifdef XNU_KERNEL_PRIVATE
115 #include <libkern/crypto/aes.h>
116 #include <IOKit/IOTypes.h>
117 #include <IOKit/IOHibernatePrivate.h>
119 // kern_open_file_for_direct_io() flags
121 kIOPolledFileCreate
= 0x00000001,
122 kIOPolledFileHibernate
= 0x00000002,
125 // kern_open_file_for_direct_io() oflags
127 kIOPolledFileSSD
= 0x00000001
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
;
137 class IOPolledFilePollers
;
140 struct IOPolledFileIOVars
{
141 IOPolledFilePollers
* pollers
;
142 struct kern_direct_file_io_ref_t
* fileRef
;
143 OSData
* fileExtents
;
145 IOByteCount blockSize
;
147 IOByteCount bufferLimit
;
149 IOByteCount bufferSize
;
150 IOByteCount bufferOffset
;
151 IOByteCount bufferHalf
;
152 IOByteCount extentRemaining
;
153 IOByteCount lastRead
;
158 uint64_t extentPosition
;
159 uint64_t encryptStart
;
162 AbsoluteTime cryptTime
;
163 IOPolledFileExtent
* extentMap
;
164 IOPolledFileExtent
* currentExtent
;
168 typedef struct IOPolledFileIOVars IOPolledFileIOVars
;
170 struct IOPolledFileCryptVars
{
171 uint8_t aes_iv
[AES_BLOCK_SIZE
];
174 typedef struct IOPolledFileCryptVars IOPolledFileCryptVars
;
176 #if defined(__cplusplus)
178 IOReturn
IOPolledFileOpen(const char * filename
,
180 uint64_t setFileSize
, uint64_t fsFreeSize
,
181 void * write_file_addr
, size_t write_file_len
,
182 IOPolledFileIOVars
** fileVars
,
184 uint8_t * volumeCryptKey
, size_t * keySize
);
186 IOReturn
IOPolledFileClose(IOPolledFileIOVars
** pVars
,
187 off_t write_offset
, void * addr
, size_t write_length
,
188 off_t discard_offset
, off_t discard_end
);
190 IOReturn
IOPolledFilePollersSetup(IOPolledFileIOVars
* vars
, uint32_t openState
);
192 LIBKERN_RETURNS_NOT_RETAINED IOMemoryDescriptor
* IOPolledFileGetIOBuffer(IOPolledFileIOVars
* vars
);
194 #endif /* defined(__cplusplus) */
196 #if defined(__cplusplus)
202 extern __C IOReturn
IOPolledFileSeek(IOPolledFileIOVars
* vars
, uint64_t position
);
204 extern __C IOReturn
IOPolledFileWrite(IOPolledFileIOVars
* vars
,
205 const uint8_t * bytes
, IOByteCount size
,
206 IOPolledFileCryptVars
* cryptvars
);
207 extern __C IOReturn
IOPolledFileRead(IOPolledFileIOVars
* vars
,
208 uint8_t * bytes
, IOByteCount size
,
209 IOPolledFileCryptVars
* cryptvars
);
211 extern __C IOReturn
IOPolledFileFlush(IOPolledFileIOVars
* vars
);
213 extern __C IOReturn
IOPolledFilePollersOpen(IOPolledFileIOVars
* vars
, uint32_t state
, bool abortable
);
215 extern __C IOReturn
IOPolledFilePollersClose(IOPolledFileIOVars
* vars
, uint32_t state
);
217 extern __C IOReturn
IOPolledFilePollersSetEncryptionKey(IOPolledFileIOVars
* vars
,
218 const uint8_t * key
, size_t keySize
);
220 extern __C IOPolledFileIOVars
* gCoreFileVars
;
226 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
228 struct kern_direct_file_io_ref_t
*
229 kern_open_file_for_direct_io(const char * name
,
231 kern_get_file_extents_callback_t callback
,
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
,
244 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
,
245 off_t write_offset
, void * addr
, size_t write_length
,
246 off_t discard_offset
, off_t discard_end
);
248 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
250 kern_read_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
253 kern_file_mount(struct kern_direct_file_io_ref_t
* ref
);
256 kIOPolledFileMountChangeMount
= 0x00000101,
257 kIOPolledFileMountChangeUnmount
= 0x00000102,
258 kIOPolledFileMountChangeWillResize
= 0x00000201,
259 kIOPolledFileMountChangeDidResize
= 0x00000202,
261 extern void IOPolledFileMountChange(struct mount
* mp
, uint32_t op
);
265 #endif /* _SYS_CONF_H_ */
267 #endif /* XNU_KERNEL_PRIVATE */
269 #endif /* _IOPOLLEDINTERFACE_H_ */