]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/fdisk-menu.c
ce3422c6982cb5ff504e091f43ba519840ce2961
14 const char key
; /* command key */
15 const char *title
; /* help string */
16 unsigned int normal
: 1, /* normal mode */
17 expert
: 1, /* expert mode */
18 hidden
: 1; /* be sensitive for this key,
19 but don't print it in help */
21 enum fdisk_labeltype label
; /* only for this label */
22 int exclude
; /* all labels except these */
23 enum fdisk_labeltype parent
; /* for nested PT */
26 #define IS_MENU_SEP(e) ((e)->key == '-')
27 #define IS_MENU_HID(e) ((e)->hidden)
30 enum fdisk_labeltype label
; /* only for this label */
31 int exclude
; /* all labels except these */
33 unsigned int nonested
: 1; /* don't make this menu active in nested PT */
35 int (*callback
)(struct fdisk_context
**,
37 const struct menu_entry
*);
39 struct menu_entry entries
[]; /* NULL terminated array */
43 size_t menu_idx
; /* the current menu */
44 size_t entry_idx
; /* index with in the current menu */
47 #define MENU_CXT_EMPTY { 0, 0 }
48 #define DECLARE_MENU_CB(x) \
49 static int x(struct fdisk_context **, \
50 const struct menu *, \
51 const struct menu_entry *)
53 DECLARE_MENU_CB(gpt_menu_cb
);
54 DECLARE_MENU_CB(sun_menu_cb
);
55 DECLARE_MENU_CB(sgi_menu_cb
);
56 DECLARE_MENU_CB(geo_menu_cb
);
57 DECLARE_MENU_CB(dos_menu_cb
);
58 DECLARE_MENU_CB(bsd_menu_cb
);
59 DECLARE_MENU_CB(createlabel_menu_cb
);
60 DECLARE_MENU_CB(generic_menu_cb
);
64 * MENU_X* expert mode only
65 * MENU_B* both -- expert + normal mode
67 * *_E exclude this label
69 * *_L only for this label
73 #define MENU_SEP(t) { .title = t, .key = '-', .normal = 1 }
74 #define MENU_XSEP(t) { .title = t, .key = '-', .expert = 1 }
75 #define MENU_BSEP(t) { .title = t, .key = '-', .expert = 1, .normal = 1 }
78 #define MENU_ENT(k, t) { .title = t, .key = k, .normal = 1 }
79 #define MENU_ENT_E(k, t, l) { .title = t, .key = k, .normal = 1, .exclude = l }
80 #define MENU_ENT_L(k, t, l) { .title = t, .key = k, .normal = 1, .label = l }
82 #define MENU_XENT(k, t) { .title = t, .key = k, .expert = 1 }
83 #define MENU_XENT_H(k, t) { .title = t, .key = k, .expert = 1, .hidden = 1 }
85 #define MENU_BENT(k, t) { .title = t, .key = k, .expert = 1, .normal = 1 }
86 #define MENU_BENT_E(k, t, l) { .title = t, .key = k, .expert = 1, .normal = 1, .exclude = l }
88 #define MENU_ENT_NEST(k, t, l, p) { .title = t, .key = k, .normal = 1, .label = l, .parent = p }
89 #define MENU_XENT_NEST(k, t, l, p) { .title = t, .key = k, .expert = 1, .label = l, .parent = p }
92 struct menu menu_generic
= {
93 .callback
= generic_menu_cb
,
95 MENU_BSEP(N_("Generic")),
96 MENU_ENT ('d', N_("delete a partition")),
97 MENU_ENT ('F', N_("list free unpartitioned space")),
98 MENU_ENT ('l', N_("list known partition types")),
99 MENU_ENT ('n', N_("add a new partition")),
100 MENU_BENT ('p', N_("print the partition table")),
101 MENU_ENT ('t', N_("change a partition type")),
102 MENU_BENT_E('v', N_("verify the partition table"), FDISK_DISKLABEL_BSD
),
103 MENU_ENT ('i', N_("print information about a partition")),
105 MENU_XENT('d', N_("print the raw data of the first sector from the device")),
106 MENU_XENT('D', N_("print the raw data of the disklabel from the device")),
107 MENU_XENT('f', N_("fix partitions order")),
109 MENU_SEP(N_("Misc")),
110 MENU_BENT ('m', N_("print this menu")),
111 MENU_ENT_E('u', N_("change display/entry units"), FDISK_DISKLABEL_GPT
),
112 MENU_ENT_E('x', N_("extra functionality (experts only)"), FDISK_DISKLABEL_BSD
),
114 MENU_SEP(N_("Script")),
115 MENU_ENT ('I', N_("load disk layout from sfdisk script file")),
116 MENU_ENT ('O', N_("dump disk layout to sfdisk script file")),
118 MENU_BSEP(N_("Save & Exit")),
119 MENU_ENT_E('w', N_("write table to disk and exit"), FDISK_DISKLABEL_BSD
),
120 MENU_ENT_L('w', N_("write table to disk"), FDISK_DISKLABEL_BSD
),
121 MENU_BENT ('q', N_("quit without saving changes")),
122 MENU_XENT ('r', N_("return to main menu")),
124 MENU_ENT_NEST('r', N_("return from BSD to DOS"), FDISK_DISKLABEL_BSD
, FDISK_DISKLABEL_DOS
),
130 struct menu menu_createlabel
= {
131 .callback
= createlabel_menu_cb
,
132 .exclude
= FDISK_DISKLABEL_BSD
,
135 MENU_SEP(N_("Create a new label")),
136 MENU_ENT('g', N_("create a new empty GPT partition table")),
137 MENU_ENT('G', N_("create a new empty SGI (IRIX) partition table")),
138 MENU_ENT('o', N_("create a new empty DOS partition table")),
139 MENU_ENT('s', N_("create a new empty Sun partition table")),
141 /* backward compatibility -- be sensitive to 'g', but don't
142 * print it in the expert menu */
143 MENU_XENT_H('g', N_("create an IRIX (SGI) partition table")),
148 struct menu menu_geo
= {
149 .callback
= geo_menu_cb
,
150 .exclude
= FDISK_DISKLABEL_GPT
| FDISK_DISKLABEL_BSD
,
152 MENU_XSEP(N_("Geometry")),
153 MENU_XENT('c', N_("change number of cylinders")),
154 MENU_XENT('h', N_("change number of heads")),
155 MENU_XENT('s', N_("change number of sectors/track")),
160 struct menu menu_gpt
= {
161 .callback
= gpt_menu_cb
,
162 .label
= FDISK_DISKLABEL_GPT
,
164 MENU_XSEP(N_("GPT")),
165 MENU_XENT('i', N_("change disk GUID")),
166 MENU_XENT('n', N_("change partition name")),
167 MENU_XENT('u', N_("change partition UUID")),
168 MENU_XENT('l', N_("change table length")),
169 MENU_XENT('M', N_("enter protective/hybrid MBR")),
172 MENU_XENT('A', N_("toggle the legacy BIOS bootable flag")),
173 MENU_XENT('B', N_("toggle the no block IO protocol flag")),
174 MENU_XENT('R', N_("toggle the required partition flag")),
175 MENU_XENT('S', N_("toggle the GUID specific bits")),
181 struct menu menu_sun
= {
182 .callback
= sun_menu_cb
,
183 .label
= FDISK_DISKLABEL_SUN
,
185 MENU_BSEP(N_("Sun")),
186 MENU_ENT('a', N_("toggle the read-only flag")),
187 MENU_ENT('c', N_("toggle the mountable flag")),
189 MENU_XENT('a', N_("change number of alternate cylinders")),
190 MENU_XENT('e', N_("change number of extra sectors per cylinder")),
191 MENU_XENT('i', N_("change interleave factor")),
192 MENU_XENT('o', N_("change rotation speed (rpm)")),
193 MENU_XENT('y', N_("change number of physical cylinders")),
198 struct menu menu_sgi
= {
199 .callback
= sgi_menu_cb
,
200 .label
= FDISK_DISKLABEL_SGI
,
203 MENU_ENT('a', N_("select bootable partition")),
204 MENU_ENT('b', N_("edit bootfile entry")),
205 MENU_ENT('c', N_("select sgi swap partition")),
206 MENU_ENT('i', N_("create SGI info")),
211 struct menu menu_dos
= {
212 .callback
= dos_menu_cb
,
213 .label
= FDISK_DISKLABEL_DOS
,
215 MENU_BSEP(N_("DOS (MBR)")),
216 MENU_ENT('a', N_("toggle a bootable flag")),
217 MENU_ENT('b', N_("edit nested BSD disklabel")),
218 MENU_ENT('c', N_("toggle the dos compatibility flag")),
220 MENU_XENT('b', N_("move beginning of data in a partition")),
221 MENU_XENT('i', N_("change the disk identifier")),
223 MENU_XENT_NEST('M', N_("return from protective/hybrid MBR to GPT"),
224 FDISK_DISKLABEL_DOS
, FDISK_DISKLABEL_GPT
),
229 struct menu menu_bsd
= {
230 .callback
= bsd_menu_cb
,
231 .label
= FDISK_DISKLABEL_BSD
,
234 MENU_ENT('e', N_("edit drive data")),
235 MENU_ENT('i', N_("install bootstrap")),
236 MENU_ENT('s', N_("show complete disklabel")),
237 MENU_ENT('x', N_("link BSD partition to non-BSD partition")),
242 static const struct menu
*menus
[] = {
253 static const struct menu_entry
*next_menu_entry(
254 struct fdisk_context
*cxt
,
255 struct menu_context
*mc
)
257 struct fdisk_label
*lb
= fdisk_get_label(cxt
, NULL
);
258 struct fdisk_context
*parent
= fdisk_get_parent(cxt
);
259 unsigned int type
= 0, pr_type
= 0;
264 type
= fdisk_label_get_type(lb
);
266 pr_type
= fdisk_label_get_type(fdisk_get_label(parent
, NULL
));
268 while (mc
->menu_idx
< ARRAY_SIZE(menus
)) {
269 const struct menu
*m
= menus
[mc
->menu_idx
];
270 const struct menu_entry
*e
= &(m
->entries
[mc
->entry_idx
]);
276 /* no more entries */
277 if (e
->title
== NULL
||
278 /* menu wanted for specified labels only */
279 (m
->label
&& lb
&& !(m
->label
& type
)) ||
280 /* unwanted for nested PT */
281 (m
->nonested
&& parent
) ||
282 /* menu excluded for specified labels */
283 (m
->exclude
&& lb
&& (m
->exclude
& type
))) {
293 /* excluded for the current label */
294 if ((e
->exclude
&& lb
&& e
->exclude
& type
) ||
295 /* entry wanted for specified labels only */
296 (e
->label
&& lb
&& !(e
->label
& type
)) ||
297 /* exclude non-expert entries in expect mode */
298 (e
->expert
== 0 && fdisk_is_details(cxt
)) ||
300 (e
->parent
&& (!parent
|| pr_type
!= e
->parent
)) ||
301 /* exclude non-normal entries in normal mode */
302 (e
->normal
== 0 && !fdisk_is_details(cxt
))) {
313 /* returns @menu and menu entry for then @key */
314 static const struct menu_entry
*get_fdisk_menu_entry(
315 struct fdisk_context
*cxt
,
317 const struct menu
**menu
)
319 struct menu_context mc
= MENU_CXT_EMPTY
;
320 const struct menu_entry
*e
;
322 while ((e
= next_menu_entry(cxt
, &mc
))) {
323 if (IS_MENU_SEP(e
) || e
->key
!= key
)
327 *menu
= menus
[mc
.menu_idx
];
334 static int menu_detect_collisions(struct fdisk_context
*cxt
)
336 struct menu_context mc
= MENU_CXT_EMPTY
;
337 const struct menu_entry
*e
, *r
;
339 while ((e
= next_menu_entry(cxt
, &mc
))) {
343 r
= get_fdisk_menu_entry(cxt
, e
->key
, NULL
);
345 DBG(MENU
, ul_debug("warning: not found "
346 "entry for %c", e
->key
));
350 DBG(MENU
, ul_debug("warning: duplicate key '%c'",
352 DBG(MENU
, ul_debug(" : %s", e
->title
));
353 DBG(MENU
, ul_debug(" : %s", r
->title
));
361 static int print_fdisk_menu(struct fdisk_context
*cxt
)
363 struct menu_context mc
= MENU_CXT_EMPTY
;
364 const struct menu_entry
*e
;
366 ON_DBG(MENU
, menu_detect_collisions(cxt
));
368 if (fdisk_is_details(cxt
))
369 printf(_("\nHelp (expert commands):\n"));
371 printf(_("\nHelp:\n"));
373 while ((e
= next_menu_entry(cxt
, &mc
))) {
375 continue; /* hidden entry */
376 if (IS_MENU_SEP(e
) && (!e
->title
|| !*e
->title
))
378 else if (IS_MENU_SEP(e
)) {
379 color_scheme_enable("help-title", UL_COLOR_BOLD
);
380 printf("\n %s\n", _(e
->title
));
383 printf(" %c %s\n", e
->key
, _(e
->title
));
387 if (fdisk_get_parent(cxt
)) {
388 struct fdisk_label
*l
= fdisk_get_label(cxt
, NULL
),
389 *p
= fdisk_get_label(fdisk_get_parent(cxt
), NULL
);
391 fdisk_info(cxt
, _("You're editing nested '%s' partition table, "
392 "primary partition table is '%s'."),
393 fdisk_label_get_name(l
),
394 fdisk_label_get_name(p
));
400 /* Asks for command, verify the key and perform the command or
401 * returns the command key if no callback for the command is
404 * Note that this function might exchange the context pointer to
405 * switch to another (nested) context.
407 * Returns: <0 on error
408 * 0 on success (the command performed)
409 * >0 if no callback (then returns the key)
411 int process_fdisk_menu(struct fdisk_context
**cxt0
)
413 struct fdisk_context
*cxt
= *cxt0
;
414 const struct menu_entry
*ent
;
415 const struct menu
*menu
;
420 if (fdisk_is_details(cxt
))
421 prompt
= _("Expert command (m for help): ");
423 prompt
= _("Command (m for help): ");
426 rc
= get_user_reply(cxt
, prompt
, buf
, sizeof(buf
));
431 ent
= get_fdisk_menu_entry(cxt
, key
, &menu
);
433 fdisk_warnx(cxt
, _("%c: unknown command"), key
);
437 DBG(MENU
, ul_debug("selected: key=%c, entry='%s'",
440 /* menu has implemented callback, use it */
442 rc
= menu
->callback(cxt0
, menu
, ent
);
444 DBG(MENU
, ul_debug("no callback for key '%c'", key
));
448 DBG(MENU
, ul_debug("process menu done [rc=%d]", rc
));
452 static int script_read(struct fdisk_context
*cxt
)
454 struct fdisk_script
*sc
= NULL
;
455 char *filename
= NULL
;
458 rc
= fdisk_ask_string(cxt
, _("Enter script file name"), &filename
);
463 sc
= fdisk_new_script_from_file(cxt
, filename
);
465 fdisk_warn(cxt
, _("Cannot open %s"), filename
);
467 fdisk_warnx(cxt
, _("Failed to parse script file %s"), filename
);
468 else if (fdisk_apply_script(cxt
, sc
) != 0)
469 fdisk_warnx(cxt
, _("Failed to apply script %s"), filename
);
471 fdisk_info(cxt
, _("Script successfully applied."));
473 fdisk_unref_script(sc
);
478 static int script_write(struct fdisk_context
*cxt
)
480 struct fdisk_script
*sc
= NULL
;
481 char *filename
= NULL
;
485 rc
= fdisk_ask_string(cxt
, _("Enter script file name"), &filename
);
489 sc
= fdisk_new_script(cxt
);
491 fdisk_warn(cxt
, _("Failed to allocate script handler"));
495 rc
= fdisk_script_read_context(sc
, NULL
);
497 fdisk_warnx(cxt
, _("Failed to transform disk layout into script"));
501 f
= fopen(filename
, "w");
503 fdisk_warn(cxt
, _("Cannot open %s"), filename
);
507 rc
= fdisk_script_write_file(sc
, f
);
509 fdisk_warn(cxt
, _("Failed to write script %s"), filename
);
511 fdisk_info(cxt
, _("Script successfully saved."));
515 fdisk_unref_script(sc
);
520 static int ask_for_wipe(struct fdisk_context
*cxt
, size_t partno
)
522 struct fdisk_partition
*tmp
= NULL
;
526 rc
= fdisk_get_partition(cxt
, partno
, &tmp
);
530 rc
= fdisk_partition_to_string(tmp
, cxt
, FDISK_FIELD_FSTYPE
, &fstype
);
531 if (rc
|| fstype
== NULL
)
534 fdisk_warnx(cxt
, _("Partition #%zu contains a %s signature."), partno
+ 1, fstype
);
536 if (pwipemode
== WIPEMODE_AUTO
&& isatty(STDIN_FILENO
))
537 fdisk_ask_yesno(cxt
, _("Do you want to remove the signature?"), &yes
);
538 else if (pwipemode
== WIPEMODE_ALWAYS
)
542 fdisk_info(cxt
, _("The signature will be removed by a write command."));
543 rc
= fdisk_wipe_partition(cxt
, partno
, TRUE
);
546 fdisk_unref_partition(tmp
);
552 * Basic fdisk actions
554 static int generic_menu_cb(struct fdisk_context
**cxt0
,
555 const struct menu
*menu
__attribute__((__unused__
)),
556 const struct menu_entry
*ent
)
558 struct fdisk_context
*cxt
= *cxt0
;
562 /* actions shared between expert and normal mode */
565 list_disk_geometry(cxt
);
569 if (fdisk_is_readonly(cxt
)) {
570 fdisk_warnx(cxt
, _("Device is open in read-only mode."));
573 rc
= fdisk_write_disklabel(cxt
);
575 err(EXIT_FAILURE
, _("failed to write disklabel"));
576 if (fdisk_get_parent(cxt
))
577 break; /* nested PT, don't leave */
578 fdisk_info(cxt
, _("The partition table has been altered."));
579 rc
= fdisk_reread_partition_table(cxt
);
581 rc
= fdisk_deassign_device(cxt
, 0);
584 fdisk_unref_context(cxt
);
586 exit(rc
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
);
588 rc
= print_fdisk_menu(cxt
);
591 rc
= fdisk_verify_disklabel(cxt
);
594 rc
= print_partition_info(cxt
);
605 dump_firstsector(cxt
);
611 rc
= fdisk_reorder_partitions(cxt
);
613 fdisk_warnx(cxt
, _("Failed to fix partitions order."));
615 fdisk_info(cxt
, _("Partitions order fixed."));
618 rc
= fdisk_enable_details(cxt
, 0);
627 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
629 rc
= fdisk_delete_partition(cxt
, n
);
631 fdisk_warnx(cxt
, _("Could not delete partition %zu"), n
+ 1);
633 fdisk_info(cxt
, _("Partition %zu has been deleted."), n
+ 1);
642 list_partition_types(cxt
);
647 rc
= fdisk_add_partition(cxt
, NULL
, &partno
);
649 rc
= ask_for_wipe(cxt
, partno
);
653 change_partition_type(cxt
);
657 fdisk_use_cylinders(cxt
) ? "sectors" :
659 if (fdisk_use_cylinders(cxt
))
660 fdisk_info(cxt
, _("Changing display/entry units to cylinders (DEPRECATED!)."));
662 fdisk_info(cxt
, _("Changing display/entry units to sectors."));
665 fdisk_enable_details(cxt
, 1);
668 /* return from nested BSD to DOS */
669 if (fdisk_get_parent(cxt
)) {
670 *cxt0
= fdisk_get_parent(cxt
);
672 fdisk_info(cxt
, _("Leaving nested disklabel."));
673 fdisk_unref_context(cxt
);
683 * This is fdisk frontend for GPT specific libfdisk functions that
684 * are not expported by generic libfdisk API.
686 static int gpt_menu_cb(struct fdisk_context
**cxt0
,
687 const struct menu
*menu
__attribute__((__unused__
)),
688 const struct menu_entry
*ent
)
690 struct fdisk_context
*cxt
= *cxt0
;
691 struct fdisk_context
*mbr
;
692 struct fdisk_partition
*pa
= NULL
;
695 unsigned long length
;
699 assert(fdisk_is_label(cxt
, GPT
));
701 DBG(MENU
, ul_debug("enter GPT menu"));
706 return fdisk_set_disklabel_id(cxt
);
708 rc
= fdisk_ask_number(cxt
, 1, fdisk_get_npartitions(cxt
),
709 ~(uint32_t)0, _("New maximum entries"), &length
);
712 return fdisk_gpt_set_npartitions(cxt
, length
);
714 mbr
= fdisk_new_nested_context(cxt
, "dos");
718 fdisk_enable_details(cxt
, 1); /* keep us in expert mode */
719 fdisk_info(cxt
, _("Entering protective/hybrid MBR disklabel."));
723 /* actions where is necessary partnum */
724 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
730 pa
= fdisk_new_partition(); /* new template */
735 rc
= fdisk_ask_string(cxt
, _("New UUID (in 8-4-4-4-12 format)"), &str
);
737 rc
= fdisk_partition_set_uuid(pa
, str
);
739 rc
= fdisk_set_partition(cxt
, n
, pa
);
741 fdisk_unref_partition(pa
);
745 pa
= fdisk_new_partition(); /* new template */
750 rc
= fdisk_ask_string(cxt
, _("New name"), &str
);
752 rc
= fdisk_partition_set_name(pa
, str
);
754 rc
= fdisk_set_partition(cxt
, n
, pa
);
756 fdisk_unref_partition(pa
);
760 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_LEGACYBOOT
);
763 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_NOBLOCK
);
766 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_REQUIRED
);
769 rc
= fdisk_toggle_partition_flag(cxt
, n
, GPT_FLAG_GUIDSPECIFIC
);
779 * This is fdisk frontend for MBR specific libfdisk functions that
780 * are not expported by generic libfdisk API.
782 static int dos_menu_cb(struct fdisk_context
**cxt0
,
783 const struct menu
*menu
__attribute__((__unused__
)),
784 const struct menu_entry
*ent
)
786 struct fdisk_context
*cxt
= *cxt0
;
789 DBG(MENU
, ul_debug("enter DOS menu"));
796 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
798 rc
= fdisk_toggle_partition_flag(cxt
, n
, DOS_FLAG_ACTIVE
);
803 struct fdisk_context
*bsd
804 = fdisk_new_nested_context(cxt
, "bsd");
807 if (!fdisk_has_label(bsd
))
808 rc
= fdisk_create_disklabel(bsd
, "bsd");
810 fdisk_unref_context(bsd
);
813 fdisk_info(cxt
, _("Entering nested BSD disklabel."));
818 toggle_dos_compatibility_flag(cxt
);
829 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
831 rc
= fdisk_dos_move_begin(cxt
, n
);
835 rc
= fdisk_set_disklabel_id(cxt
);
838 /* return from nested MBR to GPT */
839 if (fdisk_get_parent(cxt
)) {
840 *cxt0
= fdisk_get_parent(cxt
);
842 fdisk_info(cxt
, _("Leaving nested disklabel."));
843 fdisk_unref_context(cxt
);
850 static int sun_menu_cb(struct fdisk_context
**cxt0
,
851 const struct menu
*menu
__attribute__((__unused__
)),
852 const struct menu_entry
*ent
)
854 struct fdisk_context
*cxt
= *cxt0
;
857 DBG(MENU
, ul_debug("enter SUN menu"));
861 assert(fdisk_is_label(cxt
, SUN
));
863 DBG(MENU
, ul_debug("enter SUN menu"));
869 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
874 rc
= fdisk_toggle_partition_flag(cxt
, n
, SUN_FLAG_RONLY
);
877 rc
= fdisk_toggle_partition_flag(cxt
, n
, SUN_FLAG_UNMNT
);
886 rc
= fdisk_sun_set_alt_cyl(cxt
);
889 rc
= fdisk_sun_set_xcyl(cxt
);
892 rc
= fdisk_sun_set_ilfact(cxt
);
895 rc
= fdisk_sun_set_rspeed(cxt
);
898 rc
= fdisk_sun_set_pcylcount(cxt
);
904 static int sgi_menu_cb(struct fdisk_context
**cxt0
,
905 const struct menu
*menu
__attribute__((__unused__
)),
906 const struct menu_entry
*ent
)
908 struct fdisk_context
*cxt
= *cxt0
;
912 DBG(MENU
, ul_debug("enter SGI menu"));
916 assert(fdisk_is_label(cxt
, SGI
));
923 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
925 rc
= fdisk_toggle_partition_flag(cxt
, n
, SGI_FLAG_BOOT
);
928 fdisk_sgi_set_bootfile(cxt
);
931 rc
= fdisk_ask_partnum(cxt
, &n
, FALSE
);
933 rc
= fdisk_toggle_partition_flag(cxt
, n
, SGI_FLAG_SWAP
);
936 rc
= fdisk_sgi_create_info(cxt
);
944 * This is fdisk frontend for BSD specific libfdisk functions that
945 * are not expported by generic libfdisk API.
947 static int bsd_menu_cb(struct fdisk_context
**cxt0
,
948 const struct menu
*menu
__attribute__((__unused__
)),
949 const struct menu_entry
*ent
)
951 struct fdisk_context
*cxt
= *cxt0
;
956 assert(fdisk_is_label(cxt
, BSD
));
958 DBG(MENU
, ul_debug("enter BSD menu"));
962 rc
= fdisk_bsd_edit_disklabel(cxt
);
965 rc
= fdisk_bsd_write_bootstrap(cxt
);
968 org
= fdisk_is_details(cxt
);
970 fdisk_enable_details(cxt
, 1);
972 fdisk_enable_details(cxt
, org
);
975 rc
= fdisk_bsd_link_partition(cxt
);
982 static int geo_menu_cb(struct fdisk_context
**cxt0
,
983 const struct menu
*menu
__attribute__((__unused__
)),
984 const struct menu_entry
*ent
)
986 struct fdisk_context
*cxt
= *cxt0
;
988 uintmax_t c
= 0, h
= 0, s
= 0;
990 DBG(MENU
, ul_debug("enter GEO menu"));
997 rc
= fdisk_ask_number(cxt
, 1, fdisk_get_geom_cylinders(cxt
),
998 1048576, _("Number of cylinders"), &c
);
1001 rc
= fdisk_ask_number(cxt
, 1, fdisk_get_geom_heads(cxt
),
1002 256, _("Number of heads"), &h
);
1005 rc
= fdisk_ask_number(cxt
, 1, fdisk_get_geom_sectors(cxt
),
1006 63, _("Number of sectors"), &s
);
1011 fdisk_override_geometry(cxt
, c
, h
, s
);
1015 static int createlabel_menu_cb(struct fdisk_context
**cxt0
,
1016 const struct menu
*menu
__attribute__((__unused__
)),
1017 const struct menu_entry
*ent
)
1019 struct fdisk_context
*cxt
= *cxt0
;
1022 DBG(MENU
, ul_debug("enter Create label menu"));
1030 /* Deprecated, use 'G' in main menu, just for backward
1031 * compatibility only. */
1032 rc
= fdisk_create_disklabel(cxt
, "sgi");
1040 fdisk_create_disklabel(cxt
, "gpt");
1043 fdisk_create_disklabel(cxt
, "sgi");
1046 fdisk_create_disklabel(cxt
, "dos");
1049 fdisk_create_disklabel(cxt
, "sun");