Module Name: src Committed By: christos Date: Fri Apr 2 13:36:59 UTC 2010
Modified Files: src/sbin/gpt: gpt.c Log Message: 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.10 -r1.11 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.10 src/sbin/gpt/gpt.c:1.11 --- src/sbin/gpt/gpt.c:1.10 Sat Feb 20 03:47:10 2010 +++ src/sbin/gpt/gpt.c Fri Apr 2 09:36:59 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.10 2010/02/20 08:47:10 mlelstv Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.11 2010/04/02 13:36:59 christos Exp $"); #endif #include <sys/param.h> @@ -561,7 +561,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; @@ -594,8 +594,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) @@ -620,7 +627,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)); @@ -644,7 +651,7 @@ return (-1); m->map_index = i + 1; } - return (0); + return (1); fail_ent: free(p); @@ -658,7 +665,7 @@ gpt_open(const char *dev) { struct stat sb; - int fd, mode; + int fd, mode, found; mode = readonly ? O_RDONLY : O_RDWR|O_EXCL; @@ -724,9 +731,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);