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@
23 #include <IOKit/IOSyncer.h>
24 #include <IOKit/storage/IOCDBlockStorageDriver.h>
25 #include <IOKit/storage/IOCDMedia.h>
28 OSDefineMetaClassAndStructors(IOCDMedia
, IOMedia
)
30 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 static void readCDCompletion(void * target
,
36 UInt64 actualByteCount
)
39 // Internal completion routine for synchronous version of readCD.
42 if (parameter
) *((UInt64
*)parameter
) = actualByteCount
;
43 ((IOSyncer
*)target
)->signal(status
);
46 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 IOCDBlockStorageDriver
* IOCDMedia::getProvider() const
51 // Obtain this object's provider. We override the superclass's method to
52 // return a more specific subclass of IOService -- IOCDBlockStorageDriver.
53 // This method serves simply as a convenience to subclass developers.
56 return (IOCDBlockStorageDriver
*) IOService::getProvider();
59 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61 void IOCDMedia::read(IOService
* /* client */,
63 IOMemoryDescriptor
* buffer
,
64 IOStorageCompletion completion
)
67 // Read data from the storage object at the specified byte offset into the
68 // specified buffer, asynchronously. When the read completes, the caller
69 // will be notified via the specified completion action.
71 // The buffer will be retained for the duration of the read.
73 // This method will work even when the media is in the terminated state.
78 complete(completion
, kIOReturnNoMedia
);
82 if (_openLevel
== kIOStorageAccessNone
) // (instantaneous value, no lock)
84 complete(completion
, kIOReturnNotOpen
);
88 if (_mediaSize
== 0 || _preferredBlockSize
== 0)
90 complete(completion
, kIOReturnUnformattedMedia
);
94 if (_mediaSize
< byteStart
+ buffer
->getLength())
96 complete(completion
, kIOReturnBadArgument
);
100 byteStart
+= _mediaBase
;
101 getProvider()->readCD( /* client */ this,
102 /* byteStart */ byteStart
,
104 /* sectorArea */ (CDSectorArea
) 0xF8, // (2352 bytes)
105 /* sectorType */ (CDSectorType
) 0x00, // ( all types)
106 /* completion */ completion
);
109 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111 IOReturn
IOCDMedia::readCD(IOService
* client
,
113 IOMemoryDescriptor
* buffer
,
114 CDSectorArea sectorArea
,
115 CDSectorType sectorType
,
116 UInt64
* actualByteCount
= 0)
119 // Read data from the CD media object at the specified byte offset into the
120 // specified buffer, synchronously. Special areas of the CD sector can be
121 // read via this method, such as the header and subchannel data. When the
122 // read completes, this method will return to the caller. The actual byte
123 // count field is optional.
125 // This method will work even when the media is in the terminated state.
128 IOStorageCompletion completion
;
129 IOSyncer
* completionSyncer
;
131 // Initialize the lock we will synchronize against.
133 completionSyncer
= IOSyncer::create();
135 // Fill in the completion information for this request.
137 completion
.target
= completionSyncer
;
138 completion
.action
= readCDCompletion
;
139 completion
.parameter
= actualByteCount
;
141 // Issue the asynchronous read.
143 readCD(client
, byteStart
, buffer
, sectorArea
, sectorType
, completion
);
145 // Wait for the read to complete.
147 return completionSyncer
->wait();
150 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152 void IOCDMedia::readCD(IOService
* client
,
154 IOMemoryDescriptor
* buffer
,
155 CDSectorArea sectorArea
,
156 CDSectorType sectorType
,
157 IOStorageCompletion completion
)
160 // Read data from the CD media object at the specified byte offset into the
161 // specified buffer, asynchronously. Special areas of the CD sector can be
162 // read via this method, such as the header and subchannel data. When the
163 // read completes, the caller will be notified via the specified completion
166 // The buffer will be retained for the duration of the read.
168 // This method will work even when the media is in the terminated state.
173 complete(completion
, kIOReturnNoMedia
);
177 if (_openLevel
== kIOStorageAccessNone
) // (instantaneous value, no lock)
179 complete(completion
, kIOReturnNotOpen
);
183 if (_mediaSize
== 0 || _preferredBlockSize
== 0)
185 complete(completion
, kIOReturnUnformattedMedia
);
189 if (_mediaSize
< byteStart
+ buffer
->getLength())
191 complete(completion
, kIOReturnBadArgument
);
195 byteStart
+= _mediaBase
;
196 getProvider()->readCD( /* client */ this,
197 /* byteStart */ byteStart
,
199 /* sectorArea */ sectorArea
,
200 /* sectorType */ sectorType
,
201 /* completion */ completion
);
204 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206 IOReturn
IOCDMedia::readISRC(UInt8 track
, CDISRC isrc
)
209 // Read the International Standard Recording Code for the specified track.
211 // This method will work even when the media is in the terminated state.
216 return kIOReturnNoMedia
;
219 return getProvider()->readISRC(track
, isrc
);
222 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
224 IOReturn
IOCDMedia::readMCN(CDMCN mcn
)
227 // Read the Media Catalog Number (also known as the Universal Product Code).
229 // This method will work even when the media is in the terminated state.
234 return kIOReturnNoMedia
;
237 return getProvider()->readMCN(mcn
);
240 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
242 CDTOC
* IOCDMedia::getTOC()
245 // Get the full Table Of Contents.
247 // This method will work even when the media is in the terminated state.
255 return getProvider()->getTOC();
258 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
260 OSMetaClassDefineReservedUnused(IOCDMedia
, 0);
262 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
264 OSMetaClassDefineReservedUnused(IOCDMedia
, 1);
266 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
268 OSMetaClassDefineReservedUnused(IOCDMedia
, 2);
270 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
272 OSMetaClassDefineReservedUnused(IOCDMedia
, 3);
274 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
276 OSMetaClassDefineReservedUnused(IOCDMedia
, 4);
278 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
280 OSMetaClassDefineReservedUnused(IOCDMedia
, 5);
282 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
284 OSMetaClassDefineReservedUnused(IOCDMedia
, 6);
286 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
288 OSMetaClassDefineReservedUnused(IOCDMedia
, 7);
290 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
292 OSMetaClassDefineReservedUnused(IOCDMedia
, 8);
294 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
296 OSMetaClassDefineReservedUnused(IOCDMedia
, 9);
298 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
300 OSMetaClassDefineReservedUnused(IOCDMedia
, 10);
302 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
304 OSMetaClassDefineReservedUnused(IOCDMedia
, 11);
306 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
308 OSMetaClassDefineReservedUnused(IOCDMedia
, 12);
310 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
312 OSMetaClassDefineReservedUnused(IOCDMedia
, 13);
314 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
316 OSMetaClassDefineReservedUnused(IOCDMedia
, 14);
318 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
320 OSMetaClassDefineReservedUnused(IOCDMedia
, 15);