Deleted Added
full compact
camcontrol.c (225018) camcontrol.c (225950)
1/*
2 * Copyright (c) 1997-2007 Kenneth D. Merry
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1997-2007 Kenneth D. Merry
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sbin/camcontrol/camcontrol.c 225018 2011-08-19 21:33:46Z mav $");
30__FBSDID("$FreeBSD: head/sbin/camcontrol/camcontrol.c 225950 2011-10-03 20:32:55Z ken $");
31
32#include <sys/ioctl.h>
33#include <sys/stdint.h>
34#include <sys/types.h>
35#include <sys/endian.h>
36#include <sys/sbuf.h>
37
38#include <stdio.h>

--- 1863 unchanged lines hidden (view full) ---

1902
1903 if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR)
1904 && (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
1905 && ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
1906 struct scsi_sense_data *sense;
1907 int error_code, sense_key, asc, ascq;
1908
1909 sense = &ccb->csio.sense_data;
31
32#include <sys/ioctl.h>
33#include <sys/stdint.h>
34#include <sys/types.h>
35#include <sys/endian.h>
36#include <sys/sbuf.h>
37
38#include <stdio.h>

--- 1863 unchanged lines hidden (view full) ---

1902
1903 if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR)
1904 && (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
1905 && ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
1906 struct scsi_sense_data *sense;
1907 int error_code, sense_key, asc, ascq;
1908
1909 sense = &ccb->csio.sense_data;
1910 scsi_extract_sense(sense, &error_code, &sense_key, &asc, &ascq);
1910 scsi_extract_sense_len(sense, ccb->csio.sense_len -
1911 ccb->csio.sense_resid, &error_code, &sense_key, &asc,
1912 &ascq, /*show_errors*/ 1);
1911
1912 /*
1913 * According to the SCSI spec, if the disk doesn't support
1914 * the requested format, it will generally return a sense
1915 * key of RECOVERED ERROR, and an additional sense code
1916 * of "DEFECT LIST NOT FOUND". So, we check for that, and
1917 * also check to make sure that the returned length is
1918 * greater than 0, and then print out whatever format the

--- 1874 unchanged lines hidden (view full) ---

3793
3794 if ((status != CAM_REQ_CMP)
3795 && (status == CAM_SCSI_STATUS_ERROR)
3796 && ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
3797 struct scsi_sense_data *sense;
3798 int error_code, sense_key, asc, ascq;
3799
3800 sense = &ccb->csio.sense_data;
1913
1914 /*
1915 * According to the SCSI spec, if the disk doesn't support
1916 * the requested format, it will generally return a sense
1917 * key of RECOVERED ERROR, and an additional sense code
1918 * of "DEFECT LIST NOT FOUND". So, we check for that, and
1919 * also check to make sure that the returned length is
1920 * greater than 0, and then print out whatever format the

--- 1874 unchanged lines hidden (view full) ---

3795
3796 if ((status != CAM_REQ_CMP)
3797 && (status == CAM_SCSI_STATUS_ERROR)
3798 && ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
3799 struct scsi_sense_data *sense;
3800 int error_code, sense_key, asc, ascq;
3801
3802 sense = &ccb->csio.sense_data;
3801 scsi_extract_sense(sense, &error_code, &sense_key,
3802 &asc, &ascq);
3803 scsi_extract_sense_len(sense, ccb->csio.sense_len -
3804 ccb->csio.sense_resid, &error_code, &sense_key,
3805 &asc, &ascq, /*show_errors*/ 1);
3803
3804 /*
3805 * According to the SCSI-2 and SCSI-3 specs, a
3806 * drive that is in the middle of a format should
3807 * return NOT READY with an ASC of "logical unit
3808 * not ready, format in progress". The sense key
3809 * specific bytes will then be a progress indicator.
3810 */
3811 if ((sense_key == SSD_KEY_NOT_READY)
3812 && (asc == 0x04) && (ascq == 0x04)) {
3806
3807 /*
3808 * According to the SCSI-2 and SCSI-3 specs, a
3809 * drive that is in the middle of a format should
3810 * return NOT READY with an ASC of "logical unit
3811 * not ready, format in progress". The sense key
3812 * specific bytes will then be a progress indicator.
3813 */
3814 if ((sense_key == SSD_KEY_NOT_READY)
3815 && (asc == 0x04) && (ascq == 0x04)) {
3813 if ((sense->extra_len >= 10)
3814 && ((sense->sense_key_spec[0] &
3815 SSD_SCS_VALID) != 0)
3816 uint8_t sks[3];
3817
3818 if ((scsi_get_sks(sense, ccb->csio.sense_len -
3819 ccb->csio.sense_resid, sks) == 0)
3816 && (quiet == 0)) {
3817 int val;
3818 u_int64_t percentage;
3819
3820 && (quiet == 0)) {
3821 int val;
3822 u_int64_t percentage;
3823
3820 val = scsi_2btoul(
3821 &sense->sense_key_spec[1]);
3824 val = scsi_2btoul(&sks[1]);
3822 percentage = 10000 * val;
3823
3824 fprintf(stdout,
3825 "\rFormatting: %ju.%02u %% "
3826 "(%d/%d) done",
3827 (uintmax_t)(percentage /
3828 (0x10000 * 100)),
3829 (unsigned)((percentage /

--- 2320 unchanged lines hidden ---
3825 percentage = 10000 * val;
3826
3827 fprintf(stdout,
3828 "\rFormatting: %ju.%02u %% "
3829 "(%d/%d) done",
3830 (uintmax_t)(percentage /
3831 (0x10000 * 100)),
3832 (unsigned)((percentage /

--- 2320 unchanged lines hidden ---