Currently fdisk does not ask which partition will be deleted if there is only one partition which could be selected. This means that when using the 'd'elete function, you may or may not be prompted for the partition to delete, depending on how many partitions there are on the disk. (The same applies to the 't'ype command, and the selection of the final cylinder when there is only one cylinder available for partitioning). This is meant to aid interactive use, but in practice it causes mistakes (I've set the type of partition 1 to 1 many times). This means that manipulating the first partition of a device through fdisk is unnecessarily tricky (features are later known as bugs). I propose to remove the default selection, and explicitly prompt, except where there is nothing to do. Any comments? Is this going to break someone's favourite USB stick formatter? PROPOSED BEHAVIOUR:: Command (m for help): p Disk ./hda: 0 MB, 0 bytes 255 heads, 63 sectors/track, 256 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xe2f79aba Device Boot Start End Blocks Id System ./hda2 1 123 987966 83 Linux Command (m for help): t Partition number (1-4): 2 <============== new prompt Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap / Solaris) Command (m for help): d Partition number (1-4): 1 Warning: partition 1 has empty type Command (m for help): d Partition number (1-4): 2 <============== new prompt Command (m for help): d No partition is defined yet! CURRENT BEHAVIOUR:: Command (m for help): p Disk hda: 0 MB, 0 bytes 255 heads, 63 sectors/track, 256 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x5459a60a Device Boot Start End Blocks Id System hda2 1 123 987966 83 Linux Command (m for help): t Selected partition 2 <======= no prompt here Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap / Solaris) Command (m for help): d Selected partition 2 <======= no prompt here Command (m for help): 1 1: unknown command Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) 1-CYLINDER PARTITIONS (CURRENT BEHAVIOUR): Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 4 First cylinder (124-256, default 124): 256 <======== no prompt! Command (m for help): d Partition number (1-4): 4 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 4 First cylinder (124-256, default 124): 255 Last cylinder, +cylinders or +size{K,M,G} (255-256, default 256): 256 <=== ! PARTIAL PATCH:: (only for partition selection): diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 6b0fdfe..6bb7003 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -1382,20 +1382,12 @@ get_existing_partition(int warn, int max) { struct partition *p = pe->part_table; if (p && !is_cleared_partition(p)) { - if (pno >= 0) - goto not_unique; - pno = i; + /* If there are partitions defined, ask which */ + return get_partition(warn, max); } } - if (pno >= 0) { - printf(_("Selected partition %d\n"), pno+1); - return pno; - } printf(_("No partition is defined yet!\n")); return -1; - - not_unique: - return get_partition(warn, max); } static int -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html