summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Parted.hs
diff options
context:
space:
mode:
authorJoey Hess2017-12-21 16:59:57 -0400
committerJoey Hess2017-12-21 16:59:57 -0400
commitfd7ad4c7ce726de9d27bfe660c3e8366e2415cc2 (patch)
treefdfce8a7e44e25c4bdb715d96993e5dd0cfb3f74 /src/Propellor/Property/Parted.hs
parenta6aba6cdc5eb793052167e0899657093d71ee7be (diff)
fuzzy partition end location for parted
This should fix the reversion in GPT partition creation. See my long comment for the gory details. This commit was sponsored by Peter on Patreon.
Diffstat (limited to 'src/Propellor/Property/Parted.hs')
-rw-r--r--src/Propellor/Property/Parted.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/Propellor/Property/Parted.hs b/src/Propellor/Property/Parted.hs
index 38c55b93..be12933d 100644
--- a/src/Propellor/Property/Parted.hs
+++ b/src/Propellor/Property/Parted.hs
@@ -85,8 +85,8 @@ calcPartedParamsSize (PartTable tabletype alignment parts) =
[ "mkpart"
, pval (partType p)
, pval (partFs p)
- , partpos startpos
- , partpos endpos
+ , partposexact startpos
+ , partposfuzzy endpos
] ++ case partName p of
Just n -> ["name", show partnum, n]
Nothing -> []
@@ -95,14 +95,29 @@ calcPartedParamsSize (PartTable tabletype alignment parts) =
in calcparts (partnum+1) endpos ps
(c ++ mkpart partnum startpos (endpos-1) p : map (mkflag partnum) (partFlags p))
calcparts _ endpos [] c = (c, endpos)
- partpos n
- | n > 0 = val n ++ "B"
+
+ -- Exact partition position value for parted.
+ -- For alignment to work, the start of a partition must be
+ -- specified exactly.
+ partposexact n
+ | n > 0 = show n ++ "B"
-- parted can't make partitions smaller than 1MB;
-- avoid failure in edge cases
| otherwise = "1MB"
+
+ -- Fuzzy partition position valie for parted.
+ -- This is used to specify the end of the partition,
+ -- parted takes the "MB" as license to slightly reduce the
+ -- partition size when something about the partition table
+ -- does not allow the partition to end exactly at the position.
+ partposfuzzy n
+ | n > 0 = show (fromIntegral n / 1000000) ++ "MB"
+ | otherwise = "1MB"
+
-- Location of the start of the first partition,
-- leaving space for the partition table, and aligning.
firstpos = align partitionTableOverhead
+
align = alignTo alignment
-- | Runs parted on a disk with the specified parameters.