[oe-commits] [openembedded-core] 13/31: wic: use truncate utility to create sparse files
git at git.openembedded.org
git at git.openembedded.org
Fri Apr 29 08:24:20 UTC 2016
rpurdie pushed a commit to branch master-next
in repository openembedded-core.
commit a2a8fcd54c40ed408662c6c7728122cbc2d02962
Author: Ed Bartosh <ed.bartosh at linux.intel.com>
AuthorDate: Thu Apr 28 13:58:04 2016 +0300
wic: use truncate utility to create sparse files
Used truncate instead of dd to create wic images for the
following reasons:
- dd doesn't preserve sparseness
- truncate syntax is much more clear
- dd requires additional calculations of the image size
in blocks
- the way dd was used in the code is not always correct.
In some cases it was writing one block to the file which makes
it not 100% sparse.
[YOCTO #9099]
Signed-off-by: Ed Bartosh <ed.bartosh at linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
scripts/lib/wic/partition.py | 20 +++++---------------
scripts/lib/wic/utils/fs_related.py | 12 +++---------
2 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 227b685..6d21193 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -220,9 +220,7 @@ class Partition(object):
msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
(extra_blocks, self.mountpoint, rootfs_size))
- dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
- (rootfs, rootfs_size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))
extra_imagecmd = "-i 8192"
@@ -255,9 +253,7 @@ class Partition(object):
msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
(extra_blocks, self.mountpoint, rootfs_size))
- dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
- (rootfs, rootfs_size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))
label_str = ""
if self.label:
@@ -320,9 +316,7 @@ class Partition(object):
"""
Prepare an empty ext2/3/4 partition.
"""
- dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
- (rootfs, self.size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))
extra_imagecmd = "-i 8192"
@@ -339,9 +333,7 @@ class Partition(object):
"""
Prepare an empty btrfs partition.
"""
- dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
- (rootfs, self.size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))
label_str = ""
if self.label:
@@ -402,9 +394,7 @@ class Partition(object):
"""
path = "%s/fs.%s" % (cr_workdir, self.fstype)
- dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
- (path, self.size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (path, self.size * 1024))
import uuid
label_str = ""
diff --git a/scripts/lib/wic/utils/fs_related.py b/scripts/lib/wic/utils/fs_related.py
index 2e74461..2658dcf 100644
--- a/scripts/lib/wic/utils/fs_related.py
+++ b/scripts/lib/wic/utils/fs_related.py
@@ -71,14 +71,8 @@ class DiskImage(Disk):
def create(self):
if self.device is not None:
return
-
- blocks = self.size / 1024
- if self.size - blocks * 1024:
- blocks += 1
-
- # create disk image
- dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=1" % \
- (self.image_file, blocks)
- exec_cmd(dd_cmd)
+ # create sparse disk image
+ cmd = "truncate %s -s %s" % (self.image_file, self.size)
+ exec_cmd(cmd)
self.device = self.image_file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Openembedded-commits
mailing list