Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/fdisk/auto.c

Source at commit 1406 created 12 years 10 months ago.
By meklort, Revert drivers.c so that kexts are only loaded when OSBundleRequired is set and that value is not safe mode. Added some comments about it too.
1/*
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*
25 * Auto partitioning code.
26 */
27
28#include <stdio.h>
29#include <ctype.h>
30#include <stdlib.h>
31#include <unistd.h>
32#include <string.h>
33#include <err.h>
34#include "disk.h"
35#include "mbr.h"
36#include "auto.h"
37
38int AUTO_boothfs __P((disk_t *, mbr_t *));
39int AUTO_bootufs __P((disk_t *, mbr_t *));
40int AUTO_hfs __P((disk_t *, mbr_t *));
41int AUTO_ufs __P((disk_t *, mbr_t *));
42int AUTO_dos __P((disk_t *, mbr_t *));
43int AUTO_raid __P((disk_t *, mbr_t *));
44
45/* The default style is the first one in the list */
46struct _auto_style {
47 char *style_name;
48 int (*style_fn)(disk_t *, mbr_t *);
49 char *description;
50} style_fns[] = {
51 {"boothfs", AUTO_boothfs, "8Mb boot plus HFS+ root partition"},
52 {"bootufs", AUTO_bootufs, "8Mb boot plus UFS root partition"},
53 {"hfs", AUTO_hfs, "Entire disk as one HFS+ partition"},
54 {"ufs", AUTO_ufs, "Entire disk as one UFS partition"},
55 {"dos", AUTO_dos, "Entire disk as one DOS partition"},
56 {"raid", AUTO_raid, "Entire disk as one 0xAC partition"},
57 {0,0}
58};
59
60void
61AUTO_print_styles(FILE *f)
62{
63 struct _auto_style *fp;
64 int i;
65
66 for (i=0, fp = &style_fns[0]; fp->style_name != NULL; i++, fp++) {
67 fprintf(f, " %-10s %s%s\n", fp->style_name, fp->description, (i==0) ? " (default)" : "");
68 }
69}
70
71
72int
73AUTO_init(disk_t *disk, char *style, mbr_t *mbr)
74{
75 struct _auto_style *fp;
76
77 for (fp = &style_fns[0]; fp->style_name != NULL; fp++) {
78 /* If style is NULL, use the first (default) style */
79 if (style == NULL || strcasecmp(style, fp->style_name) == 0) {
80 return (*fp->style_fn)(disk, mbr);
81 }
82 }
83 warnx("No such auto-partition style %s", style);
84 return AUTO_ERR;
85}
86
87
88static int
89use_whole_disk(disk_t *disk, unsigned char id, mbr_t *mbr)
90{
91 MBR_clear(mbr);
92 mbr->part[0].id = id;
93 mbr->part[0].bs = 63;
94 mbr->part[0].ns = disk->real->size - 63;
95 PRT_fix_CHS(disk, &mbr->part[0], 0);
96 return AUTO_OK;
97}
98
99/* DOS style: one partition for the whole disk */
100int
101AUTO_dos(disk_t *disk, mbr_t *mbr)
102{
103 int cc;
104 cc = use_whole_disk(disk, 0x0C, mbr);
105 if (cc == AUTO_OK) {
106 mbr->part[0].flag = DOSACTIVE;
107 }
108 return cc;
109}
110
111/* HFS style: one partition for the whole disk */
112int
113AUTO_hfs(disk_t *disk, mbr_t *mbr)
114{
115 int cc;
116 cc = use_whole_disk(disk, 0xAF, mbr);
117 if (cc == AUTO_OK) {
118 mbr->part[0].flag = DOSACTIVE;
119 }
120 return cc;
121}
122
123/* UFS style: one partition for the whole disk */
124int
125AUTO_ufs(disk_t *disk, mbr_t *mbr)
126{
127 int cc;
128 cc = use_whole_disk(disk, 0xA8, mbr);
129 if (cc == AUTO_OK) {
130 mbr->part[0].flag = DOSACTIVE;
131 }
132 return cc;
133}
134
135/* One boot partition, one HFS+ root partition */
136int
137AUTO_boothfs (disk_t *disk, mbr_t *mbr)
138{
139 /* Check disk size. */
140 if (disk->real->size < 16 * 2048) {
141 errx(1, "Disk size must be greater than 16Mb");
142 return AUTO_ERR;
143 }
144
145 MBR_clear(mbr);
146
147 /* 8MB boot partition */
148 mbr->part[0].id = 0xAB;
149 mbr->part[0].bs = 63;
150 mbr->part[0].ns = 8 * 1024 * 2;
151 mbr->part[0].flag = DOSACTIVE;
152 PRT_fix_CHS(disk, &mbr->part[0], 0);
153
154 /* Rest of the disk for rooting */
155 mbr->part[1].id = 0xAF;
156 mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns);
157 mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63;
158 PRT_fix_CHS(disk, &mbr->part[1], 1);
159
160 return AUTO_OK;
161}
162
163/* One boot partition, one UFS root partition */
164int
165AUTO_bootufs(disk_t *disk, mbr_t *mbr)
166{
167 /* Check disk size. */
168 if (disk->real->size < 16 * 2048) {
169 errx(1, "Disk size must be greater than 16Mb");
170 return AUTO_ERR;
171 }
172
173 MBR_clear(mbr);
174
175 /* 8MB boot partition */
176 mbr->part[0].id = 0xAB;
177 mbr->part[0].bs = 63;
178 mbr->part[0].ns = 8 * 1024 * 2;
179 mbr->part[0].flag = DOSACTIVE;
180 PRT_fix_CHS(disk, &mbr->part[0], 0);
181
182 /* Rest of the disk for rooting */
183 mbr->part[1].id = 0xA8;
184 mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns);
185 mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63;
186 PRT_fix_CHS(disk, &mbr->part[1], 1);
187
188 return AUTO_OK;
189}
190
191/* RAID style: one 0xAC partition for the whole disk */
192int
193AUTO_raid(disk_t *disk, mbr_t *mbr)
194{
195 return use_whole_disk(disk, 0xAC, mbr);
196}
197
198

Archive Download this file

Revision: 1406