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 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgment:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * File: am-utils/fsinfo/fsinfo.c
50 #endif /* HAVE_CONFIG_H */
60 char hostname[MAXHOSTNAMELEN + 1];
64 dict *dict_of_volnames;
69 qelem *list_of_automounts;
73 * Output file prefixes
75 char *bootparams_pref;
83 * Argument cracking...
86 fsi_get_args(int c, char *v[])
93 * Determine program name
96 progname = strrchr(v[0], '/');
97 if (progname && progname[1])
106 while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1)
116 fatal("-b option specified twice");
117 bootparams_pref = optarg;
122 fatal("-d option specified twice");
123 dumpset_pref = optarg;
127 xstrlcpy(hostname, optarg, sizeof(hostname));
132 fatal("-e option specified twice");
133 exportfs_pref = optarg;
138 fatal("-f option specified twice");
144 fatal("-m option specified twice");
159 /* sizeof(iptr) is actually that of idvbuf. See declaration above */
160 xsnprintf(iptr, sizeof(idvbuf), "-%c%s ", ch, optarg);
161 iptr += strlen(iptr);
170 g_argv = v + optind - 1;
174 fatal("Cannot read any input files");
182 Usage: %s [-v] [-a autodir] [-h hostname] [-b bootparams] [-d dumpsets]\n\
183 \t[-e exports] [-f fstabs] [-m automounts]\n\
184 \t[-I dir] [-D|-U string[=string]] config ...\n", progname);
189 fsi_log("g_argv[0] = %s", g_argv[0]);
191 fsi_log("g_argv[0] = (nil)");
196 * Determine username of caller
201 const char *u = getlogin();
204 struct passwd *pw = getpwuid(getuid());
212 u = getenv("LOGNAME");
224 main(int argc, char *argv[])
229 fsi_get_args(argc, argv);
232 * If no hostname given then use the local name
234 if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) {
235 perror("gethostname");
238 hostname[sizeof(hostname) - 1] = '\0';
243 username = find_username();
246 * New hosts and automounts
248 list_of_hosts = new_que();
249 list_of_automounts = new_que();
254 dict_of_volnames = new_dict();
255 dict_of_hosts = new_dict();
260 show_area_being_processed("read config", 11);
263 errors += file_io_errors + parse_errors;
267 * Do semantic analysis of input
269 analyze_hosts(list_of_hosts);
270 analyze_automounts(list_of_automounts);
281 write_atab(list_of_automounts);
282 write_bootparams(list_of_hosts);
283 write_dumpset(list_of_hosts);
284 write_exportfs(list_of_hosts);
285 write_fstab(list_of_hosts);
290 return errors; /* should never reach here */