diff options
author | yu, larry liu - Sun Microsystems - Beijing China <Larry.Liu@Sun.COM> | 2009-06-17 19:20:05 +0800 |
---|---|---|
committer | yu, larry liu - Sun Microsystems - Beijing China <Larry.Liu@Sun.COM> | 2009-06-17 19:20:05 +0800 |
commit | 65908c77dfc02644236ba18bffe67b5ed6f23135 (patch) | |
tree | 90d89cc047a404c32e2537573bee1d8566a562e3 /usr/src/cmd/format | |
parent | 6ccacea7930c58faadb6224d30e24c5658b67c81 (diff) | |
download | illumos-joyent-65908c77dfc02644236ba18bffe67b5ed6f23135.tar.gz |
PSARC 2008/769 Multiple disk sector size support.
6710930 Solaris needs to support large sector size hard drive disk
Diffstat (limited to 'usr/src/cmd/format')
-rw-r--r-- | usr/src/cmd/format/analyze.c | 17 | ||||
-rw-r--r-- | usr/src/cmd/format/auto_sense.c | 366 | ||||
-rw-r--r-- | usr/src/cmd/format/ctlr_ata.c | 9 | ||||
-rw-r--r-- | usr/src/cmd/format/ctlr_scsi.c | 71 | ||||
-rw-r--r-- | usr/src/cmd/format/defect.c | 31 | ||||
-rw-r--r-- | usr/src/cmd/format/defect.h | 28 | ||||
-rw-r--r-- | usr/src/cmd/format/disk_generic.c | 6 | ||||
-rw-r--r-- | usr/src/cmd/format/global.h | 3 | ||||
-rw-r--r-- | usr/src/cmd/format/hardware_structs.h | 4 | ||||
-rw-r--r-- | usr/src/cmd/format/io.c | 17 | ||||
-rw-r--r-- | usr/src/cmd/format/label.c | 33 | ||||
-rw-r--r-- | usr/src/cmd/format/main.c | 7 | ||||
-rw-r--r-- | usr/src/cmd/format/menu_analyze.c | 6 | ||||
-rw-r--r-- | usr/src/cmd/format/menu_command.c | 526 | ||||
-rw-r--r-- | usr/src/cmd/format/menu_defect.c | 43 | ||||
-rw-r--r-- | usr/src/cmd/format/menu_fdisk.c | 107 | ||||
-rw-r--r-- | usr/src/cmd/format/misc.c | 12 | ||||
-rw-r--r-- | usr/src/cmd/format/prompts.c | 13 | ||||
-rw-r--r-- | usr/src/cmd/format/startup.c | 19 |
19 files changed, 647 insertions, 671 deletions
diff --git a/usr/src/cmd/format/analyze.c b/usr/src/cmd/format/analyze.c index 8d8404b280..64417130d2 100644 --- a/usr/src/cmd/format/analyze.c +++ b/usr/src/cmd/format/analyze.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -461,7 +461,7 @@ scan_repair(bn, mode) { int status; int result = 1; - char buf[SECSIZE]; + char *buf; int buf_is_good; int i; @@ -471,6 +471,11 @@ scan_repair(bn, mode) return (result); } + buf = malloc(cur_blksz); + if (buf == NULL) { + err_print("Warning: no memory.\n\n"); + return (result); + } enter_critical(); /* @@ -509,7 +514,7 @@ scan_repair(bn, mode) * determine if the new block appears ok. */ if (!buf_is_good) { - bzero(buf, SECSIZE); + bzero(buf, cur_blksz); fmt_print("Warning: Block %llu zero-filled.\n", bn); } else { fmt_print("ok.\n"); @@ -565,7 +570,7 @@ scan_repair(bn, mode) } exit_critical(); - + free(buf); return (result); } @@ -596,7 +601,7 @@ analyze_blocks(flags, blkno, blkcnt, data, init, driver_flags, xfercntp) /* * Initialize the pattern buffer if necessary. */ - nints = (diskaddr_t)blkcnt * SECSIZE / sizeof (int); + nints = (diskaddr_t)blkcnt * cur_blksz / sizeof (int); if ((flags & SCAN_PATTERN) && init) { for (i = 0; i < nints; i++) *((int *)((int *)pattern_buf + i)) = data; @@ -724,7 +729,7 @@ verify_blocks(int flags, int status, i, nints; unsigned *ptr = (uint_t *)pattern_buf; - nints = SECSIZE / sizeof (int); + nints = cur_blksz / sizeof (int); /* * Initialize the pattern buffer if we are in write pass. diff --git a/usr/src/cmd/format/auto_sense.c b/usr/src/cmd/format/auto_sense.c index 094c6c2c1d..57d44562a6 100644 --- a/usr/src/cmd/format/auto_sense.c +++ b/usr/src/cmd/format/auto_sense.c @@ -223,8 +223,6 @@ static char *get_sun_disk_name( static char *get_generic_disk_name( char *disk_name, struct scsi_inquiry *inquiry); -static int force_blocksize(int fd); -static int raw_format(int fd); static char *strcopy( char *dst, char *src, @@ -308,10 +306,10 @@ auto_efi_sense(int fd, struct efi_info *label) */ if (ioctl(fd, DKIOCINFO, &dkinfo) == -1) { - if (option_msg && diag_msg) { - err_print("DKIOCINFO failed\n"); - } - return (NULL); + if (option_msg && diag_msg) { + err_print("DKIOCINFO failed\n"); + } + return (NULL); } if ((cur_ctype != NULL) && (cur_ctype->ctype_ctype == DKC_DIRECT)) { ctlr = find_direct_ctlr_info(&dkinfo); @@ -337,11 +335,11 @@ auto_efi_sense(int fd, struct efi_info *label) disk->dtype_next = NULL; (void) strlcpy(disk->vendor, label->vendor, - sizeof (disk->vendor)); + sizeof (disk->vendor)); (void) strlcpy(disk->product, label->product, - sizeof (disk->product)); + sizeof (disk->product)); (void) strlcpy(disk->revision, label->revision, - sizeof (disk->revision)); + sizeof (disk->revision)); disk->capacity = label->capacity; part = (struct partition_info *) @@ -554,11 +552,6 @@ auto_label_init(struct dk_label *label) disk_info.dki_lbsize = DEV_BSIZE; } - if (disk_info.dki_lbsize != DEV_BSIZE) { - err_print("auto_label_init: lbasize is not 512\n"); - goto auto_label_init_out; - } - dk_ioc_back.dki_data = databack; /* @@ -584,7 +577,7 @@ auto_label_init(struct dk_label *label) goto auto_label_init_out; } - backsigp = (efi_gpt_t *)((uintptr_t)dk_ioc_back.dki_data + DEV_BSIZE); + backsigp = (efi_gpt_t *)((uintptr_t)dk_ioc_back.dki_data + cur_blksz); backsig = backsigp->efi_gpt_Signature; @@ -736,7 +729,7 @@ new_direct_disk_type( disk->dtype_rpm = label->dkl_rpm; part = (struct partition_info *) - zalloc(sizeof (struct partition_info)); + zalloc(sizeof (struct partition_info)); pt = disk->dtype_plist; if (pt == NULL) { disk->dtype_plist = part; @@ -764,11 +757,11 @@ new_direct_disk_type( #elif defined(_SUNOS_VTOC_16) part->pinfo_map[i].dkl_cylno = - label->dkl_vtoc.v_part[i].p_start / - ((blkaddr_t)(disk->dtype_nhead * - disk->dtype_nsect - apc)); + label->dkl_vtoc.v_part[i].p_start / + ((blkaddr_t)(disk->dtype_nhead * + disk->dtype_nsect - apc)); part->pinfo_map[i].dkl_nblk = - label->dkl_vtoc.v_part[i].p_size; + label->dkl_vtoc.v_part[i].p_size; #else #error No VTOC format defined. #endif /* defined(_SUNOS_VTOC_8) */ @@ -779,7 +772,7 @@ new_direct_disk_type( */ if (label->dkl_vtoc.v_version == V_VERSION) { (void) memcpy(disk_info->v_volume, label->dkl_vtoc.v_volume, - LEN_DKL_VVOL); + LEN_DKL_VVOL); part->vtoc = label->dkl_vtoc; } else { (void) memset(disk_info->v_volume, 0, LEN_DKL_VVOL); @@ -845,10 +838,10 @@ auto_sense( deflt = 1; ioparam.io_charlist = confirm_list; if (input(FIO_MSTR, FORMAT_MSG, '?', &ioparam, - &deflt, DATA_INPUT) == 0) { + &deflt, DATA_INPUT) == 0) { force_format_dat = 1; } else if (input(FIO_MSTR, GENERIC_MSG, '?', &ioparam, - &deflt, DATA_INPUT) == 0) { + &deflt, DATA_INPUT) == 0) { force_generic = 1; } } @@ -890,7 +883,7 @@ auto_sense( } if (option_msg && diag_msg) { err_print("blocks: %llu (0x%llx)\n", - capacity.sc_capacity, capacity.sc_capacity); + capacity.sc_capacity, capacity.sc_capacity); err_print("blksize: %u\n", capacity.sc_lbasize); } @@ -910,7 +903,7 @@ auto_sense( if (force_generic) { return (generic_disk_sense(fd, can_prompt, label, - &inquiry, &capacity, disk_name)); + &inquiry, &capacity, disk_name)); } /* @@ -918,7 +911,7 @@ auto_sense( */ if ((disk_type = find_scsi_disk_by_name(disk_name)) != NULL) { if (use_existing_disk_type(fd, can_prompt, label, - &inquiry, disk_type, &capacity)) { + &inquiry, disk_type, &capacity)) { return (disk_type); } if (force_format_dat) { @@ -931,7 +924,7 @@ auto_sense( */ return (generic_disk_sense(fd, can_prompt, label, - &inquiry, &capacity, disk_name)); + &inquiry, &capacity, disk_name)); } @@ -964,7 +957,6 @@ generic_disk_sense( struct mode_geometry page4; uchar_t buf4[MAX_MODE_SENSE_SIZE]; } u_page4; - struct scsi_capacity_16 new_capacity; struct mode_format *page3 = &u_page3.page3; struct mode_geometry *page4 = &u_page4.page4; struct scsi_ms_header header; @@ -982,38 +974,6 @@ generic_disk_sense( } /* - * If the device's block size is not 512, we have to - * change block size, reformat, and then sense the - * geometry. To do this, we must be able to prompt - * the user. - */ - if (capacity->sc_lbasize != DEV_BSIZE) { - if (!can_prompt) { - return (NULL); - } - if (force_blocksize(fd)) { - goto err; - } - - /* - * Get the capacity again, since this has changed - */ - if (uscsi_read_capacity(fd, &new_capacity)) { - goto err; - } - if (option_msg && diag_msg) { - err_print("blocks: %llu (0x%llx)\n", - new_capacity.sc_capacity, - new_capacity.sc_capacity); - err_print("blksize: %u\n", new_capacity.sc_lbasize); - } - capacity = &new_capacity; - if (capacity->sc_lbasize != DEV_BSIZE) { - goto err; - } - } - - /* * 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. @@ -1028,7 +988,7 @@ generic_disk_sense( * Get current Page 3 - Format Parameters page */ if (uscsi_mode_sense(fd, DAD_MODE_FORMAT, MODE_SENSE_PC_CURRENT, - (caddr_t)&u_page3, MAX_MODE_SENSE_SIZE, &header)) { + (caddr_t)&u_page3, MAX_MODE_SENSE_SIZE, &header)) { setdefault = 1; } @@ -1036,7 +996,7 @@ generic_disk_sense( * Get current Page 4 - Drive Geometry page */ if (uscsi_mode_sense(fd, DAD_MODE_GEOMETRY, MODE_SENSE_PC_CURRENT, - (caddr_t)&u_page4, MAX_MODE_SENSE_SIZE, &header)) { + (caddr_t)&u_page4, MAX_MODE_SENSE_SIZE, &header)) { setdefault = 1; } @@ -1071,7 +1031,7 @@ generic_disk_sense( &nsect); } else { pcyl = (page4->cyl_ub << 16) + (page4->cyl_mb << 8) + - page4->cyl_lb; + page4->cyl_lb; nhead = page4->heads; nsect = page3->sect_track; } @@ -1094,7 +1054,12 @@ generic_disk_sense( } } - if (setdefault == 1) { + /* + * Mode sense page 3 and page 4 are obsolete in SCSI-3. For + * newly developed large sector size disk, we will not rely on + * those two pages but compute geometry directly. + */ + if ((setdefault == 1) || (capacity->sc_lbasize != DEV_BSIZE)) { /* * If the number of cylinders or the number of heads reported * is zero, we think the inquiry of page 3 and page 4 failed. @@ -1223,7 +1188,7 @@ generic_disk_sense( p, nhead, n); if (input(FIO_INT, "Select one of the above " "choices ", ':', &ioparam, - &deflt, DATA_INPUT) == 2) { + &deflt, DATA_INPUT) == 2) { pcyl = p; nsect = n; } @@ -1239,16 +1204,16 @@ generic_disk_sense( */ if ((pcyl > MAXIMUM_NO_CYLINDERS && - ((nsect > MAXIMUM_NO_SECTORS) || - (nhead > MAXIMUM_NO_HEADS))) || - ((nsect > MAXIMUM_NO_SECTORS) && - (nhead > MAXIMUM_NO_HEADS))) { + ((nsect > MAXIMUM_NO_SECTORS) || + (nhead > MAXIMUM_NO_HEADS))) || + ((nsect > MAXIMUM_NO_SECTORS) && + (nhead > MAXIMUM_NO_HEADS))) { err_print("This disk is too big to label. " - " You will lose some blocks.\n"); + " You will lose some blocks.\n"); } if ((pcyl > MAXIMUM_NO_CYLINDERS) || - (nsect > MAXIMUM_NO_SECTORS) || - (nhead > MAXIMUM_NO_HEADS)) { + (nsect > MAXIMUM_NO_SECTORS) || + (nhead > MAXIMUM_NO_HEADS)) { u_ioparam_t ioparam; int order; char msg[256]; @@ -1259,45 +1224,45 @@ generic_disk_sense( switch (order) { case 0x7: /* pcyl > nhead > nsect */ nblocks = - square_box(nblocks, - &pcyl, MAXIMUM_NO_CYLINDERS, - &nhead, MAXIMUM_NO_HEADS, - &nsect, MAXIMUM_NO_SECTORS); + square_box(nblocks, + &pcyl, MAXIMUM_NO_CYLINDERS, + &nhead, MAXIMUM_NO_HEADS, + &nsect, MAXIMUM_NO_SECTORS); break; case 0x6: /* pcyl > nsect > nhead */ nblocks = - square_box(nblocks, - &pcyl, MAXIMUM_NO_CYLINDERS, - &nsect, MAXIMUM_NO_SECTORS, - &nhead, MAXIMUM_NO_HEADS); + square_box(nblocks, + &pcyl, MAXIMUM_NO_CYLINDERS, + &nsect, MAXIMUM_NO_SECTORS, + &nhead, MAXIMUM_NO_HEADS); break; case 0x4: /* nsect > pcyl > nhead */ nblocks = - square_box(nblocks, - &nsect, MAXIMUM_NO_SECTORS, - &pcyl, MAXIMUM_NO_CYLINDERS, - &nhead, MAXIMUM_NO_HEADS); + square_box(nblocks, + &nsect, MAXIMUM_NO_SECTORS, + &pcyl, MAXIMUM_NO_CYLINDERS, + &nhead, MAXIMUM_NO_HEADS); break; case 0x0: /* nsect > nhead > pcyl */ nblocks = - square_box(nblocks, - &nsect, MAXIMUM_NO_SECTORS, - &nhead, MAXIMUM_NO_HEADS, - &pcyl, MAXIMUM_NO_CYLINDERS); + square_box(nblocks, + &nsect, MAXIMUM_NO_SECTORS, + &nhead, MAXIMUM_NO_HEADS, + &pcyl, MAXIMUM_NO_CYLINDERS); break; case 0x3: /* nhead > pcyl > nsect */ nblocks = - square_box(nblocks, - &nhead, MAXIMUM_NO_HEADS, - &pcyl, MAXIMUM_NO_CYLINDERS, - &nsect, MAXIMUM_NO_SECTORS); + square_box(nblocks, + &nhead, MAXIMUM_NO_HEADS, + &pcyl, MAXIMUM_NO_CYLINDERS, + &nsect, MAXIMUM_NO_SECTORS); break; case 0x1: /* nhead > nsect > pcyl */ nblocks = - square_box(nblocks, - &nhead, MAXIMUM_NO_HEADS, - &nsect, MAXIMUM_NO_SECTORS, - &pcyl, MAXIMUM_NO_CYLINDERS); + square_box(nblocks, + &nhead, MAXIMUM_NO_HEADS, + &nsect, MAXIMUM_NO_SECTORS, + &pcyl, MAXIMUM_NO_CYLINDERS); break; default: /* How did we get here? */ @@ -1305,10 +1270,10 @@ generic_disk_sense( /* Do something useful */ nblocks = - square_box(nblocks, - &nhead, MAXIMUM_NO_HEADS, - &nsect, MAXIMUM_NO_SECTORS, - &pcyl, MAXIMUM_NO_CYLINDERS); + square_box(nblocks, + &nhead, MAXIMUM_NO_HEADS, + &nsect, MAXIMUM_NO_SECTORS, + &pcyl, MAXIMUM_NO_CYLINDERS); break; } if (option_msg && diag_msg && @@ -1333,7 +1298,7 @@ generic_disk_sense( ioparam.io_charlist = confirm_list; if (input(FIO_MSTR, msg, '?', &ioparam, - &deflt, DATA_INPUT) != 0) + &deflt, DATA_INPUT) != 0) break; ioparam.io_bounds.lower = MINIMUM_NO_HEADS; @@ -1417,7 +1382,7 @@ generic_disk_sense( char old_name[DISK_NAME_MAX]; (void) strcpy(old_name, disk_name); (void) get_generic_disk_name(disk_name, - inquiry); + inquiry); if (option_msg && diag_msg) { err_print( "Changing disk type name from '%s' to '%s'\n", old_name, disk_name); @@ -1457,7 +1422,6 @@ use_existing_disk_type( struct disk_type *disk_type, struct scsi_capacity_16 *capacity) { - struct scsi_capacity_16 new_capacity; int pcyl; int acyl; int nhead; @@ -1465,40 +1429,6 @@ use_existing_disk_type( int rpm; /* - * If the device's block size is not 512, we have to - * change block size, reformat, and then sense the - * geometry. To do this, we must be able to prompt - * the user. - */ - if (capacity->sc_lbasize != DEV_BSIZE) { - if (!can_prompt) { - return (0); - } - if (force_blocksize(fd)) { - goto err; - } - - /* - * Get the capacity again, since this has changed - */ - if (uscsi_read_capacity(fd, &new_capacity)) { - goto err; - } - - if (option_msg && diag_msg) { - err_print("blocks: %llu (0x%llx)\n", - new_capacity.sc_capacity, - new_capacity.sc_capacity); - err_print("blksize: %u\n", new_capacity.sc_lbasize); - } - - capacity = &new_capacity; - if (capacity->sc_lbasize != DEV_BSIZE) { - goto err; - } - } - - /* * Construct a new label out of the format.dat */ pcyl = disk_type->dtype_pcyl; @@ -1545,7 +1475,7 @@ use_existing_disk_type( err: if (option_msg && diag_msg) { err_print( - "Configuration via format.dat geometry failed\n"); + "Configuration via format.dat geometry failed\n"); } return (0); } @@ -1589,11 +1519,11 @@ build_default_partition( * is in integral number of megabytes. */ capacity = ((diskaddr_t)(label->dkl_ncyl) * label->dkl_nhead * - label->dkl_nsect) / (1024 * 1024) / DEV_BSIZE; + label->dkl_nsect) / (1024 * 1024) / cur_blksz; dpt = default_partitions; for (i = 0; i < DEFAULT_PARTITION_TABLE_SIZE; i++, dpt++) { if (capacity >= dpt->min_capacity && - capacity < dpt->max_capacity) { + capacity < dpt->max_capacity) { break; } } @@ -1623,7 +1553,7 @@ build_default_partition( * cylinders. Always give what they * asked or more, never less. */ - nblks = pt->partitions[i] * ((1024*1024)/DEV_BSIZE); + nblks = pt->partitions[i] * ((1024*1024)/cur_blksz); nblks += (blks_per_cyl - 1); ncyls[i] = nblks / blks_per_cyl; freecyls -= ncyls[i]; @@ -1639,7 +1569,7 @@ build_default_partition( i, ncyls[i]); } err_print("Free cylinders exhausted (%d)\n", - freecyls); + freecyls); } return (0); } @@ -1733,13 +1663,13 @@ build_default_partition( #if defined(_SUNOS_VTOC_8) label->dkl_map[2].dkl_cylno = 0; label->dkl_map[2].dkl_nblk = - label->dkl_ncyl * label->dkl_nhead * label->dkl_nsect; + label->dkl_ncyl * label->dkl_nhead * label->dkl_nsect; #elif defined(_SUNOS_VTOC_16) label->dkl_vtoc.v_part[2].p_start = 0; label->dkl_vtoc.v_part[2].p_size = - (label->dkl_ncyl + label->dkl_acyl) * label->dkl_nhead * - label->dkl_nsect; + (label->dkl_ncyl + label->dkl_acyl) * label->dkl_nhead * + label->dkl_nsect; #else #error No VTOC format defined. #endif /* defined(_SUNOS_VTOC_8) */ @@ -1776,13 +1706,12 @@ build_default_partition( } else { err_print("%6.2fMB ", scaled); } - err_print(" %6d cylinders\n", #if defined(_SUNOS_VTOC_8) + err_print(" %6d cylinders\n", label->dkl_map[i].dkl_nblk/blks_per_cyl); - #elif defined(_SUNOS_VTOC_16) + err_print(" %6d cylinders\n", label->dkl_vtoc.v_part[i].p_size/blks_per_cyl); - #else #error No VTOC format defined. #endif /* defined(_SUNOS_VTOC_8) */ @@ -1810,16 +1739,16 @@ find_scsi_disk_type( ctlr = find_scsi_ctlr_type(); for (dp = ctlr->ctype_dlist; dp != NULL; dp = dp->dtype_next) { - if (dp->dtype_asciilabel) { - if ((strcmp(dp->dtype_asciilabel, disk_name) == 0) && - dp->dtype_pcyl == label->dkl_pcyl && - dp->dtype_ncyl == label->dkl_ncyl && - dp->dtype_acyl == label->dkl_acyl && - dp->dtype_nhead == label->dkl_nhead && - dp->dtype_nsect == label->dkl_nsect) { - return (dp); + if (dp->dtype_asciilabel) { + if ((strcmp(dp->dtype_asciilabel, disk_name) == 0) && + dp->dtype_pcyl == label->dkl_pcyl && + dp->dtype_ncyl == label->dkl_ncyl && + dp->dtype_acyl == label->dkl_acyl && + dp->dtype_nhead == label->dkl_nhead && + dp->dtype_nsect == label->dkl_nsect) { + return (dp); + } } - } } return ((struct disk_type *)NULL); @@ -1839,11 +1768,11 @@ find_scsi_disk_by_name( ctlr = find_scsi_ctlr_type(); for (dp = ctlr->ctype_dlist; dp != NULL; dp = dp->dtype_next) { - if (dp->dtype_asciilabel) { - if ((strcmp(dp->dtype_asciilabel, disk_name) == 0)) { - return (dp); + if (dp->dtype_asciilabel) { + if ((strcmp(dp->dtype_asciilabel, disk_name) == 0)) { + return (dp); + } } - } } return ((struct disk_type *)NULL); @@ -1997,7 +1926,7 @@ new_scsi_disk_type( */ if (part == NULL) { part = (struct partition_info *) - zalloc(sizeof (struct partition_info)); + zalloc(sizeof (struct partition_info)); pt = disk->dtype_plist; if (pt == NULL) { disk->dtype_plist = part; @@ -2024,11 +1953,11 @@ new_scsi_disk_type( #elif defined(_SUNOS_VTOC_16) part->pinfo_map[i].dkl_cylno = - label->dkl_vtoc.v_part[i].p_start / - ((blkaddr32_t)(disk->dtype_nhead * - disk->dtype_nsect - apc)); + label->dkl_vtoc.v_part[i].p_start / + ((blkaddr32_t)(disk->dtype_nhead * + disk->dtype_nsect - apc)); part->pinfo_map[i].dkl_nblk = - label->dkl_vtoc.v_part[i].p_size; + label->dkl_vtoc.v_part[i].p_size; #else #error No VTOC format defined. #endif /* defined(_SUNOS_VTOC_8) */ @@ -2042,7 +1971,7 @@ new_scsi_disk_type( */ if (label->dkl_vtoc.v_version == V_VERSION) { (void) memcpy(disk_info->v_volume, label->dkl_vtoc.v_volume, - LEN_DKL_VVOL); + LEN_DKL_VVOL); part->vtoc = label->dkl_vtoc; } else { (void) memset(disk_info->v_volume, 0, LEN_DKL_VVOL); @@ -2151,112 +2080,16 @@ get_generic_disk_name( (void) memset(disk_name, 0, DISK_NAME_MAX); p = strcopy(disk_name, inquiry->inq_vid, - sizeof (inquiry->inq_vid)); + sizeof (inquiry->inq_vid)); *p++ = '-'; p = strcopy(p, inquiry->inq_pid, sizeof (inquiry->inq_pid)); *p++ = '-'; p = strcopy(p, inquiry->inq_revision, - sizeof (inquiry->inq_revision)); + sizeof (inquiry->inq_revision)); return (disk_name); } - - -static int -force_blocksize( - int fd) -{ - union { - struct mode_format page3; - uchar_t buf3[MAX_MODE_SENSE_SIZE]; - } u_page3; - struct mode_format *page3 = &u_page3.page3; - struct scsi_ms_header header; - - if (check("\ -Must reformat device to 512-byte blocksize. Continue") == 0) { - - /* - * Get current Page 3 - Format Parameters page - */ - if (uscsi_mode_sense(fd, DAD_MODE_FORMAT, - MODE_SENSE_PC_CURRENT, (caddr_t)&u_page3, - MAX_MODE_SENSE_SIZE, &header)) { - goto err; - } - - /* - * Make our changes to the geometry - */ - header.mode_header.length = 0; - header.mode_header.device_specific = 0; - page3->mode_page.ps = 0; - page3->data_bytes_sect = DEV_BSIZE; - - /* - * make sure that logical block size is of - * DEV_BSIZE. - */ - header.block_descriptor.blksize_hi = (DEV_BSIZE >> 16); - header.block_descriptor.blksize_mid = (DEV_BSIZE >> 8); - header.block_descriptor.blksize_lo = (char)(DEV_BSIZE); - /* - * Select current Page 3 - Format Parameters page - */ - if (uscsi_mode_select(fd, DAD_MODE_FORMAT, - MODE_SELECT_PF, (caddr_t)&u_page3, - MODESENSE_PAGE_LEN(&u_page3), &header)) { - goto err; - } - - /* - * Now reformat the device - */ - if (raw_format(fd)) { - goto err; - } - return (0); - } - -err: - if (option_msg && diag_msg) { - err_print( - "Reformat device to 512-byte blocksize failed\n"); - } - return (1); -} - -static int -raw_format( - int fd) -{ - union scsi_cdb cdb; - struct uscsi_cmd ucmd; - struct scsi_defect_hdr defect_hdr; - - (void) memset((char *)&ucmd, 0, sizeof (ucmd)); - (void) memset((char *)&cdb, 0, sizeof (union scsi_cdb)); - (void) memset((char *)&defect_hdr, 0, sizeof (defect_hdr)); - cdb.scc_cmd = SCMD_FORMAT; - ucmd.uscsi_cdb = (caddr_t)&cdb; - ucmd.uscsi_cdblen = CDB_GROUP0; - ucmd.uscsi_bufaddr = (caddr_t)&defect_hdr; - ucmd.uscsi_buflen = sizeof (defect_hdr); - cdb.cdb_opaque[1] = FPB_DATA; - - /* - * Issue the format ioctl - */ - fmt_print("Formatting...\n"); - (void) fflush(stdout); - if (uscsi_cmd(fd, &ucmd, - (option_msg && diag_msg) ? F_NORMAL : F_SILENT)) { - return (1); - } - return (0); -} - /* * Copy a string of characters from src to dst, for at * most n bytes. Strip all leading and trailing spaces, @@ -2383,7 +2216,8 @@ square_box( * any blocks. */ - for (i = 0; (((*dim1)>>i)&1) == 0 && ((*dim1)>>i) > lim1; i++); + for (i = 0; (((*dim1)>>i)&1) == 0 && ((*dim1)>>i) > lim1; i++) + ; if (i) { *dim1 = ((*dim1)>>i); *dim3 = ((*dim3)<<i); diff --git a/usr/src/cmd/format/ctlr_ata.c b/usr/src/cmd/format/ctlr_ata.c index 2f417b9b78..c8f982d71b 100644 --- a/usr/src/cmd/format/ctlr_ata.c +++ b/usr/src/cmd/format/ctlr_ata.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -155,7 +155,7 @@ ata_rdwr(int dir, int fd, diskaddr_t blk64, int secnt, caddr_t bufaddr, blkno = (blkaddr_t)blk64; bzero((caddr_t)&dadkio_rwcmd, sizeof (struct dadkio_rwcmd)); - tmpsec = secnt * 512; + tmpsec = secnt * cur_blksz; /* Doing raw read */ dadkio_rwcmd.cmd = (dir == DIR_READ) ? DADKIO_RWCMD_READ : @@ -213,12 +213,15 @@ ata_rdwr(int dir, int fd, diskaddr_t blk64, int secnt, caddr_t bufaddr, int ata_ck_format() { - unsigned char bufaddr[2048]; + char *bufaddr; int status; + bufaddr = (char *)zalloc(4 * cur_blksz); status = ata_rdwr(DIR_READ, cur_file, (diskaddr_t)1, 4, (caddr_t)bufaddr, 0, NULL); + free(bufaddr); + return (!status); } diff --git a/usr/src/cmd/format/ctlr_scsi.c b/usr/src/cmd/format/ctlr_scsi.c index c9ddee8f15..c16327832d 100644 --- a/usr/src/cmd/format/ctlr_scsi.c +++ b/usr/src/cmd/format/ctlr_scsi.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -264,7 +264,7 @@ scsi_rdwr(dir, fd, blkno, secnt, bufaddr, flags, xfercntp) } ucmd.uscsi_cdb = (caddr_t)&cdb; ucmd.uscsi_bufaddr = bufaddr; - ucmd.uscsi_buflen = nsectors * SECSIZE; + ucmd.uscsi_buflen = nsectors * cur_blksz; rc = uscsi_cmd(fd, &ucmd, flags); if (rc != 0) @@ -290,7 +290,7 @@ scsi_rdwr(dir, fd, blkno, secnt, bufaddr, flags, xfercntp) blkno += nsectors; secnt -= nsectors; - bufaddr += nsectors * SECSIZE; + bufaddr += nsectors * cur_blksz; } /* @@ -326,7 +326,7 @@ scsi_ck_format(void) * Try to read the first four blocks. */ status = scsi_rdwr(DIR_READ, cur_file, (diskaddr_t)0, 4, - (caddr_t)cur_buf, F_SILENT, NULL); + (caddr_t)cur_buf, F_SILENT, NULL); return (!status); } @@ -498,7 +498,7 @@ scsi_raw_format(void) "by format verification and surface analysis.\n\n"); if (check("Retry format without mode selects and Grown Defects list") - != 0) { + != 0) { return (-1); } @@ -580,18 +580,18 @@ scsi_format_time() * If it fail, try to use the saved or current instead. */ status = uscsi_mode_sense(cur_file, DAD_MODE_GEOMETRY, - MODE_SENSE_PC_DEFAULT, (caddr_t)page4, - MAX_MODE_SENSE_SIZE, &header); + MODE_SENSE_PC_DEFAULT, (caddr_t)page4, + MAX_MODE_SENSE_SIZE, &header); if (status) { status = uscsi_mode_sense(cur_file, DAD_MODE_GEOMETRY, - MODE_SENSE_PC_SAVED, (caddr_t)page4, - MAX_MODE_SENSE_SIZE, &header); + MODE_SENSE_PC_SAVED, (caddr_t)page4, + MAX_MODE_SENSE_SIZE, &header); } if (status) { status = uscsi_mode_sense(cur_file, DAD_MODE_GEOMETRY, - MODE_SENSE_PC_CURRENT, (caddr_t)page4, - MAX_MODE_SENSE_SIZE, &header); + MODE_SENSE_PC_CURRENT, (caddr_t)page4, + MAX_MODE_SENSE_SIZE, &header); } if (status) { return (0); @@ -609,7 +609,7 @@ scsi_format_time() page4->rpm = BE_16(page4->rpm); p4_cylinders = (page4->cyl_ub << 16) + (page4->cyl_mb << 8) + - page4->cyl_lb; + page4->cyl_lb; p4_heads = page4->heads; p4_rpm = page4->rpm; @@ -618,7 +618,7 @@ scsi_format_time() */ if (p4_rpm < MIN_RPM || p4_rpm > MAX_RPM) { err_print("Mode sense page(4) reports rpm value as %d," - " adjusting it to %d\n", p4_rpm, AVG_RPM); + " adjusting it to %d\n", p4_rpm, AVG_RPM); p4_rpm = AVG_RPM; } @@ -626,7 +626,7 @@ scsi_format_time() return (0); format_time = ((scsi_format_revolutions * p4_heads * - p4_cylinders) + p4_rpm) / p4_rpm; + p4_cylinders) + p4_rpm) / p4_rpm; if (option_msg && diag_msg) { err_print(" pcyl: %d\n", p4_cylinders); @@ -1027,8 +1027,8 @@ scsi_ms_page3(scsi2_flag) tmp5 = page3->alt_tracks_vol; tmp6 = page3->alt_sect_zone; - flag = (page3->data_bytes_sect != SECSIZE); - page3->data_bytes_sect = SECSIZE; + flag = (page3->data_bytes_sect != cur_blksz); + page3->data_bytes_sect = cur_blksz; flag |= (page3->interleave != 1); page3->interleave = 1; @@ -1844,7 +1844,8 @@ scsi_convert_list_to_new(list, def_list, list_format) len = def_list->length / sizeof (struct scsi_bfi_defect); old_defect = def_list->list; new_defect = (struct defect_entry *) - zalloc(LISTSIZE(len) * SECSIZE); + zalloc(deflist_size(cur_blksz, len) * + cur_blksz); list->header.magicno = (uint_t)DEFECT_MAGIC; list->list = new_defect; @@ -2618,7 +2619,7 @@ uscsi_reserve_release(int fd, int cmd) ucmd.uscsi_cdb = (caddr_t)&cdb; ucmd.uscsi_cdblen = CDB_GROUP0; status = uscsi_cmd(fd, &ucmd, - (option_msg && diag_msg) ? F_NORMAL : F_SILENT); + (option_msg && diag_msg) ? F_NORMAL : F_SILENT); if (status) { /* @@ -2630,14 +2631,14 @@ uscsi_reserve_release(int fd, int cmd) (void) memset((char *)&cdb, 0, sizeof (union scsi_cdb)); ucmd.uscsi_cdb = (caddr_t)&cdb; cdb.scc_cmd = (cmd == SCMD_RESERVE) ? - SCMD_RESERVE_G1 : SCMD_RELEASE_G1; + SCMD_RESERVE_G1 : SCMD_RELEASE_G1; ucmd.uscsi_cdblen = CDB_GROUP1; status = uscsi_cmd(fd, &ucmd, - (option_msg && diag_msg) ? F_NORMAL : F_SILENT); + (option_msg && diag_msg) ? F_NORMAL : F_SILENT); if (status) { if (option_msg) { - err_print("%s failed\n", (cmd == SCMD_RESERVE) ? - "Reserve" : "Release"); + err_print("%s failed\n", (cmd == SCMD_RESERVE) ? + "Reserve" : "Release"); } } } @@ -2916,13 +2917,13 @@ scsi_extract_sense_info_descr(struct scsi_descr_sense_hdr *sdsp, int rqlen) */ result = (((diskaddr_t)isd->isd_information[0] << 56) | - ((diskaddr_t)isd->isd_information[1] << 48) | - ((diskaddr_t)isd->isd_information[2] << 40) | - ((diskaddr_t)isd->isd_information[3] << 32) | - ((diskaddr_t)isd->isd_information[4] << 24) | - ((diskaddr_t)isd->isd_information[5] << 16) | - ((diskaddr_t)isd->isd_information[6] << 8) | - ((diskaddr_t)isd->isd_information[7])); + ((diskaddr_t)isd->isd_information[1] << 48) | + ((diskaddr_t)isd->isd_information[2] << 40) | + ((diskaddr_t)isd->isd_information[3] << 32) | + ((diskaddr_t)isd->isd_information[4] << 24) | + ((diskaddr_t)isd->isd_information[5] << 16) | + ((diskaddr_t)isd->isd_information[6] << 8) | + ((diskaddr_t)isd->isd_information[7])); break; } @@ -2975,7 +2976,7 @@ apply_chg_list(int pageno, int pagsiz, uchar_t *curbits, while (chglist != NULL) { if (chglist->pageno == pageno && - chglist->byteno < pagsiz) { + chglist->byteno < pagsiz) { i = chglist->byteno; c = curbits[i]; switch (chglist->mode) { @@ -3288,16 +3289,16 @@ check_support_for_defects() rq = (struct scsi_extended_sense *)ucmd.uscsi_rqbuf; status = uscsi_cmd(cur_file, &ucmd, - (option_msg && diag_msg) ? F_NORMAL : F_SILENT); + (option_msg && diag_msg) ? F_NORMAL : F_SILENT); if (status != 0) { /* * check if read_defect_list_is_supported. */ if (ucmd.uscsi_rqstatus == STATUS_GOOD && - rq->es_key == KEY_ILLEGAL_REQUEST && - rq->es_add_code == INVALID_OPCODE) - return (0); + rq->es_key == KEY_ILLEGAL_REQUEST && + rq->es_add_code == INVALID_OPCODE) + return (0); } return (1); } @@ -3335,7 +3336,7 @@ scsi_format_without_defects() * Issue the format ioctl */ status = uscsi_cmd(cur_file, &ucmd, - (option_msg && diag_msg) ? F_NORMAL : F_SILENT); + (option_msg && diag_msg) ? F_NORMAL : F_SILENT); return (status); } diff --git a/usr/src/cmd/format/defect.c b/usr/src/cmd/format/defect.c index 537a854518..a2f77e1032 100644 --- a/usr/src/cmd/format/defect.c +++ b/usr/src/cmd/format/defect.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -132,8 +132,8 @@ read_list(struct defect_list *list) /* * Allocate space for the rest of the list. */ - size = LISTSIZE(list->header.count); - list->list = (struct defect_entry *)zalloc(size * SECSIZE); + size = deflist_size(cur_blksz, list->header.count); + list->list = (struct defect_entry *)zalloc(size * cur_blksz); /* * Try to read in the rest of the list. If there is an * error, or the checksum is wrong, this copy is corrupt. @@ -352,7 +352,7 @@ write_deflist(struct defect_list *list) /* * calculate how many sectors the defect list will occupy. */ - size = LISTSIZE(list->header.count); + size = deflist_size(cur_blksz, list->header.count); /* * Loop for each copy of the list to be written. Write * out the header of the list followed by the data. @@ -444,9 +444,9 @@ add_def(struct defect_entry *def, struct defect_list *list, int index) * sector, allocate the necessary space. */ count = list->header.count; - if (LISTSIZE(count + 1) > LISTSIZE(count)) + if (deflist_size(cur_blksz, count + 1) > deflist_size(cur_blksz, count)) list->list = (struct defect_entry *)rezalloc((void *)list->list, - LISTSIZE(count + 1) * SECSIZE); + deflist_size(cur_blksz, count + 1) * cur_blksz); /* * Slip all the defects after this one down one slot in the list. */ @@ -485,3 +485,22 @@ kill_deflist(struct defect_list *list) list->list = NULL; list->flags = 0; } + +/* + * This routine returns the defect list size + * according to the sector size. + */ +int +deflist_size(int secsz, int sz) +{ + int rval; + + if (secsz == 0) { + secsz = SECSIZE; + } + + rval = sz ? ((sz * sizeof (struct defect_entry) + + secsz - 1) / secsz) : 1; + + return (rval); +} diff --git a/usr/src/cmd/format/defect.h b/usr/src/cmd/format/defect.h index a917144068..7b3990ceee 100644 --- a/usr/src/cmd/format/defect.h +++ b/usr/src/cmd/format/defect.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 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _DEFECT_H #define _DEFECT_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef __cplusplus extern "C" { #endif @@ -82,16 +79,6 @@ struct defect_list { #define LISTCOUNT 2 /* - * This defines the size (in sectors) of the defect array given the number - * of defects in the array. It must be rounded to a sector boundary since - * that is the atomic disk size. We make a zero length list use up a - * sector because it is convenient to have malloc'd space in every - * non-null list. - */ -#define LISTSIZE(x) ((x) ? ((x) * sizeof (struct defect_entry) + \ - SECSIZE - 1) / SECSIZE : 1) - -/* * These defines are the flags for the defect list. */ #define LIST_DIRTY 0x01 /* List needs to be synced */ @@ -135,6 +122,15 @@ void add_def(struct defect_entry *def, struct defect_list *list, int index); void kill_deflist(struct defect_list *list); +/* + * This defines the size (in sectors) of the defect array given the number + * of defects in the array. It must be rounded to a sector boundary since + * that is the atomic disk size. We make a zero length list use up a + * sector because it is convenient to have malloc'd space in every + * non-null list. + */ +int deflist_size(int secsz, int sz); + #ifdef __cplusplus } #endif diff --git a/usr/src/cmd/format/disk_generic.c b/usr/src/cmd/format/disk_generic.c index 3aa205b3c0..d053660a04 100644 --- a/usr/src/cmd/format/disk_generic.c +++ b/usr/src/cmd/format/disk_generic.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -121,8 +121,8 @@ generic_rdwr(dir, fd, blkno, secnt, bufaddr, flags, xfercntp) offset_t tmpsec, status, tmpblk; int ret; - tmpsec = (offset_t)secnt * UBSIZE; - tmpblk = (offset_t)blkno * UBSIZE; + tmpsec = (offset_t)secnt * cur_blksz; + tmpblk = (offset_t)blkno * cur_blksz; #if defined(_FIRMWARE_NEEDS_FDISK) /* Use "p0" file to seek/read the data */ diff --git a/usr/src/cmd/format/global.h b/usr/src/cmd/format/global.h index fc3a25a938..241df1e3e5 100644 --- a/usr/src/cmd/format/global.h +++ b/usr/src/cmd/format/global.h @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -107,6 +107,7 @@ int dev_expert; /* enable for developer mode */ int cur_file; /* file descriptor for current disk */ int cur_flags; /* flags for current disk */ int cur_label; /* current label type */ +uint_t cur_blksz; /* currect disk block size */ struct disk_info *cur_disk; /* current disk */ struct disk_type *cur_dtype; /* current dtype */ struct ctlr_info *cur_ctlr; /* current ctlr */ diff --git a/usr/src/cmd/format/hardware_structs.h b/usr/src/cmd/format/hardware_structs.h index b72ebdf308..81bc40d202 100644 --- a/usr/src/cmd/format/hardware_structs.h +++ b/usr/src/cmd/format/hardware_structs.h @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -62,6 +62,8 @@ struct disk_info { char v_volume[LEN_DKL_VVOL]; /* volume name from label */ /* (no terminating null) */ + uint_t disk_lbasize; /* disk block size */ + }; #define NSPECIFICS 8 diff --git a/usr/src/cmd/format/io.c b/usr/src/cmd/format/io.c index 1aa2413c65..6e9e4064a9 100644 --- a/usr/src/cmd/format/io.c +++ b/usr/src/cmd/format/io.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -606,11 +606,11 @@ reprompt: fmt_print("[%llub, %llue, %llumb, %llugb, %llutb]", efi_deflt->end_sector, efi_deflt->start_sector + efi_deflt->end_sector - 1, - (efi_deflt->end_sector * DEV_BSIZE) / + (efi_deflt->end_sector * cur_blksz) / (1024 * 1024), - (efi_deflt->end_sector * DEV_BSIZE) / + (efi_deflt->end_sector * cur_blksz) / (1024 * 1024 * 1024), - (efi_deflt->end_sector * DEV_BSIZE) / + (efi_deflt->end_sector * cur_blksz) / ((uint64_t)1024 * 1024 * 1024 * 1024)); break; case FIO_OPINT: @@ -1518,13 +1518,13 @@ or g(gigabytes)\n"); fmt_print("Expecting up to %llu sectors,", cur_parts->etoc->efi_last_u_lba); fmt_print("or %llu megabytes,", - (cur_parts->etoc->efi_last_u_lba * DEV_BSIZE)/ + (cur_parts->etoc->efi_last_u_lba * cur_blksz)/ (1024 * 1024)); fmt_print("or %llu gigabytes\n", - (cur_parts->etoc->efi_last_u_lba * DEV_BSIZE)/ + (cur_parts->etoc->efi_last_u_lba * cur_blksz)/ (1024 * 1024 * 1024)); fmt_print("or %llu terabytes\n", - (cur_parts->etoc->efi_last_u_lba * DEV_BSIZE)/ + (cur_parts->etoc->efi_last_u_lba * cur_blksz)/ ((uint64_t)1024 * 1024 * 1024 * 1024)); break; } @@ -1676,7 +1676,7 @@ or g(gigabytes)\n"); break; } return (uint64_t)((float)nmegs * 1024.0 * - 1024.0 * 1024.0 * 1024.0 / DEV_BSIZE); + 1024.0 * 1024.0 * 1024.0 / cur_blksz); default: err_print( @@ -2102,6 +2102,7 @@ pr_diskline(disk, num) type->dtype_acyl, type->dtype_nhead, type->dtype_nsect); } else if ((type != NULL) && (disk->label_type == L_TYPE_EFI)) { + cur_blksz = disk->disk_lbasize; print_efi_string(type->vendor, type->product, type->revision, type->capacity); } else if (disk->disk_flags & DSK_RESERVED) { diff --git a/usr/src/cmd/format/label.c b/usr/src/cmd/format/label.c index 3f172c5806..4740baebb2 100644 --- a/usr/src/cmd/format/label.c +++ b/usr/src/cmd/format/label.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -270,11 +270,11 @@ write_label() { int error = 0, head, sec; struct dk_label label; - struct dk_label new_label; struct extvtoc vtoc; struct dk_geom geom; struct dk_gpt *vtoc64; int nbackups; + char *new_label; #if defined(_SUNOS_VTOC_8) int i; @@ -313,7 +313,8 @@ write_label() * Fill in a label structure with the geometry information. */ (void) memset((char *)&label, 0, sizeof (struct dk_label)); - (void) memset((char *)&new_label, 0, sizeof (struct dk_label)); + new_label = zalloc(cur_blksz); + label.dkl_pcyl = pcyl; label.dkl_ncyl = ncyl; label.dkl_acyl = acyl; @@ -358,10 +359,9 @@ write_label() #if defined(_SUNOS_VTOC_16) /* - * Also add in v_sectorsz, as the driver will. Everyone - * else is assuming DEV_BSIZE, so we do the same. + * Also add in v_sectorsz, as the driver will. */ - label.dkl_vtoc.v_sectorsz = DEV_BSIZE; + label.dkl_vtoc.v_sectorsz = cur_blksz; #endif /* defined(_SUNOS_VTOC_16) */ /* @@ -372,6 +372,7 @@ write_label() * Convert the label into a vtoc */ if (label_to_vtoc(&vtoc, &label) == -1) { + free(new_label); return (-1); } /* @@ -400,6 +401,7 @@ write_label() * is only for SCSI disks. */ if (SCSI && do_geometry_sanity_check() != 0) { + free(new_label); return (-1); } @@ -444,14 +446,15 @@ write_label() for (sec = 1; ((sec < BAD_LISTCNT * 2 + 1) && (sec < nsect)); sec += 2) { if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, (diskaddr_t) - ((chs2bn(ncyl + acyl - 1, head, sec)) + solaris_offset), - 1, (caddr_t)&new_label, F_NORMAL, NULL)) { - err_print("Warning: error reading backup label.\n"); + ((chs2bn(ncyl + acyl - 1, head, sec)) + + solaris_offset), 1, new_label, F_NORMAL, NULL)) { + err_print("Warning: error reading" + "backup label.\n"); error = -1; } else { - if (bcmp((char *)&label, (char *)&new_label, + if (bcmp((char *)&label, new_label, sizeof (struct dk_label)) == 0) { - nbackups++; + nbackups++; } } } @@ -466,6 +469,7 @@ write_label() cur_disk->disk_flags |= DSK_LABEL; exit_critical(); + free(new_label); return (error); } @@ -578,7 +582,8 @@ get_disk_info(int fd, struct efi_info *label) err_print("Fetch Capacity failed\n"); return (-1); } - label->capacity = minf.dki_capacity * minf.dki_lbsize / 512; + label->capacity = + minf.dki_capacity * minf.dki_lbsize / cur_blksz; } else { label->capacity = capacity.sc_capacity; @@ -689,7 +694,7 @@ vtoc_to_label(struct dk_label *label, struct extvtoc *vtoc, /* * Sanity-check the vtoc */ - if (vtoc->v_sanity != VTOC_SANE || vtoc->v_sectorsz != DEV_BSIZE || + if (vtoc->v_sanity != VTOC_SANE || vtoc->v_nparts != V_NUMPAR) { return (-1); } @@ -881,7 +886,7 @@ label_to_vtoc(struct extvtoc *vtoc, struct dk_label *label) */ vtoc->v_sanity = VTOC_SANE; vtoc->v_version = V_VERSION; - vtoc->v_sectorsz = DEV_BSIZE; + vtoc->v_sectorsz = cur_blksz; vtoc->v_nparts = V_NUMPAR; (void) memcpy(vtoc->v_asciilabel, label->dkl_asciilabel, diff --git a/usr/src/cmd/format/main.c b/usr/src/cmd/format/main.c index 5d1d9c6c81..5cdb72a825 100644 --- a/usr/src/cmd/format/main.c +++ b/usr/src/cmd/format/main.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -365,6 +365,7 @@ init_globals(disk) cur_label = cur_disk->label_type; cur_ctlr = cur_disk->disk_ctlr; cur_parts = cur_disk->disk_parts; + cur_blksz = cur_disk->disk_lbasize; cur_ctype = cur_ctlr->ctlr_ctype; cur_ops = cur_ctype->ctype_ops; cur_flags = 0; @@ -439,8 +440,8 @@ init_globals(disk) /* * Allocate the buffers. */ - cur_buf = (void *) zalloc(BUF_SECTS * SECSIZE); - pattern_buf = (void *) zalloc(BUF_SECTS * SECSIZE); + cur_buf = (void *) zalloc(BUF_SECTS * cur_blksz); + pattern_buf = (void *) zalloc(BUF_SECTS * cur_blksz); /* * Tell the user which disk (s)he selected. diff --git a/usr/src/cmd/format/menu_analyze.c b/usr/src/cmd/format/menu_analyze.c index 2b18e3c327..e932c258c8 100644 --- a/usr/src/cmd/format/menu_analyze.c +++ b/usr/src/cmd/format/menu_analyze.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -183,12 +183,12 @@ a_print() * Loop through the data buffer. */ lines = 0; - for (i = 0; i < scan_size * SECSIZE / sizeof (int); i += 6) { + for (i = 0; i < scan_size * cur_blksz / sizeof (int); i += 6) { /* * Print the data. */ for (j = 0; j < 6; j++) - if (i + j < scan_size * SECSIZE / sizeof (int)) + if (i + j < scan_size * cur_blksz / sizeof (int)) fmt_print("0x%08x ", *((int *)((int *)cur_buf + i + j))); fmt_print("\n"); diff --git a/usr/src/cmd/format/menu_command.c b/usr/src/cmd/format/menu_command.c index c5b5ea930e..9c43d41ae0 100644 --- a/usr/src/cmd/format/menu_command.c +++ b/usr/src/cmd/format/menu_command.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -293,8 +293,8 @@ found: * Also, set partition table (best guess) too. */ if (!option_f && ncyl == 0 && nhead == 0 && nsect == 0 && - (disk->label_type != L_TYPE_EFI)) { - (void) c_type(); + (disk->label_type != L_TYPE_EFI)) { + (void) c_type(); } /* @@ -305,11 +305,11 @@ found: if ((cur_disk->label_type == L_TYPE_EFI) && (cur_disk->disk_parts->etoc->efi_flags & - EFI_GPT_PRIMARY_CORRUPT)) { - err_print("Reading the primary EFI GPT label "); - err_print("failed. Using backup label.\n"); - err_print("Use the 'backup' command to restore "); - err_print("the primary label.\n"); + EFI_GPT_PRIMARY_CORRUPT)) { + err_print("Reading the primary EFI GPT label "); + err_print("failed. Using backup label.\n"); + err_print("Use the 'backup' command to restore "); + err_print("the primary label.\n"); } #if defined(_SUNOS_VTOC_16) @@ -383,6 +383,7 @@ c_type() } else { auto_conf_choice = -1; } + i = first_disk; for (tptr = type; tptr != NULL; tptr = tptr->dtype_next) { /* @@ -396,7 +397,8 @@ c_type() continue; } if (tptr->dtype_asciilabel) - fmt_print(" %d. %s\n", i++, tptr->dtype_asciilabel); + fmt_print(" %d. %s\n", i++, + tptr->dtype_asciilabel); } other_choice = i; fmt_print(" %d. other\n", i); @@ -418,85 +420,89 @@ c_type() /* * User chose "auto configure". */ - (void) strcpy(x86_devname, cur_disk->disk_name); - switch (cur_disk->label_type) { - case L_TYPE_SOLARIS: - if ((tptr = auto_sense(cur_file, 1, &label)) == NULL) { - err_print("Auto configure failed\n"); - return (-1); - } - fmt_print("%s: configured with capacity of ", - cur_disk->disk_name); - nblks = (diskaddr_t)tptr->dtype_ncyl * tptr->dtype_nhead * - tptr->dtype_nsect; - scaled = bn2mb(nblks); - if (scaled > 1024.0) { - fmt_print("%1.2fGB\n", scaled/1024.0); - } else { - fmt_print("%1.2fMB\n", scaled); - } - fmt_print("<%s cyl %d alt %d hd %d sec %d>\n", - tptr->dtype_asciilabel, tptr->dtype_ncyl, - tptr->dtype_acyl, tptr->dtype_nhead, - tptr->dtype_nsect); - break; - case L_TYPE_EFI: - if ((tptr = auto_efi_sense(cur_file, &efi_info)) == NULL) { - err_print("Auto configure failed\n"); - return (-1); - } - fmt_print("%s: configured with capacity of ", - cur_disk->disk_name); - scaled = bn2mb(efi_info.capacity); - if (scaled > 1024.0) { - fmt_print("%1.2fGB\n", scaled/1024.0); - } else { - fmt_print("%1.2fMB\n", scaled); - } - print_efi_string(efi_info.vendor, efi_info.product, - efi_info.revision, efi_info.capacity); - fmt_print("\n"); - for (nparts = 0; nparts < cur_parts->etoc->efi_nparts; - nparts++) { - if (cur_parts->etoc->efi_parts[nparts].p_tag == - V_RESERVED) { - if (cur_parts->etoc->efi_parts[nparts].p_name) { - (void) strcpy(volname, - cur_parts->etoc->efi_parts[nparts].p_name); - volinit = 1; + (void) strcpy(x86_devname, cur_disk->disk_name); + switch (cur_disk->label_type) { + case L_TYPE_SOLARIS: + if ((tptr = auto_sense(cur_file, 1, &label)) == NULL) { + err_print("Auto configure failed\n"); + return (-1); + } + fmt_print("%s: configured with capacity of ", + cur_disk->disk_name); + nblks = (diskaddr_t)tptr->dtype_ncyl * + tptr->dtype_nhead * tptr->dtype_nsect; + scaled = bn2mb(nblks); + if (scaled > 1024.0) { + fmt_print("%1.2fGB\n", scaled/1024.0); + } else { + fmt_print("%1.2fMB\n", scaled); } + fmt_print("<%s cyl %d alt %d hd %d sec %d>\n", + tptr->dtype_asciilabel, tptr->dtype_ncyl, + tptr->dtype_acyl, tptr->dtype_nhead, + tptr->dtype_nsect); break; - } - } - enter_critical(); - if (delete_disk_type(cur_disk->disk_type) != 0) { - fmt_print("Autoconfiguration failed.\n"); - return (-1); - } - cur_disk->disk_type = tptr; - cur_disk->disk_parts = tptr->dtype_plist; - init_globals(cur_disk); - exit_critical(); - if (volinit) { - for (nparts = 0; nparts < cur_parts->etoc->efi_nparts; - nparts++) { - if (cur_parts->etoc->efi_parts[nparts].p_tag == - V_RESERVED) { - (void) strcpy( - cur_parts->etoc->efi_parts[nparts].p_name, + case L_TYPE_EFI: + if ((tptr = auto_efi_sense(cur_file, &efi_info)) + == NULL) { + err_print("Auto configure failed\n"); + return (-1); + } + fmt_print("%s: configured with capacity of ", + cur_disk->disk_name); + scaled = bn2mb(efi_info.capacity); + if (scaled > 1024.0) { + fmt_print("%1.2fGB\n", scaled/1024.0); + } else { + fmt_print("%1.2fMB\n", scaled); + } + cur_blksz = efi_info.e_parts->efi_lbasize; + print_efi_string(efi_info.vendor, efi_info.product, + efi_info.revision, efi_info.capacity); + fmt_print("\n"); + for (nparts = 0; nparts < cur_parts->etoc->efi_nparts; + nparts++) { + if (cur_parts->etoc->efi_parts[nparts].p_tag == + V_RESERVED) { + if (cur_parts->etoc->efi_parts[nparts]. + p_name) { + (void) strcpy(volname, + cur_parts->etoc->efi_parts + [nparts].p_name); + volinit = 1; + } + break; + } + } + enter_critical(); + if (delete_disk_type(cur_disk->disk_type) != 0) { + fmt_print("Autoconfiguration failed.\n"); + return (-1); + } + cur_disk->disk_type = tptr; + cur_disk->disk_parts = tptr->dtype_plist; + init_globals(cur_disk); + exit_critical(); + if (volinit) { + for (nparts = 0; nparts < + cur_parts->etoc->efi_nparts; nparts++) { + if (cur_parts->etoc->efi_parts[nparts].p_tag == + V_RESERVED) { + (void) strcpy( + cur_parts->etoc->efi_parts[nparts].p_name, volname); - (void) strlcpy(cur_disk->v_volume, volname, + (void) strlcpy(cur_disk->v_volume, volname, LEN_DKL_VVOL); - break; + break; + } + } } - } - } - return (0); - break; - default: + return (0); + break; + default: /* Should never happen */ return (-1); - } + } } else if ((index == other_choice) && (cur_label == L_TYPE_SOLARIS)) { /* * User chose "other". @@ -525,14 +531,13 @@ c_type() d->dtype_threshold = get_threshold(&d->dtype_options); d->dtype_prefetch_min = get_min_prefetch(&d->dtype_options); d->dtype_prefetch_max = get_max_prefetch(d->dtype_prefetch_min, - &d->dtype_options); + &d->dtype_options); d->dtype_bps = get_bps(); #if defined(sparc) d->dtype_dr_type = 0; #endif /* defined(sparc) */ d->dtype_asciilabel = get_asciilabel(); - /* * Add the new type to the list of possible types for * this controller. We lock out interrupts so the lists @@ -563,18 +568,18 @@ c_type() cur_parts->etoc->efi_last_lba = maxLBA; cur_parts->etoc->efi_last_u_lba = maxLBA - 34; for (i = 0; i < cur_parts->etoc->efi_nparts; i++) { - cur_parts->etoc->efi_parts[i].p_start = 0; - cur_parts->etoc->efi_parts[i].p_size = 0; - cur_parts->etoc->efi_parts[i].p_tag = V_UNASSIGNED; + cur_parts->etoc->efi_parts[i].p_start = 0; + cur_parts->etoc->efi_parts[i].p_size = 0; + cur_parts->etoc->efi_parts[i].p_tag = V_UNASSIGNED; } cur_parts->etoc->efi_parts[8].p_start = - maxLBA - 34 - (1024 * 16); + maxLBA - 34 - (1024 * 16); cur_parts->etoc->efi_parts[8].p_size = (1024 * 16); cur_parts->etoc->efi_parts[8].p_tag = V_RESERVED; if (write_label()) { - err_print("Write label failed\n"); + err_print("Write label failed\n"); } else { - cur_disk->disk_flags &= ~DSK_LABEL_DIRTY; + cur_disk->disk_flags &= ~DSK_LABEL_DIRTY; } return (0); } else { @@ -584,10 +589,10 @@ c_type() i = first_disk; tptr = type; while (i < index) { - if (tptr->dtype_asciilabel) { - i++; - } - tptr = tptr->dtype_next; + if (tptr->dtype_asciilabel) { + i++; + } + tptr = tptr->dtype_next; } if ((tptr->dtype_asciilabel == NULL) && (tptr->dtype_next != NULL)) { @@ -605,18 +610,19 @@ c_type() * running from a file. */ if ((tptr != oldtype) && - checkmount((diskaddr_t)-1, (diskaddr_t)-1)) { + checkmount((diskaddr_t)-1, (diskaddr_t)-1)) { err_print( - "Cannot set disk type while it has mounted partitions.\n\n"); + "Cannot set disk type while it has mounted " + "partitions.\n\n"); return (-1); } /* * check for partitions being used for swapping in format zone */ if ((tptr != oldtype) && - checkswap((diskaddr_t)-1, (diskaddr_t)-1)) { - err_print("Cannot set disk type while its partition are \ -currently being used for swapping.\n"); + 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); } @@ -625,11 +631,11 @@ currently being used for swapping.\n"); */ if ((tptr != oldtype) && - checkdevinuse(cur_disk->disk_name, (diskaddr_t)-1, - (diskaddr_t)-1, 0, 0)) { + checkdevinuse(cur_disk->disk_name, (diskaddr_t)-1, + (diskaddr_t)-1, 0, 0)) { err_print("Cannot set disk type while its " "partitions are currently in use.\n"); - return (-1); + return (-1); } /* * If the type selected is different from the previous type, @@ -742,8 +748,8 @@ c_current() fmt_print("<type unknown>\n"); } else if (cur_label == L_TYPE_SOLARIS) { fmt_print("<%s cyl %d alt %d hd %d sec %d>\n", - cur_dtype->dtype_asciilabel, ncyl, - acyl, nhead, nsect); + cur_dtype->dtype_asciilabel, ncyl, + acyl, nhead, nsect); } else if (cur_label == L_TYPE_EFI) { print_efi_string(cur_dtype->vendor, cur_dtype->product, cur_dtype->revision, @@ -753,13 +759,13 @@ c_current() fmt_print("%s\n", cur_disk->devfs_name); } else { fmt_print("%s%d: <", cur_ctlr->ctlr_dname, - cur_disk->disk_dkinfo.dki_unit); + cur_disk->disk_dkinfo.dki_unit); if (cur_dtype == NULL) { fmt_print("type unknown"); } else if (cur_label == L_TYPE_SOLARIS) { fmt_print("%s cyl %d alt %d hd %d sec %d", - cur_dtype->dtype_asciilabel, ncyl, - acyl, nhead, nsect); + cur_dtype->dtype_asciilabel, ncyl, + acyl, nhead, nsect); } else if (cur_label == L_TYPE_EFI) { print_efi_string(cur_dtype->vendor, cur_dtype->product, cur_dtype->revision, @@ -811,8 +817,8 @@ c_format() * can only be retrieved after formatting the disk. */ if ((cur_ctype->ctype_flags & CF_SCSI) && !EMBEDDED_SCSI && - (cur_ctype->ctype_flags & CF_DEFECTS) && - ! (cur_flags & DISK_FORMATTED)) { + (cur_ctype->ctype_flags & CF_DEFECTS) && + ! (cur_flags & DISK_FORMATTED)) { cur_list.flags |= LIST_RELOAD; } else if (cur_list.list == NULL && !EMBEDDED_SCSI) { @@ -827,25 +833,25 @@ c_format() */ ioparam.io_bounds.lower = start = 0; if (cur_label == L_TYPE_SOLARIS) { - if (cur_ctype->ctype_flags & CF_SCSI) { - ioparam.io_bounds.upper = end = datasects() - 1; - } else { - ioparam.io_bounds.upper = end = physsects() - 1; - } + if (cur_ctype->ctype_flags & CF_SCSI) { + ioparam.io_bounds.upper = end = datasects() - 1; + } else { + ioparam.io_bounds.upper = end = physsects() - 1; + } } else { - ioparam.io_bounds.upper = end = cur_parts->etoc->efi_last_lba; + ioparam.io_bounds.upper = end = cur_parts->etoc->efi_last_lba; } if (! (cur_ctlr->ctlr_flags & DKI_FMTVOL)) { deflt = ioparam.io_bounds.lower; start = input(FIO_BN, - "Enter starting block number", ':', - &ioparam, (int *)&deflt, DATA_INPUT); + "Enter starting block number", ':', + &ioparam, (int *)&deflt, DATA_INPUT); ioparam.io_bounds.lower = start; deflt = ioparam.io_bounds.upper; end = input(FIO_BN, - "Enter ending block number", ':', - &ioparam, (int *)&deflt, DATA_INPUT); + "Enter ending block number", ':', + &ioparam, (int *)&deflt, DATA_INPUT); } /* * Some disks can format tracks. Make sure the whole track is @@ -853,7 +859,7 @@ c_format() */ if (cur_ctlr->ctlr_flags & DKI_FMTTRK) { if (bn2s(start) != 0 || - bn2s(end) != sectors(bn2h(end)) - 1) { + bn2s(end) != sectors(bn2h(end)) - 1) { err_print("Controller requires formatting of "); err_print("entire tracks.\n"); return (-1); @@ -886,13 +892,22 @@ currently being used for swapping.\n"); */ if (checkdevinuse(cur_disk->disk_name, start, end, 0, 0)) { err_print("Cannot format disk while its partitions " - "are currently in use.\n"); + "are currently in use.\n"); + return (-1); + } + + if (cur_disk->disk_lbasize != DEV_BSIZE) { + fmt_print("Current disk sector size is %d Byte, format\n" + "will change the sector size to 512 Byte. ", + cur_disk->disk_lbasize); + if (check("Continue")) { return (-1); + } } if (SCSI && (format_time = scsi_format_time()) > 0) { fmt_print( - "Ready to format. Formatting cannot be interrupted\n" + "\nReady to format. Formatting cannot be interrupted\n" "and takes %d minutes (estimated). ", format_time); } else if (cur_dtype->dtype_options & SUP_FMTTIME) { @@ -913,7 +928,7 @@ currently being used for swapping.\n"); * ms. */ format_time = ((60000 / cur_dtype->dtype_rpm) +1) * - format_tracks + format_cyls * 7; + format_tracks + format_cyls * 7; /* * 20% done tick (sec) */ @@ -964,7 +979,7 @@ currently being used for swapping.\n"); */ clock = time((time_t *)0); fmt_print("Beginning format. The current time is %s\n", - ctime(&clock)); + ctime(&clock)); enter_critical(); /* * Mark the defect list dirty so it will be rewritten when we are @@ -980,15 +995,15 @@ currently being used for swapping.\n"); * dirty so it will be rewritten. */ if (cur_disk->label_type == L_TYPE_SOLARIS) { - if (start < totalsects() && end >= datasects()) { - if (cur_disk->disk_flags & DSK_LABEL) - cur_flags |= LABEL_DIRTY; - } + if (start < totalsects() && end >= datasects()) { + if (cur_disk->disk_flags & DSK_LABEL) + cur_flags |= LABEL_DIRTY; + } } else if (cur_disk->label_type == L_TYPE_EFI) { - if (start < 34) { - if (cur_disk->disk_flags & DSK_LABEL) - cur_flags |= LABEL_DIRTY; - } + if (start < 34) { + if (cur_disk->disk_flags & DSK_LABEL) + cur_flags |= LABEL_DIRTY; + } } if (start == 0) { cur_flags |= LABEL_DIRTY; @@ -1078,7 +1093,7 @@ c_repair() diskaddr_t bn; int status; u_ioparam_t ioparam; - char buf[SECSIZE]; + char *buf; int buf_is_good; int block_has_error; int i; @@ -1125,13 +1140,13 @@ c_repair() */ ioparam.io_bounds.lower = 0; if (cur_disk->label_type == L_TYPE_SOLARIS) { - ioparam.io_bounds.upper = physsects() - 1; + ioparam.io_bounds.upper = physsects() - 1; } else { - ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba; + ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba; } bn = input(FIO_BN, - "Enter absolute block number of defect", ':', - &ioparam, (int *)NULL, DATA_INPUT); + "Enter absolute block number of defect", ':', + &ioparam, (int *)NULL, DATA_INPUT); /* * Check to see if there is a mounted file system over the * specified sector. If there is, make sure the user is @@ -1156,6 +1171,9 @@ being used for swapping.\ncontinue")) return (-1); } + buf = zalloc((cur_disk->disk_lbasize == 0) ? + SECSIZE : cur_disk->disk_lbasize); + /* * Try to read the sector before repairing it. If we can * get good data out of it, we can write that data back @@ -1169,7 +1187,7 @@ being used for swapping.\ncontinue")) block_has_error = 1; for (i = 0; i < 5; i++) { status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, bn, - 1, buf, (F_SILENT | F_ALLERRS), NULL); + 1, buf, (F_SILENT | F_ALLERRS), NULL); if (status) break; /* one of the tries failed */ } @@ -1177,6 +1195,7 @@ being used for swapping.\ncontinue")) block_has_error = 0; if (check("\ This block doesn't appear to be bad. Repair it anyway")) { + free(buf); return (0); } } @@ -1184,6 +1203,7 @@ This block doesn't appear to be bad. Repair it anyway")) { * Last chance... */ if (check("Ready to repair defect, continue")) { + free(buf); return (-1); } /* @@ -1194,7 +1214,7 @@ This block doesn't appear to be bad. Repair it anyway")) { buf_is_good = 0; for (i = 0; i < 5; i++) { status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, bn, - 1, buf, F_SILENT, NULL); + 1, buf, F_SILENT, NULL); if (status == 0) { buf_is_good = 1; break; @@ -1229,13 +1249,13 @@ This block doesn't appear to be bad. Repair it anyway")) { */ fmt_print("ok.\n"); if (!buf_is_good) { - bzero(buf, SECSIZE); + bzero(buf, cur_disk->disk_lbasize); } status = (*cur_ops->op_rdwr)(DIR_WRITE, cur_file, bn, - 1, buf, (F_SILENT | F_ALLERRS), NULL); + 1, buf, (F_SILENT | F_ALLERRS), NULL); if (status == 0) { status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, - bn, 1, buf, (F_SILENT | F_ALLERRS), NULL); + bn, 1, buf, (F_SILENT | F_ALLERRS), NULL); } if (status) { fmt_print("The new block %llu (", bn); @@ -1275,6 +1295,8 @@ This block doesn't appear to be bad. Repair it anyway")) { kill_deflist(&work_list); } exit_critical(); + free(buf); + /* * Return status. */ @@ -1304,9 +1326,9 @@ c_show() */ ioparam.io_bounds.lower = 0; if (cur_disk->label_type == L_TYPE_SOLARIS) { - ioparam.io_bounds.upper = physsects() - 1; + ioparam.io_bounds.upper = physsects() - 1; } else { - ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba; + ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba; } bn = input(FIO_BN, "Enter a disk block", ':', &ioparam, (int *)NULL, DATA_INPUT); @@ -1359,7 +1381,7 @@ c_label() /* Bleagh, too descriptive */ if (check_label_with_mount()) { err_print("Cannot label disk while it has " - "mounted partitions.\n\n"); + "mounted partitions.\n\n"); return (-1); } } @@ -1398,7 +1420,7 @@ c_label() */ if (cur_parts == NULL) { fmt_print("Current Partition Table is not set, " - "using default.\n"); + "using default.\n"); cur_disk->disk_parts = cur_parts = cur_dtype->dtype_plist; if (cur_parts == NULL) { err_print("No default available, cannot label.\n"); @@ -1411,53 +1433,55 @@ c_label() */ if (expert_mode) { #if defined(_SUNOS_VTOC_8) - int i; + int i; #endif - int choice; - u_ioparam_t ioparam; - struct extvtoc vtoc; - struct dk_label label; - struct dk_gpt *vtoc64; - struct efi_info efinfo; - struct disk_type *dptr; - - /* Ask user what label to use */ - fmt_print("[0] SMI Label\n"); - fmt_print("[1] EFI Label\n"); - ioparam.io_bounds.lower = 0; - ioparam.io_bounds.upper = 1; - if (cur_label == L_TYPE_SOLARIS) - deflt = 0; - else - deflt = 1; - defltptr = &deflt; - choice = input(FIO_INT, "Specify Label type", ':', - &ioparam, defltptr, DATA_INPUT); - if ((choice == 0) && (cur_label == L_TYPE_SOLARIS)) { - goto expert_end; - } else if ((choice == 1) && (cur_label == L_TYPE_EFI)) { - goto expert_end; - } - switch (choice) { - case 0: + int choice; + u_ioparam_t ioparam; + struct extvtoc vtoc; + struct dk_label label; + struct dk_gpt *vtoc64; + struct efi_info efinfo; + struct disk_type *dptr; + + /* Ask user what label to use */ + fmt_print("[0] SMI Label\n"); + fmt_print("[1] EFI Label\n"); + ioparam.io_bounds.lower = 0; + ioparam.io_bounds.upper = 1; + if (cur_label == L_TYPE_SOLARIS) + deflt = 0; + else + deflt = 1; + defltptr = &deflt; + choice = input(FIO_INT, "Specify Label type", ':', + &ioparam, defltptr, DATA_INPUT); + if ((choice == 0) && (cur_label == L_TYPE_SOLARIS)) { + goto expert_end; + } else if ((choice == 1) && (cur_label == L_TYPE_EFI)) { + goto expert_end; + } + switch (choice) { + case 0: /* * EFI label to SMI label */ if (cur_dtype->capacity > INFINITY) { - fmt_print("Warning: SMI labels only support up to 2 TB.\n"); + fmt_print("Warning: SMI labels only support up to " + "2 TB.\n"); } 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")) + fmt_print("Warning: This disk has an EFI label. " + "Changing to SMI label will erase all\n" + "current partitions.\n"); + if (check("Continue")) return (-1); #if defined(_FIRMWARE_NEEDS_FDISK) - fmt_print("You must use fdisk to delete the current " + 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); + return (-1); #endif } @@ -1509,7 +1533,7 @@ c_label() } - case 1: + case 1: /* * SMI label to EFI label */ @@ -1523,7 +1547,7 @@ c_label() } if (get_disk_info(cur_file, &efinfo) != 0) { - return (-1); + return (-1); } (void) memset((char *)&label, 0, sizeof (struct dk_label)); label.dkl_pcyl = pcyl; @@ -1536,21 +1560,21 @@ c_label() label.dkl_nsect = nsect; #if defined(_SUNOS_VTOC_8) for (i = 0; i < NDKMAP; i++) { - label.dkl_map[i] = cur_parts->pinfo_map[i]; + label.dkl_map[i] = cur_parts->pinfo_map[i]; } #endif /* defined(_SUNOS_VTOC_8) */ label.dkl_magic = DKL_MAGIC; label.dkl_vtoc = cur_parts->vtoc; if (label_to_vtoc(&vtoc, &label) == -1) { - return (-1); + return (-1); } if (SMI_vtoc_to_EFI(cur_file, &vtoc64) == -1) { - return (-1); + return (-1); } if (efi_write(cur_file, vtoc64) != 0) { - err_check(vtoc64); - err_print("Warning: error writing EFI.\n"); - return (-1); + err_check(vtoc64); + err_print("Warning: error writing EFI.\n"); + return (-1); } else { cur_disk->disk_flags &= ~DSK_LABEL_DIRTY; } @@ -1580,7 +1604,7 @@ c_label() (void) copy_solaris_part(&cur_disk->fdisk_part); return (0); - } + } } expert_end: @@ -1648,7 +1672,7 @@ c_defect() * display appropriate message. */ if ((cur_ops->op_ex_man == NULL) && (cur_ops->op_ex_cur == NULL) && - (cur_ops->op_create == NULL) && (cur_ops->op_wr_cur == NULL)) { + (cur_ops->op_create == NULL) && (cur_ops->op_wr_cur == NULL)) { err_print("Controller does not support defect management\n"); err_print("or disk supports automatic defect management.\n"); return (-1); @@ -1667,7 +1691,8 @@ c_defect() if ((work_list.list == NULL) && (cur_list.list != NULL)) { work_list.header = cur_list.header; work_list.list = (struct defect_entry *)zalloc( - LISTSIZE(work_list.header.count) * SECSIZE); + deflist_size(cur_blksz, work_list.header.count) * + cur_blksz); for (i = 0; i < work_list.header.count; i++) *(work_list.list + i) = *(cur_list.list + i); work_list.flags = cur_list.flags & LIST_PGLIST; @@ -1710,6 +1735,7 @@ c_backup() struct partition_info *parts, *plist; diskaddr_t bn; int sec, head, i; + char *buf; /* * There must be a current disk type (and therefore a current disk). @@ -1736,23 +1762,26 @@ c_backup() * the user is serious. */ if (cur_disk->label_type == L_TYPE_EFI) { - if (((cur_disk->disk_parts->etoc->efi_flags & - EFI_GPT_PRIMARY_CORRUPT) == 0) && - check("Disk has a primary label, still continue")) - return (-1); - fmt_print("Restoring primary label.\n"); - if (write_label()) { - err_print("Failed\n"); - return (-1); - } - return (0); + if (((cur_disk->disk_parts->etoc->efi_flags & + EFI_GPT_PRIMARY_CORRUPT) == 0) && + check("Disk has a primary label, still continue")) + return (-1); + fmt_print("Restoring primary label.\n"); + if (write_label()) { + err_print("Failed\n"); + return (-1); + } + return (0); } else if (((cur_disk->disk_flags & (DSK_LABEL | DSK_LABEL_DIRTY)) == - DSK_LABEL) && + DSK_LABEL) && (check("Disk has a primary label, still continue"))) { return (-1); } + + buf = zalloc(cur_blksz); fmt_print("Searching for backup labels..."); (void) fflush(stdout); + /* * Some disks have the backup labels in a strange place. */ @@ -1770,9 +1799,12 @@ c_backup() * Attempt to read it. */ if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, bn, - 1, (char *)&label, F_NORMAL, NULL)) { + 1, buf, F_NORMAL, NULL)) { continue; } + + (void *) memcpy((char *)&label, buf, sizeof (struct dk_label)); + /* * Verify that it is a reasonable label. */ @@ -1801,15 +1833,17 @@ c_backup() fmt_print("\ Unknown disk type in backup label\n"); exit_critical(); + free(buf); return (-1); } fmt_print("Backup label claims different type:\n"); fmt_print(" <%s cyl %d alt %d hd %d sec %d>\n", - label.dkl_asciilabel, label.dkl_ncyl, - label.dkl_acyl, label.dkl_nhead, - label.dkl_nsect); + label.dkl_asciilabel, label.dkl_ncyl, + label.dkl_acyl, label.dkl_nhead, + label.dkl_nsect); if (check("Continue")) { exit_critical(); + free(buf); return (-1); } cur_dtype = dtype; @@ -1828,7 +1862,7 @@ Unknown disk type in backup label\n"); */ if (parts == NULL) { parts = (struct partition_info *) - zalloc(sizeof (struct partition_info)); + zalloc(sizeof (struct partition_info)); plist = dtype->dtype_plist; if (plist == NULL) dtype->dtype_plist = parts; @@ -1863,22 +1897,28 @@ Unknown disk type in backup label\n"); */ if (EMBEDDED_SCSI) { fmt_print("Restoring primary label.\n"); - if (write_label()) + if (write_label()) { + free(buf); return (-1); + } } else { fmt_print("Restoring primary label and defect list.\n"); - if (write_label()) + if (write_label()) { + free(buf); return (-1); + } if (cur_list.list != NULL) write_deflist(&cur_list); } fmt_print("\n"); + free(buf); return (0); } /* * If we didn't find any backup labels, say so. */ fmt_print("not found.\n\n"); + free(buf); return (0); } @@ -1894,8 +1934,8 @@ c_verify_efi() status = read_efi_label(cur_file, &efi_info); if (status != 0) { - err_print("Warning: Could not read label.\n"); - return (-1); + err_print("Warning: Could not read label.\n"); + return (-1); } if (cur_parts->etoc->efi_flags & EFI_GPT_PRIMARY_CORRUPT) { err_print("Reading the primary EFI GPT label "); @@ -1906,20 +1946,20 @@ c_verify_efi() tmp_pinfo.etoc = efi_info.e_parts; fmt_print("\n"); if (cur_parts->etoc->efi_parts[8].p_name) { - fmt_print("Volume name = <%8s>\n", - cur_parts->etoc->efi_parts[8].p_name); + fmt_print("Volume name = <%8s>\n", + cur_parts->etoc->efi_parts[8].p_name); } else { - fmt_print("Volume name = < >\n"); + fmt_print("Volume name = < >\n"); } fmt_print("ascii name = "); print_efi_string(efi_info.vendor, efi_info.product, efi_info.revision, efi_info.capacity); fmt_print("\n"); - fmt_print("bytes/sector = %d\n", DEV_BSIZE); + fmt_print("bytes/sector = %d\n", cur_blksz); fmt_print("sectors = %llu\n", cur_parts->etoc->efi_last_lba); fmt_print("accessible sectors = %llu\n", - cur_parts->etoc->efi_last_u_lba); + cur_parts->etoc->efi_last_u_lba); print_map(&tmp_pinfo); return (0); @@ -1941,6 +1981,7 @@ c_verify() int p_label_found = 0; int b_label_found = 0; char id_str[128]; + char *buf; /* * There must be a current disk type (and therefore a current disk). @@ -1966,7 +2007,7 @@ c_verify() * Branch off here if the disk is EFI labelled. */ if (cur_label == L_TYPE_EFI) { - return (c_verify_efi()); + return (c_verify_efi()); } /* * Attempt to read the primary label. @@ -1985,7 +2026,7 @@ c_verify() (void) strncpy(id_str, p_label.dkl_asciilabel, 128); if ((!checklabel((struct dk_label *)&p_label)) || - (trim_id(p_label.dkl_asciilabel))) { + (trim_id(p_label.dkl_asciilabel))) { err_print("\ Warning: Primary label appears to be corrupt.\n"); p_label_bad = 1; @@ -1995,10 +2036,10 @@ Warning: Primary label appears to be corrupt.\n"); * Make sure it matches current label */ if ((!dtype_match(&p_label, cur_dtype)) || - (!parts_match(&p_label, cur_parts))) { + (!parts_match(&p_label, cur_parts))) { err_print("\ Warning: Primary label on disk appears to be different from\ncurrent label.\n"); - p_label_bad = 1; + p_label_bad = 1; } } } @@ -2011,6 +2052,8 @@ Warning: Primary label on disk appears to be different from\ncurrent label.\n"); head = 2; else head = nhead - 1; + + buf = zalloc(cur_blksz); /* * Loop through each copy of the backup label. */ @@ -2021,8 +2064,12 @@ 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, bn, - 1, (char *)&b_label, F_NORMAL, NULL)) + 1, buf, F_NORMAL, NULL)) continue; + + (void *) memcpy((char *)&b_label, buf, + sizeof (struct dk_label)); + /* * Verify that it is a reasonable label. */ @@ -2043,11 +2090,11 @@ Warning: Primary label on disk appears to be different from\ncurrent label.\n"); */ if (p_label_found) { if ((strcmp(b_label.dkl_asciilabel, - p_label.dkl_asciilabel) != 0) || - (b_label.dkl_ncyl != p_label.dkl_ncyl) || - (b_label.dkl_acyl != p_label.dkl_acyl) || - (b_label.dkl_nhead != p_label.dkl_nhead) || - (b_label.dkl_nsect != p_label.dkl_nsect)) { + p_label.dkl_asciilabel) != 0) || + (b_label.dkl_ncyl != p_label.dkl_ncyl) || + (b_label.dkl_acyl != p_label.dkl_acyl) || + (b_label.dkl_nhead != p_label.dkl_nhead) || + (b_label.dkl_nsect != p_label.dkl_nsect)) { b_label_bad = 1; } else { for (i = 0; i < NDKMAP; i++) { @@ -2062,13 +2109,16 @@ Warning: Primary label on disk appears to be different from\ncurrent label.\n"); #elif defined(_SUNOS_VTOC_16) if ((b_label.dkl_vtoc.v_part[i].p_tag != - p_label.dkl_vtoc.v_part[i].p_tag) || - (b_label.dkl_vtoc.v_part[i].p_flag != - p_label.dkl_vtoc.v_part[i].p_flag) || - (b_label.dkl_vtoc.v_part[i].p_start != - p_label.dkl_vtoc.v_part[i].p_start) || - (b_label.dkl_vtoc.v_part[i].p_size != - p_label.dkl_vtoc.v_part[i].p_size)) { + p_label.dkl_vtoc.v_part[i].p_tag) || + (b_label.dkl_vtoc.v_part[i].p_flag + != p_label.dkl_vtoc.v_part[i]. + p_flag) || + (b_label.dkl_vtoc.v_part[i].p_start + != p_label.dkl_vtoc.v_part[i]. + p_start) || + (b_label.dkl_vtoc.v_part[i].p_size + != p_label.dkl_vtoc.v_part[i]. + p_size)) { b_label_bad = 1; break; } @@ -2104,6 +2154,7 @@ Warning: Check the current partitioning and 'label' the disk or use the\n\ fmt_print("\nBackup label contents:\n"); label = &b_label; } else { + free(buf); return (0); } @@ -2119,9 +2170,9 @@ Warning: Check the current partitioning and 'label' the disk or use the\n\ #elif defined(_SUNOS_VTOC_16) tmp_pinfo.pinfo_map[i].dkl_cylno = - label->dkl_vtoc.v_part[i].p_start / spc(); + label->dkl_vtoc.v_part[i].p_start / spc(); tmp_pinfo.pinfo_map[i].dkl_nblk = - label->dkl_vtoc.v_part[i].p_size; + label->dkl_vtoc.v_part[i].p_size; #else #error No VTOC layout defined. #endif /* defined(_SUNOS_VTOC_8) */ @@ -2143,6 +2194,7 @@ Warning: Check the current partitioning and 'label' the disk or use the\n\ fmt_print("nsect = %4d\n", label->dkl_nsect); print_map(&tmp_pinfo); + free(buf); return (0); } @@ -2323,9 +2375,9 @@ being used for swapping.\n\n"); bcopy(volname, cur_disk->v_volume, min((int)strlen(volname), LEN_DKL_VVOL)); if (cur_label == L_TYPE_EFI) { - bzero(cur_parts->etoc->efi_parts[8].p_name, LEN_DKL_VVOL); - bcopy(volname, cur_parts->etoc->efi_parts[8].p_name, - LEN_DKL_VVOL); + bzero(cur_parts->etoc->efi_parts[8].p_name, LEN_DKL_VVOL); + bcopy(volname, cur_parts->etoc->efi_parts[8].p_name, + LEN_DKL_VVOL); } /* * Write the labels out (this will also notify unix) and diff --git a/usr/src/cmd/format/menu_defect.c b/usr/src/cmd/format/menu_defect.c index 9a31134ec9..55388253ae 100644 --- a/usr/src/cmd/format/menu_defect.c +++ b/usr/src/cmd/format/menu_defect.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -92,7 +92,8 @@ d_restore() if (cur_list.list != NULL) { work_list.header = cur_list.header; work_list.list = (struct defect_entry *)zalloc( - LISTSIZE(work_list.header.count) * SECSIZE); + deflist_size(cur_blksz, work_list.header.count) * + cur_blksz); for (i = 0; i < work_list.header.count; i++) *(work_list.list + i) = *(cur_list.list + i); } @@ -230,7 +231,7 @@ and may take a long while. Continue")) fmt_print("Extraction complete.\n"); fmt_print( "Working list updated, total of %d defects.\n\n", - work_list.header.count); + work_list.header.count); } else { fmt_print("Extraction failed.\n\n"); } @@ -277,7 +278,7 @@ d_add() ioparam.io_bounds.lower = 0; ioparam.io_bounds.upper = 1; type = input(FIO_INT, "Select input format (enter its number)", ':', - &ioparam, &deflt, DATA_INPUT); + &ioparam, &deflt, DATA_INPUT); fmt_print("\nEnter Control-C to terminate.\n"); loop: if (type) { @@ -288,9 +289,9 @@ loop: def.bfi = def.nbits = UNKNOWN; ioparam.io_bounds.lower = 0; if (cur_disk->label_type == L_TYPE_SOLARIS) { - ioparam.io_bounds.upper = physsects() - 1; + ioparam.io_bounds.upper = physsects() - 1; } else { - ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba; + ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba; } bn = input(FIO_BN, "Enter defective block number", ':', &ioparam, (int *)NULL, DATA_INPUT); @@ -349,7 +350,7 @@ loop: work_list.header.magicno = (uint_t)DEFECT_MAGIC; work_list.header.count = 0; work_list.list = (struct defect_entry *)zalloc( - LISTSIZE(0) * SECSIZE); + deflist_size(cur_blksz, 0) * cur_blksz); } /* * Add the defect to the working list. @@ -420,9 +421,11 @@ d_delete() * If the size of the list in sectors has changed, reallocate * the list to shrink it appropriately. */ - if (LISTSIZE(count - 1) < LISTSIZE(count)) + if (deflist_size(cur_blksz, count - 1) < + deflist_size(cur_blksz, count)) work_list.list = (struct defect_entry *)rezalloc( - (void *)work_list.list, LISTSIZE(count - 1) * SECSIZE); + (void *)work_list.list, + deflist_size(cur_blksz, count - 1) * cur_blksz); /* * Decrement the defect count. */ @@ -488,7 +491,7 @@ d_print() * before going on. */ if (one_line || - (!nomore && ((i + 1) % (tty_lines - 1) == 0))) { + (!nomore && ((i + 1) % (tty_lines - 1) == 0))) { /* * Get the next character. */ @@ -574,8 +577,8 @@ d_dump() * Print a header containing the magic number, count, and checksum. */ (void) fprintf(fptr, "0x%08x%8d 0x%08x\n", - work_list.header.magicno, - work_list.header.count, work_list.header.cksum); + work_list.header.magicno, + work_list.header.count, work_list.header.cksum); /* * Loop through each defect in the working list. Write the * defect info to the defect file. @@ -583,8 +586,8 @@ d_dump() for (i = 0; i < work_list.header.count; i++) { dptr = work_list.list + i; (void) fprintf(fptr, "%4d%8d%7d%8d%8d%8d\n", - i+1, dptr->cyl, dptr->head, - dptr->bfi, dptr->nbits, dptr->sect); + i+1, dptr->cyl, dptr->head, + dptr->bfi, dptr->nbits, dptr->sect); } fmt_print("defect file updated, total of %d defects.\n", i); /* @@ -663,13 +666,13 @@ d_load() * Scan in the header. */ items = fscanf(fptr, "0x%x%d 0x%x\n", &magicno, - &count, (uint_t *)&cksum); + &count, (uint_t *)&cksum); /* * If the header is wrong, this isn't a good defect file. */ if (items != 3 || count < 0 || (magicno != (uint_t)DEFECT_MAGIC && - magicno != (uint_t)NO_CHECKSUM)) { + magicno != (uint_t)NO_CHECKSUM)) { err_print("Defect file is corrupted.\n"); status = -1; goto out; @@ -690,8 +693,8 @@ d_load() /* * Allocate space for the new list. */ - work_list.list = (struct defect_entry *)zalloc(LISTSIZE(count) * - SECSIZE); + work_list.list = (struct defect_entry *)zalloc( + deflist_size(cur_blksz, count) * cur_blksz); /* * Mark the working list dirty since we are modifying it. */ @@ -806,14 +809,14 @@ commit_list() work_list.header.magicno = (uint_t)DEFECT_MAGIC; work_list.header.count = 0; work_list.list = (struct defect_entry *)zalloc( - LISTSIZE(0) * SECSIZE); + deflist_size(cur_blksz, 0) * cur_blksz); } /* * Copy the working list into the current list. */ cur_list.header = work_list.header; cur_list.list = (struct defect_entry *)zalloc( - LISTSIZE(cur_list.header.count) * SECSIZE); + deflist_size(cur_blksz, cur_list.header.count) * cur_blksz); for (i = 0; i < cur_list.header.count; i++) *(cur_list.list + i) = *(work_list.list + i); /* diff --git a/usr/src/cmd/format/menu_fdisk.c b/usr/src/cmd/format/menu_fdisk.c index 4ebadee5ab..e1affd636a 100644 --- a/usr/src/cmd/format/menu_fdisk.c +++ b/usr/src/cmd/format/menu_fdisk.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -274,11 +274,11 @@ open_cur_file(int mode) char pbuf[MAXPATHLEN]; switch (mode) { - case FD_USE_P0_PATH: + case FD_USE_P0_PATH: (void) get_pname(&pbuf[0]); dkpath = pbuf; break; - case FD_USE_CUR_DISK_PATH: + case FD_USE_CUR_DISK_PATH: if (cur_disk->fdisk_part.systid == SUNIXOS || cur_disk->fdisk_part.systid == SUNIXOS2) { (void) get_sname(&pbuf[0]); @@ -287,7 +287,7 @@ open_cur_file(int mode) dkpath = cur_disk->disk_path; } break; - default: + default: err_print("Error: Invalid mode option for opening cur_file\n"); fullabort(); } @@ -388,7 +388,7 @@ update_cur_parts() for (i = 0; i < NDKMAP; i++) { #if defined(_SUNOS_VTOC_16) if (cur_parts->vtoc.v_part[i].p_tag && - cur_parts->vtoc.v_part[i].p_tag != V_ALTSCTR) { + cur_parts->vtoc.v_part[i].p_tag != V_ALTSCTR) { cur_parts->vtoc.v_part[i].p_start = 0; cur_parts->vtoc.v_part[i].p_size = 0; @@ -396,9 +396,9 @@ update_cur_parts() cur_parts->pinfo_map[i].dkl_nblk = 0; cur_parts->pinfo_map[i].dkl_cylno = 0; cur_parts->vtoc.v_part[i].p_tag = - default_vtoc_map[i].p_tag; + default_vtoc_map[i].p_tag; cur_parts->vtoc.v_part[i].p_flag = - default_vtoc_map[i].p_flag; + default_vtoc_map[i].p_flag; #if defined(_SUNOS_VTOC_16) } #endif @@ -412,14 +412,14 @@ update_cur_parts() cur_parts->pinfo_map[I_PARTITION].dkl_nblk = spc(); cur_parts->pinfo_map[I_PARTITION].dkl_cylno = 0; cur_parts->vtoc.v_part[C_PARTITION].p_start = - cur_parts->pinfo_map[C_PARTITION].dkl_cylno * nhead * nsect; + cur_parts->pinfo_map[C_PARTITION].dkl_cylno * nhead * nsect; cur_parts->vtoc.v_part[C_PARTITION].p_size = - cur_parts->pinfo_map[C_PARTITION].dkl_nblk; + cur_parts->pinfo_map[C_PARTITION].dkl_nblk; cur_parts->vtoc.v_part[I_PARTITION].p_start = - cur_parts->pinfo_map[I_PARTITION].dkl_cylno; + cur_parts->pinfo_map[I_PARTITION].dkl_cylno; cur_parts->vtoc.v_part[I_PARTITION].p_size = - cur_parts->pinfo_map[I_PARTITION].dkl_nblk; + cur_parts->pinfo_map[I_PARTITION].dkl_nblk; #endif /* defined(_SUNOS_VTOC_16) */ parts = cur_dtype->dtype_plist; @@ -438,18 +438,33 @@ get_solaris_part(int fd, struct ipart *ipart) int i; struct ipart ip; int status; + char *mbr; char *bootptr; struct dk_label update_label; (void) lseek(fd, 0, 0); - status = read(fd, (caddr_t)&boot_sec, NBPSCTR); - if (status != NBPSCTR) { + /* + * We may get mbr of different size, but the first 512 bytes + * are valid information. + */ + mbr = malloc(cur_blksz); + if (mbr == NULL) { + err_print("No memory available.\n"); + return (-1); + } + status = read(fd, mbr, cur_blksz); + + if (status != cur_blksz) { err_print("Bad read of fdisk partition. Status = %x\n", status); err_print("Cannot read fdisk partition information.\n"); + free(mbr); return (-1); } + (void) memcpy(&boot_sec, mbr, sizeof (struct mboot)); + free(mbr); + for (i = 0; i < FD_NUMPART; i++) { int ipc; @@ -478,8 +493,8 @@ get_solaris_part(int fd, struct ipart *ipart) #ifdef DEBUG else { err_print("Critical geometry values are zero:\n" - "\tnhead = %d; nsect = %d\n", nhead, - nsect); + "\tnhead = %d; nsect = %d\n", nhead, + nsect); } #endif /* DEBUG */ @@ -555,6 +570,7 @@ get_solaris_part(int fd, struct ipart *ipart) nsect = cur_dtype->dtype_nsect; nhead = cur_dtype->dtype_nhead; } + return (0); } @@ -565,6 +581,7 @@ copy_solaris_part(struct ipart *ipart) int status, i, fd; struct mboot mboot; + char *mbr; struct ipart ip; char buf[MAXPATHLEN]; char *bootptr; @@ -574,7 +591,7 @@ copy_solaris_part(struct ipart *ipart) if (stat(buf, &statbuf) == -1 || !S_ISCHR(statbuf.st_mode) || ((cur_label == L_TYPE_EFI) && - (cur_disk->disk_flags & DSK_LABEL_DIRTY))) { + (cur_disk->disk_flags & DSK_LABEL_DIRTY))) { /* * Make sure to reset solaris_offset to zero if it is * previously set by a selected disk that @@ -595,14 +612,26 @@ copy_solaris_part(struct ipart *ipart) return (-1); } - status = read(fd, (caddr_t)&mboot, sizeof (struct mboot)); + /* + * We may get mbr of different size, but the first 512 bytes + * are valid information. + */ + mbr = malloc(cur_blksz); + if (mbr == NULL) { + err_print("No memory available.\n"); + return (-1); + } + status = read(fd, mbr, cur_blksz); - if (status != sizeof (struct mboot)) { + if (status != cur_blksz) { err_print("Bad read of fdisk partition.\n"); (void) close(fd); + free(mbr); return (-1); } + (void) memcpy(&mboot, mbr, sizeof (struct mboot)); + for (i = 0; i < FD_NUMPART; i++) { int ipc; @@ -631,8 +660,8 @@ copy_solaris_part(struct ipart *ipart) #ifdef DEBUG else { err_print("Critical geometry values are zero:\n" - "\tnhead = %d; nsect = %d\n", nhead, - nsect); + "\tnhead = %d; nsect = %d\n", nhead, + nsect); } #endif /* DEBUG */ @@ -641,8 +670,8 @@ copy_solaris_part(struct ipart *ipart) } (void) close(fd); + free(mbr); return (0); - } #if defined(_FIRMWARE_NEEDS_FDISK) @@ -652,24 +681,36 @@ auto_solaris_part(struct dk_label *label) int status, i, fd; struct mboot mboot; + char *mbr; struct ipart ip; char *bootptr; char pbuf[MAXPATHLEN]; - (void) get_pname(&pbuf[0]); if ((fd = open_disk(pbuf, O_RDONLY)) < 0) { err_print("Error: can't open selected disk '%s'.\n", pbuf); return (-1); } - status = read(fd, (caddr_t)&mboot, sizeof (struct mboot)); + /* + * We may get mbr of different size, but the first 512 bytes + * are valid information. + */ + mbr = malloc(cur_blksz); + if (mbr == NULL) { + err_print("No memory available.\n"); + return (-1); + } + status = read(fd, mbr, cur_blksz); - if (status != sizeof (struct mboot)) { + if (status != cur_blksz) { err_print("Bad read of fdisk partition.\n"); + free(mbr); return (-1); } + (void) memcpy(&mboot, mbr, sizeof (struct mboot)); + for (i = 0; i < FD_NUMPART; i++) { int ipc; @@ -697,11 +738,11 @@ auto_solaris_part(struct dk_label *label) #ifdef DEBUG else { err_print("Critical label fields aren't " - "non-zero:\n" - "\tlabel->dkl_nhead = %d; " - "label->dkl_nsect = " - "%d\n", label->dkl_nhead, - label->dkl_nsect); + "non-zero:\n" + "\tlabel->dkl_nhead = %d; " + "label->dkl_nsect = " + "%d\n", label->dkl_nhead, + label->dkl_nsect); } #endif /* DEBUG */ @@ -711,7 +752,7 @@ auto_solaris_part(struct dk_label *label) } (void) close(fd); - + free(mbr); return (0); } #endif /* defined(_FIRMWARE_NEEDS_FDISK) */ @@ -739,9 +780,9 @@ good_fdisk() } else { err_print("WARNING - "); err_print("This disk may be in use by an application " - "that has\n\t modified the fdisk table. Ensure " - "that this disk is\n\t not currently in use " - "before proceeding to use fdisk.\n"); + "that has\n\t modified the fdisk table. Ensure " + "that this disk is\n\t not currently in use " + "before proceeding to use fdisk.\n"); return (0); } } diff --git a/usr/src/cmd/format/misc.c b/usr/src/cmd/format/misc.c index f148cc3115..55ca2e80a8 100644 --- a/usr/src/cmd/format/misc.c +++ b/usr/src/cmd/format/misc.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -867,7 +867,7 @@ bn2mb(uint64_t nblks) float n; n = (float)nblks / 1024.0; - return ((n / 1024.0) * DEV_BSIZE); + return ((n / 1024.0) * cur_blksz); } @@ -876,7 +876,7 @@ mb2bn(float mb) { diskaddr_t n; - n = (diskaddr_t)(mb * 1024.0 * (1024.0 / DEV_BSIZE)); + n = (diskaddr_t)(mb * 1024.0 * (1024.0 / cur_blksz)); return (n); } @@ -886,7 +886,7 @@ bn2gb(uint64_t nblks) float n; n = (float)nblks / (1024.0 * 1024.0); - return ((n/1024.0) * DEV_BSIZE); + return ((n/1024.0) * cur_blksz); } @@ -896,7 +896,7 @@ bn2tb(uint64_t nblks) float n; n = (float)nblks / (1024.0 * 1024.0 * 1024.0); - return ((n/1024.0) * DEV_BSIZE); + return ((n/1024.0) * cur_blksz); } diskaddr_t @@ -904,7 +904,7 @@ gb2bn(float gb) { diskaddr_t n; - n = (diskaddr_t)(gb * 1024.0 * 1024.0 * (1024.0 / DEV_BSIZE)); + n = (diskaddr_t)(gb * 1024.0 * 1024.0 * (1024.0 / cur_blksz)); return (n); } diff --git a/usr/src/cmd/format/prompts.c b/usr/src/cmd/format/prompts.c index ce87f06349..e6ef368bbb 100644 --- a/usr/src/cmd/format/prompts.c +++ b/usr/src/cmd/format/prompts.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 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * This file contains functions to prompt the user for various * disk characteristics. By isolating these into functions, @@ -196,7 +193,7 @@ get_bpt(n_sects, options) *options |= SUP_BPT; ioparam.io_bounds.lower = 1; ioparam.io_bounds.upper = INFINITY; - deflt = n_sects * SECSIZE; + deflt = n_sects * cur_blksz; return (input(FIO_INT, "Enter number of bytes/track", ':', &ioparam, &deflt, DATA_INPUT)); } @@ -435,7 +432,7 @@ get_bps() ioparam.io_bounds.upper = MAX_BPS; deflt = AVG_BPS; return (input(FIO_INT, "Enter bytes per sector", - ':', &ioparam, &deflt, DATA_INPUT)); + ':', &ioparam, &deflt, DATA_INPUT)); } return (0); diff --git a/usr/src/cmd/format/startup.c b/usr/src/cmd/format/startup.c index 99aa8d9d34..fd8e035688 100644 --- a/usr/src/cmd/format/startup.c +++ b/usr/src/cmd/format/startup.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -1607,6 +1607,12 @@ add_device_to_disklist(char *devname, char *devpath) } } + if (ioctl(search_file, DKIOCGMEDIAINFO, &mediainfo) == -1) { + cur_blksz = DEV_BSIZE; + } else { + cur_blksz = mediainfo.dki_lbsize; + } + /* * If the type of disk is one we don't know about, * add it to the list. @@ -1708,8 +1714,11 @@ add_device_to_disklist(char *devname, char *devpath) * generic check for reserved disks here, including intel disks. */ if (dkinfo.dki_ctype == DKC_SCSI_CCS) { + char *first_sector; + + first_sector = zalloc(cur_blksz); i = scsi_rdwr(DIR_READ, search_file, (diskaddr_t)0, - 1, (char *)&search_label, F_SILENT, NULL); + 1, first_sector, F_SILENT, NULL); switch (i) { case DSK_RESERVED: access_flags |= DSK_RESERVED; @@ -1720,6 +1729,7 @@ add_device_to_disklist(char *devname, char *devpath) default: break; } + free(first_sector); } #endif /* defined(sparc) */ @@ -1751,6 +1761,11 @@ add_device_to_disklist(char *devname, char *devpath) search_disk->disk_name = alloc_string(devname); search_disk->disk_path = alloc_string(devpath); + /* + * Remember the lba size of the disk + */ + search_disk->disk_lbasize = cur_blksz; + (void) strcpy(x86_devname, devname); /* |