1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
46 #include <acpi/amlcode.h>
47 #include <acpi/acnamesp.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsnames")
54 /*******************************************************************************
56 * FUNCTION: acpi_ns_build_external_path
58 * PARAMETERS: Node - NS node whose pathname is needed
59 * Size - Size of the pathname
60 * *name_buffer - Where to return the pathname
62 * RETURN: Places the pathname into the name_buffer, in external format
63 * (name segments separated by path separators)
65 * DESCRIPTION: Generate a full pathaname
67 ******************************************************************************/
70 acpi_ns_build_external_path (
71 struct acpi_namespace_node
*node
,
76 struct acpi_namespace_node
*parent_node
;
79 ACPI_FUNCTION_NAME ("ns_build_external_path");
82 /* Special case for root */
85 if (index
< ACPI_NAME_SIZE
) {
86 name_buffer
[0] = AML_ROOT_PREFIX
;
91 /* Store terminator byte, then build name backwards */
94 name_buffer
[index
] = 0;
96 while ((index
> ACPI_NAME_SIZE
) && (parent_node
!= acpi_gbl_root_node
)) {
97 index
-= ACPI_NAME_SIZE
;
99 /* Put the name into the buffer */
101 ACPI_MOVE_32_TO_32 ((name_buffer
+ index
), &parent_node
->name
);
102 parent_node
= acpi_ns_get_parent_node (parent_node
);
104 /* Prefix name with the path separator */
107 name_buffer
[index
] = ACPI_PATH_SEPARATOR
;
110 /* Overwrite final separator with the root prefix character */
112 name_buffer
[index
] = AML_ROOT_PREFIX
;
115 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
116 "Could not construct pathname; index=%X, size=%X, Path=%s\n",
117 (u32
) index
, (u32
) size
, &name_buffer
[size
]));
124 #ifdef ACPI_DEBUG_OUTPUT
125 /*******************************************************************************
127 * FUNCTION: acpi_ns_get_external_pathname
129 * PARAMETERS: Node - NS node whose pathname is needed
131 * RETURN: Pointer to storage containing the fully qualified name of
132 * the node, In external format (name segments separated by path
135 * DESCRIPTION: Used for debug printing in acpi_ns_search_table().
137 ******************************************************************************/
140 acpi_ns_get_external_pathname (
141 struct acpi_namespace_node
*node
)
147 ACPI_FUNCTION_TRACE_PTR ("ns_get_external_pathname", node
);
150 /* Calculate required buffer size based on depth below root */
152 size
= acpi_ns_get_pathname_length (node
);
154 /* Allocate a buffer to be returned to caller */
156 name_buffer
= ACPI_MEM_CALLOCATE (size
);
158 ACPI_REPORT_ERROR (("ns_get_table_pathname: allocation failure\n"));
162 /* Build the path in the allocated buffer */
164 acpi_ns_build_external_path (node
, size
, name_buffer
);
165 return_PTR (name_buffer
);
170 /*******************************************************************************
172 * FUNCTION: acpi_ns_get_pathname_length
174 * PARAMETERS: Node - Namespace node
176 * RETURN: Length of path, including prefix
178 * DESCRIPTION: Get the length of the pathname string for this node
180 ******************************************************************************/
183 acpi_ns_get_pathname_length (
184 struct acpi_namespace_node
*node
)
187 struct acpi_namespace_node
*next_node
;
190 ACPI_FUNCTION_ENTRY ();
194 * Compute length of pathname as 5 * number of name segments.
195 * Go back up the parent tree to the root
200 while (next_node
&& (next_node
!= acpi_gbl_root_node
)) {
201 size
+= ACPI_PATH_SEGMENT_LENGTH
;
202 next_node
= acpi_ns_get_parent_node (next_node
);
206 size
= 1; /* Root node case */
209 return (size
+ 1); /* +1 for null string terminator */
213 /*******************************************************************************
215 * FUNCTION: acpi_ns_handle_to_pathname
217 * PARAMETERS: target_handle - Handle of named object whose name is
219 * Buffer - Where the pathname is returned
221 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
223 * DESCRIPTION: Build and return a full namespace pathname
225 ******************************************************************************/
228 acpi_ns_handle_to_pathname (
229 acpi_handle target_handle
,
230 struct acpi_buffer
*buffer
)
233 struct acpi_namespace_node
*node
;
234 acpi_size required_size
;
237 ACPI_FUNCTION_TRACE_PTR ("ns_handle_to_pathname", target_handle
);
240 node
= acpi_ns_map_handle_to_node (target_handle
);
242 return_ACPI_STATUS (AE_BAD_PARAMETER
);
245 /* Determine size required for the caller buffer */
247 required_size
= acpi_ns_get_pathname_length (node
);
249 /* Validate/Allocate/Clear caller buffer */
251 status
= acpi_ut_initialize_buffer (buffer
, required_size
);
252 if (ACPI_FAILURE (status
)) {
253 return_ACPI_STATUS (status
);
256 /* Build the path in the caller buffer */
258 acpi_ns_build_external_path (node
, required_size
, buffer
->pointer
);
260 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "%s [%X] \n",
261 (char *) buffer
->pointer
, (u32
) required_size
));
262 return_ACPI_STATUS (AE_OK
);