-
Notifications
You must be signed in to change notification settings - Fork 6
/
IOFilterScheme.cpp
268 lines (238 loc) · 10.4 KB
/
IOFilterScheme.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* Copyright (c) 1998-2014 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <IOKit/storage/IOFilterScheme.h>
#define super IOStorage
OSDefineMetaClassAndStructors(IOFilterScheme, IOStorage)
IOMedia * IOFilterScheme::getProvider() const
{
//
// Obtain this object's provider. We override the superclass's method
// to return a more specific subclass of OSObject -- an IOMedia. This
// method serves simply as a convenience to subclass developers.
//
return (IOMedia *) IOService::getProvider();
}
bool IOFilterScheme::handleOpen(IOService * client,
IOOptionBits options,
void * argument)
{
//
// The handleOpen method grants or denies permission to access this object
// to an interested client. The argument is an IOStorageAccess value that
// specifies the level of access desired -- reader or reader-writer.
//
// This method can be invoked to upgrade or downgrade the access level for
// an existing client as well. The previous access level will prevail for
// upgrades that fail, of course. A downgrade should never fail. If the
// new access level should be the same as the old for a given client, this
// method will do nothing and return success. In all cases, one, singular
// close-per-client is expected for all opens-per-client received.
//
// This implementation replaces the IOService definition of handleOpen().
//
// We are guaranteed that no other opens or closes will be processed until
// we make our decision, change our state, and return from this method.
//
return getProvider()->open(this, options, (IOStorageAccess) (uintptr_t) argument);
}
bool IOFilterScheme::handleIsOpen(const IOService * client) const
{
//
// The handleIsOpen method determines whether the specified client, or any
// client if none is specificed, presently has an open on this object.
//
// This implementation replaces the IOService definition of handleIsOpen().
//
// We are guaranteed that no other opens or closes will be processed until
// we return from this method.
//
return getProvider()->isOpen(this);
}
void IOFilterScheme::handleClose(IOService * client, IOOptionBits options)
{
//
// The handleClose method closes the client's access to this object.
//
// This implementation replaces the IOService definition of handleClose().
//
// We are guaranteed that no other opens or closes will be processed until
// we change our state and return from this method.
//
getProvider()->close(this, options);
}
void IOFilterScheme::read(IOService * client,
UInt64 byteStart,
IOMemoryDescriptor * buffer,
IOStorageAttributes * attributes,
IOStorageCompletion * completion)
{
//
// Read data from the storage object at the specified byte offset into the
// specified buffer, asynchronously. When the read completes, the caller
// will be notified via the specified completion action.
//
// The buffer will be retained for the duration of the read.
//
// For simple filter schemes, the default behavior is to simply pass the
// read through to the provider media. More complex filter schemes such
// as RAID will need to do extra processing here.
//
getProvider( )->read( this, byteStart, buffer, attributes, completion );
}
void IOFilterScheme::write(IOService * client,
UInt64 byteStart,
IOMemoryDescriptor * buffer,
IOStorageAttributes * attributes,
IOStorageCompletion * completion)
{
//
// Write data into the storage object at the specified byte offset from the
// specified buffer, asynchronously. When the write completes, the caller
// will be notified via the specified completion action.
//
// The buffer will be retained for the duration of the write.
//
// For simple filter schemes, the default behavior is to simply pass the
// write through to the provider media. More complex filter schemes such
// as RAID will need to do extra processing here.
//
getProvider( )->write( this, byteStart, buffer, attributes, completion );
}
IOReturn IOFilterScheme::synchronize(IOService * client,
UInt64 byteStart,
UInt64 byteCount,
IOStorageSynchronizeOptions options)
{
//
// Flush the cached data in the storage object, if any.
//
#if TARGET_OS_OSX
if ( _respondsTo_synchronizeCache )
{
if ( options == _kIOStorageSynchronizeOption_super__synchronizeCache )
{
options = 0;
}
else
{
return IOStorage::synchronize( client, byteStart, byteCount, options );
}
}
#endif /* TARGET_OS_OSX */
return getProvider( )->synchronize( this, byteStart, byteCount, options );
}
IOReturn IOFilterScheme::unmap(IOService * client,
IOStorageExtent * extents,
UInt32 extentsCount,
IOStorageUnmapOptions options)
{
//
// Delete unused data from the storage object at the specified byte offsets.
//
return getProvider( )->unmap( this, extents, extentsCount, options );
}
IOReturn
IOFilterScheme::getProvisionStatus(IOService * client,
UInt64 byteStart,
UInt64 byteCount,
UInt32 * extentsCount,
IOStorageProvisionExtent * extents,
IOStorageGetProvisionStatusOptions options)
{
return getProvider( )->getProvisionStatus( this, byteStart, byteCount, extentsCount, extents, options );
}
bool IOFilterScheme::lockPhysicalExtents(IOService * client)
{
//
// Lock the contents of the storage object against relocation temporarily,
// for the purpose of getting physical extents.
//
return getProvider( )->lockPhysicalExtents( this );
}
IOStorage * IOFilterScheme::copyPhysicalExtent(IOService * client,
UInt64 * byteStart,
UInt64 * byteCount)
{
//
// Convert the specified byte offset into a physical byte offset, relative
// to a physical storage object. This call should only be made within the
// context of lockPhysicalExtents().
//
return getProvider( )->copyPhysicalExtent( this, byteStart, byteCount );
}
void IOFilterScheme::unlockPhysicalExtents(IOService * client)
{
//
// Unlock the contents of the storage object for relocation again. This
// call must balance a successful call to lockPhysicalExtents().
//
getProvider( )->unlockPhysicalExtents( this );
}
IOReturn IOFilterScheme::setPriority(IOService * client,
IOStorageExtent * extents,
UInt32 extentsCount,
IOStoragePriority priority)
{
//
// Reprioritize read or write requests at the specified byte offsets.
//
return getProvider( )->setPriority( this, extents, extentsCount, priority );
}
OSMetaClassDefineReservedUnused(IOFilterScheme, 0);
OSMetaClassDefineReservedUnused(IOFilterScheme, 1);
OSMetaClassDefineReservedUnused(IOFilterScheme, 2);
OSMetaClassDefineReservedUnused(IOFilterScheme, 3);
OSMetaClassDefineReservedUnused(IOFilterScheme, 4);
OSMetaClassDefineReservedUnused(IOFilterScheme, 5);
OSMetaClassDefineReservedUnused(IOFilterScheme, 6);
OSMetaClassDefineReservedUnused(IOFilterScheme, 7);
OSMetaClassDefineReservedUnused(IOFilterScheme, 8);
OSMetaClassDefineReservedUnused(IOFilterScheme, 9);
OSMetaClassDefineReservedUnused(IOFilterScheme, 10);
OSMetaClassDefineReservedUnused(IOFilterScheme, 11);
OSMetaClassDefineReservedUnused(IOFilterScheme, 12);
OSMetaClassDefineReservedUnused(IOFilterScheme, 13);
OSMetaClassDefineReservedUnused(IOFilterScheme, 14);
OSMetaClassDefineReservedUnused(IOFilterScheme, 15);
OSMetaClassDefineReservedUnused(IOFilterScheme, 16);
OSMetaClassDefineReservedUnused(IOFilterScheme, 17);
OSMetaClassDefineReservedUnused(IOFilterScheme, 18);
OSMetaClassDefineReservedUnused(IOFilterScheme, 19);
OSMetaClassDefineReservedUnused(IOFilterScheme, 20);
OSMetaClassDefineReservedUnused(IOFilterScheme, 21);
OSMetaClassDefineReservedUnused(IOFilterScheme, 22);
OSMetaClassDefineReservedUnused(IOFilterScheme, 23);
OSMetaClassDefineReservedUnused(IOFilterScheme, 24);
OSMetaClassDefineReservedUnused(IOFilterScheme, 25);
OSMetaClassDefineReservedUnused(IOFilterScheme, 26);
OSMetaClassDefineReservedUnused(IOFilterScheme, 27);
OSMetaClassDefineReservedUnused(IOFilterScheme, 28);
OSMetaClassDefineReservedUnused(IOFilterScheme, 29);
OSMetaClassDefineReservedUnused(IOFilterScheme, 30);
OSMetaClassDefineReservedUnused(IOFilterScheme, 31);
#if TARGET_OS_OSX
extern "C" void _ZN14IOFilterScheme16synchronizeCacheEP9IOService( IOFilterScheme * scheme, IOService * client )
{
scheme->synchronize( client, 0, 0 );
}
#endif /* TARGET_OS_OSX */