Merge branch 'vendor/GMP' into gcc441
[dragonfly.git] / usr.sbin / installer / dfuibe_installer / fn_subpart_hammer.c
1 /*
2  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *   Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  *
11  *   Redistributions in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in
13  *   the documentation and/or other materials provided with the
14  *   distribution.
15  *
16  *   Neither the name of the DragonFly Project nor the names of its
17  *   contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 /*
35  * fn_subpart_hammer.c
36  * Installer Function : Create HAMMER Subpartitions.
37  */
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42
43 #ifdef ENABLE_NLS
44 #include <libintl.h>
45 #define _(String) gettext (String)
46 #else
47 #define _(String) (String)
48 #endif
49
50 #include "libaura/mem.h"
51 #include "libaura/buffer.h"
52 #include "libaura/dict.h"
53 #include "libaura/fspred.h"
54
55 #include "libdfui/dfui.h"
56 #include "libdfui/dump.h"
57 #include "libdfui/system.h"
58
59 #include "libinstaller/commands.h"
60 #include "libinstaller/diskutil.h"
61 #include "libinstaller/functions.h"
62 #include "libinstaller/uiutil.h"
63
64 #include "fn.h"
65 #include "flow.h"
66 #include "pathnames.h"
67
68 static int      create_subpartitions(struct i_fn_args *);
69 static long     default_capacity(struct storage *, const char *);
70 static int      check_capacity(struct i_fn_args *);
71 static int      check_subpartition_selections(struct dfui_response *, struct i_fn_args *);
72 static void     save_subpartition_selections(struct dfui_response *, struct i_fn_args *);
73 static void     populate_create_subpartitions_form(struct dfui_form *, struct i_fn_args *);
74 static int      warn_subpartition_selections(struct i_fn_args *);
75 static struct dfui_form *make_create_subpartitions_form(struct i_fn_args *);
76 static int      show_create_subpartitions_form(struct dfui_form *, struct i_fn_args *);
77
78 static const char *def_mountpt[]  = {"/boot", "swap", "/", NULL};
79 static int expert = 0;
80
81 /*
82  * Given a set of subpartitions-to-be in the selected slice,
83  * create them.
84  */
85 static int
86 create_subpartitions(struct i_fn_args *a)
87 {
88         struct subpartition *sp;
89         struct commands *cmds;
90         int result = 0;
91         int num_partitions;
92
93         cmds = commands_new();
94         if (!is_file("%sinstall.disklabel.%s",
95             a->tmp,
96             slice_get_device_name(storage_get_selected_slice(a->s)))) {
97                 /*
98                  * Get a copy of the 'virgin' disklabel.
99                  * XXX It might make more sense for this to
100                  * happen right after format_slice() instead.
101                  */
102                 command_add(cmds, "%s%s -r %s >%sinstall.disklabel.%s",
103                     a->os_root, cmd_name(a, "DISKLABEL64"),
104                     slice_get_device_name(storage_get_selected_slice(a->s)),
105                     a->tmp,
106                     slice_get_device_name(storage_get_selected_slice(a->s)));
107         }
108
109         /*
110          * Weave together a new disklabel out the of the 'virgin'
111          * disklabel, and the user's subpartition choices.
112          */
113
114         /*
115          * Take everything from the 'virgin' disklabel up until the
116          * '16 partitions' line.
117          */
118         num_partitions = 16;
119         command_add(cmds, "%s%s '$2==\"partitions:\" || cut { cut = 1 } !cut { print $0 }' <%sinstall.disklabel.%s >%sinstall.disklabel",
120             a->os_root, cmd_name(a, "AWK"),
121             a->tmp,
122             slice_get_device_name(storage_get_selected_slice(a->s)),
123             a->tmp);
124
125         /*
126          * 16 partitions:
127          * #          size     offset    fstype
128          *   c:   16383969          0    unused #    7999.985MB
129          */
130
131         command_add(cmds, "%s%s '%d partitions:' >>%sinstall.disklabel",
132             a->os_root, cmd_name(a, "ECHO"), num_partitions ,a->tmp);
133         command_add(cmds, "%s%s '%s' >>%sinstall.disklabel",
134             a->os_root, cmd_name(a, "ECHO"),
135             "#          size     offset    fstype",
136             a->tmp);
137
138 #ifdef DEBUG
139         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
140              sp != NULL; sp = subpartition_next(sp)) {
141                 command_add(cmds, "%s%s 'mountpoint: %s device: %s'",
142                      a->os_root, cmd_name(a, "ECHO"),
143                      subpartition_get_mountpoint(sp),
144                      subpartition_get_device_name(sp));
145         }
146 #endif
147
148         /*
149          * Write a line for each subpartition the user wants.
150          */
151         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
152              sp != NULL; sp = subpartition_next(sp)) {
153                 if (subpartition_is_mfsbacked(sp)) {
154                         continue;
155                 }
156                 if (subpartition_is_swap(sp)) {
157                         command_add(cmds, "%s%s '  %c:\t%s\t*\tswap' >>%sinstall.disklabel",
158                             a->os_root, cmd_name(a, "ECHO"),
159                             subpartition_get_letter(sp),
160                             capacity_to_string(subpartition_get_capacity(sp)),
161                             a->tmp);
162                 } else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
163                         command_add(cmds, "%s%s '  %c:\t%s\t0\t4.2BSD' >>%sinstall.disklabel",
164                             a->os_root, cmd_name(a, "ECHO"),
165                             subpartition_get_letter(sp),
166                             capacity_to_string(subpartition_get_capacity(sp)),
167                             a->tmp);
168                 } else {
169                         command_add(cmds, "%s%s '  %c:\t%s\t*\tHAMMER' >>%sinstall.disklabel",
170                             a->os_root, cmd_name(a, "ECHO"),
171                             subpartition_get_letter(sp),
172                             capacity_to_string(subpartition_get_capacity(sp)),
173                             a->tmp);
174                 }
175         }
176         temp_file_add(a, "install.disklabel");
177
178         /*
179          * Label the slice from the disklabel we just wove together.
180          */
181         command_add(cmds, "%s%s -R -B -r %s %sinstall.disklabel",
182             a->os_root, cmd_name(a, "DISKLABEL64"),
183             slice_get_device_name(storage_get_selected_slice(a->s)),
184             a->tmp);
185
186         /*
187          * Create a snapshot of the disklabel we just created
188          * for debugging inspection in the log.
189          */
190         command_add(cmds, "%s%s %s",
191             a->os_root, cmd_name(a, "DISKLABEL64"),
192             slice_get_device_name(storage_get_selected_slice(a->s)));
193
194         /*
195          * Create filesystems on the newly-created subpartitions.
196          */
197         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
198              sp != NULL; sp = subpartition_next(sp)) {
199                 if (subpartition_is_swap(sp) || subpartition_is_mfsbacked(sp))
200                         continue;
201
202                 /*
203                  * Ensure that all the needed device nodes exist.
204                  */
205                 command_add_ensure_dev(a, cmds,
206                     disk_get_device_name(storage_get_selected_disk(a->s)));
207                 command_add_ensure_dev(a, cmds,
208                     slice_get_device_name(storage_get_selected_slice(a->s)));
209                 command_add_ensure_dev(a, cmds,
210                     subpartition_get_device_name(sp));
211
212                 if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
213                         command_add(cmds, "%s%s %sdev/%s",
214                             a->os_root, cmd_name(a, "NEWFS"),
215                             a->os_root,
216                             subpartition_get_device_name(sp));
217                 } else {
218                         command_add(cmds, "%s%s -f -L ROOT %sdev/%s",
219                             a->os_root, cmd_name(a, "NEWFS_HAMMER"),
220                             a->os_root,
221                             subpartition_get_device_name(sp));
222                 }
223         }
224
225         result = commands_execute(a, cmds);
226         commands_free(cmds);
227         return(result);
228 }
229
230 static long
231 default_capacity(struct storage *s, const char *mtpt)
232 {
233         unsigned long swap;
234         unsigned long capacity;
235         unsigned long mem;
236
237         capacity = slice_get_capacity(storage_get_selected_slice(s));
238         mem = storage_get_memsize(s);
239         swap = 2 * mem;
240         if (mem > (capacity / 2) || capacity < 4096)
241                 swap = mem;
242         if (mem > capacity)
243                 swap = capacity / 2;
244         if (swap > 8192)
245                 swap = 8192;
246
247         if (capacity < DISK_MIN) {
248                 /*
249                  * For the purposes of this installer:
250                  * can't be done.  Sorry.
251                  */
252                 return(-1);
253         } else if (strcmp(mtpt, "/boot") == 0) {
254                 return(256);
255         } else if (strcmp(mtpt, "swap") == 0) {
256                 return(swap);
257         } else if (strcmp(mtpt, "/") == 0) {
258                 return(-1);
259         }
260         /* shouldn't ever happen */
261         return(-1);
262 }
263
264 static int
265 check_capacity(struct i_fn_args *a)
266 {
267         struct subpartition *sp;
268         unsigned long min_capacity[] = {256, 0, DISK_MIN - 256, 0};
269         unsigned long total_capacity = 0;
270         int mtpt;
271
272         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
273              sp != NULL; sp = subpartition_next(sp)) {
274                 if (subpartition_get_capacity(sp) == -1)
275                         total_capacity++;
276                 else
277                         total_capacity += subpartition_get_capacity(sp);
278                 for (mtpt = 0; def_mountpt[mtpt] != NULL; mtpt++) {
279                         if (strcmp(subpartition_get_mountpoint(sp), def_mountpt[mtpt]) == 0 &&
280                             min_capacity[mtpt] > 0 &&
281                             subpartition_get_capacity(sp) < min_capacity[mtpt]) {
282                                 inform(a->c, _("WARNING: the %s subpartition should "
283                                     "be at least %dM in size or you will "
284                                     "risk running out of space during "
285                                     "the installation."),
286                                     subpartition_get_mountpoint(sp), min_capacity[mtpt]);
287                         }
288                 }
289                 if (strcmp(subpartition_get_mountpoint(sp), "/") == 0 &&
290                     subpartition_get_capacity(sp) < HAMMER_MIN) {
291                         inform(a->c, _("WARNING: HAMMER file systems"
292                         "less than 50G are not recommended!  You may"
293                         "have to run 'hammer prune-everything' and 'hammer reblock'"
294                         "quite often, even if using a nohistory mount."));
295                 }
296         }
297
298         if (total_capacity > slice_get_capacity(storage_get_selected_slice(a->s))) {
299                 inform(a->c, _("The space allocated to all of your selected "
300                     "subpartitions (%dM) exceeds the total "
301                     "capacity of the selected primary partition "
302                     "(%dM). Remove some subpartitions or choose "
303                     "a smaller size for them and try again."),
304                     total_capacity, slice_get_capacity(storage_get_selected_slice(a->s)));
305                 return(0);
306         }
307
308         return(1);
309 }
310
311 static int
312 check_subpartition_selections(struct dfui_response *r, struct i_fn_args *a)
313 {
314         struct dfui_dataset *ds;
315         struct dfui_dataset *star_ds = NULL;
316         struct aura_dict *d;
317         const char *mountpoint, *capstring;
318         long capacity = 0;
319         int found_root = 0;
320         int valid = 1;
321
322         d = aura_dict_new(1, AURA_DICT_LIST);
323
324         if ((ds = dfui_response_dataset_get_first(r)) == NULL) {
325                 inform(a->c, _("Please set up at least one subpartition."));
326                 valid = 0;
327         }
328
329         for (ds = dfui_response_dataset_get_first(r); valid && ds != NULL;
330             ds = dfui_dataset_get_next(ds)) {
331 #ifdef DEBUG
332                 dfui_dataset_dump(ds);
333 #endif
334                 mountpoint = dfui_dataset_get_value(ds, "mountpoint");
335                 capstring = dfui_dataset_get_value(ds, "capacity");
336
337                 if (aura_dict_exists(d, mountpoint, strlen(mountpoint) + 1)) {
338                         inform(a->c, _("The same mount point cannot be specified "
339                             "for two different subpartitions."));
340                         valid = 0;
341                 }
342
343                 if (strcmp(mountpoint, "/") == 0)
344                         found_root = 1;
345
346                 if (strcmp(capstring, "*") == 0) {
347                         if (star_ds != NULL) {
348                                 inform(a->c, _("You cannot have more than one subpartition "
349                                     "with a '*' capacity (meaning 'use the remainder "
350                                     "of the primary partition'.)"));
351                                 valid = 0;
352                         } else {
353                                 star_ds = ds;
354                         }
355                 }
356
357                 if (!(!strcasecmp(mountpoint, "swap") || mountpoint[0] == '/')) {
358                         inform(a->c, _("Mount point must be either 'swap', or it must "
359                             "start with a '/'."));
360                         valid = 0;
361                 }
362
363                 if (strpbrk(mountpoint, " \\\"'`") != NULL) {
364                         inform(a->c, _("Mount point may not contain the following "
365                             "characters: blank space, backslash, or "
366                             "single, double, or back quotes."));
367                         valid = 0;
368                 }
369
370                 if (strlen(capstring) == 0) {
371                         inform(a->c, _("A capacity must be specified."));
372                         valid = 0;
373                 }
374
375                 if (!string_to_capacity(capstring, &capacity)) {
376                         inform(a->c, _("Capacity must be either a '*' symbol to indicate "
377                             "'use the rest of the primary partition', or it "
378                             "must be a series of decimal digits ending with a "
379                             "'M' (indicating megabytes) or a 'G' (indicating "
380                             "gigabytes.)"));
381                         valid = 0;
382                 }
383
384                 if ((strcasecmp(mountpoint, "swap") == 0) && (capacity > 8192)) {
385                         inform(a->c, _("Swap capacity is limited to 8G."));
386                         valid = 0;
387                 }
388
389                 /*
390                  * If we made it through that obstacle course, all is well.
391                  */
392
393                 if (valid)
394                         aura_dict_store(d, mountpoint, strlen(mountpoint) + 1, "", 1);
395         }
396
397         if (!found_root) {
398                 inform(a->c, _("You must include a / (root) subpartition."));
399                 valid = 0;
400         }
401
402         if (aura_dict_size(d) > 16) {
403                 inform(a->c, _("You cannot have more than 16 subpartitions "
404                     "on a single primary partition.  Remove some "
405                     "and try again."));
406                 valid = 0;
407         }
408
409         aura_dict_free(d);
410
411         return(valid);
412 }
413
414 static void
415 save_subpartition_selections(struct dfui_response *r, struct i_fn_args *a)
416 {
417         struct dfui_dataset *ds;
418         const char *mountpoint, *capstring;
419         long capacity;
420         int valid = 1;
421
422         subpartitions_free(storage_get_selected_slice(a->s));
423
424         for (ds = dfui_response_dataset_get_first(r); valid && ds != NULL;
425             ds = dfui_dataset_get_next(ds)) {
426                 mountpoint = dfui_dataset_get_value(ds, "mountpoint");
427                 capstring = dfui_dataset_get_value(ds, "capacity");
428
429                 if (string_to_capacity(capstring, &capacity)) {
430                         subpartition_new_hammer(storage_get_selected_slice(a->s),
431                              mountpoint, capacity);
432                 }
433         }
434 }
435
436 static void
437 populate_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a)
438 {
439         struct subpartition *sp;
440         struct dfui_dataset *ds;
441         int i;
442         long capacity;
443
444         if (slice_subpartition_first(storage_get_selected_slice(a->s)) != NULL) {
445                 /*
446                  * The user has already given us their subpartition
447                  * preferences, so use them here.
448                  */
449                 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
450                      sp != NULL; sp = subpartition_next(sp)) {
451                         ds = dfui_dataset_new();
452                         dfui_dataset_celldata_add(ds, "mountpoint",
453                             subpartition_get_mountpoint(sp));
454                         dfui_dataset_celldata_add(ds, "capacity",
455                             capacity_to_string(subpartition_get_capacity(sp)));
456                         dfui_form_dataset_add(f, ds);
457                 }
458         } else {
459                 /*
460                  * Otherwise, populate the form with datasets representing
461                  * reasonably-calculated defaults.  The defaults are chosen
462                  * based on the slice's total capacity and the machine's
463                  * total physical memory (for swap.)
464                  */
465                 for (i = 0; def_mountpt[i] != NULL; i++) {
466                         capacity = default_capacity(a->s, def_mountpt[i]);
467                         ds = dfui_dataset_new();
468                         dfui_dataset_celldata_add(ds, "mountpoint",
469                             def_mountpt[i]);
470                         dfui_dataset_celldata_add(ds, "capacity",
471                             capacity_to_string(capacity));
472                         dfui_form_dataset_add(f, ds);
473                 }
474         }
475 }
476
477 static int
478 warn_subpartition_selections(struct i_fn_args *a)
479 {
480         int valid = 0;
481
482         if (subpartition_find(storage_get_selected_slice(a->s), "/boot") == NULL) {
483                 inform(a->c, _("The /boot partition must not be omitted."));
484         } else if (subpartition_find(storage_get_selected_slice(a->s), "/home") != NULL ||
485             subpartition_find(storage_get_selected_slice(a->s), "/tmp") != NULL ||
486             subpartition_find(storage_get_selected_slice(a->s), "/usr") != NULL ||
487             subpartition_find(storage_get_selected_slice(a->s), "/usr/obj") != NULL ||
488             subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL ||
489             subpartition_find(storage_get_selected_slice(a->s), "/var/crash") != NULL ||
490             subpartition_find(storage_get_selected_slice(a->s), "/var/tmp") != NULL) {
491                 inform(a->c, _("Pseudo filesystems will automatically be created "
492                         "for /home, /tmp, /usr, /usr/obj, /var, /var/crash "
493                         "and /var/tmp and must not be specified."));
494         } else {
495                 valid = check_capacity(a);
496         }
497
498         return(!valid);
499 }
500
501 static struct dfui_form *
502 make_create_subpartitions_form(struct i_fn_args *a)
503 {
504         struct dfui_form *f;
505         char msg_buf[1][1024];
506
507         snprintf(msg_buf[0], sizeof(msg_buf[0]),
508             _("Subpartitions further divide a primary partition for "
509             "use with %s.  Some reasons you may want "
510             "a set of subpartitions are:\n\n"
511             "- you want to restrict how much data can be written "
512             "to certain parts of the primary partition, to quell "
513             "denial-of-service attacks; and\n"
514             "- you want to speed up access to data on the disk."
515             ""), OPERATING_SYSTEM_NAME);
516
517         f = dfui_form_create(
518             "create_subpartitions",
519             _("Create Subpartitions"),
520             _("Set up the subpartitions (also known as just `partitions' "
521             "in BSD tradition) you want to have on this primary "
522             "partition. In most cases you should be fine with "
523             "the default settings.\n\n"
524             "For Capacity, use 'M' to indicate megabytes, 'G' to "
525             "indicate gigabytes, or a single '*' to indicate "
526             "'use the remaining space on the primary partition'."),
527
528             msg_buf[0],
529
530             "p", "special", "dfinstaller_create_subpartitions",
531             "p", "minimum_width","64",
532
533             "f", "mountpoint", _("Mountpoint"), "", "",
534             "f", "capacity", _("Capacity"), "", "",
535
536             "a", "ok", _("Accept and Create"), "", "",
537             "a", "cancel",
538             (disk_get_formatted(storage_get_selected_disk(a->s)) ?
539             _("Return to Select Disk") :
540             _("Return to Select Primary Partition")), "", "",
541             "p", "accelerator", "ESC",
542
543             NULL
544         );
545
546         dfui_form_set_multiple(f, 1);
547         dfui_form_set_extensible(f, 1);
548         /*
549          * Remove ATM until HAMMER installer support is better
550          * dfui_form_set_extensible(f, 1);
551          */
552 #if 0
553         if (expert) {
554                 fi = dfui_form_field_add(f, "softupdates",
555                     dfui_info_new(_("Softupdates"), "", ""));
556                 dfui_field_property_set(fi, "control", "checkbox");
557
558                 fi = dfui_form_field_add(f, "mfsbacked",
559                     dfui_info_new(_("MFS"), "", ""));
560                 dfui_field_property_set(fi, "control", "checkbox");
561
562                 fi = dfui_form_field_add(f, "fsize",
563                     dfui_info_new(_("Frag Sz"), "", ""));
564
565                 fi = dfui_form_field_add(f, "bsize",
566                     dfui_info_new(_("Block Sz"), "", ""));
567
568                 dfui_form_action_add(f, "switch",
569                     dfui_info_new(_("Switch to Normal Mode"), "", ""));
570         } else {
571                 dfui_form_action_add(f, "switch",
572                     dfui_info_new(_("Switch to Expert Mode"), "", ""));
573         }
574 #endif
575         return(f);
576 }
577
578 /*
579  * Returns:
580  *      -1 = the form should be redisplayed
581  *       0 = failure, function is over
582  *       1 = success, function is over
583  */
584 static int
585 show_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a)
586 {
587         struct dfui_dataset *ds;
588         struct dfui_response *r;
589
590         for (;;) {
591                 if (dfui_form_dataset_get_first(f) == NULL)
592                         populate_create_subpartitions_form(f, a);
593
594                 if (!dfui_be_present(a->c, f, &r))
595                         abort_backend();
596
597                 if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
598                         dfui_response_free(r);
599                         return(0);
600                 } else if (strcmp(dfui_response_get_action_id(r), "switch") == 0) {
601                         if (check_subpartition_selections(r, a)) {
602                                 save_subpartition_selections(r, a);
603                                 expert = expert ? 0 : 1;
604                                 dfui_response_free(r);
605                                 return(-1);
606                         }
607                 } else {
608                         if (check_subpartition_selections(r, a)) {
609                                 save_subpartition_selections(r, a);
610                                 if (!warn_subpartition_selections(a)) {
611                                         if (!create_subpartitions(a)) {
612                                                 inform(a->c, _("The subpartitions you chose were "
613                                                         "not correctly created, and the "
614                                                         "primary partition may "
615                                                         "now be in an inconsistent state. "
616                                                         "We recommend re-formatting it "
617                                                         "before proceeding."));
618                                                 dfui_response_free(r);
619                                                 return(0);
620                                         } else {
621                                                 dfui_response_free(r);
622                                                 return(1);
623                                         }
624                                 }
625                         }
626                 }
627
628                 dfui_form_datasets_free(f);
629                 /* dfui_form_datasets_add_from_response(f, r); */
630                 for (ds = dfui_response_dataset_get_first(r); ds != NULL;
631                     ds = dfui_dataset_get_next(ds)) {
632                         dfui_form_dataset_add(f, dfui_dataset_dup(ds));
633                 }
634         }
635 }
636
637 /*
638  * fn_create_subpartitions_hammer: let the user specify what subpartitions they
639  * want on the disk, how large each should be, and where it should be mounted.
640  */
641 void
642 fn_create_subpartitions_hammer(struct i_fn_args *a)
643 {
644         struct dfui_form *f;
645         int done = 0;
646
647         a->result = 0;
648         while (!done) {
649                 f = make_create_subpartitions_form(a);
650                 switch (show_create_subpartitions_form(f, a)) {
651                 case -1:
652                         done = 0;
653                         break;
654                 case 0:
655                         done = 1;
656                         a->result = 0;
657                         break;
658                 case 1:
659                         done = 1;
660                         a->result = 1;
661                         break;
662                 }
663                 dfui_form_free(f);
664         }
665 }