fix(fs): seek fs brfore writing data to file (#4859)

Signed-off-by: wangxuedong <wangxuedong@xiaomi.com>
This commit is contained in:
xaowang96 2023-11-25 04:08:53 +08:00 committed by GitHub
parent 990fbc8cdf
commit b587fd78c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -280,10 +280,21 @@ lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, u
return LV_FS_RES_NOT_IMP;
}
lv_fs_res_t res = LV_FS_RES_OK;
/*Need to do FS seek before writing data to FS*/
if(file_p->drv->cache_size) {
res = file_p->drv->seek_cb(file_p->drv, file_p->file_d, file_p->cache->file_position, LV_FS_SEEK_SET);
if(res != LV_FS_RES_OK) return res;
}
uint32_t bw_tmp = 0;
lv_fs_res_t res = file_p->drv->write_cb(file_p->drv, file_p->file_d, buf, btw, &bw_tmp);
res = file_p->drv->write_cb(file_p->drv, file_p->file_d, buf, btw, &bw_tmp);
if(bw != NULL) *bw = bw_tmp;
if(file_p->drv->cache_size && res == LV_FS_RES_OK)
file_p->cache->file_position += bw_tmp;
return res;
}