1 From a3db7def912c2fd3756cfd99c1165db075281caa Mon Sep 17 00:00:00 2001
2 From: Fabio M. Di Nitto <fdinitto@redhat.com>
3 Date: Tue, 13 Oct 2009 09:26:02 +0200
4 Subject: [PATCH 05/12] RH: cciss_id
6 Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
8 :100644 100644 54be0a5... 7e4b7b1... M Makefile
9 :000000 100644 0000000... 6db12a4... A cciss_id/Makefile
10 :000000 100644 0000000... 091b5fe... A cciss_id/cciss_id.c
12 cciss_id/Makefile | 47 +++++++++++++++++++
13 cciss_id/cciss_id.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++
14 3 files changed, 177 insertions(+), 1 deletions(-)
16 diff --git a/Makefile b/Makefile
17 index 54be0a5..7e4b7b1 100644
20 @@ -25,7 +25,8 @@ BUILDDIRS = \
21 libmultipath/checkers \
28 ifeq ($(MULTIPATH_VERSION),)
29 VERSION = $(shell basename ${PWD} | cut -d'-' -f3)
30 diff --git a/cciss_id/Makefile b/cciss_id/Makefile
32 index 0000000..6db12a4
34 +++ b/cciss_id/Makefile
37 +# *****************************************************************************
39 +# * (C) Copyright 2007 Hewlett-Packard Development Company, L.P *
41 +# * This program is free software; you can redistribute it and/or modify it *
42 +# * under the terms of the GNU General Public License as published by the Free*
43 +# * Software Foundation; either version 2 of the License, or (at your option)*
44 +# * any later version. *
46 +# * This program is distributed in the hope that it will be useful, but *
47 +# * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY*
48 +# * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
49 +# * for more details. *
51 +# * You should have received a copy of the GNU General Public License along *
52 +# * with this program; if not, write to the Free Software Foundation, Inc., *
53 +# * 675 Mass Ave, Cambridge, MA 02139, USA. *
58 +# *****************************************************************************
60 +include ../Makefile.inc
63 +CFLAGS = -pipe -g -Wall -Wunused -Wstrict-prototypes
65 +LDFLAGS = -ldevmapper
72 + $(CC) $(OBJS) -o $(EXEC) $(LDFLAGS)
75 + $(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir)
76 + $(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir)/
79 + rm $(DESTDIR)$(bindir)/$(EXEC)
82 + rm -f core.* *.o $(EXEC) *.gz
83 diff --git a/cciss_id/cciss_id.c b/cciss_id/cciss_id.c
85 index 0000000..091b5fe
87 +++ b/cciss_id/cciss_id.c
90 + *****************************************************************************
92 + * (C) Copyright 2007 Hewlett-Packard Development Company, L.P *
94 + * This program is free software; you can redistribute it and/or modify it *
95 + * under the terms of the GNU General Public License as published by the Free*
96 + * Software Foundation; either version 2 of the License, or (at your option)*
97 + * any later version. *
99 + * This program is distributed in the hope that it will be useful, but *
100 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY*
101 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
102 + * for more details. *
104 + * You should have received a copy of the GNU General Public License along *
105 + * with this program; if not, write to the Free Software Foundation, Inc., *
106 + * 675 Mass Ave, Cambridge, MA 02139, USA. *
111 + *****************************************************************************
114 +#include <sys/types.h>
115 +#include <sys/stat.h>
116 +#include <sys/ioctl.h>
124 +#include <linux/cciss_ioctl.h>
126 +#define LEN_PAGE83_CCISSDEV 0x20 /* Page length of 83h for cciss devices */
127 +#define LEN_DEVICEFILE 255 /* Length of device file name */
128 +#define PATH_CCISSDEV "/dev/cciss/" /* Path of CCISS devices */
129 +int main(int argc, char *argv[])
131 + const int resp_len = LEN_PAGE83_CCISSDEV;
132 + unsigned char resp[resp_len+1];
133 + char dev_name[LEN_DEVICEFILE] = "\0" ;
134 + unsigned int lun_id = 0;
136 + struct stat file_stat;
138 + LogvolInfo_struct lvi; // logical "volume" info
139 + IOCTL_Command_struct cic; // cciss ioctl command
142 + fprintf(stderr, "Usage: %s /dev/cciss/cNdN\n", argv[0]);
146 + if ( strncmp(PATH_CCISSDEV, argv[1], strlen(PATH_CCISSDEV) ) != 0 ) {
147 + if ( strchr(argv[1], '!') ) {
148 + sprintf(dev_name, "%s%s", PATH_CCISSDEV,
149 + strchr(argv[1], '!')+1);
151 + //fprintf(stderr, "dev_name is: -%s-", dev_name);
153 + sprintf(dev_name, "%s", argv[1]);
156 + if (stat(dev_name, &file_stat) < 0) {
157 + fprintf (stderr, "Stat failed for file %s. Errno=%d\n", dev_name, errno);
160 + if (!S_ISBLK(file_stat.st_mode)) {
161 + fprintf (stderr, "File %s is not a block device. \n", dev_name);
166 + if((fd = open(dev_name, O_RDWR)) < 0) {
167 + fprintf(stderr, "Open failed for file %s. Errno=%d\n", dev_name, errno);
171 + if (ioctl(fd, CCISS_GETLUNINFO, &lvi) < 0) {
172 + fprintf(stderr, "IOCTL failure CCISS_GETLUNINFO for file %s Errno=%d\n", dev_name, errno);
176 + lun_id = lvi.LunID;
179 + memset(&cic, 0, sizeof(IOCTL_Command_struct));
180 + memset(resp, 0, resp_len+1);
181 + cic.LUN_info.LogDev.Mode = 0x01; /* logical volume addressing */
182 + cic.LUN_info.LogDev.VolId = lun_id & 0x3FFFFFFF;
183 + cic.Request.CDBLen = 6;
184 + cic.Request.Type.Type = TYPE_CMD; // It is a command.
185 + cic.Request.Type.Attribute = ATTR_SIMPLE;
186 + cic.Request.Type.Direction = XFER_READ; // Read
187 + cic.Request.Timeout = 0; // Don't time out
188 + cic.Request.CDB[0] = 0x12;
189 + cic.Request.CDB[1] = 0x01; /* EVPD (enable vital product data) */
190 + cic.Request.CDB[2] = 0x83;
191 + cic.Request.CDB[4] = resp_len & 0xFF;
192 + cic.buf_size = resp_len;
194 + status = ioctl(fd, CCISS_PASSTHRU, &cic);
196 + fprintf(stderr, "IOCTL failure CCISS_PASSTHRU for file %s Errno=%d\n", dev_name, errno);
201 + if ((cic.error_info.CommandStatus | cic.error_info.ScsiStatus )) {
202 + fprintf(stderr, "CCISS command status error for Inquiry on %s\n",
208 + for(i=8; i<24; i++)
209 + /* printf("Buff[%d] =%x\n", i, resp[i]); */
210 + printf("%02x", resp[i]);