From 1f091b19e09a91e9c01b961878f75c21b80f9d30 Mon Sep 17 00:00:00 2001 From: mellvik Date: Sat, 19 Oct 2024 11:43:48 +0200 Subject: [PATCH] [cmd] Prevent fdisk from creating partition beyond end of medium. --- tlvccmd/disk_utils/fdisk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tlvccmd/disk_utils/fdisk.c b/tlvccmd/disk_utils/fdisk.c index a37f7f99..abc078b7 100644 --- a/tlvccmd/disk_utils/fdisk.c +++ b/tlvccmd/disk_utils/fdisk.c @@ -166,8 +166,8 @@ void add_part(void) oset = MBR + PARTITION_START + ((part - 1) * 16); printf("Total cylinders: %d\n", geometry.cylinders); - for (scyl = geometry.cylinders + 1; scyl < 0 || scyl > geometry.cylinders;) { - printf("First cylinder (%d-%d): ", 0, geometry.cylinders); + for (scyl = geometry.cylinders; scyl < 0 || scyl > geometry.cylinders-1;) { + printf("First cylinder (%d-%d): ", 0, geometry.cylinders-1); fflush(stdout); fgets(buf, 31, stdin); scyl = atoi(buf); @@ -187,8 +187,8 @@ void add_part(void) p.cyl = (scyl & 0xff); p.sys_ind = PARTITION_TYPE; - for (ecyl = geometry.cylinders + 1; ecyl < scyl || ecyl > geometry.cylinders;) { - printf("Ending cylinder (%d-%d): ", 0, geometry.cylinders); + for (ecyl = geometry.cylinders; ecyl < scyl || ecyl > geometry.cylinders-1;) { + printf("Ending cylinder (%d-%d): ", 0, geometry.cylinders-1); fflush(stdout); fgets(buf, 31, stdin); ecyl = atoi(buf);