Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xattr.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2002-2005 Roland McGrath <roland@redhat.com>
  3. * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
  4. * Copyright (c) 2005-2018 Dmitry V. Levin <ldv@altlinux.org>
  5. * All rights reserved.
  6. *
  7. * SPDX-License-Identifier: LGPL-2.1-or-later
  8. */
  9. #include "defs.h"
  10. #ifdef HAVE_SYS_XATTR_H
  11. # include <sys/xattr.h>
  12. #endif
  13. #include "xlat/xattrflags.h"
  14. #ifndef XATTR_SIZE_MAX
  15. # define XATTR_SIZE_MAX 65536
  16. #endif
  17. static void
  18. print_xattr_val(struct tcb *const tcp,
  19. const kernel_ulong_t addr,
  20. const kernel_ulong_t insize,
  21. const kernel_ulong_t size)
  22. {
  23. tprints(", ");
  24. if (size > XATTR_SIZE_MAX)
  25. printaddr(addr);
  26. else
  27. printstr_ex(tcp, addr, size, QUOTE_OMIT_TRAILING_0);
  28. tprintf(", %" PRI_klu, insize);
  29. }
  30. SYS_FUNC(setxattr)
  31. {
  32. printpath(tcp, tcp->u_arg[0]);
  33. tprints(", ");
  34. printstr(tcp, tcp->u_arg[1]);
  35. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
  36. tprints(", ");
  37. printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
  38. return RVAL_DECODED;
  39. }
  40. SYS_FUNC(fsetxattr)
  41. {
  42. printfd(tcp, tcp->u_arg[0]);
  43. tprints(", ");
  44. printstr(tcp, tcp->u_arg[1]);
  45. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
  46. tprints(", ");
  47. printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
  48. return RVAL_DECODED;
  49. }
  50. SYS_FUNC(getxattr)
  51. {
  52. if (entering(tcp)) {
  53. printpath(tcp, tcp->u_arg[0]);
  54. tprints(", ");
  55. printstr(tcp, tcp->u_arg[1]);
  56. } else {
  57. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
  58. }
  59. return 0;
  60. }
  61. SYS_FUNC(fgetxattr)
  62. {
  63. if (entering(tcp)) {
  64. printfd(tcp, tcp->u_arg[0]);
  65. tprints(", ");
  66. printstr(tcp, tcp->u_arg[1]);
  67. } else {
  68. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
  69. }
  70. return 0;
  71. }
  72. static void
  73. print_xattr_list(struct tcb *const tcp, const kernel_ulong_t addr,
  74. const kernel_ulong_t size)
  75. {
  76. if (!size || syserror(tcp)) {
  77. printaddr(addr);
  78. } else {
  79. printstrn(tcp, addr, tcp->u_rval);
  80. }
  81. tprintf(", %" PRI_klu, size);
  82. }
  83. SYS_FUNC(listxattr)
  84. {
  85. if (entering(tcp)) {
  86. printpath(tcp, tcp->u_arg[0]);
  87. tprints(", ");
  88. } else {
  89. print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  90. }
  91. return 0;
  92. }
  93. SYS_FUNC(flistxattr)
  94. {
  95. if (entering(tcp)) {
  96. printfd(tcp, tcp->u_arg[0]);
  97. tprints(", ");
  98. } else {
  99. print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  100. }
  101. return 0;
  102. }
  103. SYS_FUNC(removexattr)
  104. {
  105. printpath(tcp, tcp->u_arg[0]);
  106. tprints(", ");
  107. printstr(tcp, tcp->u_arg[1]);
  108. return RVAL_DECODED;
  109. }
  110. SYS_FUNC(fremovexattr)
  111. {
  112. printfd(tcp, tcp->u_arg[0]);
  113. tprints(", ");
  114. printstr(tcp, tcp->u_arg[1]);
  115. return RVAL_DECODED;
  116. }