]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOCDStorage/IOCDMedia.cpp
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IOCDStorage / IOCDMedia.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <IOKit/IOSyncer.h>
24 #include <IOKit/storage/IOCDBlockStorageDriver.h>
25 #include <IOKit/storage/IOCDMedia.h>
26
27 #define super IOMedia
28 OSDefineMetaClassAndStructors(IOCDMedia, IOMedia)
29
30 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 // Local Functions
32
33 static void readCDCompletion(void * target,
34 void * parameter,
35 IOReturn status,
36 UInt64 actualByteCount)
37 {
38 //
39 // Internal completion routine for synchronous version of readCD.
40 //
41
42 if (parameter) *((UInt64 *)parameter) = actualByteCount;
43 ((IOSyncer *)target)->signal(status);
44 }
45
46 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47
48 IOCDBlockStorageDriver * IOCDMedia::getProvider() const
49 {
50 //
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.
54 //
55
56 return (IOCDBlockStorageDriver *) IOService::getProvider();
57 }
58
59 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60
61 void IOCDMedia::read(IOService * /* client */,
62 UInt64 byteStart,
63 IOMemoryDescriptor * buffer,
64 IOStorageCompletion completion)
65 {
66 //
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.
70 //
71 // The buffer will be retained for the duration of the read.
72 //
73 // This method will work even when the media is in the terminated state.
74 //
75
76 if (isInactive())
77 {
78 complete(completion, kIOReturnNoMedia);
79 return;
80 }
81
82 if (_openLevel == kIOStorageAccessNone) // (instantaneous value, no lock)
83 {
84 complete(completion, kIOReturnNotOpen);
85 return;
86 }
87
88 if (_mediaSize == 0 || _preferredBlockSize == 0)
89 {
90 complete(completion, kIOReturnUnformattedMedia);
91 return;
92 }
93
94 if (_mediaSize < byteStart + buffer->getLength())
95 {
96 complete(completion, kIOReturnBadArgument);
97 return;
98 }
99
100 byteStart += _mediaBase;
101 getProvider()->readCD( /* client */ this,
102 /* byteStart */ byteStart,
103 /* buffer */ buffer,
104 /* sectorArea */ (CDSectorArea) 0xF8, // (2352 bytes)
105 /* sectorType */ (CDSectorType) 0x00, // ( all types)
106 /* completion */ completion );
107 }
108
109 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110
111 IOReturn IOCDMedia::readCD(IOService * client,
112 UInt64 byteStart,
113 IOMemoryDescriptor * buffer,
114 CDSectorArea sectorArea,
115 CDSectorType sectorType,
116 UInt64 * actualByteCount = 0)
117 {
118 //
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.
124 //
125 // This method will work even when the media is in the terminated state.
126 //
127
128 IOStorageCompletion completion;
129 IOSyncer * completionSyncer;
130
131 // Initialize the lock we will synchronize against.
132
133 completionSyncer = IOSyncer::create();
134
135 // Fill in the completion information for this request.
136
137 completion.target = completionSyncer;
138 completion.action = readCDCompletion;
139 completion.parameter = actualByteCount;
140
141 // Issue the asynchronous read.
142
143 readCD(client, byteStart, buffer, sectorArea, sectorType, completion);
144
145 // Wait for the read to complete.
146
147 return completionSyncer->wait();
148 }
149
150 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
151
152 void IOCDMedia::readCD(IOService * client,
153 UInt64 byteStart,
154 IOMemoryDescriptor * buffer,
155 CDSectorArea sectorArea,
156 CDSectorType sectorType,
157 IOStorageCompletion completion)
158 {
159 //
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
164 // action.
165 //
166 // The buffer will be retained for the duration of the read.
167 //
168 // This method will work even when the media is in the terminated state.
169 //
170
171 if (isInactive())
172 {
173 complete(completion, kIOReturnNoMedia);
174 return;
175 }
176
177 if (_openLevel == kIOStorageAccessNone) // (instantaneous value, no lock)
178 {
179 complete(completion, kIOReturnNotOpen);
180 return;
181 }
182
183 if (_mediaSize == 0 || _preferredBlockSize == 0)
184 {
185 complete(completion, kIOReturnUnformattedMedia);
186 return;
187 }
188
189 if (_mediaSize < byteStart + buffer->getLength())
190 {
191 complete(completion, kIOReturnBadArgument);
192 return;
193 }
194
195 byteStart += _mediaBase;
196 getProvider()->readCD( /* client */ this,
197 /* byteStart */ byteStart,
198 /* buffer */ buffer,
199 /* sectorArea */ sectorArea,
200 /* sectorType */ sectorType,
201 /* completion */ completion );
202 }
203
204 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
205
206 IOReturn IOCDMedia::readISRC(UInt8 track, CDISRC isrc)
207 {
208 //
209 // Read the International Standard Recording Code for the specified track.
210 //
211 // This method will work even when the media is in the terminated state.
212 //
213
214 if (isInactive())
215 {
216 return kIOReturnNoMedia;
217 }
218
219 return getProvider()->readISRC(track, isrc);
220 }
221
222 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223
224 IOReturn IOCDMedia::readMCN(CDMCN mcn)
225 {
226 //
227 // Read the Media Catalog Number (also known as the Universal Product Code).
228 //
229 // This method will work even when the media is in the terminated state.
230 //
231
232 if (isInactive())
233 {
234 return kIOReturnNoMedia;
235 }
236
237 return getProvider()->readMCN(mcn);
238 }
239
240 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
241
242 CDTOC * IOCDMedia::getTOC()
243 {
244 //
245 // Get the full Table Of Contents.
246 //
247 // This method will work even when the media is in the terminated state.
248 //
249
250 if (isInactive())
251 {
252 return 0;
253 }
254
255 return getProvider()->getTOC();
256 }
257
258 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
259
260 OSMetaClassDefineReservedUnused(IOCDMedia, 0);
261
262 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
263
264 OSMetaClassDefineReservedUnused(IOCDMedia, 1);
265
266 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
267
268 OSMetaClassDefineReservedUnused(IOCDMedia, 2);
269
270 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
271
272 OSMetaClassDefineReservedUnused(IOCDMedia, 3);
273
274 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
275
276 OSMetaClassDefineReservedUnused(IOCDMedia, 4);
277
278 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
279
280 OSMetaClassDefineReservedUnused(IOCDMedia, 5);
281
282 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
283
284 OSMetaClassDefineReservedUnused(IOCDMedia, 6);
285
286 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
287
288 OSMetaClassDefineReservedUnused(IOCDMedia, 7);
289
290 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
291
292 OSMetaClassDefineReservedUnused(IOCDMedia, 8);
293
294 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
295
296 OSMetaClassDefineReservedUnused(IOCDMedia, 9);
297
298 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
299
300 OSMetaClassDefineReservedUnused(IOCDMedia, 10);
301
302 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
303
304 OSMetaClassDefineReservedUnused(IOCDMedia, 11);
305
306 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307
308 OSMetaClassDefineReservedUnused(IOCDMedia, 12);
309
310 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
311
312 OSMetaClassDefineReservedUnused(IOCDMedia, 13);
313
314 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
315
316 OSMetaClassDefineReservedUnused(IOCDMedia, 14);
317
318 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
319
320 OSMetaClassDefineReservedUnused(IOCDMedia, 15);