1 /* 2 * Copyright (c) 1989 Jan-Simon Pendry 3 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 4 * Copyright (c) 1989 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Jan-Simon Pendry at Imperial College, London. 9 * 10 * %sccs.include.redist.c% 11 * 12 * @(#)wr_fstab.c 5.3 (Berkeley) 05/12/91 13 * 14 * $Id: wr_fstab.c,v 5.2.1.3 91/05/07 22:19:14 jsp Alpha $ 15 * 16 */ 17 18 #include "../fsinfo/fsinfo.h" 19 20 /* ---------- AIX 1 ------------------------------ */ 21 22 /* 23 * AIX 1 format 24 */ 25 static void write_aix1_dkfstab(ef, dp) 26 FILE *ef; 27 disk_fs *dp; 28 { 29 char *hp = strdup(dp->d_host->h_hostname); 30 char *p = strchr(hp, '.'); 31 if (p) 32 *p = '\0'; 33 34 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", 35 dp->d_mountpt, 36 dp->d_dev, 37 dp->d_fstype, 38 dp->d_fstype, 39 dp->d_log, 40 dp->d_mountpt, 41 dp->d_opts); 42 free(hp); 43 } 44 45 static void write_aix1_dkrmount(ef, hn, fp) 46 FILE *ef; 47 char *hn; 48 fsmount *fp; 49 { 50 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 51 char *hp = strdup(h); 52 char *p = strchr(hp, '.'); 53 if (p) 54 *p = '\0'; 55 domain_strip(h, hn); 56 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", 57 fp->f_localname, 58 hp, 59 h, 60 fp->f_volname, 61 fp->f_fstype, 62 fp->f_fstype, 63 fp->f_localname, 64 fp->f_opts); 65 66 free(hp); 67 free(h); 68 } 69 70 /* ---------- AIX 3 ------------------------------ */ 71 72 /* 73 * AIX 3 format 74 */ 75 static void write_aix3_dkfstab(ef, dp) 76 FILE *ef; 77 disk_fs *dp; 78 { 79 if (strcmp(dp->d_fstype, "jfs") == 0 && strncmp(dp->d_dev, "/dev/", 5) == 0 && !dp->d_log) 80 error("aix 3 needs a log device for journalled filesystem (jfs) mounts"); 81 82 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", 83 dp->d_mountpt, 84 dp->d_dev, 85 dp->d_fstype, 86 dp->d_fstype, 87 dp->d_log, 88 dp->d_mountpt, 89 dp->d_opts); 90 } 91 92 static void write_aix3_dkrmount(ef, hn, fp) 93 FILE *ef; 94 char *hn; 95 fsmount *fp; 96 { 97 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 98 domain_strip(h, hn); 99 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", 100 fp->f_localname, 101 h, 102 fp->f_volname, 103 fp->f_fstype, 104 fp->f_fstype, 105 fp->f_localname, 106 fp->f_opts); 107 108 free(h); 109 } 110 111 /* ---------- Ultrix ----------------------------- */ 112 113 static void write_ultrix_dkfstab(ef, dp) 114 FILE *ef; 115 disk_fs *dp; 116 { 117 fprintf(ef, "%s:%s:%s:%s:%d:%d\n", 118 dp->d_dev, 119 dp->d_mountpt, 120 dp->d_fstype, 121 dp->d_opts, 122 dp->d_freq, 123 dp->d_passno); 124 } 125 126 static void write_ultrix_dkrmount(ef, hn, fp) 127 FILE *ef; 128 char *hn; 129 fsmount *fp; 130 { 131 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 132 domain_strip(h, hn); 133 fprintf(ef, "%s@%s:%s:%s:%s:0:0\n", 134 fp->f_volname, 135 h, 136 fp->f_localname, 137 fp->f_fstype, 138 fp->f_opts); 139 free(h); 140 } 141 142 /* ---------- Generic ---------------------------- */ 143 144 /* 145 * Generic (BSD, SunOS, HPUX) format 146 */ 147 static void write_generic_dkfstab(ef, dp) 148 FILE *ef; 149 disk_fs *dp; 150 { 151 fprintf(ef, "%s %s %s %s %d %d\n", 152 dp->d_dev, 153 dp->d_mountpt, 154 dp->d_fstype, 155 dp->d_opts, 156 dp->d_freq, 157 dp->d_passno); 158 } 159 160 static void write_generic_dkrmount(ef, hn, fp) 161 FILE *ef; 162 char *hn; 163 fsmount *fp; 164 { 165 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 166 domain_strip(h, hn); 167 fprintf(ef, "%s:%s %s %s %s 0 0\n", 168 h, 169 fp->f_volname, 170 fp->f_localname, 171 fp->f_fstype, 172 fp->f_opts); 173 free(h); 174 } 175 176 /* ----------------------------------------------- */ 177 178 static struct os_fstab_type { 179 char *os_name; 180 void (*op_fstab)(); 181 void (*op_mount)(); 182 } os_tabs[] = { 183 { "aix1", write_aix1_dkfstab, write_aix1_dkrmount }, /* AIX 1 */ 184 { "aix3", write_aix3_dkfstab, write_aix3_dkrmount }, /* AIX 3 */ 185 { "generic", write_generic_dkfstab, write_generic_dkrmount }, /* Generic */ 186 { "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount }, /* Ultrix */ 187 { "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount }, /* Ultrix */ 188 { "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount }, /* Ultrix */ 189 { 0, 0, 0 } 190 }; 191 192 #define GENERIC_OS_NAME "generic" 193 194 static struct os_fstab_type *find_fstab_type(hp) 195 host *hp; 196 { 197 struct os_fstab_type *op = 0; 198 char *os_name = 0; 199 200 again:; 201 if (os_name == 0) { 202 if (ISSET(hp->h_mask, HF_OS)) 203 os_name = hp->h_os; 204 else 205 os_name = GENERIC_OS_NAME; 206 } 207 208 for (op = os_tabs; op->os_name; op++) 209 if (strcmp(os_name, op->os_name) == 0) 210 return op; 211 212 os_name = GENERIC_OS_NAME; 213 goto again; 214 } 215 216 static int write_dkfstab(ef, q, output) 217 FILE *ef; 218 qelem *q; 219 void (*output)(); 220 { 221 int errors = 0; 222 disk_fs *dp; 223 224 ITER(dp, disk_fs, q) 225 if (strcmp(dp->d_fstype, "export") != 0) 226 (*output)(ef, dp); 227 228 return errors; 229 } 230 231 static int write_dkrmount(ef, q, hn, output) 232 FILE *ef; 233 qelem *q; 234 char *hn; 235 void (*output)(); 236 { 237 int errors = 0; 238 fsmount *fp; 239 240 ITER(fp, fsmount, q) 241 (*output)(ef, hn, fp); 242 243 return errors; 244 } 245 246 int write_fstab(q) 247 qelem *q; 248 { 249 int errors = 0; 250 251 if (fstab_pref) { 252 host *hp; 253 show_area_being_processed("write fstab", 4); 254 ITER(hp, host, q) { 255 if (hp->h_disk_fs || hp->h_mount) { 256 FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname); 257 if (ef) { 258 struct os_fstab_type *op = find_fstab_type(hp); 259 show_new(hp->h_hostname); 260 if (hp->h_disk_fs) 261 errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab); 262 else 263 log("No local disk mounts on %s", hp->h_hostname); 264 265 if (hp->h_mount) 266 errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount); 267 268 pref_close(ef); 269 } 270 } else { 271 error("no disk mounts on %s", hp->h_hostname); 272 } 273 } 274 } 275 276 return errors; 277 } 278