Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!sdcsvax!ucsdhub!jack!man!crash!pnet01!kb5mu From: kb5mu@pnet01.CTS.COM (Paul Williamson) Newsgroups: comp.sys.ibm.pc Subject: fix to DU Message-ID: <1115@crash.CTS.COM> Date: Sun, 17-May-87 23:37:17 EDT Article-I.D.: crash.1115 Posted: Sun May 17 23:37:17 1987 Date-Received: Mon, 18-May-87 04:05:25 EDT Sender: news@crash.CTS.COM Organization: People-Net [pnet01], El Cajon, CA Lines: 45 In the program DU by Tom Vijlbrief, recently distributed on the net, the function comp_cluster tries to read the partition boot record to get the number of sectors in a cluster. Unfortunately, the method it uses to find the boot record is incorrect. It simply searches the first cylinder for a sector that looks like a boot sector, in that it starts with the byte 0xEB. This is not sufficient in the case of a hard disk. On mine, it finds an old boot sector left over from a previous formatting with DOS 2.0, instead of the current DOS 3.1 boot sector. If you're going to look for the boot sector, the Master Boot Record of the hard disk must be consulted to find out which sector contains the boot record for the currect partition. There is an easier and better way. DOS function 1Ch returns the needed information, plus the sector size so 512 needn't be hard-coded into the program. The following is a replacement for the function comp_cluster() in the program du.c. In addition, the routines readsect() and max_head() and the associated #defines (BLOCK_SIZE, DISK, READ_SECT, RESET_DISK, FLOP_RETRIES, GET_PARAM) can be deleted, along with the declaration for sector[BLOCK_SIZE]. This modification may be distributed freely. int comp_cluster(drive_nr) int drive_nr; { int nr_sectors; int block_size; union REGS regs; struct SREGS sregs; segread(&sregs); /* set up input segment registers */ regs.h.ah = 0x1C; /* Get allocation info for drive */ regs.h.dl = drive_nr + 1; /* zero is used for default here */ intdosx(®s, ®s, &sregs); /* get info */ /* intdosx is needed to restore DS after the call. */ nr_sectors = regs.h.al; /* this is what we wanted */ block_size = regs.x.cx; return(nr_sectors * block_size); } Paul Williamson ... !sdcsvax!macomw!williams or ... !sdcsvax!crash!pnet01!kb5mu