2 * WARNING: I got spontaneous hangups with the following code in NetBSD 4.99.20
5 * gcc readwd.c -o readwd -Wall -W -Wextra -ansi -pedantic
13 #include <dev/ata/atareg.h>
14 #include <sys/ataio.h>
15 #include <sys/ioctl.h>
16 #include <sys/param.h>
18 int main(int argc
, char *argv
[])
24 unsigned char inbuf
[DEV_BSIZE
];
25 struct ataparams inqbuf
;
29 /* Check argument count */
31 fprintf(stderr
, "usage: %s /dev/file\n", argv
[0]);
35 /* Open device file descriptor */
36 if ((fd
= open(argv
[1], O_RDONLY
)) == -1) {
41 /* Construct an ata request */
42 memset(&req
, 0, sizeof req
);
43 req
.flags
= ATACMD_READ
;
44 req
.command
= WDCC_IDENTIFY
;
45 req
.databuf
= (caddr_t
) &inbuf
;
46 req
.datalen
= sizeof inbuf
;
47 req
.timeout
= 1000; /* 1 sec */
49 /* Make the ioctl call */
50 if (ioctl(fd
, ATAIOCCOMMAND
, &req
) == -1) {
55 /* Handle ata request return status */
60 fprintf(stderr
, "ata request timed out\n");
63 fprintf(stderr
, "ata device returned a device fault\n");
66 fprintf(stderr
, "ata device returned error code: %0x\n", req
.error
);
69 fprintf(stderr
, "unknown ata request return status: %d\n", req
.retsts
);
74 * Magic for little endian archs
75 * FIXME: add #ifdef condition for little endian archs
77 for (i
= 0; i
< sizeof inbuf
.inqbuf
.atap_model
; i
+=2) {
78 p
= (u_int16_t
*) (inbuf
.inqbuf
.atap_model
+ i
);
82 /* Print the model (trim spaces when printing) */
83 for (i
= 0; i
< sizeof inbuf
.inqbuf
.atap_model
; i
++)
84 if (inbuf
.inqbuf
.atap_model
[i
] != ' ')
85 printf("%c", inbuf
.inqbuf
.atap_model
[i
]);
88 /* Close file descriptor */