1 /* 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * All advertising materials mentioning features or use of this software 10 * must display the following acknowledgement: 11 * This product includes software developed by the University of 12 * California, Lawrence Berkeley Laboratories. 13 * 14 * %sccs.include.redist.c% 15 * 16 * @(#)mkswap.c 5.1 (Berkeley) 01/12/93 17 * 18 * from: $Header: mkswap.c,v 1.2 92/09/22 03:32:04 torek Exp $ 19 */ 20 21 #include <sys/param.h> 22 #include <errno.h> 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 #include "config.h" 27 28 static int mkoneswap __P((struct config *)); 29 30 /* 31 * Make the various swap*.c files. Nothing to do for generic swap. 32 */ 33 int 34 mkswap() 35 { 36 register struct config *cf; 37 38 for (cf = allcf; cf != NULL; cf = cf->cf_next) 39 if (cf->cf_root != NULL && mkoneswap(cf)) 40 return (1); 41 return (0); 42 } 43 44 static int 45 mkoneswap(cf) 46 register struct config *cf; 47 { 48 register struct nvlist *nv; 49 register FILE *fp; 50 register char *fname; 51 char buf[200]; 52 53 (void)sprintf(buf, "swap%s.c", cf->cf_name); 54 fname = path(buf); 55 if ((fp = fopen(fname, "w")) == NULL) { 56 (void)fprintf(stderr, "config: cannot write %s: %s\n", 57 fname, strerror(errno)); 58 return (1); 59 } 60 if (fputs("\ 61 #include <sys/param.h>\n\ 62 #include <sys/conf.h>\n\n", fp) < 0) 63 goto wrerror; 64 nv = cf->cf_root; 65 if (fprintf(fp, "dev_t\trootdev = makedev(%d, %d);\t/* %s */\n", 66 major(nv->nv_int), minor(nv->nv_int), nv->nv_str) < 0) 67 goto wrerror; 68 nv = cf->cf_dump; 69 if (fprintf(fp, "dev_t\tdumpdev = makedev(%d, %d);\t/* %s */\n", 70 major(nv->nv_int), minor(nv->nv_int), nv->nv_str) < 0) 71 goto wrerror; 72 if (fputs("\nstruct\tswdevt swdevt[] = {\n", fp) < 0) 73 goto wrerror; 74 for (nv = cf->cf_swap; nv != NULL; nv = nv->nv_next) 75 if (fprintf(fp, "\t{ makedev(%d, %d),\t0,\t0 },\t/* %s */\n", 76 major(nv->nv_int), minor(nv->nv_int), nv->nv_str) < 0) 77 goto wrerror; 78 if (fputs("\t{ NODEV, 0, 0 }\n};\n", fp) < 0) 79 goto wrerror; 80 if (fclose(fp)) { 81 fp = NULL; 82 goto wrerror; 83 } 84 free(fname); 85 return (0); 86 wrerror: 87 (void)fprintf(stderr, "config: error writing %s: %s\n", 88 fname, strerror(errno)); 89 if (fp != NULL) 90 (void)fclose(fp); 91 /* (void)unlink(fname); */ 92 free(fname); 93 return (1); 94 } 95