fdisk_label_set_changed(cxt->label, 1);
}
+
+static int dos_get_partition_status(
+ struct fdisk_context *cxt,
+ struct fdisk_label *lb __attribute__((__unused__)),
+ int i,
+ int *status)
+{
+ struct pte *pe;
+ struct partition *p;
+
+ assert(cxt);
+ assert(fdisk_is_disklabel(cxt, DOS));
+
+ if (!status || i < 0 || i >= partitions)
+ return -EINVAL;
+
+ *status = FDISK_PARTSTAT_NONE;
+ pe = &ptes[i];
+ p = pe->part_table;
+
+ if (p && !is_cleared_partition(p))
+ *status = FDISK_PARTSTAT_USED;
+
+ return 0;
+}
+
static const struct fdisk_label_operations dos_operations =
{
.probe = dos_probe_label,
.part_delete = dos_delete_partition,
.part_get_type = dos_get_parttype,
.part_set_type = dos_set_parttype,
+
+ .part_get_status = dos_get_partition_status,
+
.reset_alignment = dos_reset_alignment,
};
return 0;
}
+
+static int sgi_get_partition_status(
+ struct fdisk_context *cxt,
+ struct fdisk_label *lb __attribute__((__unused__)),
+ int i,
+ int *status)
+{
+
+ assert(cxt);
+ assert(fdisk_is_disklabel(cxt, SGI));
+
+ if (!status || i < 0 || i >= partitions)
+ return -EINVAL;
+
+ *status = FDISK_PARTSTAT_NONE;
+
+ if (sgilabel->partitions[i].num_sectors &&
+ sgilabel->partitions[i].num_sectors)
+ *status = FDISK_PARTSTAT_USED;
+
+ return 0;
+}
+
static const struct fdisk_label_operations sgi_operations =
{
.probe = sgi_probe_label,
.part_add = sgi_add_partition,
.part_delete = sgi_delete_partition,
.part_get_type = sgi_get_parttype,
- .part_set_type = sgi_set_parttype
+ .part_set_type = sgi_set_parttype,
+
+ .part_get_status = sgi_get_partition_status
};
/*
return 0;
}
+
+static int sun_get_partition_status(
+ struct fdisk_context *cxt,
+ struct fdisk_label *lb __attribute__((__unused__)),
+ int i,
+ int *status)
+{
+ struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+
+ if (!status || i < 0 || (size_t) i >= lb->nparts_max)
+ return -EINVAL;
+
+ *status = FDISK_PARTSTAT_NONE;
+
+ if (sunlabel->partitions[i].num_sectors)
+ *status = FDISK_PARTSTAT_USED;
+
+ return 0;
+}
+
+
const struct fdisk_label_operations sun_operations =
{
.probe = sun_probe_label,
.part_delete = sun_delete_partition,
.part_get_type = sun_get_parttype,
.part_set_type = sun_set_parttype,
- .reset_alignment = sun_reset_alignment
+
+ .part_get_status = sun_get_partition_status,
+
+ .reset_alignment = sun_reset_alignment,
};
/*
return 0;
}
+static int gpt_get_partition_status(
+ struct fdisk_context *cxt,
+ struct fdisk_label *lb __attribute__((__unused__)),
+ int i,
+ int *status)
+{
+ struct fdisk_gpt_label *gpt = gpt_label(cxt);
+ struct gpt_entry *e;
+
+ if (!cxt || !gpt || i < 0 || !status
+ || (uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries))
+ return -EINVAL;
+
+ e = &gpt->ents[i];
+ *status = FDISK_PARTSTAT_NONE;
+
+ if (!partition_unused(&gpt->ents[i]) || gpt_partition_size(e))
+ *status = FDISK_PARTSTAT_USED;
+
+ return 0;
+}
+
+
/*
* Deinitialize fdisk-specific variables
*/
.part_get_type = gpt_get_partition_type,
.part_set_type = gpt_set_partition_type,
+ .part_get_status = gpt_get_partition_status,
+
.deinit = gpt_deinit
};
int (*part_set_type)(struct fdisk_context *cxt, struct fdisk_label *lb,
int partnum,
struct fdisk_parttype *t);
+
+ /* returns FDISK_PARTSTAT_* flags */
+ int (*part_get_status)(struct fdisk_context *cxt, struct fdisk_label *lb,
+ int partnum, int *status);
+
/* refresh alignment setting */
int (*reset_alignment)(struct fdisk_context *cxt,
struct fdisk_label *lb);
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, int partnum, int *status)
+{
+ if (!cxt || !cxt->label)
+ return -EINVAL;
+ if (!cxt->label->op->part_get_status)
+ return -ENOSYS;
+
+ return cxt->label->op->part_get_status(cxt, cxt->label, partnum, status);
+}
+
+
/*
* Resets the current used label driver to initial state
*/
FDISK_DISKLABEL_ANY = -1
};
+enum {
+ FDISK_PARTSTAT_NONE,
+ FDISK_PARTSTAT_USED /* partition used */
+};
+
/* init.c */
extern void fdisk_init_debug(int mask);
extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed);
extern int fdisk_label_is_changed(struct fdisk_label *lb);
+extern int fdisk_partition_get_status(struct fdisk_context *cxt, int partnum, int *status);
/* alignment.c */
extern int fdisk_reset_alignment(struct fdisk_context *cxt);