From cc41397876f127c7e6e25ad7a9175785f34e0e62 Mon Sep 17 00:00:00 2001 From: Yadong Qi Date: Tue, 29 Mar 2022 15:44:46 +0800 Subject: [PATCH] Support split large images Walk through the image dir, and split the large file(>=4G) to smaller parts. Tracked-On: OAM-100900 Signed-off-by: Yadong Qi --- src/guest/flash.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/guest/flash.c b/src/guest/flash.c index 2d0a5ca..b2c7a33 100644 --- a/src/guest/flash.c +++ b/src/guest/flash.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include "vm_manager.h" @@ -21,6 +22,8 @@ #include "rpmb.h" #include "vtpm.h" +#define GIGABYTE *1024L*1024L*1024L + extern keyfile_group_t g_group[]; #define VUSB_FLASH_DISK "/tmp/flash.vfat" @@ -39,10 +42,30 @@ static char flashing_arg[] = " -nographic -display none -serial mon:stdio" " -boot menu=on,splash-time=5000,strict=on "; +static int split_large_image(const char *fpath, const struct stat *st, int tflag) +{ + char cmd[MAX_CMDLINE_LEN] = { 0 }; + + if (tflag != FTW_F) + return 0; + + if (st->st_size < (4 GIGABYTE)) + return 0; + + snprintf(cmd, 1024, "split --bytes=%ld --numeric-suffixes %s %s.part", (4 GIGABYTE) - 1, fpath, fpath); + printf("%s\n", cmd); + if(system(cmd) != 0) { + return -1; + } + remove(fpath); + return 0; +} + static int create_vusb(GKeyFile *gkf) { char *p = NULL; char cmd[MAX_CMDLINE_LEN] = { 0 }; + char buf[PATH_MAX] = { 0 }; char *fname = NULL; keyfile_group_t *g = NULL; g_autofree gchar *file = NULL; @@ -68,6 +91,12 @@ static int create_vusb(GKeyFile *gkf) if (system(cmd)) return -1; + snprintf(buf, PATH_MAX, "/tmp/%s", fname); + if (ftw(buf, split_large_image, 10) == -1) { + fprintf(stderr, "failed to tree walk"); + return -1; + } + snprintf(cmd, MAX_CMDLINE_LEN, "dd if=/dev/zero of="VUSB_FLASH_DISK" bs=63M count=160"); printf("%s\n", cmd); if (system(cmd))