core.lua (73531a2abd8de866a3581d556b026b278fdedffa) core.lua (277f38abffc6a8160b5044128b5b2c620fbb970c)
1--
2-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3--
4-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6-- All rights reserved.
7--
8-- Redistribution and use in source and binary forms, with or without

--- 24 unchanged lines hidden (view full) ---

33local hook = require("hook")
34
35local core = {}
36
37local default_safe_mode = false
38local default_single_user = false
39local default_verbose = false
40
1--
2-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3--
4-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6-- All rights reserved.
7--
8-- Redistribution and use in source and binary forms, with or without

--- 24 unchanged lines hidden (view full) ---

33local hook = require("hook")
34
35local core = {}
36
37local default_safe_mode = false
38local default_single_user = false
39local default_verbose = false
40
41local bootenv_list = "bootenvs"
42
41local function composeLoaderCmd(cmd_name, argstr)
42 if argstr ~= nil then
43 cmd_name = cmd_name .. " " .. argstr
44 end
45 return cmd_name
46end
47
48local function recordDefaults()

--- 216 unchanged lines hidden (view full) ---

265 return core.cached_kernels
266end
267
268function core.bootenvDefault()
269 return loader.getenv("zfs_be_active")
270end
271
272function core.bootenvList()
43local function composeLoaderCmd(cmd_name, argstr)
44 if argstr ~= nil then
45 cmd_name = cmd_name .. " " .. argstr
46 end
47 return cmd_name
48end
49
50local function recordDefaults()

--- 216 unchanged lines hidden (view full) ---

267 return core.cached_kernels
268end
269
270function core.bootenvDefault()
271 return loader.getenv("zfs_be_active")
272end
273
274function core.bootenvList()
273 local bootenv_count = tonumber(loader.getenv("bootenvs_count"))
275 local bootenv_count = tonumber(loader.getenv(bootenv_list .. "_count"))
274 local bootenvs = {}
275 local curenv
276 local envcount = 0
277 local unique = {}
278
279 if bootenv_count == nil or bootenv_count <= 0 then
280 return bootenvs
281 end
282
283 -- Currently selected bootenv is always first/default
276 local bootenvs = {}
277 local curenv
278 local envcount = 0
279 local unique = {}
280
281 if bootenv_count == nil or bootenv_count <= 0 then
282 return bootenvs
283 end
284
285 -- Currently selected bootenv is always first/default
284 curenv = core.bootenvDefault()
286 -- On the rewinded list the bootenv may not exists
287 if core.isRewinded() then
288 curenv = core.bootenvDefaultRewinded()
289 else
290 curenv = core.bootenvDefault()
291 end
285 if curenv ~= nil then
286 envcount = envcount + 1
287 bootenvs[envcount] = curenv
288 unique[curenv] = true
289 end
290
291 for curenv_idx = 0, bootenv_count - 1 do
292 if curenv ~= nil then
293 envcount = envcount + 1
294 bootenvs[envcount] = curenv
295 unique[curenv] = true
296 end
297
298 for curenv_idx = 0, bootenv_count - 1 do
292 curenv = loader.getenv("bootenvs[" .. curenv_idx .. "]")
299 curenv = loader.getenv(bootenv_list .. "[" .. curenv_idx .. "]")
293 if curenv ~= nil and unique[curenv] == nil then
294 envcount = envcount + 1
295 bootenvs[envcount] = curenv
296 unique[curenv] = true
297 end
298 end
299 return bootenvs
300end
301
300 if curenv ~= nil and unique[curenv] == nil then
301 envcount = envcount + 1
302 bootenvs[envcount] = curenv
303 unique[curenv] = true
304 end
305 end
306 return bootenvs
307end
308
309function core.isCheckpointed()
310 return loader.getenv("zpool_checkpoint") ~= nil
311end
312
313function core.bootenvDefaultRewinded()
314 local defname = "zfs:!" .. string.sub(core.bootenvDefault(), 5)
315 local bootenv_count = tonumber("bootenvs_check_count")
316
317 if bootenv_count == nil or bootenv_count <= 0 then
318 return defname
319 end
320
321 for curenv_idx = 0, bootenv_count - 1 do
322 curenv = loader.getenv("bootenvs_check[" .. curenv_idx .. "]")
323 if curenv == defname then
324 return defname
325 end
326 end
327
328 return loader.getenv("bootenvs_check[0]")
329end
330
331function core.isRewinded()
332 return bootenv_list == "bootenvs_check"
333end
334
335function core.changeRewindCheckpoint()
336 if core.isRewinded() then
337 bootenv_list = "bootenvs"
338 else
339 bootenv_list = "bootenvs_check"
340 end
341end
342
302function core.setDefaults()
303 core.setACPI(core.getACPIPresent(true))
304 core.setSafeMode(default_safe_mode)
305 core.setSingleUser(default_single_user)
306 core.setVerbose(default_verbose)
307end
308
309function core.autoboot(argstr)

--- 106 unchanged lines hidden ---
343function core.setDefaults()
344 core.setACPI(core.getACPIPresent(true))
345 core.setSafeMode(default_safe_mode)
346 core.setSingleUser(default_single_user)
347 core.setVerbose(default_verbose)
348end
349
350function core.autoboot(argstr)

--- 106 unchanged lines hidden ---