• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修訂3faffd2687ddfeb114c60c2c605330698d23f39a (tree)
時間2016-11-09 00:24:23
作者Paul Drews <paul.drews@inte...>
CommiterChih-Wei Huang

Log Message

Use progressive offset in buffer for successive writes

The code for copying from one raw file to another looped
back and tried again with a suitably smaller number of bytes
if the entire buffer was not written on the first try.
However, it failed to advance an offset in the buffer past
the bytes that were written. This could conceivably happen
under rare circumstances, leading to a corrupted disk image.

This fix defines an offset into the buffer, advancing it by
the number of bytes written on each successive retry.

Signed-off-by: Paul Drews <paul.drews@intel.com>

Change-Id: I76b8e0b3c0d3b0c32bd2114d0867ac7489808279

Change Summary

差異

--- a/libdiskconfig/diskutils.c
+++ b/libdiskconfig/diskutils.c
@@ -36,6 +36,7 @@ write_raw_image(const char *dst, const char *src, loff_t offset, int test)
3636 int dst_fd = -1;
3737 int src_fd = -1;
3838 uint8_t buffer[2048];
39+ ssize_t buf_offset;
3940 ssize_t nr_bytes;
4041 ssize_t tmp;
4142 int done = 0;
@@ -80,8 +81,9 @@ write_raw_image(const char *dst, const char *src, loff_t offset, int test)
8081 if (test)
8182 nr_bytes = 0;
8283
84+ buf_offset = 0;
8385 while (nr_bytes > 0) {
84- if ((tmp = write(dst_fd, buffer, nr_bytes)) < 0) {
86+ if ((tmp = write(dst_fd, &buffer[buf_offset], nr_bytes)) < 0) {
8587 /* XXX: Should we not even bother with EINTR? */
8688 if (errno == EINTR)
8789 continue;
@@ -91,6 +93,7 @@ write_raw_image(const char *dst, const char *src, loff_t offset, int test)
9193 if (!tmp)
9294 continue;
9395 nr_bytes -= tmp;
96+ buf_offset += tmp;
9497 }
9598 }
9699