printf(" %c %s\n", menulist[i].command, menulist[i].description);
}
-static int
-get_sysid(struct fdisk_context *cxt, int i) {
- return (
- disklabel == SUN_LABEL ? sun_get_sysid(cxt, i) :
- disklabel == SGI_LABEL ? sgi_get_sysid(cxt, i) :
- ptes[i].part_table->sys_ind);
-}
-
void list_partition_types(struct fdisk_context *cxt)
{
struct fdisk_parttype *types;
{
int i;
struct fdisk_parttype *t, *org_t;
- struct partition *p;
i = get_existing_partition(cxt, 0, partitions);
-
if (i == -1)
return;
- p = ptes[i].part_table;
-
- /* TODO: add get_partition_type(xt, partn) to API */
- org_t = t = fdisk_get_parttype_from_code(cxt, get_sysid(cxt, i));
- /* if changing types T to 0 is allowed, then
- the reverse change must be allowed, too */
- if (!t && disklabel != SGI_LABEL && disklabel != SUN_LABEL && !get_nr_sects(p))
+ org_t = t = fdisk_get_partition_type(cxt, i);
+ if (!t)
printf(_("Partition %d does not exist yet!\n"), i + 1);
+
else while (1) {
t = read_partition_type(cxt);
continue;
if (disklabel != SGI_LABEL && disklabel != SUN_LABEL) {
- if (IS_EXTENDED (t->type) != IS_EXTENDED (p->sys_ind)) {
+ if (IS_EXTENDED (t->type) != IS_EXTENDED (t->type)) {
printf(_("You cannot change a partition into"
" an extended one or vice versa\n"
"Delete it first.\n"));
if (disklabel == SGI_LABEL) {
ptes[i].changed = sgi_change_sysid(cxt, i, t->type);
} else {
- p->sys_ind = t->type;
+ ptes[i].part_table->sys_ind = t->type;
ptes[i].changed = 1;
}
void (*part_add)(struct fdisk_context *cxt, int partnum, int parttype);
/* delete partition */
void (*part_delete)(struct fdisk_context *cxt, int partnum);
+ /* get partition type */
+ struct fdisk_parttype *(*part_get_type)(struct fdisk_context *cxt, int partnum);
+
};
/*
extern int fdisk_write_disklabel(struct fdisk_context *cxt);
extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
+extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum);
extern size_t fdisk_get_nparttypes(struct fdisk_context *cxt);
extern struct fdisk_parttype *fdisk_get_parttype_from_code(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);
/* prototypes for fdisk.c */
}
#endif /* __alpha__ */
+static struct fdisk_parttype *xbsd_get_parttype(struct fdisk_context *cxt, int n)
+{
+ struct fdisk_parttype *t;
+
+ if (n >= xbsd_dlabel.d_npartitions)
+ return NULL;
+
+ t = fdisk_get_parttype_from_code(cxt, xbsd_dlabel.d_partitions[n].p_fstype);
+ if (!t)
+ t = fdisk_new_unknown_parttype(xbsd_dlabel.d_partitions[n].p_fstype, NULL);
+ return t;
+}
+
const struct fdisk_label bsd_label =
{
.name = "bsd",
.create = xbsd_create_disklabel,
.part_add = xbsd_add_part,
.part_delete = xbsd_delete_part,
+ .part_get_type = xbsd_get_parttype,
};
return rc;
}
+static struct fdisk_parttype *dos_get_parttype(struct fdisk_context *cxt, int partnum)
+{
+ struct fdisk_parttype *t;
+ struct partition *p;
+
+ if (partnum >= partitions)
+ return NULL;
+
+ p = ptes[partnum].part_table;
+ t = fdisk_get_parttype_from_code(cxt, p->sys_ind);
+ if (!t)
+ t = fdisk_new_unknown_parttype(p->sys_ind, NULL);
+ return t;
+}
+
const struct fdisk_label dos_label =
{
.name = "dos",
.create = dos_create_disklabel,
.part_add = dos_add_partition,
.part_delete = dos_delete_partition,
+ .part_get_type = dos_get_parttype,
};
if (sgi_get_num_sectors(cxt, i) || debug) {
uint32_t start = sgi_get_start_sector(cxt, i);
uint32_t len = sgi_get_num_sectors(cxt, i);
- struct fdisk_parttype *t =
- fdisk_get_parttype_from_code(cxt, sgi_get_sysid(cxt, i));
+ struct fdisk_parttype *t = fdisk_get_partition_type(cxt, i);
kpi++; /* only count nonempty partitions */
printf(
/* start */ (long) scround(start),
/* end */ (long) scround(start+len)-1,
/* no odd flag on end */ (long) len,
-/* type id */ t ? t->type : sgi_get_sysid(cxt, i),
-/* type name */ t ? t->name : _("Unknown"));
+/* type id */ t->type,
+/* type name */ t->name);
+
+ fdisk_free_parttype(t);
}
}
printf(_("----- Bootinfo -----\nBootfile: %s\n"
return SSWAP32(sgilabel->partitions[i].num_sectors);
}
-int
+static int
sgi_get_sysid(struct fdisk_context *cxt, int i)
{
return SSWAP32(sgilabel->partitions[i].id);
return info;
}
+static struct fdisk_parttype *sgi_get_parttype(struct fdisk_context *cxt, int n)
+{
+ struct fdisk_parttype *t;
+
+ if (n >= partitions)
+ return NULL;
+
+ t = fdisk_get_parttype_from_code(cxt, sgi_get_sysid(cxt, n));
+ if (!t)
+ t = fdisk_new_unknown_parttype(sgi_get_sysid(cxt, n), NULL);
+ return t;
+}
+
const struct fdisk_label sgi_label =
{
.name = "sgi",
.create = sgi_create_disklabel,
.part_add = sgi_add_partition,
.part_delete = sgi_delete_partition,
+ .part_get_type = sgi_get_parttype,
};
extern int sgi_change_sysid(struct fdisk_context *cxt, int i, int sys);
extern unsigned int sgi_get_start_sector(struct fdisk_context *cxt, int i );
extern unsigned int sgi_get_num_sectors(struct fdisk_context *cxt, int i );
-extern int sgi_get_sysid(struct fdisk_context *cxt, int i );
extern void create_sgiinfo(struct fdisk_context *cxt);
extern void sgi_set_ilfact( void );
extern void sgi_set_rspeed( void );
if (part->num_sectors) {
uint32_t start = SSWAP32(part->start_cylinder) * cxt->geom.heads * cxt->geom.sectors;
uint32_t len = SSWAP32(part->num_sectors);
- struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, SSWAP16(tag->tag));
+ struct fdisk_parttype *t = fdisk_get_partition_type(cxt, i);
printf(
"%s %c%c %9lu %9lu %9lu%c %2x %s\n",
/* start */ (unsigned long) scround(start),
/* end */ (unsigned long) scround(start+len),
/* odd flag on end */ (unsigned long) len / 2, len & 1 ? '+' : ' ',
-/* type id */ SSWAP16(tag->tag),
-/* type name */ t ? t->name : _("Unknown"));
+/* type id */ t->type,
+/* type name */ t->name);
+
+ fdisk_free_parttype(t);
}
}
}
return 0;
}
-int sun_get_sysid(struct fdisk_context *cxt, int i)
+static struct fdisk_parttype *sun_get_parttype(struct fdisk_context *cxt, int n)
{
- return SSWAP16(sunlabel->part_tags[i].tag);
+ struct fdisk_parttype *t;
+
+ if (n >= partitions)
+ return NULL;
+
+ t = fdisk_get_parttype_from_code(cxt, SSWAP16(sunlabel->part_tags[n].tag));
+ if (!t)
+ t = fdisk_new_unknown_parttype(SSWAP16(sunlabel->part_tags[n].tag), NULL);
+ return t;
}
const struct fdisk_label sun_label =
.create = sun_create_disklabel,
.part_add = sun_add_partition,
.part_delete = sun_delete_partition,
+ .part_get_type = sun_get_parttype,
};
extern void sun_set_rspeed(struct fdisk_context *cxt);
extern void sun_set_pcylcount(struct fdisk_context *cxt);
extern void toggle_sunflags(struct fdisk_context *cxt, int i, uint16_t mask);
-extern int sun_get_sysid(struct fdisk_context *cxt, int i);
#endif /* FDISK_SUN_LABEL_H */
return NULL;
}
-static struct fdisk_parttype *mk_unknown_partype(unsigned int type, const char *typestr)
+struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int type, const char *typestr)
{
struct fdisk_parttype *t;
return &types[i];
}
- return mk_unknown_partype(code, typestr);
+ return fdisk_new_unknown_parttype(code, typestr);
}
/*
free(t);
}
}
+
+/**
+ * fdisk_get_partition_type:
+ * @cxt: fdisk context
+ * @partnum: partition number
+ *
+ * Returns partition type
+ */
+struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum)
+{
+ if (!cxt || !cxt->label || !cxt->label->part_get_type)
+ return NULL;
+
+ return cxt->label->part_get_type(cxt, partnum);
+}