/* create new disk label */
int (*create)(struct fdisk_context *cxt);
/* new partition */
- void (*part_add)(struct fdisk_context *cxt, int partnum, struct fdisk_parttype *t);
+ int (*part_add)(struct fdisk_context *cxt, int partnum, struct fdisk_parttype *t);
/* delete partition */
int (*part_delete)(struct fdisk_context *cxt, int partnum);
/* get partition type */
return 1;
}
-static void aix_add_partition(
+static int aix_add_partition(
struct fdisk_context *cxt __attribute__((__unused__)),
int partnum __attribute__((__unused__)),
struct fdisk_parttype *t __attribute__((__unused__)))
"\n\ta new empty DOS partition table first. (Use o.)"
"\n\tWARNING: "
"This will destroy the present disk contents.\n"));
+
+ return -ENOSYS;
}
const struct fdisk_label aix_label =
return 0;
}
-static void xbsd_add_part (struct fdisk_context *cxt,
+static int xbsd_add_part (struct fdisk_context *cxt,
int partnum __attribute__((__unused__)),
struct fdisk_parttype *t __attribute__((__unused__)))
{
unsigned int begin, end;
char mesg[256];
- int i;
+ int i, rc;
- if (!xbsd_check_new_partition (&i))
- return;
+ rc = xbsd_check_new_partition(&i);
+ if (rc)
+ return rc;
#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__)
begin = get_start_sect(xbsd_part);
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;
+
+ return 0;
}
static int xbsd_create_disklabel (struct fdisk_context *cxt)
if (t == BSD_MAXPARTITIONS) {
fprintf (stderr, _("The maximum number of partitions "
"has been created\n"));
- return 0;
+ return -EINVAL;
}
}
if (xbsd_dlabel.d_partitions[*i].p_size != 0) {
fprintf (stderr, _("This partition already exists.\n"));
- return 0;
+ return -EINVAL;
}
- return 1;
+ return 0;
}
static unsigned short
k = get_partition (cxt, 1, partitions);
- if (!xbsd_check_new_partition (&i))
+ if (xbsd_check_new_partition (&i))
return;
p = get_part_table(k);
return lba;
}
-static void add_partition(struct fdisk_context *cxt, int n, struct fdisk_parttype *t)
+static int add_partition(struct fdisk_context *cxt, int n, struct fdisk_parttype *t)
{
char mesg[256]; /* 48 does not suffice in Japanese */
int i, sys, read = 0;
if (p && p->sys_ind) {
printf(_("Partition %d is already defined. Delete "
"it before re-adding it.\n"), n + 1);
- return;
+ return -EINVAL;
}
fill_bounds(first, last);
if (n < 4) {
printf(_("No free sectors available\n"));
if (n > 4)
partitions--;
- return;
+ return -ENOSPC;
}
if (cround(start) == cround(limit)) {
stop = limit;
pe4->changed = 1;
partitions = 5;
}
+
+ return 0;
}
-static void add_logical(struct fdisk_context *cxt)
+static int add_logical(struct fdisk_context *cxt)
{
if (partitions > 5 || ptes[4].part_table->sys_ind) {
struct pte *pe = &ptes[partitions];
partitions++;
}
printf(_("Adding logical partition %d\n"), partitions);
- add_partition(cxt, partitions - 1, NULL);
+ return add_partition(cxt, partitions - 1, NULL);
}
static int dos_verify_disklabel(struct fdisk_context *cxt)
*
* API callback.
*/
-static void dos_add_partition(
+static int dos_add_partition(
struct fdisk_context *cxt,
int partnum __attribute__ ((__unused__)),
struct fdisk_parttype *t)
{
- int i, free_primary = 0;
+ int i, free_primary = 0, rc = 0;
for (i = 0; i < 4; i++)
free_primary += !ptes[i].part_table->sys_ind;
if (!free_primary && partitions >= MAXIMUM_PARTS) {
printf(_("The maximum number of partitions has been created\n"));
- return;
+ return -EINVAL;
}
if (!free_primary) {
if (extended_offset) {
printf(_("All primary partitions are in use\n"));
- add_logical(cxt);
+ rc = add_logical(cxt);
} else
printf(_("If you want to create more than four partitions, you must replace a\n"
"primary partition with an extended partition first.\n"));
} else if (partitions >= MAXIMUM_PARTS) {
printf(_("All logical partitions are in use\n"));
printf(_("Adding a primary partition\n"));
- add_partition(cxt, get_partition(cxt, 0, 4), t);
+ rc = add_partition(cxt, get_partition(cxt, 0, 4), t);
} else {
char c, dflt, line[LINE_LENGTH];
if (c == 'p') {
int i = get_nonexisting_partition(cxt, 0, 4);
if (i >= 0)
- add_partition(cxt, i, t);
- return;
+ rc = add_partition(cxt, i, t);
+ goto done;
} else if (c == 'l' && extended_offset) {
- add_logical(cxt);
- return;
+ rc = add_logical(cxt);
+ goto done;
} else if (c == 'e' && !extended_offset) {
int i = get_nonexisting_partition(cxt, 0, 4);
if (i >= 0) {
t = fdisk_get_parttype_from_code(cxt, EXTENDED);
- add_partition(cxt, i, t);
+ rc = add_partition(cxt, i, t);
}
- return;
+ goto done;
} else
printf(_("Invalid partition type `%c'\n"), c);
}
+done:
+ return rc;
}
static int write_sector(struct fdisk_context *cxt, sector_t secno,
return 1;
}
-static void mac_add_partition(
+static int mac_add_partition(
struct fdisk_context *cxt __attribute__ ((__unused__)),
int partnum __attribute__ ((__unused__)),
struct fdisk_parttype *t __attribute__ ((__unused__)))
"\n\ta new empty DOS partition table first. (Use o.)"
"\n\tWARNING: "
"This will destroy the present disk contents.\n"));
+
+ return -ENOSYS;
}
const struct fdisk_label mac_label =
return sgi_set_partition(cxt, partnum, 0, 0, 0);
}
-static void sgi_add_partition(struct fdisk_context *cxt, int n,
- struct fdisk_parttype *t)
+static int sgi_add_partition(struct fdisk_context *cxt, int n,
+ struct fdisk_parttype *t)
{
char mesg[256];
unsigned int first=0, last=0;
if (sgi_get_num_sectors(cxt, n)) {
printf(_("Partition %d is already defined. Delete "
"it before re-adding it.\n"), n + 1);
- return;
+ return -EINVAL;
}
if ((sgi_entire(cxt) == -1)
&& (sys != SGI_VOLUME)) {
}
if ((sgi_gaps(cxt) == 0) && (sys != SGI_VOLUME)) {
printf(_("The entire disk is already covered with partitions.\n"));
- return;
+ return -EINVAL;
}
if (sgi_gaps(cxt) < 0) {
printf(_("You got a partition overlap on the disk. Fix it first!\n"));
- return;
+ return -EINVAL;
}
snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
for (;;) {
printf(_("It is highly recommended that eleventh partition\n"
"covers the entire disk and is of type `SGI volume'\n"));
sgi_set_partition(cxt, n, first, last-first, sys);
+
+ return 0;
}
static int sgi_create_disklabel(struct fdisk_context *cxt)
return 0;
}
-static void sun_add_partition(struct fdisk_context *cxt, int n,
- struct fdisk_parttype *t)
+static int sun_add_partition(struct fdisk_context *cxt, int n,
+ struct fdisk_parttype *t)
{
uint32_t starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS];
struct sun_partition *part = &sunlabel->partitions[n];
if (part->num_sectors && tag->tag != SSWAP16(SUN_TAG_UNASSIGNED)) {
printf(_("Partition %d is already defined. Delete "
"it before re-adding it.\n"), n + 1);
- return;
+ return -EINVAL;
}
fetch_sun(cxt, starts, lens, &start, &stop);
else {
printf(_("Other partitions already cover the whole disk.\nDelete "
"some/shrink them before retry.\n"));
- return;
+ return -EINVAL;
}
}
snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
sys = SUN_TAG_BACKUP;
set_sun_partition(cxt, n, first, last, sys);
+ return 0;
}
static int sun_delete_partition(struct fdisk_context *cxt, int partnum)
}
/* Performs logical checks to add a new partition entry */
-static void gpt_add_partition(struct fdisk_context *cxt, int partnum,
+static int gpt_add_partition(struct fdisk_context *cxt, int partnum,
struct fdisk_parttype *t)
{
char msg[256];
/* check basic tests before even considering adding a new partition */
if (!cxt || partnum < 0)
- return;
+ return -EINVAL;
if (!partition_unused(ents[partnum])) {
printf(_("Partition %d is already defined. "
"Delete it before re-adding it.\n"), partnum +1);
- return;
+ return -EINVAL;
}
if (le32_to_cpu(pheader->npartition_entries) == partitions_in_use(pheader, ents)) {
printf(_("All partitions are already in use.\n"));
- return;
+ return -EINVAL;
}
if (!get_free_sectors(cxt, pheader, ents, &tmp, &f0)) {
printf(_("No free sectors available.\n"));
- return;
+ return -ENOSPC;
}
first_sect = find_first_available(pheader, ents, 0);
printf(_("Could not create partition %d\n"), partnum + 1);
else
printf(_("Created partition %d\n"), partnum + 1);
+
+ return 0;
}
/*