Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

disklabel: support (non-interactive) printing in selectable units

From: mho <mho(at)mho.nu>
Date: Sun Feb 02 2003 - 03:34:01 EST


Hi,

The following patch adds support for '[-p unit]' to disklabel. This allows one to view the partition sizes and offsets in megabytes, etc, without being root and entering 'disklabel -E'.

  • mho

Index: disklabel.8



RCS file: /cvs/src/sbin/disklabel/disklabel.8,v retrieving revision 1.48
diff -u -r1.48 disklabel.8
--- disklabel.8	2003/02/01 16:29:52	1.48
+++ disklabel.8	2003/02/02 08:27:53

@@ -47,6 +47,7 @@
 .Nm disklabel
 .Op Fl n
 .Op Fl cd Li \&| Fl r
+.Op Fl p Ar unit
 .Op Fl t
 .Op Fl v
 .Ar disk

@@ -187,6 +188,12 @@

 If
 .Ar tempfile
 already exists, it will be overwritten.
+.It Fl p Ar unit
+Print partition sizes and offsets in
+.Ar unit
+instead of sectors.
+Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes) and
+g(igabytes).

 .It Fl t
 Format the label as a
 .Xr disktab 5
Index: disklabel.c

RCS file: /cvs/src/sbin/disklabel/disklabel.c,v retrieving revision 1.76
diff -u -r1.76 disklabel.c
--- disklabel.c	2002/12/31 16:22:25	1.76
+++ disklabel.c	2003/02/02 08:27:53

@@ -1,7 +1,7 @@
/* $OpenBSD: disklabel.c,v 1.76 2002/12/31 16:22:25 miod Exp $ */ /* - * Copyright (c) 1987, 1993 + * Copyright (c) 1987, 1993, 2003 * The Regents of the University of California. All rights reserved.
  *
  • This code is derived from software contributed to Berkeley by
    @@ -125,7 +125,7 @@
    void l_perror(char *); struct disklabel *readlabel(int); struct disklabel *makebootarea(char *, struct disklabel *, int); -void display(FILE *, struct disklabel *); +void display(FILE *, struct disklabel *, char); void display_partition(FILE *, struct disklabel *, char **, int, char, int); int width_partition(struct disklabel *, int); int editor(struct disklabel *, int, char *, char *);
    @@ -148,9 +148,10 @@
    int ch, f, writeable, error = 0; char *fstabfile = NULL; struct disklabel *lp; + char print_unit = 'S'; FILE *t;
    • while ((ch = getopt(argc, argv, "BEFf:NRWb:cdenrs:tvw")) != -1) + while ((ch = getopt(argc, argv, "BEFf:NRWb:cdenp:rs:tvw")) != -1) switch (ch) { #if NUMBOOT > 0 case 'B':
      @@ -212,6 +213,9 @@
      usage(); op = WRITE; break; + case 'p': + print_unit = *optarg; + break; case 'n': donothing++; break;
      @@ -284,7 +288,7 @@
      if (tflag) makedisktab(stdout, lp); else
    • display(stdout, lp); + display(stdout, lp, print_unit); error = checklabel(lp); break; case RESTORE:
      @@ -1089,9 +1093,10 @@
      }

 void
-display(f, lp)
+display(f, lp, unit)

 	FILE *f;
 	struct disklabel *lp;
+	char unit;
 {
 	int i, j;
 	int width;

@@ -1139,7 +1144,7 @@
"# %*.*s %*.*s fstype [fsize bsize cpg]\n", width, width, "size", width, width, "offset"); for (i = 0; i < lp->d_npartitions; i++) - display_partition(f, lp, NULL, i, 0, width); + display_partition(f, lp, NULL, i, unit, width); fflush(f);

 }  

@@ -1158,7 +1163,7 @@

 		warn("%s", tmpfil);
 		return (1);
 	}
-	display(fp, lp);
+	display(fp, lp, 'S');
 	fprintf(fp, "\n# Notes:\n");
 	fprintf(fp,

 "# Up to 16 partitions are valid, named from 'a' to 'p'. Partition 'a' is\n"
@@ -1758,7 +1763,7 @@
 
 	fprintf(stderr, "usage:\n");
 	fprintf(stderr,
-	    "  disklabel [-nv] [-r|-cd] [-t] disk%s     (read)\n",
+	    "  disklabel [-nv] [-r|-cd] [-p unit] [-t] disk%s (read)\n",
 	    blank);
 	fprintf(stderr,
 	    "  disklabel [-nv] [-r|-cd] -e disk%s       (edit)\n",
Index: editor.c

RCS file: /cvs/src/sbin/disklabel/editor.c,v retrieving revision 1.81
diff -u -r1.81 editor.c
--- editor.c	2002/06/09 08:13:05	1.81
+++ editor.c	2003/02/02 08:27:53

@@ -1,7 +1,7 @@
/* $OpenBSD: editor.c,v 1.81 2002/06/09 08:13:05 todd Exp $ */ /* - * Copyright (c) 1997-2000 Todd C. Miller + * Copyright (c) 1997-2003 Todd C. Miller * All rights reserved.

  *

 /* from disklabel.c */

 int	checklabel(struct disklabel *);
-void	display(FILE *, struct disklabel *);
+void	display(FILE *, struct disklabel *, char);
Do you need help?X
void display_partition(FILE *, struct disklabel *, char **, int, char, int); int width_partition(struct disklabel *, int);
@@ -385,7 +385,7 @@
if ((fp = fopen(arg, "w")) == NULL) { warn("cannot open %s", arg); } else { - display(fp, &label); + display(fp, &label, 'S'); (void)fclose(fp); } break;
Received on Sun Feb 2 03:34:36 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:48:29 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library