~ubuntu-branches/debian/stretch/sg3-utils/stretch

« back to all changes in this revision

Viewing changes to src/sg_sat_identify.c

  • Committer: Bazaar Package Importer
  • Author(s): Ritesh Raj Sarraf
  • Date: 2011-08-09 16:36:28 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110809163628-yh8okvhe20j5rekq
Tags: 1.32-1
* [06cef8d] Use kfreebsd-any as the build-dep.
  Thanks to Robert Millan (Closes: 634362)
* [850586d] separate build-arch and build-indep targets
* [a432747] Drop duplicate changelog
* [ec2bbd8] Update Standards Version to 3.9.2. No changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2006-2010 Douglas Gilbert.
 
2
 * Copyright (c) 2006-2011 Douglas Gilbert.
3
3
 * All rights reserved.
4
4
 * Use of this source code is governed by a BSD-style
5
5
 * license that can be found in the BSD_LICENSE file.
11
11
#include <stdlib.h>
12
12
#include <string.h>
13
13
#include <getopt.h>
 
14
#define __STDC_FORMAT_MACROS 1
 
15
#include <inttypes.h>
14
16
 
15
17
#ifdef HAVE_CONFIG_H
16
18
#include "config.h"
19
21
#include "sg_cmds_basic.h"
20
22
#include "sg_cmds_extra.h"
21
23
 
22
 
/* This program uses a ATA PASS-THROUGH SCSI command to package
23
 
   an ATA IDENTIFY (PACKAGE) DEVICE command. See http://www.t10.org
24
 
   for the most recent SAT: sat-r09.pdf . SAT is now a standard:
25
 
   SAT ANSI INCITS 431-2007.
26
 
 
27
 
*/
 
24
/* This program uses a ATA PASS-THROUGH SCSI command to package an
 
25
 * ATA IDENTIFY (PACKAGE) DEVICE command. It is based on the SCSI to
 
26
 * ATA Translation (SAT) drafts and standards. See http://www.t10.org
 
27
 * for drafts. SAT is a standard: SAT ANSI INCITS 431-2007 (draft prior
 
28
 * to that is sat-r09.pdf). SAT-2 is also a standard: SAT-2 ANSI INCITS
 
29
 * 465-2010 and the draft prior to that is sat2r09.pdf . The SAT-3
 
30
 * project has started and the most recent draft is sat3r01.pdf .
 
31
 */
28
32
 
29
33
#define SAT_ATA_PASS_THROUGH16 0x85
30
34
#define SAT_ATA_PASS_THROUGH16_LEN 16
41
45
 
42
46
#define EBUFF_SZ 256
43
47
 
44
 
static char * version_str = "1.06 20100312";
 
48
static char * version_str = "1.08 20110513";
45
49
 
46
50
static struct option long_options[] = {
47
51
        {"ck_cond", no_argument, 0, 'c'},
49
53
        {"help", no_argument, 0, 'h'},
50
54
        {"hex", no_argument, 0, 'H'},
51
55
        {"len", required_argument, 0, 'l'},
 
56
        {"ident", no_argument, 0, 'i'},
52
57
        {"packet", no_argument, 0, 'p'},
53
58
        {"raw", no_argument, 0, 'r'},
54
59
        {"verbose", no_argument, 0, 'v'},
60
65
{
61
66
    fprintf(stderr, "Usage: "
62
67
          "sg_sat_identify [--ck_cond] [--extend] [--help] [--hex] "
63
 
          "[--len=16|12]\n"
64
 
          "                       [--packet] [--raw] [--verbose] [--version] "
65
 
          "DEVICE\n"
 
68
          "[--ident]\n"
 
69
          "                       [--len=16|12] [--packet] [--raw] "
 
70
          "[--verbose]\n"
 
71
          "                       [--version] DEVICE\n"
66
72
          "  where:\n"
67
73
          "    --ck_cond|-c     sets ck_cond bit in cdb (def: 0)\n"
68
74
          "    --extend|-e      sets extend bit in cdb (def: 0)\n"
69
75
          "    --help|-h        print out usage message then exit\n"
70
76
          "    --hex|-H         output response in hex\n"
 
77
          "    --ident|-i       output WWN prefixed by 0x, if not available "
 
78
          "output\n"
 
79
          "                     0x0000000000000000\n"
71
80
          "    --len=16|12 | -l 16|12    cdb length: 16 or 12 bytes "
72
81
          "(default: 16)\n"
73
82
          "    --packet|-p      do IDENTIFY PACKET DEVICE (def: IDENTIFY "
88
97
}
89
98
 
90
99
static int do_identify_dev(int sg_fd, int do_packet, int cdb_len,
91
 
                           int ck_cond, int extend, int do_hex, int do_raw,
92
 
                           int verbose)
 
100
                           int ck_cond, int extend, int do_indent,
 
101
                           int do_hex, int do_raw, int verbose)
93
102
{
94
 
    int ok, res, ret;
 
103
    int ok, j, res, ret;
95
104
    int protocol = 4;   /* PIO data-in */
96
105
    int t_dir = 1;      /* 0 -> to device, 1 -> from device */
97
106
    int byte_block = 1; /* 0 -> bytes, 1 -> 512 byte blocks */
109
118
    unsigned char apt12CmdBlk[SAT_ATA_PASS_THROUGH12_LEN] =
110
119
                {SAT_ATA_PASS_THROUGH12, 0, 0, 0, 0, 0, 0, 0,
111
120
                 0, 0, 0, 0};
 
121
    const unsigned short * usp;
 
122
    uint64_t ull;
112
123
 
113
124
    sb_sz = sizeof(sense_buffer);
114
125
    memset(sense_buffer, 0, sb_sz);
244
255
        if (do_raw)
245
256
            dStrRaw((const char *)inBuff, 512);
246
257
        else if (0 == do_hex) {
247
 
            printf("Response for IDENTIFY %sDEVICE ATA command:\n",
248
 
                   (do_packet ? "PACKET " : ""));
249
 
            dWordHex((const unsigned short *)inBuff, 256, 0,
250
 
                     sg_is_big_endian());
 
258
            if (do_indent) {
 
259
                usp = (const unsigned short *)inBuff;
 
260
                ull = 0;
 
261
                for (j = 0; j < 4; ++j) {
 
262
                    if (j > 0)
 
263
                        ull <<= 16;
 
264
                    ull |= usp[108 + j];
 
265
                }
 
266
                printf("0x%016" PRIx64 "\n", ull);
 
267
            } else {
 
268
                printf("Response for IDENTIFY %sDEVICE ATA command:\n",
 
269
                       (do_packet ? "PACKET " : ""));
 
270
                dWordHex((const unsigned short *)inBuff, 256, 0,
 
271
                         sg_is_big_endian());
 
272
            }
251
273
        } else if (1 == do_hex)
252
274
            dStrHex((const char *)inBuff, 512, 0);
253
275
        else if (2 == do_hex)
267
289
    int cdb_len = SAT_ATA_PASS_THROUGH16_LEN;
268
290
    int do_packet = 0;
269
291
    int do_hex = 0;
 
292
    int do_indent = 0;
270
293
    int do_raw = 0;
271
294
    int verbose = 0;
272
295
    int ck_cond = 0;   /* set to 1 to read register(s) back */
276
299
    while (1) {
277
300
        int option_index = 0;
278
301
 
279
 
        c = getopt_long(argc, argv, "cehHl:prvV", long_options,
 
302
        c = getopt_long(argc, argv, "cehHil:prvV", long_options,
280
303
                        &option_index);
281
304
        if (c == -1)
282
305
            break;
295
318
        case 'H':
296
319
            ++do_hex;
297
320
            break;
 
321
        case 'i':
 
322
            ++do_indent;
 
323
            break;
298
324
        case 'l':
299
325
           cdb_len = sg_get_num(optarg);
300
326
           if (! ((cdb_len == 12) || (cdb_len == 16))) {
354
380
    }
355
381
 
356
382
    ret = do_identify_dev(sg_fd, do_packet, cdb_len, ck_cond, extend,
357
 
                          do_hex, do_raw, verbose);
 
383
                          do_indent, do_hex, do_raw, verbose);
358
384
 
359
385
    res = sg_cmds_close_device(sg_fd);
360
386
    if (res < 0) {