Hi!
After some discussion with Eric, we decise that fixing non-filled
geometry should be in that way:
______________O\_/_________________________________\_/O______________
/* Linux dosfstools 'mkdosfs' treats all filesystems like images, so it does
not fill in the physical geometry. To make the disk bootable, we have to
fill in trackSectors, heads and hiddenSectors ourselves. We take the
values from the default BPB provided by the kernel. Eric Auer.
*/
void fix_bpb (UBYTE drive, UWORD code, BPB *pb)
{
static struct {
UBYTE func;
UBYTE reserved1 [6];
BPB bpb;
UBYTE reserved2 [0x5C - sizeof (BPB) - 7];
} IOCTL_data;
/* bit 0 set if function to use current BPB, clear if Device
BIOS Parameter Block field contains new default BPB
bit 1 set if function to use track layout fields only
must be clear if CL=60h
bit 2 set if all sectors in track same size (should be set) (RBIL)
*/
IOCTL_data.func = 4;
if (generic_block_ioctl (drive, code, &IOCTL_data))
return;
if (pb->hiddenSectors != IOCTL_data.bpb.hiddenSectors &&
pb->trackSectors != IOCTL_data.bpb.trackSectors &&
pb->heads != IOCTL_data.bpb.heads) {
/* if geometry was filled, but different with default, then this
may mean erroroneous data, which should be fixed
*/
if (pb->trackSectors && pb->heads) {
printf (PGM ": error: geometry (hidden,sectors/track,heads) is different
between\n"
" boot sector (%lu,%u,%u) and OS (%lu,%u,%u)\n",
pb->hiddenSectors, pb->trackSectors, pb->heads,
IOCTL_data.bpb.hiddenSectors,
IOCTL_data.bpb.trackSectors,
IOCTL_data.bpb.heads);
exit (1); return; /* remain fixing for CHKDSK */
}
pb->hiddenSectors = IOCTL_data.bpb.hiddenSectors;
pb->trackSectors = IOCTL_data.bpb.trackSectors;
pb->heads = IOCTL_data.bpb.heads;
}
}
void put_boot (UBYTE drive, int both)
{
bootsector_t curboot, *newboot;
[...]
if (fs == FAT32) {
[...]
} else {
/* get the FAT12/16 CHS+LBA boot sector */
newboot = (bootsector_t*)(fs == FAT16 ? boot16 : boot12);
code = 0x860;
sz = BPBSIZE;
}
fix_bpb (drive, code, &curboot._.bs.bpb);
/* Copy disk parameter from current sector to new sector */
memcpy (&newboot->_.bs.bpb, &curboot._.bs.bpb, sz);
_____________________________________________________________________
O/~\ /~\O
Is there comments, additions?
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Freedos-kernel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freedos-kernel