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