Skip to contentSkip to conversation

sfdisk: exit with error if rereading partition table fails

PATCH Applied Victor Dodon 2 participants 3 messages Apr 21, 2016 – May 5, 2016 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sfdisk: exit with error if rereading partition table fails

Use the return value of fdisk_reread_partition_table in write_changes so that sfdisk exits with error if re-reading the partition table fails.

---
 disk-utils/sfdisk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
disk-utils/sfdisk.c +1 -1
index 15fa99c..b520c9b 100644
@@ -534,7 +534,7 @@ static int write_changes(struct sfdisk *sf)
 			rc = move_partition_data(sf, sf->partno, sf->orig_pa);
 		if (!rc) {
 			fdisk_info(sf->cxt, _("\nThe partition table has been altered."));
-			fdisk_reread_partition_table(sf->cxt);
+			rc = fdisk_reread_partition_table(sf->cxt);
 		}
 	}
 	if (!rc)
Signature · 1 line
2.8.0
maintainer
#1 lore raw
Quoted 13 lines · Victor Dodon

Use the return value of fdisk_reread_partition_table in write_changes so that sfdisk exits with error if re-reading the partition table fails.

---
 disk-utils/sfdisk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
disk-utils/sfdisk.c +0 -0
index 15fa99c..b520c9b 100644

disk-utils/sfdisk.c static int write_changes(struct sfdisk *sf) · line 537

Quoted 5 lines
disk-utils/sfdisk.c +1 -1
@@ -534,7 +534,7 @@ static int write_changes(struct sfdisk *sf)
 			rc = move_partition_data(sf, sf->partno, sf->orig_pa);
 		if (!rc) {
 			fdisk_info(sf->cxt, _("\nThe partition table has been altered."));
-			fdisk_reread_partition_table(sf->cxt);
+			rc = fdisk_reread_partition_table(sf->cxt);

Yes, the old sfdisk implementation exit with error in this case, but I'm not sure about it. The problem is that partition table is properly written to the device (but kernel don't use it). If would be nice to distinguish between this non-fatal error and another errors. Maybe we need more return codes.

0 -- success
1 -- fatal error
2 -- minor error (e.g. reread problem)

.. or so. We can also add error codes for initial re-read check, etc.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer Applied
#2 lore raw
In reply to Victor Dodon
Quoted 2 lines · Victor Dodon
 disk-utils/sfdisk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, good enough for now. Thanks.

I'm going to improve [s]fdisk return codes later.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com