summaryrefslogtreecommitdiff
path: root/extras/multipath-tools/multipathd/checkers.c
blob: 7ad32b04e9d51b7a941a86c2f20a1e7eb1138565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>

#include "sg_include.h"

#define TUR_CMD_LEN      6

/*
 * test IO functions : add yours here
 *
 * returns 0 : path gone valid
 * returns 1 : path still failed
 */

int readsector0 (char *devnode)
{
	int fd, r;
	char buf;

	fd = open (devnode, O_RDONLY);
	if (read (fd, &buf, 1) != 1)
		r = 0;
	else
		r = 1;
	
	close (fd);

	return r;
}

int tur(char *devnode)
{
        unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
        struct sg_io_hdr io_hdr;
        unsigned char sense_buffer[32];
	int fd;

	fd = open (devnode, O_RDONLY);

        memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
        io_hdr.interface_id = 'S';
        io_hdr.cmd_len = sizeof (turCmdBlk);
        io_hdr.mx_sb_len = sizeof (sense_buffer);
        io_hdr.dxfer_direction = SG_DXFER_NONE;
        io_hdr.cmdp = turCmdBlk;
        io_hdr.sbp = sense_buffer;
        io_hdr.timeout = 20000;
        io_hdr.pack_id = 0;
        if (ioctl(fd, SG_IO, &io_hdr) < 0) {
                close(fd);
                return 0;
        }
        if (io_hdr.info & SG_INFO_OK_MASK) {
                return 0;
        }
        return 1;
}