diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2016-04-28 13:58:09 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-06 10:31:13 +0100 |
commit | 4b971568e142952aa4c71ebc7a1f5326717ff210 (patch) | |
tree | 048dc2c1757376706b0b26d1f6d4f353fe30af96 /scripts | |
parent | a468d4bc57e093a7c7c721ba14d069cd576d8a90 (diff) | |
download | poky-4b971568e142952aa4c71ebc7a1f5326717ff210.tar.gz |
wic: add sparse_copy API
In order to make wic images sparse sparse_copy function has been
copied from meta-ostro:
https://github.com/kad/meta-ostro/blob/master/meta-ostro/lib/image-dsk.py
This function uses filemap APIs to copy source sparse file into
destination file preserving sparseness.
The function has been modified to satisfy wic requirements:
parameter 'skip' has been added.
[YOCTO #9099]
(From OE-Core rev: bfde62bdc03152a4d3d383512479b974fa867f94)
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/wic/filemap.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/lib/wic/filemap.py b/scripts/lib/wic/filemap.py index 1d04328322..f8b2ba71bb 100644 --- a/scripts/lib/wic/filemap.py +++ b/scripts/lib/wic/filemap.py | |||
@@ -529,3 +529,33 @@ def filemap(image, log=None): | |||
529 | return FilemapFiemap(image, log) | 529 | return FilemapFiemap(image, log) |
530 | except ErrorNotSupp: | 530 | except ErrorNotSupp: |
531 | return FilemapSeek(image, log) | 531 | return FilemapSeek(image, log) |
532 | |||
533 | def sparse_copy(src_fname, dst_fname, offset=0, skip=0): | ||
534 | """Efficiently copy sparse file to or into another file.""" | ||
535 | fmap = filemap(src_fname) | ||
536 | try: | ||
537 | dst_file = open(dst_fname, 'r+b') | ||
538 | except IOError: | ||
539 | dst_file = open(dst_fname, 'wb') | ||
540 | |||
541 | for first, last in fmap.get_mapped_ranges(0, fmap.blocks_cnt): | ||
542 | start = first * fmap.block_size | ||
543 | end = (last + 1) * fmap.block_size | ||
544 | |||
545 | if start < skip < end: | ||
546 | start = skip | ||
547 | |||
548 | fmap._f_image.seek(start, os.SEEK_SET) | ||
549 | dst_file.seek(offset + start, os.SEEK_SET) | ||
550 | |||
551 | chunk_size = 1024 * 1024 | ||
552 | to_read = end - start | ||
553 | read = 0 | ||
554 | |||
555 | while read < to_read: | ||
556 | if read + chunk_size > to_read: | ||
557 | chunk_size = to_read - read | ||
558 | chunk = fmap._f_image.read(chunk_size) | ||
559 | dst_file.write(chunk) | ||
560 | read += chunk_size | ||
561 | dst_file.close() | ||