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 */
9 #include <dev/ata/atareg.h>
10 #include <sys/ataio.h>
11 #include <sys/ioctl.h>
12 #include <sys/param.h>
14 int main(int argc
, char *argv
[])
20 unsigned char inbuf
[DEV_BSIZE
];
21 struct ataparams inqbuf
;
25 /* check argument count */
27 fprintf(stderr
, "usage: %s /dev/file\n", argv
[0]);
31 /* open device file descriptor */
32 if ((fd
= open(argv
[1], O_RDONLY
)) == -1) {
37 /* construct an ata request */
38 memset(&req
, 0, sizeof req
);
39 req
.flags
= ATACMD_READ
;
40 req
.command
= WDCC_IDENTIFY
;
41 req
.databuf
= (caddr_t
) &inbuf
;
42 req
.datalen
= sizeof(inbuf
);
43 req
.timeout
= 1000; /* 1 sec */
45 /* make the ioctl call */
46 if (ioctl(fd
, ATAIOCCOMMAND
, &req
) == -1) {
51 /* handle ata request return status */
56 fprintf(stderr
, "ata request timed out\n");
59 fprintf(stderr
, "ata device returned a device fault\n");
62 fprintf(stderr
, "ata device returned error code: %0x\n", req
.error
);
65 fprintf(stderr
, "unknown ata request return status: %d\n", req
.retsts
);
70 for (i
= 0; i
< sizeof(inbuf
.inqbuf
.atap_model
); i
+=2) {
71 p
= (u_int16_t
*) (inbuf
.inqbuf
.atap_model
+ i
);
75 for (i
= 0; i
< sizeof(inbuf
.inqbuf
.atap_model
); i
++)
76 printf("%c", inbuf
.inqbuf
.atap_model
[i
]);
78 /* close file descriptor */