Print this page
10517 Convert dkio(7I) to mandoc
   1 .\"
   2 .\" The contents of this file are subject to the terms of the
   3 .\" Common Development and Distribution License (the "License").
   4 .\" You may not use this file except in compliance with the License.
   5 .\"
   6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   7 .\" or http://www.opensolaris.org/os/licensing.
   8 .\" See the License for the specific language governing permissions
   9 .\" and limitations under the License.
  10 .\"
  11 .\" When distributing Covered Code, include this CDDL HEADER in each
  12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  13 .\" If applicable, add the following below this CDDL HEADER, with the
  14 .\" fields enclosed by brackets "[]" replaced with your own identifying
  15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
  16 .\"
  17 .\"
  18 .\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
  19 .\" Copyright 2016 Nexenta Systems, Inc.

  20 .\"
  21 .TH DKIO 7I "Oct 8, 2016"
  22 .SH NAME
  23 dkio \- disk control operations
  24 .SH SYNOPSIS
  25 .LP
  26 .nf
  27 #include <sys/dkio.h>
  28 #include <sys/vtoc.h>
  29 .fi
  30 
  31 .LP
  32 .nf
  33 \fB\fR
  34 .fi
  35 
  36 .SH DESCRIPTION
  37 .LP
  38 Disk drivers support a set of \fBioctl\fR(2) requests for disk controller,
  39 geometry, and partition information. Basic to these \fBioctl()\fR requests are
  40 the definitions in \fB<sys/dkio.h>\fR\&.
  41 .SH IOCTLS
  42 .LP
  43 The following \fBioctl()\fR requests set and/or retrieve the current disk
  44 controller, partitions, or geometry information on all architectures:
  45 .sp
  46 .ne 2
  47 .na
  48 \fB\fBDKIOCINFO\fR\fR
  49 .ad
  50 .sp .6
  51 .RS 4n
  52 The argument is a pointer to a \fBdk_cinfo\fR structure (described below). This
  53 structure tells the controller-type and attributes regarding bad-block
  54 processing done on the controller.
  55 .RE
  56 
  57 .sp
  58 .in +2
  59 .nf
  60 /*
  61  * Structures and definitions for disk I/O control commands
  62  */
  63 #define DK_DEVLEN 16   /* device name max length, */
  64                        /* including unit # and NULL */
  65                        /* Used for controller info */

  66 struct dk_cinfo {
  67      char      dki_cname[DK_DEVLEN];    /* controller name */
  68                                         /* (no unit #) */
  69      ushort_t  dki_ctype;               /* controller type */
  70      ushort_t  dki_flags;               /* flags */
  71      ushort_t  dki_cnum;                /* controller number */
  72      uint_t    dki_addr;                /* controller address */
  73      uint_t    dki_space;               /* controller bus type */
  74      uint_t    dki_prio;                /* interrupt priority */
  75      uint_t    dki_vec;                 /* interrupt vector */
  76      char      dki_dname[DK_DEVLEN];    /* drive name (no unit #) */
  77      uint_t    dki_unit;                /* unit number */
  78      uint_t    dki_slave;               /* slave number */
  79      ushort_t  dki_partition;           /* partition number */
  80      ushort_t  dki_maxtransfer;         /* maximum transfer size */
  81                                         /* in DEV_BSIZE */
  82 
  83      };

  84      /*
  85       * Controller types
  86       */
  87 
  88      #define DKC_UNKNOWN      0
  89      #define DKC_CDROM        1         /* CD-ROM, SCSI or other */
  90      #define DKC_WDC2880      2
  91      #define DKC_XXX_0        3         /* unassigned */
  92      #define DKC_XXX_1        4         /* unassigned */
  93      #define DKC_DSD5215      5
  94      #define DKC_ACB4000      7
  95      #define DKC_XXX_2        9         /* unassigned */
  96      #define DKC_NCRFLOPPY    10
  97      #define DKC_SMSFLOPPY    12
  98      #define DKC_SCSI_CCS     13        /* SCSI CCS compatible */
  99      #define DKC_INTEL82072   14        /* native floppy chip */
 100      #define DKC_INTEL82077   19        /* 82077 floppy disk */
 101                                         /* controller */
 102      #define DKC_DIRECT       20        /* Intel direct attached */
 103                                         /* device (IDE) */
 104      #define DKC_PCMCIA_MEM   21        /* PCMCIA memory disk-like */
 105                                         /* type */
 106      #define DKC_PCMCIA_ATA   22        /* PCMCIA AT Attached type */
 107 
 108      /*
 109       * Sun reserves up through 1023
 110       */
 111 
 112      #define DKC_CUSTOMER_BASE  1024
 113 
 114      /*
 115       * Flags
 116       */
 117 
 118      #define DKI_BAD144       0x01          /* use  DEC  std  144  */
 119                                             /* bad  sector fwding */
 120      #define DKI_MAPTRK       0x02          /* controller does */
 121                                             /* track mapping */
 122      #define DKI_FMTTRK       0x04          /* formats only  full
 123                                             /* track at a time*/
 124      #define DKI_FMTVOL       0x08          /* formats only full */
 125                                             /* volume at a time*/
 126      #define DKI_FMTCYL       0x10          /* formats only full */
 127                                             /* cylinders at a time*/
 128      #define DKI_HEXUNIT      0x20          /* unit number printed as */
 129                                             /* 3 hexdigits */
 130      #define DKI_PCMCIA_PFD   0x40          /* PCMCIA pseudo-floppy */
 131                                             /* memory card */
 132 .fi
 133 .in -2
 134 
 135 .sp
 136 .ne 2
 137 .na
 138 \fB\fBDKIOCGAPART\fR\fR
 139 .ad
 140 .sp .6
 141 .RS 4n
 142 The argument is a pointer to a \fBdk_allmap\fR structure (described below).
 143 This \fBioctl()\fR gets the controller's notion of the current partition table
 144 for disk drive.
 145 .RE
 146 
 147 .sp
 148 .ne 2
 149 .na
 150 \fB\fBDKIOCSAPART\fR\fR
 151 .ad
 152 .sp .6
 153 .RS 4n
 154 The argument is a pointer to a \fBdk_allmap\fR structure (described below).
 155 This \fBioctl()\fR sets the controller's notion of the partition table without
 156 changing the disk itself.
 157 .RE
 158 
 159 .sp
 160 .in +2
 161 .nf
 162 /*
 163  * Partition map (part of dk_label)
 164  */ struct dk_map {

 165      daddr_t dkl_cylno;     /* starting cylinder */
 166      daddr_t dkl_nblk;      /* number of blocks */
 167      };

 168 /*
 169  * Used for all partitions
 170  */
 171 struct dk_allmap {
 172     struct dk_map    dka_map[NDKMAP];
 173 };
 174 .fi
 175 .in -2
 176 
 177 .sp
 178 .ne 2
 179 .na
 180 \fB\fBDKIOCGGEOM\fR\fR
 181 .ad
 182 .RS 14n
 183 The argument is a pointer to a \fBdk_geom\fR structure (described below). This
 184 \fBioctl()\fR gets the controller's notion of the current geometry of the disk
 185 drive.
 186 .RE
 187 
 188 .sp
 189 .ne 2
 190 .na
 191 \fB\fBDKIOCSGEOM\fR\fR
 192 .ad
 193 .RS 14n
 194 The argument is a pointer to a \fBdk_geom\fR structure (described below). This
 195 \fBioctl()\fR sets the controller's notion of the geometry without changing the
 196 disk itself.
 197 .RE
 198 
 199 .sp
 200 .ne 2
 201 .na
 202 \fB\fBDKIOCGVTOC\fR\fR
 203 .ad
 204 .RS 14n
 205 The argument is a pointer to a \fBvtoc\fR structure (described below). This
 206 \fBioctl()\fR returns the device's current volume table of contents (VTOC.) For
 207 disks larger than 1TB, DKIOCGEXTVTOC must be used instead.
 208 .RE
 209 
 210 .sp
 211 .ne 2
 212 .na
 213 \fB\fBDKIOCSVTOC\fR\fR
 214 .ad
 215 .RS 14n
 216 The argument is a pointer to a \fBvtoc\fR structure (described below). This
 217 \fBioctl()\fR changes the VTOC associated with the device. For disks larger
 218 than 1TB, DKIOCSEXTVTOC must be used instead.
 219 .RE
 220 
 221 .sp
 222 .in +2
 223 .nf
 224 struct partition {
 225 ushort_t      p_tag;         /* ID tag of partition */
 226 ushort_t      p_flag;        /* permission flags */
 227 daddr_t       p_start;       /* start sector of partition */
 228 long          p_size;        /* # of blocks in partition */
 229 };
 230 .fi
 231 .in -2
 232 
 233 .sp
 234 .LP
 235 If \fBDKIOCSVTOC\fR is used with a floppy diskette, the \fBp_start\fR field
 236 must be the first sector of a cylinder. To compute the number of sectors per

 237 cylinder, multiply the number of heads by the number of sectors per track.
 238 .sp
 239 .in +2
 240 .nf
 241 struct vtoc {
 242 unsigned long     v_bootinfo[3];               /* info needed by mboot
 243                                                /* (unsupported)*/
 244 unsigned long     v_sanity;                    /* to verify vtoc */
 245                                                /* sanity */
 246 unsigned long     v_version;                   /* layout version */
 247 char              v_volume[LEN_DKL_VVOL];      /* volume name */
 248 ushort_t          v_sectorsz;                  /* sector size in bytes*/
 249 ushort_t          v_nparts;                    /* number of partitions*/
 250 unsigned long     v_reserved[10];              /* free space */
 251 struct partition  v_part[V_NUMPAR];            /* partition headers */
 252 time_t            timestamp[V_NUMPAR];         /* partition timestamp */
 253                                                /* (unsupported) */
 254 char              v_asciilabel[LEN_DKL_ASCII]; /* compatibility */
 255 };
 256 
 257 /*
 258 * Partition permission flags
 259 */
 260 
 261 #define V_UNMNT      0x01    /* Unmountable partition */
 262 #define V_RONLY      0x10    /* Read only */
 263 
 264 /*
 265 * Partition identification tags
 266 */
 267 
 268 #define V_UNASSIGNED   0x00  /* unassigned partition */
 269 #define V_BOOT         0x01  /* Boot partition */
 270 #define V_ROOT         0x02  /* Root filesystem */
 271 #define V_SWAP         0x03  /* Swap filesystem */
 272 #define V_USR          0x04  /* Usr filesystem */
 273 #define V_BACKUP       0x05  /* full disk */
 274 #define V_VAR          0x07  /* Var partition */
 275 #define V_HOME         0x08  /* Home partition */
 276 #define V_ALTSCTR      0x09  /* Alternate sector partition */
 277 .fi
 278 .in -2
 279 
 280 .sp
 281 .ne 2
 282 .na
 283 \fB\fBDKIOCGEXTVTOC\fR\fR
 284 .ad
 285 .sp .6
 286 .RS 4n
 287 The argument is a pointer to an \fBextvtoc\fR structure (described below). This
 288 ioctl returns the device's current volume table of contents (VTOC). VTOC is
 289 extended to support a disk up to 2TB in size. For disks larger than 1TB this
 290 ioctl must be used instead of \fBDKIOCGVTOC\fR.
 291 .RE
 292 
 293 .sp
 294 .ne 2
 295 .na
 296 \fB\fBDKIOCSEXTVTOC\fR\fR
 297 .ad
 298 .sp .6
 299 .RS 4n
 300 The argument is a pointer to an \fBextvtoc\fR structure (described below). This
 301 ioctl changes the VTOC associated with the device. VTOC is extended to support
 302 a disk up to 2TB in size. For disks larger than 1TB this ioctl must be used
 303 instead of \fBDKIOCSVTOC\fR.
 304 .sp
 305 .in +2
 306 .nf
 307 struct extpartition {
 308 ushort_t p_tag;         /* ID tag of partition */
 309 ushort_t p_flag;        /* permission flags */
 310 ushort_t p_pad[2];       /* reserved */
 311 diskaddr_t p_start;      /* start sector no of partition */
 312 diskaddr_t p_size;       /* # of blocks in partition */
 313 };
 314 
 315 
 316 struct extvtoc {
 317 uint64_t   v_bootinfo[3]; /* info needed by mboot (unsupported) */
 318 uint64_t   v_sanity;     /* to verify vtoc sanity */
 319 uint64_t   v_version;    /* layout version */
 320 char    v_volume[LEN_DKL_VVOL]; /* volume name */
 321 ushort_t   v_sectorsz;   /* sector size in bytes */
 322 ushort_t   v_nparts;     /* number of partitions */
 323 ushort_t   pad[2];
 324 uint64_t   v_reserved[10];
 325 struct extpartition v_part[V_NUMPAR]; /* partition headers */
 326 uint64_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported)*/
 327 char    v_asciilabel[LEN_DKL_ASCII];    /* for compatibility */

 328 };
 329 

 330 Partition permissions flags and identification tags
 331 are defined the same as vtoc structure.
 332 .fi
 333 .in -2
 334 
 335 .RE
 336 
 337 .sp
 338 .ne 2
 339 .na
 340 \fB\fBDKIOCEJECT\fR\fR
 341 .ad
 342 .sp .6
 343 .RS 4n
 344 If the drive supports removable media, this \fBioctl()\fR requests the disk
 345 drive to eject its disk.
 346 .RE
 347 
 348 .sp
 349 .ne 2
 350 .na
 351 \fB\fBDKIOCREMOVABLE\fR\fR
 352 .ad
 353 .sp .6
 354 .RS 4n
 355 The argument to this \fBioctl()\fR is an integer. After successful completion,
 356 this \fBioctl()\fR sets that integer to a non-zero value if the drive in
 357 question has removable media. If the media is not removable, the integer is set
 358 to \fB0\fR.
 359 .RE
 360 
 361 .sp
 362 .ne 2
 363 .na
 364 \fB\fBDKIOCHOTPLUGGABLE\fR\fR
 365 .ad
 366 .sp .6
 367 .RS 4n
 368 The argument to this \fBioctl()\fR is an integer. After successful completion,
 369 this \fBioctl()\fR sets that integer to a non-zero value if the drive in
 370 question is hotpluggable. If the media is not hotpluggable, the integer is set
 371 to 0.
 372 .RE
 373 
 374 .sp
 375 .ne 2
 376 .na
 377 \fB\fBDKIOCSTATE\fR\fR
 378 .ad
 379 .sp .6
 380 .RS 4n
 381 This \fBioctl()\fR blocks until the state of the drive, inserted or ejected, is
 382 changed. The argument is a pointer to a \fBdkio_state\fR, enum, whose possible
 383 enumerations are listed below. The initial value should be either the last
 384 reported state of the drive, or \fBDKIO_NONE\fR. Upon return, the enum pointed
 385 to by the argument is updated with the current state of the drive.
 386 .sp
 387 .in +2
 388 .nf
 389 enum dkio_state {
 390 DKIO_NONE,          /* Return disk's current state */
 391 DKIO_EJECTED,       /* Disk state is 'ejected' */
 392 DKIO_INSERTED       /* Disk state is 'inserted' */
 393 };
 394 .fi
 395 .in -2
 396 
 397 .RE
 398 
 399 .sp
 400 .ne 2
 401 .na
 402 \fB\fBDKIOCLOCK\fR\fR
 403 .ad
 404 .sp .6
 405 .RS 4n
 406 For devices with removable media, this \fBioctl()\fR requests the disk drive to
 407 lock the door.
 408 .RE
 409 
 410 .sp
 411 .ne 2
 412 .na
 413 \fB\fBDKIOCUNLOCK\fR\fR
 414 .ad
 415 .sp .6
 416 .RS 4n
 417 For devices with removable media, this \fBioctl()\fR requests the disk drive to
 418 unlock the door.
 419 .RE
 420 
 421 .sp
 422 .ne 2
 423 .na
 424 \fB\fBDKIOCGMEDIAINFO\fR\fR
 425 .ad
 426 .sp .6
 427 .RS 4n
 428 The argument to this \fBioctl()\fR is a pointer to a \fBdk_minfo\fR structure.
 429 The structure indicates the type of media or the command set profile used by
 430 the drive to operate on the media. The \fBdk_minfo\fR structure also indicates
 431 the logical media block size the drive uses as the basic unit block size of
 432 operation and the raw formatted capacity of the media in number of logical
 433 blocks.
 434 .RE
 435 
 436 .sp
 437 .ne 2
 438 .na
 439 \fB\fBDKIOCGMEDIAINFOEXT\fR\fR
 440 .ad
 441 .sp .6
 442 .RS 4n
 443 The argument to this \fBioctl()\fR is a pointer to a \fBdk_minfo_ext\fR
 444 structure. The structure indicates the type of media or the command set profile
 445 used by the drive to operate on the media. The \fBdk_minfo_ext\fR structure


 446 also indicates the logical media block size the drive uses as the basic unit
 447 block size of operation, the raw formatted capacity of the media in number of
 448 logical blocks and the physical block size of the media.
 449 .RE
 450 
 451 .sp
 452 .in +2
 453 .nf
 454 /*
 455 * Used for media info or profile info
 456 */
 457 struct dk_minfo {
 458 uint_t dki_media_type; /* Media type or profile info */
 459 uint_t dki_lbsize; /* Logical blocksize of media */
 460 diskaddr_t dki_capacity; /* Capacity as # of dki_lbsize blks */
 461 };
 462 
 463 /*
 464 * Used for media info or profile info and physical blocksize
 465 */
 466 struct dk_minfo_ext {
 467 uint_t dki_media_type; /* Media type or profile info */
 468 uint_t dki_lbsize; /* Logical blocksize of media */
 469 diskaddr_t dki_capacity; /* Capacity as # of dki_lbsize blks */
 470 uint_t dki_pbsize; /* Physical blocksize of media */
 471 };
 472 
 473 
 474 /*
 475 * Media types or profiles known
 476 */
 477 #define DK_UNKNOWN         0x00    /* Media inserted - type unknown */
 478 
 479 /*
 480 * SFF 8090 Specification Version 3, media types 0x01 - 0xfffe are
 481 * retained to maintain compatibility with SFF8090.  The following
 482 * define the optical media type.
 483 */
 484 #define DK_MO_ERASABLE     0x03 /* MO Erasable */
 485 #define DK_MO_WRITEONCE    0x04 /* MO Write once */
 486 #define DK_AS_MO           0x05 /* AS MO */
 487 #define DK_CDROM           0x08 /* CDROM */
 488 #define DK_CDR             0x09 /* CD-R */
 489 #define DK_CDRW            0x0A /* CD-RW */
 490 #define DK_DVDROM          0x10 /* DVD-ROM */
 491 #define DK_DVDR            0x11 /* DVD-R */
 492 #define DK_DVDRAM          0x12 /* DVD_RAM or DVD-RW */
 493 
 494 /*
 495 * Media types for other rewritable magnetic media
 496 */
 497 #define DK_FIXED_DISK      0x10001 /* Fixed disk SCSI or otherwise */
 498 #define DK_FLOPPY          0x10002 /* Floppy media */
 499 #define DK_ZIP             0x10003 /* IOMEGA ZIP media */
 500 #define DK_JAZ             0x10004 /* IOMEGA JAZ media */
 501 .fi
 502 .in -2
 503 
 504 .sp
 505 .LP
 506 If the media exists and the host can obtain a current profile list, the command
 507 succeeds and returns the \fBdk_minfo\fR structure with data representing that
 508 media.
 509 .sp
 510 .LP
 511 If there is no media in the drive, the command fails and the host returns an
 512 \fBENXIO\fR error, indicating that it cannot gather the information requested.
 513 .sp
 514 .LP
 515 If the profile list is not available, the host attempts to identify the
 516 media-type based on the available information.
 517 .sp
 518 .LP
 519 If identification is not possible, the host returns media type
 520 \fBDK_UNKNOWN\fR. See \fINOTES\fR for blocksize usage and capacity information.
 521 .sp
 522 .ne 2
 523 .na
 524 \fB\fBDKIOCSMBOOT\fR\fR
 525 .ad
 526 .sp .6
 527 .RS 4n
 528 The argument is a pointer to struct \fImboot\fR.
 529 .sp
 530 Copies the \fImboot\fR information supplied in the argument to the absolute
 531 sector 0 of the device. Prior to copying the information, this \fBioctl()\fR
 532 performs the following checks on the \fImboot\fR data:
 533 .RS +4
 534 .TP
 535 .ie t \(bu
 536 .el o


 537 Ensures that the signature field is set to 0xAA55.
 538 .RE
 539 .RS +4
 540 .TP
 541 .ie t \(bu
 542 .el o
 543 Ensures that partitions do not overlap.
 544 .RE
 545 .RS +4
 546 .TP
 547 .ie t \(bu
 548 .el o
 549 On SPARC platforms, determines if the device is a removable media.
 550 .RE
 551 If the above verification fails, \fBerrno\fR is set to \fBEINVAL\fR and the
 552 \fBioctl()\fR command fails.
 553 .sp
 554 x86 Platforms \(em Upon successful write of \fImboot\fR, the partition map
 555 structure maintained in the driver is updated. If the new Solaris partition is








 556 different from the previous one, the internal VTOC table maintained in the
 557 driver is set as follows:
 558 .sp
 559 If _SUNOS_VTOC_8 is defined:
 560 .sp
 561 Partition: 0. Start: 0. Capacity = Capacity of device.
 562 .sp
 563 Partition: 2. Start: 0. Capacity = Capacity of device.
 564 .sp
 565 If _SUNOS_VTOC_16 is defined:
 566 .sp
 567 Partition: 2. Start: 0. Size = Size specified in mboot - 2 cylinders.
 568 .sp
 569 Partition: 8. Start: 0. Size = Sectors/cylinder.
 570 .sp
 571 Partition: 9. Start: Sectors/cylinder. Size = 2 * sectors/cylinder
 572 .sp



 573 To determine if the Solaris partition has changed:
 574 .sp
 575 If either offset or the size of the Solaris partition is different from the
 576 previous one then it shall be deemed to have changed. In all other cases, the

 577 internal VTOC info remains as before.
 578 .sp
 579 SPARC Platforms \(em The VTOC label and \fImboot\fR both occupy the same
 580 location, namely sector 0. As a result, following the successful write of
 581 \fImboot\fR info, the internal VTOC table maintained in the driver is set as
 582 follows:
 583 .sp
 584 Partition: 0. Start: 0. Size = Capacity of device.
 585 .sp
 586 Partition: 2. Start: 0. Size = Capacity of device.
 587 .sp
 588 See the NOTES section for usage of DKIOCSMBOOT when modifying Solaris
 589 partitions.
 590 .RE
 591 
 592 .sp
 593 .ne 2
 594 .na
 595 \fB\fBDKIOCGETVOLCAP\fR\fR
 596 .ad
 597 .sp .6
 598 .RS 4n
 599 This ioctl provides information and status of available capabilities.
 600 .sp
 601 \fIvc_info\fR is a bitmap and the valid flag values are:
 602 .sp
 603 .in +2
 604 .nf
 605 DKV_ABR_CAP -  Capable of application-based recovery
 606 DKV_DMR_CAP -  Ability to read specific copy of data when
 607                multiple copies exist. For example, in a two
 608                way mirror, this ioctl is used to read each
 609                side of the mirror.
 610 .fi
 611 .in -2
 612 
 613 \fIvc_set\fR is a bitmap and the valid flag values are:
 614 .sp
 615 .in +2
 616 .nf
 617 DKV_ABR_CAP - This flag is set if ABR has been set on a device
 618               that supports ABR functionality.
 619 DKV_DMR_CAP - Directed read has been enabled.
 620 .fi
 621 .in -2
 622 
 623 These capabilities are not required to be persistent across a system reboot and
 624 their persistence depends upon the implementation. For example, if the ABR

 625 capability for a DRL mirror simply clears the dirty-region list and
 626 subsequently stops updating this list, there is no reason for persistence
 627 because the VM recovery is a no-op. Conversely, if the ABR capability is

 628 applied to a non-DRL mirror to indicate that the VM should not perform a full
 629 recovery of the mirror following a system crash, the capability must be
 630 persistent so that the VM know whether or not to perform recovery.
 631 .sp
 632 Return Errors:
 633 .sp
 634 .ne 2
 635 .na
 636 \fB\fBEINVAL\fR\fR
 637 .ad
 638 .RS 11n
 639 Invalid device for this operation.
 640 .RE
 641 
 642 .sp
 643 .ne 2
 644 .na
 645 \fB\fBENOTSUP\fR\fR
 646 .ad
 647 .RS 11n
 648 Functionality that is attempted to be set is not supported.
 649 .RE
 650 
 651 .RE
 652 
 653 .sp
 654 .ne 2
 655 .na
 656 \fB\fBDKIOCSETVOLCAP\fR\fR
 657 .ad
 658 .sp .6
 659 .RS 4n
 660 This ioctl sets the available capabilities for the device. If a capability flag
 661 is not set in vc_set, that capability is cleared.
 662 .sp
 663 \fIvc_info\fR flags are ignored
 664 .sp
 665 \fIvc_set\fR valid flags are:
 666 .sp
 667 .in +2
 668 .nf
 669 DKV_ABR_CAP - Flag to set application-based recovery. A device can
 670               successfully support ABR only if it is capable.
 671 DKV_DMR_CAP - Flag to set directed read.
 672 
 673 
 674 int
 675 ioctl(int , DKIODMR, vol_directed_rd *);
 676 .fi
 677 .in -2
 678 
 679 .RE
 680 
 681 .sp
 682 .ne 2
 683 .na
 684 \fB\fBDKIODMR\fR\fR
 685 .ad
 686 .sp .6
 687 .RS 4n
 688 This ioctl allows highly available applications to perform round-robin reads
 689 from the underlying devices of a replicated device.
 690 .sp
 691 .in +2
 692 .nf
 693 vdr_offset      - offset at which the read should occur.
 694 vdr_nbytes      - number of bytes to be read
 695 vdr_bytesread   - number of bytes successfully read by the kernel.
 696 vdr_data        - pointer to a user allocated buffer to return the
 697                   data read
 698 vdr_side        - side to be read. Initialized to DKV_SIDE_INIT
 699 vdr_side_name   - The volume name that has been read.
 700 
 701 Valid vdr_flags are:
 702       DKV_DMR_NEXT_SIDE (set by user)
 703       DKV_DMR_DONE (return value)
 704       DKV_DMR_ERROR (return value)
 705       DKV_DMR_SUCCESS(return value)
 706       DKV_DMR_SHORT(return value)
 707 .fi
 708 .in -2
 709 
 710 The calling sequence is as follows: The caller sets the \fIvdr_flags\fR to
 711 \fBDK_DMR_NEXT_SIDE\fR and \fIvdr_side\fR to \fBDKV_SIDE_INIT\fR at the start.
 712 Subsequent calls should be made without any changes to these values. If they
 713 are changed the results of the ioctl are indeterminate.
 714 .sp
 715 When \fBDKV_SIDE_INIT\fR is set, the call results in the kernel reading from
 716 the first side. The kernel updates \fIvdr_side\fR to indicate the side that was
 717 read, and \fIvdr_side_name\fR to contain the name of that side. \fIvdr_data\fR
 718 contains the data that was read. Therefore to perform a round-robin read all of





























 719 the valid sides, there is no need for the caller to change the contents of
 720 \fIvdr_side\fR.
 721 .sp
 722 Subsequent ioctl calls result in reads from the next valid side until all valid
 723 sides have been read. On success, the kernel sets \fBDKV_DMR_SUCCESS\fR. The
 724 following table shows the values of \fIvdr_flags\fR that are returned when an
 725 error occurs:
 726 .sp
 727 .in +2
 728 .nf
 729 vdr_flags    |   vdr_side        |       Notes
 730 -------------|-------------------|----------------------------
 731 DKV_DMR_ERROR|   DKV_SIDE_INIT   |   No valid side to read
 732 DKV_DMR_DONE |   Not Init side   |   All valid sides read
 733 DKV_DMR_SHORT|   Any value       |   Bytes requested cannot
 734                                      be read. vdr_bytesread
 735                                      set to bytes actually
 736                                      read.
 737 .fi
 738 .in -2
 739 
 740 .sp
 741 .in +2
 742 .nf
 743 Typical code fragment:
 744 
 745 enable->vc_set |= DKV_ABR_SET;
 746 retval = ioctl(filedes, DKIOSETVOLCAP, enable);
 747 if (retval != EINVAL || retval != ENOTSUP) {
 748         if (info->vc_set & DKV_DMR_SET) {
 749                 dr->vdr_flags |= DKV_DMR_NEXT_SIDE;
 750                 dr->vdr_side = DKV_SIDE_INIT;
 751                 dr->vdr_nbytes = 1024;
 752                 dr->vdr_offset = 0xff00;
 753                 do {
 754                         rval =ioctl(fildes, DKIODMR, dr);
 755                         if (rval != EINVAL) {
 756                                 /* Process data */
 757                         }
 758                 } while (rval != EINVAL || dr->vdr_flags &
 759                     (DKV_DMR_DONE | DKV_DMR_ERROR | DKV_DMR_SHORT)
 760         }
 761 }
 762 .fi
 763 .in -2
 764 
 765 .RE
 766 
 767 .SS "RETURN VALUES"
 768 .LP
 769 Upon successful completion, the value returned is \fB0\fR. Otherwise, \fB-1\fR
 770 is returned and \fBerrno\fR is set to indicate the error.
 771 .SS "x86 Only"
 772 .LP
 773 The following \fBioctl()\fR requests set and/or retrieve the current disk


 774 controller, partitions, or geometry information on the x86 architecture.
 775 .sp
 776 .ne 2
 777 .na
 778 \fB\fBDKIOCG_PHYGEOM\fR\fR
 779 .ad
 780 .sp .6
 781 .RS 4n
 782 The argument is a pointer to a \fBdk_geom\fR structure (described below). This
 783 \fBioctl()\fR gets the driver's notion of the physical geometry of the disk
 784 drive. It is functionally identical to the \fBDKIOCGGEOM\fR \fBioctl()\fR.
 785 .RE
 786 
 787 .sp
 788 .ne 2
 789 .na
 790 \fB\fBDKIOCG_VIRTGEOM\fR\fR
 791 .ad
 792 .sp .6
 793 .RS 4n
 794 The argument is a pointer to a \fBdk_geom\fR structure (described below). This
 795 \fBioctl()\fR gets the controller's (and hence the driver's) notion of the
 796 virtual geometry of the disk drive. Virtual geometry is a view of the disk
 797 geometry maintained by the firmware in a host bus adapter or disk controller.
 798 If the disk is larger than 8 Gbytes, this ioctl fails because a CHS-based
 799 geometry is not relevant or useful for this drive.
 800 .RE
 801 
 802 .sp
 803 .in +2
 804 .nf
 805 /*
 806 * Definition of a disk's geometry
 807 */
 808 */struct dk_geom {
 809 unsigned shor    dkg_ncyl;             /* # of data cylinders */
 810 unsigned shor    dkg_acyl;             /* # of alternate cylinders */
 811 unsigned short   dkg_bcyl;             /* cyl offset (for fixed head */
 812                                        /* area) */
 813 unsigned short   dkg_nhead;            /* # of heads */
 814 unsigned short   dkg_obs1;             /* obsolete */
 815 unsigned short   dkg_nsect;            /* # of sectors per track*/
 816 unsigned short   dkg_intrlv;           /* interleave factor */
 817 unsigned short   dkg_obs2;             /* obsolete */
 818 unsigned short   dkg_obs3;             /* obsolete */
 819 unsigned short   dkg_apc;              /* alternates per cylinder */
 820                                        /* (SCSI only) */
 821 unsigned short   dkg_rpm;              /* revolutions per min*/
 822 unsigned short   dkg_pcyl;             /* # of physical cylinders */
 823 unsigned short   dkg_write_reinstruct; /* # sectors to skip, writes*/
 824 unsigned short   dkg_read_reinstruct;  /* # sectors to skip, reads*/
 825 unsigned short   dkg_extra[7];         /* for compatible expansion*/


 826 };
 827 .fi
 828 .in -2
 829 
 830 .sp
 831 .ne 2
 832 .na
 833 \fB\fBDKIOCADDBAD\fR\fR
 834 .ad
 835 .sp .6
 836 .RS 4n
 837 This \fBioctl()\fR forces the driver to re-examine the alternates slice and
 838 rebuild the internal bad block map accordingly. It should be used whenever the
 839 alternates slice is changed by any method other than the \fBaddbadsec\fR(1M) or
 840 \fBformat\fR(1M) utilities. \fBDKIOCADDBAD\fR can only be used for software
 841 remapping on \fB IDE\fR drives; \fBSCSI\fR drives use hardware remapping of
 842 alternate sectors.
 843 .RE
 844 
 845 .sp
 846 .ne 2
 847 .na
 848 \fB\fBDKIOCPARTINFO\fR\fR
 849 .ad
 850 .sp .6
 851 .RS 4n
 852 The argument is a pointer to a \fBpart_info\fR structure (described below).
 853 This \fBioctl()\fR gets the driver's notion of the size and extent of the

 854 partition or slice indicated by the file descriptor argument.
 855 .sp
 856 .in +2
 857 .nf
 858 /*
 859  * Used by applications to get partition or slice information
 860  */
 861 struct part_info {
 862 daddr_t    p_start;
 863 int        p_length;
 864       };
 865 .fi
 866 .in -2
 867 
 868 .RE
 869 
 870 .sp
 871 .ne 2
 872 .na
 873 \fB\fBDKIOCEXTPARTINFO\fR\fR
 874 .ad
 875 .sp .6
 876 .RS 4n
 877 The argument is a pointer to an \fBextpart_info\fR structure (described below).
 878 This ioctl gets the driver's notion of the size and extent of the partition or
 879 slice indicated by the file descriptor argument. On disks larger than 1TB, this
 880 ioctl must be used instead of \fBDKIOCPARTINFO\fR.
 881 .sp
 882 .in +2
 883 .nf
 884 /*
 885 * Used by applications to get partition or slice information
 886 */
 887 struct extpart_info {
 888 diskkaddr_t      p_start;
 889 diskaddr_t       p_length;
 890 };
 891 .fi
 892 .in -2
 893 
 894 .RE
 895 
 896 .sp
 897 .ne 2
 898 .na
 899 \fB\fBDKIOCSETEXTPART\fR\fR
 900 .ad
 901 .sp .6
 902 .RS 4n
 903 This ioctl is used to update the in-memory copy of the logical drive
 904 information maintained by the driver. The ioctl takes no arguments. It causes a
 905 re-read of the partition information and recreation of minor nodes if required.


 906 Prior to updating the data structures, the ioctl ensures that the partitions do
 907 not overlap. Device nodes are created only for valid partition entries. If
 908 there is any change in the partition offset, size or ID from the previous read,
 909 the partition is deemed to have been changed and hence the device nodes are
 910 recreated. Any modification to any of the logical partitions results in the


 911 recreation of all logical device nodes.
 912 .RE
 913 
 914 .SH SEE ALSO
 915 .LP
 916 \fBaddbadsec\fR(1M), \fBfdisk\fR(1M), \fBformat\fR(1M), \fBioctl\fR(2),
 917 \fBcdio\fR(7I), \fBcmdk\fR(7D), \fBfdio\fR(7I), \fBhdio\fR(7I), \fBsd\fR(7D)
 918 .SH NOTES
 919 .LP
 920 Blocksize information provided in \fBDKIOCGMEDIAINFO\fR is the size (in bytes)
 921 of the device's basic unit of operation and can differ from the blocksize that
 922 the Solaris operating environment exports to the user. Capacity information
 923 provided in the \fBDKIOCGMEDIAINFO\fR are for reference only and you are
 924 advised to use the values returned by \fBDKIOCGGEOM\fR or other appropriate
 925 \fBioctl\fR for accessing data using the standard interfaces.
 926 .sp
 927 .LP
 928 For x86 only: If the \fBDKIOCSMBOOT\fR command is used to modify the Solaris
 929 partitions, the VTOC information should also be set appropriately to reflect
 930 the changes to partition. Failure to do so leads to unexpected results when the
 931 device is closed and reopened fresh at a later time. This is because a default
 932 VTOC is assumed by driver when a Solaris partition is changed. The default VTOC
 933 persists until the ioctl \fBDKIOCSVTOC\fR is called to modify VTOC or the
 934 device is closed and reopened. At that point, the old valid VTOC is read from













 935 the disk if it is still available.
   1 .\"
   2 .\" The contents of this file are subject to the terms of the
   3 .\" Common Development and Distribution License (the "License").
   4 .\" You may not use this file except in compliance with the License.
   5 .\"
   6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   7 .\" or http://www.opensolaris.org/os/licensing.
   8 .\" See the License for the specific language governing permissions
   9 .\" and limitations under the License.
  10 .\"
  11 .\" When distributing Covered Code, include this CDDL HEADER in each
  12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  13 .\" If applicable, add the following below this CDDL HEADER, with the
  14 .\" fields enclosed by brackets "[]" replaced with your own identifying
  15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
  16 .\"
  17 .\"
  18 .\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
  19 .\" Copyright 2016 Nexenta Systems, Inc.
  20 .\" Copyright (c) 2017, Joyent, Inc.
  21 .\"
  22 .Dd October 23, 2017
  23 .Dt DKIO 7I
  24 .Os
  25 .Sh NAME
  26 .Nm dkio
  27 .Nd disk control operations
  28 .Sh SYNOPSIS
  29 .In sys/dkio.h
  30 .In sys/vtoc.h
  31 .Sh DESCRIPTION
  32 Disk drivers support a set of
  33 .Xr ioctl 2
  34 requests for disk controller, geometry, and partition information.
  35 Basic to these
  36 .Xr ioctl 2
  37 requests are the definitions in
  38 .In sys/dkio.h .
  39 .Sh IOCTLS
  40 The following
  41 .Xr ioctl 2
  42 requests set and/or retrieve the current disk


  43 controller, partitions, or geometry information on all architectures:
  44 .Bl -tag -width 1n
  45 .It Dv DKIOCINFO
  46 .Pp
  47 The argument is a pointer to a
  48 .Vt dk_cinfo
  49 structure (described below).
  50 This structure tells the controller-type and attributes regarding bad-block


  51 processing done on the controller.
  52 .Bd -literal -offset 2n




  53 /*
  54  * Structures and definitions for disk I/O control commands
  55  */
  56 #define DK_DEVLEN 16   /* device name max length, */
  57                        /* including unit # and NULL */
  58 
  59 /* Used for controller info */
  60 struct dk_cinfo {
  61      char      dki_cname[DK_DEVLEN];    /* controller name */
  62                                         /* (no unit #) */
  63      ushort_t  dki_ctype;               /* controller type */
  64      ushort_t  dki_flags;               /* flags */
  65      ushort_t  dki_cnum;                /* controller number */
  66      uint_t    dki_addr;                /* controller address */
  67      uint_t    dki_space;               /* controller bus type */
  68      uint_t    dki_prio;                /* interrupt priority */
  69      uint_t    dki_vec;                 /* interrupt vector */
  70      char      dki_dname[DK_DEVLEN];    /* drive name (no unit #) */
  71      uint_t    dki_unit;                /* unit number */
  72      uint_t    dki_slave;               /* slave number */
  73      ushort_t  dki_partition;           /* partition number */
  74      ushort_t  dki_maxtransfer;         /* maximum transfer size */
  75                                         /* in DEV_BSIZE */

  76      };
  77 
  78      /*
  79       * Controller types
  80       */

  81      #define DKC_UNKNOWN      0
  82      #define DKC_CDROM        1         /* CD-ROM, SCSI or other */
  83      #define DKC_WDC2880      2
  84      #define DKC_XXX_0        3         /* unassigned */
  85      #define DKC_XXX_1        4         /* unassigned */
  86      #define DKC_DSD5215      5
  87      #define DKC_ACB4000      7
  88      #define DKC_XXX_2        9         /* unassigned */
  89      #define DKC_NCRFLOPPY    10
  90      #define DKC_SMSFLOPPY    12
  91      #define DKC_SCSI_CCS     13        /* SCSI CCS compatible */
  92      #define DKC_INTEL82072   14        /* native floppy chip */
  93      #define DKC_INTEL82077   19        /* 82077 floppy disk */
  94                                         /* controller */
  95      #define DKC_DIRECT       20        /* Intel direct attached */
  96                                         /* device (IDE) */
  97      #define DKC_PCMCIA_MEM   21        /* PCMCIA memory disk-like */
  98                                         /* type */
  99      #define DKC_PCMCIA_ATA   22        /* PCMCIA AT Attached type */
 100 
 101      /*
 102       * Sun reserves up through 1023
 103       */
 104 
 105      #define DKC_CUSTOMER_BASE  1024
 106 
 107      /*
 108       * Flags
 109       */

 110      #define DKI_BAD144       0x01          /* use  DEC  std  144  */
 111                                             /* bad  sector fwding */
 112      #define DKI_MAPTRK       0x02          /* controller does */
 113                                             /* track mapping */
 114      #define DKI_FMTTRK       0x04          /* formats only  full
 115                                             /* track at a time */
 116      #define DKI_FMTVOL       0x08          /* formats only full */
 117                                             /* volume at a time */
 118      #define DKI_FMTCYL       0x10          /* formats only full */
 119                                             /* cylinders at a time */
 120      #define DKI_HEXUNIT      0x20          /* unit number printed */
 121                                             /* as 3 hexdigits */
 122      #define DKI_PCMCIA_PFD   0x40          /* PCMCIA pseudo-floppy */
 123                                             /* memory card */
 124 .Ed
 125 .It Dv DKIOCGAPART
 126 .Pp
 127 The argument is a pointer to a
 128 .Vt dk_allmap
 129 structure (described below).
 130 This
 131 .Xr ioctl 2
 132 gets the controller's notion of the current partition table



 133 for disk drive.
 134 .It Dv DKIOCSAPART
 135 .Pp
 136 The argument is a pointer to a
 137 .Vt dk_allmap
 138 structure (described below).
 139 This
 140 .Xr ioctl 2
 141 sets the controller's notion of the partition table without



 142 changing the disk itself.
 143 .Bd -literal -offset 2n




 144 /*
 145  * Partition map (part of dk_label)
 146  */
 147 struct dk_map {
 148      daddr_t dkl_cylno;     /* starting cylinder */
 149      daddr_t dkl_nblk;      /* number of blocks */
 150 };
 151 
 152 /*
 153  * Used for all partitions
 154  */
 155 struct dk_allmap {
 156     struct dk_map    dka_map[NDKMAP];
 157 };
 158 .Ed
 159 .It Dv DKIOCGGEOM
 160 .Pp
 161 The argument is a pointer to a
 162 .Vt dk_geom
 163 structure (described below).
 164 This
 165 .Xr ioctl 2
 166 gets the controller's notion of the current geometry of the disk drive.
 167 .It Dv DKIOCSGEOM
 168 .Pp
 169 The argument is a pointer to a
 170 .Vt dk_geom
 171 structure (described below).
 172 This
 173 .Xr ioctl 2
 174 sets the controller's notion of the geometry without changing the disk itself.
 175 .It Dv DKIOCGVTOC
 176 .Pp
 177 The argument is a pointer to a
 178 .Vt vtoc
 179 structure (described below).
 180 This
 181 .Xr ioctl 2
 182 returns the device's current volume table of contents (VTOC).
 183 For disks larger than 1TB,
 184 .Dv DKIOCGEXTVTOC
 185 must be used instead.
 186 .It Dv DKIOCSVTOC
 187 .Pp
 188 The argument is a pointer to a
 189 .Vt vtoc
 190 structure (described below).
 191 This
 192 .Xr ioctl 2
 193 changes the VTOC associated with the device.
 194 For disks larger than 1TB,
 195 .Dv DKIOCSEXTVTOC
 196 must be used instead.
 197 .Bd -literal -offset 2n










 198 struct partition {
 199     ushort_t      p_tag;         /* ID tag of partition */
 200     ushort_t      p_flag;        /* permission flags */
 201     daddr_t       p_start;       /* start sector of partition */
 202     long          p_size;        /* # of blocks in partition */
 203 };
 204 .Ed
 205 .Pp
 206 If
 207 .Dv DKIOCSVTOC
 208 is used with a floppy diskette, the
 209 .Fa p_start
 210 field must be the first sector of a cylinder.
 211 To compute the number of sectors per
 212 cylinder, multiply the number of heads by the number of sectors per track.
 213 .Bd -literal -offset 2n


 214 struct vtoc {
 215     unsigned long     v_bootinfo[3];        /* info needed by mboot */
 216                                             /* (unsupported) */
 217     unsigned long     v_sanity;             /* to verify vtoc */
 218                                             /* sanity */
 219     unsigned long     v_version;            /* layout version */
 220     char              v_volume[LEN_DKL_VVOL]; /* volume name */
 221     ushort_t          v_sectorsz;           /* sector size in bytes */
 222     ushort_t          v_nparts;             /* number of partitions */
 223     unsigned long     v_reserved[10];       /* free space */
 224     struct partition  v_part[V_NUMPAR];     /* partition headers */
 225     time_t            timestamp[V_NUMPAR];  /* partition timestamp */
 226                                             /* (unsupported) */
 227     char              v_asciilabel[LEN_DKL_ASCII]; /* compatibility */
 228 };
 229 
 230 /*
 231  * Partition permission flags
 232  */

 233 #define V_UNMNT      0x01    /* Unmountable partition */
 234 #define V_RONLY      0x10    /* Read only */
 235 
 236 /*
 237  * Partition identification tags
 238  */

 239 #define V_UNASSIGNED   0x00  /* unassigned partition */
 240 #define V_BOOT         0x01  /* Boot partition */
 241 #define V_ROOT         0x02  /* Root filesystem */
 242 #define V_SWAP         0x03  /* Swap filesystem */
 243 #define V_USR          0x04  /* Usr filesystem */
 244 #define V_BACKUP       0x05  /* full disk */
 245 #define V_VAR          0x07  /* Var partition */
 246 #define V_HOME         0x08  /* Home partition */
 247 #define V_ALTSCTR      0x09  /* Alternate sector partition */
 248 .Ed
 249 .It Dv DKIOCGEXTVTOC
 250 .Pp
 251 The argument is a pointer to an
 252 .Vt extvtoc
 253 structure (described below).
 254 This ioctl returns the device's current volume table of contents (VTOC).
 255 VTOC is extended to support a disk up to 2TB in size.
 256 For disks larger than 1TB this ioctl must be used instead of
 257 .Dv DKIOCGVTOC .
 258 .It Dv DKIOCSEXTVTOC
 259 .Pp
 260 The argument is a pointer to an
 261 .Vt extvtoc
 262 structure (described below).
 263 This ioctl changes the VTOC associated with the device.
 264 VTOC is extended to support a disk up to 2TB in size.
 265 For disks larger than 1TB this ioctl must be used instead of
 266 .Vt DKIOCSVTOC .
 267 .Bd -literal -offset 2n










 268 struct extpartition {
 269     ushort_t p_tag;         /* ID tag of partition */
 270     ushort_t p_flag;        /* permission flags */
 271     ushort_t p_pad[2];      /* reserved */
 272     diskaddr_t p_start;     /* start sector no of partition */
 273     diskaddr_t p_size;      /* # of blocks in partition */
 274 };
 275 

 276 struct extvtoc {
 277     uint64_t   v_bootinfo[3]; /* info needed by mboot (unsupported) */
 278     uint64_t   v_sanity;      /* to verify vtoc sanity */
 279     uint64_t   v_version;     /* layout version */
 280     char    v_volume[LEN_DKL_VVOL]; /* volume name */
 281     ushort_t   v_sectorsz;    /* sector size in bytes */
 282     ushort_t   v_nparts;      /* number of partitions */
 283     ushort_t   pad[2];
 284     uint64_t   v_reserved[10];
 285     struct extpartition v_part[V_NUMPAR]; /* partition headers */
 286     uint64_t timestamp[V_NUMPAR]; /* partition timestamp */
 287                                   /* (unsupported) */
 288     char    v_asciilabel[LEN_DKL_ASCII];    /* for compatibility */
 289 };
 290 .Ed
 291 .Pp
 292 Partition permissions flags and identification tags
 293 are defined the same as vtoc structure.
 294 .It Dv DKIOCEJECT
 295 .Pp
 296 If the drive supports removable media, this
 297 .Xr ioctl 2
 298 requests the disk drive to eject its disk.
 299 .It Dv DKIOCREMOVABLE
 300 .Pp
 301 The argument to this
 302 .Xr ioctl 2
 303 is an integer.
 304 After successful completion, this
 305 .Xr ioctl 2
 306 sets that integer to a non-zero value if the drive in
 307 question has removable media.
 308 If the media is not removable, the integer is set to
 309 .Sy 0 .
 310 .It Dv DKIOCHOTPLUGGABLE
 311 .Pp
 312 The argument to this
 313 .Xr ioctl 2
 314 is an integer.
 315 After successful completion, this
 316 .Xr ioctl 2
 317 sets that integer to a non-zero value if the drive in question is hotpluggable.
 318 If the media is not hotpluggable, the integer is set to 0.
 319 .It Dv DKIOCSTATE
 320 .Pp
 321 This
 322 .Xr ioctl 2
 323 blocks until the state of the drive, inserted or ejected, is changed.
 324 The argument is a pointer to a
 325 .Vt dkio_state ,
 326 enum, whose possible enumerations are listed below.
 327 The initial value should be either the last
 328 reported state of the drive, or
 329 .Dv DKIO_NONE .
 330 Upon return, the enum pointed
















 331 to by the argument is updated with the current state of the drive.
 332 .Bd -literal -offset 2n


 333 enum dkio_state {
 334     DKIO_NONE,          /* Return disk's current state */
 335     DKIO_EJECTED,       /* Disk state is 'ejected' */
 336     DKIO_INSERTED       /* Disk state is 'inserted' */
 337 };
 338 .Ed
 339 .It Dv DKIOCLOCK
 340 .Pp
 341 For devices with removable media, this
 342 .Xr ioctl 2
 343 requests the disk drive to lock the door.
 344 .It Dv DKIOCUNLOCK
 345 .Pp
 346 For devices with removable media, this
 347 .Xr ioctl 2
 348 requests the disk drive to unlock the door.
 349 .It Dv DKIOCGMEDIAINFO
 350 .Pp
 351 The argument to this
 352 .Xr ioctl 2
 353 is a pointer to a
 354 .Vt dk_minfo
 355 structure.

















 356 The structure indicates the type of media or the command set profile used by
 357 the drive to operate on the media.
 358 The
 359 .Vt dk_minfo
 360 structure also indicates the logical media block size the drive uses as the
 361 basic unit block size of operation and the raw formatted capacity of the media
 362 in number of logical blocks.
 363 .It Dv DKIOCGMEDIAINFOEXT
 364 .Pp
 365 The argument to this
 366 .Xr ioctl 2
 367 is a pointer to a
 368 .Vt dk_minfo_ext
 369 structure.
 370 The structure indicates the type of media or the command set profile
 371 used by the drive to operate on the media.
 372 The
 373 .Vt dk_minfo_ext
 374 structure
 375 also indicates the logical media block size the drive uses as the basic unit
 376 block size of operation, the raw formatted capacity of the media in number of
 377 logical blocks and the physical block size of the media.
 378 .Bd -literal -offset 2n




 379 /*
 380  * Used for media info or profile info
 381  */
 382 struct dk_minfo {
 383     uint_t dki_media_type;   /* Media type or profile info */
 384     uint_t dki_lbsize;       /* Logical blocksize of media */
 385     diskaddr_t dki_capacity; /* Capacity as # of dki_lbsize blks */
 386 };
 387 
 388 /*
 389  * Used for media info or profile info and physical blocksize
 390  */
 391 struct dk_minfo_ext {
 392     uint_t dki_media_type; /* Media type or profile info */
 393     uint_t dki_lbsize; /* Logical blocksize of media */
 394     diskaddr_t dki_capacity; /* Capacity as # of dki_lbsize blks */
 395     uint_t dki_pbsize; /* Physical blocksize of media */
 396 };
 397 
 398 
 399 /*
 400  * Media types or profiles known
 401  */
 402 #define DK_UNKNOWN         0x00    /* Media inserted - type unknown */
 403 
 404 /*
 405  * SFF 8090 Specification Version 3, media types 0x01 - 0xfffe are
 406  * retained to maintain compatibility with SFF8090.  The following
 407  * define the optical media type.
 408  */
 409 #define DK_MO_ERASABLE     0x03 /* MO Erasable */
 410 #define DK_MO_WRITEONCE    0x04 /* MO Write once */
 411 #define DK_AS_MO           0x05 /* AS MO */
 412 #define DK_CDROM           0x08 /* CDROM */
 413 #define DK_CDR             0x09 /* CD-R */
 414 #define DK_CDRW            0x0A /* CD-RW */
 415 #define DK_DVDROM          0x10 /* DVD-ROM */
 416 #define DK_DVDR            0x11 /* DVD-R */
 417 #define DK_DVDRAM          0x12 /* DVD_RAM or DVD-RW */
 418 
 419 /*
 420  * Media types for other rewritable magnetic media
 421  */
 422 #define DK_FIXED_DISK      0x10001 /* Fixed disk SCSI or otherwise */
 423 #define DK_FLOPPY          0x10002 /* Floppy media */
 424 #define DK_ZIP             0x10003 /* IOMEGA ZIP media */
 425 #define DK_JAZ             0x10004 /* IOMEGA JAZ media */
 426 .Ed
 427 .Pp



 428 If the media exists and the host can obtain a current profile list, the command
 429 succeeds and returns the
 430 .Vt dk_minfo
 431 structure with data representing that media.
 432 .Pp
 433 If there is no media in the drive, the command fails and the host returns an
 434 .Er ENXIO
 435 error, indicating that it cannot gather the information requested.
 436 .Pp
 437 If the profile list is not available, the host attempts to identify the
 438 media-type based on the available information.
 439 .Pp

 440 If identification is not possible, the host returns media type
 441 .Dv DK_UNKNOWN .
 442 See
 443 .Sx NOTES
 444 for blocksize usage and capacity information.
 445 .It Dv DKIOCSMBOOT
 446 .Pp
 447 The argument is a pointer to struct
 448 .Vt mboot .
 449 .Pp
 450 Copies the
 451 .Vt mboot
 452 information supplied in the argument to the absolute sector 0 of the device.
 453 Prior to copying the information, this
 454 .Xr ioctl 2
 455 performs the following checks on the
 456 .Vt mboot
 457 data:
 458 .Bl -bullet -offset indent
 459 .It
 460 Ensures that the signature field is set to 0xAA55.
 461 .It




 462 Ensures that partitions do not overlap.
 463 .It




 464 On SPARC platforms, determines if the device is a removable media.
 465 .El
 466 .Pp
 467 If the above verification fails,
 468 .Va errno
 469 is set to
 470 .Er EINVAL
 471 and the
 472 .Xr ioctl 2
 473 command fails.
 474 .Pp
 475 x86 Platforms \(em Upon successful write of
 476 .Vt mboot ,
 477 the partition map structure maintained in the driver is updated.
 478 If the new Solaris partition is
 479 different from the previous one, the internal VTOC table maintained in the
 480 driver is set as follows:
 481 .Pp
 482 If
 483 .Dv _SUNOS_VTOC_8
 484 is defined:
 485 .Bd -unfilled -offset 4n
 486 Partition: 0 Start: 0 Capacity = Capacity of device.
 487 Partition: 2 Start: 0 Capacity = Capacity of device.
 488 .Ed
 489 .Pp
 490 If
 491 .Dv _SUNOS_VTOC_16
 492 is defined:
 493 .Bd -unfilled -offset 4n
 494 Partition: 2 Start: 0 Size = Size specified in mboot - 2 cylinders.
 495 Partition: 8 Start: 0 Size = Sectors/cylinder.
 496 Partition: 9 Start: Sectors/cylinder  Size = 2 * sectors/cylinder
 497 .Ed
 498 .Pp
 499 To determine if the Solaris partition has changed:
 500 .Bd -offset 4n -ragged
 501 If either offset or the size of the Solaris partition is different from the
 502 previous one then it shall be deemed to have changed.
 503 In all other cases, the
 504 internal VTOC info remains as before.
 505 .Ed
 506 .Pp
 507 SPARC Platforms \(em The VTOC label and
 508 .Vt mboot
 509 both occupy the same location, namely sector 0.
 510 As a result, following the successful write of
 511 .Vt mboot
 512 info, the internal VTOC table maintained in the driver is set as follows:
 513 .Bd -unfilled -offset 4n
 514 Partition: 0  Start: 0  Size = Capacity of device.
 515 Partition: 2  Start: 0  Size = Capacity of device.
 516 .Ed
 517 .Pp
 518 See the
 519 .Sx NOTES
 520 section for usage of
 521 .Dv DKIOCSMBOOT
 522 when modifying Solaris partitions.
 523 .It Dv DKIOCGETVOLCAP
 524 .Pp

 525 This ioctl provides information and status of available capabilities.
 526 .Fa vc_info
 527 is a bitmap and the valid flag values are:
 528 .Pp
 529 .Bl -tag -width DKV_ABR_CAP -compact -offset 2n
 530 .It Dv DKV_ABR_CAP
 531 Capable of application-based recovery
 532 .It Dv DKV_DMR_CAP
 533 Ability to read specific copy of data when multiple copies exist.
 534 For example, in a two way mirror, this ioctl is used to read each
 535 side of the mirror.
 536 .El
 537 .Pp
 538 .Fa vc_set
 539 is a bitmap and the valid flag values are:
 540 .Pp
 541 .Bl -tag -width DKV_ABR_CAP -compact -offset 2n
 542 .It Dv DKV_ABR_CAP
 543 This flag is set if ABR has been set on a device that supports ABR functionality.
 544 .It Dv DKV_DMR_CAP
 545 Directed read has been enabled.
 546 .El
 547 .Pp

 548 These capabilities are not required to be persistent across a system reboot and
 549 their persistence depends upon the implementation.
 550 For example, if the ABR
 551 capability for a DRL mirror simply clears the dirty-region list and
 552 subsequently stops updating this list, there is no reason for persistence
 553 because the VM recovery is a no-op.
 554 Conversely, if the ABR capability is
 555 applied to a non-DRL mirror to indicate that the VM should not perform a full
 556 recovery of the mirror following a system crash, the capability must be
 557 persistent so that the VM know whether or not to perform recovery.
 558 .Pp
 559 Return Errors:
 560 .Pp
 561 .Bl -tag -width ENOTSUP -compact -offset 2n
 562 .It Er EINVAL



 563 Invalid device for this operation.
 564 .It Er ENOTSUP







 565 Functionality that is attempted to be set is not supported.
 566 .El
 567 .It Dv DKIOCSETVOLCAP
 568 .Pp
 569 This ioctl sets the available capabilities for the device.
 570 If a capability flag
 571 is not set in
 572 .Fa vc_set ,
 573 that capability is cleared.
 574 .Pp
 575 .Fa vc_info
 576 flags are ignored.
 577 .Pp
 578 .Fa vc_set
 579 valid flags are:
 580 .Pp
 581 .Bl -tag -width DKV_ABR_CAP -compact -offset 2n
 582 .It Dv DKV_ABR_CAP
 583 Flag to set application-based recovery.
 584 A device can successfully support ABR only if it is capable.
 585 .It Dv DKV_DMR_CAP
 586 Flag to set directed read.
 587 .El
 588 .It Dv DKIODMR
 589 .Pp
 590 .Ft int
 591 .Fo ioctl
 592 .Fa int ,
 593 .\" This could be .Fa as well -- but mandoc doesn't seem to allow both
 594 .Dv DKIODMR ,
 595 .Fa "vol_directed_rd *"
 596 .Fc
 597 .Pp







 598 This ioctl allows highly available applications to perform round-robin reads
 599 from the underlying devices of a replicated device.
 600 .Pp
 601 .Bl -tag -width vdr_bytesread -offset 2n -compact
 602 .It Fa vdr_offset
 603 Offset at which the read should occur.
 604 .It Fa vdr_nbytes
 605 Number of bytes to be read
 606 .It Fa vdr_bytesread
 607 Number of bytes successfully read by the kernel.
 608 .It Fa vdr_data
 609 Pointer to a user allocated buffer to return the data read
 610 .It Fa vdr_side
 611 Side to be read.
 612 Initialized to
 613 .Dv DKV_SIDE_INIT
 614 .It Fa vdr_side_name
 615 The volume name that has been read.
 616 .El
 617 .Pp
 618 Valid
 619 .Fa vdr_flags
 620 are:
 621 .Pp
 622 .Bl -tag -width DKV_DMR_NEXT_SIDE -offset 2n -compact
 623 .It Dv DKV_DMR_NEXT_SIDE
 624 Set by user
 625 .It Dv DKV_DMR_DONE
 626 Return value
 627 .It Dv DKV_DMR_ERROR
 628 Return value
 629 .It Dv DKV_DMR_SUCCESS
 630 Return value
 631 .It Dv DKV_DMR_SHORT
 632 Return value
 633 .El
 634 .Pp
 635 The calling sequence is as follows: The caller sets the
 636 .Fa vdr_flags
 637 to
 638 .Dv DK_DMR_NEXT_SIDE
 639 and
 640 .Fa vdr_side
 641 to
 642 .Dv DKV_SIDE_INIT
 643 at the start.
 644 Subsequent calls should be made without any changes to these values.
 645 If they are changed the results of the ioctl are indeterminate.
 646 .Pp
 647 When
 648 .Dv DKV_SIDE_INIT
 649 is set, the call results in the kernel reading from the first side.
 650 The kernel updates
 651 .Fa vdr_side
 652 to indicate the side that was read, and
 653 .Fa vdr_side_name
 654 to contain the name of that side.
 655 .Fa vdr_data
 656 contains the data that was read.
 657 Therefore to perform a round-robin read all of
 658 the valid sides, there is no need for the caller to change the contents of
 659 .Fa vdr_side .
 660 .Pp
 661 Subsequent
 662 .Xr ioctl 2
 663 calls result in reads from the next valid side until all valid
 664 sides have been read.
 665 On success, the kernel sets
 666 .Dv DKV_DMR_SUCCESS .
 667 The following table shows the values of
 668 .Fa vdr_flags
 669 that are returned when an error occurs:
 670 .Bl -column DKV_DMR_SHORT DKV_SIDE_INIT "Bytes requested cannot" -offset 2n
 671 .It Fa vda_flags Ta Fa vdr_side Ta Notes
 672 .It Dv DKV_DMR_ERROR Ta Dv DKV_SIDE_INIT Ta \&No valid side to read
 673 .It Dv DKV_DMR_DONE Ta Not Init side Ta All valid sides read
 674 .It Dv DKV_DMR_SHORT Ta Any value Ta Bytes requested cannot be read Fa vdr_bytesread No set to bytes actually read
 675 .El






 676 Typical code fragment:
 677 .Bd -literal -offset 2n
 678 enable->vc_set |= DKV_ABR_SET;
 679 retval = ioctl(filedes, DKIOSETVOLCAP, enable);
 680 if (retval != EINVAL || retval != ENOTSUP) {
 681         if (info->vc_set & DKV_DMR_SET) {
 682                 dr->vdr_flags |= DKV_DMR_NEXT_SIDE;
 683                 dr->vdr_side = DKV_SIDE_INIT;
 684                 dr->vdr_nbytes = 1024;
 685                 dr->vdr_offset = 0xff00;
 686                 do {
 687                         rval = ioctl(fildes, DKIODMR, dr);
 688                         if (rval != EINVAL) {
 689                                 /* Process data */
 690                         }
 691                 } while (rval != EINVAL || dr->vdr_flags &
 692                     (DKV_DMR_DONE | DKV_DMR_ERROR | DKV_DMR_SHORT)
 693         }
 694 }
 695 .Ed
 696 .El
 697 .Ss "RETURN VALUES"
 698 Upon successful completion, the value returned is
 699 .Sy 0 .
 700 Otherwise,
 701 .Sy -1
 702 is returned and
 703 .Va errno
 704 is set to indicate the error.
 705 .Ss "x86 Only"
 706 The following
 707 .Xr ioctl 2
 708 requests set and/or retrieve the current disk
 709 controller, partitions, or geometry information on the x86 architecture.
 710 .Bl -tag -width 1n
 711 .It Dv DKIOCG_PHYGEOM
 712 .Pp
 713 The argument is a pointer to a
 714 .Vt dk_geom
 715 structure (described below).
 716 This
 717 .Xr ioctl 2
 718 gets the driver's notion of the physical geometry of the disk drive.
 719 It is functionally identical to the
 720 .Dv DKIOCGGEOM
 721 .Xr ioctl 2 .
 722 .It Dv DKIOCG_VIRTGEOM
 723 .Pp
 724 The argument is a pointer to a
 725 .Vt dk_geom
 726 structure (described below).
 727 This
 728 .Xr ioctl 2
 729 gets the controller's (and hence the driver's) notion of the
 730 virtual geometry of the disk drive.
 731 Virtual geometry is a view of the disk
 732 geometry maintained by the firmware in a host bus adapter or disk controller.
 733 If the disk is larger than 8 Gbytes, this ioctl fails because a CHS-based
 734 geometry is not relevant or useful for this drive.
 735 .Bd -literal -offset 2n




 736 /*
 737  * Definition of a disk's geometry
 738  */
 739 struct dk_geom {
 740     unsigned shor    dkg_ncyl;   /* # of data cylinders */
 741     unsigned shor    dkg_acyl;   /* # of alternate cylinders */
 742     unsigned short   dkg_bcyl;   /* cyl offset (for fixed head */
 743                                  /* area) */
 744     unsigned short   dkg_nhead;  /* # of heads */
 745     unsigned short   dkg_obs1;   /* obsolete */
 746     unsigned short   dkg_nsect;  /* # of sectors per track */
 747     unsigned short   dkg_intrlv; /* interleave factor */
 748     unsigned short   dkg_obs2;   /* obsolete */
 749     unsigned short   dkg_obs3;   /* obsolete */
 750     unsigned short   dkg_apc;    /* alternates per cylinder */
 751                                  /* (SCSI only) */
 752     unsigned short   dkg_rpm;    /* revolutions per min */
 753     unsigned short   dkg_pcyl;   /* # of physical cylinders */
 754     unsigned short   dkg_write_reinstruct; /* # sectors to skip, */
 755                                            /* writes */
 756     unsigned short   dkg_read_reinstruct;  /* # sectors to skip ,*/
 757                                            /* reads */
 758     unsigned short   dkg_extra[7]; /* for compatible expansion */
 759 };
 760 .Ed
 761 .It Dv DKIOCADDBAD
 762 .Pp
 763 This
 764 .Xr ioctl 2
 765 forces the driver to re-examine the alternates slice and
 766 rebuild the internal bad block map accordingly.
 767 It should be used whenever the
 768 alternates slice is changed by any method other than the
 769 .Xr addbadsec 1M
 770 or
 771 .Xr format 1M
 772 utilities.
 773 .Dv DKIOCADDBAD
 774 can only be used for software
 775 remapping on
 776 .Sy IDE
 777 drives;
 778 .Sy SCSI
 779 drives use hardware remapping of alternate sectors.
 780 .It Dv DKIOCPARTINFO
 781 .Pp
 782 The argument is a pointer to a
 783 .Vt part_info
 784 structure (described below).
 785 This
 786 .Xr ioctl 2
 787 gets the driver's notion of the size and extent of the
 788 partition or slice indicated by the file descriptor argument.
 789 .Bd -literal -offset 2n


 790 /*
 791  * Used by applications to get partition or slice information
 792  */
 793 struct part_info {
 794     daddr_t    p_start;
 795     int        p_length;
 796 };
 797 .Ed
 798 .It Dv DKIOCEXTPARTINFO
 799 .Pp
 800 The argument is a pointer to an
 801 .Vt extpart_info
 802 structure (described below).







 803 This ioctl gets the driver's notion of the size and extent of the partition or
 804 slice indicated by the file descriptor argument.
 805 On disks larger than 1TB, this ioctl must be used instead of
 806 .Dv DKIOCPARTINFO .
 807 .Bd -literal -offset 2n

 808 /*
 809  * Used by applications to get partition or slice information
 810  */
 811 struct extpart_info {
 812     diskkaddr_t      p_start;
 813     diskaddr_t       p_length;
 814 };
 815 .Ed
 816 .It Dv DKIOCSETEXTPART
 817 .Pp









 818 This ioctl is used to update the in-memory copy of the logical drive
 819 information maintained by the driver.
 820 The ioctl takes no arguments.
 821 It causes a re-read of the partition information and recreation of minor nodes
 822 if required.
 823 Prior to updating the data structures, the ioctl ensures that the partitions do
 824 not overlap.
 825 Device nodes are created only for valid partition entries.
 826 If there is any change in the partition offset, size or ID from the previous
 827 read, the partition is deemed to have been changed and hence the device nodes
 828 are recreated.
 829 Any modification to any of the logical partitions results in the
 830 recreation of all logical device nodes.
 831 .El
 832 .Sh SEE ALSO
 833 .Xr addbadsec 1M ,
 834 .Xr fdisk 1M ,
 835 .Xr format 1M ,
 836 .Xr ioctl 2 ,
 837 .Xr cmdk 7D ,
 838 .Xr sd 7D ,
 839 .Xr cdio 7I ,
 840 .Xr fdio 7I ,
 841 .Xr hdio 7I
 842 .Sh NOTES
 843 Blocksize information provided in
 844 .Dv DKIOCGMEDIAINFO
 845 is the size (in bytes) of the device's basic unit of operation and can differ
 846 from the blocksize that the Solaris operating environment exports to the user.
 847 Capacity information provided in the
 848 .Dv DKIOCGMEDIAINFO
 849 are for reference only and you are advised to use the values returned by
 850 .Dv DKIOCGGEOM
 851 or other appropriate
 852 .Xr ioctl 2
 853 for accessing data using the standard interfaces.
 854 .Pp
 855 For x86 only: If the
 856 .Dv DKIOCSMBOOT
 857 command is used to modify the Solaris partitions, the VTOC information should
 858 also be set appropriately to reflect the changes to partition.
 859 Failure to do so leads to unexpected results when the
 860 device is closed and reopened fresh at a later time.
 861 This is because a default VTOC is assumed by driver when a Solaris partition
 862 is changed.
 863 The default VTOC persists until the ioctl
 864 .Dv DKIOCSVTOC
 865 is called to modify VTOC or the device is closed and reopened.
 866 At that point, the old valid VTOC is read from
 867 the disk if it is still available.