changeset 7563:84ec90ffc3f7

PSARC/2008/336 Extended VTOC 6708609 Support booting on disks > 1TB (phase 1) 6672960 cmlb: default minor nodes for disks > 1TB is not EFI/GPT style 6727240 When a fat32 partition created in the part of the disk after 1TB, block I/O and umount fail
author Prasad Singamsetty <Prasad.Singamsetty@Sun.COM>
date Thu, 11 Sep 2008 18:00:50 -0700
parents 770b950e4950
children 34c3bf16874f
files usr/src/cmd/boot/Makefile usr/src/cmd/boot/installgrub/floppy.c usr/src/cmd/boot/installgrub/installgrub.c usr/src/cmd/boot/mbr/mbr.c usr/src/cmd/boot/scripts/root_archive.ksh usr/src/cmd/devinfo/devinfo.c usr/src/cmd/devmgmt/mkdtab/mkdtab.c usr/src/cmd/diskscan/diskscan.c usr/src/cmd/fdisk/fdisk.c usr/src/cmd/fmthard/fmthard.c usr/src/cmd/format/Makefile usr/src/cmd/format/analyze.c usr/src/cmd/format/analyze.h usr/src/cmd/format/auto_sense.c usr/src/cmd/format/badsec.h usr/src/cmd/format/ctlr_ata.c usr/src/cmd/format/ctlr_ata.h usr/src/cmd/format/ctlr_scsi.c usr/src/cmd/format/defect.c usr/src/cmd/format/disk_generic.c usr/src/cmd/format/global.h usr/src/cmd/format/hardware_structs.h usr/src/cmd/format/io.c usr/src/cmd/format/io.h usr/src/cmd/format/ix_altsctr.c usr/src/cmd/format/label.c usr/src/cmd/format/label.h usr/src/cmd/format/main.c usr/src/cmd/format/menu_analyze.c usr/src/cmd/format/menu_command.c usr/src/cmd/format/menu_defect.c usr/src/cmd/format/menu_fdisk.c usr/src/cmd/format/menu_partition.c usr/src/cmd/format/menu_scsi.c usr/src/cmd/format/misc.c usr/src/cmd/format/misc.h usr/src/cmd/format/modify_partition.c usr/src/cmd/format/param.h usr/src/cmd/format/partition.c usr/src/cmd/format/startup.c usr/src/cmd/fs.d/pcfs/fsck/pcfs_common.c usr/src/cmd/fs.d/pcfs/mkfs/mkfs.c usr/src/cmd/fs.d/ufs/fsck/utilities.c usr/src/cmd/fs.d/ufs/mkfs/mkfs.c usr/src/cmd/fs.d/ufs/newfs/newfs.c usr/src/cmd/fstyp/fstyp.c usr/src/cmd/hal/probing/storage/probe-storage.c usr/src/cmd/hal/probing/volume/probe-volume.c usr/src/cmd/hal/utils/fsutils.c usr/src/cmd/hal/utils/fsutils.h usr/src/cmd/iscsi/iscsitgtd/mgmt_create.c usr/src/cmd/lvm/rpc.metamhd/mhd_drive.c usr/src/cmd/prtvtoc/prtvtoc.c usr/src/cmd/rmformat/rmf_main.c usr/src/cmd/rmformat/rmf_menu.c usr/src/cmd/rmformat/rmf_misc.c usr/src/cmd/rmformat/rmf_slice.c usr/src/cmd/smserverd/smediad.c usr/src/common/fs/decompress.c usr/src/common/fs/ufsops.c usr/src/grub/grub-0.95/grub/asmstub.c usr/src/grub/grub-0.95/stage2/bios.c usr/src/grub/grub-0.95/stage2/builtins.c usr/src/grub/grub-0.95/stage2/disk_io.c usr/src/grub/grub-0.95/stage2/shared.h usr/src/grub/grub-0.95/stage2/stage1_5.c usr/src/grub/install_menu usr/src/head/meta.h usr/src/lib/libadm/common/mapfile-vers usr/src/lib/libadm/common/rdwr_vtoc.c usr/src/lib/libdiskmgt/common/media.c usr/src/lib/libdiskmgt/common/slice.c usr/src/lib/libefi/common/rdwr_efi.c usr/src/lib/lvm/libmeta/common/meta_devstamp.c usr/src/lib/lvm/libmeta/common/meta_getdevs.c usr/src/lib/lvm/libmeta/common/meta_nameinfo.c usr/src/pkgdefs/SUNWckr/prototype_i386 usr/src/pkgdefs/SUNWcsr/prototype_com usr/src/pkgdefs/SUNWcsr/prototype_sparc usr/src/pkgdefs/SUNWcsu/prototype_com usr/src/pkgdefs/SUNWcsu/prototype_sparc usr/src/uts/common/fs/pcfs/pc_dir.c usr/src/uts/common/fs/pcfs/pc_vfsops.c usr/src/uts/common/fs/ufs/ufs_vnops.c usr/src/uts/common/io/cmlb.c usr/src/uts/common/io/lvm/md/md_ioctl.c usr/src/uts/common/io/lvm/md/md_subr.c usr/src/uts/common/io/lvm/mirror/mirror_ioctl.c usr/src/uts/common/io/lvm/raid/raid_ioctl.c usr/src/uts/common/io/lvm/softpart/sp_ioctl.c usr/src/uts/common/io/lvm/stripe/stripe_ioctl.c usr/src/uts/common/io/lvm/trans/trans_ioctl.c usr/src/uts/common/io/scsi/targets/sd.c usr/src/uts/common/os/dumpsubr.c usr/src/uts/common/sys/cmlb_impl.h usr/src/uts/common/sys/dkio.h usr/src/uts/common/sys/dklabel.h usr/src/uts/common/sys/dktp/altsctr.h usr/src/uts/common/sys/dktp/dadkio.h usr/src/uts/common/sys/dktp/fdisk.h usr/src/uts/common/sys/dktp/gda.h usr/src/uts/common/sys/dktp/tgdk.h usr/src/uts/common/sys/lvm/mdvar.h usr/src/uts/common/sys/lvm/meta_basic.x usr/src/uts/common/sys/vtoc.h usr/src/uts/common/xen/io/xdf.c usr/src/uts/i86pc/i86hvm/io/pv_cmdk.c usr/src/uts/i86pc/i86hvm/pv_cmdk/Makefile usr/src/uts/intel/Makefile.intel.shared usr/src/uts/intel/cmdk/Makefile usr/src/uts/intel/cmlb/Makefile usr/src/uts/intel/dadk/Makefile usr/src/uts/intel/dcfs/Makefile usr/src/uts/intel/io/dktp/dcdev/dadk.c usr/src/uts/intel/io/dktp/dcdev/gda.c usr/src/uts/intel/io/dktp/disk/cmdk.c usr/src/uts/sparc/cmlb/Makefile usr/src/uts/sun4v/io/vdc.c usr/src/uts/sun4v/io/vds.c usr/src/uts/sun4v/sys/vdc.h usr/src/uts/sun4v/vdc/Makefile usr/src/uts/sun4v/vds/Makefile
diffstat 122 files changed, 3618 insertions(+), 2213 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/boot/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/boot/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -19,11 +19,9 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 
 include $(SRC)/cmd/Makefile.cmd
 
@@ -31,6 +29,7 @@
 
 COMMON_SUBDIRS=		\
 	filelist	\
+	fiocompress	\
 	scripts		\
 	bootadm
 
@@ -39,28 +38,21 @@
 	mbr		\
 	symdef
 
-sparc_SUBDIRS=		\
-	fiocompress
-
 COMMON_LINTSUBDIRS=	\
 	bootadm	
 
 i386_LINTSUBDIRS=	\
+	fiocompress	\
 	installgrub	\
 	symdef
 
-sparc_LINTSUBDIRS=	\
+COMMON_MSGSUBDIRS=	\
+	bootadm		\
 	fiocompress
 
-COMMON_MSGSUBDIRS=	\
-	bootadm
-
 i386_MSGSUBDIRS=	\
 	installgrub
 
-sparc_MSGSUBDIRS=	\
-	fiocompress
-
 
 all:=		TARGET= all
 install:=	TARGET= install
--- a/usr/src/cmd/boot/installgrub/floppy.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/boot/installgrub/floppy.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -51,7 +48,7 @@
 #define	DEV_BSIZE	512
 #define	MAX_CHUNK	64
 
-static int *blocklist;
+static unsigned int *blocklist;
 
 /* diskread_callback is set in filesytem module (pcfs.c) */
 int (*diskread_callback)(int, int);
@@ -171,7 +168,7 @@
  * Get the blocklist for stage2
  */
 int
-read_stage2_blocklist(int device_fd, int *blkbuf)
+read_stage2_blocklist(int device_fd, unsigned int *blkbuf)
 {
 	int i, fd, stage2_block;
 	char buf[DEV_BSIZE];
--- a/usr/src/cmd/boot/installgrub/installgrub.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/boot/installgrub/installgrub.c	Thu Sep 11 18:00:50 2008 -0700
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <libgen.h>
@@ -74,14 +72,14 @@
 static int is_bootpar = 0;
 static int stage2_fd;
 static int partition, slice = 0xff;
-static int stage2_first_sector, stage2_second_sector;
+static unsigned int stage2_first_sector, stage2_second_sector;
 
 
 static char bpb_sect[SECTOR_SIZE];
 static char boot_sect[SECTOR_SIZE];
 static char stage1_buffer[SECTOR_SIZE];
 static char stage2_buffer[2 * SECTOR_SIZE];
-static int blocklist[SECTOR_SIZE / sizeof (int)];
+static unsigned int blocklist[SECTOR_SIZE / sizeof (unsigned int)];
 
 static int open_device(char *);
 static void read_bpb_sect(int);
@@ -90,12 +88,12 @@
 static void read_stage1_stage2(char *, char *);
 static void modify_and_write_stage1(int);
 static void modify_and_write_stage2(int);
-static int get_start_sector(int);
+static unsigned int get_start_sector(int);
 static void copy_stage2(int, char *);
 static char *get_raw_partition(char *);
 static void usage(char *);
 
-extern int read_stage2_blocklist(int, int *);
+extern int read_stage2_blocklist(int, unsigned int *);
 
 int
 main(int argc, char *argv[])
@@ -169,10 +167,10 @@
 	return (0);
 }
 
-static int
+static unsigned int
 get_start_sector(int fd)
 {
-	static int start_sect = 0;
+	static unsigned int start_sect = 0;
 
 	int i;
 	struct mboot *mboot;
@@ -196,15 +194,20 @@
 
 	if (i == FD_NUMPART) {
 		struct part_info dkpi;
+		struct extpart_info edkpi;
 
 		/*
 		 * Get the solaris partition information from the device
 		 * and compare the offset of S2 with offset of solaris partition
 		 * from fdisk partition table.
 		 */
-		if (ioctl(fd, DKIOCPARTINFO, &dkpi) < 0) {
-			(void) fprintf(stderr, PART_FAIL);
-			exit(-1);
+		if (ioctl(fd, DKIOCEXTPARTINFO, &edkpi) < 0) {
+			if (ioctl(fd, DKIOCPARTINFO, &dkpi) < 0) {
+				(void) fprintf(stderr, PART_FAIL);
+				exit(-1);
+			} else {
+				edkpi.p_start = dkpi.p_start;
+			}
 		}
 
 		for (i = 0; i < FD_NUMPART; i++) {
@@ -214,8 +217,8 @@
 				(void) fprintf(stderr, BAD_PART, i);
 				exit(-1);
 			}
-			if (dkpi.p_start >= part->relsect &&
-			    dkpi.p_start < (part->relsect + part->numsect)) {
+			if (edkpi.p_start >= part->relsect &&
+			    edkpi.p_start < (part->relsect + part->numsect)) {
 				/* Found the partition */
 				break;
 			}
--- a/usr/src/cmd/boot/mbr/mbr.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/boot/mbr/mbr.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <stdio.h>
 #include <sys/types.h>
 #include <string.h>
@@ -135,7 +132,7 @@
 			sol_part = i;
 		}
 		if (!list_hd)
-			printf("%d (0x%2x): start_sect %d, size_sect %d\n",
+			printf("%d (0x%2x): start_sect %u, size_sect %u\n",
 			    i + 1, part->systid, part->relsect, part->numsect);
 	}
 
--- a/usr/src/cmd/boot/scripts/root_archive.ksh	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/boot/scripts/root_archive.ksh	Thu Sep 11 18:00:50 2008 -0700
@@ -23,7 +23,6 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
 
 # utility to pack and unpack a boot/root archive
 # both ufs and hsfs (iso9660) format archives are unpacked
@@ -41,11 +40,6 @@
 #   Solaris media and all the things that don't go into the ramdisk image
 #   are (un)cpio'd as well
 #
-# This utility is also used to pack parts (in essence the window system,
-# usr/dt and usr/openwin) of the non ramdisk SPARC
-# miniroot. (un)packmedia will recognize that they are being run a SPARC
-# miniroot and do the appropriate work.
-#
 
 usage()
 {
@@ -67,6 +61,7 @@
 		rm -f "$TMR"
 	fi
 	rm -f "$TMR.gz"
+	rm -f /tmp/flist$$
 }
 
 preload_Gnome()
@@ -409,12 +404,20 @@
 
 	(
 		cd "$MINIROOT"
-		find usr/lib/install usr/snadm usr/sbin | \
-		    cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR"/lu.cpio.bz2
+		find usr/lib/install usr/snadm usr/sbin \
+		    boot/grub boot/solaris/bootenv.rc \
+		    tmp/root/boot/grub tmp/root/boot/solaris/bootenv.rc \
+		    2> /dev/null | cpio -ocmPuB 2> /dev/null | bzip2 \
+		    > "$CPIO_DIR"/lu.cpio.bz2
 		ls platform > "$CPIO_DIR/lu.platforms"
 	)
 }
 
+cleanout_pkgdata()
+{
+	rm -Rf tmp/root/var/sadm/install tmp/root/var/sadm/pkg
+}
+
 packmedia()
 {
 	MEDIA="$1"
@@ -483,13 +486,11 @@
 		find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \
 		    cpio -ocmPuB 2> /dev/null | bzip2 > \
 		    "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2"
-	)
-	rm -rf "$MINIROOT/tmp/root/var/sadm/install"
-	rm -rf "$MINIROOT/tmp/root/var/sadm/pkg"
 
-	if [ -d "$MINIROOT/kernel/drv/sparcv9" ] ; then
-		archive_lu "$MEDIA" "$MINIROOT"
-	fi
+		cleanout_pkgdata
+	)
+
+	archive_lu "$MEDIA" "$MINIROOT"
 
 	archive_X "$MEDIA" "$MINIROOT"
 
@@ -512,6 +513,7 @@
 		# 32-bit archives and miniroot
 
 		unpackmedia "$MEDIA" "$MINIROOT"
+		cleanout_pkgdata
 		mkdir -p "$MEDIA/$RELEASE/Tools/Boot/amd64"
 		for i in $ARCHIVES; do
 			mv "$MEDIA/$RELEASE/Tools/Boot/${i}.cpio.bz2" \
@@ -630,7 +632,7 @@
 		exit 1
 	fi
 
-	if [ `basename $MR` = x86.miniroot ] ; then
+	if [ `uname -i` = i86pc ] ; then
 		gzcat "$MR" > $TMR
 	else
 		REALTHING=true ; export REALTHING
@@ -688,21 +690,49 @@
 
 		done
 
+		wait `pgrep fiocompress`
+
 		# now re-copy a couple of uncompressed files
-		#
 
-		find kernel platform -name unix | cpio -pdum $DST 2> /dev/null
-		find kernel platform -name genunix | cpio -pdum $DST \
-		    2> /dev/null
-		find kernel platform -name platmod | cpio -pdum $DST \
-		    2> /dev/null
-		find `find kernel platform -name cpu` | cpio -pdum $DST \
-		    2> /dev/null
-		find `find kernel platform -name kmdb\*` | cpio -pdum $DST \
-		    2> /dev/null
-		find kernel/misc/sparcv9/ctf kernel/fs/sparcv9/dcfs \
-		    etc/system etc/name_to_major etc/path_to_inst \
-		    etc/name_to_sysnum | cpio -pdum $DST 2> /dev/null
+		if [ -d "$SRC/platform/i86pc" ] ; then
+			find `cat boot/solaris/filelist.ramdisk` -type file \
+			    -print 2> /dev/null > /tmp/flist$$
+			find usr/kernel -type file -print 2> /dev/null \
+			    >> /tmp/flist$$
+			# some of the files are replaced with links into
+			# tmp/root on the miniroot, so find the backing files
+			# from there as well and add them to the list ti
+			# be copied uncompressed
+			(
+				cd $SRC/tmp/root
+				find `cat ../../boot/solaris/filelist.ramdisk` \
+				    -type file -print 2> /dev/null | \
+				    sed 's#^#tmp/root/#' >> /tmp/flist$$
+			)
+			flist=`cat /tmp/flist$$`
+			(
+				cd $DST
+				rm -f $flist
+			)
+			for file in $flist ; do
+				echo $file | cpio -pdum $DST 2> /dev/null
+			done
+		else
+			find kernel platform -name unix | \
+			    cpio -pdum $DST 2> /dev/null
+			find kernel platform -name genunix | cpio -pdum $DST \
+			    2> /dev/null
+			find kernel platform -name platmod | cpio -pdum $DST \
+			    2> /dev/null
+			find `find kernel platform -name cpu` | \
+			    cpio -pdum $DST 2> /dev/null
+			find `find kernel platform -name kmdb\*` | \
+				cpio -pdum $DST 2> /dev/null
+			find kernel/misc/sparcv9/ctf kernel/fs/sparcv9/dcfs \
+			    kernel/misc/ctf kernel/fs/dcfs \
+			    etc/system etc/name_to_major etc/path_to_inst \
+			    etc/name_to_sysnum | cpio -pdum $DST 2> /dev/null
+		fi
 	)
 }
 
@@ -724,10 +754,9 @@
 		exit 1
 	fi
 
-	# always compress on sparc if fiocompress exists
+	# always compress if fiocompress exists
 	#
-	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] && \
-	    [ -x /usr/sbin/fiocompress ] ; then
+	if [ -x /usr/sbin/fiocompress ] ; then
 		COMPRESS=true
 	fi
 
@@ -750,7 +779,7 @@
 	    {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
 	    END {print int(t * 1.10 / 1024)}')
 	if [ "$COMPRESS" = true ] ; then
-		size=`echo $size | nawk '{s = $1} END {print int(s * .53)}'`
+		size=`echo $size | nawk '{s = $1} END {print int(s * 0.6)}'`
 	fi
 
 	/usr/sbin/mkfile ${size}k "$TMR"
--- a/usr/src/cmd/devinfo/devinfo.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/devinfo/devinfo.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,16 +18,15 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  *	Two output fields under the -i option will always be
  *	output as zero, since they are not supported by Sun:
@@ -62,7 +61,7 @@
 
 static	void	partinfo(int fd, char *device);
 static	void	devinfo(struct dk_geom *geom, int fd, char *device);
-static	int	readvtoc(int fd, char *name, struct vtoc *vtoc);
+static	int	readvtoc(int fd, char *name, struct extvtoc *vtoc);
 static	int	warn(char *what, char *why);
 static	void	usage(void);
 
@@ -133,7 +132,7 @@
 	major_t maj;
 	minor_t min;
 	struct stat64 statbuf;
-	struct vtoc vtdata;
+	struct extvtoc vtdata;
 	struct dk_gpt *efi;
 
 	i = stat64(device, &statbuf);
@@ -144,7 +143,7 @@
 
 	if ((slice = readvtoc(fd, device, &vtdata)) >= 0) {
 
-		(void) printf("%s\t%0lx\t%0lx\t%ld\t%ld\t%x\t%x\n",
+		(void) printf("%s\t%0lx\t%0lx\t%llu\t%llu\t%x\t%x\n",
 			device, maj, min,
 			vtdata.v_part[slice].p_start,
 			vtdata.v_part[slice].p_size,
@@ -168,7 +167,7 @@
 {
 	int i;
 	unsigned int nopartitions, sectorcyl, bytes;
-	struct vtoc vtdata;
+	struct extvtoc vtdata;
 /*
  *	unsigned int version = 0;
  *	unsigned int driveid = 0;
@@ -207,11 +206,11 @@
  * Read a partition map.
  */
 static int
-readvtoc(int fd, char *name, struct vtoc *vtoc)
+readvtoc(int fd, char *name, struct extvtoc *vtoc)
 {
 	int	retval;
 
-	retval = read_vtoc(fd, vtoc);
+	retval = read_extvtoc(fd, vtoc);
 
 	switch (retval) {
 		case (VT_ERROR):
--- a/usr/src/cmd/devmgmt/mkdtab/mkdtab.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/devmgmt/mkdtab/mkdtab.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,14 +19,12 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include	<stdio.h>
 #include	<stdlib.h>
 #include	<string.h>
@@ -59,10 +56,10 @@
 #define	ORIGLEN	1024
 
 struct dpart {
-	char	alias[20];
-	char	*cdevice;
-	char	*bdevice;
-	long	capacity;
+	char		alias[20];
+	char		*cdevice;
+	char		*bdevice;
+	diskaddr_t	capacity;
 };
 
 static int		vfsnum;
@@ -97,15 +94,16 @@
 static void
 fdisk(const int diskno, const char *disknm)
 {
-	if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev -a diskette%d \
-cdevice=/dev/r%s bdevice=/dev/%s desc=\"Floppy Drive\" \
-mountpt=/mnt volume=diskette \
-type=diskette removable=true capacity=2880 \
-fmtcmd=\"/usr/bin/fdformat -f -v /dev/r%s\" \
-erasecmd=\"/usr/sbin/fdformat -f -v /dev/r%s\" \
-removecmd=\"/usr/bin/eject\" copy=true \
-mkfscmd=\"/usr/sbin/mkfs -F ufs /dev/r%s 2880 18 2 4096 512 80 2 5 3072 t\"",
-diskno, disknm, disknm, disknm, disknm, disknm) >= lastlen) {
+	if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev -a diskette%d "
+	    "cdevice=/dev/r%s bdevice=/dev/%s desc=\"Floppy Drive\" "
+	    "mountpt=/mnt volume=diskette "
+	    "type=diskette removable=true capacity=2880 "
+	    "fmtcmd=\"/usr/bin/fdformat -f -v /dev/r%s\" "
+	    "erasecmd=\"/usr/sbin/fdformat -f -v /dev/r%s\" "
+	    "removecmd=\"/usr/bin/eject\" copy=true "
+	    "mkfscmd=\"/usr/sbin/mkfs -F ufs /dev/r%s 2880 18 "
+	    "2 4096 512 80 2 5 3072 t\"",
+	    diskno, disknm, disknm, disknm, disknm, disknm) >= lastlen) {
 		(void) fprintf(stderr,
 		    "%s: Command too long: %s\n", cmd, putdevcmd);
 		exit(1);
@@ -147,7 +145,7 @@
 	char		*bdskpath;
 	char		*mountpoint;
 	int		i, j, dpartcnt, fd;
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	static struct dpart    *dparttab;
 
 	if ((cdskpath = (char *)malloc(strlen(drivepfx) + 13)) == NULL) {
@@ -166,7 +164,7 @@
 	/*
 	 * Read volume table of contents.
 	 */
-	if (read_vtoc(fd, &vtoc) < 0) {
+	if (read_extvtoc(fd, &vtoc) < 0) {
 		(void) close(fd);
 		free(cdskpath);
 		return;
@@ -186,11 +184,11 @@
 
 	(void) snprintf(bdskpath, strlen(drivepfx) + 13, "/dev/dsk/%ss2",
 	    drivepfx);
-	if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev -a disk%d \
-cdevice=%s bdevice=%s \
-desc=\"Disk Drive\" type=disk \
-part=true removable=false capacity=%ld dpartlist=",
-	    drive, cdskpath, bdskpath, vtoc.v_part[6].p_size) >= lastlen) {
+	if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev -a disk%d "
+	    "cdevice=%s bdevice=%s "
+	    "desc=\"Disk Drive\" type=disk "
+	    "part=true removable=false capacity=%llu dpartlist=",
+	    drive, cdskpath, bdskpath, vtoc.v_part[2].p_size) >= lastlen) {
 		(void) fprintf(stderr,
 		    "%s: Command too long: %s\n", cmd, putdevcmd);
 		exit(1);
@@ -205,11 +203,10 @@
 	 */
 
 	if ((dparttab =
-		(struct dpart *)malloc((int)vtoc.v_nparts *
-				sizeof (struct dpart))) == NULL) {
+	    (struct dpart *)malloc((int)vtoc.v_nparts *
+	    sizeof (struct dpart))) == NULL) {
 		(void) fprintf(stderr,
-			"%s: can't disk partitions table: Out of memory\n",
-			cmd);
+		    "%s: can't disk partitions table: Out of memory\n", cmd);
 		exit(1);
 	}
 
@@ -221,7 +218,7 @@
 		    i);
 
 		if ((dparttab[dpartcnt].cdevice =
-			(char *)malloc(strlen(drivepfx) + 14)) == NULL) {
+		    (char *)malloc(strlen(drivepfx) + 14)) == NULL) {
 			(void) fprintf(stderr, "%s: Out of memory\n", cmd);
 			exit(1);
 		}
@@ -229,7 +226,7 @@
 		(void) snprintf(dparttab[dpartcnt].cdevice,
 		    strlen(drivepfx) + 14, "/dev/rdsk/%ss%x", drivepfx, i);
 		if ((dparttab[dpartcnt].bdevice =
-			(char *)malloc(strlen(drivepfx) + 14)) == NULL) {
+		    (char *)malloc(strlen(drivepfx) + 14)) == NULL) {
 			(void) fprintf(stderr, "%s: Out of memory\n", cmd);
 			exit(1);
 		}
@@ -253,7 +250,7 @@
 		for (j = 0; j < vfsnum; j++) {
 			if (vfstab[j].vfs_special != NULL &&
 			    strcmp(dparttab[i].bdevice,
-				vfstab[j].vfs_special) == 0)
+			    vfstab[j].vfs_special) == 0)
 				break;
 		}
 		if (j < vfsnum) {
@@ -262,14 +259,17 @@
 			 */
 			if (vfstab[j].vfs_mountp == NULL ||
 			    strcmp(vfstab[j].vfs_mountp, "-") == 0)
-				mountpoint="/mnt";
+				mountpoint = "/mnt";
 			else
-				mountpoint=vfstab[j].vfs_mountp;
-			if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev \
--a %s cdevice=%s bdevice=%s desc=\"Disk Partition\" type=dpart removable=false \
-capacity=%ld dparttype=fs fstype=%s mountpt=%s", dparttab[i].alias,
-dparttab[i].cdevice, dparttab[i].bdevice, dparttab[i].capacity,
-vfstab[j].vfs_fstype, mountpoint) >= lastlen) {
+				mountpoint = vfstab[j].vfs_mountp;
+			if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev "
+			    "-a %s cdevice=%s bdevice=%s "
+			    "desc=\"Disk Partition\" type=dpart "
+			    "removable=false capacity=%llu dparttype=fs "
+			    "fstype=%s mountpt=%s", dparttab[i].alias,
+			    dparttab[i].cdevice, dparttab[i].bdevice,
+			    dparttab[i].capacity, vfstab[j].vfs_fstype,
+			    mountpoint) >= lastlen) {
 					(void) fprintf(stderr,
 					    "%s: Command too long: %s\n",
 					    cmd, putdevcmd);
@@ -319,12 +319,12 @@
 static void
 tape(const int driveno, const char *drivenm)
 {
-	if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev -a ctape%d \
-cdevice=/dev/rmt/%s \
-desc=\"Tape Drive\" volume=\"tape\" \
-type=ctape removable=true capacity=45539 bufsize=15872 \
-erasecmd=\"/usr/bin/mt -f /dev/rmt/%s erase\" \
-removecmd=\"/usr/bin/mt -f /dev/rmt/%s offline\"",
+	if (snprintf(putdevcmd, lastlen, "/usr/bin/putdev -a ctape%d "
+	    "cdevice=/dev/rmt/%s "
+	    "desc=\"Tape Drive\" volume=\"tape\" "
+	    "type=ctape removable=true capacity=45539 bufsize=15872 "
+	    "erasecmd=\"/usr/bin/mt -f /dev/rmt/%s erase\" "
+	    "removecmd=\"/usr/bin/mt -f /dev/rmt/%s offline\"",
 	    driveno, drivenm, drivenm, drivenm) >= lastlen) {
 		(void) fprintf(stderr,
 		    "%s: Command too long: %s\n", cmd, putdevcmd);
@@ -369,7 +369,7 @@
 	if ((fp = fopen("/etc/vfstab", "r")) == NULL) {
 		(void) fprintf(stderr,
 		    "%s: can't update device tables:Can't open /etc/vfstab\n",
-			cmd);
+		    cmd);
 		exit(1);
 	}
 
@@ -385,8 +385,7 @@
 	if ((vfstab = (struct vfstab *)malloc(vfsnum * sizeof (struct vfstab)))
 	    == NULL) {
 		(void) fprintf(stderr,
-			"%s: can't update device tables:Out of memory\n",
-		    cmd);
+		    "%s: can't update device tables:Out of memory\n", cmd);
 		exit(1);
 	}
 
@@ -432,7 +431,7 @@
 
 	if (putdevcmd == NULL) {
 		perror("malloc");
-		exit (-1);
+		exit(-1);
 	}
 
 	(void) memset(putdevcmd, 0, ORIGLEN);
--- a/usr/src/cmd/diskscan/diskscan.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/diskscan/diskscan.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  *   diskscan:
  *   performs a verification pass over a device specified on command line;
@@ -49,7 +46,7 @@
 static void verexit();	/* signal handler and exit routine	*/
 static void report();	   /* tell user how we're getting on */
 static void scandisk(char *device, int devfd, int writeflag);
-static void report(char *what, int sector);
+static void report(char *what, diskaddr_t sector);
 static void verexit(int code);
 
 #define	TRUE		1
@@ -60,8 +57,8 @@
 static char	*progname;
 static struct  dk_geom	dkg;	  /* physical device boot info */
 static char	replybuf[64];	  /* used for user replies to questions */
-static daddr_t unix_base;	  /* first sector of UNIX System partition */
-static daddr_t unix_size;	  /* # sectors in UNIX System partition */
+static diskaddr_t unix_base;	  /* first sector of UNIX System partition */
+static diskaddr_t unix_size;	  /* # sectors in UNIX System partition */
 static long	numbadrd = 0;	  /* number of bad sectors on read */
 static long	numbadwr = 0;	  /* number of bad sectors on write */
 static char	eol = '\n';	  /* end-of-line char (if -n, we set to '\n') */
@@ -74,6 +71,7 @@
 	int		devfd;	/* device file descriptor */
 	struct stat 	statbuf;
 	struct part_info	part_info;
+	struct extpart_info	extpartinfo;
 	int		c;
 	int		errflag = 0;
 	char		*device;
@@ -141,15 +139,22 @@
 		perror("");
 		exit(9);
 	}
-	if ((ioctl(devfd, DKIOCPARTINFO, &part_info)) == -1) {
-		(void) fprintf(stderr, "%s: unable to get partition info.\n",
-				progname);
-		perror("");
-		exit(9);
+
+	if ((ioctl(devfd, DKIOCEXTPARTINFO, &extpartinfo)) == 0) {
+		unix_base = extpartinfo.p_start;
+		unix_size = extpartinfo.p_length;
+	} else {
+		if ((ioctl(devfd, DKIOCPARTINFO, &part_info)) == 0) {
+			unix_base = (ulong_t)part_info.p_start;
+			unix_size = (uint_t)part_info.p_length;
+		} else {
+			(void) fprintf(stderr, "%s: unable to get partition "
+			    "info.\n", progname);
+			perror("");
+			exit(9);
+		}
 	}
 
-	unix_base = part_info.p_start;
-	unix_size = part_info.p_length;
 	scandisk(device, devfd, do_scan);
 	return (0);
 }
@@ -165,12 +170,12 @@
 {
 	int	 trksiz = NBPSCTR * dkg.dkg_nsect;
 	char	*verbuf;
-	daddr_t cursec;
+	diskaddr_t cursec;
 	int	 cylsiz =  dkg.dkg_nsect * dkg.dkg_nhead;
 	int	 i;
 	char	*rptr;
-	long	tmpend = 0;
-	long	tmpsec = 0;
+	diskaddr_t tmpend = 0;
+	diskaddr_t tmpsec = 0;
 
 /* #define LIBMALLOC */
 
@@ -233,10 +238,10 @@
 	}
 
 	for (cursec = 0; cursec < unix_size; cursec +=  dkg.dkg_nsect) {
-		if (lseek(devfd, (long)cursec * NBPSCTR, 0) == -1) {
+		if (llseek(devfd, cursec * NBPSCTR, 0) == -1) {
 			(void) fprintf(stderr,
-			    "Error seeking sector %ld Cylinder %ld\n",
-				    cursec, cursec / cylsiz);
+			    "Error seeking sector %llu Cylinder %llu\n",
+			    cursec, cursec / cylsiz);
 			verexit(1);
 		}
 
@@ -256,10 +261,9 @@
 				 *  then announce the sector bad on stderr
 				 */
 
-				if (lseek
-				    (devfd, (long)tmpsec * NBPSCTR, 0) == -1) {
+				if (llseek(devfd, tmpsec * NBPSCTR, 0) == -1) {
 					(void) fprintf(stderr, "Error seeking "
-					    "sector %ld Cylinder %ld\n",
+					    "sector %llu Cylinder %llu\n",
 					    tmpsec, cursec / cylsiz);
 					verexit(1);
 				}
@@ -268,7 +272,7 @@
 
 				if (write(devfd, verbuf, NBPSCTR) != NBPSCTR) {
 					(void) fprintf(stderr,
-					    "%ld\n", tmpsec + unix_base);
+					    "%llu\n", tmpsec + unix_base);
 					numbadwr++;
 				}
 			}
@@ -279,10 +283,10 @@
 	do_readonly:
 
 	for (cursec = 0; cursec < unix_size; cursec +=  dkg.dkg_nsect) {
-		if (lseek(devfd, (long)cursec * NBPSCTR, 0) == -1) {
+		if (llseek(devfd, cursec * NBPSCTR, 0) == -1) {
 			(void) fprintf(stderr,
-			    "Error seeking sector %ld Cylinder %ld\n",
-				    cursec, cursec / cylsiz);
+			    "Error seeking sector %llu Cylinder %llu\n",
+			    cursec, cursec / cylsiz);
 			verexit(1);
 		}
 
@@ -296,16 +300,15 @@
 		if (read(devfd, verbuf, trksiz) != trksiz) {
 			tmpend = cursec +  dkg.dkg_nsect;
 			for (tmpsec = cursec; tmpsec < tmpend; tmpsec++) {
-				if (lseek(devfd, (long)tmpsec * NBPSCTR, 0)
-				    == -1) {
+				if (llseek(devfd, tmpsec * NBPSCTR, 0) == -1) {
 					(void) fprintf(stderr, "Error seeking"
-					    " sector %ld Cylinder %ld\n",
+					    " sector %llu Cylinder %llu\n",
 					    tmpsec, cursec / cylsiz);
 					verexit(1);
 				}
 				report("Reading", tmpsec);
 				if (read(devfd, verbuf, NBPSCTR) != NBPSCTR) {
-					(void) fprintf(stderr, "%ld\n",
+					(void) fprintf(stderr, "%llu\n",
 					    tmpsec + unix_base);
 					numbadrd++;
 				}
@@ -335,8 +338,8 @@
  */
 
 static void
-report(char *what, int sector)
+report(char *what, diskaddr_t sector)
 {
-	(void) printf("%s sector %-7d of %-7ld%c", what, sector,
+	(void) printf("%s sector %-19llu of %-19llu%c", what, sector,
 	    unix_size, eol);
 }
--- a/usr/src/cmd/fdisk/fdisk.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fdisk/fdisk.c	Thu Sep 11 18:00:50 2008 -0700
@@ -31,8 +31,6 @@
 /*	Copyright (c) 1987, 1988 Microsoft Corporation	*/
 /*	  All Rights Reserved	*/
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * PROGRAM: fdisk(1M)
  * This program reads the partition table on the specified device and
@@ -50,6 +48,7 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <limits.h>
 #include <sys/param.h>
 #include <sys/systeminfo.h>
 #include <sys/efi_partition.h>
@@ -87,6 +86,8 @@
 #define	MAX_CYL		(1022)
 #define	MAX_HEAD	(254)
 
+#define	DK_MAX_2TB	UINT32_MAX	/* Max # of sectors in 2TB */
+
 /* for clear_vtoc() */
 #define	OLD		0
 #define	NEW		1
@@ -272,7 +273,7 @@
 static struct mboot *Bootblk;		/* pointer to cut/paste sector zero */
 static char	*Bootsect;		/* pointer to sector zero buffer */
 static char	*Nullsect;
-static struct vtoc	disk_vtoc;	/* verify VTOC table */
+static struct extvtoc	disk_vtoc;	/* verify VTOC table */
 static int	vt_inval = 0;
 static int	no_virtgeom_ioctl = 0;	/* ioctl for virtual geometry failed */
 static int	no_physgeom_ioctl = 0;	/* ioctl for physical geometry failed */
@@ -284,10 +285,14 @@
 static struct dk_minfo	minfo;
 static struct dk_geom	disk_geom;
 
+static int Dev;			/* fd for open device */
+
 static diskaddr_t	dev_capacity;	/* number of blocks on device */
-static diskaddr_t	chs_capacity;	/* Numcyl * heads * sectors */
-
-static int Dev;			/* fd for open device */
+static diskaddr_t	chs_capacity;	/* Numcyl_usable * heads * sectors */
+
+static int		Numcyl_usable;	/* Number of usable cylinders */
+					/*  used to limit fdisk to 2TB */
+
 /* Physical geometry for the drive */
 static int	Numcyl;			/* number of cylinders */
 static int	heads;			/* number of heads */
@@ -323,14 +328,14 @@
 static int insert_tbl(int id, int act,
     int bhead, int bsect, int bcyl,
     int ehead, int esect, int ecyl,
-    int rsect, int numsect);
+    uint32_t rsect, uint32_t numsect);
 static int verify_tbl(void);
 static int pars_fdisk(char *line,
     int *id, int *act,
     int *bhead, int *bsect, int *bcyl,
     int *ehead, int *esect, int *ecyl,
-    int *rsect, int *numsect);
-static int validate_part(int id, int rsect, int numsect);
+    uint32_t *rsect, uint32_t *numsect);
+static int validate_part(int id, uint32_t rsect, uint32_t numsect);
 static void stage0(void);
 static int pcreate(void);
 static int specify(uchar_t tsystid);
@@ -728,8 +733,16 @@
 	 * some drivers may not support DKIOCGMEDIAINFO
 	 * in that case use CHS
 	 */
-	chs_capacity = Numcyl * heads * sectors;
+	chs_capacity = (diskaddr_t)Numcyl * heads * sectors;
 	dev_capacity = chs_capacity;
+	Numcyl_usable = Numcyl;
+
+	if (chs_capacity > DK_MAX_2TB) {
+		/* limit to 2TB */
+		Numcyl_usable = DK_MAX_2TB / (heads * sectors);
+		chs_capacity = (diskaddr_t)Numcyl_usable * heads * sectors;
+	}
+
 	if (minfo.dki_capacity > 0)
 		dev_capacity = minfo.dki_capacity;
 
@@ -805,6 +818,11 @@
 				    "Type \"y\" to accept the default "
 				    "partition,  otherwise type \"n\" to "
 				    "edit the\n partition table.\n");
+
+				if (Numcyl > Numcyl_usable)
+					(void) printf("WARNING: Disk is larger"
+					    " than 2TB. Solaris partition will"
+					    " be limited to 2 TB.\n");
 			}
 
 			/* Edit the partition table as directed */
@@ -812,23 +830,25 @@
 
 				/* Default scenario */
 				nulltbl();
-
 				/* now set up UNIX System partition */
 				Table[0].bootid = ACTIVE;
 				Table[0].relsect = lel(heads * sectors);
-				Table[0].numsect = lel((long)((Numcyl - 1) *
+
+				Table[0].numsect =
+				    lel((ulong_t)((Numcyl_usable - 1) *
 				    heads * sectors));
+
 				Table[0].systid = SUNIXOS2;   /* Solaris */
 
 				/* calculate CHS values for table entry 0 */
 				Set_Table_CHS_Values(0);
-
 				update_disk_and_exit(B_TRUE);
 			} else if (io_EFIdisk) {
 				/* create an EFI partition for the whole disk */
 				nulltbl();
 				i = insert_tbl(EFI_PMBR, 0, 0, 0, 0, 0, 0, 0, 1,
-				    dev_capacity - 1);
+				    (dev_capacity > DK_MAX_2TB) ? DK_MAX_2TB :
+				    (dev_capacity - 1));
 				if (i != 0) {
 					(void) fprintf(stderr,
 					    "Error creating EFI partition\n");
@@ -1315,8 +1335,8 @@
 	int	ehead;
 	int	esect;
 	int	ecyl;
-	int	rsect;
-	int	numsect;
+	uint32_t	rsect;
+	uint32_t	numsect;
 	char	line[256];
 	int	i = 0;
 	int	j;
@@ -1475,11 +1495,21 @@
 				exit(1);
 			}
 
-			if (numsect != dev_capacity - 1) {
+
+			if (dev_capacity > DK_MAX_2TB) {
+				if (numsect != DK_MAX_2TB) {
+					(void) fprintf(stderr,
+					    "fdisk: EFI partitions must "
+					    "encompass the entire maximum 2 TB "
+					    "(input numsect: %u - max: %llu)\n",
+					    numsect, (diskaddr_t)DK_MAX_2TB);
+				exit(1);
+				}
+			} else if (numsect != dev_capacity - 1) {
 				(void) fprintf(stderr,
 				    "fdisk: EFI partitions must encompass the "
 				    "entire disk\n"
-				    "(input numsect: %d - avail: %llu)\n",
+				    "(input numsect: %u - avail: %llu)\n",
 				    numsect,
 				    dev_capacity - 1);
 				exit(1);
@@ -1570,17 +1600,18 @@
     int id, int act,
     int bhead, int bsect, int bcyl,
     int ehead, int esect, int ecyl,
-    int rsect, int numsect)
+    uint32_t rsect, uint32_t numsect)
 {
 	int	i;
 
 	/* validate partition size */
-	if (rsect + numsect > dev_capacity) {
+	if (((diskaddr_t)rsect + numsect) > dev_capacity) {
 		(void) fprintf(stderr,
 		    "fdisk: Partition table exceeds the size of the disk.\n");
 		return (-1);
 	}
 
+
 	/* find UNUSED partition table entry */
 	for (i = 0; i < FD_NUMPART; i++) {
 		if (Table[i].systid == UNUSED) {
@@ -1639,7 +1670,7 @@
 static int
 verify_tbl(void)
 {
-	int	i, j, rsect, numsect;
+	uint32_t	i, j, rsect, numsect;
 	int	noMoreParts = 0;
 	int	numParts = 0;
 
@@ -1693,14 +1724,18 @@
 			/* make sure the partition isn't larger than the disk */
 			rsect = lel(Table[i].relsect);
 			numsect = lel(Table[i].numsect);
-			if ((rsect + numsect) > dev_capacity) {
+
+			if ((((diskaddr_t)rsect + numsect) > dev_capacity) ||
+			    (((diskaddr_t)rsect + numsect) > DK_MAX_2TB)) {
 				return (-1);
 			}
 
 			for (j = i + 1; j < FD_NUMPART; j++) {
 				if (Table[j].systid != UNUSED) {
-					int t_relsect = lel(Table[j].relsect);
-					int t_numsect = lel(Table[j].numsect);
+					uint32_t t_relsect =
+					    lel(Table[j].relsect);
+					uint32_t t_numsect =
+					    lel(Table[j].numsect);
 
 					if (noMoreParts) {
 						(void) fprintf(stderr,
@@ -1742,7 +1777,6 @@
 
 						return (-1);
 					}
-
 					if ((rsect >=
 					    (t_relsect + t_numsect)) ||
 					    ((rsect + numsect) <= t_relsect)) {
@@ -1762,8 +1796,10 @@
 	}
 	if (Table[i].systid != UNUSED) {
 		if (noMoreParts ||
-		    ((lel(Table[i].relsect) + lel(Table[i].numsect)) >
-		    dev_capacity)) {
+		    (((diskaddr_t)lel(Table[i].relsect) +
+		    lel(Table[i].numsect)) > dev_capacity) ||
+		    (((diskaddr_t)lel(Table[i].relsect) +
+		    lel(Table[i].numsect)) > DK_MAX_2TB)) {
 			return (-1);
 		}
 	}
@@ -1782,7 +1818,7 @@
     int *id, int *act,
     int *bhead, int *bsect, int *bcyl,
     int *ehead, int *esect, int *ecyl,
-    int *rsect, int *numsect)
+    uint32_t *rsect, uint32_t *numsect)
 {
 	int	i;
 	if (line[0] == '\0' || line[0] == '\n' || line[0] == '*')
@@ -1795,7 +1831,7 @@
 			line[i] = ' ';
 		}
 	}
-	if (sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
+	if (sscanf(line, "%d %d %d %d %d %d %d %d %u %u",
 	    id, act, bhead, bsect, bcyl, ehead, esect, ecyl,
 	    rsect, numsect) != 10) {
 		(void) fprintf(stderr, "Syntax error:\n	\"%s\".\n", line);
@@ -1810,7 +1846,7 @@
  * partitions and previously existing partitions are allowed to start at 0.
  */
 static int
-validate_part(int id, int rsect, int numsect)
+validate_part(int id, uint32_t rsect, uint32_t numsect)
 {
 	int i;
 	if ((id != UNUSED) && (rsect == 0)) {
@@ -1912,7 +1948,7 @@
 {
 	uchar_t tsystid = 'z';
 	int i, j;
-	int rsect = 1;
+	uint32_t numsect;
 	int retCode = 0;
 
 	i = 0;
@@ -1931,12 +1967,12 @@
 		i++;
 	}
 
-	j = 0;
+	numsect = 0;
 	for (i = 0; i < FD_NUMPART; i++) {
 		if (Table[i].systid != UNUSED) {
-			j += lel(Table[i].numsect);
+			numsect += lel(Table[i].numsect);
 		}
-		if (j >= chs_capacity) {
+		if (numsect >= chs_capacity) {
 			(void) printf(E_LINE);
 			(void) printf("There is no more room on the disk for"
 			    " another partition.\n");
@@ -1947,6 +1983,15 @@
 		}
 	}
 	while (tsystid == 'z') {
+
+		/*
+		 * The question here is expanding to more than what is
+		 * allocated for question lines (Q_LINE) which garbles
+		 * at least warning line. Clearing warning line as workaround
+		 * for now.
+		 */
+
+		(void) printf(W_LINE);
 		(void) printf(Q_LINE);
 		(void) printf(
 		    "Select the partition type to create:\n"
@@ -2026,6 +2071,11 @@
 	(void) printf(E_LINE);
 
 	if (tsystid != EFI_PMBR) {
+		(void) printf(W_LINE);
+		if ((dev_capacity > DK_MAX_2TB))
+			(void) printf("WARNING: Disk is larger than 2 TB. "
+			    "Upper limit is 2 TB for non-EFI partition ID\n");
+
 		/* create the new partition */
 		i = specify(tsystid);
 
@@ -2093,8 +2143,9 @@
 		}
 
 		/* create the table entry - i should be 0 */
-		i = insert_tbl(tsystid, 0, 0, 0, 0, 0, 0, 0, rsect,
-		    dev_capacity - rsect);
+		i = insert_tbl(tsystid, 0, 0, 0, 0, 0, 0, 0, 1,
+		    (dev_capacity > DK_MAX_2TB) ? DK_MAX_2TB:
+		    (dev_capacity - 1));
 
 		if (i != 0) {
 			(void) printf("Error creating EFI partition!!!\n");
@@ -2122,8 +2173,9 @@
 specify(uchar_t tsystid)
 {
 	int	i, j, percent = -1;
-	int	cyl, cylen, first_free, size_free;
-	int	max_free;
+	int	cyl, cylen;
+	diskaddr_t first_free, size_free;
+	diskaddr_t max_free;
 	int	cyl_size;
 	struct ipart *partition[FD_NUMPART];
 
@@ -2151,6 +2203,7 @@
 		}
 	}
 
+
 	(void) printf(Q_LINE);
 	(void) printf(
 	    "Specify the percentage of disk to use for this partition\n"
@@ -2189,17 +2242,16 @@
 			return (-1);
 		}
 
-
 		if (percent == 100)
-			cylen = Numcyl - 1;
+			cylen = Numcyl_usable - 1;
 		else
-			cylen = (Numcyl * percent) / 100;
+			cylen = (Numcyl_usable * percent) / 100;
 
 		/* Verify DOS12 partition doesn't exceed max size of 32MB. */
 		if ((tsystid == DOSOS12) &&
 		    ((long)((long)cylen * cyl_size) > MAXDOS)) {
 			int n;
-			n = MAXDOS * 100 / (int)(cyl_size) / Numcyl;
+			n = MAXDOS * 100 / (int)(cyl_size) / Numcyl_usable;
 			(void) printf(E_LINE);
 			(void) printf("Maximum size for a DOS partition "
 			    "is %d%%; retry the operation.",
@@ -2244,7 +2296,7 @@
 			if (max_free < size_free)
 				max_free = size_free;
 
-			if ((cylen * cyl_size) <= size_free) {
+			if (((uint64_t)cylen * cyl_size) <= size_free) {
 				/* We found a place to use */
 				break;
 			}
@@ -2252,8 +2304,8 @@
 				(void) printf(E_LINE);
 				max_free /= (cyl_size);
 				(void) fprintf(stderr, "fdisk: "
-				    "Maximum percentage available is %d\n",
-				    100 * max_free / Numcyl);
+				    "Maximum percentage available is %lld\n",
+				    100 * max_free / Numcyl_usable);
 				return (-1);
 			}
 		}
@@ -2287,14 +2339,17 @@
 			    "New partition cannot start at cylinder 0.\n");
 			return (-1);
 		}
-		if (cyl >= (unsigned int)Numcyl) {
+
+
+		if (cyl >= Numcyl_usable) {
 			(void) printf(E_LINE);
 			(void) printf(
 			    "Cylinder %d is out of bounds, "
 			    "the maximum is %d.\n",
-			    cyl, Numcyl - 1);
+			    cyl, Numcyl_usable - 1);
 			return (-1);
 		}
+
 		(void) printf(Q_LINE);
 		(void) printf("Enter partition size in cylinders: ");
 		if ((cylen = getcyl()) == -1) {
@@ -2332,13 +2387,20 @@
 			}
 		}
 
-		/* Verify partition doesn't exceed disk size */
-		if (cyl + cylen > Numcyl) {
+		/* Verify partition doesn't exceed disk size or 2 TB */
+		if (cyl + cylen > Numcyl_usable) {
 			(void) printf(E_LINE);
-			(void) printf(
-			    "Maximum size for partition is %d cylinders;"
-			    "\nretry the operation.",
-			    Numcyl - cyl);
+			if (Numcyl > Numcyl_usable) {
+				(void) printf(
+				    "Maximum size for partition is %d "
+				    "cylinders; \nretry the operation.",
+				    Numcyl_usable - cyl);
+			} else {
+				(void) printf(
+				    "Maximum size for partition is %d "
+				    "cylinders; \nretry the operation.",
+				    Numcyl_usable - cyl);
+			}
 			return (-1);
 		}
 
@@ -2638,6 +2700,7 @@
 	int i;
 	unsigned int startcyl, endcyl, length, percent, remainder;
 	char *stat, *type;
+	int is_pmbr = 0;
 
 	if ((heads == 0) || (sectors == 0)) {
 		(void) printf("WARNING: critical disk geometry information"
@@ -2768,6 +2831,9 @@
 			break;
 		case EFI_PMBR:
 			type = EFIstr;
+			if (lel(Table[i].numsect) == DK_MAX_2TB)
+				is_pmbr = 1;
+
 			break;
 		default:
 			type = Ostr;
@@ -2775,14 +2841,22 @@
 		}
 		startcyl = lel(Table[i].relsect) /
 		    (unsigned long)(heads * sectors);
-		length = lel(Table[i].numsect) /
-		    (unsigned long)(heads * sectors);
-		if (lel(Table[i].numsect) % (unsigned long)(heads * sectors))
-			length++;
-		endcyl = startcyl + length - 1;
-		percent = length * 100 / Numcyl;
-		if ((remainder = (length * 100 % Numcyl)) != 0) {
-			if ((remainder * 100 / Numcyl) > 50) {
+
+		if (lel(Table[i].numsect) == DK_MAX_2TB) {
+			endcyl = Numcyl - 1;
+			length = endcyl - startcyl + 1;
+		} else {
+			length = lel(Table[i].numsect) /
+			    (unsigned long)(heads * sectors);
+			if (lel(Table[i].numsect) %
+			    (unsigned long)(heads * sectors))
+				length++;
+			endcyl = startcyl + length - 1;
+		}
+
+		percent = length * 100 / Numcyl_usable;
+		if ((remainder = (length * 100 % Numcyl_usable)) != 0) {
+			if ((remainder * 100 / Numcyl_usable) > 50) {
 				/* round up */
 				percent++;
 			}
@@ -2796,6 +2870,7 @@
 		    "    %3d",
 		    i + 1, stat, type, startcyl, endcyl, length, percent);
 	}
+
 	/* Print warning message if table is empty */
 	if (Table[0].systid == UNUSED) {
 		(void) printf(W_LINE);
@@ -2803,6 +2878,11 @@
 	} else {
 		/* Clear the warning line */
 		(void) printf(W_LINE);
+
+		/* Print warning if disk > 2TB and is not EFI PMBR */
+		if (!is_pmbr && (dev_capacity > DK_MAX_2TB))
+			(void) printf("WARNING: Disk is larger than 2 TB. "
+			    "Upper limit is 2 TB for non-EFI partition ID\n");
 	}
 }
 
@@ -2832,8 +2912,8 @@
 		(void) fprintf(stderr, "%-5d ", Table[i].endsect & 0x3f);
 		(void) fprintf(stderr, "%-8d ",
 		    (((uint_t)Table[i].endsect & 0xc0) << 2) + Table[i].endcyl);
-		(void) fprintf(stderr, "%-9d ", lel(Table[i].relsect));
-		(void) fprintf(stderr, "%-9d\n", lel(Table[i].numsect));
+		(void) fprintf(stderr, "%-10u ", lel(Table[i].relsect));
+		(void) fprintf(stderr, "%-10u\n", lel(Table[i].numsect));
 
 	}
 }
@@ -3103,12 +3183,13 @@
 	(void) fprintf(fp, "*\n");
 	(void) fprintf(fp,
 	    "\n* Id    Act  Bhead  Bsect  Bcyl    Ehead  Esect  Ecyl"
-	    "    Rsect    Numsect\n");
+	    "    Rsect      Numsect\n");
+
 	for (i = 0; i < FD_NUMPART; i++) {
 		if (Table[i].systid != UNUSED)
 			(void) fprintf(fp,
-			    "  %-5d %-4d %-6d %-6d %-7d %-6d %-6d %-7d %-8d"
-			    " %-8d\n",
+			    "  %-5d %-4d %-6d %-6d %-7d %-6d %-6d %-7d %-10u"
+			    " %-10u\n",
 			    Table[i].systid,
 			    Table[i].bootid,
 			    Table[i].beghead,
@@ -3136,7 +3217,7 @@
 fix_slice(void)
 {
 	int	i;
-	int	numsect;
+	uint32_t	numsect;
 
 	if (io_image) {
 		return;
@@ -3171,7 +3252,7 @@
 		if (i == 2) {
 			if (disk_vtoc.v_part[i].p_start != 0) {
 				(void) fprintf(stderr,
-				    "slice %d starts at %ld, is not at"
+				    "slice %d starts at %llu, is not at"
 				    " start of partition",
 				    i, disk_vtoc.v_part[i].p_start);
 				if (!io_nifdisk) {
@@ -3186,7 +3267,7 @@
 			}
 			if (disk_vtoc.v_part[i].p_size != numsect) {
 				(void) fprintf(stderr,
-				    "slice %d size %ld does not cover"
+				    "slice %d size %llu does not cover"
 				    " complete partition",
 				    i, disk_vtoc.v_part[i].p_size);
 				if (!io_nifdisk) {
@@ -3221,7 +3302,7 @@
 			    disk_vtoc.v_part[i].p_start +
 			    disk_vtoc.v_part[i].p_size > numsect) {
 				(void) fprintf(stderr,
-				    "slice %d (start %ld, end %ld)"
+				    "slice %d (start %llu, end %llu)"
 				    " is larger than the partition",
 				    i, disk_vtoc.v_part[i].p_start,
 				    disk_vtoc.v_part[i].p_start +
@@ -3247,8 +3328,8 @@
 		}
 		if (disk_vtoc.v_part[i].p_start > numsect) {
 			(void) fprintf(stderr,
-			    "slice %d (start %ld) is larger than the partition",
-			    i, disk_vtoc.v_part[i].p_start);
+			    "slice %d (start %llu) is larger than the "
+			    "partition", i, disk_vtoc.v_part[i].p_start);
 			if (!io_nifdisk) {
 				(void) printf(" remove ?:");
 				if (yesno()) {
@@ -3268,7 +3349,7 @@
 		} else if (disk_vtoc.v_part[i].p_start
 		    + disk_vtoc.v_part[i].p_size > numsect) {
 			(void) fprintf(stderr,
-			    "slice %d (end %ld) is larger"
+			    "slice %d (end %llu) is larger"
 			    " than the partition",
 			    i,
 			    disk_vtoc.v_part[i].p_start +
@@ -3333,7 +3414,7 @@
 	int	i;
 	int	retval = VTOC_OK;
 
-	if ((i = read_vtoc(Dev, &disk_vtoc)) < VTOC_OK) {
+	if ((i = read_extvtoc(Dev, &disk_vtoc)) < VTOC_OK) {
 		if (i == VT_EINVAL) {
 			(void) fprintf(stderr, "fdisk: Invalid VTOC.\n");
 			vt_inval++;
@@ -3360,7 +3441,7 @@
 	int	i;
 	int	retval = 0;
 
-	if ((i = write_vtoc(Dev, &disk_vtoc)) != 0) {
+	if ((i = write_extvtoc(Dev, &disk_vtoc)) != 0) {
 		if (i == VT_EINVAL) {
 			(void) fprintf(stderr,
 			    "fdisk: Invalid entry exists in VTOC.\n");
@@ -3496,8 +3577,9 @@
 {
 	struct ipart *clr_table;
 	struct dk_label disk_label;
-	int pcyl, ncyl, count, bytes;
-	uint_t backup_block, solaris_offset;
+	uint32_t pcyl, ncyl, count;
+	diskaddr_t backup_block, solaris_offset;
+	ssize_t bytes;
 	off_t seek_byte;
 
 #ifdef DEBUG
@@ -3532,8 +3614,8 @@
 
 	if (bytes != sizeof (struct dk_label)) {
 		(void) fprintf(stderr,
-		    "\tWarning: only %d bytes written to clear primary VTOC!\n",
-		    bytes);
+		    "\tWarning: only %d bytes written to clear primary"
+		    " VTOC!\n", bytes);
 	}
 
 #ifdef DEBUG
@@ -3684,10 +3766,11 @@
 static void
 sanity_check_provided_device(char *devname, int fd)
 {
-	struct vtoc v;
+	struct extvtoc v;
 	struct dk_geom d;
 	struct part_info pi;
-	long totsize;
+	struct extpart_info extpi;
+	diskaddr_t totsize;
 	int idx = -1;
 
 	/*
@@ -3695,7 +3778,15 @@
 	 *  to tell if they've specified the full disk partition by checking
 	 *  to see if they've specified a partition that starts at sector 0.
 	 */
-	if (ioctl(fd, DKIOCPARTINFO, &pi) != -1) {
+	if (ioctl(fd, DKIOCEXTPARTINFO, &extpi) != -1) {
+		if (extpi.p_start != 0) {
+			if (!lecture_and_query(FDISK_LECTURE_NOT_SECTOR_ZERO,
+			    devname)) {
+				(void) close(fd);
+				exit(1);
+			}
+		}
+	} else if (ioctl(fd, DKIOCPARTINFO, &pi) != -1) {
 		if (pi.p_start != 0) {
 			if (!lecture_and_query(FDISK_LECTURE_NOT_SECTOR_ZERO,
 			    devname)) {
@@ -3704,7 +3795,7 @@
 			}
 		}
 	} else {
-		if ((idx = read_vtoc(fd, &v)) < 0) {
+		if ((idx = read_extvtoc(fd, &v)) < 0) {
 			if (!lecture_and_query(FDISK_LECTURE_NO_VTOC,
 			    devname)) {
 				(void) close(fd);
@@ -3721,7 +3812,7 @@
 			}
 			return;
 		}
-		totsize = d.dkg_ncyl * d.dkg_nhead * d.dkg_nsect;
+		totsize = (diskaddr_t)d.dkg_ncyl * d.dkg_nhead * d.dkg_nsect;
 		if (v.v_part[idx].p_size != totsize) {
 			if (!lecture_and_query(FDISK_LECTURE_NOT_FULL,
 			    devname)) {
--- a/usr/src/cmd/fmthard/fmthard.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fmthard/fmthard.c	Thu Sep 11 18:00:50 2008 -0700
@@ -28,10 +28,8 @@
  *	Computers Limited (ICL) under a development agreement with AT&T.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -67,6 +65,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/param.h>
+#include <sys/int_limits.h>
 #include <sys/stat.h>
 #include <sys/uadmin.h>
 #include <sys/open.h>
@@ -85,29 +84,22 @@
 #define	SECSIZE			DEV_BSIZE
 #endif	/* SECSIZE */
 
-
-/*
- * External functions.
- */
-extern	int	read_vtoc(int, struct vtoc *);
-extern	int	write_vtoc(int, struct vtoc *);
-
 /*
  * Internal functions.
  */
 extern	int	main(int, char **);
-static	void	display(struct dk_geom *, struct vtoc *, char *);
+static	void	display(struct dk_geom *, struct extvtoc *, char *);
 static	void	display64(struct dk_gpt *,  char *);
-static	void	insert(char *, struct vtoc *);
+static	void	insert(char *, struct extvtoc *);
 static	void	insert64(char *, struct dk_gpt *);
-static	void	load(FILE *, struct dk_geom *, struct vtoc *);
+static	void	load(FILE *, struct dk_geom *, struct extvtoc *);
 static	void	load64(FILE *, int fd, struct dk_gpt **);
 static	void	usage(void);
-static	void	validate(struct dk_geom *, struct vtoc *);
+static	void	validate(struct dk_geom *, struct extvtoc *);
 static	void	validate64(struct dk_gpt *);
-static	int	vread(int, struct vtoc *, char *);
+static	int	vread(int, struct extvtoc *, char *);
 static	void	vread64(int, struct dk_gpt **, char *);
-static	void	vwrite(int, struct vtoc *, char *);
+static	void	vwrite(int, struct extvtoc *, char *);
 static	void	vwrite64(int, struct dk_gpt *, char *);
 
 /*
@@ -135,7 +127,7 @@
 static char	*ufirm = "firm";
 #if defined(_SUNOS_VTOC_16)
 static int		sectsiz;
-static struct vtoc	disk_vtoc;
+static struct extvtoc	disk_vtoc;
 #endif	/* defined(_SUNOS_VTOC_16) */
 
 int
@@ -147,7 +139,7 @@
 	char		*vname;
 	struct stat	statbuf;
 #if defined(_SUNOS_VTOC_8)
-	struct vtoc	disk_vtoc;
+	struct extvtoc	disk_vtoc;
 #endif	/* defined(_SUNOS_VTOC_8) */
 	struct dk_gpt	*disk_efi;
 	struct dk_geom	disk_geom;
@@ -376,7 +368,7 @@
  * display contents of VTOC without writing it to disk
  */
 static void
-display(struct dk_geom *geom, struct vtoc *vtoc, char *device)
+display(struct dk_geom *geom, struct extvtoc *vtoc, char *device)
 {
 	int	i;
 	int	c;
@@ -411,7 +403,7 @@
 	for (i = 0; i < V_NUMPAR; i++) {
 		if (vtoc->v_part[i].p_size > 0)
 			(void) printf(
-"    %d		%d	0%x		%ld		%ld\n",
+"    %d		%d	0%x		%llu		%llu\n",
 				i, vtoc->v_part[i].p_tag,
 				vtoc->v_part[i].p_flag,
 				vtoc->v_part[i].p_start,
@@ -467,15 +459,15 @@
  * Insert a change into the VTOC.
  */
 static void
-insert(char *data, struct vtoc *vtoc)
+insert(char *data, struct extvtoc *vtoc)
 {
-	int	part;
-	int	tag;
-	uint_t	flag;
-	daddr_t	start;
-	long	size;
+	int		part;
+	int		tag;
+	uint_t		flag;
+	diskaddr_t	start;
+	uint64_t	size;
 
-	if (sscanf(data, "%d:%d:%x:%ld:%ld",
+	if (sscanf(data, "%d:%d:%x:%llu:%llu",
 	    &part, &tag, &flag, &start, &size) != 5) {
 		(void) fprintf(stderr, "Delta syntax error on \"%s\"\n", data);
 		exit(1);
@@ -529,17 +521,17 @@
  * Load VTOC information from a datafile.
  */
 static void
-load(FILE *fp, struct dk_geom *geom, struct vtoc *vtoc)
+load(FILE *fp, struct dk_geom *geom, struct extvtoc *vtoc)
 {
-	int	part;
-	int	tag;
-	uint_t	flag;
-	daddr_t	start;
-	long	size;
-	char	line[256];
-	int	i;
-	long	nblks;
-	long	fullsz;
+	int		part;
+	int		tag;
+	uint_t		flag;
+	diskaddr_t	start;
+	uint64_t	size;
+	char		line[256];
+	int		i;
+	uint64_t	nblks;
+	uint64_t	fullsz;
 
 	for (i = 0; i < V_NUMPAR; ++i) {
 		vtoc->v_part[i].p_tag = 0;
@@ -551,7 +543,7 @@
 	 * initialize partition 2, by convention it corresponds to whole
 	 * disk. It will be overwritten, if specified in the input datafile
 	 */
-	fullsz = geom->dkg_ncyl * geom->dkg_nsect * geom->dkg_nhead;
+	fullsz = (uint64_t)geom->dkg_ncyl * geom->dkg_nsect * geom->dkg_nhead;
 	vtoc->v_part[2].p_tag = V_BACKUP;
 	vtoc->v_part[2].p_flag = V_UNMNT;
 	vtoc->v_part[2].p_start = 0;
@@ -563,7 +555,7 @@
 		if (line[0] == '\0' || line[0] == '\n' || line[0] == '*')
 			continue;
 		line[strlen(line) - 1] = '\0';
-		if (sscanf(line, "%d %d %x %ld %ld",
+		if (sscanf(line, "%d %d %x %llu %llu",
 		    &part, &tag, &flag, &start, &size) != 5) {
 			(void) fprintf(stderr, "Syntax error: \"%s\"\n",
 				line);
@@ -697,21 +689,21 @@
  * Validate the new VTOC.
  */
 static void
-validate(struct dk_geom *geom, struct vtoc *vtoc)
+validate(struct dk_geom *geom, struct extvtoc *vtoc)
 {
-	int	i;
-	int	j;
-	long	fullsz;
-	long	endsect;
-	daddr_t	istart;
-	daddr_t	jstart;
-	long	isize;
-	long	jsize;
-	long	nblks;
+	int		i;
+	int		j;
+	uint64_t	fullsz;
+	diskaddr_t	endsect;
+	diskaddr_t	istart;
+	diskaddr_t	jstart;
+	uint64_t	isize;
+	uint64_t	jsize;
+	uint64_t	nblks;
 
 	nblks = geom->dkg_nsect * geom->dkg_nhead;
 
-	fullsz = geom->dkg_ncyl * geom->dkg_nsect * geom->dkg_nhead;
+	fullsz = (uint64_t)geom->dkg_ncyl * geom->dkg_nsect * geom->dkg_nhead;
 
 #if defined(_SUNOS_VTOC_16)
 	/* make the vtoc look sane - ha ha */
@@ -729,7 +721,7 @@
 			if (vtoc->v_part[i].p_size != fullsz) {
 				(void) fprintf(stderr, "\
 fmthard: Partition %d specifies the full disk and is not equal\n\
-full size of disk.  The full disk capacity is %lu sectors.\n", i, fullsz);
+full size of disk.  The full disk capacity is %llu sectors.\n", i, fullsz);
 #if defined(sparc)
 			exit(1);
 #endif
@@ -747,8 +739,8 @@
 			vtoc->v_part[i].p_start +
 				vtoc->v_part[i].p_size > fullsz) {
 			(void) fprintf(stderr, "\
-fmthard: Partition %d specified as %lu sectors starting at %lu\n\
-\tdoes not fit. The full disk contains %lu sectors.\n",
+fmthard: Partition %d specified as %llu sectors starting at %llu\n\
+\tdoes not fit. The full disk contains %llu sectors.\n",
 				i, vtoc->v_part[i].p_size,
 				vtoc->v_part[i].p_start, fullsz);
 #if defined(sparc)
@@ -861,11 +853,11 @@
  * Read the VTOC
  */
 int
-vread(int fd, struct vtoc *vtoc, char *devname)
+vread(int fd, struct extvtoc *vtoc, char *devname)
 {
 	int	i;
 
-	if ((i = read_vtoc(fd, vtoc)) < 0) {
+	if ((i = read_extvtoc(fd, vtoc)) < 0) {
 		if (i == VT_ENOTSUP) {
 			return (1);
 		}
@@ -904,11 +896,11 @@
  * Write the VTOC
  */
 void
-vwrite(int fd, struct vtoc *vtoc, char *devname)
+vwrite(int fd, struct extvtoc *vtoc, char *devname)
 {
 	int	i;
 
-	if ((i = write_vtoc(fd, vtoc)) != 0) {
+	if ((i = write_extvtoc(fd, vtoc)) != 0) {
 		if (i == VT_EINVAL) {
 			(void) fprintf(stderr,
 			"%s: invalid entry exists in vtoc\n",
--- a/usr/src/cmd/format/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
 # CDDL HEADER START
 #
 # The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License").  You may not use this file except in compliance
-# with the License.
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
 #
 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 # or http://www.opensolaris.org/os/licensing.
@@ -20,11 +19,9 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
-#
 
 PROG= format
 
@@ -58,6 +55,8 @@
 
 LDLIBS +=	-ladm -lefi -ldiskmgt -lnvpair -ldevid
 
+CFLAGS    += -D_EXTVTOC
+
 .KEEP_STATE:
 
 all: $(PROG) $(DATA)
--- a/usr/src/cmd/format/analyze.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/analyze.c	Thu Sep 11 18:00:50 2008 -0700
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains routines to analyze the surface of a disk.
  */
@@ -51,7 +49,7 @@
 int	scan_loop = 0;			/* loop forever flag */
 int	scan_passes = 2;		/* number of passes */
 int	scan_random = 0;		/* random patterns flag */
-int	scan_size = 0;			/* sectors/scan operation */
+uint_t	scan_size = 0;			/* sectors/scan operation */
 int	scan_auto = 1;			/* scan after format flag */
 int	scan_restore_defects = 1;	/* restore defect list after writing */
 int	scan_restore_label = 1;		/* restore label after writing */
@@ -100,10 +98,10 @@
 #ifdef	__STDC__
 
 static int	scan_repair(diskaddr_t bn, int mode);
-static int	analyze_blocks(int flags, diskaddr_t blkno, int blkcnt,
+static int	analyze_blocks(int flags, diskaddr_t blkno, uint_t blkcnt,
 		unsigned data, int init, int driver_flags, int *xfercntp);
 static int	handle_error_conditions(void);
-static int	verify_blocks(int flags, diskaddr_t blkno, int blkcnt,
+static int	verify_blocks(int flags, diskaddr_t blkno, uint_t blkcnt,
 		unsigned data, int driver_flags, int *xfercntp);
 #else	/* __STDC__ */
 
@@ -125,7 +123,8 @@
 	int	flags, mode;
 {
 	diskaddr_t	start, end, curnt;
-	int	pass, size, needinit, data;
+	int	pass, needinit, data;
+	uint_t	size;
 	int	status, founderr, i, j;
 	int	error = 0;
 	int	pattern = 0;
@@ -197,8 +196,8 @@
 	 */
 	if (flags & (SCAN_PATTERN | SCAN_WRITE)) {
 	    if (cur_label == L_TYPE_SOLARIS) {
-		if (start < (daddr_t)totalsects() &&
-				end >= (daddr_t)datasects()) {
+		if (start < (diskaddr_t)totalsects() &&
+				end >= (diskaddr_t)datasects()) {
 			if (!EMBEDDED_SCSI) {
 				cur_list.flags |= LIST_DIRTY;
 			}
@@ -577,13 +576,15 @@
  */
 static int
 analyze_blocks(flags, blkno, blkcnt, data, init, driver_flags, xfercntp)
-	int	flags, driver_flags, blkcnt, init;
+	int	flags, driver_flags, init;
+	uint_t	blkcnt;
 	register unsigned data;
 	diskaddr_t	blkno;
 	int	*xfercntp;
 {
-	int	corrupt = 0;
-	register int	status, i, nints;
+	int		corrupt = 0;
+	int		status;
+	register diskaddr_t	i, nints;
 	register unsigned *ptr = (uint_t *)pattern_buf;
 
 	media_error = 0;
@@ -595,7 +596,7 @@
 	/*
 	 * Initialize the pattern buffer if necessary.
 	 */
-	nints = blkcnt * SECSIZE / sizeof (int);
+	nints = (diskaddr_t)blkcnt * SECSIZE / sizeof (int);
 	if ((flags & SCAN_PATTERN) && init) {
 		for (i = 0; i < nints; i++)
 			*((int *)((int *)pattern_buf + i)) = data;
@@ -663,7 +664,7 @@
 					*((int *)((int *)pattern_buf +
 					(nints - i))));
 				pr_dblock(err_print, blkno);
-				err_print(", offset = 0x%x.\n",
+				err_print(", offset = 0x%llx.\n",
 					(nints - i) * sizeof (int));
 				goto bad;
 			}
@@ -715,7 +716,7 @@
 static int
 verify_blocks(int flags,
 		diskaddr_t blkno,
-		int blkcnt,
+		uint_t blkcnt,
 		unsigned data,
 		int driver_flags,
 		int *xfercntp)
@@ -759,17 +760,19 @@
 		 * compare and make sure the pattern came back intact.
 		 */
 		for (data = blkno; data < blkno + blkcnt; data++) {
-		    for (i = 0; i < nints; i++) {
-			if (*ptr++ != data) {
-			    ptr--;
-			    err_print("Data miscompare error (expecting "
-				"0x%x, got 0x%x) at ", data, *ptr);
-			    pr_dblock(err_print, blkno);
-			    err_print(", offset = 0x%x.\n", (ptr -
-				(uint_t *)pattern_buf) * sizeof (int));
-			    goto bad;
+			for (i = 0; i < nints; i++) {
+				if (*ptr++ != data) {
+					ptr--;
+					err_print("Data miscompare error "
+					    "(expecting 0x%x, got 0x%x) at ",
+					    data, *ptr);
+					pr_dblock(err_print, blkno);
+					err_print(", offset = 0x%x.\n",
+					    (ptr - (uint_t *)pattern_buf) *
+					    sizeof (int));
+					goto bad;
+				}
 			}
-		    }
 		}
 	}
 	/*
--- a/usr/src/cmd/format/analyze.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/analyze.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,15 +19,13 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 1998-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_ANALYZE_H
 #define	_ANALYZE_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -44,7 +41,8 @@
 extern	int scan_entire;
 extern	diskaddr_t scan_lower, scan_upper;
 extern	int scan_correct, scan_stop, scan_loop, scan_passes;
-extern	int scan_random, scan_size, scan_auto;
+extern	int scan_random, scan_auto;
+extern	uint_t scan_size;
 extern	int scan_restore_defects, scan_restore_label;
 
 /*
--- a/usr/src/cmd/format/auto_sense.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/auto_sense.c	Thu Sep 11 18:00:50 2008 -0700
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions to implement automatic configuration
  * of scsi disks.
@@ -116,8 +114,8 @@
 
 
 static struct default_partitions {
-	long			min_capacity;
-	long			max_capacity;
+	diskaddr_t		min_capacity;
+	diskaddr_t		max_capacity;
 	struct part_table	*part_table;
 } default_partitions[] = {
 	{ 0,	64,		&part_table_64mb },	/* 0 to 64 mb */
@@ -228,14 +226,17 @@
 				char	*dst,
 				char	*src,
 				int	n);
-static	int		adjust_disk_geometry(int capacity, int *cyl,
-						int *nsect, int *nhead);
+static	int		adjust_disk_geometry(diskaddr_t capacity, uint_t *cyl,
+				uint_t *nsect, uint_t *nhead);
+static void 		compute_chs_values(diskaddr_t total_capacity,
+				diskaddr_t usable_capacity, uint_t *pcylp,
+				uint_t *nheadp, uint_t *nsectp);
 #if defined(_SUNOS_VTOC_8)
-static int square_box(
-			int capacity,
-			int *dim1, int lim1,
-			int *dim2, int lim2,
-			int *dim3, int lim3);
+static diskaddr_t square_box(
+			diskaddr_t capacity,
+			uint_t *dim1, uint_t lim1,
+			uint_t *dim2, uint_t lim2,
+			uint_t *dim3, uint_t lim3);
 #endif	/* defined(_SUNOS_VTOC_8) */
 
 
@@ -566,7 +567,7 @@
 	label->dkl_magic = DKL_MAGIC;
 
 	(void) snprintf(label->dkl_asciilabel, sizeof (label->dkl_asciilabel),
-	    "%s cyl %d alt %d hd %d sec %d",
+	    "%s cyl %u alt %u hd %u sec %u",
 	    "DEFAULT", ncyl, acyl, nhead, nsect);
 
 	rval = 0;
@@ -696,8 +697,8 @@
 #elif defined(_SUNOS_VTOC_16)
 		part->pinfo_map[i].dkl_cylno =
 			label->dkl_vtoc.v_part[i].p_start /
-				((int)(disk->dtype_nhead *
-					disk->dtype_nsect - apc));
+			    ((blkaddr_t)(disk->dtype_nhead *
+			    disk->dtype_nsect - apc));
 		part->pinfo_map[i].dkl_nblk =
 			label->dkl_vtoc.v_part[i].p_size;
 #else
@@ -878,15 +879,15 @@
 	char			*disk_name)
 {
 	struct disk_type		*disk;
-	int				i;
 	int				setdefault = 0;
-	int				pcyl = 0;
-	int				ncyl = 0;
-	int				acyl = 0;
-	int				nhead = 0;
-	int				nsect = 0;
+	uint_t				pcyl = 0;
+	uint_t				ncyl = 0;
+	uint_t				acyl = 0;
+	uint_t				nhead = 0;
+	uint_t				nsect = 0;
 	int				rpm = 0;
-	long				nblocks = 0;
+	diskaddr_t			nblocks = 0;
+	diskaddr_t			tblocks = 0;
 	union {
 		struct mode_format	page3;
 		uchar_t			buf3[MAX_MODE_SENSE_SIZE];
@@ -899,19 +900,6 @@
 	struct mode_format		*page3 = &u_page3.page3;
 	struct mode_geometry		*page4 = &u_page4.page4;
 	struct scsi_ms_header		header;
-	/* refer cmlb_convert_geometry in cmlb.c */
-	static const struct chs_values {
-		uint_t max_cap;		/* Max Capacity for this HS. */
-		uint_t nhead;		/* Heads to use. */
-		uint_t nsect;		/* SPT to use. */
-	} CHS_values[] = {
-		{0x00200000,  64, 32},		/* 1GB or smaller disk. */
-		{0x01000000, 128, 32},		/* 8GB or smaller disk. */
-		{MAXBLKS(255,  63)},		/* 502.02GB or smaller disk. */
-		{MAXBLKS(255, 126)},		/* .98TB or smaller disk. */
-		{INFINITY, 255, 189}		/* Max size is just under 1TB */
-	};
-
 
 	/*
 	 * If the name of this disk appears to be "SUN", use it,
@@ -960,8 +948,13 @@
 	/*
 	 * Get the number of blocks from Read Capacity data. Note that
 	 * the logical block address range from 0 to capacity->sc_capacity.
+	 * Limit the size to 2 TB (UINT32_MAX) to use with SMI labels.
 	 */
-	nblocks = (long)(capacity->sc_capacity + 1);
+	tblocks = (capacity->sc_capacity + 1);
+	if (tblocks > UINT32_MAX)
+		nblocks = UINT32_MAX;
+	else
+		nblocks = tblocks;
 
 	/*
 	 * Get current Page 3 - Format Parameters page
@@ -1000,11 +993,21 @@
 		/*
 		 * Construct a new label out of the sense data,
 		 * Inquiry and Capacity.
+		 *
+		 * If the disk capacity is > 1TB then simply compute
+		 * the CHS values based on the total disk capacity and
+		 * not use the values from mode-sense data.
 		 */
-		pcyl = (page4->cyl_ub << 16) + (page4->cyl_mb << 8) +
-		    page4->cyl_lb;
-		nhead = page4->heads;
-		nsect = page3->sect_track;
+		if (tblocks > INT32_MAX) {
+			compute_chs_values(tblocks, nblocks, &pcyl, &nhead,
+			    &nsect);
+		} else {
+			pcyl = (page4->cyl_ub << 16) + (page4->cyl_mb << 8) +
+				page4->cyl_lb;
+			nhead = page4->heads;
+			nsect = page3->sect_track;
+		}
+
 		rpm = page4->rpm;
 
 		/*
@@ -1013,10 +1016,10 @@
 		 * we have atleast SUN_MIN_CYL cylinders.
 		 */
 		if (pcyl < SUN_MIN_CYL) {
-			if (nhead <= 0 || nsect <= 0) {
+			if (nhead == 0 || nsect == 0) {
 				setdefault = 1;
 			} else if (adjust_disk_geometry(
-			    (int)(capacity->sc_capacity + 1),
+			    (diskaddr_t)(capacity->sc_capacity + 1),
 			    &pcyl, &nhead, &nsect)) {
 				setdefault = 1;
 			}
@@ -1036,20 +1039,7 @@
 		    "capacity data.\n\n");
 
 		/* convert capacity to nsect * nhead * pcyl */
-		/* Unlabeled SCSI floppy device */
-		if (nblocks <= 0x1000) {
-			nhead = 2;
-			pcyl = 80;
-			nsect = nblocks / (nhead * pcyl);
-		} else {
-			for (i = 0; CHS_values[i].max_cap < nblocks &&
-			    CHS_values[i].max_cap != INFINITY; i++)
-				;
-
-			nhead = CHS_values[i].nhead;
-			nsect = CHS_values[i].nsect;
-			pcyl = nblocks / (nhead * nsect);
-		}
+		compute_chs_values(tblocks, nblocks, &pcyl, &nhead, &nsect);
 	}
 
 	/*
@@ -1061,17 +1051,18 @@
 
 	if (option_msg && diag_msg) {
 		err_print("Geometry:\n");
-		err_print("    pcyl:    %d\n", pcyl);
-		err_print("    ncyl:    %d\n", ncyl);
-		err_print("    heads:   %d\n", nhead);
-		err_print("    nsects:  %d\n", nsect);
-		err_print("    acyl:    %d\n", acyl);
+		err_print("    pcyl:    %u\n", pcyl);
+		err_print("    ncyl:    %u\n", ncyl);
+		err_print("    heads:   %u\n", nhead);
+		err_print("    nsects:  %u\n", nsect);
+		err_print("    acyl:    %u\n", acyl);
 
 #if defined(_SUNOS_VTOC_16)
-		err_print("    bcyl:    %d\n", bcyl);
+		err_print("    bcyl:    %u\n", bcyl);
 #endif			/* defined(_SUNOS_VTOC_16) */
 
 		err_print("    rpm:     %d\n", rpm);
+		err_print("    nblocks:     %llu\n", nblocks);
 	}
 
 	/*
@@ -1092,12 +1083,37 @@
 	 * chosen so that this change below does not generate a different
 	 * geometry for currently supported sun disks.
 	 */
-	if ((nsect <= 0) ||
-	    (pcyl * nhead * nsect) < (nblocks - nblocks/32) ||
-	    (pcyl * nhead * nsect) > (nblocks + nblocks/4)) {
-		err_print("Mode sense page(3) reports nsect value as %d, "
-		    "adjusting it to %ld\n", nsect, nblocks / (pcyl * nhead));
-		nsect = nblocks / (pcyl * nhead);
+	if ((nsect == 0) ||
+	    ((diskaddr_t)pcyl * nhead * nsect) < (nblocks - nblocks/32) ||
+	    ((diskaddr_t)pcyl * nhead * nsect) > (nblocks + nblocks/4)) {
+		if (nblocks > (pcyl * nhead)) {
+			err_print("Mode sense page(3) reports nsect value"
+			    " as %d, adjusting it to %llu\n",
+			    nsect, nblocks / (pcyl * nhead));
+			nsect = nblocks / (pcyl * nhead);
+		} else {
+			/* convert capacity to nsect * nhead * pcyl */
+			err_print("\nWARNING: Disk geometry is based on "
+			    "capacity data.\n\n");
+			compute_chs_values(tblocks, nblocks, &pcyl, &nhead,
+			    &nsect);
+			ncyl = pcyl - acyl;
+			if (option_msg && diag_msg) {
+				err_print("Geometry:(after adjustment)\n");
+				err_print("    pcyl:    %u\n", pcyl);
+				err_print("    ncyl:    %u\n", ncyl);
+				err_print("    heads:   %u\n", nhead);
+				err_print("    nsects:  %u\n", nsect);
+				err_print("    acyl:    %u\n", acyl);
+
+#if defined(_SUNOS_VTOC_16)
+				err_print("    bcyl:    %u\n", bcyl);
+#endif
+
+				err_print("    rpm:     %d\n", rpm);
+				err_print("    nblocks:     %llu\n", nblocks);
+			}
+		}
 	}
 
 	/*
@@ -1106,16 +1122,16 @@
 	 * geometry to allow for this, so we don't run off
 	 * the end of the disk.
 	 */
-	if ((pcyl * nhead * nsect) > nblocks) {
-		int	p = pcyl;
+	if (((diskaddr_t)pcyl * nhead * nsect) > nblocks) {
+		uint_t	p = pcyl;
 		if (option_msg && diag_msg) {
-			err_print("Computed capacity (%ld) exceeds actual "
-				"disk capacity (%ld)\n",
-				(long)(pcyl * nhead * nsect), nblocks);
+			err_print("Computed capacity (%llu) exceeds actual "
+			    "disk capacity (%llu)\n",
+			    (diskaddr_t)pcyl * nhead * nsect, nblocks);
 		}
 		do {
 			pcyl--;
-		} while ((pcyl * nhead * nsect) > nblocks);
+		} while (((diskaddr_t)pcyl * nhead * nsect) > nblocks);
 
 		if (can_prompt && expert_mode && !option_f) {
 			/*
@@ -1123,11 +1139,12 @@
 			 * can optimize. For compatability reasons do this
 			 * only in expert mode (refer to bug 1144812).
 			 */
-			int	n = nsect;
+			uint_t	n = nsect;
 			do {
 				n--;
-			} while ((p * nhead * n) > nblocks);
-			if ((p * nhead * n) > (pcyl * nhead * nsect)) {
+			} while (((diskaddr_t)p * nhead * n) > nblocks);
+			if (((diskaddr_t)p * nhead * n) >
+			    ((diskaddr_t)pcyl * nhead * nsect)) {
 				u_ioparam_t	ioparam;
 				int		deflt = 1;
 				/*
@@ -1135,14 +1152,14 @@
 				 */
 				ioparam.io_bounds.lower = 1;
 				ioparam.io_bounds.upper = 2;
-				err_print("1. Capacity = %d, with pcyl = %d "
-					"nhead = %d nsect = %d\n",
-					(pcyl * nhead * nsect),
-					pcyl, nhead, nsect);
-				err_print("2. Capacity = %d, with pcyl = %d "
-					"nhead = %d nsect = %d\n",
-					(p * nhead * n),
-					p, nhead, n);
+				err_print("1. Capacity = %llu, with pcyl = %u "
+				    "nhead = %u nsect = %u\n",
+				    ((diskaddr_t)pcyl * nhead * nsect),
+				    pcyl, nhead, nsect);
+				err_print("2. Capacity = %llu, with pcyl = %u "
+				    "nhead = %u nsect = %u\n",
+				    ((diskaddr_t)p * nhead * n),
+				    p, nhead, n);
 				if (input(FIO_INT, "Select one of the above "
 				    "choices ", ':', &ioparam,
 					&deflt, DATA_INPUT) == 2) {
@@ -1236,9 +1253,9 @@
 		if (option_msg && diag_msg &&
 		    (capacity->sc_capacity + 1 != nblocks)) {
 			err_print("After adjusting geometry you lost"
-				" %llu of %lld blocks.\n",
-				(capacity->sc_capacity + 1 - nblocks),
-				capacity->sc_capacity + 1);
+			    " %llu of %llu blocks.\n",
+			    (capacity->sc_capacity + 1 - nblocks),
+			    capacity->sc_capacity + 1);
 		}
 		while (can_prompt && expert_mode && !option_f) {
 			int				deflt = 1;
@@ -1247,11 +1264,11 @@
 			 * Allow user to modify this by hand if desired.
 			 */
 			(void) sprintf(msg,
-				"\nGeometry: %d heads, %d sectors %d "
-				" cylinders result in %d out of %lld blocks.\n"
-				"Do you want to modify the device geometry",
-				nhead, nsect, pcyl,
-				(int)nblocks, capacity->sc_capacity + 1);
+			    "\nGeometry: %u heads, %u sectors %u cylinders"
+			    " result in %llu out of %llu blocks.\n"
+			    "Do you want to modify the device geometry",
+			    nhead, nsect, pcyl,
+			    nblocks, capacity->sc_capacity + 1);
 
 			ioparam.io_charlist = confirm_list;
 			if (input(FIO_MSTR, msg, '?', &ioparam,
@@ -1261,22 +1278,22 @@
 			ioparam.io_bounds.lower = MINIMUM_NO_HEADS;
 			ioparam.io_bounds.upper = MAXIMUM_NO_HEADS;
 			nhead = input(FIO_INT, "Number of heads", ':',
-				&ioparam, &nhead, DATA_INPUT);
+			    &ioparam, (int *)&nhead, DATA_INPUT);
 			ioparam.io_bounds.lower = MINIMUM_NO_SECTORS;
 			ioparam.io_bounds.upper = MAXIMUM_NO_SECTORS;
 			nsect = input(FIO_INT,
-				"Number of sectors per track",
-				':', &ioparam, &nsect, DATA_INPUT);
+			    "Number of sectors per track",
+			    ':', &ioparam, (int *)&nsect, DATA_INPUT);
 			ioparam.io_bounds.lower = SUN_MIN_CYL;
 			ioparam.io_bounds.upper = MAXIMUM_NO_CYLINDERS;
 			pcyl = input(FIO_INT, "Number of cylinders",
-				':', &ioparam, &pcyl, DATA_INPUT);
-			nblocks = nhead * nsect * pcyl;
+			    ':', &ioparam, (int *)&pcyl, DATA_INPUT);
+			nblocks = (diskaddr_t)nhead * nsect * pcyl;
 			if (nblocks > capacity->sc_capacity + 1) {
-				err_print("Warning: %ld blocks exceeds "
-					"disk capacity of %lld blocks\n",
-					nblocks,
-					capacity->sc_capacity + 1);
+				err_print("Warning: %llu blocks exceeds "
+				    "disk capacity of %llu blocks\n",
+				    nblocks,
+				    capacity->sc_capacity + 1);
 			}
 		}
 	}
@@ -1286,11 +1303,11 @@
 
 	if (option_msg && diag_msg) {
 		err_print("\nGeometry after adjusting for capacity:\n");
-		err_print("    pcyl:    %d\n", pcyl);
-		err_print("    ncyl:    %d\n", ncyl);
-		err_print("    heads:   %d\n", nhead);
-		err_print("    nsects:  %d\n", nsect);
-		err_print("    acyl:    %d\n", acyl);
+		err_print("    pcyl:    %u\n", pcyl);
+		err_print("    ncyl:    %u\n", ncyl);
+		err_print("    heads:   %u\n", nhead);
+		err_print("    nsects:  %u\n", nsect);
+		err_print("    acyl:    %u\n", acyl);
 		err_print("    rpm:     %d\n", rpm);
 	}
 
@@ -1299,8 +1316,8 @@
 	label->dkl_magic = DKL_MAGIC;
 
 	(void) snprintf(label->dkl_asciilabel, sizeof (label->dkl_asciilabel),
-		"%s cyl %d alt %d hd %d sec %d",
-		disk_name, ncyl, acyl, nhead, nsect);
+	    "%s cyl %u alt %u hd %u sec %u",
+	    disk_name, ncyl, acyl, nhead, nsect);
 
 	label->dkl_pcyl = pcyl;
 	label->dkl_ncyl = ncyl;
@@ -1312,7 +1329,8 @@
 	label->dkl_rpm = rpm;
 
 #if defined(_FIRMWARE_NEEDS_FDISK)
-	(void) auto_solaris_part(label);
+	if (auto_solaris_part(label) == -1)
+		goto err;
 	ncyl = label->dkl_ncyl;
 #endif		/* defined(_FIRMWARE_NEEDS_FDISK) */
 
@@ -1344,9 +1362,9 @@
 "Changing disk type name from '%s' to '%s'\n", old_name, disk_name);
 			}
 			(void) snprintf(label->dkl_asciilabel,
-				sizeof (label->dkl_asciilabel),
-				"%s cyl %d alt %d hd %d sec %d",
-				disk_name, ncyl, acyl, nhead, nsect);
+			    sizeof (label->dkl_asciilabel),
+			    "%s cyl %u alt %u hd %u sec %u",
+			    disk_name, ncyl, acyl, nhead, nsect);
 			(void) checksum(label, CK_MAKESUM);
 			disk = find_scsi_disk_type(disk_name, label);
 		}
@@ -1431,10 +1449,10 @@
 
 	if (option_msg && diag_msg) {
 		err_print("Format.dat geometry:\n");
-		err_print("    pcyl:    %d\n", pcyl);
-		err_print("    heads:   %d\n", nhead);
-		err_print("    nsects:  %d\n", nsect);
-		err_print("    acyl:    %d\n", acyl);
+		err_print("    pcyl:    %u\n", pcyl);
+		err_print("    heads:   %u\n", nhead);
+		err_print("    nsects:  %u\n", nsect);
+		err_print("    acyl:    %u\n", acyl);
 		err_print("    rpm:     %d\n", rpm);
 	}
 
@@ -1443,9 +1461,9 @@
 	label->dkl_magic = DKL_MAGIC;
 
 	(void) snprintf(label->dkl_asciilabel, sizeof (label->dkl_asciilabel),
-		"%s cyl %d alt %d hd %d sec %d",
-		disk_type->dtype_asciilabel,
-		ncyl, acyl, nhead, nsect);
+	    "%s cyl %u alt %u hd %u sec %u",
+	    disk_type->dtype_asciilabel,
+	    ncyl, acyl, nhead, nsect);
 
 	label->dkl_pcyl = pcyl;
 	label->dkl_ncyl = ncyl;
@@ -1478,12 +1496,12 @@
 {
 	int				i;
 	int				ncyls[NDKMAP];
-	int				nblks;
+	diskaddr_t			nblks;
 	int				cyl;
 	struct dk_vtoc			*vtoc;
 	struct part_table		*pt;
 	struct default_partitions	*dpt;
-	long				capacity;
+	diskaddr_t			capacity;
 	int				freecyls;
 	int				blks_per_cyl;
 	int				ncyl;
@@ -1509,8 +1527,8 @@
 	 * Find a partition that matches this disk.  Capacity
 	 * is in integral number of megabytes.
 	 */
-	capacity = (long)(label->dkl_ncyl * label->dkl_nhead *
-		label->dkl_nsect) / (long)((1024 * 1024) / DEV_BSIZE);
+	capacity = ((diskaddr_t)(label->dkl_ncyl) * label->dkl_nhead *
+	    label->dkl_nsect) / (1024 * 1024) / DEV_BSIZE;
 	dpt = default_partitions;
 	for (i = 0; i < DEFAULT_PARTITION_TABLE_SIZE; i++, dpt++) {
 		if (capacity >= dpt->min_capacity &&
@@ -1520,8 +1538,8 @@
 	}
 	if (i == DEFAULT_PARTITION_TABLE_SIZE) {
 		if (option_msg && diag_msg) {
-			err_print("No matching default partition (%ld)\n",
-				capacity);
+			err_print("No matching default partition (%llu)\n",
+			    capacity);
 		}
 		return (0);
 	}
@@ -1556,8 +1574,8 @@
 			for (i = 0; i < NDKMAP; i++) {
 				if (ncyls[i] == 0)
 					continue;
-				err_print("Partition %d: %d cyls\n",
-					i, ncyls[i]);
+				err_print("Partition %d: %u cyls\n",
+				    i, ncyls[i]);
 			}
 			err_print("Free cylinders exhausted (%d)\n",
 				freecyls);
@@ -1879,7 +1897,7 @@
 	 */
 	dp = ctlr->ctlr_ctype->ctype_dlist;
 	if (dp == NULL) {
-		ctlr->ctlr_ctype->ctype_dlist = dp;
+		ctlr->ctlr_ctype->ctype_dlist = disk;
 	} else {
 		while (dp->dtype_next != NULL) {
 			dp = dp->dtype_next;
@@ -1947,8 +1965,8 @@
 #elif defined(_SUNOS_VTOC_16)
 			part->pinfo_map[i].dkl_cylno =
 				label->dkl_vtoc.v_part[i].p_start /
-					((int)(disk->dtype_nhead *
-						disk->dtype_nsect - apc));
+				    ((blkaddr32_t)(disk->dtype_nhead *
+				    disk->dtype_nsect - apc));
 			part->pinfo_map[i].dkl_nblk =
 				label->dkl_vtoc.v_part[i].p_size;
 #else
@@ -2218,11 +2236,12 @@
  * cylinder )
  */
 int
-adjust_disk_geometry(int capacity, int *cyl, int *nhead, int *nsect)
+adjust_disk_geometry(diskaddr_t capacity, uint_t *cyl, uint_t *nhead,
+	uint_t *nsect)
 {
-	int	lcyl = *cyl;
-	int	lnhead = *nhead;
-	int	lnsect = *nsect;
+	uint_t	lcyl = *cyl;
+	uint_t	lnhead = *nhead;
+	uint_t	lnsect = *nsect;
 
 	assert(lcyl < SUN_MIN_CYL);
 
@@ -2272,14 +2291,14 @@
  * values will be twiddled until they are all less than or
  * equal to their limit.  Returns the number in the new geometry.
  */
-static int
+static diskaddr_t
 square_box(
-		int capacity,
-		int *dim1, int lim1,
-		int *dim2, int lim2,
-		int *dim3, int lim3)
+		diskaddr_t capacity,
+		uint_t *dim1, uint_t lim1,
+		uint_t *dim2, uint_t lim2,
+		uint_t *dim3, uint_t lim3)
 {
-	int	i;
+	uint_t	i;
 
 	/*
 	 * Although the routine should work with any ordering of
@@ -2347,3 +2366,73 @@
 	return (*dim1 * *dim2 * *dim3);
 }
 #endif /* defined(_SUNOS_VTOC_8) */
+
+/*
+ * Calculate CHS values based on the capacity data.
+ *
+ * NOTE: This function is same as cmlb_convert_geomerty() function in
+ * cmlb kernel module.
+ */
+static void
+compute_chs_values(diskaddr_t total_capacity, diskaddr_t usable_capacity,
+	uint_t *pcylp, uint_t *nheadp, uint_t *nsectp)
+{
+
+	/* Unlabeled SCSI floppy device */
+	if (total_capacity <= 0x1000) {
+		*nheadp = 2;
+		*pcylp = 80;
+		*nsectp = total_capacity / (80 * 2);
+		return;
+	}
+
+	/*
+	 * For all devices we calculate cylinders using the heads and sectors
+	 * we assign based on capacity of the device.  The algorithm is
+	 * designed to be compatible with the way other operating systems
+	 * lay out fdisk tables for X86 and to insure that the cylinders never
+	 * exceed 65535 to prevent problems with X86 ioctls that report
+	 * geometry.
+	 * For some smaller disk sizes we report geometry that matches those
+	 * used by X86 BIOS usage. For larger disks, we use SPT that are
+	 * multiples of 63, since other OSes that are not limited to 16-bits
+	 * for cylinders stop at 63 SPT we make do by using multiples of 63 SPT.
+	 *
+	 * The following table (in order) illustrates some end result
+	 * calculations:
+	 *
+	 * Maximum number of blocks 		nhead	nsect
+	 *
+	 * 2097152 (1GB)			64	32
+	 * 16777216 (8GB)			128	32
+	 * 1052819775 (502.02GB)		255  	63
+	 * 2105639550 (0.98TB)			255	126
+	 * 3158459325 (1.47TB)			255  	189
+	 * 4211279100 (1.96TB)			255  	252
+	 * 5264098875 (2.45TB)			255  	315
+	 * ...
+	 */
+
+	if (total_capacity <= 0x200000) {
+		*nheadp = 64;
+		*nsectp = 32;
+	} else if (total_capacity <= 0x01000000) {
+		*nheadp = 128;
+		*nsectp = 32;
+	} else {
+		*nheadp = 255;
+
+		/* make nsect be smallest multiple of 63 */
+		*nsectp = ((total_capacity +
+		    (UINT16_MAX * 255 * 63) - 1) /
+		    (UINT16_MAX * 255 * 63)) * 63;
+
+		if (*nsectp == 0)
+			*nsectp = (UINT16_MAX / 63) * 63;
+	}
+
+	if (usable_capacity < total_capacity)
+		*pcylp = usable_capacity / ((*nheadp) * (*nsectp));
+	else
+		*pcylp = total_capacity / ((*nheadp) * (*nsectp));
+}
--- a/usr/src/cmd/format/badsec.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/badsec.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -21,7 +20,7 @@
  */
 
 /*
- * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  * copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
@@ -32,8 +31,6 @@
 #ifndef	_BADSEC_H
 #define	_BADSEC_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -44,9 +41,9 @@
 
 #define	MAXBLENT	4
 struct	badsec_lst {
-	int	bl_cnt;
+	uint_t	bl_cnt;
 	struct	badsec_lst *bl_nxt;
-	int	bl_sec[MAXBLENT];
+	uint_t	bl_sec[MAXBLENT];
 };
 
 #define	BADSLSZ		sizeof (struct badsec_lst)
@@ -57,16 +54,16 @@
 struct	alts_mempart {			/* incore alts partition info	*/
 	int	ap_flag;		/* flag for alternate partition	*/
 	struct	alts_parttbl *ap_tblp;	/* alts partition table		*/
-	int	ap_tbl_secsiz;		/* alts parttbl sector size	*/
+	uint_t	ap_tbl_secsiz;		/* alts parttbl sector size	*/
 	uchar_t	*ap_memmapp;		/* incore alternate sector map	*/
 	uchar_t	*ap_mapp;		/* alternate sector map		*/
-	int	ap_map_secsiz;		/* alts partmap sector size	*/
-	int	ap_map_sectot;		/* alts partmap # sector 	*/
+	uint_t	ap_map_secsiz;		/* alts partmap sector size	*/
+	uint_t	ap_map_sectot;		/* alts partmap # sector 	*/
 	struct  alts_ent *ap_entp;	/* alternate sector entry table */
-	int	ap_ent_secsiz;		/* alts entry sector size	*/
+	uint_t	ap_ent_secsiz;		/* alts entry sector size	*/
 	struct	alts_ent *ap_gbadp;	/* growing badsec entry table	*/
-	int	ap_gbadcnt;		/* growing bad sector count	*/
-	struct	partition part;		/* alts partition configuration */
+	uint_t	ap_gbadcnt;		/* growing bad sector count	*/
+	struct	dkl_partition part;	/* alts partition configuration */
 };
 
 /*	size of incore alternate partition memory structure		*/
@@ -74,17 +71,17 @@
 
 struct	altsectbl {			/* working alts info		*/
 	struct  alts_ent *ast_entp;	/* alternate sector entry table */
-	int	ast_entused;		/* entry used			*/
+	uint_t	ast_entused;		/* entry used			*/
 	struct	alt_info *ast_alttblp;	/* alts info			*/
-	int	ast_altsiz;		/* size of alts info		*/
+	uint_t	ast_altsiz;		/* size of alts info		*/
 	struct  alts_ent *ast_gbadp;	/* growing bad sector entry ptr */
-	int	ast_gbadcnt;		/* growing bad sector entry cnt */
+	uint_t	ast_gbadcnt;		/* growing bad sector entry cnt */
 };
 /*	size of incore alternate partition memory structure		*/
 #define	ALTSECTBL_SIZE	sizeof (struct altsectbl)
 
 /*	macro definitions						*/
-#define	byte_to_secsiz(APSIZE, BPS)	(daddr_t) \
+#define	byte_to_secsiz(APSIZE, BPS)	(uint_t) \
 					((((APSIZE) + (BPS) - 1) \
 					    / (uint_t)(BPS)) * (BPS))
 
--- a/usr/src/cmd/format/ctlr_ata.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/ctlr_ata.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains the routines for the IDE drive interface
  */
@@ -68,7 +65,7 @@
 #ifdef i386
 static int	ata_ex_cur(struct defect_list *);
 static int	ata_wr_cur(struct defect_list *);
-static int	ata_repair(int, int);
+static int	ata_repair(diskaddr_t, int);
 #endif /* i386 */
 #else /* __STDC__ */
 static int	ata_ck_format();
@@ -114,7 +111,7 @@
 
 
 #if defined(i386)
-static struct	partition	*dpart = NULL;
+static struct	dkl_partition	*dpart = NULL;
 #endif	/* defined(i386) */
 extern	struct	badsec_lst	*badsl_chain;
 extern	int	badsl_chain_cnt;
@@ -153,9 +150,9 @@
 {
 	int	tmpsec;
 	struct dadkio_rwcmd	dadkio_rwcmd;
-	daddr_t	blkno;
+	blkaddr_t	blkno;
 
-	blkno = (daddr_t)blk64;
+	blkno = (blkaddr_t)blk64;
 	bzero((caddr_t)&dadkio_rwcmd, sizeof (struct dadkio_rwcmd));
 
 	tmpsec = secnt * 512;
@@ -219,7 +216,8 @@
 	unsigned char bufaddr[2048];
 	int status;
 
-	status = ata_rdwr(DIR_READ, cur_file, 1, 4, (caddr_t)bufaddr, 0, NULL);
+	status = ata_rdwr(DIR_READ, cur_file, (diskaddr_t)1, 4,
+	    (caddr_t)bufaddr, 0, NULL);
 
 	return (!status);
 }
@@ -242,7 +240,7 @@
 	for (i = 0; i < V_NUMPAR && alts_slice == -1; i++) {
 		if (cur_parts->vtoc.v_part[i].p_tag == V_ALTSCTR) {
 			alts_slice = i;
-			dpart = (struct partition *)&cur_parts->vtoc.v_part[i];
+			dpart = &cur_parts->vtoc.v_part[i];
 		}
 	}
 
@@ -301,14 +299,14 @@
 			list->header.magicno = (uint_t)DEFECT_MAGIC;
 			list->list = new_defect;
 			for (i = 0; i < ap->ap_tblp->alts_ent_used;
-					    i++, new_defect++) {
+			    i++, new_defect++) {
 				new_defect->cyl =
-					    bn2c((ap->ap_entp)[i].bad_start);
+				    bn2c((ap->ap_entp)[i].bad_start);
 				new_defect->head =
-					    bn2h((ap->ap_entp)[i].bad_start);
+				    bn2h((ap->ap_entp)[i].bad_start);
 				new_defect->bfi = UNKNOWN;
 				new_defect->sect =
-					    bn2s((ap->ap_entp)[i].bad_start);
+				    bn2s((ap->ap_entp)[i].bad_start);
 				new_defect->nbits = UNKNOWN;
 			}
 
@@ -365,7 +363,7 @@
 }
 
 int
-ata_repair(int bn, int flag)
+ata_repair(diskaddr_t bn, int flag)
 {
 
 	int	status;
@@ -398,7 +396,7 @@
 		}
 		blc_p = blc_p->bl_nxt;
 	}
-	blc_p->bl_sec[blc_p->bl_cnt++] = bn;
+	blc_p->bl_sec[blc_p->bl_cnt++] = (uint_t)bn;
 	gbadsl_chain_cnt++;
 
 	(void) updatebadsec(dpart, 0);
@@ -460,7 +458,7 @@
 		/* test for unsupported list format */
 		if ((dlist->bfi != UNKNOWN) || (dlist->nbits != UNKNOWN)) {
 			(void) fprintf(stderr,
-				"BFI unsuported format for bad sectors\n");
+			    "BFI unsuported format for bad sectors\n");
 			return (-1);
 		}
 
@@ -487,7 +485,7 @@
 			blc_p = blc_p->bl_nxt;
 		}
 		blc_p->bl_sec[blc_p->bl_cnt++] =
-			    chs2bn(dlist->cyl, dlist->head, dlist->sect);
+		    (uint_t)chs2bn(dlist->cyl, dlist->head, dlist->sect);
 		gbadsl_chain_cnt++;
 		dlist++;
 	}
--- a/usr/src/cmd/format/ctlr_ata.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/ctlr_ata.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -21,15 +20,13 @@
  */
 
 /*
- * Copyright 1998-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_CTLR_ATA_H
 #define	_CTLR_ATA_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -49,7 +46,7 @@
 #define	TRIPLET(u, m, l)	((int)((((u))&0xff<<16) + \
 				(((m)&0xff)<<8) + (l&0xff)))
 #if	defined(i386)
-daddr_t	altsec_offset;		/* Alternate sector offset */
+diskaddr_t	altsec_offset;	/* Alternate sector offset */
 #endif	/* defined(i386) */
 
 #ifdef	__STDC__
--- a/usr/src/cmd/format/ctlr_scsi.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/ctlr_scsi.c	Thu Sep 11 18:00:50 2008 -0700
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains the routines for embedded scsi disks
  */
@@ -327,8 +325,8 @@
 	/*
 	 * Try to read the first four blocks.
 	 */
-	status = scsi_rdwr(DIR_READ, cur_file, 0, 4, (caddr_t)cur_buf,
-		F_SILENT, NULL);
+	status = scsi_rdwr(DIR_READ, cur_file, (diskaddr_t)0, 4,
+		(caddr_t)cur_buf, F_SILENT, NULL);
 	return (!status);
 }
 
--- a/usr/src/cmd/format/defect.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/defect.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains routines that manipulate the defect list.
  */
@@ -214,7 +212,7 @@
 	 */
 	lp = (int *)list->list;
 	for (i = 0; i < (list->header.count *
-			sizeof (struct defect_entry) / sizeof (int)); i++)
+	    sizeof (struct defect_entry) / sizeof (int)); i++)
 		sum ^= *(lp + i);
 	/*
 	 * If in check mode, return whether header checksum was correct.
@@ -257,7 +255,7 @@
 	} else {
 		fmt_print("                ");
 		fmt_print("%8d", def->sect);
-		fmt_print("%8lu", chs2bn(def->cyl, def->head, def->sect));
+		fmt_print("%8llu", chs2bn(def->cyl, def->head, def->sect));
 	}
 	fmt_print("\n");
 }
--- a/usr/src/cmd/format/disk_generic.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/disk_generic.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions that implement the fdisk menu commands.
  */
@@ -67,9 +64,8 @@
  *	Local prototypes for ANSI C compilers
  */
 static int	generic_ck_format(void);
-static int	generic_rdwr(int dir, int fd, daddr_t blkno, int secnt,
+static int	generic_rdwr(int dir, int fd, diskaddr_t blkno, int secnt,
 			caddr_t bufaddr, int flags, int *xfercntp);
-
 #else	/* __STDC__ */
 
 static int	generic_ck_format();
@@ -102,7 +98,7 @@
 	 * Try to read the first four blocks.
 	 */
 	status = generic_rdwr(DIR_READ, cur_file, 0, 4, (caddr_t)cur_buf,
-			F_SILENT, NULL);
+	    F_SILENT, NULL);
 	return (!status);
 }
 
@@ -115,37 +111,52 @@
 generic_rdwr(dir, fd, blkno, secnt, bufaddr, flags, xfercntp)
 	int	dir;
 	int	fd;
-	daddr_t	blkno;
+	diskaddr_t	blkno;
 	int	secnt;
 	caddr_t	bufaddr;
 	int	flags;
 	int	*xfercntp;
 {
 
-	int	tmpsec, status, tmpblk;
+	offset_t	tmpsec, status, tmpblk;
+	int		ret;
 
-	tmpsec = secnt * UBSIZE;
-	tmpblk = blkno * UBSIZE;
+	tmpsec = (offset_t)secnt * UBSIZE;
+	tmpblk = (offset_t)blkno * UBSIZE;
 
+#if defined(_FIRMWARE_NEEDS_FDISK)
+	/* Use "p0" file to seek/read the data  */
+	(void) open_cur_file(FD_USE_P0_PATH);
+#endif
 	if (dir == DIR_READ) {
-		status = lseek(fd, tmpblk, SEEK_SET);
-		if (status != tmpblk)
-			return (status);
+		status = llseek(fd, tmpblk, SEEK_SET);
+		if (status != tmpblk) {
+			ret = (int)status;
+			goto out;
+		}
 
-		status = read(fd, bufaddr, tmpsec);
+		status = read(fd, bufaddr, (size_t)tmpsec);
 		if (status != tmpsec)
-			return (tmpsec);
+			ret = (int)tmpsec;
 		else
-			return (0);
+			ret = 0;
 	} else {
-		status = lseek(fd, tmpblk, SEEK_SET);
-		if (status != tmpblk)
-			return (status);
+		status = llseek(fd, tmpblk, SEEK_SET);
+		if (status != tmpblk) {
+			ret = (int)status;
+			goto out;
+		}
 
-		status = write(fd, bufaddr, tmpsec);
+		status = write(fd, bufaddr, (size_t)tmpsec);
 		if (status != tmpsec)
-			return (tmpsec);
+			ret = (int)tmpsec;
 		else
-			return (0);
+			ret = 0;
 	}
+out:
+#if defined(_FIRMWARE_NEEDS_FDISK)
+	/* Restore cur_file with cur_disk->disk_path */
+	(void) open_cur_file(FD_USE_CUR_DISK_PATH);
+#endif
+	return (ret);
 }
--- a/usr/src/cmd/format/global.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/global.h	Thu Sep 11 18:00:50 2008 -0700
@@ -19,15 +19,13 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_GLOBAL_H
 #define	_GLOBAL_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -44,7 +42,11 @@
 #endif
 
 #ifndef UINT_MAX32
-#define	UINT_MAX32	0xffffffff
+#define	UINT_MAX32	0xffffffffU
+#endif
+
+#if !defined(_EXTVTOC)
+#define	_EXTVTOC	/* extented vtoc (struct extvtoc) format is used */
 #endif
 
 /*
@@ -114,22 +116,22 @@
 struct	defect_list cur_list;		/* current disk's defect list */
 void	*cur_buf;			/* current disk's I/O buffer */
 void	*pattern_buf;			/* current disk's pattern buffer */
-int	pcyl;				/* # physical cyls */
-int	ncyl;				/* # data cyls */
-int	acyl;				/* # alt cyls */
-int	nhead;				/* # heads */
-int	phead;				/* # physical heads */
-int	nsect;				/* # data sects/track */
-int	psect;				/* # physical sects/track */
-int	apc;				/* # alternates/cyl */
-int	solaris_offset;			/* Solaris offset, this value is zero */
+uint_t	pcyl;				/* # physical cyls */
+uint_t	ncyl;				/* # data cyls */
+uint_t	acyl;				/* # alt cyls */
+uint_t	nhead;				/* # heads */
+uint_t	phead;				/* # physical heads */
+uint_t	nsect;				/* # data sects/track */
+uint_t	psect;				/* # physical sects/track */
+uint_t	apc;				/* # alternates/cyl */
+uint_t	solaris_offset;			/* Solaris offset, this value is zero */
 					/* for non-fdisk machines. */
 #if defined(_SUNOS_VTOC_16)
-int	bcyl;				/* # other cyls */
+uint_t	bcyl;				/* # other cyls */
 #endif		/* defined(_SUNOS_VTOC_16) */
 
 struct	mboot boot_sec;			/* fdisk partition info */
-int	xstart;				/* solaris partition start */
+uint_t	xstart;				/* solaris partition start */
 char	x86_devname[MAXNAMELEN];	/* saved device name for fdisk */
 					/* information accesses */
 struct	mctlr_list	*controlp;	/* master controller list ptr */
@@ -140,11 +142,11 @@
  * the current disk.
  */
 #define	sectors(h)	((h) == nhead - 1 ? nsect - apc : nsect)
-#define	spc()		((int)(nhead * nsect - apc))
-#define	chs2bn(c, h, s)	((daddr_t)((c) * spc() + (h) * nsect + (s)))
-#define	bn2c(bn)	((bn) / (int)spc())
-#define	bn2h(bn)	(((bn) % (int)spc()) / (int)nsect)
-#define	bn2s(bn)	(((bn) % (int)spc()) % (int)nsect)
+#define	spc()		(nhead * nsect - apc)
+#define	chs2bn(c, h, s)	(((diskaddr_t)(c) * spc() + (h) * nsect + (s)))
+#define	bn2c(bn)	(uint_t)((diskaddr_t)(bn) / spc())
+#define	bn2h(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) / nsect)
+#define	bn2s(bn)	(uint_t)(((diskaddr_t)(bn) % spc()) % nsect)
 #define	datasects()	(ncyl * spc())
 #define	totalsects()	((ncyl + acyl) * spc())
 #define	physsects()	(pcyl * spc())
--- a/usr/src/cmd/format/hardware_structs.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/hardware_structs.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,15 +19,13 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 1991-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_HARDWARE_STRUCTS_H
 #define	_HARDWARE_STRUCTS_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -81,19 +78,19 @@
 	ulong_t	dtype_options;			/* flags for options */
 	uint_t	dtype_fmt_time;			/* format time */
 	uint_t	dtype_bpt;			/* # bytes per track */
-	int	dtype_ncyl;			/* # of data cylinders */
-	int	dtype_acyl;			/* # of alternate cylinders */
-	int	dtype_pcyl;			/* # of physical cylinders */
-	int	dtype_nhead;			/* # of heads */
-	int	dtype_phead;			/* # of physical heads */
-	int	dtype_nsect;			/* # of data sectors/track */
-	int	dtype_psect;			/* # physical sectors/track */
-	int	dtype_rpm;			/* rotations per minute */
+	uint_t	dtype_ncyl;			/* # of data cylinders */
+	uint_t	dtype_acyl;			/* # of alternate cylinders */
+	uint_t	dtype_pcyl;			/* # of physical cylinders */
+	uint_t	dtype_nhead;			/* # of heads */
+	uint_t	dtype_phead;			/* # of physical heads */
+	uint_t	dtype_nsect;			/* # of data sectors/track */
+	uint_t	dtype_psect;			/* # physical sectors/track */
+	uint_t	dtype_rpm;			/* rotations per minute */
 	int	dtype_cyl_skew;			/* cylinder skew */
 	int	dtype_trk_skew;			/* track skew */
-	int	dtype_trks_zone;		/* # tracks per zone */
-	int	dtype_atrks;			/* # alt. tracks  */
-	int	dtype_asect;			/* # alt. sectors */
+	uint_t	dtype_trks_zone;		/* # tracks per zone */
+	uint_t	dtype_atrks;			/* # alt. tracks  */
+	uint_t	dtype_asect;			/* # alt. sectors */
 	int	dtype_cache;			/* cache control */
 	int	dtype_threshold;		/* cache prefetch threshold */
 	int	dtype_read_retries;		/* read retries */
--- a/usr/src/cmd/format/io.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/io.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains I/O related functions.
  */
@@ -71,7 +69,7 @@
 static int	checkeof(void);
 static void	flushline(void);
 static int	strcnt(char *s1, char *s2);
-static int	getbn(char *str, daddr_t *iptr);
+static int	getbn(char *str, diskaddr_t *iptr);
 static void	print_input_choices(int type, u_ioparam_t *param);
 static int	slist_widest_str(slist_t *slist);
 static void	ljust_print(char *str, int width);
@@ -89,7 +87,7 @@
 static int	checkeof(void);
 static void	flushline(void);
 static int	strcnt(char *s1, char *s2);
-static int	getbn(char *str, daddr_t *iptr);
+static int	getbn(char *str, diskaddr_t *iptr);
 static void	print_input_choices(int type, u_ioparam_t *param);
 static int	slist_widest_str(slist_t *slist);
 static void	ljust_print(char *str, int width);
@@ -347,10 +345,12 @@
 static int
 getbn(str, iptr)
 	char	*str;
-	daddr_t	*iptr;
+	diskaddr_t	*iptr;
 {
 	char	*cptr, *hptr, *sptr;
-	int	cyl, head, sect, wild;
+	int	cyl, head, sect;
+	int	wild;
+	diskaddr_t	wild64;
 	TOKEN	buf;
 
 	/*
@@ -366,8 +366,8 @@
 	 * If there wasn't one, convert string to an integer and return it.
 	 */
 	if (*str == '\0') {
-		wild = physsects() - 1;
-		if (geti(cptr, (int *)iptr, &wild))
+		wild64 = physsects() - 1;
+		if (geti64(cptr, iptr, &wild64))
 			return (-1);
 		return (0);
 	}
@@ -449,7 +449,7 @@
 	int		cmdflag;
 {
 	int		interactive, help, i, length, index, tied;
-	daddr_t		bn;
+	blkaddr_t	bn;
 	diskaddr_t	bn64;
 	char		**str, **strings;
 	TOKEN		token, cleantoken;
@@ -499,9 +499,11 @@
 	if (deflt != NULL) {
 		switch (type) {
 		case FIO_BN:
-			fmt_print("[%d, ", *deflt);
-			pr_dblock(fmt_print, (daddr_t)*deflt);
+#if !defined(lint)	/* caller has aligned the pointer specifying FIO_BN */
+			fmt_print("[%llu, ", *(diskaddr_t *)deflt);
+			pr_dblock(fmt_print, *(diskaddr_t *)deflt);
 			fmt_print("]");
+#endif
 			break;
 		case FIO_INT:
 			fmt_print("[%d]", *deflt);
@@ -544,8 +546,9 @@
 			 * Old-style partition size input, used to
 			 * modify complete partition tables
 			 */
-			fmt_print("[%db, %dc, %1.2fmb, %1.2fgb]", *deflt,
-			    bn2c(*deflt), bn2mb(*deflt), bn2gb(*deflt));
+			blokno = *(blkaddr32_t *)deflt;
+			fmt_print("[%llub, %uc, %1.2fmb, %1.2fgb]", blokno,
+			    bn2c(blokno), bn2mb(blokno), bn2gb(blokno));
 			break;
 		case FIO_ECYL:
 			/*
@@ -578,14 +581,13 @@
 			if (part_deflt->deflt_size == 0) {
 				cylno = part_deflt->start_cyl;
 			} else if (part_deflt->start_cyl == 0) {
-				cylno = bn2c(part_deflt->deflt_size)
-				    - 1;
+				cylno = bn2c(part_deflt->deflt_size) - 1;
 			} else {
 				cylno = (bn2c(part_deflt->deflt_size) +
 					    part_deflt->start_cyl) - 1;
 			}
 
-			fmt_print("[%db, %dc, %de, %1.2fmb, %1.2fgb]",
+			fmt_print("[%ub, %uc, %de, %1.2fmb, %1.2fgb]",
 			    part_deflt->deflt_size,
 			    bn2c(part_deflt->deflt_size),
 			    cylno,
@@ -813,31 +815,22 @@
 			(uint64_t *)NULL))
 			    break;
 		} else {
-		    if (getbn(cleantoken, &bn))
+		    if (getbn(cleantoken, &bn64))
 			break;
 		}
-		if (cur_label == L_TYPE_EFI) {
-		    if ((bn64 < bounds->lower) || (bn64 > bounds->upper)) {
+		/*
+		 * Check to be sure it is within the legal bounds.
+		 */
+		if ((bn64 < bounds->lower) || (bn64 > bounds->upper)) {
 			err_print("`");
 			pr_dblock(err_print, bn64);
 			err_print("' is out of range.\n");
 			break;
-		    }
-		    return (bn64);
 		}
 		/*
-		 * Check to be sure it is within the legal bounds.
+		 * It's ok, return it.
 		 */
-		if ((bn < bounds->lower) || (bn > bounds->upper)) {
-			err_print("`");
-			pr_dblock(err_print, bn);
-			err_print("' is out of range.\n");
-			break;
-		}
-		/*
-		 * If it's ok, return it.
-		 */
-		return (bn);
+		return (bn64);
 	/*
 	 * Expecting an integer.
 	 */
@@ -864,7 +857,7 @@
 		 * Check to be sure it is within the legal bounds.
 		 */
 		if ((bn < bounds->lower) || (bn > bounds->upper)) {
-			err_print("`%ld' is out of range.\n", bn);
+			err_print("`%lu' is out of range.\n", bn);
 			break;
 		}
 		/*
@@ -928,14 +921,15 @@
 		 * Check to be sure it is within the legal bounds.
 		 */
 		if ((bn < bounds->lower) || (bn > bounds->upper)) {
-			err_print("`%ld' is out of range.\n", bn);
+			err_print("`%lu' is out of range.\n", bn);
 			break;
 		}
 		/*
 		 * For optional case, return 1 indicating that
 		 * the user actually did enter something.
 		 */
-		*deflt = bn;
+		if (!deflt)
+			*deflt = bn;
 		return (1);
 	/*
 	 * Expecting a closed string.  This means that the input
@@ -1107,7 +1101,7 @@
 		if (help) {
 			fmt_print("Expecting up to %llu blocks,",
 			    bounds->upper);
-			fmt_print(" %llu cylinders, ", bn2c(bounds->upper));
+			fmt_print(" %u cylinders, ", bn2c(bounds->upper));
 			fmt_print(" %1.2f megabytes, ", bn2mb(bounds->upper));
 			fmt_print("or %1.2f gigabytes\n", bn2gb(bounds->upper));
 			break;
@@ -1159,34 +1153,33 @@
 			/*
 			 * Convert token to a disk block number.
 			 */
-			i = bounds->upper;
-			if (geti(cleantoken, &value, &i))
+			if (geti64(cleantoken, &bn64, &bounds->upper))
 				break;
-			bn = value;
 			/*
 			 * Check to be sure it is within the legal bounds.
 			 */
-			if ((bn < bounds->lower) || (bn > bounds->upper)) {
+			if ((bn64 < bounds->lower) || (bn64 > bounds->upper)) {
 				err_print(
-"`%ldb' is out of the range %llu to %llu\n",
-				    bn, bounds->lower, bounds->upper);
+				    "`%llub' is out of the range %llu "
+				    "to %llu\n",
+				    bn64, bounds->lower, bounds->upper);
 				break;
 			}
 			/*
 			 * Verify the block lies on a cylinder boundary
 			 */
-			if ((bn % spc()) != 0) {
+			if ((bn64 % spc()) != 0) {
 				err_print(
-"partition size must be a multiple of %d blocks to lie on a cylinder \
-boundary\n",
+				    "partition size must be a multiple of "
+				    "%u blocks to lie on a cylinder boundary\n",
 				    spc());
 				err_print(
-"%ld blocks is approximately %ld cylinders, %1.2f megabytes or %1.2f\
-gigabytes\n",
-				    bn, bn2c(bn), bn2mb(bn), bn2gb(bn));
+				    "%llu blocks is approximately %u cylinders,"
+				    " %1.2f megabytes or %1.2f gigabytes\n",
+				    bn64, bn2c(bn64), bn2mb(bn64), bn2gb(bn64));
 				break;
 			}
-			return (bn);
+			return (bn64);
 		case 'c':
 			/*
 			 * Convert token from a number of cylinders to
@@ -1225,13 +1218,13 @@
 			/*
 			 * Convert to blocks
 			 */
-			bn = mb2bn(nmegs);
+			bn64 = mb2bn(nmegs);
 			/*
 			 * Round value up to nearest cylinder
 			 */
 			i = spc();
-			bn = ((bn + (i-1)) / i) * i;
-			return (bn);
+			bn64 = ((bn64 + (i-1)) / i) * i;
+			return (bn64);
 		case 'g':
 			/*
 			 * Convert token from gigabytes to a block number.
@@ -1251,13 +1244,13 @@
 			/*
 			 * Convert to blocks
 			 */
-			bn = gb2bn(ngigs);
+			bn64 = gb2bn(ngigs);
 			/*
 			 * Round value up to nearest cylinder
 			 */
 			i = spc();
-			bn = ((bn + (i-1)) / i) * i;
-			return (bn);
+			bn64 = ((bn64 + (i-1)) / i) * i;
+			return (bn64);
 		default:
 			err_print(
 "Please specify units in either b(blocks), c(cylinders), m(megabytes) \
@@ -1279,10 +1272,10 @@
 		if (help) {
 			fmt_print("Expecting up to %llu blocks,",
 			    bounds->upper);
-			fmt_print(" %llu cylinders, ",
+			fmt_print(" %u cylinders, ",
 			    bn2c(bounds->upper));
-			fmt_print(" %llu end cylinder, ",
-			    (bounds->upper / spc()));
+			fmt_print(" %u end cylinder, ",
+			    (uint_t)(bounds->upper / spc()));
 			fmt_print(" %1.2f megabytes, ",
 			    bn2mb(bounds->upper));
 			fmt_print("or %1.2f gigabytes\n",
@@ -1345,18 +1338,16 @@
 			/*
 			 * Convert token to a disk block number.
 			 */
-			i = bounds->upper;
-			if (geti(cleantoken, &value, &i))
+			if (geti64(cleantoken, &bn64, &bounds->upper))
 				break;
-			bn = value;
 			/*
 			 * Check to be sure it is within the
 			 * legal bounds.
 			 */
-			if ((bn < bounds->lower) || (bn > bounds->upper)) {
+			if ((bn64 < bounds->lower) || (bn64 > bounds->upper)) {
 				err_print(
-"`%ldb' is out of the range %llu to %llu\n",
-				    bn, bounds->lower, bounds->upper);
+"`%llub' is out of the range %llu to %llu\n",
+				    bn64, bounds->lower, bounds->upper);
 				break;
 			}
 
@@ -1364,19 +1355,19 @@
 			 * Verify the block lies on a cylinder
 			 * boundary
 			 */
-			if ((bn % spc()) != 0) {
+			if ((bn64 % spc()) != 0) {
 				err_print(
-"partition size must be a multiple of %d blocks to lie on a cylinder \
-boundary\n",
+				    "partition size must be a multiple of %u "
+				    "blocks to lie on a cylinder boundary\n",
 				    spc());
 				err_print(
-"%ld blocks is approximately %ld cylinders, %1.2f \
-megabytes or %1.2f gigabytes\n",
-				    bn, bn2c(bn), bn2mb(bn), bn2gb(bn));
+				    "%llu blocks is approximately %u cylinders,"
+				    " %1.2f megabytes or %1.2f gigabytes\n",
+				    bn64, bn2c(bn64), bn2mb(bn64), bn2gb(bn64));
 				break;
 			}
 
-			return (bn);
+			return (bn64);
 
 		case 'e':
 			/*
@@ -1396,7 +1387,7 @@
 			 */
 			if (cylno < part_deflt->start_cyl) {
 				err_print(
-"End cylinder must fall on or after start cylinder %d\n",
+"End cylinder must fall on or after start cylinder %u\n",
 				    part_deflt->start_cyl);
 				break;
 			}
@@ -1467,14 +1458,14 @@
 			/*
 			 * Convert to blocks
 			 */
-			bn = mb2bn(nmegs);
+			bn64 = mb2bn(nmegs);
 
 			/*
 			 * Round value up to nearest cylinder
 			 */
 			i = spc();
-			bn = ((bn + (i-1)) / i) * i;
-			return (bn);
+			bn64 = ((bn64 + (i-1)) / i) * i;
+			return (bn64);
 
 		case 'g':
 			/*
@@ -1498,14 +1489,14 @@
 			/*
 			 * Convert to blocks
 			 */
-			bn = gb2bn(ngigs);
+			bn64 = gb2bn(ngigs);
 
 			/*
 			 * Round value up to nearest cylinder
 			 */
 			i = spc();
-			bn = ((bn + (i-1)) / i) * i;
-			return (bn);
+			bn64 = ((bn64 + (i-1)) / i) * i;
+			return (bn64);
 
 		default:
 			err_print(
@@ -2106,7 +2097,7 @@
 
 	fmt_print("    %4d. %s ", num, disk->disk_name);
 	if ((type != NULL) && (disk->label_type == L_TYPE_SOLARIS)) {
-		fmt_print("<%s cyl %d alt %d hd %d sec %d>",
+		fmt_print("<%s cyl %u alt %u hd %u sec %u>",
 			type->dtype_asciilabel, type->dtype_ncyl,
 			type->dtype_acyl, type->dtype_nhead,
 			type->dtype_nsect);
@@ -2145,7 +2136,7 @@
 	fmt_print("\n");
 	if (type != NULL) {
 		fmt_print(
-"           %s%d: <%s cyl %d alt %d hd %d sec %d>\n",
+"           %s%d: <%s cyl %u alt %u hd %u sec %u>\n",
 		    ctlr->ctlr_dname, disk->disk_dkinfo.dki_unit,
 		    type->dtype_asciilabel, type->dtype_ncyl,
 		    type->dtype_acyl, type->dtype_nhead,
@@ -2160,15 +2151,13 @@
 /*
  * This routine prints out a given disk block number in cylinder/head/sector
  * format.  It uses the printing routine passed in to do the actual output.
- * Downcasting bn is okay for L_TYPE_SOLARIS because the number of blocks
- * on a Solaris (VTOC) label will never exceed 4 bytes (daddr_t).
  */
 void
 pr_dblock(void (*func)(char *, ...), diskaddr_t bn)
 {
 	if (cur_label == L_TYPE_SOLARIS) {
-		(*func)("%d/%d/%d", bn2c((daddr_t)bn),
-		    bn2h((daddr_t)bn), bn2s((daddr_t)bn));
+		(*func)("%u/%u/%u", bn2c(bn),
+		    bn2h(bn), bn2s(bn));
 	} else {
 		(*func)("%llu", bn);
 	}
--- a/usr/src/cmd/format/io.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/io.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,15 +19,13 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_IO_H
 #define	_IO_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -55,8 +52,8 @@
  * Input structure for current partition information
  */
 typedef struct partition_defaults {
-	int start_cyl;
-	int deflt_size;
+	uint_t start_cyl;
+	uint_t deflt_size;
 } part_deflt_t;
 
 typedef struct efi_defaults {
--- a/usr/src/cmd/format/ix_altsctr.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/ix_altsctr.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  * copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
@@ -34,8 +33,6 @@
  * All rights reserved.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <ctype.h>
 #include <fcntl.h>
@@ -60,8 +57,6 @@
 #define	CMD_READ	0
 #define	CMD_WRITE	1
 
-extern  daddr_t	altsec_offset;		/* Alternate sector offset */
-
 struct	badsec_lst *badsl_chain = NULL;
 int	badsl_chain_cnt = 0;
 struct	badsec_lst *gbadsl_chain = NULL;
@@ -72,8 +67,8 @@
 						/*  alts tables	*/
 
 /* prototypes */
-int updatebadsec(struct  partition *, int);
-int read_altsctr(struct  partition *);
+int updatebadsec(struct  dkl_partition *, int);
+int read_altsctr(struct  dkl_partition *);
 static int chk_badsec();
 static int init_altsctr();
 static int get_altsctr();
@@ -84,14 +79,14 @@
 static int assign_altsctr();
 static void expand_map();
 static void compress_map();
-static int altsmap_getbit(daddr_t);
-static int altsmap_alloc(daddr_t, daddr_t, int, int);
+static int altsmap_getbit(blkaddr_t);
+static blkaddr_t altsmap_alloc(blkaddr_t, blkaddr_t, int, int);
 static void ent_sort(struct  alts_ent *, int);
 static void ent_compress(struct  alts_ent *, int);
 static int ent_merge(struct alts_ent *, struct alts_ent *, int,
 		struct alts_ent *, int);
 static int ent_bsearch(struct  alts_ent *, int, struct  alts_ent *);
-static int chk_bad_altsctr(daddr_t);
+static int chk_bad_altsctr(blkaddr_t);
 
 /*
  * updatebadsec () -- update bad sector/track mapping tables
@@ -99,7 +94,7 @@
 int
 updatebadsec(part, init_flag)
 int	init_flag;
-struct  partition *part;
+struct  dkl_partition *part;
 {
 	if (init_flag)
 		ap->ap_flag |= ALTS_ADDPART;
@@ -118,7 +113,7 @@
  */
 int
 read_altsctr(part)
-struct 	partition *part;
+struct 	dkl_partition *part;
 {
 	if (ap->ap_tblp == NULL) {
 /*	    allocate buffer for the alts partition table (sector size)	*/
@@ -180,9 +175,9 @@
 static int
 chk_badsec()
 {
-	daddr_t	badsec;
-	daddr_t	altsp_srtsec = ap->part.p_start;
-	daddr_t	altsp_endsec = ap->part.p_start + ap->part.p_size - 1;
+	blkaddr_t	badsec;
+	blkaddr_t	altsp_srtsec = ap->part.p_start;
+	blkaddr_t	altsp_endsec = ap->part.p_start + ap->part.p_size - 1;
 	int	cnt;
 	int	status;
 
@@ -213,10 +208,10 @@
 			return (55);
 		    }
 		    (ap->ap_memmapp)[badsec - altsp_srtsec] = ALTS_BAD;
-		    (ap->ap_gbadp)[cnt].bad_start = ALTS_ENT_EMPTY;
+		    (ap->ap_gbadp)[cnt].bad_start = (uint32_t)ALTS_ENT_EMPTY;
 		} else {
 		    status = chk_bad_altsctr(badsec);
-		    (ap->ap_gbadp)[cnt].bad_start = ALTS_ENT_EMPTY;
+		    (ap->ap_gbadp)[cnt].bad_start = (uint32_t)ALTS_ENT_EMPTY;
 		}
 	    } else {
 /*
@@ -229,7 +224,7 @@
  *		then ignore the bad sector
  */
 		if (status != -1) {
-		    (ap->ap_gbadp)[cnt].bad_start = ALTS_ENT_EMPTY;
+		    (ap->ap_gbadp)[cnt].bad_start = (uint32_t)ALTS_ENT_EMPTY;
 		}
 	    }
 	}
@@ -242,9 +237,9 @@
 static int
 init_altsctr()
 {
-	daddr_t	badsec;
-	daddr_t	altsp_srtsec = ap->part.p_start;
-	daddr_t	altsp_endsec = ap->part.p_start + ap->part.p_size - 1;
+	blkaddr_t	badsec;
+	blkaddr_t	altsp_srtsec = ap->part.p_start;
+	blkaddr_t	altsp_endsec = ap->part.p_start + ap->part.p_size - 1;
 	int	cnt;
 
 	ap->ap_entp = NULL;
@@ -268,7 +263,7 @@
 		    return (56);
 		}
 		(ap->ap_memmapp)[badsec - altsp_srtsec] = ALTS_BAD;
-		(ap->ap_gbadp)[cnt].bad_start = ALTS_ENT_EMPTY;
+		(ap->ap_gbadp)[cnt].bad_start = (uint32_t)ALTS_ENT_EMPTY;
 	    }
 	}
 
@@ -393,8 +388,8 @@
 {
 	int	cnt;
 	struct	badsec_lst *blc_p;
-	daddr_t	curbad;
-	long	maxsec = (long)cur_dtype->dtype_nhead *
+	blkaddr_t	curbad;
+	blkaddr_t	maxsec = cur_dtype->dtype_nhead *
 				cur_dtype->dtype_ncyl *
 				cur_dtype->dtype_nsect;
 	struct	alts_ent *growbadp;
@@ -417,7 +412,7 @@
 		blc_p; blc_p = blc_p->bl_nxt) {
 		for (i = 0; i < blc_p->bl_cnt; i++) {
 		    curbad = blc_p->bl_sec[i];
-		    if (curbad < (daddr_t)cur_dtype->dtype_nsect) {
+		    if (curbad < (blkaddr_t)cur_dtype->dtype_nsect) {
 			(void) fprintf(stderr,
 "Ignoring bad sector %ld which is in first track of the drive.\n", curbad);
 			continue;
@@ -466,7 +461,7 @@
  */
 static int
 gen_alts_ent() {
-	int	ent_used;
+	uint_t	ent_used;
 	struct	alts_ent *entp;
 
 	if (ap->ap_gbadcnt == 0)
@@ -498,8 +493,8 @@
 
 /*	allocate the alts_entry on disk skipping possible bad sectors	*/
 	ap->ap_tblp->alts_ent_base =
-		altsmap_alloc(ap->ap_tblp->alts_map_base + ap->ap_map_sectot,
-			ap->part.p_size,
+		altsmap_alloc((blkaddr_t)ap->ap_tblp->alts_map_base +
+			ap->ap_map_sectot, (blkaddr_t)ap->part.p_size,
 			ap->ap_ent_secsiz / NBPSCTR, ALTS_MAP_UP);
 	if (ap->ap_tblp->alts_ent_base == NULL) {
 	    perror("Unable to allocate alternate entry table on disk: ");
@@ -518,13 +513,13 @@
 static int
 assign_altsctr()
 {
-	int	i;
-	int	j;
-	daddr_t	alts_ind;
-	int	cluster;
+	uint_t	i;
+	uint_t	j;
+	blkaddr_t	alts_ind;
+	uint_t	cluster;
 
 	for (i = 0; i < ap->ap_tblp->alts_ent_used; i++) {
-	    if ((ap->ap_entp)[i].bad_start == ALTS_ENT_EMPTY)
+	    if ((ap->ap_entp)[i].bad_start == (uint32_t)ALTS_ENT_EMPTY)
 		continue;
 	    if ((ap->ap_entp)[i].good_start != 0)
 		continue;
@@ -596,10 +591,10 @@
  */
 static int
 altsmap_getbit(badsec)
-daddr_t	badsec;
+blkaddr_t	badsec;
 {
-	int	slot = badsec / 8;
-	int	field = badsec % 8;
+	uint_t	slot = badsec / 8;
+	uint_t	field = badsec % 8;
 	uchar_t	mask;
 
 	mask = ALTS_BAD<<7;
@@ -613,16 +608,16 @@
 /*
  *	allocate a range of sectors from the alternate partition
  */
-static int
+static blkaddr_t
 altsmap_alloc(srt_ind, end_ind, cnt, dir)
-daddr_t	srt_ind;
-daddr_t	end_ind;
+blkaddr_t	srt_ind;
+blkaddr_t	end_ind;
 int	cnt;
 int	dir;
 {
-	int	i;
-	int	total;
-	int	first_ind;
+	blkaddr_t	i;
+	blkaddr_t	total;
+	blkaddr_t	first_ind;
 
 	for (i = srt_ind, first_ind = srt_ind, total = 0;
 	    i != end_ind; i += dir) {
@@ -688,15 +683,15 @@
 int	i;
 
 	for (i = 0; i < cnt; i++) {
-	    if (buf[i].bad_start == ALTS_ENT_EMPTY)
+	    if (buf[i].bad_start == (uint32_t)ALTS_ENT_EMPTY)
 		continue;
 	    for (keyp = i, movp = i+1; movp < cnt; movp++) {
-		if (buf[movp].bad_start == ALTS_ENT_EMPTY)
+		if (buf[movp].bad_start == (uint32_t)ALTS_ENT_EMPTY)
 			continue;
 		if (buf[keyp].bad_end+1 != buf[movp].bad_start)
 		    break;
 		buf[keyp].bad_end++;
-		buf[movp].bad_start = ALTS_ENT_EMPTY;
+		buf[movp].bad_start = (uint32_t)ALTS_ENT_EMPTY;
 	    }
 	    if (movp == cnt) break;
 	}
@@ -719,11 +714,11 @@
 	int	j1, j2;
 
 	for (i = 0, j1 = 0, j2 = 0; j1 < lcnt1 && j2 < lcnt2; ) {
-	    if (list1[j1].bad_start == ALTS_ENT_EMPTY) {
+	    if (list1[j1].bad_start == (uint32_t)ALTS_ENT_EMPTY) {
 		j1++;
 		continue;
 	    }
-	    if (list2[j2].bad_start == ALTS_ENT_EMPTY) {
+	    if (list2[j2].bad_start == (uint32_t)ALTS_ENT_EMPTY) {
 		j2++;
 		continue;
 	    }
@@ -733,12 +728,12 @@
 		buf[i++] = list2[j2++];
 	}
 	for (; j1 < lcnt1; j1++) {
-	    if (list1[j1].bad_start == ALTS_ENT_EMPTY)
+	    if (list1[j1].bad_start == (uint32_t)ALTS_ENT_EMPTY)
 		continue;
 	    buf[i++] = list1[j1];
 	}
 	for (; j2 < lcnt2; j2++) {
-	    if (list2[j2].bad_start == ALTS_ENT_EMPTY)
+	    if (list2[j2].bad_start == (uint32_t)ALTS_ENT_EMPTY)
 		continue;
 	    buf[i++] = list2[j2];
 	}
@@ -791,10 +786,10 @@
  */
 static int
 chk_bad_altsctr(badsec)
-daddr_t	badsec;
+blkaddr_t	badsec;
 {
 	int	i;
-	daddr_t	numsec;
+	blkaddr_t	numsec;
 	int	cnt = ap->ap_tblp->alts_ent_used;
 /*
  *	daddr_t intv[3];
--- a/usr/src/cmd/format/label.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/label.c	Thu Sep 11 18:00:50 2008 -0700
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains the code relating to label manipulation.
  */
@@ -60,10 +58,10 @@
  * Prototypes for ANSI C compilers
  */
 static int	do_geometry_sanity_check(void);
-static int	vtoc_to_label(struct dk_label *label, struct vtoc *vtoc,
+static int	vtoc_to_label(struct dk_label *label, struct extvtoc *vtoc,
 		struct dk_geom *geom, struct dk_cinfo *cinfo);
-extern int	read_vtoc(int, struct vtoc *);
-extern int	write_vtoc(int, struct vtoc *);
+extern int	read_extvtoc(int, struct extvtoc *);
+extern int	write_extvtoc(int, struct extvtoc *);
 static int	vtoc64_to_label(struct efi_info *, struct dk_gpt *);
 
 #else	/* __STDC__ */
@@ -73,12 +71,16 @@
  */
 static int	do_geometry_sanity_check();
 static int	vtoc_to_label();
-extern int	read_vtoc();
-extern int	write_vtoc();
+extern int	read_extvtoc();
+extern int	write_extvtoc();
 static int	vtoc64_to_label();
 
 #endif	/* __STDC__ */
 
+#ifdef	DEBUG
+static void dump_label(struct dk_label *label);
+#endif
+
 /*
  * This routine checks the given label to see if it is valid.
  */
@@ -212,7 +214,7 @@
 
 /*
  * create a clear EFI partition table when format is used
- * to convert a SMI label to an EFI lable
+ * to convert an SMI label to an EFI label
  */
 int
 SMI_vtoc_to_EFI(int fd, struct dk_gpt **new_vtoc)
@@ -269,7 +271,7 @@
 	int	error = 0, head, sec;
 	struct dk_label label;
 	struct dk_label new_label;
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	struct dk_geom	geom;
 	struct dk_gpt	*vtoc64;
 	int		nbackups;
@@ -420,7 +422,7 @@
 	 * always use an ioctl to read the vtoc from the
 	 * driver, so it can do as it likes.
 	 */
-	if (write_vtoc(cur_file, &vtoc) != 0) {
+	if (write_extvtoc(cur_file, &vtoc) != 0) {
 		err_print("Warning: error writing VTOC.\n");
 		error = -1;
 	}
@@ -470,17 +472,17 @@
 
 /*
  * Read the label from the disk.
- * Do this via the read_vtoc() library routine, then convert it to a label.
+ * Do this via the read_extvtoc() library routine, then convert it to a label.
  * We also need a DKIOCGGEOM ioctl to get the disk's geometry.
  */
 int
 read_label(int fd, struct dk_label *label)
 {
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	struct dk_geom	geom;
 	struct dk_cinfo	dkinfo;
 
-	if (read_vtoc(fd, &vtoc) < 0		||
+	if (read_extvtoc(fd, &vtoc) < 0		||
 	    ioctl(fd, DKIOCGGEOM, &geom) == -1	||
 	    ioctl(fd, DKIOCINFO, &dkinfo) == -1) {
 		return (-1);
@@ -667,8 +669,8 @@
  * Convert vtoc/geom to label.
  */
 static int
-vtoc_to_label(struct dk_label *label, struct vtoc *vtoc, struct dk_geom *geom,
-    struct dk_cinfo *cinfo)
+vtoc_to_label(struct dk_label *label, struct extvtoc *vtoc,
+    struct dk_geom *geom, struct dk_cinfo *cinfo)
 {
 #if defined(_SUNOS_VTOC_8)
 	struct dk_map32		*lmap;
@@ -678,8 +680,8 @@
 #error No VTOC format defined.
 #endif			/* defined(_SUNOS_VTOC_8) */
 
-	struct partition	*vpart;
-	long			nblks;
+	struct extpartition	*vpart;
+	ulong_t			nblks;
 	int			i;
 
 	(void) memset((char *)label, 0, sizeof (struct dk_label));
@@ -740,13 +742,15 @@
 	for (i = 0; i < V_NUMPAR; i++) {
 		label->dkl_vtoc.v_part[i].p_tag = vtoc->v_part[i].p_tag;
 		label->dkl_vtoc.v_part[i].p_flag = vtoc->v_part[i].p_flag;
+		label->dkl_vtoc.v_timestamp[i] = vtoc->timestamp[i];
 	}
-	(void) memcpy((char *)label->dkl_vtoc.v_bootinfo,
-	    (char *)vtoc->v_bootinfo, sizeof (vtoc->v_bootinfo));
-	(void) memcpy((char *)label->dkl_vtoc.v_reserved,
-	    (char *)vtoc->v_reserved, sizeof (vtoc->v_reserved));
-	(void) memcpy((char *)label->dkl_vtoc.v_timestamp,
-	    (char *)vtoc->timestamp, sizeof (vtoc->timestamp));
+
+	for (i = 0; i < 10; i++)
+		label->dkl_vtoc.v_reserved[i] = vtoc->v_reserved[i];
+
+	label->dkl_vtoc.v_bootinfo[0] = vtoc->v_bootinfo[0];
+	label->dkl_vtoc.v_bootinfo[1] = vtoc->v_bootinfo[1];
+	label->dkl_vtoc.v_bootinfo[2] = vtoc->v_bootinfo[2];
 
 	(void) memcpy(label->dkl_asciilabel, vtoc->v_asciilabel,
 	    LEN_DKL_ASCII);
@@ -772,7 +776,7 @@
 
 	vpart = vtoc->v_part;
 
-	nblks = (int)label->dkl_nsect * (int)label->dkl_nhead;
+	nblks = label->dkl_nsect * label->dkl_nhead;
 
 	for (i = 0; i < NDKMAP; i++, lmap++, vpart++) {
 		if (cinfo->dki_ctype != DKC_VBD) {
@@ -782,12 +786,12 @@
 			}
 		}
 #if defined(_SUNOS_VTOC_8)
-		lmap->dkl_cylno = vpart->p_start / nblks;
-		lmap->dkl_nblk = vpart->p_size;
+		lmap->dkl_cylno = (blkaddr32_t)(vpart->p_start / nblks);
+		lmap->dkl_nblk = (blkaddr32_t)vpart->p_size;
 
 #elif defined(_SUNOS_VTOC_16)
-		lmap->p_start = vpart->p_start;
-		lmap->p_size = vpart->p_size;
+		lmap->p_start = (blkaddr32_t)vpart->p_start;
+		lmap->p_size = (blkaddr32_t)vpart->p_size;
 #else
 #error No VTOC format defined.
 #endif			/* defined(_SUNOS_VTOC_8) */
@@ -798,6 +802,10 @@
 	 */
 	(void) checksum(label, CK_MAKESUM);
 
+#ifdef DEBUG
+	if (option_msg && diag_msg)
+		dump_label(label);
+#endif
 	return (0);
 }
 
@@ -807,12 +815,12 @@
  * Extract a vtoc structure out of a valid label
  */
 int
-label_to_vtoc(struct vtoc *vtoc, struct dk_label *label)
+label_to_vtoc(struct extvtoc *vtoc, struct dk_label *label)
 {
 #if defined(_SUNOS_VTOC_8)
 	struct dk_map2		*lpart;
 	struct dk_map32		*lmap;
-	long			nblks;
+	ulong_t			nblks;
 
 #elif defined(_SUNOS_VTOC_16)
 	struct dkl_partition	*lpart;
@@ -820,10 +828,10 @@
 #error No VTOC format defined.
 #endif				/* defined(_SUNOS_VTOC_8) */
 
-	struct partition	*vpart;
+	struct extpartition	*vpart;
 	int			i;
 
-	(void) memset((char *)vtoc, 0, sizeof (struct vtoc));
+	(void) memset((char *)vtoc, 0, sizeof (struct extvtoc));
 
 	switch (label->dkl_vtoc.v_version) {
 	case 0:
@@ -846,21 +854,20 @@
 			vpart->p_flag = lpart->p_flag;
 
 #if defined(_SUNOS_VTOC_16)
-			vpart->p_start = lpart->p_start;
-			vpart->p_size = lpart->p_size;
+			vpart->p_start = (diskaddr_t)lpart->p_start;
+			vpart->p_size = (diskaddr_t)lpart->p_size;
 #endif	/* defined(_SUNOS_VTOC_16) */
+			vtoc->timestamp[i] = label->dkl_vtoc.v_timestamp[i];
 		}
 		(void) memcpy(vtoc->v_volume, label->dkl_vtoc.v_volume,
 		    LEN_DKL_VVOL);
-		(void) memcpy((char *)vtoc->v_bootinfo,
-		    (char *)label->dkl_vtoc.v_bootinfo,
-		    sizeof (vtoc->v_bootinfo));
-		(void) memcpy((char *)vtoc->v_reserved,
-		    (char *)label->dkl_vtoc.v_reserved,
-		    sizeof (vtoc->v_reserved));
-		(void) memcpy((char *)vtoc->timestamp,
-		    (char *)label->dkl_vtoc.v_timestamp,
-		    sizeof (vtoc->timestamp));
+
+		for (i = 0; i < 10; i++)
+			vtoc->v_reserved[i] = label->dkl_vtoc.v_reserved[i];
+
+		vtoc->v_bootinfo[0] = label->dkl_vtoc.v_bootinfo[0];
+		vtoc->v_bootinfo[1] = label->dkl_vtoc.v_bootinfo[1];
+		vtoc->v_bootinfo[2] = label->dkl_vtoc.v_bootinfo[2];
 		break;
 
 	default:
@@ -890,8 +897,8 @@
 	vpart = vtoc->v_part;
 	nblks = label->dkl_nsect * label->dkl_nhead;
 	for (i = 0; i < V_NUMPAR; i++, vpart++, lmap++) {
-		vpart->p_start = lmap->dkl_cylno * nblks;
-		vpart->p_size = lmap->dkl_nblk;
+		vpart->p_start = (diskaddr_t)(lmap->dkl_cylno * nblks);
+		vpart->p_size = (diskaddr_t)lmap->dkl_nblk;
 	}
 #endif			/* defined(_SUNOS_VTOC_8) */
 
@@ -900,18 +907,17 @@
 
 /*
  * Input: File descriptor
- * Output: 1 if disk is >1TB OR has an EFI label, 0 otherwise.
+ * Output: 1 if disk has an EFI label, 0 otherwise.
  */
 
 int
 is_efi_type(int fd)
 {
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 
-	if (ioctl(fd, DKIOCGVTOC, &vtoc) == -1) {
-		if (errno == ENOTSUP) {
-			return (1);
-		}
+	if (read_extvtoc(fd, &vtoc) == VT_ENOTSUP) {
+		/* assume the disk has EFI label */
+		return (1);
 	}
 	return (0);
 }
@@ -1005,8 +1011,8 @@
 	}
 }
 
-#ifdef	FOR_DEBUGGING_ONLY
-int
+#ifdef	DEBUG
+static void
 dump_label(label)
 	struct dk_label	*label;
 {
@@ -1064,7 +1070,7 @@
 			label->dkl_map[i].dkl_nblk);
 
 #elif defined(_SUNOS_VTOC_16)
-		fmt_print("%c:        start=%d, blocks=%d", i+'a',
+		fmt_print("%c:        start=%u, blocks=%u", i+'a',
 		    label->dkl_vtoc.v_part[i].p_start,
 		    label->dkl_vtoc.v_part[i].p_size);
 #else
@@ -1107,4 +1113,4 @@
 
 	fmt_print("\n\n");
 }
-#endif	/* FOR_DEBUGGING_ONLY */
+#endif	/* DEBUG */
--- a/usr/src/cmd/format/label.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/label.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,15 +19,13 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_LABEL_H
 #define	_LABEL_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -43,7 +40,7 @@
 int	read_label(int fd, struct dk_label *label);
 int	read_efi_label(int fd, struct efi_info *label);
 int	get_disk_info(int fd, struct efi_info *label);
-int	label_to_vtoc(struct vtoc *vtoc, struct dk_label *label);
+int	label_to_vtoc(struct extvtoc *vtoc, struct dk_label *label);
 int	SMI_vtoc_to_EFI(int fd, struct dk_gpt **new_vtoc);
 void	err_check(struct dk_gpt *vtoc);
 extern int	is_efi_type(int fd);
--- a/usr/src/cmd/format/main.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/main.c	Thu Sep 11 18:00:50 2008 -0700
@@ -23,7 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
 /*
  * This file contains the main entry point of the program and other
  * routines relating to the general flow.
@@ -542,7 +541,7 @@
 	 * Check to see if there are any mounted file systems on the
 	 * disk.  If there are, print a warning.
 	 */
-	if ((found_mount = checkmount((daddr_t)-1, (daddr_t)-1)) != 0)
+	if ((found_mount = checkmount((diskaddr_t)-1, (diskaddr_t)-1)) != 0)
 		err_print("Warning: Current Disk has mounted partitions.\n");
 
 	/*
--- a/usr/src/cmd/format/menu_analyze.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/menu_analyze.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 1991-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions implementing the analyze menu commands.
  */
@@ -193,7 +190,7 @@
 		for (j = 0; j < 6; j++)
 			if (i + j < scan_size * SECSIZE / sizeof (int))
 				fmt_print("0x%08x  ",
-				*((int *)((int *)cur_buf + i + j)));
+				    *((int *)((int *)cur_buf + i + j)));
 		fmt_print("\n");
 		lines++;
 
@@ -274,11 +271,11 @@
 		ioparam.io_bounds.lower = 0;
 		if ((cur_ctype->ctype_flags & CF_SCSI) &&
 		    (cur_disk->label_type == L_TYPE_SOLARIS)) {
-		    ioparam.io_bounds.upper = datasects() - 1;
+			ioparam.io_bounds.upper = datasects() - 1;
 		} else if (cur_disk->label_type == L_TYPE_SOLARIS) {
-		    ioparam.io_bounds.upper = physsects() - 1;
+			ioparam.io_bounds.upper = physsects() - 1;
 		} else if (cur_disk->label_type == L_TYPE_EFI) {
-		    ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba;
+			ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba;
 		}
 
 		scan_lower = (diskaddr_t)input(FIO_BN,
@@ -331,8 +328,8 @@
 	ioparam.io_bounds.upper = min(size, BUF_SECTS);
 	if (scan_size > ioparam.io_bounds.upper)
 		scan_size = ioparam.io_bounds.upper;
-	scan_size = input(FIO_BN, "Enter number of blocks per transfer", ':',
-	    &ioparam, &scan_size, DATA_INPUT);
+	scan_size = input(FIO_INT, "Enter number of blocks per transfer", ':',
+	    &ioparam, (int *)&scan_size, DATA_INPUT);
 	deflt = !scan_auto;
 	ioparam.io_charlist = confirm_list;
 	scan_auto = !input(FIO_MSTR, "Verify media after formatting", '?',
@@ -391,7 +388,7 @@
 	fmt_print(scan_random ? "yes\n" : "no\n");
 
 	fmt_print("        Number of blocks per transfer: %d (", scan_size);
-	pr_dblock(fmt_print, (daddr_t)scan_size);
+	pr_dblock(fmt_print, (diskaddr_t)scan_size);
 	fmt_print(")\n");
 
 	fmt_print("        Verify media after formatting? ");
@@ -436,9 +433,9 @@
 		if (scan_passes < NPPATTERNS) {
 			fmt_print("The purge command runs for a minimum of ");
 			fmt_print("%d passes plus a last pass if the\n",
-						NPPATTERNS);
+			    NPPATTERNS);
 			fmt_print("first %d passes were successful.\n",
-					NPPATTERNS);
+			    NPPATTERNS);
 		}
 		scan_passes = NPPATTERNS + 1;
 	}
--- a/usr/src/cmd/format/menu_command.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/menu_command.c	Thu Sep 11 18:00:50 2008 -0700
@@ -147,7 +147,7 @@
 		/*
 		 * Convert the token into an integer.
 		 */
-		if (geti(cleantoken, (int *)&index, (int *)NULL))
+		if (geti(cleantoken, &index, (int *)NULL))
 			return (0);
 
 		/*
@@ -400,7 +400,7 @@
 	 */
 	if (index == auto_conf_choice) {
 		float			scaled;
-		long			nblks;
+		diskaddr_t		nblks;
 		int			nparts;
 
 		/*
@@ -415,7 +415,7 @@
 		}
 		fmt_print("%s: configured with capacity of ",
 			cur_disk->disk_name);
-		nblks = tptr->dtype_ncyl * tptr->dtype_nhead *
+		nblks = (diskaddr_t)tptr->dtype_ncyl * tptr->dtype_nhead *
 			tptr->dtype_nsect;
 		scaled = bn2mb(nblks);
 		if (scaled > 1024.0) {
@@ -593,7 +593,7 @@
 	 * running from a file.
 	 */
 	if ((tptr != oldtype) &&
-			checkmount((daddr_t)-1, (daddr_t)-1)) {
+			checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
 		err_print(
 		"Cannot set disk type while it has mounted partitions.\n\n");
 		return (-1);
@@ -602,7 +602,7 @@
 	 * check for partitions being used for swapping in format zone
 	 */
 	if ((tptr != oldtype) &&
-			checkswap((daddr_t)-1, (daddr_t)-1)) {
+			checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
 		err_print("Cannot set disk type while its partition are \
 currently being used for swapping.\n");
 		return (-1);
@@ -770,7 +770,8 @@
 	time_t			clock;
 	int			format_time, format_tracks, format_cyls;
 	int			format_interval;
-	int			deflt, status;
+	diskaddr_t		deflt;
+	int			status;
 	u_ioparam_t		ioparam;
 
 	/*
@@ -827,12 +828,12 @@
 		deflt = ioparam.io_bounds.lower;
 		start = input(FIO_BN,
 			"Enter starting block number", ':',
-			&ioparam, &deflt, DATA_INPUT);
+			&ioparam, (int *)&deflt, DATA_INPUT);
 		ioparam.io_bounds.lower = start;
 		deflt = ioparam.io_bounds.upper;
 		end = input(FIO_BN,
 			"Enter ending block number", ':',
-			&ioparam, &deflt, DATA_INPUT);
+			&ioparam, (int *)&deflt, DATA_INPUT);
 	}
 	/*
 	 * Some disks can format tracks.  Make sure the whole track is
@@ -1277,7 +1278,7 @@
 c_show()
 {
 	u_ioparam_t	ioparam;
-	daddr_t		bn;
+	diskaddr_t	bn;
 
 	/*
 	 * There must be a current disk type, so we will know the geometry.
@@ -1295,12 +1296,12 @@
 	} else {
 	    ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba;
 	}
-	bn = (daddr_t)input(FIO_BN, "Enter a disk block", ':',
+	bn = input(FIO_BN, "Enter a disk block", ':',
 	    &ioparam, (int *)NULL, DATA_INPUT);
 	/*
 	 * Echo it back.
 	 */
-	fmt_print("Disk block = %ld = 0x%lx = (", bn, bn);
+	fmt_print("Disk block = %lld = 0x%llx = (", bn, bn);
 	pr_dblock(fmt_print, bn);
 	fmt_print(")\n\n");
 	return (0);
@@ -1342,7 +1343,7 @@
 	 * only if the partitions would change for the mounted partitions.
 	 *
 	 */
-	if (checkmount((daddr_t)-1, (daddr_t)-1)) {
+	if (checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
 		/* Bleagh, too descriptive */
 		if (check_label_with_mount()) {
 			err_print("Cannot label disk while it has "
@@ -1356,7 +1357,7 @@
 	 * on the current disk.  If so, refuse to label the disk, but
 	 * only if the partitions would change for the mounted partitions.
 	 */
-	if (checkswap((daddr_t)-1, (daddr_t)-1)) {
+	if (checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
 		if (check_label_with_swap()) {
 			err_print("Cannot label disk while its "
 			    "partitions are currently being used for "
@@ -1402,19 +1403,13 @@
 #endif
 	    int 		choice;
 	    u_ioparam_t		ioparam;
-	    struct vtoc		vtoc;
+	    struct extvtoc	vtoc;
 	    struct dk_label	label;
 	    struct dk_gpt	*vtoc64;
 	    struct efi_info	efinfo;
 	    struct disk_type	*dptr;
 
-		/* If capacity > 1TB then offer no choice */
-	    if (cur_label == L_TYPE_EFI) {
-		if (cur_dtype->capacity > INFINITY) {
-		    goto expert_end;
-		}
-	    }
-		/* Ask user what label to use */
+	    /* Ask user what label to use */
 	    fmt_print("[0] SMI Label\n");
 	    fmt_print("[1] EFI Label\n");
 	    ioparam.io_bounds.lower = 0;
@@ -1437,29 +1432,34 @@
 		 * EFI label to SMI label
 		 */
 		if (cur_dtype->capacity > INFINITY) {
-		    fmt_print("SMI Label not supported on this disk\n");
-		    return (-1);
+		    fmt_print("Warning: SMI labels only support up to 2 TB.\n");
 		}
 
-
-		fmt_print("Warning: This disk has an EFI label. Changing to "
-		    "SMI label will erase all\ncurrent partitions.\n");
-
-		if (check("Continue"))
+		if (cur_disk->fdisk_part.systid == EFI_PMBR) {
+		    fmt_print("Warning: This disk has an EFI label. Changing to"
+		    " SMI label will erase all\ncurrent partitions.\n");
+		    if (check("Continue"))
 			return (-1);
-
-		(void) memset((char *)&label, 0, sizeof (struct dk_label));
-
-		if ((cur_disk->fdisk_part.systid == EFI_PMBR) ||
-		    (((cur_disk->fdisk_part.systid == SUNIXOS) ||
-		    (cur_disk->fdisk_part.systid == SUNIXOS2)) &&
-		    (cur_disk->fdisk_part.numsect == 0))) {
-			fmt_print("You must use fdisk to delete the current "
+#if defined(_FIRMWARE_NEEDS_FDISK)
+		    fmt_print("You must use fdisk to delete the current "
 			    "EFI partition and create a new\n"
 			    "Solaris partition before you can convert the "
 			    "label.\n");
+		    return (-1);
+#endif
+		}
+
+#if defined(_FIRMWARE_NEEDS_FDISK)
+		if (!(((cur_disk->fdisk_part.systid != SUNIXOS) ||
+		    (cur_disk->fdisk_part.systid != SUNIXOS2)) &&
+		    (cur_disk->fdisk_part.numsect > 0))) {
+			fmt_print("You must use fdisk to create a Solaris "
+			    "partition before you can convert the label.\n");
 			return (-1);
 		}
+#endif
+
+		(void) memset((char *)&label, 0, sizeof (struct dk_label));
 
 		(void) strcpy(x86_devname, cur_disk->disk_name);
 		if (cur_ctype->ctype_ctype == DKC_DIRECT)
@@ -1696,7 +1696,7 @@
 	struct	dk_label label;
 	struct	disk_type *dtype;
 	struct	partition_info *parts, *plist;
-	daddr_t	bn;
+	diskaddr_t	bn;
 	int	sec, head, i;
 
 	/*
@@ -1757,7 +1757,7 @@
 		/*
 		 * Attempt to read it.
 		 */
-		if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, (diskaddr_t)bn,
+		if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, bn,
 				1, (char *)&label, F_NORMAL, NULL)) {
 			continue;
 		}
@@ -1922,7 +1922,7 @@
 {
 	struct	dk_label p_label, b_label, *label;
 	struct	partition_info tmp_pinfo;
-	daddr_t	bn;
+	diskaddr_t	bn;
 	int	sec, head, i, status;
 	int	p_label_bad = 0;
 	int	b_label_bad = 0;
@@ -2008,7 +2008,7 @@
 		/*
 		 * Attempt to read it.
 		 */
-		if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, (diskaddr_t)bn,
+		if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, bn,
 				1, (char *)&b_label, F_NORMAL, NULL))
 			continue;
 		/*
@@ -2220,7 +2220,7 @@
 	 * only if the partitions would change for the mounted partitions.
 	 *
 	 */
-	if (checkmount((daddr_t)-1, (daddr_t)-1)) {
+	if (checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
 		/* Bleagh, too descriptive */
 		if (check_label_with_mount()) {
 			err_print(
@@ -2235,7 +2235,7 @@
 	 * only if the partitions would change for the swap partitions.
 	 *
 	 */
-	if (checkswap((daddr_t)-1, (daddr_t)-1)) {
+	if (checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
 		/* Bleagh, too descriptive */
 		if (check_label_with_swap()) {
 			err_print(
--- a/usr/src/cmd/format/menu_defect.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/menu_defect.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions to implement the defect menu commands.
  */
@@ -264,7 +261,8 @@
 int
 d_add()
 {
-	int			type, bn, deflt, index;
+	int			type, deflt, index;
+	diskaddr_t		bn;
 	u_ioparam_t		ioparam;
 	struct defect_entry	def;
 
--- a/usr/src/cmd/format/menu_fdisk.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/menu_fdisk.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions that implement the fdisk menu commands.
  */
@@ -335,15 +333,6 @@
 	}
 
 	/*
-	 * If disk is larger than 1TB then an EFI label is required
-	 * and there is no point in running fdisk
-	 */
-	if (cur_dtype->capacity > INFINITY) {
-		err_print("This disk must use an EFI label.\n");
-		return (-1);
-	}
-
-	/*
 	 * Before running the fdisk command, get file status of
 	 *	/dev/rdsk/cn[tn]dnp0 path to see if this disk
 	 *	supports fixed disk partition table.
@@ -494,7 +483,7 @@
 			}
 #endif /* DEBUG */
 
-			solaris_offset = lel(ip.relsect);
+			solaris_offset = (uint_t)lel(ip.relsect);
 			break;
 		}
 	}
@@ -515,13 +504,20 @@
 
 	/* if the disk partitioning has changed - get the VTOC */
 	if (status) {
-		status = ioctl(fd, DKIOCGVTOC, &cur_parts->vtoc);
+		struct extvtoc exvtoc;
+		struct vtoc vtoc;
+
+		status = ioctl(fd, DKIOCGEXTVTOC, &exvtoc);
 		if (status == -1) {
 			i = errno;
-			err_print("Bad ioctl DKIOCGVTOC.\n");
-			err_print("errno=%d %s\n", i, strerror(i));
-			err_print("Cannot read vtoc information.\n");
-			return (-1);
+			/* Try the old ioctl DKIOCGVTOC */
+			status = ioctl(fd, DKIOCGVTOC, &vtoc);
+			if (status == -1) {
+				err_print("Bad ioctl DKIOCGEXTVTOC.\n");
+				err_print("errno=%d %s\n", i, strerror(i));
+				err_print("Cannot read vtoc information.\n");
+				return (-1);
+			}
 		}
 
 		status = read_label(fd, &update_label);
@@ -530,6 +526,9 @@
 			return (-1);
 		}
 
+		/* copy vtoc information */
+		cur_parts->vtoc = update_label.dkl_vtoc;
+
 #if defined(_SUNOS_VTOC_16)
 		/*
 		 * this is to update the slice table on x86
--- a/usr/src/cmd/format/menu_partition.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/menu_partition.c	Thu Sep 11 18:00:50 2008 -0700
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions to implement the partition menu commands.
  */
@@ -201,9 +199,9 @@
 	struct partition_info	*pptr, *parts;
 	u_ioparam_t		ioparam;
 	int			i, index, deflt, *defltptr = NULL;
-	long			b_cylno;
+	blkaddr_t		b_cylno;
 #if defined(i386)
-	long			cyl_offset;
+	blkaddr_t		cyl_offset;
 #endif
 
 	parts = cur_dtype->dtype_plist;
@@ -291,13 +289,14 @@
 				pptr->pinfo_map[i].dkl_cylno);
 			return (0);
 		}
-		if (pptr->pinfo_map[i].dkl_nblk < 0 ||
+		if (pptr->pinfo_map[i].dkl_nblk == 0 ||
 			(int)pptr->pinfo_map[i].dkl_nblk > ((ncyl -
 				pptr->pinfo_map[i].dkl_cylno) * spc())) {
 			err_print(
-"partition %c: specified # of blocks, %d, is out of range\n",
-				(PARTITION_BASE+i),
-				pptr->pinfo_map[i].dkl_nblk);
+			    "partition %c: specified # of blocks, %u, "
+			    "is out of range\n",
+			    (PARTITION_BASE+i),
+			    pptr->pinfo_map[i].dkl_nblk);
 			return (0);
 		}
 	}
@@ -319,10 +318,10 @@
 #if defined(_SUNOS_VTOC_16)
 	for (i = 0; i < NDKMAP; i++)  {
 		cur_parts->vtoc.v_part[i].p_start =
-		    (daddr_t)(cur_parts->pinfo_map[i].dkl_cylno *
+		    (blkaddr_t)(cur_parts->pinfo_map[i].dkl_cylno *
 		    (nhead * nsect));
 		cur_parts->vtoc.v_part[i].p_size =
-		    (long)cur_parts->pinfo_map[i].dkl_nblk;
+		    (blkaddr_t)cur_parts->pinfo_map[i].dkl_nblk;
 	}
 #endif	/* defined(_SUNOS_VTOC_16) */
 
@@ -561,15 +560,15 @@
 print_partition(struct partition_info *pinfo, int partnum, int want_header)
 {
 	int		i;
-	uint_t		nblks;
+	blkaddr_t	nblks;
 	int		cyl1;
 	int		cyl2;
 	float		scaled;
 	int		maxcyl2;
 	int		ncyl2_digits;
 	char		*s;
-	daddr_t		maxnblks = 0;
-	size_t		len;
+	blkaddr_t	maxnblks = 0;
+	blkaddr_t	len;
 
 	/*
 	 * To align things nicely, we need to know the maximum
@@ -662,7 +661,7 @@
 	 */
 	len = strlen(" %") + ndigits(ndigits(maxnblks)) + strlen("d\n") + 1;
 	s = zalloc(len);
-	(void) snprintf(s, len, "%s%d%s", " %", ndigits(maxnblks), "u\n");
+	(void) snprintf(s, len, "%s%u%s", " %", ndigits(maxnblks), "u\n");
 	fmt_print(s, nblks);
 	(void) free(s);
 }
--- a/usr/src/cmd/format/menu_scsi.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/menu_scsi.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -21,12 +20,10 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions implementing the scsi menu commands.
  *
@@ -282,7 +279,7 @@
 				(void) do_mode_sense(pageno);
 			} else if (*p == 'b') {
 				if (parse_change_spec(s, p, pageno,
-						&change_item)) {
+				    &change_item)) {
 					(void) do_mode_select(&change_item);
 				}
 			}
@@ -293,9 +290,9 @@
 					goto error;
 				}
 				chg_item = (struct chg_list *)
-					zalloc(sizeof (struct chg_list));
+				    zalloc(sizeof (struct chg_list));
 				if (parse_change_spec(s, s, current_page,
-						chg_item)) {
+				    chg_item)) {
 					add_new_change_list_item(chg_item);
 				} else {
 					destroy_data((char *)chg_item);
@@ -552,7 +549,7 @@
 	/*
 	 * Are there mounted partitions?
 	 */
-	if (checkmount((daddr_t)-1, (daddr_t)-1)) {
+	if (checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
 		err_print("Cannot format disk with mounted partitions\n\n");
 		return (-1);
 	}
@@ -560,7 +557,7 @@
 	/*
 	 * Is any of the partitions being used for swapping.
 	 */
-	if (checkswap((daddr_t)-1, (daddr_t)-1)) {
+	if (checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
 		err_print("Cannot format disk while its partitions are \
 currently being used for swapping.\n\n");
 		return (-1);
@@ -582,7 +579,7 @@
 	deflt = 0;
 	ioparam.io_charlist = confirm_list;
 	grown_list = !input(FIO_MSTR, "Format with the Grown Defects list",
-		'?', &ioparam, &deflt, DATA_INPUT);
+	    '?', &ioparam, &deflt, DATA_INPUT);
 
 	/*
 	 * Construct the uscsi format ioctl.
@@ -766,7 +763,7 @@
 				break;
 			case CHG_MODE_CLR:
 				fmt_print("&= ~0x%x\n",
-					(~(cp->value)) & 0xff);
+				    (~(cp->value)) & 0xff);
 				break;
 			default:
 				impossible("do_display");
@@ -968,8 +965,7 @@
 	ucmd.uscsi_cdblen = CDB_GROUP0;
 	ucmd.uscsi_bufaddr = msbuf;
 	ucmd.uscsi_buflen = nbytes;
-	status = uscsi_cmd(cur_file, &ucmd,
-		(option_msg) ? F_NORMAL : F_SILENT);
+	status = uscsi_cmd(cur_file, &ucmd, (option_msg) ? F_NORMAL : F_SILENT);
 	if (status) {
 		if (!option_msg) {
 			err_print("\nMode sense page 0x3f failed\n");
@@ -984,7 +980,7 @@
 	 */
 	mh = (struct mode_header *)msbuf;
 	nbytes = mh->length - sizeof (struct mode_header) -
-			mh->bdesc_length + 1;
+	    mh->bdesc_length + 1;
 	p = msbuf + sizeof (struct mode_header) + mh->bdesc_length;
 
 	while (nbytes > 0) {
--- a/usr/src/cmd/format/misc.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/misc.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains miscellaneous routines.
  */
@@ -447,7 +444,7 @@
 	 */
 	if (ttystate.ttyflags == 0) {
 		if ((ttystate.ttyfile = open("/dev/tty",
-					O_RDWR | O_NDELAY)) < 0) {
+		    O_RDWR | O_NDELAY)) < 0) {
 			err_print("Unable to open /dev/tty.\n");
 			fullabort();
 		}
@@ -508,7 +505,7 @@
 	 */
 	if (ttystate.ttyflags == 0) {
 		if ((ttystate.ttyfile = open("/dev/tty",
-					O_RDWR | O_NDELAY)) < 0) {
+		    O_RDWR | O_NDELAY)) < 0) {
 			err_print("Unable to open /dev/tty.\n");
 			fullabort();
 		}
@@ -874,12 +871,12 @@
 }
 
 
-uint_t
+diskaddr_t
 mb2bn(float mb)
 {
-	uint_t	n;
+	diskaddr_t	n;
 
-	n = (uint_t)(mb * 1024.0 * (1024.0 / DEV_BSIZE));
+	n = (diskaddr_t)(mb * 1024.0 * (1024.0 / DEV_BSIZE));
 	return (n);
 }
 
@@ -902,12 +899,12 @@
 	return ((n/1024.0) * DEV_BSIZE);
 }
 
-uint_t
+diskaddr_t
 gb2bn(float gb)
 {
-	uint_t	n;
+	diskaddr_t	n;
 
-	n = (uint_t)(gb * 1024.0 * 1024.0 * (1024.0 / DEV_BSIZE));
+	n = (diskaddr_t)(gb * 1024.0 * 1024.0 * (1024.0 / DEV_BSIZE));
 	return (n);
 }
 
--- a/usr/src/cmd/format/misc.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/misc.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,15 +19,13 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_MISC_H
 #define	_MISC_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -169,10 +166,10 @@
 int	match_substr(char *s1, char *s2);
 void	dump(char *, caddr_t, int, int);
 float	bn2mb(uint64_t);
-uint_t	mb2bn(float);
+diskaddr_t	mb2bn(float);
 float	bn2gb(uint64_t);
 float	bn2tb(uint64_t);
-uint_t	gb2bn(float);
+diskaddr_t	gb2bn(float);
 int	get_tty_lines();
 
 
--- a/usr/src/cmd/format/modify_partition.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/modify_partition.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions to implement the partition menu commands.
  */
@@ -104,7 +102,7 @@
 	/*
 	 * If the disk has mounted partitions, cannot modify
 	 */
-	if (checkmount((daddr_t)-1, (daddr_t)-1)) {
+	if (checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
 		err_print(
 "Cannot modify disk partitions while it has mounted partitions.\n\n");
 		return (-1);
@@ -114,7 +112,7 @@
 	 * If the disk has partitions currently being used for
 	 * swapping, cannot modify
 	 */
-	if (checkswap((daddr_t)-1, (daddr_t)-1)) {
+	if (checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
 		err_print(
 "Cannot modify disk partitions while it is \
 currently being used for swapping.\n");
@@ -396,9 +394,9 @@
 check_map(map)
 	struct	dk_map32 *map;
 {
-	int	i;
-	int	cyloffset = 0;
-	int	tot_blks = 0;
+	int		i;
+	int		cyloffset = 0;
+	blkaddr32_t	tot_blks = 0;
 
 #ifdef i386
 	/*
@@ -413,17 +411,16 @@
 	 * not modify the table.
 	 */
 	for (i = 0; i < NDKMAP; i++) {
-		if (map[i].dkl_cylno < 0 ||
-				map[i].dkl_cylno > (daddr_t)ncyl-1) {
+		if (map[i].dkl_cylno > (blkaddr32_t)ncyl-1) {
 			err_print("\
 Warning: Partition %c starting cylinder %d is out of range.\n",
 				(PARTITION_BASE+i), map[i].dkl_cylno);
 			return (-1);
 		}
-		if (map[i].dkl_nblk < 0 || map[i].dkl_nblk > (daddr_t)(ncyl -
-			map[i].dkl_cylno) * spc()) {
+		if (map[i].dkl_nblk >
+			(blkaddr32_t)(ncyl - map[i].dkl_cylno) * spc()) {
 			err_print("\
-Warning: Partition %c, specified # of blocks, %d, is out of range.\n",
+Warning: Partition %c, specified # of blocks, %u, is out of range.\n",
 				(PARTITION_BASE+i), map[i].dkl_nblk);
 			return (-1);
 		}
@@ -464,8 +461,8 @@
 	int	float_part;
 {
 	int		i;
-	int		newsize;
-	int		deflt;
+	blkaddr32_t	newsize;
+	blkaddr32_t	deflt;
 	char		tmpstr[80];
 	u_ioparam_t	ioparam;
 
@@ -491,8 +488,8 @@
 			(void) snprintf(tmpstr, sizeof (tmpstr),
 				"Enter size of partition '%s' ",
 				partn_list[i]);
-			newsize = input(FIO_CYL, tmpstr, ':',
-				&ioparam, &deflt, DATA_INPUT);
+			newsize = (blkaddr32_t)input(FIO_CYL, tmpstr, ':',
+				&ioparam, (int *)&deflt, DATA_INPUT);
 			map[float_part].dkl_nblk -= (newsize - map[i].dkl_nblk);
 			map[i].dkl_nblk = newsize;
 		}
@@ -539,8 +536,8 @@
 	    part->pinfo_map[i] = label->dkl_map[i];
 #else
 	    part->pinfo_map[i].dkl_cylno =
-	    label->dkl_vtoc.v_part[i].p_start /
-			((int)(tptr->dtype_nhead * tptr->dtype_nsect - apc));
+		label->dkl_vtoc.v_part[i].p_start /
+		(blkaddr32_t)(tptr->dtype_nhead * tptr->dtype_nsect - apc);
 	    part->pinfo_map[i].dkl_nblk =
 		label->dkl_vtoc.v_part[i].p_size;
 #endif /* ifdefined(_SUNOS_VTOC_8) */
--- a/usr/src/cmd/format/param.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/param.h	Thu Sep 11 18:00:50 2008 -0700
@@ -27,8 +27,6 @@
 #ifndef	_PARAM_H
 #define	_PARAM_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -37,6 +35,14 @@
 #define	UINT16_MAX	0xffffU
 #endif
 
+#ifndef UINT32_MAX
+#define	UINT32_MAX	0xffffffffU
+#endif
+
+#ifndef INT32_MAX
+#define	INT32_MAX	0x7fffffff
+#endif
+
 /*
  * This file contains declarations of miscellaneous parameters.
  */
@@ -56,7 +62,7 @@
 #define	AVG_BPS		600			/* default bytes/sector */
 #define	MAX_BPS		1000			/* max legal bytes/sector */
 
-#define	INFINITY	0x7fffffff		/* a big number */
+#define	INFINITY	0xffffffffU		/* a big number */
 
 #define	MAXBLKS(heads, spt)	UINT16_MAX * heads * spt, heads, spt
 #ifdef	__cplusplus
--- a/usr/src/cmd/format/partition.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/partition.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains functions that operate on partition tables.
  */
@@ -117,16 +114,16 @@
 void
 change_partition(int num)
 {
-	int		i;
+	uint_t		i;
 	uint64_t	i64, j64;
-	int		j;
+	uint_t		j;
 	int		deflt;
 	part_deflt_t	p_deflt;
 	u_ioparam_t	ioparam;
 	int		tag;
 	int		flag;
 	char		msg[256];
-	long		cyl_offset = 0;
+	blkaddr32_t	cyl_offset = 0;
 	efi_deflt_t	efi_deflt;
 
 	/*
@@ -251,7 +248,7 @@
 	ioparam.io_bounds.upper = ncyl - 1;
 	deflt = max(cur_parts->pinfo_map[num].dkl_cylno,
 		cyl_offset);
-	i = input(FIO_INT, "Enter new starting cyl", ':', &ioparam,
+	i = (uint_t)input(FIO_INT, "Enter new starting cyl", ':', &ioparam,
 	    &deflt, DATA_INPUT);
 
 	ioparam.io_bounds.lower = 0;
@@ -264,7 +261,7 @@
 		    ioparam.io_bounds.upper);
 
 	/* call input, passing p_deflt's address, typecast to (int *) */
-	j = input(FIO_ECYL, "Enter partition size", ':', &ioparam,
+	j = (uint_t)input(FIO_ECYL, "Enter partition size", ':', &ioparam,
 	    (int *)&p_deflt, DATA_INPUT);
 
 	/*
@@ -310,7 +307,7 @@
 	 * return an Error.
 	 */
 	if (tag == V_BACKUP) {
-		int fullsz;
+		uint_t fullsz;
 
 		fullsz = ncyl * nhead * nsect;
 		if (fullsz != j) {
--- a/usr/src/cmd/format/startup.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/format/startup.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This file contains the code to perform program startup.  This
  * includes reading the data file and the search for disks.
@@ -80,7 +78,7 @@
 		struct disk_type *dp2);
 static void	check_pinfo_for_inconsistency(struct partition_info *pp1,
 		struct partition_info *pp2);
-static int	str2blks(char *str);
+static uint_t	str2blks(char *str);
 static int	str2cyls(char *str);
 static struct	chg_list *new_chg_list(struct disk_type *);
 static char	*get_physical_name(char *);
@@ -106,7 +104,7 @@
 static void	search_duplicate_pinfo();
 static void	check_dtypes_for_inconsistency();
 static void	check_pinfo_for_inconsistency();
-static int	str2blks();
+static uint_t	str2blks();
 static int	str2cyls();
 static struct	chg_list *new_chg_list();
 static char	*get_physical_name();
@@ -943,7 +941,8 @@
 	struct	ctlr_type *ctype = NULL;
 	struct	partition_info *pinfo, *parts;
 	char	*pinfo_name;
-	int	i, index, status, val1, val2, flags = 0;
+	int	i, index, status, flags = 0;
+	uint_t	val1, val2;
 	ushort_t	vtoc_tag;
 	ushort_t	vtoc_flag;
 	struct	mctlr_list	*mlp;
@@ -1207,7 +1206,7 @@
 		 * is the starting cylinder number of the partition.
 		 */
 		val1 = str2cyls(cleaned);
-		if (val1 == -1) {
+		if (val1 == (uint_t)(-1)) {
 			datafile_error("Expecting an integer, found '%s'",
 			    cleaned);
 			return;
@@ -1237,7 +1236,7 @@
 		 * they choose to be so specific.
 		 */
 		val2 = str2blks(cleaned);
-		if (val2 == -1) {
+		if (val2 == (uint_t)(-1)) {
 			datafile_error("Expecting an integer, found '%s'",
 			    cleaned);
 			return;
@@ -1454,7 +1453,7 @@
 	i = 0;
 	for (disk = disk_list; disk != NULL; disk = disk->disk_next) {
 		float			scaled;
-		long			nblks;
+		diskaddr_t		nblks;
 		struct disk_type	*type;
 		if (disk->disk_flags & DSK_AUTO_CONFIG) {
 			if (i++ == 0) {
@@ -1709,7 +1708,7 @@
 	 * generic check for reserved disks here, including intel disks.
 	 */
 	if (dkinfo.dki_ctype == DKC_SCSI_CCS) {
-		i = scsi_rdwr(DIR_READ, search_file, (daddr_t)0,
+		i = scsi_rdwr(DIR_READ, search_file, (diskaddr_t)0,
 		    1, (char *)&search_label, F_SILENT, NULL);
 		switch (i) {
 		case DSK_RESERVED:
@@ -1860,7 +1859,7 @@
 	/*
 	 * If reading the label failed, and this is a SCSI
 	 * disk, we can attempt to auto-sense the disk
-	 * configuration.
+	 * Configuration.
 	 */
 	ctlr = search_ctlr->ctlr_ctype;
 	if ((status == -1) && (ctlr->ctype_ctype == DKC_SCSI_CCS)) {
@@ -2087,7 +2086,7 @@
 #elif defined(_SUNOS_VTOC_16)
 			search_parts->pinfo_map[i].dkl_cylno =
 			    search_label.dkl_vtoc.v_part[i].p_start /
-			    ((int)(search_label.dkl_nhead *
+			    ((blkaddr32_t)(search_label.dkl_nhead *
 			    search_label.dkl_nsect));
 			search_parts->pinfo_map[i].dkl_nblk =
 			    search_label.dkl_vtoc.v_part[i].p_size;
@@ -2540,7 +2539,7 @@
  *
  * Returns -1 in the case of an error.
  */
-static int
+static uint_t
 str2blks(char *str)
 {
 	int	blks;
@@ -2591,7 +2590,7 @@
 	 */
 	if (*p != 0) {
 		/*
-		 * Units specifier of 'c': convert cylinders to blocks
+		 * Units specifier of 'c': accept it.
 		 */
 		if (*p == 'c') {
 			p++;
--- a/usr/src/cmd/fs.d/pcfs/fsck/pcfs_common.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fs.d/pcfs/fsck/pcfs_common.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright (c) 1999,2001 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * fsck_pcfs -- common.c
  *	All the routines in this file are being swiped directly from
@@ -377,7 +374,7 @@
 bad_arg(char *option)
 {
 	(void) fprintf(stderr,
-		gettext("Unrecognized option -o %s.\n"), option);
+	    gettext("Unrecognized option -o %s.\n"), option);
 	usage();
 	exit(2);
 }
@@ -386,7 +383,7 @@
 missing_arg(char *option)
 {
 	(void) fprintf(stderr,
-		gettext("Option %s requires a value.\n"), option);
+	    gettext("Option %s requires a value.\n"), option);
 	usage();
 	exit(3);
 }
@@ -474,7 +471,7 @@
 	struct ipart part[FD_NUMPART];
 	struct mboot extmboot;
 	struct mboot mb;
-	daddr_t xstartsect;
+	diskaddr_t xstartsect;
 	off64_t nextseek = 0;
 	off64_t lastseek = 0;
 	off64_t found = 0;
@@ -483,7 +480,7 @@
 	int extendedPart = -1;
 	int primaryPart = -1;
 	int bootPart = -1;
-	int xnumsect = -1;
+	uint32_t xnumsect = 0;
 	int drvnum;
 	int driveIndex;
 	int i;
@@ -606,9 +603,9 @@
 			 */
 			if (lseek64(fd, nextseek * BPSEC, SEEK_SET) < 0 ||
 			    read(fd, &extmboot, sizeof (extmboot)) !=
-				sizeof (extmboot)) {
+			    sizeof (extmboot)) {
 				perror(gettext("Unable to read extended "
-					"partition record"));
+				    "partition record"));
 				return (error);
 			}
 			(void) memcpy(part, extmboot.parts, sizeof (part));
--- a/usr/src/cmd/fs.d/pcfs/mkfs/mkfs.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fs.d/pcfs/mkfs/mkfs.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <ctype.h>
 #include <unistd.h>
@@ -643,14 +641,14 @@
 	struct ipart part[FD_NUMPART];
 	struct mboot extmboot;
 	struct mboot mb;
-	daddr_t xstartsect;
+	diskaddr_t xstartsect;
 	off64_t nextseek = 0;
 	off64_t lastseek = 0;
 	int logicalDriveCount = 0;
 	int extendedPart = -1;
 	int primaryPart = -1;
 	int bootPart = -1;
-	int xnumsect = -1;
+	uint32_t xnumsect = 0;
 	int drvnum;
 	int driveIndex;
 	int i;
--- a/usr/src/cmd/fs.d/ufs/fsck/utilities.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fs.d/ufs/fsck/utilities.c	Thu Sep 11 18:00:50 2008 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -25,8 +25,6 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -2422,11 +2420,11 @@
 static diskaddr_t
 get_device_size(int fd, caddr_t name)
 {
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 	struct dk_gpt *efi_vtoc;
 	diskaddr_t slicesize = 0;
 
-	int index = read_vtoc(fd, &vtoc);
+	int index = read_extvtoc(fd, &vtoc);
 
 	if (index >= 0) {
 		label_type = LABEL_TYPE_VTOC;
@@ -2474,16 +2472,7 @@
 		slicesize = efi_vtoc->efi_parts[index].p_size;
 		efi_free(efi_vtoc);
 	} else if (label_type == LABEL_TYPE_VTOC) {
-		/*
-		 * In the vtoc struct, p_size is a 32-bit signed quantity.
-		 * In the dk_gpt struct (efi's version of the vtoc), p_size
-		 * is an unsigned 64-bit quantity.  By casting the vtoc's
-		 * psize to an unsigned 32-bit quantity, it will be copied
-		 * to 'slicesize' (an unsigned 64-bit diskaddr_t) without
-		 * sign extension.
-		 */
-
-		slicesize = (uint32_t)vtoc.v_part[index].p_size;
+		slicesize = vtoc.v_part[index].p_size;
 	}
 
 	return (slicesize);
--- a/usr/src/cmd/fs.d/ufs/mkfs/mkfs.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fs.d/ufs/mkfs/mkfs.c	Thu Sep 11 18:00:50 2008 -0700
@@ -36,9 +36,6 @@
  * contributors.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
-
 /*
  * The maximum supported file system size (in sectors) is the
  * number of frags that can be represented in an int32_t field
@@ -1155,15 +1152,16 @@
 				    "system determined parameters.\n", fsys));
 				ishotpluggable = 0;
 			}
-			if (((dkg.dkg_ncyl * dkg.dkg_nhead * dkg.dkg_nsect)
-			    > CHSLIMIT) || isremovable || ishotpluggable) {
+			if ((((diskaddr_t)dkg.dkg_ncyl * dkg.dkg_nhead *
+			    dkg.dkg_nsect) > CHSLIMIT) || isremovable ||
+			    ishotpluggable) {
 				use_efi_dflts = 1;
 				retry = 1;
 			}
 		}
 	}
-	dprintf(("DeBuG CHSLIMIT = %d geom = %ld\n", CHSLIMIT,
-	    dkg.dkg_ncyl * dkg.dkg_nhead * dkg.dkg_nsect));
+	dprintf(("DeBuG CHSLIMIT = %d geom = %llu\n", CHSLIMIT,
+	    (diskaddr_t)dkg.dkg_ncyl * dkg.dkg_nhead * dkg.dkg_nsect));
 	dprintf(("DeBuG label_type = %d isremovable = %d ishotpluggable = %d "
 	    "use_efi_dflts = %d\n", label_type, isremovable, ishotpluggable,
 	    use_efi_dflts));
@@ -2393,11 +2391,11 @@
 static diskaddr_t
 get_max_size(int fd)
 {
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 	dk_gpt_t *efi_vtoc;
 	diskaddr_t	slicesize;
 
-	int index = read_vtoc(fd, &vtoc);
+	int index = read_extvtoc(fd, &vtoc);
 
 	if (index >= 0) {
 		label_type = LABEL_TYPE_VTOC;
--- a/usr/src/cmd/fs.d/ufs/newfs/newfs.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fs.d/ufs/newfs/newfs.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,9 +19,6 @@
  * CDDL HEADER END
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-	/* from UCB 5.2 9/11/85 */
-
 /*
  * newfs: friendly front end to mkfs
  *
@@ -758,14 +755,14 @@
 		if (ioctl(fd, DKIOCGGEOM, &g))
 			fatal(gettext(
 			    "%s: Unable to read Disk geometry"), disk);
-		if (((g.dkg_ncyl * g.dkg_nhead * g.dkg_nsect) > CHSLIMIT) &&
-		    !Tflag) {
+		if ((((diskaddr_t)g.dkg_ncyl * g.dkg_nhead *
+		    g.dkg_nsect) > CHSLIMIT) && !Tflag) {
 			use_efi_dflts = 1;
 		}
-		dprintf(("DeBuG newfs : geom=%ld, CHSLIMIT=%d "
+		dprintf(("DeBuG newfs : geom=%llu, CHSLIMIT=%d "
 		    "isremovable = %d ishotpluggable = %d use_efi_dflts = %d\n",
-		    g.dkg_ncyl * g.dkg_nhead * g.dkg_nsect, CHSLIMIT,
-		    isremovable, ishotpluggable, use_efi_dflts));
+		    (diskaddr_t)g.dkg_ncyl * g.dkg_nhead * g.dkg_nsect,
+		    CHSLIMIT, isremovable, ishotpluggable, use_efi_dflts));
 		/*
 		 * The ntracks that is passed to mkfs is decided here based
 		 * on 'use_efi_dflts' and whether ntracks was specified as a
@@ -819,11 +816,11 @@
 static diskaddr_t
 get_device_size(int fd, char *name)
 {
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 	dk_gpt_t *efi_vtoc;
 	diskaddr_t	slicesize;
 
-	int index = read_vtoc(fd, &vtoc);
+	int index = read_extvtoc(fd, &vtoc);
 
 	if (index >= 0) {
 		label_type = LABEL_TYPE_VTOC;
@@ -875,16 +872,7 @@
 		slicesize = efi_vtoc->efi_parts[index].p_size;
 		efi_free(efi_vtoc);
 	} else if (label_type == LABEL_TYPE_VTOC) {
-		/*
-		 * In the vtoc struct, p_size is a 32-bit signed quantity.
-		 * In the dk_gpt struct (efi's version of the vtoc), p_size
-		 * is an unsigned 64-bit quantity.  By casting the vtoc's
-		 * psize to an unsigned 32-bit quantity, it will be copied
-		 * to 'slicesize' (an unsigned 64-bit diskaddr_t) without
-		 * sign extension.
-		 */
-
-		slicesize = (uint32_t)vtoc.v_part[index].p_size;
+		slicesize = vtoc.v_part[index].p_size;
 	}
 
 	return (slicesize);
--- a/usr/src/cmd/fstyp/fstyp.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/fstyp/fstyp.c	Thu Sep 11 18:00:50 2008 -0700
@@ -440,8 +440,8 @@
 	int	count;
 	int	systid;
 	int	r_systid;
-	int	r_relsect;
-	int	r_numsect;
+	uint32_t	r_relsect;
+	uint32_t	r_numsect;
 };
 
 enum { WALK_CONTINUE, WALK_TERMINATE };
@@ -450,16 +450,16 @@
  * Walk partition tables and invoke a callback for each.
  */
 static void
-walk_partitions(int fd, int startsec, off_t secsz,
-    int (*f)(void *, int, int, int), void *arg)
+walk_partitions(int fd, uint32_t startsec, off_t secsz,
+    int (*f)(void *, int, uint32_t, uint32_t), void *arg)
 {
 	uint32_t buf[1024/4];
 	int bufsize = 1024;
 	struct mboot *mboot = (struct mboot *)&buf[0];
 	struct ipart ipart[FD_NUMPART];
-	int sec = startsec;
-	int lastsec = sec + 1;
-	int relsect;
+	uint32_t sec = startsec;
+	uint32_t lastsec = sec + 1;
+	uint32_t relsect;
 	int ext = 0;
 	int systid;
 	boolean_t valid;
@@ -499,7 +499,7 @@
 }
 
 static int
-find_dos_drive_cb(void *arg, int systid, int relsect, int numsect)
+find_dos_drive_cb(void *arg, int systid, uint32_t relsect, uint32_t numsect)
 {
 	struct part_find_s *p = arg;
 
--- a/usr/src/cmd/hal/probing/storage/probe-storage.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/hal/probing/storage/probe-storage.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,15 +2,13 @@
  *
  * probe-storage.c : Probe for storage devices
  *
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  * Licensed under the Academic Free License version 2.1
  *
  **************************************************************************/
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
@@ -349,7 +347,7 @@
 	dbus_bool_t vtoc_slices = FALSE;
 	int dos_cnt = 0;
 	const char *scheme = "";
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 	dk_gpt_t *gpt;
 	LibHalChangeSet *cs = NULL;
 
@@ -436,7 +434,7 @@
 	if (is_mbr) {
 		scheme = "mbr";
 	}
-	if (read_vtoc(rfd, &vtoc) >= 0) {
+	if (read_extvtoc(rfd, &vtoc) >= 0) {
 		if (!vtoc_one_slice_entire_disk(&vtoc)) {
 			is_smi = TRUE;
 			if (!is_mbr) {
--- a/usr/src/cmd/hal/probing/volume/probe-volume.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/hal/probing/volume/probe-volume.c	Thu Sep 11 18:00:50 2008 -0700
@@ -9,8 +9,6 @@
  *
  **************************************************************************/
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
@@ -436,7 +434,7 @@
 	char *partition_scheme = NULL;
 	dbus_uint64_t partition_start = 0;
 	int partition_number = 0;
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 	dk_gpt_t *gpt;
 	struct dk_minfo mi;
 	int i, dos_cnt;
@@ -557,7 +555,7 @@
 		partition_start = (dbus_uint64_t)probe_offset;
 		partition_number = dos_num;
 	} else {
-		if ((partition_number = read_vtoc(rfd, &vtoc)) >= 0) {
+		if ((partition_number = read_extvtoc(rfd, &vtoc)) >= 0) {
 			if (!vtoc_one_slice_entire_disk(&vtoc)) {
 				partition_scheme = "smi";
 				if (partition_number < vtoc.v_nparts) {
--- a/usr/src/cmd/hal/utils/fsutils.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/hal/utils/fsutils.c	Thu Sep 11 18:00:50 2008 -0700
@@ -1,4 +1,4 @@
-/***************************************************************************
+/*
  *
  * fsutils.c : filesystem utilities
  *
@@ -7,12 +7,10 @@
  *
  * Licensed under the Academic Free License version 2.1
  *
- **************************************************************************/
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+ */
 
 #ifdef HAVE_CONFIG_H
-#  include <config.h>
+#include <config.h>
 #endif
 
 #include <stdio.h>
@@ -54,7 +52,7 @@
 }
 
 char *
-get_slice_name (char *devlink)
+get_slice_name(char *devlink)
 {
 	char	*part, *slice, *disk;
 	char	*s = NULL;
@@ -102,8 +100,8 @@
 	int	count;
 	int	systid;
 	int	r_systid;
-	int	r_relsect;
-	int	r_numsect;
+	uint_t	r_relsect;
+	uint_t	r_numsect;
 };
 
 enum { WALK_CONTINUE, WALK_TERMINATE };
@@ -113,15 +111,15 @@
  */
 static void
 walk_partitions(int fd, int startsec, uint_t secsz,
-    int (*f)(void *, int, int, int), void *arg)
+    int (*f)(void *, int, uint_t, uint_t), void *arg)
 {
 	uint32_t buf[1024/4];
 	int bufsize = 1024;
 	struct mboot *mboot = (struct mboot *)&buf[0];
 	struct ipart ipart[FD_NUMPART];
-	int sec = startsec;
-	int lastsec = sec + 1;
-	int relsect;
+	uint_t sec = startsec;
+	uint_t lastsec = sec + 1;
+	uint_t relsect;
 	int ext = 0;
 	int systid;
 	boolean_t valid;
@@ -161,7 +159,7 @@
 }
 
 static int
-find_dos_drive_cb(void *arg, int systid, int relsect, int numsect)
+find_dos_drive_cb(void *arg, int systid, uint_t relsect, uint_t numsect)
 {
 	struct part_find_s *p = arg;
 
@@ -200,7 +198,7 @@
 }
 
 static int
-get_num_dos_drives_cb(void *arg, int systid, int relsect, int numsect)
+get_num_dos_drives_cb(void *arg, int systid, uint_t relsect, uint_t numsect)
 {
 	if (is_dos_drive(systid)) {
 		(*(int *)arg)++;
@@ -223,12 +221,12 @@
  * are tagged backup/entire disk.
  */
 boolean_t
-vtoc_one_slice_entire_disk(struct vtoc *vtoc)
+vtoc_one_slice_entire_disk(struct extvtoc *vtoc)
 {
 	int		i;
-	struct partition *p;
-	daddr_t		prev_start;
-	long		prev_size;
+	struct extpartition *p;
+	diskaddr_t	prev_start;
+	diskaddr_t	prev_size;
 
 	for (i = 0; i < vtoc->v_nparts; i++) {
 		p = &vtoc->v_part[i];
--- a/usr/src/cmd/hal/utils/fsutils.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/hal/utils/fsutils.h	Thu Sep 11 18:00:50 2008 -0700
@@ -1,4 +1,4 @@
-/***************************************************************************
+/*
  *
  * fsutils.h : definitions for filesystem utilities
  *
@@ -7,9 +7,7 @@
  *
  * Licensed under the Academic Free License version 2.1
  *
- **************************************************************************/
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+ */
 
 #ifndef FSUTILS_H
 #define	FSUTILS_H
@@ -23,6 +21,6 @@
 boolean_t is_dos_extended(uchar_t id);
 boolean_t find_dos_drive(int fd, int num, uint_t secsz, off_t *offset);
 int get_num_dos_drives(int fd, uint_t);
-boolean_t vtoc_one_slice_entire_disk(struct vtoc *vtoc);
+boolean_t vtoc_one_slice_entire_disk(struct extvtoc *vtoc);
 
 #endif /* FSUTILS_H */
--- a/usr/src/cmd/iscsi/iscsitgtd/mgmt_create.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/iscsi/iscsitgtd/mgmt_create.c	Thu Sep 11 18:00:50 2008 -0700
@@ -24,8 +24,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <ctype.h>
 #include <sys/types.h>
 #include <time.h>
@@ -1006,9 +1004,9 @@
 }
 
 static Boolean_t
-readvtoc(int fd, struct vtoc *v, int *slice)
+readvtoc(int fd, struct extvtoc *v, int *slice)
 {
-	if ((*slice = read_vtoc(fd, v)) >= 0)
+	if ((*slice = read_extvtoc(fd, v)) >= 0)
 		return (True);
 	else
 		return (False);
@@ -1040,7 +1038,7 @@
 {
 	struct stat	s;
 	char		*raw_name, buf[512];
-	struct vtoc	vtoc;
+	struct extvtoc	extvtoc;
 	struct dk_gpt	*efi;
 	int		slice, fd;
 	tgt_node_t	*pn;
@@ -1083,8 +1081,8 @@
 			(void) close(fd);
 			return (False);
 		}
-		if (readvtoc(fd, &vtoc, &slice) == True) {
-			*size = (long long)vtoc.v_part[slice].p_size * 512;
+		if (readvtoc(fd, &extvtoc, &slice) == True) {
+			*size = extvtoc.v_part[slice].p_size * 512;
 
 		} else if (readefi(fd, &efi, &slice) == True) {
 			*size = efi->efi_parts[slice].p_size * 512;
--- a/usr/src/cmd/lvm/rpc.metamhd/mhd_drive.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/lvm/rpc.metamhd/mhd_drive.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include "mhd_local.h"
 
 #include <ftw.h>
@@ -769,7 +766,7 @@
 	struct uscsi_cmd	ucmd;
 	union scsi_cdb		cdb;
 	struct scsi_inquiry	inq;
-	struct vtoc		vtoc_buf;
+	struct extvtoc		vtoc_buf;
 	char			path[MAXPATHLEN + 1];
 	int			len;
 	int			err;
@@ -841,15 +838,15 @@
 		if (! serial)
 			mhd_mx_unlock(&sp->sr_mx);
 		(void) memset(&vtoc_buf, 0, sizeof (vtoc_buf));
-		err = read_vtoc(dp->dr_fd, &vtoc_buf);
+		err = read_extvtoc(dp->dr_fd, &vtoc_buf);
 		if (! serial)
 			mhd_mx_lock(&sp->sr_mx);
 		if (err < 0) {
-			MHDPRINTF(("%s: read_vtoc: failed errno %d\n",
+			MHDPRINTF(("%s: read_extvtoc: failed errno %d\n",
 			    dp->dr_rname, errno));
 			dp->dr_drive_id.did_flags &= ~MHD_DID_TIME;
 		} else {
-			MHDPRINTF(("%s: read_vtoc: success\n",
+			MHDPRINTF(("%s: read_extvtoc: success\n",
 			    dp->dr_rname));
 			dp->dr_drive_id.did_flags |= MHD_DID_TIME;
 			dp->dr_drive_id.did_time = vtoc_buf.timestamp[0];
--- a/usr/src/cmd/prtvtoc/prtvtoc.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/prtvtoc/prtvtoc.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -28,12 +27,10 @@
 
 
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Print a disk partition map (volume table of contents, or VTOC).
  */
@@ -75,18 +72,18 @@
 	u_longlong_t	fr_size;	/* Length of free space */
 } freemap_t;
 
-static	freemap_t	*findfree(struct dk_geom *, struct vtoc *);
+static	freemap_t	*findfree(struct dk_geom *, struct extvtoc *);
 static	int	partcmp(const void *, const void *);
 static	int	partcmp64(const void *, const void *);
 static	int	prtvtoc(char *);
-static	void	putfree(struct vtoc *, freemap_t *);
+static	void	putfree(struct extvtoc *, freemap_t *);
 static	void	putfree64(struct dk_gpt *, freemap_t *);
-static	void	puttable(struct dk_geom *, struct vtoc *, freemap_t *,
+static	void	puttable(struct dk_geom *, struct extvtoc *, freemap_t *,
 			char *, char **);
 static	void	puttable64(struct dk_gpt *, freemap_t *,
 			char *, char **);
 static	int	readgeom(int, char *, struct dk_geom *);
-static	int	readvtoc(int, char *, struct vtoc *);
+static	int	readvtoc(int, char *, struct extvtoc *);
 static	int	readefi(int, char *, struct dk_gpt **);
 static	void	usage(void);
 static	int	warn(char *, char *);
@@ -148,18 +145,18 @@
  * findfree(): Find free space on a disk.
  */
 static freemap_t *
-findfree(struct dk_geom *geom, struct vtoc *vtoc)
+findfree(struct dk_geom *geom, struct extvtoc *vtoc)
 {
-	struct partition	*part;
-	struct partition	**list;
+	struct extpartition	*part;
+	struct extpartition	**list;
 	freemap_t		*freeidx;
-	ulong_t			fullsize;
+	diskaddr_t		fullsize;
 	ulong_t			cylsize;
-	struct partition	*sorted[V_NUMPAR + 1];
+	struct extpartition	*sorted[V_NUMPAR + 1];
 
 	freemap = calloc(sizeof (freemap_t), V_NUMPAR + 1);
 	cylsize  = (geom->dkg_nsect) * (geom->dkg_nhead);
-	fullsize = (geom->dkg_ncyl) * cylsize;
+	fullsize = (diskaddr_t)(geom->dkg_ncyl) * cylsize;
 	if (vtoc->v_nparts > V_NUMPAR) {
 		(void) warn("putfree()", "Too many partitions on disk!");
 		exit(1);
@@ -369,7 +366,7 @@
 	int		idx;
 	freemap_t	*freemap;
 	struct stat	sb;
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	int		geo;
 	struct dk_geom	geom;
 	char		*name;
@@ -432,7 +429,7 @@
  * of free space. FREE_PART lists the unassigned partitions.
  */
 static void
-putfree(struct vtoc *vtoc, freemap_t *freemap)
+putfree(struct extvtoc *vtoc, freemap_t *freemap)
 {
 	freemap_t *freeidx;
 	ushort_t idx;
@@ -475,7 +472,7 @@
  * puttable(): Print a human-readable VTOC.
  */
 static void
-puttable(struct dk_geom *geom, struct vtoc *vtoc, freemap_t *freemap,
+puttable(struct dk_geom *geom, struct extvtoc *vtoc, freemap_t *freemap,
     char *name, char **mtab)
 {
 	ushort_t	idx;
@@ -519,7 +516,7 @@
 	for (idx = 0; idx < vtoc->v_nparts; ++idx) {
 		if (vtoc->v_part[idx].p_size == 0)
 			continue;
-		(void) printf("      %2u  %5u    %02x  %9lu %9lu %9lu",
+		(void) printf("      %2u  %5u    %02x  %9llu %9llu %9llu",
 		    idx, vtoc->v_part[idx].p_tag, vtoc->v_part[idx].p_flag,
 		    vtoc->v_part[idx].p_start, vtoc->v_part[idx].p_size,
 		    vtoc->v_part[idx].p_start + vtoc->v_part[idx].p_size - 1);
@@ -608,11 +605,11 @@
  * readvtoc(): Read a partition map.
  */
 static int
-readvtoc(int fd, char *name, struct vtoc *vtoc)
+readvtoc(int fd, char *name, struct extvtoc *vtoc)
 {
 	int	retval;
 
-	if ((retval = read_vtoc(fd, vtoc)) >= 0)
+	if ((retval = read_extvtoc(fd, vtoc)) >= 0)
 		return (0);
 
 	switch (retval) {
--- a/usr/src/cmd/rmformat/rmf_main.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/rmformat/rmf_main.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * rmf_main.c :
  *	The file containing main() for rmformat. The command line
@@ -53,7 +51,7 @@
 static char *myname;
 char *slice_file = NULL;
 char *label;
-uint32_t repair_blk_no;
+diskaddr_t repair_blk_no;
 int32_t quick_format = 0;
 int32_t long_format = 0;
 int32_t force_format = 0;
@@ -69,7 +67,7 @@
 static void usage(char *);
 void check_invalid_combinations();
 void check_invalid_combinations_again(int32_t);
-extern int64_t my_atoll(char *ptr);
+extern uint64_t my_atoll(char *ptr);
 extern void my_perror(char *err_string);
 void process_options();
 
@@ -100,8 +98,7 @@
 	myname = argv[0];
 	DPRINTF1("myname %s\n", myname);
 
-	while ((i = getopt(argc, argv, "b:c:DeF:HlpR:s:tUV:W:w:"))
-							!= -1) {
+	while ((i = getopt(argc, argv, "b:c:DeF:HlpR:s:tUV:W:w:")) != -1) {
 		DPRINTF1("arg %c\n", i);
 		switch (i) {
 		case 'b' :
@@ -120,13 +117,13 @@
 			c_flag++;
 			tmp_ptr = strdup(optarg);
 			errno = 0;
-			repair_blk_no = (uint32_t)my_atoll(tmp_ptr);
-			if (repair_blk_no == (uint32_t)(-1)) {
+			repair_blk_no = my_atoll(tmp_ptr);
+			if (repair_blk_no == (diskaddr_t)(-1)) {
 				free(tmp_ptr);
 				usage("invalid block number");
 			}
 
-			DPRINTF1(" block no. %x\n", repair_blk_no);
+			DPRINTF1(" block no. %llu\n", repair_blk_no);
 			free(tmp_ptr);
 			break;
 
@@ -326,7 +323,7 @@
 check_invalid_combinations_again(int32_t medium_type)
 {
 	if ((medium_type != SM_FLOPPY) &&
-			(medium_type != SM_PCMCIA_MEM)) {
+	    (medium_type != SM_PCMCIA_MEM)) {
 		if (D_flag || H_flag) {
 			usage("-D, -H  options are compatible with floppy and \
 PCMCIA memory cards only.");
--- a/usr/src/cmd/rmformat/rmf_menu.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/rmformat/rmf_menu.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * rmf_menu.c :
  *	Command line options to rmformat are processed in this file.
@@ -51,7 +49,7 @@
 
 extern char *myname;
 extern char *slice_file;
-extern uint32_t repair_blk_no;
+extern diskaddr_t repair_blk_no;
 extern int32_t quick_format;
 extern int32_t long_format;
 extern int32_t force_format;
@@ -75,12 +73,12 @@
 extern void process_options();
 extern void get_passwd(struct smwp_state *wp, int32_t confirm);
 extern int32_t valid_slice_file(smedia_handle_t, int32_t, char *,
-	struct vtoc *);
+	struct extvtoc *);
 extern void trap_SIGINT();
 extern void release_SIGINT();
 extern int32_t verify(smedia_handle_t handle, int32_t fd,
-		uint32_t start_sector, uint32_t nblocks,
-		char *buf, int32_t flag, int32_t blocksize, int32_t no_raw_rw);
+	diskaddr_t start_sector, uint32_t nblocks,
+	char *buf, int32_t flag, int32_t blocksize, int32_t no_raw_rw);
 extern void my_perror(char *err_string);
 extern void write_default_label(smedia_handle_t, int32_t fd);
 extern int find_device(int defer, char *tmpstr);
@@ -223,7 +221,7 @@
 
 	DPRINTF1("media type %x\n", med_info.sm_media_type);
 	DPRINTF1("media block size %x\n", med_info.sm_blocksize);
-	DPRINTF1("media capacity %x\n", med_info.sm_capacity);
+	DPRINTF1("media capacity %u\n", (uint32_t)med_info.sm_capacity);
 	DPRINTF3("media cyl %d head %d sect %d\n",
 		med_info.sm_pcyl, med_info.sm_nhead, med_info.sm_nsect);
 	check_invalid_combinations_again(med_info.sm_media_type);
@@ -818,7 +816,7 @@
 
 	if (smedia_reassign_block(handle, repair_blk_no) != 0) {
 		(void) snprintf(error_string, 255,
-		    gettext("Could not repair block no %d"), repair_blk_no);
+		    gettext("Could not repair block no %llu"), repair_blk_no);
 		PERROR(error_string);
 		return;
 	}
@@ -836,13 +834,14 @@
 process_V_flag(smedia_handle_t handle, int32_t fd)
 {
 	int32_t ret;
-	uint32_t i, j;
+	uint32_t j;
+	diskaddr_t bn;
 	char *read_buf, *write_buf;
 	int32_t old_per = 0;
 	int32_t new_per;
 	int32_t no_raw_rw = 0;
 	int32_t verify_size;
-	uint32_t capacity;
+	diskaddr_t capacity;
 	int32_t blocksize;
 
 	DPRINTF("ANALYSE MEDIA \n");
@@ -855,12 +854,12 @@
 
 	DPRINTF1("media_type %d\n", med_info.sm_media_type);
 	DPRINTF1("sector_size %d\n", med_info.sm_blocksize);
-	DPRINTF1("num_sectors %d\n", med_info.sm_capacity);
+	DPRINTF1("num_sectors %u\n", (uint32_t)med_info.sm_capacity);
 	DPRINTF1("nsect	 %d\n", med_info.sm_nsect);
 
 	blocksize = med_info.sm_blocksize;
 
-	capacity = med_info.sm_capacity;
+	capacity = (uint32_t)med_info.sm_capacity;
 	verify_size = (med_info.sm_nsect > 64) ? 64 : med_info.sm_nsect;
 	read_buf = (char *)malloc(blocksize * verify_size);
 	if (read_buf == NULL) {
@@ -876,40 +875,42 @@
 
 	if (!verify_write) {
 		DPRINTF("Non-destructive verify \n");
-		for (i = 0; i < med_info.sm_capacity; i += verify_size) {
-			new_per = (i * 80)/med_info.sm_capacity;
+		for (bn = 0; bn < (uint32_t)med_info.sm_capacity;
+		    bn += verify_size) {
+			new_per = (bn * 80)/(uint32_t)med_info.sm_capacity;
 			if (new_per >= old_per) {
 				(void) printf(".");
 				(void) fflush(stdout);
 				old_per++;
 			}
-			DPRINTF2("Reading %d blks starting at %d\n",
-				verify_size, i);
-			ret = verify(handle, fd, i, verify_size, read_buf,
-				VERIFY_READ, blocksize, no_raw_rw);
+			DPRINTF2("Reading %d blks starting at %llu\n",
+			    verify_size, bn);
+			ret = verify(handle, fd, bn, verify_size, read_buf,
+			    VERIFY_READ, blocksize, no_raw_rw);
 			if ((ret == -1) && (errno == ENOTSUP)) {
 				no_raw_rw = 1;
-				ret = verify(handle, fd, i, verify_size,
-					read_buf,
-					VERIFY_READ, blocksize, no_raw_rw);
-				capacity = med_info.sm_pcyl * med_info.sm_nhead
-					* med_info.sm_nsect;
+				ret = verify(handle, fd, bn, verify_size,
+				    read_buf,
+				    VERIFY_READ, blocksize, no_raw_rw);
+				capacity = (diskaddr_t)med_info.sm_pcyl *
+				    med_info.sm_nhead * med_info.sm_nsect;
 			}
 
 			if (ret != 0) {
 				for (j = 0; j < verify_size; j++) {
-					if ((i + j) >= capacity)
+					if ((bn + j) >= capacity)
 							return;
-					    DPRINTF2(
-					"Reading %d blks starting at %d\n",
-						1, i+j);
-					ret = verify(handle, fd, i + j, 1,
-						read_buf,
-						VERIFY_READ, blocksize,
-						no_raw_rw);
+					DPRINTF2(
+					    "Reading %d blks starting "
+					    "at %llu\n", 1, bn + j);
+					ret = verify(handle, fd, bn + j, 1,
+					    read_buf,
+					    VERIFY_READ, blocksize,
+					    no_raw_rw);
 					if (ret == -1) {
-						(void) printf("Bad block %d\n",
-							i+j);
+						(void) printf(
+						    "Bad block %llu\n",
+						    bn + j);
 					}
 				}
 			}
@@ -917,8 +918,9 @@
 	} else {
 
 		DPRINTF("Destrutive verify \n");
-		for (i = 0; i < med_info.sm_capacity; i += verify_size) {
-			new_per = (i * 80)/med_info.sm_capacity;
+		for (bn = 0; bn < (uint32_t)med_info.sm_capacity;
+		    bn += verify_size) {
+			new_per = (bn * 80)/(uint32_t)med_info.sm_capacity;
 			if (new_per >= old_per) {
 				(void) printf(".");
 
@@ -927,48 +929,48 @@
 			}
 
 			for (j = 0; j < blocksize * verify_size; j++) {
-				write_buf[j] = (i|j) & 0xFF;
+				write_buf[j] = (bn | j) & 0xFF;
 			}
-			DPRINTF2("Writing %d blks starting at %d\n",
-				verify_size, i);
-			ret = verify(handle, fd, i, verify_size, write_buf,
-				VERIFY_WRITE, blocksize, no_raw_rw);
+			DPRINTF2("Writing %d blks starting at %llu\n",
+			    verify_size, bn);
+			ret = verify(handle, fd, bn, verify_size, write_buf,
+			    VERIFY_WRITE, blocksize, no_raw_rw);
 
 			if (ret != 0) {
 				for (j = 0; j < verify_size; j++) {
-					if ((i + j) >= capacity)
+					if ((bn + j) >= capacity)
 							break;
 					DPRINTF2(
-				"Writing %d blks starting at %d\n",
-					1, i+j);
-					ret = verify(handle, fd, i + j, 1,
-						write_buf,
-						VERIFY_WRITE, blocksize,
-						no_raw_rw);
+					    "Writing %d blks starting "
+					    "at %llu\n", 1, bn + j);
+					ret = verify(handle, fd, bn + j, 1,
+					    write_buf,
+					    VERIFY_WRITE, blocksize,
+					    no_raw_rw);
 					if (ret == -1) {
-						(void) printf("Bad block %d\n",
-							i+j);
+						(void) printf(
+						    "Bad block %llu\n", bn + j);
 					}
 				}
 			}
-			DPRINTF2("Read after write  %d blks starting at %d\n",
-				verify_size, i);
-			ret = verify(handle, fd, i, verify_size,
-				read_buf, VERIFY_READ, blocksize, no_raw_rw);
+			DPRINTF2("Read after write  %d blks starting at %llu\n",
+			    verify_size, bn);
+			ret = verify(handle, fd, bn, verify_size,
+			    read_buf, VERIFY_READ, blocksize, no_raw_rw);
 
 			if (ret != 0) {
 				for (j = 0; j < verify_size; j++) {
-					if ((i + j) >= capacity)
+					if ((bn + j) >= capacity)
 							return;
 					DPRINTF2(
-				"Read after write  %d blks starting at %d\n",
-					1, i+j);
-					ret = verify(handle, fd, i + j, 1,
-						read_buf, VERIFY_READ,
-						blocksize, no_raw_rw);
+					    "Read after write  %d blks "
+					    "starting at %llu\n", 1, bn + j);
+					ret = verify(handle, fd, bn + j, 1,
+					    read_buf, VERIFY_READ,
+					    blocksize, no_raw_rw);
 					if (ret == -1) {
-						(void) printf("Bad block %d\n",
-							i+j);
+						(void) printf(
+						    "Bad block %llu\n", bn + j);
 					}
 				}
 			}
@@ -982,7 +984,7 @@
 process_s_flag(smedia_handle_t handle, int32_t fd)
 {
 	int32_t i, ret;
-	struct vtoc v_toc, t_vtoc;
+	struct extvtoc v_toc, t_vtoc;
 	if (valid_slice_file(handle, fd, slice_file, &v_toc)) {
 			(void) smedia_release_handle(handle);
 			(void) close(fd);
@@ -1002,7 +1004,7 @@
 	/* Turn on privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
-	(void) read_vtoc(fd, &t_vtoc);
+	(void) read_extvtoc(fd, &t_vtoc);
 
 	/* Turn off privileges. */
 	(void) __priv_bracket(PRIV_OFF);
@@ -1020,7 +1022,7 @@
 	/* Turn on privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
-	ret = write_vtoc(fd, &t_vtoc);
+	ret = write_extvtoc(fd, &t_vtoc);
 
 	/* Turn off privileges. */
 	(void) __priv_bracket(PRIV_OFF);
@@ -1117,7 +1119,7 @@
 process_b_flag(int32_t fd)
 {
 	int32_t ret, nparts;
-	struct vtoc v_toc;
+	struct extvtoc v_toc;
 	struct dk_gpt *vtoc64;
 
 	/* For EFI disks. */
@@ -1158,7 +1160,7 @@
 	/* Turn on privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
-	ret = read_vtoc(fd, &v_toc);
+	ret = read_extvtoc(fd, &v_toc);
 
 	/* Turn off privileges */
 	(void) __priv_bracket(PRIV_OFF);
@@ -1185,7 +1187,7 @@
 	/* Turn on the privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
-	ret = write_vtoc(fd, &v_toc);
+	ret = write_extvtoc(fd, &v_toc);
 
 	/* Turn off the privileges. */
 	(void) __priv_bracket(PRIV_OFF);
--- a/usr/src/cmd/rmformat/rmf_misc.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/rmformat/rmf_misc.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,14 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
-
 /*
  * rmf_misc.c :
  *	Miscelleneous routines for rmformat.
@@ -713,12 +711,12 @@
 	return (fd);
 }
 
-int64_t
+uint64_t
 my_atoll(char *ptr)
 {
 	char *tmp_ptr = ptr;
 	int32_t base = 10;
-	int64_t ret_val;
+	uint64_t ret_val;
 
 	while (*tmp_ptr) {
 		if (isdigit(*tmp_ptr))
@@ -745,7 +743,7 @@
 			}
 		}
 	}
-	ret_val = strtoll(ptr, (char **)NULL, 0);
+	ret_val = (uint64_t)strtoull(ptr, (char **)NULL, 0);
 	return (ret_val);
 }
 
@@ -753,10 +751,10 @@
 write_sunos_label(int32_t fd, int32_t media_type)
 {
 
-	struct vtoc v_toc;
+	struct extvtoc v_toc;
 	int32_t ret;
 
-	(void) memset(&v_toc, 0, sizeof (struct vtoc));
+	(void) memset(&v_toc, 0, sizeof (struct extvtoc));
 
 	/* Initialize the vtoc information */
 
@@ -874,15 +872,15 @@
 		/* we want the same partitioning as used for normal floppies */
 
 		v_toc.v_part[0].p_start = 0;
-		v_toc.v_part[0].p_size =  (dkgeom.dkg_ncyl - 1) *
+		v_toc.v_part[0].p_size =  (diskaddr_t)(dkgeom.dkg_ncyl - 1) *
 		    dkgeom.dkg_nhead * dkgeom.dkg_nsect;
 
-		v_toc.v_part[1].p_start = (dkgeom.dkg_ncyl - 1) *
+		v_toc.v_part[1].p_start = (diskaddr_t)(dkgeom.dkg_ncyl - 1) *
 		    dkgeom.dkg_nhead * dkgeom.dkg_nsect;
 		v_toc.v_part[1].p_size =  dkgeom.dkg_nhead * dkgeom.dkg_nsect;
 
 		v_toc.v_part[2].p_start = 0;
-		v_toc.v_part[2].p_size = dkgeom.dkg_ncyl *
+		v_toc.v_part[2].p_size = (diskaddr_t)dkgeom.dkg_ncyl *
 		    dkgeom.dkg_nhead * dkgeom.dkg_nsect;
 
 		/* both write_vtoc and DKIOCSVTOC require V_NUMPAR partitions */
@@ -909,7 +907,7 @@
 	/* Turn on the privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
-	ret = write_vtoc(fd, &v_toc);
+	ret = write_extvtoc(fd, &v_toc);
 
 	/* Turn off the privileges. */
 	(void) __priv_bracket(PRIV_OFF);
@@ -969,11 +967,11 @@
 }
 
 int32_t
-verify(smedia_handle_t handle, int32_t fd, uint32_t start_sector,
+verify(smedia_handle_t handle, int32_t fd, diskaddr_t start_sector,
 	uint32_t nblocks, char *buf,
-			int32_t flag, int32_t blocksize, int32_t no_raw_rw)
+	int32_t flag, int32_t blocksize, int32_t no_raw_rw)
 {
-	int32_t ret;
+	uint64_t ret;
 
 	DPRINTF("ANALYSE MEDIA \n");
 
@@ -989,11 +987,11 @@
 		/* Turn off the privileges. */
 		(void) __priv_bracket(PRIV_OFF);
 
-		if ((ret < 0) || (ret != (nblocks * blocksize)))
-				return (-1);
+		if (ret != (nblocks * blocksize))
+			return (-1);
 		return (0);
 
-		} else if ((flag == VERIFY_WRITE) && (!no_raw_rw)) {
+	} else if ((flag == VERIFY_WRITE) && (!no_raw_rw)) {
 
 		/* Turn on privileges. */
 		(void) __priv_bracket(PRIV_ON);
@@ -1004,7 +1002,7 @@
 		/* Turn off the privileges. */
 		(void) __priv_bracket(PRIV_OFF);
 
-		if ((ret < 0) || (ret != (blocksize * nblocks)))
+		if (ret != (blocksize * nblocks))
 			return (-1);
 		return (0);
 
@@ -2028,7 +2026,7 @@
 get_media_info(device_t *t_dev, char *sdev, char *pname, char *sn)
 {
 	struct dk_cinfo cinfo;
-	struct vtoc vtocinfo;
+	struct extvtoc vtocinfo;
 	float size;
 	int32_t fd;
 	smedia_handle_t handle;
@@ -2079,7 +2077,7 @@
 	/*
 	 * Print label.
 	 */
-	if (!device_type && (!ioctl(t_dev->d_fd, DKIOCGVTOC, &vtocinfo))) {
+	if (!device_type && (read_extvtoc(t_dev->d_fd,  &vtocinfo) >= 0)) {
 		if (*vtocinfo.v_volume) {
 			(void) printf("\tLabel: %s\n", vtocinfo.v_volume);
 		} else {
--- a/usr/src/cmd/rmformat/rmf_slice.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/rmformat/rmf_slice.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * rmf_slice.c :
  * 	This file contains the functions for parsing a slice file
@@ -129,8 +127,8 @@
 /*
  *	Prototypes for ANSI C compilers
  */
-static int32_t	sup_prxfile(char *file_name, struct vtoc *vt);
-static int32_t	sup_setpart(struct vtoc *vt);
+static int32_t	sup_prxfile(char *file_name, struct extvtoc *vt);
+static int32_t	sup_setpart(struct extvtoc *vt);
 static void	sup_pushchar(int32_t c);
 static void	clean_token(char *cleantoken, char *token);
 static void clean_token(char *cleantoken, char *token);
@@ -138,21 +136,22 @@
 static int32_t sup_gettoken(char *buf);
 static int32_t sup_get_token(char *buf);
 static int32_t find_value(slist_t *slist, char *str, int32_t *value);
-static int32_t check_vtoc_sanity(smedia_handle_t, int32_t fd, struct vtoc *vt);
-static int32_t str2sector(char *str);
+static int32_t check_vtoc_sanity(smedia_handle_t, int32_t fd,
+		struct extvtoc *vt);
+static uint64_t str2sector(char *str);
 static int32_t strcnt(char *s1, char *s2);
 static int32_t get_fdisk(smedia_handle_t, int32_t fd, int32_t offset,
 		struct fdisk_info *fdisk);
-static void erase(smedia_handle_t handle, uint32_t offset, uint32_t size);
+static void erase(smedia_handle_t handle, diskaddr_t offset, diskaddr_t size);
 
 extern char *myname;
-extern int64_t my_atoll(char *ptr);
+extern uint64_t my_atoll(char *ptr);
 extern smmedium_prop_t med_info;
 
 static FILE *data_file;
 
 static int32_t
-sup_prxfile(char *file_name, struct vtoc *vt)
+sup_prxfile(char *file_name, struct extvtoc *vt)
 {
 	int32_t	status, ret_val;
 	TOKEN	token;
@@ -426,10 +425,11 @@
 }
 
 static int32_t
-sup_setpart(struct vtoc *vt)
+sup_setpart(struct extvtoc *vt)
 {
 	TOKEN	token, cleaned, ident;
-	int32_t	i, index, status, val1, val2;
+	int32_t	i, index, status;
+	uint64_t	val1, val2;
 	ushort_t	vtoc_tag = 0xFFFF;
 	ushort_t	vtoc_flag = 0xFFFF;
 
@@ -728,13 +728,13 @@
 	return (i);
 }
 
-static int32_t
+static uint64_t
 str2sector(char *str)
 {
 	int32_t mul_factor = 1;
 	char *s1, *s2, *base;
-	int32_t num_sectors;
-	int64_t size;
+	uint64_t num_sectors;
+	uint64_t size;
 
 	base = s2 = (char *)malloc(strlen(str) + 1);
 	if (s2 == NULL) {
@@ -779,7 +779,7 @@
 		free(base);
 		return (-1);
 	}
-	num_sectors = (uint64_t)size * (uint64_t)mul_factor /512;
+	num_sectors = size * (uint64_t)mul_factor /512;
 
 	free(base);
 	return (num_sectors);
@@ -788,7 +788,7 @@
 
 int32_t
 valid_slice_file(smedia_handle_t handle, int32_t fd, char *file_name,
-	struct vtoc *vt)
+	struct extvtoc *vt)
 {
 	struct stat status;
 	int32_t ret_val;
@@ -817,8 +817,8 @@
 	int32_t i;
 	for (i = 0; i < 8; i++) {
 		DPRINTF1("\npart %d\n", i);
-		DPRINTF1("\t start %d",  (int32_t)vt->v_part[i].p_start);
-		DPRINTF1("\t size %d ", (int32_t)vt->v_part[i].p_size);
+		DPRINTF1("\t start %llu",  vt->v_part[i].p_start);
+		DPRINTF1("\t size %llu ", vt->v_part[i].p_size);
 		DPRINTF1("\t tag %d", vt->v_part[i].p_tag);
 		DPRINTF1("\t flag %d", vt->v_part[i].p_flag);
 	}
@@ -832,8 +832,8 @@
 	int32_t i;
 	for (i = 0; i < 8; i++) {
 		DPRINTF1("\npart %d\n", i);
-		DPRINTF1("\t start %d",  (int32_t)vt->v_part[i].p_start);
-		DPRINTF1("\t size %d ", (int32_t)vt->v_part[i].p_size);
+		DPRINTF1("\t start %llu",  vt->v_part[i].p_start);
+		DPRINTF1("\t size %llu ", vt->v_part[i].p_size);
 		DPRINTF1("\t tag %d", vt->v_part[i].p_tag);
 		DPRINTF1("\t flag %d", vt->v_part[i].p_flag);
 	}
@@ -842,7 +842,7 @@
 	return (0);
 }
 
-#define	SWAP(a, b)	{int32_t tmp; tmp = (a); (a) = (b); (b) = tmp; }
+#define	SWAP(a, b)	{diskaddr_t tmp; tmp = (a); (a) = (b); (b) = tmp; }
 
 /*
  * On x86 Solaris, the partitioning is done in two levels, fdisk and Solaris
@@ -870,21 +870,22 @@
  */
 
 static int32_t
-check_vtoc_sanity(smedia_handle_t handle, int32_t fd, struct vtoc *vt)
+check_vtoc_sanity(smedia_handle_t handle, int32_t fd, struct extvtoc *vt)
 {
 
 	int32_t i, j;
 	struct dk_geom dkg;
 	int32_t num_backup = 0;
-	long backup_size = 0;
+	diskaddr_t backup_size = 0;
 	struct part_struct {
-		long start;
-		long end;
+		diskaddr_t start;
+		diskaddr_t end;
 		int32_t num;
 	} part[NDKMAP];
-	long min_val, min_slice, num_slices;
-	long media_size;
-	int32_t cyl_size;
+	diskaddr_t min_val;
+	int32_t min_slice, num_slices;
+	diskaddr_t media_size;
+	uint32_t cyl_size;
 	int sparc_style = 0;	/* sparc_style handling ? */
 	struct fdisk_info fdisk;
 	int sol_part;
@@ -907,7 +908,8 @@
 			PERROR("DKIOCGGEOM Failed");
 			return (-1);
 		}
-		media_size = dkg.dkg_ncyl * dkg.dkg_nhead * dkg.dkg_nsect;
+		media_size = (diskaddr_t)dkg.dkg_ncyl * dkg.dkg_nhead *
+		    dkg.dkg_nsect;
 		cyl_size = dkg.dkg_nhead * dkg.dkg_nsect;
 	}
 
@@ -938,10 +940,10 @@
 			if (total_parts > 1)
 				(void) fprintf(stderr, gettext("Multiple FDISK \
 Solaris partitions found.\n"));
-			media_size = fdisk.part[sol_part].numsect;
+			media_size = (diskaddr_t)fdisk.part[sol_part].numsect;
 
 			DPRINTF1("sol_part %d\n", sol_part);
-			DPRINTF1("media_size %d\n", (int)media_size);
+			DPRINTF1("media_size %llu\n", media_size);
 		} else {
 			DPRINTF("Didn't get fdisk\n");
 			/*
@@ -956,7 +958,7 @@
 			}
 			/* On x86 platform 1 cylinder is used for fdisk table */
 			dkg.dkg_ncyl = dkg.dkg_ncyl - 1;
-			media_size = dkg.dkg_ncyl * dkg.dkg_nhead *
+			media_size = (diskaddr_t)dkg.dkg_ncyl * dkg.dkg_nhead *
 			    dkg.dkg_nsect;
 		}
 	}
@@ -968,7 +970,7 @@
 #endif /* DEBUG */
 
 	if (media_size == 0) {
-		media_size = med_info.sm_capacity;
+		media_size = (uint32_t)med_info.sm_capacity;
 	}
 
 	(void) memset(&part, 0, sizeof (part));
@@ -1031,8 +1033,8 @@
 
 #ifdef DEBUG
 	for (i = 0; i < num_slices; i++) {
-		DPRINTF4("\n %d (%d) : %d, %d", i, part[i].num,
-			part[i].start, part[i].end);
+		DPRINTF4("\n %d (%d) : %llu, %llu", i, part[i].num,
+		    part[i].start, part[i].end);
 	}
 #endif /* DEBUG */
 
@@ -1042,7 +1044,8 @@
 			    gettext(
 			"Backup slice extends beyond size of media\n"));
 			(void) fprintf(stderr,
-			    gettext("media size : %d sectors \n"), media_size);
+			    gettext("media size : %llu sectors \n"),
+				media_size);
 		} else {
 
 			(void) fprintf(stderr,
@@ -1050,7 +1053,7 @@
 Solaris partition\n"));
 			(void) fprintf(stderr,
 			    gettext(
-			"FDISK Solaris partition size : %d sectors \n"),
+			"FDISK Solaris partition size : %llu sectors \n"),
 			    media_size);
 		}
 		return (-1);
@@ -1077,16 +1080,16 @@
 				"Slice %d extends beyond media size\n"),
 				    part[num_slices -1].num);
 				(void) fprintf(stderr,
-					gettext("media size : %d sectors \n"),
+				    gettext("media size : %llu sectors \n"),
 				    media_size);
 			} else {
 				(void) fprintf(stderr,
 				    gettext(
 		"Slice %d extends beyond FDISK Solaris partition size\n"),
 			part[num_slices -1].num);
-				(void) fprintf(stderr,
-				    gettext("FDISK Solaris partition size : %d \
-sectors \n"), media_size);
+				(void) fprintf(stderr, gettext(
+				    "FDISK Solaris partition size : %llu "
+				    "sectors \n"), media_size);
 			}
 			return (-1);
 		}
@@ -1139,8 +1142,9 @@
 		/* Turn on privileges. */
 		(void) __priv_bracket(PRIV_ON);
 
-		ret = smedia_raw_read(handle, offset/med_info.sm_blocksize,
-			buf, med_info.sm_blocksize);
+		ret = smedia_raw_read(handle,
+		    (diskaddr_t)offset/med_info.sm_blocksize,
+		    buf, med_info.sm_blocksize);
 
 		/* Turn off privileges. */
 		(void) __priv_bracket(PRIV_OFF);
@@ -1242,12 +1246,13 @@
 write_default_label(smedia_handle_t handle, int32_t fd)
 {
 
-	struct vtoc v_toc;
-	int32_t nhead, numcyl, nsect, capacity;
+	struct extvtoc v_toc;
+	uint32_t nhead, numcyl, nsect;
+	diskaddr_t capacity;
 	int32_t ret;
 	char asciilabel[LEN_DKL_ASCII];
 	char asciilabel2[LEN_DKL_ASCII] = "DEFAULT\0";
-	int32_t acyl = 2;
+	uint32_t acyl = 2;
 
 
 	DPRINTF("Writing default vtoc\n");
@@ -1267,7 +1272,7 @@
 	 * This will cause some truncation of size due to
 	 * round off errors.
 	 */
-	if (med_info.sm_capacity <= 0x200000) {
+	if ((uint32_t)med_info.sm_capacity <= 0x200000) {
 		nhead = 64;
 		nsect = 32;
 	} else {
@@ -1275,8 +1280,8 @@
 		nsect = 63;
 	}
 
-	numcyl = med_info.sm_capacity / (nhead * nsect);
-	capacity = nhead * nsect * numcyl;
+	numcyl = (uint32_t)med_info.sm_capacity / (nhead * nsect);
+	capacity = (diskaddr_t)nhead * nsect * numcyl;
 
 	v_toc.v_part[0].p_start = 0;
 	v_toc.v_part[0].p_size = capacity;
@@ -1300,7 +1305,7 @@
 	/* Turn on privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
-	ret = write_vtoc(fd, &v_toc);
+	ret = write_extvtoc(fd, &v_toc);
 
 	/* Turn off privileges. */
 	(void) __priv_bracket(PRIV_OFF);
@@ -1320,20 +1325,20 @@
 
 	int32_t i, ret;
 	struct dk_geom  dkg;
-	struct vtoc v_toc;
+	struct extvtoc v_toc;
 	int tmp_fd;
 	char *fdisk_buf;
 	struct mboot boot_code;		/* Buffer for master boot record */
 	struct ipart parts[FD_NUMPART];
-	int32_t numcyl, nhead, nsect;
-	int32_t unixend;
-	int32_t blocksize;
-	int32_t capacity;
+	uint32_t numcyl, nhead, nsect;
+	uint32_t unixend;
+	uint32_t blocksize;
+	diskaddr_t capacity;
 	int	save_errno;
 	size_t	bytes_written;
 	char asciilabel[LEN_DKL_ASCII];
 	char asciilabel2[LEN_DKL_ASCII] = "DEFAULT\0";
-	int32_t acyl = 2;
+	uint32_t acyl = 2;
 
 	DPRINTF("Writing default fdisk table and vtoc\n");
 	(void) memset(&v_toc, 0, sizeof (v_toc));
@@ -1384,7 +1389,7 @@
 	unixend = numcyl;
 
 	parts[0].relsect = lel(nhead * nsect);
-	parts[0].numsect = lel((long)((numcyl) * nhead * nsect));
+	parts[0].numsect = lel(((diskaddr_t)numcyl * nhead * nsect));
 	parts[0].systid = SUNIXOS2;   /* Solaris */
 	parts[0].beghead = 0;
 	parts[0].begcyl = 1;
@@ -1413,8 +1418,8 @@
 		/* Turn on privileges. */
 		(void) __priv_bracket(PRIV_ON);
 
-		bytes_written = smedia_raw_write(handle, 0, fdisk_buf,
-			blocksize);
+		bytes_written = smedia_raw_write(handle, (diskaddr_t)0,
+		    fdisk_buf, blocksize);
 
 		/* Turn off privileges. */
 		(void) __priv_bracket(PRIV_OFF);
@@ -1440,7 +1445,7 @@
 			}
 		}
 	}
-	capacity = (numcyl - 1) * nhead * nsect;
+	capacity = (diskaddr_t)(numcyl - 1) * nhead * nsect;
 
 	v_toc.v_nparts = V_NUMPAR;
 	v_toc.v_sanity = VTOC_SANE;
@@ -1470,7 +1475,7 @@
 	/* Turn on privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
-	ret = write_vtoc(fd, &v_toc);
+	ret = write_extvtoc(fd, &v_toc);
 
 	/* Turn off privileges. */
 	(void) __priv_bracket(PRIV_OFF);
@@ -1508,11 +1513,11 @@
 {
 
 	struct fdisk_info fdisk;
-	uint32_t sol_offset = 0;
+	diskaddr_t sol_offset = 0;
 	int i, ret;
-	struct vtoc t_vtoc;
+	struct extvtoc t_vtoc;
 #ifdef i386
-	uint32_t sol_size = 0;
+	diskaddr_t sol_size = 0;
 	int32_t active = 0;
 #endif /* i386 */
 
@@ -1545,8 +1550,8 @@
 				}
 			}
 #endif /* i386 */
-			erase(handle, fdisk.part[i].relsect,
-			    fdisk.part[i].numsect);
+			erase(handle, (diskaddr_t)fdisk.part[i].relsect,
+			    (diskaddr_t)fdisk.part[i].numsect);
 		}
 	}
 
@@ -1559,14 +1564,14 @@
 		/* Turn on privileges. */
 		(void) __priv_bracket(PRIV_ON);
 
-		ret = read_vtoc(fd, &t_vtoc);
+		ret = read_extvtoc(fd, &t_vtoc);
 
 		/* Turn off privileges. */
 		(void) __priv_bracket(PRIV_OFF);
 
 		if (ret < 0) {
 			/* No valid vtoc, erase fdisk table. */
-			erase(handle, 0, 1);
+			erase(handle, (diskaddr_t)0, (diskaddr_t)1);
 			return;
 		}
 	} else {
@@ -1575,14 +1580,15 @@
 		/* Turn on privileges */
 		(void) __priv_bracket(PRIV_ON);
 
-		ret = read_vtoc(fd, &t_vtoc);
+		ret = read_extvtoc(fd, &t_vtoc);
 
 		/* Turn off privileges. */
 		(void) __priv_bracket(PRIV_OFF);
 
 		if (ret < 0) {
 			/* No valid vtoc, erase from 0th sector */
-			erase(handle, 0, med_info.sm_capacity);
+			erase(handle, (diskaddr_t)0,
+			    (uint32_t)med_info.sm_capacity);
 			return;
 		}
 	}
@@ -1596,16 +1602,16 @@
 			 * erase sectors 256, (p_size-256) and psize.
 			 */
 			erase(handle,
-				sol_offset + t_vtoc.v_part[i].p_start + 256,
-				1);
+			    sol_offset + t_vtoc.v_part[i].p_start + 256,
+			    (diskaddr_t)1);
 			erase(handle,
-				(sol_offset + t_vtoc.v_part[i].p_start +
-				t_vtoc.v_part[i].p_size - 256),
-				1);
+			    (sol_offset + t_vtoc.v_part[i].p_start +
+			    t_vtoc.v_part[i].p_size - 256),
+			    (diskaddr_t)1);
 			erase(handle,
-				(sol_offset + t_vtoc.v_part[i].p_start +
-				t_vtoc.v_part[i].p_size - 1),
-				1);
+			    (sol_offset + t_vtoc.v_part[i].p_start +
+			    t_vtoc.v_part[i].p_size - 1),
+			    (diskaddr_t)1);
 		}
 	}
 
@@ -1614,7 +1620,7 @@
 	 * for sparc, the erasing 0the sector erases vtoc.
 	 */
 	if (sol_offset) {
-		erase(handle, sol_offset, DK_LABEL_LOC + 2);
+		erase(handle, sol_offset, (diskaddr_t)DK_LABEL_LOC + 2);
 	}
 
 	/*
@@ -1622,7 +1628,7 @@
 	 * erased in the above sequence.
 	 */
 
-	erase(handle, 0, 1);
+	erase(handle, (diskaddr_t)0, (diskaddr_t)1);
 }
 
 /*
@@ -1633,10 +1639,10 @@
  */
 
 static void
-erase(smedia_handle_t handle, uint32_t offset, uint32_t size)
+erase(smedia_handle_t handle, diskaddr_t offset, diskaddr_t size)
 {
 	char *buf;
-	int32_t nblocks = size;
+	diskaddr_t nblocks = size;
 	int32_t ret;
 
 
@@ -1646,13 +1652,13 @@
 		PERROR("malloc failed");
 		return;
 	}
-	(void) memset(buf, 0, nblocks * med_info.sm_blocksize);
+	(void) memset(buf, 0, (size_t)nblocks * med_info.sm_blocksize);
 
 	/* Turn on privileges. */
 	(void) __priv_bracket(PRIV_ON);
 
 	ret = smedia_raw_write(handle, offset, buf,
-	    nblocks * med_info.sm_blocksize);
+	    (size_t)nblocks * med_info.sm_blocksize);
 
 	/* Turn off privileges. */
 	(void) __priv_bracket(PRIV_OFF);
--- a/usr/src/cmd/smserverd/smediad.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/cmd/smserverd/smediad.c	Thu Sep 11 18:00:50 2008 -0700
@@ -24,8 +24,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <stdio.h>
 #include <stdio_ext.h>
 #include <errno.h>
@@ -1978,6 +1976,7 @@
 	char			rq_data[RQ_LEN];
 	uint_t			nexpected_desc;
 	struct vtoc		vtoc;
+	struct extvtoc		extvtoc;
 
 	door_dp = (door_data_t *)cookie;
 	req = (smedia_services_t *)((void *)argp);
@@ -2224,7 +2223,10 @@
 		}
 
 		/* Check for EFI type because DKIOCGGEOM does not support EFI */
-		ret_val = ioctl(door_dp->dd_fd, DKIOCGVTOC, &vtoc);
+		ret_val = ioctl(door_dp->dd_fd, DKIOCGEXTVTOC, &extvtoc);
+		if (ret_val < 0 && errno == ENOTTY)
+			ret_val = ioctl(door_dp->dd_fd, DKIOCGVTOC, &vtoc);
+
 		if (!((ret_val < 0) && (errno == ENOTSUP))) {
 			ret_val = ioctl(door_dp->dd_fd, DKIOCGGEOM, &dkgeom);
 			if (ret_val < 0)  {
--- a/usr/src/common/fs/decompress.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/common/fs/decompress.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Decompression module for stand alone file systems.
  */
@@ -48,10 +47,12 @@
 #define	GZIP_CM_DEFLATE		0x08
 #define	SEEKBUFSIZE		8192
 
+extern void prom_printf(const char *fmt, ...);
+
 #ifdef	_BOOT
-#define	dprintf	if (cf_debug) printf
+#define	dprintf	if (cf_debug) prom_printf
 #else
-#define	dprintf	if (cf_debug) printf
+#define	dprintf	if (cf_debug) prom_printf
 
 #endif
 
@@ -63,7 +64,7 @@
 int decomp_bufcnt;			/* total no, of allocated decomp bufs */
 int free_dcomp_bufs;			/* no. of free decomp bufs */
 char seek_scrbuf[SEEKBUFSIZE];		/* buffer for seeking */
-int cf_debug;				/* non-zero enables debug prints */
+int cf_debug = 0;			/* non-zero enables debug prints */
 
 void *
 cf_alloc(void *opaque, unsigned int items, unsigned int size)
@@ -107,8 +108,15 @@
 	z_stream *zsp;
 
 	/*
-	 * If the file is not long enough to check for a decompression header
-	 * then return not compressed.
+	 * checking for a dcfs compressed file first would involve:
+	 *
+	 *	if (filep->fi_inode->i_cflags & ICOMPRESS)
+	 * 		filep->fi_flags |= FI_COMPRESSED;
+	 */
+
+	/*
+	 * If the file is not long enough to check for a
+	 * decompression header then return not compressed.
 	 */
 	if (filep->fi_inode->i_size < 3)
 		return (0);
@@ -119,7 +127,8 @@
 	filep->fi_count = 0;
 	filep->fi_cfoff = 0;
 	filebytes = (unsigned char *)filep->fi_memp;
-	if (filebytes[0] != GZIP_ID_BYTE_1 || filebytes[1] != GZIP_ID_BYTE_2 ||
+	if (filebytes[0] != GZIP_ID_BYTE_1 ||
+	    filebytes[1] != GZIP_ID_BYTE_2 ||
 	    filebytes[2] != GZIP_CM_DEFLATE)
 		return (0); /* not compressed */
 	filep->fi_flags |= FI_COMPRESSED;
@@ -150,7 +159,7 @@
 	zsp->next_in = NULL;
 	zsp->avail_out = 0;
 	zsp->next_out = NULL;
-	if (inflateInit2(zsp, MAX_WBITS + 16) != Z_OK) {
+	if (inflateInit2(zsp, MAX_WBITS | 0x20) != Z_OK) {
 		dprintf("inflateInit2() failed\n");
 		return (-1);
 	}
--- a/usr/src/common/fs/ufsops.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/common/fs/ufsops.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/vnode.h>
@@ -106,7 +105,7 @@
 
 	filep->fi_offset = 0;
 	filep->fi_blocknum = fsbtodb(&devp->un_fs.di_fs,
-				itod(&devp->un_fs.di_fs, inode));
+	    itod(&devp->un_fs.di_fs, inode));
 
 	/* never more than 1 disk block */
 	filep->fi_count = devp->un_fs.di_fs.fs_bsize;
--- a/usr/src/grub/grub-0.95/grub/asmstub.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/grub/grub-0.95/grub/asmstub.c	Thu Sep 11 18:00:50 2008 -0700
@@ -926,7 +926,7 @@
 
 int
 biosdisk (int subfunc, int drive, struct geometry *geometry,
-	  int sector, int nsec, int segment)
+	  unsigned int sector, int nsec, int segment)
 {
   char *buf;
   int fd = geometry->flags;
@@ -984,7 +984,7 @@
     case BIOSDISK_WRITE:
       if (verbose)
 	{
-	  grub_printf ("Write %d sectors starting from %d sector"
+	  grub_printf ("Write %d sectors starting from %u sector"
 		       " to drive 0x%x (%s)\n",
 		       nsec, sector, drive, device_map[drive]);
 	  hex_dump (buf, nsec * SECTOR_SIZE);
--- a/usr/src/grub/grub-0.95/stage2/bios.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/grub/grub-0.95/stage2/bios.c	Thu Sep 11 18:00:50 2008 -0700
@@ -47,8 +47,9 @@
    return the error number. Otherwise, return 0.  */
 int
 biosdisk (int read, int drive, struct geometry *geometry,
-	  int sector, int nsec, int segment)
+	  unsigned int sector, int nsec, int segment)
 {
+
   int err;
   
   if (geometry->flags & BIOSDISK_FLAG_LBA_EXTENSION)
@@ -79,7 +80,6 @@
       /* This is undocumented part. The address is formated in
 	 SEGMENT:ADDRESS.  */
       dap.buffer = segment << 16;
-      
       err = biosdisk_int13_extensions ((read + 0x42) << 8, drive, &dap);
       /*
        * Try to report errors upwards when the bios has read only part of
@@ -108,7 +108,6 @@
     {
       int cylinder_offset, head_offset, sector_offset;
       int head;
-
       /* SECTOR_OFFSET is counted from one, while HEAD_OFFSET and
 	 CYLINDER_OFFSET are counted from zero.  */
       sector_offset = sector % geometry->sectors + 1;
--- a/usr/src/grub/grub-0.95/stage2/builtins.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/grub/grub-0.95/stage2/builtins.c	Thu Sep 11 18:00:50 2008 -0700
@@ -17,6 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -90,6 +91,8 @@
 static void solaris_config_file (void);
 #endif
 
+static unsigned int min_mem64 = 0;
+
 #if defined(__sun) && !defined(GRUB_UTIL)
 extern void __enable_execute_stack (void *);
 void
@@ -147,9 +150,9 @@
 
 /* Print which sector is read when loading a file.  */
 static void
-disk_read_print_func (int sector, int offset, int length)
+disk_read_print_func(unsigned int sector, int offset, int length)
 {
-  grub_printf ("[%d,%d,%d]", sector, offset, length);
+  grub_printf ("[%u,%d,%d]", sector, offset, length);
 }
 
 
@@ -165,7 +168,8 @@
 
   /* Collect contiguous blocks into one entry as many as possible,
      and print the blocklist notation on the screen.  */
-  static void disk_read_blocklist_func (int sector, int offset, int length)
+  static void disk_read_blocklist_func(unsigned int sector, int offset,
+	int length)
     {
       if (num_sectors > 0)
 	{
@@ -1230,6 +1234,10 @@
 	       "Upper memory (to first chipset hole): %uK\n",
 	       mbi.mem_lower, mbi.mem_upper);
 
+  if (min_mem64 != 0)
+  	grub_printf (" Memory limit for 64-bit ISADIR expansion: %uMB\n",
+	    min_mem64);
+
   if (mbi.flags & MB_INFO_MEM_MAP)
     {
       struct AddrRangeDesc *map = (struct AddrRangeDesc *) mbi.mmap_addr;
@@ -1246,12 +1254,12 @@
 	  else
 	    str = "Reserved";
 	  grub_printf ("   %s:  Base Address:  0x%x X 4GB + 0x%x,\n"
-		       "      Length:   0x%x X 4GB + 0x%x bytes\n",
-		       str,
-		       (unsigned long) (map->BaseAddr >> 32),
-		       (unsigned long) (map->BaseAddr & 0xFFFFFFFF),
-		       (unsigned long) (map->Length >> 32),
-		       (unsigned long) (map->Length & 0xFFFFFFFF));
+		"      Length:   0x%x X 4GB + 0x%x bytes\n",
+		str,
+		(unsigned long) (map->BaseAddr >> 32),
+		(unsigned long) (map->BaseAddr & 0xFFFFFFFF),
+		(unsigned long) (map->Length >> 32),
+		(unsigned long) (map->Length & 0xFFFFFFFF));
 
 	  map = ((struct AddrRangeDesc *) (((int) map) + 4 + map->size));
 	}
@@ -1443,7 +1451,7 @@
     }
 
   /* Clear the cache.  */
-  buf_track = -1;
+  buf_track = BUF_CACHE_INVALID;
 
   /* Now perform the embedding.  */
   if (! devwrite (sector - part_start, size, stage1_5_buffer))
@@ -1814,7 +1822,7 @@
 #endif
 
   grub_printf ("drive 0x%x: C/H/S = %d/%d/%d, "
-	       "The number of sectors = %d, %s\n",
+	       "The number of sectors = %u, %s\n",
 	       current_drive,
 	       geom.cylinders, geom.heads, geom.sectors,
 	       geom.total_sectors, msg);
@@ -2162,12 +2170,13 @@
   char *config_filename = stage2_second_buffer + SECTOR_SIZE;
   char *dummy = config_filename + SECTOR_SIZE;
   int new_drive = GRUB_INVALID_DRIVE;
-  int dest_drive, dest_partition, dest_sector;
+  int dest_drive, dest_partition;
+  unsigned int dest_sector;
   int src_drive, src_partition, src_part_start;
   int i;
   struct geometry dest_geom, src_geom;
-  int saved_sector;
-  int stage2_first_sector, stage2_second_sector;
+  unsigned int saved_sector;
+  unsigned int stage2_first_sector, stage2_second_sector;
   char *ptr;
   int installaddr, installlist;
   /* Point to the location of the name of a configuration file in Stage 2.  */
@@ -2188,10 +2197,11 @@
 #endif /* GRUB_UTIL */
   
   /* Save the first sector of Stage2 in STAGE2_SECT.  */
-  static void disk_read_savesect_func (int sector, int offset, int length)
+  static void disk_read_savesect_func(unsigned int sector, int offset,
+	int length)
     {
       if (debug)
-	printf ("[%d]", sector);
+	printf ("[%u]", sector);
 
       /* ReiserFS has files which sometimes contain data not aligned
          on sector boundaries.  Returning an error is better than
@@ -2204,10 +2214,11 @@
 
   /* Write SECTOR to INSTALLLIST, and update INSTALLADDR and
      INSTALLSECT.  */
-  static void disk_read_blocklist_func (int sector, int offset, int length)
+  static void disk_read_blocklist_func(unsigned int sector, int offset,
+	int length)
     {
       if (debug)
-	printf("[%d]", sector);
+	printf("[%u]", sector);
 
       if (offset != 0 || last_length != SECTOR_SIZE)
 	{
@@ -2548,7 +2559,7 @@
 	    }
 	  
 	  /* Write it to the disk.  */
-	  buf_track = -1;
+	  buf_track = BUF_CACHE_INVALID;
 
 #ifdef GRUB_UTIL
 	  /* In the grub shell, access the Stage 2 via the OS filesystem
@@ -2591,7 +2602,7 @@
     }
 
   /* Clear the cache.  */
-  buf_track = -1;
+  buf_track = BUF_CACHE_INVALID;
 
   /* Write the modified sectors of Stage2 to the disk.  */
 #ifdef GRUB_UTIL
@@ -2905,6 +2916,34 @@
   " Linux's mem option automatically."
 };
 
+int
+min_mem64_func(char *arg, int flags)
+{
+	if (!safe_parse_maxint(&arg, &min_mem64))
+		return (1);
+}
+
+static struct builtin builtin_min_mem64 =
+{
+	"min_mem64",
+	min_mem64_func,
+	BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_SCRIPT | BUILTIN_HELP_LIST,
+	"min_mem64 <memory in MB>",
+	"Sets minimum memory (in MB) required for $ISADIR to expand to amd64, "
+	"even on 64-bit capable hardware."
+};
+
+int
+check_min_mem64()
+{
+	if (min_mem64 == 0)
+		return (1);
+
+	if ((mbi.mem_upper / 10240) * 11 >= min_mem64)
+		return (1);
+
+	return (0);
+}
 
 static int detect_target_operating_mode();
 
@@ -3144,7 +3183,7 @@
     strncat(newarg, arg, MAX_CMDLINE);
     index[0] = '$';
 
-    if (isamd64())
+    if (isamd64() && check_min_mem64())
       strncat(newarg, "amd64", MAX_CMDLINE);
 
     arg = index + 7;
@@ -3597,7 +3636,7 @@
   PC_MBR_SIG (mbr) = PC_MBR_SIGNATURE;
   
   /* Write back the MBR to the disk.  */
-  buf_track = -1;
+  buf_track = BUF_CACHE_INVALID;
   if (! rawwrite (current_drive, 0, mbr))
     return 1;
 
@@ -3669,7 +3708,7 @@
 	  PC_SLICE_TYPE (mbr, entry) = new_type;
 	  
 	  /* Write back the MBR to the disk.  */
-	  buf_track = -1;
+	  buf_track = BUF_CACHE_INVALID;
 	  if (! rawwrite (current_drive, offset, mbr))
 	    return 1;
 
@@ -4139,7 +4178,7 @@
   char sect[SECTOR_SIZE];
   int entryno;
   int sector_count = 0;
-  int saved_sectors[2];
+  unsigned int saved_sectors[2];
   int saved_offsets[2];
   int saved_lengths[2];
 
@@ -4149,8 +4188,9 @@
   }
 
   /* Save sector information about at most two sectors.  */
-  auto void disk_read_savesect_func (int sector, int offset, int length);
-  void disk_read_savesect_func (int sector, int offset, int length)
+  auto void disk_read_savesect_func(unsigned int sector, int offset,
+	int length);
+  void disk_read_savesect_func(unsigned int sector, int offset, int length)
     {
       if (sector_count < 2)
 	{
@@ -4265,7 +4305,7 @@
 	}
 
       /* Clear the cache.  */
-      buf_track = -1;
+      buf_track = BUF_CACHE_INVALID;
     }
 
  fail:
@@ -5768,6 +5808,7 @@
 #ifdef USE_MD5_PASSWORDS
   &builtin_md5crypt,
 #endif /* USE_MD5_PASSWORDS */
+  &builtin_min_mem64,
   &builtin_module,
   &builtin_module_dollar,
   &builtin_modulenounzip,
--- a/usr/src/grub/grub-0.95/stage2/disk_io.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/grub/grub-0.95/stage2/disk_io.c	Thu Sep 11 18:00:50 2008 -0700
@@ -31,8 +31,8 @@
 #endif
 
 /* instrumentation variables */
-void (*disk_read_hook) (int, int, int) = NULL;
-void (*disk_read_func) (int, int, int) = NULL;
+void (*disk_read_hook) (unsigned int, int, int) = NULL;
+void (*disk_read_func) (unsigned int, int, int) = NULL;
 
 #ifndef STAGE1_5
 int print_possibilities;
@@ -136,7 +136,7 @@
 
 /* disk buffer parameters */
 int buf_drive = -1;
-int buf_track;
+unsigned int buf_track;
 struct geometry buf_geom;
 
 /* filesystem common variables */
@@ -154,7 +154,8 @@
 #define log2 grub_log2
 
 int
-rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
+rawread(int drive, unsigned int sector, int byte_offset, int byte_len,
+	char *buf)
 {
   int slen, sectors_per_vtrack;
   int sector_size_bits = log2 (buf_geom.sector_size);
@@ -164,7 +165,8 @@
 
   while (byte_len > 0 && !errnum)
     {
-      int soff, num_sect, track, size = byte_len;
+      int soff, num_sect, size = byte_len;
+      unsigned int track;  
       char *bufaddr;
 
       /*
@@ -179,12 +181,12 @@
 	      return 0;
 	    }
 	  buf_drive = drive;
-	  buf_track = -1;
+	  buf_track = BUF_CACHE_INVALID;
 	  sector_size_bits = log2 (buf_geom.sector_size);
 	}
 
       /* Make sure that SECTOR is valid.  */
-      if (sector < 0 || sector >= buf_geom.total_sectors)
+      if (sector >= buf_geom.total_sectors)
 	{
 	  errnum = ERR_GEOM;
 	  return 0;
@@ -208,7 +210,8 @@
 
       if (track != buf_track)
 	{
-	  int bios_err, read_start = track, read_len = sectors_per_vtrack;
+	  int bios_err, read_len = sectors_per_vtrack;
+	  unsigned int read_start = track;
 
 	  /*
 	   *  If there's more than one read in this entire loop, then
@@ -226,7 +229,7 @@
 			       read_start, read_len, BUFFERSEG);
 	  if (bios_err)
 	    {
-	      buf_track = -1;
+	      buf_track = BUF_CACHE_INVALID;
 
 	      if (bios_err == BIOSDISK_ERROR_GEOMETRY)
 		errnum = ERR_GEOM;
@@ -278,7 +281,7 @@
        */
       if (disk_read_func)
 	{
-	  int sector_num = sector;
+	  unsigned int sector_num = sector;
 	  int length = buf_geom.sector_size - byte_offset;
 	  if (length > size)
 	    length = size;
@@ -308,14 +311,13 @@
 
 
 int
-devread (int sector, int byte_offset, int byte_len, char *buf)
+devread(unsigned int sector, int byte_offset, int byte_len, char *buf)
 {
   /*
    *  Check partition boundaries
    */
-  if (sector < 0
-      || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS))
-	  >= part_length))
+  if ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS))
+	>= part_length)
     {
       errnum = ERR_OUTSIDE_PART;
       return 0;
@@ -329,7 +331,7 @@
 
 #if !defined(STAGE1_5)
   if (disk_read_hook && debug)
-    printf ("<%d, %d, %d>", sector, byte_offset, byte_len);
+    printf ("<%u, %d, %d>", sector, byte_offset, byte_len);
 #endif /* !STAGE1_5 */
 
   /*
@@ -347,7 +349,7 @@
 
 #ifndef STAGE1_5
 int
-rawwrite (int drive, int sector, char *buf)
+rawwrite(int drive, unsigned int sector, char *buf)
 {
   if (sector == 0)
     {
@@ -374,13 +376,13 @@
 
   if (sector - sector % buf_geom.sectors == buf_track)
     /* Clear the cache.  */
-    buf_track = -1;
+    buf_track = BUF_CACHE_INVALID;
 
   return 1;
 }
 
 int
-devwrite (int sector, int sector_count, char *buf)
+devwrite(unsigned int sector, int sector_count, char *buf)
 {
 #if defined(GRUB_UTIL) && defined(__linux__)
   if (current_partition != 0xFFFFFF
@@ -552,7 +554,7 @@
 	    PC_SLICE_TYPE (mbr, entry) &= ~PC_SLICE_TYPE_HIDDEN_FLAG;       
 	  
 	  /* Write back the MBR to the disk.  */
-	  buf_track = -1;
+	  buf_track = BUF_CACHE_INVALID;
 	  if (! rawwrite (current_drive, offset, mbr))
 	    return 1;
 	  
@@ -870,7 +872,7 @@
 	  return 0;
 	}
       buf_drive = current_drive;
-      buf_track = -1;
+      buf_track = BUF_CACHE_INVALID;
     }
   part_length = buf_geom.total_sectors;
 
--- a/usr/src/grub/grub-0.95/stage2/shared.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/grub/grub-0.95/stage2/shared.h	Thu Sep 11 18:00:50 2008 -0700
@@ -652,8 +652,8 @@
 #endif
 
 /* instrumentation variables */
-extern void (*disk_read_hook) (int, int, int);
-extern void (*disk_read_func) (int, int, int);
+extern void (*disk_read_hook) (unsigned int, int, int);
+extern void (*disk_read_func) (unsigned int, int, int);
 
 #ifndef STAGE1_5
 /* The flag for debug mode.  */
@@ -699,7 +699,8 @@
 extern int current_slice;
 
 extern int buf_drive;
-extern int buf_track;
+#define BUF_CACHE_INVALID 0xffffffff
+extern unsigned int buf_track;
 extern struct geometry buf_geom;
 
 /* these are the current file position and maximum file position */
@@ -873,7 +874,7 @@
 /* Low-level disk I/O */
 int get_diskinfo (int drive, struct geometry *geometry);
 int biosdisk (int subfunc, int drive, struct geometry *geometry,
-	      int sector, int nsec, int segment);
+    unsigned int sector, int nsec, int segment);
 void stop_floppy (void);
 
 /* Command-line interface functions. */
@@ -990,10 +991,11 @@
 int gunzip_read (char *buf, int len);
 #endif /* NO_DECOMPRESSION */
 
-int rawread (int drive, int sector, int byte_offset, int byte_len, char *buf);
-int devread (int sector, int byte_offset, int byte_len, char *buf);
-int rawwrite (int drive, int sector, char *buf);
-int devwrite (int sector, int sector_len, char *buf);
+int rawread (int drive, unsigned int sector, int byte_offset, int byte_len,
+	char *buf);
+int devread (unsigned int sector, int byte_offset, int byte_len, char *buf);
+int rawwrite (int drive, unsigned int sector, char *buf);
+int devwrite (unsigned int sector, int sector_len, char *buf);
 
 /* Parse a device string and initialize the global parameters. */
 char *set_device (char *device);
--- a/usr/src/grub/grub-0.95/stage2/stage1_5.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/grub/grub-0.95/stage2/stage1_5.c	Thu Sep 11 18:00:50 2008 -0700
@@ -19,10 +19,10 @@
 
 #include "shared.h"
 
-static int saved_sector = -1;
+static unsigned int saved_sector = (unsigned int)-1;
 
 static void
-disk_read_savesect_func (int sector, int offset, int length)
+disk_read_savesect_func (unsigned int sector, int offset, int length)
 {
   saved_sector = sector;
 }
@@ -45,7 +45,7 @@
       disk_read_hook = NULL;
 
       /* Sanity check: catch an internal error.  */
-      if (saved_sector == -1)
+      if (saved_sector == (unsigned int)-1)
 	{
 	  grub_printf ("internal error: the second sector of Stage 2 is unknown.");
 	  stop ();
--- a/usr/src/grub/install_menu	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/grub/install_menu	Thu Sep 11 18:00:50 2008 -0700
@@ -1,14 +1,35 @@
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
 #
 default=0
 timeout=60
+min_mem64 1024
 title Solaris Express
-	kernel /boot/platform/i86pc/kernel/unix -B install_media=cdrom
-	module /boot/x86.miniroot
+	kernel$ /boot/platform/i86pc/kernel/$ISADIR/unix -B install_media=cdrom
+	module$ /boot/$ISADIR/x86.miniroot
 title Solaris Express Serial Console ttya
-        kernel /boot/platform/i86pc/kernel/unix -B install_media=cdrom,console=ttya
-        module /boot/x86.miniroot
+        kernel$ /boot/platform/i86pc/kernel/$ISADIR/unix -B install_media=cdrom,console=ttya
+        module$ /boot/$ISADIR/x86.miniroot
 title Solaris Express Serial Console ttyb (for lx50, v60x and v65x)
-        kernel /boot/platform/i86pc/kernel/unix -B install_media=cdrom,console=ttyb
-        module /boot/x86.miniroot
+        kernel$ /boot/platform/i86pc/kernel/$ISADIR/unix -B install_media=cdrom,console=ttyb
+        module$ /boot/$ISADIR/x86.miniroot
--- a/usr/src/head/meta.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/head/meta.h	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -779,10 +780,10 @@
 extern	int		meta_getalldevs(mdsetname_t *sp, mdnamelist_t **nlpp,
 			    int check_db, md_error_t *ep);
 extern	int		meta_getvtoc(int fd, char *devname,
-			    struct vtoc *vtocbufp, int *partno,
+			    struct extvtoc *vtocbufp, int *partno,
 			    md_error_t *ep);
 extern	int		meta_setvtoc(int fd, char *devname,
-			    struct vtoc *vtocbufp, md_error_t *ep);
+			    struct extvtoc *vtocbufp, md_error_t *ep);
 extern	int		meta_setmdvtoc(int fd, char *devname,
 			    mdvtoc_t *mdvtocbufp, md_error_t *ep);
 extern	int		meta_get_names(char *drivername, mdsetname_t *sp,
--- a/usr/src/lib/libadm/common/mapfile-vers	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/libadm/common/mapfile-vers	Thu Sep 11 18:00:50 2008 -0700
@@ -19,11 +19,15 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
-#
+
+SUNW_1.2 {
+    global:
+	read_extvtoc;
+	write_extvtoc;
+} SUNW_1.1;
 
 # Due to mistakes made early in the history of this library, there are
 # no SUNW_1.1 symbols, but the version is now kept as a placeholder.
--- a/usr/src/lib/libadm/common/rdwr_vtoc.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/libadm/common/rdwr_vtoc.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -19,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 1991-1997,2002 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*LINTLIBRARY*/
 
 
@@ -37,6 +35,44 @@
 #include <sys/param.h>
 #include <sys/dkio.h>
 #include <sys/vtoc.h>
+#include <strings.h>
+#include <limits.h>
+
+/*
+ * To copy each field of vtoc individually for copying extvtoc
+ * to 32 bit vtoc and vs.
+ * Currently bootinfo and timestamp are not really supported.
+ */
+
+#define	libadm_vtoc_copy(vs, vd) \
+	{							\
+	int i;							\
+	vd->v_bootinfo[0]	= (unsigned)vs->v_bootinfo[0];	\
+	vd->v_bootinfo[1]	= (unsigned)vs->v_bootinfo[1];	\
+	vd->v_bootinfo[2]	= (unsigned)vs->v_bootinfo[2];	\
+	vd->v_sanity		= (unsigned)vs->v_sanity;	\
+	vd->v_version		= (unsigned)vs->v_version;	\
+	bcopy(vs->v_volume, vd->v_volume, LEN_DKL_VVOL);	\
+	vd->v_sectorsz		= vs->v_sectorsz;		\
+	vd->v_nparts		= vs->v_nparts;			\
+	vd->v_version		= (unsigned)vs->v_version;	\
+	for (i = 0; i < 10; i++)				\
+		vd->v_reserved[i] = (unsigned)vs->v_reserved[i];\
+	for (i = 0; i < V_NUMPAR; i++) {			\
+		vd->v_part[i].p_tag = vs->v_part[i].p_tag;	\
+		vd->v_part[i].p_flag = vs->v_part[i].p_flag;	\
+		vd->v_part[i].p_start = (unsigned)vs->v_part[i].p_start;\
+		vd->v_part[i].p_size = (unsigned)vs->v_part[i].p_size;	\
+	}								\
+	for (i = 0; i < V_NUMPAR; i++)					\
+		if ((sizeof (vd->timestamp[i]) != sizeof (vs->timestamp[i])) &&\
+		    (vs->timestamp[i] > INT32_MAX))			\
+			vd->timestamp[i] = INT32_MAX;			\
+		else							\
+			vd->timestamp[i] = (unsigned)vs->timestamp[i];	\
+	bcopy(vs->v_asciilabel, vd->v_asciilabel, LEN_DKL_ASCII);	\
+	}
+
 
 /*
  * Read VTOC - return partition number.
@@ -55,9 +91,11 @@
 			return (VT_EIO);
 		case EINVAL:
 			return (VT_EINVAL);
-		/* for disks > 1TB */
 		case ENOTSUP:
+			/* GPT labeled or disk > 1TB with no extvtoc support */
 			return (VT_ENOTSUP);
+		case EOVERFLOW:
+			return (VT_EOVERFLOW);
 		default:
 			return (VT_ERROR);
 		}
@@ -151,12 +189,171 @@
 			return (VT_EIO);
 		case EINVAL:
 			return (VT_EINVAL);
-		/* for disks > 1TB */
 		case ENOTSUP:
+			/* GPT labeled or disk > 1TB with no extvtoc support */
 			return (VT_ENOTSUP);
+		case EOVERFLOW:
+			return (VT_EOVERFLOW);
 		default:
 			return (VT_ERROR);
 		}
 	}
 	return (0);
 }
+
+int
+read_extvtoc(int fd, struct extvtoc *extvtoc)
+{
+	struct dk_cinfo		dki_info;
+	struct vtoc	oldvtoc;
+	struct vtoc *oldvtocp = &oldvtoc;
+	int ret;
+
+	/*
+	 * Read the vtoc.
+	 */
+	if (ioctl(fd, DKIOCGEXTVTOC, (caddr_t)extvtoc) == -1) {
+		switch (errno) {
+		case EIO:
+			return (VT_EIO);
+		case EINVAL:
+			return (VT_EINVAL);
+		/* for disks > 1TB */
+		case ENOTSUP:
+			return (VT_ENOTSUP);
+		case EOVERFLOW:
+			return (VT_EOVERFLOW);
+		case ENOTTY:
+
+			if ((ret = read_vtoc(fd, oldvtocp)) < 0)
+				return (ret);
+
+#ifdef _LP64
+			/*
+			 * 64-bit vtoc and extvtoc have the same field sizes
+			 * and offsets.
+			 */
+			bcopy(oldvtocp, extvtoc, sizeof (struct extvtoc));
+#else
+			bzero(extvtoc, sizeof (struct extvtoc));
+			libadm_vtoc_copy(oldvtocp, extvtoc);
+#endif
+			return (ret);
+
+
+		default:
+			return (VT_ERROR);
+		}
+	}
+
+	/*
+	 * Sanity-check the vtoc.
+	 */
+	if (extvtoc->v_sanity != VTOC_SANE) {
+		return (VT_EINVAL);
+	}
+
+	switch (extvtoc->v_version) {
+	case 0:
+		/*
+		 * For pre-version 1 vtoc keep same functionality
+		 * as read_vtoc.
+		 */
+
+		extvtoc->v_version = V_VERSION;
+		if (extvtoc->v_nparts == 0)
+			extvtoc->v_nparts = V_NUMPAR;
+		if (extvtoc->v_sectorsz == 0)
+			extvtoc->v_sectorsz = DEV_BSIZE;
+
+		break;
+
+	case V_VERSION:
+		break;
+
+	default:
+		return (VT_EINVAL);
+	}
+
+	/*
+	 * Return partition number for this file descriptor.
+	 */
+	if (ioctl(fd, DKIOCINFO, (caddr_t)&dki_info) == -1) {
+		switch (errno) {
+		case EIO:
+			return (VT_EIO);
+		case EINVAL:
+			return (VT_EINVAL);
+		default:
+			return (VT_ERROR);
+		}
+	}
+	if (dki_info.dki_partition > V_NUMPAR) {
+		return (VT_EINVAL);
+	}
+	return ((int)dki_info.dki_partition);
+}
+
+/*
+ * Write ext VTOC.
+ */
+int
+write_extvtoc(int fd, struct extvtoc *extvtoc)
+{
+	int i;
+	struct vtoc	oldvtoc;
+	struct vtoc	*oldvtocp = &oldvtoc;
+	/*
+	 * Sanity-check the vtoc
+	 */
+	if (extvtoc->v_sanity != VTOC_SANE || extvtoc->v_nparts > V_NUMPAR) {
+		return (-1);
+	}
+
+	/*
+	 * since many drivers won't allow opening a device make sure
+	 * all partitions aren't being set to zero. If all are zero then
+	 * we have no way to set them to something else
+	 */
+
+	for (i = 0; i < (int)extvtoc->v_nparts; i++)
+		if (extvtoc->v_part[i].p_size > 0)
+			break;
+	if (i == (int)extvtoc->v_nparts)
+		return (-1);
+
+	/*
+	 * Write the extvtoc
+	 */
+	if (ioctl(fd, DKIOCSEXTVTOC, (caddr_t)extvtoc) == -1) {
+		switch (errno) {
+		case EIO:
+			return (VT_EIO);
+		case EINVAL:
+			return (VT_EINVAL);
+		/* for disks > 1TB */
+		case ENOTSUP:
+			return (VT_ENOTSUP);
+		case EOVERFLOW:
+			return (VT_EOVERFLOW);
+		case ENOTTY:
+#ifdef _LP64
+			/*
+			 * 64-bit vtoc and extvtoc have the same field sizes
+			 * and offsets.
+			 */
+			bcopy(extvtoc, oldvtocp, sizeof (struct vtoc));
+#else
+			bzero(oldvtocp, sizeof (struct vtoc));
+			libadm_vtoc_copy(extvtoc, oldvtocp);
+
+#endif
+			return (write_vtoc(fd, &oldvtoc));
+
+		default:
+			return (VT_ERROR);
+		}
+	}
+
+	return (0);
+}
--- a/usr/src/lib/libdiskmgt/common/media.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/libdiskmgt/common/media.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <fcntl.h>
 #include <libdevinfo.h>
 #include <stdio.h>
@@ -421,7 +420,7 @@
 	/* sparc call */
 	if (ioctl(fd, DKIOCGGEOM, &geometry) >= 0) {
 #endif
-		struct vtoc	vtoc;
+		struct extvtoc	vtoc;
 
 		if (nvlist_add_uint64(attrs, DM_START, 0) != 0) {
 			return (ENOMEM);
@@ -456,7 +455,7 @@
 			return (ENOMEM);
 		}
 
-		if (read_vtoc(fd, &vtoc) >= 0 && vtoc.v_volume[0] != 0) {
+		if (read_extvtoc(fd, &vtoc) >= 0 && vtoc.v_volume[0] != 0) {
 			char	label[LEN_DKL_VVOL + 1];
 
 			(void) snprintf(label, sizeof (label), "%.*s",
@@ -548,9 +547,9 @@
 		struct dk_minfo minfo;
 
 		if ((loaded = media_read_info(fd, &minfo))) {
-			struct vtoc vtoc;
+			struct extvtoc vtoc;
 
-			if (read_vtoc(fd, &vtoc) >= 0) {
+			if (read_extvtoc(fd, &vtoc) >= 0) {
 				if (vtoc.v_volume[0] != NULL) {
 					if (LEN_DKL_VVOL < size) {
 						(void) strlcpy(mname,
--- a/usr/src/lib/libdiskmgt/common/slice.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/libdiskmgt/common/slice.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <fcntl.h>
 #include <libdevinfo.h>
 #include <stdio.h>
@@ -401,7 +400,7 @@
 	int		data_format = FMT_UNKNOWN;
 	int		snum = -1;
 	int		error;
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	struct dk_gpt	*efip;
 	struct dk_cinfo	dkinfo;
 	disk_t		*diskp;
@@ -419,7 +418,7 @@
 	    return (ENODEV);
 	}
 
-	if ((status = read_vtoc(fd, &vtoc)) >= 0) {
+	if ((status = read_extvtoc(fd, &vtoc)) >= 0) {
 	    data_format = FMT_VTOC;
 	} else if (status == VT_ENOTSUP && efi_alloc_and_read(fd, &efip) >= 0) {
 	    data_format = FMT_EFI;
@@ -620,7 +619,7 @@
 	int		status;
 	int		data_format = FMT_UNKNOWN;
 	int		cnt;
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	struct dk_gpt	*efip;
 	int		pos;
 	char		*media_name = NULL;
@@ -632,7 +631,7 @@
 	    return (NULL);
 	}
 
-	if ((status = read_vtoc(fd, &vtoc)) >= 0) {
+	if ((status = read_extvtoc(fd, &vtoc)) >= 0) {
 	    data_format = FMT_VTOC;
 	} else if (status == VT_ENOTSUP && efi_alloc_and_read(fd, &efip) >= 0) {
 	    data_format = FMT_EFI;
@@ -739,7 +738,7 @@
 	slice_t		*devp;
 	char		mname[MAXPATHLEN];
 	int		data_format = FMT_UNKNOWN;
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	struct dk_gpt	*efip;
 
 	/* Just check the first drive name. */
@@ -765,7 +764,7 @@
 		int	status;
 
 		if ((fd = drive_open_disk(dp, NULL, 0)) >= 0) {
-		    if ((status = read_vtoc(fd, &vtoc)) >= 0) {
+		    if ((status = read_extvtoc(fd, &vtoc)) >= 0) {
 			data_format = FMT_VTOC;
 		    } else if (status == VT_ENOTSUP &&
 			efi_alloc_and_read(fd, &efip) >= 0) {
@@ -819,7 +818,7 @@
 	int		fd;
 	int		status;
 	int		data_format = FMT_UNKNOWN;
-	struct vtoc	vtoc;
+	struct extvtoc	vtoc;
 	struct dk_gpt	*efip;
 
 	ap = diskp->aliases;
@@ -869,7 +868,7 @@
 	    return (1);
 	}
 
-	if ((status = read_vtoc(fd, &vtoc)) >= 0) {
+	if ((status = read_extvtoc(fd, &vtoc)) >= 0) {
 	    data_format = FMT_VTOC;
 	} else if (status == VT_ENOTSUP && efi_alloc_and_read(fd, &efip) >= 0) {
 	    data_format = FMT_EFI;
--- a/usr/src/lib/libefi/common/rdwr_efi.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/libefi/common/rdwr_efi.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -993,16 +992,22 @@
 
 /*
  * Input: File descriptor
- * Output: 1 if disk is >1TB OR has an EFI label, 0 otherwise.
+ * Output: 1 if disk has an EFI label, or > 2TB with no VTOC or legacy MBR.
+ * Otherwise 0.
  */
 int
 efi_type(int fd)
 {
 	struct vtoc vtoc;
+	struct extvtoc extvtoc;
 
-	if (ioctl(fd, DKIOCGVTOC, &vtoc) == -1) {
-		if (errno == ENOTSUP) {
+	if (ioctl(fd, DKIOCGEXTVTOC, &extvtoc) == -1) {
+		if (errno == ENOTSUP)
 			return (1);
+		else if (errno == ENOTTY) {
+			if (ioctl(fd, DKIOCGVTOC, &vtoc) == -1)
+				if (errno == ENOTSUP)
+					return (1);
 		}
 	}
 	return (0);
--- a/usr/src/lib/lvm/libmeta/common/meta_devstamp.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/lvm/libmeta/common/meta_devstamp.c	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -19,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 1993-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * get timestamp from device
  */
@@ -44,7 +42,7 @@
 {
 	int		fd;
 	int		partno;
-	struct vtoc	vtocbuf;
+	struct extvtoc	vtocbuf;
 	mdname_t	*np;
 
 	if ((np = metaslicename(dnp, MD_SLICE0, ep)) == NULL)
@@ -83,7 +81,7 @@
 {
 	int		fd;
 	int		partno;
-	struct vtoc	vtocbuf;
+	struct extvtoc	vtocbuf;
 	time_t		now = time(NULL);
 	mdname_t	*np;
 
@@ -121,7 +119,7 @@
 
 	if (*stamp != vtocbuf.timestamp[partno])
 		return (mddeverror(ep, MDE_CANTVERIFY_VTOC, NODEV64,
-				    np->cname));
+		    np->cname));
 
 	return (0);
 }
--- a/usr/src/lib/lvm/libmeta/common/meta_getdevs.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/lvm/libmeta/common/meta_getdevs.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * get dev_t list
  */
@@ -370,7 +369,7 @@
 meta_getvtoc(
 	int		fd,		/* fd for named device */
 	char		*devname,	/* name of device */
-	struct vtoc	*vtocbufp,	/* vtoc buffer to fill */
+	struct extvtoc	*vtocbufp,	/* vtoc buffer to fill */
 	int		*partno,	/* return partno here */
 	md_error_t	*ep
 )
@@ -378,7 +377,7 @@
 	int		part;
 
 	(void) memset(vtocbufp, 0, sizeof (*vtocbufp));
-	if ((part = read_vtoc(fd, vtocbufp)) < 0) {
+	if ((part = read_extvtoc(fd, vtocbufp)) < 0) {
 		int	err = errno;
 
 		if (ioctl(fd, MHIOCSTATUS, NULL) == 1)
@@ -400,6 +399,10 @@
 	if (part >= V_NUMPAR)
 		return (mdsyserror(ep, EINVAL, devname));
 
+	/* Slice number for *p0 partition (whole disk on x86) is 16 */
+	if (part >= V_NUMPAR)
+		return (mdsyserror(ep, EINVAL, devname));
+
 	if (partno)
 		*partno = part;
 	return (0);
@@ -454,14 +457,14 @@
 meta_setvtoc(
 	int		fd,		/* fd for named device */
 	char		*devname,	/* name of device */
-	struct vtoc	*vtocbufp,	/* vtoc buffer to fill */
+	struct extvtoc	*vtocbufp,	/* vtoc buffer to fill */
 	md_error_t	*ep
 )
 {
 	int		part;
 	int		err;
 
-	if ((part = write_vtoc(fd, vtocbufp)) < 0) {
+	if ((part = write_extvtoc(fd, vtocbufp)) < 0) {
 		if (part == VT_EINVAL)
 			err = EINVAL;
 		else if (part == VT_EIO)
--- a/usr/src/lib/lvm/libmeta/common/meta_nameinfo.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/lib/lvm/libmeta/common/meta_nameinfo.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -246,9 +247,9 @@
 char *
 getdrvnode(mdname_t *np, md_error_t *ep)
 {
-	char	*devicespath,
-	    *drvnode,
-	    *cp;
+	char	*devicespath;
+	char	*drvnode;
+	char	*cp;
 
 	if ((devicespath = metagetdevicesname(np, ep)) == NULL)
 		return (NULL);
@@ -288,9 +289,9 @@
 static void *
 meta_load_dl(mdname_t *np, md_error_t *ep)
 {
-	char	*drvnode,
-	    newpath[MAXPATHLEN],
-	    *p;
+	char	*drvnode;
+	char	newpath[MAXPATHLEN];
+	char	*p;
 	void	*cookie;
 
 	if ((drvnode = getdrvnode(np, ep)) != NULL) {
@@ -355,8 +356,8 @@
 int
 meta_match_enclosure(mdname_t *np, mdcinfo_t *mdcp, md_error_t *ep)
 {
-	meta_enclosure_e	e,
-	    ((*fptr)(mdname_t *, mdcinfo_t *,
+	meta_enclosure_e	e;
+	meta_enclosure_e	((*fptr)(mdname_t *, mdcinfo_t *,
 	    md_error_t *));
 	void			*cookie;
 
@@ -424,7 +425,7 @@
 
 static void
 meta_vtoc_to_md(
-	struct vtoc	*vp,
+	struct extvtoc	*vp,
 	mdvtoc_t	*mdvp
 )
 {
@@ -627,7 +628,7 @@
 		efi_free(gpt);
 	} else {
 		/* no error on DKIOCGGEOM, try meta_getvtoc */
-		struct vtoc	vtoc;
+		struct extvtoc	vtoc;
 
 		if (meta_getvtoc(fd, np->cname, &vtoc, &partno, ep) < 0) {
 			(void) close(fd);
@@ -660,7 +661,7 @@
 static void
 meta_mdvtoc_to_vtoc(
 	mdvtoc_t	*mdvp,
-	struct vtoc	*vp
+	struct extvtoc	*vp
 )
 {
 	uint_t		i;
@@ -668,8 +669,8 @@
 	(void) memset(&vp->v_part, '\0', sizeof (vp->v_part));
 	vp->v_nparts = (ushort_t)mdvp->nparts;
 	for (i = 0; (i < mdvp->nparts); ++i) {
-		vp->v_part[i].p_start = (daddr32_t)mdvp->parts[i].start;
-		vp->v_part[i].p_size  = (daddr32_t)mdvp->parts[i].size;
+		vp->v_part[i].p_start = mdvp->parts[i].start;
+		vp->v_part[i].p_size  = mdvp->parts[i].size;
 		vp->v_part[i].p_tag   = mdvp->parts[i].tag;
 		vp->v_part[i].p_flag  = mdvp->parts[i].flag;
 	}
@@ -704,7 +705,7 @@
 	err = ioctl(fd, DKIOCGGEOM, &geom);
 	save_errno = errno;
 	if (err == 0) {
-		struct vtoc	vtoc;
+		struct extvtoc	vtoc;
 
 		if (meta_getvtoc(fd, np->cname, &vtoc, NULL, ep) < 0) {
 			(void) close(fd);
@@ -1244,12 +1245,10 @@
 			 * Hence NO_LOG and NO_MCT
 			 */
 			err = mdmn_send_message(
-			    sp->setno,
-			    MD_MN_MSG_CLU_CHECK,
+			    sp->setno, MD_MN_MSG_CLU_CHECK,
 			    MD_MSGF_NO_MCT | MD_MSGF_STOP_ON_ERROR |
 			    MD_MSGF_NO_LOG | MD_MSGF_OVERRIDE_SUSPEND,
-			    (char *)&d, sizeof (md_isopen_t),
-			    &resp, ep);
+			    (char *)&d, sizeof (md_isopen_t), &resp, ep);
 			if (err == 0) {
 				d.isopen = resp->mmr_exitval;
 			} else {
--- a/usr/src/pkgdefs/SUNWckr/prototype_i386	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/pkgdefs/SUNWckr/prototype_i386	Thu Sep 11 18:00:50 2008 -0700
@@ -155,6 +155,7 @@
 f none kernel/fs/autofs 755 root sys
 f none kernel/fs/cachefs 755 root sys
 f none kernel/fs/ctfs 755 root sys
+f none kernel/fs/dcfs 755 root sys
 f none kernel/fs/devfs 755 root sys
 f none kernel/fs/dev 755 root sys
 f none kernel/fs/fifofs 755 root sys
@@ -364,6 +365,7 @@
 f none kernel/fs/amd64/autofs 755 root sys
 f none kernel/fs/amd64/cachefs 755 root sys
 f none kernel/fs/amd64/ctfs 755 root sys
+f none kernel/fs/amd64/dcfs 755 root sys
 f none kernel/fs/amd64/dev 755 root sys
 f none kernel/fs/amd64/devfs 755 root sys
 f none kernel/fs/amd64/fifofs 755 root sys
--- a/usr/src/pkgdefs/SUNWcsr/prototype_com	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/pkgdefs/SUNWcsr/prototype_com	Thu Sep 11 18:00:50 2008 -0700
@@ -23,8 +23,6 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
-#
 # This required package information file contains a list of package contents.
 # The 'pkgmk' command uses this file to identify the contents of a package
 # and their location on the development machine when building the package.
@@ -399,6 +397,7 @@
 f none sbin/dhcpagent 555 root bin
 f none sbin/dhcpinfo 555 root bin
 f none sbin/fdisk 555 root bin
+f none sbin/fiocompress 555 root bin
 f none sbin/hostconfig 555 root bin
 f none sbin/ifconfig 555 root bin
 f none sbin/ifparse 555 root bin
--- a/usr/src/pkgdefs/SUNWcsr/prototype_sparc	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/pkgdefs/SUNWcsr/prototype_sparc	Thu Sep 11 18:00:50 2008 -0700
@@ -19,11 +19,9 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
-#
 # This required package information file contains a list of package contents.
 # The 'pkgmk' command uses this file to identify the contents of a package
 # and their location on the development machine when building the package.
@@ -46,7 +44,6 @@
 #
 # SUNWcsr
 #
-f none sbin/fiocompress 555 root bin
 d none var/ld/sparcv9 755 root bin
 s none var/ld/64=sparcv9
 d none var/svc/manifest/platform/sun4u 755 root sys
--- a/usr/src/pkgdefs/SUNWcsu/prototype_com	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/pkgdefs/SUNWcsu/prototype_com	Thu Sep 11 18:00:50 2008 -0700
@@ -803,6 +803,7 @@
 f none usr/sbin/eeprom 2555 root sys
 s none usr/sbin/fdisk=../../sbin/fdisk
 f none usr/sbin/ff 555 root bin
+s none usr/sbin/fiocompress=../../sbin/fiocompress
 f none usr/sbin/fmthard 555 root sys
 f none usr/sbin/format 555 root bin
 f none usr/sbin/fsck 555 root bin
--- a/usr/src/pkgdefs/SUNWcsu/prototype_sparc	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/pkgdefs/SUNWcsu/prototype_sparc	Thu Sep 11 18:00:50 2008 -0700
@@ -22,8 +22,6 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
-#
 # This required package information file contains a list of package contents.
 # The 'pkgmk' command uses this file to identify the contents of a package
 # and their location on the development machine when building the package.
@@ -113,7 +111,6 @@
 f none usr/lib/sparcv9/libshare.so.1 755 root bin
 d none usr/lib/fs/nfs 755 root sys
 d none usr/lib/fs/nfs/sparcv9 755 root sys
-s none usr/sbin/fiocompress=../../sbin/fiocompress
 l none usr/sbin/prtdiag=../../usr/lib/platexec
 d none usr/sbin/sparcv9 755 root bin
 f none usr/sbin/sparcv9/add_drv 555 root sys
--- a/usr/src/uts/common/fs/pcfs/pc_dir.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/fs/pcfs/pc_dir.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/param.h>
 #include <sys/errno.h>
 #include <sys/systm.h>
@@ -135,7 +134,7 @@
 	struct vnode *vp = PCTOV(dp);
 	struct pcfs *fsp = VFSTOPCFS(vp->v_vfsp);
 	offset_t offset;
-	int	blkno;
+	daddr_t	blkno;
 	int	boff;
 	struct buf *bp = NULL;
 	struct pcdir *ep;
@@ -676,7 +675,7 @@
 
 	if ((error == 0) || (error == ENOENT)) {
 		offset_t lfn_offset = -1;
-		int	blkno;
+		daddr_t	blkno;
 		struct pcdir *direntries;
 		struct pcdir *ep;
 		int	ndirentries;
--- a/usr/src/uts/common/fs/pcfs/pc_vfsops.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/fs/pcfs/pc_vfsops.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kmem.h>
@@ -1525,7 +1524,7 @@
 	int extendedPart = -1;		/* index of extended dos partition */
 	int primaryPart = -1;		/* index of primary dos partition */
 	int bootPart = -1;		/* index of a Solaris boot partition */
-	int xnumsect = -1;		/* length of extended DOS partition */
+	uint32_t xnumsect = 0;		/* length of extended DOS partition */
 	int driveIndex;			/* computed FDISK table index */
 	daddr_t startsec;
 	len_t mediasize;
--- a/usr/src/uts/common/fs/ufs/ufs_vnops.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/fs/ufs/ufs_vnops.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -31,8 +32,6 @@
  * under license from the Regents of the University of California.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/t_lock.h>
 #include <sys/ksynch.h>
@@ -1936,13 +1935,12 @@
 			 * This is a project private ufs ioctl() to mark
 			 * the inode as that belonging to a compressed
 			 * file. This is used to mark individual
-			 * files in a miniroot archive for SPARC boot.
+			 * compressed files in a miniroot archive.
 			 * The files compressed in this manner are
 			 * automatically decompressed by the dcfs filesystem
 			 * (via an interception in ufs_lookup - see decompvp())
 			 * which is layered on top of ufs on a system running
-			 * the new archive booted SPARC system. See
-			 * uts/common/fs/dcfs for details.
+			 * from the archive. See uts/common/fs/dcfs for details.
 			 * This ioctl only marks the file as compressed - the
 			 * actual compression is done by fiocompress (a
 			 * userland utility) which invokes this ioctl().
--- a/usr/src/uts/common/io/cmlb.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/cmlb.c	Thu Sep 11 18:00:50 2008 -0700
@@ -24,8 +24,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * This module provides support for labeling operations for target
  * drivers.
@@ -175,7 +173,7 @@
 
 static struct modlmisc modlmisc = {
 	&mod_miscops,   /* Type of module */
-	"Common Labeling module %I%"
+	"Common Labeling module"
 };
 
 static struct modlinkage modlinkage = {
@@ -209,7 +207,7 @@
 static void cmlb_setup_default_geometry(struct cmlb_lun *cl, void *tg_cookie);
 static int cmlb_create_minor_nodes(struct cmlb_lun *cl);
 static int cmlb_check_update_blockcount(struct cmlb_lun *cl, void *tg_cookie);
-static int cmlb_check_efi_mbr(uchar_t *buf);
+static int cmlb_check_efi_mbr(uchar_t *buf, int *is_mbr);
 
 #if defined(__i386) || defined(__amd64)
 static int cmlb_update_fdisk_and_vtoc(struct cmlb_lun *cl, void *tg_cookie);
@@ -235,8 +233,12 @@
     int flag, void *tg_cookie);
 static int cmlb_dkio_get_vtoc(struct cmlb_lun *cl, caddr_t arg, int flag,
     void *tg_cookie);
+static int cmlb_dkio_get_extvtoc(struct cmlb_lun *cl, caddr_t arg, int flag,
+    void *tg_cookie);
 static int cmlb_dkio_set_vtoc(struct cmlb_lun *cl, dev_t dev, caddr_t arg,
     int flag, void *tg_cookie);
+static int cmlb_dkio_set_extvtoc(struct cmlb_lun *cl, dev_t dev, caddr_t arg,
+    int flag, void *tg_cookie);
 static int cmlb_dkio_get_mboot(struct cmlb_lun *cl, caddr_t arg, int flag,
     void *tg_cookie);
 static int cmlb_dkio_set_mboot(struct cmlb_lun *cl, caddr_t arg, int flag,
@@ -249,6 +251,8 @@
 static int cmlb_dkio_get_phygeom(struct cmlb_lun *cl, caddr_t  arg, int flag);
 static int cmlb_dkio_partinfo(struct cmlb_lun *cl, dev_t dev, caddr_t arg,
     int flag);
+static int cmlb_dkio_extpartinfo(struct cmlb_lun *cl, dev_t dev, caddr_t arg,
+    int flag);
 #endif
 
 static void cmlb_dbg(uint_t comp, struct cmlb_lun *cl, const char *fmt, ...);
@@ -507,7 +511,7 @@
  *
  *			3) Calculate geometry:refer to cmlb_convert_geometry()
  *			   If capacity increasing by 1 causes disks' capacity
- *			   to cross over the limits in table CHS_values,
+ *			   to cross over the limits in geometry calculation,
  *			   geometry info will change. This will raise an issue:
  *			   In case that primary VTOC label is destroyed, format
  *			   commandline can restore it via backup VTOC labels.
@@ -588,13 +592,14 @@
 	cl->cl_def_labeltype = CMLB_LABEL_VTOC;
 	cl->cl_alter_behavior = alter_behavior;
 	cl->cl_reserved = -1;
-
-	if (is_removable != 0) {
+	cl->cl_msglog_flag |= CMLB_ALLOW_2TB_WARN;
+
+	if (is_removable == 0) {
 		mutex_exit(CMLB_MUTEX(cl));
 		status = DK_TG_GETCAP(cl, &cap, tg_cookie);
 		mutex_enter(CMLB_MUTEX(cl));
-		if (status == 0 && cap > DK_MAX_BLOCKS) {
-			/* set default EFI if > 1TB */
+		if (status == 0 && cap > CMLB_EXTVTOC_LIMIT) {
+			/* set default EFI if > 2TB */
 			cl->cl_def_labeltype = CMLB_LABEL_EFI;
 		}
 	}
@@ -851,7 +856,7 @@
 		}
 	} else {
 		/* if the disk is unlabeled, don't write a devid to it */
-		if (!cl->cl_vtoc_label_is_from_media) {
+		if (cl->cl_label_from_media != CMLB_LABEL_VTOC) {
 			mutex_exit(CMLB_MUTEX(cl));
 			return (EINVAL);
 		}
@@ -934,8 +939,14 @@
 			(void) cmlb_validate_geometry((struct cmlb_lun *)cl, 0,
 			    0, tg_cookie);
 
+#if defined(_SUNOS_VTOC_16)
+		if (((cl->cl_f_geometry_is_valid == FALSE) ||
+		    (part < NDKMAP && cl->cl_solaris_size == 0)) &&
+		    (part != P0_RAW_DISK)) {
+#else
 		if ((cl->cl_f_geometry_is_valid == FALSE) ||
 		    (part < NDKMAP && cl->cl_solaris_size == 0)) {
+#endif
 			rval = EINVAL;
 		} else {
 			if (startblockp != NULL)
@@ -1024,7 +1035,6 @@
 
 	int err;
 	struct cmlb_lun *cl;
-	int status;
 
 	cl = (struct cmlb_lun *)cmlbhandle;
 
@@ -1037,58 +1047,50 @@
 	}
 
 	switch (cmd) {
-		case DKIOCSVTOC:
+		case DKIOCSEXTVTOC:
 		case DKIOCSGEOM:
 		case DKIOCSETEFI:
 		case DKIOCSMBOOT:
 			break;
+		case DKIOCSVTOC:
+#if defined(__i386) || defined(__amd64)
+		case DKIOCPARTINFO:
+#endif
+			if (cl->cl_blockcount > CMLB_OLDVTOC_LIMIT) {
+				mutex_exit(CMLB_MUTEX(cl));
+				return (EOVERFLOW);
+			}
+			break;
 		default:
-			status = cmlb_validate_geometry(cl, 1, CMLB_SILENT,
+			(void) cmlb_validate_geometry(cl, 1, CMLB_SILENT,
 			    tg_cookie);
 
-			/*
-			 * VTOC related ioctls except SVTOC/SGEOM should
-			 * fail if > 1TB disk and there is not already a VTOC
-			 * on the disk.i.e either EFI or blank
-			 *
-			 * PHYGEOM AND VIRTGEOM succeeds when disk is
-			 * EFI labeled but <1TB
-			 */
-
-			if (status == ENOTSUP &&
-			    cl->cl_f_geometry_is_valid == FALSE) {
-				switch (cmd) {
-				case DKIOCGAPART:
-				case DKIOCGGEOM:
-				case DKIOCGVTOC:
-				case DKIOCSAPART:
-				case DKIOCG_PHYGEOM:
-				case DKIOCG_VIRTGEOM:
-
+			switch (cmd) {
+			case DKIOCGVTOC:
+			case DKIOCGAPART:
+			case DKIOCSAPART:
+
+				if (cl->cl_label_from_media == CMLB_LABEL_EFI) {
+					/* GPT label on disk */
+					mutex_exit(CMLB_MUTEX(cl));
+					return (ENOTSUP);
+				} else if
+				    (cl->cl_blockcount > CMLB_OLDVTOC_LIMIT) {
+					mutex_exit(CMLB_MUTEX(cl));
+					return (EOVERFLOW);
+				}
+				break;
+
+			case DKIOCGGEOM:
+				if (cl->cl_label_from_media == CMLB_LABEL_EFI) {
+					/* GPT label on disk */
 					mutex_exit(CMLB_MUTEX(cl));
 					return (ENOTSUP);
 				}
-			} else {
-				if ((cl->cl_f_geometry_is_valid == TRUE) &&
-				    (cl->cl_solaris_size > 0)) {
-					if (cl->cl_vtoc.v_sanity != VTOC_SANE) {
-					/*
-					 * it is EFI, so return ENOTSUP for
-					 * these
-					 */
-					switch (cmd) {
-					case DKIOCGAPART:
-					case DKIOCGGEOM:
-					case DKIOCGVTOC:
-					case DKIOCSVTOC:
-					case DKIOCSAPART:
-
-						mutex_exit(CMLB_MUTEX(cl));
-						return (ENOTSUP);
-					}
-				}
+				break;
+			default:
+				break;
 			}
-		}
 	}
 
 	mutex_exit(CMLB_MUTEX(cl));
@@ -1120,6 +1122,11 @@
 		err = cmlb_dkio_get_vtoc(cl, (caddr_t)arg, flag, tg_cookie);
 		break;
 
+	case DKIOCGEXTVTOC:
+		cmlb_dbg(CMLB_TRACE, cl, "DKIOCGVTOC\n");
+		err = cmlb_dkio_get_extvtoc(cl, (caddr_t)arg, flag, tg_cookie);
+		break;
+
 	case DKIOCGETEFI:
 		cmlb_dbg(CMLB_TRACE, cl, "DKIOCGETEFI\n");
 		err = cmlb_dkio_get_efi(cl, (caddr_t)arg, flag, tg_cookie);
@@ -1136,6 +1143,12 @@
 		    tg_cookie);
 		break;
 
+	case DKIOCSEXTVTOC:
+		cmlb_dbg(CMLB_TRACE, cl, "DKIOCSVTOC\n");
+		err = cmlb_dkio_set_extvtoc(cl, dev, (caddr_t)arg, flag,
+		    tg_cookie);
+		break;
+
 	case DKIOCSETEFI:
 		cmlb_dbg(CMLB_TRACE, cl, "DKIOCSETEFI\n");
 		err = cmlb_dkio_set_efi(cl, dev, (caddr_t)arg, flag, tg_cookie);
@@ -1174,6 +1187,14 @@
 		err = ENOTTY;
 #endif
 		break;
+	case DKIOCEXTPARTINFO:
+		cmlb_dbg(CMLB_TRACE, cl, "DKIOCPARTINFO");
+#if defined(__i386) || defined(__amd64)
+		err = cmlb_dkio_extpartinfo(cl, dev, (caddr_t)arg, flag);
+#else
+		err = ENOTTY;
+#endif
+		break;
 
 	default:
 		err = ENOTTY;
@@ -1193,6 +1214,7 @@
 		case DKIOCSGEOM:
 		case DKIOCSAPART:
 		case DKIOCSVTOC:
+		case DKIOCSEXTVTOC:
 		case DKIOCSETEFI:
 			i_ddi_prop_dyn_cache_invalidate(CMLB_DEVINFO(cl),
 			    i_ddi_prop_dyn_driver_get(CMLB_DEVINFO(cl)));
@@ -1426,9 +1448,6 @@
 	int		label_error = 0;
 	diskaddr_t	capacity;
 	int		count;
-#if defined(__i386) || defined(__amd64)
-	int forced_under_1t = 0;
-#endif
 
 	ASSERT(mutex_owned(CMLB_MUTEX(cl)));
 
@@ -1450,9 +1469,10 @@
 	 * or vtoc.
 	 */
 	cl->cl_map[P0_RAW_DISK].dkl_cylno = 0;
+	cl->cl_offset[P0_RAW_DISK] = 0;
 	/*
-	 * note if capacity > uint32_max we should be using efi,
-	 * and not use p0, so the truncation does not matter.
+	 * note if capacity > int32_max(1TB) we are in 64bit environment
+	 * so no truncation happens
 	 */
 	cl->cl_map[P0_RAW_DISK].dkl_nblk  = capacity;
 #endif
@@ -1463,6 +1483,7 @@
 	 */
 	cmlb_resync_geom_caches(cl, capacity, tg_cookie);
 
+	cl->cl_label_from_media = CMLB_LABEL_UNDEF;
 	label_error = cmlb_use_efi(cl, capacity, flags, tg_cookie);
 	if (label_error == 0) {
 
@@ -1478,41 +1499,29 @@
 
 	/* NO EFI label found */
 
-	if (capacity > DK_MAX_BLOCKS) {
+	if (capacity > CMLB_EXTVTOC_LIMIT) {
 		if (label_error == ESRCH) {
 			/*
-			 * they've configured a LUN over 1TB, but used
+			 * they've configured a LUN over 2TB, but used
 			 * format.dat to restrict format's view of the
-			 * capacity to be under 1TB
+			 * capacity to be under 2TB in some earlier Solaris
+			 * release.
 			 */
-			/* i.e > 1Tb with a VTOC < 1TB */
-			if (!(flags & CMLB_SILENT)) {
-				cmlb_log(CMLB_DEVINFO(cl), CMLB_LABEL(cl),
-				    CE_WARN, "is >1TB and has a VTOC label: "
-				    "use format(1M) to either decrease the");
+			/* i.e > 2TB with a VTOC < 2TB */
+			if (!(flags & CMLB_SILENT) &&
+			    (cl->cl_msglog_flag & CMLB_ALLOW_2TB_WARN)) {
 
 				cmlb_log(CMLB_DEVINFO(cl), CMLB_LABEL(cl),
-				    CE_NOTE, "size to be < 1TB or relabel the "
-				    "disk with an EFI label");
-#if defined(__i386) || defined(__amd64)
-				forced_under_1t = 1;
-#endif
+				    CE_NOTE, "!Disk (%s%d) is limited to 2 TB "
+				    "due to VTOC label. To use the full "
+				    "capacity of the disk, use format(1M) to "
+				    "relabel the disk with EFI/GPT label.\n",
+				    CMLB_LABEL(cl),
+				    ddi_get_instance(CMLB_DEVINFO(cl)));
+
+				cl->cl_msglog_flag &= ~CMLB_ALLOW_2TB_WARN;
 			}
 		} else {
-			/* unlabeled disk over 1TB */
-#if defined(__i386) || defined(__amd64)
-
-			/*
-			 * Refer to comments on off-by-1 at the head of the file
-			 * A 1TB disk was treated as (1T - 512)B in the past,
-			 * thus, it might have valid solaris partition. We
-			 * will return ENOTSUP later only if this disk has no
-			 * valid solaris partition.
-			 */
-			if (!(cl->cl_alter_behavior & CMLB_OFF_BY_ONE) ||
-			    (cl->cl_sys_blocksize != cl->cl_tgt_blocksize) ||
-			    (capacity - 1 > DK_MAX_BLOCKS))
-#endif
 				return (ENOTSUP);
 		}
 	}
@@ -1545,17 +1554,6 @@
 		}
 
 		if (cl->cl_solaris_size <= DK_LABEL_LOC) {
-
-#if defined(__i386) || defined(__amd64)
-			/*
-			 * Refer to comments on off-by-1 at the head of the file
-			 * This is for 1TB disk only. Since that there is no
-			 * solaris partitions, return ENOTSUP as we do for
-			 * >1TB disk.
-			 */
-			if (cl->cl_blockcount > DK_MAX_BLOCKS)
-				return (ENOTSUP);
-#endif
 			/*
 			 * Found fdisk table but no Solaris partition entry,
 			 * so don't call cmlb_uselabel() and don't create
@@ -1568,27 +1566,6 @@
 
 		label_addr = (daddr_t)(cl->cl_solaris_offset + DK_LABEL_LOC);
 
-#if defined(__i386) || defined(__amd64)
-		/*
-		 * Refer to comments on off-by-1 at the head of the file
-		 * Now, this 1TB disk has valid solaris partition. It
-		 * must be created by previous sd driver, we have to
-		 * treat it as (1T-512)B.
-		 */
-		if ((cl->cl_blockcount > DK_MAX_BLOCKS) &&
-		    (forced_under_1t != 1)) {
-			/*
-			 * Refer to cmlb_read_fdisk, when there is no
-			 * fdisk partition table, cl_solaris_size is
-			 * set to disk's capacity. In this case, we
-			 * need to adjust it
-			 */
-			if (cl->cl_solaris_size > DK_MAX_BLOCKS)
-				cl->cl_solaris_size = DK_MAX_BLOCKS;
-			cmlb_resync_geom_caches(cl, DK_MAX_BLOCKS, tg_cookie);
-		}
-#endif
-
 		buffer_size = sizeof (struct dk_label);
 
 		cmlb_dbg(CMLB_TRACE, cl, "cmlb_validate_geometry: "
@@ -1613,7 +1590,7 @@
 			    CMLB_LABEL_IS_VALID) {
 				label_error = EINVAL;
 			} else
-				cl->cl_vtoc_label_is_from_media = 1;
+				cl->cl_label_from_media = CMLB_LABEL_VTOC;
 			break;
 		case EACCES:
 			label_error = EACCES;
@@ -1656,7 +1633,7 @@
 	 * we set it to an entirely bogus value.
 	 */
 	for (count = 0; count < FD_NUMPART; count++) {
-		cl->cl_map[FDISK_P1 + count].dkl_cylno = -1;
+		cl->cl_map[FDISK_P1 + count].dkl_cylno = UINT16_MAX;
 		cl->cl_map[FDISK_P1 + count].dkl_nblk =
 		    cl->cl_fmap[count].fmap_nblk;
 
@@ -1684,16 +1661,6 @@
 
 #if defined(_SUNOS_VTOC_16)
 /*
- * Macro: MAX_BLKS
- *
- *	This macro is used for table entries where we need to have the largest
- *	possible sector value for that head & SPT (sectors per track)
- *	combination.  Other entries for some smaller disk sizes are set by
- *	convention to match those used by X86 BIOS usage.
- */
-#define	MAX_BLKS(heads, spt)	UINT16_MAX * heads * spt, heads, spt
-
-/*
  *    Function: cmlb_convert_geometry
  *
  * Description: Convert physical geometry into a dk_geom structure. In
@@ -1705,18 +1672,6 @@
 static void
 cmlb_convert_geometry(diskaddr_t capacity, struct dk_geom *cl_g)
 {
-	int i;
-	static const struct chs_values {
-		uint_t max_cap;		/* Max Capacity for this HS. */
-		uint_t nhead;		/* Heads to use. */
-		uint_t nsect;		/* SPT to use. */
-	} CHS_values[] = {
-		{0x00200000,  64, 32},		/* 1GB or smaller disk. */
-		{0x01000000, 128, 32},		/* 8GB or smaller disk. */
-		{MAX_BLKS(255,  63)},		/* 502.02GB or smaller disk. */
-		{MAX_BLKS(255, 126)},		/* .98TB or smaller disk. */
-		{DK_MAX_BLOCKS, 255, 189}	/* Max size is just under 1TB */
-	};
 
 	/* Unlabeled SCSI floppy device */
 	if (capacity <= 0x1000) {
@@ -1727,26 +1682,50 @@
 	}
 
 	/*
-	 * For all devices we calculate cylinders using the
-	 * heads and sectors we assign based on capacity of the
-	 * device.  The table is designed to be compatible with the
-	 * way other operating systems lay out fdisk tables for X86
-	 * and to insure that the cylinders never exceed 65535 to
-	 * prevent problems with X86 ioctls that report geometry.
-	 * We use SPT that are multiples of 63, since other OSes that
-	 * are not limited to 16-bits for cylinders stop at 63 SPT
-	 * we make do by using multiples of 63 SPT.
+	 * For all devices we calculate cylinders using the heads and sectors
+	 * we assign based on capacity of the device.  The algorithm is
+	 * designed to be compatible with the way other operating systems
+	 * lay out fdisk tables for X86 and to insure that the cylinders never
+	 * exceed 65535 to prevent problems with X86 ioctls that report
+	 * geometry.
+	 * For some smaller disk sizes we report geometry that matches those
+	 * used by X86 BIOS usage. For larger disks, we use SPT that are
+	 * multiples of 63, since other OSes that are not limited to 16-bits
+	 * for cylinders stop at 63 SPT we make do by using multiples of 63 SPT.
+	 *
+	 * The following table (in order) illustrates some end result
+	 * calculations:
+	 *
+	 * Maximum number of blocks 		nhead	nsect
 	 *
-	 * Note than capacities greater than or equal to 1TB will simply
-	 * get the largest geometry from the table. This should be okay
-	 * since disks this large shouldn't be using CHS values anyway.
+	 * 2097152 (1GB)			64	32
+	 * 16777216 (8GB)			128	32
+	 * 1052819775 (502.02GB)		255  	63
+	 * 2105639550 (0.98TB)			255	126
+	 * 3158459325 (1.47TB)			255  	189
+	 * 4211279100 (1.96TB)			255  	252
+	 * 5264098875 (2.45TB)			255  	315
+	 * ...
 	 */
-	for (i = 0; CHS_values[i].max_cap < capacity &&
-	    CHS_values[i].max_cap != DK_MAX_BLOCKS; i++)
-		;
-
-	cl_g->dkg_nhead = CHS_values[i].nhead;
-	cl_g->dkg_nsect = CHS_values[i].nsect;
+
+	if (capacity <= 0x200000) {
+		cl_g->dkg_nhead = 64;
+		cl_g->dkg_nsect = 32;
+	} else if (capacity <= 0x01000000) {
+		cl_g->dkg_nhead = 128;
+		cl_g->dkg_nsect = 32;
+	} else {
+		cl_g->dkg_nhead = 255;
+
+		/* make nsect be smallest multiple of 63 */
+		cl_g->dkg_nsect = ((capacity +
+		    (UINT16_MAX * 255 * 63) - 1) /
+		    (UINT16_MAX * 255 * 63)) * 63;
+
+		if (cl_g->dkg_nsect == 0)
+			cl_g->dkg_nsect = (UINT16_MAX / 63) * 63;
+	}
+
 }
 #endif
 
@@ -2011,8 +1990,8 @@
 	solaris_size   = 0;
 
 	for (fdp = fdisk, i = 0; i < FD_NUMPART; i++, fdp++) {
-		int	relsect;
-		int	numsect;
+		uint32_t relsect;
+		uint32_t numsect;
 
 		if (fdp->numsect == 0) {
 			cl->cl_fmap[i].fmap_start = 0;
@@ -2144,15 +2123,21 @@
  */
 
 static int
-cmlb_check_efi_mbr(uchar_t *buf)
+cmlb_check_efi_mbr(uchar_t *buf, int *is_mbr)
 {
 	struct ipart	*fdp;
 	struct mboot	*mbp = (struct mboot *)buf;
 	struct ipart	fdisk[FD_NUMPART];
 	int		i;
 
-	if (LE_16(mbp->signature) != MBB_MAGIC)
+	if (is_mbr != NULL)
+		*is_mbr = TRUE;
+
+	if (LE_16(mbp->signature) != MBB_MAGIC) {
+		if (is_mbr != NULL)
+			is_mbr = FALSE;
 		return (TRUE);
+	}
 
 	bcopy(&mbp->parts[0], fdisk, sizeof (fdisk));
 
@@ -2179,6 +2164,9 @@
 	diskaddr_t	alternate_lba;
 	int		iofailed = 0;
 	struct uuid	uuid_type_reserved = EFI_RESERVED;
+#if defined(_FIRMWARE_NEEDS_FDISK)
+		int 		is_mbr;
+#endif
 
 	ASSERT(mutex_owned(CMLB_MUTEX(cl)));
 
@@ -2195,7 +2183,7 @@
 
 	buf = kmem_zalloc(EFI_MIN_ARRAY_SIZE, KM_SLEEP);
 
-	rval = DK_TG_READ(cl, buf, 0, lbasize, tg_cookie);
+	rval = DK_TG_READ(cl, buf,  0, lbasize, tg_cookie);
 	if (rval) {
 		iofailed = 1;
 		goto done_err;
@@ -2206,11 +2194,22 @@
 		goto done_err;
 	}
 
-	if (cmlb_check_efi_mbr(buf) == FALSE) {
+#if defined(_FIRMWARE_NEEDS_FDISK)
+	if (cmlb_check_efi_mbr(buf, &is_mbr) == FALSE) {
+		if (is_mbr == TRUE)
+			rval = ESRCH;
+		else
+			rval = EINVAL;
+		goto done_err;
+	}
+#else
+	if (cmlb_check_efi_mbr(buf, NULL) == FALSE) {
 		rval = EINVAL;
 		goto done_err;
 	}
 
+#endif
+
 	rval = DK_TG_READ(cl, buf, 1, lbasize, tg_cookie);
 	if (rval) {
 		iofailed = 1;
@@ -2321,6 +2320,7 @@
 	}
 	cl->cl_solaris_offset = 0;
 	cl->cl_solaris_size = capacity;
+	cl->cl_label_from_media = CMLB_LABEL_EFI;
 	cl->cl_f_geometry_is_valid = TRUE;
 
 	/* clear the vtoc label */
@@ -2341,7 +2341,7 @@
 	 * valid because cmlb_prop_op will now fail, which in turn
 	 * causes things like opens and stats on the partition to fail.
 	 */
-	if ((capacity > DK_MAX_BLOCKS) && (rval != ESRCH) && !iofailed) {
+	if ((capacity > CMLB_EXTVTOC_LIMIT) && (rval != ESRCH) && !iofailed) {
 		cl->cl_f_geometry_is_valid = FALSE;
 	}
 	return (rval);
@@ -2376,7 +2376,7 @@
 	int		label_error = CMLB_LABEL_IS_VALID;
 	int		i;
 	diskaddr_t	label_capacity;
-	int		part_end;
+	uint32_t	part_end;
 	diskaddr_t	track_capacity;
 #if defined(_SUNOS_VTOC_16)
 	struct	dkl_partition	*vpartp;
@@ -2699,7 +2699,7 @@
 			cl->cl_g.dkg_nhead = 64;
 			cl->cl_g.dkg_nsect = 32;
 			cl->cl_g.dkg_ncyl = cl->cl_blockcount / (64 * 32);
-			cl->cl_solaris_size = cl->cl_g.dkg_ncyl *
+			cl->cl_solaris_size = (diskaddr_t)cl->cl_g.dkg_ncyl *
 			    cl->cl_g.dkg_nhead * cl->cl_g.dkg_nsect;
 		} else {
 			cl->cl_g.dkg_ncyl  = 1;
@@ -2731,7 +2731,8 @@
 		}
 
 		cl->cl_solaris_size =
-		    cl->cl_g.dkg_ncyl * cl->cl_g.dkg_nhead * cl->cl_g.dkg_nsect;
+		    (diskaddr_t)cl->cl_g.dkg_ncyl * cl->cl_g.dkg_nhead *
+		    cl->cl_g.dkg_nsect;
 
 	}
 
@@ -2895,7 +2896,7 @@
 	cl->cl_vtoc.v_sanity  = VTOC_SANE;
 
 	cl->cl_f_geometry_is_valid = TRUE;
-	cl->cl_vtoc_label_is_from_media = 0;
+	cl->cl_label_from_media = CMLB_LABEL_UNDEF;
 
 	cmlb_dbg(CMLB_INFO,  cl,
 	    "cmlb_build_default_label: Default label created: "
@@ -2980,7 +2981,7 @@
 		 * do not really assume a default label for the device.
 		 * dad driver utilizes this.
 		 */
-		if (cl->cl_blockcount <= DK_MAX_BLOCKS) {
+		if (cl->cl_blockcount <= CMLB_OLDVTOC_LIMIT) {
 			cmlb_setup_default_geometry(cl, tg_cookie);
 			rval = 0;
 		}
@@ -3210,7 +3211,7 @@
 	_NOTE(DATA_READABLE_WITHOUT_LOCK(cmlb_lun::cl_solaris_size))
 	mutex_enter(CMLB_MUTEX(cl));
 
-	if (cl->cl_blockcount > DK_MAX_BLOCKS) {
+	if (cl->cl_blockcount > CMLB_OLDVTOC_LIMIT) {
 		mutex_exit(CMLB_MUTEX(cl));
 		return (ENOTSUP);
 	}
@@ -3306,6 +3307,11 @@
 	int		rval = 0;
 
 	mutex_enter(CMLB_MUTEX(cl));
+	if (cl->cl_blockcount > CMLB_OLDVTOC_LIMIT) {
+		mutex_exit(CMLB_MUTEX(cl));
+		return (EOVERFLOW);
+	}
+
 	rval = cmlb_validate_geometry(cl, 1, 0, tg_cookie);
 
 #if defined(_SUNOS_VTOC_8)
@@ -3316,7 +3322,7 @@
 		 * really assume a default label for the device.
 		 * dad driver utilizes this.
 		 */
-		if (cl->cl_blockcount <= DK_MAX_BLOCKS) {
+		if (cl->cl_blockcount <= CMLB_OLDVTOC_LIMIT) {
 			cmlb_setup_default_geometry(cl, tg_cookie);
 			rval = 0;
 		}
@@ -3403,6 +3409,85 @@
 	return (rval);
 }
 
+
+/*
+ *    Function: cmlb_dkio_get_extvtoc
+ */
+static int
+cmlb_dkio_get_extvtoc(struct cmlb_lun *cl, caddr_t arg, int flag,
+    void *tg_cookie)
+{
+	struct extvtoc	ext_vtoc;
+#if defined(_SUNOS_VTOC_8)
+	struct vtoc	user_vtoc;
+#endif	/* defined(_SUNOS_VTOC_8) */
+	int		rval = 0;
+
+	bzero(&ext_vtoc, sizeof (struct extvtoc));
+	mutex_enter(CMLB_MUTEX(cl));
+	rval = cmlb_validate_geometry(cl, 1, 0, tg_cookie);
+
+#if defined(_SUNOS_VTOC_8)
+	if (rval == EINVAL &&
+	    (cl->cl_alter_behavior & CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8)) {
+		/*
+		 * This is to return a default label even when we do not
+		 * really assume a default label for the device.
+		 * dad driver utilizes this.
+		 */
+		if (cl->cl_blockcount <= CMLB_OLDVTOC_LIMIT) {
+			cmlb_setup_default_geometry(cl, tg_cookie);
+			rval = 0;
+		}
+	}
+#endif
+	if (rval) {
+		mutex_exit(CMLB_MUTEX(cl));
+		return (rval);
+	}
+
+#if defined(_SUNOS_VTOC_8)
+	cmlb_build_user_vtoc(cl, &user_vtoc);
+	mutex_exit(CMLB_MUTEX(cl));
+
+	/*
+	 * Checking callers data model does not make much sense here
+	 * since extvtoc will always be equivalent to 64bit vtoc.
+	 * What is important is whether the kernel is in 32 or 64 bit
+	 */
+
+#ifdef _LP64
+		if (ddi_copyout(&user_vtoc, (void *)arg,
+		    sizeof (struct extvtoc), flag)) {
+			return (EFAULT);
+		}
+#else
+		vtoc32tovtoc(user_vtoc, ext_vtoc);
+		if (ddi_copyout(&ext_vtoc, (void *)arg,
+		    sizeof (struct extvtoc), flag)) {
+			return (EFAULT);
+		}
+#endif
+
+#elif defined(_SUNOS_VTOC_16)
+	mutex_exit(CMLB_MUTEX(cl));
+
+	/*
+	 * The cl_vtoc structure is a "struct dk_vtoc"  which is always
+	 * 32-bit to maintain compatibility with existing on-disk
+	 * structures.  Thus, we need to convert the structure when copying
+	 * it out to extvtoc
+	 */
+	vtoc32tovtoc(cl->cl_vtoc, ext_vtoc);
+
+	if (ddi_copyout(&ext_vtoc, (void *)arg, sizeof (struct extvtoc), flag))
+		return (EFAULT);
+#else
+#error "No VTOC format defined."
+#endif
+
+	return (rval);
+}
 static int
 cmlb_dkio_get_efi(struct cmlb_lun *cl, caddr_t arg, int flag, void *tg_cookie)
 {
@@ -3455,7 +3540,7 @@
 	struct dk_map2		*lpart;
 	struct dk_map		*lmap;
 	struct partition	*vpart;
-	int			nblks;
+	uint32_t		nblks;
 	int			i;
 
 	ASSERT(mutex_owned(CMLB_MUTEX(cl)));
@@ -3631,9 +3716,10 @@
 #endif /* _MULTI_DATAMODEL */
 
 	mutex_enter(CMLB_MUTEX(cl));
-	if (cl->cl_blockcount > DK_MAX_BLOCKS) {
+
+	if (cl->cl_blockcount > CMLB_OLDVTOC_LIMIT) {
 		mutex_exit(CMLB_MUTEX(cl));
-		return (ENOTSUP);
+		return (EOVERFLOW);
 	}
 
 #if defined(__i386) || defined(__amd64)
@@ -3667,12 +3753,81 @@
 				    "cmlb_dkio_set_vtoc: "
 				    "Failed validate geometry\n");
 			}
+			cl->cl_msglog_flag |= CMLB_ALLOW_2TB_WARN;
 		}
 	}
 	mutex_exit(CMLB_MUTEX(cl));
 	return (rval);
 }
 
+/*
+ *    Function: cmlb_dkio_set_extvtoc
+ */
+static int
+cmlb_dkio_set_extvtoc(struct cmlb_lun *cl, dev_t dev, caddr_t arg, int flag,
+    void *tg_cookie)
+{
+	int		rval = 0;
+	struct vtoc	user_vtoc;
+
+	/*
+	 * Checking callers data model does not make much sense here
+	 * since extvtoc will always be equivalent to 64bit vtoc.
+	 * What is important is whether the kernel is in 32 or 64 bit
+	 */
+
+#ifdef _LP64
+	if (ddi_copyin((const void *)arg, &user_vtoc,
+		    sizeof (struct extvtoc), flag)) {
+			return (EFAULT);
+	}
+#else
+	struct	extvtoc	user_extvtoc;
+	if (ddi_copyin((const void *)arg, &user_extvtoc,
+		    sizeof (struct extvtoc), flag)) {
+			return (EFAULT);
+	}
+
+	vtoctovtoc32(user_extvtoc, user_vtoc);
+#endif
+
+	mutex_enter(CMLB_MUTEX(cl));
+#if defined(__i386) || defined(__amd64)
+	if (cl->cl_tgt_blocksize != cl->cl_sys_blocksize) {
+		mutex_exit(CMLB_MUTEX(cl));
+		return (EINVAL);
+	}
+#endif
+
+	if (cl->cl_g.dkg_ncyl == 0) {
+		mutex_exit(CMLB_MUTEX(cl));
+		return (EINVAL);
+	}
+
+	mutex_exit(CMLB_MUTEX(cl));
+	cmlb_clear_efi(cl, tg_cookie);
+	ddi_remove_minor_node(CMLB_DEVINFO(cl), "wd");
+	ddi_remove_minor_node(CMLB_DEVINFO(cl), "wd,raw");
+	(void) ddi_create_minor_node(CMLB_DEVINFO(cl), "h",
+	    S_IFBLK, (CMLBUNIT(dev) << CMLBUNIT_SHIFT) | WD_NODE,
+	    cl->cl_node_type, NULL);
+	(void) ddi_create_minor_node(CMLB_DEVINFO(cl), "h,raw",
+	    S_IFCHR, (CMLBUNIT(dev) << CMLBUNIT_SHIFT) | WD_NODE,
+	    cl->cl_node_type, NULL);
+	mutex_enter(CMLB_MUTEX(cl));
+
+	if ((rval = cmlb_build_label_vtoc(cl, &user_vtoc)) == 0) {
+		if ((rval = cmlb_write_label(cl, tg_cookie)) == 0) {
+			if (cmlb_validate_geometry(cl, 1, 0, tg_cookie) != 0) {
+				cmlb_dbg(CMLB_ERROR, cl,
+				    "cmlb_dkio_set_vtoc: "
+				    "Failed validate geometry\n");
+			}
+		}
+	}
+	mutex_exit(CMLB_MUTEX(cl));
+	return (rval);
+}
 
 /*
  *    Function: cmlb_build_label_vtoc
@@ -3692,7 +3847,7 @@
 {
 	struct dk_map		*lmap;
 	struct partition	*vpart;
-	int			nblks;
+	uint_t			nblks;
 #if defined(_SUNOS_VTOC_8)
 	int			ncyl;
 	struct dk_map2		*lpart;
@@ -3720,16 +3875,16 @@
 #if defined(_SUNOS_VTOC_8)
 	vpart = user_vtoc->v_part;
 	for (i = 0; i < V_NUMPAR; i++) {
-		if ((vpart->p_start % nblks) != 0) {
+		if (((unsigned)vpart->p_start % nblks) != 0) {
 			cmlb_dbg(CMLB_INFO,  cl,
 			    "cmlb_build_label_vtoc: p_start not multiply of"
 			    "nblks part %d p_start %d nblks %d\n", i,
 			    vpart->p_start, nblks);
 			return (EINVAL);
 		}
-		ncyl = vpart->p_start / nblks;
-		ncyl += vpart->p_size / nblks;
-		if ((vpart->p_size % nblks) != 0) {
+		ncyl = (unsigned)vpart->p_start / nblks;
+		ncyl += (unsigned)vpart->p_size / nblks;
+		if (((unsigned)vpart->p_size % nblks) != 0) {
 			ncyl++;
 		}
 		if (ncyl > (int)cl->cl_g.dkg_ncyl) {
@@ -3763,8 +3918,8 @@
 	vpart = user_vtoc->v_part;
 
 	for (i = 0; i < (int)user_vtoc->v_nparts; i++, lmap++, vpart++) {
-		lmap->dkl_cylno = vpart->p_start / nblks;
-		lmap->dkl_nblk = vpart->p_size;
+		lmap->dkl_cylno = (unsigned)vpart->p_start / nblks;
+		lmap->dkl_nblk = (unsigned)vpart->p_size;
 	}
 
 #elif defined(_SUNOS_VTOC_8)
@@ -3795,8 +3950,8 @@
 	for (i = 0; i < (int)user_vtoc->v_nparts; i++) {
 		lpart->p_tag  = vpart->p_tag;
 		lpart->p_flag = vpart->p_flag;
-		lmap->dkl_cylno = vpart->p_start / nblks;
-		lmap->dkl_nblk = vpart->p_size;
+		lmap->dkl_cylno = (unsigned)vpart->p_start / nblks;
+		lmap->dkl_nblk = (unsigned)vpart->p_size;
 
 		lmap++;
 		lpart++;
@@ -3934,7 +4089,7 @@
 {
 	uint_t	label_addr;
 	int	sec;
-	int	blk;
+	diskaddr_t	blk;
 	int	head;
 	int	cyl;
 	int	rval;
@@ -3971,7 +4126,7 @@
 	 * write past the last cylinder.
 	 */
 	for (sec = 1; ((sec < 5 * 2 + 1) && (sec < dkl->dkl_nsect)); sec += 2) {
-		blk = (daddr_t)(
+		blk = (diskaddr_t)(
 		    (cyl * ((dkl->dkl_nhead * dkl->dkl_nsect) - dkl->dkl_apc)) +
 		    (head * dkl->dkl_nsect) + sec);
 #if defined(__i386) || defined(__amd64)
@@ -3980,7 +4135,7 @@
 		rval = DK_TG_WRITE(cl, dkl, blk, cl->cl_sys_blocksize,
 		    tg_cookie);
 		cmlb_dbg(CMLB_INFO,  cl,
-		"cmlb_set_vtoc: wrote backup label %d\n", blk);
+		"cmlb_set_vtoc: wrote backup label %llx\n", blk);
 		if (rval != 0) {
 			goto exit;
 		}
@@ -4135,7 +4290,7 @@
 		if (cl->cl_vtoc.v_sanity == VTOC_SANE) {
 			cmlb_dbg(CMLB_TRACE,  cl,
 			    "cmlb_dkio_set_efi: CLEAR VTOC\n");
-			if (cl->cl_vtoc_label_is_from_media)
+			if (cl->cl_label_from_media == CMLB_LABEL_VTOC)
 				cmlb_clear_vtoc(cl, tg_cookie);
 			bzero(&cl->cl_vtoc, sizeof (struct dk_vtoc));
 			mutex_exit(CMLB_MUTEX(cl));
@@ -4320,10 +4475,11 @@
 		 * mboot has been written successfully.
 		 * set up the default geometry and VTOC
 		 */
-		if (cl->cl_blockcount <= DK_MAX_BLOCKS)
+		if (cl->cl_blockcount <= CMLB_EXTVTOC_LIMIT)
 			cmlb_setup_default_geometry(cl, tg_cookie);
 	}
 #endif
+	cl->cl_msglog_flag |= CMLB_ALLOW_2TB_WARN;
 	mutex_exit(CMLB_MUTEX(cl));
 	kmem_free(mboot, (size_t)(sizeof (struct mboot)));
 	return (rval);
@@ -4569,7 +4725,7 @@
 	 * we set it to an entirely bogus value.
 	 */
 	for (count = 0; count < FD_NUMPART; count++) {
-		cl->cl_map[FDISK_P1 + count].dkl_cylno = -1;
+		cl->cl_map[FDISK_P1 + count].dkl_cylno = UINT32_MAX;
 		cl->cl_map[FDISK_P1 + count].dkl_nblk =
 		    cl->cl_fmap[count].fmap_nblk;
 		cl->cl_offset[FDISK_P1 + count] =
@@ -4770,6 +4926,35 @@
 	}
 	return (err);
 }
+static int
+cmlb_dkio_extpartinfo(struct cmlb_lun *cl, dev_t dev, caddr_t  arg, int flag)
+{
+	int err = 0;
+
+	/*
+	 * Return parameters describing the selected disk slice.
+	 * Note: this ioctl is for the intel platform only
+	 */
+	int part;
+
+	part = CMLBPART(dev);
+
+	mutex_enter(CMLB_MUTEX(cl));
+	/* don't check cl_solaris_size for pN */
+	if (part < P0_RAW_DISK && cl->cl_solaris_size == 0) {
+		err = EIO;
+		mutex_exit(CMLB_MUTEX(cl));
+	} else {
+		struct extpart_info p;
+
+		p.p_start = (diskaddr_t)cl->cl_offset[part];
+		p.p_length = (diskaddr_t)cl->cl_map[part].dkl_nblk;
+		mutex_exit(CMLB_MUTEX(cl));
+		if (ddi_copyout(&p, (void *)arg, sizeof (p), flag))
+			err = EFAULT;
+	}
+	return (err);
+}
 #endif
 
 int
--- a/usr/src/uts/common/io/lvm/md/md_ioctl.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/lvm/md/md_ioctl.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Driver for Virtual Disk.
  */
@@ -3587,10 +3586,10 @@
 				vtoc32tovtoc((*vt32), (*vtoc));
 			}
 			if (un->c.un_flag & MD_LABELED)
-				vtoc->v_part[0].p_start = 0;
+				vtoc->v_part[0].p_start = 0ULL;
 			else
-				vtoc->v_part[0].p_start =
-				    un->c.un_nhead * un->c.un_nsect;
+				vtoc->v_part[0].p_start = (diskaddr_t)
+				    (un->c.un_nhead * un->c.un_nsect);
 			vtoc->v_part[0].p_size = un->c.un_total_blocks;
 			vtoc->v_version = V_VERSION;
 			vtoc->v_sectorsz = DEV_BSIZE;
@@ -3607,9 +3606,10 @@
 	vtoc->v_version = V_VERSION;
 	vtoc->v_sectorsz = DEV_BSIZE;
 	if (un->c.un_flag & MD_LABELED)
-		vtoc->v_part[0].p_start = 0;
+		vtoc->v_part[0].p_start = 0ULL;
 	else
-		vtoc->v_part[0].p_start = un->c.un_nhead * un->c.un_nsect;
+		vtoc->v_part[0].p_start = (diskaddr_t)(un->c.un_nhead *
+		    un->c.un_nsect);
 	vtoc->v_part[0].p_size = un->c.un_total_blocks;
 }
 
@@ -3623,7 +3623,7 @@
 	mddb_recid_t		recids[3];
 	mddb_recstatus_t	status;
 	caddr_t			v;
-	daddr_t			sb;
+	diskaddr_t		sb;
 
 	/*
 	 * Sanity-check the vtoc
@@ -3641,19 +3641,20 @@
 	for (i = 0; i < V_NUMPAR; i++, vpart++) {
 		if (i == 0) {
 			if (un->c.un_flag & MD_LABELED)
-				sb = 0;
+				sb = 0ULL;
 			else
-				sb = un->c.un_nhead * un->c.un_nsect;
+				sb = (diskaddr_t)(un->c.un_nhead *
+				    un->c.un_nsect);
 			if (vpart->p_start != sb)
 				return (EINVAL);
-			if (vpart->p_size != (long)un->c.un_total_blocks)
+			if (vpart->p_size != un->c.un_total_blocks)
 				return (EINVAL);
 			continue;
 		}
 		/* all other partitions must be zero */
-		if (vpart->p_start != 0)
+		if (vpart->p_start != 0ULL)
 			return (EINVAL);
-		if (vpart->p_size != 0)
+		if (vpart->p_size != 0ULL)
 			return (EINVAL);
 	}
 
@@ -3706,6 +3707,161 @@
 	return (0);
 }
 
+void
+md_get_extvtoc(md_unit_t *un, struct extvtoc *extvtoc)
+{
+	caddr_t			v;
+	mddb_recstatus_t	status;
+	struct vtoc32		*vt32;
+	struct vtoc		*vtoc;
+
+	/*
+	 * Return extvtoc structure fields in the provided VTOC area, addressed
+	 * by *extvtoc.
+	 *
+	 */
+
+	bzero((caddr_t)extvtoc, sizeof (struct extvtoc));
+	if (un->c.un_vtoc_id) {
+		status = mddb_getrecstatus(un->c.un_vtoc_id);
+		if (status == MDDB_OK) {
+			v = mddb_getrecaddr(un->c.un_vtoc_id);
+			if (un->c.un_flag & MD_EFILABEL) {
+				bcopy(v, (caddr_t)&(extvtoc->v_volume),
+				    LEN_DKL_VVOL);
+			} else {
+				/*
+				 * if this seems to be a sane vtoc,
+				 * just copy it ...
+				 */
+				if (((struct vtoc *)v)->v_sanity == VTOC_SANE) {
+					vtoc = (struct vtoc *)v;
+					vtoctoextvtoc((*vtoc), (*extvtoc));
+				} else {
+					/* assume a vtoc32 was stored here */
+					vt32 = (struct vtoc32 *)v;
+					vtoc32toextvtoc((*vt32), (*extvtoc));
+				}
+			}
+		} else {
+			un->c.un_vtoc_id = 0;
+			mddb_commitrec_wrapper(un->c.un_record_id);
+		}
+	}
+
+	extvtoc->v_sanity = VTOC_SANE;
+	extvtoc->v_nparts = 1;
+	extvtoc->v_version = V_VERSION;
+	extvtoc->v_sectorsz = DEV_BSIZE;
+	if (un->c.un_flag & MD_LABELED)
+		extvtoc->v_part[0].p_start = 0ULL;
+	else
+		extvtoc->v_part[0].p_start = (diskaddr_t)(un->c.un_nhead *
+		    un->c.un_nsect);
+	extvtoc->v_part[0].p_size = un->c.un_total_blocks;
+}
+
+int
+md_set_extvtoc(md_unit_t *un, struct extvtoc *extvtoc)
+{
+
+	struct extpartition	*vpart;
+	int			i;
+	mddb_recid_t		recid;
+	mddb_recid_t		recids[3];
+	mddb_recstatus_t	status;
+	caddr_t			v;
+	diskaddr_t		sb;
+	struct vtoc		vtoc;
+
+	/*
+	 * Sanity-check the vtoc
+	 */
+	if (extvtoc->v_sanity != VTOC_SANE || extvtoc->v_nparts != 1)
+		return (EINVAL);
+
+	/*
+	 * Validate the partition table
+	 */
+	vpart = extvtoc->v_part;
+	for (i = 0; i < V_NUMPAR; i++, vpart++) {
+		if (i == 0) {
+			if (un->c.un_flag & MD_LABELED)
+				sb = 0ULL;
+			else
+				sb = (diskaddr_t)(un->c.un_nhead *
+				    un->c.un_nsect);
+			if (vpart->p_start != sb)
+				return (EINVAL);
+			if (vpart->p_size != un->c.un_total_blocks)
+				return (EINVAL);
+			continue;
+		}
+		/* all other partitions must be zero */
+		if (vpart->p_start != 0ULL)
+			return (EINVAL);
+		if (vpart->p_size != 0)
+			return (EINVAL);
+	}
+
+	if (!(un->c.un_revision & MD_64BIT_META_DEV)) {
+		extvtoctovtoc((*extvtoc), (vtoc));
+		return (md_set_vtoc(un, &vtoc));
+	}
+
+	/*
+	 * Since the size is greater than 1 TB the information can either
+	 * be stored as a VTOC or EFI.  Since EFI uses less space just use
+	 * it.  md_get_extvtoc can reconstruct the label information from
+	 * either format.
+	 */
+	if (un->c.un_vtoc_id) {
+		recid = un->c.un_vtoc_id;
+		status = mddb_getrecstatus(recid);
+		if (status == MDDB_OK) {
+			/*
+			 * If there's enough space in the record, and the
+			 * existing record is an EFI record (not vtoc),
+			 * we just can use the existing space.
+			 * Otherwise, we create a new MDDB_EFILABEL record for
+			 * this unit.
+			 */
+			if ((mddb_getrecsize(recid) >= MD_EFI_PARTNAME_BYTES) &&
+			    (un->c.un_flag & MD_EFILABEL))  {
+				v = mddb_getrecaddr(recid);
+				bzero((caddr_t)v, MD_EFI_PARTNAME_BYTES);
+				bcopy((caddr_t)&(extvtoc->v_volume),
+				    v, LEN_DKL_VVOL);
+				mddb_commitrec_wrapper(recid);
+				return (0);
+			}
+
+			un->c.un_vtoc_id = 0;
+			mddb_commitrec_wrapper(un->c.un_record_id);
+			mddb_deleterec_wrapper(recid);
+		}
+	}
+
+	recid = mddb_createrec(MD_EFI_PARTNAME_BYTES, MDDB_EFILABEL, 0,
+	    MD_CRO_32BIT, MD_UN2SET(un));
+
+	if (recid < 0) {
+		return (ENOSPC);
+	}
+
+	recids[0] = recid;
+	recids[1] = un->c.un_record_id;
+	recids[2] = 0;
+	v = mddb_getrecaddr(recid);
+	bzero((caddr_t)v, MD_EFI_PARTNAME_BYTES);
+	bcopy((caddr_t)&(extvtoc->v_volume), v, LEN_DKL_VVOL);
+
+	un->c.un_vtoc_id = recid;
+	un->c.un_flag |= MD_EFILABEL;
+	mddb_commitrecs_wrapper(recids);
+	return (0);
+}
+
 
 void
 md_get_cgapart(md_unit_t *un, struct dk_map *dkmapp)
--- a/usr/src/uts/common/io/lvm/md/md_subr.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/lvm/md/md_subr.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Driver for Virtual Disk.
  */
@@ -680,7 +679,7 @@
 		 * replica.
 		 */
 		mddb_parse_msg = kmem_zalloc(sizeof (md_mn_msg_mddb_parse_t),
-			KM_SLEEP);
+		    KM_SLEEP);
 		while (((s->s_mn_parseflags_sending & MDDB_PARSE_MASK) == 0) &&
 		    (s->s_mn_parseflags & MDDB_PARSE_MASK) &&
 		    (!(status & MD_SET_MNPARSE_BLK))) {
@@ -700,14 +699,14 @@
 			 * replica.
 			 */
 			mddb_parse_msg->msg_parse_flags =
-				s->s_mn_parseflags_sending;
+			    s->s_mn_parseflags_sending;
 
 			for (i = 0; i < MDDB_NLB; i++) {
 				mddb_parse_msg->msg_lb_flags[i] =
-					lbp->lb_locators[i].l_flags;
+				    lbp->lb_locators[i].l_flags;
 			}
 			kresult = kmem_zalloc(sizeof (md_mn_kresult_t),
-				KM_SLEEP);
+			    KM_SLEEP);
 			while (rval != 0) {
 				flag = 0;
 				if (status & MD_SET_STALE)
@@ -719,7 +718,7 @@
 				/* if the node hasn't yet joined, it's Ok. */
 				if ((!MDMN_KSEND_MSG_OK(rval, kresult)) &&
 				    (kresult->kmmr_comm_state !=
-							MDMNE_NOT_JOINED)) {
+				    MDMNE_NOT_JOINED)) {
 					mdmn_ksend_show_error(rval, kresult,
 					    "MD_MN_MSG_MDDB_PARSE");
 					cmn_err(CE_WARN, "md_ioctl_lock_exit: "
@@ -847,7 +846,8 @@
 		md_mtioctl_cnt++;
 		mutex_exit(&md_mx);
 	} else {
-		while (md_ioctl_lock_enter() == EINTR);
+		while (md_ioctl_lock_enter() == EINTR)
+			;
 	}
 	if (flags & MD_ARRAY_WRITER) {
 		rw_enter(&md_unit_array_rw.lock, RW_WRITER);
@@ -1333,12 +1333,12 @@
 		 */
 		mutex_enter(&md_cpr_resync.md_resync_mutex);
 		if ((md_cpr_resync.md_mirror_resync > 0) ||
-				(md_cpr_resync.md_raid_resync > 0)) {
+		    (md_cpr_resync.md_raid_resync > 0)) {
 			mutex_exit(&md_cpr_resync.md_resync_mutex);
 			cmn_err(CE_WARN, "There are Solaris Volume Manager "
 			    "synchronization threads running.");
 			cmn_err(CE_WARN, "Please try system suspension at "
-							"a later time.");
+			    "a later time.");
 			ret = -1;
 			break;
 		}
@@ -1348,7 +1348,7 @@
 		while (!(cp->cc_events & CALLB_CPR_SAFE))
 			/* cv_timedwait() returns -1 if it times out. */
 			if ((ret = cv_timedwait(&cp->cc_callb_cv, cp->cc_lockp,
-				lbolt + CPR_KTHREAD_TIMEOUT_SEC * hz)) == -1)
+			    lbolt + CPR_KTHREAD_TIMEOUT_SEC * hz)) == -1)
 				break;
 			break;
 
@@ -1454,7 +1454,7 @@
 	anchor->dq.qlen += i;
 	anchor->dq.treqs += i;
 	anchor->dq.maxq_len = (anchor->dq.qlen > anchor->dq.maxq_len) ?
-					anchor->dq.qlen : anchor->dq.maxq_len;
+	    anchor->dq.qlen : anchor->dq.maxq_len;
 
 	/* now add the list to request queue */
 	request->dq_prev = anchor->dq.dq_prev;
@@ -1850,7 +1850,7 @@
 		}
 
 		/* uninitialize */
-		name = ops->md_driver.md_drivername,
+		name = ops->md_driver.md_drivername;
 		md_ops[i] = NULL;
 		md_mods[i] = NULL;
 		ops->md_selfindex = 0;
@@ -1874,7 +1874,7 @@
 		md_haltsnarf_exit(i);
 
 	return (md_global_lock_exit(global_locks_owned_mask, 0,
-		MD_ARRAY_WRITER, NULL));
+	    MD_ARRAY_WRITER, NULL));
 }
 
 /*
@@ -1913,7 +1913,7 @@
 		ui = MDI_UNIT(mnum);
 		if (md_ops[ui->ui_opsindex]->md_open != NULL) {
 			int ret = (*md_ops[ui->ui_opsindex]->md_open)(&ddi_dev,
-					flag, OTYP_LYR, cred_p, md_oflags);
+			    flag, OTYP_LYR, cred_p, md_oflags);
 			/*
 			 * As open() may change the device,
 			 * send this info back to the caller.
@@ -2033,7 +2033,7 @@
 
 	bp->b_resid = 0;
 	endblk = (diskaddr_t)(bp->b_lblkno +
-			howmany(bp->b_bcount, DEV_BSIZE) - 1);
+	    howmany(bp->b_bcount, DEV_BSIZE) - 1);
 
 	if (endblk > (un->c.un_total_blocks - 1)) {
 		bp->b_resid = dbtob(endblk - (un->c.un_total_blocks - 1));
@@ -2117,7 +2117,7 @@
 	i = 0;
 	while (!NULL_REQUESTQ_ENTRY(rqp)) {
 		cnt = init_requestq(rqp, start_daemon,
-			(caddr_t)rqp->dispq_headp, minclsyspri, init_queue);
+		    (caddr_t)rqp->dispq_headp, minclsyspri, init_queue);
 
 		if (cnt && cnt != *rqp->num_threadsp) {
 			retval = 1;
@@ -2977,7 +2977,7 @@
 		/* This is a traditional metadevice */
 		if (setno == MD_LOCAL_SET) {
 			(void) snprintf(buf, sizeof (buf), "d%u",
-				(unsigned)unit);
+			    (unsigned)unit);
 		} else {
 			(void) snprintf(buf, sizeof (buf), "%s/d%u",
 			    mddb_getsetname(setno), (unsigned)unit);
@@ -2991,7 +2991,7 @@
 	side = mddb_getsidenum(setno);
 	devname = (char *)kmem_alloc(MAXPATHLEN, KM_SLEEP);
 	if (md_getdevname(setno, side, MD_KEYWILD,
-		md_makedevice(md_major, mnum), devname, MAXPATHLEN) == 0) {
+	    md_makedevice(md_major, mnum), devname, MAXPATHLEN) == 0) {
 		/*
 		 * md_getdevname has given us either /dev/md/dsk/<metaname>
 		 * or /dev/md/<setname>/dsk/<metname> depending on whether
@@ -3009,7 +3009,7 @@
 		} else {
 			/* Include setname */
 			(void) snprintf(buf, sizeof (buf), "%s/%s",
-				mddb_getsetname(setno), metaname);
+			    mddb_getsetname(setno), metaname);
 		}
 	} else {
 		/* We couldn't find the name. */
@@ -3040,7 +3040,7 @@
 	}
 
 	err = md_getdevname_common(setno, mddb_getsidenum(setno),
-		0, dev, buf, size, MD_NOWAIT_LOCK);
+	    0, dev, buf, size, MD_NOWAIT_LOCK);
 	if (err) {
 		if (err == ENOENT) {
 			(void) sprintf(buf, "(Unavailable)");
@@ -3343,7 +3343,7 @@
 
 	modindx = md_getmodindex(&(p->probe.md_driver), 1, 1);
 	probe_test = md_get_named_service(NODEV64, modindx,
-		p->probe.test_name, 0);
+	    p->probe.test_name, 0);
 	if (probe_test == NULL) {
 		err = EINVAL;
 		goto err_out;
@@ -3380,7 +3380,8 @@
 	 * on the metadevice because metaclear takes the readerlock (via
 	 * openclose lock).
 	 */
-	while (md_ioctl_lock_enter() == EINTR);
+	while (md_ioctl_lock_enter() == EINTR)
+		;
 	ui = MDI_UNIT(reqp->mnum);
 	if (ui != NULL) {
 		(void) md_unit_writerlock_common(ui, 0);
@@ -3396,7 +3397,7 @@
 	mutex_enter(PROBE_MX(p));
 	if (err != 0) {
 		cmn_err(CE_NOTE, "md_probe_one: err %d mnum %d\n", err,
-			reqp->mnum);
+		    reqp->mnum);
 		(void) mdsyserror(&(p->probe.mde), err);
 	}
 
@@ -3748,7 +3749,7 @@
 }
 
 int
-md_check_ioctl_against_efi(int cmd, ushort_t flags)
+md_check_ioctl_against_unit(int cmd, mdc_unit_t c)
 {
 	/*
 	 * If the metadevice is an old style device, it has a vtoc,
@@ -3758,15 +3759,32 @@
 	 */
 	switch (cmd) {
 		case DKIOCGGEOM:
+		case DKIOCGAPART:
+			/* if > 2 TB then fail */
+			if (c.un_total_blocks > MD_MAX_BLKS_FOR_EXTVTOC) {
+				return (ENOTSUP);
+			}
+			break;
 		case DKIOCGVTOC:
-		case DKIOCGAPART:
-			if ((flags & MD_EFILABEL) != 0) {
+			/* if > 2 TB then fail */
+			if (c.un_total_blocks > MD_MAX_BLKS_FOR_EXTVTOC) {
+				return (ENOTSUP);
+			}
+
+			/* if > 1 TB but < 2TB return overflow */
+			if (c.un_revision & MD_64BIT_META_DEV) {
+				return (EOVERFLOW);
+			}
+			break;
+		case DKIOCGEXTVTOC:
+			/* if > 2 TB then fail */
+			if (c.un_total_blocks > MD_MAX_BLKS_FOR_EXTVTOC) {
 				return (ENOTSUP);
 			}
 			break;
 		case DKIOCGETEFI:
 		case DKIOCPARTITION:
-			if ((flags & MD_EFILABEL) == 0) {
+			if ((c.un_flag & MD_EFILABEL) == 0) {
 				return (ENOTSUP);
 			}
 			break;
@@ -3776,11 +3794,21 @@
 			return (0);
 
 		case DKIOCSVTOC:
-		/*
-		 * This one is ok for small devices, even if they have an EFI
-		 * label. The appropriate check is in md_set_vtoc
-		 */
-			return (0);
+			/* if > 2 TB then fail */
+			if (c.un_total_blocks > MD_MAX_BLKS_FOR_EXTVTOC) {
+				return (ENOTSUP);
+			}
+
+			/* if > 1 TB but < 2TB return overflow */
+			if (c.un_revision & MD_64BIT_META_DEV) {
+				return (EOVERFLOW);
+			}
+			break;
+		case DKIOCSEXTVTOC:
+			if (c.un_total_blocks > MD_MAX_BLKS_FOR_EXTVTOC) {
+				return (ENOTSUP);
+			}
+			break;
 	}
 	return (0);
 }
@@ -3818,7 +3846,7 @@
 	}
 	vtoc = (struct vtoc *)mddb_getrecaddr(vtoc_recid);
 	efi_recid = mddb_createrec(MD_EFI_PARTNAME_BYTES, MDDB_EFILABEL, 0,
-					MD_CRO_32BIT, setno);
+	    MD_CRO_32BIT, setno);
 	if (efi_recid < 0) {
 		return (0);
 	}
@@ -3867,13 +3895,9 @@
 
 #ifdef DEBUG_COMM
 	printf("send msg: set=%d, flags=%d, type=%d, txid = 0x%llx,"
-		" size=%d, data=%d, data2=%d\n",
-			kmsg->kmsg_setno,
-			kmsg->kmsg_flags,
-			kmsg->kmsg_type,
-			kmsg->kmsg_size,
-			*(int *)data,
-			*(int *)(char *)(&kmsg->kmsg_data));
+	    " size=%d, data=%d, data2=%d\n",
+	    kmsg->kmsg_setno, kmsg->kmsg_flags, kmsg->kmsg_type,
+	    kmsg->kmsg_size, *(int *)data, *(int *)(char *)(&kmsg->kmsg_data));
 
 
 #endif /* DEBUG_COMM */
@@ -3907,7 +3931,7 @@
 			}
 		} else {
 			cmn_err(CE_WARN,
-				"md door call failed. Returned %d", rval);
+			    "md door call failed. Returned %d", rval);
 		}
 		delay(md_hz);
 	}
@@ -4097,7 +4121,7 @@
 		while (!(cp->cc_events & CALLB_CPR_SAFE))
 			/* cv_timedwait() returns -1 if it times out. */
 			if ((ret = cv_timedwait(&cp->cc_callb_cv, cp->cc_lockp,
-				lbolt + CPR_KTHREAD_TIMEOUT_SEC * hz)) == -1)
+			    lbolt + CPR_KTHREAD_TIMEOUT_SEC * hz)) == -1)
 				break;
 			break;
 
@@ -4149,7 +4173,7 @@
 	}
 
 	if ((n = (struct nm_name *)lookup_entry(nh, setno, MD_SIDEWILD,
-		MD_KEYWILD, dev, 0L)) == NULL) {
+	    MD_KEYWILD, dev, 0L)) == NULL) {
 		return (ENOENT);
 	}
 
--- a/usr/src/uts/common/io/lvm/mirror/mirror_ioctl.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/lvm/mirror/mirror_ioctl.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -449,6 +450,26 @@
 }
 
 static int
+mirror_get_extvtoc(
+	mm_unit_t	*un,
+	struct extvtoc	*vtocp
+)
+{
+	md_get_extvtoc((md_unit_t *)un, vtocp);
+
+	return (0);
+}
+
+static int
+mirror_set_extvtoc(
+	mm_unit_t	*un,
+	struct extvtoc	*vtocp
+)
+{
+	return (md_set_extvtoc((md_unit_t *)un, vtocp));
+}
+
+static int
 mirror_get_cgapart(
 	mm_unit_t	*un,
 	struct dk_map	*dkmapp
@@ -2964,7 +2985,7 @@
 	    ((un = MD_UNIT(mnum)) == NULL))
 		return (ENXIO);
 	/* is this a supported ioctl? */
-	err = md_check_ioctl_against_efi(cmd, un->c.un_flag);
+	err = md_check_ioctl_against_unit(cmd, un->c);
 	if (err != 0) {
 		return (err);
 	}
@@ -3078,6 +3099,40 @@
 		return (err);
 	}
 
+	case DKIOCGEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FREAD))
+			return (EACCES);
+
+		if ((err = mirror_get_extvtoc(un, &extvtoc)) != 0) {
+			return (err);
+		}
+
+		if (ddi_copyout(&extvtoc, data, sizeof (extvtoc), mode))
+			err = EFAULT;
+
+		return (err);
+	}
+
+	case DKIOCSEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FWRITE))
+			return (EACCES);
+
+		if (ddi_copyin(data, &extvtoc, sizeof (extvtoc), mode)) {
+			err = EFAULT;
+		}
+
+		if (err == 0)
+			err = mirror_set_extvtoc(un, &extvtoc);
+
+		return (err);
+	}
+
 	case DKIOCGAPART:
 	{
 		struct dk_map	dmp;
--- a/usr/src/uts/common/io/lvm/raid/raid_ioctl.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/lvm/raid/raid_ioctl.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * NAME:	raid_ioctl.c
  *
@@ -48,6 +47,8 @@
  *	raid_get_geom() - used to get the geometry of a RAID metadevice
  *	raid_get_vtoc() - used to get the VTOC on a RAID metadevice
  *	raid_set_vtoc() - used to set the VTOC on a RAID metadevice
+ *	raid_get_extvtoc() - used to get the extended VTOC on a RAID metadevice
+ *	raid_set_extvtoc() - used to set the extended VTOC on a RAID metadevice
  *	 raid_getdevs() - return all devices within a RAID metadevice
  *   raid_admin_ioctl() - IOCTL operations unique to metadevices and RAID
  */
@@ -269,7 +270,7 @@
 		 * use the hotspare key
 		 */
 		tmpdev = md_resolve_bydevid(mnum, tmpdev, HOTSPARED(un, i) ?
-			colptr->un_hs_key : colptr->un_orig_key);
+		    colptr->un_hs_key : colptr->un_orig_key);
 		if (md_layered_open(mnum, &tmpdev, MD_OFLG_NULL)) {
 			colptr->un_dev = tmpdev;
 			return (1);
@@ -371,7 +372,7 @@
 		/* truncate last chunk to end_addr if needed */
 		if (cur->ci_blkno + cur->ci_zerosize > cur->ci_lastblk) {
 			cur->ci_zerosize = (size_t)
-				(cur->ci_lastblk - cur->ci_blkno);
+			    (cur->ci_lastblk - cur->ci_blkno);
 		}
 
 		/* set address and length for I/O bufs */
@@ -412,7 +413,7 @@
 		return (1);
 	}
 	daemon_request(&md_done_daemon, init_col_nextio,
-			(daemon_queue_t *)cur, REQ_OLD);
+	    (daemon_queue_t *)cur, REQ_OLD);
 	return (1);
 }
 
@@ -516,10 +517,8 @@
 		cur->ci_buf.b_iodone = init_col_int;
 		cur->ci_buf.b_flags = B_BUSY | B_WRITE;
 		cur->ci_buf.b_edev = md_dev64_to_dev(un->un_column[ix].un_dev);
-		sema_init(&cur->ci_buf.b_io, 0, NULL,
-			SEMA_DEFAULT, NULL);
-		sema_init(&cur->ci_buf.b_sem, 0, NULL,
-			SEMA_DEFAULT, NULL);
+		sema_init(&cur->ci_buf.b_io, 0, NULL, SEMA_DEFAULT, NULL);
+		sema_init(&cur->ci_buf.b_sem, 0, NULL, SEMA_DEFAULT, NULL);
 		/* set address and length for I/O bufs */
 		cur->ci_buf.b_bufsize = dbtob(zerosize);
 		cur->ci_buf.b_bcount = dbtob(zerosize);
@@ -534,9 +533,9 @@
 			 * use the hotspare key
 			 */
 			tmpdev = md_resolve_bydevid(mnum, tmpdev,
-				HOTSPARED(un, ix) ?
-				un->un_column[ix].un_hs_key :
-				un->un_column[ix].un_orig_key);
+			    HOTSPARED(un, ix) ?
+			    un->un_column[ix].un_hs_key :
+			    un->un_column[ix].un_orig_key);
 			if ((cur->ci_err = md_layered_open(mnum, &tmpdev,
 			    MD_OFLG_NULL)) == 0)
 				un->un_column[ix].un_devflags |=
@@ -562,9 +561,9 @@
 					err = cur->ci_err;
 				else if (cur->ci_flag == COL_INIT_DONE) {
 					(void) init_pw_area(un,
-						un->un_column[col].un_dev,
-						un->un_column[col].un_pwstart,
-						col);
+					    un->un_column[col].un_dev,
+					    un->un_column[col].un_pwstart,
+					    col);
 					cur->ci_flag = COL_READY;
 				}
 			} else {
@@ -662,7 +661,7 @@
 	}
 
 	if (raid_internal_open(mnum, (FREAD | FWRITE),
-			OTYP_LYR, MD_OFLG_ISINIT)) {
+	    OTYP_LYR, MD_OFLG_ISINIT)) {
 		rval = mdmderror(ep, MDE_RAID_OPEN_FAILURE, mnum);
 		goto out;
 	}
@@ -737,7 +736,7 @@
 
 	for (line = 0; line < total_segments; line++) {
 		bp->b_lblkno = line *
-				((un->un_origcolumncnt - 1) * un->un_segsize);
+		    ((un->un_origcolumncnt - 1) * un->un_segsize);
 		bp->b_un.b_addr = buffer;
 		bp->b_bcount = iosize;
 		bp->b_iodone = NULL;
@@ -753,7 +752,7 @@
 			break;
 		}
 		un->un_percent_done = (uint_t)((line * 1000) /
-						un->un_segsincolumn);
+		    un->un_segsincolumn);
 		/* just to avoid rounding errors */
 		if (un->un_percent_done > 1000)
 			un->un_percent_done = 1000;
@@ -767,12 +766,12 @@
 	(void) md_io_writerexit(ui);
 	un = md_unit_writerlock(ui);
 	if (!err &&
-		(raid_state_cnt(un, RCS_OKAY) == un->un_totalcolumncnt))
+	    (raid_state_cnt(un, RCS_OKAY) == un->un_totalcolumncnt))
 			un->un_state = RUS_OKAY;
 	raid_commit(un, NULL);
 	md_unit_writerexit(ui);
 	if (err ||
-		raid_state_cnt(un, RCS_OKAY) != un->un_totalcolumncnt) {
+	    raid_state_cnt(un, RCS_OKAY) != un->un_totalcolumncnt) {
 		SE_NOTIFY(EC_SVM_STATE, ESC_SVM_REGEN_FAILED,
 		    SVM_TAG_METADEVICE, MD_UN2SET(un), MD_SID(un));
 	} else {
@@ -915,16 +914,16 @@
 		return (mdmderror(&msp->mde, MDE_UNIT_TOO_LARGE, mnum));
 #else
 		mr_recid = mddb_createrec(msp->size, typ1, 0,
-			MD_CRO_64BIT | MD_CRO_RAID | MD_CRO_FN, setno);
+		    MD_CRO_64BIT | MD_CRO_RAID | MD_CRO_FN, setno);
 #endif
 	} else {
 		mr_recid = mddb_createrec(msp->size, typ1, 0,
-			MD_CRO_32BIT | MD_CRO_RAID | MD_CRO_FN, setno);
+		    MD_CRO_32BIT | MD_CRO_RAID | MD_CRO_FN, setno);
 	}
 
 	if (mr_recid < 0)
 		return (mddbstatus2error(&msp->mde,
-				(int)mr_recid, mnum, setno));
+		    (int)mr_recid, mnum, setno));
 
 	/* get the address of the mdstruct */
 	un = (mr_unit_t *)mddb_getrecaddr(mr_recid);
@@ -977,7 +976,7 @@
 	if (err = raid_build_incore(un, 0)) {
 		if (un->mr_ic) {
 			kmem_free(un->un_column_ic, sizeof (mr_column_ic_t) *
-				un->un_totalcolumncnt);
+			    un->un_totalcolumncnt);
 			kmem_free(un->mr_ic, sizeof (*un->mr_ic));
 		}
 		MD_UNIT(mnum) = NULL;
@@ -1067,7 +1066,7 @@
 	mdclrerror(&migph->mde);
 
 	if ((un = raid_getun(mnum, &migph->mde,
-		RD_LOCK, lock)) == NULL)
+	    RD_LOCK, lock)) == NULL)
 		return (0);
 
 	if (migph->size == 0) {
@@ -1160,7 +1159,7 @@
 		 */
 		if (tmpdevt == NODEV64) {
 			tmpdevt = md_resolve_bydevid(mnum, tmpdevt,
-				un->un_column[ix].un_orig_key);
+			    un->un_column[ix].un_orig_key);
 			un->un_column[ix].un_orig_dev = tmpdevt;
 		}
 
@@ -1197,7 +1196,7 @@
 
 	if (un->un_state & RUS_DOI)
 		return (mdcomperror(ep, MDE_REPL_INVAL_STATE, mnum,
-			un->un_column[col].un_dev));
+		    un->un_column[col].un_dev));
 
 	if ((raid_state_cnt(un, RCS_INIT) != 0) || (un->un_state & RUS_INIT) ||
 	    (MD_STATUS(un) & MD_UN_GROW_PENDING))
@@ -1213,16 +1212,15 @@
 	if (un->un_state == RUS_LAST_ERRED) {
 		/* Must use -f force flag for unit in LAST_ERRED state */
 		if (!force)
-			return (mdmderror(ep,
-				MDE_RAID_NEED_FORCE, mnum));
+			return (mdmderror(ep, MDE_RAID_NEED_FORCE, mnum));
 
 		/* Must use -f force flag on ERRED column first */
 		if (un->un_column[col].un_devstate != RCS_ERRED) {
 			for (ix = 0; ix < un->un_totalcolumncnt; ix++) {
 				if (un->un_column[ix].un_devstate & RCS_ERRED)
 					return (mdcomperror(ep,
-						MDE_RAID_COMP_ERRED, mnum,
-						un->un_column[ix].un_dev));
+					    MDE_RAID_COMP_ERRED, mnum,
+					    un->un_column[ix].un_dev));
 			}
 		}
 
@@ -1230,7 +1228,7 @@
 		if ((un->un_column[col].un_devstate != RCS_LAST_ERRED) &&
 		    (un->un_column[col].un_devstate != RCS_ERRED))
 			return (mdcomperror(ep, MDE_RAID_COMP_ERRED,
-				mnum, un->un_column[col].un_dev));
+			    mnum, un->un_column[col].un_dev));
 	}
 
 	if (un->un_state == RUS_ERRED) {
@@ -1390,7 +1388,7 @@
 			un->un_column[col].un_devflags |= MD_RAID_COPY_RESYNC;
 		} else {
 			if (!(un->un_column[col].un_devflags &
-				MD_RAID_DEV_ISOPEN)) {
+			    MD_RAID_DEV_ISOPEN)) {
 				if (md_layered_open(mnum, &tmpdev,
 				    MD_OFLG_NULL)) {
 					un->un_column[col].un_dev = tmpdev;
@@ -1401,17 +1399,17 @@
 				    tmpdev != 0);
 
 				if ((md_getmajor(tmpdev) != md_major) &&
-					(md_devid_found(setno, side, raidkey)
-						== 1)) {
+				    (md_devid_found(setno, side, raidkey)
+				    == 1)) {
 					if (md_update_namespace_did(setno, side,
 					    raidkey, &mde) != 0) {
 						cmn_err(CE_WARN,
 						    "md: could not"
-							" update namespace\n");
+						    " update namespace\n");
 					}
 				}
 				un->un_column[col].un_dev =
-					un->un_column[col].un_orig_dev;
+				    un->un_column[col].un_orig_dev;
 			}
 			un->un_column[col].un_devflags |= MD_RAID_DEV_ISOPEN;
 			un->un_column[col].un_devflags |= MD_RAID_REGEN_RESYNC;
@@ -1574,7 +1572,7 @@
 	/* The unit requires not work so just force replay of the device */
 	if (raid_internal_open(mnum, (FREAD | FWRITE), OTYP_LYR, 0))
 		return (mdmderror(&rip->mde,
-			MDE_RAID_OPEN_FAILURE, mnum));
+		    MDE_RAID_OPEN_FAILURE, mnum));
 	(void) raid_internal_close(mnum, OTYP_LYR, 0, 0);
 
 	return (0);
@@ -1706,14 +1704,12 @@
 
 	if (MD_STATUS(un) & MD_UN_RESYNC_ACTIVE) {
 		md_unit_readerexit(ui);
-		return (mdmderror(&mgph->mde, MDE_RESYNC_ACTIVE,
-			mnum));
+		return (mdmderror(&mgph->mde, MDE_RESYNC_ACTIVE, mnum));
 	}
 
 	if (UNIT_STATE(un) & RUS_LAST_ERRED) {
 		md_unit_readerexit(ui);
-		return (mdmderror(&mgph->mde, MDE_RAID_LAST_ERRED,
-			mnum));
+		return (mdmderror(&mgph->mde, MDE_RAID_LAST_ERRED, mnum));
 	}
 
 	if (UNIT_STATE(un) & RUS_DOI) {
@@ -1729,22 +1725,20 @@
 	md_unit_readerexit(ui);
 
 	if ((un = raid_getun(mnum, &mgph->mde, WRITERS, lock)) ==
-		NULL)
+	    NULL)
 		return (0);
 
 	if (MD_STATUS(un) & MD_UN_GROW_PENDING)
 		return (mdmderror(&mgph->mde, MDE_IN_USE, mnum));
 
 	if (MD_STATUS(un) & MD_UN_RESYNC_ACTIVE)
-		return (mdmderror(&mgph->mde, MDE_RESYNC_ACTIVE,
-			mnum));
+		return (mdmderror(&mgph->mde, MDE_RESYNC_ACTIVE, mnum));
 
 	if (un->c.un_size >= mgph->size)
 		return (EINVAL);
 
 	if (UNIT_STATE(un) & RUS_LAST_ERRED)
-		return (mdmderror(&mgph->mde, MDE_RAID_LAST_ERRED,
-			mnum));
+		return (mdmderror(&mgph->mde, MDE_RAID_LAST_ERRED, mnum));
 
 	if (UNIT_STATE(un) & RUS_DOI)
 		return (mdmderror(&mgph->mde, MDE_RAID_DOI, mnum));
@@ -1769,15 +1763,15 @@
 		return (mdmderror(&mgph->mde, MDE_UNIT_TOO_LARGE, mnum));
 #else
 		mr_recid = mddb_createrec(mgph->size, typ1, 0,
-				MD_CRO_64BIT | options, setno);
+		    MD_CRO_64BIT | options, setno);
 #endif
 	} else {
 		mr_recid = mddb_createrec(mgph->size, typ1, 0,
-				MD_CRO_32BIT | options, setno);
+		    MD_CRO_32BIT | options, setno);
 	}
 	if (mr_recid < 0) {
 		rval = mddbstatus2error(&mgph->mde, (int)mr_recid,
-			mnum, setno);
+		    mnum, setno);
 		return (rval);
 	}
 
@@ -1843,14 +1837,14 @@
 	 */
 	new_un->un_column_ic = (mr_column_ic_t *)
 	    kmem_zalloc(sizeof (mr_column_ic_t) * new_un->un_totalcolumncnt,
-		KM_SLEEP);
+	    KM_SLEEP);
 
 	/*
 	 * Restore old column slots
 	 * Free the old column slots
 	 */
 	bcopy(mrc, new_un->un_column_ic,
-		sizeof (mr_column_ic_t) * un->un_totalcolumncnt);
+	    sizeof (mr_column_ic_t) * un->un_totalcolumncnt);
 	kmem_free(mrc, sizeof (mr_column_ic_t) * un->un_totalcolumncnt);
 
 	/* All 64 bit metadevices only support EFI labels. */
@@ -1865,7 +1859,7 @@
 		    (un->c.un_vtoc_id != 0)) {
 			old_vtoc = un->c.un_vtoc_id;
 			new_un->c.un_vtoc_id =
-				md_vtoc_to_efi_record(old_vtoc, setno);
+			    md_vtoc_to_efi_record(old_vtoc, setno);
 		}
 	}
 
@@ -1949,8 +1943,7 @@
 	md_unit_writerexit(ui);
 
 	if (raid_internal_open(mnum, (FREAD | FWRITE), OTYP_LYR, 0)) {
-		rval = mdmderror(&mgph->mde, MDE_RAID_OPEN_FAILURE,
-			mnum);
+		rval = mdmderror(&mgph->mde, MDE_RAID_OPEN_FAILURE, mnum);
 		SE_NOTIFY(EC_SVM_STATE, ESC_SVM_OPEN_FAIL, SVM_TAG_METADEVICE,
 		    MD_UN2SET(new_un), MD_SID(new_un));
 		return (rval);
@@ -1959,7 +1952,7 @@
 	for (i = 0; i < new_un->un_totalcolumncnt; i++) {
 		if (new_un->un_column[i].un_devstate & RCS_OKAY)
 			(void) init_pw_area(new_un, new_un->un_column[i].un_dev,
-				new_un->un_column[i].un_pwstart, i);
+			    new_un->un_column[i].un_pwstart, i);
 	}
 	md_unit_writerexit(ui);
 	(void) raid_internal_close(mnum, OTYP_LYR, 0, 0);
@@ -2097,6 +2090,45 @@
 }
 
 
+/*
+ * NAME:	raid_get_extvtoc
+ * DESCRIPTION: used to get the extended VTOC on a RAID metadevice
+ * PARAMETERS:	mr_unit_t    *un - RAID unit to get the VTOC from
+ *		struct extvtoc *vtocp - pointer to extended VTOC data structure
+ *
+ * LOCKS:	none
+ *
+ */
+static int
+raid_get_extvtoc(
+	mr_unit_t	*un,
+	struct extvtoc	*vtocp
+)
+{
+	md_get_extvtoc((md_unit_t *)un, vtocp);
+
+	return (0);
+}
+
+/*
+ * NAME:	raid_set_extvtoc
+ * DESCRIPTION: used to set the extended VTOC on a RAID metadevice
+ * PARAMETERS:	mr_unit_t    *un - RAID unit to set the VTOC on
+ *		struct extvtoc *vtocp - pointer to extended VTOC data structure
+ *
+ * LOCKS:	none
+ *
+ */
+static int
+raid_set_extvtoc(
+	mr_unit_t	*un,
+	struct extvtoc	*vtocp
+)
+{
+	return (md_set_extvtoc((md_unit_t *)un, vtocp));
+}
+
+
 
 /*
  * NAME:	raid_get_cgapart
@@ -2149,8 +2181,7 @@
 	/* check out unit */
 	mdclrerror(&mgdph->mde);
 
-	if ((un = raid_getun(mnum, &mgdph->mde, RD_LOCK,
-		lock)) == NULL)
+	if ((un = raid_getun(mnum, &mgdph->mde, RD_LOCK, lock)) == NULL)
 		return (0);
 
 	udevs = (md_dev64_t *)(uintptr_t)mgdph->devs;
@@ -2165,8 +2196,7 @@
 			}
 
 			if (ddi_copyout((caddr_t)&unit_dev,
-					(caddr_t)&udevs[cnt], sizeof (*udevs),
-					mode) != 0)
+			    (caddr_t)&udevs[cnt], sizeof (*udevs), mode) != 0)
 				return (EFAULT);
 		}
 		if (HOTSPARED(un, i)) {
@@ -2182,8 +2212,7 @@
 			}
 
 			if (ddi_copyout((caddr_t)&unit_dev,
-					(caddr_t)&udevs[cnt], sizeof (*udevs),
-					mode) != 0)
+			    (caddr_t)&udevs[cnt], sizeof (*udevs), mode) != 0)
 				return (EFAULT);
 		}
 	}
@@ -2516,10 +2545,10 @@
 		p->probe.nmdevs = ph->nmdevs;
 		(void) strcpy(p->probe.test_name, ph->test_name);
 		bcopy(&ph->md_driver, &(p->probe.md_driver),
-				sizeof (md_driver_t));
+		    sizeof (md_driver_t));
 
 		if ((p->probe.nmdevs < 1) ||
-			(strstr(p->probe.test_name, "probe") == NULL)) {
+		    (strstr(p->probe.test_name, "probe") == NULL)) {
 			err = EINVAL;
 			goto free_mem;
 		}
@@ -2549,7 +2578,8 @@
 		for (i = 0; i < p->probe.nmdevs; i++) {
 			sema_p(PROBE_SEMA(p));
 		}
-		while (md_ioctl_lock_enter() == EINTR);
+		while (md_ioctl_lock_enter() == EINTR)
+			;
 
 		/*
 		 * clean up. The hdr list is freed in the probe routines
@@ -2628,7 +2658,7 @@
 		return (ENXIO);
 
 	/* is this a supported ioctl? */
-	err = md_check_ioctl_against_efi(cmd, un->c.un_flag);
+	err = md_check_ioctl_against_unit(cmd, un->c);
 	if (err != 0) {
 		return (err);
 	}
@@ -2742,6 +2772,40 @@
 		return (err);
 	}
 
+	case DKIOCGEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FREAD))
+			return (EACCES);
+
+		if ((err = raid_get_extvtoc(un, &extvtoc)) != 0) {
+			return (err);
+		}
+
+		if (ddi_copyout(&extvtoc, data, sizeof (extvtoc), mode))
+			err = EFAULT;
+
+		return (err);
+	}
+
+	case DKIOCSEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FWRITE))
+			return (EACCES);
+
+		if (ddi_copyin(data, &extvtoc, sizeof (extvtoc), mode)) {
+			err = EFAULT;
+		}
+
+		if (err == 0)
+			err = raid_set_extvtoc(un, &extvtoc);
+
+		return (err);
+	}
+
 	case DKIOCGAPART:
 	{
 		struct dk_map	dmp;
@@ -2752,7 +2816,7 @@
 
 		if ((mode & DATAMODEL_MASK) == DATAMODEL_NATIVE) {
 			if (ddi_copyout((caddr_t)&dmp, data, sizeof (dmp),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #ifdef _SYSCALL32
@@ -2763,7 +2827,7 @@
 			dmp32.dkl_nblk = dmp.dkl_nblk;
 
 			if (ddi_copyout((caddr_t)&dmp32, data, sizeof (dmp32),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #endif /* _SYSCALL32 */
@@ -2830,7 +2894,7 @@
 
 	if (!un || !ui) {
 		(void) mdmderror(&rtxnp->mde, MDE_RENAME_CONFIG_ERROR,
-								from_min);
+		    from_min);
 		return (EINVAL);
 	}
 
@@ -2855,7 +2919,7 @@
 
 		if (!related) {
 			(void) mdmderror(&rtxnp->mde,
-					MDE_RENAME_TARGET_UNRELATED, to_min);
+			    MDE_RENAME_TARGET_UNRELATED, to_min);
 			return (EINVAL);
 		}
 
@@ -2869,14 +2933,14 @@
 
 		if (toplevel && md_unit_isopen(ui)) {
 			(void) mdmderror(&rtxnp->mde, MDE_RENAME_BUSY,
-								from_min);
+			    from_min);
 			return (EBUSY);
 		}
 		break;
 
 	default:
 		(void) mdmderror(&rtxnp->mde, MDE_RENAME_CONFIG_ERROR,
-								from_min);
+		    from_min);
 		return (EINVAL);
 	}
 
@@ -2921,38 +2985,38 @@
 
 		if (colstate & RCS_LAST_ERRED) {
 			(void) mdmderror(&rtxnp->mde, MDE_RAID_LAST_ERRED,
-						md_getminor(delta->dev));
+			    md_getminor(delta->dev));
 			return (EINVAL);
 		}
 
 		if (colstate & RCS_INIT_ERRED) {
 			(void) mdmderror(&rtxnp->mde, MDE_RAID_DOI,
-						md_getminor(delta->dev));
+			    md_getminor(delta->dev));
 			return (EINVAL);
 		}
 
 		/* How did we get this far before detecting this? */
 		if (colstate & RCS_RESYNC) {
 			(void) mdmderror(&rtxnp->mde, MDE_RENAME_BUSY,
-						md_getminor(delta->dev));
+			    md_getminor(delta->dev));
 			return (EBUSY);
 		}
 
 		if (colstate & RCS_ERRED) {
 			(void) mdmderror(&rtxnp->mde, MDE_RAID_NOT_OKAY,
-						md_getminor(delta->dev));
+			    md_getminor(delta->dev));
 			return (EINVAL);
 		}
 
 		if (!(colstate & RCS_OKAY)) {
 			(void) mdmderror(&rtxnp->mde, MDE_RAID_NOT_OKAY,
-						md_getminor(delta->dev));
+			    md_getminor(delta->dev));
 			return (EINVAL);
 		}
 
 		if (HOTSPARED(un, column)) {
 			(void) mdmderror(&rtxnp->mde, MDE_RAID_NOT_OKAY,
-						md_getminor(delta->dev));
+			    md_getminor(delta->dev));
 			return (EINVAL);
 		}
 	}
@@ -2960,7 +3024,7 @@
 	/* self does additional checks */
 	if (delta->old_role == MDRR_SELF) {
 		err = raid_may_renexch_self((mr_unit_t *)delta->unp,
-							delta->uip, rtxnp);
+		    delta->uip, rtxnp);
 	}
 	return (err);
 }
@@ -3046,13 +3110,12 @@
 		goto out;
 	}
 	if (raid_internal_open(mnum, (FREAD | FWRITE),
-			OTYP_LYR, MD_OFLG_ISINIT) == 0) {
+	    OTYP_LYR, MD_OFLG_ISINIT) == 0) {
 		for (col = 0; col < un->un_totalcolumncnt; col++) {
 			if (un->un_column[col].un_devstate & RCS_OKAY)
 				(void) init_pw_area(un,
-						un->un_column[col].un_dev,
-						un->un_column[col].un_pwstart,
-						col);
+				    un->un_column[col].un_dev,
+				    un->un_column[col].un_pwstart, col);
 		}
 		(void) raid_internal_close(mnum, OTYP_LYR, 0, 0);
 	}
--- a/usr/src/uts/common/io/lvm/softpart/sp_ioctl.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/lvm/softpart/sp_ioctl.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Soft partitioning metadevice driver (md_sp), administrative routines.
  *
@@ -486,11 +485,11 @@
 		return (mdmderror(mdep, MDE_UNIT_TOO_LARGE, mnum));
 #else
 		recids[0] = mddb_createrec((size_t)msp->size, rec_type, 0,
-			MD_CRO_64BIT | MD_CRO_SOFTPART | MD_CRO_FN, setno);
+		    MD_CRO_64BIT | MD_CRO_SOFTPART | MD_CRO_FN, setno);
 #endif
 	} else {
 		recids[0] = mddb_createrec((size_t)msp->size, rec_type, 0,
-			MD_CRO_32BIT | MD_CRO_SOFTPART | MD_CRO_FN, setno);
+		    MD_CRO_32BIT | MD_CRO_SOFTPART | MD_CRO_FN, setno);
 	}
 	/* set initial value for possible child record */
 	recids[1] = 0;
@@ -814,11 +813,11 @@
 		goto out;
 #else
 		recid = mddb_createrec((size_t)mgp->size, rec_type, 0,
-				MD_CRO_64BIT | options, setno);
+		    MD_CRO_64BIT | options, setno);
 #endif
 	} else {
 		recid = mddb_createrec((size_t)mgp->size, rec_type, 0,
-				MD_CRO_32BIT | options, setno);
+		    MD_CRO_32BIT | options, setno);
 	}
 	if (recid < 0) {
 		rval = mddbstatus2error(mdep, (int)recid, mnum, setno);
@@ -851,7 +850,7 @@
 		    (un->c.un_vtoc_id != 0)) {
 			old_vtoc = un->c.un_vtoc_id;
 			new_un->c.un_vtoc_id =
-				md_vtoc_to_efi_record(old_vtoc, setno);
+			    md_vtoc_to_efi_record(old_vtoc, setno);
 		}
 	}
 
@@ -1248,7 +1247,7 @@
 		return (ENXIO);
 
 	/* is this a supported ioctl? */
-	err = md_check_ioctl_against_efi(cmd, un->c.un_flag);
+	err = md_check_ioctl_against_unit(cmd, un->c);
 	if (err != 0) {
 		return (err);
 	}
@@ -1316,7 +1315,7 @@
 
 		if ((mode & DATAMODEL_MASK) == DATAMODEL_NATIVE) {
 			if (ddi_copyout((caddr_t)&dmp, data, sizeof (dmp),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #ifdef _SYSCALL32
@@ -1327,7 +1326,7 @@
 			dmp32.dkl_nblk = dmp.dkl_nblk;
 
 			if (ddi_copyout((caddr_t)&dmp32, data, sizeof (dmp32),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #endif /* _SYSCALL32 */
@@ -1389,6 +1388,39 @@
 		return (err);
 	}
 
+	case DKIOCGEXTVTOC:
+	{
+		/* extended vtoc information */
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FREAD))
+			return (EACCES);
+
+		md_get_extvtoc((md_unit_t *)un, &extvtoc);
+
+		if (ddi_copyout(&extvtoc, data, sizeof (extvtoc), mode))
+			err = EFAULT;
+
+		return (err);
+	}
+
+	case DKIOCSEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FWRITE))
+			return (EACCES);
+
+		if (ddi_copyin(data, &extvtoc, sizeof (extvtoc), mode)) {
+			err = EFAULT;
+		}
+
+		if (err == 0)
+			err = md_set_extvtoc((md_unit_t *)un, &extvtoc);
+
+		return (err);
+	}
+
 	case DKIOCGETEFI:
 	{
 		/*
--- a/usr/src/uts/common/io/lvm/stripe/stripe_ioctl.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/lvm/stripe/stripe_ioctl.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/conf.h>
@@ -72,8 +71,8 @@
 	mddb_recid_t	recids[6];
 	ms_new_dev_t	nd;
 	ms_cd_info_t	cd;
-	int		ci,
-			cmpcnt;
+	int		ci;
+	int		cmpcnt;
 	void		*repl_data;
 	md_dev64_t	fake_devt;
 	void		(*repl_done)();
@@ -176,11 +175,11 @@
 		return (mdmderror(mdep, MDE_UNIT_TOO_LARGE, mnum));
 #else
 		ms_recid = mddb_createrec((size_t)msp->size, typ1, 0,
-			MD_CRO_64BIT | MD_CRO_STRIPE | MD_CRO_FN, setno);
+		    MD_CRO_64BIT | MD_CRO_STRIPE | MD_CRO_FN, setno);
 #endif
 	} else {
 		ms_recid = mddb_createrec((size_t)msp->size, typ1, 0,
-			MD_CRO_32BIT | MD_CRO_STRIPE | MD_CRO_FN, setno);
+		    MD_CRO_32BIT | MD_CRO_STRIPE | MD_CRO_FN, setno);
 	}
 	if (ms_recid < 0)
 		return (mddbstatus2error(mdep, ms_recid, mnum, setno));
@@ -482,11 +481,11 @@
 		goto out;
 #else
 		ms_recid = mddb_createrec((size_t)mgp->size, typ1, 0,
-				MD_CRO_64BIT | options, setno);
+		    MD_CRO_64BIT | options, setno);
 #endif
 	} else {
 		ms_recid = mddb_createrec((size_t)mgp->size, typ1, 0,
-				MD_CRO_32BIT | options, setno);
+		    MD_CRO_32BIT | options, setno);
 	}
 
 
@@ -574,7 +573,7 @@
 		    (un->c.un_vtoc_id != 0)) {
 			old_vtoc = un->c.un_vtoc_id;
 			new_un->c.un_vtoc_id =
-				md_vtoc_to_efi_record(old_vtoc, setno);
+			    md_vtoc_to_efi_record(old_vtoc, setno);
 		}
 	}
 
@@ -622,11 +621,10 @@
 				 * if it is then use the key for hotspare
 				 */
 				tmpdev = md_resolve_bydevid(mnum, tmpdev,
-					mdc->un_mirror.ms_hs_id ?
-					mdc->un_mirror.ms_hs_key :
-					mdc->un_key);
+				    mdc->un_mirror.ms_hs_id ?
+				    mdc->un_mirror.ms_hs_key : mdc->un_key);
 				(void) md_layered_open(mnum, &tmpdev,
-					MD_OFLG_NULL);
+				    MD_OFLG_NULL);
 				mdc->un_dev = tmpdev;
 				mdc->un_mirror.ms_flags |= MDM_S_ISOPEN;
 			}
@@ -703,6 +701,26 @@
 }
 
 static int
+stripe_get_extvtoc(
+	ms_unit_t	*un,
+	struct extvtoc	*vtocp
+)
+{
+	md_get_extvtoc((md_unit_t *)un, vtocp);
+
+	return (0);
+}
+
+static int
+stripe_set_extvtoc(
+	ms_unit_t	*un,
+	struct extvtoc	*vtocp
+)
+{
+	return (md_set_extvtoc((md_unit_t *)un, vtocp));
+}
+
+static int
 stripe_get_cgapart(
 	ms_unit_t	*un,
 	struct dk_map	*dkmapp
@@ -763,7 +781,7 @@
 				}
 
 				if (ddi_copyout((caddr_t)&unit_dev, devsp,
-						sizeof (*devsp), mode) != 0)
+				    sizeof (*devsp), mode) != 0)
 					return (EFAULT);
 				++devsp;
 			}
@@ -1052,7 +1070,7 @@
 		return (ENXIO);
 
 	/* is this a supported ioctl? */
-	err = md_check_ioctl_against_efi(cmd, un->c.un_flag);
+	err = md_check_ioctl_against_unit(cmd, un->c);
 	if (err != 0) {
 		return (err);
 	}
@@ -1167,6 +1185,42 @@
 		return (err);
 	}
 
+
+	case DKIOCGEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FREAD))
+			return (EACCES);
+
+		if ((err = stripe_get_extvtoc(un, &extvtoc)) != 0) {
+			return (err);
+		}
+
+		if (ddi_copyout(&extvtoc, data, sizeof (extvtoc), mode))
+			err = EFAULT;
+
+		return (err);
+	}
+
+	case DKIOCSEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FWRITE))
+			return (EACCES);
+
+		if (ddi_copyin(data, &extvtoc, sizeof (extvtoc), mode)) {
+			err = EFAULT;
+		}
+
+		if (err == 0) {
+			err = stripe_set_extvtoc(un, &extvtoc);
+		}
+
+		return (err);
+	}
+
 	case DKIOCGAPART:
 	{
 		struct dk_map	dmp;
@@ -1177,7 +1231,7 @@
 
 		if ((mode & DATAMODEL_MASK) == DATAMODEL_NATIVE) {
 			if (ddi_copyout((caddr_t)&dmp, data, sizeof (dmp),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #ifdef _SYSCALL32
@@ -1188,7 +1242,7 @@
 			dmp32.dkl_nblk = dmp.dkl_nblk;
 
 			if (ddi_copyout((caddr_t)&dmp32, data, sizeof (dmp32),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #endif /* _SYSCALL32 */
@@ -1251,7 +1305,7 @@
 
 	if (!un || !ui) {
 		(void) mdmderror(&rtxnp->mde, MDE_RENAME_CONFIG_ERROR,
-								from_min);
+		    from_min);
 		return (EINVAL);
 	}
 
@@ -1276,7 +1330,7 @@
 
 		if (!related) {
 			(void) mdmderror(&rtxnp->mde,
-					MDE_RENAME_TARGET_UNRELATED, to_min);
+			    MDE_RENAME_TARGET_UNRELATED, to_min);
 			return (EINVAL);
 		}
 
@@ -1290,14 +1344,14 @@
 
 		if (toplevel && md_unit_isopen(ui)) {
 			(void) mdmderror(&rtxnp->mde, MDE_RENAME_BUSY,
-						from_min);
+			    from_min);
 			return (EBUSY);
 		}
 		break;
 
 	default:
 		(void) mdmderror(&rtxnp->mde, MDE_RENAME_CONFIG_ERROR,
-					from_min);
+		    from_min);
 		return (EINVAL);
 	}
 
@@ -1328,7 +1382,7 @@
 	/* self does additional checks */
 	if (delta->old_role == MDRR_SELF) {
 		err = stripe_may_renexch_self((ms_unit_t *)delta->unp,
-						delta->uip, rtxnp);
+		    delta->uip, rtxnp);
 	}
 out:
 	return (err);
--- a/usr/src/uts/common/io/lvm/trans/trans_ioctl.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/lvm/trans/trans_ioctl.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/conf.h>
@@ -173,7 +172,7 @@
 	migp->size = 0;
 
 	un = trans_getun(migp->id, &migp->mde,
-		RD_LOCK, lock);
+	    RD_LOCK, lock);
 	if (un == NULL)
 		return (EINVAL);
 
@@ -284,7 +283,7 @@
 	migp->size = 0;
 
 	un = trans_getun(migp->id, &migp->mde,
-		RD_LOCK, lock);
+	    RD_LOCK, lock);
 	if (un == NULL)
 		return (EINVAL);
 
@@ -731,7 +730,7 @@
 	for (i = 0; i < NKEYS; ++i) {
 		allocatorvalue = i;
 		if (*(int *)tsd_getcreate(&keys[i], trans_test_destructor_alloc,
-			trans_test_allocator) != allocatorvalue) {
+		    trans_test_allocator) != allocatorvalue) {
 			error = 600;
 			goto errout;
 		}
@@ -844,7 +843,7 @@
 	ASSERT(mutex_owned(&error_mutex) != 0);
 	while ((errp = errp->er_next) != (mt_error_t *)NULL) {
 		if ((errp->er_unitp->un_m_dev == dev) ||
-			(errp->er_unitp->un_l_dev == dev))
+		    (errp->er_unitp->un_l_dev == dev))
 			break;
 	}
 	return (errp);
@@ -871,10 +870,9 @@
 			 * can try again later.
 			 */
 			if ((((errp->er_total_errors % 2) == 0) &&
-			(errp->er_unitp->un_l_dev == target)) ||
-				(((errp->er_total_errors % 2) != 0) &&
-				(errp->er_unitp->un_m_dev ==
-					target))) {
+			    (errp->er_unitp->un_l_dev == target)) ||
+			    (((errp->er_total_errors % 2) != 0) &&
+			    (errp->er_unitp->un_m_dev == target))) {
 				/* simulate an error */
 				bp->b_flags |= B_ERROR;
 				bp->b_error = EIO;
@@ -899,7 +897,7 @@
 
 	case mte_watch_block:
 		if ((bp->b_edev == errp->er_bad_unit) &&
-			(bp->b_blkno == errp->er_bad_block)) {
+		    (bp->b_blkno == errp->er_bad_block)) {
 			bp->b_flags |= B_ERROR;
 			bp->b_error = EIO;
 			rv = 1;
@@ -935,8 +933,8 @@
 			 * the range of blocks designated as our log.
 			 */
 			if ((bp->b_blkno >= un->un_l_pwsblk) &&
-				((bp->b_blkno + btodb(bp->b_bcount)) <=
-				(un->un_l_sblk + un->un_l_tblks))) {
+			    ((bp->b_blkno + btodb(bp->b_bcount)) <=
+			    (un->un_l_sblk + un->un_l_tblks))) {
 				rv = trans_check_error(bp, errp);
 			}
 		}
@@ -986,7 +984,7 @@
 	mdclrerror(&migp->mde);
 
 	un = trans_getun(migp->id, &migp->mde,
-		RD_LOCK, lock);
+	    RD_LOCK, lock);
 	if (un == NULL)
 		return (EINVAL);
 
@@ -1047,7 +1045,7 @@
 	mdclrerror(&migp->mde);
 
 	un = trans_getun(migp->id, &migp->mde,
-		RD_LOCK, lock);
+	    RD_LOCK, lock);
 	if (un == NULL)
 		return (EINVAL);
 
@@ -1057,7 +1055,7 @@
 		/* Remove from list. */
 		pred_errp->er_next = errp->er_next;
 		if ((error_list_head.er_next == (mt_error_t *)NULL) &&
-			(mdv_strategy_tstpnt == trans_error_injector)) {
+		    (mdv_strategy_tstpnt == trans_error_injector)) {
 			mdv_strategy_tstpnt = tstpnt_save;
 		}
 	} else {
@@ -1111,7 +1109,7 @@
 	mdclrerror(&migp->mde);
 
 	un = trans_getun(migp->id, &migp->mde,
-		RD_LOCK, lock);
+	    RD_LOCK, lock);
 	if (un == NULL || un->un_ut == NULL)
 		return (EINVAL);
 
@@ -1131,7 +1129,7 @@
 	mdclrerror(&migp->mde);
 
 	un = trans_getun(migp->id, &migp->mde,
-		WR_LOCK, lock);
+	    WR_LOCK, lock);
 	if (un == NULL)
 		return (EINVAL);
 
@@ -1165,7 +1163,7 @@
 	mdclrerror(&migp->mde);
 
 	un = trans_getun(migp->id, &migp->mde,
-		RD_LOCK, lock);
+	    RD_LOCK, lock);
 	if (un == NULL)
 		return (0);
 
@@ -1211,7 +1209,7 @@
 				if (un->un_l_nblks > btodb(LDL_MAXLOGSIZE))
 					un->un_l_nblks = btodb(LDL_MAXLOGSIZE);
 				un->un_l_maxresv = (uint_t)(un->un_l_nblks *
-					LDL_USABLE_BSIZE);
+				    LDL_USABLE_BSIZE);
 			}
 	}
 
@@ -1228,9 +1226,9 @@
 	minor_t		mnum = params->mnum;
 	mt_unit_t	*un;
 	mdi_unit_t	*ui;
-	md_dev64_t	cmp_dev,
-			ldev,
-			mdev;
+	md_dev64_t	cmp_dev;
+	md_dev64_t	ldev;
+	md_dev64_t	mdev;
 
 	mdclrerror(&params->mde);
 
@@ -1268,7 +1266,7 @@
 	mdclrerror(&mgp->mde);
 
 	un = trans_getun(mgp->mnum, &mgp->mde,
-		RD_LOCK, lock);
+	    RD_LOCK, lock);
 	if (un == NULL)
 		return (0);
 
@@ -1302,7 +1300,7 @@
 
 	/* acquire both md_unit_array_rw, and unit_reader lock */
 	un = trans_getun(migp->id, &migp->mde,
-		READERS, lock);
+	    READERS, lock);
 	if (un == NULL)
 		return (0);
 
@@ -1462,6 +1460,14 @@
 }
 
 static int
+trans_get_extvtoc(mt_unit_t *un, struct extvtoc *vtocp)
+{
+	md_get_extvtoc((md_unit_t *)un, vtocp);
+
+	return (0);
+}
+
+static int
 trans_islog(mt_unit_t *un)
 {
 	if (un->un_l_unit == NULL)
@@ -1479,6 +1485,12 @@
 }
 
 static int
+trans_set_extvtoc(mt_unit_t *un, struct extvtoc *vtocp)
+{
+	return (md_set_extvtoc((md_unit_t *)un, vtocp));
+}
+
+static int
 trans_get_cgapart(
 	mt_unit_t	*un,
 	struct dk_map	*dkmapp
@@ -2043,6 +2055,41 @@
 		return (err);
 	}
 
+
+	case DKIOCGEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FREAD))
+			return (EACCES);
+
+		if ((err = trans_get_extvtoc(un, &extvtoc)) != 0) {
+			return (err);
+		}
+
+		if (ddi_copyout(&extvtoc, data, sizeof (extvtoc), mode))
+			err = EFAULT;
+
+		return (err);
+	}
+
+	case DKIOCSEXTVTOC:
+	{
+		struct extvtoc	extvtoc;
+
+		if (! (mode & FWRITE))
+			return (EACCES);
+
+		if (ddi_copyin(data, &extvtoc, sizeof (extvtoc), mode)) {
+			err = EFAULT;
+		}
+
+		if (err == 0)
+			err = trans_set_extvtoc(un, &extvtoc);
+
+		return (err);
+	}
+
 	case DKIOCGAPART:
 	{
 		struct dk_map	dmp;
@@ -2053,7 +2100,7 @@
 
 		if ((mode & DATAMODEL_MASK) == DATAMODEL_NATIVE) {
 			if (ddi_copyout((caddr_t)&dmp, data, sizeof (dmp),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #ifdef _SYSCALL32
@@ -2064,7 +2111,7 @@
 			dmp32.dkl_nblk = dmp.dkl_nblk;
 
 			if (ddi_copyout((caddr_t)&dmp32, data, sizeof (dmp32),
-				mode) != 0)
+			    mode) != 0)
 				err = EFAULT;
 		}
 #endif /* _SYSCALL32 */
@@ -2213,7 +2260,7 @@
 	ASSERT(!(un->un_l_unit && (md_getmajor(un->un_l_dev) != md_major)));
 
 	if ((md_getmajor(un->un_m_dev) == md_major) &&
-		(master_min == from_min)) {
+	    (master_min == from_min)) {
 
 		ASSERT(!(un->un_l_unit && (log_min == from_min)));
 
@@ -2221,7 +2268,7 @@
 		un->un_m_key = rtxnp->to.key;
 
 	} else if ((md_getmajor(un->un_m_dev) == md_major) &&
-		    un->un_l_unit && (log_min == from_min)) {
+	    un->un_l_unit && (log_min == from_min)) {
 
 		ASSERT(master_min != from_min);
 
@@ -2315,8 +2362,7 @@
 
 	/* both devices must be metadevices in order to be updated */
 	ASSERT(md_getmajor(un->un_m_dev) == md_major);
-	ASSERT(!(un->un_l_unit &&
-		(md_getmajor(un->un_l_dev) != md_major)));
+	ASSERT(!(un->un_l_unit && (md_getmajor(un->un_l_dev) != md_major)));
 
 	if ((md_getmajor(un->un_m_dev) == md_major) &&
 	    (master_min == to_min)) {
@@ -2329,7 +2375,7 @@
 		un->un_m_key = rtxnp->from.key;
 
 	} else if ((md_getmajor(un->un_m_dev) == md_major) &&
-		    un->un_l_unit && (log_min == to_min)) {
+	    un->un_l_unit && (log_min == to_min)) {
 
 		/* master and log can't both be changed */
 		ASSERT(!(master_min == to_min));
@@ -2435,11 +2481,10 @@
 
 	/* both devices must be metadevices in order to be updated */
 	ASSERT(md_getmajor(un->un_m_dev) == md_major);
-	ASSERT(!(un->un_l_unit &&
-		(md_getmajor(un->un_l_dev) != md_major)));
+	ASSERT(!(un->un_l_unit && (md_getmajor(un->un_l_dev) != md_major)));
 
 	if ((md_getmajor(un->un_m_dev) == md_major) &&
-		(master_min == from_min)) {
+	    (master_min == from_min)) {
 
 		/* can't be changing log and master */
 		ASSERT(!(un->un_l_unit && (log_min == to_min)));
@@ -2449,8 +2494,7 @@
 		un->un_m_key = rtxnp->to.key;
 
 	} else if (un->un_l_unit &&
-		    ((md_getmajor(un->un_l_dev) == md_major) &&
-		    log_min == to_min)) {
+	    ((md_getmajor(un->un_l_dev) == md_major) && log_min == to_min)) {
 
 		/* can't be changing log and master */
 		ASSERT(master_min != from_min);
@@ -2516,10 +2560,9 @@
 		master_min = md_getminor(from_un->un_m_dev);
 
 		p = new = md_build_rendelta(MDRR_CHILD,
-				to_min == master_min? MDRR_SELF: MDRR_CHILD,
-				from_un->un_m_dev, p,
-				MD_UNIT(master_min), MDI_UNIT(master_min),
-				&rtxnp->mde);
+		    to_min == master_min? MDRR_SELF: MDRR_CHILD,
+		    from_un->un_m_dev, p, MD_UNIT(master_min),
+		    MDI_UNIT(master_min), &rtxnp->mde);
 
 		if (!new) {
 			if (mdisok(&rtxnp->mde)) {
@@ -2536,10 +2579,9 @@
 		log_min = md_getminor(from_un->un_l_dev);
 
 		new = md_build_rendelta(MDRR_CHILD,
-				to_min == log_min? MDRR_SELF: MDRR_CHILD,
-				from_un->un_l_dev, p,
-				MD_UNIT(log_min), MDI_UNIT(log_min),
-				&rtxnp->mde);
+		    to_min == log_min? MDRR_SELF: MDRR_CHILD,
+		    from_un->un_l_dev, p, MD_UNIT(log_min),
+		    MDI_UNIT(log_min), &rtxnp->mde);
 		if (!new) {
 			if (mdisok(&rtxnp->mde)) {
 				(void) mdsyserror(&rtxnp->mde, ENOMEM);
@@ -2572,7 +2614,7 @@
 
 	if (!un || !ui) {
 		(void) mdmderror(&rtxnp->mde, MDE_RENAME_CONFIG_ERROR,
-								from_min);
+		    from_min);
 		return (EINVAL);
 	}
 
@@ -2595,21 +2637,21 @@
 		 */
 		if (md_getmajor(un->un_m_dev) != md_major) {
 			(void) mdmderror(&rtxnp->mde, MDE_RENAME_TARGET_BAD,
-									to_min);
+			    to_min);
 			return (EINVAL);
 		}
 
 		if (un->un_l_unit &&
-			(md_getmajor(un->un_l_dev) != md_major)) {
+		    (md_getmajor(un->un_l_dev) != md_major)) {
 
 			(void) mdmderror(&rtxnp->mde, MDE_RENAME_TARGET_BAD,
-									to_min);
+			    to_min);
 			return (EINVAL);
 		}
 
 		if (md_getminor(un->un_m_dev) != to_min) {
 			(void) mdmderror(&rtxnp->mde, MDE_RENAME_TARGET_BAD,
-									to_min);
+			    to_min);
 			return (EINVAL);
 		}
 
@@ -2620,7 +2662,7 @@
 
 	default:
 		(void) mdmderror(&rtxnp->mde, MDE_RENAME_CONFIG_ERROR,
-								from_min);
+		    from_min);
 		return (EINVAL);
 	}
 
@@ -2661,7 +2703,7 @@
 		    ((md_getminor(delta->dev) == rtxnp->from.mnum) ||
 		    (md_getminor(delta->dev) == rtxnp->to.mnum))) {
 			(void) mdmderror(&rtxnp->mde,
-					MDE_RENAME_BUSY, rtxnp->from.mnum);
+			    MDE_RENAME_BUSY, rtxnp->from.mnum);
 			return (EBUSY);
 		}
 	}
@@ -2672,7 +2714,7 @@
 
 	if (un->un_l_unit) {
 		(void) mdmderror(&rtxnp->mde,
-					MDE_RENAME_BUSY, rtxnp->from.mnum);
+		    MDE_RENAME_BUSY, rtxnp->from.mnum);
 		return (EBUSY);
 	}
 
@@ -2682,7 +2724,7 @@
 		 * self does additional checks
 		 */
 		err = trans_may_renexch_self((mt_unit_t *)delta->unp,
-						delta->uip, rtxnp);
+		    delta->uip, rtxnp);
 		if (err != 0) {
 			goto out;
 		}
--- a/usr/src/uts/common/io/scsi/targets/sd.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/io/scsi/targets/sd.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -1200,7 +1201,7 @@
  */
 static int  sdopen(dev_t *dev_p, int flag, int otyp, cred_t *cred_p);
 static int  sdclose(dev_t dev, int flag, int otyp, cred_t *cred_p);
-static int  sd_ready_and_valid(struct sd_lun *un);
+static int  sd_ready_and_valid(struct sd_lun *un, int part);
 
 static void sdmin(struct buf *bp);
 static int sdread(dev_t dev, struct uio *uio, cred_t *cred_p);
@@ -9406,7 +9407,7 @@
 	 */
 	if (!nodelay) {
 		mutex_exit(SD_MUTEX(un));
-		rval = sd_ready_and_valid(un);
+		rval = sd_ready_and_valid(un, part);
 		mutex_enter(SD_MUTEX(un));
 		/*
 		 * Fail if device is not ready or if the number of disk
@@ -9759,7 +9760,7 @@
  */
 
 static int
-sd_ready_and_valid(struct sd_lun *un)
+sd_ready_and_valid(struct sd_lun *un, int part)
 {
 	struct sd_errstats	*stp;
 	uint64_t		capacity;
@@ -9885,8 +9886,9 @@
 
 	if (un->un_f_format_in_progress == FALSE) {
 		mutex_exit(SD_MUTEX(un));
-		if (cmlb_validate(un->un_cmlbhandle, 0,
-		    (void *)SD_PATH_DIRECT) != 0) {
+
+		if (cmlb_partinfo(un->un_cmlbhandle, part, NULL, NULL, NULL,
+		    NULL, (void *) SD_PATH_DIRECT) != 0) {
 			rval = SD_NOT_READY_VALID;
 			mutex_enter(SD_MUTEX(un));
 			goto done;
@@ -10015,7 +10017,7 @@
 		}
 		un->un_ncmds_in_driver++;
 		mutex_exit(SD_MUTEX(un));
-		if ((sd_ready_and_valid(un)) != SD_READY_VALID) {
+		if ((sd_ready_and_valid(un, SDPART(dev))) != SD_READY_VALID) {
 			mutex_enter(SD_MUTEX(un));
 			un->un_ncmds_in_driver--;
 			ASSERT(un->un_ncmds_in_driver >= 0);
@@ -10094,7 +10096,7 @@
 		}
 		un->un_ncmds_in_driver++;
 		mutex_exit(SD_MUTEX(un));
-		if ((sd_ready_and_valid(un)) != SD_READY_VALID) {
+		if ((sd_ready_and_valid(un, SDPART(dev))) != SD_READY_VALID) {
 			mutex_enter(SD_MUTEX(un));
 			un->un_ncmds_in_driver--;
 			ASSERT(un->un_ncmds_in_driver >= 0);
@@ -10173,7 +10175,7 @@
 		}
 		un->un_ncmds_in_driver++;
 		mutex_exit(SD_MUTEX(un));
-		if ((sd_ready_and_valid(un)) != SD_READY_VALID) {
+		if ((sd_ready_and_valid(un, SDPART(dev))) != SD_READY_VALID) {
 			mutex_enter(SD_MUTEX(un));
 			un->un_ncmds_in_driver--;
 			ASSERT(un->un_ncmds_in_driver >= 0);
@@ -10252,7 +10254,7 @@
 		}
 		un->un_ncmds_in_driver++;
 		mutex_exit(SD_MUTEX(un));
-		if ((sd_ready_and_valid(un)) != SD_READY_VALID) {
+		if ((sd_ready_and_valid(un, SDPART(dev))) != SD_READY_VALID) {
 			mutex_enter(SD_MUTEX(un));
 			un->un_ncmds_in_driver--;
 			ASSERT(un->un_ncmds_in_driver >= 0);
@@ -11066,8 +11068,10 @@
 	 * removable-media devices, of if the device was opened in
 	 * NDELAY/NONBLOCK mode.
 	 */
+	partition = SDPART(bp->b_edev);
+
 	if (!SD_IS_VALID_LABEL(un) &&
-	    (sd_ready_and_valid(un) != SD_READY_VALID)) {
+	    (sd_ready_and_valid(un, partition) != SD_READY_VALID)) {
 		/*
 		 * For removable devices it is possible to start an I/O
 		 * without a media by opening the device in nodelay mode.
@@ -11086,7 +11090,6 @@
 		return;
 	}
 
-	partition = SDPART(bp->b_edev);
 
 	nblocks = 0;
 	(void) cmlb_partinfo(un->un_cmlbhandle, partition,
@@ -20106,13 +20109,16 @@
 		switch (cmd) {
 		case DKIOCGGEOM:	/* SD_PATH_DIRECT */
 		case DKIOCGVTOC:
+		case DKIOCGEXTVTOC:
 		case DKIOCGAPART:
 		case DKIOCPARTINFO:
+		case DKIOCEXTPARTINFO:
 		case DKIOCSGEOM:
 		case DKIOCSAPART:
 		case DKIOCGETEFI:
 		case DKIOCPARTITION:
 		case DKIOCSVTOC:
+		case DKIOCSEXTVTOC:
 		case DKIOCSETEFI:
 		case DKIOCGMBOOT:
 		case DKIOCSMBOOT:
@@ -20192,7 +20198,7 @@
 		}
 
 		mutex_exit(SD_MUTEX(un));
-		err = sd_ready_and_valid(un);
+		err = sd_ready_and_valid(un, SDPART(dev));
 		mutex_enter(SD_MUTEX(un));
 
 		if (err != SD_READY_VALID) {
@@ -20241,13 +20247,16 @@
 
 	case DKIOCGGEOM:
 	case DKIOCGVTOC:
+	case DKIOCGEXTVTOC:
 	case DKIOCGAPART:
 	case DKIOCPARTINFO:
+	case DKIOCEXTPARTINFO:
 	case DKIOCSGEOM:
 	case DKIOCSAPART:
 	case DKIOCGETEFI:
 	case DKIOCPARTITION:
 	case DKIOCSVTOC:
+	case DKIOCSEXTVTOC:
 	case DKIOCSETEFI:
 	case DKIOCGMBOOT:
 	case DKIOCSMBOOT:
--- a/usr/src/uts/common/os/dumpsubr.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/os/dumpsubr.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -256,9 +255,9 @@
 		if (VOP_OPEN(&cdev_vp, FREAD | FWRITE, kcred, NULL) == 0) {
 			size_t blk_size;
 			struct dk_cinfo dki;
-			struct vtoc vtoc;
+			struct extvtoc vtoc;
 
-			if (VOP_IOCTL(cdev_vp, DKIOCGVTOC, (intptr_t)&vtoc,
+			if (VOP_IOCTL(cdev_vp, DKIOCGEXTVTOC, (intptr_t)&vtoc,
 			    FKIOCTL, kcred, NULL, NULL) == 0 &&
 			    vtoc.v_sectorsz != 0)
 				blk_size = vtoc.v_sectorsz;
--- a/usr/src/uts/common/sys/cmlb_impl.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/cmlb_impl.h	Thu Sep 11 18:00:50 2008 -0700
@@ -18,16 +18,15 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef _SYS_CMLB_IMPL_H
 #define	_SYS_CMLB_IMPL_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -104,12 +103,18 @@
 #define	CMLB_LABEL_IS_VALID	0
 #define	CMLB_LABEL_IS_INVALID	1
 
+#define	CMLB_2TB_BLOCKS		0xffffffff
+#define	CMLB_1TB_BLOCKS		0x7fffffff
+
+#define	CMLB_EXTVTOC_LIMIT	CMLB_2TB_BLOCKS
+#define	CMLB_OLDVTOC_LIMIT	CMLB_1TB_BLOCKS
+
 /*
  * fdisk partition mapping structure
  */
 struct fmap {
-	daddr_t fmap_start;	/* starting block number */
-	daddr_t fmap_nblk;	/* number of blocks */
+	ulong_t fmap_start;	/* starting block number */
+	ulong_t fmap_nblk;	/* number of blocks */
 };
 
 /* for cm_state */
@@ -125,6 +130,8 @@
 	CMLB_LABEL_EFI
 } cmlb_label_t;
 
+#define	CMLB_ALLOW_2TB_WARN 0x1
+
 
 typedef struct cmlb_lun {
 	dev_info_t	*cl_devi;		/* pointer to devinfo */
@@ -138,6 +145,9 @@
 	uint_t		cl_solaris_offset;	/* offset to Solaris part. */
 
 	struct  dk_map  cl_map[MAXPART];	/* logical partitions */
+						/* cylno is overloaded. used */
+						/* for starting block for EFI */
+
 	diskaddr_t	cl_offset[MAXPART];	/* partition start blocks */
 
 	struct fmap	cl_fmap[FD_NUMPART];	/* fdisk partitions */
@@ -167,7 +177,7 @@
 	cmlb_label_t	cl_cur_labeltype;	/* current label type */
 
 	/* indicates whether vtoc label is read from media */
-	uchar_t		cl_vtoc_label_is_from_media;
+	cmlb_label_t		cl_label_from_media;
 
 	cmlb_state_t	cl_state;		/* state of handle */
 
@@ -184,10 +194,10 @@
 	int		cl_device_type;		/* DTYPE_DIRECT,.. */
 	int		cl_reserved;		/* reserved efi partition # */
 	cmlb_tg_ops_t 	*cmlb_tg_ops;
-
+	uint8_t		cl_msglog_flag;		/* used to enable/suppress */
+						/* certain log messages */
 } cmlb_lun_t;
 
-_NOTE(MUTEX_PROTECTS_DATA(cmlb_lun::cl_mutex, cmlb_lun))
 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cmlb_tg_ops))
 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_devi))
 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_removable))
--- a/usr/src/uts/common/sys/dkio.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/dkio.h	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -26,8 +27,6 @@
 #ifndef _SYS_DKIO_H
 #define	_SYS_DKIO_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS-4.0 5.19 */
-
 #include <sys/dklabel.h>	/* Needed for NDKMAP define */
 
 #ifdef	__cplusplus
@@ -166,6 +165,9 @@
 #define	DKIOCGVTOC	(DKIOC|11)		/* Get VTOC */
 #define	DKIOCSVTOC	(DKIOC|12)		/* Set VTOC & Write to Disk */
 
+#define	DKIOCGEXTVTOC	(DKIOC|23)	/* Get extended VTOC */
+#define	DKIOCSEXTVTOC	(DKIOC|24)	/* Set extended VTOC, Write to Disk */
+
 /*
  * Disk Cache Controls.  These ioctls should be supported by
  * all disk drivers.
@@ -252,6 +254,9 @@
 };
 
 #define	DKIOCPARTINFO	(DKIOC|22)	/* Get partition or slice parameters */
+#define	DKIOCEXTPARTINFO (DKIOC|19)	/* Get extended partition or slice */
+					/* parameters */
+
 
 /*
  * Used by applications to get partition or slice information
@@ -268,6 +273,11 @@
 	int		p_length;
 };
 
+struct extpart_info {
+	diskaddr_t	p_start;
+	diskaddr_t	p_length;
+};
+
 /* The following ioctls are for Optical Memory Device */
 #define	DKIOC_EBP_ENABLE  (DKIOC|40)	/* enable by pass erase on write */
 #define	DKIOC_EBP_DISABLE (DKIOC|41)	/* disable by pass erase on write */
--- a/usr/src/uts/common/sys/dklabel.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/dklabel.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -19,16 +18,15 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 1990-2002 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef _SYS_DKLABEL_H
 #define	_SYS_DKLABEL_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/isa_defs.h>
 #include <sys/types32.h>
 #include <sys/isa_defs.h>
@@ -76,13 +74,24 @@
  * at the beginning of the sector.
  */
 
+#if !defined(BLKADDR_TYPE)
+#define	BLKADDR_TYPE
+#if defined(_EXTVTOC)
+typedef	unsigned long	blkaddr_t;
+typedef	unsigned int	blkaddr32_t;
+#else
+typedef	daddr_t		blkaddr_t;
+typedef	daddr32_t	blkaddr32_t;
+#endif
+#endif
+
 /*
  * partition headers:  section 1
  * Returned in struct dk_allmap by ioctl DKIOC[SG]APART (dkio(7I))
  */
 struct dk_map {
-	daddr_t	dkl_cylno;		/* starting cylinder */
-	daddr_t	dkl_nblk;		/* number of blocks;  if == 0, */
+	blkaddr_t	dkl_cylno;	/* starting cylinder */
+	blkaddr_t	dkl_nblk;	/* number of blocks;  if == 0, */
 					/* partition is undefined */
 };
 
@@ -91,8 +100,8 @@
  * Fixed size for on-disk dk_label
  */
 struct dk_map32 {
-	daddr32_t	dkl_cylno;	/* starting cylinder */
-	daddr32_t	dkl_nblk;	/* number of blocks;  if == 0, */
+	blkaddr32_t	dkl_cylno;	/* starting cylinder */
+	blkaddr32_t	dkl_nblk;	/* number of blocks;  if == 0, */
 					/* partition is undefined */
 };
 
@@ -108,8 +117,8 @@
 struct dkl_partition    {
 	uint16_t	p_tag;		/* ID tag of partition */
 	uint16_t	p_flag;		/* permision flags */
-	daddr32_t	p_start;	/* start sector no of partition */
-	int32_t		p_size;		/* # of blocks in partition */
+	blkaddr32_t	p_start;	/* start sector no of partition */
+	blkaddr32_t	p_size;		/* # of blocks in partition */
 };
 
 
--- a/usr/src/uts/common/sys/dktp/altsctr.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/dktp/altsctr.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -36,8 +36,6 @@
 #ifndef _SYS_DKTP_ALTSCTR_H
 #define	_SYS_DKTP_ALTSCTR_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -46,20 +44,20 @@
 struct	alts_parttbl {
 	uint32_t	alts_sanity;	/* to validate correctness	*/
 	uint32_t  	alts_version;	/* version number		*/
-	daddr32_t	alts_map_base;	/* disk offset of alts_partmap	*/
+	uint32_t	alts_map_base;	/* disk offset of alts_partmap	*/
 	uint32_t	alts_map_len;	/* byte length of alts_partmap	*/
-	daddr32_t	alts_ent_base;	/* disk offset of alts_entry	*/
+	uint32_t	alts_ent_base;	/* disk offset of alts_entry	*/
 	uint32_t	alts_ent_used;	/* number of alternate entries used */
-	daddr32_t	alts_ent_end;	/* disk offset of top of alts_entry */
-	daddr32_t	alts_resv_base;	/* disk offset of alts_reserved	*/
+	uint32_t	alts_ent_end;	/* disk offset of top of alts_entry */
+	uint32_t	alts_resv_base;	/* disk offset of alts_reserved	*/
 	uint32_t 	alts_pad[5];	/* reserved fields		*/
 };
 
 /*	alternate sector remap entry table				*/
 struct	alts_ent {
-	daddr32_t	bad_start;	/* starting bad sector number	*/
-	daddr32_t	bad_end;	/* ending bad sector number	*/
-	daddr32_t	good_start;	/* starting alternate sector to use */
+	uint32_t	bad_start;	/* starting bad sector number	*/
+	uint32_t	bad_end;	/* ending bad sector number	*/
+	uint32_t	good_start;	/* starting alternate sector to use */
 };
 
 /*	size of alternate partition table structure			*/
--- a/usr/src/uts/common/sys/dktp/dadkio.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/dktp/dadkio.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -19,16 +18,15 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef _SYS_DKTP_DADKIO_H
 #define	_SYS_DKTP_DADKIO_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -40,6 +38,18 @@
 #define	DIOCTL_GETSERIAL	4	/* get serial number		*/
 #define	DIOCTL_RWCMD		5	/* read/write a disk		*/
 #define	DIOCTL_GETWCE		6	/* get write cache enabled state */
+
+#if !defined(BLKADDR_TYPE)
+#define	BLKADDR_TYPE
+#if defined(_EXTVTOC)
+typedef	unsigned long	blkaddr_t;
+typedef	unsigned int	blkaddr32_t;
+#else
+typedef	daddr_t		blkaddr_t;
+typedef	daddr32_t	blkaddr32_t;
+#endif
+#endif
+
 /*
  * arg structure for DIOCTL_GETMODEL and DIOCTL_GETSERIAL
  * On input to the ioctl, is_size contains the size of the buffer
@@ -158,7 +168,7 @@
 	int		status;
 	ulong_t		resid;
 	int		failed_blk_is_valid;
-	daddr_t		failed_blk;
+	blkaddr_t	failed_blk;
 	int		fru_code_is_valid;
 	int		fru_code;
 	char		add_error_info[DADKIO_ERROR_INFO_LEN];
@@ -169,7 +179,7 @@
 	int		status;
 	uint32_t	resid;
 	int		failed_blk_is_valid;
-	daddr32_t	failed_blk;
+	blkaddr32_t	failed_blk;
 	int		fru_code_is_valid;
 	int		fru_code;
 	char		add_error_info[DADKIO_ERROR_INFO_LEN];
@@ -182,7 +192,7 @@
 struct dadkio_rwcmd {
 	int			cmd;
 	int			flags;
-	daddr_t			blkaddr;
+	blkaddr_t		blkaddr;
 	uint_t			buflen;
 	caddr_t			bufaddr;
 	struct dadkio_status	status;
@@ -192,7 +202,7 @@
 struct dadkio_rwcmd32 {
 	int			cmd;
 	int			flags;
-	daddr32_t		blkaddr;
+	blkaddr32_t		blkaddr;
 	uint_t			buflen;
 	caddr32_t		bufaddr;
 	struct dadkio_status32	status;
--- a/usr/src/uts/common/sys/dktp/fdisk.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/dktp/fdisk.h	Thu Sep 11 18:00:50 2008 -0700
@@ -18,8 +18,9 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 /*	Copyright (c) 1984, 1986, 1987, 1988 AT&T	*/
@@ -29,8 +30,6 @@
 #ifndef _SYS_DKTP_FDISK_H
 #define	_SYS_DKTP_FDISK_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -70,8 +69,8 @@
 	unsigned char endhead;	/* ending head, sector, cylinder */
 	unsigned char endsect;	/* endcyl is a 10-bit number.  High 2 bits */
 	unsigned char endcyl;	/*	are in endsect. */
-	int	relsect;	/* first sector relative to start of disk */
-	int	numsect;	/* number of sectors in partition */
+	uint32_t relsect;	/* first sector relative to start of disk */
+	uint32_t numsect;	/* number of sectors in partition */
 };
 /*
  * Values for bootid.
--- a/usr/src/uts/common/sys/dktp/gda.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/dktp/gda.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -19,16 +18,15 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef _SYS_DKTP_GDA_H
 #define	_SYS_DKTP_GDA_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -44,7 +42,7 @@
 extern void	gda_log(dev_info_t *, char *, uint_t, const char *, ...)
 	__KPRINTFLIKE(4);
 extern void	gda_errmsg(struct scsi_device *, struct cmpkt *, char *,
-			int, int, int, char **, char **);
+			int, daddr_t, daddr_t, char **, char **);
 extern struct 	cmpkt *gda_pktprep(opaque_t objp, struct cmpkt *in_pktp,
 			opaque_t dmatoken, int (*func)(caddr_t), caddr_t arg);
 extern void	gda_free(opaque_t objp, struct cmpkt *pktp, struct buf *bp);
--- a/usr/src/uts/common/sys/dktp/tgdk.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/dktp/tgdk.h	Thu Sep 11 18:00:50 2008 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -19,16 +18,15 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef _SYS_DKTP_TGDK_H
 #define	_SYS_DKTP_TGDK_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -68,7 +66,7 @@
 	int	g_head;
 	int	g_sec;
 	int	g_secsiz;
-	int	g_cap;
+	diskaddr_t 	g_cap;
 };
 
 struct	tgdk_objops {
--- a/usr/src/uts/common/sys/lvm/mdvar.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/lvm/mdvar.h	Thu Sep 11 18:00:50 2008 -0700
@@ -18,16 +18,15 @@
  *
  * CDDL HEADER END
  */
+
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef	_SYS_MDVAR_H
 #define	_SYS_MDVAR_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/kmem.h>
 #include <sys/mkdev.h>
@@ -741,7 +740,7 @@
 extern int	md_checkpid(pid_t pid, proc_t *proc);
 extern char	*md_strdup(char *cp);
 extern void	freestr(char *cp);
-extern int	md_check_ioctl_against_efi(int, ushort_t);
+extern int	md_check_ioctl_against_unit(int, mdc_unit_t);
 extern mddb_recid_t md_vtoc_to_efi_record(mddb_recid_t, set_t);
 
 extern int	mdmn_ksend_message(set_t, md_mn_msgtype_t, uint_t, char *, int,
@@ -761,8 +760,10 @@
 extern void	md_mn_clear_commd_present(void);
 extern int	md_admin_ioctl(md_dev64_t, int, caddr_t, int, IOLOCK *lockp);
 extern void	md_get_geom(md_unit_t *, struct dk_geom *);
+extern int	md_set_vtoc(md_unit_t *, struct vtoc *);
 extern void	md_get_vtoc(md_unit_t *, struct vtoc *);
-extern int	md_set_vtoc(md_unit_t *, struct vtoc *);
+extern int	md_set_extvtoc(md_unit_t *, struct extvtoc *);
+extern void	md_get_extvtoc(md_unit_t *, struct extvtoc *);
 extern void	md_get_cgapart(md_unit_t *, struct dk_map *);
 extern void	md_get_efi(md_unit_t *, char *);
 extern int	md_set_efi(md_unit_t *, char *);
--- a/usr/src/uts/common/sys/lvm/meta_basic.x	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/lvm/meta_basic.x	Thu Sep 11 18:00:50 2008 -0700
@@ -24,8 +24,6 @@
 % * Use is subject to license terms.
 % */
 %
-%#pragma ident	"%Z%%M%	%I%	%E% SMI"
-%
 
 %/* get timeval32 definition */
 %#include <sys/types32.h>
@@ -239,6 +237,7 @@
 const	MD_MAXDRVNM = 16;
 
 const	MD_MAX_BLKS_FOR_SMALL_DEVS = 2147483647;
+%#define	MD_MAX_BLKS_FOR_EXTVTOC	4294967295ULL
 %
 %/* Minimum number of metadevice database replicas needed */
 const	MD_MINREPLICAS = 1;
--- a/usr/src/uts/common/sys/vtoc.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/sys/vtoc.h	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -31,8 +32,6 @@
 #ifndef _SYS_VTOC_H
 #define	_SYS_VTOC_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/dklabel.h>
 
 #ifdef	__cplusplus
@@ -63,6 +62,7 @@
 
 #define	VTOC_SANE	0x600DDEEE	/* Indicates a sane VTOC */
 #define	V_VERSION	0x01		/* layout version number */
+#define	V_EXTVERSION	V_VERSION	/* extvtoc layout version number */
 
 /*
  * Partition identification tags
@@ -94,10 +94,11 @@
 #define	VT_EINVAL	(-4)		/* illegal value in vtoc or request */
 #define	VT_ENOTSUP	(-5)		/* VTOC op. not supported */
 #define	VT_ENOSPC	(-6)		/* requested space not found */
+#define	VT_EOVERFLOW	(-7)		/* VTOC op. data struct limited */
 
 struct partition	{
 	ushort_t p_tag;			/* ID tag of partition */
-	ushort_t p_flag;			/* permision flags */
+	ushort_t p_flag;		/* permission flags */
 	daddr_t	p_start;		/* start sector no of partition */
 	long	p_size;			/* # of blocks in partition */
 };
@@ -115,10 +116,83 @@
 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
 };
 
+struct extpartition {
+	ushort_t p_tag;			/* ID tag of partition */
+	ushort_t p_flag;		/* permission flags */
+	ushort_t p_pad[2];
+	diskaddr_t p_start;		/* start sector no of partition */
+	diskaddr_t p_size;			/* # of blocks in partition */
+};
+
+
+struct extvtoc {
+	uint64_t	v_bootinfo[3];	/* info needed by mboot (unsupported) */
+	uint64_t	v_sanity;	/* to verify vtoc sanity */
+	uint64_t	v_version;	/* layout version */
+	char	v_volume[LEN_DKL_VVOL];	/* volume name */
+	ushort_t	v_sectorsz;	/* sector size in bytes */
+	ushort_t	v_nparts;	/* number of partitions */
+	ushort_t	pad[2];
+	uint64_t	v_reserved[10];
+	struct extpartition v_part[V_NUMPAR]; /* partition headers */
+	uint64_t timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
+	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
+};
+
+#ifdef _KERNEL
+#define	extvtoctovtoc(extv, v)						\
+	{								\
+	int i;								\
+	v.v_bootinfo[0]		= (unsigned long)extv.v_bootinfo[0];	\
+	v.v_bootinfo[1]		= (unsigned long)extv.v_bootinfo[1];	\
+	v.v_bootinfo[2]		= (unsigned long)extv.v_bootinfo[2];	\
+	v.v_sanity		= (unsigned long)extv.v_sanity;		\
+	v.v_version		= (unsigned long)extv.v_version;	\
+	bcopy(extv.v_volume, v.v_volume, LEN_DKL_VVOL);			\
+	v.v_sectorsz		= extv.v_sectorsz;			\
+	v.v_nparts		= extv.v_nparts;			\
+	for (i = 0; i < 10; i++)					\
+		v.v_reserved[i] = (unsigned long)extv.v_reserved[i];	\
+	for (i = 0; i < V_NUMPAR; i++) {				\
+		v.v_part[i].p_tag = extv.v_part[i].p_tag;		\
+		v.v_part[i].p_flag = extv.v_part[i].p_flag;		\
+		v.v_part[i].p_start = (daddr_t)extv.v_part[i].p_start;	\
+		v.v_part[i].p_size = (long)extv.v_part[i].p_size;	\
+		v.timestamp[i] = (time_t)v.timestamp[i];		\
+	}								\
+	bcopy(extv.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII);	\
+	}
+
+#define	vtoctoextvtoc(v, extv)						\
+	{								\
+	int i;								\
+	extv.v_bootinfo[0]	= (uint64_t)v.v_bootinfo[0];		\
+	extv.v_bootinfo[1]	= (uint64_t)v.v_bootinfo[1];		\
+	extv.v_bootinfo[2]	= (uint64_t)v.v_bootinfo[2];		\
+	extv.v_sanity		= (uint64_t)v.v_sanity;			\
+	extv.v_version		= (uint64_t)v.v_version;		\
+	bcopy(v.v_volume, extv.v_volume, LEN_DKL_VVOL);			\
+	extv.v_sectorsz		= v.v_sectorsz;				\
+	extv.v_nparts		= v.v_nparts;				\
+	for (i = 0; i < 10; i++)					\
+		extv.v_reserved[i] = (uint64_t)v.v_reserved[i];		\
+	for (i = 0; i < V_NUMPAR; i++) {				\
+		extv.v_part[i].p_tag = v.v_part[i].p_tag;		\
+		extv.v_part[i].p_flag = v.v_part[i].p_flag;		\
+		extv.v_part[i].p_start =				\
+		    (diskaddr_t)(unsigned long)v.v_part[i].p_start;	\
+		extv.v_part[i].p_size =					\
+		    (diskaddr_t)(unsigned long)v.v_part[i].p_size;	\
+		extv.timestamp[i] = (uint64_t)v.timestamp[i];		\
+	}								\
+	bcopy(v.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII);	\
+	}
+#endif /* _KERNEL */
+
 #if defined(_SYSCALL32)
 struct partition32	{
 	uint16_t	p_tag;		/* ID tag of partition */
-	uint16_t	p_flag;		/* permision flags */
+	uint16_t	p_flag;		/* permission flags */
 	daddr32_t	p_start;	/* start sector no of partition */
 	int32_t		p_size;		/* # of blocks in partition */
 };
@@ -153,14 +227,39 @@
 	for (i = 0; i < V_NUMPAR; i++) {		\
 		v.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag;	\
 		v.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag;	\
-		v.v_part[i].p_start = (daddr_t)v32.v_part[i].p_start;	\
-		v.v_part[i].p_size = (long)v32.v_part[i].p_size;	\
+		v.v_part[i].p_start = (unsigned)v32.v_part[i].p_start;	\
+		v.v_part[i].p_size = (unsigned)v32.v_part[i].p_size;	\
 	}						\
 	for (i = 0; i < V_NUMPAR; i++)			\
 		v.timestamp[i] = (time_t)v32.timestamp[i];		\
 	bcopy(v32.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII);		\
 	}
 
+#define	vtoc32toextvtoc(v32, extv)					\
+	{								\
+	int i;								\
+	extv.v_bootinfo[0]		= v32.v_bootinfo[0];		\
+	extv.v_bootinfo[1]		= v32.v_bootinfo[1];		\
+	extv.v_bootinfo[2]		= v32.v_bootinfo[2];		\
+	extv.v_sanity		= v32.v_sanity;				\
+	extv.v_version		= v32.v_version;			\
+	bcopy(v32.v_volume, extv.v_volume, LEN_DKL_VVOL);		\
+	extv.v_sectorsz		= v32.v_sectorsz;			\
+	extv.v_nparts		= v32.v_nparts;				\
+	extv.v_version		= v32.v_version;			\
+	for (i = 0; i < 10; i++)					\
+		extv.v_reserved[i] = v32.v_reserved[i];			\
+	for (i = 0; i < V_NUMPAR; i++) {				\
+		extv.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag;	\
+		extv.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag;	\
+		extv.v_part[i].p_start = (diskaddr_t)v32.v_part[i].p_start; \
+		extv.v_part[i].p_size = (diskaddr_t)v32.v_part[i].p_size; \
+		extv.timestamp[i] = (time_t)v32.timestamp[i];		\
+	}								\
+	bcopy(v32.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII);	\
+	}
+
+
 #define	vtoctovtoc32(v, v32)				\
 	{						\
 	int i;						\
@@ -178,8 +277,8 @@
 	for (i = 0; i < V_NUMPAR; i++) {		\
 		v32.v_part[i].p_tag = (ushort_t)v.v_part[i].p_tag;	\
 		v32.v_part[i].p_flag = (ushort_t)v.v_part[i].p_flag;	\
-		v32.v_part[i].p_start = (daddr32_t)v.v_part[i].p_start;	\
-		v32.v_part[i].p_size = (int32_t)v.v_part[i].p_size;	\
+		v32.v_part[i].p_start = (unsigned)v.v_part[i].p_start;	\
+		v32.v_part[i].p_size = (unsigned)v.v_part[i].p_size;	\
 	}						\
 	for (i = 0; i < V_NUMPAR; i++) {		\
 		if (v.timestamp[i] > TIME32_MAX)	\
@@ -190,6 +289,36 @@
 	bcopy(v.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII);		\
 	}
 
+#define	extvtoctovtoc32(extv, v32)				\
+	{						\
+	int i;						\
+	v32.v_bootinfo[0]	= extv.v_bootinfo[0];	\
+	v32.v_bootinfo[1]	= extv.v_bootinfo[1];	\
+	v32.v_bootinfo[2]	= extv.v_bootinfo[2];	\
+	v32.v_sanity		= extv.v_sanity;		\
+	v32.v_version		= extv.v_version;		\
+	bcopy(extv.v_volume, v32.v_volume, LEN_DKL_VVOL);	\
+	v32.v_sectorsz		= extv.v_sectorsz;		\
+	v32.v_nparts		= extv.v_nparts;		\
+	v32.v_version		= extv.v_version;		\
+	for (i = 0; i < 10; i++)			\
+		v32.v_reserved[i] = extv.v_reserved[i];	\
+	for (i = 0; i < V_NUMPAR; i++) {		\
+		v32.v_part[i].p_tag = (ushort_t)extv.v_part[i].p_tag;	\
+		v32.v_part[i].p_flag = (ushort_t)extv.v_part[i].p_flag;	\
+		v32.v_part[i].p_start = (unsigned)extv.v_part[i].p_start; \
+		v32.v_part[i].p_size = (unsigned)extv.v_part[i].p_size;	\
+	}						\
+	for (i = 0; i < V_NUMPAR; i++) {		\
+		if (extv.timestamp[i] > TIME32_MAX)	\
+			v32.timestamp[i] = TIME32_MAX;	\
+		else 					\
+			v32.timestamp[i] = (time32_t)extv.timestamp[i];	\
+	}						\
+	bcopy(extv.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII);	\
+	}
+
+
 #endif /* _SYSCALL32 */
 
 /*
@@ -202,11 +331,15 @@
 
 extern	int	read_vtoc(int, struct vtoc *);
 extern	int	write_vtoc(int, struct vtoc *);
+extern	int	read_extvtoc(int, struct extvtoc *);
+extern	int	write_extvtoc(int, struct extvtoc *);
 
 #else
 
 extern	int	read_vtoc();
 extern	int	write_vtoc();
+extern	int	read_extvtoc();
+extern	int	write_extvtoc();
 
 #endif 	/* __STDC__ */
 
--- a/usr/src/uts/common/xen/io/xdf.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/common/xen/io/xdf.c	Thu Sep 11 18:00:50 2008 -0700
@@ -1137,6 +1137,9 @@
 	case DKIOCGVTOC:
 	case DKIOCSVTOC:
 	case DKIOCPARTINFO:
+	case DKIOCGEXTVTOC:
+	case DKIOCSEXTVTOC:
+	case DKIOCEXTPARTINFO:
 	case DKIOCGMBOOT:
 	case DKIOCSMBOOT:
 	case DKIOCGETEFI:
@@ -1882,6 +1885,18 @@
 		return (DDI_FAILURE);
 	}
 
+#ifdef _ILP32
+	if (vdp->xdf_xdev_nblocks > DK_MAX_BLOCKS) {
+		cmn_err(CE_WARN, "xdf_post_connect: xdf@%s: "
+		    "backend disk device too large with %llu blocks for"
+		    " 32-bit kernel", ddi_get_name_addr(devi),
+		    vdp->xdf_xdev_nblocks);
+		xvdi_fatal_error(devi, rv, "reading backend info");
+		return (DDI_FAILURE);
+	}
+#endif
+
+
 	/*
 	 * Only update the physical geometry to reflect the new device
 	 * size if this is the first time we're connecting to the backend
--- a/usr/src/uts/i86pc/i86hvm/io/pv_cmdk.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/i86pc/i86hvm/io/pv_cmdk.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,13 +18,12 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/scsi/scsi_types.h>
 #include <sys/modctl.h>
 #include <sys/cmlb.h>
@@ -732,7 +731,7 @@
 
 			rwcmdp->cmd = cmd32.cmd;
 			rwcmdp->flags = cmd32.flags;
-			rwcmdp->blkaddr = (daddr_t)cmd32.blkaddr;
+			rwcmdp->blkaddr = (blkaddr_t)cmd32.blkaddr;
 			rwcmdp->buflen = cmd32.buflen;
 			rwcmdp->bufaddr = (caddr_t)(intptr_t)cmd32.bufaddr;
 			/*
--- a/usr/src/uts/i86pc/i86hvm/pv_cmdk/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/i86pc/i86hvm/pv_cmdk/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -24,8 +24,6 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	This makefile drives the production of the xdc driver.
 #
 #	i86pc implementation architecture dependent
@@ -66,6 +64,9 @@
 LDFLAGS		+= -dy -Nmisc/strategy -Nmisc/cmlb
 LDFLAGS		+= -Ndrv/xpvd -Ndrv/xdf
 
+CPPFLAGS	+= -D_EXTVTOC
+
+
 #
 # The Xen header files do not lint cleanly.  Since the troublesome
 # structures form part of the externally defined interface to the
--- a/usr/src/uts/intel/Makefile.intel.shared	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/intel/Makefile.intel.shared	Thu Sep 11 18:00:50 2008 -0700
@@ -477,7 +477,7 @@
 #
 #	File System Modules (/kernel/fs):
 #
-FS_KMODS	+= autofs cachefs ctfs dev devfs fdfs fifofs hsfs lofs
+FS_KMODS	+= autofs cachefs ctfs dcfs dev devfs fdfs fifofs hsfs lofs
 FS_KMODS	+= lx_afs lx_proc mntfs namefs nfs objfs zfs
 FS_KMODS	+= pcfs procfs sockfs specfs tmpfs udfs ufs sharefs
 FS_KMODS	+= smbfs
--- a/usr/src/uts/intel/cmdk/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/intel/cmdk/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -21,11 +21,9 @@
 #
 # uts/intel/cmdk/Makefile
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	This makefile drives the production of the cmdk driver
 #	kernel module.
 #
@@ -65,6 +63,9 @@
 DEBUG_DEFS	+= $(DEBUG_FLGS)
 LDFLAGS		+= -dy -Nmisc/dadk -Nmisc/strategy -Nmisc/cmlb
 
+# Larger than 1TB VTOC support
+CPPFLAGS	+= -D_EXTVTOC
+
 #
 # For now, disable these lint checks; maintainers should endeavor
 # to investigate and remove these for maximum lint coverage.
--- a/usr/src/uts/intel/cmlb/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/intel/cmlb/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -20,11 +20,9 @@
 #
 
 #
-# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	This makefile drives the production of the cmlb "misc"
 #	kernel module.
 #
@@ -64,6 +62,10 @@
 DEBUG_FLGS	=
 DEBUG_DEFS	+= $(DEBUG_FLGS)
 
+# enable larger than 1TB VTOC support
+
+CPPFLAGS	+= -D_EXTVTOC
+
 #
 # For now, disable these lint checks; maintainers should endeavor
 # to investigate and remove these for maximum lint coverage.
--- a/usr/src/uts/intel/dadk/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/intel/dadk/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -21,11 +21,9 @@
 #
 # uts/intel/dadk/Makefile
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	This makefile drives the production of the dadk "misc"
 #	kernel module.
 #
@@ -64,6 +62,10 @@
 DEBUG_DEFS	+= $(DEBUG_FLGS)
 LDFLAGS		+= -dy -Nmisc/gda
 
+# Larger than 1TB VTOC support
+
+CPPFLAGS	+= -D_EXTVTOC
+
 #
 # For now, disable these lint checks; maintainers should endeavor
 # to investigate and remove these for maximum lint coverage.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/uts/intel/dcfs/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -0,0 +1,85 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# uts/intel/dcfs/Makefile
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#	This makefile drives the production of the dcfs file system
+#	kernel module.
+#
+#
+
+#
+#	Path to the base of the uts directory tree (usually /usr/src/uts).
+#
+UTSBASE	= ../..
+
+#
+#	Define the module and object file sets.
+#
+MODULE		= dcfs
+OBJECTS		= $(DCFS_OBJS:%=$(OBJS_DIR)/%)
+LINTS		= $(DCFS_OBJS:%.o=$(LINTS_DIR)/%.ln)
+ROOTMODULE	= $(ROOT_FS_DIR)/$(MODULE)
+
+#
+#	Include common rules.
+#
+include $(UTSBASE)/intel/Makefile.intel
+
+#
+#	Define targets
+#
+ALL_TARGET	= $(BINARY)
+LINT_TARGET	= $(MODULE).lint
+INSTALL_TARGET	= $(BINARY) $(ROOTMODULE)
+
+#
+#	Overrides.
+#
+CFLAGS		+= $(CCVERBOSE)
+
+#
+#	Default build targets.
+#
+.KEEP_STATE:
+
+def:		$(DEF_DEPS)
+
+all:		$(ALL_DEPS)
+
+clean:		$(CLEAN_DEPS)
+
+clobber:	$(CLOBBER_DEPS)
+
+lint:		$(LINT_DEPS)
+
+modlintlib:	$(MODLINTLIB_DEPS)
+
+clean.lint:	$(CLEAN_LINT_DEPS)
+
+install:	$(INSTALL_DEPS)
+
+#
+#	Include common targets.
+#
+include $(UTSBASE)/intel/Makefile.targ
--- a/usr/src/uts/intel/io/dktp/dcdev/dadk.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/intel/io/dktp/dcdev/dadk.c	Thu Sep 11 18:00:50 2008 -0700
@@ -24,8 +24,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Direct Attached Disk
  */
@@ -1388,7 +1386,7 @@
 static int
 dadk_chkerr(struct cmpkt *pktp)
 {
-	int err_blkno;
+	daddr_t err_blkno;
 	struct dadk *dadkp = PKT2DADK(pktp);
 	dadk_errstats_t *dep;
 	int scb = *(char *)pktp->cp_scbp;
--- a/usr/src/uts/intel/io/dktp/dcdev/gda.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/intel/io/dktp/dcdev/gda.c	Thu Sep 11 18:00:50 2008 -0700
@@ -20,12 +20,10 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/scsi/scsi.h>
 
 #include <sys/dktp/dadev.h>
@@ -204,8 +202,8 @@
 	if (dev) {
 		if (level == CE_PANIC || level == CE_WARN) {
 			(void) sprintf(name, "%s (%s%d):\n",
-				ddi_pathname(dev, buf), label,
-				ddi_get_instance(dev));
+			    ddi_pathname(dev, buf), label,
+			    ddi_get_instance(dev));
 		} else if (level == CE_NOTE ||
 		    level >= (uint_t)SCSI_DEBUG) {
 			(void) sprintf(name,
@@ -246,7 +244,7 @@
 
 void
 gda_errmsg(struct scsi_device *devp, struct cmpkt *pktp, char *label,
-    int severity, int blkno, int err_blkno,
+    int severity, daddr_t blkno, daddr_t err_blkno,
     char **cmdvec, char **senvec)
 {
 	auto char buf[256];
@@ -258,27 +256,27 @@
 
 	bzero((caddr_t)buf, 256);
 	(void) sprintf(buf, "Error for command '%s'\tError Level: %s",
-		gda_name(*(uchar_t *)pktp->cp_cdbp, cmdvec),
-		error_classes[severity]);
+	    gda_name(*(uchar_t *)pktp->cp_cdbp, cmdvec),
+	    error_classes[severity]);
 	gda_log(dev, label, CE_WARN, buf);
 
 	bzero((caddr_t)buf, 256);
 	if ((blkno != -1) && (err_blkno != -1)) {
-		(void) sprintf(buf, "Requested Block %d, Error Block: %d\n",
+		(void) sprintf(buf, "Requested Block %ld, Error Block: %ld\n",
 		    blkno, err_blkno);
 		gda_log(dev, label, CE_CONT, buf);
 	}
 
 	bzero((caddr_t)buf, 256);
 	(void) sprintf(buf, "Sense Key: %s\n",
-		gda_name(*(uchar_t *)pktp->cp_scbp, senvec));
+	    gda_name(*(uchar_t *)pktp->cp_scbp, senvec));
 
 	gda_log(dev, label, CE_CONT, buf);
 	bzero((caddr_t)buf, 256);
 	(void) strcpy(buf, "Vendor '");
 	gda_inqfill(devp->sd_inq->inq_vid, 8, &buf[strlen(buf)]);
 	(void) sprintf(&buf[strlen(buf)],
-		"' error code: 0x%x",
-		*(uchar_t *)pktp->cp_scbp);
+	    "' error code: 0x%x",
+	    *(uchar_t *)pktp->cp_scbp);
 	gda_log(dev, label, CE_CONT, "%s\n", buf);
 }
--- a/usr/src/uts/intel/io/dktp/disk/cmdk.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/intel/io/dktp/disk/cmdk.c	Thu Sep 11 18:00:50 2008 -0700
@@ -18,6 +18,7 @@
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
@@ -379,6 +380,18 @@
 	if (dadk_open(DKTP_DATA, 0) != DDI_SUCCESS)
 		goto fail2;
 
+#ifdef _ILP32
+	{
+		struct  tgdk_geom phyg;
+		(void) dadk_getphygeom(DKTP_DATA, &phyg);
+		if ((phyg.g_cap - 1) > DK_MAX_BLOCKS) {
+			(void) dadk_close(DKTP_DATA);
+			goto fail2;
+		}
+	}
+#endif
+
+
 	/* mark as having opened target */
 	dkp->dk_flag |= CMDK_TGDK_OPEN;
 
@@ -764,7 +777,7 @@
 
 			rwcmdp->cmd = cmd32.cmd;
 			rwcmdp->flags = cmd32.flags;
-			rwcmdp->blkaddr = (daddr_t)cmd32.blkaddr;
+			rwcmdp->blkaddr = (blkaddr_t)cmd32.blkaddr;
 			rwcmdp->buflen = cmd32.buflen;
 			rwcmdp->bufaddr = (caddr_t)(intptr_t)cmd32.bufaddr;
 			/*
@@ -971,6 +984,9 @@
 	case DKIOCGVTOC:
 	case DKIOCSVTOC:
 	case DKIOCPARTINFO:
+	case DKIOCGEXTVTOC:
+	case DKIOCSEXTVTOC:
+	case DKIOCEXTPARTINFO:
 	case DKIOCGMBOOT:
 	case DKIOCSMBOOT:
 	case DKIOCGETEFI:
--- a/usr/src/uts/sparc/cmlb/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/sparc/cmlb/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -1,11 +1,29 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
 #
 # uts/sparc/cmlb/Makefile
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	This makefile drives the production of the cmlb "misc"
 #	kernel module.
 #
@@ -43,6 +61,10 @@
 DEBUG_FLGS	=
 DEBUG_DEFS	+= $(DEBUG_FLGS)
 
+# Larger than 1TB VTOC
+
+CPPFLAGS	+= -D_EXTVTOC
+
 #
 # For now, disable these lint checks; maintainers should endeavor
 # to investigate and remove these for maximum lint coverage.
--- a/usr/src/uts/sun4v/io/vdc.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/sun4v/io/vdc.c	Thu Sep 11 18:00:50 2008 -0700
@@ -24,7 +24,6 @@
  * Use is subject to license terms.
  */
 
-
 /*
  * LDoms virtual disk client (vdc) device driver
  *
@@ -98,6 +97,8 @@
 #include <sys/vdsk_mailbox.h>
 #include <sys/vdc.h>
 
+#define	VD_OLDVTOC_LIMIT	0x7fffffff
+
 /*
  * function prototypes
  */
@@ -144,7 +145,8 @@
 static void	vdc_destroy_descriptor_ring(vdc_t *vdc);
 static int	vdc_setup_devid(vdc_t *vdc);
 static void	vdc_store_label_efi(vdc_t *, efi_gpt_t *, efi_gpe_t *);
-static void	vdc_store_label_vtoc(vdc_t *, struct dk_geom *, struct vtoc *);
+static void	vdc_store_label_vtoc(vdc_t *, struct dk_geom *,
+		    struct extvtoc *);
 static void	vdc_store_label_unk(vdc_t *vdc);
 static boolean_t vdc_is_opened(vdc_t *vdc);
 static void	vdc_update_size(vdc_t *vdc, size_t, size_t, size_t);
@@ -204,6 +206,10 @@
 		    int mode, int dir);
 static int	vdc_set_vtoc_convert(vdc_t *vdc, void *from, void *to,
 		    int mode, int dir);
+static int	vdc_get_extvtoc_convert(vdc_t *vdc, void *from, void *to,
+		    int mode, int dir);
+static int	vdc_set_extvtoc_convert(vdc_t *vdc, void *from, void *to,
+		    int mode, int dir);
 static int	vdc_get_geom_convert(vdc_t *vdc, void *from, void *to,
 		    int mode, int dir);
 static int	vdc_set_geom_convert(vdc_t *vdc, void *from, void *to,
@@ -555,7 +561,7 @@
 		kmem_free(vdc->cinfo, sizeof (struct dk_cinfo));
 
 	if (vdc->vtoc)
-		kmem_free(vdc->vtoc, sizeof (struct vtoc));
+		kmem_free(vdc->vtoc, sizeof (struct extvtoc));
 
 	if (vdc->geom)
 		kmem_free(vdc->geom, sizeof (struct dk_geom));
@@ -675,7 +681,7 @@
 
 	/* Initialize remaining structures before starting the msg thread */
 	vdc->vdisk_label = VD_DISK_LABEL_UNK;
-	vdc->vtoc = kmem_zalloc(sizeof (struct vtoc), KM_SLEEP);
+	vdc->vtoc = kmem_zalloc(sizeof (struct extvtoc), KM_SLEEP);
 	vdc->geom = kmem_zalloc(sizeof (struct dk_geom), KM_SLEEP);
 	vdc->minfo = kmem_zalloc(sizeof (struct dk_minfo), KM_SLEEP);
 
@@ -5148,7 +5154,7 @@
 vdc_dkio_gapart(vdc_t *vdc, caddr_t arg, int flag)
 {
 	struct dk_geom *geom;
-	struct vtoc *vtoc;
+	struct extvtoc *vtoc;
 	union {
 		struct dk_map map[NDKMAP];
 		struct dk_map32 map32[NDKMAP];
@@ -5162,6 +5168,11 @@
 		return (rv);
 	}
 
+	if (vdc->vdisk_size > VD_OLDVTOC_LIMIT) {
+		mutex_exit(&vdc->lock);
+		return (EOVERFLOW);
+	}
+
 	vtoc = vdc->vtoc;
 	geom = vdc->geom;
 
@@ -6621,6 +6632,10 @@
 		vdc_get_vtoc_convert},
 	{VD_OP_SET_VTOC,	DKIOCSVTOC,		sizeof (vd_vtoc_t),
 		vdc_set_vtoc_convert},
+	{VD_OP_GET_VTOC,	DKIOCGEXTVTOC,		sizeof (vd_vtoc_t),
+		vdc_get_extvtoc_convert},
+	{VD_OP_SET_VTOC,	DKIOCSEXTVTOC,		sizeof (vd_vtoc_t),
+		vdc_set_extvtoc_convert},
 	{VD_OP_GET_DISKGEOM,	DKIOCGGEOM,		sizeof (vd_geom_t),
 		vdc_get_geom_convert},
 	{VD_OP_GET_DISKGEOM,	DKIOCG_PHYGEOM,		sizeof (vd_geom_t),
@@ -7162,12 +7177,10 @@
 vdc_get_vtoc_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
 {
 	int		i;
-	void		*tmp_mem = NULL;
-	void		*tmp_memp;
-	struct vtoc	vt;
-	struct vtoc32	vt32;
-	int		copy_len = 0;
-	int		rv = 0;
+	struct vtoc	vtoc;
+	struct vtoc32	vtoc32;
+	struct extvtoc	evtoc;
+	int		rv;
 
 	if (dir != VD_COPYOUT)
 		return (0);	/* nothing to do */
@@ -7175,32 +7188,29 @@
 	if ((from == NULL) || (to == NULL))
 		return (ENXIO);
 
-	if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32)
-		copy_len = sizeof (struct vtoc32);
-	else
-		copy_len = sizeof (struct vtoc);
-
-	tmp_mem = kmem_alloc(copy_len, KM_SLEEP);
-
-	VD_VTOC2VTOC((vd_vtoc_t *)from, &vt);
+	if (vdc->vdisk_size > VD_OLDVTOC_LIMIT)
+		return (EOVERFLOW);
+
+	VD_VTOC2VTOC((vd_vtoc_t *)from, &evtoc);
 
 	/* fake the VTOC timestamp field */
 	for (i = 0; i < V_NUMPAR; i++) {
-		vt.timestamp[i] = vdc->vtoc->timestamp[i];
+		evtoc.timestamp[i] = vdc->vtoc->timestamp[i];
 	}
 
 	if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
 		/* LINTED E_ASSIGN_NARROW_CONV */
-		vtoctovtoc32(vt, vt32);
-		tmp_memp = &vt32;
+		extvtoctovtoc32(evtoc, vtoc32);
+		rv = ddi_copyout(&vtoc32, to, sizeof (vtoc32), mode);
+		if (rv != 0)
+			rv = EFAULT;
 	} else {
-		tmp_memp = &vt;
-	}
-	rv = ddi_copyout(tmp_memp, to, copy_len, mode);
-	if (rv != 0)
-		rv = EFAULT;
-
-	kmem_free(tmp_mem, copy_len);
+		extvtoctovtoc(evtoc, vtoc);
+		rv = ddi_copyout(&vtoc, to, sizeof (vtoc), mode);
+		if (rv != 0)
+			rv = EFAULT;
+	}
+
 	return (rv);
 }
 
@@ -7227,40 +7237,30 @@
 static int
 vdc_set_vtoc_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
 {
-	_NOTE(ARGUNUSED(vdc))
-
-	void		*tmp_mem = NULL, *uvtoc;
-	struct vtoc	vt;
-	struct vtoc	*vtp = &vt;
-	vd_vtoc_t	vtvd;
-	int		copy_len = 0;
-	int		i, rv = 0;
+	void		*uvtoc;
+	struct vtoc	vtoc;
+	struct vtoc32	vtoc32;
+	struct extvtoc	evtoc;
+	int		i, rv;
 
 	if ((from == NULL) || (to == NULL))
 		return (ENXIO);
 
-	if (dir == VD_COPYIN)
-		uvtoc = from;
-	else
-		uvtoc = to;
-
-	if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32)
-		copy_len = sizeof (struct vtoc32);
-	else
-		copy_len = sizeof (struct vtoc);
-
-	tmp_mem = kmem_alloc(copy_len, KM_SLEEP);
-
-	rv = ddi_copyin(uvtoc, tmp_mem, copy_len, mode);
-	if (rv != 0) {
-		kmem_free(tmp_mem, copy_len);
-		return (EFAULT);
-	}
+	if (vdc->vdisk_size > VD_OLDVTOC_LIMIT)
+		return (EOVERFLOW);
+
+	uvtoc = (dir == VD_COPYIN)? from : to;
 
 	if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
-		vtoc32tovtoc((*(struct vtoc32 *)tmp_mem), vt);
+		rv = ddi_copyin(uvtoc, &vtoc32, sizeof (vtoc32), mode);
+		if (rv != 0)
+			return (EFAULT);
+		vtoc32toextvtoc(vtoc32, evtoc);
 	} else {
-		vtp = tmp_mem;
+		rv = ddi_copyin(uvtoc, &vtoc, sizeof (vtoc), mode);
+		if (rv != 0)
+			return (EFAULT);
+		vtoctoextvtoc(vtoc, evtoc);
 	}
 
 	if (dir == VD_COPYOUT) {
@@ -7274,15 +7274,75 @@
 		 * We also need to keep track of the timestamp fields.
 		 */
 		for (i = 0; i < V_NUMPAR; i++) {
-			vdc->vtoc->timestamp[i] = vtp->timestamp[i];
+			vdc->vtoc->timestamp[i] = evtoc.timestamp[i];
 		}
 
-		return (0);
-	}
-
-	VTOC2VD_VTOC(vtp, &vtvd);
-	bcopy(&vtvd, to, sizeof (vd_vtoc_t));
-	kmem_free(tmp_mem, copy_len);
+	} else {
+		VTOC2VD_VTOC(&evtoc, (vd_vtoc_t *)to);
+	}
+
+	return (0);
+}
+
+static int
+vdc_get_extvtoc_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
+{
+	int		i, rv;
+	struct extvtoc	evtoc;
+
+	if (dir != VD_COPYOUT)
+		return (0);	/* nothing to do */
+
+	if ((from == NULL) || (to == NULL))
+		return (ENXIO);
+
+	VD_VTOC2VTOC((vd_vtoc_t *)from, &evtoc);
+
+	/* fake the VTOC timestamp field */
+	for (i = 0; i < V_NUMPAR; i++) {
+		evtoc.timestamp[i] = vdc->vtoc->timestamp[i];
+	}
+
+	rv = ddi_copyout(&evtoc, to, sizeof (struct extvtoc), mode);
+	if (rv != 0)
+		rv = EFAULT;
+
+	return (rv);
+}
+
+static int
+vdc_set_extvtoc_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
+{
+	void		*uvtoc;
+	struct extvtoc	evtoc;
+	int		i, rv;
+
+	if ((from == NULL) || (to == NULL))
+		return (ENXIO);
+
+	uvtoc = (dir == VD_COPYIN)? from : to;
+
+	rv = ddi_copyin(uvtoc, &evtoc, sizeof (struct extvtoc), mode);
+	if (rv != 0)
+		return (EFAULT);
+
+	if (dir == VD_COPYOUT) {
+		/*
+		 * The disk label may have changed. Revalidate the disk
+		 * geometry. This will also update the device nodes.
+		 */
+		vdc_validate(vdc);
+
+		/*
+		 * We also need to keep track of the timestamp fields.
+		 */
+		for (i = 0; i < V_NUMPAR; i++) {
+			vdc->vtoc->timestamp[i] = evtoc.timestamp[i];
+		}
+
+	} else {
+		VTOC2VD_VTOC(&evtoc, (vd_vtoc_t *)to);
+	}
 
 	return (0);
 }
@@ -7645,7 +7705,7 @@
 	int	rv, rval;
 	struct dk_label label;
 	struct dk_geom geom;
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 	efi_gpt_t *gpt;
 	efi_gpe_t *gpe;
 	vd_efi_dev_t edev;
@@ -7665,7 +7725,7 @@
 
 	rv = vd_process_ioctl(dev, DKIOCGGEOM, (caddr_t)&geom, FKIOCTL, &rval);
 	if (rv == 0)
-		rv = vd_process_ioctl(dev, DKIOCGVTOC, (caddr_t)&vtoc,
+		rv = vd_process_ioctl(dev, DKIOCGEXTVTOC, (caddr_t)&vtoc,
 		    FKIOCTL, &rval);
 
 	if (rv == ENOTSUP) {
@@ -7957,7 +8017,7 @@
 	ASSERT(MUTEX_HELD(&vdc->lock));
 
 	vdc->vdisk_label = VD_DISK_LABEL_EFI;
-	bzero(vdc->vtoc, sizeof (struct vtoc));
+	bzero(vdc->vtoc, sizeof (struct extvtoc));
 	bzero(vdc->geom, sizeof (struct dk_geom));
 	bzero(vdc->slice, sizeof (vd_slice_t) * V_NUMPAR);
 
@@ -7982,7 +8042,7 @@
 }
 
 static void
-vdc_store_label_vtoc(vdc_t *vdc, struct dk_geom *geom, struct vtoc *vtoc)
+vdc_store_label_vtoc(vdc_t *vdc, struct dk_geom *geom, struct extvtoc *vtoc)
 {
 	int i;
 
@@ -7990,7 +8050,7 @@
 	ASSERT(vdc->block_size == vtoc->v_sectorsz);
 
 	vdc->vdisk_label = VD_DISK_LABEL_VTOC;
-	bcopy(vtoc, vdc->vtoc, sizeof (struct vtoc));
+	bcopy(vtoc, vdc->vtoc, sizeof (struct extvtoc));
 	bcopy(geom, vdc->geom, sizeof (struct dk_geom));
 	bzero(vdc->slice, sizeof (vd_slice_t) * V_NUMPAR);
 
@@ -8006,7 +8066,7 @@
 	ASSERT(MUTEX_HELD(&vdc->lock));
 
 	vdc->vdisk_label = VD_DISK_LABEL_UNK;
-	bzero(vdc->vtoc, sizeof (struct vtoc));
+	bzero(vdc->vtoc, sizeof (struct extvtoc));
 	bzero(vdc->geom, sizeof (struct dk_geom));
 	bzero(vdc->slice, sizeof (vd_slice_t) * V_NUMPAR);
 }
--- a/usr/src/uts/sun4v/io/vds.c	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/sun4v/io/vds.c	Thu Sep 11 18:00:50 2008 -0700
@@ -56,6 +56,8 @@
 #include <sys/ontrap.h>
 #include <vm/seg_map.h>
 
+#define	ONE_MEGABYTE	(1ULL << 20)
+#define	ONE_GIGABYTE	(1ULL << 30)
 #define	ONE_TERABYTE	(1ULL << 40)
 
 /* Virtual disk server initialization flags */
@@ -428,7 +430,7 @@
 	uint_t			flabel_size;	/* fake label size */
 	uint_t			flabel_limit;	/* limit of the fake label */
 	struct dk_geom		dk_geom;	/* synthetic for slice type */
-	struct vtoc		vtoc;		/* synthetic for slice type */
+	struct extvtoc		vtoc;		/* synthetic for slice type */
 	vd_slice_t		slices[VD_MAXPART]; /* logical partitions */
 	boolean_t		ownership;	/* disk ownership status */
 	ldc_status_t		ldc_state;	/* LDC connection state */
@@ -472,12 +474,13 @@
 	    sizeof (efi_gpe_t) * VD_MAXPART, DEV_BSIZE)
 
 #define	VD_LABEL_VTOC(vd)	\
-		((struct dk_label *)((vd)->flabel))
+		((struct dk_label *)(void *)((vd)->flabel))
 
 #define	VD_LABEL_EFI_GPT(vd)	\
-		((efi_gpt_t *)((vd)->flabel + DEV_BSIZE))
+		((efi_gpt_t *)(void *)((vd)->flabel + DEV_BSIZE))
 #define	VD_LABEL_EFI_GPE(vd)	\
-		((efi_gpe_t *)((vd)->flabel + DEV_BSIZE + sizeof (efi_gpt_t)))
+		((efi_gpe_t *)(void *)((vd)->flabel + DEV_BSIZE + \
+		sizeof (efi_gpt_t)))
 
 
 typedef struct vds_operation {
@@ -613,12 +616,12 @@
 static int vds_efi_alloc_and_read(vd_t *, efi_gpt_t **, efi_gpe_t **);
 static void vds_efi_free(vd_t *, efi_gpt_t *, efi_gpe_t *);
 static void vds_driver_types_free(vds_t *vds);
-static void vd_vtocgeom_to_label(struct vtoc *vtoc, struct dk_geom *geom,
+static void vd_vtocgeom_to_label(struct extvtoc *vtoc, struct dk_geom *geom,
     struct dk_label *label);
-static void vd_label_to_vtocgeom(struct dk_label *label, struct vtoc *vtoc,
+static void vd_label_to_vtocgeom(struct dk_label *label, struct extvtoc *vtoc,
     struct dk_geom *geom);
 static boolean_t vd_slice_geom_isvalid(vd_t *vd, struct dk_geom *geom);
-static boolean_t vd_slice_vtoc_isvalid(vd_t *vd, struct vtoc *vtoc);
+static boolean_t vd_slice_vtoc_isvalid(vd_t *vd, struct extvtoc *vtoc);
 
 extern int is_pseudo_device(dev_info_t *);
 
@@ -839,32 +842,57 @@
 	bzero(label, sizeof (struct dk_label));
 
 	/*
-	 * We must have a resonable number of cylinders and sectors so
+	 * Ideally we would like the cylinder size (nsect * nhead) to be the
+	 * same whatever the disk size is. That way the VTOC label could be
+	 * easily updated in case the disk size is increased (keeping the
+	 * same cylinder size allows to preserve the existing partitioning
+	 * when updating the VTOC label). But it is not possible to have
+	 * a fixed cylinder size and to cover all disk size.
+	 *
+	 * So we define different cylinder sizes depending on the disk size.
+	 * The cylinder size is chosen so that we don't have too few cylinders
+	 * for a small disk image, or so many on a big disk image that you
+	 * waste space for backup superblocks or cylinder group structures.
+	 * Also we must have a resonable number of cylinders and sectors so
 	 * that newfs can run using default values.
 	 *
-	 * if (disk_size < 2MB)
-	 * 	phys_cylinders = disk_size / 100K
-	 * else if (disk_size >= 18.75GB)
-	 *	phys_cylinders = 65535 (maximum number of cylinders)
-	 * else
-	 * 	phys_cylinders = disk_size / 300K
+	 *	+-----------+--------+---------+--------+
+	 *	| disk_size |  < 2MB | 2MB-4GB | >= 8GB |
+	 *	+-----------+--------+---------+--------+
+	 *	| nhead	    |	 1   |	   1   |    96  |
+	 *	| nsect	    |  200   |   600   |   768  |
+	 *	+-----------+--------+---------+--------+
 	 *
-	 * phys_cylinders = (phys_cylinders == 0) ? 1 : phys_cylinders
-	 * alt_cylinders = (phys_cylinders > 2) ? 2 : 0;
-	 * data_cylinders = phys_cylinders - alt_cylinders
+	 * Other parameters are computed from these values:
+	 *
+	 * 	pcyl = disk_size / (nhead * nsect * 512)
+	 * 	acyl = (pcyl > 2)? 2 : 0
+	 * 	ncyl = pcyl - acyl
 	 *
-	 * sectors = disk_size / (phys_cylinders * blk_size)
-	 *
-	 * The disk size test is an attempt to not have too few cylinders
-	 * for a small disk image, or so many on a big disk image that you
-	 * waste space for backup superblocks or cylinder group structures.
+	 * The maximum number of cylinder is 65535 so this allows to define a
+	 * geometry for a disk size up to 65535 * 96 * 768 * 512 = 2.24 TB
+	 * which is more than enough to cover the maximum size allowed by the
+	 * extended VTOC format (2TB).
 	 */
-	if (disk_size < (2 * 1024 * 1024))
-		label->dkl_pcyl = disk_size / (100 * 1024);
-	else if (disk_size >= (UINT16_MAX * 300 * 1024ULL))
-		label->dkl_pcyl = UINT16_MAX;
-	else
-		label->dkl_pcyl = disk_size / (300 * 1024);
+
+	if (disk_size >= 8 * ONE_GIGABYTE) {
+
+		label->dkl_nhead = 96;
+		label->dkl_nsect = 768;
+
+	} else if (disk_size >= 2 * ONE_MEGABYTE) {
+
+		label->dkl_nhead = 1;
+		label->dkl_nsect = 600;
+
+	} else {
+
+		label->dkl_nhead = 1;
+		label->dkl_nsect = 200;
+	}
+
+	label->dkl_pcyl = disk_size /
+	    (label->dkl_nsect * label->dkl_nhead * DEV_BSIZE);
 
 	if (label->dkl_pcyl == 0)
 		label->dkl_pcyl = 1;
@@ -874,9 +902,7 @@
 	if (label->dkl_pcyl > 2)
 		label->dkl_acyl = 2;
 
-	label->dkl_nsect = disk_size / (DEV_BSIZE * label->dkl_pcyl);
 	label->dkl_ncyl = label->dkl_pcyl - label->dkl_acyl;
-	label->dkl_nhead = 1;
 	label->dkl_write_reinstruct = 0;
 	label->dkl_read_reinstruct = 0;
 	label->dkl_rpm = 7200;
@@ -903,7 +929,7 @@
 	    label->dkl_nsect);
 
 	/* default VTOC */
-	label->dkl_vtoc.v_version = V_VERSION;
+	label->dkl_vtoc.v_version = V_EXTVERSION;
 	label->dkl_vtoc.v_nparts = V_NUMPAR;
 	label->dkl_vtoc.v_sanity = VTOC_SANE;
 	label->dkl_vtoc.v_part[VD_ENTIRE_DISK_SLICE].p_tag = V_BACKUP;
@@ -933,7 +959,7 @@
 static int
 vd_file_set_vtoc(vd_t *vd, struct dk_label *label)
 {
-	int blk, sec, cyl, head, cnt;
+	size_t blk, sec, cyl, head, cnt;
 
 	ASSERT(vd->file);
 
@@ -972,12 +998,12 @@
 
 		if (vd_file_rw(vd, VD_SLICE_NONE, VD_OP_BWRITE, (caddr_t)label,
 		    blk + sec, sizeof (struct dk_label)) < 0) {
-			PR0("error writing backup label at block %d\n",
+			PR0("error writing backup label at block %lu\n",
 			    blk + sec);
 			return (EIO);
 		}
 
-		PR1("wrote backup label at block %d\n", blk + sec);
+		PR1("wrote backup label at block %lu\n", blk + sec);
 
 		sec += 2;
 	}
@@ -1059,7 +1085,7 @@
 	int i;
 
 	chksum = 0;
-	ip = (uint_t *)dkdevid;
+	ip = (void *)dkdevid;
 	for (i = 0; i < ((DEV_BSIZE - sizeof (int)) / sizeof (int)); i++)
 		chksum ^= ip[i];
 
@@ -1259,7 +1285,7 @@
 		 */
 		if (blk < (2 << 20) && nsectors <= 0xff && !vd->is_atapi_dev) {
 			FORMG0ADDR(&cdb, blk);
-			FORMG0COUNT(&cdb, nsectors);
+			FORMG0COUNT(&cdb, (uchar_t)nsectors);
 			ucmd.uscsi_cdblen = CDB_GROUP0;
 		} else if (blk > 0xffffffff) {
 			FORMG4LONGADDR(&cdb, blk);
@@ -1509,7 +1535,7 @@
 	uint_t limit = vd->flabel_limit * DEV_BSIZE;
 	struct dk_label *label;
 	struct dk_geom geom;
-	struct vtoc vtoc;
+	struct extvtoc vtoc;
 
 	ASSERT(vd->vdisk_type == VD_DISK_TYPE_SLICE);
 	ASSERT(vd->flabel != NULL);
@@ -1524,7 +1550,7 @@
 	 */
 	if (vd->vdisk_label == VD_DISK_LABEL_VTOC &&
 	    offset == 0 && length == DEV_BSIZE) {
-		label = (struct dk_label *)data;
+		label = (void *)data;
 
 		/* check that this is a valid label */
 		if (label->dkl_magic != DKL_MAGIC ||
@@ -2313,7 +2339,7 @@
 static int
 vd_vtoc2vtoc(void *vd_buf, size_t vd_buf_len, void *ioctl_arg)
 {
-	VD_VTOC2VTOC((vd_vtoc_t *)vd_buf, (struct vtoc *)ioctl_arg);
+	VD_VTOC2VTOC((vd_vtoc_t *)vd_buf, (struct extvtoc *)ioctl_arg);
 	return (0);
 }
 
@@ -2326,7 +2352,7 @@
 static void
 vtoc2vd_vtoc(void *ioctl_arg, void *vd_buf)
 {
-	VTOC2VD_VTOC((struct vtoc *)ioctl_arg, (vd_vtoc_t *)vd_buf);
+	VTOC2VD_VTOC((struct extvtoc *)ioctl_arg, (vd_vtoc_t *)vd_buf);
 }
 
 static int
@@ -2520,7 +2546,7 @@
  * Copy information from a vtoc and dk_geom structures to a dk_label structure.
  */
 static void
-vd_vtocgeom_to_label(struct vtoc *vtoc, struct dk_geom *geom,
+vd_vtocgeom_to_label(struct extvtoc *vtoc, struct dk_geom *geom,
     struct dk_label *label)
 {
 	int i;
@@ -2573,7 +2599,7 @@
  * Copy information from a dk_label structure to a vtoc and dk_geom structures.
  */
 static void
-vd_label_to_vtocgeom(struct dk_label *label, struct vtoc *vtoc,
+vd_label_to_vtocgeom(struct dk_label *label, struct extvtoc *vtoc,
     struct dk_geom *geom)
 {
 	int i;
@@ -2644,7 +2670,7 @@
  * fake vtoc we have created.
  */
 static boolean_t
-vd_slice_vtoc_isvalid(vd_t *vd, struct vtoc *vtoc)
+vd_slice_vtoc_isvalid(vd_t *vd, struct extvtoc *vtoc)
 {
 	size_t csize;
 	int i;
@@ -2708,7 +2734,7 @@
 vd_do_slice_ioctl(vd_t *vd, int cmd, void *ioctl_arg)
 {
 	dk_efi_t *dk_ioc;
-	struct vtoc *vtoc;
+	struct extvtoc *vtoc;
 	struct dk_geom *geom;
 	size_t len, lba;
 	int rval;
@@ -2737,7 +2763,7 @@
 			bcopy(&vd->dk_geom, ioctl_arg, sizeof (vd->dk_geom));
 			return (0);
 
-		case DKIOCGVTOC:
+		case DKIOCGEXTVTOC:
 			ASSERT(ioctl_arg != NULL);
 			bcopy(&vd->vtoc, ioctl_arg, sizeof (vd->vtoc));
 			return (0);
@@ -2754,13 +2780,13 @@
 
 			return (0);
 
-		case DKIOCSVTOC:
+		case DKIOCSEXTVTOC:
 			ASSERT(ioctl_arg != NULL);
 			if (vd_slice_single_slice)
 				return (ENOTSUP);
 
 			/* fake sucess only if the new vtoc is valid */
-			vtoc = (struct vtoc *)ioctl_arg;
+			vtoc = (struct extvtoc *)ioctl_arg;
 			if (!vd_slice_vtoc_isvalid(vd, vtoc))
 				return (EINVAL);
 
@@ -2844,7 +2870,7 @@
 	if ((status = vds_efi_alloc_and_read(vd, &gpt, &gpe)) != 0)
 		return (status);
 
-	bzero(&vd->vtoc, sizeof (struct vtoc));
+	bzero(&vd->vtoc, sizeof (struct extvtoc));
 	bzero(&vd->dk_geom, sizeof (struct dk_geom));
 	bzero(vd->slices, sizeof (vd_slice_t) * VD_MAXPART);
 
@@ -2905,7 +2931,7 @@
 {
 	struct dk_label label;
 	struct dk_geom *geom = &vd->dk_geom;
-	struct vtoc *vtoc = &vd->vtoc;
+	struct extvtoc *vtoc = &vd->vtoc;
 	int i;
 	int status = 0;
 
@@ -2959,7 +2985,7 @@
 {
 	struct dk_label label;
 	struct dk_geom *geom;
-	struct vtoc *vtoc;
+	struct extvtoc *vtoc;
 	dk_efi_t *efi;
 	int rc;
 
@@ -2978,14 +3004,14 @@
 		bcopy(&vd->dk_geom, geom, sizeof (struct dk_geom));
 		return (0);
 
-	case DKIOCGVTOC:
+	case DKIOCGEXTVTOC:
 		ASSERT(ioctl_arg != NULL);
-		vtoc = (struct vtoc *)ioctl_arg;
+		vtoc = (struct extvtoc *)ioctl_arg;
 
 		rc = vd_file_validate_geometry(vd);
 		if (rc != 0 && rc != EINVAL)
 			return (rc);
-		bcopy(&vd->vtoc, vtoc, sizeof (struct vtoc));
+		bcopy(&vd->vtoc, vtoc, sizeof (struct extvtoc));
 		return (0);
 
 	case DKIOCSGEOM:
@@ -2999,16 +3025,16 @@
 		 * The current device geometry is not updated, just the driver
 		 * "notion" of it. The device geometry will be effectively
 		 * updated when a label is written to the device during a next
-		 * DKIOCSVTOC.
+		 * DKIOCSEXTVTOC.
 		 */
 		bcopy(ioctl_arg, &vd->dk_geom, sizeof (vd->dk_geom));
 		return (0);
 
-	case DKIOCSVTOC:
+	case DKIOCSEXTVTOC:
 		ASSERT(ioctl_arg != NULL);
 		ASSERT(vd->dk_geom.dkg_nhead != 0 &&
 		    vd->dk_geom.dkg_nsect != 0);
-		vtoc = (struct vtoc *)ioctl_arg;
+		vtoc = (struct extvtoc *)ioctl_arg;
 
 		if (vtoc->v_sanity != VTOC_SANE ||
 		    vtoc->v_sectorsz != DEV_BSIZE ||
@@ -3051,7 +3077,7 @@
 		return (ENOTSUP);
 	}
 
-	ASSERT(cmd == DKIOCSVTOC || cmd == DKIOCSETEFI);
+	ASSERT(cmd == DKIOCSEXTVTOC || cmd == DKIOCSETEFI);
 
 	/* label has changed, revalidate the geometry */
 	(void) vd_file_validate_geometry(vd);
@@ -3072,6 +3098,7 @@
 vd_backend_ioctl(vd_t *vd, int cmd, caddr_t arg)
 {
 	int rval = 0, status;
+	struct vtoc vtoc;
 
 	/*
 	 * Call the appropriate function to execute the ioctl depending
@@ -3092,6 +3119,35 @@
 		/* disk device exported as a full disk */
 		status = ldi_ioctl(vd->ldi_handle[0], cmd, (intptr_t)arg,
 		    vd->open_flags | FKIOCTL, kcred, &rval);
+
+		/*
+		 * By default VTOC ioctls are done using ioctls for the
+		 * extended VTOC. Some drivers (in particular non-Sun drivers)
+		 * may not support these ioctls. In that case, we fallback to
+		 * the regular VTOC ioctls.
+		 */
+		if (status == ENOTTY) {
+			switch (cmd) {
+
+			case DKIOCGEXTVTOC:
+				cmd = DKIOCGVTOC;
+				status = ldi_ioctl(vd->ldi_handle[0], cmd,
+				    (intptr_t)&vtoc, vd->open_flags | FKIOCTL,
+				    kcred, &rval);
+				vtoctoextvtoc(vtoc,
+				    (*(struct extvtoc *)(void *)arg));
+				break;
+
+			case DKIOCSEXTVTOC:
+				cmd = DKIOCSVTOC;
+				extvtoctovtoc((*(struct extvtoc *)(void *)arg),
+				    vtoc);
+				status = ldi_ioctl(vd->ldi_handle[0], cmd,
+				    (intptr_t)&vtoc, vd->open_flags | FKIOCTL,
+				    kcred, &rval);
+				break;
+			}
+		}
 	}
 
 #ifdef DEBUG
@@ -3246,7 +3302,7 @@
 	int			i, status;
 	void			*buf = NULL;
 	struct dk_geom		dk_geom = {0};
-	struct vtoc		vtoc = {0};
+	struct extvtoc		vtoc = {0};
 	struct dk_efi		dk_efi = {0};
 	struct uscsi_cmd	uscsi = {0};
 	vd_t			*vd		= task->vd;
@@ -3266,7 +3322,7 @@
 		    DKIOCGGEOM, STRINGIZE(DKIOCGGEOM),
 		    &dk_geom, NULL, dk_geom2vd_geom, B_FALSE},
 		{VD_OP_GET_VTOC, STRINGIZE(VD_OP_GET_VTOC), RNDSIZE(vd_vtoc_t),
-		    DKIOCGVTOC, STRINGIZE(DKIOCGVTOC),
+		    DKIOCGEXTVTOC, STRINGIZE(DKIOCGEXTVTOC),
 		    &vtoc, NULL, vtoc2vd_vtoc, B_FALSE},
 		{VD_OP_GET_EFI, STRINGIZE(VD_OP_GET_EFI), RNDSIZE(vd_efi_t),
 		    DKIOCGETEFI, STRINGIZE(DKIOCGETEFI),
@@ -3281,7 +3337,7 @@
 		    DKIOCSGEOM, STRINGIZE(DKIOCSGEOM),
 		    &dk_geom, vd_geom2dk_geom, NULL, B_TRUE},
 		{VD_OP_SET_VTOC, STRINGIZE(VD_OP_SET_VTOC), RNDSIZE(vd_vtoc_t),
-		    DKIOCSVTOC, STRINGIZE(DKIOCSVTOC),
+		    DKIOCSEXTVTOC, STRINGIZE(DKIOCSEXTVTOC),
 		    &vtoc, vd_vtoc2vtoc, NULL, B_TRUE},
 		{VD_OP_SET_EFI, STRINGIZE(VD_OP_SET_EFI), RNDSIZE(vd_efi_t),
 		    DKIOCSETEFI, STRINGIZE(DKIOCSETEFI),
@@ -4887,8 +4943,7 @@
 		status = recv_msg(vd->ldc_handle, vd->vio_msgp, &msglen);
 		switch (status) {
 		case 0:
-			rv = vd_process_msg(vd, (vio_msg_t *)vd->vio_msgp,
-			    msglen);
+			rv = vd_process_msg(vd, (void *)vd->vio_msgp, msglen);
 			/* check if max_msglen changed */
 			if (msgsize != vd->max_msglen) {
 				PR0("max_msglen changed 0x%lx to 0x%lx bytes\n",
@@ -5373,7 +5428,7 @@
 		bzero(vd->vtoc.v_volume, sizeof (vd->vtoc.v_volume));
 
 		/* create a fake label from the vtoc and geometry */
-		vd->flabel_limit = csize;
+		vd->flabel_limit = (uint_t)csize;
 		vd->flabel_size = VD_LABEL_VTOC_SIZE;
 		vd->flabel = kmem_zalloc(vd->flabel_size, KM_SLEEP);
 		vd_vtocgeom_to_label(&vd->vtoc, &vd->dk_geom,
@@ -5602,7 +5657,7 @@
 		vd->vdisk_label = (vd_slice_label == VD_DISK_LABEL_UNK)?
 		    vd_file_slice_label : vd_slice_label;
 		if (vd->vdisk_label == VD_DISK_LABEL_EFI ||
-		    vd->file_size >= ONE_TERABYTE) {
+		    vd->file_size >= 2 * ONE_TERABYTE) {
 			status = vd_setup_partition_efi(vd);
 		} else {
 			/*
@@ -5633,8 +5688,7 @@
 		 * of the ISO image (images for both drive types are stored
 		 * in the ISO-9600 format). CDs can store up to just under 1Gb
 		 */
-		if ((vd->vdisk_size * vd->vdisk_block_size) >
-		    (1024 * 1024 * 1024))
+		if ((vd->vdisk_size * vd->vdisk_block_size) > ONE_GIGABYTE)
 			vd->vdisk_media = VD_MEDIA_DVD;
 		else
 			vd->vdisk_media = VD_MEDIA_CD;
@@ -5843,6 +5897,7 @@
 	int status, rval;
 	struct dk_label label;
 	char *device_path = vd->device_path;
+	struct vtoc vtoc;
 
 	/* Get size of backing device */
 	if (ldi_get_size(vd->ldi_handle[0], &vd->vdisk_size) != DDI_SUCCESS) {
@@ -5878,10 +5933,18 @@
 	    vd->vdisk_size >= ONE_TERABYTE / DEV_BSIZE) {
 		vd->vdisk_label = VD_DISK_LABEL_EFI;
 	} else {
-		status = ldi_ioctl(vd->ldi_handle[0], DKIOCGVTOC,
+		status = ldi_ioctl(vd->ldi_handle[0], DKIOCGEXTVTOC,
 		    (intptr_t)&vd->vtoc, (vd->open_flags | FKIOCTL),
 		    kcred, &rval);
 
+		if (status == ENOTTY) {
+			/* try with the non-extended vtoc ioctl */
+			status = ldi_ioctl(vd->ldi_handle[0], DKIOCGVTOC,
+			    (intptr_t)&vtoc, (vd->open_flags | FKIOCTL),
+			    kcred, &rval);
+			vtoctoextvtoc(vtoc, vd->vtoc);
+		}
+
 		if (status == 0) {
 			status = ldi_ioctl(vd->ldi_handle[0], DKIOCGGEOM,
 			    (intptr_t)&vd->dk_geom, (vd->open_flags | FKIOCTL),
--- a/usr/src/uts/sun4v/sys/vdc.h	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/sun4v/sys/vdc.h	Thu Sep 11 18:00:50 2008 -0700
@@ -27,8 +27,6 @@
 #ifndef	_VDC_H
 #define	_VDC_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Virtual disk client implementation definitions
  */
@@ -272,7 +270,7 @@
 	int		dkio_flush_pending; /* # outstanding DKIO flushes */
 	int		validate_pending; /* # outstanding validate request */
 	vd_disk_label_t vdisk_label; 	/* label type of device/disk imported */
-	struct vtoc	*vtoc;		/* structure to store VTOC data */
+	struct extvtoc	*vtoc;		/* structure to store VTOC data */
 	struct dk_geom	*geom;		/* structure to store geometry data */
 	vd_slice_t	slice[V_NUMPAR]; /* logical partitions */
 
--- a/usr/src/uts/sun4v/vdc/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/sun4v/vdc/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -20,13 +20,11 @@
 #
 
 #
-# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # uts/sun4v/vdc/Makefile
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	This makefile drives the production of the vdc driver module.
 #
 #	sun4v implementation architecture dependent
@@ -64,11 +62,8 @@
 LINT_TARGET	= $(MODULE).lint
 INSTALL_TARGET	= $(BINARY) $(ROOTMODULE)
 
-#
-# lint pass one enforcement
-#
 CFLAGS	+= $(CCVERBOSE)
-CFLAGS	+= -errwarn=%all
+CFLAGS += -D_EXTVTOC
 
 LDFLAGS += -dy -Nmisc/ldc -Nmisc/platsvc -Nmisc/scsi
 
--- a/usr/src/uts/sun4v/vds/Makefile	Thu Sep 11 17:31:20 2008 -0700
+++ b/usr/src/uts/sun4v/vds/Makefile	Thu Sep 11 18:00:50 2008 -0700
@@ -25,8 +25,6 @@
 #
 # uts/sun4v/vds/Makefile
 #
-#ident	"%Z%%M%	%I%	%E% SMI"
-#
 #	This makefile drives the production of the vds driver module.
 #
 #	sun4v implementation architecture dependent
@@ -64,10 +62,8 @@
 LINT_TARGET	= $(MODULE).lint
 INSTALL_TARGET	= $(BINARY) $(ROOTMODULE)
 
-#
-# lint pass one enforcement
-#
 CFLAGS += $(CCVERBOSE)
+CFLAGS += -D_EXTVTOC
 
 #
 # module dependencies
@@ -75,19 +71,6 @@
 LDFLAGS += -dy -Nmisc/ldc -Nmisc/platsvc
 
 #
-# Manually turn on C99 compilation until the sync with snv_38 re-enables it
-#
-C99MODE = $(C99_ENABLE)
-
-#
-# For now, disable these lint checks; maintainers should endeavor
-# to investigate and remove these for maximum lint coverage.
-# Please do not carry these forward to new Makefiles.
-#
-LINTTAGS	+= -erroff=E_BAD_PTR_CAST_ALIGN
-LINTTAGS	+= -erroff=E_ASSIGN_NARROW_CONV
-
-#
 #	Default build targets.
 #
 .KEEP_STATE: