| File: | satacmds.c |
| Location: | line 95, column 3 |
| Description: | Value stored to 'p' is never read |
| 1 | /* |
| 2 | * Copyright (C) 2002 Emmanuel VARAGNAT <hddtemp@guzu.net> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | // Include file generated by ./configure |
| 20 | #ifdef HAVE_CONFIG_H1 |
| 21 | #include <config.h> |
| 22 | #endif |
| 23 | |
| 24 | // Gettext includes |
| 25 | #if ENABLE_NLS1 |
| 26 | #include <libintl.h> |
| 27 | #define _(String)dcgettext (((void*)0), String, 5) gettext (String)dcgettext (((void*)0), String, 5) |
| 28 | #else |
| 29 | #define _(String)dcgettext (((void*)0), String, 5) (String) |
| 30 | #endif |
| 31 | |
| 32 | // Standard includes |
| 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
| 36 | #include <unistd.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <errno(*__errno_location ()).h> |
| 39 | #include <sys/ioctl.h> |
| 40 | #include <scsi/sg.h> |
| 41 | #include <linux1/hdreg.h> |
| 42 | #include <byteswap.h> |
| 43 | |
| 44 | // Application specific includes |
| 45 | #include "satacmds.h" |
| 46 | #include "scsicmds.h" |
| 47 | |
| 48 | #ifndef ATA_160x85 |
| 49 | /* Values for T10/04-262r7 */ |
| 50 | #define ATA_160x85 0x85 /* 16-byte pass-thru */ |
| 51 | #endif |
| 52 | |
| 53 | int sata_pass_thru(int device, unsigned char *cmd, unsigned char *buffer) { |
| 54 | unsigned char cdb[16]; |
| 55 | unsigned char sense[32]; |
| 56 | int dxfer_direction; |
| 57 | int ret; |
| 58 | |
| 59 | memset(cdb, 0, sizeof(cdb)); |
| 60 | cdb[0] = ATA_160x85; |
| 61 | if (cmd[3]) { |
| 62 | cdb[1] = (4 << 1); /* PIO Data-in */ |
| 63 | cdb[2] = 0x2e; /* no off.line, cc, read from dev, lock count in sector count field */ |
| 64 | dxfer_direction = SG_DXFER_FROM_DEV-3; |
| 65 | } else { |
| 66 | cdb[1] = (3 << 1); /* Non-data */ |
| 67 | cdb[2] = 0x20; /* cc */ |
| 68 | dxfer_direction = SG_DXFER_NONE-1; |
| 69 | } |
| 70 | cdb[4] = cmd[2]; |
| 71 | if (cmd[0] == WIN_SMART0xB0) { |
| 72 | cdb[6] = cmd[3]; |
| 73 | cdb[8] = cmd[1]; |
| 74 | cdb[10] = 0x4f; |
| 75 | cdb[12] = 0xc2; |
| 76 | } |
| 77 | else |
| 78 | cdb[6] = cmd[1]; |
| 79 | cdb[14] = cmd[0]; |
| 80 | |
| 81 | ret = scsi_SG_IO(device, cdb, sizeof(cdb), buffer, cmd[3] * 512, sense, sizeof(sense), dxfer_direction); |
| 82 | |
| 83 | /* Verify SATA magic */ |
| 84 | if (sense[0] != 0x72) |
| 85 | return 1; |
| 86 | else |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | void sata_fixstring(unsigned char *s, int bytecount) |
| 91 | { |
| 92 | unsigned char *p; |
| 93 | unsigned char *end; |
| 94 | |
| 95 | p = s; |
Value stored to 'p' is never read | |
| 96 | end = &s[bytecount & ~1]; /* bytecount must be even */ |
| 97 | |
| 98 | /* convert from big-endian to string order */ |
| 99 | for (p = end ; p != s;) { |
| 100 | unsigned short *pp = (unsigned short *) (p -= 2); |
| 101 | *pp = bswap_16(*pp)(__extension__ ({ unsigned short int __v, __x = (unsigned short int) (*pp); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff ) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })); |
| 102 | } |
| 103 | |
| 104 | /* strip leading blanks */ |
| 105 | while (s != end && *s == ' ') |
| 106 | ++s; |
| 107 | /* compress internal blanks and strip trailing blanks */ |
| 108 | while (s != end && *s) { |
| 109 | if (*s++ != ' ' || (s != end && *s && *s != ' ')) |
| 110 | *p++ = *(s-1); |
| 111 | } |
| 112 | /* wipe out trailing garbage */ |
| 113 | while (p != end) |
| 114 | *p++ = '\0'; |
| 115 | } |
| 116 | |
| 117 | int sata_enable_smart(int device) { |
| 118 | unsigned char cmd[4] = { WIN_SMART0xB0, 0, SMART_ENABLE0xD8, 0 }; |
| 119 | |
| 120 | return sata_pass_thru(device, cmd, NULL((void*)0)); |
| 121 | } |
| 122 | |
| 123 | int sata_get_smart_values(int device, unsigned char* buff) { |
| 124 | unsigned char cmd[4] = { WIN_SMART0xB0, 0, SMART_READ_VALUES0xD0, 1 }; |
| 125 | |
| 126 | return sata_pass_thru(device, cmd, buff); |
| 127 | } |
| 128 |