summaryrefslogtreecommitdiff
path: root/Grow.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-10-04 16:34:21 +1000
committerNeilBrown <neilb@suse.de>2012-10-04 16:34:21 +1000
commitb48e2e25c4abce2874aa1f81e001a8047d3319ea (patch)
tree6a50d5dc55be3ede7e1192c706e38966548d5b88 /Grow.c
parentfe384ca0b90e4e8e18f705aacbf031ea76d9c604 (diff)
Split 'GCD' out into a separate function.
It is neater that way. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'Grow.c')
-rw-r--r--Grow.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Grow.c b/Grow.c
index f6fe1683..ba00f275 100644
--- a/Grow.c
+++ b/Grow.c
@@ -938,6 +938,17 @@ int reshape_open_backup_file(char *backup_file,
return 1;
}
+unsigned long GCD(unsigned long a, unsigned long b)
+{
+ while (a != b) {
+ if (a < b)
+ b -= a;
+ if (b < a)
+ a -= b;
+ }
+ return a;
+}
+
unsigned long compute_backup_blocks(int nchunk, int ochunk,
unsigned int ndata, unsigned int odata)
{
@@ -950,12 +961,7 @@ unsigned long compute_backup_blocks(int nchunk, int ochunk,
a = (ochunk/512) * odata;
b = (nchunk/512) * ndata;
/* Find GCD */
- while (a != b) {
- if (a < b)
- b -= a;
- if (b < a)
- a -= b;
- }
+ a = GCD(a, b);
/* LCM == product / GCD */
blocks = (ochunk/512) * (nchunk/512) * odata * ndata / a;