17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*47644099Sgt29601 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate *
317c478bd9Sstevel@tonic-gate * stats_create.c
327c478bd9Sstevel@tonic-gate *
337c478bd9Sstevel@tonic-gate * Routines for the `clean interface' to cachefs statistics.
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #include <stdarg.h>
377c478bd9Sstevel@tonic-gate #include <libintl.h>
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
397c478bd9Sstevel@tonic-gate #include <sys/stat.h>
407c478bd9Sstevel@tonic-gate #include <assert.h>
417c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
427c478bd9Sstevel@tonic-gate #include <string.h>
437c478bd9Sstevel@tonic-gate #include "stats.h"
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate void *malloc(), *calloc();
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate /* forward declarations of statics */
487c478bd9Sstevel@tonic-gate static stats_cookie_t *stats_create(char *);
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate static stats_cookie_t *
stats_create(char * progname)517c478bd9Sstevel@tonic-gate stats_create(char *progname)
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate stats_cookie_t *rc;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate if ((rc = (stats_cookie_t *)calloc(1, sizeof (*rc))) == NULL)
567c478bd9Sstevel@tonic-gate goto out;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate rc->st_magic = STATS_MAGIC;
597c478bd9Sstevel@tonic-gate if (rc->st_progname = strrchr(progname, '/'))
607c478bd9Sstevel@tonic-gate rc->st_progname++;
617c478bd9Sstevel@tonic-gate else
627c478bd9Sstevel@tonic-gate rc->st_progname = progname;
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate if ((rc->st_kstat_cookie = kstat_open()) == NULL) {
657c478bd9Sstevel@tonic-gate stats_perror(rc, SE_KERNEL,
667c478bd9Sstevel@tonic-gate gettext("Cannot initialize kstats"));
677c478bd9Sstevel@tonic-gate goto out;
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate out:
717c478bd9Sstevel@tonic-gate return (rc);
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate stats_cookie_t *
stats_create_unbound(char * progname)757c478bd9Sstevel@tonic-gate stats_create_unbound(char *progname)
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate stats_cookie_t *st;
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate if ((st = stats_create(progname)) == NULL)
807c478bd9Sstevel@tonic-gate goto out;
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate st->st_flags |= ST_VALID;
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate out:
857c478bd9Sstevel@tonic-gate return (st);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate stats_cookie_t *
stats_create_mountpath(char * mountpath,char * progname)897c478bd9Sstevel@tonic-gate stats_create_mountpath(char *mountpath, char *progname)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate stats_cookie_t *st;
927c478bd9Sstevel@tonic-gate kstat_t *key;
937c478bd9Sstevel@tonic-gate cachefs_kstat_key_t *k;
947c478bd9Sstevel@tonic-gate dev_t dev;
957c478bd9Sstevel@tonic-gate ino64_t ino;
967c478bd9Sstevel@tonic-gate struct stat64 s;
977c478bd9Sstevel@tonic-gate int i, n;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate if ((st = stats_create(progname)) == NULL)
1007c478bd9Sstevel@tonic-gate goto out;
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate if ((key = kstat_lookup(st->st_kstat_cookie, "cachefs", 0, "key"))
1037c478bd9Sstevel@tonic-gate == NULL) {
1047c478bd9Sstevel@tonic-gate stats_perror(st, SE_KERNEL,
1057c478bd9Sstevel@tonic-gate gettext("Cannot lookup cachefs key kstat"));
1067c478bd9Sstevel@tonic-gate goto out;
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate if (kstat_read(st->st_kstat_cookie, key, NULL) < 0) {
1097c478bd9Sstevel@tonic-gate stats_perror(st, SE_KERNEL,
1107c478bd9Sstevel@tonic-gate gettext("Cannot read cachefs key kstat"));
1117c478bd9Sstevel@tonic-gate goto out;
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate k = (cachefs_kstat_key_t *)key->ks_data;
1147c478bd9Sstevel@tonic-gate n = key->ks_ndata;
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate if (stat64(mountpath, &s) != 0) {
1177c478bd9Sstevel@tonic-gate stats_perror(st, SE_FILE,
1187c478bd9Sstevel@tonic-gate gettext("Cannot stat %s"), mountpath);
1197c478bd9Sstevel@tonic-gate goto out;
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate ino = s.st_ino;
1227c478bd9Sstevel@tonic-gate dev = s.st_dev;
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) {
1257c478bd9Sstevel@tonic-gate k[i].ks_mountpoint += (uintptr_t)k;
1267c478bd9Sstevel@tonic-gate k[i].ks_backfs += (uintptr_t)k;
1277c478bd9Sstevel@tonic-gate k[i].ks_cachedir += (uintptr_t)k;
1287c478bd9Sstevel@tonic-gate k[i].ks_cacheid += (uintptr_t)k;
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate if (! k[i].ks_mounted)
1317c478bd9Sstevel@tonic-gate continue;
1327c478bd9Sstevel@tonic-gate
133*47644099Sgt29601 if ((stat64((char *)(uintptr_t)k[i].ks_mountpoint, &s) == 0) &&
1347c478bd9Sstevel@tonic-gate (s.st_dev == dev) &&
1357c478bd9Sstevel@tonic-gate (s.st_ino == ino))
1367c478bd9Sstevel@tonic-gate break;
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate if (i >= n) {
1407c478bd9Sstevel@tonic-gate stats_perror(st, SE_FILE,
1417c478bd9Sstevel@tonic-gate gettext("%s: not a cachefs mountpoint"), mountpath);
1427c478bd9Sstevel@tonic-gate goto out;
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate st->st_fsid = k[i].ks_id;
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate st->st_flags |= ST_VALID | ST_BOUND;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate out:
1507c478bd9Sstevel@tonic-gate return (st);
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * stats_next - bind the cookie to the next valid cachefs mount.
1557c478bd9Sstevel@tonic-gate *
1567c478bd9Sstevel@tonic-gate * returns cachefs_kstat_key_t *, which gives all the info you need.
1577c478bd9Sstevel@tonic-gate * returns NULL if we're out of mounts, or if an error occured.
1587c478bd9Sstevel@tonic-gate * returns malloc()ed data, which the client has to free() itself.
1597c478bd9Sstevel@tonic-gate */
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate cachefs_kstat_key_t *
stats_next(stats_cookie_t * st)1627c478bd9Sstevel@tonic-gate stats_next(stats_cookie_t *st)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate kstat_t *key;
1657c478bd9Sstevel@tonic-gate cachefs_kstat_key_t *k, *prc = NULL, *rc = NULL;
1667c478bd9Sstevel@tonic-gate int i, n;
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate assert(stats_good(st));
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate if (((key = kstat_lookup(st->st_kstat_cookie, "cachefs", 0,
1717c478bd9Sstevel@tonic-gate "key")) == NULL) ||
1727c478bd9Sstevel@tonic-gate (kstat_read(st->st_kstat_cookie, key, NULL) < 0)) {
1737c478bd9Sstevel@tonic-gate stats_perror(st, SE_KERNEL,
1747c478bd9Sstevel@tonic-gate gettext("Cannot get cachefs key kstat"));
1757c478bd9Sstevel@tonic-gate goto out;
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate k = (cachefs_kstat_key_t *)key->ks_data;
1787c478bd9Sstevel@tonic-gate n = key->ks_ndata;
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate if (st->st_flags & ST_BOUND) {
1817c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++)
1827c478bd9Sstevel@tonic-gate if (st->st_fsid == k[i].ks_id)
1837c478bd9Sstevel@tonic-gate break;
1847c478bd9Sstevel@tonic-gate ++i;
1857c478bd9Sstevel@tonic-gate if (i < n) {
1867c478bd9Sstevel@tonic-gate prc = k + i;
1877c478bd9Sstevel@tonic-gate st->st_fsid = k[i].ks_id;
1887c478bd9Sstevel@tonic-gate } else
1897c478bd9Sstevel@tonic-gate st->st_flags &= ~ST_BOUND;
1907c478bd9Sstevel@tonic-gate } else if (n > 0) {
1917c478bd9Sstevel@tonic-gate st->st_fsid = k[0].ks_id;
1927c478bd9Sstevel@tonic-gate st->st_flags |= ST_BOUND;
1937c478bd9Sstevel@tonic-gate prc = k;
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate out:
1977c478bd9Sstevel@tonic-gate if (prc != NULL) {
1987c478bd9Sstevel@tonic-gate char *s;
1997c478bd9Sstevel@tonic-gate int size;
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate prc->ks_mountpoint += (uintptr_t)k;
2027c478bd9Sstevel@tonic-gate prc->ks_backfs += (uintptr_t)k;
2037c478bd9Sstevel@tonic-gate prc->ks_cachedir += (uintptr_t)k;
2047c478bd9Sstevel@tonic-gate prc->ks_cacheid += (uintptr_t)k;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate size = sizeof (*rc);
207*47644099Sgt29601 size += strlen((char *)(uintptr_t)prc->ks_mountpoint) + 1;
208*47644099Sgt29601 size += strlen((char *)(uintptr_t)prc->ks_backfs) + 1;
209*47644099Sgt29601 size += strlen((char *)(uintptr_t)prc->ks_cachedir) + 1;
210*47644099Sgt29601 size += strlen((char *)(uintptr_t)prc->ks_cacheid) + 1;
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate if ((rc = (cachefs_kstat_key_t *)
2137c478bd9Sstevel@tonic-gate malloc(size)) == NULL) {
2147c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
2157c478bd9Sstevel@tonic-gate gettext("Cannot malloc return code"));
2167c478bd9Sstevel@tonic-gate } else {
2177c478bd9Sstevel@tonic-gate memcpy(rc, prc, sizeof (*rc));
2187c478bd9Sstevel@tonic-gate s = (char *)((uintptr_t)rc + sizeof (*rc));
2197c478bd9Sstevel@tonic-gate
220*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)prc->ks_mountpoint);
2217c478bd9Sstevel@tonic-gate rc->ks_mountpoint = (uintptr_t)s;
2227c478bd9Sstevel@tonic-gate s += strlen(s) + 1;
223*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)prc->ks_backfs);
2247c478bd9Sstevel@tonic-gate rc->ks_backfs = (uintptr_t)s;
2257c478bd9Sstevel@tonic-gate s += strlen(s) + 1;
226*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)prc->ks_cachedir);
2277c478bd9Sstevel@tonic-gate rc->ks_cachedir = (uintptr_t)s;
2287c478bd9Sstevel@tonic-gate s += strlen(s) + 1;
229*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)prc->ks_cacheid);
2307c478bd9Sstevel@tonic-gate rc->ks_cacheid = (uintptr_t)s;
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate return (rc);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate cachefs_kstat_key_t *
stats_getkey(stats_cookie_t * st)2387c478bd9Sstevel@tonic-gate stats_getkey(stats_cookie_t *st)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate kstat_t *ksp;
2417c478bd9Sstevel@tonic-gate cachefs_kstat_key_t *k, *key, *rc = NULL;
2427c478bd9Sstevel@tonic-gate int size;
2437c478bd9Sstevel@tonic-gate char *s;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate assert(stats_good(st));
2467c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_BOUND);
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate if (((ksp = kstat_lookup(st->st_kstat_cookie, "cachefs", 0,
2497c478bd9Sstevel@tonic-gate "key")) == NULL) ||
2507c478bd9Sstevel@tonic-gate (kstat_read(st->st_kstat_cookie, ksp, NULL) < 0)) {
2517c478bd9Sstevel@tonic-gate stats_perror(st, SE_KERNEL,
2527c478bd9Sstevel@tonic-gate gettext("Cannot get cachefs key kstat"));
2537c478bd9Sstevel@tonic-gate goto out;
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate key = (cachefs_kstat_key_t *)ksp->ks_data;
2567c478bd9Sstevel@tonic-gate k = key + st->st_fsid - 1;
2577c478bd9Sstevel@tonic-gate k->ks_mountpoint += (uintptr_t)key;
2587c478bd9Sstevel@tonic-gate k->ks_backfs += (uintptr_t)key;
2597c478bd9Sstevel@tonic-gate k->ks_cachedir += (uintptr_t)key;
2607c478bd9Sstevel@tonic-gate k->ks_cacheid += (uintptr_t)key;
2617c478bd9Sstevel@tonic-gate size = sizeof (*rc);
262*47644099Sgt29601 size += strlen((char *)(uintptr_t)k->ks_mountpoint) + 1;
263*47644099Sgt29601 size += strlen((char *)(uintptr_t)k->ks_backfs) + 1;
264*47644099Sgt29601 size += strlen((char *)(uintptr_t)k->ks_cachedir) + 1;
265*47644099Sgt29601 size += strlen((char *)(uintptr_t)k->ks_cacheid) + 1;
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if ((rc = (cachefs_kstat_key_t *)malloc(size)) == NULL)
2687c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
2697c478bd9Sstevel@tonic-gate gettext("Cannot malloc return code"));
2707c478bd9Sstevel@tonic-gate else {
2717c478bd9Sstevel@tonic-gate memcpy(rc, k, sizeof (*rc));
2727c478bd9Sstevel@tonic-gate s = (char *)((uintptr_t)rc + sizeof (*rc));
2737c478bd9Sstevel@tonic-gate
274*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)k->ks_mountpoint);
2757c478bd9Sstevel@tonic-gate rc->ks_mountpoint = (uintptr_t)s;
2767c478bd9Sstevel@tonic-gate s += strlen(s) + 1;
277*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)k->ks_backfs);
2787c478bd9Sstevel@tonic-gate rc->ks_backfs = (uintptr_t)s;
2797c478bd9Sstevel@tonic-gate s += strlen(s) + 1;
280*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)k->ks_cachedir);
2817c478bd9Sstevel@tonic-gate rc->ks_cachedir = (uintptr_t)s;
2827c478bd9Sstevel@tonic-gate s += strlen(s) + 1;
283*47644099Sgt29601 (void) strcpy(s, (char *)(uintptr_t)k->ks_cacheid);
2847c478bd9Sstevel@tonic-gate rc->ks_cacheid = (uintptr_t)s;
2857c478bd9Sstevel@tonic-gate s += strlen(s) + 1;
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate assert(rc->ks_id == st->st_fsid);
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate out:
2917c478bd9Sstevel@tonic-gate return (rc);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate void
stats_destroy(stats_cookie_t * st)2957c478bd9Sstevel@tonic-gate stats_destroy(stats_cookie_t *st)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate void free();
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate if (st == NULL)
3007c478bd9Sstevel@tonic-gate return;
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate if (st->st_kstat_cookie != NULL)
3037c478bd9Sstevel@tonic-gate kstat_close(st->st_kstat_cookie);
3047c478bd9Sstevel@tonic-gate if (st->st_logxdr.x_ops != NULL)
3057c478bd9Sstevel@tonic-gate xdr_destroy(&st->st_logxdr);
3067c478bd9Sstevel@tonic-gate if ((st->st_logstream != NULL) && (st->st_flags & ST_LFOPEN))
3077c478bd9Sstevel@tonic-gate (void) fclose(st->st_logstream);
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate * we don't want to depend on dbm (or stats_dbm), so we don't
3117c478bd9Sstevel@tonic-gate * do a stats_dbm_close. we do try to require the client to
3127c478bd9Sstevel@tonic-gate * have done it, via an assert(), however.
3137c478bd9Sstevel@tonic-gate */
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate assert(! (st->st_flags & ST_DBMOPEN));
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate st->st_magic++;
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate free(st);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate int
stats_good(stats_cookie_t * st)3237c478bd9Sstevel@tonic-gate stats_good(stats_cookie_t *st)
3247c478bd9Sstevel@tonic-gate {
3257c478bd9Sstevel@tonic-gate if (st == NULL)
3267c478bd9Sstevel@tonic-gate return (0);
3277c478bd9Sstevel@tonic-gate if (st->st_magic != STATS_MAGIC)
3287c478bd9Sstevel@tonic-gate return (0);
3297c478bd9Sstevel@tonic-gate if (! (st->st_flags & ST_VALID))
3307c478bd9Sstevel@tonic-gate return (0);
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate return (1);
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate void
3367c478bd9Sstevel@tonic-gate /*PRINTFLIKE3*/
stats_perror(stats_cookie_t * st,int Errno,char * fmt,...)3377c478bd9Sstevel@tonic-gate stats_perror(stats_cookie_t *st, int Errno, char *fmt, ...)
3387c478bd9Sstevel@tonic-gate {
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate va_list ap;
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate assert(st != NULL);
3437c478bd9Sstevel@tonic-gate assert(st->st_magic == STATS_MAGIC);
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate va_start(ap, fmt);
3467c478bd9Sstevel@tonic-gate (void) vsnprintf(st->st_errorstr, sizeof (st->st_errorstr), fmt, ap);
3477c478bd9Sstevel@tonic-gate va_end(ap);
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate st->st_errno = Errno;
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate st->st_flags |= ST_ERROR;
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate char *
stats_errorstr(stats_cookie_t * st)3557c478bd9Sstevel@tonic-gate stats_errorstr(stats_cookie_t *st)
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate assert(st != NULL);
3587c478bd9Sstevel@tonic-gate assert(st->st_magic == STATS_MAGIC);
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate return (st->st_errorstr);
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate int
stats_errno(stats_cookie_t * st)3647c478bd9Sstevel@tonic-gate stats_errno(stats_cookie_t *st)
3657c478bd9Sstevel@tonic-gate {
3667c478bd9Sstevel@tonic-gate assert(st != NULL);
3677c478bd9Sstevel@tonic-gate assert(st->st_magic == STATS_MAGIC);
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate return (st->st_errno);
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate int
stats_inerror(stats_cookie_t * st)3737c478bd9Sstevel@tonic-gate stats_inerror(stats_cookie_t *st)
3747c478bd9Sstevel@tonic-gate {
3757c478bd9Sstevel@tonic-gate assert(st != NULL);
3767c478bd9Sstevel@tonic-gate assert(st->st_magic == STATS_MAGIC);
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate return (st->st_flags & ST_ERROR);
3797c478bd9Sstevel@tonic-gate }
380