perf header: Add is_perf_magic() func
authorFeng Tang <feng.tang@intel.com>
Tue, 30 Oct 2012 03:56:07 +0000 (11:56 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 29 Oct 2012 13:56:59 +0000 (11:56 -0200)
With this function, other modules can basically check whether a file is
a legal perf data file by checking its first 8 bytes against all
possible perf magic numbers.

Change the function name from check_perf_magic to more meaningful
is_perf_magic as suggested by acme.

Signed-off-by: Feng Tang <feng.tang@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1351569369-26732-7-git-send-email-feng.tang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/header.c
tools/perf/util/header.h

index 514ed1bd41a260b79b8aead5592943c0a4143bb3..195a47a8f05218b1b68f1e09fd46b45ce2485fee 100644 (file)
@@ -2341,6 +2341,16 @@ static int try_all_pipe_abis(uint64_t hdr_sz, struct perf_header *ph)
        return -1;
 }
 
+bool is_perf_magic(u64 magic)
+{
+       if (!memcmp(&magic, __perf_magic1, sizeof(magic))
+               || magic == __perf_magic2
+               || magic == __perf_magic2_sw)
+               return true;
+
+       return false;
+}
+
 static int check_magic_endian(u64 magic, uint64_t hdr_sz,
                              bool is_pipe, struct perf_header *ph)
 {
index 879d215cdac9007c360fbd4862c2e0d3aaa514e3..5f1cd6884f3769c4def9409dfe9c814083e7a0c5 100644 (file)
@@ -154,6 +154,7 @@ int perf_event__synthesize_build_id(struct perf_tool *tool,
 int perf_event__process_build_id(struct perf_tool *tool,
                                 union perf_event *event,
                                 struct perf_session *session);
+bool is_perf_magic(u64 magic);
 
 /*
  * arch specific callback