Пример #1
0
static int sgi_list_table(struct fdisk_context *cxt)
{
	struct tt *tb = NULL;
	struct sgi_disklabel *sgilabel = self_disklabel(cxt);
	struct sgi_device_parameter *sgiparam = &sgilabel->devparam;
	size_t i, used;
	char *p;
	int rc;

	if (fdisk_context_display_details(cxt))
		fdisk_colon(cxt, _(
			"Label geometry: %d heads, %llu sectors\n"
			"                %llu cylinders, %d physical cylinders\n"
			"                %d extra sects/cyl, interleave %d:1\n"),
			cxt->geom.heads, cxt->geom.sectors,
			cxt->geom.cylinders, be16_to_cpu(sgiparam->pcylcount),
			(int) sgiparam->sparecyl, be16_to_cpu(sgiparam->ilfact));

	/*
	 * Partitions
	 */
	tb = tt_new_table(TT_FL_FREEDATA);
	if (!tb)
		return -ENOMEM;

	tt_define_column(tb, _("Pt#"),      3, TT_FL_RIGHT);
	tt_define_column(tb, _("Device"), 0.2, 0);
	tt_define_column(tb, _("Info"),     2, 0);
	tt_define_column(tb, _("Start"),    9, TT_FL_RIGHT);
	tt_define_column(tb, _("End"),      9, TT_FL_RIGHT);
	tt_define_column(tb, _("Sectors"),  9, TT_FL_RIGHT);
	tt_define_column(tb, _("Id"),       2, TT_FL_RIGHT);
	tt_define_column(tb, _("System"), 0.2, TT_FL_TRUNC);

	for (i = 0, used = 1; i < cxt->label->nparts_max; i++) {
		uint32_t start, len;
		struct fdisk_parttype *t;
		struct tt_line *ln;

		if (sgi_get_num_sectors(cxt, i) == 0)
			continue;

		ln = tt_add_line(tb, NULL);
		if (!ln)
			continue;
		start = sgi_get_start_sector(cxt, i);
		len = sgi_get_num_sectors(cxt, i);
		t = fdisk_get_partition_type(cxt, i);

		if (asprintf(&p, "%zu:", i + 1) > 0)
			tt_line_set_data(ln, 0, p);	/* # */
		p = fdisk_partname(cxt->dev_path, used++);
		if (p)
			tt_line_set_data(ln, 1, p);	/* Device */

		p = sgi_get_swappartition(cxt) == (int) i ? "swap" :
		    sgi_get_bootpartition(cxt) == (int) i ? "boot" : NULL;
		if (p)
			tt_line_set_data(ln, 2, strdup(p));	/* Info */

		if (asprintf(&p, "%ju", (uintmax_t) fdisk_scround(cxt, start)) > 0)
			tt_line_set_data(ln, 3, p);	/* Start */
		if (asprintf(&p, "%ju",	(uintmax_t) fdisk_scround(cxt, start + len) - 1) > 0)
			tt_line_set_data(ln, 4, p);	/* End */
		if (asprintf(&p, "%ju",	(uintmax_t) len) > 0)
			tt_line_set_data(ln, 5, p);	/* Sectors*/
		if (asprintf(&p, "%2x", t->type) > 0)
			tt_line_set_data(ln, 6, p);	/* type ID */
		if (t->name)
			tt_line_set_data(ln, 7, strdup(t->name)); /* type Name */
		fdisk_free_parttype(t);
	}

	rc = fdisk_print_table(cxt, tb);
	tt_free_table(tb);
	if (rc)
		return rc;

	/*
	 * Volumes
	 */
	tb = tt_new_table(TT_FL_FREEDATA);
	if (!tb)
		return -ENOMEM;

	tt_define_column(tb, _("#"),       3, TT_FL_RIGHT);
	tt_define_column(tb, _("Name"),  0.2, 0);
	tt_define_column(tb, _("Sector"),  2, TT_FL_RIGHT);
	tt_define_column(tb, _("Size"),    9, TT_FL_RIGHT);

	for (i = 0, used = 0; i < SGI_MAXVOLUMES; i++) {
		struct tt_line *ln;
		uint32_t start = be32_to_cpu(sgilabel->volume[i].block_num),
			 len = be32_to_cpu(sgilabel->volume[i].num_bytes);
		if (!len)
			continue;
		ln = tt_add_line(tb, NULL);
		if (!ln)
			continue;
		if (asprintf(&p, "%zu:", i) > 0)
			tt_line_set_data(ln, 0, p);		/* # */
		if (*sgilabel->volume[i].name)
			tt_line_set_data(ln, 1,
				strndup((char *) sgilabel->volume[i].name,
				        sizeof(sgilabel->volume[i].name)));	/* Name */
		if (asprintf(&p, "%ju", (uintmax_t) start) > 0)
			tt_line_set_data(ln, 2, p);	/* Sector */
		if (asprintf(&p, "%ju",	(uintmax_t) len) > 0)
			tt_line_set_data(ln, 3, p);	/* Size */
		used++;
	}

	if (used)
		rc = fdisk_print_table(cxt, tb);
	tt_free_table(tb);

	fdisk_colon(cxt, _("Bootfile: %s"), sgilabel->boot_file);

	return rc;
}
Пример #2
0
static int sun_list_disklabel(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel;
	struct tt *tb = NULL;
	size_t i;
	int rc;

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_disklabel(cxt, SUN));

	sunlabel = self_disklabel(cxt);

	if (fdisk_context_display_details(cxt)) {
		fdisk_colon(cxt,
		_("Label geometry: %d rpm, %d alternate and %d physical cylinders,\n"
		  "                %d extra sects/cyl, interleave %d:1"),
		       be16_to_cpu(sunlabel->rpm),
		       be16_to_cpu(sunlabel->acyl),
		       be16_to_cpu(sunlabel->pcyl),
		       be16_to_cpu(sunlabel->apc),
		       be16_to_cpu(sunlabel->intrlv));
		fdisk_colon(cxt, _("Label ID: %s"), sunlabel->label_id);
		fdisk_colon(cxt, _("Volume ID: %s"),
		       *sunlabel->vtoc.volume_id ? sunlabel->vtoc.volume_id : _("<none>"));
	}

	tb = tt_new_table(TT_FL_FREEDATA);
	if (!tb)
		return -ENOMEM;

	tt_define_column(tb, _("Device"), 0.2, 0);
	tt_define_column(tb, _("Flag"),     2, TT_FL_RIGHT);
	tt_define_column(tb, _("Start"),    9, TT_FL_RIGHT);
	tt_define_column(tb, _("End"),      9, TT_FL_RIGHT);
	/* TRANSLATORS: keep one blank space behind 'Blocks' */
	tt_define_column(tb, _("Blocks "),  9, TT_FL_RIGHT);
	tt_define_column(tb, _("Id"),       2, TT_FL_RIGHT);
	tt_define_column(tb, _("System"), 0.2, TT_FL_TRUNC);

	for (i = 0 ; i < cxt->label->nparts_max; i++) {
		struct sun_partition *part = &sunlabel->partitions[i];
		uint16_t flags = be16_to_cpu(sunlabel->vtoc.infos[i].flags);
		uint32_t start, len;
		struct fdisk_parttype *t;
		struct tt_line *ln;
		char *p;

		if (!part->num_sectors)
			continue;
		ln = tt_add_line(tb, NULL);
		if (!ln)
			continue;

		start = be32_to_cpu(part->start_cylinder)
				* cxt->geom.heads
				* cxt->geom.sectors;

		len = be32_to_cpu(part->num_sectors);
		t = fdisk_get_partition_type(cxt, i);

		p = fdisk_partname(cxt->dev_path, i + 1);
		if (p)
			tt_line_set_data(ln, 0, p);	/* devname */
		if ((flags & SUN_FLAG_UNMNT || flags & SUN_FLAG_RONLY)
		    && asprintf(&p, "%c%c",
				flags & SUN_FLAG_UNMNT ? 'u' : ' ',
				flags & SUN_FLAG_RONLY ? 'r' : ' ') > 0)
			tt_line_set_data(ln, 1, p);	/* flags */
		if (asprintf(&p, "%ju", (uintmax_t) fdisk_scround(cxt, start)) > 0)
			tt_line_set_data(ln, 2, p);	/* start */
		if (asprintf(&p, "%ju",	(uintmax_t) fdisk_scround(cxt, start + len - 1)) > 0)
			tt_line_set_data(ln, 3, p);	/* end */
		if (asprintf(&p, "%lu%c",
				(unsigned long) len / 2,
				len & 1 ? '+' : ' ') > 0)
			tt_line_set_data(ln, 4, p);	/* blocks + flag */
		if (asprintf(&p, "%2x", t->type) > 0)
			tt_line_set_data(ln, 5, p);	/* type ID */
		if (t->name)
			tt_line_set_data(ln, 6, strdup(t->name)); /* type Name */

		fdisk_free_parttype(t);
	}

	rc = fdisk_print_table(cxt, tb);
	tt_free_table(tb);

	return rc;
}