Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!think!linus!gwr From: gwr@linus.UUCP (Gordon W. Ross) Newsgroups: comp.os.minix Subject: Re: Booting Minix from 1.44m floppies Summary: (Really about automatic media detection.) Message-ID: <88750@linus.UUCP> Date: 16 Jan 90 23:21:44 GMT References: <7961@nigel.udel.EDU>,<2401@ditsyda.oz> Reply-To: gwr@linus.mitre.org Organization: The MITRE Corp., Bedford, MA Lines: 95 In article <7961@nigel.udel.EDU> Peter_Van_Epp@cc.sfu.ca writes: [Aubrey McIntosh writes] >>Why not just seek to track 40? >[...] >Because some 5.25s will get to track 41, and because the floppy >controller doesn't know how many tracks the drive has (and in >at least some cases neither does the drive except via a mechanical >stop!) The standard way to determine 40 vs. 80 track drive is as follows: (Pseudo code, based on IBM BIOS listing) Recalibrate drive, seek to track 48 (40 track drives can't seek this far) seek to track 10 (40 track drive now has position < 10) for (trk=10; trk; trk--) { Tell FDC to sense-status of floppy if floppy status has TRACK_0 bit on disk is only 40 tracks return(disk_is_40_tracks); } return(disk_is_80_tracks); Note that this test only needs to be done once at driver initialization time. The number of tracks on the DRIVE never changes, though a 360KB disk in a 1.2MB drive only uses (40) even cylinders. This is one reason I don't much like the idea of a "media sensitive" floppy device. Even the floppy driver itself can only guess! Automatically sensing the media type (of a formatted disk) can be done by reading track 0 and track 1, as Bruce Evans suggested. This should be done on every dev_open call to the floppy driver. An algorithm for determining media format is as follows: (We already know the size of the DRIVE.) If drive has 80 tracks, Seek to track 1 If sector 1 is readable, It's an 80 track format Else Assume 40 track disk in 80 track drive. (Double-stepping required) EndIf Else (drive is 40 track) Format uses 40 track (no double-stepping) EndIf Now we determine the number of sectors/track (MAX_SPT=18) Seek to track 0, Try reading sectors, starting with highest number (If no error, that was the right format) The combinations to try reading (in order) are: sector data rate (Kbps) Format description 18 500 HD, 1.44 MB drive (300 RPM) 15 500 HD, 1.2 MB drive, (360 RPM) 9 250/300 DD, 360KB drive/1.2 MB drive 8 250/300 DD, 360KB drive/1.2 MB drive Note that the 8 and 9 sector formats require a data rate of 250 Kbps for a 360KB drive (300 RPM) and 300 Kbps for a 1.2 MB drive (360 RPM). The driver therefore has to know which of these it is dealing with. (Are other formats desired? Maybe 10 or 16 sectors/track?) There are two ways to determine which type of drive we are dealing with. The easy way is to ask the BIOS at boot time. The harder (but more reliable) way is to measure the drive speed by timing index pulses from the drive (this requires a diskette in the drive). The drive speed never changes, so this test need only be done once. I believe it would be relatively easy to add a media sensitive (minor) device to the minix floppy driver using the above sensing methods. Also, we would still need minor devices that force a particular format for use when the media sensitive device gets it wrong, or (eventually) for use with a diskette formatting program. Sys V/386 uses exactly this scheme, where normal read/write activity can safely use the media sensitive device (/dev/dsk/f0) and formatting or other special programs use /dev/dsk/f0{format}{t?} where: f0 means drive 0 {format} specifies a format {t} if present means use whole disk, including cyl. 0 without the 't' the device starts on cylinder one. Standard tar floppies used by Sys.V/386 are read in using /dev/dsk/f0 (the device that starts on cylinder one). As far as I can tell, there are no special parameter tables on the floppies used by SysV/386, so I presume it does media sensing as described above. Media sensing works on both /dev/dsk/f0 and /dev/dsk/f0t (the "whole disk" device). Mountable file systems use the /dev/dsk/f0 (starts on cylinder one) device. Anybody for file system compatibility? -- Gordon W. Ross (E025) ARPA: gwr@linus.mitre.org The MITRE Corporation UUCP: {decvax,philabs}!linus!gwr Burlington Road, Bedford, MA 01730 (617) 271-3205