diff options
Diffstat (limited to 'usr/src/cmd')
58 files changed, 1433 insertions, 1320 deletions
diff --git a/usr/src/cmd/boot/Makefile b/usr/src/cmd/boot/Makefile index 31945e80f1..c18e53e57b 100644 --- a/usr/src/cmd/boot/Makefile +++ b/usr/src/cmd/boot/Makefile @@ -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 @@ include $(SRC)/cmd/Makefile.cmd COMMON_SUBDIRS= \ filelist \ + fiocompress \ scripts \ bootadm @@ -39,28 +38,21 @@ i386_SUBDIRS= \ mbr \ symdef -sparc_SUBDIRS= \ - fiocompress - COMMON_LINTSUBDIRS= \ bootadm i386_LINTSUBDIRS= \ + fiocompress \ installgrub \ symdef -sparc_LINTSUBDIRS= \ - fiocompress - COMMON_MSGSUBDIRS= \ - bootadm + bootadm \ + fiocompress i386_MSGSUBDIRS= \ installgrub -sparc_MSGSUBDIRS= \ - fiocompress - all:= TARGET= all install:= TARGET= install diff --git a/usr/src/cmd/boot/installgrub/floppy.c b/usr/src/cmd/boot/installgrub/floppy.c index 41a48abc53..208c9eb130 100644 --- a/usr/src/cmd/boot/installgrub/floppy.c +++ b/usr/src/cmd/boot/installgrub/floppy.c @@ -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 @@ int bootrd_debug = 0; #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 @@ floppy_lseek(int fd, off_t addr, int whence) * 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]; diff --git a/usr/src/cmd/boot/installgrub/installgrub.c b/usr/src/cmd/boot/installgrub/installgrub.c index 25677223ab..14dc050189 100644 --- a/usr/src/cmd/boot/installgrub/installgrub.c +++ b/usr/src/cmd/boot/installgrub/installgrub.c @@ -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_floppy = 0; 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 write_boot_sect(char *); 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 @@ main(int argc, char *argv[]) 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 @@ get_start_sector(int fd) 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 @@ get_start_sector(int fd) (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; } diff --git a/usr/src/cmd/boot/mbr/mbr.c b/usr/src/cmd/boot/mbr/mbr.c index 746d1e1d34..44dd3bf282 100644 --- a/usr/src/cmd/boot/mbr/mbr.c +++ b/usr/src/cmd/boot/mbr/mbr.c @@ -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 @@ main(int argc, char *argv[]) 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); } diff --git a/usr/src/cmd/boot/scripts/root_archive.ksh b/usr/src/cmd/boot/scripts/root_archive.ksh index 598118f4f4..928fda093b 100644 --- a/usr/src/cmd/boot/scripts/root_archive.ksh +++ b/usr/src/cmd/boot/scripts/root_archive.ksh @@ -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 @@ cleanup() rm -f "$TMR" fi rm -f "$TMR.gz" + rm -f /tmp/flist$$ } preload_Gnome() @@ -409,12 +404,20 @@ archive_lu() ( 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 @@ packmedia() 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" + + cleanout_pkgdata ) - 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 + archive_lu "$MEDIA" "$MINIROOT" archive_X "$MEDIA" "$MINIROOT" @@ -512,6 +513,7 @@ packmedia() # 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 @@ unpack() 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 @@ compress() 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 @@ pack() 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 @@ pack() {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" diff --git a/usr/src/cmd/devinfo/devinfo.c b/usr/src/cmd/devinfo/devinfo.c index 6f03f7f106..cde3bc5608 100644 --- a/usr/src/cmd/devinfo/devinfo.c +++ b/usr/src/cmd/devinfo/devinfo.c @@ -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 @@ partinfo(int fd, char *device) 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 @@ partinfo(int fd, char *device) 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 @@ devinfo(struct dk_geom *geom, int fd, char *device) { 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 @@ devinfo(struct dk_geom *geom, int fd, char *device) * 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): diff --git a/usr/src/cmd/devmgmt/mkdtab/mkdtab.c b/usr/src/cmd/devmgmt/mkdtab/mkdtab.c index f239b0b3e3..73eb7cbacc 100644 --- a/usr/src/cmd/devmgmt/mkdtab/mkdtab.c +++ b/usr/src/cmd/devmgmt/mkdtab/mkdtab.c @@ -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 @@ memstr(const char *str) 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 @@ hdisk(const int drive, const char *drivepfx) 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 @@ hdisk(const int drive, const char *drivepfx) /* * 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 @@ hdisk(const int drive, const char *drivepfx) (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 @@ part=true removable=false capacity=%ld dpartlist=", */ 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 @@ part=true removable=false capacity=%ld dpartlist=", 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 @@ part=true removable=false capacity=%ld dpartlist=", (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 @@ part=true removable=false capacity=%ld dpartlist=", 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 @@ part=true removable=false capacity=%ld dpartlist=", */ 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 @@ do_hdisks(void) 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 @@ initialize(void) 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 @@ initialize(void) 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 @@ initialize(void) if (putdevcmd == NULL) { perror("malloc"); - exit (-1); + exit(-1); } (void) memset(putdevcmd, 0, ORIGLEN); diff --git a/usr/src/cmd/diskscan/diskscan.c b/usr/src/cmd/diskscan/diskscan.c index 7d2e0d239d..4c311b37bf 100644 --- a/usr/src/cmd/diskscan/diskscan.c +++ b/usr/src/cmd/diskscan/diskscan.c @@ -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 void verexit(int code); 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 @@ main(int argc, char *argv[]) { 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 @@ main(int argc, char *argv[]) { 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 @@ scandisk(char *device, int devfd, int writeflag) { 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 @@ scandisk(char *device, int devfd, int writeflag) } 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 @@ scandisk(char *device, int devfd, int writeflag) * 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 @@ scandisk(char *device, int devfd, int writeflag) if (write(devfd, verbuf, NBPSCTR) != NBPSCTR) { (void) fprintf(stderr, - "%ld\n", tmpsec + unix_base); + "%llu\n", tmpsec + unix_base); numbadwr++; } } @@ -279,10 +283,10 @@ scandisk(char *device, int devfd, int writeflag) 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 @@ scandisk(char *device, int devfd, int writeflag) 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 @@ verexit(int code) */ 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); } diff --git a/usr/src/cmd/fdisk/fdisk.c b/usr/src/cmd/fdisk/fdisk.c index a12a956197..a9a1ab8046 100644 --- a/usr/src/cmd/fdisk/fdisk.c +++ b/usr/src/cmd/fdisk/fdisk.c @@ -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 int io_image = 0; /* create image using geometry (-I) */ 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 ipart Old_Table[FD_NUMPART]; 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 diskaddr_t chs_capacity; /* Numcyl_usable * heads * sectors */ + +static int Numcyl_usable; /* Number of usable cylinders */ + /* used to limit fdisk to 2TB */ -static int Dev; /* fd for open device */ /* Physical geometry for the drive */ static int Numcyl; /* number of cylinders */ static int heads; /* number of heads */ @@ -323,14 +328,14 @@ static void Set_Table_CHS_Values(int ti); 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 @@ main(int argc, char *argv[]) * 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 @@ main(int argc, char *argv[]) "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 @@ main(int argc, char *argv[]) /* 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 @@ load(int funct, char *file) 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 @@ load(int funct, char *file) 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 @@ 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) { 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 @@ insert_tbl( 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 @@ verify_tbl(void) /* 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 @@ verify_tbl(void) return (-1); } - if ((rsect >= (t_relsect + t_numsect)) || ((rsect + numsect) <= t_relsect)) { @@ -1762,8 +1796,10 @@ verify_tbl(void) } 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 @@ pars_fdisk( 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 @@ pars_fdisk( 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 @@ pars_fdisk( * 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 @@ pcreate(void) { uchar_t tsystid = 'z'; int i, j; - int rsect = 1; + uint32_t numsect; int retCode = 0; i = 0; @@ -1931,12 +1967,12 @@ pcreate(void) 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 @@ pcreate(void) } } 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 @@ pcreate(void) (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 @@ pcreate(void) } /* 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 @@ static int 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 @@ specify(uchar_t tsystid) } } + (void) printf(Q_LINE); (void) printf( "Specify the percentage of disk to use for this partition\n" @@ -2189,17 +2242,16 @@ specify(uchar_t tsystid) 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 @@ specify(uchar_t tsystid) 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 @@ specify(uchar_t tsystid) (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 @@ specify(uchar_t tsystid) "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 @@ specify(uchar_t tsystid) } } - /* 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 @@ disptbl(void) 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 @@ disptbl(void) 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 @@ disptbl(void) } 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 @@ disptbl(void) " %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 @@ disptbl(void) } 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 @@ print_Table(void) (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 @@ ffile_write(char *file) (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 @@ static void fix_slice(void) { int i; - int numsect; + uint32_t numsect; if (io_image) { return; @@ -3171,7 +3252,7 @@ fix_slice(void) 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 @@ fix_slice(void) } 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 @@ fix_slice(void) 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 @@ fix_slice(void) } 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 @@ fix_slice(void) } 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 @@ readvtoc(void) 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 @@ writevtoc(void) 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 @@ clear_vtoc(int table, int part) { 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 @@ clear_vtoc(int table, int part) 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 @@ lecture_and_query(char *warning, char *devname) 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 @@ sanity_check_provided_device(char *devname, int fd) * 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 @@ sanity_check_provided_device(char *devname, int fd) } } } 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 @@ sanity_check_provided_device(char *devname, int fd) } 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)) { diff --git a/usr/src/cmd/fmthard/fmthard.c b/usr/src/cmd/fmthard/fmthard.c index 4d24e712dd..900bd8be6e 100644 --- a/usr/src/cmd/fmthard/fmthard.c +++ b/usr/src/cmd/fmthard/fmthard.c @@ -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 *uboot = ""; 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 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) * 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 @@ display(struct dk_geom *geom, struct vtoc *vtoc, char *device) 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 @@ display64(struct dk_gpt *efi, char *device) * 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 @@ insert64(char *data, struct dk_gpt *efi) * 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 @@ load(FILE *fp, struct dk_geom *geom, struct vtoc *vtoc) * 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 @@ load(FILE *fp, struct dk_geom *geom, struct vtoc *vtoc) 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 @@ raw-device\n"); * 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 @@ validate(struct dk_geom *geom, struct vtoc *vtoc) 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 @@ fmthard: Partition %d not aligned on cylinder boundary \n", i); 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 @@ fmthard: Partition %d overlaps partition %d. Overlap is allowed\n\ * 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 @@ vread64(int fd, struct dk_gpt **efi_hdr, char *devname) * 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", diff --git a/usr/src/cmd/format/Makefile b/usr/src/cmd/format/Makefile index 2a5270a9ec..d40fff9348 100644 --- a/usr/src/cmd/format/Makefile +++ b/usr/src/cmd/format/Makefile @@ -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 @@ $(ROOTETCDATA) := GROUP = sys LDLIBS += -ladm -lefi -ldiskmgt -lnvpair -ldevid +CFLAGS += -D_EXTVTOC + .KEEP_STATE: all: $(PROG) $(DATA) diff --git a/usr/src/cmd/format/analyze.c b/usr/src/cmd/format/analyze.c index 4368daceb8..8d8404b280 100644 --- a/usr/src/cmd/format/analyze.c +++ b/usr/src/cmd/format/analyze.c @@ -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_stop = 0; /* stop after error flag */ 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 @@ static unsigned int alpha_pattern = 0x40404040; /* 10000000... == @@@@... */ #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 @@ do_scan(flags, mode) 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 @@ do_scan(flags, mode) */ 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 @@ scan_repair(bn, mode) */ 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 @@ analyze_blocks(flags, blkno, blkcnt, data, init, driver_flags, xfercntp) /* * 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 @@ analyze_blocks(flags, blkno, blkcnt, data, init, driver_flags, xfercntp) *((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 @@ bad: 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 @@ verify_blocks(int flags, * 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; + } } - } } } /* diff --git a/usr/src/cmd/format/analyze.h b/usr/src/cmd/format/analyze.h index 81d950e3bf..54e84891b6 100644 --- a/usr/src/cmd/format/analyze.h +++ b/usr/src/cmd/format/analyze.h @@ -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 "C" { 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; /* diff --git a/usr/src/cmd/format/auto_sense.c b/usr/src/cmd/format/auto_sense.c index 9adb5242ad..9ea4cd0909 100644 --- a/usr/src/cmd/format/auto_sense.c +++ b/usr/src/cmd/format/auto_sense.c @@ -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 part_table part_table_infinity = { 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 @@ static char *strcopy( 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 @@ auto_label_init(struct dk_label *label) 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 @@ new_direct_disk_type( #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 @@ generic_disk_sense( 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 @@ generic_disk_sense( 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 @@ generic_disk_sense( /* * 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 @@ generic_disk_sense( /* * 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 @@ generic_disk_sense( * 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 @@ generic_disk_sense( "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 @@ generic_disk_sense( 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 @@ generic_disk_sense( * 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 @@ generic_disk_sense( * 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 @@ generic_disk_sense( * 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 @@ generic_disk_sense( */ 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 @@ generic_disk_sense( 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 @@ generic_disk_sense( * 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 @@ generic_disk_sense( 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 @@ generic_disk_sense( 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 @@ generic_disk_sense( 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 @@ generic_disk_sense( 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 @@ generic_disk_sense( "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 @@ use_existing_disk_type( 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 @@ use_existing_disk_type( 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 @@ build_default_partition( { 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 @@ build_default_partition( * 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 @@ build_default_partition( } 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 @@ build_default_partition( 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 @@ new_scsi_disk_type( */ 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 @@ new_scsi_disk_type( #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 @@ strcopy( * 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 @@ adjust_disk_geometry(int capacity, int *cyl, int *nhead, int *nsect) * 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 @@ square_box( 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)); +} diff --git a/usr/src/cmd/format/badsec.h b/usr/src/cmd/format/badsec.h index fbc761bde6..2fdae5e670 100644 --- a/usr/src/cmd/format/badsec.h +++ b/usr/src/cmd/format/badsec.h @@ -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 @@ extern "C" { #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 badsec_lst { 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 alts_mempart { /* incore alts partition info */ 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)) diff --git a/usr/src/cmd/format/ctlr_ata.c b/usr/src/cmd/format/ctlr_ata.c index a5f616c512..2f417b9b78 100644 --- a/usr/src/cmd/format/ctlr_ata.c +++ b/usr/src/cmd/format/ctlr_ata.c @@ -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 @@ static int ata_ck_format(void); #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 @@ struct ctlr_ops pcmcia_ataops = { #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 @@ ata_rdwr(int dir, int fd, diskaddr_t blk64, int secnt, caddr_t bufaddr, { 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 @@ ata_ck_format() 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 @@ get_alts_slice() 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 @@ ata_convert_list(struct defect_list *list, int list_format) 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 @@ ata_ex_cur(struct defect_list *list) } int -ata_repair(int bn, int flag) +ata_repair(diskaddr_t bn, int flag) { int status; @@ -398,7 +396,7 @@ ata_repair(int bn, int flag) } 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 @@ ata_wr_cur(struct defect_list *list) /* 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 @@ ata_wr_cur(struct defect_list *list) 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++; } diff --git a/usr/src/cmd/format/ctlr_ata.h b/usr/src/cmd/format/ctlr_ata.h index 5ed0fe0be8..38e3fcdc10 100644 --- a/usr/src/cmd/format/ctlr_ata.h +++ b/usr/src/cmd/format/ctlr_ata.h @@ -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 @@ extern "C" { #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__ diff --git a/usr/src/cmd/format/ctlr_scsi.c b/usr/src/cmd/format/ctlr_scsi.c index d810b34559..c9ddee8f15 100644 --- a/usr/src/cmd/format/ctlr_scsi.c +++ b/usr/src/cmd/format/ctlr_scsi.c @@ -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 @@ scsi_ck_format(void) /* * 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); } diff --git a/usr/src/cmd/format/defect.c b/usr/src/cmd/format/defect.c index d30f06cde6..537a854518 100644 --- a/usr/src/cmd/format/defect.c +++ b/usr/src/cmd/format/defect.c @@ -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 @@ checkdefsum(struct defect_list *list, int mode) */ 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 @@ pr_defect(struct defect_entry *def, int num) } 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"); } diff --git a/usr/src/cmd/format/disk_generic.c b/usr/src/cmd/format/disk_generic.c index 5c06688745..3aa205b3c0 100644 --- a/usr/src/cmd/format/disk_generic.c +++ b/usr/src/cmd/format/disk_generic.c @@ -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 @@ generic_ck_format() * 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 @@ static int 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); } diff --git a/usr/src/cmd/format/global.h b/usr/src/cmd/format/global.h index beb1bae40a..fc3a25a938 100644 --- a/usr/src/cmd/format/global.h +++ b/usr/src/cmd/format/global.h @@ -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 @@ extern "C" { #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 partition_info *cur_parts; /* current disk's partitioning */ 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 @@ struct mctlr_list *controlp; /* master controller list ptr */ * 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()) diff --git a/usr/src/cmd/format/hardware_structs.h b/usr/src/cmd/format/hardware_structs.h index 6162cd863a..b72ebdf308 100644 --- a/usr/src/cmd/format/hardware_structs.h +++ b/usr/src/cmd/format/hardware_structs.h @@ -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 @@ struct disk_type { 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 */ diff --git a/usr/src/cmd/format/io.c b/usr/src/cmd/format/io.c index ba4c312b38..1aa2413c65 100644 --- a/usr/src/cmd/format/io.c +++ b/usr/src/cmd/format/io.c @@ -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 void pushchar(int c); 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 void pushchar(int c); 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 @@ geti64(str, iptr, wild) 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 @@ getbn(str, iptr) * 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 @@ input(type, promptstr, delim, param, deflt, cmdflag) 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 @@ reprompt: 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 @@ reprompt: * 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 @@ reprompt: 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 @@ reprompt: (uint64_t *)NULL)) break; } else { - if (getbn(cleantoken, &bn)) - break; - } - if (cur_label == L_TYPE_EFI) { - if ((bn64 < bounds->lower) || (bn64 > bounds->upper)) { - err_print("`"); - pr_dblock(err_print, bn64); - err_print("' is out of range.\n"); + if (getbn(cleantoken, &bn64)) break; - } - return (bn64); } /* * 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("`"); - pr_dblock(err_print, bn); + pr_dblock(err_print, bn64); err_print("' is out of range.\n"); break; } /* - * If it's ok, return it. + * It's ok, return it. */ - return (bn); + return (bn64); /* * Expecting an integer. */ @@ -864,7 +857,7 @@ reprompt: * 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 @@ reprompt: * 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 @@ reprompt: 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 @@ reprompt: /* * 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 @@ gigabytes\n", /* * 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 @@ gigabytes\n", /* * 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 @@ or g(gigabytes)\n"); 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 @@ or g(gigabytes)\n"); /* * 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 @@ or g(gigabytes)\n"); * 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 @@ megabytes or %1.2f gigabytes\n", */ 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 @@ megabytes or %1.2f gigabytes\n", /* * 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 @@ megabytes or %1.2f gigabytes\n", /* * 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 @@ pr_diskline(disk, num) 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 @@ pr_diskline(disk, num) 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 @@ pr_diskline(disk, num) /* * 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); } diff --git a/usr/src/cmd/format/io.h b/usr/src/cmd/format/io.h index 059f887dfd..e20c719c02 100644 --- a/usr/src/cmd/format/io.h +++ b/usr/src/cmd/format/io.h @@ -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 @@ typedef struct slist { * 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 { diff --git a/usr/src/cmd/format/ix_altsctr.c b/usr/src/cmd/format/ix_altsctr.c index 33c7933cbd..03770bc422 100644 --- a/usr/src/cmd/format/ix_altsctr.c +++ b/usr/src/cmd/format/ix_altsctr.c @@ -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 @@ struct alts_mempart *ap = &alts_part; /* pointer to incore */ /* 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 gen_alts_ent(); 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 @@ static int chk_bad_altsctr(daddr_t); 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 @@ struct partition *part; */ 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 @@ struct partition *part; 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 @@ chk_badsec() 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 @@ chk_badsec() * 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 @@ chk_badsec() 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 @@ init_altsctr() 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 @@ get_badsec() { 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 @@ get_badsec() 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 @@ count_badsec() */ 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 @@ gen_alts_ent() { /* 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 @@ gen_alts_ent() { 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 @@ compress_map() */ 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 @@ daddr_t badsec; /* * 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 movp; 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 lcnt2; 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 @@ int lcnt2; 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 @@ struct alts_ent *key; */ 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]; diff --git a/usr/src/cmd/format/label.c b/usr/src/cmd/format/label.c index d4362250a2..3f172c5806 100644 --- a/usr/src/cmd/format/label.c +++ b/usr/src/cmd/format/label.c @@ -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 vtoc64_to_label(struct efi_info *, struct dk_gpt *); */ 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 @@ do_geometry_sanity_check() /* * 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 @@ write_label() 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 @@ write_label() * 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 @@ write_label() /* * 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 @@ vtoc64_to_label(struct efi_info *label, struct dk_gpt *vtoc) * 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 @@ vtoc_to_label(struct dk_label *label, struct vtoc *vtoc, struct dk_geom *geom, #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 @@ vtoc_to_label(struct dk_label *label, struct vtoc *vtoc, struct dk_geom *geom, 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 @@ vtoc_to_label(struct dk_label *label, struct vtoc *vtoc, struct dk_geom *geom, 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 @@ vtoc_to_label(struct dk_label *label, struct vtoc *vtoc, struct dk_geom *geom, } } #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 @@ vtoc_to_label(struct dk_label *label, struct vtoc *vtoc, struct dk_geom *geom, */ (void) checksum(label, CK_MAKESUM); +#ifdef DEBUG + if (option_msg && diag_msg) + dump_label(label); +#endif return (0); } @@ -807,12 +815,12 @@ vtoc_to_label(struct dk_label *label, struct vtoc *vtoc, struct dk_geom *geom, * 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 @@ label_to_vtoc(struct vtoc *vtoc, struct dk_label *label) #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 @@ label_to_vtoc(struct vtoc *vtoc, struct dk_label *label) 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 @@ label_to_vtoc(struct vtoc *vtoc, struct dk_label *label) 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 @@ label_to_vtoc(struct vtoc *vtoc, struct dk_label *label) /* * 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 @@ err_check(struct dk_gpt *vtoc) } } -#ifdef FOR_DEBUGGING_ONLY -int +#ifdef DEBUG +static void dump_label(label) struct dk_label *label; { @@ -1064,7 +1070,7 @@ dump_label(label) 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 @@ dump_label(label) fmt_print("\n\n"); } -#endif /* FOR_DEBUGGING_ONLY */ +#endif /* DEBUG */ diff --git a/usr/src/cmd/format/label.h b/usr/src/cmd/format/label.h index 0e5563a507..e7dbba9d36 100644 --- a/usr/src/cmd/format/label.h +++ b/usr/src/cmd/format/label.h @@ -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 write_label(void); 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); diff --git a/usr/src/cmd/format/main.c b/usr/src/cmd/format/main.c index a1a5b28297..5d1d9c6c81 100644 --- a/usr/src/cmd/format/main.c +++ b/usr/src/cmd/format/main.c @@ -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 @@ Continue")) * 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"); /* diff --git a/usr/src/cmd/format/menu_analyze.c b/usr/src/cmd/format/menu_analyze.c index 0f6bb31031..727a8b8695 100644 --- a/usr/src/cmd/format/menu_analyze.c +++ b/usr/src/cmd/format/menu_analyze.c @@ -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 @@ a_print() 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 @@ a_setup() 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 @@ a_setup() 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 @@ a_config() 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 @@ a_purge() 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; } diff --git a/usr/src/cmd/format/menu_command.c b/usr/src/cmd/format/menu_command.c index e0bfc0b40a..1eedba1c85 100644 --- a/usr/src/cmd/format/menu_command.c +++ b/usr/src/cmd/format/menu_command.c @@ -147,7 +147,7 @@ c_disk() /* * 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 @@ c_type() */ if (index == auto_conf_choice) { float scaled; - long nblks; + diskaddr_t nblks; int nparts; /* @@ -415,7 +415,7 @@ c_type() } 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 @@ c_type() * 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 @@ c_type() * 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 @@ c_format() 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 @@ c_format() 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 @@ int 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 @@ c_show() } 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 @@ c_label() * 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 @@ c_label() * 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 @@ c_label() #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 @@ c_label() * 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 @@ c_backup() 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 @@ c_backup() /* * 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 @@ c_verify() { 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 @@ Warning: Primary label on disk appears to be different from\ncurrent label.\n"); /* * 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 @@ c_volname() * 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 @@ c_volname() * 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( diff --git a/usr/src/cmd/format/menu_defect.c b/usr/src/cmd/format/menu_defect.c index e8c20dccaf..9a31134ec9 100644 --- a/usr/src/cmd/format/menu_defect.c +++ b/usr/src/cmd/format/menu_defect.c @@ -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 @@ and may take a long while. Continue")) int d_add() { - int type, bn, deflt, index; + int type, deflt, index; + diskaddr_t bn; u_ioparam_t ioparam; struct defect_entry def; diff --git a/usr/src/cmd/format/menu_fdisk.c b/usr/src/cmd/format/menu_fdisk.c index d5c6d21f35..4ebadee5ab 100644 --- a/usr/src/cmd/format/menu_fdisk.c +++ b/usr/src/cmd/format/menu_fdisk.c @@ -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 @@ c_fdisk() } /* - * 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 @@ get_solaris_part(int fd, struct ipart *ipart) } #endif /* DEBUG */ - solaris_offset = lel(ip.relsect); + solaris_offset = (uint_t)lel(ip.relsect); break; } } @@ -515,13 +504,20 @@ get_solaris_part(int fd, struct ipart *ipart) /* 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 @@ get_solaris_part(int fd, struct ipart *ipart) 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 diff --git a/usr/src/cmd/format/menu_partition.c b/usr/src/cmd/format/menu_partition.c index 9b5b5b6749..aea7354f12 100644 --- a/usr/src/cmd/format/menu_partition.c +++ b/usr/src/cmd/format/menu_partition.c @@ -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 @@ p_select() 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 @@ p_select() 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 @@ p_select() #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 @@ void 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 @@ print_partition(struct partition_info *pinfo, int partnum, int want_header) */ 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); } diff --git a/usr/src/cmd/format/menu_scsi.c b/usr/src/cmd/format/menu_scsi.c index 99ccafb72c..491aa79f84 100644 --- a/usr/src/cmd/format/menu_scsi.c +++ b/usr/src/cmd/format/menu_scsi.c @@ -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 @@ c_scsi() (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 @@ Please display the page on which you'd like to do a mode select\n"); 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 @@ do_format() /* * 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 @@ do_format() /* * 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 @@ currently being used for swapping.\n\n"); 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 @@ do_display() 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 @@ default_all_pages() 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 @@ default_all_pages() */ 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) { diff --git a/usr/src/cmd/format/misc.c b/usr/src/cmd/format/misc.c index 9e43e3f318..f148cc3115 100644 --- a/usr/src/cmd/format/misc.c +++ b/usr/src/cmd/format/misc.c @@ -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 @@ echo_off() */ 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 @@ charmode_on() */ 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 @@ bn2mb(uint64_t nblks) } -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 @@ bn2tb(uint64_t nblks) 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); } diff --git a/usr/src/cmd/format/misc.h b/usr/src/cmd/format/misc.h index 27ceaebab9..ca3050b02b 100644 --- a/usr/src/cmd/format/misc.h +++ b/usr/src/cmd/format/misc.h @@ -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 @@ void canonicalize_name(char *dst, char *src); 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(); diff --git a/usr/src/cmd/format/modify_partition.c b/usr/src/cmd/format/modify_partition.c index 94b56b47fe..b2bc580e69 100644 --- a/usr/src/cmd/format/modify_partition.c +++ b/usr/src/cmd/format/modify_partition.c @@ -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 @@ p_modify() /* * 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 @@ p_modify() * 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 @@ static int 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 @@ check_map(map) * 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 @@ get_user_map(map, float_part) 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 @@ Warning: no space available for '%s' from Free Hog partition\n", (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 @@ struct disk_type *tptr; 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) */ diff --git a/usr/src/cmd/format/param.h b/usr/src/cmd/format/param.h index e92005e2e5..553ee1ebb1 100644 --- a/usr/src/cmd/format/param.h +++ b/usr/src/cmd/format/param.h @@ -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 @@ extern "C" { #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 @@ extern "C" { #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 diff --git a/usr/src/cmd/format/partition.c b/usr/src/cmd/format/partition.c index 20439696f7..11ae4488a1 100644 --- a/usr/src/cmd/format/partition.c +++ b/usr/src/cmd/format/partition.c @@ -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 @@ maxofN(struct dk_gpt *map) 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 @@ change_partition(int num) 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 @@ change_partition(int num) 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 @@ change_partition(int num) * return an Error. */ if (tag == V_BACKUP) { - int fullsz; + uint_t fullsz; fullsz = ncyl * nhead * nsect; if (fullsz != j) { diff --git a/usr/src/cmd/format/startup.c b/usr/src/cmd/format/startup.c index 7d3144c250..99aa8d9d34 100644 --- a/usr/src/cmd/format/startup.c +++ b/usr/src/cmd/format/startup.c @@ -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 @@ static void check_dtypes_for_inconsistency(struct disk_type *dp1, 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_dtypes(); 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 @@ sup_setpart() 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 @@ sup_setpart() * 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 @@ sup_setpart() * 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 @@ do_search(char *arglist[]) 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 @@ add_device_to_disklist(char *devname, char *devpath) * 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 @@ add_device_to_disklist(char *devname, char *devpath) /* * 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 @@ add_device_to_disklist(char *devname, char *devpath) #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 @@ check_pinfo_for_inconsistency(pp1, pp2) * * Returns -1 in the case of an error. */ -static int +static uint_t str2blks(char *str) { int blks; @@ -2591,7 +2590,7 @@ str2cyls(char *str) */ if (*p != 0) { /* - * Units specifier of 'c': convert cylinders to blocks + * Units specifier of 'c': accept it. */ if (*p == 'c') { p++; diff --git a/usr/src/cmd/fs.d/pcfs/fsck/pcfs_common.c b/usr/src/cmd/fs.d/pcfs/fsck/pcfs_common.c index 72c5e99dd5..f8a5b4e98d 100644 --- a/usr/src/cmd/fs.d/pcfs/fsck/pcfs_common.c +++ b/usr/src/cmd/fs.d/pcfs/fsck/pcfs_common.c @@ -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 @@ void 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 @@ void 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 @@ findPartitionOffset(int fd, char *ldrive) 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 @@ findPartitionOffset(int fd, char *ldrive) 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 @@ findPartitionOffset(int fd, char *ldrive) */ 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)); diff --git a/usr/src/cmd/fs.d/pcfs/mkfs/mkfs.c b/usr/src/cmd/fs.d/pcfs/mkfs/mkfs.c index 9dadf79683..a811306f74 100644 --- a/usr/src/cmd/fs.d/pcfs/mkfs/mkfs.c +++ b/usr/src/cmd/fs.d/pcfs/mkfs/mkfs.c @@ -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 @@ seek_partn(int fd, char *pn, bpb_t *wbpb, off64_t *seekto) 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; diff --git a/usr/src/cmd/fs.d/ufs/fsck/utilities.c b/usr/src/cmd/fs.d/ufs/fsck/utilities.c index e7a22ea5bc..8fde1889b9 100644 --- a/usr/src/cmd/fs.d/ufs/fsck/utilities.c +++ b/usr/src/cmd/fs.d/ufs/fsck/utilities.c @@ -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 @@ getdisksize(caddr_t disk, int fd) 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 @@ get_device_size(int fd, caddr_t name) 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); diff --git a/usr/src/cmd/fs.d/ufs/mkfs/mkfs.c b/usr/src/cmd/fs.d/ufs/mkfs/mkfs.c index 95d017027b..de6f6bc3e6 100644 --- a/usr/src/cmd/fs.d/ufs/mkfs/mkfs.c +++ b/usr/src/cmd/fs.d/ufs/mkfs/mkfs.c @@ -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 @@ main(int argc, char *argv[]) "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 @@ grow50: 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; diff --git a/usr/src/cmd/fs.d/ufs/newfs/newfs.c b/usr/src/cmd/fs.d/ufs/newfs/newfs.c index 950a1c3e43..d517971873 100644 --- a/usr/src/cmd/fs.d/ufs/newfs/newfs.c +++ b/usr/src/cmd/fs.d/ufs/newfs/newfs.c @@ -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 @@ getdiskbydev(char *disk) 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 @@ getdiskbydev(char *disk) 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 @@ get_device_size(int fd, char *name) 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); diff --git a/usr/src/cmd/fstyp/fstyp.c b/usr/src/cmd/fstyp/fstyp.c index e099387034..fb81b0edbb 100644 --- a/usr/src/cmd/fstyp/fstyp.c +++ b/usr/src/cmd/fstyp/fstyp.c @@ -440,8 +440,8 @@ struct part_find_s { 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 @@ enum { WALK_CONTINUE, WALK_TERMINATE }; * 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 @@ walk_partitions(int fd, int startsec, off_t secsz, } 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; diff --git a/usr/src/cmd/hal/probing/storage/probe-storage.c b/usr/src/cmd/hal/probing/storage/probe-storage.c index 33df696813..6fa8fead0a 100644 --- a/usr/src/cmd/hal/probing/storage/probe-storage.c +++ b/usr/src/cmd/hal/probing/storage/probe-storage.c @@ -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 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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) { diff --git a/usr/src/cmd/hal/probing/volume/probe-volume.c b/usr/src/cmd/hal/probing/volume/probe-volume.c index 54ce28f222..f0af8da167 100644 --- a/usr/src/cmd/hal/probing/volume/probe-volume.c +++ b/usr/src/cmd/hal/probing/volume/probe-volume.c @@ -9,8 +9,6 @@ * **************************************************************************/ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef HAVE_CONFIG_H # include <config.h> #endif @@ -436,7 +434,7 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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) { diff --git a/usr/src/cmd/hal/utils/fsutils.c b/usr/src/cmd/hal/utils/fsutils.c index 579657c9c7..7e1f66019e 100644 --- a/usr/src/cmd/hal/utils/fsutils.c +++ b/usr/src/cmd/hal/utils/fsutils.c @@ -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 @@ dos_to_dev(char *path, char **devpath, int *num) } char * -get_slice_name (char *devlink) +get_slice_name(char *devlink) { char *part, *slice, *disk; char *s = NULL; @@ -102,8 +100,8 @@ struct part_find_s { 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 @@ enum { WALK_CONTINUE, WALK_TERMINATE }; */ 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 @@ walk_partitions(int fd, int startsec, uint_t secsz, } 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 @@ find_dos_drive(int fd, int num, uint_t secsz, off_t *offset) } 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 @@ get_num_dos_drives(int fd, uint_t secsz) * 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]; diff --git a/usr/src/cmd/hal/utils/fsutils.h b/usr/src/cmd/hal/utils/fsutils.h index 9c85789512..92491f55c7 100644 --- a/usr/src/cmd/hal/utils/fsutils.h +++ b/usr/src/cmd/hal/utils/fsutils.h @@ -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_drive(uchar_t id); 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 */ diff --git a/usr/src/cmd/iscsi/iscsitgtd/mgmt_create.c b/usr/src/cmd/iscsi/iscsitgtd/mgmt_create.c index bd140ec19e..8d9d600a7d 100644 --- a/usr/src/cmd/iscsi/iscsitgtd/mgmt_create.c +++ b/usr/src/cmd/iscsi/iscsitgtd/mgmt_create.c @@ -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 @@ error: } 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 @@ setup_disk_backing(err_code_t *code, char *path, char *backing, tgt_node_t *n, { 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 @@ setup_disk_backing(err_code_t *code, char *path, char *backing, tgt_node_t *n, (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; diff --git a/usr/src/cmd/lvm/rpc.metamhd/mhd_drive.c b/usr/src/cmd/lvm/rpc.metamhd/mhd_drive.c index 4c1b31b5ed..9aa0fc56e7 100644 --- a/usr/src/cmd/lvm/rpc.metamhd/mhd_drive.c +++ b/usr/src/cmd/lvm/rpc.metamhd/mhd_drive.c @@ -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 @@ mhd_ident( 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 @@ mhd_ident( 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]; diff --git a/usr/src/cmd/prtvtoc/prtvtoc.c b/usr/src/cmd/prtvtoc/prtvtoc.c index ad08c4a242..531fd244e8 100644 --- a/usr/src/cmd/prtvtoc/prtvtoc.c +++ b/usr/src/cmd/prtvtoc/prtvtoc.c @@ -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 @@ typedef struct { 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 @@ static freemap_t *freemap; * 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 @@ prtvtoc(char *devname) 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 @@ prtvtoc(char *devname) * 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 @@ putfree64(struct dk_gpt *efi, freemap_t *freemap) * 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 @@ puttable(struct dk_geom *geom, struct vtoc *vtoc, freemap_t *freemap, 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 @@ readgeom(int fd, char *name, struct dk_geom *geom) * 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) { diff --git a/usr/src/cmd/rmformat/rmf_main.c b/usr/src/cmd/rmformat/rmf_main.c index addf9c0278..68404c80d5 100644 --- a/usr/src/cmd/rmformat/rmf_main.c +++ b/usr/src/cmd/rmformat/rmf_main.c @@ -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 @@ int32_t w_flag = 0; 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 @@ char *dev_name = NULL; 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 @@ main(int32_t argc, char **argv) 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 @@ restricted to 8 characters.\n")); 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 @@ void 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."); diff --git a/usr/src/cmd/rmformat/rmf_menu.c b/usr/src/cmd/rmformat/rmf_menu.c index b4693ebf6d..253d29270f 100644 --- a/usr/src/cmd/rmformat/rmf_menu.c +++ b/usr/src/cmd/rmformat/rmf_menu.c @@ -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 int32_t l_flag; 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 check_invalid_combinations_again(int32_t); 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 @@ performed on a mounted device.\n")); 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 @@ process_c_flag(smedia_handle_t handle) 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 @@ static void 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 @@ process_V_flag(smedia_handle_t handle, int32_t fd) 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 @@ process_V_flag(smedia_handle_t handle, int32_t fd) 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 @@ process_V_flag(smedia_handle_t handle, int32_t fd) } 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 @@ process_V_flag(smedia_handle_t handle, int32_t fd) } 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 @@ static void 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 @@ process_s_flag(smedia_handle_t handle, int32_t fd) /* 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 @@ process_s_flag(smedia_handle_t handle, int32_t fd) /* 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 @@ static void 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 @@ process_b_flag(int32_t fd) /* 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 @@ process_b_flag(int32_t fd) /* 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); diff --git a/usr/src/cmd/rmformat/rmf_misc.c b/usr/src/cmd/rmformat/rmf_misc.c index 320e8fde0f..5202d19f72 100644 --- a/usr/src/cmd/rmformat/rmf_misc.c +++ b/usr/src/cmd/rmformat/rmf_misc.c @@ -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 @@ is not a raw device.\n")); 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 @@ my_atoll(char *ptr) } } } - ret_val = strtoll(ptr, (char **)NULL, 0); + ret_val = (uint64_t)strtoull(ptr, (char **)NULL, 0); return (ret_val); } @@ -753,10 +751,10 @@ int32_t 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 @@ write_sunos_label(int32_t fd, int32_t media_type) /* 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 @@ write_sunos_label(int32_t fd, int32_t media_type) /* 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 @@ release_SIGINT() } 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 @@ verify(smedia_handle_t handle, int32_t fd, uint32_t start_sector, /* 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 @@ verify(smedia_handle_t handle, int32_t fd, uint32_t start_sector, /* 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 @@ static void 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 @@ get_media_info(device_t *t_dev, char *sdev, char *pname, char *sn) /* * 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 { diff --git a/usr/src/cmd/rmformat/rmf_slice.c b/usr/src/cmd/rmformat/rmf_slice.c index 717806b0e5..c8ace3374e 100644 --- a/usr/src/cmd/rmformat/rmf_slice.c +++ b/usr/src/cmd/rmformat/rmf_slice.c @@ -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 @@ static slist_t pflag_choices[] = { /* * 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_inputchar(); 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 @@ clean_token(char *cleantoken, char *token) } 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 @@ strcnt(char *s1, char *s2) 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 @@ str2sector(char *str) 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 @@ str2sector(char *str) 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 @@ valid_slice_file(smedia_handle_t handle, int32_t fd, char *file_name, 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 @@ valid_slice_file(smedia_handle_t handle, int32_t fd, char *file_name, 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 @@ valid_slice_file(smedia_handle_t handle, int32_t fd, char *file_name, 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 @@ valid_slice_file(smedia_handle_t handle, int32_t fd, char *file_name, */ 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 @@ check_vtoc_sanity(smedia_handle_t handle, int32_t fd, struct vtoc *vt) 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 @@ Solaris partition found!\n")); 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 @@ Solaris partitions found.\n")); } /* 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 @@ Solaris partitions found.\n")); #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 @@ Solaris partitions found.\n")); #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 @@ Solaris partitions found.\n")); 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 partitions found.\n")); 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 @@ Solaris partition\n")); "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 @@ get_fdisk(smedia_handle_t handle, int32_t fd, int32_t offset, /* 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 @@ void 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) * 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) /* 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) /* 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) } } } - 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 @@ write_default_label(smedia_handle_t handle, int32_t fd) /* 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 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) { 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 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) } } #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 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) /* 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 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) /* 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 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) * 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 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) * 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 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) * erased in the above sequence. */ - erase(handle, 0, 1); + erase(handle, (diskaddr_t)0, (diskaddr_t)1); } /* @@ -1633,10 +1639,10 @@ overwrite_metadata(int32_t fd, smedia_handle_t handle) */ 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 @@ erase(smedia_handle_t handle, uint32_t offset, uint32_t size) 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); diff --git a/usr/src/cmd/smserverd/smediad.c b/usr/src/cmd/smserverd/smediad.c index b69be16694..dcd3dd7028 100644 --- a/usr/src/cmd/smserverd/smediad.c +++ b/usr/src/cmd/smserverd/smediad.c @@ -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 @@ client_servproc(void *cookie, char *argp, size_t arg_size, 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 @@ client_servproc(void *cookie, char *argp, size_t arg_size, } /* 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) { |