Home | History | Annotate | Line # | Download | only in disklabel
printlabel.c revision 1.3
      1  1.3     lukem /*	$NetBSD: printlabel.c,v 1.3 2001/10/19 01:16:38 lukem 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.1     lukem  * 3. All advertising materials mentioning features or use of this software
     19  1.1     lukem  *    must display the following acknowledgement:
     20  1.1     lukem  *	This product includes software developed by the University of
     21  1.1     lukem  *	California, Berkeley and its contributors.
     22  1.1     lukem  * 4. Neither the name of the University nor the names of its contributors
     23  1.1     lukem  *    may be used to endorse or promote products derived from this software
     24  1.1     lukem  *    without specific prior written permission.
     25  1.1     lukem  *
     26  1.1     lukem  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1     lukem  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1     lukem  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1     lukem  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1     lukem  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1     lukem  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1     lukem  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1     lukem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1     lukem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1     lukem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1     lukem  * SUCH DAMAGE.
     37  1.1     lukem  */
     38  1.1     lukem 
     39  1.1     lukem #include <sys/cdefs.h>
     40  1.1     lukem #ifndef lint
     41  1.3     lukem __RCSID("$NetBSD: printlabel.c,v 1.3 2001/10/19 01:16:38 lukem 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.1     lukem #include <sys/disklabel.h>
     49  1.1     lukem 
     50  1.1     lukem #include <stdio.h>
     51  1.1     lukem 
     52  1.1     lukem #include "extern.h"
     53  1.1     lukem 
     54  1.1     lukem 
     55  1.1     lukem void
     56  1.3     lukem showinfo(FILE *f, struct disklabel *lp, const char *specialname)
     57  1.1     lukem {
     58  1.1     lukem 	int	i, j;
     59  1.1     lukem 
     60  1.3     lukem 	(void)fprintf(f, "# %s:\n", specialname);
     61  1.1     lukem 	if ((unsigned) lp->d_type < DKMAXTYPES)
     62  1.2  christos 		(void)fprintf(f, "type: %s\n", dktypenames[lp->d_type]);
     63  1.1     lukem 	else
     64  1.2  christos 		(void)fprintf(f, "type: %d\n", lp->d_type);
     65  1.2  christos 	(void)fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename),
     66  1.1     lukem 	    lp->d_typename);
     67  1.2  christos 	(void)fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname),
     68  1.1     lukem 	    lp->d_packname);
     69  1.2  christos 	(void)fprintf(f, "flags:");
     70  1.1     lukem 	if (lp->d_flags & D_REMOVABLE)
     71  1.2  christos 		(void)fprintf(f, " removable");
     72  1.1     lukem 	if (lp->d_flags & D_ECC)
     73  1.2  christos 		(void)fprintf(f, " ecc");
     74  1.1     lukem 	if (lp->d_flags & D_BADSECT)
     75  1.2  christos 		(void)fprintf(f, " badsect");
     76  1.2  christos 	(void)fprintf(f, "\n");
     77  1.2  christos 	(void)fprintf(f, "bytes/sector: %ld\n", (long) lp->d_secsize);
     78  1.2  christos 	(void)fprintf(f, "sectors/track: %ld\n", (long) lp->d_nsectors);
     79  1.2  christos 	(void)fprintf(f, "tracks/cylinder: %ld\n", (long) lp->d_ntracks);
     80  1.2  christos 	(void)fprintf(f, "sectors/cylinder: %ld\n", (long) lp->d_secpercyl);
     81  1.2  christos 	(void)fprintf(f, "cylinders: %ld\n", (long) lp->d_ncylinders);
     82  1.2  christos 	(void)fprintf(f, "total sectors: %ld\n", (long) lp->d_secperunit);
     83  1.2  christos 	(void)fprintf(f, "rpm: %ld\n", (long) lp->d_rpm);
     84  1.2  christos 	(void)fprintf(f, "interleave: %ld\n", (long) lp->d_interleave);
     85  1.2  christos 	(void)fprintf(f, "trackskew: %ld\n", (long) lp->d_trackskew);
     86  1.2  christos 	(void)fprintf(f, "cylinderskew: %ld\n", (long) lp->d_cylskew);
     87  1.2  christos 	(void)fprintf(f, "headswitch: %ld\t\t# microseconds\n",
     88  1.2  christos 	    (long)lp->d_headswitch);
     89  1.2  christos 	(void)fprintf(f, "track-to-track seek: %ld\t# microseconds\n",
     90  1.2  christos 	    (long)lp->d_trkseek);
     91  1.2  christos 	(void)fprintf(f, "drivedata: ");
     92  1.1     lukem 	for (i = NDDATA - 1; i >= 0; i--)
     93  1.1     lukem 		if (lp->d_drivedata[i])
     94  1.1     lukem 			break;
     95  1.1     lukem 	if (i < 0)
     96  1.1     lukem 		i = 0;
     97  1.1     lukem 	for (j = 0; j <= i; j++)
     98  1.2  christos 		(void)fprintf(f, "%d ", lp->d_drivedata[j]);
     99  1.2  christos 	(void)fprintf(f, "\n\n");
    100  1.2  christos 	(void)fflush(f);
    101  1.2  christos }
    102  1.2  christos 
    103  1.2  christos void
    104  1.2  christos showpartition(FILE *f, struct disklabel *lp, int i, int ctsformat)
    105  1.2  christos {
    106  1.2  christos 	struct partition *pp = lp->d_partitions + i;
    107  1.2  christos 	if (pp->p_size == 0)
    108  1.2  christos 		return;
    109  1.2  christos 
    110  1.2  christos 	if (ctsformat && lp->d_secpercyl && lp->d_nsectors) {
    111  1.2  christos 		char sbuf[64], obuf[64];
    112  1.2  christos 
    113  1.2  christos 		(void)snprintf(sbuf, sizeof(sbuf), "%d/%d/%d",
    114  1.2  christos 		    pp->p_size/lp->d_secpercyl,
    115  1.2  christos 		    (pp->p_size%lp->d_secpercyl) / lp->d_nsectors,
    116  1.2  christos 		    pp->p_size%lp->d_nsectors);
    117  1.2  christos 
    118  1.2  christos 		(void)snprintf(obuf, sizeof(obuf), "%d/%d/%d",
    119  1.2  christos 		    pp->p_offset/lp->d_secpercyl,
    120  1.2  christos 		    (pp->p_offset%lp->d_secpercyl) / lp->d_nsectors,
    121  1.2  christos 		    pp->p_offset%lp->d_nsectors);
    122  1.2  christos 
    123  1.2  christos 		(void)fprintf(f, " %c: %9s %9s ",
    124  1.2  christos 		    'a' + i, sbuf, obuf);
    125  1.2  christos 	} else {
    126  1.2  christos 		(void)fprintf(f, " %c: %9d %9d ", 'a' + i,
    127  1.2  christos 		    pp->p_size, pp->p_offset);
    128  1.2  christos 	}
    129  1.2  christos 
    130  1.2  christos 	if ((unsigned) pp->p_fstype < FSMAXTYPES)
    131  1.2  christos 		(void)fprintf(f, "%10.10s", fstypenames[pp->p_fstype]);
    132  1.2  christos 	else
    133  1.2  christos 		(void)fprintf(f, "%10d", pp->p_fstype);
    134  1.2  christos 
    135  1.2  christos 	switch (pp->p_fstype) {
    136  1.2  christos 	case FS_UNUSED:				/* XXX */
    137  1.2  christos 		(void)fprintf(f, "  %5d %5d %5.5s ",
    138  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, "");
    139  1.2  christos 		break;
    140  1.2  christos 
    141  1.2  christos 	case FS_BSDFFS:
    142  1.2  christos 	case FS_ADOS:
    143  1.2  christos 		(void)fprintf(f, "  %5d %5d %5d ",
    144  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg);
    145  1.2  christos 		break;
    146  1.2  christos 
    147  1.2  christos 	case FS_BSDLFS:
    148  1.2  christos 		(void)fprintf(f, "  %5d %5d %5d ",
    149  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_sgs);
    150  1.2  christos 		break;
    151  1.2  christos 
    152  1.2  christos 	case FS_EX2FS:
    153  1.2  christos 		(void)fprintf(f, "  %5d %5d       ",
    154  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag);
    155  1.2  christos 		break;
    156  1.2  christos 
    157  1.2  christos 	default:
    158  1.2  christos 		(void)fprintf(f, "%20.20s", "");
    159  1.2  christos 		break;
    160  1.2  christos 	}
    161  1.2  christos 	if (lp->d_secpercyl != 0) {
    162  1.2  christos 		(void)fprintf(f, "  # (Cyl. %4d",
    163  1.2  christos 		    pp->p_offset / lp->d_secpercyl);
    164  1.2  christos 
    165  1.2  christos 		if (pp->p_offset % lp->d_secpercyl)
    166  1.2  christos 		    putc('*', f);
    167  1.2  christos 		else
    168  1.2  christos 		    putc(' ', f);
    169  1.2  christos 
    170  1.2  christos 		(void)fprintf(f, "- %d",
    171  1.2  christos 		    (pp->p_offset +
    172  1.2  christos 		    pp->p_size + lp->d_secpercyl - 1) /
    173  1.2  christos 		    lp->d_secpercyl - 1);
    174  1.2  christos 
    175  1.2  christos 		if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
    176  1.2  christos 		    putc('*', f);
    177  1.2  christos 
    178  1.2  christos 		(void)fprintf(f, ")\n");
    179  1.2  christos 	} else
    180  1.2  christos 		(void)fprintf(f, "\n");
    181  1.1     lukem }
    182  1.1     lukem 
    183  1.1     lukem void
    184  1.1     lukem showpartitions(FILE *f, struct disklabel *lp, int ctsformat)
    185  1.1     lukem {
    186  1.1     lukem 	int	i;
    187  1.1     lukem 
    188  1.2  christos 	(void)fprintf(f, "%d partitions:\n", lp->d_npartitions);
    189  1.2  christos 	(void)fprintf(f,
    190  1.2  christos 	    "#        size    offset     fstype  [fsize bsize cpg/sgs]\n");
    191  1.2  christos 
    192  1.2  christos 	for (i = 0; i < lp->d_npartitions; i++)
    193  1.2  christos 		showpartition(f, lp, i, ctsformat);
    194  1.2  christos 	(void)fflush(f);
    195  1.1     lukem }
    196