/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
* cfdisk.c - Display or manipulate a disk partition table.
*
- * Copyright (C) 2014-2015 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2014-2023 Karel Zak <kzak@redhat.com>
* Copyright (C) 1994 Kevin E. Martin (martin@cs.unc.edu)
*
* The original cfdisk was inspired by the fdisk program
* by A. V. Le Blanc (leblanc@mcc.ac.uk.
- *
- * cfdisk is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
*/
#include <stdlib.h>
#include <stdio.h>
{ 0, NULL, NULL }
};
-/* extra partinfo in name:value pairs */
-struct cfdisk_extra {
- char *name;
- char *data;
-
- struct list_head exs;
-};
-
/* line and extra partinfo list_head */
struct cfdisk_line {
char *data; /* line data */
" ",
N_("Command Meaning"),
N_("------- -------"),
- N_(" b Toggle bootable flag of the current partition"),
+ N_(" b Toggle bootable flag of the current partition;"),
+ N_(" implemented for DOS (MBR) and SGI labels only"),
N_(" d Delete the current partition"),
N_(" h Print this screen"),
N_(" n Create new partition from free space"),
N_("Use lsblk(8) or partx(8) to see more details about the device."),
" ",
" ",
- "Copyright (C) 2014-2017 Karel Zak <kzak@redhat.com>"
+ "Copyright (C) 2014-2023 Karel Zak <kzak@redhat.com>"
};
erase();
}
case 'r': /* resize */
{
- struct fdisk_partition *npa, *next;
uint64_t size, max_size, secs;
+ struct fdisk_partition *npa;
if (fdisk_partition_is_freespace(pa) || !fdisk_partition_has_start(pa))
return -EINVAL;
- size = fdisk_partition_get_size(pa);
-
- /* is the next freespace? */
- next = fdisk_table_get_partition(cf->table, cf->lines_idx + 1);
- if (next && fdisk_partition_is_freespace(next))
- size += fdisk_partition_get_size(next);
+ rc = fdisk_partition_get_max_size(cf->cxt,
+ fdisk_partition_get_partno(pa),
+ &size);
+ if (rc)
+ return rc;
size *= fdisk_get_sector_size(cf->cxt);
max_size = size;
if (rc)
warn = _("Failed to write disklabel.");
else {
+ size_t q_idx = 0;
+
if (cf->device_is_used)
fdisk_reread_changes(cf->cxt, cf->original_layout);
else
fdisk_reread_partition_table(cf->cxt);
info = _("The partition table has been altered.");
+ if (menu_get_menuitem_by_key(cf, 'q', &q_idx))
+ ui_menu_goto(cf, q_idx);
}
cf->nwrites++;
break;
fputs(_(" -r, --read-only forced open cfdisk in read-only mode\n"), out);
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(26));
+ fprintf(out, USAGE_HELP_OPTIONS(26));
- printf(USAGE_MAN_TAIL("cfdisk(8)"));
+ fprintf(out, USAGE_MAN_TAIL("cfdisk(8)"));
exit(EXIT_SUCCESS);
}