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
This commit is contained in:
Maxim Konovalov 2007-04-30 18:29:36 +00:00
parent a7b27253d0
commit 7914c60f5a
2 changed files with 36 additions and 4 deletions

View File

@ -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

View File

@ -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);
}