Quote:
void ata_partProbe(void)
{
struct partition part_entry;
unsigned char buffer[512], drive, part;
unsigned char lheads, heads, sects, Temp3;
unsigned int Temp, track, Temp2;
unsigned short offset, cyls;
unsigned char* cp;
unsigned int i;
unsigned char str[255];
unsigned int d_cyl, d_head, d_sec;
printk("IDE Disk Partition probe: ( )) <--- \n");
for(drive=0; drive < MAX_INTERFACES; drive++)
{
if (ide_interfaces[drive].detect == 0) continue;
if (ide_interfaces[drive].flags & ATA_FLG_ATAPI) continue;
/* load sector 0 (the partition table) - 1 block, 1 count - 512 Bytes */
Temp = ata_read(drive, 1, 1, Buffer);
if (Temp < 0) continue;
if (buffer[0x1FE] != 0x55 || buffer[0x1FF] != 0xAA)
{
error("Invalid parition table on IDE Hard Disk device %d! Recommend you format it",drive);
continue;
}
lheads = ide_interfaces[drive].max_head;
for (part=0; part < MAX_INTERFACES; part++)
{
offset = 0x1BE + 16 * part;
Temp=*(unsigned int *)(Buffer + Offset + 8);
if (Temp == 0) continue;
sects = Temp % ide_interfaces[drive].max_sec + 1;
track = Temp / ide_interfaces[drive].max_sec;
heads = track % lheads;
cyls = track / lheads;
Temp2=*(unsigned int *)(buffer + offset + 12);
Temp3=*(unsigned char *)(buffer + offset + 4);
switch (Temp3)
{
case 0x01: sprintf(str,"FAT12"); break;
case 0x04: sprintf(str,"FAT16"); break;
case 0x05: sprintf(str,"Extended"); break;
case 0x06: sprintf(str,"FAT16 >32MB"); break;
case 0x07: sprintf(str,"HPFS"); break;
case 0x0B: sprintf(str,"FAT32"); break;
case 0x0C: sprintf(str,"FAT32"); break;
case 0x0E: sprintf(str,"FAT16"); break;
}
printk("HDD%d%c: start LBA=%d, start CHS=%d:%d:%d, Size: %dMB %s", drive, 'a' + part, Temp, Cyls, Heads, Sects, Temp2 * 512/1024/1024, str);
drive_para [drive * 4 + 4 + part].start_block = Temp;
sprintf(str,"HDD%d%c",drive,'a' + part);
}
}
}
I condensed some of that code so that it's not too ugly(removed some comments). The code above basically checks all the IDE hard disks and asks them for their first sector(boot block) for the FS IDs. When making your boot block, be sure to include the FAT identifier table. I'll show you people the CTOS boot block as an attachment :)