2 * Copyright (c) 1997-2014 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. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * File: am-utils/fsinfo/wr_fstab.c
42 #endif /* HAVE_CONFIG_H */
47 #define GENERIC_OS_NAME "generic"
49 /* forward definitions */
50 static void write_aix1_dkfstab(FILE *ef, disk_fs *dp);
51 static void write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp);
52 static void write_aix3_dkfstab(FILE *ef, disk_fs *dp);
53 static void write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp);
54 static int write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *));
55 static int write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *));
56 static void write_generic_dkfstab(FILE *ef, disk_fs *dp);
57 static void write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp);
58 static void write_ultrix_dkfstab(FILE *ef, disk_fs *dp);
59 static void write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp);
61 /* ----------------------------------------------- */
63 static struct os_fstab_type {
65 void (*op_fstab) (FILE *ef, disk_fs *dp);
66 void (*op_mount) (FILE *ef, char *hn, fsmount *fp);
70 "aix1", write_aix1_dkfstab, write_aix1_dkrmount
73 "aix3", write_aix3_dkfstab, write_aix3_dkrmount
76 "generic", write_generic_dkfstab, write_generic_dkrmount
79 "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount
82 "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount
85 "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount
93 /* ---------- AIX 1 ------------------------------ */
99 write_aix1_dkfstab(FILE *ef, disk_fs *dp)
101 char *hp = xstrdup(dp->d_host->h_hostname);
102 char *p = strchr(hp, '.');
107 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",
120 write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp)
122 char *h = xstrdup(fp->f_ref->m_dk->d_host->h_hostname);
123 char *hp = xstrdup(h);
124 char *p = strchr(hp, '.');
129 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",
144 /* ---------- AIX 3 ------------------------------ */
150 write_aix3_dkfstab(FILE *ef, disk_fs *dp)
152 if (STREQ(dp->d_fstype, "jfs") &&
153 NSTREQ(dp->d_dev, "/dev/", 5) &&
155 error("aix 3 needs a log device for journalled filesystem (jfs) mounts");
157 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",
169 write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp)
171 char *h = xstrdup(fp->f_ref->m_dk->d_host->h_hostname);
174 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",
187 /* ---------- Ultrix ----------------------------- */
190 write_ultrix_dkfstab(FILE *ef, disk_fs *dp)
192 fprintf(ef, "%s:%s:%s:%s:%d:%d\n",
203 write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp)
205 char *h = xstrdup(fp->f_ref->m_dk->d_host->h_hostname);
208 fprintf(ef, "%s@%s:%s:%s:%s:0:0\n",
218 /* ---------- Generic ---------------------------- */
221 * Generic (BSD, SunOS, HPUX) format
224 write_generic_dkfstab(FILE *ef, disk_fs *dp)
226 fprintf(ef, "%s %s %s %s %d %d\n",
237 write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp)
242 h = xstrdup(fp->f_ref->m_dk->d_host->h_hostname);
244 h = xstrdup(fp->f_from);
247 fprintf(ef, "%s:%s %s %s %s 0 0\n",
257 static struct os_fstab_type *
258 find_fstab_type(host *hp)
260 struct os_fstab_type *op = NULL;
261 char *os_name = NULL;
265 if (ISSET(hp->h_mask, HF_OS))
268 os_name = GENERIC_OS_NAME;
270 for (op = os_tabs; op->os_name; op++)
271 if (STREQ(os_name, op->os_name))
274 os_name = GENERIC_OS_NAME;
280 write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *))
286 if (!STREQ(dp->d_fstype, "export"))
294 write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *))
300 (*output) (ef, hn, fp);
307 write_fstab(qelem *q)
314 show_area_being_processed("write fstab", 4);
316 if (hp->h_disk_fs || hp->h_mount) {
317 FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname);
319 struct os_fstab_type *op = find_fstab_type(hp);
320 show_new(hp->h_hostname);
322 errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab);
324 fsi_log("No local disk mounts on %s", hp->h_hostname);
327 errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);
332 error("no disk mounts on %s", hp->h_hostname);