]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libdisk/change.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / lib / libdisk / change.c
1 /*
2  * ----------------------------------------------------------------------------
3  * "THE BEER-WARE LICENSE" (Revision 42):
4  * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
5  * can do whatever you want with this stuff. If we meet some day, and you think
6  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7  * ----------------------------------------------------------------------------
8  */
9
10 #include <sys/cdefs.h>
11 __FBSDID("$FreeBSD$");
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #include <string.h>
18 #include <sys/types.h>
19 #include "libdisk.h"
20
21 void
22 Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
23 {
24
25         disk->bios_cyl = cyl;
26         disk->bios_hd = hd;
27         disk->bios_sect = sect;
28 }
29
30 void
31 Sanitize_Bios_Geom(struct disk *disk)
32 {
33         int sane;
34
35         sane = 1;
36
37 #ifdef PC98
38         if (disk->bios_cyl >= 65536)
39 #else
40         if (disk->bios_cyl > 1024)
41 #endif
42                 sane = 0;
43 #ifdef PC98
44         if (disk->bios_hd >= 256)
45 #else
46         if (disk->bios_hd > 16)
47 #endif
48                 sane = 0;
49 #ifdef PC98
50         if (disk->bios_sect >= 256)
51 #else
52         if (disk->bios_sect > 63)
53 #endif
54                 sane = 0;
55         if (disk->bios_cyl * disk->bios_hd * disk->bios_sect !=
56             disk->chunks->size)
57                 sane = 0;
58         if (sane)
59                 return;
60
61         /* First try something that IDE can handle */
62         disk->bios_sect = 63;
63         disk->bios_hd = 16;
64         disk->bios_cyl = disk->chunks->size /
65                 (disk->bios_sect * disk->bios_hd);
66
67 #ifdef PC98
68         if (disk->bios_cyl < 65536)
69 #else
70         if (disk->bios_cyl < 1024)
71 #endif
72                 return;
73
74         /* Hmm, try harder... */
75         /* Assume standard SCSI parameter */
76 #ifdef PC98
77         disk->bios_sect = 128;
78         disk->bios_hd = 8;
79 #else
80         disk->bios_hd = 255;
81 #endif
82         disk->bios_cyl = disk->chunks->size /
83                 (disk->bios_sect * disk->bios_hd);
84
85 #ifdef PC98
86         if (disk->bios_cyl < 65536)
87                 return;
88
89         /* Assume UIDE-133/98-A Challenger BIOS 0.9821C parameter */
90         disk->bios_sect = 255;
91         disk->bios_hd = 16;
92         disk->bios_cyl = disk->chunks->size /
93                 (disk->bios_sect * disk->bios_hd);
94
95         if (disk->bios_cyl < 65536)
96                 return;
97
98         /* BIG-na-Drive? */
99         disk->bios_hd = 255;
100         disk->bios_cyl = disk->chunks->size /
101                 (disk->bios_sect * disk->bios_hd);
102 #endif
103 }
104
105 void
106 All_FreeBSD(struct disk *d, int force_all)
107 {
108         struct chunk *c;
109         int type;
110
111 #ifdef PC98
112         type = 0xc494;
113 #else
114         type = 0xa5;
115 #endif
116
117 again:
118         for (c = d->chunks->part; c; c = c->next)
119                 if (c->type != unused) {
120                         Delete_Chunk(d, c);
121                         goto again;
122                 }
123         c = d->chunks;
124         if (force_all) {
125                 Sanitize_Bios_Geom(d);
126                 Create_Chunk(d, c->offset, c->size, freebsd, type,
127                     CHUNK_FORCE_ALL, "FreeBSD");
128         } else {
129                 Create_Chunk(d, c->offset, c->size, freebsd, type, 0,
130                     "FreeBSD");
131         }
132 }