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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2002-2005 Roland McGrath <roland@redhat.com>
  3. * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
  4. * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "defs.h"
  30. #ifdef HAVE_SYS_XATTR_H
  31. # include <sys/xattr.h>
  32. #endif
  33. #include "xlat/xattrflags.h"
  34. #ifndef XATTR_SIZE_MAX
  35. # define XATTR_SIZE_MAX 65536
  36. #endif
  37. static void
  38. print_xattr_val(struct tcb *const tcp,
  39. const kernel_ulong_t addr,
  40. const kernel_ulong_t insize,
  41. const kernel_ulong_t size)
  42. {
  43. tprints(", ");
  44. if (size > XATTR_SIZE_MAX)
  45. printaddr(addr);
  46. else
  47. printstr_ex(tcp, addr, size, QUOTE_OMIT_TRAILING_0);
  48. tprintf(", %" PRI_klu, insize);
  49. }
  50. SYS_FUNC(setxattr)
  51. {
  52. printpath(tcp, tcp->u_arg[0]);
  53. tprints(", ");
  54. printstr(tcp, tcp->u_arg[1]);
  55. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
  56. tprints(", ");
  57. printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
  58. return RVAL_DECODED;
  59. }
  60. SYS_FUNC(fsetxattr)
  61. {
  62. printfd(tcp, tcp->u_arg[0]);
  63. tprints(", ");
  64. printstr(tcp, tcp->u_arg[1]);
  65. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
  66. tprints(", ");
  67. printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
  68. return RVAL_DECODED;
  69. }
  70. SYS_FUNC(getxattr)
  71. {
  72. if (entering(tcp)) {
  73. printpath(tcp, tcp->u_arg[0]);
  74. tprints(", ");
  75. printstr(tcp, tcp->u_arg[1]);
  76. } else {
  77. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
  78. }
  79. return 0;
  80. }
  81. SYS_FUNC(fgetxattr)
  82. {
  83. if (entering(tcp)) {
  84. printfd(tcp, tcp->u_arg[0]);
  85. tprints(", ");
  86. printstr(tcp, tcp->u_arg[1]);
  87. } else {
  88. print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
  89. }
  90. return 0;
  91. }
  92. static void
  93. print_xattr_list(struct tcb *const tcp, const kernel_ulong_t addr,
  94. const kernel_ulong_t size)
  95. {
  96. if (!size || syserror(tcp)) {
  97. printaddr(addr);
  98. } else {
  99. printstrn(tcp, addr, tcp->u_rval);
  100. }
  101. tprintf(", %" PRI_klu, size);
  102. }
  103. SYS_FUNC(listxattr)
  104. {
  105. if (entering(tcp)) {
  106. printpath(tcp, tcp->u_arg[0]);
  107. tprints(", ");
  108. } else {
  109. print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  110. }
  111. return 0;
  112. }
  113. SYS_FUNC(flistxattr)
  114. {
  115. if (entering(tcp)) {
  116. printfd(tcp, tcp->u_arg[0]);
  117. tprints(", ");
  118. } else {
  119. print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  120. }
  121. return 0;
  122. }
  123. SYS_FUNC(removexattr)
  124. {
  125. printpath(tcp, tcp->u_arg[0]);
  126. tprints(", ");
  127. printstr(tcp, tcp->u_arg[1]);
  128. return RVAL_DECODED;
  129. }
  130. SYS_FUNC(fremovexattr)
  131. {
  132. printfd(tcp, tcp->u_arg[0]);
  133. tprints(", ");
  134. printstr(tcp, tcp->u_arg[1]);
  135. return RVAL_DECODED;
  136. }