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 | |
| 27 | if (syserror(tcp) || !verbose(tcp)) { |
| 28 | tprintf("%#lx", addr); |
| 29 | return; |
| 30 | } |
| 31 | if (umove(tcp, addr, &statbuf) < 0) { |
| 32 | tprints("{...}"); |
| 33 | return; |
| 34 | } |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 35 | tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ", |
| 36 | sprintfstype(statbuf.f_type), |
| 37 | (unsigned long)statbuf.f_bsize, |
| 38 | (unsigned long)statbuf.f_blocks, |
| 39 | (unsigned long)statbuf.f_bfree); |
| 40 | tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}", |
| 41 | (unsigned long)statbuf.f_bavail, |
| 42 | (unsigned long)statbuf.f_files, |
| 43 | (unsigned long)statbuf.f_ffree, |
| 44 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 45 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 46 | #ifdef _STATFS_F_FRSIZE |
| 47 | tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize); |
| 48 | #endif |
Elliott Hughes | 1b5b567 | 2015-03-17 16:00:31 -0700 | [diff] [blame] | 49 | #ifdef _STATFS_F_FLAGS |
| 50 | tprintf(", f_flags=%lu", (unsigned long)statbuf.f_flags); |
| 51 | #endif |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 52 | tprints("}"); |
| 53 | } |
| 54 | |
| 55 | int |
| 56 | sys_statfs(struct tcb *tcp) |
| 57 | { |
| 58 | if (entering(tcp)) { |
| 59 | printpath(tcp, tcp->u_arg[0]); |
| 60 | tprints(", "); |
| 61 | } else { |
| 62 | printstatfs(tcp, tcp->u_arg[1]); |
| 63 | } |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | int |
| 68 | sys_fstatfs(struct tcb *tcp) |
| 69 | { |
| 70 | if (entering(tcp)) { |
| 71 | printfd(tcp, tcp->u_arg[0]); |
| 72 | tprints(", "); |
| 73 | } else { |
| 74 | printstatfs(tcp, tcp->u_arg[1]); |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
Dmitry V. Levin | 9e6a7bf | 2015-01-08 04:12:29 +0000 | [diff] [blame] | 79 | #ifdef HAVE_STRUCT_STATFS64 |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 80 | static void |
| 81 | printstatfs64(struct tcb *tcp, long addr) |
| 82 | { |
| 83 | struct statfs64 statbuf; |
| 84 | |
| 85 | if (syserror(tcp) || !verbose(tcp)) { |
| 86 | tprintf("%#lx", addr); |
| 87 | return; |
| 88 | } |
| 89 | if (umove(tcp, addr, &statbuf) < 0) { |
| 90 | tprints("{...}"); |
| 91 | return; |
| 92 | } |
| 93 | tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ", |
| 94 | sprintfstype(statbuf.f_type), |
| 95 | (unsigned long long)statbuf.f_bsize, |
| 96 | (unsigned long long)statbuf.f_blocks, |
| 97 | (unsigned long long)statbuf.f_bfree); |
| 98 | tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}", |
| 99 | (unsigned long long)statbuf.f_bavail, |
| 100 | (unsigned long long)statbuf.f_files, |
| 101 | (unsigned long long)statbuf.f_ffree, |
| 102 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 103 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
| 104 | #ifdef _STATFS_F_FRSIZE |
| 105 | tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize); |
| 106 | #endif |
| 107 | #ifdef _STATFS_F_FLAGS |
| 108 | tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags); |
| 109 | #endif |
| 110 | tprints("}"); |
| 111 | } |
| 112 | |
| 113 | struct compat_statfs64 { |
| 114 | uint32_t f_type; |
| 115 | uint32_t f_bsize; |
| 116 | uint64_t f_blocks; |
| 117 | uint64_t f_bfree; |
| 118 | uint64_t f_bavail; |
| 119 | uint64_t f_files; |
| 120 | uint64_t f_ffree; |
| 121 | fsid_t f_fsid; |
| 122 | uint32_t f_namelen; |
| 123 | uint32_t f_frsize; |
| 124 | uint32_t f_flags; |
| 125 | uint32_t f_spare[4]; |
| 126 | } |
Dmitry V. Levin | d50949d | 2015-03-02 21:34:02 +0000 | [diff] [blame] | 127 | #if defined AARCH64 || defined X86_64 || defined X32 || defined IA64 |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 128 | __attribute__ ((packed, aligned(4))) |
| 129 | #endif |
| 130 | ; |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 131 | #if defined AARCH64 || defined ARM |
| 132 | /* See arch/arm/kernel/sys_oabi-compat.c for details. */ |
| 133 | # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct compat_statfs64) + 4) |
| 134 | #endif |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 135 | |
| 136 | static void |
| 137 | printcompat_statfs64(struct tcb *tcp, const long addr) |
| 138 | { |
| 139 | struct compat_statfs64 statbuf; |
| 140 | |
| 141 | if (syserror(tcp) || !verbose(tcp)) { |
| 142 | tprintf("%#lx", addr); |
| 143 | return; |
| 144 | } |
| 145 | if (umove(tcp, addr, &statbuf) < 0) { |
| 146 | tprints("{...}"); |
| 147 | return; |
| 148 | } |
| 149 | tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ", |
| 150 | sprintfstype(statbuf.f_type), |
| 151 | (unsigned long)statbuf.f_bsize, |
| 152 | (unsigned long long)statbuf.f_blocks, |
| 153 | (unsigned long long)statbuf.f_bfree); |
| 154 | tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}", |
| 155 | (unsigned long long)statbuf.f_bavail, |
| 156 | (unsigned long long)statbuf.f_files, |
| 157 | (unsigned long long)statbuf.f_ffree, |
| 158 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 159 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
| 160 | tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize); |
| 161 | tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize); |
| 162 | } |
| 163 | |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 164 | static int |
| 165 | do_statfs64_fstatfs64(struct tcb *tcp) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 166 | { |
| 167 | if (entering(tcp)) { |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 168 | tprintf(", %lu, ", tcp->u_arg[1]); |
| 169 | } else { |
| 170 | if (tcp->u_arg[1] == sizeof(struct statfs64)) |
| 171 | printstatfs64(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 172 | else if (tcp->u_arg[1] == sizeof(struct compat_statfs64) |
| 173 | #ifdef COMPAT_STATFS64_PADDED_SIZE |
| 174 | || tcp->u_arg[1] == COMPAT_STATFS64_PADDED_SIZE |
| 175 | #endif |
| 176 | ) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 177 | printcompat_statfs64(tcp, tcp->u_arg[2]); |
| 178 | else |
| 179 | tprints("{???}"); |
| 180 | } |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 185 | sys_statfs64(struct tcb *tcp) |
| 186 | { |
| 187 | if (entering(tcp)) |
| 188 | printpath(tcp, tcp->u_arg[0]); |
| 189 | return do_statfs64_fstatfs64(tcp); |
| 190 | } |
| 191 | |
| 192 | int |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 193 | sys_fstatfs64(struct tcb *tcp) |
| 194 | { |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 195 | if (entering(tcp)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 196 | printfd(tcp, tcp->u_arg[0]); |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 197 | return do_statfs64_fstatfs64(tcp); |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 198 | } |
Dmitry V. Levin | 9e6a7bf | 2015-01-08 04:12:29 +0000 | [diff] [blame] | 199 | #endif /* HAVE_STRUCT_STATFS64 */ |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 200 | |
| 201 | #ifdef ALPHA |
| 202 | int |
| 203 | osf_statfs(struct tcb *tcp) |
| 204 | { |
| 205 | if (entering(tcp)) { |
| 206 | printpath(tcp, tcp->u_arg[0]); |
| 207 | tprints(", "); |
| 208 | } else { |
| 209 | printstatfs(tcp, tcp->u_arg[1]); |
| 210 | tprintf(", %lu", tcp->u_arg[2]); |
| 211 | } |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | int |
| 216 | osf_fstatfs(struct tcb *tcp) |
| 217 | { |
| 218 | if (entering(tcp)) { |
| 219 | tprintf("%lu, ", tcp->u_arg[0]); |
| 220 | } else { |
| 221 | printstatfs(tcp, tcp->u_arg[1]); |
| 222 | tprintf(", %lu", tcp->u_arg[2]); |
| 223 | } |
| 224 | return 0; |
| 225 | } |
| 226 | #endif /* ALPHA */ |