From 6c3c3e717df8875c526e2161d2ed26cce7ece762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 25 Nov 2013 02:28:35 +0100 Subject: [PATCH] tar2qfile: use lseek() to skip unwanted data if possible When reading from file it is much faster. --- qubes-rpc/tar2qfile.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/qubes-rpc/tar2qfile.c b/qubes-rpc/tar2qfile.c index 516eaaa..eeccc0b 100644 --- a/qubes-rpc/tar2qfile.c +++ b/qubes-rpc/tar2qfile.c @@ -168,6 +168,7 @@ static unsigned long tar_chksm (char *, int); char *gnu_hack_string; /* GNU ././@LongLink hackery */ char untrusted_namebuf[MAX_PATH_LENGTH]; +int use_seek = 1; extern int ignore_quota_error; struct filters { @@ -914,12 +915,27 @@ void tar_file_processor(int fd, struct filters *filters) if (to_skip%BLKMULT > 0) { to_skip += BLKMULT-(to_skip%BLKMULT); } - while (to_skip > 0) { - ret = read_all(fd, &buf, MIN(to_skip,BLKMULT)); - if (ret <= 0) { - exit(1); + if (use_seek) { + ret = lseek(fd, to_skip, SEEK_CUR); + if (ret < 0) { + if (errno == ESPIPE) { + // fallback to read() + use_seek = 0; + } else { + perror("lseek"); + exit(1); + } + } + } + // not using "else" because above can fallback to read() method + if (!use_seek) { + while (to_skip > 0) { + ret = read_all(fd, &buf, MIN(to_skip,BLKMULT)); + if (ret <= 0) { + exit(1); + } + to_skip -= MIN(to_skip,BLKMULT); } - to_skip -= MIN(to_skip,BLKMULT); } current = NEED_SYNC_TRAIL;