ignore[i++] = 'b'; /* set bootable */
} else {
ignore[i++] = 'n';
- if (!fdisk_is_disklabel(cf->cxt, DOS) &&
- !fdisk_is_disklabel(cf->cxt, SGI))
+ if (!fdisk_is_label(cf->cxt, DOS) &&
+ !fdisk_is_label(cf->cxt, SGI))
ignore[i++] = 'b';
}
switch (key) {
case 'b': /* Bootable flag */
{
- int fl = fdisk_is_disklabel(cf->cxt, DOS) ? DOS_FLAG_ACTIVE :
- fdisk_is_disklabel(cf->cxt, SGI) ? SGI_FLAG_BOOT : 0;
+ int fl = fdisk_is_label(cf->cxt, DOS) ? DOS_FLAG_ACTIVE :
+ fdisk_is_label(cf->cxt, SGI) ? SGI_FLAG_BOOT : 0;
if (fl && fdisk_partition_toggle_flag(cf->cxt, n, fl))
warn = _("Could not toggle the flag.");
DBG(UI, ul_debug("start COLS=%d, LINES=%d", COLS, LINES));
- if (!fdisk_dev_has_disklabel(cf->cxt) || cf->zero_start) {
+ if (!fdisk_has_label(cf->cxt) || cf->zero_start) {
rc = ui_create_label(cf);
if (rc < 0)
ui_errx(EXIT_FAILURE,
assert(cxt);
assert(ent);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
DBG(FRONTEND, ul_debug("enter GPT menu"));
= fdisk_new_nested_context(cxt, "bsd");
if (!bsd)
return -ENOMEM;
- if (!fdisk_dev_has_disklabel(bsd))
+ if (!fdisk_has_label(bsd))
rc = fdisk_create_disklabel(bsd, "bsd");
if (rc)
fdisk_free_context(bsd);
assert(cxt);
assert(ent);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
DBG(FRONTEND, ul_debug("enter SUN menu"));
assert(cxt);
assert(ent);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
if (ent->expert)
return rc;
assert(cxt);
assert(ent);
- assert(fdisk_is_disklabel(cxt, BSD));
+ assert(fdisk_is_label(cxt, BSD));
DBG(FRONTEND, ul_debug("enter BSD menu"));
fdisk_dos_enable_compatible(lb, flag);
- if (fdisk_is_disklabel(cxt, DOS))
+ if (fdisk_is_label(cxt, DOS))
fdisk_reset_alignment(cxt); /* reset the current label */
}
if (cxt->alignment_offset)
fdisk_info(cxt, _("Alignment offset: %lu bytes"),
cxt->alignment_offset);
- if (fdisk_dev_has_disklabel(cxt))
+ if (fdisk_has_label(cxt))
fdisk_info(cxt, _("Disklabel type: %s"), cxt->label->name);
if (fdisk_get_disklabel_id(cxt, &id) == 0 && id)
list_disk_geometry(cxt);
- if (fdisk_dev_has_disklabel(cxt))
+ if (fdisk_has_label(cxt))
list_disklabel(cxt);
}
fflush(stdout);
- if (!fdisk_dev_has_disklabel(cxt)) {
+ if (!fdisk_has_label(cxt)) {
fdisk_info(cxt, _("Device does not contain a recognized partition table."));
fdisk_create_disklabel(cxt, NULL);
- } else if (fdisk_is_disklabel(cxt, GPT) && fdisk_gpt_is_hybrid(cxt))
+ } else if (fdisk_is_label(cxt, GPT) && fdisk_gpt_is_hybrid(cxt))
fdisk_warnx(cxt, _(
"A hybrid GPT was detected. You have to sync "
"the hybrid MBR manually (expert command 'M')."));
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, BSD));
+ assert(fdisk_is_label(cxt, BSD));
return (struct fdisk_bsd_label *) cxt->label;
}
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, BSD));
+ assert(fdisk_is_label(cxt, BSD));
return &((struct fdisk_bsd_label *) cxt->label)->bsd;
}
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, BSD));
+ assert(fdisk_is_label(cxt, BSD));
if (fdisk_is_details(cxt)) {
fdisk_info(cxt, "# %s:", cxt->dev_path);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, BSD));
+ assert(fdisk_is_label(cxt, BSD));
if (n >= d->d_npartitions)
return -EINVAL;
struct dos_partition *p;
struct bsd_disklabel *d = self_disklabel(cxt);
- if (!cxt->parent || !fdisk_is_disklabel(cxt->parent, DOS)) {
+ if (!cxt->parent || !fdisk_is_label(cxt->parent, DOS)) {
fdisk_warnx(cxt, _("BSD label is not nested within a DOS partition."));
return -EINVAL;
}
return __fdisk_switch_label(cxt, fdisk_get_label(cxt, name));
}
+/**
+ * fdisk_has_label:
+ * @cxt: fdisk context
+ *
+ * Returns: return 1 if there is label on the device.
+ */
+int fdisk_has_label(struct fdisk_context *cxt)
+{
+ return cxt && cxt->label;
+}
+
+/**
+ * fdisk_is_labeltype:
+ * @cxt: fdisk context
+ * @l: disklabel type
+ *
+ * Returns: return 1 if there is @l disklabel on the device.
+ */
+int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype l)
+{
+ return cxt && cxt->label && cxt->label->id == l;
+}
static void reset_context(struct fdisk_context *cxt)
{
assert(cxt);
- if (fdisk_dev_has_disklabel(cxt) || cxt->dev_fd < 0)
+ if (fdisk_has_label(cxt) || cxt->dev_fd < 0)
return -EINVAL;
#ifdef HAVE_LIBBLKID
DBG(CXT, ul_debugobj(cxt, "wipe check: initialize libblkid prober"));
/* warn about obsolete stuff on the device if we aren't in
* list-only mode and there is not PT yet */
- if (!fdisk_is_listonly(cxt) && !fdisk_dev_has_disklabel(cxt))
+ if (!fdisk_is_listonly(cxt) && !fdisk_has_label(cxt))
warn_wipe(cxt);
DBG(CXT, ul_debugobj(cxt, "initialized for %s [%s]",
assert(cxt);
return cxt->dev_path;
}
+
+
+
#define alignment_required(_x) ((_x)->grain != (_x)->sector_size)
#define is_dos_compatible(_x) \
- (fdisk_is_disklabel(_x, DOS) && \
+ (fdisk_is_label(_x, DOS) && \
fdisk_dos_is_compatible(fdisk_get_label(_x, NULL)))
#define cround(c, n) fdisk_cround(c, n)
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
return (struct fdisk_dos_label *) cxt->label;
}
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
return self_partition(cxt, i);
}
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
DBG(LABEL, ul_debug("DOS: initialize, first sector buffer %p", cxt->firstsector));
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
pe = self_pte(cxt, partnum);
if (!pe)
assert(cxt);
assert(id);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
num = mbr_get_id(cxt->firstsector);
if (asprintf(id, "0x%08x", num) > 0)
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
DBG(LABEL, ul_debug("DOS: creating new disklabel"));
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
DBG(LABEL, ul_debug("DOS: setting Id"));
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
/* overwrite necessary stuff by DOS deprecated stuff */
if (is_dos_compatible(cxt)) {
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
/* ignore disks with AIX magic number */
if (memcmp(cxt->firstsector, AIX_MAGIC_STRING, AIX_MAGIC_STRLEN) == 0)
}
fill_bounds(cxt, first, last);
if (n < 4) {
- if (cxt->parent && fdisk_is_disklabel(cxt->parent, GPT))
+ if (cxt->parent && fdisk_is_label(cxt->parent, GPT))
start = 1; /* Bad boy modifies hybrid MBR */
else
start = cxt->first_lba;
struct dos_partition *p;
struct fdisk_dos_label *l = self_label(cxt);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
fill_bounds(cxt, first, last);
for (i = 0; i < cxt->label->nparts_max; i++) {
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
l = self_label(cxt);
ext_pe = l->ext_offset ? self_pte(cxt, l->ext_index) : NULL;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
mbr_changed = l->non_pt_changed;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
if (partnum >= cxt->label->nparts_max || !t || t->type > UINT8_MAX)
return -EINVAL;
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
return 0;
}
assert(cxt);
assert(pa);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
lb = self_label(cxt);
pe = self_pte(cxt, n);
int rc;
assert(cxt);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
pe = self_pte(cxt, i);
p = pe->pt_entry;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
if (i >= cxt->label->nparts_max)
return 0;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, DOS));
+ assert(fdisk_is_label(cxt, DOS));
if (i >= cxt->label->nparts_max)
return -EINVAL;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
if (fdisk_is_details(cxt)) {
struct gpt_header *h = self_label(cxt)->pheader;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
mbr_type = valid_pmbr(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
DBG(LABEL, ul_debug("GPT new partition: partno=%zu, start=%ju, end=%ju",
partnum, fsect, lsect));
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
pheader = gpt->pheader;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
assert(cxt);
assert(id);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
guid_to_string(&gpt->pheader->disk_guid, str);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
if (fdisk_ask_string(cxt,
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
if ((uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries)
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
DBG(LABEL, ul_debug("UUID change requested partno=%zu", i));
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
DBG(LABEL, ul_debug("NAME change requested partno=%zu", i));
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
DBG(LABEL, ul_debug("GPT entry attribute change requested partno=%zu", i));
gpt = self_label(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
nparts = le32_to_cpu(gpt->pheader->npartition_entries);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
+ assert(fdisk_is_label(cxt, GPT));
gpt = self_label(cxt);
h = gpt ? gpt->pheader : NULL;
#include "fdiskP.h"
+
/*
* Don't use this function derectly
*/
for (i = 0; i < cxt->nlabels; i++) {
struct fdisk_label *lb = cxt->labels[i];
- struct fdisk_label *org = cxt->label;
+ struct fdisk_label *org = fdisk_get_label(cxt, NULL);
int rc;
if (!lb->op->probe)
return 1; /* not found */
}
-
/**
- * fdisk_dev_has_disklabel:
- * @cxt: fdisk context
+ * fdisk_label_get_name:
+ * @lb: label
*
- * Returns: return 1 if there is label on the device.
+ * Returns: label name
*/
-int fdisk_dev_has_disklabel(struct fdisk_context *cxt)
+const char *fdisk_label_get_name(struct fdisk_label *lb)
{
- return cxt && cxt->label;
+ return lb ? lb->name : NULL;
}
-/**
- * fdisk_dev_is_disklabel:
- * @cxt: fdisk context
- * @l: disklabel type
- *
- * Returns: return 1 if there is @l disklabel on the device.
- */
-int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l)
-{
- return cxt && cxt->label && cxt->label->id == l;
-}
/**
* fdisk_write_disklabel:
size_t fdisk_get_nlabels(struct fdisk_context *cxt);
int fdisk_switch_label(struct fdisk_context *cxt, const char *name);
+int fdisk_has_label(struct fdisk_context *cxt);
+int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype l);
+#define fdisk_is_label(c, x) fdisk_is_labeltype(c, FDISK_DISKLABEL_ ## x)
+
+
int fdisk_assign_device(struct fdisk_context *cxt,
const char *fname, int readonly);
int fdisk_deassign_device(struct fdisk_context *cxt, int nosync);
FDISK_FIELD_UUID,
};
+const char *fdisk_label_get_name(struct fdisk_label *lb);
+
extern int fdisk_require_geometry(struct fdisk_context *cxt);
extern int fdisk_missing_geometry(struct fdisk_context *cxt);
-extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
-
-extern int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l);
-#define fdisk_is_disklabel(c, x) fdisk_dev_is_disklabel(c, FDISK_DISKLABEL_ ## x)
extern int fdisk_write_disklabel(struct fdisk_context *cxt);
extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
return ((struct fdisk_sgi_label *) cxt->label)->header;
}
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
return (struct fdisk_sgi_label *) cxt->label;
}
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
assert(sizeof(struct sgi_disklabel) <= 512);
/* map first sector to header */
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
sgilabel = self_disklabel(cxt);
sgilabel->csum = 0;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
clear_freelist(cxt);
memset(Index, 0, sizeof(Index));
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
sgilabel = self_disklabel(cxt);
sgilabel->partitions[i].type = cpu_to_be32(sys);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
rc = fdisk_partition_next_partno(pa, cxt, &n);
if (rc)
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
#ifdef HDIO_GETGEO
if (cxt->geom.heads && cxt->geom.sectors) {
size_t i)
{
assert(cxt);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
if (i >= cxt->label->nparts_max)
return 0;
struct sgi_disklabel *sgilabel;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SGI));
+ assert(fdisk_is_label(cxt, SGI));
if (i >= cxt->label->nparts_max)
return -EINVAL;
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
return ((struct fdisk_sun_label *) cxt->label)->header;
}
{
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
return (struct fdisk_sun_label *) cxt->label;
}
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
/* map first sector to header */
sun = (struct fdisk_sun_label *) cxt->label;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
/* map first sector to header */
rc = fdisk_init_firstsector_buffer(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
if (i >= cxt->label->nparts_max)
return -EINVAL;
assert(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
#endif
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
fetch_sun(cxt, starts, lens, &start, &stop);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
part = &sunlabel->partitions[partnum];
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
if (n >= cxt->label->nparts_max)
return -EINVAL;
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
sunlabel = self_disklabel(cxt);
assert(cxt);
assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, SUN));
+ assert(fdisk_is_label(cxt, SUN));
if (i >= cxt->label->nparts_max)
return 0;