summaryrefslogtreecommitdiffstats
path: root/sbin/fdisk/fdisk.c
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/fdisk/fdisk.c
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/fdisk/fdisk.c')
-rw-r--r--sbin/fdisk/fdisk.c30
1 files changed, 28 insertions, 2 deletions
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