fdisk_script_set_header(dp, "label", label);
- printf(_("\nInput in the following format; absent fields get a default value.\n"
- "<start> <size> <type [uuid, hex or E,S,L,X]> <bootable [-,*]>\n"
- "Usually you only need to specify <start> and <size>\n\n"));
+ fputc('\n', stdout);
+ printf(_("Input in the following format; absent fields get a default value.\n"
+ "<start> <size> <type [uuid, hex or E,S,L,X]> <bootable [-,*]>\n"));
+ fputc('\n', stdout);
+ printf(_("If the size is specified by <number>{K,M,G,T,P,E,Z,Y} then\n"
+ "it's interpreted as size in bytes rather then in sectors.\n"));
+
+ fputc('\n', stdout);
if (!fdisk_has_label(sf->cxt))
printf(_("sfdisk is going to create a new '%s' disk label.\n"
"Use 'label: <name>' before you define a first partition\n"
rc = fdisk_script_read_line(dp, stdin, buf, sizeof(buf));
if (rc == 1) { /* end of file */
+ printf(_("Done.\n"));
rc = 0;
break;
} else if (rc < 0) {
} else if (pa) /* error, drop partition from script */
fdisk_table_remove_partition(tb, pa);
} else
- printf(_("OK\n")); /* probably added script header */
+ printf(_("\nScript header accepted.\n"));
} while (1);
return NULL;
}
-static int next_number(char **s, uint64_t *num)
+static int next_number(char **s, uint64_t *num, int *power)
{
char *end = NULL;
int rc;
if (end)
*end = '\0';
- rc = strtosize(*s, (uintmax_t *) num);
+ rc = parse_size(*s, (uintmax_t *) num, power);
if (end)
*s = ++end;
else
if (!*p)
break;
+ DBG(SCRIPT, ul_debugobj(dp, " parsing '%s'", p));
+
if (!strncasecmp(p, "start=", 6)) {
p += 6;
- rc = next_number(&p, &num);
+ rc = next_number(&p, &num, NULL);
if (!rc)
fdisk_partition_set_start(pa, num);
} else if (!strncasecmp(p, "size=", 5)) {
- p += 5;
- rc = next_number(&p, &num);
- if (!rc)
- fdisk_partition_set_size(pa, num / dp->cxt->sector_size);
+ int pow = 0;
+ p += 5;
+ rc = next_number(&p, &num, &pow);
+ if (!rc) {
+ if (pow)
+ num /= dp->cxt->sector_size;
+ fdisk_partition_set_size(pa, num);
+ }
} else if (!strncasecmp(p, "end=", 4)) {
p += 4;
- rc = next_number(&p, &num);
+ rc = next_number(&p, &num, NULL);
if (!rc)
fdisk_partition_set_end(pa, num);
if (*p == ',' || *p == ';')
fdisk_partition_start_follow_default(pa, 1);
else {
- rc = next_number(&p, &num);
+ rc = next_number(&p, &num, NULL);
if (!rc)
fdisk_partition_set_start(pa, num);
fdisk_partition_start_follow_default(pa, 0);
if (*p == ',' || *p == ';')
fdisk_partition_end_follow_default(pa, 1);
else {
- rc = next_number(&p, &num);
- if (!rc)
- fdisk_partition_set_size(pa, num / dp->cxt->sector_size);
+ int pow = 0;
+ rc = next_number(&p, &num, &pow);
+ if (!rc) {
+ if (pow)
+ num /= dp->cxt->sector_size;
+ fdisk_partition_set_size(pa, num);
+ }
fdisk_partition_end_follow_default(pa, 0);
}
break;