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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/param.h>
33 #include <topo_error.h>
34 #include <topo_tree.h>
35 #include <topo_subr.h>
36 #include <topo_file.h>
41 * This file hides the details of any file manipulation to
42 * establish topology for a given enumerator.
45 #define TOPO_DEFAULT_FILE "maps/%s-%s-topology.xml"
46 #define TOPO_COMMON_FILE "maps/%s-topology.xml"
49 topo_file_unload(topo_file_t
*tfp
)
55 if (tfp
->tf_filenm
!= NULL
)
56 topo_mod_strfree(tfp
->tf_mod
, tfp
->tf_filenm
);
58 if (tfp
->tf_tmap
!= NULL
)
59 tf_info_free(tfp
->tf_mod
, tfp
->tf_tmap
);
61 topo_mod_free(tfp
->tf_mod
, tfp
, sizeof (topo_file_t
));
65 topo_file_load(topo_mod_t
*mod
, tnode_t
*node
, const char *name
,
66 const char *scheme
, int pmap
)
71 if ((tfp
= topo_mod_zalloc(mod
, sizeof (topo_file_t
))) == NULL
)
72 return (topo_mod_seterrno(mod
, ETOPO_NOMEM
));
77 (void) snprintf(fp
, MAXNAMELEN
, TOPO_DEFAULT_FILE
, name
,
80 (void) snprintf(fp
, MAXNAMELEN
, TOPO_COMMON_FILE
, scheme
);
82 if ((tfp
->tf_filenm
= topo_search_path(mod
, mod
->tm_rootdir
, fp
))
84 topo_file_unload(tfp
);
85 return (topo_mod_seterrno(mod
, ETOPO_MOD_NOENT
));
88 if ((tfp
->tf_tmap
= topo_xml_read(mod
, tfp
->tf_filenm
, scheme
))
90 topo_dprintf(mod
->tm_hdl
, TOPO_DBG_ERR
,
91 "failed to load topology file %s: "
92 "%s\n", tfp
->tf_filenm
, topo_strerror(ETOPO_MOD_XRD
));
93 topo_file_unload(tfp
);
94 return (topo_mod_seterrno(mod
, ETOPO_MOD_XRD
));
98 tfp
->tf_tmap
->tf_flags
|= TF_PROPMAP
;
100 if (topo_xml_enum(mod
, tfp
->tf_tmap
, node
) < 0) {
101 topo_dprintf(mod
->tm_hdl
, TOPO_DBG_ERR
,
102 "Failed to enumerate topology: %s\n",
103 topo_strerror(ETOPO_MOD_XENUM
));
104 topo_file_unload(tfp
);
105 return (topo_mod_seterrno(mod
, ETOPO_MOD_XENUM
));
108 topo_file_unload(tfp
);