CVS commit: src/sbin/atactl

2020-12-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 20 10:19:30 UTC 2020

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Managment -> Management


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.84 src/sbin/atactl/atactl.c:1.85
--- src/sbin/atactl/atactl.c:1.84	Mon Dec  7 10:36:19 2020
+++ src/sbin/atactl/atactl.c	Sun Dec 20 10:19:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.84 2020/12/07 10:36:19 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.85 2020/12/20 10:19:30 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.84 2020/12/07 10:36:19 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.85 2020/12/20 10:19:30 jmcneill Exp $");
 #endif
 
 
@@ -306,7 +306,7 @@ static const struct bitinfo ata_sata_cap
 static const struct bitinfo ata_sata_feat[] = {
 	{ SATA_NONZERO_OFFSETS, "Non-zero Offset DMA" },
 	{ SATA_DMA_SETUP_AUTO, "DMA Setup Auto Activate" },
-	{ SATA_DRIVE_PWR_MGMT, "Device-Initiated Interface Power Managment" },
+	{ SATA_DRIVE_PWR_MGMT, "Device-Initiated Interface Power Management" },
 	{ SATA_IN_ORDER_DATA, "In-order Data Delivery" },
 	{ SATA_SW_STTNGS_PRS, "Software Settings Preservation" },
 	{ 0, NULL },



CVS commit: src/sbin/atactl

2020-12-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 20 10:19:30 UTC 2020

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Managment -> Management


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2020-12-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Dec  7 10:36:19 UTC 2020

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
micron SMART 202 is percent lifetime used not remaining.

almost gave myself a heart attack when my server said 7% remaining!


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.83 src/sbin/atactl/atactl.c:1.84
--- src/sbin/atactl/atactl.c:1.83	Thu May 30 21:32:08 2019
+++ src/sbin/atactl/atactl.c	Mon Dec  7 10:36:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.83 2019/05/30 21:32:08 mlelstv Exp $	*/
+/*	$NetBSD: atactl.c,v 1.84 2020/12/07 10:36:19 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.83 2019/05/30 21:32:08 mlelstv Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.84 2020/12/07 10:36:19 mrg Exp $");
 #endif
 
 
@@ -418,7 +418,7 @@ static const struct attr_table micron_sm
 	{ 189,  "Factory bad block count", NULL },
 	{ 197,		"Current pending ECC count", NULL },
 	{ 198,		"SMART offline scan uncorrectable error count", NULL },
-	{ 202,		"Percent lifetime remaining", NULL },
+	{ 202,		"Percent lifetime used", NULL },
 	{ 206,		"Write error rate", NULL },
 	{ 247,		"Number of NAND pages of data written by the host", NULL },
 	{ 248,		"Number of NAND pages written by the FTL", NULL },



CVS commit: src/sbin/atactl

2020-12-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Dec  7 10:36:19 UTC 2020

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
micron SMART 202 is percent lifetime used not remaining.

almost gave myself a heart attack when my server said 7% remaining!


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2019-05-31 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri May 31 16:38:27 UTC 2019

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2019-05-31 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri May 31 16:38:27 UTC 2019

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.30 src/sbin/atactl/atactl.8:1.31
--- src/sbin/atactl/atactl.8:1.30	Fri May 31 05:47:22 2019
+++ src/sbin/atactl/atactl.8	Fri May 31 16:38:27 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: atactl.8,v 1.30 2019/05/31 05:47:22 mlelstv Exp $
+.\"	$NetBSD: atactl.8,v 1.31 2019/05/31 16:38:27 wiz Exp $
 .\"
 .\" Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -50,7 +50,8 @@ It is used by specifying a device or bus
 the command to perform, and any arguments the command may require.
 .Pp
 You may also control devices which are inside a SCSI enclosure, this
-includes many USB disks. In this case ATA commands are passed through
+includes many USB disks.
+In this case ATA commands are passed through
 the SCSI layer using SATL commands.
 .Sh DEVICE COMMANDS
 The following commands may be used on IDE and ATA devices.



CVS commit: src/sbin/atactl

2019-05-30 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri May 31 05:47:22 UTC 2019

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
Mention SATL support.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2019-05-30 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri May 31 05:47:22 UTC 2019

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
Mention SATL support.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.29 src/sbin/atactl/atactl.8:1.30
--- src/sbin/atactl/atactl.8:1.29	Sun Mar  3 04:51:57 2019
+++ src/sbin/atactl/atactl.8	Fri May 31 05:47:22 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: atactl.8,v 1.29 2019/03/03 04:51:57 mrg Exp $
+.\"	$NetBSD: atactl.8,v 1.30 2019/05/31 05:47:22 mlelstv Exp $
 .\"
 .\" Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -48,6 +48,10 @@ control devices which reside on standard
 the ATA bus itself.
 It is used by specifying a device or bus to manipulate,
 the command to perform, and any arguments the command may require.
+.Pp
+You may also control devices which are inside a SCSI enclosure, this
+includes many USB disks. In this case ATA commands are passed through
+the SCSI layer using SATL commands.
 .Sh DEVICE COMMANDS
 The following commands may be used on IDE and ATA devices.
 Note that not all devices support all commands.
@@ -279,6 +283,8 @@ command written by
 significantly enhanced the
 .Cm smart status
 support.
+.An Michael van Elst
+added support for SATL.
 .Sh BUGS
 The output from the
 .Cm identify
@@ -295,3 +301,5 @@ The
 .Cm smart status
 command currently guesses the vendor attribute name table to use,
 and may be wrong or miss supported devices.
+.Pp
+SATL bus commands don't work yet.



CVS commit: src/sbin/atactl

2019-05-30 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu May 30 21:32:08 UTC 2019

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Add support for ATA command pass-through to SCSI devices.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2019-05-30 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu May 30 21:32:08 UTC 2019

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Add support for ATA command pass-through to SCSI devices.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.82 src/sbin/atactl/atactl.c:1.83
--- src/sbin/atactl/atactl.c:1.82	Sun Mar  3 04:51:57 2019
+++ src/sbin/atactl/atactl.c	Thu May 30 21:32:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.82 2019/03/03 04:51:57 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.83 2019/05/30 21:32:08 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.82 2019/03/03 04:51:57 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.83 2019/05/30 21:32:08 mlelstv Exp $");
 #endif
 
 
@@ -54,6 +54,9 @@ __RCSID("$NetBSD: atactl.c,v 1.82 2019/0
 #include 
 #include 
 
+#include 
+#include 
+
 struct ata_smart_error {
 	struct {
 		uint8_t device_control;
@@ -90,6 +93,53 @@ struct ata_smart_errorlog {
 	uint8_t			checksum;
 } __packed;
 
+#define SCSI_ATA_PASS_THROUGH_16	0x85
+struct scsi_ata_pass_through_16 {
+	uint8_t			opcode;
+	uint8_t			byte2;
+#define SATL_NODATA	0x06
+#define SATL_PIO_IN	0x08
+#define SATL_PIO_OUT	0x0a
+#define	SATL_EXTEND	0x01
+	uint8_t			byte3;
+#define SATL_CKCOND	0x20
+#define SATL_READ	0x08
+#define SATL_BLOCKS	0x04
+#define SATL_LEN(x)	((x) & 0x03)
+	uint8_t			features[2];
+	uint8_t			sector_count[2];
+	uint8_t			lba[6];
+	uint8_t			device;
+	uint8_t			ata_cmd;
+	uint8_t			control;
+} __packed;
+
+#define SCSI_ATA_PASS_THROUGH_12	0xa1
+struct scsi_ata_pass_through_12 {
+	uint8_t			opcode;
+	uint8_t			byte2;
+	uint8_t			byte3;
+	uint8_t			features[1];
+	uint8_t			sector_count[1];
+	uint8_t			lba[3];
+	uint8_t			device;
+	uint8_t			ata_cmd;
+	uint8_t			reserved;
+	uint8_t			control;
+} __packed;
+
+struct scsi_ata_return_descriptor {
+	uint8_t			descr;
+#define SCSI_ATA_RETURN_DESCRIPTOR	9
+	uint8_t			additional_length;
+	uint8_t			extend;
+	uint8_t			error;
+	uint8_t			sector_count[2];
+	uint8_t			lba[6];
+	uint8_t			device;
+	uint8_t			status;
+} __packed;
+
 struct command {
 	const char *cmd_name;
 	const char *arg_names;
@@ -103,6 +153,8 @@ struct bitinfo {
 
 __dead static void	usage(void);
 static void	ata_command(struct atareq *);
+static int	satl_command(struct atareq *, int);
+static const uint8_t *satl_return_desc(const uint8_t *, size_t, uint8_t);
 static void	print_bitinfo(const char *, const char *, u_int,
 const struct bitinfo *);
 static void	print_bitinfo2(const char *, const char *, u_int, u_int,
@@ -119,6 +171,7 @@ static void	fillataparams(void);
 static int	is_smart(void);
 
 static int	fd;/* file descriptor for device */
+static int	use_satl;			/* tunnel through SATL */
 static const	char *dvname;			/* device name */
 static char	dvname_store[MAXPATHLEN];	/* for opendisk(3) */
 static const	char *cmdname;			/* command user issued */
@@ -531,10 +584,25 @@ ata_command(struct atareq *req)
 {
 	int error;
 
-	error = ioctl(fd, ATAIOCCOMMAND, req);
-
-	if (error == -1)
-		err(1, "ATAIOCCOMMAND failed");
+	switch (use_satl) {
+	case 0:
+		error = ioctl(fd, ATAIOCCOMMAND, req);
+		if (error == 0)
+			break;
+		if (errno != ENOTTY)
+			err(1, "ATAIOCCOMMAND failed");
+		use_satl = 1;
+		/* FALLTHROUGH */
+	case 1:
+		error = satl_command(req, 16);
+		if (error == 0)
+			return;
+		use_satl = 2;
+		/* FALLTHROUGH */
+	case 2:
+		(void) satl_command(req, 12);
+		return;
+	}
 
 	switch (req->retsts) {
 
@@ -562,6 +630,191 @@ ata_command(struct atareq *req)
 }
 
 /*
+ * Wrapper that calls SCIOCCOMMAND for a tunneled ATA command
+ */
+static int
+satl_command(struct atareq *req, int cmdlen)
+{
+	scsireq_t sreq;
+	int error;
+	union {
+		struct scsi_ata_pass_through_12 cmd12;
+		struct scsi_ata_pass_through_16 cmd16;
+	} c;
+	uint8_t b2, b3;
+	const uint8_t *desc;
+
+	b2 = SATL_NODATA;
+	if (req->datalen > 0) {
+		if (req->flags & ATACMD_READ)
+			b2 = SATL_PIO_IN;
+		else
+			b2 = SATL_PIO_OUT;
+	}
+
+	b3 = SATL_BLOCKS;
+	if (req->datalen > 0) {
+		b3 |= 2; /* sector count holds count */
+	} else {
+		b3 |= SATL_CKCOND;
+	}
+	if (req->datalen == 0 || req->flags & ATACMD_READ)
+		b3 |= SATL_READ;
+
+	switch (cmdlen) {
+	case 16:
+		c.cmd16.opcode = SCSI_ATA_PASS_THROUGH_16;
+		c.cmd16.byte2 = b2;
+		c.cmd16.byte3 = b3;
+		c.cmd16.features[0] = 0;
+		c.cmd16.features[1] = req->features;
+		c.cmd16.sector_count[0] = 0;
+		c.cmd16.sector_count[1] = req->sec_count;
+		c.cmd16.lba[0] = 0;
+		c.cmd16.lba[1] = req->sec_num;
+		c.cmd16.lba[2] = 0;
+		c.cmd16.lba[3] = req->cylinder;
+		c.cmd16.lba[4] = 0;
+		c.cmd16.lba[5] = req->cylinder >> 8;
+		c.cmd16.device = 0;
+		c.cmd16.ata_cmd = req->command;
+		c.cmd16.control = 0;

CVS commit: src/sbin/atactl

2019-03-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Mar  3 04:51:57 UTC 2019

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
- smart vendor support now does try to guess the vendor,
  adjust the BUGS to suit
- claim some copyright


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.81 -r1.82 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.28 src/sbin/atactl/atactl.8:1.29
--- src/sbin/atactl/atactl.8:1.28	Wed Dec  5 14:45:59 2018
+++ src/sbin/atactl/atactl.8	Sun Mar  3 04:51:57 2019
@@ -1,10 +1,10 @@
-.\"	$NetBSD: atactl.8,v 1.28 2018/12/05 14:45:59 wiz Exp $
+.\"	$NetBSD: atactl.8,v 1.29 2019/03/03 04:51:57 mrg Exp $
 .\"
-.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
-.\" by Ken Hornstein.
+.\" by Ken Hornstein and Matthew R. Green.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 5, 2018
+.Dd March 2, 2019
 .Dt ATACTL 8
 .Os
 .Sh NAME
@@ -293,6 +293,5 @@ locked.
 .Pp
 The
 .Cm smart status
-command is currently unable to automatically determine the vendor
-attribute name table to use.
-The vendor must be specified manually.
+command currently guesses the vendor attribute name table to use,
+and may be wrong or miss supported devices.

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.81 src/sbin/atactl/atactl.c:1.82
--- src/sbin/atactl/atactl.c:1.81	Sun Mar  3 04:48:19 2019
+++ src/sbin/atactl/atactl.c	Sun Mar  3 04:51:57 2019
@@ -1,11 +1,11 @@
-/*	$NetBSD: atactl.c,v 1.81 2019/03/03 04:48:19 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.82 2019/03/03 04:51:57 mrg Exp $	*/
 
 /*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Ken Hornstein.
+ * by Ken Hornstein and Matthew R. Green.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.81 2019/03/03 04:48:19 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.82 2019/03/03 04:51:57 mrg Exp $");
 #endif
 
 



CVS commit: src/sbin/atactl

2019-03-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Mar  3 04:51:57 UTC 2019

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
- smart vendor support now does try to guess the vendor,
  adjust the BUGS to suit
- claim some copyright


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.81 -r1.82 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2019-03-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Mar  3 04:48:20 UTC 2019

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add a samsung specific SMART table with:

235 - POR Recovery Count
243 - SATA Downshift Count
244 - Thermal Throttle Status
245 - Timed Workload Media Wear
251 - NAND Writes

all 5 turn up on newer samsung SSDs, though 3 of them all
read 65535 for me across muliplte devices.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.80 src/sbin/atactl/atactl.c:1.81
--- src/sbin/atactl/atactl.c:1.80	Fri Mar  1 02:33:43 2019
+++ src/sbin/atactl/atactl.c	Sun Mar  3 04:48:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.80 2019/03/01 02:33:43 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.81 2019/03/03 04:48:19 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.80 2019/03/01 02:33:43 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.81 2019/03/03 04:48:19 mrg Exp $");
 #endif
 
 
@@ -380,6 +380,18 @@ static const struct attr_table intel_sma
 };
 
 /*
+ * Samsung specific SMART attributes.  Fill me in with more.
+ */
+static const struct attr_table samsung_smart_names[] = {
+	{ 235,  "POR Recovery Count", NULL },
+	{ 243,  "SATA Downshift Count", NULL },
+	{ 244,  "Thermal Throttle Status", NULL },
+	{ 245,  "Timed Workload Media Wear", NULL },
+	{ 251,  "NAND Writes", NULL },
+};
+
+
+/*
  * Vendor-specific SMART attribute table.  Can be used to override
  * a particular attribute name and special printer function, with the
  * default is the main table.
@@ -390,6 +402,7 @@ static const struct vendor_name_table {
 } vendor_smart_names[] = {
 	{ "Micron",		micron_smart_names },
 	{ "Intel",		intel_smart_names },
+	{ "Samsung",		samsung_smart_names },
 };
 
 /*
@@ -410,6 +423,7 @@ static const struct model_to_vendor_tabl
 	{ "MTFDDA",		"Micron" },
 	{ "EEFDDA",		"Micron" },
 	{ "INTEL",		"Intel" },
+	{ "SAMSUNG",		"Samsung" },
 };
 
 static const struct bitinfo ata_sec_st[] = {



CVS commit: src/sbin/atactl

2019-03-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Mar  3 04:48:20 UTC 2019

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add a samsung specific SMART table with:

235 - POR Recovery Count
243 - SATA Downshift Count
244 - Thermal Throttle Status
245 - Timed Workload Media Wear
251 - NAND Writes

all 5 turn up on newer samsung SSDs, though 3 of them all
read 65535 for me across muliplte devices.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2019-02-28 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Mar  1 02:33:43 UTC 2019

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add some intel specific smart values, and be more specific for
a bunch of micron/crucial values.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.79 src/sbin/atactl/atactl.c:1.80
--- src/sbin/atactl/atactl.c:1.79	Wed Dec  5 06:49:54 2018
+++ src/sbin/atactl/atactl.c	Fri Mar  1 02:33:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.79 2018/12/05 06:49:54 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.80 2019/03/01 02:33:43 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.79 2018/12/05 06:49:54 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.80 2019/03/01 02:33:43 mrg Exp $");
 #endif
 
 
@@ -299,7 +299,7 @@ static const struct attr_table {
 	{ 180,  "Unused Reserved Block Count", NULL },
 	{ 181,  "Program Fail Count", NULL },
 	{ 182,  "Erase Fail Count", NULL },
-	{ 183,  "SATA Downshift Error Count", NULL },
+	{ 183,  "Runtime Bad Block", NULL },
 	{ 184,  "End-to-end error", NULL },
 	{ 185,  "Head Stability", NULL },
 	{ 186,  "Induced Op-Vibration Detection", NULL },
@@ -360,6 +360,7 @@ static const struct attr_table micron_sm
 	{   5,		"Reallocated NAND block count", NULL },
 	{ 173,  "Average block erase count", NULL },
 	{ 181,  "Non 4K aligned access count", NULL },
+	{ 183,  "SATA Downshift Error Count", NULL },
 	{ 184,  "Error correction count", NULL },
 	{ 189,  "Factory bad block count", NULL },
 	{ 197,		"Current pending ECC count", NULL },
@@ -372,15 +373,43 @@ static const struct attr_table micron_sm
 };
 
 /*
+ * Intel specific SMART attributes.  Fill me in with more.
+ */
+static const struct attr_table intel_smart_names[] = {
+	{ 183,  "SATA Downshift Error Count", NULL },
+};
+
+/*
  * Vendor-specific SMART attribute table.  Can be used to override
  * a particular attribute name and special printer function, with the
  * default is the main table.
  */
-const struct vendor_name_table {
+static const struct vendor_name_table {
 	const char *name;
 	const struct attr_table *table;
 } vendor_smart_names[] = {
-	{ .name = "Micron", .table = micron_smart_names },
+	{ "Micron",		micron_smart_names },
+	{ "Intel",		intel_smart_names },
+};
+
+/*
+ * Global model -> vendor table.  Extend this to regexp.
+ */
+static const struct model_to_vendor_table {
+	const char *model;
+	const char *vendor;
+} model_to_vendor[] = {
+	{ "Crucial",		"Micron" },
+	{ "Micron",		"Micron" },
+	{ "C300-CT",		"Micron" },
+	{ "C400-MT",		"Micron" },
+	{ "M4-CT",		"Micron" },
+	{ "M500",		"Micron" },
+	{ "M510",		"Micron" },
+	{ "M550",		"Micron" },
+	{ "MTFDDA",		"Micron" },
+	{ "EEFDDA",		"Micron" },
+	{ "INTEL",		"Intel" },
 };
 
 static const struct bitinfo ata_sec_st[] = {
@@ -1009,21 +1038,7 @@ compute_capacity(uint64_t *capacityp, ui
 static const char *
 guess_vendor(void)
 {
-	struct {
-		const char *model;
-		const char *vendor;
-	} model_to_vendor[] = {
-		{ "Crucial", "Micron" },
-		{ "Micron", "Micron" },
-		{ "C300-CT", "Micron" },
-		{ "C400-MT", "Micron" },
-		{ "M4-CT", "Micron" },
-		{ "M500", "Micron" },
-		{ "M510", "Micron" },
-		{ "M550", "Micron" },
-		{ "MTFDDA", "Micron" },
-		{ "EEFDDA", "Micron" },
-	};
+
 	unsigned i;
 
 	for (i = 0; i < __arraycount(model_to_vendor); i++)



CVS commit: src/sbin/atactl

2019-02-28 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Mar  1 02:33:43 UTC 2019

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add some intel specific smart values, and be more specific for
a bunch of micron/crucial values.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2018-12-05 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Dec  5 14:45:59 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.27 src/sbin/atactl/atactl.8:1.28
--- src/sbin/atactl/atactl.8:1.27	Wed Dec  5 06:49:54 2018
+++ src/sbin/atactl/atactl.8	Wed Dec  5 14:45:59 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: atactl.8,v 1.27 2018/12/05 06:49:54 mrg Exp $
+.\"	$NetBSD: atactl.8,v 1.28 2018/12/05 14:45:59 wiz Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -276,7 +276,7 @@ It was based heavily on the
 command written by
 .An Jason R. Thorpe .
 .An Matthew R. Green
-significantly enhanced the 
+significantly enhanced the
 .Cm smart status
 support.
 .Sh BUGS



CVS commit: src/sbin/atactl

2018-12-05 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Dec  5 14:45:59 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2018-12-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec  5 06:49:54 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
"smart status" already obtains the ata parameters to check if smart
is actually supported, so we can attempt to guess a vendor smart
table from the model name.  add basic support for all the micron /
crucial disk names i could find, and add a couple more micron
specific values.

XXX: probably should add regex support for matching, and probably
 should be more restrictive with the current matches.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.78 -r1.79 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.26 src/sbin/atactl/atactl.8:1.27
--- src/sbin/atactl/atactl.8:1.26	Sat Nov  3 10:51:14 2018
+++ src/sbin/atactl/atactl.8	Wed Dec  5 06:49:54 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: atactl.8,v 1.26 2018/11/03 10:51:14 wiz Exp $
+.\"	$NetBSD: atactl.8,v 1.27 2018/12/05 06:49:54 mrg Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 4, 2018
+.Dd December 5, 2018
 .Dt ATACTL 8
 .Os
 .Sh NAME
@@ -162,6 +162,8 @@ information if known to
 Currently, only
 .Dq micron
 has a vendor-specific table.
+If the vendor is not supplied, it may be guessed from devices' model
+or other data available.
 .It Ar offline #
 Runs the numbered offline self-test on the drive.
 .It Ar error-log
@@ -273,6 +275,10 @@ It was based heavily on the
 .Xr scsictl 8
 command written by
 .An Jason R. Thorpe .
+.An Matthew R. Green
+significantly enhanced the 
+.Cm smart status
+support.
 .Sh BUGS
 The output from the
 .Cm identify

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.78 src/sbin/atactl/atactl.c:1.79
--- src/sbin/atactl/atactl.c:1.78	Wed Oct 31 20:00:56 2018
+++ src/sbin/atactl/atactl.c	Wed Dec  5 06:49:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.78 2018/10/31 20:00:56 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.79 2018/12/05 06:49:54 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.78 2018/10/31 20:00:56 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.79 2018/12/05 06:49:54 mrg Exp $");
 #endif
 
 
@@ -114,7 +114,7 @@ static void	print_selftest_entry(int, co
 static void	print_error(const void *);
 static void	print_selftest(const void *);
 
-static const struct ataparams *getataparams(void);
+static void	fillataparams(void);
 
 static int	is_smart(void);
 
@@ -122,6 +122,10 @@ static int	fd;/* file descriptor for
 static const	char *dvname;			/* device name */
 static char	dvname_store[MAXPATHLEN];	/* for opendisk(3) */
 static const	char *cmdname;			/* command user issued */
+static const	struct ataparams *inqbuf;	/* inquiry buffer */
+static char	model[sizeof(inqbuf->atap_model)+1];
+static char	revision[sizeof(inqbuf->atap_revision)+1];
+static char	serial[sizeof(inqbuf->atap_serial)+1];
 
 static void	device_identify(int, char *[]);
 static void	device_setidle(int, char *[]);
@@ -355,7 +359,9 @@ static const struct attr_table {
 static const struct attr_table micron_smart_names[] = {
 	{   5,		"Reallocated NAND block count", NULL },
 	{ 173,  "Average block erase count", NULL },
+	{ 181,  "Non 4K aligned access count", NULL },
 	{ 184,  "Error correction count", NULL },
+	{ 189,  "Factory bad block count", NULL },
 	{ 197,		"Current pending ECC count", NULL },
 	{ 198,		"SMART offline scan uncorrectable error count", NULL },
 	{ 202,		"Percent lifetime remaining", NULL },
@@ -855,14 +861,19 @@ print_selftest(const void *buf)
 		print_selftest_entry(i, >log_entries[i]);
 }
 
-static const struct ataparams *
-getataparams(void)
+static void
+fillataparams(void)
 {
 	struct atareq req;
 	static union {
 		unsigned char inbuf[DEV_BSIZE];
 		struct ataparams inqbuf;
 	} inbuf;
+	static int first = 1;
+
+	if (!first)
+		return;
+	first = 0;
 
 	memset(, 0, sizeof(inbuf));
 	memset(, 0, sizeof(req));
@@ -875,7 +886,7 @@ getataparams(void)
 
 	ata_command();
 
-	return ();
+	inqbuf = 
 }
 
 /*
@@ -888,10 +899,9 @@ static int
 is_smart(void)
 {
 	int retval = 0;
-	const struct ataparams *inqbuf;
 	const char *status;
 
-	inqbuf = getataparams();
+	fillataparams();
 
 	if (inqbuf->atap_cmd_def != 0 && inqbuf->atap_cmd_def != 0x) {
 		if (!(inqbuf->atap_cmd_set1 & WDC_CMD1_SMART)) {
@@ -951,8 +961,7 @@ extract_string(char *buf, size_t bufmax,
 }
 
 static void
-compute_capacity(const struct ataparams *inqbuf, uint64_t *capacityp,
-uint64_t *sectorsp, uint32_t *secsizep)
+compute_capacity(uint64_t *capacityp, uint64_t 

CVS commit: src/sbin/atactl

2018-12-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec  5 06:49:54 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
"smart status" already obtains the ata parameters to check if smart
is actually supported, so we can attempt to guess a vendor smart
table from the model name.  add basic support for all the micron /
crucial disk names i could find, and add a couple more micron
specific values.

XXX: probably should add regex support for matching, and probably
 should be more restrictive with the current matches.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.78 -r1.79 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2018-11-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Nov  3 10:51:14 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
Use more appropriate macros. Make a sentence easier to read.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2018-11-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Nov  3 10:51:14 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8

Log Message:
Use more appropriate macros. Make a sentence easier to read.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sbin/atactl/atactl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.25 src/sbin/atactl/atactl.8:1.26
--- src/sbin/atactl/atactl.8:1.25	Wed Oct 31 20:00:56 2018
+++ src/sbin/atactl/atactl.8	Sat Nov  3 10:51:14 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: atactl.8,v 1.25 2018/10/31 20:00:56 mrg Exp $
+.\"	$NetBSD: atactl.8,v 1.26 2018/11/03 10:51:14 wiz Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -84,7 +84,7 @@ A value of 0 will disable the Standby ti
 .It Cm checkpower
 Will print out if the device is in Active, Idle, or Standby power
 management mode.
-.It Cm apm Bq Ar disable | set #
+.It Cm apm Oo Ar disable | set # Oc
 Controls the Advanced Power Management feature of the specified device.
 Advanced Power Management is an optional feature used to specify a power
 management level to balance between device performance and power consumption.
@@ -103,7 +103,7 @@ and other from 127 to 253.
 Per the specification, values of 127 and higher do not permit the device
 to spin down to save power.
 .El
-.It Cm smart Bq Ar enable | disable | status [ vendor ] | offline # | error-log | selftest-log
+.It Cm smart Oo Ar enable | disable | status Oo vendor Oc | offline # | error-log | selftest-log Oc
 Controls SMART feature set of the specified device.
 SMART stands for Self-Monitoring, Analysis, and Reporting Technology.
 It provides an early warning system by comparing subtle operation
@@ -119,7 +119,7 @@ be preserved by the device across power 
 .It Ar disable
 Disables access to SMART capabilities within the device.
 Attribute values will be saved, and will no longer be monitored.
-.It Ar status Bq Ar vendor
+.It Ar status Op Ar vendor
 Reports whether SMART is supported by the device, and whether SMART is
 enabled on the device (can only be determined on ATA6 or better devices).
 If SMART is enabled, then a table of attribute information is printed.
@@ -169,7 +169,7 @@ Prints the error log.
 .It Ar selftest-log
 Prints the self-test log.
 .El
-.It Cm security Bq Ar status | freeze | setpass | unlock | disable | erase
+.It Cm security Oo Ar status | freeze | setpass | unlock | disable | erase Oc
 Controls
 .Dq security
 (password protection) features of modern ATA drives.
@@ -188,13 +188,13 @@ command early in the boot process.
 displays the drive's security status
 .It Ar freeze
 freezes the drive's security status
-.It Ar setpass Bq user | master
+.It Ar setpass Oo user | master Oc
 sets the drive's user or master password
-.It Ar unlock Bq user | master
+.It Ar unlock Oo user | master Oc
 unlocks a password-protected drive
-.It Ar disable Bq user | master
+.It Ar disable Oo user | master Oc
 disables password protection
-.It Ar erase Bq user | master
+.It Ar erase Oo user | master Oc
 erases the device and clears security state, using enhanced erasure if
 the drive supports it; may take a long time to run
 .El
@@ -264,12 +264,15 @@ The
 command first appeared in
 .Nx 1.4 .
 .Sh AUTHORS
+.An -nosplit
 The
 .Nm
-command was written by Ken Hornstein.
+command was written by
+.An Ken Hornstein .
 It was based heavily on the
 .Xr scsictl 8
-command written by Jason R. Thorpe.
+command written by
+.An Jason R. Thorpe .
 .Sh BUGS
 The output from the
 .Cm identify
@@ -285,4 +288,5 @@ locked.
 The
 .Cm smart status
 command is currently unable to automatically determine the vendor
-attribute name table to use, and must be specified manually.
+attribute name table to use.
+The vendor must be specified manually.



CVS commit: src/sbin/atactl

2018-10-31 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Oct 31 20:00:56 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
extend "smart status" command to "smart status [vendor]", and supply a
"Micron" (for Micron/Crucial) list with their documented values.

this allows the vendor-specific data to be used.

there appears to be no simple way to automatically determine the right
vendor to use -- identify data seems to be the only obvious way and
that data can be and is changed by OEMs.  (eg, a disk may be listed as
being "dell", but dell don't make disks.)  as such, no attempt is made
to automatically determine if a vendor list should be used.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.77 -r1.78 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.24 src/sbin/atactl/atactl.8:1.25
--- src/sbin/atactl/atactl.8:1.24	Wed Jan  9 21:58:23 2013
+++ src/sbin/atactl/atactl.8	Wed Oct 31 20:00:56 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: atactl.8,v 1.24 2013/01/09 21:58:23 riastradh Exp $
+.\"	$NetBSD: atactl.8,v 1.25 2018/10/31 20:00:56 mrg Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 9, 2013
+.Dd October 4, 2018
 .Dt ATACTL 8
 .Os
 .Sh NAME
@@ -103,7 +103,7 @@ and other from 127 to 253.
 Per the specification, values of 127 and higher do not permit the device
 to spin down to save power.
 .El
-.It Cm smart Bq Ar enable | disable | status | offline # | error-log | selftest-log
+.It Cm smart Bq Ar enable | disable | status [ vendor ] | offline # | error-log | selftest-log
 Controls SMART feature set of the specified device.
 SMART stands for Self-Monitoring, Analysis, and Reporting Technology.
 It provides an early warning system by comparing subtle operation
@@ -119,7 +119,7 @@ be preserved by the device across power 
 .It Ar disable
 Disables access to SMART capabilities within the device.
 Attribute values will be saved, and will no longer be monitored.
-.It Ar status
+.It Ar status Bq Ar vendor
 Reports whether SMART is supported by the device, and whether SMART is
 enabled on the device (can only be determined on ATA6 or better devices).
 If SMART is enabled, then a table of attribute information is printed.
@@ -153,6 +153,15 @@ The collect field indicates whether this
 device is online.
 The reliability field indicates whether the attribute
 value is within the acceptable threshold.
+.Pp
+If the
+.Ar vendor
+argument is supplied, a vendor-specific table will be used for SMART
+information if known to
+.Nm .
+Currently, only
+.Dq micron
+has a vendor-specific table.
 .It Ar offline #
 Runs the numbered offline self-test on the drive.
 .It Ar error-log
@@ -272,3 +281,8 @@ The
 .Nx
 kernel behaves poorly with drives that have passwords set and are
 locked.
+.Pp
+The
+.Cm smart status
+command is currently unable to automatically determine the vendor
+attribute name table to use, and must be specified manually.

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.77 src/sbin/atactl/atactl.c:1.78
--- src/sbin/atactl/atactl.c:1.77	Tue Oct  4 21:37:46 2016
+++ src/sbin/atactl/atactl.c	Wed Oct 31 20:00:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.77 2016/10/04 21:37:46 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.78 2018/10/31 20:00:56 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.77 2016/10/04 21:37:46 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.78 2018/10/31 20:00:56 mrg Exp $");
 #endif
 
 
@@ -107,7 +107,7 @@ static void	print_bitinfo(const char *, 
 const struct bitinfo *);
 static void	print_bitinfo2(const char *, const char *, u_int, u_int,
 const struct bitinfo *);
-static void	print_smart_status(void *, void *);
+static void	print_smart_status(void *, void *, const char *);
 static void	print_error_entry(int, const struct ata_smart_error *);
 static void	print_selftest_entry(int, const struct ata_smart_selftest *);
 
@@ -143,7 +143,7 @@ static const struct command device_comma
 	{ "sleep",	"",			device_idle },
 	{ "checkpower",	"",			device_checkpower },
 	{ "smart",
-		"enable|disable|status|offline #|error-log|selftest-log",
+		"enable|disable|status [vendor]|offline #|error-log|selftest-log",
 		device_smart },
 	{ "security",
 		"status|freeze|[setpass|unlock|disable|erase] [user|master]",
@@ -255,8 +255,15 @@ static const struct bitinfo ata_sata_fea
 	{ 0, NULL },
 };
 
-static const struct {
-	const int	id;
+/*
+ * Global SMART attribute table.  All known attributes should be defined
+ * here with overrides outside of the standard 

CVS commit: src/sbin/atactl

2018-10-31 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Oct 31 20:00:56 UTC 2018

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
extend "smart status" command to "smart status [vendor]", and supply a
"Micron" (for Micron/Crucial) list with their documented values.

this allows the vendor-specific data to be used.

there appears to be no simple way to automatically determine the right
vendor to use -- identify data seems to be the only obvious way and
that data can be and is changed by OEMs.  (eg, a disk may be listed as
being "dell", but dell don't make disks.)  as such, no attempt is made
to automatically determine if a vendor list should be used.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.77 -r1.78 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2016-10-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Oct  4 21:37:46 UTC 2016

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add SMART 249: Total Raw NAND Writes (1GiB units), sourced from
intel spec sheets.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.76 src/sbin/atactl/atactl.c:1.77
--- src/sbin/atactl/atactl.c:1.76	Tue May 10 08:08:59 2016
+++ src/sbin/atactl/atactl.c	Tue Oct  4 21:37:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.76 2016/05/10 08:08:59 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.77 2016/10/04 21:37:46 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.76 2016/05/10 08:08:59 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.77 2016/10/04 21:37:46 mrg Exp $");
 #endif
 
 
@@ -335,6 +335,7 @@ static const struct {
 	{ 246,		"Total Host Sector Writes", NULL },
 	{ 247,		"Host Program NAND Pages Count", NULL },
 	{ 248,		"FTL Program Pages Count ", NULL },
+	{ 249,		"Total Raw NAND Writes (1GiB units)", NULL },
 	{ 250,		"Read error retry rate", NULL },
 	{ 254,		"Free Fall Sensor", NULL },
 	{   0,		"Unknown", NULL },



CVS commit: src/sbin/atactl

2016-10-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Oct  4 21:37:46 UTC 2016

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add SMART 249: Total Raw NAND Writes (1GiB units), sourced from
intel spec sheets.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2016-05-10 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue May 10 08:08:59 UTC 2016

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
update the micron smart codes for 247/248 to match data i found in
micron's "TN-FD-33: M510DC SSD SMART Implementation Introduction"
document.

these two values can be used to calculate the write amplication
factor:

   WAF = ( A247 + A248 ) / A247


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.75 src/sbin/atactl/atactl.c:1.76
--- src/sbin/atactl/atactl.c:1.75	Mon Sep 21 06:05:00 2015
+++ src/sbin/atactl/atactl.c	Tue May 10 08:08:59 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.75 2015/09/21 06:05:00 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.76 2016/05/10 08:08:59 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.75 2015/09/21 06:05:00 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.76 2016/05/10 08:08:59 mrg Exp $");
 #endif
 
 
@@ -333,8 +333,8 @@ static const struct {
 	{ 241,		"Total LBAs Written", NULL },
 	{ 242,		"Total LBAs Read", NULL },
 	{ 246,		"Total Host Sector Writes", NULL },
-	{ 247,		"Contact Factory (Micron)", NULL },
-	{ 248,		"Contact Factory (Micron)", NULL },
+	{ 247,		"Host Program NAND Pages Count", NULL },
+	{ 248,		"FTL Program Pages Count ", NULL },
 	{ 250,		"Read error retry rate", NULL },
 	{ 254,		"Free Fall Sensor", NULL },
 	{   0,		"Unknown", NULL },



CVS commit: src/sbin/atactl

2016-05-10 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue May 10 08:08:59 UTC 2016

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
update the micron smart codes for 247/248 to match data i found in
micron's "TN-FD-33: M510DC SSD SMART Implementation Introduction"
document.

these two values can be used to calculate the write amplication
factor:

   WAF = ( A247 + A248 ) / A247


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2015-09-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep 21 06:05:00 UTC 2015

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add smart IDs 210, 246, 247 and 248 (Micron):
+   { 210,  "Successful RAIN Recovery Count", NULL },
+   { 246,  "Total Host Sector Writes", NULL },
+   { 247,  "Contact Factory (Micron)", NULL },
+   { 248,  "Contact Factory (Micron)", NULL },

(eek i hope 247 and 248 don't move.)


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.74 src/sbin/atactl/atactl.c:1.75
--- src/sbin/atactl/atactl.c:1.74	Wed Oct 15 06:54:04 2014
+++ src/sbin/atactl/atactl.c	Mon Sep 21 06:05:00 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.74 2014/10/15 06:54:04 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.75 2015/09/21 06:05:00 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.74 2014/10/15 06:54:04 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.75 2015/09/21 06:05:00 mrg Exp $");
 #endif
 
 
@@ -315,6 +315,7 @@ static const struct {
 	{ 207,		"Spin high current", NULL },
 	{ 208,		"Spin buzz", NULL },
 	{ 209,		"Offline seek performance", NULL },
+	{ 210,		"Successful RAIN Recovery Count", NULL },
 	{ 220,		"Disk shift", NULL },
 	{ 221,		"G-Sense error rate", NULL },
 	{ 222,		"Loaded hours", NULL },
@@ -331,6 +332,9 @@ static const struct {
 	{ 240,		"Head flying hours", NULL },
 	{ 241,		"Total LBAs Written", NULL },
 	{ 242,		"Total LBAs Read", NULL },
+	{ 246,		"Total Host Sector Writes", NULL },
+	{ 247,		"Contact Factory (Micron)", NULL },
+	{ 248,		"Contact Factory (Micron)", NULL },
 	{ 250,		"Read error retry rate", NULL },
 	{ 254,		"Free Fall Sensor", NULL },
 	{   0,		"Unknown", NULL },



CVS commit: src/sbin/atactl

2015-09-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep 21 06:05:00 UTC 2015

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add smart IDs 210, 246, 247 and 248 (Micron):
+   { 210,  "Successful RAIN Recovery Count", NULL },
+   { 246,  "Total Host Sector Writes", NULL },
+   { 247,  "Contact Factory (Micron)", NULL },
+   { 248,  "Contact Factory (Micron)", NULL },

(eek i hope 247 and 248 don't move.)


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2014-10-15 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Oct 15 06:54:04 UTC 2014

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add a whole bunch of S.M.A.R.T. status i found around various sources.

now nothing on my new SSD is unknown, except #249.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.73 src/sbin/atactl/atactl.c:1.74
--- src/sbin/atactl/atactl.c:1.73	Mon Dec  9 09:35:16 2013
+++ src/sbin/atactl/atactl.c	Wed Oct 15 06:54:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.73 2013/12/09 09:35:16 wiz Exp $	*/
+/*	$NetBSD: atactl.c,v 1.74 2014/10/15 06:54:04 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.73 2013/12/09 09:35:16 wiz Exp $);
+__RCSID($NetBSD: atactl.c,v 1.74 2014/10/15 06:54:04 mrg Exp $);
 #endif
 
 
@@ -273,8 +273,27 @@ static const struct {
 	{  11,		Calibration retry count, NULL },
 	{  12,		Device power cycle count, NULL },
 	{  13,		Soft read error rate, NULL },
+	{ 100,  Erase/Program Cycles, NULL },
+	{ 103,  Translation Table Rebuild, NULL },
+	{ 170,  Reserved Block Count, NULL },
+	{ 171,  Program Fail Count, NULL },
+	{ 172,  Erase Fail Count, NULL },
+	{ 173,  Wear Leveller Worst Case Erase Count, NULL },
+	{ 174,  Unexpected Power Loss, NULL },
+	{ 175,  Program Fail Count, NULL },
+	{ 176,  Erase Fail Count, NULL },
+	{ 177,  Wear Leveling Count, NULL },
+	{ 178,  Used Reserved Block Count, NULL },
+	{ 179,  Used Reserved Block Count, NULL },
+	{ 180,  Unused Reserved Block Count, NULL },
+	{ 181,  Program Fail Count, NULL },
+	{ 182,  Erase Fail Count, NULL },
+	{ 183,  SATA Downshift Error Count, NULL },
 	{ 184,  End-to-end error, NULL },
+	{ 185,  Head Stability, NULL },
+	{ 186,  Induced Op-Vibration Detection, NULL },
 	{ 187,  Reported uncorrect, NULL },
+	{ 188,  Command Timeout, NULL },
 	{ 189,  High Fly Writes, NULL },
 	{ 190,  Airflow Temperature,		device_smart_temp },
 	{ 191,		G-sense error rate, NULL },
@@ -310,7 +329,10 @@ static const struct {
 	{ 232,		Available reserved space, NULL },
 	{ 233,		Media wearout indicator, NULL },
 	{ 240,		Head flying hours, NULL },
+	{ 241,		Total LBAs Written, NULL },
+	{ 242,		Total LBAs Read, NULL },
 	{ 250,		Read error retry rate, NULL },
+	{ 254,		Free Fall Sensor, NULL },
 	{   0,		Unknown, NULL },
 };
 



CVS commit: src/sbin/atactl

2014-10-15 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Oct 15 06:54:04 UTC 2014

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
add a whole bunch of S.M.A.R.T. status i found around various sources.

now nothing on my new SSD is unknown, except #249.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2013-08-03 Thread Soren S. Jorvang
Module Name:src
Committed By:   soren
Date:   Sat Aug  3 18:35:31 UTC 2013

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Don't use \t to align text columns.
Add a few attribute descriptions.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.69 src/sbin/atactl/atactl.c:1.70
--- src/sbin/atactl/atactl.c:1.69	Fri Feb  8 03:58:36 2013
+++ src/sbin/atactl/atactl.c	Sat Aug  3 18:35:31 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.69 2013/02/08 03:58:36 jakllsch Exp $	*/
+/*	$NetBSD: atactl.c,v 1.70 2013/08/03 18:35:31 soren Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.69 2013/02/08 03:58:36 jakllsch Exp $);
+__RCSID($NetBSD: atactl.c,v 1.70 2013/08/03 18:35:31 soren Exp $);
 #endif
 
 
@@ -191,9 +191,9 @@ static const struct bitinfo ata_cmd_set1
 	{ WDC_CMD1_HPA, Host Protected Area feature set },
 	{ WDC_CMD1_DVRST, DEVICE RESET command },
 	{ WDC_CMD1_SRV, SERVICE interrupt },
-	{ WDC_CMD1_RLSE, release interrupt },
-	{ WDC_CMD1_AHEAD, look-ahead },
-	{ WDC_CMD1_CACHE, write cache },
+	{ WDC_CMD1_RLSE, Release interrupt },
+	{ WDC_CMD1_AHEAD, Look-ahead },
+	{ WDC_CMD1_CACHE, Write cache },
 	{ WDC_CMD1_PKT, PACKET command feature set },
 	{ WDC_CMD1_PM, Power Management feature set },
 	{ WDC_CMD1_REMOV, Removable Media feature set },
@@ -273,6 +273,7 @@ static const struct {
 	{  11,		Calibration retry count, NULL },
 	{  12,		Device power cycle count, NULL },
 	{  13,		Soft read error rate, NULL },
+	{ 184,  End-to-end error, NULL },
 	{ 187,  Reported uncorrect, NULL },
 	{ 189,  High Fly Writes, NULL },
 	{ 190,  Airflow Temperature,		device_smart_temp },
@@ -306,6 +307,8 @@ static const struct {
 	{ 228,		Power-off retract count, NULL },
 	{ 230,		GMR head amplitude, NULL },
 	{ 231,		Temperature,			device_smart_temp },
+	{ 232,		Available reserved space, NULL },
+	{ 233,		Media wearout indicator, NULL },
 	{ 240,		Head flying hours, NULL },
 	{ 250,		Read error retry rate, NULL },
 	{   0,		Unknown, NULL },
@@ -518,7 +521,7 @@ print_smart_status(void *vbuf, void *tbu
 	}
 
 	printf(id value thresh crit collect reliability description
-	\t\t\traw\n);
+	 raw\n);
 	for (i = 0; i  256; i++) {
 		int thresh = 0;
 
@@ -546,7 +549,7 @@ print_smart_status(void *vbuf, void *tbu
 
 		flags = le16toh(attr-flags);
 
-		printf(%3d %3d  %3d %-3s %-7s %stive%-24s\t,
+		printf(%3d %3d  %3d %-3s %-7s %stive%-27s ,
 		i, attr-value, thresh,
 		flags  WDSM_ATTR_ADVISORY ? yes : no,
 		flags  WDSM_ATTR_COLLECTIVE ? online : offline,



CVS commit: src/sbin/atactl

2013-08-03 Thread Soren S. Jorvang
Module Name:src
Committed By:   soren
Date:   Sat Aug  3 18:35:31 UTC 2013

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Don't use \t to align text columns.
Add a few attribute descriptions.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2013-02-07 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Feb  8 03:58:36 UTC 2013

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Decode 6Gbps signaling SATA capability in IDENTIFY DEVICE data.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.68 src/sbin/atactl/atactl.c:1.69
--- src/sbin/atactl/atactl.c:1.68	Wed Jan  9 21:58:23 2013
+++ src/sbin/atactl/atactl.c	Fri Feb  8 03:58:36 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.68 2013/01/09 21:58:23 riastradh Exp $	*/
+/*	$NetBSD: atactl.c,v 1.69 2013/02/08 03:58:36 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.68 2013/01/09 21:58:23 riastradh Exp $);
+__RCSID($NetBSD: atactl.c,v 1.69 2013/02/08 03:58:36 jakllsch Exp $);
 #endif
 
 
@@ -239,6 +239,7 @@ static const struct bitinfo ata_cmd_ext[
 static const struct bitinfo ata_sata_caps[] = {
 	{ SATA_SIGNAL_GEN1, 1.5Gb/s signaling },
 	{ SATA_SIGNAL_GEN2, 3.0Gb/s signaling },
+	{ SATA_SIGNAL_GEN3, 6.0Gb/s signaling },
 	{ SATA_NATIVE_CMDQ, Native Command Queuing },
 	{ SATA_HOST_PWR_MGMT, Host-Initiated Interface Power Management },
 	{ SATA_PHY_EVNT_CNT, PHY Event Counters },



CVS commit: src/sbin/atactl

2013-02-07 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Feb  8 03:58:36 UTC 2013

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Decode 6Gbps signaling SATA capability in IDENTIFY DEVICE data.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2013-01-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan  9 21:58:24 UTC 2013

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
Add some ATA SECURITY commands to atactl(8).


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.67 -r1.68 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.8
diff -u src/sbin/atactl/atactl.8:1.23 src/sbin/atactl/atactl.8:1.24
--- src/sbin/atactl/atactl.8:1.23	Wed Apr 30 13:10:52 2008
+++ src/sbin/atactl/atactl.8	Wed Jan  9 21:58:23 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: atactl.8,v 1.23 2008/04/30 13:10:52 martin Exp $
+.\	$NetBSD: atactl.8,v 1.24 2013/01/09 21:58:23 riastradh Exp $
 .\
 .\ Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd November 18, 2007
+.Dd January 9, 2013
 .Dt ATACTL 8
 .Os
 .Sh NAME
@@ -160,7 +160,7 @@ Prints the error log.
 .It Ar selftest-log
 Prints the self-test log.
 .El
-.It Cm security Bq Ar freeze | status
+.It Cm security Bq Ar status | freeze | setpass | unlock | disable | erase
 Controls
 .Dq security
 (password protection) features of modern ATA drives.
@@ -175,11 +175,46 @@ sense to issue the
 .Dq freeze
 command early in the boot process.
 .Bl -tag -width freezeXX
-.It Ar freeze
-freezes the drive's security status
 .It Ar status
 displays the drive's security status
+.It Ar freeze
+freezes the drive's security status
+.It Ar setpass Bq user | master
+sets the drive's user or master password
+.It Ar unlock Bq user | master
+unlocks a password-protected drive
+.It Ar disable Bq user | master
+disables password protection
+.It Ar erase Bq user | master
+erases the device and clears security state, using enhanced erasure if
+the drive supports it; may take a long time to run
 .El
+.Pp
+Note that to erase a drive, it must have a password set and be
+unfrozen.
+If you can't persuade your firmware to leave the drive unfrozen on
+boot, but it is a SATA drive, say
+.Pa wd2
+at
+.Pa atabus3 ,
+that you can safely physically disconnect and reconnect, then you may
+be able to use SATA hot-plug to work around this: first run
+.Bd -literal -offset indent
+# drvctl -d wd2
+.Ed
+.Pp
+Then physically disconnect and reconnect the drive, and run
+.Bd -literal -offset indent
+# drvctl -r -a ata_hl atabus3
+.Ed
+.Pp
+After this, check that the security status does not list
+.Dq frozen :
+.Bd -literal -offset indent
+# atactl wd2 security status
+	supported
+#
+.Ed
 .El
 .Sh BUS COMMANDS
 The following commands may be used on IDE and ATA busses.
@@ -190,10 +225,29 @@ Reset the bus.
 This will reset all ATA devices present on the bus.
 Any ATAPI device with pending commands will also be reset.
 .El
+.Sh EXAMPLES
+To erase
+.Pa wd2
+which is currently unfrozen and has no password set:
+.Bd -literal -offset indent
+# atactl wd2 security status
+	supported
+# atactl wd2 security setpass user
+Password:
+Confirm password:
+# atactl wd2 security status
+	supported
+	enabled
+# atactl wd2 security erase user
+Password:
+Erasing may take up to 0h 2m 0s...
+#
+.Ed
 .Sh SEE ALSO
 .Xr ioctl 2 ,
 .Xr wd 4 ,
 .Xr dkctl 8 ,
+.Xr drvctl 8 ,
 .Xr scsictl 8
 .Sh HISTORY
 The
@@ -211,3 +265,10 @@ command written by Jason R. Thorpe.
 The output from the
 .Cm identify
 command is rather ugly.
+.Pp
+Support for master passwords is not implemented.
+.Pp
+The
+.Nx
+kernel behaves poorly with drives that have passwords set and are
+locked.

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.67 src/sbin/atactl/atactl.c:1.68
--- src/sbin/atactl/atactl.c:1.67	Fri Oct 19 17:09:07 2012
+++ src/sbin/atactl/atactl.c	Wed Jan  9 21:58:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.67 2012/10/19 17:09:07 drochner Exp $	*/
+/*	$NetBSD: atactl.c,v 1.68 2013/01/09 21:58:23 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.67 2012/10/19 17:09:07 drochner Exp $);
+__RCSID($NetBSD: atactl.c,v 1.68 2013/01/09 21:58:23 riastradh Exp $);
 #endif
 
 
@@ -44,6 +44,7 @@ __RCSID($NetBSD: atactl.c,v 1.67 2012/1
 #include err.h
 #include errno.h
 #include fcntl.h
+#include pwd.h
 #include stdio.h
 #include stdlib.h
 #include string.h
@@ -144,7 +145,9 @@ static const struct command device_comma
 	{ smart,
 		enable|disable|status|offline #|error-log|selftest-log,
 		device_smart },
-	{ security,	freeze|status,	device_security },
+	{ security,
+		status|freeze|[setpass|unlock|disable|erase] [user|master],
+		device_security },
 	{ NULL,		NULL,			NULL },
 };
 
@@ -851,6 +854,49 @@ extract_string(char *buf, size_t bufmax,
 	buf[j] = '\0';
 }
 
+static void
+compute_capacity(const struct ataparams 

CVS commit: src/sbin/atactl

2013-01-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan  9 21:58:24 UTC 2013

Modified Files:
src/sbin/atactl: atactl.8 atactl.c

Log Message:
Add some ATA SECURITY commands to atactl(8).


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sbin/atactl/atactl.8
cvs rdiff -u -r1.67 -r1.68 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-10-31 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 31 14:44:07 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Wrap or shorten lines longer than 80 columns.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.63 src/sbin/atactl/atactl.c:1.64
--- src/sbin/atactl/atactl.c:1.63	Mon Oct 24 19:15:42 2011
+++ src/sbin/atactl/atactl.c	Mon Oct 31 14:44:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.63 2011/10/24 19:15:42 jakllsch Exp $	*/
+/*	$NetBSD: atactl.c,v 1.64 2011/10/31 14:44:07 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.63 2011/10/24 19:15:42 jakllsch Exp $);
+__RCSID($NetBSD: atactl.c,v 1.64 2011/10/31 14:44:07 jakllsch Exp $);
 #endif
 
 
@@ -102,8 +102,10 @@ struct bitinfo {
 
 __dead static void	usage(void);
 static void	ata_command(struct atareq *);
-static void	print_bitinfo(const char *, const char *, u_int, const struct bitinfo *);
-static void	print_bitinfo2(const char *, const char *, u_int, u_int, const struct bitinfo *);
+static void	print_bitinfo(const char *, const char *, u_int,
+const struct bitinfo *);
+static void	print_bitinfo2(const char *, const char *, u_int, u_int,
+const struct bitinfo *);
 static void	print_smart_status(void *, void *);
 static void	print_error_entry(int, const struct ata_smart_error *);
 static void	print_selftest_entry(int, const struct ata_smart_selftest *);
@@ -119,7 +121,7 @@ static int	fd;/* file descriptor for
 static const	char *dvname;			/* device name */
 static char	dvname_store[MAXPATHLEN];	/* for opendisk(3) */
 static const	char *cmdname;			/* command user issued */
-static const	char *argnames;			/* helpstring: expected arguments */
+static const	char *argnames;		/* helpstring: expected arguments */
 
 static void	device_identify(int, char *[]);
 static void	device_setidle(int, char *[]);
@@ -140,7 +142,8 @@ static const struct command device_comma
 	{ standby,	,			device_idle },
 	{ sleep,	,			device_idle },
 	{ checkpower,	,			device_checkpower },
-	{ smart,	enable|disable|status|offline #|error-log|selftest-log,
+	{ smart,
+		enable|disable|status|offline #|error-log|selftest-log,
 		device_smart },
 	{ security,	freeze|status,	device_security },
 	{ NULL,		NULL,			NULL },
@@ -446,7 +449,8 @@ ata_command(struct atareq *req)
  */
 
 static void
-print_bitinfo(const char *bf, const char *af, u_int bits, const struct bitinfo *binfo)
+print_bitinfo(const char *bf, const char *af, u_int bits,
+const struct bitinfo *binfo)
 {
 
 	for (; binfo-bitmask != 0; binfo++)
@@ -455,7 +459,8 @@ print_bitinfo(const char *bf, const char
 }
 
 static void
-print_bitinfo2(const char *bf, const char *af, u_int bits, u_int enables, const struct bitinfo *binfo)
+print_bitinfo2(const char *bf, const char *af, u_int bits, u_int enables,
+const struct bitinfo *binfo)
 {
 
 	for (; binfo-bitmask != 0; binfo++)
@@ -510,7 +515,8 @@ print_smart_status(void *vbuf, void *tbu
 		return;
 	}
 
-	printf(id value thresh crit collect reliability description\t\t\traw\n);
+	printf(id value thresh crit collect reliability description
+	\t\t\traw\n);
 	for (i = 0; i  256; i++) {
 		int thresh = 0;
 
@@ -597,7 +603,8 @@ print_error_entry(int num, const struct 
 	printf(Log entry: %d\n, num);
 
 	for (i = 0; i  5; i++)
-		printf(\tCommand %d: dc=%02x sf=%02x sc=%02x sn=%02x cl=%02x ch=%02x dh=%02x cmd=%02x time=%02x%02x%02x%02x\n, i,
+		printf(\tCommand %d: dc=%02x sf=%02x sc=%02x sn=%02x cl=%02x 
+		ch=%02x dh=%02x cmd=%02x time=%02x%02x%02x%02x\n, i,
 		le-command[i].device_control,
 		le-command[i].features,
 		le-command[i].sector_count,
@@ -610,7 +617,8 @@ print_error_entry(int num, const struct 
 		le-command[i].timestamp[2],
 		le-command[i].timestamp[1],
 		le-command[i].timestamp[0]);
-	printf(\tError: err=%02x sc=%02x sn=%02x cl=%02x ch=%02x dh=%02x status=%02x state=%02x lifetime=%02x%02x\n,
+	printf(\tError: err=%02x sc=%02x sn=%02x cl=%02x ch=%02x dh=%02x 
+	status=%02x state=%02x lifetime=%02x%02x\n,
 	le-error_data.error,
 	le-error_data.sector_count,
 	le-error_data.sector_number,
@@ -621,7 +629,8 @@ print_error_entry(int num, const struct 
 	le-error_data.state,
 	le-error_data.lifetime[1],
 	le-error_data.lifetime[0]);
-	printf(\tExtended: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n,
+	printf(\tExtended: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x 
+	%02x %02x %02x %02x %02x %02x %02x %02x %02x\n,
 	le-error_data.extended_error[0],
 	le-error_data.extended_error[1],
 	le-error_data.extended_error[2],



CVS commit: src/sbin/atactl

2011-10-31 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 31 14:50:10 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Remove write-only variable.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.64 src/sbin/atactl/atactl.c:1.65
--- src/sbin/atactl/atactl.c:1.64	Mon Oct 31 14:44:07 2011
+++ src/sbin/atactl/atactl.c	Mon Oct 31 14:50:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.64 2011/10/31 14:44:07 jakllsch Exp $	*/
+/*	$NetBSD: atactl.c,v 1.65 2011/10/31 14:50:10 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.64 2011/10/31 14:44:07 jakllsch Exp $);
+__RCSID($NetBSD: atactl.c,v 1.65 2011/10/31 14:50:10 jakllsch Exp $);
 #endif
 
 
@@ -121,7 +121,6 @@ static int	fd;/* file descriptor for
 static const	char *dvname;			/* device name */
 static char	dvname_store[MAXPATHLEN];	/* for opendisk(3) */
 static const	char *cmdname;			/* command user issued */
-static const	char *argnames;		/* helpstring: expected arguments */
 
 static void	device_identify(int, char *[]);
 static void	device_setidle(int, char *[]);
@@ -378,8 +377,6 @@ main(int argc, char *argv[])
 	if (commands == NULL)
 		errx(1, unknown command: %s, cmdname);
 
-	argnames = commands-arg_names;
-
 	(*commands-cmd_func)(argc, argv);
 	exit(0);
 }



CVS commit: src/sbin/atactl

2011-10-31 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 31 15:26:12 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Constify structure pointed to by getataparams() return value.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.65 src/sbin/atactl/atactl.c:1.66
--- src/sbin/atactl/atactl.c:1.65	Mon Oct 31 14:50:10 2011
+++ src/sbin/atactl/atactl.c	Mon Oct 31 15:26:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.65 2011/10/31 14:50:10 jakllsch Exp $	*/
+/*	$NetBSD: atactl.c,v 1.66 2011/10/31 15:26:11 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.65 2011/10/31 14:50:10 jakllsch Exp $);
+__RCSID($NetBSD: atactl.c,v 1.66 2011/10/31 15:26:11 jakllsch Exp $);
 #endif
 
 
@@ -113,7 +113,7 @@ static void	print_selftest_entry(int, co
 static void	print_error(const void *);
 static void	print_selftest(const void *);
 
-static struct ataparams *getataparams(void);
+static const struct ataparams *getataparams(void);
 
 static int	is_smart(void);
 
@@ -755,7 +755,7 @@ print_selftest(const void *buf)
 		print_selftest_entry(i, stlog-log_entries[i]);
 }
 
-static struct ataparams *
+static const struct ataparams *
 getataparams(void)
 {
 	struct atareq req;
@@ -788,7 +788,7 @@ static int
 is_smart(void)
 {
 	int retval = 0;
-	struct ataparams *inqbuf;
+	const struct ataparams *inqbuf;
 	const char *status;
 
 	inqbuf = getataparams();
@@ -824,7 +824,7 @@ is_smart(void)
  */
 static void
 extract_string(char *buf, size_t bufmax,
-	   uint8_t *bytes, unsigned numbytes,
+	   const uint8_t *bytes, size_t numbytes,
 	   int needswap)
 {
 	unsigned i;
@@ -862,7 +862,7 @@ extract_string(char *buf, size_t bufmax,
 static void
 device_identify(int argc, char *argv[])
 {
-	struct ataparams *inqbuf;
+	const struct ataparams *inqbuf;
 	char model[sizeof(inqbuf-atap_model)+1];
 	char revision[sizeof(inqbuf-atap_revision)+1];
 	char serial[sizeof(inqbuf-atap_serial)+1];
@@ -884,7 +884,7 @@ device_identify(int argc, char *argv[])
 	if ((inqbuf-atap_integrity  WDC_INTEGRITY_MAGIC_MASK) ==
 	WDC_INTEGRITY_MAGIC) {
 		for (i = checksum = 0; i  512; i++)
-			checksum += ((uint8_t *)inqbuf)[i];
+			checksum += ((const uint8_t *)inqbuf)[i];
 		if (checksum != 0)
 			puts(IDENTIFY DEVICE data checksum invalid\n);
 	}
@@ -1362,7 +1362,7 @@ static void
 device_security(int argc, char *argv[])
 {
 	struct atareq req;
-	struct ataparams *inqbuf;
+	const struct ataparams *inqbuf;
 
 	/* need subcommand */
 	if (argc  1)



CVS commit: src/sbin/atactl

2011-10-31 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 31 14:44:07 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Wrap or shorten lines longer than 80 columns.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-10-31 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 31 14:50:10 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Remove write-only variable.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-10-31 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 31 15:26:12 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Constify structure pointed to by getataparams() return value.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sbin/atactl

2011-10-24 Thread Jukka Ruohonen
On Mon, Oct 24, 2011 at 07:13:04PM +, Jonathan A. Kollasch wrote:
 Module Name:  src
 Committed By: jakllsch
 Date: Mon Oct 24 19:13:04 UTC 2011
 
 Modified Files:
   src/sbin/atactl: atactl.c
 
 Log Message:
 constify

Can you follow common style guidelines and wrap longs line to 80 characters?
Those long lines are painful to read with many editors.

- Jukka.



CVS commit: src/sbin/atactl

2011-10-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 24 15:56:17 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
change lines containing only whitespace to empty lines,
remove trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.60 src/sbin/atactl/atactl.c:1.61
--- src/sbin/atactl/atactl.c:1.60	Sat Aug 27 16:12:54 2011
+++ src/sbin/atactl/atactl.c	Mon Oct 24 15:56:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.60 2011/08/27 16:12:54 joerg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.61 2011/10/24 15:56:17 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.60 2011/08/27 16:12:54 joerg Exp $);
+__RCSID($NetBSD: atactl.c,v 1.61 2011/10/24 15:56:17 jakllsch Exp $);
 #endif
 
 
@@ -475,7 +475,7 @@ device_smart_temp(struct ata_smart_attr 
 {
 	printf(% PRIu8, attr-raw[0]);
 	if (attr-raw[0] != raw_value)
-		printf( Lifetime min/max % PRIu8 /% PRIu8, 
+		printf( Lifetime min/max % PRIu8 /% PRIu8,
 		attr-raw[2], attr-raw[4]);
 }
 
@@ -531,8 +531,8 @@ print_smart_status(void *vbuf, void *tbu
 		if (attr-value == 0||attr-value == 0xFE||attr-value == 0xFF)
 			continue;
 
-		for (aid = 0; 
-		 smart_attrs[aid].id != i  smart_attrs[aid].id != 0; 
+		for (aid = 0;
+		 smart_attrs[aid].id != i  smart_attrs[aid].id != 0;
 		 aid++)
 			;
 
@@ -667,12 +667,12 @@ print_error(void *buf)
 		printf(No errors have been logged\n);
 		return;
 	}
-		
+
 	if (erlog-mostrecenterror  5) {
 		fprintf(stderr, Most recent error is too large\n);
 		return;
 	}
-	
+
 	for (i = erlog-mostrecenterror; i  5; i++)
 		print_error_entry(i, erlog-log_entries[i]);
 	for (i = 0; i  erlog-mostrecenterror; i++)
@@ -737,12 +737,12 @@ print_selftest(void *buf)
 		printf(No self-tests have been logged\n);
 		return;
 	}
-		
+
 	if (stlog-mostrecenttest  22) {
 		fprintf(stderr, Most recent test is too large\n);
 		return;
 	}
-	
+
 	for (i = stlog-mostrecenttest; i  22; i++)
 		print_selftest_entry(i, stlog-log_entries[i]);
 	for (i = 0; i  stlog-mostrecenttest; i++)
@@ -957,13 +957,13 @@ device_identify(int argc, char *argv[])
 	humanize_number(hnum, sizeof(hnum), capacity, bytes,
 		HN_AUTOSCALE, HN_DIVISOR_1000);
 
-	printf(Capacity %s, % PRIu64  sectors, % PRIu32  bytes/sector\n, 
+	printf(Capacity %s, % PRIu64  sectors, % PRIu32  bytes/sector\n,
 		   hnum, sectors, secsize);
 
 	printf(Cylinders: %d, heads: %d, sec/track: %d\n,
 		inqbuf-atap_cylinders, inqbuf-atap_heads,
 		inqbuf-atap_sectors);
-	
+
 	lb_per_pb = 1;
 
 	if ((inqbuf-atap_secsz  ATA_SECSZ_VALID_MASK) == ATA_SECSZ_VALID) {
@@ -1083,22 +1083,22 @@ device_apm(int argc, char *argv[])
 	if (argc = 1) {
 		req.command = SET_FEATURES;
 		req.timeout = 1000;
-		
+
 		if (strcmp(argv[0], disable) == 0)
 			req.features = WDSF_APM_DS;
 		else if (strcmp(argv[0], set) == 0  argc = 2 
 		 (l = strtol(argv[1], NULL, 0)) = 0  l = 253) {
-			
+
 			req.features = WDSF_APM_EN;
 			req.sec_count = l + 1;
 		} else
 			usage();
 	} else
 		usage();
-	
+
 	ata_command(req);
 }
-	
+
 
 /*
  * Set the idle timer on the disk.  Set it for either idle mode or
@@ -1244,7 +1244,7 @@ device_smart(int argc, char *argv[])
 		req.command = WDCC_SMART;
 		req.cylinder = WDSMART_CYL;
 		req.timeout = 1000;
-	
+
 		ata_command(req);
 
 		if (req.cylinder != WDSMART_CYL) {
@@ -1266,7 +1266,7 @@ device_smart(int argc, char *argv[])
 		req.datalen = sizeof(inbuf);
 		req.cylinder = WDSMART_CYL;
 		req.timeout = 1000;
-	
+
 		ata_command(req);
 
 		memset(inbuf2, 0, sizeof(inbuf2));
@@ -1309,7 +1309,7 @@ device_smart(int argc, char *argv[])
 
 		memset(inbuf, 0, sizeof(inbuf));
 		memset(req, 0, sizeof(req));
-		
+
 		req.flags = ATACMD_READ;
 		req.features = WDSM_RD_LOG;
 		req.sec_count = 1;
@@ -1319,9 +1319,9 @@ device_smart(int argc, char *argv[])
 		req.datalen = sizeof(inbuf);
 		req.cylinder = WDSMART_CYL;
 		req.timeout = 1000;
-		
+
 		ata_command(req);
-		
+
 		print_error(inbuf);
 	} else if (strcmp(argv[0], selftest-log) == 0) {
 		if (!is_smart()) {
@@ -1331,7 +1331,7 @@ device_smart(int argc, char *argv[])
 
 		memset(inbuf, 0, sizeof(inbuf));
 		memset(req, 0, sizeof(req));
-		
+
 		req.flags = ATACMD_READ;
 		req.features = WDSM_RD_LOG;
 		req.sec_count = 1;
@@ -1341,9 +1341,9 @@ device_smart(int argc, char *argv[])
 		req.datalen = sizeof(inbuf);
 		req.cylinder = WDSMART_CYL;
 		req.timeout = 1000;
-		
+
 		ata_command(req);
-		
+
 		print_selftest(inbuf);
 
 	} else {



CVS commit: src/sbin/atactl

2011-10-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 24 19:13:04 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
constify


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.61 src/sbin/atactl/atactl.c:1.62
--- src/sbin/atactl/atactl.c:1.61	Mon Oct 24 15:56:17 2011
+++ src/sbin/atactl/atactl.c	Mon Oct 24 19:13:03 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.61 2011/10/24 15:56:17 jakllsch Exp $	*/
+/*	$NetBSD: atactl.c,v 1.62 2011/10/24 19:13:03 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.61 2011/10/24 15:56:17 jakllsch Exp $);
+__RCSID($NetBSD: atactl.c,v 1.62 2011/10/24 19:13:03 jakllsch Exp $);
 #endif
 
 
@@ -102,14 +102,14 @@ struct bitinfo {
 
 __dead static void	usage(void);
 static void	ata_command(struct atareq *);
-static void	print_bitinfo(const char *, const char *, u_int, struct bitinfo *);
-static void	print_bitinfo2(const char *, const char *, u_int, u_int, struct bitinfo *);
+static void	print_bitinfo(const char *, const char *, u_int, const struct bitinfo *);
+static void	print_bitinfo2(const char *, const char *, u_int, u_int, const struct bitinfo *);
 static void	print_smart_status(void *, void *);
-static void	print_error_entry(int, struct ata_smart_error *);
-static void	print_selftest_entry(int, struct ata_smart_selftest *);
+static void	print_error_entry(int, const struct ata_smart_error *);
+static void	print_selftest_entry(int, const struct ata_smart_selftest *);
 
-static void	print_error(void *);
-static void	print_selftest(void *);
+static void	print_error(const void *);
+static void	print_selftest(const void *);
 
 static struct ataparams *getataparams(void);
 
@@ -129,9 +129,9 @@ static void	device_checkpower(int, char 
 static void	device_smart(int, char *[]);
 static void	device_security(int, char *[]);
 
-static void	device_smart_temp(struct ata_smart_attr *, uint64_t);
+static void	device_smart_temp(const struct ata_smart_attr *, uint64_t);
 
-static struct command device_commands[] = {
+static const struct command device_commands[] = {
 	{ identify,	,			device_identify },
 	{ setidle,	idle-timer,		device_setidle },
 	{ apm,	disable|set #,	device_apm },
@@ -148,7 +148,7 @@ static struct command device_commands[] 
 
 static void	bus_reset(int, char *[]);
 
-static struct command bus_commands[] = {
+static const struct command bus_commands[] = {
 	{ reset,	,			bus_reset },
 	{ NULL,		NULL,			NULL },
 };
@@ -158,7 +158,7 @@ static struct command bus_commands[] = {
  * device identification.
  */
 
-static struct bitinfo ata_caps[] = {
+static const struct bitinfo ata_caps[] = {
 	{ WDC_CAP_DMA, DMA },
 	{ WDC_CAP_LBA, LBA },
 	{ ATA_CAP_STBY, ATA standby timer values },
@@ -167,7 +167,7 @@ static struct bitinfo ata_caps[] = {
 	{ 0, NULL },
 };
 
-static struct bitinfo ata_vers[] = {
+static const struct bitinfo ata_vers[] = {
 	{ WDC_VER_ATA1,	ATA-1 },
 	{ WDC_VER_ATA2,	ATA-2 },
 	{ WDC_VER_ATA3,	ATA-3 },
@@ -178,7 +178,7 @@ static struct bitinfo ata_vers[] = {
 	{ 0, NULL },
 };
 
-static struct bitinfo ata_cmd_set1[] = {
+static const struct bitinfo ata_cmd_set1[] = {
 	{ WDC_CMD1_NOP, NOP command },
 	{ WDC_CMD1_RB, READ BUFFER command },
 	{ WDC_CMD1_WB, WRITE BUFFER command },
@@ -196,7 +196,7 @@ static struct bitinfo ata_cmd_set1[] = {
 	{ 0, NULL },
 };
 
-static struct bitinfo ata_cmd_set2[] = {
+static const struct bitinfo ata_cmd_set2[] = {
 	{ ATA_CMD2_FCE, FLUSH CACHE EXT command },
 	{ WDC_CMD2_FC, FLUSH CACHE command },
 	{ WDC_CMD2_DCO, Device Configuration Overlay feature set },
@@ -213,7 +213,7 @@ static struct bitinfo ata_cmd_set2[] = {
 	{ 0, NULL },
 };
 
-static struct bitinfo ata_cmd_ext[] = {
+static const struct bitinfo ata_cmd_ext[] = {
 	{ ATA_CMDE_TLCONT, Time-limited R/W feature set R/W Continuous mode },
 	{ ATA_CMDE_TL, Time-limited Read/Write },
 	{ ATA_CMDE_URGW, URG bit for WRITE STREAM DMA/PIO },
@@ -230,7 +230,7 @@ static struct bitinfo ata_cmd_ext[] = {
 	{ 0, NULL },
 };
 
-static struct bitinfo ata_sata_caps[] = {
+static const struct bitinfo ata_sata_caps[] = {
 	{ SATA_SIGNAL_GEN1, 1.5Gb/s signaling },
 	{ SATA_SIGNAL_GEN2, 3.0Gb/s signaling },
 	{ SATA_NATIVE_CMDQ, Native Command Queuing },
@@ -239,7 +239,7 @@ static struct bitinfo ata_sata_caps[] = 
 	{ 0, NULL },
 };
 
-static struct bitinfo ata_sata_feat[] = {
+static const struct bitinfo ata_sata_feat[] = {
 	{ SATA_NONZERO_OFFSETS, Non-zero Offset DMA },
 	{ SATA_DMA_SETUP_AUTO, DMA Setup Auto Activate },
 	{ SATA_DRIVE_PWR_MGMT, Device-Initiated Interface Power Managment },
@@ -251,7 +251,7 @@ static struct bitinfo ata_sata_feat[] = 
 static const struct {
 	const int	id;
 	const char	

CVS commit: src/sbin/atactl

2011-10-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 24 19:15:42 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
use C99 fixed-width integer types


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.62 src/sbin/atactl/atactl.c:1.63
--- src/sbin/atactl/atactl.c:1.62	Mon Oct 24 19:13:03 2011
+++ src/sbin/atactl/atactl.c	Mon Oct 24 19:15:42 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.62 2011/10/24 19:13:03 jakllsch Exp $	*/
+/*	$NetBSD: atactl.c,v 1.63 2011/10/24 19:15:42 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.62 2011/10/24 19:13:03 jakllsch Exp $);
+__RCSID($NetBSD: atactl.c,v 1.63 2011/10/24 19:15:42 jakllsch Exp $);
 #endif
 
 
@@ -55,38 +55,38 @@ __RCSID($NetBSD: atactl.c,v 1.62 2011/1
 
 struct ata_smart_error {
 	struct {
-		u_int8_t device_control;
-		u_int8_t features;
-		u_int8_t sector_count;
-		u_int8_t sector_number;
-		u_int8_t cylinder_low;
-		u_int8_t cylinder_high;
-		u_int8_t device_head;
-		u_int8_t command;
-		u_int8_t timestamp[4];
+		uint8_t device_control;
+		uint8_t features;
+		uint8_t sector_count;
+		uint8_t sector_number;
+		uint8_t cylinder_low;
+		uint8_t cylinder_high;
+		uint8_t device_head;
+		uint8_t command;
+		uint8_t timestamp[4];
 	} command[5];
 	struct {
-		u_int8_t reserved;
-		u_int8_t error;
-		u_int8_t sector_count;
-		u_int8_t sector_number;
-		u_int8_t cylinder_low;
-		u_int8_t cylinder_high;
-		u_int8_t device_head;
-		u_int8_t status;
-		u_int8_t extended_error[19];
-		u_int8_t state;
-		u_int8_t lifetime[2];
+		uint8_t reserved;
+		uint8_t error;
+		uint8_t sector_count;
+		uint8_t sector_number;
+		uint8_t cylinder_low;
+		uint8_t cylinder_high;
+		uint8_t device_head;
+		uint8_t status;
+		uint8_t extended_error[19];
+		uint8_t state;
+		uint8_t lifetime[2];
 	} error_data;
 } __packed;
 
 struct ata_smart_errorlog {
-	u_int8_t		data_structure_revision;
-	u_int8_t		mostrecenterror;
+	uint8_t			data_structure_revision;
+	uint8_t			mostrecenterror;
 	struct ata_smart_error	log_entries[5];
-	u_int16_t		device_error_count;
-	u_int8_t		reserved[57];
-	u_int8_t		checksum;
+	uint16_t		device_error_count;
+	uint8_t			reserved[57];
+	uint8_t			checksum;
 } __packed;
 
 struct command {
@@ -494,17 +494,17 @@ print_smart_status(void *vbuf, void *tbu
 	int flags;
 	int i, j;
 	int aid;
-	u_int8_t checksum;
+	uint8_t checksum;
 
 	for (i = checksum = 0; i  512; i++)
-		checksum += ((const u_int8_t *) value_buf)[i];
+		checksum += ((const uint8_t *) value_buf)[i];
 	if (checksum != 0) {
 		fprintf(stderr, SMART attribute values checksum error\n);
 		return;
 	}
 
 	for (i = checksum = 0; i  512; i++)
-		checksum += ((const u_int8_t *) threshold_buf)[i];
+		checksum += ((const uint8_t *) threshold_buf)[i];
 	if (checksum != 0) {
 		fprintf(stderr, SMART attribute thresholds checksum error\n);
 		return;
@@ -566,7 +566,7 @@ static const struct {
 	{ 127, Abort off-line test },
 	{ 129, Short captive },
 	{ 130, Extended captive },
-	{ 256, Unknown test }, /* larger then u_int8_t */
+	{ 256, Unknown test }, /* larger then uint8_t */
 	{ 0, NULL }
 };
 
@@ -647,11 +647,11 @@ static void
 print_error(const void *buf)
 {
 	const struct ata_smart_errorlog *erlog = buf;
-	u_int8_t checksum;
+	uint8_t checksum;
 	int i;
 
 	for (i = checksum = 0; i  512; i++)
-		checksum += ((const u_int8_t *) buf)[i];
+		checksum += ((const uint8_t *) buf)[i];
 	if (checksum != 0) {
 		fprintf(stderr, SMART error log checksum error\n);
 		return;
@@ -717,11 +717,11 @@ static void
 print_selftest(const void *buf)
 {
 	const struct ata_smart_selftestlog *stlog = buf;
-	u_int8_t checksum;
+	uint8_t checksum;
 	int i;
 
 	for (i = checksum = 0; i  512; i++)
-		checksum += ((const u_int8_t *) buf)[i];
+		checksum += ((const uint8_t *) buf)[i];
 	if (checksum != 0) {
 		fprintf(stderr, SMART selftest log checksum error\n);
 		return;



CVS commit: src/sbin/atactl

2011-10-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 24 15:56:17 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
change lines containing only whitespace to empty lines,
remove trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-10-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 24 19:13:04 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
constify


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-10-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Oct 24 19:15:42 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
use C99 fixed-width integer types


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-08-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Aug 27 16:12:54 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
staticfy. Use __dead.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.59 src/sbin/atactl/atactl.c:1.60
--- src/sbin/atactl/atactl.c:1.59	Wed Jan 19 07:55:12 2011
+++ src/sbin/atactl/atactl.c	Sat Aug 27 16:12:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.59 2011/01/19 07:55:12 nisimura Exp $	*/
+/*	$NetBSD: atactl.c,v 1.60 2011/08/27 16:12:54 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.59 2011/01/19 07:55:12 nisimura Exp $);
+__RCSID($NetBSD: atactl.c,v 1.60 2011/08/27 16:12:54 joerg Exp $);
 #endif
 
 
@@ -100,38 +100,38 @@
 	const char *string;
 };
 
-void	usage(void);
-void	ata_command(struct atareq *);
-void	print_bitinfo(const char *, const char *, u_int, struct bitinfo *);
-void	print_bitinfo2(const char *, const char *, u_int, u_int, struct bitinfo *);
-void	print_smart_status(void *, void *);
-void	print_error_entry(int, struct ata_smart_error *);
-void	print_selftest_entry(int, struct ata_smart_selftest *);
-
-void	print_error(void *);
-void	print_selftest(void *);
-
-struct ataparams *getataparams(void);
-
-int	is_smart(void);
-
-int	fd;/* file descriptor for device */
-const	char *dvname;			/* device name */
-char	dvname_store[MAXPATHLEN];	/* for opendisk(3) */
-const	char *cmdname;			/* command user issued */
-const	char *argnames;			/* helpstring: expected arguments */
-
-void	device_identify(int, char *[]);
-void	device_setidle(int, char *[]);
-void	device_idle(int, char *[]);
-void	device_apm(int, char *[]);
-void	device_checkpower(int, char *[]);
-void	device_smart(int, char *[]);
-void	device_security(int, char *[]);
+__dead static void	usage(void);
+static void	ata_command(struct atareq *);
+static void	print_bitinfo(const char *, const char *, u_int, struct bitinfo *);
+static void	print_bitinfo2(const char *, const char *, u_int, u_int, struct bitinfo *);
+static void	print_smart_status(void *, void *);
+static void	print_error_entry(int, struct ata_smart_error *);
+static void	print_selftest_entry(int, struct ata_smart_selftest *);
+
+static void	print_error(void *);
+static void	print_selftest(void *);
+
+static struct ataparams *getataparams(void);
+
+static int	is_smart(void);
+
+static int	fd;/* file descriptor for device */
+static const	char *dvname;			/* device name */
+static char	dvname_store[MAXPATHLEN];	/* for opendisk(3) */
+static const	char *cmdname;			/* command user issued */
+static const	char *argnames;			/* helpstring: expected arguments */
+
+static void	device_identify(int, char *[]);
+static void	device_setidle(int, char *[]);
+static void	device_idle(int, char *[]);
+static void	device_apm(int, char *[]);
+static void	device_checkpower(int, char *[]);
+static void	device_smart(int, char *[]);
+static void	device_security(int, char *[]);
 
-void	device_smart_temp(struct ata_smart_attr *, uint64_t);
+static void	device_smart_temp(struct ata_smart_attr *, uint64_t);
 
-struct command device_commands[] = {
+static struct command device_commands[] = {
 	{ identify,	,			device_identify },
 	{ setidle,	idle-timer,		device_setidle },
 	{ apm,	disable|set #,	device_apm },
@@ -146,9 +146,9 @@
 	{ NULL,		NULL,			NULL },
 };
 
-void	bus_reset(int, char *[]);
+static void	bus_reset(int, char *[]);
 
-struct command bus_commands[] = {
+static struct command bus_commands[] = {
 	{ reset,	,			bus_reset },
 	{ NULL,		NULL,			NULL },
 };
@@ -158,7 +158,7 @@
  * device identification.
  */
 
-struct bitinfo ata_caps[] = {
+static struct bitinfo ata_caps[] = {
 	{ WDC_CAP_DMA, DMA },
 	{ WDC_CAP_LBA, LBA },
 	{ ATA_CAP_STBY, ATA standby timer values },
@@ -167,7 +167,7 @@
 	{ 0, NULL },
 };
 
-struct bitinfo ata_vers[] = {
+static struct bitinfo ata_vers[] = {
 	{ WDC_VER_ATA1,	ATA-1 },
 	{ WDC_VER_ATA2,	ATA-2 },
 	{ WDC_VER_ATA3,	ATA-3 },
@@ -178,7 +178,7 @@
 	{ 0, NULL },
 };
 
-struct bitinfo ata_cmd_set1[] = {
+static struct bitinfo ata_cmd_set1[] = {
 	{ WDC_CMD1_NOP, NOP command },
 	{ WDC_CMD1_RB, READ BUFFER command },
 	{ WDC_CMD1_WB, WRITE BUFFER command },
@@ -196,7 +196,7 @@
 	{ 0, NULL },
 };
 
-struct bitinfo ata_cmd_set2[] = {
+static struct bitinfo ata_cmd_set2[] = {
 	{ ATA_CMD2_FCE, FLUSH CACHE EXT command },
 	{ WDC_CMD2_FC, FLUSH CACHE command },
 	{ WDC_CMD2_DCO, Device Configuration Overlay feature set },
@@ -213,7 +213,7 @@
 	{ 0, NULL },
 };
 
-struct bitinfo ata_cmd_ext[] = {
+static struct bitinfo ata_cmd_ext[] = {
 	{ ATA_CMDE_TLCONT, Time-limited R/W feature set R/W Continuous mode },
 	{ ATA_CMDE_TL, Time-limited Read/Write },
 	{ ATA_CMDE_URGW, 

CVS commit: src/sbin/atactl

2011-08-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Aug 27 16:12:54 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
staticfy. Use __dead.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-01-18 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Jan 19 07:55:13 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
fix mislabelled S.M.A.R.T. lifetime temperature record reading.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.58 src/sbin/atactl/atactl.c:1.59
--- src/sbin/atactl/atactl.c:1.58	Fri Jan 14 06:02:57 2011
+++ src/sbin/atactl/atactl.c	Wed Jan 19 07:55:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.58 2011/01/14 06:02:57 nisimura Exp $	*/
+/*	$NetBSD: atactl.c,v 1.59 2011/01/19 07:55:12 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.58 2011/01/14 06:02:57 nisimura Exp $);
+__RCSID($NetBSD: atactl.c,v 1.59 2011/01/19 07:55:12 nisimura Exp $);
 #endif
 
 
@@ -475,7 +475,7 @@
 {
 	printf(% PRIu8, attr-raw[0]);
 	if (attr-raw[0] != raw_value)
-		printf( Lifetime max/min % PRIu8 /% PRIu8, 
+		printf( Lifetime min/max % PRIu8 /% PRIu8, 
 		attr-raw[2], attr-raw[4]);
 }
 



CVS commit: src/sbin/atactl

2011-01-18 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Jan 19 07:55:13 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
fix mislabelled S.M.A.R.T. lifetime temperature record reading.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2011-01-13 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Jan 14 06:02:57 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
fix a mysterious indent lossage roaming around for last couple of years.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.57 src/sbin/atactl/atactl.c:1.58
--- src/sbin/atactl/atactl.c:1.57	Sat Mar 13 19:49:50 2010
+++ src/sbin/atactl/atactl.c	Fri Jan 14 06:02:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.57 2010/03/13 19:49:50 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.58 2011/01/14 06:02:57 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.57 2010/03/13 19:49:50 mrg Exp $);
+__RCSID($NetBSD: atactl.c,v 1.58 2011/01/14 06:02:57 nisimura Exp $);
 #endif
 
 
@@ -553,8 +553,8 @@
 		else
 			printf(% PRIu64, raw_value);
 		printf(\n);
-		}
 	}
+}
 
 struct {
 	int number;



CVS commit: src/sbin/atactl

2011-01-13 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Jan 14 06:02:57 UTC 2011

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
fix a mysterious indent lossage roaming around for last couple of years.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sbin/atactl

2010-03-13 Thread David Holland
On Sat, Mar 13, 2010 at 07:49:50PM +, matthew green wrote:
  Log Message:
  add SMART code 187: Reported uncorrect.  from smartmontools.

Is that supposed to be read as uncorrected or incorrect? (And can
we edit it or does it need to stay verbatim?)

-- 
David A. Holland
dholl...@netbsd.org


CVS commit: src/sbin/atactl

2010-01-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Jan 25 01:24:11 UTC 2010

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Add display of Long Physical Sector and Long Logical Sectors feature set
information to atactl identify output.

Also:
- remove caddr_t cast
- warn about invalid IDENTIFY data checksum (when possible)
- humanize capacity in power-of-10 format
- remove semi-pointless ATAPI check
- slightly rework command queue depth output to be less conversational


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sbin/atactl

2010-01-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Jan 25 01:24:11 UTC 2010

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Add display of Long Physical Sector and Long Logical Sectors feature set
information to atactl identify output.

Also:
- remove caddr_t cast
- warn about invalid IDENTIFY data checksum (when possible)
- humanize capacity in power-of-10 format
- remove semi-pointless ATAPI check
- slightly rework command queue depth output to be less conversational


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.55 src/sbin/atactl/atactl.c:1.56
--- src/sbin/atactl/atactl.c:1.55	Mon Jun  8 23:26:13 2009
+++ src/sbin/atactl/atactl.c	Mon Jan 25 01:24:11 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.55 2009/06/08 23:26:13 jakllsch Exp $	*/
+/*	$NetBSD: atactl.c,v 1.56 2010/01/25 01:24:11 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.55 2009/06/08 23:26:13 jakllsch Exp $);
+__RCSID($NetBSD: atactl.c,v 1.56 2010/01/25 01:24:11 jakllsch Exp $);
 #endif
 
 
@@ -762,7 +762,7 @@
 
 	req.flags = ATACMD_READ;
 	req.command = WDCC_IDENTIFY;
-	req.databuf = (caddr_t)inbuf;
+	req.databuf = inbuf;
 	req.datalen = sizeof(inbuf);
 	req.timeout = 1000;
 
@@ -859,8 +859,14 @@
 	char model[sizeof(inqbuf-atap_model)+1];
 	char revision[sizeof(inqbuf-atap_revision)+1];
 	char serial[sizeof(inqbuf-atap_serial)+1];
+	char hnum[12];
 	uint64_t capacity;
+	uint64_t sectors;
+	uint32_t secsize;
+	int lb_per_pb;
 	int needswap = 0;
+	int i;
+	uint8_t checksum;
 
 	/* No arguments. */
 	if (argc != 0)
@@ -868,6 +874,14 @@
 
 	inqbuf = getataparams();
 
+	if ((inqbuf-atap_integrity  WDC_INTEGRITY_MAGIC_MASK) ==
+	WDC_INTEGRITY_MAGIC) {
+		for (i = checksum = 0; i  512; i++)
+			checksum += ((uint8_t *)inqbuf)[i];
+		if (checksum != 0)
+			puts(IDENTIFY DEVICE data checksum invalid\n);
+	}
+
 #if BYTE_ORDER == LITTLE_ENDIAN
 	/*
 	 * On little endian machines, we need to shuffle the string
@@ -912,32 +926,63 @@
 	   ATAPI : ATA, inqbuf-atap_config  ATA_CFG_FIXED ? fixed :
 	   removable);
 
-	capacity = 0;
-
 	if (inqbuf-atap_cmd2_en != 0  inqbuf-atap_cmd2_en != 0x 
 	inqbuf-atap_cmd2_en  ATA_CMD2_LBA48) {
-		capacity =
+		sectors =
 		((uint64_t)inqbuf-atap_max_lba[3]  48) |
 		((uint64_t)inqbuf-atap_max_lba[2]  32) |
 		((uint64_t)inqbuf-atap_max_lba[1]  16) |
 		((uint64_t)inqbuf-atap_max_lba[0]   0);
 	} else if (inqbuf-atap_capabilities1  WDC_CAP_LBA) {
-		capacity = (inqbuf-atap_capacity[1]  16) |
+		sectors = (inqbuf-atap_capacity[1]  16) |
 		inqbuf-atap_capacity[0];
+	} else {
+		sectors = inqbuf-atap_cylinders *
+		inqbuf-atap_heads * inqbuf-atap_sectors;
+	}
+
+	secsize = 512;
+
+	if ((inqbuf-atap_secsz  ATA_SECSZ_VALID_MASK) == ATA_SECSZ_VALID) {
+		if (inqbuf-atap_secsz  ATA_SECSZ_LLS) {
+			secsize = 2 *		/* words to bytes */
+			(inqbuf-atap_lls_secsz[1]  16 |
+			inqbuf-atap_lls_secsz[0]   0);
+		}
 	}
-	if ((inqbuf-atap_config  WDC_CFG_ATAPI_MASK) != WDC_CFG_ATAPI) {
-		if (capacity == 0)
-			capacity = inqbuf-atap_cylinders *
-			inqbuf-atap_heads * inqbuf-atap_sectors;
-		printf(Cylinders: %d, heads: %d, sec/track: %d, total 
-		   sectors: % PRIu64 \n, inqbuf-atap_cylinders,
-		   inqbuf-atap_heads, inqbuf-atap_sectors, capacity);
+
+	capacity = sectors * secsize;
+
+	humanize_number(hnum, sizeof(hnum), capacity, bytes,
+		HN_AUTOSCALE, HN_DIVISOR_1000);
+
+	printf(Capacity %s, % PRIu64  sectors, % PRIu32  bytes/sector\n, 
+		   hnum, sectors, secsize);
+
+	printf(Cylinders: %d, heads: %d, sec/track: %d\n,
+		inqbuf-atap_cylinders, inqbuf-atap_heads,
+		inqbuf-atap_sectors);
+	
+	lb_per_pb = 1;
+
+	if ((inqbuf-atap_secsz  ATA_SECSZ_VALID_MASK) == ATA_SECSZ_VALID) {
+		if (inqbuf-atap_secsz  ATA_SECSZ_LPS) {
+			lb_per_pb = inqbuf-atap_secsz  ATA_SECSZ_LPS_SZMSK;
+			printf(Physical sector size: %d bytes\n,
+			lb_per_pb * secsize);
+			if ((inqbuf-atap_logical_align 
+			ATA_LA_VALID_MASK) == ATA_LA_VALID) {
+printf(First physically aligned sector: %d\n,
+lb_per_pb - (inqbuf-atap_logical_align 
+	ATA_LA_MASK));
+			}
+		}
 	}
 
 	if (((inqbuf-atap_sata_caps  SATA_NATIVE_CMDQ) ||
 	(inqbuf-atap_cmd_set2  ATA_CMD2_RWQ)) 
 	(inqbuf-atap_queuedepth  WDC_QUEUE_DEPTH_MASK))
-		printf(Device supports command queue depth of %d\n,
+		printf(Command queue depth: %d\n,
 		(inqbuf-atap_queuedepth  WDC_QUEUE_DEPTH_MASK) + 1);
 
 	printf(Device capabilities:\n);



CVS commit: src/sbin/atactl

2009-06-08 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Jun  8 23:26:13 UTC 2009

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Improve identify output slightly:
 - Capitialize Name in World Wide Name.
 - Print the World Wide Name if it exists.
 - Use LBA48 maximum address when available for total sectors output.
 - So that geometry will display on more drives, don't be as strict when
   checking for non-ATAPI devices.  (This seemed to be an issue on at least
   one instance of a Caviar SE16 drive.)
 - Check more carefully for valid/relevant queue depth before printing it.
 - Increment the queue depth by one for display.

While here, wrap some long lines that I should have had wrapped before they
were commited in rev. 1.46.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.54 src/sbin/atactl/atactl.c:1.55
--- src/sbin/atactl/atactl.c:1.54	Sat Jun  6 09:18:55 2009
+++ src/sbin/atactl/atactl.c	Mon Jun  8 23:26:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.54 2009/06/06 09:18:55 mlelstv Exp $	*/
+/*	$NetBSD: atactl.c,v 1.55 2009/06/08 23:26:13 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: atactl.c,v 1.54 2009/06/06 09:18:55 mlelstv Exp $);
+__RCSID($NetBSD: atactl.c,v 1.55 2009/06/08 23:26:13 jakllsch Exp $);
 #endif
 
 
@@ -218,7 +218,7 @@
 	{ ATA_CMDE_TL, Time-limited Read/Write },
 	{ ATA_CMDE_URGW, URG bit for WRITE STREAM DMA/PIO },
 	{ ATA_CMDE_URGR, URG bit for READ STREAM DMA/PIO },
-	{ ATA_CMDE_WWN, World Wide name },
+	{ ATA_CMDE_WWN, World Wide Name },
 	{ ATA_CMDE_WQFE, WRITE DMA QUEUED FUA EXT command },
 	{ ATA_CMDE_WFE, WRITE DMA/MULTIPLE FUA EXT commands },
 	{ ATA_CMDE_GPL, General Purpose Logging feature set },
@@ -859,6 +859,7 @@
 	char model[sizeof(inqbuf-atap_model)+1];
 	char revision[sizeof(inqbuf-atap_revision)+1];
 	char serial[sizeof(inqbuf-atap_serial)+1];
+	uint64_t capacity;
 	int needswap = 0;
 
 	/* No arguments. */
@@ -899,20 +900,45 @@
 	printf(Model: %s, Rev: %s, Serial #: %s\n,
 		model, revision, serial);
 
+	if (inqbuf-atap_cmd_ext != 0  inqbuf-atap_cmd_ext != 0x 
+	inqbuf-atap_cmd_ext  ATA_CMDE_WWN)
+		printf(World Wide Name: %016 PRIX64 \n,
+		((uint64_t)inqbuf-atap_wwn[0]  48) |
+		((uint64_t)inqbuf-atap_wwn[1]  32) |
+		((uint64_t)inqbuf-atap_wwn[2]  16) |
+		((uint64_t)inqbuf-atap_wwn[3]   0));
+
 	printf(Device type: %s, %s\n, inqbuf-atap_config  WDC_CFG_ATAPI ?
 	   ATAPI : ATA, inqbuf-atap_config  ATA_CFG_FIXED ? fixed :
 	   removable);
 
-	if ((inqbuf-atap_config  WDC_CFG_ATAPI_MASK) == 0)
+	capacity = 0;
+
+	if (inqbuf-atap_cmd2_en != 0  inqbuf-atap_cmd2_en != 0x 
+	inqbuf-atap_cmd2_en  ATA_CMD2_LBA48) {
+		capacity =
+		((uint64_t)inqbuf-atap_max_lba[3]  48) |
+		((uint64_t)inqbuf-atap_max_lba[2]  32) |
+		((uint64_t)inqbuf-atap_max_lba[1]  16) |
+		((uint64_t)inqbuf-atap_max_lba[0]   0);
+	} else if (inqbuf-atap_capabilities1  WDC_CAP_LBA) {
+		capacity = (inqbuf-atap_capacity[1]  16) |
+		inqbuf-atap_capacity[0];
+	}
+	if ((inqbuf-atap_config  WDC_CFG_ATAPI_MASK) != WDC_CFG_ATAPI) {
+		if (capacity == 0)
+			capacity = inqbuf-atap_cylinders *
+			inqbuf-atap_heads * inqbuf-atap_sectors;
 		printf(Cylinders: %d, heads: %d, sec/track: %d, total 
-		   sectors: %d\n, inqbuf-atap_cylinders,
-		   inqbuf-atap_heads, inqbuf-atap_sectors,
-		   (inqbuf-atap_capacity[1]  16) |
-		   inqbuf-atap_capacity[0]);
+		   sectors: % PRIu64 \n, inqbuf-atap_cylinders,
+		   inqbuf-atap_heads, inqbuf-atap_sectors, capacity);
+	}
 
-	if (inqbuf-atap_queuedepth  WDC_QUEUE_DEPTH_MASK)
+	if (((inqbuf-atap_sata_caps  SATA_NATIVE_CMDQ) ||
+	(inqbuf-atap_cmd_set2  ATA_CMD2_RWQ)) 
+	(inqbuf-atap_queuedepth  WDC_QUEUE_DEPTH_MASK))
 		printf(Device supports command queue depth of %d\n,
-		   inqbuf-atap_queuedepth  WDC_QUEUE_DEPTH_MASK);
+		(inqbuf-atap_queuedepth  WDC_QUEUE_DEPTH_MASK) + 1);
 
 	printf(Device capabilities:\n);
 	print_bitinfo(\t, \n, inqbuf-atap_capabilities1, ata_caps);
@@ -945,15 +971,22 @@
 
 	if (inqbuf-atap_sata_caps != 0  inqbuf-atap_sata_caps != 0x) {
 		printf(Serial ATA capabilities:\n);
-		print_bitinfo(\t, \n, inqbuf-atap_sata_caps, ata_sata_caps);
+		print_bitinfo(\t, \n,
+		inqbuf-atap_sata_caps, ata_sata_caps);
+
 	}
 
-	if (inqbuf-atap_sata_features_supp != 0  inqbuf-atap_sata_features_supp != 0x) {
+	if (inqbuf-atap_sata_features_supp != 0 
+	inqbuf-atap_sata_features_supp != 0x) {
 		printf(Serial ATA features:\n);
-		if (inqbuf-atap_sata_features_en != 0  inqbuf-atap_sata_features_en != 0x)
-			print_bitinfo2(\t, \n, inqbuf-atap_sata_features_supp,