Message-ID: <000b01bf7136$1bbe6b20$94702ecb@sphinx> From: "Johan Venter" To: "Duane Atly" Cc: References: <7c6p8sccsimi62b7el2pfkid1qd4dfvnrf AT 4ax DOT com> <3890db83_6 AT goliath DOT newsfeeds DOT com> Subject: Re: Be passing Windows HDD driver (WAS Re: Boot sectors and partition tables) Date: Sat, 5 Feb 2000 22:02:26 +1000 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Reply-To: djgpp AT delorie DOT com > Is there a "good clean" way of going around Windows to look at the partition > table (or even issue Drive Cmds?) > > Just wondering. Here's some code I wrote to read the partition table (a quick hack, so forgive any minor errors, it works ok though). Note: this code also saves the mbr into mbr.bin, and the partition table to pt.bin: /* reads partition table on first hard disk and prints info */ #include #include struct partitionEntry { unsigned char mediaByte __attribute__ ((packed)); unsigned char startHead __attribute__ ((packed)); unsigned short startCylSec __attribute__ ((packed)); unsigned char partitionType __attribute__ ((packed)); unsigned char endHead __attribute__ ((packed)); unsigned short endCylSec __attribute__ ((packed)); unsigned int sectorsToPartition __attribute__ ((packed)); unsigned int partitionSectors __attribute__ ((packed)); }; struct partitionTable { struct partitionEntry partitions[4] __attribute__ ((packed)); } primaryPartitions; unsigned char MasterBootRecord[512]; int readMBR(unsigned char *MBR); struct partitionTable extractPartitionTable(unsigned char *MBR); int main(void) { int c; if (readMBR(MasterBootRecord)) { printf("error reading MBR.\n"); exit(0); } primaryPartitions = extractPartitionTable(MasterBootRecord); printf("Partition Table/MBR reading example\n"); printf("by Johan Venter (jventer AT writeme DOT com)\n\n"); printf("number\t\ttype\t\tsize\t\tactive?\n"); printf("======\t\t====\t\t====\t\t=======\n"); for (c = 0; c < 4; c++) { printf("%d\t\t%d\t\t%d\t\t%s\n", c + 1, primaryPartitions.partitions[c].partitionType, primaryPartitions.partitions[c].partitionSectors*512/1024/1024, primaryPartitions.partitions[c].mediaByte != 0 ? "Yes" : "No"); } return 0; } int readMBR(unsigned char *MBR) { FILE *f = fopen("mbr.bin", "wb"); if (biosdisk(2, 0x80, 0, 0, 1, 1, MBR)) return 1; else { fwrite(MBR, 512, 1, f); fclose(f); return 0; } } struct partitionTable extractPartitionTable(unsigned char *MBR) { FILE *f = fopen("pt.bin", "wb"); struct partitionTable temp; memcpy(&temp, MBR + 0x1be, sizeof(struct partitionTable)); fwrite(&temp, sizeof(struct partitionTable), 1, f); fclose(f); return temp; } Hope this helps. This won't work from Windows NT obviously, so I suggest you make a Windows 95 or plain DOS bootdisk from someone elses machine. Johan Venter ICQ 3643877 jventer AT writeme DOT com Binaries Servers ==-----