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