... this allows to avoid unnecessary sync() from cfdisk.
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
size_t lines_idx; /* current line <0..N>, exclude header */
size_t page_sz;
+ unsigned int nwrites; /* fdisk_write_disklabel() counter */
+
unsigned int wrong_order :1, /* PT not in right order */
zero_start :1; /* ignore existing partition table */
};
fdisk_reread_partition_table(cf->cxt);
info = _("The partition table has been altered.");
}
+ cf->nwrites++;
break;
}
default:
free(cf->linesbuf);
fdisk_unref_table(cf->table);
- rc = fdisk_context_deassign_device(cf->cxt);
+ rc = fdisk_context_deassign_device(cf->cxt, cf->nwrites == 0);
fdisk_free_context(cf->cxt);
DBG(FRONTEND, ul_debug("bye! [rc=%d]", rc));
return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
fdisk_info(cxt, _("The partition table has been altered."));
rc = fdisk_reread_partition_table(cxt);
if (!rc)
- rc = fdisk_context_deassign_device(cxt);
+ rc = fdisk_context_deassign_device(cxt, 0);
/* fallthrough */
case 'q':
fdisk_free_context(cxt);
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;
}
extern int fdisk_context_is_readonly(struct fdisk_context *cxt);
extern int fdisk_context_assign_device(struct fdisk_context *cxt,
const char *fname, int readonly);
-extern int fdisk_context_deassign_device(struct fdisk_context *cxt);
+extern int fdisk_context_deassign_device(struct fdisk_context *cxt, int nosync);
extern struct fdisk_label *fdisk_context_get_label(struct fdisk_context *cxt,
const char *name);