Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/gpt PR/43105: Peter Kerwien: Destroying a GPT partition...



details:   https://anonhg.NetBSD.org/src/rev/2f45572baf5c
branches:  trunk
changeset: 753566:2f45572baf5c
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Apr 02 13:36:59 2010 +0000

description:
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.

diffstat:

 sbin/gpt/gpt.c |  25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diffs (78 lines):

diff -r a3ef4cceec77 -r 2f45572baf5c sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c    Fri Apr 02 03:46:50 2010 +0000
+++ b/sbin/gpt/gpt.c    Fri Apr 02 13:36:59 2010 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index