]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/fdisk-menu.c
51ae7b5e6e912eeefeab203bd83c76ae530232b0
15 const char key
; /* command key */
16 const char *title
; /* help string */
17 unsigned int normal
: 1, /* normal mode */
18 expert
: 1, /* expert mode */
19 hidden
: 1; /* be sensitive for this key,
20 but don't print it in help */
22 enum fdisk_labeltype label
; /* only for this label */
23 int exclude
; /* all labels except these */
24 enum fdisk_labeltype parent
; /* for nested PT */
27 #define IS_MENU_SEP(e) ((e)->key == '-')
28 #define IS_MENU_HID(e) ((e)->hidden)
31 enum fdisk_labeltype label
; /* only for this label */
32 int exclude
; /* all labels except these */
34 unsigned int nonested
: 1; /* don't make this menu active in nested PT */
36 int (*callback
)(struct fdisk_context
**,
38 const struct menu_entry
*);
40 struct menu_entry entries
[]; /* NULL terminated array */
44 size_t menu_idx
; /* the current menu */
45 size_t entry_idx
; /* index with in the current menu */
48 #define MENU_CXT_EMPTY { 0, 0 }
49 #define DECLARE_MENU_CB(x) \
50 static int x(struct fdisk_context **, \
51 const struct menu *, \
52 const struct menu_entry *)
54 DECLARE_MENU_CB(gpt_menu_cb
);
55 DECLARE_MENU_CB(sun_menu_cb
);
56 DECLARE_MENU_CB(sgi_menu_cb
);
57 DECLARE_MENU_CB(geo_menu_cb
);
58 DECLARE_MENU_CB(dos_menu_cb
);
59 DECLARE_MENU_CB(bsd_menu_cb
);
60 DECLARE_MENU_CB(createlabel_menu_cb
);
61 DECLARE_MENU_CB(generic_menu_cb
);
65 * MENU_X* expert mode only
66 * MENU_B* both -- expert + normal mode
68 * *_E exclude this label
70 * *_L only for this label
74 #define MENU_SEP(t) { .title = t, .key = '-', .normal = 1 }
75 #define MENU_XSEP(t) { .title = t, .key = '-', .expert = 1 }
76 #define MENU_BSEP(t) { .title = t, .key = '-', .expert = 1, .normal = 1 }
79 #define MENU_ENT(k, t) { .title = t, .key = k, .normal = 1 }
80 #define MENU_ENT_E(k, t, l) { .title = t, .key = k, .normal = 1, .exclude = l }
81 #define MENU_ENT_L(k, t, l) { .title = t, .key = k, .normal = 1, .label = l }
83 #define MENU_XENT(k, t) { .title = t, .key = k, .expert = 1 }
84 #define MENU_XENT_H(k, t) { .title = t, .key = k, .expert = 1, .hidden = 1 }
86 #define MENU_BENT(k, t) { .title = t, .key = k, .expert = 1, .normal = 1 }
87 #define MENU_BENT_E(k, t, l) { .title = t, .key = k, .expert = 1, .normal = 1, .exclude = l }
89 #define MENU_ENT_NEST(k, t, l, p) { .title = t, .key = k, .normal = 1, .label = l, .parent = p }
90 #define MENU_BENT_NEST_H(k, t, l, p) { .title = t, .key = k, .expert = 1, .normal = 1, .label = l, .parent = p, .hidden = 1 }
93 static const struct menu menu_generic
= {
94 .callback
= generic_menu_cb
,
96 MENU_BSEP(N_("Generic")),
97 MENU_ENT ('d', N_("delete a partition")),
98 MENU_ENT ('F', N_("list free unpartitioned space")),
99 MENU_ENT ('l', N_("list known partition types")),
100 MENU_ENT ('n', N_("add a new partition")),
101 MENU_BENT ('p', N_("print the partition table")),
102 MENU_ENT ('t', N_("change a partition type")),
103 MENU_BENT_E('v', N_("verify the partition table"), FDISK_DISKLABEL_BSD
),
104 MENU_ENT ('i', N_("print information about a partition")),
106 MENU_XENT('d', N_("print the raw data of the first sector from the device")),
107 MENU_XENT('D', N_("print the raw data of the disklabel from the device")),
108 MENU_XENT('f', N_("fix partitions order")),
110 MENU_SEP(N_("Misc")),
111 MENU_BENT ('m', N_("print this menu")),
112 MENU_ENT_E('u', N_("change display/entry units"), FDISK_DISKLABEL_GPT
),
113 MENU_ENT_E('x', N_("extra functionality (experts only)"), FDISK_DISKLABEL_BSD
),
115 MENU_SEP(N_("Script")),
116 MENU_ENT ('I', N_("load disk layout from sfdisk script file")),
117 MENU_ENT ('O', N_("dump disk layout to sfdisk script file")),
119 MENU_BSEP(N_("Save & Exit")),
120 MENU_ENT_E('w', N_("write table to disk and exit"), FDISK_DISKLABEL_BSD
),
121 MENU_ENT_L('w', N_("write table to disk"), FDISK_DISKLABEL_BSD
),
122 MENU_BENT ('q', N_("quit without saving changes")),
123 MENU_XENT ('r', N_("return to main menu")),
125 MENU_ENT_NEST('r', N_("return from BSD to DOS"), FDISK_DISKLABEL_BSD
, FDISK_DISKLABEL_DOS
),
127 MENU_ENT_NEST('r', N_("return from protective/hybrid MBR to GPT"), FDISK_DISKLABEL_DOS
, FDISK_DISKLABEL_GPT
),
133 static const struct menu menu_createlabel
= {
134 .callback
= createlabel_menu_cb
,
135 .exclude
= FDISK_DISKLABEL_BSD
,
138 MENU_SEP(N_("Create a new label")),
139 MENU_ENT('g', N_("create a new empty GPT partition table")),
140 MENU_ENT('G', N_("create a new empty SGI (IRIX) partition table")),
141 MENU_ENT('o', N_("create a new empty DOS partition table")),
142 MENU_ENT('s', N_("create a new empty Sun partition table")),
144 /* backward compatibility -- be sensitive to 'g', but don't
145 * print it in the expert menu */
146 MENU_XENT_H('g', N_("create an IRIX (SGI) partition table")),
151 static const struct menu menu_geo
= {
152 .callback
= geo_menu_cb
,
153 .exclude
= FDISK_DISKLABEL_GPT
| FDISK_DISKLABEL_BSD
,
155 MENU_XSEP(N_("Geometry (for the current label)")),
156 MENU_XENT('c', N_("change number of cylinders")),
157 MENU_XENT('h', N_("change number of heads")),
158 MENU_XENT('s', N_("change number of sectors/track")),
163 static const struct menu menu_gpt
= {
164 .callback
= gpt_menu_cb
,
165 .label
= FDISK_DISKLABEL_GPT
,
167 MENU_BSEP(N_("GPT")),
168 MENU_XENT('i', N_("change disk GUID")),
169 MENU_XENT('n', N_("change partition name")),
170 MENU_XENT('u', N_("change partition UUID")),
171 MENU_XENT('l', N_("change table length")),
172 MENU_BENT('M', N_("enter protective/hybrid MBR")),
175 MENU_XENT('A', N_("toggle the legacy BIOS bootable flag")),
176 MENU_XENT('B', N_("toggle the no block IO protocol flag")),
177 MENU_XENT('R', N_("toggle the required partition flag")),
178 MENU_XENT('S', N_("toggle the GUID specific bits")),
184 static const struct menu menu_sun
= {
185 .callback
= sun_menu_cb
,
186 .label
= FDISK_DISKLABEL_SUN
,
188 MENU_BSEP(N_("Sun")),
189 MENU_ENT('a', N_("toggle the read-only flag")),
190 MENU_ENT('c', N_("toggle the mountable flag")),
192 MENU_XENT('a', N_("change number of alternate cylinders")),
193 MENU_XENT('e', N_("change number of extra sectors per cylinder")),
194 MENU_XENT('i', N_("change interleave factor")),
195 MENU_XENT('o', N_("change rotation speed (rpm)")),
196 MENU_XENT('y', N_("change number of physical cylinders")),
201 static const struct menu menu_sgi
= {
202 .callback
= sgi_menu_cb
,
203 .label
= FDISK_DISKLABEL_SGI
,
206 MENU_ENT('a', N_("select bootable partition")),
207 MENU_ENT('b', N_("edit bootfile entry")),
208 MENU_ENT('c', N_("select sgi swap partition")),
209 MENU_ENT('i', N_("create SGI info")),
214 static const struct menu menu_dos
= {
215 .callback
= dos_menu_cb
,
216 .label
= FDISK_DISKLABEL_DOS
,
218 MENU_BSEP(N_("DOS (MBR)")),
219 MENU_ENT('a', N_("toggle a bootable flag")),
220 MENU_ENT('b', N_("edit nested BSD disklabel")),
221 MENU_ENT('c', N_("toggle the dos compatibility flag")),
223 MENU_XENT('b', N_("move beginning of data in a partition")),
224 MENU_XENT('i', N_("change the disk identifier")),
226 MENU_BENT_NEST_H('M', N_("return from protective/hybrid MBR to GPT"), FDISK_DISKLABEL_DOS
, FDISK_DISKLABEL_GPT
),
232 static const struct menu menu_bsd
= {
233 .callback
= bsd_menu_cb
,
234 .label
= FDISK_DISKLABEL_BSD
,
237 MENU_ENT('e', N_("edit drive data")),
238 MENU_ENT('i', N_("install bootstrap")),
239 MENU_ENT('s', N_("show complete disklabel")),
240 MENU_ENT('x', N_("link BSD partition to non-BSD partition")),
245 static const struct menu
*menus
[] = {
256 static const struct menu_entry
*next_menu_entry(
257 struct fdisk_context
*cxt
,
258 struct menu_context
*mc
)
260 struct fdisk_label
*lb
= fdisk_get_label(cxt
, NULL
);
261 struct fdisk_context
*parent
= fdisk_get_parent(cxt
);
262 unsigned int type
= 0, pr_type
= 0;
267 type
= fdisk_label_get_type(lb
);
269 pr_type
= fdisk_label_get_type(fdisk_get_label(parent
, NULL
));
271 while (mc
->menu_idx
< ARRAY_SIZE(menus
)) {
272 const struct menu
*m
= menus
[mc
->menu_idx
];
273 const struct menu_entry
*e
= &(m
->entries
[mc
->entry_idx
]);
279 /* no more entries */
280 if (e
->title
== NULL
||
281 /* menu wanted for specified labels only */
282 (m
->label
&& (!lb
|| !(m
->label
& type
))) ||
283 /* unwanted for nested PT */
284 (m
->nonested
&& parent
) ||
285 /* menu excluded for specified labels */
286 (m
->exclude
&& lb
&& (m
->exclude
& type
))) {
296 /* excluded for the current label */
297 if ((e
->exclude
&& lb
&& e
->exclude
& type
) ||
298 /* entry wanted for specified labels only */
299 (e
->label
&& (!lb
|| !(e
->label
& type
))) ||
300 /* exclude non-expert entries in expect mode */
301 (e
->expert
== 0 && fdisk_is_details(cxt
)) ||
303 (e
->parent
&& (!parent
|| pr_type
!= e
->parent
)) ||
304 /* exclude non-normal entries in normal mode */
305 (e
->normal
== 0 && !fdisk_is_details(cxt
))) {
316 /* returns @menu and menu entry for then @key */
317 static const struct menu_entry
*get_fdisk_menu_entry(
318 struct fdisk_context
*cxt
,
320 const struct menu
**menu
)
322 struct menu_context mc
= MENU_CXT_EMPTY
;
323 const struct menu_entry
*e
;
325 while ((e
= next_menu_entry(cxt
, &mc
))) {
326 if (IS_MENU_SEP(e
) || e
->key
!= key
)
330 *menu
= menus
[mc
.menu_idx
];
337 static int menu_detect_collisions(struct fdisk_context
*cxt
)
339 struct menu_context mc
= MENU_CXT_EMPTY
;
340 const struct menu_entry
*e
, *r
;
342 while ((e
= next_menu_entry(cxt
, &mc
))) {
346 r
= get_fdisk_menu_entry(cxt
, e
->key
, NULL
);
348 DBG(MENU
, ul_debug("warning: not found "
349 "entry for %c", e
->key
));
353 DBG(MENU
, ul_debug("warning: duplicate key '%c'",
355 DBG(MENU
, ul_debug(" : %s", e
->title
));
356 DBG(MENU
, ul_debug(" : %s", r
->title
));
364 static int print_fdisk_menu(struct fdisk_context
*cxt
)
366 struct menu_context mc
= MENU_CXT_EMPTY
;
367 const struct menu_entry
*e
;
369 ON_DBG(MENU
, menu_detect_collisions(cxt
));
371 if (fdisk_is_details(cxt
))
372 printf(_("\nHelp (expert commands):\n"));
374 printf(_("\nHelp:\n"));
376 while ((e
= next_menu_entry(cxt
, &mc
))) {
378 continue; /* hidden entry */
379 if (IS_MENU_SEP(e
) && (!e
->title
|| !*e
->title
))
381 else if (IS_MENU_SEP(e
)) {
382 color_scheme_enable("help-title", UL_COLOR_BOLD
);
383 printf("\n %s\n", _(e
->title
));
386 printf(" %c %s\n", e
->key
, _(e
->title
));
390 if (fdisk_get_parent(cxt
)) {
391 struct fdisk_label
*l
= fdisk_get_label(cxt
, NULL
),
392 *p
= fdisk_get_label(fdisk_get_parent(cxt
), NULL
);
394 fdisk_info(cxt
, _("You're editing nested '%s' partition table, "
395 "primary partition table is '%s'."),
396 fdisk_label_get_name(l
),
397 fdisk_label_get_name(p
));
403 /* Asks for command, verify the key and perform the command or
404 * returns the command key if no callback for the command is
407 * Note that this function might exchange the context pointer to
408 * switch to another (nested) context.
410 * Returns: <0 on error
411 * 0 on success (the command performed)
412 * >0 if no callback (then returns the key)
414 int process_fdisk_menu(struct fdisk_context
**cxt0
)
416 struct fdisk_context
*cxt
= *cxt0
;
417 const struct menu_entry
*ent
;
418 const struct menu
*menu
;
421 char buf
[BUFSIZ
] = { '\0' };
423 if (fdisk_is_details(cxt
))
424 prompt
= _("Expert command (m for help): ");
426 prompt
= _("Command (m for help): ");
429 rc
= get_user_reply(prompt
, buf
, sizeof(buf
));
431 if (rc
== -ECANCELED
) {
432 /* Map ^C and ^D in main menu to 'q' */
434 && fdisk_label_is_changed(fdisk_get_label(cxt
, NULL
))) {
436 _("\nAll unwritten changes will be lost, do you really want to quit? "),
438 if (rc
|| !rpmatch(buf
))
447 ent
= get_fdisk_menu_entry(cxt
, key
, &menu
);
449 fdisk_warnx(cxt
, _("%c: unknown command"), key
);
453 DBG(MENU
, ul_debug("selected: key=%c, entry='%s'",
456 /* menu has implemented callback, use it */
458 rc
= menu
->callback(cxt0
, menu
, ent
);
460 DBG(MENU
, ul_debug("no callback for key '%c'", key
));
464 DBG(MENU
, ul_debug("process menu done [rc=%d]", rc
));
468 static int script_read(struct fdisk_context
*cxt
)
470 struct fdisk_script
*sc
= NULL
;
471 char *filename
= NULL
;
474 rc
= fdisk_ask_string(cxt
, _("Enter script file name"), &filename
);
479 sc
= fdisk_new_script_from_file(cxt
, filename
);
481 fdisk_warn(cxt
, _("Cannot open %s"), filename
);
483 fdisk_warnx(cxt
, _("Failed to parse script file %s"), filename
);
484 else if (fdisk_apply_script(cxt
, sc
) != 0) {
485 fdisk_warnx(cxt
, _("Failed to apply script %s"), filename
);
486 fdisk_warnx(cxt
, _("Resetting fdisk!"));
487 rc
= fdisk_reassign_device(cxt
);
488 if (rc
== 0 && !fdisk_has_label(cxt
)) {
489 fdisk_info(cxt
, _("Device does not contain a recognized partition table."));
490 fdisk_create_disklabel(cxt
, NULL
);
493 fdisk_info(cxt
, _("Script successfully applied."));
495 fdisk_unref_script(sc
);
500 static int script_write(struct fdisk_context
*cxt
)
502 struct fdisk_script
*sc
= NULL
;
503 char *filename
= NULL
;
507 rc
= fdisk_ask_string(cxt
, _("Enter script file name"), &filename
);
511 sc
= fdisk_new_script(cxt
);
513 fdisk_warn(cxt
, _("Failed to allocate script handler"));
517 rc
= fdisk_script_read_context(sc
, NULL
);
519 fdisk_warnx(cxt
, _("Failed to transform disk layout into script"));
523 f
= fopen(filename
, "w");
525 fdisk_warn(cxt
, _("Cannot open %s"), filename
);
529 rc
= fdisk_script_write_file(sc
, f
);
531 fdisk_warn(cxt
, _("Failed to write script %s"), filename
);
533 fdisk_info(cxt
, _("Script successfully saved."));
537 fdisk_unref_script(sc
);
542 static int ask_for_wipe(struct fdisk_context
*cxt
, size_t partno
)
544 struct fdisk_partition
*tmp
= NULL
;
548 rc
= fdisk_get_partition(cxt
, partno
, &tmp
);
552 rc
= fdisk_partition_to_string(tmp
, cxt
, FDISK_FIELD_FSTYPE
, &fstype
);
553 if (rc
|| fstype
== NULL
)
556 fdisk_warnx(cxt
, _("Partition #%zu contains a %s signature."), partno
+ 1, fstype
);
558 if (pwipemode
== WIPEMODE_AUTO
&& isatty(STDIN_FILENO
))
559 fdisk_ask_yesno(cxt
, _("Do you want to remove the signature?"), &yes
);
560 else if (pwipemode
== WIPEMODE_ALWAYS
)
564 fdisk_info(cxt
, _("The signature will be removed by a write command."));
565 rc
= fdisk_wipe_partition(cxt
, partno
, TRUE
);
568 fdisk_unref_partition(tmp
);
574 * Basic fdisk actions
576 static int generic_menu_cb(struct fdisk_context
**cxt0
,
577 const struct menu
*menu
__attribute__((__unused__
)),
578 const struct menu_entry
*ent
)
580 struct fdisk_context
*cxt
= *cxt0
;
584 /* actions shared between expert and normal mode */
587 list_disk_geometry(cxt
);
591 if (fdisk_is_readonly(cxt
)) {
592 fdisk_warnx(cxt
, _("Device is open in read-only mode."));
595 rc
= fdisk_write_disklabel(cxt
);
597 err(EXIT_FAILURE
, _("failed to write disklabel"));
599 fdisk_info(cxt
, _("The partition table has been altered."));
600 if (fdisk_get_parent(cxt
))
601 break; /* nested PT, don't leave */
604 rc
= fdisk_reread_changes(cxt
, original_layout
);
606 rc
= fdisk_reread_partition_table(cxt
);
608 rc
= fdisk_deassign_device(cxt
, 0);
611 fdisk_unref_context(cxt
);
613 exit(rc
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
);
615 rc
= print_fdisk_menu(cxt
);
618 rc
= fdisk_verify_disklabel(cxt
);
621 rc
= print_partition_info(cxt
);
632 dump_firstsector(cxt
);
638 rc
= fdisk_reorder_partitions(cxt
);
640 fdisk_warnx(cxt
, _("Failed to fix partitions order."));
642 fdisk_info(cxt
, _("Partitions order fixed."));
645 rc
= fdisk_enable_details(cxt
, 0);
654 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
656 break; /* no partitions yet (or ENOMEM, ...) */
658 rc
= fdisk_delete_partition(cxt
, n
);
660 fdisk_warnx(cxt
, _("Could not delete partition %zu"), n
+ 1);
662 fdisk_info(cxt
, _("Partition %zu has been deleted."), n
+ 1);
671 list_partition_types(cxt
);
676 rc
= fdisk_add_partition(cxt
, NULL
, &partno
);
678 rc
= ask_for_wipe(cxt
, partno
);
682 change_partition_type(cxt
);
686 fdisk_use_cylinders(cxt
) ? "sectors" :
688 if (fdisk_use_cylinders(cxt
))
689 fdisk_info(cxt
, _("Changing display/entry units to cylinders (DEPRECATED!)."));
691 fdisk_info(cxt
, _("Changing display/entry units to sectors."));
694 fdisk_enable_details(cxt
, 1);
697 /* return from nested BSD to DOS or MBR to GPT */
698 if (fdisk_get_parent(cxt
)) {
699 *cxt0
= fdisk_get_parent(cxt
);
701 fdisk_info(cxt
, _("Leaving nested disklabel."));
702 fdisk_unref_context(cxt
);
712 * This is fdisk frontend for GPT specific libfdisk functions that
713 * are not exported by generic libfdisk API.
715 static int gpt_menu_cb(struct fdisk_context
**cxt0
,
716 const struct menu
*menu
__attribute__((__unused__
)),
717 const struct menu_entry
*ent
)
719 struct fdisk_context
*cxt
= *cxt0
;
720 struct fdisk_context
*mbr
;
721 struct fdisk_partition
*pa
= NULL
;
724 uintmax_t length
= 0;
728 assert(fdisk_is_label(cxt
, GPT
));
730 DBG(MENU
, ul_debug("enter GPT menu"));
735 return fdisk_set_disklabel_id(cxt
);
737 rc
= fdisk_ask_number(cxt
, 1, fdisk_get_npartitions(cxt
),
738 ~(uint32_t)0, _("New maximum entries"), &length
);
741 return fdisk_gpt_set_npartitions(cxt
, (uint32_t) length
);
743 mbr
= fdisk_new_nested_context(cxt
, "dos");
747 if (fdisk_is_details(cxt
))
748 fdisk_enable_details(cxt
, 1); /* keep us in expert mode */
749 fdisk_info(cxt
, _("Entering protective/hybrid MBR disklabel."));
753 /* actions where is necessary partnum */
754 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
760 pa
= fdisk_new_partition(); /* new template */
765 rc
= fdisk_ask_string(cxt
, _("New UUID (in 8-4-4-4-12 format)"), &str
);
767 rc
= fdisk_partition_set_uuid(pa
, str
);
769 rc
= fdisk_set_partition(cxt
, n
, pa
);
771 fdisk_unref_partition(pa
);
775 pa
= fdisk_new_partition(); /* new template */
780 rc
= fdisk_ask_string(cxt
, _("New name"), &str
);
782 rc
= fdisk_partition_set_name(pa
, str
);
784 rc
= fdisk_set_partition(cxt
, n
, pa
);
786 fdisk_unref_partition(pa
);
790 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_LEGACYBOOT
);
793 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_NOBLOCK
);
796 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_REQUIRED
);
799 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_GUIDSPECIFIC
);
809 * This is fdisk frontend for MBR specific libfdisk functions that
810 * are not exported by generic libfdisk API.
812 static int dos_menu_cb(struct fdisk_context
**cxt0
,
813 const struct menu
*menu
__attribute__((__unused__
)),
814 const struct menu_entry
*ent
)
816 struct fdisk_context
*cxt
= *cxt0
;
819 DBG(MENU
, ul_debug("enter DOS menu"));
826 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
828 rc
= fdisk_toggle_partition_flag(cxt
, n
, DOS_FLAG_ACTIVE
);
833 struct fdisk_context
*bsd
834 = fdisk_new_nested_context(cxt
, "bsd");
837 if (!fdisk_has_label(bsd
))
838 rc
= fdisk_create_disklabel(bsd
, "bsd");
840 fdisk_unref_context(bsd
);
843 fdisk_info(cxt
, _("Entering nested BSD disklabel."));
848 toggle_dos_compatibility_flag(cxt
);
859 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
861 rc
= fdisk_dos_move_begin(cxt
, n
);
865 rc
= fdisk_set_disklabel_id(cxt
);
868 /* return from nested MBR to GPT (backward compatibility only) */
869 if (fdisk_get_parent(cxt
)) {
870 *cxt0
= fdisk_get_parent(cxt
);
872 fdisk_info(cxt
, _("Leaving nested disklabel."));
873 fdisk_unref_context(cxt
);
880 static int sun_menu_cb(struct fdisk_context
**cxt0
,
881 const struct menu
*menu
__attribute__((__unused__
)),
882 const struct menu_entry
*ent
)
884 struct fdisk_context
*cxt
= *cxt0
;
887 DBG(MENU
, ul_debug("enter SUN menu"));
891 assert(fdisk_is_label(cxt
, SUN
));
893 DBG(MENU
, ul_debug("enter SUN menu"));
899 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
904 rc
= fdisk_toggle_partition_flag(cxt
, n
, SUN_FLAG_RONLY
);
907 rc
= fdisk_toggle_partition_flag(cxt
, n
, SUN_FLAG_UNMNT
);
916 rc
= fdisk_sun_set_alt_cyl(cxt
);
919 rc
= fdisk_sun_set_xcyl(cxt
);
922 rc
= fdisk_sun_set_ilfact(cxt
);
925 rc
= fdisk_sun_set_rspeed(cxt
);
928 rc
= fdisk_sun_set_pcylcount(cxt
);
934 static int sgi_menu_cb(struct fdisk_context
**cxt0
,
935 const struct menu
*menu
__attribute__((__unused__
)),
936 const struct menu_entry
*ent
)
938 struct fdisk_context
*cxt
= *cxt0
;
942 DBG(MENU
, ul_debug("enter SGI menu"));
946 assert(fdisk_is_label(cxt
, SGI
));
953 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
955 rc
= fdisk_toggle_partition_flag(cxt
, n
, SGI_FLAG_BOOT
);
958 fdisk_sgi_set_bootfile(cxt
);
961 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
963 rc
= fdisk_toggle_partition_flag(cxt
, n
, SGI_FLAG_SWAP
);
966 rc
= fdisk_sgi_create_info(cxt
);
974 * This is fdisk frontend for BSD specific libfdisk functions that
975 * are not exported by generic libfdisk API.
977 static int bsd_menu_cb(struct fdisk_context
**cxt0
,
978 const struct menu
*menu
__attribute__((__unused__
)),
979 const struct menu_entry
*ent
)
981 struct fdisk_context
*cxt
= *cxt0
;
986 assert(fdisk_is_label(cxt
, BSD
));
988 DBG(MENU
, ul_debug("enter BSD menu"));
992 rc
= fdisk_bsd_edit_disklabel(cxt
);
995 rc
= fdisk_bsd_write_bootstrap(cxt
);
998 org
= fdisk_is_details(cxt
);
1000 fdisk_enable_details(cxt
, 1);
1001 list_disklabel(cxt
);
1002 fdisk_enable_details(cxt
, org
);
1005 rc
= fdisk_bsd_link_partition(cxt
);
1013 * The geometry setting from this dialog is not persistent and maybe reset by
1014 * fdisk_reset_device_properties() (for example when you create a new disk
1015 * label). Note that on command line specified -C/-H/-S setting is persistent
1016 * as it's based on fdisk_save_user_geometry().
1018 static int geo_menu_cb(struct fdisk_context
**cxt0
,
1019 const struct menu
*menu
__attribute__((__unused__
)),
1020 const struct menu_entry
*ent
)
1022 struct fdisk_context
*cxt
= *cxt0
;
1023 struct fdisk_label
*lb
= fdisk_get_label(cxt
, NULL
);
1025 uintmax_t c
= 0, h
= 0, s
= 0;
1026 fdisk_sector_t mi
, ma
;
1028 DBG(MENU
, ul_debug("enter GEO menu"));
1035 lb
= fdisk_get_label(cxt
, "dos");
1039 fdisk_label_get_geomrange_cylinders(lb
, &mi
, &ma
);
1040 rc
= fdisk_ask_number(cxt
, mi
, fdisk_get_geom_cylinders(cxt
),
1041 ma
, _("Number of cylinders"), &c
);
1046 fdisk_label_get_geomrange_heads(lb
, &i
, &a
);
1047 rc
= fdisk_ask_number(cxt
, i
, fdisk_get_geom_heads(cxt
),
1048 a
, _("Number of heads"), &h
);
1052 fdisk_label_get_geomrange_sectors(lb
, &mi
, &ma
);
1053 rc
= fdisk_ask_number(cxt
, mi
, fdisk_get_geom_sectors(cxt
),
1054 ma
, _("Number of sectors"), &s
);
1059 fdisk_override_geometry(cxt
, c
, h
, s
);
1063 static int createlabel_menu_cb(struct fdisk_context
**cxt0
,
1064 const struct menu
*menu
__attribute__((__unused__
)),
1065 const struct menu_entry
*ent
)
1067 struct fdisk_context
*cxt
= *cxt0
;
1070 DBG(MENU
, ul_debug("enter Create label menu"));
1078 /* Deprecated, use 'G' in main menu, just for backward
1079 * compatibility only. */
1080 rc
= fdisk_create_disklabel(cxt
, "sgi");
1086 rc
= fdisk_create_disklabel(cxt
, "gpt");
1089 rc
= fdisk_create_disklabel(cxt
, "sgi");
1092 rc
= fdisk_create_disklabel(cxt
, "dos");
1095 rc
= fdisk_create_disklabel(cxt
, "sun");
1100 if (rc
== 0 && fdisk_get_collision(cxt
))
1101 follow_wipe_mode(cxt
);