Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "defs.h" |
| 29 | |
| 30 | #include DEF_MPERS_TYPE(struct_statfs) |
| 31 | #include DEF_MPERS_TYPE(struct_statfs64) |
| 32 | |
| 33 | #include <linux/types.h> |
| 34 | #include <asm/statfs.h> |
| 35 | typedef struct statfs struct_statfs; |
| 36 | typedef struct statfs64 struct_statfs64; |
| 37 | |
| 38 | #include MPERS_DEFS |
| 39 | |
| 40 | #include "statfs.h" |
| 41 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 42 | MPERS_PRINTER_DECL(bool, fetch_struct_statfs, |
| 43 | struct tcb *tcp, const long addr, struct strace_statfs *p) |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 44 | { |
| 45 | struct_statfs b; |
| 46 | |
| 47 | if (umove_or_printaddr(tcp, addr, &b)) |
| 48 | return false; |
| 49 | |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 50 | p->f_type = widen_to_ull(b.f_type); |
| 51 | p->f_bsize = widen_to_ull(b.f_bsize); |
| 52 | p->f_blocks = widen_to_ull(b.f_blocks); |
| 53 | p->f_bfree = widen_to_ull(b.f_bfree); |
| 54 | p->f_bavail = widen_to_ull(b.f_bavail); |
| 55 | p->f_files = widen_to_ull(b.f_files); |
| 56 | p->f_ffree = widen_to_ull(b.f_ffree); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 57 | #if defined HAVE_STRUCT_STATFS_F_FSID_VAL |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 58 | p->f_fsid[0] = widen_to_ull(b.f_fsid.val[0]); |
| 59 | p->f_fsid[1] = widen_to_ull(b.f_fsid.val[1]); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 60 | #elif defined HAVE_STRUCT_STATFS_F_FSID___VAL |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 61 | p->f_fsid[0] = widen_to_ull(b.f_fsid.__val[0]); |
| 62 | p->f_fsid[1] = widen_to_ull(b.f_fsid.__val[1]); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 63 | #endif |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 64 | p->f_namelen = widen_to_ull(b.f_namelen); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 65 | #ifdef HAVE_STRUCT_STATFS_F_FRSIZE |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 66 | p->f_frsize = widen_to_ull(b.f_frsize); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 67 | #endif |
| 68 | #ifdef HAVE_STRUCT_STATFS_F_FLAGS |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 69 | p->f_flags = widen_to_ull(b.f_flags); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | #if defined ARM || (defined AARCH64 && defined IN_MPERS) |
| 76 | /* See arch/arm/kernel/sys_oabi-compat.c for details. */ |
| 77 | # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct_statfs64) + 4) |
| 78 | #endif |
| 79 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 80 | MPERS_PRINTER_DECL(bool, fetch_struct_statfs64, |
| 81 | struct tcb *tcp, const long addr, const unsigned long size, |
| 82 | struct strace_statfs *p) |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 83 | { |
| 84 | struct_statfs64 b; |
| 85 | |
| 86 | if (sizeof(b) != size |
| 87 | #ifdef COMPAT_STATFS64_PADDED_SIZE |
| 88 | && sizeof(b) != COMPAT_STATFS64_PADDED_SIZE |
| 89 | #endif |
| 90 | ) { |
| 91 | printaddr(addr); |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | if (umove_or_printaddr(tcp, addr, &b)) |
| 96 | return false; |
| 97 | |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 98 | p->f_type = widen_to_ull(b.f_type); |
| 99 | p->f_bsize = widen_to_ull(b.f_bsize); |
| 100 | p->f_blocks = widen_to_ull(b.f_blocks); |
| 101 | p->f_bfree = widen_to_ull(b.f_bfree); |
| 102 | p->f_bavail = widen_to_ull(b.f_bavail); |
| 103 | p->f_files = widen_to_ull(b.f_files); |
| 104 | p->f_ffree = widen_to_ull(b.f_ffree); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 105 | #if defined HAVE_STRUCT_STATFS64_F_FSID_VAL |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 106 | p->f_fsid[0] = widen_to_ull(b.f_fsid.val[0]); |
| 107 | p->f_fsid[1] = widen_to_ull(b.f_fsid.val[1]); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 108 | #elif defined HAVE_STRUCT_STATFS64_F_FSID___VAL |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 109 | p->f_fsid[0] = widen_to_ull(b.f_fsid.__val[0]); |
| 110 | p->f_fsid[1] = widen_to_ull(b.f_fsid.__val[1]); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 111 | #endif |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 112 | p->f_namelen = widen_to_ull(b.f_namelen); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 113 | #ifdef HAVE_STRUCT_STATFS64_F_FRSIZE |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 114 | p->f_frsize = widen_to_ull(b.f_frsize); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 115 | #endif |
| 116 | #ifdef HAVE_STRUCT_STATFS64_F_FLAGS |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 117 | p->f_flags = widen_to_ull(b.f_flags); |
Dmitry V. Levin | 67c2f67 | 2016-04-26 00:21:26 +0000 | [diff] [blame] | 118 | #endif |
| 119 | |
| 120 | return true; |
| 121 | } |