Ticket #1079: patch_scsiprint_v1.01.diff

File patch_scsiprint_v1.01.diff, 72.6 KB (added by Rick Chen, 6 years ago)
  • scsiprint.cpp

    diff --git a/scsiprint.cpp b/scsiprint.cpp
    index cca0dcc..5f55265 100644
    a b scsiGetSupportedLogPages(scsi_device * device)  
    126126    if ((err = scsiLogSense(device, SUPPORTED_LPAGES, 0, gBuf,
    127127                            LOG_RESP_LEN, 0))) {
    128128        if (scsi_debugmode > 0)
    129             pout("%s for supported pages failed [%s]\n", logSenStr,
     129            jout("%s for supported pages failed [%s]\n", logSenStr,
    130130                 scsiErrString(err));
    131131        /* try one more time with defined length, workaround for the bug #678
    132132        found with ST8000NM0075/E001 */
    133133        err = scsiLogSense(device, SUPPORTED_LPAGES, 0, gBuf,
    134134                            LOG_RESP_LEN, 68); /* 64 max pages + 4b header */
    135135        if (scsi_debugmode > 0)
    136             pout("%s for supported pages failed (second attempt) [%s]\n",
     136            jout("%s for supported pages failed (second attempt) [%s]\n",
    137137                 logSenStr, scsiErrString(err));
    138138        if (err)
    139139            return;
    scsiGetSupportedLogPages(scsi_device * device)  
    146146                                gBuf, LOG_RESP_LONG_LEN,
    147147                                -1 /* just single not double fetch */))) {
    148148            if (scsi_debugmode > 0)
    149                 pout("%s for supported pages and subpages failed [%s]\n",
     149                jout("%s for supported pages and subpages failed [%s]\n",
    150150                     logSenStr, scsiErrString(err));
    151151        } else {
    152152            if (0 == memcmp(gBuf, sup_lpgs, LOG_RESP_LEN)) {
    153153                if (scsi_debugmode > 0)
    154                     pout("%s: %s ignored subpage field, bad\n",
     154                    jout("%s: %s ignored subpage field, bad\n",
    155155                         __func__, logSenRspStr);
    156156            } else if (! ((0x40 & gBuf[0]) &&
    157157                          (SUPP_SPAGE_L_SPAGE == gBuf[1]))) {
    158158                if (scsi_debugmode > 0)
    159                     pout("%s supported subpages is bad SPF=%u SUBPG=%u\n",
     159                    jout("%s supported subpages is bad SPF=%u SUBPG=%u\n",
    160160                         logSenRspStr, !! (0x40 & gBuf[0]), gBuf[2]);
    161161            } else
    162162                got_subpages = true;
    scsiGetSupportedLogPages(scsi_device * device)  
    185185                if (! ((NO_SUBPAGE_L_SPAGE == sub_pg_num) ||
    186186                       (SUPP_SPAGE_L_SPAGE == sub_pg_num))) {
    187187                    if (scsi_debugmode > 1)
    188                         pout("%s: Strange Log page number: 0x0,0x%x\n",
     188                        jout("%s: Strange Log page number: 0x0,0x%x\n",
    189189                             __func__, sub_pg_num);
    190190                }
    191191                break;
    scsiGetSupportedLogPages(scsi_device * device)  
    284284        }
    285285    }
    286286    if (scsi_debugmode > 1)
    287         pout("%s: number of unreported (standard) log pages: %d (sub-pages: "
     287        jout("%s: number of unreported (standard) log pages: %d (sub-pages: "
    288288             "%d)\n", __func__, num_unreported, num_unreported_spg);
    289289}
    290290
    scsiGetSmartData(scsi_device * device, bool attribs)  
    325325
    326326    if (attribs && !gTempLPage) {
    327327        if (255 == currenttemp)
    328             pout("Current Drive Temperature:     <not available>\n");
     328            jout("Current Drive Temperature:     <not available>\n");
    329329        else {
    330330            jout("Current Drive Temperature:     %d C\n", currenttemp);
    331331            jglb["temperature"]["current"] = currenttemp;
    332332        }
    333333        if (255 == triptemp)
    334             pout("Drive Trip Temperature:        <not available>\n");
    335         else
    336             pout("Drive Trip Temperature:        %d C\n", triptemp);
     334            jout("Drive Trip Temperature:        <not available>\n");
     335        else {
     336            jout("Drive Trip Temperature:        %d C\n", triptemp);
     337            jglb["temperature"]["drive_trip"] = triptemp;
     338        }
    337339    }
    338     pout("\n");
     340    jout("\n");
    339341    return err;
    340342}
    341343
    scsiGetTapeAlertsData(scsi_device * device, int peripheral_type)  
    357359    print_on();
    358360    if ((err = scsiLogSense(device, TAPE_ALERTS_LPAGE, 0, gBuf,
    359361                        LOG_RESP_TAPE_ALERT_LEN, LOG_RESP_TAPE_ALERT_LEN))) {
    360         pout("%s Failed [%s]\n", __func__, scsiErrString(err));
     362        jout("%s Failed [%s]\n", __func__, scsiErrString(err));
    361363        print_off();
    362364        return -1;
    363365    }
    364366    if (gBuf[0] != 0x2e) {
    365         pout("TapeAlerts %s Failed\n", logSenStr);
     367        jout("TapeAlerts %s Failed\n", logSenStr);
    366368        print_off();
    367369        return -1;
    368370    }
    scsiGetTapeAlertsData(scsi_device * device, int peripheral_type)  
    378380                    scsiTapeAlertsTapeDevice(parametercode);
    379381                if (*ts == *s) {
    380382                    if (!failures)
    381                         pout("TapeAlert Errors (C=Critical, W=Warning, "
     383                        jout("TapeAlert Errors (C=Critical, W=Warning, "
    382384                             "I=Informational):\n");
    383                     pout("[0x%02x] %s\n", parametercode, ts);
     385                    jout("[0x%02x] %s\n", parametercode, ts);
    384386                    failures += 1;
    385387                }
    386388            }
    scsiGetTapeAlertsData(scsi_device * device, int peripheral_type)  
    389391    print_off();
    390392
    391393    if (! failures)
    392         pout("TapeAlert: OK\n");
     394        jout("TapeAlert: OK\n");
    393395
    394396    return failures;
    395397}
    scsiGetStartStopData(scsi_device * device)  
    403405    if ((err = scsiLogSense(device, STARTSTOP_CYCLE_COUNTER_LPAGE, 0, gBuf,
    404406                            LOG_RESP_LEN, 0))) {
    405407        print_on();
    406         pout("%s Failed [%s]\n", __func__, scsiErrString(err));
     408        jout("%s Failed [%s]\n", __func__, scsiErrString(err));
    407409        print_off();
    408410        return;
    409411    }
    410412    if ((gBuf[0] & 0x3f) != STARTSTOP_CYCLE_COUNTER_LPAGE) {
    411413        print_on();
    412         pout("StartStop %s Failed, page mismatch\n", logSenStr);
     414        jout("StartStop %s Failed, page mismatch\n", logSenStr);
    413415        print_off();
    414416        return;
    415417    }
    scsiGetStartStopData(scsi_device * device)  
    418420    for (k = len; k > 0; k -= extra, ucp += extra) {
    419421        if (k < 3) {
    420422            print_on();
    421             pout("StartStop %s: short\n", logSenRspStr);
     423            jout("StartStop %s: short\n", logSenRspStr);
    422424            print_off();
    423425            return;
    424426        }
    scsiGetStartStopData(scsi_device * device)  
    429431        switch (pc) {
    430432        case 1:
    431433            if (10 == extra)
    432                 pout("Manufactured in week %.2s of year %.4s\n", ucp + 8,
     434                jout("Manufactured in week %.2s of year %.4s\n", ucp + 8,
    433435                     ucp + 4);
    434436            break;
    435437        case 2:
    scsiGetStartStopData(scsi_device * device)  
    437439            break;
    438440        case 3:
    439441            if ((extra > 7) && (! is_all_ffs))
    440                 pout("Specified cycle count over device lifetime:  %u\n", u);
     442                jout("Specified cycle count over device lifetime:  %u\n", u);
    441443            break;
    442444        case 4:
    443445            if ((extra > 7) && (! is_all_ffs))
    444                 pout("Accumulated start-stop cycles:  %u\n", u);
     446                jout("Accumulated start-stop cycles:  %u\n", u);
    445447            break;
    446448        case 5:
    447449            if ((extra > 7) && (! is_all_ffs))
    448                 pout("Specified load-unload count over device lifetime:  "
     450                jout("Specified load-unload count over device lifetime:  "
    449451                     "%u\n", u);
    450452            break;
    451453        case 6:
    452454            if ((extra > 7) && (! is_all_ffs))
    453                 pout("Accumulated load-unload cycles:  %u\n", u);
     455                jout("Accumulated load-unload cycles:  %u\n", u);
    454456            break;
    455457        default:
    456458            /* ignore */
    scsiPrintPendingDefectsLPage(scsi_device * device)  
    472474                            PEND_DEFECTS_L_SPAGE, gBuf, LOG_RESP_LONG_LEN,
    473475                            0))) {
    474476        print_on();
    475         pout("%s Failed [%s]\n", __func__, scsiErrString(err));
     477        jout("%s Failed [%s]\n", __func__, scsiErrString(err));
    476478        print_off();
    477479        return;
    478480    }
    479481    if (((gBuf[0] & 0x3f) != BACKGROUND_RESULTS_LPAGE) &&
    480482        (gBuf[1] != PEND_DEFECTS_L_SPAGE)) {
    481483        print_on();
    482         pout("%s %s, page mismatch\n", pDefStr, logSenRspStr);
     484        jout("%s %s, page mismatch\n", pDefStr, logSenRspStr);
    483485        print_off();
    484486        return;
    485487    }
    486488    num = sg_get_unaligned_be16(gBuf + 2);
    487489    if (num > LOG_RESP_LONG_LEN) {
    488490        print_on();
    489         pout("%s %s too long\n", pDefStr, logSenRspStr);
     491        jout("%s %s too long\n", pDefStr, logSenRspStr);
    490492        print_off();
    491493        return;
    492494    }
    scsiPrintPendingDefectsLPage(scsi_device * device)  
    499501            printf("  Pending defect count:");
    500502            if ((pl < 8) || (num < 8)) {
    501503                print_on();
    502                 pout("%s truncated descriptor\n", pDefStr);
     504                jout("%s truncated descriptor\n", pDefStr);
    503505                print_off();
    504506                return;
    505507            }
    scsiPrintPendingDefectsLPage(scsi_device * device)  
    517519        default:
    518520            if ((pl < 16) || (num < 16)) {
    519521                print_on();
    520                 pout("%s truncated descriptor\n", pDefStr);
     522                jout("%s truncated descriptor\n", pDefStr);
    521523                print_off();
    522524                return;
    523525            }
    scsiPrintGrownDefectListLen(scsi_device * device)  
    552554            if (err) {
    553555                if (scsi_debugmode > 0) {
    554556                    print_on();
    555                     pout("%s (10) Failed: %s\n", hname, scsiErrString(err));
     557                    jout("%s (10) Failed: %s\n", hname, scsiErrString(err));
    556558                    print_off();
    557559                }
    558560                return;
    scsiPrintGrownDefectListLen(scsi_device * device)  
    563565        else {
    564566            if (scsi_debugmode > 0) {
    565567                print_on();
    566                 pout("%s (12) Failed: %s\n", hname, scsiErrString(err));
     568                jout("%s (12) Failed: %s\n", hname, scsiErrString(err));
    567569                print_off();
    568570            }
    569571            return;
    scsiPrintGrownDefectListLen(scsi_device * device)  
    575577        int generation = sg_get_unaligned_be16(gBuf + 2);
    576578        if ((generation > 1) && (scsi_debugmode > 0)) {
    577579            print_on();
    578             pout("%s (12): generation=%d\n", hname, generation);
     580            jout("%s (12): generation=%d\n", hname, generation);
    579581            print_off();
    580582        }
    581583        dl_len = sg_get_unaligned_be32(gBuf + 4);
    scsiPrintGrownDefectListLen(scsi_device * device)  
    583585        dl_len = sg_get_unaligned_be16(gBuf + 2);
    584586    if (0x8 != (gBuf[1] & 0x18)) {
    585587        print_on();
    586         pout("%s: asked for grown list but didn't get it\n", hname);
     588        jout("%s: asked for grown list but didn't get it\n", hname);
    587589        print_off();
    588590        return;
    589591    }
    scsiPrintGrownDefectListLen(scsi_device * device)  
    605607            break;
    606608        default:
    607609            print_on();
    608             pout("defect list format %d unknown\n", dl_format);
     610            jout("defect list format %d unknown\n", dl_format);
    609611            print_off();
    610612            break;
    611613    }
    612     if (0 == dl_len)
    613         pout("Elements in grown defect list: 0\n\n");
     614    if (0 == dl_len) {
     615        jout("Elements in grown defect list: 0\n\n");
     616        jglb["scsi_elements_grown_list"] = 0;
     617    }
    614618    else {
    615619        if (0 == div)
    616             pout("Grown defect list length=%u bytes [unknown "
     620            jout("Grown defect list length=%u bytes [unknown "
    617621                 "number of elements]\n\n", dl_len);
    618         else
    619             pout("Elements in grown defect list: %u\n\n", dl_len / div);
     622        else {
     623            jout("Elements in grown defect list: %u\n\n", dl_len / div);
     624            jglb["scsi_elements_grown_list"] = dl_len;
     625        }
    620626    }
    621627}
    622628
    scsiPrintSeagateCacheLPage(scsi_device * device)  
    632638                            LOG_RESP_LEN, 0))) {
    633639        if (scsi_debugmode > 0) {
    634640            print_on();
    635             pout("%s %s Failed: %s\n", seaCacStr, logSenStr,
     641            jout("%s %s Failed: %s\n", seaCacStr, logSenStr,
    636642                 scsiErrString(err));
    637643            print_off();
    638644        }
    scsiPrintSeagateCacheLPage(scsi_device * device)  
    641647    if ((gBuf[0] & 0x3f) != SEAGATE_CACHE_LPAGE) {
    642648        if (scsi_debugmode > 0) {
    643649            print_on();
    644             pout("%s %s, page mismatch\n", seaCacStr, logSenRspStr);
     650            jout("%s %s, page mismatch\n", seaCacStr, logSenRspStr);
    645651            print_off();
    646652        }
    647653        return;
    scsiPrintSeagateCacheLPage(scsi_device * device)  
    658664        default:
    659665            if (scsi_debugmode > 0) {
    660666                print_on();
    661                 pout("Vendor (%s) lpage has unexpected parameter, skip\n",
     667                jout("Vendor (%s) lpage has unexpected parameter, skip\n",
    662668                     seaCacStr);
    663669                print_off();
    664670            }
    scsiPrintSeagateCacheLPage(scsi_device * device)  
    667673        num -= pl;
    668674        ucp += pl;
    669675    }
    670     pout("Vendor (%s) information\n", seaCacStr);
     676    jout("Vendor (%s) information\n", seaCacStr);
    671677    num = len - 4;
    672678    ucp = &gBuf[0] + 4;
    673679    while (num > 3) {
    674680        pc = sg_get_unaligned_be16(ucp + 0);
    675681        pl = ucp[3] + 4;
    676682        switch (pc) {
    677         case 0: pout("  Blocks sent to initiator"); break;
    678         case 1: pout("  Blocks received from initiator"); break;
    679         case 2: pout("  Blocks read from cache and sent to initiator"); break;
    680         case 3: pout("  Number of read and write commands whose size "
     683        case 0: jout("  Blocks sent to initiator"); break;
     684        case 1: jout("  Blocks received from initiator"); break;
     685        case 2: jout("  Blocks read from cache and sent to initiator"); break;
     686        case 3: jout("  Number of read and write commands whose size "
    681687                       "<= segment size"); break;
    682         case 4: pout("  Number of read and write commands whose size "
     688        case 4: jout("  Number of read and write commands whose size "
    683689                       "> segment size"); break;
    684         default: pout("  Unknown Seagate parameter code [0x%x]", pc); break;
     690        default: jout("  Unknown Seagate parameter code [0x%x]", pc); break;
    685691        }
    686692        int k = pl - 4;
    687693        const int sz_ull = (int)sizeof(ull);
    scsiPrintSeagateCacheLPage(scsi_device * device)  
    691697            k = sz_ull;
    692698        }
    693699        ull = sg_get_unaligned_be(k, xp + 0);
    694         pout(" = %" PRIu64 "\n", ull);
     700        jout(" = %" PRIu64 "\n", ull);
    695701        num -= pl;
    696702        ucp += pl;
    697703    }
    698     pout("\n");
     704    jout("\n");
    699705}
    700706
    701707static void
    scsiPrintSeagateFactoryLPage(scsi_device * device)  
    704710    int num, pl, pc, len, err, good, bad;
    705711    unsigned char * ucp;
    706712    uint64_t ull;
     713    static const char * jname = "format_status";
    707714
    708715    if ((err = scsiLogSense(device, SEAGATE_FACTORY_LPAGE, 0, gBuf,
    709716                            LOG_RESP_LEN, 0))) {
    710717        if (scsi_debugmode > 0) {
    711718            print_on();
    712             pout("%s Failed [%s]\n", __func__, scsiErrString(err));
     719            jout("%s Failed [%s]\n", __func__, scsiErrString(err));
    713720            print_off();
    714721        }
    715722        return;
    scsiPrintSeagateFactoryLPage(scsi_device * device)  
    717724    if ((gBuf[0] & 0x3f) != SEAGATE_FACTORY_LPAGE) {
    718725        if (scsi_debugmode > 0) {
    719726            print_on();
    720             pout("Seagate/Hitachi Factory %s, page mismatch\n", logSenRspStr);
     727            jout("Seagate/Hitachi Factory %s, page mismatch\n", logSenRspStr);
    721728            print_off();
    722729        }
    723730        return;
    scsiPrintSeagateFactoryLPage(scsi_device * device)  
    744751    if ((good < 2) || (bad > 4)) {  /* heuristic */
    745752        if (scsi_debugmode > 0) {
    746753            print_on();
    747             pout("\nVendor (Seagate/Hitachi) factory lpage has too many "
     754            jout("\nVendor (Seagate/Hitachi) factory lpage has too many "
    748755                 "unexpected parameters, skip\n");
    749756            print_off();
    750757        }
    751758        return;
    752759    }
    753     pout("Vendor (Seagate/Hitachi) factory information\n");
     760    jout("Vendor (Seagate/Hitachi) factory information\n");
    754761    num = len - 4;
    755762    ucp = &gBuf[0] + 4;
    756763    while (num > 3) {
    scsiPrintSeagateFactoryLPage(scsi_device * device)  
    758765        pl = ucp[3] + 4;
    759766        good = 0;
    760767        switch (pc) {
    761         case 0: pout("  number of hours powered up");
     768        case 0: jout("  number of hours powered up");
     769            jname = "scsi_hours_powered_up";
    762770            good = 1;
    763771            break;
    764         case 8: pout("  number of minutes until next internal SMART test");
     772        case 8: jout("  number of minutes until next internal SMART test");
     773            jname = "scsi_minutes_next_smart_test";
    765774            good = 1;
    766775            break;
    767776        default:
    768777            if (scsi_debugmode > 0) {
    769778                print_on();
    770                 pout("Vendor (Seagate/Hitachi) factory lpage: "
     779                jout("Vendor (Seagate/Hitachi) factory lpage: "
    771780                     "unknown parameter code [0x%x]\n", pc);
    772781                print_off();
    773782            }
    scsiPrintSeagateFactoryLPage(scsi_device * device)  
    781790                k = (int)sizeof(ull);
    782791            }
    783792            ull = sg_get_unaligned_be(k, xp + 0);
    784             if (0 == pc)
    785                 pout(" = %.2f\n", ull / 60.0 );
    786             else
    787                 pout(" = %" PRIu64 "\n", ull);
     793            if (0 == pc) {
     794                jout(" = %.2f\n", ull / 60.0 );
     795                jglb[jname] = strprintf("%.2f", ull / 60.0);
     796            }
     797            else {
     798                jout(" = %" PRIu64 "\n", ull);
     799                jglb[jname] = ull;
     800            }
    788801        }
    789802        num -= pl;
    790803        ucp += pl;
    791804    }
    792     pout("\n");
     805    jout("\n");
    793806}
    794807
    795808static void
    scsiPrintErrorCounterLog(scsi_device * device)  
    821834        }
    822835    }
    823836    if (found[0] || found[1] || found[2]) {
    824         pout("Error counter log:\n");
    825         pout("           Errors Corrected by           Total   "
     837        jout("Error counter log:\n");
     838        jout("           Errors Corrected by           Total   "
    826839             "Correction     Gigabytes    Total\n");
    827         pout("               ECC          rereads/    errors   "
     840        jout("               ECC          rereads/    errors   "
    828841             "algorithm      processed    uncorrected\n");
    829         pout("           fast | delayed   rewrites  corrected  "
     842        jout("           fast | delayed   rewrites  corrected  "
    830843             "invocations   [10^9 bytes]  errors\n");
     844
     845        json::ref jref = jglb["scsi_error_counter_log"];
    831846        for (int k = 0; k < 3; ++k) {
    832847            if (! found[k])
    833848                continue;
    834849            ecp = &errCounterArr[k];
    835850            static const char * const pageNames[3] =
    836851                                 {"read:   ", "write:  ", "verify: "};
    837             pout("%s%8" PRIu64 " %8" PRIu64 "  %8" PRIu64 "  %8" PRIu64
     852            static const char * jpageNames[3] =
     853                                 {"read", "write", "verify"};
     854            jout("%s%8" PRIu64 " %8" PRIu64 "  %8" PRIu64 "  %8" PRIu64
    838855                 "   %8" PRIu64, pageNames[k], ecp->counter[0],
    839856                 ecp->counter[1], ecp->counter[2], ecp->counter[3],
    840857                 ecp->counter[4]);
    841858            double processed_gb = ecp->counter[5] / 1000000000.0;
    842             pout("   %12.3f    %8" PRIu64 "\n", processed_gb,
     859            jout("   %12.3f    %8" PRIu64 "\n", processed_gb,
    843860                 ecp->counter[6]);
     861            // Error counter log info
     862            jref[jpageNames[k]]["errors_corrected_by_eccfast"] = ecp->counter[0];
     863            jref[jpageNames[k]]["errors_corrected_by_eccdelayed"] = ecp->counter[1];
     864            jref[jpageNames[k]]["errors_corrected_by_rereads_rewrites"] = ecp->counter[2];
     865            jref[jpageNames[k]]["total_errors_corrected"] = ecp->counter[3];
     866            jref[jpageNames[k]]["correction_algorithm_invocations"] = ecp->counter[4];
     867            jref[jpageNames[k]]["gigabytes_processed"] = strprintf("%.3f", processed_gb);
     868            jref[jpageNames[k]]["total_uncorrected_errors"] = ecp->counter[6];
    844869        }
    845870    }
    846871    else
    847         pout("Error Counter logging not supported\n");
     872        jout("Error Counter logging not supported\n");
    848873    if (gNonMediumELPage && (0 == scsiLogSense(device,
    849874                NON_MEDIUM_ERROR_LPAGE, 0, gBuf, LOG_RESP_LEN, 0))) {
    850875        struct scsiNonMediumError nme;
    851876        scsiDecodeNonMediumErrPage(gBuf, &nme);
    852877        if (nme.gotPC0)
    853             pout("\nNon-medium error count: %8" PRIu64 "\n", nme.counterPC0);
     878            jout("\nNon-medium error count: %8" PRIu64 "\n", nme.counterPC0);
    854879        if (nme.gotTFE_H)
    855             pout("Track following error count [Hitachi]: %8" PRIu64 "\n",
     880            jout("Track following error count [Hitachi]: %8" PRIu64 "\n",
    856881                 nme.counterTFE_H);
    857882        if (nme.gotPE_H)
    858             pout("Positioning error count [Hitachi]: %8" PRIu64 "\n",
     883            jout("Positioning error count [Hitachi]: %8" PRIu64 "\n",
    859884                 nme.counterPE_H);
    860885    }
    861886    if (gLastNErrorEvLPage &&
    scsiPrintErrorCounterLog(scsi_device * device)  
    868893        unsigned char * ucp = gBuf + 4;
    869894        num -= 4;
    870895        if (num < 4)
    871             pout("\nNo error events logged\n");
     896            jout("\nNo error events logged\n");
    872897        else {
    873             pout("\nLast n error events log page\n");
     898            jout("\nLast n error events log page\n");
    874899            for (int k = num, pl; k > 0; k -= pl, ucp += pl) {
    875900                if (k < 3) {
    876                     pout("  <<short Last n error events log page>>\n");
     901                    jout("  <<short Last n error events log page>>\n");
    877902                    break;
    878903                }
    879904                pl = ucp[3] + 4;
    880905                int pc = sg_get_unaligned_be16(ucp + 0);
    881906                if (pl > 4) {
    882907                    if ((ucp[2] & 0x1) && (ucp[2] & 0x2)) {
    883                         pout("  Error event %d:\n", pc);
    884                         pout("    [binary]:\n");
     908                        jout("  Error event %d:\n", pc);
     909                        jout("    [binary]:\n");
    885910                        dStrHex((const uint8_t *)ucp + 4, pl - 4, 1);
    886911                    } else if (ucp[2] & 0x1) {
    887                         pout("  Error event %d:\n", pc);
    888                         pout("    %.*s\n", pl - 4, (const char *)(ucp + 4));
     912                        jout("  Error event %d:\n", pc);
     913                        jout("    %.*s\n", pl - 4, (const char *)(ucp + 4));
    889914                    } else {
    890915                        if (scsi_debugmode > 0) {
    891                             pout("  Error event %d:\n", pc);
    892                             pout("    [data counter??]:\n");
     916                            jout("  Error event %d:\n", pc);
     917                            jout("    [data counter??]:\n");
    893918                            dStrHex((const uint8_t *)ucp + 4, pl - 4, 1);
    894919                        }
    895920                    }
    896921                }
    897922            }
    898923            if (truncated)
    899                 pout(" >>>> log truncated, fetched %d of %d available "
     924                jout(" >>>> log truncated, fetched %d of %d available "
    900925                     "bytes\n", LOG_RESP_LONG_LEN, truncated);
    901926        }
    902927    }
    903     pout("\n");
     928    jout("\n");
    904929}
    905930
    906931static const char * self_test_code[] = {
    scsiPrintSelfTest(scsi_device * device)  
    952977    if (!scsiRequestSense(device, &sense_info) &&
    953978                        (sense_info.asc == 0x04 && sense_info.ascq == 0x09 &&
    954979                        sense_info.progress != -1)) {
    955         pout("%s execution status:\t\t%d%% of test remaining\n", hname,
     980        jout("%s execution status:\t\t%d%% of test remaining\n", hname,
    956981             100 - ((sense_info.progress * 100) / 65535));
    957982    }
    958983
    959984    if ((err = scsiLogSense(device, SELFTEST_RESULTS_LPAGE, 0, gBuf,
    960985                            LOG_RESP_SELF_TEST_LEN, 0))) {
    961986        print_on();
    962         pout("%s: Failed [%s]\n", __func__, scsiErrString(err));
     987        jout("%s: Failed [%s]\n", __func__, scsiErrString(err));
    963988        print_off();
    964989        return FAILSMART;
    965990    }
    966991    if ((gBuf[0] & 0x3f) != SELFTEST_RESULTS_LPAGE) {
    967992        print_on();
    968         pout("%s %s, page mismatch\n", hname, logSenRspStr);
     993        jout("%s %s, page mismatch\n", hname, logSenRspStr);
    969994        print_off();
    970995        return FAILSMART;
    971996    }
    scsiPrintSelfTest(scsi_device * device)  
    974999    // Log sense page length 0x190 bytes
    9751000    if (num != 0x190) {
    9761001        print_on();
    977         pout("%s %s length is 0x%x not 0x190 bytes\n", hname, logSenStr, num);
     1002        jout("%s %s length is 0x%x not 0x190 bytes\n", hname, logSenStr, num);
    9781003        print_off();
    9791004        return FAILSMART;
    9801005    }
    scsiPrintSelfTest(scsi_device * device)  
    9901015
    9911016        // only print header if needed
    9921017        if (noheader) {
    993             pout("SMART %s log\n", hname);
    994             pout("Num  Test              Status                 segment  "
     1018            jout("SMART %s log\n", hname);
     1019            jout("Num  Test              Status                 segment  "
    9951020                   "LifeTime  LBA_first_err [SK ASC ASQ]\n");
    996             pout("     Description                              number   "
     1021            jout("     Description                              number   "
    9971022                   "(hours)\n");
    9981023            noheader=0;
    9991024        }
    10001025
    10011026        // print parameter code (test number) & self-test code text
    1002         pout("#%2d  %s", sg_get_unaligned_be16(ucp + 0),
     1027        jout("#%2d  %s", sg_get_unaligned_be16(ucp + 0),
    10031028            self_test_code[(ucp[4] >> 5) & 0x7]);
    10041029
    10051030        // check the self-test result nibble, using the self-test results
    scsiPrintSelfTest(scsi_device * device)  
    10351060        default:
    10361061            break;
    10371062        }
    1038         pout("  %s", self_test_result[res]);
     1063        jout("  %s", self_test_result[res]);
    10391064
    10401065        // self-test number identifies test that failed and consists
    10411066        // of either the number of the segment that failed during
    scsiPrintSelfTest(scsi_device * device)  
    10441069        // vendor-specific method of putting both numbers into a
    10451070        // single byte.
    10461071        if (ucp[5])
    1047             pout(" %3d",  (int)ucp[5]);
     1072            jout(" %3d",  (int)ucp[5]);
    10481073        else
    1049             pout("   -");
     1074            jout("   -");
    10501075
    10511076        // print time that the self-test was completed
    10521077        if (n==0 && res==0xf)
    10531078        // self-test in progress
    1054             pout("     NOW");
     1079            jout("     NOW");
    10551080        else
    1056             pout("   %5d", n);
     1081            jout("   %5d", n);
    10571082
    10581083        // construct 8-byte integer address of first failure
    10591084        ull = sg_get_unaligned_be64(ucp + 8);
    scsiPrintSelfTest(scsi_device * device)  
    10651090            // was hex but change to decimal to conform with ATA
    10661091            snprintf(buff, sizeof(buff), "%" PRIu64, ull);
    10671092            // snprintf(buff, sizeof(buff), "0x%" PRIx64, ull);
    1068             pout("%18s", buff);
     1093            jout("%18s", buff);
    10691094        } else
    1070             pout("                 -");
     1095            jout("                 -");
    10711096
    10721097        // if sense key nonzero, then print it, along with
    10731098        // additional sense code and additional sense code qualifier
    10741099        if (ucp[16] & 0xf)
    1075             pout(" [0x%x 0x%x 0x%x]\n", ucp[16] & 0xf, ucp[17], ucp[18]);
     1100            jout(" [0x%x 0x%x 0x%x]\n", ucp[16] & 0xf, ucp[17], ucp[18]);
    10761101        else
    1077             pout(" [-   -    -]\n");
     1102            jout(" [-   -    -]\n");
    10781103    }
    10791104
    10801105    // if header never printed, then there was no output
    10811106    if (noheader)
    1082         pout("No %ss have been logged\n", hname);
     1107        jout("No %ss have been logged\n", hname);
    10831108    else
    10841109    if ((0 == scsiFetchExtendedSelfTestTime(device, &durationSec,
    10851110                        modese_len)) && (durationSec > 0)) {
    1086         pout("\nLong (extended) %s duration: %d seconds "
     1111        jout("\nLong (extended) %s duration: %d seconds "
    10871112             "[%.1f minutes]\n", hname, durationSec, durationSec / 60.0);
    10881113    }
    1089     pout("\n");
     1114    jout("\n");
    10901115    return retval;
    10911116}
    10921117
    scsiPrintBackgroundResults(scsi_device * device)  
    11311156    if ((err = scsiLogSense(device, BACKGROUND_RESULTS_LPAGE, 0, gBuf,
    11321157                            LOG_RESP_LONG_LEN, 0))) {
    11331158        print_on();
    1134         pout("%s Failed [%s]\n", __func__, scsiErrString(err));
     1159        jout("%s Failed [%s]\n", __func__, scsiErrString(err));
    11351160        print_off();
    11361161        return FAILSMART;
    11371162    }
    11381163    if ((gBuf[0] & 0x3f) != BACKGROUND_RESULTS_LPAGE) {
    11391164        print_on();
    1140         pout("%s %s, page mismatch\n", hname, logSenRspStr);
     1165        jout("%s %s, page mismatch\n", hname, logSenRspStr);
    11411166        print_off();
    11421167        return FAILSMART;
    11431168    }
    scsiPrintBackgroundResults(scsi_device * device)  
    11451170    num = sg_get_unaligned_be16(gBuf + 2) + 4;
    11461171    if (num < 20) {
    11471172        print_on();
    1148         pout("%s %s length is %d, no scan status\n", hname, logSenStr, num);
     1173        jout("%s %s length is %d, no scan status\n", hname, logSenStr, num);
    11491174        print_off();
    11501175        return FAILSMART;
    11511176    }
    scsiPrintBackgroundResults(scsi_device * device)  
    11621187        case 0:
    11631188            if (noheader) {
    11641189                noheader = 0;
    1165                 pout("%s log\n", hname);
     1190                jout("%s log\n", hname);
    11661191            }
    1167             pout("  Status: ");
     1192            jout("  Status: ");
    11681193            if ((pl < 16) || (num < 16)) {
    1169                 pout("\n");
     1194                jout("\n");
    11701195                break;
    11711196            }
    11721197            j = ucp[9];
    11731198            if (j < (int)(sizeof(bms_status) / sizeof(bms_status[0])))
    1174                 pout("%s\n", bms_status[j]);
     1199                jout("%s\n", bms_status[j]);
    11751200            else
    1176                 pout("unknown [0x%x] background scan status value\n", j);
     1201                jout("unknown [0x%x] background scan status value\n", j);
    11771202            j = sg_get_unaligned_be32(ucp + 4);
    1178             pout("    Accumulated power on time, hours:minutes %d:%02d "
     1203            jout("    Accumulated power on time, hours:minutes %d:%02d "
    11791204                 "[%d minutes]\n", (j / 60), (j % 60), j);
    1180             pout("    Number of background scans performed: %d,  ",
     1205            jglb["scsi_accumulated_power_on_time_minutes"] = j;
     1206            jout("    Number of background scans performed: %d,  ",
    11811207                 sg_get_unaligned_be16(ucp + 10));
    1182             pout("scan progress: %.2f%%\n",
     1208            jglb["scsi_number_sacns_performed"] = sg_get_unaligned_be16(ucp + 10);
     1209            jout("scan progress: %.2f%%\n",
    11831210                 (double)sg_get_unaligned_be16(ucp + 12) * 100.0 / 65536.0);
    1184             pout("    Number of background medium scans performed: %d\n",
     1211            jout("    Number of background medium scans performed: %d\n",
    11851212                 sg_get_unaligned_be16(ucp + 14));
     1213            jglb["scsi_number_medium_scans_performed"] = sg_get_unaligned_be16(ucp + 14);
    11861214            break;
    11871215        default:
    11881216            if (noheader) {
    11891217                noheader = 0;
    1190                 pout("\n%s log\n", hname);
     1218                jout("\n%s log\n", hname);
    11911219            }
    11921220            if (firstresult) {
    11931221                firstresult = 0;
    1194                 pout("\n   #  when        lba(hex)    [sk,asc,ascq]    "
     1222                jout("\n   #  when        lba(hex)    [sk,asc,ascq]    "
    11951223                     "reassign_status\n");
    11961224            }
    1197             pout(" %3d ", pc);
     1225            jout(" %3d ", pc);
    11981226            if ((pl < 24) || (num < 24)) {
    11991227                if (pl < 24)
    1200                     pout("parameter length >= 24 expected, got %d\n", pl);
     1228                    jout("parameter length >= 24 expected, got %d\n", pl);
    12011229                break;
    12021230            }
    12031231            j = sg_get_unaligned_be32(ucp + 4);
    1204             pout("%4d:%02d  ", (j / 60), (j % 60));
     1232            jout("%4d:%02d  ", (j / 60), (j % 60));
    12051233            for (m = 0; m < 8; ++m)
    1206                 pout("%02x", ucp[16 + m]);
    1207             pout("  [%x,%x,%x]   ", ucp[8] & 0xf, ucp[9], ucp[10]);
     1234                jout("%02x", ucp[16 + m]);
     1235            jout("  [%x,%x,%x]   ", ucp[8] & 0xf, ucp[9], ucp[10]);
    12081236            j = (ucp[8] >> 4) & 0xf;
    12091237            if (j <
    12101238                (int)(sizeof(reassign_status) / sizeof(reassign_status[0])))
    1211                 pout("%s\n", reassign_status[j]);
     1239                jout("%s\n", reassign_status[j]);
    12121240            else
    1213                 pout("Reassign status: reserved [0x%x]\n", j);
     1241                jout("Reassign status: reserved [0x%x]\n", j);
    12141242            break;
    12151243        }
    12161244        num -= pl;
    12171245        ucp += pl;
    12181246    }
    12191247    if (truncated)
    1220         pout(" >>>> log truncated, fetched %d of %d available "
     1248        jout(" >>>> log truncated, fetched %d of %d available "
    12211249             "bytes\n", LOG_RESP_LONG_LEN, truncated);
    1222     pout("\n");
     1250    jout("\n");
    12231251    return retval;
    12241252}
    12251253
    scsiPrintSSMedia(scsi_device * device)  
    12381266    if ((err = scsiLogSense(device, SS_MEDIA_LPAGE, 0, gBuf,
    12391267                            LOG_RESP_LONG_LEN, 0))) {
    12401268        print_on();
    1241         pout("%s: Failed [%s]\n", __func__, scsiErrString(err));
     1269        jout("%s: Failed [%s]\n", __func__, scsiErrString(err));
    12421270        print_off();
    12431271        return FAILSMART;
    12441272    }
    12451273    if ((gBuf[0] & 0x3f) != SS_MEDIA_LPAGE) {
    12461274        print_on();
    1247         pout("%s %s, page mismatch\n", hname, logSenStr);
     1275        jout("%s %s, page mismatch\n", hname, logSenStr);
    12481276        print_off();
    12491277        return FAILSMART;
    12501278    }
    scsiPrintSSMedia(scsi_device * device)  
    12521280    num = sg_get_unaligned_be16(gBuf + 2) + 4;
    12531281    if (num < 12) {
    12541282        print_on();
    1255         pout("%s %s length is %d, too short\n", hname, logSenStr, num);
     1283        jout("%s %s length is %d, too short\n", hname, logSenStr, num);
    12561284        print_off();
    12571285        return FAILSMART;
    12581286    }
    scsiPrintSSMedia(scsi_device * device)  
    12691297        case 1:
    12701298            if (pl < 8) {
    12711299                print_on();
    1272                 pout("%s Percentage used endurance indicator parameter "
     1300                jout("%s Percentage used endurance indicator parameter "
    12731301                     "too short (pl=%d)\n", hname, pl);
    12741302                print_off();
    12751303                return FAILSMART;
    12761304            }
    1277             pout("Percentage used endurance indicator: %d%%\n", ucp[7]);
     1305            jout("Percentage used endurance indicator: %d%%\n", ucp[7]);
     1306            jglb["scsi_percentage_used_endurance_indicator"] = ucp[7];
    12781307        default:        /* ignore other parameter codes */
    12791308            break;
    12801309        }
    scsiPrintFormatStatus(scsi_device * device)  
    13661395            break;
    13671396        default:
    13681397            if (scsi_debugmode > 3) {
    1369                 pout("  Unknown Format parameter code = 0x%x\n", pc);
     1398                jout("  Unknown Format parameter code = 0x%x\n", pc);
    13701399                dStrHex((const uint8_t *)ucp, pl, 0);
    13711400            }
    13721401            is_count = false;
    show_sas_phy_event_info(int peis, unsigned int val, unsigned thresh_val)  
    14021431
    14031432    switch (peis) {
    14041433    case 0:
    1405         pout("     No event\n");
     1434        jout("     No event\n");
    14061435        break;
    14071436    case 0x1:
    1408         pout("     Invalid word count: %u\n", val);
     1437        jout("     Invalid word count: %u\n", val);
    14091438        break;
    14101439    case 0x2:
    1411         pout("     Running disparity error count: %u\n", val);
     1440        jout("     Running disparity error count: %u\n", val);
    14121441        break;
    14131442    case 0x3:
    1414         pout("     Loss of dword synchronization count: %u\n", val);
     1443        jout("     Loss of dword synchronization count: %u\n", val);
    14151444        break;
    14161445    case 0x4:
    1417         pout("     Phy reset problem count: %u\n", val);
     1446        jout("     Phy reset problem count: %u\n", val);
    14181447        break;
    14191448    case 0x5:
    1420         pout("     Elasticity buffer overflow count: %u\n", val);
     1449        jout("     Elasticity buffer overflow count: %u\n", val);
    14211450        break;
    14221451    case 0x6:
    1423         pout("     Received ERROR  count: %u\n", val);
     1452        jout("     Received ERROR  count: %u\n", val);
    14241453        break;
    14251454    case 0x20:
    1426         pout("     Received address frame error count: %u\n", val);
     1455        jout("     Received address frame error count: %u\n", val);
    14271456        break;
    14281457    case 0x21:
    1429         pout("     Transmitted abandon-class OPEN_REJECT count: %u\n", val);
     1458        jout("     Transmitted abandon-class OPEN_REJECT count: %u\n", val);
    14301459        break;
    14311460    case 0x22:
    1432         pout("     Received abandon-class OPEN_REJECT count: %u\n", val);
     1461        jout("     Received abandon-class OPEN_REJECT count: %u\n", val);
    14331462        break;
    14341463    case 0x23:
    1435         pout("     Transmitted retry-class OPEN_REJECT count: %u\n", val);
     1464        jout("     Transmitted retry-class OPEN_REJECT count: %u\n", val);
    14361465        break;
    14371466    case 0x24:
    1438         pout("     Received retry-class OPEN_REJECT count: %u\n", val);
     1467        jout("     Received retry-class OPEN_REJECT count: %u\n", val);
    14391468        break;
    14401469    case 0x25:
    1441         pout("     Received AIP (WATING ON PARTIAL) count: %u\n", val);
     1470        jout("     Received AIP (WATING ON PARTIAL) count: %u\n", val);
    14421471        break;
    14431472    case 0x26:
    1444         pout("     Received AIP (WAITING ON CONNECTION) count: %u\n", val);
     1473        jout("     Received AIP (WAITING ON CONNECTION) count: %u\n", val);
    14451474        break;
    14461475    case 0x27:
    1447         pout("     Transmitted BREAK count: %u\n", val);
     1476        jout("     Transmitted BREAK count: %u\n", val);
    14481477        break;
    14491478    case 0x28:
    1450         pout("     Received BREAK count: %u\n", val);
     1479        jout("     Received BREAK count: %u\n", val);
    14511480        break;
    14521481    case 0x29:
    1453         pout("     Break timeout count: %u\n", val);
     1482        jout("     Break timeout count: %u\n", val);
    14541483        break;
    14551484    case 0x2a:
    1456         pout("     Connection count: %u\n", val);
     1485        jout("     Connection count: %u\n", val);
    14571486        break;
    14581487    case 0x2b:
    1459         pout("     Peak transmitted pathway blocked count: %u\n",
     1488        jout("     Peak transmitted pathway blocked count: %u\n",
    14601489               val & 0xff);
    1461         pout("         Peak value detector threshold: %u\n",
     1490        jout("         Peak value detector threshold: %u\n",
    14621491               thresh_val & 0xff);
    14631492        break;
    14641493    case 0x2c:
    14651494        u = val & 0xffff;
    14661495        if (u < 0x8000)
    1467             pout("     Peak transmitted arbitration wait time (us): "
     1496            jout("     Peak transmitted arbitration wait time (us): "
    14681497                   "%u\n", u);
    14691498        else
    1470             pout("     Peak transmitted arbitration wait time (ms): "
     1499            jout("     Peak transmitted arbitration wait time (ms): "
    14711500                   "%u\n", 33 + (u - 0x8000));
    14721501        u = thresh_val & 0xffff;
    14731502        if (u < 0x8000)
    1474             pout("         Peak value detector threshold (us): %u\n",
     1503            jout("         Peak value detector threshold (us): %u\n",
    14751504                   u);
    14761505        else
    1477             pout("         Peak value detector threshold (ms): %u\n",
     1506            jout("         Peak value detector threshold (ms): %u\n",
    14781507                   33 + (u - 0x8000));
    14791508        break;
    14801509    case 0x2d:
    1481         pout("     Peak arbitration time (us): %u\n", val);
    1482         pout("         Peak value detector threshold: %u\n", thresh_val);
     1510        jout("     Peak arbitration time (us): %u\n", val);
     1511        jout("         Peak value detector threshold: %u\n", thresh_val);
    14831512        break;
    14841513    case 0x2e:
    1485         pout("     Peak connection time (us): %u\n", val);
    1486         pout("         Peak value detector threshold: %u\n", thresh_val);
     1514        jout("     Peak connection time (us): %u\n", val);
     1515        jout("         Peak value detector threshold: %u\n", thresh_val);
    14871516        break;
    14881517    case 0x40:
    1489         pout("     Transmitted SSP frame count: %u\n", val);
     1518        jout("     Transmitted SSP frame count: %u\n", val);
    14901519        break;
    14911520    case 0x41:
    1492         pout("     Received SSP frame count: %u\n", val);
     1521        jout("     Received SSP frame count: %u\n", val);
    14931522        break;
    14941523    case 0x42:
    1495         pout("     Transmitted SSP frame error count: %u\n", val);
     1524        jout("     Transmitted SSP frame error count: %u\n", val);
    14961525        break;
    14971526    case 0x43:
    1498         pout("     Received SSP frame error count: %u\n", val);
     1527        jout("     Received SSP frame error count: %u\n", val);
    14991528        break;
    15001529    case 0x44:
    1501         pout("     Transmitted CREDIT_BLOCKED count: %u\n", val);
     1530        jout("     Transmitted CREDIT_BLOCKED count: %u\n", val);
    15021531        break;
    15031532    case 0x45:
    1504         pout("     Received CREDIT_BLOCKED count: %u\n", val);
     1533        jout("     Received CREDIT_BLOCKED count: %u\n", val);
    15051534        break;
    15061535    case 0x50:
    1507         pout("     Transmitted SATA frame count: %u\n", val);
     1536        jout("     Transmitted SATA frame count: %u\n", val);
    15081537        break;
    15091538    case 0x51:
    1510         pout("     Received SATA frame count: %u\n", val);
     1539        jout("     Received SATA frame count: %u\n", val);
    15111540        break;
    15121541    case 0x52:
    1513         pout("     SATA flow control buffer overflow count: %u\n", val);
     1542        jout("     SATA flow control buffer overflow count: %u\n", val);
    15141543        break;
    15151544    case 0x60:
    1516         pout("     Transmitted SMP frame count: %u\n", val);
     1545        jout("     Transmitted SMP frame count: %u\n", val);
    15171546        break;
    15181547    case 0x61:
    1519         pout("     Received SMP frame count: %u\n", val);
     1548        jout("     Received SMP frame count: %u\n", val);
    15201549        break;
    15211550    case 0x63:
    1522         pout("     Received SMP frame error count: %u\n", val);
     1551        jout("     Received SMP frame error count: %u\n", val);
    15231552        break;
    15241553    default:
    15251554        break;
    show_sas_port_param(unsigned char * ucp, int param_len)  
    15361565    sz = sizeof(s);
    15371566    // pcb = ucp[2];
    15381567    t = sg_get_unaligned_be16(ucp + 0);
    1539     pout("relative target port id = %d\n", t);
    1540     pout("  generation code = %d\n", ucp[6]);
     1568    jout("relative target port id = %d\n", t);
     1569    jout("  generation code = %d\n", ucp[6]);
    15411570    nphys = ucp[7];
    1542     pout("  number of phys = %d\n", nphys);
     1571    jout("  number of phys = %d\n", nphys);
    15431572
    15441573    for (j = 0, vcp = ucp + 8; j < (param_len - 8);
    15451574         vcp += spld_len, j += spld_len) {
    1546         pout("  phy identifier = %d\n", vcp[1]);
     1575        jout("  phy identifier = %d\n", vcp[1]);
    15471576        spld_len = vcp[3];
    15481577        if (spld_len < 44)
    15491578            spld_len = 48;      /* in SAS-1 and SAS-1.1 vcp[3]==0 */
    show_sas_port_param(unsigned char * ucp, int param_len)  
    15571586        case 3: snprintf(s, sz, "expander device (fanout)"); break;
    15581587        default: snprintf(s, sz, "reserved [%d]", t); break;
    15591588        }
    1560         pout("    attached device type: %s\n", s);
     1589        jout("    attached device type: %s\n", s);
    15611590        t = 0xf & vcp[4];
    15621591        switch (t) {
    15631592        case 0: snprintf(s, sz, "unknown"); break;
    show_sas_port_param(unsigned char * ucp, int param_len)  
    15741603             break;
    15751604        default: snprintf(s, sz, "reserved [0x%x]", t); break;
    15761605        }
    1577         pout("    attached reason: %s\n", s);
     1606        jout("    attached reason: %s\n", s);
    15781607        t = (vcp[5] & 0xf0) >> 4;
    15791608        switch (t) {
    15801609        case 0: snprintf(s, sz, "unknown"); break;
    show_sas_port_param(unsigned char * ucp, int param_len)  
    15911620             break;
    15921621        default: snprintf(s, sz, "reserved [0x%x]", t); break;
    15931622        }
    1594         pout("    reason: %s\n", s);
     1623        jout("    reason: %s\n", s);
    15951624        t = (0xf & vcp[5]);
    15961625        switch (t) {
    15971626        case 0: snprintf(s, sz, "phy enabled; unknown");
    show_sas_port_param(unsigned char * ucp, int param_len)  
    16131642        case 0xb: snprintf(s, sz, "phy enabled; 12 Gbps"); break;
    16141643        default: snprintf(s, sz, "reserved [%d]", t); break;
    16151644        }
    1616         pout("    negotiated logical link rate: %s\n", s);
    1617         pout("    attached initiator port: ssp=%d stp=%d smp=%d\n",
     1645        jout("    negotiated logical link rate: %s\n", s);
     1646        jout("    attached initiator port: ssp=%d stp=%d smp=%d\n",
    16181647               !! (vcp[6] & 8), !! (vcp[6] & 4), !! (vcp[6] & 2));
    1619         pout("    attached target port: ssp=%d stp=%d smp=%d\n",
     1648        jout("    attached target port: ssp=%d stp=%d smp=%d\n",
    16201649               !! (vcp[7] & 8), !! (vcp[7] & 4), !! (vcp[7] & 2));
    16211650        if (!dont_print_serial_number) {
    16221651            uint64_t ull = sg_get_unaligned_be64(vcp + 8);
    16231652
    1624             pout("    SAS address = 0x%" PRIx64 "\n", ull);
     1653            jout("    SAS address = 0x%" PRIx64 "\n", ull);
    16251654            ull = sg_get_unaligned_be64(vcp + 16);
    1626             pout("    attached SAS address = 0x%" PRIx64 "\n", ull);
     1655            jout("    attached SAS address = 0x%" PRIx64 "\n", ull);
    16271656        }
    1628         pout("    attached phy identifier = %d\n", vcp[24]);
     1657        jout("    attached phy identifier = %d\n", vcp[24]);
    16291658        unsigned int ui = sg_get_unaligned_be32(vcp + 32);
    16301659
    1631         pout("    Invalid DWORD count = %u\n", ui);
     1660        jout("    Invalid DWORD count = %u\n", ui);
    16321661        ui = sg_get_unaligned_be32(vcp + 36);
    1633         pout("    Running disparity error count = %u\n", ui);
     1662        jout("    Running disparity error count = %u\n", ui);
    16341663        ui = sg_get_unaligned_be32(vcp + 40);
    1635         pout("    Loss of DWORD synchronization = %u\n", ui);
     1664        jout("    Loss of DWORD synchronization = %u\n", ui);
    16361665        ui = sg_get_unaligned_be32(vcp + 44);
    1637         pout("    Phy reset problem = %u\n", ui);
     1666        jout("    Phy reset problem = %u\n", ui);
    16381667        if (spld_len > 51) {
    16391668            int num_ped;
    16401669            unsigned char * xcp;
    16411670
    16421671            num_ped = vcp[51];
    16431672            if (num_ped > 0)
    1644                pout("    Phy event descriptors:\n");
     1673               jout("    Phy event descriptors:\n");
    16451674            xcp = vcp + 52;
    16461675            for (m = 0; m < (num_ped * 12); m += 12, xcp += 12) {
    16471676                int peis;
    show_protocol_specific_page(unsigned char * resp, int len)  
    16681697        if (SCSI_TPROTO_SAS != (0xf & ucp[4]))
    16691698            return 0;   /* only decode SAS log page */
    16701699        if (0 == k)
    1671             pout("Protocol Specific port log page for SAS SSP\n");
     1700            jout("Protocol Specific port log page for SAS SSP\n");
    16721701        show_sas_port_param(ucp, param_len);
    16731702        k += param_len;
    16741703        ucp += param_len;
    16751704    }
    1676     pout("\n");
     1705    jout("\n");
    16771706    return 1;
    16781707}
    16791708
    scsiPrintSasPhy(scsi_device * device, int reset)  
    16891718    if ((err = scsiLogSense(device, PROTOCOL_SPECIFIC_LPAGE, 0, gBuf,
    16901719                            LOG_RESP_LONG_LEN, 0))) {
    16911720        print_on();
    1692         pout("%s %s Failed [%s]\n\n", __func__, logSenStr,
     1721        jout("%s %s Failed [%s]\n\n", __func__, logSenStr,
    16931722             scsiErrString(err));
    16941723        print_off();
    16951724        return FAILSMART;
    16961725    }
    16971726    if ((gBuf[0] & 0x3f) != PROTOCOL_SPECIFIC_LPAGE) {
    16981727        print_on();
    1699         pout("%s %s, page mismatch\n\n", hname, logSenRspStr);
     1728        jout("%s %s, page mismatch\n\n", hname, logSenRspStr);
    17001729        print_off();
    17011730        return FAILSMART;
    17021731    }
    scsiPrintSasPhy(scsi_device * device, int reset)  
    17041733    num = sg_get_unaligned_be16(gBuf + 2);
    17051734    if (1 != show_protocol_specific_page(gBuf, num + 4)) {
    17061735        print_on();
    1707         pout("Only support %s log page on SAS devices\n\n", hname);
     1736        jout("Only support %s log page on SAS devices\n\n", hname);
    17081737        print_off();
    17091738        return FAILSMART;
    17101739    }
    scsiPrintSasPhy(scsi_device * device, int reset)  
    17121741        if ((err = scsiLogSelect(device, 1 /* pcr */, 0 /* sp */, 0 /* pc */,
    17131742                                 PROTOCOL_SPECIFIC_LPAGE, 0, NULL, 0))) {
    17141743            print_on();
    1715             pout("%s Log Select (reset) Failed [%s]\n\n", __func__,
     1744            jout("%s Log Select (reset) Failed [%s]\n\n", __func__,
    17161745                 scsiErrString(err));
    17171746            print_off();
    17181747            return FAILSMART;
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    17941823    req_len = 36;
    17951824    if ((err = scsiStdInquiry(device, gBuf, req_len))) {
    17961825        print_on();
    1797         pout("Standard Inquiry (36 bytes) failed [%s]\n", scsiErrString(err));
    1798         pout("Retrying with a 64 byte Standard Inquiry\n");
     1826        jout("Standard Inquiry (36 bytes) failed [%s]\n", scsiErrString(err));
     1827        jout("Retrying with a 64 byte Standard Inquiry\n");
    17991828        print_off();
    18001829        /* Marvell controllers fail with 36 byte StdInquiry, but 64 is ok */
    18011830        req_len = 64;
    18021831        if ((err = scsiStdInquiry(device, gBuf, req_len))) {
    18031832            print_on();
    1804             pout("Standard Inquiry (64 bytes) failed [%s]\n",
     1833            jout("Standard Inquiry (64 bytes) failed [%s]\n",
    18051834                 scsiErrString(err));
    18061835            print_off();
    18071836            return 1;
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    18171846
    18181847    if (len < 36) {
    18191848        print_on();
    1820         pout("Short INQUIRY response, skip product id\n");
     1849        jout("Short INQUIRY response, skip product id\n");
    18211850        print_off();
    18221851        return 1;
    18231852    }
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    18311860        scsi_format_id_string(product, &gBuf[16], 16);
    18321861        scsi_format_id_string(revision, &gBuf[32], 4);
    18331862
    1834         pout("=== START OF INFORMATION SECTION ===\n");
     1863        jout("=== START OF INFORMATION SECTION ===\n");
    18351864        jout("Vendor:               %.8s\n", scsi_vendor);
    18361865        jglb["vendor"] = scsi_vendor;
    18371866        jout("Product:              %.16s\n", product);
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    18541883
    18551884    if (!*device->get_req_type()/*no type requested*/ &&
    18561885               (0 == strncmp((char *)&gBuf[8], "ATA", 3))) {
    1857         pout("\nProbable ATA device behind a SAT layer\n"
     1886        jout("\nProbable ATA device behind a SAT layer\n"
    18581887             "Try an additional '-d ata' or '-d sat' argument.\n");
    18591888        return 2;
    18601889    }
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    18881917                    jout("Physical block size:  %u bytes\n", pb_size);
    18891918                    jglb["physical_block_size"] = pb_size;
    18901919                    if (srr.l_a_lba > 0)  // not common so cut the clutter
    1891                         pout("Lowest aligned LBA:   %u\n", srr.l_a_lba);
     1920                        jout("Lowest aligned LBA:   %u\n", srr.l_a_lba);
    18921921                }
    18931922                if (srr.prot_type > 0) {
    18941923                    switch (srr.prot_type) {
    18951924                    case 1 :
    1896                         pout("Formatted with type 1 protection\n");
     1925                        jout("Formatted with type 1 protection\n");
    18971926                        break;
    18981927                    case 2 :
    1899                         pout("Formatted with type 2 protection\n");
     1928                        jout("Formatted with type 2 protection\n");
    19001929                        break;
    19011930                    case 3 :
    1902                         pout("Formatted with type 3 protection\n");
     1931                        jout("Formatted with type 3 protection\n");
    19031932                        break;
    19041933                    default:
    1905                         pout("Formatted with unknown protection type [%d]\n",
     1934                        jout("Formatted with unknown protection type [%d]\n",
    19061935                             srr.prot_type);
    19071936                        break;
    19081937                    }
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    19111940                                                   app-tag(2), tag-mask(2) */
    19121941
    19131942                    if (p_i_per_lb > 1)
    1914                         pout("%d protection information intervals per "
     1943                        jout("%d protection information intervals per "
    19151944                             "logical block\n", p_i_per_lb);
    1916                     pout("%d bytes of protection information per logical "
     1945                    jout("%d bytes of protection information per logical "
    19171946                         "block\n", pi_sz * p_i_per_lb);
    19181947                }
    19191948                /* Pick up some LB provisioning info since its available */
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    19381967            switch (prov_type) {
    19391968            case 0:
    19401969                if (lbpme <= 0) {
    1941                     pout("LU is fully provisioned");
     1970                    jout("LU is fully provisioned");
    19421971                    if (lbprz)
    1943                         pout(" [LBPRZ=%d]\n", lbprz);
     1972                        jout(" [LBPRZ=%d]\n", lbprz);
    19441973                    else
    1945                         pout("\n");
     1974                        jout("\n");
    19461975                } else
    1947                      pout("LB provisioning type: not reported [LBPME=1, "
     1976                     jout("LB provisioning type: not reported [LBPME=1, "
    19481977                          "LBPRZ=%d]\n", lbprz);
    19491978                break;
    19501979            case 1:
    1951                 pout("LU is resource provisioned, LBPRZ=%d\n", lbprz);
     1980                jout("LU is resource provisioned, LBPRZ=%d\n", lbprz);
    19521981                break;
    19531982            case 2:
    1954                 pout("LU is thin provisioned, LBPRZ=%d\n", lbprz);
     1983                jout("LU is thin provisioned, LBPRZ=%d\n", lbprz);
    19551984                break;
    19561985            default:
    1957                 pout("LU provisioning type reserved [%d], LBPRZ=%d\n",
     1986                jout("LU provisioning type reserved [%d], LBPRZ=%d\n",
    19581987                     prov_type, lbprz);
    19591988                break;
    19601989            }
    19611990        } else if (1 == lbpme) {
    19621991            if (scsi_debugmode > 0)
    1963                 pout("rcap_16 sets LBPME but no LB provisioning VPD page\n");
    1964             pout("Logical block provisioning enabled, LBPRZ=%d\n", lbprz);
     1992                jout("rcap_16 sets LBPME but no LB provisioning VPD page\n");
     1993            jout("Logical block provisioning enabled, LBPRZ=%d\n", lbprz);
    19651994        }
    19661995
    19671996        int rpm = scsiGetRPM(device, modese_len, &form_factor, &haw_zbc);
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    20032032            }
    20042033        }
    20052034        if (haw_zbc > 0)
    2006             pout("Host aware zoned block capable\n");
     2035            jout("Host aware zoned block capable\n");
    20072036    }
    20082037
    20092038    /* Do this here to try and detect badly conforming devices (some USB
    20102039       keys) that will lock up on a InquiryVpd or log sense or ... */
    20112040    if ((iec_err = scsiFetchIECmpage(device, &iec, modese_len))) {
    20122041        if (SIMPLE_ERR_BAD_RESP == iec_err) {
    2013             pout(">> Terminate command early due to bad response to IEC "
     2042            jout(">> Terminate command early due to bad response to IEC "
    20142043                 "mode page\n");
    20152044            print_off();
    20162045            gIecMPage = 0;
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    20272056            len = gBuf[3];
    20282057            scsi_decode_lu_dev_id(gBuf + 4, len, s, sizeof(s), &transport);
    20292058            if (strlen(s) > 0)
    2030                 pout("Logical Unit id:      %s\n", s);
     2059                jout("Logical Unit id:      %s\n", s);
    20312060        } else if (scsi_debugmode > 0) {
    20322061            print_on();
    20332062            if (SIMPLE_ERR_BAD_RESP == err)
    2034                 pout("Vital Product Data (VPD) bit ignored in INQUIRY\n");
     2063                jout("Vital Product Data (VPD) bit ignored in INQUIRY\n");
    20352064            else
    2036                 pout("Vital Product Data (VPD) INQUIRY failed [%d]\n", err);
     2065                jout("Vital Product Data (VPD) INQUIRY failed [%d]\n", err);
    20372066            print_off();
    20382067        }
    20392068        if (0 == (err = scsiInquiryVpd(device, SCSI_VPD_UNIT_SERIAL_NUMBER,
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    20482077        } else if (scsi_debugmode > 0) {
    20492078            print_on();
    20502079            if (SIMPLE_ERR_BAD_RESP == err)
    2051                 pout("Vital Product Data (VPD) bit ignored in INQUIRY\n");
     2080                jout("Vital Product Data (VPD) bit ignored in INQUIRY\n");
    20522081            else
    2053                 pout("Vital Product Data (VPD) INQUIRY failed [%d]\n", err);
     2082                jout("Vital Product Data (VPD) INQUIRY failed [%d]\n", err);
    20542083            print_off();
    20552084        }
    20562085    }
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    20692098    if (transport < 0)
    20702099        transport = scsiFetchTransportProtocol(device, modese_len);
    20712100    if ((transport >= 0) && (transport <= 0xf))
    2072         pout("Transport protocol:   %s\n", transport_proto_arr[transport]);
     2101        jout("Transport protocol:   %s\n", transport_proto_arr[transport]);
    20732102
    20742103    // print current time and date and timezone
    20752104    time_t now = time(0);
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    20832112        if (SIMPLE_ERR_NOT_READY == err) {
    20842113            print_on();
    20852114            if (!is_tape)
    2086                 pout("device is NOT READY (e.g. spun down, busy)\n");
     2115                jout("device is NOT READY (e.g. spun down, busy)\n");
    20872116            else
    2088                 pout("device is NOT READY (e.g. no tape)\n");
     2117                jout("device is NOT READY (e.g. no tape)\n");
    20892118            print_off();
    20902119        } else if (SIMPLE_ERR_NO_MEDIUM == err) {
    20912120            print_on();
    20922121            if (is_tape)
    2093                 pout("NO tape present in drive\n");
     2122                jout("NO tape present in drive\n");
    20942123            else
    2095                 pout("NO MEDIUM present in device\n");
     2124                jout("NO MEDIUM present in device\n");
    20962125            print_off();
    20972126        } else if (SIMPLE_ERR_BECOMING_READY == err) {
    20982127            print_on();
    2099             pout("device becoming ready (wait)\n");
     2128            jout("device becoming ready (wait)\n");
    21002129            print_off();
    21012130        } else {
    21022131            print_on();
    2103             pout("device Test Unit Ready  [%s]\n", scsiErrString(err));
     2132            jout("device Test Unit Ready  [%s]\n", scsiErrString(err));
    21042133            print_off();
    21052134        }
    21062135        if (! is_tape) {
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    21132142    if (iec_err) {
    21142143        if (!is_tape) {
    21152144            print_on();
    2116             pout("SMART support is:     Unavailable - device lacks SMART "
     2145            jout("SMART support is:     Unavailable - device lacks SMART "
    21172146                 "capability.\n");
    21182147            if (scsi_debugmode > 0)
    2119                 pout(" [%s]\n", scsiErrString(iec_err));
     2148                jout(" [%s]\n", scsiErrString(iec_err));
    21202149            print_off();
    21212150        }
    21222151        gIecMPage = 0;
    scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)  
    21242153    }
    21252154
    21262155    if (!is_tape)
    2127         pout("SMART support is:     Available - device has SMART capability.\n"
     2156        jout("SMART support is:     Available - device has SMART capability.\n"
    21282157             "SMART support is:     %s\n",
    21292158             (scsi_IsExceptionControlEnabled(&iec)) ? "Enabled" : "Disabled");
    2130     pout("%s\n", (scsi_IsWarningEnabled(&iec)) ?
     2159    jout("%s\n", (scsi_IsWarningEnabled(&iec)) ?
    21312160                  "Temperature Warning:  Enabled" :
    21322161                  "Temperature Warning:  Disabled or Not Supported");
    21332162    return 0;
    scsiSmartEnable(scsi_device * device)  
    21412170
    21422171    if ((err = scsiFetchIECmpage(device, &iec, modese_len))) {
    21432172        print_on();
    2144         pout("unable to fetch IEC (SMART) mode page [%s]\n",
     2173        jout("unable to fetch IEC (SMART) mode page [%s]\n",
    21452174             scsiErrString(err));
    21462175        print_off();
    21472176        return 1;
    scsiSmartEnable(scsi_device * device)  
    21502179
    21512180    if ((err = scsiSetExceptionControlAndWarning(device, 1, &iec))) {
    21522181        print_on();
    2153         pout("unable to enable Exception control and warning [%s]\n",
     2182        jout("unable to enable Exception control and warning [%s]\n",
    21542183             scsiErrString(err));
    21552184        print_off();
    21562185        return 1;
    21572186    }
    21582187    /* Need to refetch 'iec' since could be modified by previous call */
    21592188    if ((err = scsiFetchIECmpage(device, &iec, modese_len))) {
    2160         pout("unable to fetch IEC (SMART) mode page [%s]\n",
     2189        jout("unable to fetch IEC (SMART) mode page [%s]\n",
    21612190             scsiErrString(err));
    21622191        return 1;
    21632192    } else
    21642193        modese_len = iec.modese_len;
    21652194
    2166     pout("Informational Exceptions (SMART) %s\n",
     2195    jout("Informational Exceptions (SMART) %s\n",
    21672196         scsi_IsExceptionControlEnabled(&iec) ? "enabled" : "disabled");
    2168     pout("Temperature warning %s\n",
     2197    jout("Temperature warning %s\n",
    21692198         scsi_IsWarningEnabled(&iec) ? "enabled" : "disabled");
    21702199    return 0;
    21712200}
    scsiSmartDisable(scsi_device * device)  
    21782207
    21792208    if ((err = scsiFetchIECmpage(device, &iec, modese_len))) {
    21802209        print_on();
    2181         pout("unable to fetch IEC (SMART) mode page [%s]\n",
     2210        jout("unable to fetch IEC (SMART) mode page [%s]\n",
    21822211             scsiErrString(err));
    21832212        print_off();
    21842213        return 1;
    scsiSmartDisable(scsi_device * device)  
    21872216
    21882217    if ((err = scsiSetExceptionControlAndWarning(device, 0, &iec))) {
    21892218        print_on();
    2190         pout("unable to disable Exception control and warning [%s]\n",
     2219        jout("unable to disable Exception control and warning [%s]\n",
    21912220             scsiErrString(err));
    21922221        print_off();
    21932222        return 1;
    21942223    }
    21952224    /* Need to refetch 'iec' since could be modified by previous call */
    21962225    if ((err = scsiFetchIECmpage(device, &iec, modese_len))) {
    2197         pout("unable to fetch IEC (SMART) mode page [%s]\n",
     2226        jout("unable to fetch IEC (SMART) mode page [%s]\n",
    21982227             scsiErrString(err));
    21992228        return 1;
    22002229    } else
    22012230        modese_len = iec.modese_len;
    22022231
    2203     pout("Informational Exceptions (SMART) %s\n",
     2232    jout("Informational Exceptions (SMART) %s\n",
    22042233         scsi_IsExceptionControlEnabled(&iec) ? "enabled" : "disabled");
    2205     pout("Temperature warning %s\n",
     2234    jout("Temperature warning %s\n",
    22062235         scsi_IsWarningEnabled(&iec) ? "enabled" : "disabled");
    22072236    return 0;
    22082237}
    scsiPrintTemp(scsi_device * device)  
    22172246        return;
    22182247
    22192248    if (255 == temp)
    2220         pout("Current Drive Temperature:     <not available>\n");
     2249        jout("Current Drive Temperature:     <not available>\n");
    22212250    else {
    22222251        jout("Current Drive Temperature:     %d C\n", temp);
    22232252        jglb["temperature"]["current"] = temp;
    22242253    }
    22252254    if (255 == trip)
    2226         pout("Drive Trip Temperature:        <not available>\n");
    2227     else
    2228         pout("Drive Trip Temperature:        %d C\n", trip);
    2229     pout("\n");
     2255        jout("Drive Trip Temperature:        <not available>\n");
     2256    else {
     2257        jout("Drive Trip Temperature:        %d C\n", trip);
     2258        jglb["temperature"]["drive_trip"] = trip;
     2259    }
     2260    jout("\n");
    22302261}
    22312262
    22322263/* Main entry point used by smartctl command. Return 0 for success */
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    22682299        if (is_disk) {
    22692300            res = scsiGetSetCache(device, modese_len, &wce, &rcd);
    22702301            if (options.get_rcd)
    2271                 pout("Read Cache is:        %s\n",
     2302                jout("Read Cache is:        %s\n",
    22722303                     res ? "Unavailable" : // error
    22732304                     rcd ? "Disabled" : "Enabled");
    22742305            if (options.get_wce)
    2275                 pout("Writeback Cache is:   %s\n",
     2306                jout("Writeback Cache is:   %s\n",
    22762307                     res ? "Unavailable" : // error
    22772308                     !wce ? "Disabled" : "Enabled");
    22782309        }
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    22802311        any_output = true;
    22812312
    22822313    if (options.drive_info)
    2283         pout("\n");
     2314        jout("\n");
    22842315
    22852316    // START OF THE ENABLE/DISABLE SECTION OF THE CODE
    22862317    if (options.smart_disable           || options.smart_enable ||
    22872318        options.smart_auto_save_disable || options.smart_auto_save_enable)
    2288         pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
     2319        jout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
    22892320
    22902321    if (options.smart_enable) {
    22912322        if (scsiSmartEnable(device))
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    23012332
    23022333    if (options.smart_auto_save_enable) {
    23032334        if (scsiSetControlGLTSD(device, 0, modese_len)) {
    2304             pout("Enable autosave (clear GLTSD bit) failed\n");
     2335            jout("Enable autosave (clear GLTSD bit) failed\n");
    23052336            failuretest(OPTIONAL_CMD,returnval |= FAILSMART);
    23062337        } else
    2307             pout("Autosave enabled (GLTSD bit cleared).\n");
     2338            jout("Autosave enabled (GLTSD bit cleared).\n");
    23082339        any_output = true;
    23092340    }
    23102341
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    23142345
    23152346        rcd = -1;
    23162347        if (scsiGetSetCache(device, modese_len, &wce, &rcd)) {
    2317             pout("Write cache %sable failed: %s\n", (enable ? "en" : "dis"),
     2348            jout("Write cache %sable failed: %s\n", (enable ? "en" : "dis"),
    23182349                 device->get_errmsg());
    23192350            failuretest(OPTIONAL_CMD,returnval |= FAILSMART);
    23202351        } else
    2321             pout("Write cache %sabled\n", (enable ? "en" : "dis"));
     2352            jout("Write cache %sabled\n", (enable ? "en" : "dis"));
    23222353        any_output = true;
    23232354    }
    23242355
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    23292360        rcd = !enable;
    23302361        wce = -1;
    23312362        if (scsiGetSetCache(device, modese_len, &wce, &rcd)) {
    2332             pout("Read cache %sable failed: %s\n", (enable ? "en" : "dis"),
     2363            jout("Read cache %sable failed: %s\n", (enable ? "en" : "dis"),
    23332364                device->get_errmsg());
    23342365            failuretest(OPTIONAL_CMD,returnval |= FAILSMART);
    23352366        } else
    2336             pout("Read cache %sabled\n", (enable ? "en" : "dis"));
     2367            jout("Read cache %sabled\n", (enable ? "en" : "dis"));
    23372368        any_output = true;
    23382369    }
    23392370
    23402371    if (options.smart_auto_save_disable) {
    23412372        if (scsiSetControlGLTSD(device, 1, modese_len)) {
    2342             pout("Disable autosave (set GLTSD bit) failed\n");
     2373            jout("Disable autosave (set GLTSD bit) failed\n");
    23432374            failuretest(OPTIONAL_CMD,returnval |= FAILSMART);
    23442375        } else
    2345             pout("Autosave disabled (GLTSD bit set).\n");
     2376            jout("Autosave disabled (GLTSD bit set).\n");
    23462377        any_output = true;
    23472378    }
    23482379    if (options.smart_disable           || options.smart_enable ||
    23492380        options.smart_auto_save_disable || options.smart_auto_save_enable)
    2350         pout("\n"); // END OF THE ENABLE/DISABLE SECTION OF THE CODE
     2381        jout("\n"); // END OF THE ENABLE/DISABLE SECTION OF THE CODE
    23512382
    23522383    // START OF READ-ONLY OPTIONS APART FROM -V and -i
    23532384    if (options.smart_check_status  || options.smart_ss_media_log ||
    23542385        options.smart_vendor_attrib || options.smart_error_log ||
    23552386        options.smart_selftest_log  || options.smart_background_log ||
    23562387        options.sasphy)
    2357         pout("=== START OF READ SMART DATA SECTION ===\n");
     2388        jout("=== START OF READ SMART DATA SECTION ===\n");
    23582389
    23592390    if (options.smart_check_status) {
    23602391        scsiGetSupportedLogPages(device);
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    23622393        if (is_tape) {
    23632394            if (gTapeAlertsLPage) {
    23642395                if (options.drive_info)
    2365                     pout("TapeAlert Supported\n");
     2396                    jout("TapeAlert Supported\n");
    23662397                if (-1 == scsiGetTapeAlertsData(device, peripheral_type))
    23672398                    failuretest(OPTIONAL_CMD, returnval |= FAILSMART);
    23682399            }
    23692400            else
    2370                 pout("TapeAlert Not Supported\n");
     2401                jout("TapeAlert Not Supported\n");
    23712402        } else { /* disk, cd/dvd, enclosure, etc */
    23722403            if ((res = scsiGetSmartData(device,
    23732404                                        options.smart_vendor_attrib))) {
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    24172448        if (gPendDefectsLPage)
    24182449            scsiPrintPendingDefectsLPage(device);
    24192450        if (1 == scsiFetchControlGLTSD(device, modese_len, 1))
    2420             pout("\n[GLTSD (Global Logging Target Save Disable) set. "
     2451            jout("\n[GLTSD (Global Logging Target Save Disable) set. "
    24212452                 "Enable Save with '-S on']\n");
    24222453        any_output = true;
    24232454    }
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    24282459        if (gSelfTestLPage)
    24292460            res = scsiPrintSelfTest(device);
    24302461        else {
    2431             pout("Device does not support Self Test logging\n");
     2462            jout("Device does not support Self Test logging\n");
    24322463            failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
    24332464        }
    24342465        if (0 != res)
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    24422473        if (gBackgroundResultsLPage)
    24432474            res = scsiPrintBackgroundResults(device);
    24442475        else {
    2445             pout("Device does not support Background scan results logging\n");
     2476            jout("Device does not support Background scan results logging\n");
    24462477            failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
    24472478        }
    24482479        if (0 != res)
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    24522483    if (options.smart_default_selftest) {
    24532484        if (scsiSmartDefaultSelfTest(device))
    24542485            return returnval | FAILSMART;
    2455         pout("Default Self Test Successful\n");
     2486        jout("Default Self Test Successful\n");
    24562487        any_output = true;
    24572488    }
    24582489    if (options.smart_short_cap_selftest) {
    24592490        if (scsiSmartShortCapSelfTest(device))
    24602491            return returnval | FAILSMART;
    2461         pout("Short Foreground Self Test Successful\n");
     2492        jout("Short Foreground Self Test Successful\n");
    24622493        any_output = true;
    24632494    }
    24642495    // check if another test is running
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    24662497        if (!scsiRequestSense(device, &sense_info) &&
    24672498            (sense_info.asc == 0x04 && sense_info.ascq == 0x09)) {
    24682499            if (!options.smart_selftest_force) {
    2469                 pout("Can't start self-test without aborting current test");
     2500                jout("Can't start self-test without aborting current test");
    24702501                if (sense_info.progress != -1)
    2471                     pout(" (%d%% remaining)",
     2502                    jout(" (%d%% remaining)",
    24722503                         100 - sense_info.progress * 100 / 65535);
    2473                 pout(",\nadd '-t force' option to override, or run "
     2504                jout(",\nadd '-t force' option to override, or run "
    24742505                     "'smartctl -X' to abort test.\n");
    24752506                return -1;
    24762507            } else
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    24802511    if (options.smart_short_selftest) {
    24812512        if (scsiSmartShortSelfTest(device))
    24822513            return returnval | FAILSMART;
    2483         pout("Short Background Self Test has begun\n");
    2484         pout("Use smartctl -X to abort test\n");
     2514        jout("Short Background Self Test has begun\n");
     2515        jout("Use smartctl -X to abort test\n");
    24852516        any_output = true;
    24862517    }
    24872518    if (options.smart_extend_selftest) {
    24882519        if (scsiSmartExtendSelfTest(device))
    24892520            return returnval | FAILSMART;
    2490         pout("Extended Background Self Test has begun\n");
     2521        jout("Extended Background Self Test has begun\n");
    24912522        if ((0 == scsiFetchExtendedSelfTestTime(device, &durationSec,
    24922523                        modese_len)) && (durationSec > 0)) {
    24932524            time_t t = time(NULL);
    24942525
    24952526            t += durationSec;
    2496             pout("Please wait %d minutes for test to complete.\n",
     2527            jout("Please wait %d minutes for test to complete.\n",
    24972528                 durationSec / 60);
    2498             pout("Estimated completion time: %s\n", ctime(&t));
     2529            jout("Estimated completion time: %s\n", ctime(&t));
    24992530        }
    2500         pout("Use smartctl -X to abort test\n");
     2531        jout("Use smartctl -X to abort test\n");
    25012532        any_output = true;
    25022533    }
    25032534    if (options.smart_extend_cap_selftest) {
    25042535        if (scsiSmartExtendCapSelfTest(device))
    25052536            return returnval | FAILSMART;
    2506         pout("Extended Foreground Self Test Successful\n");
     2537        jout("Extended Foreground Self Test Successful\n");
    25072538    }
    25082539    if (options.smart_selftest_abort) {
    25092540        if (scsiSmartSelfTestAbort(device))
    25102541            return returnval | FAILSMART;
    2511         pout("Self Test returned without error\n");
     2542        jout("Self Test returned without error\n");
    25122543        any_output = true;
    25132544    }
    25142545    if (options.sasphy && gProtocolSpecificLPage) {
    scsiPrintMain(scsi_device * device, const scsi_print_options & options)  
    25182549    }
    25192550
    25202551    if (!any_output)
    2521         pout("SCSI device successfully opened\n\nUse 'smartctl -a' (or '-x') "
     2552        jout("SCSI device successfully opened\n\nUse 'smartctl -a' (or '-x') "
    25222553             "to print SMART (and more) information\n\n");
    25232554
    25242555    return returnval;