2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * This header contains the IOMedia class definition.
33 * @defined kIOMediaClass
35 * kIOMediaClass is the name of the IOMedia class.
37 * kIOMediaClass is the name of the IOMedia class.
40 #define kIOMediaClass "IOMedia"
43 * @defined kIOMediaContentKey
45 * kIOMediaContentKey is a property of IOMedia objects. It has an OSString
48 * The kIOMediaContentKey property contains a description of the media's
49 * contents. The description is the same as the hint at the time of the object's
50 * creation, but it is possible that the description be overrided by a client
51 * (which has probed the media and identified the content correctly) of the media
52 * object. It is more accurate than the hint for this reason. The string is
53 * formed in the likeness of Apple's "Apple_HFS" strings.
56 #define kIOMediaContentKey "Content"
57 #define kIOMediaContent "Content" ///d:deprecated
60 * @defined kIOMediaContentHintKey
62 * kIOMediaContentHintKey is a property of IOMedia objects. It has an OSString
65 * The kIOMediaContentHintKey property contains a hint of the media's contents.
66 * The hint is set at the time of the object's creation, should the creator have
67 * a clue as to what it may contain. The hint string does not change for the
68 * lifetime of the object and is formed in the likeness of Apple's "Apple_HFS"
72 #define kIOMediaContentHintKey "Content Hint"
75 * @defined kIOMediaEjectableKey
77 * kIOMediaEjectableKey is a property of IOMedia objects. It has an OSBoolean
80 * The kIOMediaEjectableKey property describes whether the media is ejectable.
83 #define kIOMediaEjectableKey "Ejectable"
84 #define kIOMediaEjectable "Ejectable" ///d:deprecated
87 * @defined kIOMediaLeafKey
89 * kIOMediaLeafKey is a property of IOMedia objects. It has an OSBoolean value.
91 * The kIOMediaLeafKey property describes whether the media is a leaf, that is,
92 * it is the deepest media object in this branch of the I/O Kit registry.
95 #define kIOMediaLeafKey "Leaf"
96 #define kIOMediaLeaf "Leaf" ///d:deprecated
99 * @defined kIOMediaPreferredBlockSizeKey
101 * kIOMediaPreferredBlockSizeKey is a property of IOMedia objects. It has an
104 * The kIOMediaPreferredBlockSizeKey property describes the media's natural block
105 * size in bytes. This information is useful to clients that want to optimize
106 * access to the media.
109 #define kIOMediaPreferredBlockSizeKey "Preferred Block Size"
112 * @defined kIOMediaSizeKey
114 * kIOMediaSizeKey is a property of IOMedia objects. It has an OSNumber value.
116 * The kIOMediaSizeKey property describes the total length of the media in bytes.
119 #define kIOMediaSizeKey "Size"
120 #define kIOMediaSize "Size" ///d:deprecated
123 * @defined kIOMediaWholeKey
125 * kIOMediaWholeKey is a property of IOMedia objects. It has an OSBoolean value.
127 * The kIOMediaWholeKey property describes whether the media is whole, that is,
128 * it represents the whole disk (the physical disk, or a virtual replica
132 #define kIOMediaWholeKey "Whole"
135 * @defined kIOMediaWritableKey
137 * kIOMediaWritableKey is a property of IOMedia objects. It has an OSBoolean
140 * The kIOMediaWritableKey property describes whether the media is writable.
143 #define kIOMediaWritableKey "Writable"
144 #define kIOMediaWritable "Writable" ///d:deprecated
147 * @defined kIOMediaContentMaskKey
149 * kIOMediaContentMaskKey is a property of IOMedia clients. It has an OSString
152 * The kIOMediaContentMaskKey property must exist in all IOMedia clients that
153 * drive new content (that is, produce new media objects). When the client
154 * matches against the provider media, the value of the client's
155 * kIOMediaContentMaskKey property is used to replace the provider's
156 * kIOMediaContentKey property.
159 #define kIOMediaContentMaskKey "Content Mask"
165 #if defined(KERNEL) && defined(__cplusplus)
167 #include <IOKit/storage/IOStorage.h>
172 * The IOMedia class is a random-access disk device abstraction.
174 * The IOMedia class is a random-access disk device abstraction. It provides a
175 * consistent interface for both real and virtual disk devices, for subdivisions
176 * of disks such as partitions, for supersets of disks such as RAID volumes, and
177 * so on. It extends the IOStorage class by implementing the appropriate open,
178 * close, read, write, and matching semantics for media objects. The properties
179 * it has reflect the properties of real disk devices, such as ejectability and
182 * The read and write interfaces support byte-level access to the storage space,
183 * with the appropriate deblocking handled by the block storage driver, however,
184 * a typical client will want to get the natural block size in order to optimize
185 * access to the real disk device. A read or write is accepted so long as the
186 * client's access is valid, the media is formatted and the transfer is within
187 * the bounds of the media. An optional non-zero base (offset) is then applied
188 * before the read or write is passed to provider object.
190 * An open is accepted so long as no more than one writer is active at any time.
193 class IOMedia
: public IOStorage
195 OSDeclareDefaultStructors(IOMedia
)
199 struct ExpansionData
{ /* */ };
200 ExpansionData
* _expansionData
;
206 UInt64 _mediaBase
; /* (relative to the storage object below us) */
209 IOStorageAccess _openLevel
;
210 OSSet
* _openReaders
;
211 IOService
* _openReaderWriter
;
213 UInt64 _preferredBlockSize
;
216 * Free all of this object's outstanding resources.
222 * @function handleOpen
224 * The handleOpen method grants or denies permission to access this object
225 * to an interested client. The argument is an IOStorageAccess value that
226 * specifies the level of access desired -- reader or reader-writer.
228 * This method can be invoked to upgrade or downgrade the access level for
229 * an existing client as well. The previous access level will prevail for
230 * upgrades that fail, of course. A downgrade should never fail. If the
231 * new access level should be the same as the old for a given client, this
232 * method will do nothing and return success. In all cases, one, singular
233 * close-per-client is expected for all opens-per-client received.
235 * This implementation replaces the IOService definition of handleOpen().
237 * Client requesting the open.
239 * Options for the open. Set to zero.
241 * Access level for the open. Set to kIOStorageAccessReader or
242 * kIOStorageAccessReaderWriter.
244 * Returns true if the open was successful, false otherwise.
247 virtual bool handleOpen(IOService
* client
,
248 IOOptionBits options
,
252 * @function handleIsOpen
254 * The handleIsOpen method determines whether the specified client, or any
255 * client if none is specificed, presently has an open on this object.
257 * This implementation replaces the IOService definition of handleIsOpen().
259 * Client to check the open state of. Set to zero to check the open state
262 * Returns true if the client was (or clients were) open, false otherwise.
265 virtual bool handleIsOpen(const IOService
* client
) const;
268 * @function handleClose
270 * The handleClose method closes the client's access to this object.
272 * This implementation replaces the IOService definition of handleClose().
274 * Client requesting the close.
276 * Options for the close. Set to zero.
279 virtual void handleClose(IOService
* client
, IOOptionBits options
);
283 ///m:2333367:workaround:commented:start
286 ///m:2333367:workaround:commented:stop
291 * Initialize this object's minimal state.
293 * Media offset, in bytes.
295 * Media size, in bytes.
296 * @param preferredBlockSize
297 * Natural block size, in bytes.
299 * Indicates whether the media is ejectable.
301 * Indicated whether the media represents the whole disk.
303 * Indicates whether the media is writable.
305 * Hint of media's contents (optional). See getContentHint().
307 * Substitute property table for this object (optional).
309 * Returns true on success, false otherwise.
312 virtual bool init(UInt64 base
,
314 UInt64 preferredBlockSize
,
318 const char * contentHint
= 0,
319 OSDictionary
* properties
= 0);
322 * This method is called for each client interested in the services we
323 * provide. The superclass links us as a parent to this client in the
324 * I/O Kit registry on success.
327 virtual bool attachToChild(IORegistryEntry
* client
,
328 const IORegistryPlane
* plane
);
331 * This method is called for each client that loses interest in the
332 * services we provide. The superclass unlinks us from this client
333 * in the I/O Kit registry on success.
336 virtual void detachFromChild(IORegistryEntry
* client
,
337 const IORegistryPlane
* plane
);
340 * Compare the properties in the supplied table to this object's properties.
343 virtual bool matchPropertyTable(OSDictionary
* table
, SInt32
* score
);
348 * Read data from the storage object at the specified byte offset into the
349 * specified buffer, asynchronously. When the read completes, the caller
350 * will be notified via the specified completion action.
352 * The buffer will be retained for the duration of the read.
354 * Client requesting the read.
356 * Starting byte offset for the data transfer.
358 * Buffer for the data transfer. The size of the buffer implies the size of
361 * Completion routine to call once the data transfer is complete.
364 virtual void read(IOService
* client
,
366 IOMemoryDescriptor
* buffer
,
367 IOStorageCompletion completion
);
372 * Write data into the storage object at the specified byte offset from the
373 * specified buffer, asynchronously. When the write completes, the caller
374 * will be notified via the specified completion action.
376 * The buffer will be retained for the duration of the write.
378 * Client requesting the write.
380 * Starting byte offset for the data transfer.
382 * Buffer for the data transfer. The size of the buffer implies the size of
385 * Completion routine to call once the data transfer is complete.
388 virtual void write(IOService
* client
,
390 IOMemoryDescriptor
* buffer
,
391 IOStorageCompletion completion
);
393 virtual IOReturn
synchronizeCache(IOService
* client
);
396 * @function getPreferredBlockSize
398 * Ask the media object for its natural block size. This information
399 * is useful to clients that want to optimize access to the media.
401 * Natural block size, in bytes.
404 virtual UInt64
getPreferredBlockSize() const;
409 * Ask the media object for its total length in bytes.
411 * Media size, in bytes.
414 virtual UInt64
getSize() const;
419 * Ask the media object for its byte offset relative to its provider media
420 * object below it in the storage hierarchy.
421 * Media offset, in bytes.
424 virtual UInt64
getBase() const;
427 * @function isEjectable
429 * Ask the media object whether it is ejectable.
431 * Returns true if the media is ejectable, false otherwise.
434 virtual bool isEjectable() const;
437 * @function isFormatted
439 * Ask the media object whether it is formatted.
441 * Returns true if the media is formatted, false otherwise.
444 virtual bool isFormatted() const;
449 * Ask the media object whether it represents the whole disk.
451 * Returns true if the media represents the whole disk, false otherwise.
454 virtual bool isWhole() const;
457 * @function isWritable
459 * Ask the media object whether it is writable.
461 * Returns true if the media is writable, false otherwise.
464 virtual bool isWritable() const;
467 * @function getContent
469 * Ask the media object for a description of its contents. The description
470 * is the same as the hint at the time of the object's creation, but it is
471 * possible that the description be overrided by a client (which has probed
472 * the media and identified the content correctly) of the media object. It
473 * is more accurate than the hint for this reason. The string is formed in
474 * the likeness of Apple's "Apple_HFS" strings.
476 * The content description can be overrided by any client that matches onto
477 * this media object with a match category of kIOStorageCategory. The media
478 * object checks for a kIOMediaContentMaskKey property in the client, and if
479 * it finds one, it copies it into kIOMediaContentKey property.
481 * Description of media's contents.
484 virtual const char * getContent() const;
487 * @function getContentHint
489 * Ask the media object for a hint of its contents. The hint is set at the
490 * time of the object's creation, should the creator have a clue as to what
491 * it may contain. The hint string does not change for the lifetime of the
492 * object and is also formed in the likeness of Apple's "Apple_HFS" strings.
494 * Hint of media's contents.
497 virtual const char * getContentHint() const;
500 * Obtain this object's provider. We override the superclass's method to
501 * return a more specific subclass of OSObject -- IOStorage. This method
502 * serves simply as a convenience to subclass developers.
505 virtual IOStorage
* getProvider() const;
507 OSMetaClassDeclareReservedUnused(IOMedia
, 0);
508 OSMetaClassDeclareReservedUnused(IOMedia
, 1);
509 OSMetaClassDeclareReservedUnused(IOMedia
, 2);
510 OSMetaClassDeclareReservedUnused(IOMedia
, 3);
511 OSMetaClassDeclareReservedUnused(IOMedia
, 4);
512 OSMetaClassDeclareReservedUnused(IOMedia
, 5);
513 OSMetaClassDeclareReservedUnused(IOMedia
, 6);
514 OSMetaClassDeclareReservedUnused(IOMedia
, 7);
515 OSMetaClassDeclareReservedUnused(IOMedia
, 8);
516 OSMetaClassDeclareReservedUnused(IOMedia
, 9);
517 OSMetaClassDeclareReservedUnused(IOMedia
, 10);
518 OSMetaClassDeclareReservedUnused(IOMedia
, 11);
519 OSMetaClassDeclareReservedUnused(IOMedia
, 12);
520 OSMetaClassDeclareReservedUnused(IOMedia
, 13);
521 OSMetaClassDeclareReservedUnused(IOMedia
, 14);
522 OSMetaClassDeclareReservedUnused(IOMedia
, 15);
525 #endif /* defined(KERNEL) && defined(__cplusplus) */
527 #endif /* !_IOMEDIA_H */