| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fdisk.c,v 1.137 2011/12/02 04:05:20 enami Exp $ */ | | 1 | /* $NetBSD: fdisk.c,v 1.138 2011/12/02 15:21:15 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Mach Operating System | | 4 | * Mach Operating System |
5 | * Copyright (c) 1992 Carnegie Mellon University | | 5 | * Copyright (c) 1992 Carnegie Mellon University |
6 | * All Rights Reserved. | | 6 | * All Rights Reserved. |
7 | * | | 7 | * |
8 | * Permission to use, copy, modify and distribute this software and its | | 8 | * Permission to use, copy, modify and distribute this software and its |
9 | * documentation is hereby granted, provided that both the copyright | | 9 | * documentation is hereby granted, provided that both the copyright |
10 | * notice and this permission notice appear in all copies of the | | 10 | * notice and this permission notice appear in all copies of the |
11 | * software, derivative works or modified versions, and any portions | | 11 | * software, derivative works or modified versions, and any portions |
12 | * thereof, and that both notices appear in supporting documentation. | | 12 | * thereof, and that both notices appear in supporting documentation. |
13 | * | | 13 | * |
14 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | | 14 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| @@ -29,27 +29,27 @@ | | | @@ -29,27 +29,27 @@ |
29 | /* | | 29 | /* |
30 | * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University | | 30 | * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University |
31 | * Copyright (c) 1989 Robert. V. Baron | | 31 | * Copyright (c) 1989 Robert. V. Baron |
32 | * Created. | | 32 | * Created. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #if HAVE_NBTOOL_CONFIG_H | | 35 | #if HAVE_NBTOOL_CONFIG_H |
36 | #include "nbtool_config.h" | | 36 | #include "nbtool_config.h" |
37 | #endif | | 37 | #endif |
38 | | | 38 | |
39 | #include <sys/cdefs.h> | | 39 | #include <sys/cdefs.h> |
40 | | | 40 | |
41 | #ifndef lint | | 41 | #ifndef lint |
42 | __RCSID("$NetBSD: fdisk.c,v 1.137 2011/12/02 04:05:20 enami Exp $"); | | 42 | __RCSID("$NetBSD: fdisk.c,v 1.138 2011/12/02 15:21:15 christos Exp $"); |
43 | #endif /* not lint */ | | 43 | #endif /* not lint */ |
44 | | | 44 | |
45 | #define MBRPTYPENAMES | | 45 | #define MBRPTYPENAMES |
46 | #include <sys/types.h> | | 46 | #include <sys/types.h> |
47 | #include <sys/param.h> | | 47 | #include <sys/param.h> |
48 | #include <sys/stat.h> | | 48 | #include <sys/stat.h> |
49 | #include <ctype.h> | | 49 | #include <ctype.h> |
50 | #include <err.h> | | 50 | #include <err.h> |
51 | #include <errno.h> | | 51 | #include <errno.h> |
52 | #include <fcntl.h> | | 52 | #include <fcntl.h> |
53 | #include <paths.h> | | 53 | #include <paths.h> |
54 | #include <stdarg.h> | | 54 | #include <stdarg.h> |
55 | #include <stddef.h> | | 55 | #include <stddef.h> |
| @@ -145,27 +145,27 @@ static const char *disk = _PATH_DEFDISK; | | | @@ -145,27 +145,27 @@ static const char *disk = _PATH_DEFDISK; |
145 | static struct disklabel disklabel; /* disk parameters */ | | 145 | static struct disklabel disklabel; /* disk parameters */ |
146 | | | 146 | |
147 | static struct mbr_sector mboot; | | 147 | static struct mbr_sector mboot; |
148 | | | 148 | |
149 | static const char *boot_dir = DEFAULT_BOOTDIR; | | 149 | static const char *boot_dir = DEFAULT_BOOTDIR; |
150 | static char *boot_path = NULL; /* name of file we actually opened */ | | 150 | static char *boot_path = NULL; /* name of file we actually opened */ |
151 | | | 151 | |
152 | #ifdef BOOTSEL | | 152 | #ifdef BOOTSEL |
153 | #define BOOTSEL_OPTIONS "B" | | 153 | #define BOOTSEL_OPTIONS "B" |
154 | #else | | 154 | #else |
155 | #define BOOTSEL_OPTIONS | | 155 | #define BOOTSEL_OPTIONS |
156 | #define change_part(e, p, id, st, sz, bm) change__part(e, p, id, st, sz) | | 156 | #define change_part(e, p, id, st, sz, bm) change__part(e, p, id, st, sz) |
157 | #endif | | 157 | #endif |
158 | #define OPTIONS BOOTSEL_OPTIONS "0123FSafiluvA:b:c:E:r:s:w:" | | 158 | #define OPTIONS BOOTSEL_OPTIONS "0123FSafiIluvA:b:c:E:r:s:w:" |
159 | | | 159 | |
160 | /* | | 160 | /* |
161 | * Disk geometry and partition alignment. | | 161 | * Disk geometry and partition alignment. |
162 | * | | 162 | * |
163 | * Modern disks do not have a fixed geomery and will always give a 'faked' | | 163 | * Modern disks do not have a fixed geomery and will always give a 'faked' |
164 | * geometry that matches the ATA standard - max 16 heads and 256 sec/track. | | 164 | * geometry that matches the ATA standard - max 16 heads and 256 sec/track. |
165 | * The ATA geometry allows access to 2^28 sectors (as does LBA mode). | | 165 | * The ATA geometry allows access to 2^28 sectors (as does LBA mode). |
166 | * | | 166 | * |
167 | * The BIOS calls originally used an 8bit register for cylinder, head and | | 167 | * The BIOS calls originally used an 8bit register for cylinder, head and |
168 | * sector. Later 2 bits were stolen from the sector number and added to | | 168 | * sector. Later 2 bits were stolen from the sector number and added to |
169 | * cylinder number. The BIOS will translate this faked geometry either to | | 169 | * cylinder number. The BIOS will translate this faked geometry either to |
170 | * the geometry reported by the disk, or do LBA reads (possibly LBA48). | | 170 | * the geometry reported by the disk, or do LBA reads (possibly LBA48). |
171 | * BIOS CHS reads have all sorts of limits, but 2^24 is absolute. | | 171 | * BIOS CHS reads have all sorts of limits, but 2^24 is absolute. |
| @@ -605,26 +605,27 @@ usage(void) | | | @@ -605,26 +605,27 @@ usage(void) |
605 | int indent = 7 + (int)strlen(getprogname()) + 1; | | 605 | int indent = 7 + (int)strlen(getprogname()) + 1; |
606 | | | 606 | |
607 | (void)fprintf(stderr, "usage: %s [-aBFfIilSuv] " | | 607 | (void)fprintf(stderr, "usage: %s [-aBFfIilSuv] " |
608 | "[-A ptn_alignment[/ptn_0_offset]] \\\n" | | 608 | "[-A ptn_alignment[/ptn_0_offset]] \\\n" |
609 | "%*s[-b cylinders/heads/sectors] \\\n" | | 609 | "%*s[-b cylinders/heads/sectors] \\\n" |
610 | "%*s[-0123 | -E num " | | 610 | "%*s[-0123 | -E num " |
611 | "[-s id/start/size[/bootmenu]]] \\\n" | | 611 | "[-s id/start/size[/bootmenu]]] \\\n" |
612 | "%*s[-t disktab] [-T disktype] \\\n" | | 612 | "%*s[-t disktab] [-T disktype] \\\n" |
613 | "%*s[-c bootcode] " | | 613 | "%*s[-c bootcode] " |
614 | "[-r|-w file] [device]\n" | | 614 | "[-r|-w file] [device]\n" |
615 | "\t-a change active partition\n" | | 615 | "\t-a change active partition\n" |
616 | "\t-f force - not interactive\n" | | 616 | "\t-f force - not interactive\n" |
617 | "\t-i initialise MBR code\n" | | 617 | "\t-i initialise MBR code\n" |
| | | 618 | "\t-I ignore errors about no space or overlapping partitions\n" |
618 | "\t-l list partition types\n" | | 619 | "\t-l list partition types\n" |
619 | "\t-u update partition data\n" | | 620 | "\t-u update partition data\n" |
620 | "\t-v verbose output, -v -v more verbose still\n" | | 621 | "\t-v verbose output, -v -v more verbose still\n" |
621 | "\t-B update bootselect options\n" | | 622 | "\t-B update bootselect options\n" |
622 | "\t-F treat device as a regular file\n" | | 623 | "\t-F treat device as a regular file\n" |
623 | "\t-S output as shell defines\n" | | 624 | "\t-S output as shell defines\n" |
624 | "\t-r and -w access 'file' for non-destructive testing\n", | | 625 | "\t-r and -w access 'file' for non-destructive testing\n", |
625 | getprogname(), indent, "", indent, "", indent, "", indent, ""); | | 626 | getprogname(), indent, "", indent, "", indent, "", indent, ""); |
626 | exit(1); | | 627 | exit(1); |
627 | } | | 628 | } |
628 | | | 629 | |
629 | static daddr_t | | 630 | static daddr_t |
630 | ext_offset(int part) | | 631 | ext_offset(int part) |
| @@ -2055,27 +2056,27 @@ change_part(int extended, int part, int | | | @@ -2055,27 +2056,27 @@ change_part(int extended, int part, int |
2055 | if (start == 0) { | | 2056 | if (start == 0) { |
2056 | /* Look for first gap */ | | 2057 | /* Look for first gap */ |
2057 | start = ptn_0_offset; | | 2058 | start = ptn_0_offset; |
2058 | for (p = 0; p < MBR_PART_COUNT; p++) { | | 2059 | for (p = 0; p < MBR_PART_COUNT; p++) { |
2059 | if (mboot.mbr_parts[p].mbrp_type == 0) | | 2060 | if (mboot.mbr_parts[p].mbrp_type == 0) |
2060 | continue; | | 2061 | continue; |
2061 | n_s = le32toh(mboot.mbr_parts[p].mbrp_start); | | 2062 | n_s = le32toh(mboot.mbr_parts[p].mbrp_start); |
2062 | n_e = n_s + le32toh(mboot.mbr_parts[p].mbrp_size); | | 2063 | n_e = n_s + le32toh(mboot.mbr_parts[p].mbrp_size); |
2063 | if (start >= n_s && start < n_e) { | | 2064 | if (start >= n_s && start < n_e) { |
2064 | start = n_e; | | 2065 | start = n_e; |
2065 | p = -1; | | 2066 | p = -1; |
2066 | } | | 2067 | } |
2067 | } | | 2068 | } |
2068 | if (start >= disksectors) { | | 2069 | if (start >= disksectors && !I_flag) { |
2069 | printf("No free space\n"); | | 2070 | printf("No free space\n"); |
2070 | return 0; | | 2071 | return 0; |
2071 | } | | 2072 | } |
2072 | } | | 2073 | } |
2073 | } | | 2074 | } |
2074 | | | 2075 | |
2075 | if (!f_flag) { | | 2076 | if (!f_flag) { |
2076 | /* request new values from user */ | | 2077 | /* request new values from user */ |
2077 | if (sysid == 0) | | 2078 | if (sysid == 0) |
2078 | sysid = 169; | | 2079 | sysid = 169; |
2079 | sysid = decimal("sysid", sysid, 0, 0, 255); | | 2080 | sysid = decimal("sysid", sysid, 0, 0, 255); |
2080 | if (sysid == 0 && !v_flag) { | | 2081 | if (sysid == 0 && !v_flag) { |
2081 | start = 0; | | 2082 | start = 0; |