1) A zero-length partition is a non-partition. Also PRT_fix_CHS()
assumes length is non-zero and scribbles garbage is it is zero.

2) Having written the MBR, refresh the in-memory copy to reflect
what was written.

3) If we are writing an MBR, always write DOSMBR_SIGNATURE so it
will be recognized by our disklabel logic.

Noticed by matthew@ at c2k11.

OK?

.... Ken

Index: cmd.c
===================================================================
RCS file: /cvs/src/sbin/fdisk/cmd.c,v
retrieving revision 1.45
diff -u -p -r1.45 cmd.c
--- cmd.c       2 Jul 2010 02:54:09 -0000       1.45
+++ cmd.c       23 Jul 2011 02:41:18 -0000
@@ -224,9 +224,9 @@ Xedit(cmd_t *cmd, disk_t *disk, mbr_t *m
                            d, m, pp->bs , DO_CONVERSIONS |
                            ((pp->id == FS_BSDFFS || pp->id == FS_SWAP) ?
                            DO_ROUNDING : 0));
-                       if (pp->ns == UINT_MAX)
+                       if (pp->ns == UINT_MAX || pp->ns == 0)
                                printf("Invalid size.\n");
-               } while (pp->ns == UINT_MAX);
+               } while (pp->ns == UINT_MAX || pp->ns == 0);
 
                /* Fix up CHS values */
                PRT_fix_CHS(disk, pp);
@@ -342,6 +342,9 @@ Xwrite(cmd_t *cmd, disk_t *disk, mbr_t *
                return (CMD_CONT);
        }
        close(fd);
+
+       /* Refresh in memory copy to reflect what was just written. */
+       MBR_parse(disk, mbr_buf, mbr->offset, mbr->reloffset, mbr);
 
        return (CMD_CLEAN);
 }
Index: mbr.c
===================================================================
RCS file: /cvs/src/sbin/fdisk/mbr.c,v
retrieving revision 1.27
diff -u -p -r1.27 mbr.c
--- mbr.c       20 Jun 2011 19:10:41 -0000      1.27
+++ mbr.c       23 Jul 2011 02:41:18 -0000
@@ -123,7 +123,7 @@ MBR_make(mbr_t *mbr, char *mbr_buf)
        int i;
 
        memcpy(mbr_buf, mbr->code, MBR_CODE_SIZE);
-       putshort(&mbr_buf[MBR_SIG_OFF], mbr->signature);
+       putshort(&mbr_buf[MBR_SIG_OFF], DOSMBR_SIGNATURE);
 
        for (i = 0; i < NDOSPART; i++)
                PRT_make(&mbr->part[i], mbr->offset, mbr->reloffset,

Reply via email to