diff options
author | Cameron Katri <me@cameronkatri.com> | 2021-05-09 14:20:58 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2021-05-09 14:20:58 -0400 |
commit | 5fd83771641d15c418f747bd343ba6738d3875f7 (patch) | |
tree | 5abf0f78f680d9837dbd93d4d4c3933bb7509599 /diskdev_cmds/fdisk.tproj/auto.c | |
download | apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.gz apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.zst apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.zip |
Import macOS userland
adv_cmds-176
basic_cmds-55
bootstrap_cmds-116.100.1
developer_cmds-66
diskdev_cmds-667.40.1
doc_cmds-53.60.1
file_cmds-321.40.3
mail_cmds-35
misc_cmds-34
network_cmds-606.40.1
patch_cmds-17
remote_cmds-63
shell_cmds-216.60.1
system_cmds-880.60.2
text_cmds-106
Diffstat (limited to 'diskdev_cmds/fdisk.tproj/auto.c')
-rw-r--r-- | diskdev_cmds/fdisk.tproj/auto.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/diskdev_cmds/fdisk.tproj/auto.c b/diskdev_cmds/fdisk.tproj/auto.c new file mode 100644 index 0000000..155f7ab --- /dev/null +++ b/diskdev_cmds/fdisk.tproj/auto.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Auto partitioning code. + */ + +#include <stdio.h> +#include <ctype.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <err.h> +#include "disk.h" +#include "mbr.h" +#include "auto.h" + +int AUTO_boothfs __P((disk_t *, mbr_t *)); +int AUTO_hfs __P((disk_t *, mbr_t *)); +int AUTO_dos __P((disk_t *, mbr_t *)); +int AUTO_raid __P((disk_t *, mbr_t *)); + +/* The default style is the first one in the list */ +struct _auto_style { + char *style_name; + int (*style_fn)(disk_t *, mbr_t *); + char *description; +} style_fns[] = { + {"boothfs", AUTO_boothfs, "8Mb boot plus HFS+ root partition"}, + {"hfs", AUTO_hfs, "Entire disk as one HFS+ partition"}, + {"dos", AUTO_dos, "Entire disk as one DOS partition"}, + {"raid", AUTO_raid, "Entire disk as one 0xAC partition"}, + {0,0} +}; + +void +AUTO_print_styles(FILE *f) +{ + struct _auto_style *fp; + int i; + + for (i=0, fp = &style_fns[0]; fp->style_name != NULL; i++, fp++) { + fprintf(f, " %-10s %s%s\n", fp->style_name, fp->description, (i==0) ? " (default)" : ""); + } +} + + +int +AUTO_init(disk_t *disk, char *style, mbr_t *mbr) +{ + struct _auto_style *fp; + + for (fp = &style_fns[0]; fp->style_name != NULL; fp++) { + /* If style is NULL, use the first (default) style */ + if (style == NULL || strcasecmp(style, fp->style_name) == 0) { + return (*fp->style_fn)(disk, mbr); + } + } + warnx("No such auto-partition style %s", style); + return AUTO_ERR; +} + + +static int +use_whole_disk(disk_t *disk, unsigned char id, mbr_t *mbr) +{ + MBR_clear(mbr); + mbr->part[0].id = id; + mbr->part[0].bs = 63; + mbr->part[0].ns = disk->real->size - 63; + PRT_fix_CHS(disk, &mbr->part[0], 0); + return AUTO_OK; +} + +/* DOS style: one partition for the whole disk */ +int +AUTO_dos(disk_t *disk, mbr_t *mbr) +{ + int cc; + cc = use_whole_disk(disk, 0x0C, mbr); + if (cc == AUTO_OK) { + mbr->part[0].flag = DOSACTIVE; + } + return cc; +} + +/* HFS style: one partition for the whole disk */ +int +AUTO_hfs(disk_t *disk, mbr_t *mbr) +{ + int cc; + cc = use_whole_disk(disk, 0xAF, mbr); + if (cc == AUTO_OK) { + mbr->part[0].flag = DOSACTIVE; + } + return cc; +} + +/* One boot partition, one HFS+ root partition */ +int +AUTO_boothfs (disk_t *disk, mbr_t *mbr) +{ + /* Check disk size. */ + if (disk->real->size < 16 * 2048) { + errx(1, "Disk size must be greater than 16Mb"); + return AUTO_ERR; + } + + MBR_clear(mbr); + + /* 8MB boot partition */ + mbr->part[0].id = 0xAB; + mbr->part[0].bs = 63; + mbr->part[0].ns = 8 * 1024 * 2; + mbr->part[0].flag = DOSACTIVE; + PRT_fix_CHS(disk, &mbr->part[0], 0); + + /* Rest of the disk for rooting */ + mbr->part[1].id = 0xAF; + mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns); + mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63; + PRT_fix_CHS(disk, &mbr->part[1], 1); + + return AUTO_OK; +} + + + +/* RAID style: one 0xAC partition for the whole disk */ +int +AUTO_raid(disk_t *disk, mbr_t *mbr) +{ + return use_whole_disk(disk, 0xAC, mbr); +} + |