]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix sun and sgi to be usable from sfdisk
authorKarel Zak <kzak@redhat.com>
Fri, 3 Oct 2014 12:47:05 +0000 (14:47 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 7 Oct 2014 12:55:33 +0000 (14:55 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/sfdisk.8
disk-utils/sfdisk.c
libfdisk/src/sgi.c
libfdisk/src/sun.c

index 49b0daffdaa0507404a1e5a0bbe39d1594249799..226fa34214a1e7d8c480d0a4abcfa88a90bf2a9d 100644 (file)
@@ -39,6 +39,12 @@ sense for new devices.
 block-device I/O limits when specified by relative sizes, or when default
 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
 The commands are mutually exclusive.
 .TP
index af83d2c2296ba85cc94c544ce83dbc38fcc4eb68..7a5e8be8d0b79a29ffdea6d7f95939854e7a9a65 100644 (file)
@@ -1226,8 +1226,13 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
                                if (rc == 0)
                                        rc = SFDISK_DONE_ASK;
                                break;
-                       } else if (!rc)         /* add partition */
+                       } else if (!rc) {               /* add partition */
                                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 */
                                sfdisk_print_partition(sf, cur_partno);
index 38b1c80c1b80a39d17cf3e568a2739e6e9e6a5b9..20ae59c03077ea14f88bbe7349efefba93b8ca32 100644 (file)
@@ -552,6 +552,8 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
        if (sortcount == 0) {
                if (verbose)
                        fdisk_info(cxt, _("No partitions defined."));
+               if (lastblock)
+                       add_to_freelist(cxt, 0, lastblock);
                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);
                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."));
                sgi_set_entire(cxt);
                sgi_set_volhdr(cxt);
@@ -853,11 +855,11 @@ static int sgi_add_partition(struct fdisk_context *cxt,
 
        /* last sector */
        if (pa && pa->end_follow_default)
-               last -= 1;
+               last -= 1ULL;
        else if (pa && pa->size) {
-               if (first + pa->size > last)
+               if (first + pa->size - 1ULL > last)
                        return -ERANGE;
-               last = first + pa->size;
+               last = first + pa->size - 1ULL;
        } else {
                snprintf(mesg, sizeof(mesg),
                         _("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,
                        sizeof(struct sgi_partition) * 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);
 
        fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
index 48ab7dc1c1f2635133218c80409f431e5e98703a..f9f1d472f2a69e3f7b4c384737c3a9d25886770b 100644 (file)
@@ -261,16 +261,19 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
        } else
                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);
-       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,
                          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,
                          SUN_TAG_WHOLEDISK);
+       }
 
        {
                unsigned short *ush = (unsigned short *)sunlabel;