blob: 0cfe5bafc0272bba72517e603ac6f9dfb3b8dde2 [file] [log] [blame]
Dmitry V. Levin67c2f672016-04-26 00:21:26 +00001/*
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>
35typedef struct statfs struct_statfs;
36typedef struct statfs64 struct_statfs64;
37
38#include MPERS_DEFS
39
40#include "statfs.h"
41
Dmitry V. Levina8fce092016-05-21 22:53:06 +000042MPERS_PRINTER_DECL(bool, fetch_struct_statfs,
43 struct tcb *tcp, const long addr, struct strace_statfs *p)
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000044{
45 struct_statfs b;
46
47 if (umove_or_printaddr(tcp, addr, &b))
48 return false;
49
Dmitry V. Levin84a979c2016-05-26 10:12:17 +000050 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. Levin67c2f672016-04-26 00:21:26 +000057#if defined HAVE_STRUCT_STATFS_F_FSID_VAL
Dmitry V. Levin84a979c2016-05-26 10:12:17 +000058 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. Levin67c2f672016-04-26 00:21:26 +000060#elif defined HAVE_STRUCT_STATFS_F_FSID___VAL
Dmitry V. Levin84a979c2016-05-26 10:12:17 +000061 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. Levin67c2f672016-04-26 00:21:26 +000063#endif
Dmitry V. Levin84a979c2016-05-26 10:12:17 +000064 p->f_namelen = widen_to_ull(b.f_namelen);
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000065#ifdef HAVE_STRUCT_STATFS_F_FRSIZE
Dmitry V. Levin84a979c2016-05-26 10:12:17 +000066 p->f_frsize = widen_to_ull(b.f_frsize);
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000067#endif
68#ifdef HAVE_STRUCT_STATFS_F_FLAGS
Dmitry V. Levin84a979c2016-05-26 10:12:17 +000069 p->f_flags = widen_to_ull(b.f_flags);
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000070#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. Levina8fce092016-05-21 22:53:06 +000080MPERS_PRINTER_DECL(bool, fetch_struct_statfs64,
81 struct tcb *tcp, const long addr, const unsigned long size,
82 struct strace_statfs *p)
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000083{
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. Levin84a979c2016-05-26 10:12:17 +000098 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. Levin67c2f672016-04-26 00:21:26 +0000105#if defined HAVE_STRUCT_STATFS64_F_FSID_VAL
Dmitry V. Levin84a979c2016-05-26 10:12:17 +0000106 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. Levin67c2f672016-04-26 00:21:26 +0000108#elif defined HAVE_STRUCT_STATFS64_F_FSID___VAL
Dmitry V. Levin84a979c2016-05-26 10:12:17 +0000109 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. Levin67c2f672016-04-26 00:21:26 +0000111#endif
Dmitry V. Levin84a979c2016-05-26 10:12:17 +0000112 p->f_namelen = widen_to_ull(b.f_namelen);
Dmitry V. Levin67c2f672016-04-26 00:21:26 +0000113#ifdef HAVE_STRUCT_STATFS64_F_FRSIZE
Dmitry V. Levin84a979c2016-05-26 10:12:17 +0000114 p->f_frsize = widen_to_ull(b.f_frsize);
Dmitry V. Levin67c2f672016-04-26 00:21:26 +0000115#endif
116#ifdef HAVE_STRUCT_STATFS64_F_FLAGS
Dmitry V. Levin84a979c2016-05-26 10:12:17 +0000117 p->f_flags = widen_to_ull(b.f_flags);
Dmitry V. Levin67c2f672016-04-26 00:21:26 +0000118#endif
119
120 return true;
121}