chiark / gitweb /
[PATCH] extras multipath update
[elogind.git] / extras / multipath / unused.c
1 static int
2 get_serial (int fd, char * str)
3 {
4         char buff[MX_ALLOC_LEN + 1];
5         int len;
6
7         if (0 == do_inq(fd, 0, 1, 0x80, buff, MX_ALLOC_LEN, 0)) {
8                 len = buff[3];
9                 if (len > 0) {
10                         memcpy(str, buff + 4, len);
11                         buff[len] = '\0';
12                 }
13                 return 1;
14         }
15         return 0;
16 }
17
18 static int
19 do_tur(int fd)
20 {
21         unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
22         struct sg_io_hdr io_hdr;
23         unsigned char sense_buffer[32];
24
25         memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
26         io_hdr.interface_id = 'S';
27         io_hdr.cmd_len = sizeof (turCmdBlk);
28         io_hdr.mx_sb_len = sizeof (sense_buffer);
29         io_hdr.dxfer_direction = SG_DXFER_NONE;
30         io_hdr.cmdp = turCmdBlk;
31         io_hdr.sbp = sense_buffer;
32         io_hdr.timeout = 20000;
33         io_hdr.pack_id = 0;
34         if (ioctl(fd, SG_IO, &io_hdr) < 0) {
35                 close(fd);
36                 return 0;
37         }
38         if (io_hdr.info & SG_INFO_OK_MASK) {
39                 return 0;
40         }
41         return 1;
42 }
43
44 static int
45 del_map(char * str) {
46         struct dm_task *dmt;
47
48         if (!(dmt = dm_task_create(DM_DEVICE_REMOVE)))
49                 return 0;
50         if (!dm_task_set_name(dmt, str))
51                 goto delout;
52         if (!dm_task_run(dmt))
53                 goto delout;
54
55         printf("Deleted device map : %s\n", str);
56
57         delout:
58         dm_task_destroy(dmt);
59         return 1;
60 }
61
62 get_table(const char * str)
63 {
64         int r = 0;
65         struct dm_task *dmt;
66         void *next = NULL;
67         uint64_t start, length;
68         char *target_type = NULL;
69         char *params;
70
71         if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
72                 return 0;
73
74         if (!dm_task_set_name(dmt, str))
75                 goto out;
76
77         if (!dm_task_run(dmt))
78                 goto out;
79
80         do {
81                 next = dm_get_next_target(dmt, next, &start, &length,
82                                           &target_type, &params);
83                 if (target_type) {
84                         printf("%" PRIu64 " %" PRIu64 " %s %s\n",
85                                start, length, target_type, params);
86                 }
87         } while (next);
88
89         r = 1;
90
91       out:
92         dm_task_destroy(dmt);
93         return r;
94
95 }