1 /* $NetBSD: printlabel.c,v 1.11 2004/02/28 18:19:00 dsl Exp $ */ 2 3 /* 4 * Copyright (c) 1987, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Symmetric Computer Systems. 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. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #include <sys/cdefs.h> 36 #ifndef lint 37 __RCSID("$NetBSD: printlabel.c,v 1.11 2004/02/28 18:19:00 dsl Exp $"); 38 #endif /* not lint */ 39 40 #include <sys/param.h> 41 42 #define DKTYPENAMES 43 #define FSTYPENAMES 44 #include <sys/disklabel.h> 45 46 #include <stdio.h> 47 48 #include "extern.h" 49 50 51 void 52 showinfo(FILE *f, struct disklabel *lp, const char *specialname) 53 { 54 int i, j; 55 56 (void)fprintf(f, "# %s:\n", specialname); 57 if ((unsigned) lp->d_type < DKMAXTYPES) 58 (void)fprintf(f, "type: %s\n", dktypenames[lp->d_type]); 59 else 60 (void)fprintf(f, "type: %d\n", lp->d_type); 61 (void)fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), 62 lp->d_typename); 63 (void)fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), 64 lp->d_packname); 65 (void)fprintf(f, "flags:"); 66 if (lp->d_flags & D_REMOVABLE) 67 (void)fprintf(f, " removable"); 68 if (lp->d_flags & D_ECC) 69 (void)fprintf(f, " ecc"); 70 if (lp->d_flags & D_BADSECT) 71 (void)fprintf(f, " badsect"); 72 (void)fprintf(f, "\n"); 73 (void)fprintf(f, "bytes/sector: %" PRIu32 "\n", lp->d_secsize); 74 (void)fprintf(f, "sectors/track: %" PRIu32 "\n", lp->d_nsectors); 75 (void)fprintf(f, "tracks/cylinder: %" PRIu32 "\n", lp->d_ntracks); 76 (void)fprintf(f, "sectors/cylinder: %" PRIu32 "\n", lp->d_secpercyl); 77 (void)fprintf(f, "cylinders: %" PRIu32 "\n", lp->d_ncylinders); 78 (void)fprintf(f, "total sectors: %" PRIu32 "\n", lp->d_secperunit); 79 (void)fprintf(f, "rpm: %" PRIu32 "\n", lp->d_rpm); 80 (void)fprintf(f, "interleave: %" PRIu32 "\n", lp->d_interleave); 81 (void)fprintf(f, "trackskew: %" PRIu32 "\n", lp->d_trackskew); 82 (void)fprintf(f, "cylinderskew: %" PRIu32 "\n", lp->d_cylskew); 83 (void)fprintf(f, "headswitch: %" PRIu32 "\t\t# microseconds\n", 84 lp->d_headswitch); 85 (void)fprintf(f, "track-to-track seek: %" PRIu32 "\t# microseconds\n", 86 lp->d_trkseek); 87 (void)fprintf(f, "drivedata: "); 88 for (i = NDDATA - 1; i >= 0; i--) 89 if (lp->d_drivedata[i]) 90 break; 91 if (i < 0) 92 i = 0; 93 for (j = 0; j <= i; j++) 94 (void)fprintf(f, "%d ", lp->d_drivedata[j]); 95 (void)fprintf(f, "\n\n"); 96 (void)fflush(f); 97 } 98 99 void 100 showpartition(FILE *f, struct disklabel *lp, int i, int ctsformat) 101 { 102 struct partition *pp = lp->d_partitions + i; 103 if (pp->p_size == 0) 104 return; 105 106 if (ctsformat && lp->d_secpercyl && lp->d_nsectors) { 107 char sbuf[64], obuf[64]; 108 109 (void)snprintf(sbuf, sizeof(sbuf), "%u/%u/%u", 110 pp->p_size/lp->d_secpercyl, 111 (pp->p_size%lp->d_secpercyl) / lp->d_nsectors, 112 pp->p_size%lp->d_nsectors); 113 114 (void)snprintf(obuf, sizeof(obuf), "%u/%u/%u", 115 pp->p_offset/lp->d_secpercyl, 116 (pp->p_offset%lp->d_secpercyl) / lp->d_nsectors, 117 pp->p_offset%lp->d_nsectors); 118 119 (void)fprintf(f, " %c: %9s %9s ", 120 'a' + i, sbuf, obuf); 121 } else { 122 (void)fprintf(f, " %c: %9u %9u ", 'a' + i, 123 pp->p_size, pp->p_offset); 124 } 125 126 if ((unsigned) pp->p_fstype < FSMAXTYPES) 127 (void)fprintf(f, "%10.10s", fstypenames[pp->p_fstype]); 128 else 129 (void)fprintf(f, "%10d", pp->p_fstype); 130 131 switch (pp->p_fstype) { 132 case FS_UNUSED: /* XXX */ 133 (void)fprintf(f, " %5u %5u %5.5s ", 134 pp->p_fsize, pp->p_fsize * pp->p_frag, ""); 135 break; 136 137 case FS_BSDFFS: 138 case FS_ADOS: 139 case FS_APPLEUFS: 140 (void)fprintf(f, " %5u %5u %5u ", 141 pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg); 142 break; 143 144 case FS_BSDLFS: 145 (void)fprintf(f, " %5u %5u %5u ", 146 pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_sgs); 147 break; 148 149 case FS_EX2FS: 150 (void)fprintf(f, " %5u %5u ", 151 pp->p_fsize, pp->p_fsize * pp->p_frag); 152 break; 153 154 case FS_ISO9660: 155 (void)fprintf(f, " %6u ", pp->p_cdsession); 156 break; 157 158 default: 159 (void)fprintf(f, "%20.20s", ""); 160 break; 161 } 162 if (lp->d_secpercyl != 0) { 163 (void)fprintf(f, " # (Cyl. %6u", 164 pp->p_offset / lp->d_secpercyl); 165 166 if (pp->p_offset > lp->d_secperunit) 167 putc('+', f); 168 else if (pp->p_offset % lp->d_secpercyl) 169 putc('*', f); 170 else 171 putc(' ', f); 172 173 (void)fprintf(f, "- %6u", 174 (pp->p_offset + 175 pp->p_size + lp->d_secpercyl - 1) / 176 lp->d_secpercyl - 1); 177 178 if ((pp->p_offset + pp->p_size) > lp->d_secperunit) 179 putc('+', f); 180 else if ((pp->p_offset + pp->p_size) % lp->d_secpercyl) 181 putc('*', f); 182 183 (void)fprintf(f, ")\n"); 184 } else 185 (void)fprintf(f, "\n"); 186 } 187 188 void 189 showpartitions(FILE *f, struct disklabel *lp, int ctsformat) 190 { 191 int i; 192 193 (void)fprintf(f, "%d partitions:\n", lp->d_npartitions); 194 (void)fprintf(f, 195 "# size offset fstype [fsize bsize cpg/sgs]\n"); 196 197 for (i = 0; i < lp->d_npartitions; i++) 198 showpartition(f, lp, i, ctsformat); 199 (void)fflush(f); 200 } 201