Home | History | Annotate | Line # | Download | only in disklabel
printlabel.c revision 1.12
      1  1.12    dyoung /*	$NetBSD: printlabel.c,v 1.12 2005/06/12 19:18:34 dyoung 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.12    dyoung __RCSID("$NetBSD: printlabel.c,v 1.12 2005/06/12 19:18:34 dyoung 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.2  christos 		(void)fprintf(f, "type: %d\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.2  christos 		(void)fprintf(f, "%d ", 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.9     pooka 		(void)snprintf(sbuf, sizeof(sbuf), "%u/%u/%u",
    118   1.2  christos 		    pp->p_size/lp->d_secpercyl,
    119   1.2  christos 		    (pp->p_size%lp->d_secpercyl) / lp->d_nsectors,
    120   1.2  christos 		    pp->p_size%lp->d_nsectors);
    121   1.2  christos 
    122   1.9     pooka 		(void)snprintf(obuf, sizeof(obuf), "%u/%u/%u",
    123   1.2  christos 		    pp->p_offset/lp->d_secpercyl,
    124   1.2  christos 		    (pp->p_offset%lp->d_secpercyl) / lp->d_nsectors,
    125   1.2  christos 		    pp->p_offset%lp->d_nsectors);
    126   1.2  christos 
    127   1.2  christos 		(void)fprintf(f, " %c: %9s %9s ",
    128   1.2  christos 		    'a' + i, sbuf, obuf);
    129   1.2  christos 	} else {
    130   1.9     pooka 		(void)fprintf(f, " %c: %9u %9u ", 'a' + i,
    131   1.2  christos 		    pp->p_size, pp->p_offset);
    132   1.2  christos 	}
    133   1.2  christos 
    134   1.2  christos 	if ((unsigned) pp->p_fstype < FSMAXTYPES)
    135   1.2  christos 		(void)fprintf(f, "%10.10s", fstypenames[pp->p_fstype]);
    136   1.2  christos 	else
    137   1.2  christos 		(void)fprintf(f, "%10d", pp->p_fstype);
    138   1.2  christos 
    139   1.2  christos 	switch (pp->p_fstype) {
    140   1.2  christos 	case FS_UNUSED:				/* XXX */
    141  1.11       dsl 		(void)fprintf(f, "  %5u %5u %5.5s ",
    142   1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, "");
    143   1.2  christos 		break;
    144   1.2  christos 
    145   1.2  christos 	case FS_BSDFFS:
    146   1.2  christos 	case FS_ADOS:
    147   1.5       dbj 	case FS_APPLEUFS:
    148  1.11       dsl 		(void)fprintf(f, "  %5u %5u %5u ",
    149   1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg);
    150   1.2  christos 		break;
    151   1.2  christos 
    152   1.2  christos 	case FS_BSDLFS:
    153  1.11       dsl 		(void)fprintf(f, "  %5u %5u %5u ",
    154   1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_sgs);
    155   1.2  christos 		break;
    156   1.2  christos 
    157   1.2  christos 	case FS_EX2FS:
    158  1.11       dsl 		(void)fprintf(f, "  %5u %5u       ",
    159   1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag);
    160   1.4  drochner 		break;
    161   1.4  drochner 
    162   1.4  drochner 	case FS_ISO9660:
    163  1.11       dsl 		(void)fprintf(f, "  %6u            ", pp->p_cdsession);
    164   1.2  christos 		break;
    165   1.2  christos 
    166   1.2  christos 	default:
    167   1.2  christos 		(void)fprintf(f, "%20.20s", "");
    168   1.2  christos 		break;
    169   1.2  christos 	}
    170   1.2  christos 	if (lp->d_secpercyl != 0) {
    171   1.9     pooka 		(void)fprintf(f, " # (Cyl. %6u",
    172   1.2  christos 		    pp->p_offset / lp->d_secpercyl);
    173   1.2  christos 
    174  1.10       jdc 		if (pp->p_offset > lp->d_secperunit)
    175  1.10       jdc 		    putc('+', f);
    176  1.10       jdc 		else if (pp->p_offset % lp->d_secpercyl)
    177   1.2  christos 		    putc('*', f);
    178   1.2  christos 		else
    179   1.2  christos 		    putc(' ', f);
    180   1.2  christos 
    181   1.9     pooka 		(void)fprintf(f, "- %6u",
    182   1.2  christos 		    (pp->p_offset +
    183   1.2  christos 		    pp->p_size + lp->d_secpercyl - 1) /
    184   1.2  christos 		    lp->d_secpercyl - 1);
    185   1.2  christos 
    186  1.10       jdc 		if ((pp->p_offset + pp->p_size) > lp->d_secperunit)
    187  1.10       jdc 		    putc('+', f);
    188  1.10       jdc 		else if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
    189   1.2  christos 		    putc('*', f);
    190   1.2  christos 
    191   1.2  christos 		(void)fprintf(f, ")\n");
    192   1.2  christos 	} else
    193   1.2  christos 		(void)fprintf(f, "\n");
    194   1.1     lukem }
    195   1.1     lukem 
    196   1.1     lukem void
    197   1.1     lukem showpartitions(FILE *f, struct disklabel *lp, int ctsformat)
    198   1.1     lukem {
    199   1.1     lukem 	int	i;
    200   1.1     lukem 
    201   1.2  christos 	(void)fprintf(f, "%d partitions:\n", lp->d_npartitions);
    202   1.2  christos 	(void)fprintf(f,
    203   1.7       dsl 	    "#        size    offset     fstype [fsize bsize cpg/sgs]\n");
    204   1.2  christos 
    205   1.2  christos 	for (i = 0; i < lp->d_npartitions; i++)
    206   1.2  christos 		showpartition(f, lp, i, ctsformat);
    207   1.2  christos 	(void)fflush(f);
    208   1.1     lukem }
    209