1 /* $NetBSD: savenewlabel.c,v 1.6 2009/05/14 16:23:38 sborrill Exp $ */
4 * Copyright 1997 Jonathan Stone
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project by
19 * 4. The name of Jonathan Stone may not be used to endorse
20 * or promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY JONATHAN STONE ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/cdefs.h>
38 #if defined(LIBC_SCCS) && !defined(lint)
39 __RCSID("$NetBSD: savenewlabel.c,v 1.6 2009/05/14 16:23:38 sborrill Exp $");
42 #include <sys/types.h>
50 #include <sys/ioctl.h>
54 #include "menu_defs.h"
58 savenewlabel(partinfo
*lp
, int nparts
)
64 N.B. disklabels only support up to 2TB (32-bit field for sectors).
65 This function explicitly narrows from daddr_t (64-bit unsigned) to
66 uint32_t when writing the disklabel.
69 /* Create /etc/disktab */
70 f
= fopen("/tmp/disktab", "w");
72 (void)fprintf(logfp
, "Creating disklabel %s\n", bsddiskname
);
73 scripting_fprintf(NULL
, "cat <<EOF >>/etc/disktab\n");
76 (void)fprintf(stderr
, "Could not open /etc/disktab");
79 "Failed to open /etc/diskabel for appending.\n");
82 scripting_fprintf(f
, "%s|NetBSD installation generated:\\\n", bsddiskname
);
83 scripting_fprintf(f
, "\t:dt=%s:ty=winchester:\\\n", disktype
);
84 scripting_fprintf(f
, "\t:nc#%d:nt#%d:ns#%d:\\\n", dlcyl
, dlhead
, dlsec
);
85 scripting_fprintf(f
, "\t:sc#%d:su#%" PRIu32
":\\\n", dlhead
*dlsec
,
87 scripting_fprintf(f
, "\t:se#%d:%s\\\n", sectorsize
, doessf
);
88 for (i
= 0; i
< nparts
; i
++) {
89 scripting_fprintf(f
, "\t:p%c#%" PRIu32
":o%c#%" PRIu32
":t%c=%s:",
90 'a'+i
, (uint32_t)bsdlabel
[i
].pi_size
,
91 'a'+i
, (uint32_t)bsdlabel
[i
].pi_offset
,
92 'a'+i
, fstypenames
[bsdlabel
[i
].pi_fstype
]);
93 if (PI_ISBSDFS(&bsdlabel
[i
]))
94 scripting_fprintf (f
, "b%c#%" PRIu32
":f%c#%" PRIu32
":ta=4.2BSD:",
95 'a'+i
, (uint32_t)(bsdlabel
[i
].pi_fsize
* bsdlabel
[i
].pi_frag
),
96 'a'+i
, (uint32_t)bsdlabel
[i
].pi_fsize
);
99 scripting_fprintf(f
, "\\\n");
101 scripting_fprintf(f
, "\n");
104 scripting_fprintf(NULL
, "EOF\n");