summaryrefslogtreecommitdiffstats
path: root/fdisks/fdisk.c
diff options
context:
space:
mode:
authorPetr Uzel2012-07-26 16:04:24 +0200
committerKarel Zak2012-07-26 16:59:35 +0200
commitb29ce87ba499bca5eea5ff2878aa112a0162f22b (patch)
tree169371a58b9557bf886a32d8451b84af5e01fe81 /fdisks/fdisk.c
parentpartx: support -o +<attr> for adding attribute to output fields (diff)
downloadkernel-qcow2-util-linux-b29ce87ba499bca5eea5ff2878aa112a0162f22b.tar.gz
kernel-qcow2-util-linux-b29ce87ba499bca5eea5ff2878aa112a0162f22b.tar.xz
kernel-qcow2-util-linux-b29ce87ba499bca5eea5ff2878aa112a0162f22b.zip
fdisk: make grain global variable part of fdisk_context()
There is no reason for this to be global variable - it belongs to the context. Signed-off-by: Petr Uzel <petr.uzel@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/fdisk.c')
-rw-r--r--fdisks/fdisk.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index f00db4a9d..0aa8a0b27 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -132,7 +132,6 @@ int nowarn = 0, /* no warnings for fdisk -l/-s */
unsigned int user_cylinders, user_heads, user_sectors;
sector_t sector_offset = 1;
unsigned int units_per_sector = 1, display_in_cyl_units = 0;
-unsigned long grain = DEFAULT_SECTOR_SIZE;
enum fdisk_labeltype disklabel; /* Current disklabel */
static void __attribute__ ((__noreturn__)) usage(FILE *out)
@@ -300,8 +299,8 @@ lba_is_aligned(struct fdisk_context *cxt, sector_t lba)
unsigned int granularity = max(cxt->phy_sector_size, cxt->min_io_size);
unsigned long long offset;
- if (grain > granularity)
- granularity = grain;
+ if (cxt->grain > granularity)
+ granularity = cxt->grain;
offset = (lba * cxt->sector_size) & (granularity - 1);
return !((granularity + cxt->alignment_offset - offset) & (granularity - 1));
@@ -323,7 +322,7 @@ sector_t align_lba(struct fdisk_context *cxt, sector_t lba, int direction)
if (lba_is_aligned(cxt, lba))
res = lba;
else {
- sector_t sects_in_phy = grain / cxt->sector_size;
+ sector_t sects_in_phy = cxt->grain / cxt->sector_size;
if (lba < sector_offset)
res = sector_offset;
@@ -446,7 +445,7 @@ void warn_alignment(struct fdisk_context *cxt)
void
update_sector_offset(struct fdisk_context *cxt)
{
- grain = cxt->io_size;
+ cxt->grain = cxt->io_size;
if (dos_compatible_flag)
sector_offset = cxt->geom.sectors; /* usually 63 sectors */
@@ -481,12 +480,12 @@ update_sector_offset(struct fdisk_context *cxt)
sector_offset = cxt->phy_sector_size / cxt->sector_size;
/* use 1MiB grain always when possible */
- if (grain < 2048 * 512)
- grain = 2048 * 512;
+ if (cxt->grain < 2048 * 512)
+ cxt->grain = 2048 * 512;
/* don't use huge grain on small devices */
- if (cxt->total_sectors <= (grain * 4 / cxt->sector_size))
- grain = cxt->phy_sector_size;
+ if (cxt->total_sectors <= (cxt->grain * 4 / cxt->sector_size))
+ cxt->grain = cxt->phy_sector_size;
}
}