X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/4bf43ab9d4e6b724836724c1d514760d164df79a..a1c6fe2d2428cb8a1b4a9e11a9a5075a4bccecd1:/Plugson/src/Core/ventoy_util_linux.c diff --git a/Plugson/src/Core/ventoy_util_linux.c b/Plugson/src/Core/ventoy_util_linux.c index fa799a9..c432f08 100644 --- a/Plugson/src/Core/ventoy_util_linux.c +++ b/Plugson/src/Core/ventoy_util_linux.c @@ -234,42 +234,6 @@ int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen) return 0; } -int ventoy_decompress_tar(char *tarbuf, int buflen, int *tarsize) -{ - int rc = 1; - int inused = 0; - int BufLen = 0; - unsigned char *buffer = NULL; - char tarxz[MAX_PATH]; - - scnprintf(tarxz, sizeof(tarxz), "%s/tool/plugson.tar.xz", g_ventoy_dir); - if (ventoy_read_file_to_buf(tarxz, 0, (void **)&buffer, &BufLen)) - { - vlog("Failed to read file <%s>\n", tarxz); - return 1; - } - - g_unxz_buffer = (unsigned char *)tarbuf; - g_unxz_len = 0; - - unxz(buffer, BufLen, NULL, unxz_flush, NULL, &inused, unxz_error); - vlog("xzlen:%u rawdata size:%d\n", BufLen, g_unxz_len); - - if (inused != BufLen) - { - vlog("Failed to unxz data %d %d\n", inused, BufLen); - rc = 1; - } - else - { - *tarsize = g_unxz_len; - rc = 0; - } - - free(buffer); - - return rc; -} static volatile int g_thread_stop = 0; static pthread_t g_writeback_thread; @@ -328,6 +292,41 @@ void ventoy_stop_writeback_thread(void) } + +int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen) +{ + int FileSize; + FILE *fp = NULL; + void *Data = NULL; + + fp = fopen(FileName, "rb"); + if (fp == NULL) + { + vlog("Failed to open file %s", FileName); + return 1; + } + + fseek(fp, 0, SEEK_END); + FileSize = (int)ftell(fp); + + Data = malloc(FileSize + ExtLen); + if (!Data) + { + fclose(fp); + return 1; + } + + fseek(fp, 0, SEEK_SET); + fread(Data, 1, FileSize, fp); + + fclose(fp); + + *Bufer = Data; + *BufLen = FileSize; + + return 0; +} + int ventoy_copy_file(const char *a, const char *b) { int len = 0;