diff options
author | Karel Zak | 2014-09-17 15:25:02 +0200 |
---|---|---|
committer | Karel Zak | 2014-10-07 14:55:32 +0200 |
commit | ea50ba5bf188dc02812e062678479ded1e727d1c (patch) | |
tree | a398b059f48125fa47289759ac12c0a8aaf323ce /libfdisk | |
parent | libfdisk: (sgi) add set_part() API (diff) | |
download | kernel-qcow2-util-linux-ea50ba5bf188dc02812e062678479ded1e727d1c.tar.gz kernel-qcow2-util-linux-ea50ba5bf188dc02812e062678479ded1e727d1c.tar.xz kernel-qcow2-util-linux-ea50ba5bf188dc02812e062678479ded1e727d1c.zip |
libfdisk: remove old label drives' API for parttypes
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/fdiskP.h | 9 | ||||
-rw-r--r-- | libfdisk/src/label.c | 9 | ||||
-rw-r--r-- | libfdisk/src/sun.c | 99 |
3 files changed, 62 insertions, 55 deletions
diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index af0470b68..6dff06b97 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -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); diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 5ae67856b..071657c57 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -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; } diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c index 4f9e10a2a..48ab7dc1c 100644 --- a/libfdisk/src/sun.c +++ b/libfdisk/src/sun.c @@ -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, |