Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add lzma_is_compressed function

Add implementation of the is_compressed callback for lzma.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180817094813.15086-12-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
4b57fd44 8b42b7e5

+17 -2
+17 -2
tools/perf/util/lzma.c
··· 3 3 #include <lzma.h> 4 4 #include <stdio.h> 5 5 #include <linux/compiler.h> 6 + #include <sys/types.h> 7 + #include <sys/stat.h> 8 + #include <fcntl.h> 6 9 #include "compress.h" 7 10 #include "util.h" 8 11 #include "debug.h" 12 + #include <unistd.h> 9 13 10 14 #define BUFSIZE 8192 11 15 ··· 104 100 return err; 105 101 } 106 102 107 - bool lzma_is_compressed(const char *input __maybe_unused) 103 + bool lzma_is_compressed(const char *input) 108 104 { 109 - return true; 105 + int fd = open(input, O_RDONLY); 106 + const uint8_t magic[6] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 }; 107 + char buf[6] = { 0 }; 108 + ssize_t rc; 109 + 110 + if (fd < 0) 111 + return -1; 112 + 113 + rc = read(fd, buf, sizeof(buf)); 114 + close(fd); 115 + return rc == sizeof(buf) ? 116 + memcmp(buf, magic, sizeof(buf)) == 0 : false; 110 117 }