static void new_partition(struct fdisk_context *cxt)
{
- if (warn_geometry(cxt))
- return;
-
- if (disklabel == SUN_LABEL) {
- add_sun_partition(cxt, get_partition(cxt, 0, partitions), LINUX_NATIVE);
- return;
- }
+ int partnum = 0;
- if (disklabel == SGI_LABEL) {
- sgi_add_partition(cxt, get_partition(cxt, 0, partitions), LINUX_NATIVE);
- return;
- }
-
- if (disklabel == AIX_LABEL) {
- printf(_("\tSorry - this fdisk cannot handle AIX disk labels."
- "\n\tIf you want to add DOS-type partitions, create"
- "\n\ta new empty DOS partition table first. (Use o.)"
- "\n\tWARNING: "
- "This will destroy the present disk contents.\n"));
+ if (warn_geometry(cxt))
return;
- }
- if (disklabel == MAC_LABEL) {
- printf(_("\tSorry - this fdisk cannot handle Mac disk labels."
- "\n\tIf you want to add DOS-type partitions, create"
- "\n\ta new empty DOS partition table first. (Use o.)"
- "\n\tWARNING: "
- "This will destroy the present disk contents.\n"));
- return;
- }
+ if (disklabel == SUN_LABEL || disklabel == SGI_LABEL)
+ partnum = get_partition(cxt, 0, partitions);
- /* default to DOS/BSD */
- dos_new_partition(cxt);
+ /*
+ * Use default LINUX_NATIVE partition type, DOS labels
+ * may override this internally.
+ */
+ fdisk_add_partition(cxt, partnum, LINUX_NATIVE);
}
static void write_table(struct fdisk_context *cxt)
int (*probe)(struct fdisk_context *cxt);
/* write in-memory changes to disk */
int (*write)(struct fdisk_context *cxt);
+ /* new partition */
+ void (*part_add)(struct fdisk_context *cxt, int partnum, int parttype);
/* delete partition */
void (*part_delete)(struct fdisk_context *cxt, int partnum);
};
unsigned int sectors);
extern int fdisk_create_default_disklabel(struct fdisk_context *cxt);
extern int fdisk_delete_partition(struct fdisk_context *cxt, int partnum);
+extern int fdisk_add_partition(struct fdisk_context *cxt, int partnum, int parttype);
extern int fdisk_write_disklabel(struct fdisk_context *cxt);
/* prototypes for fdisk.c */
return 1;
}
+static void aix_add_partition(struct fdisk_context *cxt, int partnum, int parttype)
+{
+ printf(_("\tSorry - this fdisk cannot handle AIX disk labels."
+ "\n\tIf you want to add DOS-type partitions, create"
+ "\n\ta new empty DOS partition table first. (Use o.)"
+ "\n\tWARNING: "
+ "This will destroy the present disk contents.\n"));
+}
+
const struct fdisk_label aix_label =
{
.name = "aix",
.probe = aix_probe_label,
.write = NULL,
+ .part_add = aix_add_partition,
.part_delete = NULL,
};
#include "fdiskbsdlabel.h"
static void xbsd_delete_part (struct fdisk_context *cxt, int partnum);
-static void xbsd_new_part (struct fdisk_context *cxt);
static int xbsd_create_disklabel (struct fdisk_context *cxt);
static void xbsd_edit_disklabel (void);
static void xbsd_write_bootstrap (struct fdisk_context *cxt);
return 0;
}
+static void xbsd_add_part (struct fdisk_context *cxt, int partnum, int parttype)
+{
+ unsigned int begin, end;
+ char mesg[256];
+ int i;
+
+ if (!xbsd_check_new_partition (&i))
+ return;
+
+#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__)
+ begin = get_start_sect(xbsd_part);
+ end = begin + get_nr_sects(xbsd_part) - 1;
+#else
+ begin = 0;
+ end = xbsd_dlabel.d_secperunit - 1;
+#endif
+
+ snprintf (mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
+ begin = read_int (cxt, bsd_cround (begin), bsd_cround (begin), bsd_cround (end),
+ 0, mesg);
+
+ if (display_in_cyl_units)
+ begin = (begin - 1) * xbsd_dlabel.d_secpercyl;
+
+ snprintf (mesg, sizeof(mesg), _("Last %s or +size or +sizeM or +sizeK"),
+ str_units(SINGULAR));
+ end = read_int (cxt, bsd_cround (begin), bsd_cround (end), bsd_cround (end),
+ bsd_cround (begin), mesg);
+
+ if (display_in_cyl_units)
+ end = end * xbsd_dlabel.d_secpercyl - 1;
+
+ xbsd_dlabel.d_partitions[i].p_size = end - begin + 1;
+ xbsd_dlabel.d_partitions[i].p_offset = begin;
+ xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
+}
+
void
bsd_command_prompt (struct fdisk_context *cxt)
{
xbsd_list_types ();
break;
case 'n':
- xbsd_new_part (cxt);
- break;
+ xbsd_add_part (cxt, 0, 0);
+ break;
case 'p':
xbsd_print_disklabel (cxt, 0);
break;
xbsd_dlabel.d_npartitions--;
}
-static void
-xbsd_new_part (struct fdisk_context *cxt)
-{
- unsigned int begin, end;
- char mesg[256];
- int i;
-
- if (!xbsd_check_new_partition (&i))
- return;
-
-#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__)
- begin = get_start_sect(xbsd_part);
- end = begin + get_nr_sects(xbsd_part) - 1;
-#else
- begin = 0;
- end = xbsd_dlabel.d_secperunit - 1;
-#endif
-
- snprintf (mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
- begin = read_int (cxt, bsd_cround (begin), bsd_cround (begin), bsd_cround (end),
- 0, mesg);
-
- if (display_in_cyl_units)
- begin = (begin - 1) * xbsd_dlabel.d_secpercyl;
-
- snprintf (mesg, sizeof(mesg), _("Last %s or +size or +sizeM or +sizeK"),
- str_units(SINGULAR));
- end = read_int (cxt, bsd_cround (begin), bsd_cround (end), bsd_cround (end),
- bsd_cround (begin), mesg);
-
- if (display_in_cyl_units)
- end = end * xbsd_dlabel.d_secpercyl - 1;
-
- xbsd_dlabel.d_partitions[i].p_size = end - begin + 1;
- xbsd_dlabel.d_partitions[i].p_offset = begin;
- xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
-}
-
void
xbsd_print_disklabel (struct fdisk_context *cxt, int show_all) {
struct xbsd_disklabel *lp = &xbsd_dlabel;
.name = "bsd",
.probe = osf_probe_label,
.write = xbsd_write_disklabel,
+ .part_add= xbsd_add_part,
.part_delete = xbsd_delete_part,
};
return lba;
}
-void dos_add_partition(struct fdisk_context *cxt, int n, int sys)
+static void add_partition(struct fdisk_context *cxt, int n, int sys)
{
char mesg[256]; /* 48 does not suffice in Japanese */
int i, read = 0;
partitions++;
}
printf(_("Adding logical partition %d\n"), partitions);
- dos_add_partition(cxt, partitions - 1, LINUX_NATIVE);
+ add_partition(cxt, partitions - 1, LINUX_NATIVE);
}
/*
* Ask the user for new partition type information (logical, extended).
- * This function calls the actual partition adding logic - dos_add_partition.
+ * This function calls the actual partition adding logic - add_partition.
+ *
+ * API callback.
*/
-void dos_new_partition(struct fdisk_context *cxt)
+static void dos_add_partition(struct fdisk_context *cxt, int partnum, int parttype)
{
int i, free_primary = 0;
+ /* default */
+ parttype = LINUX_NATIVE;
+
for (i = 0; i < 4; i++)
free_primary += !ptes[i].part_table->sys_ind;
} else if (partitions >= MAXIMUM_PARTS) {
printf(_("All logical partitions are in use\n"));
printf(_("Adding a primary partition\n"));
- dos_add_partition(cxt, get_partition(cxt, 0, 4), LINUX_NATIVE);
+ add_partition(cxt, get_partition(cxt, 0, 4), parttype);
} else {
char c, dflt, line[LINE_LENGTH];
if (c == 'p') {
int i = get_nonexisting_partition(cxt, 0, 4);
if (i >= 0)
- dos_add_partition(cxt, i, LINUX_NATIVE);
+ add_partition(cxt, i, parttype);
return;
} else if (c == 'l' && extended_offset) {
add_logical(cxt);
} else if (c == 'e' && !extended_offset) {
int i = get_nonexisting_partition(cxt, 0, 4);
if (i >= 0)
- dos_add_partition(cxt, i, EXTENDED);
+ add_partition(cxt, i, EXTENDED);
return;
} else
printf(_("Invalid partition type `%c'\n"), c);
.name = "dos",
.probe = dos_probe_label,
.write = dos_write_disklabel,
+ .part_add = dos_add_partition,
.part_delete = dos_delete_partition,
};
extern void dos_set_mbr_id(struct fdisk_context *cxt);
extern int is_dos_partition(int t);
extern void dos_init(struct fdisk_context *cxt);
-extern void dos_add_partition(struct fdisk_context *cxt, int n, int sys);
-extern void dos_new_partition(struct fdisk_context *cxt);
extern int mbr_is_valid_magic(unsigned char *b);
return 1;
}
+static void mac_add_partition(struct fdisk_context *cxt, int partnum, int parttype)
+{
+ printf(_("\tSorry - this fdisk cannot handle Mac disk labels."
+ "\n\tIf you want to add DOS-type partitions, create"
+ "\n\ta new empty DOS partition table first. (Use o.)"
+ "\n\tWARNING: "
+ "This will destroy the present disk contents.\n"));
+}
+
const struct fdisk_label mac_label =
{
.name = "mac",
.probe = mac_probe_label,
.write = NULL,
+ .part_add = mac_add_partition,
.part_delete = NULL,
};
sgi_set_partition(cxt, partnum, 0, 0, 0);
}
-void
-sgi_add_partition(struct fdisk_context *cxt, int n, int sys)
+static void sgi_add_partition(struct fdisk_context *cxt, int n, int sys)
{
char mesg[256];
unsigned int first=0, last=0;
.name = "sgi",
.probe = sgi_probe_label,
.write = sgi_write_disklabel,
+ .part_add = sgi_add_partition,
.part_delete = sgi_delete_partition,
};
extern unsigned int sgi_get_start_sector(struct fdisk_context *cxt, int i );
extern unsigned int sgi_get_num_sectors(struct fdisk_context *cxt, int i );
extern int sgi_get_sysid(struct fdisk_context *cxt, int i );
-extern void sgi_add_partition( struct fdisk_context *cxt, int n, int sys );
extern void create_sgilabel( struct fdisk_context *cxt );
extern void create_sgiinfo(struct fdisk_context *cxt);
extern int verify_sgi(struct fdisk_context *cxt, int verbose );
printf(_("Unused gap - sectors %d-%d\n"), start, stop);
}
-void add_sun_partition(struct fdisk_context *cxt, int n, int sys)
+static void sun_add_partition(struct fdisk_context *cxt, int n, int sys)
{
uint32_t starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS];
struct sun_partition *part = &sunlabel->partitions[n];
.name = "sun",
.probe = sun_probe_label,
.write = sun_write_disklabel,
+ .part_add = sun_add_partition,
.part_delete = sun_delete_partition,
};
extern int sun_change_sysid(struct fdisk_context *cxt, int i, uint16_t sys);
extern void sun_list_table(struct fdisk_context *cxt, int xtra);
extern void verify_sun(struct fdisk_context *cxt);
-extern void add_sun_partition(struct fdisk_context *cxt, int n, int sys);
extern void sun_set_alt_cyl(struct fdisk_context *cxt);
extern void sun_set_ncyl(struct fdisk_context *cxt, int cyl);
extern void sun_set_xcyl(struct fdisk_context *cxt);
return cxt->label->write(cxt);
}
+/*
+ * fdisk_add_partition:
+ * @cxt: fdisk context
+ * @partnum: partition number to create
+ * @parttype: partition type to create
+ *
+ * Creates a new partition, with number @partnum and type @parttype.
+ *
+ * Returns 0.
+ */
+int fdisk_add_partition(struct fdisk_context *cxt, int partnum, int parttype)
+{
+ if (!cxt)
+ return -EINVAL;
+
+ cxt->label->part_add(cxt, partnum, parttype);
+ return 0;
+}
+
/**
* fdisk_delete_partition:
* @cxt: fdisk context