File: [cvs.NetBSD.org] / src / distrib / utils / sysinst / savenewlabel.c (download)
Revision 1.12, Thu Jan 5 22:18:36 2012 UTC (16 months, 1 week ago) by christos
Branch: MAIN
CVS Tags: yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, tls-maxphys-nbase, tls-maxphys-base, tls-maxphys, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, khorben-n900, agc-symver-base, agc-symver, HEAD Changes since 1.11: +4 -4
lines
we want the label name not the fstype name.
|
/* $NetBSD: savenewlabel.c,v 1.12 2012/01/05 22:18:36 christos Exp $ */
/*
* Copyright 1997 Jonathan Stone
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Jonathan Stone.
* 4. The name of Jonathan Stone may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY JONATHAN STONE ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: savenewlabel.c,v 1.12 2012/01/05 22:18:36 christos Exp $");
#endif
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <inttypes.h>
#include <util.h>
#include <unistd.h>
#include <sys/dkio.h>
#include <sys/ioctl.h>
#include "defs.h"
#include "msg_defs.h"
#include "menu_defs.h"
int
/*ARGSUSED*/
savenewlabel(partinfo *lp, int nparts)
{
FILE *f;
int i;
/*
N.B. disklabels only support up to 2TB (32-bit field for sectors).
This function explicitly narrows from daddr_t (64-bit unsigned) to
uint32_t when writing the disklabel.
*/
/* Create /etc/disktab */
f = fopen("/tmp/disktab", "w");
if (logfp)
(void)fprintf(logfp, "Creating disklabel %s\n", bsddiskname);
scripting_fprintf(NULL, "cat <<EOF >>/etc/disktab\n");
if (f == NULL) {
endwin();
(void)fprintf(stderr, "Could not open /etc/disktab");
if (logfp)
(void)fprintf(logfp,
"Failed to open /etc/disktab for appending.\n");
exit (1);
}
scripting_fprintf(f, "%s|NetBSD installation generated:\\\n", bsddiskname);
scripting_fprintf(f, "\t:dt=%s:ty=winchester:\\\n", disktype);
scripting_fprintf(f, "\t:nc#%d:nt#%d:ns#%d:\\\n", dlcyl, dlhead, dlsec);
scripting_fprintf(f, "\t:sc#%d:su#%" PRIu32 ":\\\n", dlhead*dlsec,
(uint32_t)dlsize);
scripting_fprintf(f, "\t:se#%d:%s\\\n", sectorsize, doessf);
if ((size_t)nparts > __arraycount(bsdlabel)) {
nparts = __arraycount(bsdlabel);
if (logfp)
(void)fprintf(logfp, "nparts limited to %d.\n", nparts);
}
for (i = 0; i < nparts; i++) {
scripting_fprintf(f, "\t:p%c#%" PRIu32 ":o%c#%" PRIu32
":t%c=%s:", 'a'+i, (uint32_t)bsdlabel[i].pi_size,
'a'+i, (uint32_t)bsdlabel[i].pi_offset, 'a'+i,
getfslabelname(bsdlabel[i].pi_fstype));
if (PI_ISBSDFS(&bsdlabel[i]))
scripting_fprintf (f, "b%c#%" PRIu32 ":f%c#%" PRIu32
":", 'a'+i,
(uint32_t)(bsdlabel[i].pi_fsize *
bsdlabel[i].pi_frag),
'a'+i, (uint32_t)bsdlabel[i].pi_fsize);
if (i < nparts - 1)
scripting_fprintf(f, "\\\n");
else
scripting_fprintf(f, "\n");
}
fclose (f);
scripting_fprintf(NULL, "EOF\n");
fflush(NULL);
return(0);
}