]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: remove old label drives' API for parttypes
authorKarel Zak <kzak@redhat.com>
Wed, 17 Sep 2014 13:25:02 +0000 (15:25 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 7 Oct 2014 12:55:32 +0000 (14:55 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/fdiskP.h
libfdisk/src/label.c
libfdisk/src/sun.c

index af0470b6827c37a7f348165fdee4dda7fc369ce5..6dff06b9744ac407744667f8ca7790509db3ca0f 100644 (file)
@@ -205,19 +205,10 @@ struct fdisk_label_operations {
        int (*set_part)(struct fdisk_context *cxt, size_t n,
                                                struct fdisk_partition *pa);
 
-/*** TODO use set_part() */
-       /* get partition type */
-       struct fdisk_parttype *(*part_get_type)(struct fdisk_context *cxt,
-                                               size_t partnum);
-       /* set partition type */
-       int (*part_set_type)(struct fdisk_context *cxt,
-                                               size_t partnum,
-                                               struct fdisk_parttype *t);
        /* return state of the partition */
        int (*part_is_used)(struct fdisk_context *cxt, size_t partnum);
 
        int (*part_toggle_flag)(struct fdisk_context *cxt, size_t i, unsigned long flag);
-/******/
 
        /* refresh alignment setting */
        int (*reset_alignment)(struct fdisk_context *cxt);
index 5ae67856bc5e878cc5fe97a1b2c7eeb2ba3133ea..071657c57742af139a7abb31e228f340e69a5bb9 100644 (file)
@@ -404,17 +404,16 @@ int fdisk_set_partition_type(struct fdisk_context *cxt,
                             size_t partnum,
                             struct fdisk_parttype *t)
 {
-       if (!cxt || !cxt->label)
+       if (!cxt || !cxt->label || !t)
                return -EINVAL;
 
-       DBG(CXT, ul_debugobj(cxt, "partition: %zd: set type", partnum));
 
        if (cxt->label->op->set_part) {
                struct fdisk_partition pa = { .type = t };
-               return cxt->label->op->set_part(cxt, partnum, &pa);
 
-       } else if (cxt->label->op->part_set_type)
-               return cxt->label->op->part_set_type(cxt, partnum, t);
+               DBG(CXT, ul_debugobj(cxt, "partition: %zd: set type", partnum));
+               return cxt->label->op->set_part(cxt, partnum, &pa);
+       }
 
        return -ENOSYS;
 }
index 4f9e10a2a641161504fff415f80c90967f03bd75..48ab7dc1c1f2635133218c80409f431e5e98703a 100644 (file)
@@ -68,7 +68,7 @@ static inline struct fdisk_sun_label *self_label(struct fdisk_context *cxt)
        return (struct fdisk_sun_label *) cxt->label;
 }
 
-static void set_sun_partition(struct fdisk_context *cxt, size_t i,
+static void set_partition(struct fdisk_context *cxt, size_t i,
                uint32_t start,uint32_t stop, uint16_t sysid)
 {
        struct sun_disklabel *sunlabel = self_disklabel(cxt);
@@ -261,14 +261,14 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
        } else
                ndiv = cxt->geom.cylinders * 2 / 3;
 
-       set_sun_partition(cxt, 0, 0, ndiv * cxt->geom.heads * cxt->geom.sectors,
+       set_partition(cxt, 0, 0, ndiv * cxt->geom.heads * cxt->geom.sectors,
                          SUN_TAG_LINUX_NATIVE);
-       set_sun_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);
 
-       set_sun_partition(cxt, 2, 0,
+       set_partition(cxt, 2, 0,
                          cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors,
                          SUN_TAG_WHOLEDISK);
 
@@ -610,7 +610,7 @@ static int sun_add_partition(
        if (pa && pa->end_follow_default)
                last = whole_disk || (n == 2 && !first) ? stop2 : stop;
        else if (pa && pa->size) {
-               last = pa->size;
+               last = first + pa->size - 1ULL;
 
                if (!whole_disk && last > stop)
                        return -ERANGE;
@@ -680,7 +680,7 @@ static int sun_add_partition(
        if (whole_disk)
                sys = SUN_TAG_WHOLEDISK;
 
-       set_sun_partition(cxt, n, first, last, sys);
+       set_partition(cxt, n, first, last, sys);
        cxt->label->nparts_cur = count_used_partitions(cxt);
        if (partno)
                *partno = n;
@@ -919,10 +919,10 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
        return 0;
 }
 
-static int sun_set_parttype(
+static int sun_set_partition(
                struct fdisk_context *cxt,
                size_t i,
-               struct fdisk_parttype *t)
+               struct fdisk_partition *pa)
 {
        struct sun_disklabel *sunlabel;
        struct sun_partition *part;
@@ -934,42 +934,59 @@ static int sun_set_parttype(
 
        sunlabel = self_disklabel(cxt);
 
-       if (i >= cxt->label->nparts_max || !t || t->code > UINT16_MAX)
+       if (i >= cxt->label->nparts_max)
                return -EINVAL;
 
-       if (i == 2 && t->code != SUN_TAG_WHOLEDISK)
-               fdisk_info(cxt, _("Consider leaving partition 3 as Whole disk (5),\n"
-                        "as SunOS/Solaris expects it and even Linux likes it.\n"));
-
-       part = &sunlabel->partitions[i];
-       info = &sunlabel->vtoc.infos[i];
-
-       if (t->code == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
-           int yes, rc;
-           rc = fdisk_ask_yesno(cxt,
-             _("It is highly recommended that the partition at offset 0\n"
-             "is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n"
-             "there may destroy your partition table and bootblock.\n"
-             "Are you sure you want to tag the partition as Linux swap?"), &yes);
-           if (rc)
-                   return rc;
-           if (!yes)
-                   return 1;
-       }
+       if (pa->type) {
+               struct fdisk_parttype *t = pa->type;
 
-       switch (t->code) {
-       case SUN_TAG_SWAP:
-       case SUN_TAG_LINUX_SWAP:
-               /* swaps are not mountable by default */
-               info->flags |= cpu_to_be16(SUN_FLAG_UNMNT);
-               break;
-       default:
-               /* assume other types are mountable;
-                  user can change it anyway */
-               info->flags &= ~cpu_to_be16(SUN_FLAG_UNMNT);
-               break;
+               if (t->code > UINT16_MAX)
+                       return -EINVAL;
+
+               if (i == 2 && t->code != SUN_TAG_WHOLEDISK)
+                       fdisk_info(cxt, _("Consider leaving partition 3 as Whole disk (5),\n"
+                                "as SunOS/Solaris expects it and even Linux likes it.\n"));
+
+               part = &sunlabel->partitions[i];
+               info = &sunlabel->vtoc.infos[i];
+
+               if (cxt->script == NULL &&
+                   t->code == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
+                       int yes, rc;
+
+                       rc = fdisk_ask_yesno(cxt,
+                             _("It is highly recommended that the partition at offset 0\n"
+                             "is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n"
+                             "there may destroy your partition table and bootblock.\n"
+                             "Are you sure you want to tag the partition as Linux swap?"), &yes);
+                       if (rc)
+                               return rc;
+                       if (!yes)
+                               return 1;
+               }
+
+               switch (t->code) {
+               case SUN_TAG_SWAP:
+               case SUN_TAG_LINUX_SWAP:
+                       /* swaps are not mountable by default */
+                       info->flags |= cpu_to_be16(SUN_FLAG_UNMNT);
+                       break;
+               default:
+                       /* assume other types are mountable;
+                          user can change it anyway */
+                       info->flags &= ~cpu_to_be16(SUN_FLAG_UNMNT);
+                       break;
+               }
+               info->id = cpu_to_be16(t->code);
        }
-       info->id = cpu_to_be16(t->code);
+
+       if (pa->start)
+               sunlabel->partitions[i].start_cylinder =
+                       cpu_to_be32(pa->start / (cxt->geom.heads * cxt->geom.sectors));
+       if (pa->size)
+               sunlabel->partitions[i].num_sectors = cpu_to_be32(pa->size);
+
+       fdisk_label_set_changed(cxt->label, 1);
        return 0;
 }
 
@@ -1019,10 +1036,10 @@ const struct fdisk_label_operations sun_operations =
        .list           = sun_list_disklabel,
 
        .get_part       = sun_get_partition,
+       .set_part       = sun_set_partition,
        .add_part       = sun_add_partition,
        .del_part       = sun_delete_partition,
 
-       .part_set_type  = sun_set_parttype,
        .part_is_used   = sun_partition_is_used,
        .part_toggle_flag = sun_toggle_partition_flag,