xref: /freebsd/lib/libbsdconf/bsdconf_format_loader.c (revision 3fe5961a0b708da599d42cbb6b5e4f030c28ea45)
1 /*
2  * Copyright (c) 2013-2026 Devin Teske <dteske@FreeBSD.org>
3  * Copyright (c) 2021-2026 Faraz Vahedi <kfv@FreeBSD.org>
4  *
5  * SPDX-License-Identifier: BSD-2-Clause
6  */
7 
8 #include "bsdconf_formats.h"
9 
10 /*
11  * BSDCONF_FORMAT_LOADER: loader.conf(5)
12  *
13  * Assignments with no whitespace around the `=' -- the Forth reader in
14  * support.4th rejects anything else, so BSDCONF_STRICT_EQUALS is enforced.
15  * Quoted or unquoted input values are accepted when parsing but values are
16  * always written back quoted (BSDCONF_PUT_QUOTE_ALWAYS), the form every
17  * loader accepts for every value.
18  *
19  * The loader itself hardcodes only /boot/defaults/loader.conf and discovers
20  * every other file from the loader_conf_files, loader_conf_dirs, and
21  * local_loader_conf_files directives encountered along the way -- any file
22  * so discovered may revise those lists in turn. The `defaults' member
23  * quintet below hands that same discovery to bsdconf_format_files(); the
24  * static source list is only the fallback for systems whose defaults file
25  * is missing. The defaults file itself is deliberately excluded from the
26  * resolved list, mirroring how sysrc(8) excludes /etc/defaults/rc.conf.
27  */
28 static const struct bsdconf_source bsdconf_loader_sources[] = {
29 	{ BSDCONF_SOURCE_FILE,	"/boot/device.hints" },
30 	{ BSDCONF_SOURCE_FILE,	"/boot/loader.conf" },
31 	{ BSDCONF_SOURCE_DIR,	"/boot/loader.conf.d" },
32 	{ BSDCONF_SOURCE_FILE,	"/boot/loader.conf.local" },
33 	{ BSDCONF_SOURCE_FILE,	NULL },
34 };
35 
36 const struct bsdconf_format_def bsdconf_format_loader_def = {
37 	.keyword		= "loader",
38 	.path			= "/boot/loader.conf",
39 	.sources		= bsdconf_loader_sources,
40 	.defaults		= "/boot/defaults/loader.conf",
41 	.defaults_env		= "LOADER_DEFAULTS",
42 	.files_directive	= "loader_conf_files",
43 	.dirs_directive		= "loader_conf_dirs",
44 	.local_directive	= "local_loader_conf_files",
45 	.processing		= BSDCONF_BREAK_ON_EQUALS |
46 				  BSDCONF_CASE_SENSITIVE |
47 				  BSDCONF_REQUIRE_EQUALS |
48 				  BSDCONF_STRICT_EQUALS,
49 	.put			= BSDCONF_PUT_QUOTE_ALWAYS |
50 				  BSDCONF_PUT_ALLOW_EMPTY,
51 };
52