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