4 * Copyright (c) 1997-2009 Erez Zadok
5 * Copyright (c) 1989 Jan-Simon Pendry
6 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1989 The Regents of the University of California.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgment:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * File: am-utils/fsinfo/fsi_util.c
45 #endif /* HAVE_CONFIG_H */
50 /* static variables */
51 static int show_range
= 10;
53 static int total_shown
= 0;
54 static int total_mmm
= 8;
75 if (total_mmm
!= -show_range
+ 1) {
81 xsnprintf(n
, sizeof(n
), "%d", total_shown
);
87 total_mmm
= -show_range
;
109 * Lots of ways of reporting errors...
112 error(char *fmt
, ...)
118 fprintf(stderr
, "%s: Error, ", progname
);
119 vfprintf(stderr
, fmt
, ap
);
127 lerror(ioloc
*l
, char *fmt
, ...)
133 fprintf(stderr
, "%s:%d: ", l
->i_file
, l
->i_line
);
134 vfprintf(stderr
, fmt
, ap
);
142 lwarning(ioloc
*l
, char *fmt
, ...)
148 fprintf(stderr
, "%s:%d: ", l
->i_file
, l
->i_line
);
149 vfprintf(stderr
, fmt
, ap
);
156 fatal(char *fmt
, ...)
162 fprintf(stderr
, "%s: Fatal, ", progname
);
163 vfprintf(stderr
, fmt
, ap
);
174 fsi_log(char *fmt
, ...)
181 fprintf(stdout
, "%s: ", progname
);
182 vfprintf(stdout
, fmt
, ap
);
190 info_hdr(FILE *ef
, char *info
)
192 fprintf(ef
, "# *** NOTE: This file contains %s info\n", info
);
197 gen_hdr(FILE *ef
, char *hn
)
199 fprintf(ef
, "# *** NOTE: Only for use on %s\n", hn
);
204 make_banner(FILE *fp
)
206 time_t t
= time((time_t *) NULL
);
207 char *cp
= ctime(&t
);
211 # *** This file was automatically generated -- DO NOT EDIT HERE ***\n\
212 # \"%s\" run by %s@%s on %s\
215 progname
, username
, hostname
, cp
);
226 if (total_mmm
> show_range
) {
228 } else if (total_mmm
== 0) {
238 show_area_being_processed(char *area
, int n
)
240 static char *last_area
= NULL
;
251 if (!last_area
|| !STREQ(area
, last_area
)) {
255 total_mmm
= show_range
+ 1;
257 (void) col_output(strlen(area
) + 2);
258 fprintf(stdout
, "[%s", area
);
272 * Open a file with the given prefix and name
275 pref_open(char *pref
, char *hn
, void (*hdr
) (FILE *, char *), char *arg
)
280 xsnprintf(p
, sizeof(p
), "%s%s", pref
, hn
);
281 fsi_log("Writing %s info for %s to %s", pref
, hn
, p
);
287 error("can't open %s for writing", p
);
297 return fclose(fp
) == 0;
302 * Determine where Amd would automount the host/volname pair
305 compute_automount_point(char *buf
, size_t l
, host
*hp
, char *vn
)
307 xsnprintf(buf
, l
, "%s/%s%s", autodir
, hp
->h_lochost
, vn
);
312 * Data constructors..
315 new_automount(char *name
)
317 automount
*ap
= CALLOC(struct automount
);
319 ap
->a_ioloc
= current_location();
321 ap
->a_volname
= NULL
;
324 show_new("automount");
330 new_auto_tree(char *def
, qelem
*ap
)
332 auto_tree
*tp
= CALLOC(struct auto_tree
);
334 tp
->t_ioloc
= current_location();
335 tp
->t_defaults
= def
;
337 show_new("auto_tree");
345 host
*hp
= CALLOC(struct host
);
347 hp
->h_ioloc
= current_location();
355 set_host(host
*hp
, int k
, char *v
)
359 if (hp
->h_mask
& m
) {
360 fsi_yyerror("host field \"%s\" already set", host_strings
[k
]);
369 dict_ent
*de
= dict_locate(dict_of_hosts
, v
);
372 fsi_yyerror("duplicate host %s!", v
);
374 dict_add(dict_of_hosts
, v
, (char *) hp
);
376 domain_strip(p
, hostname
);
377 if (strchr(p
, '.') != 0)
386 qelem
*vq
= (qelem
*) v
;
392 q
= hp
->h_config
= new_que();
393 ins_que(vq
, q
->q_back
);
399 qelem
*vq
= (qelem
*) v
;
405 q
= hp
->h_ether
= new_que();
406 ins_que(vq
, q
->q_back
);
432 ether_if
*ep
= CALLOC(struct ether_if
);
435 ep
->e_ioloc
= current_location();
436 show_new("ether_if");
442 set_ether_if(ether_if
*ep
, int k
, char *v
)
446 if (ep
->e_mask
& m
) {
447 fsi_yyerror("netif field \"%s\" already set", ether_if_strings
[k
]);
455 ep
->e_inaddr
.s_addr
= inet_addr(v
);
456 if ((int) ep
->e_inaddr
.s_addr
== (int) INADDR_NONE
)
457 fsi_yyerror("malformed IP dotted quad: %s", v
);
465 if ((sscanf(v
, "0x%lx", &nm
) == 1 || sscanf(v
, "%lx", &nm
) == 1) && nm
!= 0)
466 ep
->e_netmask
= htonl(nm
);
468 fsi_yyerror("malformed netmask: %s", v
);
485 set_disk_fs(disk_fs
*dp
, int k
, char *v
)
489 if (dp
->d_mask
& m
) {
490 fsi_yyerror("fs field \"%s\" already set", disk_fs_strings
[k
]);
514 dp
->d_passno
= atoi(v
);
519 dp
->d_freq
= atoi(v
);
524 dp
->d_mount
= &((fsi_mount
*) v
)->m_q
;
537 disk_fs
*dp
= CALLOC(struct disk_fs
);
539 dp
->d_ioloc
= current_location();
546 set_mount(fsi_mount
*mp
, int k
, char *v
)
550 if (mp
->m_mask
& m
) {
551 fsi_yyerror("mount tree field \"%s\" already set", mount_strings
[k
]);
559 dict_add(dict_of_volnames
, v
, (char *) mp
);
581 fsi_mount
*fp
= CALLOC(struct fsi_mount
);
583 fp
->m_ioloc
= current_location();
590 set_fsmount(fsmount
*fp
, int k
, char *v
)
594 if (fp
->f_mask
& m
) {
595 fsi_yyerror("mount field \"%s\" already set", fsmount_strings
[k
]);
635 fsmount
*fp
= CALLOC(struct fsmount
);
637 fp
->f_ioloc
= current_location();
646 q
->q_forw
= q
->q_back
= q
;
653 qelem
*q
= CALLOC(qelem
);
661 ins_que(qelem
*elem
, qelem
*pred
)