2006-12-07 00:25:35 +01:00
|
|
|
/*
|
|
|
|
* fdisksunlabel.c
|
|
|
|
*
|
|
|
|
* I think this is mostly, or entirely, due to
|
|
|
|
* Jakub Jelinek (jj@sunsite.mff.cuni.cz), July 1996
|
|
|
|
*
|
|
|
|
* Merged with fdisk for other architectures, aeb, June 1998.
|
2006-12-07 00:25:39 +01:00
|
|
|
*
|
|
|
|
* Sat Mar 20 EST 1999 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
* Internationalization
|
2006-12-07 00:25:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h> /* stderr */
|
2006-12-07 00:26:12 +01:00
|
|
|
#include <stdlib.h> /* qsort */
|
2006-12-07 00:25:35 +01:00
|
|
|
#include <string.h> /* strstr */
|
|
|
|
#include <unistd.h> /* write */
|
|
|
|
#include <sys/ioctl.h> /* ioctl */
|
2006-12-07 00:26:05 +01:00
|
|
|
|
2006-12-07 00:25:39 +01:00
|
|
|
#include "nls.h"
|
2007-11-07 19:05:31 +01:00
|
|
|
#include "blkdev.h"
|
2013-02-04 17:33:49 +01:00
|
|
|
#include "bitops.h"
|
2006-12-07 00:25:35 +01:00
|
|
|
|
2006-12-07 00:25:39 +01:00
|
|
|
#include "common.h"
|
2006-12-07 00:25:35 +01:00
|
|
|
#include "fdisk.h"
|
2012-12-03 16:22:17 +01:00
|
|
|
#include "fdiskdoslabel.h"
|
2013-02-04 18:29:27 +01:00
|
|
|
#include "fdisksunlabel.h"
|
2006-12-07 00:25:35 +01:00
|
|
|
|
2012-12-11 12:56:27 +01:00
|
|
|
/*
|
|
|
|
* in-memory fdisk SUN stuff
|
|
|
|
*/
|
|
|
|
struct fdisk_sun_label {
|
|
|
|
struct fdisk_label head; /* generic part */
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *header; /* on-disk data (pointer to cxt->firstsector) */
|
2012-12-11 12:56:27 +01:00
|
|
|
};
|
|
|
|
|
2012-09-24 11:30:26 +02:00
|
|
|
static struct fdisk_parttype sun_parttypes[] = {
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{SUN_TAG_UNASSIGNED, N_("Unassigned")},
|
|
|
|
{SUN_TAG_BOOT, N_("Boot")},
|
|
|
|
{SUN_TAG_ROOT, N_("SunOS root")},
|
|
|
|
{SUN_TAG_SWAP, N_("SunOS swap")},
|
|
|
|
{SUN_TAG_USR, N_("SunOS usr")},
|
2013-02-04 18:29:27 +01:00
|
|
|
{SUN_TAG_WHOLEDISK, N_("Whole disk")},
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{SUN_TAG_STAND, N_("SunOS stand")},
|
|
|
|
{SUN_TAG_VAR, N_("SunOS var")},
|
|
|
|
{SUN_TAG_HOME, N_("SunOS home")},
|
|
|
|
{SUN_TAG_ALTSCTR, N_("SunOS alt sectors")},
|
|
|
|
{SUN_TAG_CACHE, N_("SunOS cachefs")},
|
|
|
|
{SUN_TAG_RESERVED, N_("SunOS reserved")},
|
|
|
|
{SUN_TAG_LINUX_SWAP, N_("Linux swap")},
|
|
|
|
{SUN_TAG_LINUX_NATIVE, N_("Linux native")},
|
|
|
|
{SUN_TAG_LINUX_LVM, N_("Linux LVM")},
|
|
|
|
{SUN_TAG_LINUX_RAID, N_("Linux raid autodetect")},
|
2006-12-07 00:25:35 +01:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
/* return poiter buffer with on-disk data */
|
2013-02-04 18:29:27 +01:00
|
|
|
static inline struct sun_disklabel *self_disklabel(struct fdisk_context *cxt)
|
2013-01-18 14:43:00 +01:00
|
|
|
{
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt);
|
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
return ((struct fdisk_sun_label *) cxt->label)->header;
|
2013-01-18 14:43:00 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
/* return in-memory sun fdisk data */
|
|
|
|
static inline struct fdisk_sun_label *self_label(struct fdisk_context *cxt)
|
|
|
|
{
|
|
|
|
assert(cxt);
|
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
|
|
|
|
|
|
|
return (struct fdisk_sun_label *) cxt->label;
|
|
|
|
}
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
int sun_is_empty_type(struct fdisk_context *cxt, size_t i)
|
2013-01-18 14:43:00 +01:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-01-18 14:43:00 +01:00
|
|
|
|
|
|
|
return (!sunlabel->partitions[i].num_sectors ||
|
2013-02-04 18:29:27 +01:00
|
|
|
!sunlabel->vtoc.infos[i].id);
|
2013-01-18 14:43:00 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
static void set_sun_partition(struct fdisk_context *cxt, size_t i,
|
|
|
|
uint32_t start,uint32_t stop, uint16_t sysid)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->vtoc.infos[i].id = cpu_to_be16(sysid);
|
|
|
|
sunlabel->vtoc.infos[i].flags = cpu_to_be16(0);
|
2006-12-07 00:25:35 +01:00
|
|
|
sunlabel->partitions[i].start_cylinder =
|
2013-02-04 17:33:49 +01:00
|
|
|
cpu_to_be32(start / (cxt->geom.heads * cxt->geom.sectors));
|
|
|
|
sunlabel->partitions[i].num_sectors = cpu_to_be32(stop - start);
|
2013-01-18 16:11:40 +01:00
|
|
|
fdisk_label_set_changed(cxt->label, 1);
|
2012-06-03 20:15:17 +02:00
|
|
|
print_partition_size(cxt, i + 1, start, stop, sysid);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
static size_t count_used_partitions(struct fdisk_context *cxt)
|
2011-12-15 20:02:43 +01:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-01-18 12:47:27 +01:00
|
|
|
size_t ct = 0, i;
|
|
|
|
|
2013-01-18 14:43:00 +01:00
|
|
|
assert(sunlabel);
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
for (i = 0; i < cxt->label->nparts_max; i++) {
|
2013-01-18 12:47:27 +01:00
|
|
|
if (sunlabel->partitions[i].num_sectors)
|
|
|
|
ct++;
|
|
|
|
}
|
|
|
|
return ct;
|
2011-12-15 20:02:43 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
static int sun_probe_label(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-01-18 14:43:00 +01:00
|
|
|
struct fdisk_sun_label *sun;
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel;
|
2006-12-07 00:25:35 +01:00
|
|
|
unsigned short *ush;
|
|
|
|
int csum;
|
2013-01-18 14:43:00 +01:00
|
|
|
int need_fixing = 0;
|
2006-12-07 00:26:03 +01:00
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-01-28 10:37:45 +01:00
|
|
|
/* map first sector to header */
|
|
|
|
sun = (struct fdisk_sun_label *) cxt->label;
|
2013-02-04 18:29:27 +01:00
|
|
|
sun->header = (struct sun_disklabel *) cxt->firstsector;
|
2013-01-28 10:37:45 +01:00
|
|
|
sunlabel = sun->header;
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-02-04 17:33:49 +01:00
|
|
|
if (be16_to_cpu(sunlabel->magic) != SUN_LABEL_MAGIC) {
|
2013-01-28 10:37:45 +01:00
|
|
|
sun->header = NULL;
|
2013-01-18 14:43:00 +01:00
|
|
|
return 0; /* failed */
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
2011-12-15 20:02:43 +01:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
ush = ((unsigned short *) (sunlabel + 1)) - 1;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
for (csum = 0; ush >= (unsigned short *)sunlabel;)
|
|
|
|
csum ^= *ush--;
|
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
if (csum) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Detected sun disklabel with wrong checsum.\n"
|
|
|
|
"Probably you'll have to set all the values,\n"
|
|
|
|
"e.g. heads, sectors, cylinders and partitions\n"
|
|
|
|
"or force a fresh label (s command in main menu)"));
|
2013-01-18 14:43:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* map first sector buffer to sun header */
|
2013-01-22 18:05:18 +01:00
|
|
|
sun = (struct fdisk_sun_label *) cxt->label;
|
2013-02-04 18:29:27 +01:00
|
|
|
sun->header = (struct sun_disklabel *) cxt->firstsector;
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
cxt->label->nparts_max = SUN_MAXPARTITIONS;
|
2013-02-04 17:33:49 +01:00
|
|
|
cxt->geom.heads = be16_to_cpu(sunlabel->nhead);
|
|
|
|
cxt->geom.cylinders = be16_to_cpu(sunlabel->ncyl);
|
|
|
|
cxt->geom.sectors = be16_to_cpu(sunlabel->nsect);
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
if (be32_to_cpu(sunlabel->vtoc.version) != SUN_VTOC_VERSION) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Detected sun disklabel with wrong version [%d]."),
|
2013-02-04 18:29:27 +01:00
|
|
|
be32_to_cpu(sunlabel->vtoc.version));
|
2013-01-18 14:43:00 +01:00
|
|
|
need_fixing = 1;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
2013-02-04 18:29:27 +01:00
|
|
|
if (be32_to_cpu(sunlabel->vtoc.sanity) != SUN_VTOC_SANITY) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Detected sun disklabel with wrong vtoc.sanity [0x%08x]."),
|
2013-02-04 18:29:27 +01:00
|
|
|
be32_to_cpu(sunlabel->vtoc.sanity));
|
2013-01-18 14:43:00 +01:00
|
|
|
need_fixing = 1;
|
|
|
|
}
|
2013-02-04 18:29:27 +01:00
|
|
|
if (be16_to_cpu(sunlabel->vtoc.nparts) != SUN_MAXPARTITIONS) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Detected sun disklabel with wrong vtoc.nparts [%u]."),
|
2013-02-04 18:29:27 +01:00
|
|
|
be16_to_cpu(sunlabel->vtoc.nparts));
|
2013-01-18 14:43:00 +01:00
|
|
|
need_fixing = 1;
|
|
|
|
}
|
|
|
|
if (need_fixing) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Warning: Wrong values need to be fixed up and "
|
|
|
|
"will be corrected by w(rite)"));
|
2013-02-04 17:33:49 +01:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->vtoc.version = cpu_to_be32(SUN_VTOC_VERSION);
|
|
|
|
sunlabel->vtoc.sanity = cpu_to_be32(SUN_VTOC_SANITY);
|
|
|
|
sunlabel->vtoc.nparts = cpu_to_be16(SUN_MAXPARTITIONS);
|
2013-01-18 14:43:00 +01:00
|
|
|
|
|
|
|
ush = (unsigned short *)sunlabel;
|
|
|
|
csum = 0;
|
2013-02-04 18:29:27 +01:00
|
|
|
while(ush < (unsigned short *)(&sunlabel->csum))
|
2013-01-18 14:43:00 +01:00
|
|
|
csum ^= *ush++;
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->csum = csum;
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
fdisk_label_set_changed(cxt->label, 1);
|
2013-01-18 14:43:00 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
cxt->label->nparts_cur = count_used_partitions(cxt);
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-08 10:48:15 +01:00
|
|
|
static void ask_geom(struct fdisk_context *cxt)
|
|
|
|
{
|
|
|
|
uintmax_t res;
|
|
|
|
|
|
|
|
assert(cxt);
|
|
|
|
|
|
|
|
if (fdisk_ask_number(cxt, 1, 1, 1024, _("Heads"), &res) == 0)
|
|
|
|
cxt->geom.heads = res;
|
|
|
|
if (fdisk_ask_number(cxt, 1, 1, 1024, _("Sectors/track"), &res) == 0)
|
|
|
|
cxt->geom.sectors = res;
|
|
|
|
if (fdisk_ask_number(cxt, 1, 1, USHRT_MAX, _("Cylinders"), &res) == 0)
|
|
|
|
cxt->geom.cylinders = res;
|
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
static int sun_create_disklabel(struct fdisk_context *cxt)
|
2006-12-07 00:25:35 +01:00
|
|
|
{
|
|
|
|
struct hd_geometry geometry;
|
2012-05-27 21:44:24 +02:00
|
|
|
sector_t llsectors, llcyls;
|
2010-02-26 16:06:18 +01:00
|
|
|
unsigned int ndiv, sec_fac;
|
|
|
|
int res;
|
2006-12-07 00:25:35 +01:00
|
|
|
|
2013-01-18 14:43:00 +01:00
|
|
|
struct fdisk_sun_label *sun; /* libfdisk sun handler */
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel; /* on disk data */
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_info(cxt, _("Building a new Sun disklabel."));
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-01-18 14:43:00 +01:00
|
|
|
/* map first sector to header */
|
|
|
|
fdisk_zeroize_firstsector(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
sun = (struct fdisk_sun_label *) cxt->label;
|
2013-02-04 18:29:27 +01:00
|
|
|
sun->header = (struct sun_disklabel *) cxt->firstsector;
|
2013-01-18 14:43:00 +01:00
|
|
|
|
|
|
|
sunlabel = sun->header;
|
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
cxt->label->nparts_max = SUN_MAXPARTITIONS;
|
2012-07-23 14:24:25 +02:00
|
|
|
fdisk_zeroize_firstsector(cxt);
|
2011-12-15 20:02:43 +01:00
|
|
|
|
2013-02-04 17:33:49 +01:00
|
|
|
sunlabel->magic = cpu_to_be16(SUN_LABEL_MAGIC);
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->vtoc.version = cpu_to_be32(SUN_VTOC_VERSION);
|
|
|
|
sunlabel->vtoc.sanity = cpu_to_be32(SUN_VTOC_SANITY);
|
|
|
|
sunlabel->vtoc.nparts = cpu_to_be16(SUN_MAXPARTITIONS);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2012-05-21 22:28:03 +02:00
|
|
|
res = blkdev_get_sectors(cxt->dev_fd, &llsectors);
|
2012-06-03 20:15:17 +02:00
|
|
|
sec_fac = cxt->sector_size / 512;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2008-07-24 00:46:05 +02:00
|
|
|
#ifdef HDIO_GETGEO
|
2012-05-21 22:28:03 +02:00
|
|
|
if (!ioctl(cxt->dev_fd, HDIO_GETGEO, &geometry)) {
|
2012-06-17 18:10:33 +02:00
|
|
|
cxt->geom.heads = geometry.heads;
|
|
|
|
cxt->geom.sectors = geometry.sectors;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
if (res == 0) {
|
2012-06-17 18:10:33 +02:00
|
|
|
llcyls = llsectors / (cxt->geom.heads * cxt->geom.sectors * sec_fac);
|
|
|
|
cxt->geom.cylinders = llcyls;
|
|
|
|
if (cxt->geom.cylinders != llcyls)
|
|
|
|
cxt->geom.cylinders = ~0;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
} else {
|
2012-06-17 18:10:33 +02:00
|
|
|
cxt->geom.cylinders = geometry.cylinders;
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt,
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
_("Warning: BLKGETSIZE ioctl failed on %s. "
|
2012-06-17 18:10:33 +02:00
|
|
|
"Using geometry cylinder value of %llu.\n"
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
"This value may be truncated for devices"
|
2013-02-08 10:48:15 +01:00
|
|
|
" > 33.8 GB."),
|
|
|
|
cxt->dev_path, cxt->geom.cylinders);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
}
|
2008-07-24 00:46:05 +02:00
|
|
|
} else
|
|
|
|
#endif
|
2013-02-08 10:48:15 +01:00
|
|
|
ask_geom(cxt);
|
2006-12-07 00:25:43 +01:00
|
|
|
|
2013-02-04 17:33:49 +01:00
|
|
|
sunlabel->acyl = cpu_to_be16(2);
|
|
|
|
sunlabel->pcyl = cpu_to_be16(cxt->geom.cylinders);
|
|
|
|
sunlabel->ncyl = cpu_to_be16(cxt->geom.cylinders - 2);
|
|
|
|
sunlabel->rpm = cpu_to_be16(5400);
|
|
|
|
sunlabel->intrlv = cpu_to_be16(1);
|
|
|
|
sunlabel->apc = cpu_to_be16(0);
|
2006-12-07 00:25:43 +01:00
|
|
|
|
2013-02-04 17:33:49 +01:00
|
|
|
sunlabel->nhead = cpu_to_be16(cxt->geom.heads);
|
|
|
|
sunlabel->nsect = cpu_to_be16(cxt->geom.sectors);
|
|
|
|
sunlabel->ncyl = cpu_to_be16(cxt->geom.cylinders);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
snprintf((char *) sunlabel->label_id, sizeof(sunlabel->label_id),
|
|
|
|
"Linux cyl %llu alt %u hd %u sec %llu",
|
2013-02-04 17:33:49 +01:00
|
|
|
cxt->geom.cylinders, be16_to_cpu(sunlabel->acyl),
|
|
|
|
cxt->geom.heads, cxt->geom.sectors);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2012-06-17 18:10:33 +02:00
|
|
|
if (cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors >= 150 * 2048) {
|
|
|
|
ndiv = cxt->geom.cylinders - (50 * 2048 / (cxt->geom.heads * cxt->geom.sectors)); /* 50M swap */
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
} else
|
2012-06-17 18:10:33 +02:00
|
|
|
ndiv = cxt->geom.cylinders * 2 / 3;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2012-06-17 18:10:33 +02:00
|
|
|
set_sun_partition(cxt, 0, 0, ndiv * cxt->geom.heads * cxt->geom.sectors,
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
SUN_TAG_LINUX_NATIVE);
|
2012-06-17 18:10:33 +02:00
|
|
|
set_sun_partition(cxt, 1, ndiv * cxt->geom.heads * cxt->geom.sectors,
|
|
|
|
cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors,
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
SUN_TAG_LINUX_SWAP);
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->vtoc.infos[1].flags |= cpu_to_be16(SUN_FLAG_UNMNT);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2013-01-18 14:43:00 +01:00
|
|
|
set_sun_partition(cxt, 2, 0,
|
|
|
|
cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors,
|
2013-02-04 18:29:27 +01:00
|
|
|
SUN_TAG_WHOLEDISK);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
{
|
|
|
|
unsigned short *ush = (unsigned short *)sunlabel;
|
|
|
|
unsigned short csum = 0;
|
2013-02-04 18:29:27 +01:00
|
|
|
while(ush < (unsigned short *)(&sunlabel->csum))
|
2006-12-07 00:25:35 +01:00
|
|
|
csum ^= *ush++;
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->csum = csum;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
2006-12-07 00:25:43 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
fdisk_label_set_changed(cxt->label, 1);
|
|
|
|
cxt->label->nparts_cur = count_used_partitions(cxt);
|
2012-07-23 10:56:06 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
void toggle_sunflags(struct fdisk_context *cxt, size_t i, uint16_t mask)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
|
|
|
struct sun_info *p = &sunlabel->vtoc.infos[i];
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
p->flags ^= cpu_to_be16(mask);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2013-01-18 16:11:40 +01:00
|
|
|
fdisk_label_set_changed(cxt->label, 1);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
static void fetch_sun(struct fdisk_context *cxt,
|
|
|
|
uint32_t *starts,
|
|
|
|
uint32_t *lens,
|
|
|
|
uint32_t *start,
|
|
|
|
uint32_t *stop)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel;
|
2013-01-18 12:47:27 +01:00
|
|
|
int continuous = 1;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt);
|
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
sunlabel = self_disklabel(cxt);
|
2013-01-18 14:43:00 +01:00
|
|
|
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
*start = 0;
|
2012-06-17 18:10:33 +02:00
|
|
|
*stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
for (i = 0; i < cxt->label->nparts_max; i++) {
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
struct sun_partition *part = &sunlabel->partitions[i];
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_info *info = &sunlabel->vtoc.infos[i];
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
|
|
|
if (part->num_sectors &&
|
2013-02-04 18:29:27 +01:00
|
|
|
be16_to_cpu(info->id) != SUN_TAG_UNASSIGNED &&
|
|
|
|
be16_to_cpu(info->id) != SUN_TAG_WHOLEDISK) {
|
2013-02-04 17:33:49 +01:00
|
|
|
starts[i] = be32_to_cpu(part->start_cylinder) *
|
|
|
|
cxt->geom.heads * cxt->geom.sectors;
|
|
|
|
lens[i] = be32_to_cpu(part->num_sectors);
|
2006-12-07 00:25:35 +01:00
|
|
|
if (continuous) {
|
|
|
|
if (starts[i] == *start)
|
|
|
|
*start += lens[i];
|
|
|
|
else if (starts[i] + lens[i] >= *stop)
|
|
|
|
*stop = starts[i];
|
|
|
|
else
|
2006-12-07 00:25:43 +01:00
|
|
|
continuous = 0;
|
|
|
|
/* There will be probably more gaps
|
|
|
|
than one, so lets check afterwards */
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
starts[i] = 0;
|
|
|
|
lens[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 11:41:58 +01:00
|
|
|
static int verify_sun_cmp(int *a, int *b, void *data)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-07 11:41:58 +01:00
|
|
|
unsigned int *verify_sun_starts = (unsigned int *) data;
|
|
|
|
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
if (*a == -1)
|
|
|
|
return 1;
|
|
|
|
if (*b == -1)
|
|
|
|
return -1;
|
|
|
|
if (verify_sun_starts[*a] > verify_sun_starts[*b])
|
|
|
|
return 1;
|
2006-12-07 00:25:35 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
static int sun_verify_disklabel(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
uint32_t starts[SUN_MAXPARTITIONS], lens[SUN_MAXPARTITIONS], start, stop;
|
2011-08-01 15:19:53 +02:00
|
|
|
uint32_t i,j,k,starto,endo;
|
2013-02-04 18:29:27 +01:00
|
|
|
int array[SUN_MAXPARTITIONS];
|
2013-02-07 11:41:58 +01:00
|
|
|
unsigned int *verify_sun_starts;
|
2006-12-07 00:25:35 +01:00
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
verify_sun_starts = starts;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
fetch_sun(cxt, starts, lens, &start, &stop);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
for (k = 0; k < 7; k++) {
|
2013-02-04 18:29:27 +01:00
|
|
|
for (i = 0; i < SUN_MAXPARTITIONS; i++) {
|
2012-06-17 18:10:33 +02:00
|
|
|
if (k && (lens[i] % (cxt->geom.heads * cxt->geom.sectors))) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Partition %d doesn't end on cylinder boundary"), i+1);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
if (lens[i]) {
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
if (lens[j]) {
|
|
|
|
if (starts[j] == starts[i]+lens[i]) {
|
|
|
|
starts[j] = starts[i]; lens[j] += lens[i];
|
|
|
|
lens[i] = 0;
|
|
|
|
} else if (starts[i] == starts[j]+lens[j]){
|
|
|
|
lens[j] += lens[i];
|
|
|
|
lens[i] = 0;
|
|
|
|
} else if (!k) {
|
|
|
|
if (starts[i] < starts[j]+lens[j] &&
|
|
|
|
starts[j] < starts[i]+lens[i]) {
|
|
|
|
starto = starts[i];
|
|
|
|
if (starts[j] > starto)
|
|
|
|
starto = starts[j];
|
|
|
|
endo = starts[i]+lens[i];
|
|
|
|
if (starts[j]+lens[j] < endo)
|
|
|
|
endo = starts[j]+lens[j];
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Partition %d overlaps with others in "
|
|
|
|
"sectors %d-%d"), i+1, starto, endo);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-07 11:41:58 +01:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
for (i = 0; i < SUN_MAXPARTITIONS; i++) {
|
2006-12-07 00:25:35 +01:00
|
|
|
if (lens[i])
|
|
|
|
array[i] = i;
|
|
|
|
else
|
|
|
|
array[i] = -1;
|
|
|
|
}
|
2013-02-07 11:41:58 +01:00
|
|
|
qsort_r(array,ARRAY_SIZE(array),sizeof(array[0]),
|
|
|
|
(int (*)(const void *,const void *,void *)) verify_sun_cmp,
|
|
|
|
verify_sun_starts);
|
2012-06-17 18:10:07 +02:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
if (array[0] == -1) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_info(cxt, _("No partitions defined"));
|
2012-07-24 09:54:52 +02:00
|
|
|
return 0;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
2012-06-17 18:10:33 +02:00
|
|
|
stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors;
|
2006-12-07 00:25:35 +01:00
|
|
|
if (starts[array[0]])
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Unused gap - sectors 0-%d"), starts[array[0]]);
|
2006-12-07 00:25:35 +01:00
|
|
|
for (i = 0; i < 7 && array[i+1] != -1; i++) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Unused gap - sectors %d-%d"),
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
(starts[array[i]] + lens[array[i]]),
|
|
|
|
starts[array[i+1]]);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
start = (starts[array[i]] + lens[array[i]]);
|
2006-12-07 00:25:35 +01:00
|
|
|
if (start < stop)
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Unused gap - sectors %d-%d"), start, stop);
|
2012-07-24 09:54:52 +02:00
|
|
|
return 0;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2012-12-11 18:04:25 +01:00
|
|
|
static int sun_add_partition(
|
|
|
|
struct fdisk_context *cxt,
|
2013-01-22 18:05:18 +01:00
|
|
|
size_t n,
|
2012-12-11 18:04:25 +01:00
|
|
|
struct fdisk_parttype *t)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
|
|
|
uint32_t starts[SUN_MAXPARTITIONS], lens[SUN_MAXPARTITIONS];
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
struct sun_partition *part = &sunlabel->partitions[n];
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_info *info = &sunlabel->vtoc.infos[n];
|
2007-10-27 18:27:31 +01:00
|
|
|
uint32_t start, stop, stop2;
|
2012-09-26 14:14:54 +02:00
|
|
|
int whole_disk = 0, sys = t ? t->type : SUN_TAG_LINUX_NATIVE;
|
2013-02-11 10:59:43 +01:00
|
|
|
struct fdisk_ask *ask;
|
|
|
|
int rc;
|
2012-06-01 16:15:29 +02:00
|
|
|
|
2006-12-07 00:25:41 +01:00
|
|
|
char mesg[256];
|
2013-01-18 12:47:27 +01:00
|
|
|
size_t i;
|
2011-08-01 15:19:53 +02:00
|
|
|
unsigned int first, last;
|
2006-12-07 00:25:35 +01:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
if (part->num_sectors && be16_to_cpu(info->id) != SUN_TAG_UNASSIGNED) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_info(cxt, _("Partition %zd is already defined. Delete "
|
|
|
|
"it before re-adding it."), n + 1);
|
2012-11-25 20:29:18 -08:00
|
|
|
return -EINVAL;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
2012-06-01 16:15:29 +02:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
fetch_sun(cxt, starts, lens, &start, &stop);
|
2012-06-01 16:15:29 +02:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
if (stop <= start) {
|
|
|
|
if (n == 2)
|
|
|
|
whole_disk = 1;
|
|
|
|
else {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_info(cxt, _("Other partitions already cover the "
|
|
|
|
"whole disk. Delete some/shrink them before retry."));
|
2012-11-25 20:29:18 -08:00
|
|
|
return -EINVAL;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
}
|
2013-02-11 16:38:20 +01:00
|
|
|
snprintf(mesg, sizeof(mesg), _("First %s"),
|
|
|
|
fdisk_context_get_unit(cxt, SINGULAR));
|
2006-12-07 00:25:35 +01:00
|
|
|
for (;;) {
|
2013-02-11 10:59:43 +01:00
|
|
|
ask = fdisk_new_ask();
|
|
|
|
if (!ask)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
fdisk_ask_set_query(ask, mesg);
|
|
|
|
fdisk_ask_set_type(ask, FDISK_ASKTYPE_NUMBER);
|
|
|
|
|
|
|
|
if (whole_disk) {
|
|
|
|
fdisk_ask_number_set_low(ask, 0); /* minimal */
|
|
|
|
fdisk_ask_number_set_default(ask, 0); /* default */
|
|
|
|
fdisk_ask_number_set_high(ask, 0); /* maximal */
|
|
|
|
} else {
|
2013-02-11 16:38:20 +01:00
|
|
|
fdisk_ask_number_set_low(ask, scround(cxt, start)); /* minimal */
|
|
|
|
fdisk_ask_number_set_default(ask, scround(cxt, start)); /* default */
|
|
|
|
fdisk_ask_number_set_high(ask, scround(cxt, stop)); /* maximal */
|
2013-02-11 10:59:43 +01:00
|
|
|
}
|
|
|
|
rc = fdisk_do_ask(cxt, ask);
|
|
|
|
first = fdisk_ask_number_get_result(ask);
|
|
|
|
fdisk_free_ask(ask);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2013-02-11 16:38:20 +01:00
|
|
|
if (fdisk_context_use_cylinders(cxt))
|
|
|
|
first *= fdisk_context_get_units_per_sector(cxt);
|
2006-12-07 00:26:33 +01:00
|
|
|
else {
|
2006-12-07 00:25:37 +01:00
|
|
|
/* Starting sector has to be properly aligned */
|
2012-06-17 18:10:33 +02:00
|
|
|
int cs = cxt->geom.heads * cxt->geom.sectors;
|
2006-12-07 00:26:33 +01:00
|
|
|
int x = first % cs;
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
first += cs - x;
|
|
|
|
}
|
2006-12-07 00:25:37 +01:00
|
|
|
if (n == 2 && first != 0)
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("\
|
2006-12-07 00:25:37 +01:00
|
|
|
It is highly recommended that the third partition covers the whole disk\n\
|
2013-02-08 10:48:15 +01:00
|
|
|
and is of type `Whole disk'"));
|
2006-12-07 00:25:48 +01:00
|
|
|
/* ewt asks to add: "don't start a partition at cyl 0"
|
|
|
|
However, edmundo@rano.demon.co.uk writes:
|
|
|
|
"In addition to having a Sun partition table, to be able to
|
|
|
|
boot from the disc, the first partition, /dev/sdX1, must
|
|
|
|
start at cylinder 0. This means that /dev/sdX1 contains
|
|
|
|
the partition table and the boot block, as these are the
|
|
|
|
first two sectors of the disc. Therefore you must be
|
|
|
|
careful what you use /dev/sdX1 for. In particular, you must
|
|
|
|
not use a partition starting at cylinder 0 for Linux swap,
|
|
|
|
as that would overwrite the partition table and the boot
|
|
|
|
block. You may, however, use such a partition for a UFS
|
|
|
|
or EXT2 file system, as these file systems leave the first
|
|
|
|
1024 bytes undisturbed. */
|
|
|
|
/* On the other hand, one should not use partitions
|
|
|
|
starting at block 0 in an md, or the label will
|
|
|
|
be trashed. */
|
2013-01-22 18:05:18 +01:00
|
|
|
for (i = 0; i < cxt->label->nparts_max; i++)
|
2006-12-07 00:25:37 +01:00
|
|
|
if (lens[i] && starts[i] <= first
|
|
|
|
&& starts[i] + lens[i] > first)
|
2006-12-07 00:25:35 +01:00
|
|
|
break;
|
2013-01-22 18:05:18 +01:00
|
|
|
if (i < cxt->label->nparts_max && !whole_disk) {
|
2006-12-07 00:25:35 +01:00
|
|
|
if (n == 2 && !first) {
|
|
|
|
whole_disk = 1;
|
|
|
|
break;
|
|
|
|
}
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt, _("Sector %d is already allocated"), first);
|
2006-12-07 00:25:35 +01:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
2012-06-17 18:10:33 +02:00
|
|
|
stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors; /* ancient */
|
2006-12-07 00:25:35 +01:00
|
|
|
stop2 = stop;
|
2013-01-22 18:05:18 +01:00
|
|
|
for (i = 0; i < cxt->label->nparts_max; i++) {
|
2006-12-07 00:25:35 +01:00
|
|
|
if (starts[i] > first && starts[i] < stop)
|
|
|
|
stop = starts[i];
|
|
|
|
}
|
2006-12-07 00:25:46 +01:00
|
|
|
snprintf(mesg, sizeof(mesg),
|
2013-02-11 10:59:43 +01:00
|
|
|
_("Last %s or +%s or +size{K,M,G,T,P}"),
|
2013-02-11 16:38:20 +01:00
|
|
|
fdisk_context_get_unit(cxt, SINGULAR),
|
|
|
|
fdisk_context_get_unit(cxt, PLURAL));
|
2013-02-11 10:59:43 +01:00
|
|
|
|
|
|
|
ask = fdisk_new_ask();
|
|
|
|
if (!ask)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
fdisk_ask_set_query(ask, mesg);
|
|
|
|
fdisk_ask_set_type(ask, FDISK_ASKTYPE_OFFSET);
|
|
|
|
|
|
|
|
if (whole_disk) {
|
2013-02-11 16:38:20 +01:00
|
|
|
fdisk_ask_number_set_low(ask, scround(cxt, stop2)); /* minimal */
|
|
|
|
fdisk_ask_number_set_default(ask, scround(cxt, stop2)); /* default */
|
|
|
|
fdisk_ask_number_set_high(ask, scround(cxt, stop2)); /* maximal */
|
2013-02-11 10:59:43 +01:00
|
|
|
fdisk_ask_number_set_base(ask, 0);
|
|
|
|
} else if (n == 2 && !first) {
|
2013-02-11 16:38:20 +01:00
|
|
|
fdisk_ask_number_set_low(ask, scround(cxt, first)); /* minimal */
|
|
|
|
fdisk_ask_number_set_default(ask, scround(cxt, stop2)); /* default */
|
|
|
|
fdisk_ask_number_set_high(ask, scround(cxt, stop2)); /* maximal */
|
|
|
|
fdisk_ask_number_set_base(ask, scround(cxt, first));
|
2013-02-11 10:59:43 +01:00
|
|
|
} else {
|
2013-02-11 16:38:20 +01:00
|
|
|
fdisk_ask_number_set_low(ask, scround(cxt, first)); /* minimal */
|
|
|
|
fdisk_ask_number_set_default(ask, scround(cxt, stop)); /* default */
|
|
|
|
fdisk_ask_number_set_high(ask, scround(cxt, stop)); /* maximal */
|
|
|
|
fdisk_ask_number_set_base(ask, scround(cxt, first));
|
2013-02-11 10:59:43 +01:00
|
|
|
}
|
|
|
|
|
2013-02-11 16:38:20 +01:00
|
|
|
if (fdisk_context_use_cylinders(cxt))
|
2013-02-11 10:59:43 +01:00
|
|
|
fdisk_ask_number_set_unit(ask,
|
2013-02-11 16:38:20 +01:00
|
|
|
cxt->sector_size *
|
|
|
|
fdisk_context_get_units_per_sector(cxt));
|
2013-02-11 10:59:43 +01:00
|
|
|
else
|
|
|
|
fdisk_ask_number_set_unit(ask, cxt->sector_size);
|
|
|
|
|
|
|
|
rc = fdisk_do_ask(cxt, ask);
|
|
|
|
last = fdisk_ask_number_get_result(ask);
|
|
|
|
|
|
|
|
fdisk_free_ask(ask);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
if (n == 2 && !first) {
|
|
|
|
if (last >= stop2) {
|
|
|
|
whole_disk = 1;
|
|
|
|
last = stop2;
|
|
|
|
} else if (last > stop) {
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_warnx(cxt,
|
2006-12-07 00:25:39 +01:00
|
|
|
_("You haven't covered the whole disk with the 3rd partition, but your value\n"
|
|
|
|
"%d %s covers some other partition. Your entry has been changed\n"
|
2013-02-08 10:48:15 +01:00
|
|
|
"to %d %s"),
|
2013-02-11 16:38:20 +01:00
|
|
|
scround(cxt, last), fdisk_context_get_unit(cxt, SINGULAR),
|
|
|
|
scround(cxt, stop), fdisk_context_get_unit(cxt, SINGULAR));
|
2006-12-07 00:25:35 +01:00
|
|
|
last = stop;
|
|
|
|
}
|
|
|
|
} else if (!whole_disk && last > stop)
|
|
|
|
last = stop;
|
|
|
|
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
if (whole_disk)
|
2013-02-04 18:29:27 +01:00
|
|
|
sys = SUN_TAG_WHOLEDISK;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2012-06-03 20:15:17 +02:00
|
|
|
set_sun_partition(cxt, n, first, last, sys);
|
2013-01-22 18:05:18 +01:00
|
|
|
cxt->label->nparts_cur = count_used_partitions(cxt);
|
2012-11-25 20:29:18 -08:00
|
|
|
return 0;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2012-12-11 18:04:25 +01:00
|
|
|
static int sun_delete_partition(struct fdisk_context *cxt,
|
2013-01-22 18:05:18 +01:00
|
|
|
size_t partnum)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel;
|
2013-01-18 14:43:00 +01:00
|
|
|
struct sun_partition *part;
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_info *info;
|
2006-12-07 00:26:12 +01:00
|
|
|
unsigned int nsec;
|
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
sunlabel = self_disklabel(cxt);
|
2013-01-18 14:43:00 +01:00
|
|
|
part = &sunlabel->partitions[partnum];
|
2013-02-04 18:29:27 +01:00
|
|
|
info = &sunlabel->vtoc.infos[partnum];
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2012-07-23 18:15:57 +02:00
|
|
|
if (partnum == 2 &&
|
2013-02-04 18:29:27 +01:00
|
|
|
be16_to_cpu(info->id) == SUN_TAG_WHOLEDISK &&
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
!part->start_cylinder &&
|
2013-02-04 17:33:49 +01:00
|
|
|
(nsec = be32_to_cpu(part->num_sectors))
|
2012-10-07 16:33:37 +02:00
|
|
|
== cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders)
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_info(cxt, _("If you want to maintain SunOS/Solaris compatibility, "
|
|
|
|
"consider leaving this "
|
2012-10-07 16:33:37 +02:00
|
|
|
"partition as Whole disk (5), starting at 0, with %u "
|
2013-02-08 10:48:15 +01:00
|
|
|
"sectors"), nsec);
|
2013-02-04 18:29:27 +01:00
|
|
|
info->id = cpu_to_be16(SUN_TAG_UNASSIGNED);
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
part->num_sectors = 0;
|
2013-01-22 18:05:18 +01:00
|
|
|
cxt->label->nparts_cur = count_used_partitions(cxt);
|
|
|
|
fdisk_label_set_changed(cxt->label, 1);
|
2012-10-07 16:33:37 +02:00
|
|
|
return 0;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-27 21:44:04 +02:00
|
|
|
void sun_list_table(struct fdisk_context *cxt, int xtra)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel;
|
2013-01-18 12:47:27 +01:00
|
|
|
size_t i;
|
|
|
|
int w;
|
|
|
|
|
|
|
|
assert(cxt);
|
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2006-12-07 00:25:35 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
sunlabel = self_disklabel(cxt);
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2012-05-21 22:28:03 +02:00
|
|
|
w = strlen(cxt->dev_path);
|
2006-12-07 00:25:35 +01:00
|
|
|
if (xtra)
|
2006-12-07 00:25:39 +01:00
|
|
|
printf(
|
2010-02-26 16:06:18 +01:00
|
|
|
_("\nDisk %s (Sun disk label): %u heads, %llu sectors, %d rpm\n"
|
2012-06-17 18:10:33 +02:00
|
|
|
"%llu cylinders, %d alternate cylinders, %d physical cylinders\n"
|
2006-12-07 00:25:39 +01:00
|
|
|
"%d extra sects/cyl, interleave %d:1\n"
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
"Label ID: %s\n"
|
|
|
|
"Volume ID: %s\n"
|
2006-12-07 00:25:39 +01:00
|
|
|
"Units = %s of %d * 512 bytes\n\n"),
|
2013-02-04 17:33:49 +01:00
|
|
|
cxt->dev_path, cxt->geom.heads, cxt->geom.sectors, be16_to_cpu(sunlabel->rpm),
|
|
|
|
cxt->geom.cylinders, be16_to_cpu(sunlabel->acyl),
|
|
|
|
be16_to_cpu(sunlabel->pcyl),
|
|
|
|
be16_to_cpu(sunlabel->apc),
|
|
|
|
be16_to_cpu(sunlabel->intrlv),
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
sunlabel->label_id,
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->vtoc.volume_id,
|
2013-02-11 16:38:20 +01:00
|
|
|
fdisk_context_get_unit(cxt, PLURAL),
|
|
|
|
fdisk_context_get_units_per_sector(cxt));
|
2006-12-07 00:25:35 +01:00
|
|
|
else
|
2006-12-07 00:25:39 +01:00
|
|
|
printf(
|
2012-06-17 18:10:33 +02:00
|
|
|
_("\nDisk %s (Sun disk label): %u heads, %llu sectors, %llu cylinders\n"
|
2006-12-07 00:25:39 +01:00
|
|
|
"Units = %s of %d * 512 bytes\n\n"),
|
2012-06-17 18:10:33 +02:00
|
|
|
cxt->dev_path, cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders,
|
2013-02-11 16:38:20 +01:00
|
|
|
fdisk_context_get_unit(cxt, PLURAL),
|
|
|
|
fdisk_context_get_units_per_sector(cxt));
|
2006-12-07 00:25:35 +01:00
|
|
|
|
2006-12-07 00:25:39 +01:00
|
|
|
printf(_("%*s Flag Start End Blocks Id System\n"),
|
|
|
|
w + 1, _("Device"));
|
2013-01-18 12:47:27 +01:00
|
|
|
for (i = 0 ; i < cxt->label->nparts_max; i++) {
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
struct sun_partition *part = &sunlabel->partitions[i];
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_info *info = &sunlabel->vtoc.infos[i];
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
|
|
|
if (part->num_sectors) {
|
2013-02-04 17:33:49 +01:00
|
|
|
uint32_t start = be32_to_cpu(part->start_cylinder) * cxt->geom.heads * cxt->geom.sectors;
|
|
|
|
uint32_t len = be32_to_cpu(part->num_sectors);
|
2012-09-25 12:12:28 +02:00
|
|
|
struct fdisk_parttype *t = fdisk_get_partition_type(cxt, i);
|
2012-09-25 10:23:36 +02:00
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
printf(
|
2010-02-26 16:06:18 +01:00
|
|
|
"%s %c%c %9lu %9lu %9lu%c %2x %s\n",
|
2012-05-21 22:28:03 +02:00
|
|
|
/* device */ partname(cxt->dev_path, i+1, w),
|
2013-02-04 18:29:27 +01:00
|
|
|
/* flags */ be16_to_cpu(info->flags) & SUN_FLAG_UNMNT ? 'u' : ' ',
|
|
|
|
be16_to_cpu(info->flags) & SUN_FLAG_RONLY ? 'r' : ' ',
|
2013-02-11 16:38:20 +01:00
|
|
|
/* start */ (unsigned long) scround(cxt, start),
|
|
|
|
/* end */ (unsigned long) scround(cxt, start+len),
|
2010-02-26 16:06:18 +01:00
|
|
|
/* odd flag on end */ (unsigned long) len / 2, len & 1 ? '+' : ' ',
|
2012-09-25 12:12:28 +02:00
|
|
|
/* type id */ t->type,
|
|
|
|
/* type name */ t->name);
|
|
|
|
|
|
|
|
fdisk_free_parttype(t);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 11:41:58 +01:00
|
|
|
|
2012-06-03 20:15:17 +02:00
|
|
|
void sun_set_alt_cyl(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-02-07 11:41:58 +01:00
|
|
|
uintmax_t res;
|
|
|
|
int rc = fdisk_ask_number(cxt, 0, /* low */
|
|
|
|
be16_to_cpu(sunlabel->acyl), /* default */
|
|
|
|
65535, /* high */
|
|
|
|
_("Number of alternate cylinders"), /* query */
|
|
|
|
&res); /* result */
|
|
|
|
if (!rc)
|
|
|
|
sunlabel->acyl = cpu_to_be16(res);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2012-06-17 18:10:07 +02:00
|
|
|
void sun_set_ncyl(struct fdisk_context *cxt, int cyl)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-02-04 17:33:49 +01:00
|
|
|
sunlabel->ncyl = cpu_to_be16(cyl);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2012-06-03 20:15:17 +02:00
|
|
|
void sun_set_xcyl(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-02-07 11:41:58 +01:00
|
|
|
uintmax_t res;
|
|
|
|
int rc = fdisk_ask_number(cxt, 0, /* low */
|
|
|
|
be16_to_cpu(sunlabel->apc), /* default */
|
|
|
|
cxt->geom.sectors, /* high */
|
|
|
|
_("Extra sectors per cylinder"), /* query */
|
|
|
|
&res); /* result */
|
|
|
|
if (!rc)
|
|
|
|
sunlabel->apc = cpu_to_be16(res);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2012-06-03 20:15:17 +02:00
|
|
|
void sun_set_ilfact(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-02-07 11:41:58 +01:00
|
|
|
uintmax_t res;
|
|
|
|
int rc = fdisk_ask_number(cxt, 1, /* low */
|
|
|
|
be16_to_cpu(sunlabel->intrlv), /* default */
|
|
|
|
32, /* high */
|
|
|
|
_("Interleave factor"), /* query */
|
|
|
|
&res); /* result */
|
|
|
|
if (!rc)
|
|
|
|
sunlabel->intrlv = cpu_to_be16(res);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2012-06-03 20:15:17 +02:00
|
|
|
void sun_set_rspeed(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-02-07 11:41:58 +01:00
|
|
|
uintmax_t res;
|
|
|
|
int rc = fdisk_ask_number(cxt, 1, /* low */
|
|
|
|
be16_to_cpu(sunlabel->rpm), /* default */
|
|
|
|
USHRT_MAX, /* high */
|
|
|
|
_("Rotation speed (rpm)"), /* query */
|
|
|
|
&res); /* result */
|
|
|
|
if (!rc)
|
|
|
|
sunlabel->rpm = cpu_to_be16(res);
|
|
|
|
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2012-06-03 20:15:17 +02:00
|
|
|
void sun_set_pcylcount(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2013-02-07 11:41:58 +01:00
|
|
|
uintmax_t res;
|
|
|
|
int rc = fdisk_ask_number(cxt, 0, /* low */
|
|
|
|
be16_to_cpu(sunlabel->pcyl), /* default */
|
|
|
|
USHRT_MAX, /* high */
|
|
|
|
_("Number of physical cylinders"), /* query */
|
|
|
|
&res); /* result */
|
|
|
|
if (!rc)
|
|
|
|
sunlabel->pcyl = cpu_to_be16(res);
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
static int sun_write_disklabel(struct fdisk_context *cxt)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel;
|
2013-01-18 14:43:00 +01:00
|
|
|
unsigned short *ush;
|
2006-12-07 00:25:35 +01:00
|
|
|
unsigned short csum = 0;
|
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
sunlabel = self_disklabel(cxt);
|
2013-01-18 14:43:00 +01:00
|
|
|
ush = (unsigned short *) sunlabel;
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
while(ush < (unsigned short *)(&sunlabel->csum))
|
2006-12-07 00:25:35 +01:00
|
|
|
csum ^= *ush++;
|
2013-02-04 18:29:27 +01:00
|
|
|
sunlabel->csum = csum;
|
2012-05-21 22:28:03 +02:00
|
|
|
if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
|
2012-07-23 18:47:42 +02:00
|
|
|
return -errno;
|
2012-05-21 22:28:03 +02:00
|
|
|
if (write(cxt->dev_fd, sunlabel, SECTOR_SIZE) != SECTOR_SIZE)
|
2012-07-23 18:47:42 +02:00
|
|
|
return -errno;
|
|
|
|
|
|
|
|
return 0;
|
2006-12-07 00:25:35 +01:00
|
|
|
}
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
|
2012-12-11 18:04:25 +01:00
|
|
|
static struct fdisk_parttype *sun_get_parttype(
|
|
|
|
struct fdisk_context *cxt,
|
2013-01-22 18:05:18 +01:00
|
|
|
size_t n)
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel = self_disklabel(cxt);
|
2012-09-25 12:12:28 +02:00
|
|
|
struct fdisk_parttype *t;
|
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
if (n >= cxt->label->nparts_max)
|
2012-09-25 12:12:28 +02:00
|
|
|
return NULL;
|
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
t = fdisk_get_parttype_from_code(cxt, be16_to_cpu(sunlabel->vtoc.infos[n].id));
|
2012-09-25 12:12:28 +02:00
|
|
|
if (!t)
|
2013-02-04 18:29:27 +01:00
|
|
|
t = fdisk_new_unknown_parttype(be16_to_cpu(sunlabel->vtoc.infos[n].id), NULL);
|
2012-09-25 12:12:28 +02:00
|
|
|
return t;
|
fdisk: many significant improvements and fixes to Sun label handling
1) Properly describe the exact layout and fields of the sun disk
label. Several fields were incorrectly mentioned and others
wrongly sized.
2) Properly set the version, sane, and num_partitions fields.
Because we weren't doing this, programs such as Solaris's format
and the Solaris kernel itself refused to recognize our disk labels
as valid.
3) Move SSWAP*() macros into fdisksunlabel.c as there is no reason
for them to be exposed to the rest of fdisk.
4) Kill the sun_predefined_drives array hack and assosciated code.
Instead size the disk and figure out the geometry properly just
like the SGI and MSDOS partition handling do, by means of the
HD_GETGEO ioctl() and disksize().
5) If the disk label read is found to not have the proper values
set in version, sane, or num_partitions, fix them, recompute the
label checksum, dirty the disk label, and let the user know what
we did and that the fixed values will be written out if they 'w'.
This gives users an easy way to fix up disk labels created by
disk labelling programs which had this bug.
6) Create a sun_sys_getid() function so that fdisk.c does not need
to reference the sun disk label details directly, just like the
SGI code does.
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-06-29 15:50:21 -07:00
|
|
|
}
|
2012-07-08 23:40:27 +02:00
|
|
|
|
2012-12-11 18:04:25 +01:00
|
|
|
static int sun_set_parttype(
|
|
|
|
struct fdisk_context *cxt,
|
2013-01-22 18:05:18 +01:00
|
|
|
size_t i,
|
2012-12-11 18:04:25 +01:00
|
|
|
struct fdisk_parttype *t)
|
2012-09-26 13:30:44 +02:00
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel;
|
2012-09-26 13:30:44 +02:00
|
|
|
struct sun_partition *part;
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_info *info;
|
2012-09-26 13:30:44 +02:00
|
|
|
|
2013-01-18 12:47:27 +01:00
|
|
|
assert(cxt);
|
2013-01-22 18:05:18 +01:00
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-18 12:47:27 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
sunlabel = self_disklabel(cxt);
|
2013-01-18 14:43:00 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
if (i >= cxt->label->nparts_max || !t || t->type > UINT16_MAX)
|
2012-09-26 13:30:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-02-04 18:29:27 +01:00
|
|
|
if (i == 2 && t->type != SUN_TAG_WHOLEDISK)
|
2013-02-08 10:48:15 +01:00
|
|
|
fdisk_info(cxt, _("Consider leaving partition 3 as Whole disk (5),\n"
|
|
|
|
"as SunOS/Solaris expects it and even Linux likes it.\n"));
|
2012-09-26 13:30:44 +02:00
|
|
|
|
|
|
|
part = &sunlabel->partitions[i];
|
2013-02-04 18:29:27 +01:00
|
|
|
info = &sunlabel->vtoc.infos[i];
|
2012-09-26 13:30:44 +02:00
|
|
|
|
|
|
|
if (t->type == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
|
2013-02-11 11:41:47 +01:00
|
|
|
int yes, rc;
|
|
|
|
rc = fdisk_ask_yesno(cxt,
|
2012-09-26 13:30:44 +02:00
|
|
|
_("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"
|
2013-02-11 11:41:47 +01:00
|
|
|
"Are you sure you want to tag the partition as Linux swap?"), &yes);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (!yes)
|
2012-09-26 13:30:44 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (t->type) {
|
|
|
|
case SUN_TAG_SWAP:
|
|
|
|
case SUN_TAG_LINUX_SWAP:
|
|
|
|
/* swaps are not mountable by default */
|
2013-02-04 18:29:27 +01:00
|
|
|
info->flags |= cpu_to_be16(SUN_FLAG_UNMNT);
|
2012-09-26 13:30:44 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* assume other types are mountable;
|
|
|
|
user can change it anyway */
|
2013-02-04 18:29:27 +01:00
|
|
|
info->flags &= ~cpu_to_be16(SUN_FLAG_UNMNT);
|
2012-09-26 13:30:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-02-04 18:29:27 +01:00
|
|
|
info->id = cpu_to_be16(t->type);
|
2012-09-26 13:30:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-03 16:22:17 +01:00
|
|
|
|
2013-02-11 16:38:20 +01:00
|
|
|
static int sun_reset_alignment(struct fdisk_context *cxt __attribute__((__unused__)))
|
2012-12-03 16:22:17 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-21 17:10:23 +01:00
|
|
|
|
|
|
|
static int sun_get_partition_status(
|
|
|
|
struct fdisk_context *cxt,
|
2013-01-22 18:05:18 +01:00
|
|
|
size_t i,
|
2013-01-21 17:10:23 +01:00
|
|
|
int *status)
|
|
|
|
{
|
2013-02-04 18:29:27 +01:00
|
|
|
struct sun_disklabel *sunlabel;
|
2013-01-22 18:05:18 +01:00
|
|
|
|
|
|
|
assert(cxt);
|
|
|
|
assert(cxt->label);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
2013-01-21 17:10:23 +01:00
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
if (!status || i >= cxt->label->nparts_max)
|
2013-01-21 17:10:23 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-01-22 18:05:18 +01:00
|
|
|
sunlabel = self_disklabel(cxt);
|
2013-01-21 17:10:23 +01:00
|
|
|
*status = FDISK_PARTSTAT_NONE;
|
|
|
|
|
|
|
|
if (sunlabel->partitions[i].num_sectors)
|
|
|
|
*status = FDISK_PARTSTAT_USED;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-11 12:56:27 +01:00
|
|
|
const struct fdisk_label_operations sun_operations =
|
2012-07-08 23:40:27 +02:00
|
|
|
{
|
2012-12-11 12:56:27 +01:00
|
|
|
.probe = sun_probe_label,
|
|
|
|
.write = sun_write_disklabel,
|
|
|
|
.verify = sun_verify_disklabel,
|
|
|
|
.create = sun_create_disklabel,
|
|
|
|
.part_add = sun_add_partition,
|
|
|
|
.part_delete = sun_delete_partition,
|
|
|
|
.part_get_type = sun_get_parttype,
|
|
|
|
.part_set_type = sun_set_parttype,
|
2013-01-21 17:10:23 +01:00
|
|
|
|
|
|
|
.part_get_status = sun_get_partition_status,
|
|
|
|
|
|
|
|
.reset_alignment = sun_reset_alignment,
|
2012-07-08 23:40:27 +02:00
|
|
|
};
|
2012-12-11 12:56:27 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* allocates SUN label driver
|
|
|
|
*/
|
|
|
|
struct fdisk_label *fdisk_new_sun_label(struct fdisk_context *cxt)
|
|
|
|
{
|
|
|
|
struct fdisk_label *lb;
|
|
|
|
struct fdisk_sun_label *sun;
|
|
|
|
|
|
|
|
assert(cxt);
|
|
|
|
|
|
|
|
sun = calloc(1, sizeof(*sun));
|
|
|
|
if (!sun)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* initialize generic part of the driver */
|
|
|
|
lb = (struct fdisk_label *) sun;
|
|
|
|
lb->name = "sun";
|
2012-12-11 18:30:03 +01:00
|
|
|
lb->id = FDISK_DISKLABEL_SUN;
|
2012-12-11 12:56:27 +01:00
|
|
|
lb->op = &sun_operations;
|
|
|
|
lb->parttypes = sun_parttypes;
|
|
|
|
lb->nparttypes = ARRAY_SIZE(sun_parttypes);
|
|
|
|
|
|
|
|
return lb;
|
|
|
|
}
|