--- BasiliskII/src/MacOSX/sys_darwin.cpp 2004/01/12 15:29:24 1.2 +++ BasiliskII/src/MacOSX/sys_darwin.cpp 2005/06/12 23:36:33 1.8 @@ -1,5 +1,5 @@ /* - * $Id: sys_darwin.cpp,v 1.2 2004/01/12 15:29:24 cebix Exp $ + * $Id: sys_darwin.cpp,v 1.8 2005/06/12 23:36:33 gbeauche Exp $ * * sys_darwin.cpp - Extra Darwin system dependant routines. Called by: * @@ -7,7 +7,7 @@ * * Based on Apple's CDROMSample.c and Evan Jones' cd-discid.c patches * - * Basilisk II (C) 1997-2004 Christian Bauer + * Basilisk II (C) 1997-2005 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,8 +28,12 @@ #import #import #import +#import #import #import +#ifdef HAVE_IOKIT_STORAGE_IOBLOCKSTORAGEDEVICE_H + #import +#endif #import #import #import @@ -63,7 +67,7 @@ void DarwinAddCDROMPrefs(void) // Let this task talk to the guts of the kernel: if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) - bug("IOMasterPort failed. Won't be able to do anything with CD drives"); + bug("IOMasterPort failed. Won't be able to do anything with CD drives\n"); // CD media are instances of class kIOCDMediaClass @@ -74,7 +78,7 @@ void DarwinAddCDROMPrefs(void) // has a property with key kIOMediaEjectable. We limit // the match only to those CDs that are actually ejectable CFDictionarySetValue(classesToMatch, - CFSTR(kIOMediaEjectable), kCFBooleanTrue); + CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); } if ( IOServiceGetMatchingServices(masterPort, @@ -90,8 +94,9 @@ void DarwinAddCDROMPrefs(void) { char bsdPath[MAXPATHLEN]; CFTypeRef bsdPathAsCFString = - IORegistryEntryCreateCFProperty(nextCD, CFSTR(kIOBSDName), - kCFAllocatorDefault, 0); + IORegistryEntryCreateCFProperty(nextCD, + CFSTR(kIOBSDNameKey), + kCFAllocatorDefault, 0); *bsdPath = '\0'; if ( bsdPathAsCFString ) { @@ -105,19 +110,16 @@ void DarwinAddCDROMPrefs(void) MAXPATHLEN - devPathLength, kCFStringEncodingASCII) ) { - // If we try to do raw reads on the file bsdPath (e.g. /dev/disk5), - // we get a lot of extra padding in the data. For some reason, - // the device we need has a different name (e.g. /dev/disk5s1) - //strcat(bsdPath, "s1"); D(bug("CDROM BSD path: %s\n", bsdPath)); + PrefsAddString("cdrom", bsdPath); } else D(bug("Could not get BSD device path for CD\n")); CFRelease(bsdPathAsCFString); } - - PrefsAddString("cdrom", bsdPath); + else + D(bug("Cannot determine bsdPath for CD\n")); } IOObjectRelease(nextCD); @@ -125,6 +127,173 @@ void DarwinAddCDROMPrefs(void) } +void DarwinAddFloppyPrefs(void) +{ + mach_port_t masterPort; // The way to talk to the kernel + io_iterator_t allFloppies; // List of possible floppys + CFMutableDictionaryRef classesToMatch; + io_object_t nextFloppy; + + + if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) + bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n"); + + + // This selects all partitions of all disks + classesToMatch = IOServiceMatching(kIOMediaClass); + if ( classesToMatch ) + { + // Skip drivers and partitions + CFDictionarySetValue(classesToMatch, + CFSTR(kIOMediaWholeKey), kCFBooleanTrue); + + // Skip fixed drives (hard disks?) + CFDictionarySetValue(classesToMatch, + CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); + } + + if ( IOServiceGetMatchingServices(masterPort, + classesToMatch, &allFloppies) != KERN_SUCCESS ) + { + D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n")); + return; + } + + + // Iterate through each floppy + while ( nextFloppy = IOIteratorNext(allFloppies)) + { + char bsdPath[MAXPATHLEN]; + CFTypeRef bsdPathAsCFString = + IORegistryEntryCreateCFProperty(nextFloppy, + CFSTR(kIOBSDNameKey), + kCFAllocatorDefault, 0); + long size; + CFTypeRef sizeAsCFNumber = + IORegistryEntryCreateCFProperty(nextFloppy, + CFSTR(kIOMediaSizeKey), + kCFAllocatorDefault, 0); + + if ( CFNumberGetValue((CFNumberRef)sizeAsCFNumber, + kCFNumberSInt32Type, &size) ) + { + D(bug("Got size of %ld\n", size)); + if ( size < 800 * 1024 || size > 1440 * 1024 ) + { + D(puts("Device does not appear to be 800k or 1440k")); + continue; + } + } + else + bug("Couldn't get kIOMediaSizeKey of device"); + + + *bsdPath = '\0'; + if ( bsdPathAsCFString ) + { + size_t devPathLength; + + strcpy(bsdPath, "/dev/"); + devPathLength = strlen(bsdPath); + + if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, + bsdPath + devPathLength, + MAXPATHLEN - devPathLength, + kCFStringEncodingASCII) ) + { + D(bug("Floppy BSD path: %s\n", bsdPath)); + PrefsAddString("floppy", bsdPath); + } + else + D(bug("Could not get BSD device path for floppy\n")); + + CFRelease(bsdPathAsCFString); + } + else + D(bug("Cannot determine bsdPath for floppy\n")); + } + + IOObjectRelease(nextFloppy); + IOObjectRelease(allFloppies); +} + + +void DarwinAddSerialPrefs(void) +{ + mach_port_t masterPort; // The way to talk to the kernel + io_iterator_t allModems; // List of modems on the system + CFMutableDictionaryRef classesToMatch; + io_object_t nextModem; + + + if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) + bug("IOMasterPort failed. Won't be able to do anything with modems\n"); + + + // Serial devices are instances of class IOSerialBSDClient + classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue); + if ( classesToMatch ) + { + // Narrow the search a little further. Each serial device object has + // a property with key kIOSerialBSDTypeKey and a value that is one of + // kIOSerialBSDAllTypes, kIOSerialBSDModemType, or kIOSerialBSDRS232Type. + + CFDictionarySetValue(classesToMatch, + CFSTR(kIOSerialBSDTypeKey), + CFSTR(kIOSerialBSDModemType)); + + // This will find built-in and USB modems, but not serial modems. + } + + if ( IOServiceGetMatchingServices(masterPort, + classesToMatch, &allModems) != KERN_SUCCESS ) + { + D(bug("IOServiceGetMatchingServices failed. No modems found?\n")); + return; + } + + // Iterate through each modem + while ( nextModem = IOIteratorNext(allModems)) + { + char bsdPath[MAXPATHLEN]; + CFTypeRef bsdPathAsCFString = + IORegistryEntryCreateCFProperty(nextModem, + CFSTR(kIOCalloutDeviceKey), + // kIODialinDeviceKey? + kCFAllocatorDefault, 0); + *bsdPath = '\0'; + if ( bsdPathAsCFString ) + { + if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, + bsdPath, MAXPATHLEN, + kCFStringEncodingASCII) ) + { + D(bug("Modem BSD path: %s\n", bsdPath)); + + // Note that if there are multiple modems, we only get the last + PrefsAddString("seriala", bsdPath); + } + else + D(bug("Could not get BSD device path for modem\n")); + + CFRelease(bsdPathAsCFString); + } + else + D(puts("Cannot determine bsdPath for modem\n")); + } + + IOObjectRelease(nextModem); + IOObjectRelease(allModems); + + + // Getting a printer device is a bit harder. Creating a fake device + // that emulates a simple printer (e.g. a HP DeskJet) is one possibility, + // but for now I will just create a fake, safe, device entry: + + PrefsAddString("serialb", "/dev/null"); +} + + #ifdef MAC_OS_X_VERSION_10_2 /* * Read CD-ROM TOC (binary MSF format, 804 bytes max.)