src/sg_logs.c
static bool
show_background_scan_results_page(const uint8_t * resp, int len,
                                  const struct opts_t * op)
{
    int j, m, num, pl, pc, pcb;
    const uint8_t * ucp;
    char str[PCB_STR_LEN];

    if (op->verbose || ((0 == op->do_raw) && (0 == op->do_hex)))
        printf("Background scan results page  [0x15]\n");
    num = len - 4;
    ucp = &resp[0] + 4;
    while (num > 3) {
        pc = (ucp[0] << 8) | ucp[1];
        pcb = ucp[2];
        pl = ucp[3] + 4;
        if (op->filter_given) {
            if (pc != op->filter)
                goto skip;
            if (op->do_raw) {
                dStrRaw((const char *)ucp, pl);
                break;
            } else if (op->do_hex) {
                dStrHex((const char *)ucp, pl, ((1 == op->do_hex) ? 1 : -1));
                break;
            }
        }
        switch (pc) {
        case 0:
            printf("  Status parameters:\n");
            if ((pl < 16) || (num < 16)) {
                if (num < 16)
                    pr2serr("    truncated by response length, expected at "
                            "least 16 bytes\n");
                else
                    pr2serr("    parameter length >= 16 expected, got %d\n",
                            pl);
                break;
            }
            printf("    Accumulated power on minutes: ");
            j = (ucp[4] << 24) + (ucp[5] << 16) + (ucp[6] << 8) + ucp[7];
            printf("%d [h:m  %d:%d]\n", j, (j / 60), (j % 60));
            printf("    Status: ");
            j = ucp[9];
            if (j < (int)(sizeof(bms_status) / sizeof(bms_status[0])))
                printf("%s\n", bms_status[j]);
            else
                printf("unknown [0x%x] background scan status value\n", j);
            j = (ucp[10] << 8) + ucp[11];
            printf("    Number of background scans performed: %d\n", j);
            j = (ucp[12] << 8) + ucp[13];
#ifdef SG_LIB_MINGW
            printf("    Background medium scan progress: %g%%\n",
                   (double)(j * 100.0 / 65536.0));
#else
            printf("    Background medium scan progress: %.2f%%\n",
                   (double)(j * 100.0 / 65536.0));
#endif
            j = (ucp[14] << 8) + ucp[15];
            if (0 == j)
                printf("    Number of background medium scans performed: 0 "
                       "[not reported]\n");
            else
                printf("    Number of background medium scans performed: "
                       "%d\n", j);
            break;
        default:
            if (pc > 0x800) {
                if ((pc >= 0x8000) && (pc <= 0xafff))
                    printf("  Medium scan parameter # %d [0x%x], vendor "
                           "specific\n", pc, pc);
                else
                    printf("  Medium scan parameter # %d [0x%x], "
                           "reserved\n", pc, pc);
                dStrHex((const char *)ucp, ((pl < num) ? pl : num), 0);
                break;
            } else
                printf("  Medium scan parameter # %d [0x%x]\n", pc, pc);
            if ((pl < 24) || (num < 24)) {
                if (num < 24)
                    pr2serr("    truncated by response length, expected at "
                            "least 24 bytes\n");
                else
                    pr2serr("    parameter length >= 24 expected, got %d\n",
                            pl);
                break;
            }
            printf("    Power on minutes when error detected: ");
            j = (ucp[4] << 24) + (ucp[5] << 16) + (ucp[6] << 8) + ucp[7];
            printf("%d [%d:%d]\n", j, (j / 60), (j % 60));
            j = (ucp[8] >> 4) & 0xf;
            if (j <
                (int)(sizeof(reassign_status) / sizeof(reassign_status[0])))
                printf("    %s\n", reassign_status[j]);
            else
                printf("    Reassign status: reserved [0x%x]\n", j);
            printf("    sense key: %s  [sk,asc,ascq: 0x%x,0x%x,0x%x]\n",
                   sg_get_sense_key_str(ucp[8] & 0xf, sizeof(str), str),
                   ucp[8] & 0xf, ucp[9], ucp[10]);
            if (ucp[9] || ucp[10])
                printf("      %s\n", sg_get_asc_ascq_str(ucp[9], ucp[10],
                                                         sizeof(str), str));
            if (op->verbose) {
                printf("    vendor bytes [11 -> 15]: ");
                for (m = 0; m < 5; ++m)
                    printf("0x%02x ", ucp[11 + m]);
                printf("\n");
            }
            printf("    LBA (associated with medium error): 0x");
            for (m = 0; m < 8; ++m)
                printf("%02x", ucp[16 + m]);
            printf("\n");
            break;
        }
        if (op->do_pcb) {
            get_pcb_str(pcb, str, sizeof(str));
            printf("        <%s>\n", str);
        }
        if (op->filter_given)
            break;
skip:
        num -= pl;
        ucp += pl;
    }
    return true;
}
/* Background scan results [0x15,0] for disk  introduced: SBC-3 */
Background scan results [0x15,0] for disk  introduced: SBC-3
Background scan results [ 0x15 0 ] for disk introduced : SBC - 3
static bool
show_background_scan_results_page(const uint8_t * resp, int len,
                                  const struct opts_t * op)
{
    int j, m, num, pl, pc, pcb;
    const uint8_t * ucp;
    char str[PCB_STR_LEN];
    if (op->verbose || ((0 == op->do_raw) && (0 == op->do_hex)))
        printf("Background scan results page  [0x15]\n");
    num = len - 4;
    ucp = &resp[0] + 4;
    while (num > 3) {
        pc = (ucp[0] << 8) | ucp[1];
        pcb = ucp[2];
        pl = ucp[3] + 4;
        if (op->filter_given) {
            if (pc != op->filter)
                goto skip;
            if (op->do_raw) {
                dStrRaw((const char *)ucp, pl);
                break;
            } else if (op->do_hex) {
                dStrHex((const char *)ucp, pl, ((1 == op->do_hex) ? 1 : -1));
                break;
            }
        }
        switch (pc) {
        case 0:
            printf("  Status parameters:\n");
            if ((pl < 16) || (num < 16)) {
                if (num < 16)
                    pr2serr("    truncated by response length, expected at "
                            "least 16 bytes\n");
                else
                    pr2serr("    parameter length >= 16 expected, got %d\n",
                            pl);
                break;
            }
            printf("    Accumulated power on minutes: ");
            j = (ucp[4] << 24) + (ucp[5] << 16) + (ucp[6] << 8) + ucp[7];
            printf("%d [h:m  %d:%d]\n", j, (j / 60), (j % 60));
            printf("    Status: ");
            j = ucp[9];
            if (j < (int)(sizeof(bms_status) / sizeof(bms_status[0])))
                printf("%s\n", bms_status[j]);
            else
                printf("unknown [0x%x] background scan status value\n", j);
            j = (ucp[10] << 8) + ucp[11];
            printf("    Number of background scans performed: %d\n", j);
            j = (ucp[12] << 8) + ucp[13];
#ifdef SG_LIB_MINGW
            printf("    Background medium scan progress: %g%%\n",
                   (double)(j * 100.0 / 65536.0));
#else
            printf("    Background medium scan progress: %.2f%%\n",
                   (double)(j * 100.0 / 65536.0));
#endif
            j = (ucp[14] << 8) + ucp[15];
            if (0 == j)
                printf("    Number of background medium scans performed: 0 "
                       "[not reported]\n");
            else
                printf("    Number of background medium scans performed: "
                       "%d\n", j);
            break;
        default:
            if (pc > 0x800) {
                if ((pc >= 0x8000) && (pc <= 0xafff))
                    printf("  Medium scan parameter # %d [0x%x], vendor "
                           "specific\n", pc, pc);
                else
                    printf("  Medium scan parameter # %d [0x%x], "
                           "reserved\n", pc, pc);
                dStrHex((const char *)ucp, ((pl < num) ? pl : num), 0);
                break;
            } else
                printf("  Medium scan parameter # %d [0x%x]\n", pc, pc);
            if ((pl < 24) || (num < 24)) {
                if (num < 24)
                    pr2serr("    truncated by response length, expected at "
                            "least 24 bytes\n");
                else
                    pr2serr("    parameter length >= 24 expected, got %d\n",
                            pl);
                break;
            }
            printf("    Power on minutes when error detected: ");
            j = (ucp[4] << 24) + (ucp[5] << 16) + (ucp[6] << 8) + ucp[7];
            printf("%d [%d:%d]\n", j, (j / 60), (j % 60));
            j = (ucp[8] >> 4) & 0xf;
            if (j <
                (int)(sizeof(reassign_status) / sizeof(reassign_status[0])))
                printf("    %s\n", reassign_status[j]);
            else
                printf("    Reassign status: reserved [0x%x]\n", j);
            printf("    sense key: %s  [sk,asc,ascq: 0x%x,0x%x,0x%x]\n",
                   sg_get_sense_key_str(ucp[8] & 0xf, sizeof(str), str),
                   ucp[8] & 0xf, ucp[9], ucp[10]);
            if (ucp[9] || ucp[10])
                printf("      %s\n", sg_get_asc_ascq_str(ucp[9], ucp[10],
                                                         sizeof(str), str));
            if (op->verbose) {
                printf("    vendor bytes [11 -> 15]: ");
                for (m = 0; m < 5; ++m)
                    printf("0x%02x ", ucp[11 + m]);
                printf("\n");
            }
            printf("    LBA (associated with medium error): 0x");
            for (m = 0; m < 8; ++m)
                printf("%02x", ucp[16 + m]);
            printf("\n");
            break;
        }
        if (op->do_pcb) {
            get_pcb_str(pcb, str, sizeof(str));
            printf("        <%s>\n", str);
        }
        if (op->filter_given)
            break;
skip:
        num -= pl;
        ucp += pl;
    }
    return true;
}
static bool show_background_scan_results_page ( const uint8_t * resp , int len , const struct opts_t * op ) { int j , m , num , pl , pc , pcb ; const uint8_t * ucp ; char str [ PCB_STR_LEN ] ; if ( op -> verbose || ( ( 0 == op -> do_raw ) && ( 0 == op -> do_hex ) ) ) printf ( " \n " ) ; num = len - 4 ; ucp = & resp [ 0 ] + 4 ; while ( num > 3 ) { pc = ( ucp [ 0 ] << 8 ) | ucp [ 1 ] ; pcb = ucp [ 2 ] ; pl = ucp [ 3 ] + 4 ; if ( op -> filter_given ) { if ( pc != op -> filter ) goto skip ; if ( op -> do_raw ) { dStrRaw ( ( const char * ) ucp , pl ) ; break ; } else if ( op -> do_hex ) { dStrHex ( ( const char * ) ucp , pl , ( ( 1 == op -> do_hex ) ? 1 : -1 ) ) ; break ; } } switch ( pc ) { case 0 : printf ( " \n " ) ; if ( ( pl < 16 ) || ( num < 16 ) ) { if ( num < 16 ) pr2serr ( " " " \n " ) ; else pr2serr ( " \n " , pl ) ; break ; } printf ( " " ) ; j = ( ucp [ 4 ] << 24 ) + ( ucp [ 5 ] << 16 ) + ( ucp [ 6 ] << 8 ) + ucp [ 7 ] ; printf ( " \n " , j , ( j / 60 ) , ( j % 60 ) ) ; printf ( " " ) ; j = ucp [ 9 ] ; if ( j < ( int ) ( sizeof ( bms_status ) / sizeof ( bms_status [ 0 ] ) ) ) printf ( " \n " , bms_status [ j ] ) ; else printf ( " \n " , j ) ; j = ( ucp [ 10 ] << 8 ) + ucp [ 11 ] ; printf ( " \n " , j ) ; j = ( ucp [ 12 ] << 8 ) + ucp [ 13 ] ; #ifdef SG_LIB_MINGW printf ( " \n " , ( double ) ( j * 100.0 / 65536.0 ) ) ; #else printf ( " \n " , ( double ) ( j * 100.0 / 65536.0 ) ) ; #endif j = ( ucp [ 14 ] << 8 ) + ucp [ 15 ] ; if ( 0 == j ) printf ( " " " \n " ) ; else printf ( " " " \n " , j ) ; break ; default : if ( pc > 0x800 ) { if ( ( pc >= 0x8000 ) && ( pc <= 0xafff ) ) printf ( " " " \n " , pc , pc ) ; else printf ( " " " \n " , pc , pc ) ; dStrHex ( ( const char * ) ucp , ( ( pl < num ) ? pl : num ) , 0 ) ; break ; } else printf ( " \n " , pc , pc ) ; if ( ( pl < 24 ) || ( num < 24 ) ) { if ( num < 24 ) pr2serr ( " " " \n " ) ; else pr2serr ( " \n " , pl ) ; break ; } printf ( " " ) ; j = ( ucp [ 4 ] << 24 ) + ( ucp [ 5 ] << 16 ) + ( ucp [ 6 ] << 8 ) + ucp [ 7 ] ; printf ( " \n " , j , ( j / 60 ) , ( j % 60 ) ) ; j = ( ucp [ 8 ] >> 4 ) & 0xf ; if ( j < ( int ) ( sizeof ( reassign_status ) / sizeof ( reassign_status [ 0 ] ) ) ) printf ( " \n " , reassign_status [ j ] ) ; else printf ( " \n " , j ) ; printf ( " \n " , sg_get_sense_key_str ( ucp [ 8 ] & 0xf , sizeof ( str ) , str ) , ucp [ 8 ] & 0xf , ucp [ 9 ] , ucp [ 10 ] ) ; if ( ucp [ 9 ] || ucp [ 10 ] ) printf ( " \n " , sg_get_asc_ascq_str ( ucp [ 9 ] , ucp [ 10 ] , sizeof ( str ) , str ) ) ; if ( op -> verbose ) { printf ( " " ) ; for ( m = 0 ; m < 5 ; ++ m ) printf ( " " , ucp [ 11 + m ] ) ; printf ( " \n " ) ; } printf ( " " ) ; for ( m = 0 ; m < 8 ; ++ m ) printf ( " " , ucp [ 16 + m ] ) ; printf ( " \n " ) ; break ; } if ( op -> do_pcb ) { get_pcb_str ( pcb , str , sizeof ( str ) ) ; printf ( " \n " , str ) ; } if ( op -> filter_given ) break ; skip : num -= pl ; ucp += pl ; } return true ; }
Background scan results [0x15,0] for disk  introduced: SBC-3
Background scan results [ 0x15 0 ] for disk introduced : SBC - 3