summaryrefslogtreecommitdiffstats
path: root/disk-utils
diff options
context:
space:
mode:
authorKarel Zak2015-01-05 12:13:25 +0100
committerKarel Zak2015-01-05 12:13:25 +0100
commit7509020126b751fb54e1c212b71b2b3027179a25 (patch)
treec20faae59fb92da5de212633a287c590c813fcfb /disk-utils
parentchfn: fix compilation without libuser (diff)
downloadkernel-qcow2-util-linux-7509020126b751fb54e1c212b71b2b3027179a25.tar.gz
kernel-qcow2-util-linux-7509020126b751fb54e1c212b71b2b3027179a25.tar.xz
kernel-qcow2-util-linux-7509020126b751fb54e1c212b71b2b3027179a25.zip
cfdisk: detect too small partition sizes
References: https://github.com/karelzak/util-linux/issues/136 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils')
-rw-r--r--disk-utils/cfdisk.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 14a75c554..d376b3c1e 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -1928,16 +1928,14 @@ static int main_menu_action(struct cfdisk *cf, int key)
break;
case 'n': /* New */
{
- uint64_t start, size, dflt_size;
+ uint64_t start, size, dflt_size, secs;
struct fdisk_partition *npa; /* the new partition */
int expsize = 0; /* size specified explicitly in sectors */
if (!pa || !fdisk_partition_is_freespace(pa)
|| !fdisk_partition_has_start(pa))
return -EINVAL;
- npa = fdisk_new_partition();
- if (!npa)
- return -ENOMEM;
+
/* free space range */
start = fdisk_partition_get_start(pa);
size = dflt_size = fdisk_partition_get_size(pa) * fdisk_get_sector_size(cf->cxt);
@@ -1946,10 +1944,20 @@ static int main_menu_action(struct cfdisk *cf, int key)
== -CFDISK_ERR_ESC)
break;
+ secs = size / fdisk_get_sector_size(cf->cxt);
+ if (size && secs < 1) {
+ warn = _("Too small partition size specified.");
+ break;
+ }
+
+ npa = fdisk_new_partition();
+ if (!npa)
+ return -ENOMEM;
+
if (dflt_size == size) /* default is to fillin all free space */
fdisk_partition_end_follow_default(npa, 1);
- else /* set relative size of the partition */
- fdisk_partition_set_size(npa, size / fdisk_get_sector_size(cf->cxt));
+ else
+ fdisk_partition_set_size(npa, secs);
if (expsize)
fdisk_partition_size_explicit(pa, 1);
@@ -2040,6 +2048,7 @@ static int main_menu_action(struct cfdisk *cf, int key)
ui_draw_menu(cf);
ui_clean_hint();
+
if (warn)
ui_warnx(warn, n + 1);
else if (info)