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 | |
| 42 | #define ASSIGN_NUMBER(dst, src) \ |
| 43 | if (sizeof(src) == sizeof(int)) \ |
| 44 | dst = (unsigned int) (src); \ |
| 45 | else if (sizeof(src) == sizeof(long)) \ |
| 46 | dst = (unsigned long) (src); \ |
| 47 | else \ |
| 48 | dst = (unsigned long long) (src) |
| 49 | |
| 50 | MPERS_PRINTER_DECL(bool, fetch_struct_statfs)(struct tcb *tcp, const long addr, struct strace_statfs *p) |
| 51 | { |
| 52 | struct_statfs b; |
| 53 | |
| 54 | if (umove_or_printaddr(tcp, addr, &b)) |
| 55 | return false; |
| 56 | |
| 57 | ASSIGN_NUMBER(p->f_type, b.f_type); |
| 58 | ASSIGN_NUMBER(p->f_bsize, b.f_bsize); |
| 59 | ASSIGN_NUMBER(p->f_blocks, b.f_blocks); |
| 60 | ASSIGN_NUMBER(p->f_bfree, b.f_bfree); |
| 61 | ASSIGN_NUMBER(p->f_bavail, b.f_bavail); |
| 62 | ASSIGN_NUMBER(p->f_files, b.f_files); |
| 63 | ASSIGN_NUMBER(p->f_ffree, b.f_ffree); |
| 64 | #if defined HAVE_STRUCT_STATFS_F_FSID_VAL |
| 65 | ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.val[0]); |
| 66 | ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.val[1]); |
| 67 | #elif defined HAVE_STRUCT_STATFS_F_FSID___VAL |
| 68 | ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.__val[0]); |
| 69 | ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.__val[1]); |
| 70 | #endif |
| 71 | ASSIGN_NUMBER(p->f_namelen, b.f_namelen); |
| 72 | #ifdef HAVE_STRUCT_STATFS_F_FRSIZE |
| 73 | ASSIGN_NUMBER(p->f_frsize, b.f_frsize); |
| 74 | #endif |
| 75 | #ifdef HAVE_STRUCT_STATFS_F_FLAGS |
| 76 | ASSIGN_NUMBER(p->f_flags, b.f_flags); |
| 77 | #endif |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | #if defined ARM || (defined AARCH64 && defined IN_MPERS) |
| 83 | /* See arch/arm/kernel/sys_oabi-compat.c for details. */ |
| 84 | # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct_statfs64) + 4) |
| 85 | #endif |
| 86 | |
| 87 | MPERS_PRINTER_DECL(bool, fetch_struct_statfs64)(struct tcb *tcp, const long addr, const unsigned long size, struct strace_statfs *p) |
| 88 | { |
| 89 | struct_statfs64 b; |
| 90 | |
| 91 | if (sizeof(b) != size |
| 92 | #ifdef COMPAT_STATFS64_PADDED_SIZE |
| 93 | && sizeof(b) != COMPAT_STATFS64_PADDED_SIZE |
| 94 | #endif |
| 95 | ) { |
| 96 | printaddr(addr); |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | if (umove_or_printaddr(tcp, addr, &b)) |
| 101 | return false; |
| 102 | |
| 103 | ASSIGN_NUMBER(p->f_type, b.f_type); |
| 104 | ASSIGN_NUMBER(p->f_bsize, b.f_bsize); |
| 105 | ASSIGN_NUMBER(p->f_blocks, b.f_blocks); |
| 106 | ASSIGN_NUMBER(p->f_bfree, b.f_bfree); |
| 107 | ASSIGN_NUMBER(p->f_bavail, b.f_bavail); |
| 108 | ASSIGN_NUMBER(p->f_files, b.f_files); |
| 109 | ASSIGN_NUMBER(p->f_ffree, b.f_ffree); |
| 110 | #if defined HAVE_STRUCT_STATFS64_F_FSID_VAL |
| 111 | ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.val[0]); |
| 112 | ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.val[1]); |
| 113 | #elif defined HAVE_STRUCT_STATFS64_F_FSID___VAL |
| 114 | ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.__val[0]); |
| 115 | ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.__val[1]); |
| 116 | #endif |
| 117 | ASSIGN_NUMBER(p->f_namelen, b.f_namelen); |
| 118 | #ifdef HAVE_STRUCT_STATFS64_F_FRSIZE |
| 119 | ASSIGN_NUMBER(p->f_frsize, b.f_frsize); |
| 120 | #endif |
| 121 | #ifdef HAVE_STRUCT_STATFS64_F_FLAGS |
| 122 | ASSIGN_NUMBER(p->f_flags, b.f_flags); |
| 123 | #endif |
| 124 | |
| 125 | return true; |
| 126 | } |