2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3 * Copyright (c) 2016-2018 The strace developers.
6 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include <linux/types.h>
14 #include <asm/statfs.h>
17 #include "xlat/fsmagic.h"
18 #include "xlat/statfs_flags.h"
20 #define PRINT_NUM(arg) \
22 if (sizeof(b->arg) == sizeof(int)) \
23 printf(", %s=%u", #arg, \
24 (unsigned int) b->arg); \
25 else if (sizeof(b->arg) == sizeof(long)) \
26 printf(", %s=%lu", #arg, \
27 (unsigned long) b->arg); \
29 printf(", %s=%llu", #arg, \
30 (unsigned long long) b->arg); \
34 print_statfs_type(const char *const prefix, const unsigned int magic)
36 fputs(prefix, stdout);
38 for (i = 0; i < ARRAY_SIZE(fsmagic); ++i)
39 if (magic == fsmagic[i].val) {
40 fputs(fsmagic[i].str, stdout);
47 print_statfs(const char *const sample, const char *magic_str)
49 int fd = open(sample, O_RDONLY);
51 perror_msg_and_skip("open: %s", sample);
53 TAIL_ALLOC_OBJECT_CONST_PTR(STRUCT_STATFS, b);
54 long rc = SYSCALL_INVOKE(sample, fd, b, sizeof(*b));
56 perror_msg_and_skip(SYSCALL_NAME);
58 PRINT_SYSCALL_HEADER(sample, fd, sizeof(*b));
60 printf("{f_type=%s", magic_str);
62 print_statfs_type("{f_type=", b->f_type);
70 printf(", f_fsid={val=[%u, %u]}",
71 (unsigned) b->PRINT_F_FSID[0], (unsigned) b->PRINT_F_FSID[1]);
78 if (b->f_flags & ST_VALID) {
80 printflags(statfs_flags, b->f_flags, "ST_???");
89 print_statfs("/proc/self/status", "PROC_SUPER_MAGIC");
91 print_statfs(".", NULL);
93 long rc = SYSCALL_INVOKE("", -1, 0, sizeof(STRUCT_STATFS));
94 const char *errstr = sprintrc(rc);
95 PRINT_SYSCALL_HEADER("", -1, sizeof(STRUCT_STATFS));
96 printf("NULL) = %s\n", errstr);
99 const unsigned long addr = (unsigned long) 0xfacefeeddeadbeefULL;
100 rc = SYSCALL_INVOKE("", -1, addr, sizeof(STRUCT_STATFS) + 1);
101 errstr = sprintrc(rc);
102 PRINT_SYSCALL_HEADER("", -1, sizeof(STRUCT_STATFS) + 1);
103 printf("%#lx) = %s\n", addr, errstr);
106 puts("+++ exited with 0 +++");