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

« back to all changes in this revision

Viewing changes to examples/sg_sat_chk_power.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2006-2007 Douglas Gilbert.
 
2
 * Copyright (c) 2006-2012 Douglas Gilbert.
3
3
 * All rights reserved.
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
50
50
#define SAT_ATA_PASS_THROUGH16 0x85
51
51
#define SAT_ATA_PASS_THROUGH16_LEN 16
52
52
#define SAT_ATA_RETURN_DESC 9  /* ATA Return (sense) Descriptor */
 
53
#define ASCQ_ATA_PT_INFO_AVAILABLE 0x1d
53
54
 
54
55
#define ATA_CHECK_POWER_MODE 0xe5
55
56
 
56
57
#define EBUFF_SZ 256
57
58
 
58
 
static char * version_str = "1.03 20070129";
 
59
static const char * version_str = "1.04 20120319";
 
60
 
 
61
 
 
62
#if 0
 
63
/* Returns length of decoded fixed format sense for SAT ATA pass-through
 
64
 * command, else returns 0. If returns 0 (expected sense data not found)
 
65
 * then '\0' placed in first byte of bp. */
 
66
static int
 
67
sg_sat_decode_fixed_sense(const unsigned char * sp, int slen, char * bp,
 
68
                          int max_blen, int verbose)
 
69
{
 
70
    int n;
 
71
 
 
72
    if ((NULL == bp) || (NULL == sp) || (max_blen < 1) || (slen < 14))
 
73
        return 0;
 
74
    bp[0] = '\0';
 
75
    if ((0x70 != (0x7f & sp[0])) ||
 
76
        (SPC_SK_RECOVERED_ERROR != (0xf & sp[2])) ||
 
77
        (0 != sp[12]) || (ASCQ_ATA_PT_INFO_AVAILABLE != sp[13]))
 
78
        return 0;
 
79
    n = snprintf(bp, max_blen, "error=0x%x, status=0x%x, device=0x%x, "
 
80
                 "sector_count(7:0)=0x%x%c\n", sp[3], sp[4], sp[5], sp[6],
 
81
                 ((0x40 & sp[8]) ? '+' : ' '));
 
82
    if (n >= max_blen)
 
83
        return max_blen - 1;
 
84
    n += snprintf(bp + n, max_blen - n, "extend=%d, log_index=0x%x, "
 
85
                  "lba_high,mid,low(7:0)=0x%x,0x%x,0x%x%c\n",
 
86
                  (!!(0x80 & sp[8])), (0xf & sp[8]), sp[9], sp[10], sp[11],
 
87
                  ((0x20 & sp[8]) ? '+' : ' '));
 
88
    if (n >= max_blen)
 
89
        return max_blen - 1;
 
90
    if (verbose)
 
91
        n += snprintf(bp + n, max_blen - n, "  sector_count_upper_nonzero="
 
92
                      "%d, lba_upper_nonzero=%d\n", !!(0x40 & sp[8]),
 
93
                      !!(0x20 & sp[8]));
 
94
    return (n >= max_blen) ? max_blen - 1 : n;
 
95
}
 
96
#endif
59
97
 
60
98
int main(int argc, char * argv[])
61
99
{