]> granicus.if.org Git - strace/blob - fetch_struct_statfs.c
Fix explicit casts of signed integer types to unsigned long long
[strace] / fetch_struct_statfs.c
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 MPERS_PRINTER_DECL(bool, fetch_struct_statfs,
43                    struct tcb *tcp, const long addr, struct strace_statfs *p)
44 {
45         struct_statfs b;
46
47         if (umove_or_printaddr(tcp, addr, &b))
48                 return false;
49
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);
57 #if defined HAVE_STRUCT_STATFS_F_FSID_VAL
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]);
60 #elif defined HAVE_STRUCT_STATFS_F_FSID___VAL
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]);
63 #endif
64         p->f_namelen = widen_to_ull(b.f_namelen);
65 #ifdef HAVE_STRUCT_STATFS_F_FRSIZE
66         p->f_frsize = widen_to_ull(b.f_frsize);
67 #endif
68 #ifdef HAVE_STRUCT_STATFS_F_FLAGS
69         p->f_flags = widen_to_ull(b.f_flags);
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
80 MPERS_PRINTER_DECL(bool, fetch_struct_statfs64,
81                    struct tcb *tcp, const long addr, const unsigned long size,
82                    struct strace_statfs *p)
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
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);
105 #if defined HAVE_STRUCT_STATFS64_F_FSID_VAL
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]);
108 #elif defined HAVE_STRUCT_STATFS64_F_FSID___VAL
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]);
111 #endif
112         p->f_namelen = widen_to_ull(b.f_namelen);
113 #ifdef HAVE_STRUCT_STATFS64_F_FRSIZE
114         p->f_frsize = widen_to_ull(b.f_frsize);
115 #endif
116 #ifdef HAVE_STRUCT_STATFS64_F_FLAGS
117         p->f_flags = widen_to_ull(b.f_flags);
118 #endif
119
120         return true;
121 }