libfdisk/src/utils.c \
libfdisk/src/context.c \
libfdisk/src/parttype.c \
+ libfdisk/src/partition.c \
\
libfdisk/src/sun.c \
libfdisk/src/sgi.c \
ask->data.num.inchars = inchar ? 1 : 0;
for (i = 0; i < cxt->label->nparts_max; i++) {
- int status = 0;
+ int used = fdisk_is_partition_used(cxt, i);
- rc = fdisk_partition_get_status(cxt, i, &status);
- if (rc)
- break;
- if (wantnew && !(status & FDISK_PARTSTAT_USED)) {
+ if (wantnew && !used) {
ptr = mk_string_list(ptr, &len, &begin, &run, i, inchar);
if (!ptr) {
rc = -EINVAL;
if (!num->low)
num->dfl = num->low = i + 1;
num->hig = i + 1;
- } else if (!wantnew && (status & FDISK_PARTSTAT_USED)) {
+ } else if (!wantnew && used) {
ptr = mk_string_list(ptr, &len, &begin, &run, i, inchar);
if (!num->low)
num->low = i + 1;
return 0;
}
-static int bsd_get_partition_status(
+static int bsd_partition_is_used(
struct fdisk_context *cxt,
- size_t partnum,
- int *status)
+ size_t partnum)
{
- struct bsd_partition *p;
struct bsd_disklabel *d = self_disklabel(cxt);
- if (!status || partnum >= BSD_MAXPARTITIONS)
- return -EINVAL;
-
- p = &d->d_partitions[partnum];
- *status = FDISK_PARTSTAT_NONE;
-
- if (p->p_size)
- *status = FDISK_PARTSTAT_USED;
+ if (partnum >= BSD_MAXPARTITIONS)
+ return 0;
- return 0;
+ return d->d_partitions[partnum].p_size ? 1 : 0;
}
.part_delete = bsd_delete_part,
.part_get_type = bsd_get_parttype,
.part_set_type = bsd_set_parttype,
- .part_get_status= bsd_get_partition_status,
+ .part_is_used = bsd_partition_is_used,
};
return rc;
}
-static int dos_get_partition_status(
+static int dos_partition_is_used(
struct fdisk_context *cxt,
- size_t i,
- int *status)
+ size_t i)
{
struct dos_partition *p;
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, DOS));
- if (!status || i >= cxt->label->nparts_max)
- return -EINVAL;
+ if (i >= cxt->label->nparts_max)
+ return 0;
p = self_partition(cxt, i);
- if (is_used_partition(p))
- *status = FDISK_PARTSTAT_USED;
- else
- *status = FDISK_PARTSTAT_NONE;
-
- return 0;
+ return p && !is_cleared_partition(p);
}
static int dos_toggle_partition_flag(
.part_set_type = dos_set_parttype,
.part_toggle_flag = dos_toggle_partition_flag,
- .part_get_status = dos_get_partition_status,
+ .part_is_used = dos_partition_is_used,
.reset_alignment = dos_reset_alignment,
#define FDISK_DEBUG_LABEL (1 << 5)
#define FDISK_DEBUG_ASK (1 << 6)
#define FDISK_DEBUG_FRONTEND (1 << 7)
+#define FDISK_DEBUG_PART (1 << 8)
#define FDISK_DEBUG_ALL 0xFFFF
# define ON_DBG(m, x) do { \
#define fdisk_parttype_is_invisible(_x) ((_x) && ((_x)->flags & FDISK_PARTTYPE_INVISIBLE))
#define fdisk_parttype_is_allocated(_x) ((_x) && ((_x)->flags & FDISK_PARTTYPE_ALLOCATED))
+struct fdisk_partition {
+ struct fdisk_context *cxt;
+
+ size_t partno;
+ uint64_t start;
+ uint64_t end;
+ uint64_t size;
+ char *name;
+ char *uuid;
+ char *attrs;
+
+ struct fdisk_parttype *type;
+
+ unsigned int nested : 1, /* logical partition */
+ used : 1, /* partition used */
+ endrel : 1; /* end is specified as relative number */
+};
+
+
/*
* Legacy CHS based geometry
*/
size_t partnum,
struct fdisk_parttype *t);
- /* returns FDISK_PARTSTAT_* flags */
- int (*part_get_status)(struct fdisk_context *cxt,
- size_t partnum,
- int *status);
+ /* return state of the partition */
+ int (*part_is_used)(struct fdisk_context *cxt, size_t partnum);
- /* get data according to id (FDISK_COL_*) */
- int (*part_get_data)(struct fdisk_context *cxt,
- int id,
+ /* fill in partition struct */
+ int (*get_part)(struct fdisk_context *cxt,
size_t n,
- char **data);
+ struct fdisk_partition *pa);
int (*part_toggle_flag)(struct fdisk_context *cxt, size_t i, unsigned long flag);
return *res;
}
-static int gpt_get_partition_data(struct fdisk_context *cxt, int id, size_t n, char **data)
+static int gpt_get_partition(struct fdisk_context *cxt, size_t n,
+ struct fdisk_partition *pa)
{
struct fdisk_gpt_label *gpt;
struct gpt_entry *e;
- char *p = NULL;
- int rc = 0;
+ char u_str[37], *buf = NULL;
assert(cxt);
- assert(data);
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, GPT));
gpt = self_label(cxt);
e = &gpt->ents[n];
- switch (id) {
- case FDISK_COL_DEVICE:
- p = fdisk_partname(cxt->dev_path, n + 1);
- break;
- case FDISK_COL_START:
- if (asprintf(&p, "%ju", gpt_partition_start(e)) < 0)
- rc = -ENOMEM;
- break;
- case FDISK_COL_END:
- if (asprintf(&p, "%ju", gpt_partition_end(e)) < 0)
- rc = -ENOMEM;
- break;
- case FDISK_COL_SIZE:
- if (fdisk_context_display_details(cxt)) {
- if (asprintf(&p, "%ju", gpt_partition_size(e) *
- cxt->sector_size) < 0)
- rc = -ENOMEM;
- } else {
- p = size_to_human_string(SIZE_SUFFIX_1LETTER,
- gpt_partition_size(e) * cxt->sector_size);
- if (!p)
- rc = -ENOMEM;
- }
- break;
- case FDISK_COL_TYPE:
- {
- struct fdisk_parttype *t = fdisk_get_partition_type(cxt, n);
- if (t && t->name)
- p = strdup(t->name);
- fdisk_free_parttype(t);
- break;
- }
- case FDISK_COL_UUID:
- {
- char u_str[37];
- if (guid_to_string(&e->partition_guid, u_str)) {
- p = strdup(u_str);
- if (!p)
- rc = -ENOMEM;
- }
- break;
- }
- case FDISK_COL_ATTR:
- {
- char *buf = NULL;
-
- if (asprintf(&p, "%s%s%s%s",
- e->attr.required_to_function ? "Required " : "",
- e->attr.legacy_bios_bootable ? "LegacyBoot " : "",
- e->attr.no_blockio_protocol ? "NoBlockIO " : "",
- guid_attrs_to_string(&e->attr, &buf)) < 0)
- rc = -ENOMEM;
- free(buf);
- break;
- }
- case FDISK_COL_NAME:
- p = encode_to_utf8((unsigned char *)e->name, sizeof(e->name));
- break;
- } /* switch */
+ pa->used = !partition_unused(e) || gpt_partition_start(e);
+ if (!pa->used)
+ return 0;
+ pa->start = gpt_partition_start(e);
+ pa->end = gpt_partition_end(e);
+ pa->size = gpt_partition_size(e) * cxt->sector_size;
+ pa->type = fdisk_get_partition_type(cxt, n);
- if (rc == 0)
- *data = p;
- return rc;
+ if (guid_to_string(&e->partition_guid, u_str)) {
+ pa->uuid = strdup(u_str);
+ if (!pa->uuid)
+ goto nomem;
+ } else
+ pa->uuid = NULL;
+
+ if (asprintf(&pa->attrs, "%s%s%s%s",
+ e->attr.required_to_function ? "Required " : "",
+ e->attr.legacy_bios_bootable ? "LegacyBoot " : "",
+ e->attr.no_blockio_protocol ? "NoBlockIO " : "",
+ guid_attrs_to_string(&e->attr, &buf)) < 0)
+ goto nomem;
+ pa->name = encode_to_utf8((unsigned char *)e->name, sizeof(e->name));
+
+ return 0;
+nomem:
+ fdisk_reset_partition(pa);
+ return -ENOMEM;
}
/*
return 0;
}
-static int gpt_get_partition_status(
- struct fdisk_context *cxt,
- size_t i,
- int *status)
+static int gpt_part_is_used(struct fdisk_context *cxt, size_t i)
{
struct fdisk_gpt_label *gpt;
struct gpt_entry *e;
gpt = self_label(cxt);
- if (!status || (uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries))
- return -EINVAL;
-
+ if ((uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries))
+ return 0;
e = &gpt->ents[i];
- *status = FDISK_PARTSTAT_NONE;
-
- if (!partition_unused(e) || gpt_partition_start(e))
- *status = FDISK_PARTSTAT_USED;
- return 0;
+ return !partition_unused(e) || gpt_partition_start(e);
}
int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i)
.get_id = gpt_get_disklabel_id,
.set_id = gpt_set_disklabel_id,
+ .get_part = gpt_get_partition,
+
.part_add = gpt_add_partition,
.part_delete = gpt_delete_partition,
+
+ .part_is_used = gpt_part_is_used,
.part_get_type = gpt_get_partition_type,
.part_set_type = gpt_set_partition_type,
.part_toggle_flag = gpt_toggle_partition_flag,
- .part_get_status = gpt_get_partition_status,
- .part_get_data = gpt_get_partition_data,
-
.deinit = gpt_deinit
};
*
* Verifies the partition table.
*
- * Returns 0.
+ * Returns: 0 on success, otherwise, a corresponding error.
*/
int fdisk_verify_disklabel(struct fdisk_context *cxt)
{
}
/**
- * fdisk_partition_get_data:
- * @cxt: fdisk context
- * @id: column (FDISK_COL_*)
- * @partnum: partition number
- * @data: return allocated data
+ * fdisk_get_partition:
+ * @cxt:
+ * @partno:
+ * @pa: pointer to partition struct
*
- * For exmaple
- * fdisk_partition_get_data(cxt, FDISK_COL_UUID, 0, &data);
- * returns UUID for the first partition.
+ * Fills in @pa with data about partition @n.
*
- * Returns 0 on success, otherwise, a corresponding error.
+ * Returns: 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_get_partition(struct fdisk_context *cxt, size_t partno,
+ struct fdisk_partition *pa)
+{
+ int rc;
+
+ if (!cxt || !cxt->label || !pa)
+ return -EINVAL;
+ if (!cxt->label->op->get_part)
+ return -ENOSYS;
+
+ fdisk_reset_partition(pa);
+ pa->cxt = cxt;
+
+ rc = cxt->label->op->get_part(cxt, partno, pa);
+ if (rc == 0 && fdisk_partition_is_used(pa))
+ DBG(LABEL, dbgprint("get partition %zu", partno));
+ return rc;
+}
+
+/*
+ * This is faster than fdisk_get_partition() + fdisk_partition_is_used()
*/
-int fdisk_partition_get_data(struct fdisk_context *cxt, int id,
- size_t partnum, char **data)
+int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n)
{
if (!cxt || !cxt->label)
return -EINVAL;
- if (!cxt->label->op->part_get_data)
+ if (!cxt->label->op->part_is_used)
return -ENOSYS;
- return cxt->label->op->part_get_data(cxt, id, partnum, data);
+ return cxt->label->op->part_is_used(cxt, n);
}
/**
int *org = cols, rc = 0;
struct tt *tb = NULL;
const struct fdisk_column *col;
+ struct fdisk_partition *pa = NULL;
size_t i, j;
if (!cxt || !cxt->label)
return -EINVAL;
- if (!cxt->label->op->part_get_data)
+ if (!cxt->label->op->get_part)
return -ENOSYS;
+ DBG(LABEL, dbgprint("list partitions"));
+
if (!cols || !ncols) {
rc = fdisk_get_columns(cxt, &cols, &ncols);
if (rc)
rc = -ENOMEM;
goto done;
}
+ pa = fdisk_new_partition();
+ if (!pa) {
+ rc = -ENOMEM;
+ goto done;
+ }
/* define table columns */
for (j = 0; j < ncols; j++) {
/* generate per-partition lines into table */
for (i = 0; i < cxt->label->nparts_max; i++) {
- int status = 0;
struct tt_line *ln;
- rc = fdisk_partition_get_status(cxt, i, &status);
- if (rc || !(status & FDISK_PARTSTAT_USED))
+ rc = fdisk_get_partition(cxt, i, pa);
+ if (rc)
+ goto done;
+ if (!fdisk_partition_is_used(pa))
continue;
-
ln = tt_add_line(tb, NULL);
if (!ln)
continue;
col = fdisk_label_get_column(cxt->label, cols[j]);
if (!col)
continue;
- rc = fdisk_partition_get_data(cxt, col->id, i, &data);
+ rc = fdisk_partition_to_string(pa, col->id, &data);
if (rc)
goto done;
tt_line_set_data(ln, j, data);
if (org != cols)
free(cols);
tt_free_table(tb);
+ fdisk_free_partition(pa);
return rc;
}
return cxt->label->nparttypes;
}
-/**
- * fdisk_partition_is_used:
- * @cxt: fdisk context
- * @partnum: partition number
- * @status: returns FDISK_PARTSTAT_* flags
- *
- * Returns 0 on success, otherwise, a corresponding error.
- */
-int fdisk_partition_get_status(struct fdisk_context *cxt,
- size_t partnum,
- int *status)
-{
- int rc;
-
- if (!cxt || !cxt->label)
- return -EINVAL;
- if (!cxt->label->op->part_get_status)
- return -ENOSYS;
-
- rc = cxt->label->op->part_get_status(cxt, partnum, status);
-
- DBG(LABEL, dbgprint("partition: %zd: status: 0x%04x [rc=%d]", partnum, *status, rc));
- return rc;
-}
-
-/**
- * @cxt: fdisk context
- * @partnum: partition number
- *
- * Returns: 1 on success if partition used otherwise 0.
- */
-int fdisk_partition_is_used(struct fdisk_context *cxt, size_t partnum)
-{
- int status, rc;
-
- rc = fdisk_partition_get_status(cxt, partnum, &status);
- if (rc)
- return 0;
-
- return status & FDISK_PARTSTAT_USED;
-}
-
/**
* fdisk_partition_taggle_flag:
* @cxt: fdisk context
return rc;
}
-
/*
* Resets the current used label driver to initial state
*/
struct fdisk_context;
struct fdisk_label;
struct fdisk_parttype;
+struct fdisk_partition;
struct fdisk_ask;
struct tt;
FDISK_DISKLABEL_GPT = (1 << 5)
};
-enum {
- FDISK_PARTSTAT_NONE = 0,
- FDISK_PARTSTAT_USED /* partition used */
-};
-
enum {
FDISK_ASKTYPE_NONE = 0,
FDISK_ASKTYPE_NUMBER,
extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);
-extern int fdisk_partition_get_data(struct fdisk_context *cxt, int id, size_t partnum, char **data);
+
+extern int fdisk_get_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition *pa);
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);
extern void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled);
extern int fdisk_label_is_disabled(struct fdisk_label *lb);
-extern int fdisk_partition_get_status(struct fdisk_context *cxt, size_t partnum, int *status);
-extern int fdisk_partition_is_used(struct fdisk_context *cxt, size_t partnum);
+extern int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n);
+
extern int fdisk_partition_toggle_flag(struct fdisk_context *cxt, size_t partnum, unsigned long flag);
+extern struct fdisk_partition *fdisk_new_partition(void);
+extern void fdisk_reset_partition(struct fdisk_partition *pa);
+extern void fdisk_free_partition(struct fdisk_partition *pa);
+extern int fdisk_partition_set_start(struct fdisk_partition *pa, uint64_t off);
+extern uint64_t fdisk_partition_get_start(struct fdisk_partition *pa);
+extern int fdisk_partition_set_end(struct fdisk_partition *pa, uint64_t off, int isrel);
+extern uint64_t fdisk_partition_get_end(struct fdisk_partition *pa);
+extern int fdisk_partition_set_size(struct fdisk_partition *pa, uint64_t size);
+extern uint64_t fdisk_partition_get_size(struct fdisk_partition *pa);
+extern int fdisk_partition_set_partno(struct fdisk_partition *pa, size_t n);
+extern size_t fdisk_partition_get_partno(struct fdisk_partition *pa);
+extern int fdisk_partition_set_type(struct fdisk_partition *pa, struct fdisk_parttype *type);
+extern const struct fdisk_parttype *fdisk_partition_get_type(struct fdisk_partition *pa);
+extern int fdisk_partition_set_name(struct fdisk_partition *pa, const char *name);
+extern const char *fdisk_partition_get_name(struct fdisk_partition *pa);
+extern int fdisk_partition_set_uuid(struct fdisk_partition *pa, const char *uuid);
+extern const char *fdisk_partition_get_uuid(struct fdisk_partition *pa);
+extern const char *fdisk_partition_get_attrs(struct fdisk_partition *pa);
+extern int fdisk_partition_set_nested(struct fdisk_partition *pa, int nested);
+extern int fdisk_partition_is_nested(struct fdisk_partition *pa);
+extern int fdisk_partition_is_used(struct fdisk_partition *pa);
+extern int fdisk_partition_to_string(struct fdisk_partition *pa, int id, char **data);
+
/* alignment.c */
extern int fdisk_reset_alignment(struct fdisk_context *cxt);
extern int fdisk_reset_device_properties(struct fdisk_context *cxt);
--- /dev/null
+
+#include "c.h"
+#include "strutils.h"
+
+#include "fdiskP.h"
+
+struct fdisk_partition *fdisk_new_partition(void)
+{
+ struct fdisk_partition *pa = calloc(1, sizeof(*pa));
+
+ DBG(PART, dbgprint("new %p", pa));
+ return pa;
+}
+
+void fdisk_reset_partition(struct fdisk_partition *pa)
+{
+ if (!pa)
+ return;
+ fdisk_free_parttype(pa->type);
+ free(pa->name);
+ free(pa->uuid);
+ free(pa->attrs);
+ memset(pa, 0, sizeof(*pa));
+}
+
+void fdisk_free_partition(struct fdisk_partition *pa)
+{
+ if (!pa)
+ return;
+ fdisk_reset_partition(pa);
+ DBG(PART, dbgprint("free %p", pa));
+ free(pa);
+}
+
+int fdisk_partition_set_start(struct fdisk_partition *pa, uint64_t off)
+{
+ if (!pa)
+ return -EINVAL;
+ pa->start = off;
+ return 0;
+}
+
+uint64_t fdisk_partition_get_start(struct fdisk_partition *pa)
+{
+ return pa ? pa->start : 0;
+}
+
+int fdisk_partition_set_end(struct fdisk_partition *pa, uint64_t off, int isrel)
+{
+ if (!pa)
+ return -EINVAL;
+ pa->end = off;
+ pa->size = 0;
+ pa->endrel = isrel ? 1 : 0;
+ return 0;
+}
+
+uint64_t fdisk_partition_get_end(struct fdisk_partition *pa)
+{
+ return pa ? pa->start : 0;
+}
+
+
+int fdisk_partition_set_size(struct fdisk_partition *pa, uint64_t size)
+{
+ if (!pa)
+ return -EINVAL;
+ pa->size = size;
+ pa->end = 0;
+ return 0;
+}
+
+uint64_t fdisk_partition_get_size(struct fdisk_partition *pa)
+{
+ return pa ? pa->size : 0;
+}
+
+int fdisk_partition_set_partno(struct fdisk_partition *pa, size_t n)
+{
+ if (!pa)
+ return -EINVAL;
+ pa->partno = n;
+ return 0;
+}
+
+size_t fdisk_partition_get_partno(struct fdisk_partition *pa)
+{
+ return pa ? pa->partno : (size_t) -1;
+}
+
+int fdisk_partition_set_type(struct fdisk_partition *pa, struct fdisk_parttype *type)
+{
+ if (!pa)
+ return -EINVAL;
+ pa->type = type;
+ return 0;
+}
+
+const struct fdisk_parttype *fdisk_partition_get_type(struct fdisk_partition *pa)
+{
+ return pa ? pa->type : NULL;
+}
+
+int fdisk_partition_set_name(struct fdisk_partition *pa, const char *name)
+{
+ char *p = NULL;
+
+ if (!pa)
+ return -EINVAL;
+ if (name) {
+ p = strdup(name);
+ if (!p)
+ return -ENOMEM;
+ }
+ free(pa->name);
+ pa->name = p;
+ return 0;
+}
+
+const char *fdisk_partition_get_name(struct fdisk_partition *pa)
+{
+ return pa ? pa->name : NULL;
+}
+
+int fdisk_partition_set_uuid(struct fdisk_partition *pa, const char *uuid)
+{
+ char *p = NULL;
+
+ if (!pa)
+ return -EINVAL;
+ if (uuid) {
+ p = strdup(uuid);
+ if (!p)
+ return -ENOMEM;
+ }
+ free(pa->uuid);
+ pa->uuid = p;
+ return 0;
+}
+
+const char *fdisk_partition_get_uuid(struct fdisk_partition *pa)
+{
+ return pa ? pa->uuid : NULL;
+}
+
+const char *fdisk_partition_get_attrs(struct fdisk_partition *pa)
+{
+ return pa ? pa->attrs : NULL;
+}
+
+/* nested partition means logical (within extended partition) */
+int fdisk_partition_set_nested(struct fdisk_partition *pa, int nested)
+{
+ if (!pa)
+ return -EINVAL;
+ pa->nested = nested ? 1 : 0;
+ return 0;
+}
+
+int fdisk_partition_is_nested(struct fdisk_partition *pa)
+{
+ return pa && pa->nested;
+}
+
+int fdisk_partition_is_used(struct fdisk_partition *pa)
+{
+ return pa && pa->used;
+}
+
+
+/**
+ * fdisk_partition_to_string:
+ * @pa: partition
+ * @id: column (FDISK_COL_*)
+ * @data: returns string with allocated data
+ *
+ * Returns info about partition converted to printable string.
+ *
+ * For exmaple
+ *
+ * struct fdisk_parition *pa = fdisk_new_partition();
+ *
+ * fdisk_get_partition(cxt, 0, &pa);
+ * fdisk_partition_to_string(pa, FDISK_COL_UUID, &data);
+ * printf("first partition uuid: %s\n", data);
+ * free(data);
+ * fdisk_free_partition(pa);
+ *
+ * returns UUID for the first partition.
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+
+int fdisk_partition_to_string(struct fdisk_partition *pa,
+ int id,
+ char **data)
+{
+ char *p = NULL;
+ int rc = 0;
+
+ if (!pa || !pa->cxt)
+ return -EINVAL;
+
+ switch (id) {
+ case FDISK_COL_DEVICE:
+ p = fdisk_partname(pa->cxt->dev_path, pa->partno + 1);
+ break;
+ case FDISK_COL_START:
+ if (asprintf(&p, "%ju", pa->start) < 0)
+ rc = -ENOMEM;
+ break;
+ case FDISK_COL_END:
+ if (asprintf(&p, "%ju", pa->end) < 0)
+ rc = -ENOMEM;
+ break;
+ case FDISK_COL_SIZE:
+ if (fdisk_context_display_details(pa->cxt)) {
+ if (asprintf(&p, "%ju", pa->size))
+ rc = -ENOMEM;
+ } else {
+ p = size_to_human_string(SIZE_SUFFIX_1LETTER, pa->size);
+ if (!p)
+ rc = -ENOMEM;
+ }
+ break;
+ case FDISK_COL_TYPE:
+ p = pa->type && pa->type->name ? strdup(pa->type->name) : NULL;
+ break;
+ case FDISK_COL_UUID:
+ p = pa->uuid ? strdup(pa->uuid) : NULL;
+ break;
+ case FDISK_COL_NAME:
+ p = pa->name ? strdup(pa->name) : NULL;
+ break;
+ case FDISK_COL_ATTR:
+ p = pa->attrs ? strdup(pa->attrs) : NULL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (data)
+ *data = p;
+ return rc;
+}
}
-static int sgi_get_partition_status(
+static int sgi_partition_is_used(
struct fdisk_context *cxt,
- size_t i,
- int *status)
+ size_t i)
{
assert(cxt);
assert(fdisk_is_disklabel(cxt, SGI));
- if (!status || i >= cxt->label->nparts_max)
- return -EINVAL;
-
- *status = FDISK_PARTSTAT_NONE;
-
- if (sgi_get_num_sectors(cxt, i))
- *status = FDISK_PARTSTAT_USED;
-
- return 0;
+ if (i >= cxt->label->nparts_max)
+ return 0;
+ return sgi_get_num_sectors(cxt, i) ? 1 : 0;
}
static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsigned long flag)
.part_get_type = sgi_get_parttype,
.part_set_type = sgi_set_parttype,
- .part_get_status = sgi_get_partition_status,
+ .part_is_used = sgi_partition_is_used,
.part_toggle_flag = sgi_toggle_partition_flag
};
}
-static int sun_get_partition_status(
+static int sun_partition_is_used(
struct fdisk_context *cxt,
- size_t i,
- int *status)
+ size_t i)
{
struct sun_disklabel *sunlabel;
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, SUN));
- if (!status || i >= cxt->label->nparts_max)
- return -EINVAL;
+ if (i >= cxt->label->nparts_max)
+ return 0;
sunlabel = self_disklabel(cxt);
- *status = FDISK_PARTSTAT_NONE;
-
- if (sunlabel->partitions[i].num_sectors)
- *status = FDISK_PARTSTAT_USED;
-
- return 0;
+ return sunlabel->partitions[i].num_sectors ? 1 : 0;
}
.part_get_type = sun_get_parttype,
.part_set_type = sun_set_parttype,
- .part_get_status = sun_get_partition_status,
+ .part_is_used = sun_partition_is_used,
.part_toggle_flag = sun_toggle_partition_flag,
.reset_alignment = sun_reset_alignment,