Lines Matching +full:child +full:- +full:node

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
67 static void parse_master_yyin(struct node *root, const char *master);
68 static void parse_map_yyin(struct node *parent, const char *map,
102 s1last = s1[strlen(s1) - 1]; in concat()
109 * it - skip the latter; otherwise concatenating "/" in concat()
159 struct node *
162 struct node *n; in node_new_root()
168 n->n_key = checked_strdup("/"); in node_new_root()
169 n->n_options = checked_strdup(""); in node_new_root()
171 TAILQ_INIT(&n->n_children); in node_new_root()
176 struct node *
177 node_new(struct node *parent, char *key, char *options, char *location, in node_new()
180 struct node *n; in node_new()
186 TAILQ_INIT(&n->n_children); in node_new()
189 n->n_key = key; in node_new()
191 n->n_options = options; in node_new()
193 n->n_options = strdup(""); in node_new()
194 n->n_location = location; in node_new()
196 n->n_config_file = config_file; in node_new()
198 n->n_config_line = config_line; in node_new()
201 n->n_parent = parent; in node_new()
202 TAILQ_INSERT_TAIL(&parent->n_children, n, n_next); in node_new()
207 struct node *
208 node_new_map(struct node *parent, char *key, char *options, char *map, in node_new_map()
211 struct node *n; in node_new_map()
217 TAILQ_INIT(&n->n_children); in node_new_map()
220 n->n_key = key; in node_new_map()
222 n->n_options = options; in node_new_map()
224 n->n_options = strdup(""); in node_new_map()
225 n->n_map = map; in node_new_map()
227 n->n_config_file = config_file; in node_new_map()
229 n->n_config_line = config_line; in node_new_map()
232 n->n_parent = parent; in node_new_map()
233 TAILQ_INSERT_TAIL(&parent->n_children, n, n_next); in node_new_map()
238 static struct node *
239 node_duplicate(const struct node *o, struct node *parent) in node_duplicate()
241 const struct node *child; in node_duplicate() local
242 struct node *n; in node_duplicate()
245 parent = o->n_parent; in node_duplicate()
247 n = node_new(parent, o->n_key, o->n_options, o->n_location, in node_duplicate()
248 o->n_config_file, o->n_config_line); in node_duplicate()
250 TAILQ_FOREACH(child, &o->n_children, n_next) in node_duplicate()
251 node_duplicate(child, n); in node_duplicate()
257 node_delete(struct node *n) in node_delete()
259 struct node *child, *tmp; in node_delete() local
263 TAILQ_FOREACH_SAFE(child, &n->n_children, n_next, tmp) in node_delete()
264 node_delete(child); in node_delete()
266 if (n->n_parent != NULL) in node_delete()
267 TAILQ_REMOVE(&n->n_parent->n_children, n, n_next); in node_delete()
273 * Move (reparent) node 'n' to make it sibling of 'previous', placed
277 node_move_after(struct node *n, struct node *previous) in node_move_after()
280 TAILQ_REMOVE(&n->n_parent->n_children, n, n_next); in node_move_after()
281 n->n_parent = previous->n_parent; in node_move_after()
282 TAILQ_INSERT_AFTER(&previous->n_parent->n_children, previous, n, n_next); in node_move_after()
286 node_expand_includes(struct node *root, bool is_master) in node_expand_includes()
288 struct node *n, *n2, *tmp, *tmp2, *tmproot; in node_expand_includes()
291 TAILQ_FOREACH_SAFE(n, &root->n_children, n_next, tmp) { in node_expand_includes()
292 if (n->n_key[0] != '+') in node_expand_includes()
304 yyin = auto_popen(AUTO_INCLUDE_PATH, n->n_key + 1, NULL); in node_expand_includes()
309 parse_master_yyin(tmproot, n->n_key); in node_expand_includes()
311 parse_map_yyin(tmproot, n->n_key, NULL); in node_expand_includes()
317 n->n_key); in node_expand_includes()
325 &tmproot->n_children, nodehead, n_next, tmp2) { in node_expand_includes()
391 * consist of tho levels of node structures, the key is one
394 * Variant with NULL key is for "automount -LL".
397 node_expand_ampersand(struct node *n, const char *key) in node_expand_ampersand()
399 struct node *child; in node_expand_ampersand() local
401 if (n->n_location != NULL) { in node_expand_ampersand()
403 if (n->n_parent != NULL && in node_expand_ampersand()
404 strcmp(n->n_parent->n_key, "*") != 0) { in node_expand_ampersand()
405 n->n_location = expand_ampersand(n->n_location, in node_expand_ampersand()
406 n->n_parent->n_key); in node_expand_ampersand()
409 n->n_location = expand_ampersand(n->n_location, key); in node_expand_ampersand()
413 TAILQ_FOREACH(child, &n->n_children, n_next) in node_expand_ampersand()
414 node_expand_ampersand(child, key); in node_expand_ampersand()
421 node_expand_wildcard(struct node *n, const char *key) in node_expand_wildcard()
423 struct node *child, *expanded; in node_expand_wildcard() local
427 if (strcmp(n->n_key, "*") == 0) { in node_expand_wildcard()
429 expanded->n_key = checked_strdup(key); in node_expand_wildcard()
433 TAILQ_FOREACH(child, &n->n_children, n_next) in node_expand_wildcard()
434 node_expand_wildcard(child, key); in node_expand_wildcard()
438 node_expand_defined(struct node *n) in node_expand_defined()
440 struct node *child; in node_expand_defined() local
443 if (n->n_location != NULL) { in node_expand_defined()
444 n->n_location = defined_expand(n->n_location); in node_expand_defined()
445 if (n->n_location == NULL) { in node_expand_defined()
452 TAILQ_FOREACH(child, &n->n_children, n_next) { in node_expand_defined()
453 error = node_expand_defined(child); in node_expand_defined()
462 node_is_direct_key(const struct node *n) in node_is_direct_key()
465 if (n->n_parent != NULL && n->n_parent->n_parent == NULL && in node_is_direct_key()
466 strcmp(n->n_key, "/-") == 0) { in node_is_direct_key()
474 node_is_direct_map(const struct node *n) in node_is_direct_map()
478 assert(n->n_parent != NULL); in node_is_direct_map()
479 if (n->n_parent->n_parent == NULL) in node_is_direct_map()
481 n = n->n_parent; in node_is_direct_map()
488 node_has_wildcards(const struct node *n) in node_has_wildcards()
490 const struct node *child; in node_has_wildcards() local
492 TAILQ_FOREACH(child, &n->n_children, n_next) { in node_has_wildcards()
493 if (strcmp(child->n_key, "*") == 0) in node_has_wildcards()
501 node_expand_maps(struct node *n, bool indirect) in node_expand_maps()
503 struct node *child, *tmp; in node_expand_maps() local
505 TAILQ_FOREACH_SAFE(child, &n->n_children, n_next, tmp) { in node_expand_maps()
506 if (node_is_direct_map(child)) { in node_expand_maps()
515 * This is the first-level map node; the one that contains in node_expand_maps()
518 if (child->n_map == NULL) in node_expand_maps()
523 child->n_map); in node_expand_maps()
526 child->n_map); in node_expand_maps()
528 parse_map(child, child->n_map, NULL, NULL); in node_expand_maps()
533 node_expand_direct_maps(struct node *n) in node_expand_direct_maps()
540 node_expand_indirect_maps(struct node *n) in node_expand_indirect_maps()
547 node_path_x(const struct node *n, char *x) in node_path_x()
551 if (n->n_parent == NULL) in node_path_x()
555 * Return "/-" for direct maps only if we were asked for path in node_path_x()
556 * to the "/-" node itself, not to any of its subnodes. in node_path_x()
561 assert(n->n_key[0] != '\0'); in node_path_x()
562 path = concat(n->n_key, '/', x); in node_path_x()
565 return (node_path_x(n->n_parent, path)); in node_path_x()
569 * Return full path for node, consisting of concatenated
570 * paths of node itself and all its parents, up to the root.
573 node_path(const struct node *n) in node_path()
584 if (len > 1 && path[len - 1] == '/') in node_path()
585 path[len - 1] = '\0'; in node_path()
591 node_options_x(const struct node *n, char *x) in node_options_x()
598 options = concat(x, ',', n->n_options); in node_options_x()
601 return (node_options_x(n->n_parent, options)); in node_options_x()
605 * Return options for node, consisting of concatenated
606 * options from the node itself and all its parents,
610 node_options(const struct node *n) in node_options()
617 node_print_indent(const struct node *n, const char *cmdline_options, in node_print_indent()
620 const struct node *child, *first_child; in node_print_indent() local
629 * Do not show both parent and child node if they have the same in node_print_indent()
630 * mountpoint; only show the child node. This means the typical, in node_print_indent()
635 first_child = TAILQ_FIRST(&n->n_children); in node_print_indent()
638 assert(n->n_location == NULL || n->n_map == NULL); in node_print_indent()
639 printf("%*.s%-*s %s%-*s %-*s # %s map %s at %s:%d\n", in node_print_indent()
641 25 - indent, in node_print_indent()
643 options[0] != '\0' ? "-" : " ", in node_print_indent()
647 n->n_location != NULL ? n->n_location : n->n_map != NULL ? n->n_map : "", in node_print_indent()
650 n->n_config_file, n->n_config_line); in node_print_indent()
656 TAILQ_FOREACH(child, &n->n_children, n_next) in node_print_indent()
657 node_print_indent(child, cmdline_options, indent + 2); in node_print_indent()
661 * Recursively print node with all its children. The cmdline_options
663 * others - usually those are the options passed by command line.
666 node_print(const struct node *n, const char *cmdline_options) in node_print()
668 const struct node *child; in node_print() local
670 TAILQ_FOREACH(child, &n->n_children, n_next) in node_print()
671 node_print_indent(child, cmdline_options, 0); in node_print()
674 static struct node *
675 node_find_x(struct node *node, const char *path) in node_find_x() argument
677 struct node *child, *found; in node_find_x() local
681 //log_debugx("looking up %s in %s", path, node_path(node)); in node_find_x()
683 if (!node_is_direct_key(node)) { in node_find_x()
684 tmp = node_path(node); in node_find_x()
701 TAILQ_FOREACH(child, &node->n_children, n_next) { in node_find_x()
702 found = node_find_x(child, path); in node_find_x()
707 if (node->n_parent == NULL || node_is_direct_key(node)) in node_find_x()
710 return (node); in node_find_x()
713 struct node *
714 node_find(struct node *root, const char *path) in node_find()
716 struct node *node; in node_find() local
718 assert(root->n_parent == NULL); in node_find()
720 node = node_find_x(root, path); in node_find()
721 if (node != NULL) in node_find()
722 assert(node != root); in node_find()
724 return (node); in node_find()
730 * key [-options] [ [/mountpoint] [-options2] location ... ]
733 * lack the 'key' field and are always single-line; the key field
736 * We parse it in such a way that a map always has two levels - first
740 parse_map_yyin(struct node *parent, const char *map, const char *executable_key) in parse_map_yyin()
745 struct node *node; in parse_map_yyin() local
757 * non-NULL, even if the map is empty. So, make sure in parse_map_yyin()
783 } else if (yytext[0] == '-') { in parse_map_yyin()
789 * +1 to skip leading "-". in parse_map_yyin()
819 //log_debugx("adding map node, %s", key); in parse_map_yyin()
820 node = node_new(parent, key, options, NULL, map, lineno); in parse_map_yyin()
837 if (yytext[0] == '-') { in parse_map_yyin()
875 log_debugx("adding map node, %s %s %s", in parse_map_yyin()
878 node_new(node, mountpoint, options2, location, in parse_map_yyin()
901 parse_map_keys_yyin(struct node *parent, const char *map) in parse_map_keys_yyin()
925 * "-1" to strip the trailing newline. in parse_map_keys_yyin()
927 key = strndup(line, linelen - 1); in parse_map_keys_yyin()
952 * Parse a special map, e.g. "-hosts".
955 parse_special_map(struct node *parent, const char *map, const char *key) in parse_special_map()
960 assert(map[0] == '-'); in parse_special_map()
963 * +1 to skip leading "-" in map name. in parse_special_map()
998 parse_included_map(struct node *parent, const char *map) in parse_included_map()
1002 assert(map[0] != '-'); in parse_included_map()
1026 parse_map(struct node *parent, const char *map, const char *key, in parse_map()
1041 if (map[0] == '-') { in parse_map()
1111 parse_master_yyin(struct node *root, const char *master) in parse_master_yyin()
1142 * +1 to skip leading "-". in parse_master_yyin()
1153 parse_master(struct node *root, const char *master) in parse_master()
1212 f = auto_popen("rpc.umntall", "-k", NULL); in rpc_umntall()