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 |
+ |
#import <IOKit/storage/IOBlockStorageDevice.h> |
35 |
|
#import <IOKit/storage/IOCDMedia.h> |
36 |
|
#import <IOKit/storage/IOCDMediaBSDClient.h> |
37 |
|
#import <CoreFoundation/CoreFoundation.h> |
65 |
|
|
66 |
|
// Let this task talk to the guts of the kernel: |
67 |
|
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
68 |
< |
bug("IOMasterPort failed. Won't be able to do anything with CD drives"); |
68 |
> |
bug("IOMasterPort failed. Won't be able to do anything with CD drives\n"); |
69 |
|
|
70 |
|
|
71 |
|
// CD media are instances of class kIOCDMediaClass |
76 |
|
// has a property with key kIOMediaEjectable. We limit |
77 |
|
// the match only to those CDs that are actually ejectable |
78 |
|
CFDictionarySetValue(classesToMatch, |
79 |
< |
CFSTR(kIOMediaEjectable), kCFBooleanTrue); |
79 |
> |
CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); |
80 |
|
} |
81 |
|
|
82 |
|
if ( IOServiceGetMatchingServices(masterPort, |
92 |
|
{ |
93 |
|
char bsdPath[MAXPATHLEN]; |
94 |
|
CFTypeRef bsdPathAsCFString = |
95 |
< |
IORegistryEntryCreateCFProperty(nextCD, CFSTR(kIOBSDName), |
96 |
< |
kCFAllocatorDefault, 0); |
95 |
> |
IORegistryEntryCreateCFProperty(nextCD, |
96 |
> |
CFSTR(kIOBSDNameKey), |
97 |
> |
kCFAllocatorDefault, 0); |
98 |
|
*bsdPath = '\0'; |
99 |
|
if ( bsdPathAsCFString ) |
100 |
|
{ |
108 |
|
MAXPATHLEN - devPathLength, |
109 |
|
kCFStringEncodingASCII) ) |
110 |
|
{ |
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"); |
111 |
|
D(bug("CDROM BSD path: %s\n", bsdPath)); |
112 |
+ |
PrefsAddString("cdrom", bsdPath); |
113 |
|
} |
114 |
|
else |
115 |
|
D(bug("Could not get BSD device path for CD\n")); |
116 |
|
|
117 |
|
CFRelease(bsdPathAsCFString); |
118 |
|
} |
119 |
< |
|
120 |
< |
PrefsAddString("cdrom", bsdPath); |
119 |
> |
else |
120 |
> |
D(bug("Cannot determine bsdPath for CD\n")); |
121 |
|
} |
122 |
|
|
123 |
|
IOObjectRelease(nextCD); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
+ |
void DarwinAddFloppyPrefs(void) |
129 |
+ |
{ |
130 |
+ |
mach_port_t masterPort; // The way to talk to the kernel |
131 |
+ |
io_iterator_t allFloppies; // List of CD drives on the system |
132 |
+ |
CFMutableDictionaryRef classesToMatch; |
133 |
+ |
io_object_t nextFloppy; |
134 |
+ |
|
135 |
+ |
|
136 |
+ |
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
137 |
+ |
bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n"); |
138 |
+ |
|
139 |
+ |
|
140 |
+ |
classesToMatch = IOServiceMatching(kIOMediaClass); |
141 |
+ |
if ( classesToMatch ) |
142 |
+ |
{ |
143 |
+ |
// We acually want removables that are _not_ CDs, |
144 |
+ |
// but I don't know how to do that yet. |
145 |
+ |
CFDictionarySetValue(classesToMatch, |
146 |
+ |
CFSTR(kIOMediaRemovableKey), kCFBooleanTrue); |
147 |
+ |
} |
148 |
+ |
|
149 |
+ |
if ( IOServiceGetMatchingServices(masterPort, |
150 |
+ |
classesToMatch, &allFloppies) != KERN_SUCCESS ) |
151 |
+ |
{ |
152 |
+ |
D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n")); |
153 |
+ |
return; |
154 |
+ |
} |
155 |
+ |
|
156 |
+ |
|
157 |
+ |
// Iterate through each floppy |
158 |
+ |
while ( nextFloppy = IOIteratorNext(allFloppies)) |
159 |
+ |
{ |
160 |
+ |
char bsdPath[MAXPATHLEN]; |
161 |
+ |
CFTypeRef bsdPathAsCFString = |
162 |
+ |
IORegistryEntryCreateCFProperty(nextFloppy, |
163 |
+ |
CFSTR(kIOBSDNameKey), |
164 |
+ |
kCFAllocatorDefault, 0); |
165 |
+ |
*bsdPath = '\0'; |
166 |
+ |
if ( bsdPathAsCFString ) |
167 |
+ |
{ |
168 |
+ |
size_t devPathLength; |
169 |
+ |
|
170 |
+ |
strcpy(bsdPath, "/dev/"); |
171 |
+ |
devPathLength = strlen(bsdPath); |
172 |
+ |
|
173 |
+ |
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, |
174 |
+ |
bsdPath + devPathLength, |
175 |
+ |
MAXPATHLEN - devPathLength, |
176 |
+ |
kCFStringEncodingASCII) ) |
177 |
+ |
{ |
178 |
+ |
D(bug("Floppy BSD path: %s\n", bsdPath)); |
179 |
+ |
PrefsAddString("floppy", bsdPath); |
180 |
+ |
} |
181 |
+ |
else |
182 |
+ |
D(bug("Could not get BSD device path for floppy\n")); |
183 |
+ |
|
184 |
+ |
CFRelease(bsdPathAsCFString); |
185 |
+ |
} |
186 |
+ |
else |
187 |
+ |
D(bug("Cannot determine bsdPath for floppy\n")); |
188 |
+ |
} |
189 |
+ |
|
190 |
+ |
IOObjectRelease(nextFloppy); |
191 |
+ |
IOObjectRelease(allFloppies); |
192 |
+ |
} |
193 |
+ |
|
194 |
+ |
|
195 |
+ |
void DarwinAddSerialPrefs(void) |
196 |
+ |
{ |
197 |
+ |
mach_port_t masterPort; // The way to talk to the kernel |
198 |
+ |
io_iterator_t allModems; // List of modems on the system |
199 |
+ |
CFMutableDictionaryRef classesToMatch; |
200 |
+ |
io_object_t nextModem; |
201 |
+ |
|
202 |
+ |
|
203 |
+ |
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) |
204 |
+ |
bug("IOMasterPort failed. Won't be able to do anything with modems\n"); |
205 |
+ |
|
206 |
+ |
|
207 |
+ |
// Serial devices are instances of class IOSerialBSDClient |
208 |
+ |
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue); |
209 |
+ |
if ( classesToMatch ) |
210 |
+ |
{ |
211 |
+ |
// Narrow the search a little further. Each serial device object has |
212 |
+ |
// a property with key kIOSerialBSDTypeKey and a value that is one of |
213 |
+ |
// kIOSerialBSDAllTypes, kIOSerialBSDModemType, or kIOSerialBSDRS232Type. |
214 |
+ |
|
215 |
+ |
CFDictionarySetValue(classesToMatch, |
216 |
+ |
CFSTR(kIOSerialBSDTypeKey), |
217 |
+ |
CFSTR(kIOSerialBSDModemType)); |
218 |
+ |
|
219 |
+ |
// This will find built-in and USB modems, but not serial modems. |
220 |
+ |
} |
221 |
+ |
|
222 |
+ |
if ( IOServiceGetMatchingServices(masterPort, |
223 |
+ |
classesToMatch, &allModems) != KERN_SUCCESS ) |
224 |
+ |
{ |
225 |
+ |
D(bug("IOServiceGetMatchingServices failed. No modems found?\n")); |
226 |
+ |
return; |
227 |
+ |
} |
228 |
+ |
|
229 |
+ |
// Iterate through each modem |
230 |
+ |
while ( nextModem = IOIteratorNext(allModems)) |
231 |
+ |
{ |
232 |
+ |
char bsdPath[MAXPATHLEN]; |
233 |
+ |
CFTypeRef bsdPathAsCFString = |
234 |
+ |
IORegistryEntryCreateCFProperty(nextModem, |
235 |
+ |
CFSTR(kIOCalloutDeviceKey), |
236 |
+ |
// kIODialinDeviceKey? |
237 |
+ |
kCFAllocatorDefault, 0); |
238 |
+ |
*bsdPath = '\0'; |
239 |
+ |
if ( bsdPathAsCFString ) |
240 |
+ |
{ |
241 |
+ |
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, |
242 |
+ |
bsdPath, MAXPATHLEN, |
243 |
+ |
kCFStringEncodingASCII) ) |
244 |
+ |
{ |
245 |
+ |
D(bug("Modem BSD path: %s\n", bsdPath)); |
246 |
+ |
|
247 |
+ |
// Note that if there are multiple modems, we only get the last |
248 |
+ |
PrefsAddString("seriala", bsdPath); |
249 |
+ |
} |
250 |
+ |
else |
251 |
+ |
D(bug("Could not get BSD device path for modem\n")); |
252 |
+ |
|
253 |
+ |
CFRelease(bsdPathAsCFString); |
254 |
+ |
} |
255 |
+ |
else |
256 |
+ |
D(puts("Cannot determine bsdPath for modem\n")); |
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
IOObjectRelease(nextModem); |
260 |
+ |
IOObjectRelease(allModems); |
261 |
+ |
|
262 |
+ |
|
263 |
+ |
// Getting a printer device is a bit harder. Creating a fake device |
264 |
+ |
// that emulates a simple printer (e.g. a HP DeskJet) is one possibility, |
265 |
+ |
// but for now I will just create a fake, safe, device entry: |
266 |
+ |
|
267 |
+ |
PrefsAddString("serialb", "/dev/null"); |
268 |
+ |
} |
269 |
+ |
|
270 |
+ |
|
271 |
|
#ifdef MAC_OS_X_VERSION_10_2 |
272 |
|
/* |
273 |
|
* Read CD-ROM TOC (binary MSF format, 804 bytes max.) |