2 * Copyright (c) 1997-2006 Erez Zadok
3 * Copyright (c) 1989 Jan-Simon Pendry
4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1989 The Regents of the University of California.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgment:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * File: am-utils/fsinfo/fsi_util.c
43 #endif /* HAVE_CONFIG_H */
48 /* static variables */
49 static int show_range = 10;
51 static int total_shown = 0;
52 static int total_mmm = 8;
73 if (total_mmm != -show_range + 1) {
79 xsnprintf(n, sizeof(n), "%d", total_shown);
85 total_mmm = -show_range;
107 * Lots of ways of reporting errors...
110 error(char *fmt, ...)
116 fprintf(stderr, "%s: Error, ", progname);
117 vfprintf(stderr, fmt, ap);
125 lerror(ioloc *l, char *fmt, ...)
131 fprintf(stderr, "%s:%d: ", l->i_file, l->i_line);
132 vfprintf(stderr, fmt, ap);
140 lwarning(ioloc *l, char *fmt, ...)
146 fprintf(stderr, "%s:%d: ", l->i_file, l->i_line);
147 vfprintf(stderr, fmt, ap);
154 fatal(char *fmt, ...)
160 fprintf(stderr, "%s: Fatal, ", progname);
161 vfprintf(stderr, fmt, ap);
172 fsi_log(char *fmt, ...)
179 fprintf(stdout, "%s: ", progname);
180 vfprintf(stdout, fmt, ap);
188 info_hdr(FILE *ef, char *info)
190 fprintf(ef, "# *** NOTE: This file contains %s info\n", info);
195 gen_hdr(FILE *ef, char *hn)
197 fprintf(ef, "# *** NOTE: Only for use on %s\n", hn);
202 make_banner(FILE *fp)
204 time_t t = time((time_t *) 0);
205 char *cp = ctime(&t);
209 # *** This file was automatically generated -- DO NOT EDIT HERE ***\n\
210 # \"%s\" run by %s@%s on %s\
213 progname, username, hostname, cp);
224 if (total_mmm > show_range) {
226 } else if (total_mmm == 0) {
236 show_area_being_processed(char *area, int n)
238 static char *last_area = 0;
249 if (!last_area || !STREQ(area, last_area)) {
253 total_mmm = show_range + 1;
255 (void) col_output(strlen(area) + 2);
256 fprintf(stdout, "[%s", area);
270 * Open a file with the given prefix and name
273 pref_open(char *pref, char *hn, void (*hdr) (FILE *, char *), char *arg)
278 xsnprintf(p, sizeof(p), "%s%s", pref, hn);
279 fsi_log("Writing %s info for %s to %s", pref, hn, p);
285 error("can't open %s for writing", p);
295 return fclose(fp) == 0;
300 * Determine where Amd would automount the host/volname pair
303 compute_automount_point(char *buf, size_t l, host *hp, char *vn)
305 xsnprintf(buf, l, "%s/%s%s", autodir, hp->h_lochost, vn);
310 * Data constructors..
313 new_automount(char *name)
315 automount *ap = CALLOC(struct automount);
317 ap->a_ioloc = current_location();
322 show_new("automount");
328 new_auto_tree(char *def, qelem *ap)
330 auto_tree *tp = CALLOC(struct auto_tree);
332 tp->t_ioloc = current_location();
333 tp->t_defaults = def;
335 show_new("auto_tree");
343 host *hp = CALLOC(struct host);
345 hp->h_ioloc = current_location();
353 set_host(host *hp, int k, char *v)
357 if (hp->h_mask & m) {
358 yyerror("host field \"%s\" already set", host_strings[k]);
367 dict_ent *de = dict_locate(dict_of_hosts, v);
370 yyerror("duplicate host %s!", v);
372 dict_add(dict_of_hosts, v, (char *) hp);
374 domain_strip(p, hostname);
375 if (strchr(p, '.') != 0)
384 qelem *vq = (qelem *) v;
390 q = hp->h_config = new_que();
391 ins_que(vq, q->q_back);
397 qelem *vq = (qelem *) v;
403 q = hp->h_ether = new_que();
404 ins_que(vq, q->q_back);
430 ether_if *ep = CALLOC(struct ether_if);
433 ep->e_ioloc = current_location();
434 show_new("ether_if");
440 set_ether_if(ether_if *ep, int k, char *v)
444 if (ep->e_mask & m) {
445 yyerror("netif field \"%s\" already set", ether_if_strings[k]);
453 ep->e_inaddr.s_addr = inet_addr(v);
454 if ((int) ep->e_inaddr.s_addr == (int) INADDR_NONE)
455 yyerror("malformed IP dotted quad: %s", v);
463 if ((sscanf(v, "0x%lx", &nm) == 1 || sscanf(v, "%lx", &nm) == 1) && nm != 0)
464 ep->e_netmask = htonl(nm);
466 yyerror("malformed netmask: %s", v);
483 set_disk_fs(disk_fs *dp, int k, char *v)
487 if (dp->d_mask & m) {
488 yyerror("fs field \"%s\" already set", disk_fs_strings[k]);
512 dp->d_passno = atoi(v);
517 dp->d_freq = atoi(v);
522 dp->d_mount = &((fsi_mount *) v)->m_q;
535 disk_fs *dp = CALLOC(struct disk_fs);
537 dp->d_ioloc = current_location();
544 set_mount(fsi_mount *mp, int k, char *v)
548 if (mp->m_mask & m) {
549 yyerror("mount tree field \"%s\" already set", mount_strings[k]);
557 dict_add(dict_of_volnames, v, (char *) mp);
579 fsi_mount *fp = CALLOC(struct fsi_mount);
581 fp->m_ioloc = current_location();
588 set_fsmount(fsmount *fp, int k, char *v)
592 if (fp->f_mask & m) {
593 yyerror("mount field \"%s\" already set", fsmount_strings[k]);
633 fsmount *fp = CALLOC(struct fsmount);
635 fp->f_ioloc = current_location();
644 q->q_forw = q->q_back = q;
651 qelem *q = CALLOC(qelem);
659 ins_que(qelem *elem, qelem *pred)