=================================================================== RCS file: /MkLinux/floppy-darwin/floppy_blkdev.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- floppy-darwin/floppy_blkdev.cpp 2002/04/29 23:50:37 1.34 +++ floppy-darwin/floppy_blkdev.cpp 2002/05/15 01:08:16 1.35 @@ -48,7 +48,14 @@ BSIORequestBlockPtr parentRequest, OptionBits options, struct BSErrorList **errors); +OSStatus FloppyPluginGetInfo(int unit, + struct BSStoreMPIInfo *info); +BSIOStatus FloppyPluginFormatMedia(int unit, BSStorePtr formatStore, + BSFormatIndex formatType); OSStatus FloppyPluginReinit(int unit, BSStorePtr initStore); +OSStatus FloppyPluginFlush(int unit, BSIORequestBlockPtr parentRequest, + struct BSErrorList **errors); +OSStatus FloppyPluginEject(int unit, BSAccessibilityState gotoState); int non_bsd_sleep(void *event, unsigned long usec); @@ -57,7 +64,6 @@ int org_mklinux_iokit_swim3_busyflag = 0; extern int printf(char *a, ...); #include "MkLinux_floppy/dprintf.h" - } // #undef MACH_DEBUG @@ -79,29 +85,105 @@ IOReturn org_mklinux_iokit_swim3_driver::doEjectMedia(void) { - dev_t dev; - if(locked) return kIOReturnBusy; - - dev=(this->busdev->unit << 6); - if (fdsetstat(dev, (dev_flavor_t)V_EJECT, NULL, 0) == D_SUCCESS) - return kIOReturnSuccess; - else - return kIOReturnError; + + if (FloppyPluginFlush(this->busdev->unit, 0, 0) != kBSIOCompleted) + return kIOReturnError; + + if (FloppyPluginEject(this->busdev->unit, kBSOffline) != noErr) + return kIOReturnError; + + return kIOReturnSuccess; } IOReturn org_mklinux_iokit_swim3_driver::doFormatMedia(UInt64 byteCapacity) { - /* @@@ WRITE ME! @@@*/ - return kIOReturnUnsupported; + int index = 0; + struct BSStoreMPIInfo info; + int nblks; + + if (FloppyPluginGetInfo(this->busdev->unit, &info) != E_BSSuccess) + return kIOReturnError; + + nblks = info.storeSize / 512; // get number of blocks in media + switch (nblks) { + case 0: // no disk inserted + return kIOReturnError; + case 800: // 400k GCR + if (byteCapacity == (800 * 512)) + index = 1; + else + return kIOReturnError; + case 1600: // 800k GCR + case 1440: // 720k MFM + if (byteCapacity == (1600 * 512)) + index = 2; + else if (byteCapacity == (1440 * 512)) + index = 3; + else + return kIOReturnError; + case 2880: + if (byteCapacity == (2880 * 512)) + index = 1; + else + return kIOReturnError; + case 3360: + case 5760: + default: + /* These wacko cases would need a lot of help.... */ + return kIOReturnError; + } + + if (FloppyPluginFormatMedia(this->busdev->unit, NULL, index) != kBSIOCompleted) { + return kIOReturnError; + } + return kIOReturnSuccess; } UInt32 org_mklinux_iokit_swim3_driver::doGetFormatCapacities(UInt64 * capacities, UInt32 capacitiesMaxCount) { - /* @@@ WRITE ME! @@@*/ - return kIOReturnUnsupported; + struct BSStoreMPIInfo info; +#if 0 + BSStorePtr infoStore; +#endif + UInt64 *ptr; + int nblks; + + ptr = capacities; + + if (FloppyPluginGetInfo(this->busdev->unit, &info) != E_BSSuccess) + return 0; + + nblks = info.storeSize / 512; // get number of blocks in media + switch (nblks) { + case 0: // no disk inserted + return 0; + case 800: // 400k GCR + *capacities = (800 * 512); + return 1; + case 1600: // 800k GCR + *capacities = 1600; + capacities++; + *capacities = 1440; + return 2; + case 1440: // 720k MFM + *capacities = 1440; + capacities++; + *capacities = 1600; + return 2; + case 2880: + case 3360: + case 5760: + *capacities = info.storeSize; + return 1; + default: + *capacities = info.storeSize; + return 1; + } + /* We should never get here. */ + return 0; } IOReturn org_mklinux_iokit_swim3_driver::doLockUnlockMedia(bool doLock) @@ -253,12 +335,6 @@ // virtual char * getVendorString(void) = 0; // virtual bool init(OSDictionary * properties); -extern "C" -{ -OSStatus - FloppyPluginGetInfo(int unit, - struct BSStoreMPIInfo *info); -} IOReturn org_mklinux_iokit_swim3_driver::reportBlockSize(UInt64 *blockSize) { struct BSStoreMPIInfo info;