diff options
| author | Karel Zak <kzak@redhat.com> | 2025-09-08 11:44:16 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2025-09-08 11:44:16 +0200 |
| commit | e873aa0322f42167a402e95dd398fcc4eb256119 (patch) | |
| tree | 5e64e8444749459d9d9fed99fc73daafcc7fbda3 /disk-utils/sfdisk.c | |
| parent | d073aab9d34eea205545c77222947691f4abf5aa (diff) | |
| download | util-linux-e873aa0322f42167a402e95dd398fcc4eb256119.tar.gz | |
libfdisk: improve collision reporting
In some cases, a collision occurs in the first sector. Creating a new
partition table overwrites this sector, but updating an existing table
does not. In the latter case, promising to wipe the collision is a
bug.
Because we cannot know whether the collision is expected (e.g., hybrid
or boot disks) or unintended, we inform the user and let them decide.
libfdisk can wipe the unwanted signature only when creating a new
partition table; otherwise, the user can use wipefs.
This commit introduces fdisk_is_collision_area(), an API to detect
where the collision occurs. The function is generic and not limited to
the first sector.
Fixes: https://github.com/util-linux/util-linux/issues/3659
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
| -rw-r--r-- | disk-utils/sfdisk.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index b754916efd..b691cb0846 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -1737,22 +1737,32 @@ static void follow_wipe_mode(struct sfdisk *sf) if (sf->quiet) return; - if (dowipe) { - if (!fdisk_is_ptcollision(sf->cxt)) { - fdisk_warnx(sf->cxt, _( - "The device contains '%s' signature and it may be removed by a write command. " - "See sfdisk(8) man page and --wipe option for more details."), - fdisk_get_collision(sf->cxt)); - fputc('\n', stdout); - } - } else { + if (!dowipe) { fdisk_warnx(sf->cxt, _( "The device contains '%s' signature and it may remain on the device. " "It is recommended to wipe the device with wipefs(8) or " "sfdisk --wipe, in order to avoid possible collisions."), fdisk_get_collision(sf->cxt)); fputc('\n', stderr); + return; } + + if (fdisk_is_ptcollision(sf->cxt)) + return; /* PT will be replaced */ + + if (sf->append && fdisk_has_label(sf->cxt) + && fdisk_is_collision_area(sf->cxt, 0, fdisk_get_sector_size(sf->cxt))) + fdisk_warnx(sf->cxt, _( + "The device contains a '%s' signature in the first sector; it will not be wiped " + "unless you create a new partition table. Alternatively, use wipefs(8)."), + fdisk_get_collision(sf->cxt)); + else + fdisk_warnx(sf->cxt, _( + "The device contains '%s' signature and it may be removed by a write command. " + "See sfdisk(8) man page and --wipe option for more details."), + fdisk_get_collision(sf->cxt)); + + fputc('\n', stdout); } static int wipe_partition(struct sfdisk *sf, size_t partno) |
