Date: Sun, 8 Aug 2010 14:31:57 +0200 (CEST) From: "Walter C. Pelissero" <walter.pelissero@iesy.net> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/149424: fstab and labels with whitespace Message-ID: <201008081231.o78CVv9m012032@zaphod.home.lan> Resent-Message-ID: <201008081250.o78Co19d000219@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 149424 >Category: bin >Synopsis: fstab and labels with whitespace >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Aug 08 12:50:00 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Walter C. Pelissero >Release: FreeBSD 8.1-PRERELEASE i386 >Organization: >Environment: System: FreeBSD zaphod.home.lan 8.1-PRERELEASE FreeBSD 8.1-PRERELEASE #1: Tue Jul 13 22:21:06 CEST 2010 root@zaphod.home.lan:/usr/home/obj/usr/src/sys/TIGER-MP i386 >Description: /etc/fstab currently doesn't allow for whitespace anywhere but between fields (or in comments). This makes impossible to use a label in place of a device name when mounting volumes containing whitespace in the name. Take for instance CF or SD memory cards created by Nikon cameras: they are labelled "NIKON <model>", with a whitespace between NIKON and the model name. Although it's still possible to mount the /dev/da* device, the label is arguably much more convenient. >How-To-Repeat: >Fix: The following patch modifies libc to allow for special characters in the first field of a fstab entry. A single space can be written as \s, as in NIKON\sD300S, or \040, as in NIKON\040D300S. Indeed, any octal escape sequence can be used, or sequences such as \t, \r, or \n. I'm afraid, this patch does not update fstab.5. Index: fstab.c =================================================================== RCS file: /repos/src/lib/libc/gen/fstab.c,v retrieving revision 1.15.10.1 diff -u -r1.15.10.1 fstab.c --- fstab.c 3 Aug 2009 08:13:06 -0000 1.15.10.1 +++ fstab.c 8 Aug 2010 11:51:02 -0000 @@ -106,6 +106,40 @@ _fs_fstab.fs_spec = buf; } +#define isoctal(c) ((c) >= '0' && (c) <= '7') +#define octdigit2int(c) ((c) - '0') + +static char * +unescape (char *string) +{ + static char special[] = "s\\trn"; + static char translation[] = " \\\t\r\n"; + char *s, *d; + + for (s = d = string; *s; ++s, ++d) + { + if (s[0] == '\\') { + char *p; + + if ((p = strchr(special, s[1]))) { + *d = translation[p - special]; + ++s; + } else if (isoctal(s[1]) && + isoctal(s[2]) && + isoctal(s[3])) { + *d = octdigit2int(s[1]) * 8 * 8 + + octdigit2int(s[2]) * 8 + + octdigit2int(s[3]); + s += 3; + } else + *d = *s; + } else + *d = *s; + } + *d = '\0'; + return string; +} + static int fstabscan() { @@ -148,7 +182,7 @@ /* OLD_STYLE_FSTAB */ while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') ; - _fs_fstab.fs_spec = cp; + _fs_fstab.fs_spec = unescape(cp); if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#') continue; while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008081231.o78CVv9m012032>