]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - stand/lua/core.lua
MFV r329313: 8857 zio_remove_child() panic due to already destroyed parent zio
[FreeBSD/FreeBSD.git] / stand / lua / core.lua
1 --
2 -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
3 -- All rights reserved.
4 --
5 -- Redistribution and use in source and binary forms, with or without
6 -- modification, are permitted provided that the following conditions
7 -- are met:
8 -- 1. Redistributions of source code must retain the above copyright
9 --    notice, this list of conditions and the following disclaimer.
10 -- 2. Redistributions in binary form must reproduce the above copyright
11 --    notice, this list of conditions and the following disclaimer in the
12 --    documentation and/or other materials provided with the distribution.
13 --
14 -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 -- ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 -- SUCH DAMAGE.
25 --
26 -- $FreeBSD$
27 --
28
29 local core = {};
30
31 function core.setVerbose(b)
32         if (b == nil) then
33                 b = not core.verbose;
34         end
35
36         if (b == true) then
37                 loader.setenv("boot_verbose", "YES");
38         else
39                 loader.unsetenv("boot_verbose");
40         end
41         core.verbose = b;
42 end
43
44 function core.setSingleUser(b)
45         if (b == nil) then
46                 b = not core.su;
47         end
48
49         if (b == true) then
50                 loader.setenv("boot_single", "YES");
51         else
52                 loader.unsetenv("boot_single");
53         end
54         core.su = b;
55 end
56
57 function core.setACPI(b)
58         if (b == nil) then
59                 b = not core.acpi;
60         end
61
62         if (b == true) then
63                 loader.setenv("acpi_load", "YES");
64                 loader.setenv("hint.acpi.0.disabled", "0");
65                 loader.unsetenv("loader.acpi_disabled_by_user");
66         else
67                 loader.unsetenv("acpi_load");
68                 loader.setenv("hint.acpi.0.disabled", "1");
69                 loader.setenv("loader.acpi_disabled_by_user", "1");
70         end
71         core.acpi = b;
72 end
73
74 function core.setSafeMode(b)
75         if (b == nil) then
76                 b = not core.sm;
77         end
78         if (b == true) then
79                 loader.setenv("kern.smp.disabled", "1");
80                 loader.setenv("hw.ata.ata_dma", "0");
81                 loader.setenv("hw.ata.atapi_dma", "0");
82                 loader.setenv("hw.ata.wc", "0");
83                 loader.setenv("hw.eisa_slots", "0");
84                 loader.setenv("kern.eventtimer.periodic", "1");
85                 loader.setenv("kern.geom.part.check_integrity", "0");
86         else
87                 loader.unsetenv("kern.smp.disabled");
88                 loader.unsetenv("hw.ata.ata_dma");
89                 loader.unsetenv("hw.ata.atapi_dma");
90                 loader.unsetenv("hw.ata.wc");
91                 loader.unsetenv("hw.eisa_slots");
92                 loader.unsetenv("kern.eventtimer.periodic");
93                 loader.unsetenv("kern.geom.part.check_integrity");
94         end
95         core.sm = b;
96 end
97
98 function core.kernelList()
99         local k = loader.getenv("kernel");
100         local v = loader.getenv("kernels") or "";
101
102         local kernels = {};
103         local i = 0;
104         if k ~= nil then
105                 i = i + 1;
106                 kernels[i] = k;
107         end
108
109         for n in v:gmatch("([^; ]+)[; ]?") do
110                 if n ~= k then
111                         i = i + 1;
112                         kernels[i] = n;
113                 end
114         end
115         return kernels;
116 end
117
118 function core.setDefaults()
119         core.setACPI(true);
120         core.setSafeMode(false);
121         core.setSingleUser(false);
122         core.setVerbose(false);
123 end
124
125 function core.autoboot()
126         loader.perform("autoboot");
127 end
128
129 function core.boot()
130         loader.perform("boot");
131 end
132
133 function core.bootserial()
134         local c = loader.getenv("console");
135
136         if c ~= nil then
137                 if c:find("comconsole") ~= nil then
138                         return true;
139                 end
140         end
141
142         local s = loader.getenv("boot_serial");
143         if s ~= nil then
144                 return true;
145         end
146
147         local m = loader.getenv("boot_multicons");
148         if m ~= nil then
149                 return true;
150         end
151         return false;
152 end
153
154 return core