blob: 2661d07848d56995ef0a96a5ddb0e4f463166f33 [file] [log] [blame]
Dmitry V. Levin67c2f672016-04-26 00:21:26 +00001/*
2 * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "defs.h"
29#include "statfs.h"
30#include "xlat/fsmagic.h"
31#include "xlat/statfs_flags.h"
32
33static void
34print_statfs_type(const char *const prefix, const unsigned long long magic)
35{
36 tprints(prefix);
37 const char *s = xlat_search(fsmagic, ARRAY_SIZE(fsmagic), magic);
38 if (s)
39 tprints(s);
40 else
41 tprintf("%#llx", magic);
42}
43
Dmitry V. Levine0ba9202016-05-17 20:17:13 +030044#if defined HAVE_STRUCT_STATFS_F_FLAGS || defined HAVE_STRUCT_STATFS64_F_FLAGS
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000045static void
46print_statfs_flags(const char *const prefix, const unsigned long long flags)
47{
48 if (flags & ST_VALID) {
49 tprints(prefix);
Dmitry V. Levine9dd8f92016-05-16 22:09:44 +000050 printflags64(statfs_flags, flags, "ST_???");
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000051 }
52}
Dmitry V. Levine0ba9202016-05-17 20:17:13 +030053#endif /* HAVE_STRUCT_STATFS_F_FLAGS || HAVE_STRUCT_STATFS64_F_FLAGS */
Dmitry V. Levin67c2f672016-04-26 00:21:26 +000054
55static void
56print_statfs_number(const char *const prefix, const unsigned long long number)
57{
58 tprints(prefix);
59 tprintf("%llu", number);
60}
61
62void
63print_struct_statfs(struct tcb *tcp, const long addr)
64{
65#ifdef HAVE_STRUCT_STATFS
66 struct strace_statfs b;
67
68 if (!fetch_struct_statfs(tcp, addr, &b))
69 return;
70
71 print_statfs_type("{f_type=", b.f_type);
72 print_statfs_number(", f_bsize=", b.f_bsize);
73 print_statfs_number(", f_blocks=", b.f_blocks);
74 print_statfs_number(", f_bfree=", b.f_bfree);
75 print_statfs_number(", f_bavail=", b.f_bavail);
76 print_statfs_number(", f_files=", b.f_files);
77 print_statfs_number(", f_ffree=", b.f_ffree);
78# if defined HAVE_STRUCT_STATFS_F_FSID_VAL \
79 || defined HAVE_STRUCT_STATFS_F_FSID___VAL
80 print_statfs_number(", f_fsid={", b.f_fsid[0]);
81 print_statfs_number(", ", b.f_fsid[1]);
82 tprints("}");
83# endif
84 print_statfs_number(", f_namelen=", b.f_namelen);
85# ifdef HAVE_STRUCT_STATFS_F_FRSIZE
86 print_statfs_number(", f_frsize=", b.f_frsize);
87# endif
88# ifdef HAVE_STRUCT_STATFS_F_FLAGS
89 print_statfs_flags(", f_flags=", b.f_flags);
90# endif
91 tprints("}");
92#else
93 printaddr(addr);
94#endif
95}
96
97void
98print_struct_statfs64(struct tcb *tcp, const long addr, const unsigned long size)
99{
100#ifdef HAVE_STRUCT_STATFS64
101 struct strace_statfs b;
102
103 if (!fetch_struct_statfs64(tcp, addr, size, &b))
104 return;
105
106 print_statfs_type("{f_type=", b.f_type);
107 print_statfs_number(", f_bsize=", b.f_bsize);
108 print_statfs_number(", f_blocks=", b.f_blocks);
109 print_statfs_number(", f_bfree=", b.f_bfree);
110 print_statfs_number(", f_bavail=", b.f_bavail);
111 print_statfs_number(", f_files=", b.f_files);
112 print_statfs_number(", f_ffree=", b.f_ffree);
113# if defined HAVE_STRUCT_STATFS64_F_FSID_VAL \
114 || defined HAVE_STRUCT_STATFS64_F_FSID___VAL
115 print_statfs_number(", f_fsid={", b.f_fsid[0]);
116 print_statfs_number(", ", b.f_fsid[1]);
117 tprints("}");
118# endif
119 print_statfs_number(", f_namelen=", b.f_namelen);
120# ifdef HAVE_STRUCT_STATFS64_F_FRSIZE
121 print_statfs_number(", f_frsize=", b.f_frsize);
122# endif
123# ifdef HAVE_STRUCT_STATFS64_F_FLAGS
124 print_statfs_flags(", f_flags=", b.f_flags);
125# endif
126 tprints("}");
127#else
128 printaddr(addr);
129#endif
130}