2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
32 #include <linux/types.h>
33 #include <asm/statfs.h>
36 #include "xlat/fsmagic.h"
37 #include "xlat/statfs_flags.h"
39 #define PRINT_NUM(arg) \
40 if (sizeof(b->arg) == sizeof(int)) \
41 printf(", %s=%u", #arg, (unsigned int) b->arg); \
42 else if (sizeof(b->arg) == sizeof(long)) \
43 printf(", %s=%lu", #arg, (unsigned long) b->arg); \
45 printf(", %s=%llu", #arg, (unsigned long long) b->arg)
48 print_statfs_type(const char *const prefix, const unsigned int magic)
50 fputs(prefix, stdout);
52 for (i = 0; i < ARRAY_SIZE(fsmagic); ++i)
53 if (magic == fsmagic[i].val) {
54 fputs(fsmagic[i].str, stdout);
61 print_statfs(const char *const sample, const char *magic_str)
63 int fd = open(sample, O_RDONLY);
65 perror_msg_and_fail("open: %s", sample);
67 STRUCT_STATFS *const b = tail_alloc(sizeof(*b));
68 long rc = SYSCALL_INVOKE(sample, fd, b, sizeof(*b));
70 perror_msg_and_skip(SYSCALL_NAME);
72 PRINT_SYSCALL_HEADER(sample, fd, sizeof(*b));
74 printf("{f_type=%s", magic_str);
76 print_statfs_type("{f_type=", b->f_type);
84 printf(", f_fsid={val=[%u, %u]}",
85 (unsigned) b->PRINT_F_FSID[0], (unsigned) b->PRINT_F_FSID[1]);
92 if (b->f_flags & ST_VALID) {
94 printflags(statfs_flags, b->f_flags, "ST_???");
103 print_statfs("/proc/self/status", "PROC_SUPER_MAGIC");
105 print_statfs(".", NULL);
107 long rc = SYSCALL_INVOKE("", -1, 0, sizeof(STRUCT_STATFS));
108 const char *errstr = sprintrc(rc);
109 PRINT_SYSCALL_HEADER("", -1, sizeof(STRUCT_STATFS));
110 printf("NULL) = %s\n", errstr);
112 #ifdef CHECK_ODD_SIZE
113 const unsigned long addr = (unsigned long) 0xfacefeeddeadbeefULL;
114 rc = SYSCALL_INVOKE("", -1, addr, sizeof(STRUCT_STATFS) + 1);
115 errstr = sprintrc(rc);
116 PRINT_SYSCALL_HEADER("", -1, sizeof(STRUCT_STATFS) + 1);
117 printf("%#lx) = %s\n", addr, errstr);
120 puts("+++ exited with 0 +++");