1 /* $NetBSD: printlabel.c,v 1.14 2005/08/27 23:34:52 uwe Exp $ */
4 * Copyright (c) 1987, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Symmetric Computer Systems.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
35 #if HAVE_NBTOOL_CONFIG_H
36 #include "nbtool_config.h"
39 #include <sys/cdefs.h>
41 __RCSID("$NetBSD: printlabel.c,v 1.14 2005/08/27 23:34:52 uwe Exp $");
44 #include <sys/param.h>
48 #if HAVE_NBTOOL_CONFIG_H
49 #include <nbinclude/sys/disklabel.h>
51 #include <sys/disklabel.h>
52 #endif /* HAVE_NBTOOL_CONFIG_H */
60 showinfo(FILE *f
, struct disklabel
*lp
, const char *specialname
)
64 (void)fprintf(f
, "# %s:\n", specialname
);
65 if ((unsigned) lp
->d_type
< DKMAXTYPES
)
66 (void)fprintf(f
, "type: %s\n", dktypenames
[lp
->d_type
]);
68 (void)fprintf(f
, "type: %d\n", lp
->d_type
);
69 (void)fprintf(f
, "disk: %.*s\n", (int) sizeof(lp
->d_typename
),
71 (void)fprintf(f
, "label: %.*s\n", (int) sizeof(lp
->d_packname
),
73 (void)fprintf(f
, "flags:");
74 if (lp
->d_flags
& D_REMOVABLE
)
75 (void)fprintf(f
, " removable");
76 if (lp
->d_flags
& D_ECC
)
77 (void)fprintf(f
, " ecc");
78 if (lp
->d_flags
& D_BADSECT
)
79 (void)fprintf(f
, " badsect");
80 (void)fprintf(f
, "\n");
81 (void)fprintf(f
, "bytes/sector: %" PRIu32
"\n", lp
->d_secsize
);
82 (void)fprintf(f
, "sectors/track: %" PRIu32
"\n", lp
->d_nsectors
);
83 (void)fprintf(f
, "tracks/cylinder: %" PRIu32
"\n", lp
->d_ntracks
);
84 (void)fprintf(f
, "sectors/cylinder: %" PRIu32
"\n", lp
->d_secpercyl
);
85 (void)fprintf(f
, "cylinders: %" PRIu32
"\n", lp
->d_ncylinders
);
86 (void)fprintf(f
, "total sectors: %" PRIu32
"\n", lp
->d_secperunit
);
87 (void)fprintf(f
, "rpm: %" PRIu32
"\n", lp
->d_rpm
);
88 (void)fprintf(f
, "interleave: %" PRIu32
"\n", lp
->d_interleave
);
89 (void)fprintf(f
, "trackskew: %" PRIu32
"\n", lp
->d_trackskew
);
90 (void)fprintf(f
, "cylinderskew: %" PRIu32
"\n", lp
->d_cylskew
);
91 (void)fprintf(f
, "headswitch: %" PRIu32
"\t\t# microseconds\n",
93 (void)fprintf(f
, "track-to-track seek: %" PRIu32
"\t# microseconds\n",
95 (void)fprintf(f
, "drivedata: ");
96 for (i
= NDDATA
- 1; i
>= 0; i
--)
97 if (lp
->d_drivedata
[i
])
101 for (j
= 0; j
<= i
; j
++)
102 (void)fprintf(f
, "%d ", lp
->d_drivedata
[j
]);
103 (void)fprintf(f
, "\n\n");
108 showpartition(FILE *f
, struct disklabel
*lp
, int i
, int ctsformat
)
110 struct partition
*pp
= lp
->d_partitions
+ i
;
114 if (ctsformat
&& lp
->d_secpercyl
&& lp
->d_nsectors
) {
115 char sbuf
[64], obuf
[64];
117 (void)snprintf(sbuf
, sizeof(sbuf
), "%u/%u/%u",
118 pp
->p_size
/lp
->d_secpercyl
,
119 (pp
->p_size
%lp
->d_secpercyl
) / lp
->d_nsectors
,
120 pp
->p_size
%lp
->d_nsectors
);
122 (void)snprintf(obuf
, sizeof(obuf
), "%u/%u/%u",
123 pp
->p_offset
/lp
->d_secpercyl
,
124 (pp
->p_offset
%lp
->d_secpercyl
) / lp
->d_nsectors
,
125 pp
->p_offset
%lp
->d_nsectors
);
127 (void)fprintf(f
, " %c: %9s %9s ",
128 'a' + i
, sbuf
, obuf
);
130 (void)fprintf(f
, " %c: %9u %9u ", 'a' + i
,
131 pp
->p_size
, pp
->p_offset
);
134 if ((unsigned) pp
->p_fstype
< FSMAXTYPES
)
135 (void)fprintf(f
, "%10.10s", fstypenames
[pp
->p_fstype
]);
137 (void)fprintf(f
, "%10d", pp
->p_fstype
);
139 switch (pp
->p_fstype
) {
140 case FS_UNUSED
: /* XXX */
141 (void)fprintf(f
, " %5u %5u %5.5s ",
142 pp
->p_fsize
, pp
->p_fsize
* pp
->p_frag
, "");
148 (void)fprintf(f
, " %5u %5u %5u ",
149 pp
->p_fsize
, pp
->p_fsize
* pp
->p_frag
, pp
->p_cpg
);
153 (void)fprintf(f
, " %5u %5u %5u ",
154 pp
->p_fsize
, pp
->p_fsize
* pp
->p_frag
, pp
->p_sgs
);
158 (void)fprintf(f
, " %5u %5u ",
159 pp
->p_fsize
, pp
->p_fsize
* pp
->p_frag
);
163 (void)fprintf(f
, " %6u ", pp
->p_cdsession
);
167 (void)fprintf(f
, "%20.20s", "");
170 if (lp
->d_secpercyl
!= 0) {
171 (void)fprintf(f
, " # (Cyl. %6u",
172 pp
->p_offset
/ lp
->d_secpercyl
);
174 if (pp
->p_offset
> lp
->d_secperunit
)
176 else if (pp
->p_offset
% lp
->d_secpercyl
)
181 (void)fprintf(f
, "- %6u",
183 pp
->p_size
+ lp
->d_secpercyl
- 1) /
184 lp
->d_secpercyl
- 1);
186 if ((pp
->p_offset
+ pp
->p_size
) > lp
->d_secperunit
)
188 else if ((pp
->p_offset
+ pp
->p_size
) % lp
->d_secpercyl
)
191 (void)fprintf(f
, ")\n");
193 (void)fprintf(f
, "\n");
197 showpartitions(FILE *f
, struct disklabel
*lp
, int ctsformat
)
201 (void)fprintf(f
, "%d partitions:\n", lp
->d_npartitions
);
203 "# size offset fstype [fsize bsize cpg/sgs]\n");
205 for (i
= 0; i
< lp
->d_npartitions
; i
++)
206 showpartition(f
, lp
, i
, ctsformat
);