/*---------------------------------------------------------------------------- 40-line Turbo C program to display root directory of a FAT12 floppy disk without using DOS. Chris Giese http://SisAndHappy.com/ChrisGiese/ This code is public domain (no copyright). You can do whatever you want with it. ----------------------------------------------------------------------------*/ #include #include #define read_le16(X) *(unsigned short *)(X) static unsigned g_drive_num = 0, g_heads = 1, g_sectors = 1; static int read_sector(void *buf, unsigned lba) { unsigned sector, head; sector = (lba % g_sectors) + 1; lba /= g_sectors; head = lba % g_heads; lba /= g_heads; return biosdisk(/*_DISK_READ=*/2, g_drive_num, head, /*cylinder=*/lba, sector, /* num_sects=*/1, buf); } int main(void) { unsigned first_root_sector, num_root_sectors, s; unsigned char buf[512], *e; /* should test for error here; and validate boot sector */ (void)read_sector(buf, 0); g_heads = read_le16(&buf[26]); /* number of heads */ g_sectors = read_le16(&buf[24]); /* sectors per track */ first_root_sector = read_le16(&buf[14]) + /* start of FATs */ buf[16] * /* number of FATs */ read_le16(&buf[22]); /* sectors per FAT */ num_root_sectors = read_le16(&buf[17]) * 32 / /* bytes per directory entry */ 512; /* bytes per sector */ for(s = 0; s < num_root_sectors; s++) { (void)read_sector(buf, first_root_sector + s); for(e = buf; e < &buf[512]; e = &e[32]) { if(e[0] == '\0' /* unused directory entry */ || e[0] == 0xE5 /* deleted entry */ || (e[11] & 0x08)) /* volume label or LFN */ continue; printf("%-11.11s ", e); }} printf("\n"); return 0; }