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/wr_fstab.c
46 #endif /* HAVE_CONFIG_H */
51 #define GENERIC_OS_NAME "generic"
53 /* forward definitions */
54 static void write_aix1_dkfstab(FILE *ef, disk_fs *dp);
55 static void write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp);
56 static void write_aix3_dkfstab(FILE *ef, disk_fs *dp);
57 static void write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp);
58 static int write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *));
59 static int write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *));
60 static void write_generic_dkfstab(FILE *ef, disk_fs *dp);
61 static void write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp);
62 static void write_ultrix_dkfstab(FILE *ef, disk_fs *dp);
63 static void write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp);
65 /* ----------------------------------------------- */
67 static struct os_fstab_type {
69 void (*op_fstab) (FILE *ef, disk_fs *dp);
70 void (*op_mount) (FILE *ef, char *hn, fsmount *fp);
74 "aix1", write_aix1_dkfstab, write_aix1_dkrmount
77 "aix3", write_aix3_dkfstab, write_aix3_dkrmount
80 "generic", write_generic_dkfstab, write_generic_dkrmount
83 "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount
86 "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount
89 "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount
97 /* ---------- AIX 1 ------------------------------ */
103 write_aix1_dkfstab(FILE *ef, disk_fs *dp)
105 char *hp = strdup(dp->d_host->h_hostname);
106 char *p = strchr(hp, '.');
111 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",
124 write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp)
126 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
127 char *hp = strdup(h);
128 char *p = strchr(hp, '.');
133 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",
148 /* ---------- AIX 3 ------------------------------ */
154 write_aix3_dkfstab(FILE *ef, disk_fs *dp)
156 if (STREQ(dp->d_fstype, "jfs") &&
157 NSTREQ(dp->d_dev, "/dev/", 5) &&
159 error("aix 3 needs a log device for journalled filesystem (jfs) mounts");
161 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",
173 write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp)
175 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
178 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",
191 /* ---------- Ultrix ----------------------------- */
194 write_ultrix_dkfstab(FILE *ef, disk_fs *dp)
196 fprintf(ef, "%s:%s:%s:%s:%d:%d\n",
207 write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp)
209 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
212 fprintf(ef, "%s@%s:%s:%s:%s:0:0\n",
222 /* ---------- Generic ---------------------------- */
225 * Generic (BSD, SunOS, HPUX) format
228 write_generic_dkfstab(FILE *ef, disk_fs *dp)
230 fprintf(ef, "%s %s %s %s %d %d\n",
241 write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp)
246 h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
248 h = strdup(fp->f_from);
251 fprintf(ef, "%s:%s %s %s %s 0 0\n",
261 static struct os_fstab_type *
262 find_fstab_type(host *hp)
264 struct os_fstab_type *op = 0;
269 if (ISSET(hp->h_mask, HF_OS))
272 os_name = GENERIC_OS_NAME;
274 for (op = os_tabs; op->os_name; op++)
275 if (STREQ(os_name, op->os_name))
278 os_name = GENERIC_OS_NAME;
284 write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *))
290 if (!STREQ(dp->d_fstype, "export"))
298 write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *))
304 (*output) (ef, hn, fp);
311 write_fstab(qelem *q)
318 show_area_being_processed("write fstab", 4);
320 if (hp->h_disk_fs || hp->h_mount) {
321 FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname);
323 struct os_fstab_type *op = find_fstab_type(hp);
324 show_new(hp->h_hostname);
326 errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab);
328 fsi_log("No local disk mounts on %s", hp->h_hostname);
331 errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);
336 error("no disk mounts on %s", hp->h_hostname);