[gnome-continuous-yocto/gnomeostree-3.28-rocko: 81/8267] wic: add sparse_copy API
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-continuous-yocto/gnomeostree-3.28-rocko: 81/8267] wic: add sparse_copy API
- Date: Sat, 16 Dec 2017 19:55:37 +0000 (UTC)
commit 4b971568e142952aa4c71ebc7a1f5326717ff210
Author: Ed Bartosh <ed bartosh linux intel com>
Date: Thu Apr 28 13:58:09 2016 +0300
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>
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 1d04328..f8b2ba7 100644
--- a/scripts/lib/wic/filemap.py
+++ b/scripts/lib/wic/filemap.py
@@ -529,3 +529,33 @@ def filemap(image, log=None):
return FilemapFiemap(image, log)
except ErrorNotSupp:
return FilemapSeek(image, log)
+
+def sparse_copy(src_fname, dst_fname, offset=0, skip=0):
+ """Efficiently copy sparse file to or into another file."""
+ fmap = filemap(src_fname)
+ try:
+ dst_file = open(dst_fname, 'r+b')
+ except IOError:
+ dst_file = open(dst_fname, 'wb')
+
+ for first, last in fmap.get_mapped_ranges(0, fmap.blocks_cnt):
+ start = first * fmap.block_size
+ end = (last + 1) * fmap.block_size
+
+ if start < skip < end:
+ start = skip
+
+ fmap._f_image.seek(start, os.SEEK_SET)
+ dst_file.seek(offset + start, os.SEEK_SET)
+
+ chunk_size = 1024 * 1024
+ to_read = end - start
+ read = 0
+
+ while read < to_read:
+ if read + chunk_size > to_read:
+ chunk_size = to_read - read
+ chunk = fmap._f_image.read(chunk_size)
+ dst_file.write(chunk)
+ read += chunk_size
+ dst_file.close()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]