Home | History | Annotate | Line # | Download | only in disklabel
printlabel.c revision 1.9
      1  1.9     pooka /*	$NetBSD: printlabel.c,v 1.9 2003/10/20 13:10:48 pooka 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.1     lukem #include <sys/cdefs.h>
     36  1.1     lukem #ifndef lint
     37  1.9     pooka __RCSID("$NetBSD: printlabel.c,v 1.9 2003/10/20 13:10:48 pooka Exp $");
     38  1.1     lukem #endif	/* not lint */
     39  1.1     lukem 
     40  1.1     lukem #include <sys/param.h>
     41  1.1     lukem 
     42  1.1     lukem #define DKTYPENAMES
     43  1.1     lukem #define FSTYPENAMES
     44  1.1     lukem #include <sys/disklabel.h>
     45  1.1     lukem 
     46  1.1     lukem #include <stdio.h>
     47  1.1     lukem 
     48  1.1     lukem #include "extern.h"
     49  1.1     lukem 
     50  1.1     lukem 
     51  1.1     lukem void
     52  1.3     lukem showinfo(FILE *f, struct disklabel *lp, const char *specialname)
     53  1.1     lukem {
     54  1.1     lukem 	int	i, j;
     55  1.1     lukem 
     56  1.3     lukem 	(void)fprintf(f, "# %s:\n", specialname);
     57  1.1     lukem 	if ((unsigned) lp->d_type < DKMAXTYPES)
     58  1.2  christos 		(void)fprintf(f, "type: %s\n", dktypenames[lp->d_type]);
     59  1.1     lukem 	else
     60  1.2  christos 		(void)fprintf(f, "type: %d\n", lp->d_type);
     61  1.2  christos 	(void)fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename),
     62  1.1     lukem 	    lp->d_typename);
     63  1.2  christos 	(void)fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname),
     64  1.1     lukem 	    lp->d_packname);
     65  1.2  christos 	(void)fprintf(f, "flags:");
     66  1.1     lukem 	if (lp->d_flags & D_REMOVABLE)
     67  1.2  christos 		(void)fprintf(f, " removable");
     68  1.1     lukem 	if (lp->d_flags & D_ECC)
     69  1.2  christos 		(void)fprintf(f, " ecc");
     70  1.1     lukem 	if (lp->d_flags & D_BADSECT)
     71  1.2  christos 		(void)fprintf(f, " badsect");
     72  1.2  christos 	(void)fprintf(f, "\n");
     73  1.2  christos 	(void)fprintf(f, "bytes/sector: %ld\n", (long) lp->d_secsize);
     74  1.2  christos 	(void)fprintf(f, "sectors/track: %ld\n", (long) lp->d_nsectors);
     75  1.2  christos 	(void)fprintf(f, "tracks/cylinder: %ld\n", (long) lp->d_ntracks);
     76  1.2  christos 	(void)fprintf(f, "sectors/cylinder: %ld\n", (long) lp->d_secpercyl);
     77  1.2  christos 	(void)fprintf(f, "cylinders: %ld\n", (long) lp->d_ncylinders);
     78  1.2  christos 	(void)fprintf(f, "total sectors: %ld\n", (long) lp->d_secperunit);
     79  1.2  christos 	(void)fprintf(f, "rpm: %ld\n", (long) lp->d_rpm);
     80  1.2  christos 	(void)fprintf(f, "interleave: %ld\n", (long) lp->d_interleave);
     81  1.2  christos 	(void)fprintf(f, "trackskew: %ld\n", (long) lp->d_trackskew);
     82  1.2  christos 	(void)fprintf(f, "cylinderskew: %ld\n", (long) lp->d_cylskew);
     83  1.2  christos 	(void)fprintf(f, "headswitch: %ld\t\t# microseconds\n",
     84  1.2  christos 	    (long)lp->d_headswitch);
     85  1.2  christos 	(void)fprintf(f, "track-to-track seek: %ld\t# microseconds\n",
     86  1.2  christos 	    (long)lp->d_trkseek);
     87  1.2  christos 	(void)fprintf(f, "drivedata: ");
     88  1.1     lukem 	for (i = NDDATA - 1; i >= 0; i--)
     89  1.1     lukem 		if (lp->d_drivedata[i])
     90  1.1     lukem 			break;
     91  1.1     lukem 	if (i < 0)
     92  1.1     lukem 		i = 0;
     93  1.1     lukem 	for (j = 0; j <= i; j++)
     94  1.2  christos 		(void)fprintf(f, "%d ", lp->d_drivedata[j]);
     95  1.2  christos 	(void)fprintf(f, "\n\n");
     96  1.2  christos 	(void)fflush(f);
     97  1.2  christos }
     98  1.2  christos 
     99  1.2  christos void
    100  1.2  christos showpartition(FILE *f, struct disklabel *lp, int i, int ctsformat)
    101  1.2  christos {
    102  1.2  christos 	struct partition *pp = lp->d_partitions + i;
    103  1.2  christos 	if (pp->p_size == 0)
    104  1.2  christos 		return;
    105  1.2  christos 
    106  1.2  christos 	if (ctsformat && lp->d_secpercyl && lp->d_nsectors) {
    107  1.2  christos 		char sbuf[64], obuf[64];
    108  1.2  christos 
    109  1.9     pooka 		(void)snprintf(sbuf, sizeof(sbuf), "%u/%u/%u",
    110  1.2  christos 		    pp->p_size/lp->d_secpercyl,
    111  1.2  christos 		    (pp->p_size%lp->d_secpercyl) / lp->d_nsectors,
    112  1.2  christos 		    pp->p_size%lp->d_nsectors);
    113  1.2  christos 
    114  1.9     pooka 		(void)snprintf(obuf, sizeof(obuf), "%u/%u/%u",
    115  1.2  christos 		    pp->p_offset/lp->d_secpercyl,
    116  1.2  christos 		    (pp->p_offset%lp->d_secpercyl) / lp->d_nsectors,
    117  1.2  christos 		    pp->p_offset%lp->d_nsectors);
    118  1.2  christos 
    119  1.2  christos 		(void)fprintf(f, " %c: %9s %9s ",
    120  1.2  christos 		    'a' + i, sbuf, obuf);
    121  1.2  christos 	} else {
    122  1.9     pooka 		(void)fprintf(f, " %c: %9u %9u ", 'a' + i,
    123  1.2  christos 		    pp->p_size, pp->p_offset);
    124  1.2  christos 	}
    125  1.2  christos 
    126  1.2  christos 	if ((unsigned) pp->p_fstype < FSMAXTYPES)
    127  1.2  christos 		(void)fprintf(f, "%10.10s", fstypenames[pp->p_fstype]);
    128  1.2  christos 	else
    129  1.2  christos 		(void)fprintf(f, "%10d", pp->p_fstype);
    130  1.2  christos 
    131  1.2  christos 	switch (pp->p_fstype) {
    132  1.2  christos 	case FS_UNUSED:				/* XXX */
    133  1.2  christos 		(void)fprintf(f, "  %5d %5d %5.5s ",
    134  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, "");
    135  1.2  christos 		break;
    136  1.2  christos 
    137  1.2  christos 	case FS_BSDFFS:
    138  1.2  christos 	case FS_ADOS:
    139  1.5       dbj 	case FS_APPLEUFS:
    140  1.2  christos 		(void)fprintf(f, "  %5d %5d %5d ",
    141  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg);
    142  1.2  christos 		break;
    143  1.2  christos 
    144  1.2  christos 	case FS_BSDLFS:
    145  1.2  christos 		(void)fprintf(f, "  %5d %5d %5d ",
    146  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_sgs);
    147  1.2  christos 		break;
    148  1.2  christos 
    149  1.2  christos 	case FS_EX2FS:
    150  1.2  christos 		(void)fprintf(f, "  %5d %5d       ",
    151  1.2  christos 		    pp->p_fsize, pp->p_fsize * pp->p_frag);
    152  1.4  drochner 		break;
    153  1.4  drochner 
    154  1.4  drochner 	case FS_ISO9660:
    155  1.4  drochner 		(void)fprintf(f, "  %6d            ", pp->p_cdsession);
    156  1.2  christos 		break;
    157  1.2  christos 
    158  1.2  christos 	default:
    159  1.2  christos 		(void)fprintf(f, "%20.20s", "");
    160  1.2  christos 		break;
    161  1.2  christos 	}
    162  1.2  christos 	if (lp->d_secpercyl != 0) {
    163  1.9     pooka 		(void)fprintf(f, " # (Cyl. %6u",
    164  1.2  christos 		    pp->p_offset / lp->d_secpercyl);
    165  1.2  christos 
    166  1.2  christos 		if (pp->p_offset % lp->d_secpercyl)
    167  1.2  christos 		    putc('*', f);
    168  1.2  christos 		else
    169  1.2  christos 		    putc(' ', f);
    170  1.2  christos 
    171  1.9     pooka 		(void)fprintf(f, "- %6u",
    172  1.2  christos 		    (pp->p_offset +
    173  1.2  christos 		    pp->p_size + lp->d_secpercyl - 1) /
    174  1.2  christos 		    lp->d_secpercyl - 1);
    175  1.2  christos 
    176  1.2  christos 		if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
    177  1.2  christos 		    putc('*', f);
    178  1.2  christos 
    179  1.2  christos 		(void)fprintf(f, ")\n");
    180  1.2  christos 	} else
    181  1.2  christos 		(void)fprintf(f, "\n");
    182  1.1     lukem }
    183  1.1     lukem 
    184  1.1     lukem void
    185  1.1     lukem showpartitions(FILE *f, struct disklabel *lp, int ctsformat)
    186  1.1     lukem {
    187  1.1     lukem 	int	i;
    188  1.1     lukem 
    189  1.2  christos 	(void)fprintf(f, "%d partitions:\n", lp->d_npartitions);
    190  1.2  christos 	(void)fprintf(f,
    191  1.7       dsl 	    "#        size    offset     fstype [fsize bsize cpg/sgs]\n");
    192  1.2  christos 
    193  1.2  christos 	for (i = 0; i < lp->d_npartitions; i++)
    194  1.2  christos 		showpartition(f, lp, i, ctsformat);
    195  1.2  christos 	(void)fflush(f);
    196  1.1     lukem }
    197