From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 1 08:31:45 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C9CED37B401 for ; Fri, 1 Aug 2003 08:31:45 -0700 (PDT) Received: from mailout.informatik.tu-muenchen.de (mailout.informatik.tu-muenchen.de [131.159.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id C143743FD7 for ; Fri, 1 Aug 2003 08:31:44 -0700 (PDT) (envelope-from barner@in.tum.de) Received: by zi025.glhnet.mhn.de (Postfix, from userid 1000) id 25B5938AB5; Fri, 1 Aug 2003 17:31:43 +0200 (CEST) Date: Fri, 1 Aug 2003 17:31:42 +0200 From: Simon Barner To: Murray Taylor Message-ID: <20030801153142.GA487@zi025.glhnet.mhn.de> References: <20030730224505.GD531@zi025.glhnet.mhn.de> <1059607242.64020.5.camel@mjtdev1.dand06.au.bytecraft.au.com> <3F285560.2090607@acm.org> <1059608748.64020.10.camel@mjtdev1.dand06.au.bytecraft.au.com> <002201c356fa$4a66a700$1200a8c0@gsicomp.on.ca> <20030731134343.GB1323@zi025.glhnet.mhn.de> <1059693358.64020.31.camel@mjtdev1.dand06.au.bytecraft.au.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+pHx0qQiF2pBVqBT" Content-Disposition: inline In-Reply-To: <1059693358.64020.31.camel@mjtdev1.dand06.au.bytecraft.au.com> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at informatik.tu-muenchen.de cc: freebsd-hackers@freebsd.org cc: Heiner cc: Matthew Emmerton cc: kientzle@acm.org Subject: [patch] Re: getfsent(3) and spaces in fstab X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Aug 2003 15:31:46 -0000 --+pHx0qQiF2pBVqBT Content-Type: multipart/mixed; boundary="IJpNTDwzlM2Ie8A6" Content-Disposition: inline --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, > For all the 'good rules' of orthonogolity and consistency etc=20 > it is a good thing, however I still feel that at the level of > the fstab where you are mounting entire file system trees,=20 > the simplest naming formats are probably the best.=20 > A philosophical point only, but it would keep the fstab format > minimalistic and clean. >=20 > This point of view could probably be stated in the man page once > the '\ ' form is implemented, as a suggested practice. Yes, you are definitely right with this point, and I aggree that such a hint should be added to the fstab(5) man page. But as somebody else pointed out, one of FreeBSD's advantages is its interoperability with other systems, and this was one of the reasons why I decided to extent 'getfsent'. The attached patch will allow blanks and tabs for file systems and path names, as long as the are protected by a '\'. For the old fstab style, blanks and tabs are not allowed as delimiters (as it was in the old implementation). Thus /foo\ bar:/mnt\ point:ufs is a valid old-style fstab entry, while /foo\ bar:/mnt\ point:ufs /foo\ bar :/mnt\ point:ufs etc. are not. For the current fstab style, unescaped blanks and tabs are handled as delimiters. Simon --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch-fstab.c" Content-Transfer-Encoding: quoted-printable --- fstab.c.orig Fri Aug 1 17:18:00 2003 +++ fstab.c Fri Aug 1 17:17:46 2003 @@ -84,6 +84,78 @@ _fs_fstab.fs_spec =3D buf; } =20 +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, es_strsep returns NULL. + * + * In contrast to strsep(3), es_strsep will allow escaped delimiters + * within a token. + */ +char * +es_strsep(char **stringp, const char *delim) +{ + char *s, *t; + size_t n; + + if (*stringp =3D=3D '\0') /* empty string */ + return NULL; + s =3D *stringp; + s +=3D strspn (s, delim); /* skip delimiters */ + + if (*s =3D=3D '\0') /* string consists only of delimiters */ + return NULL; +=09 + /* skip a string consisting of non-delimiters or escapted delimiters */ + t =3D s; + for (;;) { + /* skip non-delimiters */ + n =3D strcspn (t, delim); + if (n =3D=3D 0) /* delimiters found -> end of token */ + break; + t +=3D n; + if (*t =3D=3D '\0') /* end of string reached */ + break; + + /* skip escaped delimiters */ + if (*(t-1) =3D=3D '\\') /* n !=3D 0 =3D> *(t-1) is valid */ + ++t; + if (*t =3D=3D '\0') /* end of string reached */ + break; + } + + if (*t !=3D '\0') { + *t =3D '\0'; /* end current token */ + *stringp =3D t+1; /* *t !=3D '\0' =3D> *(t+1) is valid */ + } else + *stringp =3D 0; /* end of string reached */=09 +=09 + return s; /* return current token */ +} + +/* + * This function removes all '\' characters from a string. + * + * It will NOT handle escape sequences as '\t' or '\n'! + */ +void +remove_escapes (char **s) { + char *p =3D *s, *q; + while ((p =3D strchr (p, '\\')) !=3D 0) { + q =3D p; + while (q[0] !=3D '\0') { + q[0] =3D q[1]; + ++q; + } + } +} + static int fstabscan() { @@ -101,9 +173,17 @@ ++LineNo; if (*line =3D=3D '#' || *line =3D=3D '\n') continue; - if (!strpbrk(p, " \t")) { + + /* escapted white-spaces only are allowed in old-style format */ + cp =3D p; + while ((cp =3D strpbrk(cp, " \t")) !=3D 0 && + cp !=3D p && cp[-1] =3D=3D '\\') + ++cp; + if (cp =3D=3D 0) { _fs_fstab.fs_spec =3D strsep(&p, ":\n"); + remove_escapes (&_fs_fstab.fs_spec); _fs_fstab.fs_file =3D strsep(&p, ":\n"); + remove_escapes (&_fs_fstab.fs_file); fixfsfile(); _fs_fstab.fs_type =3D strsep(&p, ":\n"); if (_fs_fstab.fs_type) { @@ -124,14 +204,18 @@ goto bad; } /* OLD_STYLE_FSTAB */ - while ((cp =3D strsep(&p, " \t\n")) !=3D NULL && *cp =3D=3D '\0') + while ((cp =3D es_strsep(&p, " \t\n")) !=3D NULL && *cp =3D=3D '\0') ; _fs_fstab.fs_spec =3D cp; + remove_escapes (&_fs_fstab.fs_spec); if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec =3D=3D '#') continue; - while ((cp =3D strsep(&p, " \t\n")) !=3D NULL && *cp =3D=3D '\0') + while ((cp =3D es_strsep(&p, " \t\n")) !=3D NULL && *cp =3D=3D '\0') ; + if (cp =3D=3D 0) + goto bad; _fs_fstab.fs_file =3D cp; + remove_escapes (&_fs_fstab.fs_file); fixfsfile(); while ((cp =3D strsep(&p, " \t\n")) !=3D NULL && *cp =3D=3D '\0') ; --IJpNTDwzlM2Ie8A6-- --+pHx0qQiF2pBVqBT Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/KofeCkn+/eutqCoRAgt+AJ9DKsEejpZiy5nRX04OT6C/cmOECACcCv5w f5BpKR++a2sRB/x35hxCg9A= =4J7m -----END PGP SIGNATURE----- --+pHx0qQiF2pBVqBT--