Traditionally, there was only recalculation based on disk properties.
However, since libfdisk now supports additional script headers to
modify the default alignment, we need to check return codes. This is
because users can specify nonsensical values. If we ignore the return
codes, the library will report the issue multiple times and
return an error to the application when creating a new disk label.
Old version:
>>> Script header accepted.
>>> Last LBA specified by script is out of range.
Last LBA specified by script is out of range.
Last LBA specified by script is out of range.
Failed to apply script headers, disk label not created: Numerical result out of range
Fixed version:
>>> Script header accepted.
>>> Last LBA specified by script is out of range.
Failed to apply script headers, disk label not created: Numerical result out of range.
Signed-off-by: Karel Zak <kzak@redhat.com>
unsigned int heads,
unsigned int sectors)
{
+ int rc = 0;
+
if (!cxt)
return -EINVAL;
if (heads)
else
recount_geometry(cxt);
- fdisk_reset_alignment(cxt);
+ rc = fdisk_reset_alignment(cxt);
- DBG(CXT, ul_debugobj(cxt, "override C/H/S: %u/%u/%u",
+ DBG(CXT, ul_debugobj(cxt, "override C/H/S: %u/%u/%u [rc=%d]",
(unsigned) cxt->geom.cylinders,
(unsigned) cxt->geom.heads,
- (unsigned) cxt->geom.sectors));
+ (unsigned) cxt->geom.sectors,
+ rc));
- return 0;
+ return rc;
}
/**
int fdisk_apply_user_device_properties(struct fdisk_context *cxt)
{
+ int rc;
+
if (!cxt)
return -EINVAL;
else if (cxt->user_geom.heads || cxt->user_geom.sectors)
recount_geometry(cxt);
- fdisk_reset_alignment(cxt);
+ rc = fdisk_reset_alignment(cxt);
+ if (rc)
+ return rc;
if (cxt->user_grain) {
unsigned long granularity = max(cxt->phy_sector_size, cxt->min_io_size);
if (rc)
return rc;
- fdisk_apply_user_device_properties(cxt);
- return 0;
+ return fdisk_apply_user_device_properties(cxt);
}
/*
cxt->label = lb;
DBG(CXT, ul_debugobj(cxt, "--> switching context to %s!", lb->name));
- fdisk_apply_label_device_properties(cxt);
- return 0;
+ return fdisk_apply_label_device_properties(cxt);
}
/**
} else {
/* estimate ranges for GPT */
uint64_t first, last;
+ int rc;
- count_first_last_lba(cxt, &first, &last, NULL);
+ rc = count_first_last_lba(cxt, &first, &last, NULL);
+ if (rc)
+ return rc;
if (cxt->first_lba < first)
cxt->first_lba = first;
if (cxt->last_lba > last)
*/
int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
{
- int haslabel = 0;
+ int haslabel = 0, rc;
struct fdisk_label *lb;
if (!cxt)
if (!lb->op->create)
return -ENOSYS;
- __fdisk_switch_label(cxt, lb);
+ rc = __fdisk_switch_label(cxt, lb);
+ if (rc)
+ return rc;
+
assert(cxt->label == lb);
- if (haslabel && !cxt->parent)
- fdisk_reset_device_properties(cxt);
+ if (haslabel && !cxt->parent) {
+ rc = fdisk_reset_device_properties(cxt);
+ if (rc)
+ return rc;
+ }
- DBG(CXT, ul_debugobj(cxt, "create a new %s label", lb->name));
+ DBG(CXT, ul_debugobj(cxt, "creating a new %s label", lb->name));
return lb->op->create(cxt);
}
return rc;
}
- if (fdisk_has_user_device_properties(cxt))
- fdisk_apply_user_device_properties(cxt);
+ if (fdisk_has_user_device_properties(cxt)) {
+ rc = fdisk_apply_user_device_properties(cxt);
+ if (rc)
+ return rc;
+ }
+
/* create empty label */
name = fdisk_script_get_header(dp, "label");