Subject: bin/3863: (Small) bugfix and additions to edlabel
To: None <gnats-bugs@gnats.netbsd.org>
From: None <abs@anim.dreamworks.com>
List: netbsd-bugs
Date: 07/14/1997 09:18:12
>Number:         3863
>Category:       bin
>Synopsis:       (Small) bugfix and additions to edlabel
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 14 08:35:01 1997
>Last-Modified:
>Originator:     abs@anim.dreamworks.com
>Organization:
<a href="http://www.mono.org/">Monochrome</a>
>Release:        Mon Jul 14 09:05:28 PDT 1997
>Environment:
	
System: IRIX irony 6.3 12161207 IP32
(Ok, ok.. I'm running this on a box at work :)


>Description:
    Bugfix:
      - edlabel calls printf(modify_cmds); where modify_cmds is a string
	containing % modifiers.
      + Add the missing arguments.

    Additions:
      - Edlabel understands numbers as blks, or 'cyl/trk/head'. SunOS format
	would recognise '100/' as meaning '100/0/0'. Given that partitions need
	to be a cylinder bounderies for the prom to accept the disklabel this
	is a moot point :)
      + Make get_val_cts() also accept 'nn/' and 'nn/mm'.

      -	Disklabel recognises disks specified as 'sd1' as well as '/dev/rsd1c'.
      +	Add this to edlabel.

      -	When entering the length of a partition it would be convenient to know
	the distance from the partition start to the end of the disk.
      +	Print this number.

      - Edlabel does not even have a primitive man page.
      + Add a primitive man page :)

    And a question:
	Why does only the sparc, sun3, and atari compile edlabel? It would
	appear to be a useful tool for all ports?

>How-To-Repeat:
    Run edlabel. Like it, but want to make it a fraction better :)

>Fix:
	
--- edlabel.c.orig	Fri Jul 11 00:09:07 1997
+++ edlabel.c	Fri Jul 11 00:15:27 1997
@@ -43,6 +43,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <util.h>
+#include <paths.h>
 
 /*
  * Machine dependend constants you want to retrieve only once...
@@ -223,12 +224,12 @@
 	u_int32_t	 *result;
 {
 	u_long tmp;
-	int	cyls, trks, sects;
+	int	cyls=0, trks=0, sects=0;
 
 	tmp = sscanf(buf, "%d/%d/%d", &cyls, &trks, &sects);
 	if (tmp == 1)
 		*result = cyls;	/* really nblks! */
-	if (tmp == 3) {
+	if (strchr(buf,'/') && tmp >= 1) {
 		tmp = cyls;
 		tmp *= d->d_ntracks;
 		tmp += trks;
@@ -304,6 +305,9 @@
 	get_val_cts(d, tmpbuf, &p->p_offset);
 
 	/* number of blocks, or cyls/trks/sects */
+	printf("Blocks from end: ");
+	print_val_cts(d, d->d_partitions[rawpartition].p_size-p->p_offset);
+	printf("\n");
 	printf("length as <nblks> or <cyls/trks/sects> : ");
 	fflush(stdout);
 	if (fgets(tmpbuf, sizeof(tmpbuf), stdin) == NULL)
@@ -463,7 +467,8 @@
 		}
 		if ((c < 'a') || (c > 'q')) {
 			printf("bad input.  ");
-			printf(modify_cmds);
+			printf(modify_cmds, 'a' + maxpartitions,
+			    scsi_fict ? " s   : standarize geometry\n" : "");
 			continue;
 		}
 		edit_partition(dl, c - 'a', 1);
@@ -512,15 +517,22 @@
 	struct disklabel dl;
 	struct cmd *cmd;
 	char *devname;
+	char devbuf[sizeof(_PATH_DEV)+8+1+1];
 
 	if (argc != 2) {
 		fprintf(stderr, "usage: edlabel RAWDISK\n");
 		exit(1);
 	}
-	devname = argv[1];
 
 	rawpartition = getrawpartition();
 	maxpartitions = getmaxpartitions();
+
+	devname = argv[1];
+        if (devname[0] != '/') {
+                (void)sprintf(devbuf, "%sr%.8s%c", _PATH_DEV, devname,
+							    'a'+rawpartition);
+		devname=devbuf;
+        }
 
 	label_read(&dl, devname);
 
0a1,46
> .\"	$NetBSD: edlabel.8,v 1.14 1997/05/29 01:48:34 cgd Exp $
> .\"
> .\" Copyright assigned to the NetBSD foundation
> .\"
> .Dd July 11, 1997
> .Dt EDLABEL 8
> .Os NetBSD
> .Sh NAME
> .Nm edlabel
> .Nd edit disklabel
> .Sh SYNOPSIS
> .Nm edlabel
> .Ar disk
> .Sh DESCRIPTION
> .Nm Edlabel
> can be used to install, examine or modify the label on a disk.  It can be used
> to change the drive identification, partitions, or to replace a damaged label.
> .Pp
> The following commands are available at the 
> .Nm edlabel
> main menu:
> .Bl -tag -width Fl
> .It Ic print
> Display the current disklabel, including type, geometry, and partitions.
> .It Ic modify
> Presents the 'edlabel/modify' menu.
> .It Ic write
> Write out the new label to the disk. No changes will be made to the disklabel
> unless this command is given.
> .It Ic quit
> Exit
> .Nm edlabel .
> .El
> .Sh EXAMPLES
> .Dl edlabel sd0
> .Pp
> Edit disklabel for sd0 as obtained via
> .Pa /dev/rsd0c .
> .Sh SEE ALSO
> .Xr disklabel 5 ,
> .Xr disklabel 8 ,
> .Xr newfs 8 .
> .Sh CAVEATS
> The 
> .Nm modify
> command should be documented.
--- Makefile.orig	Mon Jul 14 00:27:37 1997
+++ Makefile	Mon Jul 14 00:26:50 1997
@@ -11,6 +11,6 @@
 all: ${PROG}
 .endif
 
-NOMAN=
+MAN=	edlabel.8
 
 .include <bsd.prog.mk>
>Audit-Trail:
>Unformatted: