From william88@gmail.com  Wed Dec 12 15:27:09 2012
Return-Path: <william88@gmail.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 47EA8DCE
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Dec 2012 15:27:09 +0000 (UTC)
	(envelope-from william88@gmail.com)
Received: from mail-ye0-f182.google.com (mail-ye0-f182.google.com [209.85.213.182])
	by mx1.freebsd.org (Postfix) with ESMTP id F11648FC0C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Dec 2012 15:27:08 +0000 (UTC)
Received: by mail-ye0-f182.google.com with SMTP id q5so174255yen.13
        for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Dec 2012 07:27:08 -0800 (PST)
Received: by 10.236.77.229 with SMTP id d65mr2073729yhe.124.1355326028103;
        Wed, 12 Dec 2012 07:27:08 -0800 (PST)
Received: from localhost ([177.16.183.188])
        by mx.google.com with ESMTPS id q48sm35330268yhk.7.2012.12.12.07.27.06
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 12 Dec 2012 07:27:07 -0800 (PST)
Message-Id: <50c8a24b.c89eec0a.0cd7.ffffaf07@mx.google.com>
Date: Wed, 12 Dec 2012 07:27:07 -0800 (PST)
From: William Grzybowski <william88@gmail.com>
Reply-To: William Grzybowski <william88@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] fstab(5): add support for spaces and tabs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         174398
>Category:       kern
>Synopsis:       [libc] [patch] fstab(5): add support for spaces and tabs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 12 15:30:00 UTC 2012
>Closed-Date:    Thu Dec 13 03:17:31 UTC 2012
>Last-Modified:  Thu Dec 13 03:17:31 UTC 2012
>Originator:     William Grzybowski
>Release:        FreeBSD 10.0-CURRENT amd64 r242822
>Organization:
>Environment:
>Description:

        It is well known that FreeBSD cannot mount files with spaces or tabs using fstab(5).
        I'm aware of PRs conf/37569, bin/55539, bin/117687 but they seem to handle it using quotes which
does not seem a very good way, besides they are quite old and are not getting any attention.
        What I'm proposing here is to handle it like Linux, decoding the octal ascii character, e.g.:
        /mnt/my\040folder here becomes: /mnt/my folder

        This is a recurrent problem, specially with people mounting CIFS shares where shares with spaces
are quite common. The workaround is remove the space but that is not practical.

        I'm aware the patch is not complete, it does not change fstab man page, probably does not follow
style(9) etc, however I would like any reviews or comments before wasting more time on this. Let me know
what you think and I can fix it.

        Thank you.

>How-To-Repeat:

	Try to mount to or from "/mnt/my folder" using fstab(5).

>Fix:

	See attached patch


--- fstab_decode.patch begins here ---
Index: lib/libc/gen/fstab.c
===================================================================
--- lib/libc/gen/fstab.c	(revision 242822)
+++ lib/libc/gen/fstab.c	(working copy)
@@ -60,6 +60,34 @@
 static void fixfsfile(void);
 static int fstabscan(void);
 
+static char *
+decode_name(char *buf)
+{
+	char *rd = buf, *wr = buf;
+
+	do {
+		if (rd[0] == '\\') {
+			if(rd[1] == '0' && rd[2] == '4' && rd[3] == '0') {
+				*wr++ = ' '; // \040 is a space
+				rd += 3;
+			} else if (rd[1] == '0' && rd[2] == '1' && rd[3] == '1') {
+				*wr++ = '\t'; // \011 is a tab
+				rd += 3;
+			} else if (rd[1] == '\\') {
+				*wr++ = '\\'; // Escape backslash
+				rd += 1;
+			} else if (rd[1] == '1' && rd[2] == '3' && rd[3] == '4') {
+				*wr++ = '\\'; // \134 is also backslash
+				rd += 3;
+			} else
+				*wr++ = *rd;
+		} else
+			*wr++ = *rd;
+	} while (*rd++ != '\0');
+
+	return buf;
+}
+
 void
 setfstab(const char *file)
 {
@@ -126,8 +154,8 @@
 		if (*line == '#' || *line == '\n')
 			continue;
 		if (!strpbrk(p, " \t")) {
-			_fs_fstab.fs_spec = strsep(&p, ":\n");
-			_fs_fstab.fs_file = strsep(&p, ":\n");
+			_fs_fstab.fs_spec = decode_name(strsep(&p, ":\n"));
+			_fs_fstab.fs_file = decode_name(strsep(&p, ":\n"));
 			fixfsfile();
 			_fs_fstab.fs_type = strsep(&p, ":\n");
 			if (_fs_fstab.fs_type) {
@@ -150,14 +178,14 @@
 /* OLD_STYLE_FSTAB */
 		while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
 			;
-		_fs_fstab.fs_spec = cp;
+		_fs_fstab.fs_spec = decode_name(cp);
 		if (_fs_fstab.fs_spec == NULL || *_fs_fstab.fs_spec == '#')
 			continue;
 		if (strunvis(_fs_fstab.fs_spec, _fs_fstab.fs_spec) < 0)
 			goto bad;
 		while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
 			;
-		_fs_fstab.fs_file = cp;
+		_fs_fstab.fs_file = decode_name(cp);
 		if (_fs_fstab.fs_file == NULL)
 			goto bad;
 		if (strunvis(_fs_fstab.fs_file, _fs_fstab.fs_file) < 0)
--- fstab_decode.patch ends here ---

>Release-Note:
>Audit-Trail:

From: William Grzybowski <william88@gmail.com>
To: bug-followup@FreeBSD.org, william88@gmail.com
Cc:  
Subject: Re: bin/174398: [PATCH] fstab(5): add support for spaces and tabs
Date: Wed, 12 Dec 2012 13:37:32 -0200

 --002354470728b4ae5904d0a99348
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 Looks like a fix has already been committed to the other PRs but they were
 not closed.
 
 I guess this can be closed.
 
 --=20
 William Grzybowski
 ------------------------------------------
 Ag=EAncia Livre - www.agencialivre.com.br
 Curitiba/PR - Brasil
 
 --002354470728b4ae5904d0a99348
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 Looks like a fix has already been committed to the other PRs but they were =
 not closed.<br><br>I guess this can be closed.<br clear=3D"all"><br>-- <br>=
 William Grzybowski<br>------------------------------------------<br>Ag=EAnc=
 ia Livre - <a href=3D"http://www.agencialivre.com.br">www.agencialivre.com.=
 br</a><br>
 Curitiba/PR - Brasil<br>
 
 --002354470728b4ae5904d0a99348--
State-Changed-From-To: open->closed 
State-Changed-By: eadler 
State-Changed-When: Thu Dec 13 03:17:31 UTC 2012 
State-Changed-Why:  
see conf/37569, bin/55539, bin/117687 

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