Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/include/IOKit/storage/IOStorage.h

1/*
2 * Copyright (c) 1998-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*!
25 * @header IOStorage
26 * @abstract
27 * This header contains the IOStorage class definition.
28 */
29
30#ifndef _IOSTORAGE_H
31#define _IOSTORAGE_H
32
33#include <IOKit/IOTypes.h>
34
35/*!
36 * @defined kIOStorageClass
37 * @abstract
38 * The name of the IOStorage class.
39 */
40
41#define kIOStorageClass "IOStorage"
42
43/*!
44 * @defined kIOStorageCategory
45 * @abstract
46 * kIOStorageCategory is a value for IOService's kIOMatchCategoryKey property.
47 * @discussion
48 * The kIOStorageCategory value is the standard value for the IOService property
49 * kIOMatchCategoryKey ("IOMatchCategory") for all storage drivers. All storage
50 * objects that expect to drive new content (that is, produce new media objects)
51 * are expected to compete within the kIOStorageCategory namespace.
52 *
53 * See the IOService documentation for more information on match categories.
54 */
55
56#define kIOStorageCategory "IOStorage" /* (as IOMatchCategory) */
57
58/*!
59 * @defined kIOStorageFeaturesKey
60 * @abstract
61 * A property of any object in the storage stack.
62 * @discussion
63 * kIOStorageFeaturesKey is a property of any object in the storage stack that
64 * wishes to express support of additional features, such as Force Unit Access.
65 * It is typically defined in the device object below the block storage driver
66 * object. It has an OSDictionary value, where each entry describes one given
67 * feature.
68 */
69
70#define kIOStorageFeaturesKey "IOStorageFeatures"
71
72/*!
73 * @defined kIOStorageFeatureDiscard
74 * @abstract
75 * Describes the presence of the Discard feature.
76 * @discussion
77 * This property describes the ability of the storage stack to delete unused
78 * data from the media. It is one of the feature entries listed under the top-
79 * level kIOStorageFeaturesKey property table. It has an OSBoolean value.
80 */
81
82#define kIOStorageFeatureDiscard "Discard"
83
84/*!
85 * @defined kIOStorageFeatureForceUnitAccess
86 * @abstract
87 * Describes the presence of the Force Unit Access feature.
88 * @discussion
89 * This property describes the ability of the storage stack to force a request
90 * to access the media. It is one of the feature entries listed under the top-
91 * level kIOStorageFeaturesKey property table. It has an OSBoolean value.
92 */
93
94#define kIOStorageFeatureForceUnitAccess "Force Unit Access"
95
96#ifdef KERNEL
97#ifdef __cplusplus
98
99/*
100 * Kernel
101 */
102
103#include <IOKit/assert.h>
104#include <IOKit/IOMemoryDescriptor.h>
105#include <IOKit/IOService.h>
106
107/*!
108 * @enum IOStorageAccess
109 * @discussion
110 * The IOStorageAccess enumeration describes the possible access levels for open
111 * requests.
112 * @constant kIOStorageAccessNone
113 * No access is requested; should not be passed to open().
114 * @constant kIOStorageAccessReader
115 * Read-only access is requested.
116 * @constant kIOStorageAccessReaderWriter
117 * Read and write access is requested.
118 * @constant kIOStorageAccessSharedLock
119 * Shared access is requested.
120 * @constant kIOStorageAccessExclusiveLock
121 * Exclusive access is requested.
122 */
123
124enum
125{
126 kIOStorageAccessNone = 0x00,
127 kIOStorageAccessReader = 0x01,
128 kIOStorageAccessReaderWriter = 0x03,
129 kIOStorageAccessSharedLock = 0x04,
130 kIOStorageAccessExclusiveLock = 0x08
131};
132
133typedef UInt32 IOStorageAccess;
134
135/*!
136 * @enum IOStorageOptions
137 * @discussion
138 * Options for read and write storage requests.
139 * @constant kIOStorageOptionForceUnitAccess
140 * Force the request to access the media.
141 */
142
143enum
144{
145 kIOStorageOptionNone = 0x00000000,
146 kIOStorageOptionForceUnitAccess = 0x00000001,
147 kIOStorageOptionReserved = 0xFFFFFFFE
148};
149
150typedef UInt32 IOStorageOptions;
151
152/*!
153 * @struct IOStorageAttributes
154 * @discussion
155 * Attributes of read and write storage requests.
156 * @field options
157 * Options for the request. See IOStorageOptions.
158 * @field reserved
159 * Reserved for future use. Set to zero.
160 */
161
162struct IOStorageAttributes
163{
164 IOStorageOptions options;
165 UInt32 reserved0032;
166 UInt64 reserved0064;
167#ifdef __LP64__
168 UInt64 reserved0128;
169 UInt64 reserved0192;
170#endif /* __LP64__ */
171};
172
173/*!
174 * @typedef IOStorageCompletionAction
175 * @discussion
176 * The IOStorageCompletionAction declaration describes the C (or C++) completion
177 * routine that is called once an asynchronous storage operation completes.
178 * @param target
179 * Opaque client-supplied pointer (or an instance pointer for a C++ callback).
180 * @param parameter
181 * Opaque client-supplied pointer.
182 * @param status
183 * Status of the data transfer.
184 * @param actualByteCount
185 * Actual number of bytes transferred in the data transfer.
186 */
187
188typedef void (*IOStorageCompletionAction)(void * target,
189 void * parameter,
190 IOReturn status,
191 UInt64 actualByteCount);
192
193/*!
194 * @struct IOStorageCompletion
195 * @discussion
196 * The IOStorageCompletion structure describes the C (or C++) completion routine
197 * that is called once an asynchronous storage operation completes. The values
198 * passed for the target and parameter fields will be passed to the routine when
199 * it is called.
200 * @field target
201 * Opaque client-supplied pointer (or an instance pointer for a C++ callback).
202 * @field action
203 * Completion routine to call on completion of the data transfer.
204 * @field parameter
205 * Opaque client-supplied pointer.
206 */
207
208struct IOStorageCompletion
209{
210 void * target;
211 IOStorageCompletionAction action;
212 void * parameter;
213};
214
215/*!
216 * @class IOStorage
217 * @abstract
218 * The common base class for mass storage objects.
219 * @discussion
220 * The IOStorage class is the common base class for mass storage objects. It is
221 * an abstract class that defines the open/close/read/write APIs that need to be
222 * implemented in a given subclass. Synchronous versions of the read/write APIs
223 * are provided here -- they are coded in such a way as to wrap the asynchronous
224 * versions implemented in the subclass.
225 */
226
227class IOStorage : public IOService
228{
229 OSDeclareAbstractStructors(IOStorage);
230
231protected:
232
233 struct ExpansionData { /* */ };
234 ExpansionData * _expansionData;
235
236 /*!
237 * @function handleOpen
238 * @discussion
239 * The handleOpen method grants or denies permission to access this object
240 * to an interested client. The argument is an IOStorageAccess value that
241 * specifies the level of access desired -- reader or reader-writer.
242 *
243 * This method can be invoked to upgrade or downgrade the access level for
244 * an existing client as well. The previous access level will prevail for
245 * upgrades that fail, of course. A downgrade should never fail. If the
246 * new access level should be the same as the old for a given client, this
247 * method will do nothing and return success. In all cases, one, singular
248 * close-per-client is expected for all opens-per-client received.
249 * @param client
250 * Client requesting the open.
251 * @param options
252 * Options for the open. Set to zero.
253 * @param access
254 * Access level for the open. Set to kIOStorageAccessReader or
255 * kIOStorageAccessReaderWriter.
256 * @result
257 * Returns true if the open was successful, false otherwise.
258 */
259
260 virtual bool handleOpen(IOService * client,
261 IOOptionBits options,
262 void * access) = 0;
263
264 /*!
265 * @function handleIsOpen
266 * @discussion
267 * The handleIsOpen method determines whether the specified client, or any
268 * client if none is specified, presently has an open on this object.
269 * @param client
270 * Client to check the open state of. Set to zero to check the open state
271 * of all clients.
272 * @result
273 * Returns true if the client was (or clients were) open, false otherwise.
274 */
275
276 virtual bool handleIsOpen(const IOService * client) const = 0;
277
278 /*!
279 * @function handleClose
280 * @discussion
281 * The handleClose method closes the client's access to this object.
282 * @param client
283 * Client requesting the close.
284 * @param options
285 * Options for the close. Set to zero.
286 */
287
288 virtual void handleClose(IOService * client, IOOptionBits options) = 0;
289
290public:
291
292#ifndef __LP64__
293 /*
294 * Initialize this object's minimal state.
295 */
296
297 virtual bool init(OSDictionary * properties = 0);
298#endif /* !__LP64__ */
299
300 /*!
301 * @function complete
302 * @discussion
303 * Invokes the specified completion action of the read/write request. If
304 * the completion action is unspecified, no action is taken. This method
305 * serves simply as a convenience to storage subclass developers.
306 * @param completion
307 * Completion information for the data transfer.
308 * @param status
309 * Status of the data transfer.
310 * @param actualByteCount
311 * Actual number of bytes transferred in the data transfer.
312 */
313
314 static void complete(IOStorageCompletion * completion,
315 IOReturn status,
316 UInt64 actualByteCount = 0);
317
318#ifndef __LP64__
319 static void complete(IOStorageCompletion completion,
320 IOReturn status,
321 UInt64 actualByteCount = 0); /* DEPRECATED */
322#endif /* !__LP64__ */
323
324 /*!
325 * @function open
326 * @discussion
327 * Ask the storage object for permission to access its contents; the method
328 * is equivalent to IOService::open(), but with the correct parameter types.
329 *
330 * This method may also be invoked to upgrade or downgrade the access of an
331 * existing open (if it fails, the existing open prevails).
332 * @param client
333 * Client requesting the open.
334 * @param options
335 * Options for the open. Set to zero.
336 * @param access
337 * Access level for the open. Set to kIOStorageAccessReader or
338 * kIOStorageAccessReaderWriter.
339 * @result
340 * Returns true if the open was successful, false otherwise.
341 */
342
343 virtual bool open(IOService * client,
344 IOOptionBits options,
345 IOStorageAccess access);
346
347#ifndef __LP64__
348 virtual void read(IOService * client,
349 UInt64 byteStart,
350 IOMemoryDescriptor * buffer,
351 IOStorageCompletion completion) __attribute__ ((deprecated));
352
353 virtual void write(IOService * client,
354 UInt64 byteStart,
355 IOMemoryDescriptor * buffer,
356 IOStorageCompletion completion) __attribute__ ((deprecated));
357#endif /* !__LP64__ */
358
359 /*!
360 * @function read
361 * @discussion
362 * Read data from the storage object at the specified byte offset into the
363 * specified buffer, synchronously. When the read completes, this method
364 * will return to the caller. The actual byte count field is optional.
365 * @param client
366 * Client requesting the read.
367 * @param byteStart
368 * Starting byte offset for the data transfer.
369 * @param buffer
370 * Buffer for the data transfer. The size of the buffer implies the size of
371 * the data transfer.
372 * @param attributes
373 * Attributes of the data transfer. See IOStorageAttributes.
374 * @param actualByteCount
375 * Returns the actual number of bytes transferred in the data transfer.
376 * @result
377 * Returns the status of the data transfer.
378 */
379
380#ifdef __LP64__
381 virtual IOReturn read(IOService * client,
382 UInt64 byteStart,
383 IOMemoryDescriptor * buffer,
384 IOStorageAttributes * attributes = 0,
385 UInt64 * actualByteCount = 0);
386#else /* !__LP64__ */
387 virtual IOReturn read(IOService * client,
388 UInt64 byteStart,
389 IOMemoryDescriptor * buffer,
390 UInt64 * actualByteCount = 0);
391#endif /* !__LP64__ */
392
393 /*!
394 * @function write
395 * @discussion
396 * Write data into the storage object at the specified byte offset from the
397 * specified buffer, synchronously. When the write completes, this method
398 * will return to the caller. The actual byte count field is optional.
399 * @param client
400 * Client requesting the write.
401 * @param byteStart
402 * Starting byte offset for the data transfer.
403 * @param buffer
404 * Buffer for the data transfer. The size of the buffer implies the size of
405 * the data transfer.
406 * @param attributes
407 * Attributes of the data transfer. See IOStorageAttributes.
408 * @param actualByteCount
409 * Returns the actual number of bytes transferred in the data transfer.
410 * @result
411 * Returns the status of the data transfer.
412 */
413
414#ifdef __LP64__
415 virtual IOReturn write(IOService * client,
416 UInt64 byteStart,
417 IOMemoryDescriptor * buffer,
418 IOStorageAttributes * attributes = 0,
419 UInt64 * actualByteCount = 0);
420#else /* !__LP64__ */
421 virtual IOReturn write(IOService * client,
422 UInt64 byteStart,
423 IOMemoryDescriptor * buffer,
424 UInt64 * actualByteCount = 0);
425#endif /* !__LP64__ */
426
427 /*!
428 * @function synchronizeCache
429 * @discussion
430 * Flush the cached data in the storage object, if any, synchronously.
431 * @param client
432 * Client requesting the cache synchronization.
433 * @result
434 * Returns the status of the cache synchronization.
435 */
436
437 virtual IOReturn synchronizeCache(IOService * client) = 0;
438
439 /*!
440 * @function read
441 * @discussion
442 * Read data from the storage object at the specified byte offset into the
443 * specified buffer, asynchronously. When the read completes, the caller
444 * will be notified via the specified completion action.
445 *
446 * The buffer will be retained for the duration of the read.
447 * @param client
448 * Client requesting the read.
449 * @param byteStart
450 * Starting byte offset for the data transfer.
451 * @param buffer
452 * Buffer for the data transfer. The size of the buffer implies the size of
453 * the data transfer.
454 * @param attributes
455 * Attributes of the data transfer. See IOStorageAttributes. It is the
456 * responsibility of the callee to maintain the information for the duration
457 * of the data transfer, as necessary.
458 * @param completion
459 * Completion routine to call once the data transfer is complete. It is the
460 * responsibility of the callee to maintain the information for the duration
461 * of the data transfer, as necessary.
462 */
463
464#ifdef __LP64__
465 virtual void read(IOService * client,
466 UInt64 byteStart,
467 IOMemoryDescriptor * buffer,
468 IOStorageAttributes * attributes,
469 IOStorageCompletion * completion) = 0;
470#else /* !__LP64__ */
471 virtual void read(IOService * client,
472 UInt64 byteStart,
473 IOMemoryDescriptor * buffer,
474 IOStorageAttributes * attributes,
475 IOStorageCompletion * completion); /* 10.5.0 */
476#endif /* !__LP64__ */
477
478 /*!
479 * @function write
480 * @discussion
481 * Write data into the storage object at the specified byte offset from the
482 * specified buffer, asynchronously. When the write completes, the caller
483 * will be notified via the specified completion action.
484 *
485 * The buffer will be retained for the duration of the write.
486 * @param client
487 * Client requesting the write.
488 * @param byteStart
489 * Starting byte offset for the data transfer.
490 * @param buffer
491 * Buffer for the data transfer. The size of the buffer implies the size of
492 * the data transfer.
493 * @param attributes
494 * Attributes of the data transfer. See IOStorageAttributes. It is the
495 * responsibility of the callee to maintain the information for the duration
496 * of the data transfer, as necessary.
497 * @param completion
498 * Completion routine to call once the data transfer is complete. It is the
499 * responsibility of the callee to maintain the information for the duration
500 * of the data transfer, as necessary.
501 */
502
503#ifdef __LP64__
504 virtual void write(IOService * client,
505 UInt64 byteStart,
506 IOMemoryDescriptor * buffer,
507 IOStorageAttributes * attributes,
508 IOStorageCompletion * completion) = 0;
509#else /* !__LP64__ */
510 virtual void write(IOService * client,
511 UInt64 byteStart,
512 IOMemoryDescriptor * buffer,
513 IOStorageAttributes * attributes,
514 IOStorageCompletion * completion); /* 10.5.0 */
515#endif /* !__LP64__ */
516
517 /*!
518 * @function discard
519 * @discussion
520 * Delete unused data from the storage object at the specified byte offset,
521 * synchronously.
522 * @param client
523 * Client requesting the operation.
524 * @param byteStart
525 * Starting byte offset for the operation.
526 * @param byteCount
527 * Size of the operation.
528 * @result
529 * Returns the status of the operation.
530 */
531
532 virtual IOReturn discard(IOService * client,
533 UInt64 byteStart,
534 UInt64 byteCount); /* 10.6.0 */
535
536#ifdef __LP64__
537 OSMetaClassDeclareReservedUnused(IOStorage, 0);
538 OSMetaClassDeclareReservedUnused(IOStorage, 1);
539 OSMetaClassDeclareReservedUnused(IOStorage, 2);
540#else /* !__LP64__ */
541 OSMetaClassDeclareReservedUsed(IOStorage, 0);
542 OSMetaClassDeclareReservedUsed(IOStorage, 1);
543 OSMetaClassDeclareReservedUsed(IOStorage, 2);
544#endif /* !__LP64__ */
545 OSMetaClassDeclareReservedUnused(IOStorage, 3);
546 OSMetaClassDeclareReservedUnused(IOStorage, 4);
547 OSMetaClassDeclareReservedUnused(IOStorage, 5);
548 OSMetaClassDeclareReservedUnused(IOStorage, 6);
549 OSMetaClassDeclareReservedUnused(IOStorage, 7);
550 OSMetaClassDeclareReservedUnused(IOStorage, 8);
551 OSMetaClassDeclareReservedUnused(IOStorage, 9);
552 OSMetaClassDeclareReservedUnused(IOStorage, 10);
553 OSMetaClassDeclareReservedUnused(IOStorage, 11);
554 OSMetaClassDeclareReservedUnused(IOStorage, 12);
555 OSMetaClassDeclareReservedUnused(IOStorage, 13);
556 OSMetaClassDeclareReservedUnused(IOStorage, 14);
557 OSMetaClassDeclareReservedUnused(IOStorage, 15);
558};
559
560#endif /* __cplusplus */
561#endif /* KERNEL */
562#endif /* !_IOSTORAGE_H */
563

Archive Download this file

Revision: 881