summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2007-04-30 18:29:36 +0000
committermaxim <maxim@FreeBSD.org>2007-04-30 18:29:36 +0000
commit24e3ce108a904527e77cb4fbbaac2ae1c12bf0ce (patch)
tree161e16a849fb933f927ae2ff7fa1692cef3fb3c5 /sbin
parentc0dd4e798d02065ab87dcf8e939ec5985f3c6317 (diff)
downloadFreeBSD-src-24e3ce108a904527e77cb4fbbaac2ae1c12bf0ce.zip
FreeBSD-src-24e3ce108a904527e77cb4fbbaac2ae1c12bf0ce.tar.gz
o Add -p flag: print a slice table in fdisk configuration file format.
Now it is possible to do something like fdisk -p ad0 | fdisk -f - ad1. PR: bin/110182 Submitted by: Jukka A. Ukkonen MFC after: 1 month
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fdisk/fdisk.810
-rw-r--r--sbin/fdisk/fdisk.c30
2 files changed, 36 insertions, 4 deletions
diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8
index 78eafa7..562adbb 100644
--- a/sbin/fdisk/fdisk.8
+++ b/sbin/fdisk/fdisk.8
@@ -1,6 +1,6 @@
.\" $FreeBSD$
.\"
-.Dd December 12, 2006
+.Dd April 30, 2007
.Dt FDISK 8
.Os
.Sh NAME
@@ -8,7 +8,7 @@
.Nd PC slice table maintenance utility
.Sh SYNOPSIS
.Nm
-.Op Fl BIaistu
+.Op Fl BIaipstu
.Op Fl b Ar bootcode
.Op Fl 1234
.Op Ar disk
@@ -109,6 +109,12 @@ Initialize sector 0 slice table
for one
.Fx
slice covering the entire disk.
+.It Fl p
+Print a slice table in
+.Nm
+configuration file format and exit; see
+.Sx CONFIGURATION FILE ,
+below.
.It Fl s
Print summary information and exit.
.It Fl t
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index 142cf13..fab164b 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -120,6 +120,7 @@ static int s_flag = 0; /* Print a summary and exit */
static int t_flag = 0; /* test only */
static char *f_flag = NULL; /* Read config info from file */
static int v_flag = 0; /* Be verbose */
+static int print_config_flag = 0;
static struct part_type
{
@@ -247,7 +248,7 @@ main(int argc, char *argv[])
int partition = -1;
struct dos_partition *partp;
- while ((c = getopt(argc, argv, "BIab:f:istuv1234")) != -1)
+ while ((c = getopt(argc, argv, "BIab:f:ipstuv1234")) != -1)
switch (c) {
case 'B':
B_flag = 1;
@@ -267,6 +268,9 @@ main(int argc, char *argv[])
case 'i':
i_flag = 1;
break;
+ case 'p':
+ print_config_flag = 1;
+ break;
case 's':
s_flag = 1;
break;
@@ -322,6 +326,28 @@ main(int argc, char *argv[])
free(mboot.bootinst);
mboot.bootinst = NULL;
+ if (print_config_flag) {
+ if (read_s0())
+ err(1, "read_s0");
+
+ printf("# %s\n", disk);
+ printf("g c%d h%d s%d\n", dos_cyls, dos_heads, dos_sectors);
+
+ for (i = 0; i < NDOSPART; i++) {
+ partp = ((struct dos_partition *)&mboot.parts) + i;
+
+ if (partp->dp_start == 0 && partp->dp_size == 0)
+ continue;
+
+ printf("p %d 0x%02x %lu %lu\n", i + 1, partp->dp_typ,
+ (u_long)partp->dp_start, (u_long)partp->dp_size);
+
+ /* Fill flags for the partition. */
+ if (partp->dp_flag & 0x80)
+ printf("a %d\n", i + 1);
+ }
+ exit(0);
+ }
if (s_flag) {
if (read_s0())
err(1, "read_s0");
@@ -413,7 +439,7 @@ static void
usage()
{
fprintf(stderr, "%s%s",
- "usage: fdisk [-BIaistu] [-b bootcode] [-1234] [disk]\n",
+ "usage: fdisk [-BIaipstu] [-b bootcode] [-1234] [disk]\n",
" fdisk -f configfile [-itv] [disk]\n");
exit(1);
}
OpenPOWER on IntegriCloud