1995-04-28 19:57:04 -04:00
|
|
|
/*
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
2002-03-25 08:52:45 -05:00
|
|
|
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
|
1995-04-28 19:57:04 -04:00
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2001-09-30 17:16:57 -04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
1995-04-28 19:57:04 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include "libdisk.h"
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
|
|
|
|
|
{
|
2002-11-15 08:24:29 -05:00
|
|
|
|
1995-04-28 19:57:04 -04:00
|
|
|
disk->bios_cyl = cyl;
|
|
|
|
|
disk->bios_hd = hd;
|
|
|
|
|
disk->bios_sect = sect;
|
|
|
|
|
}
|
1995-04-29 00:00:57 -04:00
|
|
|
|
1996-11-27 17:44:43 -05:00
|
|
|
void
|
|
|
|
|
Sanitize_Bios_Geom(struct disk *disk)
|
|
|
|
|
{
|
2001-04-01 08:18:20 -04:00
|
|
|
int sane;
|
|
|
|
|
|
|
|
|
|
sane = 1;
|
1996-11-27 17:44:43 -05:00
|
|
|
|
2002-10-14 09:15:14 -04:00
|
|
|
if (disk->bios_cyl >= 65536)
|
1996-11-27 17:44:43 -05:00
|
|
|
sane = 0;
|
2002-10-14 09:15:14 -04:00
|
|
|
#ifdef PC98
|
2009-09-18 23:33:18 -04:00
|
|
|
if (disk->bios_hd >= 256)
|
|
|
|
|
sane = 0;
|
2002-10-14 09:15:14 -04:00
|
|
|
if (disk->bios_sect >= 256)
|
2009-09-18 23:33:18 -04:00
|
|
|
sane = 0;
|
2002-10-14 09:15:14 -04:00
|
|
|
#else
|
2009-09-18 23:33:18 -04:00
|
|
|
if (disk->bios_hd > 256)
|
|
|
|
|
sane = 0;
|
1996-11-27 17:44:43 -05:00
|
|
|
if (disk->bios_sect > 63)
|
|
|
|
|
sane = 0;
|
2009-09-18 23:33:18 -04:00
|
|
|
#endif
|
2009-09-21 00:04:02 -04:00
|
|
|
#if 0 /* Disable a check on a disk size. It's too strict. */
|
2002-11-15 08:24:29 -05:00
|
|
|
if (disk->bios_cyl * disk->bios_hd * disk->bios_sect !=
|
|
|
|
|
disk->chunks->size)
|
1996-11-27 17:44:43 -05:00
|
|
|
sane = 0;
|
2009-09-21 00:04:02 -04:00
|
|
|
#endif
|
1996-11-27 17:44:43 -05:00
|
|
|
if (sane)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* First try something that IDE can handle */
|
|
|
|
|
disk->bios_sect = 63;
|
|
|
|
|
disk->bios_hd = 16;
|
2002-11-15 08:24:29 -05:00
|
|
|
disk->bios_cyl = disk->chunks->size /
|
|
|
|
|
(disk->bios_sect * disk->bios_hd);
|
1996-11-27 17:44:43 -05:00
|
|
|
|
2002-10-14 09:15:14 -04:00
|
|
|
#ifdef PC98
|
|
|
|
|
if (disk->bios_cyl < 65536)
|
|
|
|
|
#else
|
1996-11-27 17:44:43 -05:00
|
|
|
if (disk->bios_cyl < 1024)
|
2002-10-14 09:15:14 -04:00
|
|
|
#endif
|
1996-11-27 17:44:43 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Hmm, try harder... */
|
2002-10-14 09:15:14 -04:00
|
|
|
/* Assume standard SCSI parameter */
|
2005-03-30 08:03:33 -05:00
|
|
|
#ifdef PC98
|
2002-10-14 09:15:14 -04:00
|
|
|
disk->bios_sect = 128;
|
|
|
|
|
disk->bios_hd = 8;
|
|
|
|
|
#else
|
1996-11-27 17:44:43 -05:00
|
|
|
disk->bios_hd = 255;
|
2002-10-14 09:15:14 -04:00
|
|
|
#endif
|
2002-11-15 08:24:29 -05:00
|
|
|
disk->bios_cyl = disk->chunks->size /
|
|
|
|
|
(disk->bios_sect * disk->bios_hd);
|
2005-03-30 08:03:33 -05:00
|
|
|
|
|
|
|
|
#ifdef PC98
|
|
|
|
|
if (disk->bios_cyl < 65536)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Assume UIDE-133/98-A Challenger BIOS 0.9821C parameter */
|
|
|
|
|
disk->bios_sect = 255;
|
|
|
|
|
disk->bios_hd = 16;
|
|
|
|
|
disk->bios_cyl = disk->chunks->size /
|
|
|
|
|
(disk->bios_sect * disk->bios_hd);
|
|
|
|
|
|
|
|
|
|
if (disk->bios_cyl < 65536)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* BIG-na-Drive? */
|
|
|
|
|
disk->bios_hd = 255;
|
|
|
|
|
disk->bios_cyl = disk->chunks->size /
|
|
|
|
|
(disk->bios_sect * disk->bios_hd);
|
|
|
|
|
#endif
|
1996-11-27 17:44:43 -05:00
|
|
|
}
|
|
|
|
|
|
1995-04-29 00:00:57 -04:00
|
|
|
void
|
1995-12-07 05:34:59 -05:00
|
|
|
All_FreeBSD(struct disk *d, int force_all)
|
1995-04-29 00:00:57 -04:00
|
|
|
{
|
|
|
|
|
struct chunk *c;
|
2002-10-22 07:55:27 -04:00
|
|
|
int type;
|
|
|
|
|
|
|
|
|
|
#ifdef PC98
|
2004-01-27 10:25:33 -05:00
|
|
|
type = 0xc494;
|
2002-10-22 07:55:27 -04:00
|
|
|
#else
|
|
|
|
|
type = 0xa5;
|
|
|
|
|
#endif
|
1995-04-29 00:00:57 -04:00
|
|
|
|
2002-11-15 08:24:29 -05:00
|
|
|
again:
|
2001-04-01 08:18:20 -04:00
|
|
|
for (c = d->chunks->part; c; c = c->next)
|
1995-04-29 00:00:57 -04:00
|
|
|
if (c->type != unused) {
|
2001-04-01 08:18:20 -04:00
|
|
|
Delete_Chunk(d, c);
|
1995-04-29 00:00:57 -04:00
|
|
|
goto again;
|
|
|
|
|
}
|
2001-04-01 08:18:20 -04:00
|
|
|
c = d->chunks;
|
1996-11-27 17:44:43 -05:00
|
|
|
if (force_all) {
|
|
|
|
|
Sanitize_Bios_Geom(d);
|
2002-10-22 07:55:27 -04:00
|
|
|
Create_Chunk(d, c->offset, c->size, freebsd, type,
|
2001-04-01 08:18:20 -04:00
|
|
|
CHUNK_FORCE_ALL, "FreeBSD");
|
1996-11-27 17:44:43 -05:00
|
|
|
} else {
|
2002-10-22 07:55:27 -04:00
|
|
|
Create_Chunk(d, c->offset, c->size, freebsd, type, 0,
|
2001-04-01 08:18:20 -04:00
|
|
|
"FreeBSD");
|
1996-11-27 17:44:43 -05:00
|
|
|
}
|
1995-04-29 00:00:57 -04:00
|
|
|
}
|