~ubuntu-branches/ubuntu/vivid/sg3-utils/vivid-proposed

« back to all changes in this revision

Viewing changes to src/sg_logs.c

  • Committer: Package Import Robot
  • Author(s): Ritesh Raj Sarraf
  • Date: 2013-06-23 16:08:01 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20130623160801-7rt7zb2dwk0ba7ut
Tags: 1.36-1
* [69e9dac] Imported Upstream version 1.36
* [cb75936] Add debian compat, level 7
* [68fed25] update README.source
* [3c724fc] Add build-dep autotools-dev
* [e4b9fdd] add destdir to install path
* [7cfff11] Simplify build with debhelper
* [f9a7540] Update symbols for 1.36 release
* [7b0b48d] Enable hardening build

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* A utility program originally written for the Linux OS SCSI subsystem.
 
2
*  Copyright (C) 2000-2013 D. Gilbert
 
3
*  This program is free software; you can redistribute it and/or modify
 
4
*  it under the terms of the GNU General Public License as published by
 
5
*  the Free Software Foundation; either version 2, or (at your option)
 
6
*  any later version.
 
7
 
 
8
   This program outputs information provided by a SCSI LOG SENSE command.
 
9
 
 
10
*/
 
11
 
1
12
#include <unistd.h>
2
13
#include <fcntl.h>
3
14
#include <stdio.h>
14
25
#include "sg_lib.h"
15
26
#include "sg_cmds_basic.h"
16
27
 
17
 
/* A utility program originally written for the Linux OS SCSI subsystem.
18
 
*  Copyright (C) 2000-2011 D. Gilbert
19
 
*  This program is free software; you can redistribute it and/or modify
20
 
*  it under the terms of the GNU General Public License as published by
21
 
*  the Free Software Foundation; either version 2, or (at your option)
22
 
*  any later version.
23
 
 
24
 
   This program outputs information provided by a SCSI LOG SENSE command.
25
 
 
26
 
*/
27
 
 
28
 
static char * version_str = "1.05 20111020";    /* spc4r30 + sbc3r28 */
 
28
static const char * version_str = "1.11 20130517";    /* spc4r35 + sbc3r30 */
29
29
 
30
30
#define MX_ALLOC_LEN (0xfffc)
31
31
#define SHORT_RESP_LEN 128
46
46
#define APP_CLIENT_LPAGE 0xf
47
47
#define SELF_TEST_LPAGE 0x10
48
48
#define SOLID_STATE_MEDIA_LPAGE 0x11
 
49
#define SAT_ATA_RESULTS_LPAGE 0x16
49
50
#define PROTO_SPECIFIC_LPAGE 0x18
50
51
#define STATS_LPAGE 0x19
51
52
#define PCT_LPAGE 0x1a
576
577
   command, SG_LIB_CAT_NOT_READY, SG_LIB_CAT_UNIT_ATTENTION,
577
578
   SG_LIB_CAT_ABORTED_COMMAND and -1 for other errors. */
578
579
static int
579
 
do_logs(int sg_fd, unsigned char * resp, int mx_resp_len, int noisy,
 
580
do_logs(int sg_fd, unsigned char * resp, int mx_resp_len,
580
581
        const struct opts_t * optsp)
581
582
{
582
583
    int actual_len, res, vb;
590
591
                                   optsp->page_control, optsp->pg_code,
591
592
                                   optsp->subpg_code, optsp->paramp,
592
593
                                   resp, LOG_SENSE_PROBE_ALLOC_LEN,
593
 
                                   noisy, vb))) {
 
594
                                   1 /* noisy */, vb))) {
594
595
            switch (res) {
595
596
            case SG_LIB_CAT_NOT_READY:
596
597
            case SG_LIB_CAT_INVALID_OP:
629
630
    if ((res = sg_ll_log_sense(sg_fd, optsp->do_ppc, optsp->do_sp,
630
631
                               optsp->page_control, optsp->pg_code,
631
632
                               optsp->subpg_code, optsp->paramp,
632
 
                               resp, actual_len, noisy, vb))) {
 
633
                               resp, actual_len, 1 /* noisy */, vb))) {
633
634
        switch (res) {
634
635
        case SG_LIB_CAT_NOT_READY:
635
636
        case SG_LIB_CAT_INVALID_OP:
683
684
        case START_STOP_LPAGE: printf("%sStart-stop cycle counter", b); break;
684
685
        case APP_CLIENT_LPAGE: printf("%sApplication client", b); break;
685
686
        case SELF_TEST_LPAGE: printf("%sSelf-test results", b); break;
686
 
        case PROTO_SPECIFIC_LPAGE: printf("%sProtocol specific port", b); break;
 
687
        case PROTO_SPECIFIC_LPAGE:
 
688
            printf("%sProtocol specific port", b);
 
689
            break;
687
690
        case STATS_LPAGE:
688
691
            printf("%sGeneral statistics and performance", b);
689
692
            break;
740
743
            case SOLID_STATE_MEDIA_LPAGE:       /* 0x11 */
741
744
                printf("%sSolid state media (sbc-3)\n", b);
742
745
                break;
743
 
            case 0x16:
 
746
            case SAT_ATA_RESULTS_LPAGE:
744
747
                printf("%sATA pass-through results (sat-2)\n", b);
745
748
                break;
746
749
            case 0x17:
788
791
                printf("%sVolume statistics (ssc-4)\n", b);
789
792
                done = 0;
790
793
                break;
 
794
            case 0x1b:
 
795
                printf("%sData compression (ssc-4)\n", b);
 
796
                break;
791
797
            case 0x2d:
792
798
                printf("%sCurrent service information (ssc-3)\n", b);
793
799
                break;
898
904
        outp[0] = '\0';
899
905
}
900
906
 
901
 
/* BUFF_OVER_UNDER_LPAGE */
 
907
/* BUFF_OVER_UNDER_LPAGE [0x1] */
902
908
static void
903
909
show_buffer_under_overrun_page(unsigned char * resp, int len, int show_pcb)
904
910
{
965
971
}
966
972
 
967
973
/* WRITE_ERR_LPAGE; READ_ERR_LPAGE; READ_REV_ERR_LPAGE; VERIFY_ERR_LPAGE */
 
974
/* [0x2, 0x3, 0x4, 0x5] */
968
975
static void
969
976
show_error_counter_page(unsigned char * resp, int len, int show_pcb)
970
977
{
1032
1039
    }
1033
1040
}
1034
1041
 
1035
 
/* NON_MEDIUM_LPAGE */
 
1042
/* NON_MEDIUM_LPAGE [0x6] */
1036
1043
static void
1037
1044
show_non_medium_error_page(unsigned char * resp, int len, int show_pcb)
1038
1045
{
1082
1089
    }
1083
1090
}
1084
1091
 
1085
 
/* PCT_LPAGE */
 
1092
/* PCT_LPAGE [0x1a] */
1086
1093
static void
1087
1094
show_power_condition_transitions_page(unsigned char * resp, int len,
1088
1095
                                      int show_pcb)
1139
1146
    }
1140
1147
}
1141
1148
 
 
1149
/* Vendor specific: 0x30 */
1142
1150
static void
1143
1151
show_tape_usage_log_page(unsigned char * resp, int len, int show_pcb)
1144
1152
{
1231
1239
    }
1232
1240
}
1233
1241
 
 
1242
/* Vendor specific: 0x31 */
1234
1243
static void
1235
1244
show_tape_capacity_log_page(unsigned char * resp, int len, int show_pcb)
1236
1245
{
1279
1288
    }
1280
1289
}
1281
1290
 
 
1291
/* originally vendor specific 0x32, ssc4 standardizes at 0x1b */
1282
1292
static void
1283
1293
show_data_compression_log_page(unsigned char * resp, int len, int show_pcb)
1284
1294
{
1285
 
    int k, num, extra, pc, pcb;
1286
 
    unsigned int n;
 
1295
    int k, j, pl, num, extra, pc, pcb;
 
1296
    uint64_t n;
1287
1297
    unsigned char * ucp;
1288
1298
    char pcb_str[PCB_STR_LEN];
1289
1299
 
1297
1307
    for (k = num; k > 0; k -= extra, ucp += extra) {
1298
1308
        pc = (ucp[0] << 8) + ucp[1];
1299
1309
        pcb = ucp[2];
1300
 
        extra = ucp[3] + 4;
1301
 
        switch (ucp[3]) {
1302
 
        case 2:
1303
 
            n = (ucp[4] << 8) | ucp[5];
1304
 
            break;
1305
 
        case 4:
1306
 
            n = (ucp[4] << 24) | (ucp[5] << 16) | (ucp[6] << 8) | ucp[7];
1307
 
            break;
1308
 
        default:
1309
 
            n = 0;
 
1310
        pl = ucp[3];
 
1311
        extra = pl + 4;
 
1312
        if ((0 == pl) || (pl > 8)) {
 
1313
            printf("badly formed data compression log parameter\n");
 
1314
            printf("  parameter code = 0x%x, contents in hex:\n", pc);
 
1315
            dStrHex((const char *)ucp, extra, 1);
 
1316
            goto skip_para;
 
1317
        }
 
1318
        for (j = 0, n = 0; j < pl; ++j) {
 
1319
            if (j > 0)
 
1320
                n <<= 8;
 
1321
            n |= ucp[4 + j];
1310
1322
        }
1311
1323
        switch (pc) {
1312
1324
        case 0x00:
1313
 
            if (extra == 6)
1314
 
                printf("  Read compression ratio x100: %u", n);
 
1325
            printf("  Read compression ratio x100: %" PRIu64 , n);
1315
1326
            break;
1316
1327
        case 0x01:
1317
 
            if (extra == 6)
1318
 
                printf("  Write compression ratio x100: %u", n);
 
1328
            printf("  Write compression ratio x100: %" PRIu64 , n);
1319
1329
            break;
1320
1330
        case 0x02:
1321
 
            if (extra == 8)
1322
 
                printf("  Megabytes transferred to server: %u", n);
 
1331
            printf("  Megabytes transferred to server: %" PRIu64 , n);
1323
1332
            break;
1324
1333
        case 0x03:
1325
 
            if (extra == 8)
1326
 
                printf("  Bytes transferred to server: %u", n);
 
1334
            printf("  Bytes transferred to server: %" PRIu64 , n);
1327
1335
            break;
1328
1336
        case 0x04:
1329
 
            if (extra == 8)
1330
 
                printf("  Megabytes read from tape: %u", n);
 
1337
            printf("  Megabytes read from tape: %" PRIu64 , n);
1331
1338
            break;
1332
1339
        case 0x05:
1333
 
            if (extra == 8)
1334
 
                printf("  Bytes read from tape: %u", n);
 
1340
            printf("  Bytes read from tape: %" PRIu64 , n);
1335
1341
            break;
1336
1342
        case 0x06:
1337
 
            if (extra == 8)
1338
 
                printf("  Megabytes transferred from server: %u", n);
 
1343
            printf("  Megabytes transferred from server: %" PRIu64 , n);
1339
1344
            break;
1340
1345
        case 0x07:
1341
 
            if (extra == 8)
1342
 
                printf("  Bytes transferred from server: %u", n);
 
1346
            printf("  Bytes transferred from server: %" PRIu64 , n);
1343
1347
            break;
1344
1348
        case 0x08:
1345
 
            if (extra == 8)
1346
 
                printf("  Megabytes written to tape: %u", n);
 
1349
            printf("  Megabytes written to tape: %" PRIu64 , n);
1347
1350
            break;
1348
1351
        case 0x09:
1349
 
            if (extra == 8)
1350
 
                printf("  Bytes written to tape: %u", n);
 
1352
            printf("  Bytes written to tape: %" PRIu64 , n);
 
1353
            break;
 
1354
        case 0x100:
 
1355
            printf("  Data compression enabled: 0x%" PRIx64, n);
1351
1356
            break;
1352
1357
        default:
1353
1358
            printf("  unknown parameter code = 0x%x, contents in hex:\n", pc);
1354
1359
            dStrHex((const char *)ucp, extra, 1);
1355
1360
            break;
1356
1361
        }
 
1362
skip_para:
1357
1363
        if (show_pcb) {
1358
1364
            get_pcb_str(pcb, pcb_str, sizeof(pcb_str));
1359
1365
            printf("\n        <%s>\n", pcb_str);
1362
1368
    }
1363
1369
}
1364
1370
 
1365
 
/* LAST_N_ERR_LPAGE */
 
1371
/* LAST_N_ERR_LPAGE [0x7] */
1366
1372
static void
1367
1373
show_last_n_error_page(unsigned char * resp, int len, int show_pcb)
1368
1374
{
1404
1410
    }
1405
1411
}
1406
1412
 
1407
 
/* LAST_N_DEFERRED_LPAGE */
 
1413
/* LAST_N_DEFERRED_LPAGE [0xb] */
1408
1414
static void
1409
1415
show_last_n_deferred_error_page(unsigned char * resp, int len, int show_pcb)
1410
1416
{
1454
1460
    "reserved",
1455
1461
    "self test in progress"};
1456
1462
 
1457
 
/* SELF_TEST_LPAGE */
 
1463
/* SELF_TEST_LPAGE [0x10] */
1458
1464
static void
1459
1465
show_self_test_page(unsigned char * resp, int len, int show_pcb)
1460
1466
{
1501
1507
    }
1502
1508
}
1503
1509
 
1504
 
/* TEMPERATURE_LPAGE */
 
1510
/* TEMPERATURE_LPAGE [0xd] */
1505
1511
static void
1506
1512
show_temperature_page(unsigned char * resp, int len, int show_pcb, int hdr,
1507
1513
                      int show_unknown)
1554
1560
    }
1555
1561
}
1556
1562
 
1557
 
/* START_STOP_LPAGE */
 
1563
/* START_STOP_LPAGE [0xe] */
1558
1564
static void
1559
1565
show_start_stop_page(unsigned char * resp, int len, int show_pcb, int verbose)
1560
1566
{
1623
1629
            if (extra > 7) {
1624
1630
                n = (ucp[4] << 24) | (ucp[5] << 16) | (ucp[6] << 8) | ucp[7];
1625
1631
                if (0xffffffff == n)
1626
 
                    printf("  Specified load-unload count over device lifetime "
1627
 
                           "= -1");
 
1632
                    printf("  Specified load-unload count over device "
 
1633
                           "lifetime = -1");
1628
1634
                else
1629
 
                    printf("  Specified load-unload count over device lifetime "
1630
 
                           "= %u", n);
 
1635
                    printf("  Specified load-unload count over device "
 
1636
                           "lifetime = %u", n);
1631
1637
            }
1632
1638
            break;
1633
1639
        case 6:
1652
1658
    }
1653
1659
}
1654
1660
 
1655
 
/* IE_LPAGE */
 
1661
/* IE_LPAGE [0x2f] */
1656
1662
static void
1657
1663
show_ie_page(unsigned char * resp, int len, int show_pcb, int full)
1658
1664
{
1847
1853
    }
1848
1854
}
1849
1855
 
1850
 
/* PROTO_SPECIFIC_LPAGE for a SAS port */
 
1856
/* PROTO_SPECIFIC_LPAGE [0x18] for a SAS port */
1851
1857
static void
1852
1858
show_sas_port_param(unsigned char * ucp, int param_len,
1853
1859
                    const struct opts_t * optsp)
1966
1972
            printf("    reason: %s\n", s);
1967
1973
            t = (0xf & vcp[5]);
1968
1974
            switch (t) {
1969
 
            case 0: snprintf(s, sz, "phy enabled; unknown");
1970
 
                         break;
1971
 
            case 1: snprintf(s, sz, "phy disabled"); break;
1972
 
            case 2: snprintf(s, sz, "phy enabled; speed negotiation failed");
1973
 
                         break;
1974
 
            case 3: snprintf(s, sz, "phy enabled; SATA spinup hold state");
1975
 
                         break;
1976
 
            case 4: snprintf(s, sz, "phy enabled; port selector");
1977
 
                         break;
1978
 
            case 5: snprintf(s, sz, "phy enabled; reset in progress");
1979
 
                         break;
1980
 
            case 6: snprintf(s, sz, "phy enabled; unsupported phy attached");
1981
 
                         break;
1982
 
            case 8: snprintf(s, sz, "phy enabled; 1.5 Gbps"); break;
1983
 
            case 9: snprintf(s, sz, "phy enabled; 3 Gbps"); break;
1984
 
            case 0xa: snprintf(s, sz, "phy enabled; 6 Gbps"); break;
1985
 
            case 0xb: snprintf(s, sz, "phy enabled; 12 Gbps"); break;
1986
 
            default: snprintf(s, sz, "reserved [%d]", t); break;
 
1975
            case 0:
 
1976
                snprintf(s, sz, "phy enabled; unknown reason");
 
1977
                break;
 
1978
            case 1:
 
1979
                snprintf(s, sz, "phy disabled");
 
1980
                break;
 
1981
            case 2:
 
1982
                snprintf(s, sz, "phy enabled; speed negotiation failed");
 
1983
                break;
 
1984
            case 3:
 
1985
                snprintf(s, sz, "phy enabled; SATA spinup hold state");
 
1986
                break;
 
1987
            case 4:
 
1988
                snprintf(s, sz, "phy enabled; port selector");
 
1989
                break;
 
1990
            case 5:
 
1991
                snprintf(s, sz, "phy enabled; reset in progress");
 
1992
                break;
 
1993
            case 6:
 
1994
                snprintf(s, sz, "phy enabled; unsupported phy attached");
 
1995
                break;
 
1996
            case 8:
 
1997
                snprintf(s, sz, "1.5 Gbps");
 
1998
                break;
 
1999
            case 9:
 
2000
                snprintf(s, sz, "3 Gbps");
 
2001
                break;
 
2002
            case 0xa:
 
2003
                snprintf(s, sz, "6 Gbps");
 
2004
                break;
 
2005
            case 0xb:
 
2006
                snprintf(s, sz, "12 Gbps");
 
2007
                break;
 
2008
            default:
 
2009
                snprintf(s, sz, "reserved [%d]", t);
 
2010
                break;
1987
2011
            }
1988
2012
            printf("    negotiated logical link rate: %s\n", s);
1989
2013
            printf("    attached initiator port: ssp=%d stp=%d smp=%d\n",
2039
2063
    }
2040
2064
}
2041
2065
 
2042
 
/* PROTO_SPECIFIC_LPAGE */
 
2066
/* PROTO_SPECIFIC_LPAGE [0x18] */
2043
2067
static int
2044
2068
show_protocol_specific_page(unsigned char * resp, int len,
2045
2069
                            const struct opts_t * optsp)
2064
2088
}
2065
2089
 
2066
2090
/* Returns 1 if processed page, 0 otherwise */
2067
 
/* STATS_LPAGE, 0x0 to 0x1f */
 
2091
/* STATS_LPAGE [0x19], subpages: 0x0 to 0x1f */
2068
2092
static int
2069
2093
show_stats_perform_page(unsigned char * resp, int len,
2070
2094
                        const struct opts_t * optsp)
2391
2415
}
2392
2416
 
2393
2417
/* Returns 1 if processed page, 0 otherwise */
2394
 
/* STATS_LPAGE, CACHE_STATS_SUBPG */
 
2418
/* STATS_LPAGE [0x19], CACHE_STATS_SUBPG [0x20] */
2395
2419
static int
2396
2420
show_cache_stats_page(unsigned char * resp, int len,
2397
2421
                      const struct opts_t * optsp)
2524
2548
    return 1;
2525
2549
}
2526
2550
 
2527
 
/* FORMAT_STATUS_LPAGE */
 
2551
/* FORMAT_STATUS_LPAGE [0x8] */
2528
2552
static void
2529
2553
show_format_status_page(unsigned char * resp, int len, int show_pcb)
2530
2554
{
2594
2618
    }
2595
2619
}
2596
2620
 
 
2621
/* Non-volatile cache page [0x17] */
2597
2622
static void
2598
2623
show_non_volatile_cache_page(unsigned char * resp, int len, int show_pcb)
2599
2624
{
2671
2696
{
2672
2697
    int j, num, pl, pc, pcb;
2673
2698
    unsigned char * ucp;
2674
 
    char * cp;
 
2699
    const char * cp;
2675
2700
    char str[PCB_STR_LEN];
2676
2701
 
2677
2702
    printf("Logical block provisioning page (sbc-3) [0xc]\n");
2739
2764
    }
2740
2765
}
2741
2766
 
2742
 
/* SOLID_STATE_MEDIA_LPAGE */
 
2767
/* SOLID_STATE_MEDIA_LPAGE [0x11] */
2743
2768
static void
2744
2769
show_solid_state_media_page(unsigned char * resp, int len, int show_pcb)
2745
2770
{
2779
2804
    }
2780
2805
}
2781
2806
 
 
2807
/* SAT_ATA_RESULTS_LPAGE (SAT-2) [0x16] */
 
2808
static void
 
2809
show_ata_pt_results_page(unsigned char * resp, int len, int show_pcb)
 
2810
{
 
2811
    int num, pl, pc, pcb;
 
2812
    unsigned char * ucp;
 
2813
    unsigned char * dp;
 
2814
    char str[PCB_STR_LEN];
 
2815
 
 
2816
    printf("ATA pass-through results page (sat-2) [0x16]\n");
 
2817
    num = len - 4;
 
2818
    ucp = &resp[0] + 4;
 
2819
    while (num > 3) {
 
2820
        pc = (ucp[0] << 8) | ucp[1];
 
2821
        pcb = ucp[2];
 
2822
        pl = ucp[3] + 4;
 
2823
        if ((pc < 0xf) && (pl > 17)) {
 
2824
            int extend, sector_count;
 
2825
 
 
2826
            dp = ucp + 4;
 
2827
            printf("  Log_index=0x%x (parameter_code=0x%x)\n", pc + 1, pc);
 
2828
            extend = dp[2] & 1;
 
2829
            sector_count = dp[5] + (extend ? (dp[4] << 8) : 0);
 
2830
            printf("    extend=%d  error=0x%x sector_count=0x%x\n", extend,
 
2831
                   dp[3], sector_count);
 
2832
            if (extend)
 
2833
                printf("    lba=0x%02x%02x%02x%02x%02x%02x\n", dp[10], dp[8],
 
2834
                       dp[6], dp[11], dp[9], dp[7]);
 
2835
            else
 
2836
                printf("    lba=0x%02x%02x%02x\n", dp[11], dp[9], dp[7]);
 
2837
            printf("    device=0x%x  status=0x%x\n", dp[12], dp[13]);
 
2838
        } else {
 
2839
            printf("  Reserved [parameter_code=0x%x]:", pc);
 
2840
            dStrHex((const char *)ucp, ((pl < num) ? pl : num), 0);
 
2841
        }
 
2842
        if (show_pcb) {
 
2843
            get_pcb_str(pcb, str, sizeof(str));
 
2844
            printf("\n        <%s>\n", str);
 
2845
        }
 
2846
        num -= pl;
 
2847
        ucp += pl;
 
2848
    }
 
2849
}
 
2850
 
2782
2851
static const char * bms_status[] = {
2783
2852
    "no background scans active",
2784
2853
    "background medium scan is active",
2790
2859
    "background scan halted due to temperature out of range",
2791
2860
    "background scan enabled, none active (waiting for BMS interval timer "
2792
2861
        "to expire)", /* 8 */
 
2862
    "background scan halted - scan results list full",
 
2863
    "background scan halted - pre-scan time limit timer expired" /* 10 */,
2793
2864
};
2794
2865
 
2795
2866
static const char * reassign_status[] = {
2804
2875
    "Logical block unsuccessfully reassigned by application client", /* 8 */
2805
2876
};
2806
2877
 
 
2878
/* Background scan results [0x15] for disk */
2807
2879
static void
2808
2880
show_background_scan_results_page(unsigned char * resp, int len, int show_pcb,
2809
2881
                                  int verbose)
2914
2986
    }
2915
2987
}
2916
2988
 
 
2989
/* Sequential access device page [0xc] for tape */
2917
2990
static void
2918
2991
show_sequential_access_page(unsigned char * resp, int len, int show_pcb,
2919
2992
                            int verbose)
3020
3093
    }
3021
3094
}
3022
3095
 
 
3096
/* 0x14 for tape and ADC */
3023
3097
static void
3024
3098
show_device_stats_page(unsigned char * resp, int len, int show_pcb)
3025
3099
{
3124
3198
    }
3125
3199
}
3126
3200
 
 
3201
/* 0x14 for media changer */
3127
3202
static void
3128
3203
show_media_stats_page(unsigned char * resp, int len, int show_pcb)
3129
3204
{
3258
3333
    }
3259
3334
}
3260
3335
 
 
3336
/* 0x15 for media changer */
3261
3337
static void
3262
3338
show_element_stats_page(unsigned char * resp, int len, int show_pcb)
3263
3339
{
3295
3371
    }
3296
3372
}
3297
3373
 
 
3374
/* 0x16 for media changer */
3298
3375
static void
3299
3376
show_mchanger_diag_data_page(unsigned char * resp, int len, int show_pcb)
3300
3377
{
3366
3443
    }
3367
3444
}
3368
3445
 
3369
 
static char * tape_alert_strs[] = {
 
3446
static const char * tape_alert_strs[] = {
3370
3447
    "<parameter code 0, unknown>",              /* 0x0 */
3371
3448
    "Read warning",
3372
3449
    "Write warning",
3430
3507
    "WORM medium - overwrite attempted",
3431
3508
};
3432
3509
 
 
3510
/* TAPE_ALERT_LPAGE [0x2e] */
3433
3511
static void
3434
3512
show_tape_alert_ssc_page(unsigned char * resp, int len, int show_pcb,
3435
3513
                         const struct opts_t * optsp)
3466
3544
    }
3467
3545
}
3468
3546
 
 
3547
/* 0x37 */
3469
3548
static void
3470
3549
show_seagate_cache_page(unsigned char * resp, int len, int show_pcb)
3471
3550
{
3485
3564
        switch (pc) {
3486
3565
        case 0: printf("  Blocks sent to initiator"); break;
3487
3566
        case 1: printf("  Blocks received from initiator"); break;
3488
 
        case 2: printf("  Blocks read from cache and sent to initiator"); break;
3489
 
        case 3: printf("  Number of read and write commands whose size "
3490
 
                       "<= segment size"); break;
3491
 
        case 4: printf("  Number of read and write commands whose size "
3492
 
                       "> segment size"); break;
 
3567
        case 2:
 
3568
            printf("  Blocks read from cache and sent to initiator");
 
3569
            break;
 
3570
        case 3:
 
3571
            printf("  Number of read and write commands whose size "
 
3572
                   "<= segment size");
 
3573
            break;
 
3574
        case 4:
 
3575
            printf("  Number of read and write commands whose size "
 
3576
                   "> segment size"); break;
3493
3577
        default: printf("  Unknown Seagate parameter code = 0x%x", pc); break;
3494
3578
        }
3495
3579
        k = pl - 4;
3515
3599
    }
3516
3600
}
3517
3601
 
 
3602
/* 0x3e */
3518
3603
static void
3519
3604
show_seagate_factory_page(unsigned char * resp, int len, int show_pcb)
3520
3605
{
3699
3784
            }
3700
3785
        }
3701
3786
        break;
3702
 
    case 0x16:
 
3787
    case SAT_ATA_RESULTS_LPAGE:         /* 0x16 */
3703
3788
        {
3704
3789
            switch (inq_dat->peripheral_type) {
 
3790
            case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_RBC:
 
3791
                /* disk (direct access) type devices */
 
3792
                show_ata_pt_results_page(resp, len, optsp->do_pcb);
 
3793
                break;
3705
3794
            case PDT_MCHANGER: /* smc-3 */
3706
3795
                show_mchanger_diag_data_page(resp, len, optsp->do_pcb);
3707
3796
                break;
3710
3799
                break;
3711
3800
            }
3712
3801
        }
 
3802
        break;
3713
3803
    case 0x17:
3714
3804
        {
3715
3805
            switch (inq_dat->peripheral_type) {
3723
3813
            }
3724
3814
        }
3725
3815
        break;
3726
 
    case PROTO_SPECIFIC_LPAGE:
 
3816
    case PROTO_SPECIFIC_LPAGE:  /* 0x18 */
3727
3817
        done = show_protocol_specific_page(resp, len, optsp);
3728
3818
        break;
3729
 
    case STATS_LPAGE: /* defined for subpages 0 to 32 inclusive */
 
3819
    case STATS_LPAGE: /* 0x19, defined for subpages 0 to 32 inclusive */
3730
3820
        if (subpg_code <= HIGH_GRP_STATS_SUBPG)
3731
3821
            done = show_stats_perform_page(resp, len, optsp);
3732
3822
        else if (subpg_code == CACHE_STATS_SUBPG)
3734
3824
        else
3735
3825
            done = 0;
3736
3826
        break;
3737
 
    case PCT_LPAGE:
 
3827
    case PCT_LPAGE:     /* 0x1a */
3738
3828
        show_power_condition_transitions_page(resp, len, optsp->do_pcb);
3739
3829
        break;
3740
 
    case TAPE_ALERT_LPAGE:
 
3830
    case 0x1b:
 
3831
        show_data_compression_log_page(resp, len, optsp->do_pcb);
 
3832
        break;
 
3833
    case TAPE_ALERT_LPAGE:      /* 0x2e */
3741
3834
        {
3742
3835
            switch (inq_dat->peripheral_type) {
3743
3836
            case PDT_TAPE:     /* ssc only */
3749
3842
            }
3750
3843
        }
3751
3844
        break;
3752
 
    case 0x30:
 
3845
    case 0x30:  /* vendor specific: IBM */
3753
3846
        show_tape_usage_log_page(resp, len, optsp->do_pcb);
3754
3847
        break;
3755
 
    case 0x31:
 
3848
    case 0x31:  /* vendor specific: IBM */
3756
3849
        show_tape_capacity_log_page(resp, len, optsp->do_pcb);
3757
3850
        break;
3758
 
    case 0x32:
 
3851
    case 0x32:  /* vendor specific, now tweaked and standardized at 0x1b */
3759
3852
        show_data_compression_log_page(resp, len, optsp->do_pcb);
3760
3853
        break;
3761
3854
    case IE_LPAGE:
3813
3906
 
3814
3907
    optsp->pg_code = TEMPERATURE_LPAGE;
3815
3908
    optsp->subpg_code = NOT_SPG_SUBPG;
3816
 
    res = do_logs(sg_fd, resp, max_len, 0, optsp);
 
3909
    res = do_logs(sg_fd, resp, max_len, optsp);
3817
3910
    if (0 == res) {
3818
3911
        len = (resp[2] << 8) + resp[3] + 4;
3819
3912
        if (optsp->do_raw)
3826
3919
        fprintf(stderr, "Device not ready\n");
3827
3920
    else {
3828
3921
        optsp->pg_code = IE_LPAGE;
3829
 
        res = do_logs(sg_fd, resp, max_len, 0, optsp);
 
3922
        res = do_logs(sg_fd, resp, max_len, optsp);
3830
3923
        if (0 == res) {
3831
3924
            len = (resp[2] << 8) + resp[3] + 4;
3832
3925
            if (optsp->do_raw)
3942
4035
        return (k >= 0) ?  k : SG_LIB_CAT_OTHER;
3943
4036
    }
3944
4037
    resp_len = (opts.maxlen > 0) ? opts.maxlen : MX_ALLOC_LEN;
3945
 
    res = do_logs(sg_fd, rsp_buff, resp_len, 1, &opts);
 
4038
    res = do_logs(sg_fd, rsp_buff, resp_len, &opts);
3946
4039
    if (0 == res) {
3947
4040
        pg_len = (rsp_buff[2] << 8) + rsp_buff[3];
3948
4041
        if ((pg_len + 4) > resp_len) {
4004
4097
            else
4005
4098
                opts.subpg_code = NOT_SPG_SUBPG;
4006
4099
 
4007
 
            res = do_logs(sg_fd, rsp_buff, resp_len, 1, &opts);
 
4100
            res = do_logs(sg_fd, rsp_buff, resp_len, &opts);
4008
4101
            if (0 == res) {
4009
4102
                pg_len = (rsp_buff[2] << 8) + rsp_buff[3];
4010
4103
                if ((pg_len + 4) > resp_len) {