bin/174398: [PATCH] fstab(5): add support for spaces and tabs

William Grzybowski william88 at gmail.com
Wed Dec 12 15:30:00 UTC 2012


>Number:         174398
>Category:       bin
>Synopsis:       [PATCH] fstab(5): add support for spaces and tabs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 12 15:30:00 UTC 2012
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


More information about the freebsd-bugs mailing list