{
struct cfdisk_menuitem *d, *cm;
size_t i = 0, nitems, idx = 0;
- struct fdisk_parttype *types, *t = NULL;
+ struct fdisk_parttype *t = NULL;
struct fdisk_label *lb;
- int has_typestr = 0;
+ int codetypes = 0;
DBG(UI, ul_debug("asking for parttype."));
/* create cfdisk menu according to label types, note that the
* last cm[] item has to be empty -- so nitems + 1 */
- if (fdisk_label_get_parttypes(lb, &types, &nitems) || !nitems)
+ nitems = fdisk_label_get_nparttypes(lb);
+ if (!nitems)
return NULL;
cm = xcalloc(nitems + 1, sizeof(struct cfdisk_menuitem));
if (!cm)
return NULL;
- has_typestr = fdisk_label_is_parttype_string(lb);
+ codetypes = fdisk_label_has_code_parttypes(lb);
for (i = 0; i < nitems; i++) {
- struct fdisk_parttype *x = &types[i];
+ const struct fdisk_parttype *x = fdisk_label_get_parttype(lb, i);
char *name;
- if (!x || !x->name)
- continue;
- cm[i].userdata = x;
- if (!has_typestr)
- xasprintf(&name, "%2x %s", x->type, _(x->name));
+ cm[i].userdata = (void *) x;
+ if (codetypes)
+ xasprintf(&name, "%2x %s",
+ fdisk_parttype_get_code(x),
+ _(fdisk_parttype_get_name(x)));
else {
- name = (char *) _(x->name);
- cm[i].desc = x->typestr;
+ name = (char *) _(fdisk_parttype_get_name(x));
+ cm[i].desc = fdisk_parttype_get_string(x);
}
cm[i].name = name;
if (x == cur)
done:
menu_pop(cf);
- if (!has_typestr) {
+ if (codetypes) {
for (i = 0; i < nitems; i++)
free((char *) cm[i].name);
}
struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt)
{
const char *q;
- struct fdisk_label *lb = fdisk_get_label(cxt, NULL);
+ struct fdisk_label *lb;
+
+ assert(cxt);
+ lb = fdisk_get_label(cxt, NULL);
- if (!cxt || !cxt->label || !cxt->label->nparttypes)
+ if (!lb)
return NULL;
- q = fdisk_label_is_parttype_string(lb) ?
+ q = fdisk_label_has_code_parttypes(lb) ?
_("Partition type (type L to list all types): ") :
_("Hex code (type L to list all codes): ");
do {
if (buf[1] == '\0' && toupper(*buf) == 'L')
list_partition_types(cxt);
else if (*buf)
- return fdisk_parse_parttype(cxt, buf);
+ return fdisk_label_parse_parttype(lb, buf);
} while (1);
return NULL;
void list_partition_types(struct fdisk_context *cxt)
{
- struct fdisk_parttype *types;
size_t ntypes = 0;
+ struct fdisk_label *lb = fdisk_get_label(cxt, NULL);
- if (!cxt || !cxt->label || !cxt->label->parttypes)
+ assert(cxt);
+ lb = fdisk_get_label(cxt, NULL);
+ if (!lb)
+ return;
+ ntypes = fdisk_label_get_nparttypes(lb);
+ if (!ntypes)
return;
- types = cxt->label->parttypes;
- ntypes = cxt->label->nparttypes;
-
- if (types[0].typestr == NULL) {
+ if (fdisk_label_has_code_parttypes(lb)) {
/*
* Prints in 4 columns in format <hex> <name>
*/
int i;
size = ntypes;
- if (types[ntypes - 1].name == NULL)
- size--;
for (i = 3; i >= 0; i--)
last[3 - i] = done += (size + i - done) / (i + 1);
#define NAME_WIDTH 15
char name[NAME_WIDTH * MB_LEN_MAX];
size_t width = NAME_WIDTH;
- struct fdisk_parttype *t = &types[next];
+ const struct fdisk_parttype *t = fdisk_label_get_parttype(lb, next);
size_t ret;
if (t->name) {
- printf("%c%2x ", i ? ' ' : '\n', t->type);
- ret = mbsalign(_(t->name), name, sizeof(name),
- &width, MBS_ALIGN_LEFT, 0);
+ printf("%c%2x ", i ? ' ' : '\n',
+ fdisk_parttype_get_code(t));
+ ret = mbsalign(_(fdisk_parttype_get_name(t)),
+ name, sizeof(name),
+ &width, MBS_ALIGN_LEFT, 0);
if (ret == (size_t)-1 || ret >= sizeof(name))
- printf("%-15.15s", _(t->name));
+ printf("%-15.15s",
+ _(fdisk_parttype_get_name(t)));
else
fputs(name, stdout);
}
/*
* Prints 1 column in format <idx> <name> <typestr>
*/
- struct fdisk_parttype *t;
size_t i;
- for (i = 0, t = types; t && i < ntypes; t++, i++) {
- if (t->name)
- printf("%3zu %-30s %s\n", i + 1,
- t->name, t->typestr);
+ for (i = 0; i < ntypes; i++) {
+ const struct fdisk_parttype *t = fdisk_label_get_parttype(lb, i);
+ printf("%3zu %-30s %s\n", i + 1,
+ fdisk_parttype_get_name(t),
+ fdisk_parttype_get_string(t));
}
}
putchar('\n');
if (fdisk_set_partition_type(cxt, i, t) == 0)
fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
_("Changed type of partition '%s' to '%s'."),
- old, t ? t->name : _("Unknown"));
+ old, t ? fdisk_parttype_get_name(t) : _("Unknown"));
else
fdisk_info(cxt,
_("Type of partition %zu is unchanged: %s."),
struct bsd_partition *p)
{
struct fdisk_parttype *t
- = fdisk_get_parttype_from_code(cxt, p->p_fstype);
+ = fdisk_label_get_parttype_from_code(cxt->label, p->p_fstype);
return t ? : fdisk_new_unknown_parttype(p->p_fstype, NULL);
}
struct bsd_partition *p;
struct bsd_disklabel *d = self_disklabel(cxt);
- if (partnum >= d->d_npartitions || !t || t->type > UINT8_MAX)
+ if (partnum >= d->d_npartitions || !t || t->code > UINT8_MAX)
return -EINVAL;
p = &d->d_partitions[partnum];
- if (t->type == p->p_fstype)
+ if (t->code == p->p_fstype)
return 0;
- p->p_fstype = t->type;
+ p->p_fstype = t->code;
fdisk_label_set_changed(cxt->label, 1);
return 0;
}
lb->id = FDISK_DISKLABEL_BSD;
lb->op = &bsd_operations;
lb->parttypes = bsd_fstypes;
- lb->nparttypes = ARRAY_SIZE(bsd_fstypes);
+ lb->nparttypes = ARRAY_SIZE(bsd_fstypes) - 1;
lb->fields = bsd_fields;
lb->nfields = ARRAY_SIZE(bsd_fields);
struct dos_partition *p)
{
struct fdisk_parttype *t
- = fdisk_get_parttype_from_code(cxt, p->sys_ind);
+ = fdisk_label_get_parttype_from_code(cxt->label, p->sys_ind);
return t ? : fdisk_new_unknown_parttype(p->sys_ind, NULL);
}
dos_partition_set_size(p, stop - start + 1);
if (!doext) {
- struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
+ struct fdisk_parttype *t =
+ fdisk_label_get_parttype_from_code(cxt->label, sysid);
fdisk_info_new_partition(cxt, i + 1, start, stop, t);
}
if (is_dos_compatible(cxt) && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023))
DBG(LABEL, ul_debug("DOS: adding partition %zu", n));
- sys = pa && pa->type ? pa->type->type : MBR_LINUX_DATA_PARTITION;
+ sys = pa && pa->type ? pa->type->code : MBR_LINUX_DATA_PARTITION;
if (is_used_partition(p)) {
fdisk_warnx(cxt, _("Partition %zu is already defined. "
struct fdisk_partition xpa = { .type = NULL };
struct fdisk_parttype *t;
- t = fdisk_get_parttype_from_code(cxt,
+ t = fdisk_label_get_parttype_from_code(cxt->label,
MBR_DOS_EXTENDED_PARTITION);
if (!pa)
pa = &xpa;
assert(cxt->label);
assert(fdisk_is_label(cxt, DOS));
- if (partnum >= cxt->label->nparts_max || !t || t->type > UINT8_MAX)
+ if (partnum >= cxt->label->nparts_max || !t || t->code > UINT8_MAX)
return -EINVAL;
p = self_partition(cxt, partnum);
- if (t->type == p->sys_ind)
+ if (t->code == p->sys_ind)
return 0;
- if (IS_EXTENDED(p->sys_ind) || IS_EXTENDED(t->type)) {
+ if (IS_EXTENDED(p->sys_ind) || IS_EXTENDED(t->code)) {
fdisk_warnx(cxt, _("You cannot change a partition into an "
"extended one or vice versa. Delete it first."));
return -EINVAL;
}
- if (is_dos_partition(t->type) || is_dos_partition(p->sys_ind))
+ if (is_dos_partition(t->code) || is_dos_partition(p->sys_ind))
fdisk_info(cxt, _("If you have created or modified any DOS 6.x "
"partitions, please see the fdisk documentation for additional "
"information."));
- if (!t->type)
+ if (!t->code)
fdisk_warnx(cxt, _("Type 0 means free space to many systems. "
"Having partitions of type 0 is probably unwise."));
- p->sys_ind = t->type;
+ p->sys_ind = t->code;
partition_set_changed(cxt, partnum, 1);
return 0;
lb->id = FDISK_DISKLABEL_DOS;
lb->op = &dos_operations;
lb->parttypes = dos_parttypes;
- lb->nparttypes = ARRAY_SIZE(dos_parttypes);
+ lb->nparttypes = ARRAY_SIZE(dos_parttypes) - 1;
lb->fields = dos_fields;
lb->nfields = ARRAY_SIZE(dos_fields);
* Partition types
*/
struct fdisk_parttype {
- unsigned int type; /* type as number or zero */
+ unsigned int code; /* type as number or zero */
const char *name; /* description */
char *typestr; /* type as string or NULL */
char str[37];
guid_to_string(&e->type, str);
- t = fdisk_get_parttype_from_string(cxt, str);
+ t = fdisk_label_get_parttype_from_string(cxt->label, str);
return t ? : fdisk_new_unknown_parttype(0, str);
}
return lb ? lb->name : NULL;
}
-/**
- * fdisk_label_get_parttypes:
- * @lb: label
- * @types: returns array with supported partition types
- * @ntypes: returns number of types
- *
- * Returns: 0 on success, <0 on error.
- */
-int fdisk_label_get_parttypes(struct fdisk_label *lb,
- struct fdisk_parttype **types,
- size_t *ntypes)
-{
- if (!lb)
- return -EINVAL;
- if (types)
- *types = lb->parttypes;
- if (ntypes)
- *ntypes = lb->nparttypes;
- return 0;
-}
-
-/**
- * fdisk_label_is_parttype_string:
- * @lb: label
- *
- * Returns: 1 if the label uses strings as partition type
- * identifiers (e.g. GPT UUIDS) or 0.
- */
-int fdisk_label_is_parttype_string(struct fdisk_label *lb)
-{
- assert(lb);
-
- if (lb->parttypes && lb->parttypes[0].typestr)
- return 1;
- return 0;
-}
-
/**
* fdisk_label_require_geometry:
* @lb: label
const char *fdisk_get_devname(struct fdisk_context *cxt);
/* parttype.c */
-extern struct fdisk_parttype *fdisk_get_parttype_from_code(struct fdisk_context *cxt,
- unsigned int code);
-extern struct fdisk_parttype *fdisk_get_parttype_from_string(struct fdisk_context *cxt,
- const char *str);
-extern struct fdisk_parttype *fdisk_parse_parttype(struct fdisk_context *cxt, const char *str);
-
-extern struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int type, const char *typestr);
-extern void fdisk_free_parttype(struct fdisk_parttype *type);
-
-extern int fdisk_is_parttype_string(struct fdisk_context *cxt);
+const struct fdisk_parttype *fdisk_label_get_parttype(struct fdisk_label *lb, size_t n);
+size_t fdisk_label_get_nparttypes(struct fdisk_label *lb);
+
+int fdisk_label_has_code_parttypes(struct fdisk_label *lb);
+struct fdisk_parttype *fdisk_label_get_parttype_from_code(
+ struct fdisk_label *lb,
+ unsigned int code);
+
+struct fdisk_parttype *fdisk_label_get_parttype_from_string(
+ struct fdisk_label *lb,
+ const char *str);
+struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int code,
+ const char *typestr);
+struct fdisk_parttype *fdisk_label_parse_parttype(
+ struct fdisk_label *lb,
+ const char *str);
+void fdisk_free_parttype(struct fdisk_parttype *t);
+
+const char *fdisk_parttype_get_string(const struct fdisk_parttype *t);
+unsigned int fdisk_parttype_get_code(const struct fdisk_parttype *t);
+const char *fdisk_parttype_get_name(const struct fdisk_parttype *t);
/* label.c */
enum {
extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
struct fdisk_parttype *t);
-extern int fdisk_label_get_parttypes(struct fdisk_label *lb,
- struct fdisk_parttype **types,
- size_t *ntypes);
-extern int fdisk_label_is_parttype_string(struct fdisk_label *lb);
-
extern int fdisk_label_get_fields_ids(
struct fdisk_label *lb,
struct fdisk_context *cxt,
p = pa->type && pa->type->name ? strdup(pa->type->name) : NULL;
break;
case FDISK_FIELD_TYPEID:
- if (pa->type && pa->type->typestr)
- rc = asprintf(&p, "%s", pa->type->typestr);
+ if (pa->type && fdisk_parttype_get_string(pa->type))
+ rc = asprintf(&p, "%s", fdisk_parttype_get_string(pa->type));
else if (pa->type)
- rc = asprintf(&p, "%x", pa->type->type);
+ rc = asprintf(&p, "%x", fdisk_parttype_get_code(pa->type));
break;
case FDISK_FIELD_UUID:
p = pa->uuid ? strdup(pa->uuid) : NULL;
#include "fdiskP.h"
+
+/**
+ * fdisk_label_get_nparttypes:
+ * @lb: label
+ *
+ * Returns: number of types supported by label.
+ */
+size_t fdisk_label_get_nparttypes(struct fdisk_label *lb)
+{
+ if (!lb)
+ return 0;
+ return lb->nparttypes;
+}
+
+/**
+ * fdisk_label_get_parttype:
+ * @lb: label
+ * @n: number
+ *
+ * Returns: return parttype
+ */
+const struct fdisk_parttype *fdisk_label_get_parttype(struct fdisk_label *lb, size_t n)
+{
+ if (!lb || n >= lb->nparttypes)
+ return NULL;
+ return &lb->parttypes[n];
+}
+
/**
- * fdisk_get_parttype_from_code:
- * @cxt: fdisk context
+ * fdisk_label_has_code_parttypes:
+ * @lb: label
+ *
+ * Returns: 1 if the label uses code as partition type
+ * identifiers (e.g. MBR) or 0.
+ */
+int fdisk_label_has_code_parttypes(struct fdisk_label *lb)
+{
+ assert(lb);
+
+ if (lb->parttypes && lb->parttypes[0].typestr)
+ return 0;
+ return 1;
+}
+
+
+/**
+ * fdisk_label_get_parttype_from_code:
+ * @lb: label
* @code: code to search for
*
* Search in lable-specific table of supported partition types by code.
*
- * Returns partition type or NULL upon failure or invalid @code.
+ * Returns: partition type or NULL upon failure or invalid @code.
*/
-struct fdisk_parttype *fdisk_get_parttype_from_code(
- struct fdisk_context *cxt,
+struct fdisk_parttype *fdisk_label_get_parttype_from_code(
+ struct fdisk_label *lb,
unsigned int code)
{
size_t i;
- if (!cxt->label->nparttypes)
+ assert(lb);
+
+ if (!lb->nparttypes)
return NULL;
- for (i = 0; i < cxt->label->nparttypes; i++)
- if (cxt->label->parttypes[i].type == code)
- return &cxt->label->parttypes[i];
+ for (i = 0; i < lb->nparttypes; i++)
+ if (lb->parttypes[i].code == code)
+ return &lb->parttypes[i];
return NULL;
}
/**
- * fdisk_get_parttype_from_string:
- * @cxt: fdisk context
+ * fdisk_label_get_parttype_from_string:
+ * @lb: label
* @str: string to search for
*
* Search in lable-specific table of supported partition types by typestr.
*
- * Returns partition type or NULL upon failure or invalid @str.
+ * Returns: partition type or NULL upon failure or invalid @str.
*/
-struct fdisk_parttype *fdisk_get_parttype_from_string(
- struct fdisk_context *cxt,
+struct fdisk_parttype *fdisk_label_get_parttype_from_string(
+ struct fdisk_label *lb,
const char *str)
{
size_t i;
- if (!cxt->label->nparttypes)
+ assert(lb);
+
+ if (!lb->nparttypes)
return NULL;
- for (i = 0; i < cxt->label->nparttypes; i++)
- if (cxt->label->parttypes[i].typestr
- &&strcasecmp(cxt->label->parttypes[i].typestr, str) == 0)
- return &cxt->label->parttypes[i];
+ for (i = 0; i < lb->nparttypes; i++)
+ if (lb->parttypes[i].typestr
+ && strcasecmp(lb->parttypes[i].typestr, str) == 0)
+ return &lb->parttypes[i];
return NULL;
}
/**
* fdisk_new_unknown_parttype:
- * @type: type as number
+ * @code: type as number
* @typestr: type as string
* Allocates new 'unknown' partition type. Use fdisk_free_parttype() to
* deallocate.
*
- * Returns newly allocated partition type, or NULL upon failure.
+ * Returns: newly allocated partition type, or NULL upon failure.
*/
-struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int type,
+struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int code,
const char *typestr)
{
struct fdisk_parttype *t;
}
}
t->name = _("unknown");
- t->type = type;
+ t->code = code;
t->flags |= FDISK_PARTTYPE_UNKNOWN | FDISK_PARTTYPE_ALLOCATED;
DBG(PARTTYPE, ul_debugobj(t, "allocated new unknown type"));
}
/**
- * fdisk_parse_parttype:
- * @cxt: fdisk context
+ * fdisk_label_parse_parttype:
+ * @lb: label
* @str: string to parse from
*
- * Returns pointer to static table of the partition types, or newly allocated
+ * Returns: pointer to static table of the partition types, or newly allocated
* partition type for unknown types. It's safe to call fdisk_free_parttype()
* for all results.
*/
-struct fdisk_parttype *fdisk_parse_parttype(
- struct fdisk_context *cxt,
+struct fdisk_parttype *fdisk_label_parse_parttype(
+ struct fdisk_label *lb,
const char *str)
{
struct fdisk_parttype *types, *ret;
unsigned int code = 0;
char *typestr = NULL, *end = NULL;
- if (!cxt->label->nparttypes)
+ assert(lb);
+
+ if (!lb->nparttypes)
return NULL;
- DBG(CXT, ul_debugobj(cxt, "parsing '%s' partition type", str));
+ DBG(LABEL, ul_debugobj(lb, "parsing '%s' partition type", str));
- types = cxt->label->parttypes;
+ types = lb->parttypes;
if (types[0].typestr == NULL && isxdigit(*str)) {
code = strtol(str, &end, 16);
if (errno || *end != '\0') {
- DBG(CXT, ul_debugobj(cxt, "parsing failed: %m"));
+ DBG(LABEL, ul_debugobj(lb, "parsing failed: %m"));
return NULL;
}
- ret = fdisk_get_parttype_from_code(cxt, code);
+ ret = fdisk_label_get_parttype_from_code(lb, code);
if (ret)
goto done;
} else {
int i;
/* maybe specified by type string (e.g. UUID) */
- ret = fdisk_get_parttype_from_string(cxt, str);
+ ret = fdisk_label_get_parttype_from_string(lb, str);
if (ret)
goto done;
errno = 0;
i = strtol(str, &end, 0);
if (errno == 0 && *end == '\0' && i > 0
- && i - 1 < (int) cxt->label->nparttypes) {
+ && i - 1 < (int) lb->nparttypes) {
ret = &types[i - 1];
goto done;
}
ret = fdisk_new_unknown_parttype(code, typestr);
done:
- DBG(PARTTYPE, ul_debugobj(ret, "returns '%s' partition type", ret->name));
+ DBG(PARTTYPE, ul_debugobj(ret, "returns parsed '%s' partition type", ret->name));
return ret;
}
}
}
+const char *fdisk_parttype_get_string(const struct fdisk_parttype *t)
+{
+ assert(t);
+ return t->typestr && *t->typestr ? t->typestr : NULL;
+}
+
+unsigned int fdisk_parttype_get_code(const struct fdisk_parttype *t)
+{
+ assert(t);
+ return t->code;
+}
+
+const char *fdisk_parttype_get_name(const struct fdisk_parttype *t)
+{
+ assert(t);
+ return t->name;
+}
+
+
if (n >= cxt->label->nparts_max)
return NULL;
- t = fdisk_get_parttype_from_code(cxt, sgi_get_sysid(cxt, n));
+ t = fdisk_label_get_parttype_from_code(cxt->label, sgi_get_sysid(cxt, n));
return t ? : fdisk_new_unknown_parttype(sgi_get_sysid(cxt, n), NULL);
}
pa->start = start;
pa->end = start + len - (len ? 1 : 0);
- if (pa->type && pa->type->type == SGI_TYPE_ENTIRE_DISK)
+ if (pa->type && pa->type->code == SGI_TYPE_ENTIRE_DISK)
pa->wholedisk = 1;
pa->attrs = sgi_get_swappartition(cxt) == (int) n ? "swap" :
if (sgi_gaps(cxt) < 0) /* rebuild freelist */
fdisk_warnx(cxt, _("Partition overlap on the disk."));
if (length) {
- struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sys);
+ struct fdisk_parttype *t =
+ fdisk_label_get_parttype_from_code(cxt->label, sys);
fdisk_info_new_partition(cxt, i + 1, start, start + length, t);
}
char mesg[256];
unsigned int first = 0, last = 0;
struct fdisk_ask *ask;
- int sys = pa && pa->type ? pa->type->type : SGI_TYPE_XFS;
+ int sys = pa && pa->type ? pa->type->code : SGI_TYPE_XFS;
int rc;
size_t n;
{
struct sgi_disklabel *sgilabel;
- if (i >= cxt->label->nparts_max || !t || t->type > UINT32_MAX)
+ if (i >= cxt->label->nparts_max || !t || t->code > UINT32_MAX)
return -EINVAL;
if (sgi_get_num_sectors(cxt, i) == 0) /* caught already before, ... */ {
return -EINVAL;
}
- if ((i == 10 && t->type != SGI_TYPE_ENTIRE_DISK)
- || (i == 8 && t->type != 0))
+ if ((i == 10 && t->code != SGI_TYPE_ENTIRE_DISK)
+ || (i == 8 && t->code != 0))
fdisk_info(cxt, _("Consider leaving partition 9 as volume header (0), "
"and partition 11 as entire volume (6), "
"as IRIX expects it."));
- if (((t->type != SGI_TYPE_ENTIRE_DISK) && (t->type != SGI_TYPE_VOLHDR))
+ if (((t->code != SGI_TYPE_ENTIRE_DISK) && (t->code != SGI_TYPE_VOLHDR))
&& (sgi_get_start_sector(cxt, i) < 1)) {
int yes = 0;
fdisk_ask_yesno(cxt,
}
sgilabel = self_disklabel(cxt);
- sgilabel->partitions[i].type = cpu_to_be32(t->type);
+ sgilabel->partitions[i].type = cpu_to_be32(t->code);
return 0;
}
lb->id = FDISK_DISKLABEL_SGI;
lb->op = &sgi_operations;
lb->parttypes = sgi_parttypes;
- lb->nparttypes = ARRAY_SIZE(sgi_parttypes);
+ lb->nparttypes = ARRAY_SIZE(sgi_parttypes) - 1;
lb->fields = sgi_fields;
lb->nfields = ARRAY_SIZE(sgi_fields);
uint32_t start,uint32_t stop, uint16_t sysid)
{
struct sun_disklabel *sunlabel = self_disklabel(cxt);
- struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
+ struct fdisk_parttype *t =
+ fdisk_label_get_parttype_from_code(cxt->label, sysid);
sunlabel->vtoc.infos[i].id = cpu_to_be16(sysid);
sunlabel->vtoc.infos[i].flags = cpu_to_be16(0);
struct sun_info *info;
uint32_t start, stop, stop2;
int whole_disk = 0;
- int sys = pa && pa->type ? pa->type->type : SUN_TAG_LINUX_NATIVE;
+ int sys = pa && pa->type ? pa->type->code : SUN_TAG_LINUX_NATIVE;
int rc;
size_t n;
if (n >= cxt->label->nparts_max)
return NULL;
- t = fdisk_get_parttype_from_code(cxt, be16_to_cpu(sunlabel->vtoc.infos[n].id));
+ t = fdisk_label_get_parttype_from_code(cxt->label,
+ be16_to_cpu(sunlabel->vtoc.infos[n].id));
return t ? : fdisk_new_unknown_parttype(be16_to_cpu(sunlabel->vtoc.infos[n].id), NULL);
}
len = be32_to_cpu(part->num_sectors);
pa->type = sun_get_parttype(cxt, n);
- if (pa->type && pa->type->type == SUN_TAG_WHOLEDISK)
+ if (pa->type && pa->type->code == SUN_TAG_WHOLEDISK)
pa->wholedisk = 1;
if (flags & SUN_FLAG_UNMNT || flags & SUN_FLAG_RONLY) {
sunlabel = self_disklabel(cxt);
- if (i >= cxt->label->nparts_max || !t || t->type > UINT16_MAX)
+ if (i >= cxt->label->nparts_max || !t || t->code > UINT16_MAX)
return -EINVAL;
- if (i == 2 && t->type != SUN_TAG_WHOLEDISK)
+ if (i == 2 && t->code != SUN_TAG_WHOLEDISK)
fdisk_info(cxt, _("Consider leaving partition 3 as Whole disk (5),\n"
"as SunOS/Solaris expects it and even Linux likes it.\n"));
part = &sunlabel->partitions[i];
info = &sunlabel->vtoc.infos[i];
- if (t->type == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
+ if (t->code == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
int yes, rc;
rc = fdisk_ask_yesno(cxt,
_("It is highly recommended that the partition at offset 0\n"
return 1;
}
- switch (t->type) {
+ switch (t->code) {
case SUN_TAG_SWAP:
case SUN_TAG_LINUX_SWAP:
/* swaps are not mountable by default */
info->flags &= ~cpu_to_be16(SUN_FLAG_UNMNT);
break;
}
- info->id = cpu_to_be16(t->type);
+ info->id = cpu_to_be16(t->code);
return 0;
}
lb->id = FDISK_DISKLABEL_SUN;
lb->op = &sun_operations;
lb->parttypes = sun_parttypes;
- lb->nparttypes = ARRAY_SIZE(sun_parttypes);
+ lb->nparttypes = ARRAY_SIZE(sun_parttypes) - 1;
lb->fields = sun_fields;
lb->nfields = ARRAY_SIZE(sun_fields);
lb->flags |= FDISK_LABEL_FL_REQUIRE_GEOMETRY;