list_disk_geometry(cxt);
- if (fdisk_is_disklabel(cxt, GPT)) {
- gpt_list_table(cxt, xtra);
- return;
- }
-
- if (fdisk_is_disklabel(cxt, OSF)) {
+ if (fdisk_is_disklabel(cxt, OSF))
xbsd_print_disklabel(cxt, xtra);
- return;
- }
- if (fdisk_is_disklabel(cxt, DOS))
+ else if (fdisk_is_disklabel(cxt, DOS))
dos_list_table(cxt, xtra);
+ else
+ fdisk_list_disklabel(cxt);
+
}
static void verify(struct fdisk_context *cxt)
int (*verify)(struct fdisk_context *cxt);
/* create new disk label */
int (*create)(struct fdisk_context *cxt);
+ /* list partition table */
+ int (*list)(struct fdisk_context *cxt);
+
/* new partition */
int (*part_add)(struct fdisk_context *cxt,
size_t partnum,
* requirements, but once partition semantics are added to the fdisk
* API it can be removed for custom implementation (see gpt_label struct).
*/
-void gpt_list_table(struct fdisk_context *cxt,
- int xtra __attribute__ ((__unused__)))
+static int gpt_list_disklabel(struct fdisk_context *cxt)
{
+ int rc;
uint32_t i;
struct fdisk_gpt_label *gpt;
uint64_t fu;
tb = tt_new_table(TT_FL_FREEDATA);
if (!tb)
- return; /* ENOMEM */
+ return -ENOMEM;
+
tt_define_column(tb, "#", 2, TT_FL_RIGHT);
tt_define_column(tb, "Start", 12, TT_FL_RIGHT);
tt_define_column(tb, "End", 12, TT_FL_RIGHT);
fdisk_free_parttype(t);
}
- fdisk_print_table(cxt, tb);
+ rc = fdisk_print_table(cxt, tb);
tt_free_table(tb);
+
+ return rc;
}
/*
.write = gpt_write_disklabel,
.verify = gpt_verify_disklabel,
.create = gpt_create_disklabel,
+ .list = gpt_list_disklabel,
.part_add = gpt_add_partition,
.part_delete = gpt_delete_partition,
.part_get_type = gpt_get_partition_type,
return cxt->label->op->verify(cxt);
}
+/**
+ * fdisk_list_disklabel:
+ * @cxt: fdisk context
+ *
+ * Lists in-memory partition table
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_list_disklabel(struct fdisk_context *cxt)
+{
+ if (!cxt || !cxt->label)
+ return -EINVAL;
+ if (!cxt->label->op->list)
+ return -ENOSYS;
+
+ return cxt->label->op->list(cxt);
+}
+
/**
* fdisk_add_partition:
* @cxt: fdisk context
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 int fdisk_list_disklabel(struct fdisk_context *cxt);
extern int fdisk_add_partition(struct fdisk_context *cxt, struct fdisk_parttype *t);
extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum);