예제 #1
0
/**
 * fdisk_deassign_device:
 * @cxt: context
 * @nosync: disable fsync()
 *
 * Close device and call fsync(). If the @cxt is nested context than the
 * request is redirected to the parent.
 *
 * Returns: 0 on success, < 0 on error.
 */
int fdisk_deassign_device(struct fdisk_context *cxt, int nosync)
{
	assert(cxt);
	assert(cxt->dev_fd >= 0);

	if (cxt->parent) {
		int rc = fdisk_deassign_device(cxt->parent, nosync);

		if (!rc)
			rc = init_nested_from_parent(cxt, 0);
		return rc;
	}

	if (cxt->readonly)
		close(cxt->dev_fd);
	else {
		if (fsync(cxt->dev_fd) || close(cxt->dev_fd)) {
			fdisk_warn(cxt, _("%s: close device failed"),
					cxt->dev_path);
			return -errno;
		}

		if (!nosync) {
			fdisk_info(cxt, _("Syncing disks."));
			sync();
		}
	}

	free(cxt->dev_path);
	cxt->dev_path = NULL;

	cxt->dev_fd = -1;

	return 0;
}
예제 #2
0
int print_device_freespace(struct fdisk_context *cxt, char *device, int warnme)
{
	if (fdisk_assign_device(cxt, device, 1) != 0) {	/* read-only */
		if (warnme || errno == EACCES)
			warn(_("cannot open %s"), device);
		return -1;
	}

	list_freespace(cxt);
	fdisk_deassign_device(cxt, 1);
	return 0;
}
예제 #3
0
static int write_changes(struct sfdisk *sf)
{
	int rc = 0;

	if (sf->noact)
		fdisk_info(sf->cxt, _("The partition table is unchanged (--no-act)."));
	else {
		rc = fdisk_write_disklabel(sf->cxt);
		if (!rc) {
			fdisk_info(sf->cxt, _("\nThe partition table has been altered."));
			fdisk_reread_partition_table(sf->cxt);
		}
	}
	if (!rc)
		rc = fdisk_deassign_device(sf->cxt, sf->noact);	/* no-sync when no-act */
	return rc;
}
예제 #4
0
파일: fdisk-list.c 프로젝트: gg0/util-linux
int print_device_pt(struct fdisk_context *cxt, char *device, int warnme, int verify)
{
	if (fdisk_assign_device(cxt, device, 1) != 0) {	/* read-only */
		if (warnme || errno == EACCES)
			warn(_("cannot open %s"), device);
		return -1;
	}

	list_disk_geometry(cxt);

	if (fdisk_has_label(cxt)) {
		list_disklabel(cxt);
		if (verify)
			fdisk_verify_disklabel(cxt);
	}
	fdisk_deassign_device(cxt, 1);
	return 0;
}
예제 #5
0
static int verify_device(struct sfdisk *sf, const char *devname)
{
	int rc = 1;

	fdisk_enable_listonly(sf->cxt, 1);

	if (fdisk_assign_device(sf->cxt, devname, 1)) {
		warn(_("cannot open %s"), devname);
		return 1;
	}

	color_scheme_enable("header", UL_COLOR_BOLD);
	fdisk_info(sf->cxt, "%s:", devname);
	color_disable();

	if (!fdisk_has_label(sf->cxt))
		fdisk_info(sf->cxt, _("unrecognized partition table type"));
	else
		rc = fdisk_verify_disklabel(sf->cxt);

	fdisk_deassign_device(sf->cxt, 1);
	return rc;
}