Subject: bin/3810: minor enhancement for vnconfig
To: None <gnats-bugs@gnats.netbsd.org>
From: None <enami@ba2.so-net.or.jp>
List: netbsd-bugs
Date: 06/29/1997 13:24:52
>Number:         3810
>Category:       bin
>Synopsis:       minor enhancement for vnconfig
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 28 21:35:01 1997
>Last-Modified:
>Originator:     enami tsugutomo
>Organization:
>Release:        NetBSD-current 1997 June 27
>Environment:
System: NetBSD pavlov.enami.ba2.so-net.or.jp 1.2G NetBSD 1.2G (PAVLOV) #299: Sat Jun 28 11:55:32 JST 1997 enami@pavlov.enami.ba2.so-net.or.jp:/b/netbsd/kernel/compile/PAVLOV i386


>Description:
	Now, special file to use configure vnd is device file of raw
	partition, isn't it?  If so, I think it is better to document it.
	And then, it may useful if we can spacify vndN instead of
	/dev/rvnd0d like disklabel(8).
	Finaly, since return value of rawdevice() is malloc()'ed,
	it should be free()'ed.

>How-To-Repeat:
	Read the source and manuals

>Fix:
	Here is my fix:

cvs diff: Diffing .
Index: vnconfig.8
===================================================================
RCS file: /a/cvsroot/NetBSD/src/usr.sbin/vnconfig/vnconfig.8,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 vnconfig.8
--- vnconfig.8	1997/06/28 00:42:13	1.1.1.4
+++ vnconfig.8	1997/06/29 02:28:36
@@ -99,6 +99,10 @@
 allowing the latter to be accessed as though it were a disk.
 Hence a regular file within the filesystem can be used for swapping
 or can contain a filesystem that is mounted in the name space.
+The
+.Ar special_file
+shoud be a device file of raw partition,
+or a disk name like vnd0.
 .Pp
 Options indicate an action to be performed:
 .Bl -tag -width indent
Index: vnconfig.c
===================================================================
RCS file: /a/cvsroot/NetBSD/src/usr.sbin/vnconfig/vnconfig.c,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 vnconfig.c
--- vnconfig.c	1997/06/24 18:40:24	1.1.1.3
+++ vnconfig.c	1997/06/29 02:27:25
@@ -91,6 +91,7 @@
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -163,6 +164,7 @@
 	fd = open(rdev, O_RDWR, 0666);
 	if (fd < 0) {
 		warn(rdev);
+		free(rdev);
 		return (1);
 	}
 
@@ -216,6 +218,7 @@
  done:
 	(void) close(fd);
 	fflush(stdout);
+	free(rdev);
 	return (rv < 0);
 }
 
@@ -269,10 +272,18 @@
 {
 	register char *rawbuf, *dp, *ep;
 	struct stat sb;
-	int len;
+	size_t len, size;
 
 	len = strlen(dev);
-	rawbuf = malloc(len + 2);
+	/*
+	 * If dev is block device and we convert it to char device, size
+	 * to allocate is len + 2 (one for 'r' and one for nul).
+	 * If dev is name like vnd0, size is len + 2 + sizeof(_PATH_DEV)
+	 * (one for 'r', one for partition char and nul is counted
+	 * in sizeof(_PATH_DEV)).
+	 */
+	size = len + 2 + sizeof(_PATH_DEV);
+	rawbuf = malloc(size);
 	strcpy(rawbuf, dev);
 	if (stat(rawbuf, &sb) != 0 || !S_ISCHR(sb.st_mode)) {
 		dp = rindex(rawbuf, '/');
@@ -280,7 +291,9 @@
 			for (ep = &rawbuf[len]; ep > dp; --ep)
 				*(ep+1) = *ep;
 			*++ep = 'r';
-		}
+		} else
+			snprintf(rawbuf, size, "%sr%s%c", _PATH_DEV, dev,
+			    'a' + RAW_PART);
 	}
 	return (rawbuf);
 }
>Audit-Trail:
>Unformatted: