bin/55539: [patch] Parse fstab(5) with spaces in path names
Simon Barner
barner at in.tum.de
Mon Aug 18 10:50:05 PDT 2003
The following reply was made to PR bin/55539; it has been noted by GNATS.
From: Simon Barner <barner at in.tum.de>
To: freebsd-gnats-submit at FreeBSD.org
Cc: Garrett Wollman <wollman at khavrinen.lcs.mit.edu>
Subject: Re: bin/55539: [patch] Parse fstab(5) with spaces in path names
Date: Mon, 18 Aug 2003 18:24:10 +0200
> It has a number of style bugs.
[...]
> Indentation.
I hope it's style(9) conforming now. I have also updated the fstab(5)
man page.
> Other than that it looks OK.
Thanks for reviewing my work :-)
Regards,
Simon
--- fstab.c.orig Mon Aug 18 10:42:11 2003
+++ fstab.c Mon Aug 18 17:50:17 2003
@@ -53,6 +53,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <vis.h>
static FILE *_fs_fp;
static struct fstab _fs_fstab;
@@ -84,6 +85,41 @@
_fs_fstab.fs_spec = buf;
}
+/*
+ * Converts a string *str, that possibly contains vis(1|3) encoded
+ * characters (visual representation) into the original form.
+ * See also: unvis(1|3)
+ *
+ * Return values: 0 on success, 1 otherwise
+ */
+int unescape (char *str) {
+ int state = 0;
+ char out, *s = str, *t = str;
+
+ if (str == NULL)
+ return 1;
+
+ while (*s != '\0') {
+ again:
+ switch(unvis(&out, *s, &state, 0)) {
+ case 0:
+ case UNVIS_NOCHAR:
+ break;
+ case UNVIS_VALID:
+ *t++ = out;
+ break;
+ case UNVIS_VALIDPUSH:
+ *t++ = out;
+ goto again;
+ case UNVIS_SYNBAD:
+ return 1;
+ }
+ ++s;
+ }
+ *t = '\0';
+ return 0;
+}
+
static int
fstabscan()
{
@@ -102,9 +138,19 @@
if (*line == '#' || *line == '\n')
continue;
if (!strpbrk(p, " \t")) {
- _fs_fstab.fs_spec = strsep(&p, ":\n");
- _fs_fstab.fs_file = strsep(&p, ":\n");
+ cp = strsep(&p, ":\n");
+ if (!unescape (cp))
+ _fs_fstab.fs_spec = cp;
+ else
+ goto bad;
+
+ cp = strsep(&p, ":\n");
+ if (!unescape (cp))
+ _fs_fstab.fs_file = cp;
+ else
+ goto bad;
fixfsfile();
+
_fs_fstab.fs_type = strsep(&p, ":\n");
if (_fs_fstab.fs_type) {
if (!strcmp(_fs_fstab.fs_type, FSTAB_XX))
@@ -126,13 +172,21 @@
/* OLD_STYLE_FSTAB */
while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
;
- _fs_fstab.fs_spec = cp;
+ if (!unescape (cp))
+ _fs_fstab.fs_spec = cp;
+ else
+ goto bad;
if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#')
continue;
+
while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
;
- _fs_fstab.fs_file = cp;
+ if (!unescape (cp))
+ _fs_fstab.fs_file = cp;
+ else
+ goto bad;
fixfsfile();
+
while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
;
_fs_fstab.fs_vfstype = cp;
--- fstab.5.orig Mon Aug 18 17:50:43 2003
+++ fstab.5 Mon Aug 18 18:17:48 2003
@@ -10,7 +10,7 @@
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
+.\" must display the following acknowledgment:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
@@ -79,6 +79,19 @@
describes the mount point for the filesystem.
For swap partitions, this field should be specified as ``none''.
.Pp
+Both the
+.Fa fs_spec
+and the
+.Fa fs_file
+field may contain white spaces, that must be encoded in a
+.Xr vis 1 compatible way (you can run ``vis -wc'' or ``vis -w'' to
+encode the path names properly).
+Despite this ability to handle path names with with spaces, system
+administrators should avoid them wherever possible in order to keep
+file system and mount point specifications simple and clean.
+It is only only intended to provide compatibility with systems,
+where white spaces in path names are common (mostly SMB/CIFS shares).
+.Pp
The third field,
.Pq Fa fs_vfstype ,
describes the type of the filesystem.
@@ -109,6 +122,8 @@
.\" maybe also say Rock Ridge extensions are handled ?
.It Em procfs
a file system for accessing process data
+.It Em smbfs
+SMB/CIFS compatible network shares
.El
.Pp
The fourth field,
More information about the freebsd-bugs
mailing list