struct fdisk_context *cxt;
struct fdisk_partition *pa;
const char *label = NULL, *device = NULL;
- int n = 0, c;
+ int n = 0, c, nopartno = 0;
unsigned int sectorsize;
+ uint64_t grain = 0;
static const struct option longopts[] = {
{ "label", required_argument, NULL, 'x' },
{ "device", required_argument, NULL, 'd' },
+ { "nopartno", no_argument, NULL, 'p' },
+ { "grain", required_argument, NULL, 'g' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 },
};
fdisk_init_debug(0);
- while((c = getopt_long(argc, argv, "x:d:h", longopts, NULL)) != -1) {
+ while((c = getopt_long(argc, argv, "g:x:d:h", longopts, NULL)) != -1) {
switch(c) {
case 'x':
label = optarg;
case 'd':
device = optarg;
break;
+ case 'p':
+ nopartno = 1;
+ break;
+ case 'g':
+ grain = strtosize_or_err(optarg, "failed to parse grain");
+ break;
case 'h':
printf("%s [options] <size> ...", program_invocation_short_name);
fputs(USAGE_SEPARATOR, stdout);
fputs(USAGE_OPTIONS, stdout);
fputs(" -x, --label <dos,gpt,...> disk label type\n", stdout);
fputs(" -d, --device <path> block device\n", stdout);
+ fputs(" -p, --nopartno don't set partno (use default)\n", stdout);
fputs(" -h, --help this help\n", stdout);
fputs(USAGE_SEPARATOR, stdout);
return EXIT_SUCCESS;
err_oom();
fdisk_set_ask(cxt, ask_callback, NULL);
+ if (grain)
+ fdisk_save_user_grain(cxt, grain);
+
pa = fdisk_new_partition();
if (!pa)
err_oom();
sectorsize = fdisk_get_sector_size(cxt);
+ fdisk_disable_dialogs(cxt, 1);
+
while (optind < argc) {
int rc;
uint64_t size;
/* defaults */
fdisk_partition_start_follow_default(pa, 1);
fdisk_partition_end_follow_default(pa, 1);
+ fdisk_partition_partno_follow_default(pa, 1);
/* set size */
if (isdigit(*str)) {
* This is possible by explicitly specified partition
* number, <4 means primary, >=4 means logical.
*/
- fdisk_partition_partno_follow_default(pa, 0);
- fdisk_partition_set_partno(pa, n);
+ if (!nopartno) {
+ fdisk_partition_partno_follow_default(pa, 0);
+ fdisk_partition_set_partno(pa, n);
+ }
/* Make sure last primary partition is extended if user
* wants more than 4 partitions.
fdisk_partition_set_type(pa, type);
fdisk_unref_parttype(type);
}
- } else
- fdisk_partition_partno_follow_default(pa, 1);
-
+ }
rc = fdisk_add_partition(cxt, pa, NULL);
if (rc) {