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