svn commit: r244585 - in head: . sys/geom/label

Jaakko Heinonen jh at FreeBSD.org
Tue Jan 8 19:40:03 UTC 2013


On 2013-01-07, John Baldwin wrote:
> I think if it isn't hard to do so, we should aim to preserve labels as they 
> are generally intended to be human readable as-is.  Just preserving spaces is 
> probably sufficient for this as they are probably the most commonly used 
> character in labels affected by this change.

All right. I have prepared patches for review.

- Quote device names in devctl(4) device events. This allows events to
  work for device names containing spaces.
- Allow spaces again in device names.

Requested by:	jhb
PR:		kern/161912

%%%
Index: sys/kern/kern_conf.c
===================================================================
--- sys/kern/kern_conf.c	(revision 245155)
+++ sys/kern/kern_conf.c	(working copy)
@@ -536,17 +536,17 @@ notify(struct cdev *dev, const char *ev,
 {
 	static const char prefix[] = "cdev=";
 	char *data;
-	int namelen, mflags;
+	size_t datalen;
+	int mflags;
 
 	if (cold)
 		return;
 	mflags = (flags & MAKEDEV_NOWAIT) ? M_NOWAIT : M_WAITOK;
-	namelen = strlen(dev->si_name);
-	data = malloc(namelen + sizeof(prefix), M_TEMP, mflags);
+	datalen = strlen(dev->si_name) + sizeof(prefix) + 2;
+	data = malloc(datalen, M_TEMP, mflags);
 	if (data == NULL)
 		return;
-	memcpy(data, prefix, sizeof(prefix) - 1);
-	memcpy(data + sizeof(prefix) - 1, dev->si_name, namelen + 1);
+	snprintf(data, datalen, "%s\"%s\"", prefix, dev->si_name);
 	devctl_notify_f("DEVFS", "CDEV", ev, data, mflags);
 	free(data, M_TEMP);
 }
@@ -699,11 +699,11 @@ prep_devname(struct cdev *dev, const cha
 
 	for (to = dev->si_name; *from != '\0'; from++, to++) {
 		/*
-		 * Spaces and double quotation marks cause
-		 * problems for the devctl(4) protocol.
-		 * Reject names containing those characters.
+		 * Double quotation marks cause problems for the
+		 * devctl(4) protocol. Reject names containing
+		 * those characters.
 		 */
-		if (isspace(*from) || *from == '"')
+		if (*from == '"')
 			return (EINVAL);
 		/* Treat multiple sequential slashes as single. */
 		while (from[0] == '/' && from[1] == '/')
Index: sys/geom/geom_dev.c
===================================================================
--- sys/geom/geom_dev.c	(revision 245155)
+++ sys/geom/geom_dev.c	(working copy)
@@ -107,15 +107,15 @@ static void
 g_dev_attrchanged(struct g_consumer *cp, const char *attr)
 {
 	struct cdev *dev;
-	char buf[SPECNAMELEN + 6];
+	char buf[SPECNAMELEN + 8];
 
 	if (strcmp(attr, "GEOM::media") == 0) {
 		dev = cp->geom->softc;
-		snprintf(buf, sizeof(buf), "cdev=%s", dev->si_name);
+		snprintf(buf, sizeof(buf), "cdev=\"%s\"", dev->si_name);
 		devctl_notify_f("DEVFS", "CDEV", "MEDIACHANGE", buf, M_WAITOK);
 		dev = cp->cp_alias_dev;
 		if (dev != NULL) {
-			snprintf(buf, sizeof(buf), "cdev=%s", dev->si_name);
+			snprintf(buf, sizeof(buf), "cdev=\"%s\"", dev->si_name);
 			devctl_notify_f("DEVFS", "CDEV", "MEDIACHANGE", buf,
 			    M_WAITOK);
 		}
%%%

Don't mangle spaces in label names.

Requested by:	jhb

%%%
Index: sys/geom/label/g_label.c
===================================================================
--- sys/geom/label/g_label.c	(revision 245155)
+++ sys/geom/label/g_label.c	(working copy)
@@ -148,7 +148,7 @@ g_label_mangle_name(char *label, size_t 
 
 	sb = sbuf_new(NULL, NULL, size, SBUF_FIXEDLEN);
 	for (c = label; *c != '\0'; c++) {
-		if (!isprint(*c) || isspace(*c) || *c =='"' || *c == '%')
+		if (!isprint(*c) || *c =='"' || *c == '%')
 			sbuf_printf(sb, "%%%02X", *c);
 		else
 			sbuf_putc(sb, *c);
Index: UPDATING
===================================================================
--- UPDATING	(revision 245155)
+++ UPDATING	(working copy)
@@ -33,9 +33,9 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 10
 
 20121222:
 	GEOM_LABEL now mangles label names read from file system metadata.
-	Mangling affect labels containing spaces, non-printable characters,
-	'%' or '"'. Device names in /etc/fstab and other places may need to
-	be updated.
+	Mangling affect labels containing non-printable characters, '%' or
+	'"'. Device names in /etc/fstab and other places may need to be
+	updated.
 
 20121217:
 	By default, only the 10 most recent kernel dumps will be saved.  To
%%%

-- 
Jaakko


More information about the svn-src-all mailing list