kstat.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>
#include <memory.h>
#include <strings.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <poll.h>
#include "kstat.h"
/*LINTLIBRARY*/
static void
{
if (free_first)
}
static void
{
while (ksp) {
}
kc->kc_chain_id = 0;
}
kstat_open(void)
{
int kd;
if (kd == -1)
return (NULL);
return (NULL);
kc->kc_chain_id = 0;
(void) kstat_close(kc);
return (NULL);
}
return (kc);
}
int
{
int rc;
return (rc);
}
{
return (-1);
}
continue; /* and try again */
}
/*
* Mating dance for variable-size kstats.
* You start with a buffer of a certain size,
* which you hope will hold all the data.
* If your buffer is too small, the kstat driver
* returns ENOMEM and sets ksp->ks_data_size to
* the current size of the kstat's data. You then
* resize your buffer and try again. In practice,
* this almost always converges in two passes.
*/
continue;
}
return (-1);
}
ksp->ks_data_size !=
/*
* Has KSTAT_DATA_STRING fields. Fix the pointers.
*/
uint_t i;
continue;
continue;
/*
* The offsets of the strings within the
* buffers are the same, so add the offset of
* the string to the beginning of 'data' to fix
* the pointer so that strings in 'data' don't
* point at memory in 'ksp->ks_data'.
*/
}
}
}
return (kcid);
}
{
return (-1);
}
uint_t i;
continue;
continue;
/*
* The buffer passed in as 'data' has string
* pointers that point within 'data'. Fix the
* pointers so they point into the same offset
* within the newly allocated buffer.
*/
}
}
}
continue; /* and try again */
}
break;
}
return (kcid);
}
/*
* If the current KCID is the same as kc->kc_chain_id, return 0;
* if different, update the chain and return the new KCID.
* This operation is non-destructive for unchanged kstats.
*/
{
int i;
if (kcid == -1)
return (-1);
return (0);
/*
* kstat 0's data is the kstat chain, so we can get the chain
* by doing a kstat_read() of this kstat. The only fields the
* kstat driver needs are ks_kid (this identifies the kstat),
* ks_data (the pointer to our buffer), and ks_data_size (the
* size of our buffer). By zeroing the struct we set ks_data = NULL
* and ks_data_size = 0, so that kstat_read() will automatically
* determine the size and allocate space for us. We also fill in the
* name, so that truss can print something meaningful.
*/
if (kcid == -1) {
/* errno set by kstat_read() */
return (-1);
}
/*
* Chain the new headers together
*/
/*
* Remove all deleted kstats from the chain.
*/
} else {
}
}
/*
* Add all new kstats to the chain.
*/
return (-1);
}
}
return (kcid);
}
kstat_t *
{
return (ksp);
}
return (NULL);
}
void *
{
int i, size;
case KSTAT_TYPE_NAMED:
size = sizeof (kstat_named_t);
break;
case KSTAT_TYPE_TIMER:
size = sizeof (kstat_timer_t);
break;
default:
return (NULL);
}
return (datap);
}
return (NULL);
}