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