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>
124 kIOPolledFileSSD
= 0x00000001
127 #if !defined(__cplusplus)
128 typedef struct IORegistryEntry IORegistryEntry
;
129 typedef struct OSData OSData
;
130 typedef struct OSArray OSArray
;
131 typedef struct IOMemoryDescriptor IOMemoryDescriptor
;
132 typedef struct IOPolledFilePollers IOPolledFilePollers
;
134 class IOPolledFilePollers
;
137 struct IOPolledFileIOVars
139 IOPolledFilePollers
* pollers
;
140 struct kern_direct_file_io_ref_t
* fileRef
;
141 OSData
* fileExtents
;
143 IOByteCount blockSize
;
145 IOByteCount bufferLimit
;
147 IOByteCount bufferSize
;
148 IOByteCount bufferOffset
;
149 IOByteCount bufferHalf
;
150 IOByteCount extentRemaining
;
151 IOByteCount lastRead
;
156 uint64_t extentPosition
;
157 uint64_t encryptStart
;
160 AbsoluteTime cryptTime
;
161 IOPolledFileExtent
* extentMap
;
162 IOPolledFileExtent
* currentExtent
;
166 typedef struct IOPolledFileIOVars IOPolledFileIOVars
;
168 struct IOPolledFileCryptVars
170 uint8_t aes_iv
[AES_BLOCK_SIZE
];
173 typedef struct IOPolledFileCryptVars IOPolledFileCryptVars
;
175 #if defined(__cplusplus)
177 IOReturn
IOPolledFileOpen(const char * filename
,
178 uint64_t setFileSize
, uint64_t fsFreeSize
,
179 void * write_file_addr
, size_t write_file_len
,
180 IOPolledFileIOVars
** fileVars
,
182 uint8_t * volumeCryptKey
, size_t * keySize
);
184 IOReturn
IOPolledFileClose(IOPolledFileIOVars
** pVars
,
185 off_t write_offset
, void * addr
, size_t write_length
,
186 off_t discard_offset
, off_t discard_end
);
188 IOReturn
IOPolledFilePollersSetup(IOPolledFileIOVars
* vars
, uint32_t openState
);
190 IOMemoryDescriptor
* IOPolledFileGetIOBuffer(IOPolledFileIOVars
* vars
);
192 #endif /* defined(__cplusplus) */
194 #if defined(__cplusplus)
200 extern __C IOReturn
IOPolledFileSeek(IOPolledFileIOVars
* vars
, uint64_t position
);
202 extern __C IOReturn
IOPolledFileWrite(IOPolledFileIOVars
* vars
,
203 const uint8_t * bytes
, IOByteCount size
,
204 IOPolledFileCryptVars
* cryptvars
);
205 extern __C IOReturn
IOPolledFileRead(IOPolledFileIOVars
* vars
,
206 uint8_t * bytes
, IOByteCount size
,
207 IOPolledFileCryptVars
* cryptvars
);
209 extern __C IOReturn
IOPolledFileFlush(IOPolledFileIOVars
* vars
);
211 extern __C IOReturn
IOPolledFilePollersOpen(IOPolledFileIOVars
* vars
, uint32_t state
, bool abortable
);
213 extern __C IOReturn
IOPolledFilePollersClose(IOPolledFileIOVars
* vars
, uint32_t state
);
215 extern __C IOReturn
IOPolledFilePollersSetEncryptionKey(IOPolledFileIOVars
* vars
,
216 const uint8_t * key
, size_t keySize
);
218 extern __C IOPolledFileIOVars
* gCoreFileVars
;
224 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
226 struct kern_direct_file_io_ref_t
*
227 kern_open_file_for_direct_io(const char * name
, boolean_t create_file
,
228 kern_get_file_extents_callback_t callback
,
232 off_t write_file_offset
,
233 void * write_file_addr
,
234 size_t write_file_len
,
235 dev_t
* partition_device_result
,
236 dev_t
* image_device_result
,
237 uint64_t * partitionbase_result
,
238 uint64_t * maxiocount_result
,
241 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
,
242 off_t write_offset
, void * addr
, size_t write_length
,
243 off_t discard_offset
, off_t discard_end
);
245 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
247 kern_read_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, void * addr
, size_t len
, int ioflag
);
250 kern_file_mount(struct kern_direct_file_io_ref_t
* ref
);
254 kIOPolledFileMountChangeMount
= 0x00000101,
255 kIOPolledFileMountChangeUnmount
= 0x00000102,
256 kIOPolledFileMountChangeWillResize
= 0x00000201,
257 kIOPolledFileMountChangeDidResize
= 0x00000202,
259 extern void IOPolledFileMountChange(struct mount
* mp
, uint32_t op
);
263 #endif /* _SYS_CONF_H_ */
265 #endif /* XNU_KERNEL_PRIVATE */
267 #endif /* _IOPOLLEDINTERFACE_H_ */