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, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * 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) 1992, 1993, 1994, 2000 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * Caching stat function
2N/A */
2N/A
2N/A#include <meta.h>
2N/A
2N/A#define MD_NUM_STAT_HEAD 16
2N/A
2N/Astruct statcache {
2N/A struct statcache *sc_next;
2N/A struct stat sc_stat;
2N/A char *sc_filename;
2N/A};
2N/A
2N/Astatic struct statcache *statcache_head[MD_NUM_STAT_HEAD] =
2N/A {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2N/A
2N/Aint
2N/Ameta_stat(const char *filename, struct stat *sbp)
2N/A{
2N/A struct statcache *scp;
2N/A int hash;
2N/A char *cp;
2N/A
2N/A hash = 0;
2N/A for (cp = (char *)filename; *cp != 0; cp++)
2N/A hash += *cp;
2N/A
2N/A hash &= 0xf;
2N/A
2N/A for (scp = statcache_head[hash]; scp != NULL; scp = scp->sc_next)
2N/A if (strcmp(filename, scp->sc_filename) == 0)
2N/A break;
2N/A if (scp) {
2N/A (void) memcpy((caddr_t)sbp, (caddr_t)&scp->sc_stat,
2N/A sizeof (*sbp));
2N/A return (0);
2N/A }
2N/A if (stat(filename, sbp) != 0)
2N/A return (-1);
2N/A
2N/A if (!S_ISBLK(sbp->st_mode) && !S_ISCHR(sbp->st_mode))
2N/A return (-1);
2N/A
2N/A scp = (struct statcache *)malloc(sizeof (*scp));
2N/A if (scp != NULL) {
2N/A (void) memcpy((caddr_t)&scp->sc_stat, (caddr_t)sbp,
2N/A sizeof (*sbp));
2N/A scp->sc_filename = strdup(filename);
2N/A if (scp->sc_filename == NULL) {
2N/A free((char *)scp);
2N/A return (0);
2N/A }
2N/A scp->sc_next = statcache_head[hash];
2N/A statcache_head[hash] = scp;
2N/A }
2N/A return (0);
2N/A}
2N/A
2N/Avoid
2N/Ametaflushstatcache(void)
2N/A{
2N/A struct statcache *p, *n;
2N/A int i;
2N/A
2N/A for (i = 0; i < MD_NUM_STAT_HEAD; i++) {
2N/A for (p = statcache_head[i], n = NULL; p != NULL; p = n) {
2N/A n = p->sc_next;
2N/A Free(p->sc_filename);
2N/A Free(p);
2N/A }
2N/A statcache_head[i] = NULL;
2N/A }
2N/A}