7 |
|
* |
8 |
|
* Based on Apple's CDROMSample.c and Evan Jones' cd-discid.c patches |
9 |
|
* |
10 |
< |
* Basilisk II (C) 1997-2003 Christian Bauer |
10 |
> |
* Basilisk II (C) 1997-2004 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 |
78 |
|
// has a property with key kIOMediaEjectable. We limit |
79 |
|
// the match only to those CDs that are actually ejectable |
80 |
|
CFDictionarySetValue(classesToMatch, |
81 |
< |
CFSTR(kIOMediaEjectable), kCFBooleanTrue); |
81 |
> |
CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); |
82 |
|
} |
83 |
|
|
84 |
|
if ( IOServiceGetMatchingServices(masterPort, |
94 |
|
{ |
95 |
|
char bsdPath[MAXPATHLEN]; |
96 |
|
CFTypeRef bsdPathAsCFString = |
97 |
< |
IORegistryEntryCreateCFProperty(nextCD, CFSTR(kIOBSDName), |
98 |
< |
kCFAllocatorDefault, 0); |
97 |
> |
IORegistryEntryCreateCFProperty(nextCD, |
98 |
> |
CFSTR(kIOBSDNameKey), |
99 |
> |
kCFAllocatorDefault, 0); |
100 |
|
*bsdPath = '\0'; |
101 |
|
if ( bsdPathAsCFString ) |
102 |
|
{ |
110 |
|
MAXPATHLEN - devPathLength, |
111 |
|
kCFStringEncodingASCII) ) |
112 |
|
{ |
108 |
– |
// If we try to do raw reads on the file bsdPath (e.g. /dev/disk5), |
109 |
– |
// we get a lot of extra padding in the data. For some reason, |
110 |
– |
// the device we need has a different name (e.g. /dev/disk5s1) |
111 |
– |
//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 |
+ |
#ifdef MAC_OS_X_VERSION_10_2 |
133 |
+ |
mach_port_t masterPort; // The way to talk to the kernel |
134 |
+ |
io_iterator_t allFloppies; // List of CD drives on the system |
135 |
+ |
CFMutableDictionaryRef classesToMatch; |
136 |
+ |
io_object_t nextFloppy; |
137 |
+ |
|
138 |
+ |
|
139 |
+ |
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
140 |
+ |
bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n"); |
141 |
+ |
|
142 |
+ |
|
143 |
+ |
classesToMatch = IOServiceMatching(kIOMediaClass); |
144 |
+ |
if ( classesToMatch ) |
145 |
+ |
{ |
146 |
+ |
// We acually want removables that are _not_ CDs, |
147 |
+ |
// but I don't know how to do that yet. |
148 |
+ |
CFDictionarySetValue(classesToMatch, |
149 |
+ |
CFSTR(kIOMediaRemovableKey), kCFBooleanTrue); |
150 |
+ |
} |
151 |
+ |
|
152 |
+ |
if ( IOServiceGetMatchingServices(masterPort, |
153 |
+ |
classesToMatch, &allFloppies) != KERN_SUCCESS ) |
154 |
+ |
{ |
155 |
+ |
D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n")); |
156 |
+ |
return; |
157 |
+ |
} |
158 |
+ |
|
159 |
+ |
|
160 |
+ |
// Iterate through each floppy |
161 |
+ |
while ( nextFloppy = IOIteratorNext(allFloppies)) |
162 |
+ |
{ |
163 |
+ |
char bsdPath[MAXPATHLEN]; |
164 |
+ |
CFTypeRef bsdPathAsCFString = |
165 |
+ |
IORegistryEntryCreateCFProperty(nextFloppy, |
166 |
+ |
CFSTR(kIOBSDNameKey), |
167 |
+ |
kCFAllocatorDefault, 0); |
168 |
+ |
*bsdPath = '\0'; |
169 |
+ |
if ( bsdPathAsCFString ) |
170 |
+ |
{ |
171 |
+ |
size_t devPathLength; |
172 |
+ |
|
173 |
+ |
strcpy(bsdPath, "/dev/"); |
174 |
+ |
devPathLength = strlen(bsdPath); |
175 |
+ |
|
176 |
+ |
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, |
177 |
+ |
bsdPath + devPathLength, |
178 |
+ |
MAXPATHLEN - devPathLength, |
179 |
+ |
kCFStringEncodingASCII) ) |
180 |
+ |
{ |
181 |
+ |
D(bug("Floppy BSD path: %s\n", bsdPath)); |
182 |
+ |
PrefsAddString("floppy", bsdPath); |
183 |
+ |
} |
184 |
+ |
else |
185 |
+ |
D(bug("Could not get BSD device path for floppy\n")); |
186 |
+ |
|
187 |
+ |
CFRelease(bsdPathAsCFString); |
188 |
+ |
} |
189 |
+ |
else |
190 |
+ |
D(bug("Cannot determine bsdPath for floppy\n")); |
191 |
+ |
} |
192 |
+ |
|
193 |
+ |
IOObjectRelease(nextFloppy); |
194 |
+ |
IOObjectRelease(allFloppies); |
195 |
+ |
#endif |
196 |
+ |
} |
197 |
+ |
|
198 |
+ |
|
199 |
+ |
void DarwinAddSerialPrefs(void) |
200 |
+ |
{ |
201 |
+ |
mach_port_t masterPort; // The way to talk to the kernel |
202 |
+ |
io_iterator_t allModems; // List of modems on the system |
203 |
+ |
CFMutableDictionaryRef classesToMatch; |
204 |
+ |
io_object_t nextModem; |
205 |
+ |
|
206 |
+ |
|
207 |
+ |
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
208 |
+ |
bug("IOMasterPort failed. Won't be able to do anything with modems\n"); |
209 |
+ |
|
210 |
+ |
|
211 |
+ |
// Serial devices are instances of class IOSerialBSDClient |
212 |
+ |
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue); |
213 |
+ |
if ( classesToMatch ) |
214 |
+ |
{ |
215 |
+ |
// Narrow the search a little further. Each serial device object has |
216 |
+ |
// a property with key kIOSerialBSDTypeKey and a value that is one of |
217 |
+ |
// kIOSerialBSDAllTypes, kIOSerialBSDModemType, or kIOSerialBSDRS232Type. |
218 |
+ |
|
219 |
+ |
CFDictionarySetValue(classesToMatch, |
220 |
+ |
CFSTR(kIOSerialBSDTypeKey), |
221 |
+ |
CFSTR(kIOSerialBSDModemType)); |
222 |
+ |
|
223 |
+ |
// This will find built-in and USB modems, but not serial modems. |
224 |
+ |
} |
225 |
+ |
|
226 |
+ |
if ( IOServiceGetMatchingServices(masterPort, |
227 |
+ |
classesToMatch, &allModems) != KERN_SUCCESS ) |
228 |
+ |
{ |
229 |
+ |
D(bug("IOServiceGetMatchingServices failed. No modems found?\n")); |
230 |
+ |
return; |
231 |
+ |
} |
232 |
+ |
|
233 |
+ |
// Iterate through each modem |
234 |
+ |
while ( nextModem = IOIteratorNext(allModems)) |
235 |
+ |
{ |
236 |
+ |
char bsdPath[MAXPATHLEN]; |
237 |
+ |
CFTypeRef bsdPathAsCFString = |
238 |
+ |
IORegistryEntryCreateCFProperty(nextModem, |
239 |
+ |
CFSTR(kIOCalloutDeviceKey), |
240 |
+ |
// kIODialinDeviceKey? |
241 |
+ |
kCFAllocatorDefault, 0); |
242 |
+ |
*bsdPath = '\0'; |
243 |
+ |
if ( bsdPathAsCFString ) |
244 |
+ |
{ |
245 |
+ |
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, |
246 |
+ |
bsdPath, MAXPATHLEN, |
247 |
+ |
kCFStringEncodingASCII) ) |
248 |
+ |
{ |
249 |
+ |
D(bug("Modem BSD path: %s\n", bsdPath)); |
250 |
+ |
|
251 |
+ |
// Note that if there are multiple modems, we only get the last |
252 |
+ |
PrefsAddString("seriala", bsdPath); |
253 |
+ |
} |
254 |
+ |
else |
255 |
+ |
D(bug("Could not get BSD device path for modem\n")); |
256 |
+ |
|
257 |
+ |
CFRelease(bsdPathAsCFString); |
258 |
+ |
} |
259 |
+ |
else |
260 |
+ |
D(puts("Cannot determine bsdPath for modem\n")); |
261 |
+ |
} |
262 |
+ |
|
263 |
+ |
IOObjectRelease(nextModem); |
264 |
+ |
IOObjectRelease(allModems); |
265 |
+ |
|
266 |
+ |
|
267 |
+ |
// Getting a printer device is a bit harder. Creating a fake device |
268 |
+ |
// that emulates a simple printer (e.g. a HP DeskJet) is one possibility, |
269 |
+ |
// but for now I will just create a fake, safe, device entry: |
270 |
+ |
|
271 |
+ |
PrefsAddString("serialb", "/dev/null"); |
272 |
+ |
} |
273 |
+ |
|
274 |
+ |
|
275 |
|
#ifdef MAC_OS_X_VERSION_10_2 |
276 |
|
/* |
277 |
|
* Read CD-ROM TOC (binary MSF format, 804 bytes max.) |