]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libdisk/change.c
This commit was generated by cvs2svn to compensate for changes in r101615,
[FreeBSD/FreeBSD.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         disk->bios_cyl = cyl;
25         disk->bios_hd = hd;
26         disk->bios_sect = sect;
27 }
28
29 /* XXX - parameters should change to fit for PC-98, but I'm not sure */
30 void
31 Sanitize_Bios_Geom(struct disk *disk)
32 {
33         int sane;
34
35         sane = 1;
36
37         if (disk->bios_cyl > 1024)
38                 sane = 0;
39         if (disk->bios_hd > 16)
40                 sane = 0;
41         if (disk->bios_sect > 63)
42                 sane = 0;
43         if (disk->bios_cyl*disk->bios_hd*disk->bios_sect != disk->chunks->size)
44                 sane = 0;
45         if (sane)
46                 return;
47
48         /* First try something that IDE can handle */
49         disk->bios_sect = 63;
50         disk->bios_hd = 16;
51         disk->bios_cyl = disk->chunks->size / (disk->bios_sect*disk->bios_hd);
52
53         if (disk->bios_cyl < 1024)
54                 return;
55
56         /* Hmm, try harder... */
57         disk->bios_hd = 255;
58         disk->bios_cyl = disk->chunks->size / (disk->bios_sect*disk->bios_hd);
59
60         return;
61 }
62
63 void
64 All_FreeBSD(struct disk *d, int force_all)
65 {
66         struct chunk *c;
67
68     again:
69         for (c = d->chunks->part; c; c = c->next)
70                 if (c->type != unused) {
71                         Delete_Chunk(d, c);
72                         goto again;
73                 }
74         c = d->chunks;
75         if (force_all) {
76                 Sanitize_Bios_Geom(d);
77 #ifdef PC98
78                 Create_Chunk(d, c->offset, c->size, freebsd, 0x494,
79                     CHUNK_FORCE_ALL, "FreeBSD");
80 #else
81                 Create_Chunk(d, c->offset, c->size, freebsd, 0xa5,
82                     CHUNK_FORCE_ALL);
83 #endif
84         } else {
85 #ifdef PC98
86                 Create_Chunk(d, c->offset, c->size, freebsd, 0x494, 0,
87                     "FreeBSD");
88 #else
89                 Create_Chunk(d, c->offset, c->size, freebsd, 0xa5, 0);
90 #endif
91         }
92 }