diff options
author | Karel Zak | 2013-07-12 11:57:44 +0200 |
---|---|---|
committer | Karel Zak | 2013-09-16 16:47:08 +0200 |
commit | a57639e1f83149111e9855f3a042630117fe9736 (patch) | |
tree | 5aa12961088bbab021c3b08a72a12a8a8fd3e83a /libfdisk/src/alignment.c | |
parent | fdisk: cleanup write table code (diff) | |
download | kernel-qcow2-util-linux-a57639e1f83149111e9855f3a042630117fe9736.tar.gz kernel-qcow2-util-linux-a57639e1f83149111e9855f3a042630117fe9736.tar.xz kernel-qcow2-util-linux-a57639e1f83149111e9855f3a042630117fe9736.zip |
libfdisk: move sync() and reread PT code from fdisk to libfdisk
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/alignment.c')
-rw-r--r-- | libfdisk/src/alignment.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libfdisk/src/alignment.c b/libfdisk/src/alignment.c index 9e7d33b67..6df785a94 100644 --- a/libfdisk/src/alignment.c +++ b/libfdisk/src/alignment.c @@ -484,3 +484,35 @@ sector_t fdisk_scround(struct fdisk_context *cxt, sector_t num) sector_t un = fdisk_context_get_units_per_sector(cxt); return (num + un - 1) / un; } + +int fdisk_reread_partition_table(struct fdisk_context *cxt) +{ + int i; + struct stat statbuf; + + assert(cxt); + assert(cxt->dev_fd >= 0); + + i = fstat(cxt->dev_fd, &statbuf); + if (i == 0 && S_ISBLK(statbuf.st_mode)) { + sync(); +#ifdef BLKRRPART + fdisk_info(cxt, _("Calling ioctl() to re-read partition table.")); + i = ioctl(cxt->dev_fd, BLKRRPART); +#else + errno = ENOSYS; + i = 1; +#endif + } + + if (i) { + fdisk_warn(cxt, _("Re-reading the partition table failed.")); + fdisk_info(cxt, _( + "The kernel still uses the old table. The " + "new table will be used at the next reboot " + "or after you run partprobe(8) or kpartx(8).")); + return -errno; + } + + return 0; +} |