CVS commit: src/sbin/fdisk
Module Name:src Committed By: mlelstv Date: Sat Apr 2 19:15:09 UTC 2022 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Avoid crashes with invalid or tiny sector sizes. To generate a diff of this commit: cvs rdiff -u -r1.160 -r1.161 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: mlelstv Date: Sat Apr 2 19:15:09 UTC 2022 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Avoid crashes with invalid or tiny sector sizes. To generate a diff of this commit: cvs rdiff -u -r1.160 -r1.161 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.160 src/sbin/fdisk/fdisk.c:1.161 --- src/sbin/fdisk/fdisk.c:1.160 Wed Nov 3 14:30:04 2021 +++ src/sbin/fdisk/fdisk.c Sat Apr 2 19:15:09 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.160 2021/11/03 14:30:04 nia Exp $ */ +/* $NetBSD: fdisk.c,v 1.161 2022/04/02 19:15:09 mlelstv Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.160 2021/11/03 14:30:04 nia Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.161 2022/04/02 19:15:09 mlelstv Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -2551,6 +2551,9 @@ read_disk(daddr_t sector, void *buf) if (*rfd == -1) errx(1, "read_disk(); fd == -1"); + if (secsize <= 0) + errx(1, "read_disk(); secsize invalid"); + off_t offs = sector * (off_t)secsize; off_t mod = offs & (secsize - 1); off_t rnd = offs & ~(secsize - 1); @@ -2558,8 +2561,8 @@ read_disk(daddr_t sector, void *buf) if (lseek(*rfd, rnd, SEEK_SET) == (off_t)-1) return -1; - if (secsize == 512) - return read(*rfd, buf, 512); + if (secsize <= 512) + return read(*rfd, buf, secsize); if ((nr = read(*rfd, iobuf, secsize)) != secsize) return nr;
CVS commit: src/sbin/fdisk
Module Name:src Committed By: nia Date: Wed Nov 3 14:30:04 UTC 2021 Modified Files: src/sbin/fdisk: fdisk.c Log Message: fdisk(8): Convert realloc(x * y) to reallocarr. Eliminate temp variables. To generate a diff of this commit: cvs rdiff -u -r1.159 -r1.160 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: nia Date: Wed Nov 3 14:30:04 UTC 2021 Modified Files: src/sbin/fdisk: fdisk.c Log Message: fdisk(8): Convert realloc(x * y) to reallocarr. Eliminate temp variables. To generate a diff of this commit: cvs rdiff -u -r1.159 -r1.160 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.159 src/sbin/fdisk/fdisk.c:1.160 --- src/sbin/fdisk/fdisk.c:1.159 Sun May 24 21:02:12 2020 +++ src/sbin/fdisk/fdisk.c Wed Nov 3 14:30:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.159 2020/05/24 21:02:12 wiz Exp $ */ +/* $NetBSD: fdisk.c,v 1.160 2021/11/03 14:30:04 nia Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.159 2020/05/24 21:02:12 wiz Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.160 2021/11/03 14:30:04 nia Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -1148,7 +1148,6 @@ get_extended_ptn(void) struct mbr_partition *mp; struct mbr_sector *boot; daddr_t offset; - struct mbr_sector *nptn; /* find first (there should only be one) extended partition */ for (mp = mboot.mbr_parts; !MBR_IS_EXTENDED(mp->mbrp_type); mp++) @@ -1163,10 +1162,9 @@ get_extended_ptn(void) ext.limit = ext.base + le32toh(mp->mbrp_size); ext.ptn_id = mp - mboot.mbr_parts; for (offset = 0;; offset = le32toh(boot->mbr_parts[1].mbrp_start)) { - nptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn); - if (nptn == NULL) + if (reallocarr(, + ext.num_ptn + 1, sizeof(*ext.ptn)) != 0) err(1, "Malloc failed"); - ext.ptn = nptn; boot = ext.ptn + ext.num_ptn; if (read_s0(offset + ext.base, boot) == -1) break; @@ -1810,12 +1808,9 @@ add_ext_ptn(daddr_t start, daddr_t size) { int part; struct mbr_partition *partp; - struct mbr_sector *nptn; - nptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn); - if (!nptn) - err(1, "realloc"); - ext.ptn = nptn; + if (reallocarr(, ext.num_ptn + 1, sizeof(*ext.ptn)) != 0) + err(1, "reallocarr"); for (part = 0; part < ext.num_ptn; part++) if (ext_offset(part) > start) break;
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sun May 24 21:02:12 UTC 2020 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add -g to usage. To generate a diff of this commit: cvs rdiff -u -r1.158 -r1.159 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sun May 24 21:02:12 UTC 2020 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add -g to usage. To generate a diff of this commit: cvs rdiff -u -r1.158 -r1.159 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.158 src/sbin/fdisk/fdisk.c:1.159 --- src/sbin/fdisk/fdisk.c:1.158 Sun May 24 18:42:48 2020 +++ src/sbin/fdisk/fdisk.c Sun May 24 21:02:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.158 2020/05/24 18:42:48 jmcneill Exp $ */ +/* $NetBSD: fdisk.c,v 1.159 2020/05/24 21:02:12 wiz Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.158 2020/05/24 18:42:48 jmcneill Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.159 2020/05/24 21:02:12 wiz Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -665,7 +665,7 @@ usage(void) { int indent = 7 + (int)strlen(getprogname()) + 1; - (void)fprintf(stderr, "usage: %s [-aBFfIilSuv] " + (void)fprintf(stderr, "usage: %s [-aBFfgIilSuv] " "[-A ptn_alignment[/ptn_0_offset]] \\\n" "%*s[-b cylinders/heads/sectors] \\\n" "%*s[-0123 | -E num " @@ -675,6 +675,7 @@ usage(void) "[-r|-w file] [-z sectorsize] [device]\n" "\t-a change active partition\n" "\t-f force - not interactive\n" + "\t-g preserve existing GPT headers\n" "\t-i initialise MBR code\n" "\t-I ignore errors about no space or overlapping partitions\n" "\t-l list partition types\n"
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sun May 24 21:01:49 UTC 2020 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Use Nx, fix formatting nit. To generate a diff of this commit: cvs rdiff -u -r1.91 -r1.92 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sun May 24 21:01:49 UTC 2020 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Use Nx, fix formatting nit. To generate a diff of this commit: cvs rdiff -u -r1.91 -r1.92 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.91 src/sbin/fdisk/fdisk.8:1.92 --- src/sbin/fdisk/fdisk.8:1.91 Sun May 24 18:42:48 2020 +++ src/sbin/fdisk/fdisk.8 Sun May 24 21:01:49 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: fdisk.8,v 1.91 2020/05/24 18:42:48 jmcneill Exp $ +.\" $NetBSD: fdisk.8,v 1.92 2020/05/24 21:01:49 wiz Exp $ .\" .Dd May 24, 2020 .Dt FDISK 8 @@ -519,7 +519,7 @@ sector .It Em "cylinder" , Em "head" , Em "sector" are the beginning or ending address of a partition. .Pp -.Em "Note:" +.Em Note : these numbers are read from the bootblock, so are the values calculated by a previous run of .Nm . @@ -601,8 +601,9 @@ Default location of i386 bootcode .It Pa /usr/mdec/mbr_bootsel Default location of i386 bootselect code .It Pa /usr/mdec/mbr_ext -Default location of i386 bootselect for extended partitions (i.e., NetBSD on -logical partitions) +Default location of i386 bootselect for extended partitions (i.e., +.Nx +on logical partitions) .El .Sh EXAMPLES Update MBR partition data of
CVS commit: src/sbin/fdisk
Module Name:src Committed By: jmcneill Date: Sun May 24 18:42:48 UTC 2020 Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: Add -g flag to preserve GPT headers when updating MBR. To generate a diff of this commit: cvs rdiff -u -r1.90 -r1.91 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.157 -r1.158 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.90 src/sbin/fdisk/fdisk.8:1.91 --- src/sbin/fdisk/fdisk.8:1.90 Sun Dec 15 11:49:28 2019 +++ src/sbin/fdisk/fdisk.8 Sun May 24 18:42:48 2020 @@ -1,6 +1,6 @@ -.\" $NetBSD: fdisk.8,v 1.90 2019/12/15 11:49:28 wiz Exp $ +.\" $NetBSD: fdisk.8,v 1.91 2020/05/24 18:42:48 jmcneill Exp $ .\" -.Dd December 14, 2019 +.Dd May 24, 2020 .Dt FDISK 8 .Os .Sh NAME @@ -8,7 +8,7 @@ .Nd MS-DOS partition maintenance program .Sh SYNOPSIS .Nm -.Op Fl aBFfIiSuv +.Op Fl aBFfgIiSuv .Oo .Fl 0 | 1 | 2 | 3 | E Ar number .Op Fl s Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc @@ -114,7 +114,9 @@ selects defaults for its questions to gu If partition data is going to be updated and the disk carries GUID Partition Tables, .Nm -will remove both primary and backup GPT headers from the disk. +will remove both primary and backup GPT headers from the disk unless the +.Fl g +flag is specified. See .Xr gpt 8 for information on how to manipulate GUID Partition Tables. @@ -262,6 +264,8 @@ and fields .Pq only Ar start No and Ar size No can be specified by Fl s No option . They will be automatically computed using the BIOS geometry. +.It Fl g +Preserve existing GPT headers when updating partitions. .It Fl I Ignore errors from overlapping partitions. Some devices (cameras CHDK) require overlapping partitions to support Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.157 src/sbin/fdisk/fdisk.c:1.158 --- src/sbin/fdisk/fdisk.c:1.157 Mon Oct 7 20:56:07 2019 +++ src/sbin/fdisk/fdisk.c Sun May 24 18:42:48 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.157 2019/10/07 20:56:07 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.158 2020/05/24 18:42:48 jmcneill Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.157 2019/10/07 20:56:07 christos Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.158 2020/05/24 18:42:48 jmcneill Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -141,7 +141,7 @@ static char *boot_path = NULL; /* name #define BOOTSEL_OPTIONS #define change_part(e, p, id, st, sz, bm) change__part(e, p, id, st, sz) #endif -#define OPTIONS BOOTSEL_OPTIONS "0123FSafiIluvA:b:c:E:r:s:w:z:" +#define OPTIONS BOOTSEL_OPTIONS "0123FSafgiIluvA:b:c:E:r:s:w:z:" /* * Disk geometry and partition alignment. @@ -215,6 +215,7 @@ static int u_flag; /* update partition static int v_flag; /* more verbose */ static int sh_flag; /* Output data as shell defines */ static int f_flag; /* force --not interactive */ +static int g_flag; /* preserve GPT headers */ static int s_flag; /* set id,offset,size */ static int b_flag; /* Set cyl, heads, secs (as c/h/s) */ static int B_flag; /* Edit/install bootselect code */ @@ -430,6 +431,9 @@ main(int argc, char *argv[]) case 'f': /* Non interactive */ f_flag = 1; break; + case 'g': /* Preserve GPT headers */ + g_flag = 1; + break; case 'i': /* Always update bootcode */ i_flag = 1; break; @@ -3058,6 +3062,9 @@ delete_gpt(struct gpt_hdr *gptp) char buf[512]; struct gpt_hdr *hdr = (void *)buf; + if (g_flag) + return 0; /* preserve existing GPT headers */ + if (gptp->hdr_size == 0) return 0;
CVS commit: src/sbin/fdisk
Module Name:src Committed By: jmcneill Date: Sun May 24 18:42:48 UTC 2020 Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: Add -g flag to preserve GPT headers when updating MBR. To generate a diff of this commit: cvs rdiff -u -r1.90 -r1.91 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.157 -r1.158 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sun Dec 15 11:49:28 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix xrefs. To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.89 src/sbin/fdisk/fdisk.8:1.90 --- src/sbin/fdisk/fdisk.8:1.89 Sat Dec 14 20:46:13 2019 +++ src/sbin/fdisk/fdisk.8 Sun Dec 15 11:49:28 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: fdisk.8,v 1.89 2019/12/14 20:46:13 christos Exp $ +.\" $NetBSD: fdisk.8,v 1.90 2019/12/15 11:49:28 wiz Exp $ .\" .Dd December 14, 2019 .Dt FDISK 8 @@ -175,7 +175,7 @@ On an i386 or amd64 system, interactivel These include the default boot partition and the timeout value for the prompt. (The boot selector permits the user to interactively select the boot partition, and thus which operating system is run, at system boot time; see -.Xr mbr 8 +.Xr x86/mbr 8 for more information.) .It Fl b Ar cylinders/heads/sectors Specify the BIOS geometry parameters for @@ -651,8 +651,8 @@ partition using whole disk without promp .Xr disklabel 8 , .Xr gpt 8 , .Xr installboot 8 , -.Xr mbr 8 , -.Xr mbrlabel 8 +.Xr mbrlabel 8 , +.Xr x86/mbr 8 .Sh HISTORY A version of .Nm
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sun Dec 15 11:49:28 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix xrefs. To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sat Dec 14 20:46:13 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: PR/54756: germain: Avoid confusion caused by overuse of the word "file" both as a noun and an argument name. To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.88 src/sbin/fdisk/fdisk.8:1.89 --- src/sbin/fdisk/fdisk.8:1.88 Tue Apr 9 05:03:41 2019 +++ src/sbin/fdisk/fdisk.8 Sat Dec 14 15:46:13 2019 @@ -1,6 +1,6 @@ -.\" $NetBSD: fdisk.8,v 1.88 2019/04/09 09:03:41 tnn Exp $ +.\" $NetBSD: fdisk.8,v 1.89 2019/12/14 20:46:13 christos Exp $ .\" -.Dd April 9, 2019 +.Dd December 14, 2019 .Dt FDISK 8 .Os .Sh NAME @@ -13,7 +13,7 @@ .Fl 0 | 1 | 2 | 3 | E Ar number .Op Fl s Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc .Oc -.Op Fl r Ar file | Fl w Ar file +.Op Fl r Ar bootfile | Fl w Ar bootfile .Op Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset .Op Fl b Ar cylinders/heads/sectors .Op Fl c Ar bootcode @@ -282,9 +282,9 @@ The partition table is left alone by thi Lists known .Em sysid values and exit. -.It Fl r Ar file +.It Fl r Ar bootfile Read the boot record from file -.Ar file +.Ar bootfile instead of the specified disk. The geometry information used is still that of the disk volume. Any changes are written back to the file. @@ -386,9 +386,9 @@ Using with .Fl u allows the user to change more parameters than normally permitted. -.It Fl w Ar file +.It Fl w Ar bootfile Write the modified partition table to file -.Ar file +.Ar bootfile instead of the disk. .It Fl z Ar sectorsize Specify a sector size other than 512, for devices that only @@ -585,9 +585,9 @@ lose all the data in that partition. You should run this program interactively once or twice to see how it works. This is completely safe as long as you answer the last question in the negative. You can also specify -.Fl w Ar file +.Fl w Ar bootfile to write the output to a file and later specify -.Fl r Ar file +.Fl r Ar bootfile to read back the updated information. This can be done without having write access to the disk volume. .Sh FILES
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sat Dec 14 20:46:13 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: PR/54756: germain: Avoid confusion caused by overuse of the word "file" both as a noun and an argument name. To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Mon Oct 7 20:56:07 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.c Log Message: print the name of the disk causing the error. To generate a diff of this commit: cvs rdiff -u -r1.156 -r1.157 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.156 src/sbin/fdisk/fdisk.c:1.157 --- src/sbin/fdisk/fdisk.c:1.156 Wed Nov 14 07:05:29 2018 +++ src/sbin/fdisk/fdisk.c Mon Oct 7 16:56:07 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.156 2018/11/14 12:05:29 mlelstv Exp $ */ +/* $NetBSD: fdisk.c,v 1.157 2019/10/07 20:56:07 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.156 2018/11/14 12:05:29 mlelstv Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.157 2019/10/07 20:56:07 christos Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -2620,19 +2620,19 @@ get_params(void) struct disklabel *tmplabel; if ((tmplabel = getdiskbyname(disk_type)) == NULL) { - warn("bad disktype"); + warn("%s: bad disktype", disk); return (-1); } disklabel = *tmplabel; } else if (F_flag) { struct stat st; if (fstat(fd, ) == -1) { - warn("fstat"); + warn("%s: fstat", disk); return (-1); } if (st.st_size % 512 != 0) { - warnx("%s size (%lld) is not divisible " - "by sector size (%d)", disk, (long long)st.st_size, + warnx("%s size (%ju) is not divisible " + "by sector size (%d)", disk, (uintmax_t)st.st_size, 512); } disklabel.d_secperunit = st.st_size / 512; @@ -2644,9 +2644,9 @@ get_params(void) } #if !HAVE_NBTOOL_CONFIG_H else if (ioctl(fd, DIOCGDEFLABEL, ) == -1) { - warn("DIOCGDEFLABEL"); + warn("%s: DIOCGDEFLABEL", disk); if (ioctl(fd, DIOCGDINFO, ) == -1) { - warn("DIOCGDINFO"); + warn("%s: DIOCGDINFO", disk); return (-1); } }
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Mon Oct 7 20:56:07 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.c Log Message: print the name of the disk causing the error. To generate a diff of this commit: cvs rdiff -u -r1.156 -r1.157 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: tnn Date: Tue Apr 9 09:03:41 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: mention that -B is used to set the timeout for mbr_bootsel To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.87 src/sbin/fdisk/fdisk.8:1.88 --- src/sbin/fdisk/fdisk.8:1.87 Fri Jan 27 10:12:05 2017 +++ src/sbin/fdisk/fdisk.8 Tue Apr 9 09:03:41 2019 @@ -1,6 +1,6 @@ -.\" $NetBSD: fdisk.8,v 1.87 2017/01/27 10:12:05 abhinav Exp $ +.\" $NetBSD: fdisk.8,v 1.88 2019/04/09 09:03:41 tnn Exp $ .\" -.Dd September 11, 2016 +.Dd April 9, 2019 .Dt FDISK 8 .Os .Sh NAME @@ -172,6 +172,7 @@ In interactive mode this question will b have been processed. .It Fl B On an i386 or amd64 system, interactively update the boot selector settings. +These include the default boot partition and the timeout value for the prompt. (The boot selector permits the user to interactively select the boot partition, and thus which operating system is run, at system boot time; see .Xr mbr 8
CVS commit: src/sbin/fdisk
Module Name:src Committed By: tnn Date: Tue Apr 9 09:03:41 UTC 2019 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: mention that -B is used to set the timeout for mbr_bootsel To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: mlelstv Date: Wed Nov 14 12:05:29 UTC 2018 Modified Files: src/sbin/fdisk: fdisk.c Log Message: In validate_bootsel, the code assumed that arr[j][i] can be accessed with something like arr[0][j*ARRAYWIDTH+i]. gcc no longer allows such hacks and discards the code silently because of undefined behaviour. To generate a diff of this commit: cvs rdiff -u -r1.155 -r1.156 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.155 src/sbin/fdisk/fdisk.c:1.156 --- src/sbin/fdisk/fdisk.c:1.155 Mon Aug 27 14:55:46 2018 +++ src/sbin/fdisk/fdisk.c Wed Nov 14 12:05:29 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.155 2018/08/27 14:55:46 sevan Exp $ */ +/* $NetBSD: fdisk.c,v 1.156 2018/11/14 12:05:29 mlelstv Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.155 2018/08/27 14:55:46 sevan Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.156 2018/11/14 12:05:29 mlelstv Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -2685,7 +2685,7 @@ validate_bootsel(struct mbr_bootsel *mbs { unsigned int key = mbs->mbrbs_defkey; unsigned int tmo; - size_t i; + size_t i, j; if (v_flag) return 0; @@ -2717,8 +2717,9 @@ validate_bootsel(struct mbr_bootsel *mbs /* Check the menu strings are printable */ /* Unfortunately they aren't zero filled... */ - for (i = 0; i < sizeof(mbs->mbrbs_nametab); i++) { - int c = (uint8_t)mbs->mbrbs_nametab[0][i]; + for (j = 0; j < __arraycount(mbs->mbrbs_nametab); ++j) + for (i = 0; i < sizeof(mbs->mbrbs_nametab[j]); i++) { + int c = (uint8_t)mbs->mbrbs_nametab[j][i]; if (c == 0 || isprint(c)) continue; return 3;
CVS commit: src/sbin/fdisk
Module Name:src Committed By: mlelstv Date: Wed Nov 14 12:05:29 UTC 2018 Modified Files: src/sbin/fdisk: fdisk.c Log Message: In validate_bootsel, the code assumed that arr[j][i] can be accessed with something like arr[0][j*ARRAYWIDTH+i]. gcc no longer allows such hacks and discards the code silently because of undefined behaviour. To generate a diff of this commit: cvs rdiff -u -r1.155 -r1.156 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: sevan Date: Mon Aug 27 14:55:47 UTC 2018 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add missing -z flag to usage() To generate a diff of this commit: cvs rdiff -u -r1.154 -r1.155 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.154 src/sbin/fdisk/fdisk.c:1.155 --- src/sbin/fdisk/fdisk.c:1.154 Mon Oct 2 22:02:05 2017 +++ src/sbin/fdisk/fdisk.c Mon Aug 27 14:55:46 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.154 2017/10/02 22:02:05 joerg Exp $ */ +/* $NetBSD: fdisk.c,v 1.155 2018/08/27 14:55:46 sevan Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.154 2017/10/02 22:02:05 joerg Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.155 2018/08/27 14:55:46 sevan Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -668,7 +668,7 @@ usage(void) "[-s [id][/[start][/[size][/bootmenu \\\n" "%*s[-t disktab] [-T disktype] \\\n" "%*s[-c bootcode] " - "[-r|-w file] [device]\n" + "[-r|-w file] [-z sectorsize] [device]\n" "\t-a change active partition\n" "\t-f force - not interactive\n" "\t-i initialise MBR code\n"
CVS commit: src/sbin/fdisk
Module Name:src Committed By: sevan Date: Mon Aug 27 14:55:47 UTC 2018 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add missing -z flag to usage() To generate a diff of this commit: cvs rdiff -u -r1.154 -r1.155 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: joerg Date: Mon Oct 2 22:02:05 UTC 2017 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Really don't include ioctl code for tools build. To generate a diff of this commit: cvs rdiff -u -r1.153 -r1.154 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: joerg Date: Mon Oct 2 22:02:05 UTC 2017 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Really don't include ioctl code for tools build. To generate a diff of this commit: cvs rdiff -u -r1.153 -r1.154 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.153 src/sbin/fdisk/fdisk.c:1.154 --- src/sbin/fdisk/fdisk.c:1.153 Sun Nov 22 15:53:10 2015 +++ src/sbin/fdisk/fdisk.c Mon Oct 2 22:02:05 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.153 2015/11/22 15:53:10 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.154 2017/10/02 22:02:05 joerg Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.153 2015/11/22 15:53:10 christos Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.154 2017/10/02 22:02:05 joerg Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -58,6 +58,7 @@ __RCSID("$NetBSD: fdisk.c,v 1.153 2015/1 #include #include #include +#include #if !HAVE_NBTOOL_CONFIG_H #include @@ -67,7 +68,6 @@ __RCSID("$NetBSD: fdisk.c,v 1.153 2015/1 #include #include #include -#include #else #include #include @@ -75,15 +75,6 @@ __RCSID("$NetBSD: fdisk.c,v 1.153 2015/1 #include "../../include/disktab.h" /* We enforce -F, so none of these possibly undefined items can be needed */ #define opendisk(path, fl, buf, buflen, cooked) (-1) -#ifndef DIOCGDEFLABEL -#define DIOCGDEFLABEL 0 -#endif -#ifndef DIOCGDINFO -#define DIOCGDINFO 0 -#endif -#ifndef DIOCWLABEL -#define DIOCWLABEL 0 -#endif #endif /* HAVE_NBTOOL_CONFIG_H */ #ifndef DEFAULT_BOOTDIR @@ -2650,13 +2641,16 @@ get_params(void) disklabel.d_ntracks = dos_heads; disklabel.d_secsize = 512; disklabel.d_nsectors = dos_sectors; - } else if (ioctl(fd, DIOCGDEFLABEL, ) == -1) { + } +#if !HAVE_NBTOOL_CONFIG_H + else if (ioctl(fd, DIOCGDEFLABEL, ) == -1) { warn("DIOCGDEFLABEL"); if (ioctl(fd, DIOCGDINFO, ) == -1) { warn("DIOCGDINFO"); return (-1); } } +#endif disksectors = disklabel.d_secperunit; cylinders = disklabel.d_ncylinders; @@ -2813,8 +2807,10 @@ write_mbr(void) * sector 0. (e.g. empty disk) */ flag = 1; +#if !HAVE_NBTOOL_CONFIG_H if (wfd == fd && F_flag == 0 && ioctl(wfd, DIOCWLABEL, ) < 0) warn("DIOCWLABEL"); +#endif if (write_disk(0, ) == -1) { warn("Can't write fdisk partition table"); goto protect_label; @@ -2835,8 +2831,10 @@ write_mbr(void) rval = 0; protect_label: flag = 0; +#if !HAVE_NBTOOL_CONFIG_H if (wfd == fd && F_flag == 0 && ioctl(wfd, DIOCWLABEL, ) < 0) warn("DIOCWLABEL"); +#endif return rval; }
CVS commit: src/sbin/fdisk
Module Name:src Committed By: abhinav Date: Fri Jan 27 10:12:05 UTC 2017 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix spelling of simultaneous. To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.86 src/sbin/fdisk/fdisk.8:1.87 --- src/sbin/fdisk/fdisk.8:1.86 Sun Sep 11 03:35:08 2016 +++ src/sbin/fdisk/fdisk.8 Fri Jan 27 10:12:05 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: fdisk.8,v 1.86 2016/09/11 03:35:08 sevan Exp $ +.\" $NetBSD: fdisk.8,v 1.87 2017/01/27 10:12:05 abhinav Exp $ .\" .Dd September 11, 2016 .Dt FDISK 8 @@ -186,7 +186,7 @@ It is used only in conjunction with the .Fl u flag. If not specified the BIOS geometry will be obtained using sysctl (i386 and -amd64) or by solving the simultaenous equations from the existing partition +amd64) or by solving the simultaneous equations from the existing partition information. If that fails then either the geometry from the disklabel or 63 sectors and 16 heads is used.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: abhinav Date: Fri Jan 27 10:12:05 UTC 2017 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix spelling of simultaneous. To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: sevan Date: Sun Sep 11 03:35:08 UTC 2016 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: - Document the HISTORY of fdisk based on the original post to comp.unix.bsd by Julian Elischer [1] and the Mach 2.5 Installation notes [2]. I was unable to pin point the exact version of Mach the fdisk utility appeared as I didn't find documentation older than version 2.5 & no source code or repo history. fdisk utility appears as a separate utility[3] in v2.5. Due to this, I've avoided stating the exact version fdisk first appeared in Mach. - Make correction pointed by textproc/igor - Bump date [1] https://groups.google.com/forum/#!searchin/comp.unix.bsd/14-Dec-89$20Robert$20Baron$20(rvb)$20at$20Carnegie-Mellon$20University%7Csort:relevance/comp.unix.bsd/Hhi45vAHxDg [2] ftp://ftp.mcs.vuw.ac.nz/doc/misc/mach-i386-doc/i386_install.ps [3] ftp://ftp.mcs.vuw.ac.nz/doc/misc/mach-i386-doc/i386_manpages.ps To generate a diff of this commit: cvs rdiff -u -r1.85 -r1.86 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.85 src/sbin/fdisk/fdisk.8:1.86 --- src/sbin/fdisk/fdisk.8:1.85 Fri Apr 4 13:07:30 2014 +++ src/sbin/fdisk/fdisk.8 Sun Sep 11 03:35:08 2016 @@ -1,6 +1,6 @@ -.\" $NetBSD: fdisk.8,v 1.85 2014/04/04 13:07:30 wiz Exp $ +.\" $NetBSD: fdisk.8,v 1.86 2016/09/11 03:35:08 sevan Exp $ .\" -.Dd April 3, 2014 +.Dd September 11, 2016 .Dt FDISK 8 .Os .Sh NAME @@ -157,11 +157,11 @@ is specified and is not specified, then the offset is set to the alignment. If .Fl A -isn't specified, then the alignment of the first partition is inspected. +is not specified, then the alignment of the first partition is inspected. If it ends on a 2048 sector boundary, then the alignment is set to 2048, if the start is a power of 2 less than, or equal to 2048 then the offset is set to the start sector. -If the first partition isn't defined then the alignment and offset for disks +If the first partition is not defined then the alignment and offset for disks larger than 128GB is set to 2048 (1MB). In all other cases the alignment default to a cylinder and the offset to a track (both using the BIOS geometry). @@ -217,7 +217,7 @@ machines. Specify logical partition .Ar number to be printed or updated. -If the specified logical partition doesn't exist on updating partition data +If the specified logical partition does not exist on updating partition data an additional logical partition will be created. .It Fl F Indicate that @@ -367,7 +367,7 @@ If is specified for any partition .Nm will determine whether the installed boot code supports the bootselect code, -if it doesn't you will be asked whether you want to install the required +if it does not you will be asked whether you want to install the required boot code. To remove a .Em bootmenu @@ -652,6 +652,21 @@ partition using whole disk without promp .Xr installboot 8 , .Xr mbr 8 , .Xr mbrlabel 8 +.Sh HISTORY +A version of +.Nm +first appeared in the Mach Operating System. +It was subsequently ported to +.Bx 386 . +.Sh AUTHORS +.An -nosplit +.Nm +for Mach Operating System was written by +.An Robert Baron Aq Mt r...@cs.cmu.edu . +It was ported to +.Bx 386 +by +.An Julian Elischer Aq Mt jul...@tfs.com . .Sh BUGS The word .Sq partition
CVS commit: src/sbin/fdisk
Module Name:src Committed By: sevan Date: Sun Sep 11 03:35:08 UTC 2016 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: - Document the HISTORY of fdisk based on the original post to comp.unix.bsd by Julian Elischer [1] and the Mach 2.5 Installation notes [2]. I was unable to pin point the exact version of Mach the fdisk utility appeared as I didn't find documentation older than version 2.5 & no source code or repo history. fdisk utility appears as a separate utility[3] in v2.5. Due to this, I've avoided stating the exact version fdisk first appeared in Mach. - Make correction pointed by textproc/igor - Bump date [1] https://groups.google.com/forum/#!searchin/comp.unix.bsd/14-Dec-89$20Robert$20Baron$20(rvb)$20at$20Carnegie-Mellon$20University%7Csort:relevance/comp.unix.bsd/Hhi45vAHxDg [2] ftp://ftp.mcs.vuw.ac.nz/doc/misc/mach-i386-doc/i386_install.ps [3] ftp://ftp.mcs.vuw.ac.nz/doc/misc/mach-i386-doc/i386_manpages.ps To generate a diff of this commit: cvs rdiff -u -r1.85 -r1.86 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sun Nov 22 15:53:10 UTC 2015 Modified Files: src/sbin/fdisk: fdisk.c Log Message: explain how to clear an entry (without reading the source) To generate a diff of this commit: cvs rdiff -u -r1.152 -r1.153 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sun Nov 22 15:53:10 UTC 2015 Modified Files: src/sbin/fdisk: fdisk.c Log Message: explain how to clear an entry (without reading the source) To generate a diff of this commit: cvs rdiff -u -r1.152 -r1.153 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.152 src/sbin/fdisk/fdisk.c:1.153 --- src/sbin/fdisk/fdisk.c:1.152 Tue Jun 16 19:58:30 2015 +++ src/sbin/fdisk/fdisk.c Sun Nov 22 10:53:10 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.152 2015/06/16 23:58:30 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.153 2015/11/22 15:53:10 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.152 2015/06/16 23:58:30 christos Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.153 2015/11/22 15:53:10 christos Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -2975,7 +2975,7 @@ string(const char *prompt, int length, c int len; for (;;) { - printf("%s: [%.*s] ", prompt, length, buf); + printf("%s: [%.*s] (space to clear)", prompt, length, buf); if (!fgets(lbuf, LBUF, stdin)) errx(1, "EOF");
Re: CVS commit: src/sbin/fdisk
On Thu, Apr 03, 2014 at 11:48:10PM +, Christos Zoulas wrote: In article 20140403215619.a8f1...@cvs.netbsd.org, Thomas Klausner source-changes-d@NetBSD.org wrote: -=-=-=-=-=- Module Name: src Committed By:wiz Date:Thu Apr 3 21:56:19 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Update SYNOPSIS. Christos, please check. Needs the same treatment in .It Fl s... Done. Please describe in the manpage what it means when one of these is missing (what is used instead?). Thanks, Thomas
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Fri Apr 4 09:32:56 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix a bug in previous and update detailed -s description. To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.83 src/sbin/fdisk/fdisk.8:1.84 --- src/sbin/fdisk/fdisk.8:1.83 Thu Apr 3 21:56:19 2014 +++ src/sbin/fdisk/fdisk.8 Fri Apr 4 09:32:56 2014 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.83 2014/04/03 21:56:19 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.84 2014/04/04 09:32:56 wiz Exp $ .\ .Dd April 3, 2014 .Dt FDISK 8 @@ -11,7 +11,7 @@ .Op Fl aBFfIiSuv .Oo .Fl 0 | 1 | 2 | 3 | E Ar number -.Op Fl s Ar Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc +.Op Fl s Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc .Oc .Op Fl r Ar file | Fl w Ar file .Op Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset @@ -292,12 +292,12 @@ When used with no other flags print a se .Pa /bin/sh commands for setting variables to the partition information. This could be used by installation scripts. -.It Fl s Ar id/start/size Ns Bq Ar /bootmenu +.It Fl s Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc Specify the partition .Ar id , .Ar start , .Ar size , -and optionally +and .Ar bootmenu . This flag requires the use of a partition selection flag .Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number .
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Fri Apr 4 13:07:30 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: -s: If the optional arguments are not provided, they stay as before or use the same defaults as the interactive mode, if new. (feel free to improve) To generate a diff of this commit: cvs rdiff -u -r1.84 -r1.85 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.84 src/sbin/fdisk/fdisk.8:1.85 --- src/sbin/fdisk/fdisk.8:1.84 Fri Apr 4 09:32:56 2014 +++ src/sbin/fdisk/fdisk.8 Fri Apr 4 13:07:30 2014 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.84 2014/04/04 09:32:56 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.85 2014/04/04 13:07:30 wiz Exp $ .\ .Dd April 3, 2014 .Dt FDISK 8 @@ -299,6 +299,8 @@ Specify the partition .Ar size , and .Ar bootmenu . +If the optional arguments are not provided, they stay as before or +use the same defaults as the interactive mode, if new. This flag requires the use of a partition selection flag .Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number . .It Fl T Ar disktype
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Fri Apr 4 16:15:30 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: remove debugging. To generate a diff of this commit: cvs rdiff -u -r1.149 -r1.150 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.149 src/sbin/fdisk/fdisk.c:1.150 --- src/sbin/fdisk/fdisk.c:1.149 Thu Apr 3 13:07:11 2014 +++ src/sbin/fdisk/fdisk.c Fri Apr 4 12:15:30 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.149 2014/04/03 17:07:11 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.150 2014/04/04 16:15:30 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.149 2014/04/03 17:07:11 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.150 2014/04/04 16:15:30 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -462,8 +462,6 @@ main(int argc, char *argv[]) if (parse_s(optarg, csysid, cstart, csize, cbootmenu) == -1) errx(1, Bad argument to the -s flag.); - printf(%d %d %d %s\n, csysid, cstart, csize, cbootmenu); - exit(0); break; case 'b': /* BIOS geometry */ b_flag = 1;
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Fri Apr 4 09:32:56 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix a bug in previous and update detailed -s description. To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Fri Apr 4 13:07:30 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: -s: If the optional arguments are not provided, they stay as before or use the same defaults as the interactive mode, if new. (feel free to improve) To generate a diff of this commit: cvs rdiff -u -r1.84 -r1.85 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Fri Apr 4 16:15:30 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: remove debugging. To generate a diff of this commit: cvs rdiff -u -r1.149 -r1.150 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/sbin/fdisk
Module Name: src Committed By: christos Date: Tue Apr 1 19:08:48 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: default to something reasonable (like the interactive mode does) instead of 0 when -1 is specified for the start or size. Could you also update man page? Thanks. --- Izumi Tsutsui
Re: CVS commit: src/sbin/fdisk
On Apr 3, 11:09pm, tsut...@ceres.dti.ne.jp (Izumi Tsutsui) wrote: -- Subject: Re: CVS commit: src/sbin/fdisk | Could you also update man page? Thanks. I did not like the -1 stuff anyway, I wanted to use empty strings instead. But now my nroff foo is not strong enough to handle: [sysid][/[start][/[size][/[bootmenu christos
Re: CVS commit: src/sbin/fdisk
On Thu, Apr 03, 2014 at 01:08:21PM -0400, Christos Zoulas wrote: On Apr 3, 11:09pm, tsut...@ceres.dti.ne.jp (Izumi Tsutsui) wrote: -- Subject: Re: CVS commit: src/sbin/fdisk | Could you also update man page? Thanks. I did not like the -1 stuff anyway, I wanted to use empty strings instead. But now my nroff foo is not strong enough to handle: [sysid][/[start][/[size][/[bootmenu I've tried. Let me know if you want it differently. Thomas
Re: CVS commit: src/sbin/fdisk
On Apr 3, 11:57pm, w...@netbsd.org (Thomas Klausner) wrote: -- Subject: Re: CVS commit: src/sbin/fdisk | On Thu, Apr 03, 2014 at 01:08:21PM -0400, Christos Zoulas wrote: | On Apr 3, 11:09pm, tsut...@ceres.dti.ne.jp (Izumi Tsutsui) wrote: | -- Subject: Re: CVS commit: src/sbin/fdisk | | | Could you also update man page? Thanks. | | I did not like the -1 stuff anyway, I wanted to use empty strings instead. | But now my nroff foo is not strong enough to handle: | | [sysid][/[start][/[size][/[bootmenu | | I've tried. Let me know if you want it differently. Perfect! Thanks, christos
Re: CVS commit: src/sbin/fdisk
In article 20140403215619.a8f1...@cvs.netbsd.org, Thomas Klausner source-changes-d@NetBSD.org wrote: -=-=-=-=-=- Module Name: src Committed By: wiz Date: Thu Apr 3 21:56:19 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Update SYNOPSIS. Christos, please check. Needs the same treatment in .It Fl s... christos
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Thu Apr 3 17:07:11 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: instead of using ugly -1's make args optional To generate a diff of this commit: cvs rdiff -u -r1.148 -r1.149 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.148 src/sbin/fdisk/fdisk.c:1.149 --- src/sbin/fdisk/fdisk.c:1.148 Tue Apr 1 15:08:48 2014 +++ src/sbin/fdisk/fdisk.c Thu Apr 3 13:07:11 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.148 2014/04/01 19:08:48 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.149 2014/04/03 17:07:11 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.148 2014/04/01 19:08:48 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.149 2014/04/03 17:07:11 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -321,6 +321,66 @@ initvar_disk(const char **diskp) #endif /* HAVE_NBTOOL_CONFIG_H */ } +static int +getnum(const char *str, int *num) +{ + char *e; + long l; + + errno = 0; + l = strtol(str, e, 0); + if (str[0] == '\0' || *e != '\0') + return -1; + if (errno == ERANGE (l == LONG_MAX || l == LONG_MIN)) + return -1; + /* XXX: truncation */ + *num = (int)l; + return 0; +} + +/* [sysid][/[start][/[size][/[bootmenu */ +static int +parse_s(char *arg, int *csysid, unsigned *cstart, unsigned *csize, +char **cbootmenu) +{ + char *ptr; + int num; + + if ((ptr = strchr(arg, '/')) != NULL) + *ptr++ = '\0'; + + if (*arg) { + if (getnum(arg, num) == -1) + return -1; + *csysid = num; + } + if (ptr == NULL) + return 0; + + arg = ptr; + if ((ptr = strchr(arg, '/')) != NULL) + *ptr++ = '\0'; + if (*arg) { + if (getnum(arg, num) == -1) + return -1; + *cstart = num; + } + if (ptr == NULL) + return 0; + + arg = ptr; + if ((ptr = strchr(arg, '/')) != NULL) + *ptr++ = '\0'; + if (*arg) { + if (getnum(arg, num) == -1) + return -1; + *csize = num; + } + if (ptr != NULL *ptr) + *cbootmenu = ptr; + return 0; +} + int main(int argc, char *argv[]) { @@ -331,8 +391,8 @@ main(int argc, char *argv[]) int n; #ifdef BOOTSEL daddr_t default_ptn; /* start sector of default ptn */ - char *cbootmenu = 0; #endif + char *cbootmenu = 0; int csysid; /* For the s_flag. */ unsigned int cstart, csize; @@ -340,7 +400,8 @@ main(int argc, char *argv[]) i_flag = B_flag = 0; v_flag = 0; E_flag = 0; - csysid = cstart = csize = 0; + csysid = -1; + cstart = csize = ~0; while ((ch = getopt(argc, argv, OPTIONS)) != -1) { switch (ch) { case '0': @@ -397,18 +458,12 @@ main(int argc, char *argv[]) break; case 's': /* Partition details */ s_flag = 1; - if (sscanf(optarg, %d/%u/%u%n, csysid, cstart, - csize, n) == 3) { -if (optarg[n] == 0) - break; -#ifdef BOOTSEL -if (optarg[n] == '/') { - cbootmenu = optarg + n + 1; - break; -} -#endif - } - errx(1, Bad argument to the -s flag.); + + if (parse_s(optarg, csysid, cstart, csize, + cbootmenu) == -1) +errx(1, Bad argument to the -s flag.); + printf(%d %d %d %s\n, csysid, cstart, csize, cbootmenu); + exit(0); break; case 'b': /* BIOS geometry */ b_flag = 1; @@ -621,7 +676,7 @@ usage(void) [-A ptn_alignment[/ptn_0_offset]] \\\n %*s[-b cylinders/heads/sectors] \\\n %*s[-0123 | -E num - [-s id/start/size[/bootmenu]]] \\\n + [-s [id][/[start][/[size][/bootmenu \\\n %*s[-t disktab] [-T disktype] \\\n %*s[-c bootcode] [-r|-w file] [device]\n
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Thu Apr 3 21:56:19 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Update SYNOPSIS. Christos, please check. To generate a diff of this commit: cvs rdiff -u -r1.82 -r1.83 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.82 src/sbin/fdisk/fdisk.8:1.83 --- src/sbin/fdisk/fdisk.8:1.82 Mon Mar 31 11:25:48 2014 +++ src/sbin/fdisk/fdisk.8 Thu Apr 3 21:56:19 2014 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.82 2014/03/31 11:25:48 martin Exp $ +.\ $NetBSD: fdisk.8,v 1.83 2014/04/03 21:56:19 wiz Exp $ .\ -.Dd October 6, 2013 +.Dd April 3, 2014 .Dt FDISK 8 .Os .Sh NAME @@ -11,7 +11,7 @@ .Op Fl aBFfIiSuv .Oo .Fl 0 | 1 | 2 | 3 | E Ar number -.Op Fl s Ar id/start/size Ns Bq Ar /bootmenu +.Op Fl s Ar Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc .Oc .Op Fl r Ar file | Fl w Ar file .Op Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Thu Apr 3 17:07:11 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: instead of using ugly -1's make args optional To generate a diff of this commit: cvs rdiff -u -r1.148 -r1.149 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Thu Apr 3 21:56:19 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Update SYNOPSIS. Christos, please check. To generate a diff of this commit: cvs rdiff -u -r1.82 -r1.83 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Tue Apr 1 19:08:48 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: default to something reasonable (like the interactive mode does) instead of 0 when -1 is specified for the start or size. To generate a diff of this commit: cvs rdiff -u -r1.147 -r1.148 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.147 src/sbin/fdisk/fdisk.c:1.148 --- src/sbin/fdisk/fdisk.c:1.147 Sun Mar 30 18:18:13 2014 +++ src/sbin/fdisk/fdisk.c Tue Apr 1 15:08:48 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.147 2014/03/30 22:18:13 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.148 2014/04/01 19:08:48 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.147 2014/03/30 22:18:13 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.148 2014/04/01 19:08:48 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -1817,7 +1817,7 @@ check_overlap(int part, int sysid, daddr /* This is just a convention, not a requirement */ return Track zero is reserved for the BIOS; #endif - if (start + size disksectors) + if (start + size disksectors) return Partition exceeds size of disk; for (p = 0; p MBR_PART_COUNT; p++) { if (p == part || mboot.mbr_parts[p].mbrp_type == 0) @@ -2036,10 +2036,16 @@ change_part(int extended, int part, int } else { if (sysid == -1) sysid = partp-mbrp_type; - if (start == (daddr_t)0x) + if (start == (daddr_t)0x) { start = offset + le32toh(partp-mbrp_start); - if (size == (daddr_t)0x) +if (start == 0) + start = offset = ptn_0_offset; + } + if (size == (daddr_t)0x) { size = le32toh(partp-mbrp_size); +if (size == 0) + size = disksectors - start; + } } }
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Tue Apr 1 19:08:48 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: default to something reasonable (like the interactive mode does) instead of 0 when -1 is specified for the start or size. To generate a diff of this commit: cvs rdiff -u -r1.147 -r1.148 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sun Mar 30 22:18:13 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Allow -1 values in the -s sysid/start/size indicate use the previous values. For example: fdisk -f -i /dev/rsd0d # initialize mbr and create an msdos partition. fdisk -f -u -0 -a -s 169/-1/-1 /dev/rsd0d # converts the msdos partition to a netbsd one, and makes it active. To generate a diff of this commit: cvs rdiff -u -r1.146 -r1.147 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.146 src/sbin/fdisk/fdisk.c:1.147 --- src/sbin/fdisk/fdisk.c:1.146 Mon Mar 10 11:42:51 2014 +++ src/sbin/fdisk/fdisk.c Sun Mar 30 18:18:13 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.146 2014/03/10 15:42:51 jakllsch Exp $ */ +/* $NetBSD: fdisk.c,v 1.147 2014/03/30 22:18:13 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.146 2014/03/10 15:42:51 jakllsch Exp $); +__RCSID($NetBSD: fdisk.c,v 1.147 2014/03/30 22:18:13 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -2027,11 +2027,20 @@ change_part(int extended, int part, int tmp_bootmenu[0] = 0; #endif - if (!s_flag partp != NULL) { - /* values not specified, default to current ones */ - sysid = partp-mbrp_type; - start = offset + le32toh(partp-mbrp_start); - size = le32toh(partp-mbrp_size); + if (partp != NULL) { + if (!s_flag) { + /* values not specified, default to current ones */ + sysid = partp-mbrp_type; + start = offset + le32toh(partp-mbrp_start); + size = le32toh(partp-mbrp_size); + } else { + if (sysid == -1) +sysid = partp-mbrp_type; + if (start == (daddr_t)0x) +start = offset + le32toh(partp-mbrp_start); + if (size == (daddr_t)0x) +size = le32toh(partp-mbrp_size); + } } /* creating a new partition, default to free space */
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sun Mar 30 22:18:13 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Allow -1 values in the -s sysid/start/size indicate use the previous values. For example: fdisk -f -i /dev/rsd0d # initialize mbr and create an msdos partition. fdisk -f -u -0 -a -s 169/-1/-1 /dev/rsd0d # converts the msdos partition to a netbsd one, and makes it active. To generate a diff of this commit: cvs rdiff -u -r1.146 -r1.147 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: jakllsch Date: Mon Mar 10 15:42:51 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Always print the MBR drive serial number, even if it's 0. To generate a diff of this commit: cvs rdiff -u -r1.145 -r1.146 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.145 src/sbin/fdisk/fdisk.c:1.146 --- src/sbin/fdisk/fdisk.c:1.145 Sun Apr 14 22:48:22 2013 +++ src/sbin/fdisk/fdisk.c Mon Mar 10 15:42:51 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.145 2013/04/14 22:48:22 jakllsch Exp $ */ +/* $NetBSD: fdisk.c,v 1.146 2014/03/10 15:42:51 jakllsch Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.145 2013/04/14 22:48:22 jakllsch Exp $); +__RCSID($NetBSD: fdisk.c,v 1.146 2014/03/10 15:42:51 jakllsch Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -705,7 +705,7 @@ print_s0(int which) else printf(First active partition: %d\n, active); } - if (!sh_flag mboot.mbr_dsn != 0) + if (!sh_flag) printf(Drive serial number: %PRIu32 (0x%08x)\n, le32toh(mboot.mbr_dsn), le32toh(mboot.mbr_dsn));
CVS commit: src/sbin/fdisk
Module Name:src Committed By: jakllsch Date: Mon Mar 10 15:42:51 UTC 2014 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Always print the MBR drive serial number, even if it's 0. To generate a diff of this commit: cvs rdiff -u -r1.145 -r1.146 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: apb Date: Sun Oct 6 12:27:15 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Suggest using -b 1023/255/63 for modern disks where the BIOS is configured to use LBA-Assisted translation. To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.80 src/sbin/fdisk/fdisk.8:1.81 --- src/sbin/fdisk/fdisk.8:1.80 Sat Oct 6 09:11:34 2012 +++ src/sbin/fdisk/fdisk.8 Sun Oct 6 12:27:15 2013 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.80 2012/10/06 09:11:34 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.81 2013/10/06 12:27:15 apb Exp $ .\ -.Dd April 6, 2012 +.Dd October 6, 2013 .Dt FDISK 8 .Os .Sh NAME @@ -190,6 +190,12 @@ amd64) or by solving the simultaenous eq information. If that fails then either the geometry from the disklabel or 63 sectors and 16 heads is used. +For modern disks larger than about 8GB, and where the BIOS is configured +to use LBA-Assisted translation, a setting of +.Fl b Ar 1023/255/63 +is likely to work. +.\ see http://web.inter.nl.net/hcc/J.Steunebrink/bioslim.htm#LBA +.\ for a table of C/H/S values used in LBA-Assisted translation mode .It Fl c Ar bootcode Specify the filename that .Nm
CVS commit: src/sbin/fdisk
Module Name:src Committed By: apb Date: Sun Oct 6 12:27:15 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Suggest using -b 1023/255/63 for modern disks where the BIOS is configured to use LBA-Assisted translation. To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: jakllsch Date: Sun Apr 14 22:48:22 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Improve support for logical sector sizes greater than 512. To generate a diff of this commit: cvs rdiff -u -r1.144 -r1.145 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.144 src/sbin/fdisk/fdisk.c:1.145 --- src/sbin/fdisk/fdisk.c:1.144 Wed Feb 13 00:40:28 2013 +++ src/sbin/fdisk/fdisk.c Sun Apr 14 22:48:22 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.144 2013/02/13 00:40:28 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.145 2013/04/14 22:48:22 jakllsch Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.144 2013/02/13 00:40:28 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.145 2013/04/14 22:48:22 jakllsch Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -200,7 +200,7 @@ static daddr_t dos_disksectors; #define DOSSECT(s,c) (((s) 0x3f) | (((c) 2) 0xc0)) #define DOSCYL(c) ((c) 0xff) -#define SEC_IN_1M (1024 * 1024 / 512) +#define SEC_IN_1M (1024 * 1024 / secsize) #define SEC_TO_MB(sec) ((unsigned int)(((sec) + SEC_IN_1M / 2) / SEC_IN_1M)) #define SEC_TO_CYL(sec) (((sec) + dos_cylindersectors/2) / dos_cylindersectors) @@ -460,9 +460,6 @@ out: errx(EXIT_FAILURE, Invalid sec continue; if (ch != 1) goto out; - if ((iobuf = malloc(secsize)) == NULL) -err(EXIT_FAILURE, Cannot allocate %zd buffer, -secsize); break; default: usage(); @@ -508,6 +505,12 @@ out: errx(EXIT_FAILURE, Invalid sec if (open_disk(B_flag || a_flag || i_flag || u_flag) 0) exit(1); + if (secsize 512) { + if ((iobuf = malloc(secsize)) == NULL) + err(EXIT_FAILURE, Cannot allocate %zd buffer, + secsize); + } + if (read_s0(0, mboot)) /* must have been a blank disk */ init_sector0(1); @@ -2321,8 +2324,9 @@ print_geometry(void) printf(Disk: %s\n, disk); printf(NetBSD disklabel disk geometry:\n); printf(cylinders: %d, heads: %d, sectors/track: %d - (%d sectors/cylinder)\ntotal sectors: %PRIdaddr\n\n, - cylinders, heads, sectors, cylindersectors, disksectors); + (%d sectors/cylinder)\ntotal sectors: %PRIdaddr, + bytes/sector: %zd\n\n, cylinders, heads, sectors, + cylindersectors, disksectors, secsize); printf(BIOS disk geometry:\n); printf(cylinders: %d, heads: %d, sectors/track: %d (%d sectors/cylinder)\ntotal sectors: %PRIdaddr\n\n, @@ -2488,7 +2492,7 @@ read_disk(daddr_t sector, void *buf) if (*rfd == -1) errx(1, read_disk(); fd == -1); - off_t offs = sector * (off_t)512; + off_t offs = sector * (off_t)secsize; off_t mod = offs (secsize - 1); off_t rnd = offs ~(secsize - 1); @@ -2514,7 +2518,7 @@ write_disk(daddr_t sector, void *buf) if (wfd == -1) errx(1, write_disk(); wfd == -1); - off_t offs = sector * (off_t)512; + off_t offs = sector * (off_t)secsize; off_t mod = offs (secsize - 1); off_t rnd = offs ~(secsize - 1); @@ -2576,6 +2580,7 @@ get_params(void) guess_geometry(disklabel.d_secperunit); disklabel.d_ncylinders = dos_cylinders; disklabel.d_ntracks = dos_heads; + disklabel.d_secsize = 512; disklabel.d_nsectors = dos_sectors; } else if (ioctl(fd, DIOCGDEFLABEL, disklabel) == -1) { warn(DIOCGDEFLABEL); @@ -2588,6 +2593,7 @@ get_params(void) disksectors = disklabel.d_secperunit; cylinders = disklabel.d_ncylinders; heads = disklabel.d_ntracks; + secsize = disklabel.d_secsize; sectors = disklabel.d_nsectors; /* pick up some defaults for the BIOS sizes */
CVS commit: src/sbin/fdisk
Module Name:src Committed By: jakllsch Date: Sun Apr 14 22:48:22 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Improve support for logical sector sizes greater than 512. To generate a diff of this commit: cvs rdiff -u -r1.144 -r1.145 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Wed Feb 13 00:40:29 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Don't produce spurious errors when creating labels on files. To generate a diff of this commit: cvs rdiff -u -r1.143 -r1.144 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.143 src/sbin/fdisk/fdisk.c:1.144 --- src/sbin/fdisk/fdisk.c:1.143 Fri Feb 8 20:50:04 2013 +++ src/sbin/fdisk/fdisk.c Tue Feb 12 19:40:28 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.143 2013/02/09 01:50:04 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.144 2013/02/13 00:40:28 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.143 2013/02/09 01:50:04 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.144 2013/02/13 00:40:28 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -1645,6 +1645,8 @@ intuit_translated_geometry(void) } if (xheads == -1) { + if (F_flag) + return; warnx(Cannot determine the number of heads); return; } @@ -2671,6 +2673,8 @@ read_s0(daddr_t offset, struct mbr_secto return -1; } if (boot-mbr_magic != LE_MBR_MAGIC) { + if (F_flag boot-mbr_magic == 0) + return -1; warnx(%s partition table invalid, no magic in sector %PRIdaddr, tabletype, offset); return -1;
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Wed Feb 13 00:40:29 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Don't produce spurious errors when creating labels on files. To generate a diff of this commit: cvs rdiff -u -r1.143 -r1.144 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sat Feb 9 01:50:04 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.c Log Message: CID/979997: missing va_end() To generate a diff of this commit: cvs rdiff -u -r1.142 -r1.143 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.142 src/sbin/fdisk/fdisk.c:1.143 --- src/sbin/fdisk/fdisk.c:1.142 Tue Jun 5 09:41:23 2012 +++ src/sbin/fdisk/fdisk.c Fri Feb 8 20:50:04 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.142 2012/06/05 13:41:23 tsutsui Exp $ */ +/* $NetBSD: fdisk.c,v 1.143 2013/02/09 01:50:04 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.142 2012/06/05 13:41:23 tsutsui Exp $); +__RCSID($NetBSD: fdisk.c,v 1.143 2013/02/09 01:50:04 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -2769,8 +2769,8 @@ yesno(const char *str, ...) va_list ap; va_start(ap, str); - vprintf(str, ap); + va_end(ap); printf( [n] ); first = ch = getchar();
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sat Feb 9 01:50:04 UTC 2013 Modified Files: src/sbin/fdisk: fdisk.c Log Message: CID/979997: missing va_end() To generate a diff of this commit: cvs rdiff -u -r1.142 -r1.143 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sat Oct 6 09:11:35 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Revert my previous commit, I misunderstood the intention. Noted by njoly. To generate a diff of this commit: cvs rdiff -u -r1.79 -r1.80 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.79 src/sbin/fdisk/fdisk.8:1.80 --- src/sbin/fdisk/fdisk.8:1.79 Fri Oct 5 21:30:29 2012 +++ src/sbin/fdisk/fdisk.8 Sat Oct 6 09:11:34 2012 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.79 2012/10/05 21:30:29 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.80 2012/10/06 09:11:34 wiz Exp $ .\ .Dd April 6, 2012 .Dt FDISK 8 @@ -434,7 +434,8 @@ The various fields in each partition ent .Em ptn_number : id_name (sysid .Em id_number ) -.br +.Ed +.Bd -filled -offset 8n -compact bootmenu: .Em bootmenu .br
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Sat Oct 6 09:11:35 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Revert my previous commit, I misunderstood the intention. Noted by njoly. To generate a diff of this commit: cvs rdiff -u -r1.79 -r1.80 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: njoly Date: Fri Oct 5 18:07:47 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix indented blocks rendering with mandoc. Switch from .in unsupported macro to .Bd/.Ed ones. While here kill some unneeded .Pp/.br macros. To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.77 src/sbin/fdisk/fdisk.8:1.78 --- src/sbin/fdisk/fdisk.8:1.77 Sun Apr 8 22:00:37 2012 +++ src/sbin/fdisk/fdisk.8 Fri Oct 5 18:07:46 2012 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.77 2012/04/08 22:00:37 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.78 2012/10/05 18:07:46 njoly Exp $ .\ .Dd April 6, 2012 .Dt FDISK 8 @@ -138,7 +138,6 @@ Only if you reply affirmatively to this write anything to the disk. .Pp Available options: -.Pp .Bl -tag -width Ds .It Fl 0 Specify partition slot 0 to be printed or updated. @@ -431,13 +430,12 @@ In this case there is no free space in e partition. .Pp The various fields in each partition entry are: -.br -.in +4 +.Bd -filled -offset 4n -compact .Em ptn_number : id_name (sysid .Em id_number ) -.br -.in +4 +.Ed +.Bd -filled -offset 8n -compact bootmenu: .Em bootmenu .br @@ -448,8 +446,7 @@ size MB, Cyls .Em first Ns No - Ns Em next ) .Op , Active -.in -4 -.in -4 +.Ed .Bl -tag -width bootmenu .It Em ptn_number is the number of the partition. @@ -490,7 +487,7 @@ If the .Fl v flag is specified, the beginning and end of each partition are also displayed as follows: -.in +4 +.Bd -filled -offset 4n -compact beg: cylinder .Em cylinder , head @@ -504,7 +501,7 @@ head .Em head , sector .Em sector -.in -4 +.Ed .Bl -tag -width bootmenu .It Em cylinder , Em head , Em sector are the beginning or ending address of a partition.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Fri Oct 5 21:30:29 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Previous slightly more consistently. To generate a diff of this commit: cvs rdiff -u -r1.78 -r1.79 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.78 src/sbin/fdisk/fdisk.8:1.79 --- src/sbin/fdisk/fdisk.8:1.78 Fri Oct 5 18:07:46 2012 +++ src/sbin/fdisk/fdisk.8 Fri Oct 5 21:30:29 2012 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.78 2012/10/05 18:07:46 njoly Exp $ +.\ $NetBSD: fdisk.8,v 1.79 2012/10/05 21:30:29 wiz Exp $ .\ .Dd April 6, 2012 .Dt FDISK 8 @@ -434,8 +434,7 @@ The various fields in each partition ent .Em ptn_number : id_name (sysid .Em id_number ) -.Ed -.Bd -filled -offset 8n -compact +.br bootmenu: .Em bootmenu .br
CVS commit: src/sbin/fdisk
Module Name:src Committed By: njoly Date: Fri Oct 5 18:07:47 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Fix indented blocks rendering with mandoc. Switch from .in unsupported macro to .Bd/.Ed ones. While here kill some unneeded .Pp/.br macros. To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Fri Oct 5 21:30:29 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Previous slightly more consistently. To generate a diff of this commit: cvs rdiff -u -r1.78 -r1.79 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Fri Apr 6 20:09:26 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: support sector sizes 512. To generate a diff of this commit: cvs rdiff -u -r1.75 -r1.76 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.139 -r1.140 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.75 src/sbin/fdisk/fdisk.8:1.76 --- src/sbin/fdisk/fdisk.8:1.75 Wed Jan 4 05:57:40 2012 +++ src/sbin/fdisk/fdisk.8 Fri Apr 6 16:09:26 2012 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.75 2012/01/04 10:57:40 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.76 2012/04/06 20:09:26 christos Exp $ .\ -.Dd December 1, 2011 +.Dd April 6, 2012 .Dt FDISK 8 .Os .Sh NAME @@ -34,6 +34,9 @@ .Op Fl t Ar disktab .Ek .Bk -words +.Op Fl z Ar sectorsize +.Ek +.Bk -words .Op Ar device .Ek .Nm @@ -397,6 +400,10 @@ allows the user to change more parameter Write the modified partition table to file .Ar file instead of the disk. +.It Fl z Ar sectorsize +Specify a sector size other than 512, for devices that only +support larger sector sizes. +The sector size needs to be a power of two greater than 512. .El .Pp When called with no arguments, it prints the partition table. Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.139 src/sbin/fdisk/fdisk.c:1.140 --- src/sbin/fdisk/fdisk.c:1.139 Wed Mar 14 22:02:21 2012 +++ src/sbin/fdisk/fdisk.c Fri Apr 6 16:09:26 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.139 2012/03/15 02:02:21 joerg Exp $ */ +/* $NetBSD: fdisk.c,v 1.140 2012/04/06 20:09:26 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.139 2012/03/15 02:02:21 joerg Exp $); +__RCSID($NetBSD: fdisk.c,v 1.140 2012/04/06 20:09:26 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -155,7 +155,7 @@ static char *boot_path = NULL; /* name #define BOOTSEL_OPTIONS #define change_part(e, p, id, st, sz, bm) change__part(e, p, id, st, sz) #endif -#define OPTIONS BOOTSEL_OPTIONS 0123FSafiIluvA:b:c:E:r:s:w: +#define OPTIONS BOOTSEL_OPTIONS 0123FSafiIluvA:b:c:E:r:s:w:z: /* * Disk geometry and partition alignment. @@ -245,6 +245,8 @@ static int F_flag = 1; static struct gpt_hdr gpt1, gpt2; /* GUID partition tables */ static struct mbr_sector bootcode[8192 / sizeof (struct mbr_sector)]; +static ssize_t secsize = 512; /* sector size */ +static char *iobuf; /* buffer for non 512 sector I/O */ static int bootsize; /* actual size of bootcode */ static int boot_installed; /* 1 if we've copied code into the mbr */ @@ -279,8 +281,8 @@ static void change_active(int); static void change_bios_geometry(void); static void dos(int, unsigned char *, unsigned char *, unsigned char *); static int open_disk(int); -static int read_disk(daddr_t, void *); -static int write_disk(daddr_t, void *); +static ssize_t read_disk(daddr_t, void *); +static ssize_t write_disk(daddr_t, void *); static int get_params(void); static int read_s0(daddr_t, struct mbr_sector *); static int write_mbr(void); @@ -454,6 +456,19 @@ main(int argc, char *argv[]) case 'T': disk_type = optarg; break; + case 'z': + secsize = atoi(optarg); + if (secsize = 512) +out: errx(EXIT_FAILURE, Invalid sector size %zd, +secsize); + for (ch = secsize; (ch 1) == 0; ch = 1) +continue; + if (ch != 1) +goto out; + if ((iobuf = malloc(secsize)) == NULL) +err(EXIT_FAILURE, Cannot allocate %zd buffer, +secsize); + break; default: usage(); } @@ -2468,26 +2483,62 @@ open_disk(int update) return (0); } -static int +static ssize_t read_disk(daddr_t sector, void *buf) { + ssize_t nr; if (*rfd == -1) errx(1, read_disk(); fd == -1); - if (lseek(*rfd, sector * (off_t)512, 0) == -1) - return (-1); - return (read(*rfd, buf, 512)); -} -static int + off_t offs = sector * (off_t)512; + off_t mod = offs (secsize - 1); + off_t rnd = offs ~(secsize - 1); + + if (lseek(*rfd, rnd, SEEK_SET) == (off_t)-1) + return -1; + + if (secsize == 512) + return read(*rfd, buf, 512); + + if ((nr = read(*rfd, iobuf, secsize)) != secsize) + return nr; + + memcpy(buf, iobuf[mod], 512); + + return 512; +} + +static ssize_t write_disk(daddr_t sector, void *buf) { + ssize_t nr; if (wfd == -1) errx(1, write_disk(); wfd == -1); - if (lseek(wfd, sector * (off_t)512, 0) == -1) - return (-1); - return (write(wfd, buf, 512)); + + off_t offs = sector * (off_t)512; + off_t mod = offs (secsize - 1); + off_t rnd = offs ~(secsize - 1); + + if (lseek(wfd, rnd, SEEK_SET) == (off_t)-1) + return -1; + + if (secsize == 512) + return write(wfd, buf, 512); + + if ((nr = read(wfd, iobuf, secsize)) != secsize) + return nr; + + if (lseek(wfd, rnd, SEEK_SET) == (off_t)-1) + return -1; + + memcpy(iobuf[mod], buf,
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Fri Apr 6 20:09:26 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: support sector sizes 512. To generate a diff of this commit: cvs rdiff -u -r1.75 -r1.76 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.139 -r1.140 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Wed Jan 4 10:57:40 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.74 src/sbin/fdisk/fdisk.8:1.75 --- src/sbin/fdisk/fdisk.8:1.74 Sat Dec 31 22:18:56 2011 +++ src/sbin/fdisk/fdisk.8 Wed Jan 4 10:57:40 2012 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.74 2011/12/31 22:18:56 riz Exp $ +.\ $NetBSD: fdisk.8,v 1.75 2012/01/04 10:57:40 wiz Exp $ .\ .Dd December 1, 2011 .Dt FDISK 8 @@ -60,7 +60,7 @@ and (optionally, depending on the boot c for selecting a partition to be booted. There can be at most 4 partitions defined in sector 0, one of which can be an extended -partition which can be split into any number of sub-partitions (then called +partition which can be split into any number of sub-partitions (then called logical partitions). .Pp The boot code in the MBR is usually invoked by the BIOS or firmware, @@ -602,7 +602,7 @@ Default location of i386 bootcode .It Pa /usr/mdec/mbr_bootsel Default location of i386 bootselect code .It Pa /usr/mdec/mbr_ext -Default location of i386 bootselect for extended partitions (i.e., NetBSD on +Default location of i386 bootselect for extended partitions (i.e., NetBSD on logical partitions) .El .Sh EXAMPLES
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Wed Jan 4 10:57:40 UTC 2012 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: riz Date: Sat Dec 31 22:18:56 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: According to most other OSes and documentation sources, an MBR has one extended partition and the partitions inside that are logical partitions. Make fdisk(8) man page follow suit. Patch from Julian Fagir in PR#45695. To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.73 src/sbin/fdisk/fdisk.8:1.74 --- src/sbin/fdisk/fdisk.8:1.73 Thu Dec 1 23:14:06 2011 +++ src/sbin/fdisk/fdisk.8 Sat Dec 31 22:18:56 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.73 2011/12/01 23:14:06 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.74 2011/12/31 22:18:56 riz Exp $ .\ .Dd December 1, 2011 .Dt FDISK 8 @@ -60,7 +60,8 @@ and (optionally, depending on the boot c for selecting a partition to be booted. There can be at most 4 partitions defined in sector 0, one of which can be an extended -partition which can be split into any number of sub-partitions. +partition which can be split into any number of sub-partitions (then called +logical partitions). .Pp The boot code in the MBR is usually invoked by the BIOS or firmware, and the MBR passes control to the next stage boot code @@ -164,7 +165,7 @@ Specify partition slot 2 to be printed o Specify partition slot 3 to be printed or updated. .It Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset Specify the alignment for all partitions and optionally the offset for the -first partition of the disk and of extended partitions. +first partition of the disk and of logical partitions. If .Ar ptn_alignment is specified and @@ -223,11 +224,11 @@ was specified for any partitions on an i386 machine, and leave the bootcode empty for other machines. .It Fl E Ar number -Specify extended partition +Specify logical partition .Ar number to be printed or updated. -If the specified extended partition doesn't exist on updating partition data -an additional extended partition will be created. +If the specified logical partition doesn't exist on updating partition data +an additional logical partition will be created. .It Fl F Indicate that .Ar device @@ -436,7 +437,7 @@ An example follows: .Pp This example disk is divided into four partitions, the last of which is an extended partition. -The sub-partitions of the extended partition are also shown. +The logical partitions of the extended partition are also shown. In this case there is no free space in either the disk or in the extended partition. .Pp @@ -489,7 +490,7 @@ If the partition starts (or ends) on a c sector values are omitted. If .Fl v -is not specified the start of extended partitions and the first partition +is not specified the start of logical partitions and the first partition on the disk are rounded down to include the mandatory red tape in the preceding track. .It Active @@ -601,7 +602,8 @@ Default location of i386 bootcode .It Pa /usr/mdec/mbr_bootsel Default location of i386 bootselect code .It Pa /usr/mdec/mbr_ext -Default location of i386 bootselect for extended partitions +Default location of i386 bootselect for extended partitions (i.e., NetBSD on +logical partitions) .El .Sh EXAMPLES Update MBR partition data of
CVS commit: src/sbin/fdisk
Module Name:src Committed By: riz Date: Sat Dec 31 22:18:56 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: According to most other OSes and documentation sources, an MBR has one extended partition and the partitions inside that are logical partitions. Make fdisk(8) man page follow suit. Patch from Julian Fagir in PR#45695. To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Fri Dec 2 15:21:15 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Also ignore out of space conditions for -I so we can create overlapping partitions on a full disk. Document and add it to the options. To generate a diff of this commit: cvs rdiff -u -r1.137 -r1.138 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Thu Dec 1 22:24:29 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: Add a flag to support writing overlapping partitions and explain why. To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.134 -r1.135 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.71 src/sbin/fdisk/fdisk.8:1.72 --- src/sbin/fdisk/fdisk.8:1.71 Mon Apr 25 18:23:47 2011 +++ src/sbin/fdisk/fdisk.8 Thu Dec 1 17:24:29 2011 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.71 2011/04/25 22:23:47 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.72 2011/12/01 22:24:29 christos Exp $ .\ -.Dd April 6, 2010 +.Dd December 1, 2011 .Dt FDISK 8 .Os .Sh NAME @@ -8,7 +8,7 @@ .Nd MS-DOS partition maintenance program .Sh SYNOPSIS .Nm -.Op Fl aBFfiSuv +.Op Fl aBFfIiSuv .Bk -words .Oo .Fl 0 | 1 | 2 | 3 | E Ar number @@ -270,6 +270,14 @@ and fields .Pq only Ar start No and Ar size No can be specified by Fl s No option . They will be automatically computed using the BIOS geometry. +.It Fl I +Ignore errors from overlapping partitions. +Some devices (cameras CHDK) require overlapping partitions to support +bigger than 4GB cards. +The +.Fl I +flag ignores overlapping error checks and does not fix them, allowing these +incorrect configurations to be used. .It Fl i Explicitly request initialisation of the master boot code (similar to what Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.134 src/sbin/fdisk/fdisk.c:1.135 --- src/sbin/fdisk/fdisk.c:1.134 Sun Aug 28 11:46:26 2011 +++ src/sbin/fdisk/fdisk.c Thu Dec 1 17:24:29 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.134 2011/08/28 15:46:26 gson Exp $ */ +/* $NetBSD: fdisk.c,v 1.135 2011/12/01 22:24:29 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.134 2011/08/28 15:46:26 gson Exp $); +__RCSID($NetBSD: fdisk.c,v 1.135 2011/12/01 22:24:29 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -224,6 +224,7 @@ static char *disk_type = NULL; static int a_flag; /* set active partition */ static int i_flag; /* init bootcode */ +static int I_flag; /* ignore errors */ static int u_flag; /* update partition data */ static int v_flag; /* more verbose */ static int sh_flag; /* Output data as shell defines */ @@ -383,6 +384,9 @@ main(int argc, char *argv[]) case 'i': /* Always update bootcode */ i_flag = 1; break; + case 'I': /* Ignore errors */ + I_flag = 1; + break; case 'l': /* List known partition types */ for (len = 0; len KNOWN_SYSIDS; len++) printf(%03d %s\n, mbr_ptypes[len].id, @@ -2156,7 +2160,7 @@ change_part(int extended, int part, int errtext = check_ext_overlap(part, sysid, start, size, 0); else errtext = check_overlap(part, sysid, start, size, 0); - if (errtext != NULL) { + if (errtext != NULL !I_flag) { if (f_flag) errx(2, %s\n, errtext); printf(%s\n, errtext); @@ -2170,11 +2174,12 @@ change_part(int extended, int part, int * This also fixes the base of each extended partition if the * partition itself has moved. */ - - if (extended) - errtext = check_ext_overlap(part, sysid, start, size, 1); - else - errtext = check_overlap(part, sysid, start, size, 1); + if (!I_flag) { + if (extended) + errtext = check_ext_overlap(part, sysid, start, size, 1); + else + errtext = check_overlap(part, sysid, start, size, 1); + } if (errtext) errx(1, %s\n, errtext);
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Thu Dec 1 23:14:06 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.72 src/sbin/fdisk/fdisk.8:1.73 --- src/sbin/fdisk/fdisk.8:1.72 Thu Dec 1 22:24:29 2011 +++ src/sbin/fdisk/fdisk.8 Thu Dec 1 23:14:06 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.72 2011/12/01 22:24:29 christos Exp $ +.\ $NetBSD: fdisk.8,v 1.73 2011/12/01 23:14:06 wiz Exp $ .\ .Dd December 1, 2011 .Dt FDISK 8 @@ -272,7 +272,7 @@ fields They will be automatically computed using the BIOS geometry. .It Fl I Ignore errors from overlapping partitions. -Some devices (cameras CHDK) require overlapping partitions to support +Some devices (cameras CHDK) require overlapping partitions to support bigger than 4GB cards. The .Fl I
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Fri Dec 2 03:04:11 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: put the error check in the conditional where it belongs. To generate a diff of this commit: cvs rdiff -u -r1.135 -r1.136 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.135 src/sbin/fdisk/fdisk.c:1.136 --- src/sbin/fdisk/fdisk.c:1.135 Thu Dec 1 17:24:29 2011 +++ src/sbin/fdisk/fdisk.c Thu Dec 1 22:04:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.135 2011/12/01 22:24:29 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.136 2011/12/02 03:04:11 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.135 2011/12/01 22:24:29 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.136 2011/12/02 03:04:11 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -2179,10 +2179,10 @@ change_part(int extended, int part, int errtext = check_ext_overlap(part, sysid, start, size, 1); else errtext = check_overlap(part, sysid, start, size, 1); + if (errtext) + errx(1, %s\n, errtext); } - if (errtext) - errx(1, %s\n, errtext); if (sysid == 0) { /* delete this partition - save info though */
CVS commit: src/sbin/fdisk
Module Name:src Committed By: enami Date: Fri Dec 2 04:05:20 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add missing -F flag and -I flag in usage. Sort the order to match manpage. To generate a diff of this commit: cvs rdiff -u -r1.136 -r1.137 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.136 src/sbin/fdisk/fdisk.c:1.137 --- src/sbin/fdisk/fdisk.c:1.136 Fri Dec 2 03:04:11 2011 +++ src/sbin/fdisk/fdisk.c Fri Dec 2 04:05:20 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.136 2011/12/02 03:04:11 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.137 2011/12/02 04:05:20 enami Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.136 2011/12/02 03:04:11 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.137 2011/12/02 04:05:20 enami Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -604,7 +604,7 @@ usage(void) { int indent = 7 + (int)strlen(getprogname()) + 1; - (void)fprintf(stderr, usage: %s [-afiluvBS] + (void)fprintf(stderr, usage: %s [-aBFfIilSuv] [-A ptn_alignment[/ptn_0_offset]] \\\n %*s[-b cylinders/heads/sectors] \\\n %*s[-0123 | -E num
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Thu Dec 1 22:24:29 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: Add a flag to support writing overlapping partitions and explain why. To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.134 -r1.135 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Thu Dec 1 23:14:06 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Fri Dec 2 03:04:11 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: put the error check in the conditional where it belongs. To generate a diff of this commit: cvs rdiff -u -r1.135 -r1.136 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: enami Date: Fri Dec 2 04:05:20 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add missing -F flag and -I flag in usage. Sort the order to match manpage. To generate a diff of this commit: cvs rdiff -u -r1.136 -r1.137 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: gson Date: Sun Aug 28 15:46:26 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: fix the sparc build To generate a diff of this commit: cvs rdiff -u -r1.133 -r1.134 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.133 src/sbin/fdisk/fdisk.c:1.134 --- src/sbin/fdisk/fdisk.c:1.133 Sat Aug 27 20:49:03 2011 +++ src/sbin/fdisk/fdisk.c Sun Aug 28 15:46:26 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.133 2011/08/27 20:49:03 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.134 2011/08/28 15:46:26 gson Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.133 2011/08/27 20:49:03 christos Exp $); +__RCSID($NetBSD: fdisk.c,v 1.134 2011/08/28 15:46:26 gson Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -292,7 +292,6 @@ #define DEC_RND_0 4 /* convert 0 to size of a track */ #define DEC_RND_DOWN 8 /* subtract 1 track */ #define DEC_RND_DOWN_2 16 /* subtract 2 tracks */ -static void string(const char *, int, char *); static int ptn_id(const char *, int *); static int type_match(const void *, const void *); static const char *get_type(int); @@ -302,6 +301,7 @@ static void install_bootsel(int); static daddr_t get_default_boot(void); static void set_default_boot(daddr_t); +static void string(const char *, int, char *); #endif static void
CVS commit: src/sbin/fdisk
Module Name:src Committed By: gson Date: Sun Aug 28 15:46:26 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: fix the sparc build To generate a diff of this commit: cvs rdiff -u -r1.133 -r1.134 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: joerg Date: Sat Aug 27 17:16:01 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: staticfy. __dead. To generate a diff of this commit: cvs rdiff -u -r1.131 -r1.132 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.131 src/sbin/fdisk/fdisk.c:1.132 --- src/sbin/fdisk/fdisk.c:1.131 Sun May 8 14:22:16 2011 +++ src/sbin/fdisk/fdisk.c Sat Aug 27 17:16:01 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.131 2011/05/08 14:22:16 pgoyette Exp $ */ +/* $NetBSD: fdisk.c,v 1.132 2011/08/27 17:16:01 joerg Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.131 2011/05/08 14:22:16 pgoyette Exp $); +__RCSID($NetBSD: fdisk.c,v 1.132 2011/08/27 17:16:01 joerg Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -140,14 +140,14 @@ #define LBUF 100 static char lbuf[LBUF]; -const char *disk = _PATH_DEFDISK; +static const char *disk = _PATH_DEFDISK; -struct disklabel disklabel; /* disk parameters */ +static struct disklabel disklabel; /* disk parameters */ -struct mbr_sector mboot; +static struct mbr_sector mboot; -const char *boot_dir = DEFAULT_BOOTDIR; -char *boot_path = 0; /* name of file we actually opened */ +static const char *boot_dir = DEFAULT_BOOTDIR; +static char *boot_path = NULL; /* name of file we actually opened */ #ifdef BOOTSEL #define BOOTSEL_OPTIONS B @@ -191,15 +191,15 @@ */ /* Disks reported geometry and overall size from device driver */ -unsigned int cylinders, sectors, heads; -daddr_t disksectors; +static unsigned int cylinders, sectors, heads; +static daddr_t disksectors; #define cylindersectors (heads * sectors) /* Geometry from the BIOS */ -unsigned int dos_cylinders; -unsigned int dos_heads; -unsigned int dos_sectors; -daddr_t dos_disksectors; +static unsigned int dos_cylinders; +static unsigned int dos_heads; +static unsigned int dos_sectors; +static daddr_t dos_disksectors; #define dos_cylindersectors (dos_heads * dos_sectors) #define dos_totalsectors (dos_heads * dos_sectors * dos_cylinders) @@ -212,96 +212,96 @@ #define MAXCYL 1024 /* Usual limit is 1023 */ #define MAXHEAD 256 /* Usual limit is 255 */ #define MAXSECTOR 63 -int partition = -1; +static int partition = -1; /* Alignment of partition, and offset if first sector unusable */ -unsigned int ptn_alignment; /* default dos_cylindersectors */ -unsigned int ptn_0_offset; /* default dos_sectors */ +static unsigned int ptn_alignment; /* default dos_cylindersectors */ +static unsigned int ptn_0_offset; /* default dos_sectors */ -int fd = -1, wfd = -1, *rfd = fd; -char *disk_file = NULL; -char *disk_type = NULL; - -int a_flag; /* set active partition */ -int i_flag; /* init bootcode */ -int u_flag; /* update partition data */ -int v_flag; /* more verbose */ -int sh_flag; /* Output data as shell defines */ -int f_flag; /* force --not interactive */ -int s_flag; /* set id,offset,size */ -int b_flag; /* Set cyl, heads, secs (as c/h/s) */ -int B_flag; /* Edit/install bootselect code */ -int E_flag; /* extended partition number */ -int b_cyl, b_head, b_sec; /* b_flag values. */ +static int fd = -1, wfd = -1, *rfd = fd; +static char *disk_file = NULL; +static char *disk_type = NULL; + +static int a_flag; /* set active partition */ +static int i_flag; /* init bootcode */ +static int u_flag; /* update partition data */ +static int v_flag; /* more verbose */ +static int sh_flag; /* Output data as shell defines */ +static int f_flag; /* force --not interactive */ +static int s_flag; /* set id,offset,size */ +static int b_flag; /* Set cyl, heads, secs (as c/h/s) */ +static int B_flag; /* Edit/install bootselect code */ +static int E_flag; /* extended partition number */ +static int b_cyl, b_head, b_sec; /* b_flag values. */ #if !HAVE_NBTOOL_CONFIG_H -int F_flag = 0; +static int F_flag = 0; #else /* Tool - force 'file' mode to avoid unsupported functions and ioctls */ -int F_flag = 1; +static int F_flag = 1; #endif -struct gpt_hdr gpt1, gpt2; /* GUID partition tables */ +static struct gpt_hdr gpt1, gpt2; /* GUID partition tables */ -struct mbr_sector bootcode[8192 / sizeof (struct mbr_sector)]; -int bootsize; /* actual size of bootcode */ -int boot_installed; /* 1 if we've copied code into the mbr */ +static struct mbr_sector bootcode[8192 / sizeof (struct mbr_sector)]; +static int bootsize; /* actual size of bootcode */ +static int boot_installed; /* 1 if we've copied code into the mbr */ #if (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H #define USE_DISKLIST -struct disklist *dl; +static struct disklist *dl; #endif #define KNOWN_SYSIDS (sizeof(mbr_ptypes)/sizeof(mbr_ptypes[0])) -void usage(void); -void print_s0(int); -void print_part(struct
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sat Aug 27 20:49:03 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: one static is enough, otherwise you risk zapping yourself. To generate a diff of this commit: cvs rdiff -u -r1.132 -r1.133 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.132 src/sbin/fdisk/fdisk.c:1.133 --- src/sbin/fdisk/fdisk.c:1.132 Sat Aug 27 13:16:01 2011 +++ src/sbin/fdisk/fdisk.c Sat Aug 27 16:49:03 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.132 2011/08/27 17:16:01 joerg Exp $ */ +/* $NetBSD: fdisk.c,v 1.133 2011/08/27 20:49:03 christos Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.132 2011/08/27 17:16:01 joerg Exp $); +__RCSID($NetBSD: fdisk.c,v 1.133 2011/08/27 20:49:03 christos Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -267,7 +267,7 @@ static void intuit_translated_geometry(void); static void get_bios_geometry(void); static void get_extended_ptn(void); -static static void get_ptn_alignmemt(void); +static void get_ptn_alignmemt(void); #if defined(USE_DISKLIST) static void get_diskname(const char *, char *, size_t); #endif
CVS commit: src/sbin/fdisk
Module Name:src Committed By: joerg Date: Sat Aug 27 17:16:01 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: staticfy. __dead. To generate a diff of this commit: cvs rdiff -u -r1.131 -r1.132 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: christos Date: Sat Aug 27 20:49:03 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: one static is enough, otherwise you risk zapping yourself. To generate a diff of this commit: cvs rdiff -u -r1.132 -r1.133 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: pgoyette Date: Sun May 8 14:22:16 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Fix parsing of -A option so that the [/ptn_0_offset] part is optional, as described in the man page. To generate a diff of this commit: cvs rdiff -u -r1.130 -r1.131 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.130 src/sbin/fdisk/fdisk.c:1.131 --- src/sbin/fdisk/fdisk.c:1.130 Wed Dec 23 18:50:40 2009 +++ src/sbin/fdisk/fdisk.c Sun May 8 14:22:16 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.130 2009/12/23 18:50:40 dsl Exp $ */ +/* $NetBSD: fdisk.c,v 1.131 2011/05/08 14:22:16 pgoyette Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.130 2009/12/23 18:50:40 dsl Exp $); +__RCSID($NetBSD: fdisk.c,v 1.131 2011/05/08 14:22:16 pgoyette Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -418,8 +418,8 @@ b_cyl = MAXCYL; break; case 'A': /* Partition alignment[/offset] */ - if (sscanf(optarg, %u/%u%n, ptn_alignment, -ptn_0_offset, n) 1 + if (sscanf(optarg, %u%n/%u%n, ptn_alignment, +n, ptn_0_offset, n) 1 || optarg[n] != 0 || ptn_0_offset ptn_alignment) errx(1, Bad argument to the -A flag.);
CVS commit: src/sbin/fdisk
Module Name:src Committed By: pgoyette Date: Sun May 8 14:22:16 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Fix parsing of -A option so that the [/ptn_0_offset] part is optional, as described in the man page. To generate a diff of this commit: cvs rdiff -u -r1.130 -r1.131 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Mon Apr 25 22:23:48 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Use Nx. To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.70 src/sbin/fdisk/fdisk.8:1.71 --- src/sbin/fdisk/fdisk.8:1.70 Wed Apr 7 09:40:58 2010 +++ src/sbin/fdisk/fdisk.8 Mon Apr 25 22:23:47 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.70 2010/04/07 09:40:58 wiz Exp $ +.\ $NetBSD: fdisk.8,v 1.71 2011/04/25 22:23:47 wiz Exp $ .\ .Dd April 6, 2010 .Dt FDISK 8 @@ -634,8 +634,9 @@ .Pp .Dl Ic fdisk -f -i -b 130/255/63 -c destdir/usr/mdec/mbr -F diskimg .Pp -Create MBR partition data for slot 0 which has an active NetBSD partition -using whole disk without prompt against 1GB disk image file +Create MBR partition data for slot 0 which has an active +.Nx +partition using whole disk without prompt against 1GB disk image file .Pa diskimg : .Pp .Dl Ic fdisk -f -a -u -0 -s 169/63/2097089 -F diskimg
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Mon Apr 25 22:23:48 UTC 2011 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Use Nx. To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fdisk
Module Name:src Committed By: wiz Date: Wed Apr 7 09:40:58 UTC 2010 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Minor punctuation fixes, improve and sort SYNOPSIS, sort flag descriptions. From Bug Hunting in PR 43130. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.69 src/sbin/fdisk/fdisk.8:1.70 --- src/sbin/fdisk/fdisk.8:1.69 Wed Dec 23 20:56:18 2009 +++ src/sbin/fdisk/fdisk.8 Wed Apr 7 09:40:58 2010 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.69 2009/12/23 20:56:18 dsl Exp $ +.\ $NetBSD: fdisk.8,v 1.70 2010/04/07 09:40:58 wiz Exp $ .\ -.Dd December 23, 2009 +.Dd April 6, 2010 .Dt FDISK 8 .Os .Sh NAME @@ -8,15 +8,15 @@ .Nd MS-DOS partition maintenance program .Sh SYNOPSIS .Nm -.Op Fl afiuvBFS +.Op Fl aBFfiSuv .Bk -words -.Op Fl 0 | 1 | 2 | 3 | E Ar number -.Ek -.Bk -words -.Op Fl t Ar disktab +.Oo +.Fl 0 | 1 | 2 | 3 | E Ar number +.Op Fl s Ar id/start/size Ns Bq Ar /bootmenu +.Oc .Ek .Bk -words -.Op Fl T Ar disktype +.Op Fl r Ar file | Fl w Ar file .Ek .Bk -words .Op Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset @@ -25,13 +25,13 @@ .Op Fl b Ar cylinders/heads/sectors .Ek .Bk -words -.Op Fl s Ar id/start/size Ns Bq Ar /bootmenu +.Op Fl c Ar bootcode .Ek .Bk -words -.Op Fl c Ar bootcode +.Op Fl T Ar disktype .Ek .Bk -words -.Op Fl r|w Ar file +.Op Fl t Ar disktab .Ek .Bk -words .Op Ar device @@ -89,7 +89,7 @@ The standard MBR boot code will only boot the .Sq active partition. -However +However, .Nx contains additional boot programs which allow the user to interactively select which of the partitions to boot. @@ -162,10 +162,6 @@ Specify partition slot 2 to be printed or updated. .It Fl 3 Specify partition slot 3 to be printed or updated. -.It Fl a -Change the active partition. -In interactive mode this question will be asked after the partitions -have been processed. .It Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset Specify the alignment for all partitions and optionally the offset for the first partition of the disk and of extended partitions. @@ -185,6 +181,16 @@ In all other cases the alignment default to a cylinder and the offset to a track (both using the BIOS geometry). The 1MB alignment is the same as that used by recent windows versions. +.It Fl a +Change the active partition. +In interactive mode this question will be asked after the partitions +have been processed. +.It Fl B +On an i386 or amd64 system, interactively update the boot selector settings. +(The boot selector permits the user to interactively select the boot +partition, and thus which operating system is run, at system boot time; see +.Xr mbr 8 +for more information.) .It Fl b Ar cylinders/heads/sectors Specify the BIOS geometry parameters for .Ar cylinders , @@ -199,13 +205,6 @@ information. If that fails then either the geometry from the disklabel or 63 sectors and 16 heads is used. -.It Fl B -On an i386 or amd64 system, interactively update the boot selector settings. -(The boot selector permits the user to interactively select the boot -partition, and thus which operating system is run, at system boot time. -See -.Xr mbr 8 -for more information.) .It Fl c Ar bootcode Specify the filename that .Nm @@ -229,6 +228,25 @@ to be printed or updated. If the specified extended partition doesn't exist on updating partition data an additional extended partition will be created. +.It Fl F +Indicate that +.Ar device +is a regular file. +Unless the geometry of +.Ar device +is told to +.Nm +by +.Fl T Ar disktype , +.Nm +will count the 512-byte sectors in +.Ar device +and produce a fake geometry. +If +.Ar device +is a regular file, +.Fl F +will be used implicitly. .It Fl f Run .Nm @@ -252,25 +270,6 @@ fields .Pq only Ar start No and Ar size No can be specified by Fl s No option . They will be automatically computed using the BIOS geometry. -.It Fl F -Indicate that -.Ar device -is a regular file. -Unless the geometry of -.Ar device -is told to -.Nm -by -.Fl T Ar disktype , -.Nm -will count the 512-byte sectors in -.Ar device -and produce a fake geometry. -If -.Ar device -is a regular file, -.Fl F -will be used implicitly. .It Fl i Explicitly request initialisation of the master boot code (similar to what @@ -289,6 +288,11 @@ instead of the specified disk. The geometry information used is still that of the disk volume. Any changes are written back to the file. +.It Fl S +When used with no other flags print a series of +.Pa /bin/sh +commands for setting variables to the partition information. +This could be used by installation scripts. .It Fl s Ar id/start/size Ns Bq Ar /bootmenu Specify the partition .Ar id , @@ -298,11 +302,11 @@ .Ar bootmenu . This flag requires the use of a partition selection flag .Pq Fl 0 , 1 , 2 , 3
CVS commit: src/sbin/fdisk
Module Name:src Committed By: dsl Date: Wed Dec 23 18:50:40 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Put #endif in correct place - fixes PR/42500 Update usage() for -A, and rename one of the variables for clarity. To generate a diff of this commit: cvs rdiff -u -r1.129 -r1.130 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.129 src/sbin/fdisk/fdisk.c:1.130 --- src/sbin/fdisk/fdisk.c:1.129 Tue Dec 22 21:55:12 2009 +++ src/sbin/fdisk/fdisk.c Wed Dec 23 18:50:40 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.129 2009/12/22 21:55:12 dsl Exp $ */ +/* $NetBSD: fdisk.c,v 1.130 2009/12/23 18:50:40 dsl Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.129 2009/12/22 21:55:12 dsl Exp $); +__RCSID($NetBSD: fdisk.c,v 1.130 2009/12/23 18:50:40 dsl Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -216,7 +216,7 @@ /* Alignment of partition, and offset if first sector unusable */ unsigned int ptn_alignment; /* default dos_cylindersectors */ -unsigned int ptn_offset; /* default dos_sectors */ +unsigned int ptn_0_offset; /* default dos_sectors */ int fd = -1, wfd = -1, *rfd = fd; char *disk_file = NULL; @@ -248,6 +248,7 @@ int boot_installed; /* 1 if we've copied code into the mbr */ #if (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H +#define USE_DISKLIST struct disklist *dl; #endif @@ -267,9 +268,9 @@ void get_bios_geometry(void); void get_extended_ptn(void); static void get_ptn_alignmemt(void); -#if (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H +#if defined(USE_DISKLIST) void get_diskname(const char *, char *, size_t); -#endif /* (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H */ +#endif int change_part(int, int, int, daddr_t, daddr_t, char *); void print_geometry(void); int first_active(void); @@ -418,12 +419,12 @@ break; case 'A': /* Partition alignment[/offset] */ if (sscanf(optarg, %u/%u%n, ptn_alignment, -ptn_offset, n) 1 +ptn_0_offset, n) 1 || optarg[n] != 0 - || ptn_offset ptn_alignment) + || ptn_0_offset ptn_alignment) errx(1, Bad argument to the -A flag.); - if (ptn_offset == 0) -ptn_offset = ptn_alignment; + if (ptn_0_offset == 0) +ptn_0_offset = ptn_alignment; break; case 'c': /* file/directory containing boot code */ if (strchr(optarg, '/') != NULL @@ -600,7 +601,8 @@ int indent = 7 + (int)strlen(getprogname()) + 1; (void)fprintf(stderr, usage: %s [-afiluvBS] - [-b cylinders/heads/sectors] \\\n + [-A ptn_alignment[/ptn_0_offset]] \\\n + %*s[-b cylinders/heads/sectors] \\\n %*s[-0123 | -E num [-s id/start/size[/bootmenu]]] \\\n %*s[-t disktab] [-T disktype] \\\n @@ -616,7 +618,7 @@ \t-F treat device as a regular file\n \t-S output as shell defines\n \t-r and -w access 'file' for non-destructive testing\n, - getprogname(), indent, , indent, , indent, ); + getprogname(), indent, , indent, , indent, , indent, ); exit(1); } @@ -801,8 +803,8 @@ indent, , start, size); if (size != 0) { printf( (%u MB, Cyls , SEC_TO_MB(size)); - if (v_flag == 0 le32toh(partp-mbrp_start) == ptn_offset) - pr_cyls(start - ptn_offset, 0); + if (v_flag == 0 le32toh(partp-mbrp_start) == ptn_0_offset) + pr_cyls(start - ptn_0_offset, 0); else pr_cyls(start, 0); printf(-); @@ -1132,7 +1134,7 @@ ext.num_ptn = 0; } -#if (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H +#if defined(USE_DISKLIST) void get_diskname(const char *fullname, char *diskname, size_t size) { @@ -1174,6 +1176,7 @@ memcpy(diskname, p, len); diskname[len] = 0; } +#endif static void get_ptn_alignmemt(void) @@ -1183,7 +1186,7 @@ /* Default to using 'traditional' cylinder alignment */ ptn_alignment = dos_cylindersectors; - ptn_offset = dos_sectors; + ptn_0_offset = dos_sectors; if (partp-mbrp_type != 0) { /* Try to copy alignment of first partition */ @@ -1195,14 +1198,14 @@ if (ptn_0_base = 2048 !(ptn_0_base (ptn_0_base - 1))) { /* ptn_base is a power of 2, use it */ -ptn_offset = ptn_0_base; +ptn_0_offset = ptn_0_base; } } } else { /* Use 1MB alignment for large disks */ if (disksectors 2048 * 1024 * 128) { ptn_alignment = 2048; - ptn_offset = 2048; + ptn_0_offset = 2048; } } } @@ -1210,7 +1213,7 @@ void get_bios_geometry(void) { -#if (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H +#if defined(USE_DISKLIST) int mib[2], i; size_t len; struct biosdisk_info *bip; @@ -1258,7 +1261,6 @@ /* Allright, allright, make a stupid guess.. */ intuit_translated_geometry(); } -#endif /* (defined(__i386__) ||
CVS commit: src/sbin/fdisk
Module Name:src Committed By: dsl Date: Wed Dec 23 20:56:18 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Add info for -A ptn_alignment[/ptn_0_offset] To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.68 src/sbin/fdisk/fdisk.8:1.69 --- src/sbin/fdisk/fdisk.8:1.68 Thu Dec 17 14:27:49 2009 +++ src/sbin/fdisk/fdisk.8 Wed Dec 23 20:56:18 2009 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.68 2009/12/17 14:27:49 pooka Exp $ +.\ $NetBSD: fdisk.8,v 1.69 2009/12/23 20:56:18 dsl Exp $ .\ -.Dd December 17, 2009 +.Dd December 23, 2009 .Dt FDISK 8 .Os .Sh NAME @@ -10,7 +10,7 @@ .Nm .Op Fl afiuvBFS .Bk -words -.Op Fl 0 | 1 | 2 | 3 +.Op Fl 0 | 1 | 2 | 3 | E Ar number .Ek .Bk -words .Op Fl t Ar disktab @@ -19,7 +19,7 @@ .Op Fl T Ar disktype .Ek .Bk -words -.Op Fl E Ar number +.Op Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset .Ek .Bk -words .Op Fl b Ar cylinders/heads/sectors @@ -166,8 +166,27 @@ Change the active partition. In interactive mode this question will be asked after the partitions have been processed. +.It Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset +Specify the alignment for all partitions and optionally the offset for the +first partition of the disk and of extended partitions. +If +.Ar ptn_alignment +is specified and +.Ar ptn_0_offset +is not specified, then the offset is set to the alignment. +If +.Fl A +isn't specified, then the alignment of the first partition is inspected. +If it ends on a 2048 sector boundary, then the alignment is set to 2048, +if the start is a power of 2 less than, or equal to 2048 then the offset +is set to the start sector. +If the first partition isn't defined then the alignment and offset for disks +larger than 128GB is set to 2048 (1MB). +In all other cases the alignment default to a cylinder +and the offset to a track (both using the BIOS geometry). +The 1MB alignment is the same as that used by recent windows versions. .It Fl b Ar cylinders/heads/sectors -Specify the BIOS parameters for +Specify the BIOS geometry parameters for .Ar cylinders , .Ar heads , and @@ -175,6 +194,11 @@ It is used only in conjunction with the .Fl u flag. +If not specified the BIOS geometry will be obtained using sysctl (i386 and +amd64) or by solving the simultaenous equations from the existing partition +information. +If that fails then either the geometry from the disklabel or 63 sectors and +16 heads is used. .It Fl B On an i386 or amd64 system, interactively update the boot selector settings. (The boot selector permits the user to interactively select the boot
CVS commit: src/sbin/fdisk
Module Name:src Committed By: dsl Date: Tue Dec 22 21:04:38 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Editing partitions larger than 1TB works better if 'decimal' returns 64 bit integer values! To generate a diff of this commit: cvs rdiff -u -r1.127 -r1.128 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.127 src/sbin/fdisk/fdisk.c:1.128 --- src/sbin/fdisk/fdisk.c:1.127 Sun Dec 20 17:32:09 2009 +++ src/sbin/fdisk/fdisk.c Tue Dec 22 21:04:37 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.127 2009/12/20 17:32:09 dsl Exp $ */ +/* $NetBSD: fdisk.c,v 1.128 2009/12/22 21:04:37 dsl Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.127 2009/12/20 17:32:09 dsl Exp $); +__RCSID($NetBSD: fdisk.c,v 1.128 2009/12/22 21:04:37 dsl Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -284,7 +284,7 @@ int read_gpt(daddr_t, struct gpt_hdr *); int delete_gpt(struct gpt_hdr *); int yesno(const char *, ...); -int decimal(const char *, int64_t, int, int64_t, int64_t); +int64_t decimal(const char *, int64_t, int, int64_t, int64_t); #define DEC_SEC 1 /* asking for a sector number */ #define DEC_RND 2 /* round to end of first track */ #define DEC_RND_0 4 /* round 0 to size of a track */ @@ -2682,7 +2682,7 @@ return (first == 'y' || first == 'Y'); } -int +int64_t decimal(const char *prompt, int64_t dflt, int flags, int64_t minval, int64_t maxval) { int64_t acc = 0;
CVS commit: src/sbin/fdisk
Module Name:src Committed By: dsl Date: Tue Dec 22 21:55:12 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add support for partition being aligned on non-cylinder boundaries. Info can be specified with -A parameter. Default is based on how the first partition is defined. For empty disks larger than 128GB (arbitrary figure) use 1MB alignment. To generate a diff of this commit: cvs rdiff -u -r1.128 -r1.129 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.128 src/sbin/fdisk/fdisk.c:1.129 --- src/sbin/fdisk/fdisk.c:1.128 Tue Dec 22 21:04:37 2009 +++ src/sbin/fdisk/fdisk.c Tue Dec 22 21:55:12 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.128 2009/12/22 21:04:37 dsl Exp $ */ +/* $NetBSD: fdisk.c,v 1.129 2009/12/22 21:55:12 dsl Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.128 2009/12/22 21:04:37 dsl Exp $); +__RCSID($NetBSD: fdisk.c,v 1.129 2009/12/22 21:55:12 dsl Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -150,12 +150,12 @@ char *boot_path = 0; /* name of file we actually opened */ #ifdef BOOTSEL - -#define OPTIONS 0123BFSafiluvs:b:c:E:r:w:t:T: +#define BOOTSEL_OPTIONS B #else +#define BOOTSEL_OPTIONS #define change_part(e, p, id, st, sz, bm) change__part(e, p, id, st, sz) -#define OPTIONS 0123FSafiluvs:b:c:E:r:w: #endif +#define OPTIONS BOOTSEL_OPTIONS 0123FSafiluvA:b:c:E:r:s:w: /* * Disk geometry and partition alignment. @@ -215,8 +215,8 @@ int partition = -1; /* Alignment of partition, and offset if first sector unusable */ -#define ptn_alignment dos_cylindersectors -#define ptn_offset dos_sectors +unsigned int ptn_alignment; /* default dos_cylindersectors */ +unsigned int ptn_offset; /* default dos_sectors */ int fd = -1, wfd = -1, *rfd = fd; char *disk_file = NULL; @@ -264,16 +264,17 @@ int read_boot(const char *, void *, size_t, int); void init_sector0(int); void intuit_translated_geometry(void); -void get_geometry(void); +void get_bios_geometry(void); void get_extended_ptn(void); +static void get_ptn_alignmemt(void); #if (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H void get_diskname(const char *, char *, size_t); #endif /* (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H */ int change_part(int, int, int, daddr_t, daddr_t, char *); -void print_params(void); +void print_geometry(void); int first_active(void); void change_active(int); -void get_params_to_use(void); +void change_bios_geometry(void); void dos(int, unsigned char *, unsigned char *, unsigned char *); int open_disk(int); int read_disk(daddr_t, void *); @@ -287,7 +288,7 @@ int64_t decimal(const char *, int64_t, int, int64_t, int64_t); #define DEC_SEC 1 /* asking for a sector number */ #define DEC_RND 2 /* round to end of first track */ -#define DEC_RND_0 4 /* round 0 to size of a track */ +#define DEC_RND_0 4 /* convert 0 to size of a track */ #define DEC_RND_DOWN 8 /* subtract 1 track */ #define DEC_RND_DOWN_2 16 /* subtract 2 tracks */ void string(const char *, int, char *); @@ -341,7 +342,7 @@ v_flag = 0; E_flag = 0; csysid = cstart = csize = 0; - while ((ch = getopt(argc, argv, OPTIONS)) != -1) + while ((ch = getopt(argc, argv, OPTIONS)) != -1) { switch (ch) { case '0': partition = 0; @@ -415,6 +416,15 @@ if (b_cyl MAXCYL) b_cyl = MAXCYL; break; + case 'A': /* Partition alignment[/offset] */ + if (sscanf(optarg, %u/%u%n, ptn_alignment, +ptn_offset, n) 1 + || optarg[n] != 0 + || ptn_offset ptn_alignment) +errx(1, Bad argument to the -A flag.); + if (ptn_offset == 0) +ptn_offset = ptn_alignment; + break; case 'c': /* file/directory containing boot code */ if (strchr(optarg, '/') != NULL stat(optarg, sb) == 0 @@ -442,6 +452,7 @@ default: usage(); } + } argc -= optind; argv += optind; @@ -489,11 +500,17 @@ read_gpt(GPT_HDR_BLKNO, gpt1); read_gpt(disksectors - 1, gpt2); -#if (defined(__i386__) || defined(__x86_64__)) !HAVE_NBTOOL_CONFIG_H - get_geometry(); -#else - intuit_translated_geometry(); -#endif + if (b_flag) { + dos_cylinders = b_cyl; + dos_heads = b_head; + dos_sectors = b_sec; + } else { + get_bios_geometry(); + } + + if (ptn_alignment == 0) + get_ptn_alignmemt(); + get_extended_ptn(); #ifdef BOOTSEL @@ -503,11 +520,11 @@ if (E_flag !u_flag partition = ext.num_ptn) errx(1, Extended partition %d is not defined., partition); - if (u_flag (!f_flag || b_flag)) - get_params_to_use(); - /* Do the update stuff! */ if (u_flag) { + if (!f_flag !b_flag) + change_bios_geometry(); + if (s_flag) change_part(E_flag, partition, csysid, cstart, csize, cbootmenu); @@ -527,11 +544,12 @@ prompt =
CVS commit: src/sbin/fdisk
Module Name:src Committed By: dsl Date: Sun Dec 20 17:32:09 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.c Log Message: Add a large comment about disk geometries. Rename (with #defines) the variables use for aligning partitions to separate them from the bios geometry. All in advance of allowing other partition alignments (eg 2048 sectors). To generate a diff of this commit: cvs rdiff -u -r1.126 -r1.127 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.126 src/sbin/fdisk/fdisk.c:1.127 --- src/sbin/fdisk/fdisk.c:1.126 Thu Dec 17 14:27:49 2009 +++ src/sbin/fdisk/fdisk.c Sun Dec 20 17:32:09 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.126 2009/12/17 14:27:49 pooka Exp $ */ +/* $NetBSD: fdisk.c,v 1.127 2009/12/20 17:32:09 dsl Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.126 2009/12/17 14:27:49 pooka Exp $); +__RCSID($NetBSD: fdisk.c,v 1.127 2009/12/20 17:32:09 dsl Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -120,9 +120,6 @@ #define GPT_TYPE(offs) ((offs) == GPT_HDR_BLKNO ? primary : secondary) -#define LBUF 100 -static char lbuf[LBUF]; - #ifndef PRIdaddr #define PRIdaddr PRId64 #endif @@ -131,17 +128,6 @@ #define _PATH_DEFDISK /dev/rwd0d #endif -const char *disk = _PATH_DEFDISK; - -struct disklabel disklabel; /* disk parameters */ - -unsigned int cylinders, sectors, heads; -daddr_t disksectors; -#define cylindersectors (heads * sectors) - -struct mbr_sector mboot; - - struct { struct mbr_sector *ptn; /* array of pbrs */ daddr_t base; /* first sector of ext. ptn */ @@ -151,6 +137,15 @@ int is_corrupt; /* 1 if extended chain illegal */ } ext; +#define LBUF 100 +static char lbuf[LBUF]; + +const char *disk = _PATH_DEFDISK; + +struct disklabel disklabel; /* disk parameters */ + +struct mbr_sector mboot; + const char *boot_dir = DEFAULT_BOOTDIR; char *boot_path = 0; /* name of file we actually opened */ @@ -162,6 +157,45 @@ #define OPTIONS 0123FSafiluvs:b:c:E:r:w: #endif +/* + * Disk geometry and partition alignment. + * + * Modern disks do not have a fixed geomery and will always give a 'faked' + * geometry that matches the ATA standard - max 16 heads and 256 sec/track. + * The ATA geometry allows access to 2^28 sectors (as does LBA mode). + * + * The BIOS calls originally used an 8bit register for cylinder, head and + * sector. Later 2 bits were stolen from the sector number and added to + * cylinder number. The BIOS will translate this faked geometry either to + * the geometry reported by the disk, or do LBA reads (possibly LBA48). + * BIOS CHS reads have all sorts of limits, but 2^24 is absolute. + * For historic reasons the BIOS geometry is the called the dos geometry! + * + * If you know the disks real geometry it is usually worth aligning + * disk partitions to cylinder boundaries (certainly traditional!). + * For 'mbr' disks this has always been done with the BIOS geometry. + * The first track (typically 63 sectors) is reserved because the first + * sector is used for boot code. Similarly the data partition in an + * extended partition will start one track in. If an extended partition + * starts at the beginning of the disk you lose 2 tracks. + * + * However non-magnetic media in particular has physical sectors that are + * not the same size as those reported, so has to do read modify write + * sequences for misaligned transfers. The alignment of partitions to + * cylinder boundaries makes this happen all the time. + * + * It is thus sensible to align partitions on a sensible sector boundary. + * For instance 1MB (2048 sectors). + * Common code can do this by using a geometry with 1 head and 2048 + * sectors per track. + */ + +/* Disks reported geometry and overall size from device driver */ +unsigned int cylinders, sectors, heads; +daddr_t disksectors; +#define cylindersectors (heads * sectors) + +/* Geometry from the BIOS */ unsigned int dos_cylinders; unsigned int dos_heads; unsigned int dos_sectors; @@ -180,6 +214,10 @@ #define MAXSECTOR 63 int partition = -1; +/* Alignment of partition, and offset if first sector unusable */ +#define ptn_alignment dos_cylindersectors +#define ptn_offset dos_sectors + int fd = -1, wfd = -1, *rfd = fd; char *disk_file = NULL; char *disk_type = NULL; @@ -745,8 +783,8 @@ indent, , start, size); if (size != 0) { printf( (%u MB, Cyls , SEC_TO_MB(size)); - if (v_flag == 0 le32toh(partp-mbrp_start) == dos_sectors) - pr_cyls(start - dos_sectors, 0); + if (v_flag == 0 le32toh(partp-mbrp_start) == ptn_offset) + pr_cyls(start - ptn_offset, 0); else pr_cyls(start, 0); printf(-); @@ -1676,8 +1714,8 @@ partp = ext.ptn[part - 1].mbr_parts[1]; ext.ptn[part].mbr_parts[1] = *partp; /* and prev onto us */ -
CVS commit: src/sbin/fdisk
Module Name:src Committed By: pooka Date: Thu Dec 17 14:27:49 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: Use implicit -F for regular files, much like disklabel(8). To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.125 -r1.126 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.67 src/sbin/fdisk/fdisk.8:1.68 --- src/sbin/fdisk/fdisk.8:1.67 Sat Dec 5 16:29:11 2009 +++ src/sbin/fdisk/fdisk.8 Thu Dec 17 14:27:49 2009 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.67 2009/12/05 16:29:11 pooka Exp $ +.\ $NetBSD: fdisk.8,v 1.68 2009/12/17 14:27:49 pooka Exp $ .\ -.Dd November 28, 2009 +.Dd December 17, 2009 .Dt FDISK 8 .Os .Sh NAME @@ -242,6 +242,11 @@ will count the 512-byte sectors in .Ar device and produce a fake geometry. +If +.Ar device +is a regular file, +.Fl F +will be used implicitly. .It Fl i Explicitly request initialisation of the master boot code (similar to what Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.125 src/sbin/fdisk/fdisk.c:1.126 --- src/sbin/fdisk/fdisk.c:1.125 Wed Nov 4 22:25:56 2009 +++ src/sbin/fdisk/fdisk.c Thu Dec 17 14:27:49 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.125 2009/11/04 22:25:56 dsl Exp $ */ +/* $NetBSD: fdisk.c,v 1.126 2009/12/17 14:27:49 pooka Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fdisk.c,v 1.125 2009/11/04 22:25:56 dsl Exp $); +__RCSID($NetBSD: fdisk.c,v 1.126 2009/12/17 14:27:49 pooka Exp $); #endif /* not lint */ #define MBRPTYPENAMES @@ -438,6 +438,9 @@ initvar_disk(disk); } + if (!F_flag stat(disk, sb) == 0 S_ISREG(sb.st_mode)) + F_flag = 1; + if (open_disk(B_flag || a_flag || i_flag || u_flag) 0) exit(1);
CVS commit: src/sbin/fdisk
Module Name:src Committed By: tsutsui Date: Sat Nov 28 16:45:20 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Clarify description of -f and -u options. (-u means updating partition data, not interactive mode) To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.63 src/sbin/fdisk/fdisk.8:1.64 --- src/sbin/fdisk/fdisk.8:1.63 Wed Oct 14 22:00:55 2009 +++ src/sbin/fdisk/fdisk.8 Sat Nov 28 16:45:20 2009 @@ -1,6 +1,6 @@ -.\ $NetBSD: fdisk.8,v 1.63 2009/10/14 22:00:55 joerg Exp $ +.\ $NetBSD: fdisk.8,v 1.64 2009/11/28 16:45:20 tsutsui Exp $ .\ -.Dd August 10, 2009 +.Dd November 28, 2009 .Dt FDISK 8 .Os .Sh NAME @@ -155,13 +155,13 @@ .Pp .Bl -tag -width Ds .It Fl 0 -Update partition slot 0. +Specify partition slot 0 to be printed or updated. .It Fl 1 -Update partition slot 1. +Specify partition slot 1 to be printed or updated. .It Fl 2 -Update partition slot 2. +Specify partition slot 2 to be printed or updated. .It Fl 3 -Update partition slot 3. +Specify partition slot 3 to be printed or updated. .It Fl a Change the active partition. In interactive mode this question will be asked after the partitions @@ -200,10 +200,11 @@ on an i386 machine, and leave the bootcode empty for other machines. .It Fl E Ar number -Update extended partition -.Ar number . -If the specified extended partition doesn't exist an additional extended -partition will be created. +Specify extended partition +.Ar number +to be printed or updated. +If the specified extended partition doesn't exist on updating partition data +an additional extended partition will be created. .It Fl f Run .Nm @@ -224,16 +225,9 @@ .Ar head , and .Ar sector -fields. +fields +.Pq only Ar start No and Ar size No can be specified by Fl s No option . They will be automatically computed using the BIOS geometry. -.Pp -If -.Fl u -and -.Fl s -are specified then the details of the specified partition will be changed. -Any other partitions which overlap the requested part of the disk will be -silently deleted. .It Fl F Indicate that .Ar device @@ -274,14 +268,7 @@ and optionally .Ar bootmenu . This flag requires the use of a partition selection flag -.Po -.Fl 0 , -.Fl 1 , -.Fl 2 , -.Fl 3 , -or -.Fl E Ar number -.Pc +.Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number . .It Fl S When used with no other flags print a series of .Pa /bin/sh @@ -300,7 +287,15 @@ instead of the disklabel on .Ar device . .It Fl u -Display the partitions and interactively ask which one you want to edit. +Update partition data, including +.Em id , start , No and Em size . +Unless +.Fl f +option +.Pq non-interactive mode +is specified, +.Nm +will display the partitions and interactively ask which one you want to edit. .Nm will step through each field showing the old value and asking for a new one. The @@ -316,8 +311,25 @@ .Em $ in which case the partition will extend to the end of the available free space. .Pp +In a non-interactive mode +.Pq specified by Fl f No option , +partition data should be specified by +.Fl s +option. +A partition selection option +.Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number +should also be specified to select a partition slot to be updated. +.Pp .Nm will not allow you to create partitions which overlap. +If +.Fl u +and +.Fl s +are specified in a non-interactive mode +then the details of the specified partition will be changed. +Any other partitions which overlap the requested part of the disk will be +silently deleted. .Pp If .Em bootmenu
CVS commit: src/sbin/fdisk
Module Name:src Committed By: tsutsui Date: Sat Nov 28 17:25:46 UTC 2009 Modified Files: src/sbin/fdisk: fdisk.8 Log Message: Update -u usage to follow changes in fdisk.c rev 1.125: Allow MB, GB and CYL (not just M, G and C) and lower case. Don't output a splurious 'd' before cyl. Fixes PR/37414. XXX NNcy is also allowed? To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/sbin/fdisk/fdisk.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.64 src/sbin/fdisk/fdisk.8:1.65 --- src/sbin/fdisk/fdisk.8:1.64 Sat Nov 28 16:45:20 2009 +++ src/sbin/fdisk/fdisk.8 Sat Nov 28 17:25:45 2009 @@ -1,4 +1,4 @@ -.\ $NetBSD: fdisk.8,v 1.64 2009/11/28 16:45:20 tsutsui Exp $ +.\ $NetBSD: fdisk.8,v 1.65 2009/11/28 17:25:45 tsutsui Exp $ .\ .Dd November 28, 2009 .Dt FDISK 8 @@ -302,8 +302,10 @@ .Em start and .Em size -can be specified in blocks (nn), cylinders (nnc), megabytes (nnm), -or gigabytes (nng), values in megabytes and gigabytes +can be specified in blocks (NN), +cylinders (NNc or NNcyl), +megabytes (NNm or NNMB), +or gigabytes (NNg or NNGB), values in megabytes and gigabytes will be rounded to the nearest cylinder boundary. The .Em size