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

First checkin of source code

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@6 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent bbe6a2a3
No related branches found
No related tags found
No related merge requests found
CHANGELOG for smartmontools
Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
You should have received a copy of the GNU General Public License (for
example COPYING); if not, write to the Free Software Foundation, Inc., 675
Mass Ave, Cambridge, MA 02139, USA.
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
# Makefile for smartmontools
#
# Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later
# version.
#
# You should have received a copy of the GNU General Public License (for
# example COPYING); if not, write to the Free Software Foundation, Inc., 675
# Mass Ave, Cambridge, MA 02139, USA.
CC = gcc
CFLAGS = -fsigned-char -Wall -g
all: smartd smartctl
smartctl: atacmds.o scsicmds.o smartctl.c smartctl.h ataprint.o scsiprint.o atacmds.h ataprint.h scsicmds.h scsiprint.h
${CC} -o smartctl ${CFLAGS} atacmds.o scsicmds.o ataprint.o smartctl.c scsiprint.o
smartd: atacmds.o scsicmds.o smartd.c smartd.h atacmds.h scsicmds.h
${CC} -o smartd ${CFLAGS} scsicmds.o atacmds.o smartd.c
ataprint.o: atacmds.o ataprint.h ataprint.c smartctl.h extern.h
${CC} ${CFLAGS} -c ataprint.c
scsiprint.o: scsiprint.h scsiprint.c scsicmds.o smartctl.h extern.h scsicmds.h
${CC} ${CFLAGS} -c scsiprint.c
atacmds.o: atacmds.h atacmds.c
${CC} ${CFLAGS} -c atacmds.c
scsicmds.o: scsicmds.h scsicmds.c
${CC} ${CFLAGS} -c scsicmds.c
clean:
rm -f *.o smartctl smartd *~
install: smartctl smartd smartctl.8 smartd.8 smartd.initd
install -m 755 -o root -g root smartctl /usr/sbin
install -m 755 -o root -g root smartd /usr/sbin
install -m 644 -o root -g root smartctl.8 /usr/share/man/man8
install -m 644 -o root -g root smartd.8 /usr/share/man/man8
cp ./smartd.initd /etc/rc.d/init.d/smartd
/sbin/chkconfig --add smartd
uninstall:
rm -f /usr/sbin/smartctl /usr/sbin/smartd /usr/share/man/man8/smartctl.8 /usr/share/man/man8/smartd.8 /usr/share/man/man8/smartctl.8.gz /usr/share/man/man8/smartd.8.gz
/sbin/chkconfig --del smartd
rm -f /etc/rc.d/init.d/smartd
===============================================
SMARTMONTOOLS - SMART utility toolset for Linux
===============================================
== HOME ==
The home for smartmontools is located at:
http://sourceforge.net/projects/smartmontools Please see this web site
for updates, documentation, and for submitting patches and bug
reports.
== COPYING ==
Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
You should have received a copy of the GNU General Public License (for
example COPYING); if not, write to the Free Software Foundation, Inc., 675
Mass Ave, Cambridge, MA 02139, USA.
== OVERVIEW ==
SMARTMONTOOLS contains utilities that control and monitor storage
devices using the Self-Monitoring, Analysis and Reporting Technology
(S.M.A.R.T.) system build into ATA and SCSI Hard Drives. This is used
to check the reliability of the hard drive and to predict drive
failures. SMARTMONTOOLS Version 5.x is designed to comply to the
ATA/ATAPI-5 specification (Revision 1). Future releases of
SMARTMONTOOLS (Versions 6.x and 7.x) will comply with the ATA/ATAPI-6
and ATA/ATAPI-7 specifications.
This package is meant to be an up-to-date replacement for the
ucsc-smartsuite and smartsuite packages, and is derived from that
code.
== CONTENTS ==
The suite contains two utilities:
smartctl is a command line utility designed to perform
S.M.A.R.T. tasks.such as disk self-checks, and to
report the S.M.A.R.T. status of the disk.
smartd is a daemon that periodically monitors S.M.A.R.T. status and
reports errors and changes in S.M.A.R.T. attributes to syslog.
You can read about these commands using the man pages. Within this
directory the commands:
man ./smartctl.8
and
man ./smartd.8
will display the manual pages for the two commands. If you install the package on
your system, then
man smartctl
and
man smartd
will display the same information.
== INSTALLATION ==
To install, use the commands:
make
make install
The tools require Linux kernel 2.2.14 or greater in order to run. Any
recent Linux distribution should support this package.
The files installed are:
/usr/sbin/smartd [Executable daemon]
/usr/sbin/smartctl [Executable command-line utility]
/etc/rc.d/init.d/smartd [Init/Startup script for smartd]
/usr/share/man/man8/smartctl.8.gz [Manual page]
/usr/share/man/man8/smartd.8.gz [Manual page]
Source and binary RPM files are available at the website listed above.
== USAGE ==
SMARTMONTOOLS contents two utilities:
smartctl - A command line control utility
smartd - A monitoring daemon
to run smartctl, use the syntax
./smartctl [options] [device]
See the man page for full details. A summary of the options is:
Read only:
p Print License/Copyright information.
i Checks if the device supports S.M.A.R.T, and prints drive model
information.
c Checks if device has any S.M.A.R.T. Warranty Failures. This means
that the device is predicting failure in the next 24 hours.
g Prints only the generic S.M.A.R.T. attributes
v Prints only the vendor specific S.M.A.R.T. attributes & thresholds
l Prints only the S.M.A.R.T. error log
L Prints only the S.M.A.R.T. self-test log
a Prints all parameters for i,c,g,v,t,l,L
Enable/Disable commands:
e Enables S.M.A.R.T. on device
d Disables S.M.A.R.T. on device
f Enables S.M.A.R.T. attributes auto-save on device
F Disables S.M.A.R.T. attributes auto-save on device
t Enables S.M.A.R.T. automatic offline self test timer which scans the
drive every four hours for disk defects.
T Disables S.M.A.R.T. automatic offline self test timer
Test Commands:
O Runs S.M.A.R.T. Immediate offline Test
S Runs S.M.A.R.T. Short Self Test (usually under ten minutes)
s Runs S.M.A.R.T. Short Self Test in Captive Mode. (WARNING this test
will busy out drive for length of test )
X Runs S.M.A.R.T. Extended Self Test (tens of minutes)
x Runs S.M.A.R.T. Extended Self Test in Captive Mode. (WARNING this
test will busy out the drive for the length of the test)
A Aborts Non-Captive S.M.A.R.T. Tests.
devices are IDE devices which usually are:
/dev/hda Primary Master
/dev/hdb Primary Slave
/dev/hdc Secondary Master
/dev/hdd Secondary Slave
for SCSI the devices are usually
/dev/sda First SCSI Disk
/dev/sdb second SCSI disl
Examples:
smartctl -e /dev/hda - enables SMART on hard drive
smartctl -c /dev/sda - checks status of hard drive.
smartd - starts background daemon to
monitor hard drive status
smartd will scan for all devices that support SMART and poll them very
thirty minutes for errors or for changes in attribute values. When an
error or attribute value change occurs, it sends log information to
the SYSLOG facility. Typically these messages and warnings appear in
/var/log/messages.
== REFERENCES ==
If you need help in understanding the output of smartctl, a good place
to start is to read Section 8.41 of the AT Attachment with Packet
Interface-5 (ATA/ATAPI-5) specification. This documents the
S.M.A.R.T. functionality which the smartmontools utilities provide
access to. You can find Revision 1 of this document at:
http://www.t13.org/project/d1321r1c.pdf
Future versions of the specifications (ATA/ATAPI-6 and ATA/ATAPI-7)
can be obtained from:
http://www.t13.org/#FTP_site
Later revisions (2, 3) of the ATA/ATAPI-5 specification are also
available there.
The functioning of S.M.A.R.T. is also described by the SFF-8035i
revision 2 specification. This is a publication of the Small Form
Factors Committee, and can be obtained from SFF Committee, 14426 Black
Walnut Ct., Saratoga, CA 95070, USA.
SFF FaxAccess: (408) 741-1600
Ph: (408) 867-6630
Fax: (408) 867-2115
E-Mail: 250-1752@mcimail.com.
sm5/TODO 0 → 100644
TODO list for smartmontools:
Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
You should have received a copy of the GNU General Public License (for
example COPYING); if not, write to the Free Software Foundation, Inc., 675
Mass Ave, Cambridge, MA 02139, USA.
Testing
-------
Test with SCSI devices (I can't do it -- Bruce)
Extensions
----------
Produce version for ATA/ATAPI-6
Produce version for ATA/ATAPI-7
Modifications
-------------
Command line option to specify devices to look for in smartd startup
// $Id: atacmds.c,v 1.1 2002/10/09 17:56:58 ballen4705 Exp $
/*
* atacmds.c
*
* Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
* Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
* Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include "atacmds.h"
int ataReadHDIdentity ( int device, struct hd_driveid *buf)
{
if (ioctl ( device , HDIO_GET_IDENTITY, buf ) != 0)
{
perror ("ATA GET HD Failed");
return -1;
}
return 0;
}
int ataVersionInfo ( struct hd_driveid drive)
{
int i;
int atavalue = 0;
#ifdef DEBUG
#ifdef __NEW_HD_DRIVE_ID
printf ("Debug: Ata Version: %04x\n", drive.major_rev_num);
#else
printf ("Debug: Ata Version: %04x\n", drive.word80);
#endif
#endif
#ifdef __NEW_HD_DRIVE_ID
if ( (drive.major_rev_num == 0xffff) || (drive.major_rev_num == 0x000) )
#else
if ( (drive.word80 == 0xffff) || (drive.word80 == 0x000) )
#endif
{
return -1;
}
for ( i = 1; i < 16; i++ )
{
#ifdef __NEW_HD_DRIVE_ID
if ( drive.major_rev_num & ( 0x1 << i) )
#else
#endif
{
atavalue = i;
}
}
return atavalue;
}
int ataSmartSupport ( struct hd_driveid drive)
{
#ifdef __NEW_HD_DRIVE_ID
if ( drive.command_set_1 & 0x0001 ){
#else
if ( drive.command_sets & 0x0001 ){
#endif
return (1); /* drive supports S.M.A.R.T. and is disabled */
}
return (0);
}
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] =
{ WIN_SMART, 0, SMART_READ_VALUES, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
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];
if ( (unsigned char) chksum != 0)
{
perror ("Smart Read Failed, Chksum error");
return -1;
}
memcpy( data,
&buf[HDIO_DRIVE_CMD_HDR_SIZE] ,
ATA_SMART_SEC_SIZE );
return 0;
}
int ataReadSelfTestLog (int device, struct ata_smart_selftestlog *data)
{
int i;
unsigned char chksum=0;
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 0x06, SMART_READ_LOG_SECTOR, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Error Log Read failed");
return -1;
}
// compute checksum
for (i=0;i<ATA_SMART_SEC_SIZE;i++)
chksum+=buf[HDIO_DRIVE_CMD_HDR_SIZE+i];
if (chksum){
fprintf(stderr,"Smart Self Test Log Checksum Incorrect!\n");
return -1;
}
memcpy( data, &buf[HDIO_DRIVE_CMD_HDR_SIZE] , ATA_SMART_SEC_SIZE);
return 0;
}
int ataReadErrorLog (int device, struct ata_smart_errorlog *data)
{
int i;
unsigned char chksum=0;
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 0x01, SMART_READ_LOG_SECTOR, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Error Log Read failed");
return -1;
}
// compute checksum
for (i=0;i<ATA_SMART_SEC_SIZE;i++)
chksum+=buf[HDIO_DRIVE_CMD_HDR_SIZE+i];
if (chksum){
fprintf(stderr,"Smart Error Log Checksum Incorrect!\n");
return -1;
}
memcpy( data, &buf[HDIO_DRIVE_CMD_HDR_SIZE] , ATA_SMART_SEC_SIZE);
return 0;
}
int ataReadSmartThresholds ( int device, struct ata_smart_thresholds *data)
{
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 1, SMART_READ_THRESHOLDS, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Thresholds Read failed");
return -1;
}
memcpy( data, &buf[HDIO_DRIVE_CMD_HDR_SIZE] , ATA_SMART_SEC_SIZE);
return 0;
}
int ataSetSmartThresholds ( int device, struct ata_smart_thresholds *data)
{
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 1, 0xD7, 1};
memcpy( &buf[HDIO_DRIVE_CMD_HDR_SIZE], data , ATA_SMART_SEC_SIZE);
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Thresholds Read failed");
return -1;
}
return 0;
}
int ataEnableSmart (int device )
{
unsigned char parms[4] = { WIN_SMART, 1, SMART_ENABLE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Enable failed");
return -1;
}
return 0;
}
int ataDisableSmart (int device )
{
unsigned char parms[4] = { WIN_SMART, 1, SMART_DISABLE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Disable failed");
return -1;
}
return 0;
}
int ataEnableAutoSave(int device){
unsigned char parms[4] = { WIN_SMART, 241, SMART_AUTOSAVE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Enable Auto-save failed");
return -1;
}
return 0;
};
int ataDisableAutoSave(int device){
unsigned char parms[4] = { WIN_SMART, 0, SMART_AUTOSAVE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Disable Auto-save failed");
return -1;
}
return 0;
};
int ataEnableAutoOffline (int device )
{
/* timer hard coded to 4 hours */
unsigned char parms[4] = { WIN_SMART, 248, SMART_AUTO_OFFLINE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Enable Automatic Offline failed");
return -1;
}
return 0;
}
int ataDisableAutoOffline (int device )
{
unsigned char parms[4] = { WIN_SMART, 0, SMART_AUTO_OFFLINE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Disable Automatic Offline failed");
return -1;
}
return 0;
}
int ataSmartStatus (int device )
{
unsigned char parms[4] = { WIN_SMART, 0, SMART_STATUS, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms) != 0)
{
return -1;
}
return 0;
}
int ataSmartTest (int device, int testtype)
{
unsigned char parms[4] = { WIN_SMART, testtype,
SMART_IMMEDIATE_OFFLINE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms) != 0)
{
perror ("Smart Offline failed");
return -1;
}
printf("Completed Off-line command\n");
return 0;
}
int ataSmartOfflineTest (int device)
{
return ataSmartTest( device, OFFLINE_FULL_SCAN );
}
int ataSmartShortSelfTest (int device)
{
return ataSmartTest( device, SHORT_SELF_TEST );
}
int ataSmartExtendSelfTest (int device)
{
return ataSmartTest( device, EXTEND_SELF_TEST );
}
int ataSmartShortCapSelfTest (int device)
{
return ataSmartTest( device, SHORT_CAPTIVE_SELF_TEST );
}
int ataSmartExtendCapSelfTest (int device)
{
return ataSmartTest( device, EXTEND_CAPTIVE_SELF_TEST );
}
int ataSmartSelfTestAbort (int device)
{
return ataSmartTest( device, 127 );
}
/* Test Time Functions */
int isOfflineTestTime ( struct ata_smart_values data)
{
return (int) data.total_time_to_complete_off_line;
}
int isShortSelfTestTime ( struct ata_smart_values data)
{
return (int) data.short_test_completion_time;
}
int isExtendedSelfTestTime ( struct ata_smart_values data)
{
return (int) data.extend_test_completion_time;
}
int isSmartErrorLogCapable ( struct ata_smart_values data)
{
return data.errorlog_capability & 0x01;
}
int isSupportExecuteOfflineImmediate ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x01;
}
int isSupportAutomaticTimer ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x02;
}
int isSupportOfflineAbort ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x04;
}
int isSupportOfflineSurfaceScan ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x08;
}
int isSupportSelfTest (struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x10;
}
int ataCheckSmart ( struct ata_smart_values data, struct ata_smart_thresholds thresholds)
{
int i;
for ( i = 0 ; i < 30 ; i++ )
{
if ( (data.vendor_attributes[i].id !=0) &&
(thresholds.thres_entries[i].id != 0) &&
(data.vendor_attributes[i].status.flag.prefailure) &&
(data.vendor_attributes[i].current <
thresholds.thres_entries[i].threshold) &&
(thresholds.thres_entries[i].threshold != 0xFE) )
{
return i;
}
}
return 0;
}
// $Id: atacmds.cpp,v 1.1 2002/10/09 17:56:58 ballen4705 Exp $
/*
* atacmds.c
*
* Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
* Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
* Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include "atacmds.h"
int ataReadHDIdentity ( int device, struct hd_driveid *buf)
{
if (ioctl ( device , HDIO_GET_IDENTITY, buf ) != 0)
{
perror ("ATA GET HD Failed");
return -1;
}
return 0;
}
int ataVersionInfo ( struct hd_driveid drive)
{
int i;
int atavalue = 0;
#ifdef DEBUG
#ifdef __NEW_HD_DRIVE_ID
printf ("Debug: Ata Version: %04x\n", drive.major_rev_num);
#else
printf ("Debug: Ata Version: %04x\n", drive.word80);
#endif
#endif
#ifdef __NEW_HD_DRIVE_ID
if ( (drive.major_rev_num == 0xffff) || (drive.major_rev_num == 0x000) )
#else
if ( (drive.word80 == 0xffff) || (drive.word80 == 0x000) )
#endif
{
return -1;
}
for ( i = 1; i < 16; i++ )
{
#ifdef __NEW_HD_DRIVE_ID
if ( drive.major_rev_num & ( 0x1 << i) )
#else
#endif
{
atavalue = i;
}
}
return atavalue;
}
int ataSmartSupport ( struct hd_driveid drive)
{
#ifdef __NEW_HD_DRIVE_ID
if ( drive.command_set_1 & 0x0001 ){
#else
if ( drive.command_sets & 0x0001 ){
#endif
return (1); /* drive supports S.M.A.R.T. and is disabled */
}
return (0);
}
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] =
{ WIN_SMART, 0, SMART_READ_VALUES, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
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];
if ( (unsigned char) chksum != 0)
{
perror ("Smart Read Failed, Chksum error");
return -1;
}
memcpy( data,
&buf[HDIO_DRIVE_CMD_HDR_SIZE] ,
ATA_SMART_SEC_SIZE );
return 0;
}
int ataReadSelfTestLog (int device, struct ata_smart_selftestlog *data)
{
int i;
unsigned char chksum=0;
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 0x06, SMART_READ_LOG_SECTOR, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Error Log Read failed");
return -1;
}
// compute checksum
for (i=0;i<ATA_SMART_SEC_SIZE;i++)
chksum+=buf[HDIO_DRIVE_CMD_HDR_SIZE+i];
if (chksum){
fprintf(stderr,"Smart Self Test Log Checksum Incorrect!\n");
return -1;
}
memcpy( data, &buf[HDIO_DRIVE_CMD_HDR_SIZE] , ATA_SMART_SEC_SIZE);
return 0;
}
int ataReadErrorLog (int device, struct ata_smart_errorlog *data)
{
int i;
unsigned char chksum=0;
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 0x01, SMART_READ_LOG_SECTOR, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Error Log Read failed");
return -1;
}
// compute checksum
for (i=0;i<ATA_SMART_SEC_SIZE;i++)
chksum+=buf[HDIO_DRIVE_CMD_HDR_SIZE+i];
if (chksum){
fprintf(stderr,"Smart Error Log Checksum Incorrect!\n");
return -1;
}
memcpy( data, &buf[HDIO_DRIVE_CMD_HDR_SIZE] , ATA_SMART_SEC_SIZE);
return 0;
}
int ataReadSmartThresholds ( int device, struct ata_smart_thresholds *data)
{
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 1, SMART_READ_THRESHOLDS, 1};
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Thresholds Read failed");
return -1;
}
memcpy( data, &buf[HDIO_DRIVE_CMD_HDR_SIZE] , ATA_SMART_SEC_SIZE);
return 0;
}
int ataSetSmartThresholds ( int device, struct ata_smart_thresholds *data)
{
unsigned char buf[ HDIO_DRIVE_CMD_HDR_SIZE +
ATA_SMART_SEC_SIZE] =
{ WIN_SMART, 1, 0xD7, 1};
memcpy( &buf[HDIO_DRIVE_CMD_HDR_SIZE], data , ATA_SMART_SEC_SIZE);
if (ioctl ( device , HDIO_DRIVE_CMD, (unsigned char *) &buf ) != 0)
{
perror ("Smart Thresholds Read failed");
return -1;
}
return 0;
}
int ataEnableSmart (int device )
{
unsigned char parms[4] = { WIN_SMART, 1, SMART_ENABLE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Enable failed");
return -1;
}
return 0;
}
int ataDisableSmart (int device )
{
unsigned char parms[4] = { WIN_SMART, 1, SMART_DISABLE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Disable failed");
return -1;
}
return 0;
}
int ataEnableAutoSave(int device){
unsigned char parms[4] = { WIN_SMART, 241, SMART_AUTOSAVE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Enable Auto-save failed");
return -1;
}
return 0;
};
int ataDisableAutoSave(int device){
unsigned char parms[4] = { WIN_SMART, 0, SMART_AUTOSAVE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Disable Auto-save failed");
return -1;
}
return 0;
};
int ataEnableAutoOffline (int device )
{
/* timer hard coded to 4 hours */
unsigned char parms[4] = { WIN_SMART, 248, SMART_AUTO_OFFLINE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Enable Automatic Offline failed");
return -1;
}
return 0;
}
int ataDisableAutoOffline (int device )
{
unsigned char parms[4] = { WIN_SMART, 0, SMART_AUTO_OFFLINE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms ) != 0)
{
perror ("Smart Disable Automatic Offline failed");
return -1;
}
return 0;
}
int ataSmartStatus (int device )
{
unsigned char parms[4] = { WIN_SMART, 0, SMART_STATUS, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms) != 0)
{
return -1;
}
return 0;
}
int ataSmartTest (int device, int testtype)
{
unsigned char parms[4] = { WIN_SMART, testtype,
SMART_IMMEDIATE_OFFLINE, 0};
if (ioctl ( device , HDIO_DRIVE_CMD, &parms) != 0)
{
perror ("Smart Offline failed");
return -1;
}
printf("Completed Off-line command\n");
return 0;
}
int ataSmartOfflineTest (int device)
{
return ataSmartTest( device, OFFLINE_FULL_SCAN );
}
int ataSmartShortSelfTest (int device)
{
return ataSmartTest( device, SHORT_SELF_TEST );
}
int ataSmartExtendSelfTest (int device)
{
return ataSmartTest( device, EXTEND_SELF_TEST );
}
int ataSmartShortCapSelfTest (int device)
{
return ataSmartTest( device, SHORT_CAPTIVE_SELF_TEST );
}
int ataSmartExtendCapSelfTest (int device)
{
return ataSmartTest( device, EXTEND_CAPTIVE_SELF_TEST );
}
int ataSmartSelfTestAbort (int device)
{
return ataSmartTest( device, 127 );
}
/* Test Time Functions */
int isOfflineTestTime ( struct ata_smart_values data)
{
return (int) data.total_time_to_complete_off_line;
}
int isShortSelfTestTime ( struct ata_smart_values data)
{
return (int) data.short_test_completion_time;
}
int isExtendedSelfTestTime ( struct ata_smart_values data)
{
return (int) data.extend_test_completion_time;
}
int isSmartErrorLogCapable ( struct ata_smart_values data)
{
return data.errorlog_capability & 0x01;
}
int isSupportExecuteOfflineImmediate ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x01;
}
int isSupportAutomaticTimer ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x02;
}
int isSupportOfflineAbort ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x04;
}
int isSupportOfflineSurfaceScan ( struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x08;
}
int isSupportSelfTest (struct ata_smart_values data)
{
return data.offline_data_collection_capability & 0x10;
}
int ataCheckSmart ( struct ata_smart_values data, struct ata_smart_thresholds thresholds)
{
int i;
for ( i = 0 ; i < 30 ; i++ )
{
if ( (data.vendor_attributes[i].id !=0) &&
(thresholds.thres_entries[i].id != 0) &&
(data.vendor_attributes[i].status.flag.prefailure) &&
(data.vendor_attributes[i].current <
thresholds.thres_entries[i].threshold) &&
(thresholds.thres_entries[i].threshold != 0xFE) )
{
return i;
}
}
return 0;
}
// $Id: atacmds.h,v 1.1 2002/10/09 17:56:58 ballen4705 Exp $
/*
* atacmds.h
*
* Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
* Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ATACMDS_H_
#define _ATACMDS_H_
#include <sys/ioctl.h>
#include <linux/hdreg.h>
#include <sys/fcntl.h>
#include <sys/types.h>
/* These defines SHOULD BE in the kernel
if not we define them */
#ifndef WIN_SMART
#define WIN_SMART 0xb0
#endif
#ifndef SMART_READ_VALUES
#define SMART_READ_VALUES 0xd0
#endif
#ifndef SMART_READ_THRESHOLDS
#define SMART_READ_THRESHOLDS 0xd1
#endif
#ifndef SMART_AUTOSAVE
#define SMART_AUTOSAVE 0xd2
#endif
#ifndef SMART_SAVE
#define SMART_SAVE 0xd3
#endif
#ifndef SMART_IMMEDIATE_OFFLINE
#define SMART_IMMEDIATE_OFFLINE 0xd4
#endif
#ifndef SMART_READ_LOG_SECTOR
#define SMART_READ_LOG_SECTOR 0xd5
#endif
#ifndef SMART_WRITE_LOG_SECTOR
#define SMART_WRITE_LOG_SECTOR 0xd6
#endif
#ifndef SMART_ENABLE
#define SMART_ENABLE 0xd8
#endif
#ifndef SMART_DISABLE
#define SMART_DISABLE 0xd9
#endif
#ifndef SMART_STATUS
#define SMART_STATUS 0xda
#endif
#ifndef SMART_AUTO_OFFLINE
#define SMART_AUTO_OFFLINE 0xdb
#endif
#define OFFLINE_FULL_SCAN 0
#define SHORT_SELF_TEST 1
#define EXTEND_SELF_TEST 2
#define SHORT_CAPTIVE_SELF_TEST 129
#define EXTEND_CAPTIVE_SELF_TEST 130
#define NUMBER_ATA_SMART_ATTRIBUTES 30
#define ATA_SMART_SEC_SIZE 512
#ifndef HDIO_DRIVE_CMD_HDR_SIZE
#define HDIO_DRIVE_CMD_HDR_SIZE 4
#endif
#ifndef HDIO_DRIVE_TASK_HDR_SIZE
#define HDIO_DRIVE_TASK_HDR_SIZE 7
#endif
/* Smart Values Data Structures */
/* Smart Status Flags */
/* ata_smart_attribute is the vendor specific in SFF-8035 spec */
struct ata_smart_attribute {
unsigned char id;
union {
unsigned short all;
struct {
unsigned prefailure:1;
unsigned online:1;
unsigned performance:1;
unsigned errorrate:1;
unsigned eventcount:1 ;
unsigned selfperserving:1;
unsigned reserved:10;
} __attribute__ ((packed)) flag;
} status ;
unsigned char current;
unsigned char worst;
unsigned char raw[6];
unsigned char reserv;
} __attribute__ ((packed));
/* ata_smart_values is format of the read drive Atrribute command */
/* see Table 34 of T13/1321D Rev 1 spec (Device SMART data structure) for *some* info */
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 offline_data_collection_capability;
unsigned short int smart_capability;
unsigned char errorlog_capability;
unsigned char vendor_specific_371; // IBM: self-test failure checkpoint
unsigned char short_test_completion_time;
unsigned char extend_test_completion_time;
unsigned char reserved_374_385 [12];
unsigned char vendor_specific_386_509 [125];
unsigned char chksum;
} __attribute__ ((packed));
/* Smart Threshold data structures */
/* Vendor attribute of SMART Threshold (compare to ata_smart_attribute above) */
struct ata_smart_threshold_entry {
unsigned char id;
unsigned char threshold;
unsigned char reserved[10];
} __attribute__ ((packed));
/* Format of Read SMART THreshold Command */
/* Compare to ata_smart_values above */
struct ata_smart_thresholds {
unsigned short int revnumber;
struct ata_smart_threshold_entry thres_entries[30];
unsigned char reserved[149];
unsigned char chksum;
} __attribute__ ((packed));
// Table 42 of T13/1321D Rev 1 spec (Error Data Structure)
struct ata_smart_errorlog_error_struct {
unsigned char reserved;
unsigned char error_register;
unsigned char sector_count;
unsigned char sector_number;
unsigned char cylinder_low;
unsigned char cylinder_high;
unsigned char drive_head;
unsigned char status;
unsigned char extended_error[19];
unsigned char state;
unsigned short timestamp;
} __attribute__ ((packed));
// Table 41 of T13/1321D Rev 1 spec (Command Data Structure)
struct ata_smart_errorlog_command_struct {
unsigned char devicecontrolreg;
unsigned char featuresreg;
unsigned char sector_count;
unsigned char sector_number;
unsigned char cylinder_low;
unsigned char cylinder_high;
unsigned char drive_head;
unsigned char commandreg;
unsigned int timestamp;
} __attribute__ ((packed));
// Table 40 of T13/1321D Rev 1 spec (Error log data structure)
struct ata_smart_errorlog_struct {
struct ata_smart_errorlog_command_struct commands[5];
struct ata_smart_errorlog_error_struct error_struct;
} __attribute__ ((packed));
// Table 39 of T13/1321D Rev 1 spec (SMART error log sector)
struct ata_smart_errorlog {
unsigned char revnumber;
unsigned char error_log_pointer;
struct ata_smart_errorlog_struct errorlog_struct[5];
unsigned short int ata_error_count;
unsigned char reserved[57];
unsigned char checksum;
} __attribute__ ((packed));
// Table 45 of T13/1321D Rev 1 spec (Self-test log descriptor entry)
struct ata_smart_selftestlog_struct {
unsigned char selftestnumber; // Sector number register
unsigned char selfteststatus;
unsigned short int timestamp;
unsigned char selftestfailurecheckpoint;
unsigned int lbafirstfailure;
unsigned char vendorspecific[15];
} __attribute__ ((packed));
// Table 44 of T13/1321D Rev 1 spec (Self-test log data structure)
struct ata_smart_selftestlog {
unsigned short int revnumber;
struct ata_smart_selftestlog_struct selftest_struct[21];
unsigned char vendorspecific[2];
unsigned char mostrecenttest;
unsigned char resevered[2];
unsigned char chksum;
} __attribute__ ((packed));
/* Read S.M.A.R.T information from drive */
int ataReadHDIdentity (int device, struct hd_driveid *buf);
int ataReadSmartValues (int device,struct ata_smart_values *);
int ataReadSmartThresholds (int device, struct ata_smart_thresholds *);
int ataReadErrorLog ( int device, struct ata_smart_errorlog *);
int ataReadSelfTestLog (int device, struct ata_smart_selftestlog *);
int ataSmartStatus ( int device);
int ataSetSmartThresholds ( int device, struct ata_smart_thresholds *);
/* Enable/Disable SMART on device */
int ataEnableSmart ( int device );
int ataDisableSmart (int device );
int ataEnableAutoSave(int device);
int ataDisableAutoSave(int device);
/* Automatic Offline Testing */
int ataEnableAutoOffline ( int device );
int ataDisableAutoOffline (int device );
/* S.M.A.R.T. test commands */
int ataSmartOfflineTest (int device);
int ataSmartExtendSelfTest (int device);
int ataSmartShortSelfTest (int device);
int ataSmartShortCapSelfTest (int device);
int ataSmartExtendCapSelfTest (int device);
int ataSmartSelfTestAbort (int device);
/*Check Parameters of Smart Data */
/* int ataVersionInfo ( struct hd_driveid drive)
* Returns the latest compability of ATA/ATAPI Version
* the device supports
* Returns -1 if Version command is not supported
*/
int ataVersionInfo ( struct hd_driveid drive);
/* int ataSmartSupport ( int device, struct hd_driveid drive)
* Check if S.M.A.R.T. is supported and enabled in drive
* returns -1:if S.M.A.R.T. cabability can not be checked
* returns 0: if drive does not support S.M.A.R.T.
* 1: if drive supports S.M.A.R.T. but not enabled
* 2: if drive supports S.M.A.R.T. and enabled
* 255: if drive supports S.M.A.R.T. but does not
* support ATA-4.
* ATA 3 and lower do not support S.M.A.R.T. enabled bit
* Attempt a Read S.M.A.R.T. attributes to check if enabled
*/
int ataSmartSupport ( struct hd_driveid drive);
/* Check SMART for Threshold failure */
int ataCheckSmart ( struct ata_smart_values data, struct ata_smart_thresholds thresholds);
/* int isOfflineTestTime ( struct ata_smart_values data)
* returns S.M.A.R.T. Offline Test Time in seconds
*/
int isOfflineTestTime ( struct ata_smart_values data);
int isShortSelfTestTime ( struct ata_smart_values data);
int isExtendedSelfTestTime ( struct ata_smart_values data);
int isSmartErrorLogCapable ( struct ata_smart_values data);
int isSupportExecuteOfflineImmediate ( struct ata_smart_values data);
int isSupportAutomaticTimer ( struct ata_smart_values data);
int isSupportOfflineAbort ( struct ata_smart_values data);
int isSupportOfflineSurfaceScan ( struct ata_smart_values data);
int isSupportSelfTest (struct ata_smart_values data);
#endif /* _ATACMDS_H_ */
This diff is collapsed.
This diff is collapsed.
// $Id: ataprint.h,v 1.1 2002/10/09 17:56:58 ballen4705 Exp $
/*
* ataprint.c
*
* Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
* Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _SMART_PRINT_H_
#define _SMART_PRINT_H_
#include <stdio.h>
#include <stdlib.h>
#include "atacmds.h"
/* Print Formart of Structures for SMART information */
/* Prints ATA Drive Information and S.M.A.R.T. Capability */
void ataPrintDriveInfo (struct hd_driveid);
void ataPrintGeneralSmartValues (struct ata_smart_values);
void ataPrintSmartThresholds (struct ata_smart_thresholds);
void ataPrintSmartErrorlog (struct ata_smart_errorlog);
void PrintSmartAttributes (struct ata_smart_values data);
void PrintSmartAttribWithThres (struct ata_smart_values data,
struct ata_smart_thresholds thresholds);
void ataPrintSmartSelfTestlog (struct ata_smart_selftestlog data);
void ataPsuedoCheckSmart (struct ata_smart_values ,
struct ata_smart_thresholds );
/* Prints Attribute Name for standard SMART attributes */
/* prints 20 character string */
void ataPrintSmartAttribName (unsigned char id);
void ataPrintMain ( int fd );
#endif
// $Id: extern.h,v 1.1 2002/10/09 17:56:58 ballen4705 Exp $
/*
* extern.h
*
* Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
* Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _EXTERN_H_
#define _EXTERN_H_
extern unsigned char driveinfo;
extern unsigned char checksmart;
extern unsigned char smartvendorattrib;
extern unsigned char generalsmartvalues;
extern unsigned char smartselftestlog;
extern unsigned char smarterrorlog;
extern unsigned char smartdisable;
extern unsigned char smartenable;
extern unsigned char smartstatus;
extern unsigned char smartexeoffimmediate;
extern unsigned char smartshortselftest;
extern unsigned char smartextendselftest;
extern unsigned char smartshortcapselftest;
extern unsigned char smartextendcapselftest;
extern unsigned char smartselftestabort;
extern unsigned char smartautoofflineenable;
extern unsigned char smartautoofflinedisable;
extern unsigned char smartautosaveenable;
extern unsigned char smartautosavedisable;
#endif
This diff is collapsed.
This diff is collapsed.
// $Id: scsicmds.h,v 1.1 2002/10/09 17:56:58 ballen4705 Exp $
/*
* scsicmds.h
*
* Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
* Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SCSICMDS_H_
#define SCSICMDS_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/hdreg.h>
typedef unsigned char UINT8;
typedef char INT8;
typedef unsigned int UINT32;
typedef int INT32;
/* Command Descriptor Block for SCSI Commands
* There are three standard length 6, 10, and 12 bytes
* List below are standard forms of CDBs the are not listed
* in structure because format can change within specific commands
* these header include data buffer sizes. This is for used with ioctl
*
*/
/* 6-type CDB format */
/*
cdb[0] is Opcode
cdb[1] bits 5-7 LUN
bits 0-4 Logical Block (MSB)
cdb[2] is Logical Block
cdb[3] is Logical Block (LSB)
cdb[4] is Transfer Length
cdb[5] is Control Byte
*/
#define CDB_6_HDR_SIZE 14
#define CDB_6_MAX_DATA_SIZE 0xff
struct cdb6hdr{
UINT32 inbufsize;
UINT32 outbufsize;
UINT8 cdb [6];
} __attribute__ ((packed));
/* 10-type CDB format */
/*
cdb[0] is Opcode
cdb[1] bits 5-7 LUN
bits 0-4 Reserved
cdb[2] is Logical Block (MSB)
cdb[3] is Logical Block
cdb[4] is Logical Block
cdb[5] is Logical Block (LSB)
cdb[6] is Reserved
cdb[7] is Transfer Length (MSB)
cdb[8] is Transfer Length (LSB)
cdb[9] is Control Byte
*/
#define CDB_10_HDR_SIZE 14
#define CDB_10_MAX_DATA_SIZE 0xffff
struct cdb10hdr {
UINT32 inbufsize;
UINT32 outbufsize;
UINT8 cdb [10];
} __attribute__ ((packed));
/* 12-type CDB format */
/*
cdb[0] is Opcode
cdb[1] bits 5-7 LUN
bits 0-4 Reserved
cdb[2] is Logical Block (MSB)
cdb[3] is Logical Block
cdb[4] is Logical Block
cdb[5] is Logical Block (LSB)
cdb[6] is Transfer Length (MSB)
cdb[7] is Transfer Length
cdb[8] is Transfer Length
cdb[9] is Transfer Length (LSB)
cdb[10] is Reserved
cdb[11] is Control Byte
*/
#define CDB_12_HDR_SIZE 14
#define CDB_12_MAX_DATA_SIZE 0xffffffff
struct cdb12hdr {
UINT32 inbufsize;
UINT32 outbufsize;
UINT8 cdb [12];
} __attribute__ ((packed));
/* Mode Select Data Header */
#define MODE_DATA_HDR_SIZE 12
struct modedatahdr {
UINT8 modedatalength;
UINT8 mediumtype;
UINT8 reserved2;
UINT8 blockdescriptor;
UINT8 numberofblocks[3];
UINT8 densitycode;
UINT8 blocklength[3];
} ;
/* ANSI SCSI-3 Log Sense Return Log Pages from device. */
#define SUPPORT_LOG_PAGES 0x00
#define BUFFER_OVERRUN_PAGE 0x01
#define WRITE_ERROR_COUNTER_PAGE 0x02
#define READ_ERROR_COUNTER_PAGE 0x03
#define READ_REVERSE_ERROR_COUNTER_PAGE 0x04
#define VERIFY_ERROR_COUNTER_PAGE 0x05
#define NON_MEDIUM_ERROR_PAGE 0x06
#define LAST_N_ERROR_PAGE 0x07
#define FORMAT_STATUS_PAGE 0x08
#define TEMPERATURE_PAGE 0x0d
#define STARTSTOP_CYCLE_COUNTER_PAGE 0x0e
#define APPLICATION_CLIENT_PAGE 0x0f
#define SELFTEST_RESULTS_PAGE 0x10
/* From IBM Documentation */
/* See more information at http://www.storage.ibm.com/techsup/hddtech/prodspecs.htm */
#define TAPE_ALERTS_PAGE 0x2e
#define SMART_PAGE 0x2f
/* ANSI SCSI-3 Mode Pages */
#define VENDOR_UNIQUE_PARAMETERS 0x00
#define READ_WRITE_ERROR_RECOVERY_PARAMETERS 0x01
#define DISCONNECT_RECONNECT_PARAMETERS 0x02
#define FORMAT_DEVICE_PARAMETERS 0x03
#define RIGID_DISK_DRIVE_GEOMETRY_PARAMETERS 0x04
#define FLEXIBLE_DISK_PARAMETERS 0x05
#define VERIFY_ERROR_RECOVERY_PARAMETERS 0x07
#define CACHING_PARAMETERS 0x08
#define PERIPHERAL_DEVICE 0x09
#define XOR_CONTROL_MODE_PARAMETERS 0x10
#define CONTROL_MODE_PAGE_PARAMETERS 0x0a
#define MEDIUM_TYPES_SUPPORTED 0x0b
#define NOTCH_PARAMETERS 0x0c
#define POWER_CONDITION_PARAMETERS 0x0d
#define CD_DEVICE_PARAMETERS 0x0d
#define CD_AUDIO_CONTROL_PAGE 0x0e
#define DATA_COMPRESSION_PARAMETERS 0x0f
#define MEDIUM_PARTITION_MODE_PARAMTERES_1 0x11
#define MEDIUM_PARTITION_MODE_PARAMTERES_2 0x12
#define MEDIUM_PARTITION_MODE_PARAMTERES_3 0x13
#define MEDIUM_PARTITION_MODE_PARAMTERES_4 0x14
#define ENCLOSURE_SERVICES_MANAGEMENT 0x14
#define LUN_CONTROL 0x18
#define PORT_CONTROL 0x19
#define POWER_CONTROL 0x1a
#define LUN_MAPPING_PAGE 0x1b
#define INFORMATIONAL_EXCEPTIONS_CONTROL 0x1c
#define FAULT_FAILURE_REPORTING_PAGE 0x1c
#define ELEMENT_ADDRESS_ASSIGNMENT 0x1d
#define TIMEOUT_AND_PROTECT_PARAMETERS 0x1d
#define TRANSPORT_GEOMETRY_PARAMETERS 0x1e
#define DEVICE_CAPABILITIES 0x1f
#define CD_CAPABILITIES_AND_MECHANISM_STATUS 0x2a
#define ALL_PARAMETERS 0x3f
/* defines for functioncode parameter in SENDDIAGNOSTIC function */
#define SCSI_DIAG_NO_SELF_TEST 0x00
#define SCSI_DIAG_SELF_TEST 0xff
#define SCSI_DIAG_BG_SHORT_SELF_TEST 0x01
#define SCSI_DIAG_BG_EXTENDED_SELF_TEST 0x02
#define SCSI_DIAG_FG_SHORT_SELF_TEST 0x05
#define SCSI_DIAG_FG_EXTENDED_SELF_TEST 0x06
#define SCSI_DIAG_ABORT_SELF_TEST 0x04
#define LOGPAGEHDRSIZE 4
/* STANDARD SCSI Commands */
UINT8 testunitready (int device);
UINT8 stdinquiry ( int device, UINT8 *pBuffer);
UINT8 inquiry ( int device, UINT8 pagenum, UINT8 *pBuf);
UINT8 logsense (int device, UINT8 pagenum, UINT8 *pBuffer);
UINT8 modesense ( int device, UINT8 pagenum, UINT8 *pBuffer);
UINT8 modeselect ( int device, UINT8 pagenum, UINT8 *pBuffer);
UINT8 modesense10 ( int device, UINT8 pagenum, UINT8 *pBuffer);
UINT8 modeselect10 ( int device, UINT8 pagenum, UINT8 *pBuffer);
UINT8 requestsense (int device, UINT8 *pBuffer);
UINT8 senddiagnostic (int device, UINT8 functioncode, UINT8 *pBuffer);
UINT8 receivediagnostic (int device, UINT8 pagenum, UINT8 *pBuf);
/* S.M.A.R.T. specific commands */
/*scsSmartSupport return value can be masked with the following */
/* Parsing response of ModePage 1c */
#define DEXCPT_DISABLE 0xf7
#define DEXCPT_ENABLE 0x08
#define EWASC_ENABLE 0x10
#define EWASC_DISABLE 0xef
#define CHECK_SMART_BY_LGPG_2F 0x01
#define CHECK_SMART_BY_REQSENSE 0x00
#define SMART_SENSE_MAX_ENTRY 0x6c
UINT8 scsiCheckSmart(int device, UINT8 method, UINT8 *retval, UINT8 *currenttemp, UINT8 *triptemp);
UINT8 scsiSmartSupport (int device, UINT8 *retval);
UINT8 scsiSmartEWASCEnable (int device);
UINT8 scsiSmartEWASCDisable (int device);
UINT8 scsiSmartDEXCPTEnable (int device);
UINT8 scsiSmartDEXCPTDisable (int device);
/* T10 Standard SMART Sense Code assignment taken from t10.org */
char* scsiSmartGetSenseCode ( UINT8 ascq);
UINT8 scsiGetTemp ( int device, UINT8 *currenttemp, UINT8 *triptemp);
UINT8 scsiSmartOfflineTest (int device);
UINT8 scsiSmartShortSelfTest (int device);
UINT8 scsiSmartExtendSelfTest (int device);
UINT8 scsiSmartShortCapSelfTest (int device);
UINT8 scsiSmartExtendCapSelfTest (int device);
UINT8 scsiSmartSelfTestAbort (int device);
char* scsiTapeAlertsTapeDevice ( unsigned short code);
#endif
This diff is collapsed.
This diff is collapsed.
// $Id: scsiprint.h,v 1.1 2002/10/09 17:56:58 ballen4705 Exp $
/*
* scsiprint.h
*
* Copyright (C) 2002 Bruce Allen <ballen@uwm.edu>
* Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* scsismart version number */
#ifndef SCSI_PRINT_H_
#define SCSI_PRINT_H_
void scsiPrintMain (int fd);
#endif
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment