diff options
author | Davidlohr Bueso | 2012-06-17 18:10:33 +0200 |
---|---|---|
committer | Karel Zak | 2012-06-21 08:05:49 +0200 |
commit | 24cd580b70fa04c7374c4f5c5fa477fc06748211 (patch) | |
tree | 46adb56e5eb9188a8be50131743169f2213c5759 /fdisk/fdiskdoslabel.c | |
parent | fdisk: mark dos compatibility/CHS options deprecated in manpage (diff) | |
download | kernel-qcow2-util-linux-24cd580b70fa04c7374c4f5c5fa477fc06748211.tar.gz kernel-qcow2-util-linux-24cd580b70fa04c7374c4f5c5fa477fc06748211.tar.xz kernel-qcow2-util-linux-24cd580b70fa04c7374c4f5c5fa477fc06748211.zip |
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 <dave@gnu.org>
Diffstat (limited to 'fdisk/fdiskdoslabel.c')
-rw-r--r-- | fdisk/fdiskdoslabel.c | 24 |
1 files changed, 12 insertions, 12 deletions
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; |