Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/gpt merge the create errors in one place and fix them.
details: https://anonhg.NetBSD.org/src/rev/544df21433a0
branches: trunk
changeset: 341914:544df21433a0
user: christos <christos%NetBSD.org@localhost>
date: Sun Nov 29 00:14:46 2015 +0000
description:
merge the create errors in one place and fix them.
diffstat:
sbin/gpt/add.c | 8 +--
sbin/gpt/backup.c | 8 +--
sbin/gpt/biosboot.c | 10 +--
sbin/gpt/create.c | 8 +--
sbin/gpt/destroy.c | 16 +++--
sbin/gpt/gpt.c | 119 +++++++++++++++++++++++++++++++++----------------
sbin/gpt/gpt.h | 7 ++-
sbin/gpt/header.c | 8 +--
sbin/gpt/label.c | 8 +--
sbin/gpt/migrate.c | 8 +--
sbin/gpt/recover.c | 8 +--
sbin/gpt/remove.c | 8 +--
sbin/gpt/resize.c | 8 +--
sbin/gpt/resizedisk.c | 8 +--
sbin/gpt/restore.c | 8 +--
sbin/gpt/set.c | 8 +--
sbin/gpt/show.c | 8 +--
sbin/gpt/type.c | 8 +--
sbin/gpt/unset.c | 8 +--
19 files changed, 142 insertions(+), 130 deletions(-)
diffs (truncated from 724 to 300 lines):
diff -r 034052017fc5 -r 544df21433a0 sbin/gpt/add.c
--- a/sbin/gpt/add.c Sat Nov 28 23:53:48 2015 +0000
+++ b/sbin/gpt/add.c Sun Nov 29 00:14:46 2015 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: add.c,v 1.27 2014/09/30 17:59:59 christos Exp $");
+__RCSID("$NetBSD: add.c,v 1.28 2015/11/29 00:14:46 christos Exp $");
#endif
#include <sys/types.h>
@@ -272,11 +272,9 @@
}
while (optind < argc) {
- fd = gpt_open(argv[optind++]);
- if (fd == -1) {
- warn("unable to open device '%s'", device_name);
+ fd = gpt_open(argv[optind++], 0);
+ if (fd == -1)
continue;
- }
if (alignment % secsz != 0) {
warnx("Alignment must be a multiple of sector size;");
diff -r 034052017fc5 -r 544df21433a0 sbin/gpt/backup.c
--- a/sbin/gpt/backup.c Sat Nov 28 23:53:48 2015 +0000
+++ b/sbin/gpt/backup.c Sun Nov 29 00:14:46 2015 +0000
@@ -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.8 2014/09/30 17:59:59 christos Exp $");
+__RCSID("$NetBSD: backup.c,v 1.9 2015/11/29 00:14:46 christos Exp $");
#endif
#include <sys/bootblock.h>
@@ -296,11 +296,9 @@
usage_backup();
while (optind < argc) {
- fd = gpt_open(argv[optind++]);
- if (fd == -1) {
- warn("unable to open device '%s'", device_name);
+ fd = gpt_open(argv[optind++], 0);
+ if (fd == -1)
continue;
- }
backup();
gpt_close(fd);
diff -r 034052017fc5 -r 544df21433a0 sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c Sat Nov 28 23:53:48 2015 +0000
+++ b/sbin/gpt/biosboot.c Sun Nov 29 00:14:46 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: biosboot.c,v 1.14 2014/10/03 20:30:06 christos Exp $ */
+/* $NetBSD: biosboot.c,v 1.15 2015/11/29 00:14:46 christos Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.14 2014/10/03 20:30:06 christos Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.15 2015/11/29 00:14:46 christos Exp $");
#endif
#include <sys/stat.h>
@@ -335,12 +335,10 @@
close:
close(fd);
- fd = gpt_open(dev);
+ fd = gpt_open(dev, 0);
next:
- if (fd == -1) {
- warn("unable to open device '%s'", device_name);
+ if (fd == -1)
continue;
- }
biosboot(fd);
diff -r 034052017fc5 -r 544df21433a0 sbin/gpt/create.c
--- a/sbin/gpt/create.c Sat Nov 28 23:53:48 2015 +0000
+++ b/sbin/gpt/create.c Sun Nov 29 00:14:46 2015 +0000
@@ -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: create.c,v 1.12 2014/10/03 20:30:06 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.13 2015/11/29 00:14:46 christos Exp $");
#endif
#include <sys/types.h>
@@ -235,11 +235,9 @@
usage_create();
while (optind < argc) {
- fd = gpt_open(argv[optind++]);
- if (fd == -1) {
- warn("unable to open device '%s'", device_name);
+ fd = gpt_open(argv[optind++], force);
+ if (fd == -1)
continue;
- }
create(fd);
diff -r 034052017fc5 -r 544df21433a0 sbin/gpt/destroy.c
--- a/sbin/gpt/destroy.c Sat Nov 28 23:53:48 2015 +0000
+++ b/sbin/gpt/destroy.c Sun Nov 29 00:14:46 2015 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/destroy.c,v 1.6 2005/08/31 01:47:19 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: destroy.c,v 1.6 2014/09/29 21:04:34 christos Exp $");
+__RCSID("$NetBSD: destroy.c,v 1.7 2015/11/29 00:14:46 christos Exp $");
#endif
#include <sys/types.h>
@@ -49,8 +49,9 @@
#include "gpt.h"
static int recoverable;
+static int force;
-const char destroymsg[] = "destroy [-r] device ...";
+const char destroymsg[] = "destroy [-rf] device ...";
__dead static void
usage_destroy(void)
@@ -95,8 +96,11 @@
{
int ch, fd;
- while ((ch = getopt(argc, argv, "r")) != -1) {
+ while ((ch = getopt(argc, argv, "fr")) != -1) {
switch(ch) {
+ case 'f':
+ force = 1;
+ break;
case 'r':
recoverable = 1;
break;
@@ -109,11 +113,9 @@
usage_destroy();
while (optind < argc) {
- fd = gpt_open(argv[optind++]);
- if (fd == -1) {
- warn("unable to open device '%s'", device_name);
+ fd = gpt_open(argv[optind++], force);
+ if (fd == -1)
continue;
- }
destroy(fd);
diff -r 034052017fc5 -r 544df21433a0 sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c Sat Nov 28 23:53:48 2015 +0000
+++ b/sbin/gpt/gpt.c Sun Nov 29 00:14:46 2015 +0000
@@ -35,7 +35,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: gpt.c,v 1.41 2015/11/03 02:19:24 jnemeth Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.42 2015/11/29 00:14:46 christos Exp $");
#endif
#include <sys/param.h>
@@ -49,6 +49,7 @@
#include <fcntl.h>
#include <paths.h>
#include <stddef.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -67,7 +68,7 @@
u_int parts;
u_int secsz;
-int readonly, verbose;
+int readonly, verbose, quiet;
static uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
@@ -283,13 +284,15 @@
unsigned int i, pmbr;
mbr = gpt_read(fd, lba, 1);
- if (mbr == NULL)
+ if (mbr == NULL) {
+ if (!quiet)
+ warn("%s: read failed", device_name);
return (-1);
+ }
if (mbr->mbr_sig != htole16(MBR_SIG)) {
if (verbose)
- warnx("%s: MBR not found at sector %llu", device_name,
- (long long)lba);
+ gpt_msg("MBR not found at sector %ju", (uintmax_t)lba);
free(mbr);
return (0);
}
@@ -309,20 +312,19 @@
break;
}
if (pmbr && i == 4 && lba == 0) {
- if (pmbr != 1)
- warnx("%s: Suspicious PMBR at sector %llu",
- device_name, (long long)lba);
+ if (pmbr != 1 && !quiet)
+ warnx("%s: Suspicious PMBR at sector %ju",
+ device_name, (uintmax_t)lba);
else if (verbose > 1)
- warnx("%s: PMBR at sector %llu", device_name,
- (long long)lba);
+ gpt_msg("PMBR at sector %ju", (uintmax_t)lba);
p = map_add(lba, 1LL, MAP_TYPE_PMBR, mbr);
return ((p == NULL) ? -1 : 0);
}
- if (pmbr)
- warnx("%s: Suspicious MBR at sector %llu", device_name,
- (long long)lba);
+ if (pmbr && !quiet)
+ warnx("%s: Suspicious MBR at sector %ju", device_name,
+ (uintmax_t)lba);
else if (verbose > 1)
- warnx("%s: MBR at sector %llu", device_name, (long long)lba);
+ gpt_msg("MBR at sector %ju", (uintmax_t)lba);
p = map_add(lba, 1LL, MAP_TYPE_MBR, mbr);
if (p == NULL)
@@ -343,9 +345,9 @@
/* start is relative to the offset of the MBR itself. */
start += lba;
if (verbose > 2)
- warnx("%s: MBR part: type=%d, start=%llu, size=%llu",
- device_name, mbr->mbr_part[i].part_typ,
- (long long)start, (long long)size);
+ gpt_msg("MBR part: type=%d, start=%ju, size=%ju",
+ mbr->mbr_part[i].part_typ,
+ (uintmax_t)start, (uintmax_t)size);
if (mbr->mbr_part[i].part_typ != MBR_PTYPE_EXT_LBA) {
m = map_add(start, size, MAP_TYPE_MBR_PART, p);
if (m == NULL)
@@ -461,7 +463,7 @@
}
int
-gpt_open(const char *dev)
+gpt_open(const char *dev, int flags)
{
struct stat sb;
int fd, mode, found;
@@ -470,27 +472,48 @@
device_arg = device_name = dev;
fd = opendisk(dev, mode, device_path, sizeof(device_path), 0);
- if (fd == -1)
+ if (fd == -1) {
+ if (!quiet)
+ warn("Cannot open `%s'", device_name);
return -1;
- if (strncmp(device_path, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- device_name = device_path + strlen(_PATH_DEV);
- else
- device_name = device_path;
+ }
+ device_name = device_path;
- if (fstat(fd, &sb) == -1)
+ if (fstat(fd, &sb) == -1) {
+ if (!quiet)
+ warn("Cannot stat `%s'", device_name);
goto close;
+ }
if ((sb.st_mode & S_IFMT) != S_IFREG) {
-#ifdef DIOCGSECTORSIZE
- if ((secsz == 0 && ioctl(fd, DIOCGSECTORSIZE, &secsz) == -1) ||
- (mediasz == 0 && ioctl(fd, DIOCGMEDIASIZE, &mediasz) == -1))
- goto close;
-#else
- if (getdisksize(device_name, &secsz, &mediasz) == -1)
- goto close;
-#endif
- if (secsz == 0 || mediasz == 0)
- errx(1, "Please specify sector/media size");
+ if (secsz == 0) {
+ if (ioctl(fd, DIOCGSECTORSIZE, &secsz) == -1) {
+ if (!quiet)
+ warn("Cannot get sector size for `%s'",
+ device_name);
+ goto close;
Home |
Main Index |
Thread Index |
Old Index