1 -- $Id: 250_partition_disk.lua,v 1.21 2005/03/31 12:35:50 den Exp $
5 local datasets_list = nil
7 local name_to_sysid_map = {
8 ["DragonFly/FreeBSD"] = 165,
16 local options_list = {}
17 local sysid_to_name_map = {}
19 for k, v in name_to_sysid_map do
20 table.insert(options_list, k)
21 sysid_to_name_map[v] = k
24 local populate_from_disk = function(dd)
28 local toyn = function(bool)
36 for pd in dd:get_parts() do
38 capstring = StorageDescriptor.format_capstring(pd:get_size()),
39 sysid = sysid_to_name_map[pd:get_sysid()] or
40 tostring(pd:get_sysid()),
41 active = toyn(pd:is_active())
48 local populate_one_big_partition = function(dd)
58 local edit_partitions = function(fsm)
59 if not datasets_list then
60 datasets_list = populate_from_disk(App.state.sel_disk)
70 name = _("Partition Type"),
71 options = options_list,
81 local actions_list = {
84 name = _("Accept and Create"),
88 name = _("Return to %s", fsm:prev().title),
92 local response = App.ui:present({
93 id = "edit_partitions",
94 name = _("Edit Partitions"),
95 short_desc = _("Select the partitions (also known " ..
96 "as `slices' in BSD tradition) you want to " ..
97 "have on this disk.\n\n" ..
98 "For Capacity, use 'M' to indicate megabytes, 'G' to " ..
99 "indicate gigabytes, or a single '*' to indicate " ..
100 "'use the remaining space on the disk'."),
101 special = "bsdinstaller_edit_partitions",
102 minimum_width = "64",
104 actions = actions_list,
105 fields = fields_list,
106 datasets = datasets_list,
112 -- remember these subpartition selections in case we come back here.
113 datasets_list = response.datasets
115 return response.action_id == "ok"
118 local check_datasets = function(dd, list)
121 local disk_size = dd:get_raw_size()
122 local used_size = 60 -- initial offset
123 local wildcard_size = false
125 for i, dataset in list do
126 if (name_to_sysid_map[dataset.sysid] or tonumber(dataset.sysid)) == 0 then
128 "'%s' is not a recognized partition type. " ..
129 "Please use a numeric identifier if you " ..
130 "wish to use an unlisted partition type.",
136 if dataset.capstring == "*" then
137 if wildcard_size then
139 "Only one partition may have a " ..
147 size = StorageDescriptor.parse_capstring(dataset.capstring, 0)
150 "Capacity must either end in 'M' " ..
151 "for megabytes, 'G' for gigabytes, " ..
152 "or be '*' to indicate 'use all " ..
158 used_size = used_size + size
161 if used_size > disk_size then
162 if not App.ui:confirm(_(
163 "WARNING: The total number of sectors needed " ..
164 "for the requested partitions (%d) exceeds the " ..
165 "number of sectors available on the disk (%d) " ..
166 "by %d sectors (%s.)\n\n" ..
167 "This is an invalid configuration; we " ..
168 "recommend shrinking the size of one or " ..
169 "more partitions before proceeding.\n\n" ..
171 used_size, disk_size, used_size - disk_size,
172 StorageDescriptor.format_capstring(used_size - disk_size))) then
177 if used_size < disk_size - App.state.max_waste and
178 not wildcard_size then
179 if not App.ui:confirm(_(
180 "Note: the total number of sectors needed " ..
181 "for the requested partitions (%d) does not make " ..
182 "full use of the number of sectors available " ..
183 "on the disk (%d.) There will be %d unused " ..
184 "sectors (%s.)\n\n" ..
185 "You may wish to expand one or more partitions " ..
186 "before proceeding.\n\n" ..
188 used_size, disk_size, disk_size - used_size,
189 StorageDescriptor.format_capstring(disk_size - used_size))) then
198 -- This assumes check_datasets has already been called.
200 local create_partitions_from_datasets = function(dd, list)
204 local disk_size = dd:get_raw_size()
205 local used_size = offset
211 for i, dataset in list do
212 used_size = used_size +
213 StorageDescriptor.parse_capstring(dataset.capstring, 0)
216 for i, dataset in list do
217 size = StorageDescriptor.parse_capstring(dataset.capstring,
218 disk_size - used_size)
220 dd:add_part(PartitionDescriptor.new{
225 sysid = name_to_sysid_map[dataset.sysid] or tonumber(dataset.sysid),
226 active = (dataset.active == "Y")
229 offset = offset + size
230 part_no = part_no + 1
236 local do_edit_partitions = function(fsm)
237 if edit_partitions(fsm) then
238 local cmds = CmdChain.new()
240 if check_datasets(App.state.sel_disk, datasets_list) and
241 create_partitions_from_datasets(
242 App.state.sel_disk, datasets_list) then
244 App.state.sel_disk:cmds_partition(cmds)
247 -- refresh our knowledge of the storage
248 App.state.sel_disk, App.state.sel_part =
249 App.state.storage:resurvey(
250 App.state.sel_disk, App.state.sel_part
253 -- Mark this disk as having been 'touched'
254 -- (modified destructively, i.e. partitioned)
256 if App.state.sel_disk then
257 App.state.sel_disk:touch()
270 name = "partition_disk",
271 title = "Partition Disk",
272 action = function(fsm)
275 if App.state.sel_disk:has_been_touched() then
276 return do_edit_partitions(fsm)
279 if App.state.sel_disk:get_part_count() == 0 then
281 "No valid partitions were found on this disk. " ..
282 "You will have to create at least one in which " ..
286 return do_edit_partitions(fsm)
289 choices[_("Format and Partition Disk")] = function()
290 return do_edit_partitions(fsm)
293 choices[_("Skip this Step")] = function()
297 choices[_("Return to %s", fsm:prev().title)] = function()
301 return App.ui:select(_(
302 "You may now format and partition this disk if you desire." ..
304 "If this is a brand new disk, you should do this. If you " ..
305 "would like to place multiple operating systems on this disk, " ..
306 "you should create multiple partitions, one for each operating " ..
309 "If this disk already has operating systems on it that you wish " ..
310 "to keep, you should NOT do this, and should skip this step." ..
312 "Format and partition this disk?"),