|
@@ -397,6 +397,18 @@ static int get_img_index(netio_t *io, size_t cur_offset)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+static size_t get_img_length(netio_t *io)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ size_t length;
|
|
|
+
|
|
|
+ download_img_info_t *priv = (download_img_info_t *)io->private;
|
|
|
+ for (i = 0, length = priv->head_size; i < priv->image_count; i++) {
|
|
|
+ length += priv->img_info[i].img_size;
|
|
|
+ }
|
|
|
+ return length;
|
|
|
+}
|
|
|
+
|
|
|
static int flash_open(netio_t *io, const char *path)
|
|
|
{
|
|
|
io->block_size = CONFIG_FOTA_BUFFER_SIZE;
|
|
@@ -508,7 +520,13 @@ static int _file_write(netio_t *io, int idx, uint8_t *buffer, int length)
|
|
|
__func__, __LINE__, length, fp, fd, ret, errno);
|
|
|
return -1;
|
|
|
}
|
|
|
- if (fp) fflush(fp);
|
|
|
+ if (fp) {
|
|
|
+ fflush(fp);
|
|
|
+ fsync(fileno(fp));
|
|
|
+ }
|
|
|
+ if (fd >= 0) {
|
|
|
+ fsync(fd);
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -602,6 +620,8 @@ static int download_img_info_init_from_file(netio_t *io)
|
|
|
ret = -1;
|
|
|
goto out;
|
|
|
}
|
|
|
+ close(fd);
|
|
|
+ fd = -1;
|
|
|
ret = download_img_info_init(io, buffer, length, 0);
|
|
|
if (ret < 0) {
|
|
|
ret = -1;
|
|
@@ -692,6 +712,10 @@ static int flash_seek(netio_t *io, size_t offset, int whence)
|
|
|
if (download_img_info_init_from_file(io) < 0) {
|
|
|
return -1;
|
|
|
}
|
|
|
+ if (whence == SEEK_SET && offset >= get_img_length(io)) {
|
|
|
+ LOGE(TAG, "seek offset error.");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
idx = get_img_index(io, offset);
|
|
|
if (idx < 0) {
|