1 /* $NetBSD: writedtab.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */ 2 3 /* 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julian Coleman, Waldi Ravens and Leo Weppelman. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include "privahdi.h" 40 #include <disktab.h> 41 #include <fcntl.h> 42 #include <stdio.h> 43 44 /* 45 * Write AHDI partitions to disk 46 */ 47 int 48 ahdi_writedisktab (ptable, disktype, disktab, dtype) 49 struct ahdi_ptable *ptable; 50 char *disktype, *disktab, *dtype; 51 { 52 FILE *fd; 53 int pid, i, j, todo; 54 55 if ((fd = fopen (strlen (disktab) ? disktab : _PATH_DISKTAB, "a")) 56 == NULL) 57 return (-1); 58 59 fprintf (fd, "%s disk|%s:\\\n", 60 strlen (dtype) ? dtype : "SCSI", disktype); 61 fprintf (fd, "\t:ty#winchester:dt=%s:ns#%u:nt#%u:nc#%u:sc#%u:su#%u", 62 strlen (dtype) ? dtype : "SCSI", ptable->nsectors, 63 ptable->ntracks, ptable->ncylinders, ptable->secpercyl, 64 ptable->secperunit); 65 66 todo = ptable->nparts; 67 j = 0; 68 while (todo) { 69 for (i = 0; i < ptable->nparts; i++) { 70 if (j == RAW_PART) { 71 fprintf (fd, 72 "\\\n\t:p%c#%u:o%c#0:t%c=unknown:", 73 RAW_PART + 'a', ptable->secperunit, 74 RAW_PART + 'a', RAW_PART + 'a'); 75 break; 76 } 77 if (ptable->parts[i].letter == j) { 78 fprintf (fd, "\\\n\t:p%c#%u:o%c#%u:t%c=", 79 ptable->parts[i].letter + 'a', 80 ptable->parts[i].size, 81 ptable->parts[i].letter + 'a', 82 ptable->parts[i].start, 83 ptable->parts[i].letter + 'a'); 84 pid = AHDI_MKPID (ptable->parts[i].id[0], 85 ptable->parts[i].id[1], 86 ptable->parts[i].id[2]); 87 switch (pid) { 88 case AHDI_PID_NBD: 89 fprintf (fd, "4.2BSD:"); 90 break; 91 case AHDI_PID_SWP: 92 fprintf (fd, "swap:"); 93 break; 94 case AHDI_PID_GEM: 95 case AHDI_PID_BGM: 96 fprintf (fd, "MSDOS:"); 97 break; 98 default: 99 fprintf (fd, "unknown:" ); 100 } 101 todo--; 102 break; 103 } 104 } 105 j++; 106 } 107 if (j <= RAW_PART) { 108 fprintf (fd, "\\\n\t:p%c#%u:o%c#0:t%c=unknown:", 109 RAW_PART + 'a', ptable->secperunit, 110 RAW_PART + 'a', RAW_PART + 'a'); 111 } 112 fprintf (fd, "\n\n"); 113 114 fclose (fd); 115 return (1); 116 } 117