]>
git.cameronkatri.com Git - apple_cmds.git/blob - diskdev_cmds/fdisk.tproj/auto.c
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Auto partitioning code.
38 int AUTO_boothfs
__P((disk_t
*, mbr_t
*));
39 int AUTO_hfs
__P((disk_t
*, mbr_t
*));
40 int AUTO_dos
__P((disk_t
*, mbr_t
*));
41 int AUTO_raid
__P((disk_t
*, mbr_t
*));
43 /* The default style is the first one in the list */
46 int (*style_fn
)(disk_t
*, mbr_t
*);
49 {"boothfs", AUTO_boothfs
, "8Mb boot plus HFS+ root partition"},
50 {"hfs", AUTO_hfs
, "Entire disk as one HFS+ partition"},
51 {"dos", AUTO_dos
, "Entire disk as one DOS partition"},
52 {"raid", AUTO_raid
, "Entire disk as one 0xAC partition"},
57 AUTO_print_styles(FILE *f
)
59 struct _auto_style
*fp
;
62 for (i
=0, fp
= &style_fns
[0]; fp
->style_name
!= NULL
; i
++, fp
++) {
63 fprintf(f
, " %-10s %s%s\n", fp
->style_name
, fp
->description
, (i
==0) ? " (default)" : "");
69 AUTO_init(disk_t
*disk
, char *style
, mbr_t
*mbr
)
71 struct _auto_style
*fp
;
73 for (fp
= &style_fns
[0]; fp
->style_name
!= NULL
; fp
++) {
74 /* If style is NULL, use the first (default) style */
75 if (style
== NULL
|| strcasecmp(style
, fp
->style_name
) == 0) {
76 return (*fp
->style_fn
)(disk
, mbr
);
79 warnx("No such auto-partition style %s", style
);
85 use_whole_disk(disk_t
*disk
, unsigned char id
, mbr_t
*mbr
)
90 mbr
->part
[0].ns
= disk
->real
->size
- 63;
91 PRT_fix_CHS(disk
, &mbr
->part
[0], 0);
95 /* DOS style: one partition for the whole disk */
97 AUTO_dos(disk_t
*disk
, mbr_t
*mbr
)
100 cc
= use_whole_disk(disk
, 0x0C, mbr
);
102 mbr
->part
[0].flag
= DOSACTIVE
;
107 /* HFS style: one partition for the whole disk */
109 AUTO_hfs(disk_t
*disk
, mbr_t
*mbr
)
112 cc
= use_whole_disk(disk
, 0xAF, mbr
);
114 mbr
->part
[0].flag
= DOSACTIVE
;
119 /* One boot partition, one HFS+ root partition */
121 AUTO_boothfs (disk_t
*disk
, mbr_t
*mbr
)
123 /* Check disk size. */
124 if (disk
->real
->size
< 16 * 2048) {
125 errx(1, "Disk size must be greater than 16Mb");
131 /* 8MB boot partition */
132 mbr
->part
[0].id
= 0xAB;
133 mbr
->part
[0].bs
= 63;
134 mbr
->part
[0].ns
= 8 * 1024 * 2;
135 mbr
->part
[0].flag
= DOSACTIVE
;
136 PRT_fix_CHS(disk
, &mbr
->part
[0], 0);
138 /* Rest of the disk for rooting */
139 mbr
->part
[1].id
= 0xAF;
140 mbr
->part
[1].bs
= (mbr
->part
[0].bs
+ mbr
->part
[0].ns
);
141 mbr
->part
[1].ns
= disk
->real
->size
- mbr
->part
[0].ns
- 63;
142 PRT_fix_CHS(disk
, &mbr
->part
[1], 1);
149 /* RAID style: one 0xAC partition for the whole disk */
151 AUTO_raid(disk_t
*disk
, mbr_t
*mbr
)
153 return use_whole_disk(disk
, 0xAC, mbr
);