blob: d851aa7219b92fcf186655e6eab80a2905073169 [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
Dmitry V. Levinfd55b542015-07-16 23:32:12 +000027 if (umove_or_printaddr(tcp, addr, &statbuf))
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000028 return;
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000029 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
30 sprintfstype(statbuf.f_type),
31 (unsigned long)statbuf.f_bsize,
32 (unsigned long)statbuf.f_blocks,
33 (unsigned long)statbuf.f_bfree);
34 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
35 (unsigned long)statbuf.f_bavail,
36 (unsigned long)statbuf.f_files,
37 (unsigned long)statbuf.f_ffree,
38 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
39 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000040#ifdef _STATFS_F_FRSIZE
41 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
42#endif
Elliott Hughes1b5b5672015-03-17 16:00:31 -070043#ifdef _STATFS_F_FLAGS
44 tprintf(", f_flags=%lu", (unsigned long)statbuf.f_flags);
45#endif
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000046 tprints("}");
47}
48
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000049SYS_FUNC(statfs)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000050{
51 if (entering(tcp)) {
52 printpath(tcp, tcp->u_arg[0]);
53 tprints(", ");
54 } else {
55 printstatfs(tcp, tcp->u_arg[1]);
56 }
57 return 0;
58}
59
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000060SYS_FUNC(fstatfs)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000061{
62 if (entering(tcp)) {
63 printfd(tcp, tcp->u_arg[0]);
64 tprints(", ");
65 } else {
66 printstatfs(tcp, tcp->u_arg[1]);
67 }
68 return 0;
69}
70
Dmitry V. Levin9e6a7bf2015-01-08 04:12:29 +000071#ifdef HAVE_STRUCT_STATFS64
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000072static void
73printstatfs64(struct tcb *tcp, long addr)
74{
75 struct statfs64 statbuf;
76
Dmitry V. Levinfd55b542015-07-16 23:32:12 +000077 if (umove_or_printaddr(tcp, addr, &statbuf))
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000078 return;
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +000079 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
80 sprintfstype(statbuf.f_type),
81 (unsigned long long)statbuf.f_bsize,
82 (unsigned long long)statbuf.f_blocks,
83 (unsigned long long)statbuf.f_bfree);
84 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
85 (unsigned long long)statbuf.f_bavail,
86 (unsigned long long)statbuf.f_files,
87 (unsigned long long)statbuf.f_ffree,
88 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
89 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
90#ifdef _STATFS_F_FRSIZE
91 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
92#endif
93#ifdef _STATFS_F_FLAGS
94 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
95#endif
96 tprints("}");
97}
98
99struct compat_statfs64 {
100 uint32_t f_type;
101 uint32_t f_bsize;
102 uint64_t f_blocks;
103 uint64_t f_bfree;
104 uint64_t f_bavail;
105 uint64_t f_files;
106 uint64_t f_ffree;
107 fsid_t f_fsid;
108 uint32_t f_namelen;
109 uint32_t f_frsize;
110 uint32_t f_flags;
111 uint32_t f_spare[4];
112}
Dmitry V. Levind50949d2015-03-02 21:34:02 +0000113#if defined AARCH64 || defined X86_64 || defined X32 || defined IA64
Dmitry V. Levin5647cf82015-03-29 22:45:03 +0000114 ATTRIBUTE_PACKED ATTRIBUTE_ALIGNED(4)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000115#endif
116;
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000117#if defined AARCH64 || defined ARM
118/* See arch/arm/kernel/sys_oabi-compat.c for details. */
119# define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct compat_statfs64) + 4)
120#endif
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000121
122static void
123printcompat_statfs64(struct tcb *tcp, const long addr)
124{
125 struct compat_statfs64 statbuf;
126
Dmitry V. Levinfd55b542015-07-16 23:32:12 +0000127 if (umove_or_printaddr(tcp, addr, &statbuf))
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000128 return;
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000129 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
130 sprintfstype(statbuf.f_type),
131 (unsigned long)statbuf.f_bsize,
132 (unsigned long long)statbuf.f_blocks,
133 (unsigned long long)statbuf.f_bfree);
134 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
135 (unsigned long long)statbuf.f_bavail,
136 (unsigned long long)statbuf.f_files,
137 (unsigned long long)statbuf.f_ffree,
138 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
139 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
140 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
141 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
142}
143
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000144static int
145do_statfs64_fstatfs64(struct tcb *tcp)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000146{
147 if (entering(tcp)) {
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000148 tprintf(", %lu, ", tcp->u_arg[1]);
149 } else {
150 if (tcp->u_arg[1] == sizeof(struct statfs64))
151 printstatfs64(tcp, tcp->u_arg[2]);
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000152 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64)
153#ifdef COMPAT_STATFS64_PADDED_SIZE
154 || tcp->u_arg[1] == COMPAT_STATFS64_PADDED_SIZE
155#endif
156 )
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000157 printcompat_statfs64(tcp, tcp->u_arg[2]);
158 else
159 tprints("{???}");
160 }
161 return 0;
162}
163
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000164SYS_FUNC(statfs64)
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000165{
166 if (entering(tcp))
167 printpath(tcp, tcp->u_arg[0]);
168 return do_statfs64_fstatfs64(tcp);
169}
170
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000171SYS_FUNC(fstatfs64)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000172{
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000173 if (entering(tcp))
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000174 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinbabe7f62015-03-18 16:32:04 +0000175 return do_statfs64_fstatfs64(tcp);
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000176}
Dmitry V. Levin9e6a7bf2015-01-08 04:12:29 +0000177#endif /* HAVE_STRUCT_STATFS64 */
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000178
179#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000180SYS_FUNC(osf_statfs)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000181{
182 if (entering(tcp)) {
183 printpath(tcp, tcp->u_arg[0]);
184 tprints(", ");
185 } else {
186 printstatfs(tcp, tcp->u_arg[1]);
187 tprintf(", %lu", tcp->u_arg[2]);
188 }
189 return 0;
190}
191
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000192SYS_FUNC(osf_fstatfs)
Dmitry V. Levin9a0dd742014-09-22 00:17:42 +0000193{
194 if (entering(tcp)) {
195 tprintf("%lu, ", tcp->u_arg[0]);
196 } else {
197 printstatfs(tcp, tcp->u_arg[1]);
198 tprintf(", %lu", tcp->u_arg[2]);
199 }
200 return 0;
201}
202#endif /* ALPHA */