1769cbb3ab7bfe6374f9ec418b4868dcb01402f3
[dragonfly.git] / usr.sbin / dpt / dpt_ctls / dpt_ctls.c
1 /*
2  *       Copyright (c) 1997 by Simon Shapiro
3  *       All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions, and the following disclaimer,
10  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/usr.sbin/dpt/dpt_ctls/dpt_ctls.c,v 1.3 1999/08/28 01:16:06 peter Exp $
30  * $DragonFly: src/usr.sbin/dpt/dpt_ctls/dpt_ctls.c,v 1.2 2003/06/17 04:29:53 dillon Exp $
31  */
32
33 /* dpt_ctls.c:  Dunp a the number of configured DPT HBAs */
34
35 #include <fcntl.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <sys/time.h>
40 #include <sys/stat.h>
41 #include <sys/queue.h>
42 #include <sys/ioctl.h>
43 #include <scsi/scsi_all.h>
44 #include <scsi/scsi_message.h>
45 #include <scsi/scsiconf.h>
46
47 #include <sys/dpt.h>
48
49 int
50 main(int argc, char **argv, char **argp)
51 {
52     eata_pt_t    pass_thru;
53     int                  controllers_present;
54     
55     int result;
56     int fd;
57
58     if ( (fd = open(argv[1], O_RDWR, S_IRUSR | S_IWUSR)) == -1 ) {
59                 (void)fprintf(stderr, "%s ERROR:  Failed to open \"%s\" - %s\n",
60                                           argv[0], argv[1], strerror(errno));
61                 exit(1);
62     }
63
64     pass_thru.eataID[0] = 'E';
65     pass_thru.eataID[1] = 'A';
66     pass_thru.eataID[2] = 'T';
67     pass_thru.eataID[3] = 'A';
68     pass_thru.command   = DPT_NUMCTRLS;
69     pass_thru.command_buffer = (u_int8_t *)&controllers_present;
70
71     if ( (result = ioctl(fd, DPT_IOCTL_SEND, &pass_thru)) != 0 ) {
72                 (void)fprintf(stderr, "%s ERROR:  Failed to send IOCTL "
73                               "%lx - %s\n",
74                               argv[0], DPT_IOCTL_SEND,
75                               strerror(errno));
76                 exit(1);
77     }
78
79         (void)fprintf(stdout, "%d\n", controllers_present);
80     return(0);
81 }