Skip to content

fdisk: add support for partition resizing#2570

Merged
karelzak merged 1 commit into
util-linux:masterfrom
t-8ch:fdisk/resize
Dec 11, 2023
Merged

fdisk: add support for partition resizing#2570
karelzak merged 1 commit into
util-linux:masterfrom
t-8ch:fdisk/resize

Conversation

@t-8ch

@t-8ch t-8ch commented Nov 3, 2023

Copy link
Copy Markdown
Member

Fixes #2555

Comment thread disk-utils/fdisk-menu.c
MENU_ENT ('t', N_("change a partition type")),
MENU_BENT_E('v', N_("verify the partition table"), FDISK_DISKLABEL_BSD),
MENU_ENT ('i', N_("print information about a partition")),
MENU_ENT ('e', N_("resize a partition")),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better ideas for the menu character are very welcome.
'r' is already used unfortunately.

Comment thread disk-utils/fdisk.c Outdated
@karelzak

karelzak commented Nov 7, 2023

Copy link
Copy Markdown
Collaborator

I'm unsure if fdisk_ask_number() is the right way to request the new size. The cfdisk has a private function that uses parses_size(), so you can specify the new size as 10GiB. I guess we need to improve the dialog for fdisk, too. Possible solutions:

  • implement fdisk.c-specific dialog based on get_user_reply() and parse_size()
  • don't ask for a new size, but ask for a new 'Last sector' relative to the partition start (+100M to set 100MiB partition), see, for example, https://github.com/util-linux/util-linux/blob/master/libfdisk/src/gpt.c#L2551 -- this solution is probably the most "fdisk-like", but maybe overkill in this case
  • introduce a new fdisk_ask_size() as an extension to FDISK_ASKTYPE_NUMBER; just add fdisk_ask_number_enable_size() and in the dialog backed (in disk-utils/fdisk.c:ask_number()) check for fdisk_ask_number_is_size() to call parse_size().

@t-8ch

t-8ch commented Nov 7, 2023

Copy link
Copy Markdown
Member Author

introduce a new fdisk_ask_size()

I like this the most, thanks for the suggestion!

Comment thread disk-utils/fdisk.c Outdated
Comment thread disk-utils/fdisk.c
Comment thread disk-utils/fdisk.c Outdated

fdisk_partition_size_explicit(npa, 1);

rc = strtosize_sectors(response, fdisk_get_sector_size(cxt), &size);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (rc)
  goto err;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be nice to check if the result from the user is in the valid range size > 0 && size <= max_size

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And probably also provide any feedback for the user, "Could not resize partition" seems not enough :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size can't be negative because it's unsigned.

Fixes util-linux#2555
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
@karelzak karelzak merged commit 24efda9 into util-linux:master Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fdisk: resize partitions

2 participants