clrtoeol();
}
+static int __attribute__((__noreturn__)) ui_err(int rc, const char *fmt, ...)
+ {
+ va_list ap;
+ ui_end();
+
+ va_start(ap, fmt);
+ fprintf(stderr, "%s: ", program_invocation_short_name);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": %s\n", strerror(errno));
+ va_end(ap);
+
+ exit(rc);
+}
+
static int __attribute__((__noreturn__)) ui_errx(int rc, const char *fmt, ...)
{
va_list ap;
if (!fdisk_has_label(cf->cxt) || cf->zero_start) {
rc = ui_create_label(cf);
- if (rc < 0)
- ui_errx(EXIT_FAILURE,
+ if (rc < 0) {
+ errno = -rc;
+ ui_err(EXIT_FAILURE,
_("failed to create a new disklabel"));
+ }
if (rc)
return rc;
}
rc = fdisk_reassign_device(cxt);
if (rc == 0 && !fdisk_has_label(cxt)) {
fdisk_info(cxt, _("Device does not contain a recognized partition table."));
- fdisk_create_disklabel(cxt, NULL);
+ rc = fdisk_create_disklabel(cxt, NULL);
}
} else
fdisk_info(cxt, _("Script successfully applied."));
const struct menu_entry *ent)
{
struct fdisk_context *cxt = *cxt0;
+ const char *wanted = NULL;
int rc = -EINVAL;
DBG(MENU, ul_debug("enter Create label menu"));
case 'g':
/* Deprecated, use 'G' in main menu, just for backward
* compatibility only. */
- rc = fdisk_create_disklabel(cxt, "sgi");
+ wanted = "sgi";
break;
}
} else {
switch (ent->key) {
case 'g':
- rc = fdisk_create_disklabel(cxt, "gpt");
+ wanted = "gpt";
break;
case 'G':
- rc = fdisk_create_disklabel(cxt, "sgi");
+ wanted = "sgi";
break;
case 'o':
- rc = fdisk_create_disklabel(cxt, "dos");
+ wanted = "dos";
break;
case 's':
- rc = fdisk_create_disklabel(cxt, "sun");
+ wanted = "sun";
break;
}
}
+ if (wanted) {
+ rc = fdisk_create_disklabel(cxt, wanted);
+ if (rc) {
+ errno = -rc;
+ fdisk_warn(cxt, _("Failed to create '%s' disk label"), wanted);
+ }
+ }
if (rc == 0 && fdisk_get_collision(cxt))
follow_wipe_mode(cxt);
if (!created) { /* create a new disklabel */
rc = fdisk_apply_script_headers(sf->cxt, dp);
created = !rc;
- if (rc)
- fdisk_warnx(sf->cxt, _(
- "Failed to apply script headers, "
- "disk label not created."));
+ if (rc) {
+ errno = -rc;
+ fdisk_warn(sf->cxt, _(
+ "Failed to apply script headers, disk label not created"));
+ }
if (rc == 0 && fdisk_get_collision(sf->cxt))
follow_wipe_mode(sf);