linux-yocto/tools/perf/trace/beauty/fs_at_flags.c
Yang Jihong 089ef2f4c8 perf beauty: Fix AT_EACCESS undeclared build error for system with kernel versions lower than v5.8
In the environment of ubuntu 20.04 (the version of kernel headers is
5.4), there is an error in building perf:

    CC      trace/beauty/fs_at_flags.o
  trace/beauty/fs_at_flags.c: In function ‘faccessat2__scnprintf_flags’:
  trace/beauty/fs_at_flags.c:35:14: error: ‘AT_EACCESS’ undeclared (first use in this function); did you mean ‘DN_ACCESS’?
     35 |  if (flags & AT_EACCESS) {
        |              ^~~~~~~~~~
        |              DN_ACCESS
  trace/beauty/fs_at_flags.c:35:14: note: each undeclared identifier is reported only once for each function it appears in

commit 8a1ad44135 ("tools headers: Remove now unused copies of
uapi/{fcntl,openat2}.h and asm/fcntl.h") removes fcntl.h from tools
headers directory, and fs_at_flags.c uses the 'AT_EACCESS' macro.

This macro was introduced in the kernel version v5.8.  For system with a
kernel version older than this version, it will cause compilation to
fail.

Fixes: 8a1ad44135 ("tools headers: Remove now unused copies of uapi/{fcntl,openat2}.h and asm/fcntl.h")
Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240403122558.1438841-1-yangjihong@bytedance.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-04-03 11:48:57 -03:00

59 lines
1.7 KiB
C

// SPDX-License-Identifier: LGPL-2.1
/*
* trace/beauty/fs_at_flags.c
*
* Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
*/
#include "trace/beauty/beauty.h"
#include <sys/types.h>
#include <linux/fcntl.h>
#include <linux/log2.h>
/*
* uapi/linux/fcntl.h does not keep a copy in tools headers directory,
* for system with kernel versions before v5.8, need to sync AT_EACCESS macro.
*/
#ifndef AT_EACCESS
#define AT_EACCESS 0x200
#endif
#include "trace/beauty/generated/fs_at_flags_array.c"
static DEFINE_STRARRAY(fs_at_flags, "AT_");
static size_t fs_at__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
{
return strarray__scnprintf_flags(&strarray__fs_at_flags, bf, size, show_prefix, flags);
}
size_t syscall_arg__scnprintf_fs_at_flags(char *bf, size_t size, struct syscall_arg *arg)
{
bool show_prefix = arg->show_string_prefix;
int flags = arg->val;
return fs_at__scnprintf_flags(flags, bf, size, show_prefix);
}
static size_t faccessat2__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
{
int printed = 0;
// AT_EACCESS is the same as AT_REMOVEDIR, that is in fs_at_flags_array,
// special case it here.
if (flags & AT_EACCESS) {
flags &= ~AT_EACCESS;
printed += scnprintf(bf + printed, size - printed, "%sEACCESS%s",
show_prefix ? strarray__fs_at_flags.prefix : "", flags ? "|" : "");
}
return strarray__scnprintf_flags(&strarray__fs_at_flags, bf + printed, size - printed, show_prefix, flags);
}
size_t syscall_arg__scnprintf_faccessat2_flags(char *bf, size_t size, struct syscall_arg *arg)
{
bool show_prefix = arg->show_string_prefix;
int flags = arg->val;
return faccessat2__scnprintf_flags(flags, bf, size, show_prefix);
}