*s = ls % cxt->geom.sectors + 1; /* sectors count from 1 */
}
-static void check_consistency(struct fdisk_context *cxt, struct partition *p, int partition) {
+void check_consistency(struct fdisk_context *cxt, struct partition *p, int partition)
+{
unsigned int pbc, pbh, pbs; /* physical beginning c, h, s */
unsigned int pec, peh, pes; /* physical ending c, h, s */
unsigned int lbc, lbh, lbs; /* logical beginning c, h, s */
}
}
-static void
-check_alignment(struct fdisk_context *cxt, sector_t lba, int partition)
+void check_alignment(struct fdisk_context *cxt, sector_t lba, int partition)
{
if (!lba_is_aligned(cxt, lba))
printf(_("Partition %i does not start on physical sector boundary.\n"),
}
}
-static void
-check(struct fdisk_context *cxt, int n, unsigned int h, unsigned int s, unsigned int c,
- unsigned int start) {
+void check(struct fdisk_context *cxt, int n,
+ unsigned int h, unsigned int s, unsigned int c,
+ unsigned int start)
+{
unsigned int total, real_s, real_c;
real_s = sector(s) - 1;
"total %d\n"), n, start, total);
}
-static void
-verify(struct fdisk_context *cxt) {
- int i, j;
- sector_t total = 1, n_sectors = cxt->total_sectors;
- unsigned long long first[partitions], last[partitions];
- struct partition *p;
-
+static void verify(struct fdisk_context *cxt)
+{
if (warn_geometry(cxt))
return;
- if (disklabel == SUN_LABEL) {
- verify_sun(cxt);
- return;
- }
-
- if (disklabel == SGI_LABEL) {
- verify_sgi(cxt, 1);
- return;
- }
-
- fill_bounds(first, last);
- for (i = 0; i < partitions; i++) {
- struct pte *pe = &ptes[i];
-
- p = pe->part_table;
- if (p->sys_ind && !IS_EXTENDED (p->sys_ind)) {
- check_consistency(cxt, p, i);
- check_alignment(cxt, get_partition_start(pe), i);
- if (get_partition_start(pe) < first[i])
- printf(_("Warning: bad start-of-data in "
- "partition %d\n"), i + 1);
- check(cxt, i + 1, p->end_head, p->end_sector, p->end_cyl,
- last[i]);
- total += last[i] + 1 - first[i];
- for (j = 0; j < i; j++)
- if ((first[i] >= first[j] && first[i] <= last[j])
- || ((last[i] <= last[j] && last[i] >= first[j]))) {
- printf(_("Warning: partition %d overlaps "
- "partition %d.\n"), j + 1, i + 1);
- total += first[i] >= first[j] ?
- first[i] : first[j];
- total -= last[i] <= last[j] ?
- last[i] : last[j];
- }
- }
- }
-
- if (extended_offset) {
- struct pte *pex = &ptes[ext_index];
- sector_t e_last = get_start_sect(pex->part_table) +
- get_nr_sects(pex->part_table) - 1;
-
- for (i = 4; i < partitions; i++) {
- total++;
- p = ptes[i].part_table;
- if (!p->sys_ind) {
- if (i != 4 || i + 1 < partitions)
- printf(_("Warning: partition %d "
- "is empty\n"), i + 1);
- }
- else if (first[i] < extended_offset ||
- last[i] > e_last)
- printf(_("Logical partition %d not entirely in "
- "partition %d\n"), i + 1, ext_index + 1);
- }
- }
-
- if (total > n_sectors)
- printf(_("Total allocated sectors %llu greater than the maximum"
- " %llu\n"), total, n_sectors);
- else if (total < n_sectors)
- printf(_("Remaining %lld unallocated %ld-byte sectors\n"),
- n_sectors - total, cxt->sector_size);
+ fdisk_verify_disklabel(cxt);
}
void print_partition_size(struct fdisk_context *cxt,
int (*probe)(struct fdisk_context *cxt);
/* write in-memory changes to disk */
int (*write)(struct fdisk_context *cxt);
+ /* verify the partition table */
+ int (*verify)(struct fdisk_context *cxt);
/* new partition */
void (*part_add)(struct fdisk_context *cxt, int partnum, int parttype);
/* delete partition */
extern int fdisk_delete_partition(struct fdisk_context *cxt, int partnum);
extern int fdisk_add_partition(struct fdisk_context *cxt, int partnum, int parttype);
extern int fdisk_write_disklabel(struct fdisk_context *cxt);
+extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
/* prototypes for fdisk.c */
extern char *disk_device, *line_ptr;
extern int fd, partitions;
extern unsigned int display_in_cyl_units, units_per_sector;
+
+extern void check_consistency(struct fdisk_context *cxt, struct partition *p, int partition);
+extern void check_alignment(struct fdisk_context *cxt, sector_t lba, int partition);
+extern void check(struct fdisk_context *cxt, int n, unsigned int h, unsigned int s, unsigned int c, unsigned int start);
+
extern void change_units(struct fdisk_context *cxt);
extern void fatal(struct fdisk_context *cxt, enum failure why);
extern int get_partition(struct fdisk_context *cxt, int warn, int max);
.name = "aix",
.probe = aix_probe_label,
.write = NULL,
+ .verify = NULL,
.part_add = aix_add_partition,
.part_delete = NULL,
};
.name = "bsd",
.probe = osf_probe_label,
.write = xbsd_write_disklabel,
- .part_add= xbsd_add_part,
+ .verify = NULL,
+ .part_add = xbsd_add_part,
.part_delete = xbsd_delete_part,
};
add_partition(cxt, partitions - 1, LINUX_NATIVE);
}
+static int dos_verify_disklabel(struct fdisk_context *cxt)
+{
+ int i, j;
+ sector_t total = 1, n_sectors = cxt->total_sectors;
+ unsigned long long first[partitions], last[partitions];
+ struct partition *p;
+
+ fill_bounds(first, last);
+ for (i = 0; i < partitions; i++) {
+ struct pte *pe = &ptes[i];
+
+ p = pe->part_table;
+ if (p->sys_ind && !IS_EXTENDED (p->sys_ind)) {
+ check_consistency(cxt, p, i);
+ check_alignment(cxt, get_partition_start(pe), i);
+ if (get_partition_start(pe) < first[i])
+ printf(_("Warning: bad start-of-data in "
+ "partition %d\n"), i + 1);
+ check(cxt, i + 1, p->end_head, p->end_sector, p->end_cyl,
+ last[i]);
+ total += last[i] + 1 - first[i];
+ for (j = 0; j < i; j++)
+ if ((first[i] >= first[j] && first[i] <= last[j])
+ || ((last[i] <= last[j] && last[i] >= first[j]))) {
+ printf(_("Warning: partition %d overlaps "
+ "partition %d.\n"), j + 1, i + 1);
+ total += first[i] >= first[j] ?
+ first[i] : first[j];
+ total -= last[i] <= last[j] ?
+ last[i] : last[j];
+ }
+ }
+ }
+
+ if (extended_offset) {
+ struct pte *pex = &ptes[ext_index];
+ sector_t e_last = get_start_sect(pex->part_table) +
+ get_nr_sects(pex->part_table) - 1;
+
+ for (i = 4; i < partitions; i++) {
+ total++;
+ p = ptes[i].part_table;
+ if (!p->sys_ind) {
+ if (i != 4 || i + 1 < partitions)
+ printf(_("Warning: partition %d "
+ "is empty\n"), i + 1);
+ }
+ else if (first[i] < extended_offset ||
+ last[i] > e_last)
+ printf(_("Logical partition %d not entirely in "
+ "partition %d\n"), i + 1, ext_index + 1);
+ }
+ }
+
+ if (total > n_sectors)
+ printf(_("Total allocated sectors %llu greater than the maximum"
+ " %llu\n"), total, n_sectors);
+ else if (total < n_sectors)
+ printf(_("Remaining %lld unallocated %ld-byte sectors\n"),
+ n_sectors - total, cxt->sector_size);
+
+ return 0;
+}
+
/*
* Ask the user for new partition type information (logical, extended).
* This function calls the actual partition adding logic - add_partition.
.name = "dos",
.probe = dos_probe_label,
.write = dos_write_disklabel,
+ .verify = dos_verify_disklabel,
.part_add = dos_add_partition,
.part_delete = dos_delete_partition,
};
.name = "mac",
.probe = mac_probe_label,
.write = NULL,
+ .verify = NULL,
.part_add = mac_add_partition,
.part_delete = NULL,
};
return (a > b) ? 1 : -1;
}
-static int
-sgi_gaps(struct fdisk_context *cxt) {
- /*
- * returned value is:
- * = 0 : disk is properly filled to the rim
- * < 0 : there is an overlap
- * > 0 : there is still some vacant space
- */
- return verify_sgi(cxt, 0);
-}
-
static void generic_swap(void *a, void *b, int size)
{
char t;
}
}
-
-int
-verify_sgi(struct fdisk_context *cxt, int verbose)
+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 */
- int entire = 0, i = 0;
+ int entire = 0, i = 0, verbose = 1;
unsigned int start = 0;
long long gap = 0; /* count unused blocks */
unsigned int lastblock = sgi_get_lastblock(cxt);
return (gap > 0) ? 1 : (gap == 0) ? 0 : -1;
}
+static int
+sgi_gaps(struct fdisk_context *cxt) {
+ /*
+ * returned value is:
+ * = 0 : disk is properly filled to the rim
+ * < 0 : there is an overlap
+ * > 0 : there is still some vacant space
+ */
+ return sgi_verify_disklabel(cxt);
+}
+
int
sgi_change_sysid(struct fdisk_context *cxt, int i, int sys)
{
.name = "sgi",
.probe = sgi_probe_label,
.write = sgi_write_disklabel,
+ .verify = sgi_verify_disklabel,
.part_add = sgi_add_partition,
.part_delete = sgi_delete_partition,
};
extern int sgi_get_sysid(struct fdisk_context *cxt, int i );
extern void create_sgilabel( struct fdisk_context *cxt );
extern void create_sgiinfo(struct fdisk_context *cxt);
-extern int verify_sgi(struct fdisk_context *cxt, int verbose );
extern void sgi_set_ilfact( void );
extern void sgi_set_rspeed( void );
extern void sgi_set_pcylcount( void );
return -1;
}
-void verify_sun(struct fdisk_context *cxt)
+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;
if (array[0] == -1) {
printf(_("No partitions defined\n"));
- return;
+ return 0;
}
stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors;
if (starts[array[0]])
start = (starts[array[i]] + lens[array[i]]);
if (start < stop)
printf(_("Unused gap - sectors %d-%d\n"), start, stop);
+
+ return 0;
}
static void sun_add_partition(struct fdisk_context *cxt, int n, int sys)
.name = "sun",
.probe = sun_probe_label,
.write = sun_write_disklabel,
+ .verify = sun_verify_disklabel,
.part_add = sun_add_partition,
.part_delete = sun_delete_partition,
};
extern int create_sunlabel(struct fdisk_context *cxt);
extern int sun_change_sysid(struct fdisk_context *cxt, int i, uint16_t sys);
extern void sun_list_table(struct fdisk_context *cxt, int xtra);
-extern void verify_sun(struct fdisk_context *cxt);
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_xcyl(struct fdisk_context *cxt);
return cxt->label->write(cxt);
}
+/**
+ * fdisk_verify_disklabel:
+ * @cxt: fdisk context
+ *
+ * Verifies the partition tabe.
+ *
+ * Returns 0.
+ */
+int fdisk_verify_disklabel(struct fdisk_context *cxt)
+{
+ if (!cxt)
+ return -EINVAL;
+
+ return cxt->label->verify(cxt);
+}
+
/*
* fdisk_add_partition:
* @cxt: fdisk context