blob: 6373195d2edb3356b3fec84241f64d4cf9d43066 [file] [log] [blame]
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +00001#include "defs.h"
2#ifdef HAVE_SYS_VFS_H
3# include <sys/vfs.h>
4#endif
5#include "xlat/fsmagic.h"
6
7static const char *
8sprintfstype(const unsigned int magic)
9{
10 static char buf[32];
11 const char *s;
12
13 s = xlat_search(fsmagic, ARRAY_SIZE(fsmagic), magic);
14 if (s) {
15 sprintf(buf, "\"%s\"", s);
16 return buf;
17 }
18 sprintf(buf, "%#x", magic);
19 return buf;
20}
21
22static void
23printstatfs(struct tcb *tcp, const long addr)
24{
25 struct statfs statbuf;
26
27 if (syserror(tcp) || !verbose(tcp)) {
28 tprintf("%#lx", addr);
29 return;
30 }
31 if (umove(tcp, addr, &statbuf) < 0) {
32 tprints("{...}");
33 return;
34 }
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000035 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
36 sprintfstype(statbuf.f_type),
37 (unsigned long)statbuf.f_bsize,
38 (unsigned long)statbuf.f_blocks,
39 (unsigned long)statbuf.f_bfree);
40 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
41 (unsigned long)statbuf.f_bavail,
42 (unsigned long)statbuf.f_files,
43 (unsigned long)statbuf.f_ffree,
44 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
45 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000046#ifdef _STATFS_F_FRSIZE
47 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
48#endif
Elliott Hughes1b5b5672015-03-17 16:00:31 -070049#ifdef _STATFS_F_FLAGS
50 tprintf(", f_flags=%lu", (unsigned long)statbuf.f_flags);
51#endif
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000052 tprints("}");
53}
54
55int
56sys_statfs(struct tcb *tcp)
57{
58 if (entering(tcp)) {
59 printpath(tcp, tcp->u_arg[0]);
60 tprints(", ");
61 } else {
62 printstatfs(tcp, tcp->u_arg[1]);
63 }
64 return 0;
65}
66
67int
68sys_fstatfs(struct tcb *tcp)
69{
70 if (entering(tcp)) {
71 printfd(tcp, tcp->u_arg[0]);
72 tprints(", ");
73 } else {
74 printstatfs(tcp, tcp->u_arg[1]);
75 }
76 return 0;
77}
78
Dmitry V. Levin9e6a7bf2015-01-08 04:12:29 +000079#ifdef HAVE_STRUCT_STATFS64
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000080static void
81printstatfs64(struct tcb *tcp, long addr)
82{
83 struct statfs64 statbuf;
84
85 if (syserror(tcp) || !verbose(tcp)) {
86 tprintf("%#lx", addr);
87 return;
88 }
89 if (umove(tcp, addr, &statbuf) < 0) {
90 tprints("{...}");
91 return;
92 }
93 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
94 sprintfstype(statbuf.f_type),
95 (unsigned long long)statbuf.f_bsize,
96 (unsigned long long)statbuf.f_blocks,
97 (unsigned long long)statbuf.f_bfree);
98 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
99 (unsigned long long)statbuf.f_bavail,
100 (unsigned long long)statbuf.f_files,
101 (unsigned long long)statbuf.f_ffree,
102 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
103 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
104#ifdef _STATFS_F_FRSIZE
105 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
106#endif
107#ifdef _STATFS_F_FLAGS
108 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
109#endif
110 tprints("}");
111}
112
113struct compat_statfs64 {
114 uint32_t f_type;
115 uint32_t f_bsize;
116 uint64_t f_blocks;
117 uint64_t f_bfree;
118 uint64_t f_bavail;
119 uint64_t f_files;
120 uint64_t f_ffree;
121 fsid_t f_fsid;
122 uint32_t f_namelen;
123 uint32_t f_frsize;
124 uint32_t f_flags;
125 uint32_t f_spare[4];
126}
Dmitry V. Levind50949d2015-03-02 21:34:02 +0000127#if defined AARCH64 || defined X86_64 || defined X32 || defined IA64
Dmitry V. Levin5647cf82015-03-29 22:45:03 +0000128 ATTRIBUTE_PACKED ATTRIBUTE_ALIGNED(4)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000129#endif
130;
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000131#if defined AARCH64 || defined ARM
132/* See arch/arm/kernel/sys_oabi-compat.c for details. */
133# define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct compat_statfs64) + 4)
134#endif
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000135
136static void
137printcompat_statfs64(struct tcb *tcp, const long addr)
138{
139 struct compat_statfs64 statbuf;
140
141 if (syserror(tcp) || !verbose(tcp)) {
142 tprintf("%#lx", addr);
143 return;
144 }
145 if (umove(tcp, addr, &statbuf) < 0) {
146 tprints("{...}");
147 return;
148 }
149 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
150 sprintfstype(statbuf.f_type),
151 (unsigned long)statbuf.f_bsize,
152 (unsigned long long)statbuf.f_blocks,
153 (unsigned long long)statbuf.f_bfree);
154 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
155 (unsigned long long)statbuf.f_bavail,
156 (unsigned long long)statbuf.f_files,
157 (unsigned long long)statbuf.f_ffree,
158 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
159 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
160 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
161 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
162}
163
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000164static int
165do_statfs64_fstatfs64(struct tcb *tcp)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000166{
167 if (entering(tcp)) {
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000168 tprintf(", %lu, ", tcp->u_arg[1]);
169 } else {
170 if (tcp->u_arg[1] == sizeof(struct statfs64))
171 printstatfs64(tcp, tcp->u_arg[2]);
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000172 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64)
173#ifdef COMPAT_STATFS64_PADDED_SIZE
174 || tcp->u_arg[1] == COMPAT_STATFS64_PADDED_SIZE
175#endif
176 )
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000177 printcompat_statfs64(tcp, tcp->u_arg[2]);
178 else
179 tprints("{???}");
180 }
181 return 0;
182}
183
184int
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000185sys_statfs64(struct tcb *tcp)
186{
187 if (entering(tcp))
188 printpath(tcp, tcp->u_arg[0]);
189 return do_statfs64_fstatfs64(tcp);
190}
191
192int
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000193sys_fstatfs64(struct tcb *tcp)
194{
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000195 if (entering(tcp))
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000196 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000197 return do_statfs64_fstatfs64(tcp);
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000198}
Dmitry V. Levin9e6a7bf2015-01-08 04:12:29 +0000199#endif /* HAVE_STRUCT_STATFS64 */
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000200
201#ifdef ALPHA
202int
203osf_statfs(struct tcb *tcp)
204{
205 if (entering(tcp)) {
206 printpath(tcp, tcp->u_arg[0]);
207 tprints(", ");
208 } else {
209 printstatfs(tcp, tcp->u_arg[1]);
210 tprintf(", %lu", tcp->u_arg[2]);
211 }
212 return 0;
213}
214
215int
216osf_fstatfs(struct tcb *tcp)
217{
218 if (entering(tcp)) {
219 tprintf("%lu, ", tcp->u_arg[0]);
220 } else {
221 printstatfs(tcp, tcp->u_arg[1]);
222 tprintf(", %lu", tcp->u_arg[2]);
223 }
224 return 0;
225}
226#endif /* ALPHA */