util.h revision 724365f7556fc4201fdb11766ebc6bd918523130
/*
* 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
* or http://www.opensolaris.org/os/licensing.
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _UTIL_H
#define _UTIL_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Definitions for data structures used in the SCSI IE module
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
/*
* List of strings with arbitrary matching values
*/
typedef struct slist {
char *str;
int value;
} slist_t;
/*
* The following structures comprise the implementation of the
* queue structure that's used to construct the list of state
* changes. Removals from the queue are blocking operations that
* cause the thread to wait until new entries are added.
*/
struct q_node {
void *data;
struct q_node *next;
};
typedef struct q_head {
/*
* Block On Empty (when queue is empty, the calling thread will be
* blocked until something is added)
*/
boolean_t boe;
pthread_mutex_t mutex;
pthread_cond_t cvar;
void *(*nalloc)(size_t);
void (*nfree)(void *, size_t);
void (*data_dealloc)(void *);
struct q_node *nodep;
} qu_t;
typedef enum log_class {
MM_CONF = 0x0001,
MM_FAULTMGR = 0x0002,
MM_HPMGR = 0x0004,
MM_SCHGMGR = 0x0008,
MM_FLTANALYZE = 0x0010,
MM_SCSI = 0x0020,
MM_MAIN = 0x0040,
MM_PLUGIN = 0x0080,
MM_TOPO = 0x0100,
MM_ERR = 0x0200,
MM_WARN = 0x0400,
MM_NOTE = 0x0800,
MM_OTHER = 0x1000
} log_class_t;
extern void queue_add(qu_t *qp, void *data);
extern void *queue_remove(qu_t *qp);
extern qu_t *new_queue(boolean_t block_on_empty, void *(*nodealloc)(size_t),
void (*nodefree)(void *, size_t), void (*deallocator)(void *));
extern void queue_free(qu_t **qp);
extern char *find_string(slist_t *slist, int match_value);
extern void log_dump(log_class_t cl, char *label, char *start, unsigned length);
extern void *dmalloc(size_t sz);
extern void *dzmalloc(size_t sz);
extern char *dstrdup(const char *s);
extern void dfree(void *p, size_t sz);
extern void dstrfree(char *s);
extern void log_msg(log_class_t cl, const char *fmt, ...);
extern void log_err(const char *fmt, ...);
extern void log_warn(const char *fmt, ...);
extern void log_warn_e(const char *fmt, ...);
extern void vcont(log_class_t cl, const char *fmt, va_list val);
#ifdef __cplusplus
}
#endif
#endif /* _UTIL_H */