Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / am-utils / dist / fsinfo / wr_fstab.c
blob0911e85a8b2c16b352adf282309886ae25f37c68
1 /* $NetBSD$ */
3 /*
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.
8 * All rights reserved.
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgment:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
42 * File: am-utils/fsinfo/wr_fstab.c
46 #ifdef HAVE_CONFIG_H
47 # include <config.h>
48 #endif /* HAVE_CONFIG_H */
49 #include <am_defs.h>
50 #include <fsi_data.h>
51 #include <fsinfo.h>
53 #define GENERIC_OS_NAME "generic"
55 /* forward definitions */
56 static void write_aix1_dkfstab(FILE *ef, disk_fs *dp);
57 static void write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp);
58 static void write_aix3_dkfstab(FILE *ef, disk_fs *dp);
59 static void write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp);
60 static int write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *));
61 static int write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *));
62 static void write_generic_dkfstab(FILE *ef, disk_fs *dp);
63 static void write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp);
64 static void write_ultrix_dkfstab(FILE *ef, disk_fs *dp);
65 static void write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp);
67 /* ----------------------------------------------- */
69 static struct os_fstab_type {
70 char *os_name;
71 void (*op_fstab) (FILE *ef, disk_fs *dp);
72 void (*op_mount) (FILE *ef, char *hn, fsmount *fp);
73 } os_tabs[] = {
76 "aix1", write_aix1_dkfstab, write_aix1_dkrmount
77 }, /* AIX 1 */
79 "aix3", write_aix3_dkfstab, write_aix3_dkrmount
80 }, /* AIX 3 */
82 "generic", write_generic_dkfstab, write_generic_dkrmount
83 }, /* Generic */
85 "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount
86 }, /* Ultrix */
88 "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount
89 }, /* Ultrix */
91 "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount
92 }, /* Ultrix */
94 NULL, NULL, NULL
99 /* ---------- AIX 1 ------------------------------ */
102 * AIX 1 format
104 static void
105 write_aix1_dkfstab(FILE *ef, disk_fs *dp)
107 char *hp = strdup(dp->d_host->h_hostname);
108 char *p = strchr(hp, '.');
110 if (p)
111 *p = '\0';
113 fprintf(ef, "\n%s:\n\tdev = %s\n\tvfs = %s\n\ttype = %s\n\tlog = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
114 dp->d_mountpt,
115 dp->d_dev,
116 dp->d_fstype,
117 dp->d_fstype,
118 dp->d_log,
119 dp->d_mountpt,
120 dp->d_opts);
121 XFREE(hp);
125 static void
126 write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp)
128 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
129 char *hp = strdup(h);
130 char *p = strchr(hp, '.');
132 if (p)
133 *p = '\0';
134 domain_strip(h, hn);
135 fprintf(ef, "\n%s:\n\tsite = %s\n\tdev = %s:%s\n\tvfs = %s\n\ttype = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
136 fp->f_localname,
139 fp->f_volname,
140 fp->f_fstype,
141 fp->f_fstype,
142 fp->f_localname,
143 fp->f_opts);
145 XFREE(hp);
146 XFREE(h);
150 /* ---------- AIX 3 ------------------------------ */
153 * AIX 3 format
155 static void
156 write_aix3_dkfstab(FILE *ef, disk_fs *dp)
158 if (STREQ(dp->d_fstype, "jfs") &&
159 NSTREQ(dp->d_dev, "/dev/", 5) &&
160 !dp->d_log)
161 error("aix 3 needs a log device for journalled filesystem (jfs) mounts");
163 fprintf(ef, "\n%s:\n\tdev = %s\n\tvfs = %s\n\ttype = %s\n\tlog = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
164 dp->d_mountpt,
165 dp->d_dev,
166 dp->d_fstype,
167 dp->d_fstype,
168 dp->d_log,
169 dp->d_mountpt,
170 dp->d_opts);
174 static void
175 write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp)
177 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
179 domain_strip(h, hn);
180 fprintf(ef, "\n%s:\n\tdev = %s:%s\n\tvfs = %s\n\ttype = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
181 fp->f_localname,
183 fp->f_volname,
184 fp->f_fstype,
185 fp->f_fstype,
186 fp->f_localname,
187 fp->f_opts);
189 XFREE(h);
193 /* ---------- Ultrix ----------------------------- */
195 static void
196 write_ultrix_dkfstab(FILE *ef, disk_fs *dp)
198 fprintf(ef, "%s:%s:%s:%s:%d:%d\n",
199 dp->d_dev,
200 dp->d_mountpt,
201 dp->d_fstype,
202 dp->d_opts,
203 dp->d_freq,
204 dp->d_passno);
208 static void
209 write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp)
211 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
213 domain_strip(h, hn);
214 fprintf(ef, "%s@%s:%s:%s:%s:0:0\n",
215 fp->f_volname,
217 fp->f_localname,
218 fp->f_fstype,
219 fp->f_opts);
220 XFREE(h);
224 /* ---------- Generic ---------------------------- */
227 * Generic (BSD, SunOS, HPUX) format
229 static void
230 write_generic_dkfstab(FILE *ef, disk_fs *dp)
232 fprintf(ef, "%s %s %s %s %d %d\n",
233 dp->d_dev,
234 dp->d_mountpt,
235 dp->d_fstype,
236 dp->d_opts,
237 dp->d_freq,
238 dp->d_passno);
242 static void
243 write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp)
245 char *h;
247 if (fp->f_ref) {
248 h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
249 } else {
250 h = strdup(fp->f_from);
252 domain_strip(h, hn);
253 fprintf(ef, "%s:%s %s %s %s 0 0\n",
255 fp->f_volname,
256 fp->f_localname,
257 fp->f_fstype,
258 fp->f_opts);
259 XFREE(h);
263 static struct os_fstab_type *
264 find_fstab_type(host *hp)
266 struct os_fstab_type *op = NULL;
267 char *os_name = NULL;
269 again:;
270 if (os_name == 0) {
271 if (ISSET(hp->h_mask, HF_OS))
272 os_name = hp->h_os;
273 else
274 os_name = GENERIC_OS_NAME;
276 for (op = os_tabs; op->os_name; op++)
277 if (STREQ(os_name, op->os_name))
278 return op;
280 os_name = GENERIC_OS_NAME;
281 goto again;
285 static int
286 write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *))
288 int errors = 0;
289 disk_fs *dp;
291 ITER(dp, disk_fs, q)
292 if (!STREQ(dp->d_fstype, "export"))
293 (*output) (ef, dp);
295 return errors;
299 static int
300 write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *))
302 int errors = 0;
303 fsmount *fp;
305 ITER(fp, fsmount, q)
306 (*output) (ef, hn, fp);
308 return errors;
313 write_fstab(qelem *q)
315 int errors = 0;
317 if (fstab_pref) {
318 host *hp;
320 show_area_being_processed("write fstab", 4);
321 ITER(hp, host, q) {
322 if (hp->h_disk_fs || hp->h_mount) {
323 FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname);
324 if (ef) {
325 struct os_fstab_type *op = find_fstab_type(hp);
326 show_new(hp->h_hostname);
327 if (hp->h_disk_fs)
328 errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab);
329 else
330 fsi_log("No local disk mounts on %s", hp->h_hostname);
332 if (hp->h_mount)
333 errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);
335 pref_close(ef);
337 } else {
338 error("no disk mounts on %s", hp->h_hostname);
342 return errors;