NetBSD-Bugs archive

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

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



>Number:         57410
>Category:       bin
>Synopsis:       gpt silently exits if file isn't an integral multiple of 512 bytes long
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 16 00:30:00 +0000 2023
>Originator:     Matthias Petermann
>Release:        NetBSD-10.0_BETA
>Organization:
>Environment:
NetBSD vhost2.local 10.0_BETA NetBSD 10.0_BETA (XEN3_DOM0) #0: Mon May  8 07:40:40 UTC 2023  root@ws.local:/build/netbsd-10/obj/sys/arch/amd64/compile/XEN3_DOM0 amd64
>Description:
This is a follow up to a discussion on IRC #netbsd. Once again, many thanks to Riastradh :-)

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.
>How-To-Repeat:
vhost2$ doas dd if=/dev/zero of=test3.img bs=1 count=1 seek=16g
vhost2$ stat -s test3.img                                                                                   
st_dev=43011 st_ino=8479504 st_mode=0100644 st_nlink=1 st_uid=0 st_gid=0 st_rdev=-1 st_size=17179869185 st_atime=1684224662 st_mtime=1684224651 st_ctime=1684224651 st_birthtime=1684224587 st_blksize=32768 st_blocks=320 st_flags=0
vhost2$ doas vnconfig vnd0 test3.img                                                                        
vhost2$ doas gpt create vnd0
vhost2$ doas gpt show vnd0
     start      size  index  contents
         0         1         PMBR
         1         1         Pri GPT header
         2        32         Pri GPT table
        34  33554365         Unused
  33554399        32         Sec GPT table
  33554431         1         Sec GPT header
vhost2$ doas vnconfig -u vnd0
vhost2$ doas gpt show test3.img                                                                             
vhost2$ echo $?
1
vhost2$ cat truncate.c                                                                                      
#include <unistd.h> 

int main(void)
{
   truncate("test3.img", 17179869184); 
}
vhost2$ doas truncate 
vhost2$ doas gpt show test3.img
     start      size  index  contents
         0         1         PMBR
         1         1         Pri GPT header
         2        32         Pri GPT table
        34  33554365         Unused
  33554399        32         Sec GPT table
  33554431         1         Sec GPT header
>Fix:
First, I should improve my method of creating the file images. I suspect that the byte overage is due to my dd command. I would have to specify the seek parameter in bytes instead of the human readable unit and subtract one from that.

In addition, it would of course be nice if gpt could handle such a case similarly to when the secondary GPT table is not present (I seem to recall that a meaningful error message appears in that case?).



Home | Main Index | Thread Index | Old Index