1 /* WARNING: I got spontaneous hangups with the following code in NetBSD 4.99.20
3 gcc readwd.c -o readwd -Wall -W -Wextra -ansi -pedantic */
10 #include <dev/ata/atareg.h>
11 #include <sys/ataio.h>
12 #include <sys/ioctl.h>
13 #include <sys/param.h>
15 int main(int argc
, char *argv
[])
21 unsigned char inbuf
[DEV_BSIZE
];
22 struct ataparams inqbuf
;
26 /* check argument count */
28 fprintf(stderr
, "usage: %s /dev/file\n", argv
[0]);
32 /* open device file descriptor */
33 if ((fd
= open(argv
[1], O_RDONLY
)) == -1) {
38 /* construct an ata request */
39 memset(&req
, 0, sizeof req
);
40 req
.flags
= ATACMD_READ
;
41 req
.command
= WDCC_IDENTIFY
;
42 req
.databuf
= (caddr_t
) &inbuf
;
43 req
.datalen
= sizeof inbuf
;
44 req
.timeout
= 1000; /* 1 sec */
46 /* make the ioctl call */
47 if (ioctl(fd
, ATAIOCCOMMAND
, &req
) == -1) {
52 /* handle ata request return status */
57 fprintf(stderr
, "ata request timed out\n");
60 fprintf(stderr
, "ata device returned a device fault\n");
63 fprintf(stderr
, "ata device returned error code: %0x\n", req
.error
);
66 fprintf(stderr
, "unknown ata request return status: %d\n", req
.retsts
);
70 /* magic for little endian archs
71 * FIXME: add #ifdef condition for little endian archs
73 for (i
= 0; i
< sizeof inbuf
.inqbuf
.atap_model
; i
+=2) {
74 p
= (u_int16_t
*) (inbuf
.inqbuf
.atap_model
+ i
);
78 /* print the model (trim spaces when printing) */
79 for (i
= 0; i
< sizeof inbuf
.inqbuf
.atap_model
; i
++)
80 if (inbuf
.inqbuf
.atap_model
[i
] != ' ')
81 printf("%c", inbuf
.inqbuf
.atap_model
[i
]);
84 /* close file descriptor */