Skip to content
Snippets Groups Projects
Commit f7ee52bc authored by ballen4705's avatar ballen4705
Browse files

Minor cleanup

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@38 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent a522417f
No related branches found
No related tags found
No related merge requests found
# Makefile for smartmontools
#
# $Id: Makefile,v 1.12 2002/10/11 12:48:27 ballen4705 Exp $
# $Id: Makefile,v 1.13 2002/10/13 13:10:56 ballen4705 Exp $
#
# Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
#
......@@ -14,8 +14,8 @@
# Mass Ave, Cambridge, MA 02139, USA.
CC = gcc
# CFLAGS = -fsigned-char -Wall -g
CFLAGS = -fsigned-char -Wall -O2
CFLAGS = -fsigned-char -Wall -g
# CFLAGS = -fsigned-char -Wall -O2
releasefiles=atacmds.c atacmds.h ataprint.c ataprint.h CHANGELOG COPYING extern.h Makefile\
README scsicmds.c scsicmds.h scsiprint.c scsiprint.h smartctl.8 smartctl.c smartctl.h\
......
3
5
// $Id: atacmds.c,v 1.3 2002/10/12 11:10:01 ballen4705 Exp $
// $Id: atacmds.c,v 1.4 2002/10/13 13:10:56 ballen4705 Exp $
/*
* atacmds.c
*
......@@ -22,7 +22,8 @@
#include "atacmds.h"
// Drive identity stuff shamelessly ripped from hdparm 5.2
// These Drive Identity tables are taken from hdparm 5.2. That's the
// "Gold Standard"
#define NOVAL_0 0x0000
#define NOVAL_1 0xffff
/* word 81: minor version number */
......@@ -159,38 +160,30 @@ int ataSmartSupport ( struct hd_driveid drive){
return 0;
}
int ataReadSmartValues (int device, struct ata_smart_values *data)
{
int ataReadSmartValues (int device, struct ata_smart_values *data){
int i;
unsigned char chksum;
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
unsigned char chksum=0;
unsigned char buf[HDIO_DRIVE_CMD_HDR_SIZE+ATA_SMART_SEC_SIZE]=
{WIN_SMART, 0, SMART_READ_VALUES, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
if (ioctl(device,HDIO_DRIVE_CMD,buf)){
perror ("Smart Values Read failed");
return -1;
}
chksum = 0;
for ( i = HDIO_DRIVE_CMD_HDR_SIZE;
i < ATA_SMART_SEC_SIZE + HDIO_DRIVE_CMD_HDR_SIZE;
i++ )
chksum += buf[i];
// compute checksum
for (i=0;i<ATA_SMART_SEC_SIZE;i++)
chksum+=buf[i+HDIO_DRIVE_CMD_HDR_SIZE];
if ( (unsigned char) chksum != 0)
{
perror ("Smart Read Failed, Chksum error");
// verify that checksum vanishes
if (chksum){
perror ("Smart Read Failed, Checksum error!");
return -1;
}
memcpy( data,
&buf[HDIO_DRIVE_CMD_HDR_SIZE] ,
ATA_SMART_SEC_SIZE );
// copy data and return
memcpy(data,buf+HDIO_DRIVE_CMD_HDR_SIZE,ATA_SMART_SEC_SIZE);
return 0;
}
......@@ -369,8 +362,9 @@ int ataDisableAutoOffline (int device )
}
int ataSmartStatus (int device )
{
// Not being used correctly. Must examine the CL and CH registers to
// see what the smart status was. How to fix this? I don't know...
int ataSmartStatus (int device ){
unsigned char parms[4] = { WIN_SMART, 0, SMART_STATUS, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms) != 0)
......
// $Id: atacmds.cpp,v 1.3 2002/10/12 11:10:01 ballen4705 Exp $
// $Id: atacmds.cpp,v 1.4 2002/10/13 13:10:56 ballen4705 Exp $
/*
* atacmds.c
*
......@@ -22,7 +22,8 @@
#include "atacmds.h"
// Drive identity stuff shamelessly ripped from hdparm 5.2
// These Drive Identity tables are taken from hdparm 5.2. That's the
// "Gold Standard"
#define NOVAL_0 0x0000
#define NOVAL_1 0xffff
/* word 81: minor version number */
......@@ -159,38 +160,30 @@ int ataSmartSupport ( struct hd_driveid drive){
return 0;
}
int ataReadSmartValues (int device, struct ata_smart_values *data)
{
int ataReadSmartValues (int device, struct ata_smart_values *data){
int i;
unsigned char chksum;
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
unsigned char chksum=0;
unsigned char buf[HDIO_DRIVE_CMD_HDR_SIZE+ATA_SMART_SEC_SIZE]=
{WIN_SMART, 0, SMART_READ_VALUES, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
if (ioctl(device,HDIO_DRIVE_CMD,buf)){
perror ("Smart Values Read failed");
return -1;
}
chksum = 0;
for ( i = HDIO_DRIVE_CMD_HDR_SIZE;
i < ATA_SMART_SEC_SIZE + HDIO_DRIVE_CMD_HDR_SIZE;
i++ )
chksum += buf[i];
// compute checksum
for (i=0;i<ATA_SMART_SEC_SIZE;i++)
chksum+=buf[i+HDIO_DRIVE_CMD_HDR_SIZE];
if ( (unsigned char) chksum != 0)
{
perror ("Smart Read Failed, Chksum error");
// verify that checksum vanishes
if (chksum){
perror ("Smart Read Failed, Checksum error!");
return -1;
}
memcpy( data,
&buf[HDIO_DRIVE_CMD_HDR_SIZE] ,
ATA_SMART_SEC_SIZE );
// copy data and return
memcpy(data,buf+HDIO_DRIVE_CMD_HDR_SIZE,ATA_SMART_SEC_SIZE);
return 0;
}
......@@ -369,8 +362,9 @@ int ataDisableAutoOffline (int device )
}
int ataSmartStatus (int device )
{
// Not being used correctly. Must examine the CL and CH registers to
// see what the smart status was. How to fix this? I don't know...
int ataSmartStatus (int device ){
unsigned char parms[4] = { WIN_SMART, 0, SMART_STATUS, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms) != 0)
......
// $Id: atacmds.h,v 1.9 2002/10/12 11:10:01 ballen4705 Exp $
// $Id: atacmds.h,v 1.10 2002/10/13 13:10:56 ballen4705 Exp $
/*
* atacmds.h
*
......@@ -114,8 +114,13 @@ struct ata_smart_attribute {
union {
unsigned short all;
struct {
unsigned prefailure:1;
unsigned online:1;
unsigned prefailure:1; // 0=> low attribute from age/usage
// exceeding design limit,
// 1==prefailure
unsigned online:1; // 0==> attribute only updated during
// off-line testing. 1==>only updated
// during on-line testing
unsigned performance:1;
unsigned errorrate:1;
unsigned eventcount:1 ;
......@@ -130,6 +135,24 @@ struct ata_smart_attribute {
} __attribute__ ((packed));
// What follows is the ATA/ATAPI-4 Rev 13 data structure equivalent:
// Table 23 DEVICE SMART DATA STRUCTURE
#if 0
struct ata_smart_values {
unsigned short int revnumber;
struct ata_smart_attribute vendor_attributes [NUMBER_ATA_SMART_ATTRIBUTES];
unsigned char offline_data_collection_status;
unsigned char vendor_specific_363; //IBM # segments for offline collection
unsigned short int total_time_to_complete_off_line; // IBM different
unsigned char vendor_specific_366; // IBM curent segment pointer
unsigned char offline_data_collection_capability;
unsigned short int smart_capability;
unsigned char reserved_370_385;;
unsigned char vendor_specific_386-510; // IBM: self-test failure checkpoint
unsigned char chksum;
} __attribute__ ((packed));
#endif
/* ata_smart_values is format of the read drive Attribute command */
/* see Table 34 of T13/1321D Rev 1 spec (Device SMART data structure) for *some* info */
......@@ -137,9 +160,9 @@ struct ata_smart_values {
unsigned short int revnumber;
struct ata_smart_attribute vendor_attributes [NUMBER_ATA_SMART_ATTRIBUTES];
unsigned char offline_data_collection_status;
unsigned char self_test_exec_status;
unsigned short int total_time_to_complete_off_line;
unsigned char vendor_specific_366;
unsigned char self_test_exec_status; //IBM # segments for offline collection
unsigned short int total_time_to_complete_off_line; // IBM different
unsigned char vendor_specific_366; // IBM curent segment pointer
unsigned char offline_data_collection_capability;
unsigned short int smart_capability;
unsigned char errorlog_capability;
......@@ -165,7 +188,7 @@ struct ata_smart_threshold_entry {
/* Compare to ata_smart_values above */
struct ata_smart_thresholds {
unsigned short int revnumber;
struct ata_smart_threshold_entry thres_entries[30];
struct ata_smart_threshold_entry thres_entries[NUMBER_ATA_SMART_ATTRIBUTES];
unsigned char reserved[149];
unsigned char chksum;
} __attribute__ ((packed));
......
// $Id: ataprint.c,v 1.7 2002/10/12 11:10:01 ballen4705 Exp $
// $Id: ataprint.c,v 1.8 2002/10/13 13:10:56 ballen4705 Exp $
/*
* ataprint.c
*
......@@ -308,7 +308,7 @@ void PrintSmartAttribWithThres ( struct ata_smart_values data,
printf ("Revision Number: %i\n", data.revnumber);
printf ("Attribute Flag Value Worst Threshold Raw Value\n");
for ( i = 0 ; i < 30 ; i++ ){
for ( i = 0 ; i < NUMBER_ATA_SMART_ATTRIBUTES ; i++ ){
// step through all vendor attributes
if (data.vendor_attributes[i].id && thresholds.thres_entries[i].id){
ataPrintSmartAttribName(data.vendor_attributes[i].id);
......@@ -400,7 +400,7 @@ void ataPrintSmartThresholds (struct ata_smart_thresholds data)
printf ("SMART Thresholds\n");
printf ("SMART Threshold Revision Number: %i\n", data.revnumber);
for ( i = 0 ; i < 30 ; i++) {
for ( i = 0 ; i < NUMBER_ATA_SMART_ATTRIBUTES ; i++) {
if (data.thres_entries[i].id)
printf ("Attribute %3i threshold: %02x (%2i)\n",
data.thres_entries[i].id,
......@@ -527,7 +527,7 @@ void ataPrintSmartSelfTestlog (struct ata_smart_selftestlog data){
printf("Warning - structure revision number does not match spec!\n");
if (data.mostrecenttest==0){
printf("No self-test have been logged\n");
printf("No self-tests have been logged\n");
return;
}
......@@ -591,7 +591,7 @@ void ataPsuedoCheckSmart ( struct ata_smart_values data,
struct ata_smart_thresholds thresholds) {
int i;
int failed = 0;
for (i = 0 ; i < 30 ; i++ ) {
for (i = 0 ; i < NUMBER_ATA_SMART_ATTRIBUTES ; i++ ) {
if (data.vendor_attributes[i].id &&
thresholds.thres_entries[i].id &&
data.vendor_attributes[i].status.flag.prefailure &&
......@@ -603,15 +603,13 @@ void ataPsuedoCheckSmart ( struct ata_smart_values data,
}
}
printf("%s\n", ( failed )?
"SMART drive overall health self-assessment test result: FAILED!\n"
"SMART overall-health self-assessment test result: FAILED!\n"
"Drive failure expected in less than 24 hours. SAVE ALL DATA\n":
"SMART drive overall health self-assessment test result: PASSED\n");
"SMART overall-health self-assessment test result: PASSED\n");
}
void ataPrintSmartAttribName ( unsigned char id )
{
switch (id)
{
void ataPrintSmartAttribName ( unsigned char id ){
switch (id){
case 1:
printf("( 1)Raw Read Error Rate ");
......@@ -653,7 +651,7 @@ void ataPrintSmartAttribName ( unsigned char id )
printf("( 13)Read Soft Error Rate ");
break;
case 191:
printf("(191)Gsense Error Rate ");
printf("(191)G-Sense Error Rate ");
break;
case 192:
printf("(192)Power-Off Retract Count");
......@@ -679,6 +677,33 @@ void ataPrintSmartAttribName ( unsigned char id )
case 199:
printf("(199)UDMA CRC Error Count ");
break;
case 220:
printf("(220)Disk Shift ");
break;
case 221:
printf("(221)G-Sense Error Rate ");
break;
case 222:
printf("(222)Loaded Hours ");
break;
case 223:
printf("(223)Load Retry Count ");
break;
case 224:
printf("(224)Load Friction ");
break;
case 225:
printf("(225)Load Cycle Count ");
break;
case 226:
printf("(226)Load-in Time ");
break;
case 227:
printf("(227)Torq-amp Count ");
break;
case 228:
printf("(228)Power-off Retract Count");
break;
default:
printf("(%3d)Unknown Attribute ", id);
break;
......
// $Id: ataprint.cpp,v 1.7 2002/10/12 11:10:01 ballen4705 Exp $
// $Id: ataprint.cpp,v 1.8 2002/10/13 13:10:56 ballen4705 Exp $
/*
* ataprint.c
*
......@@ -308,7 +308,7 @@ void PrintSmartAttribWithThres ( struct ata_smart_values data,
printf ("Revision Number: %i\n", data.revnumber);
printf ("Attribute Flag Value Worst Threshold Raw Value\n");
for ( i = 0 ; i < 30 ; i++ ){
for ( i = 0 ; i < NUMBER_ATA_SMART_ATTRIBUTES ; i++ ){
// step through all vendor attributes
if (data.vendor_attributes[i].id && thresholds.thres_entries[i].id){
ataPrintSmartAttribName(data.vendor_attributes[i].id);
......@@ -400,7 +400,7 @@ void ataPrintSmartThresholds (struct ata_smart_thresholds data)
printf ("SMART Thresholds\n");
printf ("SMART Threshold Revision Number: %i\n", data.revnumber);
for ( i = 0 ; i < 30 ; i++) {
for ( i = 0 ; i < NUMBER_ATA_SMART_ATTRIBUTES ; i++) {
if (data.thres_entries[i].id)
printf ("Attribute %3i threshold: %02x (%2i)\n",
data.thres_entries[i].id,
......@@ -527,7 +527,7 @@ void ataPrintSmartSelfTestlog (struct ata_smart_selftestlog data){
printf("Warning - structure revision number does not match spec!\n");
if (data.mostrecenttest==0){
printf("No self-test have been logged\n");
printf("No self-tests have been logged\n");
return;
}
......@@ -591,7 +591,7 @@ void ataPsuedoCheckSmart ( struct ata_smart_values data,
struct ata_smart_thresholds thresholds) {
int i;
int failed = 0;
for (i = 0 ; i < 30 ; i++ ) {
for (i = 0 ; i < NUMBER_ATA_SMART_ATTRIBUTES ; i++ ) {
if (data.vendor_attributes[i].id &&
thresholds.thres_entries[i].id &&
data.vendor_attributes[i].status.flag.prefailure &&
......@@ -603,15 +603,13 @@ void ataPsuedoCheckSmart ( struct ata_smart_values data,
}
}
printf("%s\n", ( failed )?
"SMART drive overall health self-assessment test result: FAILED!\n"
"SMART overall-health self-assessment test result: FAILED!\n"
"Drive failure expected in less than 24 hours. SAVE ALL DATA\n":
"SMART drive overall health self-assessment test result: PASSED\n");
"SMART overall-health self-assessment test result: PASSED\n");
}
void ataPrintSmartAttribName ( unsigned char id )
{
switch (id)
{
void ataPrintSmartAttribName ( unsigned char id ){
switch (id){
case 1:
printf("( 1)Raw Read Error Rate ");
......@@ -653,7 +651,7 @@ void ataPrintSmartAttribName ( unsigned char id )
printf("( 13)Read Soft Error Rate ");
break;
case 191:
printf("(191)Gsense Error Rate ");
printf("(191)G-Sense Error Rate ");
break;
case 192:
printf("(192)Power-Off Retract Count");
......@@ -679,6 +677,33 @@ void ataPrintSmartAttribName ( unsigned char id )
case 199:
printf("(199)UDMA CRC Error Count ");
break;
case 220:
printf("(220)Disk Shift ");
break;
case 221:
printf("(221)G-Sense Error Rate ");
break;
case 222:
printf("(222)Loaded Hours ");
break;
case 223:
printf("(223)Load Retry Count ");
break;
case 224:
printf("(224)Load Friction ");
break;
case 225:
printf("(225)Load Cycle Count ");
break;
case 226:
printf("(226)Load-in Time ");
break;
case 227:
printf("(227)Torq-amp Count ");
break;
case 228:
printf("(228)Power-off Retract Count");
break;
default:
printf("(%3d)Unknown Attribute ", id);
break;
......
Release: 2
Release: 4
Summary: SMARTmontools - for monitoring S.M.A.R.T. disks and devices
Name: smartmontools
Version: 5.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment