BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libc / gen / fstab.c
index dd5ea63..4c69dc3 100644 (file)
@@ -2,31 +2,49 @@
  * Copyright (c) 1980, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980, 1988 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that: (1) source distributions retain this entire copyright
- * notice and comment, and (2) distributions including binaries display
- * the following acknowledgement:  ``This product includes software
- * developed by the University of California, Berkeley and its contributors''
- * in the documentation or other materials provided with the distribution
- * and in all advertising materials mentioning features or use of this
- * software. Neither the name of the University nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    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:
+ *     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
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fstab.c    5.11 (Berkeley) 6/1/90";
+static char sccsid[] = "@(#)fstab.c    5.15 (Berkeley) 2/23/91";
 #endif /* LIBC_SCCS and not lint */
 
 #endif /* LIBC_SCCS and not lint */
 
+#include <sys/errno.h>
 #include <fstab.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <fstab.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 static FILE *_fs_fp;
 static struct fstab _fs_fstab;
 
 static FILE *_fs_fp;
 static struct fstab _fs_fstab;
+static error();
 
 static
 fstabscan()
 
 static
 fstabscan()
@@ -35,12 +53,34 @@ fstabscan()
 #define        MAXLINELENGTH   1024
        static char line[MAXLINELENGTH];
        char subline[MAXLINELENGTH];
 #define        MAXLINELENGTH   1024
        static char line[MAXLINELENGTH];
        char subline[MAXLINELENGTH];
-       char *fgets(), *strtok();
        int typexx;
 
        for (;;) {
                if (!(cp = fgets(line, sizeof(line), _fs_fp)))
                        return(0);
        int typexx;
 
        for (;;) {
                if (!(cp = fgets(line, sizeof(line), _fs_fp)))
                        return(0);
+/* OLD_STYLE_FSTAB */
+               if (!strpbrk(cp, " \t")) {
+                       _fs_fstab.fs_spec = strtok(cp, ":\n");
+                       _fs_fstab.fs_file = strtok((char *)NULL, ":\n");
+                       _fs_fstab.fs_type = strtok((char *)NULL, ":\n");
+                       if (_fs_fstab.fs_type) {
+                               if (!strcmp(_fs_fstab.fs_type, FSTAB_XX))
+                                       continue;
+                               _fs_fstab.fs_mntops = _fs_fstab.fs_type;
+                               _fs_fstab.fs_vfstype =
+                                   strcmp(_fs_fstab.fs_type, FSTAB_SW) ?
+                                   "ufs" : "swap";
+                               if (cp = strtok((char *)NULL, ":\n")) {
+                                       _fs_fstab.fs_freq = atoi(cp);
+                                       if (cp = strtok((char *)NULL, ":\n")) {
+                                               _fs_fstab.fs_passno = atoi(cp);
+                                               return(1);
+                                       }
+                               }
+                       }
+                       goto bad;
+               }
+/* OLD_STYLE_FSTAB */
                _fs_fstab.fs_spec = strtok(cp, " \t\n");
                if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#')
                        continue;
                _fs_fstab.fs_spec = strtok(cp, " \t\n");
                if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#')
                        continue;
@@ -87,12 +127,9 @@ fstabscan()
                        continue;
                if (cp != NULL)
                        return(1);
                        continue;
                if (cp != NULL)
                        return(1);
-       bad:
-               /* no way to distinguish between EOF and syntax error */
-               (void)write(STDERR_FILENO, "fstab: ", 7);
-               (void)write(STDERR_FILENO, _PATH_FSTAB,
-                   sizeof(_PATH_FSTAB) - 1);
-               (void)write(STDERR_FILENO, ": syntax error.\n", 16);
+
+bad:           /* no way to distinguish between EOF and syntax error */
+               error(EFTYPE);
        }
        /* NOTREACHED */
 }
        }
        /* NOTREACHED */
 }
@@ -107,7 +144,7 @@ getfsent()
 
 struct fstab *
 getfsspec(name)
 
 struct fstab *
 getfsspec(name)
-       register char *name;
+       register const char *name;
 {
        if (setfsent())
                while (fstabscan())
 {
        if (setfsent())
                while (fstabscan())
@@ -118,7 +155,7 @@ getfsspec(name)
 
 struct fstab *
 getfsfile(name)
 
 struct fstab *
 getfsfile(name)
-       register char *name;
+       register const char *name;
 {
        if (setfsent())
                while (fstabscan())
 {
        if (setfsent())
                while (fstabscan())
@@ -133,7 +170,10 @@ setfsent()
                rewind(_fs_fp);
                return(1);
        }
                rewind(_fs_fp);
                return(1);
        }
-       return((_fs_fp = fopen(_PATH_FSTAB, "r")) != NULL);
+       if (_fs_fp = fopen(_PATH_FSTAB, "r"))
+               return(1);
+       error(errno);
+       return(0);
 }
 
 void
 }
 
 void
@@ -144,3 +184,16 @@ endfsent()
                _fs_fp = NULL;
        }
 }
                _fs_fp = NULL;
        }
 }
+
+static
+error(err)
+       int err;
+{
+       char *p;
+
+       (void)write(STDERR_FILENO, "fstab: ", 7);
+       (void)write(STDERR_FILENO, _PATH_FSTAB, sizeof(_PATH_FSTAB) - 1);
+       p = strerror(err);
+       (void)write(STDERR_FILENO, p, strlen(p));
+       (void)write(STDERR_FILENO, "\n", 1);
+}