Module Name: src
Committed By: riz
Date: Sun Nov 21 21:59:38 UTC 2010
Modified Files:
src/sbin/gpt [netbsd-5]: gpt.c
Log Message:
Pull up following revision(s) (requested by christos in ticket #1464):
sbin/gpt/gpt.c: revision 1.11
PR/43105: Peter Kerwien: Destroying a GPT partition with dd will cause gpt
destroy / create to fail. When reading the GPT label from the end of the disk
ignore errors if the GPT label at the beginning of the disk was not found.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.8.6.1 src/sbin/gpt/gpt.c
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/gpt.c
diff -u src/sbin/gpt/gpt.c:1.8 src/sbin/gpt/gpt.c:1.8.6.1
--- src/sbin/gpt/gpt.c:1.8 Sun Feb 24 18:38:10 2008
+++ src/sbin/gpt/gpt.c Sun Nov 21 21:59:38 2010
@@ -31,7 +31,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.8 2008/02/24 18:38:10 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.8.6.1 2010/11/21 21:59:38 riz Exp $");
#endif
#include <sys/param.h>
@@ -560,7 +560,7 @@
#endif
static int
-gpt_gpt(int fd, off_t lba)
+gpt_gpt(int fd, off_t lba, int found)
{
uuid_t type;
off_t size;
@@ -593,8 +593,15 @@
/* Use generic pointer to deal with hdr->hdr_entsz != sizeof(*ent). */
p = gpt_read(fd, le64toh(hdr->hdr_lba_table), blocks);
- if (p == NULL)
- return (-1);
+ if (p == NULL) {
+ if (found) {
+ if (verbose)
+ warn("%s: Cannot read LBA table at sector %llu",
+ device_name, le64toh(hdr->hdr_lba_table));
+ return (-1);
+ }
+ goto fail_hdr;
+ }
if (crc32(p, tblsz) != le32toh(hdr->hdr_crc_table)) {
if (verbose)
@@ -619,7 +626,7 @@
return (-1);
if (lba != 1)
- return (0);
+ return (1);
for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
ent = (void*)(p + i * le32toh(hdr->hdr_entsz));
@@ -643,7 +650,7 @@
return (-1);
m->map_index = i + 1;
}
- return (0);
+ return (1);
fail_ent:
free(p);
@@ -657,7 +664,7 @@
gpt_open(const char *dev)
{
struct stat sb;
- int fd, mode;
+ int fd, mode, found;
mode = readonly ? O_RDONLY : O_RDWR|O_EXCL;
@@ -723,9 +730,9 @@
if (gpt_mbr(fd, 0LL) == -1)
goto close;
- if (gpt_gpt(fd, 1LL) == -1)
+ if ((found = gpt_gpt(fd, 1LL, 1)) == -1)
goto close;
- if (gpt_gpt(fd, mediasz / secsz - 1LL) == -1)
+ if (gpt_gpt(fd, mediasz / secsz - 1LL, found) == -1)
goto close;
return (fd);