chiark / gitweb /
[PATCH] update volume_id
[elogind.git] / extras / multipath-tools / multipathd / checkers.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include <sys/ioctl.h>
8
9 #include "sg_include.h"
10
11 #define TUR_CMD_LEN      6
12
13 /*
14  * test IO functions : add yours here
15  *
16  * returns 0 : path gone valid
17  * returns 1 : path still failed
18  */
19
20 int readsector0 (char *devnode)
21 {
22         int fd, r;
23         char buf;
24
25         fd = open (devnode, O_RDONLY);
26         if (read (fd, &buf, 1) != 1)
27                 r = 0;
28         else
29                 r = 1;
30         
31         close (fd);
32
33         return r;
34 }
35
36 int tur(char *devnode)
37 {
38         unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
39         struct sg_io_hdr io_hdr;
40         unsigned char sense_buffer[32];
41         int fd;
42
43         fd = open (devnode, O_RDONLY);
44
45         memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
46         io_hdr.interface_id = 'S';
47         io_hdr.cmd_len = sizeof (turCmdBlk);
48         io_hdr.mx_sb_len = sizeof (sense_buffer);
49         io_hdr.dxfer_direction = SG_DXFER_NONE;
50         io_hdr.cmdp = turCmdBlk;
51         io_hdr.sbp = sense_buffer;
52         io_hdr.timeout = 20000;
53         io_hdr.pack_id = 0;
54         if (ioctl(fd, SG_IO, &io_hdr) < 0) {
55                 close(fd);
56                 return 0;
57         }
58         if (io_hdr.info & SG_INFO_OK_MASK) {
59                 return 0;
60         }
61         return 1;
62 }