7 |
|
* |
8 |
|
* Based on Apple's CDROMSample.c and Evan Jones' cd-discid.c patches |
9 |
|
* |
10 |
< |
* Basilisk II (C) 1997-2004 Christian Bauer |
10 |
> |
* Basilisk II (C) 1997-2005 Christian Bauer |
11 |
|
* |
12 |
|
* This program is free software; you can redistribute it and/or modify |
13 |
|
* it under the terms of the GNU General Public License as published by |
28 |
|
#import <sys/param.h> |
29 |
|
#import <IOKit/IOKitLib.h> |
30 |
|
#import <IOKit/IOBSD.h> |
31 |
+ |
#import <IOKit/serial/IOSerialKeys.h> |
32 |
|
#import <IOKit/storage/IOMedia.h> |
33 |
|
#import <IOKit/storage/IOMediaBSDClient.h> |
34 |
+ |
#ifdef MAC_OS_X_VERSION_10_2 |
35 |
+ |
#import <IOKit/storage/IOBlockStorageDevice.h> |
36 |
+ |
#endif |
37 |
|
#import <IOKit/storage/IOCDMedia.h> |
38 |
|
#import <IOKit/storage/IOCDMediaBSDClient.h> |
39 |
|
#import <CoreFoundation/CoreFoundation.h> |
67 |
|
|
68 |
|
// Let this task talk to the guts of the kernel: |
69 |
|
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
70 |
< |
bug("IOMasterPort failed. Won't be able to do anything with CD drives"); |
70 |
> |
bug("IOMasterPort failed. Won't be able to do anything with CD drives\n"); |
71 |
|
|
72 |
|
|
73 |
|
// CD media are instances of class kIOCDMediaClass |
110 |
|
MAXPATHLEN - devPathLength, |
111 |
|
kCFStringEncodingASCII) ) |
112 |
|
{ |
109 |
– |
// If we try to do raw reads on the file bsdPath (e.g. /dev/disk5), |
110 |
– |
// we get a lot of extra padding in the data. For some reason, |
111 |
– |
// the device we need has a different name (e.g. /dev/disk5s1) |
112 |
– |
//strcat(bsdPath, "s1"); |
113 |
|
D(bug("CDROM BSD path: %s\n", bsdPath)); |
114 |
+ |
PrefsAddString("cdrom", bsdPath); |
115 |
|
} |
116 |
|
else |
117 |
|
D(bug("Could not get BSD device path for CD\n")); |
118 |
|
|
119 |
|
CFRelease(bsdPathAsCFString); |
120 |
|
} |
121 |
< |
|
122 |
< |
PrefsAddString("cdrom", bsdPath); |
121 |
> |
else |
122 |
> |
D(bug("Cannot determine bsdPath for CD\n")); |
123 |
|
} |
124 |
|
|
125 |
|
IOObjectRelease(nextCD); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
+ |
void DarwinAddFloppyPrefs(void) |
131 |
+ |
{ |
132 |
+ |
mach_port_t masterPort; // The way to talk to the kernel |
133 |
+ |
io_iterator_t allFloppies; // List of possible floppys |
134 |
+ |
CFMutableDictionaryRef classesToMatch; |
135 |
+ |
io_object_t nextFloppy; |
136 |
+ |
|
137 |
+ |
|
138 |
+ |
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
139 |
+ |
bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n"); |
140 |
+ |
|
141 |
+ |
|
142 |
+ |
// This selects all partitions of all disks |
143 |
+ |
classesToMatch = IOServiceMatching(kIOMediaClass); |
144 |
+ |
if ( classesToMatch ) |
145 |
+ |
{ |
146 |
+ |
// Skip drivers and partitions |
147 |
+ |
CFDictionarySetValue(classesToMatch, |
148 |
+ |
CFSTR(kIOMediaWholeKey), kCFBooleanTrue); |
149 |
+ |
|
150 |
+ |
// Skip fixed drives (hard disks?) |
151 |
+ |
CFDictionarySetValue(classesToMatch, |
152 |
+ |
CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); |
153 |
+ |
} |
154 |
+ |
|
155 |
+ |
if ( IOServiceGetMatchingServices(masterPort, |
156 |
+ |
classesToMatch, &allFloppies) != KERN_SUCCESS ) |
157 |
+ |
{ |
158 |
+ |
D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n")); |
159 |
+ |
return; |
160 |
+ |
} |
161 |
+ |
|
162 |
+ |
|
163 |
+ |
// Iterate through each floppy |
164 |
+ |
while ( nextFloppy = IOIteratorNext(allFloppies)) |
165 |
+ |
{ |
166 |
+ |
char bsdPath[MAXPATHLEN]; |
167 |
+ |
CFTypeRef bsdPathAsCFString = |
168 |
+ |
IORegistryEntryCreateCFProperty(nextFloppy, |
169 |
+ |
CFSTR(kIOBSDNameKey), |
170 |
+ |
kCFAllocatorDefault, 0); |
171 |
+ |
long size; |
172 |
+ |
CFTypeRef sizeAsCFNumber = |
173 |
+ |
IORegistryEntryCreateCFProperty(nextFloppy, |
174 |
+ |
CFSTR(kIOMediaSizeKey), |
175 |
+ |
kCFAllocatorDefault, 0); |
176 |
+ |
|
177 |
+ |
if ( CFNumberGetValue((CFNumberRef)sizeAsCFNumber, |
178 |
+ |
kCFNumberSInt32Type, &size) ) |
179 |
+ |
{ |
180 |
+ |
D(bug("Got size of %ld\n", size)); |
181 |
+ |
if ( size < 800 * 1024 || size > 1440 * 1024 ) |
182 |
+ |
{ |
183 |
+ |
D(puts("Device does not appear to be 800k or 1440k")); |
184 |
+ |
continue; |
185 |
+ |
} |
186 |
+ |
} |
187 |
+ |
else |
188 |
+ |
bug("Couldn't get kIOMediaSizeKey of device"); |
189 |
+ |
|
190 |
+ |
|
191 |
+ |
*bsdPath = '\0'; |
192 |
+ |
if ( bsdPathAsCFString ) |
193 |
+ |
{ |
194 |
+ |
size_t devPathLength; |
195 |
+ |
|
196 |
+ |
strcpy(bsdPath, "/dev/"); |
197 |
+ |
devPathLength = strlen(bsdPath); |
198 |
+ |
|
199 |
+ |
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, |
200 |
+ |
bsdPath + devPathLength, |
201 |
+ |
MAXPATHLEN - devPathLength, |
202 |
+ |
kCFStringEncodingASCII) ) |
203 |
+ |
{ |
204 |
+ |
D(bug("Floppy BSD path: %s\n", bsdPath)); |
205 |
+ |
PrefsAddString("floppy", bsdPath); |
206 |
+ |
} |
207 |
+ |
else |
208 |
+ |
D(bug("Could not get BSD device path for floppy\n")); |
209 |
+ |
|
210 |
+ |
CFRelease(bsdPathAsCFString); |
211 |
+ |
} |
212 |
+ |
else |
213 |
+ |
D(bug("Cannot determine bsdPath for floppy\n")); |
214 |
+ |
} |
215 |
+ |
|
216 |
+ |
IOObjectRelease(nextFloppy); |
217 |
+ |
IOObjectRelease(allFloppies); |
218 |
+ |
} |
219 |
+ |
|
220 |
+ |
|
221 |
+ |
void DarwinAddSerialPrefs(void) |
222 |
+ |
{ |
223 |
+ |
mach_port_t masterPort; // The way to talk to the kernel |
224 |
+ |
io_iterator_t allModems; // List of modems on the system |
225 |
+ |
CFMutableDictionaryRef classesToMatch; |
226 |
+ |
io_object_t nextModem; |
227 |
+ |
|
228 |
+ |
|
229 |
+ |
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
230 |
+ |
bug("IOMasterPort failed. Won't be able to do anything with modems\n"); |
231 |
+ |
|
232 |
+ |
|
233 |
+ |
// Serial devices are instances of class IOSerialBSDClient |
234 |
+ |
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue); |
235 |
+ |
if ( classesToMatch ) |
236 |
+ |
{ |
237 |
+ |
// Narrow the search a little further. Each serial device object has |
238 |
+ |
// a property with key kIOSerialBSDTypeKey and a value that is one of |
239 |
+ |
// kIOSerialBSDAllTypes, kIOSerialBSDModemType, or kIOSerialBSDRS232Type. |
240 |
+ |
|
241 |
+ |
CFDictionarySetValue(classesToMatch, |
242 |
+ |
CFSTR(kIOSerialBSDTypeKey), |
243 |
+ |
CFSTR(kIOSerialBSDModemType)); |
244 |
+ |
|
245 |
+ |
// This will find built-in and USB modems, but not serial modems. |
246 |
+ |
} |
247 |
+ |
|
248 |
+ |
if ( IOServiceGetMatchingServices(masterPort, |
249 |
+ |
classesToMatch, &allModems) != KERN_SUCCESS ) |
250 |
+ |
{ |
251 |
+ |
D(bug("IOServiceGetMatchingServices failed. No modems found?\n")); |
252 |
+ |
return; |
253 |
+ |
} |
254 |
+ |
|
255 |
+ |
// Iterate through each modem |
256 |
+ |
while ( nextModem = IOIteratorNext(allModems)) |
257 |
+ |
{ |
258 |
+ |
char bsdPath[MAXPATHLEN]; |
259 |
+ |
CFTypeRef bsdPathAsCFString = |
260 |
+ |
IORegistryEntryCreateCFProperty(nextModem, |
261 |
+ |
CFSTR(kIOCalloutDeviceKey), |
262 |
+ |
// kIODialinDeviceKey? |
263 |
+ |
kCFAllocatorDefault, 0); |
264 |
+ |
*bsdPath = '\0'; |
265 |
+ |
if ( bsdPathAsCFString ) |
266 |
+ |
{ |
267 |
+ |
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, |
268 |
+ |
bsdPath, MAXPATHLEN, |
269 |
+ |
kCFStringEncodingASCII) ) |
270 |
+ |
{ |
271 |
+ |
D(bug("Modem BSD path: %s\n", bsdPath)); |
272 |
+ |
|
273 |
+ |
// Note that if there are multiple modems, we only get the last |
274 |
+ |
PrefsAddString("seriala", bsdPath); |
275 |
+ |
} |
276 |
+ |
else |
277 |
+ |
D(bug("Could not get BSD device path for modem\n")); |
278 |
+ |
|
279 |
+ |
CFRelease(bsdPathAsCFString); |
280 |
+ |
} |
281 |
+ |
else |
282 |
+ |
D(puts("Cannot determine bsdPath for modem\n")); |
283 |
+ |
} |
284 |
+ |
|
285 |
+ |
IOObjectRelease(nextModem); |
286 |
+ |
IOObjectRelease(allModems); |
287 |
+ |
|
288 |
+ |
|
289 |
+ |
// Getting a printer device is a bit harder. Creating a fake device |
290 |
+ |
// that emulates a simple printer (e.g. a HP DeskJet) is one possibility, |
291 |
+ |
// but for now I will just create a fake, safe, device entry: |
292 |
+ |
|
293 |
+ |
PrefsAddString("serialb", "/dev/null"); |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
|
297 |
|
#ifdef MAC_OS_X_VERSION_10_2 |
298 |
|
/* |
299 |
|
* Read CD-ROM TOC (binary MSF format, 804 bytes max.) |