]> granicus.if.org Git - strace/blob - statfs.c
statfs: don't quote f_type macro names
[strace] / statfs.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * Copyright (c) 2003 Ulrich Drepper <drepper@redhat.com>
7  * Copyright (c) 2012 Andreas Schwab <schwab@linux-m68k.org>
8  * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include "defs.h"
35 #ifdef HAVE_SYS_VFS_H
36 # include <sys/vfs.h>
37 #endif
38 #include "xlat/fsmagic.h"
39
40 static const char *
41 sprintfstype(const unsigned int magic)
42 {
43         static char buf[32];
44         const char *s;
45
46         s = xlat_search(fsmagic, ARRAY_SIZE(fsmagic), magic);
47         if (s)
48                 return s;
49         sprintf(buf, "%#x", magic);
50         return buf;
51 }
52
53 static void
54 printstatfs(struct tcb *tcp, const long addr)
55 {
56         struct statfs statbuf;
57
58         if (umove_or_printaddr(tcp, addr, &statbuf))
59                 return;
60         tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
61                 sprintfstype(statbuf.f_type),
62                 (unsigned long)statbuf.f_bsize,
63                 (unsigned long)statbuf.f_blocks,
64                 (unsigned long)statbuf.f_bfree);
65         tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
66                 (unsigned long)statbuf.f_bavail,
67                 (unsigned long)statbuf.f_files,
68                 (unsigned long)statbuf.f_ffree,
69                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
70         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
71 #ifdef _STATFS_F_FRSIZE
72         tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
73 #endif
74 #ifdef _STATFS_F_FLAGS
75         tprintf(", f_flags=%lu", (unsigned long)statbuf.f_flags);
76 #endif
77         tprints("}");
78 }
79
80 SYS_FUNC(statfs)
81 {
82         if (entering(tcp)) {
83                 printpath(tcp, tcp->u_arg[0]);
84                 tprints(", ");
85         } else {
86                 printstatfs(tcp, tcp->u_arg[1]);
87         }
88         return 0;
89 }
90
91 SYS_FUNC(fstatfs)
92 {
93         if (entering(tcp)) {
94                 printfd(tcp, tcp->u_arg[0]);
95                 tprints(", ");
96         } else {
97                 printstatfs(tcp, tcp->u_arg[1]);
98         }
99         return 0;
100 }
101
102 #ifdef HAVE_STRUCT_STATFS64
103 static void
104 printstatfs64(struct tcb *tcp, long addr)
105 {
106         struct statfs64 statbuf;
107
108         if (umove_or_printaddr(tcp, addr, &statbuf))
109                 return;
110         tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
111                 sprintfstype(statbuf.f_type),
112                 (unsigned long long)statbuf.f_bsize,
113                 (unsigned long long)statbuf.f_blocks,
114                 (unsigned long long)statbuf.f_bfree);
115         tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
116                 (unsigned long long)statbuf.f_bavail,
117                 (unsigned long long)statbuf.f_files,
118                 (unsigned long long)statbuf.f_ffree,
119                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
120         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
121 #ifdef _STATFS_F_FRSIZE
122         tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
123 #endif
124 #ifdef _STATFS_F_FLAGS
125         tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
126 #endif
127         tprints("}");
128 }
129
130 struct compat_statfs64 {
131         uint32_t f_type;
132         uint32_t f_bsize;
133         uint64_t f_blocks;
134         uint64_t f_bfree;
135         uint64_t f_bavail;
136         uint64_t f_files;
137         uint64_t f_ffree;
138         fsid_t f_fsid;
139         uint32_t f_namelen;
140         uint32_t f_frsize;
141         uint32_t f_flags;
142         uint32_t f_spare[4];
143 }
144 #if defined AARCH64 || defined X86_64 || defined X32 || defined IA64
145   ATTRIBUTE_PACKED ATTRIBUTE_ALIGNED(4)
146 #endif
147 ;
148 #if defined AARCH64 || defined ARM
149 /* See arch/arm/kernel/sys_oabi-compat.c for details. */
150 # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct compat_statfs64) + 4)
151 #endif
152
153 static void
154 printcompat_statfs64(struct tcb *tcp, const long addr)
155 {
156         struct compat_statfs64 statbuf;
157
158         if (umove_or_printaddr(tcp, addr, &statbuf))
159                 return;
160         tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
161                 sprintfstype(statbuf.f_type),
162                 (unsigned long)statbuf.f_bsize,
163                 (unsigned long long)statbuf.f_blocks,
164                 (unsigned long long)statbuf.f_bfree);
165         tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
166                 (unsigned long long)statbuf.f_bavail,
167                 (unsigned long long)statbuf.f_files,
168                 (unsigned long long)statbuf.f_ffree,
169                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
170         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
171         tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
172         tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
173 }
174
175 static int
176 do_statfs64_fstatfs64(struct tcb *tcp)
177 {
178         if (entering(tcp)) {
179                 tprintf(", %lu, ", tcp->u_arg[1]);
180         } else {
181                 if (tcp->u_arg[1] == sizeof(struct statfs64))
182                         printstatfs64(tcp, tcp->u_arg[2]);
183                 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64)
184 #ifdef COMPAT_STATFS64_PADDED_SIZE
185                          || tcp->u_arg[1] == COMPAT_STATFS64_PADDED_SIZE
186 #endif
187                                                                         )
188                         printcompat_statfs64(tcp, tcp->u_arg[2]);
189                 else
190                         tprints("{???}");
191         }
192         return 0;
193 }
194
195 SYS_FUNC(statfs64)
196 {
197         if (entering(tcp))
198                 printpath(tcp, tcp->u_arg[0]);
199         return do_statfs64_fstatfs64(tcp);
200 }
201
202 SYS_FUNC(fstatfs64)
203 {
204         if (entering(tcp))
205                 printfd(tcp, tcp->u_arg[0]);
206         return do_statfs64_fstatfs64(tcp);
207 }
208 #endif /* HAVE_STRUCT_STATFS64 */
209
210 #ifdef ALPHA
211 SYS_FUNC(osf_statfs)
212 {
213         if (entering(tcp)) {
214                 printpath(tcp, tcp->u_arg[0]);
215                 tprints(", ");
216         } else {
217                 printstatfs(tcp, tcp->u_arg[1]);
218                 tprintf(", %lu", tcp->u_arg[2]);
219         }
220         return 0;
221 }
222
223 SYS_FUNC(osf_fstatfs)
224 {
225         if (entering(tcp)) {
226                 tprintf("%lu, ", tcp->u_arg[0]);
227         } else {
228                 printstatfs(tcp, tcp->u_arg[1]);
229                 tprintf(", %lu", tcp->u_arg[2]);
230         }
231         return 0;
232 }
233 #endif /* ALPHA */