printlabel.c revision 1.9 1 /* $NetBSD: printlabel.c,v 1.9 2003/10/20 13:10:48 pooka 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.9 2003/10/20 13:10:48 pooka 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: %ld\n", (long) lp->d_secsize);
74 (void)fprintf(f, "sectors/track: %ld\n", (long) lp->d_nsectors);
75 (void)fprintf(f, "tracks/cylinder: %ld\n", (long) lp->d_ntracks);
76 (void)fprintf(f, "sectors/cylinder: %ld\n", (long) lp->d_secpercyl);
77 (void)fprintf(f, "cylinders: %ld\n", (long) lp->d_ncylinders);
78 (void)fprintf(f, "total sectors: %ld\n", (long) lp->d_secperunit);
79 (void)fprintf(f, "rpm: %ld\n", (long) lp->d_rpm);
80 (void)fprintf(f, "interleave: %ld\n", (long) lp->d_interleave);
81 (void)fprintf(f, "trackskew: %ld\n", (long) lp->d_trackskew);
82 (void)fprintf(f, "cylinderskew: %ld\n", (long) lp->d_cylskew);
83 (void)fprintf(f, "headswitch: %ld\t\t# microseconds\n",
84 (long)lp->d_headswitch);
85 (void)fprintf(f, "track-to-track seek: %ld\t# microseconds\n",
86 (long)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, " %5d %5d %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, " %5d %5d %5d ",
141 pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg);
142 break;
143
144 case FS_BSDLFS:
145 (void)fprintf(f, " %5d %5d %5d ",
146 pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_sgs);
147 break;
148
149 case FS_EX2FS:
150 (void)fprintf(f, " %5d %5d ",
151 pp->p_fsize, pp->p_fsize * pp->p_frag);
152 break;
153
154 case FS_ISO9660:
155 (void)fprintf(f, " %6d ", 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_secpercyl)
167 putc('*', f);
168 else
169 putc(' ', f);
170
171 (void)fprintf(f, "- %6u",
172 (pp->p_offset +
173 pp->p_size + lp->d_secpercyl - 1) /
174 lp->d_secpercyl - 1);
175
176 if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
177 putc('*', f);
178
179 (void)fprintf(f, ")\n");
180 } else
181 (void)fprintf(f, "\n");
182 }
183
184 void
185 showpartitions(FILE *f, struct disklabel *lp, int ctsformat)
186 {
187 int i;
188
189 (void)fprintf(f, "%d partitions:\n", lp->d_npartitions);
190 (void)fprintf(f,
191 "# size offset fstype [fsize bsize cpg/sgs]\n");
192
193 for (i = 0; i < lp->d_npartitions; i++)
194 showpartition(f, lp, i, ctsformat);
195 (void)fflush(f);
196 }
197