xref: /csrg-svn/usr.sbin/amd/fsinfo/wr_fstab.c (revision 61793)
147491Spendry /*
247491Spendry  * Copyright (c) 1989 Jan-Simon Pendry
347491Spendry  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
4*61793Sbostic  * Copyright (c) 1989, 1993
5*61793Sbostic  *	The Regents of the University of California.  All rights reserved.
647491Spendry  *
747491Spendry  * This code is derived from software contributed to Berkeley by
847491Spendry  * Jan-Simon Pendry at Imperial College, London.
947491Spendry  *
1047530Spendry  * %sccs.include.redist.c%
1147491Spendry  *
12*61793Sbostic  *	@(#)wr_fstab.c	8.1 (Berkeley) 06/06/93
1349686Spendry  *
1452455Spendry  * $Id: wr_fstab.c,v 5.2.2.1 1992/02/09 15:09:49 jsp beta $
1549686Spendry  *
1647491Spendry  */
1747491Spendry 
1847491Spendry #include "../fsinfo/fsinfo.h"
1947491Spendry 
2047491Spendry /* ---------- AIX 1 ------------------------------ */
2147491Spendry 
2247491Spendry /*
2347491Spendry  * AIX 1 format
2447491Spendry  */
write_aix1_dkfstab(ef,dp)2547491Spendry static void write_aix1_dkfstab(ef, dp)
2647491Spendry FILE *ef;
2747491Spendry disk_fs *dp;
2847491Spendry {
2947491Spendry 	char *hp = strdup(dp->d_host->h_hostname);
3047491Spendry 	char *p = strchr(hp, '.');
3147491Spendry 	if (p)
3247491Spendry 		*p = '\0';
3347491Spendry 
3447491Spendry 	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",
3547491Spendry 		dp->d_mountpt,
3647491Spendry 		dp->d_dev,
3747491Spendry 		dp->d_fstype,
3847491Spendry 		dp->d_fstype,
3947491Spendry 		dp->d_log,
4047491Spendry 		dp->d_mountpt,
4147491Spendry 		dp->d_opts);
4247491Spendry 	free(hp);
4347491Spendry }
4447491Spendry 
write_aix1_dkrmount(ef,hn,fp)4547491Spendry static void write_aix1_dkrmount(ef, hn, fp)
4647491Spendry FILE *ef;
4747491Spendry char *hn;
4847491Spendry fsmount *fp;
4947491Spendry {
5047491Spendry 	char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
5147491Spendry 	char *hp = strdup(h);
5247491Spendry 	char *p = strchr(hp, '.');
5347491Spendry 	if (p)
5447491Spendry 		*p = '\0';
5547491Spendry 	domain_strip(h, hn);
5647491Spendry 	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",
5747491Spendry 		fp->f_localname,
5847491Spendry 		hp,
5947491Spendry 		h,
6047491Spendry 		fp->f_volname,
6147491Spendry 		fp->f_fstype,
6247491Spendry 		fp->f_fstype,
6347491Spendry 		fp->f_localname,
6447491Spendry 		fp->f_opts);
6547491Spendry 
6647491Spendry 	free(hp);
6747491Spendry 	free(h);
6847491Spendry }
6947491Spendry 
7047491Spendry /* ---------- AIX 3 ------------------------------ */
7147491Spendry 
7247491Spendry /*
7347491Spendry  * AIX 3 format
7447491Spendry  */
write_aix3_dkfstab(ef,dp)7547491Spendry static void write_aix3_dkfstab(ef, dp)
7647491Spendry FILE *ef;
7747491Spendry disk_fs *dp;
7847491Spendry {
7947491Spendry 	if (strcmp(dp->d_fstype, "jfs") == 0 && strncmp(dp->d_dev, "/dev/", 5) == 0 && !dp->d_log)
8047491Spendry 		error("aix 3 needs a log device for journalled filesystem (jfs) mounts");
8147491Spendry 
8247491Spendry 	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",
8347491Spendry 		dp->d_mountpt,
8447491Spendry 		dp->d_dev,
8547491Spendry 		dp->d_fstype,
8647491Spendry 		dp->d_fstype,
8747491Spendry 		dp->d_log,
8847491Spendry 		dp->d_mountpt,
8947491Spendry 		dp->d_opts);
9047491Spendry }
9147491Spendry 
write_aix3_dkrmount(ef,hn,fp)9247491Spendry static void write_aix3_dkrmount(ef, hn, fp)
9347491Spendry FILE *ef;
9447491Spendry char *hn;
9547491Spendry fsmount *fp;
9647491Spendry {
9747491Spendry 	char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
9847491Spendry 	domain_strip(h, hn);
9947491Spendry 	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",
10047491Spendry 		fp->f_localname,
10147491Spendry 		h,
10247491Spendry 		fp->f_volname,
10347491Spendry 		fp->f_fstype,
10447491Spendry 		fp->f_fstype,
10547491Spendry 		fp->f_localname,
10647491Spendry 		fp->f_opts);
10747491Spendry 
10847491Spendry 	free(h);
10947491Spendry }
11047491Spendry 
11147491Spendry /* ---------- Ultrix ----------------------------- */
11247491Spendry 
write_ultrix_dkfstab(ef,dp)11347491Spendry static void write_ultrix_dkfstab(ef, dp)
11447491Spendry FILE *ef;
11547491Spendry disk_fs *dp;
11647491Spendry {
11747491Spendry 	fprintf(ef, "%s:%s:%s:%s:%d:%d\n",
11847491Spendry 		dp->d_dev,
11947491Spendry 		dp->d_mountpt,
12047491Spendry 		dp->d_fstype,
12147491Spendry 		dp->d_opts,
12247491Spendry 		dp->d_freq,
12347491Spendry 		dp->d_passno);
12447491Spendry }
12547491Spendry 
write_ultrix_dkrmount(ef,hn,fp)12647491Spendry static void write_ultrix_dkrmount(ef, hn, fp)
12747491Spendry FILE *ef;
12847491Spendry char *hn;
12947491Spendry fsmount *fp;
13047491Spendry {
13147491Spendry 	char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
13247491Spendry 	domain_strip(h, hn);
13347491Spendry 	fprintf(ef, "%s@%s:%s:%s:%s:0:0\n",
13447491Spendry 		fp->f_volname,
13547491Spendry 		h,
13647491Spendry 		fp->f_localname,
13747491Spendry 		fp->f_fstype,
13847491Spendry 		fp->f_opts);
13947491Spendry 	free(h);
14047491Spendry }
14147491Spendry 
14247491Spendry /* ---------- Generic ---------------------------- */
14347491Spendry 
14447491Spendry /*
14547491Spendry  * Generic (BSD, SunOS, HPUX) format
14647491Spendry  */
write_generic_dkfstab(ef,dp)14747491Spendry static void write_generic_dkfstab(ef, dp)
14847491Spendry FILE *ef;
14947491Spendry disk_fs *dp;
15047491Spendry {
15147491Spendry 	fprintf(ef, "%s %s %s %s %d %d\n",
15247491Spendry 		dp->d_dev,
15347491Spendry 		dp->d_mountpt,
15447491Spendry 		dp->d_fstype,
15547491Spendry 		dp->d_opts,
15647491Spendry 		dp->d_freq,
15747491Spendry 		dp->d_passno);
15847491Spendry }
15947491Spendry 
write_generic_dkrmount(ef,hn,fp)16047491Spendry static void write_generic_dkrmount(ef, hn, fp)
16147491Spendry FILE *ef;
16247491Spendry char *hn;
16347491Spendry fsmount *fp;
16447491Spendry {
16547491Spendry 	char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
16647491Spendry 	domain_strip(h, hn);
16747491Spendry 	fprintf(ef, "%s:%s %s %s %s 0 0\n",
16847491Spendry 		h,
16947491Spendry 		fp->f_volname,
17047491Spendry 		fp->f_localname,
17147491Spendry 		fp->f_fstype,
17247491Spendry 		fp->f_opts);
17347491Spendry 	free(h);
17447491Spendry }
17547491Spendry 
17647491Spendry /* ----------------------------------------------- */
17747491Spendry 
17847491Spendry static struct os_fstab_type {
17947491Spendry 	char *os_name;
18047491Spendry 	void (*op_fstab)();
18147491Spendry 	void (*op_mount)();
18247491Spendry } os_tabs[] = {
18347491Spendry 	{ "aix1", write_aix1_dkfstab, write_aix1_dkrmount },		/* AIX 1 */
18447491Spendry 	{ "aix3", write_aix3_dkfstab, write_aix3_dkrmount },		/* AIX 3 */
18547491Spendry 	{ "generic", write_generic_dkfstab, write_generic_dkrmount },	/* Generic */
18647491Spendry 	{ "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount },	/* Ultrix */
18747491Spendry 	{ "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount },	/* Ultrix */
18847491Spendry 	{ "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount },	/* Ultrix */
18947491Spendry 	{ 0, 0, 0 }
19047491Spendry };
19147491Spendry 
19247491Spendry #define	GENERIC_OS_NAME "generic"
19347491Spendry 
find_fstab_type(hp)19447491Spendry static struct os_fstab_type *find_fstab_type(hp)
19547491Spendry host *hp;
19647491Spendry {
19747491Spendry 	struct os_fstab_type *op = 0;
19847491Spendry 	char *os_name = 0;
19947491Spendry 
20047491Spendry again:;
20147491Spendry 	if (os_name == 0) {
20247491Spendry 		if (ISSET(hp->h_mask, HF_OS))
20347491Spendry 			os_name = hp->h_os;
20447491Spendry 		else
20547491Spendry 			os_name = GENERIC_OS_NAME;
20647491Spendry 	}
20747491Spendry 
20847491Spendry 	for (op = os_tabs; op->os_name; op++)
20947491Spendry 		if (strcmp(os_name, op->os_name) == 0)
21047491Spendry 			return op;
21147491Spendry 
21247491Spendry 	os_name = GENERIC_OS_NAME;
21347491Spendry 	goto again;
21447491Spendry }
21547491Spendry 
write_dkfstab(ef,q,output)21647491Spendry static int write_dkfstab(ef, q, output)
21747491Spendry FILE *ef;
21847491Spendry qelem *q;
21947491Spendry void (*output)();
22047491Spendry {
22147491Spendry 	int errors = 0;
22247491Spendry 	disk_fs *dp;
22347491Spendry 
22447491Spendry 	ITER(dp, disk_fs, q)
22547491Spendry 		if (strcmp(dp->d_fstype, "export") != 0)
22647491Spendry 			(*output)(ef, dp);
22747491Spendry 
22847491Spendry 	return errors;
22947491Spendry }
23047491Spendry 
write_dkrmount(ef,q,hn,output)23147491Spendry static int write_dkrmount(ef, q, hn, output)
23247491Spendry FILE *ef;
23347491Spendry qelem *q;
23447491Spendry char *hn;
23547491Spendry void (*output)();
23647491Spendry {
23747491Spendry 	int errors = 0;
23847491Spendry 	fsmount *fp;
23947491Spendry 
24047491Spendry 	ITER(fp, fsmount, q)
24147491Spendry 		(*output)(ef, hn, fp);
24247491Spendry 
24347491Spendry 	return errors;
24447491Spendry }
24547491Spendry 
write_fstab(q)24647491Spendry int write_fstab(q)
24747491Spendry qelem *q;
24847491Spendry {
24947491Spendry 	int errors = 0;
25047491Spendry 
25147491Spendry 	if (fstab_pref) {
25247491Spendry 		host *hp;
25347491Spendry 		show_area_being_processed("write fstab", 4);
25447491Spendry 		ITER(hp, host, q) {
25547491Spendry 			if (hp->h_disk_fs || hp->h_mount) {
25647491Spendry 				FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname);
25747491Spendry 				if (ef) {
25847491Spendry 					struct os_fstab_type *op = find_fstab_type(hp);
25947491Spendry 					show_new(hp->h_hostname);
26047491Spendry 					if (hp->h_disk_fs)
26147491Spendry 						errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab);
26247491Spendry 					else
26347491Spendry 						log("No local disk mounts on %s", hp->h_hostname);
26447491Spendry 
26547491Spendry 					if (hp->h_mount)
26647491Spendry 						errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);
26747491Spendry 
26847491Spendry 					pref_close(ef);
26947491Spendry 				}
27047491Spendry 			} else {
27147491Spendry 				error("no disk mounts on %s", hp->h_hostname);
27247491Spendry 			}
27347491Spendry 		}
27447491Spendry 	}
27547491Spendry 
27647491Spendry 	return errors;
27747491Spendry }
278