From nobody@FreeBSD.org  Mon Aug 31 19:39:20 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B478C106568F
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 31 Aug 2009 19:39:20 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id A38DC8FC19
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 31 Aug 2009 19:39:20 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n7VJdKAS045572
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 31 Aug 2009 19:39:20 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n7VJdKti045565;
	Mon, 31 Aug 2009 19:39:20 GMT
	(envelope-from nobody)
Message-Id: <200908311939.n7VJdKti045565@www.freebsd.org>
Date: Mon, 31 Aug 2009 19:39:20 GMT
From: "Rick C. Petty" <rick-freebsd2008@kiwi-computer.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: UFS label limitations
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         138421
>Category:       kern
>Synopsis:       [ufs] [patch] remove UFS label limitations
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-fs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 31 19:40:06 UTC 2009
>Closed-Date:    
>Last-Modified:  Tue Sep 01 05:11:42 UTC 2009
>Originator:     Rick C. Petty
>Release:        8-STABLE
>Organization:
>Environment:
FreeBSD myhost 8.0-BETA3 FreeBSD 8.0-BETA3 #2 r196660M: Sun Aug 30 19:54:44 CDT 2009     root@myhost:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
UFS filesystems allow label/volume names containing alphanumeric
characters only.  There is a need for at least one separator character.

This request and patches were submitted to freebsd-fs@ and freebsd-
current@ but no one on those lists seems to be willing to commit this
innocuous patch.  I've been using a patched system for well over a year
on a number of systems.
>How-To-Repeat:
/sbin/newfs -L volume-name ...

-or-

/sbin/tunefs -L volume-name ...
>Fix:
One of the following patches, to allow acceptable POSIX filename
characters as part of UFS labels.

The first manually tests against the acceptable characters, which
should be faster.  This second patch is using strspn(3) as suggested
by des@ in case the first patch is not acceptable.  It is slower but
we are likely going to do I/O anyway.  I don't care which patch you
choose, just please someone commit the damn thing! =)

Patch attached with submission follows:

--- src/sbin/newfs/newfs.c.orig	2007-03-02 14:07:59.000000000 -0600
+++ src/sbin/newfs/newfs.c	2008-12-15 17:29:26.000000000 -0600
@@ -168,11 +168,15 @@
 		case 'L':
 			volumelabel = optarg;
 			i = -1;
-			while (isalnum(volumelabel[++i]));
-			if (volumelabel[i] != '\0') {
-				errx(1, "bad volume label. Valid characters are alphanumerics.");
-			}
-			if (strlen(volumelabel) >= MAXVOLLEN) {
+			while ((ch = volumelabel[++i]) != '\0')
+				if (ch != '-' && ch != '.' && ch != '_' &&
+				    (ch < '0' || ch > '9') &&
+				    (ch < 'A' || ch > 'Z') &&
+				    (ch < 'a' || ch > 'z'))
+					errx(1,
+					"bad volume label. Valid characters are "
+					"[0-9A-Za-z._-].");
+			if (i >= MAXVOLLEN) {
 				errx(1, "bad volume label. Length is longer than %d.",
 				    MAXVOLLEN);
 			}
--- src/sbin/tunefs/tunefs.c.orig	2008-02-26 14:25:35.000000000 -0600
+++ src/sbin/tunefs/tunefs.c	2008-12-15 17:27:58.000000000 -0600
@@ -153,13 +153,16 @@
 			name = "volume label";
 			Lvalue = optarg;
 			i = -1;
-			while (isalnum(Lvalue[++i]));
-			if (Lvalue[i] != '\0') {
+			while ((ch = Lvalue[++i]) != '\0')
+				if (ch != '-' && ch != '.' && ch != '_' &&
+				    (ch < '0' || ch > '9') &&
+				    (ch < 'A' || ch > 'Z') &&
+				    (ch < 'a' || ch > 'z'))
 				errx(10,
-				"bad %s. Valid characters are alphanumerics.",
+					"bad %s. Valid characters are "
+					"[0-9A-Za-z._-].",
 				    name);
-			}
-			if (strlen(Lvalue) >= MAXVOLLEN) {
+			if (i >= MAXVOLLEN) {
 				errx(10, "bad %s. Length is longer than %d.",
 				    name, MAXVOLLEN - 1);
 			}
--- src/sbin/newfs/newfs.c.orig	2008-05-03 23:51:38.000000000 -0500
+++ src/sbin/newfs/newfs.c	2009-07-22 16:58:48.000000000 -0500
@@ -167,10 +167,10 @@
 			break;
 		case 'L':
 			volumelabel = optarg;
-			i = -1;
-			while (isalnum(volumelabel[++i]));
+			i = strspn(volumelabel,
+			    "-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
 			if (volumelabel[i] != '\0') {
-				errx(1, "bad volume label. Valid characters are alphanumerics.");
+				errx(1, "bad volume label. Valid characters are [0-9A-Za-z._-].");
 			}
 			if (strlen(volumelabel) >= MAXVOLLEN) {
 				errx(1, "bad volume label. Length is longer than %d.",
--- src/sbin/tunefs/tunefs.c.orig	2008-05-03 23:51:52.000000000 -0500
+++ src/sbin/tunefs/tunefs.c	2009-07-22 17:01:23.000000000 -0500
@@ -152,11 +152,11 @@
 			found_arg = 1;
 			name = "volume label";
 			Lvalue = optarg;
-			i = -1;
-			while (isalnum(Lvalue[++i]));
+			i = strspn(Lvalue,
+			    "-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
 			if (Lvalue[i] != '\0') {
 				errx(10,
-				"bad %s. Valid characters are alphanumerics.",
+				"bad %s. Valid characters are [0-9A-Za-z._-].",
 				    name);
 			}
 			if (strlen(Lvalue) >= MAXVOLLEN) {


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Sep 1 05:02:51 UTC 2009 
Responsible-Changed-Why:  
reclassify. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=138421 
>Unformatted:
