53 lines
1.5 KiB
Diff
53 lines
1.5 KiB
Diff
From c6c56f6510257a04013f24d63ba6755cadb176bd Mon Sep 17 00:00:00 2001
|
|
From: linyan <linyanly.lin@huawei.com>
|
|
Date: Fri, 25 Jan 2019 16:13:20 +0000
|
|
Subject: [PATCH] Add extra judgment for a partition created success and solve
|
|
the problem that parted races with systemd-udevd.
|
|
|
|
---
|
|
libparted/arch/linux.c | 21 +++++++++++++++++++++
|
|
1 file changed, 21 insertions(+)
|
|
|
|
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
|
|
index ec61b11..8fda092 100644
|
|
--- a/libparted/arch/linux.c
|
|
+++ b/libparted/arch/linux.c
|
|
@@ -2530,6 +2530,25 @@ _blkpg_part_command (PedDevice* dev, struct blkpg_partition* part, int op)
|
|
return ioctl (arch_specific->fd, BLKPG, &ioctl_arg) == 0;
|
|
}
|
|
|
|
+static int _add_partition_succ(char *devname)
|
|
+{
|
|
+ int part_fd = -1;
|
|
+ int succ = 0;
|
|
+ unsigned size;
|
|
+ uint64_t bytes=0;
|
|
+
|
|
+ part_fd = open(devname, RD_MODE);
|
|
+
|
|
+ if (part_fd != -1) {
|
|
+ if(ioctl(part_fd, BLKGETSIZE64, &bytes) == 0 || ioctl (part_fd, BLKGETSIZE, &size) == 0) {
|
|
+ succ = 1;
|
|
+ }
|
|
+ close(part_fd);
|
|
+ }
|
|
+
|
|
+ return succ;
|
|
+}
|
|
+
|
|
static int
|
|
_blkpg_add_partition (PedDisk* disk, const PedPartition *part)
|
|
{
|
|
@@ -2580,6 +2599,8 @@ _blkpg_add_partition (PedDisk* disk, const PedPartition *part)
|
|
|
|
if (!_blkpg_part_command (disk->dev, &linux_part,
|
|
BLKPG_ADD_PARTITION)) {
|
|
+ if (_add_partition_succ(linux_part.devname))
|
|
+ return 1;
|
|
return 0;
|
|
}
|
|
|
|
--
|
|
1.8.3.1
|
|
|