Imported Upstream version 2.5.0
[debian/amanda] / contrib / gsc / tstinq.c
1 /*
2  * %W% %G%
3  * $Id: tstinq.c,v 1.1 2001/04/15 11:12:37 ant Exp $
4  * Copyright (c) 1997 by Matthew Jacob
5  *
6  *      This software is free software; you can redistribute it and/or
7  *      modify it under the terms of the GNU Library General Public
8  *      License as published by the Free Software Foundation; version 2.
9  *
10  *      This software is distributed in the hope that it will be useful,
11  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *      Library General Public License for more details.
14  *
15  *      You should have received a copy of the GNU Library General Public
16  *      License along with this software; if not, write to the Free
17  *      Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *      The author may be reached via electronic communications at
20  *
21  *              mjacob@feral.com
22  *
23  *      or, via United States Postal Address
24  *
25  *              Matthew Jacob
26  *              1831 Castro Street
27  *              San Francisco, CA, 94131
28  */
29
30 #include <stdio.h>
31 #include <errno.h>
32 #include "gscdds.h"
33
34 static void process(char *, int);
35
36 int
37 main(int a, char **v)
38 {
39     int fd;
40
41     while (*++v) {
42         fd = open(*v, 0);
43         if (fd < 0) {
44             perror(*v);
45             continue;
46         }
47         process(*v, fd);
48         (void) close(fd);
49     }
50     return (0);
51 }
52
53 static void
54 process(char *name, int fd)
55 {
56     scmd_t scmd;
57     char sb[32], iqd[256], sbyte, c, dt;
58     static char cdb[6] = { 0x12, 0, 0, 0, 255, 0 };
59
60     scmd.cdb = cdb;
61     scmd.cdblen = sizeof (cdb);
62     scmd.data_buf = iqd;
63     scmd.datalen = 255;
64     scmd.sense_buf = sb;
65     scmd.senselen = sizeof (sb);
66     scmd.statusp = &sbyte;
67     scmd.rw = 1;
68     scmd.timeval = 5;
69
70     if (ioctl(fd, GSC_CMD, (caddr_t) &scmd) < 0) {
71         perror("GSC_CMD");
72         return;
73     }
74     dt = iqd[0] & 0x1f;
75     c = iqd[8+28];
76     iqd[8+28] = 0;
77     (void) fprintf(stdout, "%s:%-28s|Device Type %d\n", name, &iqd[8], dt);
78 }
79 /*
80  * mode: c
81  * Local variables:
82  * c-indent-level: 4
83  * c-brace-imaginary-offset: 0
84  * c-brace-offset: -4
85  * c-argdecl-indent: 4
86  * c-label-offset: -4
87  * c-continued-statement-offset: 4
88  * c-continued-brace-offset: 0
89  * End:
90  */