installer: Add __printflike()s and fix resulting format warnings.
[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_tmpfsbacked(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_tmpfsbacked(sp))
200                         continue;
201
202                 if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
203                         command_add(cmds, "%s%s %sdev/%s",
204                             a->os_root, cmd_name(a, "NEWFS"),
205                             a->os_root,
206                             subpartition_get_device_name(sp));
207                 } else {
208                         command_add(cmds, "%s%s -f -L ROOT %sdev/%s",
209                             a->os_root, cmd_name(a, "NEWFS_HAMMER"),
210                             a->os_root,
211                             subpartition_get_device_name(sp));
212                 }
213         }
214
215         result = commands_execute(a, cmds);
216         commands_free(cmds);
217         return(result);
218 }
219
220 static long
221 default_capacity(struct storage *s, const char *mtpt)
222 {
223         unsigned long boot, root, swap;
224         unsigned long capacity;
225         unsigned long mem;
226
227         capacity = slice_get_capacity(storage_get_selected_slice(s));
228         mem = storage_get_memsize(s);
229
230         /*
231          * Try to get 768M for /boot, but if space is tight go down to 128M
232          * in 128M steps.
233          * For swap, start with 2*mem but take less if space is tight
234          * (minimum is 384).
235          * Rest goes to / (which is at least 75% slice size).
236          */
237
238         root = capacity / 4 * 3;
239         swap = 2 * mem;
240         if (swap > 8192)
241                 swap = 8192;
242         boot = 768;
243         while (boot + root > capacity - 384)
244                 boot -= 128;
245         if (boot + root + swap > capacity)
246                 swap = capacity - boot - root;
247
248         if (capacity < DISK_MIN)
249                 return(-1);
250         else if (strcmp(mtpt, "/boot") == 0)
251                 return(boot);
252         else if (strcmp(mtpt, "swap") == 0)
253                 return(swap);
254         else if (strcmp(mtpt, "/") == 0)
255                 return(-1);
256
257         /* shouldn't ever happen */
258         return(-1);
259 }
260
261 static int
262 check_capacity(struct i_fn_args *a)
263 {
264         struct subpartition *sp;
265         long min_capacity[] = {128, 0, DISK_MIN - 128, 0};
266         unsigned long total_capacity = 0;
267         unsigned long remaining_capacity;
268         int mtpt, warn_smallpart = 0;
269
270         remaining_capacity = slice_get_capacity(storage_get_selected_slice(a->s));
271         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
272              sp != NULL; sp = subpartition_next(sp)) {
273                 if (subpartition_get_capacity(sp) != -1)
274                         remaining_capacity -= subpartition_get_capacity(sp);
275         }
276
277         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
278              sp != NULL; sp = subpartition_next(sp)) {
279                 long subpart_capacity = subpartition_get_capacity(sp);
280                 const char *mountpt = subpartition_get_mountpoint(sp);
281
282                 if (subpart_capacity == -1)
283                         total_capacity++;
284                 else
285                         total_capacity += subpart_capacity;
286                 for (mtpt = 0; def_mountpt[mtpt] != NULL; mtpt++) {
287                         if (strcmp(mountpt, def_mountpt[mtpt]) == 0 &&
288                             subpart_capacity < min_capacity[mtpt] &&
289                             subpart_capacity != -1) {
290                                 inform(a->c, _("WARNING: The size (%ldM) specified for "
291                                     "the %s subpartition is too small. It "
292                                     "should be at least %ldM or you will "
293                                     "risk running out of space during "
294                                     "the installation."),
295                                     subpart_capacity, mountpt,
296                                     min_capacity[mtpt]);
297                         }
298                 }
299                 if (strcmp(mountpt, "/boot") != 0 &&
300                     strcmp(mountpt, "swap") != 0) {
301                         if ((subpart_capacity == -1 && remaining_capacity < HAMMER_MIN) ||
302                             (subpart_capacity != -1 && subpart_capacity < HAMMER_MIN))
303                                 warn_smallpart++;
304                 }
305         }
306
307         if (total_capacity > slice_get_capacity(storage_get_selected_slice(a->s))) {
308                 inform(a->c, _("The space allocated to all of your selected "
309                     "subpartitions (%luM) exceeds the total "
310                     "capacity of the selected primary partition "
311                     "(%luM). Remove some subpartitions or choose "
312                     "a smaller size for them and try again."),
313                     total_capacity, slice_get_capacity(storage_get_selected_slice(a->s)));
314                 return(0);
315         }
316
317         if (warn_smallpart)
318                 return (confirm_dangerous_action(a->c,
319                     _("WARNING: HAMMER filesystems less than 50GB are "
320                     "not recommended!\n"
321                     "You may have to run 'hammer prune-everything' and "
322                     "'hammer reblock'\n"
323                     "quite often, even if using a nohistory mount.")));
324
325         return(1);
326 }
327
328 static int
329 check_subpartition_selections(struct dfui_response *r, struct i_fn_args *a)
330 {
331         struct dfui_dataset *ds;
332         struct dfui_dataset *star_ds = NULL;
333         struct aura_dict *d;
334         const char *mountpoint, *capstring;
335         long capacity = 0;
336         int found_root = 0;
337         int valid = 1;
338
339         d = aura_dict_new(1, AURA_DICT_LIST);
340
341         if ((ds = dfui_response_dataset_get_first(r)) == NULL) {
342                 inform(a->c, _("Please set up at least one subpartition."));
343                 valid = 0;
344         }
345
346         for (ds = dfui_response_dataset_get_first(r); valid && ds != NULL;
347             ds = dfui_dataset_get_next(ds)) {
348 #ifdef DEBUG
349                 dfui_dataset_dump(ds);
350 #endif
351                 mountpoint = dfui_dataset_get_value(ds, "mountpoint");
352                 capstring = dfui_dataset_get_value(ds, "capacity");
353
354                 if (aura_dict_exists(d, mountpoint, strlen(mountpoint) + 1)) {
355                         inform(a->c, _("The same mount point cannot be specified "
356                             "for two different subpartitions."));
357                         valid = 0;
358                 }
359
360                 if (strcmp(mountpoint, "/") == 0)
361                         found_root = 1;
362
363                 if (strcmp(capstring, "*") == 0) {
364                         if (star_ds != NULL) {
365                                 inform(a->c, _("You cannot have more than one subpartition "
366                                     "with a '*' capacity (meaning 'use the remainder "
367                                     "of the primary partition'.)"));
368                                 valid = 0;
369                         } else {
370                                 star_ds = ds;
371                         }
372                 }
373
374                 if (!(!strcasecmp(mountpoint, "swap") || mountpoint[0] == '/')) {
375                         inform(a->c, _("Mount point must be either 'swap', or it must "
376                             "start with a '/'."));
377                         valid = 0;
378                 }
379
380                 if (strpbrk(mountpoint, " \\\"'`") != NULL) {
381                         inform(a->c, _("Mount point may not contain the following "
382                             "characters: blank space, backslash, or "
383                             "single, double, or back quotes."));
384                         valid = 0;
385                 }
386
387                 if (strlen(capstring) == 0) {
388                         inform(a->c, _("A capacity must be specified."));
389                         valid = 0;
390                 }
391
392                 if (!string_to_capacity(capstring, &capacity)) {
393                         inform(a->c, _("Capacity must be either a '*' symbol to indicate "
394                             "'use the rest of the primary partition', or it "
395                             "must be a series of decimal digits ending with a "
396                             "'M' (indicating megabytes) or a 'G' (indicating "
397                             "gigabytes.)"));
398                         valid = 0;
399                 }
400
401                 if ((strcasecmp(mountpoint, "swap") == 0) && (capacity > 8192)) {
402                         inform(a->c, _("Swap capacity is limited to 8G."));
403                         valid = 0;
404                 }
405
406                 /*
407                  * If we made it through that obstacle course, all is well.
408                  */
409
410                 if (valid)
411                         aura_dict_store(d, mountpoint, strlen(mountpoint) + 1, "", 1);
412         }
413
414         if (!found_root) {
415                 inform(a->c, _("You must include a / (root) subpartition."));
416                 valid = 0;
417         }
418
419         if (aura_dict_size(d) > 16) {
420                 inform(a->c, _("You cannot have more than 16 subpartitions "
421                     "on a single primary partition.  Remove some "
422                     "and try again."));
423                 valid = 0;
424         }
425
426         aura_dict_free(d);
427
428         return(valid);
429 }
430
431 static void
432 save_subpartition_selections(struct dfui_response *r, struct i_fn_args *a)
433 {
434         struct dfui_dataset *ds;
435         const char *mountpoint, *capstring;
436         long capacity;
437         int valid = 1;
438
439         subpartitions_free(storage_get_selected_slice(a->s));
440
441         for (ds = dfui_response_dataset_get_first(r); valid && ds != NULL;
442             ds = dfui_dataset_get_next(ds)) {
443                 mountpoint = dfui_dataset_get_value(ds, "mountpoint");
444                 capstring = dfui_dataset_get_value(ds, "capacity");
445
446                 if (string_to_capacity(capstring, &capacity)) {
447                         subpartition_new_hammer(storage_get_selected_slice(a->s),
448                              mountpoint, capacity);
449                 }
450         }
451 }
452
453 static void
454 populate_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a)
455 {
456         struct subpartition *sp;
457         struct dfui_dataset *ds;
458         int i;
459         long capacity;
460
461         if (slice_subpartition_first(storage_get_selected_slice(a->s)) != NULL) {
462                 /*
463                  * The user has already given us their subpartition
464                  * preferences, so use them here.
465                  */
466                 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
467                      sp != NULL; sp = subpartition_next(sp)) {
468                         ds = dfui_dataset_new();
469                         dfui_dataset_celldata_add(ds, "mountpoint",
470                             subpartition_get_mountpoint(sp));
471                         dfui_dataset_celldata_add(ds, "capacity",
472                             capacity_to_string(subpartition_get_capacity(sp)));
473                         dfui_form_dataset_add(f, ds);
474                 }
475         } else {
476                 /*
477                  * Otherwise, populate the form with datasets representing
478                  * reasonably-calculated defaults.  The defaults are chosen
479                  * based on the slice's total capacity and the machine's
480                  * total physical memory (for swap.)
481                  */
482                 for (i = 0; def_mountpt[i] != NULL; i++) {
483                         capacity = default_capacity(a->s, def_mountpt[i]);
484                         ds = dfui_dataset_new();
485                         dfui_dataset_celldata_add(ds, "mountpoint",
486                             def_mountpt[i]);
487                         dfui_dataset_celldata_add(ds, "capacity",
488                             capacity_to_string(capacity));
489                         dfui_form_dataset_add(f, ds);
490                 }
491         }
492 }
493
494 static int
495 warn_subpartition_selections(struct i_fn_args *a)
496 {
497         int valid = 0;
498
499         if (subpartition_find(storage_get_selected_slice(a->s), "/boot") == NULL) {
500                 inform(a->c, _("The /boot partition must not be omitted."));
501         } else if (subpartition_find(storage_get_selected_slice(a->s), "/home") != NULL ||
502             subpartition_find(storage_get_selected_slice(a->s), "/tmp") != NULL ||
503             subpartition_find(storage_get_selected_slice(a->s), "/usr") != NULL ||
504             subpartition_find(storage_get_selected_slice(a->s), "/usr/obj") != NULL ||
505             subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL ||
506             subpartition_find(storage_get_selected_slice(a->s), "/var/crash") != NULL ||
507             subpartition_find(storage_get_selected_slice(a->s), "/var/tmp") != NULL) {
508                 inform(a->c, _("Pseudo filesystems will automatically be created "
509                         "for /home, /tmp, /usr, /usr/obj, /var, /var/crash "
510                         "and /var/tmp and must not be specified."));
511         } else {
512                 valid = check_capacity(a);
513         }
514
515         return(!valid);
516 }
517
518 static struct dfui_form *
519 make_create_subpartitions_form(struct i_fn_args *a)
520 {
521         struct dfui_form *f;
522         char msg_buf[1][1024];
523
524         snprintf(msg_buf[0], sizeof(msg_buf[0]),
525             _("Subpartitions further divide a primary partition for "
526             "use with %s.  Some reasons you may want "
527             "a set of subpartitions are:\n\n"
528             "- you want to restrict how much data can be written "
529             "to certain parts of the primary partition, to quell "
530             "denial-of-service attacks; and\n"
531             "- you want to speed up access to data on the disk."
532             ""), OPERATING_SYSTEM_NAME);
533
534         f = dfui_form_create(
535             "create_subpartitions",
536             _("Create Subpartitions"),
537             _("Set up the subpartitions (also known as just `partitions' "
538             "in BSD tradition) you want to have on this primary "
539             "partition. In most cases you should be fine with "
540             "the default settings.\n\n"
541             "For Capacity, use 'M' to indicate megabytes, 'G' to "
542             "indicate gigabytes, or a single '*' to indicate "
543             "'use the remaining space on the primary partition'."),
544
545             msg_buf[0],
546
547             "p", "special", "dfinstaller_create_subpartitions",
548             "p", "minimum_width","64",
549
550             "f", "mountpoint", _("Mountpoint"), "", "",
551             "f", "capacity", _("Capacity"), "", "",
552
553             "a", "ok", _("Accept and Create"), "", "",
554             "a", "cancel",
555             (disk_get_formatted(storage_get_selected_disk(a->s)) ?
556             _("Return to Select Disk") :
557             _("Return to Select Primary Partition")), "", "",
558             "p", "accelerator", "ESC",
559
560             NULL
561         );
562
563         dfui_form_set_multiple(f, 1);
564         dfui_form_set_extensible(f, 1);
565         /*
566          * Remove ATM until HAMMER installer support is better
567          * dfui_form_set_extensible(f, 1);
568          */
569 #if 0
570         if (expert) {
571                 fi = dfui_form_field_add(f, "softupdates",
572                     dfui_info_new(_("Softupdates"), "", ""));
573                 dfui_field_property_set(fi, "control", "checkbox");
574
575                 fi = dfui_form_field_add(f, "tmpfsbacked",
576                     dfui_info_new(_("TMPFS"), "", ""));
577                 dfui_field_property_set(fi, "control", "checkbox");
578
579                 fi = dfui_form_field_add(f, "fsize",
580                     dfui_info_new(_("Frag Sz"), "", ""));
581
582                 fi = dfui_form_field_add(f, "bsize",
583                     dfui_info_new(_("Block Sz"), "", ""));
584
585                 dfui_form_action_add(f, "switch",
586                     dfui_info_new(_("Switch to Normal Mode"), "", ""));
587         } else {
588                 dfui_form_action_add(f, "switch",
589                     dfui_info_new(_("Switch to Expert Mode"), "", ""));
590         }
591 #endif
592         return(f);
593 }
594
595 /*
596  * Returns:
597  *      -1 = the form should be redisplayed
598  *       0 = failure, function is over
599  *       1 = success, function is over
600  */
601 static int
602 show_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a)
603 {
604         struct dfui_dataset *ds;
605         struct dfui_response *r;
606
607         for (;;) {
608                 if (dfui_form_dataset_get_first(f) == NULL)
609                         populate_create_subpartitions_form(f, a);
610
611                 if (!dfui_be_present(a->c, f, &r))
612                         abort_backend();
613
614                 if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
615                         dfui_response_free(r);
616                         return(0);
617                 } else if (strcmp(dfui_response_get_action_id(r), "switch") == 0) {
618                         if (check_subpartition_selections(r, a)) {
619                                 save_subpartition_selections(r, a);
620                                 expert = expert ? 0 : 1;
621                                 dfui_response_free(r);
622                                 return(-1);
623                         }
624                 } else {
625                         if (check_subpartition_selections(r, a)) {
626                                 save_subpartition_selections(r, a);
627                                 if (!warn_subpartition_selections(a)) {
628                                         if (!create_subpartitions(a)) {
629                                                 inform(a->c, _("The subpartitions you chose were "
630                                                         "not correctly created, and the "
631                                                         "primary partition may "
632                                                         "now be in an inconsistent state. "
633                                                         "We recommend re-formatting it "
634                                                         "before proceeding."));
635                                                 dfui_response_free(r);
636                                                 return(0);
637                                         } else {
638                                                 dfui_response_free(r);
639                                                 return(1);
640                                         }
641                                 }
642                         }
643                 }
644
645                 dfui_form_datasets_free(f);
646                 /* dfui_form_datasets_add_from_response(f, r); */
647                 for (ds = dfui_response_dataset_get_first(r); ds != NULL;
648                     ds = dfui_dataset_get_next(ds)) {
649                         dfui_form_dataset_add(f, dfui_dataset_dup(ds));
650                 }
651         }
652 }
653
654 /*
655  * fn_create_subpartitions_hammer: let the user specify what subpartitions they
656  * want on the disk, how large each should be, and where it should be mounted.
657  */
658 void
659 fn_create_subpartitions_hammer(struct i_fn_args *a)
660 {
661         struct dfui_form *f;
662         int done = 0;
663
664         a->result = 0;
665         while (!done) {
666                 f = make_create_subpartitions_form(a);
667                 switch (show_create_subpartitions_form(f, a)) {
668                 case -1:
669                         done = 0;
670                         break;
671                 case 0:
672                         done = 1;
673                         a->result = 0;
674                         break;
675                 case 1:
676                         done = 1;
677                         a->result = 1;
678                         break;
679                 }
680                 dfui_form_free(f);
681         }
682 }