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.

fetch_struct_statfs.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
  3. * Copyright (c) 2016-2018 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #include "defs.h"
  9. #include DEF_MPERS_TYPE(struct_statfs)
  10. #include DEF_MPERS_TYPE(struct_statfs64)
  11. #include <linux/types.h>
  12. #include <asm/statfs.h>
  13. typedef struct statfs struct_statfs;
  14. typedef struct statfs64 struct_statfs64;
  15. #include MPERS_DEFS
  16. #include "statfs.h"
  17. MPERS_PRINTER_DECL(bool, fetch_struct_statfs,
  18. struct tcb *const tcp, const kernel_ulong_t addr,
  19. struct strace_statfs *const p)
  20. {
  21. struct_statfs b;
  22. if (umove_or_printaddr(tcp, addr, &b))
  23. return false;
  24. p->f_type = zero_extend_signed_to_ull(b.f_type);
  25. p->f_bsize = zero_extend_signed_to_ull(b.f_bsize);
  26. p->f_blocks = zero_extend_signed_to_ull(b.f_blocks);
  27. p->f_bfree = zero_extend_signed_to_ull(b.f_bfree);
  28. p->f_bavail = zero_extend_signed_to_ull(b.f_bavail);
  29. p->f_files = zero_extend_signed_to_ull(b.f_files);
  30. p->f_ffree = zero_extend_signed_to_ull(b.f_ffree);
  31. #if defined HAVE_STRUCT_STATFS_F_FSID_VAL
  32. p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.val[0]);
  33. p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.val[1]);
  34. #elif defined HAVE_STRUCT_STATFS_F_FSID___VAL
  35. p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.__val[0]);
  36. p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.__val[1]);
  37. #endif
  38. p->f_namelen = zero_extend_signed_to_ull(b.f_namelen);
  39. #ifdef HAVE_STRUCT_STATFS_F_FRSIZE
  40. p->f_frsize = zero_extend_signed_to_ull(b.f_frsize);
  41. #endif
  42. #ifdef HAVE_STRUCT_STATFS_F_FLAGS
  43. p->f_flags = zero_extend_signed_to_ull(b.f_flags);
  44. #endif
  45. return true;
  46. }
  47. #if defined ARM || (defined AARCH64 && defined IN_MPERS)
  48. /* See arch/arm/kernel/sys_oabi-compat.c for details. */
  49. # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct_statfs64) + 4)
  50. #endif
  51. MPERS_PRINTER_DECL(bool, fetch_struct_statfs64,
  52. struct tcb *const tcp, const kernel_ulong_t addr,
  53. const kernel_ulong_t size, struct strace_statfs *const p)
  54. {
  55. struct_statfs64 b;
  56. if (sizeof(b) != size
  57. #ifdef COMPAT_STATFS64_PADDED_SIZE
  58. && sizeof(b) != COMPAT_STATFS64_PADDED_SIZE
  59. #endif
  60. ) {
  61. printaddr(addr);
  62. return false;
  63. }
  64. if (umove_or_printaddr(tcp, addr, &b))
  65. return false;
  66. p->f_type = zero_extend_signed_to_ull(b.f_type);
  67. p->f_bsize = zero_extend_signed_to_ull(b.f_bsize);
  68. p->f_blocks = zero_extend_signed_to_ull(b.f_blocks);
  69. p->f_bfree = zero_extend_signed_to_ull(b.f_bfree);
  70. p->f_bavail = zero_extend_signed_to_ull(b.f_bavail);
  71. p->f_files = zero_extend_signed_to_ull(b.f_files);
  72. p->f_ffree = zero_extend_signed_to_ull(b.f_ffree);
  73. #if defined HAVE_STRUCT_STATFS64_F_FSID_VAL
  74. p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.val[0]);
  75. p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.val[1]);
  76. #elif defined HAVE_STRUCT_STATFS64_F_FSID___VAL
  77. p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.__val[0]);
  78. p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.__val[1]);
  79. #endif
  80. p->f_namelen = zero_extend_signed_to_ull(b.f_namelen);
  81. #ifdef HAVE_STRUCT_STATFS64_F_FRSIZE
  82. p->f_frsize = zero_extend_signed_to_ull(b.f_frsize);
  83. #endif
  84. #ifdef HAVE_STRUCT_STATFS64_F_FLAGS
  85. p->f_flags = zero_extend_signed_to_ull(b.f_flags);
  86. #endif
  87. return true;
  88. }