summaryrefslogtreecommitdiffstats
path: root/lib/libdisk/change.c
blob: 12812bda47ef7f938a038921dd9f10c26bddb72c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
 * 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
 * ----------------------------------------------------------------------------
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#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)
{

	disk->bios_cyl = cyl;
	disk->bios_hd = hd;
	disk->bios_sect = sect;
}

void
Sanitize_Bios_Geom(struct disk *disk)
{
	int sane;

	sane = 1;

#ifdef PC98
	if (disk->bios_cyl >= 65536)
#else
	if (disk->bios_cyl > 1024)
#endif
		sane = 0;
	if (disk->bios_hd > 16)
		sane = 0;
#ifdef PC98
	if (disk->bios_sect >= 256)
#else
	if (disk->bios_sect > 63)
#endif
		sane = 0;
	if (disk->bios_cyl * disk->bios_hd * disk->bios_sect !=
	    disk->chunks->size)
		sane = 0;
	if (sane)
		return;

	/* First try something that IDE can handle */
	disk->bios_sect = 63;
	disk->bios_hd = 16;
	disk->bios_cyl = disk->chunks->size /
		(disk->bios_sect * disk->bios_hd);

#ifdef PC98
	if (disk->bios_cyl < 65536)
#else
	if (disk->bios_cyl < 1024)
#endif
		return;

	/* Hmm, try harder... */
#ifdef PC98
	/* Assume standard SCSI parameter */
	disk->bios_sect = 128;
	disk->bios_hd = 8;
#else
	disk->bios_hd = 255;
#endif
	disk->bios_cyl = disk->chunks->size /
		(disk->bios_sect * disk->bios_hd);
}

void
All_FreeBSD(struct disk *d, int force_all)
{
	struct chunk *c;
	int type;

#ifdef PC98
	type = 0xc494;
#else
	type = 0xa5;
#endif

again:
	for (c = d->chunks->part; c; c = c->next)
		if (c->type != unused) {
			Delete_Chunk(d, c);
			goto again;
		}
	c = d->chunks;
	if (force_all) {
		Sanitize_Bios_Geom(d);
		Create_Chunk(d, c->offset, c->size, freebsd, type,
		    CHUNK_FORCE_ALL, "FreeBSD");
	} else {
		Create_Chunk(d, c->offset, c->size, freebsd, type, 0,
		    "FreeBSD");
	}
}
OpenPOWER on IntegriCloud