]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - disk-utils/fdisk-menu.c
fstrim shouldn't run inside a container
[thirdparty/util-linux.git] / disk-utils / fdisk-menu.c
index 532c57b26defba556a99c7f8246372142902139d..cd104e20be1a130c1d08ccce94b6ef64e92c92a5 100644 (file)
@@ -88,6 +88,7 @@ DECLARE_MENU_CB(generic_menu_cb);
 
 #define MENU_ENT_NEST(k, t, l, p)      { .title = t, .key = k, .normal = 1, .label = l, .parent = p }
 #define MENU_XENT_NEST(k, t, l, p)     { .title = t, .key = k, .expert = 1, .label = l, .parent = p }
+#define MENU_BENT_NEST(k, t, l, p)     { .title = t, .key = k, .expert = 1, .normal = 1, .label = l, .parent = p }
 
 /* Generic menu */
 static const struct menu menu_generic = {
@@ -150,7 +151,7 @@ static const struct menu menu_geo = {
        .callback = geo_menu_cb,
        .exclude = FDISK_DISKLABEL_GPT | FDISK_DISKLABEL_BSD,
        .entries = {
-               MENU_XSEP(N_("Geometry")),
+               MENU_XSEP(N_("Geometry (for the current label)")),
                MENU_XENT('c', N_("change number of cylinders")),
                MENU_XENT('h', N_("change number of heads")),
                MENU_XENT('s', N_("change number of sectors/track")),
@@ -162,12 +163,12 @@ static const struct menu menu_gpt = {
        .callback = gpt_menu_cb,
        .label = FDISK_DISKLABEL_GPT,
        .entries = {
-               MENU_XSEP(N_("GPT")),
+               MENU_BSEP(N_("GPT")),
                MENU_XENT('i', N_("change disk GUID")),
                MENU_XENT('n', N_("change partition name")),
                MENU_XENT('u', N_("change partition UUID")),
                MENU_XENT('l', N_("change table length")),
-               MENU_XENT('M', N_("enter protective/hybrid MBR")),
+               MENU_BENT('M', N_("enter protective/hybrid MBR")),
 
                MENU_XSEP(""),
                MENU_XENT('A', N_("toggle the legacy BIOS bootable flag")),
@@ -221,7 +222,7 @@ static const struct menu menu_dos = {
                MENU_XENT('b', N_("move beginning of data in a partition")),
                MENU_XENT('i', N_("change the disk identifier")),
 
-               MENU_XENT_NEST('M', N_("return from protective/hybrid MBR to GPT"),
+               MENU_BENT_NEST('M', N_("return from protective/hybrid MBR to GPT"),
                                        FDISK_DISKLABEL_DOS, FDISK_DISKLABEL_GPT),
                { 0, NULL }
        }
@@ -416,7 +417,7 @@ int process_fdisk_menu(struct fdisk_context **cxt0)
        const struct menu *menu;
        int key, rc;
        const char *prompt;
-       char buf[BUFSIZ];
+       char buf[BUFSIZ] = { '\0' };
 
        if (fdisk_is_details(cxt))
                prompt = _("Expert command (m for help): ");
@@ -649,8 +650,10 @@ static int generic_menu_cb(struct fdisk_context **cxt0,
        switch (ent->key) {
        case 'd':
                rc = fdisk_ask_partnum(cxt, &n, FALSE);
-               if (!rc)
-                       rc = fdisk_delete_partition(cxt, n);
+               if (rc)
+                       break; /* no partitions yet (or ENOMEM, ...) */
+
+               rc = fdisk_delete_partition(cxt, n);
                if (rc)
                        fdisk_warnx(cxt, _("Could not delete partition %zu"), n + 1);
                else
@@ -739,7 +742,8 @@ static int gpt_menu_cb(struct fdisk_context **cxt0,
                        if (!mbr)
                                return -ENOMEM;
                        *cxt0 = cxt = mbr;
-                       fdisk_enable_details(cxt, 1);   /* keep us in expert mode */
+                       if (fdisk_is_details(cxt))
+                               fdisk_enable_details(cxt, 1);   /* keep us in expert mode */
                        fdisk_info(cxt, _("Entering protective/hybrid MBR disklabel."));
                        return 0;
                }
@@ -1002,32 +1006,50 @@ static int bsd_menu_cb(struct fdisk_context **cxt0,
        return rc;
 }
 
-/* C/H/S commands */
+/* C/H/S commands
+ *
+ * The geometry setting from this dialog is not persistent and maybe reset by
+ * fdisk_reset_device_properties() (for example when you create a new disk
+ * label). Note that on command line specified -C/-H/-S setting is persistent
+ * as it's based on fdisk_save_user_geometry().
+ */
 static int geo_menu_cb(struct fdisk_context **cxt0,
                       const struct menu *menu __attribute__((__unused__)),
                       const struct menu_entry *ent)
 {
        struct fdisk_context *cxt = *cxt0;
+       struct fdisk_label *lb = fdisk_get_label(cxt, NULL);
        int rc = -EINVAL;
        uintmax_t c = 0, h = 0, s = 0;
+       fdisk_sector_t mi, ma;
 
        DBG(MENU, ul_debug("enter GEO menu"));
 
        assert(cxt);
        assert(ent);
 
+       /* default */
+       if (!lb)
+               lb = fdisk_get_label(cxt, "dos");
+
        switch (ent->key) {
        case 'c':
-               rc =  fdisk_ask_number(cxt, 1, fdisk_get_geom_cylinders(cxt),
-                               1048576, _("Number of cylinders"), &c);
+               fdisk_label_get_geomrange_cylinders(lb, &mi, &ma);
+               rc =  fdisk_ask_number(cxt, mi, fdisk_get_geom_cylinders(cxt),
+                               ma, _("Number of cylinders"), &c);
                break;
        case 'h':
-               rc =  fdisk_ask_number(cxt, 1, fdisk_get_geom_heads(cxt),
-                               256, _("Number of heads"), &h);
+       {
+               unsigned int i, a;
+               fdisk_label_get_geomrange_heads(lb, &i, &a);
+               rc =  fdisk_ask_number(cxt, i, fdisk_get_geom_heads(cxt),
+                               a, _("Number of heads"), &h);
                break;
+       }
        case 's':
-               rc =  fdisk_ask_number(cxt, 1, fdisk_get_geom_sectors(cxt),
-                               63, _("Number of sectors"), &s);
+               fdisk_label_get_geomrange_sectors(lb, &mi, &ma);
+               rc =  fdisk_ask_number(cxt, mi, fdisk_get_geom_sectors(cxt),
+                               ma, _("Number of sectors"), &s);
                break;
        }