]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: make grain global variable part of fdisk_context()
authorPetr Uzel <petr.uzel@suse.cz>
Thu, 26 Jul 2012 14:04:24 +0000 (16:04 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 26 Jul 2012 14:59:35 +0000 (16:59 +0200)
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>
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskdoslabel.c

index f00db4a9d9c3664c058860180d235ab28aa2ed22..0aa8a0b27cb1f38c2ad1069b80357cab84dc0403 100644 (file)
@@ -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;
        }
 }
 
index 29b57fe59276b4388a2ca6eb20f6cfe9ae03c190..04c25e296641467c8084c44107dc481db4bd86b0 100644 (file)
@@ -121,6 +121,8 @@ struct fdisk_context {
        unsigned long sector_size;      /* logical size */
        unsigned long alignment_offset;
 
+       unsigned long grain;            /* alignment unit */
+
        /* geometry */
        sector_t total_sectors; /* in logical sectors */
        struct fdisk_geometry geom;
@@ -237,7 +239,6 @@ enum fdisk_labeltype {
 
 extern enum fdisk_labeltype disklabel;
 extern int MBRbuffer_changed;
-extern unsigned long grain;
 
 /* start_sect and nr_sects are stored little endian on all machines */
 /* moreover, they are not aligned correctly */
index 06c868e71ed730efa064379e641e030cb8648999..10006f6a05485983b4bc04732754558eee00ffdb 100644 (file)
@@ -22,7 +22,7 @@
                s |= (sector >> 2) & 0xc0;                              \
        }
 
-#define alignment_required     (grain != cxt->sector_size)
+#define alignment_required     (cxt->grain != cxt->sector_size)
 
 struct pte ptes[MAXIMUM_PARTS];
 sector_t extended_offset;