2005-08-28 03:34:52 +04:00
|
|
|
/* $NetBSD: printlabel.c,v 1.14 2005/08/27 23:34:52 uwe Exp $ */
|
2000-12-24 10:08:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1987, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Symmetric Computer Systems.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 14:04:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-12-24 10:08:02 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2005-06-12 23:18:34 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-12-24 10:08:02 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2005-08-28 03:34:52 +04:00
|
|
|
__RCSID("$NetBSD: printlabel.c,v 1.14 2005/08/27 23:34:52 uwe Exp $");
|
2000-12-24 10:08:02 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#define DKTYPENAMES
|
|
|
|
#define FSTYPENAMES
|
2005-06-12 23:18:34 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include <nbinclude/sys/disklabel.h>
|
2005-08-28 02:38:02 +04:00
|
|
|
#ifndef PRIu32
|
2005-08-28 03:34:52 +04:00
|
|
|
#define PRIu32 "u"
|
2005-08-28 02:38:02 +04:00
|
|
|
#endif
|
2005-06-12 23:18:34 +04:00
|
|
|
#else
|
2000-12-24 10:08:02 +03:00
|
|
|
#include <sys/disklabel.h>
|
2005-06-12 23:18:34 +04:00
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
2000-12-24 10:08:02 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-10-19 05:16:37 +04:00
|
|
|
showinfo(FILE *f, struct disklabel *lp, const char *specialname)
|
2000-12-24 10:08:02 +03:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2001-10-19 05:16:37 +04:00
|
|
|
(void)fprintf(f, "# %s:\n", specialname);
|
2000-12-24 10:08:02 +03:00
|
|
|
if ((unsigned) lp->d_type < DKMAXTYPES)
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, "type: %s\n", dktypenames[lp->d_type]);
|
2000-12-24 10:08:02 +03:00
|
|
|
else
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, "type: %d\n", lp->d_type);
|
|
|
|
(void)fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename),
|
2000-12-24 10:08:02 +03:00
|
|
|
lp->d_typename);
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname),
|
2000-12-24 10:08:02 +03:00
|
|
|
lp->d_packname);
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, "flags:");
|
2000-12-24 10:08:02 +03:00
|
|
|
if (lp->d_flags & D_REMOVABLE)
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, " removable");
|
2000-12-24 10:08:02 +03:00
|
|
|
if (lp->d_flags & D_ECC)
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, " ecc");
|
2000-12-24 10:08:02 +03:00
|
|
|
if (lp->d_flags & D_BADSECT)
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, " badsect");
|
|
|
|
(void)fprintf(f, "\n");
|
2004-02-28 21:19:00 +03:00
|
|
|
(void)fprintf(f, "bytes/sector: %" PRIu32 "\n", lp->d_secsize);
|
|
|
|
(void)fprintf(f, "sectors/track: %" PRIu32 "\n", lp->d_nsectors);
|
|
|
|
(void)fprintf(f, "tracks/cylinder: %" PRIu32 "\n", lp->d_ntracks);
|
|
|
|
(void)fprintf(f, "sectors/cylinder: %" PRIu32 "\n", lp->d_secpercyl);
|
|
|
|
(void)fprintf(f, "cylinders: %" PRIu32 "\n", lp->d_ncylinders);
|
|
|
|
(void)fprintf(f, "total sectors: %" PRIu32 "\n", lp->d_secperunit);
|
|
|
|
(void)fprintf(f, "rpm: %" PRIu32 "\n", lp->d_rpm);
|
|
|
|
(void)fprintf(f, "interleave: %" PRIu32 "\n", lp->d_interleave);
|
|
|
|
(void)fprintf(f, "trackskew: %" PRIu32 "\n", lp->d_trackskew);
|
|
|
|
(void)fprintf(f, "cylinderskew: %" PRIu32 "\n", lp->d_cylskew);
|
|
|
|
(void)fprintf(f, "headswitch: %" PRIu32 "\t\t# microseconds\n",
|
|
|
|
lp->d_headswitch);
|
|
|
|
(void)fprintf(f, "track-to-track seek: %" PRIu32 "\t# microseconds\n",
|
|
|
|
lp->d_trkseek);
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, "drivedata: ");
|
2000-12-24 10:08:02 +03:00
|
|
|
for (i = NDDATA - 1; i >= 0; i--)
|
|
|
|
if (lp->d_drivedata[i])
|
|
|
|
break;
|
|
|
|
if (i < 0)
|
|
|
|
i = 0;
|
|
|
|
for (j = 0; j <= i; j++)
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)fprintf(f, "%d ", lp->d_drivedata[j]);
|
|
|
|
(void)fprintf(f, "\n\n");
|
|
|
|
(void)fflush(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
showpartition(FILE *f, struct disklabel *lp, int i, int ctsformat)
|
|
|
|
{
|
|
|
|
struct partition *pp = lp->d_partitions + i;
|
|
|
|
if (pp->p_size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ctsformat && lp->d_secpercyl && lp->d_nsectors) {
|
|
|
|
char sbuf[64], obuf[64];
|
|
|
|
|
2003-10-20 17:10:48 +04:00
|
|
|
(void)snprintf(sbuf, sizeof(sbuf), "%u/%u/%u",
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_size/lp->d_secpercyl,
|
|
|
|
(pp->p_size%lp->d_secpercyl) / lp->d_nsectors,
|
|
|
|
pp->p_size%lp->d_nsectors);
|
|
|
|
|
2003-10-20 17:10:48 +04:00
|
|
|
(void)snprintf(obuf, sizeof(obuf), "%u/%u/%u",
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_offset/lp->d_secpercyl,
|
|
|
|
(pp->p_offset%lp->d_secpercyl) / lp->d_nsectors,
|
|
|
|
pp->p_offset%lp->d_nsectors);
|
|
|
|
|
|
|
|
(void)fprintf(f, " %c: %9s %9s ",
|
|
|
|
'a' + i, sbuf, obuf);
|
|
|
|
} else {
|
2003-10-20 17:10:48 +04:00
|
|
|
(void)fprintf(f, " %c: %9u %9u ", 'a' + i,
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_size, pp->p_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unsigned) pp->p_fstype < FSMAXTYPES)
|
|
|
|
(void)fprintf(f, "%10.10s", fstypenames[pp->p_fstype]);
|
|
|
|
else
|
|
|
|
(void)fprintf(f, "%10d", pp->p_fstype);
|
|
|
|
|
|
|
|
switch (pp->p_fstype) {
|
|
|
|
case FS_UNUSED: /* XXX */
|
2004-02-28 21:19:00 +03:00
|
|
|
(void)fprintf(f, " %5u %5u %5.5s ",
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_fsize, pp->p_fsize * pp->p_frag, "");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS_BSDFFS:
|
|
|
|
case FS_ADOS:
|
2002-09-28 04:47:24 +04:00
|
|
|
case FS_APPLEUFS:
|
2004-02-28 21:19:00 +03:00
|
|
|
(void)fprintf(f, " %5u %5u %5u ",
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS_BSDLFS:
|
2004-02-28 21:19:00 +03:00
|
|
|
(void)fprintf(f, " %5u %5u %5u ",
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_sgs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS_EX2FS:
|
2004-02-28 21:19:00 +03:00
|
|
|
(void)fprintf(f, " %5u %5u ",
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_fsize, pp->p_fsize * pp->p_frag);
|
|
|
|
break;
|
|
|
|
|
2002-05-27 21:33:08 +04:00
|
|
|
case FS_ISO9660:
|
2004-02-28 21:19:00 +03:00
|
|
|
(void)fprintf(f, " %6u ", pp->p_cdsession);
|
2002-05-27 21:33:08 +04:00
|
|
|
break;
|
|
|
|
|
2001-05-26 23:48:32 +04:00
|
|
|
default:
|
|
|
|
(void)fprintf(f, "%20.20s", "");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (lp->d_secpercyl != 0) {
|
2003-10-20 17:10:48 +04:00
|
|
|
(void)fprintf(f, " # (Cyl. %6u",
|
2001-05-26 23:48:32 +04:00
|
|
|
pp->p_offset / lp->d_secpercyl);
|
|
|
|
|
2003-12-29 22:13:19 +03:00
|
|
|
if (pp->p_offset > lp->d_secperunit)
|
|
|
|
putc('+', f);
|
|
|
|
else if (pp->p_offset % lp->d_secpercyl)
|
2001-05-26 23:48:32 +04:00
|
|
|
putc('*', f);
|
|
|
|
else
|
|
|
|
putc(' ', f);
|
|
|
|
|
2003-10-20 17:10:48 +04:00
|
|
|
(void)fprintf(f, "- %6u",
|
2001-05-26 23:48:32 +04:00
|
|
|
(pp->p_offset +
|
|
|
|
pp->p_size + lp->d_secpercyl - 1) /
|
|
|
|
lp->d_secpercyl - 1);
|
|
|
|
|
2003-12-29 22:13:19 +03:00
|
|
|
if ((pp->p_offset + pp->p_size) > lp->d_secperunit)
|
|
|
|
putc('+', f);
|
|
|
|
else if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
|
2001-05-26 23:48:32 +04:00
|
|
|
putc('*', f);
|
|
|
|
|
|
|
|
(void)fprintf(f, ")\n");
|
|
|
|
} else
|
|
|
|
(void)fprintf(f, "\n");
|
2000-12-24 10:08:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
showpartitions(FILE *f, struct disklabel *lp, int ctsformat)
|
|
|
|
{
|
|
|
|
int i;
|
2001-05-26 23:48:32 +04:00
|
|
|
|
|
|
|
(void)fprintf(f, "%d partitions:\n", lp->d_npartitions);
|
|
|
|
(void)fprintf(f,
|
2003-08-04 21:14:50 +04:00
|
|
|
"# size offset fstype [fsize bsize cpg/sgs]\n");
|
2001-05-26 23:48:32 +04:00
|
|
|
|
|
|
|
for (i = 0; i < lp->d_npartitions; i++)
|
|
|
|
showpartition(f, lp, i, ctsformat);
|
|
|
|
(void)fflush(f);
|
2000-12-24 10:08:02 +03:00
|
|
|
}
|