2 * Copyright (c) 1997-1999 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
41 * $Id: wr_fstab.c,v 1.2 1999/01/10 21:54:30 ezk Exp $
47 #endif /* HAVE_CONFIG_H */
52 #define GENERIC_OS_NAME "generic"
54 /* forward definitions */
55 static void write_aix1_dkfstab(FILE *ef, disk_fs *dp);
56 static void write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp);
57 static void write_aix3_dkfstab(FILE *ef, disk_fs *dp);
58 static void write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp);
59 static int write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *));
60 static int write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *));
61 static void write_generic_dkfstab(FILE *ef, disk_fs *dp);
62 static void write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp);
63 static void write_ultrix_dkfstab(FILE *ef, disk_fs *dp);
64 static void write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp);
66 /* ----------------------------------------------- */
68 static struct os_fstab_type {
70 void (*op_fstab) (FILE *ef, disk_fs *dp);
71 void (*op_mount) (FILE *ef, char *hn, fsmount *fp);
75 "aix1", write_aix1_dkfstab, write_aix1_dkrmount
78 "aix3", write_aix3_dkfstab, write_aix3_dkrmount
81 "generic", write_generic_dkfstab, write_generic_dkrmount
84 "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount
87 "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount
90 "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount
98 /* ---------- AIX 1 ------------------------------ */
104 write_aix1_dkfstab(FILE *ef, disk_fs *dp)
106 char *hp = strdup(dp->d_host->h_hostname);
107 char *p = strchr(hp, '.');
112 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",
125 write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp)
127 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
128 char *hp = strdup(h);
129 char *p = strchr(hp, '.');
134 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",
149 /* ---------- AIX 3 ------------------------------ */
155 write_aix3_dkfstab(FILE *ef, disk_fs *dp)
157 if (STREQ(dp->d_fstype, "jfs") &&
158 NSTREQ(dp->d_dev, "/dev/", 5) &&
160 error("aix 3 needs a log device for journalled filesystem (jfs) mounts");
162 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",
174 write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp)
176 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
179 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",
192 /* ---------- Ultrix ----------------------------- */
195 write_ultrix_dkfstab(FILE *ef, disk_fs *dp)
197 fprintf(ef, "%s:%s:%s:%s:%d:%d\n",
208 write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp)
210 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
213 fprintf(ef, "%s@%s:%s:%s:%s:0:0\n",
223 /* ---------- Generic ---------------------------- */
226 * Generic (BSD, SunOS, HPUX) format
229 write_generic_dkfstab(FILE *ef, disk_fs *dp)
231 fprintf(ef, "%s %s %s %s %d %d\n",
242 write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp)
247 h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
249 h = strdup(fp->f_from);
252 fprintf(ef, "%s:%s %s %s %s 0 0\n",
262 static struct os_fstab_type *
263 find_fstab_type(host *hp)
265 struct os_fstab_type *op = 0;
270 if (ISSET(hp->h_mask, HF_OS))
273 os_name = GENERIC_OS_NAME;
275 for (op = os_tabs; op->os_name; op++)
276 if (STREQ(os_name, op->os_name))
279 os_name = GENERIC_OS_NAME;
285 write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *))
291 if (!STREQ(dp->d_fstype, "export"))
299 write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *))
305 (*output) (ef, hn, fp);
312 write_fstab(qelem *q)
319 show_area_being_processed("write fstab", 4);
321 if (hp->h_disk_fs || hp->h_mount) {
322 FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname);
324 struct os_fstab_type *op = find_fstab_type(hp);
325 show_new(hp->h_hostname);
327 errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab);
329 log("No local disk mounts on %s", hp->h_hostname);
332 errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);
337 error("no disk mounts on %s", hp->h_hostname);