From 90a3681c1b2332093821a24c244bc3a86dbb1967 Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Thu, 13 Oct 2011 09:49:01 -0700 Subject: Fix -wipe-data option Forces overwriting (truncating) of the userimage-qemu.img file on condition that it is being initialized from userimage.img file. If *-qemu file is not truncated the system will pick up on artifacts located behind the overwritten area of the *-qemu.img file. Change-Id: I091dff0069d7049588b11c4654fe134947db101b --- hw/goldfish_nand.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/goldfish_nand.c b/hw/goldfish_nand.c index 49d575a..31e814b 100644 --- a/hw/goldfish_nand.c +++ b/hw/goldfish_nand.c @@ -795,7 +795,18 @@ void nand_add_dev(const char *arg) } if(rwfilename) { - rwfd = open(rwfilename, O_BINARY | (read_only ? O_RDONLY : O_RDWR)); + if (initfilename) { + /* Overwrite with content of the 'initfilename'. */ + if (read_only) { + /* Cannot be readonly when initializing the device from another file. */ + XLOG("incompatible read only option is requested while initializing %.*s from %s\n", + devname_len, devname, initfilename); + exit(1); + } + rwfd = open(rwfilename, O_BINARY | O_TRUNC | O_RDWR); + } else { + rwfd = open(rwfilename, O_BINARY | (read_only ? O_RDONLY : O_RDWR)); + } if(rwfd < 0) { XLOG("could not open file %s, %s\n", rwfilename, strerror(errno)); exit(1); -- cgit v1.1