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