Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com> |
| 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 2003 Ulrich Drepper <drepper@redhat.com> |
| 7 | * Copyright (c) 2012 Andreas Schwab <schwab@linux-m68k.org> |
| 8 | * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org> |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. The name of the author may not be used to endorse or promote products |
| 20 | * derived from this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | */ |
| 33 | |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 34 | #include "defs.h" |
| 35 | #ifdef HAVE_SYS_VFS_H |
| 36 | # include <sys/vfs.h> |
| 37 | #endif |
| 38 | #include "xlat/fsmagic.h" |
| 39 | |
| 40 | static const char * |
| 41 | sprintfstype(const unsigned int magic) |
| 42 | { |
| 43 | static char buf[32]; |
| 44 | const char *s; |
| 45 | |
| 46 | s = xlat_search(fsmagic, ARRAY_SIZE(fsmagic), magic); |
| 47 | if (s) { |
| 48 | sprintf(buf, "\"%s\"", s); |
| 49 | return buf; |
| 50 | } |
| 51 | sprintf(buf, "%#x", magic); |
| 52 | return buf; |
| 53 | } |
| 54 | |
| 55 | static void |
| 56 | printstatfs(struct tcb *tcp, const long addr) |
| 57 | { |
| 58 | struct statfs statbuf; |
| 59 | |
Dmitry V. Levin | fd55b54 | 2015-07-16 23:32:12 +0000 | [diff] [blame] | 60 | if (umove_or_printaddr(tcp, addr, &statbuf)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 61 | return; |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 62 | tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ", |
| 63 | sprintfstype(statbuf.f_type), |
| 64 | (unsigned long)statbuf.f_bsize, |
| 65 | (unsigned long)statbuf.f_blocks, |
| 66 | (unsigned long)statbuf.f_bfree); |
| 67 | tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}", |
| 68 | (unsigned long)statbuf.f_bavail, |
| 69 | (unsigned long)statbuf.f_files, |
| 70 | (unsigned long)statbuf.f_ffree, |
| 71 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 72 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 73 | #ifdef _STATFS_F_FRSIZE |
| 74 | tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize); |
| 75 | #endif |
Elliott Hughes | 1b5b567 | 2015-03-17 16:00:31 -0700 | [diff] [blame] | 76 | #ifdef _STATFS_F_FLAGS |
| 77 | tprintf(", f_flags=%lu", (unsigned long)statbuf.f_flags); |
| 78 | #endif |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 79 | tprints("}"); |
| 80 | } |
| 81 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 82 | SYS_FUNC(statfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 83 | { |
| 84 | if (entering(tcp)) { |
| 85 | printpath(tcp, tcp->u_arg[0]); |
| 86 | tprints(", "); |
| 87 | } else { |
| 88 | printstatfs(tcp, tcp->u_arg[1]); |
| 89 | } |
| 90 | return 0; |
| 91 | } |
| 92 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 93 | SYS_FUNC(fstatfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 94 | { |
| 95 | if (entering(tcp)) { |
| 96 | printfd(tcp, tcp->u_arg[0]); |
| 97 | tprints(", "); |
| 98 | } else { |
| 99 | printstatfs(tcp, tcp->u_arg[1]); |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
Dmitry V. Levin | 9e6a7bf | 2015-01-08 04:12:29 +0000 | [diff] [blame] | 104 | #ifdef HAVE_STRUCT_STATFS64 |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 105 | static void |
| 106 | printstatfs64(struct tcb *tcp, long addr) |
| 107 | { |
| 108 | struct statfs64 statbuf; |
| 109 | |
Dmitry V. Levin | fd55b54 | 2015-07-16 23:32:12 +0000 | [diff] [blame] | 110 | if (umove_or_printaddr(tcp, addr, &statbuf)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 111 | return; |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 112 | tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ", |
| 113 | sprintfstype(statbuf.f_type), |
| 114 | (unsigned long long)statbuf.f_bsize, |
| 115 | (unsigned long long)statbuf.f_blocks, |
| 116 | (unsigned long long)statbuf.f_bfree); |
| 117 | tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}", |
| 118 | (unsigned long long)statbuf.f_bavail, |
| 119 | (unsigned long long)statbuf.f_files, |
| 120 | (unsigned long long)statbuf.f_ffree, |
| 121 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 122 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
| 123 | #ifdef _STATFS_F_FRSIZE |
| 124 | tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize); |
| 125 | #endif |
| 126 | #ifdef _STATFS_F_FLAGS |
| 127 | tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags); |
| 128 | #endif |
| 129 | tprints("}"); |
| 130 | } |
| 131 | |
| 132 | struct compat_statfs64 { |
| 133 | uint32_t f_type; |
| 134 | uint32_t f_bsize; |
| 135 | uint64_t f_blocks; |
| 136 | uint64_t f_bfree; |
| 137 | uint64_t f_bavail; |
| 138 | uint64_t f_files; |
| 139 | uint64_t f_ffree; |
| 140 | fsid_t f_fsid; |
| 141 | uint32_t f_namelen; |
| 142 | uint32_t f_frsize; |
| 143 | uint32_t f_flags; |
| 144 | uint32_t f_spare[4]; |
| 145 | } |
Dmitry V. Levin | d50949d | 2015-03-02 21:34:02 +0000 | [diff] [blame] | 146 | #if defined AARCH64 || defined X86_64 || defined X32 || defined IA64 |
Dmitry V. Levin | 5647cf8 | 2015-03-29 22:45:03 +0000 | [diff] [blame] | 147 | ATTRIBUTE_PACKED ATTRIBUTE_ALIGNED(4) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 148 | #endif |
| 149 | ; |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 150 | #if defined AARCH64 || defined ARM |
| 151 | /* See arch/arm/kernel/sys_oabi-compat.c for details. */ |
| 152 | # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct compat_statfs64) + 4) |
| 153 | #endif |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 154 | |
| 155 | static void |
| 156 | printcompat_statfs64(struct tcb *tcp, const long addr) |
| 157 | { |
| 158 | struct compat_statfs64 statbuf; |
| 159 | |
Dmitry V. Levin | fd55b54 | 2015-07-16 23:32:12 +0000 | [diff] [blame] | 160 | if (umove_or_printaddr(tcp, addr, &statbuf)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 161 | return; |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 162 | tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ", |
| 163 | sprintfstype(statbuf.f_type), |
| 164 | (unsigned long)statbuf.f_bsize, |
| 165 | (unsigned long long)statbuf.f_blocks, |
| 166 | (unsigned long long)statbuf.f_bfree); |
| 167 | tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}", |
| 168 | (unsigned long long)statbuf.f_bavail, |
| 169 | (unsigned long long)statbuf.f_files, |
| 170 | (unsigned long long)statbuf.f_ffree, |
| 171 | statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); |
| 172 | tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); |
| 173 | tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize); |
| 174 | tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize); |
| 175 | } |
| 176 | |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 177 | static int |
| 178 | do_statfs64_fstatfs64(struct tcb *tcp) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 179 | { |
| 180 | if (entering(tcp)) { |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 181 | tprintf(", %lu, ", tcp->u_arg[1]); |
| 182 | } else { |
| 183 | if (tcp->u_arg[1] == sizeof(struct statfs64)) |
| 184 | printstatfs64(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 185 | else if (tcp->u_arg[1] == sizeof(struct compat_statfs64) |
| 186 | #ifdef COMPAT_STATFS64_PADDED_SIZE |
| 187 | || tcp->u_arg[1] == COMPAT_STATFS64_PADDED_SIZE |
| 188 | #endif |
| 189 | ) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 190 | printcompat_statfs64(tcp, tcp->u_arg[2]); |
| 191 | else |
| 192 | tprints("{???}"); |
| 193 | } |
| 194 | return 0; |
| 195 | } |
| 196 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 197 | SYS_FUNC(statfs64) |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 198 | { |
| 199 | if (entering(tcp)) |
| 200 | printpath(tcp, tcp->u_arg[0]); |
| 201 | return do_statfs64_fstatfs64(tcp); |
| 202 | } |
| 203 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 204 | SYS_FUNC(fstatfs64) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 205 | { |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 206 | if (entering(tcp)) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 207 | printfd(tcp, tcp->u_arg[0]); |
Dmitry V. Levin | babe7f6 | 2015-03-18 16:32:04 +0000 | [diff] [blame] | 208 | return do_statfs64_fstatfs64(tcp); |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 209 | } |
Dmitry V. Levin | 9e6a7bf | 2015-01-08 04:12:29 +0000 | [diff] [blame] | 210 | #endif /* HAVE_STRUCT_STATFS64 */ |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 211 | |
| 212 | #ifdef ALPHA |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 213 | SYS_FUNC(osf_statfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 214 | { |
| 215 | if (entering(tcp)) { |
| 216 | printpath(tcp, tcp->u_arg[0]); |
| 217 | tprints(", "); |
| 218 | } else { |
| 219 | printstatfs(tcp, tcp->u_arg[1]); |
| 220 | tprintf(", %lu", tcp->u_arg[2]); |
| 221 | } |
| 222 | return 0; |
| 223 | } |
| 224 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 225 | SYS_FUNC(osf_fstatfs) |
Dmitry V. Levin | 9a0dd74 | 2014-09-22 00:17:42 +0000 | [diff] [blame] | 226 | { |
| 227 | if (entering(tcp)) { |
| 228 | tprintf("%lu, ", tcp->u_arg[0]); |
| 229 | } else { |
| 230 | printstatfs(tcp, tcp->u_arg[1]); |
| 231 | tprintf(", %lu", tcp->u_arg[2]); |
| 232 | } |
| 233 | return 0; |
| 234 | } |
| 235 | #endif /* ALPHA */ |