HAMMER 33/many: Expand transaction processing, fix bug in B-Tree
[dragonfly.git] / contrib / amd / fsinfo / wr_fstab.c
bloba63d47d213689dab61ed34ec7694c549a1153314
1 /*
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.
6 * All rights reserved.
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
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.
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.
39 * %W% (Berkeley) %G%
41 * $Id: wr_fstab.c,v 1.2 1999/01/10 21:54:30 ezk Exp $
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>
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 {
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[] = {
75 "aix1", write_aix1_dkfstab, write_aix1_dkrmount
76 }, /* AIX 1 */
78 "aix3", write_aix3_dkfstab, write_aix3_dkrmount
79 }, /* AIX 3 */
81 "generic", write_generic_dkfstab, write_generic_dkrmount
82 }, /* Generic */
84 "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount
85 }, /* Ultrix */
87 "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount
88 }, /* Ultrix */
90 "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount
91 }, /* Ultrix */
93 0, 0, 0
98 /* ---------- AIX 1 ------------------------------ */
101 * AIX 1 format
103 static void
104 write_aix1_dkfstab(FILE *ef, disk_fs *dp)
106 char *hp = strdup(dp->d_host->h_hostname);
107 char *p = strchr(hp, '.');
109 if (p)
110 *p = '\0';
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);
124 static void
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, '.');
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,
138 fp->f_volname,
139 fp->f_fstype,
140 fp->f_fstype,
141 fp->f_localname,
142 fp->f_opts);
144 XFREE(hp);
145 XFREE(h);
149 /* ---------- AIX 3 ------------------------------ */
152 * AIX 3 format
154 static void
155 write_aix3_dkfstab(FILE *ef, disk_fs *dp)
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");
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);
173 static void
174 write_aix3_dkrmount(FILE *ef, char *hn, fsmount *fp)
176 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
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,
182 fp->f_volname,
183 fp->f_fstype,
184 fp->f_fstype,
185 fp->f_localname,
186 fp->f_opts);
188 XFREE(h);
192 /* ---------- Ultrix ----------------------------- */
194 static void
195 write_ultrix_dkfstab(FILE *ef, disk_fs *dp)
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);
207 static void
208 write_ultrix_dkrmount(FILE *ef, char *hn, fsmount *fp)
210 char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
212 domain_strip(h, hn);
213 fprintf(ef, "%s@%s:%s:%s:%s:0:0\n",
214 fp->f_volname,
216 fp->f_localname,
217 fp->f_fstype,
218 fp->f_opts);
219 XFREE(h);
223 /* ---------- Generic ---------------------------- */
226 * Generic (BSD, SunOS, HPUX) format
228 static void
229 write_generic_dkfstab(FILE *ef, disk_fs *dp)
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);
241 static void
242 write_generic_dkrmount(FILE *ef, char *hn, fsmount *fp)
244 char *h;
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);
251 domain_strip(h, hn);
252 fprintf(ef, "%s:%s %s %s %s 0 0\n",
254 fp->f_volname,
255 fp->f_localname,
256 fp->f_fstype,
257 fp->f_opts);
258 XFREE(h);
262 static struct os_fstab_type *
263 find_fstab_type(host *hp)
265 struct os_fstab_type *op = 0;
266 char *os_name = 0;
268 again:;
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;
275 for (op = os_tabs; op->os_name; op++)
276 if (STREQ(os_name, op->os_name))
277 return op;
279 os_name = GENERIC_OS_NAME;
280 goto again;
284 static int
285 write_dkfstab(FILE *ef, qelem *q, void (*output) (FILE *, disk_fs *))
287 int errors = 0;
288 disk_fs *dp;
290 ITER(dp, disk_fs, q)
291 if (!STREQ(dp->d_fstype, "export"))
292 (*output) (ef, dp);
294 return errors;
298 static int
299 write_dkrmount(FILE *ef, qelem *q, char *hn, void (*output) (FILE *, char *, fsmount *))
301 int errors = 0;
302 fsmount *fp;
304 ITER(fp, fsmount, q)
305 (*output) (ef, hn, fp);
307 return errors;
312 write_fstab(qelem *q)
314 int errors = 0;
316 if (fstab_pref) {
317 host *hp;
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);
331 if (hp->h_mount)
332 errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);
334 pref_close(ef);
336 } else {
337 error("no disk mounts on %s", hp->h_hostname);
341 return errors;