NetBSD-Bugs archive

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

Re: bin/57410: gpt silently exits if file isn't an integral multiple of 512 bytes long



The following reply was made to PR bin/57410; it has been noted by GNATS.

From: mlelstv%serpens.de@localhost (Michael van Elst)
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/57410: gpt silently exits if file isn't an integral multiple of 512 bytes long
Date: Tue, 16 May 2023 05:24:32 -0000 (UTC)

 mp%petermann-it.de@localhost writes:
 
 >In a file image there is a GPT. When I try to display it with "gpt show file.img", gpt exits with error code 1 without any further output.
 
 >Riastradh could conclude that it might be because the size of my image file is not a multiple of 512. The file was exactly one byte too big with 17179869185 bytes. After a truncate to 17179869184 the GPT was output correctly.
 
 
 Indeed. There are many cases, where the gpt tool fails silently when it cannot
 read the GPT, some problems are printed with -v. This seems to be intentional.
 
 
 Maybe this (untested):
 
 ndex: gpt.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/gpt/gpt.c,v
 retrieving revision 1.84
 diff -p -u -r1.84 gpt.c
 --- gpt.c       22 Nov 2022 00:25:52 -0000      1.84
 +++ gpt.c       16 May 2023 05:23:40 -0000
 @@ -386,8 +386,10 @@ gpt_gpt(gpt_t gpt, off_t lba, int found)
         uint32_t crc;
  
         hdr = gpt_read(gpt, lba, 1);
 -       if (hdr == NULL)
 +       if (hdr == NULL) {
 +               gpt_warn(gpt, "Read failed");
                 return -1;
 +       }
  
         if (memcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)))
                 goto fail_hdr;
 @@ -540,6 +542,7 @@ gpt_open(const char *dev, int flags, int
                         gpt->secsz = 512;       /* Fixed size for files. */
                 if (gpt->mediasz == 0) {
                         if (gpt->sb.st_size % gpt->secsz) {
 +                               gpt_warn(gpt, "Media size not a multiple of sector size (%u)\n", gpt->secsz);
                                 errno = EINVAL;
                                 goto close;
                         }
 @@ -602,6 +605,8 @@ gpt_open(const char *dev, int flags, int
         if (gpt->fd != -1)
                 close(gpt->fd);
         free(gpt);
 +       if (!(flags & GPT_QUIET))
 +               gpt_warn("No GPT found");
         return NULL;
  }
 
 


Home | Main Index | Thread Index | Old Index