wr_fstab.c revision 82794
1/* 2 * Copyright (c) 1997-2001 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. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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. 26 * 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 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 * 41 * $Id: wr_fstab.c,v 1.3.2.1 2001/01/10 03:23:35 ezk Exp $ 42 * 43 */ 44 45#ifdef HAVE_CONFIG_H 46# include <config.h> 47#endif /* HAVE_CONFIG_H */ 48#include <am_defs.h> 49#include <fsi_data.h> 50#include <fsinfo.h> 51 52#define GENERIC_OS_NAME "generic" 53 54/* forward definitions */ 55static void write_aix1_dkfstab(FILE *ef, disk_fs *dp); 56static void write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp); 57static void write_aix3_dkfstab(FILE *ef, disk_fs *dp); 58static void write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp); 59static int write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *)); 60static int write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *)); 61static void write_generic_dkfstab(FILE *ef, disk_fs *dp); 62static void write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp); 63static void write_ultrix_dkfstab(FILE *ef, disk_fs *dp); 64static void write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp); 65 66/* ----------------------------------------------- */ 67 68static struct os_fstab_type { 69 char *os_name; 70 void (*op_fstab) (FILE *ef, disk_fs *dp); 71 void (*op_mount) (FILE *ef, char *hn, fsmount *fp); 72} os_tabs[] = { 73 74 { 75 "aix1", write_aix1_dkfstab, write_aix1_dkrmount 76 }, /* AIX 1 */ 77 { 78 "aix3", write_aix3_dkfstab, write_aix3_dkrmount 79 }, /* AIX 3 */ 80 { 81 "generic", write_generic_dkfstab, write_generic_dkrmount 82 }, /* Generic */ 83 { 84 "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount 85 }, /* Ultrix */ 86 { 87 "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount 88 }, /* Ultrix */ 89 { 90 "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount 91 }, /* Ultrix */ 92 { 93 0, 0, 0 94 } 95}; 96 97 98/* ---------- AIX 1 ------------------------------ */ 99 100/* 101 * AIX 1 format 102 */ 103static void 104write_aix1_dkfstab(FILE *ef, disk_fs *dp) 105{ 106 char *hp = strdup(dp->d_host->h_hostname); 107 char *p = strchr(hp, '.'); 108 109 if (p) 110 *p = '\0'; 111 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", 113 dp->d_mountpt, 114 dp->d_dev, 115 dp->d_fstype, 116 dp->d_fstype, 117 dp->d_log, 118 dp->d_mountpt, 119 dp->d_opts); 120 XFREE(hp); 121} 122 123 124static void 125write_aix1_dkrmount(FILE *ef, char *hn, fsmount *fp) 126{ 127 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 128 char *hp = strdup(h); 129 char *p = strchr(hp, '.'); 130 131 if (p) 132 *p = '\0'; 133 domain_strip(h, hn); 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", 135 fp->f_localname, 136 hp, 137 h, 138 fp->f_volname, 139 fp->f_fstype, 140 fp->f_fstype, 141 fp->f_localname, 142 fp->f_opts); 143 144 XFREE(hp); 145 XFREE(h); 146} 147 148 149/* ---------- AIX 3 ------------------------------ */ 150 151/* 152 * AIX 3 format 153 */ 154static void 155write_aix3_dkfstab(FILE *ef, disk_fs *dp) 156{ 157 if (STREQ(dp->d_fstype, "jfs") && 158 NSTREQ(dp->d_dev, "/dev/", 5) && 159 !dp->d_log) 160 error("aix 3 needs a log device for journalled filesystem (jfs) mounts"); 161 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", 163 dp->d_mountpt, 164 dp->d_dev, 165 dp->d_fstype, 166 dp->d_fstype, 167 dp->d_log, 168 dp->d_mountpt, 169 dp->d_opts); 170} 171 172 173static void 174write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp) 175{ 176 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 177 178 domain_strip(h, hn); 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", 180 fp->f_localname, 181 h, 182 fp->f_volname, 183 fp->f_fstype, 184 fp->f_fstype, 185 fp->f_localname, 186 fp->f_opts); 187 188 XFREE(h); 189} 190 191 192/* ---------- Ultrix ----------------------------- */ 193 194static void 195write_ultrix_dkfstab(FILE *ef, disk_fs *dp) 196{ 197 fprintf(ef, "%s:%s:%s:%s:%d:%d\n", 198 dp->d_dev, 199 dp->d_mountpt, 200 dp->d_fstype, 201 dp->d_opts, 202 dp->d_freq, 203 dp->d_passno); 204} 205 206 207static void 208write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp) 209{ 210 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 211 212 domain_strip(h, hn); 213 fprintf(ef, "%s@%s:%s:%s:%s:0:0\n", 214 fp->f_volname, 215 h, 216 fp->f_localname, 217 fp->f_fstype, 218 fp->f_opts); 219 XFREE(h); 220} 221 222 223/* ---------- Generic ---------------------------- */ 224 225/* 226 * Generic (BSD, SunOS, HPUX) format 227 */ 228static void 229write_generic_dkfstab(FILE *ef, disk_fs *dp) 230{ 231 fprintf(ef, "%s %s %s %s %d %d\n", 232 dp->d_dev, 233 dp->d_mountpt, 234 dp->d_fstype, 235 dp->d_opts, 236 dp->d_freq, 237 dp->d_passno); 238} 239 240 241static void 242write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp) 243{ 244 char *h; 245 246 if (fp->f_ref) { 247 h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 248 } else { 249 h = strdup(fp->f_from); 250 } 251 domain_strip(h, hn); 252 fprintf(ef, "%s:%s %s %s %s 0 0\n", 253 h, 254 fp->f_volname, 255 fp->f_localname, 256 fp->f_fstype, 257 fp->f_opts); 258 XFREE(h); 259} 260 261 262static struct os_fstab_type * 263find_fstab_type(host *hp) 264{ 265 struct os_fstab_type *op = 0; 266 char *os_name = 0; 267 268again:; 269 if (os_name == 0) { 270 if (ISSET(hp->h_mask, HF_OS)) 271 os_name = hp->h_os; 272 else 273 os_name = GENERIC_OS_NAME; 274 } 275 for (op = os_tabs; op->os_name; op++) 276 if (STREQ(os_name, op->os_name)) 277 return op; 278 279 os_name = GENERIC_OS_NAME; 280 goto again; 281} 282 283 284static int 285write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *)) 286{ 287 int errors = 0; 288 disk_fs *dp; 289 290 ITER(dp, disk_fs, q) 291 if (!STREQ(dp->d_fstype, "export")) 292 (*output) (ef, dp); 293 294 return errors; 295} 296 297 298static int 299write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *)) 300{ 301 int errors = 0; 302 fsmount *fp; 303 304 ITER(fp, fsmount, q) 305 (*output) (ef, hn, fp); 306 307 return errors; 308} 309 310 311int 312write_fstab(qelem *q) 313{ 314 int errors = 0; 315 316 if (fstab_pref) { 317 host *hp; 318 319 show_area_being_processed("write fstab", 4); 320 ITER(hp, host, q) { 321 if (hp->h_disk_fs || hp->h_mount) { 322 FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname); 323 if (ef) { 324 struct os_fstab_type *op = find_fstab_type(hp); 325 show_new(hp->h_hostname); 326 if (hp->h_disk_fs) 327 errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab); 328 else 329 log("No local disk mounts on %s", hp->h_hostname); 330 331 if (hp->h_mount) 332 errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount); 333 334 pref_close(ef); 335 } 336 } else { 337 error("no disk mounts on %s", hp->h_hostname); 338 } 339 } 340 } 341 return errors; 342} 343