sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / udapl / libdat / include / dat_osd.h
blob96110ddd7bb1d5606dc70d35a8c840967c5a810b
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
32 * HEADER: dat_osd.h
34 * PURPOSE: Operating System Dependent layer
35 * Description:
36 * Provide OS dependent data structures & functions with
37 * a canonical DAT interface. Designed to be portable
38 * and hide OS specific quirks of common functions.
40 * $Id: dat_osd.h,v 1.14 2003/07/31 14:04:19 jlentini Exp $
43 #ifndef _DAT_OSD_H_
44 #define _DAT_OSD_H_
46 #pragma ident "%Z%%M% %I% %E% SMI"
48 #include <dat/udat.h>
50 #include <assert.h>
51 #include <ctype.h>
52 #include <dlfcn.h>
53 #include <errno.h>
54 #include <pthread.h>
55 #include <stdarg.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <syslog.h>
60 #include <unistd.h>
61 #include <sys/time.h>
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
69 * Debugging
73 #define dat_os_assert(expr) assert(expr)
75 typedef int DAT_OS_DBG_TYPE_VAL;
77 typedef enum
79 DAT_OS_DBG_TYPE_ERROR = 0x1,
80 DAT_OS_DBG_TYPE_GENERIC = 0x2,
81 DAT_OS_DBG_TYPE_SR = 0x4,
82 DAT_OS_DBG_TYPE_DR = 0x8,
83 DAT_OS_DBG_TYPE_PROVIDER_API = 0x10,
84 DAT_OS_DBG_TYPE_CONSUMER_API = 0x20,
85 DAT_OS_DBG_TYPE_ALL = 0xff
86 } DAT_OS_DBG_TYPE;
88 extern void
89 dat_os_dbg_init(void);
91 extern void
92 dat_os_dbg_print(
93 DAT_OS_DBG_TYPE_VAL type,
94 const char *fmt,
95 ...);
100 * Utility Functions
104 #define DAT_ERROR(Type, SubType) ((DAT_RETURN)(DAT_CLASS_ERROR | Type | \
105 SubType))
107 typedef size_t DAT_OS_SIZE;
108 typedef void * DAT_OS_LIBRARY_HANDLE;
110 extern DAT_RETURN
111 dat_os_library_load(
112 const char *library_path,
113 DAT_OS_LIBRARY_HANDLE *library_handle_ptr);
115 extern DAT_RETURN
116 dat_os_library_unload(
117 const DAT_OS_LIBRARY_HANDLE library_handle);
120 * void *dat_os_library_sym(DAT_OS_LIBRARY_HANDLE library_handle, char *sym)
122 #define dat_os_library_sym(libhndl, sym) dlsym((libhndl), (sym))
124 /* char *dat_os_getenv(const char *name) */
125 #define dat_os_getenv(name) getenv((name))
127 /* long int dat_os_strtol(const char *nptr, char **endptr, int base) */
128 #define dat_os_strtol(nptr, endptr, base) strtol((nptr), (endptr), (base))
130 /* DAT_OS_SIZE dat_os_strlen(const char *s) */
131 #define dat_os_strlen(s) strlen((s))
133 /* int dat_os_strncmp(const char *s1, const char *s2, DAT_OS_SIZE n) */
134 #define dat_os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
136 /* void * dat_os_strncpy(char *dest, const char *src, DAT_OS_SIZE len) */
137 #define dat_os_strncpy(dest, src, len) strncpy((dest), (src), (len))
139 /* DAT_BOOLEAN dat_os_isblank(int c) */
140 #define dat_os_isblank(c) ((DAT_BOOLEAN)((' ' == (c)) || ('\t' == (c))) \
141 ? DAT_TRUE : DAT_FALSE)
144 /* DAT_BOOLEAN dat_os_isdigit(int c) */
145 #define dat_os_isdigit(c) ((DAT_BOOLEAN)(isdigit((c)) ? DAT_TRUE : \
146 DAT_FALSE))
148 /* void dat_os_usleep(unsigned long usec) */
149 #define dat_os_usleep(usec) usleep((usec))
153 * Memory Functions
157 /* void *dat_os_alloc(int size) */
158 #define dat_os_alloc(size) malloc((size))
160 /* void dat_os_free(void *ptr, int size) */
161 #define dat_os_free(ptr, size) free((ptr))
163 /* void *dat_os_memset(void *loc, int c, DAT_OS_SIZE size) */
164 #define dat_os_memset(loc, c, size) memset((loc), (c), (size))
168 * File I/O
172 typedef FILE DAT_OS_FILE;
173 typedef fpos_t DAT_OS_FILE_POS;
176 * DAT_OS_FILE *dat_os_fopen(const char *path)
177 * always open files in read only mode
179 #define dat_os_fopen(path) ((DAT_OS_FILE *)fopen((path), "rF"))
182 /* DAT_RETURN dat_os_fgetpos(DAT_OS_FILE *file, DAT_OS_FILE_POS *pos) */
183 #define dat_os_fgetpos(file, pos) ((DAT_RETURN)( \
184 (0 == fgetpos((file), (pos))) ? DAT_SUCCESS : \
185 DAT_INTERNAL_ERROR))
187 /* DAT_RETURN dat_os_fsetpos(DAT_OS_FILE *file, DAT_OS_FILE_POS *pos) */
188 #define dat_os_fsetpos(file, pos) ((DAT_RETURN)( \
189 (0 == fsetpos((file), (pos))) ? DAT_SUCCESS : \
190 DAT_INTERNAL_ERROR))
193 * dat_os_fgetc() returns EOF on error or end of file.
194 * int dat_os_fgetc(DAT_OS_FILE *file)
196 #define dat_os_fgetc(file) fgetc((file))
199 /* int dat_os_fputc(DAT_OS_FILE *file, int c) */
200 #define dat_os_fputc(file, c) fputc((c), (file))
202 /* int dat_os_fungetc(DAT_OS_FILE *file) */
203 #define dat_os_fungetc(file) fseek((file), -1, SEEK_CUR)
206 * dat_os_fread returns the number of bytes read from the file.
207 * DAT_OS_SIZE dat_os_fread(DAT_OS_FILE *file, char *buf, DAT_OS_SIZE len)
209 #define dat_os_fread(file, buf, len) fread((buf), sizeof (char), \
210 (len), (file))
212 /* DAT_RETURN dat_os_fclose(DAT_OS_FILE *file) */
213 #define dat_os_fclose(file) ((0 == fclose(file)) ? DAT_SUCCESS : \
214 DAT_INTERNAL_ERROR)
218 * Locks
222 typedef pthread_mutex_t DAT_OS_LOCK;
225 /* lock functions */
227 * DAT_RETURN dat_os_lock_init(IN DAT_OS_LOCK *m)
229 #define dat_os_lock_init(m) ((0 == pthread_mutex_init((m), NULL)) ? \
230 DAT_SUCCESS : DAT_INTERNAL_ERROR)
232 /* DAT_RETURN dat_os_lock(IN DAT_OS_LOCK *m) */
233 #define dat_os_lock(m) ((DAT_RETURN)( \
234 (0 == pthread_mutex_lock((m))) ? \
235 DAT_SUCCESS : DAT_INTERNAL_ERROR))
237 /* DAT_RETURN dat_os_unlock(IN DAT_OS_LOCK *m) */
238 #define dat_os_unlock(m) ((DAT_RETURN)( \
239 (0 == pthread_mutex_unlock((m))) ? \
240 DAT_SUCCESS : DAT_INTERNAL_ERROR))
242 /* DAT_RETURN dat_os_lock_destroy(IN DAT_OS_LOCK *m) */
243 #define dat_os_lock_destroy(m) ((DAT_RETURN)( \
244 (0 == pthread_mutex_destroy((m))) ? \
245 DAT_SUCCESS : DAT_INTERNAL_ERROR))
248 * Simple macro to verify a handle is bad. Conditions:
249 * - pointer is NULL
250 * - pointer is not word aligned
252 #define DAT_BAD_HANDLE(h) (((h) == NULL) || ((unsigned long)(h) & 3))
254 #ifdef __cplusplus
256 #endif
258 #endif /* _DAT_OSD_H_ */