]> granicus.if.org Git - strace/blob - statfs.c
io.c: move sendfile parsers to a separate file
[strace] / statfs.c
1 #include "defs.h"
2 #ifdef HAVE_SYS_VFS_H
3 # include <sys/vfs.h>
4 #endif
5 #include "xlat/fsmagic.h"
6
7 static const char *
8 sprintfstype(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
22 static void
23 printstatfs(struct tcb *tcp, const long addr)
24 {
25         struct statfs statbuf;
26
27         if (umove_or_printaddr(tcp, addr, &statbuf))
28                 return;
29         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);
40 #ifdef _STATFS_F_FRSIZE
41         tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
42 #endif
43 #ifdef _STATFS_F_FLAGS
44         tprintf(", f_flags=%lu", (unsigned long)statbuf.f_flags);
45 #endif
46         tprints("}");
47 }
48
49 SYS_FUNC(statfs)
50 {
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
60 SYS_FUNC(fstatfs)
61 {
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
71 #ifdef HAVE_STRUCT_STATFS64
72 static void
73 printstatfs64(struct tcb *tcp, long addr)
74 {
75         struct statfs64 statbuf;
76
77         if (umove_or_printaddr(tcp, addr, &statbuf))
78                 return;
79         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
99 struct 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 }
113 #if defined AARCH64 || defined X86_64 || defined X32 || defined IA64
114   ATTRIBUTE_PACKED ATTRIBUTE_ALIGNED(4)
115 #endif
116 ;
117 #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
121
122 static void
123 printcompat_statfs64(struct tcb *tcp, const long addr)
124 {
125         struct compat_statfs64 statbuf;
126
127         if (umove_or_printaddr(tcp, addr, &statbuf))
128                 return;
129         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
144 static int
145 do_statfs64_fstatfs64(struct tcb *tcp)
146 {
147         if (entering(tcp)) {
148                 tprintf(", %lu, ", tcp->u_arg[1]);
149         } else {
150                 if (tcp->u_arg[1] == sizeof(struct statfs64))
151                         printstatfs64(tcp, tcp->u_arg[2]);
152                 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                                                                         )
157                         printcompat_statfs64(tcp, tcp->u_arg[2]);
158                 else
159                         tprints("{???}");
160         }
161         return 0;
162 }
163
164 SYS_FUNC(statfs64)
165 {
166         if (entering(tcp))
167                 printpath(tcp, tcp->u_arg[0]);
168         return do_statfs64_fstatfs64(tcp);
169 }
170
171 SYS_FUNC(fstatfs64)
172 {
173         if (entering(tcp))
174                 printfd(tcp, tcp->u_arg[0]);
175         return do_statfs64_fstatfs64(tcp);
176 }
177 #endif /* HAVE_STRUCT_STATFS64 */
178
179 #ifdef ALPHA
180 SYS_FUNC(osf_statfs)
181 {
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
192 SYS_FUNC(osf_fstatfs)
193 {
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 */