Expand PMF_FN_* macros.
[netbsd-mini2440.git] / distrib / utils / sysinst / savenewlabel.c
blob3d61ccc103067ba46d308458169488d8da77d0cb
1 /* $NetBSD: savenewlabel.c,v 1.6 2009/05/14 16:23:38 sborrill Exp $ */
3 /*
4 * Copyright 1997 Jonathan Stone
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
18 * Jonathan Stone.
19 * 4. The name of Jonathan Stone may not be used to endorse
20 * or promote products derived from this software without specific prior
21 * written permission.
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 $");
40 #endif
42 #include <sys/types.h>
43 #include <errno.h>
44 #include <stdio.h>
45 #include <fcntl.h>
46 #include <inttypes.h>
47 #include <util.h>
48 #include <unistd.h>
49 #include <sys/dkio.h>
50 #include <sys/ioctl.h>
52 #include "defs.h"
53 #include "msg_defs.h"
54 #include "menu_defs.h"
56 int
57 /*ARGSUSED*/
58 savenewlabel(partinfo *lp, int nparts)
60 FILE *f;
61 int i;
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");
71 if (logging)
72 (void)fprintf(logfp, "Creating disklabel %s\n", bsddiskname);
73 scripting_fprintf(NULL, "cat <<EOF >>/etc/disktab\n");
74 if (f == NULL) {
75 endwin();
76 (void)fprintf(stderr, "Could not open /etc/disktab");
77 if (logging)
78 (void)fprintf(logfp,
79 "Failed to open /etc/diskabel for appending.\n");
80 exit (1);
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,
86 (uint32_t)dlsize);
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);
98 if (i < nparts - 1)
99 scripting_fprintf(f, "\\\n");
100 else
101 scripting_fprintf(f, "\n");
103 fclose (f);
104 scripting_fprintf(NULL, "EOF\n");
105 fflush(NULL);
106 return(0);