Module Name: src Committed By: christos Date: Wed Dec 2 12:36:53 UTC 2015
Modified Files: src/sbin/gpt: backup.c gpt.8 restore.c Log Message: Allow backup and restore to operate on files. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/backup.c src/sbin/gpt/restore.c cvs rdiff -u -r1.40 -r1.41 src/sbin/gpt/gpt.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/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.12 src/sbin/gpt/backup.c:1.13 --- src/sbin/gpt/backup.c:1.12 Tue Dec 1 23:06:47 2015 +++ src/sbin/gpt/backup.c Wed Dec 2 07:36:53 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.12 2015/12/02 04:06:47 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.13 2015/12/02 12:36:53 christos Exp $"); #endif #include <sys/bootblock.h> @@ -51,9 +51,10 @@ __RCSID("$NetBSD: backup.c,v 1.12 2015/1 #include "gpt.h" #include "gpt_private.h" +static const char *outfile = "/dev/stdout"; static const char *backuphelp[] = { - "", + "[-o outfile]", }; static int cmd_backup(gpt_t, int, char *[]); @@ -251,6 +252,7 @@ backup(gpt_t gpt) prop_number_t propnum; char *propext; bool rc; + FILE *fp; props = prop_dictionary_create(); PROP_ERR(props); @@ -307,7 +309,12 @@ backup(gpt_t gpt) propext = prop_dictionary_externalize(props); PROP_ERR(propext); prop_object_release(props); - fputs(propext, stdout); + if ((fp = fopen(outfile, "w")) == NULL) { + gpt_warn(gpt, "Can't open `%s'", outfile); + return -1; + } + fputs(propext, fp); + fclose(fp); free(propext); return 0; } @@ -315,6 +322,17 @@ backup(gpt_t gpt) static int cmd_backup(gpt_t gpt, int argc, char *argv[]) { + int ch; + + while ((ch = getopt(argc, argv, "o:")) != -1) { + switch(ch) { + case 'o': + outfile = optarg; + break; + default: + return usage(); + } + } if (argc != optind) return usage(); Index: src/sbin/gpt/restore.c diff -u src/sbin/gpt/restore.c:1.12 src/sbin/gpt/restore.c:1.13 --- src/sbin/gpt/restore.c:1.12 Tue Dec 1 23:07:11 2015 +++ src/sbin/gpt/restore.c Wed Dec 2 07:36:53 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: restore.c,v 1.12 2015/12/02 04:07:11 christos Exp $"); +__RCSID("$NetBSD: restore.c,v 1.13 2015/12/02 12:36:53 christos Exp $"); #endif #include <sys/types.h> @@ -57,9 +57,11 @@ static int force; static int cmd_restore(gpt_t, int, char *[]); static const char *restorehelp[] = { - "[-F]", + "[-F] [-i <infile>]", }; +static const char *infile = "/dev/stdin"; + struct gpt_cmd c_restore = { "restore", cmd_restore, @@ -113,7 +115,7 @@ restore(gpt_t gpt) map->map_type = MAP_TYPE_UNUSED; } - props = prop_dictionary_internalize_from_file("/dev/stdin"); + props = prop_dictionary_internalize_from_file(infile); if (props == NULL) { gpt_warnx(gpt, "Unable to read/parse backup file"); return -1; @@ -396,8 +398,11 @@ cmd_restore(gpt_t gpt, int argc, char *a { int ch; - while ((ch = getopt(argc, argv, "F")) != -1) { + while ((ch = getopt(argc, argv, "Fi:")) != -1) { switch(ch) { + case 'i': + infile = optarg; + break; case 'F': force = 1; break; Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.40 src/sbin/gpt/gpt.8:1.41 --- src/sbin/gpt/gpt.8:1.40 Tue Dec 1 17:49:25 2015 +++ src/sbin/gpt/gpt.8 Wed Dec 2 07:36:53 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.40 2015/12/01 22:49:25 christos Exp $ +.\" $NetBSD: gpt.8,v 1.41 2015/12/02 12:36:53 christos Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -199,11 +199,13 @@ NetBSD swap .El as aliases for the most commonly used partition types. .\" ==== backup ==== -.It Nm Ic backup +.It Nm Ic backup Oo Fl o Ar outfile Oc The .Ic backup command dumps the MBR or (PMBR) and GPT partition tables to standard -output in a format to be used by the +output or to a file specified by the +.Ar outfile +argument in a format to be used by the .Ic restore command. The format is a plist. @@ -465,14 +467,16 @@ Using the option allows you to move the backup copy prior to resizing the medium. This is primarily useful when shrinking the medium. .\" ==== restore ==== -.It Nm Ic restore Oo Fl F Oc +.It Nm Ic restore Oo Fl F Oc Oo Fl i Ar infile Oc The .Ic restore command restores a partition table that was previously saved using the .Ic backup command. -The partition table is read from standard input and is expected to be in -the format of a plist. +The partition table is read from standard input or a file specified in +the +.Ar infile +argument and is expected to be in the format of a plist. It assumes an empty disk. The .Fl F