130
void DarwinAddFloppyPrefs(void)
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;
138
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS )
139
bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n");
142
// This selects all partitions of all disks
143
classesToMatch = IOServiceMatching(kIOMediaClass);
144
if ( classesToMatch )
146
// Skip drivers and partitions
147
CFDictionarySetValue(classesToMatch,
148
CFSTR(kIOMediaWholeKey), kCFBooleanTrue);
150
// Skip fixed drives (hard disks?)
151
CFDictionarySetValue(classesToMatch,
152
CFSTR(kIOMediaEjectableKey), kCFBooleanTrue);
155
if ( IOServiceGetMatchingServices(masterPort,
156
classesToMatch, &allFloppies) != KERN_SUCCESS )
158
D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n"));
163
// Iterate through each floppy
164
while ( nextFloppy = IOIteratorNext(allFloppies))
166
char bsdPath[MAXPATHLEN];
167
CFTypeRef bsdPathAsCFString =
168
IORegistryEntryCreateCFProperty(nextFloppy,
169
CFSTR(kIOBSDNameKey),
170
kCFAllocatorDefault, 0);
172
CFTypeRef sizeAsCFNumber =
173
IORegistryEntryCreateCFProperty(nextFloppy,
174
CFSTR(kIOMediaSizeKey),
175
kCFAllocatorDefault, 0);
177
if ( CFNumberGetValue((CFNumberRef)sizeAsCFNumber,
178
kCFNumberSInt32Type, &size) )
180
D(bug("Got size of %ld\n", size));
181
if ( size < 800 * 1024 || size > 1440 * 1024 )
183
D(puts("Device does not appear to be 800k or 1440k"));
188
bug("Couldn't get kIOMediaSizeKey of device");
192
if ( bsdPathAsCFString )
194
size_t devPathLength;
196
strcpy(bsdPath, "/dev/");
197
devPathLength = strlen(bsdPath);
199
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString,
200
bsdPath + devPathLength,
201
MAXPATHLEN - devPathLength,
202
kCFStringEncodingASCII) )
204
D(bug("Floppy BSD path: %s\n", bsdPath));
205
PrefsAddString("floppy", bsdPath);
208
D(bug("Could not get BSD device path for floppy\n"));
210
CFRelease(bsdPathAsCFString);
213
D(bug("Cannot determine bsdPath for floppy\n"));
216
IOObjectRelease(nextFloppy);
217
IOObjectRelease(allFloppies);
221
void DarwinAddSerialPrefs(void)
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;
229
if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS )
230
bug("IOMasterPort failed. Won't be able to do anything with modems\n");
233
// Serial devices are instances of class IOSerialBSDClient
234
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
235
if ( classesToMatch )
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.
241
CFDictionarySetValue(classesToMatch,
242
CFSTR(kIOSerialBSDTypeKey),
243
CFSTR(kIOSerialBSDModemType));
245
// This will find built-in and USB modems, but not serial modems.
248
if ( IOServiceGetMatchingServices(masterPort,
249
classesToMatch, &allModems) != KERN_SUCCESS )
251
D(bug("IOServiceGetMatchingServices failed. No modems found?\n"));
255
// Iterate through each modem
256
while ( nextModem = IOIteratorNext(allModems))
258
char bsdPath[MAXPATHLEN];
259
CFTypeRef bsdPathAsCFString =
260
IORegistryEntryCreateCFProperty(nextModem,
261
CFSTR(kIOCalloutDeviceKey),
262
// kIODialinDeviceKey?
263
kCFAllocatorDefault, 0);
265
if ( bsdPathAsCFString )
267
if ( CFStringGetCString((const __CFString *)bsdPathAsCFString,
269
kCFStringEncodingASCII) )
271
D(bug("Modem BSD path: %s\n", bsdPath));
273
// Note that if there are multiple modems, we only get the last
274
PrefsAddString("seriala", bsdPath);
277
D(bug("Could not get BSD device path for modem\n"));
279
CFRelease(bsdPathAsCFString);
282
D(puts("Cannot determine bsdPath for modem\n"));
285
IOObjectRelease(nextModem);
286
IOObjectRelease(allModems);
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:
293
PrefsAddString("serialb", "/dev/null");
128
297
#ifdef MAC_OS_X_VERSION_10_2
130
299
* Read CD-ROM TOC (binary MSF format, 804 bytes max.)