diff options
| author | Dragomir, Daniel <daniel.dragomir@windriver.com> | 2025-10-03 23:31:30 +0300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2026-02-27 17:45:06 +0000 |
| commit | 6c2a243d6cfb8277324904ab6b29e4e69ef68e21 (patch) | |
| tree | 35b0c43d59aa6f54a8e35e0535ace8c39ce127bb | |
| parent | df890007b4a1f15504f839d62458da0bad65137e (diff) | |
| download | poky-6c2a243d6cfb8277324904ab6b29e4e69ef68e21.tar.gz | |
wic/engine: fix copying directories into wic image with ext* partition
wic uses debugfs to write on ext* partitions, but debugfs can only
write to the current working directory and it cannot copy complete
directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory
Fix this by creating a command list for debugfs (-f parameter) when
recursive parsing the host directory in order to create a similar
directory structure (mkdir) and copy files (write) on each level
into the destination directory from the wic's ext* partition.
(From OE-Core rev: 67f08884b98576c06db8db01b093ebeee760aba0)
Signed-off-by: Daniel Dragomir <daniel.dragomir@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 1ed38aff5f810d064c87aff9cbd310906833b6ba)
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Paul Barker <paul@pbarker.dev>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | scripts/lib/wic/engine.py | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index ce7e6c5d75..565a0db38a 100644 --- a/scripts/lib/wic/engine.py +++ b/scripts/lib/wic/engine.py | |||
| @@ -327,29 +327,64 @@ class Disk: | |||
| 327 | path)) | 327 | path)) |
| 328 | 328 | ||
| 329 | def copy(self, src, dest): | 329 | def copy(self, src, dest): |
| 330 | """Copy partition image into wic image.""" | 330 | """Copy files or directories to/from the vfat or ext* partition.""" |
| 331 | pnum = dest.part if isinstance(src, str) else src.part | 331 | pnum = dest.part if isinstance(src, str) else src.part |
| 332 | partimg = self._get_part_image(pnum) | ||
| 332 | 333 | ||
| 333 | if self.partitions[pnum].fstype.startswith('ext'): | 334 | if self.partitions[pnum].fstype.startswith('ext'): |
| 334 | if isinstance(src, str): | 335 | if isinstance(src, str): # host to image case |
| 335 | cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\ | 336 | if os.path.isdir(src): |
| 336 | format(os.path.dirname(dest.path), src, os.path.basename(src), | 337 | base = os.path.abspath(src) |
| 337 | self.debugfs, self._get_part_image(pnum)) | 338 | base_parent = os.path.dirname(base) |
| 338 | else: # copy from wic | 339 | cmds = [] |
| 339 | # run both dump and rdump to support both files and directory | 340 | made = set() |
| 341 | |||
| 342 | for root, dirs, files in os.walk(base): | ||
| 343 | for fname in files: | ||
| 344 | host_file = os.path.join(root, fname) | ||
| 345 | rel = os.path.relpath(host_file, base_parent) | ||
| 346 | dest_file = os.path.join(dest.path, rel) | ||
| 347 | dest_dir = os.path.dirname(dest_file) | ||
| 348 | |||
| 349 | # create dir structure (mkdir -p) | ||
| 350 | parts = dest_dir.strip('/').split('/') | ||
| 351 | cur = '' | ||
| 352 | for p in parts: | ||
| 353 | cur = cur + '/' + p | ||
| 354 | if cur not in made: | ||
| 355 | cmds.append(f'mkdir "{cur}"') | ||
| 356 | made.add(cur) | ||
| 357 | |||
| 358 | cmds.append(f'write "{host_file}" "{dest_file}"') | ||
| 359 | |||
| 360 | # write script to a temp file | ||
| 361 | with tempfile.NamedTemporaryFile(mode='w', delete=False, | ||
| 362 | prefix='wic-debugfs-') as tf: | ||
| 363 | for line in cmds: | ||
| 364 | tf.write(line + '\n') | ||
| 365 | scriptname = tf.name | ||
| 366 | |||
| 367 | cmd = f"{self.debugfs} -w -f {scriptname} {partimg}" | ||
| 368 | |||
| 369 | else: # single file | ||
| 370 | cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\ | ||
| 371 | format(os.path.dirname(dest.path), src, | ||
| 372 | os.path.basename(src), self.debugfs, partimg) | ||
| 373 | |||
| 374 | else: # image to host case | ||
| 340 | cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\ | 375 | cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\ |
| 341 | format(os.path.dirname(src.path), src.path, | 376 | format(os.path.dirname(src.path), src.path, |
| 342 | dest, src.path, dest, self.debugfs, | 377 | dest, src.path, dest, self.debugfs, partimg) |
| 343 | self._get_part_image(pnum)) | 378 | |
| 344 | else: # fat | 379 | else: # fat |
| 345 | if isinstance(src, str): | 380 | if isinstance(src, str): |
| 346 | cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, | 381 | cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, |
| 347 | self._get_part_image(pnum), | 382 | partimg, |
| 348 | src, dest.path) | 383 | src, dest.path) |
| 349 | else: | 384 | else: |
| 350 | cmd = "{} -i {} -snop ::{} {}".format(self.mcopy, | 385 | cmd = "{} -i {} -snop ::{} {}".format(self.mcopy, |
| 351 | self._get_part_image(pnum), | 386 | partimg, |
| 352 | src.path, dest) | 387 | src.path, dest) |
| 353 | 388 | ||
| 354 | exec_cmd(cmd, as_shell=True) | 389 | exec_cmd(cmd, as_shell=True) |
| 355 | self._put_part_image(pnum) | 390 | self._put_part_image(pnum) |
