[Fwd: SMART-ide how???]

Mark Lord (mlord@pobox.com)
Tue, 11 Aug 1998 22:17:58 -0400


This is a multi-part message in MIME format.
--------------AC9FB6B195695DA1028FBCE5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Gadi, do you have a /proc/ide version of the S.M.A.R.T. demo?

-ml

--------------------------

> Gadi's utility is attached.
> --
> mlord@pobox.com
>
>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <string.h>
> #include <linux/hdreg.h>
> #include <linux/types.h>
>
> #define NR_ATTRIBUTES 30
>
> typedef struct threshold_s {
> __u8 id;
> __u8 threshold;
> __u8 reserved[10];
> } __attribute__ ((packed)) threshold_t;
>
> typedef struct thresholds_s {
> __u16 revision;
> threshold_t thresholds[NR_ATTRIBUTES];
> __u8 reserved[18];
> __u8 vendor[131];
> __u8 checksum;
> } __attribute__ ((packed)) thresholds_t;
>
> typedef struct value_s {
> __u8 id;
> __u16 status;
> __u8 value;
> __u8 vendor[8];
> } __attribute__ ((packed)) value_t;
>
> typedef struct values_s {
> __u16 revision;
> value_t values[NR_ATTRIBUTES];
> __u8 offline_status;
> __u8 vendor1;
> __u16 offline_timeout;
> __u8 vendor2;
> __u8 offline_capability;
> __u16 smart_capability;
> __u8 reserved[16];
> __u8 vendor[125];
> __u8 checksum;
> } __attribute__ ((packed)) values_t;
>
> #define NR_OFFLINE_TEXTS 5
> struct {
> __u8 value;
> char *text;
> } offline_status_text[NR_OFFLINE_TEXTS] = {
> { 0x00, "NeverStarted" },
> { 0x02, "Completed" },
> { 0x04, "Suspended" },
> { 0x05, "Aborted" },
> { 0x06, "Failed" }
> };
>
> int fd;
> values_t values;
> thresholds_t thresholds;
>
> static char *get_offline_text(int status)
> {
> int i;
>
> for (i = 0; i < NR_OFFLINE_TEXTS; i++)
> if (offline_status_text[i].value == status)
> return offline_status_text[i].text;
> return "unknown";
> }
>
> static void smart_read_values(void)
> {
> __u8 args[4 + 512] = {WIN_SMART, 0, SMART_READ_VALUES, 1, };
>
> if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
> perror(" couldn't read values");
> return;
> }
> memcpy(&values, args + 4, 512);
> }
>
> static void print_value(value_t *p, threshold_t *t)
> {
> if (!p->id || !t->id || p->id != t->id)
> return;
> printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", p->id, p->status,
> p->status & 1 ? "PreFailture" : "Advisory ",
> p->status & 2 ? "OnLine " : "OffLine",
> p->value, t->threshold,
> p->value > t->threshold ? "Passed" : "Failed");
> }
>
> static void print_values(values_t *p, thresholds_t *t)
> {
> value_t *value = p->values;
> threshold_t *threshold = t->thresholds;
> int i;
>
> printf("\n");
> for (i = 0; i < NR_ATTRIBUTES; i++)
> print_value(value++, threshold++);
> printf("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n",
> p->offline_status, get_offline_text(p->offline_status & 0x7f),
> p->offline_status & 0x80 ? "Yes" : "No",
> p->offline_timeout / 60);
> printf("OffLineCapability=%d {%s %s %s}\n", p->offline_capability,
> p->offline_capability & 1 ? "Immediate" : "",
> p->offline_capability & 2 ? "Auto" : "",
> p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
> printf("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n",
> p->revision, p->checksum, p->smart_capability,
> p->smart_capability & 1 ? "SaveOnStandBy" : "",
> p->smart_capability & 2 ? "AutoSave" : "");
> printf("\n");
> }
>
> static void print_threshold(threshold_t *p)
> {
> if (!p->id)
> return;
> printf("Id=%3d, Threshold=%3d\n", p->id, p->threshold);
> }
>
> static void print_thresholds(thresholds_t *p)
> {
> threshold_t *threshold = p->thresholds;
> int i;
>
> printf("\n");
> printf("SmartRevision=%d\n", p->revision);
> for (i = 0; i < NR_ATTRIBUTES; i++)
> print_threshold(threshold++);
> printf("CheckSum=%d\n", p->checksum);
> printf("\n");
> }
>
> static void smart_read_thresholds(void)
> {
> __u8 args[4 + 512] = {WIN_SMART, 0, SMART_READ_THRESHOLDS, 1, };
>
> if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
> perror(" SMART_READ_THRESHOLDS failed");
> return;
> }
> memcpy(&thresholds, args + 4, 512);
> }
>
> static void smart_disable(void)
> {
> __u8 args[4] = {WIN_SMART, 0, SMART_DISABLE, 0};
>
> if (ioctl(fd, HDIO_DRIVE_CMD, &args))
> perror(" SMART_DISABLE failed");
> }
>
> static void smart_enable(void)
> {
> __u8 args[4] = {WIN_SMART, 0, SMART_ENABLE, 0};
>
> if (ioctl(fd, HDIO_DRIVE_CMD, &args))
> perror(" SMART_ENABLE failed");
> }
>
> static void smart_offline_immediate(void)
> {
> __u8 args[4] = {WIN_SMART, 0, SMART_IMMEDIATE_OFFLINE, 0};
>
> if (ioctl(fd, HDIO_DRIVE_CMD, &args))
> perror(" SMART_IMMEDIATE_OFFLINE falied");
>
> }
>
> int main(int argc, char *argv[])
> {
> if (argc != 2) {
> printf("usage: ide-smart device\n");
> return 0;
> }
> if ((fd = open(argv[1], O_RDONLY)) == -1) {
> perror("couldn't open device");
> return 0;
> }
> smart_enable();
> #if 1
> smart_offline_immediate();
> #endif
> smart_read_values();
> smart_read_thresholds();
> print_values(&values, &thresholds);
> close(fd);
> return 0;
> }

-- 
mlord@pobox.com
--------------AC9FB6B195695DA1028FBCE5
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Received: from growl.pobox.com (growl.pobox.com [208.210.124.27]) by mag1.magmacom.com (8.8.8/8.8.6) with ESMTP id AAA24492 for <mlord@magmacom.com>; Tue, 11 Aug 1998 00:23:42 -0400 (EDT) Received: (from daemon@localhost) by growl.pobox.com (8.8.7/8.8.5) id AAA11301 for mlord@magmacom.com.filterdone; Tue, 11 Aug 1998 00:23:35 -0400 (EDT) Received: from vger.rutgers.edu (vger.rutgers.edu [128.6.190.2]) by growl.pobox.com (8.8.7/8.8.5) with ESMTP id AAA30508; Tue, 11 Aug 1998 00:23:20 -0400 (EDT) Received: by vger.rutgers.edu id <154188-14319>; Mon, 10 Aug 1998 21:56:58 -0400 Received: from x2port114.magma.ca ([206.191.28.114]:1072 "EHLO Foxy.org" ident: "root") by vger.rutgers.edu with ESMTP id <154881-14319>; Mon, 10 Aug 1998 19:32:20 -0400 Received: from pobox.com (root@localhost [127.0.0.1]) by Foxy.org (8.8.7/8.8.7) with ESMTP id UAA00461; Mon, 10 Aug 1998 20:10:41 -0400 Message-ID: <35CF8C01.5AC87784@pobox.com> Date: Mon, 10 Aug 1998 20:10:41 -0400 From: Mark Lord <mlord@pobox.com> Organization: Real-Time Remedies Inc. X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.1.115 i686) MIME-Version: 1.0 To: paul@ping.at CC: linux-kernel@vger.rutgers.edu Subject: Re: SMART-ide how??? References: <19980810225039.41247@snoopy.ping.at> Content-Type: multipart/mixed; boundary="------------B2074F0F92EB5B0D386C28B7" X-Orcpt: rfc822;linux-kernel@vger.rutgers.edu Sender: owner-linux-kernel@vger.rutgers.edu Precedence: bulk X-Loop: majordomo@vger.rutgers.edu

This is a multi-part message in MIME format. --------------B2074F0F92EB5B0D386C28B7 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit

Gadi's utility is attached.

-- 
mlord@pobox.com
--------------B2074F0F92EB5B0D386C28B7
Content-Type: text/plain; charset=us-ascii; name="ide-smart.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="ide-smart.c"

#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #include <linux/hdreg.h> #include <linux/types.h>

#define NR_ATTRIBUTES 30

typedef struct threshold_s { __u8 id; __u8 threshold; __u8 reserved[10]; } __attribute__ ((packed)) threshold_t; typedef struct thresholds_s { __u16 revision; threshold_t thresholds[NR_ATTRIBUTES]; __u8 reserved[18]; __u8 vendor[131]; __u8 checksum; } __attribute__ ((packed)) thresholds_t;

typedef struct value_s { __u8 id; __u16 status; __u8 value; __u8 vendor[8]; } __attribute__ ((packed)) value_t;

typedef struct values_s { __u16 revision; value_t values[NR_ATTRIBUTES]; __u8 offline_status; __u8 vendor1; __u16 offline_timeout; __u8 vendor2; __u8 offline_capability; __u16 smart_capability; __u8 reserved[16]; __u8 vendor[125]; __u8 checksum; } __attribute__ ((packed)) values_t;

#define NR_OFFLINE_TEXTS 5 struct { __u8 value; char *text; } offline_status_text[NR_OFFLINE_TEXTS] = { { 0x00, "NeverStarted" }, { 0x02, "Completed" }, { 0x04, "Suspended" }, { 0x05, "Aborted" }, { 0x06, "Failed" } };

int fd; values_t values; thresholds_t thresholds;

static char *get_offline_text(int status) { int i;

for (i = 0; i < NR_OFFLINE_TEXTS; i++) if (offline_status_text[i].value == status) return offline_status_text[i].text; return "unknown"; }

static void smart_read_values(void) { __u8 args[4 + 512] = {WIN_SMART, 0, SMART_READ_VALUES, 1, };

if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { perror(" couldn't read values"); return; } memcpy(&values, args + 4, 512); }

static void print_value(value_t *p, threshold_t *t) { if (!p->id || !t->id || p->id != t->id) return; printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", p->id, p->status, p->status & 1 ? "PreFailture" : "Advisory ", p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold, p->value > t->threshold ? "Passed" : "Failed"); }

static void print_values(values_t *p, thresholds_t *t) { value_t *value = p->values; threshold_t *threshold = t->thresholds; int i;

printf("\n"); for (i = 0; i < NR_ATTRIBUTES; i++) print_value(value++, threshold++); printf("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n", p->offline_status, get_offline_text(p->offline_status & 0x7f), p->offline_status & 0x80 ? "Yes" : "No", p->offline_timeout / 60); printf("OffLineCapability=%d {%s %s %s}\n", p->offline_capability, p->offline_capability & 1 ? "Immediate" : "", p->offline_capability & 2 ? "Auto" : "", p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd"); printf("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n", p->revision, p->checksum, p->smart_capability, p->smart_capability & 1 ? "SaveOnStandBy" : "", p->smart_capability & 2 ? "AutoSave" : ""); printf("\n"); }

static void print_threshold(threshold_t *p) { if (!p->id) return; printf("Id=%3d, Threshold=%3d\n", p->id, p->threshold); }

static void print_thresholds(thresholds_t *p) { threshold_t *threshold = p->thresholds; int i;

printf("\n"); printf("SmartRevision=%d\n", p->revision); for (i = 0; i < NR_ATTRIBUTES; i++) print_threshold(threshold++); printf("CheckSum=%d\n", p->checksum); printf("\n"); }

static void smart_read_thresholds(void) { __u8 args[4 + 512] = {WIN_SMART, 0, SMART_READ_THRESHOLDS, 1, };

if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { perror(" SMART_READ_THRESHOLDS failed"); return; } memcpy(&thresholds, args + 4, 512); }

static void smart_disable(void) { __u8 args[4] = {WIN_SMART, 0, SMART_DISABLE, 0};

if (ioctl(fd, HDIO_DRIVE_CMD, &args)) perror(" SMART_DISABLE failed"); }

static void smart_enable(void) { __u8 args[4] = {WIN_SMART, 0, SMART_ENABLE, 0};

if (ioctl(fd, HDIO_DRIVE_CMD, &args)) perror(" SMART_ENABLE failed"); }

static void smart_offline_immediate(void) { __u8 args[4] = {WIN_SMART, 0, SMART_IMMEDIATE_OFFLINE, 0};

if (ioctl(fd, HDIO_DRIVE_CMD, &args)) perror(" SMART_IMMEDIATE_OFFLINE falied");

}

int main(int argc, char *argv[]) { if (argc != 2) { printf("usage: ide-smart device\n"); return 0; } if ((fd = open(argv[1], O_RDONLY)) == -1) { perror("couldn't open device"); return 0; } smart_enable(); #if 1 smart_offline_immediate(); #endif smart_read_values(); smart_read_thresholds(); print_values(&values, &thresholds); close(fd); return 0; }

--------------B2074F0F92EB5B0D386C28B7--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html

--------------AC9FB6B195695DA1028FBCE5--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html