return;
}
-static int aix_probe_label(
- struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int aix_probe_label(struct fdisk_context *cxt)
{
- struct aix_partition *aixlabel = (struct aix_partition *) cxt->firstsector;
+ struct aix_partition *aixlabel;
+
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ aixlabel = (struct aix_partition *) cxt->firstsector;
if (aixlabel->magic != AIX_LABEL_MAGIC &&
aixlabel->magic != AIX_LABEL_MAGIC_SWAPPED) {
return 1;
}
+/* TODO: remove this, libfdisk has to return ENOSYS */
static int aix_add_partition(
struct fdisk_context *cxt __attribute__((__unused__)),
- struct fdisk_label *lb __attribute__((__unused__)),
- int partnum __attribute__((__unused__)),
+ size_t partnum __attribute__((__unused__)),
struct fdisk_parttype *t __attribute__((__unused__)))
{
printf(_("\tSorry - this fdisk cannot handle AIX disk labels."
};
-static int xbsd_delete_part (struct fdisk_context *cxt,
- struct fdisk_label *lb, int partnum);
+static int xbsd_delete_part (struct fdisk_context *cxt, size_t partnum);
static void xbsd_edit_disklabel (struct fdisk_context *cxt);
static void xbsd_write_bootstrap (struct fdisk_context *cxt);
-static void xbsd_change_fstype (struct fdisk_context *cxt, struct fdisk_label *lb);
+static void xbsd_change_fstype (struct fdisk_context *cxt);
static int xbsd_get_part_index (struct fdisk_context *cxt, int max);
static int xbsd_check_new_partition (struct fdisk_context *cxt, int *i);
static unsigned short xbsd_dkcksum (struct xbsd_disklabel *lp);
* so this does not mean that there is a BSD disk label.
*/
static int
-osf_probe_label(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+osf_probe_label(struct fdisk_context *cxt)
{
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
if (xbsd_readlabel (cxt, NULL, &xbsd_dlabel) == 0)
return 0;
return 1;
}
int
-btrydev (struct fdisk_context *cxt) {
+btrydev (struct fdisk_context *cxt)
+{
if (xbsd_readlabel (cxt, NULL, &xbsd_dlabel) == 0)
return -1;
printf(_("\nBSD label for device: %s\n"), cxt->dev_path);
}
#if !defined (__alpha__)
-static int
-hidden(int type) {
+static int hidden(int type)
+{
return type ^ 0x10;
}
-static int
-is_bsd_partition_type(int type) {
+static int is_bsd_partition_type(int type)
+{
return (type == FREEBSD_PARTITION ||
type == hidden(FREEBSD_PARTITION) ||
type == NETBSD_PARTITION ||
}
#endif
-static int xbsd_write_disklabel (struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int xbsd_write_disklabel (struct fdisk_context *cxt)
{
#if defined (__alpha__)
printf (_("Writing disklabel to %s.\n"), cxt->dev_path);
}
static int xbsd_add_part (struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int partnum __attribute__((__unused__)),
+ size_t partnum __attribute__((__unused__)),
struct fdisk_parttype *t __attribute__((__unused__)))
{
unsigned int begin, end;
char mesg[256];
int i, rc;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
rc = xbsd_check_new_partition(cxt, &i);
if (rc)
return rc;
xbsd_dlabel.d_partitions[i].p_offset = begin;
xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
- lb->nparts_cur = xbsd_dlabel.d_npartitions;
- fdisk_label_set_changed(lb, 1);
+ cxt->label->nparts_cur = xbsd_dlabel.d_npartitions;
+ fdisk_label_set_changed(cxt->label, 1);
return 0;
}
-static int xbsd_create_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb)
+static int xbsd_create_disklabel(struct fdisk_context *cxt)
{
char c;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
#if defined (__alpha__)
fprintf (stderr, _("%s contains no disklabel.\n"), cxt->dev_path);
#else
#endif
) == 1) {
xbsd_print_disklabel (cxt, 1);
- lb->nparts_cur = xbsd_dlabel.d_npartitions;
- lb->nparts_max = BSD_MAXPARTITIONS;
+ cxt->label->nparts_cur = xbsd_dlabel.d_npartitions;
+ cxt->label->nparts_max = BSD_MAXPARTITIONS;
return 1;
} else
return 0;
printf (_("Reading disklabel of %s at sector %d.\n"),
partname(cxt->dev_path, t+1, 0), ss + BSD_LABELSECTOR);
if (xbsd_readlabel (cxt, xbsd_part, &xbsd_dlabel) == 0)
- if (xbsd_create_disklabel (cxt, cxt->label) == 0)
+ if (xbsd_create_disklabel (cxt) == 0)
return;
break;
}
putchar ('\n');
switch (tolower (read_char(cxt, _("BSD disklabel command (m for help): ")))) {
case 'd':
- xbsd_delete_part(cxt, cxt->label,
- xbsd_get_part_index(cxt, xbsd_dlabel.d_npartitions));
+ xbsd_delete_part(cxt, xbsd_get_part_index(cxt, xbsd_dlabel.d_npartitions));
break;
case 'e':
xbsd_edit_disklabel (cxt);
list_partition_types (cxt);
break;
case 'n':
- xbsd_add_part (cxt, cxt->label, 0, 0);
+ xbsd_add_part (cxt, 0, 0);
break;
case 'p':
xbsd_print_disklabel (cxt, 0);
xbsd_print_disklabel (cxt, 1);
break;
case 't':
- xbsd_change_fstype (cxt, cxt->label);
+ xbsd_change_fstype (cxt);
break;
case 'u':
change_units(cxt);
break;
case 'w':
- xbsd_write_disklabel (cxt, cxt->label);
+ xbsd_write_disklabel (cxt);
break;
#if !defined (__alpha__)
case 'x':
}
static int xbsd_delete_part(
- struct fdisk_context *cxt __attribute__((__unused__)),
- struct fdisk_label *lb,
- int partnum)
+ struct fdisk_context *cxt,
+ size_t partnum)
{
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
xbsd_dlabel.d_partitions[partnum].p_size = 0;
xbsd_dlabel.d_partitions[partnum].p_offset = 0;
xbsd_dlabel.d_partitions[partnum].p_fstype = BSD_FS_UNUSED;
while (!xbsd_dlabel.d_partitions[xbsd_dlabel.d_npartitions-1].p_size)
xbsd_dlabel.d_npartitions--;
- lb->nparts_cur = xbsd_dlabel.d_npartitions;
- fdisk_label_set_changed(lb, 1);
+ cxt->label->nparts_cur = xbsd_dlabel.d_npartitions;
+ fdisk_label_set_changed(cxt->label, 1);
return 0;
}
void
-xbsd_print_disklabel (struct fdisk_context *cxt, int show_all) {
+xbsd_print_disklabel (struct fdisk_context *cxt, int show_all)
+{
struct xbsd_disklabel *lp = &xbsd_dlabel;
struct xbsd_partition *pp;
FILE *f = stdout;
}
/* TODO: remove this, use regular change_partition_type() in fdisk.c */
-static void
-xbsd_change_fstype (
- struct fdisk_context *cxt,
- struct fdisk_label *lb)
+static void xbsd_change_fstype (struct fdisk_context *cxt)
{
int i;
struct fdisk_parttype *t;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
i = xbsd_get_part_index (cxt, xbsd_dlabel.d_npartitions);
t = read_partition_type(cxt);
if (t) {
xbsd_dlabel.d_partitions[i].p_fstype = t->type;
fdisk_free_parttype(t);
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
}
}
}
static int
-xbsd_check_new_partition(struct fdisk_context *cxt, int *i) {
-
+xbsd_check_new_partition(struct fdisk_context *cxt, int *i)
+{
/* room for more? various BSD flavours have different maxima */
if (xbsd_dlabel.d_npartitions == BSD_MAXPARTITIONS) {
int t;
static struct fdisk_parttype *xbsd_get_parttype(
struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int n)
+ size_t n)
{
struct fdisk_parttype *t;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
if (n >= xbsd_dlabel.d_npartitions)
return NULL;
}
static int xbsd_set_parttype(
- struct fdisk_context *cxt __attribute__((__unused__)),
- struct fdisk_label *lb,
- int partnum,
+ struct fdisk_context *cxt,
+ size_t partnum,
struct fdisk_parttype *t)
{
struct xbsd_partition *p;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
if (partnum >= xbsd_dlabel.d_npartitions || !t || t->type > UINT8_MAX)
return -EINVAL;
return 0;
p->p_fstype = t->type;
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
return 0;
}
warn_alignment(cxt);
}
-static int dos_delete_partition(
- struct fdisk_context *cxt __attribute__ ((__unused__)),
- struct fdisk_label *lb,
- int n)
+static int dos_delete_partition(struct fdisk_context *cxt, size_t partnum)
{
- size_t partnum = (size_t) n; /* TODO: use size_t in API */
struct pte *pe = &ptes[partnum];
struct partition *p = pe->part_table;
struct partition *q = pe->ext_pointer;
clear_partition(ptes[partnum].part_table);
}
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
return 0;
}
if (!get_nr_sects(pe->part_table) &&
(cxt->label->nparts_max > 5 || ptes[4].part_table->sys_ind)) {
printf(_("omitting empty partition (%zd)\n"), i+1);
- dos_delete_partition(cxt, cxt->label, i);
+ dos_delete_partition(cxt, i);
goto remove; /* numbering changed */
}
}
printf(_("Disk identifier: 0x%08x\n"), mbr_get_id(cxt->firstsector));
}
-static int dos_create_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int dos_create_disklabel(struct fdisk_context *cxt)
{
unsigned int id;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, DOS));
+
/* random disk signature */
random_get_bytes(&id, sizeof(id));
DBG(CONTEXT, dbgprint("DOS PT geometry: heads=%u, sectors=%u", *ph, *ps));
}
-static int dos_reset_alignment(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int dos_reset_alignment(struct fdisk_context *cxt)
{
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, DOS));
+
/* overwrite necessary stuff by DOS deprecated stuff */
if (is_dos_compatible(cxt)) {
if (cxt->geom.sectors)
return 0;
}
-static int dos_probe_label(struct fdisk_context *cxt, struct fdisk_label *lb)
+static int dos_probe_label(struct fdisk_context *cxt)
{
size_t i;
unsigned int h = 0, s = 0;
assert(cxt);
assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, DOS));
if (!mbr_is_valid_magic(cxt->firstsector))
return 0;
"table %zd will be corrected by w(rite)\n"),
part_table_flag(pe->sectorbuffer), i + 1);
pe->changed = 1;
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
}
}
}
}
-static int dos_verify_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int dos_verify_disklabel(struct fdisk_context *cxt)
{
size_t i, j;
sector_t total = 1, n_sectors = cxt->total_sectors;
last[cxt->label->nparts_max];
struct partition *p;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, DOS));
+
fill_bounds(cxt, first, last);
for (i = 0; i < cxt->label->nparts_max; i++) {
struct pte *pe = &ptes[i];
*/
static int dos_add_partition(
struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int partnum __attribute__ ((__unused__)),
+ size_t partnum __attribute__ ((__unused__)),
struct fdisk_parttype *t)
{
size_t i, free_primary = 0;
int rc = 0;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, DOS));
+
for (i = 0; i < 4; i++)
free_primary += !ptes[i].part_table->sys_ind;
return 0;
}
-static int dos_write_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int dos_write_disklabel(struct fdisk_context *cxt)
{
size_t i;
int rc = 0;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, DOS));
+
/* MBR (primary partitions) */
if (!MBRbuffer_changed) {
for (i = 0; i < 4; i++)
static struct fdisk_parttype *dos_get_parttype(
struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int partnum)
+ size_t partnum)
{
struct fdisk_parttype *t;
struct partition *p;
- if (partnum < 0 || (size_t) partnum >= cxt->label->nparts_max)
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
+ if (partnum >= cxt->label->nparts_max)
return NULL;
p = ptes[partnum].part_table;
static int dos_set_parttype(
struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int partnum,
+ size_t partnum,
struct fdisk_parttype *t)
{
struct partition *p;
- if (partnum < 0 || (size_t) partnum >= cxt->label->nparts_max
- || !t || t->type > UINT8_MAX)
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, OSF));
+
+ if (partnum >= cxt->label->nparts_max || !t || t->type > UINT8_MAX)
return -EINVAL;
p = ptes[partnum].part_table;
"information.\n\n"));
p->sys_ind = t->type;
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
return 0;
}
size_t i, w;
assert(cxt);
+ assert(cxt->label);
assert(fdisk_is_disklabel(cxt, DOS));
if (is_garbage_table()) {
static int dos_get_partition_status(
struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int i,
+ size_t i,
int *status)
{
struct pte *pe;
struct partition *p;
assert(cxt);
+ assert(cxt->label);
assert(fdisk_is_disklabel(cxt, DOS));
- if (!status || i < 0 || (size_t) i >= cxt->label->nparts_max)
+ if (!status || i >= cxt->label->nparts_max)
return -EINVAL;
*status = FDISK_PARTSTAT_NONE;
}
static int
-mac_probe_label(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+mac_probe_label(struct fdisk_context *cxt)
{
struct mac_partition *maclabel = (struct mac_partition *) cxt->firstsector;
static int mac_add_partition(
struct fdisk_context *cxt __attribute__ ((__unused__)),
- struct fdisk_label *lb __attribute__((__unused__)),
- int partnum __attribute__ ((__unused__)),
+ size_t partnum __attribute__ ((__unused__)),
struct fdisk_parttype *t __attribute__ ((__unused__)))
{
printf(_("\tSorry - this fdisk cannot handle Mac disk labels."
}
static int
-sgi_probe_label(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+sgi_probe_label(struct fdisk_context *cxt)
{
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SGI));
+
if (sizeof(sgilabel) > 512) {
fprintf(stderr,
_("According to MIPS Computer Systems, Inc the "
}
static int
-sgi_check_bootfile(struct fdisk_context *cxt, const char* aFile) {
+sgi_check_bootfile(struct fdisk_context *cxt, const char* aFile)
+{
if (strlen(aFile) < 3) /* "/a\n" is minimum */ {
printf(_("\nInvalid Bootfile!\n"
"\tThe bootfile must be an absolute non-zero pathname,\n"
}
-static int sgi_write_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int sgi_write_disklabel(struct fdisk_context *cxt)
{
+
sgiinfo *info = NULL;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SGI));
+
sgilabel->csum = 0;
sgilabel->csum = SSWAP32(two_s_complement_32bit_sum(
(unsigned int*)sgilabel,
}
}
-static int sgi_verify_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int sgi_verify_disklabel(struct fdisk_context *cxt)
{
int Index[16]; /* list of valid partitions */
int sortcount = 0; /* number of used partitions, i.e. non-zero lengths */
long long gap = 0; /* count unused blocks */
unsigned int lastblock = sgi_get_lastblock(cxt);
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SGI));
+
clearfreelist();
for (i=0; i<16; i++) {
if (sgi_get_num_sectors(cxt, i) != 0) {
* < 0 : there is an overlap
* > 0 : there is still some vacant space
*/
- return sgi_verify_disklabel(cxt, cxt->label);
+ return sgi_verify_disklabel(cxt);
}
return -1;
}
-static int sgi_set_partition(struct fdisk_context *cxt, int i,
+static int sgi_set_partition(struct fdisk_context *cxt, size_t i,
unsigned int start, unsigned int length, int sys)
{
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SGI));
+
sgilabel->partitions[i].id = SSWAP32(sys);
sgilabel->partitions[i].num_sectors = SSWAP32(length);
sgilabel->partitions[i].start_sector = SSWAP32(start);
}
}
-static int sgi_delete_partition(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int partnum)
+static int sgi_delete_partition(struct fdisk_context *cxt, size_t partnum)
{
int rc;
assert(cxt);
assert(cxt->label);
- if (partnum < 0 || (size_t) partnum > cxt->label->nparts_max)
+ if (partnum > cxt->label->nparts_max)
return -EINVAL;
rc = sgi_set_partition(cxt, partnum, 0, 0, 0);
}
static int sgi_add_partition(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int n,
+ size_t n,
struct fdisk_parttype *t)
{
char mesg[256];
unsigned int first=0, last=0;
int sys = t ? t->type : SGI_XFS;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SGI));
+
if (n == 10)
sys = SGI_VOLUME;
else if (n == 8)
sys = 0;
if (sgi_get_num_sectors(cxt, n)) {
- printf(_("Partition %d is already defined. Delete "
+ printf(_("Partition %zd is already defined. Delete "
"it before re-adding it.\n"), n + 1);
return -EINVAL;
}
return 0;
}
-static int sgi_create_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int sgi_create_disklabel(struct fdisk_context *cxt)
{
struct hd_geometry geometry;
struct {
int res; /* the result from the ioctl */
int sec_fac; /* the sector factor */
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SGI));
+
sec_fac = cxt->sector_size / 512; /* determine the sector factor */
fprintf(stderr,
return info;
}
-static struct fdisk_parttype *sgi_get_parttype(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int n)
+static struct fdisk_parttype *sgi_get_parttype(struct fdisk_context *cxt, size_t n)
{
struct fdisk_parttype *t;
- if (n < 0 || (size_t) n >= cxt->label->nparts_max)
+ if (n >= cxt->label->nparts_max)
return NULL;
t = fdisk_get_parttype_from_code(cxt, sgi_get_sysid(cxt, n));
}
static int sgi_set_parttype(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int i,
+ size_t i,
struct fdisk_parttype *t)
{
- if (i < 0 || (size_t) i >= cxt->label->nparts_max
- || !t || t->type > UINT32_MAX)
+ if (i >= cxt->label->nparts_max || !t || t->type > UINT32_MAX)
return -EINVAL;
if (sgi_get_num_sectors(cxt, i) == 0) /* caught already before, ... */ {
static int sgi_get_partition_status(
struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int i,
+ size_t i,
int *status)
{
assert(cxt);
assert(fdisk_is_disklabel(cxt, SGI));
- if (!status || i < 0 || (size_t) i >= cxt->label->nparts_max)
+ if (!status || i >= cxt->label->nparts_max)
return -EINVAL;
*status = FDISK_PARTSTAT_NONE;
struct sun_disk_label *header; /* on-disk data (pointer to cxt->firstsector) */
};
-#define is_sun_label(_l) ((_l)->id == FDISK_DISKLABEL_SUN)
-
static struct fdisk_parttype sun_parttypes[] = {
{SUN_TAG_UNASSIGNED, N_("Unassigned")},
{SUN_TAG_BOOT, N_("Boot")},
#define SSWAP32(x) (other_endian ? __swap32(x) \
: (uint32_t)(x))
-static inline struct sun_disk_label *
-label_get_sun_disklabel(struct fdisk_label *lb)
+/* return poiter buffer with on-disk data */
+static inline struct sun_disk_label *self_disklabel(struct fdisk_context *cxt)
{
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- return ((struct fdisk_sun_label *) lb)->header;
+ return ((struct fdisk_sun_label *) cxt->label)->header;
}
-#define context_get_sun_disklabel(_c) label_get_sun_disklabel((_c)->label)
+/* return in-memory sun fdisk data */
+static inline struct fdisk_sun_label *self_label(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
+
+ return (struct fdisk_sun_label *) cxt->label;
+}
-int sun_is_empty_type(struct fdisk_context *cxt, int i)
+int sun_is_empty_type(struct fdisk_context *cxt, size_t i)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
return (!sunlabel->partitions[i].num_sectors ||
!sunlabel->part_tags[i].tag);
}
-static void set_sun_partition(struct fdisk_context *cxt,
- int i, uint32_t start, uint32_t stop, uint16_t sysid)
+static void set_sun_partition(struct fdisk_context *cxt, size_t i,
+ uint32_t start,uint32_t stop, uint16_t sysid)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
sunlabel->part_tags[i].tag = SSWAP16(sysid);
sunlabel->part_tags[i].flag = SSWAP16(0);
print_partition_size(cxt, i + 1, start, stop, sysid);
}
-static size_t partitions_in_use(struct fdisk_label *lb)
+static size_t count_used_partitions(struct fdisk_context *cxt)
{
- struct sun_disk_label *sunlabel = label_get_sun_disklabel(lb);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
size_t ct = 0, i;
assert(sunlabel);
- for (i = 0; i < lb->nparts_max; i++) {
+ for (i = 0; i < cxt->label->nparts_max; i++) {
if (sunlabel->partitions[i].num_sectors)
ct++;
}
return ct;
}
-static int sun_probe_label(struct fdisk_context *cxt, struct fdisk_label *lb)
+static int sun_probe_label(struct fdisk_context *cxt)
{
struct fdisk_sun_label *sun;
struct sun_disk_label *sunlabel;
int need_fixing = 0;
assert(cxt);
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- sunlabel = (struct sun_disk_label *) cxt->firstsector;
+ sunlabel = self_disklabel(cxt);
if (sunlabel->magic != SUN_LABEL_MAGIC &&
sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) {
}
/* map first sector buffer to sun header */
- sun = (struct fdisk_sun_label *) lb;
+ sun = (struct fdisk_sun_label *) cxt->label;
sun->header = (struct sun_disk_label *) cxt->firstsector;
- lb->nparts_max = SUN_NUM_PARTITIONS;
+ cxt->label->nparts_max = SUN_NUM_PARTITIONS;
cxt->geom.heads = SSWAP16(sunlabel->nhead);
cxt->geom.cylinders = SSWAP16(sunlabel->ncyl);
cxt->geom.sectors = SSWAP16(sunlabel->nsect);
csum ^= *ush++;
sunlabel->cksum = csum;
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
}
- lb->nparts_cur = partitions_in_use(lb);
+ cxt->label->nparts_cur = count_used_partitions(cxt);
return 1;
}
-static int sun_create_disklabel(struct fdisk_context *cxt, struct fdisk_label *lb)
+static int sun_create_disklabel(struct fdisk_context *cxt)
{
struct hd_geometry geometry;
sector_t llsectors, llcyls;
struct sun_disk_label *sunlabel; /* on disk data */
assert(cxt);
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
fprintf(stderr, _("Building a new Sun disklabel.\n"));
/* map first sector to header */
fdisk_zeroize_firstsector(cxt);
- sun = (struct fdisk_sun_label *) lb;
+ sun = (struct fdisk_sun_label *) cxt->label;
sun->header = (struct sun_disk_label *) cxt->firstsector;
sunlabel = sun->header;
#else
other_endian = 0;
#endif
- lb->nparts_max = SUN_NUM_PARTITIONS;
+ cxt->label->nparts_max = SUN_NUM_PARTITIONS;
fdisk_zeroize_firstsector(cxt);
sunlabel->magic = SSWAP16(SUN_LABEL_MAGIC);
sunlabel->cksum = csum;
}
- fdisk_label_set_changed(lb, 1);
- lb->nparts_cur = partitions_in_use(lb);
+ fdisk_label_set_changed(cxt->label, 1);
+ cxt->label->nparts_cur = count_used_partitions(cxt);
return 0;
}
-void toggle_sunflags(struct fdisk_context *cxt, int i, uint16_t mask)
+void toggle_sunflags(struct fdisk_context *cxt, size_t i, uint16_t mask)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
struct sun_tag_flag *p = &sunlabel->part_tags[i];
p->flag ^= SSWAP16(mask);
}
static void fetch_sun(struct fdisk_context *cxt,
- struct fdisk_label *lb,
uint32_t *starts,
uint32_t *lens,
uint32_t *start,
size_t i;
assert(cxt);
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- sunlabel = label_get_sun_disklabel(lb);
+ sunlabel = self_disklabel(cxt);
*start = 0;
*stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors;
- for (i = 0; i < lb->nparts_max; i++) {
+ for (i = 0; i < cxt->label->nparts_max; i++) {
struct sun_partition *part = &sunlabel->partitions[i];
struct sun_tag_flag *tag = &sunlabel->part_tags[i];
return -1;
}
-static int sun_verify_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb)
+static int sun_verify_disklabel(struct fdisk_context *cxt)
{
uint32_t starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS], start, stop;
uint32_t i,j,k,starto,endo;
int array[SUN_NUM_PARTITIONS];
assert(cxt);
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
verify_sun_starts = starts;
- fetch_sun(cxt, lb, starts, lens, &start, &stop);
+ fetch_sun(cxt, starts, lens, &start, &stop);
for (k = 0; k < 7; k++) {
for (i = 0; i < SUN_NUM_PARTITIONS; i++) {
static int sun_add_partition(
struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int n,
+ size_t n,
struct fdisk_parttype *t)
{
- struct sun_disk_label *sunlabel = label_get_sun_disklabel(lb);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
uint32_t starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS];
struct sun_partition *part = &sunlabel->partitions[n];
struct sun_tag_flag *tag = &sunlabel->part_tags[n];
unsigned int first, last;
if (part->num_sectors && tag->tag != SSWAP16(SUN_TAG_UNASSIGNED)) {
- printf(_("Partition %d is already defined. Delete "
+ printf(_("Partition %zd is already defined. Delete "
"it before re-adding it.\n"), n + 1);
return -EINVAL;
}
- fetch_sun(cxt, lb, starts, lens, &start, &stop);
+ fetch_sun(cxt, starts, lens, &start, &stop);
if (stop <= start) {
if (n == 2)
/* On the other hand, one should not use partitions
starting at block 0 in an md, or the label will
be trashed. */
- for (i = 0; i < lb->nparts_max; i++)
+ for (i = 0; i < cxt->label->nparts_max; i++)
if (lens[i] && starts[i] <= first
&& starts[i] + lens[i] > first)
break;
- if (i < lb->nparts_max && !whole_disk) {
+ if (i < cxt->label->nparts_max && !whole_disk) {
if (n == 2 && !first) {
whole_disk = 1;
break;
}
stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors; /* ancient */
stop2 = stop;
- for (i = 0; i < lb->nparts_max; i++) {
+ for (i = 0; i < cxt->label->nparts_max; i++) {
if (starts[i] > first && starts[i] < stop)
stop = starts[i];
}
sys = SUN_TAG_BACKUP;
set_sun_partition(cxt, n, first, last, sys);
- lb->nparts_cur = partitions_in_use(lb);
+ cxt->label->nparts_cur = count_used_partitions(cxt);
return 0;
}
static int sun_delete_partition(struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int partnum)
+ size_t partnum)
{
struct sun_disk_label *sunlabel;
struct sun_partition *part;
unsigned int nsec;
assert(cxt);
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- sunlabel = label_get_sun_disklabel(lb);
+ sunlabel = self_disklabel(cxt);
part = &sunlabel->partitions[partnum];
tag = &sunlabel->part_tags[partnum];
"sectors\n"), nsec);
tag->tag = SSWAP16(SUN_TAG_UNASSIGNED);
part->num_sectors = 0;
- lb->nparts_cur = partitions_in_use(lb);
- fdisk_label_set_changed(lb, 1);
+ cxt->label->nparts_cur = count_used_partitions(cxt);
+ fdisk_label_set_changed(cxt->label, 1);
return 0;
}
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, SUN));
- sunlabel = context_get_sun_disklabel(cxt);
+ sunlabel = self_disklabel(cxt);
w = strlen(cxt->dev_path);
if (xtra)
void sun_set_alt_cyl(struct fdisk_context *cxt)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
sunlabel->acyl =
SSWAP16(read_int(cxt, 0,SSWAP16(sunlabel->acyl), 65535, 0,
_("Number of alternate cylinders")));
void sun_set_ncyl(struct fdisk_context *cxt, int cyl)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
sunlabel->ncyl = SSWAP16(cyl);
}
void sun_set_xcyl(struct fdisk_context *cxt)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
sunlabel->apc =
SSWAP16(read_int(cxt, 0, SSWAP16(sunlabel->apc), cxt->geom.sectors, 0,
_("Extra sectors per cylinder")));
void sun_set_ilfact(struct fdisk_context *cxt)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
sunlabel->intrlv =
SSWAP16(read_int(cxt, 1, SSWAP16(sunlabel->intrlv), 32, 0,
_("Interleave factor")));
void sun_set_rspeed(struct fdisk_context *cxt)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
sunlabel->rpm =
SSWAP16(read_int(cxt, 1, SSWAP16(sunlabel->rpm), 100000, 0,
_("Rotation speed (rpm)")));
void sun_set_pcylcount(struct fdisk_context *cxt)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
sunlabel->pcyl =
SSWAP16(read_int(cxt, 0, SSWAP16(sunlabel->pcyl), 65535, 0,
_("Number of physical cylinders")));
}
-static int sun_write_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int sun_write_disklabel(struct fdisk_context *cxt)
{
struct sun_disk_label *sunlabel;
unsigned short *ush;
unsigned short csum = 0;
assert(cxt);
- assert(lb);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- sunlabel = label_get_sun_disklabel(lb);
+ sunlabel = self_disklabel(cxt);
ush = (unsigned short *) sunlabel;
while(ush < (unsigned short *)(&sunlabel->cksum))
static struct fdisk_parttype *sun_get_parttype(
struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int n)
+ size_t n)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel = self_disklabel(cxt);
struct fdisk_parttype *t;
assert(cxt);
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- if (n < 0 || (size_t) n >= lb->nparts_max)
+ if (n >= cxt->label->nparts_max)
return NULL;
t = fdisk_get_parttype_from_code(cxt, SSWAP16(sunlabel->part_tags[n].tag));
static int sun_set_parttype(
struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int i,
+ size_t i,
struct fdisk_parttype *t)
{
struct sun_disk_label *sunlabel;
struct sun_tag_flag *tag;
assert(cxt);
- assert(lb);
- assert(is_sun_label(lb));
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- sunlabel = label_get_sun_disklabel(lb);
+ sunlabel = self_disklabel(cxt);
- if (i < 0 || (size_t) i >= lb->nparts_max || !t || t->type > UINT16_MAX)
+ if (i >= cxt->label->nparts_max || !t || t->type > UINT16_MAX)
return -EINVAL;
if (i == 2 && t->type != SUN_TAG_BACKUP)
}
-static int sun_reset_alignment(struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)))
+static int sun_reset_alignment(struct fdisk_context *cxt)
{
/* this is shared with DOS ... */
update_units(cxt);
static int sun_get_partition_status(
struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int i,
+ size_t i,
int *status)
{
- struct sun_disk_label *sunlabel = context_get_sun_disklabel(cxt);
+ struct sun_disk_label *sunlabel;
+
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, SUN));
- if (!status || i < 0 || (size_t) i >= lb->nparts_max)
+ if (!status || i >= cxt->label->nparts_max)
return -EINVAL;
+ sunlabel = self_disklabel(cxt);
*status = FDISK_PARTSTAT_NONE;
if (sunlabel->partitions[i].num_sectors)
#define SUN_LABEL_MAGIC_SWAPPED 0xBEDA
/* fdisksunlabel.c */
-extern int sun_change_sysid(struct fdisk_context *cxt, int i, uint16_t sys);
+extern int sun_change_sysid(struct fdisk_context *cxt, size_t i, uint16_t sys);
extern void sun_list_table(struct fdisk_context *cxt, int xtra);
extern void sun_set_alt_cyl(struct fdisk_context *cxt);
extern void sun_set_ncyl(struct fdisk_context *cxt, int cyl);
extern void sun_set_ilfact(struct fdisk_context *cxt);
extern void sun_set_rspeed(struct fdisk_context *cxt);
extern void sun_set_pcylcount(struct fdisk_context *cxt);
-extern void toggle_sunflags(struct fdisk_context *cxt, int i, uint16_t mask);
-extern int sun_is_empty_type(struct fdisk_context *cxt, int i);
+extern void toggle_sunflags(struct fdisk_context *cxt, size_t i, uint16_t mask);
+
+extern int sun_is_empty_type(struct fdisk_context *cxt, size_t i);
#endif /* FDISK_SUN_LABEL_H */
/* overwrite default by label stuff */
if (cxt->label && cxt->label->op->reset_alignment)
- rc = cxt->label->op->reset_alignment(cxt, cxt->label);
+ rc = cxt->label->op->reset_alignment(cxt);
DBG(LABEL, dbgprint("%s alignment reseted to: "
"first LBA=%ju, grain=%lu [rc=%d]",
*/
struct fdisk_label_operations {
/* probe disk label */
- int (*probe)(struct fdisk_context *cxt, struct fdisk_label *lb);
+ int (*probe)(struct fdisk_context *cxt);
/* write in-memory changes to disk */
- int (*write)(struct fdisk_context *cxt, struct fdisk_label *lb);
+ int (*write)(struct fdisk_context *cxt);
/* verify the partition table */
- int (*verify)(struct fdisk_context *cxt, struct fdisk_label *lb);
+ int (*verify)(struct fdisk_context *cxt);
/* create new disk label */
- int (*create)(struct fdisk_context *cxt, struct fdisk_label *lb);
+ int (*create)(struct fdisk_context *cxt);
/* new partition */
- int (*part_add)(struct fdisk_context *cxt, struct fdisk_label *lb,
- int partnum,
+ int (*part_add)(struct fdisk_context *cxt,
+ size_t partnum,
struct fdisk_parttype *t);
/* delete partition */
- int (*part_delete)(struct fdisk_context *cxt, struct fdisk_label *lb,
- int partnum);
+ int (*part_delete)(struct fdisk_context *cxt,
+ size_t partnum);
/* get partition type */
struct fdisk_parttype *(*part_get_type)(struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int partnum);
+ size_t partnum);
/* set partition type */
- int (*part_set_type)(struct fdisk_context *cxt, struct fdisk_label *lb,
- int partnum,
+ int (*part_set_type)(struct fdisk_context *cxt,
+ size_t 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);
+ int (*part_get_status)(struct fdisk_context *cxt,
+ size_t partnum,
+ int *status);
/* refresh alignment setting */
- int (*reset_alignment)(struct fdisk_context *cxt,
- struct fdisk_label *lb);
+ int (*reset_alignment)(struct fdisk_context *cxt);
/* free in-memory label stuff */
void (*free)(struct fdisk_label *lb);
+
/* deinit in-memory label stuff */
void (*deinit)(struct fdisk_label *lb);
};
static void gpt_deinit(struct fdisk_label *lb);
-static inline struct fdisk_gpt_label *gpt_label(struct fdisk_context *cxt)
+static inline struct fdisk_gpt_label *self_label(struct fdisk_context *cxt)
{
- assert(cxt);
- assert(cxt->label);
- assert(fdisk_is_disklabel(cxt, GPT));
-
return (struct fdisk_gpt_label *) cxt->label;
}
return totfound;
}
-static int gpt_probe_label(struct fdisk_context *cxt, struct fdisk_label *lb)
+static int gpt_probe_label(struct fdisk_context *cxt)
{
int mbr_type;
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
- if (!cxt || !lb)
- goto failed;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
mbr_type = valid_pmbr(cxt);
if (!mbr_type)
/* OK, probing passed, now initialize backup header and fdisk variables. */
gpt->bheader = gpt_read_header(cxt, last_lba(cxt), NULL);
- lb->nparts_max = le32_to_cpu(gpt->pheader->npartition_entries);
- lb->nparts_cur = partitions_in_use(gpt->pheader, gpt->ents);
+ cxt->label->nparts_max = le32_to_cpu(gpt->pheader->npartition_entries);
+ cxt->label->nparts_cur = partitions_in_use(gpt->pheader, gpt->ents);
printf(_("\nWARNING: fdisk GPT support is currently new, and therefore "
"in an experimental phase. Use at your own discretion.\n\n"));
return 1;
failed:
DBG(LABEL, dbgprint("GPT probe failed"));
- gpt_deinit(lb);
+ gpt_deinit(cxt->label);
return 0;
}
int xtra __attribute__ ((__unused__)))
{
uint32_t i;
- struct fdisk_gpt_label *gpt = gpt_label(cxt);
- uint64_t fu = le64_to_cpu(gpt->pheader->first_usable_lba);
- uint64_t lu = le64_to_cpu(gpt->pheader->last_usable_lba);
+ struct fdisk_gpt_label *gpt;
+ uint64_t fu;
+ uint64_t lu;
+
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
+ fu = le64_to_cpu(gpt->pheader->first_usable_lba);
+ lu = le64_to_cpu(gpt->pheader->last_usable_lba);
printf("\n# Start End Size Type Name\n");
off_t offset;
struct gpt_legacy_mbr *pmbr = NULL;
- if (!cxt || !cxt->firstsector)
- return -EINVAL;
+ assert(cxt);
+ assert(cxt->firstsector);
pmbr = (struct gpt_legacy_mbr *) cxt->firstsector;
* Returns 0 if successful write, otherwise, a corresponding error.
* Any indication of error will abort the operation.
*/
-static int gpt_write_disklabel(struct fdisk_context *cxt, struct fdisk_label *lb)
+static int gpt_write_disklabel(struct fdisk_context *cxt)
{
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
- if (!cxt || !lb)
- goto err0;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
/* we do not want to mess up hybrid MBRs by creating a valid pmbr */
if (valid_pmbr(cxt) == GPT_MBR_HYBRID)
* - primary and backup header validations
* - paritition validations
*/
-static int gpt_verify_disklabel(struct fdisk_context *cxt, struct fdisk_label *lb)
+static int gpt_verify_disklabel(struct fdisk_context *cxt)
{
int nerror = 0, ptnum;
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
+
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
if (!gpt || !gpt->bheader) {
nerror++;
/* Delete a single GPT partition, specified by partnum. */
static int gpt_delete_partition(struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int partnum)
+ size_t partnum)
{
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
- if (!cxt || partnum < 0 || !gpt)
- return -EINVAL;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
- if (partition_unused(&gpt->ents[partnum]))
+ gpt = self_label(cxt);
+
+ if (partnum >= cxt->label->nparts_max
+ || partition_unused(&gpt->ents[partnum]))
return -EINVAL;
/* hasta la vista, baby! */
else {
gpt_recompute_crc(gpt->pheader, gpt->ents);
gpt_recompute_crc(gpt->bheader, gpt->ents);
- lb->nparts_cur--;
- fdisk_label_set_changed(lb, 1);
+ cxt->label->nparts_cur--;
+ fdisk_label_set_changed(cxt->label, 1);
}
return 0;
* Returns 0 on success, or negative upon failure.
*/
static int gpt_create_new_partition(struct fdisk_context *cxt,
- int partnum, uint64_t fsect, uint64_t lsect,
+ size_t partnum, uint64_t fsect, uint64_t lsect,
struct gpt_guid *type,
struct gpt_entry *entries)
{
struct gpt_entry *e = NULL;
struct fdisk_gpt_label *gpt;
- if (!cxt || fsect > lsect || partnum < 0)
- return -EINVAL;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
- gpt = gpt_label(cxt);
+ gpt = self_label(cxt);
+
+ if (fsect > lsect || partnum >= cxt->label->nparts_max)
+ return -EINVAL;
e = xcalloc(1, sizeof(*e));
e->lba_end = cpu_to_le64(lsect);
/* Performs logical checks to add a new partition entry */
static int gpt_add_partition(
struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int partnum,
+ size_t partnum,
struct fdisk_parttype *t)
{
uint64_t user_f, user_l; /* user input ranges for first and last sectors */
uint64_t disk_f, disk_l; /* first and last available sector ranges on device*/
uint64_t dflt_f, dflt_l; /* largest segment (default) */
struct gpt_guid uuid = GPT_DEFAULT_ENTRY_GUID;
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
struct gpt_header *pheader;
struct gpt_entry *ents;
- /* check basic tests before even considering adding a new partition */
- if (!cxt || partnum < 0 || !gpt)
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
+
+ if (partnum >= cxt->label->nparts_max)
return -EINVAL;
pheader = gpt->pheader;
printf(_("Could not create partition %d\n"), partnum + 1);
else {
printf(_("Created partition %d\n"), partnum + 1);
- lb->nparts_cur++;
- fdisk_label_set_changed(lb, 1);
+ cxt->label->nparts_cur++;
+ fdisk_label_set_changed(cxt->label, 1);
}
return 0;
/*
* Create a new GPT disklabel - destroys any previous data.
*/
-static int gpt_create_disklabel(struct fdisk_context *cxt, struct fdisk_label *lb)
+static int gpt_create_disklabel(struct fdisk_context *cxt)
{
int rc = 0;
ssize_t entry_sz = 0;
struct gpt_guid *uid;
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
+
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
/* label private stuff has to be empty, see gpt_deinit() */
- assert(gpt);
assert(gpt->pheader == NULL);
assert(gpt->bheader == NULL);
gpt_recompute_crc(gpt->pheader, gpt->ents);
gpt_recompute_crc(gpt->bheader, gpt->ents);
- lb->nparts_max = le32_to_cpu(gpt->pheader->npartition_entries);
- lb->nparts_cur = 0;
+ cxt->label->nparts_max = le32_to_cpu(gpt->pheader->npartition_entries);
+ cxt->label->nparts_cur = 0;
uid = &gpt->pheader->disk_guid;
fprintf(stderr, ("Building a new GPT disklabel "
uid->node[0], uid->node[1],
uid->node[2], uid->node[3],
uid->node[4], uid->node[5]);
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
done:
return rc;
}
static struct fdisk_parttype *gpt_get_partition_type(
struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int i)
+ size_t i)
{
struct fdisk_parttype *t;
struct gpt_guid uuid;
char str[37];
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
- if (!cxt)
- return NULL;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
- if (!cxt || !gpt || i < 0
- || (uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries))
+ gpt = self_label(cxt);
+
+ if ((uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries))
return NULL;
uuid = gpt->ents[i].partition_type_guid;
static int gpt_set_partition_type(
struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int i,
+ size_t i,
struct fdisk_parttype *t)
{
struct gpt_guid uuid;
- struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
+ struct fdisk_gpt_label *gpt;
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
- if (!cxt || !gpt || i < 0
- || (uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries)
+ gpt = self_label(cxt);
+ if ((uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries)
|| !t || !t->typestr || string_to_uuid(t->typestr, &uuid) != 0)
return -EINVAL;
gpt_recompute_crc(gpt->pheader, gpt->ents);
gpt_recompute_crc(gpt->bheader, gpt->ents);
- fdisk_label_set_changed(lb, 1);
+ fdisk_label_set_changed(cxt->label, 1);
return 0;
}
static int gpt_get_partition_status(
struct fdisk_context *cxt,
- struct fdisk_label *lb __attribute__((__unused__)),
- int i,
+ size_t i,
int *status)
{
- struct fdisk_gpt_label *gpt = gpt_label(cxt);
+ struct fdisk_gpt_label *gpt;
struct gpt_entry *e;
- if (!cxt || !gpt || i < 0 || !status
- || (uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries))
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
+
+ if (!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))
+ if (!partition_unused(e) || gpt_partition_size(e))
*status = FDISK_PARTSTAT_USED;
return 0;
DBG(LABEL, dbgprint("probing for %s", lb->name));
cxt->label = lb;
- rc = lb->op->probe(cxt, lb);
+ rc = lb->op->probe(cxt);
cxt->label = org;
if (rc != 1) {
if (!cxt->label->op->write)
return -ENOSYS;
- return cxt->label->op->write(cxt, cxt->label);
+ return cxt->label->op->write(cxt);
}
/**
if (!cxt->label->op->verify)
return -ENOSYS;
- return cxt->label->op->verify(cxt, cxt->label);
+ return cxt->label->op->verify(cxt);
}
/**
*
* Returns 0.
*/
-int fdisk_add_partition(struct fdisk_context *cxt, int partnum,
+int fdisk_add_partition(struct fdisk_context *cxt, size_t partnum,
struct fdisk_parttype *t)
{
if (!cxt || !cxt->label)
if (!cxt->label->op->part_add)
return -ENOSYS;
- DBG(LABEL, dbgprint("adding new partition number %d", partnum));
- cxt->label->op->part_add(cxt, cxt->label, partnum, t);
+ DBG(LABEL, dbgprint("adding new partition number %zd", partnum));
+ cxt->label->op->part_add(cxt, partnum, t);
return 0;
}
*
* Returns 0 on success, otherwise, a corresponding error.
*/
-int fdisk_delete_partition(struct fdisk_context *cxt, int partnum)
+int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum)
{
if (!cxt || !cxt->label)
return -EINVAL;
if (!cxt->label->op->part_delete)
return -ENOSYS;
- DBG(LABEL, dbgprint("deleting %s partition number %d",
+ DBG(LABEL, dbgprint("deleting %s partition number %zd",
cxt->label->name, partnum));
- return cxt->label->op->part_delete(cxt, cxt->label, partnum);
+ return cxt->label->op->part_delete(cxt, partnum);
}
/**
return -ENOSYS;
fdisk_reset_alignment(cxt);
- return cxt->label->op->create(cxt, cxt->label);
+ return cxt->label->op->create(cxt);
}
/**
*
* Returns partition type or NULL upon failure.
*/
-struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum)
+struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt,
+ size_t partnum)
{
if (!cxt || !cxt->label || !cxt->label->op->part_get_type)
return NULL;
- DBG(LABEL, dbgprint("partition: %d: get type", partnum));
- return cxt->label->op->part_get_type(cxt, cxt->label, partnum);
+ DBG(LABEL, dbgprint("partition: %zd: get type", partnum));
+ return cxt->label->op->part_get_type(cxt, partnum);
}
/**
*
* Returns 0 on success, < 0 on error.
*/
-int fdisk_set_partition_type(struct fdisk_context *cxt, int partnum,
+int fdisk_set_partition_type(struct fdisk_context *cxt,
+ size_t partnum,
struct fdisk_parttype *t)
{
if (!cxt || !cxt->label)
if (!cxt->label->op->part_set_type)
return -ENOSYS;
- DBG(LABEL, dbgprint("partition: %d: set type", partnum));
- return cxt->label->op->part_set_type(cxt, cxt->label, partnum, t);
+ DBG(LABEL, dbgprint("partition: %zd: set type", partnum));
+ return cxt->label->op->part_set_type(cxt, partnum, t);
}
/**
*
* Returns 0 on success, otherwise, a corresponding error.
*/
-int fdisk_partition_get_status(struct fdisk_context *cxt, int partnum, int *status)
+int fdisk_partition_get_status(struct fdisk_context *cxt,
+ size_t 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);
+ return cxt->label->op->part_get_status(cxt, partnum, status);
}
void fdisk_label_set_changed(struct fdisk_label *lb, int changed)
{
assert(lb);
-
lb->changed = changed ? 1 : 0;
}
extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
-extern int fdisk_add_partition(struct fdisk_context *cxt, int partnum, struct fdisk_parttype *t);
-extern int fdisk_delete_partition(struct fdisk_context *cxt, int partnum);
+extern int fdisk_add_partition(struct fdisk_context *cxt, size_t partnum, struct fdisk_parttype *t);
+extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum);
-extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum);
-extern int fdisk_set_partition_type(struct fdisk_context *cxt, int partnum,
+extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, size_t partnum);
+extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
struct fdisk_parttype *t);
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);
+extern int fdisk_partition_get_status(struct fdisk_context *cxt, size_t partnum, int *status);
/* alignment.c */
extern int fdisk_reset_alignment(struct fdisk_context *cxt);