diff --git a/sm5/atacmds.c b/sm5/atacmds.c index f71be70090173185e95170ee4d6d39623a140d93..a1bcd56d0f544ec032b4c71f4886e3220ee22f91 100644 --- a/sm5/atacmds.c +++ b/sm5/atacmds.c @@ -29,7 +29,7 @@ #include <stdlib.h> #include "atacmds.h" -const char *CVSid1="$Id: atacmds.c,v 1.41 2002/11/22 13:30:55 ballen4705 Exp $" CVSID1; +const char *CVSid1="$Id: atacmds.c,v 1.42 2002/11/25 08:40:48 ballen4705 Exp $" CVSID1; // These Drive Identity tables are taken from hdparm 5.2, and are also // given in the ATA/ATAPI specs for the IDENTIFY DEVICE command. Note @@ -162,7 +162,7 @@ int ataReadHDIdentity (int device, struct hd_driveid *buf){ // See if device responds to packet command... parms[0]=WIN_PIDENTIFY; if (ioctl(device ,HDIO_DRIVE_CMD,parms)){ - perror ("Error ATA GET HD Identity Failed"); + syserror("Error ATA GET HD Identity Failed"); return -1; } } diff --git a/sm5/atacmds.cpp b/sm5/atacmds.cpp index e154a9b45183b5cd3be6e49095586e2e218d1440..1154bc2a2451edf9254ef5a4a95b519d9fa699f8 100644 --- a/sm5/atacmds.cpp +++ b/sm5/atacmds.cpp @@ -29,7 +29,7 @@ #include <stdlib.h> #include "atacmds.h" -const char *CVSid1="$Id: atacmds.cpp,v 1.41 2002/11/22 13:30:55 ballen4705 Exp $" CVSID1; +const char *CVSid1="$Id: atacmds.cpp,v 1.42 2002/11/25 08:40:48 ballen4705 Exp $" CVSID1; // These Drive Identity tables are taken from hdparm 5.2, and are also // given in the ATA/ATAPI specs for the IDENTIFY DEVICE command. Note @@ -162,7 +162,7 @@ int ataReadHDIdentity (int device, struct hd_driveid *buf){ // See if device responds to packet command... parms[0]=WIN_PIDENTIFY; if (ioctl(device ,HDIO_DRIVE_CMD,parms)){ - perror ("Error ATA GET HD Identity Failed"); + syserror("Error ATA GET HD Identity Failed"); return -1; } } diff --git a/sm5/atacmds.h b/sm5/atacmds.h index 34bd8f74b802f79c11c8c28569b45c89201bd484..267d567216e99ea58745ab0fbaa08fa5caa9103d 100644 --- a/sm5/atacmds.h +++ b/sm5/atacmds.h @@ -26,7 +26,7 @@ #define _ATACMDS_H_ #ifndef CVSID1 -#define CVSID1 "$Id: atacmds.h,v 1.25 2002/11/07 11:00:55 ballen4705 Exp $\n" +#define CVSID1 "$Id: atacmds.h,v 1.26 2002/11/25 08:40:48 ballen4705 Exp $\n" #endif // These are the major and minor versions for smartd and smartctl @@ -356,6 +356,9 @@ void pout(char *fmt, ...) #define CVSMAXLEN 512 void printone(char *block, const char *cvsid); +// replacement for perror() with redirected output. +void syserror(const char *message); + // This checks the n'th attribute in the attribute list, NOT the // attribute with id==n. If the attribute does not exist, or the diff --git a/sm5/smartctl.8 b/sm5/smartctl.8 index 9e507d98afc24ec6ae3389d74351d28160312d10..2d2c40de21ac108ac82fb779277bbf16a17b5e12 100644 --- a/sm5/smartctl.8 +++ b/sm5/smartctl.8 @@ -1,6 +1,6 @@ \# Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net> \# -\# $Id: smartctl.8,v 1.27 2002/11/22 13:44:00 ballen4705 Exp $ +\# $Id: smartctl.8,v 1.28 2002/11/25 08:40:48 ballen4705 Exp $ \# \# 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 @@ -16,7 +16,7 @@ \# Research Center), Jack Baskin School of Engineering, University of \# California, Santa Cruz. http://ssrc.soe.ucsc.edu/ \# -.TH SMARTCTL 8 "$Date: 2002/11/22 13:44:00 $" "smartmontools-5.0" +.TH SMARTCTL 8 "$Date: 2002/11/25 08:40:48 $" "smartmontools-5.0" .SH NAME smartctl \- S.M.A.R.T. control and monitor utility .SH SYNOPSIS @@ -48,29 +48,30 @@ changers. .SH SYNTAX .PP .B smartctl -takes two arguments, options and device. Examples are given below. +takes a string of (optional) arguments followed by a mandatory device +name. Examples are given below. -The first argument, options, begins with a '\-' followed by -letters. Multiple options must begin with a single '\-'. The order of -the options does not matter. +The option arguments begin with a '\-' followed by letters. Multiple +options may begin with a single '\-', or each option may have its own '\-'. +The order of the options does not matter. -The second argument is the device to be controlled or -interrogated. ATA devices use the form "/dev/hd*" and SCSI devices use -the form "/dev/sd*". More general paths may also be specified. +The final argument is the device to be controlled or interrogated. ATA +devices use the form "/dev/hd*" and SCSI devices use the form "/dev/sd*". +More general paths may also be specified. .B Smartctl will attempt to guess the device type. If needed, use the '\-n' and '\-N' options respectively for specifying ATA and SCSI device type. SCSI devices only accept the options -.B a, i, c, e, d, O, s, S, x, X, A, N +.B \-a, \-i, \-c, \-e, \-d, \-O, \-s, \-S, \-x, \-X, \-A, \-N and -.B V. +.B \-V. For SCSI Tape Drives and Changers with TapeAlerts support use the devices "/dev/st*" and "/dev/sg*". TapeAlerts devices accept the options -.B a, i, c, e, d, N +.B \-a, \-i, \-c, \-e, \-d, \-N and -.B V. +.B \-V. The options are grouped below into several categories. .B smartctl @@ -82,26 +83,26 @@ DATA, RUN/ABORT TESTS. .TP .B SHOW INFORMATION: .TP -.B V +.B \-V Version: Prints version, Copyright, License, home page and CVS-id information for your copy of .B smartctl. Please include this information if you are reporting bugs or problems. .TP -.B i +.B \-i Information: Prints the disk model number, serial number, firmware version, and ATA Standard version/revision information. Says if the device supports S.M.A.R.T., and if so, whether S.M.A.R.T. support is currently enabled or disabled. .TP -.B a +.B \-a All: Prints all parameters for c,i,g,v,t,l,L (for SCSI c,i). This prints all S.M.A.R.T. information about the disk. .TP .B RUN-TIME BEHAVIOR: .TP -.B q +.B \-q Quiet mode: Only print: For the '\-l' option, if nonzero, the number of errors recorded in the SMART error log and the power-on time when they occured; For the '\-L' option, errors recorded in the device @@ -110,23 +111,23 @@ attributes (pre-failure or usage) which failed either now or in the past; For the '\-v' option device attributes (pre-failure or usage) which failed either now or in the past. .TP -.B Q +.B \-Q Very Quiet mode: Print no ouput. The only way to learn about what was found is to use the exit status of .B smartctl (see RETURN VALUES below). .TP -.B n +.B \-n NotSCSI: Device is an ATA device. .TP -.B N +.B \-N NotATA: Device is a SCSI device. If neither this nor the previous option are specified, then .B smartctl will attempt to guess the device type from the device name. You can use this option or the previous option to force the type. .TP -.B P +.B \-P Permissive: If a mandatory S.M.A.R.T. command to the disk fails, do .I not @@ -139,7 +140,7 @@ device implements the S.M.A.R.T. command set." The 'mandatory' S.M.A.R.T. commands are: (1) Enable/Disable Attribute Autosave, (2) Enable/Disable S.M.A.R.T., and (3) S.M.A.R.T. Return Status. .TP -.B U +.B \-U Ultraconservative: Exit .B smartctl immediately if an optional S.M.A.R.T. command to the disk fails. @@ -149,7 +150,7 @@ would just carry on if an optional command fails. Here "optional" means "Not required by the ATA/ATAPI-5 Specification even if the device implements the S.M.A.R.T. command set." .TP -.B W +.B \-W Warning: Exit .B smartctl immediately if a checksum error is detected in the: (1) Device @@ -171,19 +172,19 @@ will always be issued .B before the correponding disable command. .TP -.B e +.B \-e Enable: Enables S.M.A.R.T. on device. Note that this command (perhaps used with with the '\-t' and '\-f' options) should be placed in a start-up script for your machine, for example in rc.local or rc.sysinit. In princple the S.M.A.R.T. feature settings are preserved over power-cycling, but it doesn't hurt to be sure. .TP -.B d +.B \-d Disable: Disables S.M.A.R.T. on device. This turns off all S.M.A.R.T. functionality. [I can't imagine why you would want to do this. Or do you cover up the oil-pressure warning light on your car?] .TP -.B t +.B \-t Test: Enables S.M.A.R.T. automatic offline test which scans the drive every four hours for disk defects. This command can be given during normal system operation. @@ -226,22 +227,22 @@ S.M.A.R.T. self-test log, which can be examined using the '\-L' option. .TP -.B T +.B \-T unTest: Disables S.M.A.R.T. automatic offline test timer. .TP -.B f +.B \-f File: Enables S.M.A.R.T. autosave of device vendor-specific attributes. Note that this feature is preserved across disk power cycles, so you should only need to issue it once. .TP -.B F +.B \-F unFile: Disables S.M.A.R.T. autosave of device vendor-specific attributes. Note that this feature is preserved across disk power cycles, so you should only need to issue it once. .TP .B S.M.A.R.T. READ AND DISPLAY DATA OPTIONS: .TP -.B c +.B \-c Check: Ask the device to report its S.M.A.R.T. health status. It does this using information that it has gathered from online and offline tests, which were used to determine/update its @@ -255,7 +256,7 @@ that it is predicting its own failure within the next 24 hours. If this happens, use the '\-a' option to get more information, and .B get your data off the disk and someplace safe as soon as you can. .TP -.B g +.B \-g Generic: Prints only the generic S.M.A.R.T. attributes. This shows the S.M.A.R.T. capabilities of the device (can it log errors, does it support offline surface scanning, and so on). If the device can carry @@ -263,7 +264,7 @@ out self-tests, it also lists the estimated time required to run those tests. See REFERENCES below for further information about their meaning. .TP -.B v +.B \-v Vendor: Prints only the vendor specific S.M.A.R.T. attributes. The attributes are numbered from 1 to 253 and have specific names. For example attribute 12 is 'power cycle count': how many times has the @@ -302,7 +303,7 @@ attribute fields has been made entirely vendor-specific. However most ATA/ATAPI-5 disks seem to respect their meaning, so we have retained this option. .TP -.B l +.B \-l Log: Prints only the S.M.A.R.T. error log. S.M.A.R.T. disks maintain a log of the most recent five non-trivial errors. For each of these errors, the disk power-on lifetime at which the error occurred is @@ -314,7 +315,7 @@ took place. [Note: this time stamp wraps after 2^32 milliseconds, or 49 days 17 hours 2 minutes and 47.296 seconds.] The key ATA disk registers are also recorded in the log. .TP -.B L +.B \-L Log: Prints only the S.M.A.R.T. self-test log. The disk maintains a log showing the results of the self tests, which can be run using the '\-S', '\-s', '\-X', and '\-x' options described below. The log will @@ -326,13 +327,13 @@ measured in hours of disk lifetime, is shown. If any errors were detected, the Logical Block Address (LBA) of the first error is printed in hexidecimal notation. .TP -.B a +.B \-a All: Prints all parameters for c,i,g,v,t,l,L (for SCSI c,i). This prints all S.M.A.R.T. information about the disk. .TP .B Vendor-specific Attribute Display Options: .TP -.B m +.B \-m Minutes: The disk stores Raw Attribute number 9 (power on time) in minutes, rather than hours. Divide by 60 before displaying it as "power on hours" when using '\-v' or other options that display Raw values. @@ -343,14 +344,14 @@ on hours" when using '\-v' or other options that display Raw values. only a single one of these tests can be run at a time, so no more than one of the following options should be given on the command line. .TP -.B O +.B \-O Offline: Runs S.M.A.R.T. Immediate offline Test. This immediately starts the test describe above. This command can be given during normal system operation. The effects of this test are visible only in that it updates the S.M.A.R.T. attribute values, and if errors are found they will appear in the S.M.A.R.T. error log, visible with the '\-l' option. .TP -.B S +.B \-S Selftest: Runs S.M.A.R.T. Short Self Test (usually under ten minutes). This command can be given during normal system operation. This is a test in a different category than the immediate or automatic offline @@ -361,23 +362,23 @@ the '\-L' option. Note that on some disks the progress of the test can be monitored by watching this log during the test; with other disks use the '\-g option to monitor progress. .TP -.B s +.B \-s Selftest: Runs the S.M.A.R.T. Short Self Test just described, in Captive Mode. .B WARNING: This test may busy out the drive for the length of the test. .B Only run this on drives without any mounted partitions. .TP -.B X +.B \-X eXtended: Runs S.M.A.R.T. Extended Self Test (tens of minutes). This is a longer and more thorough version of the Short Self Test described under the '\-S' option. Note that this command can be given during normal system operation. .TP -.B x +.B \-x eXtended: Runs the S.M.A.R.T. Extended Self Test just described, in Captive Mode. .B WARNING: This test may busy out the drive for the length of the test. .B Only run this on drives without any mounted partitions. .TP -.B A +.B \-A Abort: Aborts Non-Captive S.M.A.R.T. Self Tests. .PP .SH EXAMPLES @@ -556,4 +557,4 @@ Please let us know if there is an on\-line source for this document. .SH CVS ID OF THIS PAGE: -$Id: smartctl.8,v 1.27 2002/11/22 13:44:00 ballen4705 Exp $ +$Id: smartctl.8,v 1.28 2002/11/25 08:40:48 ballen4705 Exp $ diff --git a/sm5/smartctl.c b/sm5/smartctl.c index 69e15d0263b955599cf8d924bcf94b6ceedbf614..464bb8f28355cf566d046ffb6001431c6f15e488 100644 --- a/sm5/smartctl.c +++ b/sm5/smartctl.c @@ -39,7 +39,7 @@ #include "extern.h" extern const char *CVSid1, *CVSid2, *CVSid3, *CVSid4; -const char* CVSid5="$Id: smartctl.c,v 1.28 2002/11/17 05:57:32 ballen4705 Exp $" +const char* CVSid5="$Id: smartctl.c,v 1.29 2002/11/25 08:40:48 ballen4705 Exp $" CVSID1 CVSID2 CVSID3 CVSID4 CVSID5 CVSID6; // This is a block containing all the "control variables". We declare @@ -317,17 +317,14 @@ int main (int argc, char **argv){ // Part input arguments ParseOpts(argc,argv); - - // Further argument checking - if (argc != 3){ - Usage(); - return FAILCMD; - } - + // open device - read-only mode is enough to issue needed commands - fd = open(device=argv[2], O_RDONLY); + fd = open(device=argv[argc-1], O_RDONLY); if (fd<0) { - perror("Smartctl device open failed"); + char errmsg[256]; + snprintf(errmsg,256,"Smartctl open device: %s failed",argv[argc-1]); + errmsg[255]='\0'; + syserror(errmsg); return FAILDEV; } diff --git a/sm5/smartctl.cpp b/sm5/smartctl.cpp index 7fa60619cec3064d50356eee0117549ad64ad436..34b528ec90f1cde01e94ecdf8338763c4a18e1a1 100644 --- a/sm5/smartctl.cpp +++ b/sm5/smartctl.cpp @@ -39,7 +39,7 @@ #include "extern.h" extern const char *CVSid1, *CVSid2, *CVSid3, *CVSid4; -const char* CVSid5="$Id: smartctl.cpp,v 1.28 2002/11/17 05:57:32 ballen4705 Exp $" +const char* CVSid5="$Id: smartctl.cpp,v 1.29 2002/11/25 08:40:48 ballen4705 Exp $" CVSID1 CVSID2 CVSID3 CVSID4 CVSID5 CVSID6; // This is a block containing all the "control variables". We declare @@ -317,17 +317,14 @@ int main (int argc, char **argv){ // Part input arguments ParseOpts(argc,argv); - - // Further argument checking - if (argc != 3){ - Usage(); - return FAILCMD; - } - + // open device - read-only mode is enough to issue needed commands - fd = open(device=argv[2], O_RDONLY); + fd = open(device=argv[argc-1], O_RDONLY); if (fd<0) { - perror("Smartctl device open failed"); + char errmsg[256]; + snprintf(errmsg,256,"Smartctl open device: %s failed",argv[argc-1]); + errmsg[255]='\0'; + syserror(errmsg); return FAILDEV; }