/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
*/
/*
*/
#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*/
/*
* Use a hash for the kstat records we have read in. This is done
* to reduce the number of records that have to be looked up when
* dealing with a large configuration system. Note this hash is
* internal to libkstat only. The pointer to the hash is associated
* with the kstat_ctl_t data structure. When the kstat_ctl_t is free, the
* hash is removed.
*/
struct kstat_hashed_records {
char *module_name;
char *ks_name;
int instance;
int allocated;
};
static int
{
int val = 0;
int index = 0;
if (!path)
return (0);
/*
* To force a good hashing of device paths, we need
* to scatter the hash around based on the character
* placement in the string.
* If the character is not an integer value, we simply
* multiply it by the position value in the string.
* If the character is an integer, then we use 1 of
* 4 different calculations based on the position
* the string. If we do not do this, then things like
* 1 and 2 can end up having the same hash position.
* Simple usage of a long or short value is no good
* because the length of names can get quite long.
*/
index++;
continue;
}
switch (index & 3) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
index++;
}
return (val);
}
static int
int *allocated)
{
int val;
char *tmp;
/*
* Extra chars in the string that we need to allow for
* spaces, underscores and others.
*/
int len;
return (-1);
/*
* Need to build a temporary string to use.
*/
if (!tmp)
return (-1);
*allocated = 1;
} else {
}
if (instance > 0)
if (val < 0)
return (val);
}
static kstat_t *
{
int hash_index;
char *tmp_name;
int allocated = 0;
/*
* If the entry was allocated free it up we do not care
* about it here.
*/
if (allocated)
if (hash_index >= 0 &&
while (hash_entry) {
ks_instance) {
/* Entry matches, return. */
return (hash_entry->ksp);
}
}
}
}
out:
/*
* We did not find the entry in the hash table. Check the kstat_t list
* and see if it is there. If it is add the entry to the hash.
*/
return (ksp);
}
}
return (NULL);
}
static void
{
int hash_index;
char *tmp_name;
int allocated = 0;
return;
if (!kc->kc_private) {
(struct kstat_hashed_records **)
sizeof (struct kstat_hashed_records **)));
if (!kc->kc_private)
return;
} else {
}
if (hash_index < 0)
return;
if (!ks_entry)
return;
} else {
}
}
static void
{
int hash_index;
char *tmp_name;
int allocated = 0;
return;
/*
* If hash_index < 0 then there is not enough information in the ksp to
* be able to figure out what to remove.
*/
if (hash_index < 0)
return;
/* Walk the hash chain for the ksp. */
while (hash_entry) {
break;
}
/* If we found an entry, then remove it. */
if (hash_entry) {
if (!prev_entry) {
} else {
}
if (hash_entry->allocated)
}
}
static void
{
if (free_first)
}
static void
{
while (ksp) {
}
/* Free the kc_private data if present. */
if (kc->kc_private) {
}
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 *
{
}
/* Attempt to add the entry to the hash. */
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);
}