Rev 1972 | Rev 2071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1972 | Rev 1974 | ||
|---|---|---|---|
| Line 148... | Line 148... | ||
| 148 | return NULL; |
148 | return NULL; |
| 149 | } |
149 | } |
| 150 | 150 | ||
| 151 | /** Lookup node with matching node_handle. |
151 | /** Lookup node with matching node_handle. |
| 152 | * |
152 | * |
| - | 153 | * Child nodes are looked up recursively contrary to peer nodes that |
|
| - | 154 | * are looked up iteratively to avoid stack overflow. |
|
| - | 155 | * |
|
| 153 | * @param root Root of the searched subtree. |
156 | * @param root Root of the searched subtree. |
| 154 | * @param handle OpenFirmware handle. |
157 | * @param handle OpenFirmware handle. |
| 155 | * |
158 | * |
| 156 | * @return NULL if there is no such node or pointer to the matching node. |
159 | * @return NULL if there is no such node or pointer to the matching node. |
| 157 | */ |
160 | */ |
| 158 | ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *root, uint32_t handle) |
161 | ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *root, uint32_t handle) |
| 159 | { |
162 | { |
| 160 | ofw_tree_node_t *node; |
163 | ofw_tree_node_t *cur; |
| 161 | 164 | ||
| - | 165 | for (cur = root; cur; cur = cur->peer) { |
|
| 162 | if (root->node_handle == handle) |
166 | if (cur->node_handle == handle) |
| 163 | return root; |
167 | return cur; |
| 164 | 168 | ||
| 165 | if (root->peer) { |
169 | if (cur->child) { |
| 166 | node = ofw_tree_find_node_by_handle(root->peer, handle); |
- | |
| 167 | if (node) |
- | |
| 168 | return node; |
170 | ofw_tree_node_t *node; |
| 169 | } |
- | |
| 170 | 171 | ||
| 171 | if (root->child) { |
- | |
| 172 | node = ofw_tree_find_node_by_handle(root->child, handle); |
172 | node = ofw_tree_find_node_by_handle(cur->child, handle); |
| 173 | if (node) |
173 | if (node) |
| 174 | return node; |
174 | return node; |
| - | 175 | } |
|
| 175 | } |
176 | } |
| 176 | 177 | ||
| 177 | return NULL; |
178 | return NULL; |
| 178 | } |
179 | } |
| 179 | 180 | ||
| Line 228... | Line 229... | ||
| 228 | } |
229 | } |
| 229 | 230 | ||
| 230 | return node; |
231 | return node; |
| 231 | } |
232 | } |
| 232 | 233 | ||
| 233 | /** Recursively print subtree rooted in a node. |
234 | /** Print OpenFirmware device subtree rooted in a node. |
| - | 235 | * |
|
| - | 236 | * Child nodes are processed recursively and peer nodes are processed |
|
| - | 237 | * iteratively in order to avoid stack overflow. |
|
| 234 | * |
238 | * |
| 235 | * @param node Root of the subtree. |
239 | * @param node Root of the subtree. |
| 236 | * @param path Current path, NULL for the very root of the entire tree. |
240 | * @param path Current path, NULL for the very root of the entire tree. |
| 237 | */ |
241 | */ |
| 238 | static void ofw_tree_node_print(const ofw_tree_node_t *node, const char *path) |
242 | static void ofw_tree_node_print(const ofw_tree_node_t *node, const char *path) |
| 239 | { |
243 | { |
| 240 | char *p; |
244 | char *p; |
| - | 245 | const ofw_tree_node_t *cur; |
|
| 241 | 246 | ||
| 242 | p = (char *) malloc(PATH_MAX_LEN, 0); |
247 | p = (char *) malloc(PATH_MAX_LEN, 0); |
| 243 | 248 | ||
| - | 249 | for (cur = node; cur; cur = cur->peer) { |
|
| 244 | if (node->parent) { |
250 | if (cur->parent) { |
| 245 | snprintf(p, PATH_MAX_LEN, "%s/%s", path, node->da_name); |
251 | snprintf(p, PATH_MAX_LEN, "%s/%s", path, cur->da_name); |
| 246 | printf("%s\n", p); |
252 | printf("%s\n", p); |
| 247 | } else { |
253 | } else { |
| 248 | snprintf(p, PATH_MAX_LEN, "%s", node->da_name); |
254 | snprintf(p, PATH_MAX_LEN, "%s", cur->da_name); |
| 249 | printf("/\n"); |
255 | printf("/\n"); |
| 250 | } |
256 | } |
| 251 | - | ||
| 252 | if (node->child) |
- | |
| 253 | ofw_tree_node_print(node->child, p); |
- | |
| 254 | 257 | ||
| 255 | if (node->peer) |
258 | if (cur->child) |
| 256 | ofw_tree_node_print(node->peer, path); |
259 | ofw_tree_node_print(cur->child, p); |
| - | 260 | } |
|
| 257 | 261 | ||
| 258 | free(p); |
262 | free(p); |
| 259 | } |
263 | } |
| 260 | 264 | ||
| 261 | /** Print the structure of the OpenFirmware device tree. */ |
265 | /** Print the structure of the OpenFirmware device tree. */ |