flock.c 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: LGPL-2.1
  2. #include "trace/beauty/beauty.h"
  3. #include <linux/kernel.h>
  4. #include <uapi/linux/fcntl.h>
  5. #ifndef LOCK_MAND
  6. #define LOCK_MAND 32
  7. #endif
  8. #ifndef LOCK_READ
  9. #define LOCK_READ 64
  10. #endif
  11. #ifndef LOCK_WRITE
  12. #define LOCK_WRITE 128
  13. #endif
  14. #ifndef LOCK_RW
  15. #define LOCK_RW 192
  16. #endif
  17. size_t syscall_arg__scnprintf_flock(char *bf, size_t size, struct syscall_arg *arg)
  18. {
  19. bool show_prefix = arg->show_string_prefix;
  20. const char *prefix = "LOCK_";
  21. int printed = 0, op = arg->val;
  22. if (op == 0)
  23. return scnprintf(bf, size, "NONE");
  24. #define P_CMD(cmd) \
  25. if ((op & LOCK_##cmd) == LOCK_##cmd) { \
  26. printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #cmd); \
  27. op &= ~LOCK_##cmd; \
  28. }
  29. P_CMD(SH);
  30. P_CMD(EX);
  31. P_CMD(NB);
  32. P_CMD(UN);
  33. P_CMD(MAND);
  34. P_CMD(RW);
  35. P_CMD(READ);
  36. P_CMD(WRITE);
  37. #undef P_OP
  38. if (op)
  39. printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", op);
  40. return printed;
  41. }