Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!apple!apple.com!blob From: blob@apple.com (Brian Bechtel) Newsgroups: comp.sys.mac.programmer Subject: Re: Telling Floppies from Hard Disks Message-ID: <3841@internal.Apple.COM> Date: 23 Aug 89 20:48:05 GMT References: <1742@cs-spool.calgary.UUCP> Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 55 In article <1742@cs-spool.calgary.UUCP> jamesm@cpsc.ucalgary.ca (Mark James) writes: > I'm looking for a method to test a volume to see if it is a floppy or a > hard drive. I have written an INIT to patch PBMountVol to check an > inserted disk for viruses before mounting it and giving a dialog box if > it is infected. The problem is it takes far to long to mount a hard > drive this way. It sounds like what you really want to check is if a device in the drive queue is removable or not. To do this, examine the four bytes of flags preceeding the drive queue entry for this device. See Inside Mac IV-181 & 182 for details. C source is: /* we assume that you get the drive number from some appropriate place, such as doing a PBHGetVInfo for the volume or looking directly in the vcb (ackk!) */ Boolean IsEjectable(driveNumber) short driveNumber { DrvQElPtr d; QHdrPtr queueHeader; Ptr p; queueHeader = GetDrvQHdr(); d = (DrvQElPtr)queueHeader->qHead; while (d != nil) /* find the appropriate drive # */ { if (d->dQDrive == driveNumber) /* is this the drive we want? */ { p = (Ptr)d; p -= 3; /* to get to the byte with eject info */ if (*p == 8) return false; /* non ejectable disk in drive */ else return true; } d = (DrvQElPtr)d->qLink; } return false; /* you specified an invalid drive number */ } Now if you really want to know if a volume is a floppy or not, use PBHGetVInfo, and multiply out the ioVNmAlBlks (remember, it's unsigned!) times ioVAlBlkSiz. Currently valid sizes include 400K, 800K, 720K, 1440K. How will you handle other sizes from the future? Nasty. That's why I think you are really asking to detect removable media. In such an INIT, you might also want to check that the volume isn't extremely large (i.e. CD-ROM), so that you don't waste an incredible amount of time mounting those volumes, either. --Brian Bechtel blob@apple.com "My opinion, not Apple's"