blob: 35f8652f02f367f460c8515c956ddc95551e902a [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 }
35#ifdef ALPHA
36 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
37 sprintfstype(statbuf.f_type),
38 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
39 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
40 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
41 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
42 statbuf.f_namelen);
43#else /* !ALPHA */
44 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
45 sprintfstype(statbuf.f_type),
46 (unsigned long)statbuf.f_bsize,
47 (unsigned long)statbuf.f_blocks,
48 (unsigned long)statbuf.f_bfree);
49 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
50 (unsigned long)statbuf.f_bavail,
51 (unsigned long)statbuf.f_files,
52 (unsigned long)statbuf.f_ffree,
53 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
54 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
55#endif /* !ALPHA */
56#ifdef _STATFS_F_FRSIZE
57 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
58#endif
59 tprints("}");
60}
61
62int
63sys_statfs(struct tcb *tcp)
64{
65 if (entering(tcp)) {
66 printpath(tcp, tcp->u_arg[0]);
67 tprints(", ");
68 } else {
69 printstatfs(tcp, tcp->u_arg[1]);
70 }
71 return 0;
72}
73
74int
75sys_fstatfs(struct tcb *tcp)
76{
77 if (entering(tcp)) {
78 printfd(tcp, tcp->u_arg[0]);
79 tprints(", ");
80 } else {
81 printstatfs(tcp, tcp->u_arg[1]);
82 }
83 return 0;
84}
85
Dmitry V. Levin9e6a7bf2015-01-08 04:12:29 +000086#ifdef HAVE_STRUCT_STATFS64
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000087static void
88printstatfs64(struct tcb *tcp, long addr)
89{
90 struct statfs64 statbuf;
91
92 if (syserror(tcp) || !verbose(tcp)) {
93 tprintf("%#lx", addr);
94 return;
95 }
96 if (umove(tcp, addr, &statbuf) < 0) {
97 tprints("{...}");
98 return;
99 }
100 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
101 sprintfstype(statbuf.f_type),
102 (unsigned long long)statbuf.f_bsize,
103 (unsigned long long)statbuf.f_blocks,
104 (unsigned long long)statbuf.f_bfree);
105 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
106 (unsigned long long)statbuf.f_bavail,
107 (unsigned long long)statbuf.f_files,
108 (unsigned long long)statbuf.f_ffree,
109 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
110 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
111#ifdef _STATFS_F_FRSIZE
112 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
113#endif
114#ifdef _STATFS_F_FLAGS
115 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
116#endif
117 tprints("}");
118}
119
120struct compat_statfs64 {
121 uint32_t f_type;
122 uint32_t f_bsize;
123 uint64_t f_blocks;
124 uint64_t f_bfree;
125 uint64_t f_bavail;
126 uint64_t f_files;
127 uint64_t f_ffree;
128 fsid_t f_fsid;
129 uint32_t f_namelen;
130 uint32_t f_frsize;
131 uint32_t f_flags;
132 uint32_t f_spare[4];
133}
134#if defined(X86_64) || defined(IA64)
135 __attribute__ ((packed, aligned(4)))
136#endif
137;
138
139static void
140printcompat_statfs64(struct tcb *tcp, const long addr)
141{
142 struct compat_statfs64 statbuf;
143
144 if (syserror(tcp) || !verbose(tcp)) {
145 tprintf("%#lx", addr);
146 return;
147 }
148 if (umove(tcp, addr, &statbuf) < 0) {
149 tprints("{...}");
150 return;
151 }
152 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
153 sprintfstype(statbuf.f_type),
154 (unsigned long)statbuf.f_bsize,
155 (unsigned long long)statbuf.f_blocks,
156 (unsigned long long)statbuf.f_bfree);
157 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
158 (unsigned long long)statbuf.f_bavail,
159 (unsigned long long)statbuf.f_files,
160 (unsigned long long)statbuf.f_ffree,
161 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
162 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
163 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
164 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
165}
166
167int
168sys_statfs64(struct tcb *tcp)
169{
170 if (entering(tcp)) {
171 printpath(tcp, tcp->u_arg[0]);
172 tprintf(", %lu, ", tcp->u_arg[1]);
173 } else {
174 if (tcp->u_arg[1] == sizeof(struct statfs64))
175 printstatfs64(tcp, tcp->u_arg[2]);
176 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
177 printcompat_statfs64(tcp, tcp->u_arg[2]);
178 else
179 tprints("{???}");
180 }
181 return 0;
182}
183
184int
185sys_fstatfs64(struct tcb *tcp)
186{
187 if (entering(tcp)) {
188 printfd(tcp, tcp->u_arg[0]);
189 tprintf(", %lu, ", tcp->u_arg[1]);
190 } else {
191 if (tcp->u_arg[1] == sizeof(struct statfs64))
192 printstatfs64(tcp, tcp->u_arg[2]);
193 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
194 printcompat_statfs64(tcp, tcp->u_arg[2]);
195 else
196 tprints("{???}");
197 }
198 return 0;
199}
Dmitry V. Levin9e6a7bf2015-01-08 04:12:29 +0000200#endif /* HAVE_STRUCT_STATFS64 */
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000201
202#ifdef ALPHA
203int
204osf_statfs(struct tcb *tcp)
205{
206 if (entering(tcp)) {
207 printpath(tcp, tcp->u_arg[0]);
208 tprints(", ");
209 } else {
210 printstatfs(tcp, tcp->u_arg[1]);
211 tprintf(", %lu", tcp->u_arg[2]);
212 }
213 return 0;
214}
215
216int
217osf_fstatfs(struct tcb *tcp)
218{
219 if (entering(tcp)) {
220 tprintf("%lu, ", tcp->u_arg[0]);
221 } else {
222 printstatfs(tcp, tcp->u_arg[1]);
223 tprintf(", %lu", tcp->u_arg[2]);
224 }
225 return 0;
226}
227#endif /* ALPHA */