3 * $Id: ucfggsc.c,v 1.1 2001/04/15 11:12:37 ant Exp $
4 * Copyright (c) 1997 by Matthew Jacob
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.
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.
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.
19 * The author may be reached via electronic communications at
23 * or, via United States Postal Address
27 * San Francisco, CA, 94131
31 #include <sys/types.h>
33 #include <sys/cfgdb.h>
34 #include <sys/cfgodm.h>
36 #include <sys/sysconfig.h>
37 #include <sys/sysmacros.h>
38 #include <sys/device.h>
42 #define vprintf if (verbose) printf
44 extern mid_t loadext(char *, int, int);
47 err_exit(char exitcode)
49 odm_close_class(CuDv_CLASS);
50 odm_close_class(PdDv_CLASS);
56 main(int argc, char **argv)
58 char *logical_name, *ptr;
62 int rc, how_many, errflg, c, majorno, minorno, unit, verbose;
71 while ((c = getopt(argc,argv,"vl:")) != EOF) {
77 if (logical_name != NULL)
79 logical_name = optarg;
88 if (logical_name == NULL)
91 if (odm_initialize() == -1)
94 /* Get Customized Device Object for this device */
95 sprintf(sstring,"name = '%s'",logical_name);
96 rc = (int) odm_get_first(CuDv_CLASS, sstring, &cudvobj);
99 } else if (rc == -1) {
103 if (cudvobj.status == DEFINED)
104 err_exit(E_OK); /* already unconf'd */
106 /* get device's predefined object */
107 sprintf(sstring,"uniquetype = '%s'", cudvobj.PdDvLn_Lvalue);
108 rc = (int) odm_get_first(PdDv_CLASS, sstring, &pddvobj);
115 * Call sysconfig() to "terminate" the device.
116 * If fails with EBUSY, then device instance is "open",
117 * and device cannot be "unconfigured". Any other errno
118 * returned will be ignored since we MUST unconfigure the
119 * device even if it reports some other error.
122 /* get major number of device */
123 majorno = genmajor(pddvobj.DvDr);
127 /* get minor number */
128 minor_list = getminor(majorno, &how_many, pddvobj.DvDr);
129 if (minor_list == NULL || how_many == 0)
130 err_exit (E_MINORNO);
131 vprintf("how_many=%d\n", how_many);
133 ptr += strlen(pddvobj.prefix);
135 if (unit >= how_many) {
136 err_exit (E_MINORNO);
138 minorno = minor_list[unit];
139 vprintf("unit %d minorno %d\n", unit, minorno);
141 /* create devno for this device */
142 cfg.devno = makedev(majorno, minorno);
144 cfg.ddsptr = (caddr_t) NULL;
145 cfg.ddslen = (int) 0;
147 if (sysconfig(SYS_CFGDD, &cfg, sizeof(struct cfg_dd)) == -1) {
151 cfg.kmid = loadext(pddvobj.DvDr, FALSE, FALSE);
152 if (cfg.kmid == NULL)
153 err_exit(E_UNLOADEXT);
155 /* Change the status field of device to "DEFINED" */
156 cudvobj.status = DEFINED;
157 if (odm_change_obj(CuDv_CLASS, &cudvobj) == -1)
158 err_exit(E_ODMUPDATE);
167 * Overrides for Emacs so that we follow Linus's tabbing style.
168 * Emacs will notice this stuff at the end of the file and automatically
169 * adjust the settings for this buffer only. This must remain at the end
171 * ---------------------------------------------------------------------------
174 * c-brace-imaginary-offset: 0
176 * c-argdecl-indent: 4
178 * c-continued-statement-offset: 4
179 * c-continued-brace-offset: 0