Mac Developer Library

Developer

IOMedia Class Reference

Options
Deployment Target:

On This Page
Language:

IOMedia

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Not Applicable

Objective-C

@import Kernel;

Availability


Available in OS X v10.6 and later.

A random-access disk device abstraction.

The IOMedia class is a random-access disk device abstraction. It provides a consistent interface for both real and virtual disk devices, for subdivisions of disks such as partitions, for supersets of disks such as RAID volumes, and so on. It extends the IOStorage class by implementing the appropriate open, close, read, write, and matching semantics for media objects. The properties it has reflect the properties of real disk devices, such as ejectability and writability.

The read and write interfaces support byte-level access to the storage space, with the appropriate deblocking handled by the block storage driver, however, a typical client will want to get the natural block size in order to optimize access to the real disk device. A read or write is accepted so long as the client's access is valid, the media is formatted and the transfer is within the bounds of the media. An optional non-zero base (offset) is then applied before the read or write is passed to provider object.

  • Declaration

    C++

    virtual IOStorage * copyPhysicalExtent( IOService *client, UInt64 *byteStart, UInt64 *byteCount);

    Parameters

    client

    Client requesting the operation.

    byteStart

    Starting byte offset for the operation. Returns a physical byte offset, relative to the physical storage object, on success.

    byteCount

    Size of the operation. Returns the actual number of bytes which can be transferred, relative to the physical storage object, on success.

    Return Value

    A reference to the physical storage object, which should be released by the caller, or a null on error.

    Discussion

    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().

  • Declaration

    C++

    virtual IOMediaAttributeMask getAttributes() const;

    Return Value

    Media attributes, such as ejectability and removability. See IOMediaAttributeMask.

    Discussion

    Ask the media object for its attributes.

  • Declaration

    C++

    virtual UInt64 getBase() const;

    Discussion

    Ask the media object for its byte offset relative to its provider media object below it in the storage hierarchy. Media offset, in bytes.

  • Declaration

    C++

    virtual const char * getContent() const;

    Return Value

    Description of media's contents.

    Discussion

    Ask the media object for a description of its contents. The description is the same as the hint at the time of the object's creation, but it is possible that the description has been overridden by a client (which has probed the media and identified the content correctly) of the media object. It is more accurate than the hint for this reason. The string is formed in the likeness of Apple's "Apple_HFS" strings or in the likeness of a UUID.

    The content description can be overridden by any client that matches onto this media object with a match category of kIOStorageCategory. The media object checks for a kIOMediaContentMaskKey property in the client, and if it finds one, it copies it into kIOMediaContentKey property.

  • Declaration

    C++

    virtual const char * getContentHint() const;

    Return Value

    Hint of media's contents.

    Discussion

    Ask the media object for a hint of its contents. The hint is set at the time of the object's creation, should the creator have a clue as to what it may contain. The hint string does not change for the lifetime of the object and is also formed in the likeness of Apple's "Apple_HFS" strings or in the likeness of a UUID.

  • Declaration

    C++

    virtual UInt64 getPreferredBlockSize() const;

    Return Value

    Natural block size, in bytes.

    Discussion

    Ask the media object for its natural block size. This information is useful to clients that want to optimize access to the media.

  • Declaration

    C++

    virtual UInt64 getSize() const;

    Return Value

    Media size, in bytes.

    Discussion

    Ask the media object for its total length in bytes.

  • Declaration

    C++

    virtual void handleClose( IOService *client, IOOptionBitsoptions);

    Parameters

    client

    Client requesting the close.

    options

    Options for the close. Set to zero.

    Discussion

    The handleClose method closes the client's access to this object.

    This implementation replaces the IOService definition of handleClose().

  • Declaration

    C++

    virtual bool handleIsOpen( const IOService *client) const;

    Parameters

    client

    Client to check the open state of. Set to zero to check the open state of all clients.

    Return Value

    Returns true if the client was (or clients were) open, false otherwise.

    Discussion

    The handleIsOpen method determines whether the specified client, or any client if none is specified, presently has an open on this object.

    This implementation replaces the IOService definition of handleIsOpen().

  • Declaration

    C++

    virtual bool handleOpen( IOService *client, IOOptionBitsoptions, void *access);

    Parameters

    client

    Client requesting the open.

    options

    Options for the open. Set to zero.

    access

    Access level for the open. Set to kIOStorageAccessReader or kIOStorageAccessReaderWriter.

    Return Value

    Returns true if the open was successful, false otherwise.

    Discussion

    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().

  • Declaration

    C++

    virtual bool init( UInt64 base, UInt64 size, UInt64 preferredBlockSize, IOMediaAttributeMask attributes, bool isWhole, bool isWritable, const char *contentHint = 0, OSDictionary *properties = 0);

    Parameters

    base

    Media offset, in bytes.

    size

    Media size, in bytes.

    preferredBlockSize

    Natural block size, in bytes.

    attributes

    Media attributes, such as ejectability and removability. See IOMediaAttributeMask.

    isWhole

    Indicates whether the media represents the whole disk.

    isWritable

    Indicates whether the media is writable.

    contentHint

    Hint of media's contents (optional). See getContentHint().

    properties

    Substitute property table for this object (optional).

    Return Value

    Returns true on success, false otherwise.

    Discussion

    Initialize this object's minimal state.

  • Declaration

    C++

    virtual bool isEjectable() const;

    Return Value

    Returns true if the media is ejectable, false otherwise.

    Discussion

    Ask the media object whether it is ejectable.

  • Declaration

    C++

    virtual bool isFormatted() const;

    Return Value

    Returns true if the media is formatted, false otherwise.

    Discussion

    Ask the media object whether it is formatted.

  • Declaration

    C++

    virtual bool isWhole() const;

    Return Value

    Returns true if the media represents the whole disk, false otherwise.

    Discussion

    Ask the media object whether it represents the whole disk.

  • Declaration

    C++

    virtual bool isWritable() const;

    Return Value

    Returns true if the media is writable, false otherwise.

    Discussion

    Ask the media object whether it is writable.

  • Declaration

    C++

    virtual bool lockPhysicalExtents( IOService *client);

    Parameters

    client

    Client requesting the operation.

    Return Value

    Returns true if the lock was successful, false otherwise.

    Discussion

    Lock the contents of the storage object against relocation temporarily, for the purpose of getting physical extents.

  • Declaration

    C++

    virtual void read( IOService *client, UInt64byteStart, IOMemoryDescriptor *buffer, IOStorageAttributes *attributes, IOStorageCompletion *completion);

    Parameters

    client

    Client requesting the read.

    byteStart

    Starting byte offset for the data transfer.

    buffer

    Buffer for the data transfer. The size of the buffer implies the size of the data transfer.

    attributes

    Attributes of the data transfer. See IOStorageAttributes. It is the responsibility of the callee to maintain the information for the duration of the data transfer, as necessary.

    completion

    Completion routine to call once the data transfer is complete. It is the responsibility of the callee to maintain the information for the duration of the data transfer, as necessary.

    Discussion

    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.

  • Declaration

    C++

    virtual IOReturn synchronizeCache( IOService *client);

    Parameters

    client

    Client requesting the cache synchronization.

    Return Value

    Returns the status of the cache synchronization.

    Discussion

    Flush the cached data in the storage object, if any, synchronously.

  • Declaration

    C++

    virtual void unlockPhysicalExtents( IOService *client);

    Parameters

    client

    Client requesting the operation.

    Discussion

    Unlock the contents of the storage object for relocation again. This call must balance a successful call to lockPhysicalExtents().

  • Declaration

    C++

    virtual IOReturn unmap( IOService *client, IOStorageExtent *extents, UInt32extentsCount, UInt32 options = 0);

    Parameters

    client

    Client requesting the operation.

    extents

    List of extents. See IOStorageExtent. It is legal for the callee to overwrite the contents of this buffer in order to satisfy the request.

    extentsCount

    Number of extents.

    Return Value

    Returns the status of the operation.

    Discussion

    Delete unused data from the storage object at the specified byte offsets, synchronously.

  • Declaration

    C++

    virtual void write( IOService *client, UInt64byteStart, IOMemoryDescriptor *buffer, IOStorageAttributes *attributes, IOStorageCompletion *completion);

    Parameters

    client

    Client requesting the write.

    byteStart

    Starting byte offset for the data transfer.

    buffer

    Buffer for the data transfer. The size of the buffer implies the size of the data transfer.

    attributes

    Attributes of the data transfer. See IOStorageAttributes. It is the responsibility of the callee to maintain the information for the duration of the data transfer, as necessary.

    completion

    Completion routine to call once the data transfer is complete. It is the responsibility of the callee to maintain the information for the duration of the data transfer, as necessary.

    Discussion

    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.