fs_at_flags.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: LGPL-2.1
  2. /*
  3. * trace/beauty/fs_at_flags.c
  4. *
  5. * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
  6. */
  7. #include "trace/beauty/beauty.h"
  8. #include <sys/types.h>
  9. #include <linux/fcntl.h>
  10. #include <linux/log2.h>
  11. /*
  12. * uapi/linux/fcntl.h does not keep a copy in tools headers directory,
  13. * for system with kernel versions before v5.8, need to sync AT_EACCESS macro.
  14. */
  15. #ifndef AT_EACCESS
  16. #define AT_EACCESS 0x200
  17. #endif
  18. #include "trace/beauty/generated/fs_at_flags_array.c"
  19. static DEFINE_STRARRAY(fs_at_flags, "AT_");
  20. static size_t fs_at__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
  21. {
  22. return strarray__scnprintf_flags(&strarray__fs_at_flags, bf, size, show_prefix, flags);
  23. }
  24. size_t syscall_arg__scnprintf_fs_at_flags(char *bf, size_t size, struct syscall_arg *arg)
  25. {
  26. bool show_prefix = arg->show_string_prefix;
  27. int flags = arg->val;
  28. return fs_at__scnprintf_flags(flags, bf, size, show_prefix);
  29. }
  30. static size_t faccessat2__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
  31. {
  32. int printed = 0;
  33. // AT_EACCESS is the same as AT_REMOVEDIR, that is in fs_at_flags_array,
  34. // special case it here.
  35. if (flags & AT_EACCESS) {
  36. flags &= ~AT_EACCESS;
  37. printed += scnprintf(bf + printed, size - printed, "%sEACCESS%s",
  38. show_prefix ? strarray__fs_at_flags.prefix : "", flags ? "|" : "");
  39. }
  40. return strarray__scnprintf_flags(&strarray__fs_at_flags, bf + printed, size - printed, show_prefix, flags);
  41. }
  42. size_t syscall_arg__scnprintf_faccessat2_flags(char *bf, size_t size, struct syscall_arg *arg)
  43. {
  44. bool show_prefix = arg->show_string_prefix;
  45. int flags = arg->val;
  46. return faccessat2__scnprintf_flags(flags, bf, size, show_prefix);
  47. }