]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/usr.sbin/pcvt/ispcvt/ispcvt.c
merge fix for boot-time hang on centos' xen
[FreeBSD/FreeBSD.git] / 6 / usr.sbin / pcvt / ispcvt / ispcvt.c
1 /*
2  * Copyright (c) 1992, 2000 Hellmuth Michaelis
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27
28 /*---------------------------------------------------------------------------*
29  *
30  *      ispcvt - check for pcvt driver running and its options
31  *      ------------------------------------------------------
32  *
33  *      Last Edit-Date: [Fri Mar 31 10:24:43 2000]
34  *
35  * $FreeBSD$
36  *
37  *---------------------------------------------------------------------------*/
38
39 #include <stdio.h>
40 #include <err.h>
41 #include <fcntl.h>
42 #include <unistd.h>
43 #include <machine/pcvt_ioctl.h>
44
45 #define DEFAULTFD 0
46
47 main(argc,argv)
48 int argc;
49 char *argv[];
50 {
51         struct pcvtid pcvtid;
52         struct pcvtinfo pcvtinfo;
53         int c;
54         char *p;
55         int verbose = 0;
56         int config = 0;
57         int dflag = 0;
58         int n_screens = 0;
59         int fd;
60         char *device;
61
62         while( (c = getopt(argc, argv, "cd:nv")) != -1)
63         {
64                 switch(c)
65                 {
66                         case 'c':
67                                 config = 1;
68                                 break;
69
70                         case 'd':
71                                 device = optarg;
72                                 dflag = 1;
73                                 break;
74
75                         case 'n':
76                                 n_screens = 1;
77                                 break;
78
79                         case 'v':
80                                 verbose = 1;
81                                 break;
82
83                         case '?':
84                         default:
85                                 usage();
86                                 break;
87                 }
88         }
89
90         if(dflag)
91         {
92                 if((fd = open(device, O_RDWR)) == -1)
93                 {
94                         if(verbose)
95                                 warn("ERROR opening %s", device);
96                         exit(1);
97                 }
98         }
99         else
100         {
101                 fd = DEFAULTFD;
102         }
103
104         if(ioctl(fd, VGAPCVTID, &pcvtid) == -1)
105         {
106                 if(verbose)
107                         warn("ioctl VGAPCVTID failed, error");
108                 exit(1);
109         }
110
111         if(!strcmp(pcvtid.name, PCVTIDNAME))
112         {
113                 if(pcvtid.rmajor == PCVTIDMAJOR)
114                 {
115                         if(pcvtid.rminor != PCVTIDMINOR)
116                         {
117                                 if(verbose)
118                                         warnx("minor revision: expected %d, got %d", PCVTIDMINOR, pcvtid.rminor);
119                                 exit(4);        /* minor revision mismatch */
120                         }
121                 }
122                 else
123                 {
124                         if(verbose)
125                                 warnx("major revision: expected %d, got %d", PCVTIDMAJOR, pcvtid.rmajor);
126                         exit(3);        /* major revision mismatch */
127                 }
128         }
129         else
130         {
131                 if(verbose)
132                         warnx("name check: expected %s, got %s", PCVTIDNAME, pcvtid.name);
133                 exit(2);        /* name mismatch */
134         }
135
136         if(verbose)
137         {
138                 warnx("\nkernel and utils match, driver name [%s], release [%1.1d.%02.2d]\n",
139                           pcvtid.name, pcvtid.rmajor, pcvtid.rminor);
140         }
141
142         if(config == 0 && n_screens == 0)
143                 exit(0);
144
145         if(ioctl(fd, VGAPCVTINFO, &pcvtinfo) == -1)
146         {
147                 if(verbose)
148                         warn("ioctl VGAPCVTINFO failed, error");
149                 exit(1);
150         }
151
152         if(n_screens)
153         {
154                 printf("%d", pcvtinfo.nscreens);
155                 exit(0);
156         }
157
158         if(verbose)
159         {
160                 fprintf(stderr,"PCVT_NSCREENS        = %u\t\t", pcvtinfo.nscreens);
161                 fprintf(stderr,"PCVT_UPDATEFAST      = %u\n", pcvtinfo.updatefast);
162                 fprintf(stderr,"PCVT_UPDATESLOW      = %u\t\t", pcvtinfo.updateslow);
163                 fprintf(stderr,"PCVT_SYSBEEPF        = %u\n", pcvtinfo.sysbeepf);
164                 fprintf(stderr,"PCVT_PCBURST         = %u\t\t", pcvtinfo.pcburst);
165                 fprintf(stderr,"PCVT_KBD_FIFO_SZ     = %u\n\n", pcvtinfo.kbd_fifo_sz);
166
167                 /* config booleans */
168
169                 fprintf(stderr,"PCVT_132GENERIC      = %s",
170                         (pcvtinfo.compile_opts & CONF_132GENERIC) ? "ON" : "OFF");
171                 next();
172                 fprintf(stderr,"PCVT_24LINESDEF      = %s",
173                         (pcvtinfo.compile_opts & CONF_24LINESDEF) ? "ON" : "OFF");
174                 next();
175                 fprintf(stderr,"PCVT_CTRL_ALT_DEL    = %s",
176                         (pcvtinfo.compile_opts & CONF_CTRL_ALT_DEL) ? "ON" : "OFF");
177                 next();
178                 fprintf(stderr,"PCVT_INHIBIT_NUMLOCK = %s",
179                         (pcvtinfo.compile_opts & CONF_INHIBIT_NUMLOCK) ? "ON" : "OFF");
180                 next();
181                 fprintf(stderr,"PCVT_META_ESC        = %s",
182                         (pcvtinfo.compile_opts & CONF_META_ESC) ? "ON" : "OFF");
183                 next();
184                 fprintf(stderr,"PCVT_NO_LED_UPDATE   = %s",
185                         (pcvtinfo.compile_opts & CONF_NO_LED_UPDATE) ? "ON" : "OFF");
186                 next();
187                 fprintf(stderr,"PCVT_NULLCHARS       = %s",
188                         (pcvtinfo.compile_opts & CONF_NULLCHARS) ? "ON" : "OFF");
189                 next();
190                 fprintf(stderr,"PCVT_PRETTYSCRNS     = %s",
191                         (pcvtinfo.compile_opts & CONF_PRETTYSCRNS) ? "ON" : "OFF");
192                 next();
193                 fprintf(stderr,"PCVT_SCREENSAVER     = %s",
194                         (pcvtinfo.compile_opts & CONF_SCREENSAVER) ? "ON" : "OFF");
195                 next();
196                 fprintf(stderr,"PCVT_SETCOLOR        = %s",
197                         (pcvtinfo.compile_opts & CONF_SETCOLOR) ? "ON" : "OFF");
198                 next();
199                 fprintf(stderr,"PCVT_SHOWKEYS        = %s",
200                         (pcvtinfo.compile_opts & CONF_SHOWKEYS) ? "ON" : "OFF");
201                 next();
202                 fprintf(stderr,"PCVT_SLOW_INTERRUPT  = %s",
203                         (pcvtinfo.compile_opts & CONF_SLOW_INTERRUPT) ? "ON" : "OFF");
204                 next();
205                 fprintf(stderr,"PCVT_USEKBDSEC       = %s",
206                         (pcvtinfo.compile_opts & CONF_USEKBDSEC) ? "ON" : "OFF");
207                 next();
208                 fprintf(stderr,"PCVT_VT220KEYB       = %s",
209                         ((u_int)pcvtinfo.compile_opts & (u_int)CONF_VT220KEYB) ? "ON" : "OFF");
210                 next();
211                 fprintf(stderr,"XSERVER              = %s",
212                         (pcvtinfo.compile_opts & CONF_XSERVER) ? "ON" : "OFF");
213
214                 next();
215                 fprintf(stderr,"PCVT_GREENSAVER      = %s",
216                         (pcvtinfo.compile_opts & CONF_GREENSAVER) ? "ON" : "OFF");
217
218                 fprintf(stderr,"\n\n");
219         }
220         else /* !verbose */
221         {
222                 fprintf(stderr,"PCVT_NSCREENS    = %u\n", pcvtinfo.nscreens);
223                 fprintf(stderr,"PCVT_UPDATEFAST  = %u\n", pcvtinfo.updatefast);
224                 fprintf(stderr,"PCVT_UPDATESLOW  = %u\n", pcvtinfo.updateslow);
225                 fprintf(stderr,"PCVT_SYSBEEPF    = %u\n", pcvtinfo.sysbeepf);
226                 fprintf(stderr,"Compile options  = 0x%08X\n", pcvtinfo.compile_opts);
227         }
228 }
229
230 usage()
231 {
232         fprintf(stderr,"\nispcvt - verify current video driver is the pcvt-driver\n");
233         fprintf(stderr,"  usage: ispcvt [-c] [-d device] [-n] [-v]\n");
234         fprintf(stderr,"options: -c         print compile time configuration\n");
235         fprintf(stderr,"         -d <name>  use devicefile <name>\n");
236         fprintf(stderr,"         -n         print number of virtual screens (to stdout)\n");
237         fprintf(stderr,"         -v         be verbose\n\n");
238         exit(5);
239 }
240
241 next()
242 {
243         static int i = 0;
244
245         fprintf(stderr, "%s", (i == 0) ? "\t\t" : "\n");
246
247         i = ~i;
248 }
249
250 /* EOF */