]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libdisk/change.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.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         if (disk->bios_cyl >= 65536)
38                 sane = 0;
39 #ifdef PC98
40         if (disk->bios_hd >= 256)
41                 sane = 0;
42         if (disk->bios_sect >= 256)
43                 sane = 0;
44 #else
45         if (disk->bios_hd > 256)
46                 sane = 0;
47         if (disk->bios_sect > 63)
48                 sane = 0;
49 #endif
50 #if 0   /* Disable a check on a disk size.  It's too strict. */
51         if (disk->bios_cyl * disk->bios_hd * disk->bios_sect !=
52             disk->chunks->size)
53                 sane = 0;
54 #endif
55         if (sane)
56                 return;
57
58         /* First try something that IDE can handle */
59         disk->bios_sect = 63;
60         disk->bios_hd = 16;
61         disk->bios_cyl = disk->chunks->size /
62                 (disk->bios_sect * disk->bios_hd);
63
64 #ifdef PC98
65         if (disk->bios_cyl < 65536)
66 #else
67         if (disk->bios_cyl < 1024)
68 #endif
69                 return;
70
71         /* Hmm, try harder... */
72         /* Assume standard SCSI parameter */
73 #ifdef PC98
74         disk->bios_sect = 128;
75         disk->bios_hd = 8;
76 #else
77         disk->bios_hd = 255;
78 #endif
79         disk->bios_cyl = disk->chunks->size /
80                 (disk->bios_sect * disk->bios_hd);
81
82 #ifdef PC98
83         if (disk->bios_cyl < 65536)
84                 return;
85
86         /* Assume UIDE-133/98-A Challenger BIOS 0.9821C parameter */
87         disk->bios_sect = 255;
88         disk->bios_hd = 16;
89         disk->bios_cyl = disk->chunks->size /
90                 (disk->bios_sect * disk->bios_hd);
91
92         if (disk->bios_cyl < 65536)
93                 return;
94
95         /* BIG-na-Drive? */
96         disk->bios_hd = 255;
97         disk->bios_cyl = disk->chunks->size /
98                 (disk->bios_sect * disk->bios_hd);
99 #endif
100 }
101
102 void
103 All_FreeBSD(struct disk *d, int force_all)
104 {
105         struct chunk *c;
106         int type;
107
108 #ifdef PC98
109         type = 0xc494;
110 #else
111         type = 0xa5;
112 #endif
113
114 again:
115         for (c = d->chunks->part; c; c = c->next)
116                 if (c->type != unused) {
117                         Delete_Chunk(d, c);
118                         goto again;
119                 }
120         c = d->chunks;
121         if (force_all) {
122                 Sanitize_Bios_Geom(d);
123                 Create_Chunk(d, c->offset, c->size, freebsd, type,
124                     CHUNK_FORCE_ALL, "FreeBSD");
125         } else {
126                 Create_Chunk(d, c->offset, c->size, freebsd, type, 0,
127                     "FreeBSD");
128         }
129 }