MENU_ENT_E('u', N_("change display/entry units"), FDISK_DISKLABEL_GPT),
MENU_ENT_E('x', N_("extra functionality (experts only)"), FDISK_DISKLABEL_BSD),
+ MENU_SEP(N_("Script")),
+ MENU_ENT ('I', N_("read disk layout from fdisk script file")),
+ MENU_ENT ('O', N_("write disk layout to fdisk script file")),
+
MENU_BSEP(N_("Save & Exit")),
MENU_ENT_E('w', N_("write table to disk and exit"), FDISK_DISKLABEL_BSD),
MENU_ENT_L('w', N_("write table to disk"), FDISK_DISKLABEL_BSD),
return rc;
}
+static int script_read(struct fdisk_context *cxt)
+{
+ struct fdisk_script *sc = NULL;
+ char *filename = NULL;
+ int rc;
+
+ rc = fdisk_ask_string(cxt, _("Enter script file name"), &filename);
+ if (rc)
+ return rc;
+
+ errno = 0;
+ sc = fdisk_new_script_from_file(cxt, filename);
+ if (!sc && errno)
+ fdisk_warn(cxt, _("Cannot open: %s"), filename);
+ else if (!sc)
+ fdisk_warnx(cxt, _("Failed to parse script file %s"), filename);
+ else if (fdisk_apply_script(cxt, sc) != 0)
+ fdisk_warnx(cxt, _("Failed to apply script %s"), filename);
+ else
+ fdisk_info(cxt, _("Script successfully applied."));
+
+ fdisk_unref_script(sc);
+ free(filename);
+ return rc;
+}
+
+static int script_write(struct fdisk_context *cxt)
+{
+ struct fdisk_script *sc = NULL;
+ char *filename = NULL;
+ FILE *f = NULL;
+ int rc;
+
+ rc = fdisk_ask_string(cxt, _("Enter script file name"), &filename);
+ if (rc)
+ return rc;
+
+ sc = fdisk_new_script(cxt);
+ if (!sc) {
+ fdisk_warn(cxt, _("Failed to allocate script handler"));
+ goto done;
+ }
+
+ rc = fdisk_script_read_context(sc, NULL);
+ if (rc) {
+ fdisk_warnx(cxt, _("Failed to read disk layout into script."));
+ goto done;
+ }
+
+ f = fopen(filename, "w");
+ if (!f) {
+ fdisk_warn(cxt, _("Cannot open: %s"), filename);
+ goto done;
+ }
+
+ rc = fdisk_script_write_file(sc, f);
+ if (rc)
+ fdisk_warn(cxt, _("Failed to write script %s"), filename);
+ else
+ fdisk_info(cxt, _("Script successfully saved."));
+done:
+ if (f)
+ fclose(f);
+ fdisk_unref_script(sc);
+ free(filename);
+ return rc;
+}
+
/*
* Basic fdisk actions
*/
else
fdisk_info(cxt, _("Partition %zu has been deleted."), n + 1);
break;
+ case 'I':
+ script_read(cxt);
+ break;
+ case 'O':
+ script_write(cxt);
+ break;
case 'l':
list_partition_types(cxt);
break;
MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB. These 10^N suffixes
are deprecated.
+.SH SCRIPT FILES
+.B fdisk
+allows to read (by 'I' command) sfdisk compatible script files. The script is
+applied to in-memory partition table, and then it is possible to modify the
+partition table before you write it to the device.
+.PP
+And vice-versa it is possible to write the current in-memory disk layout
+to the script file by command 'O'.
+.PP
+The script files are compatible between cfdisk, sfdisk, fdisk and another
+libfdisk applications. For more details see
+.BR sfdisk (8).
+
.SH DISK LABELS
.B GPT (GUID Partition Table)
.RS