1 /*
2  * Copyright (c) 1989 Jan-Simon Pendry
3  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
4  * Copyright (c) 1989 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Jan-Simon Pendry at Imperial College, London.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)wr_bparam.c	5.3 (Berkeley) 05/12/91
13  *
14  * $Id: wr_bparam.c,v 5.2.1.3 91/05/07 22:19:10 jsp Alpha $
15  *
16  */
17 
18 #include "../fsinfo/fsinfo.h"
19 
20 /*
21  * Write a host/path in NFS format
22  */
23 static int write_nfsname(ef, fp, hn)
24 FILE *ef;
25 fsmount *fp;
26 char *hn;
27 {
28 	int errors = 0;
29 	char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
30 	domain_strip(h, hn);
31 	fprintf(ef, "%s:%s", h, fp->f_volname);
32 	free(h);
33 	return errors;
34 }
35 
36 /*
37  * Write a bootparams entry for a host
38  */
39 static int write_boot_info(ef, hp)
40 FILE *ef;
41 host *hp;
42 {
43 	int errors = 0;
44 	fprintf(ef, "%s\troot=", hp->h_hostname);
45 	errors += write_nfsname(ef, hp->h_netroot, hp->h_hostname);
46 	fputs(" swap=", ef);
47 	errors += write_nfsname(ef, hp->h_netswap, hp->h_hostname);
48 	fputs("\n", ef);
49 
50 	return 0;
51 }
52 
53 /*
54  * Output a bootparams file
55  */
56 int write_bootparams(q)
57 qelem *q;
58 {
59 	int errors = 0;
60 
61 	if (bootparams_pref) {
62 		FILE *ef = pref_open(bootparams_pref, "bootparams", info_hdr, "bootparams");
63 		if (ef) {
64 			host *hp;
65 			ITER(hp, host, q)
66 				if (hp->h_netroot && hp->h_netswap)
67 					errors += write_boot_info(ef, hp);
68 			errors += pref_close(ef);
69 		} else {
70 			errors++;
71 		}
72 	}
73 
74 	return errors;
75 }
76