From 24cd580b70fa04c7374c4f5c5fa477fc06748211 Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Sun, 17 Jun 2012 18:10:33 +0200 Subject: fdisk: API: add geometry Add device geometry to the fdisk API. While it maintains traditional behaviour, the cylinders are changed to sector_t instead of unsigned int in order to avoid dealing with truncated cylinders. A new helper is added to compute the amount of cylinders based on the heads and sectors - if a user passed -H or -S to the program, it must call this function to update the corresponding values. This patch passes regression tests. Signed-off-by: Davidlohr Bueso --- fdisk/fdiskdoslabel.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'fdisk/fdiskdoslabel.c') diff --git a/fdisk/fdiskdoslabel.c b/fdisk/fdiskdoslabel.c index abf101b32..a72a432c1 100644 --- a/fdisk/fdiskdoslabel.c +++ b/fdisk/fdiskdoslabel.c @@ -14,12 +14,12 @@ #include "fdiskdoslabel.h" #define set_hsc(h,s,c,sector) { \ - s = sector % sectors + 1; \ - sector /= sectors; \ - h = sector % heads; \ - sector /= heads; \ - c = sector & 0xff; \ - s |= (sector >> 2) & 0xc0; \ + s = sector % cxt->geom.sectors + 1; \ + sector /= cxt->geom.sectors; \ + h = sector % cxt->geom.heads; \ + sector /= cxt->geom.heads; \ + c = sector & 0xff; \ + s |= (sector >> 2) & 0xc0; \ } #define alignment_required (grain != cxt->sector_size) @@ -115,7 +115,7 @@ void dos_init(struct fdisk_context *cxt) pe->changed = 0; } - warn_geometry(); + warn_geometry(cxt); warn_limits(cxt); warn_alignment(cxt); } @@ -389,11 +389,11 @@ static void set_partition(struct fdisk_context *cxt, if (!doext) print_partition_size(cxt, i + 1, start, stop, sysid); - if (dos_compatible_flag && (start/(sectors*heads) > 1023)) - start = heads*sectors*1024 - 1; + if (dos_compatible_flag && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023)) + start = cxt->geom.heads*cxt->geom.sectors*1024 - 1; set_hsc(p->head, p->sector, p->cyl, start); - if (dos_compatible_flag && (stop/(sectors*heads) > 1023)) - stop = heads*sectors*1024 - 1; + if (dos_compatible_flag && (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023)) + stop = cxt->geom.heads*cxt->geom.sectors*1024 - 1; set_hsc(p->end_head, p->end_sector, p->end_cyl, stop); ptes[i].changed = 1; } @@ -449,7 +449,7 @@ void dos_add_partition(struct fdisk_context *cxt, int n, int sys) if (n < 4) { start = sector_offset; if (display_in_cyl_units || !cxt->total_sectors) - limit = heads * sectors * cylinders - 1; + limit = cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders - 1; else limit = cxt->total_sectors - 1; -- cgit v1.2.3-55-g7522