Util-Linux package development
 help / color / mirror / Atom feed
From: Tianyi Chen <hi@tychen.cc>
To: util-linux@vger.kernel.org
Cc: kzak@redhat.com
Subject: [PATCH 2/3] libfdisk: limit resized DOS extended partitions to two sectors
Date: Thu, 17 Sep 2026 01:05:13 +0800	[thread overview]
Message-ID: <20260916170514.2595842-3-hi@tychen.cc> (raw)
In-Reply-To: <20260916170514.2595842-1-hi@tychen.cc>

The kernel represents a DOS extended partition with at most two 512-byte
sectors. Passing its full on-disk size to BLKPG_RESIZE_PARTITION can
therefore overlap its logical partitions and fail with EBUSY.

Apply the same size limit when resizing as when adding an extended
partition, keeping its kernel representation consistent.

Assisted-by: LLM
Signed-off-by: Tianyi Chen <hi@tychen.cc>
---
 libfdisk/src/context.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c
index f06667c6..045c3ea5 100644
--- a/libfdisk/src/context.c
+++ b/libfdisk/src/context.c
@@ -1026,10 +1026,16 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
 		}
 	}
 	for (i = 0; i < nupds; i++) {
+		uint64_t sz;
+
 		pa = upd[i];
+		sz = pa->size * ssf;
+		if (fdisk_is_label(cxt, DOS) && fdisk_partition_is_container(pa))
+			sz = min(sz, (uint64_t) 2);
+
 		DBG_OBJ(PART, pa, ul_debug("#%zu calling BLKPG_RESIZE_PARTITION", pa->partno));
 		if (partx_resize_partition(cxt->dev_fd, pa->partno + 1,
-					   pa->start * ssf, pa->size * ssf) != 0) {
+					   pa->start * ssf, sz) != 0) {
 			fdisk_warn(cxt, _("Failed to update system information about partition %zu"), pa->partno + 1);
 			err++;
 		}
-- 
2.55.0


  parent reply	other threads:[~2026-09-16 18:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 17:05 [PATCH 0/3] sfdisk: incremental kernel updates for -N and --append Tianyi Chen
2026-09-16 17:05 ` [PATCH 1/3] libfdisk: propagate errors from fdisk_reread_changes() Tianyi Chen
2026-09-16 17:05 ` Tianyi Chen [this message]
2026-09-16 17:05 ` [PATCH 3/3] sfdisk: update only changed partitions with -N and --append Tianyi Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916170514.2595842-3-hi@tychen.cc \
    --to=hi@tychen.cc \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox