138494Sobrien/* 2310490Scy * Copyright (c) 1997-2014 Erez Zadok 338494Sobrien * Copyright (c) 1989 Jan-Simon Pendry 438494Sobrien * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 538494Sobrien * Copyright (c) 1989 The Regents of the University of California. 638494Sobrien * All rights reserved. 738494Sobrien * 838494Sobrien * This code is derived from software contributed to Berkeley by 938494Sobrien * Jan-Simon Pendry at Imperial College, London. 1038494Sobrien * 1138494Sobrien * Redistribution and use in source and binary forms, with or without 1238494Sobrien * modification, are permitted provided that the following conditions 1338494Sobrien * are met: 1438494Sobrien * 1. Redistributions of source code must retain the above copyright 1538494Sobrien * notice, this list of conditions and the following disclaimer. 1638494Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1738494Sobrien * notice, this list of conditions and the following disclaimer in the 1838494Sobrien * documentation and/or other materials provided with the distribution. 19310490Scy * 3. Neither the name of the University nor the names of its contributors 2038494Sobrien * may be used to endorse or promote products derived from this software 2138494Sobrien * without specific prior written permission. 2238494Sobrien * 2338494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2438494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2538494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2638494Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2738494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2838494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2938494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3038494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3138494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3238494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3338494Sobrien * SUCH DAMAGE. 3438494Sobrien * 3538494Sobrien * 36174294Sobrien * File: am-utils/fsinfo/wr_bparam.c 3738494Sobrien * 3838494Sobrien */ 3938494Sobrien 4038494Sobrien#ifdef HAVE_CONFIG_H 4138494Sobrien# include <config.h> 4238494Sobrien#endif /* HAVE_CONFIG_H */ 4338494Sobrien#include <am_defs.h> 4438494Sobrien#include <fsi_data.h> 4538494Sobrien#include <fsinfo.h> 4638494Sobrien 4738494Sobrien 4838494Sobrien/* 4938494Sobrien * Write a host/path in NFS format 5038494Sobrien */ 5138494Sobrienstatic int 5238494Sobrienwrite_nfsname(FILE *ef, fsmount *fp, char *hn) 5338494Sobrien{ 5438494Sobrien int errors = 0; 55310490Scy char *h = xstrdup(fp->f_ref->m_dk->d_host->h_hostname); 5638494Sobrien 5738494Sobrien domain_strip(h, hn); 5838494Sobrien fprintf(ef, "%s:%s", h, fp->f_volname); 5938494Sobrien XFREE(h); 6038494Sobrien return errors; 6138494Sobrien} 6238494Sobrien 6338494Sobrien 6438494Sobrien/* 6538494Sobrien * Write a bootparams entry for a host 6638494Sobrien */ 6738494Sobrienstatic int 6838494Sobrienwrite_boot_info(FILE *ef, host *hp) 6938494Sobrien{ 7038494Sobrien int errors = 0; 7138494Sobrien 7238494Sobrien fprintf(ef, "%s\troot=", hp->h_hostname); 7338494Sobrien errors += write_nfsname(ef, hp->h_netroot, hp->h_hostname); 7438494Sobrien fputs(" swap=", ef); 7538494Sobrien errors += write_nfsname(ef, hp->h_netswap, hp->h_hostname); 7638494Sobrien fputs("\n", ef); 7738494Sobrien 7838494Sobrien return 0; 7938494Sobrien} 8038494Sobrien 8138494Sobrien 8238494Sobrien/* 8338494Sobrien * Output a bootparams file 8438494Sobrien */ 8538494Sobrienint 8638494Sobrienwrite_bootparams(qelem *q) 8738494Sobrien{ 8838494Sobrien int errors = 0; 8938494Sobrien 9038494Sobrien if (bootparams_pref) { 9138494Sobrien FILE *ef = pref_open(bootparams_pref, "bootparams", info_hdr, "bootparams"); 9238494Sobrien if (ef) { 9338494Sobrien host *hp; 9438494Sobrien ITER(hp, host, q) 9538494Sobrien if (hp->h_netroot && hp->h_netswap) 9638494Sobrien errors += write_boot_info(ef, hp); 9738494Sobrien errors += pref_close(ef); 9838494Sobrien } else { 9938494Sobrien errors++; 10038494Sobrien } 10138494Sobrien } 10238494Sobrien 10338494Sobrien return errors; 10438494Sobrien} 105