1*47488Spendry /*
2*47488Spendry  * $Id: wr_bparam.c,v 5.2.1.2 90/12/21 16:46:49 jsp Alpha $
3*47488Spendry  *
4*47488Spendry  * Copyright (c) 1989 Jan-Simon Pendry
5*47488Spendry  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
6*47488Spendry  * Copyright (c) 1989 The Regents of the University of California.
7*47488Spendry  * All rights reserved.
8*47488Spendry  *
9*47488Spendry  * This code is derived from software contributed to Berkeley by
10*47488Spendry  * Jan-Simon Pendry at Imperial College, London.
11*47488Spendry  *
12*47488Spendry  * Redistribution and use in source and binary forms are permitted provided
13*47488Spendry  * that: (1) source distributions retain this entire copyright notice and
14*47488Spendry  * comment, and (2) distributions including binaries display the following
15*47488Spendry  * acknowledgement:  ``This product includes software developed by the
16*47488Spendry  * University of California, Berkeley and its contributors'' in the
17*47488Spendry  * documentation or other materials provided with the distribution and in
18*47488Spendry  * all advertising materials mentioning features or use of this software.
19*47488Spendry  * Neither the name of the University nor the names of its contributors may
20*47488Spendry  * be used to endorse or promote products derived from this software without
21*47488Spendry  * specific prior written permission.
22*47488Spendry  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
23*47488Spendry  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
24*47488Spendry  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25*47488Spendry  *
26*47488Spendry  *	@(#)wr_bparam.c	5.1 (Berkeley) 03/17/91
27*47488Spendry  */
28*47488Spendry 
29*47488Spendry #include "../fsinfo/fsinfo.h"
30*47488Spendry 
31*47488Spendry /*
32*47488Spendry  * Write a host/path in NFS format
33*47488Spendry  */
34*47488Spendry static int write_nfsname(ef, fp, hn)
35*47488Spendry FILE *ef;
36*47488Spendry fsmount *fp;
37*47488Spendry char *hn;
38*47488Spendry {
39*47488Spendry 	int errors = 0;
40*47488Spendry 	char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
41*47488Spendry 	domain_strip(h, hn);
42*47488Spendry 	fprintf(ef, "%s:%s", h, fp->f_volname);
43*47488Spendry 	free(h);
44*47488Spendry 	return errors;
45*47488Spendry }
46*47488Spendry 
47*47488Spendry /*
48*47488Spendry  * Write a bootparams entry for a host
49*47488Spendry  */
50*47488Spendry static int write_boot_info(ef, hp)
51*47488Spendry FILE *ef;
52*47488Spendry host *hp;
53*47488Spendry {
54*47488Spendry 	int errors = 0;
55*47488Spendry 	fprintf(ef, "%s\troot=", hp->h_hostname);
56*47488Spendry 	errors += write_nfsname(ef, hp->h_netroot, hp->h_hostname);
57*47488Spendry 	fputs(" swap=", ef);
58*47488Spendry 	errors += write_nfsname(ef, hp->h_netswap, hp->h_hostname);
59*47488Spendry 	fputs("\n", ef);
60*47488Spendry 
61*47488Spendry 	return 0;
62*47488Spendry }
63*47488Spendry 
64*47488Spendry /*
65*47488Spendry  * Output a bootparams file
66*47488Spendry  */
67*47488Spendry int write_bootparams(q)
68*47488Spendry qelem *q;
69*47488Spendry {
70*47488Spendry 	int errors = 0;
71*47488Spendry 
72*47488Spendry 	if (bootparams_pref) {
73*47488Spendry 		FILE *ef = pref_open(bootparams_pref, "bootparams", info_hdr, "bootparams");
74*47488Spendry 		if (ef) {
75*47488Spendry 			host *hp;
76*47488Spendry 			ITER(hp, host, q)
77*47488Spendry 				if (hp->h_netroot && hp->h_netswap)
78*47488Spendry 					errors += write_boot_info(ef, hp);
79*47488Spendry 			errors += pref_close(ef);
80*47488Spendry 		} else {
81*47488Spendry 			errors++;
82*47488Spendry 		}
83*47488Spendry 	}
84*47488Spendry 
85*47488Spendry 	return errors;
86*47488Spendry }
87