OpenSolaris

Printable Version Enter a New Search
Bug ID 6623217
Synopsis Some of the disk attributes are not defined (DM_NSECT, DM_NHEADS) for removable USB disk
State 10-Fix Delivered (Fix available in build)
Category:Subcategory library:libdiskmgt
Keywords
Responsible Engineer Sarah Jelinek
Reported Against
Duplicate Of
Introduced In solaris_10
Commit to Fix snv_79
Fixed In snv_79
Release Fixed solaris_nevada(snv_79)
Related Bugs 6623175
Submit Date 29-October-2007
Last Update Date 5-December-2007
Description
For fixing 6623175, we need to convert the size from MB to cylinder. The size of the cylinder can be calculated by getting the disk geometry attributes DM_NSECT, and DM_NHEADS. libdiskmgt provides these attributes correctly for internal disks. But there are not available for removable USB disks.
Looking at the libdiskmgt:media.c code, it uses DKIOCGGEOM to get DM_NSECT, DM_NHEADS and bunch of other attributes for sparc and X86. It fails for removable USB stick in X86. So it should use DKIOCG_PHYGEOM to get all X86 disk attributes. Check the output the following program. It uses both DKIOCGGEOM and DKIOCG_PHYGEOM

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/types.h>
#include <libnvpair.h>
#include <sys/dkio.h>

main(char **argv, int argc)
{
        struct dk_geom  dkg;
        char    path[1024];
        int     fd;

        if (argc < 2) {
                printf("Usage: %s <raw disk path>\n", argv[0]);
                exit (1);
        }

        if ((fd = open(argv[1], O_RDONLY|O_NDELAY)) < 0) {
                printf("Usage: %s <raw disk path>\n", argv[0]);
                exit (2);
        }

        if (ioctl(fd, DKIOCGGEOM, &dkg) < 0) {
                printf("DKIOCGGEOM failed for %s\n", argv[1]);
                return;
        }

        printf("\nResults using DKIOCGGEOM \n");
        printf("DM_NHEADS = %d\n", dkg.dkg_nhead);
        printf("DM_NSECT = %d\n", dkg.dkg_nsect);

        if (ioctl(fd, DKIOCG_PHYGEOM, &dkg) < 0) {
                printf("DKIOCGGEOM failed for %s\n", argv[1]);
                return;
        }

        printf("\nResults using DKIOCG_PHYGEOM \n");
        printf("DM_NHEADS = %d\n", dkg.dkg_nhead);
        printf("DM_NSECT = %d\n", dkg.dkg_nsect);
}

------------------------------------------------------------------------------------

# ./dkiotest /dev/rdsk/c5t0d0p0
DKIOCGGEOM failed for /dev/rdsk/c5t0d0p0

Results using DKIOCG_PHYGEOM 
DM_NHEADS = 128
DM_NSECT = 32

The data looks correct because the cylinder size is 4096 blocks (DM_NHEADS*DM_NSECT) and it is the same size reported by fdisk.

# fdisk /dev/rdsk/c5t0d0p0

             Total disk size is 984 cylinders
             Cylinder size is 4096 (512 byte) blocks

                                               Cylinders
      Partition   Status    Type          Start   End   Length    %
      =========   ======    ============  =====   ===   ======   ===
          1                 Solaris2          1   246     246     25
          2                 Solaris2        247   975     729     74




SELECT ONE OF THE FOLLOWING:
   1. Create a partition
   2. Specify the active partition
   3. Delete a partition
   4. Change between Solaris and Solaris2 Partition IDs
   5. Exit (update disk configuration and exit)
   6. Cancel (exit without updating disk configuration)



*** (#1 of 1): [ UNSAVED ]  xxxxx@xxxxx.com
*** (#1 of 1): 2007-10-30 11:53:59 MDT  xxxxx@xxxxx.com
Work Around
N/A
Comments
N/A