blockdev-util: split out blockdev_reread_partition_table()
No functional changes, just refactoring.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <linux/blkpg.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-device.h"
|
||||
@@ -649,3 +650,23 @@ int block_device_has_partitions(sd_device *dev) {
|
||||
|
||||
return !!sd_device_enumerator_get_device_first(e);
|
||||
}
|
||||
|
||||
int blockdev_reread_partition_table(sd_device *dev) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
assert(dev);
|
||||
|
||||
/* Try to re-read the partition table. This only succeeds if none of the devices is busy. */
|
||||
|
||||
fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
if (flock(fd, LOCK_EX|LOCK_NB) < 0)
|
||||
return -errno;
|
||||
|
||||
if (ioctl(fd, BLKRRPART, 0) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user