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>


 753 {
 754         int size = sizeof (struct ipart);
 755         struct ipart *table;
 756 
 757         if ((table = calloc(4, size)) == NULL) {
 758                 return (NULL);
 759         }
 760 
 761         return (table);
 762 }
 763 
 764 /*
 765  * Reads the master fdisk partition table from the device assuming that it has
 766  * a valid table.
 767  * MBR is supposed to be of 512 bytes no matter what the device block size is.
 768  */
 769 static int
 770 fdisk_read_master_part_table(ext_part_t *epp)
 771 {
 772         struct dk_minfo_ext dkmp_ext;

 773         uchar_t *buf;
 774         int sectsize;
 775         int size = sizeof (struct ipart);
 776         int cpcnt = FD_NUMPART * size;
 777 
 778         if (lseek(epp->dev_fd, 0, SEEK_SET) < 0) {
 779                 return (EIO);
 780         }
 781         if (ioctl(epp->dev_fd, DKIOCGMEDIAINFOEXT, &dkmp_ext) < 0) {

 782                 return (EIO);
 783         }
 784         if (dkmp_ext.dki_lbsize < 512) {




 785                 return (EIO);
 786         }
 787         sectsize = dkmp_ext.dki_lbsize;
 788         buf = calloc(sectsize, sizeof (uchar_t));
 789         if (buf == NULL) {
 790                 return (ENOMEM);
 791         }
 792         if (read(epp->dev_fd, buf, sectsize) < sectsize) {
 793                 free(buf);
 794                 return (EIO);
 795         }
 796 
 797         /*LINTED*/
 798         if (LE_16((*(uint16_t *)&buf[510])) != MBB_MAGIC) {
 799                 bzero(epp->mtable, cpcnt);
 800                 free(buf);
 801                 return (FDISK_EBADMAGIC);
 802         }
 803 
 804         bcopy(&buf[FDISK_PART_TABLE_START], epp->mtable, cpcnt);
 805         free(buf);
 806 
 807         return (FDISK_SUCCESS);




 753 {
 754         int size = sizeof (struct ipart);
 755         struct ipart *table;
 756 
 757         if ((table = calloc(4, size)) == NULL) {
 758                 return (NULL);
 759         }
 760 
 761         return (table);
 762 }
 763 
 764 /*
 765  * Reads the master fdisk partition table from the device assuming that it has
 766  * a valid table.
 767  * MBR is supposed to be of 512 bytes no matter what the device block size is.
 768  */
 769 static int
 770 fdisk_read_master_part_table(ext_part_t *epp)
 771 {
 772         struct dk_minfo_ext dkmp_ext;
 773         struct dk_minfo dkmp;
 774         uchar_t *buf;
 775         int sectsize;
 776         int size = sizeof (struct ipart);
 777         int cpcnt = FD_NUMPART * size;
 778 
 779         if (lseek(epp->dev_fd, 0, SEEK_SET) < 0) {
 780                 return (EIO);
 781         }
 782         if (ioctl(epp->dev_fd, DKIOCGMEDIAINFOEXT, &dkmp_ext) < 0) {
 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;
 789         }
 790         if (sectsize < 512) {
 791                 return (EIO);
 792         }

 793         buf = calloc(sectsize, sizeof (uchar_t));
 794         if (buf == NULL) {
 795                 return (ENOMEM);
 796         }
 797         if (read(epp->dev_fd, buf, sectsize) < sectsize) {
 798                 free(buf);
 799                 return (EIO);
 800         }
 801 
 802         /*LINTED*/
 803         if (LE_16((*(uint16_t *)&buf[510])) != MBB_MAGIC) {
 804                 bzero(epp->mtable, cpcnt);
 805                 free(buf);
 806                 return (FDISK_EBADMAGIC);
 807         }
 808 
 809         bcopy(&buf[FDISK_PART_TABLE_START], epp->mtable, cpcnt);
 810         free(buf);
 811 
 812         return (FDISK_SUCCESS);