diff options
author | Karel Zak | 2014-07-15 12:28:16 +0200 |
---|---|---|
committer | Karel Zak | 2014-07-15 12:32:03 +0200 |
commit | bc787727d4a114d5f8926fb9c22fb11c40d1d8c0 (patch) | |
tree | 83bd407eb22b1f770cee7841ec82d8215e38f070 /libfdisk/src/context.c | |
parent | docs: fix name and URL of 2.25-rc1 (diff) | |
download | kernel-qcow2-util-linux-bc787727d4a114d5f8926fb9c22fb11c40d1d8c0.tar.gz kernel-qcow2-util-linux-bc787727d4a114d5f8926fb9c22fb11c40d1d8c0.tar.xz kernel-qcow2-util-linux-bc787727d4a114d5f8926fb9c22fb11c40d1d8c0.zip |
libfdisk: make disk sync() optional
... this allows to avoid unnecessary sync() from cfdisk.
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/context.c')
-rw-r--r-- | libfdisk/src/context.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 2e224b363..61a6ce30a 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -294,19 +294,24 @@ fail: return -errno; } -int fdisk_context_deassign_device(struct fdisk_context *cxt) +int fdisk_context_deassign_device(struct fdisk_context *cxt, int nosync) { assert(cxt); assert(cxt->dev_fd >= 0); - if (fsync(cxt->dev_fd) || close(cxt->dev_fd)) { - fdisk_warn(cxt, _("%s: close device failed"), cxt->dev_path); - return -errno; - } + if (cxt->readonly || nosync) + close(cxt->dev_fd); - fdisk_info(cxt, _("Syncing disks.")); - sync(); + else { + if (fsync(cxt->dev_fd) || close(cxt->dev_fd)) { + fdisk_warn(cxt, _("%s: close device failed"), + cxt->dev_path); + return -errno; + } + fdisk_info(cxt, _("Syncing disks.")); + sync(); + } cxt->dev_fd = -1; return 0; } |