Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 1 | #include "defs.h" |
| 2 | #ifdef HAVE_SYS_VFS_H |
| 3 | # include <sys/vfs.h> |
| 4 | #endif |
| 5 | #include "xlat/fsmagic.h" |
| 6 | |
| 7 | static const char * |
| 8 | sprintfstype(const unsigned int magic) |
| 9 | { |
| 10 | static char buf[32]; |
| 11 | const char *s; |
| 12 | |
| 13 | s = xlat_search(fsmagic, ARRAY_SIZE(fsmagic), magic); |
| 14 | if (s) { |
| 15 | sprintf(buf, "\"%s\"", s); |
| 16 | return buf; |
| 17 | } |
| 18 | sprintf(buf, "%#x", magic); |
| 19 | return buf; |
| 20 | } |
| 21 | |
| 22 | static void |
| 23 | printstatfs(struct tcb *tcp, const long addr) |
| 24 | { |
| 25 | struct statfs statbuf; |
| 26 | |
Dmitry V. Levin | fd55b54 | 2015-07-16 23:32:12 +0000 | [diff] [blame] | 27 | if (umove_or_printaddr(tcp, addr, &statbuf)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 28 | return; |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 29 | tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ", |
| 30 | sprintfstype(statbuf.f_type), |
| 31 | (unsigned long)statbuf.f_bsize, |
| 32 | (unsigned long)statbuf.f_blocks, |
| 33 | (unsigned long)statbuf.f_bfree); |
| 34 | tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}", |
| 35 | (unsigned long)statbuf.f_bavail, |
| 36 | (unsigned long)statbuf.f_files, |
| 37 | (unsigned long)statbuf.f_ffree, |
| 38 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 39 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 40 | #ifdef _STATFS_F_FRSIZE |
| 41 | tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize); |
| 42 | #endif |
Elliott Hughes | 1b5b567 | 2015-03-17 16:00:31 -0700 | [diff] [blame] | 43 | #ifdef _STATFS_F_FLAGS |
| 44 | tprintf(", f_flags=%lu", (unsigned long)statbuf.f_flags); |
| 45 | #endif |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 46 | tprints("}"); |
| 47 | } |
| 48 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 49 | SYS_FUNC(statfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 50 | { |
| 51 | if (entering(tcp)) { |
| 52 | printpath(tcp, tcp->u_arg[0]); |
| 53 | tprints(", "); |
| 54 | } else { |
| 55 | printstatfs(tcp, tcp->u_arg[1]); |
| 56 | } |
| 57 | return 0; |
| 58 | } |
| 59 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 60 | SYS_FUNC(fstatfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 61 | { |
| 62 | if (entering(tcp)) { |
| 63 | printfd(tcp, tcp->u_arg[0]); |
| 64 | tprints(", "); |
| 65 | } else { |
| 66 | printstatfs(tcp, tcp->u_arg[1]); |
| 67 | } |
| 68 | return 0; |
| 69 | } |
| 70 | |
Dmitry V. Levin | 9e6a7bf | 2015-01-08 04:12:29 +0000 | [diff] [blame] | 71 | #ifdef HAVE_STRUCT_STATFS64 |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 72 | static void |
| 73 | printstatfs64(struct tcb *tcp, long addr) |
| 74 | { |
| 75 | struct statfs64 statbuf; |
| 76 | |
Dmitry V. Levin | fd55b54 | 2015-07-16 23:32:12 +0000 | [diff] [blame] | 77 | if (umove_or_printaddr(tcp, addr, &statbuf)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 78 | return; |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 79 | tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ", |
| 80 | sprintfstype(statbuf.f_type), |
| 81 | (unsigned long long)statbuf.f_bsize, |
| 82 | (unsigned long long)statbuf.f_blocks, |
| 83 | (unsigned long long)statbuf.f_bfree); |
| 84 | tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}", |
| 85 | (unsigned long long)statbuf.f_bavail, |
| 86 | (unsigned long long)statbuf.f_files, |
| 87 | (unsigned long long)statbuf.f_ffree, |
| 88 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 89 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
| 90 | #ifdef _STATFS_F_FRSIZE |
| 91 | tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize); |
| 92 | #endif |
| 93 | #ifdef _STATFS_F_FLAGS |
| 94 | tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags); |
| 95 | #endif |
| 96 | tprints("}"); |
| 97 | } |
| 98 | |
| 99 | struct compat_statfs64 { |
| 100 | uint32_t f_type; |
| 101 | uint32_t f_bsize; |
| 102 | uint64_t f_blocks; |
| 103 | uint64_t f_bfree; |
| 104 | uint64_t f_bavail; |
| 105 | uint64_t f_files; |
| 106 | uint64_t f_ffree; |
| 107 | fsid_t f_fsid; |
| 108 | uint32_t f_namelen; |
| 109 | uint32_t f_frsize; |
| 110 | uint32_t f_flags; |
| 111 | uint32_t f_spare[4]; |
| 112 | } |
Dmitry V. Levin | d50949d | 2015-03-02 21:34:02 +0000 | [diff] [blame] | 113 | #if defined AARCH64 || defined X86_64 || defined X32 || defined IA64 |
Dmitry V. Levin | 5647cf8 | 2015-03-29 22:45:03 +0000 | [diff] [blame] | 114 | ATTRIBUTE_PACKED ATTRIBUTE_ALIGNED(4) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 115 | #endif |
| 116 | ; |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 117 | #if defined AARCH64 || defined ARM |
| 118 | /* See arch/arm/kernel/sys_oabi-compat.c for details. */ |
| 119 | # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct compat_statfs64) + 4) |
| 120 | #endif |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 121 | |
| 122 | static void |
| 123 | printcompat_statfs64(struct tcb *tcp, const long addr) |
| 124 | { |
| 125 | struct compat_statfs64 statbuf; |
| 126 | |
Dmitry V. Levin | fd55b54 | 2015-07-16 23:32:12 +0000 | [diff] [blame] | 127 | if (umove_or_printaddr(tcp, addr, &statbuf)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 128 | return; |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 129 | tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ", |
| 130 | sprintfstype(statbuf.f_type), |
| 131 | (unsigned long)statbuf.f_bsize, |
| 132 | (unsigned long long)statbuf.f_blocks, |
| 133 | (unsigned long long)statbuf.f_bfree); |
| 134 | tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}", |
| 135 | (unsigned long long)statbuf.f_bavail, |
| 136 | (unsigned long long)statbuf.f_files, |
| 137 | (unsigned long long)statbuf.f_ffree, |
| 138 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 139 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
| 140 | tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize); |
| 141 | tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize); |
| 142 | } |
| 143 | |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 144 | static int |
| 145 | do_statfs64_fstatfs64(struct tcb *tcp) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 146 | { |
| 147 | if (entering(tcp)) { |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 148 | tprintf(", %lu, ", tcp->u_arg[1]); |
| 149 | } else { |
| 150 | if (tcp->u_arg[1] == sizeof(struct statfs64)) |
| 151 | printstatfs64(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 152 | else if (tcp->u_arg[1] == sizeof(struct compat_statfs64) |
| 153 | #ifdef COMPAT_STATFS64_PADDED_SIZE |
| 154 | || tcp->u_arg[1] == COMPAT_STATFS64_PADDED_SIZE |
| 155 | #endif |
| 156 | ) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 157 | printcompat_statfs64(tcp, tcp->u_arg[2]); |
| 158 | else |
| 159 | tprints("{???}"); |
| 160 | } |
| 161 | return 0; |
| 162 | } |
| 163 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 164 | SYS_FUNC(statfs64) |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 165 | { |
| 166 | if (entering(tcp)) |
| 167 | printpath(tcp, tcp->u_arg[0]); |
| 168 | return do_statfs64_fstatfs64(tcp); |
| 169 | } |
| 170 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 171 | SYS_FUNC(fstatfs64) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 172 | { |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 173 | if (entering(tcp)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 174 | printfd(tcp, tcp->u_arg[0]); |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 175 | return do_statfs64_fstatfs64(tcp); |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 176 | } |
Dmitry V. Levin | 9e6a7bf | 2015-01-08 04:12:29 +0000 | [diff] [blame] | 177 | #endif /* HAVE_STRUCT_STATFS64 */ |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 178 | |
| 179 | #ifdef ALPHA |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 180 | SYS_FUNC(osf_statfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 181 | { |
| 182 | if (entering(tcp)) { |
| 183 | printpath(tcp, tcp->u_arg[0]); |
| 184 | tprints(", "); |
| 185 | } else { |
| 186 | printstatfs(tcp, tcp->u_arg[1]); |
| 187 | tprintf(", %lu", tcp->u_arg[2]); |
| 188 | } |
| 189 | return 0; |
| 190 | } |
| 191 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 192 | SYS_FUNC(osf_fstatfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 193 | { |
| 194 | if (entering(tcp)) { |
| 195 | tprintf("%lu, ", tcp->u_arg[0]); |
| 196 | } else { |
| 197 | printstatfs(tcp, tcp->u_arg[1]); |
| 198 | tprintf(", %lu", tcp->u_arg[2]); |
| 199 | } |
| 200 | return 0; |
| 201 | } |
| 202 | #endif /* ALPHA */ |