summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/wic/ksparser.py46
-rw-r--r--scripts/lib/wic/partition.py1
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py15
3 files changed, 42 insertions, 20 deletions
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index 650b976223..f32315c631 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -51,26 +51,31 @@ class KickStartParser(ArgumentParser):
51 def error(self, message): 51 def error(self, message):
52 raise ArgumentError(None, message) 52 raise ArgumentError(None, message)
53 53
54def sizetype(arg): 54def sizetype(default):
55 """ 55 def f(arg):
56 Custom type for ArgumentParser 56 """
57 Converts size string in <num>[K|k|M|G] format into the integer value 57 Custom type for ArgumentParser
58 """ 58 Converts size string in <num>[K|k|M|G] format into the integer value
59 if arg.isdigit(): 59 """
60 return int(arg) * 1024 60 try:
61 suffix = default
62 size = int(arg)
63 except ValueError:
64 try:
65 suffix = arg[-1:]
66 size = int(arg[:-1])
67 except ValueError:
68 raise ArgumentTypeError("Invalid size: %r" % arg)
69
70 if suffix == "k" or suffix == "K":
71 return size
72 if suffix == "M":
73 return size * 1024
74 if suffix == "G":
75 return size * 1024 * 1024
61 76
62 if not arg[:-1].isdigit():
63 raise ArgumentTypeError("Invalid size: %r" % arg) 77 raise ArgumentTypeError("Invalid size: %r" % arg)
64 78 return f
65 size = int(arg[:-1])
66 if arg.endswith("k") or arg.endswith("K"):
67 return size
68 if arg.endswith("M"):
69 return size * 1024
70 if arg.endswith("G"):
71 return size * 1024 * 1024
72
73 raise ArgumentTypeError("Invalid size: %r" % arg)
74 79
75def overheadtype(arg): 80def overheadtype(arg):
76 """ 81 """
@@ -136,6 +141,7 @@ class KickStart():
136 part.add_argument('mountpoint', nargs='?') 141 part.add_argument('mountpoint', nargs='?')
137 part.add_argument('--active', action='store_true') 142 part.add_argument('--active', action='store_true')
138 part.add_argument('--align', type=int) 143 part.add_argument('--align', type=int)
144 part.add_argument('--offset', type=sizetype("K"))
139 part.add_argument('--exclude-path', nargs='+') 145 part.add_argument('--exclude-path', nargs='+')
140 part.add_argument('--include-path', nargs='+') 146 part.add_argument('--include-path', nargs='+')
141 part.add_argument("--extra-space", type=sizetype) 147 part.add_argument("--extra-space", type=sizetype)
@@ -160,8 +166,8 @@ class KickStart():
160 # --error, but since nesting mutually exclusive groups does not work, 166 # --error, but since nesting mutually exclusive groups does not work,
161 # ----extra-space/--overhead-factor are handled later 167 # ----extra-space/--overhead-factor are handled later
162 sizeexcl = part.add_mutually_exclusive_group() 168 sizeexcl = part.add_mutually_exclusive_group()
163 sizeexcl.add_argument('--size', type=sizetype, default=0) 169 sizeexcl.add_argument('--size', type=sizetype("M"), default=0)
164 sizeexcl.add_argument('--fixed-size', type=sizetype, default=0) 170 sizeexcl.add_argument('--fixed-size', type=sizetype("M"), default=0)
165 171
166 part.add_argument('--source') 172 part.add_argument('--source')
167 part.add_argument('--sourceparams') 173 part.add_argument('--sourceparams')
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 2d95f78439..3490b4e75d 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -39,6 +39,7 @@ class Partition():
39 self.mountpoint = args.mountpoint 39 self.mountpoint = args.mountpoint
40 self.no_table = args.no_table 40 self.no_table = args.no_table
41 self.num = None 41 self.num = None
42 self.offset = args.offset
42 self.overhead_factor = args.overhead_factor 43 self.overhead_factor = args.overhead_factor
43 self.part_name = args.part_name 44 self.part_name = args.part_name
44 self.part_type = args.part_type 45 self.part_type = args.part_type
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 2d06c242b6..1f65a7afe5 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -428,6 +428,21 @@ class PartitionedImage():
428 # increase the offset so we actually start the partition on right alignment 428 # increase the offset so we actually start the partition on right alignment
429 self.offset += align_sectors 429 self.offset += align_sectors
430 430
431 if part.offset is not None:
432 offset = (part.offset * 1024) // self.sector_size
433
434 if offset * self.sector_size != part.offset * 1024:
435 raise WicError("Could not place %s%s at offset %dK with sector size %d" % (part.disk, self.numpart, part.offset, self.sector_size))
436
437 delta = offset - self.offset
438 if delta < 0:
439 raise WicError("Could not place %s%s at offset %dK: next free sector is %d (delta: %d)" % (part.disk, self.numpart, part.offset, offset, delta))
440
441 logger.debug("Skipping %d sectors to place %s%s at offset %dK",
442 delta, part.disk, self.numpart, part.offset)
443
444 self.offset = offset
445
431 part.start = self.offset 446 part.start = self.offset
432 self.offset += part.size_sec 447 self.offset += part.size_sec
433 448