git: gpt(8): Skip GPT header probe when MBR is present

Aaron LI aly at crater.dragonflybsd.org
Wed Feb 18 06:32:43 PST 2026


commit 4a92b9c1252f2f85571045054a2831d16cc2013b
Author: Aaron LI <aly at aaronly.me>
Date:   Thu Feb 12 12:48:45 2026 +0800

    gpt(8): Skip GPT header probe when MBR is present
    
    gpt_open() previously probed the GPT header even when an MBR was
    present.  When opening a disk that had been initialized with
    "fdisk -I" (converting it from GPT to MBR), this caused errors in
    map_add(), as shown:
    
        % sudo ./gpt -vv show da8
        gpt show: da8: mediasize=180045766656; sectorsize=512; blocks=351651888
        gpt show: da8: MBR at sector 0
        gpt show: da8: Primary GPT at sector 1
        gpt show: error: map entry doesn't fit media: new_start + new_size < start + size (34 + 29 < 40 + 409600)
        gpt show: unable to open device 'da8': Undefined error: 0
    
    After this change, gpt(8) correctly treats the disk as MBR-only and
    displays the partition table:
    
        % sudo ./gpt -vv show da8
        gpt show: da8: mediasize=180045766656; sectorsize=512; blocks=351651888
        gpt show: da8: MBR at sector 0
        Disk da8: 168GB (351651888 512-byte sectors)
              Start    Sectors    Size  Index  Contents
                  0          1    512B      -  MBR
                  1         62  31.0KB      -  Unused
                 63  351638721   168GB      0  MBR part 108 (active)
          351638784      13104  6552KB      -  Unused

Summary of changes:
 sbin/gpt/gpt.c | 65 ++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 25 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/4a92b9c1252f2f85571045054a2831d16cc2013b


-- 
DragonFly BSD source repository


More information about the Commits mailing list