2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A#include "lint.h"
2N/A#include <mtlib.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <errno.h>
2N/A#include <sys/types.h>
2N/A#include <sys/stat.h>
2N/A#include <sys/vfstab.h>
2N/A#include <string.h>
2N/A#include <thread.h>
2N/A#include <synch.h>
2N/A#include <strings.h>
2N/A#include <libc.h>
2N/A#include "tsd.h"
2N/A
2N/A
2N/A#define GETTOK_R(xx, ll, tmp)\
2N/A if ((vp->xx = (char *)strtok_r(ll, sepstr, tmp)) == NULL)\
2N/A return (VFS_TOOFEW);\
2N/A if (strcmp(vp->xx, dash) == 0)\
2N/A vp->xx = NULL
2N/A#define GETTOK(xx, ll)\
2N/A if ((vp->xx = strtok(ll, sepstr)) == NULL)\
2N/A return (VFS_TOOFEW);\
2N/A if (strcmp(vp->xx, dash) == 0)\
2N/A vp->xx = NULL
2N/A#define DIFF(xx)\
2N/A (vrefp->xx != NULL && (vgetp->xx == NULL ||\
2N/A strcmp(vrefp->xx, vgetp->xx) != 0))
2N/A#define SDIFF(xx, typem, typer)\
2N/A (vgetp->xx == NULL || stat64(vgetp->xx, &statb) == -1 ||\
2N/A (statb.st_mode & S_IFMT) != typem ||\
2N/A statb.st_rdev != typer)
2N/A
2N/Astatic const char sepstr[] = " \t\n";
2N/Astatic const char dash[] = "-";
2N/A
2N/Astatic int getaline(char *, FILE *);
2N/A
2N/Aint
2N/Agetvfsspec(FILE *fd, struct vfstab *vgetp, char *special)
2N/A{
2N/A int ret, bstat;
2N/A mode_t bmode;
2N/A dev_t brdev;
2N/A struct stat64 statb;
2N/A
2N/A
2N/A if (special && stat64(special, &statb) == 0 &&
2N/A ((bmode = (statb.st_mode & S_IFMT)) == S_IFBLK ||
2N/A bmode == S_IFCHR)) {
2N/A bstat = 1;
2N/A brdev = statb.st_rdev;
2N/A } else
2N/A bstat = 0;
2N/A
2N/A while ((ret = getvfsent(fd, vgetp)) == 0 &&
2N/A ((bstat == 0 &&
2N/A (special != NULL && (vgetp->vfs_special == NULL ||
2N/A strcmp(special, vgetp->vfs_special) != 0))) ||
2N/A (bstat == 1 &&
2N/A (vgetp->vfs_special == NULL ||
2N/A stat64(vgetp->vfs_special, &statb) == -1 ||
2N/A (statb.st_mode & S_IFMT) != bmode ||
2N/A statb.st_rdev != brdev))))
2N/A ;
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/Agetvfsfile(FILE *fd, struct vfstab *vp, char *mountp)
2N/A{
2N/A struct vfstab vv;
2N/A
2N/A bzero(&vv, (size_t)sizeof (vv));
2N/A vv.vfs_mountp = mountp;
2N/A return (getvfsany(fd, vp, &vv));
2N/A}
2N/A
2N/Aint
2N/Agetvfsany(FILE *fd, struct vfstab *vgetp, struct vfstab *vrefp)
2N/A{
2N/A int ret, bstat, cstat;
2N/A mode_t bmode, cmode;
2N/A dev_t brdev, crdev;
2N/A struct stat64 statb;
2N/A off64_t start = ftello64(fd);
2N/A
2N/A /* Match by straight strcmp */
2N/A while ((ret = getvfsent(fd, vgetp)) == 0 &&
2N/A (DIFF(vfs_special) || DIFF(vfs_fsckdev) ||
2N/A DIFF(vfs_mountp) ||
2N/A DIFF(vfs_fstype) ||
2N/A DIFF(vfs_fsckpass) ||
2N/A DIFF(vfs_automnt) ||
2N/A DIFF(vfs_mntopts)))
2N/A ;
2N/A
2N/A /* If something other than EOF, return it */
2N/A if (ret != -1)
2N/A return (ret);
2N/A
2N/A /*
2N/A * Go back to the original location in the file and try to
2N/A * match the devices by doing stat's (retains compatibility
2N/A * with original getvfsany).
2N/A */
2N/A (void) fseeko64(fd, start, SEEK_SET);
2N/A
2N/A if (vrefp->vfs_special && stat64(vrefp->vfs_special, &statb) == 0 &&
2N/A ((bmode = (statb.st_mode & S_IFMT)) == S_IFBLK ||
2N/A bmode == S_IFCHR)) {
2N/A bstat = 1;
2N/A brdev = statb.st_rdev;
2N/A } else
2N/A bstat = 0;
2N/A
2N/A if (vrefp->vfs_fsckdev && stat64(vrefp->vfs_fsckdev, &statb) == 0 &&
2N/A ((cmode = (statb.st_mode & S_IFMT)) == S_IFBLK ||
2N/A cmode == S_IFCHR)) {
2N/A cstat = 1;
2N/A crdev = statb.st_rdev;
2N/A } else
2N/A cstat = 0;
2N/A
2N/A while ((ret = getvfsent(fd, vgetp)) == 0 &&
2N/A ((bstat == 0 && DIFF(vfs_special)) ||
2N/A (bstat == 1 && SDIFF(vfs_special, bmode, brdev)) ||
2N/A (cstat == 0 && DIFF(vfs_fsckdev)) ||
2N/A (cstat == 1 && SDIFF(vfs_fsckdev, cmode, crdev)) ||
2N/A DIFF(vfs_mountp) ||
2N/A DIFF(vfs_fstype) ||
2N/A DIFF(vfs_fsckpass) ||
2N/A DIFF(vfs_automnt) ||
2N/A DIFF(vfs_mntopts)))
2N/A ;
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/Agetvfsent(FILE *fd, struct vfstab *vp)
2N/A{
2N/A int ret;
2N/A char *tmp, *line;
2N/A
2N/A line = tsdalloc(_T_GETVFSENT, VFS_LINE_MAX, NULL);
2N/A if (line == NULL)
2N/A return (0);
2N/A
2N/A /* skip leading spaces and comments */
2N/A if ((ret = getaline(line, fd)) != 0)
2N/A return (ret);
2N/A
2N/A /* split up each field */
2N/A GETTOK_R(vfs_special, line, &tmp);
2N/A GETTOK_R(vfs_fsckdev, NULL, &tmp);
2N/A GETTOK_R(vfs_mountp, NULL, &tmp);
2N/A GETTOK_R(vfs_fstype, NULL, &tmp);
2N/A GETTOK_R(vfs_fsckpass, NULL, &tmp);
2N/A GETTOK_R(vfs_automnt, NULL, &tmp);
2N/A GETTOK_R(vfs_mntopts, NULL, &tmp);
2N/A
2N/A /* check for too many fields */
2N/A if (strtok_r(NULL, sepstr, &tmp) != NULL)
2N/A return (VFS_TOOMANY);
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Astatic int
2N/Agetaline(char *lp, FILE *fd)
2N/A{
2N/A char *cp;
2N/A
2N/A while ((lp = fgets(lp, VFS_LINE_MAX, fd)) != NULL) {
2N/A if (strlen(lp) == VFS_LINE_MAX-1 && lp[VFS_LINE_MAX-2] != '\n')
2N/A return (VFS_TOOLONG);
2N/A
2N/A for (cp = lp; *cp == ' ' || *cp == '\t'; cp++)
2N/A ;
2N/A
2N/A if (*cp != '#' && *cp != '\n')
2N/A return (0);
2N/A }
2N/A return (-1);
2N/A}