Print this page
7999 'format' command says "Failed to initialise libfdisk"
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Garrett D'Amore <garrett@damore.org>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libfdisk/common/libfdisk.c
          +++ new/usr/src/lib/libfdisk/common/libfdisk.c
↓ open down ↓ 762 lines elided ↑ open up ↑
 763  763  
 764  764  /*
 765  765   * Reads the master fdisk partition table from the device assuming that it has
 766  766   * a valid table.
 767  767   * MBR is supposed to be of 512 bytes no matter what the device block size is.
 768  768   */
 769  769  static int
 770  770  fdisk_read_master_part_table(ext_part_t *epp)
 771  771  {
 772  772          struct dk_minfo_ext dkmp_ext;
      773 +        struct dk_minfo dkmp;
 773  774          uchar_t *buf;
 774  775          int sectsize;
 775  776          int size = sizeof (struct ipart);
 776  777          int cpcnt = FD_NUMPART * size;
 777  778  
 778  779          if (lseek(epp->dev_fd, 0, SEEK_SET) < 0) {
 779  780                  return (EIO);
 780  781          }
 781  782          if (ioctl(epp->dev_fd, DKIOCGMEDIAINFOEXT, &dkmp_ext) < 0) {
 782      -                return (EIO);
      783 +                if (ioctl(epp->dev_fd, DKIOCGMEDIAINFO, &dkmp) < 0) {
      784 +                        return (EIO);
      785 +                }
      786 +                sectsize = dkmp.dki_lbsize;
      787 +        } else {
      788 +                sectsize = dkmp_ext.dki_lbsize;
 783  789          }
 784      -        if (dkmp_ext.dki_lbsize < 512) {
      790 +        if (sectsize < 512) {
 785  791                  return (EIO);
 786  792          }
 787      -        sectsize = dkmp_ext.dki_lbsize;
 788  793          buf = calloc(sectsize, sizeof (uchar_t));
 789  794          if (buf == NULL) {
 790  795                  return (ENOMEM);
 791  796          }
 792  797          if (read(epp->dev_fd, buf, sectsize) < sectsize) {
 793  798                  free(buf);
 794  799                  return (EIO);
 795  800          }
 796  801  
 797  802          /*LINTED*/
↓ open down ↓ 612 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX