4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
27 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
37 * PURPOSE: dynamic registry implementation
39 * $Id: dat_dr.c,v 1.12 2003/08/20 14:28:40 hobie16 Exp $
45 #include "dat_dictionary.h"
54 static DAT_OS_LOCK g_dr_lock
;
55 static DAT_DICTIONARY
*g_dr_dictionary
= NULL
;
66 * Function: dat_dr_init
74 status
= dat_os_lock_init(&g_dr_lock
);
75 if (DAT_SUCCESS
!= status
) {
79 status
= dat_dictionary_create(&g_dr_dictionary
);
80 if (DAT_SUCCESS
!= status
) {
89 * Function: dat_dr_fini
97 status
= dat_os_lock_destroy(&g_dr_lock
);
98 if (DAT_SUCCESS
!= status
) {
102 status
= dat_dictionary_destroy(g_dr_dictionary
);
103 if (DAT_SUCCESS
!= status
) {
107 return (DAT_SUCCESS
);
112 * Function: dat_dr_insert
117 IN
const DAT_PROVIDER_INFO
*info
,
118 IN DAT_DR_ENTRY
*entry
)
121 DAT_DICTIONARY_ENTRY dict_entry
;
124 data
= dat_os_alloc(sizeof (DAT_DR_ENTRY
));
126 status
= DAT_ERROR(DAT_INSUFFICIENT_RESOURCES
,
127 DAT_RESOURCE_MEMORY
);
134 status
= dat_dictionary_entry_create(&dict_entry
);
135 if (DAT_SUCCESS
!= status
) {
139 dat_os_lock(&g_dr_lock
);
141 status
= dat_dictionary_insert(g_dr_dictionary
,
144 (DAT_DICTIONARY_DATA
*) data
);
146 dat_os_unlock(&g_dr_lock
);
149 if (DAT_SUCCESS
!= status
) {
151 dat_os_free(data
, sizeof (DAT_DR_ENTRY
));
155 if (NULL
!= dict_entry
) {
156 (void) dat_dictionary_entry_destroy(dict_entry
);
165 * Function: dat_dr_remove
170 IN
const DAT_PROVIDER_INFO
*info
)
173 DAT_DICTIONARY_ENTRY dict_entry
;
176 dat_os_lock(&g_dr_lock
);
178 status
= dat_dictionary_search(g_dr_dictionary
,
180 (DAT_DICTIONARY_DATA
*) &data
);
182 if (DAT_SUCCESS
!= status
) {
183 /* return status from dat_dictionary_search() */
187 if (0 != data
->ref_count
) {
188 status
= DAT_ERROR(DAT_PROVIDER_IN_USE
, 0);
193 status
= dat_dictionary_remove(g_dr_dictionary
,
196 (DAT_DICTIONARY_DATA
*) &data
);
198 if (DAT_SUCCESS
!= status
) {
199 /* return status from dat_dictionary_remove() */
203 dat_os_free(data
, sizeof (DAT_DR_ENTRY
));
206 dat_os_unlock(&g_dr_lock
);
208 if (NULL
!= dict_entry
) {
209 (void) dat_dictionary_entry_destroy(dict_entry
);
217 * Function: dat_dr_provider_open
221 dat_dr_provider_open(
222 IN
const DAT_PROVIDER_INFO
*info
,
223 OUT DAT_IA_OPEN_FUNC
*p_ia_open_func
)
228 dat_os_lock(&g_dr_lock
);
230 status
= dat_dictionary_search(g_dr_dictionary
,
232 (DAT_DICTIONARY_DATA
*) &data
);
234 dat_os_unlock(&g_dr_lock
);
236 if (DAT_SUCCESS
== status
) {
238 *p_ia_open_func
= data
->ia_open_func
;
246 * Function: dat_dr_provider_close
250 dat_dr_provider_close(
251 IN
const DAT_PROVIDER_INFO
*info
)
256 dat_os_lock(&g_dr_lock
);
258 status
= dat_dictionary_search(g_dr_dictionary
,
260 (DAT_DICTIONARY_DATA
*) &data
);
262 dat_os_unlock(&g_dr_lock
);
264 if (DAT_SUCCESS
== status
) {
273 * Function: dat_dr_size
280 return (dat_dictionary_size(g_dr_dictionary
, size
));
285 * Function: dat_dr_list
290 IN DAT_COUNT max_to_return
,
291 OUT DAT_COUNT
*entries_returned
,
292 OUT DAT_PROVIDER_INFO
* (dat_provider_list
[]))
294 DAT_DR_ENTRY
**array
;
295 DAT_COUNT array_size
;
300 status
= DAT_SUCCESS
;
303 * The dictionary size may increase between the call to
304 * dat_dictionary_size() and dat_dictionary_enumerate().
305 * Therefore we loop until a successful enumeration is made.
307 *entries_returned
= 0;
309 status
= dat_dictionary_size(g_dr_dictionary
, &array_size
);
310 if (status
!= DAT_SUCCESS
) {
314 if (array_size
== 0) {
315 status
= DAT_SUCCESS
;
319 array
= dat_os_alloc(array_size
* sizeof (DAT_DR_ENTRY
*));
321 status
= DAT_ERROR(DAT_INSUFFICIENT_RESOURCES
,
322 DAT_RESOURCE_MEMORY
);
326 dat_os_lock(&g_dr_lock
);
328 status
= dat_dictionary_enumerate(g_dr_dictionary
,
329 (DAT_DICTIONARY_DATA
*) array
,
332 dat_os_unlock(&g_dr_lock
);
334 if (DAT_SUCCESS
== status
) {
338 array_size
* sizeof (DAT_DR_ENTRY
*));
344 for (i
= 0; (i
< max_to_return
) && (i
< array_size
); i
++) {
345 if (NULL
== dat_provider_list
[i
]) {
346 status
= DAT_ERROR(DAT_INVALID_PARAMETER
,
351 *dat_provider_list
[i
] = array
[i
]->info
;
354 *entries_returned
= i
;
358 dat_os_free(array
, array_size
* sizeof (DAT_DR_ENTRY
*));