libfdisk: fix sun and sgi to be usable from sfdisk

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2014-10-03 14:47:05 +02:00
parent f5aa7b613d
commit a8a4887bcd
4 changed files with 30 additions and 11 deletions

View File

@ -39,6 +39,12 @@ sense for new devices.
block-device I/O limits when specified by relative sizes, or when default block-device I/O limits when specified by relative sizes, or when default
values expected. values expected.
.B sfdisk
does not create default system partitions for SGI and SUN disk label like
.BR fdisk (8).
It is necessary to explicitly create all partitions including whole-disk system
partitions.
.SH COMMANDS .SH COMMANDS
The commands are mutually exclusive. The commands are mutually exclusive.
.TP .TP

View File

@ -1226,8 +1226,13 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
if (rc == 0) if (rc == 0)
rc = SFDISK_DONE_ASK; rc = SFDISK_DONE_ASK;
break; break;
} else if (!rc) /* add partition */ } else if (!rc) { /* add partition */
rc = fdisk_add_partition(sf->cxt, pa, &cur_partno); rc = fdisk_add_partition(sf->cxt, pa, &cur_partno);
if (rc) {
errno = -rc;
fdisk_warn(sf->cxt, _("failed to add partition"));
}
}
if (!rc) { /* success, print reult */ if (!rc) { /* success, print reult */
sfdisk_print_partition(sf, cur_partno); sfdisk_print_partition(sf, cur_partno);

View File

@ -552,6 +552,8 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
if (sortcount == 0) { if (sortcount == 0) {
if (verbose) if (verbose)
fdisk_info(cxt, _("No partitions defined.")); fdisk_info(cxt, _("No partitions defined."));
if (lastblock)
add_to_freelist(cxt, 0, lastblock);
return (lastblock > 0) ? 1 : (lastblock == 0) ? 0 : -1; return (lastblock > 0) ? 1 : (lastblock == 0) ? 0 : -1;
} }
@ -789,7 +791,7 @@ static int sgi_add_partition(struct fdisk_context *cxt,
"Delete it before re-adding it."), n + 1); "Delete it before re-adding it."), n + 1);
return -EINVAL; return -EINVAL;
} }
if (sgi_entire(cxt) == -1 && sys != SGI_TYPE_ENTIRE_DISK) { if (!cxt->script && sgi_entire(cxt) == -1 && sys != SGI_TYPE_ENTIRE_DISK) {
fdisk_info(cxt, _("Attempting to generate entire disk entry automatically.")); fdisk_info(cxt, _("Attempting to generate entire disk entry automatically."));
sgi_set_entire(cxt); sgi_set_entire(cxt);
sgi_set_volhdr(cxt); sgi_set_volhdr(cxt);
@ -853,11 +855,11 @@ static int sgi_add_partition(struct fdisk_context *cxt,
/* last sector */ /* last sector */
if (pa && pa->end_follow_default) if (pa && pa->end_follow_default)
last -= 1; last -= 1ULL;
else if (pa && pa->size) { else if (pa && pa->size) {
if (first + pa->size > last) if (first + pa->size - 1ULL > last)
return -ERANGE; return -ERANGE;
last = first + pa->size; last = first + pa->size - 1ULL;
} else { } else {
snprintf(mesg, sizeof(mesg), snprintf(mesg, sizeof(mesg),
_("Last %s or +%s or +size{K,M,G,T,P}"), _("Last %s or +%s or +size{K,M,G,T,P}"),
@ -990,9 +992,12 @@ static int sgi_create_disklabel(struct fdisk_context *cxt)
memset(&(sgilabel->partitions), 0, memset(&(sgilabel->partitions), 0,
sizeof(struct sgi_partition) * SGI_MAXPARTITIONS); sizeof(struct sgi_partition) * SGI_MAXPARTITIONS);
cxt->label->nparts_max = SGI_MAXPARTITIONS; cxt->label->nparts_max = SGI_MAXPARTITIONS;
sgi_set_entire(cxt);
sgi_set_volhdr(cxt);
/* don't create default layout when a script defined */
if (!cxt->script) {
sgi_set_entire(cxt);
sgi_set_volhdr(cxt);
}
cxt->label->nparts_cur = count_used_partitions(cxt); cxt->label->nparts_cur = count_used_partitions(cxt);
fdisk_sinfo(cxt, FDISK_INFO_SUCCESS, fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,

View File

@ -261,16 +261,19 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
} else } else
ndiv = cxt->geom.cylinders * 2 / 3; ndiv = cxt->geom.cylinders * 2 / 3;
set_partition(cxt, 0, 0, ndiv * cxt->geom.heads * cxt->geom.sectors, /* create the default layout only if no-script defined */
if (!cxt->script) {
set_partition(cxt, 0, 0, ndiv * cxt->geom.heads * cxt->geom.sectors,
SUN_TAG_LINUX_NATIVE); SUN_TAG_LINUX_NATIVE);
set_partition(cxt, 1, ndiv * cxt->geom.heads * cxt->geom.sectors, set_partition(cxt, 1, ndiv * cxt->geom.heads * cxt->geom.sectors,
cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors, cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors,
SUN_TAG_LINUX_SWAP); SUN_TAG_LINUX_SWAP);
sunlabel->vtoc.infos[1].flags |= cpu_to_be16(SUN_FLAG_UNMNT); sunlabel->vtoc.infos[1].flags |= cpu_to_be16(SUN_FLAG_UNMNT);
set_partition(cxt, 2, 0, set_partition(cxt, 2, 0,
cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors, cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors,
SUN_TAG_WHOLEDISK); SUN_TAG_WHOLEDISK);
}
{ {
unsigned short *ush = (unsigned short *)sunlabel; unsigned short *ush = (unsigned short *)sunlabel;