1 /* $NetBSD: mkswap.c,v 1.6 2008/12/28 01:23:46 christos Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * from: @(#)mkswap.c 8.1 (Berkeley) 6/6/93
43 #if HAVE_NBTOOL_CONFIG_H
44 #include "nbtool_config.h"
47 #include <sys/param.h>
56 static char *mkdevstr(dev_t
);
57 static int mkoneswap(struct config
*);
60 * Make the various swap*.c files. Nothing to do for generic swap.
67 TAILQ_FOREACH(cf
, &allcf
, cf_next
) {
80 (void)snprintf(buf
, sizeof(buf
), "NODEV");
82 (void)snprintf(buf
, sizeof(buf
), "makedev(%d, %d)",
88 mkoneswap(struct config
*cf
)
92 char fname
[200], tname
[200];
95 (void)snprintf(fname
, sizeof(fname
), "swap%s.c", cf
->cf_name
);
96 (void)snprintf(tname
, sizeof(tname
), "swap%s.c.tmp", cf
->cf_name
);
97 if ((fp
= fopen(tname
, "w")) == NULL
) {
98 warn("cannot open %s", fname
);
102 autogen_comment(fp
, fname
);
104 fputs("#include <sys/param.h>\n"
105 "#include <sys/conf.h>\n\n", fp
);
107 * Emit the root device.
110 if (cf
->cf_root
->nv_str
== s_qmark
)
111 strlcpy(specinfo
, "NULL", sizeof(specinfo
));
113 snprintf(specinfo
, sizeof(specinfo
), "\"%s\"",
114 cf
->cf_root
->nv_str
);
115 fprintf(fp
, "const char *rootspec = %s;\n", specinfo
);
116 fprintf(fp
, "dev_t\trootdev = %s;\t/* %s */\n\n",
117 mkdevstr(nv
->nv_num
),
118 nv
->nv_str
== s_qmark
? "wildcarded" : nv
->nv_str
);
121 * Emit the dump device.
124 if (cf
->cf_dump
== NULL
)
125 strlcpy(specinfo
, "NULL", sizeof(specinfo
));
127 snprintf(specinfo
, sizeof(specinfo
), "\"%s\"", cf
->cf_dump
->nv_str
);
128 fprintf(fp
, "const char *dumpspec = %s;\n", specinfo
);
129 fprintf(fp
, "dev_t\tdumpdev = %s;\t/* %s */\n\n",
130 nv
? mkdevstr(nv
->nv_num
) : "NODEV",
131 nv
? nv
->nv_str
: "unspecified");
134 * Emit the root file system.
136 fprintf(fp
, "const char *rootfstype = \"%s\";\n",
137 cf
->cf_fstype
? cf
->cf_fstype
: "?");
147 if (moveifchanged(tname
, fname
) != 0) {
148 warn("error renaming %s", fname
);
154 warn("error writing %s", fname
);