Lines Matching refs:node

21  * xbc_parse() parses the text to build a simple tree. Each tree node is
22 * simply a key word or a value. A key node may have a next key node or/and
23 * a child node (both key and value). A value node may have a next value
24 * node (for array).
46 * xbc_root_node() - Get the root node of extended boot config
48 * Return the address of root node of extended boot config. If the
60 * xbc_node_index() - Get the index of XBC node
61 * @node: A target node of getting index.
63 * Return the index number of @node in XBC node list.
65 int __init xbc_node_index(struct xbc_node *node)
67 return node - &xbc_nodes[0];
71 * xbc_node_get_parent() - Get the parent XBC node
72 * @node: An XBC node.
74 * Return the parent node of @node. If the node is top node of the tree,
77 struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node)
79 return node->parent == XBC_NODE_MAX ? NULL : &xbc_nodes[node->parent];
83 * xbc_node_get_child() - Get the child XBC node
84 * @node: An XBC node.
86 * Return the first child node of @node. If the node has no child, return
89 struct xbc_node * __init xbc_node_get_child(struct xbc_node *node)
91 return node->child ? &xbc_nodes[node->child] : NULL;
95 * xbc_node_get_next() - Get the next sibling XBC node
96 * @node: An XBC node.
98 * Return the NEXT sibling node of @node. If the node has no next sibling,
99 * return NULL. Note that even if this returns NULL, it doesn't mean @node
100 * has no siblings. (You also has to check whether the parent's child node
101 * is @node or not.)
103 struct xbc_node * __init xbc_node_get_next(struct xbc_node *node)
105 return node->next ? &xbc_nodes[node->next] : NULL;
109 * xbc_node_get_data() - Get the data of XBC node
110 * @node: An XBC node.
112 * Return the data (which is always a null terminated string) of @node.
113 * If the node has invalid data, warn and return NULL.
115 const char * __init xbc_node_get_data(struct xbc_node *node)
117 int offset = node->data & ~XBC_VALUE;
126 xbc_node_match_prefix(struct xbc_node *node, const char **prefix)
128 const char *p = xbc_node_get_data(node);
145 * xbc_node_find_child() - Find a child node which matches given key
146 * @parent: An XBC node.
149 * Search a node under @parent which matches @key. The @key can contain
151 * node from whole tree. Return NULL if no node is matched.
156 struct xbc_node *node;
159 node = xbc_node_get_child(parent);
161 node = xbc_root_node();
163 while (node && xbc_node_is_key(node)) {
164 if (!xbc_node_match_prefix(node, &key))
165 node = xbc_node_get_next(node);
167 node = xbc_node_get_child(node);
172 return node;
176 * xbc_node_find_value() - Find a value node which matches given key
177 * @parent: An XBC node.
179 * @vnode: A container pointer of found XBC node.
181 * Search a value node under @parent whose (parent) key node matches @key,
184 * this searches the node from whole tree. Return the value string if a
185 * matched key found, return NULL if no node is matched.
194 struct xbc_node *node = xbc_node_find_child(parent, key);
196 if (!node || !xbc_node_is_key(node))
199 node = xbc_node_get_child(node);
200 if (node && !xbc_node_is_value(node))
204 *vnode = node;
206 return node ? xbc_node_get_data(node) : "";
210 * xbc_node_compose_key_after() - Compose partial key string of the XBC node
211 * @root: Root XBC node
212 * @node: Target XBC node.
216 * Compose the partial key of the @node into @buf, which is starting right
218 * key words of @node.
220 * if @node is NULL or @root is not the ancestor of @node or @root is @node,
226 struct xbc_node *node,
232 if (!node || node == root)
235 if (xbc_node_is_value(node))
236 node = xbc_node_get_parent(node);
238 while (node && node != root) {
239 keys[depth++] = xbc_node_index(node);
242 node = xbc_node_get_parent(node);
244 if (!node && root)
248 node = xbc_nodes + keys[depth];
249 ret = snprintf(buf, size, "%s%s", xbc_node_get_data(node),
266 * xbc_node_find_next_leaf() - Find the next leaf node under given node
267 * @root: An XBC root node
268 * @node: An XBC node which starts from.
270 * Search the next leaf node (which means the terminal key node) of @node
271 * under @root node (including @root node itself).
272 * Return the next node or NULL if next leaf node is not found.
275 struct xbc_node *node)
280 if (!node) { /* First try */
281 node = root;
282 if (!node)
283 node = xbc_nodes;
285 if (node == root) /* @root was a leaf, no child node. */
288 while (!node->next) {
289 node = xbc_node_get_parent(node);
290 if (node == root)
292 /* User passed a node which is not uder parent */
293 if (WARN_ON(!node))
296 node = xbc_node_get_next(node);
299 while (node && !xbc_node_is_leaf(node))
300 node = xbc_node_get_child(node);
302 return node;
307 * @root: An XBC root node
308 * @leaf: A container pointer of XBC node which starts from.
310 * Search the next leaf node (which means the terminal key node) of *@leaf
311 * under @root node. Returns the value and update *@leaf if next leaf node
312 * is found, or NULL if no next leaf node is found.
334 static int __init xbc_init_node(struct xbc_node *node, char *data, u32 flag)
341 node->data = (u16)offset | flag;
342 node->child = 0;
343 node->next = 0;
350 struct xbc_node *node;
355 node = &xbc_nodes[xbc_node_num++];
356 if (xbc_init_node(node, data, flag) < 0)
359 return node;
362 static inline __init struct xbc_node *xbc_last_sibling(struct xbc_node *node)
364 while (node->next)
365 node = xbc_node_get_next(node);
367 return node;
372 struct xbc_node *sib, *node = xbc_add_node(data, flag);
374 if (node) {
376 node->parent = XBC_NODE_MAX;
378 sib->next = xbc_node_index(node);
380 node->parent = xbc_node_index(last_parent);
382 last_parent->child = xbc_node_index(node);
386 sib->next = xbc_node_index(node);
392 return node;
397 struct xbc_node *node = xbc_add_sibling(data, flag);
399 if (node)
400 last_parent = node;
402 return node;
462 * Return delimiter or error, no node added. As same as lib/cmdline.c,
516 struct xbc_node *node;
525 node = xbc_add_sibling(*__v, XBC_VALUE);
526 if (!node)
530 node->next = 0;
536 struct xbc_node *find_match_node(struct xbc_node *node, char *k)
538 while (node) {
539 if (!strcmp(xbc_node_get_data(node), k))
541 node = xbc_node_get_next(node);
543 return node;
548 struct xbc_node *node, *child;
557 node = find_match_node(xbc_nodes, k);
562 node = find_match_node(child, k);
565 if (node)
566 last_parent = node;
569 node = xbc_add_child(k, XBC_KEY);
570 if (!node)
866 * xbc_debug_dump() - Dump current XBC node list
868 * Dump the current XBC node list on printk buffer for debug.